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
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 12 27,822 Feb-13-2025, 04:48 AM
Last Post: tomhansky
  How to write variable in a python file then import it in another python file? tatahuft 4 862 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 988 Dec-19-2024, 11:57 AM
Last Post: snippsat
  Write json data to csv Olive 6 1,289 Oct-22-2024, 06:59 AM
Last Post: Olive
  [SOLVED] [Linux] Write file and change owner? Winfried 6 1,479 Oct-17-2024, 01:15 AM
Last Post: Winfried
  python read PDF Statement and write it into excel mg24 1 934 Sep-22-2024, 11:42 AM
Last Post: Pedroski55
  Read TXT file in Pandas and save to Parquet zinho 2 1,200 Sep-15-2024, 06:14 PM
Last Post: zinho
  Pycharm can't read file Genericgamemaker 5 1,530 Jul-24-2024, 08:10 PM
Last Post: deanhystad
  Python is unable to read file Genericgamemaker 13 3,521 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Delete file with read-only permission, but write permission to parent folder cubei 6 25,242 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo

Forum Jump:

User Panel Messages

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