Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-18 Thread Barry via Python-list


> On 17 Aug 2023, at 15:01, c.buhtz--- via Python-list  
> wrote:
> 
> I want to display one string in its original source (untranslated) version 
> and in its translated version site by site without duplicating the string in 
> the python source code?
> It wouldn't be a big deal if it is only one word.

The key to solving this to separate the parsing of the string into the .po file 
and its translation.

def i18n(s):
  return s

msg = i18n(‘my message’)

print(_(msg))
print(msg)

Now you tell the xgettex, pygettext etc, to parse to use “i18n” to find strings 
to translate.

This is covered in the docs at 
https://docs.python.org/3/library/gettext.html#localizing-your-module

Barry





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-18 Thread Greg Ewing via Python-list

On 17/08/23 7:10 pm, c.bu...@posteo.jp wrote:

def foobar(translate):
     if not translate:
     # I try to mask the global _() builtins-function
     def _(txt):
     return txt

     return _('Hello')


This causes _ to become a local that is left undefined on one
branch of the if. You need to ensure it's always defined. Here's
one way that should work:

gttran = _

def foobar(translate):
def _(txt):
if translate:
return gttran(txt)
else:
return txt
return _('Hello')

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Mirko via Python-list

Am 17.08.23 um 21:17 schrieb c.buhtz--- via Python-list:

Hello Mirko,

thanks for reply.

Am 17.08.2023 18:19 schrieb Mirko via Python-list:

You could solve it by defining _() locally like so:

def foobar(translate):
    _ = gettext.gettext


I see no way to do that. It is not the "class based API" of gettext 
installing _() into the builtins namespace.



Does this work:

def foobar(translate):
_ = __builtins__._



My users are able to configure the language of their UI explicit. It 
is a full application.



def orig_and_trans(msg):
    return (_(msg), msg)


This will be ignored by GNU gettext utils (xgettext in my case) will 
ignore this line because they do not know what "msg" is. The string 
"hello" won't appear in the pot-file.



xgettext has an option "-k" which allows you to specify an 
additional "keyword" (like a function name, I guess) for detecting 
translatable strings. With the orig_and_trans() function, the 
following command produces a messages.po with "hello" in it.


xgettext -korig_and_trans source.py
--
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread c.buhtz--- via Python-list

Hello Mirko,

thanks for reply.

Am 17.08.2023 18:19 schrieb Mirko via Python-list:

You could solve it by defining _() locally like so:

def foobar(translate):
_ = gettext.gettext


I see no way to do that. It is not the "class based API" of gettext 
installing _() into the builtins namespace.
My users are able to configure the language of their UI explicit. It is 
a full application.



def orig_and_trans(msg):
return (_(msg), msg)


This will be ignored by GNU gettext utils (xgettext in my case) will 
ignore this line because they do not know what "msg" is. The string 
"hello" won't appear in the pot-file.

--
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Dieter Maurer via Python-list
c.bu...@posteo.jp wrote at 2023-8-17 07:10 +:
>I want to display one string in its original source (untranslated)
>version and in its translated version site by site without duplicating
>the string in the python source code?

