Discussion:
Pycharm Won't Do Long Underscore
(too old to reply)
Tony Kaloki
2020-06-23 19:18:18 UTC
Permalink
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: Tony Kaloki<mailto:***@live.co.uk>
Sent: 23 June 2020 19:45
To: python-***@python.org<mailto:python-***@python.org>
Subject: Pycharm Won't Do Long Underscore


Hi Guys,
I’ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I’ve come across a problem that’s stopped me in my tracks.
When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can’t find any answers on the web and I’m not sure if I can go any further in my learning without being able to get long underscores.
Sorry if I’m just being really dense, but like I said I’m an absolute beginner. Thanks for your time,
Tony
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
MRAB
2020-06-23 20:44:24 UTC
Permalink
On 2020-06-23 20:18, Tony Kaloki wrote:
>
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
> From: Tony Kaloki<mailto:***@live.co.uk>
> Sent: 23 June 2020 19:45
> To: python-***@python.org<mailto:python-***@python.org>
> Subject: Pycharm Won't Do Long Underscore
>
>
> Hi Guys,
> I’ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I’ve come across a problem that’s stopped me in my tracks.
> When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can’t find any answers on the web and I’m not sure if I can go any further in my learning without being able to get long underscores.
> Sorry if I’m just being really dense, but like I said I’m an absolute beginner. Thanks for your time,
>
The "__" is 2 underscores; it's just that they usually appear joined
together in many fonts.

If you try:

print('_' * 2)

do they appear joined together or separate? If they appear separate,
then you can see that that's just how they're displayed in that funt.
Tony Kaloki
2020-06-23 20:49:36 UTC
Permalink
Alexander,
Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?
In any case, thanks again for your quick and easy to follow - even for me - reply.
Tony

Get Outlook for Android<https://aka.ms/ghei36>

________________________________
From: Alexander Neilson <***@neilson.net.nz>
Sent: Tuesday, June 23, 2020 9:28:37 PM
To: Tony Kaloki <***@live.co.uk>
Cc: python-***@python.org <python-***@python.org>
Subject: Re: Pycharm Won't Do Long Underscore

Hi Tony

The “long underscore” (often called Dunder as “double underscore”) is actually two underscores as you are seeing shown in PyCharm.

However the display of it as one long underscore is a ligature (special font display to communicate clearer) and to enable these in PyCharm go to the settings dialog (depending on windows or Mac this could be in different locations) and select Editor > Font

In that screen select “enable font ligatures” and if your font supports it (like the default JetBrains Mono does) that will start to display the double underscores as a single long underscore.

Regards
Alexander

Alexander Neilson
Neilson Productions Limited
021 329 681
***@neilson.net.nz

> On 24/06/2020, at 07:57, Tony Kaloki <***@live.co.uk> wrote:
>
> 
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
> From: Tony Kaloki<mailto:***@live.co.uk>
> Sent: 23 June 2020 19:45
> To: python-***@python.org<mailto:python-***@python.org>
> Subject: Pycharm Won't Do Long Underscore
>
>
> Hi Guys,
> I’ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I’ve come across a problem that’s stopped me in my tracks.
> When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can’t find any answers on the web and I’m not sure if I can go any further in my learning without being able to get long underscores.
> Sorry if I’m just being really dense, but like I said I’m an absolute beginner. Thanks for your time,
> Tony
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
> --
> https:/
Christian Gollwitzer
2020-06-24 05:15:36 UTC
Permalink
Am 23.06.20 um 22:49 schrieb Tony Kaloki:
> Alexander,
> Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?

Python only ever sees two separate underscores. There is no long
underscore, its only the way it is printed to your screen that differs.
The difference is the same as if you would choose Arial, Times, or
Courier to print your source code. The characters look slightly
different to your eye, but they are exactly the same for Python. The .py
file doesn't have a difference, regardless how you set the font.

As others have said, the underscore of some fonts is so long that they
overlap, if you put more than on in a row.

Christian
Alexander Neilson
2020-06-23 20:28:37 UTC
Permalink
Hi Tony

The “long underscore” (often called Dunder as “double underscore”) is actually two underscores as you are seeing shown in PyCharm.

