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 • • 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 10 '20

Python module compatibility

2 Upvotes

Hi all

Python noob so please bear with me

I'm writing some AWS Lambdas using Azure's eventhub module and I'm hitting some issues with c_uamqp not loading (I don't use this module directly, it's eventhubs dependency) but It all works ok locally...

Which got me thinking if python modules aren't all cross OS compatible as I develop on a Mac and I'm guessing Aws runs on Linux.

So my question is, are python modules always cross OS compatible or are there some that just won't work with some OS's?

Thanks!


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 • • 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

r/learningpython • • Oct 31 '20

how do i search for a specific value in a dictionary using a user input?

2 Upvotes

'''

here is my code

i want to be able to type in an actor's name and have their role returned, but i dont know how to do it

i think im onto something in the third last line, but idk what to do after that

'''

def dictionary_converter():

actor_keys = ['Graham Chapman','John Cleese','Terry Gilliam','Eric Idle','Terry Jones','Michael Palin',\

'Connie Booth','Carol Cleveland','Neil Innes','Bee Duffell','John Young','Rita Davies',\

'Avril Stewart', 'Sally Kinghorn','Mark Zycon','Sandy Johnson','Julian Doyle','Richard Burton']

role_values = ["Arthur", 'King of the Britons','Sir Lancelot the Brave','Patsy', "Arthur's Servant", \

'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', \

'Sir Galahad the Pure', 'Miss Islington, the Witch','Zoot', "Leader of Robin's Minstrels", \

'Old Crone', 'Frank, the Historian', "Frank's Wife'", 'Dr. Piglet','Dr. Winston']#, \

'Sir Robin (Stand-in)', 'Knight Who Says Ni', 'Police Sergeant who stops the film', "One-legged Black Knight (Stand-in)"]

dictionary = {}

for key in actor_keys:

for value in role_values:

dictionary[key] = value

role_values.remove(value)

break

searched_name=input('what actor would you like to look up? ').title()

print(searched_name)

for searched_name in actor_keys:

#???

dictionary_converter()


r/learningpython • • Oct 21 '20

Need help with dictionaries and return values.

2 Upvotes

Need an explenaton why dictionaries requires no return as you would need if you wanted to update a variable in the same way (python 3):

def rTest1(dic):
    dic[2] = "woof"
 
def test1():
    i = {1: "dog", 2: "bark"}
    print(i)
    rTest2(i)
    print(i)

# Where as

def rTest2(value):
    value = 5
    return value 

def test2():
    x = 3
    print(x)
    x = rTest2(x)       # requires assigning the function call to x, 
    print(x)            # and for the value to be returned

i want to know why rTest1 updates a dictionary outside of its scope, or am i looking at it wrong?


r/learningpython • • Oct 20 '20

Where to find feedback on code?

2 Upvotes

I wrote a chess independence calculator for a job challenge. It was the largest python program I'd written and I'm looking for some feedback on the code. More like a mentor than just a brief comment. Where can I find such a thing?


r/learningpython • • Sep 14 '20

Is it possible to include or force the requests lib in my parent code so users don't have to install it?

2 Upvotes

r/learningpython • • Sep 14 '20

Python Programming Made Easy for Beginners - Lesson 3: Variables

Thumbnail
youtu.be
2 Upvotes

r/learningpython • • Sep 06 '20

Tutorial on how to create good quality REST API with Django

Thumbnail reddit.com
2 Upvotes

r/learningpython • • Sep 05 '20

How do people deal with unknown object types?

2 Upvotes

If I am running some TensorFlow project and an hour later some object that is returned by one of the TensorFlow functions is incompatible with an object that it input into another TensorFlow function it crashes the code.

In C++ I can look at each object's data type and its member variables, and if it doesn't match the prototype of the input function, it simply won't compile. I dont have to waste hours on running the code until it gets to that error.

How do people deal with this? The only thing I can do is copy and paste code and hope it works


r/learningpython • • Sep 04 '20

A minimal framework for web automation with docker

2 Upvotes

Hello Folks,

I would like to share with you my small project, I thought it might help people doing automation, and want to run their script in a reproducible manner using docker containers.

Here is the repo link: https://github.com/ayoubeddafali/docker-selenium-bootstrap

I would be grateful if you could share your insights, and what could be improved.

Thanks,


r/learningpython • • Aug 24 '20

networking scripts

2 Upvotes

I need to create a script in python that will that will build a list of all ports on all switches on a given vlan. So I am just trying to extract all the tagged and untagged ports from the output and create a list with it. Any help would be great. It is an hpe switch.


r/learningpython • • Aug 19 '20

Learning Python playlist on Youtube - Promotion post

2 Upvotes

This is a promo/advert post. I've started a youtube playlist for learning python, any comments, criticisms, and helpful discussions welcome here.

Thank you.

https://www.youtube.com/playlist?list=PLgGQIE0cGrkh4gFIKIeTUfprHZrqV6tOQ


r/learningpython • • Aug 08 '20

Troubleshooting Python module importing problems?

2 Upvotes

Hi,

I have installed beautifulsoup and get a module not found error when I try to import it (import bs4 as BeautifulSoup). I've uninstalled and reinstalled Python. It works fine in Anaconda, but Anaconda seems to create its own sandboxes for each project or something. I can't get it work using regular old IDLE.

I'm running Python 3.8.6, and installed it with pip3 in the usual fashion (with and without --user, in my case, cause I wasn't sure what the difference is).

The problem seems to be common but I'm now on day 2 without a resolution. Is there some general troubleshooting techniques I can use or breadcrumbs I can follow to troubleshoot a module not working on my setup?

Edit:
if I attempt to reinstall I get this message - it seems to be installed fine.

pip3.8 install --user beautifulsoup4

Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.8/site-packages (4.9.1)


r/learningpython • • Aug 02 '20

What´s the easy way to understand the difference between yield and return

2 Upvotes

In this quarantine I was reading a book about data structures and algorithms but in a part they talk about yield.

I imagine like if we have a list of names but to make the programm more "light" we use yield to not save this list in the memory. ¿I´m wrong?


r/learningpython • • Jul 21 '20

Please give me your feedback and advice. I really, really appreciate it.

2 Upvotes

I was recently laid off and live in the LA area. I have experience with graphic design, layout, print media though I went to school for multimedia (Animate, some Dreamweaver). I would ultimately like to acquire skills to become a web developer or multimedia developer. I need to understand some things better before choosing a path and committing time and money to long-term skills development. It would mean a lot to me if you gave me feedback on these items:

  1. is it realistic, based on your experience, that there are positions that specialize in both of those things; web development and multimedia development?

  2. machine languages, skills I want to develop are HTML, CSS, Python, Ruby. Do you think these are appropriate for the above goal?


r/learningpython • • Jun 26 '20

Which one is cleaner to use?

2 Upvotes
if variable.attr in (1, 2):
    some_list.append(variable)

or

if variable.attr == 1:
    some_list.append(variable)
elif variable.attr == 2:
    some_list.append(variable)

The code executed inside of the if statement will always be a single line of code


r/learningpython • • Jun 17 '20

Is there an online text editor or IDE i can use?

2 Upvotes

I cant download an ide on my laptop and would like to use an online ide. Also i just like 2 weeks ago


r/learningpython • • Jun 03 '20

What's the difference?

2 Upvotes

Hi,

When I type the following code below,

x = [4, 6, 7]

for index in enumerate (x):

print (item, index)

I get the following output

7 (0, 4) 7 (1, 6) 7 (2, 7)

But when I type the following code below:

x = [4, 6, 7]

for item, index in enumerate (x):

print (item, index)

I get the following output:
0 4 1 6 2 7

What about adding "item" made the results so different?

Thanks!


r/learningpython • • Jun 02 '20

What am I doing wrong here? I wanted to collect only the values "html_url" from the json url...

2 Upvotes

This is my code:

@ app.route('/string2')

def string2():

return github.get('/search/code?q="string2"')['html_url']

This is the error:

KeyError: 'html_url'

It works without ['html_url']

The output of URL is pure JSON. I wanted filter only html_url entries (which are many). I am exhausted, its 1:58AM here.... any advice is welcomed, thanks!