I am attempting to write data to a .txt file. The data that is being written are the random integers from the randrange
function in the following code.
I keep getting an error stating the object has no attribute when trying to write to the file.
Please help.
import random
def main():
file_size = open('numbers.txt','w')
file_size = random.randint(4, 7)
print("file_size = ", file_size)
for _ in range(file_size):
random_num = random.randrange(5,20,2)
if random_num % 2 ==1:
print(random_num)
file_size.write(str(random_num))
file_size.close()
print('Data has been written.')
main()