开发者

Generating random Unicode between certain range

I am trying to generate random Unicode characters with two starting number+letter combination..

I have tried the following below but I am getting an error.

def rand_unicode():
    b = ['03','20']
    l = ''.join([random.choice('ABCDEF0123456789') for x in xrange(2)])
    return unicode(u'\u'+random.choice(b)+l,'utf8')

The error I am getting:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode byte开发者_如何学Cs in position 0-1: end of string in escape sequence

I use Python 2.6.


Yeah, uh, that's not how.

return unichr(random.choice((0x300, 0x2000)) + random.randint(0, 0xff))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