Re: Insert character at a fixed position of lines

2008-07-30 Thread alex23
On Jul 30, 10:43 pm, Lie <[EMAIL PROTECTED]> wrote: > Lessons learned, should test codes even if you thought it seemed > trivial. And I learned I should always make sure to cut&paste the right example :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Insert character at a fixed position of lines

2008-07-30 Thread Lie
On Jul 27, 10:02 am, alex23 <[EMAIL PROTECTED]> wrote: > Ugh, and in pointing our your inaccurate code I posted my own: > > > >>> f = open('dummy.txt','w') > > >>> f.write(line = 'this doesn't work') > > >   File "", line 1 > >     f.write(line = 'this doesn't work') > >                            

Re: Insert character at a fixed position of lines

2008-07-26 Thread castironpi
On Jul 26, 10:02 pm, alex23 <[EMAIL PROTECTED]> wrote: > Ugh, and in pointing our your inaccurate code I posted my own: > > > >>> f = open('dummy.txt','w') > > >>> f.write(line = 'this doesn't work') > > >   File "", line 1 > >     f.write(line = 'this doesn't work') > >                            

Re: Insert character at a fixed position of lines

2008-07-26 Thread alex23
Ugh, and in pointing our your inaccurate code I posted my own: > >>> f = open('dummy.txt','w') > >>> f.write(line = 'this doesn't work') > > File "", line 1 > f.write(line = 'this doesn't work') >^ > SyntaxError: invalid syntax That should be: >>> f.write(li

Re: Insert character at a fixed position of lines

2008-07-26 Thread alex23
On Jul 27, 9:26 am, Lie Ryan <[EMAIL PROTECTED]> wrote: > Btw, if you do f.write('line = line[:22] + "A" + line[23:]'), you'd > output exactly that, and not inserting the 23rd character, you'd want to > do this instead: f.write(line = line[:22] + "A" + line[23:]) Please check your examples before

Re: Insert character at a fixed position of lines

2008-07-26 Thread Lie Ryan
On Sat, 2008-07-26 at 17:47 +0200, Francesco Pietra wrote: > Sorry to come again for the same problem. On commanding: > > $ python script.py 2>&1 | tee fileout.pdb > > nothing occurred (fileout.pdb was zero byte). The script reads: > > f = open("xxx.pdb", "w") > f.write('line = line[:22] + "A" +

Re: Insert character at a fixed position of lines

2008-07-26 Thread Francesco Pietra
Sorry to come again for the same problem. On commanding: $ python script.py 2>&1 | tee fileout.pdb nothing occurred (fileout.pdb was zero byte). The script reads: f = open("xxx.pdb", "w") f.write('line = line[:22] + "A" + line[23:]') f.close() File xxx.pdb is opened by the command: when I forgo

Re: Insert character at a fixed position of lines

2008-07-26 Thread Fredrik Lundh
Francesco Pietra wrote: How to insert letter "A" on each line (of a very long list of lines) at position 22, i.e., one space after "LEU", leaving all other characters at the same position as in the original example: ATOM 1 N LEU 1 146.615 40.494 103.776 1.00 73.04 1SG

Re: Insert character at a fixed position of lines

2008-07-26 Thread Lie
On Jul 26, 5:42 pm, "Francesco Pietra" <[EMAIL PROTECTED]> wrote: > I am still at the stone age, using scripts (e.g., to insert a string > after a string) of the type > > f = open("xxx.pdb", "r") > for line in f: >    print line >    if "H16Z POPC" in line: >        print "TER" > f.close() > > That

Re: Insert character at a fixed position of lines

2008-07-26 Thread Francesco Pietra
I am still at the stone age, using scripts (e.g., to insert a string after a string) of the type f = open("xxx.pdb", "r") for line in f: print line if "H16Z POPC" in line: print "TER" f.close() That is, I have to learn about modules. In your scripts I am lost about the filename for t

Re: Insert character at a fixed position of lines

2008-07-26 Thread Lie
On Jul 26, 2:41 pm, "Francesco Pietra" <[EMAIL PROTECTED]> wrote: > How to insert letter "A" on each line (of a very long list of lines) > at position 22, i.e., one space after "LEU", leaving all other > characters at the same position as in the original example: > > ATOM      1  N   LEU     1    

Re: Insert character at a fixed position of lines

2008-07-26 Thread Peter Otten
Francesco Pietra wrote: > How to insert letter "A" on each line (of a very long list of lines) > at position 22, i.e., one space after "LEU", leaving all other > characters at the same position as in the original example: > > > ATOM 1 N LEU 1 146.615 40.494 103.776 1.00 73.04