Just started Python today... first question

General discussion for off-topic subjects.
User avatar
FlyingDoggyJake
Junior Member
Posts: 4
Joined: Tue Feb 01, 2022 3:11 am

Just started Python today... first question

Postby FlyingDoggyJake » Tue Feb 01, 2022 3:39 am

Hi all, I was a VB6 programmer about 20 years ago. I'm trying to get back into the fun again. Things have changed a lot. At any rate, my first question is that I wrote an extremely basic first program and saved it to a .py file. The code is as follows:

Code: Select all

for x in range(0, 150, 1):
    print("All work and no play makes Jake a dull boy. ", end = "")



When I executed it, the python console opened and it did exactly what I thought it would but I was shocked at how slow the loop ran. I mean the 150 lines printed in about 9 seconds. I had assumed that the loop would have been so lightning quick that I would not have even been able to see the lines rising on the screen. 20 years ago if I had done the same program in VB6 it would have been that lightning quick... so what gives? The computers now are waaaaay faster. I'm confused.
User avatar
Articha
Member
Posts: 32
Joined: Tue Sep 21, 2021 12:13 pm
Location: Russia

Re: Just started Python today... first question

Postby Articha » Tue Feb 01, 2022 6:30 am

That's because you using print function. To prevent spam, python adding delay between them

Use write to file instead:

Code: Select all

file = open("text.txt", "w")
for x in range(0, 150, 1):
    file.write("All work and no play makes Jake a dull boy. ", end = "")
file.close()

And your code will be executed instantly
User avatar
FlyingDoggyJake
Junior Member
Posts: 4
Joined: Tue Feb 01, 2022 3:11 am

Re: Just started Python today... first question

Postby FlyingDoggyJake » Tue Feb 01, 2022 7:33 am

Ahhh that makes sense! Thanks Articha!

Return to “Whatever”

Who is online

Users browsing this forum: No registered users and 20 guests