473,890 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is a "real" C-Python possible?

I understand that the standard Python distribution is considered
the C-Python. Howerver, the current C-Python is really a combination
of C and Python implementation. There are about 2000 Python files
included in the Windows version of Python distribution. I'm not sure
how much of the C-Python is implemented in C but I think the more
modules implemented in C, the better performance and lower memory
footprint it will get.

I wonder if it's possible to have a Python that's completely (or at
least for the most part) implemented in C, just like PHP - I think
this is where PHP gets its performance advantage. Or maybe I'm wrong
because the core modules that matter are already in C and those Python
files are really a think wrapper. Anyhow, if would be ideal if Python
has performance similar to Java, with both being interpreted languages.

Jack
Dec 9 '07
71 3398
Kay Schluehr wrote:
class A(object):
foo = property:
def fget(self):
return self._foo
def fset(self, value):
self._foo = value

which was translated as follows:

class A(object):
def thunk():
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
return vars()
foo = propery(**thunk ())
del thunk
Python 2.6 and 3.0 have a more Pythonic way for the problem:

class A(object):
@property
def foo(self):
return self._foo

@foo.setter
def foo(self, value)
self._foo = value

@foo.deletter
def foo(self)
del self._foo

class B(A):
# one can even overwrite the getter in a subclass
@foo.getter
def foo(self):
return self._foo * 2

Christian

Dec 12 '07 #51
On Dec 12, 4:09 am, Kay Schluehr <kay.schlu...@g mx.netwrote:
I vaguely remember a discussion a few years ago, where someone made
the quite reasonable suggestion of introducing some kind of
thunk_statement :

class A(object):
foo = property:
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
That's almost identical to a recipe I had written once upon a time,
without requiring a syntax change: http://aspn.activestate.com/ASPN/Coo.../Recipe/410698

George
Dec 12 '07 #52
On Dec 12, 1:12 pm, Christian Heimes <li...@cheimes. dewrote:
Kay Schluehr wrote:
class A(object):
foo = property:
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
which was translated as follows:
class A(object):
def thunk():
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
return vars()
foo = propery(**thunk ())
del thunk

Python 2.6 and 3.0 have a more Pythonic way for the problem:

class A(object):
@property
def foo(self):
return self._foo

@foo.setter
def foo(self, value)
self._foo = value

@foo.deletter
def foo(self)
del self._foo

class B(A):
# one can even overwrite the getter in a subclass
@foo.getter
def foo(self):
return self._foo * 2

Christian
This is by definition Pythonic since it was conceived by the BDFL.It
is also certainly an improvement over the current common practice of
polluting the class namespace with private getters and setters. Still
it's a kludge compared to languages with builtin support for
properties.

George
Dec 12 '07 #53
On Dec 12, 3:36 pm, sturlamolden <sturlamol...@y ahoo.nowrote:
On 12 Des, 12:56, George Sakkis <george.sak...@ gmail.comwrote:
Ah, the 'make' statement.. I liked (and still do) that PEP, I think it
would have an impact comparable to the decorator syntax sugar, if not
more.

I think it is one step closer to Lisp. I believe that it would be
worth considering adding defmacro statement. Any syntax, including if,
else, for, while, class, lambda, try, except, etc. would be
implemented with defmacros. We would only need a minimalistic syntax,
that would bootstrap a full Python syntax on startup. And as for
speed, we all know how Lisp compares to Python.
It would be great if Python could be speeded up to SBCL Lisp by just
transforming one parse tree into another one. But since Python is
compiled to bytecodes I dare to say that surface syntax is not the key
factor ;)

Kay
Dec 12 '07 #54
On Dec 12, 2007 12:53 PM, George Sakkis <ge***********@ gmail.comwrote:
On Dec 12, 1:12 pm, Christian Heimes <li...@cheimes. dewrote:
Kay Schluehr wrote:
class A(object):
foo = property:
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
which was translated as follows:
class A(object):
def thunk():
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
return vars()
foo = propery(**thunk ())
del thunk
Python 2.6 and 3.0 have a more Pythonic way for the problem:

class A(object):
@property
def foo(self):
return self._foo

@foo.setter
def foo(self, value)
self._foo = value

@foo.deletter
def foo(self)
del self._foo

class B(A):
# one can even overwrite the getter in a subclass
@foo.getter
def foo(self):
return self._foo * 2

Christian

This is by definition Pythonic since it was conceived by the BDFL.It
is also certainly an improvement over the current common practice of
polluting the class namespace with private getters and setters. Still
it's a kludge compared to languages with builtin support for
properties.

How exactly is this a kludge? This is almost identical syntax (but
with less indentation) to a C# property declaration. The only thing
that's simpler is auto-generation of trivial accessors via a
decoration, but those are useless in Python so only the case of
getters and setters that actually do something needs to be addressed.

If the only thing that's not a "kludge" is direct syntax support for a
feature, you've set a pretty high and uselessly arbitrary bar.
Dec 12 '07 #55
On Dec 12, 2:23 pm, "Chris Mellon" <arka...@gmail. comwrote:
On Dec 12, 2007 12:53 PM, George Sakkis <george.sak...@ gmail.comwrote:
On Dec 12, 1:12 pm, Christian Heimes <li...@cheimes. dewrote:
Kay Schluehr wrote:
class A(object):
foo = property:
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
which was translated as follows:
class A(object):
def thunk():
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
return vars()
foo = propery(**thunk ())
del thunk
Python 2.6 and 3.0 have a more Pythonic way for the problem:
class A(object):
@property
def foo(self):
return self._foo
@foo.setter
def foo(self, value)
self._foo = value
@foo.deletter
def foo(self)
del self._foo
class B(A):
# one can even overwrite the getter in a subclass
@foo.getter
def foo(self):
return self._foo * 2
Christian
This is by definition Pythonic since it was conceived by the BDFL.It
is also certainly an improvement over the current common practice of
polluting the class namespace with private getters and setters. Still
it's a kludge compared to languages with builtin support for
properties.

How exactly is this a kludge?
In three (at least) ways:

1. The property name ('foo') is repeated *5* times for a single class.
Talk about DRY.
2. Total inconsistency: @property for the getter when it is defined
for the first time, @foo.setter/@foo.deletter for the setter/deletter,
@foo.getter when the getter is redefined. WTF ?!
This is almost identical syntax (but with less indentation) to a C# property declaration.
3. Less indentation is not an advantage here; typically ones wants all
two or three related functions that define the property to stand out
as a separate group, not be mixed with regular public methods.

Sorry, C# wins hands down on this.

George
Dec 12 '07 #56
In article <87************ @rudin.co.uk>,
Paul Rudin <pa*********@ru din.co.ukwrote:
>Christian Heimes <li***@cheimes. dewrites:
>>
We are happy and glad for every improvement regarding speed, memory
usage or features if and only if: ...

... platform independent / supported on all platforms. Python runs
on machines from mobile phones to large main frames.

JOOI - there are things in the standard library that are not supported
on all platforms. Why would that be a basis for excluding some
psyco-like package?
As a stand-alone package (even shipping with Python), that's not a
problem; my understanding is that other issues have prevented including
Psyco. However, Christian was talking specifically about changes to the
CPython core for performance purposes.
--
Aahz (aa**@pythoncra ft.com) <* http://www.pythoncraft.com/

"Typing is cheap. Thinking is expensive." --Roy Smith
Dec 12 '07 #57
On Dec 12, 8:23 pm, "Chris Mellon" <arka...@gmail. comwrote:
On Dec 12, 2007 12:53 PM, George Sakkis <george.sak...@ gmail.comwrote:
On Dec 12, 1:12 pm, Christian Heimes <li...@cheimes. dewrote:
Kay Schluehr wrote:
class A(object):
foo = property:
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
which was translated as follows:
class A(object):
def thunk():
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
return vars()
foo = propery(**thunk ())
del thunk
Python 2.6 and 3.0 have a more Pythonic way for the problem:
class A(object):
@property
def foo(self):
return self._foo
@foo.setter
def foo(self, value)
self._foo = value
@foo.deletter
def foo(self)
del self._foo
class B(A):
# one can even overwrite the getter in a subclass
@foo.getter
def foo(self):
return self._foo * 2
Christian
This is by definition Pythonic since it was conceived by the BDFL.It
is also certainly an improvement over the current common practice of
polluting the class namespace with private getters and setters. Still
it's a kludge compared to languages with builtin support for
properties.

How exactly is this a kludge? This is almost identical syntax (but
with less indentation) to a C# property declaration.
C# properties are thunk statements:

private Object _foo = null;

public Object foo {
get { return this._foo; }
set { this._foo = value; }
}

In Python pseudo code this would translate to

foo:
def get(self): return self._foo
def set(self, value): self._foo = value

omitting the reference to a property constructor. This is the pure
essence: assign methods not to objects but object attributes, for
which certain protocols are defined. It could be generalized for GUI
applications using triggers or other dataflow related bindings. The
"pythonic" solution being mentioned is a rather obscure and convoluted
decorator hack. "Executable pseudocode" reads different and for the
latter assertion one doesn't need a BDFL stamped license. It
demonstrates the cleverness of the programmer more than it clarifies
the issue.

Kay
Dec 12 '07 #58
Paul Boddie wrote:
Then you haven't been reading the right IRC channel recently. ;-)
What's the right channel? I'm on #python and #python-dev
Indeed, but there's arguably a certain amount of deadlock around
making unpatched, released versions of Python available in all these
places, unless there's been some activity below the surface in the
python-dev community on things like cross-compilation and not running
distutils using the newly built Python executable (which, as I
remember, was but one of the problems). Your point stands, naturally,
but if there's potential for some real movement on some
uncontroversial issues, and yet we see no movement, one remains
skeptical about getting even slightly controversial improvements into
vanilla CPython.
I don't get your point, especially when you talk about distutils. Please
elaborate.

(C)Python has a well known process to get new features or changes into
the language: Write a PEP, convince enough core developers and/or Guido,
implement the feature. I don't see a PEP about JIT in the list at
abouthttp://www.python.org/dev/peps/, do you? :]

Besides nobody is going to stop you from creating a fork. Christian
Tismer forked of stackless years ago. It's a successful branch with
useful additions to the language. It got never merged back because
Christian didn't feel right about it.
Perhaps, but what would people prefer: yet more language bolt-ons or
better performance?
I prefer a fast, stable and maintainable Python over a faster but unstable.
It will be interesting to see what happens with recent work on
improving threading within CPython. As for Psyco (which perhaps offers
concurrency benefits only through instruction-level parallelism, if we
briefly consider that topic), I can understand that just-in-time
compilation can bring certain penalties in terms of memory usage and
initialisation times (as Java virtual machines have demonstrated), but
there's a compelling argument for trying to make such technologies
available to CPython if they can be switched off and won't then incur
such penalties. But we presumably return to the point of people not
wanting to touch code that has anything to do with such features: a
combination of social factors and the priorities of the group.
Rhamph is working on a GIL-less Python version. It may become a compile
time option someday in the future. Others have worked hard to speed up
other parts of Python. We have multiple pending patches which speed up
small parts of Python. Some are related to peephole (byte code
optimizations), other patches speed up attribute access on classes or
globals. The global lookup patch makes globals as fast as locals.

I've done my share for the poor Windows souls when I created the VS 2008
PCbuild9 directory and enabled PGO builds. PGO builds are about 10%
faster than ordinary VS 2008 builds. VS 2008 should be slightly faster
than VS 2003 but I can bench mark it on my machine.

In my opinion an optional JIT as compile time or startup option has good
chances to become part of the CPython implementation. You "only" have to
replace ceval.c ... :]

Christian

Dec 13 '07 #59
Paul Boddie wrote:
Then you haven't been reading the right IRC channel recently. ;-)
What's the right channel? I'm on #python and #python-dev
Indeed, but there's arguably a certain amount of deadlock around
making unpatched, released versions of Python available in all these
places, unless there's been some activity below the surface in the
python-dev community on things like cross-compilation and not running
distutils using the newly built Python executable (which, as I
remember, was but one of the problems). Your point stands, naturally,
but if there's potential for some real movement on some
uncontroversial issues, and yet we see no movement, one remains
skeptical about getting even slightly controversial improvements into
vanilla CPython.
I don't get your point, especially when you talk about distutils. Please
elaborate.

(C)Python has a well known process to get new features or changes into
the language: Write a PEP, convince enough core developers and/or Guido,
implement the feature. I don't see a PEP about JIT in the list at
abouthttp://www.python.org/dev/peps/, do you? :]

Besides nobody is going to stop you from creating a fork. Christian
Tismer forked of stackless years ago. It's a successful branch with
useful additions to the language. It got never merged back because
Christian didn't feel right about it.
Perhaps, but what would people prefer: yet more language bolt-ons or
better performance?
I prefer a fast, stable and maintainable Python over a faster but unstable.
It will be interesting to see what happens with recent work on
improving threading within CPython. As for Psyco (which perhaps offers
concurrency benefits only through instruction-level parallelism, if we
briefly consider that topic), I can understand that just-in-time
compilation can bring certain penalties in terms of memory usage and
initialisation times (as Java virtual machines have demonstrated), but
there's a compelling argument for trying to make such technologies
available to CPython if they can be switched off and won't then incur
such penalties. But we presumably return to the point of people not
wanting to touch code that has anything to do with such features: a
combination of social factors and the priorities of the group.
Rhamph is working on a GIL-less Python version. It may become a compile
time option someday in the future. Others have worked hard to speed up
other parts of Python. We have multiple pending patches which speed up
small parts of Python. Some are related to peephole (byte code
optimizations), other patches speed up attribute access on classes or
globals. The global lookup patch makes globals as fast as locals.

