Getting Started With Python: Attribute Error
I'm new to python and just downloaded it today. I use it to work with web spider, so to test it and make sure everything works, I downloaded the sample code. Unfortunately it doesn't work and gives me an error:
AttributeError: MyShell object has no loaded attribute
I'm not sure if the code has its "i" error, or if I was unable to do something right when installing python. Is there anything you need to do while installing python, like adding environment variables, etc.? And what does this error actually mean?
Here is some sample code I used with the 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 source to share
And what does this error actually do? means?
An attribute in Python is a name that belongs to an object - a method or a variable. AttributeError means that the program tried to use an attribute of an object, but the object did not have the requested attribute.
For example, string objects have an "upper" attribute, which is a method that returns the uppercase version of the string. You can write a method that uses it like this:
def get_upper(my_string):
return my_string.upper()
Note, however, that there is nothing in this method to ensure that you must give it a string. You can pass a file object or a number. None of them have an attribute "top", and Python will raise an attribute error.
As to why you are seeing this in this case, you have not provided enough details for us to resolve. Add a complete error message to your question.
a source to share
1) Put your code in Try ... Except block. get information about the exception.
2) Could you please say that StackTrace data means which line # and method threw the error.
And also you can run other simple python scripts without any error. The tool just tries to run a sample script, etc.
a source to share