import csv
with open('test.csv', 'rb') as f:
data = list(csv.reader(f))
import collections
counter = collections.defaultdict(int)
for row in data:
counter[row[1]] += 1
for row in data:
if counter[row[1]] >= 4:
writer = csv.writer(open("test1.csv", "wb"))
writer.writerows(row)
i am getting strange output! what is...
What are the disadvantages to using signal.alert to timeout Python I/O?
I ask because I have found that socket.settimeout isn't entirely reliable[0] and I'd like finer control over the timeouts for different operations[1].
So, as far as I can tell, the drawbacks are:
Added signal call overhead (but if you're doing I/O, this shouldn't...
I need to create Excel XML files from Python.
The Excel XML format is fairly simple. I looked at a a sample xml file saved from Excel 2003 and it is fairly simple.
I'm looking for a a Pythonic, ready made library to create such xml files instead of reinventing one.
Something that I can use as below:
book = Expy.Workbook()
s1 = boo...
I'm querying a table from my Django app, but whenever I do a query on one specific table, I am getting the UUID column returned as a bytes_le style UUID instead of a workable string representation. Now, I know I convert it using uuid.UUID(bytes_le=value), but I'm using this query to populate a WTForms QuerySelectField, so I don't really...
Hello,
I want to access a web page with urllib2 and I keep getting an HTTP Error 401: Unauthorized.
Now, my problem is that this page doesn't need any authentication when using browsers like Firefox. Only when I use Google Chrome an authentication dialog pops up. Though this happens only after the page is fully loaded. So I can just ca...
Does anyone have any information or advice about adjusting one image so that the skin tones in it will match that of another image?
It is a bit of an obscure question but I was hoping there would be someone that has come across this problem before! The purpose of me doing this is so that I can replace a face in one image with a face fro...
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting?
thanks.
...
I am trying to get a handle on the state of the art regarding web site development and have several questions. Maybe I'll end up finding most of the answers on my own. I come from a background of C++ and Windows development, and generally I am befuddled by what seems to be the ad-hoc nature of web development.
I focussed in on Django, ...
So at the moment I'm trying to delete files listed in the directory that are 1 minute old, I will change that value once I have the script working.
The code below returns the error: AttributeError: 'str' object has no attribute 'mtime'
import time
import os
#from path import path
seven_days_ago = time.time() - 60
folder = '/home/rv/De...
I'm currently making a function using pygame that draws a message on the screen, adding one character each frame (i.e. The Hunt for Red October). I know that I could simply copy (or pass) gradually bigger slices from the original string, but I know that it would be very resource-intensive. Is there a better way to do this?
Code, using...
I have recently been jumping into understanding regex with python.
I have been looking at the api; I can't seem to understand the difference between:
re.match vs. re.search
when is it best to use each of these? pros? cons?
Please and thank you.
...
I'm using the Django database models from a process that's not called from an HTTP request. The process is supposed to poll for new data every few seconds and do some processing on it. I have a loop that sleeps for a few seconds and then gets all unhandled data from the database.
What I'm seeing is that after the first fetch, the pro...
How do I wrap long lines in Python without sacrificing on the indentation part?
For example, consider this:
>>> def fun():
print '{0} Here is a really long sentence with {1}'.format(3, 5)
Suppose that this goes over the 79 character recommended limit. The way I read it, here is how to indent it:
>>> def fun():
prin...
I have an esoteric question involving Python metaclasses. I am creating a Python package for web-server-side code that will make it easy to access arbitrary Python classes via client-side proxies. My proxy-generating code needs a catalog of all of the Python classes that I want to include in my API. To create this catalog, I am using ...
I'm using Google Engine App with Python. I want to add custom user authentication. How is it done, with the best practices?
I want custom authentication because the app is built in Flex and I don't want to redirect to an HTML page.
The user value object is like this:
class User(db.Model):
email = db.EmailProperty(required = True, i...
Hi
I'm trying to set custom 'name' attribute in django form.
I've been trying this kind of approach:
class BaseQuestionForm(forms.Form):
question_id = forms.CharField(widget=forms.HiddenInput)
answer = forms.ChoiceField(choices = [ ... ], widget=forms.RadioSelect)
and then setting the 'name'-attr on answer with:
form.fields['an...
I have a text file which contains a time stamp on each line. My goal is to find the time range. All the times are in order so the first line will be the earliest time and the last line will be the latest time. I only need the very first and very last line. What would be the most efficient way to get these lines in python.
Note: These f...
I'm having problems with my PythonPath on windows XP, and I'm wondering if I'm doing something wrong.
Say that I have a project (created with Pydev) that has an src directory. Under src I have a single package, named common, and in it a single class module, named service.py with a class name Service
Say now that I have another project ...
I've created a simple SOAP web service using soaplib and run into an issue in which SOAP parameters sent including ampersands or angle brackets are ignored, even when escaped.
Whether the method is set up to accept a primitive string or a primitive of type 'any', any of those characters introduced result in a webfault (using suds) of th...
It is not safe to modify the sequence being iterated over in the loop (this can only happen for mutable sequence types, such as lists). If you need to modify the list you are iterating over (for example, to duplicate selected items) you must iterate over a copy. The slice notation makes this particularly convenient:
>>> for x in a...