python-3.9

Python argparse with optional positional and default None

Python argparse with optional positional and default None Question: Working with Python and argparse, trying to accomplish the following: $> my_app Namespace(positional=None) $> my_app file.txt somedir Namespace(positional=[‘file.txt’, ‘somedir’]) i.e., a positional argument of type list, whose default is None. I would expect the following code to accomplish this: p = argparse.ArgumentParser() p.add_argument("positional", nargs=’*’, default=None) print(p.parse_args()) …

Total answers: 2

How would I put a API's output into different variables in Python?

How would I put a API's output into different variables in Python? Question: So I am using a riddle API and whenever it is ran it outputs it data like this: [ { "title": "The Magic House", "question": "There is a house,if it rains ,there is water in it and if it doesn’t rain,there is …

Total answers: 1

HTTPS error 401 when running discord bot in python

HTTPS error 401 when running discord bot in python Question: I get this error whenever i run my bot: Traceback (most recent call last): File "C:UsersAdminAppDataLocalProgramsPythonPython39libsite-packagesdiscordhttp.py", line 801, in static_login data = await self.request(Route(‘GET’, ‘/users/@me’)) File "C:UsersAdminAppDataLocalProgramsPythonPython39libsite-packagesdiscordhttp.py", line 744, in request raise HTTPException(response, data) discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized The above exception …

Total answers: 1

Python discord bot errors

Python discord bot errors Question: I am getting the TypeError: expected token to be a str, received NoneType instead error in python when trying to run my bot. Here is the full error: Traceback (most recent call last): File "d:PythonProjectsdisco botppap", line 20, in <module> client.run(os.getenv(‘TOKEN’)) File "C:UsersAdminAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 828, in run asyncio.run(runner()) File "C:UsersAdminAppDataLocalProgramsPythonPython39libasynciorunners.py", …

Total answers: 1

How to make the square have blue lines and be at the front of the green line?

How to make the square have blue lines and be at the front of the green line? Question: I want to make the square appear at the start of the green line and be blue. How do I do that? from turtle import * color(‘green’) begin_fill() forward(200) end_fill() import turtle turtle.color(‘blue’) # Creating a for …

Total answers: 1

TypeError: __call__() missing 1 required positional argument: 'context'

TypeError: __call__() missing 1 required positional argument: 'context' Question: I want to create a program to send an email with a discord bot but when i laucnh my program i have this error. My code to send an email works fine in a separate file but when i put in in my python discord bot …

Total answers: 2

"Typeerror int is not collable" from http requests.post()

"Typeerror int is not collable" from http requests.post() Question: I know this question has come up a lot, but I couldn’t find any suitable solution for my problem. from the library requests I try to use something like this: response = requests.post(url, headers, data, proxies) if response.status_code >= 300: logging.ERROR(f"MY ERROR MESSAGE") elif response.status_code < …

Total answers: 1

Is it the best way to create an array from a list of objects?

Is it the best way to create an array from a list of objects? Question: I have a list of objects stored in socialmedias variable. One parameter of SocialMedia class is called username. I want to create an array with all usernames from that list of objects socialmedias and I want to be sure I …

Total answers: 4

Python: How to prevent special characters in input

Python: How to prevent special characters in input Question: My problem is when I enter a number in the input field, it becomes number with special character. I don’t know why it’s adding extra characters to input. You can see the example. I entered just 5.2 and it became ‘5.2& """ length of rectangle = …

Total answers: 2