Created
November 12, 2019 00:25
-
-
Save sam-lb/38824677afaa16334b590b1c2b0e5a24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I am ashamed for writing this. | |
import inspect; | |
class Cin: | |
""" time to whip out some python magic """ | |
def __rshift__(self, other): | |
# I don't want to require that "other" is declared global. | |
cin = input(); | |
var_name = [v[0] for v in inspect.currentframe().f_back.f_locals.items() if v[1] == other][0]; | |
globals()[var_name] = cin; | |
return cin; | |
def __rlshift__(self, other): | |
# due to the nature of this sorcery, I can't simply write: | |
# return cin >> other. that would create a new global variable called | |
# "other" with the value of the input. | |
cin = input(); | |
var_name = [v[0] for v in inspect.currentframe().f_back.f_locals.items() if v[1] == other][0]; | |
globals()[var_name] = cin; | |
return cin; | |
cin = Cin(); | |
foo = ""; | |
cin >> foo; | |
print(foo); | |
# works both ways! | |
foo << cin; | |
print(foo); | |
# I apologize in advance for the psychological damage this may have caused. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now add
cout