473,702 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type in Python, Pyrex, etc...

Hi,

I'm playing with python and try to add type declaration in python. No,
don't leave now !

I have done it in order to stay python's syntax compatible (whereas for
example pyrex introduce a new syntax) so of course it should not be that
nice but...

The advantage is that you can debug with the python interpreter and then
compile it trough pyrex.
Of course, some other program like StarKiller could also use such
annotation...

First I though to use declare(int,obj ) (wich in the interpreter just
check type) but it cause exception if the obj is not yet initialize so I
change the notation...

What do you think about this ?

Look at the following example (from pyrex) and the automated translation
in pyrex

--
Yermat

# Prime.py
from declaration import *

def primes(kmax):
declare(ListOf( int),primes)
declare(int,kma x)
n = int
k = int
i = int
p = ArrayOf(int,100 0)
result = []
if kmax > 1000:
kmax = 1000
k = 0
n = 2
while k < kmax:
i = 0
while i < k and n % p[i] <> 0:
i = i + 1
if i == k:
p[k] = n
k = k + 1
result.append(n )
n = n + 1
return result

if __name__=="__ma in__":
print primes(10)
# Prime.pyx
# automatically generated from the previous one
def primes(int kmax):
cdef int n
cdef int k
cdef int i
cdef int p[1000]
result = []
if kmax > 1000:
kmax = 1000

k = 0
n = 2
while k < kmax:
i = 0
while i < k and n % p[i] != 0:
i = i + 1

if i == k:
p[k] = n
k = k + 1
result.append(n )

n = n + 1

return result

if __name__ == '__main__':
print primes(10)

Jul 18 '05 #1
2 1602
Yermat <lo**@yermat.ne t1.nerim.net> writes:
I'm playing with python and try to add type declaration in python.
Is the intent to eventually incorporate it into Pyrex? I suppose it's
not necessary. It could easily become part of the makefile, converting
..py files to .pyx.
The advantage is that you can debug with the python interpreter and then
compile it trough pyrex.
I do this a lot. How 'bout making it translate "+=" too?
# Prime.py
from declaration import * def primes(kmax):
declare(ListOf( int),primes)
declare(int,kma x)

# Prime.pyx
# automatically generated from the previous one
def primes(int kmax):


Shouldn't "primes" be cdef-ed? Will there be a way to add "public" to
declarations?

Thank you.

--kyler
Jul 18 '05 #2
Kyler Laird a écrit :
Yermat <lo**@yermat.ne t1.nerim.net> writes:

I'm playing with python and try to add type declaration in python.

Is the intent to eventually incorporate it into Pyrex? I suppose it's
not necessary. It could easily become part of the makefile, converting
.py files to .pyx.

The advantage is that you can debug with the python interpreter and then
compile it trough pyrex.

I do this a lot. How 'bout making it translate "+=" too?

# Prime.py

from declaration import *


def primes(kmax):
declare(ListOf( int),primes)
declare(int,kma x)


# Prime.pyx
# automatically generated from the previous one
def primes(int kmax):

Shouldn't "primes" be cdef-ed? Will there be a way to add "public" to
declarations?


By now, this is just a proof-of-concept so it just work for this simple
example but I think you can do nearly everything. Eventually expand "+="
stuff...

In my example, "primes" come from the pyrex website and wasn't "cdef"...

All of this is just an ast manipulation. What I would like is feed-back
from python notation to add type that could serve to pyrex (like this
example), psycho, Starkiller...

Then It could become part of them !

Yermat

Jul 18 '05 #3

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

Similar topics

0
2153
by: Irmen de Jong | last post by:
QOTW: "Confronting the Martellibot is like flirting with an encyclopedia, I'd rather not do it myself, but I respect those who do, because it produces knowledge." -- Anton Vredegoor "Python and Java are not diametrically opposed religions that must fight to the death in jihad, despite the existence of loonies favoring exactly that. They solve different problems; sometimes in similar ways, sometimes not." ...
5
2254
by: Gary | last post by:
Hi- I've been searching the web for a while and I've been unable to find a way to access c data objects in python without using SWIG. I can do methods just fine but I can't access variables. It seems like PyModule_AddObject should work but it segfaults my program. There's a good chance I'm just using it wrong, or I should be using something else. Could someone give me a simple, complete example pretty please? Thanks!
58
4002
by: Svein Ove Aas | last post by:
Is anyone working on a python-to-native compiler? I'd be interested in taking a look. Come to think of it, is anyone working on a sexpr-enabled version of Python, or anything similar? I really miss my macros whenever I try to use it...
6
1986
by: nell | last post by:
Hi all, I've developed a testing application in python, and should supply it in a way that no one (lets say they are regular users) will understand it and edit it. The application source is all python but we expose a UI written in C# that go over all our code and expose to user functions (Indicated with a special prefix). So the problem on one hand is protecting the source and make it less accessible ond on the other hand to make it...
6
9373
by: jppx1 | last post by:
Can I use python to make a regular Windows DLL that will be called from other programs? I know I can use the win32 extensions to make a COM server, but I need a straight DLL. Regards, Phillip ------------------------------------------------------------------------ Phillip Piper
7
1864
by: Georg Grabler | last post by:
Hello everybody. There's a C library which i'd like to have python bindings for. I havn't known anything before about how to write python bindings for a C library. I succeeded now by using distutils to write the first bindings for functions and similar. Now, it seems as something is blocking my brain. For the library, i need "custom" types, so types defined in this library (structures),
4
2532
by: vedrandekovic | last post by:
Hi, I have already install Microsoft visual studio .NET 2003 and MinGw, when I try to build a extension: python my_extension_setup.py build ( or install ) , I get an error: LINK : fatal error LNK1141: failure during build of exports file error: command '"C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe"' failed with exit status 1141.What shoud I
68
2704
by: Santiago Romero | last post by:
( Surely if this question has been asked for a zillion of times... ) ( and sorry for my english! ) I'm impressed with python. I'm very happy with the language and I find Python+Pygame a very powerful and productive way of writing 2D games. I'm not, at this moment, worried about execution speed of the small game I'm working on (it runs at full 60 fps even in an old AMD- K6 450 Laptop computer), but I continue asking me the same question:...
1
168
by: Hendrik van Rooyen | last post by:
Patrick Maupin <pmau....ail.comwrote: Thanks. Nice to see that there is still some sense of humour left somewhere - its all been so serious here lately - people seem to forget that hacking is fun! Actually, I am not complaining - I am asking for advice on the side effects of what I am doing, which is replacing a bunch of bits
0
8739
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9089
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
8940
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7831
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
6575
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
5907
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4412
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...
1
3107
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
2036
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.