Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6949 > unrolled thread

Re: Newby Python help needed with functions

Started byAndrew Berg <bahamutzero8825@gmail.com>
First post2011-06-03 10:10 -0500
Last post2011-06-03 10:10 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Newby Python help needed with functions Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-03 10:10 -0500

#6949 — Re: Newby Python help needed with functions

FromAndrew Berg <bahamutzero8825@gmail.com>
Date2011-06-03 10:10 -0500
SubjectRe: Newby Python help needed with functions
Message-ID<mailman.2431.1307113857.9059.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web