継続は力にゃりん。毎日続けることができるのか?
とばし
* filecmp 大半
* イテレータ型
* a.copy()
* MatchObject オブジェクト expand(template)
* 6.9.6 tzinfo オブジェクト
* 6.1.2 ファイルオブジェクトの生成
* 6.1.3 ファイル記述子の操作
積み残し
* オブジェクト指向な機能:継承。親のメソッドを呼ぶ。super 使用
進捗
* 2007-11-01 中断
* 2007-10-14 xml.parsers.expat (途中)
* 2007-10-03 HTMLParser
* 2007-09-24 shutil
* 2007-09-14 string.Template
* 2007-08-30 itertools
* 2007-07-30 operator
* 2007-07-28 cStringIO
* 2007-07-15 StringIO
* 2007-05-06 プログラミング言語 Cアンサー・ブック
* 2007-04-05 unittest
* 2007-03-09 types
* 2007-02-21 zipfile
* 2007-01-25 tarfile
* 2007-01-02 日本語の扱い
* 2006-11-20 optparse
* 2006-10-25 set(集合)型
* 2006-09-05 オブジェクト指向な機能
* 2006-08-13 mhlib
* 2006-07-29 csv
* 2006-06-26 sys
* 2006-06-11 urllib
* 2006-05-20 shlex
* 2006-05-15 放浪
* 2006-04-29 platform
* 2006-04-10 Ruby との比較 正規表現 関係(String, Enumerable)
* 2006-04-02 Ruby との比較 Dir
* 2006-02-19 Ruby との比較 File
* 2006-01-20 Ruby との比較 ハッシュ
* 2006-01-09 Ruby との比較 配列(Enumerable)
* 2005-11-25 Ruby との比較 配列
* 2005-10-11 Ruby との比較 文字列
* 2005-09-20 Ruby との比較 数
* 2005-09-18 Ruby との比較 Bool
* 2005-08-26 勝手に例題 フィルタ編
* 2005-04-28 チュートリアル
* 2005-04-23 filecmp
* 2005-04-22 pydoc
* 2005-04-21 __future__
* 2005-04-20 __main__
* 2005-04-19 __builtin__
* 2005-04-18 dl
* 2005-03-29 difflib
* 2005-03-21 zlib
* 2005-03-20 getpass
* 2005-03-14 urlparse
* 2005-03-13 fnmatch
* 2005-03-12 glob
* 2005-03-08 getopt
* 2005-02-01 os
* 2005-01-04 os.path
* 2004-12-25 fileinput
* 2004-12-02 Set
* 2004-11-22 calendar
* 2004-10-26 datetime
* 2004-10-15 textwrap
* 2004-10-05 random
* 2004-09-17 math
* 2004-08-18 re
* 2004-07-18 string
!2007-10-31 Wed
>>> import xml.parsers.expat
>>> def processing_instruction(target, data):
... print 'ProcessingInstruction:', target, data
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.ProcessingInstructionHandler = processing_instruction
>>> p.Parse("""
... Text goes here
... More text
... """)
1
>>> p = xml.parsers.expat.ParserCreate()
>>> p.ProcessingInstructionHandler = processing_instruction
>>> p.Parse("""
...
...
...
... """)
1
?
!2007-10-30 Tue
>>> import xml.parsers.expat
>>> import xml.parsers.expat
>>> def attlistdecl(elname, attname, type, default, required):
... print 'AttlistDecl: ', elname
... print 'AttlistDecl: ', attname
... print 'AttlistDecl: ', type
... print 'AttlistDecl: ', default
... print 'AttlistDecl: ', required
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.AttlistDeclHandler = attlistdecl
>>> p.Parse("""
... Text goes here
... More text
... """)
1
?
!2007-10-29 Mon
>>> import xml.parsers.expat
>>> def element_decl(name, model):
... print 'Element Decl:', name, model
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.ElementDeclHandler = element_decl
>>> p.Parse("""
... Text goes here
... More text
... """)
1
>>> import xml.parsers.expat
>>> def element_decl(name, model):
... print 'Element Decl:', name, model
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.ElementDeclHandler = element_decl
>>> p.Parse("""
...
...
...
... """)
1
?
!2007-10-28 Sun
>>> import xml.parsers.expat
>>> def end_doctype():
... print 'End DocType'
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.EndDoctypeDeclHandler = end_doctype
>>> p.Parse("""""")
End DocType
1
!2007-10-27 Sat
>>> import xml.parsers.expat
>>> def start_doctype(doctypeName, systemId, publicId, has_internal_subset): ... print 'Start DoctypeDecl:', doctypeName, systemId, publicId, has_internal_subset
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.StartDoctypeDeclHandler = start_doctype
>>> p.Parse("""""")
Start DoctypeDecl: html http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd -//W3C//DTD XHTML 1.1//EN 0
1
>>> def start_doctype(doctypeName, systemId, publicId, has_internal_subset):
... print 'Start DoctypeDecl1:', doctypeName
... print 'Start DoctypeDecl2:', systemId
... print 'Start DoctypeDecl3:', publicId
... print 'Start DoctypeDecl4:', has_internal_subset
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.StartDoctypeDeclHandler = start_doctype
>>> p.Parse("""""")
Start DoctypeDecl1: html
Start DoctypeDecl2: http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd
Start DoctypeDecl3: -//W3C//DTD XHTML 1.1//EN
Start DoctypeDecl4: 0
1
!2007-10-26 Fri
>>> import xml.parsers.expat
>>> def xml_decl(version, encoding, standalone):
... print 'XmlDecl:', version, encoding, standalone
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.XmlDeclHandler = xml_decl
>>> p.Parse("""""")
XmlDecl: 1.0 None -1
1
!2007-10-25 Thu
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.ErrorByteIndex
-1
>>> p.ErrorCode
0
>>> p.ErrorColumnNumber
0
>>> p.ErrorLineNumber
1
!2007-10-24 Wed
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.specified_attributes
False
!2007-10-23 Tue
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.returns_unicode
True
!2007-10-22 Mon
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.ordered_attributes
False
>>> def start_element(name, attrs):
... print 'Start element:', name, attrs
...
>>> p.StartElementHandler = start_element
>>> p.ordered_attributes = 1
>>> p.Parse("""
... Text goes here
... More text
... """)
Start element: parent [u'id', u'top']
Start element: child1 [u'name', u'paul']
Start element: child2 [u'name', u'fred']
1
!2007-10-21 Sun
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.buffer_text = True
>>> p.buffer_used
0
>>> p.Parse("""""")
1
>>> p.buffer_used
0
!2007-10-20 Sat
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.buffer_text
False
>>> p.Parse("""""")
1
>>> p.buffer_text
False
>>> p.buffer_text = True
>>> p.buffer_text
True
自分で設定するもののようだ
!2007-10-19 Fri
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.buffer_size
8192
!2007-10-18 Thu
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> def start_element(name, attrs):
... print 'Start element:', name, attrs
...
>>> p.StartElementHandler = start_element
>>> p.ParseFile(open('foo'))
Start element: parent {u'id': u'top'}
Start element: child1 {u'name': u'paul'}
Start element: child2 {u'name': u'fred'}
1
!2007-10-17 Wed
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> p.Parse("")
1
「最後に呼び出す時」って何のこと?
!2007-10-16 Tue
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate()
>>> def start_element(name, attrs):
... print 'Start element:', name, attrs
...
>>> p.StartElementHandler = start_element
>>> p.Parse("""
...
...
...
... """)
Start element: root {u'xmlns:py': u'http://www.python.org/ns/', u'xmlns': u'http://default-namespace.org/'}
Start element: py:elem1 {}
Start element: elem2 {u'xmlns': u''}
1
>>> p = xml.parsers.expat.ParserCreate('ASCII', ' ')
>>> p.StartElementHandler = start_element
>>> p.Parse("""
...
...
...
... """)
Start element: http://default-namespace.org/ root {}
Start element: http://www.python.org/ns/ elem1 {}
Start element: elem2 {}
1
!2007-10-15 Mon
>>> import xml.parsers.expat
>>> p = xml.parsers.expat.ParserCreate('ASCII')
>>> p.Parse("""""")
1
>>> def start_element(name, attrs):
... print 'Start element:', name, attrs
...
>>> p = xml.parsers.expat.ParserCreate('ASCII')
>>> p.StartElementHandler = start_element
>>> p.Parse("""""")
Start element: parent {u'id': u'top'}
1
!2007-10-14 Sun
まんま
>>> import xml.parsers.expat
>>> def start_element(name, attrs):
... print 'Start element:', name, attrs
...
>>> def end_element(name):
... print 'End element:', name
...
>>> def char_data(data):
... print 'Character data:', repr(data)
...
>>> p = xml.parsers.expat.ParserCreate()
>>> p.StartElementHandler = start_element
>>> p.EndElementHandler = end_element
>>> p.CharacterDataHandler = char_data
>>> p.Parse("""
... Text goes here
... More text
... """)
Start element: parent {u'id': u'top'}
Start element: child1 {u'name': u'paul'}
Character data: u'Text goes here'
End element: child1
Character data: u'\n'
Start element: child2 {u'name': u'fred'}
Character data: u'More text'
End element: child2
Character data: u'\n'
End element: parent
1
!2007-10-13 Sat
>>> import HTMLParser
>>> hp = HTMLParser.HTMLParser()
>>> hp.feed("<<")
>>> hp.reset()
>>> hp.feed("<
>")
!2007-10-12 Fri
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_pi(self, data):
... print data
...
>>> hp = MyHTMLParser()
>>> hp.feed("")
proc color='red'
>>> hp.feed("")
proc color='red'?
!2007-10-11 Thu
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_decl(self, decl):
... print decl
...
>>> hp = MyHTMLParser()
>>> hp.feed('')
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"
!2007-10-10 Wed
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_comment(self, data):
... print data
...
>>> hp = MyHTMLParser()
>>> hp.feed("")
foo
!2007-10-09 Tue
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_entityref(self, name):
... print name
...
>>> hp = MyHTMLParser()
>>> hp.feed(""<foo>")
quot
lt
gt
!2007-10-08 Mon
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_charref(self, ref):
... print ref
...
>>> hp = MyHTMLParser()
>>> hp.feed(""<foo>")
>>> hp.feed("&123;")
>>> hp.feed("{")
123
!2007-10-07 Sun
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_data(self, data):
... print "data %s" % data
...
>>> hp = MyHTMLParser()
>>> hp.feed("h1
fooh2 1
h2 2
")
data h1
data foo
data h2 1
data h2 2
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_starttag(self, tag, attrs):
... print "Encountered the beginning of a %s tag" % tag
... def handle_endtag(self, tag):
... print "Encountered the end of a %s tag" % tag
... def handle_data(self, data):
... print "data %s" % data
...
>>> hp = MyHTMLParser()
>>> hp.feed("h1
fooh2 1
h2 2
")
Encountered the beginning of a html tag
Encountered the beginning of a h1 tag
data h1
Encountered the end of a h1 tag
data foo
Encountered the beginning of a h2 tag
data h2 1
Encountered the end of a h2 tag
Encountered the beginning of a h2 tag
data h2 2
Encountered the end of a h2 tag
Encountered the end of a html tag
>>> hp.feed(" h1
foo h2 1
h2 2
")
Encountered the beginning of a html tag
data
Encountered the beginning of a h1 tag
data h1
Encountered the end of a h1 tag
data foo
Encountered the beginning of a h2 tag
data h2 1
Encountered the end of a h2 tag
Encountered the beginning of a h2 tag
data h2 2
Encountered the end of a h2 tag
Encountered the end of a html tag
data
!2007-10-06 Sat
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_starttag(self, tag, attrs):
... print "Encountered the beginning of a %s tag" % tag
... def handle_endtag(self, tag):
... print "Encountered the end of a %s tag" % tag
... def handle_startendtag(self, tag, attrs):
... print "Encountered a %s tag" % tag
...
>>> hp = MyHTMLParser()
>>> hp.feed("
")
Encountered a br tag
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_starttag(self, tag, attrs):
... print "Encountered the beginning of a %s tag" % tag
... def handle_endtag(self, tag):
... print "Encountered the end of a %s tag" % tag
...
>>> hp = MyHTMLParser()
>>> hp.feed("
")
Encountered the beginning of a br tag
Encountered the end of a br tag
!2007-10-05 Fri
>>> import HTMLParser
>>> class MyHTMLParser(HTMLParser.HTMLParser):
... def handle_starttag(self, tag, attrs):
... print "Encountered the beginning of a %s tag" % tag
... def handle_endtag(self, tag):
... print "Encountered the end of a %s tag" % tag
...
>>> hp = MyHTMLParser()
>>> hp.getpos()
(1, 0)
>>> hp.feed('h1')
Encountered the beginning of a html tag
Encountered the beginning of a h1 tag
>>> hp.getpos()
(1, 12)
>>> hp.get_starttag_text()
''
>>> hp.feed('
')
Encountered the end of a h1 tag
Encountered the end of a html tag
>>> hp.get_starttag_text()
''
>>> hp = MyHTMLParser()
>>> hp.feed('