Solved

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

Posted on 2011-03-03
2
423 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now