[排除任何只是嘲弄内置的测试代码]
鉴于随着时间的推移已添加了许多内置函数,如果有多次出现,我会接受一个答案,显示一个模块或一些代码,这些代码是在内置之后创建的。
我的理由是,在python邮件列表上发布question之后,一些回复表明有些Python社区的成员认为它是 完全合理地使用影子内置函数的变量名称,当任何其他名称也能正常工作时。
我想使用标准库来衡量这种做法在各种Python开发人员中的常见程度。
答案 0 :(得分:5)
内置我最常见的影子是id
,因为它作为变量名称非常有用,并且内置很少被调用。快速查看2.7标准库有很多用途:
aifc.py: if id == marker[0]:
aifc.py: id = _read_short(chunk)
aifc.py: if id == self._markers[i][0]:
aifc.py: if id == marker[0]:
difflib.py: id = ' id="%s%s"' % (self._prefix[side],linenum)
difflib.py: id = ''
nntplib.py: id = ''
nntplib.py: id = words[2]
nntplib.py: resp, nr, id = self.statparse(resp)
pdb.py: id = idstring[0].strip()
pdb.py: id = idstring[1].strip()
pdb.py: if id == '': return failed
platform.py: id = values[2]
platform.py: id = ''
platform.py: id = l[1]
platform.py: id = _id
str
,list
和int
也有很多用途:
Cookie.py: str = str[1:-1]
mailcap.py: str = os.environ['MAILCAPS']
mimetools.py: str = self.typeheader
mimetools.py: str = 'text/plain'
mimetools.py: str = str[:i]
mimetools.py: str = self.plisttext
mimetools.py: str = str[1:]
mimetools.py: str = str[end:]
rfc822.py: str = m.getheader(name)
rfc822.py: str = m.getrawheader(name)
smtplib.py: str = ""
smtplib.py: str = '%s%s' % (cmd, CRLF)
smtplib.py: str = '%s %s%s' % (cmd, args, CRLF)
sre_parse.py: pattern.str = str
xmllib.py: str = res.group(1)
xmllib.py: str = chr(int(str[2:], 16))
xmllib.py: str = chr(int(str[1:]))
xmllib.py: str = self.entitydefs[str]
xmllib.py: str = '&' + str + ';'
uuid.py: int = long(hex, 16)
uuid.py: int = long(('%02x'*16) % tuple(map(ord, bytes)), 16)
uuid.py: int = ((time_low << 96L) | (time_mid << 80L) |
SimpleHTTPServer.py: list = os.listdir(path)
StringIO.py:list = f.readlines()# list of f.readline() results until EOF
StringIO.py: list = f.readlines()
anydbm.py: list = d.keys() # return a list of all existing keys (slow!)
asynchat.py: self.list = deque()
asynchat.py: self.list = deque(list)
bdb.py: list = self.breaks[filename]
cgi.py: list = None
cgi.py: list = traceback.format_tb(tb, limit) + \
code.py: list = traceback.format_exception_only(type, value)
code.py: list = traceback.format_list(tblist)
dircache.py: cached_mtime, list = cache[path]
dircache.py: cached_mtime, list = -1, []
dircache.py: list = os.listdir(path)
mailbox.py: # list = map(long, filter(pat.match, os.listdir(self.dirname)))
mailbox.py: list = os.listdir(self.dirname)
mailbox.py: list = filter(pat.match, list)
mailbox.py: list = map(long, list)
mhlib.py:list = mh.listfolders() # names of top-level folders
mhlib.py:list = mh.listallfolders() # names of all folders, including subfolders
mhlib.py:list = mh.listsubfolders(name) # direct subfolders of given folder
mhlib.py:list = mh.listallsubfolders(name) # all subfolders of given folder
mhlib.py:list = f.listmessages() # list of messages in folder (as numbers)
mhlib.py:list = f.parsesequence(seq) # parse msgs syntax into list of messages
mhlib.py: list = []
mhlib.py: list = map(int, stuff.split())
multifile.py: list = []
nntplib.py: list = []
nntplib.py: resp, list = self.longcmd('LIST', file)
nntplib.py: resp, list = self.longcmd(line, file)
pickle.py: list = stack[-1]
pickle.py: list = stack[mark - 1]
pipes.py: list = []
poplib.py: list = []; octets = 0
pstats.py: width, list = self.get_print_list(amount)
pstats.py: width, list = self.get_print_list(amount)
pstats.py: width, list = self.get_print_list(amount)
rexec.py: list = []
rfc822.py: list = m.getaddrlist(name)
shelve.py: list = d.keys() # a list of all existing keys (slow!)
socket.py: list = []
telnetlib.py: list = list[:]
traceback.py: list = []
traceback.py: list = []
traceback.py: list = ['Traceback (most recent call last):\n']
traceback.py: list = list + format_tb(tb, limit)
traceback.py: list = []
traceback.py: list = list + format_exception_only(etype, value)
traceback.py: list = []
xdrlib.py: list = []
xdrlib.py: list = []
并且有太多file
和dir
用于发布...
答案 1 :(得分:0)
id
作为变量名的几种用法; id
作为变量名称; len
作为变量名; hex
作为变量名称; filter
作为变量名; 在空格之间搜索内置名称可以提供帮助。