字符串
https://www.cnblogs.com/dreamer-fish/p/3818443.html
python 学习
http://www.runoob.com/python/python-for-loop.html
字符与数字转换
2、如果你需要捕获命令的输出结果,那么你就需要使用subprocess.Pope
http://blog.csdn.net/carolzhang8406/article/details/22286913
p = subprocess.Pope
p.wait() //可能导致死锁
代码中经常会有变量是否为None的判断,有三种主要的写法:
第一种是`if x is None`;
第一种是`if x is not None`;
第二种是 `if not x:`;
第三种是`if not x is None`(这句这样理解更清晰`if not (x is None)`)
在python中 None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于False ,即:
not None == not False == not '' == not 0 == not [] == not {} == not ()
因此在使用列表的时候,如果你想区分x==[]和x==None两种情况的话, 此时`if not x:`将会出现问题:
也许你是想判断x是否为None,但是却把`x==[]`的情况也判断进来了,此种情况下将无法区分。
对于习惯于使用if not x这种写法的pythoner,必须清楚x等于None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()时对你的判断没有影响才行。
而对于`if x is not None`和`if not x is None`写法,很明显前者更清晰,而后者有可能使读者误解为`if (not x) is None`,因此推荐前者,同时这也是谷歌推荐的风格
结论:
`if x is not None`是最好的写法,清晰,不会出现错误,以后坚持使用这种写法。
使用if not x这种写法的前提是:必须清楚x等于None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()时对你的判断没有影响才行。
不过这并不适用于变量是函数的情况
if foo is None: pass
if foo == None: pass
http://www.jb51.net/article/93165.htm
https://stackoverflow.com/questions/26595/is-there-any-difference-between-foo-is-none-and-foo-none
class
A(
object
):
def
foo(
self
,x):
#类实例方法
print
"executing foo(%s,%s)"
%
(
self
,x)
@
classmethod
def
class_foo(
cls
,x):
#类方法
print
"executing class_foo(%s,%s)"
%
(
cls
,x)
@
staticmethod
def
static_foo(x):
#静态方法
print
"executing static_foo(%s)"
%
x
|
调用方法:
1
2
3
4
5
6
7
8
|
a
=
A()
a.foo(
1
)
/
/
print
: executing foo(<__main__.A
object
at
0xb77d67ec
>,
1
)
a.class_foo(
1
)
/
/
executing class_foo(<
class
'__main__.A'
>,
1
)
A.class_foo(
1
)
/
/
executing class_foo(<
class
'__main__.A'
>,
1
)
a.static_foo(
1
)
/
/
executing static_foo(
1
)
A.static_foo(
1
)
/
/
executing static_foo(
1
)
|
类方法和静态方法都可以被类和类实例调用,类实例方法仅可以被类实例调用。
类方法的隐含调用参数是类,而类实例方法的隐含调用参数是类的实例,静态方法没有隐含调用参数。
python 类介绍:
http://blog.csdn.net/dreamhua927/article/details/52461816
print 'farg:', farg
for value in args:
print 'another arg:', value
def func_var_kwargs(farg, **kwargs):
print 'arg:', farg
for key in kwargs:
print 'another pair arg [%s: %s]' %(key, kwargs[key])
if __name__ == '__main__':
func_var_args(1, 'two', 3)
print '========================================'
func_var_kwargs(farg=1, myarg2='two', myarg3=3)
print '========================================'
#不带参数也是可以的
func_var_args(1)
print '========================================'
func_var_kwargs(2)
xml
package.
xml.etree.ElementTree
: the ElementTree API, a simple and lightweight XML processor- Source code: Lib/xml/etree/ElementTree.py
Element
constructor or theSubElement()
factory function.Element
has some useful methods that help iterate recursively over all the sub-tree below it (its children, their children, and so on). For example,Element.iter()
Element.findall()
finds only elements with a tag which are direct children of the current element.
Element.find()
finds the
first child with a particular tag, and
Element.text
accesses the element’s text content.
Element.get()
accesses the element’s attributes:
This module allows you to spawn processes, connect to their
input/output/error pipes, and obtain their return codes.
For a complete description of this module see the Python documentation.
Main API
========
call(...): Runs a command, waits for it to complete, then returns
the return code.
check_call(...): Same as call() but raises CalledProcessError()
if return code is not 0
check_output(...): Same as check_call() but returns the contents of
stdout instead of a return code
Popen(...): A class for flexibly executing a command in a new process
def call(*popenargs, **kwargs):
"""Run command with arguments. Wait for command to complete, then
return the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
retcode = call(["ls", "-l"])
"""
return Popen(*popenargs, **kwargs).wait()
http://blog.csdn.net/MTbaby/article/details/53159053
微信跳一跳
http://blog.csdn.net/mtbaby/article/details/79000399