Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > Jon Ribbens writes: >> On 2022-04-19, Loris Bennett wrote: >>> I now realise that timedelta is not really what I need. I am interested >>> solely in pure periods, i.e. numbers of seconds, >> >> That's exactly what timedelta is. >> >>> that I can convert bac

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > If I am merely trying to represent part a very large number of seconds > as a number of years, 365 days per year does not seem that controversial > to me. Obviously there are issues if you expect all periods of an > integer number of years which start on a gi

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Barry wrote: >> On 19 Apr 2022, at 19:38, Dennis Lee Bieber wrote: >> *I /think/ this is the year used for leap-day calculations, and >> why some leap centuries are skipped as it is really less than a >> quarter day per year, so eventually one gets to over-correcting

Re: Why no list as dict key?

2022-04-20 Thread Avi Gross via Python-list
This does raise an issue, Chris, if you use the method of making a tuple  companion for a list at a specific time just for use as a dictionary key, then later change the list, you can end up with various situations. Obviously the changed list can not only not access the stored item, but if conver

How to have python 2 and 3 both on windows?

2022-04-22 Thread Sunil KR via Python-list
I have some scripts that are old and won't work under python2 and at the same time I am writing new scripts which will use python3. However, if python 2 and 3 cannot co-exist in a windows box it will be impossible to transition What I try:- remove all pythons and launchers- Use windows installer

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

2022-04-22 Thread Sunil KR via Python-list
nil On Friday, April 22, 2022, 09:09:22 AM PDT, Sunil KR via Python-list wrote: I have some scripts that are old and won't work under python2 and at the same time I am writing new scripts which will use python3. However, if python 2 and 3 cannot co-exist in a windows box it will

Re: Style for docstring

2022-04-22 Thread Rob Cliffe via Python-list
I don't use docstrings much; instead I put a line or two of comments after the `def ` line. But my practice in such situations is as per the OP's 3rd suggestion, e.g.     # Returns True if . I'm curious as to why so many people prefer "Return" to "Returns". Checking out help() on a few funct

Re: Style for docstring

2022-04-22 Thread Avi Gross via Python-list
Python does have a concept of "truthy" that includes meaning for not just the standard Booleans but for 0 and non-zero and the empty string and many more odd things such as an object that defines __bool__ (). But saying it returns a Boolean True/False valuesounds direct and simple and informativ

Re: Style for docstring

2022-04-22 Thread Avi Gross via Python-list
-Original Message- From: MRAB To: [email protected] Sent: Fri, Apr 22, 2022 8:57 pm Subject: Re: Style for docstring On 2022-04-23 00:25, Rob Cliffe via Python-list wrote: > I don't use docstrings much; instead I put a line or two of comments > after the `def ` line. > But

Re: Style for docstring

2022-04-23 Thread Avi Gross via Python-list
Given what you added, Michael, your function is part of a larger collection of functions and being compatible with the others is a valid consideration. Whatever you decide, would ideally be done consistently with all or most of them. And, of course, it others in the collection also can handle mu

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

2022-04-23 Thread Sunil KR via Python-list
, if I can make python 2 and 3 coexist on my system > On 22 Apr 2022, at 17:10, Sunil KR via Python-list wrote: > > I have some scripts that are old and won't work under python2 and at the > same time I am writing new scripts which will use python3. However, if python

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

2022-04-24 Thread Sunil KR via Python-list
The question is not one of conversion. The question is this: When I have both python 2 and python3, why is my python 2 script breaking? And when I remove python3 the problem goes away? In both cases (regardless of installing python 3 or not) I am using only python 2 to run the python2 script. W

Re: tail

2022-04-24 Thread Avi Gross via Python-list
I have been getting confused by how many interpretations and conditions for chasing tail people seem to be talking about. A fairly normal task is to want to see just the last N lines of a text-based  file.  A variant is the "tail -f" command from UNIX that continues to follow a growing file, ofte

Re: Style for docstring

2022-04-24 Thread Avi Gross via Python-list
Yes, Michael, a dictionary is an excellent way to represent a closed set of transitions which your permutations are. You examples use numerals but obviously a dictionary will allow transformations  of anything that can be hashed which mostly is items that are not mutable. Of course for the purpose

Re: Verifying I installed Python correctly

2022-04-25 Thread Sunil KR via Python-list
cd C:\google-python-exercises> python hello.py this doesn't looks like a valid command. However, is it because a newline got swallowed by misformatting? For clarity, I am reproducing the correct version of the steps: cd /d  C:\google-python-exercises python hello.py The error is:  The system c

Re: Style for docstring

2022-04-25 Thread Rob Cliffe via Python-list
Well, de gustibus non est disputandum.  For me, the switch from the imperative mode to the descriptive mode produces a mild cognitive dissonance. Best wishes Rob Cliffe On 25/04/2022 23:34, Cameron Simpson wrote: On 23Apr2022 03:26, Avi Gross wrote: We know some people using "professional" l

Re: Printing Unicode strings in a list

2022-04-28 Thread Jon Ribbens via Python-list
On 2022-04-28, Stephen Tucker wrote: > Hi PythonList Members, > > Consider the following log from a run of IDLE: > >== > > Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] > on win32 > Type "copyright", "credits" or "license()" for more information. p

Re: Printing Unicode strings in a list

2022-04-28 Thread Rob Cliffe via Python-list
On 28/04/2022 14:27, Stephen Tucker wrote: To Cameron Simpson, Thanks for your in-depth and helpful reply. I have noted it and will be giving it close attention when I can. The main reason why I am still using Python 2.x is that my colleagues are still using a GIS system that has a Python pro

Re: Python/New/Learn

2022-05-04 Thread Avi Gross via Python-list
https://wiki.python.org/moin/PythonBooks -Original Message- From: Patrick 0511 To: [email protected] Sent: Wed, May 4, 2022 9:36 pm Subject: Python/New/Learn Hello, I'm completely new here and don't know anything about python. Can someone tell me how best to start? So what things

Re: Python/New/Learn

2022-05-04 Thread Avi Gross via Python-list
[email protected] Sent: Wed, May 4, 2022 11:02 pm Subject: Re: Python/New/Learn On Thu, 5 May 2022 at 12:57, Avi Gross via Python-list wrote: > > https://wiki.python.org/moin/PythonBooks > That's an incredibly daunting list, and not something I'd overly strongly recommend, but yes, i

Re: Python/New/Learn

2022-05-04 Thread Avi Gross via Python-list
I agree Chris that the Ukrainian Python Books are daunting as I barely started learning that language now even though my early years were just a few miles away and I might even have relatives still there! But as has been pointed out, suggestions are more helpful if you know a bit more about the

Re: Python/New/Learn

2022-05-05 Thread Avi Gross via Python-list
Before more people reply to this user, I note I have not seen them reply back to the list about any questions or comments others have taken the time to provide. My warning bells go off when I see patterns and there was a similar request from another gmail account to an R language forum I am als

Re: Python/New/Learn

2022-05-06 Thread Avi Gross via Python-list
This topic has rapidly shifted over way beyond Python even as the original  person has not returned to participate. There are many ways to teach anything and since the classical method was to learn in person from someone using mainly sound or pantomime, it has hung on. Even with the existence of

Re: tail

2022-05-07 Thread Avi Gross via Python-list
Marco, I think it was made clear from the start that "text" files in the classic sense have no random access method at any higher level than reading a byte at some offset from the beginning of the file, or back from the end when it has not grown. The obvious fact is that most of the time the li

Re: tail

2022-05-11 Thread Avi Gross via Python-list
Just FYI, UNIX had a bunch of utilities that could emulate a vanilla version of tail on a command line. You can use sed, awk and quite a few others to simply show line N to the end of a file or other variations.  Of course the way many things were done back then had less focus on efficiency than

Re: tail

2022-05-11 Thread Avi Gross via Python-list
This seems to be a regular refrain where someone wants something as STANDARD in a programming language or environment and others want to keep it lean and mean or do not see THIS suggestion as particularly important or useful. Looking at the end of something is extremely common. Packages like nump

Re: .0 in name

2022-05-13 Thread Avi Gross via Python-list
Bryan, As has been pointed out, it is very common in possibly all programming languages to not allow digits at the start of many identifiers. It makes it hard to parse for numbers which tend to start with digits. Some languages even have special rules on not starting a number with a zero unless

Re: .0 in name

2022-05-13 Thread Avi Gross via Python-list
... ❽ ❽ -Original Message----- From: Avi Gross via Python-list To: [email protected] Sent: Fri, May 13, 2022 6:02 pm Subject: Re: .0 in name Bryan, As has been pointed out, it is very common in possibly all programming languages to not allow digits at the start of many identifiers. It

Re: .0 in name

2022-05-13 Thread Avi Gross via Python-list
You left out 3CPO, Dave. Names with numerals are not unreasonable in some circumstances. But programming languages are not a full spectrum of real life. They can have  reserved words too so you may not be able to use "while" and if you choose to create a function that masks another, you cannot c

Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
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

Re: Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
On 16/05/2022 04:13, Dan Stromberg wrote: On Sun, May 15, 2022 at 8:01 PM Rob Cliffe via Python-list 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

Re: Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
Thanks, Paul.  Question answered! Rob Cliffe On 16/05/2022 04:36, Paul Bryan wrote: This may explain it: https://stackoverflow.com/questions/27522626/hash-function-in-python-3-3-returns-different-results-between-sessions On Mon, 2022-05-16 at 04:20 +0100, Rob Cliffe via Python-list wrote

Re: Python & nmap

2022-05-18 Thread Jon Ribbens via Python-list
On 2022-05-18, ^Bart wrote: > THE INPUT > - > import nmap > nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE -PA21,23,80,3389') > hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()] > for host, status i

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

2022-05-20 Thread Vinay Sajip via Python-list
What Changed? = This is an enhancement and bug-fix release, and all users are encouraged to upgrade. Brief summary: * Fixed #161: Added a status attribute to the returned object from gen_key() which   is set to 'ok' if a key was successfully created, or 'key not created' if that   wa

Re: oop issue

2022-05-23 Thread Avi Gross via Python-list
invest_crypto.client_list.append(self) I am wondering about the phrasing above. When you are in the dunder init function, you normally create and change items in YOURSELF so why is your code not changing self.crypto_client_list? And what are you appending to before ever creating it? Would it k

Re: Problems with Python

2022-05-31 Thread Howard Samuels via Python-list
Good day I am new to programming.  I have signed up for a virtual online course and installed Python using Anaconda as well as jupyter notebook. I encountered problems & then went to YouTube tried going directly to the python website and used Pycharm. When I used pycharm and try to run the first

Re: How to test characters of a string

2022-06-07 Thread Avi Gross via Python-list
Amazing how some people bring out the heavy artillery, first! LOL! If the question was how to remove any initial digits and perhaps whitespace in a string, it is fairly easy to do without any functions to test if there are digits before the title. I mean look at initial characters and move forwa

Re: How to replace characters in a string?

2022-06-08 Thread Jon Ribbens via Python-list
On 2022-06-08, Dave wrote: > I misunderstood how it worked, basically I’ve added this function: > > def filterCommonCharacters(theString): > myNewString = theString.replace("\u2019", "'") > return myNewString > Which returns a new string replacing the common characters. > > This can easil

Re: How to replace characters in a string?

2022-06-08 Thread Avi Gross via Python-list
Dave, Your goal is to compare titles and there can be endless replacements needed if you allow the text to contain anything but ASCII. Have you considered stripping out things instead? I mean remove lots of stuff that is not ASCII in the first place and perhaps also remove lots of extra punctu

Re: How to test characters of a string

2022-06-09 Thread Avi Gross via Python-list
Dave, Sometimes a task is done faster by NOT programming anything in any language! Not only have you spent a lot of your own time but many dozens of messages here have dragged in others, who gain nothing ;-) The domain you are operating in seems to have lots of variants in how the titles are s

Re: Missing global # gdal DRIVER_NAME declaration in gdal_array.py

2022-06-09 Thread Payton Ireland via Python-list
On Tuesday, March 8, 2022 at 12:52:29 PM UTC-6, Shaozhong SHI wrote: > The following warning kept coming up when running ogr2ogr. > > Warning 1: Missing global # gdal: DRIVER_NAME declaration in > C:\Users\AppData\Local\Programs\Python\Python36\Lib\site-packages\osgeo\gdal_array.py > > > What

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

2022-06-09 Thread Avi Gross via Python-list
Dave, Despite your other programming knowledge, I suspect you think this is the forum where people come to be tutored. Try here: https://mail.python.org/mailman/listinfo/tutor Yes, there are plenty of pretty printers available and you can build your own function fairly easily. A module like pp

Re: fill out bulletins

2022-06-14 Thread Avi Gross via Python-list
I wish this discussion was simplified. It sounds to me like what is wanted is a way to PRINT a filled-out form using some dynamic text that fits over designated slots in the data. It is not that different from many other tasks where you overlay some graphics with text. You need a decent version o

What's up with modern Python programmers rewriting everything in Rust?

2022-06-20 Thread jan Anja via Python-list
Dude, it's called CPython for a reason. -- https://mail.python.org/mailman/listinfo/python-list

Re: "CPython"

2022-06-20 Thread Avi Gross via Python-list
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 I don't even want to think fo what sound a C# Python would make. OK, my apologies to all. Being an inter

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.

Re: "CPython"

2022-06-23 Thread Avi Gross via Python-list
David, I am curious why you are undertaking the effort to take a language already  decades old and showing signs of being a tad rusty into a language that suggests further oxidation. More seriously, I am interested in what this can gain and the intended user  base. I studied Rust for a while and i

Re: "CPython"

2022-06-24 Thread Avi Gross via Python-list
David, I understand now. As a project for your own edification I can understand it, albeit it is a more substantial effort than many people might choose, LOL! So unless it starts being used heavily and adopted by some organization, the result of your effort will not necessarily be compatible with

REPL with multiple function definitions

2022-06-26 Thread Rob Cliffe via Python-list
This 2-line program def f(): pass def g(): pass runs silently (no Exception).  But: 23:07:02 c:\>python Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): pass ... d

Re: REPL with multiple function definitions

2022-06-26 Thread Jon Ribbens via Python-list
On 2022-06-26, Rob Cliffe wrote: > This 2-line program > > def f(): pass > def g(): pass > > runs silently (no Exception).  But: > > 23:07:02 c:\>python > Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 > bit (Intel)] on win32 > Type "help", "copyright", "credits" or "lic

Re: REPL with multiple function definitions

2022-06-28 Thread Rob Cliffe via Python-list
On 26/06/2022 23:22, Jon Ribbens via Python-list wrote: On 2022-06-26, Rob Cliffe wrote: This 2-line program def f(): pass def g(): pass runs silently (no Exception).  But: 23:07:02 c:\>python Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on wi

Byte arrays and DLLs

