- https://pythonhosted.org/an_example_pypi_project/sphinx.html
- https://pythonhosted.org/an_example_pypi_project/sphinx.html#full-code-example
- https://pythonhosted.org/an_example_pypi_project/pkgcode.html
class MyClass: def method(self): ':rtype unittest.TestCase'
class MyClass: def method(self, a): ':type a: TestCase' #Note that just the class name is accepted, but in this case, #it'll search for a TestCase class in the whole workspace
class MyClass: def method(self, a): ':param TestCase a:'
class MyClass: def method(self, lst): #Can be on the same line for a in lst: #: :type a: GUITest a.;
class MyClass: def method(self, lst): #Or on the line before #: :type a: GUITest for a in lst: a.;
class MyClass: def method(self, lst): #If commented as a docstring must be on the #line after for a in lst: ': :type a: GUITest' a.;
class MyClass: def method(self): '@rtype unittest.TestCase'
class MyClass: def method(self, a): '@type a: TestCase' #Note that just the class name is accepted, but in this case, #it'll search for a TestCase class in the whole workspace
[str(elem) for elem in list]..
import xml.etree.ElementTree as ET ... ...When executing the file, it raises the following error:
ImportError: No module named etree.ElementTreeAccording the stackoverflow post, it was caused by the moudle file name xml.py, rename the xml.py to something else resolved the issue.
import xml.etree.ElementTree as ET # element is an xml.etree.ElementTree.Element object xmlstr = ET.tostring(element, encoding='utf8', method='xml')
import xml.etree.ElementTree as ET tree = ET.parse('/home/wilson/my.xml') root = tree.getroot()
import xml.etree.ElementTree as ET root = ET.fromstring('1')
class A: def object_m(self,x): print "executing object_m(%s,%s)"%(self,x) @classmethod def class_m(cls,x): print "executing class_m(%s,%s)"%(cls,x) @staticmethod def static_m(x): print "executing static_m(%s)"%xAccording to stackoverflow:
def f(arg): if isinstance(arg, ClassA): print('A') elif isintance(arg, ClassB): print('B') elif issubclass(arg, ClassC): print('subclass of C') else: print("D")
def f(arg): if type(arg) is str: print "str" elif type(arg) is int: print "int" elif type(arg) is dict: print "dict" else: print "unsupported"
all_descendants = list(element.iter())
children = list(element)
for name in dict.keys(): print(name) print(dict[name])
values = [ dict[name] for name in dict.keys() ]
list2 = [ unicode(e.strip()) for e in list1 ]
list2 = [ unicode(e.strip()) if e is not None else '' for e in list1 ]