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?

  • 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 ] (python.org/dev/peps/pep-0008). It well help others to read your code.
    – LarsVegas
    Oct 15, 2012 at 9:16

1 Answer 1


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):

  • 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! Oct 15, 2012 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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