Skip to content

Instantly share code, notes, and snippets.

@mayankdiatm
Created February 13, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayankdiatm/fac22d91a142e1d55fcc5b1d519a031f to your computer and use it in GitHub Desktop.
Save mayankdiatm/fac22d91a142e1d55fcc5b1d519a031f to your computer and use it in GitHub Desktop.
open multiple files in with statement
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)
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