Re: Best use of "open" context manager

2024-07-06 Thread Richard Damon via Python-list

My thoughts is that if the "many lines of code" puts the except to far
from the try, then perhaps it would have made sense to factor out some
part there into a function.

Perhaps like:

try:
   with open(FileName) as f:
  for ln in f{
 process(ln)
except FileNotFoundError:
   print(f"File {FileName} not found:")
   sys.exit()

Now the "process" function has been factored out and can be well
documented as to what it is doing on each line, and this code can be
documented as running process on each line of the file.

On 7/6/24 6:49 AM, Rob Cliffe via Python-list wrote:

Consider this scenario (which I ran into in real life):
    I want to open a text file and do a lot of processing on the lines
of that file.
    If the file does not exist I want to take appropriate action, e.g.
print an error message and abort the program.
I might write it like this:

try:
    with open(FileName) as f:
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()

but this violates the principle that a "try" suite should be kept
small, so that only targeted exceptions are trapped,
not to mention that having "try" and "except" far apart decreases
readability.

Or I might write it like this:

try:
    f = open(FileName) as f:
    FileLines = f.readlines()
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
        print("I do a lot of processing here")
        # Many lines of code here .

but this loses the benefits of using "open" as a context manager,
and would also be unacceptable if the file was too large to read into
memory.

Really I would like to write something like

try:
    with open(FileName) as f:
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
else: # or "finally:"
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .

but this of course does not work because by the time we get to "for ln
in f:" the file has been closed so we get
ValueError: I/O operation on closed file

I could modify the last attempt to open the file twice, which would
work, but seems like a kludge (subject to race condition, inefficient).

Is there a better / more Pythonic solution?

Best wishes
Rob Cliffe



--
Richard Damon

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


Re: Best use of "open" context manager

2024-07-06 Thread Thomas Passin via Python-list

On 7/6/2024 6:49 AM, Rob Cliffe via Python-list wrote:

Consider this scenario (which I ran into in real life):
     I want to open a text file and do a lot of processing on the lines 
of that file.
     If the file does not exist I want to take appropriate action, e.g. 
print an error message and abort the program.

I might write it like this:

try:
     with open(FileName) as f:
         for ln in f:
             print("I do a lot of processing here")
             # Many lines of code here .
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()

but this violates the principle that a "try" suite should be kept small, 
so that only targeted exceptions are trapped,
not to mention that having "try" and "except" far apart decreases 
readability.


Or I might write it like this:

try:
     f = open(FileName) as f:
     FileLines = f.readlines()
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
         print("I do a lot of processing here")
         # Many lines of code here .

but this loses the benefits of using "open" as a context manager,
and would also be unacceptable if the file was too large to read into 
memory.


Really I would like to write something like

try:
     with open(FileName) as f:
except FileNotFoundError:
     print(f"File {FileName} not found")
     sys.exit()
else: # or "finally:"
         for ln in f:
             print("I do a lot of processing here")
             # Many lines of code here .

but this of course does not work because by the time we get to "for ln 
in f:" the file has been closed so we get

ValueError: I/O operation on closed file

I could modify the last attempt to open the file twice, which would 
work, but seems like a kludge (subject to race condition, inefficient).


Is there a better / more Pythonic solution?


I usually read the file into a sequence of lines and then leave the 
open() as soon as possible.  Something like this:


FILENAME = 'this_is_an_example.txt'
lines = None
if os.path.exists(FILENAME):
with open(FILENAME) as f:
lines = f.readlines()
# do something with lines

Of course, if you want to read a huge number of lines you will need to 
be more thoughtful about it.  Or make all the processing within the 
open() block be a function.  Then you just have one more line in the block.


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


Re: Best use of "open" context manager

2024-07-06 Thread Oscar Benjamin via Python-list
On Sat, 6 Jul 2024 at 11:55, Rob Cliffe via Python-list
 wrote:
>
> Consider this scenario (which I ran into in real life):
>  I want to open a text file and do a lot of processing on the lines
> of that file.
>  If the file does not exist I want to take appropriate action, e.g.
> print an error message and abort the program.
> I might write it like this:
>
> try:
>  with open(FileName) as f:
>  for ln in f:
>  print("I do a lot of processing here")
>  # Many lines of code here .
> except FileNotFoundError:
>  print(f"File {FileName} not found")
>  sys.exit()
>
> but this violates the principle that a "try" suite should be kept small,
> so that only targeted exceptions are trapped,
> not to mention that having "try" and "except" far apart decreases
> readability.

This is catching a targeted exception (FileNotFoundError) so I think
it is fine. If the intention is just to call sys.exit() on error then
I wouldn't worry too much about having too much code in the try. Just
make sure that you do this in any other place where you open a file as
well.

One possible improvement is that you could catch the exception and use
its filename attribute:

except FileNotFoundError as e
 print(f"File {e.filename} not found")

That way if you did catch the wrong FileNotFoundError then at least
you print the correct filename.

Alternatively:

except FileNotFoundError as e
 if e.filename != FileName:
  raise  # re-raise if not the intended exception
 print(f"File {e.filename} not found")

For readability I would just move the many lines of code into a
separate function.

The reason to avoid having too much code in the try mainly applies to
situations where you are going to do something other than call
sys.exit() and the exception is overly generic like ValueError or
TypeError. If the exception can easily be raised by a bug or something
other than the intended cause then it is bad to catch exceptions
around a larger block of code.

If it is expected that the caller of a function might have good reason
to catch the exception and handle it somehow then it is better to make
a dedicated exception class and raise that instead. When there is only
one place in the code that raises a particular exception type and only
one place that catches it then it is usually going to be clear that
you are catching the expected exception.

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


Re: Best use of "open" context manager

2024-07-06 Thread Alan Gauld via Python-list
On 06/07/2024 11:49, Rob Cliffe via Python-list wrote:

>      If the file does not exist I want to take appropriate action, e.g. 
> print an error message and abort the program.
> I might write it like this:
> 
> try:
>      with open(FileName) as f:
>          for ln in f:
>              print("I do a lot of processing here")
>              # Many lines of code here .
> except FileNotFoundError:
>      print(f"File {FileName} not found")
>      sys.exit()
> 
> but this violates the principle that a "try" suite should be kept small, 

The try is small, it only has a single statement inside.
The compound block inside that statement should have its
own try/ecxepts but the outer one really only applies to
the with statement.

I certainly prefer this option to any of the others presented.

> not to mention that having "try" and "except" far apart decreases 
> readability.

This is a valid concern although that's part of the reason
we use indentation. Compared to early BASIC and FORTRAN with massive
GOSUB type leaps (and often no indentation) it's very readable!

But its still preferable to having the multi-level indents below
or having to remember to close the file when finished (and
ensure that all possible paths do so.

> try:
>      f = open(FileName) as f:
>      FileLines = f.readlines()
> except FileNotFoundError:
>      print(f"File {FileName} not found")
>      sys.exit()
> # I forgot to put "f.close()" here -:)

Exactly! That's why using with is safer even if the
except is detached from the try.

You are also reading the entire file into memory which could
be an issue. And you are not catching any errors in the
read operations because the except only covers a missing
file.

> Really I would like to write something like
> 
> try:
>      with open(FileName) as f:
> except FileNotFoundError:
>      print(f"File {FileName} not found")
>      sys.exit()
> else: # or "finally:"
>          for ln in f:
>              print("I do a lot of processing here")
>              # Many lines of code here .

I find that much less readable because the file handling
block is a long way from the open file line and has extra
control statements to mentally negotiate.

The advantage of the original version is that you can
ignore errors and read the code easily. You only need
to find the except clause if you need to know how errors
will be dealt with. But if comprehending the core
functionality of the code you can just ignore all
the error handling blocks.

> Is there a better / more Pythonic solution?

All IMHO of course, but I think the current implementation
is the best of the options presented.

-- 
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


Re: Best use of "open" context manager

2024-07-06 Thread Dan Sommers via Python-list
On 2024-07-06 at 11:49:06 +0100,
Rob Cliffe via Python-list  wrote:

> Is there a better / more Pythonic solution?

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

At least this attempts to abstract the problem of iterating over a file
(or multiple files) into a library routine.  I've used it a little, but
I don't know the full depths of your use case and/or requirements.

HTH,
Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Best use of "open" context manager

2024-07-06 Thread Rob Cliffe via Python-list

Consider this scenario (which I ran into in real life):
    I want to open a text file and do a lot of processing on the lines 
of that file.
    If the file does not exist I want to take appropriate action, e.g. 
print an error message and abort the program.

I might write it like this:

try:
    with open(FileName) as f:
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()

but this violates the principle that a "try" suite should be kept small, 
so that only targeted exceptions are trapped,
not to mention that having "try" and "except" far apart decreases 
readability.


Or I might write it like this:

try:
    f = open(FileName) as f:
    FileLines = f.readlines()
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
        print("I do a lot of processing here")
        # Many lines of code here .

but this loses the benefits of using "open" as a context manager,
and would also be unacceptable if the file was too large to read into 
memory.


Really I would like to write something like

try:
    with open(FileName) as f:
except FileNotFoundError:
    print(f"File {FileName} not found")
    sys.exit()
else: # or "finally:"
        for ln in f:
            print("I do a lot of processing here")
            # Many lines of code here .

but this of course does not work because by the time we get to "for ln 
in f:" the file has been closed so we get

ValueError: I/O operation on closed file

I could modify the last attempt to open the file twice, which would 
work, but seems like a kludge (subject to race condition, inefficient).


Is there a better / more Pythonic solution?

Best wishes
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


Re: python for irc client

2024-07-04 Thread Daniel via Python-list
inhahe  writes:

> On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
> python-list@python.org> wrote:
>
>> Hi guys -
>>
>> I have historical experience developing sofwtare for my own use. It has
>> been
>> quite a while since doing so and the advent of new languages has brought me
>> here. Python has built quite a reputation. It would be fun to pick up a
>> new language while I'm at it.
>>
>> I've been a consumer of IRC since the nineties and have been running an
>> instance of quassel core on an old laptop for the last decade. Over the
>> years, my use of xwindows has dramatically decreased and I spend 90% of my
>> computer time with multiple panes of tmux while I do my usual daily fun.
>> One
>> thing missing is a good textmode irc client that will connect to quassel
>> core.
>>
>> I've seen efforts to make a plugin for weechat but, to date, I don't see
>> much
>> progress on that end.
>>
>> In your wisdom, would python be a good environment to accomplish this? I'd
>> likely use extended ascii and colors. The point would be to minimize the
>> memory footprint of the application.
>>
>> I don't use standard desktop computers anymore - I'm writing this on my
>> beloved pi400 using emacs.
>>
>> Thanks
>>
>> Daniel
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> I think Python would be a great language to write an IRC client in, it's a
> rapid-development language, and also Python is particularly good for text
> manipulation and the IRC protocol is textual rather than binary. But, if
> your only purpose for using Python is to reduce the memory footprint, I'm
> not sure. I don't know specifically, but I'd guess Python has a higher
> memory footprint than, say, C, because it's a high-level language. For
> example, each variable has to be boxed, and also the interpreter has to be
> loaded..
>
> Regarding high ASCII, I don't know if that works in IRC, but either way,
> ASCII isn't really enough nowadays. You need to support Unicode;
> specifically, UTF-8.

Okay great. Since my original post, I settled on UTF8. I have to create
a list of requirements for v1.0 to limit scope creep and I can actually
get this done.

I may put it on github and solicit for assistance at some point.

Thanks for the response, both of them. I'll look at the other code and
see how I can fold it in. What I have to find out, still, is how the
core server manages the messages. I suspect the core does all the
sending and receiving and the client just sends the packets to core for
management. That's just a guess though.

I still have to review the liraries, this is a new idea hatched last
night so I have yet to investigate much.

My initial thought was C++ but this would be my first termianl-only
application in many years so I thought a different coding platform would
be effective.

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


Re: python for irc client

2024-07-04 Thread Left Right via Python-list
Hi.

Just FYI, I use Erc (in Emacs). I'm not a very advanced user, perhaps,
but I never felt like I miss anything. That's not to stop you from
making your own, but if you just need a decent text client for IRC,
then there's already at least one.

On Thu, Jul 4, 2024 at 11:30 AM inhahe via Python-list
 wrote:
>
> On Thu, Jul 4, 2024 at 5:22 AM inhahe  wrote:
>
> >
> >
> > On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
> > python-list@python.org> wrote:
> >
> >>
> >> In your wisdom, would python be a good environment to accomplish this?
> >
> >
>
> > I think Python would be a great language to write an IRC client in, it's a
> > rapid-development language, and also Python is particularly good for text
> > manipulation and the IRC protocol is textual rather than binary.
> >
>
> Oh yeah, I forgot I was going to mention that Twisted has already done a
> lot of the dirty work for you if you make it in Python...they have twisted.
> words.protocols.irc, which implements the IRC protocol. (I don't know if
> it's up to date and supports ircv3, though.)
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for irc client

2024-07-04 Thread inhahe via Python-list
On Thu, Jul 4, 2024 at 5:22 AM inhahe  wrote:

>
>
> On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
> python-list@python.org> wrote:
>
>>
>> In your wisdom, would python be a good environment to accomplish this?
>
>

> I think Python would be a great language to write an IRC client in, it's a
> rapid-development language, and also Python is particularly good for text
> manipulation and the IRC protocol is textual rather than binary.
>

Oh yeah, I forgot I was going to mention that Twisted has already done a
lot of the dirty work for you if you make it in Python...they have twisted.
words.protocols.irc, which implements the IRC protocol. (I don't know if
it's up to date and supports ircv3, though.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for irc client

2024-07-04 Thread inhahe via Python-list
On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
python-list@python.org> wrote:

> Hi guys -
>
> I have historical experience developing sofwtare for my own use. It has
> been
> quite a while since doing so and the advent of new languages has brought me
> here. Python has built quite a reputation. It would be fun to pick up a
> new language while I'm at it.
>
> I've been a consumer of IRC since the nineties and have been running an
> instance of quassel core on an old laptop for the last decade. Over the
> years, my use of xwindows has dramatically decreased and I spend 90% of my
> computer time with multiple panes of tmux while I do my usual daily fun.
> One
> thing missing is a good textmode irc client that will connect to quassel
> core.
>
> I've seen efforts to make a plugin for weechat but, to date, I don't see
> much
> progress on that end.
>
> In your wisdom, would python be a good environment to accomplish this? I'd
> likely use extended ascii and colors. The point would be to minimize the
> memory footprint of the application.
>
> I don't use standard desktop computers anymore - I'm writing this on my
> beloved pi400 using emacs.
>
> Thanks
>
> Daniel
> --
> https://mail.python.org/mailman/listinfo/python-list


I think Python would be a great language to write an IRC client in, it's a
rapid-development language, and also Python is particularly good for text
manipulation and the IRC protocol is textual rather than binary. But, if
your only purpose for using Python is to reduce the memory footprint, I'm
not sure. I don't know specifically, but I'd guess Python has a higher
memory footprint than, say, C, because it's a high-level language. For
example, each variable has to be boxed, and also the interpreter has to be
loaded..

Regarding high ASCII, I don't know if that works in IRC, but either way,
ASCII isn't really enough nowadays. You need to support Unicode;
specifically, UTF-8.
-- 
https://mail.python.org/mailman/listinfo/python-list


python for irc client

2024-07-04 Thread Daniel via Python-list
Hi guys -

I have historical experience developing sofwtare for my own use. It has been
quite a while since doing so and the advent of new languages has brought me
here. Python has built quite a reputation. It would be fun to pick up a
new language while I'm at it.

I've been a consumer of IRC since the nineties and have been running an
instance of quassel core on an old laptop for the last decade. Over the
years, my use of xwindows has dramatically decreased and I spend 90% of my
computer time with multiple panes of tmux while I do my usual daily fun. One
thing missing is a good textmode irc client that will connect to quassel
core.

I've seen efforts to make a plugin for weechat but, to date, I don't see much
progress on that end.

In your wisdom, would python be a good environment to accomplish this? I'd
likely use extended ascii and colors. The point would be to minimize the
memory footprint of the application.

I don't use standard desktop computers anymore - I'm writing this on my
beloved pi400 using emacs.

Thanks

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


ANN: eGenix PyRun - One file Python Runtime 2.5.0

2024-07-01 Thread eGenix Team via Python-list

*ANNOUNCING*


   eGenix PyRun - One file Python Runtime

Version 2.5.0

Python runtime taking up just 4-6MB on disk

This announcement is also available on our web-site for online reading:
https://www.egenix.com/company/news/eGenix-PyRun-2.5.0-GA.html


*INTRODUCTION*

*eGenix PyRun*™  
is our open source, one file, no installation version of Python, making 
the distribution of a Python interpreter to run Python based scripts and 
applications to Unix based systems simple and efficient.


eGenix PyRun's executable only needs 4-6MB on disk, but still supports 
most Python applications and scripts.


Compared to a regular Python installation of typically 100MB on disk, 
eGenix PyRun is ideal for applications and scripts that need to be 
distributed to containers, VMs, clusters, client installations, 
customers or end-users.


It makes "installing" Python on a Unix based system as simple as copying 
a single file.


eGenix has been using eGenix PyRun as run-time for the Linux version of 
mxODBC Connect Server 
 product since 
2008 with great success and decided to make it available as a 
stand-alone open-source product.


We provide the source archive to build your own *eGenix PyRun on Github* 
, as well as a few binary 
distributions to get you started on Linux x86_64. In the future, we will 
set up automated builds for several other platforms.


Please see the product page for more details:

>>> eGenix PyRun - One file Python Runtime 





*NEWS*

This major release of eGenix PyRun 
 comes with the following 
enhancements:


 * Added support for *Python 3.8 - 3.11*
 * Removed support for Python 3.5-3.7
 * Modernized the directory setup and build
 * Changed the license to the *Apache2 license*
 * Extracted the code from our internal mono-repo to put on Github
 * *Relaunched the project on Github*

For a complete list of changes, please see the *eGenix PyRun Changelog 
*.



Enjoy,

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Jul 01 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


Re: Difference method vs attribut = function

2024-06-30 Thread Dieter Maurer via Python-list
Ulrich Goebel wrote at 2024-6-28 18:08 +0200:
>Hi,
>
>a class can have methods, and it can have attributes, which can hold a 
>function. Both is well known, of course.
>
>My question: Is there any difference?

I think you should make the distinction "class versus instance attribute"
rather than "mether versus function".

If you look at the `__dict__` of an instance, you see only the
instance variables (the class's `__dict__` gives you the (most) attributes
of the class).

You can access (most) class attributes via an instance;
if a function is accessed in this way, it becomes (typically) a method.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference method vs attribut = function

2024-06-29 Thread Thomas Passin via Python-list

On 6/28/2024 12:08 PM, Ulrich Goebel via Python-list wrote:

Hi,

a class can have methods, and it can have attributes, which can hold a 
function. Both is well known, of course.

My question: Is there any difference?

The code snipped shows that both do what they should do. But __dict__ includes 
just the method, while dir detects the method and the attribute holding a 
function. My be that is the only difference?


class MyClass:
 def __init__(self):
 functionAttribute = None
 
 def method(self):

 print("I'm a method")

def function():
 print("I'm a function passed to an attribute")

mc = MyClass()
mc.functionAttribute = function

mc.method()
mc.functionAttribute()

print('Dict: ', mc.__dict__)# shows functionAttribute but not method
print('Dir:  ', dir(mc))# shows both functionAttribute and method


By the way: in my usecase I want to pass different functions to different 
instances of MyClass. It is in the context of a database app where I build 
Getters for database data and pass one Getter per instance.

Thanks for hints
Ulrich



https://docs.python.org/3/library/functions.html#dir -

object.__dict__¶
A dictionary or other mapping object used to store an object’s 
(writable) attributes.


dir(object)
...
With an argument, attempt to return a list of valid attributes for that 
object.


"functionAttribute" is a class method, not an instance method.  If you 
want an instance method:


class MyClass:
def __init__(self):
functionAttribute = None
self.instance_functionAttribute = None

def method(self):
print("I'm a method")

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


Re: Difference method vs attribut = function

2024-06-29 Thread Mats Wichmann via Python-list

On 6/28/24 10:08, Ulrich Goebel via Python-list wrote:


By the way: in my usecase I want to pass different functions to different 
instances of MyClass. It is in the context of a database app where I build 
Getters for database data and pass one Getter per instance.


If I understood what you're trying to accomplish, you could take a look 
here (possibly a bit complex for what you need).


https://refactoring.guru/design-patterns/strategy/python/example



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


Re: Difference method vs attribut = function

2024-06-29 Thread Peter J. Holzer via Python-list
On 2024-06-28 18:08:54 +0200, Ulrich Goebel via Python-list wrote:
> a class can have methods, and it can have attributes, which can hold a
> function. Both is well known, of course.
> 
> My question: Is there any difference?
> 
> The code snipped shows that both do what they should do. But __dict__
> includes just the method,

The other way around: It includes only the attributes, not the methods.

> while dir detects the method and the
> attribute holding a function. My be that is the only difference?
> 
> 
> class MyClass:
> def __init__(self):
> functionAttribute = None
> 
> def method(self):
> print("I'm a method")
> 
> def function():
> print("I'm a function passed to an attribute")

Here is the other main difference: The object is not passed implicitely
to the function. You have no way to access mc here.

You can create a method on the fly with types.MethodType:

import types
mc.functionAttribute = types.MethodType(function, mc)


> By the way: in my usecase I want to pass different functions to
> different instances of MyClass. It is in the context of a database app
> where I build Getters for database data and pass one Getter per
> instance.

Or in this case, since each function is specific to one instance, you
could just use a closure to capture the object. But that might be
confusing to any future maintainers (e.g. yourself in 6 months), if the
method doesn't actually behave like a method.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Difference method vs attribut = function

2024-06-29 Thread Ulrich Goebel via Python-list
Hi,

a class can have methods, and it can have attributes, which can hold a 
function. Both is well known, of course.

My question: Is there any difference?

The code snipped shows that both do what they should do. But __dict__ includes 
just the method, while dir detects the method and the attribute holding a 
function. My be that is the only difference?


class MyClass:
def __init__(self):
functionAttribute = None

def method(self):
print("I'm a method")

def function():
print("I'm a function passed to an attribute")

mc = MyClass()
mc.functionAttribute = function

mc.method()
mc.functionAttribute()

print('Dict: ', mc.__dict__)# shows functionAttribute but not method
print('Dir:  ', dir(mc))# shows both functionAttribute and method


By the way: in my usecase I want to pass different functions to different 
instances of MyClass. It is in the context of a database app where I build 
Getters for database data and pass one Getter per instance.

Thanks for hints
Ulrich


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


[RELEASE] Python 3.13.0 beta 3 released.

2024-06-27 Thread Thomas Wouters via Python-list
The *next to last* Python 3.13 beta version, beta 3, is now released:
https://www.python.org/downloads/release/python-3130b3/

*This is a beta preview of Python 3.13*

Python 3.13 is still in development. This release, 3.13.0b3, is the third
of four beta release previews of 3.13.

Beta release previews are intended to give the wider community the
opportunity to test new features and bug fixes and to prepare their
projects to support the new feature release.

We *strongly encourage* maintainers of third-party Python projects to *test
with 3.13* during the beta phase and report issues found to the Python bug
tracker  as soon as possible.
While the release is planned to be feature complete entering the beta
phase, it is possible that features may be modified or, in rare cases,
deleted up until the start of the release candidate phase (Tuesday
2024-07-30). Our goal is to have no ABI changes after beta 4 and as few
code changes as possible after 3.13.0rc1, the first release candidate. To
achieve that, it will be *extremely important* to get as much exposure for
3.13 as possible during the beta phase.

Please keep in mind that this is a preview release and its use is *not*
recommended for production environments.
Major
new features of the 3.13 series, compared to 3.12

Some of the new major new features and changes in Python 3.13 are:
New
features

   - A new and improved interactive interpreter
   
,
   based on PyPy ’s, featuring multi-line editing and
   color support, as well as colorized exception tracebacks
   
   .
   - An *experimental* free-threaded build mode
   ,
   which disables the Global Interpreter Lock, allowing threads to run more
   concurrently. The build mode is available as an experimental feature in the
   Windows and macOS installers as well.
   - A preliminary, *experimental* JIT
   ,
   providing the ground work for significant performance improvements.
   - The (cyclic) garbage collector is now incremental
   
,
   which should mean shorter pauses for collection in programs with a lot of
   objects.
   - A modified version of mimalloc 
   is now included, optional but enabled by default if supported by the
   platform, and required for the free-threaded build mode.
   - Docstrings now have their leading indentation stripped
   ,
   reducing memory use and the size of .pyc files. (Most tools handling
   docstrings already strip leading indentation.)
   - The dbm module  has a
   new dbm.sqlite3 backend
    that is used by
   default when creating new files.
   - The minimum supported macOS version was changed from 10.9 to *10.13
   (High Sierra)*. Older macOS versions will not be supported going forward.


Typing

   - Support for type defaults in type parameters
   .
   - A new type narrowing annotation ,
   typing.TypeIs.
   - A new annotation for read-only items in TypeDicts
   .

Removals
and new deprecations

   - PEP 594 (Removing dead batteries from the standard library)
    scheduled removals of many
   deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr,
   mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau,
   telnetlib, uu, xdrlib, lib2to3.
   - Many other removals
    of deprecated
   classes, functions and methods in various standard library modules.
   - C API removals 
   and deprecations .
   (Some removals present in alpha 1 were reverted in alpha 2, as the removals
   were deemed too disruptive at this time.)
   - New deprecations
   , most of
   which are scheduled for removal from Python 3.15 or 3.16.

(Hey, *fellow core developer,* if a feature 

Re: [Tutor] How to install tensorflow on Python 2.7 in Windows?

2024-06-26 Thread Mats Wichmann via Python-list

On 6/26/24 09:29, marc nicole wrote:

Browsing the available version of tensorflow for the dates before January
2021 (date when Python 2.7 stopped being supported) I can't find a
tensorflow version for Python 2.7 that works under Windows.

The reference site I use is https://pypi.org/project/tensorflow/

Anybody can point out a compatible .whl file with Python 2.7 and Windows?


The last version of tensorflow to support Python 2.7 was indeed 2.1, and 
I don't think there was *ever* an official Windows wheel for Python 2, 
but I'm not that expert to be completely sure. tensorflow support on 
Windows has never been good, and in a way they've given up, at least 
part of the fight: they no longer produce official releases for Windows 
with GPU support (although you may be able to get one from the vendor 
that produces the GPU hardware like Nvidia or Intel, or from a third 
party like Amazon Web Services). The official recommendation for WIndows 
used to be "build your own" (which nearly always failed), then for a few 
years they tried making Windows builds, now the new "best practice" 
recommendation is to install on WSL if you want to run on a Windows box 
(this *might* work for you, unless you're also on an ancient Windows 
that won't run WSL).  Or, try seeing if you can find a docker setup 
(which, again, will give you a Linux environment running tensorflow).


Note that like your other problem, getting numpy going, this is going to 
be an uphill battle trying to cobble things together to run on 2.7. 
This is really the problem when something like Python goes out of date / 
out of support: it's not that it magically stops working, it's that vast 
amounts of the ecosystem around it stop providing support for *their* 
bits on the old version, and the combinations become progressively 
harder to make work.



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


How to install tensorflow on Python 2.7 in Windows?

2024-06-26 Thread marc nicole via Python-list
Browsing the available version of tensorflow for the dates before January
2021 (date when Python 2.7 stopped being supported) I can't find a
tensorflow version for Python 2.7 that works under Windows.

The reference site I use is https://pypi.org/project/tensorflow/

Anybody can point out a compatible .whl file with Python 2.7 and Windows?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

2024-06-25 Thread Chris Angelico via Python-list
On Wed, 26 Jun 2024 at 03:40, Anton Shepelev via Python-list
 wrote:
>
> Chris Angelico to dn:
>
> > > Python mailing-lists are covered by the Code of Conduct
> > > and monitored by ListAdmins. Thus, there are controls
> > > which limit the impact which advertisers and others with
> > > non-pythonic aims might otherwise exert!
> >
> > So long as there's a newsgroup gateway, those controls are
> > toothless.
>
> The gateway operator can have the usual anti-spam software
> installed

Anti-spam is not the same as CoC and admins, though. Without putting
an actual moderation barrier in there, it's still toothless.

(Yes, there are a scant few posters who've been blocked from the
gateway, but it's rare.)

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


Re: Anonymous email users

2024-06-25 Thread Anton Shepelev via Python-list
Chris Angelico to dn:

> > Python mailing-lists are covered by the Code of Conduct
> > and monitored by ListAdmins. Thus, there are controls
> > which limit the impact which advertisers and others with
> > non-pythonic aims might otherwise exert!
>
> So long as there's a newsgroup gateway, those controls are
> toothless.

The gateway operator can have the usual anti-spam software
installed, and of course there is Gmane:

  

which actually subscribes users to mailing lists (on their
behalf).  Gmane's NNTP server is: news.gmane.io .

-- 
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

2024-06-25 Thread Anton Shepelev via Python-list
Sebastian Wells:

> The spammers won the spam wars, so even if you have
> someone's real e-mail address, that's no guarantee that
> you can contact them.

No so with me.  My e-mail address here is munged, but in a
very obvious way, and no, my mailbox is not overwhelmed with
spam.

I make a habit of reporting spam via:

  1.  https://www.spamcop.net/anonsignup.shtml
  2.  https://submit.spamhaus.org/submit/

They maintain blacklists of e-mail providers or notify them
of spam e-mails.  It helps.

-- 
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Anonymous email users

2024-06-24 Thread AVI GROSS via Python-list
This discussion has wandered far from my original mention that I found it
hard to reply to people using an invalid email address. I see no real
connection to python except insofar as at least one spam-filter mentioned is
written in python!

Just to add an observation, the people writing here have obviously had many
different experiences with their email addresses and whether yours is
hijacked in some way, and made less useful, can even just become down to
random luck. 

But SPAM filters can also be manipulated and cause you to lose mail. I think
some people have been reporting email from a source they do not favor, such
as for political reasons, that then ends up being junked for people who
would welcome the messages. And, I can well imagine how something like a
post about python programs can start being filtered out because some key
words commonly use end up being used a lot in some kind of SPAM and the
filter "learns" to filter those out. Imagine of "python" appeared in lots of
actual SPAM messages as the war moved on, such as in the metadata designed
to make it look legit.

Email addresses can go bad for many reasons. My wife had a nice simple
address like jane.sm...@gmail.com that was messed up probably by
well-meaning people when another Jane Smith had an email address like
smith.jane or janesmith123 and they or others typed in the more
straightforward ones. It seems we ended up getting odd email from many
continents such as e-tickets for airplanes, initial estimates or bills from
vendors for products in places we have never been for services rendered in
say Tennessee or South Africa (well, I've been in Tennessee, but) and
subscriptions to internet magazines or groups that sent lots of messages, or
conversations between lots of people (all To: or Cc:) that included her
email address wrongly and even when she replied to ask to be taken off, the
conversations continued for months as many kept hitting reply-all, ...)

And, obviously, with so many people using the address wrongly, SPAM
followed.

Of course, choosing a strange name designed not to be typed by accident, has
it's own disadvantages.

But for those who want me to CALL their unspecified phone number and tell
them the subject line and then maybe you will look for my message,
FUGGEDABOUTIT! I have a cousin who does a trick  with her phone service
where she never answers and I have to run some gauntlet to identify myself
and then wait for a call back. After a few times, I solved the problem and
simply never call her.

Admittedly, making it hard for an email address to be abused in a forum like
this is understandable. Making it very hard to reach you legitimately when
the message is that your house is burning or just that your appointment is
canceled, may not work as well as you think.

And, FYI, I check my junkmail regularly and I have a fairly high rate of
finding things, including posts on forums like this one, that are NOT in my
opinion junk as I ordered them and they are on topic and not easily visible
as having committed some kind of sin. And as I use many email services, I
still find a high rate of false negatives everywhere.

It would not surprise me if a phrase like "not SPAM" gets this message
dumped into /dev/null


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Monday, June 24, 2024 9:49 PM
To: python-list@python.org
Subject: Re: Anonymous email users

On Tue, 25 Jun 2024 at 11:41, Grant Edwards via Python-list
 wrote:
> I've been using the same e-mail address for about 20 years. I've use
> that e-mail address with probably close to 100 retailers, charities,
> open-source projects, media sites, and various other organizations.

Mostly the same, although in my case, I've had multiple email
addresses for different purposes (and still kept all of them for
decades).

> I get at most a few spam emails per week [I just checked my spam
> folder: 8 in the past 30 days]. And Gmail is very, very close to 100%
> accurate at filtering them out.  I can't remember the last time I
> actually got a spam message in my inbox.
>
> > A few years ago the spam count was greater than a 1,000 a month.
>
> I'm baffled.  Is Gmail silently rejecting that much junk before it
> even gets to the filter that puts stuff into my "spam" folder?
>

It really depends on how you count. On my mail server (can't get stats
for Gmail), I have a number of anti-spam and anti-abuse rules that
apply prior to the Bayesian filtering (for example, protocol
violations), and any spam that gets blocked by those rules isn't shown
in my stats. And then I have a further set of rules that nuke some of
the most blatant spam, and finally the regular trainable filter. I
should probably keep better stats on the stuff I don't keep, but at
the moment, all I actually track is the ones that the filter sees -
which is roughly 25-50 a day.

So yeah, Gmail is probably rejecting that much junk, but most of
it for protocol violations.

ChrisA
-- 

Re: Anonymous email users

2024-06-24 Thread Chris Angelico via Python-list
On Tue, 25 Jun 2024 at 11:41, Grant Edwards via Python-list
 wrote:
> I've been using the same e-mail address for about 20 years. I've use
> that e-mail address with probably close to 100 retailers, charities,
> open-source projects, media sites, and various other organizations.

Mostly the same, although in my case, I've had multiple email
addresses for different purposes (and still kept all of them for
decades).

> I get at most a few spam emails per week [I just checked my spam
> folder: 8 in the past 30 days]. And Gmail is very, very close to 100%
> accurate at filtering them out.  I can't remember the last time I
> actually got a spam message in my inbox.
>
> > A few years ago the spam count was greater than a 1,000 a month.
>
> I'm baffled.  Is Gmail silently rejecting that much junk before it
> even gets to the filter that puts stuff into my "spam" folder?
>

It really depends on how you count. On my mail server (can't get stats
for Gmail), I have a number of anti-spam and anti-abuse rules that
apply prior to the Bayesian filtering (for example, protocol
violations), and any spam that gets blocked by those rules isn't shown
in my stats. And then I have a further set of rules that nuke some of
the most blatant spam, and finally the regular trainable filter. I
should probably keep better stats on the stuff I don't keep, but at
the moment, all I actually track is the ones that the filter sees -
which is roughly 25-50 a day.

So yeah, Gmail is probably rejecting that much junk, but most of
it for protocol violations.

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


Re: Anonymous email users

2024-06-24 Thread Grant Edwards via Python-list
On 2024-06-24, Barry Scott via Python-list  wrote:
>> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
>>  wrote:
>> 
>> The spammers won the spam wars, so even if you have someone's real
>> e-mail address, that's no guarantee that you can contact them. [...]
>
> My email address is well known and yes I get spam emails.

I've been puzzled by this for a long time. Many people talk about how
they get so much spam e-mail that there's little chance they'll notice
if I send them an e-mail.

I've been using the same e-mail address for about 20 years. I've use
that e-mail address with probably close to 100 retailers, charities,
open-source projects, media sites, and various other organizations.

I get at most a few spam emails per week [I just checked my spam
folder: 8 in the past 30 days]. And Gmail is very, very close to 100%
accurate at filtering them out.  I can't remember the last time I
actually got a spam message in my inbox.

> A few years ago the spam count was greater than a 1,000 a month.

I'm baffled.  Is Gmail silently rejecting that much junk before it
even gets to the filter that puts stuff into my "spam" folder?

--
Grant


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


Re: Anonymous email users

2024-06-24 Thread Chris Angelico via Python-list
On Tue, 25 Jun 2024 at 08:31, dn via Python-list  wrote:
> Python mailing-lists are covered by the Code of Conduct and monitored by
> ListAdmins. Thus, there are controls which limit the impact which
> advertisers and others with non-pythonic aims might otherwise exert!
>

So long as there's a newsgroup gateway, those controls are toothless.

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


Re: Anonymous email users

2024-06-24 Thread dn via Python-list

On 25/06/24 05:17, Thomas Passin via Python-list wrote:

On 6/24/2024 5:51 AM, Barry Scott via Python-list wrote:



On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
 wrote:


The spammers won the spam wars, so even if you have someone's real
e-mail address, that's no guarantee that you can contact them. You
certainly wouldn't be able to contact me at my real e-mail address,
unless you also had my phone number, so you could call me and tell
me that you sent me an e-mail, and what the subject line was so I
can find it. I don't even open my e-mail inbox unless there's a
specific message I'm expecting to find there right now.


My email address is well known and yes I get spam emails.

I use the wonderful python based spambayes software to detect spam and
file into a Junk folder. It works for 99.9% of the emails I get.


I use the Thunderbird mail client and I just use its built in spam 
detector.  I don't know how it works but it's pretty darn good.  Very 
few false positives or false negatives.  And it learns each time I 
classify a message as "Junk", in case it missed one.


I am subscribed to a lot of mailing lists. I just checked and I am 
getting ~3,200

emails a month of which less than 200 are spam.

A few years ago the spam count was greater than a 1,000 a month.

I have been using spambayes for a very long time, 20 years I guess at 
this

point and bayesian categorisation has stood the test of time for me.

For me the spammers have not won, I have the tech to keep ahead of them.


Aside from the attractions of the new, and the 'shiny', what 
email-antagonists didn't anticipate, was that as fast as they moved to 
non-email messaging, the spammers, advertisers, and malcontents would 
simply do the same. Thus, a variation on whack-a-mole, as folk move from 
platform to platform trying to stay-ahead and find an illusion of 
safety. Quite how one out-runs human-nature is an issue 
philosophised-over by the (Ancient) Greeks (and was no-doubt old even-then).


Paradoxically, applying for an account elsewhere usually involves 
providing an email address. Even backing-up a cell-phone (communication 
tool) to the cloud requires an email address(!!!)


Most of the non-email platforms are provided by organisations who have 
'other uses' for your personal-data (and not forgetting GMail and MSFT's 
email services).


Python mailing-lists are covered by the Code of Conduct and monitored by 
ListAdmins. Thus, there are controls which limit the impact which 
advertisers and others with non-pythonic aims might otherwise exert!


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


RE: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects)

2024-06-24 Thread AVI GROSS via Python-list
Marc,

Several people have supplied feedback on whether your request is a good fit for 
here. Ultimately it is up to the owner/moderator. In particular, your request 
to the Tutor List may not fit the purpose and be a bit complex  and to the main 
Python List also outside some common usage whether it is about a specific 
module or product you are using, or asking about algorithms in a very general 
way.

You question has evolved to being about algorithms, more than about Python as a 
basic language or even commonly used modules.

So, I suggest you simplify your model and then maybe bring it in-line with the 
module(s) you showed us you were using. Some of what you ask sounds like it 
would be extremely commonly done in things like robotics, or even just machines 
with moving parts.

Consider the somewhat related concept often seen of how you get from one place 
to another in parts of Manhattan where most of the streets run either in one 
direction or the orthogonal direction. How do you get from say East 14th Street 
at 1st Avenue to West 28th Street and 11th Avenue? This is a slight imitation 
of how to move a robotic arm that can mainly either go one way or another but 
not both at once. And, in the real world, parts of Manhattan are more complex 
with streets ending or renaming or running more diagonally or huge voids like 
Central Park.

The number of solutions is huge for walking, and smaller for driving as some 
streets are one way. But assuming you avoid wasteful paths (except when roads 
are closed for endless purposes) and you do not take a path through Brooklyn, 
Queens and The Bronx and back to Manhattan as in the NY Marathon that also 
touches another borough, the solutions mainly look like this:

Go as far horizontally as you need and then as far vertically.
Or, do vertical, then horizontal.
Or lots of combined versions such as climbing stairs by doing a block or three 
one way then some in the other and repeat.

The above is referred to as Manhattan Distance, as compared to other measures 
like Euclidean distance.

So back to your robot arm, you can see a set of simple solutions where you make 
a sort of triangle with the direct Euclidean arm being a hypoteneuse and the  X 
and Y movements are the other two sides. You can then break up your problem as 
heading one way and pausing and turning the other way and stopping just short 
of the object you want. If there are no obstacles, you can do that in either 
order. Or, you could alternate in smaller amounts and get to the same 
destination. 

Grabbing it would be something else I will not address except to say that 
depending on what is grabbing and how it is shaped, you may need to aim not for 
the object, but the appropriate distance and direction so that when you stop 
moving, the "grasper" can close on it, again, avoiding existing obstacles. And 
note, speed is a consideration as many things need to be approached slowly and 
gently.

Next, consider what it would mean if you could have a combined motion based on 
both operations allowed at the same time. Consider a robot that is on wheels 
that can move horizontally while also having a "lift" component that lifts the 
part with the graspers vertically. Both could be programmed to run in tandem at 
appropriate speeds so the graspers are traveling along the hypotenuse I mention 
and are going the shortest path. This might be faster and more economical in 
other ways but can be more complex. And, it may be the robot does not have 
power or computing ability to do both at the same time. Your design is beyond 
vague.

Both of the approaches above make a plan and carry it out. But in the real 
world, many algorithms must adjust and work somewhat probabilistically. One 
algorithm for say catching a moving object, especially one that can change 
speed and direction a bit, like a running dog or a kite flying in the wind, is 
to locate where the object seems to be now, perhaps just a direction and a 
guess at distance, and maybe with some observation make a guess at where it 
might be at some time in the future that is approximately when you might move 
the robot near there. Then, use a technique like above (or completely 
different) that perhaps aims to get you something like halfway there. Monitor 
along the way to update your position and the newest destination position (if 
it is moving) and re-evaluate and adjust for the next round and maybe evaluate 
again as you approach halfway or so, again. Eventually, if you are close, slow 
down and gradually try to come to a stop where you can grab. If the object 
reacts to your attempting to go after it, it can be complex. And, you may 
overshoot and sort of circle back.

Now, expand the problem more if needed. What does the robot look like. How many 
places can it bend? For example, can it have something like two or more elbows, 
perhaps one allowing twisting of up to 30 degrees and one moving forward and 
backward and another allowing movement side to 

Re: Anonymous email users

2024-06-24 Thread Thomas Passin via Python-list

On 6/24/2024 5:51 AM, Barry Scott via Python-list wrote:




On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
 wrote:

The spammers won the spam wars, so even if you have someone's real
e-mail address, that's no guarantee that you can contact them. You
certainly wouldn't be able to contact me at my real e-mail address,
unless you also had my phone number, so you could call me and tell
me that you sent me an e-mail, and what the subject line was so I
can find it. I don't even open my e-mail inbox unless there's a
specific message I'm expecting to find there right now.


My email address is well known and yes I get spam emails.

I use the wonderful python based spambayes software to detect spam and
file into a Junk folder. It works for 99.9% of the emails I get.


I use the Thunderbird mail client and I just use its built in spam 
detector.  I don't know how it works but it's pretty darn good.  Very 
few false positives or false negatives.  And it learns each time I 
classify a message as "Junk", in case it missed one.



I am subscribed to a lot of mailing lists. I just checked and I am getting 
~3,200
emails a month of which less than 200 are spam.

A few years ago the spam count was greater than a 1,000 a month.

I have been using spambayes for a very long time, 20 years I guess at this
point and bayesian categorisation has stood the test of time for me.

For me the spammers have not won, I have the tech to keep ahead of them.

Barry



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


Re: Anonymous email users

2024-06-24 Thread Barry Scott via Python-list



> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list 
>  wrote:
> 
> The spammers won the spam wars, so even if you have someone's real
> e-mail address, that's no guarantee that you can contact them. You
> certainly wouldn't be able to contact me at my real e-mail address,
> unless you also had my phone number, so you could call me and tell
> me that you sent me an e-mail, and what the subject line was so I
> can find it. I don't even open my e-mail inbox unless there's a
> specific message I'm expecting to find there right now.

My email address is well known and yes I get spam emails.

I use the wonderful python based spambayes software to detect spam and
file into a Junk folder. It works for 99.9% of the emails I get.

I am subscribed to a lot of mailing lists. I just checked and I am getting 
~3,200
emails a month of which less than 200 are spam.

A few years ago the spam count was greater than a 1,000 a month.

I have been using spambayes for a very long time, 20 years I guess at this
point and bayesian categorisation has stood the test of time for me.

For me the spammers have not won, I have the tech to keep ahead of them.

Barry

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


Tkinter and astral characters (was: Decoding bytes to text strings in Python 2)

2024-06-24 Thread Peter J. Holzer via Python-list
On 2024-06-24 01:14:22 +0100, MRAB via Python-list wrote:
> Tkinter in recent versions of Python can handle astral characters, at least
> back to Python 3.8, the oldest I have on my Windows PC.

I just tried modifying
https://docs.python.org/3/library/tkinter.html#a-hello-world-program
to display "Hello World \N{ROCKET}" instead (Python 3.10.12 as included
with Ubuntu 22.04). I don't get a warning or error, but the emoji isn't
displayed either.

I suspect that the default font doesn't include emojis and Tk isn't
smart enough to fall back to a different font (unlike xfce4-terminal
which shows the emoji just fine).

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects)

2024-06-24 Thread marc nicole via Python-list
What are the parameters to account for in this type of algorithm? are there
some checks to perform the arm moves ? for example angle moves or cartesian
moves based on some distance thresholds? Any idea about the
pseudo-algorithm is welcome.

Thanks.

Le dim. 23 juin 2024 à 10:33, Alan Gauld via Tutor  a
écrit :

> On 22/06/2024 13:41, marc nicole wrote:
>
> > So, given the x,y,z coordinates of a target object and the offset x,y,z
> of
> > arms of a robot, what is a good algorithm to perform to grab the object
> > between the hands (either from both sides or from below all using both
> > hands).
> >
> > Specifically, my problem is applied to a NAO robot environment where I
> > retrieve a target object coordinates using the following code:
>
> This is almost entirely outside the Python domain and all within
> your 3rd party environment. Do they have a user forum or mailing
> list? You will probably get better results asking there?
>
> Another possibility is that you are using a Python wrapper around
> a C (or other language) library and there might be FAQs, fora or
> lists supporting that. If so you should be able to translate
> their examples to your Python code?
>
> In terms of generic solutions the only thing I can suggest that
> might help is to research collision detection algorithms.
> Wikipedia is likely a good starting point.
>
> --
> 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
>
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Chris Angelico via Python-list
On Mon, 24 Jun 2024 at 10:18, MRAB via Python-list
 wrote:
> Tkinter in recent versions of Python can handle astral characters, at
> least back to Python 3.8, the oldest I have on my Windows PC.

Good to know, thanks! I was hoping that would be the case, but I don't
have a Windows system to check on, so I didn't want to speak without
facts.

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


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread MRAB via Python-list

On 2024-06-24 00:30, Chris Angelico via Python-list wrote:

On Mon, 24 Jun 2024 at 08:20, Rayner Lucas via Python-list
 wrote:


In article ,
ros...@gmail.com says...
>
> If you switch to a Linux system, it should work correctly, and you'll
> be able to migrate the rest of the way onto Python 3. Once you achieve
> that, you'll be able to operate on Windows or Linux equivalently,
> since Python 3 solved this problem. At least, I *think* it will; my
> current system has a Python 2 installed, but doesn't have tkinter
> (because I never bothered to install it), and it's no longer available
> from the upstream Debian repos, so I only tested it in the console.
> But the decoding certainly worked.

Thank you for the idea of trying it on a Linux system. I did so, and my
example code generated the error:

_tkinter.TclError: character U+1f40d is above the range (U+-U+)
allowed by Tcl

So it looks like the problem is ultimately due to a limitation of
Tcl/Tk.

Yep, that seems to be the case. Not sure if that's still true on a
more recent Python, but it does look like you won't get astral
characters in tkinter on the one you're using.


[snip]
Tkinter in recent versions of Python can handle astral characters, at 
least back to Python 3.8, the oldest I have on my Windows PC.

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


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Chris Angelico via Python-list
On Mon, 24 Jun 2024 at 08:20, Rayner Lucas via Python-list
 wrote:
>
> In article ,
> ros...@gmail.com says...
> >
> > If you switch to a Linux system, it should work correctly, and you'll
> > be able to migrate the rest of the way onto Python 3. Once you achieve
> > that, you'll be able to operate on Windows or Linux equivalently,
> > since Python 3 solved this problem. At least, I *think* it will; my
> > current system has a Python 2 installed, but doesn't have tkinter
> > (because I never bothered to install it), and it's no longer available
> > from the upstream Debian repos, so I only tested it in the console.
> > But the decoding certainly worked.
>
> Thank you for the idea of trying it on a Linux system. I did so, and my
> example code generated the error:
>
> _tkinter.TclError: character U+1f40d is above the range (U+-U+)
> allowed by Tcl
>
> So it looks like the problem is ultimately due to a limitation of
> Tcl/Tk.
Yep, that seems to be the case. Not sure if that's still true on a
more recent Python, but it does look like you won't get astral
characters in tkinter on the one you're using.

> I'm still not sure why it doesn't give an error on Windows and

Because of the aforementioned weirdness of old (that is: pre-3.3)
Python versions on Windows. They were built to use a messy, buggy
hybrid of UCS-2 and UTF-16. Sometimes this got you around problems, or
at least masked them; but it wouldn't be reliable. That's why, in
Python 3.3, all that was fixed :)

> instead either works (when UTF-8 encoding is specified) or converts the
> out-of-range characters to ones it can display (when the encoding isn't
> specified). But now I know what the root of the problem is, I can deal
> with it appropriately (and my curiosity is at least partly satisfied).

Converting out-of-range characters is fairly straightforward, at least
as long as your Python interpreter is correctly built (so, Python 3,
or a Linux build of Python 2).

"".join(c if ord(c) < 65536 else "?" for c in text)

> This has given me a much better understanding of what I need to do in
> order to migrate to Python 3 and add proper support for non-ASCII
> characters, so I'm very grateful for your help!
>

Excellent. Hopefully all this mess is just a transitional state and
you'll get to something that REALLY works, soon!

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


Re: Anonymous email users

2024-06-23 Thread Sebastian Wells via Python-list
On Fri, 14 Jun 2024 18:00:37 -0400, avi.e.gross wrote:

> I notice that in some recent discussions, we have users who cannot be
> replied to directly as their email addresses are not valid ones, and I
> believe on purpose. Examples in the thread I was going to reply to are:
>  
>   henha...@devnull.tb
>  
>   no.email@nospam.invalid
>  
>  
> candycanearter07@candycanearter07.nomail.afraid (user  is
> generated from /dev/urandom)
>  
> I know some here suggest that we only reply to the wider community and
> they have a point. But I think there is a role for having some
> conversations offline and especially when they are not likely to be
> wanted, or even tolerated, by many in the community.
>  
> Using such fake or invalid emails makes it hard to answer the person
> directly or perhaps politely ask them for more info on their request or
> discuss unrelated common interests. Worse, when I reply, unless I use
> reply-all, my mailer sends to them futilely. When I do the reply-all, I
> have to edit out their name or get a rejection.
>  

The spammers won the spam wars, so even if you have someone's real
e-mail address, that's no guarantee that you can contact them. You
certainly wouldn't be able to contact me at my real e-mail address,
unless you also had my phone number, so you could call me and tell
me that you sent me an e-mail, and what the subject line was so I
can find it. I don't even open my e-mail inbox unless there's a
specific message I'm expecting to find there right now.

With e-mail addresses being phone-validated, it's not easy to create
a new one either. And even if I did, you can't even trust e-mail 
providers not to give your address out to spammers.

The only function e-mail addresses serve now is to positively identify
the sender of a Usenet posting so he can be targeted for harassment,
lawsuits, or worse.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Rayner Lucas via Python-list
In article , r...@zedat.fu-
berlin.de says...
> 
>   I didn't really do a super thorough deep dive on this,
>   but I'm just giving the initial impression without 
>   actually being familiar with Tkinter under Python 2,
>   so I might be wrong!
> 
>   The Text widget typically expects text in Tcl encoding,
>   which is usually UTF-8. 
> 
>   This is independent of the result returned by sys.get-
>   defaultencoding()! 
> 
>   If a UTF-8 string is inserted directly as a bytes object,
>   its code points will be displayed correctly by the Text 
>   widget as long as they are in the BMP (Basic Multilingual
>   Plane), as you already found out yourself.

Many thanks, you've helped me greatly in understanding what's happening. 
When I tried running my example code on a different system (Python 
2.7.18 on Linux, with Tcl/Tk 8.5), I got the error:

_tkinter.TclError: character U+1f40d is above the range (U+-U+) 
allowed by Tcl

So, as your reply suggests, the problem is ultimately a limitation of 
Tcl/Tk itself. Perhaps I should have spent more time studying the docs 
for that instead of puzzling over the details of character encodings in 
Python! I'm not sure why it doesn't give the same error on Windows, but 
at least now I know where the root of the issue is.

I am now much better informed about how to migrate the code I'm working 
on, so I am very grateful for your help.

Thanks,
Rayner
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Rayner Lucas via Python-list
In article , 
ros...@gmail.com says...
> 
> If you switch to a Linux system, it should work correctly, and you'll
> be able to migrate the rest of the way onto Python 3. Once you achieve
> that, you'll be able to operate on Windows or Linux equivalently,
> since Python 3 solved this problem. At least, I *think* it will; my
> current system has a Python 2 installed, but doesn't have tkinter
> (because I never bothered to install it), and it's no longer available
> from the upstream Debian repos, so I only tested it in the console.
> But the decoding certainly worked.

Thank you for the idea of trying it on a Linux system. I did so, and my 
example code generated the error:

_tkinter.TclError: character U+1f40d is above the range (U+-U+) 
allowed by Tcl

So it looks like the problem is ultimately due to a limitation of 
Tcl/Tk. I'm still not sure why it doesn't give an error on Windows and 
instead either works (when UTF-8 encoding is specified) or converts the 
out-of-range characters to ones it can display (when the encoding isn't 
specified). But now I know what the root of the problem is, I can deal 
with it appropriately (and my curiosity is at least partly satisfied).

This has given me a much better understanding of what I need to do in 
order to migrate to Python 3 and add proper support for non-ASCII 
characters, so I'm very grateful for your help!

Thanks,
Rayner
-- 
https://mail.python.org/mailman/listinfo/python-list


How to go about a simple object grabbing in python (given coordinates of arms and objects)

2024-06-23 Thread marc nicole via Python-list
Hello to all of this magnificent community!

I have this problem I had already spent a few days on and still can't
figure out a proper solution.

So, given the x,y,z coordinates of a target object and the offset x,y,z of
arms of a robot, what is a good algorithm to perform to grab the object
between the hands (either from both sides or from below all using both
hands).

Specifically, my problem is applied to a NAO robot environment where I
retrieve a target object coordinates using the following code:

tracker_service= session.service("ALTracker")
xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO)


src:
http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors


Then I get to move the right arm towards nearby the object using the
following code:

effector = "RArm"

frame = motion.FRAME_TORSO
effector_offset =
almath.Transform(self.motion.getTransform(effector, frame, False))
effector_init_3d_position = almath.position3DFromTransform(
effector_offset)

target_3d_position = almath.Position3D(target_position)
move_3d = target_3d_position - effector_init_3d_position
moveTransform = almath.Transform.fromPosition(move_3d.x,
move_3d.y, move_3d.z)
target_transformer_list = list(moveTransform.toVector())
times = [2.0]
axis_mask_list = motion.AXIS_MASK_VEL
self.motion.transformInterpolations(effector, frame,
target_transformer_list, axis_mask_list, times).

src: 
http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset
This question is specific to NAO environment but in general how to go
about this task? what is a most common algorithm used in this case? Do
I have to also get the side of the object in order to know where
exactly the arms should be placed?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects)

2024-06-22 Thread marc nicole via Python-list
My code is just an attempt at the task, it is not exact as what relates to
the coordinates (e.g., doesn't account for the size of the object. I would
like to have a idea on the general approach to such problems (even a pseudo
code would do)

"Get the hands rapidly enough in the vicinity and then do some fine
coordinated motions to capture the object and then presumably move it."
seems to be a good approach indeed,
The grabbing with both hands code should be more precise.

Thanks for the help anyways!

Le sam. 22 juin 2024 à 23:04, ThreeBlindQuarks 
a écrit :

> Marc,
>
> Could you specify what is wrong with what you are doing? you show us code
> that uses an environment you point to that is largely outside of basic
> Python.
>
> There is no one way to get from point A to point B and various constraints
> you have not mentioned can apply. How many joints does the assemblage have
> and what are the limits and costs associated with each. Cam there be
> barriers along a route, including to the side where they may brush part of
> your equipment. Are other things moving (independently even) that may end
> up blocking.
>
> You seem to need both "hands" and presumably at the same time. So
> solutions can take that into account. You need to define what is meant by
> contacting the object to move and you don't want to approach it and hit
> with some speed.
>
> So, the problem may be in parts. Get the hands rapidly enough in the
> vicinity and then do some fine coordinated motions to capture the object
> and then presumably move it.
>
> If you could point to what code is not doing what is expected, someone who
> knows the details or is willing to learn, might help, If you want an
> overall algorithm, there may be some people could share but they may not
> easily translate into the package of sorts you are using.
>
> But the web site you point us to may well already contain examples of
> doing some aspects that you might learn from.
>
> For me, this is too detailed to focus on as I struggle to figure out how
> to move my hands to different parts of my keyboard while looking ...
>
> And that may be one variant of an algorithm where instead of trying to
> move all the way, you move art-way and LOOK where you are, then repeat.
>
>
> Sent with Proton Mail secure email.
>
> On Saturday, June 22nd, 2024 at 8:41 AM, marc nicole 
> wrote:
>
> > Hello to all of this magnificent community!
> >
> > I have this problem I had already spent a few days on and still can't
> > figure out a proper solution.
> >
> > So, given the x,y,z coordinates of a target object and the offset x,y,z
> of
> > arms of a robot, what is a good algorithm to perform to grab the object
> > between the hands (either from both sides or from below all using both
> > hands).
> >
> > Specifically, my problem is applied to a NAO robot environment where I
> > retrieve a target object coordinates using the following code:
> >
> > tracker_service= session.service("ALTracker")
> > xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO)
> >
> >
> > src:
> >
> http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors
> >
> >
> > Then I get to move the right arm towards nearby the object using the
> > following code:
> >
> > effector = "RArm"
> >
> > frame = motion.FRAME_TORSO
> > effector_offset =
> > almath.Transform(self.motion.getTransform(effector, frame, False))
> > effector_init_3d_position = almath.position3DFromTransform(
> > effector_offset)
> >
> > target_3d_position = almath.Position3D(target_position)
> > move_3d = target_3d_position - effector_init_3d_position
> > moveTransform = almath.Transform.fromPosition(move_3d.x,
> > move_3d.y, move_3d.z)
> > target_transformer_list = list(moveTransform.toVector())
> > times = [2.0]
> > axis_mask_list = motion.AXIS_MASK_VEL
> > self.motion.transformInterpolations(effector, frame,
> > target_transformer_list, axis_mask_list, times).
> >
> > src:
> http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset
> > This question is specific to NAO environment but in general how to go
> > about this task? what is a most common algorithm used in this case? Do
> > I have to also get the side of the object in order to know where
> > exactly the arms should be placed?
> > ___
> > Tutor maillist - tu...@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decoding bytes to text strings in Python 2

2024-06-21 Thread Chris Angelico via Python-list
On Sat, 22 Jun 2024 at 03:28, Rayner Lucas via Python-list
 wrote:
> I'm curious about something I've encountered while updating a very old
> Tk app (originally written in Python 1, but I've ported it to Python 2
> as a first step towards getting it running on modern systems).
>
> I am using Python 2.7.18 on a Windows 10 system. If there's any other
> relevant information I should provide please let me know.

Unfortunately, you're running into one of the most annoying problems
from Python 2 and Windows: "narrow builds". You don't actually have
proper Unicode support. You have a broken implementation that works
for UCS-2 but doesn't actually support astral characters.

If you switch to a Linux system, it should work correctly, and you'll
be able to migrate the rest of the way onto Python 3. Once you achieve
that, you'll be able to operate on Windows or Linux equivalently,
since Python 3 solved this problem. At least, I *think* it will; my
current system has a Python 2 installed, but doesn't have tkinter
(because I never bothered to install it), and it's no longer available
from the upstream Debian repos, so I only tested it in the console.
But the decoding certainly worked.

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


Decoding bytes to text strings in Python 2

2024-06-21 Thread Rayner Lucas via Python-list


I'm curious about something I've encountered while updating a very old 
Tk app (originally written in Python 1, but I've ported it to Python 2 
as a first step towards getting it running on modern systems). The app 
downloads emails from a POP server and displays them. At the moment, the 
code is completely unaware of character encodings (which is something I 
plan to fix), and I have found that I don't understand what Python is 
doing when no character encoding is specified.

To demonstrate, I have written this short example program that displays 
a variety of UTF-8 characters to check whether they are decoded 
properly:

 Example Code 
import Tkinter as tk

window = tk.Tk()

mytext = """
  \xc3\xa9 LATIN SMALL LETTER E WITH ACUTE
  \xc5\x99 LATIN SMALL LETTER R WITH CARON
  \xc4\xb1 LATIN SMALL LETTER DOTLESS I
  \xef\xac\x84 LATIN SMALL LIGATURE FFL
  \xe2\x84\x9a DOUBLE-STRUCK CAPITAL Q
  \xc2\xbd VULGAR FRACTION ONE HALF
  \xe2\x82\xac EURO SIGN
  \xc2\xa5 YEN SIGN
  \xd0\x96 CYRILLIC CAPITAL LETTER ZHE
  \xea\xb8\x80 HANGUL SYLLABLE GEUL
  \xe0\xa4\x93 DEVANAGARI LETTER O
  \xe5\xad\x97 CJK UNIFIED IDEOGRAPH-5B57
  \xe2\x99\xa9 QUARTER NOTE
  \xf0\x9f\x90\x8d SNAKE
  \xf0\x9f\x92\x96 SPARKLING HEART
"""

mytext = mytext.decode(encoding="utf-8")
greeting = tk.Label(text=mytext)
greeting.pack()

window.mainloop()
 End Example Code 

This works exactly as expected, with all the characters displaying 
correctly.

However, if I comment out the line 'mytext = mytext.decode
(encoding="utf-8")', the program still displays *almost* everything 
correctly. All of the characters appear correctly apart from the two 
four-byte emoji characters at the end, which instead display as four 
characters. For example, the "SNAKE" character actually displays as:
U+00F0 LATIN SMALL LETTER ETH
U+FF9F HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
U+FF90 HALFWIDTH KATAKANA LETTER MI
U+FF8D HALFWIDTH KATAKANA LETTER HE

What's Python 2 doing here? sys.getdefaultencoding() returns 'ascii', 
but it's clearly not attempting to display the bytes as ASCII (or 
cp1252, or ISO-8859-1). How is it deciding on some sort of almost-but-
not-quite UTF-8 decoding?

I am using Python 2.7.18 on a Windows 10 system. If there's any other 
relevant information I should provide please let me know.

Many thanks,
Rayner
-- 
https://mail.python.org/mailman/listinfo/python-list


glibc strverscmp called from python

2024-06-20 Thread vallor via Python-list
So there's been discussion in comp.lang.c and comp.unix.shell
about doing a "versionsort(3)" type sort on a list
of parameters.  glibc offers strverscmp(3) for this type
of sort, and here I am posting a q python program to expose
that to its sort routine for commentary and future reference.

Caveat:  I know just enough python to be dangerous -- wrote
this using ChatGPT.  It is a learning experience, comments
very much appreciated.

 - -%<- -

#!/usr/bin/python3

import ctypes
from ctypes import c_char_p, c_int
import os
import sys

# Load the C standard library (libc)
libc = ctypes.CDLL("libc.so.6")

# Define the prototype of strverscmp
# int strverscmp (const char *s1, const char *s2)
libc.strverscmp.argtypes = [c_char_p, c_char_p]
libc.strverscmp.restype = c_int

# Define a comparison function for Python sorting
def version_compare(x, y):
return libc.strverscmp(x.encode('utf-8'), y.encode('utf-8'))

# Define a key function for sorting
def version_key(s):
class K:
def __init__(self, s):
self.s = s
def __lt__(self, other):
return version_compare(self.s, other.s) < 0
def __gt__(self, other):
return version_compare(self.s, other.s) > 0
def __eq__(self, other):
return version_compare(self.s, other.s) == 0
def __le__(self, other):
return version_compare(self.s, other.s) <= 0
def __ge__(self, other):
return version_compare(self.s, other.s) >= 0
def __ne__(self, other):
return version_compare(self.s, other.s) != 0
return K(s)

# Function to escape special characters
def shell_escape(s):
return s.replace(" ", "\\ ").replace("\n", "\\n").replace("\t", "\\t")

# Parse command-line arguments
args = sys.argv[1:]

# Sort the list using the version key
sorted_args = sorted(args, key=version_key)

# Print each sorted, escaped value on a new line
for arg in sorted_args:
print(shell_escape(arg))

 - -%<- -

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


Re: Timezone in HH:MM Format

2024-06-18 Thread Ivan "Rambius" Ivanov via Python-list
Thank you all for your responses!

On Tue, Jun 18, 2024 at 9:54 PM Jon Ribbens via Python-list
 wrote:
>
> datetime.now(ZoneInfo("America/New_York")).isoformat()

Both .isoformat() and "%:z" work.


-- 
Tangra Mega Rock: http://www.radiotangra.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Timezone in HH:MM Format

2024-06-18 Thread Jon Ribbens via Python-list
On 2024-06-18, Ivan "Rambius" Ivanov  wrote:
> Hello,
>
> How can I convert a date, usually datetime.now(), into a format where
> the timezone is in hours:minutes format. I was able to get that format
> in shell:
>
> $ date +%Y-%m-%dT%H:%M:%S%:z
> 2024-06-18T19:24:09-04:00
>
> The closest I got in python is
>
> from datetime import datetime
> from zoneinfo import ZoneInfo
>
> s = datetime.strftime(datetime.now(ZoneInfo("America/New_York")),
> "%Y-%m-%dT%H:%M:%S%z")
> print(s)
>
> This prints the same as the shell command above except the last column:
> 2024-06-18T19:28:56-0400
>
> Any help will be appreciated.

datetime.now(ZoneInfo("America/New_York")).isoformat()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Timezone in HH:MM Format

2024-06-18 Thread MRAB via Python-list

On 2024-06-19 00:32, Ivan "Rambius" Ivanov via Python-list wrote:

Hello,

How can I convert a date, usually datetime.now(), into a format where
the timezone is in hours:minutes format. I was able to get that format
in shell:

$ date +%Y-%m-%dT%H:%M:%S%:z
2024-06-18T19:24:09-04:00

The closest I got in python is

from datetime import datetime
from zoneinfo import ZoneInfo

s = datetime.strftime(datetime.now(ZoneInfo("America/New_York")),
"%Y-%m-%dT%H:%M:%S%z")
print(s)

This prints the same as the shell command above except the last column:
2024-06-18T19:28:56-0400

Starting from Python 3.12, you can use "%:z" in the format string. For 
earlier versions of Python, you need to do some string slicing.

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


Timezone in HH:MM Format

2024-06-18 Thread Ivan "Rambius" Ivanov via Python-list
Hello,

How can I convert a date, usually datetime.now(), into a format where
the timezone is in hours:minutes format. I was able to get that format
in shell:

$ date +%Y-%m-%dT%H:%M:%S%:z
2024-06-18T19:24:09-04:00

The closest I got in python is

from datetime import datetime
from zoneinfo import ZoneInfo

s = datetime.strftime(datetime.now(ZoneInfo("America/New_York")),
"%Y-%m-%dT%H:%M:%S%z")
print(s)

This prints the same as the shell command above except the last column:
2024-06-18T19:28:56-0400

Any help will be appreciated.

Regards
Ivan

-- 
Tangra Mega Rock: http://www.radiotangra.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: in Python: (101 102 103 201 202 203 301 302 303 401 402 403 )

2024-06-18 Thread Peter J. Holzer via Python-list
On 2024-06-14 06:10:06 -, candycanearter07 via Python-list wrote:
> Phil Carmody  wrote at 12:01 this Thursday (GMT):
> > I'd say you can't beat the verbosity, or lack thereof of just plain 
> > zsh/bash:
> >   $ echo {1,2,3,4}0{1,2,3}
> >   101 102 103 201 202 203 301 302 303 401 402 403
> 
> 
> I /think/ you can replace it with {1...4} and {1...3}? I know there is
> some syntax for "range of numbers" but I can't remember it exactly.

Only two dots, not three:

% echo {1..4}0{1..3}
101 102 103 201 202 203 301 302 303 401 402 403

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

2024-06-18 Thread Grant Edwards via Python-list
On 2024-06-18, Mats Wichmann via Python-list  wrote:
> On 6/17/24 17:51, dn via Python-list wrote:
>
>> +1
>> 
>> The "public" part is not to embarrass posters, but recognition that 
>> there are likely other people 'out there' (or arriving in-future if they 
>> care to read the archives) experiencing a similar problem. (hence need 
>> for descriptive Subject lines - isn't the most difficult task in 
>> programming 'choosing names'?)
>
> well, one of two, along with cache invalidation and off-by-one errors 
> (according to the wags).
>
> I do agree with this, but mailman (2) archives aren't particularly 
> useful for searching, as they're organized in monthly chunks and you 
> have to keep clicking around - this list doesn't have a search engine as 
> it's not converted to be one of the mailman 3 lists.

Gmane used to have a usable search feature (along with a decent
threaded web UI to read the arhives), but that got lost during the
great gmane server/domain upheaval of 2016 (or whenever that was). I
still miss it.

--
Grant

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


Re: Anonymous email users

2024-06-18 Thread Mats Wichmann via Python-list

On 6/17/24 17:51, dn via Python-list wrote:


+1

The "public" part is not to embarrass posters, but recognition that 
there are likely other people 'out there' (or arriving in-future if they 
care to read the archives) experiencing a similar problem. (hence need 
for descriptive Subject lines - isn't the most difficult task in 
programming 'choosing names'?)


well, one of two, along with cache invalidation and off-by-one errors 
(according to the wags).


I do agree with this, but mailman (2) archives aren't particularly 
useful for searching, as they're organized in monthly chunks and you 
have to keep clicking around - this list doesn't have a search engine as 
it's not converted to be one of the mailman 3 lists.


There are supposed to be some search engine incantations to make this 
better. I find this one works, though I can never actually remember it 
and have to go hunting again each time... picking a random-ish subject 
line from this list in the past:


site:mail.python.org inurl:Python-list multiplication

I don't know that we publicise such methods (there are probably others).

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


Re: win32clipboard writing to clipboard on Windows 11

2024-06-18 Thread Eryk Sun via Python-list
On Tue, Jun 18, 2024 at 2:19 AM Eryk Sun  wrote:
>
>
> def set_clipboard_text(text):
> hMem = global_alloc_text(text)
> try:
> win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
> hMem)
> # Now the system owns the global memory.
> except:
> kernel32.GlobalFree(hMem)

Oops, that suppresses the exception. Fixed:

def set_clipboard_text(text):
hMem = global_alloc_from_text(text)
try:
win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
hMem)
# Now the system owns the global memory.
except:
kernel32.GlobalFree(hMem)
raise
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: win32clipboard writing to clipboard on Windows 11

2024-06-18 Thread Eryk Sun via Python-list
On Mon, Jun 17, 2024 at 8:36 PM MRAB via Python-list
 wrote:
> On 2024-06-17 20:27, Rob Cliffe via Python-list wrote:
>
> > SetClipboardData(CF_UNICODETEXT, "0")
> > CloseClipboard()

win32clipboard.SetClipboardData() first tries to covert the second
argument as an integer handle to global memory, which gets passed to
WinAPI SetClipboardData(). The integer conversion is basically via
int(). With int("0"), it's passing a NULL handle value, which
instructs the window manager to query the data from the window that
was associated via OpenClipboard(), if any. Since no memory handle is
passed in this case, SetClipboardData() returns NULL.
win32clipboard.SetClipboardData() misinterprets this as failure and
raises an exception for whatever random error code is currently set in
the thread's last error value. On the other hand, for a numeric text
string with a nonzero value, such as "123",
win32clipboard.SetClipboardData() will raise an exception for the
error code ERROR_INVALID_HANDLE (6), unless the integer value happens
to be a valid global memory handle value.

I recommend just using win32clipboard.SetClipboardText(). Otherwise I
don't see an easy workaround given the peculiar design of
win32clipboard.SetClipboardData(). You'd have to manually allocate a
block of global memory, copy the numeric text string into it, and pass
the global memory handle to win32clipboard.SetClipboardData(). For
example:

import ctypes
import win32clipboard
from ctypes import wintypes

kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

GMEM_MOVEABLE = 0x0002

kernel32.GlobalAlloc.restype = wintypes.HGLOBAL
kernel32.GlobalFree.argtypes = (wintypes.HGLOBAL,)
kernel32.GlobalLock.restype = wintypes.LPVOID
kernel32.GlobalLock.argtypes = (wintypes.HGLOBAL,)
kernel32.GlobalUnlock.argtypes = (wintypes.HGLOBAL,)

def global_alloc_text(text):
array_t = ctypes.c_wchar * (len(text) + 1)
hMem = kernel32.GlobalAlloc(GMEM_MOVEABLE, ctypes.sizeof(array_t))
if not hMem:
raise ctypes.WinError(ctypes.get_last_error())
pMem = kernel32.GlobalLock(hMem)
try:
try:
array_t.from_address(pMem).value = text
finally:
kernel32.GlobalUnlock(hMem)
except:
kernel32.GlobalFree(hMem)
raise
return hMem

