NameError

Fredrik Lundh effbot at telia.com
Mon Oct 9 16:41:20 EDT 2000


alfred6465 at my-deja.com wrote:
> I am a new Python user and am having some
> problems.  I have a file called test.py that
> looks like the following:
> 
> import struct
> 
> def unpack_data():
>    f=open('C:\\cudacom\\result\\1.rp1').read()
>    start = 42
>    stop = (struct.calcsize('6s') + start)
>    name = struct.unpack('6s', f[start:stop])
>    grab_data(start,stop)
>    print_results(name,desc,data)
>    f.close()
> 
> def grab_data(start, stop):
>    header = 5
>    start = stop+header
>    stop =  struct.calcsize('sh')+start
>    desc, data = struct.unpack('sh', fstart:stop])

better make that:

     desc, data = struct.unpack('sh', f[start:stop])

>    return desc,data
> 
> def print_results(name,desc,data):
>    print 'Variable Name: %s' %name
>    print 'Descriptor: %s' %desc
>    print 'Data: %s' %data
>    print ""
>    return

:::

> If I open up PythonWin and type 'import test' at
> the prompt I get the following error.
> Traceback (innermost last):
>   File "<interactive input>", line 1, in ?
>   File "GetInfo2.py", line 42
>      return (descriptor, data)
>      ^
>  SyntaxError: invalid syntax

there's no "return (descriptor, data)" in the code you posted...

</F>





More information about the Python-list mailing list