0

Even after 3 years of python programming, I still interchangeably write strings using either the single quotes or double quotes ('my string' vs "my string"). It seems that there is no single standard within the community, and I often see the two types of string in a same project.

Purely for the sake of consistency, I'd like to work with a single format from now on. I have found no options in PyCharm that enforces a single string style. I am looking for such a tool (or a way to achieve this in PyCharm alone), one that would replace a single-quote string by a double-quote one on typing, or vice-versa.

For now I am working with a simple regex, I run a search and replace operation on all project files when I am done working. The downsides is that it fails on edge cases and it is not automatic.

0

Can I suggest installing and using Black which is a tool that:

  • Will reformat your code so as to minimize diffs on version control systems going forward.
  • Black prefers double quotes (" and """) over single quotes (' and '''). It will replace the latter with the former as long as it does not result in more backslash escapes than before.
  • Does a lot of other good stuff.
  • Black can be installed by running pip install black. It requires Python 3.6.0+ to run but you can reformat Python 2 code with it, too.
  • Allows many configuration options including which python version is targeted.
  • Can be called from the command line or integrated into many IDEs/Editors including pyCharm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.