LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Does Python 2.4 compile? (https://www.linuxquestions.org/questions/programming-9/does-python-2-4-compile-533557/)

phantom_cyph 03-01-2007 05:49 AM

Does Python 2.4 compile?
 
If I write a program in Python, can it compile?

ghostdog74 03-01-2007 08:08 AM

you just run your script using the Python interpreter
Code:

/usr/bin/python yourscript.py

tuxdev 03-01-2007 08:24 AM

I believe you can compile a python script. Don't really know the particulars, though.

uselpa 03-01-2007 02:40 PM

Basically, no.

reddazz 03-01-2007 03:04 PM

Quote:

Originally Posted by uselpa
Basically, no.

You can compile python programs into c type files. Unfortunately I don't know how to do this, so can't be of much help.

rshaw 03-01-2007 03:22 PM

http://www.python.org/ftp/python/wpy/freeze.txt

not sure why you would bother though.

taylor_venable 03-01-2007 03:31 PM

Define "Compile"
 
Technically, every time you run a Python program, it's compiled into bytecodes which are then interpreted by the virtual machine. When modules are called from scripts, they are oftentimes compiled and then their bytecodes are written to .pyc files for fast loading later on. Googling turns up a page about this straight away. The idea is similar to byte-compiling Lisp code. Perl works this way as well, it's just that Perl doesn't write its bytecodes to files (by default).

But you're probably thinking more along the lines of native binary compilation?

phantom_cyph 03-01-2007 04:45 PM

OK-but I want to write programs that I can open later. I have had some (as in very little) experience with C++ and know HTML pretty well. (I know HTML isn't really a programming language but I thought I'd throw it in...)

taylor_venable 03-01-2007 04:56 PM

Oh, you mean as opposed to typing them into the REPL? (In other words, the interactive prompt?) Yes, just type your program into a file (use a .py extension) and then run `python name-of-file` to run the program. Or, alternatively, at the start of the file write "#!/usr/bin/env python" and make the file executable with `chmod +x name-of-file` and run it like any other command from the shell (not available in Windows). You'll probably have to put the directory in front of it, like so: `./name-of-file`

phantom_cyph 03-01-2007 05:30 PM

What is Ruby like? And is KDevelop: Ruby the actual program in which to create it?

taylor_venable 03-01-2007 08:54 PM

Ruby is a fantastical programming language. To sum up its virtues in one word: abstraction. I'd say, the best way to decide if you like it is to give it a shot.

And by the way, decent programming languages are not tied to IDEs -- if you want to write Ruby in KDevelop, go ahead. I use Emacs for editing everything and then run stuff from the shell (or actually, from Emacs' shell mode, but they're still standalone commands). You can really learn a lot about how stuff works by doing things from the CLI instead of relying on IDE magick.

phantom_cyph 03-01-2007 09:02 PM

Where can I get a tutorial on it?

uselpa 03-02-2007 12:48 AM

Quote:

Originally Posted by reddazz
You can compile python programs into c type files. Unfortunately I don't know how to do this, so can't be of much help.

I suppose you talk about Shed Skin.

There are various attempts at compiling Python to machine code, but they are either incomplete, or they package the interpreter with the Python program in one way or another.

That's why I say basically, No.
AFAIK, the same goes for Ruby.

billiejoex 03-02-2007 03:10 AM

You can use py2exe on Windows and PyInstaller on Linux.
Both programs 'compiles' python scripts into 'stand alone executables'.

uselpa 03-02-2007 04:43 AM

Quote:

Originally Posted by billiejoex
You can use py2exe on Windows and PyInstaller on Linux.
Both programs 'compiles' python scripts into 'stand alone executables'.

True, but then again if you use that on more than one program you end up installing multiple partial copies of the Python interpreter. Doesn't make any sense IMHO.


All times are GMT -5. The time now is 12:38 AM.