python self __init__
self
ÀàµÄ·½·¨ÓëÆÕͨµÄº¯ÊýÖ»ÓÐÒ»¸öÌرðµÄÇø±ð——ËüÃDZØÐëÓÐÒ»¸ö¶îÍâµÄµÚÒ»¸ö²ÎÊýÃû³Æ£¬µ«ÊÇ
ÔÚµ÷ÓÃÕâ¸ö·½·¨µÄʱºòÄ㲻ΪÕâ¸ö²ÎÊý¸³Öµ£¬Python»áÌṩÕâ¸öÖµ¡£Õâ¸öÌرðµÄ±äÁ¿Ö¸¶ÔÏó±¾
Éí£¬°´ÕÕ¹ßÀýËüµÄÃû³ÆÊÇself¡£
ÕâÒ²Òâζ×ÅÈç¹ûÄãÓÐÒ»¸ö²»ÐèÒª²ÎÊýµÄ·½·¨£¬Ä㻹ÊǵøøÕâ¸ö·½·¨¶¨ÒåÒ»¸öself²ÎÊý¡£
__init__·½·¨
__init__·½·¨ÔÚÀàµÄÒ»¸ö¶ÔÏó±»½¨Á¢Ê±£¬ÂíÉÏÔËÐС£Õâ¸ö·½·¨¿ÉÒÔÓÃÀ´¶ÔÄãµÄ¶ÔÏó×öһЩÄãÏ£
ÍûµÄ ³õʼ»¯ ¡£×¢Ò⣬Õâ¸öÃû³ÆµÄ¿ªÊ¼ºÍ½áβ¶¼ÊÇË«Ï»®Ïß¡£
#!/usr/bin/python
# Filename: class_init.py
class Person:
def __init__(self, name):
self.name = name
def sayHi(self):
print 'Hello, my name is', self.name
p = Person('Swaroop')
p.sayHi()
# This short example can also be written as Person('Swaroop').sayHi()
Êä³ö
$ python class_init.py
Hello, my name is Swaroop
Ïà¹ØÎĵµ£º
×î½üÓÖÖØÐÂ×°ÉÏÁËwindows 7¸Ð¾õ»¹ÊÇÄÇÑù£¬Ö÷ÒªÊÇÏëÓÃM8SDKдЩ³ÌÐò¡£Ò²ÏëÔÚwindowsÉÏÍæÍ棬һֱ¶¼¾õµÃÓÃCдһЩ³£ÓõĶ«¶«ºÜ¸´ÔÓ£¬Ö»ÓнèÖúÓÚ½âÊÍÐÔÓïÑÔÁË£¬ÔÚpython, ruby¼äÑ¡Ôñ£¬×îÖÕÓÃPython¡£
pythonµÄÓï·¨·Ç³£¼òµ¥£¬¶ÔÓÚÒ»¸öѧ¹ý±à³ÌµÄÈË¿ÉÄÜÒ»ÉÏÎç¾Í²î²»¶àÁË£¬²»¹ýpythonµÄÇ¿´óÖ®´¦ÔÚÓÚËüÓÐN¶àµÄ¿â¿ÉÒÔ·½±ãÎÒÃÇ´¦ÀíÎ ......
±¾ÎÄ×ܽáÁËÔÚPythonÖÐÖ÷ÒªµÄ¼¸ÖÖ´¦ÀíXMLµÄ·½·¨£º
Element Tree
SAX
Dom
ʹÓõÚÈý·½Àà¿âÈçAmara 2.x£¬ libxml2dom µÈ
Element Tree
Element TreeÊÇPython 2.5ÒýÈëµÄʹÓüòµ¥£¬¿ì½ÝµÄ´¦Àí·½·¨£¬ Ò²ÊÇPython±ê×¼Àà¿âÍƼöµÄ´¦ÀíXMLµÄ·½·¨¡£
ËüʹÓÃÊ÷ÐνڵãµÄÐÎʽÀ´¶ÁдXML¡£Element TreeÊÇÇáÁ¿¼¶µÄDOM£¬ ËùÒÔÊ ......
ÕÒÁË°ëÌìûÕÒ×Å£¬ÖÕÓÚÔÚÓ¢ÎÄÕ¾µãÉÏÕÒµ½£¬»¹ÓиÐлȺÀïµÄʯͷºÍÇòÃÔ
>>> s = datetime.datetime(2009,1,1)
>>> time.mktime(s.timetuple())
1230739200.0
±ðÍ⸶һ¸öpython¶Ôʱ¼äµÄһЩº¯Êý£¬ºÜºÃÓõÄ
ÎÒÃÇÏȵ¼Èë±ØÐëÓõ½µÄÒ»¸ömodule
>>> import time
ÉèÖÃÒ»¸öʱ¼äµÄ¸ñʽ£¬ÏÂÃæ»áÓõ½
& ......
ÒÔÏÂΪÎÒÔÚ´¦ÀíÍøÒ³±àÂëÎÊÌâ¿´µÄÎÄÕ£¬ÏÖÔÚдÅÀ³æ×Ô¼º´¦ÀíÍøÒ³±àÂëÎÊÌâȷʵ±È½ÏÂé·³£¬ÍøҳҲûÓй涨
Ò»¶¨ÒªÔÚMETAÍ·ÐÅÏ¢Àï´ø±àÂëÐÅÏ¢£¬¶øºÜ¶àÈËдµÄ̽²â±àÂë¾ÍÊÇ»ñÈ¡META£¬ÕâÊDz»¿ÉÈ¡µÄ£¬¶øÓеÄÈËÔòÊÇ·ÖÎöHTTP·µ»ØµÄÊý¾Ý°üÀï±ßµÄ
charset£¬È磨a.headers.getparam('charset')£©£¬¶øHTTP°üûÓй涨һ¶¨Òª´øcharset£¬ËùÒ ......
×÷ÕߣºÀÏÍõ
PythonËƺõºÜÌÖÑáÐÞÊηû£¬Ã»Óг£¼ûµÄstaticÓï·¨¡£Æ侲̬·½·¨µÄʵÏÖ´óÖÂÓÐÒÔÏÂÁ½ÖÖ·½·¨£º
µÚÒ»ÖÖ·½Ê½£¨staticmethod£©£º
>>> class Foo:
str = "I'm a static method."
def ba ......