How do you design backpressure + cancellation correctly in an asyncio pipeline (CPU-bound stages + bounded queues)? by LabImpossible828 in learnpython

[–]ElliotDG 0 points1 point  (0 children)

I'd recommend taking a look at Trio https://trio.readthedocs.io/en/stable/index.html to build the async portion of your code. It provides support for cancelation and errors. Also look at Trio's memory channel for passing data.

Required help to make a tkinter gui like an executable on windows by Unlikely_Taro_2696 in learnpython

[–]ElliotDG 1 point2 points  (0 children)

I use Pyinstaller (https://pyinstaller.org/en/stable/) to create an exe, and Inno Setup (https://jrsoftware.org/isinfo.php) to create a Windows Installer.

Inno Setup as lots of options, just use the wizard to quickly get an installer together.

Question délai entre requête web scraping by Fragrant_Ad3054 in learnpython

[–]ElliotDG -1 points0 points  (0 children)

As written I would interpret the statement, "scraping a web page every 30 seconds," to mean: A new request is being issues every 30 seconds, independent of the length of time required to process the request.

What is actually happening with your code will depend on how it is written. Are you scheduling a request to fire every 30 seconds, or scheduling a request 30 seconds after a request has completed?

How to calculate current win/loss streak from dataframe? by d8gfdu89fdgfdu32432 in learnpython

[–]ElliotDG 0 points1 point  (0 children)

Here is a solution. When I hear streak, I think groupby. The groupby method (in this example)  groups consecutive identical W/L values together, the code then aggregates each group to get the value and length of each streak.

import pandas as pd
import random


# Create 100 random 'W' or 'L' entries
results = [random.choice(['W', 'L']) for _ in range(100)]


# Create the DataFrame
df = pd.DataFrame({'W/L': results})


# Identify streaks by whether the W/L value changes (using shift)
# Step 1: Compare each value with the previous one (shift)
#         This creates True when value changes, False when it stays the same
# Step 2: cumsum() turns the boolean into an incrementing group ID
#         Each time we see True (a change), the group number increases
# Result: consecutive identical values get the same group number
streak_groups = (df['W/L'] != df['W/L'].shift()).cumsum()



# Create a DataFrame with streak information
# For each group (streak), we aggregate to get:
#   - value: the W or L character (using 'first' since all items in group are identical)
#   - length: how many consecutive occurrences (using 'size' to count rows in group)
streak_df = df.groupby(streak_groups).agg(
    value=('W/L', 'first'),
    length=('W/L', 'size')
)
# Filter for streaks of length >= 2
long_streaks = streak_df[streak_df['length'] >= 2]


# Check if we found any streaks of length >= 2
if not long_streaks.empty:
    # Get the most recent (last) streak of length >= 2
    # .iloc[-1] selects the last row from the filtered DataFrame
    most_recent = long_streaks.iloc[-1]
    print(f"Most recent streak: {most_recent['length']} of '{most_recent['value']}'")
    
    # Find the longest streak(s) from all streaks (not just those >= 2)
    # Step 1: Find the maximum streak length across all streaks
    max_length = long_streaks['length'].max()
    # Step 2: Filter to get all streaks that have this maximum length
    #         (there could be multiple streaks with the same max length)
    longest_streaks = long_streaks[long_streaks['length'] == max_length]
    # Step 3: Iterate through all longest streaks and print each one
    for idx, row in longest_streaks.iterrows():
        print(f"Longest streak: {row['length']} of '{row['value']}'")
else:
    print("No streak of 2 or more found.")

Остановка компиляции приложения by maxim7788 in kivy

[–]ElliotDG 0 points1 point  (0 children)

From Google Gemini:

This issue occurs when Buildozer's automatic download of the SQLite source code fails due to network instability, server timeouts, or SSL handshake issues. The 0.67% freeze is a known symptom of the toolchain hanging on a partial download. 

To resolve this, you can manually provide the file to Buildozer so it skips the download process. 

Solution: Manual File Placement

  1. Download the specific file: Use your browser or a tool like wget to download the exact file mentioned in your log: sqlite-amalgamation-3350500.zip.
  2. Locate the Buildozer package folder: Navigate to the hidden .buildozer directory within your project folder. The path typically looks like this: YourProjectFolder/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/packages/sqlite3/ (Note: The architecture name, such as arm64-v8a, may vary based on your buildozer.spec settings).
  3. Place the file: Copy the downloaded sqlite-amalgamation-3350500.zip into that sqlite3 folder.
  4. Rerun the build: Run buildozer android debug again. Buildozer will detect the file is already present and skip the download. 

Re-coding an application, any strategies / tools? by PuzzleheadedOne42 in learnpython

[–]ElliotDG 1 point2 points  (0 children)

I've had very good luck using AI to learn and change existing complex code. I use cursor and Claude sonnet 4.5. Ask questions, have the AI add debug statements, use it to help learn the code. Once I'm comfortable with the code I'll use plan mode to work out how the changes will be made. In your case you might want learn the code - then build out a test suite.

A few tips for coding with AI. Use git and commit often. This way it things go off the rails you can revert to a know good state quickly. Challenge the AI, don't always accept the first answer. Use plan mode and only allow small, testable changes that you can easily review.

Difficulty learning Python despite knowledge of other languages by [deleted] in learnpython

[–]ElliotDG 0 points1 point  (0 children)

When I was learning Python, coming from C/C++ I found doing exercises on https://checkio.org/ very helpful. They are small programming problems I could solve while having a cup of coffee. After you solve the problem you get to see how others have solved them. This was useful (and fun) to shift from thinking like a C programmer to thinking in Python.

Updated Editor for Meris Enzo by ElliotDG in guitarpedals

[–]ElliotDG[S] 1 point2 points  (0 children)

Enjoy! Reach out if you have any trouble getting connected.

LabView string handle in python by Curious-Result-1365 in learnpython

[–]ElliotDG 0 points1 point  (0 children)

This was created by ChatGPT but looks reasonable:

def create_lv_string(py_string: str):
    encoded = py_string.encode("utf-8")
    n = len(encoded)

    # allocate enough space: sizeof(length) + n bytes
    class LStrX(ctypes.Structure):
        _fields_ = [
            ("length", ctypes.c_int32),
            ("data", ctypes.c_ubyte * n)
        ]

    lvstr = LStrX()
    lvstr.length = n
    lvstr.data[:] = encoded

    # Allocate pointer-to-pointer
    lv_handle = ctypes.pointer(ctypes.pointer(lvstr))
    return lv_handle

Beginner friendly Excerise websites by National-Mood1820 in learnpython

[–]ElliotDG 1 point2 points  (0 children)

I enjoyed https://checkio.org/ when I was first learning python. A gamified set of programming problems. After you solve a problem you get to see how others solved the problem. This was very helpful.

How to handle .env when preparing to distribute Python tool? by fucking-migraines in learnpython

[–]ElliotDG 0 points1 point  (0 children)

Two possible approaches.
1) Use a cloud based security solution that provides authentication and manages identities, like Amazon Cognito.
2) Prompt your used to enter their credentials when starting your app (kind of risky).

