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: 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> 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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()