global variable, ok for string, bad for int

Tim Roberts timr at probo.com
Fri Jan 21 02:58:10 EST 2005


francisl <francisl at aei.ca> wrote:
>
>I have a problem when I declare global variable.
>If it is string, dict, array or tuple, everything goes fine, but with int, I get an "used before declaration" error.

Excuse me for being dubious, but I don't believe you.  Both of the examples
you posted work fine in Python 2.3 on Windows XP.  Please type the EXACT
script you ran, and show us the EXACT error message you get.  You can
cut-and-paste from the cmd shell script to make sure we see the right
output.

>here a sample :
>
>vardict = {'un':1, 'deux':2}
>
>def print_value():
>	print vardict['un']
>######### ok, that works
>
>--------------------
>
>#!/bin/python
>varint = 1
>
>def print_value():
>	print varint
>######### ok, that failed
>
>python 2.3.4 - windows2000
>
>(it works in linux!)
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list