python绘制emoji_在Flask/Python中处理emoji的正确方法是什么?

好吧,我现在知道为什么会这样了。。。在

>服务器端

尽管这两个版本都运行在python2.6之上,但awseb Python版本是使用UCS4支持编译的,而本地(macosx)python2.6是使用UCS2编译的。More info about UCS here。在AWS EB EC2:>>> import sys

>>> print sys.maxunicode

1114111本地Python 2.6.8安装:

^{pr2}$

最后,我决定我们的项目最好使用支持UCS4的Python 2.6,因此我必须更新Python安装(Mac OS X 10.9.4):

下载并安装Python2.6.8(与EC2实例相同):$ curl -O https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz

$ tar xzvf Python-2.6.8.tgz

$ cd Python-2.6.8

$ ./configure disable-framework disable-toolbox-glue OPT="-fast -arch x86_64 -Wall -Wstrict-prototypes -fno-common -fPIC" enable-unicode=ucs4 LDFLAGS="-arch x86_64"

$ make

$ sudo make install

创建新的virtualenv和安装依赖项:$ virtualenv -p /usr/local/bin/python2.6 venv_ayf_eb_26

$ . venv_ayf_eb_26/bin/activate

$ pip install -r requirements.txt

>客户端

现在在客户端(Javascript)中,我们需要更新循环字符串的方式,因为ECMAScript 5-使用UCS2。在

因此,要读取“实际字符串/符号长度”,我们使用:String.prototype.getSymbols = function() {

var length = this.length;

var index = -1;

var output = [];

var character;

var charCode;

while (++index < length) {

character = this.charAt(index);

charCode = character.charCodeAt(0);

if (charCode >= 0xD800 && charCode <= 0xDBFF) {

// note: this doesn’t account for lone high surrogates

output.push(character + this.charAt(++index));

} else {

output.push(character);

}

}

return output;

};

String.prototype.realLength = function() {

return this.getSymbols().length;

};

循环:// GET original_text over REST API

text = original_text.getSymbols();

for ( var i=0; i

参考文献

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值