[IPython-dev] Problem when sys.argv does not exist
Fernando Perez
fperez at colorado.edu
Mon Oct 6 13:28:00 EDT 2003
Adam Hupp wrote:
> I'm running into a problem embedding when sys.argv is not defined.
> I'm running ipython from a C extension that does not set sys.argv.
> The root of the problem is that DPyGetOpt unconditionally checks the
> passed arguments against sys.argv. With no sys.argv this raises an
> exception and aborts the whole program. Checked against 0.5.0. The
> following change to DPyGetOpt.py should fix it:
>
> < if args == sys.argv:
> < args = sys.argv[1:]
> ---
>
>> if hasattr(sys, "argv"):
>> if args == sys.argv:
>> args = sys.argv[1:]
Cool! Ipython _can_ run from within C extensions :) A while back a user
asked about it and said he had some problems, but I never heard back from him.
So I had no idea whether it worked or not.
I applied your change as:
if hasattr(sys, "argv") and args == sys.argv:
args = sys.argv[1:]
Given the short-circuiting behavior of 'and', this should be fully equivalent
to your suggestion and slightly cheaper than a nested 'if'.
Thanks for the contribution, it's already in CVS.
Regards,
Fernando.
More information about the IPython-dev
mailing list