Re: how to discover what values produced an exception?

2024-05-06 Thread Alan Bawden via Python-list
Thomas Passin writes: On 5/3/2024 9:56 AM, 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: > >

Re: Python Dialogs (Posting On Python-List Prohibited)

2024-05-03 Thread Alan Bawden via Python-list
Lawrence D'Oliveiro writes: > Assume you have an expression "s.replace('a','b').replace('c','d'). > replace('e','f').replace('g','h')". Its value is a string which > is the value of s, but with "a" replaced by "b", "c" replaced by > "d", "e" replaced by "f" and "g" replaced by "h".

Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Alan Bawden via Python-list
Chris Angelico writes: > On 08Feb2024 12:21, tony.fl...@btinternet.com wrote: > >I know that mappings by default support the ** operator, to unpack the > >mapping into key word arguments. > > > >Has it been considered implementing a dunder method for the ** > >operator so you

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

2023-12-05 Thread Alan Bawden via Python-list
jak writes: Oscar Benjamin ha scritto: ... If we now use the function being discussed: powers_of_2_in(n) (63, 1) we can see that the bit_count() method had to do 63 iterations to count the bits I certainly hope that the bit_count method doesn't count bits by iterating

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

2023-11-29 Thread Alan Bawden via Python-list
jak writes: Alan Bawden ha scritto: > Julieta Shem writes: > > How would you write this procedure? > def powers_of_2_in(n): > ... > > def powers_of_2_in(n): > return (n ^ (n - 1)).bit_count() - 1 > Great solutio

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

2023-11-29 Thread Alan Bawden via Python-list
Julieta Shem writes: How would you write this procedure? def powers_of_2_in(n): ... def powers_of_2_in(n): return (n ^ (n - 1)).bit_count() - 1 -- https://mail.python.org/mailman/listinfo/python-list

Re: Checking if email is valid

2023-11-02 Thread Alan Bawden via Python-list
Chris Angelico writes: On Thu, 2 Nov 2023 at 15:20, AVI GROSS via Python-list wrote: > Yes, it would be nice if there was a syntax for sending a test > message sort of like an ACK that is not delivered to the recipient > but merely results in some status being sent back such as

Re: Python list insert iterators

2023-03-03 Thread Alan Bawden
Guenther Sohler writes: Hi Python community, I have a got an example list like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 T T and i eventually want to insert items in the given locations (A shall go between 2 and 3, B shall go between 6 and 7) Right now i just use

Re: Regular Expression bug?

2023-03-02 Thread Alan Bawden
jose isaias cabrera writes: On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s)

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

2022-07-27 Thread Alan Bawden
Cecil Westerhof writes: 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

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

2022-07-27 Thread Alan Bawden
e willing to have it destroyed by this process: seq = list(seq) n = len(seq) while n: i = randrange(n) yield seq[i] n -= 1 if i < n: seq[i] = seq[n] -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: on a statement followed by an expression

2022-06-04 Thread Alan Bawden
time. Your original code that used a `for' loop is actually much clearer. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: min, max with position

2022-06-04 Thread Alan Bawden
looking for is usually called "argmax" and "argmin" (see ). These don't exist in the standard Python library as far as I can tell, but numpy does have "argmax" and "argmin" routines. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: tail

2022-05-09 Thread Alan Bawden
Marco Sulla writes: On Mon, 9 May 2022 at 19:53, Chris Angelico wrote: ... Nevertheless, tail is a fundamental tool in *nix. It's fast and reliable. Also the tail command can't handle different encodings? It definitely can't. It works for UTF-8, and all the ASCII compatible single

Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
And I missed one that was just published last month: https://datatracker.ietf.org/doc/html/rfc9171 Unlike RFC 5050, this version of the protocol actually claims to be a "Proposed Standard". -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
g/wiki/Delay-tolerant_networking https://datatracker.ietf.org/doc/html/rfc4838 https://datatracker.ietf.org/doc/html/rfc5050 -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Advantages of Default Factory in Dataclasses

2021-11-16 Thread Alan Bawden
David Lowry-Duda writes: ... For the same reason that the following code doesn't do what some people might expect it to: ```python def add_to(elem, inlist=[]): inlist.append(elem) return inlist list1 = add_to(1) list2 = add_to(2) print(list1) # prints

Re: New assignmens ...

2021-10-24 Thread Alan Bawden
the target to be as general as possible! I'm guessing that about 70% of you will think that this is a horrible idea, 10% of you will find it compelling, and the remaining 20% will find themselves conflicted. You can count me in that last category... -- Alan Bawden -- https://mail.python.org/mailman

Re: Strange disassembly

2021-06-19 Thread Alan Bawden
Chris Angelico writes: >>> sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>> def chk(x): ... if not(0 < x < 10): raise Exception ... >>> dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST

Re: .title() - annoying mistake

2021-03-20 Thread Alan Bawden
Sibylle Koczian writes: Am 20.03.2021 um 09:34 schrieb Alan Bawden: > > When you write that code to capitalize your book titles, you should be > calling .title() rather than .upper() if you are doing it right. > But that's exactly what he's doing, with a

Re: .title() - annoying mistake

2021-03-20 Thread Alan Bawden
'\u01f1'.lower() '\u01f3' This is the "dz" character. >>> '\u01f1'.title() '\u01f2' This is the "Dz" character. When you write that code to capitalize your book titles, you should be calling .title() rather than .upper() if you are doing it right. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about generators

2021-03-05 Thread Alan Bawden
tween append and extend. I suspect that the heart of your confusion actually has nothing to do with generators. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Control stript which is runing in background.

2021-01-02 Thread Alan Bawden
jak writes: Il 02/01/2021 01:07, Alan Bawden ha scritto: > jak writes: > > Il 01/01/2021 06:23, Alan Bawden ha scritto: > > jak writes: > > > > Running the command: > > > > $ cat bible.txt &g

Re: Control stript which is runing in background.

2021-01-01 Thread Alan Bawden
jak writes: Il 01/01/2021 06:23, Alan Bawden ha scritto: > jak writes: > > Running the command: > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > the three texts do not mix >

Re: Control stript which is runing in background.

2020-12-31 Thread Alan Bawden
tes may have data interleaved, on arbitrary boundaries, with writes by other processes, whether or not the O_NONBLOCK flag of the file status flags is set. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Class Definitions

2020-11-12 Thread Alan Bawden
like: class Main: value = [] def add(self, x): self.value += [x] and be suprised by the resulting behavior. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: IP address to binary conversion

2020-05-08 Thread Alan Bawden
al.alex...@gmail.com writes: > Just for the records and to have a fully working bidirectional solution: > > >>> ip > '10.44.32.0' > >>> struct.unpack('L', socket.inet_aton(ip))[0] > 2108426 > >>> socket.inet_ntoa(struct.pack(' '10.44.32.0' > >>> > > Good luck ;-) This will not work as expected

Re: How to test the data type of a variable

2020-04-23 Thread Alan Bawden
8 to test the data type, e.g. > is_floate(var) > is_string(var) > etc. ? You should probably be using isinstance(), as in: isinstance(var, float) isinstance(var, str) -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: [Python-ideas] Re: Magnitude and ProtoMagnitude ABCs — primarily for argument validation

2020-03-10 Thread Alan Bawden
n error. Kahan doesn't think much of signalling NaNs, writing that they "exist mainly for political reasons and are rarely used". -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: A small quiz

2020-01-03 Thread Alan Bawden
.« statement). Can you guess what it is? Well, there's sys.stdin. But I would expect beginning students to find the effect of typing "next(sys.stdin)" to the commnd prompt to be a bit confusing... -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: WedWonder: Scripts and Modules

2019-09-11 Thread Alan Bawden
I have been known to add `if __name__' to my colleagues' Python scripts, just so that I can safely `pydoc' them. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-02 Thread Alan Bawden
Chris Angelico writes: > On Mon, Sep 2, 2019 at 12:36 PM Alan Bawden wrote: ... > > > > a,b = 2,3 and [a,b] = [2,3] ... > > It looks to me like they generate identical code. The first one calls the > > construction of a tuple, where the second one calls for the

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-01 Thread Alan Bawden
ized the tuple away, but failed to optimize the list away! -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: An "Object" class?

2019-08-28 Thread Alan Bawden
e _implementation_ of `int' and `float' that you _usually_ shouldn't concern yourself with. Stick to `isinstance' and `issubclass' and everthing looks pretty kosher. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: What make function with huge list so slow

2019-08-25 Thread Alan Bawden
much physical memory you have, you much actually be swapping before you're done. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: My pseudocode to Python?

2019-08-19 Thread Alan Bawden
Alan Bawden writes: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > > for i in range( len( list )- 1, 0, -1 ): > > if list[ i ]is None: del list[ i ] > > list = [x for x in list if x is not None] Except 'list' is a bad name to use... -- Alan Bawden -- https://ma

Re: My pseudocode to Python?

2019-08-19 Thread Alan Bawden
r...@zedat.fu-berlin.de (Stefan Ram) writes: > for i in range( len( list )- 1, 0, -1 ): > if list[ i ]is None: del list[ i ] list = [x for x in list if x is not None] -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: FDs will be closed after exception automatically in python2.7?

2019-06-11 Thread Alan Bawden
D'Arcy Cain writes: > On 2019-06-10 15:46, Alan Bawden wrote: > > D'Arcy Cain writes: > >> with open("file","w+") as fd: > > > > That makes the window smaller, but it doesn't actually eliminate it. Look > > at the generated byte code. I

Re: FDs will be closed after exception automatically in python2.7?

2019-06-10 Thread Alan Bawden
,"w+") as fd: That makes the window smaller, but it doesn't actually eliminate it. Look at the generated byte code. In both cases the call to open() is over and the open file is created _before_ the SETUP_WITH instruction is executed. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Testing the data type of a value

2019-05-13 Thread Alan Bawden
(Red Hat 4.8.5-28)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> isinstance(True, int) True >>> type(True) == int False >>> type(True) -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Lifetime of a local reference

2019-03-01 Thread Alan Bawden
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Alan Bawden writes: > >The Java compiler has no way to know whether a variable references an > >object with a finalize() method that has side effects > > java.lang.Object#finalize() is deprecated since Java 9. And

Re: Lifetime of a local reference

2019-02-27 Thread Alan Bawden
Gregory Ewing writes: > Alan Bawden wrote: > > the Java Language > > Specification contains the following language: > >Optimizing transformations of a program can be designed that reduce > >the number of objects that are reachable to be less than those

Re: Lifetime of a local reference

2019-02-26 Thread Alan Bawden
spect that given the history of Python, pretty much everybody has always assumed that a Python implementation will not delete local variables early. But I agree with you that the Python Language Reference does not appear to address this question anywhere! -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Improvement Request

2018-11-24 Thread Alan Bawden
e table of contents disappears off the top. It's a reasonable request, but this probably isn't the most effective place to make it. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Odd truth result with in and ==

2018-11-23 Thread Alan Bawden
xError: invalid syntax 3.6> not [1,2,3] == (not True) True 3.6> not [] == (not True) True 3.6> (not []) == (not True) False -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Python indentation (3 spaces)

2018-10-14 Thread Alan Bawden
Chris Angelico writes: > On Mon, Oct 15, 2018 at 9:56 AM Alan Bawden wrote: > > In my experience this is a very common way to assume that tabs will be > > interpreted. Virtually every source-code file I have encountered since the > > mid 1970s (for any programming languag

Re: Python indentation (3 spaces)

2018-10-14 Thread Alan Bawden
red since the mid 1970s (for any programming language or operating system) has assumed either this convention or, slightly less often, its 4-column variant. It's surprising that you've never encountered it. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Quickest way to concatenate strings

2018-10-12 Thread Alan Bawden
sed that it doesn't take a few more than that. Although I imagine that that balance might tip at a different point in future releases of Python (I tested using 3.6.6). -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: List replication operator

2018-05-27 Thread Alan Bawden
uldn't there also be a concatenation operator that performs a copy of some kind on its operands? -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Usenet Gateway

2018-05-23 Thread Alan Bawden
Gene Heskett writes: > You are stating an opinion, but no facts to back it up, so describe your > environment that makes you write that, please. If he describes his environment and why he likes it, will that be a "fact"? Or will you dismiss that as just another

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Alan Bawden
signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGPIPE, signal.SIG_DFL) -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Make a unique filesystem path, without creating the file

2016-02-28 Thread Alan Bawden
Cameron Simpson <c...@zip.com.au> writes: > On 22Feb2016 12:34, Alan Bawden <a...@csail.mit.edu> wrote: I have deleted the part of discussion where it seems that we must simply agree to disagree. You think mktemp() is _way_ more dangerous that I do. >>> In fact your use

Re: Make a unique filesystem path, without creating the file

2016-02-22 Thread Alan Bawden
Cameron Simpson <c...@zip.com.au> writes: > On 16Feb2016 19:24, Alan Bawden <a...@csail.mit.edu> wrote: >>So in the FIFO case, I might write something like the following: >> >>def make_temp_fifo(mode=0o600): >>while True: >>

Re: Make a unique filesystem path, without creating the file

2016-02-16 Thread Alan Bawden
utions in the common cases of making files and directories, but I see no good reason to deprecate this useful utility. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: What is a function parameter =[] for?

2015-11-25 Thread Alan Bawden
in the documentation I can find actually _guarantees_ that a Python implementation will only have one unique empty tuple, but I wouldn't be suprised if the following is nonetheless true in all current implementations: >>> tuple([]) is tuple([]) True ) -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: What is a function parameter =[] for?

2015-11-25 Thread Alan Bawden
Chris Angelico <ros...@gmail.com> writes: > On Thu, Nov 26, 2015 at 1:08 PM, Alan Bawden <a...@csail.mit.edu> wrote: >> (Note that nothing in the documentation I can find actually _guarantees_ >> that a Python implementation will only have one unique empty tuple, bu

Re: How to wow someone new to Python

2015-01-21 Thread Alan Bawden
, but for some other Java datatypes (e.g., Buffer) it is a real problem. Score one for untyped languages. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: How to wow someone new to Python

2015-01-21 Thread Alan Bawden
Alan Bawden a...@scooby-doo.csail.mit.edu writes: ... Score one for untyped languages. Drat. I should have writted dynamically typed languages. The language has changed. When I was a novice Lisp hacker, we were comfortable saying that Lisp was untyped. But nowadays we always say that Lisp

Re: .write() behavior

2014-10-31 Thread Alan Bawden
not. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

.write() behavior

2014-10-28 Thread Alan Bawden
design document for Python 3 IO that I should read that would explain the rationale for all this? -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Proposal: === and !=== operators

2014-07-11 Thread Alan Bawden
not is. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of list reference

2014-02-16 Thread Alan Bawden
Marko Rauhamaa ma...@pacujo.net writes: Case in point, if everything is a reference, how come: hello.__str__() 'hello' 1.__str__() SyntaxError: invalid syntax (1).__str__() '1' 1..__str__() '1.0' -- Alan Bawden -- https://mail.python.org/mailman/listinfo

Re: interactive help on the base object

2013-12-09 Thread Alan Bawden
start using their current ordering until Python 2.3. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: interactive help on the base object

2013-12-08 Thread Alan Bawden
don't ask me if it was good for anything, but it was definitely there... -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: 10 sec poll - please reply!

2012-11-20 Thread Alan Bawden
Since the event being generated is commonly called a keystroke, and since my dictionary defines the noun stroke as being: the act of striking, a good verb to choose for the action itself would seem to be strike: strike('a') -- http://mail.python.org/mailman/listinfo/python-list