0

I want to write a documentation with Sphinx using reStructuredText.

In my documentation I want to add this line of python code, which uses an apostrophe after the name jack. This apostrophe is escaped by a backslash in Python:

print('I am jack\'s raging bile duct')

When I add this to a reStructuredText (rst) file like this:

This is a simple example:
::

print('I am jack\'s raging bile duct')

after compiling to a html file I will see this:

enter image description here

How can I get rid of the backslash \ in my rst/Sphinx output html and still use the aposthrophe after jack and ' ?

StefanOverFlow
  • 389
  • 4
  • 17
  • 1
    I might be missing something, but are you trying to show a purposefully wrong Python syntax? – sinoroc Jan 23 '20 at 15:36
  • You mean: print('I am jack\'s raging bile duct')? What is wrong with it? When I run the script it prints "I am jack's raging bile duct". See also https://stackoverflow.com/questions/14104728/not-able-to-print-statements-with-apostrophe-in-it-in-python-invalid-syntax-e – StefanOverFlow Jan 23 '20 at 16:02
  • 1
    I think I see what is a little confusing regarding my question. Yes I am actually looking for "wrong Python syntax", as I use this format in a totally different context. I just chose the Python example to illustrate the issue. – StefanOverFlow Jan 23 '20 at 16:08
  • 1
    OK, then I would just remove the backslash. I don't think _docutils_ nor _Sphinx_ care about it. The syntax highlighting might be wrong though, so you might want to disable it. – sinoroc Jan 23 '20 at 16:10

1 Answers1

1

You can use double quotes

print("I am jack's raging bile duct")
hurlenko
  • 1,363
  • 2
  • 12
  • 17
  • Yes, but I am looking for a solution to use ' instead of double quotes. – StefanOverFlow Jan 23 '20 at 15:31
  • 2
    You can't use single quote in a single-quoted string. It is not valid python code. You can use ` as an apostrophe instead – hurlenko Jan 23 '20 at 15:34
  • Why, what is wrong with it? When I run the script it prints "I am jack's raging bile duct". https://stackoverflow.com/questions/14104728/not-able-to-print-statements-with-apostrophe-in-it-in-python-invalid-syntax-e – StefanOverFlow Jan 23 '20 at 16:03
  • I think I see what is a little confusing regarding my question. Yes I am actually looking for "wrong Python syntax", as I use this format in a totally different context. I just chose the Python example to illustrate the issue. – StefanOverFlow Jan 23 '20 at 16:09
  • 2
    Well, what stopped from removing the backslash. By opening this issue I assumed you wanted to preserve code validity. There are multiple ways to avoid the backslash by using double quotes, triple double or single quotes (`'''` and `"""`), unicode escape sequences (`\u0001`) etc. If you're good with invalid syntax then just remove the backslash. – hurlenko Jan 23 '20 at 16:16