def set_clipboard_text(text):
hMem = global_alloc_text(text)
try:
win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
hMem)
# Now the system owns the global memory.
except:
kernel32.GlobalFree(hMem)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: win32clipboard writing to clipboard on Windows 11

2024-06-17 Thread Thomas Passin via Python-list

On 6/17/2024 9:30 PM, MRAB via Python-list wrote:

On 2024-06-17 20:27, Rob Cliffe via Python-list wrote:

Recently I acquired a new laptop running WIndows 11; my previous one
uses WIndows 10.  I encountered a strange problem:
I am using the win32clipboard backage (part of pywin32), and when I use
SetClipboardData() to write text which consists ***entirely of digits***
to the clipboard, I either get an error (not always the same error
message) or a program crash.  The problem does not appear if I use
SetClipboardText() instead.  The problem does not occur on my old
machine (where I used the feature extensively).

Sample program:

from win32clipboard import *
OpenClipboard()
SetClipboardData(CF_UNICODETEXT, "A")
SetClipboardData(CF_UNICODETEXT, "A0")
SetClipboardData(CF_UNICODETEXT, "0A")
SetClipboardText("0", CF_UNICODETEXT)
print("OK so far")
SetClipboardData(CF_UNICODETEXT, "0")
CloseClipboard()

Sample output:

