Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Joaquin Alzola Newsgroups: comp.lang.python Subject: RE: Python path and append Date: Mon, 25 Apr 2016 19:08:56 +0000 Lines: 63 Message-ID: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de UHaC4Ee5lVmwyDkr9DlaxAl3QNT1p8bp7ci4m17Tyd1g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*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; 'entirely.': 0.16; 'iterating': 0.16; 'privilege.': 0.16; 'received:io': 0.16; 'received:psf.io': 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; 'to:name:python- list@python.org': 0.20; 'fix': 0.21; 'to:2**1': 0.21; 'please?': 0.22; 'trying': 0.22; 'leave': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "doesn't": 0.26; 'long.': 0.29; 'whitespace': 0.29; 'that.': 0.30; 'url:mailman': 0.30; 'work.': 0.30; 'task': 0.30; '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; 'path': 0.35; 'skip:> 10': 0.35; 'something': 0.35; 'subject:': 0.35; 'but': 0.36; 'url:org': 0.36; 'lines': 0.36; 'email addr:python.org': 0.36; 'beginning': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'method': 0.37; 'charset:us-ascii': 0.37; 'wrong': 0.38; 'someone': 0.38; 'end': 0.39; 'means': 0.39; 'enough': 0.39; 'from:': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'space': 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; 'url:tutorial': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lebara.onmicrosoft.com; s=selector1-lebara-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CjZS06WqqnqLiOFCqruGHIjlYDeDvH0zVtb79BFbFSo=; b=GY2XqYokazFFWoWAxn37mTIUM92mWweIdueg/J65kFqipTBSRZWL1QQq3014XgpWq63lX6odWbplUVAESYpn/bx4TdK9FxPRhHvCN2ZkAdfvqL8aWOyN9LlSeTaYvfNmac3XlnRo54ePtMl8Ldgh27/8oIifSl57b3S4CVTI5mA= Thread-Topic: Python path and append Thread-Index: AQHRnx5siZI8LDMh+UWjCvuErIEqbJ+bAsyWgAAJyE2AAACdQA== In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: Hotmail.invalid; dkim=none (message not signed) header.d=none; Hotmail.invalid; dmarc=none action=none header.from=lebara.com; x-originating-ip: [165.225.80.110] x-ms-office365-filtering-correlation-id: 6edcf248-7cd7-4c77-2be7-08d36d3d0ca4 x-microsoft-exchange-diagnostics: 1; HE1PR07MB1356; 5:xrwwk9yfSOLhBfX9fkqKiIA1B8nIZauaAY9kNlteoKuq7RCk4OGGXSg4AnCwBs2byhiOVigBHuP0HVzMbH0sNic73nbGlVZT6zS/E4w+uZB/fO1djnW4nu4ckIqtPtOGPrdBSugLR9QSe1fxe4U4ug==; 24:yK9mKrUWBmP4qNcPTWQzXAeJbHViBwRHZqNYv7klxutAUZW3HMXqy1OAbPXctKOza8Tz77AmFQvDQTP/yQxcQDBRwPG1G5t/c26uFl68Oks=; 7:vmKjbO/TGviPFHEGw6VgyAJr8x3BDRdsusF+8i7dycSjPM4hCdAvXLT1vFH9sRa8osV+aqT9gr/IvOJbdY6I/Mgm0rbnFC0ky2IEc+qEz+xZTw/dq0xztABwfDpAsriAm9UGArGh/h25JDvd8NzYl9Gz+BODw1k2B0RycDK5QbjUlipR+qqmXrskDy2gW6oI x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR07MB1356; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(9101521072)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:HE1PR07MB1356; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB1356; x-forefront-prvs: 0923977CCA x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(13464003)(24454002)(92566002)(3480700003)(3660700001)(106116001)(5002640100001)(5008740100001)(10400500002)(86362001)(76176999)(50986999)(66066001)(93886004)(15975445007)(77096005)(33656002)(2501003)(2950100001)(2900100001)(2906002)(74316001)(110136002)(107886002)(189998001)(3280700002)(87936001)(76576001)(54356999)(5004730100002)(11100500001)(6116002)(102836003)(3846002)(81166005)(586003)(5003600100002)(1220700001)(1096002)(9686002)(19580405001)(122556002)(19580395003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB1356; H:HE1PR07MB1356.eurprd07.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM X-OriginatorOrg: lebara.com X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Apr 2016 19:08:56.0640 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d7093539-83cd-4991-b1b3-aacef74cf097 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR07MB1356 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:107623 Strip() =3D white spaces. Description The method strip() returns a copy of the string in which all chars have bee= n stripped from the beginning and the end of the string (default whitespace= characters). Use to remove return carriage--> line[:-1] -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=3Dlebara.com@p= ython.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 =3D 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 e= ven remember the simple stuff. Then when I try to use if for something sim= ple I forget how. f =3D open('wout.txt', 'r+') for line in f: line=3Dline.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 cont= act the sender immediately upon receipt.