Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: python track time 
Python :: python get name of vlue 
Python :: Check and Install appropriate ChromeDriver Version for Selenium Using Python 
Python :: how to print out even index in python 
Python :: python how to print something at a specific place 
Python :: download unsplash images code 
Python :: python remove by index 
Python :: map to list python 
Python :: push notification using python 
Python :: how to make a bill in python 
Python :: python sliding window 
Python :: beautifulsoup 
Python :: requests save file python 
Python :: Add label to histogram 
Python :: how to generate random number in python 
Python :: django redirect 
Python :: expand alphabets in python 
Python :: current working directory in python 
Python :: pickled list 
Python :: leetcode matrix diagonal sum in python 
Python :: python number of lines in file 
Python :: add icon to exe file 
Python :: make gif from images in python 
Python :: python for unity 
Python :: rename all columns 
Python :: keyboard write python 
Python :: python check None 
Python :: strip characters from a string python 
Python :: dataframe look at every second column 
Python :: producer and consumer problem in python 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =