It's the indentation, where otehr programming languagess wants scopes defining where what starts/ends by using brackets, python uses indentation, in your example code you have the for loop printing the
item from returnline within the scope of you for loop reading from the file, in C/C++ it would be equivalent to writing something like this:
Code:
int j=0, i;
while(fgets(buffer, MAX_SIZE, file_pointer))
{
buffer[strlen(buffer)-1] = '\0';
strcpy(list[j], buffer);
for(i=0; i< j; ++i)
{
printf("%s\n", list[i]);
}
++j;
}
As you can see the printing of your gathered lines should only occure when you've finished filling in the list of lines found in the file, so obvius we're looking for this solution:
Code:
int j=0, i;
while(fgets(buffer, MAX_SIZE, file_pointer))
{
buffer[strlen(buffer)-1] = '\0';
strcpy(list[j], buffer);
++j;
}
for(i=0; i< j; ++i)
{
printf("%s\n", list[i]);
}
This should work, but not testet:
Code:
import re
returnline = []
f = open("List.txt", "r")
for line in f.readlines():
returnline.append(re.compile(' ').sub(',', line[0:-1]))
for item in returnline:
print item
Note the way theres no indentation befor the second
for line.