Automatically import all modules in current directory into python interactive interpreter

Based on the background of Matlab, I wanted to write small functions in python and test them separately in the interpreter. However, every time I start the interpreter, I have to import all the modules. On the contrary, with Matlab, all you do is the directory path, and you can execute any matlab function through the interpreter without worrying about what to import.

Is there a way a python interpreter could do this?

+4
source share
2 answers

Try autoimp . Example from a web page:

>>> from autoimp import * >>> os.stat('.') >>> Image.open('test.bmp') >>> pylab.plot([1,2],[3,4]) >>> scipy.linalg.eig([[1,2],[3,4]]) 
+7
source

I also consider myself a MATLAB user who converts to Python. "ipython-pylab" (from a unix shell or Mac shell) does a pretty good job of setting up the variables and functions that I use for MATLAB type calculations.

Also, although it was painful for me to install on my mac, I like Spyder for its resemblance to the MATLAB IDE. In the Spyder environment - as in MATLAB - you can run scripts (.py files compared to .m files in MATLAB) in an interactive window that can import. You can then enter interactively into the window using the functions you imported. Compared to ipython-pylab and autoimport, this allows you to import only the functions / variables you want and keep your workspace uncluttered. This may not be interesting at the moment, but it may come in handy in the end.

0
source

Source: https://habr.com/ru/post/1333337/


All Articles