Problem porting class to python3.2

N

Nick Buchholz

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

Please reply directly.

Nick
(e-mail address removed)
Day phone: (520) 318-8203
"Time is an illusion, Lunchtime doubly so" - Ford Prefect
Time is an illusion perpetrated by the manufacturers of space.
 

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,197
Latest member
ScottChare

Latest Threads

Top