On Tue, Nov 12, 2013 at 9:26 AM, Matt <mattgrav...@gmail.com> 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

You're using the % operator, which does your interpolations, at the
wrong point. You want to be adjusting the file name, not adjusting the
opened file:

        in_file = open("desktop/%s.txt" % file)
        out_file = open("desktop/newfolder/%s.txt" % file, 'w')

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to