I want to extract a text file from a FTP server. This is the code I already have:
from ftplib import FTP
import re
def my_function(data):
print(data)
ftp = FTP('ftp.nasdaqtrader.com')
ftp.login()
nasdaq=ftp.retrbinary('RETR /SymbolDirectory/nasdaqlisted.txt', my_function)
#nasdaq contains the text file
I've had a couple of problems with this approach. For instance, every time I run the script everything prints out which I really don't want, I just need the variable "nasdaq" to be stored as a string. Also, even though "nasdaq" prints out this line:
b'Symbol|Security Name|Market Category|Test Issue|Financial Status|Round Lot Size|ETF|NextShares\r\nAAAP|Advanced Accelerator Applications S.A. - American Depositary Shares
I can't prove it to be in "nasdaq":
print ("\r\nAAAP|Advanced Accelerator Applications S.A." in nasdaq)
Out: False
What would be a more pythonic approach?