is there any principle when writing python function

rantingrick rantingrick at gmail.com
Sat Aug 27 00:37:11 CEST 2011


On Aug 26, 1:16 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:

> (3) Fault isolation. If you have a 100 line function that fails on line 73,
> that failure may have been introduced way back in line 16. By splitting the
> function up into smaller functions, you can more easily isolate where the
> failure comes from, by checking for violated pre- and post-conditions.

What's wrong Steven, are track backs too complicated for you?

############################################################
# START DUMMY SCRIPT
############################################################
def very_long_function():
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(object)
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
    max(range(5))
#
print 'blah'
print 'blah'
print 'blah-blah'
very_long_function()
############################################################
# END DUMMY SCRIPT
############################################################

Traceback (most recent call last):
  File "C:/Python27/test33333.py", line 48, in <module>
    very_long_function()
  File "C:/Python27/test33333.py", line 26, in very_long_function
    max(object)
TypeError: 'type' object is not iterable

Oh the humanity!



More information about the Python-list mailing list