0

I'm trying to compile a project but I'm getting a invalid syntax error during tests with arrow point at the 'h' in with. I haven't written the code and it is fairly years old.

d = Gnuplot.Data(pnts,title=im_title,with='candlesticks')

I tried changing with to something else but then I got different errors. What can I do to fix this issue?

4
  • 1
    with is a Python keyword. Commented Apr 23, 2015 at 19:24
  • with is a reserved word for Python interpreter. Without error traceback we can't say anything about "different errors". Commented Apr 23, 2015 at 19:24
  • 2
    I doubt this class constructor uses with as a keyword argument, because with is a Python keyword. Double-check the API. Commented Apr 23, 2015 at 19:24
  • with_ worked, thanks. Commented Apr 23, 2015 at 19:28

2 Answers 2

4

Apparently this code was written before with became one of the reserved keywords.

The (possible) workaround:

d = Gnuplot.Data(pnts, **{'title': im_title, 'with': 'candlesticks'})

Just checked, it won't work - they were using with as a variable name extensively until Gnuplot.py 1.8.

The solution for Gnuplot.py 1.8+ is to use with_ argument:

d = Gnuplot.Data(pnts, title=im_title, with_='candlesticks')
Sign up to request clarification or add additional context in comments.

1 Comment

"A couple years" is therefore more like ten years.
3

In PEP 8 - Style Guide for Python Code, the following guidance appears in the section Descriptive: Naming Styles :

single_trailing_underscore_ : used by convention to avoid conflicts with Python keyword

i.e.:

d = Gnuplot.Data(pnts,title=im_title,with_='candlesticks')

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.