Skip to content

Tag: python

Python’s enumerate in Ruby?

Is something built in for this? It doesn’t need to have it’s members immutable, it just needs to be in the standard library. I don’t want to be the guy who subclasses the Array class to add a Python feature to a project. Does it have a different name in Ruby? Answer Something like this in Py…

Progress of Python requests post

I am uploading a large file using the Python requests package, and I can’t find any way to give data back about the progress of the upload. I have seen a number of progress meters for downloading a file, but these will not work for a file upload. The ideal solution would be some sort of callback method …

What does the comma mean in Python’s unpack?

We can simply use: why do people write it like this: What does the comma mean? Answer The first variant returns a single-element tuple: To get to the value, you have to write crc[0]. The second variant unpacks the tuple, enabling you to write crc instead of crc[0]:

base64 miss encodestring

I run in console python base64.py, get the below error message. but i can run it in textMate correctly. AttributeError: ‘module’ object has no attribute ‘encodestring’ Answer The name of your file should not be base64.py, it collides with the module you’re using. Rename your file…

Writelines writes lines without newline, Just fills the file

I have a program that writes a list to a file. The list is a list of pipe delimited lines and the lines should be written to the file like this: BUT it wrote them line this ahhhh: This program wrote all the lines into like one line without any line breaks.. This hurts me a lot and I gotta

Split string into strings by length?

Is there a way to take a string that is 4*x characters long, and cut it into 4 strings, each x characters long, without knowing the length of the string? For example: Answer