Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: Appending an asterisk to the end of each line Date: Wed, 6 Jul 2016 00:03:29 +0100 Lines: 28 Message-ID: References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de KH+zTsIW7EmWNamKyophPQuBlcxE8R6GD/agOm1a7dQA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'rename': 0.07; "'w')": 0.09; 'exception,': 0.09; 'exist.': 0.09; "'r')": 0.16; 'empty.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'renames': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; 'creates': 0.18; 'posted': 0.21; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; "skip:' 10": 0.28; 'subject:end': 0.29; 'raise': 0.29; 'run': 0.33; 'file': 0.34; 'text': 0.35; 'but': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'several': 0.38; 'skip:o 20': 0.38; 'subject:the': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; "you'll": 0.61; 'ago.': 0.61; 'reuse': 0.66; 'seymore4head': 0.84; 'subject:Appending': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.2 cv=J7fo10vS c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=IkcTkHD0fZMA:10 a=V72XSmP8dmDrRH7EPKEA:9 X-AUTH: mrabarnett@:2500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 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: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:111148 On 2016-07-05 23:05, Seymore4Head wrote: > import os > > f_in = open('win.txt', 'r') > f_out = open('win_new.txt', 'w') > > for line in f_in.read().splitlines(): > f_out.write(line + " *\n") > > f_in.close() > f_out.close() > > os.rename('win.txt', 'win_old.txt') > os.rename('win_new.txt', 'win.txt') > > > I just tried to reuse this program that was posted several months ago. > I am using a text flie that is about 200 lines long and have named it > win.txt. The file it creates when I run the program is win_new.txt > but it's empty. > Although it creates a file called "win_new.txt", it then renames it to "win.txt", so "win_new.txt" shouldn't exist. Of course, if there's already a file called "win_old.txt", then the first rename will raise an exception, and you'll have "win_new.txt" and the original "win.txt".