-1

Here is my program:

file='_pycache_'
test=[]
with open(file) as f:
    for line in f:
      test.append(line)

    for i in range(196):
        for j in range(10):
            print(test[j * 196 + i], sep=' ', end = " ", flush=True)
        print()

But the output still displays the output as vertical instead of horizontal such as:

 2016.10.19_22:53:57
    3
   10
   254.1
   848.1
      17
    567.6
    210
   1.1491
   0.6985

 2016.10.19_22:54:18
    4
   10
   334.8
   837.0
      12
    759.8
    166
   1.1134
   0.9032

instead of printing the output in chunks of horizontal output ie each chunk begins with 2016.10.19... so there is a horizontal "table":

 2016.10.19_22:53:57            2016.10.19_22:54:18
    3                                   4
   10                                  11
   254.1                             245.1
   848.1                             848.1
      17                               17
    567.6                              567.7
    210                                211
   1.1491                             1.1491
   0.6985                             0.7985
Arya McCarthy
  • 8,554
  • 4
  • 34
  • 56
Ella
  • 3
  • 2
  • I don't think you have a clear understanding about how `STDOUT` works. Just like with writing to a file, you go line by line, not column by column. – Arya McCarthy Jun 19 '17 at 23:08
  • How could I edit the code to give an output with horizontal data displayed? – Ella Jun 19 '17 at 23:09
  • try change your `test.append(line)` line into `test.append(line.rstrip())` – Skycc Jun 19 '17 at 23:12
  • Possible duplicate of [Print multiline strings side-by-side](https://stackoverflow.com/questions/43560588/print-multiline-strings-side-by-side) – Arya McCarthy Jun 19 '17 at 23:13

1 Answers1

1
print(test[j * 196 + i].replace('\n', ' '), sep=' ', end = " ")

When reading from the file, you copy the newline too.

cs95
  • 379,657
  • 97
  • 704
  • 746