Python web-framework with the widest scalability?

2012-05-12 Thread Alec Taylor
I am building a project requiring high performance and scalability,
entailing:

   - Role-based
authenticationwith
   
API-keylicensing
to access data of specific users
   - API exposed
with
   REST 
(XML,
   JSON ),
XMLRPC,
   JSONRPC  and
SOAP
   - "Easily" configurable getters and
settersto create APIs
accessing the same data but with input/output in different
   schemas 

A conservative estimate of the number of tables—often whose queries require
joins—is: 20.

Which database type—e.g.: NoSQL 
or DBMS
—key-value data store
or
object-relational
database —e.g.:
Redis  or
PostgreSQL—and
web-framework —e.g.
Django ,
Web2Pyor
Flask —would you recommend?
-- 
http://mail.python.org/mailman/listinfo/python-list


Minor gripe about module names

2012-05-12 Thread John O'Hagan
Not sure if this is only package-manager specific, but occasionally I come
across a module that sounds interesting, install it (in my case by apt-get),
and then can't find it, because the actual module has a different name from
what it says on the package - unlike the majority, which if they are called
"python-whatever", are imported using "import whatever".

Today's example was python-ecasound, which after some fruitless guessing
followed by scanning the hundreds of entries returned by help('modules') and
trying to import anything with a promising filename, turned out to really be
called pyeca.

Are there any rules about this kind of thing? (I did say "minor gripe".)

--

John 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Minor gripe about module names

2012-05-12 Thread Chris Angelico
On Sat, May 12, 2012 at 8:41 PM, John O'Hagan  wrote:
> Not sure if this is only package-manager specific, but occasionally I come
> across a module that sounds interesting, install it (in my case by apt-get),
> and then can't find it, because the actual module has a different name from
> what it says on the package - unlike the majority, which if they are called
> "python-whatever", are imported using "import whatever".

You import based on the filename, so all you need is the list of files
from the package:

$ dpkg -L python-ecasound

This works only after the package has been installed successfully. Not
a solution to your problem, but possibly a viable workaround.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Minor gripe about module names

2012-05-12 Thread Tim Chase
On 05/12/12 05:51, Chris Angelico wrote:
> On Sat, May 12, 2012 at 8:41 PM, John O'Hagan
>  wrote:
>> Not sure if this is only package-manager specific, but
>> occasionally I come across a module that sounds interesting,
>> install it (in my case by apt-get), and then can't find it,
>> because the actual module has a different name from what it
>> says on the package - unlike the majority, which if they are
>> called "python-whatever", are imported using "import
>> whatever".
> 
> $ dpkg -L python-ecasound
> 
> This works only after the package has been installed
> successfully. Not a solution to your problem, but possibly a
> viable workaround.

I use the dpkg method on my Debian-based systems, but (1) I never
remember the syntax and only occasionally need it, so I have to look
it up EVERY time and (2) it can return a lot of chaff if the module
includes auxiliary files.

If only we had some way to develop a simple program that knew about
where Python modules were stored... ;-)

=
import os
import sys

if len(sys.argv) < 2:
  print("Usage:")
  print("%s module_text [or_module_text ...]" % argv[0])
  sys.exit(1)

mods_to_find = [s.lower() for s in sys.argv[1:]]

for d in sys.path:
  if os.path.isdir(d):
for modname in os.listdir(d):
  for piece in mods_to_find:
if piece in modname.lower():
  print(os.path.join(d, modname))
  else:
sys.stderr.write("Unable to check %r\n" % d)
==

should about do the trick and return less chaff.  Could be tweaked
to refine even further.  Or to deduplicate results if the same file
is found due to search criteria.

-tkc



-- 
http://mail.python.org/mailman/listinfo/python-list


Good data structure for finding date intervals including a given date

2012-05-12 Thread Jean-Daniel
Hello,

I have a long list of n date intervals that gets added or suppressed
intervals regularly. I am looking for a fast way to find the intervals
containing a given date, without having to check all intervals (less
than O(n)).

Do you know the best way to do this in Python with the stdlib?

A variant of the red black trees can do the job quickly [1], is this a
good enough use case to discuss the inclusion of a red black tree
implementation in the stdlib?

This has been discussed here: http://bugs.python.org/issue1324770 ,
and lack of good use case was the reason the bug was closed. A dict
implemented with red black trees is slower (but not too slow) at
inserting, searching and deleting but the dict is always kept ordered.
Bigger projects have their own implementation of ordered dict so such
datastructures in the standard library would help the porting of the
project to other platforms. Take the example of the zodb and the
C-only implementation of the btree: btree in the stdlib in Python
would help the porting to GAE or pypy [2].

Cheers,

[1] in the "Cormen" book:
http://en.wikipedia.org/wiki/Introduction_to_Algorithms
[2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Newbie naive question ... int() throws ValueError

2012-05-12 Thread Karl Knechtel
I really wish gmail picked up the mailing list as a default reply-to address...


-- Forwarded message --
From: Karl Knechtel 
Date: Sat, May 12, 2012 at 8:25 AM
Subject: Re: Newbie naive question ... int() throws ValueError
To: Devin Jeanpierre 


On Sat, May 12, 2012 at 12:11 AM, Devin Jeanpierre
 wrote:
> I'm not talking about unexpected exceptions. I'm saying, if I expect
> invalid input for int, where should I go to find out how to deal with
> said invalid input properly? How do I know that int raises ValueError
> on failure, and not, for example, something like ArgumentError
> (something that Python doesn't have) or (like chr) TypeError?
>
> Apparently the answer is to read the documentation for ValueError.

The easiest way is to try it. In fact, in most cases, this will be
easier than looking it up in the documentation could ever be, because
looking something up in documentation requires you to read through a
bunch of documentation until you find key info like 'raises FooError
in bar circumstance', and then interpret it; by trial and error, you
see exactly what happens right away, and you can do it by just banging
out a couple of lines on the REPL.

You should have already read the documentation for things like
ValueError as a part of learning the language (i.e. the first time
something raised a ValueError and you wanted to know what that meant);
or at the very least you should have a good idea of what the
"standard" exceptions are all named, and *develop an intuition* for
which apply to what circumstances. As noted by others, you should not
expect `int` to throw a `TypeError` when fed a bad string, because a
`TypeError` means "something is wrong with the type of some object",
and the problem with the bad string isn't that it's a string (its
type), but that the string contents are not interpretable as int (its
value, hence ValueError).

--
~Zahlman {:>


-- 
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Karl Knechtel
On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel
 wrote:
> I am looking for a fast way to find the intervals
> containing a given date, without having to check all intervals (less
> than O(n)).

Since you say "intervals" in plural here, I assume that they can overlap?

-- 
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-12 Thread Karl Knechtel
On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn  wrote:
> And there's also something like...
>
> return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in 
> self.__dict__))
>
> which is a nice length, but I lose control of the order of the attributes and 
> the formatting is fixed. It also looks a bit too much like Lisp ;o)
>
> Is there a better way?

If you don't care about being able to change the attributes
dynamically, define the `__slots__` of your class, and then you can
use

return '\n'.join('%s: %s' % (name, getattr(self, name)) for name in
self.__slots__)

Calling `getattr` is probably more Pythonic than looking things up in
`__dict__`, string formatting can take care of "casting" (converting,
really) for you, and the nested `join` is really overkill :) Anyway
the main point is that `__slots__` is a list, and thus has a defined
order.

>
> p.s. I may want to substitute __repr__ for __str__ perhaps?

Depending. Sometimes you want them to behave the same way. Since
functions are objects, this is as simple as `__repr__ = __str__`. :)

p.s. Is Python seeing a lot of use at Ubisoft or is this just for
personal interest (or perhaps both)?

-- 
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Mark Lawrence

On 12/05/2012 13:17, Jean-Daniel wrote:

Hello,



Do you know the best way to do this in Python with the stdlib?


Sorry, not part of the stdlib but search for red black tree here 
http://pypi.python.org/pypi.  While you're there also take a look at the 
blist package.


--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python web-framework with the widest scalability?

2012-05-12 Thread Tim Chase
On 05/12/12 03:30, Alec Taylor wrote:
> I am building a project requiring high performance and scalability,
> entailing:

Most of the frameworks are sufficiently scalable.  Scalability
usually stems from design decisions (architecture and algorithm) and
caching, and you'll usually hit bandwidth or algorithm/architecture
limits long before the frameworks are your primary bottleneck.

-tkc



-- 
http://mail.python.org/mailman/listinfo/python-list


to solve the simple equation

2012-05-12 Thread contro opinion
there is a simple equation,
50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045=0
i input :
>>> from sympy import *
>>> x=Symbol('x')
>>>solve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line
332, in solve
result = tsolve(f, *symbols)
  File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line
697, in tsolve
"(tsolve: at least one Function expected at this point")
NotImplementedError: Unable to solve the equation(tsolve: at least one
Function expected at this point

 tsolve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line
697, in tsolve
"(tsolve: at least one Function expected at this point")
NotImplementedError: Unable to solve the equation(tsolve: at least one
Function expected at this point

1.how can i solve it  with sympy?
2.how can i solve it  with other package?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie naive question ... int() throws ValueError

2012-05-12 Thread Ethan Furman

Devin Jeanpierre wrote:

On Fri, May 11, 2012 at 11:21 PM, Chris Angelico  wrote:

There are times when you want to catch all exceptions, though.
Top-level code will often want to replace exception tracebacks with
error messages appropriate to some external caller, or possibly log
the exception and return to some primary loop. Otherwise, though, most
code will just let unexpected exceptions through.


I'm not talking about unexpected exceptions. I'm saying, if I expect
invalid input for int, where should I go to find out how to deal with
said invalid input properly? How do I know that int raises ValueError
on failure, and not, for example, something like ArgumentError
(something that Python doesn't have) or (like chr) TypeError?

Apparently the answer is to read the documentation for ValueError.

It's a bit like putting the documentation on the return type for `map`
in the list documentation. Kinda hard to get there without already
knowing the answer.


Unit tests.  :)

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-12 Thread Ethan Furman

Karl Knechtel wrote:

On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn  wrote:

And there's also something like...

return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in 
self.__dict__))

which is a nice length, but I lose control of the order of the attributes and 
the formatting is fixed. It also looks a bit too much like Lisp ;o)

Is there a better way?


If you don't care about being able to change the attributes
dynamically, define the `__slots__` of your class  [...]


Firstly, __slots__ is a tuple.

Secondly, this is bad advice.  __slots__ is there as a memory 
optimization for classes that will have thousands of instances and do 
not need the ability to have arbitrary attributes added after creation. 
 __slots__ is an advanced feature, and as such is easier to get wrong. 
 It is *not* there to make __str__ nor __repr__ easier to write.


8<---
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit 
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> class Test1(object):
... __slots__ = ('item', 'size')
... desc = 'class-only attribute'
...

>>> t1 = Test1()
>>> t1.desc = 'read-only attribute'  # fails because 'desc' is
 # not in __slots__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Test1' object attribute 'desc' is read-only

>>> print t1.item# fails because 'item' was
 # not set
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: item

>>> class Test2(Test1):
... def __init__(self, price):
... self.price = price
...
>>> t2 = Test2(7.99)  # __slots__ not defined in
  # subclass, optimizations lost

>>> t2.oops = '__slots__ no longer active'
>>> print t2.oops
__slots__ no longer active
8<---

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Jean-Daniel
> Since you say "intervals" in plural here, I assume that they can overlap?

Yes,

For instance, there are the following intervals :
[[1, 10],
[4, 7],
[6, 15],
[11, 17]]

asking for the intervals including  5, the returned value should be

[[1, 10],
[4, 7]]

The idea here to make it fast is to have done some preprocessing at
insertion time, so that not all intervals are processed at query time.



On Sat, May 12, 2012 at 2:30 PM, Karl Knechtel  wrote:
> On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel
>  wrote:
>> I am looking for a fast way to find the intervals
>> containing a given date, without having to check all intervals (less
>> than O(n)).
>
> Since you say "intervals" in plural here, I assume that they can overlap?
>
> --
> ~Zahlman {:>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: to solve the simple equation

2012-05-12 Thread Terry Reedy

On 5/12/2012 9:30 AM, contro opinion wrote:

there is a simple equation,
50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045=0
i input :

 from sympy import *
 x=Symbol('x')
solve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x)

Traceback (most recent call last):
   File"", line 1, in
   File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 332, in 
solve
 result = tsolve(f, *symbols)
   File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in 
tsolve
 "(tsolve: at least one Function expected at this point")
NotImplementedError: Unable to solve the equation(tsolve: at least one Function 
expected at this point

  tsolve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x)
Traceback (most recent call last):
   File"", line 1, in
   File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in 
tsolve
 "(tsolve: at least one Function expected at this point")
NotImplementedError: Unable to solve the equation(tsolve: at least one Function 
expected at this point

1.how can i solve it  with sympy?


Read the sympy doc and learn how to make a Function and use tsolve 
correctly?


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Neal Becker
Probably boost ITL (Interval Template Library) would serve as a good example.  
I 
noticed recently someone created an interface for python.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie naive question ... int() throws ValueError

2012-05-12 Thread Devin Jeanpierre
On Sat, May 12, 2012 at 8:27 AM, Karl Knechtel  wrote:
> I really wish gmail picked up the mailing list as a default reply-to 
> address...

There is some labs thing that makes "reply to all" the default if you
click the button on the top-right. Unfortunately, that applies for
non-mailing-lists too...

> The easiest way is to try it. In fact, in most cases, this will be
> easier than looking it up in the documentation could ever be, because
> looking something up in documentation requires you to read through a
> bunch of documentation until you find key info like 'raises FooError
> in bar circumstance', and then interpret it; by trial and error, you
> see exactly what happens right away, and you can do it by just banging
> out a couple of lines on the REPL.

Eh, this doesn't make sense. Before I would ever try the int()
function, I would've read about it in the documentation -- otherwise
how would I know what it does at all? How would I even know that it exists?

What having to try-it-and-see does is give me extra steps to know what
it does. Instead of only reading the documentation, now I have to both
read the documentation *and* try it out in the interactive interpreter
to see its behaviour in a bunch of undocumented error cases.

What should actually happen is that the error cases should be
documented explicitly, so that I don't have to run around in the REPL
or orthogonal bits of documentation trying to figure out the behaviour
of the function.

> You should have already read the documentation for things like
> ValueError as a part of learning the language (i.e. the first time
> something raised a ValueError and you wanted to know what that meant);
> or at the very least you should have a good idea of what the
> "standard" exceptions are all named, and *develop an intuition* for
> which apply to what circumstances. As noted by others, you should not
> expect `int` to throw a `TypeError` when fed a bad string, because a
> `TypeError` means "something is wrong with the type of some object",
> and the problem with the bad string isn't that it's a string (its
> type), but that the string contents are not interpretable as int (its
> value, hence ValueError).

And yet this is what ord does. Every rule has an exception.

I concede that reading the docs on ValueError is probably worth doing
the first time you see it. Although, it's also one of those exceptions
that has a "clear" name, so it isn't something everyone will do. I'm
not sure if I ever did it. And certainly the OP never looked there.

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie naive question ... int() throws ValueError

2012-05-12 Thread Chris Angelico
On Sun, May 13, 2012 at 4:25 AM, Devin Jeanpierre
 wrote:
> What having to try-it-and-see does is give me extra steps to know what
> it does. Instead of only reading the documentation, now I have to both
> read the documentation *and* try it out in the interactive interpreter
> to see its behaviour in a bunch of undocumented error cases.

Point to note: The Python documentation tells you about the language.
Trying it in the interpreter tells you about your implementation.
There can be differences. I doubt there will be in something as simple
as casting to int, but in other functions, it wouldn't surprise me to
find that CPython (the one that most people think of as Python) and
IronPython, PyPy, or Jython have differences in what they can throw.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Opening a csv file in python on a mac

2012-05-12 Thread Brian Heese
I created a csv file called python test file.csv. It is stored on my Desktop 
directory.  When I try to open it using the command open ('Desktop python test 
file.csv') I get the following error: "No such file or directory". The same 
thing happens if I use open ('python test file.csv'). What I am I doing wrong? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Opening a csv file in python on a mac

2012-05-12 Thread Alec Taylor
Import csv

Lookup usage in the python docs
On 13/05/2012 9:22 AM, "Brian Heese"  wrote:

> I created a csv file called python test file.csv. It is stored on my
> Desktop directory.  When I try to open it using the command open ('Desktop
> python test file.csv') I get the following error: "No such file or
> directory". The same thing happens if I use open ('python test file.csv').
> What I am I doing wrong?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Opening a csv file in python on a mac

2012-05-12 Thread Dave Angel
On 05/12/2012 06:50 PM, Brian Heese wrote:
> I created a csv file called python test file.csv. It is stored on my Desktop 
> directory.  When I try to open it using the command open ('Desktop python 
> test file.csv') I get the following error: "No such file or directory". The 
> same thing happens if I use open ('python test file.csv'). What I am I doing 
> wrong? 

It is totally unclear just where you "used" these "commands."  Please
identify your OS and python version, and paste a complete log of what
you typed and saw on your console.  Do NOT retype it, copy/paste it.



-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Opening a csv file in python on a mac

2012-05-12 Thread MRAB

On 12/05/2012 23:50, Brian Heese wrote:

I created a csv file called python test file.csv. It is stored on my
Desktop directory.  When I try to open it using the command open
('Desktop python test file.csv') I get the following error: "No such
file or directory". The same thing happens if I use open ('python
test file.csv'). What I am I doing wrong?


You should provide the full absolute path of the file.

'python test file.csv' is the name of the file, but it doesn't say
where it is, and 'Desktop python test file.csv' is also just a name.
(Is the file called 'Desktop python test file.csv'? No. It's called
'python test file.csv' and it's in the 'Desktop' directory, wherever
that is.)
--
http://mail.python.org/mailman/listinfo/python-list