Changeset 30


Ignore:
Timestamp:
01/07/09 10:57:01 (4 years ago)
Author:
facundobatista
Message:

Un par de secciones.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/traducidos/stdlib.rst

    r26 r30  
    103103 
    104104   >>> import re 
    105    >>> re.findall(r'\bf[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 because 
    111 they are easier to read and debug:: 
    112  
    113    >>> 'tea for too'.replace('too', 'two') 
    114    'tea 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 
     110Cuando se necesita algo más sencillo solamente, se prefieren los métodos de 
     111las cadenas porque son más fáciles de leer y depurar. 
     112 
     113   >>> 'te para tos'.replace('tos', 'dos') 
     114   'te para dos' 
    115115 
    116116 
    117117.. _tut-mathematics: 
    118118 
    119 Mathematics 
    120 =========== 
    121  
    122 The :mod:`math` module gives access to the underlying C library functions for 
    123 floating point math:: 
     119Matemática 
     120========== 
     121 
     122El módulo :mod:`math` permite el acceso a las funciones de la biblioteca C 
     123subyacente para la matemática de punto flotante:: 
    124124 
    125125   >>> import math 
     
    129129   10.0 
    130130 
    131 The :mod:`random` module provides tools for making random selections:: 
     131El módulo :mod:`random` provee herramientas para realizar selecciones al azar:: 
    132132 
    133133   >>> import random 
    134    >>> random.choice(['apple', 'pear', 'banana']) 
    135    'apple' 
    136    >>> random.sample(xrange(100), 10)   # sampling without replacement 
     134   >>> random.choice(['manzana', 'pera', 'banana']) 
     135   'manzana' 
     136   >>> random.sample(xrange(100), 10)   # elección sin reemplazo 
    137137   [30, 83, 16, 4, 8, 81, 41, 50, 18, 33] 
    138    >>> random.random()    # random float 
     138   >>> random.random()    # un float al azar 
    139139   0.17970987693706186 
    140    >>> random.randrange(6)    # random integer chosen from range(6) 
     140   >>> random.randrange(6)    # un entero al azar tomado de range(6) 
    141141   4 
    142142 
     
    144144.. _tut-internet-access: 
    145145 
    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:: 
     146Acceso a Internet 
     147================= 
     148 
     149Hay varios módulos para acceder a internet y procesar sus protocolos.  Dos de 
     150los más simples son :mod:`urllib2` para traer data de URLs y :mod:`smtplib` 
     151para mandar correos:: 
    152152 
    153153   >>> import urllib2 
    154154   >>> 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 Time 
     155   ...     if 'EST' in line or 'EDT' in line:  # buscamos la hora del este 
    156156   ...         print line 
    157157 
     
    160160   >>> import smtplib 
    161161   >>> server = smtplib.SMTP('localhost') 
    162    >>> server.sendmail('soothsayer@example.org', 'jcaesar@example.org', 
    163    ... """To: jcaesar@example.org 
    164    ... From: soothsayer@example.org 
     162   >>> server.sendmail('soothsayer@ejemplo.org', 'jcaesar@ejemplo.org', 
     163   ... """To: jcaesar@ejemplo.org 
     164   ... From: soothsayer@ejemplo.org 
    165165   ... 
    166    ... Beware the Ides of March. 
     166   ... Ojo al piojo. 
    167167   ... """) 
    168168   >>> server.quit() 
    169169 
    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 
     171máquina local) 
    171172 
    172173 
     
    228229that answers those questions immediately. 
    229230 
    230 For example, it may be tempting to use the tuple packing and unpacking feature 
     231For ejemplo, it may be tempting to use the tuple packing and unpacking feature 
    231232instead of the traditional approach to swapping arguments. The :mod:`timeit` 
    232233module quickly demonstrates a modest performance advantage:: 
     
    255256tests embedded in a program's docstrings.  Test construction is as simple as 
    256257cutting-and-pasting a typical call along with its results into the docstring. 
    257 This improves the documentation by providing the user with an example and it 
     258This improves the documentation by providing the user with an ejemplo and it 
    258259allows the doctest module to make sure the code remains true to the 
    259260documentation:: 
     
    293294 
    294295Python has a "batteries included" philosophy.  This is best seen through the 
    295 sophisticated and robust capabilities of its larger packages. For example: 
     296sophisticated and robust capabilities of its larger packages. For ejemplo: 
    296297 
    297298* The :mod:`xmlrpclib` and :mod:`SimpleXMLRPCServer` modules make implementing 
Note: See TracChangeset for help on using the changeset viewer.