decimal problem

Discussion in 'Mac Programming' started by jamesapp, Jul 10, 2008.

  1. jamesapp macrumors 6502a

    Joined:
    Mar 7, 2008
    #1
    working on a python programming book.
    in the book there is a section on numbers. One numeric type according to the book was introduced with Python 2.4, it is the decimal object. In the book they are using the interactive Python prompt and they say to type the following:
    Code:
    decimal.Decimal(1) / decimal.Decimal(7)
    
    and in the book they show there answer:
    Decimal("0.142857...etc.")
    earlier in the book they say to import, the code that is needed to work with Decimals
    by including the following code at the interactive prompt:
    Code:
    from decimal import Decimal
    
    when i go to run the code from the book i get the following error from my Python interactive prompt:
    Code:
    >>> decimal.Decimal(1) / decimal.Decimal(7)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'decimal' is not defined
    
    any help?
     
  2. AlmostThere macrumors 6502a

    #2
    You don't need to qualify Decimal with decimal if you have explicitly imported it.

    Just write Decimal(1)
     

Share This Page