Bug about dynamic typing ?

Benoit Dupire bdupire at seatech.fau.edu
Thu Jul 6 14:43:31 EDT 2000


bdupire wrote:

>
> My aim is to write an extension module to access functions in C which
> "get" and "set" some structures from/in shared memory.
>
>  It works well when I set the structure the first time, but not a second
> time I have got the following (run-time) error... did I miss something?
>
>  >>> import structure
>  The structure is now:
>  name Benoit
>  age 22
>  rate 3.141500
>
>  Traceback (innermost last):
>    File "<stdin>", line 1, in ?
>    File "structure.py", line 19, in ?
>      test_API.setstruct(packed)
>  TypeError: argument 1: expected string,
>                                          found
>
>  I am working with Python 1.5.2 on QNX 4.25
> test_API.c  is therefore statically linked with Python as dynamic
> linking is not possible on QNX.
>
>  file : structure.py
>  -----------------------------------------
>
>  import struct
>  import test_API
>
>  #1st  try
>  fmt="20sif"
>  a="Benoit"
>  b=22
>  c=3.1415
>  packed=struct.pack(fmt,a,b,c)
>  test_API.setstruct(packed)
>
>  #2nd try
>  a="Ben"
>  b=23
>  c=3.1417
>  packed=struct.pack(fmt,a,b,c)
>  test_API.setstruct(packed)
>
>

[see the c wrapper in the previous message]

it works well when I use a different name for the 'packed' object the second
time.

i.e :
 #2nd try
 a="Ben"
 b=23
 c=3.1417
 pp=struct.pack(fmt,a,b,c)
test_API.setstruct(pp)




I thought variables were dynamic in Python.
is there a bug, is it QNX, or is it the struct.pack function which allocates
memory behind the scene ?






More information about the Python-list mailing list