[IPython-user] FakeModule and python's __main__ module
Tue Oct 6 22:02:53 CDT 2009
With tab completion, pretty printing, and output history management, I
think you'll find that IPython handles normally returned values quite
If you still have extensive side-channel data (and logging, etc.
doesn't cut it), you could add that data as an attribute on whatever
object you're returning, or make a module-global dictionary that you
update. I've never felt the need to do those things, though. Keep even
your API clean; you'll thank yourself later :)
On Tue, Oct 6, 2009 at 10:56 PM, Mike Blatchley <firstname.lastname@example.org> 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
> 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 : myObject=None
> In : def test():
> ....: import __main__
> ....: print __main__.myObject
> In : 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,
> IPython-user mailing list
More information about the IPython-user