Python 3
March 30, 2018 — 14:26

Author: silver  Category: dev  Comments: Off

Print modules:

python3 -c "import sys;print (sys.path)"
python3 -c "import sys;print (sys.modules)"
python3 -c "help('modules')"
python3 -c "help('modules package')"
pydoc3 modules

Packages:

  • Location in Debian: /usr/lib/python{3}/dist-packages/pkgname/{__init__.py}
  • Other distro’s use “site-packages”

pip3 install pkgname
pip3 uninstall pkgname
pip3 freeze
python3 -m pip install pkgname

python3
import pip
sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])

Virtualenv:

$ pip3 install virtualenv
$ mkdir workdir && cd workdir
$ virtualenv project
$ source project/bin/activate
$ pip3 install requests

(and/or git clone + python3 setup.py install / etc)

$ deactivate
$ rm -rf project

Strings:

Besides %-format  and str.format() there’s now also f-Strings (since Python 3.6).

Example:

foo="value"

print(f'This string has a variable: {foo}.')

Notes:

  • make sure your script.py does not have the same name as package
  • print syntax changed from python2 to 3: print ("foo")







We use Matomo free and open source web analytics
We also use Jetpack WordPress.com Stats which honors DNT