Insert character at a fixed position of lines

alex23 wuwei23 at
Sun Jul 27 04:45:39 CEST 2008

On Jul 27, 9:26 am, Lie Ryan <lie.1... at> 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 further confusing an already
confused poster.

You -cannot- assign within a function call. What you're doing there is
claiming line is a keyword argument:

>>> f = open('dummy.txt','w')
>>> f.write(line = 'this doesn't work')
  File "<stdin>", line 1
    f.write(line = 'this doesn't work')
SyntaxError: invalid syntax

What you meant, of course, was:

>>> f.write(line[:22] + "A" + line[23:])

More information about the Python-list mailing list