[IPython-user] FakeModule and python's __main__ module

Robin robince@gmail....
Mon Oct 19 16:28:58 CDT 2009


On Wed, Oct 14, 2009 at 8:42 PM, Brian Granger <ellisonbg.net@gmail.com> wrote:
> I know you are busy, but you are most familiar with this side of IPython.
> Did this behavior change when you fixed the issues in 0.10?  Is this
> unavoidable or is there something we can do about this?

Just to make the point I think this is the same issue that prevents
using multiprocessing module in ipython with functions defined
interactively - the multiprocessing module can't access the __main__
workspace and so can't pickle the interactively defined functions. So
fixing this would not only solve Mikes problem, but also allow better
integration with multiprocessing (it does work now, but everything has
to be encapsulated in a module in a file on disk)

Cheers

Robin

>
> On Tue, Oct 6, 2009 at 7:56 PM, Mike Blatchley <mabxmab@gmail.com> wrote:
>>
>> A friend of mine has recently introduced me to IPython and I'm hooked.
>> I've been using an older version (0.8.x), but have now downloaded 0.10 and
>> am having trouble with some of my existing python scripts.  In a few of
>> these, I get lazy with "returning" certain objects from methods.  Instead of
>> returning them, I place them directly in the main/interactive namespace with
>> the __main__ module.
>>
>> def someFunction():
>>     import __main__
>>     # do some stuff here
>>     __main__.myObject=myObject
>>     #etc.
>>
>> When I return to the interactive prompt, myObject isn't there.
>> Conversely, sometimes I try to retrieve "global" attributes from that
>> namespace, but now get an error.  For example:
>>
>> In [16]: myObject=None
>> In [17]: def test():
>>    ....:     import __main__
>>    ....:     print __main__.myObject
>> In [18]: test()
>>
>> ---------------------------------------------------------------------------
>> AttributeError                            Traceback (most recent call
>> last)
>> C:\work\test\<ipython console> in <module>()
>> C:\work\test\<ipython console> in test()
>> AttributeError: 'FakeModule' object has no attribute 'myObject'
>>
>> I've done searches on FakeModule and see quite a few mailing list postings
>> indicating it replaces python's __main__, but am unclear if there is any way
>> around my problem.  That is, other than sticking with the older releases of
>> IPython.  Or rewriting my affected methods to not use __main__.
>>
>> Any suggestions would be much appreciated.
>>
>> Thanks much,
>> Mike
>>
>>
>> _______________________________________________
>> IPython-user mailing list
>> IPython-user@scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>>
>
>
> _______________________________________________
> IPython-user mailing list
> IPython-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>


More information about the IPython-user mailing list