py stuff

Thomas Grill t.grill at
Tue Jul 23 00:26:55 CEST 2002

Hi David,

> I'm having a bit of trouble trying to load any other scripts as
> modules other than and (the examples)...I have tried
> loading something simple like:
> import sys
> def printList(alist, blist=[]):
>     if not len(alist): print ''.join(blist)
>     for i in range(len(alist)):
>         blist.append(alist.pop(i))
>         printList(alist, blist)
>         alist.insert(i, blist.pop())
> if __name__ == '__main__':
>     k='love'
>     if len(sys.argv)>1: k = sys.argv[1]
>     printList(list(k))
> PY says it managed to load this little script (which does simple
> permutation) succesfully, but when given a number as a message or from a
> number box, it fails with:
> py - no method for type float
> If the left inlet of py is for calling functions, and the right inlet is
> for passing stuff to python, shouldn't I be able to give the script above
> a number like 512 and get permutation back from py? I tried:
> message box with 512
> |
> |
> py permute
> |
> |
> print box

working with py, you will also have to define the function of the Python
script to be called, for example

[py permute printList]

you can then try to send it numbers or symbols through the right inlet.

However, your Python script has some caveats. printList always expects a
list as its argument but the py external passes floats as numbers and
symbols as strings.
Therefore, you could define another function

def printAll(v):

and then (with [py permute printAll]), try to send it numbers or symbols.

Also, your script function doesn't return any values to be printed by the pd
print objects but it will rather output the permuted values to the console.

all the best,

More information about the Pd-list mailing list