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
Ïà¹ØÎĵµ£º
±àÒëÁËÒ»¸öwindowsϵÄpython3Á¬½ÓMysqlµÄ¿â
mypysql
°æ±¾ÊÇ 0.5.1 £¬¸ù¾Ý¹Ù·½µÄÐÞ¸ÄÈÕÖ¾£¬Õâ¸ö°æ±¾ÐÞ¸ÄÁË0.5ÖÐÒ»¸öÄÚ´æй©ÎÊÌâ¡£
Ô´´úÂëºÍ±àÒëºóµÄÎļþΪ£º
http://211.147.215.55/down/mypysql-0.5.1-win.zip
mypysqlµÄ¹Ù·½µØÖ· https://sourceforge.net/projects/mypysql/
......
1. ÊÖ¶¯ÖÆ×÷pythonµÄexe¿ÉÖ´ÐгÌÐò
תÔØ---------------
PythonûÓÐÄÚ½¨Ò»¸ö±à ......
×Ô¼ºÓöµ½µÄÒ»¸öÎÊÌâ, WestGecoµÄ3DµØÕðÊý¾Ý, ÌáÈ¡µ¼º½Êý¾Ý:
#!/bin/env python
import sys
import struct
try:
f=open(sys.argv[1],'rb')
except (IOError,Exception):
print '''usage:
scriptname segyfilename
'''
&nbs ......
Ó¢ÎÄ°æDive in python¿ÉÒÔÔÚÏÂÃæÕÒµ½ÖÐÎÄ·Òëhttp://linuxtoy.org/docs/dip/toc/index.html
Ä£¿éµÄ__name__£¬µ±Ä£¿é±»importʱ£¬ÆäΪģ¿éµÄÃû×Ö£¬µ±Ä£¿é×÷ΪmainÖ´ÐеÄʱºò£¬ÆäΪ__main__
´ÊµäµÄkeyÊÇ´óСдÃô¸ÐµÄ¡£
ListÒ²Ö§³ÖÖØÔØ+²Ù×÷£¬ÓÃÓÚ½«Á½¸ölistÁ¬½ÓÆðÀ´£¬²¢·µ»ØÒ»¸öList£¬Òò´ËËüûÓÐextendedÖ´ÐиßЧ¡£listÒ²+ ......
С°×¶ÔÉϽڿÎÀïµÄ“СÂéȸ”ÐËȤ°»È»£¬ÕûÌì¾ÍÔÚËÞÉáµ·¹Ä¡£Õâ²»£¬¼¸ÌìÏÂÀ´ËûÒѾ¹¥ÏÂÊ®¼¸¸öÍøÕ¾ÁË¡£
С²Ëȴϲ»¶Ò»¸öÈË×øÔÚµçÄÔÅԱߣ¬Öå×Åüͷ£¬ÐÀÉÍ×ÅÕâÒ»ÐÐÐÐ×Ô¼º¿´²»¶®µÄ´úÂë¡£“ÕâЩ×Ö·ûºÃ¹ÖÒìѽ£¡”С²ËÍá×ÅÍ·£¬“ËüΪɶ½ÐÕýÔò±í´ïʽÄØ£¿”
°Ù¶Èһϣ¬ÖÕÓÚÖªµÀ¡£Ð¡² ......