Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'great.': 0.07; 'file)': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tismer': 0.09; 'python': 0.11; 'def': 0.12; "'w')": 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'script,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'programming': 0.22; 'header:User-Agent:1': 0.23; 'second': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; "skip:' 10": 0.31; 'file': 0.32; 'but': 0.35; 'christian': 0.38; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:o 30': 0.61; 'world.': 0.61; 'such': 0.63; 'directory:': 0.84; 'received:as9105.com': 0.84; 'received:dsl.as9105.com': 0.84; 'received:dynamic.dsl.as9105.com': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Creating a function for a directory Date: Mon, 11 Nov 2013 22:45:24 +0000 References: <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 80-44-199-176.dynamic.dsl.as9105.com User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 In-Reply-To: <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384209937 news.xs4all.nl 15994 [2001:888:2000:d::a6]:57415 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59111 On 11/11/2013 22:26, 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 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") > -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence