python's import mechanism
摘要:[python's import mechanism] 问题描述: 该如何解决呢? 动态解决就行了。 import sys sys.modules 就是所有modules的容器,通过sys.modules动态引用即可。
阅读全文
python安装
摘要:[python安装] 安装 $ tar –jxvf Python-2.5.2.tar.bz2 $ cd Python-2.5.2 $ ./configure $ make $ make install 参考:http://www.cnblogs.com/ewyb/archive/2010/10/26/1861744.html
阅读全文
python's object model
摘要:[python's object model] 1、object.__init__(self[,...]) 如果subclass没有实现__init__,那么python类在实例化的时候,显然会调用到父ClassObject的__init__,所以在subclass没实现__init__的时候,对象可以正常实现继承特性。 如果subclass实现了__init__,但是没有调用super的__init__,则父类实例中的变量在子类实例中不会存在,因为没有执行父ClassObject的__init__,所以无法正常实现继承特性。 If a base class has an__init.
阅读全文
python's nonlocal
摘要:[python's nonlocal] nonlocal是python3.x中新加的关键字,用于引用本作用域外层作用域的名字 参考:http://blog.csdn.net/chain2012/article/details/7415602
阅读全文
python之name binding
摘要:[python之name binding]1. 名字 名字是对一个对象的称呼,一个对象可以只有一个名字,也可以没有名字或取多个名字。但对象自己却不知道有多少名字,叫什么,只有名字本身知道它所指向的是个什么对象。给对象取一个名字的操作叫作命名,python将赋值语句认为是一个命名操作(或者称为名字绑定)。 名字在一定的名字空间内有效,而且唯一,不可能在同一个名字空间内有两个或更多的对象取同一名字。 让我们再来看看本篇的第一个例子:i = 1。在python中,它有如下两个含义:* 创建一个值为1的整型对象* "i"是指向该整型对象的名字(而且它是一个引用)2. 绑定 如上所讲
阅读全文
python之private variables
摘要:[python之private variables] “Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g._spam) should be treated as a non-public part of the API (.
阅读全文
python之with...as
摘要:[python之with...as] 参考:http://python.42qu.com/11155501
阅读全文
python变量作用域
摘要:[python变量作用域] 几个概念:python能够改变变量作用域的代码段是def、class、lamda.if/elif/else、try/except/finally、for/while 并不能涉及变量作用域的更改,也就是说他们的代码块中的变量,在外部也是可以访问的变量搜索路径是:本地变量->全局变量 所以一个变量a在method内找不到的话,就会在全局作用域内找,所以method内无法访问class中的变量.python能够改变变量作用域的代码段是def、class、lamda, 意即 if/for/while中的变量可以在同一个函数内被访问到 参考:http://blog...
阅读全文
wait&waitpid状态值
摘要:[wait&waitpid状态值] 1. python 中 os.system 的返回值的format与wait的返回值status一致: On Unix, the return value is the exit status of the process encoded in the format specified forwait() os.system直到命令进程执行完毕才返回, SIGSTOP把子进程暂停, os.system也依旧阻塞 2. os.wait的返回值, 在不同的情况下有不同的含意, 需通过 头文件中的宏来操作 3. 若waitpid加入了WNOHAN...
阅读全文
python之private variable
摘要:【python之private variable】 Since there is a valid use-case for class-private members (namely to avoid name clashes of names with names defined by subclasses), there is limited support for such a mechanism, calledname mangling. Any identifier of the form__spam(at least two leading underscores, at mos.
阅读全文
python实例、类方法、静态方法
摘要:【python实例、类方法、静态方法】 参考:http://blog.163.com/yang_jianli/blog/static/161990006201122411586729/
阅读全文
python常用option
摘要:【python常用option】 1. -c cmd : program passed in as string (terminates option list) 解析字符串命令,不读cmd之后的option 2. -i : inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x 运行完输入脚本后,进入交互模式,通常用于自己检测状态 3. -m mod : run libra...
阅读全文
split
摘要:[split]1.str.split([sep[,maxsplit]])Return a list of the words in the string, usingsepas the delimiter string. Ifmaxsplitis given, at mostmaxsplitsplits are done (thus, the list will have at mostmaxsplit+1elements). Ifmaxsplitis not specified or-1, then there is no limit on the number of splits (all
阅读全文
python中os.system()的返回值
摘要:[python中os.system()的返回值] 如果第三方程序返回的是布尔型返回值,os.system会将true转为1,false转为0进行返回。问题: /bin/xxx.py是一个返回码为1的程序。 当python 程序使用os.system(”./bin/xxx.py”) 这样调用的时...
阅读全文
python之time&datetime
摘要:【time】 secs:统一值,无local、UTC之分。 struct_time:有local、UTC之分。 time.time():返回secs,secs为统一值,无local&utc之分。 time.localtime([secs]):secs => local struct_time。output:struct_time。 tim.gmtime([secs]):secs => utc struct_time。output:struct_time。 time.asctime():返回字符串时间, 参数为struct_time,如果无参数,则使用localtime(ti
阅读全文
python之daemon线程
摘要:[python之daemon线程] A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon
阅读全文
Python之ConfigParser
摘要:[Python之ConfigParser] ConfigParser是一个读取/写入类似于windows ini的配置文件的类. 参考:http://blog.chinaunix.net/uid-25890465-id-3312861.html 官方文档:http://docs.python.org/2.7/library/configparser.html#ConfigParser.ConfigParser.get
阅读全文
pdb调试
摘要:[pdb调试] 前置技能: os.getcwd():获取当前工作目录。 os.chdir():切换工作目录。 运行 python -m pdb myscript.py (Pdb) 会自动停在第一行,等待调试,这时你可以看看 帮助 (Pdb) h 说明下这几个关键 命令 >断点设置 ...
阅读全文
Python Modules
摘要:[Python Modules] 1. a module is a python source file. 2. a package is a directory with a __init__.py file within it. 1) 如果目录下没有__init__.py文件, 则python不
阅读全文
python's @property
摘要:[python's @property] 参考:http://docs.python.org/3/library/functions.html?highlight=property#property
阅读全文