Python Forum
Reading list items without brackets and quotes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading list items without brackets and quotes
#1
These brackets and quotes always cause me grief.

If I create the list from reading a csv file then print the list, it prints with brackets.

import csv
with open ('csvtest2.csv','r') as csv_file:
    reader =csv.reader(csv_file)
    included_cols = [0]
    next(reader) # skip first row
    gateways  =[]
    for row in reader:
        content = list(row[i] for i in included_cols)
        gateways.append (content)

print(*gateways, sep = "\n")
OUTPUT:
['NODE001']
['NODE002']
['NODE003']
['NODE004']

This breaks my SSH API code which appears to be reading the item with the brackets and not the actual item. If I can get print to print correctly then my app should work. The problem appears to be how the list is written. This shouldn't be that hard. Help.. please?


If I create the list on the fly eg. list=["item1", "item2", "item3"] it prints only the items without bracket and quotes.

gateways = ["NODE001", "NODE002", "NODE003", "NODE004"]
print(*gateways, sep = "\n")
OUTPUT:
NODE001
NODE002
NODE003
NODE004

The SSH API works fine with above.

Thanks much!

Attached Files

.py   Pytest1.py (Size: 438 bytes / Downloads: 304)
.csv   csvtest2.csv (Size: 56 bytes / Downloads: 274)
Reply


Messages In This Thread
Reading list items without brackets and quotes - by jesse68 - Jan-14-2022, 06:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  trouble reading string/module from excel as a list popular_dog 0 928 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 2,885 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Finding combinations of list of items (30 or so) LynnS 1 1,515 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 2,711 Sep-03-2022, 11:21 PM
Last Post: Winfried
  For Word, Count in List (Counts.Items()) new_coder_231013 6 6,768 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get list of exactly 10 items? Mark17 1 3,668 May-26-2022, 01:37 PM
Last Post: Mark17
  how to assign items from a list to a dictionary CompleteNewb 3 2,678 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Data pulled from SQL comes in brackets nickzsche 3 4,257 Jan-04-2022, 03:39 PM
Last Post: ibreeden
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 3,757 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
Question How to gather specific second-level items from a list chatguy 2 2,302 Dec-17-2021, 05:05 PM
Last Post: chatguy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020