Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm still trying to write a python plugin to create an input file for an urban climate model out of three shape files. Now I stumbeled into another problem, that I think is an easy one, but I just can't see whats wrong. I wrote a little function to get me the path and file name of the current project file (as I want the result file of my calculations to be called like the project file by default).

def projectfilepathname(): 
    # function to extract the file path and name of the current project file
    qgis.mainWindow().statusBar().showMessage("Getting project name and path")
    prjfi = QFileInfo(QgsProject.instance().fileName())
    path_name = []
    if prjfi:
            filename = str(prjfi.fileName())
            if filename.count(".") > 0:
    return path_name

I call the function by

currentprofile = self.projectfilepathname

but that doesn't seem to work. At least I get an error for the next line

currentprofile_dir = currentprofile[1]

telling me 'instancemethod' object has no attribute 'getitem'. Maybe I'm wrong, but I have the impression that the function is not called, but its name is saved to currentprofile. Whats wrong?

share|improve this question
Your indentation levels, at least how you posted them here, are not quite right. You also should take a look at [the python style guide ] ( It well help others to read your code. – LarsVegas Oct 15 '12 at 9:16
up vote 3 down vote accepted

You are assigning currentprofile to the function named projectfilepathname:

Change this:

currentprofile = self.projectfilepathname


currentprofile = self.projectfilepathname()

You should also change the method def to def projectfilepathname(self):

share|improve this answer
That did it. I thought it was something like that. I tried self.projectfilepathname() before, but without "self" in the functions definition and got another error. Thats why I removed the brackets. Thank you! – Dominik Froehlich Oct 15 '12 at 9:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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