0

This is not a duplicate as I'm using python 2.7.6, not 3.

I'm using the script from V8 source repo and it gives me the error:

D:\v8\source\v8\tools\dev>v8gen.py x64.release
  File "D:\v8\source\v8\tools\dev\v8gen.py", line 147
    print '%s does not exist in %s for %s' % (
                                         ^
SyntaxError: invalid syntax

The file itself should be fine, since it's working on other environments, possibly linux. But I'm running the script from the Windows 10 native shell (cmd).

I'm not familiar with python, can someone suggest what can be wrong?

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • 1
    We'd need to see more code. Do you have end brackets on your print parameters? Are there exactly 3 values that you are trying to print? – NuclearPeon May 04 '17 at 18:12
  • @NuclearPeon, I've linked to the actual file contents, [here it is again](https://chromium.googlesource.com/v8/v8.git/+/master/tools/dev/v8gen.py#147) – Max Koretskyi May 04 '17 at 18:14
  • 1
    How do you know you’re using Python 2.7.6? That looks exactly like the error you’d get in Python 3. – Ry- May 04 '17 at 18:18
  • So I looked it over and for 2.7.6 I see no syntax issues. pylint rates it a -2.27/10, but no syntax/major issues. – TemporalWolf May 04 '17 at 18:22
  • @Ryan, I typed `python` in `cmd` and got `Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32` – Max Koretskyi May 04 '17 at 18:22
  • `%s` assumes that a string is being given. Can you guarantee that all 3 parameters are strings? I would encapulate those parameters in `str()` if you are not sure to test. – NuclearPeon May 04 '17 at 18:26
  • @NuclearPeon Neither giving the incorrect number of args nor supplying something without a `__str__()` will give a `SyntaxError`. – TemporalWolf May 04 '17 at 18:28
  • @TemporalWolf, so how to check what version of python the script is being run? – Max Koretskyi May 04 '17 at 18:32
  • 1
    I would suggest just wrapping that print in parenthesis and seeing if you see the same issue. `print(...)` is valid in Py2 & Py3 – TemporalWolf May 04 '17 at 18:33
  • @TemporalWolf, it's working with paranthesis. I get another error. How come I get 2.7.x on the command line but the script is running with 3.x? – Max Koretskyi May 04 '17 at 18:39
  • Just going to throw this out there: Check your script encodings. https://stackoverflow.com/questions/3170211/why-declare-unicode-by-string-in-python#3170331 - Add `# -*- coding: utf-8 -*-` to the top of your script file. Windows could be adding carriage returns or your parameters could be in byte strings, not strings. If I had a windows machine to test with I could give you better answers, sorry. – NuclearPeon May 04 '17 at 18:41
  • 2
    If somewhere you are using [`from __future__ import print_function`](http://stackoverflow.com/questions/32032697/how-to-use-from-future-import-print-function) this would make sense. NuclearPeon's suggestion is also worth a go. – TemporalWolf May 04 '17 at 18:42
  • @TemporalWolf, indeed, `from __future__ import print_function` is used at the top of the script – Max Koretskyi May 04 '17 at 18:42
  • haha, well that forces you to use Py3 `print()` instead of Py2 `print ...` I'll update that doc page to reflect a new possible solution. – TemporalWolf May 04 '17 at 18:43
  • @TemporalWolf, but it's used in different file, which is referenced [here](https://chromium.googlesource.com/v8/v8.git/+/master/tools/dev/v8gen.py#161) – Max Koretskyi May 04 '17 at 18:44
  • 1
    @Maximus: Just because `python` reports Python 2.7.6 doesn’t *necessarily* mean it’s what’s associated with .py files. What happens if you use `python v8gen.py x64.release`? – Ry- May 04 '17 at 18:49
  • @Ryan, this way it's working fine. How come? How to know which version is associated with `.py` version? – Max Koretskyi May 04 '17 at 18:50
  • 1
    @Maximus: You have .py files associated with Python 3. Right-click on a .py file and look at the “Open with…” dialog. – Ry- May 04 '17 at 18:51
  • @Ryan, yeah, it seems so. You can post it as answer. I'll accept. Although it'd be great to know _why_ python 3 is associated with `.py` files and where this python 3 is located – Max Koretskyi May 04 '17 at 18:55

1 Answers1

4

I think you are using Python 3.x, and this code is written in Python 2.x.

Try to run it in the correct version of python, or change it to:

print ('%s does not exist in %s for %s' % (
      self._options.builder, CONFIG, self._options.master))
Ry-
  • 218,210
  • 55
  • 464
  • 476
Yuval Pruss
  • 8,716
  • 15
  • 42
  • 67