从CSV文件加载的列表中删除括号和单引号

时间:2020-01-15 09:01:03

标签: python python-3.x csv csvreader

我正在打开一个包含链接的.csv文件,我想导航到每个链接。但是,当我打印链接列表时,它周围有方括号和单引号。如何打印不带括号和单引号的链接?

import csv
import os

with open('links.csv', 'r') as f:
  reader = csv.reader(f)
  links = list(reader)

for i in links:
    print(i)

结果

['https://links.com/100GLC-PFAQ-6X9?idc=43']
['https://links.com/100GLC-PFAQ-9X12?idc=43']
['https://links.com/100LB-PFLIN-9X12?idc=43']
['https://links.com/14PT-PFUV-5.25X10.5?idc=43']
['https://links.com/14PT-PFUV-6X9?idc=43']
['https://links.com/14PT-PFUV-9X12?idc=43']

更新 我使用*解决了问题。下面是我的更新代码。

import csv
import os

with open('links.csv', 'r') as f:
  reader = csv.reader(f)
  links = list(reader)

for i in links:
    print(*i)

2 个答案:

答案 0 :(得分:0)

您可以下一步:

import csv
import os

links = []

with open('links.csv', 'r') as f:
  reader = csv.reader(f)
  links.extend(reader)

print(links) # show all links without for loop

答案 1 :(得分:0)

我使用*解决了问题。下面是我的更新代码。

import csv
import os

with open('links.csv', 'r') as f:
  reader = csv.reader(f)
  links = list(reader)

for i in links:
    print(*i)