Используйте модуль csv
(Python 2.x):
import csv
with open('file.csv', 'rb') as f:
reader = csv.reader(f)
your_list = list(reader)
print your_list
# [['This is the first line', 'Line1'],
# ['This is the second line', 'Line2'],
# ['This is the third line', 'Line3']]
Если вам нужны кортежи:
import csv
with open('test.csv', 'rb') as f:
reader = csv.reader(f)
your_list = map(tuple, reader)
print your_list
# [('This is the first line', ' Line1'),
# ('This is the second line', ' Line2'),
# ('This is the third line', ' Line3')]
Python 3 .x (by @seokhoonlee ниже)
import csv
with open('file.csv', 'r') as f:
reader = csv.reader(f)
your_list = list(reader)
print(your_list)
# [['This is the first line', 'Line1'],
# ['This is the second line', 'Line2'],
# ['This is the third line', 'Line3']]
Мне удалось добиться этого с помощью следующего кода:
import sys
import new_package
sys.modules['package'].scenario=new_package