You could try to translate into an unknown language: this
should give you the default translation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Richard Damon via Python-list
> On Aug 17, 2023, at 10:02 AM, c.buhtz--- via Python-list 
>  wrote:
> 
> X-Post: https://stackoverflow.com/q/76913082/4865723
> 
> I want to display one string in its original source (untranslated) version 
> and in its translated version site by site without duplicating the string in 
> the python source code?
> It wouldn't be a big deal if it is only one word.
> 
>print('The translated string "{}" is originally "{}".'.format(_('Hello'), 
> 'Hello'))
> 
> But in my situation it is a multi line string containing multiple paragraphs. 
> It is a full text. I don't want to duplicate that string.
> 
># Imagine 'Hello' as a 50x70 characters multi line string.
>original = 'Hello'
>translated = _('Hello')
>print('The translated string "{}" is originally "{}".'.format(translated, 
> original))
> 
> I do use the "class based API" of GNU gettext. My current approach, which is 
> not working, is to somehow (how!?) disable (or mask) the translation function 
> "_()" temporarily.
> But as described in the stackoverflow question (see first line of this mail) 
> this do not work.
> 
> def foobar(translate):
>if not translate:
># I try to mask the global _() builtins-function
>def _(txt):
>return txt
> 
>return _('Hello')
> 
> if __name__ == '__main__':
> 
># To ilustrate that _() is part of "builtins" namespace
>print(_('No problem.'))
> 
>print('The translated string "{}" is originally "{}".'
>  .format(foobar(True), foobar(False)))
> 
> This is the output:
> 
>Traceback (most recent call last):
>  File "/home/user/ownCloud/_transfer/./z.py", line 27, in 
>.format(foobar(True), foobar(False)))
>  File "/home/user/ownCloud/_transfer/./z.py", line 19, in foobar
>return _('Hello')
>UnboundLocalError: local variable '_' referenced before assignment
> 
> The full MWE can be found at stackoverflow 
> (https://stackoverflow.com/q/76913082/4865723).
> 
> The question is if this can be solved somehow or if there is an alternative 
> approach.
> The "_()" function is installed in the builtins namespace because of gettext 
> class based API. This is nice.
> Maybe I can somehow manipulate that builtins namespace? I tried to import 
> builtins and played around with it but couldn't find a way to do it.
> 
> Thanks
> Christian Buhtz
> 
> PS: This is IMHO not relevant for my question but if someone is interested 
> the connection to productive code can be found in this issue: 
> https://github.com/bit-team/backintime/issues/1473 There I describe what I 
> want to achive and also provide a GUI mockup.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

One thing to remember is that the _() function, which calls gettext doesn’t 
need a literal string, so you can set a variable to ‘raw’ string, and then 
translate it to another variable, so you can have both.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Dieter Maurer via Python-list
c.bu...@posteo.jp wrote at 2023-8-17 07:10 +:
>I want to display one string in its original source (untranslated)
>version and in its translated version site by site without duplicating
>the string in the python source code?

Is it an option for you to replace the `gettext` binding
by `zope.i18nmessageid`? Its `Message` instances provide
access to all interesting attributes (id, default, mapping, domain).
Together with other packages (--> `zope.i18n` and `i18ndude`)
it is compatible with `GNU gettext` translation catalogs.

If this is not an option, use Python's inspection functionality
to learn which attributes are made available by the binding's
message class.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Mirko via Python-list

Am 17.08.23 um 09:10 schrieb c.buhtz--- via Python-list:



     UnboundLocalError: local variable '_' referenced before assignment


This is a common gotcha:

https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value

You could solve it by defining _() locally like so:


def foobar(translate):
_ = gettext.gettext
if not translate:
# I try to mask the global _() builtins-function
def _(txt):
return txt
return _('minutes')



The question is if this can be solved somehow or if there is an alternative 
approach.


However, you might not need this, because the following seems to 
work for me:


def orig_and_trans(msg):
return (_(msg), msg)

print('The translated string "{}" is originally 
"{}".'.format(*orig_and_trans("hello")))


--
https://mail.python.org/mailman/listinfo/python-list


GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread c.buhtz--- via Python-list

X-Post: https://stackoverflow.com/q/76913082/4865723

I want to display one string in its original source (untranslated) 
version and in its translated version site by site without duplicating 
the string in the python source code?

It wouldn't be a big deal if it is only one word.

print('The translated string "{}" is originally 
"{}".'.format(_('Hello'), 'Hello'))


But in my situation it is a multi line string containing multiple 
paragraphs. It is a full text. I don't want to duplicate that string.


# Imagine 'Hello' as a 50x70 characters multi line string.
original = 'Hello'
translated = _('Hello')
print('The translated string "{}" is originally 
"{}".'.format(translated, original))


I do use the "class based API" of GNU gettext. My current approach, 
which is not working, is to somehow (how!?) disable (or mask) the 
translation function "_()" temporarily.
But as described in the stackoverflow question (see first line of this 
mail) this do not work.


def foobar(translate):
if not translate:
# I try to mask the global _() builtins-function
def _(txt):
return txt

return _('Hello')

if __name__ == '__main__':

# To ilustrate that _() is part of "builtins" namespace
print(_('No problem.'))

print('The translated string "{}" is originally "{}".'
  .format(foobar(True), foobar(False)))

This is the output:

Traceback (most recent call last):
  File "/home/user/ownCloud/_transfer/./z.py", line 27, in 
.format(foobar(True), foobar(False)))
  File "/home/user/ownCloud/_transfer/./z.py", line 19, in foobar
return _('Hello')
UnboundLocalError: local variable '_' referenced before assignment

The full MWE can be found at stackoverflow 
(https://stackoverflow.com/q/76913082/4865723).


The question is if this can be solved somehow or if there is an 
alternative approach.
The "_()" function is installed in the builtins namespace because of 
gettext class based API. This is nice.
Maybe I can somehow manipulate that builtins namespace? I tried to 
import builtins and played around with it but couldn't find a way to do 
it.


Thanks
Christian Buhtz

PS: This is IMHO not relevant for my question but if someone is 
interested the connection to productive code can be found in this issue: 
https://github.com/bit-team/backintime/issues/1473 There I describe what 
I want to achive and also provide a GUI mockup.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.7+ cannot print unicode characters when output is redirected to file - is this a bug?

2022-11-13 Thread Eryk Sun
On 11/13/22, Jessica Smith <12jessicasmit...@gmail.com> wrote:
> Consider the following code ran in Powershell or cmd.exe:
>
> $ python -c "print('└')"
> └
>
> $ python -c "print('└')" > test_file.txt
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 19, in
> encode
> return codecs.charmap_encode(input,self.errors,encoding_table)[0]
> UnicodeEncodeError: 'charmap' codec can't encode character '\u2514' in
> position 0: character maps to 

If your applications and existing data files are compatible with using
UTF-8, then in Windows 10+ you can modify the administrative regional
settings in the control panel to force using UTF-8. In this case,
GetACP() and GetOEMCP() will return CP_UTF8 (65001), and the reserved
code page constants CP_ACP (0),  CP_OEMCP (1), CP_MACCP (2), and
CP_THREAD_ACP (3) will use CP_UTF8.

You can override this on a per-application basis via the
ActiveCodePage setting in the manifest:

https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests#activecodepage

In Windows 10, this setting only supports "UTF-8". In Windows 11, it
also supports "legacy" to allow old applications to run on a system
that's configured to use UTF-8.  Setting an explicit locale is also
supported in Windows 11, such as "en-US", with fallback to UTF-8 if
the given locale has no legacy code page.

Note that setting the system to use UTF-8 also affects the host
process for console sessions (i.e. conhost.exe or openconsole.exe),
since it defaults to using the OEM code page (UTF-8 in this case).
Unfortunately, a legacy read from the console host does not support
reading non-ASCII text as UTF-8. For example:

>>> os.read(0, 6)
SPĀM
b'SP\x00M\r\n'

This is a trivial bug in the console host, which stems from the fact
that UTF-8 is a multibyte encoding (1-4 bytes per code), but for some
reason the console team at Microsoft still hasn't fixed it. You can
use chcp.com to set the console's input and output code pages to
something other than UTF-8 if you have to read non-ASCII input in a
legacy console app. By default, this problem doesn't affect Python's
sys.stdin, which internally uses wide-character ReadConsoleW() with
the system's native text encoding, UTF-16LE.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.7+ cannot print unicode characters when output is redirected to file - is this a bug?

2022-11-13 Thread Thomas Passin

On 11/13/2022 9:49 AM, Jessica Smith wrote:

Consider the following code ran in Powershell or cmd.exe:

$ python -c "print('└')"
└

$ python -c "print('└')" > test_file.txt
Traceback (most recent call last):
   File "", line 1, in 
   File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 19, in encode
 return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2514' in
position 0: character maps to 

Is this a known limitation of Windows + Unicode? I understand that
using -x utf8 would fix this, or modifying various environment
variables. But is this expected for a standard Python installation on
Windows?

Jessica



This also fails with the same error:

$ python -c "print('└')" |clip
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.7+ cannot print unicode characters when output is redirected to file - is this a bug?

2022-11-13 Thread Barry


> On 13 Nov 2022, at 14:52, Jessica Smith <12jessicasmit...@gmail.com> wrote:
> 
> Consider the following code ran in Powershell or cmd.exe:
> 
> $ python -c "print('└')"
> └
> 
> $ python -c "print('└')" > test_file.txt
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 19, in encode
>return codecs.charmap_encode(input,self.errors,encoding_table)[0]
> UnicodeEncodeError: 'charmap' codec can't encode character '\u2514' in
> position 0: character maps to 
> 
> Is this a known limitation of Windows + Unicode? I understand that
> using -x utf8 would fix this, or modifying various environment
> variables. But is this expected for a standard Python installation on
> Windows?

Your other thread has a reply that explained this.
It is a problem with windows and character sets.
You have to set things up to allow Unicode to work.

Barry

> 
> Jessica
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Python 3.7+ cannot print unicode characters when output is redirected to file - is this a bug?

2022-11-13 Thread Jessica Smith
Consider the following code ran in Powershell or cmd.exe:

$ python -c "print('└')"
└

$ python -c "print('└')" > test_file.txt
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2514' in
position 0: character maps to 

Is this a known limitation of Windows + Unicode? I understand that
using -x utf8 would fix this, or modifying various environment
variables. But is this expected for a standard Python installation on
Windows?

Jessica
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: pdfposter 0.8.1 - scale and tile PDF pages to print on multiple sheets

2022-11-04 Thread jkn
On Friday, November 4, 2022 at 6:21:55 PM UTC, Hartmut Goebel wrote:
> I'm pleased to announce pdftools.pdfposter 0.8.1, a tool to scale and 
> tile PDF images/pages to print on multiple pages. 
> 
> :Homepage:  https://pdfposter.readthedocs.io/ 
> :Author:Hartmut Goebel  
> :License:   GNU Public License v3 or later (GPL-3.0-or-later) 
> 
> :Quick Installation: 
> pip install -U pdftools.pdfposter 
> 
> :Tarballs:  https://pypi.org/project/pdftools.pdfposter/#files 
> 
> 
> What is pdfposter? 
> ---- 
> 
> Scale and tile PDF images/pages to print on multiple pages. 
> 
> ``Pdfposter`` can be used to create a large poster by building it from 
> multiple pages and/or printing it on large media. It expects as input a 
> PDF file, normally printing on a single page. The output is again a 
> PDF file, maybe containing multiple pages together building the 
> poster. 
> The input page will be scaled to obtain the desired size. 
> 
> This is much like ``poster`` does for Postscript files, but working 
> with PDF. Since sometimes poster does not like your files converted 
> from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``. 
> 
> For more information please refer to the manpage or visit 
> the `project homepage <https://pdfposter.readthedocs.io/>`_. 
> 
> 
> What's new in version 0.8.1 
> - 
> 
> * This is a bug-fix release for release 0.8. 
> 
> What's new in version 0.8 
> - 
> 
> * Be less strict when reading PDF files. 
> 
> * Enhance some help messages. 
> 
> * Drop support for Python 2 and Python <= 3.5. Minimum supported 
> versions are 
>   now 3.6 to 3.10. 
> 
> * Internal changes: 
> 
>   - Update required version of `PyPDF` to 2.1.1. 
>   - Enhance code quality. 
> 
> -- 
> Regards 
> Hartmut Goebel 
> 
> | Hartmut Goebel | h.go...@crazy-compilers.com | 
> | www.crazy-compilers.com | compilers which you thought are impossible |

Thanks for this - yes, I remember poster for n-up Postscript files...

-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: pdfposter 0.8.1 - scale and tile PDF pages to print on multiple sheets

2022-11-04 Thread Hartmut Goebel

I'm pleased to announce pdftools.pdfposter 0.8.1, a tool to scale and
tile PDF images/pages to print on multiple pages.

:Homepage:  https://pdfposter.readthedocs.io/
:Author:    Hartmut Goebel 
:License:   GNU Public License v3 or later (GPL-3.0-or-later)

:Quick Installation:
    pip install -U pdftools.pdfposter

:Tarballs:  https://pypi.org/project/pdftools.pdfposter/#files


What is pdfposter?


Scale and tile PDF images/pages to print on multiple pages.

``Pdfposter`` can be used to create a large poster by building it from
multiple pages and/or printing it on large media. It expects as input a
PDF file, normally printing on a single page. The output is again a
PDF file, maybe containing multiple pages together building the
poster.
The input page will be scaled to obtain the desired size.

This is much like ``poster`` does for Postscript files, but working
with PDF. Since sometimes poster does not like your files converted
from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``.

For more information please refer to the manpage or visit
the `project homepage <https://pdfposter.readthedocs.io/>`_.


What's new in version 0.8.1
-

* This is a bug-fix release for release 0.8.

What's new in version 0.8
-

* Be less strict when reading PDF files.

* Enhance some help messages.

* Drop support for Python 2 and Python <= 3.5. Minimum supported 
versions are

  now 3.6 to 3.10.

* Internal changes:

  - Update required version of `PyPDF` to 2.1.1.
  - Enhance code quality.

--
Regards
Hartmut Goebel

| Hartmut Goebel  | h.goe...@crazy-compilers.com   |
| www.crazy-compilers.com | compilers which you thought are impossible |

--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Dan Stromberg
On Thu, Jun 9, 2022 at 1:52 PM Michael F. Stemper 
wrote:

> On 09/06/2022 12.52, Chris Angelico wrote:
> > On Fri, 10 Jun 2022 at 03:44, Dave  wrote:
>
> >> Before I write my own I wondering if anyone knows of a function that
> will print a nicely formatted dictionary?
> >>
> >> By nicely formatted I mean not all on one line!
> >>
> >
> > https://docs.python.org/3/library/pprint.html
> >
> > from pprint import pprint
> > pprint(thing)
>
>   >>> from pprint import pprint
>   >>> d = {'two':2, 'three':5}
>   >>> pprint(d)
>   {'three': 5, 'two': 2}
>   >>>
>
> This is all on one line. That might be acceptable to the OP, but it
> doesn't actually match what he said.
>

For small outputs, pprint uses a single line.  For larger outputs, it
inserts newlines. It's intended to be human-readable more than
machine-readable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Grant Edwards
On 2022-06-09, Dennis Lee Bieber  wrote:

> However, the Gmane list<>NNTP gateway server DOES make the tutor
> list available to news readers (unfortunately, the comp.lang.python
> <> list <> Gmane has been read-only since last fall (unless things
> have changed recently) so I'm stuck with the spammy general
> comp.lang.python news group.

Here's how I fixed that problem:

  https://github.com/GrantEdwards/hybrid-inews

I read this "group" using slrn pointed at gmane.comp.python.general,
on the NNTP server news.gmain.io. When I post to this group from slrn,
it gets e-mailed to the regular mailing list address. Other gmane
"groups" get posts sent via NNTP. slrn is configured to post all
articles via /usr/local/bin/inews (which is the python "inews"
work-alike program above) when connected to news.gmane.io.

How/why people follow mailing lists via actual e-mail is beyond my
ken... 

--
Grant
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Cameron Simpson
On 09Jun2022 21:35, Dave  wrote:
>I quite like the format that JSON gives - thanks a lot!

Note that JSON output is JavaScript notation, not Python. The `pprint` 
module (which has `pprint` and `pformat` functions) outputs Python 
notation.

If you're just writing for human eyes, JSON is fine, though you will 
want to keep in mind that JSON spells `None` as `null`.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Michael F. Stemper

On 09/06/2022 12.52, Chris Angelico wrote:

On Fri, 10 Jun 2022 at 03:44, Dave  wrote:



Before I write my own I wondering if anyone knows of a function that will print 
a nicely formatted dictionary?

By nicely formatted I mean not all on one line!



https://docs.python.org/3/library/pprint.html

from pprint import pprint
pprint(thing)


 >>> from pprint import pprint
 >>> d = {'two':2, 'three':5}
 >>> pprint(d)
 {'three': 5, 'two': 2}
 >>>

This is all on one line. That might be acceptable to the OP, but it
doesn't actually match what he said.

--
Michael F. Stemper
Outside of a dog, a book is man's best friend.
Inside of a dog, it's too dark to read.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Friedrich Rentsch
If you want tables layed out in a framing grid, you might want to take a 
look at this:


https://bitbucket.org/astanin/python-tabulate/pull-requests/31/allow-specifying-float-formats-per-column/diff

Frederic



On 6/9/22 12:43, Dave wrote:

Hi,

Before I write my own I wondering if anyone knows of a function that will print 
a nicely formatted dictionary?

By nicely formatted I mean not all on one line!

Cheers
Dave



--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Dave
Hi,

I quite like the format that JSON gives - thanks a lot!

Cheers
Dave

> On 9 Jun 2022, at 20:02, Stefan Ram  wrote:
> 
>  Since nicety is in the eyes of the beholder, I would not
>  hesitate to write a custom function in this case. Python
>  has the standard modules "pprint" and "json".
> 
>  main.py
> 
> import json
> d ={ 1:2, 'alpha': 'beta' }
> print( json.dumps( d, indent=4 ))
> 
>  output
> 
> {
>"1": 2,
>"alpha": "beta"
> }
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Mats Wichmann
On 6/9/22 11:52, Chris Angelico wrote:
> On Fri, 10 Jun 2022 at 03:44, Dave  wrote:
>>
>> Hi,
>>
>> Before I write my own I wondering if anyone knows of a function that will 
>> print a nicely formatted dictionary?
>>
>> By nicely formatted I mean not all on one line!
>>
> 
> https://docs.python.org/3/library/pprint.html
> 
> from pprint import pprint
> pprint(thing)
> 
> ChrisA


I might add the note that there was a recent thread on the Discuss board
about options for styling the pprint output (okay, it was me that
started that one...) - you can choose indent and compact (compact is the
not-all-on-one-line flag) but there might be some other choices missing.
haven't gotten around to following up on that...

https://discuss.python.org/t/pprint-styling-options/15947
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Avi Gross via Python-list
Dave,

Despite your other programming knowledge, I suspect you think this is the forum 
where people come to be tutored. Try here:

https://mail.python.org/mailman/listinfo/tutor

Yes, there are plenty of pretty printers available and you can build your own 
function fairly easily. A module like pprint may have what you want in 
pprint.pprint()  but you can write a function for yourself that takes a  
dictionary and loops through items and prints them one per line and, if you 
feel like it, also prints how many items there are and your own custom touches 
such as doing them alphabetically.
Consider using a search engine before posting. Throw in a few words like 
"python pretty print dictionary function" and refine that if it does not get 
you immediate results. It is free and easy and does not waste time for so many 
others who already know or don't care.
And consider reading a few books perhaps designed to teach python to people 
with some programming experience or taking a course on something like COURSERA 
as a part of your learning process and not depending on volunteers so much. 
Much of what you are asking is covered in fairly beginner and intermediate such 
books/courses.

I think I am now going to ignore messages from you for a while. Signal to noise 
ratio ...


-Original Message-
From: Dave 
To: python-list@python.org
Sent: Thu, Jun 9, 2022 6:43 am
Subject: Function to Print a nicely formatted Dictionary or List?

Hi,

Before I write my own I wondering if anyone knows of a function that will print 
a nicely formatted dictionary?

By nicely formatted I mean not all on one line!

Cheers
Dave

-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Chris Angelico
On Fri, 10 Jun 2022 at 03:44, Dave  wrote:
>
> Hi,
>
> Before I write my own I wondering if anyone knows of a function that will 
> print a nicely formatted dictionary?
>
> By nicely formatted I mean not all on one line!
>

https://docs.python.org/3/library/pprint.html

from pprint import pprint
pprint(thing)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread MRAB

On 2022-06-09 11:43, Dave wrote:

Hi,

Before I write my own I wondering if anyone knows of a function that will print 
a nicely formatted dictionary?

By nicely formatted I mean not all on one line!


It's called "pretty-printing". Have a look at the 'pprint' module.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Larry Martell
On Thu, Jun 9, 2022 at 11:44 AM Dave  wrote:
>
> Hi,
>
> Before I write my own I wondering if anyone knows of a function that will 
> print a nicely formatted dictionary?
>
> By nicely formatted I mean not all on one line!

>>> import json
>>> d = {'John': 'Cleese', 'Eric': "Idle", 'Micheal': 'Palin'}
>>> print(json.dumps(d, indent=4))
{
"John": "Cleese",
"Eric": "Idle",
"Micheal": "Palin"
}
-- 
https://mail.python.org/mailman/listinfo/python-list


Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Dave
Hi,

Before I write my own I wondering if anyone knows of a function that will print 
a nicely formatted dictionary?

By nicely formatted I mean not all on one line!

Cheers
Dave

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to distinguish return from print()

2022-05-25 Thread Meredith Montgomery
r...@zedat.fu-berlin.de (Stefan Ram) writes:

> Meredith Montgomery  writes:
> ...
>>def f(x):
>>return x + 1
> ...
>>>>> print("hello")
>
>   To me, what would make more sense would be:
>
>   Teacher:
>
> |>>> def r():
> |... return 7
> |...
> |>>> def p():
> |... print( 7 )
> |...
> |>>> r()
> |7
> |>>> p()
> |7
>
>   Pupil:
>
>   That was a very instructive example, teacher. Thank you!
>   But could you also show us some context where the calls 
>   to p and r show some difference?
>
>   Teacher:
>   
> |>>> print( r() )
> |7
> |>>> print( p() )
> |7
> |None
>
> |>>> x = r()
> |>>> x = p()
> |7
>
>   Pupil:
>
>   Now I'm confused. What's "None"?
>
>   Teacher:
>
>   ...

I did do this too.  I think that was helpful.  I told them --- a print
doesn't let you easily ``capture'' a value calculated in a procedure.
Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: F-string usage in a print()

2022-05-24 Thread Cameron Simpson
On 25May2022 00:13, Kevin M. Wilson  wrote:
>Cameron, I have a misunderstanding here, the 'f-string' is used when 
>the str() is not...isn't it!

No, f-strings (format strings) are just a convenient way to embed values 
in a string. The result is a string.

In days of yore the common formatting method was the % operator like C's 
printf() format. You could do stuff like this:

    print("%s: length is %d items" % (thing, len(thing)))

which would print something like:

Thing5: length is 12 items

Ignore the print() itself, that's just how you might use this: format a 
string with 2 values, then print it out for a person to read.

You can do various things with %-formatting, but it is pretty limited 
and a bit prone to pairing things up incorrectly (human error making the 
"(thing, len(thing,len(thing)))" tuple) because those values are 
separates from the string itself.

The funky new thing is format strings, where you can write:

print(f"{thing}: length is {len(thing)} items")

Again ignore the print(), we're really just interested in the 
expression:

f"{thing}: length is {len(thing)} items"

which does the same thing as the %-format earlier, but more readably and 
conveniently.

I suspect you think they have another purpose. Whereas I suspect you're 
actaully trying to do something inappropriate for a number. If you've 
come here from another language such as PHP you might expect to go:

print(some_number + some_string)

In Python you need compatible types - so many accidents come from mixing 
stuff up.

You may know that print()'s operation is to take each expression you 
give it and call str() on that value, then print that string.

f-strings have a similar operation: each {expression} inside one is 
converted to a string for embedding in the larger format string; that is 
also done with str() unless you've added something special in the {} 
part.

Aside from output you should not expect to be adding strings and 
numbers; - it isn't normally a sensible thing to do. And when printing 
things, you need text (strings). But print() takes can of that by 
passing every value to str(), which returns a string (in a manner 
appropriate to the type of value). You only want f-strings or manual 
joining up if you don't want the default separator between items (a 
space).

Can you elaborate on _why_ you wanted an f-string? What were you doing 
at the time?

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: F-string usage in a print()

2022-05-24 Thread Cameron Simpson
On 24May2022 21:14, Kevin M. Wilson  wrote:
>future_value = 0
>for i in range(years):
># for i in range(months):
>   future_value += monthly_investment
>   future_value = round(future_value, 2)
>   # monthly_interest_amount = future_value * monthly_interest_rate
>   # future_value += monthly_interest_amount
>   # display the result
>   print(f"Year = ", years + f"Future value = \n", future_value)
>
>When joining a string with a number, use an f-string otherwise, code a
>str() because a implicit convert of an int to str causes a
>TypeError!Well...WTF! Am I not using the f-string function
>correctly...in the above line of code???

The short answer is that you cannot add (the "+" operator) a string to 
an integer in Python because one is a numeric value and one is a text 
value. You would need to convert the int to a str first if you really 
wanted to.  But in your code above, you don't need to.

Let's pick apart that print():

print(
f"Year = ",
    years + f"Future value = \n",
future_value
)

Like any function, print()'s arguments are separate by commas. So you've 
got 3 expressions there. The problematic expression looks like this 
one:

years + f"Future value = \n"

You didn't supply a complete runnable example so we don't see "years" 
get initialised.  However, I assume it is an int because range() only 
accepts ints. You can't add an int to a str.

Now, print() converts all its arguments to strings, so there's no need 
for f-strings anywhere in this. I'd go:

    print("Year =", years, "Future value =", future_value)

myself. If you really want that newline, maybe:

print("Year =", years, "Future value =")
print(future_value)

Format strings are for embedding values inside strings, which you don't 
need to do in your code as written. And whether you wrote:

years + f"Future value = \n"

or:

years + "Future value = \n"

(because that string has no embedded values) it is still wrong because 
years is an int and the string is still a str.

You _could_ use an f-string to compute the whole print line in one go:

print(f"Year = {years} Future value = \n{future_value}")

but I can't see the point, personally. I've code from people who prefer 
that form though.

BTW, it helps people to help you if you supply a complete example. Your 
example code did not initialise years or monthly_investment, and so will 
not run for someone else. It also helps to winnow it down to the 
smallest example you can which still shows the problem. FOr yoru example 
you could have reduced things to this, perhaps:

years = 9
years + f"Future value = \n"

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: F-string usage in a print()

2022-05-24 Thread Mats Wichmann
On 5/24/22 15:14, Kevin M. Wilson via Python-list wrote:
> future_value = 0
> for i in range(years):
> # for i in range(months):
>future_value += monthly_investment
>future_value = round(future_value, 2)
># monthly_interest_amount = future_value * monthly_interest_rate
># future_value += monthly_interest_amount
># display the result
>print(f"Year = ", years + f"Future value = \n", future_value)When joining 
> a string with a number, use an f-string otherwise, code a str() because a 
> implicit convert of an int to str causes a TypeError!Well...WTF! Am I not 
> using the f-string function correctly...in the above line of code???


As noted elsewhere, your f-strings by themselves are fine, it isn't
complaining about those, though they're kind of silly as they don't do
any formatting that justifies entering them as f-strings. It's
complaining about this piece:

years + f"Future value = \n"

which is the second of the three comma-separated argument to print().
That's the int + string the error is grumping about.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: F-string usage in a print()

2022-05-24 Thread Paul Bryan
Try something like:

print(f"Year = {years}, Future value = {future_value}")

On Tue, 2022-05-24 at 21:14 +, Kevin M. Wilson via Python-list
wrote:
> future_value = 0
> for i in range(years):
> # for i in range(months):
>    future_value += monthly_investment
>    future_value = round(future_value, 2)
>    # monthly_interest_amount = future_value * monthly_interest_rate
>    # future_value += monthly_interest_amount
>    # display the result
>    print(f"Year = ", years + f"Future value = \n", future_value)When
> joining a string with a number, use an f-string otherwise, code a
> str() because a implicit convert of an int to str causes a
> TypeError!Well...WTF! Am I not using the f-string function
> correctly...in the above line of code???
> Caddy Man
> 
> Good sense makes one slow to anger, and it is his glory tooverlook an
> offense.
> 
> Proverbs 19:11
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: F-string usage in a print()

2022-05-24 Thread MRAB

On 2022-05-24 22:14, Kevin M. Wilson via Python-list wrote:

future_value = 0
for i in range(years):
# for i in range(months):
future_value += monthly_investment
future_value = round(future_value, 2)
# monthly_interest_amount = future_value * monthly_interest_rate
# future_value += monthly_interest_amount
# display the result
print(f"Year = ", years + f"Future value = \n", future_value)When joining a 
string with a number, use an f-string otherwise, code a str() because a implicit convert of an int 
to str causes a TypeError!Well...WTF! Am I not using the f-string function correctly...in the above 
line of code???


There's no implicit conversion. An f-string always gives you a string.

'years' is an int, f"Future value = \n" is a str, and you can't add an 
int and a str.


Maybe you meant this:

print(f"Year = {i}, Future value = {future_value}")

or this:

print(f"Year = {i + 1}, Future value = {future_value}")

These are equivalent to:

print("Year = {}, Future value = {}".format(i, future_value))

and:

print("Year = {}, Future value = {}".format(i + 1, future_value))
--
https://mail.python.org/mailman/listinfo/python-list


F-string usage in a print()

2022-05-24 Thread Kevin M. Wilson via Python-list
future_value = 0
for i in range(years):
# for i in range(months):
   future_value += monthly_investment
   future_value = round(future_value, 2)
   # monthly_interest_amount = future_value * monthly_interest_rate
   # future_value += monthly_interest_amount
   # display the result
   print(f"Year = ", years + f"Future value = \n", future_value)When joining a 
string with a number, use an f-string otherwise, code a str() because a 
implicit convert of an int to str causes a TypeError!Well...WTF! Am I not using 
the f-string function correctly...in the above line of code???
Caddy Man

Good sense makes one slow to anger, and it is his glory tooverlook an offense.

Proverbs 19:11

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to distinguish return from print()

2022-05-22 Thread Chris Angelico
On Mon, 23 May 2022 at 09:23, Stefan Ram  wrote:
>   You are making it extra hard by wording the question in this
>   way. "What's the difference between the moon and liberty?". Uh ...
>
>   It's much easier to explain the moon and liberty separately.

"You can't tell the difference between a lump on the head and
margarine. The leadership of the Conservative Party is yours for the
asking!"
-- Grytpype Thynne, "The Last Goon Show of All"

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


how to distinguish return from print()

2022-05-22 Thread Meredith Montgomery
Students seeing a programming language for the first time and using
Python's REPL for the first time have asked me what is the difference
between a return statement and a print() call.  They got a point.

--8<---cut here---start->8---
def f(x):
return x + 1

>>> f(1)
2

>>> print("hello")
hello
--8<---cut here---end--->8---

There's no visual difference.

(*) My answer

The way I know how to answer the difference there is to explain how a
typical computer system works, which is a more or less long answer.  A
return statement is usually just another CPU instruction, while /print/
is a procedure that must eventually run a CPU instruction that
interrupts the CPU, passes control to the operating system which, in
turn, talks to the i/o devices in question (the video, for example) to
get the job finally done.  (We may expect a print() call, therefore, to
be usually much slower than a return statement.)

I also explain that if, say, math.sin(x) is going to print a message to
the screen...

>>> sin(pi/2)
calculating your sine... hang on...
1.0

... I might as well not use it because this will get mixed with my own
print() statements and I'll be surprised about who added that
calculating-your-sine message.  So adding print() statements to
procedures is, in practice, rare.  (To them it's the most typical
operation because they never do any serious programming and they learn
their first steps out on the Internet.  In my course, print() is only
allowed after at 10th homework, after 10 weeks.)

I also explain that if f(x) prints its answer to the screen instead of
returning it, it will be harder to capture the answer in a variable.
For example,

>>> def f(x):
...   print(x + 1)
... 
>>> f(1)
2
>>> y = f(1)
2
>>> y
>>> 
>>> y == None
True

I take this opportunity to remark that Python seems to always returns
something, even if it's the ``special'' value None.

(*) The REPL

I also explain that the REPL is just another program.  Its purpose
happens to be to [r]ead, [e]val, [p]rint and [l]oop, which is why we get
to see return values printed to the screen.

(*) My insatisfaction

I wish I had simpler answers.  Explaining about operating systems, the
CPU, system calls...  I wish there was an easier way to clarify such
things.  You guys might have ideas.

I'm thinking about showing them the code for the simplest toy-REPL so
that we can perhaps demystify the REPL.  I think they see the REPL as
part of the programming language, so I think it might help to figure out
that nothing happens unless code is written to make it happen.  If
something gets displayed on the screen, there is definitely some i/o
going on and print() is the one initiating that i/o, while return is
just another ``arithmetic'' operation such as addition.

Thank you so much.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue512497] multi-line print statement

2022-04-10 Thread admin


Change by admin :


--
github: None -> 36025

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue515000] print result of f.tell() in test

2022-04-10 Thread admin


Change by admin :


--
github: None -> 36054

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue431422] print not emitting POP_TOP

2022-04-10 Thread admin


Change by admin :


--
github: None -> 34599

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue431060] print 'foo',;readline() softspace error

2022-04-10 Thread admin


Change by admin :


--
github: None -> 34596

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue515021] lib/smtpd.py print refused addresses

2022-04-10 Thread admin


Change by admin :


--
github: None -> 36065

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue484866] print '\b', '\a', etc.

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35569

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue477863] Print warning at shutdown if gc.garbage not empty

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35458

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue484857] print with comma ended

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35568

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue480215] softspace confused in nested print

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35499

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue467381] print statement and exception

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35269

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue215918] 2.0b2: print a_module.__dict__ also prints the license text

2022-04-10 Thread admin


Change by admin :


--
github: None -> 33261

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue417030] print '%*s' fails for unicode string

2022-04-10 Thread admin


Change by admin :


--
github: None -> 34363

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue405849] print (float) of Python 2.0

2022-04-10 Thread admin


Change by admin :


--
github: None -> 34058

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue229840] IDLE needs to print !

2022-04-10 Thread admin


Change by admin :


--
github: None -> 33788

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue233717] mimetools: Nice libraries don't "print"

2022-04-10 Thread admin


Change by admin :


--
github: None -> 33995

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue215918] 2.0b2: print a_module.__dict__ also prints the license text

2022-04-10 Thread admin


Change by admin :


___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue401439] Better syntax for print ( 'print [to file [, ]] [(arg , )*]' )

