Re: Printing UTF-8 mail to terminal

2024-10-31 Thread Left Right via Python-list
There's quite a lot of misuse of terminology around terminal / console
/ shell.  Please, correct me if I'm wrong, but it looks like you are
printing that on MS Windows, right?  MS Windows doesn't have or use
terminals (that's more of a Unix-related concept). And, by "terminal"
I mean terminal emulator (i.e. a program that emulates the behavior of
a physical terminal). You can, of course, find some terminal programs
for windows (eg. mintty), but I doubt that that's what you are dealing
with.

What MS Windows users usually end up using is the console.  If you
run, eg. cmd.exe, it will create a process that displays a graphical
console.  The console uses an encoding scheme to represent the text
output.  I believe that the default on MS Windows is to use some
single-byte encoding. This answer from SE family site tells you how to
set the console encoding to UTF-8 permanently:
https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8
, which, I believe, will solve your problem with how the text is
displayed.

On Thu, Oct 31, 2024 at 5:19 PM Loris Bennett via Python-list
 wrote:
>
> Hi,
>
> I have a command-line program which creates an email containing German
> umlauts.  On receiving the mail, my mail client displays the subject and
> body correctly:
>
>   Subject: Übung
>
>   Sehr geehrter Herr Dr. Bennett,
>
>   Dies ist eine Übung.
>
> So far, so good.  However, when I use the --verbose option to print
> the mail to the terminal via
>
>   if args.verbose:
>   print(mail)
>
> I get:
>
>   Subject: Übungsbetreff
>
>   Sehr geehrter Herr Dr. Bennett,
>
>   Dies ist eine =C3=9Cbung.
>
> What do I need to do to prevent the body from getting mangled?
>
> I seem to remember that I had issues in the past with a Perl version of
> a similar program.  As far as I recall there was an issue with fact the
> greeting is generated by querying a server, whereas the body is being
> read from a file, which lead to oddities when the two bits were
> concatenated.  But that might just have been a Perl thing.
>
> Cheers,
>
> Loris
>
> --
> This signature is currently under constuction.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read

2024-10-31 Thread Jon Ribbens via Python-list
On 2024-10-31, Loris Bennett  wrote:
> Jon Ribbens  writes:
>> On 2024-10-30, Loris Bennett  wrote:
>>> Jon Ribbens  writes:
 On 2024-10-30, Loris Bennett  wrote:
> Jon Ribbens  writes:
>> As per the docs you link to, the read() method only takes filename(s)
>> as arguments, if you have an already-open file you want to read then
>> you should use the read_file() method instead.
>
> As you and others have pointed out, this is indeed covered in the docs,
> so mea culpa.
>
> However, whereas I can see why you might want to read the config from a
> dict or a string, what would be a use case in which I would want to
> read from an open file rather than just reading from a file(name)?

 The ConfigParser module provides read(), read_file(), read_string(),
 and read_dict() methods. I think they were just trying to be
 comprehensive. It's a bit non-Pythonic really.
>>>
>>> OK, but is there a common situation might I be obliged to use
>>> 'read_file'?  I.e. is there some common case where the file name is not
>>> available, only a corresponding file-like object or stream?
>>
>> Well, sure - any time it's not being read from a file. A bit ironic
>> that the method to use in that situation is "read_file", of course.
>> In my view the read() and read_file() methods have their names the
>> wrong way round. But bear in mind this code is 27 years old, and
>> the read() function came first.
>
> Yes, I suppose history has a lot to answer for :-)
>
> However I didn't make myself clear: I understand that there are
> different functions, depending on whether I have a file name or a
> stream.  Nevertheless, I just can't think of a practical example where I
> might just have *only* a stream, especially one containing my
> configuration data.  I was just interested to know if anyone can give an
> example.

That was answered the first sentence of my reply. It's a bit vague
because in most of the situations I can think of, one of the other
read_*() methods would probably be more appropriate. But again,
the history is that read_file() was added first (originally called
readfp() ) so it had to handle all cases where the data being read
was not coming from a named filesystem file - e.g. it's coming over
a Unix socket, or an HTTP request, or from a database.

It is good practice in general to provide a method that allows your
class to read data as a stream, if that is appropriate for what
you're doing, so that people aren't unnecessarily forced to load
data fully into memory or write it to a file, as well as perhaps a
convenience method thaat will read from a named file for people who
are doing that.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: PyDDF Python Herbst Sprint 2024

2024-10-31 Thread eGenix Team via Python-list


/This announcement is in German since it targets a local user 
group//meeting in Düsseldorf, Germany/



   Ankündigung

Python Meeting Herbst Sprint 2024 
 in

Düsseldorf 

Samstag, 09.11.2024, 10:00-18:00 Uhr
Sonntag, 10.11.2024. 10:00-18:00 Uhr

/Eviden / Atos Information Technology GmbH 
/, Am Seestern 1, 40547 Düsseldorf



   Informationen

Das Python Meeting Düsseldorf (PyDDF)  veranstaltet 
mit freundlicher Unterstützung von Eviden Deutschland 
ein Python Sprint Wochenende.


Der Sprint findet am Wochenende 09./10.11.2024 in der Eviden / Atos 
Niederlassung, Am Seestern 1, in Düsseldorf statt.


 * Sprint Ort in Google Maps 

Folgende Themengebiete sind als Anregung bereits angedacht:

 * *AI/ML: Bilderkennung* mit Azure Computervision
 * *AI/ML: Texte und Meta Daten aus Presseseiten extrahieren*, mit
   Hilfe eines lokalen LLMs
 * *AI/ML: Transkription* von Videos/Audiodateien mit Whisper
 * *Kodi Add-Ons* für ARD, ZDF und ARTE
   **

Natürlich können die Teilnehmenden weitere Themen vorschlagen und umsetzen.


   Anmeldung, Kosten und weitere Infos

Alles weitere und die Anmeldung findet Ihr auf der Meetup Sprint Seite:

 * *Python Spring Sprint & Hackathon in Düsseldorf*
   

*WICHTIG*: Ohne Anmeldung können wir den Gebäudezugang nicht 
vorbereiten. Eine spontane Anmeldung am Sprint Tag wird daher vermutlich 
nicht funktionieren.


Teilnehmer sollten sich zudem in der PyDDF Telegram Gruppe registrieren, 
da wir uns dort koordinieren:


 * *PyDDF Telegram Gruppe *


   Über das Python Meeting Düsseldorf

Das Python Meeting Düsseldorf  ist eine regelmäßige 
Veranstaltung in Düsseldorf, die sich an Python-Begeisterte aus der 
Region wendet.


Einen guten Überblick über die Vorträge bietet unser PyDDF YouTube-Kanal 
, auf dem wir Videos der Vorträge nach 
den Meetings veröffentlichen.


Veranstaltet wird das Meeting von der eGenix.com GmbH 
, Langenfeld, in Zusammenarbeit mit Clark 
Consulting & Research , Düsseldorf.


Viel Spaß !

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Oct 31 2024)

Python Projects, Coaching and Support ...https://www.egenix.com/
Python Product Development ...https://consulting.egenix.com/



::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48

D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   https://www.egenix.com/company/contact/
 https://www.malemburg.com/
--
https://mail.python.org/mailman/listinfo/python-list


Printing UTF-8 mail to terminal

2024-10-31 Thread Loris Bennett via Python-list
Hi,

I have a command-line program which creates an email containing German
umlauts.  On receiving the mail, my mail client displays the subject and
body correctly:

  Subject: Übung

  Sehr geehrter Herr Dr. Bennett,

  Dies ist eine Übung.

So far, so good.  However, when I use the --verbose option to print
the mail to the terminal via

  if args.verbose:
  print(mail)

I get:

  Subject: Übungsbetreff

  Sehr geehrter Herr Dr. Bennett,

  Dies ist eine =C3=9Cbung.

What do I need to do to prevent the body from getting mangled?

I seem to remember that I had issues in the past with a Perl version of
a similar program.  As far as I recall there was an issue with fact the
greeting is generated by querying a server, whereas the body is being
read from a file, which lead to oddities when the two bits were
concatenated.  But that might just have been a Perl thing. 

Cheers,

Loris

-- 
This signature is currently under constuction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read

2024-10-31 Thread Karsten Hilbert via Python-list
Am Thu, Oct 31, 2024 at 07:47:17AM +0100 schrieb Loris Bennett via Python-list:

> However I didn't make myself clear: I understand that there are
> different functions, depending on whether I have a file name or a
> stream.  Nevertheless, I just can't think of a practical example where I
> might just have *only* a stream, especially one containing my
> configuration data.  I was just interested to know if anyone can give an
> example.

Apart from the fact that any data source can be made into a
file: one might have a stream of data coming in over, say,
http, as in a centralized configuration repository.

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Poetry: endpoints with endpoints

2024-10-31 Thread Loris Bennett via Python-list
Hi,

I am using Poetry and have the following in my pyproj.toml

  [tool.poetry.scripts]
  frobnicate = "frobnicator.cli:frobnicate"

The CLI provides an option '--flavour' and I would like to add further
endpoints for specific values of 'flavour'.  I tried adding 

  frobnicate_foo = "frobnicator.cli:frobnicate --flavour foo"

to '[tool.poetry.scripts]', but when I call this I get the error

  $ poetry run frobnicate_foo --verbose
  File "", line 1
import sys; from importlib import import_module; sys.argv = ['frobnicate, 
'--verbose']; import_module('frobniator.cli').frobnicate --flavour foo()

^
SyntaxError: invalid syntax

Is it possible to add such endpoint?  If so, how?

Cheers,

Loris

-- 
This signature is currently under constuction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read

2024-10-31 Thread Loris Bennett via Python-list
Jon Ribbens  writes:

> On 2024-10-30, Loris Bennett  wrote:
>> Jon Ribbens  writes:
>>> On 2024-10-30, Loris Bennett  wrote:
 Jon Ribbens  writes:
> As per the docs you link to, the read() method only takes filename(s)
> as arguments, if you have an already-open file you want to read then
> you should use the read_file() method instead.

 As you and others have pointed out, this is indeed covered in the docs,
 so mea culpa.

 However, whereas I can see why you might want to read the config from a
 dict or a string, what would be a use case in which I would want to
 read from an open file rather than just reading from a file(name)?
>>>
>>> The ConfigParser module provides read(), read_file(), read_string(),
>>> and read_dict() methods. I think they were just trying to be
>>> comprehensive. It's a bit non-Pythonic really.
>>
>> OK, but is there a common situation might I be obliged to use
>> 'read_file'?  I.e. is there some common case where the file name is not
>> available, only a corresponding file-like object or stream?
>
> Well, sure - any time it's not being read from a file. A bit ironic
> that the method to use in that situation is "read_file", of course.
> In my view the read() and read_file() methods have their names the
> wrong way round. But bear in mind this code is 27 years old, and
> the read() function came first.

Yes, I suppose history has a lot to answer for :-)

However I didn't make myself clear: I understand that there are
different functions, depending on whether I have a file name or a
stream.  Nevertheless, I just can't think of a practical example where I
might just have *only* a stream, especially one containing my
configuration data.  I was just interested to know if anyone can give an
example.

-- 
This signature is currently under constuction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read

2024-10-31 Thread MRAB via Python-list

On 2024-10-31 06:47, Loris Bennett via Python-list wrote:

Jon Ribbens  writes:


On 2024-10-30, Loris Bennett  wrote:

Jon Ribbens  writes:

On 2024-10-30, Loris Bennett  wrote:

Jon Ribbens  writes:

As per the docs you link to, the read() method only takes filename(s)
as arguments, if you have an already-open file you want to read then
you should use the read_file() method instead.


As you and others have pointed out, this is indeed covered in the docs,
so mea culpa.

However, whereas I can see why you might want to read the config from a
dict or a string, what would be a use case in which I would want to
read from an open file rather than just reading from a file(name)?


The ConfigParser module provides read(), read_file(), read_string(),
and read_dict() methods. I think they were just trying to be
comprehensive. It's a bit non-Pythonic really.


OK, but is there a common situation might I be obliged to use
'read_file'?  I.e. is there some common case where the file name is not
available, only a corresponding file-like object or stream?


Well, sure - any time it's not being read from a file. A bit ironic
that the method to use in that situation is "read_file", of course.
In my view the read() and read_file() methods have their names the
wrong way round. But bear in mind this code is 27 years old, and
the read() function came first.


Yes, I suppose history has a lot to answer for :-)

However I didn't make myself clear: I understand that there are
different functions, depending on whether I have a file name or a
stream.  Nevertheless, I just can't think of a practical example where I
might just have *only* a stream, especially one containing my
configuration data.  I was just interested to know if anyone can give an
example.


What if the config file was inside a zipped folder?

Although I haven't used ConfigParser like that, I have read the contents 
of files that are in a zipped folder. It means that I don't have to 
extract the file first.

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


Re: Printing UTF-8 mail to terminal

2024-10-31 Thread Cameron Simpson via Python-list

On 31Oct2024 16:33, Loris Bennett  wrote:

I have a command-line program which creates an email containing German
umlauts.  On receiving the mail, my mail client displays the subject and
body correctly:

[...]

So far, so good.  However, when I use the --verbose option to print
the mail to the terminal via

 if args.verbose:
 print(mail)

I get:

 Subject: Übungsbetreff

 Sehr geehrter Herr Dr. Bennett,

 Dies ist eine =C3=9Cbung.

What do I need to do to prevent the body from getting mangled?


That looks to me like quoted-printable. This is an encoding for binary 
transport of text to make it robust against not 8-buit clean transports.  
So your Unicode text is encodings as UTF-8, and then that is encoded in 
quoted-printable for transport through the email system.


Your terminal probably accepts UTF-8 - I imagine other German text 
renders corectly?


You need to get the text and undo the quoted-printable encoding.

If you're using the Python email module to parse (or construct) the 
message as a `Message` object I'd expect that to happen automatically.


If you're just dealing with this directly, use the `quopri` stdlib 
module: https://docs.python.org/3/library/quopri.html


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


Re: Printing UTF-8 mail to terminal

2024-10-31 Thread Alan Gauld via Python-list
On 31/10/2024 20:50, Cameron Simpson via Python-list wrote:

> That looks to me like quoted-printable. This is an encoding for binary 
> transport of text to make it robust against not 8-buit clean 
...

> If you're just dealing with this directly, use the `quopri` stdlib 
> module: https://docs.python.org/3/library/quopri.html

One of the things I love about this list are these little features
that I didn't know existed. Despite having used Python for over 25
years, I've never noticed that module before! :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



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


Correct module for site customization of path

2024-10-31 Thread Tim Johnson via Python-list
FYI: I am retired programmer using a recent upgrade to ubuntu 24.04 and 
python 3.12
My needs are that of a hobbyist at this time. I am on a single user home 
desktop with root privileges available.


After the recent upgrades I had to install youtube_dl with pipx for the 
new python version.
When I ran the script which imported youtube_dl, I got an import error 
as it appears the path to the module
was not in sys.path. For me,  it was a simple matter of appending the 
path for youtube_dl to sys.path, however,

I would prefer to not have to do an append at every script using it.

There is a boatload of documentation of site path configuration, but 
still, I am not sure what option to take.

Recommendations are invited and welcome.

Thanks

--
Tim
thjmm...@gmail.com
--
https://mail.python.org/mailman/listinfo/python-list