OK so far
Traceback (most recent call last):
    File "C:\TEST*.PY", line 8, in 
      SetClipboardData(CF_UNICODETEXT, "0")
pywintypes.error: (0, 'SetClipboardData', 'No error message is 
available')


Can anyone shed light on this?
Best wishes
Rob Cliffe


I tried it on Windows 10 and got this:

 >>> from win32clipboard import *
 >>> OpenClipboard()
 >>> SetClipboardData(CF_UNICODETEXT, "A")
1830508101640
 >>> CloseClipboard()
 >>> OpenClipboard()
 >>> SetClipboardData(CF_UNICODETEXT, "0")
Traceback (most recent call last):
   File "", line 1, in 
pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.')
 >>> CloseClipboard()

It looks like it's something to memory ownership:

https://stackoverflow.com/questions/1264137/how-to-copy-string-to-clipboard-in-c

If you're putting text on the clipboard, why not just use 
SetClipboardText()? That's what I do.


If you can make a change, and you only need to work with text on the 
clipboard, you could change to use pyperclip.  It also works on Linux, 
if you might care about that in the future.  It's available as a pip 
install. It's easier to use than the win32 approach.

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


Re: win32clipboard writing to clipboard on Windows 11

2024-06-17 Thread MRAB via Python-list

On 2024-06-17 20:27, Rob Cliffe via Python-list wrote:

Recently I acquired a new laptop running WIndows 11; my previous one
uses WIndows 10.  I encountered a strange problem:
I am using the win32clipboard backage (part of pywin32), and when I use
SetClipboardData() to write text which consists ***entirely of digits***
to the clipboard, I either get an error (not always the same error
message) or a program crash.  The problem does not appear if I use
SetClipboardText() instead.  The problem does not occur on my old
machine (where I used the feature extensively).

Sample program:

from win32clipboard import *
OpenClipboard()
SetClipboardData(CF_UNICODETEXT, "A")
SetClipboardData(CF_UNICODETEXT, "A0")
SetClipboardData(CF_UNICODETEXT, "0A")
SetClipboardText("0", CF_UNICODETEXT)
print("OK so far")
SetClipboardData(CF_UNICODETEXT, "0")
CloseClipboard()

Sample output:

OK so far
Traceback (most recent call last):
    File "C:\TEST*.PY", line 8, in 
      SetClipboardData(CF_UNICODETEXT, "0")
pywintypes.error: (0, 'SetClipboardData', 'No error message is available')

Can anyone shed light on this?
Best wishes
Rob Cliffe


I tried it on Windows 10 and got this:

>>> from win32clipboard import *
>>> OpenClipboard()
>>> SetClipboardData(CF_UNICODETEXT, "A")
1830508101640
>>> CloseClipboard()
>>> OpenClipboard()
>>> SetClipboardData(CF_UNICODETEXT, "0")
Traceback (most recent call last):
  File "", line 1, in 
pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.')
>>> CloseClipboard()

It looks like it's something to memory ownership:

https://stackoverflow.com/questions/1264137/how-to-copy-string-to-clipboard-in-c

If you're putting text on the clipboard, why not just use 
SetClipboardText()? That's what I do.

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


Re: Anonymous email users

2024-06-17 Thread dn via Python-list

On 18/06/24 05:29, Roel Schroeven via Python-list wrote:

AVI GROSS via Python-list schreef op 17/06/2024 om 17:03:
I simply am thinking that people who do not allow me to easily reply 
to them

directly, should be ignored by me and not get my cooperation that way.
FWIW, personally I (mostly) don't see the point of replying to people 
personally. To me a public mailing list is much like any public forum, 
where my expectation is that conversations happen in public. To me it 
always feels weird when I get a personal reply when I make a public post 
in a mailing list. I mostly ignore those, unless there's really 
something in it that's best kept out of the public. Sometimes people 
write long mails with wandering thoughts only loosely related to the 
topic at hand directly to me instead of to the whole list. My take is: 
if it's not on-topic enough for the list, it's not on-topic enough for 
me either. Not that it bothers me *that* much; I just ignore those. It's 
very well possible that's just me, and that other people have different 
expectations.


+1

The "public" part is not to embarrass posters, but recognition that 
there are likely other people 'out there' (or arriving in-future if they 
care to read the archives) experiencing a similar problem. (hence need 
for descriptive Subject lines - isn't the most difficult task in 
programming 'choosing names'?)


Yes, like @Avi, I have been known to contact folk directly. However, 
such for personal purposes - as distinct from the list, and possibly 
subjects OT for the list.


When contacted by others off-list, I play it by ear - ignore, personal, 
or post response on-list. (some lists/email-clients do seem to prefer 
personal replies, even when incoming message is from a list - so easy 
accident.)


The Delete-key is your friend!

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


RE: Anonymous email users

2024-06-17 Thread AVI GROSS via Python-list


It seems clear we have people on mailing lists that see it as a purely
public forum, and that is fine for them.

I have found plenty of times I choose not to continue in public and waste
time for people as in this reply on a topic I raised and now will move away
from.

I have in the past, for example, offered to help people and participate in
aspects of their project that do not need to be viewed here, such as helping
them find out how to adjust their graphical output to better fit their
needs. Or, if someone mentions me negatively, I prefer not always replying
in public to perhaps see if I misunderstood something or was misunderstood. 

I have lots of people I "met" in places like this that I keep in touch with
privately and see that as a plus. For those who just want a business-like
experience, no problem. For those who choose levels of anonymity or don't
like being contacted, again, fine for them.

The reality is that I have found people who show up in forums looking almost
legit but actually are not at all who they appear or claim to be even when
they have valid email addresses like mrsp...@gmail.com or even use names of
real people you can search for on the internet but who are not actually the
ones they may even claim.

My message was not to say what people could not do, but to point out they
may be missing out on what some see as collateral opportunities. The people
I have helped privately would not have received it had they only
participated through the group and I would not have received some chances to
learn if I could not ask questions in private that clearly did not fit the
purpose of the group.

So, I am outa this conversation IN PUBLIC. LOL!

-Original Message-
From: Python-list  On
Behalf Of Grant Edwards via Python-list
Sent: Monday, June 17, 2024 5:08 PM
To: python-list@python.org
Subject: Re: Anonymous email users

On 2024-06-17, Roel Schroeven via Python-list 
wrote:

> FWIW, personally I (mostly) don't see the point of replying to people 
> personally. To me a public mailing list is much like any public forum, 
> where my expectation is that conversations happen in public. To me it 
> always feels weird when I get a personal reply when I make a public post 
> in a mailing list. I mostly ignore those, unless there's really 
> something in it that's best kept out of the public.

My sentiments exactly. I generally don't even read replies that get
mailed to me. They almost always seem to be copies of replies that
were also posted to the mailing list (which I read using an NNTP
client pointed at news.gmane.io).

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

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


Re: Anonymous email users

2024-06-17 Thread Grant Edwards via Python-list
On 2024-06-17, Roel Schroeven via Python-list  wrote:

> FWIW, personally I (mostly) don't see the point of replying to people 
> personally. To me a public mailing list is much like any public forum, 
> where my expectation is that conversations happen in public. To me it 
> always feels weird when I get a personal reply when I make a public post 
> in a mailing list. I mostly ignore those, unless there's really 
> something in it that's best kept out of the public.

My sentiments exactly. I generally don't even read replies that get
mailed to me. They almost always seem to be copies of replies that
were also posted to the mailing list (which I read using an NNTP
client pointed at news.gmane.io).

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


win32clipboard writing to clipboard on Windows 11

2024-06-17 Thread Rob Cliffe via Python-list
Recently I acquired a new laptop running WIndows 11; my previous one 
uses WIndows 10.  I encountered a strange problem:
I am using the win32clipboard backage (part of pywin32), and when I use 
SetClipboardData() to write text which consists ***entirely of digits*** 
to the clipboard, I either get an error (not always the same error 
message) or a program crash.  The problem does not appear if I use 
SetClipboardText() instead.  The problem does not occur on my old 
machine (where I used the feature extensively).


Sample program:

from win32clipboard import *
OpenClipboard()
SetClipboardData(CF_UNICODETEXT, "A")
SetClipboardData(CF_UNICODETEXT, "A0")
SetClipboardData(CF_UNICODETEXT, "0A")
SetClipboardText("0", CF_UNICODETEXT)
print("OK so far")
SetClipboardData(CF_UNICODETEXT, "0")
CloseClipboard()

Sample output:

OK so far
Traceback (most recent call last):
  File "C:\TEST*.PY", line 8, in 
    SetClipboardData(CF_UNICODETEXT, "0")
pywintypes.error: (0, 'SetClipboardData', 'No error message is available')

Can anyone shed light on this?
Best wishes
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

2024-06-17 Thread Roel Schroeven via Python-list

AVI GROSS via Python-list schreef op 17/06/2024 om 17:03:

I simply am thinking that people who do not allow me to easily reply to them
directly, should be ignored by me and not get my cooperation that way.
FWIW, personally I (mostly) don't see the point of replying to people 
personally. To me a public mailing list is much like any public forum, 
where my expectation is that conversations happen in public. To me it 
always feels weird when I get a personal reply when I make a public post 
in a mailing list. I mostly ignore those, unless there's really 
something in it that's best kept out of the public. Sometimes people 
write long mails with wandering thoughts only loosely related to the 
topic at hand directly to me instead of to the whole list. My take is: 
if it's not on-topic enough for the list, it's not on-topic enough for 
me either. Not that it bothers me *that* much; I just ignore those. It's 
very well possible that's just me, and that other people have different 
expectations.


But I don't go hiding my email address, that's a whole different kettle.

--
"Let everything happen to you
Beauty and terror
Just keep going
No feeling is final"
-- Rainer Maria Rilke

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


RE: Anonymous email users

2024-06-17 Thread AVI GROSS via Python-list
Thanks, Marco, for explaining.

I, personally, have no interest in finding out who people are in this case.
I simply am thinking that people who do not allow me to easily reply to them
directly, should be ignored by me and not get my cooperation that way.

I do understand reasons people use fake ID but note others have put their
email address in their signature, perhaps slightly disguised as in:

Myname=ereweon.com

Or 

myn...@unspecified.tb s/unspecified.tb/yahoo.com/

It may be the gateway or other records can find them if they are nasty, but
for now, it is just an observation that it seems the discussions with people
in the email list are more useful to me.

-Original Message-
From: Python-list  On
Behalf Of Marco Moock via Python-list
Sent: Saturday, June 15, 2024 2:03 AM
To: python-list@python.org
Subject: Re: Anonymous email users

On 15.06.2024 um 10:30 Uhr dn wrote:

> These mailing-lists all run under the Python Code of Conduct.
> 
> This also effects a conundrum. Firstly, that someone abusing others
> (for example) shall be held responsible. Secondly, that in order to
> hold someone responsible, he/she/... must be identifiable.

The mailing list has a Usenet gateway

Those users use the Usenet to post.
Check the Injection-Info header for the address of the news server
operator. He can identify the account that posted it.

-- 
kind regards
Marco

Send spam to 1718440236mu...@cartoonies.org

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

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


Re: Anonymous email users

2024-06-17 Thread Marco Moock via Python-list
On 15.06.2024 um 10:30 Uhr dn wrote:

> These mailing-lists all run under the Python Code of Conduct.
> 
> This also effects a conundrum. Firstly, that someone abusing others
> (for example) shall be held responsible. Secondly, that in order to
> hold someone responsible, he/she/... must be identifiable.

The mailing list has a Usenet gateway

Those users use the Usenet to post.
Check the Injection-Info header for the address of the news server
operator. He can identify the account that posted it.

-- 
kind regards
Marco

Send spam to 1718440236mu...@cartoonies.org

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


Re: Suggested python feature: allowing except in context maneger

2024-06-17 Thread j via Python-list


On 2024-06-13 23:49, Cameron Simpson via Python-list wrote:
On 13Jun2024 19:44, dieter.mau...@online.de  
wrote:

Why not use:
```
try:
 with open()...
   ...
except FileNotFoundError:
 ...
```


This is exactly what the OP was expressing dissatisfaction with.

I'm -1 on the idea myself - not every combination of things needs 
additional syntactic support, and doing stuff like merging an `except` 
with a `wtih` is bound to introduce some weird corner case, 
complicating its semantics.


I agree. If python allowed statement lambdas you could write what you 
want above within the language (albeit a bit clumsily). It's very handy.


jan



Cheers,
Cameron Simpson 

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


Re: Suggested python feature: allowing except in context maneger

2024-06-16 Thread Albert-Jan Roskam via Python-list
 The example exception is not what bothers me. The syntax change is
 nowhere near as useful as `with` and context managers. They provide an
 excellent idiom for resource usage and release.

 Your suggestion complicates the `with` statement and brings only a tiny
 indentation reduction over the `with`-inside-`try` idiom. It brings no
 semantic changes or new features.

   
   I also don't see the added value. If you desperately want to get rid of an
   indentation level, you could use an except
   hook. https://docs.python.org/3/library/sys.html#sys.excepthook
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

2024-06-14 Thread Cameron Simpson via Python-list

On 14Jun2024 09:07, Yair Eshel  wrote:

Cameron, I'm not really sure I got your point. I've used the "file not
found" exception as an example for a behavior typical on context managers.
This could be a failure to connect to DB, or threads. It also applies to
any kind of possible exception, whether cased by the context manager itself
or the lines inside it. Long story short, this syntax change is as useful
as context managers are


The example exception is not what bothers me. The syntax change is 
nowhere near as useful as `with` and context managers. They provide an 
excellent idiom for resource usage and release.


Your suggestion complicates the `with` statement and brings only a tiny 
indentation reduction over the `with`-inside-`try` idiom. It brings no 
semantic changes or new features.


That is why I'm -1: the benefit is triviailly small to my eye.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Anonymous email users

2024-06-14 Thread Cameron Simpson via Python-list

On 14Jun2024 18:00, avi.e.gr...@gmail.com  wrote:

I notice that in some recent discussions, we have users who cannot be
replied to directly as their email addresses are not valid ones, and I
believe on purpose. Examples in the thread I was going to reply to are:

 henha...@devnull.tb

[...]
I know some here suggest that we only reply to the wider community and 
they

have a point. But I think there is a role for having some conversations
offline and especially when they are not likely to be wanted, or even
tolerated, by many in the community.

Using such fake or invalid emails makes it hard to answer the person
directly or perhaps politely ask them for more info on their request or
discuss unrelated common interests. Worse, when I reply, unless I use
reply-all, my mailer sends to them futilely. When I do the reply-all, I have
to edit out their name or get a rejection.


I often reply-all (meaning to the list and to the author). And edit the 
headers (frankly, often just to discard anything @gmail.com which has 
very stupid spam poolicies).  If I miss an @invalid.com or whatever, 
then whoops.


If I want to reply directly (eg for some kind of feedback rather than a 
list type reply) and they've got a bogus address, well then I don't.  
Supposedly my reply would be of benefit for them or I shouldn't be doing 
it, so their loss. But equally, if they don't want personal off-list 
contact, they've expressed their preference. I should respect that.


Plenty of people have reasons to post anonymously, even to a list like 
this one. Just assume they've got their reasons and move on.

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


Re: Anonymous email users

2024-06-14 Thread Chris Angelico via Python-list
On Sat, 15 Jun 2024 at 08:32, dn via Python-list  wrote:
> These mailing-lists all run under the Python Code of Conduct.
>

The newsgroup, however, is not. Which means that anyone who posts on
the newsgroup is subject to no such restrictions - and that might
explain the, shall we say, quite different signal-to-noise ratio of
newsgroup posters compared to mailing list posters.

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


Re: Anonymous email users

2024-06-14 Thread dn via Python-list

On 15/06/24 10:00, AVI GROSS via Python-list wrote:

I notice that in some recent discussions, we have users who cannot be
replied to directly as their email addresses are not valid ones, and I
believe on purpose. Examples in the thread I was going to reply to are:

...

It's an interesting conundrum. There are good reasons and nefarious, for 
such behavior.


Some have questioned my behavior in similar regard - asking why I use 
initials (also used IRL). It is because my first name "David" is/was 
very popular. At a meeting this week there were three of us. Thus, 
"David", "Dave", and "dn" was necessary to distinguish between us.



These mailing-lists all run under the Python Code of Conduct.

This also effects a conundrum. Firstly, that someone abusing others (for 
example) shall be held responsible. Secondly, that in order to hold 
someone responsible, he/she/... must be identifiable.



Personal opinion: if someone is asked a 
question/clarification/sample-code, particularly as a response to their 
own OP, and does not answer; this is at the least rude, and thus 
disrespectful, or at worst grounds for not bothering with them again - 
hardly a 'community' attitude!


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Anonymous email users

2024-06-14 Thread AVI GROSS via Python-list
I notice that in some recent discussions, we have users who cannot be
replied to directly as their email addresses are not valid ones, and I
believe on purpose. Examples in the thread I was going to reply to are:
 
  henha...@devnull.tb
 
  no.email@nospam.invalid
 
 
candycanearter07@candycanearter07.nomail.afraid (user  is
generated from /dev/urandom)
 
I know some here suggest that we only reply to the wider community and they
have a point. But I think there is a role for having some conversations
offline and especially when they are not likely to be wanted, or even
tolerated, by many in the community.
 
Using such fake or invalid emails makes it hard to answer the person
directly or perhaps politely ask them for more info on their request or
discuss unrelated common interests. Worse, when I reply, unless I use
reply-all, my mailer sends to them futilely. When I do the reply-all, I have
to edit out their name or get a rejection.
 
I understand some are concerned over getting email of the junk variety by
any who scan members of forums like this. I can see making a throwaway email
address for such purposes that can be replaced when it gets inundated. But
emails that don't work are a bit irksome to me albeit I assume perfectly
legit for many purposes.
 
The thread I posted in recently is an example where I spent a little time,
just for fun, and wrote a fairly short piece of code (almost a one-liner)
that I might have sent to the OP and not bothered others here with. I
suspect few here understand why there was a request to generate a limited
subset of three-digit numbers. I did suggest an outline of a way it could be
done, perhaps a bit wastefully but compactly. But there is no way to share
that with people who choose not to receive private email except to post
something like this here:
 
import re
[i for i in range(999) if re.match("^[1-4]0[1-3]$",str(i))]
 
*   The internet is a wild place and when it is anonymous, even wilder.
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: in Python: (101 102 103 201 202 203 301 302 303 401 402 403 )

2024-06-14 Thread candycanearter07 via Python-list
Phil Carmody  wrote at 12:01 this Thursday (GMT):
> Paul Rubin  writes:
>> HenHanna  writes:
>>> is there another (simple) way to write this?
>>
>> Yes, but please consider doing these easy exercises yourself instead of
>> fobbing them onto other people.
>
> Hen's probably just an experimental GPT. You, with your limited
> resources, can never train it.
>
> I'd say you can't beat the verbosity, or lack thereof of just plain zsh/bash:
>   $ echo {1,2,3,4}0{1,2,3}
>   101 102 103 201 202 203 301 302 303 401 402 403
>
> Phil


I /think/ you can replace it with {1...4} and {1...3}? I know there is
some syntax for "range of numbers" but I can't remember it exactly.
-- 
user  is generated from /dev/urandom
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

2024-06-14 Thread Yair Eshel via Python-list
Cameron, I'm not really sure I got your point. I've used the "file not
found" exception as an example for a behavior typical on context managers.
This could be a failure to connect to DB, or threads. It also applies to
any kind of possible exception, whether cased by the context manager itself
or the lines inside it. Long story short, this syntax change is as useful
as context managers are

On Fri, 14 Jun 2024, 01:49 Cameron Simpson,  wrote:

> On 13Jun2024 19:44, dieter.mau...@online.de 
> wrote:
> >Why not use:
> >```
> >try:
> >  with open()...
> >...
> >except FileNotFoundError:
> >  ...
> >```
>
> This is exactly what the OP was expressing dissatisfaction with.
>
> I'm -1 on the idea myself - not every combination of things needs
> additional syntactic support, and doing stuff like merging an `except`
> with a `wtih` is bound to introduce some weird corner case, complicating
> its semantics.
>
> Cheers,
> Cameron Simpson 
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

2024-06-13 Thread Cameron Simpson via Python-list

On 13Jun2024 19:44, dieter.mau...@online.de  wrote:

Why not use:
```
try:
 with open()...
   ...
except FileNotFoundError:
 ...
```


This is exactly what the OP was expressing dissatisfaction with.

I'm -1 on the idea myself - not every combination of things needs 
additional syntactic support, and doing stuff like merging an `except` 
with a `wtih` is bound to introduce some weird corner case, complicating 
its semantics.


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


Suggested python feature: allowing except in context maneger

2024-06-13 Thread Dieter Maurer via Python-list
Yair Eshel wrote at 2024-6-13 13:01 +0300:
> ...
>I would like to suggest an alternative syntax, that will, in a sense, apply
>the best of both worlds:
>
>import logging
>with open('sample_data/README.md') as f:
>  print (len(f.read()))
>except FileNotFoundError:
>  logging.error("File not")

Are you aware that in the case of a `FileNotFoundError`
no context manager is created (the context manager is the `f`
in your code).

Why not use:
try:
  with open()...
...
except FileNotFoundError:
  ...


I do not think that your use case requires a `with` extension.



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


Re: Couldn't install numpy on Python 2.7

2024-06-13 Thread Ethan Furman via Python-list

Hey, everyone!

I believe the original question has been answered, and tempers seem to be flaring in sub-threads, so let's call this 
thread done and move on to other interesting topics.


Thank you for your support!

--
~Ethan~
Moderator
--
https://mail.python.org/mailman/listinfo/python-list


Re: Suggested python feature: allowing except in context maneger

2024-06-13 Thread Barry Scott via Python-list



> On 13 Jun 2024, at 11:01, Yair Eshel via Python-list  
> wrote:
> 
> I read this is a good place to give some suggestions for features in
> python.

Best place these days is to raise an idea on https://discuss.python.org/

Beware that this idea has come up in the past and was rejected.

Barry

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


Re: in Python: (101 102 103 201 202 203 301 302 303 401 402 403 )

2024-06-13 Thread Phil Carmody via Python-list
Paul Rubin  writes:
> HenHanna  writes:
>> is there another (simple) way to write this?
>
> Yes, but please consider doing these easy exercises yourself instead of
> fobbing them onto other people.

Hen's probably just an experimental GPT. You, with your limited
resources, can never train it.

I'd say you can't beat the verbosity, or lack thereof of just plain zsh/bash:
  $ echo {1,2,3,4}0{1,2,3}
  101 102 103 201 202 203 301 302 303 401 402 403

Phil
-- 
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Couldn't install numpy on Python 2.7

2024-06-13 Thread Chris Green via Python-list
Chris Angelico  wrote:
> On Thu, 13 Jun 2024 at 10:58,  wrote:
> >
> > Chris,
> >
> > You seem to have perceived an insult that I remain unaware of.
> 
> If you're not aware that you're saying this, then don't say it.
> 
Er, um, that really makes no sense! :-)

