Last active
August 29, 2015 14:02
-
-
Save d2207197/11cdb483b7a31227d798 to your computer and use it in GitHub Desktop.
Use full python snippet
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
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) |
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
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') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment