Re: MATLAB to Python?

2010-11-22 Thread MATLABdude
On Nov 23, 9:43 am, Arnaud Delobelle  wrote:
> T0_orig is a list and you are trying to multiply this list by a float
> (m**-1)

Yes, yes of course. Thanks! :)

This works:
---8<---8<---8<---
T0_orig = [5, 50, 500, 5000]
for counter in T0_orig:
T0 = (L**2)/(D*pi**2)*counter
amax = T0/kappa
alpha = (10**-6)*amax
lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx)
V0 = sqrt( counter*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
print "V0 = ", V0
print ""
---8<---8<---8<---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MATLAB to Python?

2010-11-22 Thread Arnaud Delobelle
MATLABdude  writes:

> On Nov 22, 11:11 am, Peter Otten <__pete...@web.de> wrote:
>> Try numpy.arange() instead:
>> >>> numpy.arange(0, 1, .1)
>> array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])
>
> Thanks! It worked.
>
> What's wrong with the following code?
> ---8<---8<---8<---
> T0_orig = [5, 50, 500, 5000]
> for counter in T0_orig:
> T0 = (L**2)/(D*pi**2)*counter
> amax = T0/kappa
> alpha = (10**-6)*amax
> lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx)
> V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
> print "V0 = ", V0
> print ""
> ---8<---8<---8<---
>
> Python says:
> ---8<---8<---8<---
> Traceback (most recent call last):
>   File "nonhomog.py", line 159, in 
> main()
>   File "nonhomog.py", line 157, in main
> nonhomog(0.2)
>   File "nonhomog.py", line 152, in nonhomog
> V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
> TypeError: can't multiply sequence by non-int of type 'float'
> ---8<---8<---8<---

T0_orig is a list and you are trying to multiply this list by a float
(m**-1)

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


Re: MATLAB to Python?

2010-11-22 Thread MATLABdude
On Nov 22, 11:11 am, Peter Otten <__pete...@web.de> wrote:
> Try numpy.arange() instead:
> >>> numpy.arange(0, 1, .1)
> array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])

Thanks! It worked.

What's wrong with the following code?
---8<---8<---8<---
T0_orig = [5, 50, 500, 5000]
for counter in T0_orig:
T0 = (L**2)/(D*pi**2)*counter
amax = T0/kappa
alpha = (10**-6)*amax
lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx)
V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
print "V0 = ", V0
print ""
---8<---8<---8<---

Python says:
---8<---8<---8<---
Traceback (most recent call last):
  File "nonhomog.py", line 159, in 
main()
  File "nonhomog.py", line 157, in main
nonhomog(0.2)
  File "nonhomog.py", line 152, in nonhomog
V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
TypeError: can't multiply sequence by non-int of type 'float'
---8<---8<---8<---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI FieldStorage instances?

2010-11-22 Thread Gnarlodious
Let me rephrase the question. Say I have a query string like this:

?view=Data&item=9875

What I want to do is simply invoke process "view" with variable
"Data". This would replace my existing query string mess which looks
like this:

if 'view' in form and 'item' in form:
HTML=view(Data, item(9875))

so it just seems like it would be easier to encode the process in the
query rather than filtering the query string.

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


Re: bug? mmap doesn't like 0-length files

2010-11-22 Thread Nobody
On Mon, 22 Nov 2010 20:33:08 -0500, Neal Becker wrote:

> I don't see anything in linux man-page about the underlying C mmap function 
> not accepting 0-length files.

My mmap(2) manpage says:

ERRORS
...
   EINVAL (since Linux 2.6.12) length was 0.

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


Re: Reading bz2 file into numpy array

2010-11-22 Thread Nobody
On Mon, 22 Nov 2010 11:37:22 +0100, Peter Otten wrote:

>> is there a convenient way to read bz2 files into a numpy array?
> 
> Try

> f = bz2.BZ2File(filename)
> data = numpy.fromstring(f.read(), numpy.float32)

That's going to hurt if the file is large.

You might be better off either extracting to a temporary file, or creating
a pipe with numpy.fromfile() reading the pipe and either a thread or
subprocess decompressing the data into the pipe.

E.g.:

import os
import threading

class Pipe(threading.Thread):
def __init__(self, f, blocksize = 65536):
super(Pipe, self).__init__()
self.f = f
self.blocksize = blocksize
rd, wr = os.pipe()
self.rd = rd
self.wr = wr
self.daemon = True
self.start()

def run(self):
while True:
s = self.f.read(self.blocksize)
if not s:
break
os.write(self.wr, s)
os.close(self.wr)

def make_real(f):
return os.fdopen(Pipe(f).rd, 'rb')

Given the number of situations where you need a "real" (OS-level) file
handle or descriptor rather than a Python "file-like object",
something like this should really be part of the standard library.

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


Re: bug? mmap doesn't like 0-length files

2010-11-22 Thread Cameron Simpson
On 23Nov2010 13:59, I wrote:
| On 22Nov2010 20:33, Neal Becker  wrote:
| |  mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ)
| | error: [Errno 22] Invalid argument
[...]
| | I don't see anything in linux man-page about the underlying C mmap function 
| | not accepting 0-length files.

It's worth noting that any time you get an errno error/exception then it
is almost certainly the underlying OS interface that has rejected your
request, not the python library.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Don't have awk? Use this simple sh emulation:
#!/bin/sh
echo 'Awk bailing out!' >&2
exit 2
- Tom Horsley 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bug? mmap doesn't like 0-length files

2010-11-22 Thread Cameron Simpson
On 22Nov2010 20:33, Neal Becker  wrote:
|  mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ)
| error: [Errno 22] Invalid argument
| 
| According to http://docs.python.org/library/mmap.html, mmap on _windows_ 
| doesn't accept 0-length file.  But this was tested on linux.  Is this a bug?  
| 
| I don't see anything in linux man-page about the underlying C mmap function 
| not accepting 0-length files.

On a local Gentoo Linux box mmap(2) says in the ERRORS section:

  EINVAL We don't like addr, length, or offset (e.g., they are too
 large, or not aligned on a page boundary).

  EINVAL (since Linux 2.6.12) length was 0.

  EINVAL flags contained neither MAP_PRIVATE or MAP_SHARED, or contained both
 of these values.

Sure looks like a length of 0 is disliked.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Carpe Daemon - Seize the Background Process
- Paul Tomblin 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Round Trip: C to Python to C Module

2010-11-22 Thread bobicanprogram
On Nov 19, 11:05 am, Eric Frederich  wrote:
> I have a proprietary software PropSoft that I need to extend.
> They support extensions written in C that can link against PropLib to
> interact with the system.
>
> I have a Python C module that wraps a couple PropLib functions that I
> call PyProp.>From an interactive Python shell I can import PyProp and call a 
> function.
>
> None of these functions really do anything outside the context of
> being logged into the PropSoft software; so all the functions fail
> when running from Python alone.
>
> To my amazement, I was able to run PyRun_SimpleString("import
> PyProp\nPyProp.some_function()") without setting PYTHONPATH or
> anything.  How this works, I don't know and I don't really care (at
> the moment anyway).
>
> The problem I'm having now is how do I return things from my Python
> script back to C?
> Ultimately I won't be hard coding python inside of PyRun_SimpleString
> but loading the script from a file.
> So, how do I return values back to C?  Python functions return values
> but running a python script?... doesn't that just have an exit status?
> Is there a mechanism for doing this?
>
> Thanks in advance,
> ~Eric


If you find you can't make this work as planned,  you might want to
check out the SIMPL toolkit (http://www.icanprogram.com/06py/lesson1/
lesson1.html) for an alternative way to connect C programs to Python
modules.

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


Re: File Reading In Mac

2010-11-22 Thread Ned Deily
In article 
<66e4164c-e81d-4a65-b847-c5ef900fa...@a37g2000yqi.googlegroups.com>,
 dilip raghavan  wrote:
>  I have been trying to read contents from a file in MAC.
> I wrote the code
> 
> filename = "test.rtf"
> FileHandle = open(filename,'r')
> 
> fileStr = FileHandle.read()
> print fileStr
> FileHandle.close()
> 
> When I see the output I see a lot of junk. The junk is like a lot of
> question marks, the font information and other details of the file.
> The actual content is lost in the junk.
> 
> I have tried other methods like readline but still I see the junk.
> I tried the asme code in windows and it worked correctly.
> Can any one tell me the reason and the solution  for this.

With an extension of "rtf", the file is presumably a "Rich Text Format" 
file.  http://en.wikipedia.org/wiki/Rich_Text_Format

There are some Python packages out there for dealing with rtf format 
files.  You might try rtf2xml to convert the file, preserving style 
attributes:  http://pypi.python.org/pypi/rtf2xml/
Or look at the Mac OS X command line utility textutil (man 1 textutil) 
to convert the file to another format.  Or use the OS X TextEdit.app.

-- 
 Ned Deily,
 n...@acm.org

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


bug? mmap doesn't like 0-length files

2010-11-22 Thread Neal Becker
 mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ)
error: [Errno 22] Invalid argument

According to http://docs.python.org/library/mmap.html, mmap on _windows_ 
doesn't accept 0-length file.  But this was tested on linux.  Is this a bug?  

I don't see anything in linux man-page about the underlying C mmap function 
not accepting 0-length files.

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


File Reading In Mac

2010-11-22 Thread dilip raghavan
Hello ,
 I have been trying to read contents from a file in MAC.
I wrote the code

filename = "test.rtf"
FileHandle = open(filename,'r')

fileStr = FileHandle.read()
print fileStr
FileHandle.close()

When I see the output I see a lot of junk. The junk is like a lot of
question marks, the font information and other details of the file.
The actual content is lost in the junk.

I have tried other methods like readline but still I see the junk.
I tried the asme code in windows and it worked correctly.
Can any one tell me the reason and the solution  for this.

Thanks In advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to install uTidylib, easy_install problem

2010-11-22 Thread Sridhar Ratnakumar

On 2010-11-22, at 4:22 PM, goldtech wrote:

> I'm using activepython 2.6 on XP. I am trying to install uTidylib 0.2
> with easy_install.  I like uTidylib more vs. newer modules.and want to
> use it. I get output below. How do I install it? I do see it in
> http://pypi.python.org/simple/uTidylib/
> 
> Thanks.
> 
> C:\Documents and Settings\user1>easy_install uTidylib
> install_dir C:\Python26\Lib\site-packages\
> Searching for uTidylib
> Reading http://pypi.python.org/simple/uTidylib/
> Reading http://utidylib.sf.net
> No local packages or download links found for uTidylib
> error: Could not find suitable distribution for
> Requirement.parse('uTidylib')

You could try using the Windows installer (uTidylib-0.2.1.win32.exe) from:
 http://developer.berlios.de/project/showfiles.php?group_id=1810

And perhaps also let Cory Dodt know that his 6-year old package entry has 
broken download link in it
http://pypi.python.org/pypi/uTidylib/

There is not even a source release for 0.2.1.  I'd be more than happy to make 
this available in PyPM  once I can 
find at least the source release of 0.2.1

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


Re: Glob in python which supports the ** wildcard

2010-11-22 Thread Martin v. Loewis
Am 22.11.2010 22:43, schrieb Martin Lundberg:
> Hi,
> 
> I want to be able to let the user enter paths like this:
> 
> apps/name/**/*.js
> 
> and then find all the matching files in apps/name and all its
> subdirectories. However I found out that Python's glob function
> doesn't support the recursive ** wildcard. Is there any 3rd party glob
> function which do support **?

mercurial.match supports apps/name/**.js (IIUC).
mglob supports rec:*.js.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


How to install uTidylib, easy_install problem

2010-11-22 Thread goldtech
I'm using activepython 2.6 on XP. I am trying to install uTidylib 0.2
with easy_install.  I like uTidylib more vs. newer modules.and want to
use it. I get output below. How do I install it? I do see it in
http://pypi.python.org/simple/uTidylib/

Thanks.

C:\Documents and Settings\user1>easy_install uTidylib
install_dir C:\Python26\Lib\site-packages\
Searching for uTidylib
Reading http://pypi.python.org/simple/uTidylib/
Reading http://utidylib.sf.net
No local packages or download links found for uTidylib
error: Could not find suitable distribution for
Requirement.parse('uTidylib')

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


Re: Need advices regarding the strings (str, unicode, coding) used as interface for an external library.

2010-11-22 Thread Terry Reedy

On 11/22/2010 3:25 PM, jmfauth wrote:

I'm planning to build an external lib. This lib will exchange
a lot of strings between the lib and the "core Python code"
of applications.


Are you planning to exchange indirectly via disk files or directly via 
memory buffers?


This pretty much amounts to whether the library will interface with 
Python-only or with anything.


Also, what OSes? If 'all', you need to be able to work with both 2 and 4 
byte unicodes.


--
Terry Jan Reedy

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


Re: Glob in python which supports the ** wildcard

2010-11-22 Thread Kurt Mueller
Hi,


Am 22.11.2010 um 23:05 schrieb Stefan Sonnenberg-Carstens:
> Am 22.11.2010 22:43, schrieb Martin Lundberg:
>> I want to be able to let the user enter paths like this:
>> apps/name/**/*.js
>> and then find all the matching files in apps/name and all its
>> subdirectories. However I found out that Python's glob function
>> doesn't support the recursive ** wildcard. Is there any 3rd party glob
>> function which do support **?
> os.walk() or os.path.walk() can be used.
> You need to traverse the file system.
> AFAIK there is no support for this.


If you are a lucky Unix/Linux/MacOS user:
---
#!/usr/bin/env python
# find files
import os
cmd = 'find apps/name/ -type f -name "*.js" -print' # find is a standard 
Unix tool
for filename in os.popen(cmd).readlines():  # run find command
# do something with filename 
---

find is very powerful, really.


Have anice day
-- 
kurt.alfred.muel...@gmail.com

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


Re: Glob in python which supports the ** wildcard

2010-11-22 Thread Kurt Mueller
HI,


Am 22.11.2010 um 23:05 schrieb Stefan Sonnenberg-Carstens:
> Am 22.11.2010 22:43, schrieb Martin Lundberg;
>> 
>> I want to be able to let the user enter paths like this:
>> apps/name/**/*.js
>> and then find all the matching files in apps/name and all its
>> subdirectories. However I found out that Python's glob function
>> doesn't support the recursive ** wildcard. Is there any 3rd party glob
>> function which do support **?
>> 
> os.walk() or os.path.walk() can be used.
> You need to traverse the file system.
> AFAIK there is no support for this.


Or python only:
--
#!/usr/bin/env python
import os, fnmatch
# generator:
def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
yield filename
# process each file as it is found:
for filename in find_files('apps/name', '*.js'):
print 'found java source:', filename
--
Found at
http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python

Have a nice day
-- 
kurt.alfred.muel...@gmail.com

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


Re: Scheme as a virtual machine?

2010-11-22 Thread Raffael Cavallaro

On 2010-11-22 11:25:34 -0500, scattered said:


And you don't think that [JH] could write a book about Haskell
if he honestly came to think that it were a superior all-aroung
language?


Until he actually does, he has a financial interest in trash-talking 
Haskell. This makes anything he says about Haskell suspect.



 The fact that he *didn't* mindlessly reject [musical note lang] in favor of
[Irish Ship Of The Desert] when [musical note lang] came out (despite 
the fact that at the time his company
was deeply (exclusively?) invested in [Irish Ship Of The Desert] and 
arguably had a vested
interest in having [musical note lang] fail to gain support) suggests 
that he is able

to fairly evaluate the merits of other languages.


No, it suggests that he saw that supporting the Irish Ship Of The 
Desert meant going up against Microsoft, so he jumped to the MS 
supported variant of the Donut Dromedary.


You miss the fundamental point; having a financial interest in the 
outcome of a debate makes anything that person says an advertisement 
for his financial interests, not a fair assessment.



Doubtless he has
biases, but there is no reason to think that they are any greater than
the bias of any programmer who has invested substantial amounts of
time in becoming fluent in a particular language.


Just the opposite. A person who makes his living by being paid to 
program in a language he has developed some expertise in (rather than 
selling books on it and training for it) has no financial interest in 
seeing others develop expertise in it - they would just represent 
competition. By contrast, one who sells training and books for a 
language profits directly when others take an interest in that 
language. Their financial interests are in fact opposite.


JH profits when people take an interest in languages he sells training 
for; a working lisp programmer sees additional *competition* when 
someone else develops expertise in common lisp.



But an advocate isn't a judge. Nobody is handing down binding
decisions here - they are just advocating their positions.


Now you're arguing our point; JH is an *advocate* with a clear conflict 
of interest which prevents him from presenting anything but the most 
one sided, and therefore largely useless, assessment. His writing 
should be seen as a paid advertisement, not as a fair treatment of 
programming languages.


warmest regards,

Ralph



--
Raffael Cavallaro

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


Re: Glob in python which supports the ** wildcard

2010-11-22 Thread Stefan Sonnenberg-Carstens

Am 22.11.2010 22:43, schrieb Martin Lundberg:

Hi,

I want to be able to let the user enter paths like this:

apps/name/**/*.js

and then find all the matching files in apps/name and all its
subdirectories. However I found out that Python's glob function
doesn't support the recursive ** wildcard. Is there any 3rd party glob
function which do support **?

Regards,

Martin Lundberg


os.walk() or os.path.walk() can be used.
You need to traverse the file system.
AFAIK there is no support for this.
<>-- 
http://mail.python.org/mailman/listinfo/python-list


Glob in python which supports the ** wildcard

2010-11-22 Thread Martin Lundberg
Hi,

I want to be able to let the user enter paths like this:

apps/name/**/*.js

and then find all the matching files in apps/name and all its
subdirectories. However I found out that Python's glob function
doesn't support the recursive ** wildcard. Is there any 3rd party glob
function which do support **?

Regards,

Martin Lundberg

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


Re: Python recursively __getattribute__

2010-11-22 Thread Roman Dolgiy
On Nov 22, 7:57 pm, Terry Reedy  wrote:
> On 11/22/2010 10:46 AM, Roman Dolgiy wrote:
>
> > Hello,
>
> > I need to implement such behavior:
>
> > obj.attr1.attr2.attr3 -->  obj.attr1__attr2__attr3
>
> obj.attr1.attr2.attr3 is parsed as ((obj.attr1).attr2).attr3,
> so this cannot work in general but only if attr1 and attr2 are known to
> not be 'final' names.
>
> > It looks like I have to override obj's class __getattribute__ and also
> > use python descriptors somehow.
>
> > Any help will be much appreciated.
> >http://stackoverflow.com/questions/4247036/python-recursively-getattr...
>
> The code posted there by THC4k depened on such knowledge, which you gave
> there but not here.
>
> --
> Terry Jan Reedy

I need to support a lot of legacy code, with THC4k's approach I'll
have to modify project's existing code to use obj.attr1.val instead of
obj.attr1 but this is not suitable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Need advices regarding the strings (str, unicode, coding) used as interface for an external library.

2010-11-22 Thread jmfauth
I'm planning to build an external lib. This lib will exchange
a lot of strings between the lib and the "core Python code"
of applications.

I wish this lib to be modern, 100% unicode compliant. It will
be developped for Python 2.7 and for Python 3. In an early
phase, technically, it will be developed on Python 2.7 before
Python 3, probably 3.2.

Two options for the strings interface.

a) Pure unicode, that means only type 'unicode' in Python 2.7
and only type 'str' in Python 3.

Similar to the Python io module.

b) Like a) plus ascii and utf-8 encoded type 'str' to keep
some kind of retro compatibility. This lib will anyway
work in a "unicode mode", so the ascii and the encoded
utf-8 str's have to be converted into "unicode".

I'm very comfortable with all this coding stuff
and aware of the pros and cons of each solutions.

My favourite solution is clearly on the a) side.

Advices and comments are welcome. Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittests with different parameters

2010-11-22 Thread Ben Finney
Ulrich Eckhardt  writes:

> Let's say I have two flags invert X and invert Y. Now, for testing these, I
> would write one test for each combination. What I have in the test case is
> something like this:
>
>   def test_invert_flags(self):
>   """test flags to invert coordinates"""
>   tests = [((10, 20), INVERT_NONE, (10, 20)),
>((10, 20), INVERT_X, (-10, 20)),
>((10, 20), INVERT_Y, (10, -20))]
>   for input, flags, expected in tests:
>   res = do_invert(input, flags)
>   self.assertEqual(res, expected,
>"%s caused wrong results" % (flags,))

The ‘testscenarios’ library is designed for just this reason
http://pypi.python.org/pypi/testscenarios/>. It takes a sequence of
scenarios, each of which is a tuple just like in your example, and
causes a separate test run and report for each one.

-- 
 \   “If we listen only to those who are like us, we will squander |
  `\   the great opportunity before us: To live together peacefully in |
_o__)a world of unresolved differences.” —David Weinberger |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Ian Kelly wrote:
> On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote:
>> Also, I'd rather construct the error message from the data
>> instead of maintaining it in different places, because 
>> manually keeping those in sync is another, errorprone burden.
> 
> I'm not sure I follow the problem you're describing.  If the factored
> out workhorse function receives the data to test, what prevents it from
> constructing an error message from that data?

Sorry, unprecise description of what I want. If you define a test function
and run the tests with "-v", the framework prints the first line of the
docstring of that function followed by okay/fail/error, which is much
friendlier to the reader than the exception dump afterwards. Using multiple
very similar functions requires equally similar docstrings that repeat
themselves. I'd prefer creating these from the input data.

Thanks for your suggestion, Ian!

Uli

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Python recursively __getattribute__

2010-11-22 Thread Terry Reedy

On 11/22/2010 10:46 AM, Roman Dolgiy wrote:

Hello,

I need to implement such behavior:

obj.attr1.attr2.attr3 -->  obj.attr1__attr2__attr3


obj.attr1.attr2.attr3 is parsed as ((obj.attr1).attr2).attr3,
so this cannot work in general but only if attr1 and attr2 are known to 
not be 'final' names.



It looks like I have to override obj's class __getattribute__ and also
use python descriptors somehow.

Any help will be much appreciated.
http://stackoverflow.com/questions/4247036/python-recursively-getattribute


The code posted there by THC4k depened on such knowledge, which you gave 
there but not here.


--
Terry Jan Reedy

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


Re: Scheme as a virtual machine?

2010-11-22 Thread toby
On Nov 22, 12:28 pm, namekuseijin  wrote:
> On 22 nov, 14:47, Howard Brazee  wrote:
>
> > On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby
>
> >  wrote:
> > >This is a good (if familiar) observation. Teaching children (or young
> > >people with little exposure to computers) how to program in various
> > >paradigms could produce interesting primary evidence. Pity that this
> > >isn't examined widely and systematically. We could learn something
> > >about how to teach programming and design languages this way, don't
> > >you agree?
>
> > I do.
>
> > A study such as that would be more useful than how to teach languages
> > - it could be useful in teaching other stuff as well.
>
> yes, pity most children are (used to be) taught Basic first.
>
> Also, with a study like this, it's likely some children would be
> taught some lame language and others would be taught some "industrial
> strength" language and still others would be taught some esoteric
> language.

This is not worse than the status quo, which does exactly that, but
without paying attention to outcomes.

What I am proposing is doing it systematically, with observation. Then
we can learn something.

> I'm not sure it'd prove as much as we are hoping for -- as
> they are all Turing equivalent and the kids would be able to
> eventually do the task asked for in any of them -- but I'm sure some
> of those children would be mentally hurt for all their life.  Poor
> pioneers :p
>
> JH, nice to have you back! :)

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


Re: Scheme as a virtual machine?

2010-11-22 Thread markhanif...@gmail.com
On Nov 22, 8:45 am, Raffael Cavallaro
 wrote:
> On 2010-11-22 08:12:27 -0500, markhanif...@gmail.com said:
>
> > All opinions are biased.
>
> All opinions show some bias. Not all opinions represent what is usually
> called a "conflict of interest."
>

Maybe, but in the case of regulars on newsgroups like c.l.l, there are
"conflicts of interest" that either don't or don't indirectly have to
do with profiting off the popularity or perception of a particular
programming language.

Harrop is annoying is the same way that "MatzLisp" guy is annoying on
c.l.l.

> warmest regards,
>
> Ralph
>
> --
> Raffael Cavallaro

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


Re: Scheme as a virtual machine?

2010-11-22 Thread namekuseijin
On 22 nov, 14:47, Howard Brazee  wrote:
> On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby
>
>  wrote:
> >This is a good (if familiar) observation. Teaching children (or young
> >people with little exposure to computers) how to program in various
> >paradigms could produce interesting primary evidence. Pity that this
> >isn't examined widely and systematically. We could learn something
> >about how to teach programming and design languages this way, don't
> >you agree?
>
> I do.
>
> A study such as that would be more useful than how to teach languages
> - it could be useful in teaching other stuff as well.

yes, pity most children are (used to be) taught Basic first.

Also, with a study like this, it's likely some children would be
taught some lame language and others would be taught some "industrial
strength" language and still others would be taught some esoteric
language.  I'm not sure it'd prove as much as we are hoping for -- as
they are all Turing equivalent and the kids would be able to
eventually do the task asked for in any of them -- but I'm sure some
of those children would be mentally hurt for all their life.  Poor
pioneers :p

JH, nice to have you back! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittests with different parameters

2010-11-22 Thread Ian Kelly

On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote:

Let's say I have two flags invert X and invert Y. Now, for testing these, I
would write one test for each combination. What I have in the test case is
something like this:

   def test_invert_flags(self):
   """test flags to invert coordinates"""
   tests = [((10, 20), INVERT_NONE, (10, 20)),
((10, 20), INVERT_X, (-10, 20)),
((10, 20), INVERT_Y, (10, -20))]
   for input, flags, expected in tests:
   res = do_invert(input, flags)
   self.assertEqual(res, expected,
"%s caused wrong results" % (flags,))

So, what I do that I test the function 'do_invert' for different input
combinations and verify the result. The ugly thing is that this will abort
the whole test if one of the tests in the loop fails. So, my question is
how do I avoid this?

I know that I could write a common test function instead:

   def _test_invert_flags(self, input, flags, expected):
   res = do_invert(input, flags)
   self.assertEqual(res, expected)

   def test_invert_flags_non(self):
   """test not inverting coordinates"""
   self._test_invert_flags((10, 20), INVERT_NONE, (10, 20))

   def test_invert_flags_x(self):
   """test inverting X coordinates"""
   self._test_invert_flags((10, 20), INVERT_X, (-10, 20))

   def test_invert_flags_y(self):
   """test inverting Y coordinates"""
   self._test_invert_flags((10, 20), INVERT_Y, (10, -20))

What I don't like here is that this is unnecessarily verbose and that it
basically repeats information.


The above code looks perfectly fine to me for testing.  I think the 
question you should ask yourself is whether the different combinations 
you are testing represent tests of distinct behaviors, or tests of the 
same behavior on a variety of data.  If the former case, as in the 
sample code you posted, then these should probably have separate tests 
anyway, so that you can easily see that both INVERT_X and INVERT_BOTH 
are failing, but INVERT_Y is not, which may be valuable diagnostic data.


On the other hand, if your test is trying the INVERT_X behavior on nine 
different points, you probably don't need or want to see every 
individual point that fails.  It's enough to know that INVERT_X is 
failing and to have a sample point where it fails.  In that case I would 
say just run them in a loop and don't worry that it might exit early.



Also, I'd rather construct the error message
from the data instead of maintaining it in different places, because
manually keeping those in sync is another, errorprone burden.


I'm not sure I follow the problem you're describing.  If the factored 
out workhorse function receives the data to test, what prevents it from 
constructing an error message from that data?


Cheers,
Ian

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


Re: Python recursively __getattribute__

2010-11-22 Thread Andreas Waldenburger
On Mon, 22 Nov 2010 08:41:49 -0800 (PST) Roman Dolgiy  wrote:

> On Nov 22, 6:04 pm, Andreas Waldenburger 
> wrote:
> > On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy
> >  wrote:
> >
> > > Hello,
> >
> > > I need to implement such behavior:
> >
> > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3
> > > It looks like I have to override obj's class __getattribute__ and
> > > also use python descriptors somehow.
> >
> > > Any help will be much appreciated.
> > >http://stackoverflow.com/questions/4247036/python-recursively-getattr...
> >
> > Why? No, really: Why?
> >
> > [...]
> 
> I have a django project.
> 
> obj is django-haystack's SearchResult instance, it contains a lot of
> de-normalized data (user__name, user__address) from django model, and
> I need to access it as result.user.name for compability reasons.

I don't know anything about django, so I may be babbling nonsense. Caveat 
emptor.

How about taking your "user__whatever" thingies and have a function emit 
customized result instances. For this you can just create a plain object 
subclass, say ResultElement. If these "user__whatever" thingies are strings 
(you haven't told), split them by "__" and create a new plain object for every 
level of attributes, attaching it to the previous level.

You can probably make your life easier if you use defaultdicts first and then 
translate these to your object hierarchy.

That's how I'd do it. I don't know if that helps you. If not, please provide 
more info.

/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

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


Re: Scheme as a virtual machine?

2010-11-22 Thread Tamas K Papp
On Mon, 22 Nov 2010 08:25:34 -0800, scattered wrote:

> On Nov 22, 9:45 am, Raffael Cavallaro
>  wrote:
>> On 2010-11-22 08:12:27 -0500, markhanif...@gmail.com said:
>>
>> > All opinions are biased.
>>
>> All opinions show some bias. Not all opinions represent what is usually
>> called a "conflict of interest." Since JH makes his living selling
>> tools and training for certain languages, he has a severe conflict of
>> interest wrt asessing the value of various other languages. If these
>> other languages are just as good or better than those he makes his
>> living from, it would be very damaging to his livlihood for him to
>> admit this fact. As a result, he is a completely unreliable source on
>> the question.
>>
>>
> And you don't think that Jon Harrop could write a book about Haskell if
> he honestly came to think that it were a superior all-aroung language?

Until he writes one, it is useless to speculate about what he could or
could not do.

There are some pretty good books on Haskell, lots of excellent
resources online, and the online community is very supportive.
Writing a book which adds significant value to that would not be a
trivial undertaking.

Best,

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


Re: Scheme as a virtual machine?

2010-11-22 Thread Howard Brazee
On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby
 wrote:

>This is a good (if familiar) observation. Teaching children (or young
>people with little exposure to computers) how to program in various
>paradigms could produce interesting primary evidence. Pity that this
>isn't examined widely and systematically. We could learn something
>about how to teach programming and design languages this way, don't
>you agree?

I do.

A study such as that would be more useful than how to teach languages
- it could be useful in teaching other stuff as well.

-- 
"In no part of the constitution is more wisdom to be found,
than in the clause which confides the question of war or peace 
to the legislature, and not to the executive department." 

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


Re: Python recursively __getattribute__

2010-11-22 Thread Roman Dolgiy
On Nov 22, 6:04 pm, Andreas Waldenburger 
wrote:
> On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy  
> wrote:
>
> > Hello,
>
> > I need to implement such behavior:
>
> > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3
> > It looks like I have to override obj's class __getattribute__ and also
> > use python descriptors somehow.
>
> > Any help will be much appreciated.
> >http://stackoverflow.com/questions/4247036/python-recursively-getattr...
>
> Why? No, really: Why?
>
> In that link you say that you need to do this to support legacy code. I still 
> don't see how this would be necessary. If you need to support legacy code, 
> doesn't that mean that the solution you're asking for already exists?
>
> I really think you should go into detail about why you need this. I'm certain 
> that there's a better solution to your problem. ("Better" being one that is 
> reasonably easy to implement and maintain.)
>
> /W
>
> --
> To reach me via email, replace INVALID with the country code of my home
> country.  But if you spam me, I'll be one sour Kraut.

I have a django project.

obj is django-haystack's SearchResult instance, it contains a lot of
de-normalized data (user__name, user__address) from django model, and
I need to access it as result.user.name for compability reasons.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheme as a virtual machine?

2010-11-22 Thread scattered
On Nov 22, 9:45 am, Raffael Cavallaro
 wrote:
> On 2010-11-22 08:12:27 -0500, markhanif...@gmail.com said:
>
> > All opinions are biased.
>
> All opinions show some bias. Not all opinions represent what is usually
> called a "conflict of interest." Since JH makes his living selling
> tools and training for certain languages, he has a severe conflict of
> interest wrt asessing the value of various other languages. If these
> other languages are just as good or better than those he makes his
> living from, it would be very damaging to his livlihood for him to
> admit this fact. As a result, he is a completely unreliable source on
> the question.
>

And you don't think that Jon Harrop could write a book about Haskell
if he honestly came to think that it were a superior all-aroung
language? The fact that he *didn't* mindlessly reject F# in favor of
O'Caml when F# came out (despite the fact that at the time his company
was deeply (exclusively?) invested in O'Caml and arguably had a vested
interest in having F# fail to gain support) suggests that he is able
to fairly evaluate the merits of other languages. Doubtless he has
biases, but there is no reason to think that they are any greater than
the bias of any programmer who has invested substantial amounts of
time in becoming fluent in a particular language.

> This is why judges must recuse themselves from both civil and criminal
> trials if they have some significant conflict of interest.

But an advocate isn't a judge. Nobody is handing down binding
decisions here - they are just advocating their positions. It would be
better to compare JH to a defense lawyer. You can't reject the
defense's arguments just because the lawyer has a vested interest in
the outcome of the trial.

> the law recognizes that we cannot expect a fair judgement from someone who
> stands to profit significantly if the judgement goes one way or the
> other. Similarly, we cannot expect a fair judgement on the relative
> value of various language tools from a person whose livlihood depends
> on the audience choosing only those certain language tools that he
> sells services and training for.
>
> warmest regards,
>
> Ralph
>
> --
> Raffael Cavallaro

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


Re: print line number and source filename

2010-11-22 Thread Wei Sun
Here is what you want for printing python source filename:

print __file__

> On Tuesday, June 22, 2010 12:44 PM Peng Yu wrote:

> I want to print filename and line number for debugging purpose. So far
> I only find how to print the line number but not how to print
> filename.
> 
> import inspect
> print inspect.currentframe().f_lineno
> 
> I found inspect.getsourcefile(), but I have to supply a class name to
> it. I have searched online, but I do not find how to print the source
> filename. Would you please let me know?
> 
> Also, always importing the inspect module and getting the frame and
> accessing the lineno from the frame is not very convenient to type. Is
> there a shorter way to access the line number (for example, in C++ and
> perl, __LINE__ can be used to access line number, which is much more
> convenient than the way that I found in python).
> 
> --
> Regards,
> Peng


> Submitted via EggHeadCafe 
> Merging SharePoint List Data into Word Documents
> http://www.eggheadcafe.com/tutorials/aspnet/6054abc5-c5fb-4e86-a352-afd0e8c4a7c6/merging-sharepoint-list-data-into-word-documents.aspx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheme as a virtual machine?

2010-11-22 Thread toby
On Nov 22, 10:57 am, Howard Brazee  wrote:
> On Mon, 22 Nov 2010 05:38:53 +0100, Ertugrul S ylemez 
> wrote:
>
> >Haskell is a simple language with a comparably small specification.
> >It's not as simple as Common Lisp, but it's simple.  Note that simple
> >doesn't mean easy.  Haskell is certainly more difficult to learn than
> >other languages, which explains the low number of success stories.  On
> >the other hand, I'm doing rapid web development in it.
>
> I wonder how much that difficulty is innate, and how much is due to
> learning other languages first.

This is a good (if familiar) observation. Teaching children (or young
people with little exposure to computers) how to program in various
paradigms could produce interesting primary evidence. Pity that this
isn't examined widely and systematically. We could learn something
about how to teach programming and design languages this way, don't
you agree?

The OLPC might do some interesting things in this area but it is still
one set of tools. More interesting might be to compare outcomes across
a range of different tools, paradigms, syntaxes, and teaching
strategies.

> I'm an old time CoBOL programmer, and know of quite a few people who
> tried to learn OO-CoBOL without much luck.   The way to learn it was
> to forget it - learn OO with some other language, then come back to it
> later.    We had to divorce ourselves from the old paradigm first.    
>
> --
> "In no part of the constitution is more wisdom to be found,
> than in the clause which confides the question of war or peace
> to the legislature, and not to the executive department."
>
> - James Madison

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


Re: Python recursively __getattribute__

2010-11-22 Thread Andreas Waldenburger
On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy  wrote:

> Hello,
> 
> I need to implement such behavior:
> 
> obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3
> It looks like I have to override obj's class __getattribute__ and also
> use python descriptors somehow.
> 
> Any help will be much appreciated.
> http://stackoverflow.com/questions/4247036/python-recursively-getattribute

Why? No, really: Why?

In that link you say that you need to do this to support legacy code. I still 
don't see how this would be necessary. If you need to support legacy code, 
doesn't that mean that the solution you're asking for already exists?

I really think you should go into detail about why you need this. I'm certain 
that there's a better solution to your problem. ("Better" being one that is 
reasonably easy to implement and maintain.)

/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

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


Re: Scheme as a virtual machine?

2010-11-22 Thread Howard Brazee
On Mon, 22 Nov 2010 05:38:53 +0100, Ertugrul Söylemez 
wrote:

>Haskell is a simple language with a comparably small specification.
>It's not as simple as Common Lisp, but it's simple.  Note that simple
>doesn't mean easy.  Haskell is certainly more difficult to learn than
>other languages, which explains the low number of success stories.  On
>the other hand, I'm doing rapid web development in it.

I wonder how much that difficulty is innate, and how much is due to
learning other languages first.

I'm an old time CoBOL programmer, and know of quite a few people who
tried to learn OO-CoBOL without much luck.   The way to learn it was
to forget it - learn OO with some other language, then come back to it
later.We had to divorce ourselves from the old paradigm first.

-- 
"In no part of the constitution is more wisdom to be found,
than in the clause which confides the question of war or peace 
to the legislature, and not to the executive department." 

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


Python recursively __getattribute__

2010-11-22 Thread Roman Dolgiy
Hello,

I need to implement such behavior:

obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3
It looks like I have to override obj's class __getattribute__ and also
use python descriptors somehow.

Any help will be much appreciated.
http://stackoverflow.com/questions/4247036/python-recursively-getattribute
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheme as a virtual machine?

2010-11-22 Thread Andreas Waldenburger
On 22 Nov 2010 06:26:34 GMT Steven D'Aprano 
 wrote:

> On Sun, 21 Nov 2010 23:57:21 -0500, Steve Holden wrote:
> 
> > Perhaps we could take this thread to alt.small.minded.bickering now?
> 
> Alas, my ISP doesn't carry that newsgroup. Where else can I get my 
> mindless off-topic bitching if not for cross-posts from
> comp.lang.scheme and comp.lang.functional?
> 
> *wink*
> 

alt.off-topic

*wink*

/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

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


Re: unittests with different parameters

2010-11-22 Thread Roy Smith
In article ,
 Ulrich Eckhardt  wrote:

> > Yet another possibility is to leave it the way you originally wrote it
> > and not worry about the fact that the loop aborts on the first failure.
> > Let it fail, fix it, then re-run the test to find the next failure.
> > Perhaps not as efficient as finding them all at once, but you're going
> > to fix them one at a time anyway, so what does it matter?
> 
> Imagine all tests that use INVERT_X fail, all others pass. What would your
> educated guess be where the code is wrong? ;)

Well, let me leave you with one last thought.  There's really two kinds 
of tests -- acceptance tests, and diagnostic tests.

I tend to write acceptance tests first.  The idea is that if all the 
tests pass, I know my code works.  When some test fails, that's when I 
start digging deeper and writing diagnostic tests, to help me figure out 
what went wrong.

The worst test is a test which is never written because it's too hard to 
write.  If it's easy to write a bunch of tests which verify correct 
operation but don't give a lot of clues about what went wrong, it might 
be worth doing that first and seeing what happens.  If some of the tests 
fail, then invest the time to write more detailed tests which give you 
more information about each failure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheme as a virtual machine?

2010-11-22 Thread Raffael Cavallaro

On 2010-11-22 08:12:27 -0500, markhanif...@gmail.com said:


All opinions are biased.


All opinions show some bias. Not all opinions represent what is usually 
called a "conflict of interest." Since JH makes his living selling 
tools and training for certain languages, he has a severe conflict of 
interest wrt asessing the value of various other languages. If these 
other languages are just as good or better than those he makes his 
living from, it would be very damaging to his livlihood for him to 
admit this fact. As a result, he is a completely unreliable source on 
the question.


This is why judges must recuse themselves from both civil and criminal 
trials if they have some significant conflict of interest. The law 
recognizes that we cannot expect a fair judgement from someone who 
stands to profit significantly if the judgement goes one way or the 
other. Similarly, we cannot expect a fair judgement on the relative 
value of various language tools from a person whose livlihood depends 
on the audience choosing only those certain language tools that he 
sells services and training for.


warmest regards,

Ralph

--
Raffael Cavallaro

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


Re: unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Richard Thomas wrote:
[batch-programming different unit tests] 
> You could have a parameter to the test method and some custom
> TestLoader that knows what to do with it.

Interesting, thanks for this suggestion, I'll look into it!

Uli

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Roy Smith wrote:
> Writing one test method per parameter combination, as you suggested, is
> a reasonable approach, especially if the number of combinations is
> reasonably small.

The number of parameters and thus combinations are unfortunately rather
large. Also, sometimes that data is not static but rather computed from a
loop instead. There are a few optimised computations, where I compute the
expected result with the slow but simple version, in those cases I want to
check a whole range of inputs using a loop.

I'm wondering, classes aren't as static as I'm still used to from C++, so
creating the test functions dynamically with a loop outside the class
declaration should be another possibility...

> Yet another possibility is to leave it the way you originally wrote it
> and not worry about the fact that the loop aborts on the first failure.
> Let it fail, fix it, then re-run the test to find the next failure.
> Perhaps not as efficient as finding them all at once, but you're going
> to fix them one at a time anyway, so what does it matter?

Imagine all tests that use INVERT_X fail, all others pass. What would your
educated guess be where the code is wrong? ;)

Thanks Roy!

Uli

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Error Starting Python(Django) App using Apache+Mod_Wsgi

2010-11-22 Thread Anurag Chourasia
All,

I have a problem in starting my Python(Django) App using Apache and Mod_Wsgi

I am using Django 1.2.3 and Python 2.6.6 running on Apache 2.2.17 with
Mod_Wsgi 3.3

When I try to access the app from Web Browser, I am getting these
errors.

[Mon Nov 22 09:45:25 2010] [notice] Apache/2.2.17 (Unix) mod_wsgi/3.3
Python/2.6.6 configured -- resuming normal operations

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] mod_wsgi
(pid=1273874): Target WSGI script '/u01/home/apli/wm/app/gdd/pyserver/
apache/django.wsgi' cannot be loaded as Python module.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] mod_wsgi
(pid=1273874): Exception occurred processing WSGI script '/u01/home/
apli/wm/app/gdd/pyserver/apache/django.wsgi'.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] Traceback
(most recent call last):

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   File "/u01/
home/apli/wm/app/gdd/pyserver/apache/django.wsgi", line 19, in


[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] import
django.core.handlers.wsgi

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   File "/usr/
local/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line
1, in 

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from
threading import Lock

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   File "/usr/
local/lib/python2.6/threading.py", line 13, in 

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from
functools import wraps

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   File "/usr/
local/lib/python2.6/functools.py", line 10, in 

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from
_functools import partial, reduce

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] ImportError:
rtld: 0712-001 Symbol PyArg_UnpackTuple was referenced

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   from
module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a
runtime definition


[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   of the
symbol was not found.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld:
0712-001 Symbol PyCallable_Check was referenced

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   from
module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a
runtime definition

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   of the
symbol was not found.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld:
0712-001 Symbol PyDict_Copy was referenced


[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   from
module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a
runtime definition

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   of the
symbol was not found.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld:
0712-001 Symbol PyDict_Merge was referenced

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   from
module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a
runtime definition

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   of the
symbol was not found.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld:
0712-001 Symbol PyDict_New was referenced

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   from
module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a
runtime definition

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   of the
symbol was not found.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld:
0712-001 Symbol PyErr_Occurred was referenced

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   from
module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a
runtime definition

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   of the
symbol was not found.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld:
0712-001 Symbol PyErr_SetString was referenced

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   from
module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a
runtime definition

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191]   of the
symbol was not found.

[Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] \t0509-021
Additional errors occurred but are not reported.


I assume that those missing runtime definitions are supposed to be in
the Python executable. Doing an nm on the first missing symbol reveals
that it does exist.

root [zibal]% nm  /usr/local/bin/python | grep -i PyArg_UnpackTuple
.PyArg_UnpackTuple   T   268683204 524
PyArg_UnpackTupleD   537073500
PyArg_UnpackTupled   537073500  12
PyArg_UnpackTuple:F-1 - 224

Please guide.

Regards,
Guddu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittests with different parameters

2010-11-22 Thread Roy Smith
In article ,
 Ulrich Eckhardt  wrote:

>   def test_invert_flags(self):
>   """test flags to invert coordinates"""
>   tests = [((10, 20), INVERT_NONE, (10, 20)),
>((10, 20), INVERT_X, (-10, 20)),
>((10, 20), INVERT_Y, (10, -20))]
>   for input, flags, expected in tests:
>   res = do_invert(input, flags)
>   self.assertEqual(res, expected,
>"%s caused wrong results" % (flags,))
> 
> So, what I do that I test the function 'do_invert' for different input
> combinations and verify the result. The ugly thing is that this will abort
> the whole test if one of the tests in the loop fails. So, my question is
> how do I avoid this?

Writing one test method per parameter combination, as you suggested, is 
a reasonable approach, especially if the number of combinations is 
reasonably small.  Another might be to make your loop:

   failCount = 0
   for input, flags, expected in tests:
   res = do_invert(input, flags)
   if res != expected:
   print "%s caused wrong results" % (flags,)
   failCount += 1
   self.assertEqual(failCount, 0, "%d of them failed" % failCount)

Yet another possibility is to leave it the way you originally wrote it 
and not worry about the fact that the loop aborts on the first failure.  
Let it fail, fix it, then re-run the test to find the next failure.  
Perhaps not as efficient as finding them all at once, but you're going 
to fix them one at a time anyway, so what does it matter?  It may also 
turn out that all the failures are due to a single bug, so fixing one 
fixes them all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittests with different parameters

2010-11-22 Thread Richard Thomas
On Nov 22, 11:38 am, Ulrich Eckhardt 
wrote:
> Hi!
>
> I'm writing tests and I'm wondering how to achieve a few things most
> elegantly with Python's unittest module.
>
> Let's say I have two flags invert X and invert Y. Now, for testing these, I
> would write one test for each combination. What I have in the test case is
> something like this:
>
>   def test_invert_flags(self):
>       """test flags to invert coordinates"""
>       tests = [((10, 20), INVERT_NONE, (10, 20)),
>                ((10, 20), INVERT_X, (-10, 20)),
>                ((10, 20), INVERT_Y, (10, -20))]
>       for input, flags, expected in tests:
>           res = do_invert(input, flags)
>           self.assertEqual(res, expected,
>                            "%s caused wrong results" % (flags,))
>
> So, what I do that I test the function 'do_invert' for different input
> combinations and verify the result. The ugly thing is that this will abort
> the whole test if one of the tests in the loop fails. So, my question is
> how do I avoid this?
>
> I know that I could write a common test function instead:
>
>   def _test_invert_flags(self, input, flags, expected):
>       res = do_invert(input, flags)
>       self.assertEqual(res, expected)
>
>   def test_invert_flags_non(self):
>       """test not inverting coordinates"""
>       self._test_invert_flags((10, 20), INVERT_NONE, (10, 20))
>
>   def test_invert_flags_x(self):
>       """test inverting X coordinates"""
>       self._test_invert_flags((10, 20), INVERT_X, (-10, 20))
>
>   def test_invert_flags_y(self):
>       """test inverting Y coordinates"""
>       self._test_invert_flags((10, 20), INVERT_Y, (10, -20))
>
> What I don't like here is that this is unnecessarily verbose and that it
> basically repeats information. Also, I'd rather construct the error message
> from the data instead of maintaining it in different places, because
> manually keeping those in sync is another, errorprone burden.
>
> Any suggestions?
>
> Uli
>
> --
> Domino Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

You could have a parameter to the test method and some custom
TestLoader that knows what to do with it. See 
http://docs.python.org/library/unittest.html.
I would venture that unit tests are verbose by their very nature; they
are 100% redundant. The usual argument against unnecessary redundancy,
that of ease of maintenance, really doesn't apply to unit tests.
Anyway, good luck with your efforts.

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


Re: Scheme as a virtual machine?

2010-11-22 Thread markhanif...@gmail.com
On Nov 21, 10:38 pm, Ertugrul Söylemez  wrote:
> "Jon Harrop"  wrote:
> > "Ertugrul Söylemez"  wrote in message
> >news:20101014052650.510e8...@tritium.streitmacht.eu...
>
> > > That's nonsense.
>
> > Actually namekuseijin is right. You really need to persevere and
> > familiarize yourself with some of the other languages out
> > there. Haskell is many things but simple is not one of them. If
> > Haskell were half of the things you think it is, it would have more
> > credible success stories.
>
> Jon, I don't care about your opinion, because it's biased.

All opinions are biased.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some syntactic sugar proposals

2010-11-22 Thread Andreas Löscher
> if x in range(a, b): #wrong!
> it feels so natural to check it that way, but we have to write
> if a <= x <= b
> I understand that it's not a big deal, but it would be awesome to have
> some optimisations - it's clearly possible to detect things like that
> "wrong" one and fix it in a bytecode.


You can implement it yourself:

class between(object):
def __init__(self, a,b):
super(crang, self).__init__()
self.a=a
self.b=b
def __contains__(self, value):
return self.a <= value <= self.b

>>> 12.45 in between(-100,100)
true


But do you need

a <  x <  b
a <= x <  b
a <= x <= b or
a <  x <= b ?

Sure, you could set a new parameter for this, but the normal way is not
broken at all.

Best


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


unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Hi!

I'm writing tests and I'm wondering how to achieve a few things most
elegantly with Python's unittest module.

Let's say I have two flags invert X and invert Y. Now, for testing these, I
would write one test for each combination. What I have in the test case is
something like this:

  def test_invert_flags(self):
  """test flags to invert coordinates"""
  tests = [((10, 20), INVERT_NONE, (10, 20)),
   ((10, 20), INVERT_X, (-10, 20)),
   ((10, 20), INVERT_Y, (10, -20))]
  for input, flags, expected in tests:
  res = do_invert(input, flags)
  self.assertEqual(res, expected,
   "%s caused wrong results" % (flags,))

So, what I do that I test the function 'do_invert' for different input
combinations and verify the result. The ugly thing is that this will abort
the whole test if one of the tests in the loop fails. So, my question is
how do I avoid this?

I know that I could write a common test function instead:

  def _test_invert_flags(self, input, flags, expected):
  res = do_invert(input, flags)
  self.assertEqual(res, expected)

  def test_invert_flags_non(self):
  """test not inverting coordinates"""
  self._test_invert_flags((10, 20), INVERT_NONE, (10, 20))

  def test_invert_flags_x(self):
  """test inverting X coordinates"""
  self._test_invert_flags((10, 20), INVERT_X, (-10, 20))

  def test_invert_flags_y(self):
  """test inverting Y coordinates"""
  self._test_invert_flags((10, 20), INVERT_Y, (10, -20))

What I don't like here is that this is unnecessarily verbose and that it
basically repeats information. Also, I'd rather construct the error message
from the data instead of maintaining it in different places, because
manually keeping those in sync is another, errorprone burden.


Any suggestions?

Uli

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: multiple times subprocess fails on windows

2010-11-22 Thread kvbik
To be more specific, I have something like this in rvirtualenv itself
(that's the pokus.py file):

import os
os.system("echo 128")

I generate a batch file like this (that's the pokus.bat file):

@echo off
pokus.py

And after that, I run the pokus.bat file from a test (that's the
run.py file):

from subprocess import Popen, PIPE
p = Popen('pokus.bat', stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = p.communicate()
print stdout.strip()

And the problem is, that I don't receive the output of the os.system
to the PIPE. Probable there is something different on windows stdout
redirection, because similar stuff works on linux..

Thanks, Jakub.


On Nov 21, 8:39 pm, kvbik  wrote:
> Hello,
>
> in a test suite in my project (called rvirtualenv [1]) I discovered a
> strange behaviour when calling from python a batch file which calles
> another python and this calles a shell command.
>
> [1]http://github.com/kvbik/rvirtualenv
>
> I know it sounds pretty strange, but I do this only because I am
> testing such specific tool (that has similar functionality like
> original virtualenv and there are things like activate.bat commands).
>
> I've uploaded some code snippet here:
>
> https://gist.github.com/709004/6ccc44d6aed5fe694bb2adbef2400bbea92998a1
>
> If anyone could explain me this behaviour I would be more than happy,
> because right now it is the only failing test in my project ;).
>
> Thanks in advance, Jakub..

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


Accepting a SAML 2 Assertion

2010-11-22 Thread raghu bg
Hello,

I am working on providing a SSO solution to a customer who acts as an
identity provider. He already has IDP on his side to generate SAML 2
assertions with user first name , last name  and time stamp as parameters.
Our task is to accept this assertion which is signed, decrypt it and send it
to the authenticator we already have. The authenticator validates the info
and gives access to our application which is written using Python. Here we
act as the *service provider.*
I am new to SAML and have no idea how to integrate SAML to our current
Python application. Can you help me on how to accept these assertion
requests from the Idp and decrypt it at Service Provider end using Python.

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


Re: building a web interface

2010-11-22 Thread Jean-Michel Pichavant

Shel wrote:

Hello,

I am pretty new to all this. I have some coding experience, and am
currently most comfortable with Python.  I also have database design
experience with MS Access, and have just created my first mySQL db.

So right now I have a mySQL db structure and some Python code. My end
goal is to create a browser-based interactive fiction/game thing. My
code is currently just using dummy data rather than pulling in data
from the db, but I think/hope it won't be too big of a deal to
interact with the db through Python (famous last words...).

My main problem right now is how to do the web interface. I don't know
much about web architecture, unfortunately. I think I need a CGI
script?

What I would really like is to find a GUI tool to design the interface
that would have customizable templates or drag-and-drop elements or
something, so I wouldn't have to code much by hand. Something easy, if
such a tool exists.

Also would prefer something that I would be able to install/use
without having much access to the server where the site will be hosted
(on a university server that I don't have control over). I don't fully
understand how a lot of the tools I have been looking at work, but it
seems like they're often things where you'd have to get an
administrator to do stuff on the server (is that right?), which I
would prefer to avoid.

It looks like Django has some sort of standalone implementation, but
I'm not clear on how that would work or how much of a learning curve
there would be for using it.

If anyone has any thoughts or suggestions, I would really appreciate
it.

Hope my questions make sense. I don't really know what I'm doing, so
could be they're a bit silly. I apologize if that's the case, and
please let me know if you need any additional informmation.

Thanks,
Shel
  
Django is quite popular, they claim to be easy to learn/use. That's for 
the web framework.
You could use pyjamas for the web interface, looks like it works well 
with django.


Hmm, writing python code only, sounds like a dream come true :D

Note that I never used one of these, it just happened I had to look for 
possible solutions for a web application.



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


Re: Reading bz2 file into numpy array

2010-11-22 Thread Peter Otten
Johannes Korn wrote:

> I tried:
> 
> from bz2 import *
> from numpy import *
> fd = BZ2File(filename, 'rb')
> read_data = fromfile(fd, float32)
> 
> but BZ2File doesn't seem to produce a transparent filehandle.

> is there a convenient way to read bz2 files into a numpy array?

Try

import numpy
import bz2

filename = ...

f = bz2.BZ2File(filename)
data = numpy.fromstring(f.read(), numpy.float32)

print data

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


Reading bz2 file into numpy array

2010-11-22 Thread Johannes Korn
Hi,

is there a convenient way to read bz2 files into a numpy array?

I tried:

from bz2 import *
from numpy import *
fd = BZ2File(filename, 'rb')
read_data = fromfile(fd, float32)

but BZ2File doesn't seem to produce a transparent filehandle.

Kind regards!

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


Re: MATLAB to Python?

2010-11-22 Thread Peter Otten
MATLABdude wrote:

> On Nov 17, 10:53 am, Arnaud Delobelle  wrote:
>> I guess that the step is supposed to be h, so you should write:
>> xx = range(-kappa, kappa+1, h)
> 
> This is what I have in the source code:
> ---8<---8<---8<---8<---
> h =  0.105069988414
> xx = range(-kappa, kappa+1, h)
> ---8<---8<---8<---8<---
> 
> This is what Python says: ValueError: range() step argument must not
> be zero
> 
> Can step not be a float value?

Indeed. Older Pythons will warn you and then try to convert the arguments to 
integers

>>> range(1.0)
__main__:1: DeprecationWarning: integer argument expected, got float
[0]

and in 2.7 or 3.x you'll get a type error:

>>> range(1.0)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: range() integer end argument expected, got float.

Try numpy.arange() instead:

>>> numpy.arange(0, 1, .1)
array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])


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


Re: MATLAB to Python?

2010-11-22 Thread Chris Rebert
On Mon, Nov 22, 2010 at 12:47 AM, MATLABdude  wrote:
> On Nov 17, 10:53 am, Arnaud Delobelle  wrote:
>> I guess that the step is supposed to be h, so you should write:
>>     xx = range(-kappa, kappa+1, h)
>
> This is what I have in the source code:
> ---8<---8<---8<---8<---
> h =  0.105069988414
> xx = range(-kappa, kappa+1, h)
> ---8<---8<---8<---8<---
>
> This is what Python says: ValueError: range() step argument must not
> be zero
>
> Can step not be a float value?

Correct. Note the DeprecationWarning which is also shown:
__main__:1: DeprecationWarning: integer argument expected, got float

There are too many subtleties with floating-point, so range() doesn't
handle it; that way, you deal with the subtleties yourself,
explicitly.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MATLAB to Python?

2010-11-22 Thread MATLABdude
On Nov 17, 10:53 am, Arnaud Delobelle  wrote:
> I guess that the step is supposed to be h, so you should write:
>     xx = range(-kappa, kappa+1, h)

This is what I have in the source code:
---8<---8<---8<---8<---
h =  0.105069988414
xx = range(-kappa, kappa+1, h)
---8<---8<---8<---8<---

This is what Python says: ValueError: range() step argument must not
be zero

Can step not be a float value?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Weibull distr. random number generation

2010-11-22 Thread Dimos
Hello Mark,

Exactly, thanks very much!

Dimos

--- On Sat, 11/20/10, Mark Dickinson  wrote:

> From: Mark Dickinson 
> Subject: Re: Weibull distr. random number generation
> To: python-list@python.org
> Date: Saturday, November 20, 2010, 7:09 PM
> On Nov 19, 3:21 pm, Dimos 
> wrote:
> > I would like to use the random module, and if I
> understand well the Random class, to create  1300 decimal
> numbers in python, by providing the 2 Weibull parameters
> (b,c). How this can be done???
> >
> > import random
> > print random
> > random.weibullvariate(b,c)
> > How can I set the population size n=1300 in decimals?
> 
> random.weibullvariate(b, c) generates a single sample from
> the
> specified Weibull distribution.  If you want 1300
> samples, you'd use
> this within a loop.  For example, here's code to put
> 10 Weibull
> variates with scale parameter 12345.0 and shape parameter
> 6.0 into a
> list:
> 
> >>> import random
> >>> samples = []
> >>> for i in xrange(10):
> ... 
>    samples.append(random.weibullvariate(12345.0,
> 6.0))
> ...
> >>> print samples
> [15553.186762792948, 14304.175032317309,
> 9015.5053691933044,
> 12585.469181732506, 9436.2677219460638, 13350.89758791281,
> 5687.4330250037565, 12172.747202474553,
> 9687.8685933610814,
> 11699.040541029028]
> 
> A more experienced Python programmer might use a list
> comprehension to
> achieve the same effect in a single line:
> 
> >>> samples = [random.weibullvariate(12345.0, 6.0)
> for _ in xrange(10)]
> >>> print samples
> [10355.396846416865, 14689.507803932587,
> 11491.850991569485,
> 14128.56397290655, 12592.739991974759, 9076.7752548878998,
> 11868.012238422616, 12016.784656753523,
> 14724.818462506191,
> 13253.477389116439]
> 
> Is this the sort of thing you were looking for?
> 
> --
> Mark
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


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