From ElectroDragon
Revision as of 10:43, 25 September 2018 by Chao (talk | contribs) (Module/Library)
Jump to navigation Jump to search


  • to check if python installed, you can run python and see the command line >>
  • to check python version in linux run, python -V
  • following content based on python2.7
  • Install python-pip, setuptools, wheels, etc
apt-get install python-pip
pip install -U pip setuptools # get support by setuptools, and
  • Example to use to install package: python install

Proxy Install

for chinese install by - pip install mbed-cli --proxy=


  • Download from here for 2.7., add pip and add system path
  • Set path for system environment for windows, on cmd command, run once, and you can type python directly anytime anywhere in cmd to run python
set path=%path%;C:\Python27\
  • Or open system environment config to setup
  • Install module, downloard tar.gz file, unzip and run command: install


  • Install python 3.2 in linux: apt-get install python3, run by: python3
  • install python3 pip: apt-get install python3-pip
  • install python-dev python-pip: sudo apt-get install python-dev
  • download targ.gz zip file and setup


  • Pip install package
python2   -m pip install SomePackage  # default Python 2
python2.7 -m pip install SomePackage  # specifically Python 2.7
python3   -m pip install SomePackage  # default Python 3
python3.4 -m pip install SomePackage  # specifically Python 3.4


Command description example Header text
comment # for line, """ and """ for paragraph Example Example
print Example print("234") # print string; print 234 # print variable Example
linux bash run #! /usr/bin/python Example Example
Example Example Example Example


String Format

print("I'm %s. I'm %d year old" % ('Vamei', 99))
print ('this is %s %%') (% date) # %% to print %
  • s.strip() .lstrip() .rstrip(',') remove empty space, and special words

Format type

  • print type(aaa) # print type of aaa variable
  • print len(aaa) # print length

Change format

a = float(b) change to type float

Module String


import string
a = 'abcde'
b = string.replace(a, 'ab', '', 1)
print b

file operation

    myfile = open('/srv/www/', 'w')

    myfile = open('/srv/www/', 'a')             # open for output (creates)
    myfile.writelines(line1)        # write a line of text
    myfile.writelines(line2)        # write a line of text


not is evaluated first; and is evaluated next; or is evaluated last.

Group, List, Dict

  • group = (), list = [], dict = {}


  • L[2] 'SPAM!' read the third element
  • L[-2] 'Spam' red the last third element
  • L[1:] ['Spam', 'SPAM!'] cut the list from the second element


Installation by:

List Modules

  • bs4, BeautifulSoup, feedparser,

Pratical Test

  • for loop
for x in range (xxx, 0, -1):


install/unstall a library, first install pip: apt-get install python-pip

pip install datetime
pip uninstall datetime 

common used library

  • Datetime
  • Django


For android

  • install debian jessie, install python-kivy, python-pip
  • install buildozer (pip install), java SDK (default-jdk), cython, etc
  • buildozer init, and run: buildozer set default android_new debug deploy run, android USB debug should turn on
  • buildozer need ANT, SDK, NDK on first time