I need to output the CSV file text in three files for odds, evens and all numbers. However, Right now it only has them being printed on a single line in an array format when you run the program. I need all the numbers to be on their own individual lines separated by commas.
For example:
1,
2,
3,
4,
5,
I can use loops on all the writerows as seen in the code below however this option crates values separated like
1,
2,
3,
4,
5,
I would like to avoid this and just use .join or the newline, or even something else in order to get the correct output, but I could not get either to work and don't have a ton of experience in formatting csv files.
import csv
from tkinter import *
myGui = Tk()
myGui.title("Label Creator v: 0.01")
myGui.geometry("290x70")
allArray = []
oddArray = []
evenArray = []
Label(myGui, text="Starting value: ").grid(row=0)
Label(myGui, text="Ending value: ").grid(row=1)
a = IntVar()
b = IntVar()
e1 = Entry(myGui, textvariable=a)
e1.grid(row=0, column=1)
e2 = Entry(myGui, textvariable=b)
e2.grid(row=1, column=1)
def main():
oute1 = a.get()
oute2 = b.get()
for i in range(oute1, oute2 + 1):
x = i
allArray.append(x)
# Odds
if(x % 2 == 1):
oddArray.append(x)
# Evens
elif(x % 2 == 0):
evenArray.append(x)
with open("all_labels", "w") as outputFile1:
writer1 = csv.writer(outputFile1)
for k in allArray:
writer1.writerow([k])
with open("odd_labels", "w") as outputFile1:
writer2 = csv.writer(outputFile1)
for k in oddArray:
writer2.writerow([k])
with open("even_labels", "w") as outputFile2:
writer3 = csv.writer(outputFile2)
for k in evenArray:
writer3.writerow([k])
Button(myGui, text="Start", command=main).grid(row=3)
myGui.mainloop()
for k in allArray:? Why not just write allArray directly. Then it will be one row