python

python web framework for webmail service

I'm planning to write a webmail service in Python but I can't decide which framework to choose. What criteria should I look into when trying to decide which framework to use ? ...

using os.path is quite verbose is there a more concise way to manipulate paths

for example I have a script that needs to put it's parent directory on the python path, currently I'm using the following sys.path += [os.path.dirname(os.path.dirname(os.path.realpath(__file__)))] this seems a touch ridiculous, surely there is a simpler way? ...

Coding style - keep parentheses on the same line or new line?

Suppose you are calling a function, where there's clearly a need to break down the statement into few lines, for readability's sake. However there are at least two way to do it: Would you do this: return render(request, template, { 'var1' : value1, 'var2' : value2, 'var3' : ...

Whoosh index viewer

I'm using haystack with whoosh as backend for a Django app. Is there any way to view the content (in a easy to read format) of the indexes generated by whoosh? I'd like to see what data was indexed and how so i can better understand how it works. ...

Why time.clock() returns such a large value on Windows Server 2008 X64

I ran following script on different machine and got quite different results. The elapsed time.clock() is so large. Script: #------------------------------------------------------------------------------------ import time start_clock = time.clock() time.sleep(60) end_clock = time.clock() print "Sleep Clock = ", str(end_clock - start_cl...

how to load data and store the data from a file using numpy

I have the following file like this: 2 qid:1 1:0.32 2:0.50 3:0.78 4:0.02 10:0.90 5 qid:2 2:0.22 5:0.34 6:0.87 10:0.56 12:0.32 19:0.24 20:0.55 ... he structure is follwoing like that: output={} rel=2 qid=1 features={} # the feature list "1:0.32 2:0.50 3:0.78 4:0.02 10:0.90" output.append([rel,qid,features]) ... How can I write my ...

Python: startswith any alpha character

How can I use the startswith function to match any alpha character [a-zA-Z]. For example I would like to do this: if line.startswith(ALPHA): Do Something ...

storing app settings on Google App Engine

I need to store settings for my Google App Engine project. Currently I have: class Settings(db.Model): rate = db.IntegerProperty(default=4) ... And when I want to use it: Settings.get_or_insert('settings') This feels clumsy so is there a better way (without using Django)? ...

how to document a python package

I know what's the standard way to document functions, classes and modules, but how do I document packages - do I put a docstring in __init__.py, or something else? ...

Best seed for parallel process

I need to run a MonteCarlo simulations in parallel on different machines. The code is in c++, but the program is set up and launched with a python script that set a lot of things, in particular the random seed. The function setseed thake a 4 bytes unsigned integer Using a simple import time setseed(int(time.time())) is not very good ...

Memory error due to the huge input file size

When I using the following code to read file: lines=file("data.txt").read().split("\n") I have the following error MemoryError the file size is ls -l -rw-r--r-- 1 charlie charlie 1258467201 Sep 26 12:57 data.txt ...

How to supress Powershell window when using the -File option

I'm calling Powershell like so: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noninteractive -nologo -file "C:\Users\dummy\Documents\dev\powershell\samples\test.ps1" I'm calling it from a python script, but the same problem can be observed if called via a shortcut. I thought the -NonInteractive flag would cause...

migrating from one framework to another in python

I'm having trouble deciding which python framework to use for my website. So I've decided to bite the bullet and use Django. My question is how easy (or difficult) will it be to migrate to a different framework in future if I have issues with Django ? ...

Load huge data to memory using python

I have to load large data to the memory, and the structure is list. How can I get another approach. thanx ...

Python: web login script, what's the problem ??

this is the script >> import ClientForm import urllib2 request = urllib2.Request("http://ritaj.birzeit.edu") response = urllib2.urlopen(request) forms = ClientForm.ParseResponse(response, backwards_compat=False) response.close() form = forms[0] print form sooform = str(raw_input("Form Name: ")) username = str(raw_input("Username: ")) ...

App Engine, Python: problem updating datastore record

I need to update a record in the datastore, but instead of updated record I get always a new record. My model: class PageModel(db.Model): title = db.StringProperty() content = db.TextProperty() reference = db.SelfReferenceProperty() user = db.UserProperty(auto_current_user = True) created = db.DateTimeProperty...

Using one Scrapy spider for several websites

I need to create a user configurable web spider/crawler, and I'm thinking about using Scrapy. But, I can't hard-code the domains and allowed URL regex:es -- this will instead be configurable in a GUI. How do I (as simple as possible) create a spider or a set of spiders with Scrapy where the domains and allowed URL regex:es are dynamical...

GTK StatusIcon: Coordinates of left-click?

Hello, how do I get the x/y-coordinates of a left click in a Gtk StatusIcon? This is my first GTK app and I'm stuck. Is there any way to get details about the last button event that occurred? Or is it possible to pass those details to the handler function when connect()ing the "activate" callback? Greets, Philip ...

In mako, display a python dict element only if it exists

I'd like to display an error from my python dict "errors" only if it exists. % if c.errors.email: <div class="hint_error">${c.errors.email}</div> % endif But I keep getting the error: AttributeError: 'str' object has no attribute 'email' What am I doing wrong? ...

In a pylons web app, should a cookie be set from a model class or a controller?

Trying to figure out the best way to do this: Should I do something like: def index(self): if request.POST: u = User(id) u.setCookie() #All session logic in def setCookie() Or set the cookie in the controller like: def index(self): if request.POST: u = User(id) response.set_cookie('session_key...