Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6949
| Date | 2011-06-03 10:10 -0500 |
|---|---|
| From | Andrew Berg <bahamutzero8825@gmail.com> |
| Subject | Re: Newby Python help needed with functions |
| References | <BANLkTinpQGQ0wtdkLuVegy_SmyvurQs-yg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2431.1307113857.9059.python-list@python.org> (permalink) |
On 2011.06.03 09:42 AM, Cathy James wrote:
> I need a jolt here with my python excercise, please somebody!! How can
> I make my functions work correctly? I tried below but I get the
> following error:
>
> if f_dict[capitalize]:
>
> KeyError: <function capitalize at 0x00AE12B8>
>
...
>
> def capitalize (s):
> """capitalize accepts a string parameter and applies the
> capitalize() method"""
> s.capitalize()
>
...
>
> f_dict = {'capitalize': 'capitalize(s)',
>
Your capitalize() function doesn't return anything, therefore
f_dict[capitalize] won't contain anything. Your string s will still be
changed (inside the function) when the function is called, but there is
still no value associated with capitalize().
Also, capitalize in f_dict[capitalize] points to the capitalize function
object instead of the entry in the dictionary. You should call
f_dict['capitalize'] instead.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Newby Python help needed with functions Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-03 10:10 -0500
csiph-web