Skip to content

Tag: python

Using Python to add a list of files into a zip file

I want to write a script to add all the ‘.py’ files into a zip file. Here is what I have: However it gives an error: so seems the file names given is not correct. Answer You need to pass in the compression type as a keyword argument: Without the keyword argument, you are giving ZipFile.write() an integer arcn…

Print not showing in ipython notebook

I am using ipython notebook (http://ipython.org/notebook.html) to do a demo and it seems like the print function is not working: The commands in the above picture are rewritten here for clarity. In short, there’s no print output from the [2]. Does anyone know whether it’s a known bug? And does any…

Python3: JSON POST Request WITHOUT requests library

I want to send JSON encoded data to a server using only native Python libraries. I love requests but I simply can’t use it because I can’t use it on the machine which runs the script. I need to do it without. My server is a local WAMP server. I always get an urllib.error.HTTPError: HTTP Error 500:…

ZipFile does not store any text inside an archived file

The following code results in the file found in the zip being empty, instead of having some text in it: Answer Add flush to the file object: This problem also affects normal (non-temporary) files, so they’ll also need the flush treatment: Alternatively, de-denting the 2nd with block would avoid having t…

Print raw HTTP request in Flask or WSGI

I am debugging a microcontroller I’ve built which is writing raw HTTP requests line by line. I am using Flask for my backend and I would like to see the entire request as it appears in this format: I know Flask is based on WSGI. Is there anyway to get this to work with Flask? Answer With flask you have