Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6881 > unrolled thread

Re: Problem porting class to python3.2

Started byMRAB <python@mrabarnett.plus.com>
First post2011-06-02 20:33 +0100
Last post2011-06-02 20:33 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Problem porting class to python3.2 MRAB <python@mrabarnett.plus.com> - 2011-06-02 20:33 +0100

#6881 — Re: Problem porting class to python3.2

FromMRAB <python@mrabarnett.plus.com>
Date2011-06-02 20:33 +0100
SubjectRe: Problem porting class to python3.2
Message-ID<mailman.2398.1307043191.9059.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web