2022-06-30 Thread Rob Cliffe via Python-list
I have an application in which I wanted a fixed-length "array of bytes" (that's intended as an informal term) where I could read and write individual bytes and slices, and also pass the array to a DLL (one I wrote in C) which expects an "unsigned char *" parameter. I am using ctypes to talk to t

Re: Byte arrays and DLLs

2022-07-03 Thread Rob Cliffe via Python-list
That worked.  Many thanks Eryk. Rob On 30/06/2022 23:45, Eryk Sun wrote: On 6/30/22, Rob Cliffe via Python-list wrote: AKAIK it is not possible to give ctypes a bytearray object and persuade it to give you a pointer to the actual array data, suitable for passing to a DLL. You're overlo

Re: NILEARN - WHY THIS CODE THROWS AN ERROR?????

2022-07-08 Thread Avi Gross via Python-list
Nati Stern has asked several questions here, often about relatively technical uses of python code that many of us have never used and still is not providing more exact info that tends to be needed before anyone can even think of diagnosing the problem. I have learned to stay away from some such

Re: what's the problem??????

2022-07-13 Thread Avi Gross via Python-list
Nati, This is a two-way process and requires you to be very clear on what is not working or what you are trying to do or help clear away having us try to understand lots of code that is not very related to the question. Your code, as shown, makes an empty string repeatedly in a loop.  a=dict() I

ANN: distlib 0.3.5 released on PyPI

2022-07-14 Thread Vinay Sajip via Python-list
I've recently released version 0.3.5 of distlib on PyPI [1]. For newcomers, distlib is a library of packaging functionality which is intended to be usable as the basis for third-party packaging tools. The main changes in this release are as follows: * Fixed #161: Updated test case. * Fixed #164:

message

2022-07-14 Thread Bart Kuijer via Python-list
In the last 10 years of my working life I worked as a freelancer, as a specialist in Microsoft Access, at Interpolis-Tilburg, Rabobank-Zeist, Abn-Amro-Amsterdam and the SVB in Amstelveen, among others. From 1999 onward, I developed an accounting program in Microsoft Access for myself, Boeket,

random.SystemRandom().randint() inefficient

2022-07-26 Thread Cecil Westerhof via Python-list
I need to get a random integer. At first I tried it with: from secrets import randbelow index = randbelow(len(to_try)) This works perfectly, but it took some time. So I thought I try: from random import SystemRandom index = SystemRandom().randint(0, len(to_try) - 1) A first indic

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

2022-07-26 Thread Cecil Westerhof via Python-list
Chris Angelico writes: > On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list > wrote: >> >> I need to get a random integer. At first I tried it with: >> from secrets import randbelow >> index = randbelow(len(to_try)) >> >> This wo

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

2022-07-26 Thread Cecil Westerhof via Python-list
Chris Angelico writes: > On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list > wrote: >> >> Chris Angelico writes: >> >> > On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list >> > wrote: >> >> >> >> I need

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

2022-07-27 Thread Cecil Westerhof via Python-list
Barry writes: >> On 26 Jul 2022, at 16:07, Cecil Westerhof via Python-list >> wrote: >> >> I need to get a random integer. At first I tried it with: >>from secrets import randbelow >>index = randbelow(len(to_try)) >> >> This works perf

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

2022-07-27 Thread Cecil Westerhof via Python-list
"Michael F. Stemper" writes: > This is orthogonal to your question, but might be of some use to you: > > The combination of using len(to_try) as an argument to randint() and > saving the output to a variable named "index" suggests that you might > be setting up to select a random element from to_

Re: More efficient code, but slower program

2022-07-27 Thread Cecil Westerhof via Python-list
[email protected] (Stefan Ram) writes: > Cecil Westerhof writes: >>values = [*range(100)] > > In many cases, any iterable is just fine and a list is not > required, just as peudo-random numbers often are just fine and > real-world entropy is not required. In this case both are. I mus

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

2022-07-27 Thread Cecil Westerhof via Python-list
Chris Angelico writes: > On Wed, 27 Jul 2022 at 08:18, Cecil Westerhof via Python-list > wrote: >> >> Chris Angelico writes: >> >> > On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list >> > wrote: >> >> >> >> Chris A

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

2022-07-27 Thread Cecil Westerhof via Python-list
Chris Angelico writes: > Incidentally - if you are actually trying to select a specific item, > you may want to consider random.choice. Yes, I try to select a random element, but it has also to be removed. An element should be used at most once. This is the code I use: # index = randbelow(le

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

2022-07-27 Thread Cecil Westerhof via Python-list
Dennis Lee Bieber writes: > On Tue, 26 Jul 2022 23:47:59 +0200, Cecil Westerhof > declaimed the following: > > >>The new code: >>from random import SystemRandom >>system_random = SystemRandom() >>index = system_random.randint(0, len(to_try) - 1) >> >>The first two statements are e

More efficient code, but slower program

2022-07-27 Thread Cecil Westerhof via Python-list
It is not very important, but I am just curious. Original I had in a program: values = [*range(100)] But because it is done quite often I expected that initialising: range_list = [*range(100)] and then use: values = range_list.copy() Would be more efficient. So I tried:

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

2022-07-27 Thread Cecil Westerhof via Python-list
Dennis Lee Bieber writes: > On Wed, 27 Jul 2022 10:45:47 +0200, Cecil Westerhof > declaimed the following: > > >>What do you mean with where the python version is from? > > Base Python.org download, ActiveState package download, Anaconda > package download, native OS install/extra install

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

2022-07-27 Thread Cecil Westerhof via Python-list
MRAB writes: > On 27/07/2022 16:43, Cecil Westerhof via Python-list wrote: >> "Michael F. Stemper" writes: >> >>> This is orthogonal to your question, but might be of some use to you: >>> >>> The combination of using len(to_try) as an

Re: More efficient code, but slower program

2022-07-27 Thread Cecil Westerhof via Python-list
[email protected] writes: > On 2022-07-27 at 17:48:47 +0200, > Regarding "Re: More efficient code, but slower program," > Cecil Westerhof via Python-list wrote: > >> [email protected] (Stefan Ram) writes: >> >> > Cecil W

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

2022-07-27 Thread Cecil Westerhof via Python-list
Roel Schroeven writes: > Cecil Westerhof via Python-list schreef op 27/07/2022 om 17:43: >> "Michael F. Stemper" writes: >> >> > This is orthogonal to your question, but might be of some use to you: >> > >> > The combination of using len(to_

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

2022-07-27 Thread Cecil Westerhof via Python-list
MRAB writes: >>> When you pop an element from the last, the elements after it need to be >>> moved down, which takes time. >>> >>> Try shuffling the list and then popping the now randomly-ordered >>> elements off the end. >> Would shuffling not be a lot more expensive? Especially because I do >>

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

2022-07-27 Thread Cecil Westerhof via Python-list
Alan Bawden writes: > Cecil Westerhof writes: > >Yes, I try to select a random element, but it has also to be removed, >because an element should not be used more as once. > > Instead of using pop to do that why not something like: > > def lazy_shuffle(seq): > """ > G

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread Jon Ribbens via Python-list
On 2022-07-28, Ben Hirsig wrote: > Hi, I noticed this when using the requests library in the response.elapsed > object (type timedelta). Tested using the standard datetime library alone > with the example displayed on > https://docs.python.org/3/library/datetime.html#examples-of-usage-timedelta >

Re: Trying to understand nested loops

2022-08-05 Thread Mladen Gogala via Python-list
On Fri, 5 Aug 2022 08:34:45 +0100, ojomooluwatolami675 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): >

Re: Persistent Error: Python was not found

2022-08-15 Thread Gisle Vanem via Python-list
Eryk Sun wrote: If the redirector app is run without arguments, it will open the Microsoft Store to install the latest version of the Python store app distribution. Currently that means Python 3.10. That is true with cmd. But with a shell like 4NT, I get: c:\> "%LocalAppData%\Microsoft\Windo

Re: UTF-8 and latin1

2022-08-17 Thread Jon Ribbens via Python-list
On 2022-08-17, Tobiah wrote: > I get data from various sources; client emails, spreadsheets, and > data from web applications. I find that I can do some_string.decode('latin1') > to get unicode that I can use with xlsxwriter, > or put in the header of a web page to display > European characters

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-17, Tobiah wrote: >> That has already been decided, as much as it ever can be. UTF-8 is >> essentially always the correct encoding to use on output, and almost >> always the correct encoding to assume on input absent any explicit >> indication of another encoding. (e.g. the HTML "standa

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-17, Barry wrote: >> On 17 Aug 2022, at 18:30, Jon Ribbens via Python-list >> wrote: >> On 2022-08-17, Tobiah wrote: >>> I get data from various sources; client emails, spreadsheets, and >>> data from web applications. I find that I can do >

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-18, Tobiah wrote: >> Generally speaking browser submisisons were/are supposed to be sent >> using the same encoding as the page, so if you're sending the page >> as "latin1" then you'll see that a fair amount I should think. If you >> send it as "utf-8" then you'll get 100% utf-8 back.

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-18, Tobiah wrote: >> You configure the web server to send: >> >> Content-Type: text/html; charset=... >> >> in the HTTP header when it serves HTML files. > > So how does this break down? When a person enters > Montréal, Quebéc into a form field, what are they > doing on the keyb

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Jon Ribbens via Python-list
On 2022-08-19, Chris Angelico wrote: > What's the best way to precisely reconstruct an HTML file after > parsing it with BeautifulSoup? > > Using the Alice example from the BS4 docs: > html_doc = """The Dormouse's story > >The Dormouse's story > >Once upon a time there were three little siste

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Jon Ribbens via Python-list
On 2022-08-20, Chris Angelico wrote: > On Sun, 21 Aug 2022 at 03:27, Stefan Ram wrote: >> [email protected] writes: >> >textual representations. That way, the following two elements are the >> >same (and similar with a collection of sub-elements in a different order >> >in anoth

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Jon Ribbens via Python-list
On 2022-08-20, Stefan Ram wrote: > Jon Ribbens writes: >>... or you could avoid all that faff and just do re.sub()? > > import bs4 > import re > > source = '' > > # Use Python to change the source, keeping the order of attributes. > > result = re.sub( r'href\s*=\s*"http"', r'href="https"', source

Re: Mutating an HTML file with BeautifulSoup

2022-08-21 Thread Jon Ribbens via Python-list
On 2022-08-21, Chris Angelico wrote: > On Sun, 21 Aug 2022 at 09:31, Jon Ribbens via Python-list > wrote: >> On 2022-08-20, Chris Angelico wrote: >> > On Sun, 21 Aug 2022 at 03:27, Stefan Ram wrote: >> >> [email protected] writes: >> >

Re: Mutating an HTML file with BeautifulSoup

2022-08-22 Thread Jon Ribbens via Python-list
On 2022-08-21, Peter J. Holzer wrote: > On 2022-08-20 21:51:41 -, Jon Ribbens via Python-list wrote: >> On 2022-08-20, Stefan Ram wrote: >> > Jon Ribbens writes: >> >>... or you could avoid all that faff and just do re.sub()? > >> > source = 

Re: Mutating an HTML file with BeautifulSoup

2022-08-22 Thread Jon Ribbens via Python-list
On 2022-08-21, Chris Angelico wrote: > On Mon, 22 Aug 2022 at 05:43, Jon Ribbens via Python-list > wrote: >> On 2022-08-21, Chris Angelico wrote: >> > On Sun, 21 Aug 2022 at 09:31, Jon Ribbens via Python-list >> > wrote: >> >> On 2022-08-20, Chris Angel

Re: Mutating an HTML file with BeautifulSoup

2022-08-22 Thread Jon Ribbens via Python-list
On 2022-08-22, Peter J. Holzer wrote: > On 2022-08-22 00:45:56 -, Jon Ribbens via Python-list wrote: >> With the offset though, BeautifulSoup made an arbitrary decision to >> use ISO-8859-1 encoding and so when you chopped the bytestring at >> that offset it only worked

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

2022-08-23 Thread Vinay Sajip via Python-list
What Changed? = This is an enhancement and bug-fix release, and all users are encouraged to upgrade. Brief summary: * Fixed #181: Added the ability to pass file paths to encrypt_file, decrypt_file,   sign_file, verify_file, get_recipients_file and added import_keys_file. * Fixed #18

Re: any author you find very good has written a book on Python?

2022-09-07 Thread Tim Daneliuk via Python-list
On 9/5/22 21:22, Meredith Montgomery wrote: I never read a book on Python. I'm looking for a good one now. I just searched the web for names such as Charles Petzold, but it looks like he never wrote a book on Python. I also searched for Peter Seibel, but he also never did. I also tried to sea

Re: DoesNotExist at /admin/blog/blog/add/: blog matching query does not exist

2022-09-12 Thread Enerel Amgalan via Python-list
unsubscribe -Bat > On Sep 12, 2022, at 14:32, [email protected] wrote: > > Suddenly I can no longer add blogs to Django. Django says 'blog > matching query does not exist'. That seems strange to me because I want > to add something to the database and not request a blog. What could b

Re: Asynchronous execution of synchronous functions

2022-09-26 Thread Jon Ribbens via Python-list
On 2022-09-26, Stefan Ram wrote: > So, I wanted to try to download all pages in parallel with > processes to avoid any GIL effect, while I don't understand > what the GIL actuall is. But processes didn't work here, so > I tried threads. This worked and now the total run time is > down to

Implementation of an lru_cache() decorator that ignores the first argument

2022-09-28 Thread Robert Latest via Python-list
Hi all, in a (Flask) web application I often find that many equal (SQLAlchemy) queries are executed across subsequent requests. So I tried to cache the results of those queries on the module level like this: @lru_cache() def query_db(db, args): # do the "expensive" query r

PyObject_CallFunctionObjArgs segfaults

2022-09-29 Thread Jen Kris via Python-list
Recently I completed a project where I used PyObject_CallFunctionObjArgs extensively with the NLTK library from a program written in NASM, with no problems.  Now I am on a new project where I call the Python random library.  I use the same setup as before, but I am getting a segfault with random

Re: Implementation of an lru_cache() decorator that ignores the first argument

2022-09-29 Thread Robert Latest via Python-list
Hi Chris and dh, thanks for your --as usually-- thoughtful and interesting answers. Indeed, when doing these web applications I find that there are several layers of useful, maybe less useful, and unknown caching. Many of my requests rely on a notoriously unreliable read-only database outside of m

Re: PyObject_CallFunctionObjArgs segfaults

2022-09-29 Thread Jen Kris via Python-list
cremented the reference to all objects in Get_LibModules, but I still get the same segfault at PyObject_CallFunctionObjArgs.  Unfortunately, reference counting is not well documented so I’m not clear what’s wrong.  Sep 29, 2022, 10:06 by [email protected]: > On 2022-09-29 16:5

Re: PyObject_CallFunctionObjArgs segfaults

2022-09-29 Thread Jen Kris via Python-list
> > So I incremented the reference to all objects in Get_LibModules, but I still > get the same segfault at PyObject_CallFunctionObjArgs.  Unfortunately, > reference counting is not well documented so I’m not clear what’s wrong.  > > > > > Sep 29, 2022, 10:06 by p

Re: PyObject_CallFunctionObjArgs segfaults

2022-09-29 Thread Jen Kris via Python-list
;> value_ptr, NULL); >> >> if (p_seed_calc == 0x0){ >>     PyErr_Print(); >>     return 1;} >> >> //Prepare return values >> long return_val = PyLong_AsLong(p_seed_calc); >> >> return return_val; >> } >> >> So I in

Re: PyObject_CallFunctionObjArgs segfaults

2022-09-30 Thread Jen Kris via Python-list
Thanks very much for your detailed reply.  I have a few followup questions.  You said, “Some functions return an object that has already been incref'ed ("new reference"). This occurs when it has either created a new object (the refcount will be 1) or has returned a pointer to an existing objec

Re: PyObject_CallFunctionObjArgs segfaults

2022-09-30 Thread Jen Kris via Python-list
That's great.  It clarifies things a lot for me, particularly re ref count for new references.  I would have had trouble if I didn't decref it twice.  Thanks very much once again.  Sep 30, 2022, 12:18 by [email protected]: > On 2022-09-30 17:02, Jen Kris wrote: > >> >> Thanks very

<    12   13   14   15   16   17   18   19   20   21   >