Append some stuff into a file with only the last appended line reserved.

Hongyi Zhao hongyi.zhao at gmail.com
Tue Sep 3 18:20:32 EDT 2019


On Tue, 03 Sep 2019 08:29:31 +1000, Cameron Simpson wrote:

> Please describe this in more detail. Present a little pycurl output and
> then explain what portion of it should land in the log file.

See the following code from here: 
http://pycurl.io/docs/latest/callbacks.html#xferinfofunction

----------------
## Callback function invoked when download/upload has progress
def progress(download_t, download_d, upload_t, upload_d):
    print "Total to download", download_t
    print "Total downloaded", download_d
    print "Total to upload", upload_t
    print "Total uploaded", upload_d

c = pycurl.Curl()
c.setopt(c.URL, "http://slashdot.org/")
c.setopt(c.NOPROGRESS, False)
c.setopt(c.XFERINFOFUNCTION, progress)
c.perform()
--------------------


If I want to print these info ( or write them into log ) only when some 
specific events occur, say:

pycurl.ABORTED_BY_CALLBACK
pycurl.OPERTATION_TIMEOUT

How to do it?





More information about the Python-list mailing list