¿Qué significan estas definiciones de parámetros en Python?

Many different representation of parameters in python such as :

urllib2.urlopen(url[, data][, timeout])

urllib2.build_opener([handler, ...])

cookielib.MozillaCookieJar(filename, delayload=None, policy=None)


urllib2.urlopen(url[, data][, timeout])

y

urllib2.urlopen(url,data,timeout)

Does the first one means all the url ,data and timeout can be passed as list?

preguntado el 01 de julio de 12 a las 05:07

2 Respuestas

I know that the parameter in second method is a list

This is incorrect. Square brackets in command/function documentation denote optional parameters. Note that in Python order of parameters matter, so you'll need to use keyword arguments to omit parameters in the middle.

urllib2.urlopen(someurl, somedata, sometimeout)
urllib2.urlopen(someurl)
urllib2.urlopen(someurl, somedata)
urllib2.urlopen(someurl, timeout=sometimeout)

urllib2.build_opener()
urllib2.build_opener(handler1)
urllib2.build_opener(handler1, handler2)
urllib2.build_opener(handler1, handler2, handler3)

Respondido 01 Jul 12, 05:07

It's standard notation for optional arguments... ie you may pass data, optionally followed by timeout, or as you have its name, pass timeout without data using timeout=...

Respondido 01 Jul 12, 05:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.