Re: "CPython"

2022-06-21 Thread Greg Ewing

On 22/06/22 4:42 am, MRAB wrote:

On 2022-06-21 03:52, Avi Gross via Python-list wrote:


This leads to the extremely important question of what would an 
implementation of Python, written completely in C++, be called?

C++Python
CPython++
C+Python+
DPython
SeaPython?
SeeSeaSiPython


CincPython?


Python+=1

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


Re: Subtract n months from datetime

2022-06-21 Thread Cameron Simpson
On 21Jun2022 17:02, Paulo da Silva  wrote:
>I have a datetime, not a date.

Then you need a date. I would break the datetime into a date and a time, 
then do the months stuff to the date, then compose a new datetime from 
the result.

>Anyway, the use of calendar.monthrange simplifies the task a lot.

Hmm, yes it would.

The important thing to remember about any solutions mentioned is that 
dates and datetimes have different semantics. Specificly, you can't add 
fixed elapsed times such as seconds to do "calendar like" arithmetic, 
which works in days etc because months have varying numbers of days, and 
days have varying numbers of seconds (not merely the odd leap second but 
also the horrors of timezones and summer/winter time shifts).

So working with the calendar component (days upwards) is a meaningful 
thing. But working in, say, seconds with the _bjective_ of doing days or 
months is nearly pointless.

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


Re: "CPython"

2022-06-21 Thread jkn
On Tuesday, June 21, 2022 at 2:09:27 PM UTC+1, Grant Edwards wrote:
> On 2022-06-21, Chris Angelico  wrote: 
> 
> > Not sure why it's strange. The point is to distinguish "CPython" from 
> > "Jython" or "Brython" or "PyPy" or any of the other implementations. 
> > Yes, CPython has a special place because it's the reference 
> > implementation and the most popular, but the one thing that makes it 
> > distinct from all the others is that it's implemented in C.
> I've been using CPython (and reading this list) for over 20 years, and 
> there's no doubt in my mind that the C in CPython has always been 
> interpreted by 99+ percent of the Python community as meaning the 
> implementation language. 
> 
> Sort of like ckermit  was the original 
> implementation of Kermit written in C. At the time, the other popular 
> implementations (for DOS, IBM, etc.) were written in assembly. 
> 

Same here, on both counts (20+ years on this Usenet group,
 and CPython == "the canonical C implementation of Python")

Actually, on all three counts - I remember ckermit as well ;-)

Fourthly...

J^n
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python installation

2022-06-21 Thread Dennis Lee Bieber
On Tue, 21 Jun 2022 14:22:29 +0300, Brian Karinga 
declaimed the following:

>I have been trying to download and install the latest version of python on
>my windows device. However, when I run the program, three options arise.
>These are:
>
>Modify
>Repair
>Uninstall
>

You are (re-)running the INSTALLER. Once you've run it, hide it away
someplace and only look at it if you need to -- well -- repair or modify
the installation.

