简体   繁体   中英

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 " ?

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"
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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM