)
In [9]: ^D
Do you really want to exit ([y]/n)?
odd% python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> f=urllib2.urlopen("http://blake.bcm.edu/dl/test.html")
>>> for i in f: print i
...
My Page
Hi Everyone
This is really just some test text to demonstrate how HTML works. I can do interesting
things like italicize or make text bold, or even both together. ta da
>>> ^D
odd% ipython
Leopard libedit detected.
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: from xml.etree import cElementTree
In [2]: !
In [3]: ^D
Do you really want to exit ([y]/n)? y
odd% ls
20140117114538 launch-VZEk7L
20140125123848 launch-wKcu4o
com.microsoft.office.updater launchd-247.PVLsIw
histdata1.txt launchd-248.dtS7UW
histdata2.txt launchd-530.tilNwM
launch-8GJkjI launchd-974.9dhnbj
odd% /Users/stevel/wp/lecture/2012_01_Intro_Programming/lec7/xml_example.xml
odd% cp /Users/stevel/wp/lecture/2012_01_Intro_Programming/lec7/xml_example.xml /tmp
odd% pwd
/tmp
odd% ls
20140117114538 launch-wKcu4o
20140125123848 launchd-247.PVLsIw
com.microsoft.office.updater launchd-248.dtS7UW
histdata1.txt launchd-530.tilNwM
histdata2.txt launchd-974.9dhnbj
launch-8GJkjI xml_example.xml
launch-VZEk7L
odd% more xml_example.xml
Bloodroot
Sanguinaria canadensis
4
Mostly Shady
2.44
031599
Columbine
Aquilegia canadensis
3
Mostly Shady
9.37
030699
odd% ipython
Leopard libedit detected.
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: from xml.etree import cElementTree
In [2]: et=cElementTree.parse("xml_example.xml")
In [3]: et
Out[3]:
In [4]: et.
et.__class__ et.__module__ et.__subclasshook__ et.getroot
et.__delattr__ et.__new__ et.__weakref__ et.iter
et.__dict__ et.__reduce__ et._root et.iterfind
et.__doc__ et.__reduce_ex__ et._setroot et.parse
et.__format__ et.__repr__ et.find et.write
et.__getattribute__ et.__setattr__ et.findall et.write_c14n
et.__hash__ et.__sizeof__ et.findtext
et.__init__ et.__str__ et.getiterator
In [4]: e=et.getroot()
In [5]: e
Out[5]:
In [6]: e.tag
Out[6]: 'CATALOG'
In [7]: e[0]
Out[7]:
In [8]: e[0][0]
Out[8]:
In [9]: e[0][0].text
Out[9]: 'Bloodroot'
In [10]: e[0][4]
Out[10]:
In [11]: for t in e[0]: print t.tag
....:
COMMON
BOTANICAL
ZONE
LIGHT
PRICE
AVAILABILITY
In [12]: for t in e[0]:
....: if t.tag=="PRICE" : break
....:
In [13]: t
Out[13]:
In [14]: t
Out[14]:
In [15]: t.text
Out[15]: '2.44'
In [16]: t.items
Out[16]:
In [17]: t.items()
Out[17]: [('CURRENCY', 'dollar')]
In [18]: dict(t.items())
Out[18]: {'CURRENCY': 'dollar'}
In [19]: ^D
Do you really want to exit ([y]/n)?
odd% ls
20140117114538 launch-wKcu4o
20140125123848 launchd-247.PVLsIw
com.microsoft.office.updater launchd-248.dtS7UW
histdata1.txt launchd-530.tilNwM
histdata2.txt launchd-974.9dhnbj
launch-8GJkjI xml_example.xml
launch-VZEk7L
odd%