Python ÐòÁÐ
Python ÐòÁÐ
ÁÐ±í¡¢Ôª×éºÍ×Ö·û´®¶¼ÊÇÐòÁУ¬µ«ÊÇÐòÁÐÊÇʲô£¬ËüÃÇΪʲôÈç´ËÌØ±ðÄØ£¿ÐòÁеÄÁ½¸öÖ÷ÒªÌØµãÊÇË÷Òý²Ù×÷·ûºÍÇÐÆ¬²Ù×÷·û¡£Ë÷Òý²Ù×÷·ûÈÃÎÒÃÇ¿ÉÒÔ´ÓÐòÁÐÖÐץȡһ¸öÌØ¶¨ÏîÄ¿¡£ÇÐÆ¬²Ù×÷·ûÈÃÎÒÃÇÄܹ»»ñÈ¡ÐòÁеÄÒ»¸öÇÐÆ¬£¬¼´Ò»²¿·ÖÐòÁС£
ʹÓÃÐòÁÐ
Àý9.5 ʹÓÃÐòÁÐ
#!/usr/bin/python
# Filename: seq.py
shoplist = ['apple', 'mango', 'carrot', 'banana']
# Indexing or 'Subscription' operation
print 'Item 0 is', shoplist[0]
print 'Item 1 is', shoplist[1]
print 'Item 2 is', shoplist[2]
print 'Item 3 is', shoplist[3]
print 'Item -1 is', shoplist[-1]
print 'Item -2 is', shoplist[-2]
# Slicing on a list
print 'Item 1 to 3 is', shoplist[1:3]
print 'Item 2 to end is', shoplist[2:]
print 'Item 1 to -1 is', shoplist[1:-1]
print 'Item start to end is', shoplist[:]
# Slicing on a string
name = 'swaroop'
print 'characters 1 to 3 is', name[1:3]
print 'characters 2 to end is', name[2:]
print 'characters 1 to -1 is', name[1:-1]
print 'characters start to end is', name[:]
£¨Ô´Îļþ£ºcode/seq.py£©
Êä³ö
$ python seq.py
Item 0 is apple
Item 1 is mango
Item 2 is carrot
Item 3 is banana
Item -1 is banana
Item -2 is carrot
Item 1 to 3 is ['mango', 'carrot']
Item 2 to end is ['carrot', 'banana']
Item 1 to -1 is ['mango', 'carrot']
Item start to end is ['apple', 'mango', 'carrot', 'banana']
characters 1 to 3 is wa
characters 2 to end is aroop
characters 1 to -1 is waroo
characters start to end is swaroop
ËüÈçºÎ¹¤×÷
Ê×ÏÈ£¬ÎÒÃÇÀ´Ñ§Ï°ÈçºÎʹÓÃË÷ÒýÀ´È¡µÃÐòÁÐÖеĵ¥¸öÏîÄ¿¡£ÕâÒ²±»³Æ×÷ÊÇϱê²Ù×÷¡£Ã¿µ±ÄãÓ÷½À¨ºÅÖеÄÒ»¸öÊýÀ´Ö¸¶¨Ò»¸öÐòÁеÄʱºò£¬Python»áΪÄãץȡÐòÁÐÖжÔӦλÖõÄÏîÄ¿¡£¼Çס£¬Python´Ó0¿ªÊ¼¼ÆÊý¡£Òò´Ë£¬shoplist[0]ץȡµÚÒ»¸öÏîÄ¿£¬shoplist[3]ץȡshoplistÐòÁÐÖеĵÚËĸöÔªËØ¡£
Ë÷ÒýͬÑù¿ÉÒÔÊǸºÊý£¬ÔÚÄÇÑùµÄÇé¿öÏ£¬Î»ÖÃÊÇ´ÓÐòÁÐβ¿ªÊ¼¼ÆËãµÄ¡£Òò´Ë£¬shoplist[-1]±íʾÐòÁеÄ×îºóÒ»¸öÔªËØ¶øshoplist[-2]ץȡÐòÁеĵ¹ÊýµÚ¶þ¸öÏîÄ¿¡£
ÇÐÆ¬²Ù×÷·ûÊÇÐòÁÐÃûºó¸úÒ»¸ö·½À¨ºÅ£¬·½À¨ºÅÖÐÓÐÒ»¶Ô¿ÉÑ¡µÄÊý×Ö£¬²¢ÓÃðºÅ·Ö¸î¡£×¢ÒâÕâÓëÄãʹÓõÄË÷Òý²Ù×÷·ûÊ®·ÖÏàËÆ¡£¼ÇסÊýÊÇ¿ÉÑ¡µÄ£¬¶øÃ°ºÅÊDZØÐëµÄ¡£
ÇÐÆ¬²Ù×÷·ûÖеĵ
Ïà¹ØÎĵµ£º
#==================================================
import wx
import wx.media
class MyFrame(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,-1,title,pos=(150,150),size&;nbsp;=(640, 480),style=wx.MAXIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX| ......
Including binaries in your sources
+y F J2A T&N1H f(L ]0
Sometime it's handy to include small files in your sources (icons, test files, etc.)CNOUG²©¿ÍÊ×Ò³ P x z c W R K+x3{ N
CNOUG²©¿ÍÊ×Ò³ h I A O$k-n P
Let's take a file (myimage.gif) and convert it in base64 (optionnaly compressing it wit ......
¼ò½é
ÄãÒѾѧϰÁËÈçºÎÔÚÄãµÄ³ÌÐòÖж¨ÒåÒ»´Îº¯Êý¶øÖØÓôúÂë¡£Èç¹ûÄãÏëÒªÔÚÆäËû³ÌÐòÖÐÖØÓúܶຯÊý£¬ÄÇôÄã¸ÃÈçºÎ±àд³ÌÐòÄØ£¿Äã¿ÉÄÜÒѾ²Âµ½ÁË£¬´ð°¸ÊÇʹÓÃÄ£¿é¡£Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.pyΪÀ©Õ¹Ãû¡£
Ä£¿é¿ÉÒÔ´ÓÆäËû³ÌÐò ÊäÈë ÒÔ±ãÀûÓÃËüµ ......
1. What’s the difference between all of the os.popen() methods?
popen2 doesn't capture standard error, popen3 does capture standard
error and gives a unique file handle for it. Finally, popen4 captures
standard error but includes it in the same file object as standard
output.
os.popen()&n ......