Python可以';无法在与脚本相同的目录中找到PDF文件

Python可以';无法在与脚本相同的目录中找到PDF文件,python,python-3.x,pdf,filesystems,Python,Python 3.x,Pdf,Filesystems,我正在编写一个程序来打开PDF文件和提取电子邮件地址,但由于某些原因,我无法打开PDF文件,因为它们找不到。以下是查找和打开文件的代码: filePath = os.getcwd() #Start Function def extractEmail(userInput): #Create object out of file that the user opens, instruct it to read binaries fileObj = open(filePath +&qu

我正在编写一个程序来打开PDF文件和提取电子邮件地址,但由于某些原因,我无法打开PDF文件,因为它们找不到。以下是查找和打开文件的代码:

filePath = os.getcwd()
#Start Function
def extractEmail(userInput):
    #Create object out of file that the user opens, instruct it to read binaries
    fileObj = open(filePath +"\\"+userInput, 'rb')
当我在userInput变量中插入一个pdf文件(位于正确的目录中)时,它会显示错误消息:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\myName\\Desktop\\Work\\MyWorkplace\\Documents\\DateOfThing\\EmailSender\\TestDoc.pdf'

您确定此文件夹结构和文件存在吗?请确保pdf未锁定或密码未锁定。确保它位于该文件夹中。还要确保在python脚本上接受pdf。