Re: Declare a variable global

2007-02-19 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On Feb 19, 11:09 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: >> On 19 Feb 2007 09:04:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> >>> Hi, >>> I have the following code: >>> colorIndex = 0; >>> def test(): >>> print colorIndex; >>> This won't work

Re: Declare a variable global

2007-02-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Feb 19, 11:09 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > >>On 19 Feb 2007 09:04:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> >> >>>Hi, >> >>>I have the following code: >> >>>colorIndex = 0; >> >>>def test(): >>>print colorIndex; >> >>>T

Re: Declare a variable global

2007-02-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hi, > > I have the following code: > > colorIndex = 0; You don't need the ; > > def test(): > print colorIndex; Idem. > This won't work. Why ? Or more exactly : for which definition of "won't work" ? (hint: this code prints 0 on sys.stdout - I don't know

Re: Declare a variable global

2007-02-19 Thread Terry Reedy
| Here is my complete script: | #!/usr/bin/python | | import re | import sys | import time | import os | import shutil | | colors = ["#FF", "#00FF00", "#FF", | "#00" ,"#FFA500" ,"#DA70D6"] | colorIndex = 0 | | def getText( intputstr): |rc = "" | |maxX = 0; |maxY = 0; |m

Re: Declare a variable global

2007-02-19 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote: > I have the following code: > > colorIndex = 0; > > def test(): > print colorIndex; Don't use ";". It's redundant. > This won't work. But it works if i do this: > > colorIndex = 0; > > def test(): > global colorIndex; > print colorIndex; > > My qu

Re: Declare a variable global

2007-02-19 Thread Peter Otten
[EMAIL PROTECTED] wrote: > On Feb 19, 11:09 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: >> On 19 Feb 2007 09:04:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> >> wrote: >> >> >Hi, >> >> >I have the following code: >> >> >colorIndex = 0; >> >> >def test(): >> > print colorIndex; >> >>

Re: Declare a variable global

2007-02-19 Thread Gary Herron
[EMAIL PROTECTED] wrote: > Hi, > > I have the following code: > > colorIndex = 0; > > def test(): > print colorIndex; > > This won't work. But it works if i do this: > Yes, it does work. Can you be more explicit about why you think it doesn't? (Also, this is Python not C/C++. Get *RID* o

Re: Declare a variable global

2007-02-19 Thread [EMAIL PROTECTED]
On Feb 19, 11:09 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On 19 Feb 2007 09:04:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > >Hi, > > >I have the following code: > > >colorIndex = 0; > > >def test(): > > print colorIndex; > > >This won't work. > > Are you sure? > >

Re: Declare a variable global

2007-02-19 Thread Jean-Paul Calderone
On 19 Feb 2007 09:04:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >Hi, > >I have the following code: > >colorIndex = 0; > >def test(): > print colorIndex; > >This won't work. Are you sure? [EMAIL PROTECTED]:~$ cat foo.py colorIndex = 0 def test(): print

Declare a variable global

2007-02-19 Thread [EMAIL PROTECTED]
Hi, I have the following code: colorIndex = 0; def test(): print colorIndex; This won't work. But it works if i do this: colorIndex = 0; def test(): global colorIndex; print colorIndex; My question is why do I have to explicit declaring 'global' for 'colorIndex'? Can't pyth