Chris, Thanks for your clarifications
> > I am a newbie. I am reading > > http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html > > Defining a function with "N" arguments and calling them in "M" different > > ways. Why does it have to be this complicated ? I like the idea of > calling > > the function by explicitly naming the arguments, but there are so many > other > > ways here that is very confusing. Do people really use all these features > ? > > Perhaps, there is a equivalent book to "Javascript: Good Parts" for > Python ? > > Oh $DEITY, don't even compare Python to JavaScript. At least in > Python, when you try to access a non-existent attribute, a proper > NameError exception is thrown rather than silently getting back > "undefined"... (*has traumatic horror story flashback*) I did not try to compare python to Javascript. Just because there are ten different ways of doing certain things, not all of them may be used. Over a period of time, people tend to use certain features more and more. Javascript is a different beast where some of the features need to be avoided for writing good programs. I don't know anything about python. But it is possible that there is a subset that people use frequently which may be sufficient to write good programs. Sure, that would not help me the python interview test :-) > > The calling syntax is not so much complicated as it is liberating. > Are you a C junkie who has never heard of named arguments? > Just use the call sequence like you've always done. > Are you a exacting Smalltalk or Objective-C person who likes to name > all the arguments all the time for clarity? > You can do that. That's where I fit. I did not expect to see more than that :-) > Do you want to call a function with lots of default arguments but only > want to override a couple of them? > Specifying them by name lets you do that succinctly. > Do you not want to have to worry about the order of the parameters > because it seems kinda arbitrary? > Then specify the arguments by name. > etc... > > And if you try and specify an argument twice, Python will throw an > error, so anything truly confusing will get caught right away. > And there's only one definition syntax, so while the call could be > complicated, figuring out what it means by looking to the definition > is fairly easy. > > There really aren't that many ways it's done in practice. In practice, > the following styles cover 90% of cases: > - All named arguments: foo(bar=a, baz=b, qux=c) > - All sequential arguments: foo(a, b, c) > - All sequential arguments, with a few optional arguments given by > name: foo(a, b, c, flag=True, style=qux) - Simple pass-through: foo(*args, **kwargs) > > Granted, there's 4 of them, but each taken by itself seems pretty easy > to read, IMHO. So, all four of them above has its use cases in practice i guess. thanks mohan > > Cheers, > Chris > -- > http://blog.rebertia.com >
-- http://mail.python.org/mailman/listinfo/python-list