Python Forum
Write Variable String To CSV Cell
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write Variable String To CSV Cell
#1
Hey guys,

How would I go about writing data into a specific CSV cell?

example

x = "true"

list(csv.reader(open('test.csv', 'w')))
list.write(x)to([5][1]) #cell location row 5, column 1
Reply
#2
hi,

this is the least best method i found for you:

import csv

f = open("mycsv.csv", "r")
reader = csv.reader(f)
mylist = list(reader)
f.close()
print(mylist)

mylist[2][0] = "x"#here 2 is third row starting from 0 and [0] is the cell postion
my_new_list = open('mylist.csv', 'w', newline = '')
csv_writer = csv.writer(my_new_list)
csv_writer.writerows(mylist)# you can use writerow also to get the data into 1 single column
my_new_list.close()
make three rows with number 1,2,3
4,5,6
7,8,9
and then use this code
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing String Variable with a new String Name kevv11 2 773 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Need help on how to include single quotes on data of variable string hani_hms 5 2,012 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Problem with print variable in print.cell (fpdf) muconi 0 655 Dec-25-2022, 02:24 PM
Last Post: muconi
  python r string for variable mg24 3 2,792 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 958 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 6,277 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 1,777 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  How to write a part of powershell command as a variable? ilknurg 2 1,118 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  Split string using variable found in a list japo85 2 1,295 Jul-11-2022, 08:52 AM
Last Post: japo85
  Can you print a string variable to printer hammer 2 1,937 Apr-30-2022, 11:48 PM
Last Post: hammer

Forum Jump:

User Panel Messages

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