本文整理汇总了Python中pyexcel_io.save_data函数的典型用法代码示例。如果您正苦于以下问题:Python save_data函数的具体用法?Python save_data怎么用?Python save_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: render_book_to_stream
def render_book_to_stream(self, models, book,
inits=None, mapdicts=None,
batch_size=None, **keywords):
colnames_array = common.get_book_headers_in_array(book)
new_models = [model for model in models if model is not None]
initializers = inits
if initializers is None:
initializers = [None] * len(new_models)
if mapdicts is None:
mapdicts = [None] * len(new_models)
scattered = zip(new_models, colnames_array, mapdicts, initializers)
importer = django.DjangoModelImporter()
for each_model in scattered:
adapter = django.DjangoModelImportAdapter(each_model[0])
adapter.column_names = each_model[1]
adapter.column_name_mapping_dict = each_model[2]
adapter.row_initializer = each_model[3]
importer.append(adapter)
to_store = OrderedDict()
for sheet in book:
# due book.to_dict() brings in column_names
# which corrupts the data
to_store[sheet.name] = sheet.get_internal_array()
save_data(importer, to_store, file_type=self._file_type,
batch_size=batch_size, **keywords)
开发者ID:caspartse,项目名称:QQ-Groups-Spider,代码行数:26,代码来源:django.py
示例2: test_reading_from_more_models
def test_reading_from_more_models(self):
model1 = FakeDjangoModel()
model2 = FakeDjangoModel()
importer = DjangoModelImporter()
adapter1 = DjangoModelImportAdapter(model1)
adapter1.column_names = self.content["Sheet1"][0]
adapter2 = DjangoModelImportAdapter(model2)
adapter2.column_names = self.content["Sheet2"][0]
importer.append(adapter1)
importer.append(adapter2)
to_store = {
adapter1.get_name(): self.content["Sheet1"][1:],
adapter2.get_name(): self.content["Sheet2"][1:],
}
save_data(importer, to_store, file_type=DB_DJANGO)
assert model1.objects.objs == self.result1
assert model2.objects.objs == self.result2
model1._meta.model_name = "Sheet1"
model2._meta.model_name = "Sheet2"
model1._meta.update(["X", "Y", "Z"])
model2._meta.update(["A", "B", "C"])
exporter = DjangoModelExporter()
adapter1 = DjangoModelExportAdapter(model1)
adapter2 = DjangoModelExportAdapter(model2)
exporter.append(adapter1)
exporter.append(adapter2)
reader = DjangoBookReader()
reader.open_content(exporter)
data = reader.read_all()
for key in data.keys():
data[key] = list(data[key])
assert data == self.content
开发者ID:pyexcel,项目名称:pyexcel-io,代码行数:32,代码来源:test_django_book.py
示例3: setUp
def setUp(self):
self.test_file = "test_filter.csv"
sample = [
[1, 21, 31],
[2, 22, 32]
]
save_data(self.test_file, sample)
开发者ID:schulzsebastian,项目名称:qgisplugin_spreadsheet,代码行数:7,代码来源:test_renderer.py
示例4: edit
def edit():
# shutil.copyfile(app.config['EXTRA_STUDENTS_SOURCE_PATH'], app.config['EXTRA_STUDENTS_WORKING_PATH'])
records = get_array(file_name=app.config['EXTRA_STUDENTS_WORKING_PATH'])
if request.method == 'POST':
changed = False
removes = []
for key in request.form.keys():
m = re.match('remove_(\d+)', key)
if m:
removes.append(int(m.group(1)))
changed = True
records = [r for r in records if not (r[0] in removes)]
if request.form['student_number'] and request.form['first_name'] and \
request.form['last_name'] and request.form['email']:
records.append([
request.form['student_number'],
request.form['first_name'],
request.form['last_name'],
'104',
request.form['gender'],
request.form['email'],
'9919.1'
])
changed = True
if changed:
save_data(app.config['EXTRA_STUDENTS_WORKING_PATH'], records, lineterminator='\n')
return render_template('students.html', page_title='Edit Students', records=records)
开发者ID:ksdtech,项目名称:easybridge,代码行数:29,代码来源:flaskapp.py
示例5: test_issue_8
def test_issue_8():
test_file = "test_issue_8.csv"
data = [[1, 2], [], [], [], [3, 4]]
save_data(test_file, data)
written_data = get_data(test_file, skip_empty_rows=False)
eq_(data, written_data[test_file])
os.unlink(test_file)
开发者ID:pyexcel,项目名称:pyexcel-io,代码行数:7,代码来源:test_issues.py
示例6: write_data
def write_data(self, book):
initializers = self.keywords.get(params.INITIALIZERS, None)
if initializers is None:
initializers = [None] * len(self.tables)
mapdicts = self.keywords.get(params.MAPDICTS, None)
if mapdicts is None:
mapdicts = [None] * len(self.tables)
for sheet in book:
if len(sheet.colnames) == 0:
sheet.name_columns_by_row(0)
colnames_array = [sheet.colnames for sheet in book]
scattered = zip(self.tables, colnames_array, mapdicts, initializers)
importer = SQLTableImporter(self.session)
for each_table in scattered:
adapter = SQLTableImportAdapter(each_table[0])
adapter.column_names = each_table[1]
adapter.column_name_mapping_dict = each_table[2]
adapter.row_initializer = each_table[3]
importer.append(adapter)
to_store = OrderedDict()
for sheet_name in book.sheet_names():
# due book.to_dict() brings in column_names
# which corrupts the data
to_store[sheet_name] = book[sheet_name].array
save_data(importer, to_store, file_type=DB_SQL, **self.keywords)
开发者ID:Gayathri001,项目名称:cir-portal,代码行数:26,代码来源:database.py
示例7: test_pyexcel_issue_138
def test_pyexcel_issue_138():
array = [["123_122", "123_1.", "123_1.0"]]
save_data("test.csv", array)
data = get_data("test.csv")
expected = [["123_122", "123_1.", "123_1.0"]]
eq_(data["test.csv"], expected)
os.unlink("test.csv")
开发者ID:pyexcel,项目名称:pyexcel-io,代码行数:7,代码来源:test_issues.py
示例8: setUp
def setUp(self):
self.content = OrderedDict()
self.content.update({
'Sheet 1':
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0]
]
})
self.content.update({
'Sheet 2':
[
['X', 'Y', 'Z'],
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
]
})
self.content.update({
'Sheet 3':
[
['O', 'P', 'Q'],
[3.0, 2.0, 1.0],
[4.0, 3.0, 2.0]
]
})
self.file="mybook.csvz"
save_data(self.file, self.content)
开发者ID:jayvdb,项目名称:pyexcel-io,代码行数:28,代码来源:test_new_csvz_book.py
示例9: render_book_to_stream
def render_book_to_stream(self, file_stream, book,
inits=None, mapdicts=None, **keywords):
session, tables = file_stream
thebook = book
initializers = inits
colnames_array = common.get_book_headers_in_array(book)
if initializers is None:
initializers = [None] * len(tables)
if mapdicts is None:
mapdicts = [None] * len(tables)
scattered = zip(tables, colnames_array, mapdicts, initializers)
importer = sql.SQLTableImporter(session)
for each_table in scattered:
adapter = sql.SQLTableImportAdapter(each_table[0])
adapter.column_names = each_table[1]
adapter.column_name_mapping_dict = each_table[2]
adapter.row_initializer = each_table[3]
importer.append(adapter)
to_store = OrderedDict()
for sheet in thebook:
# due book.to_dict() brings in column_names
# which corrupts the data
to_store[sheet.name] = sheet.get_internal_array()
save_data(importer, to_store, file_type=self._file_type, **keywords)
开发者ID:caspartse,项目名称:QQ-Groups-Spider,代码行数:25,代码来源:sqlalchemy.py
示例10: test_load_sheet_from_django_model
def test_load_sheet_from_django_model(self):
model=FakeDjangoModel()
save_data(DB_DJANGO, self.data[1:], models={DEFAULT_SHEET_NAME: [model, self.data[0], None, None]})
assert model.objects.objs == self.result
model._meta.update(["X", "Y", "Z"])
reader = DjangoModelReader(model)
data = reader.to_array()
assert data == self.data
开发者ID:fuhrysteve,项目名称:pyexcel-io,代码行数:8,代码来源:test_django_book.py
示例11: render_sheet_to_file
def render_sheet_to_file(self, file_name, sheet, **keywords):
sheet_name = DEFAULT_SHEET_NAME
if sheet.name:
sheet_name = sheet.name
data = {sheet_name: sheet.to_array()}
save_data(file_name,
data,
**keywords)
开发者ID:jayvdb,项目名称:pyexcel,代码行数:8,代码来源:renderer.py
示例12: test_file_handle_as_output
def test_file_handle_as_output():
test_file = "file_handle.csv"
with open(test_file, 'w') as f:
save_data(f, [[1, 2, 3]], 'csv', lineterminator='\n')
with open(test_file, 'r') as f:
content = f.read()
eq_(content, '1,2,3\n')
开发者ID:schulzsebastian,项目名称:qgisplugin_spreadsheet,代码行数:8,代码来源:test_io.py
示例13: test_conversion_from_bytes_to_text
def test_conversion_from_bytes_to_text():
data = [['1','2','3']]
save_data("conversion.csv", data)
with open("conversion.csv", "rb") as f:
content = f.read()
result = get_data(content, 'csv')
assert result == data
os.unlink("conversion.csv")
开发者ID:fuhrysteve,项目名称:pyexcel-io,代码行数:8,代码来源:test_io.py
示例14: render_sheet_to_stream
def render_sheet_to_stream(self, file_stream, sheet, **keywords):
sheet_name = DEFAULT_SHEET_NAME
if sheet.name:
sheet_name = sheet.name
data = {sheet_name: sheet.to_array()}
save_data(file_stream,
data,
file_type=self.file_type,
**keywords)
开发者ID:jayvdb,项目名称:pyexcel,代码行数:9,代码来源:renderer.py
示例15: test_case_insentivity
def test_case_insentivity():
data = [['1', '2', '3']]
io = manager.get_io("CSV")
# test default format for saving is 'csv'
save_data(io, data)
io.seek(0)
# test default format for reading is 'csv'
result = get_data(io)
assert result['csv'] == [[1, 2, 3]]
开发者ID:schulzsebastian,项目名称:qgisplugin_spreadsheet,代码行数:9,代码来源:test_io.py
示例16: test_conversion_from_bytes_to_text
def test_conversion_from_bytes_to_text():
test_file = "conversion.csv"
data = [['1','2','3']]
save_data(test_file, data)
with open(test_file, "rb") as f:
content = f.read()
result = get_data(content, 'csv')
assert result['csv'] == [[1, 2, 3]]
os.unlink(test_file)
开发者ID:jayvdb,项目名称:pyexcel-io,代码行数:9,代码来源:test_io.py
示例17: test_write_xlsx_data_to_memory
def test_write_xlsx_data_to_memory():
data = {'Sheet': [[1]]}
io = BytesIO()
msg = "Please install one of these plugins for write data in 'xlsx': "
msg += "pyexcel-xlsx,pyexcel-xlsxw"
try:
save_data(io, data, file_type="xlsx")
except manager.SupportingPluginAvailableButNotInstalled as e:
eq_(str(e), msg)
开发者ID:schulzsebastian,项目名称:qgisplugin_spreadsheet,代码行数:9,代码来源:test_io.py
示例18: test_generator_can_be_written
def test_generator_can_be_written():
test_filename = "generator.csv"
test_fixture = os.path.join("tests", "fixtures", "test.csv")
data = get_data(test_fixture, streaming=True)
save_data(test_filename, data)
assert os.path.exists(test_filename)
data2 = get_data(test_filename)
expected = get_data(test_fixture)
assert data2[test_filename] == expected['test.csv']
os.unlink(test_filename)
开发者ID:jayvdb,项目名称:pyexcel-io,代码行数:10,代码来源:test_io.py
示例19: test_issue_30_utf8_BOM_header
def test_issue_30_utf8_BOM_header():
content = [[u"人有悲歡離合", u"月有陰晴圓缺"]]
test_file = "test-utf8-BOM.csv"
save_data(test_file, content, encoding="utf-8-sig", lineterminator="\n")
custom_encoded_content = get_data(test_file, encoding="utf-8-sig")
assert custom_encoded_content[test_file] == content
with open(test_file, "rb") as f:
content = f.read()
assert content[0:3] == b"\xef\xbb\xbf"
os.unlink(test_file)
开发者ID:pyexcel,项目名称:pyexcel-io,代码行数:10,代码来源:test_issues.py
示例20: write_data
def write_data(self, book):
book_dict = book.to_dict()
if isinstance(self.file_name, tuple):
save_data(self.file_name[1],
book_dict,
file_type=self.file_name[0],
**self.keywords)
else:
save_data(self.file_name,
book_dict,
**self.keywords)
开发者ID:darylyu,项目名称:pyexcel,代码行数:11,代码来源:file.py
注:本文中的pyexcel_io.save_data函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论