views:

273

answers:

2

I am new to python and just downloaded it today. I am using it to work on a web spider, so to test it out and make sure everything was working, I downloaded a sample code. Unfortunately, it does not work and gives me the error:

"AttributeError: 'MyShell' object has no attribute 'loaded' "

I am not sure if the code its self has an error or I failed to do something correctly when installing python. Is there anything you have to do when installing python like adding environmental variables, etc.? And what does that error generally mean?

Here is the sample code I used with imported spider class:

import chilkat
spider = chilkat.CkSpider()
spider.Initialize("www.chilkatsoft.com")
spider.AddUnspidered("http://www.chilkatsoft.com/")
for i in range(0,10):
    success = spider.CrawlNext()
    if (success == True):
        print spider.lastUrl()
    else:
        if (spider.get_NumUnspidered() == 0):
            print "No more URLs to spider"
        else:
            print spider.lastErrorText()

    #  Sleep 1 second before spidering the next URL.
    spider.SleepMs(1000)
A: 

1) Put code in Try ... Except block. get exception details.

2) Could you tell StackTrace details means which line # and method thrown error

And also are you able to run other simple python scripts without any error. Means just try to run some sample script etc.

aberry
I think its not recognizing chilkat. I have limited experience with downloading new libraries so I probably have failed to do something correctly.
Nacari
+3  A: 

And what does that error generally mean?

An Attribute in Python is a name belonging to an object - a method or a variable. An AttributeError means that the program tried to use an attribute of an object, but the object did not have the requested attribute.

For instance, string objects have the 'upper' attribute, which is a method that returns the uppercase version of the string. You could write a method that uses it like this:

def get_upper(my_string):
  return my_string.upper()

However, note that there's nothing in that method to ensure that you have to give it a string. You could pass in a file object, or a number. Neither of those have the 'upper' attribute, and Python will raise an Attribute Error.

As for why you're seeing it in this instance, you haven't provided enough detail for us to work it out. Add the full error message to your question.

Dan
Thanks, I think the error might have something to do with the classpaths. I do not think that python is recognizing the chilkat library I imported.
Nacari
I'm not sure - if it couldn't find the library, the import statement would be mentioned in the error message.
Dan
I think its just horribly written code, I am going to try a new spdier
Nacari