Skip to content

Instantly share code, notes, and snippets.

@ftao
Created April 6, 2011 13:18
Show Gist options
  • Save ftao/905621 to your computer and use it in GitHub Desktop.
Save ftao/905621 to your computer and use it in GitHub Desktop.
根据新浪微博的规则截断 的 Python 代码片段
def cn_cut(status, length):
l = 0
end = len(status)
for i,c in enumerate(status):
if ord(c) <= 0xff:
l += 1
else:
l += 2
if l > length * 2:
end = i
break
return status[:end]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment