Skip to content
Advertisement

A more suitable way to rewrite this?

I have the method: This just returns the first of the month 2 months ago, which is what I want is there a better approach I could have used using timedeltas? I choose my way because weeks in a month are not always constant. Answer dateutil is an amazing thing. It really should become stdlib someday.

A simple Python HTTP proxy [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 4 years ago. The community reviewed whether to reopen this question 10 months ago and left it

Generating an MD5 checksum of a file

Is there any simple way of generating (and checking) MD5 checksums of a list of files in Python? (I have a small program I’m working on, and I’d like to confirm the checksums of the files). Answer You can use hashlib.md5() Note that sometimes you won’t be able to fit the whole file in memory. In that case, you’ll have

How to sort a list of strings numerically?

I know that this sounds trivial but I did not realize that the sort() function of Python was weird. I have a list of “numbers” that are actually in string form, so I first convert them to ints, then attempt a sort. Gives me: What I want is I’ve looked around for some of the algorithms associated with sorting numeric

What is the Python ‘buffer’ type for?

There is a buffer type in Python, but how can I use it? In the Python documentation about buffer(), the description is: buffer(object[, offset[, size]]) The object argument must be an object that supports the buffer call interface (such as strings, arrays, and buffers). A new buffer object will be created which references the object argument. The buffer object will

Execute python script inside a python script

I have a scenario where i want to dynamically generate a python script – inside my main python script – store it as a string and then when need be, execute this dynamically generated script from my main script. Is this possible, if so how? thanks Answer Read up on the execfile() function. http://docs.python.org/library/functions.html?highlight=exec#execfile

python: can i set a variable to equal a function of itself?

Can I do this? When I tried to do this I got errors, but perhaps I was doing something wrong. Answer If the variable has been previously defined, you can do that yes. Example: If the variable has not been defined previously, you can’t do that, simply because there is no value that could be passed to the function.

Advertisement