python: int and long are unified

Since Python 2.4, int and long are unified. Furthermore, from Python 3, int is the only type for integer, which has the capacity of long in Python 2.

sys.maxint returns the maximum integer number that Python can hold.

see also

python: parse boolean from string

def parse_bool(s):
return s.lower() in ("yes", "true", "T", "1")


bool('foo') # True
bool('') # False
You can not use the above function to parse boolean from string.

python: check if a variable is a integer

if isinstance(var, int):
print("It is integer")
On python 2:

if is instance(var, (int, long)):
print("It is integer")

Windows XP: change MAC address

  1. In Control Panel -> Network Connections, and right-click on the network connection you want to change MAC address for. (It can be a wireless or local area connection) then select Properties.
  2. On the General tab, click the Configure button
  3. Now click on the Advanced tab and select on the “Locally Administered Address” property or the “Network Address” property.
  4. Change the Value from Not present to the MAC address you want to set: e.g. 112233445566

Eclipse on Mac OS X: key combo for Java refactoring does not work after installing pydev

PyDev bind Command+Option+R to 'Set Next Statement' which is conflicting with Java refactor shortcut key combo.
To restore the Java refactor key combo (and deactivate the key combo for PyDev):
  1. Eclipse -> Preferences... -> General -&gt Keys
  2. Sort by Binding by clicking the Binding column header
  3. Select the row: Command: Set Next Statement and Category: Python - Run
  4. Click "Unbind Command" button
  5. Select the row: Command: Rename - Refactoring and Category: Refactor - Java
  6. Click to select Binding field
  7. Type Command+Option+R
  8. Click Apply button then OK button to save.

see also

python: check if a variable is a string

import sys

if isinstance(var, basestring if sys.version_info[0]<3 else str):
print("it is string") # var is string

see also

python: conditional expression

x = true_value if condition else false_value

if isinstance(s, basestring if sys.version_info[0]<3 else str):
print('It is a str.')

see also

python: dictionary comprehension

dict = { 'a':1, 'b':2 }
dict = { k: str(dict[k]) for k in dict.keys() }

main function in python module

class A:
def __init__(self):

def main():
print("Hello World")

if __name__ == '__main__':

see also

Google coding style guide for Python

Google code style for python.

git: revert back to a specific version

  • Command 1: Revert back to previous version(Note: substitute to your commit hash.):
    git reset --hard 76f134a2692c9472af3227d2f9fdb50548de6c0c
    git clean -f # clean up local repository
    git push -f # push back to central repository
  • Command 2: The following command reverts everything from the HEAD back to the commit hash:
    git revert --no-commit 76f134a2692c9472af3227d2f9fdb50548de6c0c..HEAD

see also

git: list all the files for a particular commit

Use one of the commands below:
  • git show --name-only 76f134a2692c9472af3227d2f9fdb50548de6c0c
  • git diff-tree --no-commit-id --name-only -r 76f134a2692c9472af3227d2f9fdb50548de6c0c
  • ggit show --pretty="format:" --name-only 76f134a2692c9472af3227d2f9fdb50548de6c0c