Разрешить пользователям настраивать файл импорта по умолчанию в пакете

Используйте модуль 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']]

0
задан AKE 2 March 2019 в 20:53
поделиться

1 ответ

Мне удалось добиться этого с помощью следующего кода:

import sys
import new_package
sys.modules['package'].scenario=new_package
0
ответ дан AKE 2 March 2019 в 20:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: