Python Forum
trouble reading string/module from excel as a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trouble reading string/module from excel as a list
#1
I'm trying to read from a cell in a csv file as a list, but I'm running into a problem.

import csv
from google.cloud import bigquery


with open('documents\list.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        csv_row=(row['Schema'])

csv_read=csv_row.split('\n')


text = [bigquery.SchemaField("Id","STRING", mode="NULLABLE")]

print(csv_read)
print(text)

 
when I print both these statements, I'm getting two different results, even though the string in text and inside the CSV are exactly the same.

csv_read prints out
Output:
['bigquery.SchemaField("Id","STRING", mode="NULLABLE")']
where text prints out
Output:
[SchemaField('Id', 'STRING', 'NULLABLE', None, None, (), None)]
I'm assuming the issue is that csv_read is reading as a complete string and not taking bigquery.schemafield as a module/class

how do I get the CSV to print out like text?
Larz60+ write Oct-03-2023, 10:45 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Modified for you this time. Please use BBCode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Excel File with a list of values huzzug 4 1,262 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Trouble with threading and reading variable from a different script Lembas 14 3,071 Apr-26-2023, 11:21 PM
Last Post: Lembas
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,114 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,588 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Excel file reading problem max70990 1 901 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  reading a table which is of type string saisankalpj 2 964 Dec-03-2022, 11:19 AM
Last Post: saisankalpj
  list from excel devilonline 4 1,380 Jun-22-2022, 11:00 PM
Last Post: devilonline
  Reading list items without brackets and quotes jesse68 6 4,652 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Reading Excel file and use a wildcard in file name and sheet name randolphoralph 6 7,142 Jan-13-2022, 10:20 PM
Last Post: randolphoralph
  Compare two Excel sheets with Python and list diffenrences dmkfon 1 14,664 Oct-09-2021, 03:30 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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