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 …
Tag: python
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…
Conditionally add items to a list when defining the list?
Is there a way to add items to a list conditionally, when defining the list? Here’s what I mean: Obviously the above code doesn’t work, but is there a similar way? Currently I have But I was wondering if there’s an other way that wouldn’t required looping through the list, since they c…
Django 1.7: how to make ManyToManyField required?
I have a Django Model with ManyToManyField in it. I need to require user to select at least one M2M value in this field. I tried to set blank=False to M2M field but it didn’t help. I can solve this situation with custom Form definition or with override save() method for Person model. Is it possible to p…
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…
Python zipfile compress_size returns ‘int’ object is not callable
I am trying to get the compressed size of a file with Python and zipfile I get the error What is the reason for that? Answer ZipInfo.compress_size is a simple int attribute, not a method, so you just need to do BTW, it’s a Bad Idea to use zip as the name of a variable, as it’s the name of
Increase resolution with word-cloud and remove empty border
I am using word cloud with some txt files. How do I change this example if I wanted to 1) increase resolution and 2) remove empty border. Answer You can’t increase the resolution of the image in plt.show() since that is determined by your screen, but you can increase the size. This allows it to scale, z…
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…