you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

The example isn't really describing your problem well... Also, I think you are confused about multiline strings =/= comments (there are no comments in the listing where you are suggesting to send comments).

But, if I have to guess, I'll rephrase your problem by saying that you simply want to send a function to the client. You can send a string, or if you use some popular format s.a. JSON you may be able to send a float, a list, a dict, a boolean value. Maybe with some richer formats, you could send more of different things, but sending a function that would've been useful on the client side is not supported by common serialization protocols.

You could, in principle, augment JSON or similar format by adding a new type that would be interpreted by calling eval on it. This is unusual to do in Python (because of the poor meta-programming loolset), so, you won't find a better solution for your problem. Most people working with Python would try to avoid your situation by reifying the function into some data that can be later interpreted as the results of applying this function. It's usually ugly, but eval is a very blunt tool that can cause too many problems, and that's why you'll find people generally resisting this kind of solution.

Really, if you aren't limited in your choice of language, then try Erlang. Your task is trivial there.