發新話題
打印

[PYTHON] BookMark Search and replace in Python

本主題被作者加入到個人文集中

BookMark Search and replace in Python

Jason and python



Youtube on Python and Mysql - creating our database and table









Syntax of replace() method:  str.replace(old, new[, max]) 


 ex. 

str = "this is a test demo, Well !! It is working !!! " 

 print str.replace("is", "was") 

print str.replace("is", "was", 3)



.
[ 本帖最後由 Net 於 2020-5-22 15:30 編輯 ]

TOP

fin = open("take.txt", "rt")
data = fin.read()
data = data.replace('https://', '[img]https://')
data = data.replace('jpg&name=small', 'jpg[/img]')

fin.close()

fin = open("take.txt", "wt")
fin.write(data)
fin.close()




https://pythonexamples.org/python-replace-string-in-file/

TOP

發新話題