CPython vs. Python, Same thing?


#1

Hello, I’m seriously considering Python as my next scripting language to learn. I figure I can eventually use it for XSI scripting and renderman .rib modification. I was wondering if CPython is just another way of saying Python (programmed in C). The reason I ask is that I only see CPython when people are comparing it to JPython. Also, has anyone found any difficulty in using Python as a file filter/parser in comparison to Perl or another language?


#2

I don’t know any real differences between C and Java based Python. I think yuo’d only notice if you were writing C or Java based modules to be accessed from Python, but someone ese may know more on this.

Personally for parsing files etc I find Perl slightly superior to Python as Perl’s regular expressions are easier to use and you do not really need objects too much. Perls data structures do take a while to get used to, but are very powerful when you do.

I have heard Python really comes into its own when doing GUI programming though.

Simon


#3

Currently, there’s 3 major python implementations: the original CPython, JPython (running under Java VM) and IronPython (for .net). If I understand correctly, XSI uses a variation of CPython which is python running under MS COM (kind of the granddaddy of .net).
CPython is indeed python coded in C, JPython is python coded and running under the Java VM, and IronPython is python coded in C# running under the .net environment.
CPython, being the oldest one, has the most libraries and runs under more platforms.
JPython should run anywhere where Java runs and has the advantage of being able to both use Java libraries as well as sending data back and forth with Java programs.
IronPython, the new kid on the block, offers something akin to JPython (was actually coded by the same guy that did JPython) but for the .net/mono framework.
CPython is considered the measuring stick of all other python implementations and is in general more up to date than the other ones. Recently, IronPython has been claiming as good and sometimes even better performance than CPython, while JPython in general is quite slower than either and often relegated to web work.
In general, what’s more important for you is likely to find out what version of python you are dealing with (ie. 2.1, 2.2, 2.3, etc) as some features may not be available.

To answer your second question, yes and no, depending on how picky you are. You will find that python has everything you need for parsing files. I think that the more you know Perl, the bigger your annoyance with python might end up being for file parsing.
The main difficulty of using python for file parsing (compared to Perl) is perhaps that its regular expressions are non-native to the language syntax, but are implemented thru classes. So, you will usually find that what is one line of Perl (or Ruby) usually requires a couple of lines of python.

Thus, in Perl, you can write code like:

 print $1,"
" if $line =~ /Attribute \"(\w+)\"/;

in Python, you are more or less forced to do something akin to:

import re 
attrRegex = re.compile(r"Attribute \"(\w+)\"")
m = attrRegex.search(line)
if m:
	 print m.group(1)

To avoid python’s quoting rules, you might also find yourself needing to type r"regex" (notice the ‘r’) instead of just /regex/ or “regex”.
You might also find that python’s regex engine is a tad slower than perl (albeit I think the difference now is hardly noticeable).
Another thing that you might miss if coming from Perl, is the lack of a pos() command/modifier. If you are slurping files into a single string and then running your regular expressions, you may find this much more tricky to do in python.


#4

Rendermaniac and gga, thank you for your replies. They were very helpful. gga I appreciate the detailed explanation for your answer to my question. I’ll have to look into IronPython for the .NET framework and see what that’s all about. Thanks again you guys.


#5

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.