Python Forum
Name Error: name 'Stockton' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Name Error: name 'Stockton' is not defined
#1
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.
Reply
#2
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}}}
Reply
#3
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?
Reply
#4
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/datas...ctionaries 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().
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 576 Nov-23-2023, 02:53 PM
Last Post: rob101
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,124 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Error 'Contour' not Defined DaveG 3 2,349 Mar-13-2022, 03:29 AM
Last Post: deanhystad
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,597 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Error when refering to class defined in 'main' in an imported module HeRo 2 2,376 Apr-13-2021, 07:22 PM
Last Post: HeRo
  Why does lambda throw 'name value_o is not defined' error? karabakh 3 2,179 Dec-14-2020, 05:45 PM
Last Post: karabakh
  name error "name"is not defined MaartenRo 1 3,424 Jul-28-2020, 02:39 AM
Last Post: bowlofred
  python library not defined in user defined function johnEmScott 2 3,840 May-30-2020, 04:14 AM
Last Post: DT2000
  error ,,name append is not defined'' Killdoz 1 5,031 May-24-2020, 06:23 PM
Last Post: bowlofred
  name error:name 'clf' is not defined saiankith 3 11,310 Mar-31-2020, 06:49 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020