Advertisement

05.13.2005 at 07:55AM PDT, ID: 21423386
[x]
Attachment Details

Python File Reading and Writing

Asked by ashok3sep in Python Scripting Language

Tags: python, file, read

This is a small program i have written to read a contents from a INPUT FILE containing (+1000 Lines ) and writing simultaneously to another file. ( it works fine )


1.---- QUESTION:-
--------------------
I need to have the same fomat for the written file as of the Reading file ( But the FORMAT is LOST ------ I Dont Know why ?????
2.--------QUESTION:-
---------------------------
if want to make a stop at the middle of the file and insert some data to the file and then again  perfrom the read  and the write operation( HOW CAN I DO THAT)........


import sys
import os
import stat

def ReadFile():
      try:
            input = open('c:\Abafiles\Job-1.inp','r')
            out = open("exampleWrite.inp", "w")
            s = input.readlines()
            InputTuple = []
            for line in s:
                  singleLine = line.rstrip()
                  InputTuple.append(singleLine)
                  out.write(singleLine)
            print len(InputTuple)
            
      except IOError, (errno, strerror):
            print "I/O error(%s): %s" % (errno, strerror)
      except ValueError:
            print "Could not convert data to an integer."
      except:
            print "Unexpected error:", sys.exc_info()[0]
            raise
      input.close()
      out.close()
ReadFile()
Start Free Trial
[+][-]05.14.2005 at 12:50AM PDT, ID: 14001536

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Python Scripting Language
Tags: python, file, read
Sign Up Now!
Solution Provided By: efn
Participating Experts: 3
Solution Grade: A
 
 
[+][-]05.18.2005 at 01:51AM PDT, ID: 14025336

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.18.2005 at 06:51AM PDT, ID: 14027051

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2005 at 03:39PM PDT, ID: 14146986

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32