Re: Last iteration?

2007-10-17 Thread Raymond Hettinger
> def lastdetecter(iterable):
> "fast iterator algebra"
> lookahead, t = tee(iterable)
> lookahead.next()
> t = iter(t)
> return chain(izip(repeat(False), imap(itemgetter(1),
> izip(lookahead, t))), izip(repeat(True),t))

More straight-forward version:

def lastdetecter(iterable):
t, lookahead = tee(iterable)
lookahead.next()
return izip(chain(imap(itemgetter(0), izip(repeat(False),
lookahead)), repeat(True)), t)


Raymond

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


Re: how to get my own namespace ?

2007-10-17 Thread Peter Otten
stef mientki wrote:

> I want to view my own namespace,
> i.e. to see the modules namespace in the module itself,
> is that possible ?
> 
> I can use
>dir()
> but I read dir is just a convenience function,
> and besides I want key/value pairs.

Use globals() or vars().

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


Re: Static variable vs Class variable

2007-10-17 Thread paul . melis
On Oct 10, 8:23 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > However, it is not true that += "always leads to a rebinding of a to the
> > result of the operation +". The + operator for lists creates a new list.
> > += for lists does an in-place modification:
>
> It still is true.
>
> a += b
>
> rebinds a. Period. Which is the _essential_ thing in my post, because
> this rebinding semantics are what confused the OP.

Doesn't this depend on wether "a" supports __iadd__ or not? Section
3.4.7 of the docs say

"""
If a specific method is not defined, the augmented operation falls
back to the normal methods. For instance, to evaluate the expression x
+=y, where x is an instance of a class that has an __iadd__() method,
x.__iadd__(y) is called. If x is an instance of a class that does not
define a __iadd__() method, x.__add__(y) and y.__radd__(x) are
considered, as with the evaluation of x+y.
"""

So if a.__iadd__ exists, a += b is executed as a.__iadd__(b), in which
case there's no reason to rebind a.

However, this confuses the heck out of me:

>>> class A:
... l = []
...
>>> class B(A): pass
...
>>> B.__dict__
{'__module__': '__main__', '__doc__': None}
>>> B.l
[]
>>> B.l.append('1')
>>> B.l
['1']
>>> B.__dict__
{'__module__': '__main__', '__doc__': None}
>>> B.l.__iadd__('2')
['1', '2']
>>> B.l
['1', '2']
>>> B.__dict__
{'__module__': '__main__', '__doc__': None}
>>> B.l += '3'
>>> B.__dict__
{'__module__': '__main__', '__doc__': None, 'l': ['1', '2', '3']}

Why is B.l set for the += case only? B.l.__iadd__ obviously exists.

Paul




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


Re: Simple HTML template engine?

2007-10-17 Thread Adrian Cherry
Bruno Desthuilliers <[EMAIL PROTECTED]> 
wrote in news:[EMAIL PROTECTED]:

> 
> Did you read the OP's question ?-)

Yup, as much as anyone else has. Why?

Adrian

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


Re: Static variable vs Class variable

2007-10-17 Thread Marc 'BlackJack' Rintsch
On Wed, 17 Oct 2007 00:33:59 -0700, paul.melis wrote:

> On Oct 10, 8:23 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> > However, it is not true that += "always leads to a rebinding of a to the
>> > result of the operation +". The + operator for lists creates a new list.
>> > += for lists does an in-place modification:
>>
>> It still is true.
>>
>> a += b
>>
>> rebinds a. Period. Which is the _essential_ thing in my post, because
>> this rebinding semantics are what confused the OP.
> 
> Doesn't this depend on wether "a" supports __iadd__ or not?

No.  As shown several times in this thread already.

> Section 3.4.7 of the docs say
> 
> """
> If a specific method is not defined, the augmented operation falls
> back to the normal methods. For instance, to evaluate the expression x
> +=y, where x is an instance of a class that has an __iadd__() method,
> x.__iadd__(y) is called. If x is an instance of a class that does not
> define a __iadd__() method, x.__add__(y) and y.__radd__(x) are
> considered, as with the evaluation of x+y.
> """
> 
> So if a.__iadd__ exists, a += b is executed as a.__iadd__(b), in which
> case there's no reason to rebind a.

`__iadd__` *may* doing the addition in place and return `self` but it is
also allowed to return a different object.  So there is always a rebinding.

> However, this confuses the heck out of me:
> 
 class A:
> ... l = []
> ...
 class B(A): pass
> ...
 B.__dict__
> {'__module__': '__main__', '__doc__': None}
 B.l
> []
 B.l.append('1')
 B.l
> ['1']
 B.__dict__
> {'__module__': '__main__', '__doc__': None}
 B.l.__iadd__('2')
> ['1', '2']

Here you see that the method actually returns an object!

 B.l
> ['1', '2']
 B.__dict__
> {'__module__': '__main__', '__doc__': None}
 B.l += '3'
 B.__dict__
> {'__module__': '__main__', '__doc__': None, 'l': ['1', '2', '3']}
> 
> Why is B.l set for the += case only? B.l.__iadd__ obviously exists.

Because there is always a rebinding involved.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> On Oct 10, 8:23 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

>> rebinds a. Period. Which is the _essential_ thing in my post, because
>> this rebinding semantics are what confused the OP.
> 
> Doesn't this depend on wether "a" supports __iadd__ or not? Section
> 3.4.7 of the docs say
> 
> """
> If a specific method is not defined, the augmented operation falls
> back to the normal methods. For instance, to evaluate the expression x
> +=y, where x is an instance of a class that has an __iadd__() method,
> x.__iadd__(y) is called. If x is an instance of a class that does not
> define a __iadd__() method, x.__add__(y) and y.__radd__(x) are
> considered, as with the evaluation of x+y.
> """
> 
> So if a.__iadd__ exists, a += b is executed as a.__iadd__(b), in which
> case there's no reason to rebind a.
> 
You misunderstand the documentation, what you quoted doesn't say that 
the assignment is suppressed. If a.__iadd__ exists, a += b is executed 
as a = a.__iadd__(b)

The options for a+=b are:

   a = a.__iadd__(b)
   a = a.__add__(b)
   a = b.__radd__(a)

but the assignment always happens, it is only what gets executed for the 
right hand side which varies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread paul . melis
On Oct 17, 10:00 am, Duncan Booth <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
> > On Oct 10, 8:23 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> 
> >> rebinds a. Period. Which is the _essential_ thing in my post, because
> >> this rebinding semantics are what confused the OP.
>
> > Doesn't this depend on wether "a" supports __iadd__ or not? Section
> > 3.4.7 of the docs say
>
> > """
> > If a specific method is not defined, the augmented operation falls
> > back to the normal methods. For instance, to evaluate the expression x
> > +=y, where x is an instance of a class that has an __iadd__() method,
> > x.__iadd__(y) is called. If x is an instance of a class that does not
> > define a __iadd__() method, x.__add__(y) and y.__radd__(x) are
> > considered, as with the evaluation of x+y.
> > """
>
> > So if a.__iadd__ exists, a += b is executed as a.__iadd__(b), in which
> > case there's no reason to rebind a.
>
> You misunderstand the documentation, what you quoted doesn't say that
> the assignment is suppressed. If a.__iadd__ exists, a += b is executed
> as a = a.__iadd__(b)
>
> The options for a+=b are:
>
>a = a.__iadd__(b)
>a = a.__add__(b)
>a = b.__radd__(a)
>
> but the assignment always happens, it is only what gets executed for the
> right hand side which varies.

Curious, do you have the relevant section in the docs that describes
this behaviour?

Paul

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


Re: Last iteration?

2007-10-17 Thread Peter Otten
Raymond Hettinger wrote:

> [Diez B. Roggisch]
>> > out:) But I wanted a general purpose based solution to be available that
>> > doesn't count on len() working on an arbitrary iterable.
> 
> [Peter Otten]
>> You show signs of a severe case of morbus itertools.
>> I, too, am affected and have not yet fully recovered...
> 
> Maybe you guys were secretly yearning for a magical last element
> detector used like this:

Not secretly...

> def lastdetecter(iterable):
> it = iter(iterable)
> value = it.next()
> for nextvalue in it:
> yield (False, value)
> value = nextvalue
> yield (True, value)

as that's what I posted above...

> def lastdetecter(iterable):
> "fast iterator algebra"
> lookahead, t = tee(iterable)

  # make it cope with zero-length iterables 
  lookahead = islice(lookahead, 1, None)

> return chain(izip(repeat(False), imap(itemgetter(1),
> izip(lookahead, t))), izip(repeat(True),t))

and that's the "somebody call the doctor -- now!" version ;)

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


Re: Capturing OutputDebugString information in python

2007-10-17 Thread Tim Golden
danbrotherston wrote:
> I am trying to get the output from the win32 platform command
> OutputDebugString.  I have used the following C++ code as a
> guideline:
> 
> http://groups.google.com/group/microsoft.public.vc.utilities/browse_frm/thread/1434418cb968d053/1a3c957675242c7e?lnk=st&q=DBWIN_BUFFER&rnum=3#1a3c957675242c7e
> 
> And I have been able to translate most things into python, but I have
> been unable to get it to work.  I use the pywin extensions to call
> CreateEvent and create the required events.  But when I wait on the
> event using the WaitOnSingleEvent call, it hangs indefinitely.

Well, unhelpfully, I can't get it to work, either! I used the code below,
so you might compare with yours to see if we're doing the same thing,
but I can't see any obvious problems. This page which you may have seen:

   http://www.unixwiz.net/techtips/outputdebugstring.html

is useful, but the security problem they identify with the mutex
doesn't seem to apply when I'm a local admin and my two processes
are run on my desktop.

I did have a dig inside the mmapmodule.c code (for the second time
in a month!) and a few differences do emerge from the posted code:

- The python code uses a NULL security attribute, which should mean:
full access to everyone.
- The python code assumes an access of write means: create the file
mapping for PAGE_READWRITE and map it for WRITE, while the posted
code maps for READ only.

Neither of these seems terribly significant, but who knows? The
problem of course is that the OutputDebugString function is designed
to fail silently, so you've no idea which part of your debugger is
causing it to fail -- or something else altogether.

I've scanned (very quickly) the MS groups on Google and I can't see
anything helpful. Hopefully someone else on this or on the win32
list has more experience & expertise than I do here. (Which wouldn't
be hard!)

TJG


import sys
import mmap

import win32security
import win32event

def main (args):
   sd = win32security.SECURITY_DESCRIPTOR ()
   dacl = win32security.ACL ()
   sd.SetSecurityDescriptorDacl (1, dacl, 0)
   sa = win32security.SECURITY_ATTRIBUTES ()
   sa.SECURITY_DESCRIPTOR = sd

   buffer_ready = win32event.CreateEvent (sa, 0, 0, "DBWIN_BUFFER_READY")
   data_ready = win32event.CreateEvent (sa, 0, 0, "DBWIN_DATA_READY")
   buffer = mmap.mmap (0, 4096, "DBWIN_BUFFER", mmap.ACCESS_READ)

   win32event.SetEvent (buffer_ready)

   while win32event.WaitForSingleObject (data_ready, 1000) == 
win32event.WAIT_TIMEOUT:
 pass

if __name__ == '__main__':
   main (sys.argv[1:])


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


Re: Static variable vs Class variable

2007-10-17 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> Curious, do you have the relevant section in the docs that describes
> this behaviour?
 
Yes, but mostly by implication. In section 3.4.7 of the docs, the sentence 
before the one you quoted says:

  These methods should attempt to do the operation in-place (modifying
  self) and return the result (which could be, but does not have to be,
  self). 

The 'does not have to be self' tells you that the result of __iadd__ is 
used, i.e there is still an assignment going on.

Just read all of that paragraph carefully. It says that if there is no 
__iadd__ method it considers calling __add__/__radd__. Nowhere does it say 
that it handles the result of calling the methods differently.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread paul . melis
On Oct 17, 11:08 am, Duncan Booth <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
> > Curious, do you have the relevant section in the docs that describes
> > this behaviour?
>
> Yes, but mostly by implication. In section 3.4.7 of the docs, the sentence
> before the one you quoted says:
>
>   These methods should attempt to do the operation in-place (modifying
>   self) and return the result (which could be, but does not have to be,
>   self).
>
> The 'does not have to be self' tells you that the result of __iadd__ is
> used, i.e there is still an assignment going on.
>
> Just read all of that paragraph carefully. It says that if there is no
> __iadd__ method it considers calling __add__/__radd__. Nowhere does it say
> that it handles the result of calling the methods differently.

Right, the paragraph is actually pretty clear after a second reading.
I find it surprising nonetheless, as it's easy to forget to return a
result when you're implementing a method that does an in-place
operation, like __iadd__:

>>> class C:
... def __init__(self, v):
... self.v = v
... def __iadd__(self, other):
... self.v += other
...
>>> c=C(1)
>>> c.v
1
>>> c += 3
>>> c
>>> c is None
True


Paul

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


Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes:

> Right, the paragraph is actually pretty clear after a second
> reading.  I find it surprising nonetheless, as it's easy to forget
> to return a result when you're implementing a method that does an
> in-place operation, like __iadd__:

I've recently been bitten by that, and I don't understand the
reasoning behind __iadd__'s design.  I mean, what is the point of an
*in-place* add operation (and others) if it doesn't always work
in-place?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's coming... from unexpected angles.

2007-10-17 Thread Eric Brunel
On Tue, 16 Oct 2007 13:19:26 +0200, Ben Finney  
<[EMAIL PROTECTED]> wrote:

> "Eric Brunel" <[EMAIL PROTECTED]> writes:
>
>> Well, I'd definetely vote for a name change for PyPy, as in french,
>> it's pronounced "pee-pee", and yes, it means what you think it
>> means... ;-)
>
> Does that mean you pronounce the word for the serpent as "pee-thon"?

Yes.

> Anyway, the pronunciation of "Python" (and hence the "Py" in "PyPy")
> is however you pronounce that word in the name of the comedy troupe,
> Monty Python. That's where the name originates, after all.

But the average frenchman will also pronounce "monty pee-thon" (I know:  
that's weird...).
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


UK Jobs With VISA Sponsorship

2007-10-17 Thread Devender.Kumar
Hi,

Can u let me please about UK work Permit and Job..right
now am in Norway and holding Schengen Visa

Bye
Devender Kumar
0047 96813328


This e-mail and any attachment are confidential and may be privileged or 
otherwise protected from disclosure. It is solely intended for the person(s) 
named above. If you are not the intended recipient, any reading, use, 
disclosure, copying or distribution of all or parts of this e-mail or 
associated attachments is strictly prohibited. If you are not an intended 
recipient, please notify the sender immediately by replying to this message or 
by telephone and delete this email and any attachments permanently from your 
system.

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

Re: negative base raised to fractional exponent

2007-10-17 Thread Steve Holden
John Machin wrote:
> On Oct 17, 8:03 am, Steve Holden <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>>> Does anyone know of an approximation to raising a negative base to a
>>> fractional exponent? For example, (-3)^-4.1 since this cannot be
>>> computed without using imaginary numbers. Any help is appreciated.
>> A couple of questions.
>>
>> 1. How do you approximate a complex number in the reals? That doesn't
>> make sense.
>>
>> 2. x ^ -4. = 1 / (x ^ 4.), so where do complex numbers enter
>> into this anyway?
>>
>> 3. I think you will find the complex numbers start to emerge as you
>> explore fractional exponents.
> 
> This is part of the story -- the other part is that the story differs
> depending on whether x is positive or negative.
> 
>> This being Python, and an interactive interpreter being available, you
>> can always just try it:
>>
>>  >>> -3 ** -4.
>> -0.010927147607830808
> 
> Steve, Trying to memorise the operator precedence table for each of
> several languages was never a good idea. I admit advanced age :-) and
> give up and use parentheses, just like the OP did:
> 
 (-3)**-4.1
> Traceback (most recent call last):
>   File "", line 1, in 
> ValueError: negative number cannot be raised to a fractional power
> 
> Best regards,
> John
> 
Well I guess I'd better admit to advances age too. Particularly since 
there was a python-dev thread about precedence, unaries and 
exponentiation not too long ago.

regards
  Steve

-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: Last iteration?

2007-10-17 Thread Paul Hankin
On Oct 17, 8:16 am, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> > def lastdetecter(iterable):
> > "fast iterator algebra"
> > lookahead, t = tee(iterable)
> > lookahead.next()
> > t = iter(t)
> > return chain(izip(repeat(False), imap(itemgetter(1),
> > izip(lookahead, t))), izip(repeat(True),t))
>
> More straight-forward version:
>
> def lastdetecter(iterable):
> t, lookahead = tee(iterable)
> lookahead.next()
> return izip(chain(imap(itemgetter(0), izip(repeat(False),
> lookahead)), repeat(True)), t)

def lastdetector(iterable):
t, u = tee(iterable)
return izip(chain(imap(lambda x: False, islice(u, 1, None)),
[True]), t)

--
Paul Hankin

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


Re: NUCULAR fielded text searchable indexing

2007-10-17 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Oct 8, 7:00 pm, "Delaney, Timothy (Tim)" <[EMAIL PROTECTED]>
> wrote:
>> [EMAIL PROTECTED] wrote:
>>> ANNOUNCE:
>>>   NUCULAR fielded text searchable indexing
>> Does "NUCULAR" stand for anything? The (apparent) misspelling of
>> "nuclear" has already turned me off wanting to find out more about it.
>>
>> Tim Delaney
> 
> No, it doesn't stand for anything.  I guess it's not for you :(.
> Sorry about that.
> 
> (see the graphic at the bottom of http://nucular.sourceforge.net)
> 
It's a shame the name obscures rather than enlightens. Your stuff is 
usually pretty good - I still remember Gadfly fondly.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Inheriting automatic attributes initializer considered harmful?

2007-10-17 Thread Thomas Wittek
Hi!

I'm relatively new to Python, so maybe there is an obvious answer to my
question, that I just didn't find, yet.

I've got quite some classes (from a data model mapped with SQL-Alchemy)
that can be instatiated using kwargs for the attribute values. Example:

  class User(object):
  def __init__(self, name=None):
  self.name = name

  u = User(name="user name")

Writing such constructors for all classes is very tedious.
So I subclass them from this base class to avoid writing these constructors:

  class AutoInitAttributes(object):
  def __init__(self, **kwargs):
  for k, v in kwargs.items():
  getattr(self, k) # assure that the attribute exits
  setattr(self, k, v)

Is there already a standard lib class doing (something like) this?
Or is it even harmful to do this?
Although I cannot see any problems with it, I feel very unsafe about
that, because I've not seen this (in the few lines from some tutorials)
before.

Regards
-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread Duncan Booth
Hrvoje Niksic <[EMAIL PROTECTED]> wrote:

> [EMAIL PROTECTED] writes:
> 
>> Right, the paragraph is actually pretty clear after a second
>> reading.  I find it surprising nonetheless, as it's easy to forget
>> to return a result when you're implementing a method that does an
>> in-place operation, like __iadd__:
> 
> I've recently been bitten by that, and I don't understand the
> reasoning behind __iadd__'s design.  I mean, what is the point of an
> *in-place* add operation (and others) if it doesn't always work
> in-place?
> 
A very common use case is using it to increment a number:

   x += 1

If += always had to work inplace then this would throw an exception: an 
inplace addition would be meaningless for Python numbers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes:

> Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>
>> I've recently been bitten by [rebinding the var to what __iadd__
>> returns], and I don't understand the reasoning behind __iadd__'s
>> design.  I mean, what is the point of an *in-place* add operation
>> (and others) if it doesn't always work in-place?
>> 
> A very common use case is using it to increment a number:

I'm aware of that; but remember that there's still __add__.  It would
be sufficient for numbers not to implement __iadd__.  And, in fact,
they already don't:

>>> 1 .__add__(1)
2
>>> 1 .__iadd__(1)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'int' object has no attribute '__iadd__'

The current implementation of += uses __add__ for addition and
__iadd__ for addition that may or may not be in-place.  I'd like to
know the rationale for that design.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: negative base raised to fractional exponent

2007-10-17 Thread schaefer . mp
On Oct 17, 4:05 am, Ken Schutte <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Does anyone know of an approximation to raising a negative base to a
> > fractional exponent? For example, (-3)^-4.1 since this cannot be
> > computed without using imaginary numbers. Any help is appreciated.
>
> As others have said, you can use Python's complex numbers (just write -3
> as -3+0j).  If for some reason you don't want to, you can do it all with
> reals using Euler's formula,
>
> (-3)^-4.1  =  (-1)^-4.1  *  3^-4.1
> =
> e^(j*pi*-4.1)  *  3^-4.1
> =
> (cos(pi*-4.1) + j*sin(pi*-4.1)) * 3^-4.1
>
> in Python:
>
>  >>> import math
>  >>> real_part = (3**-4.1) * math.cos(-4.1 * math.pi)
>  >>> imaj_part = (3**-4.1) * math.sin(-4.1 * math.pi)
>  >>> (real_part,imaj_part)
> (0.01026806021211755, -0.0037372276904401318)
>
> Ken

Thank you for this. Now I need to somehow express this as a real
number. For example, I can transform the real and imaginary parts into
a polar coordinate giving me the value I want:

z = sqrt( real_part**2 + imaj_part**2 )

but this is an absolute terms. How does one determine the correct sign
for this value?


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


Re: Newbi Q: Recursively reverse lists but NOT strings?

2007-10-17 Thread Bruno Desthuilliers
Paddy a écrit :
>> >   story stargaming, I caught it first this time !-)
>  Shouldn't that be s-o-r-r-y  :-)


Oui :(


>> <*ot>
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread Marc 'BlackJack' Rintsch
On Wed, 17 Oct 2007 13:41:06 +0200, Hrvoje Niksic wrote:

> Duncan Booth <[EMAIL PROTECTED]> writes:
> 
>> Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>>
>>> I've recently been bitten by [rebinding the var to what __iadd__
>>> returns], and I don't understand the reasoning behind __iadd__'s
>>> design.  I mean, what is the point of an *in-place* add operation
>>> (and others) if it doesn't always work in-place?
>>> 
>> A very common use case is using it to increment a number:
> 
> I'm aware of that; but remember that there's still __add__.  It would
> be sufficient for numbers not to implement __iadd__.  And, in fact,
> they already don't:
> 
 1 .__add__(1)
> 2
 1 .__iadd__(1)
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'int' object has no attribute '__iadd__'
> 
> The current implementation of += uses __add__ for addition and
> __iadd__ for addition that may or may not be in-place.  I'd like to
> know the rationale for that design.

Simply not to introduce special cases I guess.  If you write ``x.a += b``
then `x.a` will be rebound whether an `a.__iadd__()` exists or not. 
Otherwise one would get interesting subtle differences with properties for
example.  If `x.a` is a property that checks if the value satisfies some
constraints ``x.a += b`` would trigger the set method only if there is no
`__iadd__()` involved if there's no rebinding.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Displaying future times

2007-10-17 Thread ryan k
I have a schedule of times in the future that I want to display in a
timezone the user sets. There is a useful module
http://www.purecode.com/~tsatter/python/README.txt (at that URL) with
a function that takes seconds from the epoch and a time zone and
returns what is basically a datetime object.

