1

I want to print 300 numbers in a txt file. The code is working properly, because the txt file prints also the information of how many numbers it contains and it is correct.

However, it prints 5 first numbers then '...' and then 5 last numbers. What should I do to make the txt file have all the numbers in it one by one, without '...'?

This is the code I used:

df=open('file_name','w')
df.write(str(numbers[indexes]))
df.write('\n')
df.close()

numbers contains 10k numbers and there are 300 indexes.

barista
  • 35
  • 5
  • 2
    The reason is how the `str` function works for large arrays. It will not show the whole array, only the first and last few elements. You can fix this by iterating through the array and call `str` for every element in the array and sum them together into one string. – martensi Jan 04 '23 at 11:46
  • What is *indexes* ? – DarkKnight Jan 04 '23 at 11:53
  • The indexes of the numbers that I wanted to print. But when I iterated through this array, it worked – barista Jan 04 '23 at 11:57
  • It can be duplicate: [Ellipses when converting list of numpy arrays to string in python 3](https://stackoverflow.com/questions/32805549/ellipses-when-converting-list-of-numpy-arrays-to-string-in-python-3) – KPiach Jan 04 '23 at 12:19

0 Answers0