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


Groups > comp.lang.python > #59179

Re: Creating a function for a directory

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'great.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; "'w')": 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'script,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'file,': 0.19; 'header:User-Agent:1': 0.23; 'error': 0.23; 'mon,': 0.24; 'skip:" 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'tried': 0.27; 'function': 0.29; "skip:' 10": 0.31; '(unless': 0.31; 'file': 0.32; 'but': 0.35; 'there': 0.35; 'skip:o 20': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'future': 0.60; 'manually': 0.60; 'skip:o 30': 0.61; 'course': 0.61; 'such': 0.63; 'more': 0.64; 'directory:': 0.84; 'prone': 0.91; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Creating a function for a directory
Date Tue, 12 Nov 2013 11:24:02 +0100
Organization None
References <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> <Y5ngu.43499$8G6.1991@fx22.am4>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084aa64.dip0.t-ipconnect.de
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2450.1384251822.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384251822 news.xs4all.nl 15991 [2001:888:2000:d::a6]:54710
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59179

Show key headers only | View raw


unknown wrote:

> 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
>> out_file.write(indata)
>> out_file.close()
>> in_file.close()
>> 
>> firstdev("test")
> 
> 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)?

Hmm, I don't see a suitable function in os -- but there is 

shutil.copy()

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