[PD] pyext help, related to my other [netreceive]->[route] question
David Merrill
dmerrill at media.mit.edu
Thu Jul 6 22:35:44 CEST 2006
Thanks very much Frank. I'll give this one a try, as well as stripping
my bug down to a simple patch for review.
much appreciated!
-David
Frank Barknecht wrote:
> Hallo,
> David Merrill hat gesagt: // David Merrill wrote:
>
>
>> You might wonder why I'm bothering with sockets at all if I got pyext to
>> compile - the answer is that I am having a hard time finding examples of
>> doing some basic things with pyext.
>>
>
> There are some examples in the pyext docs, but I'm attaching an IMO
> very useful "catch all" pyexternal. It basically is a wrapper around
> (m)any python modules and makes their methods and attributes directly
> useable inside Pd. It's simple but immensely powerful.
>
> You soundfile problem could be solved with the "listdir" example on
> the left side and a [list-drip] connected to the pyext-outlet.
>
> Ciao
>
> ------------------------------------------------------------------------
>
> import pyext
> import string
>
> class pymod(pyext._class):
>
> _inlets = 1
> _outlets = 1
>
> # constructor
> def __init__(self, mod):
> mod = str(mod)
> self.mod = __import__(mod, globals(), locals(), [])
> self.mod_string = mod
>
> def _anything_1(self, func, *args):
> """inlet to accept everything"""
> # TODO this needs proper error checking ... or maybe not.
> func = str(func)
> args = [str(x) for x in args]
>
> # HACK: replace the string "[BS]" with a backslash, that cannot be input in Pd:
> args = [string.replace(x, "[BS]",'\\') for x in args]
>
> if hasattr(self.mod, func):
> result = None
> if callable(getattr(self.mod, func)):
> result = getattr(self.mod, func)(*args)
> else:
> result = getattr(self.mod, func)
> self._outlet(1, result)
> else:
> print "No such attribute: %s.%s" % (self.mod_string, func)
>
> ------------------------------------------------------------------------
>
> #N canvas 103 11 985 619 10;
> #X obj 41 363 pyext pycall pymod os;
> #X msg 41 331 reload;
> #X msg 281 227 listdir /tmp;
> #X msg 279 458 bogus;
> #X msg 283 270 listdir .;
> #X msg 280 324 __doc__;
> #X msg 280 346 name;
> #X msg 280 367 curdir;
> #X msg 281 387 pardir;
> #X msg 281 407 path;
> #X msg 279 183 mkdir /tmp/python-test;
> #X msg 280 205 rmdir /tmp/python-test;
> #X msg 282 248 getcwd;
> #X msg 278 160 getloadavg;
> #X msg 276 138 getpid;
> #X msg 275 116 getenv HOME;
> #X msg 276 92 system gvim;
> #X obj 520 175 pyext pycall pymod string;
> #X msg 721 102 letters;
> #X obj 524 450 print REGEX;
> #X obj 520 200 print STRING;
> #X obj 41 392 print OS;
> #X msg 721 81 replace 12345 3 -THREE-;
> #X msg 524 400 reload;
> #X obj 524 425 pyext pycall pymod sre;
> #X text 494 336 "[BS]" internally gets replaced by a backslash. Yes
> \, I know it's a hack.;
> #X msg 721 123 count iiiiiiiiiiiieeeehhh i;
> #X msg 722 169 lower ABC;
> #X msg 722 146 split X---Y---Z ---;
> #X msg 673 388 sub [BS]d _NUM_ 12a3b4c5;
> #X connect 0 0 21 0;
> #X connect 1 0 0 0;
> #X connect 2 0 0 1;
> #X connect 3 0 0 1;
> #X connect 4 0 0 1;
> #X connect 5 0 0 1;
> #X connect 6 0 0 1;
> #X connect 7 0 0 1;
> #X connect 8 0 0 1;
> #X connect 9 0 0 1;
> #X connect 10 0 0 1;
> #X connect 11 0 0 1;
> #X connect 12 0 0 1;
> #X connect 13 0 0 1;
> #X connect 14 0 0 1;
> #X connect 15 0 0 1;
> #X connect 16 0 0 1;
> #X connect 17 0 20 0;
> #X connect 18 0 17 1;
> #X connect 22 0 17 1;
> #X connect 23 0 24 0;
> #X connect 24 0 19 0;
> #X connect 26 0 17 1;
> #X connect 27 0 17 1;
> #X connect 28 0 17 1;
> #X connect 29 0 24 1;
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> PD-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
>
--
MIT Media Lab
dmerrill at media.mit.edu
More information about the Pd-list
mailing list