Re: shutil.rmtree() fails when used in Fedora (rpm) "mock" environment

2024-10-24 Thread Dan Sommers via Python-list
On 2024-10-24 at 20:54:53 +0100,
MRAB via Python-list  wrote:

> On 2024-10-24 20:21, Left Right wrote:
> > > > > The stack is created on line 760 with os.lstat and entries are 
> > > > > appended
> > > > > on lines 677 (os.rmdir), 679 (os.close) and 689 (os.lstat).
> > > > >
> > > > > 'func' is popped off the stack on line 651 and check in the following 
> > > > > lines.
> > > > >
> > > > > I can't see anywhere else where something else is put onto the stack 
> > > > > or
> > > > > an entry is replaced.
> > 
> > But the _rmtree_safe_fd() compares func to a *dynamically* resolved
> > reference: os.lstat. If the reference to os changed (or os object was
> > modified to have new reference at lstat) between the time os.lstat was
> > added to the stack and the time of comparison, then comparison
> > would've failed.  To illustrate my idea:
> > 
> > os.lstat = lambda x: x # thread 1
> > stack.append((os.lstat, ...)) # thread 1
> > os.lstat = lambda x: x # thread 2
> > func, *_ = stack.pop() # thread 1
> > assert func is os.lstat # thread 1 (failure!)
> > 
> > The only question is: is it possible to modify os.lstat like that, and
> > if so, how?
> > 
> > Other alternatives include a malfunctioning "is" operator,
> > malfunctioning module cache... all those are a lot less likely.
> What is the probability of replacing os.lstat, os.close or os.rmdir from
> another thread at just the right time?

That is never the right question in a multi-threaded system.  The answer
is always that is doesn't matter, the odds will beat you in the end.  Or
sometimes right in the middle of a CPU instruction; does anyone remember
the MC680XX series?

Yes, as a matter of fact, I did used to make my living designing,
building, delivering, and maintaining such systems.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-10-11 Thread Dan Ciprus (dciprus) via Python-list

Thank you for the hint !

On Fri, Oct 04, 2024 at 09:17:19AM GMT, Cameron Simpson wrote:

On 03Oct2024 22:12, Dan Ciprus (dciprus)  wrote:

I'd be interested too :-).


Untested sketch:

   def make_thread(target, *a, E=None, **kw):
   '''
   Make a new Event E and Thread T, pass `[E,*a]` as the target 
positional arguments.

   A shared preexisting Event may be supplied.
   Return a 2-tuple of `(T,E)`.
   '''
   if E is None:
 E = Event()
   T = Thread(target=target, args=[E, *a], kwargs=kw)
   return T, E

Something along those lines.

Cheers,
Cameron Simpson 


--
Dan Ciprus

[ curl -L http://git.io/unix ]


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


Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-10-03 Thread Dan Ciprus (dciprus) via Python-list

I'd be interested too :-).

On Thu, Sep 26, 2024 at 03:34:05AM GMT, marc nicole via Python-list wrote:

Could you show a python code example of this?


On Thu, 26 Sept 2024, 03:08 Cameron Simpson,  wrote:


On 25Sep2024 22:56, marc nicole  wrote:
>How to create a per-thread event in Python 2.7?

Every time you make a Thread, make an Event. Pass it to the thread
worker function and keep it to hand for your use outside the thread.
___
Tutor maillist  -  tu...@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


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


--
Dan Ciprus

[ curl -L http://git.io/unix ]


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


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-10-01 Thread Dan Sommers via Python-list
On 2024-10-01 at 23:03:01 +0200,
Left Right  wrote:

> > If I recognize the first digit, then I *can* hand that over to an
> > external function to accumulate the digits that follow.
> 
> And what is that external function going to do with this information?
> The point is you didn't parse anything if you just sent the digit.
> You just delegated the parsing further. Parsing is only meaningful if
> you extracted some information, but your idea is, essentially "what if
> I do nothing?".

If the parser detects the first digit of a number, then the parser can
read digits one at a time (i.e., "streaming"), assimilate and accumulate
the value of the number being parsed, and successfully finish parsing
the number it reads a non-digit.  Whether the function that accumulates
the value during the process is internal or external isn't relevant; the
point is that it is possible to parse integers from most significant
digit to least significant digit under a streaming model (and if you're
sufficiently clever, you can even write partial results to external
storage and/or another transmission protocol, thus allowing for numbers
bigger (as measured by JSON or your internal representation) than your
RAM).

At most, the parser has to remember the non-digit character it read so
that it (the parser) can begin to parse whatever comes after the number.
Does that break your notion of "streaming"?

Why do I have to start with the least significant digit?

> > Under that constraint, I'm not sure I can parse anything.  How can I
> > parse a string (and hand it over to an external function) until I've
> > found the closing quote?
> 
> Nobody says that parsing a number is the only pathological case.  You,
> however, exaggerate by saying you cannot parse _anything_. You can
> parse booleans or null, for example.  There's no problem there.

My intent was only to repeat what you implied:  that any parser that
reads its input until it has parsed a value is not streaming.

So how much information can the parser keep before you consider it not
to be "streaming"?

[...]

> In principle, any language that has infinite words will have the same
> problem with streaming [...]

So what magic allows anyone to stream any JSON file over SCSI or IP?
Let alone some kind of "live stream" that by definition is indefinite,
even if it only lasts a few tenths of a second?

> [...] If you ever pondered h/w or low-level
> protocols s.a. SCSI or IP [...]

I spent a good deal of my career designing and implementing all manner
of communicaations protocols, from transmitting and receiving single
bits over a wire all the way up to what are now known as session and
presentation layers.  Some imposed maximum lengths in certain places;
some allowed for indefinite amounts of data to be transferred from one
end to the other without stopping, resetting, or overflowing.  And yet
somehow, the universe never collapsed.

If you believe that some implementation of fsync fails to meet a
specification, or fails to work correctly on files containign JSON, then
file a bug report.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-10-01 Thread Dan Sommers via Python-list
On 2024-09-30 at 21:34:07 +0200,
Regarding "Re: Help with Streaming and Chunk Processing for Large JSON Data (60 
GB) from Kenna API,"
Left Right via Python-list  wrote:

> > What am I missing?  Handwavingly, start with the first digit, and as
> > long as the next character is a digit, multipliy the accumulated result
> > by 10 (or the appropriate base) and add the next value.  Oh, and handle
> > scientific notation as a special case, and perhaps fail spectacularly
> > instead of recovering gracefully in certain edge cases.  And in the
> > pathological case of a single number with 60 billion digits, run out of
> > memory (and complain loudly to the person who claimed that the file
> > contained a "dataset").  But why do I need to start with the least
> > significant digit?
> 
> You probably forgot that it has to be _streaming_. Suppose you parse
> the first digit: can you hand this information over to an external
> function to process the parsed data? -- No! because you don't know the
> magnitude yet.  What about two digits? -- Same thing.  You cannot
> leave the parser code until you know the magnitude (otherwise the
> information is useless to the external code).

If I recognize the first digit, then I *can* hand that over to an
external function to accumulate the digits that follow.

> So, even if you have enough memory and don't care about special cases
> like scientific notation: yes, you will be able to parse it, but it
> won't be a streaming parser.

Under that constraint, I'm not sure I can parse anything.  How can I
parse a string (and hand it over to an external function) until I've
found the closing quote?

How much state can a parser maintain (before it invokes an external
function) and still be considered streaming?  I fear that we may be
getting hung up on terminology rather than solving the problem at hand.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-10-01 Thread Dan Sommers via Python-list
On 2024-09-30 at 18:48:02 -0700,
Keith Thompson via Python-list  wrote:

> 2qdxy4rzwzuui...@potatochowder.com writes:
> [...]
> > In Common Lisp, you can write integers as #nnR[digits], where nn is the
> > decimal representation of the base (possibly without a leading zero),
> > the # and the R are literal characters, and the digits are written in
> > the intended base.  So the input #16f is read as the integer 65535.
> 
> Typo: You meant #16R, not #16f.

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


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-09-30 Thread Dan Sommers via Python-list
On 2024-10-01 at 09:09:07 +1000,
Chris Angelico via Python-list  wrote:

> On Tue, 1 Oct 2024 at 08:56, Grant Edwards via Python-list
>  wrote:
> >
> > On 2024-09-30, Dan Sommers via Python-list  wrote:
> >
> > > In Common Lisp, integers can be written in any integer base from two
> > > to thirty six, inclusive.  So knowing the last digit doesn't tell
> > > you whether an integer is even or odd until you know the base
> > > anyway.
> >
> > I had to think about that for an embarassingly long time before it
> > clicked.
> 
> The only part I'm not clear on is what identifies the base. If you're
> going to write numbers little-endian, it's not that hard to also write
> them with a base indicator before the digits [...]

In Common Lisp, you can write integers as #nnR[digits], where nn is the
decimal representation of the base (possibly without a leading zero),
the # and the R are literal characters, and the digits are written in
the intended base.  So the input #16f is read as the integer 65535.

You can also set or bind the global variable *read-base* (yes, the
asterisks are part of the name) to an integer between 2 and 36, and then
anything that looks like an integer in that base is interpreted as such
(including literals in programs).  The literals I described above are
still handled correctly no matter the current value of *read-base*.  So
if the value of *read-base* is 16, then the input  is read as the
integer 65535 (as is the input #16r).

(Pedants may point our details I omitted.  I admit to omitting them.)

IIRC, certain [old 8080 and Z-80?] assemblers used to put the base
indicator at the end.  So 10 meant, well, 10, but 10H meant 16 and 10b
meant 2 (IDK; the capital H and the lower case b both look right to me).

I don't recall numbers written from least significant digit to most
significant digit (big and little endian *storage*, yes, but not the
digits when presented to or read from a human).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-09-30 Thread Dan Sommers via Python-list
On 2024-10-01 at 04:46:35 +1000,
Chris Angelico via Python-list  wrote:

> On Tue, 1 Oct 2024 at 04:30, Dan Sommers via Python-list
>  wrote:
> >
> > But why do I need to start with the least
> > significant digit?
> 
> If you start from the most significant, you don't know anything about
> the number until you finish parsing it. There's almost nothing you can
> say about a number given that it starts with a particular sequence
> (since you don't know how MANY digits there are). However, if you know
> the LAST digits, you can make certain statements about it (trivial
> examples being whether it's odd or even).

But that wasn't the question.  Sure, under certain circumstances and for
specific use cases and/or requirements, there might be arguments to read
potential numbers as strings and possibly not have to parse them
completely before accepting or rejecting them.

And if I start with the least significant digit and the number happens
to be written in scientific notation and/or has a decimal point, then I
can't tell whether it's odd or even until I further process the whole
thing anyway.

> It's not very, well, significant. But there's something to it. And it
> extends nicely to p-adic numbers, which can have an infinite number of
> nonzero digits to the left of the decimal:
> 
> https://en.wikipedia.org/wiki/P-adic_number

In Common Lisp, integers can be written in any integer base from two to
thirty six, inclusive.  So knowing the last digit doesn't tell you
whether an integer is even or odd until you know the base anyway.

Curiously, we agree:  if you move the goal posts arbitrarily, then
some algorithms that parse JSON numbers will fail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-09-30 Thread Dan Sommers via Python-list
On 2024-09-30 at 11:44:50 -0400,
Grant Edwards via Python-list  wrote:

> On 2024-09-30, Left Right via Python-list  wrote:
> > Whether and to what degree you can stream JSON depends on JSON
> > structure. In general, however, JSON cannot be streamed (but commonly
> > it can be).
> >
> > Imagine a pathological case of this shape: 1... <60GB of digits>. This
> > is still a valid JSON (it doesn't have any limits on how many digits a
> > number can have). And you cannot parse this number in a streaming way
> > because in order to do that, you need to start with the least
> > significant digit.
> 
> Which is how arabic numbers were originally parsed, but when
> westerners adopted them from a R->L written language, thet didn't flip
> them around to match the L->R written language into which they were
> being adopted.

Interesting.

> So now long numbers can't be parsed as a stream in software. They
> should have anticipated this problem back in the 13th century and
> flipped the numbers around.

What am I missing?  Handwavingly, start with the first digit, and as
long as the next character is a digit, multipliy the accumulated result
by 10 (or the appropriate base) and add the next value.  Oh, and handle
scientific notation as a special case, and perhaps fail spectacularly
instead of recovering gracefully in certain edge cases.  And in the
pathological case of a single number with 60 billion digits, run out of
memory (and complain loudly to the person who claimed that the file
contained a "dataset").  But why do I need to start with the least
significant digit?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Common objects for CLI commands with Typer

2024-09-23 Thread Dan Sommers via Python-list
On 2024-09-23 at 19:00:10 +0100,
Barry Scott  wrote:

> > On 21 Sep 2024, at 11:40, Dan Sommers via Python-list 
> >  wrote:

> But once your code gets big the disciple of using classes helps
> maintenance. Code with lots of globals is problematic.

Even before your code gets big, discipline helps maintenance.  :-)

Every level of your program has globals.  An application with too many
classes is no better (or worse) than a class with too many methods, or a
module with too many functions.  Insert your own definitions of (and
tolerances for) "too many," which will vary in flexibility.

(And as was alluded to elsewhere in this thread, you could probably
deduce the original and/or preferred programming languages of people
with certain such definitions.  But I digress.)

$ python -m this|grep Namespaces
Namespaces are one honking great idea -- let's do more of those!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Common objects for CLI commands with Typer

2024-09-21 Thread Dan Sommers via Python-list
On 2024-09-21 at 06:38:05 +0100,
Barry via Python-list  wrote:

> > On 20 Sep 2024, at 21:01, Loris Bennett via Python-list 
> >  wrote:
> > 
> > Hi,
> > 
> > Apologies if the following description is to brief - I can expand if no
> > one knows what I'm on about, but maybe a short description is enough.
> > 
> > I am developing a command line application using Typer.  Most commands
> > need to do something in a database and also do LDAP stuff.  Currently
> > each command creates its own Database and LDAP objects, since each
> > command forms an entry point to the program.
> > 
> > With Typer, is there a way I can define the equivalent of class
> > attributes at a single point which are then available to all commands?
> 
> I do not know typer. But the general solution is to create an instance of 
> your class
> and tell typer to call member function of the instance.
> 
> app = Application()
> …
> typer.set_callback(app.my_handler)

Despite the fact that "everything is an object" in Python, you don't
have to put data or functions inside classes or objects.  I also know
nothing about Typer, but there's nothing wrong with functions in a
module.

There's also nothing wrong with writing a function that creates and
returns the database and LDAP connections (perhas as instances of
application-level classes), amd calling that function from within each
command.

DRY.  Yeah, yeah, yeah.  :-/ So there's one line at the top of each
comamnd that initializes things, and possibly a line at the bottom to
close those things down.  Turn those lines into a context manager, which
is actually a sub-framework inside Typer.  Don't convolute/compilicate
your design to eliminate one line at the top of each command.

Go ahead, accuse me of writing FORTRAN (all caps, no numbers or
qualifiers, as $deity intended) in Python.  But neither optimize
prematurely nor invoke the Inner Platform Effect to save one or two
lines in your not-yet-written commands, either.

Sorry for the rant.  :-)

Simple is better than complex.
Complex is better than complicated.

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


Re: Is there a better way? [combining f-string, thousands separator, right align]

2024-08-26 Thread Dan Sommers via Python-list
On 2024-08-26 at 20:42:32 +1200,
dn via Python-list  wrote:

> and if we really want to go over-board:
> 
> >>> RIGHT_JUSTIFIED = ">"
> >>> THOUSANDS_SEPARATOR = ","
> >>> s_format = F"{RIGHT_JUSTIFIED}{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
> 
> or (better) because right-justification is the default for numbers:
> 
> >>> s_format = F"{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
> 
> 
> To the extreme that if your user keeps fiddling with presentations (none
> ever do, do they?), all settings to do with s_format could be added to a
> config/environment file, and thus be even further separated from
> program-logic!

And then you'll need a parser, many of whose Unique Challenges™ aren't
even apparent until you start parsing files from actual users, and
you'll still need some sort of fallback in the code anyway for the case
that s_format can't be parsed (for whatever reason).

Isn't a config file what just caused the global CrowdStrike outage?  ;-)

That said, I understand that report generators are a thing, not to
mention RPG (https://en.wikipedia.org/wiki/IBM_RPG).

Okay, sorry; I'll just crawl back into the hole from whence I came.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: new here

2024-08-21 Thread Dan Sommers via Python-list
On 2024-08-20 at 23:16:48 -0400,
AVI GROSS via Python-list  wrote:

> I do wonder if the people at python.org want multiple forums. There is
> also one that sort of tutors people that obviously has an overlapping
> but different audience.

$ python -m this
The Zen of Python, by Tim Peters
[...]
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
[...]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best use of "open" context manager

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

> Is there a better / more Pythonic solution?

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

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

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


Re: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp

2024-05-29 Thread Dan Sommers via Python-list
On 2024-05-29 at 11:39:14 -0700,
HenHanna via Python-list  wrote:

> On 5/27/2024 1:59 PM, 2qdxy4rzwzuui...@potatochowder.com wrote:

> > https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule

[...]

> Are  the Rules 1--9  by  Greenspun   good too?

I don't know; let me look it up.  Oh, there it is:

https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule says that
Greenspun said he "was just trying to give the rule a memorable name."

Sadly, the citation link is failing for me right now.
-- 
https://mail.python.org/mailman/listinfo/python-list


Formatted Output and Argument Parsing (was: Re: Flubbed it in the second interation through the string: range error... HOW?)

2024-05-29 Thread Dan Sommers via Python-list
On 2024-05-29 at 17:14:51 +1000,
Chris Angelico via Python-list  wrote:

> I wouldn't replace str.format() everywhere, nor would I replace
> percent encoding everywhere - but in this case, I think Thomas is
> correct. Not because it's 2024 (f-strings were brought in back in
> 2015, so they're hardly chronologically special), but because most of
> this looks like debugging output that can take advantage of this
> feature:
> 
> print(f"if block {name[index]=} {index=}")

defsnark:

After years of getopt (and even more, if you include non-Python
experience), I'm glad I decided to wait a decade before chugging the
optparse koolaid.

(For the history-impaired, getopt existed long before Python and will
likely exist long after it, but getopt's "replacement" optparse lasted
only from 2003 until 2011.)

That said, I agree that the = thing makes f-strings eminently useful for
debugging, and I wholeheartedly agree with not fixing things that aren't
broken.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp

2024-05-27 Thread Dan Sommers via Python-list
On 2024-05-27 at 12:37:01 -0700,
HenHanna via Python-list  wrote:

> 
> On 5/27/2024 7:18 AM, Cor wrote:
> > Some entity, AKA "B. Pym" ,
> > wrote this mindboggling stuff:
> > (selectively-snipped-or-not-p)
> > 
> > > On 12/16/2023, c...@clsnet.nl wrote:
> > > 
> > > > Any marginally usable programming language approaches an ill
> > > > defined barely usable re-implementation of half of common-lisp
> > > 
> > > The good news is, it's not Lisp that sucks, but Common Lisp.
> > >   --- Paul Graham
> > 
> > Just to set the record straight;
> > This is not My line.
> > I quoted it but don't know who the originator of that remark is.

https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Terminal Emulator (Posting On Python-List Prohibited)

2024-05-19 Thread Dan Sommers via Python-list
On 2024-05-19 at 18:13:23 +,
Gilmeh Serda via Python-list  wrote:


> Was there a reason they chose the name Pip?

Package Installer for Python

https://pip.pypa.io/en/stable/index.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Terminal Emulator (Posting On Python-List Prohibited)

2024-05-19 Thread Dan Sommers via Python-list
On 2024-05-19 at 18:13:23 +,
Gilmeh Serda via Python-list  wrote:

> Was there a reason they chose the name Pip?

Package Installer for Python

https://pip.pypa.io/en/stable/index.html

Every time I see PIP, I think Peripheral Interchange Program, but I'm
old.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to discover what values produced an exception?

2024-05-04 Thread Dan Sommers via Python-list
On 2024-05-03 at 10:56:39 -0300,
Johanne Fairchild via Python-list  wrote:

> How to discover what values produced an exception?  Or perhaps---why
> doesn't the Python traceback show the values involved in the TypeError?
> For instance:
> 
> --8<>8---
> >>> (0,0) < 4
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: '<' not supported between instances of 'tuple' and 'int'
> --8<>8---
> 
> It could have said something like: 
> 
> --8<>8---
> TypeError: '<' not supported between instances of 'tuple' and 'int'
>   in (0,0) < 4.
> --8<>8---
> 
> We would know which were the values that caused the problem, which would
> be very helpful.

I'm not disagreeing that knowing the values could be useful in many
cases.  In the general case, though, it's not practical.  Consider a
function like this:

def f(x, y):
return g(x) < h(y)

The printed values of x, y, g(x), and h(y) could all be millions of (or
more) glyphs.  Worse, one or more of those values could contain circular
lists or similar structures.  And h or g could have changed x or y.  In
summary, printing run-time values isn't always safe or useful.  At least
printing the types is safe.  In the face of ambiguity, refuse to guess.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Configuring an object via a dictionary

2024-03-20 Thread Dan Sommers via Python-list
On 2024-03-20 at 09:49:54 +0100,
Roel Schroeven via Python-list  wrote:

> You haven't only checked for None! You have rejected *every* falsish value,
> even though they may very well be acceptable values.

OTOH, only you can answer these questions about your situations.

Every application, every item of configuration data, is going to be a
little bit different.

What, exactly, does "missing" mean?  That there's no entry in a config
file?  That there's some sort of degenerate entry with "missing"
semantics (e.g. a line in a text file that contains the name of the
value and an equals sign, but no value)?  An empty string or list?  Are
you making your program easier for users to use, easier for testers to
test, easier for authors to write and to maintain, or something else?
What is your program allowed and not allowed to do in the face of
"missing" configuration data?

Once you've nailed down the semantics of the configuration data, then
the code usually falls out pretty quickly.  But arguing about corner
cases and failure modes without specifications is a losing battle.
Every piece of code is suspect unless you know what the inputs mean, and
what the application "should" do if the don't look like that.

Python's flexibiliry and expressiveness are double edge swords.  Use
them wisely.  :-)

Sorry for the rant.

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


Re: Configuring an object via a dictionary

2024-03-15 Thread Dan Sommers via Python-list
On 2024-03-15 at 15:48:17 -0400,
Thomas Passin via Python-list  wrote:

> [...] And I suppose there is always the possibility that sometime in
> the future an "or" clause like that will be changed to return a
> Boolean, which one would expect anyway.

Not only is the current value is way more useful, but changing it would
be a compatibility and maintenance nightmare.

If I want Java, I know where to find it.  :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract lines from file, add to new files

2024-01-13 Thread Dan Sommers via Python-list
On 2024-01-13 at 11:34:29 +0100,
Left Right  wrote:

> > The Python term, at least colloquially, is "tuple unpacking."

That quote is from me.  Please do preserve attributions.

> Well, why use colloquialism if there's a language specification? Also,
> there weren't any tuples used in my example, at least not explicitly
> (i could've been a tuple, but that wasn't specified).

According to the language specification,⁰ it's a "target list," and
there can be more than one target in that list.

The unpacking isn't really called anything, it's just the way Python
assignment works, all the way back to its earliest stages.¹

⁰ https://docs.python.org/3/reference/simple_stmts.html#assignment-statements,
¹ https://docs.python.org/release/1.4/ref/ref6.html#HDR2
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract lines from file, add to new files

2024-01-12 Thread Dan Sommers via Python-list
On 2024-01-13 at 02:02:39 +0100,
Left Right via Python-list  wrote:

> Actually, after some Web search.  I think, based on this:
> https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-augtarget
> that in Python you call this "augmented assignment target". The term
> isn't in the glossary, but so are many others.

The Python term, at least colloquially, is "tuple unpacking."

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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Dan Purgert via Python-list
On 2023-12-06, Stefan Ram wrote:
> Chris Green  writes:
>>KEY1:
>>  a: v1
>>  c: v3
>>  d: v4
>>KEY2:
>>  a: v7
>>  b: v5
>>  d: v6
>
>   That maps nicely to two directories with three files
>   (under an application-specific configuration directory).

Or an .ini file with two sections (although I don't think you can re-use
key-names in a single ini file)


-- 
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Dan Sommers via Python-list
On 2023-12-06 at 09:32:02 +,
Chris Green via Python-list  wrote:

> Thomas Passin  wrote:

[...]

> > Just go with an .ini file. Simple, well-supported by the standard 
> > library. And it gives you key/value pairs.
> > 
> My requirement is *slightly* more complex than just key value pairs,
> it has one level of hierarchy, e.g.:-
> 
> KEY1:
>   a: v1
>   c: v3
>   d: v4
> KEY2:
>   a: v7
>   b: v5
>   d: v6
> 
> Different numbers of value pairs under each KEY.

INI files have sections.

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


Re: on writing a number as 2^s * q, where q is odd

2023-11-29 Thread Dan Sommers via Python-list
On 2023-11-29 at 21:44:01 -0300,
Julieta Shem via Python-list  wrote:

> How would you write this procedure?
> 
> --8<---cut here---start->8---
> def powers_of_2_in(n):
>   s = 0
>   while "I still find factors of 2 in n...":
> q, r = divmod(n, 2)
> if r == 0:
>   s = s + 1
>   n = n // 2
> else:
>   return s, n
> --8<---cut here---end--->8---

What's wrong with what you have?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beep on WIndows 11

2023-11-12 Thread Dan Sommers via Python-list
On 2023-11-11 at 23:44:19 +,
Y Y via Python-list  wrote:

> I am curious and humble to ask: What is the purpose of a BEEP?

It's a simple way for a terminal-based program to alert (hence '\a') a
user or an operator that their attention is requested or required.

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


Re: Checking if email is valid

2023-11-02 Thread Dan Purgert via Python-list
On 2023-11-02, dn wrote:
> On 02/11/2023 19.46, Simon Connah via Python-list wrote:
>> [...]
>> My goal is to make a simple mailing list platform. I guess I could
>> just send email to an address and if it bounces then I can remove it
>> from the database. Thing is I'm not sure how close to a real email
>> address an email has to be in order to be bounced. If it was
>> completely wrong it might just swallowed up.
>
> Exactly!
>
> Build a complementary script which inspects the returned/bounced 
> messages, and removes those addresses.
>
> Given that the list of addresses is built from people signing-up in the 
> first place, one has to presume that people know their own addresses and 
> can type - there's no real defence against 'stupid'*. It's not as if you 
> are making-up addresses yourself (in many jurisdictions it is illegal 
> without opt-in).

Isn't opt-in usually to the effect of "send a message with the subject
SUBSCRIBE to listname-reque...@mailinglist.domain.tld " ?  Then the
trick becomes filtering out the spam; but the "is the email valid" check
is somewhat done as a matter of processing that inbound subscribe
message.


-- 
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question(s)

2023-10-26 Thread Dan Purgert via Python-list
On 2023-10-26, o1bigtenor wrote:
> On Wed, Oct 25, 2023 at 10:19 AM Michael Torrie via Python-list
> wrote:
>>
>> On 10/25/23 05:51, o1bigtenor via Python-list wrote:
>> > Looks like I have another area to investigate. (grin!)
>> > Any suggestions?
>>
>> Seems to me you're trying to run before you have learned to walk.
>>
>> Slow down, go to the beginning and just learn python, write some code,
>> see if it runs.  Go through the tutorial at
>> https://docs.python.org/3/tutorial/index.html
>
> Interesting - - - -  ". . . see if it runs." - - - that's the issue!
> When the code is accessing sensors there isn't an easy way to
> check that the code is working until one has done the all of the
> physical construction. If I'm trying to control a pulsation system
> using square waves with distinct needs for timing etc I hadn't
> seen any way of 'stepping through the code' (phrase you use later).

You use a hardware debugger then ... and if you're talking hardware,
chances are you're also not talking Python (yes, yes, I know
"CircuitPython" is a thing, or was it MicroPython?)

> [...]
> Even in maker threads - - - say for arduino - - its 'use this cut and
> paste method of programming' with no mention of any kind of ide when
> it was microPython - - although being a subset of python it Idle may
> not work with it.

Bearing in mind, of course, that "Arduino" is basically "Programming for
dummies" level of stuff usually (i.e. people just getting their feet
wet).  It's meant to be a relatively "easy" introduction for students /
hobbiests / non-programmers into the world of programming for
microcontrollers.

