Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.033 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'great.': 0.07; 'file)': 0.09; 'received:192.168.1.101': 0.09; 'rewrite': 0.09; 'def': 0.12; "'w')": 0.16; 'chapel': 0.16; 'script,': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; "skip:' 10": 0.31; 'file': 0.32; 'problem': 0.35; 'received:google.com': 0.35; 'skip:o 20': 0.38; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:o 30': 0.61; 'here:': 0.62; 'such': 0.63; 'directory:': 0.84; 'habit': 0.91; 'hill': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=xrzX8W5c/GVqSDwX9sQDMGPV1o3INsIwjili3MEMtBs=; b=wIVgXGlBPwvjqLaGGwgMUgx2zP8apP8ox55WsBvjBB1HwAyzQ4r0WuOiin81swt3iw r3wNwzVI9BigPVvzxOTcclLoz14c2xJ5VRsapAeUHtnPLMvORVkdbSVhq+5QNsoKiSSs mfPjThK5hKOx9fdR/dNkr88b6FxhAW1fQl1VKhLoX451lKsD66wiW1Mfu5JyFLGv+rBK OHx+J1Wl75en8dCGtPj3J1SUAQHcgEUuDWr+lLsnGEM9Wluq09bMVV0lCZjM3Lscf6SI Ak0IPIqXeyYJgTWR9TSI4TqHojmekCJLbwKdQjjOWHKM0ztTkVm/ITjirat2p9KKLJf4 0nJw== X-Received: by 10.224.120.6 with SMTP id b6mr53950238qar.11.1384209745779; Mon, 11 Nov 2013 14:42:25 -0800 (PST) Date: Mon, 11 Nov 2013 17:42:26 -0500 From: bob gailer User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Creating a function for a directory References: <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> In-Reply-To: <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384209754 news.xs4all.nl 15953 [2001:888:2000:d::a6]:53476 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59109 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