Skip to content

Tag: python

QFileDialog to open multiple files

I am trying to show a dialog box to open multiple files but seems like it is not working. The following is a function defined in my Class: I thought that the keyword was QFileDialog.ExistingFiles. What am I doing wrong here? Answer You need to use getOpenFileNamesAndFilter instead of getOpenFileNameAndFilter …

Reduce multiple blank lines to single (Pythonically)

How can I reduce multiple blank lines in a text file to a single line at each occurrence? I have read the entire file into a string, because I want to do some replacement across line endings. This doesn’t seem to work and nor does this It’s easy enough to strip them all, but I want to reduce multi…

Pandas secondary y axis for boxplots

I’d like to use a secondary y-axis for some boxplots in pandas, but it doesn’t seem available. Now, using the default line plot it’s easy enough to plot to a second y-axis: But if I use boxplot style, it doesn’t work: Is there any way (maybe through matplotlib) I can get pandas to plot…

How to send requests with JSON in unit tests

I have code within a Flask application that uses JSONs in the request, and I can get the JSON object like so: This has been working fine, however I am trying to create unit tests using Python’s unittest module and I’m having difficulty finding a way to send a JSON with the request. This gives me: …

Python: Check for unique characters on a String

I’m asking the user to input a keyword and then remove any duplicate characters. Example: Input: balloon Output: balon I’ve tried this solution: List of all unique characters in a string? but it marks it as a syntax error. Any ideas? Answer For your answer, order is important. Here is a one line s…

Rabbitmq hello world connection only works on localhost (python)

I have this simple code taken from the rabbitmq tutorial (http://www.rabbitmq.com/tutorials/tutorial-one-python.html) It works but if I change localhost with the ip of my computer from my own computer or a computer in the same network: I get this error: I have no idea why, should I change something in the con…