eat python 003
Documentation for C's fopen():
---
r Open text file for reading. The stream is positioned at the beginning
of the file.
r+ Open for reading and writing. The stream is positioned at the
beginning of the file.
w Truncate file to zero length or create text file for writing. The
stream is positioned at the beginning of the file.
w+ Open for reading and writing. The file is created if it does not
exist, otherwise it is truncated. The stream is positioned at the
beginning of the file.
a Open for writing. The file is created if it does not exist. The stream
is positioned at the end of the file.
a+ Open for reading and writing. The file is created if it does not
exist. The stream is positioned at the end of the file.
======================================================
In Python: http://docs.python.org/library/functions.html#open
Modes 'r+'
, 'w+'
and 'a+'
open the file for updating (note that
'w+'
truncates the file). Append 'b'
to the mode to open the file in
binary mode, on systems that differentiate between binary and text files; on
systems that don’t have this distinction, adding the 'b'
has no effect.
In addition to the standard fopen()
values mode
may be 'U'
or
'rU'
. Python is usually built with universal newline support; supplying
'U'
opens the file as a text file, but lines may be terminated by any of the
following: the Unix end-of-line convention '\n'
, the Macintosh convention
'\r'
, or the Windows convention '\r\n'
. All of these external
representations are seen as '\n'
by the Python program. If Python is built
without universal newline support a mode
with 'U'
is the same as normal
text mode. Note that file objects so opened also have an attribute called
newlines
which has a value of None
(if no newlines have yet been
seen), '\n'
, '\r'
, '\r\n'
, or a tuple containing all the newline
types seen.
Python enforces that the mode, after stripping 'U'
, begins with 'r'
,
'w'
Ïà¹ØÎĵµ£º
pythonÖйúÂÛ̳ http://www.okpython.com/bbs/index.php
¿ªÔ´ÉçÇø http://sourceforge.net/
python¹ÙÍø http://www.python.org/
pythonIDE BOAhttp://boa-constructor.sourceforge.net/
pythonIDE ´óÈ«http://www.oschina.net/project/tag/120
python×é¼þhttp://py.dw ......
1£®»ñµÃµ±Ç°Â·¾¶
ÔÚPythonÖпÉÒÔʹÓÃos.getcwd()º¯Êý»ñµÃµ±Ç°µÄ·¾¶¡£ÆäÔÐÍÈçÏÂËùʾ¡£
os.getcwd()
¸Ãº¯Êý²»ÐèÒª´«µÝ²ÎÊý£¬Ëü·µ»Øµ±Ç°µÄĿ¼¡£ÐèҪ˵Ã÷µÄÊÇ£¬µ±Ç°Ä¿Â¼²¢²»ÊÇÖ¸½Å±¾ËùÔÚµÄĿ¼£¬¶øÊÇËùÔËÐнű¾µÄĿ¼¡£ÀýÈ磬ÔÚPythonWinÖÐÊäÈëÈçϽű¾¡£
>>> import os
>>> print 'current director ......
import Queue, threading, sys
from threading import Thread
import time,urllib
# working thread
class Worker(Thread):
worker_count = 0
def __init__( self, workQueue, resultQueue, timeout = 0, **kwds):
Thread.__init__( self, **kwds ) ......
ĿǰΪֹ£¬¾ÝÎÒËùÖª£¬ÔÚpythonÖжÔÏó³Ö¾Ã»¯ÓÐÒÔϼ¸ÖÖ·½·¨£º
1. ʹÓÃ(dbhash/bsddb, dbm, gdbm, dumbdbm µÈ£©ÒÔ¼°ËüÃǵÄ"¹ÜÀíÆ÷"( anydbm )¡£Ö»ÌṩÁË Python ×Ö
·û´®µÄÓÀ¾ÃÐÔ´¢´æ. Ìṩһ¸öÀàËÆ×ÖµäºÍÎļþµÄ¶ÔÏ󣬿ÉÒÔÍê³É×Ö·û´®µÄÓÀ¾ÃÐÔ´æ´¢¡£
2. ʹÓÃmarshalºÍpickleÀ´ÐòÁл¯python¶ÔÏ󣬲¢¾ß±¸´æ´¢µ½½éÖÊÉϵĹ ......
ÓÉsubprocess´´½¨Ò»¸ö½ø³Ì£¬È»ºó½øÐмàÊÓ
ÿһÃëÖӲ鿴һ´Î£¬Èç¹ûÕýÔÚÔËÐУ¬´òÓ¡pidºÍrunning£¬Èç¹ûÒÑÍ£Ö¹£¬,¼ÌÐøÖ´ÐÐÈÎÎñ²¢´òÓ¡Termined
shellºÍstdout¾ùÉèÖÃΪFalse
Ò²ÐíÕâ¶Ô×ö²¡¶¾µÄÊØ»¤½ø³ÌºÜºÃ
#!/usr/bin/env python
import subprocess , sys , time
p=subprocess.Popen(['ping','127.0.0.1','-n','10'], she ......