Solved

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

Posted on 2011-03-03
2
429 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

732 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