Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: Python path and append Date: Mon, 25 Apr 2016 20:44:50 +0100 Lines: 67 Message-ID: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de aS+psvp4HW9204z4SMq8yw2fWO+SgcTbrUcyslXmjJOA== 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; 'subject:Python': 0.05; 'append': 0.07; 'f.close()': 0.07; 'newline': 0.07; '(default': 0.09; 'before.': 0.09; 'path.': 0.09; 'python': 0.10; 'message-----': 0.15; '2016': 0.16; 'carriage': 0.16; 'entirely.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'iterating': 0.16; 'linefeed': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'privilege.': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'return,': 0.16; 'skip:[ 60': 0.16; 'stripped': 0.16; 'stuff.': 0.16; 'superfluous': 0.16; 'task.': 0.16; 'wrote:': 0.16; 'string': 0.17; 'variable': 0.18; '>>>': 0.20; 'fix': 0.21; 'please?': 0.22; 'trying': 0.22; 'leave': 0.23; '(or': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'header :User-Agent:1': 0.26; "doesn't": 0.26; 'followed': 0.27; 'character.': 0.29; 'long.': 0.29; 'whitespace': 0.29; 'that.': 0.30; 'url:mailman': 0.30; 'work.': 0.30; 'task': 0.30; 'received:84': 0.32; 'problem': 0.33; 'url:python': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'equal': 0.34; 'tue,': 0.34; 'file': 0.34; 'sent:': 0.35; 'next': 0.35; 'could': 0.35; 'path': 0.35; 'skip:> 10': 0.35; 'something': 0.35; 'subject:': 0.35; 'but': 0.36; 'url:org': 0.36; 'lines': 0.36; 'possible': 0.36; 'email addr:python.org': 0.36; 'beginning': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'operating': 0.37; 'wrong': 0.38; 'someone': 0.38; 'end': 0.39; 'means': 0.39; 'enough': 0.39; 'system.': 0.39; 'from:': 0.39; 'received:192': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'space': 0.40; 'some': 0.40; 'forget': 0.60; 'url:3': 0.60; 'your': 0.60; "you'll": 0.61; 'telling': 0.61; 'contact': 0.66; 'python-list': 0.66; 'email name:python-list': 0.67; 'home': 0.67; 'subject': 0.70; 'disclose': 0.71; 'yourself': 0.73; '(utc),': 0.84; 'favor:': 0.84; 'seymore4head': 0.84; '-0000': 0.91; 'safer': 0.91; 'url:tutorial': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=bsGxfxui c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=8AHkEIZyAAAA:8 a=6vK2StEHApxqnbjjBssA:9 a=QEXdDO2ut3YA:10 a=j1U0AGED2WkA:10 X-AUTH: mrabarnett@:2500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Xref: csiph.com comp.lang.python:107625 On 2016-04-25 20:08, Joaquin Alzola wrote: > Strip() = white spaces. > Description > The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters). > > Use to remove return carriage--> line[:-1] > 1. In the file it might be a linefeed, or a carriage return, or a carriage return followed by a linefeed, depending on the operating system. Python translates it to a linefeed "\n" (or 'newline') on reading. 2. It's possible that the last line doesn't end have a line ending, so line[:-1] could be removing some other character. It's safer to use line.rstrip("\n"). > -----Original Message----- > From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com@python.org] On Behalf Of Seymore4Head > Sent: 25 April 2016 20:01 > To: python-list@python.org > Subject: Re: Python path and append > > On Mon, 25 Apr 2016 18:24:02 -0000 (UTC), Rob Gaddi wrote: > >>Seymore4Head wrote: >> >>> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >>> wrote: >>> >>> I am going to forget using a directory path. >>> I would like to take the file win.txt and append a space and the * >>> symbol. >>> >>> f = open('win.txt', 'r+') >>> for line in f: >>> f.read(line) >>> f.write(line+" *") >>> >>> This doesn't work. Would someone fix it please? It is for a task I >>> am trying to accomplish just for a home task. >> >>"for line in f:" already means "make the variable line equal to each >>line in f sequentially". f.read is both superfluous and also doesn't >>do that. Leave it out entirely. >> >>The next problem you'll have is that iterating over the lines of the >>file leaves the newline at the end of line, so your * will end up on >>the wrong line. >> >>Do yourself a favor: >>https://docs.python.org/3/tutorial/inputoutput.html >>isn't very long. > > I was reading that. I have read it before. I don't use python enough to even remember the simple stuff. Then when I try to use if for something simple I forget how. > > f = open('wout.txt', 'r+') > for line in f: > line=line.strip() > f.write(line+" *") > f.close() > > Still broke. How about just telling me where I missed? Please? > -- > https://mail.python.org/mailman/listinfo/python-list > This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. >