2022-04-10 Thread admin


Change by admin :


___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue401346] print warning if exception occurs in GC

2022-04-10 Thread admin


Change by admin :


___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue400970] extended print statement

2022-04-10 Thread admin


Change by admin :


___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue401439] Better syntax for print ( 'print [to file [, ]] [(arg , )*]' )

2022-04-10 Thread admin


Change by admin :


--
github: None -> 33056

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue401346] print warning if exception occurs in GC

2022-04-10 Thread admin


Change by admin :


--
github: None -> 33009

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue400970] extended print statement

2022-04-10 Thread admin


Change by admin :


--
github: None -> 32648

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45405] configure fails on macOS with non-Apple clang version 13 which implements --print-multiarch

2022-03-15 Thread Ned Deily


Change by Ned Deily :


--
priority: release blocker -> 
resolution:  -> fixed
stage: commit review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45405] configure fails on macOS with non-Apple clang version 13 which implements --print-multiarch

2022-03-15 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset dea270a2a80214de22afadaaca2043d0d782eb7d by Ned Deily in branch 
'3.8':
bpo-45405: Prevent internal configure error when running configure with recent 
versions of clang. (GH-28845) (GH-31889)
https://github.com/python/cpython/commit/dea270a2a80214de22afadaaca2043d0d782eb7d


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45405] configure fails on macOS with non-Apple clang version 13 which implements --print-multiarch

2022-03-15 Thread Ned Deily


Ned Deily  added the comment:


New changeset 720bb456dc711b0776bae837d1f9a0b10c28ddf2 by Ned Deily in branch 
'3.7':
bpo-45405: Prevent internal configure error when running configure with recent 
versions of clang. (GH-28845) (GH-31890)
https://github.com/python/cpython/commit/720bb456dc711b0776bae837d1f9a0b10c28ddf2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45405] configure fails on macOS with non-Apple clang version 13 which implements --print-multiarch

2022-03-15 Thread Ned Deily


Ned Deily  added the comment:

As of Xcode 13.3, released 2022-03-14 to support macOS 12.3 et al, the included 
Apple Clang (Apple clang version 13.1.6 (clang-1316.0.21.2)) now supports the  
--print-multiarch option and so Python 3.8 and 3.7 are now vulnerable to this 
issue when building with that version of Xcode or Apple Command Line Tools on 
macOS. While both 3.8 and 3.7 are now in the security-fix-only phase of their 
life cycles and are not fully supported on macOS 12, you should still be able 
to run ./configure without error using the current Apple Developer Tools. PR 
31889 and PR 31890 are backports of this to 3.8 and 3.7. Setting to "release 
blocker" priority for upcoming 3.8 and 3.7 releases.

--
nosy: +lukasz.langa
priority: normal -> release blocker
resolution: fixed -> 
stage: resolved -> commit review
status: closed -> open
versions: +Python 3.7, Python 3.8 -Python 3.10, Python 3.11, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue45405>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45405] configure fails on macOS with non-Apple clang version 13 which implements --print-multiarch

2022-03-15 Thread Ned Deily


Change by Ned Deily :


--
pull_requests: +29988
pull_request: https://github.com/python/cpython/pull/31890

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45405] configure fails on macOS with non-Apple clang version 13 which implements --print-multiarch

2022-03-15 Thread Ned Deily


Change by Ned Deily :


--
pull_requests: +29987
pull_request: https://github.com/python/cpython/pull/31889

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32669] cgitb file to print OSError exceptions

2022-03-13 Thread Irit Katriel


Irit Katriel  added the comment:

cgi/cgitb are deprecated as per PEP 594, so there won't be further enhancements 
to them.

--
nosy: +iritkatriel
resolution:  -> wont fix
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46949] Print an indication if traceback exceeds sys.tracebacklimit

2022-03-07 Thread Irit Katriel

Irit Katriel  added the comment:

Re what the limit means, it’s a bit messier than that, see issue38197.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46949] Print an indication if traceback exceeds sys.tracebacklimit

2022-03-07 Thread Eric V. Smith


Eric V. Smith  added the comment:

If you go with the second idea, I'd say something like f"More than {2 * 
tracebacklimit} additional stack frames not shown". It seems handy to know the 
magnitude of the problem.

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46949] Print an indication if traceback exceeds sys.tracebacklimit

2022-03-07 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

It skips the least recent frames:

>>> def error(): 1 / 0
... 
>>> def g(): error()
... 
>>> def f(): g()
... 
>>> sys.tracebacklimit = 2
>>> f()
Traceback (most recent call last):
  File "", line 1, in g
  File "", line 1, in error
ZeroDivisionError: division by zero
>>> sys.tracebacklimit = 5
>>> f()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in f
  File "", line 1, in g
  File "", line 1, in error
ZeroDivisionError: division by zero

(tried on current main)

I think that's the right behavior because it tells you the function that 
actually throws the error, which is much harder to figure out from scratch than 
where the call started.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46949] Print an indication if traceback exceeds sys.tracebacklimit

2022-03-07 Thread Guido van Rossum


Guido van Rossum  added the comment:

There is general confusion as to which part of the traceback is truncated. If I 
have main() -> f() -> g() -> error(), and the limit is 2, does it print main() 
-> f(), or does it print g() -> error()? (I'm not even sure which would be more 
useful.)

FWIW the reason I suggested printing "many" is a worry that somehow a bug could 
cause counting the length of the list to take forever (e.g. if it ends in a 
cycle). It would seem more robust to limit the count.

--

___
Python tracker 
<https://bugs.python.org/issue46949>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46949] Print an indication if traceback exceeds sys.tracebacklimit

2022-03-07 Thread Jelle Zijlstra


New submission from Jelle Zijlstra :

If the number of frames in a traceback exceeds sys.tracebacklimit (which 
defaults to 1000), any remaining frames are silently dropped. See 
https://docs.python.org/3.10/library/sys.html#sys.tracebacklimit.

This is confusing to users. We should print some indication like "N additional 
stack frames not shown".

Here are some specific ideas:
- tracebacklimit <= 0 is documented as dropping the whole traceback. In that 
case, we don't need too print any message.
- It may be expensive to compute a complete count. Perhaps we can count frames 
up to 2 * tracebacklimit, and just say "Many additional stack frames not shown".
- The C implementation is in tb_print_internal() in traceback.c, and the Python 
one in _extract_from_extended_frame_gen in traceback.py.

--
components: Interpreter Core
messages: 414674
nosy: Jelle Zijlstra, gvanrossum, iritkatriel
priority: normal
severity: normal
status: open
title: Print an indication if traceback exceeds sys.tracebacklimit
type: enhancement
versions: Python 3.11

___
Python tracker 
<https://bugs.python.org/issue46949>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34135] The results of time.tzname print broken.

2022-01-17 Thread Irit Katriel


Change by Irit Katriel :


--
stage:  -> resolved
status: pending -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-07 Thread Barry A. Warsaw


Barry A. Warsaw  added the comment:

> Barry: The PEP 8 'return None' recommendation could be added to the Reference 
> entry for 'return'.  But I think this should be a separate issue as 1) it is 
> about coding rather than documentation and 2) there is the possible objection 
> that choosing completely explicit 'return None' versus half explicit, half 
> implicit 'return' and the latter versus completely implicit  
> should be left to the style PEP.

I do think it's a question of style.  Section 7.6 of the language reference 
says:

> If an expression list is present, it is evaluated, else None is substituted.

which is the important concept that beginners should learn.

I agree that the admonition in PEP 8 is really trying to say "don't mix 
implicit and explicit return styles".  Implicit None return is fine if all exit 
paths are implicit.  But once you add an explicit value to a return path, all 
return paths should use explicit values, including those that return None.

IME, while I do occasionally encounter push back on this when doing reviews, 
most folks come around to this p.o.v.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-07 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

