Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:
        path_name.append(str(prjfi.absolutePath()))
            filename = str(prjfi.fileName())
            if filename.count(".") > 0:
              path_name.append(filename.split(".")[0])
            else:
              path_name.append(filename)
            path_name.append(prjfi.fileName())
    else:
            path_name.append(r'C:\Users')
            path_name.append(r'test')
    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 ] (python.org/dev/peps/pep-0008). It well help others to read your code. –  LarsVegas Oct 15 '12 at 9:16
add comment

1 Answer 1

up vote 3 down vote accepted

You are assigning currentprofile to the function named projectfilepathname:

Change this:

currentprofile = self.projectfilepathname

to

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
add comment

Your Answer

 
discard

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.