在 python 中使用替代字符串引用语法
只是想知道......
我发现使用转义字符太分散注意力。我宁愿做这样的事情(控制台代码):
>>> 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!
注意字符串内的 '
,以及这种语法如何没有问题,或者基本上所有情况下的其他内容。太糟糕了 markdown 还不能正确地为其着色,所以我决定
它。
当然, ^
可以是任何其他字符,我不确定什么看起来/工作得更好。这对我来说听起来不错,不过。
可能其他一些语言已经有类似的解决方案。而且,也许 Python 已经有了这样的功能,只是我忽略了它。我希望情况确实如此。
但如果不是,那么以某种方式改变 Python 的解释器并能够选择任意(甚至标准化)语法来表示字符串会不会太困难?
我意识到有很多方法可以改变语句和整个语法一般为使用预编译器,但这要具体得多。我将这些路线中的任何一条称为“太难”。我其实并不需要这样做,所以我只是想知道。
Just wondering...
I find using escape characters too distracting. I'd rather do something like this (console code):
>>> 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python 使用 """ 或 ''' 作为分隔符
字符串中同时出现 3' 和 3" 的频率有多少
Python has this use """ or ''' as the delimiters
How often do you have both of 3' and 3" in a string