How can one not say something that one isn't aware of saying?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Suggested python feature: allowing except in context maneger

2024-06-13 Thread Yair Eshel via Python-list
Hello. I read this is a good place to give some suggestions for features in
python. If not, please let me know.

This is an example of a code I normally use in my everyday work:
import logging
try:
  with open('sample_data/READM.md') as f:
print (len(f.read()))
except FileNotFoundError:
  logging.error("File not found")


As you can see I have 2 levels of indentation, which can add some pain to
the work with the context manager. This code without context manager, can
be replaced by this code:

import logging
try:
  f = open('sample_data/READM.md') as f:
  print (len(f.read()))
except FileNotFoundError:
  logging.error("File not found")
finally:
  f.close()

And while this offers less indentations, it skips the usage of the very
handy context manager.

I would like to suggest an alternative syntax, that will, in a sense, apply
the best of both worlds:

import logging
with open('sample_data/README.md') as f:
  print (len(f.read()))
except FileNotFoundError:
  logging.error("File not")

As "with" applies the behavior of the "try / finally" it feels like a
natural part of this syntax. This could provide a cleaner code.
If this idea is accepted, there are several things that need to be
discussed, like what to do with "else" or "finally" statement following a
context manager. I'm not sure about the proper way to handle this.

With hopes for an even more readable future
Yair
-- 
בברכה,
יאיר אשל כהנסקי
מתכנת וטכנאי מילים
https://www.inspect-element.net/YouAreHere/#/start
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 10:58,  wrote:
>
> Chris,
>
> You seem to have perceived an insult that I remain unaware of.

