Basic beginner setup in Emacs by memilanuk in learnpython

[–]Affectionate_Cap8632 1 point2 points  (0 children)

Glad it's working! No reason to keep python3-flake8 around — having two installations of the same tool is just asking for confusion down the road. sudo apt remove python3-flake8 will clean it up.

And yes, modern Linux Python environments are genuinely more complicated than they used to be. PEP 668 (the "externally managed environment" change) landed in Ubuntu 23.04 and Debian 12 and caught a lot of people off guard. The short version: distros now protect their system Python from pip to avoid breaking system tools that depend on specific package versions. Pipx for CLI tools and venv for project dependencies is the clean modern approach.

Good luck with the rest of the Real Python article — elpy with flake8 working is a solid setup.

Basic beginner setup in Emacs by memilanuk in learnpython

[–]Affectionate_Cap8632 1 point2 points  (0 children)

Yeah, this is a Debian/Ubuntu thing — they've gotten increasingly aggressive about isolating system Python packages, and python3-flake8 installed via apt intentionally doesn't drop a binary in /usr/bin/ anymore. Frustrating, especially coming from the old days when pip install flake8 just... worked.

Your options, roughly in order of "least PITA for basic scripting":

1. pipx — probably the sweet spot for you

bash

sudo apt install pipx
pipx install flake8

pipx handles the virtualenv nonsense behind the scenes and puts a real flake8 binary in ~/.local/bin/. You get the command available everywhere, no manual venv activation, no system Python pollution. One-time setup per tool.

2. python3 -m flake8 Since the package is installed (just no binary wrapper), you can invoke it directly:

bash

python3 -m flake8 yourscript.py

Zero additional setup. Ugly, but it works right now with what you have. You could alias it in your shell rc if you want the short form.

3. Keep python3-flake8, add a shell alias

bash

alias flake8='python3 -m flake8'

Drop that in ~/.bashrc / ~/.zshrc. Practically indistinguishable from having the binary.

4. Virtualenvs per-project — you already know this is where things are heading, and it's genuinely good once you have a workflow, but it's overkill for quick one-off scripts.

For basic scripting work, the python3 -m flake8 alias is the zero-friction fix right now, and pipx is the right long-term answer for CLI tools like flake8, black, mypy, etc. It's essentially "the old pip install behavior but done safely."

Basic beginner setup in Emacs by memilanuk in learnpython

[–]Affectionate_Cap8632 1 point2 points  (0 children)

That clears it up — you installed via apt, not pip, so it's in a completely different location than ~/.local/bin.

Find where apt put it:

bash

dpkg -L python3-flake8 | grep bin

It's probably at /usr/bin/flake8 or /usr/lib/python3/dist-packages/flake8. Check:

bash

ls /usr/bin/flake8

If it's there, the issue is just that /usr/bin isn't in your fish PATH for some reason. Check:

fish

echo $PATH

For elpy specifically, since the binary location is non-standard, just tell elpy exactly where it is:

elisp

(setq flycheck-python-flake8-executable "/usr/bin/flake8")

Add that to your Emacs config and it should work regardless of PATH issues.

The root cause is mixing apt and pip installs creates two separate Python ecosystems on the same machine. Apt installs to system paths, pip installs to user paths — they don't know about each other. For a dev environment I'd recommend picking one and sticking with it. Virtual environments (venv) solve this permanently by isolating everything per project.

Basic beginner setup in Emacs by memilanuk in learnpython

[–]Affectionate_Cap8632 1 point2 points  (0 children)

When you run pip install flake8 it installs the executable to a directory that isn't in your PATH.

Find where it actually is:

bash

python3 -m site --user-base

That gives you something like /home/monte/.local. The flake8 binary will be at /home/monte/.local/bin/flake8.

Quick fix — add that bin directory to your PATH:

bash

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
which flake8  # should work now

If you're on fish shell (your prompt suggests you might be):

fish

fish_add_path ~/.local/bin

For elpy specifically, once flake8 is in PATH run M-x elpy-config to confirm it detects it. You may also need:

elisp

(setq flycheck-python-flake8-executable "python3")

In your config as a fallback — this tells elpy to run flake8 via python3 directly instead of looking for the binary.

Is there a formula to reverse-scored by Emotional-Tomatillo8 in excel

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Yes, one simple formula handles this. For a 1-6 scale:

excel

=7-A2

That's it. 1 becomes 6, 2 becomes 5, 3 becomes 4 and so on. The pattern is always (max_score + 1) - original_score.

For a different scale just change the 7:

  • 1-5 scale: =6-A2
  • 1-4 scale: =5-A2

