469,576 Members | 1,721 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,576 developers. It's quick & easy.

Problem in using Pulp

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 '06 #1
6 4006
am***********@gmail.com 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 '06 #2
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:
am***********@gmail.com 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 '06 #3
am***********@gmail.com 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

Dec 22 '06 #4
<am***********@gmail.comwrote:
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

Dec 22 '06 #5

Robert Kern wrote:
am***********@gmail.com 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!

Dec 22 '06 #6
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

Dec 22 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Aaron Prohaska | last post: by
reply views Thread by crawlerxp | last post: by
reply views Thread by njkirsch | last post: by
5 posts views Thread by IkBenHet | last post: by
53 posts views Thread by Vicent Giner | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.