Skip to content

Instantly share code, notes, and snippets.

@Geoffrey-T
Forked from nicolasramy/python-cs-01-installation.md
Created July 9, 2013 14:23
Show Gist options
  • Save Geoffrey-T/5957727 to your computer and use it in GitHub Desktop.
Save Geoffrey-T/5957727 to your computer and use it in GitHub Desktop.

#Python Cheat Sheet

Basics

This is a short list of different packages to install to enhace your production in Python

pip

pip is a tool for installing and managing Python packages

apt-get install python-pip python-dev build-essential

Virtualenv

virtualenv is a tool to create isolated Python environments. There is 2 ways to install it:

With apt if you have an Ubuntu or Debian system

apt-get install python-virtualenv

With pip if you want to ignore your system package tool

pip install virutalenv

If you use pip to install globally virtualenv with just add sudo before

File Handling

List a directory

you can use glob

import glob
import os
os.chdir("/mydir")
for files in glob.glob("*.txt"):
    print files

or simple os.listdir

import os
os.chdir("/mydir")
for files in os.listdir("."):
    if files.endswith(".txt"):
        print files

or if you want to traverse directory

import os
for r,d,f in os.walk("/mydir"):
    for files in f:
        if files.endswith(".txt"):
             print os.path.join(r,files)

Database

MySQL

To make the libraries available, you have to add this package first:

apt-get install python-mysqldb

CouchDB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment