はてブロ@ama_ch

https://twitter.com/ama_ch

今日のPython

正規表現

わからねえ・・・
http://www.python.jp/doc/release/lib/module-re.html


p.211 urlopen()を使ったサンプル

>>> import re
>>> import urllib
>>> url = "http://python.org/channews.rdf"
>>> src = urllib.urlopen(url).read()
>>> # ここがよくわからないんだ!
>>> for url in re.findall(r"<guid>(.*?)</guid>", src, re.M):
...     print url
... 
http://www.python.org/news/index.html#WedMay720081230-0400
http://www.python.org/news/index.html#Thu1May20082115-0400
以下略

timeモジュール

http://www.python.jp/doc/release/lib/module-time.html
この辺を見ながら。
p.215

>>> import time
>>> time.gmtime()
(2008, 5, 9, 4, 15, 18, 4, 130, 0)
>>> time.localtime()
(2008, 5, 9, 13, 15, 25, 4, 130, 0)
>>> time.ctime()
'Fri May  9 13:15:31 2008'
>>> time.asctime()
'Fri May  9 13:15:39 2008'
>>> time.time()
1210306553.7216139
>>> time.mktime(time.localtime())  #struct_time型の引数を与え、エポック経過時間にする
1210307286.0
>>> time.strftime("%y/%m/%d %H:%M:%S")  #フォーマットで指定した日付や時刻を表示する
'08/05/09 13:35:08'

calendarモジュール

http://www.python.jp/doc/release/lib/module-calendar.html
p.218

>>> import calendar
>>> calendar.weekday(2008, 5, 9)  #何曜日か調べる
4  #金曜日です
>>> calendar.weekday(9999, 12, 31)  #ここまで調べられた
4  #9999年の大晦日は金曜日!
>>> calendar.monthrange(2008, 5)  #2008年5月は・・・
(3, 31)  #木曜から始まり31日あります。
>>> print calendar.month(2008, 5)  #今月のカレンダーを表示!
      May 2008
Mo Tu We Th Fr Sa Su
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

>>> calendar.month(2008, 5)  #print入れないと改行されなくて変なる><
'      May 2008\nMo Tu We Th Fr Sa Su\n          1  2  3  4\n 5  6  7  8  9 10 11\n12 13 14 15 16 17 18\n19 20 21 22 23 24 25\n26 27 28 29 30 31\n'
>>> print calendar.monthcalendar(2008, 5)  #週単位のリストを返す
[[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, 0]]
>>> calendar.isleap(2008)  #閏年かどうか調べる
True

sysモジュール

http://www.python.jp/doc/release/lib/module-sys.html
p.220

>>> import sys
>>> sys.maxint  #最大の整数
2147483647  #32bitなり
>>> sys.platform  #Pythonの稼働するプラットフォーム
'darwin'  #Mac OS Xのことらしい
>>> print sys.version  #バージョンを調べる
2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)]

osモジュール

http://www.python.jp/doc/release/lib/module-os.html
http://www.python.jp/doc/release/lib/os-file-dir.html#os-file-dir
p.227 walk()関数を使いディレクトリを走査する

>>> for dirpath, dirnames, filenames in os.walk("/Users/ama-ch/Desktop/Python-Docs-2.4"):
...     print dirpath, dirnames, filenames
... 
/Users/ama-ch/Desktop/Python-Docs-2.4 ['api', 'dist', 'doc', 'ext', 'icons', 'inst', 'lib', 'mac', 'ref', 'tut', 'whatsnew'] ['.DS_Store', 'about.html', 'acks.html', 'index.html', 'modindex.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/api [] ['about.html', 'abstract-buffer.html', 'abstract.html', 'advanced-debugging.html', 'allocating-objects.html', 'api.css', 'api.html', 'arg-parsing.html', 'boolObjects.html', 'buffer-structs.html', 'bufferObjects.html', 'builtinCodecs.html', 'cell-objects.html', 'cObjects.html', 'common-structs.html', 'complexObjects.html', 'concrete.html', 'contents.html', 'countingRefs.html', 'datetime-objects.html', 'descriptor-objects.html', 'dictObjects.html', 'embedding.html', 'exceptionHandling.html', 'exceptions.html', 'fileObjects.html', 'floatObjects.html', 'front.html', 'fundamental.html', 'gen-objects.html', 'genindex.html', 'importing.html', 'includes.html', 'index.html', 'initialization.html', 'instanceObjects.html', 'intObjects.html', 'intro.html', 'iterator-objects.html', 'iterator.html', 'listObjects.html', 'longObjects.html', 'mapObjects.html', 'mapping-structs.html', 'mapping.html', 'marshalling-utils.html', 'memory.html', 'memoryExamples.html', 'memoryInterface.html', 'memoryOverview.html', 'method-objects.html', 'moduleObjects.html', 'newTypes.html', 'node15.html', 'node39.html', 'node40.html', 'node83.html', 'node84.html', 'node85.html', 'node86.html', 'node87.html', 'node88.html', 'node89.html', 'node90.html', 'node91.html', 'node92.html', 'node93.html', 'node94.html', 'node95.html', 'node96.html', 'node97.html', 'node98.html', 'node99.html', 'noneObject.html', 'number-structs.html', 'number.html', 'numericObjects.html', 'object.html', 'objects.html', 'os.html', 'otherObjects.html', 'processControl.html', 'profiling.html', 'refcountDetails.html', 'refcounts.html', 'reporting-bugs.html', 'sequence-structs.html', 'sequence.html', 'sequenceObjects.html', 'slice-objects.html', 'standardExceptions.html', 'stringObjects.html', 'supporting-cycle-detection.html', 'supporting-iteration.html', 'threads.html', 'tupleObjects.html', 'type-structs.html', 'typeObjects.html', 'types.html', 'typestruct.txt', 'unicodeMethodsAndSlots.html', 'unicodeObjects.html', 'utilities.html', 'veryhigh.html', 'weakref-objects.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/dist [] ['about.html', 'api-reference.html', 'built-dist.html', 'concepts.html', 'creating-dumb.html', 'creating-rpms.html', 'describing-extensions.html', 'dist.css', 'dist.html', 'distutils-term.html', 'examples.html', 'extending.html', 'genindex.html', 'index.html', 'install-scripts-cmd.html', 'intro.html', 'listing-modules.html', 'listing-packages.html', 'manifest-options.html', 'manifest.html', 'meta-data.html', 'modindex.html', 'module-distutils.archiveutil.html', 'module-distutils.bcppcompiler.html', 'module-distutils.ccompiler.html', 'module-distutils.cmd.html', 'module-distutils.command.bdist.html', 'module-distutils.command.bdistdumb.html', 'module-distutils.command.bdistpackager.html', 'module-distutils.command.bdistrpm.html', 'module-distutils.command.bdistwininst.html', 'module-distutils.command.build.html', 'module-distutils.command.buildclib.html', 'module-distutils.command.buildext.html', 'module-distutils.command.buildpy.html', 'module-distutils.command.buildscripts.html', 'module-distutils.command.clean.html', 'module-distutils.command.config.html', 'module-distutils.command.html', 'module-distutils.command.install.html', 'module-distutils.command.installdata.html', 'module-distutils.command.installheaders.html', 'module-distutils.command.installlib.html', 'module-distutils.command.installscripts.html', 'module-distutils.command.register.html', 'module-distutils.command.sdist.html', 'module-distutils.core.html', 'module-distutils.cygwinccompiler.html', 'module-distutils.debug.html', 'module-distutils.deputil.html', 'module-distutils.dirutil.html', 'module-distutils.dist.html', 'module-distutils.emxccompiler.html', 'module-distutils.errors.html', 'module-distutils.extension.html', 'module-distutils.fancygetopt.html', 'module-distutils.filelist.html', 'module-distutils.fileutil.html', 'module-distutils.log.html', 'module-distutils.msvccompiler.html', 'module-distutils.mwerkscompiler.html', 'module-distutils.spawn.html', 'module-distutils.sysconfig.html', 'module-distutils.textfile.html', 'module-distutils.unixccompiler.html', 'module-distutils.util.html', 'module-distutils.version.html', 'node10.html', 'node11.html', 'node12.html', 'node14.html', 'node29.html', 'node79.html', 'node82.html', 'package-index.html', 'postinstallation-script.html', 'pure-mod.html', 'pure-pkg.html', 'python-terms.html', 'reference.html', 'sdist-cmd.html', 'setup-config.html', 'setup-script.html', 'simple-example.html', 'single-ext.html', 'source-dist.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/doc [] ['about.html', 'classes.html', 'contents.html', 'cygwin.html', 'directories.html', 'discussion.html', 'doc.css', 'doc.html', 'futures.html', 'grammar-displays.html', 'graphics.html', 'gui-markup.html', 'img1.png', 'index.html', 'indexing.html', 'info-units.html', 'inline-markup.html', 'intro.html', 'latex-environments.html', 'latex-primer.html', 'latex-structure.html', 'latex-syntax.html', 'library-markup.html', 'meta-info.html', 'misc-text-markup.html', 'module-markup.html', 'node32.html', 'node33.html', 'node34.html', 'preamble-info.html', 'references.html', 'showing-examples.html', 'special-constructs.html', 'structured.html', 'style-guide.html', 'table-markup.html', 'tools-external.html', 'tools-internal.html', 'tools.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/ext [] ['about.html', 'backToExample.html', 'building-on-windows.html', 'building.html', 'buildValue.html', 'callingPython.html', 'compilation.html', 'contents.html', 'cplusplus.html', 'defining-new-types.html', 'distributing.html', 'dnt-basics.html', 'dnt-type-methods.html', 'dynamic-linking.html', 'embedding.html', 'embeddingInCplusplus.html', 'errors.html', 'ext.css', 'ext.html', 'extending-with-embedding.html', 'front.html', 'high-level-embedding.html', 'index.html', 'intro.html', 'link-reqs.html', 'lower-level-embedding.html', 'methodTable.html', 'noddy.txt', 'noddy2.txt', 'noddy3.txt', 'noddy4.txt', 'node22.html', 'node23.html', 'node24.html', 'node26.html', 'node27.html', 'node28.html', 'node29.html', 'node30.html', 'node31.html', 'node32.html', 'node33.html', 'node48.html', 'node49.html', 'node50.html', 'node51.html', 'node52.html', 'node53.html', 'node54.html', 'node55.html', 'node56.html', 'node57.html', 'node58.html', 'node59.html', 'node60.html', 'node61.html', 'node62.html', 'node63.html', 'node64.html', 'node65.html', 'nullPointers.html', 'ownershipRules.html', 'parseTuple.html', 'parseTupleAndKeywords.html', 'pure-embedding.html', 'refcounts.html', 'refcountsInPython.html', 'reporting-bugs.html', 'run-func.txt', 'simpleExample.html', 'thinIce.html', 'typestruct.txt', 'using-cobjects.html', 'win-cookbook.html', 'win-dlls.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/icons [] ['blank.gif', 'blank.png', 'contents.gif', 'contents.png', 'index.gif', 'index.png', 'modules.gif', 'modules.png', 'next.gif', 'next.png', 'previous.gif', 'previous.png', 'pyfav.gif', 'up.gif', 'up.png']
/Users/ama-ch/Desktop/Python-Docs-2.4/inst [] ['about.html', 'alt-install-windows.html', 'config-syntax.html', 'img1.png', 'img2.png', 'index.html', 'inst.css', 'inst.html', 'node7.html', 'search-path.html', 'standard-install.html', 'trivial-install.html', 'tweak-flags.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/lib [] ['about.html', 'abstract-basic-auth-handler.html', 'abstract-digest-auth-handler.html', 'addresslist-objects.html', 'al-config-objects.html', 'al-port-objects.html', 'allos.html', 'asynchat-example.html', 'asyncore-example.html', 'atexit-example.html', 'attributes-ns-objects.html', 'attributes-objects.html', 'au-read-objects.html', 'au-write-objects.html', 'audio-device-objects.html', 'base-handler-objects.html', 'binary-objects.html', 'binhex-notes.html', 'bisect-example.html', 'bitstring-ops.html', 'bltin-code-objects.html', 'bltin-ellipsis-object.html', 'bltin-file-objects.html', 'bltin-null-object.html', 'bltin-type-objects.html', 'boolean-objects.html', 'boolean.html', 'browser-controllers.html', 'bsddb-objects.html', 'built-in-funcs.html', 'builtin.html', 'bytecodes.html', 'cacheftp-handler-objects.html', 'cd-parser-objects.html', 'cgi-intro.html', 'cgi-security.html', 'Cmd-objects.html', 'codec-objects.html', 'comparisons.html', 'compiler.html', 'completer-objects.html', 'condition-objects.html', 'ConfigParser-objects.html', 'console-objects.html', 'content-handler-objects.html', 'contents.html', 'cookie-example.html', 'cookie-jar-objects.html', 'cookie-objects.html', 'cookie-policy-objects.html', 'cookielib-examples.html', 'crypto.html', 'csv-contents.html', 'csv-fmt-params.html', 'curses-functions.html', 'curses-panel-objects.html', 'curses-textpad-objects.html', 'curses-window-objects.html', 'cursespanel-functions.html', 'datetime-date.html', 'datetime-datetime.html', 'datetime-objects.html', 'datetime-time.html', 'datetime-timedelta.html', 'datetime-tzinfo.html', 'dbhash-objects.html', 'debugger-commands.html', 'debugger-hooks.html', 'decimal-decimal.html', 'decimal-notes.html', 'decimal-recipes.html', 'decimal-signals.html', 'decimal-threads.html', 'decimal-tutorial.html', 'default-cookie-policy-objects.html', 'deque-recipes.html', 'differ-examples.html', 'differ-objects.html', 'dircmp-objects.html', 'dl-objects.html', 'doc-xmlrpc-servers.html', 'doctest-advanced-api.html', 'doctest-basic-api.html', 'doctest-debugging.html', 'doctest-DocTest.html', 'doctest-DocTestFinder.html', 'doctest-DocTestParser.html', 'doctest-DocTestRunner.html', 'doctest-Example.html', 'doctest-finding-examples.html', 'doctest-how-it-works.html', 'doctest-options.html', 'doctest-OutputChecker.html', 'doctest-simple-testfile.html', 'doctest-simple-testmod.html', 'doctest-soapbox.html', 'doctest-unittest-api.html', 'doctest-warnings.html', 'doctest-which-docstrings.html', 'dom-accessor-methods.html', 'dom-attr-objects.html', 'dom-attributelist-objects.html', 'dom-comment-objects.html', 'dom-conformance.html', 'dom-document-objects.html', 'dom-documenttype-objects.html', 'dom-element-objects.html', 'dom-example.html', 'dom-exceptions.html', 'dom-implementation-objects.html', 'dom-node-objects.html', 'dom-nodelist-objects.html', 'dom-objects.html', 'dom-pi-objects.html', 'dom-text-objects.html', 'dom-type-mapping.html', 'domeventstream-objects.html', 'dtd-handler-objects.html', 'dumbdbm-objects.html', 'email-dir.txt', 'email-mime.txt', 'email-simple.txt', 'email-unpack.txt', 'embedding-locale.html', 'entity-resolver-objects.html', 'event-objects.html', 'examples-imp.html', 'expat-content-models.html', 'expat-errors.html', 'expat-example.html', 'expaterror-objects.html', 'fault-objects.html', 'file-cookie-jar-classes.html', 'file-handler-objects.html', 'form-objects.html', 'formatter-impls.html', 'formatter-interface.html', 'forms-objects.html', 'fpectl-example.html', 'front.html', 'ftp-handler-objects.html', 'ftp-objects.html', 'genindex.html', 'gopher-handler.html', 'grammar-doctest.txt', 'handle-object.html', 'hotshot-example.html', 'hotshot-objects.html', 'html-parser-objects.html', 'htmlparser-example.html', 'http-basic-auth-handler.html', 'http-cookie-processor.html', 'http-digest-auth-handler.html', 'http-error-processor-objects.html', 'http-handler-objects.html', 'http-password-mgr.html', 'http-redirect-handler.html', 'httpconnection-objects.html', 'httplib-examples.html', 'httpresponse-objects.html', 'https-handler-objects.html', 'idle.html', 'imap4-example.html', 'imap4-objects.html', 'img1.png', 'img2.png', 'img3.png', 'img4.png', 'immutable-transforms.html', 'incremental-parser-objects.html', 'index.html', 'input-source-objects.html', 'inspect-classes-functions.html', 'inspect-source.html', 'inspect-stack.html', 'internet.html', 'interpreter-objects.html', 'intro.html', 'itertools-example.html', 'itertools-functions.html', 'itertools-recipes.html', 'language.html', 'legacy-unit-tests.html', 'lib.css', 'lib.html', 'locale-gettext.html', 'locator-objects.html', 'lock-objects.html', 'logging-config-api.html', 'logging-config-fileformat.html', 'mailbox-objects.html', 'markup.html', 'match-objects.html', 'matching-searching.html', 'message-objects.html', 'mh-folder-objects.html', 'mh-message-objects.html', 'mh-objects.html', 'mimetools-message-objects.html', 'mimetypes-objects.html', 'MimeWriter-objects.html', 'minidom-and-dom.html', 'minidom-example.txt', 'minimal-example.html', 'misc.html', 'mixer-device-objects.html', 'mmedia.html', 'modindex.html', 'module--winreg.html', 'module-aifc.html', 'module-al-constants.html', 'module-al.html', 'module-anydbm.html', 'module-array.html', 'module-asynchat.html', 'module-asyncore.html', 'module-atexit.html', 'module-audioop.html', 'module-base64.html', 'module-BaseHTTPServer.html', 'module-Bastion.html', 'module-binascii.html', 'module-binhex.html', 'module-bisect.html', 'module-bsddb.html', 'module-builtin.html', 'module-bz2.html', 'module-calendar.html', 'module-cd.html', 'module-cgi.html', 'module-CGIHTTPServer.html', 'module-cgitb.html', 'module-chunk.html', 'module-cmath.html', 'module-cmd.html', 'module-code.html', 'module-codecs.html', 'module-codeop.html', 'module-collections.html', 'module-colorsys.html', 'module-commands.html', 'module-compileall.html', 'module-compiler.ast.html', 'module-compiler.html', 'module-compiler.visitor.html', 'module-ConfigParser.html', 'module-Cookie.html', 'module-cookielib.html', 'module-copy.html', 'module-copyreg.html', 'module-cPickle.html', 'module-crypt.html', 'module-cStringIO.html', 'module-csv.html', 'module-curses.ascii.html', 'module-curses.html', 'module-curses.panel.html', 'module-curses.textpad.html', 'module-curses.wrapper.html', 'module-datetime.html', 'module-dbhash.html', 'module-dbm.html', 'module-decimal.html', 'module-DEVICE.html', 'module-difflib.html', 'module-dircache.html', 'module-dis.html', 'module-distutils.html', 'module-dl.html', 'module-doctest.html', 'module-DocXMLRPCServer.html', 'module-dumbdbm.html', 'module-dummythread.html', 'module-dummythreading.html', 'module-email.Charset.html', 'module-email.Encoders.html', 'module-email.Errors.html', 'module-email.Generator.html', 'module-email.Header.html', 'module-email.html', 'module-email.Iterators.html', 'module-email.Message.html', 'module-email.Parser.html', 'module-email.Utils.html', 'module-encodings.idna.html', 'module-errno.html', 'module-exceptions.html', 'module-fcntl.html', 'module-filecmp.html', 'module-fileinput.html', 'module-fl-constants.html', 'module-fl.html', 'module-flp.html', 'module-fm.html', 'module-fnmatch.html', 'module-formatter.html', 'module-fpectl.html', 'module-fpformat.html', 'module-ftplib.html', 'module-future.html', 'module-gc.html', 'module-gdbm.html', 'module-getopt.html', 'module-getpass.html', 'module-gettext.html', 'module-gl-constants.html', 'module-gl.html', 'module-glob.html', 'module-gopherlib.html', 'module-grp.html', 'module-gzip.html', 'module-heapq.html', 'module-hmac.html', 'module-hotshot.html', 'module-hotshot.stats.html', 'module-htmlentitydefs.html', 'module-htmllib.html', 'module-HTMLParser.html', 'module-httplib.html', 'module-imageop.html', 'module-imaplib.html', 'module-imgfile.html', 'module-imghdr.html', 'module-imp.html', 'module-inspect.html', 'module-itertools.html', 'module-jpeg.html', 'module-keyword.html', 'module-linecache.html', 'module-locale.html', 'module-logging.html', 'module-mailbox.html', 'module-mailcap.html', 'module-main.html', 'module-marshal.html', 'module-math.html', 'module-md5.html', 'module-mhlib.html', 'module-mimetools.html', 'module-mimetypes.html', 'module-MimeWriter.html', 'module-mimify.html', 'module-mmap.html', 'module-msvcrt.html', 'module-multifile.html', 'module-mutex.html', 'module-netrc.html', 'module-new.html', 'module-nis.html', 'module-nntplib.html', 'module-operator.html', 'module-optparse.html', 'module-os.html', 'module-os.path.html', 'module-ossaudiodev.html', 'module-parser.html', 'module-pdb.html', 'module-pickle.html', 'module-pipes.html', 'module-pkgutil.html', 'module-platform.html', 'module-popen2.html', 'module-poplib.html', 'module-posix.html', 'module-posixfile.html', 'module-pprint.html', 'module-profile.html', 'module-pty.html', 'module-pwd.html', 'module-pyclbr.html', 'module-pycompile.html', 'module-pydoc.html', 'module-Queue.html', 'module-quopri.html', 'module-random.html', 'module-re.html', 'module-readline.html', 'module-repr.html', 'module-resource.html', 'module-rexec.html', 'module-rfc822.html', 'module-rgbimg.html', 'module-rlcompleter.html', 'module-robotparser.html', 'module-sched.html', 'module-ScrolledText.html', 'module-select.html', 'module-sets.html', 'module-sgmllib.html', 'module-sha.html', 'module-shelve.html', 'module-shlex.html', 'module-shutil.html', 'module-signal.html', 'module-SimpleHTTPServer.html', 'module-SimpleXMLRPCServer.html', 'module-site.html', 'module-smtpd.html', 'module-smtplib.html', 'module-sndhdr.html', 'module-socket.html', 'module-SocketServer.html', 'module-stat.html', 'module-statcache.html', 'module-statvfs.html', 'module-string.html', 'module-StringIO.html', 'module-stringprep.html', 'module-struct.html', 'module-subprocess.html', 'module-sunau.html', 'module-sunaudiodev-constants.html', 'module-sunaudiodev.html', 'module-symbol.html', 'module-sys.html', 'module-syslog.html', 'module-tabnanny.html', 'module-tarfile.html', 'module-telnetlib.html', 'module-tempfile.html', 'module-termios.html', 'module-test.html', 'module-test.testsupport.html', 'module-textwrap.html', 'module-thread.html', 'module-threading.html', 'module-time.html', 'module-timeit.html', 'module-Tix.html', 'module-Tkinter.html', 'module-token.html', 'module-tokenize.html', 'module-traceback.html', 'module-tty.html', 'module-turtle.html', 'module-types.html', 'module-unicodedata.html', 'module-unittest.html', 'module-urllib.html', 'module-urllib2.html', 'module-urlparse.html', 'module-user.html', 'module-UserDict.html', 'module-UserList.html', 'module-UserString.html', 'module-uu.html', 'module-warnings.html', 'module-wave.html', 'module-weakref.html', 'module-webbrowser.html', 'module-whichdb.html', 'module-whrandom.html', 'module-winsound.html', 'module-xdrlib.html', 'module-xml.dom.html', 'module-xml.dom.minidom.html', 'module-xml.dom.pulldom.html', 'module-xml.parsers.expat.html', 'module-xml.sax.handler.html', 'module-xml.sax.html', 'module-xml.sax.saxutils.html', 'module-xml.sax.xmlreader.html', 'module-xmllib.html', 'module-xmlrpclib.html', 'module-zipfile.html', 'module-zlib.html', 'morsel-objects.html', 'msvcrt-console.html', 'msvcrt-files.html', 'msvcrt-other.html', 'multifile-example.html', 'MultiFile-objects.html', 'multiple-destinations.html', 'mutex-objects.html', 'netdata.html', 'netrc-objects.html', 'network-logging.html', 'nntp-objects.html', 'node104.html', 'node105.html', 'node106.html', 'node107.html', 'node111.html', 'node114.html', 'node126.html', 'node144.html', 'node145.html', 'node159.html', 'node161.html', 'node175.html', 'node190.html', 'node209.html', 'node229.html', 'node230.html', 'node231.html', 'node232.html', 'node233.html', 'node234.html', 'node235.html', 'node236.html', 'node237.html', 'node238.html', 'node239.html', 'node240.html', 'node245.html', 'node251.html', 'node261.html', 'node309.html', 'node31.html', 'node313.html', 'node314.html', 'node315.html', 'node316.html', 'node317.html', 'node318.html', 'node319.html', 'node320.html', 'node321.html', 'node322.html', 'node323.html', 'node324.html', 'node325.html', 'node327.html', 'node331.html', 'node332.html', 'node333.html', 'node334.html', 'node335.html', 'node336.html', 'node337.html', 'node338.html', 'node339.html', 'node340.html', 'node341.html', 'node342.html', 'node343.html', 'node344.html', 'node345.html', 'node346.html', 'node348.html', 'node35.html', 'node351.html', 'node352.html', 'node353.html', 'node354.html', 'node355.html', 'node356.html', 'node359.html', 'node392.html', 'node393.html', 'node394.html', 'node419.html', 'node427.html', 'node428.html', 'node436.html', 'node437.html', 'node439.html', 'node444.html', 'node45.html', 'node450.html', 'node451.html', 'node457.html', 'node458.html', 'node459.html', 'node460.html', 'node462.html', 'node463.html', 'node464.html', 'node465.html', 'node469.html', 'node512.html', 'node513.html', 'node514.html', 'node515.html', 'node525.html', 'node542.html', 'node543.html', 'node547.html', 'node55.html', 'node550.html', 'node554.html', 'node564.html', 'node566.html', 'node567.html', 'node568.html', 'node570.html', 'node571.html', 'node578.html', 'node579.html', 'node580.html', 'node617.html', 'node618.html', 'node619.html', 'node63.html', 'node634.html', 'node635.html', 'node64.html', 'node65.html', 'node66.html', 'node69.html', 'node698.html', 'node699.html', 'node70.html', 'node700.html', 'node701.html', 'node702.html', 'node704.html', 'node705.html', 'node707.html', 'node708.html', 'node709.html', 'node710.html', 'node711.html', 'node712.html', 'node713.html', 'node714.html', 'node716.html', 'node717.html', 'node718.html', 'node719.html', 'node720.html', 'node721.html', 'node722.html', 'node723.html', 'node724.html', 'node725.html', 'node726.html', 'node731.html', 'node732.html', 'node733.html', 'node734.html', 'node735.html', 'node736.html', 'node737.html', 'node738.html', 'node739.html', 'node740.html', 'node746.html', 'node750.html', 'node751.html', 'node752.html', 'node753.html', 'node754.html', 'node755.html', 'node756.html', 'node757.html', 'node76.html', 'node77.html', 'node773.html', 'node774.html', 'node776.html', 'node777.html', 'node779.html', 'node789.html', 'node804.html', 'node813.html', 'node814.html', 'node815.html', 'node816.html', 'node818.html', 'node820.html', 'node821.html', 'node822.html', 'node823.html', 'node824.html', 'node825.html', 'node826.html', 'node827.html', 'node828.html', 'node829.html', 'node830.html', 'node831.html', 'node832.html', 'node833.html', 'node834.html', 'node835.html', 'node836.html', 'node837.html', 'node92.html', 'non-essential-built-in-funcs.html', 'obsolete-modules.html', 'opener-director-objects.html', 'operator-map.html', 'optparse-background.html', 'optparse-callback-example-1.html', 'optparse-callback-example-2.html', 'optparse-callback-example-3.html', 'optparse-callback-example-4.html', 'optparse-callback-example-5.html', 'optparse-callback-example-6.html', 'optparse-conflicts-between-options.html', 'optparse-default-values.html', 'optparse-defining-callback-option.html', 'optparse-defining-options.html', 'optparse-generating-help.html', 'optparse-handling-boolean-options.html', 'optparse-how-callbacks-called.html', 'optparse-how-optik-handles-errors.html', 'optparse-option-callbacks.html', 'optparse-other-actions.html', 'optparse-populating-parser.html', 'optparse-printing-version-string.html', 'optparse-putting-it-all-together.html', 'optparse-querying-manipulating-option-parser.html', 'optparse-raising-errors-in-callback.html', 'optparse-reference-guide.html', 'optparse-standard-option-actions.html', 'optparse-standard-option-types.html', 'optparse-store-action.html', 'optparse-terminology.html', 'optparse-tutorial.html', 'optparse-understanding-option-actions.html', 'optparse-what-options-for.html', 'optparse-what-positional-arguments-for.html', 'organizing-tests.html', 'os-fd-ops.html', 'os-file-dir.html', 'os-miscfunc.html', 'os-newstreams.html', 'os-path.html', 'os-process.html', 'os-procinfo.html', 'ossaudio-device-objects.html', 'other-gui-packages.html', 'pen-rawpen-objects.html', 'pickle-example.html', 'pickle-inst.html', 'pickle-protocol.html', 'pickle-sub.html', 'player-objects.html', 'poll-objects.html', 'pop3-example.html', 'pop3-objects.html', 'popen2-flow-control.html', 'popen3-objects.html', 'posix-contents.html', 'posix-large-files.html', 'profile-calibration.html', 'profile-instant.html', 'profile-limits.html', 'profile-stats.html', 'profile.html', 'protocol-error-objects.html', 'proxy-basic-auth-handler.html', 'proxy-digest-auth-handler.html', 'proxy-handler.html', 'pyclbr-class-objects.html', 'pyclbr-function-objects.html', 'python.html', 'pyzipfile-objects.html', 'QueueObjects.html', 'RawConfigParser-objects.html', 're-objects.html', 're-syntax.html', 'readline-example.html', 'regrtest.html', 'reporting-bugs.html', 'Repr-objects.html', 'request-objects.html', 'restricted.html', 'rexec-extension.html', 'rexec-objects.html', 'rlock-objects.html', 'SafeConfigParser-objects.html', 'sax-error-handler.html', 'sax-exception-objects.html', 'scheduler-objects.html', 'semaphore-examples.html', 'semaphore-objects.html', 'sequence-matcher.html', 'sequencematcher-examples.html', 'serverproxy-objects.html', 'set-example.html', 'set-objects.html', 'sgi.html', 'shlex-objects.html', 'shlex-parsing-rules.html', 'shutil-example.html', 'simple-xmlrpc-servers.html', 'SMTP-example.html', 'SMTP-objects.html', 'socket-example.html', 'socket-objects.html', 'someos.html', 'specialattrs.html', 'ssl-objects.html', 'standard-encodings.html', 'stream-reader-objects.html', 'stream-reader-writer.html', 'stream-recoder-objects.html', 'stream-writer-objects.html', 'string-methods.html', 'strings.html', 'subclassing-reprs.html', 'sunos.html', 'tar-examples.html', 'tarfile-objects.html', 'tarinfo-objects.html', 'telnet-example.html', 'telnet-objects.html', 'template-objects.html', 'testcase-objects.html', 'testloader-objects.html', 'testresult-objects.html', 'testsuite-objects.html', 'thread-objects.html', 'timer-objects.html', 'tkinter-basic-mapping.html', 'tkinter-setting-options.html', 'tkinter.html', 'traceback-example.html', 'truth.html', 'typeiter.html', 'types-set.html', 'types.html', 'typesfunctions.html', 'typesinternal.html', 'typesmapping.html', 'typesmethods.html', 'typesmodules.html', 'typesnumeric.html', 'typesobjects.html', 'typesother.html', 'typesseq-mutable.html', 'typesseq-strings.html', 'typesseq-xrange.html', 'typesseq.html', 'tzinfo-examples.txt', 'undoc.html', 'unittest-contents.html', 'unix.html', 'unknown-handler-objects.html', 'urllib2-examples.html', 'urlopener-objs.html', 'warning-categories.html', 'warning-filter.html', 'warning-functions.html', 'Wave-read-objects.html', 'Wave-write-objects.html', 'weakref-example.html', 'weakref-extension.html', 'weakref-objects.html', 'writer-impls.html', 'writer-interface.html', 'writing-tests.html', 'xdr-exceptions.html', 'xdr-packer-objects.html', 'xdr-unpacker-objects.html', 'xml-namespace.html', 'xmlparser-objects.html', 'xmlreader-objects.html', 'xmlrpc-client-example.html', 'zipfile-objects.html', 'zipinfo-objects.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/mac [] ['about.html', 'aeserver-objects.html', 'alias-objects.html', 'application-objects.html', 'argv.html', 'configuration.html', 'contents.html', 'controlswindow-object.html', 'creator-code.html', 'defaults.html', 'dialogwindow-objects.html', 'EditPythonPrefs.html', 'finfo-objects.html', 'front.html', 'fsspec-objects.html', 'genindex.html', 'getting-OSX.html', 'getting.html', 'IDE.html', 'IDEapplet.html', 'IDEexecution.html', 'IDEwrite.html', 'index.html', 'interpreter.html', 'mac.css', 'mac.html', 'macpython-modules.html', 'modindex.html', 'module-aepack.html', 'module-aetools.html', 'module-aetypes.html', 'module-applesingle.html', 'module-autoGIL.html', 'module-buildtools.html', 'module-Carbon.AE.html', 'module-Carbon.AH.html', 'module-Carbon.App.html', 'module-Carbon.CaronEvt.html', 'module-Carbon.CF.html', 'module-Carbon.CG.html', 'module-Carbon.Cm.html', 'module-Carbon.Ctl.html', 'module-Carbon.Dlg.html', 'module-Carbon.Evt.html', 'module-Carbon.Fm.html', 'module-Carbon.Folder.html', 'module-Carbon.Help.html', 'module-Carbon.List.html', 'module-Carbon.Menu.html', 'module-Carbon.Mlte.html', 'module-Carbon.Qd.html', 'module-Carbon.Qdoffs.html', 'module-Carbon.Qt.html', 'module-Carbon.Res.html', 'module-Carbon.Scrap.html', 'module-Carbon.Snd.html', 'module-Carbon.TE.html', 'module-Carbon.Win.html', 'module-cfmfile.html', 'module-ColorPicker.html', 'module-EasyDialogs.html', 'module-findertools.html', 'module-FrameWork.html', 'module-gensuitemodule.html', 'module-ic.html', 'module-icopen.html', 'module-mac.html', 'module-macerrors.html', 'module-macfs.html', 'module-MacOS.html', 'module-macostools.html', 'module-macpath.html', 'module-macresource.html', 'module-MiniAEFrame.html', 'module-mkcwproject.html', 'module-Nav.html', 'module-nsremote.html', 'module-PixMapWrapper.html', 'module-preferences.html', 'module-pyresource.html', 'module-pythonprefs.html', 'module-quietconsole.html', 'module-videoreader.html', 'module-W.html', 'module-waste.html', 'node10.html', 'node100.html', 'node101.html', 'node102.html', 'node103.html', 'node104.html', 'node105.html', 'node106.html', 'node107.html', 'node108.html', 'node109.html', 'node11.html', 'node110.html', 'node111.html', 'node112.html', 'node113.html', 'node114.html', 'node115.html', 'node14.html', 'node15.html', 'node16.html', 'node23.html', 'node35.html', 'node5.html', 'node7.html', 'node99.html', 'osx-gui-scripts.html', 'progressbar-objects.html', 'scripting-with-BBedit.html', 'scripting.html', 'scrolledwindow-object.html', 'search-path.html', 'toolbox.html', 'undocumented-modules.html', 'using.html', 'window-objects.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/ref [] ['about.html', 'assert.html', 'assignment.html', 'atom-identifiers.html', 'atom-literals.html', 'atoms.html', 'attribute-access.html', 'attribute-references.html', 'augassign.html', 'binary.html', 'bitwise.html', 'blank-lines.html', 'Booleans.html', 'break.html', 'callable-types.html', 'calls.html', 'class.html', 'coercion-rules.html', 'comments.html', 'comparisons.html', 'compound.html', 'contents.html', 'continue.html', 'conversions.html', 'customization.html', 'datamodel.html', 'del.html', 'delimiters.html', 'descriptor-invocation.html', 'descriptors.html', 'dict.html', 'dynamic-features.html', 'encodings.html', 'evalorder.html', 'exceptions.html', 'exec.html', 'execmodel.html', 'explicit-joining.html', 'expression-input.html', 'expressions.html', 'exprlists.html', 'exprstmts.html', 'file-input.html', 'floating.html', 'for.html', 'front.html', 'function.html', 'future.html', 'genexpr.html', 'genindex.html', 'global.html', 'grammar.txt', 'id-classes.html', 'identifiers.html', 'if.html', 'imaginary.html', 'implicit-joining.html', 'import.html', 'indentation.html', 'index.html', 'integers.html', 'interactive.html', 'introduction.html', 'keywords.html', 'lambdas.html', 'lexical.html', 'line-structure.html', 'lists.html', 'literals.html', 'logical.html', 'metaclasses.html', 'naming.html', 'new-style-attribute-access.html', 'node104.html', 'node105.html', 'node106.html', 'node107.html', 'node108.html', 'node109.html', 'node110.html', 'node111.html', 'node112.html', 'node113.html', 'node114.html', 'node115.html', 'node116.html', 'node117.html', 'node118.html', 'node119.html', 'node120.html', 'notation.html', 'numbers.html', 'numeric-types.html', 'objects.html', 'operators.html', 'other-tokens.html', 'parenthesized.html', 'pass.html', 'physical.html', 'power.html', 'primaries.html', 'print.html', 'programs.html', 'raise.html', 'ref.css', 'ref.html', 'return.html', 'sequence-methods.html', 'sequence-types.html', 'shifting.html', 'simple.html', 'slicings.html', 'slots.html', 'specialnames.html', 'string-catenation.html', 'string-conversions.html', 'strings.html', 'subscriptions.html', 'summary.html', 'top-level.html', 'try.html', 'types.html', 'unary.html', 'while.html', 'whitespace.html', 'yield.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/tut [] ['about.html', 'index.html', 'node1.html', 'node10.html', 'node11.html', 'node12.html', 'node13.html', 'node14.html', 'node15.html', 'node16.html', 'node17.html', 'node18.html', 'node19.html', 'node2.html', 'node20.html', 'node21.html', 'node3.html', 'node4.html', 'node5.html', 'node6.html', 'node7.html', 'node8.html', 'node9.html', 'tut.css', 'tut.html']
/Users/ama-ch/Desktop/Python-Docs-2.4/whatsnew [] ['about.html', 'acks.html', 'contents.html', 'index.html', 'node10.html', 'node11.html', 'node12.html', 'node13.html', 'node14.html', 'node15.html', 'node2.html', 'node3.html', 'node4.html', 'node5.html', 'node6.html', 'node7.html', 'node8.html', 'node9.html', 'whatsnew24.css', 'whatsnew24.html']

randomモジュール

http://www.python.jp/doc/release/lib/module-random.html
p.234 randint(a, b) - a以上b以下のランダムな整数を生成

>>> import random
>>> for i in range(random.randint(5, 20)):
...     print random.randint(1, 100)
... 
45
32
2
51
42
58
77


p.236
引数に与えたシーケンスの中から、ランダムに選んだ1つの要素を返すchoice()

>>> a = [1, 2, 3, 4, 5]
>>> random.choice(a)
5
>>> random.choice(a)
2
>>> random.choice(a)
3


シーケンスの要素をランダムに入れ替えるshuffle()

>>> a = [1, 2, 3, 4, 5]
>>> random.shuffle(a)
>>> a
[5, 1, 2, 4, 3]


シーケンスから指定した個数のサンプルを引き抜くsample()

>>> a = [1, 2, 3, 4, 5]
>>> random.sample(a, 3)
[1, 4, 2]