当前位置: 首页>>代码示例>>Python>>正文


Python Model.read_csv方法代码示例

本文整理汇总了Python中Model.Model.read_csv方法的典型用法代码示例。如果您正苦于以下问题:Python Model.read_csv方法的具体用法?Python Model.read_csv怎么用?Python Model.read_csv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Model.Model的用法示例。


在下文中一共展示了Model.read_csv方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CSVTest

# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import read_csv [as 别名]
class CSVTest(unittest.TestCase):
    def setUp(self):
        self.model = Model()

    def testsetDelimiter(self):
        self.model.setDelimiter(",")
        self.assertEqual(self.model.delimiter, ",")

    def testsetName(self):
        self.model.read_csv("data.csv")
        self.assertEqual(self.model.name, "data.csv")

    def testsetName_None(self):
        self.assertRaises(TypeError, self.model.read_csv)

    def testsetContent(self):
        self.model.setDelimiter(",")
        self.model.read_csv("data.csv")
        self.assertEqual(
            self.model.csv_content, "Year,Make,Model,Length,\n1997,Ford,E350,2.34,\n2000,Mercury,Cougar,2.38,\n"
        )

    def testsetDelimiter_None(self):
        self.assertRaises(TypeError, self.model.setDelimiter)
开发者ID:tstedronsky-tgm,项目名称:csv_tool,代码行数:26,代码来源:test.py

示例2: loader

# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import read_csv [as 别名]
class loader(QMainWindow):
    """ CSV-Module Application
        Autor: Thomas Stedronsky
        :param parent:
        """
    def __init__(self, parent=None):

        super().__init__(parent)
        self.form = view.Ui_MainWindow()
        self.form.setupUi(self)
        self.model = Model()
        self.model.setDelimiter(',')

        self.form.pushButton.clicked.connect(self.clicked)

    def get_text_line(self):
        self.model.csv_file = self.form.lineEdit.text()

    def clicked(self):
        self.model.csv_content = ''
        self.get_text_line()
        self.model.read_csv(self.model.csv_file)
        self.form.label_2.setText(self.model.name)
        self.form.textEdit.setText(self.model.csv_content)
开发者ID:tstedronsky-tgm,项目名称:csv_tool,代码行数:26,代码来源:loader.py

示例3: Controller

# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import read_csv [as 别名]

#.........这里部分代码省略.........
            pass

    def undoText_redoText(self):
        undo = "Undo"
        redo = "Redo"
        utext = self.undoStack.undoText()
        rtext = self.undoStack.redoText()
        if utext:
            undo += " \"" + utext + "\""
            self.gui.actionUndo.setText(undo)
        if rtext:
            redo += " \"" + rtext + "\""
            self.gui.actionRedo.setText(redo)

    def undo(self):
        self.undoStack.undo()
        self.undoText_redoText()
        self.gui.tableView.reset()

    def redo(self):
        self.undoStack.redo()
        self.undoText_redoText()
        self.gui.tableView.reset()

    def csvfile(self):
        """
        Mit dieser Methode wird das ausgewaehlte CSV-File in die Tabelle importiert
        :return:
        """
        if self.tablemodel.getHeader() == [] and self.tablemodel.getList() == []:
            fname = QtGui.QFileDialog.getOpenFileName(self.mwindow, 'Open file...', os.getcwd(), "CSV (*.csv)")[0]
            if len(fname) > 0:
                self.model.currentfile = fname
                datalist, header = self.model.read_csv(fname)
                self.update_table(datalist, header)
        else:
            result = QtGui.QMessageBox.question(QtGui.QWidget(),
            'Open',"Moechten Sie wirklich eine neues File öffnen?\n Alle ungespeicherten Daten gehen verloren!",
            QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
            if result == QtGui.QMessageBox.Yes:
                fname = QtGui.QFileDialog.getOpenFileName(self.mwindow, 'Open file...', os.getcwd(), "CSV (*.csv)")[0]
                if len(fname) > 0:
                    self.model.currentfile = fname
                    datalist, header = self.model.read_csv(fname)
                    self.update_table(datalist, header)
            else:
                pass


    def insertintable(self):
        """
        Erzeugt eine neuen Zeile (oberhalb der aktuellen Zeile)
        :return:
        """
        index, amount = self.get_selectedcell()
        self.undoStack.beginMacro("Add Row")
        self.undoStack.push(InsertCommand(self.tablemodel, index, 1))
        self.undoStack.endMacro()
        self.undoText_redoText()

    def removefromtable(self):
        """
        Entfernt eine asugewaehlte Zeile
        :return:
        """
        index, amount = self.get_selectedcell()
开发者ID:mbruckner-tgm,项目名称:CSV-Projekt,代码行数:70,代码来源:Control.py


注:本文中的Model.Model.read_csv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。