Hello everyone, [first post] I already have (very) good knowledge in programming (mysql, php, html,cs) and I would like to learn python, but I don’t know where to start to acquire good knowledge quickly enough, thank you for your comments and recommendations!
Guillaume.
javascript and css, also, yes…
well, I have already installed python and executed a script, so far, everything is fine!
Hello everyone, I tried to pause my simple code, like found on the internet, but it doesn’t work, stupid question from a newbie sorry for that but I couldn’t find good answers to that.
the formatting code (if it’s ok ? ) =>
import os
os.system("pause")
Thank you for your enlightenment!
Guillaume.
In what sense does it not work? What are you trying to do?
What did you expect would happen when you ran this? What happened instead?
if you want your program to run in a shell and pause until the user presses enter, I believe the best way to achieve that is input("")
.
os
is a bit finicky, and I would avoid it if possible. (It’s usually possible.)
To answer your question of why it’s not working, we’d need to know your IDE, operating system, etc. The code looks fine.
Hello Alexander, thanks for trying to help !
whell, the The window closes immediately this is my code =>
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
import os
os.system("pause")
where is my mistake please ?
Guillaume.
Hello Peter, my IDE is unless I’m mistaken? " Visual Code " and my OS => windows 11…
and I try to familiarize myself with a simple loop to improve myself little by little.
How are you running this script? Usually, python scripts like this are run from within an IDE.
If you are running the script by double-clicking on it, python probably runs into a problem in your script and prints an error message, which you never see because the process finishes and the associated window closes.
If the code is actually what you posted:
the error is IndentationError
. print(x)
needs to be indented relative to the for
loop.
When developing python, you should work in an IDE, or at the very least run your code from the command line.
and I try it in a shell, yes…
well I use Visual Code and I try to run it in a shell. Can you please post me the example of the correct script please ?
By the way, I’m French (I use Google Translate, even if I have a pretty good level in English)
Like I said, if you indent the print
statement the script is valid:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
import os
os.system("pause")
Keep in mind that this will only run on windows, since pause
is a windows-specific command. If you just want the script to pause for user input at that point, it is better to use the python function input("")
, like peterc said above.
Thank you! This time it works properly! I imagine that anointing python input(“”) is a “native” function, stay tuned, next step => functions! Maybe? Or if you have any other recommendations?
Guillaume.
I recommend you go through the official python tutorial: Le tutoriel Python — Documentation Python 3.13.2
It’s available in French and covers the basics of the language, as well as some more advanced topics. It’s really quite good.
So cool to help, thank you!
Of course, thank you Alexander, I’ll follow your advice!
The tutorial seems to be very complete indeed, it will keep me busy in terms of reading, thank you again!
I still remember writing my first scripts in mousepad, and running them from the terminal. It’s valuable experience I think.
At the same time I agree it’s easier in an IDE. Visual Studio Code is good.
my first scripts were written with notepad, not even notepad++! that’s a long time ago lol!
il y zvait déjà jquery there was already jquery and other cool stuff! )
short break, see you later,
time