Skip to content
Advertisement

Tag: function

How do I call a function from another .py file? [duplicate]

This question already has answers here: How do I import other Python files? (23 answers) Closed 6 months ago. file.py contains a function named function. How do I import it? The above gives an error: ImportError: No module named ‘file.py’; file is not a package Answer First, import function from file.py: Later, call the function using: Note that file is

python max function using ‘key’ and lambda expression

I come from OOP background and trying to learn python. I am using the max function which uses a lambda expression to return the instance of type Player having maximum totalScore among the list players. The function correctly returns instance of type Player having maximum totalScore. I am confused about the following three things: How does the max function work?

Why do function objects evaluate to True in python?

In python it is valid to make a construction like: I wish to ask what is the logic that a function pointer is evaluated to True. Why was this kind of construction inserted in the language? Answer A lot of things evaluate to True in Python. From the documentation on Boolean operators: In the context of Boolean operations, and also

How can I make a deepcopy of a function in Python?

I would like to make a deepcopy of a function in Python. The copy module is not helpful, according to the documentation, which says: This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types. It does “copy” functions and classes (shallow and deeply), by returning the original object unchanged;

What is the best way to exit a function (which has no return value) in python before the function ends (e.g. a check fails)? [duplicate]

This question already has answers here: return, return None, and no return at all? (5 answers) Closed 4 months ago. Let’s assume an iteration in which we call a function without a return value. The way I think my program should behave is explained in this pseudocode: If I implement this in python, it bothers me, that the function returns

Advertisement