Re: Any pointers/advice to help learn CPython source?

2006-05-19 Thread sébastien
There is also an interesting pep which describe the front-end

http://www.python.org/dev/peps/pep-0339/

It doesn't explain the whole things, but it gives few hints where to
start to read the code. BTW, the main difficulty is that there are fat
C files and you should ask yourself what do you want to learn, because
instead it can be interesting to read the compiler module or to look at
pypy source code. Obviously if your motivations are to understand some
internals of CPython you want to study CPython ! lol

-- 
sébastien  
http://seb.dbzteam.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any pointers/advice to help learn CPython source?

2006-05-18 Thread [EMAIL PROTECTED]
Wow thanks for your detailed reply.  Mainly I just wanted to understand
the theory and ideas needed to make an interpreter.  Your directory
description helped.

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any pointers/advice to help learn CPython source?

2006-05-18 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> Anyone have any good advice to someone interested in learning about
> innards of Python implementation?
>
> e.g. What is best place to start?
>
>Where can I get a 10,000 ft. overview of general structure?
>
>Anyone written docs on helping do this?
>
>How did other people successfully make it through?

Depends on what you want to get out of it.  There are only a handful of
top level directories that are interesting:

 Include - include files
 Objects - all Python objects (list, dict, int, float, functions, and
many others)
 Python - core interpreter and other support facilities

 Lib - Python stdlib (Lib/test is the test suite)
 Modules - C extension modules
 Parser - simple parser/tokenizer

The last three probably aren't interesting.  However, if you are
interested in the GC (or SRE) implementation, then you should look
under Modules as gcmodule.c and _sre.c are there.  So are a bunch of
others.

Include/ isn't particularly interesting.  Objects/ isn't too
interesting either from the standpoint of learning about the
interpreter.  Although the object implementations may be interesting in
their own right.  Each object is in an unsurprising file named
something like:  listobject.c or intobject.c.

That leaves Python/ which is where the real innards are.  If you are
interested in the interpreter, then Python/ceval.c is pretty much it.
The compiler is primarly in Python/compile.c, but also see Python/ast.c
(2.5 only) and Python/symtable.c.  All the global builtin functions are
in Python/bltinmodule.c.  Import support is in Python/import.c.  Most
of the other files in Python/ are small and/or platform specific.  They
probably aren't as interesting in general.

n

-- 
http://mail.python.org/mailman/listinfo/python-list


Any pointers/advice to help learn CPython source?

2006-05-17 Thread [EMAIL PROTECTED]
Anyone have any good advice to someone interested in learning about
innards of Python implementation?

e.g. What is best place to start?

   Where can I get a 10,000 ft. overview of general structure?

   Anyone written docs on helping do this?

   How did other people successfully make it through?

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between CPython, Python for .NET and IronPython?

2006-02-20 Thread Ian Bicking
Claudio Grondi wrote:
> I have asked similar 'question' some weeks ago in the German Python
> newsgroup.
> It seems, that that Pythonistas have generally not much interest in
> IronPython waiting for at least release 2.0 of it which is _perhaps_
> expected to support Mono.

My understanding is that Mono developers are trying to make each
release of Mono support whatever the last release of IronPython was.
So there might be a lag, or you have to run a version behind, to use
Mono.  But it is supported.  At least, I think I read something to that
effect in the IronPython archives; I haven't tried it.

My more vague impression is that most Python people are happy enough
with CPython (because they better be happy, because that's what we've
had), and at least people like myself dread nothing more than trying to
install software or platforms.  I suppose there's also a group who are
interested in these interpreter/runtime level issues, but are working
away on PyPy.  PyPy has stolen away at least one major developer from
Jython (though in all fairness I think he'd mostly left anyway).

That said, I think concrete instructions on exactly how to get
IronPython up and working -- for someone with no .NET experience or
familiarity with that toolset -- would be an excellent way to bring
more attention to IronPython from the existing Python community.

  Ian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between CPython, Python for .NET and IronPython?

2006-02-18 Thread Diez B. Roggisch
> For example, if I'm running IronPython, can I access modules such as Numeric
> and numarray?

AFAIK not. You can run pure python modules, but not extensions 
containing native code.

> As I understand it, interoperability with C# and .NET works in both
> directions with IronPython, but CPython modules cannot be imported, or? 

If they are pure python they can. However, there isn't e.g. a os-module 
in IronPython (at least on mono under MacOSX) - so I guess the situation 
is similar to Jython: you are basically limited to what the host-runtime 
delivers.

> With Python for .NET I can import the .NET Framework and continue using
> CPython modules, or?

Yes. It's a bridge. Problem is: you can't use Python-Objects in 
.NET-code, which is at least theoretically possible in IronPython (not 
sure if it has something like the jythonc of jython that makes that 
possible for jython, or if it can be done more automagically)

> 
> What is the roadmap for IronPython, will it be possible to import CPython
> modules in the near future?

I doubt it - it's just not the goal, after all you want the CLR 
precisely for _not_ needing bindings for C-libs on various platforms. 
However, I guess a goal is that you get all python modules in IronPython 
that are availablein the standard dist to make pure-python modules run 
out of the box. But I don't have any insights on that.

> One last question, is IronPython cross-platform. That is, can I use
> IronPython with Mono?


Yes, I did so under mono/MacOSX.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between CPython, Python for .NET and IronPython?

2006-02-18 Thread Claudio Grondi
Carl Johan Rehn wrote:
> What is the difference between CPython, Python for .NET, and IronPython?
> 
> For example, if I'm running IronPython, can I access modules such as Numeric
> and numarray?
>  
> As I understand it, interoperability with C# and .NET works in both
> directions with IronPython, but CPython modules cannot be imported, or? 
> 
> With Python for .NET I can import the .NET Framework and continue using
> CPython modules, or?
> 
> What is the roadmap for IronPython, will it be possible to import CPython
> modules in the near future?
> 
> One last question, is IronPython cross-platform. That is, can I use
> IronPython with Mono?
> 
> Carl
I have asked similar 'question' some weeks ago in the German Python 
newsgroup.
It seems, that that Pythonistas have generally not much interest in 
IronPython waiting for at least release 2.0 of it which is _perhaps_ 
expected to support Mono.
It seems, that usage of IronPython is currently limited to Windows 
platform, but I was not able to attract any expert on it to give a clear 
answer to that.
My own short test has shown, that compiled DLLs (extension modules) 
don't work in IronPython and the created .exe-s of simple Python scripts 
fail to run.
Curious to hear if there will be any expert response to your posting 
here (except replies from people like me, who have no idea about the 
subject themselves).

Claudio
-- 
http://mail.python.org/mailman/listinfo/python-list


Difference between CPython, Python for .NET and IronPython?

2006-02-18 Thread Carl Johan Rehn
What is the difference between CPython, Python for .NET, and IronPython?

For example, if I'm running IronPython, can I access modules such as Numeric
and numarray?
 
As I understand it, interoperability with C# and .NET works in both
directions with IronPython, but CPython modules cannot be imported, or? 

With Python for .NET I can import the .NET Framework and continue using
CPython modules, or?

What is the roadmap for IronPython, will it be possible to import CPython
modules in the near future?

One last question, is IronPython cross-platform. That is, can I use
IronPython with Mono?

Carl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding a CPython Script engine in a .NET application.

2005-11-23 Thread Martin v. Löwis
Carl Waldbieser wrote:
> Has anyone had any experience embedding a CPython engine in a .NET
> application?  In the COM/ActiveX world, it was pretty easy to use Mark
> Hammond's win32 modules to create a script engine component that you could
> expose other COM objects to, but I was not sure how I would go about doing
> something similar in a .NET environment.

I don't have experience with this specific problem, but in general,
.NET is really good at calling COM objects (in fact, this was
historically the sole reason for creating .NET: to make COM better
usable).

So just import, in VS.NET, the Python interpreter to your project
(Add Reference), and use the C# functions that the COM interop
code gives you.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedding a CPython Script engine in a .NET application.

2005-11-23 Thread Carl Waldbieser
Has anyone had any experience embedding a CPython engine in a .NET
application?  In the COM/ActiveX world, it was pretty easy to use Mark
Hammond's win32 modules to create a script engine component that you could
expose other COM objects to, but I was not sure how I would go about doing
something similar in a .NET environment.  For example, something like:

... .NET Application code ...
'Create Foo object.
set Foo = New Foo("baz")
'Create embedded cpython script engine.
set engine = New CPythonEngine()
'Expose Foo object to engine.
engine.AddNamedItem(Foo, "Foo")
'Load python script.
engine.LoadScript("D:\scripts\frotz.py")
'Run script (uses Foo).
engine.Run()
'Get results'
set resultsCollection = engine.getResults()

Is something like this possible, or am I thinking about things the wrong
way?

I am mainly interested in knowing if this is possible with cpython, as I
understand IronPython is currently in beta.

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JPype and classpath (Was Re: embedding jython in CPython... )

2005-01-23 Thread Steve Menard
[EMAIL PROTECTED] wrote:
Thanks for the response. However, I continue to have problems. Allow me
to give some more detail.
For simplicity of testing, I hard coded the classpath and JVM path
(BTW getDefaultJVMPath() returns None on my system)
import os, os.path
from jpype import *
startJVM("C:/jdk1.5.0/jre/bin/client/jvm.dll",
"-Djava.class.path=D:/Temp/classes")
...
shutdownJVM()
I have setup a classes folder in the script folder (D:/Temp) and have
placed test.class in it.
I run the script from the script folder (working directory is the same
as script's root path in this case)
Now how do I load the class test? I am afraid I cannot make that out
from the docs.
The simple test class is
public class test
{
public int i = 100;
}
What do I have to do before I can write
test().i
?
Thank you for your time.
About the getDefaultJVMPath(), could you send me your system 
information? On windows, JPype uses the contents of the registry to find 
the JVM. Of course, the usefulness of this mechanism is limited byt he 
sample of configurations i can test (I have only one machine). So any 
info you can provide me on yours can only help.

About the classpath. JPype 0.4 currently cannot import classes that are 
in the "default" package. The fix is easy, simply put your "test" class 
in a package. For exmaple, if you put the class in the package "test", 
the code to load it would be :

test = jpype.JPackage("test").test
--
Steve Menard

Maintainer of http://jpype.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: JPype and classpath (Was Re: embedding jython in CPython... )

2005-01-23 Thread johng2001
Thanks for the response. However, I continue to have problems. Allow me
to give some more detail.

For simplicity of testing, I hard coded the classpath and JVM path
(BTW getDefaultJVMPath() returns None on my system)

import os, os.path
from jpype import *

startJVM("C:/jdk1.5.0/jre/bin/client/jvm.dll",
"-Djava.class.path=D:/Temp/classes")
...
shutdownJVM()


I have setup a classes folder in the script folder (D:/Temp) and have
placed test.class in it.
I run the script from the script folder (working directory is the same
as script's root path in this case)

Now how do I load the class test? I am afraid I cannot make that out
from the docs.

The simple test class is
public class test
{
public int i = 100;
}


What do I have to do before I can write
test().i
?

Thank you for your time.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding jython in CPython...

2005-01-22 Thread Jim Hargrave
> I am curious to know what makes your Jython code incompatible with
> CPython. If it is only because it uses Java classes, it might
> not be too
> difficult to port them to CPython+Jpype.
CPython+Jpype may indeed be the way to go in the long run - it's only my 
ignorance stoping me at this point :-) I'll code some tests and give it 
a whirl. Thanks for the help!
--
http://mail.python.org/mailman/listinfo/python-list


Re: embedding jython in CPython...

2005-01-22 Thread Steve Menard
Jim Hargrave wrote:
Sorry - should have given more detail.  That's what I get for posting at 
1:00AM.

What I want to do us write scripts in CPython that access Windows 
ActiveX such as Word and IE. Obviously Jython can't do this (easily at 
least). I also have Jython scripts that provide a high level layer on 
top of various Java libraries. I'd like to write as much code in Python 
as possible. But I have a mixture of incompatible CPython and Jython 
scripts - that's why I would like to embed Jython in CPython. If I can 
call my Jython scripts from CPython I can have the best of both world's!

Would I be able to embed Jython using JPype? The PyLucene approach 
(compile Java source with GCJ then wrap with SWIG) looks interesting - 
but complicated.

Here's an example of embedding Jython in a regular Java app:
http://www.jython.org/docs/embedding.html
Imagine doing the same in CPython, but with JPype or GCJ/SWIG.

Certainly! As far as JPype is concerned though, Jython is just another 
library. What I mean is, the API to lauch your Jython scripts will be 
identical JPype as though coded in Java. There will be no "magic" to 
bridge CPython and Jython.

The obvious advantage of going that way though, instead of the GCJ 
approach, is that you keep the full dynamicity of Jython.

I am curious to know what makes your Jython code incompatible with 
CPython. If it is only because it uses Java classes, it might not be too 
difficult to port them to CPython+Jpype.

Let me know if you need any help.
--
Steve Menard

Maintainer of http://jpype.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


JPype and classpath (Was Re: embedding jython in CPython... )

2005-01-22 Thread Steve Menard
While we are on topic, I am having some trouble understanding JPype
classpath. How do I init the JVM with the folder in which the Python
program is located included in the classpath?
I tried
t = JPackage('.').test
That did not work.
My environment variable includes current folder in the classpath
I tried passing it as an argument to startJVM. Didn't help.
I think my main use is going to be using CPython with a few Java custom
classes and if anyone has a snippet on this it would really help me.
Thanks
That's easy.
First realise that "." denotes the current working directory, not the 
"directory where the python program is located".

Second, JPackage uses Java package names.
So, assuming you java classes are properly stord in a directory called 
"classes" at the same level as your python script (see how java looks up 
classes on the filesystem for what "properly" means), here is a snippet 
that will do what you wanted :

#==
import os, os.path, jpype
root = os.path.abspath(os.path.dirname(__file__))
jpype.startJVM(jpype.getDefaultJVMPath(),
"-Djava.class.path=%s%sclasses" % (root, os.sep))
#==
Or alternately, if the Java classes you want to use ar in JAR files, in 
a lib directory at the same level as your python script :

#==
import os, os.path, jpype
root = os.path.abspath(os.path.dirname(__file__))
jpype.startJVM(jpype.getDefaultJVMPath(),
"-Djava.ext.dirs=%s%slib" % (root, os.sep))
#==
The magic in the above script is the __file__ variable, which stores the 
absolute path to the currently executing Python script. If you have both 
situation (you classes in the classes directory and some JARS containing 
stuff that they uses) you can combine the above :

#==
import os, os.path, jpype
root = os.path.abspath(os.path.dirname(__file__))
jpype.startJVM(jpype.getDefaultJVMPath(),
"-Djava.class.path=%s%sclasses" % (root, os.sep),
"-Djava.ext.dirs=%s%slib" % (root, os.sep))
#==
Hopefully this will help.
--
Steve Menard

Maintainer of http://jpype.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: embedding jython in CPython...

2005-01-22 Thread Jim Hargrave
Sorry - should have given more detail.  That's what I get for posting at 
1:00AM.

What I want to do us write scripts in CPython that access Windows 
ActiveX such as Word and IE. Obviously Jython can't do this (easily at 
least). I also have Jython scripts that provide a high level layer on 
top of various Java libraries. I'd like to write as much code in Python 
as possible. But I have a mixture of incompatible CPython and Jython 
scripts - that's why I would like to embed Jython in CPython. If I can 
call my Jython scripts from CPython I can have the best of both world's!