> [...]
> My problem is that I'm needing to move quite quickly from 'hello, world' to
> something quite a bit more complex. Most of the instruction stuff I've run
> into assumes that one is programming only for the joy of learning to
> program where I've got things I want to do and - - - sadly - - - they're
> not sorta like the run of the mill stuff.

Sounds like you've been reading instructables :)

-- 
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question(s)

2023-10-25 Thread Dan Purgert via Python-list
On 2023-10-25, o1bigtenor wrote:
> On Wed, Oct 25, 2023 at 7:00 AM Dieter Maurer  wrote:
>> [...]
>> There are several others,
>> e.g. "ECLIPSE" can be used for Python development.
>
> Is 'Eclipse' a Windows oriented IDE?
> (Having a hard time finding linux related  information on the
> website.)

Not at all.  As I recall, it's entirely written in Java, so basically
entirely platform-independent already.


-- 
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question(s)

2023-10-25 Thread Dan Purgert via Python-list
On 2023-10-24, o1bigtenor wrote:
> On Tue, Oct 24, 2023 at 5:28 PM Rob Cliffe  wrote:
>>
>> There is no general way to prove that a program is "correct".  Or even
>> whether it will terminate or loop endlessly.
>> [...]
>> When you come to run your program "for real", and you have to
>> troubleshoot it (as in real life you probably will🙁), you will have
>> eliminated simple bugs in your program, and can concentrate on the more
>> likely sources of problems (e.g. misbehaving hardware).
>>
> Interesting - - - hopefully taken in the same vein as your second
> statement - - I sorta sounds like programmers keep running around in
> the forest looking for trees. (Grin!)

