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 "normal" indentation.  You seem to use it in all your
postings, too, which hurts my brain, but I guess that's my problem :-)

[snip (40 lines)]



It's not just your problem. When the texts are particularly long and
complex, I happen to use Google-Translator. It makes bad translations if
the lines are interrupted by the newline, so I wrote a tool dedicated to
Stefan and to all those who indent like him. This tool takes the text
from the clipboard, removes all the superfluous spaces, combines all the
lines in one and puts the result back into the clipboard. :-D

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


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 society!

# replace complete words
replacements =\
{ rb'kind of': b'kind of',
   rb'trying to': b'trying to',
   rb'got to': b'got to',
   rb'gonna': b'going to',
   }
lines =\
[ re.sub( rb"\b(" + b"|".join( replacements.keys() ) + rb")\b",
 lambda x: replacements[ x.group() ], line )
   if len( line )and line[ 0 ]not in b'>|' else line for line in lines ]



I present to you the brutality to which your posts are subjected:

   for(d = s = pCLipb; *s != TEXT('\0'); s++)
   {
  if(d == pCLipb)
  {
 if(*s != TEXT(' ') && *s != TEXT('\n') && *s != TEXT('\r'))
*d++ = *s;
  }
  else if(*s == TEXT(' ') || *s == TEXT('\n') || *s == TEXT('\r'))
  {
 if(d[-1] != TEXT(' '))
*d++ = TEXT(' ');
  }
  else
 *d++ = *s;
   }
   *d = TEXT('\0');

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


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, utf_16_be all of them
without BOM. With those utf_32_xx I have no problem but with the
UTF_16_xx I have. If I have an utf_16_le coded file and I read it with
encoding='utf_16_le' I have no problem I read it, with
encoding='utf_16_be' I can read it without any error even if the data I
receive have the inverted bytes. The same thing happens with the
utf_16_be codified file, 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. What did I not understand? What am I doing wrong?

thanks in advance

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


That is why the BOM was created. A lot of files can be “correctly” read as 
either UTF-16-LE or UTF-1-BE encoded, as most of the 16 bit codes are valid, so 
unless the wrong encoding happens to hit something that is invalid (most likely 
something looking like a Surrogage Pair without a match), there isn’t an error 
in reading the file. The BOM character was specifically designed to be an 
invalid code if read by the wrong encoding (if you ignore the possibility of 
the file having a NUL right after the BOM)

If you know the files likely contains a lot of “ASCII” characters, then you 
might be able to detect that you got it wrong, due to seeing a lot of 0xXX00 
characters and few 0x00XX characters, but that doesn’t create an “error” 
normally.



Thanks to you too for the reply. I was actually looking for a way to
distinguish "utf16le" texts from "utf16be" ones. Unfortunately, whoever
created this log file archive thought that the BOM was not important and
so omitted it. Now they want to switch to "utf8 " and also save the
previous. Fortunately I can be sure that the text of the log files
is in some European language, so after converting the file to "utf8" I
make sure that most of the bytes are less than the value 0x7F and if not
I reconvert them by replacing "utf16 " "le" with "be" or vice versa. The
strategy seems to be working. In the future, by writing files in "utf8"
they will no longer have problems like this.

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


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, so your observation isn't really
   surprising. The computer can't report an error here since it
   can't infer the correct encoding from the file data. It's like
   that koan: "A bit has the value 1. What does that mean?".



Understood. They are just 2 bytes and there is no difference between
them.

Thank you.


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


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 I have. If I have an utf_16_le coded file and I read it with
encoding='utf_16_le' I have no problem I read it, with
encoding='utf_16_be' I can read it without any error even if the data I
receive have the inverted bytes. The same thing happens with the
utf_16_be codified file, 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. What did I not understand? What am I doing wrong?

thanks in advance

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


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.


   Here's a technique to better understand such code:

   Transform it into a program with small statements and small
   expressions with no more than one call per statement if possible.
   (After each litte change check that the output stays the same.)

import pandas as pd

# Warning! Will overwrite the file 'file_20240412201813_tmp_DML.csv'!
with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out:
 print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6
foo1,aa,ab,zz,ad,ae,af
foo2,ba,bb,bc,bd,zz,bf
foo3,ca,zz,cc,cd,ce,zz
foo4,da,db,dc,dd,de,df
foo5,ea,eb,ec,zz,ee,ef
foo6,fa,fb,fc,fd,fe,ff''', file=out )
# Note the "index_col=0" below, which is important here!
df = pd.read_csv( 'file_20240412201813_tmp_DML.csv', index_col=0 )

selection = df.where( df == 'zz' )
selection_stack = selection.stack()
df = selection_stack.reset_index()
df0 = df.iloc[ :, 0 ]
df1 = df.iloc[ :, 1 ]
z = zip( df0, df1 )
l = list( z )
result ={ 'zz': l }
print( result )

   I suggest to next insert print statements to print each intermediate
   value:

# Note the "index_col=0" below, which is important here!
df = pd.read_csv( 'file_20240412201813_tmp_DML.csv', index_col=0 )
print( 'df = \n', type( df ), ':\n"', df, '"\n' )

selection = df.where( df == 'zz' )
print( "result of where( df == 'zz' ) = \n", type( selection ), ':\n"',
   selection, '"\n' )

selection_stack = selection.stack()
print( 'result of stack() = \n', type( selection_stack ), ':\n"',
   selection_stack, '"\n' )

df = selection_stack.reset_index()
print( 'result of reset_index() = \n', type( df ), ':\n"', df, '"\n' )

df0 = df.iloc[ :, 0 ]
print( 'value of .iloc[ :, 0 ]= \n', type( df0 ), ':\n"', df0, '"\n' )

df1 = df.iloc[ :, 1 ]
print( 'value of .iloc[ :, 1 ] = \n', type( df1 ), ':\n"', df1, '"\n' )

z = zip( df0, df1 )
print( 'result of zip( df0, df1 )= \n', type( z ), ':\n"', z, '"\n' )

l = list( z )
print( 'result of list( z )= \n', type( l ), ':\n"', l, '"\n' )

result ={ 'zz': l }
print( "value of { 'zz': l }= \n", type( result ), ':\n"',
   result, '"\n' )

print( result )

   Now you can see what each single step does!

df =
   :
"  foo1 foo2 foo3 foo4 foo5 foo6
obj
foo1   aa   ab   zz   ad   ae   af
foo2   ba   bb   bc   bd   zz   bf
foo3   ca   zz   cc   cd   ce   zz
foo4   da   db   dc   dd   de   df
foo5   ea   eb   ec   zz   ee   ef
foo6   fa   fb   fc   fd   fe   ff "

result of where( df == 'zz' ) =
   :
"  foo1 foo2 foo3 foo4 foo5 foo6
obj
foo1  NaN  NaN   zz  NaN  NaN  NaN
foo2  NaN  NaN  NaN  NaN   zz  NaN
foo3  NaN   zz  NaN  NaN  NaN   zz
foo4  NaN  NaN  NaN  NaN  NaN  NaN
foo5  NaN  NaN  NaN   zz  NaN  NaN
foo6  NaN  NaN  NaN  NaN  NaN  NaN "

result of stack() =
   :
" obj
foo1  foo3zz
foo2  foo5zz
foo3  foo2zz
   foo6zz
foo5  foo4zz
dtype: object "

result of reset_index() =
   :
" obj level_1   0
0  foo1foo3  zz
1  foo2foo5  zz
2  foo3foo2  zz
3  foo3foo6  zz
4  foo5foo4  zz "

value of .iloc[ :, 0 ]=
   :
" 0foo1
1foo2
2foo3
3foo3
4foo5
Name: obj, dtype: object "

value of .iloc[ :, 1 ] =
   :
" 0foo3
1foo5
2foo2
3foo6
4foo4
Name: level_1, dtype: object "

result of zip( df0, df1 )=
   :
" "

result of list( z )=
   :
" [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), ('foo5', 
'foo4')]"

value of { 'zz': l }=
   :
" {'zz': [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), 
('foo5', 'foo4')]}"

{'zz': [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), 
('foo5', 'foo4')]}

   The script reads a CSV file and stores the data in a Pandas
   DataFrame object named "df". The "index_col=0" parameter tells
   Pandas to use the first column as the index for the DataFrame,
   which is kinda like column headers.

   The "where" creates a new DataFrame selection that contains
   the same data as df, but with all values replaced by NaN (Not
   a Number) except for the values that are equal to 'zz'.

   "stack" returns a Series with a multi-level index created
   by pivoting the columns. Here it gives a Series with the
   row-col-addresses of a all the non-NaN values. The general
   meaning of "stack" might be the most complex operation of
   this script. It's explained in the pandas manual (see there).

   "reset_index" then just transforms this Series back into a
   DataFrame, and ".iloc[ :, 0 ]" and ".iloc[ :, 1 ]" are the
   first and second column, respectively, of that DataFrame. These
   then are zipped to get the desired form as a list of pairs.



And this is a technique very similar to reverse engineering. Thanks for
the explanation and examples. All this is really clear and I was able to
follow 

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


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 out:
 print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6
foo1,aa,ab,zz,ad,ae,af
foo2,ba,bb,bc,bd,zz,bf
foo3,ca,zz,cc,cd,ce,zz
foo4,da,db,dc,dd,de,df
foo5,ea,eb,ec,zz,ee,ef
foo6,fa,fb,fc,fd,fe,ff''', file=out )

df = pd.read_csv( 'file_20240412201813_tmp_DML.csv' )

result = {}

for rownum, row in df.iterrows():
 iterator = row.items()
 _, rowname = next( iterator )
 for colname, value in iterator:
 if value not in result: result[ value ]= []
 result[ value ].append( ( rowname, colname ))

print( result )



In reality what I wanted to achieve was this:

what = 'zz'
result = {what: []}

for rownum, row in df.iterrows():
iterator = row.items()
_, rowname = next(iterator)
for colname, value in iterator:
if value == what:
result[what] += [(rowname, colname)]
print(result)

In any case, thank you again for pointing me in the right direction. I
had lost myself looking for a pandas method that would do this in a
single shot or almost.


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


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
 |
 foo2|   ba   bb   bc   bd   zz   bf
 |
 foo3|   ca   zz   cc   cd   ce   zz
 |
 foo4|   da   db   dc   dd   de   df
 |
 foo5|   ea   eb   ec   zz   ee   ef
 |
 foo6|   fa   fb   fc   fd   fe   ff


And I would like to get a result similar to this:

{
'zz':[('foo1','foo3'),
  ('foo2','foo5'),
  ('foo3','foo2'),
  ('foo3','foo6'),
  ('foo5','foo4')
 ]
}

Would you show me the path, please?
Thank you in advance.

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


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):
   lt = n >> 62
   n &= (~(0x3f << 62)) & ((1 << 63) - 1)
   n = (n - ((n >> 1) & 0o3)
  - ((n >> 2) & 0o1))
   n = (   (n & 0o307070707070707070707)
+ ((n & 0o070707070707070707070) >> 3))
   return (n % 63) + (0, 1, 1, 2)[lt]

n=0x
bit_count_64(n)
64

n=0x3ffe
bit_count_64(n)
61

bit_count_64(1 << 63)
1

...in C it would have been simpler :^)

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


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 big you expect n to be and
how many trailing zeros you expect. If n is a very large integer then
this does three large integer operations in (n^(n-1)).bit_count().
They are relatively fast operations but all linear in bit size. By
contrast a check like n & 1 is O(1) and half the time proves that no
further steps are necessary.

The mpmath library needs this exact operation and is generally
intended for the large n case so I checked how it is implemented
there:

https://github.com/mpmath/mpmath/blob/f13ea4dc925d522062ac734bd19a0a3cc23f9c04/mpmath/libmp/libmpf.py#L160-L177

That code is:

 # Strip trailing bits
 if not man & 1:
 t = trailtable[man & 255]
 if not t:
 while not man & 255:
 man >>= 8
 exp += 8
 bc -= 8
 t = trailtable[man & 255]
 man >>= t
 exp += t
 bc -= t

The trailtable variable is a pre-initialised list of shifts needed to
remove zeros from an 8-bit integer. The bc variable here is just
bc=man.bit_length() which is redundant but this code predates the
addition of the int.bit_length() method.

In principle this could use a large number of man>>=8 shifts which
would potentially be quadratic in the bit size of man. In practice the
probability of hitting the worst case is very low so the code is
instead optimised for the expected common case of large man with few
trailing zeros.

--
Oscar



HI,
I would turn the question to you: how big do you expect the value to
manage?
In a 'big numbers' context or when you need to convert a large amount of
values at the same time, your comment is absolutely valid, it is less
valid if the values can be represented with 64 bits.
I'll try to imagine the worst case in 64 bit:

b64Max=0x
i=1
while True:
i *= 2
if not i <= b64Max:
break
else:
n=i
n
9223372036854775808

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. It probably had to find the highest bit first but what if it
had a simple algorithm inside like this:

def h_bit(val):
tbits = 0
bits = 64 // 2
b64Max = 0xF
while bits > 0:
if (b64Max << bits) & val:
val >>= bits
tbits += bits
bits //= 2
return tbits

