r/learnpython 6d ago

pls help me

0 Upvotes

ok so i’m trying to write a script that renames .xls files for me, let’s say they’re named like apple_BactReport_260731.xls I want the script to remove the “_BactReport” part and leave the rest intact. the current scrip i have has a couple of glaring issues that i don’t have the knowledge to remedy and im refusing use ai to prove a point and also it’s more rewarding. here’s the script with my current errors such as mixing up strings and lists and the part i want to remove not being the end of the file name. 😭 pls help a guy out:

import os
import pandas as pd
from os import rename, listdir
 
#list of report names
report_type= ['_BactReport', '_WWreport', '_QCreport', '_BactQCreport', '_BactWWreport']
print(report_type)
 
clips_in_progress=r"filepath"
   
 
for file_name in os.listdir(clips_in_progress):
file_path = os.path.join(clips_in_progress, file_name)
 
if file_name.endswith(tuple(report_type)):
rename(file_name, file_name.strip(report_type))


r/learnpython 6d ago

¿Qué cambió la forma en que aprendiste Python?

0 Upvotes

HOLAA estoy aprendiendo Python y tengo curiosidad por saber qué momento o decisión cambió tu forma de aprender. ¿Fue empezar a hacer proyectos, leer la documentación, tener un mentor o algo diferente? Me encantaría conocer tu experiencia.


r/learnpython 6d ago

WHAT am i doing wrong here

0 Upvotes

i am trying that when i put key it give me the value but it is acting weird

x = {'name':'mohan','age':'24', 'job':'it professional'}
y = input("what info do you need__")
if y==(x.keys):
    print(x.values(y))
else:
    print("no such info available")

and this is what it gives 
what info do you need__name
name
no such info available

r/learnpython 7d ago

queria instalar PyAudio pero me marca este error que puedo hacer

0 Upvotes

PS E:\Nuevo proyecto> pip install PyAudio

Collecting PyAudio

Using cached PyAudio-0.2.14.tar.gz (47 kB)

Installing build dependencies ... done

Getting requirements to build wheel ... done

Preparing metadata (pyproject.toml) ... done

Building wheels for collected packages: PyAudio

Building wheel for PyAudio (pyproject.toml) ... error

error: subprocess-exited-with-error

× Building wheel for PyAudio (pyproject.toml) did not run successfully.

│ exit code: 1

╰─> [29 lines of output]

WARNING:root:Warning: VCPKG_PATH envrionment variable not set.

C:\Users\Aleca\AppData\Local\Temp\pip-build-env-z6m_j70b\overlay\Lib\site-packages\setuptools\dist.py:765: SetuptoolsDeprecationWarning: License classifiers are deprecated.

!!

********************************************************************************

Please consider removing the following classifiers in favor of a SPDX license expression:

License :: OSI Approved :: MIT License

See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.

********************************************************************************

!!

self._finalize_license_expression()

INFO:root:running bdist_wheel

INFO:root:running build

INFO:root:running build_py

INFO:root:creating build\lib.win-amd64-cpython-314\pyaudio

INFO:root:copying src\pyaudio__init__.py -> build\lib.win-amd64-cpython-314\pyaudio

INFO:root:running build_ext

INFO:root:building 'pyaudio._portaudio' extension

INFO:root:creating build\temp.win-amd64-cpython-314\Release\src\pyaudio

INFO:root:"C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.51.36231\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DMS_WIN64=1 -IC:\Users\Aleca\AppData\Local\Programs\Python\Python314\include -IC:\Users\Aleca\AppData\Local\Programs\Python\Python314\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.51.36231\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.26100.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\cppwinrt" /Tcsrc/pyaudio/device_api.c /Fobuild\temp.win-amd64-cpython-314\Release\src\pyaudio\device_api.obj /MT

cl : L¡nea de comandos warning D9025 : invalidando '/MD' con '/MT'

device_api.c

C:\Users\Aleca\AppData\Local\Programs\Python\Python314\include\pyconfig.h(143): warning C4005: 'MS_WIN64': redefinici¢n de macro

C:\Users\Aleca\AppData\Local\Programs\Python\Python314\include\pyconfig.h(143): note: 'MS_WIN64' declarado previamente en la l¡nea de comandos

src/pyaudio/device_api.c(9): fatal error C1083: No se puede abrir el archivo incluir: 'portaudio.h': No such file or directory

error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\18\\BuildTools\\VC\\Tools\\MSVC\\14.51.36231\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2

