Re: [Tutor] Converting code to string

2007-08-24 Thread Kent Johnson
Bernard Lebel wrote: > In the task I'm currently having, I have to dynamically create a > certain number of layout elements along its logic. The number of > elements to create changes from one execution to the next, as it is > driven by the user input. Since properpty plugins do not support such >

Re: [Tutor] Converting code to string

2007-08-24 Thread Bernard Lebel
Actually, regarding inspect.getsource() that raised IOErrors: Running it from imported module actually works! Thanks Bernard ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Converting code to string

2007-08-24 Thread Bernard Lebel
okay here "simple" examples about why I have to define callbacks as strings instead of code. In XSI, one of the GUI objects that you can create is called a "custom property". A custom property is basically a floating window in which there are widgets. Custom properties can define a layout or not.

Re: [Tutor] Converting code to string

2007-08-23 Thread Alan Gauld
"Bernard Lebel" <[EMAIL PROTECTED]> wrote > Why? Because I'm using an API (the Softimage|XSI scripting API) > where > I have to create a custom GUI (using that API's GUI toolkit). > > I have to attach a logic callback to a number of widgets that can > change from one execution to the next. Can y

Re: [Tutor] Converting code to string

2007-08-23 Thread Eric Brunson
Bernard Lebel wrote: > Hi Kent, > > When try your approach, I get an IOError. > > import inspect def myFunc(): > ... print 'hello world' > ... > s = inspect.getsource(myFunc) > Traceback (most recent call last): > File "", line 1, in ? > File

Re: [Tutor] Converting code to string

2007-08-23 Thread Bernard Lebel
Hi Kent, When try your approach, I get an IOError. >>> import inspect >>> def myFunc(): ... print 'hello world' ... >>> >>> s = inspect.getsource(myFunc) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\inspect.py", line 552, in getsource lines, lnum = ge

Re: [Tutor] Converting code to string

2007-08-23 Thread Alan Gauld
"Bernard Lebel" <[EMAIL PROTECTED]> wrote > I'm looking for a way to convert Python code into a string. Read the file as text? You can find the file by checking the __file__ attribute of a module. > Now in the same module, I'd like to take this function and convert > it > into a string: If its

Re: [Tutor] Converting code to string

2007-08-23 Thread Luke Paireepinart
Bernard Lebel wrote: > Hello, > > I'm looking for a way to convert Python code into a string. > > For example, let say I have this function: > > def myFunc(): > print 'hello world' > > > Now in the same module, I'd like to take this function and convert it > into a string: > > """def myFunc():

Re: [Tutor] Converting code to string

2007-08-23 Thread Kent Johnson
Bernard Lebel wrote: > Hello, > > I'm looking for a way to convert Python code into a string. > > For example, let say I have this function: > > def myFunc(): > print 'hello world' > > > Now in the same module, I'd like to take this function and convert it > into a string: > > """def myFu

Re: [Tutor] Converting code to string

2007-08-23 Thread bhaaluu
Greetings, The following is from: http://www.hetland.org/coding/ ## Self-Printing One-Liner If you run this one-liner at a command prompt, it should print out a copy of itself (write it as one continuous line, without the line break): python -c "x='python -c %sx=%s; print x%%(chr

[Tutor] Converting code to string

2007-08-23 Thread Bernard Lebel
Hello, I'm looking for a way to convert Python code into a string. For example, let say I have this function: def myFunc(): print 'hello world' Now in the same module, I'd like to take this function and convert it into a string: """def myFunc(): print 'hello world'\n""" Thanks Bern