[PD] Re: pyext problem?

Frank Barknecht fbar at footils.org
Wed May 31 11:10:08 CEST 2006


Hallo,
Thomas Grill hat gesagt: // Thomas Grill wrote:

> Hi Michael,
> this seems to be a Python question and i'm really not an expert, but i'm 
> guessing the following:
> in the working example you have the "for i in orchestra" loop which 
> assigns values (by exec) to x1 and x2, which means they are defined in 
> the module (you can check this with "print dir()" after the loop). This 
> is not the case in the doesnt example.
> In the Test class then you are again trying to use x1 and x2 (exec 
> "x1.setVal(...)"), which are not defined in the doesnt example. I'm 
> wondering though why you don't need a "global x1,x2" in the working 
> example, but i guess that's some secret Python magic.....

Because x*, y* and orchestra are defined at global scope anyway, so
you can even omit the "global orchestra" from the works.py, see
attached standalone example.

The naming and scoping rules for Python are written here:
http://docs.python.org/ref/naming.html

I also attached a "scopes.py" which tests several of the scoping
rules.

I think, for Michael's code it would be better to make "orchestra" a
real list of "Instrument"s like: 

orchestra1 = [ ['x1','a',1], ['x2','c',11] ] # changed!
orchestra = []

for i in orchestra1:
    tmp = Instrument(i[0], i[1], i[2])
    orchestra.append(tmp)


Then in the pyext class use in float_1 something like:

    orchestra[index].setVal(f)

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: works.py
Type: text/x-python
Size: 575 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20060531/09ba532c/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: doesnt-standalone.py
Type: text/x-python
Size: 797 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20060531/09ba532c/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scopes.py
Type: text/x-python
Size: 1075 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20060531/09ba532c/attachment-0002.py>


More information about the Pd-list mailing list