However the display of it as one long underscore is a ligature (special font display to communicate clearer) and to enable these in PyCharm go to the settings dialog (depending on windows or Mac this could be in different locations) and select Editor > Font

In that screen select “enable font ligatures” and if your font supports it (like the default JetBrains Mono does) that will start to display the double underscores as a single long underscore.

Regards
Alexander

Alexander Neilson
Neilson Productions Limited
021 329 681
***@neilson.net.nz

> On 24/06/2020, at 07:57, Tony Kaloki <***@live.co.uk> wrote:
>
> 
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
> From: Tony Kaloki<mailto:***@live.co.uk>
> Sent: 23 June 2020 19:45
> To: python-***@python.org<mailto:python-***@python.org>
> Subject: Pycharm Won't Do Long Underscore
>
>
> Hi Guys,
> I’ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I’ve come across a problem that’s stopped me in my tracks.
> When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can’t find any answers on the web and I’m not sure if I can go any further in my learning without being able to get long underscores.
> Sorry if I’m just being really dense, but like I said I’m an absolute beginner. Thanks for your time,
> Tony
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
Grant Edwards
2020-06-23 21:02:12 UTC
Permalink
On 2020-06-23, Tony Kaloki <***@live.co.uk> wrote:

> in your reply, are you saying that Python would have treated the
> two separate underscores the same way as a long underscore

No.

There is no long underscore in Python.

In Python, it's always two underscores.

In some fonts, two underscores just _looks_ like a single long
underscore.

--
Grant
Alexander Neilson
2020-06-23 21:12:48 UTC
Permalink
Hi Tony

Absolutely. The “long underscore” is just a display thing. Underneath it is always two underscores. The only difference is what your editor is showing (or how the underscore is drawn in the display font - as some fonts make the underscore the full width or slightly over the edge of where the character will be displayed so that many underscores look all joined up like a line)

These links may provide you with some useful reading around this and what underscores signal in Python.

https://dbader.org/blog/meaning-of-underscores-in-python

https://dbader.org/blog/python-dunder-methods

Happy to have helped and good luck with your Python journey.

Regards
Alexander

Alexander Neilson
Neilson Productions Limited
021 329 681
***@neilson.net.nz

> On 24/06/2020, at 08:49, Tony Kaloki <***@live.co.uk> wrote:
>
> 
> Alexander,
> Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?
> In any case, thanks again for your quick and easy to follow - even for me - reply.
> Tony
>
> Get Outlook for Android
>
> From: Alexander Neilson <***@neilson.net.nz>
> Sent: Tuesday, June 23, 2020 9:28:37 PM
> To: Tony Kaloki <***@live.co.uk>
> Cc: python-***@python.org <python-***@python.org>
> Subject: Re: Pycharm Won't Do Long Underscore
>
> Hi Tony
>
> The “long underscore” (often called Dunder as “double underscore”) is actually two underscores as you are seeing shown in PyCharm.
>
> However the display of it as one long underscore is a ligature (special font display to communicate clearer) and to enable these in PyCharm go to the settings dialog (depending on windows or Mac this could be in different locations) and select Editor > Font
>
> In that screen select “enable font ligatures” and if your font supports it (like the default JetBrains Mono does) that will start to display the double underscores as a single long underscore.
>
> Regards
> Alexander
>
> Alexander Neilson
> Neilson Productions Limited
> 021 329 681
> ***@neilson.net.nz
>
> > On 24/06/2020, at 07:57, Tony Kaloki <***@live.co.uk> wrote:
> >
> > 
> >
> > Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> >
> > From: Tony Kaloki<mailto:***@live.co.uk>
> > Sent: 23 June 2020 19:45
> > To: python-***@python.org<mailto:python-***@python.org>
> > Subject: Pycharm Won't Do Long Underscore
> >
> >
> > Hi Guys,
> > I’ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I’ve come across a problem that’s stopped me in my tracks.
> > When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can’t find any answers on the web and I’m not sure if I can go any further in my learning without being able to get long underscores.
> > Sorry if I’m just being really dense, but like I said I’m an absolute beginner. Thanks for your time,
> > Tony
> > Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> >
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
Terry Reedy
2020-06-24 03:34:57 UTC
Permalink
On 6/23/2020 4:44 PM, MRAB wrote:
> On 2020-06-23 20:18, Tony Kaloki wrote:

