Python Forum
Syntax Error when running code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Error when running code
#1
Hi guys

I am working on a LP problem using PuLP, Pandas and Plotly. When I run the code this error message popped up( I include the code). My suspicion is I may have inadvertently changed something small whilst inserting my data. It is a downloaded file that I run in Jupyter Notebook:

file "<python-input-2-ea571e8e083e>", line 7
\=[.[.[pp,ooiiujname,("city","country,","lat,","long")

SyntaxError: unexpected character after line continuation character( points to the last closed bracket after " long")
Reply
#2
Too little information, but \ is line continuation character.

From PEP8:


Quote:The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

Backslashes may still be appropriate at times. For example, long, multiple with-statements cannot use implicit continuation, so backslashes are acceptable:

with open('/path/to/some/file/you/want/to/read') as file_1, \
     open('/path/to/some/file/being/written', 'w') as file_2:
    file_2.write(file_1.read())
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Ok. I will have to check it later when on my personal laptop. Is there nothing untoward immediately noticeable i.e. after the continuation character ?
Reply
#4
Hi all

Unless I am not searching the correct sources - as a newcomer to Python with the intent on upskilling as fast as reasonable possible - I have been looking for tutorials on PuLP. Reason is I am doing a lot of Linear Problem solving ( Python was proposed as the best).
Apart from one meaningful video on You tube , I have been unsuccessful to source others. Please direct me to PuLP tutorial ( video and otherwise) that can assist me. Also additional Python models I am not aware of , with a strong leaning towards LP.

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 634 Feb-14-2024, 02:57 PM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,160 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 374 Jan-19-2024, 01:20 PM
Last Post: rob101
  writing and running code in vscode without saving it akbarza 1 380 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 518 Nov-10-2023, 08:09 AM
Last Post: akbarza
  error "cannot identify image file" part way through running hatflyer 0 666 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Syntax error while executing the Python code in Linux DivAsh 8 1,545 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,206 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  Error when running kivy on python janeik 8 2,033 Jun-16-2023, 10:58 PM
Last Post: janeik
  syntax error question - string mgallotti 5 1,296 Feb-03-2023, 05:10 PM
Last Post: mgallotti

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020