PythonÎļþµÄ¶Áд
Ïà±Èjava¶øÑÔ£¬PythonÓü¸ÐдúÂë¾Í¿ÉÒÔ´úÌæjavaÊ®À´ÐеĴúÂë£¬ÕæµÄ·Ç³£²»´í
'''
Created on 2009-9-2
@author: jiangqh
'''
# file create and write
context = '''hello world
hello china '''
f = file("hello.txt",'w')
f.write(context)
f.close()
Îļþ´´½¨
#use readline() read file
f = open("hello.txt")
while True:
line = f.readline()
if line:
print line
else :
break
f.close()
Ò»ÐÐÒ»ÐеĶÁÈ¡
# read more lines
f = file("hello.txt")
lines = f.readlines()
for line in lines:
print line
¶àÐжÁÈ¡
Ò»´ÎÐÔÈ«¶Á³öÎļþÀïµÄÄÚÈÝ
'''
Created on 2009-9-2
@author: jiangqh
'''
f = open("hello.txt")
context = f.read()
print context
f = open("hello.txt")
context = f.read(5) #¶ÁȡǰÎå×Ö½Ú
print context
print f.tell() #»ñµÃµ±Ç°Ö¸ÕëµÄλÖÃ
context = f.read(5) #¼ÌÐøµ±Ç°¶ÁÈ¡Îåλ
print context
print f.tell() #»ñµÃµ±Ç°Ö¸ÕëµÄλÖÃ
f.close()
Ïà¹ØÎĵµ£º
1.»¥ÁªÍø£ºÓÖÒôÒë“ÒòÌØÍø”»òÕß“Ó¢ÌØÍø”£¬ÊÇÖ¸ÔÚARPAÍø»ù´¡ÉÏ·¢Õ¹³öµÄÊÀ½çÉÏ×î´óµÄÈ«ÇòÐÔ»¥ÁªÍøÂç¡£
2.Óйػ¥ÁªÍøµÄÐÒé¿ÉÒÔ·ÖΪ3²ã£º
×îµ×²ãµÄÊÇIPÐÒ飬ÊÇÓÃÓÚ±¨ÎĽ»»»ÍøÂçµÄÒ»ÖÖÃæÏòÊý¾ÝµÄÐÒ飬ÕâÒ»ÐÒ鶨ÒåÁËÊý¾Ý°üÔÚÍø¼Ê´«ËÍʱµÄ¸ñʽ¡£
ÉÏÒ»²ãÊÇUDPÐÒéºÍTCPÐÒ飬ËüÃÇÓÃÓÚ¿ØÖÆÊý¾ÝÁ÷µÄ´«Ê ......
PythonÖÐÎļþ²Ù×÷¿ÉÒÔͨ¹ýopenº¯Êý£¬ÕâµÄÈ·ºÜÏñCÓïÑÔÖеÄfopen¡£Í¨¹ýopenº¯Êý»ñȡһ¸öfile object£¬È»ºóµ÷ÓÃread()£¬write()µÈ·½·¨¶ÔÎļþ½øÐжÁд²Ù×÷¡£
1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt')
......
PythonÖÐÖ´ÐÐϵͳÃüÁî³£¼û·½·¨ÓÐÁ½ÖÖ£º
Á½Õß¾ùÐè import os
(1) os.system
# ½ö½öÔÚÒ»¸ö×ÓÖÕ¶ËÔËÐÐϵͳÃüÁ¶ø²»ÄÜ»ñÈ¡ÃüÁîÖ´ÐкóµÄ·µ»ØÐÅÏ¢
system(command) -> exit_status
Execute the command (a string) in a subshell.
# Èç¹ûÔÙÃüÁîÐÐÏÂÖ´ÐУ¬½á¹ûÖ±½Ó´òÓ¡³öÀ´
>>> os. ......
ÔÎÄ
http://www.hetland.org/python/instant-hacking.php
Instant Hacking[Òë
ÎÄ]
ÒëÕߣº ¿Ï¶¨À´¹ý   ......
Òª´´½¨ÄãµÄapp£¨½«djangoÅäÖõ½»·¾³±äÁ¿Ï£©
python manage.py startapp polls
ËüÃǽ«»á´´½¨Ò»¸öpollsÎļþ¼Ð£¬ÀïÃæµÄÄÚÈÝÊÇ£º
¡¡¡¡polls/
¡¡¡¡¡¡¡¡__init__.py
¡¡¡¡¡¡¡¡models.py
¡¡¡¡¡¡¡¡views.py
Õâ¸öĿ¼½á¹¹¾ÍÊÇappÓ¦ÓóÌÐò¡£
±àдÊý¾Ý¿âWebÓ¦ÓóÌÐòµÄµÚÒ»²½ÊǶ¨ÒåÄãµÄÄ£ÐͲ㗗»ù±¾ÉϾÍÊÇÄãµÄÊý¾Ý¿ ......