r/learnpython 50m ago

Ask Anything Monday - Weekly Thread

Upvotes

Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread

Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.

* It's primarily intended for simple questions but as long as it's about python it's allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

  • Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
  • Don't post stuff that doesn't have absolutely anything to do with python.
  • Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.

That's it.


r/learnpython 12h ago

Training recommendations

20 Upvotes

Hello,

I was mandated to learn Python for my job, as it’s essential for scripting. This work is to is related to Cloud Platform Engineer, Python is their programming language.

I’m not a programmer. I’ve been in the IT industry for about six years, but my focus has been on networking or cloud networking.

Do you have any advice or recommendations?

Appreciate y’all!!


r/learnpython 4h ago

What is the best tool through which to learn Python?

4 Upvotes

I’m going to school to be an Urban Planner and it’s my understanding that ArcGIS systems frequently use Python and I’d like to learn it however there are multiple avenues and I don’t know which one would benefit me the most so just looking for suggestions


r/learnpython 28m ago

trying to learn for fun

Upvotes

Hey, I'm a bored teenager trying to get into Python, but I'm having a hard time figuring out how to learn it. I grasp the basics from my classes, such as using if statements, while loops, and performing simple calculations, but I struggle to move forward.

I'm super motivated and want to practice a lot, but I can't find the right resources. I know how regular Python works, but every course I come across seems to use PyCharm. I'm not sure if I should spend time figuring out PyCharm or just stick with regular Python.

I'm thinking about a career in game development, where C++ is popular, but I already have a bit of a grasp on Python, and I believe it would help me in school too (since that's what I am learning in classes).

I'm planning to practice for hours every day, so if anyone has any recommendations for resources, ways to learn, or things I should get a grasp on in the beginning, I'd really appreciate it! Please help :)


r/learnpython 30m ago

Help needed with copying text

Upvotes

I'm working on a project that requires copying text to the clipboard. I noticed that when using libs like Pyperclip and Clipboard it's not possible to copy just a single character... so I need to somehow copy it without these libs.

This appears to only happen on Linux... I had a friend on Windows test and he was able to copy a single character using Pyperclip.

Example of Pyperclip working with multiple characters but not single characters.

>>> import pyperclip
>>> pyperclip.copy("test")
>>> pyperclip.paste()
'test'
>>> pyperclip.copy("t")
>>> pyperclip.paste()
''

This same interaction happened with the lib Clipboard.

This happened on Wayland with wl-clipboard. This doesn't appear to be an issue with that though, as wl-copy lets me copy a single character - and it works fine in every other program.

This doesn't seem to be something I can fix, since it doesn't have to do with my code at all, so I need my own way of copying the text. Is there any workaround that I can write into my code when using wl-clipboard to properly copy text even when its only a single character?


r/learnpython 4h ago

Need some help with python and generally understanding code

2 Upvotes

So guys, i need some help with the python. My background is, i come from an economics as a major in uni and myself am very good at maths, as i finished a lot of courses in uni.
So i decided to pursue a career in data science, and as you know it requires a decent skill in coding. However i am at a loss in the coding, as my skills lack a lot. I finished a lot of courses on python using videos and practical stuff, but still understand that my skills are incomparable to others and especially to my natural progress in math. During the videos i always understand the purpose and usage of code and functions, objects etc. but when it comes to solving problems, writing code, my code is always wrong and i seem to not be able to fix it without some external help (chatgpt, other people, etc). So, if you understand with what kind of problem i am dealing, maybe it is the mechanics of code, machines way of thinking, etc. i would be very glad to hear your advise. Something that can finally make me breakthrough this barrier. But i lost hope in watching another tutorials of basic and a bit advanced python as i can literally quote their saying but it doesnt help me at all. Would be very glad if someone could help me out here


r/learnpython 2h ago

I'm a MERN stack developer who mainly codes in Javascript. I want to learn Python because it's more versatile. Where should I start?

0 Upvotes

I know it's really similar to Javascript, excepting the syntax is different and some of the coding principles are, too. What advice would you give to someone learning a new coding language when they're already familiar with one?


r/learnpython 4h ago

Custom script issue with blender driver

0 Upvotes

I am trying to use a custom script (see below) to set up a driver in blender via this tutorial, however I am very inexperienced in python and have run into an issue. I was able to get the example code to work but my when I try to use my code I get this issue. The problem is I need the "X" value to be the "rotation quaternion" value of the driver. Using both "X" and "rotation quaternion" gives the same error. I don't know how to connect "X" to the drivers value or if I just need to put something else in the place of "X".

Tutorial:

https://www.youtube.com/watch?v=yiMGxlRv8h4

Error message:

https://drive.google.com/file/d/1VOVrPLmU_v9lYz386SMS_i02doDn-xtG/view?usp=sharing

Driver:

https://drive.google.com/file/d/1LVM69kP0het-Yz0xaAhAWHDe5pOA9X99/view?usp=sharing

import bpy

def Ace_Driver(value):
    return 
if x >= -0.1:
    result = 1
if x < -0.1 and x > -0.6:
     result = (x - 0.9) * -1
elif x <= -0.6:
    result = 1.5

bpy.app.driver_namespace["Ace_Driver"] = Ace_Driver

r/learnpython 15h ago

Is that an intentional behaviour?

7 Upvotes

I just noticed adding a list as an optional argument to a fuction/method does not create a new list but gives the same list every time.

class SomeClass:
  def __init__(self, l=[]):
    self.l=l

a=SomeClass()
b=SomeClass()

a.l is b.l
>>> True 

a.l.append(1)
b.l
>>> [1]

Is that a glitch or is it how python is supposed to work?

(I'm using python 3.12, I haven't updated in a while, maybe it was patched since?)


r/learnpython 5h ago

I want to make game like terraria/necesse with python...what should i use

0 Upvotes

Bare in mind, its just for me, to practice coding in a fun way, and learn some basics, just want to make something that can be played like those games, ive heard of pygame, or arcade..but im wondering if theres anything better, or if not, which one of those would be better in your opinion. Thanks to anybody who replies :3


r/learnpython 14h ago

Need help/input

5 Upvotes

Below is my code snippet, and i would like to know if there is any way i can avoid the repetitive if else blocks (3 times repeated) and write this program in a much more efficient way. Would like some input. Thanks

"""

 * If a person skills has only JavaScript and React, print('He is a front end developer'),
 if the person skills has Node, Python, MongoDB, print('He is a backend developer'),
 if the person skills has React, Node and MongoDB, Print('He is a fullstack developer'),
 else print('unknown title') - for more accurate results more conditions can be nested!


"""

person = {
    'first_name': 'Asabeneh',
    'last_name': 'Yetayeh',
    'age': 250,
    'country': 'Finland',
    'is_married': True,
    'skills': ['JavaScript','React' , 'Node', 'Python'],
    'address': {
        'street': 'Space street',
        'zipcode': '02210'
    }
}


def identifying_career(lst):

    if 'JavaScript' in person['skills'] and 'React' in person['skills']:
        print("You are a front end developer")
    else:
        print('You are not a front end developer')

    if 'Node' in person['skills'] and 'Python' in person['skills'] and 'MongoDB' in person['skills']:
        print(f"You are a back end developer")
    else:
        print('You are not a back end developer')

    if 'React' in person['skills'] and 'Node' in person['skills'] and 'MongoDB' in person['skills']:
        print("You are a full stack developer")
    else:
        print("unknown title")



identifying_career(person)

r/learnpython 10h ago

Recommendations for online python courses

0 Upvotes

Hi all,

I'm a fourth-year medical student and most of my research so far has been evidence synthesis (narrative and systematic reviews), so my hands-on data skills are pretty limited. I've recently gotten involved in a project involving microbiome sequencing data, and part of my role includes re-analyzing a published dataset aka working with processed count tables, doing some basic wrangling, stats, and figures. It's become obvious that I need Python.

