Creating a function for a directory

Joel Goldstick joel.goldstick at gmail.com
Mon Nov 11 17:44:56 EST 2013


Sorry for incorect answer. Those guys nailed it
On Nov 11, 2013 5:43 PM, "bob gailer" <bgailer at gmail.com> wrote:

> On 11/11/2013 5:26 PM, 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
>>
> The problem is the above line. Rewrite is thus:
>
>         in_file = open("desktop/%s.txt" % file)
>
>
>          indata = in_file.read()
>>         out_file = open("desktop/newfolder/%s.txt", 'w') % file
>>
> Same here:
>
>>          out_file = open("desktop/newfolder/%s.txt"% file, 'w')
>>
>>
>>         out_file.write(indata)
>>         out_file.close()
>>         in_file.close()
>>
> Also don't get in the habit of reassigning built-in functions e;g; file.
>
>>
>> firstdev("test")
>>
>
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131111/27d71784/attachment.html>


More information about the Python-list mailing list