Tag Archives: scripting

Python Quick Reference

sys variables
argv                                                  Command line args
builtin_module_names         Linked C modules
byteorder                                     Native byte order
check_interval                           Signal check frequency
exec_prefix                                  Root directory
executable                                   Name of executable
exitfunc                                         Exit function name
modules                                        Loaded modules
path                                                 Search path
platform                                        Current platform
stdin, stdout, stderr                File objects for I/O
version_info                                Python version info
winver                                            Version number

sys.argv for $python map.py loc -c zip –h
sysargv[0]                                   map.py
sysargv[1]                                   loc
sysargv[2]                                   -c
sysargv[3]                                   zip
sysargv[4]                                   –h

os variables
altsep                                             Alternate sep
curdir                                             Current dir string
defpath                                         Default search path
devnull                                          Path of null device
extsep                                            Extension separator
linesep                                           Line separator
name                                               Name of OS
pardir                                             Parent dir string
pathsep                                         Path separator
sep                                                   Path separator

Class Special Methods
__new__(cls)
__init__(self, args)
__del__(self)
__repr__(self)
__str__(self)
__cmp__(self, other)
__index__(self)
__hash__(self)
__getattr__(self, name)
__getattribute__(self, name)
__setattr__(self, name, attr)
__delattr__(self, name)
__call__(self, args, kwargs)
__lt__(self, other)
__le__(self, other)
__gt__(self, other)
__ge__(self, other)
__eq__(self, other)
__ne__(self, other)
__nonzero__(self)

String Methods
capitalize()                                  //locale dependent for 8-bit strings
center(width)
count(sub, start, end)
decode()
encode()
endswith(sub)
expandtabs()
find(sub, start, end)
index(sub, start, end)
isalnum()                                  //locale dependent for 8-bit strings
isalpha()                                   //locale dependent for 8-bit strings
isdigit()                                    //locale dependent for 8-bit strings
islower()                                 //locale dependent for 8-bit strings
isspace()                                 //locale dependent for 8-bit strings
istitle()                                    //locale dependent for 8-bit strings
isupper()                               //locale dependent for 8-bit strings
join()
ljust(width)
lower()                                   //locale dependent for 8-bit strings
lstrip()
partition(sep)
replace(old, new)
rfind(sub, start, end)
rindex(sub, start, end)
rjust(width)
rpartition(sep)
rsplit(sep)
rstrip()
split(sep)
splitlines()
startswith(sub)
strip()
swapcase()                        //locale dependent for 8-bit strings
title()                                   //locale dependent for 8-bit strings
translate(table)
upper()                              //locale dependent for 8-bit strings
zfill(width)

List Methods
append(item)
count(item)
extend(list)
index(item)
insert(position, item)
pop(position)
remove(item)
reverse()
sort()

File Methods
close()
flush()
fileno()
isatty()
next()
read(size)
readline(size)
readlines(size)
seek(offset)
tell()
truncate(size)
write(string)
writelines(list)

Indexes and Slices (of a=[0,1,2,3,4,5])
len(a)               6
a[0]                   0
a[5]                   5
a[-1]                 5
a[-2]                 4
a[1:]                  [1,2,3,4,5]
a[:5]                  [0,1,2,3,4]
a[:-2]                [0,1,2,3]
a[1:3]               [1,2]
a[1:-1]             [1,2,3,4]
b=a[:]               Shallow copy of a

Datetime Methods
today()
now(timezoneinfo)
utcnow()
fromtimestamp(timestamp)
utcfromtimestamp(timestamp)
fromordinal(ordinal)
combine(date, time)
strptime(date, format)

Time Methods
replace()
isoformat()
__str__()
strftime(format)
utcoffset()
dst()
tzname()

Date Formatting (strftime and strptime)
%a                 Abbreviated weekday (Tues)
%A                Weekdday (Tuesday)
%b                 Abbreviated month name (Nov)
%B                Month name (November)
%c                 Date and Time
%d                Day (leading zeros) (01 to 31)
%H               24 hour (leading zeros) (00 to 23)
%I                 12 hour (leading zeros) (01 to 12)
%j                 Day of year (001 to 366)
%m              Month (01 to 12)
%M             Minute (00 to 59)
%p               AM or PM
%S               Second (00 to 61) //range takes account of leap and double
leap seconds
%U              Week number (00 to 53) //Sunday is start of week. All days
in a new year preceding the first Sunday are considered to
be in week 0.
%w              Weekday (0 to 6) //0 is Sunday, 6 is Saturday
%W             Week number (00 to 53) //Monday as start of week. All
days in a neew year preceding the first Monday are
considered to be in week 0.
%x                Date
%X               Time
%y                Year without century (00 to 99)
%Y               Year (2016)
%Z               Time zone (GMT)
%%              A literal “%” character (%)

