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
Ïà¹ØÎĵµ£º
×òÌìÊÔÁËÏÂÓÃHTMLParserÀàÀ´½âÎöÍøÒ³£¬¿É·¢ÏÖ½á¹û²¢²»ÀíÏë¡£²»¹ÜÔõô˵£¬ÏÈдϹý³Ì£¬Ï£ÍûºóÀ´ÈËÄÜÔÚ´Ë»ù´¡ÉϽâ¾öÎÒËùÓöµ½µÄÎÊÌâ¡£
дÁË2Ì×½â¾ö·½°¸£¬µ±È»Õâ2Ì×Ö»ÄܶÔÌØ¶¨ÍøÕ¾ÓÐЧ¡£ÎÒÕâÀïÖ÷Ҫ˵Ã÷϶ÔBBCÖ÷Ò³www.bbc.co.ukºÍ¶ÔÍøÒ×www.163.comµÄ½âÎö¡£
¶ÔÓÚBBC£º
ÕâÌ×Òª¼òµ¥µÃ¶à£¬¿ÉÄÜÊǸÃÍøÒ³µÄ±àÂë±È½Ï±ê×¼°É
import ......
×òÌìÊÔÁËÏÂÓÃHTMLParserÀàÀ´½âÎöÍøÒ³£¬¿É·¢ÏÖ½á¹û²¢²»ÀíÏë¡£²»¹ÜÔõô˵£¬ÏÈдϹý³Ì£¬Ï£ÍûºóÀ´ÈËÄÜÔÚ´Ë»ù´¡ÉϽâ¾öÎÒËùÓöµ½µÄÎÊÌâ¡£
дÁË2Ì×½â¾ö·½°¸£¬µ±È»Õâ2Ì×Ö»ÄܶÔÌØ¶¨ÍøÕ¾ÓÐЧ¡£ÎÒÕâÀïÖ÷Ҫ˵Ã÷϶ÔBBCÖ÷Ò³www.bbc.co.ukºÍ¶ÔÍøÒ×www.163.comµÄ½âÎö¡£
¶ÔÓÚBBC£º
ÕâÌ×Òª¼òµ¥µÃ¶à£¬¿ÉÄÜÊǸÃÍøÒ³µÄ±àÂë±È½Ï±ê×¼°É
import ......
¼Ìǰƪ¡¶Import Module¡·£¨http://blog.csdn.net/xiadasong007/archive/2009/09/02/4512797.aspx£©£¬¼ÌÐø·ÖÎöǶÈ벿·Ö»ù´¡ÖªÊ¶¡£Õâ´Î²»¶à˵£¬ÓÐʲôÎÊÌâ¼ÇµÃ¶à²éÓ¢ÎÄ×ÊÁÏ£¬¹úÄÚµÄÕâ·½ÃæÖªÊ¶ÉÙ
»¹ÊÇÀ´¿´´úÂ룬дÍêÎÒ¾Í˯¾õÁË~
#include "python/python.h"
#include <iostream>
using namespace std;
int ......
µ±½ñÓÐÐí¶àÃâ·ÑµÄ RDBMS£¨Relational Database Management
System£¬¹ØÏµÊý¾Ý¿â¹ÜÀíϵͳ£©£¬ÆäÖÐһЩÊÇ¿ª·ÅÔ´ÂëÈí¼þ£¬ÁíһЩÊÇÉÌÒµ³§ÉÌÌṩµÄÃâ·Ñ²úÆ·¡£Èç¹ûÄúÕýÔÚʹÓà C/C++¡¢Java™¡¢.NET
»ò PHP
¿ª·¢Ó¦ÓóÌÐò£¬ÏëѰÕÒÒ»ÖÖ¿É¿¿µÄÊý¾Ý·þÎñÆ÷£¬Ï£ÍûËüÖ§³ÖÏȽøµÄ¼¼Êõ¡¢¾ßÓв»¶ÏÀ©´óµÄ¿ª·¢ÈËÔ±ÉçÇø²¢ÒѾ²¿ÊðÔÚÐí¶à¹Ø¼ ......
1. ´òÓ¡±äÁ¿ºÍ±äÁ¿×ÔÏÔ
>>> myString = 'Hello World!'
>>> print myString
Hello World!
>>> myString
'Hello World!'
ÒòΪ£º print Óï¾äµ÷ÓÃstr()º¯ÊýÏÔʾ¶ÔÏ󣬶ø½»»¥Ê½½âÊÍÆ÷Ôòµ÷ÓÃrepr()º¯ÊýÀ´ÏÔʾ¶ÔÏó
sys.stdout.write('hello')²»»áÔÚĩβ¼ÓÉÏ'\n'£¬¶øprint»á
2. ´òÓ¡Îļþ
hand ......