Skip to content

Tag: python-2.7

Return True if array contains a 2 or a 3

I’m having trouble with this CodingBat problem: Given an int array length 2, return True if it contains a 2 or a 3. I’ve tried two different ways to solve this. Can anyone explain what I’m doing wrong? Answer Your first one doesn’t work because the for loop in Python isn’t the sa…

Python inserting variable string as file name

I’m trying to create a file with a unique file name for every time my script runs. I am only intending to do this to every week or month. so I chose to use the date for the file name. is where I’m getting this error. it works if I use a static filename, is there an issue with the

Overriding in Python

I want to be able to do the following I would like to get a parent function from a child class in a function that is overriding it. I am not sure how to do this. This is a little hard to explain, comment if you are having trouble understanding. Edit: Thanks for the answers everyone, I almost thought that

Generate list of numbers in specific format

I need to generate a list of numbers in a specific format. The format is I know how to generate a normal list of numbers using range So, is there any built-in way in python to generate a list of numbers in the specified format. Answer Python string formatting allows you to specify a precision: Precision (opti…

ImportError: No module named mock

So I am trying to use unittest.mock to mock some of my methods in my unit tests. I do: But I am getting: I tried: It’s still not working. Answer unittest is a built-in module; mock is an external library (pre-3.3 betas, anyway). After installing mock via pip install, you import it not by using but Edit:…