I know this has been asked before, but I couldn’t find an answer for my problem and all of the answers got me more confused. So I created a class called Books, which takes as input a file location and the name of the file, and has a method called countwords which counts the words of the file. I created
Tag: python-3.x
unittest assertionError in python AssertionError: != 200
I’m writing python tests with unittest and requests modules but getting AssertionError: <Response [200]> != 200 Tests are setup in two functions, test_get and test_post. Test runners starts from Tests class, where the issue is within test2. I’ve tried to assert this also: <Response [200]&…
Is calling a “private” variable from a parent class (as a child class) violating Encapsulation
I am trying to understand more about the scopes of python variables. As of now, I do not want to break or violate encapsulation on variables that are declared to be private i.e., “self._variable”. I was wondering whether if it would be breaking encapsulation if a child class directly calls a varia…
My PyQt application not works with error – This application failed to start because no Qt platform
I developed a Python program using PyQt5 in Windows 10, and it works very well. Then i made it into .exe file with pyinstaller, but it failed and gave me an error. I searched for similar problems in here and google, but i couldn’t find the same problem – running .py works well but .exe failed. Fol…
GRequests monkey patch warning
I get the following warning each time , though the module works as expected : I tried the workaround mentioned at this github issue but that doesn’t work. How to get rid of this warning ? Answer For grequests you would need to add the following code before other modules try to import / load gevent and s…
Creating and declaring list in class
I am trying to create a list within a class and then declaring elements in that list. I don’t even know if this is the right way for python. I have some java background. I didn’t add 10 elements in the list manually because I feel creating a dynamic list will be more useful. Answer Your problem li…
How to capitalize only first letter of first word in a list
I want to capital only first letter of first word of list and remaining all words to be in lower case in ascending order of the length of word. I want the result like this in ascending order of length. In the are lines order printed reverse : Actual output that I am trying to get: Answer Your code does
A full and minimal example for a class (not method) with Python C Extension?
Everywhere, I can easily find an example about writing a method with Python C Extensions and use it in Python. Like this one: Python 3 extension example How to do write a hello word full featured Python class (not just a module method)? I think this How to wrap a C++ object using pure Python Extension API (py…
Unable to exit tkinter app when using “wait_variable()”
I have a python code that includes tkinter window and other running tasks. I’ve been trying to bind “WM_DELETE_WINDOW” event to a function that exits my python code when I close the window but can’t achieve that. This is what I try: The window is destroyed successfully but the python c…
Why isn’t setattr(super(), …) equivalent to super().__setattr__(…)?
According to this answer: setattr(instance, name, value) is syntactic sugar for instance.__setattr__(name, value) But: What gives? Shouldn’t they both do the same thing? Answer The answer you linked to glosses over some important details. Long story short, setattr bypasses super’s magic, so it tri…