python ÃüÁîÐвÎÊý
±¾Æª½«½éÉÜpythonÖÐsys, getoptÄ£¿é´¦ÀíÃüÁîÐвÎÊý
Èç¹ûÏë¶Ôpython½Å±¾´«²ÎÊý£¬pythonÖжÔÓ¦µÄargc, argv(cÓïÑÔµÄÃüÁîÐвÎÊý)ÊÇÊ²Ã´ÄØ£¿
ÐèҪģ¿é£ºsys
²ÎÊý¸öÊý£ºlen(sys.argv)
½Å±¾Ãû£º sys.argv[0]
²ÎÊý1£º sys.argv[1]
²ÎÊý2£º sys.argv[2]
test.py
1
import sys
2
print "½Å±¾Ãû£º", sys.argv[0]
3
for i in range(1, len(sys.argv)):
4
print "²ÎÊý", i, sys.argv[i]
>>>python test.py hello world
½Å±¾Ãû£ºtest.py
²ÎÊý 1 hello
²ÎÊý 2 world
pythonÖÐʹÓÃÃüÁîÐÐÑ¡Ï
ÀýÈçÎÒÃÇÐèÒªÒ»¸öconvert.py½Å±¾¡£ËüµÄ×÷ÓÃÊÇ´¦ÀíÒ»¸öÎļþ,²¢½«´¦ÀíºóµÄ½á¹ûÊä³öµ½ÁíÒ»¸öÎļþÖС£
ÒªÇó¸Ã½Å±¾Âú×ãÒÔÏÂÌõ¼þ£º
1.ͨ¹ý-i -oÑ¡ÏîÀ´Çø±ð²ÎÊýÊÇÊäÈëÎļþ»¹ÊÇÊä³öÎļþ.
>>> python convert.py -i inputfile -o outputfile
2.µ±²»ÖªµÀconvert.pyÐèÒªÄÄЩ²ÎÊýʱ£¬ÓÃ-h´òÓ¡³ö°ïÖúÐÅÏ¢
>>> python convert.py -h
getoptº¯ÊýÔÐÎ:
getopt.getopt(args, options[, long_options])
convert.py
01
import sys, getopt
02
03
opts, args = getopt.getopt(sys.argv[1:], "hi:o:")
04
input_file=""
05
output_file=""
06
07
for op, value in opts:
08
if op == "-i":
09
input_file = value
10
elif op == "-o":
11
output_file = value
12
elif op == "-h":
13
usage()
14
sys.exit()
´úÂë½âÊÍ£º
a) sys.argv[1:]ΪҪ´¦ÀíµÄ²ÎÊýÁÐ±í£¬sys.argv[0]Ϊ½Å±¾Ãû£¬ËùÒÔÓÃsys.argv[1:]¹ýÂ˵ô½Å±¾Ãû¡£
b) "hi:o:": µ±Ò»¸öÑ¡ÏîÖ»ÊDZíʾ¿ª¹Ø×´Ì¬Ê±£¬¼´ºóÃæ²»´ø¸½¼Ó²ÎÊýʱ£¬ÔÚ·ÖÎö´®ÖÐдÈëÑ¡Ïî×Ö·û¡£µ±Ñ¡ÏîºóÃæÊÇ´øÒ»¸ö¸½¼Ó²ÎÊýʱ£¬ÔÚ·ÖÎö´®ÖÐдÈëÑ¡Ïî×Ö·ûͬʱºóÃæ¼ÓÒ»¸ö":"ºÅ¡£ËùÒÔ"hi:o:"¾Í±íʾ"h"ÊÇÒ»¸ö¿ª¹ØÑ¡Ï"i:"ºÍ"o:"Ôò±íʾºóÃæÓ¦¸Ã´øÒ»¸ö²ÎÊý¡£
c)
Ïà¹ØÎĵµ£º
£¨Ò»£© py2exe¼ò½é
py2exeÊÇÒ»¸ö½«python½Å±¾×ª»»³ÉwindowsÉϵĿɶÀÁ¢Ö´ÐеĿÉÖ´ÐгÌÐò(*.exe)µÄ¹¤¾ß£¬ÕâÑù£¬Äã¾Í¿ÉÒÔ²»ÓÃ×°python¶øÔÚ
windowsϵͳÉÏÔËÐÐÕâ¸ö¿ÉÖ´ÐгÌÐò¡£
¡¡¡¡
¡¡¡¡py2exeÒѾ±»ÓÃÓÚ´´½¨
wxPython,Tkinter,Pmw,PyGTK,pygame,win32com
clientºÍserver,ºÍÆäËüµÄ¶ÀÁ¢³ ......
Python ×Ô1.5°æ±¾ÆðÔö¼ÓÁËre Ä£¿é£¬ËüÌṩ Perl ·ç¸ñµÄÕýÔò±í´ïʽģʽ¡£Python 1.5֮ǰ°æ±¾ÔòÊÇͨ¹ý regex Ä£¿éÌṩ Emecs ·ç¸ñµÄģʽ¡£Emacs ·ç¸ñģʽ¿É¶ÁÐÔÉÔ²îЩ£¬¶øÇÒ¹¦ÄÜÒ²²»Ç¿£¬Òò´Ë±àддúÂëʱ¾¡Á¿²»ÒªÔÙʹÓà regex Ä£¿é£¬µ±È»Å¼¶ûÄ㻹ÊÇ¿ÉÄÜÔÚÀÏ´úÂëÀï·¢ÏÖÆä×ÙÓ°¡£
& ......
ÉÏһƪÖÐÎÒÃÇÒѾÁ˽âÈçºÎÔÚPython³ÌÐòºÍCÄ£¿éÖ®¼ä½øÐÐÖµµÄÏ໥´«µÝ£¬ÏÖÔÚÎÒÃÇÀ´½øÈëʵ×÷½×¶Î£¬¿´¿´ÈçºÎ½«Ò»¸öCÓïÑÔ¿ª·¢µÄ¿ªÔ´mp3±à½âÂë¿âLAME°üװΪһ¸öPythonÏ¿ÉÒÔʹÓõÄÀ©Õ¹Ä£¿é¡£Ê×ÏÈÈ¥http://lame.sourceforge.net/download.phpÏÂÔØLAMEµÄÔ´´úÂ룬ȻºóÇл»µ½rootÓû§±àÒëÔ´´úÂ룬./configure
make
make instal ......
̸µ½ÁËPythonÓï¾äµÄÁ½ÖÖÖ´Ðз½Ê½£¬Êµ¼ÊÉÏ£¬ÕâÁ½ÖÖÔËÐз½Ê½ÔÚ±¾ÖÊ ÉÏÊÇÏàͬµÄ£¬ËüÃǶ¼ÊÇÓɽâÊÍÆ÷À´½âÊÍÖ´ÐÐÎÒÃÇÌṩµÄPythonÓï¾ä¡£ ÕâÀïËù˵µÄ½âÊÍÖ´ÐÐÊÇÏà¶ÔÓÚ±àÒëÖ´ÐжøÑԵġ£ÎÒÃÇÖªµÀ£¬Ê¹ÓÃÖîÈç C»òC++Ö®ÀàµÄ±àÒëÐÔÓïÑÔ±àдµÄ³ÌÐò¿ÉÒÔ´ÓÔ´Îļþת»»³É¼ÆËã»úʹÓà µÄ»úÆ÷ÓïÑÔ£¬ ¾Á¬½ÓÆ÷Á¬½ÓºóÐγɶþ½øÖÆ¿ÉÖ´ÐÐÎļþ¡£µ±ÎÒÃÇÔ ......
Python×Ö·û´®²Ù×÷
pythonÈçºÎÅжÏÒ»¸ö×Ö·û´®Ö»°üº¬Êý×Ö×Ö·û
python ×Ö·û´®±È½Ï
ÏÂÃæÁгöÁ˳£ÓõÄpythonʵÏÖµÄ×Ö·û´®²Ù×÷
1.¸´ÖÆ×Ö·û´®
#strcpy(sStr1,sStr2)
sStr1 = 'strcpy'
sStr2 = sStr1
sStr1 = 'strcpy2'
print sStr2
2.Á¬½Ó×Ö·û´®
#strcat(sStr1,sStr2)
sStr1 = 'strcat'
sStr2 = 'appen ......