On 02/06/2011 17:18, Nick Buchholz wrote:
Hi all,
I've been wandering through the DOCs for an hour and haven't found a
solution to this
I'm just starting to convert from 2.5 to 3.2 and I have a problem. I have a
code that looks like this.
from tkinter import *
import time
import datetime
import string
import math
import random
print (time.localtime())
def foo():
print (time.localtime())
print(time.localtime())
class StarDate:
""" implements StarDates regular dates but with output in
the form: YYYYMMDD:HHMMSS.FFFF
or represented by a 6-Tuple (Yr, Mon, Day, Hour, Min, Sec)
"""
def __init__(self, tTuple=None):
tt=self
tt.tm_year = tt.tm_mon = tt.tm_mday = tt.tm_hour = 0
tt.tm_min = tt.tm_sec = tt.tm_wday = tt.tm_yday = 0
tt.tm_isdst = 0
if type(tTuple) == type(None):
tTuple = time.localtime()
elif .......
The two print statements work as expected, printing the tuple of the local time.
The function foo and the StarDate class definition both fail with the error.
File "starDate.py", line 37 , in foo
print(time.localtime())
NameError: global name 'time' is not defined
or
File "starDate.py", line 103, in __init__
tTuple = time.localtime()
NameError: global name 'time' is not defined
What am I missing? This is a long used and tested file and class that is used
in several
more complex python programs.
why doesn't the definition of time at the top level get recognized inside the
class?
If I can't get a simple two class file working in 3.2, I despair of ever moving
to 3.2
You may be rebinding to "time" later in the code.
--
http://mail.python.org/mailman/listinfo/python-list