(*args **kwargs) how do I use' em?

FELD Boris lothiraldan at gmail.com
Sat Jun 11 04:18:04 EDT 2011


 A good tutorial will surely help : http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/

The idea between *args and *kwargs is to create function (callables) which accepts an arbitrary number of anonymous and/or keyword arguments.

It's useful when you want to create a function that will call an another one (inheritances or decorators).

Hope this helps,
-- 
Envoyé avec Sparrow (http://www.sparrowmailapp.com/?sig)

Le samedi 11 juin 2011 à 07:01, TheSaint a écrit :

> Hello,
> I'm seldomly writng python code, nothing but a beginner code.
> 
> I wrote these lines >>
> 
> =============================================================
> _log_in= mhandler.ConnectHandler(lmbox, _logger, accs)
> multhr= sttng['multithread']
> if multhr:
>  _log_in= mhandler.mThreadSession(lmbox, _logger, accs)
> 
> for svr in servrs:
>  nmsvr, user, pwd, ptcl = servrs[svr]
>  al, dn= sttng['Cfilter']; er= sttng['filter']
>  try:
>  rx.append( _log_in.connect((nmsvr, user, pwd, ptcl, (al, dn, er))))
>  except ProtocolError:
>  print(svr+ errors['SerProb'])
>  except KeyboardInterrupt:
>  raise SystemExit(errors['YouStop'])
> if multhr:
>  for s in rx:
>  try: s.start()
>  except (ProtocolError, AttributeError):
>  print(svr+ errors['SerProb'])
>  except KeyboardInterrupt:
>  raise SystemExit(errors['YouStop'])
>  for s in rx:
>  try: s.join() # waiting all threads to finish
>  except (ProtocolError, AttributeError):
>  print(svr+ errors['SerProb'])
>  except KeyboardInterrupt:
>  raise SystemExit(errors['YouStop'])
> 
> =============================================================
> 
> Surely ugly and I believe that would be a better way to pass the arguments 
> as I mention on the subject.
> Then it should give a dictionary of keywords and some function or a 
> callable. I don't know how to put down these code lines.
> I think I should restructure many points of my data.
> 
> Any suggestion will make me happier :)
> 
> 
> -- 
> goto /dev/null
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110611/39ed2b06/attachment-0001.html>


More information about the Python-list mailing list