Python is not an IDE (it is not something like Visual Studio where one
opens a massive suite of editing/debugging tools which will eventually
invoke Visual C/C++/C#/BASIC compilers). It is a command line interpreter
which might (depending on install setting) configure the system to use it
to run files with .py (or .pyw for GUI applications where a console window
is not desired... note that running a .py by clicking on it will open a
console window, and that window will close when the program exits -- so
that option is often useless).


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "CPython"

2022-06-21 Thread 2QdxY4RzWzUUiLuE
On 2022-06-21 at 17:04:45 +,
Avi Gross via Python-list  wrote:

> My problem with that idea is, believe it or not, that it is too negative. 
> What you meant to be seen as a dash is a minus sign to me. And both C and C++ 
> not only have both a pre and post autoincrement variable using ++x and x++, 
> they also have autodecrement operators using a minus sign such as --x and x-- 
> and it can get pretty weird trying to figure out if some code is legal, let 
> alone what it does, without parentheses. I mean what the heck does this do?
> 
> y = x++-++x

That code evokes (or at least can evoke) nasal demons.

https://en.wikipedia.org/wiki/Undefined_behavior
-- 
https://mail.python.org/mailman/listinfo/python-list


[Python-announce] Wing Python IDE version 8.3.2

2022-06-21 Thread Wingware
Wing 8.3.2 fixes several code intelligence issues for f-string 
expressions, avoids problems when using ~ or a non-default Base 
Directory with remote hosts, allows running a pytest parameterized test 
with a float value, adds the option Use Fixed Width Font for Output to 
the Testing tool's right-click context menu, scrolls correctly to the 
current line in version control blame/praise output, fixes intermittent 
PyQt & PySide autocompletion problems, and makes a number of other 
usability improvements.


Details: https://wingware.com/news/2022-06-17
Downloads: https://wingware.com/downloads

== About Wing ==

Wing is a full-featured but light-weight Python IDE designed 
specifically for Python, with powerful editing, code inspection, 
testing, and debugging capabilities. Wing's deep code analysis provides 
auto-completion, auto-editing, code navigation, early error detection, 
and refactoring that speed up development. Its top notch debugger works 
with any Python code, locally or on a remote host, container, or 
cluster. Wing also supports test-driven development, version control, 
Python package management, UI color and layout customization, and 
includes extensive documentation and support.


Wing is available in three product levels:  Wing Pro is the 
full-featured Python IDE for professional developers, Wing Personal is a 
free Python IDE for students and hobbyists (omits some features), and 
Wing 101 is a very simplified free Python IDE for beginners (omits many 
features).


Learn more at https://wingware.com/

___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


Re: Python installation

2022-06-21 Thread Sam Ezeh
Inside my Windows virtual machine only entering `py` as the command
brings up the repl, if that helps.

Kind Regards,
Sam Ezeh

On Tue, 21 Jun 2022 at 18:15, Igor Korot  wrote:
>
> Hi,
>
> On Tue, Jun 21, 2022 at 11:43 AM Brian Karinga  wrote:
> >
> > Hello,
> >
> > I hope this email finds you well.
> >
> > I have been trying to download and install the latest version of python on
> > my windows device. However, when I run the program, three options arise.
> > These are:
> >
> > Modify
> > Repair
> > Uninstall
> >
> > I have executed the modify and repair options several times but nothing has
> > changed. Please advise on what the problem could be and how it can be
> > resolved.
>
> Is it possible that Python is already installed?
>
> Open "Command Prompt" window, type python and press "Enter".
>
> What do you see on the screen?
>
> Thank you.
>
> >
> > I look forward to hearing from you.
> >
> > Thank you,
> > Brian.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python installation

2022-06-21 Thread Igor Korot
Hi,

On Tue, Jun 21, 2022 at 11:43 AM Brian Karinga  wrote:
>
> Hello,
>
> I hope this email finds you well.
>
> I have been trying to download and install the latest version of python on
> my windows device. However, when I run the program, three options arise.
> These are:
>
> Modify
> Repair
> Uninstall
>
> I have executed the modify and repair options several times but nothing has
> changed. Please advise on what the problem could be and how it can be
> resolved.

Is it possible that Python is already installed?

Open "Command Prompt" window, type python and press "Enter".

What do you see on the screen?

Thank you.

>
> I look forward to hearing from you.
>
> Thank you,
> Brian.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "CPython"

2022-06-21 Thread Avi Gross via Python-list
If we want to be humorous, RPython would obviously either be written in R, 
which really is not designed well for such purposes, or would be some kind of 
synthesis that already exists that allows you to run R and python code 
interchangeably on sort of shared data that I sometimes do in RSTUDIO.

I like the way you think Greg. I did not consider how the ++ in C++ is a bit 
like stuttering and since python also starts with a P the effect would be 
something like C-p-p-python.

My problem with that idea is, believe it or not, that it is too negative. What 
you meant to be seen as a dash is a minus sign to me. And both C and C++ not 
only have both a pre and post autoincrement variable using ++x and x++, they 
also have autodecrement operators using a minus sign such as --x and x-- and it 
can get pretty weird trying to figure out if some code is legal, let alone what 
it does, without parentheses. I mean what the heck does this do?

y = x++-++x

The truth is that although I remember Bjarne trying to figure out a good name 
for his somewhat improved language and his choice of C++ rather than D or some 
other gimmick, you could argue he also removed a bit from C. But who would call 
a language C-- ??
Back to serious. This discussion is more about names but is it?
Some of the implementations of Python are not just written in some computer 
language but also in a sort of environment. Arguably some core of functionality 
has to be pretty much consistent to the language definition. But each may add 
interesting twists on its own and that can include the ability to easily link 
in code and libraries written in that language or used in that environment. You 
can have different supersets of a language.
And it can impact where you might use the language as one reason people may not 
understand for using C is that a compiler was available for just about anywhere 
that either ran in that environment or could be run on another to produce 
lower-level code to copy to it. It was also possible to embed code in C that 
was evaluated differently in each environment for some level of fine-tuning.
Some of that may eventually have been true for other implementations but I 
suspect not for some deliberately designed to fit what one party wants and with 
no care that it be shared elsewhere especially as the C version was already 
available there.
Or am I wrong? After all, others who kept improving C thought the ++ concept 
was best removed!


-Original Message-
From: Greg Ewing 
To: python-list@python.org
Sent: Tue, Jun 21, 2022 3:53 am
Subject: Re: "CPython"

On 21/06/22 2:56 pm, Paulo da Silva wrote:
> Let's say they reimplement "reference python" CPython in Rust. What is 
> better? Change the "reference python" CPython name to RPython, for 
> example, or let it as CPython?

The C implementation would still be called CPython, and the new
implementation might be called RPython, or RustyPython, or whatever.
The names are independent of which one is currently blessed as the
reference implementation.

Although if it were called RPython, no doubt a new debate would
flare up over whether the "R" stands for "Rust" or "Reference"...

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


Re: "CPython"

2022-06-21 Thread MRAB

On 2022-06-21 03:38, Paulo da Silva wrote:

Às 02:33 de 21/06/22, Chris Angelico escreveu:

On Tue, 21 Jun 2022 at 11:13, Paulo da Silva
 wrote:


Às 20:01 de 20/06/22, Paulo da Silva escreveu:

Às 18:19 de 20/06/22, Stefan Ram escreveu:

The same personality traits that make people react
to troll postings might make them spread unconfirmed
ideas about the meaning of "C" in "CPython".

The /core/ of CPython is written in C.

CPython is the /canonical/ implementation of Python.

The "C" in "CPython" stands for C.




Not so "unconfirmed"!
Look at this article, I recently read:
https://www.analyticsinsight.net/cpython-to-step-over-javascript-in-developing-web-applications/


There is a sentence in ther that begins with "CPython, short for Core
Python, a reference implementation that other Python distributions are
derived from, ...".

Anyway, I wrote "IMHO".

Do you have any credible reference to your assertion "The "C" in
"CPython" stands for C."?

Thank you.


Well ... I read the responses and they are not touching the point!
I just answered, with my opinion based on articles I have read in the
past. Certainly I could not be sure. That's why I responded as an
opinion (IMHO) and not as an assertion.
Stefan Ram responded with a, at least, not very polite post.
That's why I needed to somehow "defend" why I posted that response, and,
BTW, trying to learn why he said that the C in CPython means "written in C".

I still find very strange, to not say weird, that a compiler or
interpreter has a name based in the language it was written. But, again,
is just my opinion and nothing more.



Not sure why it's strange. The point is to distinguish "CPython" from
"Jython" or "Brython" or "PyPy" or any of the other implementations.

Notice that they are, for example, Jython and not JPython.
There is also Cython that is a different thing.

And YES. You have the right to not feel that as strange.


Jython was originally called JPython.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime

2022-06-21 Thread Paulo da Silva

Às 05:44 de 21/06/22, Paul Bryan escreveu:

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)

