【发布时间】:2015-06-05 03:09:16
【问题描述】:
我有 python 类文件。
import re
regex = {
'a1': re.compile('(\d+)'),
}
# or A1_REGEX = re.compile('(\d+)')
class A1():
def toview(self, mystring):
data = regex['a1'].search(mystring)
if data:
......
或
import re
class A1():
a1 = re.compile('(\d+)')
def toView(self, mystring):
data = a1.search(mystring)
if data:
.......
请任何人告诉,哪一个更好,更准确。 ? 哪一个是python标准编码/PEP8标准? 在这种情况下,正则表达式使用是否有任何时间消耗或内存使用情况 可以考虑 ? 请在此添加您的意见或 cmets。 感谢您宝贵的 cmets。!
【问题讨论】:
-
请注意,在您的类方法中,第一个参数始终是对类实例的引用,通常称为
self
标签: python python-2.7 python-3.x scrapy pep8