Python文件阅读

时间:2017-09-23 12:40:40

标签: python linux python-2.7

我想从批处理中的10行文件中读取以下文本。对于来自特定变量的行的每个值,我希望以后以连续的方式绘制它们。这是文件数据格式:

CREATE TABLE PROJECT (
    NAME VARCHAR2 (100) PRIMARY KEY,
    STATE  VARCHAR2 (100),
    DATEDBT DATE,
 );

CREATE TABLE SMALLPROJECT (
    NAMEPROJECT       VARCHAR2 (100) REFERENCES PROJECT (NAME) ON DELETE CASCADE
                                                          ON UPDATE CASCADE,
    NAME VARCHAR2 (20)  PRIMARY KEY,
    DATEDBT     DATE,
    STATE VARCHAR2 (20)  PRIMARY KEY

    );

我想在python代码中阅读它。将值存储在某些变量中,然后在一次运行中绘制10行,然后在某些while循环中绘制一些睡眠,我会读取其他10行绘制它们,然后重复这些内容直到文件结束。

2 个答案:

答案 0 :(得分:0)

这应该有用。

将文件名.txt更改为文件名

 getStatistics(array: Array<number>) {
    const stats = new Statistics;
    stats.max = 0;
    stats.min = 0;
    stats.mod = 0;
}

这将保存在Level1

# open your file (Your file name.txt is the file name in read mode (r))
file = open(Your file name.txt", "r")
# for each line in Your File
for line in file:
# Split each word that is inbetween commers into seperate variables
    details =line.split(", ")
    Level1 = details[0]
    Level2 = details[1]

在Level2中

Yus level{number} : var1 = {number}

不知道如何摆脱var2=50

它一次只能做一个,按你的意愿修改它。

答案 1 :(得分:0)

只需按空格分割每一行,按索引获取列:

data.forEach(merchantSnapshot => {
    var merchantData = snapshot.val();
    var merchantName = merchantData.merchantName;
    console.log('check ' + merchantName);
    merchantSnapshot.child("branches").forEach(brancheSnapshot => {
        var branchName = brancheSnapshot.val().branchName;
        var branchAddress = brancheSnapshot.val.branchAddress;
        console.log('   ' + branchName + ' ' + branchAddress);
    });
});