python中tuple写法

From Evernote:

python中tuple写法

今天passport项目已经上了公网测试了,还没打开了,测试人员就来告诉说在内网环境的passport注册接口有bug,吓得我一身冷汗。查了半天,终于发现一个问题,在urllib请问计费接口的时候,抛出异常显示参数是个tuple,而正常的情况下,这个参数应该是个url字串,再一细查发现在写这个url的时候用了如下的代码: url = urlstr,
问题就出在这里了,后面那个逗号,正是这个逗号,将url变成tuple了,为了保险起见,测试了下如下写法:
>>>url = "a", "b", "c"
>>>type(url)
<type ‘tuple’>
在stackoverflow上查到:http://stackoverflow.com/questions/3750632/why-does-adding-a-trailing-comma-after-a-string-make-it-a-tuple,原来元组的定义就是多个由逗号分隔的值,而与括号无关,这句话是写在Python Tutorial里的,看书不认真的下场啊。

Advertisements
此条目发表在未分类分类目录。将固定链接加入收藏夹。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s