dictionary

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asit

    dictionary

    what the wrong with the following code ????
    >>d={"server":" mpilgrim","data base":"master",
    .... "uid":"sa",
    .... "pwd":"secr et"}
    >>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
  • Duncan Booth

    #2
    Re: dictionary

    asit <lipun4u@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

    Comment

    • Tim Chase

      #3
      Re: dictionary

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



      Comment

      • asit

        #4
        Re: dictionary

        On Oct 24, 3:06 pm, Tim Chase <python.l...@ti m.thechases.com wrote:
        >>["%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

        Comment

        • Steven D'Aprano

          #5
          Re: dictionary

          On Fri, 24 Oct 2008 10:04:32 +0000, Duncan Booth wrote:
          asit <lipun4u@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.
          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.


          --
          Steven
          who is having a "you damn kids get off my lawn" moment...

          Comment

          • Peter Pearson

            #6
            Re: dictionary

            On 24 Oct 2008 13:17:45 GMT, Steven D'Aprano wrote:
            >
            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.

            --
            To email me, substitute nowhere->spamcop, invalid->net.

            Comment

            • Steven D'Aprano

              #7
              Re: dictionary

              On Fri, 24 Oct 2008 14:53:19 +0000, Peter Pearson wrote:
              On 24 Oct 2008 13:17:45 GMT, Steven D'Aprano wrote:
              >>
              >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.
              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.



              --
              Steven

              Comment

              • asit

                #8
                Re: dictionary

                On Oct 24, 8:01 pm, Steven D'Aprano <st...@REMOVE-THIS-
                cybersource.com .auwrote:
                On Fri, 24 Oct 2008 14:53:19 +0000, Peter Pearson wrote:
                On 24 Oct 2008 13:17:45 GMT, Steven D'Aprano wrote:
                >
                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.
                >
                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.
                >
                --
                Steven
                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.

                Comment

                • Terry Reedy

                  #9
                  Re: dictionary

                  asit wrote:
                  what the wrong with the following code ????
                  >
                  >>>d={"server": "mpilgrim","dat abase":"master" ,
                  ... "uid":"sa",
                  ... "pwd":"secr et"}
                  >
                  >>>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
                  By single-quoted, the message mean quoted by ' or " rather than
                  triple-quoted with ''' or """.

                  Comment

                  • mblume

                    #10
                    Re: dictionary

                    Am Fri, 24 Oct 2008 05:06:23 -0500 schrieb 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
                    >
                    Or he may have wanted
                    "%s = '%s'"
                    Another neat python feature.
                    HTH
                    Martin

                    Comment

                    • Craig Allen

                      #11
                      Re: dictionary

                      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.

                      Comment

                      Working...