All Questions
4 questions
-1
votes
2
answers
801
views
How to decide if a global variable is used inside or outside a function in Python?
In Python variables that are created outside of a function are known as global variables. However to create a global variable inside a function (a local variable), you can use the global keyword.
My ...
-4
votes
4
answers
3k
views
Creating one function for multiple purposes vs multiple functions for one purpose each [closed]
I have one function that is used to compute distances of an object in 3 different ways.
Is one of the following two methods considered better practice:
Creating 3 different functions, one each for ...
4
votes
2
answers
263
views
Design of multi-test function to validate a string
Assume that I wish to perform an action on a string (e.g., print the string) if, and only if, the string first passes several tests. The tests are diverse (and may even be complex functions themselves)...
1
vote
2
answers
1k
views
Assigning dictionary values to variables before using them as function arguments
I find myself often having a function, for example authenticate:
authenticate(user, token):
# do authentication
and a dictionary created by reading a configuration file, like this:
conf['general'...