Python string Substitution example _python

Source: Internet
Author: User

php5.2 upgrade to 5.3, the original & new writing has been given up, you can directly new, in the face of hundreds of PHP files, manual modification is really want to kill, so wrote a script, minutes to fix.

Copy Code code as follows:

#-*-Coding:utf-8-*-
#!/usr/bin/python

Import OS

#定义程序根目录
Rootpath= ' D:\\wamp\\www\\erp\\app '

def m_replace (path):
For item in Os.listdir (path):
Nowpath=os.path.join (Path,item)
If Os.path.isdir (Nowpath):
M_replace (Nowpath)
Else
If Nowpath.find ('. php ') >0:
F=open (Nowpath, ' r+ ')
Content=f.read (). Replace (' & New ', ' new ')
Open (Nowpath, ' W '). Write (str (content))
F.close ()

If __name__== "__main__":
M_replace (RootPath)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.