gkleeshh
gkleeshh

Reputation: 11

How to convert a string python single quotes double quotes

New to python. I used a package named pdfminer, in the package, there is a command pdf2txt.py used in the following code. I have a problem in single quotes and double quotes. I want to use os.system() like this in Windows:

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"')

In Windows, "E:\PDF\A Functional Genetic Approach Identifies the PI3K Pathway as a Major Determinant of Trastuzumab Resistance in Breast Cancer.pdf" must use double quotes.

Now, I use strSource = "E:\PDF\A Functional Genetic Approach Identifies the PI3K Pathway as a Major Determinant of Trastuzumab Resistance in Breast Cancer.pdf", but I use StrSource in os.system(),it can't get output.txt. I think strSource may be equal to 'E:\PDF\A Functional Genetic Approach Identifies the PI3K Pathway as a Major Determinant of Trastuzumab Resistance in Breast Cancer.pdf'. How can I convert the ' to "?

Upvotes: 0

Views: 355

Answers (2)

gkleeshh
gkleeshh

Reputation: 11

strTarget = "E:\PDF\output.txt"
strSource = 'E:\PDF\Vascular_smooth_muscle_contraction.pdf'
os.system('pdf2txt.py -o %s %s' % (self.strTarget,self.strSource))

It works!

Upvotes: 0

xnx
xnx

Reputation: 25550

If the problem is as you say, then you can simply use the str replace method:

strSource = strSource.replace("'", '"')

For example,

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"

Upvotes: 2

Related Questions