If you're not aware that you're saying this, then don't say it.

> I looked up FUD and sharply disagree with suggestions I am trying to somehow
> cause Fear, Uncertainty or Doubt. I simply asked if another such update ...
> as a hypothetical. Had I asked what impact Quantum Computers might have on
> existing languages, would that also be FUD, or just a speculation in a
> discussion.

What DID you intend by your comments? Were you trying to imply that
work spent upgrading to Python 3 would have to be redone any day now
when this hypothetical massively-incompatible Python 4 is released? Or
what? What WERE you trying to say?

If you don't understand how damaging it can be to say that sort of
thing, **don't say it**. Otherwise, expect responses like this.

I *detest* the attitude that you can make vague disparaging comments
and then hide behind claims that you had no idea how damaging you were
being.

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Chris,

You seem to have perceived an insult that I remain unaware of.

I have no special knowledge, like you do, of plans made for changes to the
pthon language and implementation.

I was asking a hypothetical question about what some users would do if
python came out with a newer major version. I have seen people often wait
until some software that tries to get updated too frequently makes multiple
updates and then finally give in and skip the intermediates.

I wondered if something like a version 4.0 might get people still using
version 2 might finally come around and also if some version 3 users would
not be thrilled with something not stable enough.

I have no favorite ideas here and can see a balance between adding features
or fixing flaws and on the other side, not discomfiting many and especially
when in many cases, the original people who wrote software are no longer
there nor budgets to pay for changes.

I looked up FUD and sharply disagree with suggestions I am trying to somehow
cause Fear, Uncertainty or Doubt. I simply asked if another such update ...
as a hypothetical. Had I asked what impact Quantum Computers might have on
existing languages, would that also be FUD, or just a speculation in a
discussion.

Either way, I am taking any further discussion along these lines offline and
will not continue here.

-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Wednesday, June 12, 2024 7:23 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On Thu, 13 Jun 2024 at 09:20,  wrote:
> My point was that version 4 COULD HAPPEN one day and I meant INCOMPATIBLE
> version not 4. Obviously we can make a version 4 that is not incompatible
> too.

This is still FUD. Back your words with something, or stop trying to
imply that there's another incompatible change just around the corner.

Do you realise how insulting you are being to the developers of Python
by these implications?

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

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 09:20,  wrote:
> My point was that version 4 COULD HAPPEN one day and I meant INCOMPATIBLE
> version not 4. Obviously we can make a version 4 that is not incompatible
> too.

This is still FUD. Back your words with something, or stop trying to
imply that there's another incompatible change just around the corner.

Do you realise how insulting you are being to the developers of Python
by these implications?

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Chris,

I don't want to get off message and debate whether my "jokes" are jokes, let
alone funny. Obviously, they often aren't.

What I meant by joking here does seem relevant. As the years pass, there can
come a time when it is suggested that a language (any language including
python) is no longer useful to many in the community as it has not kept up
with changes in the industry or whatever. Suggestions are made for changes
and additions that that not be backward compatible. They can be somewhat
minor things like new keywords that have not been reserved and where
programs that exist might be scanned for use of that keyword, and you simply
replace those names with was_keyword or something and the programs will
generally  run.  But there can be major changes too and there can be a
choice to just create a new language that has some similarities to python 3
(or PERL version whatever) or just name it the same but a version higher
much like has happened.

My point was that version 4 COULD HAPPEN one day and I meant INCOMPATIBLE
version not 4. Obviously we can make a version 4 that is not incompatible
too.

I have experience in other languages where disconnects happen at various
levels. Some functions in a collection such as a package are removed perhaps
to replace them with a more abstract version that does much more. Do you
remove the old one immediately or do you make a new name for the new one and
perhaps in some way mark the old one for deprecation with a pointer to the
new one to be used as soon as reasonable? I have seen many approaches. I
have seen entire packages yanked. I have seen parts that used to be in the
distribution as if built-in and then taken out and vice versa.

The point is you do not need a 4.0 to be incompatible. The incompatibility,
or need to change, can happen anytime when you are importing things like
numpy which is released whenever they want to and is not part of the python
distribution. Also, as we have seen at times, other modules you may have
imported, in some languages, can mask names you are using in your program
that you may not even be aware are there. Much can go wrong with software
and keeping current can also give you problems when something released may
have inadvertent changes or bugs.

So much of our code is voluntary and as noted earlier, some python
variants/distributions simply may not have anyone interested in keeping them
up to date. You as a user, take your chances.


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Wednesday, June 12, 2024 5:52 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On Thu, 13 Jun 2024 at 07:36,  wrote:
> But if the goal was to deprecate python 2 and in some sense phase it out,
it
> is perhaps not working well for some. Frankly, issuing so many updates
like
> 2.7 and including backporting of new features has helped make it possible
to
> delay any upgrade.

The goal was to improve Python. I don't think anyone's ever tried to
"kill off" Python 2 - not in the sense of stopping people from using
it - but there haven't been any changes, not even security fixes, in
over four years.

> And, yes, I was KIDDING about python 4. I am simply suggesting that there
> may well be a time that another shift happens that may require another
> effort to get people on board a new and perhaps incompatible setup.

Kidding, eh? It sure sounded like you were trying to imply that there
would inevitably be another major breaking change. It definitely
smelled like FUD.

Maybe your jokes just aren't funny.

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

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Oscar Benjamin via Python-list
On Wed, 12 Jun 2024 at 23:52, Greg Ewing via Python-list
 wrote:
> On 13/06/24 10:09 am, Chris Angelico wrote:
>  > So if anyone
>  > actually does need to use pip with Python 2.7, they probably need to
>  > set up a local server
>
> You should also be able to download a .tar.gz from PyPI and use pip
> to install that. Although you'll have to track down the dependencies
> yourself in that case.

It is almost certainly better to download the wheel (.whl) file rather
than the sdist (.tar.gz) file. Building NumPy from source needs not
just compilers etc but also you first need to build/install a BLAS
library.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 08:46, Oscar Benjamin via Python-list
 wrote:
> I don't know much about SSL and related networking things especially
> on Windows. I would be surprised if pip on old Python can't install
> from current PyPI though. I imagine that something strange has
> happened like a new version of pip running on an old version of Python
> or old Python on new OS (or old PyCharm...).
>
> There is no problem using Python 2.7 with pip and PyPI on this Linux
> machine but I guess it has a newer SSL library provided by the OS:

Sadly, I would NOT be surprised if this is indeed a problem on
Windows. You're exactly right - on Linux, it can use a newer SSL
library from the OS. Of course, this does assume that you've updated
your OS, which is far from a guarantee, but since this has security
implications there's a good chance you can update it while retaining a
legacy system.

On Thu, 13 Jun 2024 at 08:51, Greg Ewing via Python-list
 wrote:
> On 13/06/24 10:09 am, Chris Angelico wrote:
>  > So if anyone
>  > actually does need to use pip with Python 2.7, they probably need to
>  > set up a local server
>
> You should also be able to download a .tar.gz from PyPI and use pip
> to install that. Although you'll have to track down the dependencies
> yourself in that case.

Also a possibility; in my opinion, losing dependency management is too
big a cost, so I would be inclined to set up a local server. But then,
I would be using a newer SSL library and not have the problem in the
first place.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Greg Ewing via Python-list

On 13/06/24 4:31 am, avi.e.gr...@gmail.com wrote:

It seems Microsoft is having a problem where something lik 2/3 of Windows
users have not upgraded from Windows 10 after many years


At least Python 3 is a clear improvement over Python 2 in many ways.
Whereas the only thing Microsoft seems to have done with Windows in
recent times is change it in ways that nobody wants, so there is
understandable resistance to upgrading even if it's possible.

On 13/06/24 10:09 am, Chris Angelico wrote:
> So if anyone
> actually does need to use pip with Python 2.7, they probably need to
> set up a local server

You should also be able to download a .tar.gz from PyPI and use pip
to install that. Although you'll have to track down the dependencies
yourself in that case.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Oscar Benjamin via Python-list
On Wed, 12 Jun 2024 at 23:11, Chris Angelico via Python-list
 wrote:
>
> On Thu, 13 Jun 2024 at 07:57, Oscar Benjamin via Python-list
>  wrote:
> > They are seeing a warning that explicitly says "You can upgrade to a
> > newer version of Python to solve this". I don't know whether that SSL
> > warning is directly connected to pip not finding any versions of numpy
> > but with the available information so far that seems like the first
> > thing to consider.
>
> I think it is; AIUI, with an ancient SSL library, pip is unable to
> download packages safely from the current pypi server. So if anyone
> actually does need to use pip with Python 2.7, they probably need to
> set up a local server, using older encryption protocols (which should
> therefore NOT be made accessible to the internet). Since pip can't
> contact the upstream pypi, there's no available numpy for it to
> install.

I don't know much about SSL and related networking things especially
on Windows. I would be surprised if pip on old Python can't install
from current PyPI though. I imagine that something strange has
happened like a new version of pip running on an old version of Python
or old Python on new OS (or old PyCharm...).

There is no problem using Python 2.7 with pip and PyPI on this Linux
machine but I guess it has a newer SSL library provided by the OS:

$ pip install numpy
DEPRECATION: Python 2.7 reached the end of its life on January 1st,
2020. Please upgrade your Python as Python 2.7 is no longer
maintained. pip 21.0 will drop support for Python 2.7 in January 2021.
More details about Python 2 support in pip can be found at
https://pip.pypa.io/en/latest/development/release-process/#python-2-support
pip 21.0 will remove support for this functionality.
Collecting numpy
  Downloading numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
 || 17.0 MB 14.3 MB/s
Installing collected packages: numpy
Successfully installed numpy-1.16.6

If it is actually the case that pip on Python 2.7 (on Windows) cannot
download from PyPI then an easier option rather than creating a local
server would just be to download the numpy wheels from PyPI using a
browser:

  https://pypi.org/project/numpy/1.15.4/#files

Then you can do

   pip install .\numpy-1.15.4-cp27-none-win_amd64.whl

Using a newer version of Python is still my primary suggestion though.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 07:57, Oscar Benjamin via Python-list
 wrote:
> They are seeing a warning that explicitly says "You can upgrade to a
> newer version of Python to solve this". I don't know whether that SSL
> warning is directly connected to pip not finding any versions of numpy
> but with the available information so far that seems like the first
> thing to consider.

I think it is; AIUI, with an ancient SSL library, pip is unable to
download packages safely from the current pypi server. So if anyone
actually does need to use pip with Python 2.7, they probably need to
set up a local server, using older encryption protocols (which should
therefore NOT be made accessible to the internet). Since pip can't
contact the upstream pypi, there's no available numpy for it to
install.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Oscar Benjamin via Python-list
On Wed, 12 Jun 2024 at 22:38, AVI GROSS via Python-list
 wrote:
>
> The discussion though was about a specific OP asking if they can fix their
> problem. One solution being suggested is to fix a deeper problem and simply
> make their code work with a recent version of python 3.

The OP has not replied with any explanation as to why they are using
Python 2.7 and has not said whether they have any existing code that
only works with Python 2.7. It is unclear at this point whether there
is any reason that they shouldn't just install a newer version of
Python.

They are seeing a warning that explicitly says "You can upgrade to a
newer version of Python to solve this". I don't know whether that SSL
warning is directly connected to pip not finding any versions of numpy
but with the available information so far that seems like the first
thing to consider.

It is entirely reasonable to start by suggesting to use a newer
version of Python until some reason is given for not doing that.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 07:36,  wrote:
> But if the goal was to deprecate python 2 and in some sense phase it out, it
> is perhaps not working well for some. Frankly, issuing so many updates like
> 2.7 and including backporting of new features has helped make it possible to
> delay any upgrade.

The goal was to improve Python. I don't think anyone's ever tried to
"kill off" Python 2 - not in the sense of stopping people from using
it - but there haven't been any changes, not even security fixes, in
over four years.

> And, yes, I was KIDDING about python 4. I am simply suggesting that there
> may well be a time that another shift happens that may require another
> effort to get people on board a new and perhaps incompatible setup.

Kidding, eh? It sure sounded like you were trying to imply that there
would inevitably be another major breaking change. It definitely
smelled like FUD.

Maybe your jokes just aren't funny.

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Chris,

Since you misunderstood, my statement was that making an incompatible set of
changes to create Python 3 in the first place was a decision made by some
and perhaps not one that thrilled others who already had an embedded base of
programs or ones in the pipeline that would need much work to become
comparable.

And, of course, users of a program who continued to use python 2, also have
to find a way to ...

But if the goal was to deprecate python 2 and in some sense phase it out, it
is perhaps not working well for some. Frankly, issuing so many updates like
2.7 and including backporting of new features has helped make it possible to
delay any upgrade.

And, yes, I was KIDDING about python 4. I am simply suggesting that there
may well be a time that another shift happens that may require another
effort to get people on board a new and perhaps incompatible setup. I have
seen things like that happen in multiple phases including phases where the
new tools are not an upgrade, but brand new. An example might be if
accompany decided to switch to another existing language because they want
better error detection and faster execution or new features that may take
forever to arrive in what they are using or that supply various services by
humans to help them.

The discussion though was about a specific OP asking if they can fix their
problem. One solution being suggested is to fix a deeper problem and simply
make their code work with a recent version of python 3. But another solution
could be to step backward to a version of python 2 that still has numpy
support, or as was suggested, find out what other modules they are using are
interfering with the program being satisfied with the last version of numpy
being used and perhaps find a way to get ...

In the long run, though, continuing with python 2 will likely cause ever
more such headaches if you want the latest and greatest of things like
numpy.


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico via Python-list
Sent: Wednesday, June 12, 2024 2:00 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On Thu, 13 Jun 2024 at 03:41, AVI GROSS via Python-list
 wrote:
