[Tutor] (no subject)

Christian Witts cwitts at compuscan.co.za
Tue Mar 27 11:20:44 CEST 2012


On 2012/03/27 03:08 AM, thao nguyen wrote:
>
> Dear Support Team,
>
> I have built a function (enclosed here) to merge many files (in this 
> example is 2 files: "a1.txt" and "a2.txt") lines by lines. The output 
> file is called "final_file". However, i could not have it run 
> successfully.
>
> Content of "a1.txt":
> 1
> 3
> 5
>
>
> Content of "a2.txt":
> 2
> 4
> 6
>
>
> Content of "final_file.txt" will be like:
> 1
> 2
> 3
> 4
> 5
> 6
>
>
> In Python, i called just written module:
>
> import argument
> reload(argument)
> argument.test(2,"C:/a1.txt","C:/a2.txt")
>
> and get the error as below:
>     "ValueError: I/O operation on closed file
>      File "c:\append.py", line 5, in <module>
>              argument.test(2,"C:/a1.txt","C:/a2.txt")
>      File "c:\argument.py", line 28, in test
>             for line_data in f:"
>
> Could you please advise the resolution for this?
>
>
> Thank you
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
Your Exception states what the problem is, which is operating on a 
closed file, and your traceback indicates it is when you're iterating 
over it.
As the error occurs in your argument.py file, you should post the 
relevant portions of that code too.

You could also do `cat file1 file2 filen > final_file` in a *nix prompt 
if that is your use-case.
-- 

Christian Witts
Python Developer
//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120327/37bb11cb/attachment-0001.html>


More information about the Tutor mailing list