Created
February 13, 2019 17:09
-
-
Save mayankdiatm/fac22d91a142e1d55fcc5b1d519a031f to your computer and use it in GitHub Desktop.
open multiple files in with statement
This file contains hidden or 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
from contextlib import contextmanager | |
@contextmanager | |
def files(*ff): | |
fi = [ open(*f) if len(f) == 2 else open(f) for f in ff ] | |
yield(fi) | |
map(close,fi) |
This file contains hidden or 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
simple python script to convert string to binary ASCII with each character on a new line | |
def toBin(s): | |
# removes space characters, puts each ascii code on a new line | |
print "\n".join(filter(lambda x:x!="100000",[bin(ord(c))[2:] for c in s])) | |
if __name__ == "__main__": | |
s = input("enter a string: \n") | |
toBin(s) | |
# or: | |
if __name__ == "__main__": | |
print "\n".join(filter(lambda x:x!="100000",[bin(ord(c))[2:] for c in input("enter a string:\n")])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment