How do I avoid the "self.x = x; self.y = y; self.z = z" pattern in __init__?

Python
I see patterns like def __init__(self, x, y, z): ... self.x = x self.y = y self.z = z ... quite frequently, often with a lot mo...
3 years ago

Numpy array indicing arrays

Python
I'm sure this question is Googleable, but I don't know what keywords to use. I'm curious about a specific case, but also about how to do it in general...
3 years ago

In python, how do I cast a class object to a dict

Python
Let's say I've got a simple class in python class Wharrgarbl(object): def __init__(self, a, b, c, sum, version='old'): self.a = a ...
3 years ago

Get Printer Status Code with win32print

Python
I have read the documentation of win32print which indicates that GetPrinter is the method which is used to obtain the status of the printer. However, ...
3 years ago

pandas: Is it possible to filter a dataframe with arbitrarily long boolean criteria?

Python
If you know exactly how you want to filter a dataframe, the solution is trivial: df[(df.A == 1) & (df.B == 1)] But what if you are accepting use...
3 years ago

installing request module in python 2.7 windows

Python
I am facing issues while installing request module (python 2.7) on windows. Tries the below steps as per docuemntation: 1 pip install requests er...
3 years ago

while (1) Vs. for while(True) -- Why is there a difference?

Python
Intrigued by this question about infinite loops in perl: http://stackoverflow.com/questions/885908/while-1-vs-for-is-there-a-speed-difference, I decid...
3 years ago

How to do multiple arguments with Python Popen?

Python
I am trying to make a PyGtk Gui, that has a button. When the user presses this button, gnome-terminal prompts the user to write their password. Then ...
3 years ago

Decrypting a string into a number

Python
Last week, I was assigned to encrypt numeric PINs into pronounceable strings (made up of vowel-consonant pairs). This went well. This week, I've been...
3 years ago

Capture screen and find reference image

Python
I'm trying to do the following in python: Capture the screen If the screenshot contains a given reference image (can be jpg or pgn), get the coordin...
3 years ago

[Python]Conversion issue: Float --> Bytes and viceversa

Python
i'm struggling with something i cannot solve. I'm developing a Client - Server app, in python ofc, i need to send some "float type" data but sock.send...
3 years ago

KeyError at /add_post/

Python
I'm trying to add a feature restricting users to post more than one in one minuate. Then I have met this error, not sure why this isn't working. Can y...
3 years ago

Use capture group in re.sub

Python
I have the following code: >>> s = 'https://www.microsoft.com/ja-jp/store/tv/%E7%BE%8E%E7%94%B7-%E3%82%A4%E3%82%B1%E3%83%A1%E3%83%B3-%E3%82%...
3 years ago

Implementing NSApplication delegate protocol for openFile in PyObjC

Python
I want to do this in Python (pyobjc) -(BOOL) application: (NSApplication*)sharedApplication openFile:(NSString*) fileName { ... } My delegate is a ...
3 years ago

How to extract link from <a> inside the <h2 class=section-heading>:BeautifulSoup

Python
I am trying to extract a link which is written like this: &lt;h2 class="section-heading"&gt; &lt;a href="http://www.nytimes.com/pages/arts/index....
3 years ago

Can I write intentionally "mis-indented" Python code?

Python
In free-form languages, sometimes I use indentation to represent some implicit structure in my statements. In the following example, I'm just doing a ...
3 years ago

Python: How to call method in separate process

Python
I want to start the ActorCore method in a seperte process and then process messages that come to that ActorCore. For some reason this code is not work...
3 years ago

Selenium get textarea error

Python
I'm trying to scrap in a website using Selenium and Python, I got stucked in a field called 'textarea' by the website. This is how the website HTML ca...
3 years ago

While condition and rate equation

Python
This is the code I have so far: def convertWeight(): (totalWeight * 0.45359237) def getRate(): if totalWeight &lt;= 2: rate = totalWeig...
3 years ago

subprocess.run: Is it safe to combine check=True with stdout=PIPE?

Python
Python 3.5 introduced the run() function in the subprocess module as the new recommended high-level means of subprocess invocation. Amongst the three...
3 years ago