>>       When I try to do a long underscore __  for classes in Pycharm,
>> it only gives me two separate single underscores _ _.

> The "__" is 2 underscores; it's just that they usually appear joined
> together in many fonts.

To really see this, start IDLE either from an icon or 'python -m
idlelib' (use 'python3' on *nix) on a command line. Open the settings
dialog with Options => Configure IDLE. On the Font tab there is a Font
Sample box. Go to the bottom and enter several _____s. In the Windows
Courier font, and several others, this looks like one line. On the
left, try other fonts. On Windows, switching to Source Code Pro (and
some others) results in separate underscores. Source Code Pro, as the
name suggests, is aimed at programmers, and we need to be able to count
underscores.

Or maybe you can switch fonts in your mail reader and see what happens
to the underscores above.


--
Terry Jan Reedy
Joe Pfeiffer
2020-06-24 21:33:16 UTC
Permalink
One other note -- while you may want various good-looking fonts with
ligatures in other domains, for writing code a monospace font with no
ligatures lets you see exactly what's there and saves a host of
problems. My personal favorite for these purposes is called "Terminus
Regular", but which specific one you pick is much less important than
that you use one.
Peter J. Holzer
2020-06-30 20:00:00 UTC
Permalink
On 2020-06-24 15:33:16 -0600, Joe Pfeiffer wrote:
> One other note -- while you may want various good-looking fonts with
> ligatures in other domains, for writing code a monospace font with no
> ligatures lets you see exactly what's there and saves a host of
> problems. My personal favorite for these purposes is called "Terminus
> Regular", but which specific one you pick is much less important than
> that you use one.

I agree. Although there are some fonts with special ligatures for
programming. I have never used one, but that seems like an interesting
concept.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | ***@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Joe Pfeiffer
2020-06-30 21:46:40 UTC
Permalink
"Peter J. Holzer" <hjp-***@hjp.at> writes:

> On 2020-06-24 15:33:16 -0600, Joe Pfeiffer wrote:
>> One other note -- while you may want various good-looking fonts with
>> ligatures in other domains, for writing code a monospace font with no
>> ligatures lets you see exactly what's there and saves a host of
>> problems. My personal favorite for these purposes is called "Terminus
>> Regular", but which specific one you pick is much less important than
>> that you use one.
>
> I agree. Although there are some fonts with special ligatures for
> programming. I have never used one, but that seems like an interesting
> concept.

I've never heard of that before. I'd be curious to try one.
Danilo Coccia
2020-07-02 20:55:04 UTC
Permalink
Il 30/06/2020 23:46, Joe Pfeiffer ha scritto:
> "Peter J. Holzer" <hjp-***@hjp.at> writes:
>
>> On 2020-06-24 15:33:16 -0600, Joe Pfeiffer wrote:
>>> One other note -- while you may want various good-looking fonts with
>>> ligatures in other domains, for writing code a monospace font with no
>>> ligatures lets you see exactly what's there and saves a host of
>>> problems. My personal favorite for these purposes is called "Terminus
>>> Regular", but which specific one you pick is much less important than
>>> that you use one.
>>
>> I agree. Although there are some fonts with special ligatures for
>> programming. I have never used one, but that seems like an interesting
>> concept.
>
> I've never heard of that before. I'd be curious to try one.
>

I've been using this one, and I like it:
https://github.com/tonsky/FiraCode
https://www.fontsquirrel.com/fonts/fira-code

Works well with PyCharm.
Michael Torrie
2020-07-02 22:30:18 UTC
Permalink
On 7/2/20 2:55 PM, Danilo Coccia wrote:
> Il 30/06/2020 23:46, Joe Pfeiffer ha scritto:
>> "Peter J. Holzer" <hjp-***@hjp.at> writes:
>>> I agree. Although there are some fonts with special ligatures for
>>> programming. I have never used one, but that seems like an interesting
>>> concept.
>>
>> I've never heard of that before. I'd be curious to try one.
>>
>
> I've been using this one, and I like it:
> https://github.com/tonsky/FiraCode
> https://www.fontsquirrel.com/fonts/fira-code
>
> Works well with PyCharm.

Hmm. That is... interesting. I'm not at all sure how I feel about that.
On the one hand it partly appeals, but on the other hand it quite
repulses me. I don't find the FireCode samples any easier to read than
a normal font. In fact I find it slightly more difficult to read, since
my brain is not used to looking for those symbols. Hmmm. Yeah I dunno
about this one! Very interesting. Thanks for sharing it.

I tried it, and it's definitely not for me!
Dennis Lee Bieber
2020-06-24 17:48:18 UTC
Permalink
On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki <***@live.co.uk>
declaimed the following:

>Alexander,
> Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?

There is no "long underscore" in the character set. If there were,
Python would not know what to do with it as it was created back when ASCII
and ISO-Latin-1 were the common character sets. (Interesting: Windows
Character Map utility calls the underscore character "low line").

Many word processors are configured to change sequences of hyphens:
- -- --- into - – — (hyphen, en-dash, em-dash)... But in this case, those
are each single characters in the character map (using Windows-Western,
similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97
(note that en-/em-dash are >127, hence would not be in pure ASCII)

The underscore is x5F, and your "long underscore" is just two x5Fx5F
characters. What they look like on screen is dependent upon the font used
for rendering the image of the character, and any kerning (how one
character is spaced next to another).


--
Wulfraed Dennis Lee Bieber AF6VN
***@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
Chris Angelico
2020-06-24 17:59:00 UTC
Permalink
On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber <***@ix.netcom.com> wrote:
>
> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki <***@live.co.uk>
> declaimed the following:
>
> >Alexander,
> > Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?
>
> There is no "long underscore" in the character set. If there were,
> Python would not know what to do with it as it was created back when ASCII
> and ISO-Latin-1 were the common character sets. (Interesting: Windows
> Character Map utility calls the underscore character "low line").

That's what Unicode calls it - charmap is probably using that name.

> Many word processors are configured to change sequences of hyphens:
> - -- --- into - – — (hyphen, en-dash, em-dash)... But in this case, those
> are each single characters in the character map (using Windows-Western,
> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97
> (note that en-/em-dash are >127, hence would not be in pure ASCII)

Hyphen is U+002D, en dash is U+2013, em dash is 2014. :)

ChrisA
MRAB
2020-06-24 18:28:52 UTC
Permalink
On 2020-06-24 18:59, Chris Angelico wrote:
> On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber <***@ix.netcom.com> wrote:
>>
>> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki <***@live.co.uk>
>> declaimed the following:
>>
>> >Alexander,
>> > Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?
>>
>> There is no "long underscore" in the character set. If there were,
>> Python would not know what to do with it as it was created back when ASCII
>> and ISO-Latin-1 were the common character sets. (Interesting: Windows
>> Character Map utility calls the underscore character "low line").
>
> That's what Unicode calls it - charmap is probably using that name.
>
>> Many word processors are configured to change sequences of hyphens:
>> - -- --- into - – — (hyphen, en-dash, em-dash)... But in this case, those
>> are each single characters in the character map (using Windows-Western,
>> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97
>> (note that en-/em-dash are >127, hence would not be in pure ASCII)
>
> Hyphen is U+002D, en dash is U+2013, em dash is 2014. :)
>
Not quite. :-)

Hyphen is U+2010.

U+002D is hyphen-minus; it's does double-duty, for historical reasons.
Tony Kaloki
2020-06-24 18:51:46 UTC
Permalink
Thanks for all your explanations, everyone. Hopefully, I'll know better next time I come across a similar case. Now, to try and understand the rest of Python...

Get Outlook for Android<https://aka.ms/ghei36>

________________________________
From: Python-list <python-list-bounces+tkaloki=***@python.org> on behalf of MRAB <***@mrabarnett.plus.com>
Sent: Wednesday, June 24, 2020 7:28:52 PM
To: python-***@python.org <python-***@python.org>
Subject: Re: Pycharm Won't Do Long Underscore

