简体   繁体   English

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

[英]Remove Brackets and Single quotes from list loaded from CSV file

I am opening a .csv file that contains links and I want to navigate to each one.我正在打开一个包含链接的 .csv 文件,我想导航到每个链接。 But when i print the list of links, it has brackets and single quotes around them.但是当我打印链接列表时,它周围有括号和单引号。 How do I print the links without the brackets and single quotes?如何打印没有括号和单引号的链接?

import csv
import os

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

for i in links:
    print(i)

Results结果

['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']

UPDATE I solved the issue using the *.更新我使用 * 解决了这个问题。 Below is my updated code.下面是我更新的代码。

import csv
import os

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

for i in links:
    print(*i)

You could do next:你可以做下一步:

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

I solved the issue using the *.我使用 * 解决了这个问题。 Below is my updated code.下面是我更新的代码。

import csv
import os

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

for i in links:
    print(*i)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM