Issues with a loop in Python 2.7
Hi all,
So I have attempted to start learning python and have got quite far into a script which reads a csv file. Inside the csv file I have a field that has a number. For now lets say it is 8. In my code it reads the field, stores it in a variable so I can re-use it later on. Now has come the time to use this variable and I want to test it in a while loop. Here is my code extract:- This line reads the data into the myData variable and I can then pull out the field needed. This works perfectly and gives me the number 8. Code:
myData = list(myReader) Code:
count = 0 What it does is just run an infinite loop and I have to ctrl-C the script. I am at a loss here as I have tried all sorts of combinations of brackets and commas and ticks. But still no joy. I apologise if this is a very basic problem. I am still learning and by the looks of it need all the help I can get! Thanks in advance for your time. |
Code:
# csv_host_cnt is a string. Code:
# So you need: |
@dugan - Thank you very much. I need to get some sleep I think! How on earth did I not see that.
Thanks again |
I'm not sure how you are reading the data, but doing myData = list(myReader) and then accessing it using var[1][1] will likely lead to frustration trying to access information from csv files.
Since it's a csv file, I would suggest something along these lines Code:
import csv Examples: The # represents what information the command is working with. Code:
# data-file file.csv Code:
data = open('file.csv') Code:
with open('file.csv') as f: |
All times are GMT -5. The time now is 08:06 PM. |