[NFBCS] Seeking mentor

Joseph C. Lininger joe at pcdesk.net
Sun Jan 3 14:37:17 UTC 2021


Hi there,
Python is not like other programming languages in that you don't need to 
compile it before you can run it. The Python interpreter will 
byte-compile modules as needed. In fact, for larger programs, people 
will sometimes put the program code in a module and have the program 
people actually run be a small stub that calls the program module so 
that the program module will be byte-compiled. That doesn't change how 
fast it runs or anything, but having the pyc file does make startup 
faster. For normal use of python, though, you can run a Python script or 
program (those terms are subjective and somewhat interchangeable) by 
typing "python <yourfile>.py". Replace <yourfile> with the name of your 
Python file, of course. There is no command that I know of that will 
give you a pyc file from a py file; the interpreter produces them as 
needed. It will also regenerate the pyc file when necessary, like if you 
delete it or if the py file that generated it changes. The last thing to 
know about pyc files is that for your main program (the one you run when 
you start your program) the interpreter won't even produce a pyc file. 
Internally it will byte compile and run from memory, but it won't write 
a pyc file out to disk. It does that only for modules. That is, things 
you pull in using an import statement. You can generate a pyc file and 
run it directly, but there's no command to do it. It actually takes a 
bit of work to make that happen. In practice, having your the py file 
people run byte compiled at execution time and pyc files for any modules 
it pulls in (including those you write as part of your program) will 
work just fine.

A pyw file is something you see when working with Python programs 
designed to be run in Windows. A pyw file will run using pythonw.exe 
instead of python.exe. The execution environment is the same, the only 
difference is that a console window doesn't appear when a program is run 
using pythonw.exe. What you would probably do is to give most of the 
files in your program a .py extension, but give the main program (the 
one the users run to run your program) a .pyw extension if it has a GUI 
instead of a text interface so that the text console wouldn't load when 
the program is run. The other files that your pyw file pulls in will be 
byte compiled to pyc files by the interpreter anyway.

Producing an executable Python program, as in a .exe file is actually 
not a simple thing. First, you typically wouldn't even want to do this 
unless you had written something that you needed to distribute as an 
executable. The executable will be largish, and it won't be any faster 
than it would be if you ran the Python interpreter. IN fact, all the 
executable file is is a copy of the Python interpreter, your program, 
and all modules that your program needs in order to run. The program 
still runs at interpreted speeds. If you do want to build an executable, 
you need a library called pyinstaller. I can describe how to get it and 
use it if you want, but I recommend you play around with Python and get 
comfortable with it before you introduce that complication.
Joe

On 1/2/2021 11:12 AM, John J. Boyer via NFBCS wrote:
> Hello Joe,
>
> Well, I have some questions. I have written a Python program. How do I compile it to pyc byte code? What is pyw? How can I compile it into a free-standing program?
>
> Thanks,
> John
> On Sat, Jan 02, 2021 at 05:26:22AM -0500, Joseph C. Lininger via NFBCS wrote:
>> Good day,
>> I work professionally in the computer science field. I have projects I have
>> developed in both C++ and Python. (I've even used C and Python together
>> once.) I am happy to answer questions or provide guidance. Feel free to
>> contact me either on or off list.
>> Joe
>>
>> On 12/31/2020 12:50 PM, Rayn Darren via NFBCS wrote:
>>> Good morning all,
>>>
>>>
>>> I'm seeking a mentor for C/C++ and/or Python. I've tried to learn both on my
>>> own and have gotten nowhere fast. I know there are online learning platforms
>>> like codecademy and coursera but they're either inaccessible or are cost
>>> prohibitive. I'm looking to expand my skillset from font-end coding and web
>>> development and thought that C/C++ and/or Python would be a good place to
>>> start. If I'm walking down an improper path as well, I'd appreciate a bit of
>>> guidance as well.
>>>
>>>
>>> Thank you,
>>>
>>> Sarah Hale
>>>
>>> Work: 714.852.3238
>>>
>>> Email:<mailto:sarah.hale at siteweaver.org>  sarah.hale at siteweaver.org
>>>
>>>
>>>
>>> _______________________________________________
>>> NFBCS mailing list
>>> NFBCS at nfbnet.org
>>> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
>>> To unsubscribe, change your list options or get your account info for NFBCS:
>>> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/joe%40pcdesk.net
>> _______________________________________________
>> NFBCS mailing list
>> NFBCS at nfbnet.org
>> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
>> To unsubscribe, change your list options or get your account info for NFBCS:
>> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/john.boyer%40abilitiessoft.org




More information about the NFBCS mailing list