Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111152

Re: Appending an asterisk to the end of each line

From Joel Goldstick <joel.goldstick@gmail.com>
Newsgroups comp.lang.python
Subject Re: Appending an asterisk to the end of each line
Date 2016-07-05 19:15 -0400
Message-ID <mailman.114.1467760532.2295.python-list@python.org> (permalink)
References <acbonb5kk4g5vr68rlpipmrehekitpfb4b@4ax.com> <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> <CAPM-O+w8jm4jjZA1OrOvDDf7WD71PXeQRnmkfEcgz6i-A9ur=g@mail.gmail.com>

Show all headers | View raw


On Tue, Jul 5, 2016 at 7:03 PM, MRAB <python@mrabarnett.plus.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 18:05 -0400
  Re: Appending an asterisk to the end of each line Joel Goldstick <joel.goldstick@gmail.com> - 2016-07-05 18:27 -0400
    Re: Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 18:29 -0400
      Re: Appending an asterisk to the end of each line Joel Goldstick <joel.goldstick@gmail.com> - 2016-07-05 18:40 -0400
        Re: Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 19:04 -0400
          Re: Appending an asterisk to the end of each line Chris Angelico <rosuav@gmail.com> - 2016-07-06 09:38 +1000
            Re: Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 19:49 -0400
  Re: Appending an asterisk to the end of each line MRAB <python@mrabarnett.plus.com> - 2016-07-06 00:03 +0100
    Re: Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 19:15 -0400
  Re: Appending an asterisk to the end of each line Joel Goldstick <joel.goldstick@gmail.com> - 2016-07-05 19:15 -0400
    Re: Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 19:29 -0400
      Re: Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 19:45 -0400
        Re: Appending an asterisk to the end of each line MRAB <python@mrabarnett.plus.com> - 2016-07-06 01:05 +0100
          Re: Appending an asterisk to the end of each line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-07-05 20:05 -0400
            Re: Appending an asterisk to the end of each line MRAB <python@mrabarnett.plus.com> - 2016-07-06 03:15 +0100
            Re: Appending an asterisk to the end of each line Steven D'Aprano <steve@pearwood.info> - 2016-07-06 12:35 +1000
  Re: Appending an asterisk to the end of each line Larry Hudson <orgnut@yahoo.com> - 2016-07-05 21:37 -0700
    Re: Appending an asterisk to the end of each line cs@zip.com.au - 2016-07-06 15:35 +1000

csiph-web