Search code examples
pythonpython-importpython-idleautostart

How to make IDLE automatically import modules at start?


Often when I am using the IDLE shell I import the pickle module. Is it possible to make it automatically import pickle when I start it?


Solution

  • You can use the -c or -r argument:

    From idle -h:

    -c cmd     run the command in a shell, or
    -r file    run script from file
    

    For example:

    idle -c 'import pickle, sys'
    

    Or:

    idle -r ~/my_startup.py
    

    Where my_startup.py might contain:

    import pickle, sys
    

    You can either create a shell alias to always use this, or create a separate script; the procedure for this differs depending on your OS and shell.