Solved

Why do I get a string argument error when calling a package class located in another folder?

Posted on 2011-03-03
2
427 Views
Last Modified: 2012-06-27
I have written a Python 2.5.6 (ESRI install) calling routine that is located at ..fc_main\Calls (see attachment 1).  My called package (attachment 2) is located at ..fc_main\Classes.  When I run the calling routine in IDLE version 2.6.5, I get the following error message on the last line:

Traceback (most recent call last):
  File "C:\Projects\Front Counter\fc_main\Calls\TileCall.py", line 8, in <module>
    VisibleCheck.CheckOnOffLayers("Front Counter Data", "Parcels", "False")
TypeError: unbound method CheckOnOffLayers() must be called with VisibleCheck instance as first argument (got str instance instead).

Can you explain why the method is unbound, and why I'm getting this message?

Thanks in advance. TileCall.py MCPIClasses.py
0
Comment
Question by:cshore12
2 Comments
 
LVL 4

Accepted Solution

by:
ute_arbeit earned 300 total points
ID: 35028429
There are two things to change if you wanted CheckOnOffLayers to be a 'normal' method defined in a class:

1. The first argument for a class method is always the reference to the class instance, as a convention named 'self'. So your CheckOnOffLayers method must be defined like this:
def CheckOnOffLayers(self, strDF, strLayerName, blnLayer):

Open in new window


2. And you have to create an instance of your VisibleCheck class and call the method on this instance:
visibleCheck = VisibleCheck()
visibleCheck.CheckOnOffLayers("Front Counter Data", "Parcels", "False")

Open in new window


Or if you wanted CheckOnOffLayers to be a static class method you have to add the decorator @staticmethod to it:
@staticmethod
def CheckOnOffLayers(strDF, strLayerName, blnLayer):

Open in new window


and call it on the class itself:
VisibleCheck.CheckOnOffLayers("Front Counter Data", "Parcels", "False")

Open in new window

0
 

Author Closing Comment

by:cshore12
ID: 35037183
Both approaches worked like a charm.

I'm also finding that the importing the arcpy module can be very touchy.  I added the appropriate paths to the path and PYTHONPATH system variables, and today the import (obviously) is working OK.  Let's hope it will stick.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question