[Qgis-developer] printing error: AttributeError: 'int' object has no attribute 'write'

Lutfi Oduncuoglu lutfioduncuoglu at gmail.com
Sun Nov 22 10:15:36 EST 2009


Hello,

I have this error when I run my plugin my code is below. What may be the
problem?

Thanks,
Lutfi

P.S. : I tried something for this problem the line begin # mark are the
things that I tried.

# Import the PyQt and QGIS libraries
from PyQt4 import QtCore, QtGui

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from os import *
from qgis.gui import *
import sys
import pdb
# Initialize Qt resources from file resources.py
import resources
# Import the code for the dialog
from ReadDataDialog import ReadDataDialog

class ReadData:

  def __init__(self, iface):
    # Save reference to the QGIS interface
    self.iface = iface

  def initGui(self):
    # Create action that will start plugin configuration
    self.action = QAction(QIcon(":/plugins/readdata/icon.png"), \
        "Read shp for calculations", self.iface.mainWindow())
    # connect the action to the run method
    QObject.connect(self.action, SIGNAL("triggered()"), self.run)

    # Add toolbar button and menu item
    self.iface.addToolBarIcon(self.action)
    self.iface.addPluginToMenu("&Read shp for calculations", self.action)

  def unload(self):
    # Remove the plugin menu item and icon
    self.iface.removePluginMenu("&Read shp for calculations",self.action)
    self.iface.removeToolBarIcon(self.action)

  # run method that performs all the real work
  def run(self):

#    fileName =
QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Select a file:"),"",
"*.shp *.gml")

#    if fileName.isNull():

#      QMessageBox.information(None, "Cancel", "File selection canceled")




#    else:

#      print fileName


    vlayer =
QgsVectorLayer("C://Users//lutfi//Documents//tezzzz//data//roads.shp",
"hebe", "ogr")
    print vlayer.source()
    print vlayer.featureCount()
    QgsMapLayerRegistry.instance().addMapLayer(vlayer)
    QMessageBox.information(self.iface.mainWindow(), "info", "file:
"+str(vlayer.source())+" is added.")





    if not vlayer.isValid():
      print "Couldn't open the layer"
      pdb.set_trace()

    else:

#    QMessageBox.information(None, "Cancel", "File selection canceled")

      provider = vlayer.dataProvider()
      feat = QgsFeature()
      allAttrs = provider.attributeIndexes()
      provider.select(allAttrs)

      while provider.nextFeature(feat):
        geom = feat.geometry()
        import sys
        import os
#
win32api.SetFileAttributes('C://Users//lutfi//Documents//tezzzz//log.txt',
win32con.FILE_ATTRIBUTE_NORMAL)
        sys.stdout = open('C://Users//lutfi//Documents//tezzzz//log.txt',
777 )
        print geom
#        QMessageBox.information(None, "Cancel", "File selection canceled")
        print "Feature ID %d: " % feat.id()
        if geom.type() == QGis.Point:
          x = geom.asPoint()
          print "Point: " + str(x)

        elif geom.type() == QGis.Line:
          x = geom.asPolyline()
          print "Line: %d points" % len(x)

        elif geom.type() == QGis.Polygon:
          x = geom.asPolygon()
          numPts = 0
          for ring in x:
            numPts += len(ring)
            print "Polygon: %d rings with %d points" % (len(x), numPts)
        else:
          print "Unknown"

        attrs = feat.attributeMap()

        for (k,attr) in attrs.iteritems():
          print "%d: %s" % (k, attr.toString())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20091122/333bfed6/attachment-0001.html


More information about the Qgis-developer mailing list