[winreg] How to access "(Default)" key value?
Hello, I am encountering an issue with winreg, I can't figure out how to read the "(Default)" of a registry value ``` def get_chrome_version() -> str: with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as registry: with winreg.OpenKeyEx(registry, r"Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", access=winreg.KEY_READ) as key: value, _ = winreg.QueryValueEx(key, "(default)") return value ``` Taking the example above it raises a FileNotFoundError : ``` Traceback (most recent call last): File "C:/Users/noulo/dev/py/chromedriver_dl/main.py", line 14, in get_chrome_version value, _ = winreg.QueryValueEx(key, "(default)") FileNotFoundError: [WinError 2] The system cannot find the file specified ``` (Trying "Path" instead of "(Default)" works) Although the value definitely exists as shown by Powershell ``` Get-Item -Path "HKCU:/Software/Microsoft/Windows/CurrentVersion/App Paths/chrome.exe" | Select-Object -ExpandProperty Property ``` Returns : ``` (default) Path ``` Is this a bug I should report, or if not, what is the way, using winreg, to access the "(Default)" value of a key? Regards, Nicolas FORMICHELLA -- https://mail.python.org/mailman/listinfo/python-list
Re: Match.groupdict: Meaning of default argument?
r...@zedat.fu-berlin.de (Stefan Ram) writes: > "Loris Bennett" writes: >>I thought that 'days' would default to '0'. > > It will get the value '0' if (?P\d*) does > /not/ participate in the match. > > In your case, it /does/ participate in the match, > \d* matching the empty string. > > Try (?P\d+)?. Ah, thanks. I was misunderstanding the meaning of 'participate'. Cheers, Loris -- This signature is currently under construction. -- https://mail.python.org/mailman/listinfo/python-list
Re: Match.groupdict: Meaning of default argument?
Julio Di Egidio writes: > On Friday, 29 April 2022 at 09:50:08 UTC+2, Loris Bennett wrote: >> Hi, >> >> If I do >> >> import re >> pattern = >> re.compile(r'(?P\d*)(-?)(?P\d\d):(?P\d\d):(?P\d\d)') >> s = '104-02:47:06' >> match = pattern.search(s) >> match_dict = match.groupdict('0') >> >> I get >> >> match_dict >> {'days': '104', 'hours': '02', 'minutes': '47', 'seconds': '06'} >> >> However, if the string has no initial part (corresponding to the number of >> days), e.g. >> >> s = '02:47:06' >> match = pattern.search(s) >> match_dict = match.groupdict('0') >> >> I get >> >> match_dict >> {'days': '', 'hours': '02', 'minutes': '47', 'seconds': '06'} >> >> I thought that 'days' would default to '0'. >> >> What am I doing wrong? > > You tell, but it's quite obvious that you (just) run a regex on a string and > captures are going to be strings: indeed, '02' is not a number either... > > Julio I am not sure what you are trying to tell me. I wasn't expecting anything other than strings. The problem was, as Stefan helped me to understand, that I misunderstood what 'participating in the match' means. Cheers, Loris -- This signature is currently under construction. -- https://mail.python.org/mailman/listinfo/python-list
Re: Match.groupdict: Meaning of default argument?
"Loris Bennett" writes: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> "Loris Bennett" writes: >>>I thought that 'days' would default to '0'. >> >> It will get the value '0' if (?P\d*) does >> /not/ participate in the match. >> >> In your case, it /does/ participate in the match, >> \d* matching the empty string. >> >> Try (?P\d+)?. > > Ah, thanks. I was misunderstanding the meaning of 'participate'. What I actually need is ((?P\d+)(-?))?(?P\d\d):(?P\d\d):(?P\d\d) so that I can match both 99-11:22:33 and 11:22:33 and have 'days' be '0' in the later case. Thanks for pointing me in the right direction. Cheers, Loris -- This signature is currently under construction. -- https://mail.python.org/mailman/listinfo/python-list
Re: [winreg] How to access "(Default)" key value?
On 2022-05-03 10:31, Nicolas Formichella wrote: Hello, I am encountering an issue with winreg, I can't figure out how to read the "(Default)" of a registry value ``` def get_chrome_version() -> str: with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as registry: with winreg.OpenKeyEx(registry, r"Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", access=winreg.KEY_READ) as key: value, _ = winreg.QueryValueEx(key, "(default)") return value ``` Taking the example above it raises a FileNotFoundError : ``` Traceback (most recent call last): File "C:/Users/noulo/dev/py/chromedriver_dl/main.py", line 14, in get_chrome_version value, _ = winreg.QueryValueEx(key, "(default)") FileNotFoundError: [WinError 2] The system cannot find the file specified ``` (Trying "Path" instead of "(Default)" works) Although the value definitely exists as shown by Powershell ``` Get-Item -Path "HKCU:/Software/Microsoft/Windows/CurrentVersion/App Paths/chrome.exe" | Select-Object -ExpandProperty Property ``` Returns : ``` (default) Path ``` Is this a bug I should report, or if not, what is the way, using winreg, to access the "(Default)" value of a key? Use 'QueryValue' with an empty string: value = winreg.QueryValue(key, "") or None: value = winreg.QueryValue(key, None) -- https://mail.python.org/mailman/listinfo/python-list
python 3.9.12 and python 3.10
Date: Tue, 3 May 2022 19:59:08 +0100 Subject: python 3.9.12 and python 3.10 I installed 3.9 and am able to enter simple code which runs. If I type an error I can highlight it but cannot copy or delete it. I looked for help & found 3.10 and installed it but when I selected the python icon 3.9 appeared with my old errors. I uninstalled 3.10 as 3.9 did not appear in control panel. Dell Inspiron 3793 Win 10 Thanks Dave Francis -- https://mail.python.org/mailman/listinfo/python-list
Re: Difference in Setup Between Windows 10 Running Python 3.9 and Windows 11 Running Python 3.10
On 5/1/22, Brent Hunter wrote: > > I was recently running a Windows 10 machine Python 3.9. I simply created a > batch file titled "Start-AIG.bat" which simply contained the following: > "pythonw AIG.py". It started a python program titled "AIG.py" and the > Python dialog box was displayed on my screen, running all day and night. I > set up Windows to run this batch file upon startup and it worked fine. I > remember having to do a bunch of research before I learned that I needed to > put "pythonw AIG.py" in the batch file as opposed to "python AIG.py". When running a command at startup, it's best to use the full path of the application and the full path of any files passed on the command line. For example, run something like the following: "path\to\pythonw.exe" "path\to\AIG.py" This removes any dependency on the search PATH or the current working directory. Also, the script shouldn't depend on the initial working directory. Any files that it needs should be in a well-known location, such as the script directory, os.path.dirname(os.path.abspath(__file__)). Also, there's no need to use a batch script just to run a single command. When you use a batch script, a visible console gets created for CMD. It doesn't close until CMD exits, which in this case won't be until pythonw.exe exits, unless you use `START` to run the command without waiting. It's simpler to just run the command directly using a shortcut (i.e. LNK file) or the task scheduler. -- https://mail.python.org/mailman/listinfo/python-list