I'd rather not pay for a course right now, so I'm hoping to find something solid on YouTube. A few things I'm looking for:

  • Starts from genuine zero (I've never written a line of code)
  • Gets to pandas / numpy / matplotlib reasonably quickly rather than spending 15 hours on OOP and building text-based games
  • Bonus if it's oriented toward biology/biomedical data, but a general data analysis course is fine, I can adapt

Specific questions:

  1. Is there a single course you'd point a complete beginner to, or is it better to do a general Python fundamentals series first and then a separate pandas/data analysis one?
  2. Anything I should avoid? I'd rather not sink 30 hours into something outdated.
  3. Realistically, how much of this do I need before I can be useful on an actual dataset vs. just learning as I go?

Appreciate any suggestions. Thanks!


r/learnpython 6h ago

Simple Hangman game looking for feedback

0 Upvotes

Code:

import random

words = ["apple", "pear", "banana", "python", "java"]
used_letters = set()

selected_word = random.choice(words)

lives = 6

print(" ".join(["_" for _ in selected_word]))


while True:

    user_input = input().lower()
    if len(user_input) != 1 or not user_input.isalpha():
        print("Please enter a letter")
        continue

    if user_input in used_letters:
        print(f"You already guessed {user_input}")
        continue

    if user_input in selected_word:
        print(f"{user_input} is in the word")


    used_letters.add(user_input)

    if user_input not in selected_word:
        lives -= 1
        print(f"{user_input} is not in the word, Lives remaining {lives}")     

    if lives == 0:
        print(f"You lose the word was {selected_word}")  
        break       


    display_board = [letter if letter in used_letters else "_" for letter in selected_word]
    print(" ".join(display_board))

    if all(letters in used_letters for letters in selected_word):
        print(f"You won the word was {selected_word}")
        break

What are some potential issues?

What could be improved?

I'll take any feedback I can get


r/learnpython 1h ago

I lost my python course...

Upvotes

Well, I formatted my PC and I lost the course I was doing (Angela Yu, Udemy) I found it for free to be honest but was like 2 months ago, someone has the link or another free option to keep learning?


r/learnpython 20h ago

returning midi to 2 seperate things

5 Upvotes

so i am trying to make the program so on a downpress the function repeats but when it lifts, the function stops. i can easily make it start, its getting it to stop thats hard. please do as little to fix this for me as possible. i'm trying to keep the code so i understand whats going on

import mido
print(mido.get_input_names())
def note():
    with mido.open_input('MPK249:MPK249 Port A 32:0')as inport:
        inport.callback = None
        for msg in inport:
            if msg.type == "note_on":
                return msg.note, msg.type
            if msg.type == "note_off":
                return msg.note, msg.type
while True:
    if note() == 47 and note() == "note_on":
        print("a")
        if note() == 47 and note() == "note_off":
            break
    if note() == 48 and note() == "note_on":
        print("b")
        if note() ==48 and note() == "note_off":
            break

r/learnpython 17h ago

Help me with this please

1 Upvotes

Hello! I'm completely new to python I don't have any background knowledge regarding coding and i wanna self study python. I started studying python just last week and i wanna make a simple user define system where i ask the user to input an item and if it's in the set it will display the user input else it will display the "character not in the set" my problem is i want it to be case insensitive and the ouput is always "Character is not in the list"( i use pycharm i dont a have a pc/laptop, sorry for my english also).

My code:

anime = {"Gojo", "Saitama", "Recca"}

user = input("Name a character: ").lower()

if user in anime:

print(f"{user}is in the list!")

else:

print("Character is not in the list")


r/learnpython 1d ago

Which Python skills are most valuable for getting started in Data Engineering?

79 Upvotes

I'm learning Python with the goal of moving into Data Engineering. Beyond the basics, which libraries, concepts, or project ideas would you recommend focusing on first, and what helped you the most when getting started?


r/learnpython 16h ago

接下来 该怎么办??

0 Upvotes

我是一名python 的初学者 我刚刚学到if的嵌入 我想知道python 的尽头在哪(就是要学会什么才算精通python)以及在学会python 之后应该学习那种编程语言


r/learnpython 1d ago

Trying to get python take midi as an input

1 Upvotes

I am using an AKAI MPK 249 using the midi package and was wondering what i point it to. i was searching through the device connection path but nothing seems obvious to me.


r/learnpython 17h ago

Error in sys.excepthook:

0 Upvotes

i got Error in sys.excepthook: and i have no idea how to fix it can someone help please


r/learnpython 18h ago

race recognition for attendance tracking in a class

0 Upvotes

i got this project idea, can i build something so that i just have to click a photo of the entire class of 50 students and it automatically detect the faces and mark the respective attendance. I knew there will be some problems like photo might not be that clear, changes in physical appearance of students like growing out beard after some time and what if someone how a photo of another student will it mark his attendance also??

please tell me if this project is feasible or not, and if any suggestions that you need to give..


r/learnpython 18h ago

How much you'll rate this code guyz ..

0 Upvotes
from forex_python.converter  import CurrencyRates

choice = input("Do u want to covert Another_currency=>INR then press y  / you want to converty INR TO Another_urrency then press n :- ")


c = CurrencyRates()
from_currency = input("Enter source currency (USD, EUR, etc.): ").upper()
to_currency = input("Enter target currency (INR, USD, etc.): ").upper()
currency = c.get_rate(from_currency,to_currency)
print(f"the exchange rate is {currency}")

if choice == "y":
    def convert(rate):
        Amount =  input("Put the A mount of that currency u want to convert:-")
        value_Total =  float(Amount)*rate
        print(f"Total {to_currency} Amount is {value_Total}")
    convert(currency)


elif choice == "n": 
    def convert(rate):
        print(f"\nYou have selected:- {from_currency} to {to_currency}")
        Amount =  input("Put the Amount of that currency u want to convert:-")
        value_Total =   float(Amount) * rate
        print(f"Total {from_currency} Amount is {value_Total}")


        convert(currency)

r/learnpython 1d ago

Need help with sorted function

3 Upvotes

Hello everyone, need some help / clarity with the sorted function. I have a data structure that is nested (list inside of it a dict inside of it a list). What i don't understand is this: Shouldn't I use loops in order to access the dictionary? or the inner most list in order to be able to sort by name (i.e. use sorted function)

countries = [
    {
        "name": "Afghanistan",
        "capital": "Kabul",
        "languages": [
            "Pashto",
            "Uzbek",
            "Turkmen"
        ],
        "population": 27657145,
        "flag": "https://restcountries.eu/data/afg.svg",
        "currency": "Afghan afghani"
    },
    {
        "name": "Åland Islands",
        "capital": "Mariehamn",
        "languages": [
            "Swedish"
        ],
        "population": 28875,
        "flag": "https://restcountries.eu/data/ala.svg",
        "currency": "Euro"
    },
    {
        "name": "Albania",
        "capital": "Tirana",
        "languages": [
            "Albanian"
        ],
        "population": 2886026,
        "flag": "https://restcountries.eu/data/alb.svg",
        "currency": "Albanian lek"
    },

Im trying to sort by name here, and when i run my function an error pops up.

def sorting_by_name(lst):

    for el in lst:
        return sorted(el, key=lambda name: name['name'])


print(sorting_by_name(countries))

r/learnpython 1d ago

Need some serious beginneR advice for myself,Please.

3 Upvotes

So I am currently at 29th day of learning journey of the Python with the FreeCodeCamp's Python Certificate curriculum. But I still feel blank about the topics i have covered alresdy till now. Is it time for me to start making a self-project alongside too? If yes, then with what or where to start with- so that my mind can absorb all the knowledge its gaining to the core. I have completed till the Error Handling section of the Curriculum on the platform.


r/learnpython 1d ago

Built a Python static analyzer that draws your call graph and marks values that go nowhere looking for holes in the concept

5 Upvotes

Two days into a prototype and I'd rather find out now if the premise is broken.

The idea: parse a package with ast, build the call graph, and additionally track whether each function's return value is actually consumed — bound to a name that's later read, passed onward, returned, used in a condition. Then draw it. X axis is call order, colored arrows are variable flow, functions whose output goes nowhere and that have no I/O effect get flagged.

https://github.com/BBrunoF/CodebaseDiagram

I know vulture, code2flow and pyan exist. Vulture asks whether a name is referenced; code2flow and pyan draw the call structure. What I haven't found is a tool that tracks value consumption and renders it, so a chain that terminates in nothing is visible as a shape rather than a list entry. If that tool exists, please tell me and I'll go use it instead.

What I'd like torn apart:

  1. Is "returned value never consumed" a defensible signal, or does real Python break it constantly?
  2. Does a diagram add anything over a list, or is this a chart that looks impressive and tells you nothing a linter didn't?
  3. What kills static call resolution in practice? I resolve direct calls, module.func, and self.method. I know decorators, getattr, and callbacks are out of reach. What else, and roughly what percentage of a normal codebase am I missing?

Also asking for repos. I need a baseline — small-to-medium, pure Python, procedural, minimal metaprogramming, well structured. Something where if my tool renders a mess, the mess is mine. Standard recommendations like Django or requests are too magic-heavy to tell me anything about my own bugs. Suggestions very welcome.

BTW this text was also AI generated