Paul

I have a datetime, not a date.
Anyway, the use of calendar.monthrange simplifies the task a lot.

Assuming dtnow has the current datetime and dtn the number of months to 
be subtracted, here is my solution (the code was not cleaned yet - just 
a test):

dtnow_t=list(dtnow.timetuple()[:6]+(dtnow.microsecond,))
y=dtnow_t[0] # y,m,d,*_=dtnow_t seems slower
m=dtnow_t[1]
d=dtnow_t[2]
dy,dm=divmod(dtn,12)
y-=dy
m-=dm
if m<1:
m+=12
y-=1
daysinmonth=calendar.monthrange(y,m)[1]
d=min(d,daysinmonth)
dtnow_t[0]=y
dtnow_t[1]=m
dtnow_t[2]=d
bt=datetime.datetime(*dtnow_t)

Any comments are welcome.

Thank you.
Paulo




On Tue, 2022-06-21 at 05:29 +0100, Paulo da Silva wrote:

Hi!

I implemented a part of a script to subtract n months from datetime.
Basically I subtracted n%12 from year and n//12 from the month adding
12
months when it goes<=0. Then used try when converting to datetime
again.
So, if the day is for example 31 for a 30 days month it raises a
ValuError exception. Then I subtract 1 to day and repeat.

The code seems too naive and very very complicated!
What is the best way to achieve this? Any existent module?

