2

I realised that I have a fairly large ~/.pythonrc.py, notably helping with pretty printing and tab-completion.

But I'm now using ipython a lot and some of the commands executed in .pythonrc.py are annoying me and slowing it down at launch.

Instead of deleting the file or commenting it out, the better would be that I execute the script conditionally depending on whether I launch python or ipython.

How can I do that?
How to detect the launching script from inside .pythonrc.py?

NB: sys.argv is not helping when used in .pythonrc.py

1 Answer 1

3

I think you can use the response used in Detecting when a python script is being run interactively in ipython, ie in you pythonrc file, detect if the variable __IPYTHON__ exists:

def in_ipython():
    try:
        __IPYTHON__
    except NameError:
        return False
    else:
        return True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.