473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 4200
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
0
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
0
by: crawlerxp | last post by:
This is the problem: I do not get the output I need when encoding and decoding data using rijndael alghoritm. Look at the code and see what the problem is actually: Please paste this code into...
0
by: njkirsch | last post by:
Hello, I am working on a project that invovles the use of linear programming. The framework for the project has been written in Python. I recently came across PuLP...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
53
by: Vicent Giner | last post by:
Hello. I am new to Python. It seems a very interesting language to me. Its simplicity is very attractive. However, it is usually said that Python is not a compiled but interpreted programming...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.