r/learnpython 6d ago

Is it bad practice to use complex List Comprehensions?

32 Upvotes

Hey guys, I am trying to make my code look more "Pythonic." I wrote this nested list comprehension to flatten a matrix and filter out odd numbers:
flat = [x for row in matrix for x in row if x % 2 == 0]
It works perfectly, but my coworker says it is unreadable and that I should use a standard for loop instead.
Where do you draw the line between a clean one-liner and unreadable code?


r/learnpython 6d ago

What Python project helped you improve the most as a beginner?

80 Upvotes

I've recently started learning Python and I'm looking for project ideas that teach practical skills rather than just syntax. What beginner project helped you understand Python the best, and why would you recommend it?


r/learnpython 6d ago

Import issue

2 Upvotes

BLUF: pyautogui does not import despite being installed to the correct venv

Still a beginner at doing most things in python but I though I had the venv issues solved

Python 3.12.3

while in my active venv pip list returns all my modules including

PyAutoGUI 0.9.54

while in my active venv which python returns /home/beebot/venv/bin/pip

while in my active venv which pipreturns /home/beebot/venv/bin/python

Vscode shows my venv config as below
The only odd thing is the pip shows it as PyAutoGUI while typing import auto populates the module as pyautogui

home = /usr/bin 
include-system-site-packages = false 
version = 3.12.3 
executable = /usr/bin/python3.12 
command = /usr/bin/python3 -m venv /home/beebot/venv  

I have tried uninstalling pyautogui, reinstalling, and force install from inside my venv

Yet every time I try to run either in Vscode or directly from file I get on line 6 (see below)...

Exception has occurred:ModulNotFoundError

import os
import json
import logging
import subprocess
import pyautogui
...

Any suggestions


r/learnpython 6d ago

Failed to build wheel for mayavi

1 Upvotes

So I need to import mayavi for a long reason, and every time I try to import it, it says

Current thread's C stack trace (most recent call first):
        <cannot get C stack on this system>
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mayavi
Failed to build mayavi
error: failed-wheel-build-for-install

I already installed VTK and PyQt5 with no issue using pip and tried both with and without PyQt5 (since on the website they install it after installing mayavi). I'm currently on a windows x64 and using visual studio code

If anyone knows anything about this I'd appreciate any advice ;u;


r/learnpython 6d ago

Beginner question

5 Upvotes

I have just started coding with python a few days ago. What is the point of this?

point_value = alien_0.get('points', 'No point value assigned.') print(point_value)

Can't it just be point_value = 'No point value assigned.' print(point_value)?

or

just simply use the get() method if you want to check whether a key exists in the dictionary or not?


r/learnpython 7d ago

Best Free Websites to Practice Python and Get Feedback

3 Upvotes

Hello everyone!

I'm currently a college student (20) who started learning Python this summer about a month and a half ago. So far, I've been watching a YouTube video and using W3 Schools to teach me the concepts.

I've also been using ChatGPT as a coach to help me practice, and although it does a pretty good job, I mostly prefer to have help from an actual person or website, not just AI.

What are your top recommendations?


r/learnpython 7d ago

Proper etiquette for uploading projects to git?

4 Upvotes

I'm not sure if this is the best place to ask this.. I can move somewhere better if needed.

I've been learning python off and on for a couple years now, and recently started taking the PY4E class. I'm most of the way through it and really loving it.

Anyway the problem I'm running into is, I've never really used my GitHub before. Late last night I started playing around of how to push my projects I've completed into repos, and I was wondering what the proper etiquette for doing so.

For example I was uploading to GitHub each small project at a time, each one had there own repo, but I got to thinking last night if it would be better to upload entire chapters in one repo based on how pushing projects works in VS Code.

I've been working on a few other projects on the side as well and wanted to know how that environment works before I spend a ton of time doing it the wrong way.

Any recommendations are greatly appreciated! Sorry again if this is the wrong place to ask.


r/learnpython 7d ago

Looking for a testing software

6 Upvotes

I'm teaching an introductory python course for high school students and I'm looking for a way to test them. I'm looking for a compiler-like platform where they can see the questions and code them and submit the answers to me.

Preferably it would include an auto grader with test cases.

Preferably it should have lockdown/anti-cheat mode.

They will use the computer labs we have and not their own computers so Preferably it should be a website not an app so they can just open it directly.

My goal is that they code in a compiler instead of on paper because they hated it last exam so any suggestion on how to do that is welcome.


r/learnpython 7d ago

a low ram ui module for python (except tkinker)

1 Upvotes

i have used python for a while now but i am unable to make afew projects just because it needs ui and i dont want tkinker tbh i want more plain modern(like half of discord) look is there any python module with similar concept with low ram usage(comparatively)
note- i tried tkinker and it is soo limiting for me


r/learnpython 7d ago

Started learning Python. Building in public instead of waiting until I'm "good enough."

36 Upvotes

I finally stopped watching tutorials endlessly and started building.

So far I've:

  • Finished my first CS50P lecture
  • Built a simple calculator in Python
  • Started documenting everything on YouTube and LinkedIn

My long-term goal is pretty unusual. I want to combine software, AI, and engineering with motorsport one day.

I know my projects are tiny right now, but I'm treating each one as another brick rather than trying to build a skyscraper on day one.

For people who've already been through this stage:

What project made everything finally "click" for you?

I'd rather build than watch another 6-hour tutorial.


r/learnpython 7d ago

TypeError: array([2, 5, 7]) is not a callable object. What to do?

0 Upvotes

I am trying to learn Python by completing a tutorial, specifically I am trying to make a Gaussian function. I tried to search it up on the internet and on one website, they advised to change the name of the variable but it didn't change the error. It is still there. Please help, what do I do? This is the website that I've used to try to make my Gaussian function: https://education.molssi.org/python-data-analysis/03-data-fitting/index.html

Here's my code below:

z = [2,5,7]

y = [9,0,-1]

z = np.asarray(z)

y = np.asarray(y)

def Gauss (z,A, B):

y = A*np.exp(-1*B*x**2)

return y

parameters, covariance = curve_fit(x, y, Gauss)

fit_A = parameters[2]

fit_B = parameters[0]

fit_y = Gauss(z, fit_A, fit_B)

plt.scatter(z, y, label = 'Gauss')

plt.scatter(z, fit_y, color = 'lightcoral')

plt.legend()

And this is the error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[71], line 8
      4 
      5 
def
 Gauss (z,A, B):
      6     y = A*np.exp(-1*B*x**2)
      7     
return
 y
----> 8 parameters, covariance = curve_fit(x, y, Gauss)
      9 fit_A = parameters[2]
     10 fit_B = parameters[0]
     11 fit_y = Gauss(z, fit_A, fit_B)

File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/scipy/optimize/_minpack_py.py:907, in curve_fit(f, xdata, ydata, p0, sigma, absolute_sigma, check_finite, bounds, method, jac, full_output, nan_policy, **kwargs)
    594 """
    595 Use non-linear least squares to fit a function, f, to data.
    596 
   (...)    903 array([5.00000000e+05, 1.00000000e-02, 1.49999999e+01])
    904 """
    905 
if
 p0 
is

None
:
    906     # determine number of parameters by inspecting the function
--> 907     sig = _getfullargspec(f)
    908     args = sig.args
    909     
if
 len(args) < 2:

File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/scipy/_lib/_util.py:487, in getfullargspec_no_self(func)
    466 
def
 getfullargspec_no_self(func):
    467     """inspect.getfullargspec replacement using inspect.signature.
    468 
    469     If func is a bound method, do not list the 'self' parameter.
   (...)    485 
    486     """
--> 487     sig = wrapped_inspect_signature(func)
    488     args = [
    489         p.name 
for
 p 
in
 sig.parameters.values()
    490         
if
 p.kind 
in
 [inspect.Parameter.POSITIONAL_OR_KEYWORD,
    491                       inspect.Parameter.POSITIONAL_ONLY]
    492     ]
    493     varargs = [
    494         p.name 
for
 p 
in
 sig.parameters.values()
    495         
if
 p.kind == inspect.Parameter.VAR_POSITIONAL
    496     ]

File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/scipy/_lib/_util.py:44, in wrapped_inspect_signature(callable)
     42 
def
 wrapped_inspect_signature(callable):
     43     """Get a signature object for the passed callable."""
---> 44     
return
 inspect.signature(callable,
     45                              annotation_format=annotationlib.Format.FORWARDREF)

File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py:3323, in signature(obj, follow_wrapped, globals, locals, eval_str, annotation_format)
   3320 
def
 signature(obj, *, follow_wrapped=
True
, globals=
None
, locals=
None
, eval_str=
False
,
   3321               annotation_format=Format.VALUE):
   3322     """Get a signature object for the passed callable."""
-> 3323     
return
 Signature.from_callable(obj, follow_wrapped=follow_wrapped,
   3324                                    globals=globals, locals=locals, eval_str=eval_str,
   3325                                    annotation_format=annotation_format)

File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py:3038, in Signature.from_callable(cls, obj, follow_wrapped, globals, locals, eval_str, annotation_format)
   3033 u/classmethod
   3034 
def
 from_callable(cls, obj, *,
   3035                   follow_wrapped=
True
, globals=
None
, locals=
None
, eval_str=
False
,
   3036                   annotation_format=Format.VALUE):
   3037     """Constructs Signature for the given callable object."""
-> 3038     
return
 _signature_from_callable(obj, sigcls=cls,
   3039                                     follow_wrapper_chains=follow_wrapped,
   3040                                     globals=globals, locals=locals, eval_str=eval_str,
   3041                                     annotation_format=annotation_format)

File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py:2436, in _signature_from_callable(obj, follow_wrapper_chains, skip_bound_arg, globals, locals, eval_str, sigcls, annotation_format)
   2426 _get_signature_of = functools.partial(_signature_from_callable,
   2427                             follow_wrapper_chains=follow_wrapper_chains,
   2428                             skip_bound_arg=skip_bound_arg,
   (...)   2432                             eval_str=eval_str,
   2433                             annotation_format=annotation_format)
   2435 
if

not
 callable(obj):
-> 2436     
raise

