Hello,<br><br>I am a newbie on oython and I am taking the error at subject my code is below, I am trying to develop a qgis plugin and lines begin with # is the thing that I tried. Thus sys.stdout gives the type error. When I comment that line it turns an error like below. What may be the problem? thanks for help:)<br>
<br>...\ReadData.py", line 128, in run<br>    print "%d %s" %(k, attr.toString())<br>IOError: [Errno 9] Bad file descriptor<br><br><br><br><br># Import the PyQt and QGIS libraries<br>from PyQt4 import QtCore, QtGui<br>
<br>from PyQt4.QtCore import * <br>from PyQt4.QtGui import *<br>from qgis.core import *<br>from os import *<br>from qgis.gui import *<br>import sys<br>import pdb<br># Initialize Qt resources from file resources.py<br>import resources<br>
# Import the code for the dialog<br>from ReadDataDialog import ReadDataDialog<br><br>class ReadData: <br><br>  def __init__(self, iface):<br>    # Save reference to the QGIS interface<br>    self.iface = iface<br><br>  def initGui(self):  <br>
    # Create action that will start plugin configuration<br>    self.action = QAction(QIcon(":/plugins/readdata/icon.png"), \<br>        "Read shp for calculations", self.iface.mainWindow())<br>    # connect the action to the run method<br>
    QObject.connect(self.action, SIGNAL("triggered()"), self.run) <br><br>    # Add toolbar button and menu item<br>    self.iface.addToolBarIcon(self.action)<br>    self.iface.addPluginToMenu("&Read shp for calculations", self.action)<br>
<br>  def unload(self):<br>    # Remove the plugin menu item and icon<br>    self.iface.removePluginMenu("&Read shp for calculations",self.action)<br>    self.iface.removeToolBarIcon(self.action)<br><br>  # run method that performs all the real work<br>
  def run(self): <br>       <br>#    fileName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Select a file:"),"", "*.shp *.gml")<br>    <br>#    if fileName.isNull():<br><br>#      QMessageBox.information(None, "Cancel", "File selection canceled")<br>
      <br>     <br><br><br>#    else:<br><br>#      print fileName<br>      <br><br>    vlayer = QgsVectorLayer("C:\\Users\\lutfi\\Documents\\tezzzz\\deneme2\\ownership.shp", "hebe", "ogr")<br>
    print vlayer.source()<br>    print vlayer.featureCount()<br>    QgsMapLayerRegistry.instance().addMapLayer(vlayer)<br>    QMessageBox.information(self.iface.mainWindow(), "info", "file: "+str(vlayer.source())+" is added.")<br>
     <br><br>    <br>    <br>        <br>    if not vlayer.isValid():<br>      print "Couldn't open the layer"<br>      pdb.set_trace()<br><br>    else:<br>      <br>#    QMessageBox.information(None, "Cancel", "File selection canceled")<br>
   <br>      provider = vlayer.dataProvider()<br>      feat = QgsFeature()<br>      allAttrs = provider.attributeIndexes()<br>      provider.select(allAttrs)<br>    <br>      while provider.nextFeature(feat):<br>        geom = feat.geometry()<br>
        import sys<br>        import os <br>#        win32api.SetFileAttributes('C://Users//lutfi//Documents//tezzzz//log.txt', win32con.FILE_ATTRIBUTE_NORMAL)<br>#        sys.stdout = open('C://Users//lutfi//Documents//tezzzz//log.txt', 777 )<br>
        print geom<br>#        QMessageBox.information(None, "Cancel", "File selection canceled")<br>        print "Feature ID %d: " % <a href="http://feat.id">feat.id</a>()<br>        if geom.type() == QGis.Point:<br>
          x = geom.asPoint()<br>          print "Point: " + str(x)<br><br>        elif geom.type() == QGis.Line:<br>          x = geom.asPolyline()<br>          print "Line: %d points" % len(x)<br><br>
        elif geom.type() == QGis.Polygon:<br>          x = geom.asPolygon()<br>          numPts = 0<br>          for ring in x:<br>            numPts += len(ring)<br>            print "Polygon: %d rings with %d points" % (len(x), numPts)<br>
        else:<br>          print "Unknown"<br>          <br>        attrs = feat.attributeMap()<br><br>        for (k,attr) in attrs.iteritems():<br>          sys.stdout = os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" )<br>
          print "%d %s" %(k, attr.toString())<br>          <br><br><br><br><br><br>        <br>        <br>      <br><br>