"import decimal"会引发错误

far*_*raz 4 python module decimal pypdf

这是我正在使用的代码

import os
import decimal
from pyPdf import PdfFileReader
path = r"E:\python\Real Python\Real Python\Course materials\Chapter 8\Practice files"
inputFileName = os.path.join(path,"Pride and Prejudice.pdf")
inputFile = PdfFileReader(file(inputFileName,"rb"))

print "Number of pages:", inputFile.getNumPages()
print "Title:", inputFile.getDocumentInfo().title
Run Code Online (Sandbox Code Playgroud)

现在,当我运行此代码时,我收到一个错误:模块'对象'没有属性'Number'

当我运行上面的代码时,我获取了整个输出的屏幕截图,包含错误和所有内容.所以,请看看,让我知道什么是错的?

在此输入图像描述

Ery*_*Sun 12

这是一个打印输出的所有数字,最多50个,不能被3整除.它可能在一个numbers模块上sys.path,它影响标准库numbers.看看它在哪里:

import numbers
print numbers.__file__
Run Code Online (Sandbox Code Playgroud)

  • 哇!这很有效.我之前创建了一个用于解决练习的数字文件,似乎这个文件被调用而不是数字模块.我更改了数字文件的名称,现在,它正常工作.非常感谢. (2认同)