Changeset 30 for trunk/traducidos/stdlib.rst
- Timestamp:
- 01/07/09 10:57:01 (4 years ago)
- File:
-
- 1 edited
-
trunk/traducidos/stdlib.rst (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/traducidos/stdlib.rst
r26 r30 103 103 104 104 >>> import re 105 >>> re.findall(r'\b f[a-z]*', 'which foot or hand fell fastest')106 [' foot', 'fell', 'fastest']107 >>> re.sub(r'(\b[a-z]+) \1', r'\1', ' cat in the the hat')108 ' cat in the hat'109 110 When only simple capabilities are needed, string methods are preferred because111 they are easier to read and debug:: 112 113 >>> 'te a for too'.replace('too', 'two')114 'te a for two'105 >>> re.findall(r'\bt[a-z]*', 'tres felices tigres comen trigo') 106 ['tres', 'tigres', 'trigo'] 107 >>> re.sub(r'(\b[a-z]+) \1', r'\1', 'gato en el el sombrero') 108 'gato en el sombrero' 109 110 Cuando se necesita algo más sencillo solamente, se prefieren los métodos de 111 las cadenas porque son más fáciles de leer y depurar. 112 113 >>> 'te para tos'.replace('tos', 'dos') 114 'te para dos' 115 115 116 116 117 117 .. _tut-mathematics: 118 118 119 Mat hematics120 ========== =121 122 The :mod:`math` module gives access to the underlying C library functions for 123 floating point math::119 Matemática 120 ========== 121 122 El módulo :mod:`math` permite el acceso a las funciones de la biblioteca C 123 subyacente para la matemática de punto flotante:: 124 124 125 125 >>> import math … … 129 129 10.0 130 130 131 The :mod:`random` module provides tools for making random selections::131 El módulo :mod:`random` provee herramientas para realizar selecciones al azar:: 132 132 133 133 >>> import random 134 >>> random.choice([' apple', 'pear', 'banana'])135 ' apple'136 >>> random.sample(xrange(100), 10) # sampling without replacement134 >>> random.choice(['manzana', 'pera', 'banana']) 135 'manzana' 136 >>> random.sample(xrange(100), 10) # elección sin reemplazo 137 137 [30, 83, 16, 4, 8, 81, 41, 50, 18, 33] 138 >>> random.random() # random float138 >>> random.random() # un float al azar 139 139 0.17970987693706186 140 >>> random.randrange(6) # random integer chosen fromrange(6)140 >>> random.randrange(6) # un entero al azar tomado de range(6) 141 141 4 142 142 … … 144 144 .. _tut-internet-access: 145 145 146 Internet Access 147 =============== 148 149 There are a number of modules for accessing the internet and processing internet 150 protocols. Two of the simplest are :mod:`urllib2` for retrieving data from urls 151 and :mod:`smtplib` for sending mail::146 Acceso a Internet 147 ================= 148 149 Hay varios módulos para acceder a internet y procesar sus protocolos. Dos de 150 los más simples son :mod:`urllib2` para traer data de URLs y :mod:`smtplib` 151 para mandar correos:: 152 152 153 153 >>> import urllib2 154 154 >>> for line in urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl'): 155 ... if 'EST' in line or 'EDT' in line: # look for Eastern Time155 ... if 'EST' in line or 'EDT' in line: # buscamos la hora del este 156 156 ... print line 157 157 … … 160 160 >>> import smtplib 161 161 >>> server = smtplib.SMTP('localhost') 162 >>> server.sendmail('soothsayer@e xample.org', 'jcaesar@example.org',163 ... """To: jcaesar@e xample.org164 ... From: soothsayer@e xample.org162 >>> server.sendmail('soothsayer@ejemplo.org', 'jcaesar@ejemplo.org', 163 ... """To: jcaesar@ejemplo.org 164 ... From: soothsayer@ejemplo.org 165 165 ... 166 ... Beware the Ides of March.166 ... Ojo al piojo. 167 167 ... """) 168 168 >>> server.quit() 169 169 170 (Note that the second example needs a mailserver running on localhost.) 170 (Notá que el segundo ejemplo necesita un servidor de correo corriendo en la 171 máquina local) 171 172 172 173 … … 228 229 that answers those questions immediately. 229 230 230 For e xample, it may be tempting to use the tuple packing and unpacking feature231 For ejemplo, it may be tempting to use the tuple packing and unpacking feature 231 232 instead of the traditional approach to swapping arguments. The :mod:`timeit` 232 233 module quickly demonstrates a modest performance advantage:: … … 255 256 tests embedded in a program's docstrings. Test construction is as simple as 256 257 cutting-and-pasting a typical call along with its results into the docstring. 257 This improves the documentation by providing the user with an e xampleand it258 This improves the documentation by providing the user with an ejemplo and it 258 259 allows the doctest module to make sure the code remains true to the 259 260 documentation:: … … 293 294 294 295 Python has a "batteries included" philosophy. This is best seen through the 295 sophisticated and robust capabilities of its larger packages. For e xample:296 sophisticated and robust capabilities of its larger packages. For ejemplo: 296 297 297 298 * The :mod:`xmlrpclib` and :mod:`SimpleXMLRPCServer` modules make implementing
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/python-tutorial/chrome/site/your_project_logo.png)