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


Groups > comp.lang.python > #6881

Re: Problem porting class to python3.2

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
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; 'python': 0.08; 'foo': 0.09; 'from:addr:python': 0.09; 'nameerror:': 0.09; 'subject:Problem': 0.09; 'tkinter': 0.09; 'tuple': 0.09; 'output': 0.11; 'def': 0.12; 'wrote:': 0.14; 'defined': 0.14; '3.2,': 0.16; '__init__': 0.16; 'expected,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'missing?': 0.16; 'nick': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply- to:addr:python-list': 0.16; 'wandering': 0.16; 'math': 0.16; 'mon,': 0.17; 'convert': 0.19; 'header:In-Reply-To:1': 0.21; "haven't": 0.22; 'code.': 0.22; 'programs.': 0.23; 'code': 0.24; "doesn't": 0.25; 'received:84': 0.25; 'function': 0.25; 'moving': 0.26; 'definition': 0.26; 'later': 0.26; 'recognized': 0.26; 'string': 0.26; "i'm": 0.27; 'random': 0.28; 'import': 0.29; 'class': 0.29; 'all,': 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; 'header:User-Agent:1': 0.35; 'skip:" 10': 0.35; 'reply-to:addr:python.org': 0.35; 'several': 0.36; 'two': 0.37; 'problem.': 0.38; 'but': 0.38; 'docs': 0.38; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'error.': 0.40; 'more': 0.60; 'day,': 0.64; 'ever': 0.64; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'skip:y 20': 0.77; '.......': 0.84; 'datetime': 0.84; 'subject:class': 0.84
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result ApwGAFfk503Unw4S/2dsb2JhbABTmBqOHXfKFIYhBJUsimw
Date Thu, 02 Jun 2011 20:33:11 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
MIME-Version 1.0
To python-list@python.org
Subject Re: Problem porting class to python3.2
References <web-74580125@email.noao.edu>
In-Reply-To <web-74580125@email.noao.edu>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
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.2398.1307043191.9059.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 82.94.164.166
X-Trace 1307043191 news.xs4all.nl 49046 [::ffff:82.94.164.166]:34410
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6881

Show key headers only | View raw


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.

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


Thread

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

csiph-web