字典 [英] dictionary

查看:69
本文介绍了字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码有什么问题????


>> d = {" server":" mpilgrim"," database":" master",



... 。uid:" sa",

...." pwd":" secret"}


>> d



{''pwd'' :''secret'',''database'':''master'',''uid'':''sa'',''server'':

''mpilgrim'' }


>> ["%s ="%s" %(k,v)代表k,v代表d.items()]



文件"< stdin>" ,第1行

["%s ="%s" %(k,v)为k,v为d.items()]

^

语法错误:EOL扫描单引号字符串

解决方案

asit< li ***** @ gmail.comwrote:


["%s = "%S" %(k,v)代表k,v代表d.items()]



第一个打开一个字符串,第二个终止它,第三个打开

再次,你没有第四个在你的行中关闭它。


尝试使用支持语法着色的编辑器(即使Idle这样做)

,问题将立即显现。


-

Duncan Booth http ://kupuguy.blogspot.com


>>> ["%s ="%s" %(k,v)表示k,v表示d.items()]


文件"< stdin>",第1行

["%s ="%s" %(k,v)表示k,v表示d.items()]

^

语法错误:EOL扫描单引号字符串


你有三个引号......你想要


"%s =%s"


不是


"%s ="%s"


-tkc


10月24日下午3:06,Tim Chase< python.l ... @ tim.thechases.com写道:


>> ["%s ="%s" %(k,v)代表k,v代表d.items()]



文件"< stdin>",第1行

["%s ="%s" %(k,v)表示k,v表示d.items()]

^

语法错误:EOL扫描单引号字符串



你有三个引号......你想要


"%s =%s"


不是


"%s ="%s"


-tkc



Thanx


what the wrong with the following code ????

>>d={"server":"mpilgrim","database":"master",

.... "uid":"sa",
.... "pwd":"secret"}

>>d

{''pwd'': ''secret'', ''database'': ''master'', ''uid'': ''sa'', ''server'':
''mpilgrim''}

>>["%s="%s" % (k,v) for k,v in d.items()]

File "<stdin>", line 1
["%s="%s" % (k,v) for k,v in d.items()]
^
SyntaxError: EOL while scanning single-quoted string

解决方案

asit <li*****@gmail.comwrote:

["%s="%s" % (k,v) for k,v in d.items()]

The first " opens a string, the second " terminates it, the third " opens
it again, and you don''t have a fourth " in your line to close it.

Try using an editor which supports syntax colouring (even Idle does this)
and the problem will be instantly apparent.

--
Duncan Booth http://kupuguy.blogspot.com


>>>["%s="%s" % (k,v) for k,v in d.items()]

File "<stdin>", line 1
["%s="%s" % (k,v) for k,v in d.items()]
^
SyntaxError: EOL while scanning single-quoted string

You have three quotation marks... you want

"%s=%s"

not

"%s="%s"

-tkc


On Oct 24, 3:06 pm, Tim Chase <python.l...@tim.thechases.comwrote:

>>["%s="%s" % (k,v) for k,v in d.items()]

File "<stdin>", line 1
["%s="%s" % (k,v) for k,v in d.items()]
^
SyntaxError: EOL while scanning single-quoted string


You have three quotation marks... you want

"%s=%s"

not

"%s="%s"

-tkc

Thanx


这篇关于字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