Should Python library modules start with #!/usr/bin/env
python?
Looking at first lines of *.py
in /usr/share/pyshared
(where Python libs are stored in Debian) reveals that there are both files that start with the hashbang line and those that do not.
Is there a reason to include or omit this line?
__init__.py file is not needed from python version 3.3 and above !! All folders from python version 3.3 and above are considered a namespace package. All folders from python 3.3 and above having a __init__.py file are considers a standard package.
There are a group of core libraries you'll need to learn. Pandas should be first. Everything you do is data centric. Next, NumPy… then SciKit-Learn, Matplotlib.
Although Python works without an __init__.py file you should still include one. It specifies that the directory should be treated as a package, so therefore include it (even if it is empty).
No, files can be imported from different directories.
The reason why some files in /usr/share/pyshared
have declared the shebang & some do not are easy to explain. Take the files uno.py
and pyinotify.py
. The former has no shebang and the latter has.
uno.py
is a python module which will be imported and used in other programs/scripts. Thus it will never be executed directly from the command line. On the other hand pyinotify.py
contains the shebang and you can see that it contains the following line at the bottom (it can made into an executable if you run a chmod u+x
on it):
if __name__ == '__main__':
command_line()
You can hardcode the python binary in the shebang, but as others have mentioned, using /usr/bin/env
will make it more portable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With