On 2020-06-24 18:59, Chris Angelico wrote:
> On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber <***@ix.netcom.com> wrote:
>>
>> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki <***@live.co.uk>
>> declaimed the following:
>>
>> >Alexander,
>> > Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?
>>
>> There is no "long underscore" in the character set. If there were,
>> Python would not know what to do with it as it was created back when ASCII
>> and ISO-Latin-1 were the common character sets. (Interesting: Windows
>> Character Map utility calls the underscore character "low line").
>
> That's what Unicode calls it - charmap is probably using that name.
>
>> Many word processors are configured to change sequences of hyphens:
>> - -- --- into - – — (hyphen, en-dash, em-dash)... But in this case, those
>> are each single characters in the character map (using Windows-Western,
>> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97
>> (note that en-/em-dash are >127, hence would not be in pure ASCII)
>
> Hyphen is U+002D, en dash is U+2013, em dash is 2014. :)
>
Not quite. :-)

Hyphen is U+2010.

U+002D is hyphen-minus; it's does double-duty, for historical reasons.
--
https://mail.python.org/mailman/listinfo/python-list
Chris Angelico
2020-06-24 18:55:26 UTC
Permalink
On Thu, Jun 25, 2020 at 4:40 AM MRAB <***@mrabarnett.plus.com> wrote:
>
> On 2020-06-24 18:59, Chris Angelico wrote:
> > On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber <***@ix.netcom.com> wrote:
> >>
> >> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki <***@live.co.uk>
> >> declaimed the following:
> >>
> >> >Alexander,
> >> > Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity?
> >>
> >> There is no "long underscore" in the character set. If there were,
> >> Python would not know what to do with it as it was created back when ASCII
> >> and ISO-Latin-1 were the common character sets. (Interesting: Windows
> >> Character Map utility calls the underscore character "low line").
> >
> > That's what Unicode calls it - charmap is probably using that name.
> >
> >> Many word processors are configured to change sequences of hyphens:
> >> - -- --- into - – — (hyphen, en-dash, em-dash)... But in this case, those
> >> are each single characters in the character map (using Windows-Western,
> >> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97
> >> (note that en-/em-dash are >127, hence would not be in pure ASCII)
> >
> > Hyphen is U+002D, en dash is U+2013, em dash is 2014. :)
> >
> Not quite. :-)
>
> Hyphen is U+2010.
>
> U+002D is hyphen-minus; it's does double-duty, for historical reasons.

True true, I should have corrected that name. But the point is,
"Windows-Western" is not a good way to describe characters (I think
that probably means "code page 1252"?). Use the Unicode codepoints for
reliability :)

ChrisA
Peter J. Holzer
2020-06-24 21:10:16 UTC
Permalink
On 2020-06-24 13:48:18 -0400, Dennis Lee Bieber wrote:
> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki <***@live.co.uk>
> declaimed the following:
> > Alexander,
> > Thank you so much! It worked! Thank you. One question: in your
> > reply, are you saying that Python would have treated the two
> > separate underscores the same way as a long underscore i.e. it's a
> > stylistic choice rather than a functional necessity?
>
> There is no "long underscore" in the character set.

There is U+FF3F Fullwidth Low Line.

> If there were, Python would not know what to do with it

You can use it in variable names, but not at the beginning, and it isn't
equivalent to two underscores, of course:

Python 3.9.0b3 (default, Jun 13 2020, 10:49:29)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>  = 12
File "<stdin>", line 1
 = 12
^
SyntaxError: invalid character '' (U+FF3F)
>>> a = 12
>>> a
12
>>> a__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a__' is not defined
>>>

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | ***@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
o1bigtenor
2020-06-24 22:27:08 UTC
Permalink
On Wed, Jun 24, 2020 at 1:54 PM Tony Kaloki <***@live.co.uk> wrote:
>
> Thanks for all your explanations, everyone. Hopefully, I'll know better next time I come across a similar case. Now, to try and understand the rest of Python...
>

Your last sentence - - - - I'm right there with you! (Reading it made
me chuckle!)
I've been a tool maker in so many areas and never really wanted to
fall into the rabbit hole called computer programming (wry grin!).
Here I am working on Python, R, SQL and that's just for starters!
Oh well - - - helps keep life interesting!!

