r/learningpython • u/stormosgmailcom • Aug 25 '22
r/learningpython • u/extremexample • Aug 22 '22
Just started, what do you think of the official Python Tutorial? A good place to start?
https://docs.python.org/3/tutorial/index.html <--- The official Python Tutorial
r/learningpython • u/stormosgmailcom • Aug 12 '22
What are some good python projects for beginners?
devhubby.comr/learningpython • u/SonicEmitter3000 • Aug 06 '22
VS Code won't let me make a new python file.
I have checked to make sure that Python is installed with the command prompt and it is. I also can open any saved Python files and the programs work, but for some reason I cannot make a new python file. I even switched interpreters but to no avail. The only thing that changed was that Mircosoft installed some add on for photos which I didn't give permission for or want and promptly deleted it. This issue did not come from deleting this add on.
Any help would be appreciated. I just want to make new python files again.
r/learningpython • u/Panfilofinomeno • Aug 04 '22
OOP Error
I am trying to learn OOP and I came across this error...
[<class name> object at <random characters>] What is the general meaning of it?
r/learningpython • u/[deleted] • Jun 28 '22
Learning Python
I’ve been learning Python from the Udemy course by Tim Buchalka. I wanted to know should I just continue to progress through the course, or focus on each section. By focus I mean as in practicing make my own data to play around with, read docs, and look at other’s code. So far I’ve just been going with the flow of the course and when I get stuck I refer to the docs and stack overflow. I usually just refer back to a doc on what I’m looking for to solve my issue. Just want to know what helped others.
r/learningpython • u/Quartz_manbun • May 29 '22
PYQT5 MDI subwindows are scaling inappropriately.
I'm working on a gui tool-- I'm building it with Pyqt5. I'm speifically NOT using QT designer. I'm using an MDI widget to keep everyhing a bit tidier. Furthermore, so that my code is more crisp and less redundant, I'm building out each child window in a separate window in the same directory and then just importing the appropriate class from the individual files. The problem is, whenver I import the subwindows, the are scaled up in the MDI subwindow. I am at a loss as to how I can address this. Has anyone expierenced something similar? I've added simplied code for my MDI subwindow below, followed by the code for one of the subwindows thta I'm importing. Any assistance would be greatly appreciated.
class MDIWindow(QMainWindow):
count = 0
htntoolcount = 0
copdcount = 0
def __init__(self):
super().__init__()
self.mdi = QMdiArea()
self.setCentralWidget(self.mdi)
self.setStyleSheet('font-size: 10pt; font-family: Times;')
self.setStyleSheet("QPushButton{font-size: 10pt;}")
self.setStyleSheet("QLabel{font-size: 10pt;}")
self.mdi.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.mdi.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
#####Setting up main Menu Labels and Buttons#####
self.mainMenuWidget = QWidget(self)
self.mmWidgetLayout = QVBoxLayout()
self.mainMenuWidget.setLayout(self.mmWidgetLayout)
self.mainMenuWidget.setWindowTitle("Main Menu")
self.mmButton1 = QPushButton("Note Setup Tool", self)
self.mmButton2 = QPushButton("Lab Entry Tool", self)
self.mmButton3 = QPushButton("Follow Up Tools", self)
self.mmButton4 = QPushButton("ROS Generator", self)
self.mmButton5 = QPushButton("Physical Exam Generator", self)
self.mmButton6 = QPushButton("Cardon Matrix", self)
self.mmButton7 = QPushButton("Trilogy Matrix", self)
self.mmButton8 = QPushButton("ASC Matrix", self)
self.mmButton9 = QPushButton("Proactive Email", self)
self.mmWidgetLayout.addWidget(self.mmButton1)
self.mmWidgetLayout.addWidget(self.mmButton2)
self.mmWidgetLayout.addWidget(self.mmButton3)
self.mmWidgetLayout.addWidget(self.mmButton4)
self.mmWidgetLayout.addWidget(self.mmButton5)
self.mmWidgetLayout.addWidget(self.mmButton6)
self.mmWidgetLayout.addWidget(self.mmButton7)
self.mmWidgetLayout.addWidget(self.mmButton8)
self.mmWidgetLayout.addWidget(self.mmButton9)
self.mdi.addSubWindow(self.mainMenuWidget)
##adding actions to main menu buttons##
self.mmButton1.clicked.connect(self.noteSetupFunc)
self.mmButton2.clicked.connect(self.admissionTool)
self.mmButton3.clicked.connect(self.COPDToolFunc)
self.setWindowTitle("Proactive Charting Tool")
def noteSetupFunc(self):
self.noteSUButtFuncWidget = NOTEWindow()
self.mdi.addSubWindow(self.noteSUButtFuncWidget)
self.noteSUButtFuncWidget.show()
Subwindow code below.
class NOTEWindow(QWidget):
def __init__(self):
super().__init__()
self.notemdi = QWidget()
self.setStyleSheet('font-size: 10pt; font-family: Times;')
self.setStyleSheet("QPushButton{font-size: 10pt;}")
self.setStyleSheet("QLabel{font-size: 10pt;}")
#Setting MAin Menu Widget for this nested MDI#
self.NOTEmainMenuWidget = QWidget(self)
self.noteMMWidgetLayout = QVBoxLayout()
self.NOTEmainMenuWidget.setLayout(self.noteMMWidgetLayout)
self.NOTEmainMenuWidget.setWindowTitle("Note Menu")
self.mmButton1 = QPushButton("Note Setup Tool", self)
self.mmButton2 = QPushButton("Lab Entry Tool", self)
self.mmButton3 = QPushButton("Follow Up Tools", self)
self.mmButton4 = QPushButton("ROS Generator", self)
self.mmButton5 = QPushButton("Physical Exam Generator", self)
self.mmButton6 = QPushButton("Cardon Matrix", self)
self.mmButton7 = QPushButton("Trilogy Matrix", self)
self.mmButton8 = QPushButton("ASC Matrix", self)
self.mmButton9 = QPushButton("Proactive Email", self)
self.noteMMWidgetLayout.addWidget(self.mmButton1)
self.noteMMWidgetLayout.addWidget(self.mmButton2)
self.noteMMWidgetLayout.addWidget(self.mmButton3)
self.noteMMWidgetLayout.addWidget(self.mmButton4)
self.noteMMWidgetLayout.addWidget(self.mmButton5)
self.noteMMWidgetLayout.addWidget(self.mmButton6)
self.noteMMWidgetLayout.addWidget(self.mmButton7)
self.noteMMWidgetLayout.addWidget(self.mmButton8)
self.noteMMWidgetLayout.addWidget(self.mmButton9)
self.NOTEmainMenuWidget.show()
def main():
app = QApplication(sys.argv)
font = QFont('Times', 10)
app.setFont(font)
mdiwindow = NOTEWindow()
app.exec_()
if __name__ == '__main__':
main()
------------------------------------------------------
Thanks for any and all help!
r/learningpython • u/randol_karter • May 25 '22
Case study: How we created Hotel Revenue Management Software for USA hotel
r/learningpython • u/Triiiiiip • Apr 26 '22
Converting time/date to one uniform timezone in pd df
I have a dataframe with the datetime information in one column and what the corresponding timezone for this timestamp is (e.g Asia/Bahrain) in another column. With these two information i now want to convert all the datasets to one uniform timezone e.g. Europe/London. I can’t find something that needs the underlying timezone as input „Asia/Bahrain“ or whatever the dataset holds and the target timezone „Europe/London“. Does anyone have an idea how to solve this?
r/learningpython • u/GenZBoiii • Mar 28 '22
I need help with isintance()
I'm a semi-beginner in Python, and I know that I might sound stupid asking for help with a sort of simple problem like this, but I really need to know how to fix it for a programme I am coding. I have cut out the bit of code from the programme that I need help fixing.
guess = int(input("Have a guess: "))
res2 = isinstance(guess, str)
if res2 == True:
print ("That's not a valid number.")
print (guess)So, the problem I have is that the isinstance() function isn't working, due to multiple factors. What I have said is the variable 'guess', is where the user has to input an integer. The variable 'res2' checks if the variable 'guess' is a string and the 'if' loop checks if it is true. If it is, it should print 'That's not a valid number.' and then the variable 'guess'. But what happens is, whenever the user inputs a string, it obviously crashes the programme as 'guess' is for the user to input an integer, and not a string. And you would think that I should change it to a normal input, but the code below tells you why I can't.
import randit
number = random.randint(1, 100)
if guess > number:
print("Guess lower...")
if guess < number:
print("Guess higher..")The variable 'number' is a random integer between 1 and 100. Since 'guess' wants an integer from the user, changing 'guess' to not wanting just an integer will treat it as a string, meaning you cannot use the 'if guess > number:' function as 'guess' would be treated as a number.
If anyone knows a way to fix it, or if you have any advice, please reply to this post. Have a good day!
r/learningpython • u/epppy • Mar 24 '22
Python Text Adventure "Try Again" Input Restart
Alright, so I'm attepting to make a text adventure. Let me show you the code.
# system module. lets us end
import sys
#lets us wait between prints. seconds only. time.sleep(seconds)
import time
time.sleep(2)
print("{REDACTED} and {REDACTED} present")
time.sleep(3)
print("A text adventure \n")
time.sleep(3)
print("T")
time.sleep(0.4)
print("H")
time.sleep(0.4)
print("E \n")
time.sleep(0.4)
print("I")
time.sleep(0.4)
print("N")
time.sleep(0.4)
print("G")
time.sleep(0.4)
print("R")
time.sleep(0.4)
print("O")
time.sleep(0.4)
print("L")
time.sleep(0.4)
print("E")
time.sleep(0.4)
print("V \n \n")
time.sleep(0.4)
time.sleep(0.6)
time.sleep(1)
print("Loading...")
time.sleep(1.7)
#CODE STARTS HERE
playGame = input("would you like to play a game?\nType y or n: ")
if playGame == ("n"):
time.sleep(1)
print("\nThe Ingrolev must be stopped. Not by you, but by someone else.")
time.sleep(1.72)
print("Goodbye, soldier.")
# waits 1 second
time.sleep(1)
# exits system
sys.exit()
else:
print("that is not one of the commands above.")
time.sleep(0.5)
print("please try again.")Alright, so clearly when it says "Try again" nothing will actually happen. I was wondering if anyone has any good ideas as to whether I would be able to make the code go back to the original 'playGame' input.
r/learningpython • u/len12901kirby • Nov 23 '21
Using Pyautogui locateOnScreen function
When I use the pyautogui's locateOnScreen function, it says it cannot find that particular file. I tried with different pngs it says "FileNotFoundError: [Errno 2] No such file or directory" on Thonny.
Why is this?
r/learningpython • u/Available-Citron2749 • Nov 17 '21
Why is it important to be able to culculate the height of a binary tree?
Is that a good skill to have or will it be another useless thing to know?
r/learningpython • u/Gorm_the_Mold • Nov 16 '21
Alternatives to declaring empty list and appending
I have created some automated processes, however I find myself always leaning heavily on declaring empty lists at the beginning of my script and later appending information to the empty list.
For example if I want python to return the names of files in a directory that use a certain file type, I use fnmatch and then append the file names to an empty list to be used later:
file_names = []
for file in os.listdir('C:\My_dir'):
if fnmatch.fnmatch(file, '*.csv'):
file_names.append(file)I know there are better practices and am wanting to improve and develop better habits.
r/learningpython • u/AlternativeMouse9616 • Nov 13 '21
beginner
for i in range(0,2): #i=[0,1]
for k in range(3,0): #k=[3,2,1]
print(k*2 + i*0, k='*''\t')
this is my sauce code for printing *. where did I made mistake?
*
**
***
***
**
*
r/learningpython • u/[deleted] • Nov 06 '21
I keep getting a syntax whenever i try to use the pip command and nothing is working
title
r/learningpython • u/dbor15 • Oct 09 '21
how do I assign tags to a canvas.
back = Canvas(window,width=500,height=400,bg='white')so this back variable is what I'm trying to give a tag to, can anyone tell me how to assign a tag to it?
r/learningpython • u/dbor15 • Oct 04 '21
how do you draw basic shapes with the simplest amount of code using tkinter?
just some basic shapes like squares and circles and lines. I already know how to set up a tab with the mainloop function, I just need to know what the simplest code possible for a beginner like me to understand and grasp it.
r/learningpython • u/[deleted] • Oct 04 '21
help plz
def groups_per_user(group_dictionary):
user_groups = {}
# Go through group_dictionary
for ___:
# Now go through the users in the group
for ___:
# Now add the group to the the list of
# groups for this user, creating the entry
# in the dictionary if necessary
return(user_groups)
print(groups_per_user({"local": ["admin", "userA"],
"public": ["admin", "userB"],
"administrator": ["admin"] }))
r/learningpython • u/[deleted] • Sep 09 '21
Where is the `NoneType` class?
I know int, str, and None come from builtins module. But it seems that NoneType is not in the builtins module. I wonder where I can find or even import it.
Same question about NotImplementedType.
Amazingly. type(None).__module__ shows it is builtins, but I failed to import builtins.NoneType. Maybe Python prohibits users from importing NoneType.
r/learningpython • u/my-tech-reddit-acct • Sep 04 '21
A question: which is better, stylistically ("Pythonicness"?) or otherwise.
I have a list of sorted lists. I want to grab an element of each in turn and print it out until I've printed them all. The lists are of different length.
At first I rolled my own:
lol_files = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i', 'j', 'k']]
while any(lol_files):
for l in lol_files:
if l:
print(l.pop(0))And that works, and looks clean to my eye (albeit a bit "arrowhead-y"). But then I ran across zip_longest in itertools and thought this must yield a bettter, 'more pythonic' way.
But there kept on being gotchas, so the briefest I could make it was:
lol_files = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i', 'j', 'k']]
from itertools import zip_longest, chain
for f in [x for x in chain(*zip_longest(*lol_files)) if x ]:
print(f)which could also have been:
print('\n'.join([x for x in chain(*zip_longest(*lol_files)) if x ]))The *lol_files is coz zip_longest doesn't do the right thing with the structure a list of lists - it wants the literal, comma-separated, manual entry of a list of lists. The * fixes that.
Ditto for chain(*zip_longest(... although the chain.from_iterable form is available, but I was fighting for brevity at this point, which is also why the specific imports.
And then I had to wrap that in [ x for x in .... if x] because zip_longest insists on putting something in place of the elements not filled by the shorter lists, and what ever it is I don't want to print that, as it won't be a proper filename. (I could have used filter(lambda x: x, ...) but I'm pretty sure the list comprehension version is considered 'more pythonic'. Plus the shit starts looking like Lisp, lol.
The longer form is:
import itertools
for f in [x for x in itertools.chain.from_iterable(itertools.zip_longest(*lol_files)) if x]:
print(f)r/learningpython • u/doughnutwardenclyffe • Sep 01 '21
What does name_var.set(" ") and passw_var.set(" ") do in this code? Currently self teaching tkinter.
Hello,
I have taken the code below from the geeksforgeeks website. I am using their tkinter tutorial to teach myself how to make GUIs via python.
I am having trouble understanding the code. I do not understand what is the purpose of name_var.set(" ") and passw_var.set(" ").
I removed those two lines of code from the submit function, and was able to get the same result.
Could someone explain to me the significance of those two lines of code?
geeksforgeeks link: https://www.geeksforgeeks.org/python-tkinter-entry-widget/
# Program to make a simple
# login screen
import tkinter as tk
root=tk.Tk()
# setting the windows size
root.geometry("600x400")
# declaring string variable
# for storing name and password
name_var=tk.StringVar()
passw_var=tk.StringVar()
# defining a function that will
# get the name and password and
# print them on the screen
def submit():
name=name_var.get()
password=passw_var.get()
print("The name is : " + name)
print("The password is : " + password)
name_var.set("")
passw_var.set("")
# creating a label for
# name using widget Label
name_label = tk.Label(root, text = 'Username', font=('calibre',10, 'bold'))
# creating a entry for input
# name using widget Entry
name_entry = tk.Entry(root,textvariable = name_var, font=('calibre',10,'normal'))
# creating a label for password
passw_label = tk.Label(root, text = 'Password', font = ('calibre',10,'bold'))
# creating a entry for password
passw_entry=tk.Entry(root, textvariable = passw_var, font = ('calibre',10,'normal'), show = '*')
# creating a button using the widget
# Button that will call the submit function
sub_btn=tk.Button(root,text = 'Submit', command = submit)
# placing the label and entry in
# the required position using grid
# method
name_label.grid(row=0,column=0)
name_entry.grid(row=0,column=1)
passw_label.grid(row=1,column=0)
passw_entry.grid(row=1,column=1)
sub_btn.grid(row=2,column=1)
# performing an infinite loop
# for the window to display
root.mainloop()