>
> Change is hard even when it may be necessary.
>
> The argument often is about whether some things are necessary or not.
>
> Python made a decision but clearly not a unanimous one.

What decision? To not release any new versions of Python 2? That isn't
actually the OP's problem here - the Python interpreter runs just
fine. But there's no numpy build for the OP's hardware and Python 2.7.

So if you want to complain about Python 2.7 being dead, all you have
to do is go through all of the popular packages and build binaries for
all modern computers. If that sounds easy, go ahead and do it; if it
sounds hard, realise that open source is not a democracy, and you
can't demand that other people do more and more and more unpaid work
just because you can't be bothered upgrading your code.

> My current PC was not upgradable because of the new hardware requirement
> Microsoft decided was needed for Windows 11.

Yes, and that's a good reason to switch to Linux for the older computer.

> I mention this in the context of examples of why even people who are
fairly
> knowledgeable do not feel much need to fix what does not feel broken.

It doesn't feel broken, right up until it does. The OP has discovered
that it *IS* broken. Whining that it doesn't "feel broken" is nonsense
when it is, in fact, not working.

> When is Python 4 coming?

Is this just another content-free whine, or are you actually curious
about the planned future of Python? If the latter, there is **PLENTY**
of information out there and I don't need to repeat it here.

Please don't FUD.

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

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 06:55, Thomas Passin via Python-list
 wrote:
> The project cannot move to a Python-3 compatible version because Jython
> 3.xx doesn't exist and may never exist.  The saving grace is that my
> project doesn't have to use packages like numpy, scipy, and so forth.

Exactly. If you don't need to ALSO use something newer, there's
nothing stopping you from continuing with the old version. And that's
fine! As long as you're okay with not getting updates, you're welcome
to do whatever you like - including running Windows 98 on an ancient
PC and editing your documents on that. (Yes, I know someone who did
that, long after Win 98 was dead to most of us.)

> Thunderbird and everything else worked perfectly for me during that
> week.  True, there were a few Windows-only programs I missed, but I used
> other similar programs even if I didn't like them as much.

It's true. And there ARE solutions to that, although it's a bit rough
trying to run them on low hardware (Wine works nicely for some
programs, less so for others; VirtualBox is really not gonna be happy
with a small fraction of your limited RAM). But if your needs are
simple, even a crazily low-end system is sufficient.

> It's amazing
> how little resources Linux installs need, even with a GUI.  Of course,
> 4GB RAM is limiting whether you are on Linux or Windows - you can't
> avoid shuffling all those GUI bits around - but with a little care it
> worked great.  And with the external SSD the laptop was a lot snappier
> than it ever was when it was new.

One of the big differences with Linux is that you have a choice of
desktop environments, from "none" (just boot straight into a terminal)
on up. Some of them are a bit of a compromise in terms of how well you
can get your work done, but let's say you had an even MORE ancient
system with maybe one gig of memory... I'd rather have a super-light
desktop environment even if it doesn't have everything I'm normally
accustomed to!

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Thomas Passin via Python-list

On 6/12/2024 1:59 PM, Chris Angelico via Python-list wrote:

On Thu, 13 Jun 2024 at 03:41, AVI GROSS via Python-list
 wrote:


Change is hard even when it may be necessary.

The argument often is about whether some things are necessary or not.

Python made a decision but clearly not a unanimous one.


What decision? To not release any new versions of Python 2? That isn't
actually the OP's problem here - the Python interpreter runs just
fine. But there's no numpy build for the OP's hardware and Python 2.7.

So if you want to complain about Python 2.7 being dead, all you have
to do is go through all of the popular packages and build binaries for
all modern computers. If that sounds easy, go ahead and do it; if it
sounds hard, realise that open source is not a democracy, and you
can't demand that other people do more and more and more unpaid work
just because you can't be bothered upgrading your code.


I support a Tomcat project that has some java code and most of the code 
is for Jython 2.7.  Jython 2.7 is approximately on a par with Python 
2.7.  Any Python-only code from the standard library will probably run, 
but of course any C extensions cannot.  The nice thing about using 
Jython in a java environment is that it can call any java object, and 
java code can call Jython objects and their methods.


The project cannot move to a Python-3 compatible version because Jython 
3.xx doesn't exist and may never exist.  The saving grace is that my 
project doesn't have to use packages like numpy, scipy, and so forth. 
Also, the project is very mature and almost certainly won't need to 
create functionality such packages would enable.  It would be nice to be 
able to use some newer parts of the standard library, but there it is. 
Jython does support "from __future__ import" and I make use of that for 
the print function and the like.



My current PC was not upgradable because of the new hardware requirement
Microsoft decided was needed for Windows 11.


Yes, and that's a good reason to switch to Linux for the older computer.


I have a 2012-vintage laptop that in modern terms has a very small 
supply of RAM and a very slow hard drive. When my newer Windows 10 
computer was going to be out of service for a while, I put a Linux 
distro on an external SSD and copied things I needed to work on to it, 
including my Thunderbird email profile directory.


Thunderbird and everything else worked perfectly for me during that 
week.  True, there were a few Windows-only programs I missed, but I used 
other similar programs even if I didn't like them as much.  It's amazing 
how little resources Linux installs need, even with a GUI.  Of course, 
4GB RAM is limiting whether you are on Linux or Windows - you can't 
avoid shuffling all those GUI bits around - but with a little care it 
worked great.  And with the external SSD the laptop was a lot snappier 
than it ever was when it was new.



I mention this in the context of examples of why even people who are fairly
knowledgeable do not feel much need to fix what does not feel broken.


It doesn't feel broken, right up until it does. The OP has discovered
that it *IS* broken. Whining that it doesn't "feel broken" is nonsense
when it is, in fact, not working.


When is Python 4 coming?


Is this just another content-free whine, or are you actually curious
about the planned future of Python? If the latter, there is **PLENTY**
of information out there and I don't need to repeat it here.

Please don't FUD.

ChrisA


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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Thu, 13 Jun 2024 at 03:41, AVI GROSS via Python-list
 wrote:
>
> Change is hard even when it may be necessary.
>
> The argument often is about whether some things are necessary or not.
>
> Python made a decision but clearly not a unanimous one.

What decision? To not release any new versions of Python 2? That isn't
actually the OP's problem here - the Python interpreter runs just
fine. But there's no numpy build for the OP's hardware and Python 2.7.

So if you want to complain about Python 2.7 being dead, all you have
to do is go through all of the popular packages and build binaries for
all modern computers. If that sounds easy, go ahead and do it; if it
sounds hard, realise that open source is not a democracy, and you
can't demand that other people do more and more and more unpaid work
just because you can't be bothered upgrading your code.

> My current PC was not upgradable because of the new hardware requirement
> Microsoft decided was needed for Windows 11.

Yes, and that's a good reason to switch to Linux for the older computer.

> I mention this in the context of examples of why even people who are fairly
> knowledgeable do not feel much need to fix what does not feel broken.

It doesn't feel broken, right up until it does. The OP has discovered
that it *IS* broken. Whining that it doesn't "feel broken" is nonsense
when it is, in fact, not working.

> When is Python 4 coming?

Is this just another content-free whine, or are you actually curious
about the planned future of Python? If the latter, there is **PLENTY**
of information out there and I don't need to repeat it here.

Please don't FUD.

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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
Change is hard even when it may be necessary.

The argument often is about whether some things are necessary or not.

Python made a decision but clearly not a unanimous one.

My current PC was not upgradable because of the new hardware requirement
Microsoft decided was needed for Windows 11. I bought a new one a while back
and turned it on in another room and then set it aside because replacing the
current one in the current position will be a pain, especially with getting
all my wires and so on, and since I do not want to use a full copy of my
data including many obsolete things, that will be another pain to get what I
need, if I can remember. Complicating issues also include licenses for
things in fixed amounts and the likelihood of messing up the
hardware/software I have that records shows from cable to my hard disk,
possibly needing to buy a new one.

I mention this in the context of examples of why even people who are fairly
knowledgeable do not feel much need to fix what does not feel broken.

I have wondered if instead of doing what Microsoft wants, if maybe switching
to Linux of some kinds makes as much sense. I suspect some may simply
upgrade to an Apple product.

And think of all the PC's that may effectively be discarded as they may not
even be usable if donated.

We live in a rapidly developing age and hence one with regularly and
irregularly scheduled rounds of obsolescence.

When is Python 4 coming?

-Original Message-
From: Python-list  On
Behalf Of MRAB via Python-list
Sent: Wednesday, June 12, 2024 12:56 PM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On 2024-06-12 17:31, AVI GROSS via Python-list wrote:
> I am sure there is inertia to move from an older product and some people
> need a reason like this where the old becomes untenable.
> 
> It seems Microsoft is having a problem where something lik 2/3 of Windows
> users have not upgraded from Windows 10 after many years and have set a
> deadline in a year or so for stopping updates. In that case, hardware was
a
> concern for some as Windows 11 did not work on their machines. With
> upgrading python, the main concern is having to get someone to examine old
> code and try to make it compatible.
> 
In the case of Windows, my PC is over 10 years old yet performs 
perfectly well for my needs. It can't run Windows 11. Therefore, I'm in 
the process of migrating to Linux, and I still have over a year to 
achieve that before support ends.

> But anyone doing new code in Python 2 in recent years should ...
> 
Indeed...

> -Original Message-
> From: Python-list 
On
> Behalf Of Gordinator via Python-list
> Sent: Wednesday, June 12, 2024 10:19 AM
> To: python-list@python.org
> Subject: Re: Couldn't install numpy on Python 2.7
> 
> On 12/06/2024 12:30, marc nicole wrote:
>> I am trying to install numpy library on Python 2.7.15 in PyCharm but the
>> error message I get is:
>> 
>> ERROR: Could not find a version that satisfies the requirement numpy
(from
>>> versions: none)
>>> ERROR: No matching distribution found for numpy
>>> c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
>>> InsecurePlatformWarning: A true SSLContext object is not available. This
>>> prevents urllib3 fro
>>> m configuring SSL appropriately and may cause certain SSL connections to
>>> fail. You can upgrade to a newer version of Python to solve this. For
> more
>>> information, see
>>>
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
>>>InsecurePlatformWarning,
>> 
>> 
>> Any clues?
> 
> Why are you using Python 2? Come on, it's been 16 years. Ya gotta move
> on at some point.

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

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread MRAB via Python-list

On 2024-06-12 17:31, AVI GROSS via Python-list wrote:

I am sure there is inertia to move from an older product and some people
need a reason like this where the old becomes untenable.

It seems Microsoft is having a problem where something lik 2/3 of Windows
users have not upgraded from Windows 10 after many years and have set a
deadline in a year or so for stopping updates. In that case, hardware was a
concern for some as Windows 11 did not work on their machines. With
upgrading python, the main concern is having to get someone to examine old
code and try to make it compatible.

In the case of Windows, my PC is over 10 years old yet performs 
perfectly well for my needs. It can't run Windows 11. Therefore, I'm in 
the process of migrating to Linux, and I still have over a year to 
achieve that before support ends.



But anyone doing new code in Python 2 in recent years should ...


Indeed...


-Original Message-
From: Python-list  On
Behalf Of Gordinator via Python-list
Sent: Wednesday, June 12, 2024 10:19 AM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On 12/06/2024 12:30, marc nicole wrote:

I am trying to install numpy library on Python 2.7.15 in PyCharm but the
error message I get is:

ERROR: Could not find a version that satisfies the requirement numpy (from

versions: none)
ERROR: No matching distribution found for numpy
c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
InsecurePlatformWarning: A true SSLContext object is not available. This
prevents urllib3 fro
m configuring SSL appropriately and may cause certain SSL connections to
fail. You can upgrade to a newer version of Python to solve this. For

more

information, see
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
   InsecurePlatformWarning,



Any clues?


Why are you using Python 2? Come on, it's been 16 years. Ya gotta move
on at some point.


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


RE: Couldn't install numpy on Python 2.7

2024-06-12 Thread AVI GROSS via Python-list
I am sure there is inertia to move from an older product and some people
need a reason like this where the old becomes untenable.

It seems Microsoft is having a problem where something lik 2/3 of Windows
users have not upgraded from Windows 10 after many years and have set a
deadline in a year or so for stopping updates. In that case, hardware was a
concern for some as Windows 11 did not work on their machines. With
upgrading python, the main concern is having to get someone to examine old
code and try to make it compatible. 

But anyone doing new code in Python 2 in recent years should ...

-Original Message-
From: Python-list  On
Behalf Of Gordinator via Python-list
Sent: Wednesday, June 12, 2024 10:19 AM
To: python-list@python.org
Subject: Re: Couldn't install numpy on Python 2.7

On 12/06/2024 12:30, marc nicole wrote:
> I am trying to install numpy library on Python 2.7.15 in PyCharm but the
> error message I get is:
> 
> ERROR: Could not find a version that satisfies the requirement numpy (from
>> versions: none)
>> ERROR: No matching distribution found for numpy
>> c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
>> InsecurePlatformWarning: A true SSLContext object is not available. This
>> prevents urllib3 fro
>> m configuring SSL appropriately and may cause certain SSL connections to
>> fail. You can upgrade to a newer version of Python to solve this. For
more
>> information, see
>> https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
>>InsecurePlatformWarning,
> 
> 
> Any clues?

Why are you using Python 2? Come on, it's been 16 years. Ya gotta move 
on at some point.
-- 
https://mail.python.org/mailman/listinfo/python-list

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Gordinator via Python-list

On 12/06/2024 12:30, marc nicole wrote:

I am trying to install numpy library on Python 2.7.15 in PyCharm but the
error message I get is:

ERROR: Could not find a version that satisfies the requirement numpy (from

versions: none)
ERROR: No matching distribution found for numpy
c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
InsecurePlatformWarning: A true SSLContext object is not available. This
prevents urllib3 fro
m configuring SSL appropriately and may cause certain SSL connections to
fail. You can upgrade to a newer version of Python to solve this. For more
information, see
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
   InsecurePlatformWarning,



Any clues?


Why are you using Python 2? Come on, it's been 16 years. Ya gotta move 
on at some point.

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


Re: Couldn't install numpy on Python 2.7

2024-06-12 Thread Chris Angelico via Python-list
On Wed, 12 Jun 2024 at 21:32, marc nicole via Python-list
 wrote:
>
> I am trying to install numpy library on Python 2.7.15 in PyCharm but the
> error message I get is:
>
> You can upgrade to a newer version of Python to solve this.

The answer is right there in the error message.

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


Couldn't install numpy on Python 2.7

2024-06-12 Thread marc nicole via Python-list
I am trying to install numpy library on Python 2.7.15 in PyCharm but the
error message I get is:

ERROR: Could not find a version that satisfies the requirement numpy (from
> versions: none)
> ERROR: No matching distribution found for numpy
> c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164:
> InsecurePlatformWarning: A true SSLContext object is not available. This
> prevents urllib3 fro
> m configuring SSL appropriately and may cause certain SSL connections to
> fail. You can upgrade to a newer version of Python to solve this. For more
> information, see
> https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
>   InsecurePlatformWarning,


Any clues?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-11 Thread HenHanna via Python-list

On 6/10/2024 6:29 AM, Rob Cliffe wrote:

import itertools

def chunk1(seq):
     return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]

def chunk2(seq):
     return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]

s='aaabbaa'
print(chunk1(s))
print(chunk2(s))
###
Program output:
['aaa', 'bb', '', 'aa']
[('a', 3), ('b', 2), ('c', 4), ('a', 2)]

Rob Cliffe




thank you...   OMG... For 10 minutes... i was SO mystified by
the question...
How can this code work??? ,  when it's
  > def chunk1(seq):
 and it's  [s]   within the def-body ?

it seemed as if the Compiler was doing a DWIM (Do what i mean)  trick.




On 09/06/2024 22:20, HenHanna via Python-list wrote:


Chunk, ChunkC -- nice simple way(s) to write these in Python?


(Chunk  '(a a   b    a a a   b b))
    ==> ((a a) (b)  (a a a) (b b))


(Chunk  '(a a a a   b   c c   a a   d   e e e e))
    ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))


(Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
    ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))

_

(ChunkC  '(a a   b b b))
 ==> ((a 2)  (b 3))

(ChunkC  '(a a   b  a a a   b b))
 ==> ((a 2)  (b 1)  (a 3)   (b 2))




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


  1   2   3   4   5   6   7   8   9   10   >