Re: best GUI library for vector drawing program

2007-08-20 Thread Mats
If you want to stay within Tcl/Tk you could take a look at my tkpath
package:
http://tclbitprint.sf.net/
and shots:
http://tclbitprint.sourceforge.net/tkpath/quartz/index.html
http://tclbitprint.sourceforge.net/tkpath/gdiplus/index.html
http://tclbitprint.sourceforge.net/tkpath/cairo/index.html

Mats

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


Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
A moderator who calls himself “animuson” on Stack Overflow doesn’t
want to face the truth. He has deleted all my postings regarding Python
regular expression matching being extremely slow compared to Perl.
Additionally my account has been suspended for 7 days. Such a dickwad.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>> want to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>> Additionally my account has been suspended for 7 days. Such a dickwad.
>
> And this matters... how? What are we supposed to do about it? We are
> not the Python Secret Underground, which emphatically does not exist.
>
> ChrisA

You aren’t supposed to do squat about it. I just wanted to mention it
to the Python evangelists, who need to see the light.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Steven D'Aprano  wrote:
> On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
>
>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>>> to face the truth. He has deleted all my postings regarding Python
>>> regular expression matching being extremely slow compared to Perl.
>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>
>> And this matters... how? What are we supposed to do about it? We are not
>> the Python Secret Underground, which emphatically does not exist.
>
> Of course not, because if it did 

Because if it did what? :p

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>> want to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>> Additionally my account has been suspended for 7 days. Such a dickwad.
>
> And this matters... how? What are we supposed to do about it? We are
> not the Python Secret Underground, which emphatically does not exist.
>
> ChrisA

I fear you don’t even know what a regular expression is. Then this of
course won’t affect you whatsoever.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:32 PM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>>> want to face the truth. He has deleted all my postings regarding Python
>>>> regular expression matching being extremely slow compared to Perl.
>>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>>
>>> And this matters... how? What are we supposed to do about it? We are
>>> not the Python Secret Underground, which emphatically does not exist.
>>>
>>> ChrisA
>>
>> You aren’t supposed to do squat about it. I just wanted to mention it
>> to the Python evangelists, who need to see the light.
>
> Your post hits me squarely between the eyes, leaving an "Uhh?"-shaped hole.
>
> ChrisA

I fear you don’t even know what a regular expression is. Then this will
of course not affect you.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:33 PM, Mats Peterson  wrote:
>> Steven D'Aprano  wrote:
>>> On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
>>>
>>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>>>>> to face the truth. He has deleted all my postings regarding Python
>>>>> regular expression matching being extremely slow compared to Perl.
>>>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>>>
>>>> And this matters... how? What are we supposed to do about it? We are not
>>>> the Python Secret Underground, which emphatically does not exist.
>>>
>>> Of course not, because if it did
>>
>> Because if it did what? :p
>
> Then they would have full control of this list and what gets pos

Ahhh so this is pos, right? Telling the truth? Interesting.

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:33 PM, Mats Peterson  wrote:
>> Steven D'Aprano  wrote:
>>> On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
>>>
>>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>>>>> to face the truth. He has deleted all my postings regarding Python
>>>>> regular expression matching being extremely slow compared to Perl.
>>>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>>>
>>>> And this matters... how? What are we supposed to do about it? We are not
>>>> the Python Secret Underground, which emphatically does not exist.
>>>
>>> Of course not, because if it did
>>
>> Because if it did what? :p
>
> Then they would have full control of this list and what gets pos

Have you ever compared the regular expression performance between Perl
and Python? If not, keep quiet.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:42 PM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>>> want to face the truth. He has deleted all my postings regarding Python
>>>> regular expression matching being extremely slow compared to Perl.
>>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>>
>>> And this matters... how? What are we supposed to do about it? We are
>>> not the Python Secret Underground, which emphatically does not exist.
>>>
>>> ChrisA
>>
>> I fear you don’t even know what a regular expression is. Then this of
>> course won’t affect you whatsoever.
>
> I know what regular expressions are. I've used them in Perl, PHP,
> JavaScript, Python, C++, Pike, and numerous text editors (which may
> have been backed by one of the above languages, or may have been
> something else). Doesn't change the fact that I have no idea what the
> significance is of your post.
>
> ChrisA

You do? And you haven't noticed the inferior performance of regular
expressions in Python compared to Perl? Then you obviously haven't
used them a lot.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Ian Kelly  wrote:
> On Wed, Jul 10, 2013 at 2:42 AM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>>> want to face the truth. He has deleted all my postings regarding Python
>>>> regular expression matching being extremely slow compared to Perl.
>>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>>
>>> And this matters... how? What are we supposed to do about it? We are
>>> not the Python Secret Underground, which emphatically does not exist.
>>>
>>> ChrisA
>>
>> I fear you don’t even know what a regular expression is. Then this of
>> course won’t affect you whatsoever.
>
> Troll.  A quick search of my Gmail archives turns up 18 threads in
> which Chris has used the phrase "regular expression".

Not a troll. It's just hard to convince Python users that their beloved
language would have inferior regular expression performance to Perl.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Ian Kelly  wrote:
> On Wed, Jul 10, 2013 at 2:46 AM, Mats Peterson  wrote:
>>> Then they would have full control of this list and what gets pos
>>
>> Ahhh so this is pos, right? Telling the truth? Interesting.
>
> I don't know what you mean by that, but since the joke appears to have
> flown over your head, I'll explain it.  Steven's "pos" was clearly
> meant to be the word "posted", before his sentence got cut off by the
> Python Secret Underground.

Being snotty, are we?

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Antoon Pardon  wrote:
> Op 10-07-13 11:03, Mats Peterson schreef:
>> Not a troll. It's just hard to convince Python users that their beloved
>> language would have inferior regular expression performance to Perl.
>
> All right, you have convinced me. Now what? Why should I care?
>

