Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

831 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