python新手。我在包中使用了一个名为pdfminer的包,在以下代码中使用了一个命令pdf2txt.py
。单引号和双引号有问题。我想在Windows中使用这样的os.system()
:
os.system('pdf2txt.py -o "E:\PDF\output.txt" "E:\PDF\A Functional Genetic Approach Identifies the PI3K Pathway as a Major Determinant of Trastuzumab Resistance in Breast Cancer.pdf"')
在Windows中,"E:\PDF\A Functional Genetic Approach Identifies the PI3K Pathway as a Major Determinant of Trastuzumab Resistance in Breast Cancer.pdf"
必须使用双引号。
现在,我使用strSource = "E:\PDF\A Functional Genetic Approach Identifies the PI3K Pathway as a Major Determinant of Trastuzumab Resistance in Breast Cancer.pdf"
,但我在StrSource
中使用os.system()
,它无法获得output.txt
。我认为strSource
可能等于'E:\PDF\A Functional Genetic Approach Identifies the PI3K Pathway as a Major Determinant of Trastuzumab Resistance in Breast Cancer.pdf'
。如何将'
转换为"
?
答案 0 :(得分:2)
如果问题与您说的相同,那么您只需使用str
replace
方法:
strSource = strSource.replace("'", '"')
例如,
In [1]: strSource = "'E:\PDF\A Functional Genetic Approach ... Cancer.pdf'"
In [2]: print(strSource)
'E:\PDF\A Functional Genetic Approach ... Cancer.pdf'
In [3]: strSource = strSource.replace("'",'"')
In [4]: print(strSource)
"E:\PDF\A Functional Genetic Approach ... Cancer.pdf"
答案 1 :(得分:0)
strTarget = "E:\PDF\output.txt"
strSource = 'E:\PDF\Vascular_smooth_muscle_contraction.pdf'
os.system('pdf2txt.py -o %s %s' % (self.strTarget,self.strSource))
有效!