2005-01-01ãã1å¹´éã®è¨äºä¸è¦§
WScript.Shellãªãã¸ã§ã¯ãã§ã¯SpecialFoldersããããã£ãå¾ããã¨ãã§ããã ãã®ããããã£ã¯windowsã®ç¹å¥ãªãã©ã«ã(ãã¹ã¯ãããããã¤ããã¥ã¡ã³ããªã©)ã®ãã¹ãå¾ããã¨ãã§ããã >>> import win32com.client >>> com = win32com.client.Dispatch("â¦
win32allã¢ã¸ã¥ã¼ã«ã®ä¸ã®win32com.clientã¯ãwindowsã®COM(Component Object Model)ãªãã¸ã§ã¯ããæä½ããæ¡å¼µã¢ã¸ã¥ã¼ã«ã Python Win32 Extensions(win32all) http://starship.python.net/crew/mhammond/win32/Downloads.html ã³ã¬ã使ããã¨ã§WSHã®ããâ¦
Shift-jisã§ã¯å¤ã«ããã¯ã¹ã©ãã·ã¥(=0x5c)ãå«ã¾ããå ´åãããã(ä¾ãã°"表"ã®å) Pythonã§ã¯ããã¯ã¹ã©ãã·ã¥ã¯ã¨ã¹ã±ã¼ãæåã¨ãã¦æ±ãããã®ã§ããã®ãããªæåãæ£è¦è¡¨ç¾ã®ãã¿ã¼ã³ã«å«ã¾ãã¦ããã¨æå³ããªãçµæã¨ãªãã æååããã£ããunicodeã«â¦
>>>import pykf >>>import urllib >>>url = "http://www.yahoo.co.jp" >>>urlhandler = urllib.urlopen(url) >>>html = urlhandler.read() >>>html = pykf.tosjis(html, pykf.EUC) >>>print html yahooãã¼ã¸ã®æåã³ã¼ãã¯ãEUCããªã®ã§ãSJISãã«å¤æãã â¦
>>>import pykf >>>string = "ããããã" >>>print pykf.guess(string) 2 対å¿è¡¨ ASCII = 1 ERROR = -1 EUC = 3 JIS = 4 SJIS = 2 UNKNOWN = 0 UTF16 = 7 UTF16_BE = 8 UTF16_LE = 7 UTF8 = 5
http://hathawaymix.org/Software/TCPWatchã³ãã³ãã©ã¤ã³ããTCPWatchãèµ·åããã c:>tcpwatch.py -p 127.0.0.1:3128 TCPWatchãset_proxyãã¦ãªã¯ã¨ã¹ããé£ã°ã >>>import urllib2 >>>req = urllib2.Request("http://www.google.co.jp") >>>req.set_proxâ¦
>>>import urllib2 >>>req = urllib2.Request("http://www.google.co.jp") >>>req.set_proxy("proxy.example.com:8080", "http") >>>req.add_header("User-agent", "python") >>>req.add_header("Pragma", "no-cache") >>>site = urllib2.urlopen(req)
>>>import urllib2 >>>req = urllib2.Request("http://www.google.co.jp") >>>req.add_header("User-agent", "python") >>>req.add_header("Pragma", "no-cache") >>>urlhandler = urllib2.urlopen(req)
>>>import urllib2 >>>req = urllib2.Request("http://www.google.co.jp") >>>req.add_header("User-agent", "python") >>>urlhandler = urllib2.urlopen(req)
>>>import urllib2 >>>urlhandler = urllib2.urlopen("http://www.google.co.jp") >>>html = urlhandler.read() ä¸è¡ãã¤èªã¿è¾¼ã >>>html = urlhandler.readline() ä¸è¡ãã¤ãªã¹ãã«æ ¼ç´ >>>html = urlhandler.readlines()
optparseã¢ã¸ã¥ã¼ã«ã使ã£ã¦èµ·åæã®å¼æ°ã®è§£æãè¡ãåºæ¬ã [argsOp.py] #!/bin/env python # -*- coding: shift_jis -*- import sys from optparse import OptionParser #å¼æ°ã®è¨å® parser = OptionParser() parser.add_option("-f", "--file", dest="filâ¦
é£çªãéãã¹ã¯ãªãããæ¸ããã®ã§ããã£ããã ããéããurlãããã¡ã¤ã«ããã¦ã³ãã¼ãããã¹ã¯ãªãããã¤ãã£ã¦ã¿ãããã¨æã£ãã®ã ããã©å·§ããããªãã urllibã®ãªãã¡ã¬ã³ã¹ã« urlretrieve( url[, filename[, reporthook[, data]]]) URL ã§è¡¨ããããâ¦
æ£è¦è¡¨ç¾ã®ç·´ç¿ã«é£çªurlãå±éãã¦è¡¨ç¤ºããã¹ã¯ãªãããä½ã£ã¦ã¿ãã http://www.doqn.ne.jp/65-32/cg/[10-20].html ã ã£ãã http://www.doqn.ne.jp/65-32/cg/10.html http://www.doqn.ne.jp/65-32/cg/11.html http://www.doqn.ne.jp/65-32/cg/12.html ã£â¦
ã¯ããã«URLãæ¸ããããã¹ããã¡ã¤ã«ãURL.txtããç¨æããã www.google.co.jp www.yahoo.co.jp www.microsoft.com/ URL.txtã®å 容ãèªã¿è¾¼ãã§ãããããã®ãµã¤ãã®ãããã表示ããã¹ã¯ãªãããä½ã£ã¦ã¿ãã [headget.py] #!/bin/env python # -*- codinâ¦
urllibã使ãã¨â¦â¦æ¥½ã #!/bin/env python # -*- coding: shift_jis -*- import urllib res = urllib.urlopen("http://www.google.co.jp/") print res.read()
httplibãã¤ãã£ã¦"GET"ãªã¯ã¨ã¹ã #!/bin/env python # -*- coding: shift_jis -*- import httplib conn = httplib.HTTPConnection("www.google.co.jp") conn.request("GET", "/index.html") res = conn.getresponse() print res.read()
ã¨ãããããããã¯ã¼ã¯ããã°ã©ãã³ã°ã£ã½ã ãã¨ããã£ã¦ã¿ãã åèï¼HTTP ãããã³ã« http://www.wakhok.ac.jp/~maruyama/W3serv/document/node92.html socketã使ã£ãåºæ¬çãªã¯ã©ã¤ã¢ã³ãããã°ã©ã googleã«"Get"ãªã¯ã¨ã¹ããéã£ã¦ã¿ã #!/bin/env pâ¦
ãã¡ã¤ã«ãä¸è¡ã¥ã¤èªã¿è¾¼ã¿ãè¡å ã«#ããã£ãã#以ä¸ãåé¤ãã¦è¡¨ç¤ºã åé¡ç¹ #ã®ã³ã¡ã³ãã«ãã対å¿ãã¦ããªãã ãprint "#ã³ã¡ã³ããããªãã"ãã®ãããªè¡ã§ã#以ä¸ãã³ã¡ã³ãã¨èªèãã¦ãã¾ãã [commentDe.py] #!/bin/env python # -*- coding: shiftâ¦
fileview.pyãè¡æ°ãä»ãã¦è¡¨ç¤ºããããã«å¤æ´ãã¦ã¿ã[fileline.py] #!/bin/env python # -*- coding: shift_jis -*- import sys argv = sys.argv[1:] for i in argv: print "[" + i + "]" for n, line in enumerate(open(i)): print "%d: %s" % (n,line) ,â¦
å¼æ°ã«æå®ããããã¡ã¤ã«ã®å 容ã表示ããã¹ã¯ãªãããä½ã£ã¦ã¿ãã [fileview.py] #!/bin/env python # -*- coding: shift_jis -*- import sys argv = sys.argv[1:] for i in argv: print "[" + i + "]" files = open(i,'r') lines = files.readlines() foâ¦
sysã¢ã¸ã¥ã¼ã«ã®argv[]ãªã¹ãã§å¼æ°ãå¾ãããã argv[0]ã¯èµ·åããpythonã¹ã¯ãªãããã¡ã¤ã«ã®ååãå ¥ãã C:\Python23jp>test.py aaa bbb ccc ã®å ´åã¯ã argv[0] = "C:\Python23jp>test.py" argv[1] = "aaa" argv[2] = "bbb" argv[3] = "ccc" ã£ã¦ãã¨ãâ¦
>>> a = 10 >>> type(a) >>> a = "test" >>> type(a) >>> a = [1, 2, 3] >>> type(a) >>> a = (1, 2, 3) >>> type(a) >>> a = {1:1, 2:2, 3:3} >>> type(a) >>> def b(): print "test" >>> a = b >>> type(a) >>> import urllib >>> a = urllib >>> type(a) â¦
ã¡ã½ãããããããªããã£ã¦ã¨ãã¯dir() >>> import urllib >>> x = urllib.urlopen("http://www.google.ne.jp") >>> dir(x) ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close', 'fileno', 'fp', 'geturl', 'headers', 'info', 'next'â¦
対話ã¢ã¼ãã®æãimport ããã¢ã¸ã¥ã¼ã«ã®ãã«ããè¦ããã >>>import string >>>help(string) ã§ã¢ã¸ã¥ã¼ã«ã®ãã«ãã表示ãããã(è±èªã ãã©ï¼ï¼ï¼)
â¼ä½¿ãæ¹ ä»¥ä¸ã¯ãcãã©ã¤ãç´ä¸ã«test.txtãåå¨ããã«ã¬ã³ããã£ã¬ã¯ããª(ä½æ¥ãã©ã«ã)ã"C:"ã§ãããã¨ãåæ (Pythonã¯"c:python23"ã«ã¤ã³ã¹ãã¼ã«ããã¦ããç¶æ ãåæ) ãªããPython Shellä¸ã§ã¯[ï¿¥]è¨å·ã¯ããã¯ã¹ã©ãã·ã¥(\)ã§è¡¨ç¤ºãããã ([c:¥¥â¦
ãã¡ã¤ã«æä½ã®æé 㯠ï¼ï¼ãã¡ã¤ã«éã(ãªã¼ãã³) ï¼ï¼ãã¡ã¤ã«å¼ã(èªãã ããæ¸ããã) ï¼ï¼ãã¡ã¤ã«éãã(ã¯ãã¼ãº) ãã¡ã¤ã«ã®ãªã¼ãã³ã«ã¯file()ã使ãã æ¸å¼ã¯ã file("ãã¡ã¤ã«å", "ãã©ã°") open("ãã¡ã¤ã«å", "ãã©ã°")ã¯ãfile("ãã¡ã¤ã«å",â¦
ã¢ã¸ã¥ã¼ã«ã¯èªåã§ä½ããã¨ãã§ããããã©ãPythonã«ã¯æ¨æºã§ã¤ãã¦ããã¢ã¸ã¥ã¼ã«ãé常ã«è±å¯ãªã®ã§ãã¡ãã£ã¨ãã使ãæ¨ã¦ã¹ã¯ãªãããä½ãã¨ãã«ã¯ã»ã¼äºè¶³ããã åè: 10. æ¨æºã©ã¤ãã©ãªã®ç°¡åãªãã¢ã¼ http://www.python.jp/doc/release/tut/node12â¦
é¢æ°ãã¯ã©ã¹ãä¿åããã¹ã¯ãªãããã¡ã¤ã«ã¯importãããã¨ã§ãå¥ã®ã¹ã¯ãªããã§ä½¿ç¨ã§ããã â¼ä½¿ãæ¹ ä»¥ä¸ãtest.pyã¨ããååã§ä¿å #!/bin/env python # -*- coding: shift_jis -*- class Arithmetic: messge = "ã¡ã½ããå®è¡" def __init__(self): prinâ¦
pythonã®ã¯ã©ã¹ã§ã¯å®ç¾©ãã¦ããªãèå¥å(å¤æ°ãªã©)ãæå®ããã¨èªåçã«ç»é²ããã¦ãã¾ãã â¼ä¾ >>> ================================ RESTART ================================ >>> class test1: a = 0 b = 0 def testprint(self): print self.a + self.â¦
ã¯ã©ã¹ã®ä¸ã§å¤æ°ã使ãã¨ãã¯ãã¤ã³ãã³ã(åä¸ã)ã«ãã£ã¦åºåããããããã¯ã®é層ã«æ³¨æã â¼ä¾ >>> ================================ RESTART ================================ >>> class test: #ããã¯éå±¤ï¼ a = "test" def testprint(self): #ããâ¦