Python defines a class instance as an FTP callback method

From , 3 Years ago, written in Python, viewed 53 times.
URL https://pastebin.vip/view/de6b1cf3
  1. class Writer:
  2.     def __init__(self, file):
  3.         self.f = open(file, "w")
  4.  
  5.     def __call__(self, data):
  6.         self.f.write(data)
  7.         self.f.write('\n')
  8.         print data
  9.  
  10. FILENAME = "AutoIndent.py"
  11. writer = Writer(FILENAME)
  12.  
  13. import ftplib
  14. ftp = ftplib.FTP('127.0.0.1', 'book', 'bookpw')
  15. ftp.retrlines("RETR %s" % FILENAME, writer)
  16. #//python/8052

Reply to "Python defines a class instance as an FTP callback method"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website