9 Replies - 813 Views - Last Post: 07 October 2020 - 06:49 AM Rate Topic: -----

#1 codelrnr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 24-May 18

Python general question

Posted 01 October 2020 - 06:32 AM

Hi,

I'm slow at learning/understanding programming. I just have a general question about programming (Python in particular) as I have never found this kind of information in my study resources, and it irritates me. My question is: how would I be able to code a program that literally runs on my native machine I'm programming in? Dumb question, I know! It hit me last night that, I'm coding in my editor(s), but I don't know how to run these programs outside of it (something that would run on my machine, right?). I want to write a simple greeting message in Python, the famous time-based ones (aren't they all?), and I want it to run on my machine anytime of day based on the correct code for this (not asking for the code). Is this where converting the Python file to some .exe would come in, or is this done a completely different way. I keep hearing "You can pretty much do anything with programming to a computerized device", so I should be able to run programs on my machine, right? By the way, if I can pick someone's brain further, what if I wanted to write a program that saves, opens files on my machine, would that require learning the native code in my OS, and the programming code communicate with this? Appreciate the help, and pointers to resources that can answer these questions. Thank you! =).

Is This A Good Question/Topic? 0
  • +

Replies To: Python general question

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15927
  • View blog
  • Posts: 63,731
  • Joined: 12-June 08

Re: Python general question

Posted 01 October 2020 - 07:00 AM

Python is an interpreted language. No compiling needed.

If you have the python package installed on your machine, so as you can write and run python. You would run the script in a few different ways.

ex: https://realpython.c...python-scripts/


Quote

what if I wanted to write a program that saves, opens files on my machine, would that require learning the native code in my OS, and the programming code communicate with this?

No, not really. A given language usually has routes for file manipulation without knowing the 'native code in an os'.
Was This Post Helpful? 0
  • +
  • -

#3 Radius Nightly   User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 419
  • Joined: 07-May 15

Re: Python general question

Posted 01 October 2020 - 07:07 AM

Writing a core is just a text, been able to run that text requires something that knows how to read it and what to do, means if its Python text, you need Python. Thats why codes need to be compiled, to get optimized, to run better and to have its base for the OS, so EXE would run on Windows OS, but not on Unix, or it can be run with emulators.
In a same way, games gets compiled for Windows OS, for Android, for Apple OS and for other systems. Each system are different system for itself, and programmer should know what he is doing, if its a game, lots of classic things happening, such as 3D models, but since different OS works differently, you will compiling it in some way.
Some languages can run in native, but again, you need to have something that can understand the code. For example, you can code in Java and play it on old Nokia phone, but Nokia need to have Java API in itself, to understand the code in first place. Since there are like 200 operating systems out there, some languages focus to trully works everywhere, including some strange 67bit systems, by compiling a code to computer language, optimize it and in the same executable file adding API, or engine for the OS you choose, so you get single file that contains everything, including original code sometimes, engine, API, etc., that you can put on your strange system and launch it without problems.

This post has been edited by Radius Nightly: 01 October 2020 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

#4 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 590
  • View blog
  • Posts: 1,884
  • Joined: 27-December 13

Re: Python general question

Posted 01 October 2020 - 07:23 AM

Just an addendum to the already provided answers:

If you make the code in python you can convert to .exe by fx "py2exe" or "pyinstaller" - they are both libraries you can download - I find them relatively easy to use.

The exe-files will execute on the Windows platform and do not require python installed.

There are some limitation on what can be converted (e.g. some programs made with 'pygame' may not work - depending on the functionalities used).
You may need to lookup some details, but as I have mentioned: It is relatively easy.
Was This Post Helpful? 1
  • +
  • -

#5 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 12076
  • View blog
  • Posts: 20,477
  • Joined: 19-March 11

Re: Python general question

Posted 01 October 2020 - 07:50 AM

View Postcodelrnr, on 01 October 2020 - 08:32 AM, said:

My question is: how would I be able to code a program that literally runs on my native machine I'm programming in? Dumb question, I know! It hit me last night that, I'm coding in my editor(s), but I don't know how to run these programs outside of it (something that would run on my machine, right?).

I may be missing something but I think you're asking "how do I run a python program?"
If so: In general, if program.py is the name of a syntactically correct python program located in some directory, executing the command python program.py from the same directory that program.py is located in.

There are probably also mouse-driven ways to execute python programs, these will be OS-bound, check your documentation. Also, many IDEs provide shortcuts for running the code you're working on. Again, check your documentation
Was This Post Helpful? 1
  • +
  • -

#6 codelrnr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 24-May 18

Re: Python general question

Posted 05 October 2020 - 07:16 AM

View PostDK3250, on 01 October 2020 - 07:23 AM, said:

Just an addendum to the already provided answers:

If you make the code in python you can convert to .exe by fx "py2exe" or "pyinstaller" - they are both libraries you can download - I find them relatively easy to use.

The exe-files will execute on the Windows platform and do not require python installed.

There are some limitation on what can be converted (e.g. some programs made with 'pygame' may not work - depending on the functionalities used).
You may need to lookup some details, but as I have mentioned: It is relatively easy.


Hi. I think I understand your response best. I simply want to run the scripts outside of the editor I'm coding in (independent of), which logically to me, means converting the script files into some sort of exe file. Thank you!
Was This Post Helpful? 0
  • +
  • -

#7 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1050
  • View blog
  • Posts: 4,014
  • Joined: 13-June 14

Re: Python general question

Posted 05 October 2020 - 09:45 PM

Actually, no, the simplest thing to do is what Jon posted. No need to create an executable.

I'm curious how you've been learning if you say you've not been shown how to run a program in any of your learning materials.
Was This Post Helpful? 1
  • +
  • -

#8 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 590
  • View blog
  • Posts: 1,884
  • Joined: 27-December 13

Re: Python general question

Posted 06 October 2020 - 12:56 AM

The way I understand it, OP does know how to make python programs and has python installed.
He wants to distribute a finished program to people (friends, family) who do not have python installed.
Thus the need of executable versions.

@codelrnr, please confirm.
Was This Post Helpful? 1
  • +
  • -

#9 codelrnr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 24-May 18

Re: Python general question

Posted 07 October 2020 - 06:20 AM

View PostDK3250, on 06 October 2020 - 12:56 AM, said:

The way I understand it, OP does know how to make python programs and has python installed.
He wants to distribute a finished program to people (friends, family) who do not have python installed.
Thus the need of executable versions.

@codelrnr, please confirm.


You are correct, DK3250. Particularly, I'm trying to understand how I would run (and I' guessing this is where the code would come in) a Python program on my machine without running it from my editor, the CLI, for example, a greeting program (that I mentioned before) with morning, afternoon, evening greetings for me that, would run anytime I boot my machine (if it was evening time, the evening greeting would pop up per timing intervals in the code), but independent of me running it from my editor, CLI (the only way I'm running programs currently). And, more to DK3250's reply, what if I wanted to port (share) the programs with others, wouldn't the py files have to be converted to exe files for sharing them? Maybe this is all in my head (the thought that I can't seem to escape my editor for running programs). =). Thank you!
Was This Post Helpful? 0
  • +
  • -

#10 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 590
  • View blog
  • Posts: 1,884
  • Joined: 27-December 13

Re: Python general question

Posted 07 October 2020 - 06:49 AM

If python is installed on the computer, you do not have to make an exe file (you should not).
Just ensure that the path to the python directory is included in your environment settings, then it is enough to call the .py file in the start code.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1