简体   繁体   中英

Python : String Replace

I have a string with code. It's not working to replace TestData using.replace

class_text = r"""
@classmethod
def setUpClass(cls):
    #Run base class' setup and then load the web app and login
    super(TestData, cls).setUpClass() 
"""
className = "Test"
class_text.replace("TestData", className)

You should use:

class_text = class_text.replace("TestData", className)

instead of

class_text.replace("TestData", className)

since .replace changes nothing but returns a new string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM