preload some libraries and scripts in python

后端 未结 3 454
悲哀的现实
悲哀的现实 2021-01-18 18:46

How to preload some libraries and scripts in python before I call python command? Is there something like .bashrc file to deal with predefining some functions/variables befo

3条回答
  •  借酒劲吻你
    2021-01-18 18:58

    Create a file, 'my_imports.py' and add the import lines for all your modules.

    import math
    import anothermodule
    import anotherothermodule
    

    Then set an environment variable 'PYTHONSTARTUP' and set it to '/path/to/my_imports.py'.

    Now when you run python at the command prompt, it will load your modules first.

提交回复
热议问题