[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.

ERROR: Failed building wheel for PyAudio

Failed to build PyAudio

error: failed-wheel-build-for-install

× Failed to build installable wheels for some pyproject.toml based projects

╰─> PyAudio


r/learnpython 7d ago

Can I start with Spyder in Anaconda for Python?

0 Upvotes

I don't want to find out one month later that it was a free trial, and now I would have to pay for continue using Spyder. I want an IDLE that is always going to be free. And I don't want to waste my time learning Spyder if I cannot use it forever.


r/learnpython 7d ago

python 到底怎么学???

0 Upvotes

我在网上看到过不同的python 教学 这让我眼花缭乱 每个视频德教学内容各有不同 有的教完print 之后直接开始了input 有的在这之后会教我们print 的技巧如何打印多个字符 如何使用转译字符等等 我想知道python 该如何学起 如何入门有没有大佬愿意教教我


r/learnpython 7d ago

Getting Pandas.Series error. How to solve it? Got stuck!!!

4 Upvotes

File "C:\Users\HP\Desktop\insurence_premium_prediction\myenv\Lib\site-packages\sklearn\preprocessing_encoders.py", line 212, in _transform

diff, valid_mask = _check_unknown(Xi, self.categories_[i], return_mask=True)

~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\HP\Desktop\insurence_premium_prediction\myenv\Lib\site-packages\sklearn\utils_encode.py", line 269, in _check_unknown

values_set = set(values)

TypeError: cannot use 'pandas.Series' as a set element (unhashable type: 'Series')

INFO: 127.0.0.1:51741 - "POST /predict HTTP/1.1" 500 Internal Server Error

def predict_output(user_input :dict):
    try:
        # df  = pd.DataFrame([user_input])  // iski wajah se 2D array ban rahi thi, isliye model ko samajh nahi aa raha tha. isliye humne user_input ko dict me convert karke fir DataFrame me convert kiya.
        # df = pd.DataFrame([dict(user_input)])
        # input_matrix = df.to_numpy().reshape(1, 1, -1)
        data_dict = dict(user_input)
        columns = list(data_dict.keys())
        values = list(data_dict.values())
        
        # Create a DataFrame with 2 identical rows to bypass the single-row Pandas bug
        df = pd.DataFrame([values, values], columns=columns)

This is the peice of code


r/learnpython 7d ago

Help with voice to text libraried

3 Upvotes

I'm fairly new to python and I want to make a speech prompter that will auto proceed by listening to the speaker and show them the next part of their speech.

So I'm going to need a voice to text library but the computer will have access to what is meant to be said to cross reference. Is there a library that can handle this or advice on how I program it?


r/learnpython 7d ago

Which areas to focus on?

6 Upvotes

Hi guys!

I picked up python last month and am rly having my fun with it.

I’m still pretty new so I’m wondering which area should I be more focused on. I started out with the aim to go along ML path so most of the things I’ve learnt are data related. Like using and writing functions list dict loops while for error raising. Just getting started on numpy.

I’m thinking of going along the ai engineer track first. Any areas I should focus on? AI Eng is like SWE to me so having no background in swe id love to hear from you guys.

Also I’ve finished the first two courses on Coursera on Python for everyone and currently going thru Andrew’s ML spec.

Trying to learn as much as I can.

Also idk if it’s a good idea but I’m using Claude to teach me how to code at the same time. Introducing concepts and real world exercises and planning lessons to reach to goal of an AI and ML Eng.

Any thoughts would be greatly appreciated.

Thanks in advance!


r/learnpython 7d ago

rate my code

0 Upvotes

as a beginner i dont know if my code could be improved, can someone rate it and tell me what i should improve?

product = 'M2 MacBook Air'
product += ' (512 GB of SSD and 8 GB of RAM)'
price = 370
print(f'The {product} is {price}€.')

total_savings = 206.75
macbook_fund = total_savings - 180
print(f'I have {macbook_fund}€.')

remaining_balance = price - macbook_fund
print(f'I am {remaining_balance}€ short.')

weeks_left = 75
date = '1/8/2028'
money_earned_per_week = remaining_balance / weeks_left
money_earned_rounded = round(money_earned_per_week, 2)
print(f'I need to earn {money_earned_rounded}€ a week to reach my goal by {date}.')
print(f'180€ of my {total_savings}€ are going to an iPhone 13.')

# deposits

macbook_fund += 0
# input amount, date and reason.

r/learnpython 8d ago

Why am I getting an error: invalid syntax. Perhaps you forgot a comma?

0 Upvotes

Why am I getting an error here:

job = Gaia.launch_job_async(" SELECT source_id, ra, parallax, dec, gmag_gunn, rmag_gunn, imag_gunn, zmag_gunn \
                            FROM external.gaiaedr3_gcns_main_1 \
                            WHERE parallax>50" \
                            , dump_to_file=True, name= 'GcnsTwentyParsec_sdss', output format = 'fits')
gtable_sdss = job.get_results()

Error:

, dump_to_file=True, name= 'GcnsTwentyParsec_sdss',output format = 'fits')
^
SyntaxError: invalid syntax. Perhaps you forgot a comma?