How about following "The Python interpreter has a number of functions and types 
built into it that are always available. They are listed here in alphabetical 
order." in
https://docs.python.org/3/library/functions.html
with "Here and elsewhere in these docs, entries for functions (including 
methods) that always return None usually omit 'Return None' and just say what 
the function does."

Barry: The PEP 8 'return None' recommendation could be added to the Reference 
entry for 'return'.  But I think this should be a separate issue as 1) it is 
about coding rather than documentation and 2) there is the possible objection 
that choosing completely explicit 'return None' versus half explicit, half 
implicit 'return' and the latter versus completely implicit  
should be left to the style PEP.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-07 Thread Éric Araujo

Change by Éric Araujo :


--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-06 Thread James Gerity


James Gerity  added the comment:

The original question was closer to the related issue of "indicate return types 
for all built-ins," conversation log follows (UTC-5):

```
09:33:50 ringo__ | is there a stdlib api docs which actually has *full* 
functions signature?
   
09:34:27 ringo__ | for example, 
https://docs.python.org/3/library/functions.html, function  

   
 | abs(x), it returns what, int? I need to read the 
whole sentence to figure
   
 | out the return value of a function?  

   
09:34:48 ringo__ | (or argument for that matter)

   
09:35:51 bjs | ringo__: well like it says it doesn't just support 
int 
 
09:36:00 bjs | int, float, or any type that supports it 

   
09:37:01 bjs | in general you can find actual type annotations for 
the functions in the

 | typeshed 

   
 | 
https://github.com/python/typeshed/blob/master/stdlib/builtins.pyi  


09:37:32 bjs | I wonder if it would be useful to include the 
typeshed annotation in the  
  
 | docs, or whether it would be more confusing  

   
09:37:49 ringo__ | Thanks bjs ! I'll bookmark this typeshed 

   
09:38:13  SnoopJ | abs() will do whatever __abs__() on the type does, 
which can be different  
 
 | for any given type. You'd expect T -> T but it's not 
guaranteed. 
   
09:38:18 ringo__ | I used abs() as an example. In fact I was wondering 
what does print()   

 | return. I *guessed* it returns None, but the docs 
won't say   
  
09:39:05 ringo__ | I could do a try-it-yourself approach but I was 
puzzled why the docs

 | simply won't give you full fn signature, ie 
print(..) -> None   

09:39:17  SnoopJ | that one is just an omission :)
```

--

___
Python tracker 
<https://bugs.python.org/issue46282>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-06 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Sure, there will always be some users who will find certain things not 
obvious. Sometimes I'm that user myself.

What did this user think print() returned? What precisely was their 
question? Perhaps if I saw the conversation in context, I would be more 
sympathetic to this.

I can see a difference between (for example) the questions:

"I see that print('Hello world') returns None, but is it safe to assume 
that print will *always* return None? It is not documented anywhere as 
far as I can see."

and

"What does x = print('Hello world') do?"

--

___
Python tracker 
<https://bugs.python.org/issue46282>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-06 Thread Barry A. Warsaw


Barry A. Warsaw  added the comment:

I think it does a better service to users to explain how Python returns None 
implicitly if a function doesn't have any other explicit return value.  If the 
print() docs had this note, it would be confusing why other similar functions 
don't.

It's also worth explaining that when a function is designed to *explicitly* 
return None in certain cases (e.g. dict.get()) that it shouldn't do so 
implicitly, but should include an explicit `return None` for readability.

--
nosy: +barry

___
Python tracker 
<https://bugs.python.org/issue46282>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-06 Thread James Gerity


James Gerity  added the comment:

I opened this ticket on behalf of a user who asked about print() specifically 
in #python on the Libera IRC network, who I assume does not find this obvious.

I don't think it would be tenable to add this note to every built-in, but 
that's not the intended scope of this issue. I do think it's worth mentioning 
for print(), though.

--

___
Python tracker 
<https://bugs.python.org/issue46282>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-06 Thread Steven D'Aprano


New submission from Steven D'Aprano :

Do the print docs need to mention something so obvious?

Functions and methods which operate by side-effect typically don't mention that 
they return None, see for example the docs for various builtin methods:

https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types

e.g. s.append, s.clear, s.extend, s.insert, s.remove, s.reverse

and likewise for list.sort, set.add, dict.clear and many others.

(However, dict.update is a rare exception, it does mention that it returns 
None.)

We should not feel it necessary to add an explicit comment to every function or 
method that operates by side-effect stating that they return None.

--
nosy: +steven.daprano

___
Python tracker 
<https://bugs.python.org/issue46282>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-06 Thread James Gerity


Change by James Gerity :


--
keywords: +patch
pull_requests: +28642
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30435

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46282] print() docs do not indicate its return value

2022-01-06 Thread James Gerity


Change by James Gerity :


--
assignee: docs@python
components: Documentation
nosy: SnoopJeDi, docs@python
priority: normal
severity: normal
status: open
title: print() docs do not indicate its return value
versions: Python 3.11

___
Python tracker 
<https://bugs.python.org/issue46282>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46199] Calculation influenced by print

2021-12-31 Thread Mark Dickinson


Mark Dickinson  added the comment:

When you do:

FINUB = np.empty(len(close))
FINLB = np.empty(len(close))

you're creating two *uninitialised* arrays of values. (See the NumPy 
documentation at 
https://numpy.org/doc/stable/reference/generated/numpy.empty.html.)

When you then do 

FINUB[i] = UB[i] if UB[i] < FINUB[i-1] \
and close[i-1] > FINUB[i] else FINUB[i-1]

on the first iteration of the loop (i = 1), you make use of the (undefined) 
value in FINUB[0] to compute FINUB[1].

In other words, this is a bug in your code, rather than in Python or NumPy.

--
nosy: +mark.dickinson
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46210] print deadlocks

2021-12-30 Thread Jason Wilkes


Change by Jason Wilkes :


--
keywords: +patch
pull_requests: +28524
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30310

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46210] print deadlocks

2021-12-30 Thread Jason Wilkes


New submission from Jason Wilkes :

Hi there. :)

(First time posting here, so apologies in advance if I'm a goof.)

I recently found a deadlock in the stdout and stderr buffer objects.

Following the dev guide, I

(1) wrote up a patch

(2) checked that it fixes the deadlock (on Linux and OS X)

(3) made sure it doesn't break any of the cpython tests (on Linux and OS X)

But I could use some feedback to make sure the patch isn't doing anything dumb, 
and to make sure I'm not missing something obvious.

Here's the situation.

The deadlock only occurs in the sinful state of threading while forking. (I'm 
aware of the reasons why one should never do that.)

But asking newcomers to never mix the two is sort of asking them to know the 
implementation details of every library they use (these abstractions are 
leaky). And I like teaching people about python and concurrency, so it would be 
nice if they didn't have to know all that.

So I've recently developed the ill-advised hobby of trying to run as much code 
as possible in the sinful state of threading while forking, to try to 
understand which bits of the interpreter and standard library are responsible 
for most of the deadlocks, in practice.

All the non-obvious deadlocks I've encountered seemed to be due to one thing, 
namely stdout and stderr's buffer->lock not having an _at_fork_reinit. So if a 
thread is printing during a fork, the child process can never print, else 
deadlock. Standard hazard of threading and forking.

What surprised me was that there didn't seem to be 100s of places in the 
interpreter where threading and forking don't mix. After fixing this one, all 
the different thread + fork code I'd been testing worked.

Which makes me wonder if there's a reason this hasn't been fixed yet.

Hence, maybe the patch is doing something dumb.

Anyways, this is sort of a bug report, and sort of a request for comments on 
how I can make this patch better. Equally cool would be an explanation of why 
re-initializing that lock is a bad idea to begin with.

Thanks for your patience if you read all that.

--
components: IO
files: example.py
messages: 409394
nosy: notarealdeveloper
priority: normal
severity: normal
status: open
title: print deadlocks
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9
Added file: https://bugs.python.org/file50532/example.py

___
Python tracker 
<https://bugs.python.org/issue46210>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46199] Calculation influenced by print

2021-12-30 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Please try to provide a minimal reproducible example:

https://stackoverflow.com/help/minimal-reproducible-example

http://sscce.org/

At the very least, you need to provide three pieces of information:

1. What you tried.
2. What you expected to happen (and why, if it isn't obvious).
3. What actually happened instead.


Ideally you should be able to get your example down to using one or two values, 
not three lists with 30 values each (90 values).

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46199] Calculation influenced by print

2021-12-29 Thread Eric V. Smith


Eric V. Smith  added the comment:

This is likely not a bug in python. You might have better luck asking on a 
numpy support list.

That said, what results do you get, and what do you expect to get? We don't 
know what error you're seeing.

You might replace:
print("LB: ", LB)

with:
str(LB)

and see what happens. That's the only operation that's called on LB when you're 
printing.

--
nosy: +eric.smith

___
Python tracker 
<https://bugs.python.org/issue46199>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46199] Calculation influenced by print

2021-12-29 Thread wby78826


New submission from wby78826 :

(Could be a numpy bug)
##Just run the script, then uncomment Line 14 and run again
The result of "supertrend" is different, depending on whether I print "LB" 
first or not.
If I don't print it first, the result is wrong.

It also does'nt matter if I print it to stdout or stderr, it only works this 
way.

(sry if I did something wrong)

--
components: Windows
files: supertrend.py
messages: 409343
nosy: paul.moore, steve.dower, tim.golden, wby78826, zach.ware
priority: normal
severity: normal
status: open
title: Calculation influenced by print
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file50527/supertrend.py

___
Python tracker 
<https://bugs.python.org/issue46199>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-12-21 Thread boB Stepp

On 21/12/22 12:14PM, Python wrote:

On 30/11/2021 12.31, Cameron Simpson wrote:

On 30Nov2021 10:59, DL Neil  wrote:

...


I've nominated Kitty as
Fedora's default terminal. We'll see how it goes with work-loads beyond
raising the flag...


I'd like to hear how that goes down the track. If I find myself on a
Linux desktop again a good terminal emulator would be very welcome.



(given that @A-R has brought this thread back-to-life)


I have been surprised/shocked/horrified/annoyed to discover that the
(Linux) clipboard is not accessible from "Kitty".


Huh?  I use kitty and copy to and from the clipboard all the time.
1) ctrl+shift+c Copy to clipboard
2) ctrl+shift+v Paste from the clipboard
3) Using mouse to select text automatically copies it to the primary 
clipboard.
4) Middle-click of mouse to paste from the primary clipboard.


