Help with new scope problem

Emile van Sebille emile at fenx.com
Mon Mar 19 00:15:07 CET 2001


Luis,

Your code doesn't use globals: all the variables are local to the function.
Also note that you check for <4, >4, >5 but never for anything =4.  I'd say
this is part of it.

Are you invoking this as:

box, gifname, newgifname = getarguments()

in your main code?

HTH,

Emile van Sebille
emile at fenx.com


"Luis Cortes" <lcortes at aodinc.com> wrote in message
news:993bar$7h5$1 at news.chatlink.com...
> 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??
>
> 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!
>
>
>





More information about the Python-list mailing list