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

lajarre
  • 4,910
  • 6
  • 42
  • 69

1 Answers1

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
Community
  • 1
  • 1
parkouss
  • 576
  • 6
  • 5