Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

pythonÖÐpackage»úÖƵÄÁ½ÖÖʵÏÖ·½Ê½


µ±Ö´ÐÐimport
moduleʱ£¬½âÊÍÆ÷»á¸ù¾ÝÏÂÃæµÄËÑË÷·¾¶£¬ËÑË÷module1.pyÎļþ¡£
1) µ±Ç°¹¤×÷Ŀ¼
2) PYTHONPATHÖеÄĿ¼
3) Python°²×°Ä¿Â¼
(/usr/local/lib/python)
ÊÂʵÉÏ£¬Ä£¿éËÑË÷ÊÇÔÚ±£´æÔÚsys.pathÕâ¸öÈ«¾Ö±äÁ¿ÖеÄĿ¼ÁбíÖнøÐÐËÑË÷¡£
sys.path»áÔÚ½âÊÍÆ÷¿ªÊ¼Ö´ÐÐʱ±»³õʼ»¯³É°üº¬£º
1)µ±Ç°¹¤×÷Ŀ¼
2) PYTHONPATHÖеÄĿ¼
3) Python°²×°Ä¿Â¼
(/usr/local/lib/python)
packageÊÇÄ£¿éµÄ¼¯ºÏ£¬Ã¿Ò»¸öPackageµÄ¸ùĿ¼ÏÂÃ涼Ӧµ±ÓÐÒ»¸ö__init__.py
Îļþ¡£µ±½âÊÍÆ÷·¢ÏÖĿ¼ÏÂÓÐÕâ¸öÎļþʱ£¬Ëû¾Í»áÈÏΪÕâÊÇÒ»¸öPackage£¬¶ø²»ÊÇÒ»¸öÆÕͨµÄĿ¼¡£
ÎÒÃÇͨ¹ýÏÂÃæÕâÑùµÄÒ»¸öʵÀýÀ´ËµÃ÷
¼Ù¶¨ÏîÄ¿½á¹¹ÈçÏ£º
demo.py
MyPackage
---classOne.py
---classTwo.py
---__init__.py       ÏÖÔÚÎÒÃÇͨ¹ýÁ½ÖÖ·½Ê½À´ÊµÏÖ°ü»úÖÆ£¬Ö÷ÒªÇø±ð¾ÍÔÚÓÚÊÇ·ñÔÚ__init__.pyÖÐдÈëÄ£¿éµ¼ÈëÓï¾ä¡£
1£¬__init__.pyÊÇÒ»¸ö¿Õ°×ÎļþµÄ·½Ê½£¬ demo.pyÄÚÈÝÈçÏ£º
from MyPackage.classOne import classOne
from MyPackage.classTwo import classTwo
if __name__ == "__main__":
    c1 = classOne()
    c1.printInfo()
    c2 = classTwo()
    c2.printInfo()
classOne.pyÄÚÈÝÈçÏ£º
class classOne:
    def __init__(self):
        self.name = "class one"
    
    def printInfo(self):
        print("i am class One!")
 classTwo.pyÄÚÈÝÈçÏ£º
class classTwo:
    def __init__(self):
        self.name = "class two"
    
    def printInfo(self):
        print("i am class two!")
        
 2,Èç¹ûÔÚ__init__.pyÖÐдÈëµ¼ÈëÄ£¿éµÄÓï¾ä£¬ÔòÉÏÊöÀý×Ó¿ÉÒÔÕâÑùÀ´×ö¡£
ÆäÖÐ__init__.py


Ïà¹ØÎĵµ£º

Install Python + Eric IDE


Install Python Eric IDE
1 Download following things
 
1) Python3.1
 
2) PyQt for python 3.1
(http://www.riverbankcomputing.co.uk/software/pyqt/download) I am using
PyQt-Py3.1-gpl-4.7.3-2.exe
 
3) Eric5 IDE
(http://eric-ide.python-projects.org/eric-download.html)
 
2 ......

»°ËµPython£¨ËÄ£©»¶Ó­Ð¡Âéȸ

С°×ÊǸö΢ÈíÃÔ£¬ËûµÄżÏñÊDZȶû´óÊ壬ԭÒòµ±È»ÊǵØÇòÈ˶¼ÖªµÀÀ²¡£´ó¶þµÄʱºò£¬ËûµÄ“ê¡Ñ§¼Æ»®”ÔøÒ»¶ÈµÃ³Ñ£¬Ô­ÒòÊÇËû¹Ò¿ÆÌ«¶à¡£µ±È»£¬´óÈýÐÂѧÆÚ¿ªÊ¼µÄʱºò£¬Ãæ¶Ô¹«ÖÚÖÊÒÉ£¬Ð¡°×Õ¾ÔÚÒÎ×ÓÉÏ£¬Ïñ¼«ÁË¡¶´óÄÚÃÜ̽ÁãÁã·¢¡·ÀïµÄÎ÷ÃÅ´µÑ©£º“ÊÀ½çÊ׸»±È²»Ò»¶¨Óжà³öÉ«£¬ÕâÖ»²»¹ýÊÇÄãÃÇÕâЩÐǶ·ÊÐÃñÒ»ÏáÇéÔ¸µÄÏë·¨° ......

python ±Ê¼Ç for loop and extend, append

list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html Õ⼸Ìì¿´Ò»ÏÂ
python howto
¶÷¡£python documentation ȷʵºÜºÃºÜÇ¿´ó°¡£¡
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......

ÊÖ¶¯ÖÆ×÷pythonµÄexe¿ÉÖ´ÐгÌÐò


1. ÊÖ¶¯ÖÆ×÷pythonµÄexe¿ÉÖ´ÐгÌÐò
                                      תÔØ---------------
PythonûÓÐÄÚ½¨Ò»¸ö±à ......

Python Get Key press

refer from:  http://www.daniweb.com/forums/thread115282.html#
python
Syntax
(Toggle Plain Text
)

# respond to a key
without the need to press
enter
 
import
Tkinter
as tk
 
def
keypress(
event)
:
if
event.keysym
== 'Escape'
:
root.destroy
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