Would I be able to embed Jython using JPype? The PyLucene approach 
(compile Java source with GCJ then wrap with SWIG) looks interesting - 
but complicated.

Here's an example of embedding Jython in a regular Java app:
http://www.jython.org/docs/embedding.html
Imagine doing the same in CPython, but with JPype or GCJ/SWIG.

--
http://mail.python.org/mailman/listinfo/python-list


Re: embedding jython in CPython...

2005-01-22 Thread johng2001
> As for using JPype ... well it depends on what you want to script. if

> you Java code is the main app, I'd eschew CPython completely and use
> Jython to script. If you main app is in Python, and the Java code is
> "simply" libraries you wish to use, then I'f go with CPython + Jpype.
It
> is very easy to manipulate Java objects that way, even to receive
callbacks.
>
> I guess it all comes down to what you mean by scripting, and exaclt
what
> the structure of your application (as far as what is java and
non-java).
> If you care to explain your situation a bit more, we'll be better
able
> to help you.
>
> Steve Menard
> Maintainer of http://jpype.sourceforge.net

While we are on topic, I am having some trouble understanding JPype
classpath. How do I init the JVM with the folder in which the Python
program is located included in the classpath?

I tried
t = JPackage('.').test

That did not work.

My environment variable includes current folder in the classpath

I tried passing it as an argument to startJVM. Didn't help.

I think my main use is going to be using CPython with a few Java custom
classes and if anyone has a snippet on this it would really help me.
Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding jython in CPython...

2005-01-22 Thread Steve Menard
Jim Hargrave wrote:
I've read that it is possible to compile jython to native code using 
GCJ. PyLucene uses this approach, they then use SWIG to create a Python 
wrapper around the natively compiled (java) Lucene. Has this been done 
before for with jython?

Another approach would be to use JPype to call the jython jar directly.
My goal is to be able to script Java code using Jython - but with the 
twist of using Cpython as a glue layer. This would allow mixing of Java 
and non-Java resources - but stil do it all in Python (Jython and Cpython).

I'd appreciate any pointers to this topic and pros/cons of the various 
methods.


Well now that IS getting kinda complicated ...
AS far a natively compiling Jython scripts ... well, if you natively 
compile them, it'll hard to "script" you java code afterward (I assume 
by scripting you mean loading scripts at runtime that were not know at 
compile time).

As for using JPype ... well it depends on what you want to script. if 
you Java code is the main app, I'd eschew CPython completely and use 
Jython to script. If you main app is in Python, and the Java code is 
"simply" libraries you wish to use, then I'f go with CPython + Jpype. It 
is very easy to manipulate Java objects that way, even to receive callbacks.

I guess it all comes down to what you mean by scripting, and exaclt what 
the structure of your application (as far as what is java and non-java). 
If you care to explain your situation a bit more, we'll be better able 
to help you.

Steve Menard
Maintainer of http://jpype.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


embedding jython in CPython...

2005-01-22 Thread Jim Hargrave
I've read that it is possible to compile jython to native code using 
GCJ. PyLucene uses this approach, they then use SWIG to create a Python 
wrapper around the natively compiled (java) Lucene. Has this been done 
before for with jython?

Another approach would be to use JPype to call the jython jar directly.
My goal is to be able to script Java code using Jython - but with the 
twist of using Cpython as a glue layer. This would allow mixing of Java 
and non-Java resources - but stil do it all in Python (Jython and Cpython).

I'd appreciate any pointers to this topic and pros/cons of the various 
methods.

--
http://mail.python.org/mailman/listinfo/python-list


<    2   3   4   5   6   7