In place replacement of text in a file in Python

后端 未结 3 1040
借酒劲吻你
借酒劲吻你 2021-01-15 14:51

I am using the following code to upload a file on server using FTP after editing it:

import fileinput

file = open(\'example.php\',\'rb+\')

for line in file         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-15 15:20

    The second error is how the replace() method works.

    It returns the entire input string, with only the specified substring replaced. See example here.

    To write to a specific place in the file, you should seek() to the right position first.

    I think this issue has been asked before in several places, I would do a quick search of StackOverflow.

    Maybe this would help?

提交回复
热议问题