私は辞書のリストを持っていますlistEntries
。print listEntries
IPython で言うと、次の出力が得られます。
[{'div': ' ',
'id': ' EE 760 ',
'instructor': 'Narayanan H.',
'instructor_type': 'I ',
'name': 'Advanced Network Analysis',
'slot': '3 ',
'student': '28'},
{'div': ' ',
'id': ' EE 764 ',
'instructor': 'Karandikar Abhay',
'instructor_type': 'I ',
'name': 'Wireless & Mobile Communication',
'slot': '1 ',
'student': '36'}]
しかし、私がすべてをa = listEntries[0]
フォローすると、 .print a
{}
更新: pop メソッドを使用すると、期待どおりの動作が得られます。このリストは、csv ファイルを解析して作成しました。
これがコードです。
import os
import csv
file1 = open('./data.txt', 'r');
csv1 = csv.reader(file1);
listEntry = list();
for row in csv1 :
# if first row is a number then this row represent course.
course = {}
if row[0].isdigit() :
course['id'] = row[1]
course['name'] = row[2]
course['instructor'] = row[3]
course['instructor_type'] = row[4]
course['slot'] = row[5]
course['div'] = row[6]
course['student'] = row[7]
else : pass
listEntry.append(course);
print listEntry[0]
ここに私が解析しているファイル data.txt があります。私はpython2.7を使用しています
"Running courses for year 2005-2006 and semester 2 "
" 1991-1992 1992-1993 1993-1994 1994-1995 1995-1996 1996-1997 1997-1998 1998-1999 1999-2000 2000-2001 2001-2002 2002-2003 2003-2004 2004-2005 2005-2006 2006-2007 2007-2008 2008-2009 2009-2010 2010-2011 2011-2012 2012-2013 1 - Autumn 2 - Spring 3 - Summer 4 - winter "
"Instructor Status A=Associate"
"Sr no.","Course Code","Course Name","Instructor Name","Instructor Status","Slot","Division","Enrolled students","Biometric Attendance Enabled?","Registration Limit","Restrictions","Division"
"67"," EE 760 ","Advanced Network Analysis","Narayanan H.","I ","3 "," ","28","-","0","",""
"68"," EE 764 ","Wireless & Mobile Communication","Karandikar Abhay","I ","1 "," ","36","-","0","",""