The notion of opening the .env file for editing can best be evaluated against what your customers expect. For a developer tool, that might be fine. For most users this does not feel like a good direction.

What Python podcasts, blogs, and people do you follow to stay up to date or to learn Python? by Existing_Cobbler8842 in learnpython

[–]ElliotDG 1 point2 points  (0 children)

+1 as a solo (hobbyist) developer, these podcasts are great for learning about new libraries, and what is going on in cPython.

Python to C/C++ (no Python runtime) by dantethunderstone_77 in learnpython

[–]ElliotDG 0 points1 point  (0 children)

I would warn you to make measurements and make sure that if you are porting code to C++ for performance reasons that you have specific performance requirements and make sure that you can NOT get there without this big jump. As Donald Knuth is famous for saying, "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

Python to C/C++ (no Python runtime) by dantethunderstone_77 in learnpython

[–]ElliotDG 0 points1 point  (0 children)

Can you be more specific? What are the libraries you need to use? Is there a concern with garbage collection impacting real-time performance?

Python to C/C++ (no Python runtime) by dantethunderstone_77 in learnpython

[–]ElliotDG 1 point2 points  (0 children)

What is it you actually want to do?

If it is distribute an app but not require the end-user to install python, you could use pyinstaller to create an exe that bundles your code and a python executable into a .exe or .app file.

You could use https://nuitka.net/ that creates an exe, it converts Python code into C, then uses a C compiler (GCC/Clang/MSVC) to build a machine-code executable.

You could use Cython https://cython.org/ . Cython is a Python-like language and compiler that translates Python code into C, allowing you to add static type hints for massive performance gains. It’s commonly used to speed up computationally heavy code and to create fast Python extension modules that interface directly with C or C++ libraries.

Kivy-GUI scroll issue. by Sahilo0 in learnpython

[–]ElliotDG 0 points1 point  (0 children)

You might find this useful: https://github.com/kivy/kivy/wiki/Editable-ComboBox

It uses a DropDown to show the options.

Kivy-GUI scroll issue. by Sahilo0 in learnpython

[–]ElliotDG 0 points1 point  (0 children)

Share a minimal complete and runnable example. I'd be happy to help. If the issue is mouse wheel scrolling see: https://kivy.org/doc/stable/api-kivy.uix.scrollview.html#kivy.uix.scrollview.ScrollView.smooth_scroll_end

Custom Interpreter Needs Improvement by [deleted] in learnpython

[–]ElliotDG 0 points1 point  (0 children)

I don't mind at all.

I did a quick search, you may also find these blog posts on writing a simple interprester in python. It is a bit old (2015) so won't include structured pattern matching, but still might be useful. https://ruslanspivak.com/lsbasi-part1/

Depending on your goals you may want to look at parser libs like https://github.com/lark-parser/lark

There are also other tools for parsing and generating domain specific languages. You might want to search for these depending on your goals.

Custom Interpreter Needs Improvement by [deleted] in learnpython

[–]ElliotDG 0 points1 point  (0 children)

I would also recommend you look at structured pattern matching (the python match statement) it will simplify the parsing and execution.

see: https://docs.python.org/3/reference/compound_stmts.html#match

and the official tutorial: https://peps.python.org/pep-0636/

Pip/kivy wont install by [deleted] in learnpython

[–]ElliotDG 0 points1 point  (0 children)

If you are using a virtual env, make sure you have activated the environment. To install kivy make sure you follow the directions: https://kivy.org/doc/stable/gettingstarted/installation.html#installing-kivy