[Tutor] PyCharm and triple quotes - Was: Tutor Digest, Vol 232, Issue 12
dn
PythonList at DancesWithMice.info
Tue Jun 20 18:47:33 EDT 2023
On 21/06/2023 00.19, Alan Gauld via Tutor wrote:
> On 20/06/2023 07:53, HARSH MOHAN wrote:
...
>> website because pycharm is for building high level projects
Yes, use the Python-REPL, working line-by-line, for experimenting,
testing your own knowledge, and similar.
Yes, could use a light-weight text-editor, eg xed, nano, notepad; to
dash-off a short code-snippet (and run from command-line) - rather than
waiting for a full-fat IDE to load.
However, both of those are available within PyCharm, if it is already
running. Don't most Python.devs have their IDE running all-the-time?
>> and for your code use three inverted codes as:* print( """ write your thing
>> here """)*
>
> Triple quotes don't normally offer any advantage for short strings
> and can lead to obscure bugs. Is there some extra advantage if
> using PyCharm?
None!
Like most 'intelligent' editors, as soon as one opens a string*, PyCharm
will auto-magically enter the closing-delimiter. Anything typed will
become part of the string...
* apostrophe/single-quotation mark, double quotes/quotation mark, or
either of the triple-quotes
Personally, reserve triple-quotes for docstrings (my PyCharm flags any
function (etc) def-ined without a docstring!), unless have some long,
multi-line string to be reproduced verbatim. Quotation-marks are used
for strings, on the grounds that am more likely to encounter a
possessive (and thus apostrophe + s) within some narrative, than to need
double-quotes) - at which point can either swap* delimiters or use an
(ugly) escape.
* PyCharm does help with those operations:
- if highlight a string and then enter string-delimiter of some kind, it
will surround the text and turn it into a string-literal
- similarly, if highlight an existing string (including both
quotation-marks) and type an alternate string-delimiter, PyCharm will
make an intelligent change.
Disclaimer: JetBrains sponsor our PUG by donating a monthly door-prize
of a 12-month Professional license. I am currently using PyCharm -
however, switch between IDEs when working for a period of time, with a
team standardised on some other tool...
YMMV!
--
Regards,
=dn
More information about the Tutor
mailing list