Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Joel Goldstick Newsgroups: comp.lang.python Subject: Re: Appending an asterisk to the end of each line Date: Tue, 5 Jul 2016 19:15:23 -0400 Lines: 40 Message-ID: References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de jtUpLBf8s5uD3C1qC4cmVQqI3LlDBxHRWpPVQxyFkUIA== 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; 'mrab': 0.05; 'rename': 0.07; 'cc:addr:python-list': 0.09; "'w')": 0.09; 'exception,': 0.09; 'exist.': 0.09; 'url:blog': 0.10; "'r')": 0.16; '2016': 0.16; 'empty.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'renames': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; 'creates': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'posted': 0.21; 'tried': 0.24; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; "skip:' 10": 0.28; 'subject:end': 0.29; 'raise': 0.29; 'url:mailman': 0.30; 'run': 0.33; 'url:python': 0.33; 'url:listinfo': 0.34; 'tue,': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'comment': 0.35; 'but': 0.36; 'url:org': 0.36; 'lines': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'several': 0.38; 'skip:o 20': 0.38; 'why': 0.39; 'subject:the': 0.39; 'url:mail': 0.40; 'called': 0.40; "you'll": 0.61; 'ago.': 0.61; 'reuse': 0.66; 'url:info': 0.71; 'jul': 0.72; 'seymore4head': 0.84; 'subject:Appending': 0.84; 'to:none': 0.91; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=I36RLrC3wmNwO6QpFQhHeu1y6l4C6z2lctvp0iWJUcI=; b=g6RhEsio67nut4WtW5kxe1XXXTjf4blFjFucdhFAZXpRjN5qiS0ok5ePU5rd5sYooD zGssZjpxTknxyvHozkopsdL1lIIolSOKRyz80HXupR/q605F8ByWOvP8aMwrLU/EhuA/ w9ffH8B5zVd2u7Z4KT58kDAP1ARySK3oHgXo4Tcnzesu5N2GCu/kQfQvqPkfs0ZS+oEI b8CHqsUqHMwFPlwtv7v41lbKenh++YNeVpEE7O+TE6pFTrAvvbdgnghY03lQbTIhdw+f 5wRbJlolRgkBHlt5ACvi6dseAU3s2ie0UJxw9DvOhP7kdJZ9tzrOyOWtVWBsXRMrg5gC hbtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=I36RLrC3wmNwO6QpFQhHeu1y6l4C6z2lctvp0iWJUcI=; b=EN6Rw14erBHc6g2LYQioYkX6KQnJnu4VuURERoivpRRLJlIj8icKj7FIg4odHJt4Yn GFFgv9Kd4pwDOvDc8LnvI1h4TQQ4qwM1X8LO27dL3CPhUZ4APpm1pDme4T4/ECyFuZyz Y3mKlxQ+yVOlse+OK2LO1EQzUqnLLsHHXT60C2bSpZ9N6BykeeOL4MUhb9u6liRJyadP buAcwEQ2sihvoPvWIpJnWZd0VnkHQpHb55JWYlWoJ/6h05eqQZviLSZ6lZ1a6gcQJrer tGmB4vsztjI/2XaBpGTnUL8BqzxBGAdG7nSFQn0wx299nE2FQO06vtHqtczxciQmOkcL thfg== X-Gm-Message-State: ALyK8tJsWyYBXl9pDF/6P1/s7uGSzjHYXs9u1QmKv8OzQ0Y7ITFRT6sOdYnrO12tiDz1NsadVf229KpLELdXNA== X-Received: by 10.202.241.68 with SMTP id p65mr11749797oih.187.1467760523786; Tue, 05 Jul 2016 16:15:23 -0700 (PDT) In-Reply-To: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> 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: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> Xref: csiph.com comp.lang.python:111152 On Tue, Jul 5, 2016 at 7:03 PM, MRAB wrote: > 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". > > -- > https://mail.python.org/mailman/listinfo/python-list Why don't you comment out the renames, and see what happens? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays