我想在我正在编写的程序中使用一个列表。基本上,它是一个包含不同人信息的元组列表,每个人的信息(姓名、电话、地址等)都存储在一个元组中。我通过一个初始函数定义了这个列表,但我需要在我的交互函数以及其他函数中使用它。
我的问题是,我是否可以使用此列表而不将其定义为全局变量?
def load_friends(filename):
"""imports filename as a list of tuples using the import command"""
import csv
with open(filename, 'Ur')as filename:
friends_list = list(tuple(x) for x in csv.reader(filename, delimiter=','))
def add_friend(friend_info, friends_list):
"""appends the friend_info tupple to the list friends_list"""
new_list = friends_list.append(friends_info)
def interact():
"""interaction function: accepts user input commands"""
while True:
command = raw_input('Command: ')
我还应该提到,有一个命令可以解析使用输入以执行功能。这会影响列表的使用吗?