Category : python-class

Fairly new to classes. I am trying to utilize a class to set a directory where the directory would then be used to access a file in a directory. import json class Dir: def __init__(self, dir): self.dir = dir def get_currencyid(name, dir: Dir): with open(dir + ‘currency.json’, ‘r’) as f: data = json.load(f) currencies = ..

Read more

So I’m trying to build a bot with python and selenium this is my code from selenium import webdriver import os import time class InstagramBot: def __init__(self, username, password): self.username = username self.password = password self.driver = webdriver.Chrome(executable_path=’./chromedriver.exe’) self.driver.get(‘https://www.Instagram.com/’) The problem is nothing will happen when I try the python bot.py I’ve tried py bot.py ..

Read more

I’m pretty new at python OOP and this error seems a simple resolving question, but I can’t find a solution anywhere. I’m getting the same error on two different classes I created and I don’t know why. Can someone help me? These are my classes: import numpy class Activation_Softmax: def forward(self, inputs): exponentiated = numpy.exp(inputs) ..

Read more

I made a class with some embeds for ease of storage: class embeds(): def __init__(self): self.help.main = discord.Embed(title="Help", description="Bot Help", color=0xFF5733) self.help.main.add_field(name="Fun and Games", value="`a!help funandgames`", inline=True) self.help.main.add_field(name="Moderation", value="`a!help moderation`", inline=True) self.errors.invalid_argument = discord.Embed(title="Error", description="Invalid argument") self.errors.requires_int = discord.Embed(title="Error", description="Wrong argument type. Requires int but arguemnt is str") When I send it: embeds = embeds() ..

Read more

I am trying to convert a list which previously has some integer values, strings and floats all to integers, however am running into some issues during the conversion. Here is what I have done: class NumbersIterable: def __init__(self, numbers): self.numbers = numbers print(self.numbers) def runConversion(self): return NumbersIterator.convertNumbers(self.numbers) class NumbersIterator: def convertNumbers(numbers): print(‘in numbers’) for i ..

Read more

I have a decorator responsible for logging. E.g. something like this: import logging import functools from typing import Callable def log_container(func: Callable, logger=None): if logger is None: logger = logging.getLogger("default") @functools.wraps(func) def wrapper(*args, **kwargs): logger.info(f"{func.__qualname__} started.") result = func(*args, **kwargs) logger.info(f"{func.__qualname__} ended.") return result return wrapper I have a class that has a distinct logger ..

Read more