luminousmen
I P
Back

__context__ vs __cause__ attributes in exception handling

Since Python 3.0, raising an exception in an `except` block will automatically add the caught exception in the `__context__` attribute of the new one. That will cause both exceptions to be printed. Essentially this is a way for the current exception to carry information about the previous exception. For example: ```python try: raise ValueError('ValueError') except ValueError: raise...

Resolve cython and numpy dependencies on setup step

I have a custom Python package on my project where some functionality implemented on Cython. We use it to speed up some of the slowest parts of our code - the syntax is pretty close (it can be identical except some imports) to regular Python. Cython compiled to .so libraries and it has support for fast access to NumPy arrays. The problem - Cython and numpy packages need to be installed before...

Optional arguments MUST use keywords (Python3)

Imagine that you are developing software for the big shipping company(why would you imagine small anyway). And you got a task to create a function for calculating a charge for ships based on their cargo weight. Easy breezy: WEIGHT_RATES = [ ( 10, 10.55), ( 5, 5.05), ( 2, 3.35), ( 0, 1.25) ] def shipping_charge(weight): if weight < 0: raise ValueError("Can't calculate shipping charge of...

Python interview questions. Part III. Senior

We all know that senior is not just a technical role that bound with years of experience and knowledge about his tools, they also have mentoring skills, some management skills in order to measure tasks and their time, and they tend to have some architecture skills etc. My questions here is only for technical side of Python senior developers. Questions Q: When will the else part of...

Python interview questions. Part II. Middle

Questions Q: What is the output: -12 % 10? Q: What is the output: -12 // 10? Q: What is the sequence of call operators in the expression a ** b ** c? Q: What are the steps required to make a script executable on Unix? Q: What is an iterator? What is a generator? What is the difference between them? Q: Why shouldn't the default argument be to make an empty list? Q: Let A and B be objects of...

Python interview questions. Part I. Junior

I am starting a series of posts about my own base of interviewing questions. Of course, it is not full and it doesn't have any answers and maybe some of the questions seem weird or even stupid, but I think they are good for finding the right candidate for Python position.   Questions Q: What is Python? What are the key features of Python? Q: What Python libs did you use? Q: What is pass in...