Python allows to use either single or double quotes for strings. I'd like to enforce only single quotes format in my projects.
Is there any specific rule in pylint or an existing pylint plugin to achieve that?
“F-strings provide a way to embed expressions inside string literals, using a minimal syntax. It should be noted that an f-string is really an expression evaluated at run time, not a constant value. In Python source code, an f-string is a literal string, prefixed with f , which contains expressions inside braces.
F-strings provide a way to embed expressions inside string literals, using a minimal syntax. It should be noted that an f-string is really an expression evaluated at run time, not a constant value. In Python source code, an f-string is a literal string, prefixed with 'f', which contains expressions inside braces.
When using f-Strings to display variables, you only need to specify the names of the variables inside a set of curly braces {} . And at runtime, all variable names will be replaced with their respective values.
To write an f-string in Python, simply preface a string with an f (or F). You can use single quotes, double quotes, or even triple quotes to create your string. Any expression you want to evaluate is placed into curly braces “{}”.
I recently wrote a pylint plugin for this: https://pypi.python.org/pypi/pylint-quotes
You can get it with
pip install pylint-quotes
Then to use it with pylint,
pylint --load-plugins pylint_quotes <module-or-package>
in the .pylintrc
file, you can configure which quotes to use:
# Set the linting for string quotes
string-quote=single
triple-quote=double
docstring-quote=double
I don't know if pylint
can currently do this, but there is an extension for flake8
called flake8-quotes
that does it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With