My question is how to I display the seconds from the epoch for a
datetime object (which will be a datetime in the future) for the UTC
timezone?

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


Displaying future times

2007-10-17 Thread ryan k
I have a schedule of times in the future that I want to display in a
timezone the user sets. There is a useful module
http://www.purecode.com/~tsatter/python/README.txt (at that URL) with
a function that takes seconds from the epoch and a time zone and
returns what is basically a datetime object.

My question is how to I display the seconds from the epoch for a
datetime object (which will be a datetime in the future) for the UTC
timezone?

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


Re: Static variable vs Class variable

2007-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2007 13:41:06 +0200, Hrvoje Niksic wrote:

> The current implementation of += uses __add__ for addition and __iadd__
> for addition that may or may not be in-place.  I'd like to know the
> rationale for that design.

Everything you need is in the PEP:

http://www.python.org/dev/peps/pep-0203/



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


Re: Static variable vs Class variable

2007-10-17 Thread Duncan Booth
Hrvoje Niksic <[EMAIL PROTECTED]> wrote:

> 
> The current implementation of += uses __add__ for addition and
> __iadd__ for addition that may or may not be in-place.  I'd like to
> know the rationale for that design.
> 

Apart from the obvious short answer of being consistent (so you don't 
have to guess whether or not a+=b is going to do an assignment), I think 
the decision was partly to keep the implementation clean.

Right now an inplace operation follows one of three patterns:

load a value LOAD_FAST or LOAD_GLOBAL
do the inplace operation (INPLACE_ADD etc)
store the result (STORE_FAST or STORE_GLOBAL)

or:

compute an expression
DUP_TOP
LOAD_ATTR
do the inplace operation
ROT_TWO
STORE_ATTR

or:

compute two expressions
DUP_TOPX 2
BINARY_SUBSCR
do the inplace operation
ROT_THREE
STORE_SUBSCR

I'm not sure I've got all the patterns here, but we have at least three 
different cases with 0, 1, or 2 objects on the stack and at least 4 
different store opcodes.

If the inplace operation wasn't always going to store the result, then 
either we would need 4 times as many INPLACE_XXX opcodes, or it would 
have to do something messy to pop the right number of items off the 
stack and skip the following 1 or 2 instructions.

I see from PEP203 that ROT_FOUR was added as part of the implementation, 
so I guess I must have missed at least one other bytecode pattern for 
augmented assignment (which turns out to be slice assignment with a 
stride).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically organize module imports

2007-10-17 Thread Andrew Durdin
On 10/15/07, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
>
> Pyflakes will tell you which imports aren't being used (among other
> things).  I don't know if an existing tool which will automatically
> rewrite your source, though.

I'll second that recommendation of Pyflakes -- as the interpreter only
lets you know about undefined names when the code is executed, I find
Pyflakes really useful at finding missing imports (or other undefined
names) as soon as possible.

As I'm doing a lot of work with Django at the moment, which requires
some configuration of the environment to run, the fact that Pyflakes
reads the source without trying to execute any of it helps a great
deal.

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


Re: Static variable vs Class variable

2007-10-17 Thread Duncan Booth
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

> Simply not to introduce special cases I guess.  If you write ``x.a +=
> b`` then `x.a` will be rebound whether an `a.__iadd__()` exists or
> not. Otherwise one would get interesting subtle differences with
> properties for example.  If `x.a` is a property that checks if the
> value satisfies some constraints ``x.a += b`` would trigger the set
> method only if there is no `__iadd__()` involved if there's no
> rebinding. 

Unfortunately that doesn't work very well. If the validation rejects the 
new value the original is still modified:

>>> class C(object):
def setx(self, value):
if len(value)>2:
raise ValueError
self._x = value
def getx(self):
return self._x
x = property(getx, setx)


>>> o = C()
>>> o.x = []
>>> o.x += ['a']
>>> o.x += ['b']
>>> o.x += ['c']

Traceback (most recent call last):
  File "", line 1, in 
o.x += ['c']
  File "", line 4, in setx
raise ValueError
ValueError
>>> o.x
['a', 'b', 'c']
>>> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Best Python Linux distribution

2007-10-17 Thread Anthony Perkins
Hi everyone,

What is the best GNU/Linux distribution (or the most preferred) for 
developing Python applications?  Ideally I would like one with both 
Python *and* IDLE included on the install media (neither Ubuntu nor SUSE 
have IDLE on the CDs), so that I can use it on machines without a 
network connection.

Thanks,

-Anthony

-- 
Anthony Perkins
muzz.be
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic and lazy import

2007-10-17 Thread Alexandre Badez
Thanks for all your advices, but it's not really what I would like to
do.

I'm going to be more clearer for what I really want to do.

Here we have got many library for different applications. All those
library have a version and between a version and an other, there isn't
always a very good backward compatibility (I know, it's very ugly, but
it's like that...).

Moreover some library use the version 1.1 and some the version 1.2 of
lib A and version 2.1 and version 2.0 of lib B ... you know what: it's
very ugly.

My idea was to be able to use lib quiet like that.

import A (<- If I want to use the very last version)
# or
import A.1_1 (<- If I want to use the version 1.1 of the A lib)

Something else ?
Yes :)
I do not want to add all those path in PYTHONPATH (would be too ugly,
and "complicated").
I want it lazy (do not import every version of every lib every time)
I want it scalable: if a user or the admin add a new lib or a version
of lib it would be very very great if he had nothing else (than copy
his directory) to do.

So what I wanted to do, was to be able to control what the user really
wanted to import, and act he excepted and put the "intelligence" in a
__init__ script

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


Re: Displaying future times

2007-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2007 12:20:06 +, ryan k wrote:

> I have a schedule of times in the future that I want to display in a
> timezone the user sets. There is a useful module
> http://www.purecode.com/~tsatter/python/README.txt (at that URL) with a
> function that takes seconds from the epoch and a time zone and returns
> what is basically a datetime object.
> 
> My question is how to I display the seconds from the epoch for a
> datetime object (which will be a datetime in the future) for the UTC
> timezone?

Is this a trick question? Won't the answer be "The same way you would for 
a datetime in the past"?


To get the number of seconds from the epoch, see the function timegm() in 
the calendar module.



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


Re: Static variable vs Class variable

2007-10-17 Thread Paul Melis
On Oct 17, 2:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> > Simply not to introduce special cases I guess.  If you write ``x.a +=
> > b`` then `x.a` will be rebound whether an `a.__iadd__()` exists or
> > not. Otherwise one would get interesting subtle differences with
> > properties for example.  If `x.a` is a property that checks if the
> > value satisfies some constraints ``x.a += b`` would trigger the set
> > method only if there is no `__iadd__()` involved if there's no
> > rebinding.
>
> Unfortunately that doesn't work very well. If the validation rejects the
> new value the original is still modified:
>
> >>> class C(object):
>
> def setx(self, value):
> if len(value)>2:
> raise ValueError
> self._x = value
> def getx(self):
> return self._x
> x = property(getx, setx)
>
> >>> o = C()
> >>> o.x = []
> >>> o.x += ['a']
> >>> o.x += ['b']
> >>> o.x += ['c']
>
> Traceback (most recent call last):
>   File "", line 1, in 
> o.x += ['c']
>   File "", line 4, in setx
> raise ValueError
> ValueError
>
> >>> o.x
> ['a', 'b', 'c']

Now that's really interesting. I added a print "before" and print
"after" statement just before and after the self._x = value and these
*do not get called* after the exception is raised when the third
element is added.

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


Re: Inheriting automatic attributes initializer considered harmful?

2007-10-17 Thread Andrew Durdin
On 10/17/07, Thomas Wittek <[EMAIL PROTECTED]> wrote:
>
> Writing such constructors for all classes is very tedious.
> So I subclass them from this base class to avoid writing these constructors:
>
>   class AutoInitAttributes(object):
>   def __init__(self, **kwargs):
>   for k, v in kwargs.items():
>   getattr(self, k) # assure that the attribute exits
>   setattr(self, k, v)
>
> Is there already a standard lib class doing (something like) this?
> Or is it even harmful to do this?

It depends on your kwargs and where they're coming from.  You could do
something like this, for example:

def fake_str(self):
return "not a User"

u = User(__str__=fake_str)
str(u)


Does SQLAlchemy let you get a list of column names? If so you could do:

class AutoInitAttributes(object):
def __init__(self, **kwargs):
valid_attrs = set(get_column_names_from_sqlalchemy())
# Only set valid attributes, ignoring any other kwargs
for k in set(kwargs.keys()) & valid_attrs:
   setattr(self, k, kwargs[k])

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


Re: Python's coming... from unexpected angles.

2007-10-17 Thread Ben Finney
"Eric Brunel" <[EMAIL PROTECTED]> writes:

> On Tue, 16 Oct 2007 13:19:26 +0200, Ben Finney
> <[EMAIL PROTECTED]> wrote:
> > Does that mean you pronounce the word for the serpent as
> > "pee-thon"?
> 
> Yes.
> 
> > Anyway, the pronunciation of "Python" (and hence the "Py" in
> > "PyPy") is however you pronounce that word in the name of the
> > comedy troupe, Monty Python.
> 
> But the average frenchman will also pronounce "monty pee-thon" (I
> know: that's weird...).

No more weird than pronunciations of words in English. At least in
this case you're presenting a consistent pronunciation :-)

-- 
 \ "Having sex with Rachel is like going to a concert. She yells a |
  `\  lot, and throws frisbees around the room; and when she wants |
_o__) more, she lights a match."  -- Steven Wright |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread schaefer . mp
To compute the absolute value of a negative base raised to a
fractional exponent such as:

z = (-3)^4.5

you can compute the real and imaginary parts and then convert to the
polar form to get the correct value:

real_part = ( 3^-4.5 ) * cos( -4.5 * pi )
imag_part = ( 3^-4.5 ) * sin( -4.5 * pi )

|z| = sqrt( real_part^2 + imag_part^2 )

Is there any way to determine the correct sign of z, or perform this
calculation in another way that allows you to get the correct value of
z expressed without imaginary parts?

For example, I can compute:

z1 = (-3)^-4 = 0,012345679
and
z3 = (-3)^-5 = -0,004115226

and I can get what the correct absolute value of z2 should be by
computing the real and imaginary parts:

|z2| = (-3)^-4.5 = sqrt( 3,92967E-18^2 + -0,007127781^2 ) =
0,007127781

but I need to know the sign.

Any help is appreciated.



but I can know the correct sign for this value.

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


Re: Displaying future times

2007-10-17 Thread ryan k
On Oct 17, 1:52 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Wed, 17 Oct 2007 12:20:06 +, ryan k wrote:
> > I have a schedule of times in the future that I want to display in a
> > timezone the user sets. There is a useful module
> >http://www.purecode.com/~tsatter/python/README.txt(at that URL) with a
> > function that takes seconds from the epoch and a time zone and returns
> > what is basically a datetime object.
>
> > My question is how to I display the seconds from the epoch for a
> > datetime object (which will be a datetime in the future) for the UTC
> > timezone?
>
> Is this a trick question? Won't the answer be "The same way you would for
> a datetime in the past"?
>
> To get the number of seconds from the epoch, see the function timegm() in
> the calendar module.
>
> --
> Steven.

Not a trick question at all... Cheers.

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


Re: Inheriting automatic attributes initializer considered harmful?

2007-10-17 Thread Thomas Wittek
Andrew Durdin:
>> Is there already a standard lib class doing (something like) this?
>> Or is it even harmful to do this?
> 
> It depends on your kwargs and where they're coming from.

They should come from my own code.

> Does SQLAlchemy let you get a list of column names?

Generellay, it does.
But it also generates some additional attributes dynamically that are
not directly defined as columns.
So, restricting the attributes to the columns would be too strict.

Thanks!
-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python Linux distribution

2007-10-17 Thread Rafał Zawadzki
Anthony Perkins wrote:

> Hi everyone,
> 
> What is the best GNU/Linux distribution (or the most preferred) for
> developing Python applications?  Ideally I would like one with both
> Python *and* IDLE included on the install media (neither Ubuntu nor SUSE
> have IDLE on the CDs), so that I can use it on machines without a
> network connection.
> 
> Thanks,
> 
> -Anthony
> 

You can prepare your own version of ubuntu with included software like
Eclipse + pydev

-- 
bluszcz
http://glam.pl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread Paul Melis
On Oct 17, 3:20 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Wed, 17 Oct 2007 05:57:50 -0700, Paul Melis wrote:
> > On Oct 17, 2:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> >> >>> class C(object):
>
> >> def setx(self, value):
> >> if len(value)>2:
> >> raise ValueError
> >> self._x = value
> >> def getx(self):
> >> return self._x
> >> x = property(getx, setx)
>
> >> >>> o = C()
> >> >>> o.x = []
> >> >>> o.x += ['a']
> >> >>> o.x += ['b']
> >> >>> o.x += ['c']
>
> >> Traceback (most recent call last):
> >>   File "", line 1, in 
> >> o.x += ['c']
> >>   File "", line 4, in setx
> >> raise ValueError
> >> ValueError
>
> >> >>> o.x
> >> ['a', 'b', 'c']
>
> > Now that's really interesting. I added a print "before" and print
> > "after" statement just before and after the self._x = value and these
> > *do not get called* after the exception is raised when the third
> > element is added.
>
> Well, of course not.  Did you really expect that!?  Why?

Because o.x *is* updated, i.e. the net result of self._x = value is
executed.

Paul

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


Re: Static variable vs Class variable

2007-10-17 Thread Paul Melis
On Oct 17, 3:41 pm, Paul Melis <[EMAIL PROTECTED]> wrote:
> On Oct 17, 3:20 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Wed, 17 Oct 2007 05:57:50 -0700, Paul Melis wrote:
> > > On Oct 17, 2:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> > >> >>> class C(object):
>
> > >> def setx(self, value):
> > >> if len(value)>2:
> > >> raise ValueError
> > >> self._x = value
> > >> def getx(self):
> > >> return self._x
> > >> x = property(getx, setx)
>
> > >> >>> o = C()
> > >> >>> o.x = []
> > >> >>> o.x += ['a']
> > >> >>> o.x += ['b']
> > >> >>> o.x += ['c']
>
> > >> Traceback (most recent call last):
> > >>   File "", line 1, in 
> > >> o.x += ['c']
> > >>   File "", line 4, in setx
> > >> raise ValueError
> > >> ValueError
>
> > >> >>> o.x
> > >> ['a', 'b', 'c']
>
> > > Now that's really interesting. I added a print "before" and print
> > > "after" statement just before and after the self._x = value and these
> > > *do not get called* after the exception is raised when the third
> > > element is added.
>
> > Well, of course not.  Did you really expect that!?  Why?
>
> Because o.x *is* updated, i.e. the net result of self._x = value is
> executed.

Argh, the getter is of course used to append the third element, after
which the rebinding triggers the exception. Got it now...

Paul

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


Order by value in dictionary

2007-10-17 Thread Abandoned
Hi..
I have a dictionary like these:
a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000
element
I want to sort this by value and i want to first 100 element..
Result must be:
[b, a, d, c .] ( first 100 element)

I done this using FOR and ITERATOR but it tooks 1 second and this is
very big time to my project.
I want to learn the fastest method..

I'm sorry my bad english.
Please help me.
King regards..

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


Write by logging.FileHandler to one file by many processess

2007-10-17 Thread Rafał Zawadzki
Hello.

As I saw in logging source - there is no lock per file during making emit()
(only lock per thread).

So, my question is - is it safe to log into one file using many processess
uses logging logger?

Cheers,
-- 
bluszcz
http://vegan-planet.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-17 Thread Marc 'BlackJack' Rintsch
On Wed, 17 Oct 2007 05:57:50 -0700, Paul Melis wrote:

> On Oct 17, 2:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
>> >>> class C(object):
>>
>> def setx(self, value):
>> if len(value)>2:
>> raise ValueError
>> self._x = value
>> def getx(self):
>> return self._x
>> x = property(getx, setx)
>>
>> >>> o = C()
>> >>> o.x = []
>> >>> o.x += ['a']
>> >>> o.x += ['b']
>> >>> o.x += ['c']
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> o.x += ['c']
>>   File "", line 4, in setx
>> raise ValueError
>> ValueError
>>
>> >>> o.x
>> ['a', 'b', 'c']
> 
> Now that's really interesting. I added a print "before" and print
> "after" statement just before and after the self._x = value and these
> *do not get called* after the exception is raised when the third
> element is added.

Well, of course not.  Did you really expect that!?  Why?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python Linux distribution

2007-10-17 Thread Joe Riopel
On 10/17/07, Anthony Perkins <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> What is the best GNU/Linux distribution (or the most preferred) for
> developing Python applications?  Ideally I would like one with both
> Python *and* IDLE included on the install media (neither Ubuntu nor SUSE
> have IDLE on the CDs), so that I can use it on machines without a
> network connection.


IDLE and Python came installed on Slackware 12, I am not 100% sure
about previous versions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic and lazy import

2007-10-17 Thread Diez B. Roggisch
Alexandre Badez wrote:

> Thanks for all your advices, but it's not really what I would like to
> do.
> 
> I'm going to be more clearer for what I really want to do.
> 
> Here we have got many library for different applications. All those
> library have a version and between a version and an other, there isn't
> always a very good backward compatibility (I know, it's very ugly, but
> it's like that...).
> 
> Moreover some library use the version 1.1 and some the version 1.2 of
> lib A and version 2.1 and version 2.0 of lib B ... you know what: it's
> very ugly.
> 
> My idea was to be able to use lib quiet like that.
> 
> import A (<- If I want to use the very last version)
> # or
> import A.1_1 (<- If I want to use the version 1.1 of the A lib)
> 
> Something else ?
> Yes :)
> I do not want to add all those path in PYTHONPATH (would be too ugly,
> and "complicated").
> I want it lazy (do not import every version of every lib every time)
> I want it scalable: if a user or the admin add a new lib or a version
> of lib it would be very very great if he had nothing else (than copy
> his directory) to do.
> 
> So what I wanted to do, was to be able to control what the user really
> wanted to import, and act he excepted and put the "intelligence" in a
> __init__ script

Use setuptools + pkg_resources to install sereval versions of your libraries
together and then you can require a certain version of your lib.

HOWEVER: this WON'T work for several versions of a library in ONE running
python process Because the import will then either fail silently (after
all, "import foo" is ignored if foo is already present) or pkg_resources is
so clever that it keeps tracks of requirements and if they are conflicting
will puke on you.

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


Re: Order by value in dictionary

2007-10-17 Thread Diez B. Roggisch
Abandoned wrote:

> Hi..
> I have a dictionary like these:
> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000
> element
> I want to sort this by value and i want to first 100 element..
> Result must be:
> [b, a, d, c .] ( first 100 element)
> 
> I done this using FOR and ITERATOR but it tooks 1 second and this is
> very big time to my project.
> I want to learn the fastest method..

That is the fastest method, unless you write your own ordered dict
implementation that sorts by value. But that will most probably lose the
time when holding up the invariant when inserting key/values into the
dictionary.

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


Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:

> Simply not to introduce special cases I guess.  If you write ``x.a
> += b`` then `x.a` will be rebound whether an `a.__iadd__()` exists
> or not.  Otherwise one would get interesting subtle differences with
> properties for example.  If `x.a` is a property that checks if the
> value satisfies some constraints ``x.a += b`` would trigger the set
> method only if there is no `__iadd__()` involved if there's no
> rebinding.

Note that such constraint is easily invalidated simply with:

foo = x.a
foo += b
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Just to clarify what I'm after:
> If you plot (-3)^n where n is a set of negative real numbers between 0

I still can't figure out for certain what you're asking, but you might
look at the article

http://en.wikipedia.org/wiki/De_Moivre%27s_formula
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Order by value in dictionary

2007-10-17 Thread cokofreedom
On Oct 17, 3:39 pm, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> I have a dictionary like these:
> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000
> element
> I want to sort this by value and i want to first 100 element..
> Result must be:
> [b, a, d, c .] ( first 100 element)
>
> I done this using FOR and ITERATOR but it tooks 1 second and this is
> very big time to my project.
> I want to learn the fastest method..
>
> I'm sorry my bad english.
> Please help me.
> King regards..

I take it you did something like this

 >>> items = d.items()
 >>> items = [(v, k) for (k, v) in items]
 >>> items.sort()
 >>> items.reverse()# so largest is first
 >>> items = [(k, v) for (v, k) in items]

?

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


Re: Write by logging.FileHandler to one file by many processess

2007-10-17 Thread Alexandre Badez
On Oct 17, 3:33 pm, Rafa  Zawadzki <[EMAIL PROTECTED]> wrote:
> Hello.
>
> As I saw in logging source - there is no lock per file during making emit()
> (only lock per thread).
>
> So, my question is - is it safe to log into one file using many processess
> uses logging logger?
>
> Cheers,
> --
> bluszczhttp://vegan-planet.net

Well, there a dummy response: there is no true thread in Python (I
mean CPython). So there is no problems in this case (cf global
interpreter lock or GIL).

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


Re: Best Python Linux distribution

2007-10-17 Thread Joe Riopel
On 10/17/07, Joe Riopel <[EMAIL PROTECTED]> wrote:
> IDLE and Python came installed on Slackware 12, I am not 100% sure
> about previous versions.


Also, I am sure a lot of it (with most distributions)  depends on the
packages you select during the  installation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread schaefer . mp
Just to clarify what I'm after:

If you plot (-3)^n where n is a set of negative real numbers between 0
and -20 for example, then you get a discontinuos line due to the
problem mentioned above with fractional exponents. However, you can
compute what the correct absolute value of the the missing points
should be (see z2 above for an example), but I would like to know how
to determine what the correct sign of z2 should be so that it fits the
graph.



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


Re: Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> Just to clarify what I'm after:
> 
> If you plot (-3)^n where n is a set of negative real numbers between 0
> and -20 for example, then you get a discontinuos line due to the
> problem mentioned above with fractional exponents. However, you can
> compute what the correct absolute value of the the missing points
> should be (see z2 above for an example), but I would like to know how
> to determine what the correct sign of z2 should be so that it fits the
> graph.

You need to ask this question on a math group.  It's not a Python question 
at all.
-- 
http://mail.python.org/mailman/listinfo/python-list


readline support on openSuSE

2007-10-17 Thread Milos Prudek
This question concerns compilation of Python from sources. Specifically Python 
2.3.6.

On Kubuntu 7.04, ./configure outputs these lines about readline:
checking for rl_pre_input_hook in -lreadline... yes
checking for rl_completion_matches in -lreadline... yes

On openSuSE 10.3, ./configure outputs these lines about readline:
checking for rl_pre_input_hook in -lreadline... no
checking for rl_completion_matches in -lreadline... no

And, of course, line editing in Python shell is possible on Kubuntu and 
impossible on openSuSE.

I do have libreadline5 and readline-devel RPM installed on openSuSE. What else 
might I need to have readline support?

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


Re: Order by value in dictionary

2007-10-17 Thread Diez B. Roggisch
Diez B. Roggisch wrote:

> Abandoned wrote:
> 
>> Hi..
>> I have a dictionary like these:
>> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000
>> element
>> I want to sort this by value and i want to first 100 element..
>> Result must be:
>> [b, a, d, c .] ( first 100 element)
>> 
>> I done this using FOR and ITERATOR but it tooks 1 second and this is
>> very big time to my project.
>> I want to learn the fastest method..
> 
> That is the fastest method, unless you write your own ordered dict
> implementation that sorts by value. But that will most probably lose the
> time when holding up the invariant when inserting key/values into the
> dictionary.

Actually, I somehow read the FOR and ITERATOR above as something like this:

entries = sorted(a.items(), key=lambda v: v[1])[:100]

The gist of my statement above is nontheless the same: if you want sorted
results, you need to sort... 

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


Re: Write by logging.FileHandler to one file by many processess

2007-10-17 Thread Diez B. Roggisch
Alexandre Badez wrote:

> On Oct 17, 3:33 pm, Rafa  Zawadzki <[EMAIL PROTECTED]> wrote:
>> Hello.
>>
>> As I saw in logging source - there is no lock per file during making
>> emit() (only lock per thread).
>>
>> So, my question is - is it safe to log into one file using many
>> processess uses logging logger?
>>
>> Cheers,
>> --
>> bluszczhttp://vegan-planet.net
> 
> Well, there a dummy response: there is no true thread in Python (I
> mean CPython). So there is no problems in this case (cf global
> interpreter lock or GIL).

You didn't read the statement of the OP - he explicitly doesn't ask about
threads, but multiple processes writing to one file.

I presume things get messed up... but I don't know for sure.

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


Re: Dynamic and lazy import

2007-10-17 Thread Alexandre Badez
On Oct 17, 3:56 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Alexandre Badez wrote:
> > Thanks for all your advices, but it's not really what I would like to
> > do.
>
> > I'm going to be more clearer for what I really want to do.
>
> > Here we have got many library for different applications. All those
> > library have a version and between a version and an other, there isn't
> > always a very good backward compatibility (I know, it's very ugly, but
> > it's like that...).
>
> > Moreover some library use the version 1.1 and some the version 1.2 of
> > lib A and version 2.1 and version 2.0 of lib B ... you know what: it's
> > very ugly.
>
> > My idea was to be able to use lib quiet like that.
>
> > import A (<- If I want to use the very last version)
> > # or
> > import A.1_1 (<- If I want to use the version 1.1 of the A lib)
>
> > Something else ?
> > Yes :)
> > I do not want to add all those path in PYTHONPATH (would be too ugly,
> > and "complicated").
> > I want it lazy (do not import every version of every lib every time)
> > I want it scalable: if a user or the admin add a new lib or a version
> > of lib it would be very very great if he had nothing else (than copy
> > his directory) to do.
>
> > So what I wanted to do, was to be able to control what the user really
> > wanted to import, and act he excepted and put the "intelligence" in a
> > __init__ script
>
> Use setuptools + pkg_resources to install sereval versions of your libraries
> together and then you can require a certain version of your lib.
>
> HOWEVER: this WON'T work for several versions of a library in ONE running
> python process Because the import will then either fail silently (after
> all, "import foo" is ignored if foo is already present) or pkg_resources is
> so clever that it keeps tracks of requirements and if they are conflicting
> will puke on you.
>
> Diez

Well, I would like to be able to use "setuptools", but the problem is
that I can't.
Cause the administrator do not want us to be able to add lib in python
dir.
So we have to create our own library directory...

Moreover, I haven't seen in distutils how it manage different version
of the same library; as far as I know, It just replace the old one by
the newest one... and that's not really what I want.

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


Re: negative base raised to fractional exponent

2007-10-17 Thread Ken Schutte
[EMAIL PROTECTED] wrote:
> On Oct 17, 4:05 am, Ken Schutte <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>>> Does anyone know of an approximation to raising a negative base to a
>>> fractional exponent? For example, (-3)^-4.1 since this cannot be
>>> computed without using imaginary numbers. Any help is appreciated.
>> As others have said, you can use Python's complex numbers (just write -3
>> as -3+0j).  If for some reason you don't want to, you can do it all with
>> reals using Euler's formula,
>>
>> (-3)^-4.1  =  (-1)^-4.1  *  3^-4.1
>> =
>> e^(j*pi*-4.1)  *  3^-4.1
>> =
>> (cos(pi*-4.1) + j*sin(pi*-4.1)) * 3^-4.1
>>
>> in Python:
>>
>>  >>> import math
>>  >>> real_part = (3**-4.1) * math.cos(-4.1 * math.pi)
>>  >>> imaj_part = (3**-4.1) * math.sin(-4.1 * math.pi)
>>  >>> (real_part,imaj_part)
>> (0.01026806021211755, -0.0037372276904401318)
>>
>> Ken
> 
> Thank you for this. Now I need to somehow express this as a real
> number. For example, I can transform the real and imaginary parts into
> a polar coordinate giving me the value I want:
> 
> z = sqrt( real_part**2 + imaj_part**2 )
> 
> but this is an absolute terms. How does one determine the correct sign
> for this value?
> 

This is a complex number with non-zero imaginary part - there is no way 
to "express it as a real number".  Depending what you are trying to do, 
you may want the magnitude, z, which is by definition always positive. 
Or, maybe you just want to take real_part (which can be positive or 
negative).  Taking just the real part is the "closest" real number, in 
some sense.


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


Re: Dynamic and lazy import

2007-10-17 Thread Diez B. Roggisch
>> Diez
> 
> Well, I would like to be able to use "setuptools", but the problem is
> that I can't.
> Cause the administrator do not want us to be able to add lib in python
> dir.
> So we have to create our own library directory...

That doesn't matter, setuptools is capable of installing anywhere - you just
have to setup _one_ PYTHONPATH (e.g. ~/.python24_packages) and then specify
that when installing the eggs.
 
> Moreover, I haven't seen in distutils how it manage different version
> of the same library; as far as I know, It just replace the old one by
> the newest one... and that's not really what I want.

Well, you might consider my statement in the last post as hint that you
didn't look properly. It CAN and will install sereval versions in parallel,
and allow for previous selection. GIYF.

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


Re: Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread J. Robertson
[EMAIL PROTECTED] wrote:
> Just to clarify what I'm after:
> 
> If you plot (-3)^n where n is a set of negative real numbers between 0
> and -20 for example, then you get a discontinuos line due to the
> problem mentioned above with fractional exponents. 
>
> .. 
> 

It looks like you crash-landed in imaginary space, you may want to think 
again about what you're up to :-)  Complex numbers are not positive or 
negative, as such.

If you want to obtain a continuous curve, then take the real part of the 
complex number you obtain, as in "((-3+0j)**(-x)).real", it will fit 
with what you obtain for integers.


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


Re: Order by value in dictionary

2007-10-17 Thread George Sakkis
On Oct 17, 10:06 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Diez B. Roggisch wrote:
> > Abandoned wrote:
>
> >> Hi..
> >> I have a dictionary like these:
> >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000
> >> element
> >> I want to sort this by value and i want to first 100 element..
> >> Result must be:
> >> [b, a, d, c .] ( first 100 element)
>
> >> I done this using FOR and ITERATOR but it tooks 1 second and this is
> >> very big time to my project.
> >> I want to learn the fastest method..
>
> > That is the fastest method, unless you write your own ordered dict
> > implementation that sorts by value. But that will most probably lose the
> > time when holding up the invariant when inserting key/values into the
> > dictionary.
>
> Actually, I somehow read the FOR and ITERATOR above as something like this:
>
> entries = sorted(a.items(), key=lambda v: v[1])[:100]
>
> The gist of my statement above is nontheless the same: if you want sorted
> results, you need to sort...
>
> Diez

If you want the top 100 out of 100K, heapq.nlargest is more than an
order of magnitude faster.

George

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


Re: Order by value in dictionary

2007-10-17 Thread Diez B. Roggisch
George Sakkis wrote:

> On Oct 17, 10:06 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> Diez B. Roggisch wrote:
>> > Abandoned wrote:
>>
>> >> Hi..
>> >> I have a dictionary like these:
>> >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000
>> >> element
>> >> I want to sort this by value and i want to first 100 element..
>> >> Result must be:
>> >> [b, a, d, c .] ( first 100 element)
>>
>> >> I done this using FOR and ITERATOR but it tooks 1 second and this is
>> >> very big time to my project.
>> >> I want to learn the fastest method..
>>
>> > That is the fastest method, unless you write your own ordered dict
>> > implementation that sorts by value. But that will most probably lose
>> > the time when holding up the invariant when inserting key/values into
>> > the dictionary.
>>
>> Actually, I somehow read the FOR and ITERATOR above as something like
>> this:
>>
>> entries = sorted(a.items(), key=lambda v: v[1])[:100]
>>
>> The gist of my statement above is nontheless the same: if you want sorted
>> results, you need to sort...
>>
>> Diez
> 
> If you want the top 100 out of 100K, heapq.nlargest is more than an
> order of magnitude faster.

Oh, cool. Didn't know about that. I'm a bit rusty on how heapsort works,
gotta check that out.

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


Re: Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread Gerard Flanagan
On Oct 17, 3:17 pm, [EMAIL PROTECTED] wrote:
> To compute the absolute value of a negative base raised to a
> fractional exponent such as:
>
> z = (-3)^4.5
>
> you can compute the real and imaginary parts and then convert to the
> polar form to get the correct value:
>
> real_part = ( 3^-4.5 ) * cos( -4.5 * pi )
> imag_part = ( 3^-4.5 ) * sin( -4.5 * pi )
>
> |z| = sqrt( real_part^2 + imag_part^2 )
>
> Is there any way to determine the correct sign of z, or perform this
> calculation in another way that allows you to get the correct value of
> z expressed without imaginary parts?
>


Your question is not clear. (There is a cmath module if that helps).

>>> z1 = complex(-3)**4.5
>>> z1
(7.7313381458154376e-014+140.29611541307906j)
>>> import cmath
>>> z2 = cmath.exp(4.5 * cmath.log(-3))
>>> z2
(7.7313381458154401e-014+140.29611541307909j)
>>>

Gerard

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


Re: Order by value in dictionary

2007-10-17 Thread cokofreedom
On Oct 17, 4:06 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Diez B. Roggisch wrote:
> > Abandoned wrote:
>
> >> Hi..
> >> I have a dictionary like these:
> >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000
> >> element
> >> I want to sort this by value and i want to first 100 element..
> >> Result must be:
> >> [b, a, d, c .] ( first 100 element)
>
> >> I done this using FOR and ITERATOR but it tooks 1 second and this is
> >> very big time to my project.
> >> I want to learn the fastest method..
>
> > That is the fastest method, unless you write your own ordered dict
> > implementation that sorts by value. But that will most probably lose the
> > time when holding up the invariant when inserting key/values into the
> > dictionary.
>
> Actually, I somehow read the FOR and ITERATOR above as something like this:
>
> entries = sorted(a.items(), key=lambda v: v[1])[:100]
>
> The gist of my statement above is nontheless the same: if you want sorted
> results, you need to sort...
>
> Diez

Agreed, and it seems using the inbuilt sorts is the most efficient
way...

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


Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes:

> Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>
>> The current implementation of += uses __add__ for addition and
>> __iadd__ for addition that may or may not be in-place.  I'd like to
>> know the rationale for that design.
>> 
>
> Apart from the obvious short answer of being consistent (so you don't 
> have to guess whether or not a+=b is going to do an assignment), I think 
> the decision was partly to keep the implementation clean.

The implementation, by necessity, supports a lot of historical cruft,
so keeping it clean was not a priority.  (This is not a criticism, I
like how they kept backward compatibility.)

> Right now an inplace operation follows one of three patterns:
[...]

Thanks for pointing it out; I didn't realize just how much work went
into the new assignment opcodes.  Given the complexity, it's a wonder
they're there at all!
-- 
http://mail.python.org/mailman/listinfo/python-list


Stopping a fucntion from printing its output on screen

2007-10-17 Thread sophie_newbie
Hi, in my program i need to call a couple of functions that do some
stuff but they always print their output on screen. But I don't want
them to print anything on the screen. Is there any way I can disable
it from doing this, like redirect the output to somewhere else? But
later on in the program i then need to print other stuff so i'd need
to re-enable printing too. Any ideas?

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


Re: Stopping a fucntion from printing its output on screen

2007-10-17 Thread Jeremy Sanders
sophie_newbie wrote:

> Hi, in my program i need to call a couple of functions that do some
> stuff but they always print their output on screen. But I don't want
> them to print anything on the screen. Is there any way I can disable
> it from doing this, like redirect the output to somewhere else? But
> later on in the program i then need to print other stuff so i'd need
> to re-enable printing too. Any ideas?

If they are python functions, this hack should work...

import sys

class NullWriter(object):
def write(self, arg):
pass

def testfunc():
print "this is a test"

nullwrite = NullWriter()
oldstdout = sys.stdout
sys.stdout = nullwrite  # disable output
testfunc()
sys.stdout = oldstdout  # enable output
testfunc()


-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Order by value in dictionary

2007-10-17 Thread Abandoned
Very very thanks everbody..

These are some method..
Now the fastest method is second..

 1 ===
def sortt(d):
items=d.items()
backitems=[ [v[1],v[0]] for v in items]
backitems.sort()
#boyut=len(backitems)
#backitems=backitems[boyut-500:]
a=[ backitems[i][1] for i in range(0,len(backitems))]
a.reverse()
return a

 2 =
import operator
def sortt(d):
backitems=d.items()
boyut=len(backitems)
backitems=backitems[boyut-500:]
backitems=sorted(backitems, key=operator.itemgetter(1))
a=[ backitems[i][0] for i in range(0,len(backitems))]
a.reverse()
return a

 3 =
def sortt(d):
backitems=d.items()
backitems.sort(lambda x,y:cmp(x[1],y[1]))
backitems=sorted(backitems, key=operator.itemgetter(1))
a=[ backitems[i][0] for i in range(0,len(backitems))]
a.reverse()
return a

== 4 ===
import heapq

def sortt(d):
backitems=d.items()
backitems=heapq.nlargest(1000, backitems, operator.itemgetter(1))
a=[ backitems[i][0] for i in range(0,len(backitems))]
a.reverse()
return a

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


Re: Inheriting automatic attributes initializer considered harmful?

2007-10-17 Thread Alex Martelli
Andrew Durdin <[EMAIL PROTECTED]> wrote:

> On 10/17/07, Thomas Wittek <[EMAIL PROTECTED]> wrote:
> >
> > Writing such constructors for all classes is very tedious.
> > So I subclass them from this base class to avoid writing these constructors:
> >
> >   class AutoInitAttributes(object):
> >   def __init__(self, **kwargs):
> >   for k, v in kwargs.items():
> >   getattr(self, k) # assure that the attribute exits
> >   setattr(self, k, v)
> >
> > Is there already a standard lib class doing (something like) this?
> > Or is it even harmful to do this?
> 
> It depends on your kwargs and where they're coming from.  You could do
> something like this, for example:
> 
> def fake_str(self):
> return "not a User"
> 
> u = User(__str__=fake_str)
> str(u)

...and, if you did, that would be totally harmless (in a new-style class
as shown by the OP):

>>> class AutoInitAttributes(object):
...   def __init__(self, **kwargs):
...   for k, v in kwargs.items():
...   getattr(self, k) # assure that the attribute exits
...   setattr(self, k, v)
... 
>>> class User(AutoInitAttributes): pass
... 
>>> def fake_str(self):
... return "not a User"
... 
>>> u = User(__str__=fake_str)
>>> str(u)
'<__main__.User object at 0x635f0>'
>>> 

fake_str is not called, because special-method lookup occurs on the
TYPE, *NOT* on the instance.

The OP's idea is handy for some "generic containers" (I published it as
the "Bunch" class back in 2001 in
, and I
doubt it was original even then); it's not particularly recommended for
classes that need to have some specific *NON*-special methods, because
then the "overwriting" issue MIGHT possibly be a (minor) annoyance.


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


HTML Parser for Jython

2007-10-17 Thread Falcolas
Does anybody know of a decent HTML parser for Jython? I have to do
some screen scraping, and would rather use a tested module instead of
rolling my own.

Thanks!

GP

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


Re: Order by value in dictionary

2007-10-17 Thread Marc 'BlackJack' Rintsch
On Wed, 17 Oct 2007 08:09:50 -0700, Abandoned wrote:

> Very very thanks everbody..
> 
> These are some method..
> Now the fastest method is second..

Maybe because the second seems to be the only one that's not processing
the whole dictionary but just 500 items less!?

You are building way too much intermediate lists in your functions.

>  1 ===
> def sortt(d):
> items=d.items()

Builds a list of all items.

> backitems=[ [v[1],v[0]] for v in items]

Builds another list from all items.

> backitems.sort()
> a=[ backitems[i][1] for i in range(0,len(backitems))]

And again a new list *plus* a list of len(backitems) integers that is
built just to iterate over it.  Instead of iterating directly over
`backitems` without the index.

> a.reverse()
> return a

This whole function can be written as (untested):

def sortt(d):
sorted_items = sorted((item[1], item[0]) for item in d.iteritems(),
  reverse=True)
return map(operator.itemgetter(1), sorted_items)

>  2 =
> import operator
> def sortt(d):
> backitems=d.items()
> boyut=len(backitems)
> backitems=backitems[boyut-500:]
> backitems=sorted(backitems, key=operator.itemgetter(1))
> a=[ backitems[i][0] for i in range(0,len(backitems))]
> a.reverse()
> return a

Without throwing away 500 items:

def sortt(d):
sorted_items = sorted(d.iteritems(),
  key=operator.itemgetter(1),
  reverse=True)
return map(operator.itemgetter(0), sorted_items)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML Parser for Jython

2007-10-17 Thread Stefan Behnel
Falcolas wrote:
> Does anybody know of a decent HTML parser for Jython? I have to do
> some screen scraping, and would rather use a tested module instead of
> rolling my own.

Not sure if it works, but have you tried BeautifulSoup? Or maybe an older
version of it?

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


linear programming in Python

2007-10-17 Thread jivelasquezt
Hi all,

I'm new to this group so I don't know if this question has been posted
before, but does anyone knows about linear/integer programming
routines in Python that are available on the web, more specifically of
the branch and bound method.

Thanks,

Jorge Velasquez
PhD Student, Department of Ecology and Evolution at Stony Brook

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


pymssql - insert NULL to int

2007-10-17 Thread rc
How to insert NULL values in to int field using params.

I'm trying to use pymssql.execute, passing the operation and list of
params.  One of the values in the params is a NULL value going to int
field.  The pymssql._quote() puts ' around the NULL which causes an
exception to be thrown, is there a way to use the params for this or
do I need to build the insert string myself?

pymssql.DatabaseError: internal error: SQL Server message 245,
severity 16, state 1, line 1:
Conversion failed when converting the varchar value 'NULL' to data
type int.
DB-Lib error message 10007, severity 5:
General SQL Server error: Check messages from the SQL Server.

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


Re: HTML Parser for Jython

2007-10-17 Thread Carsten Haese
On Wed, 2007-10-17 at 17:36 +0200, Stefan Behnel wrote:
> Falcolas wrote:
> > Does anybody know of a decent HTML parser for Jython? I have to do
> > some screen scraping, and would rather use a tested module instead of
> > rolling my own.
> 
> Not sure if it works, but have you tried BeautifulSoup? Or maybe an older
> version of it?

Recent releases of BeautifulSoup need Python 2.3+, so they won't work on
current Jython, but BeatifulSoup 1.x will work.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Order by value in dictionary

2007-10-17 Thread Peter Otten
Abandoned wrote:

> These are some method..
> Now the fastest method is second..

Your four functions return three different results for the same input.
First make sure it's correct, then make it faster (if necessary).

Here are two candidates:

def largest_sort(d, n):
return sorted(d, key=d.__getitem__, reverse=True)[:n]

def largest_heap(d, n):
return heapq.nlargest(n, d, d.__getitem__)

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


ANN: Pyrex 0.9.6.3

2007-10-17 Thread Greg Ewing
Pyrex 0.9.6.3 is now available:

   http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

Main features of this release:

   * The C API now uses just one name in the module namespace,
 instead of a name per C function.

   * The 'cdef' keyword and following extern/public/api qualifiers
 can be factored out of a group of declarations and made into
 a block header, e.g.

   cdef public:
 int spam
 float ftang
 void tomato()

   * A 3-argument form of the builtin getattr function has been
 added, called getattr3().


What is Pyrex?
--

Pyrex is a language for writing Python extension modules.
It lets you freely mix operations on Python and C data, with
all Python reference counting and error checking handled
automatically.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pymssql - insert NULL to int

2007-10-17 Thread Diez B. Roggisch
rc wrote:

> How to insert NULL values in to int field using params.
> 
> I'm trying to use pymssql.execute, passing the operation and list of
> params.  One of the values in the params is a NULL value going to int
> field.  The pymssql._quote() puts ' around the NULL which causes an
> exception to be thrown, is there a way to use the params for this or
> do I need to build the insert string myself?
> 
> pymssql.DatabaseError: internal error: SQL Server message 245,
> severity 16, state 1, line 1:
> Conversion failed when converting the varchar value 'NULL' to data
> type int.
> DB-Lib error message 10007, severity 5:
> General SQL Server error: Check messages from the SQL Server.

Can you show us the actual code you use? I doubt that such a basic thing
isn't working.

You are aware that you have to pass None, not "NULL"?

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


Re: linear programming in Python

2007-10-17 Thread Wayne Brehaut
Hi Jorge,

On Wed, 17 Oct 2007 08:44:28 -0700, [EMAIL PROTECTED] wrote:

>Hi all,
>
>I'm new to this group so I don't know if this question has been posted
>before, but does anyone knows about linear/integer programming
>routines in Python that are available on the web, more specifically of
>the branch and bound method.

Try using your favourite search engine with a search string like
"linear programming Python branch bound".  Using Alta Vista
(http://www.altavista.com/web/adv) I got:

AltaVista found 16,500 results  

and Google gave:

Results 1 - 10 of about 7,990 

Some on the first page of each look like good possibilities, and I'm
sure there are others in the group that have first-hand experience and
can offer comparisons and advice. You might also try searching the
archives of this group--I searched just what my server has still
available and got no hits on "linear programming", but didn't try just
"LP" or similar.

Good luck!
Wayne

>Thanks,
>
>Jorge Velasquez
>PhD Student, Department of Ecology and Evolution at Stony Brook

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


Re: Order by value in dictionary

2007-10-17 Thread Abandoned
I tried these:

def largest_sort(d, n):
return sorted(d, key=d.__getitem__, reverse=True)[:n]


def largest_heap(d, n):
return heapq.nlargest(n, d, d.__getitem__)

def sortt(d):
sorted_items = sorted((item[1], item[0]) for item in
d.iteritems(),
  reverse=True)
return map(operator.itemgetter(1), sorted_items)

.
and the fastest method is second ;)

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


Re: why doesn't have this list a "reply-to" ?

2007-10-17 Thread Terry Reedy

"Grant Edwards" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| On 2007-10-16, Robert Kern <[EMAIL PROTECTED]> wrote:
|
| > It's not universal. Many people consider it harmful. Google "reply-to 
considered
| > harmful" for a variety of opinions, for and against.
| >
| > I use GMane to read and post to this list because I like my lists to 
act like
| > USENET.
| >
| >   http://gmane.org
|
| Since "this list" is just mirroring a Usenet news group,
| wouldn't it be more straight-forward to just use a real Usenet
| news server?

At the time I started using Gmane, it was more dependable than the news 
server available to me.  It possible still is.  Now, I follow other Python 
mailing lists that are not Usenet groups but which are mirrored on Gmane, 
so it is easier to have all my subscribed lists in one block on the 
sidebar. 



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


Re: linear programming in Python

2007-10-17 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hi all,
|
| I'm new to this group so I don't know if this question has been posted
| before,

Searching this group for 'linear programming' at
http://groups.google.com/group/comp.lang.python/topics?lnk=srg
gives 30 hits.

| but does anyone knows about linear/integer programming
| routines in Python that are available on the web, more specifically of
| the branch and bound method.

Searching the web for 'python linear programming' gives a lot more.

tjr



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


Re: Best Python Linux distribution

2007-10-17 Thread Rafael Sachetto
You could try this
http://www.ibiblio.org/onebase/onebaselinux.com/About/features/developgo.php

On 10/17/07, Joe Riopel <[EMAIL PROTECTED]> wrote:
>
> On 10/17/07, Joe Riopel <[EMAIL PROTECTED]> wrote:
> > IDLE and Python came installed on Slackware 12, I am not 100% sure
> > about previous versions.
>
>
> Also, I am sure a lot of it (with most distributions)  depends on the
> packages you select during the  installation.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Rafael Sachetto Oliveira

Sir - Simple Image Resizer
http://rsachetto.googlepages.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: HTML Parser for Jython

2007-10-17 Thread Tim Chase
> Does anybody know of a decent HTML parser for Jython? I have to do
> some screen scraping, and would rather use a tested module instead of
> rolling my own.

GIYF[0][1]
There are the batteries-included HTMLParser[2] and htmllib[3] 
modules, and the ever-popular (and more developer-friendly) 
BeautifulSoup[4] library as the first three results.  For running 
BS in Jython, it's recommended[5] to use an older (1.x?) version 
which are available at the BS site[6]

-tkc

[0]http://en.wikipedia.org/wiki/GIYF#G
[1]http://www.google.com/search?q=python%20html%20parser
[2]http://docs.python.org/lib/module-HTMLParser.html
[3]http://docs.python.org/lib/module-htmllib.html
[4]http://www.crummy.com/software/BeautifulSoup/
[5]http://mail.python.org/pipermail/python-list/2007-May/439618.html
[6]http://www.crummy.com/software/BeautifulSoup/download/1.x/








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


Need recommendations on mock object packages

2007-10-17 Thread Matthew Wilson
What are the most popular, easiest to use, and most powerful mock
object packages out there?

Thanks in advance.

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


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Re: HTML Parser for Jython

2007-10-17 Thread Falcolas
On Oct 17, 9:50 am, Carsten Haese <[EMAIL PROTECTED]> wrote:
> Recent releases of BeautifulSoup need Python 2.3+, so they won't work on
> current Jython, but BeatifulSoup 1.x will work.

Thank you.

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


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Re: Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread Matimus
On Oct 17, 6:51 am, [EMAIL PROTECTED] wrote:
> Just to clarify what I'm after:
>
> If you plot (-3)^n where n is a set of negative real numbers between 0
> and -20 for example, then you get a discontinuos line due to the
> problem mentioned above with fractional exponents. However, you can
> compute what the correct absolute value of the the missing points
> should be (see z2 above for an example), but I would like to know how
> to determine what the correct sign of z2 should be so that it fits the
> graph.

I know this isn't specifically what you are asking, but since you
aren't asking a Python question and this is a Python group I figure
I'm justified in giving you a slightly unrelated Python answer.

If you want to raise a negative number to a fractional exponent in
Python you simply have to make sure that you use complex numbers to
begin with:

>>> (-3+0j)**4.5
(7.7313381458154376e-014+140.29611541307906j)

Then if you want the absolute value of that, you can simply use the
abs function:

>>> x = (-3+0j)**4.5
>>> abs(x)
140.29611541307906

The absolute value will always be positive. If you want the angle you
can use atan.

>>> x = (-3+0j)**4.5
>>> math.atan(x.imag/x.real)
1.5707963267948961

I would maybe do this:

>>> def ang(x):
...  return math.atan(x.imag/x.real)

So, now that you have the angle and the magnitude, you can do this:

>>> abs(x) * cmath.exp(1j * ang(x))
(7.0894366756400186e-014+140.29611541307906j)

Which matches our original answer. Well, there is a little rounding
error because we are using floats.

So, if you have a negative magnitude, that should be exactly the same
as adding pi (180 degrees) to the angle.

>>> (-abs(x)) * cmath.exp(1j * (ang(x)+cmath.pi))
(2.5771127152718125e-014+140.29611541307906j)

Which should match our original answer. It is a little different, but
notice the magnitude of the real and imaginary parts. The real part
looks different, but is so small compared to the imaginary part that
it can almost be ignored.

Matt

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


Re: Stopping a fucntion from printing its output on screen

2007-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2007 07:57:04 -0700, sophie_newbie wrote:

> Hi, in my program i need to call a couple of functions that do some
> stuff but they always print their output on screen. But I don't want
> them to print anything on the screen. Is there any way I can disable it
> from doing this, like redirect the output to somewhere else? But later
> on in the program i then need to print other stuff so i'd need to
> re-enable printing too. Any ideas?


If it is your program, then just change your program to not print to the 
screen! Instead of writing a function like this:


def parrot():
# This is bad practice!
do_lots_of_calculations()
print "This is a parrot"


write it like this:

def parrot():
# This is good practice
do_lots_of_calculations()
return "This is a parrot"


What's the difference? In the first version, the function parrot() 
decides that its result is always printed. In the second version, YOU 
decide:


result = parrot()
# now pass the result to something else
do_more_calculations(result)
# or print it
print result


Otherwise, you can do something like this:

import cStringIO
import sys
capture_output = cStringIO.StringIO()
sys.stdout = capture_output
# call the function that always prints
parrot()
# now restore stdout
sys.stdout = sys.__stdout__


but that's a little risky, and I recommend against it unless you have no 
other choice.


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


Re: readline support on openSuSE

2007-10-17 Thread gardsted
Milos Prudek wrote:
> This question concerns compilation of Python from sources. Specifically 
> Python 
> 2.3.6.
> 
> On Kubuntu 7.04, ./configure outputs these lines about readline:
> checking for rl_pre_input_hook in -lreadline... yes
> checking for rl_completion_matches in -lreadline... yes
> 
> On openSuSE 10.3, ./configure outputs these lines about readline:
> checking for rl_pre_input_hook in -lreadline... no
> checking for rl_completion_matches in -lreadline... no
> 
> And, of course, line editing in Python shell is possible on Kubuntu and 
> impossible on openSuSE.
> 
> I do have libreadline5 and readline-devel RPM installed on openSuSE. What 
> else 
> might I need to have readline support?
> 
This is not an answer but

I have 10.3 installed, and I found that a lot of my (not python-) compiling 
troubles went away after installing 'a lot' from the 
development patterns presented by yast.
I am so demented that I tend not to get the dependencies straight when 
installing from the 'personal memory';-)

kind retards
jorgen / de mente

something completely different:
myspace.com/dementedk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML, it is inserted as text hence the unterminated
string literal error. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Need help in updating a global variable by a thread

2007-10-17 Thread dedalusenator
Hello Folks,

My first posting here and I am a stuck in figuring out the exact way
to update a global variable from within a function that doesnt return
any value (because the function is a target of the thread and I dont
know how exactly return would work in such a case). I am sure I am
missing something very fundamental here. The essential pieces of my
code that cause the problem would be something like this:
-
lookuptab = {'1.9.7.3':'Bangkok','1.9.60.3':'Sydney'}

results = {}

for val in lookuptab.values():
results[val]=0

def testt(loc):
   global results
   results[loc] = 1
   return results[loc]

for x in lookuptab.values():
  thread = threading.Thread(target=testt,args=(x))
  thread.start()
print results
---

results contain 0 instead of 1. Any help clearing my block is greatly
appreciated.

-Stephen

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


Re: Problem of Readability of Python

2007-10-17 Thread kiilerix
On Oct 7, 10:24 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
> $ python -mtimeit -s'class A(object):pass' -s'a=A()' 'a.zop=23'

When I know that all instances of classes inheriting from object have
a namespace, then I would expect either that all objects have a
namespace or that it was inherited from object. I would expect
instantiating object to be the simplest and best way to get a
namespace.

But ...

>>> o = object()
>>> o.foo = 7
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'object' object has no attribute 'foo'
>>> o.__slot__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'object' object has no attribute '__slot__'
>>> class O(object): pass
>>> o = O()
>>> o.foo = 7

That object is kind of "pure virtual" seems to me to be a confusing
special case without any advantages.

Why can't object be instantiated directly? Is that explained and
documented anywhere?

/Mads

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


* Pedophile Al-Qaida Brown Muslim Kills 6 Devout Christian Policement for Enjoying a Party - Atom Bomb his country to stone age *

2007-10-17 Thread thermate
www.nkusa.org
911blogger.com
www.st911.org
www.stj911.org

http://www.cnn.com/2007/US/10/08/wisconsin.shooting/?iref=mpstoryview

updated 8:39 p.m. EDT, Mon October 8, 2007

Deputy fired 30 shots from rifle in killing 6, officials say

CRANDON, Wisconsin (CNN) -- An off-duty sheriff's deputy used a police-
style AR-15 rifle to kill six people at an early morning party in a
small Wisconsin town, officials said Monday.
art.peterson.wtmj.jpg

Tyler Peterson, a sheriff's deputy, shot and killed six people, police
said.

Twenty-year-old Tyler Peterson had gone to the party early Sunday to
make amends with his ex-girlfriend, a friend of Peterson's told The
Milwaukee Journal Sentinel.

Peterson lost control after people called him a "worthless pig," Mike
Kegley told the paper.

Peterson left and got a police-style AR-15 rifle from his truck,
forced his way back into the apartment and fired about 30 rounds at
about 2:45 a.m. (3:45 a.m. ET). Six people were killed; one person
survived and is hospitalized, Attorney General J.B. Van Hollen said at
a Monday news conference.

Peterson was killed in a shootout with law officers Sunday afternoon
after negotiations for his surrender failed, officials said. The
town's mayor said Tyler was killed by a SWAT team sniper.

The dead and wounded were all students or graduates of Crandon High
School, and Peterson was a graduate of the school, which has a little
more than 300 students.

Witnesses said the victims ranged in age from 14 to 20, and one was
apparently Peterson's former girlfriend.

Peterson's family, in a statement read by Bill Farr, a pastor,
expressed condolences to the victim's relatives and said they could
not find any reason for the killings.

"We are grieving for your losses. We are very sorry for what has
happened. This huge tragedy has deeply affected everyone, including
us. We also feel a tremendous amount of guilt and shame for the
horrible acts Tyler committed. This is not the Tyler we knew and
loved," the statement read.
Don't Miss

* Victims include high school freshman who loved animals

Jenny Stahl said her daughter, Lindsey, was the youngest victim. Video
Watch the victim's mom describe her grief »

"I don't want to believe it. I'm waiting for somebody to wake me up,"
she said. "She's only 14 -- she'll be 15 next month; she's just
starting to live. And the sad thing is who killed her -- a cop. Cops
are supposed to always protect you, I thought, and it's one who took
my daughter and how many other people's lives."

It was the high school's homecoming weekend.

Friends of the victims said Peterson also worked part time as a
Crandon police officer.

Residents near the scene of the shooting told the Associated Press it
was hard to accept that a police officer was the shooter.

"The first statement we said to each other was, 'How did he get
through the system?' " David Franz told the AP. "How do they know
somebody's background, especially that young? It is disturbing, to say
the least."

The town's schools were closed Monday, with grief counselors available
to students, said Superintendent Richard Peters.

"This was the kind of scenario where every small town in the USA says,
'This could never happen here,' " Peters said.

Crandon, a town of about 2,000 people, is 220 miles north of
Milwaukee, Wisconsin.

Crandon Mayor Gary Bradley said the town will work together to get
over the tragedy.

"There's a lot of people weeping and gnashing their teeth and the
emotions are very raw right now," Bradley said. "But we'll rebuild
brick by brick."

Forest County Sheriff Keith Van Cleve called the situation "very
difficult" for his deputies and the community.

Karly Johnson, 16, told the AP she knew the shooter.

"He was nice. He was an average guy -- normal. You wouldn't think he
could do that," Johnson said, adding that Peterson had helped her in a
class and had graduated with her brother, according to the AP.
advertisement

The state attorney general's office will investigate the case, Van
Cleve said.

Kevin St. John, a spokesman for the state Department of Justice, said
the agency's criminal investigation unit routinely investigates cases
of a "statewide or significant nature." E-mail to a friend E-mail to a
friend

CNN's Susan Roesgen and Katherine Wojtecki contributed to this report.

Copyright 2007 CNN. All rights reserved.This material may not be
published, broadcast, rewritten, or redistributed. Associated Press
contributed to this report.

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


* Pedophile Al-Qaida Brown Muslim Kills 6 Devout Christian Policement for Enjoying a Party - Atom Bomb his country to stone age *

2007-10-17 Thread thermate2
www.nkusa.org
911blogger.com
www.st911.org
www.stj911.org

http://www.cnn.com/2007/US/10/08/wisconsin.shooting/?iref=mpstoryview

updated 8:39 p.m. EDT, Mon October 8, 2007

Deputy fired 30 shots from rifle in killing 6, officials say

CRANDON, Wisconsin (CNN) -- An off-duty sheriff's deputy used a police-
style AR-15 rifle to kill six people at an early morning party in a
small Wisconsin town, officials said Monday.
art.peterson.wtmj.jpg

Tyler Peterson, a sheriff's deputy, shot and killed six people, police
said.

Twenty-year-old Tyler Peterson had gone to the party early Sunday to
make amends with his ex-girlfriend, a friend of Peterson's told The
Milwaukee Journal Sentinel.

Peterson lost control after people called him a "worthless pig," Mike
Kegley told the paper.

Peterson left and got a police-style AR-15 rifle from his truck,
forced his way back into the apartment and fired about 30 rounds at
about 2:45 a.m. (3:45 a.m. ET). Six people were killed; one person
survived and is hospitalized, Attorney General J.B. Van Hollen said at
a Monday news conference.

Peterson was killed in a shootout with law officers Sunday afternoon
after negotiations for his surrender failed, officials said. The
town's mayor said Tyler was killed by a SWAT team sniper.

The dead and wounded were all students or graduates of Crandon High
School, and Peterson was a graduate of the school, which has a little
more than 300 students.

Witnesses said the victims ranged in age from 14 to 20, and one was
apparently Peterson's former girlfriend.

Peterson's family, in a statement read by Bill Farr, a pastor,
expressed condolences to the victim's relatives and said they could
not find any reason for the killings.

"We are grieving for your losses. We are very sorry for what has
happened. This huge tragedy has deeply affected everyone, including
us. We also feel a tremendous amount of guilt and shame for the
horrible acts Tyler committed. This is not the Tyler we knew and
loved," the statement read.
Don't Miss

* Victims include high school freshman who loved animals

Jenny Stahl said her daughter, Lindsey, was the youngest victim. Video
Watch the victim's mom describe her grief »

"I don't want to believe it. I'm waiting for somebody to wake me up,"
she said. "She's only 14 -- she'll be 15 next month; she's just
starting to live. And the sad thing is who killed her -- a cop. Cops
are supposed to always protect you, I thought, and it's one who took
my daughter and how many other people's lives."

It was the high school's homecoming weekend.

Friends of the victims said Peterson also worked part time as a
Crandon police officer.

Residents near the scene of the shooting told the Associated Press it
was hard to accept that a police officer was the shooter.

"The first statement we said to each other was, 'How did he get
through the system?' " David Franz told the AP. "How do they know
somebody's background, especially that young? It is disturbing, to say
the least."

The town's schools were closed Monday, with grief counselors available
to students, said Superintendent Richard Peters.

"This was the kind of scenario where every small town in the USA says,
'This could never happen here,' " Peters said.

Crandon, a town of about 2,000 people, is 220 miles north of
Milwaukee, Wisconsin.

Crandon Mayor Gary Bradley said the town will work together to get
over the tragedy.

"There's a lot of people weeping and gnashing their teeth and the
emotions are very raw right now," Bradley said. "But we'll rebuild
brick by brick."

Forest County Sheriff Keith Van Cleve called the situation "very
difficult" for his deputies and the community.

Karly Johnson, 16, told the AP she knew the shooter.

"He was nice. He was an average guy -- normal. You wouldn't think he
could do that," Johnson said, adding that Peterson had helped her in a
class and had graduated with her brother, according to the AP.
advertisement

The state attorney general's office will investigate the case, Van
Cleve said.

Kevin St. John, a spokesman for the state Department of Justice, said
the agency's criminal investigation unit routinely investigates cases
of a "statewide or significant nature." E-mail to a friend E-mail to a
friend

CNN's Susan Roesgen and Katherine Wojtecki contributed to this report.

Copyright 2007 CNN. All rights reserved.This material may not be
published, broadcast, rewritten, or redistributed. Associated Press
contributed to this report.

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


Re: Desperately need help for html to LaTeX conversion

2007-10-17 Thread Legend
On Oct 15, 1:24 pm, "ynotssor" <[EMAIL PROTECTED]> wrote:
> Innews:[EMAIL PROTECTED],
>
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > The perl one does not run due to path problems.
>
> Nothing could be easier to fix than that.

I don't know if this could solve your problem atleast to a little
extent but try this once:

http://www.htmldoc.org/

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


* Pedophile Al-Qaida Brown Muslim Kills 6 Devout Christian Policement for Enjoying a Party - Atom Bomb his country to stone age *

2007-10-17 Thread lemnitzer
Need to typeset this article for discussion

www.nkusa.org
911blogger.com
www.st911.org
www.stj911.org

http://www.cnn.com/2007/US/10/08/wisconsin.shooting/?iref=mpstoryview

updated 8:39 p.m. EDT, Mon October 8, 2007

Deputy fired 30 shots from rifle in killing 6, officials say

CRANDON, Wisconsin (CNN) -- An off-duty sheriff's deputy used a police-
style AR-15 rifle to kill six people at an early morning party in a
small Wisconsin town, officials said Monday.
art.peterson.wtmj.jpg

Tyler Peterson, a sheriff's deputy, shot and killed six people, police
said.

Twenty-year-old Tyler Peterson had gone to the party early Sunday to
make amends with his ex-girlfriend, a friend of Peterson's told The
Milwaukee Journal Sentinel.

Peterson lost control after people called him a "worthless pig," Mike
Kegley told the paper.

Peterson left and got a police-style AR-15 rifle from his truck,
forced his way back into the apartment and fired about 30 rounds at
about 2:45 a.m. (3:45 a.m. ET). Six people were killed; one person
survived and is hospitalized, Attorney General J.B. Van Hollen said at
a Monday news conference.

Peterson was killed in a shootout with law officers Sunday afternoon
after negotiations for his surrender failed, officials said. The
town's mayor said Tyler was killed by a SWAT team sniper.

The dead and wounded were all students or graduates of Crandon High
School, and Peterson was a graduate of the school, which has a little
more than 300 students.

Witnesses said the victims ranged in age from 14 to 20, and one was
apparently Peterson's former girlfriend.

Peterson's family, in a statement read by Bill Farr, a pastor,
expressed condolences to the victim's relatives and said they could
not find any reason for the killings.

"We are grieving for your losses. We are very sorry for what has
happened. This huge tragedy has deeply affected everyone, including
us. We also feel a tremendous amount of guilt and shame for the
horrible acts Tyler committed. This is not the Tyler we knew and
loved," the statement read.
Don't Miss

* Victims include high school freshman who loved animals

Jenny Stahl said her daughter, Lindsey, was the youngest victim. Video
Watch the victim's mom describe her grief »

"I don't want to believe it. I'm waiting for somebody to wake me up,"
she said. "She's only 14 -- she'll be 15 next month; she's just
starting to live. And the sad thing is who killed her -- a cop. Cops
are supposed to always protect you, I thought, and it's one who took
my daughter and how many other people's lives."

It was the high school's homecoming weekend.

Friends of the victims said Peterson also worked part time as a
Crandon police officer.

Residents near the scene of the shooting told the Associated Press it
was hard to accept that a police officer was the shooter.

"The first statement we said to each other was, 'How did he get
through the system?' " David Franz told the AP. "How do they know
somebody's background, especially that young? It is disturbing, to say
the least."

The town's schools were closed Monday, with grief counselors available
to students, said Superintendent Richard Peters.

"This was the kind of scenario where every small town in the USA says,
'This could never happen here,' " Peters said.

Crandon, a town of about 2,000 people, is 220 miles north of
Milwaukee, Wisconsin.

Crandon Mayor Gary Bradley said the town will work together to get
over the tragedy.

"There's a lot of people weeping and gnashing their teeth and the
emotions are very raw right now," Bradley said. "But we'll rebuild
brick by brick."

Forest County Sheriff Keith Van Cleve called the situation "very
difficult" for his deputies and the community.

Karly Johnson, 16, told the AP she knew the shooter.

"He was nice. He was an average guy -- normal. You wouldn't think he
could do that," Johnson said, adding that Peterson had helped her in a
class and had graduated with her brother, according to the AP.
advertisement

The state attorney general's office will investigate the case, Van
Cleve said.

Kevin St. John, a spokesman for the state Department of Justice, said
the agency's criminal investigation unit routinely investigates cases
of a "statewide or significant nature." E-mail to a friend E-mail to a
friend

CNN's Susan Roesgen and Katherine Wojtecki contributed to this report.

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


Re: Problem of Readability of Python

2007-10-17 Thread Chris Mellon
On 10/17/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Oct 7, 10:24 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
> > $ python -mtimeit -s'class A(object):pass' -s'a=A()' 'a.zop=23'
>
> When I know that all instances of classes inheriting from object have
> a namespace, then I would expect either that all objects have a
> namespace or that it was inherited from object. I would expect
> instantiating object to be the simplest and best way to get a
> namespace.
>
> But ...
>
> >>> o = object()
> >>> o.foo = 7
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'object' object has no attribute 'foo'
> >>> o.__slot__
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'object' object has no attribute '__slot__'
> >>> class O(object): pass
> >>> o = O()
> >>> o.foo = 7
>
> That object is kind of "pure virtual" seems to me to be a confusing
> special case without any advantages.
>
> Why can't object be instantiated directly? Is that explained and
> documented anywhere?
>

What makes you think it can't be instantiated directly? You just did
it. It's not, however, suitable for use as an arbitrary thing to stick
attributes on.

Which is a little sad, but a necessary requirement for things like
int() and str() to be small and fast.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >