Re: Correct syntax for pathological re.search()

2024-10-19 Thread jak via Python-list
Peter J. Holzer ha scritto: As a trivial example, the regular expressions r"\\sout{" and r"\\sout\{" are equivalent (the \ before the { is redundant). Yet re.compile(s).pattern preserves the difference between the two strings. Hi, Allow me to be fussy: r"\\sout{" and r"\\sout\{" are similar bu

Re: Python Dialogs

2024-05-06 Thread jak via Python-list
Loris Bennett ha scritto: r...@zedat.fu-berlin.de (Stefan Ram) writes: Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! Is there a name for this kind of indentation, i.e. the stuff you are writing not being flush left? It is sort of contrary to what I think of as "norm

Re: Python Dialogs

2024-05-06 Thread jak via Python-list
Stefan Ram ha scritto: r...@zedat.fu-berlin.de (Stefan Ram) wrote or quoted: translation services are gonna interpret line breaks as I just beefed up my posting program to replace "gonna". Now I won't come across like some street thug, but rather as a respectable member of human soci

Re: UTF_16 question

2024-05-01 Thread jak via Python-list
Richard Damon ha scritto: On Apr 29, 2024, at 12:23 PM, jak via Python-list wrote: Hi everyone, one thing that I do not understand is happening to me: I have some text files with different characteristics, among these there are that they have an UTF_32_le coding, utf_32be, utf_16_le

Re: UTF_16 question

2024-04-29 Thread jak via Python-list
Stefan Ram ha scritto: jak wrote or quoted: I read it, both with encoding='utf_16_be' and with 'utf_16_le' without errors but in the last case the bytes are inverted. I think the order of the octets (bytes) is exactly the difference between these two encodings,

UTF_16 question

2024-04-29 Thread jak via Python-list
Hi everyone, one thing that I do not understand is happening to me: I have some text files with different characteristics, among these there are that they have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them without BOM. With those utf_32_xx I have no problem but with the UTF_16_xx

Re: help: pandas and 2d table

2024-04-16 Thread jak via Python-list
Stefan Ram ha scritto: jak wrote or quoted: Stefan Ram ha scritto: df = df.where( df == 'zz' ).stack().reset_index() result ={ 'zz': list( zip( df.iloc[ :, 0 ], df.iloc[ :, 1 ]))} Since I don't know Pandas, I will need a month at least to understand these 2 lines of code. Thanks again. H

Re: help: pandas and 2d table

2024-04-16 Thread jak via Python-list
Stefan Ram ha scritto: df = df.where( df == 'zz' ).stack().reset_index() result ={ 'zz': list( zip( df.iloc[ :, 0 ], df.iloc[ :, 1 ]))} Since I don't know Pandas, I will need a month at least to understand these 2 lines of code. Thanks again. -- https://mail.python.org/mailman/listinfo/python-l

Re: help: pandas and 2d table

2024-04-13 Thread jak via Python-list
Stefan Ram ha scritto: jak wrote or quoted: Would you show me the path, please? I was not able to read xls here, so I used csv instead; Warning: the script will overwrite file "file_20240412201813_tmp_DML.csv"! import pandas as pd with open( 'file_20240412201813_tmp_DML.csv', 'w' )as

help: pandas and 2d table

2024-04-12 Thread jak via Python-list
Hi everyone. I state that I don't know anything about 'pandas' but I intuited that it could do what I want. I get, through the "read_excel" method, a table similar to this: obj| foo1 foo2 foo3 foo4 foo5 foo6 --- foo1| aa ab zz ad ae af

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

2023-12-05 Thread jak via Python-list
Alan Bawden ha scritto: If you like this sort of stuff, check out the book "Hacker's Delight" by Henry Warren. See. Thank you for your suggestion. Really interesting. Just for fun I tried to port the function to 64 bit: def bit_count_64(n):

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

2023-12-04 Thread jak via Python-list
Oscar Benjamin ha scritto: On Sun, 3 Dec 2023 at 10:25, Julieta Shem via Python-list wrote: Alan Bawden writes: def powers_of_2_in(n): bc = (n ^ (n - 1)).bit_count() - 1 return bc, n >> bc That's pretty fancy and likely the fastest. It might be the fastest but it depends how b

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

2023-12-03 Thread jak via Python-list
Julieta Shem ha scritto: jak writes: [...] --8<---cut here---start->8--- def powers_of_2_in(n): if remainder(n, 2) != 0: return 0, n else: s, r = powers_of_2_in(n // 2) return 1 + s, r --8<---cut here---end-

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

2023-12-03 Thread jak via Python-list
Julieta Shem ha scritto: Alan Bawden writes: 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

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

2023-11-29 Thread jak via Python-list
Dom Grigonis ha scritto: def powers_of_2_in(n): s = 0 while n % 2 == 0: s += 1 n = n // 2 return s, n Good solution, unfortunately if the input data is zero, the function never ends. On 30 Nov 2023, at 02:44, Julieta Shem via Python-list wrote: How would y

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

2023-11-29 Thread jak via Python-list
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 solution, unfortunately the return value is not a tuple as in the OP version. Maybe in this way?

Re: Code improvement question

2023-11-17 Thread jak via Python-list
MRAB ha scritto: Bare excepts are a very bad idea. I know, you're right but to test the CAS numbers were inside a string (txt) and instead of the 'open(file)' there was 'io.StingIO(txt)' so the risk was almost null. When I copied it here I didn't think about it. Sorry. -- https://mail.python.

Re: Code improvement question

2023-11-17 Thread jak via Python-list
Mike Dewhirst ha scritto: On 15/11/2023 10:25 am, MRAB via Python-list wrote: On 2023-11-14 23:14, Mike Dewhirst via Python-list wrote: I'd like to improve the code below, which works. It feels clunky to me. I need to clean up user-uploaded files the size of which I don't know in advance. Aft

Re: Beep on WIndows 11

2023-11-12 Thread jak via Python-list
Rob Cliffe ha scritto:  Apologies if this is not a Python question. I  recently moved from a WIndows 10 laptop to a Windows 11 one. Although there is nothing wrong with the sound on the new machine (I can listen to podcasts and watch videos), I find that outputting "\a" to the console (aka std