Python Forum
Making a number list in a .txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a number list in a .txt file
#7
(Sep-16-2018, 11:51 AM)Windspar Wrote:
with open("dico.txt","w") as f:
    for a in range(999999):
        f.write('{0:0>6}\n'.format(a))

'{0:0>6}\n'
{
0 = first variable
:0 = fill
> = left adjust
6 = six spaces
}

left adjust not needed for zero padding
with open("dico.txt","w") as f:
    for a in range(999999):
        f.write('{0:06}\n'.format(a))

I'd intended to leave it to the OP to figure out how to do the padding without the function they originally coded.

Not sure the OP wants the \n between numbers either.

That said, why not f-strings rather than format?
I am trying to help you, really, even if it doesn't always seem that way
Reply


Messages In This Thread
Making a number list in a .txt file - by kwak86 - Sep-15-2018, 08:59 PM
RE: Making a number list in a .txt file - by kwak86 - Sep-15-2018, 09:39 PM
RE: Making a number list in a .txt file - by kwak86 - Sep-15-2018, 10:48 PM
RE: Making a number list in a .txt file - by gruntfutuk - Sep-16-2018, 01:23 PM
RE: Making a number list in a .txt file - by kwak86 - Sep-16-2018, 04:12 PM
RE: Making a number list in a .txt file - by kwak86 - Sep-16-2018, 05:00 PM
RE: Making a number list in a .txt file - by kwak86 - Sep-16-2018, 05:34 PM
RE: Making a number list in a .txt file - by kwak86 - Sep-16-2018, 09:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete strings from a list to create a new only number list Dvdscot 8 1,865 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,883 Apr-05-2023, 07:36 PM
Last Post: Frankduc
Photo Making Zip file of a file and Directory Nasir 2 1,160 Oct-07-2022, 02:01 PM
Last Post: Nasir
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 5,185 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Split a number to list and list sum must be number sunny9495 5 2,667 Apr-28-2022, 09:32 AM
Last Post: Dexty
  Divide a number by numbers in a list. Wallen 7 8,356 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  When did the number got included in the list? Frankduc 14 3,466 Feb-03-2022, 03:47 PM
Last Post: Frankduc
Question Help to find the largest int number in a file directory SalzmannNicholas 1 1,748 Jan-13-2022, 05:22 PM
Last Post: ndc85430
Question Making a copy list in a function RuyCab 1 1,904 Jul-11-2021, 02:06 PM
Last Post: Yoriz
Smile Help making number analysis program Dainer 2 1,884 Jun-24-2021, 09:55 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020