Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python write into file at position

mystring = 'some string'
pos = 10

with open('/path/to/file.txt', 'r+') as f:
    contents = f.read()
    contents = contents[:pos] + mystring + contents[pos + 1:]
    f.seek(0)
    f.truncate()
    f.write(contents)
 
PREVIOUS NEXT
Tagged: #python #write #file #position
ADD COMMENT
Topic
Name
2+6 =