def __replace_connection(self, id, node):
"""
Replace name of connection with user-defined id
:param id: Name to replace with
:param node: A call node
"""
newnode = ast.Name(id=id, ctx=ast.Load())
if len(node.args) != 0: # Conn given as positional arg
node.args[0] = newnode
else: # Conn given by keyword i.e. "connection = x"
for keyword in node.keywords:
if keyword.arg == 'connection'\
or keyword.arg == 'f'\
or keyword.arg == 'csvfile':
keyword.value = newnode
# Call to fill in line number and indentation information for the new
# node and its children.
ast.fix_missing_locations(node)
评论列表
文章目录