0

I have this script to load CSV data to 2D array ( I hope... :) )

with open("csv") as textFile:
    lines = [line.strip().split(",") for line in textFile]

Also I can get all data with this, or only some bite of data

print (lines)
print (lines[0][0])

However, I can't get all data with for loop, any idea ?

>>> for i in range (0,3):
...     for j in range (0,3):
...         print (lines([i][j])
... 
... 
... 
9
  • 1
    What the the problem with your loop code? Is it not getting the data from lines? Commented Apr 7, 2020 at 8:51
  • I suggest you use a csv.reader to read the rows of data into your list. Commented Apr 7, 2020 at 9:01
  • nothing, I get 3 dots only.... >> for i in range (0,3): ... for j in range (0,3): ... print (lines([i][j]) ... ... ... ... ... ... ... ... ... ... Commented Apr 7, 2020 at 9:01
  • I think, problem is somwhere else in logic or syntax, because I can get data with: print (lines);print (lines[0][0]); print (lines[1][1); Commented Apr 7, 2020 at 9:07
  • Does the 3 dots appear everytime you press enter? Commented Apr 7, 2020 at 9:22

1 Answer 1

2

It sounds like you are just experiencing one of the down-sides of using IDLE or a similar Python console. I will try to demonstrate the issue step-by-step.

  • The | represents the current cursor's location

We start by writing a simple for-loop:

>>> for i in range(3):|

Now, if we press Enter twice:

>>> for i in range(3):
...    
...    |

Now if we press the Up-arrow and write a print statement:

>>> for i in range(3):
...    print(i)|
...

Now if you press Enter again you will just get:

>>> for i in range(3):
...    print(i)
...    |
...

But if you press Delete you will go back to:

>>> for i in range(3):
...    print(i)
...    |

and now pressing Enter will actually execute the loop:

>>> for i in range(3):
...     print(i)
...         
0
1
2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.