python

Splitting list in python

Hi guys, I have a list which I have obtained from a python script. the content of the list goes something like: The content below is in a file but I loaded it into a list for comparing it to something else. But now I have to split this list such that each new list created contains the complex name with the corresponding number. Hope it i...

Python: slicing a very large binary file

Say I have a binary file of 12GB and I want to slice 8GB out of the middle of it. I know the position indices I want to cut between. How do I do this? Obviously 12GB won't fit into memory, that's fine, but 8GB won't either... Which I thought was fine, but it appears binary doesn't seem to like it if you do it in chunks! I was appending ...

python os.utime doesn't update the access time

I'm trying to modify the access timestamp and modify timestamp of a remote file I'm using the following line: os.utime(filePath, (1267533581,1267090862)) the modify timestamp get updated but the access timestamp doesn't I have tried to use this on a local file on a local file and everything is working well I'm working on windows. t...

Python PIL: color index to RGB

Hi, following this link i was able to load and read pixels from a .gif. That question specifically askes for a RGB value, but the accepted (and most voted answer) that I used as reference gets me to get an int as value. What is it? I guess some sort of index, but how to convert it to a proper rgb value? Thanks [..] img = Image.open(GIF...

returning out of for-loop

I'm pretty new at python and I was wondering if this: def func(self, foo): for foo in self.list: if foo.boolfunc(): return True return False is good practice. Can I return out of a loop like the above or should i use a while-loop, like so? def func(self, foo): found = false while(not found & i < len(self.li...

Embedding Python code as a preprocessor PHP style

I'm going back over an old project where I added preprocessor functionality to Essence' and I realised that my previous solution of writing a domain specific language and associated lexer/parser was overkill. Instead I just need to be able to embed dynamic language code into the file, isolate it at runtime, eval and insert the results. ...

append new row to old csv file python

hi, I am trying to add new row to my old csv file. Basically it get update each time when I run the python script. Right now I am storing the old csv rows values in list and then deleting the csv file and creating it again with the new list value. Wanted to know is there any better ways of doing it. Thanks ...

Comparing two lists items in python

Hi, I have two files which I loaded into lists. The content of the first file is something like this: d.complex.1 23 34 56 58 68 76 . . . etc d.complex.179 43 34 59 69 76 . . . etc The content of the second file is also the same but with different numerical values. Please consider from one d.complex.* to another d.complex.* as one set...

pyxmpp: quick tutorial for creating a muc client?

I'm attempting to write a quick load-test script for our ejabberd cluster that simply logs into a chat room, posts a couple of random messages, then exits. We had attempted this particular test with tsung, but according to the authors, the muc functionality did not make it into this release. pyxmpp seems to have this functionality, but...

Signing a string with RSA private key on Google App Engine Python SDK

Is there any known way to sign a plain text string with RSA private key on Google App Engine Python SDK? ...

Django + GAE (Google App Engine) : most convenient path for a beginner?

Some background info first: Goal: a medium-level complexity web app that I will need to maintain and possibly extend for a few years. Experience: good knowledge of python, some experience of MVC frameworks (in PHP). Desiderata: using django and google app engine. I read extensively about the compatibility issues between GAE and Djang...

Avoiding nesting two for loops

Hi, Please have a look at the code below: import string from collections import defaultdict first_complex=open( "residue_a_chain_a_b_backup.txt", "r" ) first_complex_lines=first_complex.readlines() first_complex_lines=map( string.strip, first_complex_lines ) first_complex.close() second_complex=open( "residue_a_chain_a_c_backup.txt"...

Google App Engine: Trouble with Datastore Query

This query works: item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = 13")[0] although if there are no results returned, it blows up in my face. (How can I get around this? A for loop seems dubious when I want at max one iteration.) This query does not work: item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = :1", CSIN)[0] CSIN is...

Is it OK to reconfigure a Beaker cache after import time?

The Beaker cache documentation seems to assume a configured cache at import time for use as a decorator. I would like to defer configuration of the cache until later so its parameters can be loaded from a configuration file. How do I reconfigure the Beaker cache? ...

Urlretrieve and User-Agent? - Python

I'm using urlretrieve from the urllib module. I cannot seem to find how to add a User-Agent description to my requests. Is it possible with urlretrieve? or do I need to use another method? ...

What is a good python parser for a google-like search query?

For some search-based code (in Python), I need to write a query syntax parser that would parse a simple google like query syntax. For example: all of these words "with this phrase" OR that OR this site:within.site filetype:ps from:lastweek As search becomes more an more popular, I expected to be able to easily find a python lib...

Python, PHP or what scripting language is the best for automating web-interaction tasks?

Hi, I wonder what is the best scripting language for doing the following: I go to this website http://structure.usc.edu/make-na/server.html and the input a two lines string like: ATGC TATG Afterwards I push the "Make NA" button, so I download the resulting file, which I change the name before downloading it. I would like to do t...

Matplotlib runs out of memory when plotting in a loop - EDITED

I have a fairly simple plotting routine that looks like this: from __future__ import division import datetime import matplotlib matplotlib.use('Agg') from matplotlib.pyplot import figure, plot, show, legend, close, savefig, rcParams import numpy from globalconstants import * def plotColumns(columnNumbers, t, out, showFig=False, fil...

Python (Jython) Playing notes from pixels in picture.

This is from a class assignment: This program is about listening to colors. We will treat pictures as piano scores. Write a function called listenToPicture that takes one picture as an argument. It first shows the picture. Next, it will loop through every 4th pixel in every 4th row and do the following. It will compute the total of the ...

Is there an IntelliJ Python plugin for the community edition?

I've been playing with the community edition of JetBrains ItelliJ IDEA since it came out, and I really like it; however, a lot of plugins seem to require the ultimate edition (or at least I think they do because of the com.intellij.modules.ultimate dependency). Is there a python plugin that doesn't require the ultimate edition? I'm devel...