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

Python±Ê¼Ç£¨9£©

PythonÖеÄÎļþ²Ù×÷ÒÔ¼°ÊäÈëÊä³ö
ÎÒÃÇ¿ÉÒÔ·Ö±ðʹÓÃraw_inputºÍprintÓï¾äÀ´Íê³ÉÕâЩ¹¦ÄÜ¡£¶ÔÓÚÊä³ö£¬ÄãÒ²¿ÉÒÔʹÓöàÖÖ¶àÑùµÄstr£¨×Ö·û´®£©Àà¡£ÀýÈ磬ÄãÄܹ»Ê¹ÓÃrjust·½·¨À´µÃµ½Ò»¸ö°´Ò»¶¨¿í¶ÈÓÒ¶ÔÆëµÄ×Ö·û´®¡£ÀûÓÃhelp(str)»ñµÃ¸ü¶àÏêÇé¡£
 
 
ÁíÒ»¸ö³£ÓõÄÊäÈë/Êä³öÀàÐÍÊÇ´¦ÀíÎļþ¡£´´½¨¡¢¶ÁºÍдÎļþµÄÄÜÁ¦ÊÇÐí¶à³ÌÐòËù±ØÐèµÄ£¬ÎÒÃǽ«»áÔÚÕâÕÂ̽Ë÷ÈçºÎʵÏÖÕâЩ¹¦ÄÜ¡£
Ò».ʹÓÃÎļþ
Äã¿ÉÒÔͨ¹ý´´½¨Ò»¸öfileÀàµÄ¶ÔÏóÀ´´ò¿ªÒ»¸öÎļþ£¬·Ö±ðʹÓÃfileÀàµÄread¡¢readline»òwrite·½·¨À´Ç¡µ±µØ¶ÁдÎļþ¡£¶ÔÎļþµÄ¶ÁдÄÜÁ¦ÒÀÀµÓÚÄãÔÚ´ò¿ªÎļþʱָ¶¨µÄģʽ¡£×îºó£¬µ±ÄãÍê³É¶ÔÎļþµÄ²Ù×÷µÄʱºò£¬Äãµ÷ÓÃclose·½·¨À´¸æËßPythonÎÒÃÇÍê³ÉÁ˶ÔÎļþµÄʹÓã¬ÔÚ¸÷·½Ã棬ÓëC/C++ÀàËÆ¡£
#!/usr/bin/python
# Filename: using_file.py
poem = '''\
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
'''
f = file('poem.txt', 'w') # open for 'w'riting
f.write(poem) # write text to file
f.close() # close the file
f = file('poem.txt')
# if no mode is specified, 'r'ead mode is assumed by default
while True:
line = f.readline()
if len(line) == 0: # Zero length indicates EOF
break
print line,
# Notice comma to avoid automatic newline added by Python
f.close() # close the file

Êä³öΪ£º
$ python using_file.py
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!

ģʽ¿ÉÒÔΪ¶Áģʽ£¨'r'£©¡¢Ð´Ä£Ê½£¨'w'£©»ò×·¼Óģʽ£¨'a'£©¡£ÏêϸÇé¿ö¿É¼ûhelp(file)¡£
¶þ.´æ´¢Æ÷
PythonÌṩһ¸ö±ê×¼µÄÄ£¿é£¬³ÆÎªpickle¡£Ê¹ÓÃËüÄã¿ÉÒÔÔÚÒ»¸öÎļþÖд¢´æÈκÎPython¶ÔÏó£¬Ö®ºóÄãÓÖ¿ÉÒÔ°ÑËüÍêÕûÎÞȱµØÈ¡³öÀ´¡£Õâ±»³ÆÎª³Ö¾ÃµØ´¢´æ¶ÔÏó¡£
»¹ÓÐÁíÒ»¸öÄ£¿é³ÆÎªcPickle£¬ËüµÄ¹¦ÄܺÍpickleÄ£¿éÍêÈ«Ïàͬ£¬Ö»²»¹ýËüÊÇÓÃCÓïÑÔ±àдµÄ£¬Òò´ËÒª¿ìµÃ¶à£¨±Èpickle¿ì1000±¶£©¡£Äã¿ÉÒÔʹÓÃËüÃÇÖеÄÈÎÒ»¸ö£¬¶øÎÒÃÇÔÚÕâÀォʹÓÃcPickleÄ£¿é¡£¼Çס£¬ÎÒÃǰÑÕâÁ½¸öÄ£¿é¶¼¼ò³ÆÎªpickleÄ£¿é¡£
ÀýÈç:
#!/usr/bin/python
# Filename: pickling.py
import cPickle as p
#import pickle as p
shoplistfile = 'shoplist.data'
# the name of the file where we will store the object
shoplist = ['a


Ïà¹ØÎĵµ£º

pythonÖеÄÒ»¸öºÃÓõÄÎļþÃû²Ù×÷Ä£¿églob

  ѧϰpython±¾¾ÍÊÇÒµÓàÖ®ºÃ£¡Ê鱾ɶµÄ£¬¶¼ÎÞ´Ó˵Æð¡£ËùÒÔż¶ûÅöµ½Ò»¸öºÃµÄÄ£¿é£¬¾ÍÒªÔÚ²©¿ÍÖмǼһÏ£¬ÒÔ±ãÈÕºóÖ®Óá£ÊÇÒÔ¸ßÊÖÖ±½ÓµÄÆ®¹ý¡£ÏÂÃæÇÐÈëÕýÌâ¡£
  globÊÇpython×Ô¼º´øµÄÒ»¸öÎļþ²Ù×÷Ïà¹ØÄ£¿é£¬ÄÚÈÝÒ²²»¶à£¬ÓÃËü¿ÉÒÔ²éÕÒ·ûºÏ×Ô¼ºÄ¿µÄµÄÎļþ£¬¾ÍÀàËÆÓÚWindowsϵÄÎļþËÑË÷£¬¶øÇÒÒ²Ö§³ÖͨÅä·û£¬*,?,[]Õ ......

python PIL ÅúÁ¿´¦Àí´¦ÀíͼƬ

¿Í»§¸øÒ»¶ÑͼƬҪ´«µ½ºǫ́£¬Í¼Æ¬Ì«´óÁË£¬ÉϰÙÕÅͼÓÃphotoshop¸ÄÌ«Âý£¬¾ÍÏëµ½ÓÃpythonд¸ö¼òµ¥µÄÅú´¦Àí¡£¹¦Äܼòµ¥¾ÍÊǰÑԭͼ°´±ÈÀýËõС£¬´úÂë¸ü¼òµ¥ 20¶àÐС£
# -*- coding: cp936 -*-
import Image
import glob, os
#ͼƬÅú´¦Àí
def timage():
for files in glob.glob('D:\\1\\*.JPG'):
filepath,filena ......

Python±Ê¼Ç£¨5£©

Ä£¿é
 
Ò».¼ò½é
Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.pyΪÀ©Õ¹Ãû¡£
 
ÀýÈ磺
 
#!/usr/bin/python
# Filename: using_sys.py
import sys
print 'The command line arguments are:'
for i in sys.argv:
print i
print '\n ......

pythonµÄwiki ÁÐ×Ó.

#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response

def index(request, pagename=""):
"""ÏÔʾÕý³£Ò³Ã棬¶ÔÒ³ÃæµÄÎÄ×Ö×öÌØÊâµÄÁ´½Ó´¦Àí"""
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