Python Forum
Name Error: name 'Stockton' is not defined - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Name Error: name 'Stockton' is not defined (/thread-27610.html)



Name Error: name 'Stockton' is not defined - Pinokchu - Jun-13-2020

data = DataPortal(model=m)
    
data.load(filename="Dataframe2.xlsx", range='D2:D6', set='I')
data.load(filename="Dataframe2.xlsx", range='A2:A99', set='J')
data.load(filename="Dataframe2.xlsx", range='A1:B99', param='d', index='J')
data.load(filename="Dataframe2.xlsx", range='G1:L99', param='c', format='transposed_array')
data.load(filename="Dataframe2.xlsx", range='D1:E6' , param='b', index='I')
data.load(filename="Dataframe2.xlsx", range='N1:O6' , param='i', index='I')

data = {None: {
    'e' : {Stockton:325000, Rockwall:50000, Joliet:350000, Atlanta:450000, York:170000},
}}

m = m.create_instance(data)
m = m.create_instance(data)
After running it there is the following error code:

Quote:NameError Traceback (most recent call last)
<ipython-input-264-1e6fce871313> in <module>
9
10 data = {None: {
---> 11 'e' : {Stockton:325000, Rockwall:50000, Joliet:350000, Atlanta:450000, York:170000},
12 }}
13

NameError: name 'Stockton' is not defined

The numbers are maximum restrictions and the city names are places. If somebudy could help or give any advice I'd be grateful.


RE: Name Error: name 'Stockton' is not defined - Yoriz - Jun-13-2020

As the error is saying 'Stockton' is not defined anywhere in the code shown neither is Rockwall, Joliet, Atlanta or York.
Did you mean for them to string values? add quotes to them.
data = {None: {
    'e': {'Stockton': 325000, 'Rockwall': 50000, 'Joliet': 350000,
          'Atlanta': 450000, 'York': 170000}}}



RE: Name Error: name 'Stockton' is not defined - Pinokchu - Jun-13-2020

Thanks, I added the marks.

However this won't solve the problem you said before that the city names are not defined, right?
Could you tell me how I should to this?


RE: Name Error: name 'Stockton' is not defined - Yoriz - Jun-13-2020

It does solve the problem of NameError: name 'Stockton' is not defined
what do you want the key names to be represented as?
Note
https://docs.python.org/3/tutorial/datastructures.html#dictionaries Wrote:dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys. Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key. You can’t use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like append() and extend().