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.049 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'great.': 0.07; 'file)': 0.09; 'rewrite': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; "'w')": 0.16; 'chapel': 0.16; 'script,': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'guys': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; "skip:' 10": 0.31; 'file': 0.32; 'url:python': 0.33; 'skip:& 30': 0.33; 'problem': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'nov': 0.38; 'pm,': 0.38; 'skip:& 20': 0.39; 'url:mail': 0.40; 'skip:o 30': 0.61; 'here:': 0.62; 'such': 0.63; 'to:addr:gmail.com': 0.65; 'answer.': 0.68; 'directory:': 0.84; 'habit': 0.91; 'hill': 0.95; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=pqnvWmqKDR4h4w0dH2Pa4BxvYd8z7M0He5+2stUdFIY=; b=BaNSSiaOBlubRWPc/bq8gtZlwttm6qjecd1UhbiCw4QX7uffcpdArPOwTwKBnZmjFc BeuVroDbF4cAK2e7MluIjNwTSu9lPgXn4alHc9lCfyjN1WS4wbbaVKSmD+1OG4IAYn5o SH9oLtLYN7B9stZNcfRHaFB2/vmq6phNQlkBJ+OYoEw42Br2WmD2JCxir8Q/37SQwasg J5yyOGhl/F4cPISJP6sR6Z0+Tz7ndrjZAiPVNwGW0YztBeR+RmPJ9GLAnXx4WrEzJYey QU+CSSW92X5x03rLq6piqzWVaW6JmnDY0oKDaQinwWIR4mymxgPnnN5LMUXFAp7Lyvbs IC6g== MIME-Version: 1.0 X-Received: by 10.220.196.66 with SMTP id ef2mr26479790vcb.7.1384209896997; Mon, 11 Nov 2013 14:44:56 -0800 (PST) In-Reply-To: <52815D52.3030404@gmail.com> References: <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> <52815D52.3030404@gmail.com> Date: Mon, 11 Nov 2013 17:44:56 -0500 Subject: Re: Creating a function for a directory From: Joel Goldstick To: bob gailer Content-Type: multipart/alternative; boundary=001a1132e6e234b46204eaee7b7e Cc: python-list@python.org 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: 119 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384209906 news.xs4all.nl 15886 [2001:888:2000:d::a6]:56592 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59110 --001a1132e6e234b46204eaee7b7e Content-Type: text/plain; charset=UTF-8 Sorry for incorect answer. Those guys nailed it On Nov 11, 2013 5:43 PM, "bob gailer" 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 > --001a1132e6e234b46204eaee7b7e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

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 &q= uot;desktop/newfolder/test.txt". I tried the below script, and it gave= me: "IOError: [Errno 2] No such file or directory: 'desktop/%s.tx= t'". Any suggestions would be great.



def firstdev(file):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 in_file =3D open("desktop/%s.txt") % = file
The problem is the above line. Rewrite is thus:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 in_file =3D open("desktop/%s.txt" % f= ile)


=C2=A0 =C2=A0 =C2=A0 =C2=A0 indata =3D in_file.read()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 out_file =3D open("desktop/newfolder/%s.txt", 'w') % file
Same here:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0out_file =3D open("desktop/newfolder= /%s.txt"% file, 'w')


=C2=A0 =C2=A0 =C2=A0 =C2=A0 out_file.write(indata)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 out_file.close()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 in_file.close()
Also don't get in the habit of reassigning built-in functions e;g; file= .
=C2=A0 =C2=A0 =C2=A0 =C2=A0
firstdev("test")


--
Bob Gailer
919-6= 36-4239
Chapel Hill NC

--
https://mail.python.org/mailman/listinfo/python-list
--001a1132e6e234b46204eaee7b7e--