Python tool to include imported elements

Is there a tool in python to rewrite some code that imports such things that they have nothing more to import?

Take the library that draws the box.py window

def box(text='Hello, World!')
    draw the box magic
    return

Now in another program (let's call it warning.py), it says:

from box import box

box('Warning, water found in hard drive')

Is there a tool that I can use that will see that it imports a window function (or class, for that matter) from the window and inserts this function (or class or even variable definitions) into a warning.py script removing the import line (which makes it more portable)?

Thanks, Narnie

+3
source share
2 answers

, , ?

zipped- , ... .

Python zip , __main__.py.

:.

echo "def foo(): print 'code inside a.py'" > a.py
echo "def bar(): print 'code inside b.py'" > b.py
echo "import a; import b; a.foo(); b.bar()" > __main__.py
zip test.zip a.py b.py __main__.py
rm a.py b.py __main__.py

python test.zip

zip 3- python . python test.zip. . ( , python >= 2.6, ...)

+7

, . py2exe, . linux , . distutils, .

0

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


All Articles