You can merely add something to the file. However, you cannot replace the line that is already there in the file through the seek and flush method. However, if you prefer to use read and write, always use seek operation to get to the line that is to be replaced and use flush once you finish writing the file. NOTE: Read here(not an official link), to learn better about dictionary methods. Just open the file in read mode with generator expression and keep a reference count to satisfy write operation. You can even keep a count and write based on count, if you are bothered about memory in this case. myVariable 'file.txt' webbrowser.open(myVariable) Jump to Post. Answered by Gribouillis 1,391 in a post from 11 Years Ago. Replaced_text += line.replace(word, new_word) import webbrowser webbrowser.open('file.txt') On my system, it opens the file with gedit. Words_replacer_dict = įor word, new_word in words_replacer_ems(): 'a' - Append - Opens a file for appending, creates the file if it does not exist. Opens a file for reading, error if the file does not exist. There are four different methods (modes) for opening a file: 'r' - Read - Default value. The open () function takes two parameters filename, and mode. text_read = open('samiam.py', 'r').read() The key function for working with files in Python is the open () function. It will be good to use two descriptors - one for reading and other for writing, for readability and single write operation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |