Skip to content

Instantly share code, notes, and snippets.

@sam-lb
Created November 12, 2019 00:25
Show Gist options
  • Save sam-lb/38824677afaa16334b590b1c2b0e5a24 to your computer and use it in GitHub Desktop.
Save sam-lb/38824677afaa16334b590b1c2b0e5a24 to your computer and use it in GitHub Desktop.
# 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.
@dullbananas
Copy link

im here from reddit

@bobbbay
Copy link

bobbbay commented Aug 14, 2021

I'm also here from Reddit, but from another comment 2 years later.

@jackiboi307
Copy link

me too

@aaronjamt
Copy link

Now add cout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment