Re: import from a string

2009-11-04 Thread Terry Reedy
Gabriel Genellina wrote: En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribió: On Nov 4, 3:10 am, "Gabriel Genellina" wrote: txt = """ def foo(x): print 'x=', x def bar(x): return x + x """ py> namespace = {} py> exec txt in namespace py> namespace.keys() ['__builtins__', 'foo', 'bar']

Re: import from a string

2009-11-03 Thread Gabriel Genellina
En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribió: On Nov 4, 3:10 am, "Gabriel Genellina" wrote: txt = """ def foo(x): print 'x=', x def bar(x): return x + x """ py> namespace = {} py> exec txt in namespace py> namespace.keys() ['__builtins__', 'foo', 'bar'] py> namespace['foo']('hell

Re: import from a string

2009-11-03 Thread iu2
On Nov 4, 3:10 am, "Gabriel Genellina" wrote: > En Tue, 03 Nov 2009 17:36:08 -0300, iu2 escribió: > > > > > > > On Nov 3, 7:49 pm, Matt McCredie wrote: > >> iu2 elbit.co.il> writes: > > >> > Having a file called funcs.py, I would like to read it into a string, > >> > and then import from that s

Re: import from a string

2009-11-03 Thread iu2
On Nov 3, 7:49 pm, Matt McCredie wrote: > iu2 elbit.co.il> writes: > > > > > Hi, > > > Having a file called funcs.py, I would like to read it into a string, > > and then import from that string. > > That is instead of importing from the fie system, I wonder if it's > > possible to eval the text i

Re: import from a string

2009-11-03 Thread Gabriel Genellina
En Tue, 03 Nov 2009 17:36:08 -0300, iu2 escribió: On Nov 3, 7:49 pm, Matt McCredie wrote: iu2 elbit.co.il> writes: > Having a file called funcs.py, I would like to read it into a string, > and then import from that string. > That is instead of importing from the fie system, I wonder if it's

Re: import from a string

2009-11-03 Thread Matt McCredie
iu2 elbit.co.il> writes: > > Hi, > > Having a file called funcs.py, I would like to read it into a string, > and then import from that string. > That is instead of importing from the fie system, I wonder if it's > possible to eval the text in the string and treat it as a module. > > For exampl