Python Forum

Full Version: Python Naming Error: List not defined
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have begun working on a new function, I will keep things simple by not detailing the full scope of the function, which would be uneeded information for this question.

I created a function which was to simply place a list object inside of another list object. The problem I am having is that even though the list object appears in the parent list, when I try to call it by name, python tells me the list is not defined.

def date(D):
    """This function takes a list(date), and indexes it in another 
    list('List_Of_Dates')."""
    List_Of_Dates.append(D)
    D=[]

>>>date("March_13_2018")
>>>List_Of_Dates
[[]]
>>>March_13_2018
[error][/error]***NAME ERROR***: March_13_2018 is not defined.
From the output of the python interpreter, I can tell that my function is actually creating a list and appending it to List_Of_Dates. The problem seems to be that my name assignment "March_13_2018" is not being attached to the list object, what I get is a "nameless, or undefined" list.

How do I map the name of the list that I pass through my function, so that the list that's created has that name?
(Mar-13-2018, 07:37 PM)Intelligent_Agent0 Wrote: [ -> ]so that the list that's created has that name?
Why would you care what the function's internal variable name is?
While it's possible, that's a very wacky thing to do, like putting square tires on your car.