當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleSQLite.create_table_from_csv方法代碼示例

本文整理匯總了Python中simplesqlite.SimpleSQLite.create_table_from_csv方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleSQLite.create_table_from_csv方法的具體用法?Python SimpleSQLite.create_table_from_csv怎麽用?Python SimpleSQLite.create_table_from_csv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在simplesqlite.SimpleSQLite的用法示例。


在下文中一共展示了SimpleSQLite.create_table_from_csv方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_normal_file

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_csv [as 別名]
    def test_normal_file(
        self,
        tmpdir,
        csv_text,
        csv_filename,
        table_name,
        attr_names,
        expected_table_name,
        expected_attr_names,
        expected_data_matrix,
    ):
        p_db = tmpdir.join("tmp.db")
        p_csv = tmpdir.join(csv_filename)

        with open(str(p_csv), "w") as f:
            f.write(csv_text)

        con = SimpleSQLite(str(p_db), "w")
        con.create_table_from_csv(str(p_csv), table_name, attr_names)

        assert con.fetch_table_names() == [expected_table_name]
        assert expected_attr_names == con.fetch_attr_names(expected_table_name)

        result = con.select(select="*", table_name=expected_table_name)
        result_matrix = result.fetchall()
        assert len(result_matrix) == 3
        assert result_matrix == expected_data_matrix
開發者ID:thombashi,項目名稱:SimpleSQLite,代碼行數:29,代碼來源:test_simplesqlite.py

示例2: open

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_csv [as 別名]
#!/usr/bin/env python
# encoding: utf-8

from __future__ import print_function

from simplesqlite import SimpleSQLite


with open("sample_data.csv", "w") as f:
    f.write("\n".join(['"attr_a","attr_b","attr_c"', '1,4,"a"', '2,2.1,"bb"', '3,120.9,"ccc"']))

# create table ---
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_from_csv("sample_data.csv")

# output ---
table_name = "sample_data"
print(con.fetch_attr_names(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
    print(record)
開發者ID:thombashi,項目名稱:SimpleSQLite,代碼行數:23,代碼來源:sample_create_table_from_csv.py

示例3: open

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_csv [as 別名]
#!/usr/bin/env python
# encoding: utf-8


from simplesqlite import SimpleSQLite
import six


file_path = "sample_data.csv"

with open(file_path, "w") as f:
    f.write("\n".join([
        '"attr_a","attr_b","attr_c"',
        '1,4,"a"',
        '2,2.1,"bb"',
        '3,120.9,"ccc"',
    ]))

# create table ---
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_from_csv(file_path)

# output ---
table_name = "sample_data"
six.print_(con.get_attribute_name_list(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
    six.print_(record)
開發者ID:furikake,項目名稱:SimpleSQLite,代碼行數:30,代碼來源:sample_create_table_from_csv.py


注:本文中的simplesqlite.SimpleSQLite.create_table_from_csv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。