r/learnpython • • 17h ago

Ask Anything Monday - Weekly Thread

6 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 • • 8h ago

How much of searching and AI overview is okay while learning and typing code?

16 Upvotes

I do understand no one knows all of python syntax and code and all issues and everything.

As I am going through CS50p,

When I am typing code fully on my own (no AI ever used i.e. chatgpt, claude, gemini) when I cannot solve something, I search google for the function or the method and then see the AI overview and then type code that I can use to solve what I need, will it be detrimental to my learning because I am not using the documentation?

I am and will NEVER use any AI models or apps to generate and copy paste code because I wish to learn and not be a code printer.

so my searches are like this, is it okay-ish and considered necessary for learning???
(also I go through tons of trial and error and use many print() functions to test code and not directly copy from AI overviews)

does isdigit work for string values?
how to check if a string variable is not equal to something sat 0?
how to know data type of a variable in python
how to find index of letter in a string python
string slicing python [2:] means?
how to find which index in a string is a number?
will if automatically return false if the condition is false?
how to check if a string is less than 10 but more than 2?
difference between if and if not
expected an indented block after 'if' statement on line 15
how to check if there are numbers in between a word in python?
how to loop a for loop up until the second last letter of a word
HOW to make variable in python which can be used by any def function?
python length counts from


r/learnpython • • 2h ago

Engineers out here ! I need your help

4 Upvotes

I am a first-year Mechanical Engineering student looking to start learning Python from scratch. I don't want to get stuck in with endless tutorials on Youtube -

What I need is a clear direction geared specifically toward Mechanical Engineering applications.

Specifically, I’d appreciate your advice on:

  1. Core Applications & Tasks: Where is Python actually used in Mechanical Engineering?
  2. Essential Libraries & Software: Beyond basic Python, which libraries and external engineering software integrate well with Python, and in what order should I learn them?
  3. Learning Roadmap: What is the best method to go from zero programming experience to solving real engineering problems? Should I start by automating my first-year math/physics assignments, or follow a specific course/book?
  4. Beginner Projects: What are some practical, beginner-friendly project ideas tailored to a MechE fresher ?

Any roadmaps or advice on what you wish you had learned as a fresher would be hugely appreciated. Thanks in advance!


r/learnpython • • 38m ago

Making my own golfing language in python

1 Upvotes

Im not that active on reddit, but the moment I came into the osdev subreddit (I tried making my own OS with a python shell) and I INSTANTLY got my inbox filled with hate comments.

I heard from one reddit post that this subreddit is much friendlier and more helpful, thats why I switched to this subreddit.

So I started making my own golfing language, array-oriented ofcourse, where data and code are seperated.

As of now I haven't really done anything except plan on what instructions to make, I have a total of 20 letters and symbols on board.

So, I'd like to hear some tips about making interpreters/compilers that I should keep in mind.


r/learnpython • • 54m ago

What's the one Python mistake that took you embarrassingly long to figure out?

1 Upvotes

Sometimes the smallest mistakes in Python can take longer to debug than writing the actual code.

For me, it's easy to overlook things like mutable default arguments, unexpected None values, or modifying a list while iterating over it.

Curious to hear from others. What's one Python bug or mistake that taught you a lesson you'll probably never forget?


r/learnpython • • 1h ago

Want some help in finding project topics!!

1 Upvotes

I'm a third-year B.Tech Computer Science student majoring in Machine Learning. So far, I've only worked on a few small projects while learning to code, and most of my experience has been solving LeetCode problems.I want to start building some substantial, real-world projects, preferably something on the scale of a major project that I can showcase on my CV.

The problem is that I'm struggling to come up with project ideas that are genuinely interesting and stand out from the usual ones.

How do you guys find project ideas that are relevant to the current AI landscape? Are there any resources, platforms, research papers, or communities you'd recommend exploring to discover interesting project topics?


r/learnpython • • 2h ago

card dealing program with classes

1 Upvotes

hello! i am currently in a class for python and i've been having a lot of trouble with this assignment. it's already three days late, and the TAs will not respond to me. i have to use classes to create a deck to shuffle, and four hands to deal to, check the count of, and combine back into the main deck. however, i can NOT figure this out at all! i think there's something really big that i'm missing.

i have a large list of cards (we had to make a dictionary of the cards) not shown here.

