Unicode escaped comments in Python
I made a Java program that uses unicode escaped characters to break a multiline comment and hide some functionality. The program below prints "Hello Cruel World". I'm wondering if this is possible to do in Python (any version). If it is not possible, how is this prevented in the language?
public static void main(String[] args) {
print("Hello");
/*
* u002Au002Fu0070u0072u0069u006Eu0074u0028u0022u0043u0072u0075u0065u006Cu0022u0029u003Bu002Fu002A
*/
print("World");
}
private static void print(String s){
System.out.print(s + " ");
}
Note that the unicode is the escaped string */print("Cruel");/*
My fruitless attempt so far...
test = False
#u0023test = True
'''
u0027u0027u0027
test = True
u0027u0027u0027
'''
print(test)
Python lexer only processes Unicode escapes within Unicode string literals ( u''
in Python 2, ''
in Python 3), thus such an approach is not possible.
If you try just the simple space, u0020
, python spits out:
SyntaxError: unexpected character after line continuation character
That is because outside string literals, the character is chiefly used in for breaking a long line into several shorter:
spam = foo + bar + baz + ham +
eggs + ham + spam + spam +
spam + sausages + spam
Outside strings, the only allowed character after is a newline.
上一篇: 在默认构造函数之前执行的方法
下一篇: Unicode在Python中转义了注释