[Solved] Does this class violate SOLID’s single responsibility principle? [closed]

As your class above has atleast two responsibilities i.e. creating a database connection and performing CRUD operations on the entities, so I think it violates the SOLID’s single responsibility principle. You might create a seperate class to deal with the Database connection and register it as a dependency (through an interface) to the Database class … Read more

[Solved] i want to generate an exception when user enters integer values instead of String value.. how can i do it?

Since you are interested in Type Checking, You may want to reverse your Logic a little bit like so: def log_in(): user_name1 = “xyz” user_name = input(“Enter your username:\n”) # str() try: # FOR YOUR USE CASE, IT WOULD SUFFICE TO SIMPLY TRY TO CAST THE ENTERED # INPUT TO AN INT (INITIALLY) – REGARDLESS … Read more

[Solved] How to find consecutive strings in nested lists [closed]

Is this what you’re looking for? To initialize the list with the first keyword for row in range(len(locations_and_xy)): if keywords[0] in locations_and_xy[row]: new_locations_and_xy = locations_and_xy[row:] Then we can do this for i in new_locations_and_xy: print ([i for j in keywords if j in i]) [[‘Add’, ‘1215’, ‘697’]] [[‘to’, ‘1241’, ‘698’]] [[‘Cart’, ‘1268’, ‘697’]] Edit To … Read more

[Solved] Connecting strings in a element without using double for loops Python [duplicate]

Use itertools: import itertools #to include pairs with same element (i.e. 1-1, 2-2 and 3-3) >>> [“-“.join(pair) for pair in itertools.product(lst, lst)] [‘1-1’, ‘1-2’, ‘1-3’, ‘2-1’, ‘2-2’, ‘2-3’, ‘3-1’, ‘3-2’, ‘3-3’] #to exclude pairs with the same element >>> [“-“.join(pair) for pair in itertools.permutations(lst, 2)] [‘1-2’, ‘1-3’, ‘2-1’, ‘2-3’, ‘3-1’, ‘3-2’] 2 solved Connecting strings … Read more

[Solved] How to scrape a website table that you cannot select the text using python? [closed]

It’s just a matter of finding the right url and then parsing it: import requests import pandas as pd url=”https://service.fantasylabs.com/live-contests/?sport=NFL&contest_group_id=71194″ headers = {‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36’} jsonData = requests.get(url, headers=headers).json() contestIds = {} for each in jsonData[‘live_contests’]: contestIds[each[‘contest_name’]] = each[‘contest_id’] rows = [] for contestName, contestId … Read more

[Solved] google cloud doesn’t work with previous f-string python

This line of code imports the Google Cloud SDK into an object named storage. import google.cloud import storage You then declare a string named storage with the contents of the bucket name. This overwrites the previous line of code. storage=f’gs://{bucket_id}/’ You are then trying to create a Cloud Storage Client object from a string object: … Read more

[Solved] move all folders modified after to new folder [closed]

import os from shutil import move from time import time def mins_since_mod(fname): “””Return time from last modification in minutes””” return (time() – os.path.getmtime(fname)) / 60 PARENT_DIR = ‘/some/directory’ MOVE_DIR = ‘/where/to/move’ # Loop over files in PARENT_DIR for fname in os.listdir(PARENT_DIR): # If the file is a directory and was modified in last 15 minutes … Read more

[Solved] How to make a folder instantly (as os.makedirs() creates a folder after the program has finished)?

Its the “no such file” side of the “No such file or directory” error. You need to include “w” write mode to create the file. filePassword = open(r”C:\Users\NemPl\Desktop\ProLan\Python\Python programi\user.” + profileName + “\pass.” + profilePassword, “w”) solved How to make a folder instantly (as os.makedirs() creates a folder after the program has finished)?

[Solved] Get max value in a two value list Python [duplicate]

Use the max built-in function with key kwarg. Refer to the docs of max for more details. It will return the sublist that has the max number, from which we take the first element (the “name”). li = [[‘ABC’, 1.4976557902646848], [‘LMN’, 1.946130694688788], [‘QRS’, 3.0039607941124085]] print(max(li, key=lambda x: x[1])[0]) # QRS You can use itemgetter instead … Read more

[Solved] Creating vertical dictionary from text file

if index==3: indexes=line.split(“\t”) for index in indexes: Old_Values=Old_Values{[key]} # What here? As I understand it, what you want there is simply an empty list to put the corresponding elements from the subsequent lines in: Old_Values[index] = [] Which will give you: {‘WebAddress’: [], ‘Address’: [], ‘Surname’: [], ‘Name’: [], ‘Telephone’: []} I don’t know where … Read more

[Solved] What is the point of the sep=”” at the end?

The default value for sep is a space. By setting it to an empty value you print without spaces between the 3 inputs. You could easily have tried this without the sep argument to see the difference: >>> print(“There are <“, 2**32, “> possibilities!”, sep=””) There are <4294967296> possibilities! >>> print(“There are <“, 2**32, “> … Read more