--
Wishing you only the best,
boB Stepp

Speeches are like steer horns -- a point here, a point there and a lot of bull
in between.
-- E. Anderson
--
https://mail.python.org/mailman/listinfo/python-list


Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-12-21 Thread dn via Python-list
On 30/11/2021 12.31, Cameron Simpson wrote:
> On 30Nov2021 10:59, DL Neil  wrote:
...

>> I've nominated Kitty as
>> Fedora's default terminal. We'll see how it goes with work-loads beyond
>> raising the flag...
> 
> I'd like to hear how that goes down the track. If I find myself on a 
> Linux desktop again a good terminal emulator would be very welcome.


(given that @A-R has brought this thread back-to-life)


I have been surprised/shocked/horrified/annoyed to discover that the
(Linux) clipboard is not accessible from "Kitty".

Go on, I dare you to remind me that good-old 'dumb-terminals' didn't
have 'clipboards'...
(neither did they have to cope with Unicode, emoticons, or national flags!)


Accordingly, having developed an idea in the REPL (running within
Kitty), could not later copy-paste into a Python module or tutorial text
(nor, next time the situation arises, to be able to illustrate an answer
to a question posted 'here').

Am somewhat in disbelief, and my fingers feel slightly singed. Grump!
(or its seasonal variation: "Grinch")


Am open to further non-terminal, terminal suggestions...

(during my post-op recovery period, am hoping to experiment with another
Linux distro (and Window Manager), which may alter the playing-field...)


Meantime, casting-off the terminal-Grinch, compliments of the season to
you...
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyCharm settings - per: print('\N{flag: Mauritius}') not supported in py3.9

2021-12-21 Thread Abdur-Rahmaan Janhangeer
Yet another unicode issue XD

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue34135] The results of time.tzname print broken.

2021-12-12 Thread Irit Katriel


Change by Irit Katriel :


--
resolution:  -> out of date
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



PyCharm settings - per: print('\N{flag: Mauritius}') not supported in py3.9

2021-12-01 Thread dn via Python-list
On 29/11/2021 10.08, dn via Python-list wrote:
> On 29/11/2021 02.18, Chris Angelico wrote:
>> On Mon, Nov 29, 2021 at 12:10 AM Abdur-Rahmaan Janhangeer
>>  wrote:
>>
>> Flags are actually constructed from multiple codepoints. What you want
>> is to insert each codepoint separately. You can see them listed in the
>> second column of the table you linked to.
>>
> "\U0001F1F2\U0001F1FA"
>> ''
>>
>> To do this with names, you need the names of those two codepoints:
>>
>> '\U0001f1f2' REGIONAL INDICATOR SYMBOL LETTER M
>> '\U0001f1fa' REGIONAL INDICATOR SYMBOL LETTER U
>>
> "\N{REGIONAL INDICATOR SYMBOL LETTER M}\N{REGIONAL INDICATOR SYMBOL 
> LETTER U}"
>> ''
> 
> 
> Don't use Emojis that often. The colored circles (U+1F534 etc) display
> in full, glorious, technicolor.
> 
> However, when trying the above, with our local flag in (Fedora Linux,
> Gnome) Terminal or PyCharm's Run terminal; the two letters "N" and "Z"
> are shown with dotted-outlines. Similarly, the Mauritius' flag is shown
> as "M" and "U".


Investing a bit of time/waiting for a meeting, found a number of Issues
lodged with JetBrains relating to emoji-support/display:-

Among the most recent advice is to add a "Fallback font" which is known
to include (colored!) emojis.

Thus (this includes personal settings):

File > Settings > Editor > Font
Font = IBM Plex Mono
drop down > Typography Settings
Fallback font = Twemoji

After which, patriotic-pride may be expressed!


However, the Issues (that is to say, those which I had time/energy to
read) indicate that there may still be differences between Linux, Mac,
Windows, and that 'franken-thing' which is Linux on top of Windows but
we don't label it "Linux" so that people still think it is "Windows".


Further wrinkles (drifting OT!):

Fedora 33's Gnome Font Viewer shows:
Emoji One
Noto Color Emoji
Twemoji

- don't ask me the why/when/where of Twemoji
- the other two were added via dnf (yum) today

Neither shows in PyCharm's drop-down list of choices - even after
stop/start (which doesn't appear strictly necessary, per above, but...).


Performed:

fc-cache -fv

and the listing verifies their presence, and ensures all is compos-mentis.

In Writer, all three appear (without prefix). Still only the one appears
in PyCharm. (sigh...)


PS thanks to the OP! Certainly opened my eyes and befuddled (what's left
of) my brain. Was planning to use the aforementioned 'colored circles'
in a PUG coding exercise, but have now amended to require coders to
'wave the flag'. Hopefully they will find such slightly more amusing...
Salute!
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-11-29 Thread Cameron Simpson
On 30Nov2021 10:59, DL Neil  wrote:
>Fedora names it as rxvt-unicode.
>Installed v9.26
>Text is too small for these old eyes.

Fair enough. There are resources, but not worth it unless you really 
want the app.

>No menu bar and no context menus.

Um, yes. The (hardware, serial) terminals we had a uni didn't have such 
niceties, and therefore we should not want them.

>Unable to copy-paste (the flag codes) into that window.
>Removed.

Fair enough.

>I choose not to even try to remember the difficulties of working with
>small screens over-laying one another and 'getting lost' in the pile!

Aye. Tiling is very nice.

>I'm a lazy toad. Thus the idea that the IDE will allow me to 'press a
>(single) button' to repeat the last-run test/execute the code, without
>me having to commit a Save and to jump between panels/windows/screens,
>is seductive.

I once had a vi macro bound to ";" for "^W:!!^M", which autosaves the 
current file and reran the last shell command. Used it a lot in the 
single-terminal days. I unbound it several years ago though.

>I've nominated Kitty as
>Fedora's default terminal. We'll see how it goes with work-loads beyond
>raising the flag...

I'd like to hear how that goes down the track. If I find myself on a 
Linux desktop again a good terminal emulator would be very welcome.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-11-29 Thread dn via Python-list
On 30/11/2021 10.19, Cameron Simpson wrote:
> On 29Nov2021 22:25, DL Neil  wrote:
 Probably a font issue. Not many fonts support the flags.
>>>
>>> Agree about the font support. Some terminal emulators make an effort to
>>> have fallback fonts for when your preferred font lacks a glyph. IIRC
>>> urxvt is such a terminal on Linux.
>>
>> Not sure about this. Most other applications on this PC will display the
>> two countries' flags, as desired, eg Writer, web-browser, even xed
>> (basic text editor).
> 
> Seem Stefan Ram's advice, which points out that you can tell if this is 
> a font problem (no flag glyph) or a combining problem (2 glyphs 
> presented instead of one). I had not considered that.

@Stefan's advice preceded by report that two glyphs were printed (not
one): "the two letters "N" and "Z" are shown with dotted-outlines"
(I think, the UTF-16 decoding)


>> rxvt: won't compile, gave-up fighting unfamiliar requirements
> 
> See if there's a package for urxvt, which was the "unicode" flavour of 
> rxvt (long ago - rxvt if probably supposed to be unicode capable these 
> days, surely).

Fedora names it as rxvt-unicode.
Installed v9.26
Text is too small for these old eyes.
No menu bar and no context menus.
Unable to copy-paste (the flag codes) into that window.
Removed.


>> Kitty: works!
> 
> Yay!
> 
>> Kitty is not something I've come-across before. Its write-up says
>> «
>> Kitty is a free, open-source, and fast, feature-rich, GPU accelerated
>> terminal emulator for Linux, that supports all present-day terminal
>> features, such as Unicode, true color, text formatting, bold/italic
>> fonts, tiling of multiple windows and tabs, etc.
> 
> A tiling terminal emulator can be a great thing. I'm on a Mac with 
> iTerm, which:
> - has tabs
> - has panes (split the view into multiple panels, each running a 
>   terminal)
> 
> My personal dev desktop tends to use a full screen iTerm split 
> vertically into 2 panes: an editor on the left (vim, itself split 
> vertically into 2 vim windows) and a shell on the right; sometimes 
> several shells (right hand pane further split horizontally).
> 
> Then, since I tend to keep per-branch checkouts around, tabs for the 
> things I'm working on, each configured as above. Then I just switch tabs 
> for the different areas.


