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


Groups > comp.lang.python > #107373 > unrolled thread

Python path and append

Started bySeymore4Head <Seymore4Head@Hotmail.invalid>
First post2016-04-19 18:29 -0400
Last post2016-04-26 10:25 +1000
Articles 7 on this page of 27 — 15 participants

Back to article view | Back to comp.lang.python


Contents

  Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-19 18:29 -0400
    Re: Python path and append Chris Angelico <rosuav@gmail.com> - 2016-04-20 08:38 +1000
    Re: Python path and append Matthew Barnett <mrabarnett@mrabarnett.plus.com> - 2016-04-20 00:36 +0100
    Re: Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-25 14:10 -0400
      Re: Python path and append Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-25 18:24 +0000
        Re: Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-25 15:00 -0400
          RE: Python path and append Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-25 19:08 +0000
            Re: Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-25 16:15 -0400
              Re: Python path and append Random832 <random832@fastmail.com> - 2016-04-25 16:28 -0400
              Re: Python path and append Peter Otten <__peter__@web.de> - 2016-04-25 23:38 +0200
              Re: Python path and append Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-25 19:57 -0400
          Re: Python path and append Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-25 19:31 +0000
          Re: Python path and append MRAB <python@mrabarnett.plus.com> - 2016-04-25 20:44 +0100
            Re: Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-25 16:43 -0400
          Re: Python path and append Steven D'Aprano <steve@pearwood.info> - 2016-04-26 11:51 +1000
            Re: Python path and append Dan Sommers <dan@tombstonezero.net> - 2016-04-26 01:59 +0000
            Re: Python path and append Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-04-26 18:23 +1200
            Re: Python path and append boB Stepp <robertvstepp@gmail.com> - 2016-04-29 15:26 -0500
              Re: Python path and append Steven D'Aprano <steve@pearwood.info> - 2016-04-30 11:44 +1000
      Re: Python path and append John Gordon <gordon@panix.com> - 2016-04-25 21:26 +0000
        Re: Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-25 18:04 -0400
          Re: Python path and append Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-25 20:03 -0400
          Re: Python path and append Steven D'Aprano <steve@pearwood.info> - 2016-04-26 11:53 +1000
            Re: Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-26 22:56 -0400
              Re: Python path and append Chris Angelico <rosuav@gmail.com> - 2016-04-27 13:06 +1000
              Re: Python path and append Stephen Hansen <me+python@ixokai.io> - 2016-04-27 17:24 -0700
        Re: Python path and append Chris Angelico <rosuav@gmail.com> - 2016-04-26 10:25 +1000

Page 2 of 2 — ← Prev page 1 [2]


#107632

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2016-04-25 18:04 -0400
Message-ID<pq4thb907ep4mknnali2rhqgao32jdsn5o@4ax.com>
In reply to#107630
On Mon, 25 Apr 2016 21:26:34 +0000 (UTC), John Gordon
<gordon@panix.com> wrote:

>In <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Seymore4Head <Seymore4Head@Hotmail.invalid> writes:
>
>> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head
>> <Seymore4Head@Hotmail.invalid> 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.
>
>It's much easier to create a new file and then rename it afterwards,
>instead of rewriting the original file.
>
>    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')

That is 100% spoon fed code and that is what I wanted.
Thanks

I learned enough python to complete an online course from Dr Chuck but
I don't write enough code to remember how except for a simple task
that is usually simpler to do manually than to remember how to code.

http://www.dr-chuck.com/


Thanks to everyone else too.

BTW I was trying to use a line like yours that used an output file
that didn't exist and was getting an error.  I assume that import os
fixes that.

[toc] | [prev] | [next] | [standalone]


#107634

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2016-04-25 20:03 -0400
Message-ID<mailman.96.1461629042.32212.python-list@python.org>
In reply to#107632
On Mon, 25 Apr 2016 18:04:00 -0400, Seymore4Head
<Seymore4Head@Hotmail.invalid> declaimed the following:

>I learned enough python to complete an online course from Dr Chuck but
>I don't write enough code to remember how except for a simple task
>that is usually simpler to do manually than to remember how to code.
>


	But this isn't a Python specific problem. This is simple language
independent algorithm. You'd have the same problem in C, BASIC, Pascal,
Ada, REXX, or assembler. (Well, maybe not on Xerox CP/V if using UPDATE
mode with a file organization of "KEYED" [aka ISAM] where the key is the
record number, as it could potentially put longer records somewhere else in
the data segments -- not sure as it has been over 25 years since my college
days)
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#107637

FromSteven D'Aprano <steve@pearwood.info>
Date2016-04-26 11:53 +1000
Message-ID<571eca35$0$1607$c3e8da3$5496439d@news.astraweb.com>
In reply to#107632
On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote:

> BTW I was trying to use a line like yours that used an output file
> that didn't exist and was getting an error.  I assume that import os
> fixes that.


Why would you assume that?


"Doctor, I have a problem with my arm, but I won't tell you what. I assume
that if I take cough drops that will fix it."



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#107700

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2016-04-26 22:56 -0400
Message-ID<pba0iblrf5v5kojjfbqsrpoobt50k2ggvq@4ax.com>
In reply to#107637
On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano
<steve@pearwood.info> wrote:

>On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote:
>
>> BTW I was trying to use a line like yours that used an output file
>> that didn't exist and was getting an error.  I assume that import os
>> fixes that.
>
>
>Why would you assume that?
>
>
>"Doctor, I have a problem with my arm, but I won't tell you what. I assume
>that if I take cough drops that will fix it."

OK.  Dumb question acknowledged.

I got an error when I tried to write to a non existent file.  I
"incorrectly" assumed wrong.  That is going to be a common theme.

[toc] | [prev] | [next] | [standalone]


#107702

FromChris Angelico <rosuav@gmail.com>
Date2016-04-27 13:06 +1000
Message-ID<mailman.137.1461726413.32212.python-list@python.org>
In reply to#107700
On Wed, Apr 27, 2016 at 12:56 PM, Seymore4Head
<Seymore4Head@hotmail.invalid> wrote:
> On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano
> <steve@pearwood.info> wrote:
>
>>On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote:
>>
>>> BTW I was trying to use a line like yours that used an output file
>>> that didn't exist and was getting an error.  I assume that import os
>>> fixes that.
>>
>>
>>Why would you assume that?
>>
>>
>>"Doctor, I have a problem with my arm, but I won't tell you what. I assume
>>that if I take cough drops that will fix it."
>
> OK.  Dumb question acknowledged.
>
> I got an error when I tried to write to a non existent file.  I
> "incorrectly" assumed wrong.  That is going to be a common theme.

If you can acknowledge that, I suggest adopting a stance that will
tend to avoid such assumptions in the future. The easiest way is to do
less of your own analysis and more copy/paste of exact error messages.
Don't say "getting an error" - quote the actual code and error. Don't
say "I assume that", ask the question ("Would importing the os module
fix that?"). We'll be able to help more easily with actual error text,
and you won't look dumb :)

ChrisA

[toc] | [prev] | [next] | [standalone]


#107735

FromStephen Hansen <me+python@ixokai.io>
Date2016-04-27 17:24 -0700
Message-ID<mailman.154.1461803078.32212.python-list@python.org>
In reply to#107700
On Tue, Apr 26, 2016, at 07:56 PM, Seymore4Head wrote:
> On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano
> <steve@pearwood.info> wrote:
> 
> >On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote:
> >
> >> BTW I was trying to use a line like yours that used an output file
> >> that didn't exist and was getting an error.  I assume that import os
> >> fixes that.
> >
> >
> >Why would you assume that?
> >
> >
> >"Doctor, I have a problem with my arm, but I won't tell you what. I assume
> >that if I take cough drops that will fix it."
> 
> OK.  Dumb question acknowledged.
> 
> I got an error when I tried to write to a non existent file.  I
> "incorrectly" assumed wrong.  That is going to be a common theme.

Oh, he wasn't saying it was a dumb question. He was complaining you said
you were "getting an error". That's not a dumb question, that's a
useless report of a problem. If you don't say what exactly the error is,
we can't help you.

If you want help, the two best things to do are:
  1) Show actual code. 
  2) Show actual, complete tracebacks. 

Having a nice description of what you expect to happen is often nice
too, especially if its doing something "wrong" and not giving an obvious
traceback. Seeing specifically what the wrong behavior is, and you
explaining why you think its wrong, can be invaluable. 

-- 
Stephen Hansen
  m e @ i x o k a i . i o

[toc] | [prev] | [next] | [standalone]


#107635

FromChris Angelico <rosuav@gmail.com>
Date2016-04-26 10:25 +1000
Message-ID<mailman.97.1461630354.32212.python-list@python.org>
In reply to#107630
On Tue, Apr 26, 2016 at 7:26 AM, John Gordon <gordon@panix.com> wrote:
> It's much easier to create a new file and then rename it afterwards,
> instead of rewriting the original file.

And more importantly, it's safer. If anything happens to your process
while it's doing its work, you'll have a junk file sitting around, but
you won't have lost everything. If you overwrite the existing file,
you (often) depend on completely writing out the content you have in
memory.

ChrisA

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web