When I run my code in QGIS Python console I get output, but when I run my code from normal console I didn't get any output.
Why does it work only in QGIS Python console?
import sys, os
sys.path.append(r'C:/PROGRA~1/QGIS3~1.16/apps/qgis/python/plugins')
os.environ['PROJ_LIB'] = 'C:\\Program Files\\QGIS 3.16\\share\\proj'
from qgis.core import *
from qgis.utils import *
qgispath = r'C:/PROGRA~1/QGIS3~1.16/apps/qgis'
QgsApplication.setPrefixPath(qgispath, True)
qgs = QgsApplication([], False)
qgs.initQgis()
path = r'C:/Users/ja/Inne/Desktop/POLSKA/PRG_PunktyAdresowe_POLSKA.shp'
lyr = QgsVectorLayer (path, 'PRG_PunktyAdresowe_POLSKA', 'ogr')
for f in lyr.getFeatures():
print(f.attributes())
break
asked Nov 2, 2020 at 13:28
1 Answer 1
In your last screenshot where we see the Python interpreter in an interactive session you have not actually started execution of the loop yet. Hit the Enter key one more time.
answered Nov 2, 2020 at 13:50
lang-py
break
command. Can you try using it?print(lyr)
beforefor
-loop. What does it give you?print(lyr.featureCount())
beforefor
loop. I think there are no entities or it can't read and iterate on your layer