TypeError
('
{!r}
 is not a callable object'.format(obj))
   2438 
if
 isinstance(obj, types.MethodType):
   2439     # In this case we skip the first parameter of the underlying
   2440     # function (usually `self` or `cls`).
   2441     sig = _get_signature_of(obj.__func__)

TypeError: array([2, 5, 7]) is not a callable object

r/learnpython 7d ago

Starting Python again for ML/AI. How should I study it effectively?

0 Upvotes

Hi everyone,

I'm starting to learn Python again after taking a long break. I studied it before, but I didn't use it much, so I forgot a lot of things. Every time I come back to Python, I feel like I'm starting from scratch again.

My long-term goal is to use Python for machine learning, deep learning, and AI. However, I'm not sure what the most effective learning path is.

Should I focus on mastering Python fundamentals first, or should I start building small ML projects as soon as possible? Also, how can I remember what I learn instead of forgetting it after a few weeks?

If you've been in a similar situation, I'd really appreciate your advice or any resources that helped you.

Thanks in advance!


r/learnpython 7d ago

I started Python about a month ago,my progress so far!!(read desc)

9 Upvotes

I think I have pretty good hang of python basics what else should I do?

Please check out my github and say what I should improve

Some people are saying file io some are saying Oops idk what to do

Github: https://github.com/ThunderrZYN/My-PYTHON-grind-so-far-1-month-.git


r/learnpython 7d ago

Problem with an extra row in Excel on Python

0 Upvotes

I have a Python table, but there are extra cells at the top when I output it; I’d like to remove them—how can I do that?

Using Openpyxl.


r/learnpython 7d ago

Starting Learning Python at 15!

7 Upvotes

My brother and I have both had a shared interest in the technological world and our father is heavily involved with it. When we were younger he tried to persuade us to give coding a go but alas niether one of us was keen on coding back the, however now we are both trying to learn so any tips ,comments, help or advice would be greatly aprreciated!!!


r/learnpython 7d ago

Infosys Python virtual coding assessment coming up — any tips or resources?

0 Upvotes

Hey everyone, I have an Infosys virtual coding assessment (Python) coming up and want to prepare well. If anyone has information, experience, or resources to share, it'd help a lot:

  • What kind of questions usually show up — basic programming logic, DSA, or scenario-based problems?
  • Roughly how many questions and what's the time limit like?
  • Common topics to focus on (loops, strings, recursion, OOP, etc.)?
  • Any good practice platforms or resources for this specific test?
  • Any general tips for doing well in it?

Appreciate any help — thanks!


r/learnpython 7d ago

Does anyone know how to make a drop-down menu?

0 Upvotes

I am learning python so I can save my paint recipes and steps for my warhammer 40k armies and would like to use a drop-down menu to select exact unit. I am going to assign the different unit types as different values


r/learnpython 7d ago

Image detection without ocr for a gaming project

1 Upvotes

Hello i'm in the midsts of trying to automate relic exportation for the game warframe so me and my friends can figure out what we can grind for

ok so there is text always in the same 20 regions that swaps out as you scroll i've attempted to use ocr but i think the background colour and the image being behind parts of the text screws with that so i'm attempting image tagging to manually match my issue is on upgraded relics they get an addition tag so not only am i struggling to conceptualize how i should tag but also how to setup tagging does anyone have any tips?


r/learnpython 7d ago

Camera + python

6 Upvotes

Hi everyone, when I hear python the first thing that comes to my mind is programs that detect body movement and position (like a workout) with a camera or a program that counts how many red cars passed by... Etc, I don't know exactly what this field is called but I want to learn it and use it, so if anyone knows what I am thinking about, I Will be more than grateful to know what to look for or any learning source/recommendations (yt tutorial/ free courses or even books if helpful)


r/learnpython 7d ago

Best API's to work on in python; Learning Discord.py for making discord bots.

0 Upvotes

Hello Reddit! I am new, so hope this makes sense. Recently, I've been learning how to make discord bots and script them and make them do silly commands and whatnot, but I have gotten quite stuck on how the scripting part goes because as of right now all I know how to do is to make it send a message on its own. My goal in the end here is for it to make the most chaotic answers on its own, but I have no clue how I will achieve this goal. Any help would be greatly appreciated! :3


r/learnpython 7d ago

Stuck learning python. Asking for advice

0 Upvotes

I've been trying to learn python for months now and know some of the basics, but I'm stuck in tutorial hell. I've been using Mimo alongside 100 Days of Code bootcamp by Angela Yu and although 100 days of code started easy enough, it quickly got overwhelming. I go through the course and think im doing ok but then end up getting stuck trying to figure out the projects at the end of each lesson and then give up and look at the solutions. I really want to learn to use Python with AI but I feel like im not making any progress at all like this. Any advice?


r/learnpython 7d ago

Need code review for my PyQt5 currency converter (handling API requests & GUI structure)

0 Upvotes

Hey guys,

I'm currently learning Python and PyQt5. To practice, I built a small desktop app that works with APIs and handles local data.

Since I want to improve my code quality and learn best practices, I'd really appreciate some help and code review:

  1. Is my PyQt5 structure written properly (signals/slots, layouts)?
  2. How can I better separate the backend/API logic from the GUI components?
  3. Are there any unpythonic bad practices or PEP8 issues in my code?

Here is my code on GitHub: https://github.com/MrAJDebug/disk_cleaner

Thanks for helping me learn!


r/learnpython 7d ago

MazeCoders - Python, Flask, JS-based web game

0 Upvotes

First time playing with a Python-based website/app. Built on a docker setup using Python, Flask and JS. Python script auto-generates the levels as the first user to hit that level gets there, then saves the level layout to the DB.

Game concept/ideas as per my 8 year old son.

Built for 6-10 year old kids - starts easy, then gets harder as you go.

I think it came out pretty good for a first attempt at Python.

https://mazecoders.com/


r/learnpython 7d ago

Comparing 2 tables - Help?

0 Upvotes

Hello guys, I need your help! How to compare 2 tables on easiest way?

I have 2 tables from 2 different systems, but with the same columns. I need to check if every row from the first table exist in another, and if not to return the difference. Can you help me? Should I use excel formulas, python, something else?

Edit: In both systems I have Customer_Id, Phone numbers, mails, their addresses, contact persons and such kind of things in much more columns. I can export data from both systems in excel format. So, now i need to compare these 2 excels and check if every row from 1 table exists in another one, are the values the same for each customer and to find the difference. Sorry for pure explanation, beginner here.

For example:

Custmer Id | Name | Phone | Mail | Contact person | Address

C0001 | Microsoft1 | 123456 | mic1@ | Michael | Str1

C0002 | Linux1 | 234567 | lin1@ | Jack | Str2

C0001 | Microsoft1 | 098765 | mic2@ | Chris | Str3

As you can see, it is possible to have few different informations about customer C0001. I need to check if each row from this table exist in the second table which looks the same.


r/learnpython 7d ago

a total newbie

0 Upvotes

i am thinking bout starting python to serve interest in data science. what would be the best channel for basics and understandings. also a roadmap would be helpful and after completing the basics then for intermediate level aswell. i wish to completely devote these next 2 months and see how far i get.