Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing to a text file?
#5
It should be something like this (untested):
import csv
  
with open('animals3.csv') as csvfile, open('myfilename.txt, 'w') as fp:
    readCSV = csv.reader(csvfile, delimiter=',')
    for row in readCSV:
         fp.write(row)
Again this is rather pointless as a csv file is a text file!
you can read as:
with open('animals3.csv') as fp:
    for line in fp:
        print(line.strip()
Reply


Messages In This Thread
Writing to a text file? - by Bigjay45 - Oct-11-2018, 11:11 PM
RE: Writing to a text file? - by Larz60+ - Oct-12-2018, 12:58 AM
RE: Writing to a text file? - by Bigjay45 - Oct-12-2018, 01:25 AM
RE: Writing to a text file? - by pcsailor - Oct-12-2018, 06:10 AM
RE: Writing to a text file? - by Larz60+ - Oct-12-2018, 06:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,133 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,387 Sep-27-2022, 01:38 PM
Last Post: buran
  Writing into 2 text files from the same function paul18fr 4 1,689 Jul-28-2022, 04:34 AM
Last Post: ndc85430
  Writing to json file ebolisa 1 1,013 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,696 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Writing to External File DaveG 9 2,509 Mar-30-2022, 06:25 AM
Last Post: bowlofred
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,018 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Writing to file ends incorrectly project_science 4 2,704 Jan-06-2021, 06:39 PM
Last Post: bowlofred
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,376 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,422 Nov-16-2020, 07:56 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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