3

I'm hoping to use raw_input() inside a loop to prompt the user when s/he wants to continue running the script. However, I'm getting an error:

Traceback (most recent call last):
   File "<input>", line 1, in <module>
EOFError: EOF when reading a line

Is this function supported in qgis' python console? If not, do you have any suggestion?

I don't need to read the user's input. I just need the loop to pause for a while to let the user do some other stuff, then when ready, to resume working again.

3
  • 1
    I'm not sure waiting for the user like this is a good idea. Why not make a UI for your script and turning it into a plugin.
    – Nathan W
    Mar 9, 2013 at 12:38
  • You're probably right Nathan. It's supposed to be a quick and dirty script, and I haven't learned how to write a plugin yet. :) oh, btw, it needs to pause because the script is also doing some counting.
    – n1kn0k
    Mar 9, 2013 at 13:32
  • 1
    The QGIS Plugin Builder plugin can give you a jump start with making your first plugin.
    – katahdin
    Mar 11, 2013 at 2:26

4 Answers 4

3

The alternative to raw_input is QInputDialog.getText as explained in Maximus' answer above. A quick and Dirty example would be:

##Import libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *

from PyQt4.QtGui import QInputDialog #this is for your dialogs

 tempTuple = QInputDialog.getText(None, "Your Name" ,"Enter your Full Name: ")
 userName = tempTuple[0]

see also: https://stackoverflow.com/questions/35707849/link-qinputdialog-text-to-a-variable

1
  • 1
    Thanks! This is the solution that works for me in QGIS 3.10
    – grego
    Nov 18, 2020 at 20:42
0

It is a bug in PyQGIS. This is what i found http://mappinggis.com/2015/09/feed-back-como-introducir-valores-a-traves-de-pyqgis/

2
  • 4
    Please edit your answer to give a little more information - external links are notorious for going bad.
    – MaryBeth
    Sep 26, 2016 at 16:04
  • Also, this is a link to a page in Spanish, FYI Nov 15, 2018 at 15:22
0

This is a very old question but the problem seems to persist as of QGis v2.18.

I was able to work around this issue by installing the IPython QGIS Console plugin and running my script from there.

0

This bug report indicates that neither input() nor raw_input() are currently supported, nor likely to be any time soon. Bummer...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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