[Tutor] Mail delivery failed: returning message to sender

Alan Gauld alan.gauld at yahoo.co.uk
Tue Aug 2 05:57:41 EDT 2016


Several of my messages via gmane seem to be bouncing so
I'm sending this direct to the tutor list.
Apologies if it arrives twice!

On 02/08/16 06:51, Justin Korn via Tutor wrote:

> Create a new class, SMS_store. 
> This store can hold multiple SMS messages 
> (has_been_viewed, from_number, time_arrived, text_of_SMS)

> The inbox object should provide these methods:
> my_inbox.add_new_arrival(from_number, time_arrived, text_of_SMS)
> my_inbox.message_count()
> my_inbox.get_unread_indexes()
> my_inbox.get_message(i)
> my_inbox.delete(i)     # Delete the message at index i
> my_inbox.clear()       # Delete all messages from inbox

> The following attachment is what I have so far:

Unfortunately this is a text based mailing list so your
attachment has been removed by the server. We can't see
your code. However we do see the error message this
time so we can make a guess...

> Traceback (most recent call last):
>   File "/Applications/Python Assignments/C15E6_JustinKorn.py", line 58, in <module>
>     my_inbox.get_message(i)
> NameError: name 'i' is not defined

It says 'i' is not defined.
I suspect you have used i as the parameter name in
your methods as  suggested in the assignment.
Then you have tried to call the method and also
passed an 'i' in when making the call (as shown
in the error message). But the i in the method
definition is only visible inside the method code.
You must define the value you pass in. Something like:

my_inbox = SMS_store()
i = 1   # define a value for i
print( my_inbox.get_message(i) )  # use your local i

# now use the method to print all messages
for msg_number in range(my_inbox.message_count()):
    print( my_inbox.get_message(msg_number) )

hth
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos






More information about the Tutor mailing list