Python Forum
read select data from one file and write to another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read select data from one file and write to another
#1
Hey everyone, can anyone please share with me how i can read data from a file and write selective data from this file to another file? example : I have 10 files from a.txt, b.txt....j.txt and each file has 5 rows and 3 columns. I want to read the first 3 rows and the third column from each file and then save it as .xml file. Can anyone help me on how to achieve this?

I just started with opencv and python last week so please treat me as beginner. I am reading up on this in the meantime but any help would be appreciated. Also i would be grateful if some code and/or reference code can be provided to help me visualize.
Reply
#2
We don't tend to give code until you've given us an attempt first. You should look into the with operator for opening files (with open('file.txt') as data_file:). You will want a for loop to loop over the different input file names. If you are going to output xml, you will probably want a library to assist that, such as lxml or beautiful soup. Unless your xml is really simple, of course.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 318 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Last record in file doesn't write to newline gonksoup 3 364 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,785 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  write to csv file problem jacksfrustration 11 1,373 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,314 Nov-09-2023, 10:56 AM
Last Post: mg24
Question Special Characters read-write Prisonfeed 1 582 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  read file txt on my pc to telegram bot api Tupa 0 1,052 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,043 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,161 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,016 Jun-06-2023, 06:37 PM
Last Post: rajeshgk

Forum Jump:

User Panel Messages

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