是否有一种很好的(呃)方法来查找字符串中单词的结束索引?
我的方法是这样的:
text = "fed up of seeing perfect fashion photographs"
word = "fashion"
wordEndIndex = text.index(word) + len(word) - 1
Run Code Online (Sandbox Code Playgroud) 如果我创建一个类的实例而不将其分配给变量,那么每次运行代码时它都会占用内存吗?或者在执行包含实例的代码行后内存是否会释放?
例如:
class TestClass():
def __init__(self):
self.Moto = "Moto"
def printIt(self):
print self.Moto
Run Code Online (Sandbox Code Playgroud)
所以如果我像这样使用它:
TestClass().printIt()
Run Code Online (Sandbox Code Playgroud)
每次执行该行都会占用越来越多的内存吗?
有没有一种简单的方法可以验证给定字符是否具有特殊的正则表达式函数?
当然我可以在列表中收集正则表达式字符,比如['.', "[", "]", etc.]检查一下,但我想有更优雅的方式.
我使用python为Autodesk Maya编写脚本.Maya是一个跨平台的软件,内部使用正斜杠.如果我在Windows上使用os.path.join操作,它可以产生如下路径:
e:/Test\\TemplatePicture.jpg
Run Code Online (Sandbox Code Playgroud)
我的想法是,只要我不使用ms-dos命令更简单的方式来加入这样的路径部分:
pathPart1 = "e:"
pathPart2 = "Test"
pathPart3 = "TemplatePicture.jpg"
path = "s%/s%/s%" % (pathPart1, pathPart2, pathPart3)
Run Code Online (Sandbox Code Playgroud)
有什么东西让它成为一个坏主意吗?