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


Groups > comp.lang.python > #6877

Problem porting class to python3.2

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!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <buchholz@email.noao.edu>
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; '3.2': 0.05; 'implements': 0.05; '"""': 0.07; 'space.': 0.07; 'python': 0.08; 'foo': 0.09; 'nameerror:': 0.09; 'subject:Problem': 0.09; 'tkinter': 0.09; 'tuple': 0.09; 'output': 0.11; 'def': 0.12; 'defined': 0.14; '3.2,': 0.16; '__init__': 0.16; 'expected,': 0.16; 'illusion': 0.16; 'missing?': 0.16; 'nick': 0.16; 'so"': 0.16; 'wandering': 0.16; 'math': 0.16; 'mon,': 0.17; 'convert': 0.19; "haven't": 0.22; 'programs.': 0.23; 'code': 0.24; "doesn't": 0.25; 'function': 0.25; 'moving': 0.26; 'definition': 0.26; 'recognized': 0.26; 'string': 0.26; "i'm": 0.27; 'random': 0.28; 'import': 0.29; 'class': 0.29; 'all,': 0.30; 'received:140': 0.30; 'looks': 0.31; 'print': 0.31; 'this.': 0.31; "can't": 0.32; 'to:addr:python-list': 0.33; 'starting': 0.33; "i've": 0.33; 'regular': 0.34; 'file': 0.34; 'fail': 0.34; 'skip:" 10': 0.35; 'phone:': 0.36; 'several': 0.36; 'two': 0.37; 'problem.': 0.38; 'but': 0.38; 'docs': 0.38; 'to:addr:python.org': 0.39; 'error.': 0.40; 'more': 0.60; 'reply': 0.63; 'day,': 0.64; 'ever': 0.64; 'day': 0.67; 'skip:y 20': 0.77; '.......': 0.84; 'datetime': 0.84; 'subject:class': 0.84
From "Nick Buchholz" <nbuchholz@noao.edu>
Subject Problem porting class to python3.2
To python-list@python.org
X-Mailer CommuniGate Pro WebUser v5.3.13
Date Thu, 02 Jun 2011 09:18:18 -0700
MIME-Version 1.0
Content-Type text/plain;charset=iso-8859-1
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2395.1307038708.9059.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 82.94.164.166
X-Trace 1307038709 news.xs4all.nl 49174 [::ffff:82.94.164.166]:38017
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6877

Show key headers only | View raw


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
nbuchholz@noao.edu
Day phone: (520) 318-8203
"Time is an illusion, Lunchtime doubly so" - Ford Prefect
Time is an illusion perpetrated by the manufacturers of space.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Problem porting class to python3.2 "Nick Buchholz" <nbuchholz@noao.edu> - 2011-06-02 09:18 -0700

csiph-web