isinstance(object, classinfo)
Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. Also return true if classinfo is a type object (new-style class) and object is an object of that type or of a (direct, indirect or virtual) subclass thereof. If object is not a class instance or an object of the given type, the function always returns false. If classinfo is neither a class object nor a type object, it may be a tuple of class or type objects, or may recursively contain other such tuples (other sequence types are not accepted). If classinfo is not a class, type, or tuple of classes, types, and such tuples, a TypeError exception is raised.
Changed in version 2.2: Support for a tuple of type information was added.
Source:https://docs.python.org/2/library/functions.html
About '__init__.py'
python的每个模块的包中,都有一个__init__.py文件,有了这个文件,我们才能导入这个目录下的module。
那么,__init__.py还有什么别的功能呢?
其实,__init__.py里面还是可以有内容的,我们在导入一个包时,实际上导入了它的__init__.py文件。
我们可以再__init__.py文件中再导入其他的包,或者模块。
[python]
import readers
import writers
import commands
import users
import meta
import auth
import admin
这样,当我们导入这个包的时候,__init__.py文件自动运行。帮我们导入了这么多个模块,我们就不需要将所有的import语句写在一个文件里了,也可以减少代码量。
不需要一个个去导入module了。
__init__.py 中还有一个重要的变量,叫做 __all__。我们有时会使出一招“全部导入”,也就是这样:
from PackageName import *
这时 import 就会把注册在包 __init__.py 文件中 __all__ 列表中的子模块和子包导入到当前作用域中来。比如:
#文件 __init__.py
__all__ = ["Module1", "Module2", "subPackage1", "subPackage2"]
source:http://www.2cto.com/kf/201204/129388.html
How to easily convert a list to a string for display
There are a few useful tips to convert a Python list (or any other iterable such as a tuple) to a string for display.
First, if it is a list of strings, you may simply use join this way:
>>> mylist = ['spam', 'ham', 'eggs']
>>> print ', '.join(mylist)
spam, ham, eggs
Using the same method, you might also do this:
>>> print '\n'.join(mylist)
spam
ham
eggs
However, this simple method does not work if the list contains non-string objects, such as integers.
If you just want to obtain a comma-separated string, you may use this shortcut:
>>> list_of_ints = [80, 443, 8080, 8081]
>>> print str(list_of_ints).strip('[]')
80, 443, 8080, 8081
Or this one, if your objects contain square brackets:
>>> print str(list_of_ints)[1:-1]
80, 443, 8080, 8081
Finally, you may use map() to convert each item in the list to a string, and then join them:
>>> print ', '.join(map(str, list_of_ints))
80, 443, 8080, 8081
>>> print '\n'.join(map(str, list_of_ints))
80
443
8080
8081
source: http://www.decalage.info/en/python/print_list
IOError: [Errno 22] invalid mode ('r') or filename
test_file=open('c:\\Python27\test.txt','r')
test_file=open(r'c:\Python27\test.txt','r')
or double the slashes:
test_file=open('c:\\Python27\\test.txt','r')
or use forward slashes instead:
test_file=open('c:/Python27/test.txt','r')