NOT A scope problem

Siggy Brentrup bsb at winnegan.de
Sun Mar 18 18:06:30 EST 2001


"Luis Cortes" <lcortes at aodinc.com> writes:

> Hello,
> 
> I have a piece of code that I think should work fine, but I believe that
> I've hit a scope problem (Python 2.1b1).  Does anyone out there have a hint
> as to how to fix it??

This is definitively no scope problem, you are dealing only with local
variables. You're simply not handling len(sys.argv)==4!

> code:
> 
> def getarguments():
> 
>         box = ( 160, 120 )
>         newgifname = 'new.gif'
>         gifname = ''
> 
>         if (len(sys.argv) < 4 ):
>                 print 'usage: trans.py width height image.xxx newimage.gif'
>                 sys.exit(0)
> 
          if (len(sys.argv) >= 4):
>                 # program width, height, image.xxx, newimage.gif
>                 box = ( int(sys.argv[1]), int(sys.argv[2]) )
>                 gifname = sys.argv[3]
> 
          if (len(sys.argv) >= 5 ):
>                 newgifname = sys.argv[4]
> 
>         print box, gifname, newgifname
>         sys.exit(0)
>         return ( box, gifname, newgifname )
> 
> THE PROBLEM:  when I have more than 3 arguments, the global variables do not
> change to the correct variables, but instead print their default values.
> Help!

Just replace > with >=

HTH
  Siggy


-- 
Siggy Brentrup - bsb at winnegan.de - http://www.winnegan.de/
****** ceterum censeo javascriptum esse restrictam *******





More information about the Python-list mailing list