At the very end, what I want is to subtract nx where x can be y, m,
w, d
for respectively years, months, weeks or days.

I feel I am missing something here ...

Thanks.
Paulo





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


Re: "CPython"

2022-06-21 Thread Dennis Lee Bieber
On Tue, 21 Jun 2022 19:53:51 +1200, Greg Ewing
 declaimed the following:

>Although if it were called RPython, no doubt a new debate would
>flare up over whether the "R" stands for "Rust" or "Reference"...

Or does RPython refer to a Python integrated into the R statistics
system? 

Actually -- RPython is already taken...
https://rpython.readthedocs.io/en/latest/

"""
RPython is a translation and support framework for producing
implementations of dynamic languages, emphasizing a clean separation
between language specification and implementation aspects.

By separating concerns in this way, our implementation of Python - and
other dynamic languages - is able to automatically generate a Just-in-Time
compiler for any dynamic language. It also allows a mix-and-match approach
to implementation decisions, including many that have historically been
outside of a user’s control, such as target platform, memory and threading
models, garbage collection strategies, and optimizations applied, including
whether or not to have a JIT in the first place.
"""


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "CPython"

2022-06-21 Thread Dennis Lee Bieber
On Tue, 21 Jun 2022 01:53:38 +0100, Paulo da Silva
 declaimed the following:


>I still find very strange, to not say weird, that a compiler or 
>interpreter has a name based in the language it was written. But, again, 
>is just my opinion and nothing more.
>

The whole purpose for that was to differentiate from Python /language/
implemented in OTHER languages. IronPython is a M$ .NET/C# implementation,
Jython is a JVM/Java implementation.

When you just say "Python" you are referring to ALL of those
implementations.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "CPython"

2022-06-21 Thread MRAB

On 2022-06-21 03:52, Avi Gross via Python-list wrote:


This leads to the extremely important question of what would an implementation 
of Python, written completely in C++, be called?
C++Python
CPython++
C+Python+
DPython
SeaPython?
SeeSeaSiPython


CincPython?

FYI, there's a language called D, so DPython would be written in that.


I don't even want to think fo what sound a C# Python would make.
OK, my apologies to all. Being an interpreted language, it makes sense for a 
good part of the interpreter to include parts made in other languages and also 
add-on libraries in even older languages like FORTRAN.  Quite a few languages, 
including some like R, are also partially based on C in similar ways.

[snip]
--
https://mail.python.org/mailman/listinfo/python-list


Python installation

2022-06-21 Thread Brian Karinga
Hello,

I hope this email finds you well.

I have been trying to download and install the latest version of python on
my windows device. However, when I run the program, three options arise.
These are:

