dictionary

A

asit

what the wrong with the following code ????
.... "uid":"sa",
.... "pwd":"secret"}
{'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
 
T

Tim Chase

["%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
 
S

Steven D'Aprano

asit said:
["%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.

Or just read the exception, which explained exactly what's wrong:

"EOL while scanning single-quoted string"


What are programmers coming to these days? When I was their age, we were
expected to *read* the error messages our compilers gave us, not turn to
the Interwebs for help as soon there was the tiniest problem.
 
P

Peter Pearson

What are programmers coming to these days? When I was their age, we were
expected to *read* the error messages our compilers gave us, not turn to
the Interwebs for help as soon there was the tiniest problem.

Yes, and what's more, the text of the error message was
"IEH208". After reading it several times, one looked it up
in a big fat set of books, where one found the explanation:

IEH208: Your program contains an error.
Correct the error and resubmit your job.

An excellent system for purging the world of the weak and
timid.
 
S

Steven D'Aprano

Yes, and what's more, the text of the error message was "IEH208". After
reading it several times, one looked it up in a big fat set of books,
where one found the explanation:

IEH208: Your program contains an error. Correct the error and resubmit
your job.

An excellent system for purging the world of the weak and timid.

You had reference books? You were lucky! When I was lad, we couldn't
afford reference books. If we wanted to know what an error code meant, we
had to rummage through the bins outside of compiler vendors' offices
looking for discarded documentation.
 
A

asit

You had reference books? You were lucky! When I was lad, we couldn't
afford reference books. If we wanted to know what an error code meant, we
had to rummage through the bins outside of compiler vendors' offices
looking for discarded documentation.

I don't have a reference book. I read from e-buks and some print outs
of Reference Card. Again, I had this error becoz my console has no
colour highlighting feature.
 
T

Terry Reedy

asit said:
what the wrong with the following code ????
... "uid":"sa",
... "pwd":"secret"}
{'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

By single-quoted, the message mean quoted by ' or " rather than
triple-quoted with ''' or """.
 
C

Craig Allen

when I was a baby programmer even vendors didn't have documentation to
throw out... we just viewed the dissassembeled opcodes to find out how
things worked... we never did find out much but I could make the speak
click, and we were happy with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top