I've done my share for the poor Windows souls when I created the VS 2008
PCbuild9 directory and enabled PGO builds. PGO builds are about 10%
faster than ordinary VS 2008 builds. VS 2008 should be slightly faster
than VS 2003 but I can bench mark it on my machine.

In my opinion an optional JIT as compile time or startup option has good
chances to become part of the CPython implementation. You "only" have to
replace ceval.c ... :]

Christian

Dec 13 '07 #60

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1816
by: Ira Baxter | last post by:
My understanding is that Zend are the folks behind the one and only PHP implementation. Now that PHP5 is released, I'm quite interested in using it. However, the documentation avialable at PHP.NET suggests that it isn't by Zend. What reason is there to believe it is complete and accurate in any sense? (There's lot of user clarifications which show that it isn't complete). In particular, the section of PHP5 has parts that are...
7
14858
by: Aryeh M. Friedman | last post by:
If have something like the following declartion: enum foo {One,Two,....,Ten}; How do I determine how many elements (enumerations)... in this case it is obviously 10 but I don't want to hard code that fact --Aryeh
11
2991
by: Nobody | last post by:
Heres the deal... I have an application where I have a list (as in a Windows list control, but thats not important) displayed to the user. I sort this list based on the list controls sort function (again, its not important that its Windows) which ends up calling a compare function in my code: int CompareFunc(char* str1, char* str2) { } this function returns -1, 0 or 1 which gets passed on to the internal quick
4
3142
by: Silas | last post by:
Hi, I use view to join difference table together for some function. However, when the "real" table fields changed (e.g. add/delete/change field). The view table still use the "old fields". Therefore everytimes when I change the real table, I also needed open the view table and save it by SQL enterprise manager manually for update the view table field.
0
1088
by: Simon Verona | last post by:
I have some Windows Forms software that I'm developing that uses a remote server (called using remoting) to provide the business rules and dataaccess. For development purposes the client and server portions are both running on my PC. I was wondering if there was some way that for "real world" performance, I could somehow "throttle" the tcp/ip stack so that calls to localhost had some lag to represent the latency/bandwidth of a real...
0
393
by: David Garamond | last post by:
I want to know how functional indexes are used "in the real world". Here are the common uses: * non-unique index on the first parts of a longish text field (SUBSTRING(field)) to save disk space, while still allowing faster searches than a sequential scan. * indexing on LOWER(field)/UPPER(field) to allow case-insensitive searches or case-insensitive unique constraint.
5
39977
by: playagain | last post by:
Please help me to build a list of examples of stack and queue in real life situation... Conditions: The object concerned must only one object. And the object must be tangible. Example: Queue (FIFO): The bullet in a machine gun..(you cannot fire 2 bullets at the same time) Stack (LIFO): The tennis balls in their container.. (you cannot remove 2 balls at the same time)
1
3139
by: Tyno Gendo | last post by:
Hi everyone I need to move on a step in my PHP... I know what classes are, both in PHP4 and 5 and I'm aware of "patterns" existing, but what I'm looking for are some real world projects eg. Open Source that people consider to use classes and patterns correctly. I lack a senior person to lead me in this so I feel I'm losing out on only using bare PHP class features and not really knowing how to design
1
1605
by: jamesicus | last post by:
.......... just for curiosity? "real" XHTML served as content (MIME) type application/xhtml+xml will display in MSIE 6.0 release 2900 and 7.0 but they will not render xml content. However, MSIE 6.0 release 2800 and earlier displays a download screen -- selecting OPEN presents a plain, text only, rendered page -- sans style sheet. Here is an XHTML page served as content (MIME) type application/xhtml+xml for testing by those interested. ...
0
174
by: Ignacio Machin ( .NET/ C# MVP ) | last post by:
The difference between compile & runtime. CreateInstance works at runtime, you can pass ANY string to it (even an incorrect one like "123123123123") and it will compile Only at runtime you will get the error. And honestly, you HAVE to know something about your Class. otherwise, how do you know which method to call?
0
9826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10829
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6058
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.