arguments

Python – sorted expected 1 argument, got 3 – Trying to understand named arguments

Python – sorted expected 1 argument, got 3 – Trying to understand named arguments Question: I was looking into the sorted() function in Python 3.9 with the following tiny example circus = [(‘a’, ‘b’, ‘c’, ‘d’, ‘e’),(‘w’, ‘x’, ‘y’, ‘z’, ‘a’),(‘k’, ‘l’, ‘m’, ‘n’, ‘o’),(‘u’, ‘v’, ‘w’, ‘x’, ‘y’),(‘q’, ‘r’, ‘s’, ‘t’, ‘u’),(‘e’, ‘f’, ‘g’, …

Total answers: 1

Getting error when I run my program. What do I need to change?

Getting error when I run my program. What do I need to change? Question: import random, string characters = string.ascii_letters + string.digits + string.punctuation def generate_random_password(): length = int(input("How many characters in password? ")) number_of_passwords = int(input("How many passwords would you like? ")) character_count = characters if character_count > str(length): print("To long, try again") return …

Total answers: 2

List comprehension in django orm

List comprehension in django orm Question: I have Gallery model: class Gallery(models.Model): TERMS_CHOICES = [ (1, ‘1 month’), (3, ‘3 months’), (6, ‘6 months’), (12, ’12 months’), ] date = models.DateField(default=datetime.now().strftime(‘%Y-%m-%d’), editable=False) term = models.IntegerField(choices=TERMS_CHOICES, default=1) I’m trying to create a scheduler function: it have to check expired terms, and delete the gallery. If term …

Total answers: 1

Put target function's named arguments into multiprocessing.Process with key=value syntax

Put target function's named arguments into multiprocessing.Process with key=value syntax Question: We have a standard function syntax for passing keyword arguments. We can call foo(arg_1=value1, arg_2=value2) and this works well. But it doesn’t work when I try to put arguments into multiprocessing.Process. This expression multiprocessing.Process(target=foo, args=(arg_1=value1, arg_2=value2)) causes exception: SyntaxError: invalid syntax How can I …

Total answers: 1

SystemExit: 2 , args = parser.parse_args() error

SystemExit: 2 , args = parser.parse_args() error Question: How can I fix this ? parser = argparse.ArgumentParser() parser.add_argument("mode", help="Trains or tests the CNN", nargs="*", choices=["train", "continue", "test", "confusionmatrix", "vote", "slice"]) parser.add_argument("–resume", help="The version to continue training from", required=False, default=False) parser.add_argument("–epochs", help="The number of epochs to finish training from", type=int, required=False, default=False) args = parser.parse_args() print("args", …

Total answers: 1

why the function not taking the argument value in the assigned column?

why the function not taking the argument value in the assigned column? Question: def change_date_column_type(df,change_column_name): df=df.assign(change_column_name=df[change_column_name].astype(‘datetime64′)) # return the result return df result = change_date_column_type(test_df,’release_date’) print(result) output: movie_title release_date genre MPAA_rating change_column_name 0 titanic Dec 21, 1937 Drama R 1937-12-21 1 frozen Feb 9, 1940 Musical PG 1940-02-09 2 rythm Nov 13, 1940 Family G …

Total answers: 1

Python give *args default value

Python give *args default value Question: Inside my class I have: def refresh(self, func = None, *args): if not func: return new_data = func(*args) self.set_text(new_data) But I have 2 problems: What if func doesn’t take any parameters? Why can’t I do *args = None? like I want to do something like this: def refresh(self, func …

Total answers: 4

passing an argument as list using argparse but facing issues

passing an argument as list using argparse but facing issues Question: I am trying to pass a list of values as arguments using this code: parser.add_argument(‘–items’, nargs=’+’, help=’items to buy’) and using this to pass the items: –items=bread milk from debugging I see that it is making a list of one index and that has …

Total answers: 1

Having problems showing an attribute from instance class

Having problems showing an attribute from instance class Question: I know there’s a similar post but following it I couldn’t solve the problem. I have a main class ‘User’, a subclass ‘Admin’ that inherits the methods from ‘User’. Then I have a class ‘Priviledges’. Inside ‘Admin’ there’s a ‘Priviledges’ instance. I want ‘Priviledges’ to show …

Total answers: 1

Trying to have the corresponding answer by typing the room number

Trying to have the corresponding answer by typing the room number Question: def main(): # Initialize dictionaries rooms = { ‘CS101’:3004, ‘CS102’:4501, ‘CS103’:6755, ‘NT110’:1244, ‘CM241’:1411} instructors = {‘CS101′:’Haynes’, ‘CS102′:’Alvarado’, ‘CS103′:’Rich’, ‘NT110′:’Burke’, ‘CM241′:’Lee’} times = {‘CS101′:’8:00 am’, ‘CS102′:’9:00 am’, ‘CS103′:’10:00 am’, ‘NT110′:’11:00 am’, ‘CM241′:’12:00 pm’} course = input(‘Enter a course number:’ ) if course not in …

Total answers: 3