Question

    script = open(os.path.join("SCRIPTS", checkscript + oldUser + ".SCRIPT"),"r+")
    alllines = script.readlines()
    data = ""

    lines = script.read().split("\n")
    for lineNum in range(1,len(lines)):
        if int(lineNum) < 10:
            print "|"+ str(lineNum) + "  |" + str(lines[lineNum - 2])
        if int(lineNum) < 100 and int(lineNum) > 9:
            print "|"+ str(lineNum) + " |" + str(lines[lineNum - 2])
        if int(lineNum) < 1000 and int(lineNum) > 99:
            print "|"+ str(lineNum) + "|" + str(lines[lineNum - 2])

^ I'm splitting up a files lines with .split so I can index them through an array. However, I'm doing something wrong because it does not print the lines that I'm telling it to print.

To describe what I'm trying to do...

Say this is the txt file I'm editing.

line one line two line three

I'm trying to split up the txt file so I can print my lines like this..

|1  |line one
|2  |line two
|3  |line three

The if statements about the value of the line is to keep spacing... for example...

|10 |line ten
|100|line one-hundred

However, nothing is being printed at all. I'm not even getting an error in order to try and find the issue.

Was it helpful?

Solution

Nothing is being printed because you have already called script.readlines(). The subsequent script.read() function has nothing to read.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top