[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Does Python has a read facility, like CL or Racket?

Eduardo Costa

10/16/2015 1:46:00 AM

I wonder whether Python has reading tools similar to the ones that I find in CL or Racket. I mean, something like (read), that can input lists, arrays, etc. Is there a function in Python to read Python lists? Is there something akin read macros in Python? I know that I should ask such a question in a Python discussion list, but it seems that Python programmers do not understand what I mean by Lisp like reading facilities.
6 Answers

Pascal J. Bourguignon

10/16/2015 1:53:00 AM

0

Eduardo Costa <edu500ac@gmail.com> writes:

> I wonder whether Python has reading tools similar to the ones that I
> find in CL or Racket. I mean, something like (read), that can input
> lists, arrays, etc. Is there a function in Python to read Python
> lists? Is there something akin read macros in Python? I know that I
> should ask such a question in a Python discussion list, but it seems
> that Python programmers do not understand what I mean by Lisp like
> reading facilities.

Wouldn't that be a question to be asked in comp.lang.python?

I just don't know enough python to answer.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Paul Rubin

10/16/2015 1:59:00 AM

0

Eduardo Costa <edu500ac@gmail.com> writes:
> I wonder whether Python has reading tools similar to the ones that I
> find in CL or Racket. I mean, something like (read), that can input
> lists, arrays, etc. Is there a function in Python to read Python
> lists?

There's an eval function (dangerous) and ast.literal_eval (safer since
it can only read literal data, i.e. [1,2,3] will work but [1, 2+2, 5] won't.

> Is there something akin read macros in Python?

No.

> I know that I should ask such a question in a Python discussion list,
> but it seems that Python programmers do not understand what I mean by
> Lisp like reading facilities.

Yes they do, and you can use comp.lang.python.

William James

10/16/2015 4:06:00 AM

0

Eduardo Costa wrote:

> I wonder whether Python has
> reading tools similar to the ones
> that I find in CL or Racket. I
> mean, something like (read), that
> can input lists, arrays, etc. Is
> there a function in Python to
> read Python lists? Is there
> something akin read macros in
> Python? I know that I should ask
> such a question in a Python
> discussion list, but it seems
> that Python programmers do not
> understand what I mean by Lisp
> like reading facilities.

If you are the one creating the data, perhaps you can use
marshalling.

MatzLisp (Ruby):

x = Marshal.dump( [2, 3+4, 5] )
==>"\004\b[\bi\ai\fi\n"
Marshal.restore( x )
==>[2, 7, 5]

--
A separation of the races is the only perfect preventive of amalgamation; but
as an immediate separation is impossible, the next best thing is to keep them
apart where they are not already together. If white and black people never get
together in Kansas, they will never mix blood in Kansas.
--- A. Lincoln, June 26, 1857

Kaz Kylheku

10/16/2015 4:19:00 AM

0

On 2015-10-16, Eduardo Costa <edu500ac@gmail.com> wrote:
> I wonder whether Python has reading tools similar to the ones that I find in
> CL or Racket. I mean, something like (read), that can input lists, arrays,
> etc. Is there a function in Python to read Python lists? Is there something
> akin read macros in Python? I know that I should ask such a question in a
> Python discussion list, but it seems that Python programmers do not
> understand what I mean by Lisp like reading facilities.

You're using way longer sentences than Python people can understand.
Stick to a variety of sentence lengths in the 8-12 word range.

Also, what's stopping you from describing what you want without
Lisp references?

I'm looking for a function which scans a stream. The syntax is that of Python
data structures. Examples of these are Python lists and arrays. The function
should return Python objects denoted by the syntax.

Does Python expose its parser/scanner this way for programmer use?

Also, is the scanner customizeable? Such a scanner dispatches a user-supplied
function when it sees certain characters. The dispatched code performs a
customized scan and returns an object. The object is then incorporated into
the parse.

rwiker

10/16/2015 4:48:00 AM

0

Eduardo Costa <edu500ac@gmail.com> writes:

> I wonder whether Python has reading tools similar to the ones that I
> find in CL or Racket. I mean, something like (read), that can input
> lists, arrays, etc. Is there a function in Python to read Python
> lists? Is there something akin read macros in Python? I know that I
> should ask such a question in a Python discussion list, but it seems
> that Python programmers do not understand what I mean by Lisp like
> reading facilities.

Well, you have the "pickle" and "marshal" modules, unless you
specifically want a human-readable format. Otherwise, I think there is
one or more implementations of json-like functionality.

A web search for "python serialization format" should give you a few
pointers.

Pascal J. Bourguignon

10/16/2015 5:08:00 AM

0

Raymond Wiker <rwiker@gmail.com> writes:

> Eduardo Costa <edu500ac@gmail.com> writes:
>
>> I wonder whether Python has reading tools similar to the ones that I
>> find in CL or Racket. I mean, something like (read), that can input
>> lists, arrays, etc. Is there a function in Python to read Python
>> lists? Is there something akin read macros in Python? I know that I
>> should ask such a question in a Python discussion list, but it seems
>> that Python programmers do not understand what I mean by Lisp like
>> reading facilities.
>
> Well, you have the "pickle" and "marshal" modules, unless you
> specifically want a human-readable format. Otherwise, I think there is
> one or more implementations of json-like functionality.
>
> A web search for "python serialization format" should give you a few
> pointers.

Also there's Pypy so the code exists.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk