473,287 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

python with braces pre-processor

Hi, I'm working on a project that outputs several languages including
(hopefully) python. My problem is that the generic backend architecture
has not been designed to output correctly indented code, and that would
be helpful if there were somewhere a python pre-processor that would take
python with braces as an input and output regular python code. I thought
that it must exists because everyone generating python code will
encounter more or less the same problem, but I didn't find any 'official'
thing on the subject. I mean that I wonder if there is a special mode of
the offcial parser that does such a thing. If not, do you know the most
reliable project that would do this ?

Thanks a lot.

Paul
Oct 22 '07 #1
5 1971
Ant
On Oct 22, 10:44 am, Paul Brauner <paul.brau...@loria.frwrote:
Hi, I'm working on a project that outputs several languages including
(hopefully) python. My problem is that the generic backend architecture
has not been designed to output correctly indented code, and that would
be helpful if there were somewhere a python pre-processor that would take
python with braces as an input and output regular python code. I thought
that it must exists because everyone generating python code will
encounter more or less the same problem, but I didn't find any 'official'
There's a tool in the standard Python distribution that processes code
with commented end statements. eg:

def my_funct():
pass
# end
or similar, and indents it correctly. This may be a possibility for
your purposes.

Oct 22 '07 #2
I'll look at that. Thanks a lot !
Oct 22 '07 #3
On Mon, 22 Oct 2007 09:44:27 +0000, Paul Brauner wrote:
Hi, I'm working on a project that outputs several languages including
(hopefully) python. My problem is that the generic backend architecture
has not been designed to output correctly indented code, and that would
be helpful if there were somewhere a python pre-processor that would take
python with braces as an input and output regular python code. I thought
that it must exists because everyone generating python code will
encounter more or less the same problem, but I didn't find any 'official'
thing on the subject.
Maybe (almost) nobody feels the need to generate Python source code. The
language is so dynamic that there are almost always ways to avoid
source code generation.

Maybe you can generate a token stream and use `tokenize.untokenize()` to
generate the source code!?

Ciao,
Marc 'BlackJack' Rintsch
Oct 22 '07 #4
Ant
On Oct 22, 10:58 am, Paul Brauner <paul.brau...@loria.frwrote:
I'll look at that. Thanks a lot !
I've just had a look, it's the pindent.py script in Tools/Scripts (at
least it is on Windows). It takes code of the following form:

def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b a: a = a-1
# end if
else:
print 'oops!'
# end if
# end def foobar

The help in the script looks pretty good.

--
Ant...

Oct 22 '07 #5
Le Mon, 22 Oct 2007 05:00:02 -0700, Ant a écritÂ*:
On Oct 22, 10:58 am, Paul Brauner <paul.brau...@loria.frwrote:
>I'll look at that. Thanks a lot !

I've just had a look, it's the pindent.py script in Tools/Scripts (at
least it is on Windows). It takes code of the following form:

def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b a: a = a-1
# end if
else:
print 'oops!'
# end if
# end def foobar

The help in the script looks pretty good.
Thanks,

actually i'm using it right now as a backend and it's helpful.

Oct 22 '07 #6

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

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
12
by: The Tao of Spike | last post by:
I've recentlty been getting into programming. I was wondering what language to learn first and after asking around I decided on Python. I'm about half way through "Non-Programmers Tutorial For...
4
by: Michael | last post by:
>>Right. Then we can have "does the brace go on the same line or the >>next line" wars. >> >> > > int main (void) > { > if (true) > { > }
147
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give...
76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
0
by: travis ray | last post by:
Hi, I have an extension in which a file object is created in python and passed down to a c extension which attempts to read from it or write to it. Writing to the file pointer seems to work...
852
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
29
by: Gerald | last post by:
Hi ,Im a BSc4 Maths/Computer Science student.Unfortunately my curriculum did not include Python programming yet I see many vacancies for Python developers.I studied programming Pascal,C++ and...
13
by: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= | last post by:
Within a few weeks, we will release Python 2.5.3. This will be the last bug fix release of Python 2.5, afterwards, future releases of 2.5 will only include security fixes, and no binaries (for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.