Modify
Repair
Uninstall

I have executed the modify and repair options several times but nothing has
changed. Please advise on what the problem could be and how it can be
resolved.

I look forward to hearing from you.

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


Re: traceback Shows path to my python libraries

2022-06-21 Thread Dieter Maurer
jsch...@sbcglobal.net wrote at 2022-6-20 13:49 -0500:
>I coded an application with a 64-bit executable using cython with the embed
>option and gcc and I received a traceback showing the path to my python
>installation.  Is that normal or does that mean the application is going
>outside of my executable to my python libraries?  I want it portable so it
>if is, then it's not portable.

The tracebacks are primarily for the developers.
Therefore, they identify source locations.
When you use `cython`, the compilation to "C" gets references
to the `cython` source (because those references are meaningful
for the developers). When a traceback is generated, the
`cython` source need not be available (you will then not
see the source line, only the line number and file information).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "CPython"

2022-06-21 Thread Greg Ewing

On 21/06/22 8:37 pm, Christian Gollwitzer wrote:

Am 20.06.22 um 22:47 schrieb Roel Schroeven:
"CPython is a descendant of Pyscript built on Pyodide, a port of 
CPython, or a Python distribution for the browser and Node.js that is 
based on Webassembly and Emscripten."


To me, this sentence is so badly cobbled together that it could be the 
output of a KI of some sort (GPT-3) trying to summarize stuff from the 
web.


It looks to me like the output of a Markov chain that's been fed
with all the latest programming buzzwords.

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


Re: "CPython"

2022-06-21 Thread Christian Gollwitzer

Am 20.06.22 um 22:47 schrieb Roel Schroeven:
indication that www.analyticsinsight.net is wrong on that point. Frankly 
that website seems very low quality in general. In that same article 
they say:


"CPython is a descendant of Pyscript built on Pyodide, a port of 
CPython, or a Python distribution for the browser and Node.js that is 
based on Webassembly and Emscripten."


CPython is definitely not a descendant of Pyscript! Looks like someone 
found something (semi-) interesting and tried to write something 
insightful about it, but without really understanding any of it. Other 
articles don't seem to be any better.


To me, this sentence is so badly cobbled together that it could be the 
output of a KI of some sort (GPT-3) trying to summarize stuff from the 
web. It doesn't make any sense at all on a semantic level.


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


Re: "CPython"

2022-06-21 Thread Dennis Lee Bieber
tOn Tue, 21 Jun 2022 02:52:28 + (UTC), Avi Gross 
declaimed the following:

>
>I don't even want to think fo what sound a C# Python would make.

