Skip to content

Instantly share code, notes, and snippets.

@d2207197
Last active August 29, 2015 14:02
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 d2207197/11cdb483b7a31227d798 to your computer and use it in GitHub Desktop.
Save d2207197/11cdb483b7a31227d798 to your computer and use it in GitHub Desktop.
Use full python snippet
from IPython.display import Image
from IPython.display import HTML
def website(url):
return HTML('<iframe src={} width=800 height=600></iframe>'.format(url))
def image(path):
return Image(filename=path)
from pattern.en import parse
regex =re.compile(u'''([\u4E00-\u9fa5])''')
def seg2Token(input):
'''given a utf-8 string, tokenize it'''
return parse(regex.sub(u''' \\1 ''' , input.decode('utf8')), tokenize = True, tags = False, chunks = False).encode('utf-8')
import pprint
class MyPrettyPrinter(pprint.PrettyPrinter):
def format(self, object, context, maxlevels, level):
if isinstance(object, unicode):
return (object.encode('utf8'), True, False)
return pprint.PrettyPrinter.format(self, object, context, maxlevels, level)
def print_escape(*objs):
for obj in objs:
print str(obj).decode('string_escape')
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment