[Qgis-user] from xxx import zzz

Stephen Sacks ssacks456 at gmail.com
Mon Mar 28 09:33:11 PDT 2022


Please pardon what may be a dumb question from a self- (half-) taught 
student of Python.  I often steal fragments of code from the internet 
(especially including this forum) and sometimes get an error message 
like  "xxx is not an attribute of yyy" .  My  problem, I think, is a 
missing  " from xyz import abc".  My question to you now is whether 
there is some way to know what to import, and from which module, for any 
particular Python statement.  More specifically, I get this error message:

   AttributeError: 'QgsEditFormConfig' object has no attribute 'setHidden'

when I run the following code:

from qgis.core import QgsProject
from qgis.core import *
from qgis.utils import iface
from qgis.core import *
from PyQt5.QtWidgets import QInputDialog
from PyQt5.QtWidgets import *
from qgis.PyQt.QtCore import *
from qgis.gui import *

def oneA( lyr, columnName, option ):
     flds= lyr.fields()
     indx = flds.indexOf(columnName)
     config = lyr.editFormConfig()
     config.setHidden(indx, option)
     lyr.setEditFormConfig(config)

lyr = iface.activeLayer()
aField =  'NAME'
oneA (lyr, aField, True)

When I type this code in the QGIS environment, autocompletion leads me 
to believe that "setHidden" is allowed after "config." but I must admit 
I don't understand the meaning of the several choices specified in the 
parentheses.  I'd be grateful if someone would explain that to me.  
Also,  am I correct in thinking that an asterisk following "import" 
means "everything in this module"?
    I'm running QGIS  3.16.3  under Windows 10.
    Thanks in advance for any help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220328/cec907fe/attachment.html>


More information about the Qgis-user mailing list