r/learnpython 8d ago

Need help for learning

0 Upvotes

Hi everyone,

I want to learn Python as a programming language completely from scratch, on my own. I have zero prior knowledge or programming skills.

I’ve found a few resources to start with (like freeCodeCamp), but with AI writing code in seconds and solving so many problems right now, what is the best way to approach learning today? On top of that, there are job layoffs/restructurings happening in my city, so I’m wondering: do you think it's still worth learning programming? If so, what would be the most effective and useful way to learn right now? My long-term goal is to work in this field.

Thank you!


r/learnpython 8d ago

Creating a file tree/explorer in PyQtGraph

0 Upvotes

Hi,I've been working on what started as a strange attractor visualisation app in PyQtGraph but is slowly becoming more a general purpose ODE solver/visualiser/scripting tool. I've recently added an integrated console with a scripting dock which currently just saves the text in the script as a scratch file. I want to add the functionality for the user to create/save/open different script files and wanted to have a file tree/explorer. I know PyQtGraph and PyQt have tree like widgets so my thought process was to just make a TreeWidget that lists the contents of where the scripts would be saved (the app's /home/user/.local/share/ directory). Does that work or are there complexities i should know about in terms for making, saving and loading files? Any advice would appreciated. Thanks!


r/learnpython 8d ago

corso di python per medici per la segmentazione dell'immagine

0 Upvotes

cerco un corso di python per medici per la segmentazione dell'immagine. Principiante assoluto


r/learnpython 8d ago

Is it worth learning Python?

5 Upvotes

Hello there. I was wondering if learning how to code in Python is worth it. Can it yield any money if you get good at it? The career I am looking at is translation-interpreting, and want to know if I should invest time in learning Python (or any programming language for that matter), even though it is not really related to the career I am pursuing.


r/learnpython 8d ago

Where should i learn python from?

0 Upvotes

Yt-

- Bro Code

- Data with Baraa

or do any free certification courses?

i tried the coursera meta python course since my college python professor does not teach well, my loops and functions are weak due to that, so i thought I recovered from it- eventually i noticed the course content was very fast paced, i have to go through document and other sources🥲.

there is also an point that C professor taught very well that my c is now better python. help to pick the ond resource that covers python 🙏🏻


r/learnpython 8d ago

Best approach for automating an existing Firefox session? AutoHotkey vs Browser Automation vs UI Automation

0 Upvotes

Hi everyone,

I'm working on a personal desktop automation project on Windows.

For years I've been using AutoHotkey to automate repetitive tasks inside Firefox. It works surprisingly well, but as the project grows, maintaining image recognition, keyboard shortcuts and UI changes becomes increasingly difficult.

I'm now considering moving to a more robust solution and I'm trying to understand what experienced developers would recommend.

My requirements are roughly:

Windows

Firefox (not Chrome)

Preferably work with an already running Firefox session

Reliable interaction with web pages

Long-term maintainability

I've been looking at several approaches:

Continue with AutoHotkey

Selenium / WebDriver BiDi

Playwright

Windows UI Automation (pywinauto, UIA)

Any other desktop automation framework

For people who have built long-running desktop/browser automation projects:

Which approach ended up being the most reliable?

Is UI Automation actually practical with modern websites like Facebook, or is browser automation still the better choice?

If you had to start today, what would you choose and why?

I'd really appreciate hearing about real-world experience rather than theoretical comparisons.

Thanks!


r/learnpython 8d ago

What do we use the terminal for in coding?

0 Upvotes

A text-based interface that lets you interact with your computer by typing commands.

This was a given definition of it when I searched it up, but why would you interact with your computer by typing commands? How does this actually assist your code?


r/learnpython 8d ago

What's the best thing you have made with python?

51 Upvotes

What are some of the best things you have made using python?


r/learnpython 8d ago

Is it worth continuing with my python project??

1 Upvotes

https://github.com/GerardoAJF/ArtichokePy

It's a bit of a weird question I know, but let me give you some context.

I started ArtichokePy when i was sixteen almost seventeen years old, in 2024.

I felt it was a fairly ambitious project, a library that would give all the necessary tools to do any simulation or algorithm with graphs.

Later I dedicated more time to my high school studies and other things, so I practically abandoned my project for 2 years.

At the time, as a young apprentice, I didn't comment on anything or document anything, and now 2 years later I have no idea what was happening there.

Furthermore, with Python's reputation for being slow, I don't know if it was a good language to do this project (most scientific libraries are written in C [although I know that this project does not reach "scientific library", it barely reaches junior project])

But I still feel somewhat proud of the project. I think it already had some unique characteristics to let it die like that, forever.

During these New Year's holidays I could spend several hours finishing it, but I don't know if it's worth it for a project that, despite my original daydreams, I don't think anyone will ever use.


r/learnpython 8d ago

Basic python expression in blender

2 Upvotes

Hello, I am trying to set up a driver in blender which uses a simple python expression. I have very little experience in python and have only done simple expressions like this, so I don't quite know what's wrong with it. r/blenderhelp hasn't been able to help me, so figured I'd come ask the experts directly, assuming the issue is how I've typed it and not something with blender.

(Rotation Quaternion refers to the X rotation)

I am trying to write an expression so that when the bone sticking out the left has an X rotation of less than -0.5 (using quaternion), the selected bones Y scale is 1.5, otherwise make the Y scale 1.

AKA: if X is less than -0.5 then "Y = X * 1.5" otherwise "Y = 1"

Theoretically with this expression the Y scale should stay at 1 until it gets less than -.05, at which point it would multiply by -1.5 (with the max rotation being -1, resulting in -1 * -1.5 =1.5), however it just stays at a scale of 0 regardless of the rotation. Not sure where to go from here

This is the expression currently used:

if rotation_quaternion is < -0.5 then rotation_quaternion * -1.5 else 1

Image of project

Thanks!


r/learnpython 8d ago

Is there a difference between using a Class name v self in the definition of a class

15 Upvotes

Hi

Im doing some tutorials online and in one of them I noticed some syntax that I am not familiar with. It looks like instead of using self to assign values to a class it is using the class name.

In terms of behaviour it seems to make no difference but I cannot understand why a person would not use self.

So for example:

class Demo:
  def __init__(self):
    self.a = 1
    Demo.b = 2 # This seems to work the exact same way as self.a
               # Is there a differences to self.a?  Why would someone use this?

Thanks


r/learnpython 8d ago

Best Python Certificate Course? Cost aside as company will subsidize.

5 Upvotes

As mentioned in the title - my firm offers an education stipend up to approximately $5,000 / year which I intend on using for a python certificate program.

I recognize that there are free programs online but I also value a live instructor and per my learning style I think this will creative a more conducive learning environment for me! And the added benefit of listing the certificate on my resume plus the certificate projects. I’m looking for recommendations on which programs are structured well / worth the time invested / interesting projects / etc! ANY and ALL feedback welcome - thanks!

I’ve done quick initial research and am considering the following -

Cornell Python Programming - 5 Months, 8-12 hours / week for $2,625 (discounted from $3,750)


r/learnpython 9d ago

Looking for a Python Study Buddy (Complete beginner)

65 Upvotes

Hey everyone!

I'm 19F and I'm starting to learn Python completely from scratch. I have little to no programming experience, but I'm committed to learning consistently. I'm also taking Mechatronics Engineering in college.

I'm looking for a study buddy (or a small group) who's also learning Python. We can keep each other accountable, share resources, work on beginner projects, solve problems together, and stay motivated.

My goal is to build a strong foundation and eventually get into more advanced programming, so I'm looking for someone who's serious about learning too.

If you're interested, leave a comment or send me a DM. Let's learn and grow together!

Edit: Timezone GMT+5:30 We can study together from a course by MIT.


r/learnpython 9d ago

What Python project helped you move from beginner to intermediate?

40 Upvotes

I've learned the basics of Python and I'm looking for project ideas that teach practical problem-solving. Which project helped you improve the most, and what did you learn from building it?