Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:处理列表列表_Python_List - Fatal编程技术网

Python:处理列表列表

Python:处理列表列表,python,list,Python,List,我有一份记录,包括 number,name,length,width,height,weight,price. 我有1000条相同格式的记录。我想创建一个记录列表。 此外,我还想处理列表,并应用一些逻辑检索列表中每个项目的所有记录值 file=open('filename.txt','r') file1=file.read().split('\n') listy=[] for elem in file1: listy.append(elem.split(',')) file.close(

我有一份记录,包括

number,name,length,width,height,weight,price.
我有1000条相同格式的记录。我想创建一个记录列表。 此外,我还想处理列表,并应用一些逻辑检索列表中每个项目的所有记录值

file=open('filename.txt','r')
file1=file.read().split('\n')
listy=[]
for elem in file1:
   listy.append(elem.split(','))
file.close()
print(listy)
这是假设它是一个txt文件

with open(filepath, 'r') as file:
    records = [record.strip().split(',') for record in file]

你能试试这个吗,希望这有帮助

你试过了吗?这似乎是一段足够简单的代码,因此不是一个代码编写服务网站。你好,桑托什,欢迎来到StackOverflow。我们将帮助您解决您面临的任何技术难题,但这看起来更像是一个免费工作的请求。如果你给我们的代码不起作用,我们将解释如何修复它。我假设它是一个txt文件