Skip to content
Advertisement

Tag: python-2.7

Control wsgiref simple_server log

I’m playing with wsgiref.simple_server to study the world of web servers. I would like to control the log generated, but could not find anything about it in Python’s documentation. My code looks like this: Answer wsgiref.simple_server.make_server by default creates a WSGIServer with WSGIRequestHandler: WSGIRequestHandler here extends from BaseHTTPServer.BaseHTTPRequestHandler, where the logging magic turns out to be: So it’s logging to

getattr and setattr on nested subobjects / chained properties?

I have an object (Person) that has multiple subobjects (Pet, Residence) as properties. I want to be able to dynamically set the properties of these subobjects like so: Currently I get the wrong output: {‘pet’: <__main__.Pet object at 0x10c5ec050>, ‘residence’: <__main__.Residence object at 0x10c5ec0d0>, ‘pet.name’: ‘Sparky’, ‘residence.type’: ‘Apartment’} As you can see, instead of setting the name attribute on the

Pandas read multiindexed csv with blanks

I’m struggling with properly loading a csv that has a multi lines header with blanks. The CSV looks like this: What I would like to get is: When I try to load with pd.read_csv(file, header=[0,1], sep=’,’), I end up with the following: Is there a way to get the desired result? Note: alternatively, I would accept this as a result:

Tkinter: getting coordinates of a mouse drawn rectangle

Working on the answer of my previous question, I wonder how to get the coordinates of the 4 pixels representing the corners of the rectangle as well as its 2 dimensions ? Answer You can use canvas.bbox(item) to get the coordinates of the bounding box of an item on the canvas. Because your item is a rectangle, the bounding box

Entry message: [MSC v.1500 64 bit (AMD64)] on win32

I was wondering in, when I start python I get the following message: I am using 64 bit python but why does it mention win32 as opposed to win64? Answer win32 is the general name for the Windows NT/95 API, whether you are on a 32-bit or 64-bit OS (or even using Win32s on a 16-bit OS).* The 64 bit

Naturally sorting Pandas DataFrame

I have a pandas DataFrame with indices I want to sort naturally. Natsort doesn’t seem to work. Sorting the indices prior to building the DataFrame doesn’t seem to help because the manipulations I do to the DataFrame seem to mess up the sorting in the process. Any thoughts on how I can resort the indices naturally? Answer If you want

Advertising on a tkinter program

My question is : is it possible to put ads on a tkinter program , something like google ads or something , because I made a program which a lot of people started using and I am not getting any benefits from it , is there a way ? Answer There is nothing built-in to tkinter, nor available as a

Print a dictionary into a table

I have a dictionary: I would like to output it as: Is it a good way to first convert them into a list of dictionaries, and then write them into a table, by the method in https://stackoverflow.com/a/10373268/156458? Or is there a way better in some sense? Answer Rather than convert to a list of dictionaries, directly use the .items of

Advertisement