如何避免打开多个CSV文件?

时间:2017-07-11 17:48:33

标签: python tkinter tk

以下代码实现了PSSE(Python并行动态模拟)。这段代码对我有用,但我想让它变得更好。不是为各种案例研究打开大量的CSV文件,是否可以将所有信息链接到一个csv文件或数据库中,以简化生活?

每张Excel表格都包含以下信息:Bus #Power CHANGEisload。我尝试了另一年的另一行数据,但它正在阅读第一组信息。我正在尝试链接我创建的所有160个CSV文件(合并所有CSV文件),我做了,但它没有运行。

这是我的代码:

PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN"
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION

import psspy
import redirect
import csv
psspy.throwPsseExceptions = True

from Tkinter import *
import tkFileDialog
import tkSimpleDialog
import tkMessageBox

def quit():
    global root
    root.quit()

root= Tk()
tkMessageBox.showinfo("Welcome", "Please select case study: ")

root.fileName = tkFileDialog.askopenfilename(filetypes=(("PSSE CASES", "*.sav"),
                                                       ("PSSE CASES", "*.sav*")))

STUDY_CASE = root.fileName

root.filename = tkFileDialog.askopenfilename(filetypes=(("CSV files", "*.csv"),
                                                        ("All files", "*.*")))

STUDY_CASE = ('C:\Users\RoszkowskiM\Documents\Base      '
              'Cases\Final\ceii_Case1_SUM_2017_5050_MMWG16PF_FINAL.sav')

LOAD_GEN_DATAFILE = 'C:\Users\RoszkowskiM\Documents\CSV Files\example2.csv'

psspy.psseinit(10000)
psspy.case(STUDY_CASE)

tkMessageBox.showinfo(
    "Welcome",
    "Please select folder with year and then select desired TLA Assignment ")
root.fileName = tkFileDialog.askopenfilename(filetypes=(("CSV FILES", "*.csv"),
                                                        ("CSV FILES", "*.csv*")))

LOAD_GEN_DATAFILE = root.fileName

# read the entire CSV into Python.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))

# assume CSV has columns as described in the doc string
for bus,change,isload in data:
    # convert the types from string to Python numbers
    change = float(change)
    bus = int(bus)

    if isload.isdigit() and int(isload):
        psspy.bsys(1,0,[0.0,0.0],0,[],1,[bus],0,[],0,[])
        psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0])
        psspy.scal_2(0,1,2,[0,1,0,1,0],[change,0.0,0,-.0,0.0,-.0,0])
    else:
        exit

0 个答案:

没有答案