Triple quotation marks has 2 functions?

Hi!

I have experienced 2 types of strangeness in the PyCharm editor today:

1. First, when I used triple quotation marks (""") it resulted in a multi-line comment. Then, when I tried again, it resulted in what PyCharm calls a "Triple-quoted string". That's quite strange.

2. Normally 'import' is marked in blue, put when I try 'import PIL' or

'import PIL.Image
import PIL.ImageDraw'

it is grey, although the same python source file has been using 'from PIL import Image as Image' until now, in blue...

I have "attached" a screen shot below:

7 comments
Comment actions Permalink

Hi,

"""" marks a multi-line string literal. The comments in Python are marked by #

Grey marks unused imports, they should change color as soon as you include a usage in the code.

If you think there's still an issue, please provide steps to reproduce.

0
Comment actions Permalink

Hi Andrey

Thank you for your reply!

But why do """ have one meaning in one place and another meaning in another place, as you can see on the screen shot?

About 'import': I think I DO use PIL here:

# Convert from eps format to gif format using PIL (=Pillow)
img = Image.open(filename + ".eps")
img.save(filename + ".gif", "gif")

 

0
Comment actions Permalink

Please provide a full code snippet to reproduce the issue locally. I suggest creating a sample .py file and providing a link which I can download. I can't tell just from the screenshot why parts of your code are marked as unused.

0
Comment actions Permalink

Hi!

Thank you.

I have placed a sample Python program here:

https://www.transformation.dk/deling/graphics-test1.py

Now, 'import' is blue again. So it's only the """ that act strangely. :-)

0
Comment actions Permalink

Thanks for the snippet, I see now. The first string literal in a script (before any other uncommented instruction) is treated as documentation string, so it's rendered as such, and has separate color scheme settings in **File | Settings | Editor | Color Scheme | Python**

Please check your settings, maybe you have changed it's color scheme so it looks grey. When I paste your snippet, the docstring is displayed correctly for me, I'm using default color scheme.

0
Comment actions Permalink

OK!

So PyCharm interprets """ in 2 different ways depending on where in the source code it is used. That more or less answers my question. But isn't there a way you can comment out a block of lines without having to mark each line?

Thank you!

0
Comment actions Permalink

Correct, there are normal string literals, and documentation strings, depending on where the string is placed.

And no, Python doesn't have block comments, only line comments. You can comment out multiple lines though by selecting them and hitting the comment hotkey.

0

Please sign in to leave a comment.