~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Doc/tutorial/stdlib2.rst

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
The :mod:`repr` module provides a version of :func:`repr` customized for
17
17
abbreviated displays of large or deeply nested containers::
18
18
 
19
 
   >>> import repr   
 
19
   >>> import repr
20
20
   >>> repr.repr(set('supercalifragilisticexpialidocious'))
21
21
   "set(['a', 'c', 'd', 'e', 'f', 'g', ...])"
22
22
 
116
116
   >>> for i, filename in enumerate(photofiles):
117
117
   ...     base, ext = os.path.splitext(filename)
118
118
   ...     newname = t.substitute(d=date, n=i, f=ext)
119
 
   ...     print '%s --> %s' % (filename, newname)
 
119
   ...     print '{0} --> {1}'.format(filename, newname)
120
120
 
121
121
   img_1074.jpg --> Ashley_0.jpg
122
122
   img_1076.jpg --> Ashley_1.jpg
174
174
 
175
175
   class AsyncZip(threading.Thread):
176
176
       def __init__(self, infile, outfile):
177
 
           threading.Thread.__init__(self)        
 
177
           threading.Thread.__init__(self)
178
178
           self.infile = infile
179
179
           self.outfile = outfile
180
180
       def run(self):
198
198
While those tools are powerful, minor design errors can result in problems that
199
199
are difficult to reproduce.  So, the preferred approach to task coordination is
200
200
to concentrate all access to a resource in a single thread and then use the
201
 
:mod:`queue` module to feed that thread with requests from other threads.
202
 
Applications using :class:`Queue` objects for inter-thread communication and
203
 
coordination are easier to design, more readable, and more reliable.
 
201
:mod:`Queue` module to feed that thread with requests from other threads.
 
202
Applications using :class:`Queue.Queue` objects for inter-thread communication
 
203
and coordination are easier to design, more readable, and more reliable.
204
204
 
205
205
 
206
206
.. _tut-logging:
358
358
results in decimal floating point and binary floating point. The difference
359
359
becomes significant if the results are rounded to the nearest cent::
360
360
 
361
 
   >>> from decimal import *       
 
361
   >>> from decimal import *
362
362
   >>> Decimal('0.70') * Decimal('1.05')
363
363
   Decimal("0.7350")
364
364
   >>> .70 * 1.05
365
 
   0.73499999999999999       
 
365
   0.73499999999999999
366
366
 
367
367
The :class:`Decimal` result keeps a trailing zero, automatically inferring four
368
368
place significance from multiplicands with two place significance.  Decimal
380
380
   >>> sum([Decimal('0.1')]*10) == Decimal('1.0')
381
381
   True
382
382
   >>> sum([0.1]*10) == 1.0
383
 
   False      
 
383
   False
384
384
 
385
385
The :mod:`decimal` module provides arithmetic with as much precision as needed::
386
386