python

Create a summary text file of a folder with filename and the first two lines out of each file

I have a directory with 260+ text files containing scoring information. I want to create a summary text file of all of these files containing filename and the first two lines of each file. My idea was to create two lists separately and 'zip' them. However, I can get the list of the filenames but I can't get the first two lines of the fil...

Java or Python for a System administrator ?

Hello, I'm currently studying to become a Networks/Systems administrator, and I would like to know what language do you recommend me to learn/improve that could be useful in my career ? I know Java it a lot used in enterprise as Application Servers (J2EE and co), but I also know that Python is used as script and some server-side scripti...

python dll swig help

Hello, First, I have never used SWIG, I dont know what it does... We have a python library, that as far as I can tell uses SWIG, say when I want to use this library I have to put this in my python code: import pylib Now if I go open this vendor's pylib.py I see some classes, functions and this header: # This file was automatically ...

python use __getitem__ for a method

is it possible to use getitem inside a method, ie Class MyClass: @property def function(self): def __getitem__(): ... So I can do A = MyClass() A.function[5] A.function[-1] ...

making python programs "chat" via pipe

Hi! I'm trying to make two processes communicate using a pipe. I did this in the parent process: process = subprocess.Popen(test, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) process.stdin.write("4\n"); output = process.stdout.read() print output and in the child process: inp = raw_input() integer = int(inp) print int...

getting Connection reset by peer error using urllib2

Hi, I'm getting this error: socket.error: [Errno 54] Connection reset by peer All I'm trying to do is the following in python: data = urllib.urlencode(values) req = urllib2.Request(url, data) response = urllib2.urlopen(req) id = response.read() Some previous related questions suggested using time.sleep to fiddle with the threads. ...

Get the coords and height/width of a svg group into python

Hi I want to load the groups of a svg-file into several gtk pixbuffs/subpixbufs therefore I need the coordinates and width and height of them I'm currently just using rsvg and gtk is it possible to get those information with that modules ? Or do I need another module to read out that data from the svg-file? thanks alot ...

sets in python problem

can we remove a entry from the sets. what are the commands to use for it? like, my set conatins (6,5) , (6,7), (7,9)...I need to remove the second entry...what shud I do?? ...

Chained string formatting in Python

In handling a little SQL formatting I was amazed to find I could chain string formatters: def get_sql(table, limit=True): sql = "select report_date from %s" if limit: result = "%s limit 1" % sql % table else: result = sql % table return result Is this legit? Any reason not to do this? ...

error: list objects are unhashable

closed = set() -here closed is a set node is (5,5) The error occurse at execution time. Error is: list objects are unhashable the program is: closed.add(node) for val in closed: print val Node is the output of stack. node = stack.pop() - it gives me...(5,5) Traceback: File "/home/", line 99, in depthFirstSearch ...

Django extend admin "index" view

I know how to change or extend a model's views in the Django admin ( http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.add_view ) but I want to extend the admin index (dashboard) view. Specifically, I want to keep it the same, but add some information to some of my models that will let me sort them ...

Is there a wxpython list widget that displays alternating row colours even when the list is empty?

Is there a wxpython list widget that displays alternating row colours even when empty the list is empty? or Is there even one that will display a background colour(other than white) when it is empty? ...

Extract AAC audio properties using Python?

What's the easiest Python library to use to extract properties from an AAC audio file (.m4a)? Specifically, I'd like to extract the following properties: Sample rate Channel count (mono or stereo) Length (in seconds) ...

How to write a check in python to see if file is valid UTF-8?

As stated in title, I would like to check in given file object (opened as binary stream) is valid UTF-8 file. Anyone? Thanks ...

Using if/elif/else and resp=raw_input - how to respond to part of a user's input?

print "Please Type Something" resp = raw_input() if resp *contains* "cuttlefish" print "Response One" elif resp *contains* "nautilus" print "Response Two" else: print "Response Three" What I need to know is the correct syntax to use instead of the filler contains. So, for example, if the user types "two cuttlefish" then...

"list index out of range"

Below I have the following code that is supposed to get the CPU temperature. import wmi w = wmi.WMI() print w.Win32_TemperatureProbe()[0].CurrentReading When I run it I get the following warning however: Traceback (most recent call last): File "<string>", line 244, in run_nodebug File "<module1>", line 3, in <module> IndexError:...

Why am I getting this simplejson exception?

Why does Django give me this exception [(7, u'Acura'), (18, u'Alfa Romeo'), ...] is not JSON serializable When I try data = VehicleMake.objects.filter(model__start_year__gte=request.GET.get('year',0)).values_list('id','name') return HttpResponse(simplejson.dumps(data, ensure_ascii=False), mimetype='application/json') ? It's just ...

What next after reading Dive into Python?

Possible Duplicate: How to Learn Python I only learned python from a few random tutorials like the one on Google but I feel like I missed a lot so I want to read Dive into Python (2.x) to fill in the holes (or if you think there is a better book). After I read it what would you guys recommend after that? I know there have been...

Making non-square borders in Tkinter

I have a program that looks like the following What is the easiest way to give it slanted edges, like the following? This is in windows 7, btw. Also example codes are much appreciated. ...

Disabling Django CSRF for views that do not always have a response

I have a Django view that receives POSTs which do not need to have the CSRF token. Therefore I used the @csrf_exempt decorator on the view. The problem is that sometimes I do not issue a response from the view (it's a Twitter bot, it receives an HTTP POST for every tweet and I do not want to respond to every tweet). When I don't issue a ...