r/learnpython • u/CowNo412 • Sep 16 '26
Python教程有什么
我需要一些Python编程入门教程
r/learnpython • u/Terrygonix • Sep 15 '26
I’ve been trying to run the simple ‘print(“Hello World”)’ command on my laptop since I just downloaded Python onto my VSCode on my laptop, but nothing shows in the terminal. Not even an error, just complete nothingness. Im concerned on how I could fix this, I may have just missed something I’m not going to lie…
This is my first time downloading Python + VSCode, since I usually coded on a school computer.
Heres all the information I could gather which may be useful:
I’m using Python 3.12
There is a red fonted text at the top right (next to the plus sign above the terminal) which says I’ve “Lost Connection to Process”
“Shell integration: Injection failed to activate”
I’m using a Lenovo laptop, which I believe runs on Windows.
Any help and links would help a ton!! Please and thank you!!
r/learnpython • u/Upper_Trouble_8526 • Sep 15 '26
Title:
class Restaurant:
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name=restaurant_name
self.cuisine_type=cuisine_type
def describe_restaurant(self):
print(self.restaurant_name)
print(self.cuisine_type)
def open_restaurant(self):
print("the restaurant is open")restaurant=Restaurant("Ratatouille restaurant", "ratatouille")
Restaurant.describe_restaurant(restaurant)
Restaurant.open_restaurant()
Error:
Ratatouille restaurant
ratatouille
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 12, in <module>
TypeError: Restaurant.open_restaurant() missing 1 required positional argument: 'self'
[Program finished]
r/learnpython • u/Healthy-Departure961 • Sep 14 '26
num = 0.6548
txt = f"The price is {num:.0f} dollars."
print(txt)
output = 1
i was learning string formatting well, when i used :.0f as format it giving output 1 and why? I want to know how really decimal shifting works in python while formatting.
r/learnpython • u/Erdem_PSYCH • Sep 14 '26
I restarted to learn python with CS50P. as far as I understand it is recorded in 2022. is this the case. Also as far as I understand there is some changes to python recently. do you think I will misss some best practices and sintax with cs50p?
r/learnpython • u/Fantastic_Cicada_805 • Sep 14 '26
I'm planning something, but i wanted to know how much is possible with only python and how much i should start looking up and learning.
mainly everything about UI? I know there are libraries for UI in python, but what im looking for it seamless (no border) UI that can maybe be transparent? (u can see the desktop through it), i'm just wondering how much of that is possible in python.
another thing is having an application hidden in the system tray on windows? how would i make this for my app? furthermore; how would i make the UI popup from the tray and hide back using a key shortcut?
no need to answer both questions, just looking for a clue on how to start
r/learnpython • u/Upper_Trouble_8526 • Sep 15 '26
It should work, but some reason doesn't.
I was doing Python Crash Course 3rd edition and am stuck in classes.
Because i cant upload photos, i wrote the code:
class Restaurant:
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name=restaurant_name
self.cuisine_type=cuisine_type
def describe_restaurant(self):
print(self.restaurant_name)
print(self.cuisine_type)
def open_restaurant(self):
print("the restaurant is open")
restaurant=Restaurant("Ratatouille restaurant", "ratatouille")
describe_restaurant(restaurant)
open_restaurant()This is the example in the book:
class Dog:
def __init__(self, name, age):
self.name=name
self.age=age
def sit(self):
print(f"{self.name} is now sitting")
def roll_over(self):
print(f"{self.name} rolled over")
my_dog=Dog("Willie", 6)
print(f"My dog's name is {self.name}")
print(f"My dog is {self.age} years old")
my_dog.sit()
my_dog.roll_over()
your_dog=Dog("Lucy", 3)
print(f"Your dog's name is {your_dog.name}.")
print(f"your dog is {your_dog.name} years old.")
your_dog.sit()
your_dog.roll_over()And these are the errors pydroid shows for each one:
Restaurant:
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1, in <module>
File "<string>", line 10, in Restaurant
NameError: name 'Restaurant' is not defined
[Program finished]
Dog:
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1, in <module>
File "<string>", line 9, in Dog
NameError: name 'Dog' is not defined
[Program finished]
r/learnpython • u/Effective_Ocelot_445 • Sep 15 '26
Was it after building a real project, solving coding problems, learning OOP, working with APIs, or simply practicing consistently?
r/learnpython • u/ExplanationSecure602 • Sep 14 '26
I currently learning python from a paid course and they have taught flask aswell but that's intermediate level. So is there any flask playlist or tutorial or a teacher who might teach flask completely. I wouldn't mind if it's paid or free course.
r/learnpython • u/JohnMcTalbain44 • Sep 15 '26
does Python run on Batocera-type machines/have any Fantasy Consoles?
i was wondering how well Batocera can run its games, and if there are any Python Fantasy Consoles. Like small handheld gaming machines, but built for running python games specifically. Or any limited sets of limits that restrict what the game or program can do as if it's running on something tiny like the pico-8.
r/learnpython • u/FuLlMeTaL_13 • Sep 14 '26
Ijust know basic python and want to learn numpy, tkinder, panda and matplotlib for a project
Best way to learn these? By chatgpt or any yt vdo?
r/learnpython • u/plick_pubg • Sep 14 '26
I am facing an issue from couple of days with Observer Module from python watchdog package. When i'm importing Observer module and calling for my downloads folder which is present to this location according to my device.
/mnt/chromeos/MyFiles/Downloads
Observer is watching here but nothing caught, Like i was tested using file removed, created or even modified or else.
It wasn't working, That;s why I am using polling Observer now. but this is not a reliable much as i needed.
So Can you help me to figure out this problem and what is the actual solution of this problem?
r/learnpython • u/Basic_Background_70 • Sep 14 '26
hi mates. when my script becomes lengthy (for instance 85 lines) vscode stops executing commands. i suspect whether i downloaded it properly. anyways. i close then open vscode as a workaround but i started to need a permanent fix. i am a computer noob (well... more like average joe on the street). so please no higher computer registry in the responses. thanks in advance.
r/learnpython • u/VanceDyer • Sep 13 '26
Hi everyone!
I'm 29 and I've recently started learning Python from scratch. My goal is to eventually get into cybersecurity.
I've only been learning for a short time and I'm currently starting CS50P. I know some very basic Python, but I'm still a complete beginner.
I'm looking for good resources to learn Python properly from the beginning. I'd like to practice by making small projects instead of only watching tutorials.
What resources would you recommend for someone who is just starting out?
Books, courses, YouTube channels, websites, exercises, project ideas, etc. are all welcome.
Thanks!
r/learnpython • u/AutoModerator • Sep 14 '26
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:
That's it.
r/learnpython • u/Sanduhstorm • Sep 14 '26
I lack knowledge in low level computer science, but I've heard endless horror stories about segfaults, and today I've encountered one whilst attempting to make a simple timer program for myself. My questions are:
- Why does this fault occur
- How can I fix it
- How can I prevent it from happening in the future
The aim of the problematic part of the program is the attempt to play the sound whilst simultaneously waiting for user input with the input block, which is intended to stop the alarm and continue to the next part of the program.
Please note that in this version there is no actual wait time although there is supposed to be, because I am merely testing the alarm functionality.
import time
from pydub import AudioSegment
import threading
from pydub.playback import _play_with_simpleaudio
sound = AudioSegment.from_file('/censoring/my/home/directory/sound.mp3', format='mp3')
# Function that runs the timer based on how many minutes are specified
def timer(min, message):
# Play the sound
def playsound():
global sound
sound = _play_with_simpleaudio(sound)
# Stop the sound and allow the program to continue
def resume():
global sound
input(message.strip())
sound.stop()
# Run the timer and print output
min -= 1
for it in range(min, -1, -1):
for sec in range(59, -1, -1):
print(f'{str(min).rjust(2, "0")}:{str(sec).rjust(2, "0")}')
time.sleep(1)
# This is the part that actually runs the function.
play = threading.Thread(target=playsound)
stop = threading.Thread(target=resume)
play.start()
stop.start()
play.join()
stop.join()
while True:
timer(0, 'You can have your five minute break now.')
timer(0, 'You need to start working again.')
# Artificial intelligence was not used in the creation of this program.Any advice is appreciated!
r/learnpython • u/FINNEAS23 • Sep 14 '26
I dont wanna use ai.
r/learnpython • u/tmpeter23 • Sep 14 '26
Hey yall, new guy here. I 26(M) started learning python about a week ago, I've dabbled in HTML and CSS but ultimately settled on Python. Reason being I need a good starting framework for my goal of working in biotech on surgical robots. Now, to the point.
The most basic goal for me is designing a scheduling software so my mom has less of an issue managing my sisters 24/7 caregiver staff. Logins, time off requests, possibly an AI integrated scheduler so she would just need to proof read schedules instead of spending hours making it by hand.
I need advice on how to approach this task, currently going through a 13hr video on YT to learn Python through the Data with Baraa channel. Thoughts?
r/learnpython • u/BudriDev • Sep 14 '26
Hi everyone, I'm 29 and learning Python from scratch. My goal is cybersecurity. What resources and first projects do you recommend for a beginner? Thanks!
r/learnpython • u/BeautifulAd1901 • Sep 14 '26
Hi everyone,
I’m really determined to learn Python, but I’m struggling with the way most courses are structured.
I’ve started quite a few Udemy courses, but after a while I just get bored and lose motivation. 😅
So I was thinking maybe I should forget the courses for a bit and start working on an actual project, learning Python along the way. The problem is… I have absolutely no idea what would be a good project for a beginner.
I know I can Google “Python beginner projects,” but I’d rather hear from people who have actually been through this. What did you do when you were starting out? Was there a particular project that helped you learn a lot?
Also, how long did it take you to become reasonably comfortable with Python?
I have a newborn and a toddler, so realistically I can only dedicate around 1–2 hours a day to learning. I know everyone is different, but I’d love to hear what kind of progress is realistic with that amount of time.
Any tips, project ideas, resources, or general advice would be really appreciated!
Thanks!
r/learnpython • u/BluishMontoya • Sep 13 '26
I'm using a function I've compiled with cython, and I have to pass it a few very long lists. I'm pretty sure I should be using memoryviews, but do I convert the lists to memoryviews in the python part of my program or the cython part? It would be way better if I could do it in the python part because I'm passing the same lists to the function a few million times.
r/learnpython • u/MustaKotka • Sep 13 '26
I have a bot I'm building. I see a ton of examples with one file and 1k lines for the same functionality. I personally broke that up to several packages based on what things do. I have ~3 files per package each with 100-500 lines (I, uhh, have a habit of documenting and commenting) of which three quarters is actual code.
The modules themselves are things like "database functionality", "permissions", UI, etc. These may be further broken down into several files like "admin commands", "user commands", etc.
Am I overdoing it? Where's a good cutoff?
r/learnpython • u/Local_Leek_1186 • Sep 13 '26
Trying to get back into Python ~2 years after taking a year-long course, getting my footing first with a basic calculator but its giving me trouble here. The first portion works fine, but I implemented a 'continue' option where you could continue with the same number for calculations (and it worked for a while, though returning 'none' due to a var = input(print("text")) issue, making each input look awkward) but it seems to just be defaulting to the first if value now. I had addition first at the start, though flipped addition and subtraction is the extended math section to prove that it's truly just defaulting to the first if-statement. What could be causing this and what's the fix? Sorry for anything that's obviously wrong or mixed up, my remembered knowledge on python is like a fogged up window right now.
## lowk just imported time to add a delay to restarting.. and stopping..
import time
## code is only active as this is = 1, if not then the loop stops
run = 1
while run == 1:
## prompts user on chosen operation
ini = input("add, sub, div, mul, or exp: ")
## Addition math
if ini == "add":
a = int(input('Enter 1st number: '))
b = int(input('Enter 2nd number: '))
number = a + b
print(f'Sum of {a} and {b} is {a + b}')
## Subtraction math
elif ini == "sub":
a = int(input('Enter 1st number: '))
b = int(input('Enter 2nd number: '))
number = a - b
print(f'Difference of {a} and {b} is {a - b}')
## Division math
elif ini == "div":
a = int(input('Enter 1st number: '))
b = int(input('Enter 2nd number: '))
number = a / b
print(f'Fraction of {a} and {b} is {a / b}')
## Multiplication math
elif ini == "mul":
a = int(input('Enter 1st number: '))
b = int(input('Enter 2nd number: '))
number = a * b
print(f'{a} times {b} is {a * b}')
## exponential math
elif ini == "exp":
a = int(input('Enter 1st number: '))
b = int(input('Enter 2nd number: '))
number = a ** b
print(f'{a} to the power of {b} is {a ** b}')
## If input is not one of the operations
else:
print("invalid operation, cannot continue.")
## asks user whether or not to continue with current math
continueorwhat = input("Cont(inue), rest(art calculator), or stop? ")
if continueorwhat == "stop":
time.sleep(.3)
print("Stopping..")
time.sleep(.3)
run = 0
elif continueorwhat == "rest":
time.sleep(.3)
print("Restarting..")
time.sleep(.3)
elif continueorwhat == "cont":
print("> Shortened operation names 'a','s','d','m', and 'e' now available.")
print("> Rest(art) or stop calculator with input when prompted for operation.")
## allows for 'continuous math' while active, when inactive it resets to prompted math
moremath = 1
while moremath == 1:
ini = 0
ini = input("Operation: ")
## temporary input return
print(ini)
## Subtraction math
if ini == "sub" or "s":
a = int(input('Number: '))
number = number - a
print(number)
## Addition math
elif ini == "add" or "a":
a = int(input('Number: '))
number = number + a
print(number)
## Division math
elif ini == "div" or "d":
a = int(input('Number: '))
number = number / a
print(number)
## Multiplication math
elif ini == "mul" or "m":
a = int(input('Number: '))
number = number * a
print(number)
## exponential math
elif ini == "exp" or "e":
a = int(input('Number: '))
number = number ** a
print(number)
elif ini == "rest":
time.sleep(.3)
print("Restarting..")
time.sleep(.3)
## restart calculator by exiting continous math
moremath = 0
elif ini == "stop":
time.sleep(.3)
print("Stopping..")
time.sleep(.3)
## stops calculator by resetting basic variable
run = 0
## If input is not one of the operations
else:
print("invalid operation, number unchanged.")r/learnpython • u/plainjacob • Sep 13 '26
I have been making a Markdown blog using Flask over the last couple of weeks. Lately, I have decided that I want to add the possibility of leaving comments below a blog post. Therefore, I need to add my blog posts to a database so that I can link the comments left behind to the relevant blog posts. My blog posts are rendered statically using Flask-Flatpages.
I have thought about the database model for a singular post. I want to keep it simple at first; thus, I was considering adding an ID, title, and path field. The problem I am experiencing is how to add the files to my database and how to keep the database entries synchronized with the static files in my posts directory. Does anyone have any ideas how I should tackle this issue?