Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59110

Re: Creating a function for a directory

References <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> <52815D52.3030404@gmail.com>
Date 2013-11-11 17:44 -0500
Subject Re: Creating a function for a directory
From Joel Goldstick <joel.goldstick@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2406.1384209906.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Sorry for incorect answer. Those guys nailed it
On Nov 11, 2013 5:43 PM, "bob gailer" <bgailer@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
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Creating a function for a directory Matt <mattgraves7@gmail.com> - 2013-11-11 14:26 -0800
  Re: Creating a function for a directory Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-11 17:36 -0500
  Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 09:38 +1100
  Re: Creating a function for a directory bob gailer <bgailer@gmail.com> - 2013-11-11 17:42 -0500
  Re: Creating a function for a directory Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-11 17:44 -0500
  Re: Creating a function for a directory Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-11 22:45 +0000
  Re: Creating a function for a directory Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-11 14:51 -0800
    Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 10:11 +1100
      Re: Creating a function for a directory Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-11 21:42 -0800
        Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 17:02 +1100
    Re: Creating a function for a directory Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-12 00:33 +0000
      Re: Creating a function for a directory Neil Cerutti <neilc@norwich.edu> - 2013-11-12 13:42 +0000
  Re: Creating a function for a directory Matt <mattgraves7@gmail.com> - 2013-11-11 15:05 -0800
  Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 09:51 +1100
  Re: Creating a function for a directory unknown <unknown@unknown.com> - 2013-11-12 10:07 +0000
    Re: Creating a function for a directory Peter Otten <__peter__@web.de> - 2013-11-12 11:24 +0100
      Re: Creating a function for a directory unknown <unknown@unknown.com> - 2013-11-12 11:26 +0000

csiph-web