Python Forum

Full Version: How do i run python code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i received the attached code and downloaded python. I've pasted it into the python window that looks like a cmd window. Is that what I should do? It gives a bunch of IndentationError: unexpected indent errors though.

Thanks
There are many ways. One of them is to open the Python file in a Python IDE, then choose run in a menu or use a shortcut. You could install thonny for example and open the file in thonny.
(Mar-05-2025, 04:50 PM)Gribouillis Wrote: [ -> ]There are many ways. One of them is to open the Python file in a Python IDE, then choose run in a menu or use a shortcut. You could install thonny for example and open the file in thonny.

Thanks. What is the difference between thonny and pycharm?
(Mar-05-2025, 05:08 PM)smattiko83 Wrote: [ -> ]What is the difference between thonny and pycharm?
Thonny is an IDE for beginners. There are many many IDEs for Python. You can also program Python by using only a simple editor as I usually do. Then you can run your programs from the command line by typing something like python myscript.py
(Mar-05-2025, 04:08 PM)smattiko83 Wrote: [ -> ]Hi, i received the attached code and downloaded python. I've pasted it into the python window that looks like a cmd window. Is that what I should do? It gives a bunch of IndentationError: unexpected indent errors though.

Thanks
(Mar-05-2025, 04:08 PM)smattiko83 Wrote: [ -> ]Hi, i received the attached code and downloaded python. I've pasted it into the python window that looks like a cmd window. Is that what I should do? It gives a bunch of IndentationError: unexpected indent errors though.

Thanks

Indent errors are just as described... Unlike many other languages, Python is highly dependent upon proper indentation. There's a good chance that adding a stray space (" ") - or the accidental deletion of a single space - somewhere has thrown things off kilter.

Are you getting info about which specific line (or lines) are invoking the indentation errors? If so, that's where the culprit(s) will be lurking.