r/learningpython • • Aug 27 '22

Does not recognize the directory. Help

Post image
2 Upvotes

r/learningpython • • Aug 27 '22

How to pass a parameter within a file name?

2 Upvotes

I’m trying to save three different excel files out of pandas for v1, v2, v3. The code is parameterised using a function with the parameter x taking values v1, v2, v3. How can I pass x within the file name r”C: ……\Output\x.xlsx”? This just generates a file with the name x, whereas I’d want it to take the input values.

For reference, if this were a SAS macro, adding & before the variable did the trick.

Many thanks!


r/learningpython • • Aug 25 '22

How to continue after exception in Python?

Thumbnail
devhubby.com
2 Upvotes

r/learningpython • • Aug 22 '22

Just started, what do you think of the official Python Tutorial? A good place to start?

2 Upvotes

https://docs.python.org/3/tutorial/index.html <--- The official Python Tutorial


r/learningpython • • Aug 14 '22

Image fetcher

2 Upvotes

I would like to develop an Image Fetcher which can download images from any search engine which are 'Creative Common' and crop them after downloading .. anyone could guide what libraries I can use? Thanks


r/learningpython • • Aug 12 '22

What are some good python projects for beginners?

Thumbnail devhubby.com
2 Upvotes

r/learningpython • • Aug 06 '22

VS Code won't let me make a new python file.

2 Upvotes

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 • • Aug 04 '22

OOP Error

2 Upvotes

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 • • Jun 28 '22

Learning Python

2 Upvotes

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 • • Jun 26 '22

Please help!

2 Upvotes

When I go to run the code, only 3 lines show. Can someone please explain/tell me what I am doing wrong?


r/learningpython • • May 29 '22

PYQT5 MDI subwindows are scaling inappropriately.

2 Upvotes

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)

self.mainMenuWidget.show()

##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()

mdiwindow.show()

app.exec_()

if __name__ == '__main__':

main()

------------------------------------------------------

Thanks for any and all help!


r/learningpython • • May 25 '22

Case study: How we created Hotel Revenue Management Software for USA hotel

Thumbnail
ddi-dev.com
2 Upvotes

r/learningpython • • Mar 28 '22

I need help with isintance()

2 Upvotes

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 • • Mar 24 '22

Python Text Adventure "Try Again" Input Restart

2 Upvotes

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 • • Feb 25 '22

How is this invalid syntax?!

Post image
2 Upvotes

r/learningpython • • Nov 24 '21

how to iterate through a list of strings and lists

2 Upvotes

Hi there,

how can i iterate through such a list? thanks in advance!

lst = ['nonoffensive', ['What', 'in', 'the', 'actual', 'fuck', '?', '#mkr'], ['#mkr', 'WHAT', 'A', 'GODDAMN', 'SURPRISE'], ['This', 'is', 'why', 'this', 'show', 'is', 'ridiculous', '-', "it's", 'not', 'about', 'the', 'cooking', '...', "it's", 'about', 'the', 'game', 'playing', '.', '#mkr', '#whogivesa1'], ['Absolute', 'bloody', 'bullshit', '.', 'So', 'much', 'shit', 'of', 'bull', '.', '#mkr'], ['@MKR_Official', 'a', '1', "isn't", 'strategy', ',', "it's", 'bastedry', '#mkr2015', '#mkr'], 'offensive', ['WTF', '!', '!', '!', 'I', 'not', 'a', 'huge', 'fans', 'of', 'the', 'promo', 'girls', 'but', 'they', 'never', 'voted', 'strategically', '!', 'This', 'sucks', '!', 'Soo', 'annoyed', '!', '#mkr', '#killerblondes']]

r/learningpython • • Nov 23 '21

Using Pyautogui locateOnScreen function

2 Upvotes

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 • • Nov 17 '21

Why is it important to be able to culculate the height of a binary tree?

2 Upvotes

Is that a good skill to have or will it be another useless thing to know?


r/learningpython • • Nov 16 '21

Alternatives to declaring empty list and appending

2 Upvotes

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 • • Nov 13 '21

beginner

2 Upvotes

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 • • Nov 06 '21

I keep getting a syntax whenever i try to use the pip command and nothing is working

2 Upvotes

title


r/learningpython • • Oct 09 '21

how do I assign tags to a canvas.

2 Upvotes
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 • • Oct 04 '21

how do you draw basic shapes with the simplest amount of code using tkinter?

2 Upvotes

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 • • Oct 04 '21

help plz

2 Upvotes

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 • • Sep 09 '21

Where is the `NoneType` class?

2 Upvotes

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.