3

I'm using QGIS 2.18.16 and following the training manual, and I'm stuck on 6.4.5.

I've followed the example to produce an action that will search wiki, but I receive a syntax error as listed below:

An error occurred during execution of the following code:
from PyQt4.QtCore import QUrl; from PyQt4.QtWebKit import QWebView; myWV = QWebView(None); myWV.load(QUrl(’http://wikipedia.org/wiki/Swellendam’)); myWV.show()


  File "", line 1
    from PyQt4.QtCore import QUrl; from PyQt4.QtWebKit import QWebView; myWV = QWebView(None); myWV.load(QUrl(’http://wikipedia.org/wiki/Swellendam’)); myWV.show()
                                                                                                              ^
SyntaxError: invalid syntax

The code:  from PyQt4.QtCore import QUrl; from PyQt4.QtWebKit import QWebView; myWV = QWebView(None); myWV.load(QUrl(’http://wikipedia.org/wiki/[% "name" %]’)); myWV.show()

Any thoughts on where I've gone wrong?

  • Post your code. – HeikkiVesanto Feb 20 '18 at 14:59
  • Don't put multiple python statements on the same line separated by semicolons - makes it much harder to see what line the mistake is. – Spacedman Feb 20 '18 at 15:00
  • 1
    Perhaps you should try testing it with the 2.18 Training Manual instead of 2.14. There may have been changes to the Python API between those versions. – Joseph Feb 20 '18 at 15:00
  • 1
    I think its your quotation marks.You seem to not be using proper single quote marks. You should use ' marks. – Spacedman Feb 20 '18 at 15:01
3

Your single quote marks are the wrong sort of quote mark. This is using quotes cut and pasted from your code:

s = ’http://wikipedia.org/wiki/Swellendam’

  File "<stdin>", line 1
    s = ’http://wikipedia.org/wiki/Swellendam’
        ^
SyntaxError: invalid syntax

And this is using single quotes from my keyboard:

s = 'http://wikipedia.org/wiki/Swellendam'

no syntax error.

  • Cheers, simple stuff really! Thanks for answering. – McGraw Feb 20 '18 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.