views:

56

answers:

1

Just wondering...

I find using escape characters too distracting. I'd rather do something like this:

>>> print ^'Let's begin and end with sets of unlikely 2 chars and bingo!'^
Let's begin and end with sets of unlikely 2 chars and bingo!

Note the ' inside the string, and how this syntax would have no issue with it, or whatever else inside for basically all cases. Too bad markdown can't properly colorize it (yet), so I decided to <pre> it.

Sure, the ^ could be any other char, I'm not sure what would look/work better. That sounds good enough to me, tho.

Probably some other language already have a similar solution. And, just maybe, Python already have such a feature and I overlooked it. I hope this is the case.

But if it isn't, would it be too hard to, somehow, change Python's interpreter and be able to select an arbitrary (or even standardized) syntax for notating the strings?

I realize there are many ways to change statements and the whole syntax in general by using pre-compilators, but this is far more specific. And going any of those routes is what I call "too hard". I'm not really needing to do this so, again, I'm just wondering.

+10  A: 

Python has this use """ or ''' as the delimiters

print '''Let's begin and end with sets of unlikely 2 chars and bingo'''

How often do you have both of 3' and 3" in a string

Mark
Not often, but it happens. Thanks a lot! :) - That's also much better looking than my weak suggestion. Freaking great it's there already!
Cawas
@Cawas, that's not an uncommon reaction to Python. "Batteries Included" isn't the half of it.
Mark Ransom
On a related note, what's that syntax I see in some codes using `"""` to quote "comments" right below any `def`?
Cawas
They are docstrings http://www.python.org/dev/peps/pep-0257/ The standard way of documenting functions etc
Mark