I have a file from which I’ve output several columns of information, 4 to be exact. At this moment they are separated by commas, but in order for my buddy to feed them into another script, he wants the format to be with ‘|’ as delimiter and the commas removed. The commas follow every set of data, so after my
Tag: python-2.7
What’s the difference between __builtin__ and __builtins__?
I was coding today and noticed something. If I open a new interpreter session (IDLE) and check what’s defined with the dir function I get this: Please note the last line. So, my question is: Is any an alias of the other one? Are the Python guys planning to get rid of one of those? What should I use for
Is it safe to use the python word “type” in my code?
Can I use the word type in my own code or is it reserved? My function header: Answer Using type as a keyword argument to a function will mask the built-in function “type” within the scope of the function. So while doing so does not raise a SyntaxError, it is not considered good practice, and I would avoid doing so.
Using PIL to turn a RGB image into a pure black and white image
I’m using the Python Imaging Library for some very simple image manipulation, however I’m having trouble converting a greyscale image to a monochrome (black and white) image. If I save after changing the image to greyscale (convert(‘L’)) then the image renders as you would expect. However, if I convert the image to a monochrome, single-band image it just gives me
Bad magic number error with ZipFile module in Python
I am using Python 2.7 on Windows 7 (64 bit). When I try to unzip a zip file with ZipFile module I get the following error:- WinRAR could extract the file I am trying to extract just fine. Here is the code I used to extract files from myzip.zip This code is working fine for many other zip files I
selecting attribute values from lxml
I want to use an xpath expression to get the value of an attribute. I expected the following to work but this gives an error : Am I wrong to expect this to work? Answer find and findall only implement a subset of XPath. Their presence is meant to provide compatibility with other ElementTree implementations (like ElementTree and cElementTree). The
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