I want to see if a field/variable is none within a Django template. What is the correct syntax for that? This is what I currently have: In the example above, what would I use to replace “null”? Answer None, False and True all are available within template tags and filters. None, False, the empty s…
Tag: python
pandas: filter rows of DataFrame with operator chaining
Most operations in pandas can be accomplished with operator chaining (groupby, aggregate, apply, etc), but the only way I’ve found to filter rows is via normal bracket indexing This is unappealing as it requires I assign df to a variable before being able to filter on its values. Is there something more…
Handling a timeout error in Python sockets
I am trying to figure out how to use the try and except to handle a socket timeout. The way I added the socket module was to import everything, but how do I handle exceptions? In the documentation it says you can use socket.timeouterror, but that doesn’t work for me. Also, how would I write the try exce…
How can I display an image from a file in Jupyter Notebook?
I would like to use an IPython notebook as a way to interactively analyze some genome charts I am making with Biopython’s GenomeDiagram module. While there is extensive documentation on how to use matplotlib to get graphs inline in IPython notebook, GenomeDiagram uses the ReportLab toolkit which I don&#…
Removing white space around a saved image
I need to take an image and save it after some process. The figure looks fine when I display it, but after saving the figure, I got some white space around the saved image. I have tried the ‘tight’ option for savefig method, did not work either. The code: I am trying to draw a basic graph by using…
Validate Postal Code?
I’m doing some tutorials online…and I’m stuck at an exercise:Define a function postalValidate(S) which first checks if S represents a postal code which is valid. Note: I’m supposed to solve it with strings, lists, if statements, loops, and other basic constructs like variables and func…
Python code to automate desktop activities in windows
I want to automate desktop activities in Windows environment using Python. How it can be done? Some examples will also be helpful. By desktop activities, I mean actions such as taking control over mouse and keyboard, access active windows properties, double-click on an icon on the desktop, minimize and maximi…
C++ to simpler language (Python, Lua, etc) converter? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 7 years ago. Improve this ques…
Using locals() and format() method for strings: are there any caveats?
Are there any disadvantages, caveats or bad practice warnings about using the following pattern? I had a very repetitive string generation code to write and was tempted to use this, but something about using locals() makes me uncomfortable. Is there any danger of unexpected behavior in this? Edit: context I f…
Get Image File Size From Base64 String
I’m working on a python web service. It calls another web service to change the picture of a profile. It connects to another web service. This web service can only accept pictures that are 4 MB or smaller. I will put the checking in the first web service. It uses PIL to check if the base64 string is a v…