Getting IndexError when trying to use default function arguments, if no commandline arguments are passed to script

Advertisements I’m having some issues with some python logic. Not sure if that’s possible but if it’s possible with bash I guess that’s possible in every other language. I want to use default function argument if no commandline argument is passed to script: #!/usr/bin/env python3 import sys def get_file_name(filename: str = "watched_movies"): if sys.argv[1]: filename… Read More Getting IndexError when trying to use default function arguments, if no commandline arguments are passed to script

How do I implement **kwargs to omit arguments in a function?

Advertisements I’m looking for someone who can explain a solution as simply as possible When making a function, I was wondering if it was possible to optionalize certain arguments in a function. Usually I would get an error saying missing 1 required positional argument: ‘arg1’. using **kwargs may work, any way someone can explain this… Read More How do I implement **kwargs to omit arguments in a function?

what is the difference between argument and parameter in python functions?

Advertisements are these two terms argument and parameter same or they have different meanings in python functions? Please help me with some examples also. can we call actual parameter or actual argument? can we call formal parameter or formal argument? >Solution : Parameters are the variables that accept within the function definition. Arguments are the… Read More what is the difference between argument and parameter in python functions?

Make generic method that takes 2 different generic types in c# is it

Advertisements I’m trying to make method that reads 3 different lists, but they should be generic. We know that a generic list can be read like: public void msgList<T>(List<T> readlist) { //do something with generic readlist, as long as T is Int, double or something else } But suppose you want to read 2 arguments… Read More Make generic method that takes 2 different generic types in c# is it

Is there an elegant way to pass down an argument from function1() down to a function2(), that takes several arguments?

Advertisements I have the following situation: def func1(a = 0, b = 0): return a + b**2 def func2(x): if x == ‘a’: return func1(a = 2) elif x == ‘b’: return func2(b = 2) print(func2(‘a’)) Is there a way to just pass a not as a String and get rid of the if statements?… Read More Is there an elegant way to pass down an argument from function1() down to a function2(), that takes several arguments?

How to put a function as an argument with unspecified sub arguments in C?

Advertisements I am trying to make a function, which will execute a function with the provided sub arguments in C. Like: int function(void (*func)(), …) // add as many arguments you want for ‘func()’ { va_list ptr; … func(sub_arguments) // the ‘…’ } void *abc(int a) { … } void *one(int b, int c) {… Read More How to put a function as an argument with unspecified sub arguments in C?