Creating a function for a directory
unknown at unknown.com
Tue Nov 12 11:07:52 CET 2013
On Mon, 11 Nov 2013 14:26:46 -0800, Matt wrote:
> So I want to take the file, "desktop/test.txt" and write it to
> "desktop/newfolder/test.txt". I tried the below script, and it gave me:
> "IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'". Any
> suggestions would be great.
> def firstdev(file):
> in_file = open("desktop/%s.txt") % file indata = in_file.read()
> out_file = open("desktop/newfolder/%s.txt", 'w') % file
would it not be more efficient and less error prone to use the os module
to copy the file rather than manually reading & re-writing it (unless of-
course you intend to expand this in future to process the data first)?
More information about the Python-list