环境的准备

    CentOS6.5+Python2.6/7+oschina GIT +IPython+RPM 源

    1.RPM源安装:

wKioL1b-kCDw3Cw7AABC7QrEsP8569.png

    2.Python源码安装:

    # yum install -y gcc gcc-c++ readline-devel

    # wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz

    # tar -xf Python-2.7.6.tgz

    # cd Python-2.7.6

    # ./configure

    # make && make install

    

    3.ipython安装(用于调试)

    # yum install -y ipython

    

    4.Git安装(版本控制)

    

# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
    # wget https://www.kernel.org/pub/software/scm/git/git-1.9.4.tar.gz
    # tar xzf git-1.9.4.tar.gz
    # cd git-1.9.4
    # make prefix=/usr/local/git all
    # make prefix=/usr/local/git install
    # echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
    # source /etc/bashrc

 

    5.Git快速使用

    git帮助文档

 

Python一些特性:

    1.第一个Python命令:import this 

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.


    2.Python解释器:

    机器 -> 解释器 -> 代码

    源代码(test.py)被翻译成字节码(test.pyc)加载到虚拟机运行(PVM:python虚拟机)

 

    3.交互模式注意点:

        1.只能输入Python命令;

        2.变量在源代码中如果不print是不会输出到终端,但交互模式会打印变量值;

        3.复合语句用回车结束,源代码中不需要换行;

        4.交互模式是一条条执行语句;

        5.退出交互模式就不能再次引用自定义变量,模块需要再次导出

        6.运行:

            (1)、python scripts.py 

            (2)、./scripts.py (chmod u+x scripts.py)

 

python常用简单技巧:

    1.#/usr/bin/env python  (便于移植)

    2.# -*- coding: UTF-8 -*- (中文字符编码设置)

    3.Python注释:# (''' ''' 多行注释)

    4.tab补全:vi /usr/local/lib/python2.7/tab.py(sys.path环境变量目录编辑保存)

# python startup file
import sys
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter


 

Python帮助:

    1.列模块 help("modules")

    2.列包含字符的模块 help("modules ps")

    3.列类型 help("str") list tunpl

    4.列模块的库 help(os.path)

    5.dir 查看属性:

        example:dir(str)