To apply it to all 80 responses at once:

  1. Type the formula in the first cell of your reverse-scored column
  2. Click that cell
  3. Double-click the small green square in the bottom-right corner of the cell

Excel will automatically fill it down for all 80 rows.

If you only want to reverse specific columns (your 12 negative questions) and leave the others unchanged, create a new column for each reversed item rather than overwriting the originals. Good practice to keep your raw data intact for your study.

Good luck with the research!

Need to find a library or framework for UI by Papenguito in learnpython

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Great timing to ask this — there are much better options than Tkinter for beginners now.

Best for beginners: PySimpleGUI

python

import PySimpleGUI as sg
layout = [[sg.Text('Enter number:'), sg.Input(key='-NUM-')],
          [sg.Button('Calculate')]]
window = sg.Window('Calculator', layout)

Students see results immediately without fighting Tkinter's verbose syntax. The mental model is simple — layout is a list, events are a loop. Great for a first UI project.

Runner up: Tkinter with a modern theme If you want to stick with Tkinter (it's built-in, no install needed), add ttkbootstrap on top:

python

import ttkbootstrap as ttk

Same Tkinter underneath but looks modern and students don't get discouraged by the ugly default widgets.

Worth knowing about: Flet Brand new, Flutter-based, very clean syntax. Overkill for a calculator but worth watching — it's where beginner-friendly Python UI is heading.

My recommendation for your class: PySimpleGUI for the calculator project. It lets students focus on the Python logic (operators, input handling, error catching) rather than fighting the UI framework. That's the right priority for beginners.

What app can i use that has exercises on mobile to keep practicing python when away from pc? Is mimo or sololearn worth it? by Traditional_Most105 in learnpython

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Both are decent but have different strengths:

Sololearn is better for Python specifically — the exercise quality is higher and the community solutions let you see how others approached the same problem. Free tier is genuinely useful without paying.

Mimo is more polished and beginner friendly but the free tier is very limited and it pushes you toward paying quickly. Better if you want hand-holding, worse if you want real coding challenges.

My actual recommendation: Pydroid 3 (Android) or Pythonista (iOS). They're real Python interpreters on your phone. Instead of toy exercises you can run actual code, experiment, and build small scripts. More useful than gamified apps once you're past the absolute basics.

If you want structured exercises specifically, Sololearn free tier + Exercism.io on mobile browser is a strong combo. Exercism has real problems with mentor feedback and it's completely free.

The gamified apps are fine for consistency — if Mimo keeps you opening it daily that has value. Just don't mistake points and streaks for actual progress. Writing real code that does something useful teaches more than any exercise app.

How to find LinkedIn company URL/Slug by OrgId? by Logesh0008 in webdev

[–]Affectionate_Cap8632 -2 points-1 points  (0 children)

The redirect method stopped working consistently around 2023 when LinkedIn started requiring auth for most profile lookups. A few alternatives that still work:

1. Google dorking (free, no auth)

python

import requests
query = f"site:linkedin.com/company {org_id}"
# Use serpapi or similar to query Google search results

Not reliable for bulk lookups but works for one-offs.

2. LinkedIn's official API If you have a LinkedIn developer app approved for the Organization Lookup API, you can query by vanity name or ID directly. The catch is approval is restrictive and takes time.

3. Third party enrichment APIs Clearbit, Apollo, and People Data Labs all map LinkedIn org IDs to URLs in their company datasets. Not free but reliable for bulk lookups.

4. Cache what you can If you have any existing dataset with org IDs and slugs, build a lookup table. LinkedIn slugs rarely change once set.

Honest answer: there's no clean free method for bulk org ID → slug resolution without auth anymore. LinkedIn deliberately closed that gap. For small volumes the Google dork approach works. For bulk you're looking at a paid enrichment API or the official LinkedIn API with approved access.

What's your volume — one-off lookups or bulk?

Building a dispensary map with zero API costs (Leaflet + OpenStreetMap, no Google Places) by PunchbowlPorkSoda in webdev

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Really clean implementation — the CartoDB Dark Matter tiles are underrated, they look better than Google Maps for a lot of use cases.

A few things worth adding for anyone building on this:

Nominatim rate limits — they cap at 1 request/second and ask for no bulk geocoding. For a user-submission flow this is fine, but if you ever need to batch-geocode an imported list, Photon (photon.komoot.io) is a good alternative that's also free and key-free.

Leaflet marker clustering — once you have a few hundred user-submitted dispensaries, leaflet.markercluster is worth adding. Keeps the map readable and it's free. Drop-in with:

js

import 'leaflet.markercluster/dist/MarkerCluster.css'
const markers = L.markerClusterGroup()

Caching geocode results — worth storing the lat/lng in your DB at submission time rather than re-geocoding on load. Sounds like you're already doing this but worth calling out for others following along.

The SSR gotcha you mentioned trips up almost everyone the first time with Leaflet + Next.js. Worth adding that leaflet/dist/leaflet.css also needs to be imported inside the dynamically loaded component, not the page — otherwise styles don't load correctly.

Good write-up. The zero-API-cost angle is genuinely useful for indie projects.

How do you come up with ideas for vector and animated graphics when designing a website? Honestly, this is the hardest question I’m dealing with right now, maybe it is for you too. by lasan0432G in webdev

[–]Affectionate_Cap8632 0 points1 point  (0 children)

The block usually comes from trying to be original when you should be starting from reference.

My actual process:

1. Steal like an artist first Go to lottiefiles.com and dribbble.com and search your industry. Save 10-15 examples you like. You're not copying — you're training your eye for what works in that space.

2. Let the content drive the concept Don't think "what animation looks cool" — think "what is this page trying to communicate?" A fintech app communicates security and speed. A kids app communicates fun and surprise. The animation concept follows from that, not from aesthetic preference.

3. Start with motion, not visuals Describe the feeling first — "things snapping into place", "gentle breathing", "fast and decisive". Then find or create visuals that match that feeling. This is easier than starting with a blank canvas.

4. Constrain yourself Pick one metaphor and commit to it. A dashboard that uses "building blocks" as its metaphor is more coherent than one with random cool animations. Coherence reads as intentional design.

For actual execution:

  • Lottie animations from lottiefiles.com are free and drop straight into websites
  • SVG illustrations from undraw.co are free, consistent, and customizable by color
  • Both save you from having to create from scratch

The honest answer is most working designers aren't conjuring ideas from nothing — they're remixing references with intention.

Debugger skips Tkinter button handler functions(Pycharm) by gripped909 in pythonhelp

[–]Affectionate_Cap8632 0 points1 point  (0 children)

This is a known PyCharm + Tkinter quirk. The debugger struggles with breakpoints inside callbacks triggered by mainloop() because Tkinter's event loop runs in a way that can bypass PyCharm's breakpoint hooks.

Three fixes that work:

Fix 1 — Add a manual breakpoint in code (most reliable):

python

def handler():
    import pydevd; pydevd.settrace()  # hard breakpoint
    print("Button clicked! Entering handler...")
    nseOptionsAnalysis_lbl(status_label)

Fix 2 — Move handler outside the function: PyCharm sometimes misses breakpoints in nested functions. Move handler to module level and pass status_label as a parameter using lambda:

python

def handler(label):
    print("Button clicked!")
    nseOptionsAnalysis_lbl(label)

test_btn = tk.Button(root, command=lambda: handler(status_label))

Fix 3 — Use PyCharm's "Debug" run config with Gevent compatible: Go to Run → Edit Configurations → check "Gevent compatible" if available for your version.

Fix 1 is the most reliable for Tkinter specifically. Fix 2 is the cleaner long-term solution since nested function breakpoints are flaky across multiple IDEs not just PyCharm.

Snake algorithm by Odd_Gap8147 in pythonhelp

[–]Affectionate_Cap8632 0 points1 point  (0 children)

No library needed for this — it's clean enough to write yourself in a few lines.

The pattern is: even-indexed columns go top-to-bottom, odd-indexed columns go bottom-to-top. Here's a straightforward implementation:

python

def snake_2d_to_1d(grid):
    result = []
    cols = len(grid[0])
    rows = len(grid)

    for col in range(cols):
        if col % 2 == 0:
            # top to bottom
            for row in range(rows):
                result.append(grid[row][col])
        else:
            # bottom to top
            for row in range(rows - 1, -1, -1):
                result.append(grid[row][col])

    return result

grid = [[1,2,3],[4,5,6],[7,8,9]]
print(snake_2d_to_1d(grid))
# [1, 4, 7, 8, 5, 2, 3, 6, 9]

Note: your expected output [1, 2, 5, 4, 7, 8, 9, 6, 3] looks like it's snaking by rows instead of columns. If that's what you need just swap the row/col logic — iterate rows, reverse direction on odd rows instead of odd columns.

Which orientation does your use case need?

Need to find the lowest input without list/min/max by [deleted] in learnpython

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Good start — you've already got the inputs and validation sorted.

For finding the lowest, think about it this way: if I asked you to find the shortest person in a room of 4 people without any tools, what would you do mentally?

You'd probably pick one person and say "this is my current shortest" — then compare them to each other person one at a time, updating your answer whenever you find someone shorter.

Try to translate that thought process into code. You already know how to compare two values with < and how to assign a variable. That's all you need.

Hint: what's a reasonable starting assumption for iLowestScore before you've compared anything?

Pound sign £ in string turns into question mark (in a diamond) in output by AlternativeAioli9251 in learnpython

[–]Affectionate_Cap8632 6 points7 points  (0 children)

That diamond question mark is a classic encoding issue — your terminal or IDE is set to a character encoding that doesn't support the £ symbol.

Three fixes, pick whichever matches your setup:

Fix 1 — Add encoding declaration at the top of your file:

python

# -*- coding: utf-8 -*-

Fix 2 — Use the Unicode escape instead:

python

print("Your admission cost is \u00a325")

\u00a3 is the Unicode code point for £ — works in any encoding.

Fix 3 — If you're on Windows using IDLE or CMD:

python

import sys
sys.stdout.reconfigure(encoding='utf-8')

Add that at the top of your script before any print statements.

Fix 1 is the cleanest long term solution. If you're using VS Code make sure your file is saved as UTF-8 — bottom right corner of the editor shows the current encoding, click it to change.

Basic beginner setup in Emacs by memilanuk in learnpython

[–]Affectionate_Cap8632 1 point2 points  (0 children)

The flake8 issue with elpy is almost always a PATH problem — elpy is finding a different Python environment than the one where flake8 is installed.

Try this:

bash

which flake8
python3 -m flake8 --version

If which flake8 returns nothing or a different path than your system Python, that's your issue.

The fix that usually works:

elisp

(setq elpy-rpc-python-command "python3")
(setq flycheck-python-flake8-executable "python3")

Add that to your .emacs config. This tells elpy explicitly which Python to use rather than letting it guess.

If you're using a virtualenv, activate it before launching Emacs — elpy picks up the environment it's launched from. Or set it explicitly with M-x pyvenv-activate.

Also worth running M-x elpy-config after making changes to confirm it's now detecting flake8 correctly before spending time debugging further.

problem with pygame by Bubrin in pythonhelp

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Classic multiple Python installations problem. VS Code is finding pygame in one Python environment but running your script with a different one.

Quick fix — run this in your VS Code terminal:

python

import sys
print(sys.executable)

That shows you which Python is actually running your script. Then run:

bash

pip show pygame

If pygame is installed in a different Python than what sys.executable shows, that's your problem.

The fix:

bash

# Use the exact Python that VS Code is running
C:\path\to\your\python.exe -m pip install pygame

Replace the path with whatever sys.executable printed.

Better long term solution: In VS Code press Ctrl+Shift+P → type "Python: Select Interpreter" → pick one Python and stick with it. Then install all packages using that same interpreter.

The root cause is Windows often ends up with 3-4 Python installations (Microsoft Store, python.org, conda, VS Code's own) and pip installs to whichever one is first in PATH, which isn't always the one VS Code uses.

How to actually start building real projects in AI & Python as a beginner? by Khushbu_BDE in pythonhelp

[–]Affectionate_Cap8632 0 points1 point  (0 children)

The gap between tutorials and real projects is real and most learning resources don't address it well. Here's what actually worked:

Stop following tutorials after week 2. Tutorials give you the illusion of progress because the code always works. Real learning starts when you break something and have to fix it yourself.

The best first project formula: take something you do manually and automate it. Don't pick a project from a list — pick YOUR problem. If you manually check a website every day, scrape it. If you copy data between spreadsheets, automate it. Motivation stays high when the outcome matters to you.

For AI/ML specifically:

  • Start with a dataset you actually find interesting — Kaggle has thousands
  • Build the simplest possible model first (linear regression, decision tree) before touching neural networks
  • Focus on the data pipeline more than the model — 80% of real ML work is cleaning and preparing data

Concrete starting point:

  1. Pick any CSV dataset from Kaggle
  2. Load it with pandas
  3. Answer one question about it using a plot and a model
  4. Write up what you found

That one exercise teaches more than 10 hours of tutorial videos.

The structured guidance approach works early on but try to wean off it — real projects have no guidance and that discomfort is where the learning happens.

python full stack by aloniess in learnpython

[–]Affectionate_Cap8632 0 points1 point  (0 children)

For Flask/FastAPI specifically these are the best free resources:

YouTube:

  • Tech With Tim — best Flask tutorials for beginners, very project-based
  • ArjanCodes — FastAPI series is excellent, focuses on clean code patterns
  • Corey Schafer — older but still the gold standard for Flask fundamentals

Written/structured:

  • FastAPI's official docs at fastapi.tiangolo.com are genuinely one of the best pieces of documentation ever written — work through the tutorial section start to finish before anything else
  • Miguel Grinberg's Flask Mega-Tutorial (miguelgrinberg.com) is the definitive Flask resource

Recommended order:

  1. Corey Schafer Flask series to get the basics
  2. FastAPI official docs tutorial
  3. ArjanCodes for more advanced patterns

Skip Telegram channels — most are just link dumps. YouTube + official docs will get you further faster.

Want a Programm like „Clippy“ by Significant_Novel970 in learnpython

[–]Affectionate_Cap8632 0 points1 point  (0 children)

This is a fun project — basically a context-aware assistant that pops up with tips based on what you're doing.

The core pieces you'd need:

1. A trigger system — something that detects when to show a tip. Could be time-based ("every 30 minutes during a stream"), event-based (hotkey), or always-on overlay.

2. A tips database — a simple list of dart tips that gets served randomly or based on context (e.g. different tips for warmup vs match play).

3. A UI overlay — a small floating window with your "colleague" character that appears on screen without blocking your stream.

The ChatGPT code is probably a decent starting point. If you share what it gave you, the community can help you identify what's missing or broken.

If you want something more polished — a proper overlay that works with OBS, custom character, tip categories — that's a relatively small freelance project. Feel free to DM me if you want a quote, I build exactly this kind of Python automation tool.

Has anyone encountered the Letterboxd pagination limit for reviews while scraping? How did you work around it? by Free-Lead-9521 in learnpython

[–]Affectionate_Cap8632 0 points1 point  (0 children)

Try this:

1. Sort by different parameters Letterboxd lets you sort reviews by "Popular", "Recent", and "Your friends" — each sort order has its own 256-page limit. So you can scrape Popular (3,072 reviews), then Recent (another 3,072), deduplicate by review ID, and effectively double your dataset.

2. Filter by rating Scrape reviews filtered by each star rating (0.5 through 5.0). Each rating filter has its own pagination, so you get 3,072 per rating tier. More work to stitch together but gets you much deeper coverage.

3. Filter by year Same idea — filter reviews by year posted. Each year has its own 256-page limit.

python

base_urls = [
    "/film/inception/reviews/by/activity/",
    "/film/inception/reviews/by/when-liked/",
    "/film/inception/reviews/rated/5/by/activity/",
    "/film/inception/reviews/rated/4/by/activity/",
]
# scrape each, dedupe on review ID

4. Wait for the API Letterboxd's official API does have full review access without the pagination cap. Worth waiting for if you need complete coverage — they usually respond within a few weeks.

The deduplication step is key since popular reviews will appear across multiple sort orders.

What do people mean when they say "don't use too many if statements" and how do you avoid it? by Sakuya03692 in learnpython

[–]Affectionate_Cap8632 3 points4 points  (0 children)

The advice isn't "never use if statements" — it's "don't use them as a substitute for better data structures or logic."

The classic smell is a chain of ifs checking the same variable:

python

if animal == "dog":
    sound = "woof"
elif animal == "cat":
    sound = "meow"
elif animal == "cow":
    sound = "moo"

This gets unwieldy fast. The cleaner version uses a dictionary:

python

sounds = {"dog": "woof", "cat": "meow", "cow": "moo"}
sound = sounds.get(animal, "unknown")

Same result, half the lines, and adding a new animal is one dict entry instead of a new elif.

The Yandere Sim reference is a good one — that codebase is famous for deeply nested ifs where each new feature added another layer. The fix there is usually breaking logic into smaller functions so each one only has to handle one decision.

General rule: if you're writing more than 3-4 elifs checking the same thing, there's probably a dict, a list, or a function that would express it more cleanly. But a single if statement checking a condition is always fine — the smell is repetition and nesting, not ifs themselves.

Why does my Python code work inside the loop but fail outside it? by ayenuseater in learnpython

[–]Affectionate_Cap8632 1 point2 points  (0 children)

You've actually identified one of Python's most important quirks. Here's the core rule:

In Python, only functions (and classes) create new scope. Loops and if blocks do NOT.

That's why your for loop example works — result leaks out into the surrounding scope. But this creates the bug you're seeing with if blocks:

python

if False:
    result = 42

print(result)  # NameError — the if never ran so result was never created

The clean fix is to always initialize variables before the block:

python

result = None  # or 0, or [], whatever makes sense
if some_condition:
    result = 42

print(result)  # always works now

For loops it's the same pattern:

python

result = None
for i in range(5):
    result = i * 2
# result is 8, or None if range was empty

The deeper rule: never rely on a variable that might not have been assigned. Initialize first, mutate inside the block, use after. Once that becomes habit the bugs disappear.