What is the easiest way to create a delay (or parking) queue with Python, Pika and RabbitMQ? I have seen an similar questions, but none for Python. I find this an useful idea when designing applications, as it allows us to throttle messages that needs to be re-queued again. There are always the possibility th…
Tag: python
Puzzled on the ndim from Numpy
Above is my code. the output is: I have checked the page from [here] (Link) I expected a.dim = 2 or 3, but it is 4. Why? Could you give me some hints? Thanks Answer The tuple you give to zeros and other similar functions gives the ‘shape’ of the array (and is available for any array as a.shape). T…
Relative imports in Python 3
I want to import a function from another file in the same directory. Usually, one of the following works: …but the other one gives me one of these errors: Why is this? Answer unfortunately, this module needs to be inside the package, and it also needs to be runnable as a script, sometimes. Any idea how …
Writing a pandas DataFrame to CSV file
I have a dataframe in pandas which I would like to write to a CSV file. I am doing this using: And getting the following error: Is there any way to get around this easily (i.e. I have unicode characters in my data frame)? And is there a way to write to a tab delimited file instead of a CSV
Why doesn’t the .bind() method work with a frame widget in Tkinter?
This code is an attempt to bind a command to a frame, ie. when the “Escape” key is pressed, the window should be destroyed. if frame1.bind() is replaced by root.bind(), the code works as I would expect it to. Why doesn’t what I’ve written above work? Answer The bind works, but the even…
python list append gives a error: AttributeError: ‘function’ object has no attribute ‘append’
I have list = [] and I am adding an element to it using self.list.append(‘test’) and I get this error – AttributeError: ‘function’ object has no attribute ‘append’ The other list that I have defined append just fine, any ideas? Answer It seems you have a function in y…
How to read a .xlsx file using the pandas Library in iPython?
I want to read a .xlsx file using the Pandas Library of python and port the data to a postgreSQL table. All I could do up until now is: Now I know that the step got executed successfully, but I want to know how i can parse the excel file that has been read so that I can understand how
Python vs C: different outputs
I have a small program that converts a base 10 number into a kind of a base 36 number. Here’s the Python code, and it works as expected. The output is “4 45 46” correctly represents 0, and “4 9 24” correctly represents 200. But the issue is, it stops working after I convert it to…
How to resize window in opencv2 python
I am using opencv 2 with a webcam. I can get the video stream and process it, but I can’t seem to figure out a way to resize the display window. I have some video images stacked horizontally, but the image dimension is very small that it’s difficult to see things. My code is pretty simple, and alo…
How can I set two primary key fields for my models in Django?
I have a model like this: How can I have the primary key be the combination of migration and host? Answer Update Django 4.0 Django 4.0 documentation recommends using UniqueConstraint with the constraints option instead of unique_together. Use UniqueConstraint with the constraints option instead. UniqueConstra…