我正在尝试打印csv文件中的每一行,但是它将仅打印第一行。 这是负责的代码:
var request = (HttpWebRequest) WebRequest.Create("https://analytics.itunes.apple.com/#/apps?t=apps&interval=r&datesel=d30");
request.Headers["Host"] = "analytics.itunes.apple.com";
request.Headers["Connection"] = "keep-alive";
request.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
request.Headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.Headers["Accept-Language"] = "uk-UA,uk;q=0.9,ru;q=0.8,en-US;q=0.7,en;q=0.6";
request.Headers["Cache-Control"] = "max-age=0";
request.Headers["Upgrade-Insecure-Requests"] = "1";
如果需要,这里是完整的代码:
if option == '1':
with open("songs.csv") as f:
reader = csv.reader(f)
for row in reader:
output = (row[0], row[1], row[2]) #Only outputs 1 song ?
print (output)
预先感谢您:)
答案 0 :(得分:1)
列出歌曲的代码部分对我有用。
if option == '1':
with open("songs.csv") as f:
reader = csv.reader(f)
for row in reader:
output = (row[0], row[1], row[2]) #Only outputs 1 song ?
print (output)
但是,您在循环时编写的内容,例如
outputtxt_check = False
while outputtxt_check == False:
outputtxt = input(
"Would you like to output this list to a text file? Enter 1 for yes or 2 for no: ")
在同一for循环中发生。这就是为什么它只打印一行。您正在问用户问题,因为for循环尚未完成所有歌曲的打印。尝试将while循环放在for循环的外部/之后。