Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: using mutable in function defintion as optional paramter
Post: RE: using mutable in function defintion as optiona...

(Yesterday, 04:57 PM)Pedroski55 Wrote: Is there a good reason why we should not pass the dictionary we want modified by name? It's not expected that a function mutates objects from the arguments. Bu...
DeaD_EyE General Coding Help 8 317 9 hours ago
    Thread: if else statements
Post: RE: if else statements

If you want to compare a user-input of equality, but case-insensitive, then lower the user-input and compare it only with the lower variant of the string. ... user_input = input("Do your choice: ") ...
DeaD_EyE General Coding Help 8 3,924 Apr-25-2024, 07:27 AM
    Thread: match case
Post: RE: match case

If you just want to check for types, then do not forget to use parenthesis. Wrong: obj = 42 match obj: case str: print(obj, "is a string") case int: print(obj, "is an int")Er...
DeaD_EyE Code sharing 1 166 Apr-23-2024, 09:53 AM
    Thread: Loop through all files in a directory?
Post: RE: Loop through all files in a directory?

TypeHints are not required, but they help the developers of libraries to communicate what a method/function is expecting and what it should return. Quote:What I don't like with the pathlib solution i...
DeaD_EyE General Coding Help 10 439 Apr-23-2024, 09:14 AM
    Thread: Loop through all files in a directory?
Post: RE: Loop through all files in a directory?

Use Path from pathlib module. This is the modern way to handle paths. Mostly all methods, which are functions in os and os.path for path handling, are attached to the Path object. Some are missing, b...
DeaD_EyE General Coding Help 10 439 Apr-22-2024, 07:17 PM
    Thread: A function that checks if the list is sorted
Post: RE: A function that checks if the list is sorted

The useful function itertools.pairwise was added to Python 3.10. https://docs.python.org/3/library/iterto...s.pairwise This isn't Pythonic: range(len(something)) from itertools import pairwise fro...
DeaD_EyE Homework 16 16,624 Apr-22-2024, 09:14 AM
    Thread: yield from
Post: RE: yield from

# removed the * in front of iterables print("Definition of generator-function") def join(iterables, joiner): print("First step of generator") # spliting iterable in first iterable and the re...
DeaD_EyE General Coding Help 4 310 Apr-19-2024, 07:58 PM
    Thread: Waiting for input from serial port, then move on
Post: RE: Waiting for input from serial port, then move ...

(Apr-17-2024, 06:45 AM)feistycavities Wrote: The issue with your while loop not closing is because you have an embedded for loop in your code. The cause was the condition of while. In the code there...
DeaD_EyE General Coding Help 3 1,106 Apr-17-2024, 07:21 AM
    Thread: python calculate float plus float is incorrect?
Post: RE: python calculate float plus float is incorrect...

I don't know what PHP does to prevent the visible inaccuracy. In modern programming languages, you don't see the real floating point value inclusive PHP. An algorithm is used, to show the user a nic...
DeaD_EyE General Coding Help 6 319 Apr-16-2024, 01:45 PM
    Thread: Need to get around SSL: CERTIFICATE_VERIFY_FAILED
Post: RE: Need to get around SSL: CERTIFICATE_VERIFY_FAI...

I do not have this problem. I was able to connect to api.polygon.io:443 on Windows 11 with Python 3.12.2 x64. btw. Python 3.12.3 is out import socket import ssl addr = ("api.polygon.io", 443) ctx ...
DeaD_EyE General Coding Help 3 259 Apr-16-2024, 07:50 AM
    Thread: Hide CMD call window
Post: RE: Hide CMD call window

windows ... import subprocess def arp(): """ Run arp -a and return the stripped output. Window creation is prevented. """ flags = subprocess.CREATE_NO_WINDOW return sub...
DeaD_EyE General Coding Help 8 323 Apr-15-2024, 08:56 PM
    Thread: How do I parse the string?
Post: RE: How do I parse the string?

If you need a path, a Path object is maybe what you want. Code is based on Gribouillis example: from urllib.parse import urlparse from pathlib import PurePosixPath def url2path(url: str) -> Pure...
DeaD_EyE General Coding Help 4 347 Apr-10-2024, 10:26 AM
    Thread: Next/Prev file without loading all filenames
Post: RE: Next/Prev file without loading all filenames

Here as a class with type hints. mypy does not complain :-) This loads the whole directory content for the first time, and then only if the sort_function has been changed. The __init__ method makes th...
DeaD_EyE General Coding Help 9 600 Apr-08-2024, 07:58 AM
    Thread: a better way to code this to fix a URL?
Post: RE: a better way to code this to fix a URL?

If the url should always start with https even, if only a hostname is given, you could use this: from urllib.parse import urlsplit, urlunsplit def conv2(url): return urlunsplit(("https", *urlsp...
DeaD_EyE News and Discussions 10 777 Mar-19-2024, 09:15 AM
    Thread: list.sort() returning None
Post: RE: list.sort() returning None

(Mar-18-2024, 10:39 AM)Pedroski55 Wrote: **smile** **smile** **smile** Dead_EyE: a very accurate shooter (and reader?) Quote:You can also use the list.sort() method. It modifies the list in-pla...
DeaD_EyE General Coding Help 8 610 Mar-18-2024, 08:16 PM
    Thread: Anyway to stop a thread and continue it?
Post: RE: Anyway to stop a thread and continue it?

Example with a queue: import time from random import randint from queue import Queue from threading import Thread def fake_feed(): """ Generator function which yields endless values fro...
DeaD_EyE General Coding Help 2 352 Mar-18-2024, 10:53 AM
    Thread: Request for Feedback: Python Website Accessibility
Post: RE: Request for Feedback: Python Website Accessibi...

Contact python.org Buzzwords: Accessibility, Inclusiveness Perhaps the reference to this document will help to speed up the procedure **lol** : https://eur-lex.europa.eu/legal-content/...02&from...
DeaD_EyE News and Discussions 2 402 Mar-18-2024, 10:29 AM
    Thread: list.sort() returning None
Post: RE: list.sort() returning None

There is no mention in the Documentation, that this method return a None. But, it returns None and sorts the list in-place. I guess the expectation comes from str. The str methods always return a new...
DeaD_EyE General Coding Help 8 610 Mar-18-2024, 10:20 AM
    Thread: class and runtime
Post: RE: class and runtime

(Mar-15-2024, 08:02 AM)akbarza Wrote: can explain this statement? what is the importance of the creation of a class in runtime? how can a class be modified after creation? This is not possible with ...
DeaD_EyE General Coding Help 4 400 Mar-15-2024, 10:25 AM
    Thread: MCU reboots after opening Serial port when ran from Raspberry PI
Post: RE: MCU reboots after opening Serial port when ran...

(Mar-15-2024, 09:25 AM)zazas321 Wrote: However, the device that I am connecting to reboots. When I try to do this via my Windows machine, it does not reboot. Perhaps anyone know why this could be th...
DeaD_EyE General Coding Help 3 454 Mar-15-2024, 10:13 AM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020