我有以下代码:
url = 'abcdc.com'
print(url.strip('.com'))
Run Code Online (Sandbox Code Playgroud)
我期望: abcdc
我有: abcd
现在我做
url.rsplit('.com', 1)
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
我有一些简单的python代码搜索文件中的字符串,例如path=c:\path,c:\path可能会有所不同.目前的代码是:
def find_path(i_file):
lines = open(i_file).readlines()
for line in lines:
if line.startswith("Path="):
return # what to do here in order to get line content after "Path=" ?
Run Code Online (Sandbox Code Playgroud)
之后获取字符串文本的简单方法是什么Path=?有没有简单的方法,没有封闭,反射或其他深奥的东西?