Problem in using Pulp

Discussion in 'Python' started by amitsoni.1984@gmail.com, Dec 22, 2006.

  1. Guest

    Hi,
    I am trying to run the following example which uses PULP for linear
    optimization. But I am getting this error in the last line: "EOL while
    scanning single quoted string".

    Can anyone help me with this?
    thanks
    Amit

    ----------------------------------Code----------------------------
    from pulp import *

    prob = LpProblem("linear", LpMinimize)

    # Variables
    x = LpVariable("x", 0, 4)
    y = LpVariable("y", -1, 1)
    z = LpVariable("z", 0)

    # Objective
    prob += x + 4*y + 9*z

    # Constraints
    prob += x+y <= 5
    prob += x+z >= 10
    prob += -y+z == 7

    GLPK("C:\Documents and
    Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)
     
    , Dec 22, 2006
    #1
    1. Advertising

  2. Robert Kern Guest

    wrote:
    > Hi,
    > I am trying to run the following example which uses PULP for linear
    > optimization. But I am getting this error in the last line: "EOL while
    > scanning single quoted string".


    > GLPK("C:\Documents and
    > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)


    Backslashes escape characters in strings. Specifically, when a string uses ""
    quotes as delimiters, then \" is the escape sequence for a double quote in the
    string itself. The parser sees your \" at the end as simply an escaped double
    quote and keeps interpreting the rest of the line as a string. Since the line
    ends before another, unescaped " comes along, it raises the exception that you see.

    http://docs.python.org/ref/strings.html

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Dec 22, 2006
    #2
    1. Advertising

  3. Guest

    Thanks, now I am not getting that error, but now I am getting a
    different error:
    ---------------------error-------------------------------
    GLPK("C:\Documents and
    Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
    File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114,
    in solve
    return lp.solve(self)
    File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line
    1740, in solve
    status = solver.actualSolve(self)
    File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188,
    in actualSolve
    raise "PuLP: cannot execute "+self.path
    PuLP: cannot execute C:\Documents and
    Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples"
    -------------------------------------------------------------
    can anyone tell me where the problem is? I am using following code.
    thanks
    Amit
    ----------------------Code----------------------
    from pulp import *

    prob = LpProblem("linear", LpMinimize)

    # Variables
    x = LpVariable("x", 0, 4)
    y = LpVariable("y", -1, 1)
    z = LpVariable("z", 0)

    # Objective
    prob += x + 4*y + 9*z

    # Constraints
    prob += x+y <= 5
    prob += x+z >= 10
    prob += -y+z == 7

    GLPK("C:\Documents and
    Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
    ------------------------------------------------------------------------------
    Robert Kern wrote:
    > wrote:
    > > Hi,
    > > I am trying to run the following example which uses PULP for linear
    > > optimization. But I am getting this error in the last line: "EOL while
    > > scanning single quoted string".

    >
    > > GLPK("C:\Documents and
    > > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)

    >
    > Backslashes escape characters in strings. Specifically, when a string uses ""
    > quotes as delimiters, then \" is the escape sequence for a double quote in the
    > string itself. The parser sees your \" at the end as simply an escaped double
    > quote and keeps interpreting the rest of the line as a string. Since the line
    > ends before another, unescaped " comes along, it raises the exception that you see.
    >
    > http://docs.python.org/ref/strings.html
    >
    > --
    > Robert Kern
    >
    > "I have come to believe that the whole world is an enigma, a harmless enigma
    > that is made terrible by our own mad attempt to interpret it as though it had
    > an underlying truth."
    > -- Umberto Eco
     
    , Dec 22, 2006
    #3
  4. Robert Kern Guest

    wrote:
    > Thanks, now I am not getting that error, but now I am getting a
    > different error:
    > ---------------------error-------------------------------
    > GLPK("C:\Documents and
    > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
    > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114,
    > in solve
    > return lp.solve(self)
    > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line
    > 1740, in solve
    > status = solver.actualSolve(self)
    > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188,
    > in actualSolve
    > raise "PuLP: cannot execute "+self.path
    > PuLP: cannot execute C:\Documents and
    > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples"
    > -------------------------------------------------------------
    > can anyone tell me where the problem is? I am using following code.


    > GLPK("C:\Documents and
    > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)


    The last character in that string is a double quote. You don't want that. What
    you want to do is escape all of the backslashes (or use raw strings to avoid the
    escaping altogether). E.g.

    "C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\"

    or

    r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\"

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Dec 22, 2006
    #4
  5. <> wrote:

    > GLPK("C:\Documents and
    > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)

    ^*

    * This is a no no - the backslash escapes the last quote...

    - Hendrik
     
    Hendrik van Rooyen, Dec 22, 2006
    #5
  6. MRAB Guest

    Robert Kern wrote:
    > wrote:
    > > Thanks, now I am not getting that error, but now I am getting a
    > > different error:
    > > ---------------------error-------------------------------
    > > GLPK("C:\Documents and
    > > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
    > > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114,
    > > in solve
    > > return lp.solve(self)
    > > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line
    > > 1740, in solve
    > > status = solver.actualSolve(self)
    > > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188,
    > > in actualSolve
    > > raise "PuLP: cannot execute "+self.path
    > > PuLP: cannot execute C:\Documents and
    > > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples"
    > > -------------------------------------------------------------
    > > can anyone tell me where the problem is? I am using following code.

    >
    > > GLPK("C:\Documents and
    > > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)

    >
    > The last character in that string is a double quote. You don't want that. What
    > you want to do is escape all of the backslashes (or use raw strings to avoid the
    > escaping altogether). E.g.
    >
    > "C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\"
    >
    > or
    >
    > r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\"
    >

    The second example won't work: you can't have a final backslash in a
    raw string!
     
    MRAB, Dec 22, 2006
    #6
  7. Robert Kern Guest

    MRAB wrote:
    > Robert Kern wrote:


    >> The last character in that string is a double quote. You don't want that. What
    >> you want to do is escape all of the backslashes (or use raw strings to avoid the
    >> escaping altogether). E.g.
    >>
    >> "C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\"
    >>
    >> or
    >>
    >> r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\"
    >>

    > The second example won't work: you can't have a final backslash in a
    > raw string!


    My apologies. You are correct.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Dec 22, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Robertson, Jr.
    Replies:
    1
    Views:
    1,004
    Kathy Burke
    Jun 25, 2003
  2. Adil Hasan
    Replies:
    3
    Views:
    1,145
    John J. Lee
    Jan 29, 2004
  3. PuLP and Mac OS X

    , Aug 24, 2005, in forum: Python
    Replies:
    0
    Views:
    567
  4. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    588
    Bullschmidt
    May 11, 2004
  5. Ana Dionísio

    Pulp problem _dummy

    Ana Dionísio, May 23, 2013, in forum: Python
    Replies:
    0
    Views:
    71
    Ana Dionísio
    May 23, 2013
Loading...

Share This Page