简体   繁体   中英

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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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