Products > Programming

Beginning Python Question

(1/3) > >>

bostonman:
Sometime ago I began tinkering with Python a bit by installing it on an old XP machine.

I noticed that it installed a 'command line' and a 'GUI'. Both of these seem to be the same thing except one is in a DOS window and the other is an actual Window. In both cases, it seems typing print("Hello World") gets 'Hello World' printed on the screen, but seems it's not a line-by-line list of code that I can save.

Using Notepad++ allows me to type multiple lines of code, save it as 'file.py' and, if I click on it, will execute. Unless I type #input('Press Enter to Exit...') at the end, the window opens and closes at the blink of an eye.

Up to now, think I'm doing things correctly. The problem seems to be, when I type many lines of code (ideally five or six because I'm just a beginner), and a line or lines contain an error, all I get is the flash of a window executing the program.

The little C that I know involves something like Visual Studio, compiling, and, if an error exists, it will report which line(s) have errors without successfully compiling. Obviously it's not always an ideal error statement, but it helps know where the program is having issues.

I'm looking for some initial guidance to understanding the setup for Python or how to type code and know if I'm typing errors. Up till now, I've placed the #input('Press Enter to Exit...') statement after a line, run the program, if the window doesn't blink open and then close, I move the statement after the next line, so on and so on.

Obviously an easier way must exist. Also, after I create a file.py, how do I make it so it can't be edited? Again, with C, it's compiled, so you can't really take the .exe and see the list of C code.

retiredfeline:
You can use VS to develop in Python, just install the appropriate addons.

Ian.M:
You probably should use IDLE, the Python IDE.   Its got a shell for executing Python code, an editor with syntax highlighting, a debugger + various other stuff.  N.B. on Linux it doesn't install by default with Python so you may need to install it, maybe with: sudo apt-get install idle or whatever your distro uses to install packages.

The idea of using MS Visual Studio for Python, (except if you are trying to integrate with compiled code in a MS centric language) is abhorrent!  |O

retiredfeline:
Why would it be abhorrent? VS is open source and cross-platform, and supports lots of programming environments. including some embedded platforms. It's not MS lock-in.

newbrain:

--- Quote from: retiredfeline on March 17, 2022, 04:15:13 am ---VS is open source

--- End quote ---
Nope, not in the least.
You are thinking of Visual Studio Code,  which is open source-ish (if you get the binaries, OpenSource if get the code or VS Codium).

That said both VS (the community edition is free to use) and VSC are excellent IDEs to develop in Python.

The elephant in the room here is XP: I think neither runs on XP, and I'd have some doubts even with Windows 7.
Any editor will do, notepad++ is fine too, especially at the beginning. As you progress to more complex stuff, though, you'll really want something more integrated.

If the OP cannot use a better OS (W7, W10, a [d|r]ecent Linux for VSC), Idle probably still runs on XP.
To avoid the flashing cmd window issue, just launch the python program from an already opened one.

Edit: added links to Code, VS Codium and Visual Studio.
According to its System Requirements, VS Code state is supported from Windows 8 onwards.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod