Posts: 35
Threads: 13
Joined: Oct 2017
* In Linux Mint Cinnamon, I am using Autokey 0.96.0 which uses Python 3+.
* I was told that in Python, spaces must surround the = sign in variable assignment.
* This is different from the bash files I create. The bash file fails, if spaces surround the = sign.
I couldn't find an answer, so I came to ask the sages of Python.
What is the rule about spacing regarding variable assignments?
Linux Mint Cinnamon 22 - Python 3.12.3 - Autokey-gtk 0.96.0 as of 2024-01-13.
Posts: 12,031
Threads: 485
Joined: Sep 2016
did you try it?
>>> a=3
>>> a
3
>>>
Posts: 35
Threads: 13
Joined: Oct 2017
I agree with you 100%, but I am need a clear answer in writing. I intend to fight entrenched ignorance or coding habits. This may end up in the PSC. (Python Supreme Court).
Linux Mint Cinnamon 22 - Python 3.12.3 - Autokey-gtk 0.96.0 as of 2024-01-13.
Posts: 8,160
Threads: 160
Joined: Sep 2016
It's a matter of style, not rule that will brake your code. Check PEP8:
Quote:Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).
I don't know what/how you plan to fight it, but I can tell you with 100% certainly it will be futile excersise.
Posts: 4,790
Threads: 76
Joined: Jan 2018
Jul-12-2023, 06:39 AM
(This post was last modified: Jul-12-2023, 06:39 AM by Gribouillis.)
Remark that most people follow PEP8 but PEP8 is actually a coding style for the contributors of Python's standard library. Other teams or individual programmers are free to use their own coding conventions.
Following PEP8 eases communication with other Python programmers. It also contents some automated tools that check the quality of your code.
Larz60+ and buran like this post
Posts: 8,160
Threads: 160
Joined: Sep 2016
Jul-12-2023, 06:44 AM
(This post was last modified: Jul-12-2023, 06:44 AM by buran.)
(Jul-12-2023, 06:39 AM)Gribouillis Wrote: Remark that most people follow PEP8 but PEP8 is actually a coding style for the contributors of Python's standard library. To add to @ Gribouillis remark - read at least the introduction and first section of PEP8. Anyway it's a good idea to familiarize yourself with the whole document, regardless if you decide to follow it or not.
Posts: 4,790
Threads: 76
Joined: Jan 2018
You could also reformat the code automatically with Black for example. Then you wouldn't worry again about the correct spacing between operators. You still need to read PEP8's advice on the good naming conventions for class, variables and functions.
Posts: 35
Threads: 13
Joined: Oct 2017
(Jul-12-2023, 07:06 AM)Gribouillis Wrote: You could also reformat the code automatically with Black for example. Then you wouldn't worry again about the correct spacing between operators. You still need to read PEP8's advice on the good naming conventions for class, variables and functions.
Thanks for the suggestion. "Black" is excellent, but had to revert the double quotes to single. Everything is in single quotes in the context of my use.
Linux Mint Cinnamon 22 - Python 3.12.3 - Autokey-gtk 0.96.0 as of 2024-01-13.
Posts: 4,790
Threads: 76
Joined: Jan 2018
(Aug-22-2023, 08:06 PM)ineuw Wrote: Everything is in single quotes in the context of my use. Unlike other languages like C, Python makes no difference between single quotes or double quotes for literal strings. 'hello' and "hello" represent the same string, as well as 'A' and "A"
Posts: 2,126
Threads: 11
Joined: May 2017
(Aug-22-2023, 08:06 PM)ineuw Wrote: Thanks for the suggestion. "Black" is excellent, but had to revert the double quotes to single. Everything is in single quotes in the context of my use.
It depends on your Keyboard layout. On a German layout, the double quote is Shift + 2 and the single quote is next to the Return key Shift + # .
You could try this: https://github.com/psf/black/issues/118#...-393298377
Quote:Resolution: 18.6b0 has --skip-string-normalization, or -S for short. This allows existing projects to adopt Black with less friction and works for all alternative string quotes policies.
Black still defaults to and recommends normalizing string quotes to double quotes everywhere as we believe this is a better default than single quotes, and is enforceable unlike the "single quotes for data, double quotes for human-readable strings" policy.
I hope this resolves to your satisfaction what's been the most controversial issue in Black's history.
|