Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'elif': 0.04; '2.x': 0.05; '3.2': 0.05; 'implements': 0.05; '"""': 0.07; 'does.': 0.07; 'posting.': 0.07; 'terry': 0.07; 'difference,': 0.09; 'foo': 0.09; 'nameerror:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:Problem': 0.09; 'tkinter': 0.09; 'tuple': 0.09; 'pm,': 0.10; 'output': 0.11; '>>>': 0.12; 'def': 0.12; 'wrote:': 0.14; 'defined': 0.14; '3.2,': 0.16; 'expected,': 0.16; 'missing?': 0.16; 'new-style': 0.16; 'nick': 0.16; 'obvious.': 0.16; 'reedy': 0.16; 'wandering': 0.16; 'traceback': 0.16; 'math': 0.16; 'mon,': 0.17; 'convert': 0.19; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; 'posting': 0.21; "haven't": 0.22; 'code.': 0.22; 'fine': 0.22; 'code': 0.24; "doesn't": 0.25; 'function': 0.25; 'moving': 0.26; 'classes': 0.26; 'definition': 0.26; 'recognized': 0.26; 'string': 0.26; "i'm": 0.27; 'beyond': 0.28; 'seeing': 0.28; 'random': 0.28; 'import': 0.29; 'mind.': 0.29; 'class': 0.29; 'all,': 0.30; 'also.': 0.30; 'looks': 0.31; 'print': 0.31; 'this.': 0.31; "can't": 0.32; 'change.': 0.32; 'done,': 0.32; 'header:X -Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'starting': 0.33; "i've": 0.33; '...': 0.34; 'regular': 0.34; 'file': 0.34; 'fail': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'skip:" 10': 0.35; 'itself,': 0.35; 'running': 0.37; 'too.': 0.37; 'something': 0.37; 'two': 0.37; 'received:org': 0.38; 'problem.': 0.38; 'but': 0.38; 'docs': 0.38; 'subject:: ': 0.38; 'perhaps': 0.39; 'header:Mime-Version:1': 0.39; 'add': 0.39; 'to:addr:python.org': 0.39; 'under': 0.40; 'error.': 0.40; 'addition': 0.60; 'your': 0.60; 'reply': 0.63; 'day,': 0.64; 'ever': 0.64; 'skip:y 20': 0.77; '.......': 0.84; '12:18': 0.84; 'datetime': 0.84; 'subject:class': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Problem porting class to python3.2 Date: Thu, 02 Jun 2011 15:15:22 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 79 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307042142 news.xs4all.nl 49174 [::ffff:82.94.164.166]:43673 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6879 On 6/2/2011 12:18 PM, 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()) Be itself, this works fine in 3.2 >>> import time >>> def foo(): print (time.localtime()) >>> foo() time.struct_time(tm_year=2011, tm_mon=6, tm_mday=2, tm_hour=15, tm_min=3, tm_sec=48, tm_wday=3, tm_yday=153, tm_isdst=1) Add a foo() call in your code too. > class StarDate: The first thing I would do is make this a new-style class in 2.5. class StartDate(object): Make sure your class still works with that change. ('(object)' can be removed or left when running under 3.2.) > """ 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 > What am I missing? > why doesn't the definition of time at the top level get recognized inside the class? Without seeing the complete traceback and all the code up to line 37 and everything beyond involved in the call chain, I cannot even guess. No possibilities come to mind. > If I can't get a simple two class file working in 3.2, Many people have had no problem. Again, first convert to newstyle classes in your 2.x code. This rarely makes a difference, but perhaps you so something in the ... part where is does. > I despair of ever moving to 3.2 Don't there must be something simple but not now obvious. > Please reply directly. Done, in addition to public posting. Please reply to the public posting so others can learn also. -- Terry Jan Reedy