PHP Quick Reference

Array Functions
array_diff (arr1, arr2 …)
array_filter (arr, function)
array_flip (arr)
array_intersect (arr1, arr2 …)
array_merge (arr1, arr2 …)
array_pop (arr)
array_push (arr, var1, var2 …)
array_reverse (arr)
array_search (sysrecon, arr)
array_walk (arr, function)
count (count)
in_array (sysrecon, phpquickrefference)

String Functions
crypt (str, salt)
explode (sep, str)
implode (glue, arr)
nl2br (str)
sprints (frmt, args)
strip_tags (str, allowed_tags)
str_replace (search, replace, str)
strpos (str, sysrecon)
strive (str)
strstr (str, sysrecon)
strtolower (str)
strtoupper (str)
substr (string, start, len)

Filesystem Functions
clearstatcache ()
copy (source, dest)
fclose (handle)
fgets (handle, len)
file (file)
filetime (file)
filesize (file)
file_exists (file)
fopen (file, mode)
fread (handle, len)
fwrite (handle, str)
readfile (file)

fopen() Modes
r         Read
r+      Read and write, prepend
w       Write, truncate
w+    Read and write, truncate
a        Write, append
a+     Read and write, append

Regular Expression Functions
ereg (pattern, str)
split (pattern, str)
ereg_replace (pattern, replace, str)
preg_grep (pattern, arr)
preg_match (pattern, str)
preg_match_all (pattern, str, arr)
preg_replace (pattern, replace, str)
preg_split (pattern, str)

Regular Expression Syntax
^                    Start string
$                     End String
.                       Any single character
(a|b)              a or b
(…)                Group section
[abc]              Item in range (a,b or c)
[^abc]           Not in range (not a,b or c)
\s                     White space
a?                     Zero or one of a
a*                     Zero or more of a
a*?                   Zero or more of a, ungreedy
a+                    One or more of a
a+?                  One or more of a, ungreedy
a{3}                 Exactly 3 of a
a{3,}                3 or more of a
a{,6}                Up to 6 of a
a{3,6}             3 to 6 of a
a{3,6}?           3 to 6 of a, ungreedy
\                        Escape character
[:punct:]       Any punctuation symbol
[:space:]       Any space character
{;blank:]        Space or tab

PCRE Modifiers
i         Case insensitive
s         Period matches new ine
m       ^ and $ match lines
U       Ungreedy matching
e        Evaluate replacement
x        Pattern over several lines

Date and Time Functions
checkdate (month, day, year)
date (format, timestamp)
getdate (timestamp)
mktime (hr, min, sec, month, day, yr)
strftime (formatstring, timestamp)
strtotime (str)
time()

Date Formatting
Y         4 digit year (2016)
y          2 digit year (16)
F          Long month (November)
M        Short month (Nov)
m         Month (01 to 12) //with leading zeros
n          Month (1 to 12)
D         Short day name (Fri)
l           Long day name (Friday) (lowercase L)
d         Day (01 to 31) //with leading zeros
j          Day (1 to 31)
h        12 Hour (01 to 12) //with leading zeros
g        12 Hour (1 to 12)
H       24 Hour (00 to 23) //with leading zeros
G       24 Hour (0 to 23)
i         Minutes (00 to 59) //with leading zeros
s        Seconds (00 to 59) //with leading zeros
w      Day of week (0 to 6) //0 is Sunday, 6 is Saturday
z        Day of year (0 to 365)
W      Week of year ( 1 to 53) //Week that overlaps two years belongs to the year that contains the most days of that week. date(“W”, mktime(0,0,0,12,8,$year)) always gives correct number of weeks in $year.
t         Days in month (28 to 31
a         am or pm
A        AM or PM
B        Swatch Internet Time (000 to 999)
S         Ordinal Suffix (st,nd,rd,th)
T         Timezone of machine (GMT)
Z         Timezone offset (seconds)
O        Difference to GMT (hours) (e.g., +0200)
I           Daylight saving (1 or 0)
L          Leap year (1 or 0)
U         Seconds since Epoch //The Epoch is the 1st of January 1970
c           ISO 8601 (PHP5) //2016-06-09T08:54:23+1:00
r           RFC 2822 //Thu, 09 June 2016 08:54:23 +0100