From charlesreid1

Python - the computer language

Python Modules

Security/Networking

Scapy

Olipy

Pyrit

Computing/Numerics

Numpy

Cantera

Fipy

Python Sundials

Data

Pandas

Images

Python Imaging Library

A Few Python Gems

Python/One-Liners

Profiling

Profiling Python Code

See Python/Profiling

Timing Python Code

See Python/Timing

Sizeof Python Lists

To illustrate table doubling and checking the "real" size of a list (under the hood) based on the memory allocated and not just the number of elements:

See Arrays/Python/Sizeof

Resources

This Wiki

All pages on this wiki categorized Python: Category:Python

The old Python page: Old Python Page

Code Golf with Python

Python/Golf

Awesome Python

Awesome-python: https://awesome-python.com/ (github repo here: [1])

Wow, just... wow.

Learning Python

# it's about damn time
alias python='python3'

Why you shouldn't use "Learn Python the Hard Way": http://sopython.com/wiki/LPTHW_Complaints

List of recommended Python tutorials: http://sopython.com/wiki/What_tutorial_should_I_read%3F

Ebook: Dive Into Python 3: http://www.diveintopython3.net/

Installing and Uninstalling Modules

Installing Automatically

To install a package automatically for Python 2:

pip install mymodule
# or
pip2 install mymodule

to update all packages it depends on, use the -U flag:

pip install -U mymodule

For Python3,

pip3 install mymodule

Installing Manually

System Wide Installation

To install system-wide:

cd mymodule
python setup.py build
python setup.py install

User-Specific

To install a module for a single user, use the --user flag:

In Python2:

cd mymodule
python setup.py build
python setup.py install --user

In Python3, the above command results in this error:

error: can't combine user with prefix, exec_prefix/home, or install_(plat)base

So add an empty --prefix flag:

python setup.py build
python setup.py install --user --prefix=

Uninstalling Automatically

To uninstall something using pip, just tell it uninstall:

pip uninstall mymodule

Uninstalling Manually

This is a bit more tricky, and requires you do some preparation when you install the package (or at least remember how you installed it). When you run setup.py to install software, you can tell it to make a record of every file it updates. Then, to uninstall, you can just remove all of those files.

When installing, use the --record flag:

python3 setup.py install --user --prefix= --record files.txt

Then, when you're ready to uninstall, feed files.txt to the remove command:

cat files.txt | xargs rm -rf


Building Packages

Setup.py

See Python/Setup.py


Checking Across Versions

To check if something installs OK across versions of Python, use this bash script:

for i in 2.7 3.3 3.4 3.5 3.6; do 
  mktmpenv -p /tmp/python/$i/bin/python --no-wheel 
  pip install mymodule
  deactivate
done

via [2]

Removing

Removing Python.org Python

Via http://bugs.python.org/issue7107:

tmpfile=/tmp/generate_file_list
cat <<"NOEXPAND" > "${tmpfile}"
#!/bin/sh
version="${1:-"2.6"}"
file -h /usr/local/bin/* | grep \
"symbolic link to ../../../Library/Frameworks/Python.framework/"\
"Versions/${version}" | cut -d : -f 1
echo "/Library/Frameworks/Python.framework/Versions/${version}"
echo "/Applications/Python ${version}"
set -- Applications Documentation Framework ProfileChanges \
         SystemFixes UnixTools
for package do
  echo "/Library/Receipts/Python${package}-${version}.pkg"
done
NOEXPAND
chmod  ug+x ${tmpfile}

This script lists all files/top-level directories to be removed:

  ${tmpfile} 2.6

To actually delete the files:

  ${tmpfile} 2.6 | sed -e "s/^.*$/sudo rm -r \"&\"/g" | sh

Tests

how to write tests in Python:

Python/Tests


Flags