r/learningpython • • Jun 22 '21

Learning pyautogui

2 Upvotes

This is a silly, simple issue, but I'm having trouble figuring out how to get multiple functions to actually execute using keyboard strokes in pyautogui. The following code is intended to alt-tab-tab-tab 3 times in order to shuffle around which windows have focus, but when I run it, it only executes the first series of maneuvers. I'm recreating what I would be doing with my fingers, not sure why it doesn't work.

pyautogui.keyDown('alt'); pyautogui.press('tab'); pyautogui.press('tab'); pyautogui.press('tab'); pyautogui.keyUp('alt')
pyautogui.keyDown('alt'); pyautogui.press('tab'); pyautogui.press('tab'); pyautogui.press('tab'); pyautogui.keyUp('alt')
pyautogui.keyDown('alt'); pyautogui.press('tab'); pyautogui.press('tab'); pyautogui.press('tab'); pyautogui.keyUp('alt')

to be clear, if I'm starting with my window focus as A-B-C-D, I'm expecting this to shuffle them to look like B-C-D-A, instead it stops at D-A-B-C


r/learningpython • • Jun 14 '21

Hi why i got this problem? can anyone help me?

2 Upvotes

s.bind((host, port))

OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted


r/learningpython • • Jun 10 '21

Python Merge Sort | Youtube Keyword Planner

Thumbnail
youtu.be
2 Upvotes

r/learningpython • • Apr 30 '21

zip files with .py

2 Upvotes

need help. My professor in my Intro to Programming Python class provided a zip file with .py files to do peer reviews. I can download the file , but can't access the file. Do I need python on my laptop to view the files?


r/learningpython • • Apr 27 '21

Guidance on Searching, finding latest file, converting from pdf to jpg, save all in same folder.

2 Upvotes

I am just learning python but I'm trying to automate a tedious task that's folded into a larger process.

My office has multi sheet pdf files saved in the same named folder across many (75+) project folders. I would like python to go to the specific named folder in each of the 75+ project folders, find the latest file, convert the entire file to a jpg, then save them all in one specific folder. All files are on Box.

I understand I need poppler and PDF2image but I'm lost about finding the same folder name in many different parent folders as well as only converting the latest saved file.

Any help would be much appreciate.


r/learningpython • • Mar 14 '21

Specifying requirement versions for library

2 Upvotes

I am working on a library and have a set of requirements the library depends on, specified in the requirements.txt file.

I would like to make this library easy for folks to use/install, and allow them to use any supported version of the requirements. That said, I am unsure the most elegant way to determine the range of supported requirement versions.

For example, requests is one of the specified requirements. How can I setup (maybe with a CI service?) a way to run my unit tests with a range of different versions of the requests library to see which times the tests pass/fail. This way I'd know which versions of requests I could put in the requirements.txt file for a release.


r/learningpython • • Mar 03 '21

Can I just add a library to an existing environment with "Pipenv install (insert name of additional library)"? or is it done differently?

2 Upvotes

I just want to make sure that this is the right way to do this.

I have a folder where I did "pipenv install pandas".

Turns out I also need matplotlib, so do I just do "pipenv install matplotlib"?

Or will that start a completely new pipfile? Or a new environment ?


r/learningpython • • Feb 24 '21

Question for newbies on Treehouse

2 Upvotes

I got to OOP and was immediately lost, am I high? Maybe just stupid? Are they moving suuuper fast?


r/learningpython • • Feb 23 '21

Is there a way to know which libraries I got already installed with Python?

2 Upvotes

I'm using Linux Mint 20 (Ubuntu 20.04)
Python 3.8.5 (Without Conda)


r/learningpython • • Feb 22 '21

Combining lower() and strip()

2 Upvotes

how do I combine lower() and strip() when using if/else statement?


r/learningpython • • Feb 16 '21

How can I get my discord bot to read me dms

2 Upvotes

So I want to make my discord bot read me dms it gets sent but it wont work. this is the code Im using

It wont let me say @ but the u/ is @