Right. Why should you. And who cares about you?

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Joshua Landau  wrote:
> On 10 July 2013 08:55, Mats Peterson  wrote:
>> . [anumuson from Stack Overflow] has deleted all
>> my postings regarding Python regular expression matching being
>> extremely slow compared to Perl. Additionally my account has been
>> suspended for 7 days. .
>
> Whilst I don't normally respond to trolls, I'm actually curious.
>
> Do you have any non-trivial, properly benchmarked real-world examples
> that this affects, remembering to use full Unicode support in Perl (as
> Python has it by default)?
>
> Remember to try on both major CPython versions, and PyPy -- all of
> which are in large-scale usage. Remember not just to use the builtin
> re module, as most people also use https://pypi.python.org/pypi/regex
> and https://code.google.com/p/re2/ when they are appropriate, so
> pathological cases for re aren't actually a concern anyone cares
> about.
>
> If you actually can satisfy these basic standards for a comparison (as
> I'm sure any competent person with so much bravo could) I'd be willing
> to converse with you. I'd like to see these results where Python compares
> as "extremely slow". Note that, by your own wording, a 30% drop is irrelevant.

I haven't provided a "real-world" example, since I expect you Python
Einsteins to be able do an A/B test between Python and Perl yourselves 
(provided you know Perl, of course, which I'm afraid is not always the
case). And why would I use any "custom" version of Python, when I don't
have to do that with Perl?

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Steven D'Aprano  wrote:
> On Wed, 10 Jul 2013 07:55:05 +0000, Mats Peterson wrote:
>
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>> to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>
> That's by design. We don't want to make the same mistake as Perl, where 
> every problem is solved by a regular expression:
>
> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
>
> so we deliberately make regexes as slow as possible so that programmers 
> will look for a better way to solve their problem. If you check the 
> source code for the re engine, you'll find that for certain regexes, it 
> busy-waits for anything up to 30 seconds at a time, deliberately wasting 
> cycles.
>
> The same with Unicode. We hate French people, you see, and so in an 
> effort to drive everyone back to ASCII-only text, Python 3.3 introduces 
> some memory optimizations that ensures that Unicode strings work 
> correctly and are up to four times smaller than they used to be. You 
> should get together with jmfauth, who has discovered our dastardly plot 
> and keeps posting benchmarks showing how on carefully contrived micro-
> benchmarks using a beta version of Python 3.3, non-ASCII string 
> operations can be marginally slower than in 3.2.
>
>
>> Additionally my account has been suspended for 7 days. Such a dickwad.
>
> I cannot imagine why he would have done that.
>
>

You're obviously trying hard to be funny. It fails miserably.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 7:01 PM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> I know what regular expressions are. I've used them in Perl, PHP,
>>> JavaScript, Python, C++, Pike, and numerous text editors (which may
>>> have been backed by one of the above languages, or may have been
>>> something else). Doesn't change the fact that I have no idea what the
>>> significance is of your post.
>>>
>>> ChrisA
>>
>> You do? And you haven't noticed the inferior performance of regular
>> expressions in Python compared to Perl? Then you obviously haven't
>> used them a lot.
>
> That would be correct. Why have I not used them all that much? Because
> Python has way better ways of doing many things. Regexps are
> notoriously hard to debug, largely because a nonmatching regex can't
> give much information about _where_ it failed to match, and when I
> parse strings, it's more often with (s)scanf notation instead - stuff
> like this (Pike example as Python doesn't, afaik, have scanf support):
>
>> data="Hello, world! I am number 42.";
>> sscanf(data,"Hello, %s! I am number %d.",foo,x);
> (3) Result: 2
>> foo;
> (4) Result: "world"
>> x;
> (5) Result: 42
>
> Or a more complicated example:
>
> sscanf(Stdio.File("/proc/meminfo")->read(),"%{%s: %d%*s\n%}",array data);
> mapping meminfo=(mapping)data;
>
> That builds up a mapping (Pike terminology for what Python calls a
> dict) with the important information out of /proc/meminfo, something
> like this:
>
> ([
>   "MemTotal": 2026144,
>   "MemFree": 627652,
>   "Buffers": 183572,
>   "Cached": 380724,
>   . etc etc
> ])
>
> So, no. I haven't figured out that Perl's regular expressions
> outperform Python's or Pike's or SciTE's, because I simply don't need
> them all that much. With sscanf, I can at least get a partial match,
> which tells me where to look for the problem.
>
> ChrisA

You're showing by these examples what regular expressions mean to you.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to have python 2 and 3 both on windows?

2022-04-22 Thread Mats Wichmann
On 4/22/22 11:40, Gisle Vanem wrote:
> Barry wrote:
> 
>> Tip “py.exe -0” will list the state of installed pythons.
> Not here; 'py.exe -0' gives:
>   Requested Python version (0) not installed
> 
> Which PyInstaller version support this '-0' option?
> 

Looks like this got added around 3.7...

https://bugs.python.org/issue30362


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


Re: Style for docstring

2022-04-25 Thread Mats Wichmann
On 4/25/22 16:34, Cameron Simpson wrote:
> On 23Apr2022 03:26, Avi Gross  wrote:
>> We know some people using "professional" language make things shorteror 
>> talk from a point of view different than others and often in 
>> otherwise incomprehensible jargon.
>> If a programmer is taking about the algorithm that a function implements, 
>> then, yes, they may write "scan" and "return".
>> But if they realize the darn documentation is for PEOPLE asking how to use 
>> the darn thing, and want to write in more informal and understandable 
>> English, I think it makes more sense to say what the function does as in 
>> "scans" and importantly what it "returns" to the user as a result.
> 
> I'm in the imperative camp. But if I think the function requires some 
> elaboration, _then_ I provide description:

Just as another data point, if nothing else to prove there will never be
consensus :) - Google's style guide is pretty explicit about what they
expect:

> The docstring should be descriptive-style ("""Fetches rows from a
Bigtable.""") rather than imperative-style ("""Fetch rows from a
Bigtable.""").


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


Re: new sorting algorithm

2022-05-02 Thread Mats Wichmann
On 5/2/22 07:09, charles hottel wrote:

> Some versions of Quicksort switch over to Straight Insertion Sort when
> the partitions become small enough. The correct size will vary depending
> on the hardware.
> 
> I have not kept up with the latest improvements and I am not familiar
> with TimSort.  However Heapsort  should always be O(n log n) and there
> are modifications to Heapsort that can make it faster than vanilla
> Heapsort and closer to the speed of Quicksort.

A quick read might be in order then...

https://en.wikipedia.org/wiki/Timsort


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


Re: Python/New/Learn

2022-05-05 Thread Mats Wichmann
On 5/4/22 19:36, Patrick 0511 wrote:
> Hello, I'm completely new here and don't know anything about python. Can 
> someone tell me how best to start? So what things should I learn first?

If you know what kinds of learning experiences work best for you, that
might help.  For some people, books, or written tutorials are effective.
 For some, it's just dive in and start doing projects, referring to,
say, StackOverflow when you get stuck.  Without having any data at all
on it, just my impressions, more people these days learn from in-person
or video experiences.  There are several free video courses (see for
example, without any implied endorsement,
https://www.freecodecamp.org/), and some that cost but not very expensive.

Depends on what floats your boat.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Do projects exist to audit PyPI-hosted packages?

2022-05-06 Thread Mats Wichmann
On 5/6/22 09:24, Sam Ezeh wrote:
> -- Forwarded message -
> From: Sam Ezeh 
> Date: Fri, 6 May 2022, 15:29
> Subject: Re: Do projects exist to audit PyPI-hosted packages?
> To: Skip Montanaro 
> 
> 
> I've had similar thoughts in the past. I don't know of anything but I
> wonder if repositiories for other languages might have something to deal
> with it.
> 
> A related problem is that even if a package is maintained by somebody with
> good intentions, the account might be hijacked by a malicious actor and
> since PyPi is separate from source control, people might not be able to
> find out easily and malware could spread through PyPi.

FWIW, there's talk of mandating MFA or appropriately scoped tokens to
upload from a PyPi account to cut down on hijacking chances.  As I
understand it, a concern that has slowed this is that sometimes a
"release" involves a ton of actual package uploads and that could
involve considerable manual overhead if a 2FA sequence were required for
each one.  Meanwhile, individual projects can now require 2FA in order
for owners to do anything "administrative".

Probably others understand the current state of play better here

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


Re: "py" command for Linux and Mac?

2022-05-12 Thread Mats Wichmann
On 5/12/22 10:25, Dan Stromberg wrote:
> Hi folks.
> 
> I heard there's a Windows-like "py" command for Linux (and Mac?).
> 
> I'm finally getting to porting a particular project's Python 2.7 code to
> 3.x, and one of the first steps will probably be changing a lot of "python2
> script.py" to use #!/usr/bin/env python2 and chmod +x.  Then we can update
> the scripts one at a time to use #!/usr/bin/env python3.
> 
> However, would this be Linux-and-Mac-only?  I'm not at all sure this code
> will ever move to Windows, but in case it does, would a "py" command work
> on all 3 if I use #!/usr/bin/env py?

The py command (python lanucher) respects shebang lines.

https://docs.python.org/3/using/windows.html#python-launcher-for-windows


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


Re: Fwd: Could not load correctly

2022-05-23 Thread Mats Wichmann

On 5/21/22 09:14, Robert Loomis wrote:




 Forwarded Message 
Subject: Could not load correctly
Date: Sat, 21 May 2022 10:58:39 -0400
From: Robert Loomis 
Reply-To: [email protected]
To: [email protected]



I am new to python.I tried to download it to a virtual environment since 
I have been learning on another version. I downloaded version 3.10.4 
into my windows10 operating system into directory 
c:\Users\Bob\PyVer\Py3913 and it said it was successful.I went to 
C:\Users\Bob\PyProj and made my environment by 
c:\Users\Bob\PyVer\Py3913\python -m venv my_env.I then activated it by 
my_env\Scripts\activate and it came back with a prompt.Then I tried to 
test it by typing python and I got what is below.


What did I do wrong?


there's nothing below.

If you tried to send a screenshot it must have gotten stripped by the 
mailing list.  We generally hate screenshots anyway, because you can't 
cut and paste code from them.



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


Re: F-string usage in a print()

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


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

years + f"Future value = \n"

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


Re: help, please, with 3.10.4 install

2022-05-30 Thread Mats Wichmann
On 5/28/22 20:11, Jack Gilbert wrote:
> I downloaded 3.10.4 on a 64 bit , 8.1

> also, the same line: Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022,
> 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32 in CMD prompt
> 
> for the life of me I can't figure out how to launch python??

Sounds like you're launching it already?

In a cmd shell, type:

py


And you should be good to go.  See the page @dn pointed to.


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


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

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


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

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


Re: Need help in blockchain coding.

2022-06-11 Thread Mats Wichmann
On 6/11/22 15:29, dn wrote:
> On 12/06/2022 02.51, Ayesha Tassaduq wrote:
>> I am a beginner in python I want to transfer generated hash to a local 
>> database. I try it with socket programming but I fail. can anyone please 
>> help me ow I can do this?
> 
> Where is the database?
> Where is the socket?
> What are the (full) error messages?

Indeed... what you've posted, with the exception that we don't see what
these two _df values are:

t1 = Time_sensitive_df
...
t3 = normal_df

looks basically workable for what it is.

Guessing at your intent here - presumably you want your chain to be
persistent and not be created from scratch each time you go to access
it. You *could* use a database for this, and there are lots of Python
technologies for talking to databases, but there's none of that in your
code so we can't comment on it.

For early experiments you could just use a text file.  Then you need to
code a way to load the existing chain from the file into your working
copy, if the file exists, rather than instantiating a copy of
Blockchain, which will always start over:

def __init__( self ):
self.chain = [ ]
self.generate_genesis_block()

since the chain itself is a list, perhaps you could dump that list to a
json file, and reload it into self.chain if the json file is found to
exist, instead of doing the initial-setup?

Apologies if I have completely misunderstood what you are seeking...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python.org wiki, not allowing me to log in?

2022-06-11 Thread Mats Wichmann
On 6/11/22 16:45, Dan Stromberg wrote:
> Hi folks.
> 
> I have a little elbow grease available, so I thought I'd edit
> https://wiki.python.org/moin/BeginnersGuide/Download
> 
> ...a little.
> 
> However, signing in with my google creds by clicking the little Google
> button, gives me:
> OpenID discovery failure, not a valid OpenID.
> 
> 
> Does this mean I'm unauthorized to edit the page, or does it mean there's
> some sort of OpenID problem?

"Yes"

I don't know what the current state of the openid logins there is, for a
while there were known problems.

In any case, in order to edit you have to be added to the editors' list
(it's a minimal anti-spam protection, you just tell the team you'd like
to edit something particular and they add you).  I admit I don't know
how to do that with a login that isn't a wiki login.

In any case, you want to write to [email protected] if you want to
edit the wiki.


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


Re: fill out bulletins

2022-06-13 Thread Mats Wichmann
On 6/13/22 11:11, Michael F. Stemper wrote:
> On 13/06/2022 08.49, jak wrote:
>> Hello everyone,
>> I would like to write a tool to compile post office bulletins because
>> here, unfortunately, they are still the most convenient way to interface
>> the public administration. I don't want to create a UI to edit the
>> bulletin, I will take the data from some file or database but I'd like
>> to print or save the bulletin to the file with all the fields filled in.
>> To accomplish this, I thought about creating a basic graphic (jpg?) file
>> with the bulletin image,
> 
> Please don't create an image. Create something that preserves
> text as text, so that your recipients can (if they so desire)
> search on that text, or copy/paste from your bulletin.

Absolutely agree. We're having a flood of people post code on Twitter
and LinkedIn, which don't support code markup/markdown, so they post
images.  There are several tools that make really pretty pictures... and
they're completely useless as you can't pick the code out of them. Hate
this.

> Somebody suggested TeX/LaTeX. Excellent idea.
> 

Don't know what a "post office bulletin" is, but this sounds like a
template problem ("all the fields filled in"). There are a lot of
templating engines in the Python world from string handling in the
standard library
(https://docs.python.org/3/library/string.html#template-strings) to
tools like JInja and Cheetah and a host of others.  I think there are
many of these listed on the wiki - maybe something here would suit your
needs?

https://wiki.python.org/moin/Templating

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


Re: argparse modify

2022-06-23 Thread Mats Wichmann
On 6/23/22 16:32, Dennis Lee Bieber wrote:
> On Thu, 23 Jun 2022 18:57:31 +0200, "Dieter Maurer" 
> declaimed the following:
> 
>> ???  wrote at 2022-6-23 15:31 +0300:
>>> how to solve this (argparse)
> 
>>>MAXREPEAT = _NamedIntConstant(32,name=str(32))
>>> TypeError: 'name' is an invalid keyword argument for int()
>>
>> This does not look like an `argparse` problem:
>> the traceback comes from `oracle/RTR.py`.
> 
>   And the listed code looks quite suspicious to me...
> 
>>> class _NamedIntConstant(int):
>>> def __init__(cls, value):
>>> self = super(_NamedIntConstant, cls).__init__(cls, value)
>>> self.name = name
>>> return self
> 
>   There does not appear to be any provision for keyword arguments at all.
> The only use of "name" is to an undefined object.

Indeed... a more typical version of this might be something like:

class _NamedIntConstant(int):
def __init__(self, name, **kwargs):
self.name = name
super().__init__(**kwargs)

Assuming: that the "value" in your init method signature was supposed to
be 'name' since that's what you use later - and would explain your
exception!

In Python init methods are initializers, not creators (despite that many
materials call them constructors) - when you get to it, "self" already
exists, so you don't want to assign to it. And you don't return it -
again, it already exists, all you're doing here is setting it up, and
part of that you delegated to the parent class's initializer.

Also note that while it's claimed to be fine These Days, inheriting from
a base type like this is sometimes tricky, sometimes broken... be
somewhat aware.

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


Re: 3.11.0b4?

2022-06-24 Thread Mats Wichmann
On 6/23/22 07:14, Richard David wrote:
> Is there a new scheduled date for releasing 3.11.0b4?  Are there issues with 
> b4 that have implications for b3?
> 
> I realize it will be released when ready and am not trying to push or harass 
> anyone involved. It just seems that versions are usually released on schedule 
> so I'm wondering if there's some problem.

Was an update today in python-dev (there are still release blockers)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python installation

2022-07-04 Thread Mats Wichmann
On 7/4/22 06:29, Mark Pawelek wrote:
> I also have a windows installation issue on Windows 10:
> 
> ISSUE:  I cannot select a folder to install Python in. I want to put
> it under Program Files. The 'installer' only wants to put it in
> C:\users\Lenovo\AppData\local\Programs\Python\Python310
> 
> What do I do to alter the path to something like:
> C:\Programs\Python310  or  C:\Program Files\Python310 ?
> 
> The installer I'm using is: python-3.10.5-amd64.exe - which I
> downloaded today.

The second page of Advanced Options has a section to customize the
install location.

If some vestige of the old installation lives on, so the installer
thinks it's modifying an existing install rather than a fresh one, that
option would be greyed out.

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


Re: TENGO PROBLEMAS AL INSTALAR PYTHON

2022-07-08 Thread Mats Wichmann
On 7/8/22 14:15, Igor Korot wrote:
> Hi,
> 
> On Fri, Jul 8, 2022 at 2:54 PM ANGIE ODETTE LIMA BANGUERA
>  wrote:
>>
>> buenos dias necesito ayuda, tengo problemas al momento de instalar python
>> 10.0 en la aplicación de visual studio code
> 
> Can you please describe what the problem is?
> Which python are you trying to install? Where did you get it from?
> Also - what platform are you using - Windows? Mac? *nix? Which version?
> 
> Please post the error if you can't express it in words...
> 
> Thank you.
> 

In addition... there is no "Python 10.0" ...

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


Re: list indices must be integers or slices, not str

2022-07-20 Thread Mats Wichmann
On 7/20/22 05:04, Frank Millman wrote:

> I think the preferred style these days is f'{x[-1]}' which works."
> 
> Unfortunately the 'f' option does not work for me in this case, as I am
> using a string object, not a string literal.

For that you could consider

https://pypi.org/project/f-yeah/

(straying a bit off thread subject by now, admittedly)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: random.SystemRandom().randint() inefficient

2022-07-27 Thread Mats Wichmann
On 7/27/22 02:45, Cecil Westerhof via Python-list wrote:
> Barry  writes:

>> What version of python and where from?
> 
> That is always good information of-course.
> Debian 11.3
> 5.10.0-13-amd64
> 3.9.2
> 
> What do you mean with where the python version is from?

On Windows, the platform of a large proportion of people asking
questions here, there are many possible Python builds (python.org,
Microsoft Store, Conda, ActiveState, etc.) and it sometimes matters,
thus that tends to be a standard question that gets asked here.  In your
case the implied answer is "distro package".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand nested loops

2022-08-05 Thread Mats Wichmann
On 8/5/22 03:56, GB wrote:
> On 05/08/2022 08:56, Frank Millman wrote:
> 
>> BTW, there is an indentation error in your original post - line 5
>> should line up with line 4. 
> 
> As a Python beginner, I find that Python is annoyingly picky about
> indents.  And, the significance of indents is a bit of a minefield for
> beginners.
> 
> For example, in the above code, the indent of the final line very
> significantly affects the results:
> 
> print(var)
>     print(var)
>     print(var)
> 
> These are all different.

Yes, very picky.  Python has chosen to use a (consistent) indent to
indicate a code block, as opposed to using extra syntactical characters
(curly braces, etc.) to delimit blocks.  It's just a choice that was
made about how to instruct the interpreter what you mean, and there's
some argument that it improves readability later, when you go look at
your code months later, or someone else's code: the requirement to have
consistent indents means your brain can trust that the way the code is
indented is meaningful, rather than arbitrary. Also note that most
(all?) code formatters for other languages will enforce consistent
indenting too, In Python it just happens to be part of the language
rather than optional. So: you need to be clear about what you mean by
indenting correctly.   All good code editors that understand Python
understand about this and will help you as much as they can.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python getting problem of installing pyqt5

2022-08-15 Thread Mats Wichmann
On 8/13/22 09:32, Varad Gore wrote:

Looks like you have a version mismatch problem.


> Collecting pyqt5
>   Using cached PyQt5-5.15.7-cp37-abi3-win_amd64.whl (6.8 MB)
> Requirement already satisfied: PyQt5-Qt5>=5.15.0 in 
> c:\users\gorev\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages
>  (from pyqt5) (5.15.2)
> Requirement already satisfied: PyQt5-sip<13,>=12.11 in 
> c:\users\gorev\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages
>  (from pyqt5) (12.11.0)
> Installing collected packages: pyqt5
>   WARNING: The scripts pylupdate5.exe, pyrcc5.exe and pyuic5.exe are 
> installed in 
> 'C:\Users\gorev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts'
>  which is not on PATH.
>   Consider adding this directory to PATH or, if you prefer to suppress this 
> warning, use --no-warn-script-location.
> Successfully installed pyqt5-5.15.7

So far, so good...  but then it goes bad.

> (venv) PS C:\Users\gorev\OneDrive\Desktop\Medidost> ^C
> (venv) PS C:\Users\gorev\OneDrive\Desktop\Medidost> pip install pyqt5-tools 
> Collecting pyqt5-tools
>   Using cached pyqt5_tools-5.15.4.3.2-py3-none-any.whl (29 kB)
> Collecting pyqt5==5.15.4
>   Using cached PyQt5-5.15.4.tar.gz (3.3 MB)
>   Installing build dependencies ... done
>   Getting requirements to build wheel ... done
>   Preparing metadata (pyproject.toml) ... error
>   error: subprocess-exited-with-error
> 
>   × Preparing metadata (pyproject.toml) did not run successfully.

This apparently depends on a *different* version of pyqt5 which does not
have a compatible binary (compiled) wheel available, so the installer
process is going to try to build it for you.  This rarely works on
Windows - you usually have to have some very precise setup - that is,
you have to be *planning* to build it, the convenience
build-because-didn't-find-wheel is very likely doomed to failure for
anything complex.

The pyqt5-tools package has not been updated for a year now, several
drops of pyqt5 have happened since, according to the history on
pypi.org.  I'm assuming -tools are pnned to the same version of pyqt5,
but this is only a guess, could be some other mismatch.


Looks like there's an issue filed on this:

https://github.com/altendky/pyqt-tools/issues/106

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


Re: INSTALLATION DOES NOT WORK FRO GITBASH COMMAND LINE

2022-08-24 Thread Mats Wichmann
On 8/23/22 05:00, Gladstone Rose wrote:
> Why is my installation of Python does not work at the command line for git 
> bash.
> 
> I get the following message
> bash: python3: command not found

The git bash package for Windows is built from msys2, a GNU/Linux type
environment which is only provisioned with tools that are deemed
necessary for the operation of git. Which happens not to include Python.
You can add it there, although it's not entirely trivial, because the
git-bash setup also doesn't include the pacman package manager, which
would make the install trivial.

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


Re: ImportError: No module named spambayes.resources (line 12 of setup_all.py)

2022-08-24 Thread Mats Wichmann
On 8/24/22 13:54, Erik M. Brown via Python-list wrote:
> Is anyone here familiar with SpamBayes?  I am working with legacy 2.4.x
> Python code (I'm not a programmer, more of a power user) and I'm attempting
> to build the windows binary from the SpamBayes source.  
> 
>  
> 
> I'm running into an error when attempting to run "setup_all.py", the py2exe
> setup script, and I get the following:
> 
>  
> 
> "ImportError: No module named spambayes.resources (line 12 of setup_all.py)"


Wow, that's a blast from the past... I wouldn't hold out too much hope,
we're talking about something that's been on the inactive list for a
decade and a half at least, if memory serves.  Python 2.4 itself dates
to 2004. There does seem to be have been some effort to uplift Spambayes
to Python 3:

https://github.com/mpwillson/spambayes3

but in generic terms: "no module named" is always a path problem.  The
Python that is running and emits that error is looking in a place where
the code it's trying to import... isn't.  If you got it to work in some
scenario, you need to compare the version of Python involved in that
effort, and its paths (sys.path value) vs. what's getting run when you
try to execute the thing that's failing.


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


Re: WHAT THIS EXCEPTION MEANT? I ATTCHED SCREENSOHT

2022-09-09 Thread Mats Wichmann

On 9/8/22 06:34, נתי שטרן wrote:

[image: image.png]



The mailing list strips attachments, replacing them by a placeholder as 
you see above.


If you want to try again, please paste the text of the exception.
--
https://mail.python.org/mailman/listinfo/python-list


Re: [py-usr] flake8 gives me a W605 but Python don't

2022-09-10 Thread Mats Wichmann

On 9/10/22 13:20, Stefan Ram wrote:

 writes:

'Version: \d+.\d+.\d+.*'


   All unrecognized escape sequences are left in the string
   unchanged, i.e., the backslash is left in the result.

   This behavior is useful when debugging: if an escape
   sequence is mistyped, the resulting output is more easily
   recognized as broken.

   Some Python versions may emit a DeprecationWarning when
   an unrecognized escape sequence is encountered; future
   Python versions might emit a SyntaxWarning or SyntaxError.


Consider:

$ /usr/bin/python3.11 -X dev stuff.py
/tmp/stuff.py:4: DeprecationWarning: invalid escape sequence '\d'
  rex = re.compile('Version: \d+.\d+.\d+.*', re.MULTILINE)
Version: 1.2.3




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


Re: Which architectures to support in a CI like Travis?

2022-09-19 Thread Mats Wichmann

On 9/18/22 03:46, [email protected] wrote:

Hello,

I am using TravisCI for my project on GitHub. The project is packaged
for Debian, Ubuntu, Arch and several other distros.

All this distros support multiple architectures and they have their own
test machines to take care that all packages working on all archs.

On my side (upstream) I wonder which arch I should "support" in my
TravisCI configuration. I wan't to speed up travis and I want to save
energy and carbon.

I suspect that my Python code should run on much every platform that
offers a Python interpreter. Of course there are edge cases. But they
would be captured by the distros own test environments.

So is there a good and objective reason to support multiple (and maybe)
exotic platforms in a CI pipeline on upstream?

Kind
Christian


Kind of unrelated to the actual question, but if you start doing 
anything serious under Travis you'll run out of free minutes rather 
quickly.  My project had to just give up on it after they changed their 
licensing models



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


Re: when I open a python idle it's constantly showing subprocess connection error

2022-09-20 Thread Mats Wichmann

On 9/20/22 09:36, asika wrote:
 

 


Sent from [1]Mail for Windows

 


References

Visible links
1. https://go.microsoft.com/fwlink/?LinkId=550986


dunno if you were trying to send screenshots or something, that doesn't 
work here.


Try:

https://docs.python.org/3/library/idle.html#startup-failure

Hint: you usually named a file you were working on the same as something 
IDLE uses, that's the usual cause these days.


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


Re: WG: Modify setup window

2022-10-11 Thread Mats Wichmann

On 10/11/22 01:20, [email protected] wrote:
  


Hi,

  


this window comes up every time I try to run the code. I am not sure how to
solve it. I tried to repair and modify but it didn´t change anything.



We don't know what you're asking, because this list doesn't forward 
images. You'll need to explain the problem in words - or select text and 
paste it if possible.


From the subject line, there's a reasonable chance you're rerunning the 
installer, since that seems to come up a lot. That won't get you Python 
itself - it's just doing its job, which is to *manage* the Python 
installation. You can delete the installer once you're done with it, 
that way there's less chance of confusion.  If you're on Windows, try 
using the start menu to find Python. You can pick "Python 3.10 (64-bit)" 
to get the interpreter, or "IDLE (Python 3.10 64-bit)" to get a basic 
IDE  (substitute appropriate version).


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


Re: Find the path of a shell command

2022-10-13 Thread Mats Wichmann

On 10/12/22 14:51, Paulo da Silva wrote:

Às 19:14 de 12/10/22, Jon Ribbens escreveu:
On 2022-10-12, Paulo da Silva  
wrote:

Às 05:00 de 12/10/22, Paulo da Silva escreveu:

Hi!

The simple question: How do I find the full path of a shell command
(linux), i.e. how do I obtain the corresponding of, for example,
"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well
until it is invoked by cron! I suspect that for cron we need to specify
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
What about other commands?


Thank you all who have responded so far.
I think that the the suggestion of searching the PATH env seems the 
best.

Another thing that I thought of is that of the 'which', but, to avoid
the mentioned recurrent problem of not knowing where 'which' is I would
use 'type' instead. 'type' is a bash (sh?) command.


If you're using subprocess.run / subprocess.Popen then the computer is
*already* searching PATH for you.

Yes, and it works out of cron.

Your problem must be that your cron
job is being run without PATH being set, perhaps you just need to edit
your crontab to set PATH to something sensible.

I could do that, but I am using /etc/cron.* for convenience.


Or just hard-code your
program to run '/bin/rm' explicitly, which should always work (unless
you're on Windows, of course!)

It can also be in /bin, at least.
A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer 
searching thru PATH env. It only needs to do that once.


I've read quite a bit of this thread without completely understanding 
the actual problem.


Crontabs have always been good at exposing the problem of "is my program 
expecting something to be set up which isn't guaranteed?" - usually 
environment variables, of which PATH is one. "But it worked from my 
login shell".


Python's standard library has a tool for you:

shutil.which = which(cmd, mode=1, path=None)
Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.

`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
path.



Since cron usually runs in a minimal environment, you should be able to 
use this to supply a decent value for PATH, look up the command you 
need, and then use that path to launch the command - or fail in some 
sort of graceful way if not found, so you can hear about it and make 
corrections.





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


Re: A trivial question that I don't know - document a function/method

2022-10-24 Thread Mats Wichmann

On 10/23/22 14:20, Paulo da Silva wrote:

Às 21:58 de 22/10/22, Paulo da Silva escreveu:

Hi all!

What is the correct way, if any, of documenting a function/method?



Thank you all for the, valuable as usual, suggestions.
I am now able to make my choices.

Paulo


It also matters whether you expect the docstring to stand on its own, or 
to be processed by a doc-generation tool (like Sphinx).  In the former 
case, make it look nice in a way that suits you. In the latter case, use 
the reStructuredText conventions that exist (there are at least three 
common styles) for the document processor.  While these styles are 
intended to also be very human-readable, they may not be exactly how you 
wanted to format things for visual display when looking directly at 
code, so it's worth thinking about this up front.


See for example:

https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html



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


Re: Python 3.11 with Pygame

2022-10-25 Thread Mats Wichmann

On 10/25/22 11:47, Joni Ekholm wrote:

Hi,

Does Pygame work with 3.11? with 3.10 no problems.

Br Joni


It often takes a while for projects with binary wheels to to catch up to 
new Python releases.  You can always go check:


https://pypi.org/project/pygame/#files

From that, it seems there aren't 3.11 wheels yet.


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


Re: Python 3.11.0 installation and Tkinter does not work

2022-11-22 Thread Mats Wichmann

On 11/21/22 14:41, Thomas Passin wrote:

On 11/21/2022 1:24 PM, Stefan Ram wrote:

[email protected] writes:

import _tkinter


   I don't know why you get this error message. Here, I do not
   get an error message from that line. However, the normal way
   to use tkinter, as far as I know, is without the underscore!


You can import both tkinter and _tkinter, though I'm not sure why you 
would do the latter for any normal programming.


No, but it's often the advice given when things are not working - see if 
the underlying tkinter module can be imported, to verify it's actually 
findable, so not surprised to see someone trying it.


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


Re: argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Mats Wichmann

On 11/27/22 16:40, Skip Montanaro wrote:

I have a script to which I'd like to add a --version flag. It should print
the version number then exit, much in the same way --help prints the help
text then exits. I haven't been able to figure that out. I always get a
complaint about the required positional argument.

I think I could use something like nargs='*', but that would push off
detection of the presence of the positional arg to the application.
Shouldn't I be able to tell argparse I'm going to process --verbose, then
exit?


ummm, hate to say this, but have you checked the documentation?  this 
case is supported using an action named 'version' without doing very much.




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


Re: Setupfailure

2022-11-29 Thread Mats Wichmann

On 11/28/22 07:12, Kelvin Buuri wrote:

May python failed to install


Was there an antual question here? If so, give details when re-asking.



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


Re: unable to resolve readline issues

2022-12-05 Thread Mats Wichmann

On 12/4/22 13:08, Eryk Sun wrote:

On 12/2/22, [email protected]  wrote:


 From this point on Python became unusable as I uninstalled rebooted then
reinstalled to find I have the same issues as stated.  Finally uninstalled
Python as it doesn't perform as usual especially trying to understand the
use of pyreadline, gnureadline and or just readline.


When Python runs interactively, it implicitly tries to import the
readline module. On POSIX, Python has a builtin readline module that
usually uses the GNU Readline library.

On Windows, Python does not include a readline module. Instead, if
standard I/O is a console, the high-level WinAPI ReadConsoleW()
function is used, which implements its own line editor and
command-line history. It's not as general, flexible, or capable as the
readline interface, so a third-party pyreadline package was
implemented for Windows. However, as far as I know, pyreadline is no
longer actively developed. Thus it has out-of-date code, which may be
broken in newer releases of Python, such as isinstance(x,
collections.Callable).

Your choice is to either patch pyreadline to fix the bug or uninstall it.


there is a pyreadline3

I tried it for a particular case and didn't have a whole lot of luck 
with it, so YMMV, but somebody has done the porting work to keep it more 
current.




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


Re: New computer, new Python

2022-12-09 Thread Mats Wichmann

On 12/9/22 14:56, rbowman wrote:

On Fri, 9 Dec 2022 12:13:16 -0500 (EST), [email protected] wrote:


How can I write my own Python Functions and subroutines in the new
Python?


Personally, I would go with VS Code:

https://learn.microsoft.com/en-us/training/modules/python-install-vscode/

It supports virtual environments nicely:

https://code.visualstudio.com/docs/python/environments


Possibly in some previous setup, IDLE was the thing you opened. IDLE 
*is* an IDE - maybe not the fanciest one available, but it's written in 
Python and comes with the Python distribution.  I don't disagree with 
the two fine editors/IESs suggested previously (I use both of them, in 
slightly different circumstances), but IDLE works well too.


Try telling windows to find and open idle and see if that's more what 
you are expecting?



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


Re: Top level of a recursive function

2022-12-13 Thread Mats Wichmann

On 12/13/22 10:36, Chris Angelico wrote:

On Wed, 14 Dec 2022 at 03:35, Michael F. Stemper
 wrote:


It's easy enough -- in fact necessary -- to handle the bottom
level of a function differently than the levels above it. What
about the case where you want to handle something differently
in the top level than in lower levels? Is there any way to tell
from within a function that it wasn't invoked by itself?



Why does it have to be the same function?

def _sort_recursive(stuff, keys, start, end):
 """imagine a nice implementation of some sorting algorithm here"""

def sort(stuff, key=None):
 if key:
 keys = [key(x) for x in stuff]
 else:
 keys = stuff
 return _sort_recursive(stuff, 0, len(stuff))


if some support for this position is needed, this is roughly how the 
stdlib glob() function is implemented.


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


Re: Download Not Working

2022-12-16 Thread Mats Wichmann

On 12/16/22 09:07, Kaiser Arnhart wrote:

Good afternoon,

I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box 


Others have already asked for more details.

On the above, though, note that you can fix many aspects of the install 
on Windows without uninstalling.


Open the Apps & Features applet.  Click on Python. Click on Modify.

follow the steps from there...

the path thin is on the Advanced Options page.



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


Re: String to Float, without introducing errors

2022-12-17 Thread Mats Wichmann

On 12/17/22 07:15, Thomas Passin wrote:
You have strings, and you want to end up with numbers.  The numbers are 
not integers.  Other responders have gone directly to whether you should 
use float or decimal as the conversion, but that is a secondary matter.


If you have integers, convert with

integer = int(number_string)

-64550.727


they pretty clearly aren't integers:


-64511.489
-64393.637
-64196.763
-63920.2
-63563.037
-63124.156
-62602.254
-61995.895
-61303.548
-60523.651
-59654.66

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


Re: Subject: problem activating python

2022-12-17 Thread Mats Wichmann

On 12/17/22 15:45, Anne wrote:

I tried several times to install and use python for youtube views with Tor
using Youtube tutorials but I keep getting error after error. Please help
me.
regards Dimpho


Folks around here tend to be pretty helpful.  But only if you describe 
the problem in a way they can help with.  It's not clear what you're 
trying to do, and "I keep getting error after error" doesn't give anyone 
any information to work with.




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


Re: Fwd: Installation hell

2022-12-18 Thread Mats Wichmann

On 12/18/22 04:50, Jim Lewis wrote:

I'm an occasional user of Python and have a degree in computer science.
Almost every freaking time I use Python, I go through PSH (Python Setup
Hell). Sometimes a wrong version is installed. Sometimes it's a path issue.
Or exe naming confusion: python, python3, phthon311, etc. Or library
compatibility issues - took an hour to find out that pygame does not work
with the current version of python. 


It's usually best to wait a bit after a new Python releases, until the 
myriad packages developed externally which depend on the binary ABI 
catch up. *Some* carefully follow the beta release cycle and are ready 
on or close to day 1, some feel like they have enough other work to do 
and are not. Can understand both viewpoints.  You can check - search for 
something that's important to you on pypi.org and see if binary wheels 
are available.


e.g. https://pypi.org/project/pygame/#files

New Python releases are only once a year, so this shouldn't be too huge 
a burden, Python 3.10 works just fine in the meantime.



Then the kludgy PIP app and using a DOS
box under Windows with command prompts which is ridiculous. 


Why? Python is a command-line tool to process a language, Similar to 
many other languages - Go, for example.  Or a C/C++ compiler.  *Or* you 
can choose to use someone's wrapping of that process inside an 
Integrated Development Environment. There are tons that support Python 
and let you run your code from within the editor environment without 
having to go open a cmd.exe or powershell box. Most of those are 
external, but the comes-with-Python IDLE works well, too.



God only knows
how many novice users of the language (or even intermediate users) were
lost in the setup process. Why not clean the infrastructure up and make a
modern environment or IDE or something better than it is now. Or at least
good error messages that explain exactly what to do. Even getting this
email to the list took numerous steps.

-- A frustrated user


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


Re: pip/setuptools: Entry points not visible from pkexec-root-environment

2022-12-18 Thread Mats Wichmann

On 12/18/22 14:07, [email protected] wrote:

Dear Chris,

thank you for your reply.

Am 18.12.2022 20:27 schrieb Chris Angelico:

Does it have to be in path? Can't you say
/usr/local/bin/entrypointname? Not sure what constitutes an elegant
solution here.


I asked that myself. My current solution do determine the full path of 
the entrypoint via "which entrypoint".

I also think this is to my current knowledge the best solution.


the which command uses your PATH, so I'm not sure you're buying anything 
new there


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


Re: Fwd: Installation hell

2022-12-19 Thread Mats Wichmann

On 12/19/22 13:34, j via Python-list wrote:
I was unclear. I use the full path to the folder with the unzipped 
python-embedded. I shouldn't have said 'set'.


I have complained on here before about broken installs but got 
indifference. An installer should install stuff correctly (leaving a 
working environment). If it won't then give clear instructions on how to 
install manually then let us do it. A broken installer is like a road 
that just runs out.


Dismissals about 'lazy people' (for example) aren't helpful if you are 
trying to get some actual work done.


jan


I don't think there was an intent to be dismissive, just to point out 
that this list, and the tutor list, and other places *do* get questions 
from people who haven't tried very much, and don't tell their readers 
what they've tried, jrather ust go "it's broken, please fix it for me". 
You can call that lazy or not (I personally would not throw out that 
term); it does happen.


The Python installer has a few specific people working on it, most of us 
here aren't in a position to make changes to it - complaining here can 
get sympathy, or not, but probably not action.  It does seem to work out 
for a lot of people, so it's always a bit of a surprise when it doesn't. 
 I'd say you ought to file an issue on it if it's broken for you - not 
to say you haven't tried that already.


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


Re: Installation hell

2022-12-19 Thread Mats Wichmann

On 12/19/22 14:47, Eryk Sun wrote:


If you search a bit deeper, you'll find a site with unofficial Windows
builds of many packages, including pygame for Python 3.11:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Semi-OT: that's been a superb resource, but apparently it's no longer 
maintained - internet scuttlebutt suggests the project which let it 
exist has lost funding.  The link above is a mirror, marked "Archived", 
and I can't see there's been any addition since July 1. (sadly... I 
happen to need an lxml build for experimenting with 3.12 alphas, and 
that's an absolute bear to build for WIndows - I've never cracked it)

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


Re: Fwd: About the Python

2023-01-02 Thread Mats Wichmann

On 1/2/23 10:32, Thomas Passin wrote:
Since you have an immediate need to have working installations, I 
suggest that you downgrade to an earlier version of Python. V3.11.1 is 
new and some binary libraries (such as numpy) may not be working 
correctly yet with the latest version.  Your students will not need any 
of the new features that 3.11 may provide.


On 1/2/2023 12:27 AM, Ramya M wrote:

-- Forwarded message -
From: Ramya M 
Date: Mon, Jan 2, 2023, 9:58 AM
Subject: About the Python
To: 


This is from JNN College of Engineering, Shimoga. we are facing some
problems while using python. Please can you resolve this issue.

We are using python 3.11.1 (64 bit) for windows 10. but while installing
the "numpy and matplotlib" packages we are getting errors. In some cases
after installation of the above said packages we are getting errors while
working.

So, Please can you people resolve this issue as the python labs are going
on and students are facing some difficulties.

Thanking you


Regards
Ramya M
Instructor, ECE Dept.
JNNCE, Shimoga


Second these comments... you don't have to be in a rush to upgrade to a 
new Python if there are a lot of complex dependencies.


There's a site where you can do a quick check for some of the more 
popular addons:


https://pyreadiness.org

That said, the packages you mention should be available for 3.11 - 
though there could be some dependencies in your chain causing problems.


You haven't given any actionable information. "Getting errors" is a 
meaningless statement without details.  People minded to help aren't 
going to be able to do so.

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


Re: No module named 'playsound'‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏

2023-01-09 Thread Mats Wichmann

On 1/9/23 08:30, Thomas Passin wrote:

On 1/9/2023 9:40 AM, om om wrote:

I'm installing playsound pip install playsound
but it keeps saying No module named playsound
and this error occurs on other packages


Did the installation by pip succeed? if not, what was the error message?

"It keeps saying ...". What keeps saying that (it's not a standard error 
message from pip)? What is the code or command that causes this error 
message?


You would get such a message if you tried to import a package but it had 
not been installed.  If you used pip to install a package and it 
succeeded but you could not import the package (or module), the most 
likely reason is that it got installed by a different version of python 
than the one that used pip to install it.  You may have several 
different versions of Python on your computer.


You can check versions by running

pip -V


As described in this reply, but to be more explicit: if a package 
installed wtihout error, and then you can't import it in Python, it's 
basically always a path problem.


Invoking pip the same way as you did to install, do:

pip show playsound

This will tell you where it put it. If that's not a place your Python is 
looking, it won't find it.




Then use the command you normally use to run Python (i.e., python3, py, 
etc.) and run


py_x -m pip -V

(don't type "py_x", use the command name you normally use to run python)

If the two outputs are different, then you will know for sure that your 
packages got installed to a different version of Python.  Re-install 
them using "python -m pip install" instead of "pip install" - again, 
make sure that you use the actual name for the python command that you 
normally use.



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


Re: Improvement to imports, what is a better way ?

2023-01-18 Thread Mats Wichmann

On 1/18/23 12:29, Paul Bryan wrote:

I would suggest allowing each module to define its own imports, don't
import what a module doesn't consume, keep them simple, avoid devising
a common namespace for each, and let tools like isort/black work out
how to order/express them in source files.


Indeed.  And various checkers will report on unused imports.

These add no value... why import something "as" and give it its own name?


import os as    os
import sys as   sys
import importlib as importlib


A general comment: there are some very common "import ... as" idioms 
(for example, it seems like *everyone* does "import pandas as pd") and 
those are okay to follow, but in general I would stay away from trying 
to give everything short-names.  Each module imported with a name other 
than their own is a memory burden for the reader (maybe even for you!).



import aboutTime as tt  # Time dates timestamps and the
like
import avMedia as   av  # Audio and maybe video 'someday'
well definitely lots of TTS text to speech
import basicSwitchboard as  sc  # First switchboard lurking.
Kickoff to sequence viewers


Any decent editor these days will autocomplete for you, so there's 
really not much if any typing burden in using the full names.


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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-26 Thread Mats Wichmann

On 1/24/23 23:28, Jach Feng wrote:

Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道:

On Wed, 25 Jan 2023 at 14:42, Jach Feng  wrote:

I was happy working with argparse during implement my script. To save the 
typing, I used a default equation for testing.

sample = "-4^2+5.3*abs(-2-1)/2, abs(Abc)*(B+C)/D, (-3) * sqrt(1-(x1/7)*(y1/7)) * 
sqrt(abs((x0-4.5)/(y0-4)))"
parser = argparse.ArgumentParser(description='Convert infix notation to 
postfix')
parser.add_argument('infix', nargs='?', default=sample, help="")


You're still not really using argparse as an argument parser. Why not
just do your own -h checking? Stop trying to use argparse for what
it's not designed for, and then wondering why it isn't doing what you
expect it to magically know.

ChrisA

I just don't get what you mean?


You're still not really using argparse as an argument parser. Why not just do 
your own -h checking?


Is a math equation not qualified as a command line "argument"? What criteria do you use 
when judging the quality of an "argument"?


The ancient UNIX concept, later codified in the POSIX international 
standard, is that if an argument begins with a '-' it specifies an 
option.  The three standard library CLI argument parsers (getopt, 
optparse and argparse) all follow this convention.  You're feeding it 
something that they will conclude is an option, but you have given 
argparse no information how to deal with such an option.  The advice 
you've been given is: this is built in behavior.  You don't want that 
behavior. Either "fool" the module somehow (quoting with leading spaces, 
use the special option identifier of a bare double dash indicating "end 
of options", etc.) - or just don't use a module that behaves in a way 
you don't like.




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


Re: ChatGPT Generated news poster code

2023-02-12 Thread Mats Wichmann

On 2/12/23 07:58, Roland Müller via Python-list wrote:

Hello,

On 2/11/23 03:31, Greg Ewing via Python-list wrote:

For a moment I thought this was going to be a script that
uses ChatGPT to generate a random news post and post it
to Usenet...

Which would also have been kind of cool, as long as it wasn't
overused.


Actually, I like cynical humor too ... But this is too much


Meanwhile, I'm still wondering why I need a program to "chat" to the 
GUID Partition Table


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


Re: LRU cache

2023-02-15 Thread Mats Wichmann

On 2/14/23 15:07, Dino wrote:


Here's my problem today. I am using a dict() to implement a quick and 
dirty in-memory cache.


I am stopping adding elements when I am reaching 1000 elements (totally 
arbitrary number), but I would like to have something slightly more 
sophisticated to free up space for newer and potentially more relevant 
entries.


I am thinking of the Least Recently Used principle, but how to implement 
that is not immediate. Before I embark on reinventing the wheel, is 
there a tool, library or smart trick that will allow me to remove 
elements with LRU logic?


It depends here how fancy you want to get.  If you really need the 
behavior of a size-limited cache and you expect there to be a lot of 
churn, then you'll probably want a combination of data structures... 
e.g. a dict-like thing for quick hashed lookups (means your "keys" need 
to be hashable) and a doubly-linked list for ordering so you can quickly 
move a hit to the most-recent position - and maybe you want to keep 
cache stats as well.


Do look at functools if that well-tested standard library module fits 
your needs. If you need, or are motivated (as a learning experience?) to 
roll your own, my memory tells me the RealPython crew did a tutorial on 
implementing an LRU cache, might be worth a look (not sure if this is 
one of the all-free ones, or one of the 
must-be-a-paid-subscriber-to-get-the-advanced-stuff ones.



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


Re: Precision Tail-off?

2023-02-17 Thread Mats Wichmann

On 2/17/23 11:42, Richard Damon wrote:

On 2/17/23 5:27 AM, Stephen Tucker wrote:


The key factor here is IEEE floating point is storing numbers in BINARY, 
not DECIMAL, so a multiply by 1000 will change the representation of the 
number, and thus the possible resolution errors.


Store you numbers in IEEE DECIMAL floating point, and the variations by 
multiplying by powers of 10 go away.


The development of the original IEEE standard led eventually to 
consistent implementation in hardware (when they implement floating 
point at all, which embedded/IoT class chips in particular often don't) 
that aligned with how languages/compilers treated floating point, so 
that's been a really successful standard, whatever one might feel about 
the tradeoffs. Standards are all about finding a mutually acceptable way 
forward, once people admit there is no One Perfect Answer.


Newer editions of 754 (since 2008) have added this decimal floating 
point representation, which is supported by some software such as IBM 
and Intel floating-point libraries.  Hardware support has been slower to 
arrive.  The only ones I've heard of have been the IBM z series 
(mainframes) and somebody else mentioned Power though I'd never seen 
that. It's possible some of the GPU lines may be going this direction.


As far as Python goes... the decimal module has this comment:

> It is a complete implementation of Mike Cowlishaw/IBM's General 
Decimal Arithmetic Specification.


Cowlishaw was the editor of the 2008 and 2019 editions of IEEE 754, fwiw.

And... this topic as a whole comes up over and over again, like 
everywhere.  See Stack Overflow for some amusement.

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


Re: File write, weird behaviour

2023-02-19 Thread Mats Wichmann

On 2/19/23 14:06, Dieter Maurer wrote:

Azizbek Khamdamov wrote at 2023-2-19 19:03 +0500:

...
Example 2 (weird behaviour)

file = open("D:\Programming\Python\working_with_files\cities.txt",
'r+') ## contains list cities
# the following code DOES NOT add new record TO THE BEGINNING of the
file IF FOLLOWED BY readline() and readlines()# Expected behaviour:
new content should be added to the beginning of the file (as in
Example 1)
file.write("new city\n")

file.readlines()
file.close()

I could not find anything in documentation to explain this strange
behaviour. Why is this happening?


The effect of "r+" (and friends) is specified by the C standard.

The Linux doc (of `fopen`) tells us that ANSI C requires that
a file positioning command (e.g. `seek`) must intervene
between input and output operations. Your example above violates
this condition. Therefore, weird behavior is to be expected.


If this isn't sufficiently described, someone should raise an issue 
against the Python docs.  I know that many concepts are "inherited from" 
environments generally in the POSIX space and the C language, because 
that's where Python was hatched (all of which makes perfect sense to me, 
who's been working in those spaces for...ever), but a Python programmer 
shouldn't have to read the ISO C standard (which is not free, although 
you can find copies on-line), or the POSIX standard (which also is not 
free, though manpages for systems like Linux cover the same material), 
in order to figure out how Python is going to work.

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


Re: Python + Vim editor

2023-02-22 Thread Mats Wichmann

On 2/22/23 11:16, Tramiv wrote:

On 2023-02-22, Hen Hanna  wrote:


what editor do you (all) use to write Python code?  (i use Vim)



For short editin I also use Vim and Pycharm IDE for bigger projects.



The community has submitted some answers to that question here (two 
lists, some entrants don't fit neatly into one or the other):


https://wiki.python.org/moin/PythonEditors
https://wiki.python.org/moin/IntegratedDevelopmentEnvironments

There are a *lot* if you want to rathole... :)




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


Re: lxml with python-3.12.0a5

2023-02-23 Thread Mats Wichmann

On 2/23/23 06:03, Robin Becker wrote:

I'm trying to test python-3.12.0a5 and need to install lxml.

My wheel build for lxml fails with errors like this


src/lxml/etree.c: In function ‘__Pyx_PyIndex_AsSsize_t’:
src/lxml/etree.c:270404:45: error: ‘PyLongObject’ {aka ‘struct 
_longobject’} has no member named ‘ob_digit’

270404 | const digit* digits = ((PyLongObject*)b)->ob_digit;
    | ^~

I'm using archlinux which has gcc 12.2.1. I tested and lxml will build 
with 3.11.2.


I imagine this is part of ongoing changes to the python core, but 
perhaps there's some simple workaround.


Anyone know how to get around this problem. I did try rebuilding the 
cpython stuff using make, but that also failed.


I seem to always have trouble with lxml (which I know doesn't help).

The cause would seem to be this:

GH-101291: Refactor the `PyLongObject` struct into object header 
and PyLongValue struct. (GH-101292)






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


Re: lxml with python-3.12.0a5

2023-02-23 Thread Mats Wichmann

On 2/23/23 07:47, Mats Wichmann wrote:

On 2/23/23 06:03, Robin Becker wrote:

I'm trying to test python-3.12.0a5 and need to install lxml.

My wheel build for lxml fails with errors like this


src/lxml/etree.c: In function ‘__Pyx_PyIndex_AsSsize_t’:
src/lxml/etree.c:270404:45: error: ‘PyLongObject’ {aka ‘struct 
_longobject’} has no member named ‘ob_digit’

270404 | const digit* digits = ((PyLongObject*)b)->ob_digit;
    | ^~

I'm using archlinux which has gcc 12.2.1. I tested and lxml will build 
with 3.11.2.


I imagine this is part of ongoing changes to the python core, but 
perhaps there's some simple workaround.


Anyone know how to get around this problem. I did try rebuilding the 
cpython stuff using make, but that also failed.


I seem to always have trouble with lxml (which I know doesn't help).

The cause would seem to be this:

     GH-101291: Refactor the `PyLongObject` struct into object header 
and PyLongValue struct. (GH-101292)


So it looks to me like cython was affected, and has patched themselves. 
It's possible regenerating with a patched cython will clear up the build 
problem (something which the lxml project takes pains to tell you that 
you don't really want to do :)

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


Re: putting JUNK at the end of a [.py] file

2023-02-24 Thread Mats Wichmann

On 2/23/23 22:16, Thomas Passin wrote:

On 2/23/2023 7:21 PM, Hen Hanna wrote:


in a LaTeX file,   after the (1st)   \end{document} line,
   i can put any random Junk i want    (afterwards)   until the 
end of the file.



Is there a similar Method  for a    .py file ?

Since i know of no such trick,  i sometimes put this (below) at the 
end of a .py file.




dummy= ("""  junk and more junk
   words in Dict
 239  words in Dict
 (((  notes or Code fragmetns  )))
  """ )



**    maybe i don't need the dummy= but it looks better.


You can just put it in triple quotes, no need to assign the string to a 
variable.  Or make each line a comment.




Indeed, I work on a project that by convention puts editor instructions 
at the end of each file (which some might consider junk :-) ), like this:



# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:


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


Re: putting JUNK at the end of a [.py] file

2023-02-24 Thread Mats Wichmann

On 2/24/23 08:27, Mats Wichmann wrote:



Indeed, I work on a project that by convention puts editor instructions 
at the end of each file (which some might consider junk :-) ), like this:



# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:


I should probably have added that I know the above is unnecessary, as 
there is now a standard for defining this stuff once, called 
EditorConfig, which many editors understand natively, and many more via 
plugins.


https://editorconfig.org/


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


Re: Not receiving posts

2023-02-24 Thread Mats Wichmann

On 2/23/23 13:56, Grant Edwards wrote:

On 2023-02-23, Jim Byrnes  wrote:


I have been reading the python-list for some time now. At first via
gemane and since it's demise via a subscription.


FWIW, gmane is still there, and still working fine. I read this list
by pointing slrn at news.gmane.io


Well gmane did die, and caused changes and the story is weird even by 
internet standards.  And the founder eventually spilled


https://lars.ingebrigtsen.no/2020/01/06/whatever-happened-to-news-gmane-org/

Not everything came back the same.

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


Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Mats Wichmann

On 2/26/23 14:07, Hen Hanna wrote:

On Monday, August 29, 2022 at 7:18:22 PM UTC-7, Paul Rubin wrote:

Just because.

from math import gcd



def fizz(n: int) -> str:
match gcd(n, 15):
   case 3: return "Fizz"
   case 5: return "Buzz"
   case 15: return "FizzBuzz"
   case _: return str(n)

for i in range(1,101):
 print(fizz(i))



is there any reason to prefer"over'   ?


If you intend to run Black on your code to ensure consistent formatting, 
you may as well learn to prefer double quotes, because it's going to 
convert single to double (or: don't learn, and set your IDE to "convert 
on save" and don't think about it...)


As has already been mentioned, syntactically there is no difference.



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


Re: Python 3.10 Fizzbuzz

2023-02-28 Thread Mats Wichmann

On 2/27/23 16:42, Oscar Benjamin wrote:

On Mon, 27 Feb 2023 at 21:06, Ethan Furman  wrote:


On 2/27/23 12:20, rbowman wrote:

  > "By using Black, you agree to cede control over minutiae of hand-
  > formatting. In return, Black gives you speed, determinism, and freedom
  > from pycodestyle nagging about formatting. You will save time and mental
  > energy for more important matters."
  >
  > Somehow I don't think we would get along very well. I'm a little on the
  > opinionated side myself.

I personally cannot stand Black.  It feels like every major choice it makes 
(and some minor ones) are exactly the
opposite of the choice I make.


I agree partially. There are two types of decisions black makes:

1. Leave the code alone because it seems okay or make small modifications.
2. Reformat the code because it violates some generic rule (like line
too long or something).

I've recently tried Black and mostly for my code it seems to go with 1
(code looks okay). There might be some minor changes like double vs
single quotes but I really don't care about those. In that sense me
and Black seem to agree.

However I have also reviewed code where it is clear that the author
has used black and their code came under case 2. In that case Black
seems to produce awful things. What I can't understand is someone
accepting the awful rewrite rather than just fixing the code. Treating
Black almost like a linter makes sense to me but accepting the
rewrites that it offers for bad code does not.


The amount of disagreement you see here and elsewhere are exactly why 
Black  is like it is - virtually without options.  It doesn't aim to 
solve the challenge of producing The Most Beautiful Code Layout, for 
*you*, or even for any moderately sized group of programmers.  Instead 
it's to remove the bickering:

1. we choose to use black for a project.
2. black runs automatically
3. there is now no need to spend cycles thinking about code-style 
aspects in reviews, or when we're making changes, because black makes 
sure the code aligns with the chosen style (1).


Many teams find the removal of this potential disagreement valuable - 
there's plenty of more important stuff to spend time on. If as an 
individual user, not trying to conform to style choices of a project, it 
doesn't appeal, there's no need to fuss with it.


One can certainly pick a different code style, and make sure it's 
captured in the rules for one of the several more flexible formatting 
tools (for example, I *used* to use yapf pretty regularly, and had that 
tuned as I wanted)

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


Re: How to fix this issue

2023-03-01 Thread Mats Wichmann

On 2/27/23 17:51, Arslan Mehmood wrote:

How I can remove python terminl, its again and again open during working in 
python. Please help me to resolve this issue.
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.





We have no idea what you think the "issue" is. Perhaps if you attempted 
a bit more of an explanation?  You're working with Python, and the 
Python interpreter appears. On the surface, that doesn't seem horribly 
unusual.


Have you read this?

https://docs.python.org/3/using/windows.html


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


Re: Regular Expression bug?

2023-03-02 Thread Mats Wichmann

On 3/2/23 12:28, Chris Angelico wrote:

On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera  wrote:


Greetings.

For the RegExp Gurus, consider the following python3 code:

import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)

print(r0.group(1))

align upgrade


This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.



Not a bug. Find the longest possible match that fits this; as long as
you can find a space immediately after it, everything in between goes
into the .+ part.

If you want to exclude spaces, either use [^ ]+ or .+?.



https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy

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


Re: Cryptic software announcements (was: ANN: DIPY 1.6.0)

2023-03-05 Thread Mats Wichmann

On 3/1/23 04:57, Rob Cliffe via Python-list wrote:


I think it would be a good idea if software announcements would include
a single paragraph (or maybe just a single sentence) summarizing what
the software is and does.

 hp



+1
Rob Cliffe


Excellent adivce - and many of the announcements on the separate 
python-announce list do actually follow this model (and this is probably 
actually the right place to send announcements).


I'd even extend the suggestion further - it's surprising how many 
newcomers ask questions about a particular package that many people have 
not heard of - it all seems so obvious when you have an assignment, but 
when there are over 400,000 packages on PyPI it should actually not be 
surprising that a few of us have not actually heard of all of them :-) 
Maybe give a bit more context...


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


Re: Friday finking: IDE 'macro expansions'

2023-03-16 Thread Mats Wichmann

On 3/16/23 16:55, dn via Python-list wrote:
It is a long, long, time since I've thrown one of these into the 
maelstrom of our musings.

(have the nightmares receded?)


Do you make use of your IDE's expansionist tendencies, and if-so, which 
ones?



NB this is where vi/emacs enthusiasts start chuckling (polite term for 
'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'!
Also: I'm talking 'PyCharm' because of the story, but others use Codium, 
Sublime Text, etc - which presumably offer equivalent features.



Was helping a friend install PyCharm. Jumped into the Settings. Isn't it 
incredible how many there are?


Idly noted that there are two short-cut or macro-expansion types of 
facilities:

- Postfix Completion, (nothing to do with email or polish notation) and
- Live Templates (again, we're not talking about jinja2)


With both, one types an abbreviated-name and the IDE will expand it into 
appropriate code. For (LiveTemplate) example, typing compli and pressing 
Tab induces PyCharm to add the following to the program[me]:


     [ ! for ! in !drop-down menu! if ! ]

It offers further typo-saving through the drop-down menu which lists a 
bunch of likely (iterable) candidates from amongst previously-written 
code. The action continues after selecting from the menu, by inviting 
completion of the other ("!") placeholders, in-turn.



I haven't made use of such a tool, to-date - OK, yes, I have practised a 
high typing-speed (and accuracy). Puff, puff...


Also, at the time, I'm thinking in 'code', rather than about what tool 
might implement said ideas.



Do you make use of such expansionist-tendencies?

Do you make use of other powerful features within the IDE, or are its 
editor functionalities employed at pretty-much the NotePad level?


Not sure the purpose of the "survey" but - no, I don't use these.  IDEs 
are incredible things, but you need to invest yourself completely in 
them, basically live in them, or there's not that much payback. There's 
just too much to remember, and honestly, too much mouse movement needed, 
especially if you have a big screen. In the PyCharm case, the startup 
time is incredibly slow, so, since I don't "live in it", I don't use it 
much any more - there are some things it does superbly, but it's such a 
cost to fire it up just for those I pretty much don't bother any more.


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


Re: Numpy, Matplotlib crash Python 3.8 Windows 7, 32-bit - can you help ?

2023-03-23 Thread Mats Wichmann

On 3/23/23 09:48, Thomas Passin wrote:

I didn't realize that Christoph Gohlke is still maintaining this site. 


Unless the the last-changed stuff stopped working, it's in a static state:

by Christoph Gohlke. Updated on 26 June 2022 at 07:27 UTC



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


Re: Patrick Sheehan: Major Issues with Python

2023-03-26 Thread Mats Wichmann

On 3/25/23 14:03, Patrick Sheehan wrote:

Hello,
I have been working with the attached book (See photo) to try to learn
Python and so far it has been a complete nightmare trying to get python
installed and operating correctly.  I have received a plethora of error
messages and consulted youtube videos and chat groups to try to remedy the
issues.  I am using a computer that is running Windows 10.  I have
installed, and un-installed several versions of Python and was able to
complete the first two lessons in the attached book, but could not complete
lesson 3 (Turtledemo)...Some of the error messages I have received
include:  "This app cannot run on your PC"; "Unable to initialize device
PRN"; “Python is not recognized as an internal or external command”:
"Python was not found: run without arguments to install from Microsoft
Store, or disable this shortcut from settings mange, app execution
aliases:"...


If you installed the conventional way, use the command name "py" instead 
of "python" to run things from a command shell.  Alternatively, you 
could try an installation of Python from the Microsoft Store (as the 
little stub program named python, which Microsoft preinstalls for the 
express purpose of giving you this hint).  There are times when getting 
Python working without hassle is easier when going that route.


You *can* add python to the search PATH, there's an option in the 
installer (you can rerun this from the Apps & features Settings 
applet)... in the screen for advanced options there's something that 
says "Add python to environment variables" or similar wording.


>I have been at this for 4 days now at least three hours each

day...Any information or help you can provide would be greatly
appreciated.  Additionally, I do have PyCharm installed (As you can tell, I
am a beginner), is PyCharm the same thing as Python? 


No. It's an "integrated development environment" - editor, debugger, 
source control wrangler and many other things.  It still needs to have a 
working Python installed. It will probably find the installed Python 
more easily than you will.  The concept of an IDE is you can do all your 
programming work without leaving it - you don't have to hop between 
editor, command line, and invoke other tools.  PyCharm is only one of 
many entrants in this space for Python programmers.  It's excellent, but 
I find it rather, ummm, "bulky", for beginners - there are a ton of 
features you'll not use early on in your journey, and thus I find it 
makes it much harder to find the things you do need in menus, help, etc. 
Up to you whether you push ahead with using it now, or leave it for a 
bit later when you're doing more complex things.


We have no idea what book you're using, by the way, as the list strips 
images and other attachments.  In any case, there are hundreds of Python 
books out now, most of us don't know about a particular one (unless we 
wrote it :) )



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


Re: How does a method of a subclass become a method of the base class?

2023-03-27 Thread Mats Wichmann

On 3/26/23 17:53, Jen Kris via Python-list wrote:


I’m asking all these question because I have worked in a procedural style for 
many years, with class work limited to only simple classes, but now I’m 
studying classes in more depth. The three answers I have received today, 
including yours, have helped a lot.


Classes in Python don't work quite like they do in many other languages.

You may find a lightbulb if you listen to Raymond Hettinger talk about them:

https://dailytechvideo.com/raymond-hettinger-pythons-class-development-toolkit/

I'd also advise that benchmarks often do very strange things to set up 
the scenario they're trying to test, a benchmark sure wouldn't be my 
first place to look in learning a new piece of Python - I don't know if 
it was the first place, but thought this was worth a mention.



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


Re: recent-files

2023-03-28 Thread Mats Wichmann

On 3/28/23 16:39, [email protected] wrote:

In Python 3.11.2,  the recent-files list keeps always increasing because
it is impossible to edit the list; the corresponding .txt file has
disappeared.
Please help!


Please explain what you're asking about. What recent-files list? Python 
itself has no such concept.



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


Re: Ole version set as default

2023-03-29 Thread Mats Wichmann

On 3/29/23 10:46, Pranav Bhardwaj wrote:

Dear sir,
I am Pranav Bhardwaj and I stuck in a problem. My problem is
that in my system I have python 3.11.2 but when I type python in my command
prompt, my command prompt show that python version 2.7.13 as a default. And
I can't be able to find python 2.7.13 in my system in any file


once you open that Olde Python that you can't find:

>>> import sys
>>> sys.executable

voila! you've found it.

 and I tried

various methods to set python 3.11.2 as a default but can't be able to do
so. I tried to change environment variables, try to find and delete python
2.7.13 , try to set python 3.11.2 as default, but I can't be able to do so.
So can you help me how can I solve this problem?


As noted elsewhere, for the python.org version, the Python Launcher 
exists for this purpose.


py --list

shows you which Pythons it knows about, and with a '*' which one is the 
default. You can instruct py which one should be default (for that you 
need to create an ini file), but it will otherwise choose the latest, so 
you shouldn't have the problem of it choosing 2.7 over 3.11 with the 
launcher.



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


Re: Windows Gui Frontend

2023-04-01 Thread Mats Wichmann

On 4/1/23 11:34, Eryk Sun wrote:

On 4/1/23, Jim Schwartz  wrote:

Are there any ide’s that will let me design the screen and convert it to
python?  I doubt it because it was mentioned that this is time consuming.

Thanks for the responses everyone. I appreciate it.


For Qt, the WYSIWYG UI editor is Qt Designer. The basics are covered
in the following PySide tutorial:

https://www.pythonguis.com/pyside2-tutorial


Also here is a decent tutorial:

https://realpython.com/qt-designer-python/


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


Re: Problem in using libraries

2023-04-04 Thread Mats Wichmann

On 4/3/23 10:43, Pranav Bhardwaj wrote:

Why can't I able to use python libraries such as numpy, nudenet, playsound,
pandas, etc in my python 3.11.2. It always through the error "import
'numpy' or any other libraries could not be resolved".


Will restate what others have said in the hopes it might be even more 
clear that way.


Python has an internal search path that it uses to find the module when 
you ask to "import".  If a module is not found, that means it's not in 
the search path ("it's always a path problem"). You installed it, sure - 
but it went somewhere else.


The search path is installation-specific (not just version-specific: for 
example if you have a system install of 3.10.x, and a virtualenv using 
the same 3.10.x, those will have different search paths). The search 
path can be amended or changed, but that's a different story.


If you're going to install with pip, use the same Python you're going to 
do your work with. Don't trust that a command named "pip" maps to the 
same installation as that Python command. For that, either use an 
activated virtualenv, or do "name-of-my-python -m pip install".  You can 
always check your work by doing "name-of-my-python -m pip list" - what 
does that particular installation see as installed?


Or - if you're using the classic set of "scientific" packages like numpy 
and pandas, you might look at installing it all using conda instead of 
pip: it to a large extent exists to help with getting those very common 
bundles of things set up without going through the wrestling match 
you're going though.

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


Re: Christoph Gohlke and compiled packages

2023-04-11 Thread Mats Wichmann

On 4/11/23 06:03, Roel Schroeven wrote:

Op 11/04/2023 om 12:58 schreef Chris Angelico:



Python itself is fine, but a lot of third-party packages are hard to
obtain. So if you need numpy, for instance, or psycopg2, you might
need to find an alternative source.
These days I use pip to install packages, and so far for the things I 
need it simply works. "pip install numpy" works, same for psycopg2, 
pillow, pandas, and other packages I use. Conda should work too, for 
those who use the Anaconda Python distribution. I honestly don't even 
know how it's done: are there some kind souls who provide the wheels 
(binary packages) for all those things, or if there is maybe a build 
farm that does the hard work to make things easy for us.


In the past I've used Christoph Gohlke's site and I'm very grateful for 
the service it provided, but these days I don't really need it anymore, 
luckily.


The deal really is, the instant a new Python version drops (3.11, 3.12, 
etc.) a million people rush to install it, some of whom should know 
better and be more patient.  3rd party packages are their own projects, 
some have binary wheels ready on Python release day, some soon after, 
some months after. That's the main hole this site filled in more recent 
times: for people who feel they must jump forward but their key packages 
were not yet ready, they were probably here. (I should add - it's not 
always impatience, sometimes folks are also being proactive and want to 
test Python betas, etc. so they're prepared, and they'll of course hit 
the same problem of some wheels not being available).


There's even a "readiness" site folks can check (also volunteer-run),

https://pyreadiness.org/

but often the lure of the new shiny thing just wins out.  I predict 
we'll have a flood of anguish again in the fall when 3.12.0 comes out.


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


Re: Christoph Gohlke and compiled packages

2023-04-11 Thread Mats Wichmann

On 4/11/23 11:48, Oscar Benjamin wrote:

On Tue, 11 Apr 2023 at 14:55, Mats Wichmann  wrote:


On 4/11/23 06:03, Roel Schroeven wrote:

Op 11/04/2023 om 12:58 schreef Chris Angelico:



Python itself is fine, but a lot of third-party packages are hard to
obtain. So if you need numpy, for instance, or psycopg2, you might
need to find an alternative source.

These days I use pip to install packages, and so far for the things I
need it simply works. "pip install numpy" works, same for psycopg2,
pillow, pandas, and other packages I use. Conda should work too, for
those who use the Anaconda Python distribution. I honestly don't even
know how it's done: are there some kind souls who provide the wheels
(binary packages) for all those things, or if there is maybe a build
farm that does the hard work to make things easy for us.

In the past I've used Christoph Gohlke's site and I'm very grateful for
the service it provided, but these days I don't really need it anymore,
luckily.


The deal really is, the instant a new Python version drops (3.11, 3.12,
etc.) a million people rush to install it, some of whom should know
better and be more patient.  3rd party packages are their own projects,
some have binary wheels ready on Python release day, some soon after,
some months after.


You can hardly blame a lot of people for doing this. A seb search for
"download python" gives this as the first hit:
https://www.python.org/downloads/

I am guessing that the release process automatically updates that page
so that the minute 3.12 gets released the big yellow button will
suggest downloading 3.12.0 as the default option.


Yes, you're quite right about that.


Perhaps it is really package authors who should be getting a release
out that is compatible with Python 3.12 before 3.12 itself is
released. It's tricky though because as a maintainer it makes more
sense to wait until you see the finished 3.12 product before making a
release that is fully tested with it (even if you are testing the
alphas etc in CI and making incremental fixes before 3.12 is
released).


If you can find the incantation there are often pending builds for 
packages that need binary wheels, it may be "pip --pre" or it may be 
pointing to test.pypi.org... or there may not be. The projects may not 
tell you.  And for many less experienced users (and yes this is a known 
issue), they have no idea they need to look.



The other option could be changing the downloads page so that it does
not suggest 3.12.0 as the default option until it is clear that at
least some baseline of widely used packages have uploaded compatible
wheels.


There's been some suggestion of that before. Apparently the choice of 
what goes there is at least a bit political.  Like many projects, I 
believe python prefers to recommend "the latest and best release", while 
user prudence (and especially organizational prudence) tends to say 
"hold off for a while until it's been fully vetted, and the ecosystem 
catches up". I don't think we can cast too much blame on either: I don't 
expect Microsoft will say "Don't download Windows 12 for the first six 
months", even if they know perfectly well that many enterprise customers 
will take an approach like that.


Not sure there's any really good answer, TBH.



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


Re: Weak Type Ability for Python

2023-04-12 Thread Mats Wichmann

On 4/12/23 11:11, Chris Angelico wrote:

On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
 wrote:


Hi all,
Please make this command for Python (if possible):


x=1
y='a'
wprint (x+y)
1a


In fact make a new type of print command which can print and show strings
and integers together.



Try:

print(x, y)

ChrisA



To continue on, what do you want "addition" of dissimilar types to do - 
since that's what you have asked for above.


You can write yourself an object which is happy with certain 
combinations, so you don't have this scenario:


>>> x + y
Traceback (most recent call last):
  File "", line 1, in 
x + y
 ~~^~~
TypeError: can only concatenate str (not "int") to str
>>> y + x
Traceback (most recent call last):
  File "", line 1, in 
y + x
 ~~^~~
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>


Or you can help out the print function by doing some of the fiddling 
yourself:


>>> print(f"{x}{y}")
1a




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


Re: PyCharm's strict PEP and not so strict?

2023-04-20 Thread Mats Wichmann

On 4/19/23 17:19, dn via Python-list wrote:

The "light bulb" has little to do with "quotes"! This is one of the 
advantages of utilising a Python-native IDE (cf a more general-purpose 
alternative, perhaps with some Python add-on). PyCharm attempts to 
understand the code it is editing, and apply various lessons or 
experiences to offer intelligent assistance.


To nitpick a little bit, PyCharm isn't *exactly* Python-native, it's a 
derivative of the IntelliJ generic IDE platform (written in, sigh, Java) 
with a *very* evolved Python add-on and packaged in such a way as to 
make it look as if it weren't an addon at all (but if you lift the 
covers up you can see the roots)



Builtin bits are very configurable, usually, but I haven't found that 
the Python code inspection (this is the stuff that by default gives you 
the PEP8-type warnings) is particularly so - be happy to stand corrected 
on that. However, you can configure an external tool - say, pylint - and 
if you do, you configure that in the normal way (a .pylintrc rcfile, or 
a toml config file). If you do this, you can turn off those style checks 
from the builtin checker.   If you want.


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


Re: Incomplete sys.path with embeddable python (Windows)!?

2023-04-21 Thread Mats Wichmann

On 4/20/23 15:47, Ralf M. wrote:

Hello,

when I run a script with a "normally" installed python, the directory 
the script resides in is automatically added as first element to 
sys.path, so that "import my_local_module" finds my_local_module.py in 
the directory of the script.


However, when I run the same script with embeddable python ("Windows 
embeddable package (64-bit)", download link
https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) 
the script directory is *not* prepended to the path, thus "import 
my_local_module" gives an ImportError.


This is intended behavior - the question comes up from time to time. The 
embeddable distribution is intended to be part of an application, not a 
general-purpose Python you can call for just anything.


There are a bunch of details here, for example:

https://github.com/python/cpython/issues/79022


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


Re: Incomplete sys.path with embeddable python (Windows)!?

2023-04-23 Thread Mats Wichmann

On 4/22/23 16:04, Ralf M. wrote:

Am 21.04.2023 um 18:07 schrieb Thomas Passin:

On 4/20/2023 5:47 PM, Ralf M. wrote:

Hello,

when I run a script with a "normally" installed python, the directory 
the script resides in is automatically added as first element to 
sys.path, so that "import my_local_module" finds my_local_module.py 
in the directory of the script.


However, when I run the same script with embeddable python ("Windows 
embeddable package (64-bit)", download link

https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script 
directory is *not* prepended to the path, thus "import my_local_module" gives 
an ImportError.

I couldn't find an option to get the "normal" behaviour. Any ideas 
how to do that?


What I tried so far:
[...]
* I can add the following lines to every script:
 import sys
 script_path = __file__.rsplit("\\", 1)[0]
 if script_path not in sys.path:
 sys.path[0:0] = [script_path]
 import my_local_modul
[...] 


Have used this stanza (actually, for the inverse purpose, to remove that 
script's dir from sys.path, but whatever...):


script_dir = os.path.dirname(os.path.realpath(__file__))

you can then insert it:

sys.path.insert(0, script_dir)

or just add:

sys.path = [script_dir] + sys.path

assuming you want it at the front...

but it doesn't really solve your problem of needing it *everywhere*...

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


Re: Is npyscreen still alive?

2023-04-24 Thread Mats Wichmann

On 4/24/23 10:32, Grant Edwards wrote:

On 2023-04-24, Grant Edwards  wrote:


The other big advantage of an ncurses program is that since curses
support is in the std library, a curses app is simpler to
distribute.  Right now, the application is a single .py file you
just copy to the destination machine and run.  It supports
command-line use and a Tk GUI. I can add an ncurses "CUI" without
having to either adopt a more complex bundling mechanism that
requires it to be "installed" or require that users install
dependencies via pip/apt/yum/whatever.


However... I just realized that Python's curses support is missing two
huge chunks: both menu and form support are not there.  I guess that
explains why people feel the need to write high-level UI wrappers for
Python curses: the high level stuff that curses does support is
missing from the Python bindings.

Adding a curses UI for my app might not be feasible after all...

--
Grant



I guess it's also worth mentioning that Python curses doesn't work out 
of the box on Windows - because the actual curses library isn't commonly 
present on Windows. It's not hard to get hold of builds (check PyPI) but 
that means it's no longer "standard".





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


Re: How to 'ignore' an error in Python?

2023-04-28 Thread Mats Wichmann

On 4/28/23 09:55, Chris Green wrote:

I'm sure I'm missing something obvious here but I can't see an elegant
way to do this.  I want to create a directory, but if it exists it's
not an error and the code should just continue.

So, I have:-

 for dirname in listofdirs:
 try:
 os.mkdir(dirname)
 except FileExistsError:
 # so what can I do here that says 'carry on regardless'
 except:
 # handle any other error, which is really an error

 # I want code here to execute whether or not dirname exists


Do I really have to use a finally: block?  It feels rather clumsy.


For this specific case, you can use os.makedirs:

os.makedirs(dirname, exist_ok=True)

The mkdir in pathlib also takes the exist_ok flag


As to the way you asked the question, you can use "pass" or the ellipses 
for the "# so what can I do here"



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


Re: How to 'ignore' an error in Python?

2023-04-28 Thread Mats Wichmann

On 4/28/23 11:05, MRAB wrote:

On 2023-04-28 16:55, Chris Green wrote:

I'm sure I'm missing something obvious here but I can't see an elegant
way to do this.  I want to create a directory, but if it exists it's
not an error and the code should just continue.

So, I have:-

 for dirname in listofdirs:
 try:
 os.mkdir(dirname)
 except FileExistsError:
 # so what can I do here that says 'carry on regardless'
 except:
 # handle any other error, which is really an error



I'd do this:

     from contextlib import suppress

     for dirname in listofdirs:
     with suppress(FileExistsError):
     os.mkdir(dirname)


I'm fond of that approach too, though you can't use if it you really 
wanted to do the


  except:
  # handle any other error, which is really an error

If you're okay letting Python just raise whatever other error it found, 
then great!



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


Re: Disable 'style PEP' messages

2023-05-04 Thread Mats Wichmann

On 5/4/23 10:28, Kevin M. Wilson via Python-list wrote:

Hi... How do I set Pycharm to find only syntax errors?!!


By configuring PyCharm the way you want.

See PyCharm's documentation for how to do that.

Hint:

Settings -> Editor -> Code Style -> Inspections




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


Re: Do subprocess.PIPE and subprocess.STDOUT sametime

2023-05-09 Thread Mats Wichmann

On 5/9/23 12:13, Horst Koiner wrote:

Hi @all,
i'm running a program which is still in development with subprocess.run (Python 
version 3.10), further i need to capture the output of the program in a python 
variable. The program itself runs about 2 minutes, but it can also freeze in 
case of new bugs.

For production i run the program with stdout=subprocess.PIPE and i can fetch 
than the output later. For just testing if the program works, i run with 
stdout=subprocess.STDOUT and I see all program output on the console, but my 
program afterwards crashes since there is nothing captured in the python 
variable. So I think I need to have the functionality of subprocess.PIPE and 
subprcess.STDOUT sametime.


I'm not sure you quite understood what subprocess.STDOUT is for.  If you 
say nothing stdout is not captured. STDOUT is used as a value for stderr 
to mean send it the same place as stdout, which is useful if you set 
stdout to something unusual, then you don't have to retype it if you 
want stderr going the same place.  The subprocess module, afaik, doesn't 
even have a case for stdout=STDOUT.




What I tried until now:
1. Poll the the output and use Popen instead:

# Start the subprocess
process = subprocess.Popen(['./test.sh'], stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)

captured_output = b''
process_running = True
while process_running:
 process_running = (process.poll() is not None)
 for pipe in [ process.stdout, process.stderr ]:
 while line := pipe.readline():
 print(line)
 captured_output += line

print(captured_output)
return_code = process.returncode

=> But this is discouraged by the python doc, since it says that polling this 
way is prone to deadlocks. Instead it proposes the use of the communicate() 
function.

2. Use communicate() with timeout.
=> This works not at all since when the timeout occurs an exception is thrown 
and communicate returns at all.


Well, sure ... if you set timeout, then you need to be prepared to catch 
the TimeoutExpired exception and deal with it. That should be entirely 
normal.




3. Use threading instead
=> For being that simple and universal like subprocess you will more or less 
reimplement subprocess with threading, like its done in subprocess.py. Just for a 
debug output the effort is much to high.


Not sure I get what this is asking/suggesting.  If you don't want to 
wait for the subprocess to run, you can use async - that's been fully 
implemented.


https://docs.python.org/3/library/asyncio-subprocess.html



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


Re: Black boxes

2023-05-10 Thread Mats Wichmann

On 5/10/23 08:19, Ondřej Jůn wrote:

Good day.

After installing the Python program from your site and restarting the
computer as requested by the program, problems occurred.


That's rather suspicious, because the python installer doesn't do that. 
That's only needed if you replace files in use by the running system, 
and a fresh install of Python wouldn't be "replacing" anything, now 
would it?


What exactly did you install?


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


Re: Do subprocess.PIPE and subprocess.STDOUT sametime

2023-05-10 Thread Mats Wichmann

On 5/10/23 12:51, Dieter Maurer wrote:

Horst Koiner wrote at 2023-5-9 11:13 -0700:

...
For production i run the program with stdout=subprocess.PIPE and i can fetch 
than the output later. For just testing if the program works, i run with 
stdout=subprocess.STDOUT and I see all program output on the console, but my 
program afterwards crashes since there is nothing captured in the python 
variable. So I think I need to have the functionality of subprocess.PIPE and 
subprcess.STDOUT sametime.


You might want to implement the functionality of the *nix programm
`tee` in Python.
`tee` reads from one file and writes the data to several files,
i.e. it multiplexes one input file to several output files.

Pyhton's `tee` would likely be implemented by a separate thread.

For your case, the input file could be the subprocess's pipe
and the output files `sys.stdout` and a pipe created by your own
used by your application in place of the subprocess's pipe.


should you choose to go this route, there are multiple efforts floating 
around on the internet, worth a look. Don't know which are good and 
which aren't.  Went looking once to see if there was something to 
replace a homegrown function that wasn't reliable - ended up solving 
that particular problem a different way so didn't use any of the tees.



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


Re: pip module not found

2023-05-12 Thread Mats Wichmann

On 5/12/23 00:42, David John wrote:

Hi,
I recently have been experiencing issues with the pip installation module.


How?  Please be explicit or nobody can answer your question.



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


  1   2   3   4   >