[Solved] Re: Windows registry PermissionError

2022-05-12 Thread Mike Dewhirst

Eryk

Many thanks. It is working perfectly now. See below for the reworked code.

Cheers

Mike

On 13/05/2022 1:42 pm, Eryk Sun wrote:

On 5/12/22, Mike Dewhirst  wrote:

  access=wr.KEY_ALL_ACCESS + wr.KEY_WRITE,


import winreg as wr class Registry: def __init__(self, computer=None, 
hkey=None, sub_key=None): self.computer = computer self.key = hkey 
self.sub_key = sub_key def connect(self): return 
wr.ConnectRegistry(self.computer, self.key) def select(self, 
access=None): with self.connect() as hkey: return wr.OpenKeyEx(key=hkey, 
sub_key=self.sub_key, access=access) def count(self): access = 
wr.KEY_QUERY_VALUE return wr.QueryInfoKey(self.select(access=access)) 
def query(self, vname, access=None): if access is None: access = 
wr.KEY_READ | wr.KEY_WOW64_32KEY return 
wr.QueryValueEx(self.select(access=access), vname) def setvalue(self, 
vname, value, access=None): if access is None: access = wr.KEY_SET_VALUE 
with self.select(access=access) as hkey: return wr.SetValueEx(hkey, 
vname, 0, wr.REG_SZ, value) if __name__ == "__main__": lmregistry = 
Registry( hkey=wr.HKEY_LOCAL_MACHINE, sub_key=r"SOFTWARE\XXX 
Technology\AppName", ) print(f"\n{lmregistry.sub_key}") anz = 
lmregistry.query('Country')[0] print(f"\n{anz}") db = 
lmregistry.query('Database')[0] print(f"\n{db}") devref = 
lmregistry.query('v135')[0] print(f"\n{devref}") orgid = 
lmregistry.query('v136')[0] print(f"\n{orgid}") curegistry = Registry( 
hkey=wr.HKEY_CURRENT_USER, sub_key=r"SOFTWARE\XXX Technology\AppName", ) 
print(f"\n{curegistry.sub_key}") anz = curegistry.query('Country')[0] 
print(f"\n{anz}") db = curegistry.query('Database')[0] print(f"\n{db}") 
devref = curegistry.query('v135')[0] print(f"\n{devref}") orgid = 
curegistry.query('v136')[0] print(f"\n{orgid}") 
curegistry.setvalue('Country', 'nz') curegistry.setvalue('Database', 
'2022.2') curegistry.setvalue('v135', 'Asus10') 
curegistry.setvalue('v136', orgid.replace('ALL', 'Most')) anz = 
curegistry.query('Country')[0] print(f"\n{anz}") db = 
curegistry.query('Database')[0] print(f"\n{db}") devref = 
curegistry.query('v135')[0] print(f"\n{devref}") orgid = 
curegistry.query('v136')[0] print(f"\n{orgid}")


Again, many thanks for putting so much effort into educating me.

Cheers

Mike

The access parameter is a bit mask of access rights that combine via
bitwise OR (|), not via arithmetic addition.

KEY_ALL_ACCESS (0x000F_003F) is a superset of KEY_WRITE (0x0002_0006):

 KEY_WRITE = (
 READ_CONTROL   | # 0x0002_
 KEY_SET_VALUE  | # 0x_0002
 KEY_CREATE_SUB_KEY | # 0x_0004
 )# 0x0002_0006

 KEY_ALL_ACCESS = (
 DELETE | # 0x0001_
 READ_CONTROL   | # 0x0002_
 WRITE_DAC  | # 0x0004_
 WRITE_OWNER| # 0x0008_
 KEY_QUERY_VALUE| # 0x_0001
 KEY_SET_VALUE  | # 0x_0002
 KEY_CREATE_SUB_KEY | # 0x_0004
 KEY_ENUMERATE_SUB_KEYS | # 0x_0008
 KEY_NOTIFY | # 0x_0010
 KEY_CREATE_LINK| # 0x_0020
 )# 0x000F_003F

The result of the arithmetic addition `KEY_ALL_ACCESS + KEY_WRITE` is
0x0011_0045, which is wrong and meaningless. Registry key objects do
not support SYNCHRONIZE (0x0010_) access; DELETE (0x0001_)
access isn't needed; 0x_0040 is not a supported key right;
KEY_CREATE_SUB_KEY (0x_0004) access isn't needed; and
KEY_QUERY_VALUE (0x_0001) isn't sufficient.

You should limit the requested access to the specific access rights
that are required for querying and setting values in the key:

 access=(wr.KEY_QUERY_VALUE | wr.KEY_SET_VALUE)


 def setvalue(self, vname, value):
return wr.SetValueEx(self.select(), vname, 0, 1, value)

You shouldn't hard code the value of the data type constant. Use
wr.REG_SZ instead of 1.

The return value of self.select() is a winreg PyHKEY object that wraps
the OS handle for the key object. You're relying on implicit closing
of this handle based on referencing counting. It's cleaner to use it
in a `with` statement, as you would for a file object returned by
open(). For example:

 with self.select() as hkey:
 wr.SetValueEx(hkey, vname, 0, wr.REG_SZ, value)


  lmregistry = Registry(
  hkey=wr.HKEY_LOCAL_MACHINE,
  sub_key="SOFTWARE\WOW6432Node\XXX Technology\AppName",

You really shouldn't open the "WOW6432Node" key directly. It is an
implementation detail of the WOW64 subsystem that runs 32-bit
applications on a 64-bit system. If you need to operate on the
registry keys of 32-bit applications from a native 64-bit process,
open the normal path using the access right KEY_WOW64_32KEY
(0x_0200). For example:

 hkey = wr.HKEY_LOCAL_MACHINE
 subkey = r"SOFTWARE\XXX Technology\AppName"
 access = (
 wr.KEY_QUERY_VALUE |
 

Re: Windows registry PermissionError

2022-05-12 Thread Eryk Sun
On 5/12/22, Mike Dewhirst  wrote:
>
>  access=wr.KEY_ALL_ACCESS + wr.KEY_WRITE,

The access parameter is a bit mask of access rights that combine via
bitwise OR (|), not via arithmetic addition.

KEY_ALL_ACCESS (0x000F_003F) is a superset of KEY_WRITE (0x0002_0006):

KEY_WRITE = (
READ_CONTROL   | # 0x0002_
KEY_SET_VALUE  | # 0x_0002
KEY_CREATE_SUB_KEY | # 0x_0004
)# 0x0002_0006

KEY_ALL_ACCESS = (
DELETE | # 0x0001_
READ_CONTROL   | # 0x0002_
WRITE_DAC  | # 0x0004_
WRITE_OWNER| # 0x0008_
KEY_QUERY_VALUE| # 0x_0001
KEY_SET_VALUE  | # 0x_0002
KEY_CREATE_SUB_KEY | # 0x_0004
KEY_ENUMERATE_SUB_KEYS | # 0x_0008
KEY_NOTIFY | # 0x_0010
KEY_CREATE_LINK| # 0x_0020
)# 0x000F_003F

The result of the arithmetic addition `KEY_ALL_ACCESS + KEY_WRITE` is
0x0011_0045, which is wrong and meaningless. Registry key objects do
not support SYNCHRONIZE (0x0010_) access; DELETE (0x0001_)
access isn't needed; 0x_0040 is not a supported key right;
KEY_CREATE_SUB_KEY (0x_0004) access isn't needed; and
KEY_QUERY_VALUE (0x_0001) isn't sufficient.

You should limit the requested access to the specific access rights
that are required for querying and setting values in the key:

access=(wr.KEY_QUERY_VALUE | wr.KEY_SET_VALUE)

> def setvalue(self, vname, value):
>return wr.SetValueEx(self.select(), vname, 0, 1, value)

You shouldn't hard code the value of the data type constant. Use
wr.REG_SZ instead of 1.

The return value of self.select() is a winreg PyHKEY object that wraps
the OS handle for the key object. You're relying on implicit closing
of this handle based on referencing counting. It's cleaner to use it
in a `with` statement, as you would for a file object returned by
open(). For example:

with self.select() as hkey:
wr.SetValueEx(hkey, vname, 0, wr.REG_SZ, value)

>  lmregistry = Registry(
>  hkey=wr.HKEY_LOCAL_MACHINE,
>  sub_key="SOFTWARE\WOW6432Node\XXX Technology\AppName",

You really shouldn't open the "WOW6432Node" key directly. It is an
implementation detail of the WOW64 subsystem that runs 32-bit
applications on a 64-bit system. If you need to operate on the
registry keys of 32-bit applications from a native 64-bit process,
open the normal path using the access right KEY_WOW64_32KEY
(0x_0200). For example:

hkey = wr.HKEY_LOCAL_MACHINE
subkey = r"SOFTWARE\XXX Technology\AppName"
access = (
wr.KEY_QUERY_VALUE |
wr.KEY_SET_VALUE |
wr.KEY_WOW64_32KEY
)

Typically you'd first try opening the path without either
KEY_WOW64_32KEY or KEY_WOW64_64KEY. The default view matches the
current process.

https://docs.microsoft.com/en-us/windows/win32/winprog64/accessing-an-alternate-registry-view

Remember to escape the backslash separators in string literals of key
paths, or use raw string literals as I used in the above example.
-- 
https://mail.python.org/mailman/listinfo/python-list


Windows registry PermissionError

2022-05-12 Thread Mike Dewhirst
I'm trying to copy a value from HKLM to HKCU for application rollout via 
bulk installation by an administrator but individual Windows user setup.


Getting this ...

Traceback (most recent call last):
  File "D:\Users\mike\envs\chemdata\registry\wreg\wreg.py", line 84, in 


    curegistry.setvalue('Country', anz)
  File "D:\Users\mike\envs\chemdata\registry\wreg\wreg.py", line 51, in 
setvalue

    return wr.SetValueEx(self.select(), vname, 0, 1, value)
PermissionError: [WinError 5] Access is denied

... on my very own laptop where my login has admistrator permissions ... 
which I realise means nothing in this case.


But I would not have been surprised if it worked here but not in the 
field where users are firefighters and definitely not administrators and 
cannot install software on their workstations.


import winreg as wr


class Registry:

def __init__(self, computer=None, hkey=None, sub_key=None):
# computer is None means this computer
self.computer = computer
self.key = hkey
self.sub_key = sub_key

def connect(self):
return wr.ConnectRegistry(self.computer, self.key)

def select(self):
# also tried OpenKeyEx()
return wr.OpenKey(
key=self.key,
sub_key=self.sub_key,
access=wr.KEY_ALL_ACCESS + wr.KEY_WRITE,
)

def query(self, vname):
return wr.QueryValueEx(self.select(), vname)

def setvalue(self, vname, value):
return wr.SetValueEx(self.select(), vname, 0, 1, value)

if __name__ == "__main__":

lmregistry = Registry(
hkey=wr.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\WOW6432Node\XXX Technology\AppName",
)
print(f"\n{lmregistry.sub_key}")
anz = lmregistry.query('Country')[0]
print(f"\n{anz}") # works fine

curegistry = Registry(
hkey=wr.HKEY_CURRENT_USER,
sub_key="SOFTWARE\XXX Technology\AppName",
)
curegistry.setvalue('Country', anz)  < BOOM <
...

Any hints appreciated.

Cheers

Mike

--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.



OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Accuracy of multiprocessing.Queue.qsize before any Queue.get invocations?

2022-05-12 Thread Tim Chase
The documentation says[1]

> Return the approximate size of the queue. Because of
> multithreading/multiprocessing semantics, this number is not
> reliable.

Are there any circumstances under which it *is* reliable?  Most
germane, if I've added a bunch of items to the Queue, but not yet
launched any processes removing those items from the Queue, does
Queue.qsize accurately (and reliably) reflect the number of items in
the queue?

  q = Queue()
  for fname in os.listdir():
q.put(fname)
  file_count = q.qsize() # is this reliable?
  # since this hasn't yet started fiddling with it
  for _ in range(os.cpu_count()):
Process(target=myfunc, args=(q, arg2, arg3)).start()

I'm currently tracking the count as I add them to my Queue,

  file_count = 0
  for fname in os.listdir():
q.put(fname)
file_count += 1

but if .qsize is reliably accurate before anything has a chance to
.get data from it, I'd prefer to tidy the code by removing the
redunant counting code if I can.

I'm just not sure what circumstances the "this number is not
reliable" holds.  I get that things might be asynchronously
added/removed once processes are running, but is there anything that
would cause unreliability *before* other processes/consumers run?

Thanks,

-tkc

[1]
https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue.qsize





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


Re: tail

2022-05-12 Thread Cameron Simpson
On 12May2022 19:48, Marco Sulla  wrote:
>On Thu, 12 May 2022 at 00:50, Stefan Ram  wrote:
>>   There's no spec/doc, so one can't even test it.
>
>Excuse me, you're very right.
>
>"""
>A function that "tails" the file. If you don't know what that means,
>google "man tail"
>
>filepath: the file path of the file to be "tailed"
>n: the numbers of lines "tailed"
>chunk_size: oh don't care, use it as is

This is nearly the worst "specification" I have ever seen.

Describe what your function _does_.

Do not just send people to an arbitrary search engine to find possibly 
ephemeral web pages where someone has typed "man tail" and/or (if lucky) 
web pages with the output of "man tail" for any of several platforms.

But this is sounding more and more like a special purpose task to be 
done for your particular use cases. That says it should be in your 
personal toolkit. If it has general applicability, _publish_ your 
toolkit for others to use. You can do that trivially by pushing your 
code repo to any of several free services like bitbucket, gitlab, 
sourcehut, github etc. Or you can go the extra few yards and publish a 
package to PyPI and see if anyone uses it.

Part of your problem is that you think the term "tail" has a specific 
simple obvious meaning. But even to me it means at least 2 things:
- to report the last "n" "lines" of a text file
- to continuously report "new" data appended to a file

These are different, though related, tasks. The latter one is 
particularly easy if done purely for bytes (on systems which allow it).  
As you've had explained to you, the former task is actually very fiddly.

It is fiddly both in boundary conditions and complicated by being 
dependent on the text encoding, which you do not inherently know - that 
implies that you ought to (a) provide a way to specify that encoding and 
(b) maybe have a reasonable fallback default. But that default needs to 
be carefully and precisely explained. And the "find a line ending" 
criteria need to be explained. And the "sync to a character boundary" 
needs to be explained, including where it cannot be done.

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


Re: tail

2022-05-12 Thread Dennis Lee Bieber
On Thu, 12 May 2022 22:45:42 +0200, Marco Sulla
 declaimed the following:

>
>Maybe. Maybe not. What if the file ends with no newline?

https://github.com/coreutils/coreutils/blob/master/src/tail.c
Lines 567-569 (also lines 550-557 for "bytes_read" determination)



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


Re: tail

2022-05-12 Thread Marco Sulla
Thank you very much. This helped me to improve the function:

import os

_lf = b"\n"
_err_n = "Parameter n must be a positive integer number"
_err_chunk_size = "Parameter chunk_size must be a positive integer number"

def tail(filepath, n=10, chunk_size=100):
if (n <= 0):
raise ValueError(_err_n)

if (n % 1 != 0):
raise ValueError(_err_n)

if (chunk_size <= 0):
raise ValueError(_err_chunk_size)

if (chunk_size % 1 != 0):
raise ValueError(_err_chunk_size)

n_chunk_size = n * chunk_size
pos = os.stat(filepath).st_size
chunk_line_pos = -1
newlines_to_find = n
first_step = True

with open(filepath, "rb") as f:
text = bytearray()

while pos != 0:
pos -= n_chunk_size

if pos < 0:
pos = 0

f.seek(pos)
chars = f.read(n_chunk_size)
text[0:0] = chars
search_pos = n_chunk_size

while search_pos != -1:
chunk_line_pos = chars.rfind(_lf, 0, search_pos)

if first_step and chunk_line_pos == search_pos - 1:
newlines_to_find += 1

first_step = False

if chunk_line_pos != -1:
newlines_to_find -= 1

if newlines_to_find == 0:
break

search_pos = chunk_line_pos

if newlines_to_find == 0:
break

return bytes(text[chunk_line_pos+1:])



On Thu, 12 May 2022 at 20:29, Stefan Ram  wrote:

>   I am not aware of a definition of "line" above,
>   but the PLR says:
>
> |A physical line is a sequence of characters terminated
> |by an end-of-line sequence.
>
>   . So 10 lines should have 10 end-of-line sequences.
>

Maybe. Maybe not. What if the file ends with no newline?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Changing calling sequence

2022-05-12 Thread Michael F. Stemper

On 11/05/2022 14.58, anthony.flury wrote:


Why not do :

   def TempsOneDayDT(date:datetime.date):
  return TempsOneDay(date.year, date.month, date.day)

No repeat of code - just a different interface to the same functionality.


Yeah, a one-line wrapper around the original function seems a
lot simpler that any of my ideas. I think that I'll even use the
name from your example.

Thanks to all who posted, as well as the many lurkers who support me
in email.


--
Michael F. Stemper
Economists have correctly predicted seven of the last three recessions.
--
https://mail.python.org/mailman/listinfo/python-list


Re: "py" command for Linux and Mac?

2022-05-12 Thread De ongekruisigde
On 2022-05-12, Mats Wichmann  wrote:
> On 5/12/22 10:25, Dan Stromberg wrote:
>> Hi folks.
>> 
>> I heard there's a Windows-like "py" command for Linux (and Mac?).
>> 
>> I'm finally getting to porting a particular project's Python 2.7 code to
>> 3.x, and one of the first steps will probably be changing a lot of "python2
>> script.py" to use #!/usr/bin/env python2 and chmod +x.  Then we can update
>> the scripts one at a time to use #!/usr/bin/env python3.
>> 
>> However, would this be Linux-and-Mac-only?  I'm not at all sure this code
>> will ever move to Windows, but in case it does, would a "py" command work
>> on all 3 if I use #!/usr/bin/env py?
>
> The py command (python lanucher) respects shebang lines.

Linux by itself respects shebang lines, so you don't need a separate
launcher program. Just put e.g.:

#! /usr/bin/env python

at the top of your Python file.

-- 
In the beginning there was darkness and the darkness was without form
and void. And in addition to the darkness there was also me. And I moved
upon the face of the darkness and I saw that I was alone. ... ... ...
Let there be light. [Bomb 20; John Carpenter's Dark Star - 1974]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "py" command for Linux and Mac?

2022-05-12 Thread Mats Wichmann
On 5/12/22 10:25, Dan Stromberg wrote:
> Hi folks.
> 
> I heard there's a Windows-like "py" command for Linux (and Mac?).
> 
> I'm finally getting to porting a particular project's Python 2.7 code to
> 3.x, and one of the first steps will probably be changing a lot of "python2
> script.py" to use #!/usr/bin/env python2 and chmod +x.  Then we can update
> the scripts one at a time to use #!/usr/bin/env python3.
> 
> However, would this be Linux-and-Mac-only?  I'm not at all sure this code
> will ever move to Windows, but in case it does, would a "py" command work
> on all 3 if I use #!/usr/bin/env py?

The py command (python lanucher) respects shebang lines.

https://docs.python.org/3/using/windows.html#python-launcher-for-windows


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


Re: tail

2022-05-12 Thread Marco Sulla
On Thu, 12 May 2022 at 00:50, Stefan Ram  wrote:
>
> Marco Sulla  writes:
> >def tail(filepath, n=10, chunk_size=100):
> >if (n <= 0):
> >raise ValueError(_err_n)
> ...
>
>   There's no spec/doc, so one can't even test it.

Excuse me, you're very right.

"""
A function that "tails" the file. If you don't know what that means,
google "man tail"

filepath: the file path of the file to be "tailed"
n: the numbers of lines "tailed"
chunk_size: oh don't care, use it as is
"""
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "py" command for Linux and Mac?

2022-05-12 Thread MRAB

On 2022-05-12 17:25, Dan Stromberg wrote:

Hi folks.

I heard there's a Windows-like "py" command for Linux (and Mac?).

I'm finally getting to porting a particular project's Python 2.7 code to
3.x, and one of the first steps will probably be changing a lot of "python2
script.py" to use #!/usr/bin/env python2 and chmod +x.  Then we can update
the scripts one at a time to use #!/usr/bin/env python3.

However, would this be Linux-and-Mac-only?  I'm not at all sure this code
will ever move to Windows, but in case it does, would a "py" command work
on all 3 if I use #!/usr/bin/env py?

And if so, where can I find that "py" command for Linux and Mac?

I tried searching for it in Google and on Pypi, but unsurprisingly
searching for "py" gives a buzzillion hits on other things.

It's called the "Python Launcher"; you'll get more helpful results if 
you search for that.

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


"py" command for Linux and Mac?

2022-05-12 Thread Dan Stromberg
Hi folks.

I heard there's a Windows-like "py" command for Linux (and Mac?).

I'm finally getting to porting a particular project's Python 2.7 code to
3.x, and one of the first steps will probably be changing a lot of "python2
script.py" to use #!/usr/bin/env python2 and chmod +x.  Then we can update
the scripts one at a time to use #!/usr/bin/env python3.

However, would this be Linux-and-Mac-only?  I'm not at all sure this code
will ever move to Windows, but in case it does, would a "py" command work
on all 3 if I use #!/usr/bin/env py?

And if so, where can I find that "py" command for Linux and Mac?

I tried searching for it in Google and on Pypi, but unsurprisingly
searching for "py" gives a buzzillion hits on other things.

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


RE: Changing calling sequence

2022-05-12 Thread David Raymond
>>def TempsOneDay(*dateComponents):
>>if len(dateComponents) == 3:
>>year, month, date = dateComponents
>>elif len(dateComponents) == 1 and isinstance(dateComponents[0], 
>> datetime.date):
>>year, month, date = (dateComponents[0].year, dateComponents[0].month, 
>> dateComponents[0].day)
>>else:
>>raise Exception("Error message here")
>
>|>>> help( TempsOneDay )
>|Help on function TempsOneDay in module __main__:
>|
>|TempsOneDay(*dateComponents)


Then just add an appropriate docstring.

>>> def TempsOneDay(*dateComponents):
... """Can be called either with 3 arguments: year, month, day
...or with a single datetime.date object"""
... if len(dateComponents) == 3:
... year, month, date = dateComponents
... elif len(dateComponents) == 1 and isinstance(dateComponents[0], 
datetime.date):
... year, month, date = (dateComponents[0].year, 
dateComponents[0].month, dateComponents[0].day)
... else:
... raise Exception("Error message here")
...
>>> help(TempsOneDay)
Help on function TempsOneDay in module __main__:

TempsOneDay(*dateComponents)
Can be called either with 3 arguments: year, month, day
or with a single datetime.date object

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


[Python-announce] ANN: poliastro 0.16.3 released 

2022-05-12 Thread Juan Luis Cano Rodríguez
Hi all,

It fills us with astronomical joy to announce the release of poliastro
0.16.3! 

poliastro is an open source (MIT) pure Python library for interactive
Astrodynamics and Orbital Mechanics, with a focus on ease of use, speed,
and quick visualization. It provides a simple and intuitive API, and
handles physical quantities with units. It is used in academia and the
industry by people from all around the world.

You can install it using pip or conda:

pip install poliastro
conda install poliastro --channel conda-forge

This small release fixes some problems with latest Astropy on Python
3.10, and help us prepare for the upcoming SciPy 2022 conference in
Austin, Texas, USA. You can read the full release notes here:

https://docs.poliastro.space/en/v0.16.3/changelog.html#poliastro-0-16-3-
2022-05-09

If you want to learn more about poliastro, don't miss my talk on the
Open Source Cubesat Workshop held at the European Space Operations
Centre in 2017:

https://youtu.be/KnoYzqAw_vM?t=1h36m14s

And feel welcome to join our chat on Matrix to ask any questions you
might have and participate in our weekly community meetings:

http://chat.poliastro.space

Per Python ad astra!

---
Juan Luis Cano Rodríguez
___
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: [docs] Reporting a Bug

2022-05-12 Thread anthony.flury via Python-list



This is exactly as expected.


Strip removes any of the characters in the passed string from both the 
front and the end of the string being stripped.


The letter 'T' from the start of 'The meaning of life' does not appear 
in the word 'meaning' so nothing is removed from the start of the 
string.



The letter 'e' from the end of 'The meaning of life' does appear in the 
word 'meaning' so it is removed from the sentence; it will then look at 
the next last letter 'f', but since this doesn't appear in the word 
'meaning' nothing else is removed and the new string is returned.


The argument passed to strip(..) method is the set of characters to be 
removed - so any characters in that set are removed from the start and 
end of the string.





-- Original Message --
From: "Jeff Jeffi" 
To: d...@python.org
Cc: python-list@python.org
Sent: Wednesday, 4 May, 22 At 10:36
Subject: [docs] Reporting a Bug

Hello dears,

First of all i am not sure about this issue   please advise me if 
there is any mistake   in my report.



 for example in python 3.6.3 shell:



x= "The meaning of life" x.strip("meaning")

'The meaning of lif'


As you see the letter "e" of  the word "life"  is removed.


Sincerely yours.
J.Mohammadi




 ___
docs mailing list -- d...@python.org
To unsubscribe send an email to docs-le...@python.org
https://mail.python.org/mailman3/lists/docs.python.org/ 


Member address: anthony.fl...@btinternet.com

-- Anthony Fluryanthony.fl...@btinternet.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Re: New Tool Proposal

2022-05-12 Thread anthony.flury via Python-list


On 10/05/2022 15:04, Dan Stromberg wrote:


On Tue, May 10, 2022 at 3:15 AM Chris Angelico  wrote:

> It is often the case that developer write Code in Python and
then convert to a C extension module for performance regions.
>
> A C extension module has a lot of boiler plate code - for
instance the Structures required for each class, the functions for
Module initialization etc.
>
> My Idea is a simple tool that uses introspection tools to take a
Python module and to generate the relevant boiler plate for the
module - including blank functions for the module classes and for
methods. This tool would use type annotations (if given) to make
sensible choices for parameter and attribute types, including
using int and float directly rather than Internal objects
(depending on tool options).


Two things to say about this:
1) Sometimes abandoning a pure python module for a C extension for 
performance is a mistake - because Pypy is probably going to be much 
faster with the pure python module


Dan,

Thanks for your response, but I think PyPy will have a long way to go to 
make JIT generated code more efficient than hand crafted C extension.


for instance PyPy will almost certainly be unable to determine if 
integers, floats etc will need to use the Python runtime or can be 
optimized to use direct C types, another example would be lists - there 
are some cases where the C extension will always be a lot more efficient 
using C arrays than using the C list runtime machinery.


While there might be some cases where PyPy will be more efficient, I 
don't think that will be the case for all programs, and that ignores the 
fact that PyPi has major issues with the CAPI.



2) I've had some luck using m4 to maintain a single source file that 
is used to automatically generate both pure python and cython.  This 
is a little like using cpp in a C project.


For examples of #2, perhaps see:
https://stromberg.dnsalias.org/~strombrg/treap/
https://stromberg.dnsalias.org/svn/rolling_checksum_mod/trunk/
https://stromberg.dnsalias.org/~strombrg/sort-comparison/

It's often nice to keep the lines of the pure-python and cython having 
a 1-1 relationship, so that tracebacks report useful line numbers 
either way.  However, in the treap example I've dispensed with that 
because some methods were almost identical but had some boilerplate - 
and m4 was able to handle that nicely at the cost of lines being 1-1.


HTH

--
Anthony Flury
*Moble*: +44 07743 282707
*Home*: +44 (0)1206 391294
*email*: anthony.fl...@btinternet.com
--
https://mail.python.org/mailman/listinfo/python-list