Yes, a good way to work. Neatly explained.

I choose not to even try to remember the difficulties of working with
small screens over-laying one another and 'getting lost' in the pile!

My desktop/dev.svr features two screens: one in 'portrait mode' and the
other 'landscape'. The former is very good for code-listings. The latter
for execution-display, pytest reports, etc. As you describe, each can be
sub-divided when needs-arise. A neat feature is that "Tool Windows" can
be tucked-away, and only 'pulled-out' when required, eg am not looking
at Sourcery's assessments right now (unless it highlights the commission
of some 'crime' as I type) but will check prior to (or as part of) git
commit. The Tool Window's name/label in the 'dock' also forms a reminder
that I shouldn't (totally) neglect my responsibilities!

These are managed within the IDE - sadly, PyCharm's terminal/console
fails the 'flag test', as reported yesterday. (am not sure if one might
be able to select which terminal emulator to use ...)

I'm a lazy toad. Thus the idea that the IDE will allow me to 'press a
(single) button' to repeat the last-run test/execute the code, without
me having to commit a Save and to jump between panels/windows/screens,
is seductive.

Don't tell my trainees! Every course sees three or four who 'cry for
help' because making some change in their choice of editor/IDE does not
result in similar within the web-browser. Did you forget to save the
source, Luke? That's not to say there won't be considerably more who
manage to diagnose the problem without admitting such to 'the outside
world'!


There are times when there is no need to (wait quite a while to) boot-up
a whole IDE, eg running a utility program. I've nominated Kitty as
Fedora's default terminal. We'll see how it goes with work-loads beyond
raising the flag...
Salute!
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-11-29 Thread Cameron Simpson
On 29Nov2021 22:25, DL Neil  wrote:
>>> Probably a font issue. Not many fonts support the flags.
>>
>> Agree about the font support. Some terminal emulators make an effort to
>> have fallback fonts for when your preferred font lacks a glyph. IIRC
>> urxvt is such a terminal on Linux.
>
>Not sure about this. Most other applications on this PC will display the
>two countries' flags, as desired, eg Writer, web-browser, even xed
>(basic text editor).

Seem Stefan Ram's advice, which points out that you can tell if this is 
a font problem (no flag glyph) or a combining problem (2 glyphs 
presented instead of one). I had not considered that.

>rxvt: won't compile, gave-up fighting unfamiliar requirements

See if there's a package for urxvt, which was the "unicode" flavour of 
rxvt (long ago - rxvt if probably supposed to be unicode capable these 
days, surely).

>Kitty: works!

Yay!

>Kitty is not something I've come-across before. Its write-up says
>«
>Kitty is a free, open-source, and fast, feature-rich, GPU accelerated
>terminal emulator for Linux, that supports all present-day terminal
>features, such as Unicode, true color, text formatting, bold/italic
>fonts, tiling of multiple windows and tabs, etc.

A tiling terminal emulator can be a great thing. I'm on a Mac with 
iTerm, which:
- has tabs
- has panes (split the view into multiple panels, each running a 
  terminal)

My personal dev desktop tends to use a full screen iTerm split 
vertically into 2 panes: an editor on the left (vim, itself split 
vertically into 2 vim windows) and a shell on the right; sometimes 
several shells (right hand pane further split horizontally).

Then, since I tend to keep per-branch checkouts around, tabs for the 
things I'm working on, each configured as above. Then I just switch tabs 
for the different areas.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue45912] [argparse] Print texts starting with capital letters and finish with dot for more formality

2021-11-29 Thread Eric V. Smith


Eric V. Smith  added the comment:

I agree with @iritkatriel. Also, such a change to argparse would be too 
disruptive. So, I'm going to close this.

--
components: +Library (Lib) -Parser
nosy: +eric.smith
resolution:  -> wont fix
stage:  -> resolved
status: open -> closed
type:  -> enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-11-29 Thread dn via Python-list
On 29/11/2021 12.06, Cameron Simpson wrote:
> On 29Nov2021 09:19, Chris Angelico  wrote:
>> On Mon, Nov 29, 2021 at 8:10 AM dn via Python-list
>>  wrote:
>>> However, when trying the above, with our local flag in (Fedora Linux,
>>> Gnome) Terminal or PyCharm's Run terminal; the two letters "N" and "Z"
>>> are shown with dotted-outlines. Similarly, the Mauritius' flag is shown
>>> as "M" and "U".
>>>
>>> Whereas here in email (Thunderbird) or in a web-browser, the flags
>>> appear, as desired.
>>>
>>> Is this a terminal short-coming (locale charmap -> UTF-8 - which brings
>>> to mind the old UCS-4 questions), a font issue, or what (to fix)?
>>
>> Probably a font issue. Not many fonts support the flags.
> 
> Agree about the font support. Some terminal emulators make an effort to 
> have fallback fonts for when your preferred font lacks a glyph. IIRC 
> urxvt is such a terminal on Linux.


Not sure about this. Most other applications on this PC will display the
two countries' flags, as desired, eg Writer, web-browser, even xed
(basic text editor).

Accordingly, took @Cameron's advice. Leading to:

Gnome Terminal: won't display "\U0001F1F3\U0001F1FF" (etc)
Terminator: won't display
Tabby: doesn't seem to load from (rpm) repo
RoxTerm: no choice of fonts, won't display
rxvt: won't compile, gave-up fighting unfamiliar requirements
Terminology: offers choice of fonts, but still fails

Kitty: works!


Kitty is not something I've come-across before. Its write-up says
«
Kitty is a free, open-source, and fast, feature-rich, GPU accelerated
terminal emulator for Linux, that supports all present-day terminal
features, such as Unicode, true color, text formatting, bold/italic
fonts, tiling of multiple windows and tabs, etc.

Kitty is written in C and Python programming languages, and it is one of
few terminal emulators with GPU support
»


Yes, the one that 'works', is using the same fonts as (say) Writer, and
the original (Gnome) Terminal that fails.


Please don't take this as a scientific survey. I didn't spend any time
investigating - either the s/w worked or it didn't! However, a terminal
is doing a simple job (at the user-level), so there's not much to them
in terms of knobs to twiddle or levers to pull.
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-11-28 Thread Cameron Simpson
On 29Nov2021 09:19, Chris Angelico  wrote:
>On Mon, Nov 29, 2021 at 8:10 AM dn via Python-list
> wrote:
>> However, when trying the above, with our local flag in (Fedora Linux,
>> Gnome) Terminal or PyCharm's Run terminal; the two letters "N" and "Z"
>> are shown with dotted-outlines. Similarly, the Mauritius' flag is shown
>> as "M" and "U".
>>
>> Whereas here in email (Thunderbird) or in a web-browser, the flags
>> appear, as desired.
>>
>> Is this a terminal short-coming (locale charmap -> UTF-8 - which brings
>> to mind the old UCS-4 questions), a font issue, or what (to fix)?
>
>Probably a font issue. Not many fonts support the flags.

Agree about the font support. Some terminal emulators make an effort to 
have fallback fonts for when your preferred font lacks a glyph. IIRC 
urxvt is such a terminal on Linux.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-11-28 Thread Chris Angelico
On Mon, Nov 29, 2021 at 8:10 AM dn via Python-list
 wrote:
> However, when trying the above, with our local flag in (Fedora Linux,
> Gnome) Terminal or PyCharm's Run terminal; the two letters "N" and "Z"
> are shown with dotted-outlines. Similarly, the Mauritius' flag is shown
> as "M" and "U".
>
> Whereas here in email (Thunderbird) or in a web-browser, the flags
> appear, as desired.
>
> Is this a terminal short-coming (locale charmap -> UTF-8 - which brings
> to mind the old UCS-4 questions), a font issue, or what (to fix)?

Probably a font issue. Not many fonts support the flags.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: print('\N{flag: Mauritius}') not supported in py3.9

2021-11-28 Thread dn via Python-list
On 29/11/2021 02.18, Chris Angelico wrote:
> On Mon, Nov 29, 2021 at 12:10 AM Abdur-Rahmaan Janhangeer
>  wrote:
> 
> Flags are actually constructed from multiple codepoints. What you want
> is to insert each codepoint separately. You can see them listed in the
> second column of the table you linked to.
> 
 "\U0001F1F2\U0001F1FA"
> ''
> 
> To do this with names, you need the names of those two codepoints:
> 
> '\U0001f1f2' REGIONAL INDICATOR SYMBOL LETTER M
> '\U0001f1fa' REGIONAL INDICATOR SYMBOL LETTER U
> 
 "\N{REGIONAL INDICATOR SYMBOL LETTER M}\N{REGIONAL INDICATOR SYMBOL LETTER 
 U}"
> ''


Don't use Emojis that often. The colored circles (U+1F534 etc) display
in full, glorious, technicolor.

However, when trying the above, with our local flag in (Fedora Linux,
Gnome) Terminal or PyCharm's Run terminal; the two letters "N" and "Z"
are shown with dotted-outlines. Similarly, the Mauritius' flag is shown
as "M" and "U".

Whereas here in email (Thunderbird) or in a web-browser, the flags
appear, as desired.

Is this a terminal short-coming (locale charmap -> UTF-8 - which brings
to mind the old UCS-4 questions), a font issue, or what (to fix)?
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   9   10   >