A musical hiss on a frequency of 277.183Hz (for the C# above middle-C)


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "CPython"

2022-06-21 Thread Greg Ewing

On 21/06/22 9:27 pm, Paul Rubin wrote:

What?  I never heard of such a dispute.  The PSF got after someone about
it?  Sheesh.


Upon further research, it seems it wasn't the *Python* trademark that
was at issue. From the Jython FAQ page:


1.2   How does Jython relate to JPython?

Jython is the successor to JPython. The Jython project was created in 
accordance with the CNRI JPython 1.1.x license, in order to ensure the 
continued existence and development of this important piece of Python 
software. The intent is to manage this project with the same open 
policies that are serving CPython so well.


The name had to be changed to something other than JPython, because of 
paragraph 4 in the JPython-1.1 license:


4. Licensee may not use CNRI trademarks or trade name, including
   JPython [...] to endorse or promote products [...]


So there was no dispute, they were just following the terms of a
licence.

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


Re: "CPython"

2022-06-21 Thread jak

Il 21/06/2022 04:56, Paulo da Silva ha scritto:

Às 03:20 de 21/06/22, MRAB escreveu:

On 2022-06-21 02:33, Chris Angelico wrote:

On Tue, 21 Jun 2022 at 11:13, Paulo da Silva
 wrote:


Às 20:01 de 20/06/22, Paulo da Silva escreveu:
> Às 18:19 de 20/06/22, Stefan Ram escreveu:


[snip]


After all who cares in which language it is implemented?

Regards.
Paulo



Why are you asking this? The Facebook platform which is mainly developed
in Rust are converting it to C to make it faster and lighter. If as
often happens, many people complain about the speed of python, what
would be the purpose of translating python using a slower language?

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


Re: "CPython"

2022-06-21 Thread Greg Ewing

On 21/06/22 2:56 pm, Paulo da Silva wrote:
Let's say they reimplement "reference python" CPython in Rust. What is 
better? Change the "reference python" CPython name to RPython, for 
example, or let it as CPython?


The C implementation would still be called CPython, and the new
implementation might be called RPython, or RustyPython, or whatever.
The names are independent of which one is currently blessed as the
reference implementation.

Although if it were called RPython, no doubt a new debate would
flare up over whether the "R" stands for "Rust" or "Reference"...

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


Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-21 Thread Chethan Kumar S
Hi all,

Need help with below query on python logging module.

I have a main process which makes use of different other modules. And these 
modules also use other modules. I need to log all the logs into single log 
file. Due to use of TimedRotatingFileHandler, my log behaves differently after 
midnight. I got to know why it is so but couldn't get how I can solve it.
Issue was because of serialization in logging when multiple processes are 
involved.

Below is log_config.py which is used by all other modules to get the logger and 
log.
import logging
import sys
from logging.handlers import TimedRotatingFileHandler

FORMATTER = logging.Formatter("%(asctime)s — %(name)s — %(message)s")
LOG_FILE = "my_app.log"

def get_file_handler():
   file_handler = TimedRotatingFileHandler(LOG_FILE, when='midnight')
   file_handler.setFormatter(FORMATTER)
   return file_handler

def get_logger(logger_name):
   logger = logging.getLogger(logger_name)
   logger.setLevel(logging.DEBUG) # better to have too much log than not enough
   logger.addHandler(get_file_handler())
   #with this pattern, it's rarely necessary to propagate the error up to parent
   logger.propagate = False
   return logger

All other modules call, 'logging = log_config.get_logger(name)' and use it to 
log.
I came to know about QueueHandler and QueueListener but not sure how to use 
them in my code. How can I use these to serialize logs to single file.?

Any help is appreciated.
Thanks,
Chethan


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


Re: "CPython"

2022-06-21 Thread Greg Ewing

On 21/06/22 2:52 pm, Avi Gross wrote:


This leads to the extremely important question of what would an implementation 
of Python, written completely in C++, be called?


(Pronounced with a comical stutter) "C-p-p-python!")

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


Re: "CPython"

2022-06-21 Thread Greg Ewing

On 21/06/22 2:38 pm, Paulo da Silva wrote:

Notice that they are, for example, Jython and not JPython.


Jython *was* originally called JPython, but that was judged to be
a trademark violation and they were made to change it.

I don't know how MicroPython has escaped the same fate to date.

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


Re: "CPython"

2022-06-21 Thread Eryk Sun
On 6/20/22, Paulo da Silva  wrote:
>
> Yes, but that does not necessarily means that the C has to refer to the
> language of implementation. It may well be a "core" reference to
> distinguish that implementation from others with different behaviors.

If the reference implementation and API ever switched to a different
programming language, I'd personally be fine with changing the 'C" in
"CPython" to mean "canonical", but not "core". The term "core" is used
for building the interpreter core with access to internals (i.e.
Py_BUILD_CORE, Py_BUILD_CORE_BUILTIN, Py_BUILD_CORE_MODULE, and
Include/internal/pycore*.h). It does not refer to the overall
implementation and API for embedding and extension modules.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "CPython"

2022-06-21 Thread Grant Edwards
On 2022-06-21, Chris Angelico  wrote:

> Not sure why it's strange. The point is to distinguish "CPython" from
> "Jython" or "Brython" or "PyPy" or any of the other implementations.
> Yes, CPython has a special place because it's the reference
> implementation and the most popular, but the one thing that makes it
> distinct from all the others is that it's implemented in C.

