Embed
Email

Python Cheat Sheet

Document Sample
Python Cheat Sheet
sys Variables String Methods Datetime Methods



argv Command line args capitalize() * lstrip() today() fromordinal(ordinal)

builtin_module_names Linked C modules center(width) partition(sep) now(timezoneinfo) combine(date, time)

byteorder Native byte order count(sub, start, end) replace(old, new) utcnow() strptime(date, format)

check_interval Signal check frequency decode() rfind(sub, start ,end) fromtimestamp(timestamp)

exec_prefix Root directory encode() rindex(sub, start, end) utcfromtimestamp(timestamp)

executable Name of executable endswith(sub) rjust(width)

exitfunc Exit function name expandtabs() rpartition(sep)

Time Methods

modules Loaded modules find(sub, start, end) rsplit(sep)

path Search path index(sub, start, end) rstrip() replace() utcoffset()

platform Current platform isalnum() * split(sep) isoformat() dst()

stdin, stdout, stderr File objects for I/O isalpha() * splitlines() __str__() tzname()

version_info Python version info isdigit() * startswith(sub) strftime(format)

winver Version number islower() * strip()

isspace() * swapcase() *

Date Formatting (strftime and strptime)

istitle() * title() *

sys.argv for $ python foo.py bar qux

isupper() * translate(table) %a Abbreviated weekday (Sun)

sys.argv[0] foo.py join() upper() * %A Weekday (Sunday)

sys.argv[1] bar ljust(width) zfill(width) %b Abbreviated month name (Jan)

sys.argv[2] qux lower() * %B Month name (January)

%c Date and time

Methods marked * are locale %d Day (leading zeros) (01 to 31)

os Variables Note dependant for 8-bit strings. %H 24 hour (leading zeros) (00 to 23)

altsep Alternative sep %I 12 hour (leading zeros) (01 to 12)

curdir Current dir string %j Day of year (001 to 366)

List Methods

defpath Default search path %m Month (01 to 12)

devnull Path of null device append(item) pop(position) %M Minute (00 to 59)

extsep Extension separator count(item) remove(item) %p AM or PM

linesep Line separator extend(list) reverse() %S Second (00 to 61 4)

name Name of OS index(item) sort() %U Week number 1

(00 to 53)

pardir Parent dir string insert(position, item) %w Weekday 2

(0 to 6)

pathsep Patch separator %W Week number 3

(00 to 53)

sep Path separator %x Date

File Methods

%X Time

Registered OS names: “posix”, “nt”, close() readlines(size) %y Year without century (00 to 99)

Note “mac”, “os2”, “ce”, “java”, “riscos” flush() seek(offset) %Y Year (2008)

fileno() tell() %Z Time zone (GMT)

isatty() truncate(size) %% A literal "%" character (%)

Class Special Methods

next() write(string)

__new__(cls) __lt__(self, other) read(size) writelines(list) 1. Sunday as start of week. All days in a

__init__(self, args) __le__(self, other) readline(size) new year preceding the first Sunday

__del__(self) __gt__(self, other) are considered to be in week 0.

__repr__(self) __ge__(self, other) Indexes and Slices (of a=[0,1,2,3,4,5])

__str__(self) __eq__(self, other) 2. 0 is Sunday, 6 is Saturday.

__cmp__(self, other) __ne__(self, other) len(a) 6

__index__(self) __nonzero__(self) a[0] 0 3. Monday as start of week. All days in a

__hash__(self) a[5] 5 new year preceding the first Monday

__getattr__(self, name) a[-1] 5 are considered to be in week 0.

__getattribute__(self, name) a[-2] 4

__setattr__(self, name, attr) a[1:] [1,2,3,4,5] 4. This is not a mistake. Range takes

__delattr__(self, name) a[:5] [0,1,2,3,4] account of leap and double-leap

__call__(self, args, kwargs) a[:-2] [0,1,2,3] seconds.

a[1:3] [1,2]

a[1:-1] [1,2,3,4]

b=a[:] Shallow copy of a Available free from AddedBytes.com


Related docs
Other docs by Jeffreywood
WATER MIST SYSTEM CHECK SHEET
Views: 188  |  Downloads: 4
METAL SHELL 2000 series - Sheet
Views: 9  |  Downloads: 0
Summer 2003 Cover Sheet
Views: 17  |  Downloads: 0
Product Description Sheet
Views: 23  |  Downloads: 0
History Fact Sheet
Views: 2  |  Downloads: 0
HEAD START FACT SHEET
Views: 10  |  Downloads: 0
Fruit Fact Sheet
Views: 22  |  Downloads: 0
Behavior Disorders Intervention Tip Sheet
Views: 36  |  Downloads: 1
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!