Regards
Grant Edwards
2020-06-25 01:38:00 UTC
Permalink
On 2020-06-24, Peter J. Holzer <hjp-***@hjp.at> wrote:

> There is U+FF3F Fullwidth Low Line.
>
>> If there were, Python would not know what to do with it
>
> You can use it in variable names, but not at the beginning, and it isn't
> equivalent to two underscores, of course:

Ouch. Anybody caught using that should be fed to a large snake.

--
Grant
Michael Torrie
2020-06-25 17:56:47 UTC
Permalink
On 6/24/20 7:38 PM, Grant Edwards wrote:
> On 2020-06-24, Peter J. Holzer <hjp-***@hjp.at> wrote:
>
>> There is U+FF3F Fullwidth Low Line.
>>
>>> If there were, Python would not know what to do with it
>>
>> You can use it in variable names, but not at the beginning, and it isn't
>> equivalent to two underscores, of course:
>
> Ouch. Anybody caught using that should be fed to a large snake.

Even allowing unicode letters in variable names period is questionable,
but that loud debate was over years ago. Fortunately I have never seen
any python code in the wild with non-latin characters for variable
names. Would make editing code very painful for developers from
different locales and keyboards. Even if it might seem novel at first to
have π be a variable name.
Peter J. Holzer
2020-06-30 19:47:35 UTC
Permalink
On 2020-06-25 11:56:47 -0600, Michael Torrie wrote:
> On 6/24/20 7:38 PM, Grant Edwards wrote:
> > On 2020-06-24, Peter J. Holzer <hjp-***@hjp.at> wrote:
> >> There is U+FF3F Fullwidth Low Line.
> >>
> >>> If there were, Python would not know what to do with it
> >>
> >> You can use it in variable names, but not at the beginning, and it isn't
> >> equivalent to two underscores, of course:
> >
> > Ouch. Anybody caught using that should be fed to a large snake.
>
> Even allowing unicode letters in variable names period is questionable,
> but that loud debate was over years ago. Fortunately I have never seen
> any python code in the wild with non-latin characters for variable
> names.

When I use German words as identifiers (I try to avoid this, but
sometimes translating to English would just confuse everybody), I do use
umlauts. I have also used Greek letters for physical quantities (e.g., ω
for angular velocity).

> Would make editing code very painful for developers from different
> locales and keyboards.

Yeah, editor support is a problem[1]. For my code with German identifiers
it is very unlikely that anybody who doesn't use German daily (and hence
already has the need to type umlauts) will ever have to edit it. The
Greek characters are in private code only.

hp


[1] I use vim. Digraphs are a bit awkward but good enough for medium
rare[2] characters. I don't know how to type characters not on the
keyboard[3] in VS code or PyCharm or Emacs or whatever others are
using. "I can't edit your code because I can't type that variable
name" is certainly not something I want to hear from my colleagues.

[2] Pun not intended.

[3] Includes compose-sequences, if the keyboard has a compose key.

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | ***@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Random832
2020-07-01 02:00:17 UTC
Permalink
On Wed, Jun 24, 2020, at 21:38, Grant Edwards wrote:
> On 2020-06-24, Peter J. Holzer <hjp-***@hjp.at> wrote:
>
> > There is U+FF3F Fullwidth Low Line.
> >
> >> If there were, Python would not know what to do with it
> >
> > You can use it in variable names, but not at the beginning, and it isn't
> > equivalent to two underscores, of course:

It is, in fact, equivalent to a single underscore. This is reasonable, given the unicode rules [I assume identifier lookup uses NFKC] and how these characters function for East Asian users.

> Ouch. Anybody caught using that should be fed to a large snake.

Honestly, if I were to suggest any change it'd be to fix it so it's allowed at the beginning of an identifier. Let each (human) language's community worry about coding conventions for code intended for speakers of that language instead of trying to impose things on the world as english-speakers.

>>> a=1
>>> a_b=2
>>> a
1
>>> a_b
2
>>> _
File "<stdin>", line 1
_
^
SyntaxError: invalid character in identifier
Loading...