Namespace problem?

J

Josh English

I have a script that generates a report from a bunch of data I've been
collecting for the past year. I ran the script, successfully, for
several weeks on test runs and creating more detailed reports.

Today (back from vacation) and the script doesn't work. It's giving me
a name error.

I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.
1310 32 bit (Intel)]. (Upgrading is not a possibility right now.
Eventually we'll be upgraded top Windows 7.)

Here is the reduced code:

fws_first_col = 6

for student in range(32):

if True:
idx = fws_first_col

for _month in range(12):
idx += 2
fws_last_col = idx


print fws_last_col

I get:

NameError: name 'fws_last_col' is not defined

This snippet of code works on it's own, but not in the main script. I
know it looks funny, but this should preserve the appropriate nesting
of things.

Where else could I look to find this problem?
 
M

Matt McCredie

Josh English said:
I have a script that generates a report from a bunch of data I've been
collecting for the past year. I ran the script, successfully, for
several weeks on test runs and creating more detailed reports.

Today (back from vacation) and the script doesn't work. It's giving me
a name error.

I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.
1310 32 bit (Intel)]. (Upgrading is not a possibility right now.
Eventually we'll be upgraded top Windows 7.)

Here is the reduced code:

fws_first_col = 6

for student in range(32):

if True:
idx = fws_first_col

for _month in range(12):
idx += 2
fws_last_col = idx

print fws_last_col

I get:

NameError: name 'fws_last_col' is not defined

This snippet of code works on it's own, but not in the main script.

That doesn't give me enough information to help you with the issue. In general
you need to provide enough code to reproduce the failure, not some modified
version that doesn't fail. My guess is that the "if True" is actually something
else, and it isn't being interpreted as "True". As such, "fws_last_col" never
gets assigned, and thus never gets created. You can fix that by assigning
fws_last_col to an appropriate default value before the for loop. But what do I
know, that is just a guess.

Matt
 
J

Josh English

That doesn't give me enough information to help you with the issue. In general
you need to provide enough code to reproduce the failure, not some modified
version that doesn't fail. My guess is that the "if True" is actually something
else, and it isn't being interpreted as "True". As such, "fws_last_col" never
gets assigned, and thus never gets created. You can fix that by assigning
fws_last_col to an appropriate default value before the for loop. But what do I
know, that is just a guess.

Matt

This is the code snippet with more context, but it isn't runnable
without creating a bunch of dummy objects:
# data is a dictionary. The keys are student names, the values are
Tracker object.
# The tracker class defines the method hasFWS() which returns a
boolean.
# _monthnumbers is a list: [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6]
I just cut out the code that doesn't have anything to do the variable
fws_last_col

fws_first_col = 6

for student in sorted(data.keys() ):
#~ print student

tracker = data[student]

if tracker.hasFWS():

idx = fws_first_col


for _month in iter(_monthnumbers):
idx += 2
fws_last_col = idx

fws_month_count_col = idx + 4
fwsrow += 1

print fws_last_col
 
M

Mark Lawrence

I have a script that generates a report from a bunch of data I've been
collecting for the past year. I ran the script, successfully, for
several weeks on test runs and creating more detailed reports.

Today (back from vacation) and the script doesn't work. It's giving me
a name error.

I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.
1310 32 bit (Intel)]. (Upgrading is not a possibility right now.
Eventually we'll be upgraded top Windows 7.)

Here is the reduced code:

fws_first_col = 6

So fws_first_col is set to 6.
for student in range(32):

student isn't used in the snippet below.

Isn't this always going to run?
idx = fws_first_col

Effectively set idx to 6 each time around the for loop.
for _month in range(12):
idx += 2

Add 24 to idx each time around the for loop. 24 + 6 == 30.
fws_last_col = idx

set fws_last_col to 30 each time around the for loop.
print fws_last_col

prints 30 only once.
I get:

NameError: name 'fws_last_col' is not defined

This snippet of code works on it's own, but not in the main script. I
know it looks funny, but this should preserve the appropriate nesting
of things.

Certainly doesn't look at all correct to me.
Where else could I look to find this problem?

In a mirror? :)

Kindest regards.

Mark Lawrence.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top