No, you tend to know what parts of the spec are "wrong(tm)" (either in
the language you're working in, or the hardware). 

If it comes to working with customers (as mentioned in one response),
you start to learn the questions to get at what they really want (but
that's better left to the architect :) )

>
> So how does one test software then?

You write unit tests (usually scripts or other software that can
interact with the main program to twiddle the knobs and such, and ensure
it's doing what was specified).  Alternatively, you have to program your
hardware and test directly on that.


-- 
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question(s)

2023-10-24 Thread Dan Purgert via Python-list
On 2023-10-24, o1bigtenor wrote:
> Greetings
>
> (Sorry for a nebulous subject but dunno how to have a short title for
> a complex question.)
> [...]
> Is there a way to verify that a program is going to do what it is
> supposed to do even
> before all the hardware has been assembled and installed and tested?

In short, no.

Reality is a mess, and even if you've programmed/perfectly/ to the
datasheets (and passed our unit-tests that are also based on those
datasheets), a piece of hardware may not actually conform to what's
written.  Maybe the sheet is wrong, maybe the hardware is faulty, etc.



-- 
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doc call `__init__` as a method rather than function?

2023-09-15 Thread Dan Sommers via Python-list
On 2023-09-15 at 10:49:10 +,
scruel tao via Python-list  wrote:

> ```python
> >>> class A:
> ...   def __init__(self):
> ... pass
> ...
> >>> A.__init__
> 
> >>> a = A()
> >>> a.__init__
> >
> ```
> 
> On many books and even the official documents, it seems that many authors 
> prefer to call `__init__` as a "method" rather than a "function".
> The book PYTHON CRASH COURSE  mentioned that "A function that’s part of a 
> class is a method.", however, ` A.__init__` tells that `__init__` is a 
> function...

I always call __init__ "the initializer."  YMMV.

> I wonder how can I call `__init__` as? Consider the output above.
> Maybe both are OK? If you prefer or think that we must use one of the two, 
> please explain the why, I really want to know, thanks!

Usually, you don't call (or even refer to) __init__ from your
application.  One __init__ can call another one in the case of
initializing superclasses.

When you evaluate A(), Python calls __init__ for you.  You can see this
if you add something "visible" to __init__, like a print statement.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: A new version (0.5.1) of python-gnupg has been released.

2023-07-22 Thread Dan Sommers via Python-list
On 2023-07-22 at 11:04:35 +,
Vinay Sajip via Python-list  wrote:

> What Changed?
> =

What changed, indeed.

Maybe I'm old, and curmudgeonly, but it would be nice if the body of
these annoucement emails (not just this one) contained the name of the
program and a one-line summary of what the program does, preferably
right at the top.

(Admittedly, in this case, once I found the name of the program in the
subject and the footnotes, I was able to figure out what it does.  Not
all software is named that usefully.)
-- 
https://mail.python.org/mailman/listinfo/python-list


TKinter in Python - advanced notions - ok

2023-06-24 Thread Dan Kolis via Python-list
Well, its kind of obvious to make a skeleton, copy it in for some basic 
functionality and modularly ( is that a word ? ) manage each piece.

That ( like your example ) is fine stuff.  

As a side note, I am sure large, large highly generalised programs are pretty 
hard to make.

One thing I do is make each file have a null class like:

# Empty object maker ( M T ) ... get it say it !
class MT():
pass

# Hook point for this module generally
mod = MT()  

Then, a category of symbols ( mostly 'variables ), grow under mod.(Whatever)

# This window gets to exist, and it's exit via op sys clicks
mod.ws = sb.make_Tk_Window( "seqdecodeshow" + str( a_Num ), gi.kCONFIGWIN ) 

This basic notion is that self.(stuff) is not quite multi class enough, yet 
'global' is unpopular as a notation, due to name pollution.


IN A BIG PROGRAM NOT A LITTLE WEENEY One YOU SCRATCH ON A BLACKBOARD SOMEPLACE 
!!

Generally, The way I proceed is to try to avoid CLASSes in each module, but 
only a little. If you need it, you sure do. So early on ( like < 100 lines, if 
you avoided a class, roll back and add it ).

Then, mod.(anything) is 'sort of' like self to class, but its politics is the 
filename that made it alone.

If mod. is not used exactly in a class, roll it back to self. If its way more 
abstractley used, upgrade it to your concept of really global, which generally 
should be somewhat sparely used.

All my TK calls are wrapped in a custom layer, it reduces the line count to 
1/3. like so:

   sb.checkableBoole(cFrmL, 0, 0, gi.us, e_Txt, 
 setting_ClickCb )
sb.textCmdLine( cFrmL, 1, 0, gi.us, 'Apply',
applyThoseSelects )
sb.textCmdLine( cFrmL, 1, 1, gi.us, 'Reset',
resetSelects )
sb.textCmdLine( cFrmL, 1, 2, gi.us, 'Select 
all',   cbSelectAll )

cFrmL is the TK thing that contains these few text lines, with all the bg 
colors, whitepace, fonts, managed inside


This calls 'grid' of course for placement. But all colors, and callbacks for 
changes are entirely in called pieces, which have been tested like 150% crazy. 
sb is 

import screenBuilder1 assb  # Screen maker for TKinter and TKinter ++ 
windows

If you want to use my 'screenbuilder'... talk to me, I suppose. this is a 
biology IDE, the screen part is just a little piece of a huge initiative. 
Obviously, the human being's ideas in there head matter so the TK stuff is 
important, to say the least

Regs,
Daniel B. Kolis

my ref: 24 Jun 2023, https://groups.google.com/g/comp.lang.python/

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


Re: TKinter in Python - advanced notions - reactive

2023-06-23 Thread Dan Kolis via Python-list


I am not specifically having any problems implementing what I want to make work.

Callbacks etc make it fairly easy to make TKinter react to things without any 
specific fancy plan for it.

Add callbacks for real time changes early in any new notion, after it looks 
right go to the IO part make it react.

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


Re: TKinter in Python - advanced notions

2023-06-23 Thread Dan Kolis via Python-list
If you have a problem,. ask a super specific question, here. If I can help, I 
will, but TKINTER knowledge is pretty spread around. Many others migth jump in, 
too.

Its works, its slightly quirky, has no licencing hangups.

X11 makes fine fine programs !
Keep hacking,Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


TKinter in Python - advanced notions

2023-06-21 Thread Dan Kolis via Python-list
Hi,

I've write a huge biotech program ( an IDE for synthetic biology ), and am 
slowly outgrowing TKINTER.

Has anybody out there merged a little bit of TCL direct calls from Python 3.X 
to get more freedom then TKINTER for just some Windows ?

How about bold stories of successes ( yours, not mine ) on porting to stupid MS 
Windows from linux ?

Adding threading makes TKinter hard ( but not impossible ) to manage. Also, a 
little bit here and there obviously exceeds TKINTERs goals.

I wish it looked better, but its 'ok'. I believe X11 IO is considerably 
superior for serious work the HTML.  I mean 'serious' work. with lots of multi 
media windows. I am not talking about fb "Oh ! There is a window it opened 
inthe corner !"... trivial functionality.

Must be a uber expert out there. Is it you ?

As attached. and little code. Coloring text makes me realise; some of this is 
pretty indirect, though this is quite well thought out, like all of TKINTER.

Regards,
Daniel B. Kolis


"""
An important worked example of text color and other look dynamic changes.
This is the righ way to do this for fast changes ! 
20 Jun 2023 22:11
"""

import tkinter as tk
from tkinter.font import Font

class Pad(  tk.Frame  ):

def __init__( self, parent, *args, **kwargs ):
tk.Frame.__init__(  self, parent, *args, **kwargs  )

self.toolbar = tk.Frame( self, bg="#eee" )
self.toolbar.pack( side="top", fill="x" )

self.bold_btn = tk.Button( self.toolbar, text="CHANGE highlighted", 
command=self.make_Change_Highlighted )
self.bold_btn.pack( side="left" )

self.bold_btn = tk.Button( self.toolbar, text="CHANGE H.B.", 
command=self.make_Change_Hb )
self.bold_btn.pack( side="left" )

self.bold_btn = tk.Button( self.toolbar, text="Delete a char", 
command=self.make_Change_Delete )
self.bold_btn.pack( side="left" )

self.clear_btn = tk.Button( self.toolbar, text="Clear", 
command=self.clear_Some )
self.clear_btn.pack( side="left" )

# Applies this font
self.bold_font = Font( family="Helvetica", size=14, weight="bold" )

self.da_Text = tk.Text( self )
self.da_Text.insert( "end", "Selectable parts of text is fun.\nSo is a 
happy birthday, right ?"  )
self.da_Text.focus(  )
self.da_Text.pack( fill="both", expand=True )

# configuring a tag called dingo-something
self.da_Text.tag_configure( "reddingo",  font=self.bold_font, 
foreground = "Red"  )
self.da_Text.tag_configure( "bluedingo", font=self.bold_font, 
background = "Yellow", foreground = "Blue"  )


# Button CB
def make_Change_Delete( self ):

self.da_Text.delete( '1.0', '1.1' )


# Button CB
def make_Change_Highlighted( self ):

# tk.TclError exception is raised if not text is selected
try:
   self.da_Text.tag_add( "reddingo", "sel.first", "sel.last" )

except tk.TclError:
   tt = 569


# Button CB
def make_Change_Hb( self ):

try:
lin_Idx = 2; col_Idx = 8
self.da_Text.tag_add( "bluedingo", f"{ lin_Idx }.{ col_Idx }", 
   f"{ lin_Idx }.{ col_Idx + len(  
'happy birthday'  ) }"  )
except:
gg = 457

# Button CB
def clear_Some( self ):
   self.da_Text.tag_remove( "reddingo",  "1.0", 'end' )
   self.da_Text.tag_remove( "bluedingo",  "1.0", 'end' )


# Main body really
def is_Main():
root = tk.Tk()
Pad( root ).pack( expand=1, fill="both" )
root.mainloop()

# Go
if __name__ == "__main__":
is_Main()


Document end

my ref: 21 Jun 2023, https://groups.google.com/g/comp.lang.python, Daniel B. 
Kolis, nafl




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


What is this TEST BANK stuff ?

2023-06-21 Thread Dan Kolis via Python-list
Why do we tolerate this spam ?

this seems most likely a way to inject viruses into people's workflow.

That wiped out usenet. Ahh without an explaination; ( and it woudl have to be a 
good one ); what is the purpsoe of this, why is it here ?

Can it be eliminated ?

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


Tkinter Redo's

2023-05-30 Thread Dan Kolis
On Tuesday, May 30, 2023 at 1:28:04 PM UTC-4, Rob Cliffe wrote:
> Thanks to everyone who replied.  All replies were constructive, none 
> were telling me to stop belly-aching. 

Hi, Dan says:
When you get your style ideas sort of frozen, maybe you can poke up a sample 
here.

Aworked example for yourself is useful anyway.

My stuffs all in Ubuntu so seeing what works and doesn't in MS products 
interests me a lot.

I usually avoid the tkk variations almost completely. I have all the things I 
use each wrapped in a call that does what I want both aesthetically and so on. 
My app is only medium sensitive to art look and feel, productivity to maintain 
it is more important then super fancy looking.

Regards,
Dan


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


Re: Python - working with xml/lxml/objectify/schemas, datatypes, and assignments

2023-01-19 Thread Dan Kolis
Editing text intended primarily for machine reading that involves metadata and 
lower level facts is a horror show.

I sort of worked for a company years ago and a smart ass suggested I was making 
labor for myself by doing changes to a scripting language for db users, maybe a 
few hours a week. He suggested I leave them to do it themselves in XML.

I tried it and the community went ape-shit angry. NONE of the people succeeded 
routinely at all.

Just because machine readable nomenclatures as well known and some s/w edits 
them, doesn't mean there suddenly not mostly mini computer programs.

 I suspect there isn't an easy way out, and probably the thing your making has 
to be 100% usably done before a maintenance tools can be created to make it 
easy, anyway.

Its the way it is, maybe,
Daniel B. Kolis
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2023-01-19 Thread Dan Kolis
On Thursday, January 19, 2023 at 12:09:02 AM UTC-5, cameron wrote:

> I know this is vague. Once you find its stalling in a particular 
> function (if it is) you may be able to run that function directly. Also, 
> a print() at the top abd bottom/return of the stalling function. And so 
> on. 


Dan says:

After lots of iterations, I changed one line in a call used to refresh windows 
from .update() to .update_idle_tasks()

Some other dudes were so nice they tested it before that, it worked perfectly 
on their computers anyway.

Now it seems to work 'all the way' too after this change on my favroritish 
computer.

Since a CTRL C often started it going again I had a hint there, reading other 
peoples various troubles all over the web made me think it was 'someplace in 
this part'.

Regards,
Daniel B. Kolis

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


Re: A natural magnet for the craziest TKinter lovers out there

2023-01-19 Thread Dan Kolis
Hello !

> Works fine on my work machine. (Ubuntu 20.04 / 32 G / 32 CPUS). Scalene 
> (https://github.com/plasma-umass/scalene) shows it using 9 MB of memory. 

> I ran your test program here and it generates 25 windows on my machine, 
> and I can click "run" at least half a dozen times. I tried closing the 
> font windows before clicking run again, and also just leaving the 
> windows up and generating many more windows. 300 windows. No hangs here 
> at all. Fedora 35 with Mate Desktop on X11 with compositing enabled. 


Thanks a lot These reports are very helpful !

I seemed to have 'fixed it' by changing one line, really. I used:

# Do each thing
..for aWs in workWsL:
aWs.update()


TO:
# Do each thing
..for aWs in workWsL:
aWs.update_idletasks()   


Dan says:
Thanks a lot ! This helps me visualise this is managed as a problem in a 
technical sense. I mean, there is always a requirement for real integration 
testing of all sorts for an attempt to release a program on a larger scale.

Now I know it works without stopping on 4 computers. Better then yesterday 
hugely.

 Thank you.

Regs
Daniel B. Kolis

my ref: nafl, 19 Jan 2023, 
https://groups.google.com/g/comp.lang.python/c/FNlXg0Od39o/m/9stiUtLSAQAJ








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


A natural magnet for the craziest TKinter lovers out there

2023-01-18 Thread Dan Kolis
Hangs after maybe between 4 and 50 screen rewrites. sometimes CTRL C under 
Ubuntu starts it up again. Click go rewrites al the fonts the thing can find in 
a few windows Repeated.

TKinter has a cult following. I don''t really expect others to fix my problems, 
but you know, es since its a cult thing to love TCL ( or something  ) Here 
is is.

 Same on two different computers in Python 3.6 and 3.8

Plus I suppose you get to see for sure all your finest fonts as rendered in a 
real TK thing, not that this changes the worlds so much.


Thanks for the advice so far...
Regards,
Dan Kolis

# Code version 18Jan2023 19:48 EST Dan Kolis
# Click 'go' on main page. when run over and over after a while it freezes


import tkinter as   tk
from tkinter import ttk
from tkinter import fontas  luFont


# Empty object maker ( M T ) ... get it say it !
class MT():
pass


# Module level variables
mod = MT()
mod.itsPlaces = MT()
mod.itsPlaces = []


# Apply XY Size to things like windows, variable place 31Jul22
def apply_Width_Height_Position( toThis, aWidth, aHeight, *argsPlace ):

# Width and height is expected

# Argument overflow is quite variable size is it its usual hint for me
aLen = len( argsPlace )

# Sometimes, just width and height are given ( not that + position )
wAndH = str( int( aWidth ) ) +'x' + str( int( aHeight ) )   
# Size has a funny text line interface
toThis.geometry( wAndH )
# Apply

# Sometimes position too
if aLen == 2:
eP = "+" + str( argsPlace[ 0 ] ) + "+" +  str( argsPlace[ 1 ] )
param4 = wAndH + eP 
# Combine size and position
toThis.geometry( param4 )   
# Apply

jj = 560


# Create local   toplevel   to whoever calls me 11Dec22 bc-endive
def make_Tk_Window( sReason, *attribKc ):

# Top level window maker and rememberer
# Kc = 'Kind code'

aCode = "na"
# Not available
if attribKc:
aCode = attribKc [ 0 ]  
# Better code then 'na'

# Make window
ansWin = tk.Toplevel()

# Keep track of this creation step
newEntry = {}
newEntry[ 'tkaddress' ] = ansWin
# Real TK window accessor
newEntry[ 'ideanamed' ] = sReason   
# Casual description
newEntry[ 'kindcode'  ] = aCode 
# So can be worked with together

mod.itsPlaces.append( newEntry )

return ansWin


# Idle time rewrite
def justRedisplayNow( wThings,  *argsR ):

# Redisplay a named tj thing
# Dont use this frivolously, if it's needed its here you have to study it

wThings.update()  


# Look at fonts possible 6Oct22
def showAllFonts():

# Show fonts possible

mod.lines_In_Window = 30; mod.window_Seq_Number = 1

# What we want to see
mod.seeFonts = list( luFont.families() )
mod.seeFonts.sort() 
# Alpha order is nice

# Fill windows as a look at me report
try:
populateW()
except:
tt = 456

rr = 245


# Show fonts regarding avoiding BAD ones that crash, etc size limits in buffers 
too 19Dec22
def populateW():

# Put in the fonts

aLen = len( mod.seeFonts )  
# Fun to know, debug really
last_considered_name = "gghfjhljfl" 
# Don't show doubles

# Loop through all fonts the system named
thisPassMakeWindow = True; a_Line_Count = 0; list_Number = 0
for item in mod.seeFonts:

# Multiple windows ( Python has funny ideas on this, ok like this )
if thisPassMakeWindow:
winTk_Now = winMakerFontsW(); thisPassMakeWindow = False; 
a_Line_Count = 0  # We gots one now

if a_Line_Count < mod.lines_In_Window:  
 # Will a window we made
list_Number += 1
# Counts
aN = str( list_Number ) + " "; name_In_lower = item.lower()

# Various reasons to not render this one
isOk = True
if name_In_lower == last_considered_name:
isOk = False
a_Bad_Thing = name_In_lower.find( 'emoji' ) > -1
if a_Bad_Thing:
isOk = False
a_Bad_Thing = item.find( 'Noto Sans Mono CJK' ) > -1

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

2023-01-18 Thread Dan Kolis
I have written a very sizable and elaborate program that uses tKinter for X11 
displays of genomics.

Yet maybe 1 of 6 times it freezes, so I decided to extract the minimum that 
works perfectly and add back big pieces. It does it both running .pyc and in 
VSCode.

so even the most minor of oddities is suspect. I cant really think of any 
better way to debug it. I see no evidence in WWW searches its a generic 
problem. So tracing the startup and watching it hop all around is about one of 
five lesser problem line items.

Regs
Dan

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


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

2023-01-18 Thread Dan Kolis
Thank you

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


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

2023-01-18 Thread Dan Kolis


> I don't think you've described this. I don't know what you mean here. 

When I trace it in VSCode the imports seem like they endlessly suspend scanning 
and go to other ones over and over. Like "Whats this doing ?"

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


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

2023-01-18 Thread Dan Kolis
Most of the time the newbie I visualize adding a function copies and pastes 
maybe a screen of python and changes it a little, maybe 5% of the lines have a 
xx. code so they rarely have to understand it,  thats not the part of the 
program there changing.

Also, I suffered long and hard for extreme uniformity in the names and so on, 
there utterly uniform, so there not so bad to consider, ( I hope ).

I guess I don't full understand what bothers me about the repetition of the 
imports so much. The tracing of it seems so bizarre, it just seems like its 
wrong.

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


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

2023-01-18 Thread Dan Kolis


dn and Mats, thanks for your advice.

I'm not sure what to do. Do either / both know if there is a way to make it 
parse each import list to bytecode in one shot ?? The hop around read keeps 
making me worry it migth leave some memory leak or something.

I dont know. 

Thanks though, both your dialog's are very helpful.

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


Improvement to imports, what is a better way ?

2023-01-18 Thread Dan Kolis
This program has lots of files and each is well segregated for a concept.

the top of each as a heap of imports, all identical. Well the very top has some 
one of's

import os asos
import sys as   sys
import importlib as importlib
import datetime as  dt
from   tokenize import  maybe
import signal

from   tkinter import filedialog as fd
from   tkinter.messagebox importshowinfo
import tkinter as   tk  
from   tkinter import   ttk
from   tkinter import   font
 
from   PIL import Image as  pl
from   PIL import ImageTk   as  ii

# Imports part of this program 
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
import bestNotifications as bn  # Alerts, modals and notifications of many 
kinds including TK windows
import bitBlitting as   bb  # Help - # A setup window with basic facts 
written into files and the workspace
import configSetting as cs  # A setup window with basic facts written 
into files and the workspace
import devPeeks as  dp  # Developments peek assets code for adding 
features and debugging
import fileIo asio  # File reads, writes even some of the the 
pickle and unpickling
import forFun asff  # Staging area for uncertian features, also 
some dynamic code inclusion
import fractionScreens as   fs  # Common window pieces for TK windows in 
sequence viewers
import genomeDb as  gd  # IO to from databases external files gbk 
and others sure
import globalIdeas as   gi  # Common code for stuff used everywhere and 
definition of share DOT OBJECTS
import insertableEditors as ie  # Text editor(s) and support for that, some 
language issues managed too
import modalSimple as   mo  # Modal windows icp seq ssues, not used 
much currently
import osDependant as   od  # Operating system dependant calls and 
adaptions
import pickle aspk  # Packaging to and from file system for 
objects especially DOT OBJECTS
import screenBuilder1 assb  # Screen maker for TKinter and TKinter ++ 
windows
import selectViewer as  sv  # Window for picking which sequence viewers 
are enabled
import sequencesMaintain as sm  # Touching up temporal version issues of 
DOT OBJECTS
import sequencesOverview as so  # Working with sequences as macro facts, 
lists, see turn off etc
import serverHttp1 as   sh1 # Servers for HTTP - User Support
import serverHttp2 as   sh2 # Servers for HTTP - Protein viewing
import specialFour as   sf  # Classes and stuff for viewer four, a very 
complex viewer
import stagingNow assn  # More stabler new ideas getting tried out 
and moved in
import taskingFunction as   tf  # Tasker for real timeish event processor 
calls. Has two versions both work
import toastMaker astm  # Notifications
import transFormations as   xf  # Sequence transFormations from mother 
natures ideas like DNA and RNA
import unlovedMenus as  um  # Pretty rarely used ond fashioned menus. A 
while interface is in here that works
import wayOffline aswo  # Code not discarded but just studies, etc
import windowsX as  wx  # Windows Life ! X11 esp TK not MS Windoze 
...

So the file for instance fileIo.py has a duplicate of this.

I want to be able to call any code by using the two char prefix form anywhere. 
ex: io.get_Sequence(  'abc.fa' )

this seems weirdly disorderly. when it starts it sort of iterates down into 
objects, backs up etc.

What's the right way to do this ?

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


Re: Panoptisch - A way to understand your project's dependencies and find malicious packages

2022-12-09 Thread Dan Kolis
I think it needs a built in viewer or at least a human readable output, or 
nobody will go through the trouble to use it.

Other that that, maybe a pretty good idea, sure

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


Re: In code, list.clear doesn't throw error - it's just ignored

2022-11-25 Thread Dan Stromberg
On Sun, Nov 13, 2022 at 4:45 PM DFS  wrote:

> In code, list.clear is just ignored.
> At the terminal, list.clear shows
> 
>
>
> in code:
> x = [1,2,3]
> x.clear
> print(len(x))
> 3
>
> at terminal:
> x = [1,2,3]
> x.clear
> 
> print(len(x))
> 3
>
>
> Caused me an hour of frustration before I noticed list.clear() was what
> I needed.
>
> x = [1,2,3]
> x.clear()
> print(len(x))
> 0
>
> --
> https://mail.python.org/mailman/listinfo/python-list



I'm not 100% sanguine about properties, but the fact is they are part of
the language:

$ cat p
below cmd output started 2022 Fri Nov 25 07:54:42 AM PST
#!/usr/bin/env python3

class P:
def __init__(self):
self.count = 0

@property
def increment(self):
self.count += 1

def result(self):
return self.count


p = P()
p.increment
p.increment
print(p.result())
above cmd output done2022 Fri Nov 25 07:54:42 AM PST
dstromberg@tp-mini-c:~/src/experiments/property x86_64-pc-linux-gnu 2670

$ ./p
below cmd output started 2022 Fri Nov 25 07:54:44 AM PST
2

As you can see, if the interpreter refused to do something with p.increment
because it has no parens, the meaning of this code would change
significantly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Passing information between modules

2022-11-20 Thread Dan Kolis
Its advice, I don't think the style issue is particularly important.

If you understand its meaning, it achieves my purpose. If you don't I you're 
perhaps not a programmer...

I like the abruptness of technical writing as a style, actually. If that is how 
machine learning ( aka 'A.I.' ) tends to compose messages, this seems mostly 
compatible with the sorts of written material I both make and consume.

 
https://interestingliterature.com/2017/03/10-of-the-best-poems-about-forests-and-trees/

The whisper of the aspens is not drowned,
And over lightless pane and footless road,
Empty as sky, with every other sound
Not ceasing, calls their ghosts from their abode,

there's one for you... a click will get you nine more. but none will help you 
write a better, more maintainable program.

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


Re: Passing information between modules

2022-11-20 Thread Dan Kolis
Using sys.stdout / is simply nonsense. The more I think about it, the more I 
realise how bad it is.

Going on about it endlessly seems pointless.

If the even mini threading thing is turned on, now what ? some other module 
eats the message intended for a different module ? A state machine with its own 
matching code in sends and receives to reuse the unwanted singular value ?

The precise rules for establishing a variable without the global keyword is not 
obvious, or catcat of anything  by leaving a empty set dangling initially.

*especially* if the program is fundamentally open ended, that is, there could 
be considerable new functions sharing ideas all over, planning ahead for as 
good 45 seconds is a lot better then endless hacking any old way.

1) Make a variable in a module known to be a shared item. Named for that 
specifically.
def Mt() {}
IoDot = {} # Once before program does anything... in global. ref import global 
as gi later.

2) Create highly generalised speculative named ideas init each variable once 
with a {}
ioDot.weights = Mt{} ; ( I make it a local method so the method can stand alone 
for unit testing )

3) Uniformly ref it with a import statement. in all 'other' modules

4) When a shared idea is apparent concat a new named portion to the name for 
this purpose. Then use those fairly without fussing as required. If one scares 
you, set it to {} after some scary moment if you are feeling fussy.

5) All 'ideas' will be at a 3rd or more subsid level in naming. ex:

gi.IoDot.weights.trucks = whatever
gi.IoDot.weights.cars = whatever

gi.toastDot.warnings.tooHeavy
gi.toastDot.warnings.isOk

These can all be any kind of object. So easy

I have a very sizable highly generalized program using this and have not found 
any defect in doing so.

Regs
Dan

 

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


Re: Passing information between modules

2022-11-20 Thread Dan Kolis


It's certainly not an "incredibly bad idea", it is a mildly bad idea however. 
Why be stuck with maybe's and just text strings ?

Functions as "first class operators" and object oriented languages are a 
natural pair with a bit of heavy thinking.

The problem is... there is nobody giving you a 3 line solution without 
thinking. Its a 7 line solution requiring understanding. One you do it right, 
then its a 2 line solution !

Once you construct the bridges; then, in any module you can consider global 
sharables like so:

First vague use of functionality 
  gi.setAsideArea.NewIdea = 'ok'

Next usages anywhere !
  gi.setAsideArea.NewIdea = "StateMachine Argon"

There is no hangover of vague ideas bothering future executions of the code 
either. This is not some scary file buried in a directory system which needs 
calling and might be stale, using bad ideas, etc.

 How much easier can a solution be ?

 Regards,
Daniel B. Kolis
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Passing information between modules

2022-11-19 Thread Dan Kolis


In a module mostly for this purpose; ( big program means many modules aka files 
):
--
globalIdeas.py
--
# Empty object maker ( M T ) ... get it say it !
class MT():
pass

# IO dot area readier 
def prepIO():

# Prep for general IO use really
dotObjOps.ioSupport = MT()
dotObjOps.ioSupport.sequenceMacro = MT()


-
In Every use module:
-
import globalIdeas as   gi 

so now without burdensome advanced planning, a swap area is not only segregated 
by function
but doesn't overly pollute too much globalism everywhere.

New Idea:
gl.ioSupport.sequencesMacro.newStartupIdea = {}
gl.ioSupport.sequencesMacro.thingToReuse = 14
etc ...

A method in globalIdeas is named like startEverything():
  prepIO()
  prepNext()
  prepSounds()
   etc...

This seems to me amenable to management of large programs in which absolutely 
any shaped objects be created as needed and be RW sharable in orderly fashion, 
etc.

Its important if you read write files to plan ahead and have MT() names in 
surplus before you need them.

I cant see any drawback to this at all. Many program have very legit reasons to 
have universal ideas. This avoids the emotional burden of the' "global KW" ; 
entirely.

Regards,
Daniel B. Kolis









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


Re: Are these good ideas?

2022-11-14 Thread Dan Stromberg
On Mon, Nov 14, 2022 at 11:33 AM Axy via Python-list 
wrote:

> On 14/11/2022 17:14, Stephen Tucker wrote:
> > Hi,
> >
> > I have two related issues I'd like comments on.
> >
> > Issue 1 - Global Values
>
> Your "global variables" module acts exactly as a singleton class.
>

Which is apparently a design pattern that some now believe is regrettable.

It's something I've done before too, but it's pretty much shared, mutable
state, which isn't great for functional programming or for parallelism.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: str.replace() when str contains \

2022-10-29 Thread Dan Stromberg
I believe you would do well to print a, before trying to transform it into
something else.

'\2' is chr(2).
'\a' is the bell character, and is unprintable.
'\_' is two characters though.

On Sat, Oct 29, 2022 at 2:12 PM Bernard LEDRU 
wrote:

> Hello,
>
> https://docs.python.org/3/library/stdtypes.html#string-methods
>
> str.replace(old, new[, count])¶
> Return a copy of the string with all occurrences of substring old
> replaced by new. If the optional argument count is given, only the first
> count occurrences are replaced.
>
> Attention when the string contains the escape character.
>
> Consider :
>
> >>> a="H:\2023"; print(a.replace("\\","/"))
> H:3
> >>> a="H:\a2023"; print(a.replace("\\","/"))
> H:2023
> >>> a="H:\_2023"; print(a.replace("\\","/"))
> H:/_2023
>
> Best regards,
> Bernard LEDRU
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Typing: Is there a "cast operator"?

2022-10-23 Thread Dan Stromberg
On Sun, Oct 23, 2022 at 2:11 PM Paulo da Silva <
p_d_a_s_i_l_v_a...@nonetnoaddress.pt> wrote:

> Hello!
>
> I am in the process of "typing" of some of my scripts.
> Using it should help a lot to avoid some errors.
> But this is new for me and I'm facing some problems.
>
> Let's I have the following code (please don't look at the program content):
>
> f=None  # mypy naturally assumes Optional(int) because later, at open,
> it is assigned an int.
> ..
> if f is None:
> f=os.open(...
> ..
> if f is not None:
> os.write(f, ...)
> ..
> if f is not None:
> os.close(f)
>
> When I use mypy, it claims
> Argument 1 to "write" has incompatible type "Optional[int]"; expected "int"
> Argument 1 to "close" has incompatible type "Optional[int]"; expected "int"
>
> How to solve this?
> Is there a way to specify that when calling os.open f is an int only?
>
> I use None a lot for specify uninitialized vars.
>

I've found that mypy understands simple assert statements.

So if you:
if f is not None:
assert f is not None
os.write(f, ...)

You might be in good shape.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2022-10-22 Thread Dan Stromberg
I don't think there is a "correct" way.  It depends somewhat on what tools
you're using.  I like pydocstyle, which I have hung off of vim with
syntastic.  pydocstyle checks for https://peps.python.org/pep-0257/
conformance.

Also, rather than describe the types of formal parameters to functions in a
docstring, I like to use mypy for https://peps.python.org/pep-0484/ with
its --disallow-untyped-calls and --ignore-missing-imports options, which I
hang off of a Makefile, called by a vim macro.

On Sat, Oct 22, 2022 at 3:39 PM Paulo da Silva <
p_d_a_s_i_l_v_a...@nonetnoaddress.pt> wrote:

> Hi all!
>
> What is the correct way, if any, of documenting a function/method?
>
> 1.
> def foo(a,b):
> """ A description.
> a: Whatever 1
> b: Whatever 2
> """
> ...
>
> 2.
> def foo(a,b):
> """ A description.
> a -- Whatever 1
> b -- Whatever 2
> """
> ...
>
> 3.
> def foo(a,b):
> """ A description.
> @param a: Whatever 1
> @param b: Whatever 2
> """
> ...
>
> 4.
> def foo(a,b):
> """ A description.
> :param a: Whatever 1
> :param b: Whatever 2
> """
> ...
>
> 5.
> Any other ...
>
> Any comments/suggestions are welcome.
> Thanks.
> Paulo
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command [POSTPONED]

2022-10-15 Thread Dan Stromberg
On Wed, Oct 12, 2022 at 9:57 PM Cameron Simpson  wrote:

> On 13Oct2022 03:25, Paulo da Silva 
> wrote:
> >There is another problem involved. The script, works fine except when
> >launched by cron! Why?
>
> Record the script output:
>
>  # record all output
>  exec >/tmp/script.$$.out 2>&1
>  # dump the envionment
>  env | sort
>  # turn on execution tracing
>  set -x
>  ... rest of the script
>
> and have a look afterwards. Cron's environment is very minimal. This
> will show you what's in it.
>

Careful.  On some systems if someone restarts the cron daemon, it could
pick up a larger environment than after being started on boot.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-14 Thread Dan Stromberg
On Wed, Oct 12, 2022 at 11:13 AM Paulo da Silva <
p_d_a_s_i_l_v_a...@nonetnoaddress.pt> wrote:

> 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?
>
I like to test my cronjobs with something like:

env - /usr/local/bin/my-cronjob

This will empty out the environment, and force you to set $PATH yourself.

Alternatively, you can "ps axfwwe" (on Linux) to see environment variables,
and check what the environment of cron (or similar) is.  It is this
environment (mostly) that cronjobs will inherit.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread Dan Stromberg
On Tue, Oct 11, 2022 at 12:48 PM SquidBits _  wrote:

> Does anyone else think there should be a flatten () function, which just
> turns a multi-dimensional list into a one-dimensional list in the order
> it's in. e.g.
>
> [[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
>
> I have had to flatten lists quite a few times and it's quite tedious to
> type out. It feels like this should be something built in to python, anyone
> else think this way?
>

I think the usual argument against putting something like this in the
standard library (I hope it won't be built in), is that there are many ways
to define "flatten".  That is, should it only go one level deep?   All the
way to the bottom?  n levels deep?  Should it do something special with
lists, dicts, tuples, sets?

This looks like a nice URL on the topic:
https://www.pythonpool.com/flatten-list-python/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for -- else: what was the motivation?

2022-10-07 Thread Dan Stromberg
The else is executed if you don't "break" out of the loop early.

It cuts down on boolean flags.

On Fri, Oct 7, 2022 at 8:40 PM Axy via Python-list 
wrote:

> Hi there,
>
> this is rather a philosophical question, but I assume I miss something.
> I don't remember I ever used else clause for years I was with python and
> my expectation was it executed only if the the main body was never run.
> Ha-ha! I was caught by this mental trap.
>
> So, seriously, why they needed else if the following pieces produce same
> result? Does anyone know or remember their motivation?
>
> Just curious.
>
> Axy.
>
> print('--- with else')
>
>
> for i in [1,2,3]:
>  print(i)
> else:
>  print(4)
>
> for i in []:
>  print(i)
> else:
>  print(5)
>
> print('--- without else')
>
> for i in [1,2,3]:
>  print(i)
> print(4)
>
> for i in []:
>  print(i)
> print(5)
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.9.14

2022-09-16 Thread Dan Stromberg
‪On Wed, Sep 14, 2022 at 6:05 AM ‫אורי‬‎  wrote:‬

> Hi,
>
> Python 3.9.14 has been released on Sept. 6, 2022. As I can see written on
> https://www.python.org/downloads/release/python-3914/:
>
> According to the release calendar specified in PEP 596, Python 3.9 is now
> in the "security fixes only" stage of its life cycle: the 3.9 branch only
> accepts security fixes and releases of those are made irregularly in
> source-only form until October 2025. Python 3.9 isn't receiving regular bug
> fixes anymore, and binary installers are no longer provided for it. Python
> 3.9.13 was the last full bugfix release of Python 3.9 with binary
> installers.
>
>
> Is there a safe way to install a 64-bit version of Python 3.9.14 on
> Windows?
>

I use Windows as little as I can, but you could check to see if Conda or
the Microsoft Store will give you CPython 3.9 binaries.

If that isn't happening, you could try compiling your own from the
python.org sources.  On Linux, that's pretty simple: extract the archive,
./configure && make && sudo make install
I don't know if it'll be easier or harder on WIndows.  I want to say you
could get MSYS2 as a development environment, but ISTR hearing that Python
wants to be compiled with Microsoft's compiler on Windows for ABI
compatibility.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace an instance method?

2022-09-16 Thread Dan Stromberg
On Fri, Sep 16, 2022 at 2:06 PM Ralf M.  wrote:

> I would like to replace a method of an instance, but don't know how to
> do it properly.
>

You appear to have a good answer, but...  are you sure this is a good idea?

It'll probably be confusing to future maintainers of this code, and I doubt
static analyzers will like it either.

I'm not the biggest fan of inheritance you'll ever meet, but maybe this is
a good place for it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-02 Thread Dan Stromberg
On Thu, Sep 1, 2022 at 9:16 AM Chris Angelico  wrote:

> On Fri, 2 Sept 2022 at 02:10, James Tsai  wrote:
> >
> > Hello,
> >
> > I find it very useful if I am allowed to define new local variables in a
> list comprehension. For example, I wish to have something like
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
> >
> > For now this functionality can be achieved by writing
> > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> >
> > Is it worthwhile to add a new feature like this in Python? If so, how
> can I propose this to PEP?
>
> Not everything has to be a one-liner.
>
So true!

I like list comprehensions and generator expressions, but sometimes I end
up regretting their use when there's a bug, and I have to convert one to a
for loop + list.append in order to debug.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Coffee

2022-08-29 Thread Dan Stromberg
On Mon, Aug 29, 2022 at 1:10 PM Meredith Montgomery 
wrote:

> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>
> > |Python's obviously a great tool for all kinds of programming things,
> > |and I would say if you're only gonna use one programming
> > |language in your live, Python will probably the right one.
> > Brian Kernighan
> >
> >   I transcribed this from the recent video
> >   "Coffee with Brian Kernighan".
>
> Sounds reasonable.  I have been learning Python bit by bit simply
> because there seems to be no other way to talk to university people.
> But somehow I am so in love with Lisp that it makes me sort of blind
> because sometimes I feel more productive in Python simply because I'm
> always using it.  When I can write Lisp, I do it, but often I feel like
> I'm a role-playing TCP Slow Start or something like that.
>

ISTR hearing that Python and Lisp are pretty similar semantically - not
because Python copied it, but because similar thinking went into the design
of each.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess.popen how wait complete open process

2022-08-21 Thread Dan Stromberg
On Sun, Aug 21, 2022 at 2:05 PM Chris Angelico  wrote:

> On Mon, 22 Aug 2022 at 05:39, simone zambonardi
>  wrote:
> >
> > Hi, I am running a program with the punishment subrocess.Popen(...) what
> I should do is to stop the script until the launched program is fully open.
> How can I do this? I used a time.sleep() function but I think there are
> other ways. Thanks
> >
>
> First you have to define "fully open". How would you know?
>

If you're on X11, you could conceivably use:
 xwininfo -tree -root
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: setup.py + cython == chicken and the egg problem

2022-08-18 Thread Dan Stromberg
On Tue, Aug 16, 2022 at 2:03 PM Dan Stromberg  wrote:

> Hi folks.
>
> I'm attempting to package up a python package that uses Cython.
>
> Rather than build binaries for everything under the sun, I've been
> focusing on including the .pyx file and running cython on it at install
> time.  This requires a C compiler, but I'm OK with that.
>
> BTW, the pure python version works fine, and the cython version works too
> as long as you preinstall cython - but I don't want users to have to know
> that :)
>

For the actual chicken-and-egg problem, I'd needed to include my
pyproject.toml in my MANIFEST.in, like:
include pyx_treap.pyx pyx_treap.c pyproject.toml
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: setup.py + cython == chicken and the egg problem

2022-08-17 Thread Dan Stromberg
On Wed, Aug 17, 2022 at 3:05 PM Dan Stromberg  wrote:

> I commented out those too lines, but I'm still getting errors.  They seem
>> to stem from:
>> $ "/home/dstromberg/venv/pyx-treap-testing/bin/python3",
>> ["/home/dstromberg/venv/pyx-treap-testing/bin/python3",
>> "/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py",
>> "install", "--ignore-installed", "--no-user", "--prefix",
>> "/tmp/pip-build-env-9_ivrsb6/overlay", "--no-warn-script-location",
>> "--no-binary", ":none:", "--only-binary", ":none:", "-i", "
>> https://test.pypi.org/simple/";, "--", "setuptools >= 44.1.1", "wheel",
>> "Cython"]
>> "/home/dstromberg/venv/pyx-treap-testing/bin/python3"
>> "/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py"
>> "install" "--ignore-installed" "--no-user" "--prefix"
>> "/tmp/pip-build-env-9_ivrsb6/overlay" "--no-warn-script-location"
>> "--no-binary" ":none:" "--only-binary" ":none:" "-i" "
>> https://test.pypi.org/simple/"; "--" "setuptools >= 44.1.1" "wheel"
>> "Cython"
>> Looking in indexes: https://test.pypi.org/simple/
>> ERROR: Could not find a version that satisfies the requirement
>> setuptools>=44.1.1 (from versions: none)
>> ERROR: No matching distribution found for setuptools>=44.1.1
>>
>> I copied that out of an strace.
>>
>> That's likely related to my pyproject.toml:
>> $ cat pyproject.toml
>> below cmd output started 2022 Wed Aug 17 01:57:09 PM PDT
>> [build-system]
>> requires = ["setuptools >= 44.1.1", "wheel", "Cython"]
>> build-backend = "setuptools.build_meta"
>>
>> Any other suggestions folks?
>>
>
> I don't know why, but if I delete the --ignore-installed option, I don't
> get the error:
> $ "/home/dstromberg/venv/pyx-treap-testing/bin/python3"
> "/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py"
> "install" "--ignore-installed" "--prefix"
> "/tmp/pip-build-env-9_ivrsb6/overlay" "-i" "https://test.pypi.org/simple/";
> "--" "setuptools>=44.1.1"
> below cmd output started 2022 Wed Aug 17 02:56:24 PM PDT
> Looking in indexes: https://test.pypi.org/simple/
> ERROR: Could not find a version that satisfies the requirement
> setuptools>=44.1.1 (from versions: none)
> ERROR: No matching distribution found for setuptools>=44.1.1
> (setuptools-investigation) above cmd output done2022 Wed Aug 17
> 02:56:24 PM PDT
> dstromberg@tp-mini-c:~ x86_64-pc-linux-gnu 2995
>
> $ "/home/dstromberg/venv/pyx-treap-testing/bin/python3"
> "/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py"
> "install" "--prefix" "/tmp/pip-build-env-9_ivrsb6/overlay" "-i" "
> https://test.pypi.org/simple/"; "--" "setuptools>=44.1.1"
> below cmd output started 2022 Wed Aug 17 02:56:35 PM PDT
> Looking in indexes: https://test.pypi.org/simple/
> Requirement already satisfied: setuptools>=44.1.1 in
> ./venv/pyx-treap-testing/lib/python3.9/site-packages (63.4.1)
>
> If I search for foo on pypi and testpypi, shouldn't I get foo before
> foo-bar and bar-foo?
>
> Because if I search for setuptools on pypi, I get setuptools as my first
> hit, but on testpypi, I don't see setuptools anywhere in the first page.
> That's perhaps significant if the search ordering is working as described
> above.
>
> ?
>

IOW, maybe testpypi doesn't have setuptools.  Indeed, it doesn't appear
to.  Publishing and installing from the real pypi seems to be working.

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


Re: setup.py + cython == chicken and the egg problem

2022-08-17 Thread Dan Stromberg
On Wed, Aug 17, 2022 at 1:58 PM Dan Stromberg  wrote:

> On Wed, Aug 17, 2022 at 10:20 AM Christian Gollwitzer 
> wrote:
>
>> Am 16.08.22 um 23:03 schrieb Dan Stromberg:
>> > I'm attempting to package up a python package that uses Cython.
>> >
>> > Rather than build binaries for everything under the sun, I've been
>> focusing
>> > on including the .pyx file and running cython on it at install time.
>> This
>> > requires a C compiler, but I'm OK with that.
>> >
>> > However, when I try to install the package from test.pypi.org, I get:
>> > $ python3 -m pip install -i https://test.pypi.org/simple/ pyx-treap
>> > below cmd output started 2022 Tue Aug 16 01:55:16 PM PDT
>> > Looking in indexes: https://test.pypi.org/simple/
>> > Collecting pyx-treap
>> >Downloading
>> >
>> https://test-files.pythonhosted.org/packages/3a/41/af5360934adccfc086a39e1f720323895144b53454ff6dacc0f06267db55/pyx_treap-2.0.15.tar.gz
>> > (125 kB)
>> >
>> >
>>  
>> 
>> > 125.9/125.9 kB 1.9 MB/s eta 0:00:00
>> >Installing build dependencies ... error
>> >error: subprocess-exited-with-error
>> >
>> >×? pip subprocess to install build dependencies did not run
>> successfully.
>> >?? exit code: 1
>> >> [3 lines of output]
>> >Looking in indexes: https://test.pypi.org/simple/
>> >ERROR: Could not find a version that satisfies the requirement
>> > setuptools (from versions: none)
>> >ERROR: No matching distribution found for setuptools
>> >[end of output]
>> >
>> >note: This error originates from a subprocess, and is likely not a
>> > problem with pip.
>> > error: subprocess-exited-with-error
>>
>>
>> I looked at your code and I think you are trying too hard. As far as I
>> understand, you need Cython to be installed before the build process
>> begins. Your entry in pyproject.toml should take care of that.
>> But you also have these lines in your setup.py
>>
>> subprocess.check_call('%s -m pip install cython' % (sys.executable, ),
>> shell=True)
>> subprocess.check_call('%s -m cython pyx_treap.pyx' % (sys.executable, ),
>> shell=True)
>>
>> The first one calls out to pip while pip is already running, I'm not
>> sure that this will work, but judging from the error message it is
>> looking for the requirements also from test.pypi. Maybe this is the
>> reason that it fails (the error message says that it can't find
>> setuptools). So jut delete this line and it might already work
>>
>> The second line, which compiles the Cython code, also runs *at every
>> invocation of setup.py*, even if you'd do just
>>
>> python3 setup.py --help
>>
>> It may still work, but the correct way to do it is to create a build
>> extension for setuptools. In my project you can see this here:
>>
>> https://github.com/j-from-b/CDEF/blob/main/setup.py#L88
>>
>> OTOH, I would be surprised if Cython did not have this already, indeed
>> you imported cythonize from Cython.Build. So maybe just deleting these
>> two lines and it might work?
>>
>
> I commented out those too lines, but I'm still getting errors.  They seem
> to stem from:
> $ "/home/dstromberg/venv/pyx-treap-testing/bin/python3",
> ["/home/dstromberg/venv/pyx-treap-testing/bin/python3",
> "/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py",
> "install", "--ignore-installed", "--no-user", "--prefix",
> "/tmp/pip-build-env-9_ivrsb6/overlay", "--no-warn-script-location",
> "--no-binary", ":none:", "--only-binary", ":none:", "-i", "
> https://test.pypi.org/simple/";, "--", "setuptools >= 44.1.1", "wheel",
> "Cython"]
> "/home/dstromberg/venv/pyx-treap-testing/bin/python3"
> "/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py"
> "install" "--ignore-installed" "--no-user" "--prefix"
> "/tmp/pip-build-env-9_ivrsb6/overlay" "--no-warn-script-location"
> "--no-binary" ":none:" "--only-binary" ":none:" "-i" "
> https://test.pypi.org/

Re: setup.py + cython == chicken and the egg problem

2022-08-17 Thread Dan Stromberg
On Wed, Aug 17, 2022 at 10:20 AM Christian Gollwitzer 
wrote:

> Am 16.08.22 um 23:03 schrieb Dan Stromberg:
> > I'm attempting to package up a python package that uses Cython.
> >
> > Rather than build binaries for everything under the sun, I've been
> focusing
> > on including the .pyx file and running cython on it at install time.
> This
> > requires a C compiler, but I'm OK with that.
> >
> > However, when I try to install the package from test.pypi.org, I get:
> > $ python3 -m pip install -i https://test.pypi.org/simple/ pyx-treap
> > below cmd output started 2022 Tue Aug 16 01:55:16 PM PDT
> > Looking in indexes: https://test.pypi.org/simple/
> > Collecting pyx-treap
> >Downloading
> >
> https://test-files.pythonhosted.org/packages/3a/41/af5360934adccfc086a39e1f720323895144b53454ff6dacc0f06267db55/pyx_treap-2.0.15.tar.gz
> > (125 kB)
> >
> >
>  
> 
> > 125.9/125.9 kB 1.9 MB/s eta 0:00:00
> >Installing build dependencies ... error
> >error: subprocess-exited-with-error
> >
> >×? pip subprocess to install build dependencies did not run
> successfully.
> >?? exit code: 1
> >> [3 lines of output]
> >Looking in indexes: https://test.pypi.org/simple/
> >ERROR: Could not find a version that satisfies the requirement
> > setuptools (from versions: none)
> >ERROR: No matching distribution found for setuptools
> >[end of output]
> >
> >note: This error originates from a subprocess, and is likely not a
> > problem with pip.
> > error: subprocess-exited-with-error
>
>
> I looked at your code and I think you are trying too hard. As far as I
> understand, you need Cython to be installed before the build process
> begins. Your entry in pyproject.toml should take care of that.
> But you also have these lines in your setup.py
>
> subprocess.check_call('%s -m pip install cython' % (sys.executable, ),
> shell=True)
> subprocess.check_call('%s -m cython pyx_treap.pyx' % (sys.executable, ),
> shell=True)
>
> The first one calls out to pip while pip is already running, I'm not
> sure that this will work, but judging from the error message it is
> looking for the requirements also from test.pypi. Maybe this is the
> reason that it fails (the error message says that it can't find
> setuptools). So jut delete this line and it might already work
>
> The second line, which compiles the Cython code, also runs *at every
> invocation of setup.py*, even if you'd do just
>
> python3 setup.py --help
>
> It may still work, but the correct way to do it is to create a build
> extension for setuptools. In my project you can see this here:
>
> https://github.com/j-from-b/CDEF/blob/main/setup.py#L88
>
> OTOH, I would be surprised if Cython did not have this already, indeed
> you imported cythonize from Cython.Build. So maybe just deleting these
> two lines and it might work?
>

I commented out those too lines, but I'm still getting errors.  They seem
to stem from:
$ "/home/dstromberg/venv/pyx-treap-testing/bin/python3",
["/home/dstromberg/venv/pyx-treap-testing/bin/python3",
"/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py",
"install", "--ignore-installed", "--no-user", "--prefix",
"/tmp/pip-build-env-9_ivrsb6/overlay", "--no-warn-script-location",
"--no-binary", ":none:", "--only-binary", ":none:", "-i", "
https://test.pypi.org/simple/";, "--", "setuptools >= 44.1.1", "wheel",
"Cython"]
"/home/dstromberg/venv/pyx-treap-testing/bin/python3"
"/home/dstromberg/venv/pyx-treap-testing/lib/python3.9/site-packages/pip/__pip-runner__.py"
"install" "--ignore-installed" "--no-user" "--prefix"
"/tmp/pip-build-env-9_ivrsb6/overlay" "--no-warn-script-location"
"--no-binary" ":none:" "--only-binary" ":none:" "-i" "
https://test.pypi.org/simple/"; "--" "setuptools >= 44.1.1" "wheel" "Cython"
Looking in indexes: https://test.pypi.org/simple/
ERROR: Could not find a version that satisfies the requirement
setuptools>=44.1.1 (from versions: none)
ERROR: No matching distribution found for setuptools>=44.1.1

I copied that out of an strace.

That's likely related to my pyproject.toml:
$ cat pyproject.toml
below cmd output started 2022 Wed Aug 17 01:57:09 PM PDT
[build-system]
requires = ["setuptools >= 44.1.1", "wheel", "Cython"]
build-backend = "setuptools.build_meta"

Any other suggestions folks?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: not able to use python

2022-08-17 Thread Dan Ciprus (dciprus) via Python-list

Those people keep me on my toes every time I look at such a message :-/.


On Wed, Aug 17, 2022 at 12:35:28PM -0500, Igor Korot wrote:

Hi,

On Wed, Aug 17, 2022 at 12:20 PM i am unable to use python
 wrote:





AND I"M UNABLE TO SEE ANYTHING IN YOUR MESSAGE...

THANK YOU.





   Sent from [1]Mail for Windows



References

   Visible links
   1. https://go.microsoft.com/fwlink/?LinkId=550986
--
https://mail.python.org/mailman/listinfo/python-list

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


--
Daniel Ciprus  .:|:.:|:.
CONSULTING ENGINEER.CUSTOMER DELIVERY   Cisco Systems Inc.
dcip...@cisco.com
tel: +1-703-484-0205
mob: +1-540-223-7098

[ curl -L http://git.io/unix ]


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


Re: setup.py + cython == chicken and the egg problem

2022-08-16 Thread Dan Stromberg
On Tue, Aug 16, 2022 at 2:08 PM Chris Angelico  wrote:

> On Wed, 17 Aug 2022 at 07:05, Dan Stromberg  wrote:
> >
> > Hi folks.
> >
> > I'm attempting to package up a python package that uses Cython.
> >
> > Rather than build binaries for everything under the sun, I've been
> focusing
> > on including the .pyx file and running cython on it at install time.
> This
> > requires a C compiler, but I'm OK with that.
> >
>
> Is keeping the cythonized file an option? That would still require a C
> compiler, but wouldn't require Cython.
>
> ChrisA
>

That comes under "one of the many things I tried"; it seemed like some of
the code in the .c was tailored to the specific version of python it was
being installed on or something.

But if someone has seen this work well, I'm more than open to trying it
again.
-- 
https://mail.python.org/mailman/listinfo/python-list


setup.py + cython == chicken and the egg problem

2022-08-16 Thread Dan Stromberg
Hi folks.

I'm attempting to package up a python package that uses Cython.

Rather than build binaries for everything under the sun, I've been focusing
on including the .pyx file and running cython on it at install time.  This
requires a C compiler, but I'm OK with that.

However, when I try to install the package from test.pypi.org, I get:
$ python3 -m pip install -i https://test.pypi.org/simple/ pyx-treap
below cmd output started 2022 Tue Aug 16 01:55:16 PM PDT
Looking in indexes: https://test.pypi.org/simple/
Collecting pyx-treap
  Downloading
https://test-files.pythonhosted.org/packages/3a/41/af5360934adccfc086a39e1f720323895144b53454ff6dacc0f06267db55/pyx_treap-2.0.15.tar.gz
(125 kB)

 

125.9/125.9 kB 1.9 MB/s eta 0:00:00
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  ×? pip subprocess to install build dependencies did not run successfully.
  ?? exit code: 1
  > [3 lines of output]
  Looking in indexes: https://test.pypi.org/simple/
  ERROR: Could not find a version that satisfies the requirement
setuptools (from versions: none)
  ERROR: No matching distribution found for setuptools
  [end of output]

  note: This error originates from a subprocess, and is likely not a
problem with pip.
error: subprocess-exited-with-error

×? pip subprocess to install build dependencies did not run successfully.
?? exit code: 1
> See above for output.

note: This error originates from a subprocess, and is likely not a problem
with pip.

But I analyzed the pip install with strace, and found no interesting
exec's, and no interesting "= E" patterns.

I've tried quite an assortment of things to get past this, including most
of those at:
https://stackoverflow.com/questions/4996589/in-setup-py-or-pip-requirements-file-how-to-control-order-of-installing-package
Except the one at:
https://stackoverflow.com/a/54269307/1084684
...because I was having a "there must be a better way" reaction to it.

/Is/ there a better way?

There're all these newer ways of doing packaging - surely one of them
addresses this problem?

The code I'm trying to package is at:
https://stromberg.dnsalias.org/svn/treap/trunk/cython

BTW, the pure python version works fine, and the cython version works too
as long as you preinstall cython - but I don't want users to have to know
that :)

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


Re: Conecting to MySQL

2022-08-09 Thread Dan Ciprus (dciprus) via Python-list
I'm not sure about this but this mailing list does not allow attachments ... 


On Tue, Aug 09, 2022 at 12:45:33PM -0300, Guilherme Campos wrote:

Hi Igor,

Accessing mysql-workbench it appeared new error messages when I clicked
Server Status.

I created my database on MySQL Workbench . Is that your question?


[image: image.png]

[image: image.png]


Em ter., 9 de ago. de 2022 às 12:36, Igor Korot 
escreveu:


Hi,
@OP,
Can you try to connect with mysql-workbench?
Also - you didn't answer my first question.

Are you using an ODBC wrapper or python module?

Thank you.


On Tue, Aug 9, 2022 at 10:27 AM Axy  wrote:
>
>
> >> trying to connect to MYSQL it appears the error msg below:
> >> InterfaceError: 2003: Can't connect to MySQL server on
'localhost:3306'
> >> (111 Connection refused)
> >> [image: conexao.png]
> >> How can i fix that.?
> > What do you use for connection?
> > Does the firewall interfere with the connection?
>
> Firewall usually causes connection to hang and timeout with no response.
>
> But in this case connection looks immediately refused which means either
> port number is wrong or mysql is not listening on 127.0.0.1.
>
>
> Axy
>


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


--
Daniel Ciprus  .:|:.:|:.
CONSULTING ENGINEER.CUSTOMER DELIVERY   Cisco Systems Inc.
dcip...@cisco.com
tel: +1-703-484-0205
mob: +1-540-223-7098

[ curl -L http://git.io/unix ]


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


Re: Conecting to MySQL

2022-08-09 Thread Dan Ciprus (dciprus) via Python-list

Yes, exactly that .. I replied from different account and my email was 
rejected. Just make sure that
your mysql is actually running. Depending on your OS, run netstat -an | grep 
3306 and this will tell
you whether socket is actually in listening mode or not. If it's not, your 
mysql is either not
running or you have a problem with the configuration.

On Tue, Aug 09, 2022 at 08:27:16AM -0700, Axy via Python-list wrote:



trying to connect to MYSQL it appears the error msg below:
InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306'
(111 Connection refused)
[image: conexao.png]
How can i fix that.?

What do you use for connection?
Does the firewall interfere with the connection?


Firewall usually causes connection to hang and timeout with no response.

But in this case connection looks immediately refused which means 
either port number is wrong or mysql is not listening on 127.0.0.1.



Axy

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


--
Daniel Ciprus  .:|:.:|:.

[ curl -L http://git.io/unix ]


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


Re: Parallel(?) programming with python

2022-08-08 Thread Dan Stromberg
Queues are better than lists for concurrency.  If you get the right kind,
they have implicit locking, making your code simpler and more robust at the
same time.

CPython threading is mediocre for software systems that have one or more
CPU-bound threads, and your FFT might be CPU-bound.

Rather than using threading directly, you probably should use
https://docs.python.org/3/library/concurrent.futures.html , which gives you
easy switching between threads and processes.

Or if you, like me, get inordinately joyous over programs that run on more
than one kind of Python, you could give up concurrent.futures and use
_thread.  Sadly, that gives up easy flipping between threads and processes,
but gives you easy flipping between CPython and micropython.  Better still,
micropython appears to have more scalable threading than CPython, so if you
decide you need 20 CPU-hungry threads someday, you are less likely to be in
a bind.

For reading from a socket, if you're not going the REST route, may I
suggest https://stromberg.dnsalias.org/~strombrg/bufsock.html ?  It deals
with framing and lengths relatively smoothly.  Otherwise, robust socket
code tends to need while loops and tedious arithmetic.

HTH

On Mon, Aug 8, 2022 at 10:59 AM Andreas Croci  wrote:

> I would like to write a program, that reads from the network a fixed
> amount of bytes and appends them to a list. This should happen once a
> second.
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand nested loops

2022-08-08 Thread Dan Purgert
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

dn wrote:
> On 06/08/2022 11.41, avi.e.gr...@gmail.com wrote:
>> I wonder if someone is pulling our leg as they are sending from an
>> invalid email address of "GB " which is
>> a bit sick.
>
> There are a number of folk who use evidently false email addresses - the
> OP's had me amused.
>
> Such 'hiding' is a matter for the List-Admins (thanks for all the work
> exerted on our behalf!) and how it fits with the Code-of-Conduct.

Invalid sending addresses (email@somewhere.invalid) are a standard
practice in Usenet, to combat bots scraping posts for email addresses
(remember, Usenet predates basically all spam prevention tech).

As there is a gateway between the mailing lists and Usenet, I *imagine*
that the use of said invalid addresses are within the rules -- I mean,
if they weren't, the maintainers wouldn't keep the two lists
connected.


-BEGIN PGP SIGNATURE-

iQIzBAEBCgAdFiEE3asj+xn6fYUcweBnbWVw5UznKGAFAmLw+rkACgkQbWVw5Uzn
KGBT4A/8DR8GWlEgZhcoaLYTnQCfBv8YmykUxQ69/Xwf7o34S/ObtN0WTapgEBkB
xamJHzFKENVeOoFwNgWkAaLSfOm2704DqO4vEJBZmCGrPtLTjHmpQuIcg2c+cjwz
EEaYCuWmQZrviFS9ZeWX4FIMX9IlZ3Sgy7e/qHvdI5jeclw4oltYdRxVO3h9WylM
BXn3Lvqntw+/5xV3vI/B2SODBTkB8a4D0vC64a3NwGqA3eUkyZrJYlVX8igubBwJ
/sDLTy9EOK7wmokoXIHjj7KN+s5bC8idUN/V6DJiE6Z3vU0AOujKsw8jyQbndP9d
7da3gDLECMTHTFuKkj8kWC005aaWdM+GYzm1nofQC0jpINCP88IVce9curm11IQa
AVWmxNBuGtLh8E3iE5WaydkgwZJXAll2cewOtzyJ0H8qeMwcqtL7hcKwdVPSzSYG
JDqcbthDAzJg/PXcLjBHidXNZQ1BhyLw9ySzf+/7buiSsMdHuYZEohHXH4ybRMtL
hlg6r09b5nDbKD7C9hVfL21+mogcX9t+LehsqiPLXssyMHRpTmGRzQ+CBySg5QaV
gXshFJxRqvp9UtL+xw/wNL3wODsaVTU430qSKUI1ov7ClqcUXvEP5cbmKa9ufJ/J
8iDSbAP2B54pGyF9hfF0f8h267bZy13gWWqBqiFoCBZcVkaC/Jo=
=6yDi
-END PGP SIGNATURE-

-- 
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand nested loops

2022-08-05 Thread Dan Stromberg
On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards 
wrote:

> In C, this doesn't do what it looks like it's supposed to do.
>
>if (foo)
>  do_this();
>  and_this();
>then_do_this();
>
It's been quite a while since I used C, but with the right compiler
flag(s), I think this may be a thing of the past when compiling with gcc:
https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand nested loops

2022-08-05 Thread Dan Stromberg
On Fri, Aug 5, 2022 at 12:30 PM 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.
>
No, you should indent properly anyway. Python just reduces the number of
things to worry about.

Please see:
https://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
...for the usual.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand nested loops

2022-08-05 Thread Dan Stromberg
On Fri, Aug 5, 2022 at 12:35 AM  wrote:

> Hello, I’m new to learning python and I stumbled upon a question nested
> loops. This is the question below. Can you please how they arrived at 9 as
> the answer. Thanks
>
> var = 0
> for i in range(3):
>   for j in range(-2,-7,-2):
> var += 1
>  print(var)
>

A debugger is useful for more than debugging; it can also help give an
intuition for control flow.  If you single step through this snippet with a
debugger, you'll probably see what's happening.

Of if you don't have (or want) a debugger, you could change it to:

var = 0
for i in range(3):
  print('i is', i)
  for j in range(-2,-7,-2):
print('j is', j)
var += 1
print(var)

And note that 3 times 3 is 9.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dictionary order?

2022-08-01 Thread Dan Stromberg
On Mon, Aug 1, 2022 at 4:42 PM Dan Stromberg  wrote:

>
> > Yes, but I'm pretty sure that's been true for a LONG time. The hashes
>> > for small integers have been themselves for as long as I can remember.
>> > But the behaviour of the dictionary, when fed such keys, is what's
>> > changed.
>>
>> I'm not disputing either of those facts.  I'm pointing out that the
>> apparently arbitrary order of a mapping's keys becomes obvious when you
>> look at the hashes of those keys.
>>
>
> It looks like the relationship no longer holds at around keys =
> list(range(250, 260))
>
> But i == hash(i) holds for the first million values at least.
>

I could've been more clear.  int dict keys stop being stored-in-order at
near 256.

But i == hash(i) holds for the first million values, and probably more.

This suggests to me that there's something more than i == hash(i) going on
inside dict's - but it doesn't much matter what it is for my purposes.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dictionary order?

2022-08-01 Thread Dan Stromberg
On Mon, Aug 1, 2022 at 3:25 PM <2qdxy4rzwzuui...@potatochowder.com> wrote:

> On 2022-08-02 at 07:50:52 +1000,
> Chris Angelico  wrote:
>
> > On Tue, 2 Aug 2022 at 07:48, <2qdxy4rzwzuui...@potatochowder.com> wrote:
> > >
> > > On 2022-08-01 at 13:41:11 -0700,
> > > Dan Stromberg  wrote:
> > >
> > > > keys = [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7, 12, 11]
> > > >
> > > > dict_ = {}
> > > > for key in keys:
> > > > dict_[key] = 1
> > >
> > > $ python
> > > Python 3.10.5 (main, Jun  6 2022, 18:49:26) [GCC 12.1.0] on linux
> > > Type "help", "copyright", "credits" or "license" for more information.
> > > >>> [hash(x) for x in range(20)]
> > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
> > >
> > > Just sayin'.  :-)
> >
> > Yes, but I'm pretty sure that's been true for a LONG time. The hashes
> > for small integers have been themselves for as long as I can remember.
> > But the behaviour of the dictionary, when fed such keys, is what's
> > changed.
>
> I'm not disputing either of those facts.  I'm pointing out that the
> apparently arbitrary order of a mapping's keys becomes obvious when you
> look at the hashes of those keys.
>

It looks like the relationship no longer holds at around keys =
list(range(250, 260))

But i == hash(i) holds for the first million values at least.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dictionary order?

2022-08-01 Thread Dan Stromberg
On Mon, Aug 1, 2022 at 1:41 PM Dan Stromberg  wrote:

> On 1.4 through 2.1 I got descending key order.  I expected the keys to be
> scattered, but they weren't.
>
I just noticed that 1.4 was ascending order too - so it was closer to 2.2
than 1.5.

I guess that's kind of beside the point though - it's still more ordered
than I'd've expected.
-- 
https://mail.python.org/mailman/listinfo/python-list


Dictionary order?

2022-08-01 Thread Dan Stromberg
Hi folks.

I'm still porting some code from Python 2.7 to 3.10.

As part of that, I saw a list being extended with a dict.values(), and
thought perhaps it wasn't ordered as intended on Python 2.7, even though
the problem would conceivably just disappear on 3.10.

So I decided to write a little test program to run on a variety of
CPythons, to confirm what I was thinking.

And instead I got a surprise.

On 1.4 through 2.1 I got descending key order.  I expected the keys to be
scattered, but they weren't.

On 2.2 through 3.5 I got ascending key order.  I expected the keys to be
scattered, but they weren't.

On 3.6 through 3.10 I got insertion order, as expected.

But why are 1.4 through 3.5 ordering so much?  It's like they're a treap or
red-black tree or something.  I'm pretty sure dict's used to be ordered in
a mostly-arbitrary way.

What am I missing?

Here's the little test program:

#!/usr/local/cpython-2.7/bin/python2

import sys

keys = [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7, 12, 11]

dict_ = {}
for key in keys:
dict_[key] = 1

if list(dict_.keys()) == keys:
# The order matches
print('compact')
sys.exit(0)
else:
# The order does not match
print('list(dict_): %s, keys: %s' % (list(dict_.keys()), keys))
sys.exit(1)

Here's some output (irrelevant python's deleted) when run under
https://stromberg.dnsalias.org/~strombrg/pythons/

/usr/local/cpython-1.4/bin/python (1.4) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-1.5/bin/python (1.5.2) bad  list(dict_): [15, 14, 12,
11, 10, 9, 8, 7, 6, 5, 4, 2, 1], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-1.6/bin/python (1.6.1) bad  list(dict_): [15, 14, 12,
11, 10, 9, 8, 7, 6, 5, 4, 2, 1], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.0/bin/python (2.0.1) bad  list(dict_): [15, 14, 12,
11, 10, 9, 8, 7, 6, 5, 4, 2, 1], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.1/bin/python (2.1.0) bad  list(dict_): [15, 14, 12,
11, 10, 9, 8, 7, 6, 5, 4, 2, 1], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.2/bin/python (2.2.0) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.3/bin/python (2.3.0) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.4/bin/python (2.4.0) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.5/bin/python (2.5.6) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.6/bin/python (2.6.9) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-2.7/bin/python (2.7.16) bad  list(dict_): [1, 2, 4, 5,
6, 7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-3.0/bin/python (3.0.1) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-3.1/bin/python (3.1.5) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-3.2/bin/python (3.2.5) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-3.3/bin/python (3.3.7) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-3.4/bin/python (3.4.8) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-3.5/bin/python (3.5.5) bad  list(dict_): [1, 2, 4, 5, 6,
7, 8, 9, 10, 11, 12, 14, 15], keys: [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7,
12, 11]
/usr/local/cpython-3.6/bin/python (3.6.13) good compact
/usr/local/cpython-3.7/bin/python (3.7.0) good compact
/usr/local/cpython-3.8/bin/python (3.8.0) good compact
/usr/local/cpython-3.9/bin/python (3.9.0) good compact
/usr/local/cpython-3.10/bin/python (3.10.0) good compact

BTW, usually with pythons (the script which can be found at the URL above),
a little test program will be written to exit shell-true for success or
shell-false for failure.  But in this case I'm using the exit code not as
success+failure but as compact+notcompact.

Why are those keys so ordered?

Also, I realize that the keys could come up ordered somehow by accident,
but I tried with 30 values (not just 12), and still got the same
weirdness.  Naturally, as the number of key-value pairs goes up, the chance
of accidental ordering goes way down.

Thanks for reading!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: script folder is empty

2022-07-18 Thread Dan Stromberg
This is another reason to use:
python -m pip ...
...instead of:
   pip ...

(Or many systems want python3 -m pip)

HTH

On Sun, Jul 17, 2022 at 10:42 PM dn  wrote:

> On 18/07/2022 16.53, Scott Baer wrote:
> > I just installed Python 3.10.5 on a Windows 10 home ( Ver 21H2 OS build
> > 1904431826).
> > I'm logged in with admin privileges
> > I did a custom install with  python-3.10.5-amd64.exe to C:\Program
> > Files\Python310
> > Installed with both For all Users & PIP selected.
> > ;
> > once It was done installing, I rebooted and can run python:
> > Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929
> 64
> > bit (AMD64)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> 
> >
> > when I try to run:  pip --version
> > C:\Users\baerr>pip --version
> > 'pip' is not recognized as an internal or external command,
> > operable program or batch file.
> >
> > I've done some troubleshooting, and nothing is in the C:\Program
> > Files\Python310\Scripts folder.
> >
> > I"m not a noob.. but obviously, I missing something..   I doubt this is a
> > bug.
> >
> > Any help is much appreciated !!
>
> I don't use MS-Windows. Have you perused the docs?
> eg https://docs.python.org/3/using/windows.html?highlight=windows
>
> DuckDuckGo's first 'hit' for "How to Install PIP for Python on Windows"
> is https://www.liquidweb.com/kb/install-pip-windows/ - but please be
> aware that what comes-with varies according to the source used to obtain
> the copy of Python, and (perhaps) the version of MS-Win. YMMV!
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract the space group generators from Bilbao Crystallographic Server.

2022-07-14 Thread Dan Stromberg
It's good to include what you want to see as output, but it's important to
also include what you have as input.

It's also good to include what you've coded so far. It's considered good
etiquette to give it a try yourself before asking the list.

On Thu, Jul 14, 2022 at 1:03 PM hongy...@gmail.com 
wrote:

> I'm trying to extract the matrix data of "ITA-Setting F d -3 m [origin 1]"
> listed here [1], and then building an augmented matrix for each of them by
> adding the last row as "[0, 0, 0, 1]". In short, the following form is the
> ultimate-desired  result:
>
> [[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0,1, 0], [0, 0, 0, 1]],
>[[-1, 0, 0, 1], [0,-1, 0, 1/2], [0, 0, 1, 1/2], [0, 0, 0, 1]],
>[[-1, 0, 0, 1/2], [0, 1, 0, 1/2], [0, 0,-1, 1], [0, 0, 0, 1]],
>[[0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1]],
>[[0, 1, 0, 3/4], [1, 0, 0, 1/4], [0, 0, -1, 3/4], [0, 0, 0, 1]],
>[[-1, 0, 0, 1/4], [0, -1, 0, 1/4], [0, 0, -1, 1/4], [0, 0, 0, 1]],
>[[1, 0, 0,  0], [0, 1, 0, 1/2], [0, 0, 1, 1/2], [0, 0, 0, 1 ]],
>[[1, 0, 0, 1/2], [0, 1, 0, 0], [0, 0, 1, 1/2], [0, 0, 0, 1]]]
>
> Any hints/tips/tricks for achieving this aim will be appreciated.
>
> [1]
> https://www.cryst.ehu.es/cgi-bin/cryst/programs//nph-trgen?gnum=227&what=gen&trmat=a-1/8,b-1/8,c-1/8&unconv=F%20d%20-3%20m%20:1&from=ita
>
> Regards,
> Zhao
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime

2022-06-21 Thread Dan Stromberg
On Mon, Jun 20, 2022 at 9:45 PM Paul Bryan  wrote:

> Here's how my code does it:
>
>
> import calendar
>
> def add_months(value: date, n: int):
>   """Return a date value with n months added (or subtracted if
> negative)."""
>   year = value.year + (value.month - 1 + n) // 12
>   month = (value.month - 1 + n) % 12 + 1
>   day = min(value.day, calendar.monthrange(year, month)[1])
>   return date(year, month, day)
>

This looks interesting.

You also could add or subtract the average number of seconds in a month:
2629743.75

This has the strange property that the time of day, or even calendar day,
could change. However, it is round-trippable.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2022-06-11 Thread Dan Stromberg
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?

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


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

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

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

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


Re: How to replace characters in a string?

2022-06-08 Thread Dan Stromberg
On Wed, Jun 8, 2022 at 1:11 AM Dave  wrote:

> I've got two that appear to be identical, but fail to compare. After
> getting the ascii encoding I see that they are indeed different, my
> question is how can I replace the \u2019m with a regular single quote mark
> (or apostrophe)?
>

Perhaps try https://pypi.org/project/Unidecode/ ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: min, max with position

2022-06-04 Thread Dan Stromberg
On Sat, Jun 4, 2022 at 9:07 PM Greg Ewing 
wrote:

> On 5/06/22 10:07 am, dn wrote:
> > On 05/06/2022 09.50, Chris Angelico wrote:
> > min(enumerate(l), key=lambda x: x[1])
> >> (0, 1.618033)
> >
> > But, but, but which of the above characters is an 'el' and which a
> 'one'???
> > (please have pity on us old f...s and the visually-challenged!)
> >
>
> ell = l
> one = 1
> min(enumerate(ell), key=lambda x: x[one])
>
> Hope that clears it up!11!one!ell
>

I'm kind of partial to:
min((value, index) for (index, value) in enumerate(list_))

It'll return a single 2-tuple where the value of interest is at position
0.  In the event of a tie, it should give you the first such value
encountered.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about building Python-3.9.12 on OpenBSD 7.1

2022-06-02 Thread Dan Stromberg
It's been my understanding that there is a fundamental difference between
the *BSD's and the Linuxes.

The *BSD's have their ports system, that collects deltas against
third-party packages to build them on a *BSD.  These deltas become part of
the ports system.

The Linuxes port an application, and contribute the deltas to the package's
upstream maintainer.

For this reason, I suspect you may do well to contact the person in charge
of the port of CPython to OpenBSD.

HTH


On Thu, Jun 2, 2022 at 5:46 PM Tim Brazil  wrote:

> Hello
>
> I hope I am not breaking protocol sending this message to the list.
> This is my first posting to python-list.
>
> I am trying to build Python-3.9.12 from the ports distribution on
> on a new OpenBSD 7.1 installation.
> It is failing with the following error.
>
> Traceback (most recent call last):
>File "/usr/obj/ports/Python-3.9.12/Python-3.9.12/./setup.py", line
> 2509, in 
>  class PyBuildInstallLib(install_lib):
>File "/usr/obj/ports/Python-3.9.12/Python-3.9.12/./setup.py", line
> 2516, in PyBuildInstallLib
>  shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
>File "/usr/obj/ports/Python-3.9.12/Python-3.9.12/Lib/sysconfig.py",
> line 616, in get_config_var
>  return get_config_vars().get(name)
>File "/usr/obj/ports/Python-3.9.12/Python-3.9.12/Lib/sysconfig.py",
> line 565, in get_config_vars
>  _init_posix(_CONFIG_VARS)
>File "/usr/obj/ports/Python-3.9.12/Python-3.9.12/Lib/sysconfig.py",
> line 430, in _init_posix
>  _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
> ModuleNotFoundError: No module named
> '_sysconfigdata__openbsd7_amd64-unknown-openbsd7'
> *** Error 1 in /usr/obj/ports/Python-3.9.12/Python-3.9.12 (Makefile:649
> 'sharedmods': @case "`echo X $MAKEFLAGS | sed 's/^X //;s/ -- .*//'`"...)
>
> In researching this on the internet I discovered a similar reporting on
> FreeBSD that seems to relate to regex and MULTIARZCH in the FreeBSD
> Makefile but it doesn't seem to apply to the port of my
> Makefile/environment.
>
> This is the report I am referring to:
>
>  https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=259896
>
> My exact problem is...
>
> I do not have z _sysconfigdata__openbsd7_amd64-unknown-openbsd7 module
> but I do have a _sysconfigdata__openbsd7_amd64-unknown-openbsd7.1.py
> module
> under:
>
> ./build/lib.openbsd-7.1-amd64-3.9/_
> sysconfigdata__openbsd7_amd64-unknown-openbsd7.1.py
>
> I suspect somewhere, it's not picking up the full 7.1 version string.
> I am having a problem figuring it out. I kindly ask if you have any
> pointers on fixing
> it. Should I log a bug or is it a OpenBSD package thing?
>
> Thanks in Advance
> Tim
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Non-deterministic set ordering

2022-05-15 Thread Dan Stromberg
On Sun, May 15, 2022 at 8:01 PM Rob Cliffe via Python-list <
python-list@python.org> wrote:

> I was shocked to discover that when repeatedly running the following
> program (condensed from a "real" program) under Python 3.8.3
>
> for p in { ('x','y'), ('y','x') }:
>  print(p)
>
> the output was sometimes
>
> ('y', 'x')
> ('x', 'y')
>
> and sometimes
>
> ('x', 'y')
> ('y', 'x')
>
> Can anyone explain why running identical code should result in
> traversing a set in a different order?
>

Sets are defined as unordered so that they can be hashed internally to give
O(1) operations for many tasks.

It wouldn't be unreasonable for sets to use a fixed-by-arbitrary ordering
for a given group of set operations, but being unpredictable deters
developers from mistakenly assuming they are ordered.

If you need order, you should use a tuple, list, or something like
https://grantjenks.com/docs/sortedcontainers/sortedset.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Mypy alternatives

2022-05-14 Thread Dan Stromberg
Hello people.

I've used Mypy and liked it in combination with MonkeyType.

I've heard there are alternatives to Mypy that are faster, and I'm looking
at using something like this on a 457,000 line project.

Are there equivalents to MonkeyType that will work with these alternatives
to Mypy?

And has Mypy become the defacto standard for how type annotations should
look?  That is, are there other tools that assume Mypy's format too, and
does most doc about type annotations assume Mypy's style?

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


"py" command for Linux and Mac?

2022-05-12 Thread Dan Stromberg
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?

And if so, where can I find that "py" command for Linux and Mac?

I tried searching for it in Google and on Pypi, but unsurprisingly
searching for "py" gives a buzzillion hits on other things.

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


Re: [Python-ideas] Re: New Tool Proposal

2022-05-10 Thread Dan Stromberg
On Tue, May 10, 2022 at 3:15 AM Chris Angelico  wrote:

> > It is often the case that developer write Code in Python and then
> convert to a C extension module for performance regions.
> >
> > A C extension module has a lot of boiler plate code - for instance the
> Structures required for each class, the functions for Module initialization
> etc.
> >
> > My Idea is a simple tool that uses introspection tools to take a Python
> module and to generate the relevant boiler plate for the module - including
> blank functions for the module classes and for methods. This tool would use
> type annotations (if given) to make sensible choices for parameter and
> attribute types, including using int and float directly rather than
> Internal objects (depending on tool options).
>

Two things to say about this:
1) Sometimes abandoning a pure python module for a C extension for
performance is a mistake - because Pypy is probably going to be much faster
with the pure python module
2) I've had some luck using m4 to maintain a single source file that is
used to automatically generate both pure python and cython.  This is a
little like using cpp in a C project.

For examples of #2, perhaps see:
https://stromberg.dnsalias.org/~strombrg/treap/
https://stromberg.dnsalias.org/svn/rolling_checksum_mod/trunk/
https://stromberg.dnsalias.org/~strombrg/sort-comparison/

It's often nice to keep the lines of the pure-python and cython having a
1-1 relationship, so that tracebacks report useful line numbers either
way.  However, in the treap example I've dispensed with that because some
methods were almost identical but had some boilerplate - and m4 was able to
handle that nicely at the cost of lines being 1-1.

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


  1   2   3   4   5   6   7   8   9   10   >