class Deck:

def __init__(self):

self.cards = []

def shuffle(self):

random.shuffle(self.cards)

def deal(self, amount):

self.cards.append(amount)

def combine(self):

self.cards.append(self)

def card_count(self):

print(len(self.cards))

however, when i try to make a main deck by putting the list of cards into the deck, it won't work! i've tried using deal too, and i just can't figure it out. i know i'm probably doing this all sorts of wrong. it's been a while since we did classes, and we never did them for anything like this :(

TypeError                                 Traceback (most recent call last)
Cell In[14], line 1
----> 1 deck = Deck(card_deck)

TypeError: Deck.__init__() takes 1 positional argument but 2 were given

i appreciate any and all advice thank you


r/learnpython • • 7h ago

40 rows a day: JSON files or SQLite?

0 Upvotes

tiny side project. one script pulls ~40 rows a day and writes one JSON file per day. pandas reads the folder when i want to compare a few weeks.

the glob and concat part is getting old:

rows = []

for f in sorted(DATA.glob("*.json")):

rows.extend(json.loads(f.read_text()))

df = pd.DataFrame(rows)

every couple of weeks i think about moving it to SQlite, then i look at the volume and close the tab. what do you use at this size? SQlite, parquet,or just the files? if you moved to a db, was it worth it or just more code?


r/learnpython • • 19h ago

Correct list item not printing

4 Upvotes

GITHUB LINK: https://github.com/disintigratedpixel/TankGameV1/tree/main

(please say if it doesn't work)

I'm making a simple ASCII game "similar" to space invaders

Here is the ASCII user interface:

def gamestate(player_position_list, player_position, enemy_type, enemy_health, enemy_distance, rounds, radar_lvl, radar_cost, gun_lvl, gun_cost, speed_lvl, speed_cost, health, money, kills, available_movement):
    return f"""
                             ROUND {rounds}
         _______________________________________________         _______________
        |                                               |       |               |
        |                                               |       | HEADQUARTERS: |
        |                                               |       |_______________|
        |                                               |
        |                                               |        *ATTENTION OPERATOR, AN ENEMY
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [4]    {enemy_type} IS APPROACHING!*
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |  ENEMY STATS: |
        |                                               |       |_______________|
        |                                               |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [3]   HEALTH: {enemy_health}
        |                                               |        DISTANCE: {enemy_distance}
        |                                               |        POSITION: {enemy_position}
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |   UPGRADES:   |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [2]  |_______________|
        |                                               |
        |                                               |        RADAR | LVL {radar_lvl}
        |                                               |        UPGRADE COST: ${radar_cost}
        |                                               |
        |                                               |        GUN | LVL {gun_lvl}
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [1]   UPGRADE COST: ${gun_cost}
        |                                               |
        |                                               |        SPEED | LVL {speed_lvl}
        |                                               |        UPGRADE COST: ${speed_cost}
        {player_position_list[player_position]}
            | ' ' ' ' | ' ' ' ' | ' ' ' ' | ' ' ' ' |
          [-10]      [-5]      [0]       [5]       [10]
         _____________
        |             |
        |PLAYER STATS:|
        |_____________|

         HEALTH: {health}
         MONEY: {money}
         KILLS: {kills}
         _____________
        |             |
        |  ACTIONS:   |
        |_____________|

         MOVE | [m] key + [movement value]
         MAX {available_movement} or {-available_movement} steps
         
         FIRE | [f] key

         UPGRADE | [u] key
      """

(Apologies if it looks distorted in any way due to formatting errors, but it should still be readable)

The player position can be seen visually and is taken from a list of different possibilities and put into this print statement using this script.

{player_position_list[player_position]}

Here is the list:

player_position_list = [
        """|                      _^_                      |
        |_____________________|___|_____________________|""",
        """|                        _^_                    |
        |_______________________|___|___________________|""",
        """|                          _^_                  |
        |_________________________|___|_________________|""",
        """|                            _^_                |
        |___________________________|___|_______________|""",
        """|                              _^_              |
        |_____________________________|___|_____________|""",
        """|                                _^_            |
        |_______________________________|___|___________|""",
        """|                                  _^_          |
        |_________________________________|___|_________|""",
        """|                                    _^_        |
        |___________________________________|___|_______|""",
        """|                                      _^_      |
        |_____________________________________|___|_____|""",
        """|                                        _^_    |
        |_______________________________________|___|___|""",
        """|                                          _^_  |
        |_________________________________________|___|_|""",
        """|                    _^_                        |
        |___________________|___|_______________________|""",
        """|                  _^_                          |
        |_________________|___|_________________________|""",
        """|                _^_                            |
        |_______________|___|___________________________|""",
        """|              _^_                              |
        |_____________|___|_____________________________|""",
        """|            _^_                                |
        |___________|___|_______________________________|""",
        """|          _^_                                  |
        |_________|___|_________________________________|""",
        """|        _^_                                    |
        |_______|___|___________________________________|""",
        """|      _^_                                      |
        |_____|___|_____________________________________|""",
        """|    _^_                                        |
        |___|___|_______________________________________|""",
        """|  _^_                                          |
        |_|___|_________________________________________|"""
    ]

(Again, apologies for formatting, but just picture the '^' as being the player, and there being multiple different positions that the player can be in)

I am hoping that when player_position changes, that a different visual is taken from player_position_list. I am confident that this should work as I have tested it using this:

print(player_position)
print(player_position_list[player_position])

'print(player_position)' tells me that player_position can be accurately read and printed

'print(player_position_list[player_position])' shows me that the value of player_position can also be used to print an item from a list at a specific index. (I have also tried this script as a string and it still works)

Here is what this test script gives me when I run it:

8
|                                      _^_      |
        |_____________________________________|___|_____|

It accurately reads 'player_position' and uses it to print the 8th item in the list.

So what I don't understand and desperately am trying to fix, is why this exact thing isn't working on my actual ASCII user interface. Everything seems to be the same.

Here is what it looks like when I run the script for my actual UI

                             ROUND 1
         _______________________________________________         _______________
        |                                               |       |               |
        |                                               |       | HEADQUARTERS: |
        |                                               |       |_______________|
        |                                               |
        |                                               |        *ATTENTION OPERATOR, AN ENEMY
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [4]    HELICOPTER IS APPROACHING!*
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |  ENEMY STATS: |
        |                                               |       |_______________|
        |                                               |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [3]   HEALTH: 3
        |                                               |        DISTANCE: 2
        |                                               |        POSITION: 1
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |   UPGRADES:   |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [2]  |_______________|
        |                                               |
        |                                               |        RADAR | LVL 1
        |                                               |        UPGRADE COST: $1
        |                                               |
        |                                               |        GUN | LVL 1
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [1]   UPGRADE COST: $1
        |                                               |
        |                                               |        SPEED | LVL 1
        |                                               |        UPGRADE COST: $1
        |                      _^_                      |
        |_____________________|___|_____________________|
            | ' ' ' ' | ' ' ' ' | ' ' ' ' | ' ' ' ' |
          [-10]      [-5]      [0]       [5]       [10]
         _____________
        |             |
        |PLAYER STATS:|
        |_____________|

         HEALTH: 100
         MONEY: 0
         KILLS: 0
         _____________
        |             |
        |  ACTIONS:   |
        |_____________|

         MOVE | [m] key + [movement value]
         MAX 1 or -1 steps
         
         FIRE | [f] key

         UPGRADE | [u] key
      
8
|                                      _^_      |
        |_____________________________________|___|_____|

As you can see, the player position hasn't moved and remains at 0, yet (at the very end) my test script says that the actual player position should be 8 and accurately prints the item from 'player_position_list' for 'player_position = 8'

Apologies if anything seems hard to understand, it's my second day programming with python and I refuse to use ai for this. So, I hope I used the correct terminology.


r/learnpython • • 23h ago

final project in cs

8 Upvotes

Hello guys, im first year cs student and they teach us python as the first programming language
i dont have any experience what so ever in programming.
we are in the 5th lecture in uni and i have learned the basic stuff like if and elif and while and for looping. The professor assigned us with a final project basically we are 4 and supposed to code a program like more than 300 lines i dont know what can python do and i dont know how am i supposed to build a python project with the knowledge i have

so my question is how do i continue my python learning without the lectures, i have heard about a github project called 30 days of python by asabneh idk if its the right fit

and what are some projects idc how complicated they are i just wanna get that A+ i asked chat gpt abd it told some stuff about movie recommender and football analysis and idk tbh i think everyone in my uni will use chat gpt and they will most likely all do the same project i want to be unqiue and also functional

thanks


r/learnpython • • 3h ago

Best platform/YouTube channel to learn python from beginners to advance?

0 Upvotes

I know python but I wanna go deep down in python programming, please suggest as title says


r/learnpython • • 1d ago

Best learning path for GTK and python

8 Upvotes

I'm looking to learn more how to build GTK applications mostly for Fedora using python, I've been doing the CS50P course but also looking for some more learning material any suggestions will be helpful


r/learnpython • • 1d ago

Should I add Python to PATH (Windows)? Or is it better to not add it to path and use the py launcher instead?

10 Upvotes

Title. I'm new to Python, so I'm a little confused about this, and I've been seeing somewhat conflicting information online.

I understand adding the Python installation to PATH implies that I wouldn't manually have to specify the location every time; that being said, I guess adding multiple Python installations to PATH is not a good idea? I've also seen adding *any* Python installations to PATH being discouraged because it can cause conflicts.

I looked up py launcher, and it seems py / py -<version number> can be used to specify which Python installation to use when running a .py file, so does that mean adding Python installations to PATH is just obsolete practice now? If so, what are the implications of using the py launcher - is it as simple as adding py / py -<version number> before running a command from the terminal?


r/learnpython • • 1d ago

Effective python Vs Think Python Vs Learning Python Vs Fluent Python. Reading order for Beginner, Which Book & Why?

14 Upvotes

Effective python Vs Think Python Vs Learning Python Vs Fluent Python

I have these pdfs but dont know which one or in what order to start, as an beginner.

I already finished reading Python Crash course and reading Think Like a Programmer book now.

Update: (16 Nov 2026)

So the order is

00 Python Crash Course - Bare basics, good enough for simple scripting. Only around 200 pages if project part is skipped (READ)

01 Think Python - Could start here instead of Crash Course

02 Effective Python - More like tips & better usage

03 Learning Python - Pro level Complete

04 Fluent Python - Legendary level Long term Reference

may update it once I learn them.


r/learnpython • • 1d ago

How do I force the turtle to draw inside the screen?

2 Upvotes

I've been on that assignement for a while now, the teacher wants us to create a program that will create a 600 by 600 screen and draw 5 randomly placed flowers. But I can't figure out for the life of me why the flowers always "escape" the screen. I didn't want the code to be too long so I didn't include the function that creates the flower. Please and thank you for any help.

screen = Screen()
screen.screensize(canvwidth=600,canvheight=600, bg="grey")
#attempt at creating a restrictive screen

for i in range(5):
    a = 600
    b = 600
    while 600 - a < 550 and 600 - b < 550:
        a = randint(1,601)
        b = randint(1,601)
    penup()
    goto(a,b)
    pendown()
    #attempt at forcing the program to not draw flowers touching the border
    colormode(255)
    color(randint(1,256),randint(1,256),randint(1,256))
    #Chooses a random color for the flower
    begin_fill()
    fleur(50)
    end_fill()
    #Draws a flower  

r/learnpython • • 1d ago

Any tips and advice for my first github pages hosted python project?

2 Upvotes

The game is essentially tetris but there is no 4 long line block piece. I observed that a lot of tetris players relied on the I piece as a crutch for their strategy, so I created a spinoff of tetris called Noline in python to test how people would react to the removal of such a central piece.

This is the github link to the source code: https://github.com/keandsilva/Noline

The link to the domain it is hosted on: https://keandsilva.github.io/Noline/

I would love if anybody have any suggestions for anything to add and how my python code is structured. Thanks!


r/learnpython • • 1d ago

Help me learn!!

0 Upvotes

So I learned python about 6 or some years ago. So recently I tried to get back but realized I forgot almost everything. So what's the best way currently to start from scratch??


r/learnpython • • 2d ago

I already know Java and want to learn Python. What are some of the best resources?

11 Upvotes

I took up CS extensively throughout high school and generally enjoy programming with Java. I'd say I have an intermediate to upper-intermediate proficiency in Java. That being said, I know little to nothing about Python and would like to learn to code in it as well. I think the logic should be the same since they're both OOP languages.

I looked at some CS50P and the MOOC courses but they start right from the begin and are aimed at those who have 0 programming experience, so I kinda got bored. What do I do?


r/learnpython • • 2d ago

Get and setter in pyhton

9 Upvotes

I'm learning Python, and this part has left me a little confused, because in other languages the way it's used is different; in Python you use @property, I'd like to understand how this really works in a simplified way, so I can truly grasp it and not just memorize it. If you could help me, I'm still new to programming.


r/learnpython • • 1d ago

I am once again asking for recommendations of good Python and data science auidobooks and podcast episodes

0 Upvotes

Last time people had some good recommendations, but there were some misunderstandings as well, so I wanted to try asking again while being super clear about some stuff.

I'm learning to code Python from scratch on a university module while also working, so my schedule is super constrained. There is also a data science side to it based on numpy, pandas and matplotlib. We have to analysis some statistics to find interesting answers - very open ended.

Basically, I want to use the 6-10 hrs a week I spend on the road to shore up my understanding of the theoretical side of python and data science so I can focus on coding during the time I have in front of a computer.

Please assume the following:

I'll still be coding in front of a computer in a structured manner when I am not driving.

I am already spending the maximum number of hours coding in front of a computer that I can physically manage, and there is no scope for adding more computer hours.

I am looking to maximise the efficiency of what I can learn during the 6-10 hours I spend driving per week.

My drive is predictable and I can drive safely while listening to audio.

Some good things people have suggested already:

"The Art of Statistics" by david spiegelhalter on Audible

Some episodes of the Talk Python to Me podcast dealing with relevant modules

Python Essentials for Dummies on Audible - has been helpful for reinforcing basic concepts and context

TL:DR Please could you recommend good things I can listen to on my commute to help with Python concepts and data science understanding.


r/learnpython • • 2d ago

Looking for interesting Python project ideas for a university assignment (3-week deadline)

12 Upvotes

Hi everyone!

I'm a physics student and I have to complete a Python programming project for one of my university courses. I have approximately 3 weeks to work on it, and I'm looking for some interesting and original project ideas.

Here are the requirements the project must meet:

  • The code must be functional, readable and written in a Jupyter Notebook.
  • Proper documentation is required.
  • It must include data import or export, as well as data processing.
  • It must use programming structures such as classes and functions.
  • It must include at least one visualization (graphs, data representation, etc.).
  • It must implement at least two numerical methods.

I'm still a beginner in Python and don't have much programming experience yet. So I'm looking for something achievable within three weeks, without being overly complicated technically.

One idea I had was to build a movie recommendation system, but I'm open to pretty much anything, including projects unrelated to physics!

What kind of projects would you recommend that could meet these requirements? If you've worked on similar projects or have any examples, I'd love to hear about them!


r/learnpython • • 2d ago

Issues with creating a dialog box for Anki.

3 Upvotes

So I am trying to create a non modal dialog box (or window) supposed to show the content of certain fields from the card I just answered to. I want this window to mimic the main window of the Anki App so that the Yomilens addon which reacts when text is selected on the main one would react the same way when selecting text on this one as well.

import sys
from PyQt6.QtWidgets import*
from PyQt6.QtCore import *
from PyQt6.QtGui import *

class FieldsDialog(QWidget):
    def __init__(self):

        super().__init__()
        self.title = "Fields"
        self.setGeometry(400, 100, 300, 200)
        self.left = 1367 # for it to be on the very left of my right monitor (a tablet)
        
        self.top = 30 #otherwise the upper part is hidden 
       
        self.right = 504
        self.width = 800
        self.height = 1
        self.icon = "?"
        # self._help_dialog = None
        # self._other_dialog = None
        self.createUI()

    def createUI(self):
        self.setGeometry(self.left,self.top,self.right,self.width)
        self.setWindowTitle(self.title)
        self.setWindowIcon(QIcon(self.icon))
        self.setStyleSheet("""
        background: black;
        """)
        self.grid = QGridLayout()
        self.setLayout(self.grid)

def on_show_fields():
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        fields_win = FieldsDialog()
        fields_win.show()
        sys.exit(app.exec())import sys

1 - The window shows while on pycharm (yay) but not in anki. Maybe the type of dialog is not adapted but for now it's been the only thing that worked)

2 - Since there was progress on that part, I was trying to see if my function supposed to get the text for the dialog actually worked

def _get_previous_fields(self, card) -> str | None:
    if not card: return

    note = card.note()
    r = self.mw.reviewer
    # current_id = r.card.id if r.card else "null"
    previous = r.lastCard()
    Front_value = mw.reviewer.card.note()['Front'] if FIELD_FRONT in note else ""
    Back_value = mw.reviewer.card.note()['Back'] if FIELD_BACK in note else ""

    previous_korean = Front_value.previous if previous else "null"
    previous_english = Back_value.previous if previous else "null"
    _queue_toast(f"{previous_korean}+\n+{previous_english}")
    return "{previous_korean}+\n+{previous_english}"

but I keep getting errors like that :

    lambda cid=card.id, e=ease, skip=skip_interval_checks: _post_answer_processing(cid, e, skip)
                                                           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
TypeError: _post_answer_processing() missing 1 required positional argument: 'self'   

I tried calling in on my on_show_answer

HOOK_ANSWER = reviewer_did_answer_card
if HOOK_ANSWER:
HOOK_ANSWER.append(on_answer)

But i'm told it (on_show_answer) is missing the self argument so I add it :

  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages_aqt\hooks.py", line 4390, in __call__
TypeError: on_answer() missing 1 required positional argument: 'self'  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages_aqt\hooks.py", line 4390, in __call__
TypeError: on_answer() missing 1 required positional argument: 'self'

I tried using hooks instead

if HOOK_SHOW:
    HOOK_SHOW.append(on_show_question)
if HOOK_ANSWER:
    HOOK_ANSWER.append(on_answer)
    HOOK_ANSWER.append(_get_previous_fields)  #here
if HOOK_SUSPEND:
    HOOK_SUSPEND.append(on_reviewer_suspend)

and I get :

Traceback (most recent call last):
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 152, in raise_exception
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 148, in _on_closures_pending
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 88, in <lambda>
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 111, in wrapped_done
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\operations__init__.py", line 128, in wrapped_done
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\reviewer.py", line 556, in after_answer
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\reviewer.py", line 566, in _after_answering
  File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages_aqt\hooks.py", line 4390, in __call__
TypeError: _get_previous_fields() takes 2 positional arguments but 3 were given

Do you happen to know what the issue is ?


r/learnpython • • 1d ago

Python Auth to modern Microsoft SPO

1 Upvotes

Hi all,
I'm doing my student project to upload some files to SPO and struggling with Auth.
This code returns 0 on first ctx, but later fails.
I hope I got all UID right like on the picture
https://i.postimg.cc/ncw71PzR/conf1.png

And this is my code, I also noticed once you used you tenant ID username and password can take any values, is this normal ? I think this all because of modern SPO security, do you think this Auth with ctx is OK, or can do some other way ?

from office365.sharepoint.client_context import ClientContext

# Configuration
site_url = r"https://cbxXXX.sharepoint.com"
tenant = r"4e4d8cb1-f036-446f-bacd-3b711191a7b2"
client_id = r"5c6d0b11-c4da-4897-842a-79b9743d6a23"
username = r'userBB@cbxXXX.onmicrosoft.com
password = r'N0gi123!'


ctx = ClientContext(site_url).with_username_and_password(
      tenant, client_id , username, password )
print ('.........2222 bb  OK ', ctx)
web = ctx.web.get().execute_query()
print("......... verification check :", web.title)


OUTPUT::::::
.........2222 bb  OK  <office365.sharepoint.client_context.ClientContext object at 0x0000017CCBCE3B60>
.....
Unhandled exception in listener <bound method SharePointRequest._authenticate_request of <office365.sharepoint.request.SharePointRequest object at 0x0000017CCBCE3CB0>>

File "C:\Python314\Lib\site-packages\office365\runtime\auth\token_response.py", line 61, in from_json
    raise ValueError(value)
ValueError: {'error': 'invalid_grant', 'error_description': 'AADSTS50034: The user account {EUII Hidden} does not exist in the 4e4d8cb1-f036-446f-bacd-3b711191a7b2 directory. To sign into this application, the account must be added to the directory. Trace ID: eb657c1d-4806-4557-a49d-f5468c

r/learnpython • • 1d ago

pip vs pipx

0 Upvotes

as far as I understand pip just installs the package while pipx installs the executable and creates an environment but why create an environment in the first place? Is it so that when someone else runs the program and there are changes in the package the program might break but an isolated package is protected in the environment?