Jun-05-2018, 12:10 PM
Hello all,
I have written a small script which is supposed to read from the file the last row and return it as a starting point for a while loop to start calculating prime numbers. The problem I am having is that if I run the code in Windows environment on Spyder the script writes an extra line in the file and it looks like this:
Row number, Prime number
1, 3
2,
3, 5
4,
5, 7
...and so on.
If I run the very same code on my raspberry application called Thonny, csv file is written with no lines skipped.
Here is my script:
I have written a small script which is supposed to read from the file the last row and return it as a starting point for a while loop to start calculating prime numbers. The problem I am having is that if I run the code in Windows environment on Spyder the script writes an extra line in the file and it looks like this:
Row number, Prime number
1, 3
2,
3, 5
4,
5, 7
...and so on.
If I run the very same code on my raspberry application called Thonny, csv file is written with no lines skipped.
Here is my script:
import csv
division_number = 2
csv_rows = []
with open('prime2.csv', 'r') as datafile:
for line in datafile:
csv_rows.append(line.strip())
number_checking = int(csv_rows[-2])
while division_number < number_checking:
remainder = number_checking % division_number
if remainder == 0:
number_checking += 1
division_number = 2
else:
division_number += 1
if division_number == number_checking:
print(number_checking)
with open('prime2.csv','a') as csv_file:
writer = csv.writer(csv_file)
writer.writerow([number_checking])
number_checking += 1
division_number = 2
