Gotoxy for files in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Gotoxy for files in python

Hey there! How can i write a string in a specific position in a file? For example, how can I write "hello" in coordinate (4,5)?

5th Dec 2017, 8:50 PM
Aref moloughi
Aref moloughi - avatar
1 Answer
+ 4
Use seek method of the file object. <file>.seek(offset) where offset is a zero based address of the file cursor. To go to beginning of file pass zero as offset. More about the seek method can be found at the following link: https://docs.python.org/3/tutorial/inputoutput.html Scroll down to find "7.2.1. Methods of File Objects" Hth, cmiiw
18th Dec 2017, 11:12 AM
Ipang