A bit off topic, but good web hosting for PostgreSQL/Python?

D

dananrg

Seems like most web hosting providers support MySQL, but not
PostgreSQL. I need a web hosting account that supports PostgreSQL for a
particular personal project I'm working on (as well as Python, natch),
since PostGIS runs only on PostgreSQL. PostGIS is a nice open source
spatial database extension to PostgreSQL that allows you to store
geometry in the database.

Couldn't find a good PostgreSQL newsgroup so I thought I'd ask here.
Did find one weird one named Mailing something or other, but that may
be a gateway to a e-mail distribution list.
 
F

Francisco Reyes

Seems like most web hosting providers support MySQL, but not
PostgreSQL.

There are actually many.

Two that I personally have experience with:
http://hub.org
http://bizintegrators.com

They both support PostgreSQL.

Not sure on their python support, but I believe they likely already have it
or would do mod_python for you.
Couldn't find a good PostgreSQL newsgroup so I thought I'd ask here.

The postgresql mailing lists are both active and very helpfull. Just check
the postgresql site for mailing list subscription info.
 
E

egbert

The string method isalpha() returns True when all characters in the
string are alphabetic. Unfortunately the underscore is not alphabetic.
A function that does what I need is:

def alfa_(w):
return "".join(w.split("_")).isalpha()

but for the kind of strings that I have this is about ten times
slower than isalpha() sec. Any suggestions ?
Thanks.
 
B

bearophileHUGS

This is probably faster:

def alfa_(w):
return w.replace("_", "a").isalpha()


This is another solution, but it's probably slower, you can time it:

from string import letters
_setalpha = set(letters + "_")

def alfa_2(w):
return not (set(w) - _setalpha)

Bye,
bearophile
 
Z

Zajcev Evgeny

egbert said:
The string method isalpha() returns True when all characters in the
string are alphabetic. Unfortunately the underscore is not alphabetic.
A function that does what I need is:

def alfa_(w):
return "".join(w.split("_")).isalpha()

but for the kind of strings that I have this is about ten times
slower than isalpha() sec. Any suggestions ?
Thanks.

what about

def alfa_(w):
return w.isalpha() or w.find('_') != -1

? but yes it does scan `w' twice ..

You could also do something like:

def alfa_(w):
for c in w:
if not c.isalpha() and not c == '_':
return False
return True
 
F

Fuzzyman

Zajcev said:
what about

def alfa_(w):
return w.isalpha() or w.find('_') != -1

That returns True if 'w' contains an underscore. The spec is to return
True if 'w' contains *only* alphaebtical characters and '_'.

alfa('%^_*&')

would return True here.
? but yes it does scan `w' twice ..

You could also do something like:

def alfa_(w):
for c in w:
if not c.isalpha() and not c == '_':
return False
return True

Part of the problem is that the string method 'isalpha' is implemented
in C, and so will be quicker than any pure Python alternative.

The following will work, and probably only be twice as slow as
'isalpha' :) :

def alfa(w):
return w.replace('_', '').isalpha()

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
 
Z

Zajcev Evgeny

Fuzzyman said:
That returns True if 'w' contains an underscore. The spec is to return
True if 'w' contains *only* alphaebtical characters and '_'.

true, my fault :-< !
alfa('%^_*&')

would return True here.


Part of the problem is that the string method 'isalpha' is implemented
in C, and so will be quicker than any pure Python alternative.

I've been suspecting this ..
The following will work, and probably only be twice as slow as
'isalpha' :) :

def alfa(w):
return w.replace('_', '').isalpha()

Yeah, great performance indeed, thanks!
 
A

Alex Martelli

Zajcev Evgeny said:
Yeah, great performance indeed, thanks!

Except it rejects a w that's JUST an underscore, while it would accept a
w that's just a letter, which seems weird to me. Using 'a' as the
second argument of the replace call, as somebody else suggested, appears
to produce a more sensible uniformity.


Alex
 
E

egbert

In the discussion about isalpha()_mutants that accept
underscores as well, we did not talk about regular expressions.

Afterwards I did some timings.
My first observation was that the whole experiment is rather futile,
because it takes only about a second to do a million tests.
If you take the trouble to collect a million words,
you might as well spend an extra second to analyze them.

Apart from that, a simple regular expression is often faster
than a test with replace. The last one, replace, does better
with shorter tokens without underscores. Nothing to replace.
Regular expressions are less sensitive to the length of the tokens.
Regular expressions are not monsters of inefficiency.

This is my script:

#!/usr/bin/env python
import sys
from timeit import Timer

import re
pat = re.compile(r'^[a-zA-Z_]+$')

if len(sys.argv) > 1:
token = sys.argv[1]
else:
token = "contains_underscore"

t = Timer("''.join(token.split('_')).isalpha()", "from __main__ import token")
print t.timeit() # 1.94

t = Timer("token.replace('_','X').isalpha()", "from __main__ import token")
print t.timeit() # 1.36

t = Timer("pat.search(token)", "from __main__ import token, pat")
print t.timeit() # 1.18

t = Timer("token.isalpha()", "from __main__ import token")
print t.timeit() # 0.28

#egbert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top