Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-03
2
Medium Priority
?
445 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 1200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

618 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