[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Preprocessing of input for the interactive interpreter?

Stefan Salewski

12/19/2007 4:00:00 PM

Hello,

I just start learning Python (ordered "Dive into Python" a week ago).

In the past I have used the Python interactive interpreter for some
calculations instead of Linux command line tools like "bc" or "calc".

I wonder if it is possible to do a pre-processing of command strings in
the interactive interpreter. (Not that I really need it, and currently my
Python skills are far away to manage this hack. But I am curious -- did
some Google search yesterday, but did not find an answer. Yes, an extended
interpreter called IPython exists -- this one seems to have this
functionality, and I may use this one later.)

It is possible to convert input in this form (input hook?):

My custom input format:

>>> b := 10a + 0,1

Format send to interpreter after preprocessing:

>>> b = 10*a + 0.1


Best regards

Stefan Salewski

1 Answer

Larry Bates

12/19/2007 5:10:00 PM

0

Stefan Salewski wrote:
> Hello,
>
> I just start learning Python (ordered "Dive into Python" a week ago).
>
> In the past I have used the Python interactive interpreter for some
> calculations instead of Linux command line tools like "bc" or "calc".
>
> I wonder if it is possible to do a pre-processing of command strings in
> the interactive interpreter. (Not that I really need it, and currently my
> Python skills are far away to manage this hack. But I am curious -- did
> some Google search yesterday, but did not find an answer. Yes, an extended
> interpreter called IPython exists -- this one seems to have this
> functionality, and I may use this one later.)
>
> It is possible to convert input in this form (input hook?):
>
> My custom input format:
>
>>>> b := 10a + 0,1
>
> Format send to interpreter after preprocessing:
>
>>>> b = 10*a + 0.1
>
>
> Best regards
>
> Stefan Salewski
>

I'm no expert, but I'll bet that pyparsing module will be the answer to your
question.

-Larry Bates