I've been using CPython (and reading this list) for over 20 years, and
there's no doubt in my mind that the C in CPython has always been
interpreted by 99+ percent of the Python community as meaning the
implementation language.

Sort of like ckermit  was the original
implementation of Kermit written in C. At the time, the other popular
implementations (for DOS, IBM, etc.) were written in assembly.

--
Grant


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


Re: Subtract n months from datetime

2022-06-21 Thread Richard Damon

On 6/21/22 12:29 AM, Paulo da Silva wrote:

Hi!

I implemented a part of a script to subtract n months from datetime.
Basically I subtracted n%12 from year and n//12 from the month adding 
12 months when it goes<=0. Then used try when converting to datetime 
again. So, if the day is for example 31 for a 30 days month it raises 
a ValuError exception. Then I subtract 1 to day and repeat.


The code seems too naive and very very complicated!
What is the best way to achieve this? Any existent module?

At the very end, what I want is to subtract nx where x can be y, m, w, 
d for respectively years, months, weeks or days.


I feel I am missing something here ...

Thanks.
Paulo

The biggest issue with "subtracting months" is getting the right 
definition of what you mean by that, especially in the corner cases, 
once that is established, programming it is fairly easy.


The problem is that a month isn't a fixed unit of time, but is a period 
anywhere from 28 to 31 days. (you get the same problem for years, but 
the difference is more special case, the presence or absent of Feb 29th.)


The normal definition of this operation has the strange property that if 
you subtract a month, then add a month, you sometimes don't get back to 
the same day as you started with. Also subtracting one month, and then 
subtracting another month might get you a different day than subtracting 
2 months at once (Think of Mar 31st).


In short, this sort of date operation IS hard, and application specific, 
so while there may be pre-built modules that have this operation, you 
need to see if it uses a compatible definition of what you want.


One alternative, which breaks other expectations, is to think of a month 
as 30 or 30.5 (so 2 months are 61 days) days, and add that. It says that 
often a month later than a given day isn't the same day of the month, 
but does make some operations less surprising. (This is hard to do to a 
date expressed as year-month-day, but trivial in some other formats like 
a timestamp.)


--
Richard Damon

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


Re: Tkinter - cannot import tklib

2022-06-21 Thread David
On Tue, 21 Jun 2022 at 09:22, Wolfgang Grafen  wrote:

> I am an experienced Python user and struggle with following statement:
>
> >>> from tklib import *
> Traceback (most recent call last):
> File "", line 1, in 
> ModuleNotFoundError: No module named 'tklib'

[...]

> I did not find a python module called tklib to install.

Ok, see below for how to find that file.

[...]

> I assume it should be installed by default with every python installation

It appears that your assumption is wrong. It appears to me that the
missing file is part of the tk-tutorial project.

> https://tk-tutorial.readthedocs.io/en/latest/intro/intro.html?highlight=app#

> First time that I cannot help myself. Please help, what do I do wrong?

Hi, here is a description how I found the file you seek:

Go to https://tk-tutorial.readthedocs.io/en/latest/intro/intro.html

At the top right of the page, see hyperlink "Edit on GitHub".
Click hyperlink takes you to
  https://github.com/rasql/tk-tutorial/blob/master/docs/intro/intro.rst
which is the same content rendered from 'rst' format I assume.

At top left of that page, see hyperlinks "tk-tutorial"/"docs"/"intro"
and "rasql"/"tk-tutorial".

Click one of the "tk-tutorial" hyperlinks to go to the top directory
of the project at:
  https://github.com/rasql/tk-tutorial

On that page near the very top, see a list of hyperlinks to
directories and files of the project. One of those hyperlinks
is labelled "tklib.py". Click that link to see the file at
  https://github.com/rasql/tk-tutorial/blob/master/tklib.py

On that page, click the "Raw" button. Then you can use "save as"
in your browser. Or you can just download it by some other
method from the link given in the previous paragraph.
-- 
https://mail.python.org/mailman/listinfo/python-list