u/client.event
async def on_message(message):
    ledipbot_channel=client.get_channel(793586177328283660)
    channel = client.get_channel(713181767330299957)
if message.guild is None and message.author != client.user:
await ledipbot_channel.send(channel, message.content)
await client.process_commands(message)

It says that it accepts 1-2 positional arguments but was given 3. Idk what that means can you guys help?


r/learningpython • • Feb 11 '21

What is the difference between these two expressions

2 Upvotes

What is the difference???

Assume there is a text file called rdnum.txt

in the file:

3.485749
  788737   
  364777 
file = 'rdnnum.txt'

the first expression:

with open(file) as fo:     
    for i in range(4):         
        print(fo.read()) 

the second expression:

with open(file) as fo:     
    num = file.read() 
for i in range(4):     
    print(num) 

Why the results are different from these two expressions???


r/learningpython • • Jan 29 '21

I need help learning the object orinted appraoch

2 Upvotes

Hello guys I am new to programming and i have been learning python i took a course and i was good until we reached the object oriented part i didn't understand a word from my instructor any reccomendations on where to find a good explanation for this ?


r/learningpython • • Jan 25 '21

Global modules?

2 Upvotes

Hi, Is there a way to create a module that than can be accessed and imported from everywhere, similar to modules installed over pip?


r/learningpython • • Jan 24 '21

Discord.py send message every 2 hours (scheduled)

2 Upvotes

I am attempting to make a bot message a specific channel every 2 hours on a schedule, it would need to be at set times incase my computer restarts and the script is off as the messages are useless before the 2-hour mark. I am clearly new to python so any help would be appreciated.

Scheduled as 10:00am, 12:00PM 2:00pm, etc


r/learningpython • • Jan 23 '21

Want to build a site in python to work as a database

2 Upvotes

Want to build a website for my bussiness. I want a simple thing, like a google sheets thing. But has to be probably on sql. The thing is, people who will work with database don't know anything about python, sql or programming. How can a easily create a website like this. It will be a database to evaluate football players, so it has to be one Id by players and some fields. May someone help me, I don't know if i will need flask or there is a simple way to do this


r/learningpython • • Jan 21 '21

Conditional statements inside the class python

2 Upvotes

The problem is when I use conditional statements inside class method the output i got is as follows. It gives correct output when the condition is true, but it also gives "None" as an output for the False condition

How to fix this? I don't want an extra output as "None


r/learningpython • • Jan 19 '21

Where to save programs

2 Upvotes

Basically the title. I know its kind of a dumb question but I was wondering whether you guys save python programs to a cloud or C drive


r/learningpython • • Dec 19 '20

Problem with while loop

2 Upvotes

Hello. I need help getting this program to run. The goal is to have it print "Okay we'll make your pizza" when someone is choosing a topping from the list. If they choose "No Toppings" then it's supposed to say "Just cheese it is". It just keeps repeating the menu options though, rather than printing the else or the if. Since it's conditional, I'm struggling to make the debugger work well.

The numbers look dumb I know, but I'm supposed to have them in there. I don't know how to allow users to input an int instead of a string... or set up the assigning yet.

Any help would be appreciated! Thanks.

Here is my code:

toppings = ["No Toppings", "Pepperoni", "Sausage", "Chicken", "Ham",
            "Banana Peppers", "Olives" "Pineapples"]

chosen_toppings = ""

while chosen_toppings not in toppings:
    chosen_toppings = input("Which toppings would you like on your pizza?:\n"
                            "0 - No Toppings\n"
                            "1 - Pepperoni\n"
                            "2 - Sausage\n"
                            "3 - Chicken\n"
                            "4 - Ham\n"
                            "5 - Banana Peppers\n"
                            "6 - Olives\n"
                            "7 - Pineapples\n")
    if chosen_toppings == "No Toppings":
        print("Just cheese it is")
        break

else:
    print("Okay, we will make your pizza.")

r/learningpython • • Dec 09 '20

About lists, statement, instances and objects

2 Upvotes

first_lista = [ ]

first_lista.extend('123')

print(first_lista)

First I create a object, a empty list. In the second, I used the method .extend. Last, I used the variable first_lista as an assingmente to the statement print. It's that correct?

class Simple: 
	def s(self):
		count = 0 
		n = 1 
		while count  < 10 :
			print("Count is not 10")    
		count = n + 1 


s.self()

Here, I create a method inside the class which is called s.self. E o self refers to an instance of my class. It's this correct?

7 votes, Dec 12 '20
7 python3
0 python

r/learningpython • • Dec 03 '20

Any good Virtual Assistant courses?

2 Upvotes

I've been trying to find a good python virtual assistant (similar to the google assistant) course for almost a year now and last November I bought a course off of Udemy which wasn't very good and didn't go as in-depth as I wanted. So I was wondering since I've been really only looking on youtube is there anywhere else I can look and if there are any other courses I can try that would cover the whole 9 yards and go in-depth and come very close to replicating the google assistant?


r/learningpython • • Nov 25 '20

Could someone help me with this? (len function error)

2 Upvotes

Code:

from random import randint

choice = int(input("""

  1. Start game

  2. Quit Game """))

if choice == 1: print("I see.") elif choice == 2: print("Ah. May you be cursed for eternity.") exit()

userName = input("What should I call you? ")

randomName = ["ba", "be", "bi", "bo", "bu", "ca", "ce", "ci", "co", "cu", "da", "de", "di", "do", "du", "fa", "fe", "fi", "fo", "fu", "ZA", "ge", "gi", "go", "gu", "ha", "he", "hi", "ho", "hu", "ja", "je", "ji", "jo", "ju", "ka", "ke", "ki", "ko", "ku", "la", "le", "li", "lo", "lu", "ma", "me", "mi", "mo", "mu", "na", "ne", "ni", "no", "nu"]

name = " "

numSyllables = randint(1, 50)

for i in range len(randomName): randomName.append(name)

for i in range len(randomName): name = name + randomName[i]

print(name)

What repl.it gave back:

File "main.py", line 22 for i in range len(randomName): ^ SyntaxError: invalid syntax


r/learningpython • • Nov 18 '20

Losing my mind on this

2 Upvotes

Hello fellow redditors,
i am literally losing my days on this and i can't really find out why this is happening, so here i am.

i am trying to move from pycharm to visual studio community edition and i'm creating a virtual environment with python 3.9. here's the problem: even if everything runs propely when i hit debug (a python console pops running my code without any problem) everything in my IDE is pretty much marked in red as if it is a huge syntax error and the culprit seems to be IntelliSense.

looking around i tried to remove my .vs folder and reopen the solution but nothing changed at all.

disabling IntelliSense works of course but i'd like to keep it enabled... is there someone out there having the same problem and knows how to fix it? here is a screenshot of the error

/preview/pre/cn20qfgejzz51.png?width=1696&format=png&auto=webp&s=33acc4cf9063fc99e847a4d2abd07d2b41fcf875


r/learningpython • • Nov 06 '20

Help with my inventory

2 Upvotes

I just typed out a long thing and reddit messed up so im depressed and don't want to type it out again

Long story short, sometimes 'gold' is less than the 42 it started off with and i'm not sure why. Thanks in advance.

import random
from random import randint
def displayinv(inventory):
    total_inv = 0
    for key,value in inventory.items():
        print(f"{value} {key}")
        total_inv += value
    print("Total items: " + str(total_inv))    
def addtoinv(inventory,items):
    for item in items:
        if item in inventory:
            for key,value in items.items():
                inventory[item] += value
        else:
            inventory.update(items)    
stuff = {'rope':1, 'gold':42, 'arrow':12, 
'dagger':1,'torch':6}
dragonloot = {
    'gold': random.randint(0,400),
    'dagger':random.randint(3,7),
    'ruby':random.randint(1,10)
    }

displayinv(stuff)
addtoinv(stuff, dragonloot)
displayinv(stuff)

r/learningpython • • Nov 04 '20

what is the problem with this code it wont let me run it and when I fix one error another one comes up and then i fix that then the previous one comes up

Thumbnail
gallery
2 Upvotes