我会将一大堆纳斯达克股票定义为变量。 这是代码:
apt-get update
apt-get -t jessie-backports install dh-virtualenv
如果我打印出字符串" nasdaq"我可以看到它有以下格式:
from ftplib import FTP
def my_function(data):
print(data.decode())
ftp = FTP('ftp.nasdaqtrader.com')
ftp.login()
nasdaq=ftp.retrbinary('RETR /SymbolDirectory/nasdaqlisted.txt', my_function)
我想要一个只打印出代码的列表:
AAAP|Advanced Accelerator Applications S.A. - American Depositary Shares|Q|N|N|100|N|N
AAL|American Airlines Group, Inc. - Common Stock|Q|N|N|100|N|N
AAME|Atlantic American Corporation - Common Stock|G|N|N|100|N|N
AAOI|Applied Optoelectronics, Inc. - Common Stock|G|N|N|100|N|N
and so on...
这样做的正确方法是什么?
答案 0 :(得分:0)
print '\n'.join(share.split('|')[0] for share in nasdaq.splitlines())