would only add 6 more iterations for values needing 64 bits (7
interactions for 128 bits, 3 if 8 bits)

If we use the library you suggest for a single value or a non-'big
numbers' value (e.g. 2048 bit) the initialization alone would be slower
than the function in question. The table you are talking about is
initialized in the following way:

trailtable = [trailing(n) for n in range(256)]

(it calls a function 256 times)

This is why I think that what you said is true but it depends a lot on
the context and to all this I would add that the best cases are much
greater than the worst cases.

e.g.:
powers_of_2_in(n + 1)
(0, 9223372036854775809)
powers_of_2_in(n - 1)
(0, 9223372036854775807)

(probably only 1 interaction)

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


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


for n = 0 your function get stack overflow


That's right.  Let's say ``assert n > 0'' before we say ``if''.



...or just:

...
if n == 0 or remainder(n, 2) != 0:
...

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


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() - 1
>

Great solution, unfortunately the return value is not a tuple as in the
OP version. Maybe in this way?

def powers_of_2_inB(n):
bc = (n ^ (n - 1)).bit_count() - 1
return bc, int(n / (1 << bc))

Good point.  I overlooked that.  I should have written:

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.

I was pretty happy with a recursive version.  If I'm not mistaken,
nobody has offered a recursive version so far.  It's my favorite
actually because it seems to be the clearest one.

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



for n = 0 your function get stack overflow
--
https://mail.python.org/mailman/listinfo/python-list


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

2023-11-29 Thread 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 you write this procedure?

--8<---cut here---start->8---
def powers_of_2_in(n):
  s = 0
  while "I still find factors of 2 in n...":
q, r = divmod(n, 2)
if r == 0:
  s = s + 1
  n = n // 2
else:
  return s, n
--8<---cut here---end--->8---
--
https://mail.python.org/mailman/listinfo/python-list




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


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

2023-11-29 Thread 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?

def powers_of_2_inB(n):
bc = (n ^ (n - 1)).bit_count() - 1
return bc, int(n / (1 << bc))

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


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.org/mailman/listinfo/python-list


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.

After cleaning they might be as big as 1Mb but that would be super rare.
Perhaps only for testing.

I'm extracting CAS numbers and here is the pattern xx-xx-x up to
xxx-xx-x eg., 1012300-77-4

def remove_alpha(txt):

      """  r'[^0-9\- ]':

      [^...]: Match any character that is not in the specified set.

      0-9: Match any digit.

      \: Escape character.

      -: Match a hyphen.

      Space: Match a space.

      """

  cleaned_txt = re.sub(r'[^0-9\- ]', '', txt)

      bits = cleaned_txt.split()

      pieces = []

      for bit in bits:

      # minimum size of a CAS number is 7 so drop smaller clumps 
of digits


      pieces.append(bit if len(bit) > 6 else "")

      return " ".join(pieces)


Many thanks for any hints


Why don't you use re.findall?

re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)


I think I can see what you did there but it won't make sense to me - or 
whoever looks at the code - in future.


That answers your specific question. However, I am in awe of people who 
can just "do" regular expressions and I thank you very much for what 
would have been a monumental effort had I tried it.


That little re.sub() came from ChatGPT and I can understand it without 
too much effort because it came documented


I suppose ChatGPT is the answer to this thread. Or everything. Or will be.

Thanks

Mike


I respect your opinion but from the point of view of many usenet users
asking a question to chatgpt to solve your problem is truly an overkill.
The computer world overflows with people who know regex. If you had not
already had the answer with the use of 're' I would have sent you my
suggestion that as you can see it is practically identical. I am quite
sure that in this usenet the same solution came to the mind of many
people.

with open(file) as fp:
try: ret = re.findall(r'\b\d{2,7}\-\d{2}\-\d{1}\b', fp.read())
except: ret = []

The only difference is '\d' instead of '[0-9]' but they are equivalent.

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


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 stdout) no longer beeps (or makes any sound).  This is true 
whether I print "\a" from a python program, or "type 
".

I have found via Google workarounds such as
     os.system("rundll32 user32.dll,MessageBeep")
but it is a trifle annoying to have to modify all of my programs that beep.
Can anyone shed light on this, and perhaps give a simpler fix?
Best wishes
Rob Cliffe



HI,
I would first check the properties of the terminal, then the system
configuration relating to the system beep. It can be disabled.
You can find some tips here:


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