0

In python, you can run python3 -i some_file.py to run some_file.py, then open an interactive session in the file, allowing you to debug and such.

I have my own file full of functions and things to use for testing stuff out python3 -i ~/testing_functions.py.

Is there a way I could use this in another file: python3 -i some_file.py -i ~/testing_functions.py

# a.py
a = "A"

# b.py
b = "B"
# in the shell
$ python3 -i a.py -i b.py
>>> print(a)
A
>>> print(b)
B
>>> pribt(a+b)
AB

When I try python -i file.py -i other.py is does not work, and neither does python -i file.py other.py

I would like to avoid just importing if possible, as I don't know what directory I will be in or file I will test, and relative vs. absolute imports confuse me.

  • Welcome to Python! Have you tried `import testing_functions` at the start of `some_file.py` instead? – VirtualScooter Mar 02 '21 at 22:53
  • The issue is that I'm not always going to use this on the same file. I want to use it whenever I am debugging or trying anything with any python file, without having to edit every time or deal with making sure testing_functions is in sys.path. – coderkearns Mar 03 '21 at 02:07
  • Well you can add the module to the python built-ins as described [here](https://stackoverflow.com/a/6965111/10961342). But this can be very confusing if you rename the variable by accident. A better approach would be to either use unit testing ([starters guide](https://realpython.com/python-testing/)) for your debugging, or using an IDE such as Pycharm where you can import the module at run time (or during debugging). – Thymen Mar 03 '21 at 16:11

0 Answers0