Re: about functions question

2007-10-26 Thread Bruno Desthuilliers
Neil Cerutti a écrit :
> On 2007-10-25, Bruno Desthuilliers
> <[EMAIL PROTECTED]> wrote:
>> The canonical case for small scripts is to have first all
>> functions and globals defined, then the main code protected by
>> a guard, ie:
> 
> There's no reason to "protect" your main code in a small script.

I actually have at least one: it allow me to execute all the top-level 
definitions in Emacs' Python sub-interpreter buffer for testing, without 
  actually executing the 'main' code.

>> if __name__ == '__main__':
>>print SOME_CONST
>>if not do_something():
>>  try_somethin_else()
> 
> That idiom is 

also

> useful in modules for launching tests or examples
> that should not be run when the module is imported.
> 
Indeed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel insert to postgresql with thread

2007-10-26 Thread Laurent Pointal
Le Thu, 25 Oct 2007 13:27:40 +0200, Diez B. Roggisch a écrit :

> DB modules aren't necessarily thread-safe. Most of the times, a
> connection (and of course their cursor) can't be shared between threads.
> 
> So open a connection for each thread.
> 
> Diez

DB modules following DBAPI2 must define the following attribute:

"""
  threadsafety

Integer constant stating the level of thread safety the
interface supports. Possible values are:

0 Threads may not share the module.
1 Threads may share the module, but not connections.
2 Threads may share the module and connections.
3 Threads may share the module, connections and
  cursors.
"""

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



-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: modifying __class__

2007-10-26 Thread Evan Klitzke
On 10/26/07, Piyush Jain <[EMAIL PROTECTED]> wrote:
> Hi,
> Itis possible to change the class of an object by assigning new value to
> __class__
> Is it possible to call my module when it is done.
> For example,
> object = ClassA()
>
> object.__class__ = classB # I want to call my method when this statement is
> executed.

Here's an example of how to do this:

class A(object):
def __init__(self):
self._class = A

def getclass(self):
return self._class

def setclass(self, x):
print 'setting __class__ to %s' % x
self._class = x

__class__ = property(getclass, setclass)

class B(object):
pass

if __name__ == '__main__':
a = A()
print 'Running a.__class__ = B'
a.__class__ = B

print 'a.__class__ = %s' % a.__class__

> I want to do it in a general way. For ex. , whenever __class__ is changed
> for any object instance (of different classes), my own function is called.
> How should I do it ?

I think you can do this using a metaclass, and then have all of your
classes inherit from the metaclass rather than object, but I don't
really have any experience doing this.

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


modifying __class__

2007-10-26 Thread Piyush Jain
Hi,
Itis possible to change the class of an object by assigning new value to
__class__
Is it possible to call my module when it is done.
For example,
object = ClassA()

object.__class__ = classB # I want to call my method when this statement is
executed.

I want to do it in a general way. For ex. , whenever __class__ is changed
for any object instance (of different classes), my own function is called.
How should I do it ?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python and Combinatorics

2007-10-26 Thread Gerard Flanagan
On Oct 25, 12:20 am, none <""atavory\"@(none)"> wrote:
> Hello,
>
> Is there some package to calculate combinatorical stuff like (n over
> k), i.e., n!/(k!(n - k!) ?
>
> I know it can be written in about 3 lines of code, but still...
>
> Thanks,
>
> Ami

http://probstat.sourceforge.net/

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


Need to help to parse the matlab log file.

2007-10-26 Thread wang frank

I have a big log file generated by matlab. Here is a copy of part of it. I want 
to write a function to parse some results. For example, if I want to get the 
results of BandWidth and freq_offset_in_KHz, the function will print all lines 
with contain them as : 
 
BandWidth = 10
freq_offset_in_KHz=50
 
I have submited a similar question to this forum and have not got any answer. 
May be my first one is too simple. So I decided to send part of the log file. I 
could not attach the whole file since it is big and restricted by company. This 
is not a student homework.
 
Thanks
 
Frank
 
Matlab log:
 
ans =
 
24-Oct-2007 09:53:11
 
 
BandWidth =
 
10
 
 
freq_offset_in_KHz =
 
50
 
 
maxPreambMissCount =
 
 1
 
 
maxlIterations =
 
   300
 
 
testCasesToBeRun =
 
11
 
Bandwidth 10.00 
Using config file: config_1024_V1_Acq_2
 
case_snr =
 
-1
 
 
case_backoff =
 
20
 
 
case_refPid =
 
 1
 
 
case_refRuns =
 
   300
 
 
case_refTOmin =
 
  -12.9196
 
 
case_refTOmax =
 
   20.8386
 
 
case_refTOmean =
 
3.8924
 
 
case_refTOstd =
 
3.6888
 
 
case_refFOEmin =
 
   -0.4730
 
 
case_refFOEmax =
 
0.3788
 
 
case_refFOEmean =
 
  6.3300e-004
 
 
case_refFOEstd =
 
0.148
 
 
_
マイクロソフトの最新次世代ブラウザIE7にMSN版ならではの便利な機能をプラス
http://promotion.msn.co.jp/ie7/-- 
http://mail.python.org/mailman/listinfo/python-list

renice

2007-10-26 Thread mokhtar

Hi

Is it possible to renice the python process executing the current python
script ?:confused:
-- 
View this message in context: 
http://www.nabble.com/renice-tf4695834.html#a13422771
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Read Matlab files with Python and Numeric?

2007-10-26 Thread Matthieu Brucher
Scipy proposes such a module.

Matthieu

2007/10/25, QAM <[EMAIL PROTECTED]>:
>
>  Hi Travis,
>
>
>
> Could you please send me the matlab reader you mentioned?
>
>
>
> Thanks,
>
>
>
> Frank
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
French PhD student
Website : http://miles.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Iteration for Factorials

2007-10-26 Thread Marco Mariani
[EMAIL PROTECTED] wrote:

> class fact_0(object):
>   value = 1
[...
>   def __new__(self, n_):
>   class spanish_inquisition(object):
>   __metaclass__ = fact_meta
>   n = n_
>   return spanish_inquisition()


You wrote lots of boilerplate to hide the fact you're cheating, didn't you?

The OP explicitly asked for an iterative procedure.

btw... writing a test unit to check the tested code is not calling 
itself.. could be interesting

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


tuples within tuples

2007-10-26 Thread korovev76
Hello everybody.

I'm wondering how to iterate over a tuple like this
[A,B,C,D]
while saving A and C in a list.

My problem is that C sometimes is a tuple of the same structure
itself...


thanks!
korovev

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


Proposal: Decimal literals in Python.

2007-10-26 Thread Lennart Benschop
Python has had the Decimal data type for some time now. The Decimal data
type is ideal for financial calculations. Using this data type would be
more intuitive to computer novices than float as its rounding behaviour
matches more closely what humans expect. More to the point: 0.1 and 0.01
are exact in Decimal and not exact in float. 

Unfortunately it is not very easy to access the Decimal data type. To obtain
the decimal number 12.34 one has to do something like this:

import decimal
x=decimal.Decimal("12.34")

Of course we can intruduce a single character function name as an alias for
the Decimal type constructor, but even then we have to use both parentheses
and quotes for each and every decimal constant. We cannot make it shorter
than D("12.34")

With Python 3000 major changes to the language are carried out anyway. My
proposal would require relatively minor changes.

My proposal:
- Any decimal constant suffixed with the letter "D" or "d" will be 
  interpreted as a literal of the Decimal type. This also goes for
  decimal constants with exponential notation.

Examples of decimal literals:
1d
12.34d
1e-3d (equivalent to 0.001d)
1e3d (same value as 1000d, but without trailing zeros).
1.25e5d (same value as 125000d but without trailing zeros).

When we print a decimal number or convert it to a string with str(), a
trailing d should not be added. The repr function does yield strings with a
trailing d.

When decimal numbers are converted from strings, both numbers with and
without a trailing d should be accepted. 

If we have decimal literals in the core language, we should probably have a
type constructor in the core namespace, e.g. dec() along with int() 
and float(). We then need the decimal module only for the more advanced
stuff like setcontext.

Pros:
- the Decimal data type will be more readily accessible, especially
  for novices.
- Traling characters at the end of a literal are already used (the L
  for long).
- It does not conflict with the syntax of other numeric constants or
  language constructs.
- It does not change the meaning of existing valid literal constants.
  Constants that used to be float will continue to do so.

Cons:
- The lexical scanner of the Python interpreter will be slightly more
  complex.
- The d suffix for constants with exponential notation is ugly.
- Decimal numbers with exponentail notation like 2e5d could be mistaken
  for hex (by humans, not by the parser as hex requires the 0x prefix).
- It requires the decimal module to be part of the core Python
  interpreter.

--
Lennart

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


object inheritance

2007-10-26 Thread Anand
I am trying to implement some kind of object inheritance. Just like
one class can extend from another, I want to do the same on objects
dynamically.

I just thought that I can share my excitement here.

Suppose there are classes A and B and their instances a and b.

class A:
def foo(self): self.say('foo')
def say(self, msg):
print 'a.say', msg

class B:
def say(self, msg):
print 'b.say', msg

a = A()
b = B()

I want b to inherit the behavior of a.

>>> b.extend_from(a)
>>> b.foo()
b.say foo

I looked around and found that some people talked about similar ideas,
but didn't find any concrete implementation.

I came up with the following implementation using meta-classes.

class ExtendMetaClass(type):
def __init__(cls, *a, **kw):
# take all attributes except special ones
keys = [k for k in cls.__dict__.keys() if not
k.startswith('__')]
d = [(k, getattr(cls, k)) for k in keys]

# remove those attibutes from class
for k in keys:
delattr(cls, k)

# remember then as dict _d
cls._d = dict(d)

def curry(f, arg1):
def g(*a, **kw):
return f(arg1, *a, **kw)
g.__name__ = f.__name__
return g

def _getattr(self, name):
"""Get value of attribute from self or super."""
if name in self.__dict__:
return self.__dict__[name]
elif name in self._d:
value = self._d[name]
if isinstance(value, types.MethodType):
return curry(value, self)
else:
return value
else:
if self._super != None:
return self._super._getattr(name)
else:
raise AttributeError, name

def __getattr__(self, name):
"""Returns value of the attribute from the sub object.
If there is no sub object, self._getattr is called.
"""
if name.startswith('super_'):
return self._super._getattr(name[len('super_'):])

if self._sub is not None:
return getattr(self._sub, name)
else:
return self._getattr(name)

def extend_from(self, super):
"""Makes self extend from super.
"""
self._super = super
super._sub = self

cls.__getattr__ = __getattr__
cls._getattr = _getattr
cls._super = None
cls._sub = None
cls.extend_from = extend_from

class Extend:
__metaclass__ = ExtendMetaClass
def __init__(self, super=None):
if super:
self.extend_from(super)

And the above example becomes:

class A(Extend):
def foo(self): self.say('foo')
def say(self, msg):
print 'a.say', msg

class B(Extend):
def say(self, msg):
print 'b.say', msg
# self.super_foo calls foo method on the super object
self.super_say('super ' + msg)

a = A()
b = B()

>>> b.extend_from(a)
>>> b.foo()
b.say foo
a.say super foo

There are one issue with this approach. Once b extends from a,
behavior of a also changes, which probably should not. But that
doesn't hurt me much.

Any comments?

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


Re: Iteration for Factorials

2007-10-26 Thread Nicko
On Oct 25, 2:36 am, Paul Rubin  wrote:
> Lou Pecora <[EMAIL PROTECTED]> writes:
> > There might even be an array method that can be adapted to get the
> > product.  Is there a product method? (analogous to a sum method)
>
> The "reduce" function which is being removed from python in 3.0.
>
> import operator
> def factorial(n):
>   return reduce(operator.mul, xrange(1,n+1))

Since reduce is being removed, and Guido is known not to like its use
anyway, I propose the following code for Py2.5 and later:

import math
def fact(n):
return math.exp(sum((math.log(i) for i in range(1,n+1 if n
>= 0 else None

If you don't like the rounding errors you could try:

def fact(n):
d = {"p":1L}
def f(i): d["p"] *= i
map(f, range(1,n+1))
return d["p"]

It is left as an exercise to the reader as to why this code will not
work on Py3K

Nicko


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


matplotlib & mod_python

2007-10-26 Thread kenneth
Hi all.

I would like to use a "combination" of matplotlib and mod_python to
create a
PNG figure on the fly in my web site.
The mod_python handler code should be something like this:


def handler(req):

fig = Figure()
...
... figure creation stuff
...
canvas = FigureCanvasAgg(fig)
canvas.print_figure(req, dpi=72)

   return apache.OK


This code gives me an error as req is not a file-like instance (as
sys.stdout):

TyperError: Could not convert object to file pointer

Is there a way to to this thing ?

Thank you very much for any suggestion,
Paolo

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


Mouse hover event in wxpython

2007-10-26 Thread sundarvenkata
Hi All,

Can somebody tell me if there is an event to indicate mouse hover over
a control in wxPython? EVT_MOTION does not seem to cut it.

 Thanks in advance,
Sundar

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


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread Ben Finney
Lennart Benschop <[EMAIL PROTECTED]> writes:

> Python has had the Decimal data type for some time now.

Since version 2.4 http://www.python.org/dev/peps/pep-0327>.

> Unfortunately it is not very easy to access the Decimal data
> type. To obtain the decimal number 12.34 one has to do something
> like this:
> 
> import decimal
> x=decimal.Decimal("12.34")

Slightly nicer, if you need to create a lot of them::

>>> from decimal import Decimal
>>> foo = Decimal("12.34")

> Of course we can intruduce a single character function name as an
> alias for the Decimal type constructor, but even then we have to use
> both parentheses and quotes for each and every decimal constant. We
> cannot make it shorter than D("12.34")

Nor should we. A function or type name should be short but explicit,
and 'Decimal' is about as short as I'd want.

> With Python 3000

"Python 3000" is now in beta development, and is called Python version
3.0.

> major changes to the language are carried out anyway.

All of which have been decided for some time now. It's rather too late
to introduce behaviour changes and hope for them to be in Python 3.0.

> My proposal:

Feel free to file an actual proposal using the PEP process. You might
want to refer to the PEP that introduced the Decimal type for
inspiration.

-- 
 \ "How many people here have telekenetic powers? Raise my hand."  |
  `\-- Emo Philips |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Eclipse Plugins

2007-10-26 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I'm not sure what you IDE you all generally use for your python development.
I've been somewhat lazy and always used a plain text editor, however this
technique is starting to take its toll, and it's purely been out of laziness
not finding myself a decent IDE to develop in. So this morning task is to
pull my thumb out of my arse and set something up properly.

 

For my other languages, such as HTML, ColdFusion, JAVA etc I make good use
of the Eclipse SDK, and I'm looking for some advice on the best and most
popular python plug-ins available, what would you suggest? I downloaded one
called PyDev which looked ok but nothing too exciting.

 

Thanks guys,

 

Rob

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

Re: Python Windows Installation

2007-10-26 Thread Bjoern Schliessmann
Wildemar Wildenburger wrote:
> Bjoern Schliessmann wrote:

>> Which I don't understand (works best for me, and is best practice
>> in Windows).
>  
> Best practice? Says who?

Ok, LOL. So, now you expect me to cite some official source? Despite
the fact that the vast majority of windows installers on this
planet use "%PROGRAMFILES%\Program Name" as default installation
path, particularly the ones for Microsoft's programs?

Regards,


Björn

-- 
BOFH excuse #227:

Fatal error right in front of screen

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


Re: object inheritance

2007-10-26 Thread Pradeep Jindal
Can you tell any specific use case for doing this?

Regards,
Pradeep

On 10/26/07, Anand <[EMAIL PROTECTED]> wrote:
> I am trying to implement some kind of object inheritance. Just like
> one class can extend from another, I want to do the same on objects
> dynamically.
>
> I just thought that I can share my excitement here.
>
> Suppose there are classes A and B and their instances a and b.
>
> class A:
> def foo(self): self.say('foo')
> def say(self, msg):
> print 'a.say', msg
>
> class B:
> def say(self, msg):
> print 'b.say', msg
>
> a = A()
> b = B()
>
> I want b to inherit the behavior of a.
>
> >>> b.extend_from(a)
> >>> b.foo()
> b.say foo
>
> I looked around and found that some people talked about similar ideas,
> but didn't find any concrete implementation.
>
> I came up with the following implementation using meta-classes.
>
> class ExtendMetaClass(type):
> def __init__(cls, *a, **kw):
> # take all attributes except special ones
> keys = [k for k in cls.__dict__.keys() if not
> k.startswith('__')]
> d = [(k, getattr(cls, k)) for k in keys]
>
> # remove those attibutes from class
> for k in keys:
> delattr(cls, k)
>
> # remember then as dict _d
> cls._d = dict(d)
>
> def curry(f, arg1):
> def g(*a, **kw):
> return f(arg1, *a, **kw)
> g.__name__ = f.__name__
> return g
>
> def _getattr(self, name):
> """Get value of attribute from self or super."""
> if name in self.__dict__:
> return self.__dict__[name]
> elif name in self._d:
> value = self._d[name]
> if isinstance(value, types.MethodType):
> return curry(value, self)
> else:
> return value
> else:
> if self._super != None:
> return self._super._getattr(name)
> else:
> raise AttributeError, name
>
> def __getattr__(self, name):
> """Returns value of the attribute from the sub object.
> If there is no sub object, self._getattr is called.
> """
> if name.startswith('super_'):
> return self._super._getattr(name[len('super_'):])
>
> if self._sub is not None:
> return getattr(self._sub, name)
> else:
> return self._getattr(name)
>
> def extend_from(self, super):
> """Makes self extend from super.
> """
> self._super = super
> super._sub = self
>
> cls.__getattr__ = __getattr__
> cls._getattr = _getattr
> cls._super = None
> cls._sub = None
> cls.extend_from = extend_from
>
> class Extend:
> __metaclass__ = ExtendMetaClass
> def __init__(self, super=None):
> if super:
> self.extend_from(super)
>
> And the above example becomes:
>
> class A(Extend):
> def foo(self): self.say('foo')
> def say(self, msg):
> print 'a.say', msg
>
> class B(Extend):
> def say(self, msg):
> print 'b.say', msg
> # self.super_foo calls foo method on the super object
> self.super_say('super ' + msg)
>
> a = A()
> b = B()
>
> >>> b.extend_from(a)
> >>> b.foo()
> b.say foo
> a.say super foo
>
> There are one issue with this approach. Once b extends from a,
> behavior of a also changes, which probably should not. But that
> doesn't hurt me much.
>
> Any comments?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about functions question

2007-10-26 Thread Neil Cerutti
On 2007-10-26, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Neil Cerutti a écrit :
>> On 2007-10-25, Bruno Desthuilliers
>> <[EMAIL PROTECTED]> wrote:
>>> The canonical case for small scripts is to have first all
>>> functions and globals defined, then the main code protected by
>>> a guard, ie:
>> 
>> There's no reason to "protect" your main code in a small
>> script.
>
> I actually have at least one: it allow me to execute all the
> top-level definitions in Emacs' Python sub-interpreter buffer
> for testing, without actually executing the 'main' code.
>
>>> if __name__ == '__main__':
>>>print SOME_CONST
>>>if not do_something():
>>>  try_somethin_else()
>> 
>> That idiom is 
>
>also
>
>> useful in modules for launching tests or examples
>> that should not be run when the module is imported.
>> 
> Indeed.

Thanks to you and Chris for giving me the tool-related
applications of that idiom. I haven't used the associated tools.

-- 
Neil Cerutti
Ushers will eat latecomers. --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread Steven D'Aprano
On Fri, 26 Oct 2007 19:19:46 +1000, Ben Finney wrote:

>> Of course we can intruduce a single character function name as an alias
>> for the Decimal type constructor, but even then we have to use both
>> parentheses and quotes for each and every decimal constant. We cannot
>> make it shorter than D("12.34")
> 
> Nor should we. A function or type name should be short but explicit, and
> 'Decimal' is about as short as I'd want.

You don't like str, int, float, list, set, dict, or bool?

Or for that matter, enum
http://www.python.org/dev/peps/pep-0354/

*wink*


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


Re: "Standard" Full Text Search Engine

2007-10-26 Thread Diez B. Roggisch
Martin Marcher wrote:

> Hello,
> 
> is there something like a standard full text search engine?
> 
> I'm thinking of the equivalent for python like lucene is for java or
> ferret for rails. Preferrably something that isn't exactly a clone of
> one of those but more that is python friendly in terms of the API it
> provides.
> 
> Things I'd like to have:
> 
>  * different languages are supported (it seems most FTSs do only english)
>  * I'd like to be able to provide an identifier (if I index files in
> the filesystem that would be the filename, or an ID if it lives in a
> database, or whatever applies)
>  * I'd like to pass it just some (user defined) keywords with content,
> the actual content (as string, or list of strings or whatever) and to
> retrieve the results by search by keyword
>  * something like a priority should be assignable to different fields
> (like field: title(priority=10, content="My Draft"),
> keywords(priority=50, list_of_keywords))
> 
> Unnecessary:
> 
>  * built-in parsing of different files
> 
> The "standard" I'm referring to would be something with a large and
> active user base. Like... WSGI is _the_ thing to refer to when doing
> webapps it should be something like $FTS-Engine is _the_ engine to
> refer to.
> 
> any hints?

There are several python lucene implementations available, and recently here
a project called NUCULAR turned up. And there is ZCatalog, the
full-text-indexing technology used in Zope, but which should be usable
outside of zope.

But "the" search-technology doesn't exist. I personally would most probably
go for the lucene-based stuff, because there you possibly get auxiliary
tools written in java.

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


Re: Mouse hover event in wxpython

2007-10-26 Thread Larry Bates
sundarvenkata wrote:
> Hi All,
> 
> Can somebody tell me if there is an event to indicate mouse hover over
> a control in wxPython? EVT_MOTION does not seem to cut it.
> 
>  Thanks in advance,
> Sundar
> 

You might want to take a look at gmane.comp.python.wxpython for better replies 
to wxPython specific questions.  Looks like you might want OnEnter(self, x, y, 
d) and OnLeave(self) methods of wxDropTarget class

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


Re: Eclipse Plugins

2007-10-26 Thread Martin Marcher
2007/10/26, Robert Rawlins - Think Blue <[EMAIL PROTECTED]>:
> I'm not sure what you IDE you all generally use for your python development.
> I've been somewhat lazy and always used a plain text editor, however this
> technique is starting to take its toll, and it's purely been out of laziness
> not finding myself a decent IDE to develop in. So this morning task is to
> pull my thumb out of my arse and set something up properly.

With Eclipse 3.3 IIRC there is a "Dynamic Language IDE" Package
available. Out of the box, as far as a I know it only supports ruby. I
didn't look to much into it (out of the same reasons you named). Maybe
that could do something with a few tweaks or additional plugins.

> For my other languages, such as HTML, ColdFusion, JAVA etc I make good use
> of the Eclipse SDK, and I'm looking for some advice on the best and most
> popular python plug-ins available, what would you suggest? I downloaded one
> called PyDev which looked ok but nothing too exciting.

I just switched to using emacs. Still struggling with it but it has
some nice features

C-c C-h - to find the help of something
C-c C-c - to run the "buffer" (file) I'm currently editing

a few commands which are customizeable enough to run highlighted text
(where IIRC one can define stuff to pre setup an environment if for
example you need to run a method of a class)

and some other nifty stuff. Be aware the learning curve is quite high

(for the vim guys. I've been using vim before but for my use case
emacs provides just more stuff that "just works". vim may also be your
choice with a few tweaks it does a lot, and it does it fast)

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples within tuples

2007-10-26 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> Hello everybody.
> 
> I'm wondering how to iterate over a tuple like this
> [A,B,C,D]
> while saving A and C in a list.
> 
> My problem is that C sometimes is a tuple of the same structure
> itself...
> 
> 
> thanks!
> korovev
> 
First of all [A,B,C,D] is a list not a tuple. (A,B,C,D) is a tuple.

Without a better example or explanation of what you are trying to do it is 
difficult, but I'll give it a try:

myTuple=(A,B,C,D)
for n, item enumerate(myTuple):
 if n in (0,2):
 myList.append(item)

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


"Standard" Full Text Search Engine

2007-10-26 Thread Martin Marcher
Hello,

is there something like a standard full text search engine?

I'm thinking of the equivalent for python like lucene is for java or
ferret for rails. Preferrably something that isn't exactly a clone of
one of those but more that is python friendly in terms of the API it
provides.

Things I'd like to have:

 * different languages are supported (it seems most FTSs do only english)
 * I'd like to be able to provide an identifier (if I index files in
the filesystem that would be the filename, or an ID if it lives in a
database, or whatever applies)
 * I'd like to pass it just some (user defined) keywords with content,
the actual content (as string, or list of strings or whatever) and to
retrieve the results by search by keyword
 * something like a priority should be assignable to different fields
(like field: title(priority=10, content="My Draft"),
keywords(priority=50, list_of_keywords))

Unnecessary:

 * built-in parsing of different files

The "standard" I'm referring to would be something with a large and
active user base. Like... WSGI is _the_ thing to refer to when doing
webapps it should be something like $FTS-Engine is _the_ engine to
refer to.

any hints?

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Standard" Full Text Search Engine

2007-10-26 Thread Stephan Diehl
Martin Marcher wrote:

> Hello,
> 
> is there something like a standard full text search engine?
> 
> I'm thinking of the equivalent for python like lucene is for java or
> ferret for rails. Preferrably something that isn't exactly a clone of
> one of those but more that is python friendly in terms of the API it
> provides.
> 
> Things I'd like to have:
> 
>  * different languages are supported (it seems most FTSs do only english)
>  * I'd like to be able to provide an identifier (if I index files in
> the filesystem that would be the filename, or an ID if it lives in a
> database, or whatever applies)
>  * I'd like to pass it just some (user defined) keywords with content,
> the actual content (as string, or list of strings or whatever) and to
> retrieve the results by search by keyword
>  * something like a priority should be assignable to different fields
> (like field: title(priority=10, content="My Draft"),
> keywords(priority=50, list_of_keywords))
> 
> Unnecessary:
> 
>  * built-in parsing of different files
> 
> The "standard" I'm referring to would be something with a large and
> active user base. Like... WSGI is _the_ thing to refer to when doing
> webapps it should be something like $FTS-Engine is _the_ engine to
> refer to.
> 
> any hints?
> 

I'm using swish-e (swish-e.org) for all my indexing needs. I'm not sure if
there's a python binding available, I'm using swish-e as an external
executable and live quite happyly with that.

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


Re: .py to sqlite translator [1 of 2]

2007-10-26 Thread Guilherme Polo
2007/10/26, smitty1e <[EMAIL PROTECTED]>:
> Disclaimer(s): the author is nobody's pythonista.  This could probably
> be done more elegantly.
> The driver for the effort is to get PyMacs to work with new-style
> classes.
> This rendering stage stands alone, and might be used for other
> purposes.
> A subsequent post will show using the resulting file to produce (I
> think valid) .el trampoline
> signatures for PyMacs.
> If nothing else, it shows some python internals in an interesting way.
> Tested against version 2.5.1
> Maybe "lumberjack.py" would be a better name, since "It cuts down
> trees, goes real slow, and uses disk galore.  Wishes it'd been
> webfoot[1], just like its dear author".
> Cheers,
> Chris
>
> [1] Author was born in Oregon.
>
> #A sample file:
> class sample( object ):
> """fairly trivial sample class for demonstration purposes.
> """
> def __init__( self
> , some_string ):
> self.hold_it = some_string
>
> def show( self ):
> print self.hold_it
>
> #Invocation:
> # ./pysqlrender.py -f sample.py -o output
>
> #Script:
> #!/usr/bin/python
>
> """Script to dump the parse tree of an input file to a SQLite
> database.
> """
>
> from   optparse import OptionParser
> import os
> import parser
> import pprint
> import re
> import sqlite3
> import symbol
> import token
> import types
>
> from   types import ListType \
>   , TupleType
>
> target_table  = """CREATE TABLE tbl_parse_tree(
>  parse_tree_id INTEGER PRIMARY KEY
> AUTOINCREMENT
>, parse_tree_symbol_id
>, parse_tree_indent
>, parse_tree_value  );"""
>
> target_insert = """INSERT INTO tbl_parse_tree(
>  parse_tree_symbol_id
>, parse_tree_indent
>, parse_tree_value )
>VALUES (%s,  %s, '%s' );"""
>
> symbol_table  = """CREATE TABLE tlp_parse_tree_symbol (
>  parse_tree_symbol_id INTEGER PRIMARY KEY
>, parse_tree_symbol_val   );"""
> symbol_insert = """INSERT INTO tlp_parse_tree_symbol (
>  parse_tree_symbol_id
>, parse_tree_symbol_val )
>VALUES ( %s, '%s' );"""
>
> class symbol_manager( object ):
> """ Class to merge symbols and tokens for ease of use.
> """
> def __init__( self
> , c):
> for k in symbol.sym_name:
> sql = symbol_insert % ( k, symbol.sym_name[k] )
> try:
> c.execute( sql )
> except sqlite3.IntegrityError:
> pass
> for k in token.tok_name:
> sql = symbol_insert % ( k, token.tok_name[k] )
> try:
> c.execute( sql )
> except sqlite3.IntegrityError:
> pass
>
> def get_symbol( self
>   , key  ):
> ret = -1
> if   symbol.sym_name.has_key(key): ret = symbol.sym_name[key]
> elif token.tok_name.has_key(key) : ret = token.tok_name[ key]
> return ret
>
> def recurse_it( self, tester ):
> """Check to see if dump_tup should recurse
> """
> if self.get_symbol(tester) > 0:
> return True
> return False
>
> class stocker( object ):
> """Remembers the depth of the tree and effects the INSERTs
>into the output file.
> """
> def __init__( self ):
> self.cur_indent = 0
>
> def do_symbol( self
>  , c
>  , symbol_value
>  , val  = "" ):
> """Stuff something from the parse tree into the database
> table.
> """
> if   symbol_value==5: self.cur_indent += 1
> elif symbol_value==6: self.cur_indent -= 1
>
> try:
> sql = target_insert\
> % ( symbol_value
>   , self.cur_indent
>   , re.sub( "'", "`", str(val) ))
> c.execute( sql  )
> except AttributeError:
> print "connection bad in lexer"
> except sqlite3.OperationalError:
> print "suckage at indent of %s for %s" \
> % (self.cur_indent, sql)
>
> def dump_tup( tup
> , sym
> , c
> , stok ):
> """Recursive function to descend TUP and analyze its elements.
>  tup   parse tree of a file, rendered as a tuple
>  sym   dictionary rendered from symbol module
>  c live database cursor
>  stok  output object effect token storage
> """
> for node in tup:
> typ = type( node )
> r   = getattr( typ
>  , "__repr__"
>  , None   )
>
> if (issubclass(typ, tuple) and r is tuple.__repr__):
>
> if token.tok_name.has_key( node[0] ):
> stok.do_symbol( c
>

Re: Python Windows Installation

2007-10-26 Thread Wildemar Wildenburger
Bjoern Schliessmann wrote:
> Wildemar Wildenburger wrote:
>> Bjoern Schliessmann wrote:
> 
>>> Which I don't understand (works best for me, and is best practice
>>> in Windows).
>>  
>> Best practice? Says who?
> 
> Ok, LOL. So, now you expect me to cite some official source? Despite
> the fact that the vast majority of windows installers on this
> planet use "%PROGRAMFILES%\Program Name" as default installation
> path, particularly the ones for Microsoft's programs?
> 

Of course, but that would constitute "common practice". "Best practice" 
in my book is the one that causes the least trouble, which 
names-with-whitespace clearly don't. Though by this day and age, I admit 
that programs causing the trouble are the culprits and can be declared 
broken, not the admission of whitesapce.

/W
(God I seem humorless in this one ... ;))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object inheritance

2007-10-26 Thread Anand
On Oct 26, 5:31 pm, "Pradeep Jindal" <[EMAIL PROTECTED]> wrote:
> Can you tell any specific use case for doing this?

I have many implementaions of a db interface.

SimpleDB - simple implementation
BetterDB - optimized implementation
CachedDB - an implementation with caching of queries
RestrictedDB - implementation with permissions

Now, I want to combine these implementations and use.
Typical use case scenarios are:

db = RestrictedDB(CachedDB(SimpleDB()))
db = RestrictedDB(SimpleDB())
db = RestrictedDB(BetterDB())
db = RestrictedDB(CachedDB(BetterDB())
db = CachedDB(SimpleDB())
etc..



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


Re: tuples within tuples

2007-10-26 Thread korovev76

[cut]
>
> Without a better example or explanation of what you are trying to do it is
> difficult

You're right.
Actually i'm parsing an xml file using pyrxp, which returns something
like this:
(tagName, attributes, list_of_children, spare)
Where list_of_children might "be a list with elements that are 4-
tuples or plain strings".

In other terms, if I have something like this:
('bobloblaw')
it's parsed like this:
('tagA', None, [('tagB', None, ['bobloblaw], None)], None)...

Fact is that my xml is much more deep... and I'm not sure how to
resolve it


thanx






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


Re: tuples within tuples

2007-10-26 Thread J. Clifford Dyer
On Fri, Oct 26, 2007 at 06:59:51AM -0700, [EMAIL PROTECTED] wrote regarding Re: 
tuples within tuples:
> 
> > Resolve *what*?  The problem isn't clear yet; at least to me.  Above you
> > say what you get.  What exactly do you want?  Examples please.
> >
> 
> 
> Sorry for my poor english, but I meant: how can I obtain a list of A
> and C starting from something like this?
> 
> (A,B,C,D)
> that could be
> ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
> but also
> ('tagA', None, description, None)
> when I don't know if C is a tuple or not?
> 
> I guess that, at least,  within the cicle I may test if C is a tuple
> or not.. And then apply the same cicle for C... and so on
> 
> Am i right?
> 
> 
> ciao
> korovev

So, to clarify the piece that you still haven't explicitly said, you want to 
keep the tag name and children of every element in your XML document.  (which 
is different from keeping (A, C) from tuple (A, B, C, D), because you want to 
modify C as well, and it's decendants.)

As a first solution, how about: 

def reduceXML(node):
if type(node) == str:
return node
else: 
return (node[0], reduceXML(node[2])

N.B. Beware of stack limitations.

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


Re: bug: subprocess.Popen() hangs

2007-10-26 Thread Nick Craig-Wood
Jonathan Amsterdam <[EMAIL PROTECTED]> wrote:
>  This is a bug in python 2.4 under Linux 2.6.
> 
>  I occasionally see subprocess.Popen() fail to return, and I have
>  finally figured out roughly what's going on. It involves the GC and
>  stderr.

Interesting

Do you have a program to demonstrate the problem?

You are best off reporting bugs here - then they won't get lost!

  http://bugs.python.org/

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples within tuples

2007-10-26 Thread korovev76

> Resolve *what*?  The problem isn't clear yet; at least to me.  Above you
> say what you get.  What exactly do you want?  Examples please.
>


Sorry for my poor english, but I meant: how can I obtain a list of A
and C starting from something like this?

(A,B,C,D)
that could be
('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
but also
('tagA', None, description, None)
when I don't know if C is a tuple or not?

I guess that, at least,  within the cicle I may test if C is a tuple
or not.. And then apply the same cicle for C... and so on

Am i right?


ciao
korovev






ciao
korovev

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


Re: object inheritance

2007-10-26 Thread Duncan Booth
Anand <[EMAIL PROTECTED]> wrote:

> On Oct 26, 5:31 pm, "Pradeep Jindal" <[EMAIL PROTECTED]> wrote:
>> Can you tell any specific use case for doing this?
> 
> I have many implementaions of a db interface.
> 
> SimpleDB - simple implementation
> BetterDB - optimized implementation
> CachedDB - an implementation with caching of queries
> RestrictedDB - implementation with permissions
> 
> Now, I want to combine these implementations and use.
> Typical use case scenarios are:
> 
> db = RestrictedDB(CachedDB(SimpleDB()))
> db = RestrictedDB(SimpleDB())
> db = RestrictedDB(BetterDB())
> db = RestrictedDB(CachedDB(BetterDB())
> db = CachedDB(SimpleDB())
> etc..
> 
> 
No, that is an argument for multiple-inheritance, mixin classes etc. You 
know when constructing the object what behaviour you want it to have. It 
isn't an argument for changing the behaviour of an existing object 
dynamically.

for an example where it is useful to extend the behaviour of objects have a 
look at Zope3 interfaces and adaptors: an object can be defined to 
implement one or more interfaces, and you can associate additional 
interfaces with objects at runtime. Sometimes an object will implement an 
interface directly, but often the implementation is taken out into a 
separate 'adaptor' class. Whenever you want to use a specified interface on 
an object you simply use the interface class as a constructor on the 
object, and that might find the appropriate adapter or it might just return 
the original object if the interface is provided directly.

e.g. see http://plone.org/documentation/tutorial/five-zope3-walkthrough

Most of the interface/adapter/object relationships in Zope are static, but 
there are interfaces which can be added/removed from objects at runtime: 
each web accessible object has a page where you can add or remove 
interfaces. For example there is an INavigationRoot interface that you can 
add to an object which makes it become the top of the navigation tree for 
that part of the site or IPhotoAlbumAble which lets an object behave as a 
photo album.

Note that this is very different than the forwarding mechanism which 
started this thread: when you use an adaptor you get something which 
implements just the specified interface, you don't have to worry about 
conflicting names for methods or attributes. Also you can have a common 
interface associated with objects which have completely different adapters 
implementing that interface.

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


Re: tuples within tuples

2007-10-26 Thread Marc 'BlackJack' Rintsch
On Fri, 26 Oct 2007 05:54:24 -0700, korovev76 wrote:

> [cut]
>>
>> Without a better example or explanation of what you are trying to do it is
>> difficult
> 
> You're right.
> Actually i'm parsing an xml file using pyrxp, which returns something
> like this:
> (tagName, attributes, list_of_children, spare)
> Where list_of_children might "be a list with elements that are 4-
> tuples or plain strings".
> 
> In other terms, if I have something like this:
> ('bobloblaw')
> it's parsed like this:
> ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)...
> 
> Fact is that my xml is much more deep... and I'm not sure how to
> resolve it

Resolve *what*?  The problem isn't clear yet; at least to me.  Above you
say what you get.  What exactly do you want?  Examples please.

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


Re: Mouse hover event in wxpython

2007-10-26 Thread kyosohma
On Oct 26, 3:55 am, sundarvenkata <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> Can somebody tell me if there is an event to indicate mouse hover over
> a control in wxPython? EVT_MOTION does not seem to cut it.
>
>  Thanks in advance,
> Sundar

What are you trying to do? I use EVT_MOTION for mouse hovering and it
works great in my application. You might try EVT_ENTER_WINDOW too.

See also:

http://www.wxpython.org/docs/api/wx.MouseEvent-class.html

Larry is right. The wxPython mailing list would give you even more
accurate answers.

Mike

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


Re: list (range) syntax

2007-10-26 Thread Christof Winter
Ryan Ginstrom wrote:
>> On Behalf Of Steven D'Aprano
>> Because in common English, counting starts at 1 and ranges 
>> normally include both end points (that is, it is a "closed" 
>> interval). If you say "I'll be away from the 4th to the 7th" 
>> and then turn up on the 7th, nearly everyone will wonder why 
>> you're back a day early.
> 
> Actually, I think this illustrates the point about confusion, because in the
> United States at least, "the 4th to the 7th" will not necessarily include
> the 7th. That's why it's common to use circumlocutions like "the 4th through
> the 7th" and "the 4th to the 7th, inclusive" when one wants to be sure.

[slightly OT]
A better example would be "10 to 12 people", which translates to "10, 11, or 12 
people" and hardly ever "10 or 11 people".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An efficient, pythonic way to calculate result sets

2007-10-26 Thread happyhondje
On Oct 26, 2:33 am, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> On Oct 25, 8:31 am, [EMAIL PROTECTED] wrote:
>
>
>
> > I've got a little issue, both programming and performance-wise. I have
> > a set, containing objects that refer to other sets. For example, in a
> > simple notation: (, ) (or in a more object-like
> > display: set(obj1.choices=set(a, b, c) ). There may be obj1..objN
> > objects in the outer set, and the amount of items in the choices sets
> > could also reach a high number. The objects in the choices sets might
> > overlap.
>
> > Now I want to have all possible combinations, like this: (a, d), (b,
> > d), (c, d), (a, e), (b, e), (c, e).
>
> > However, I've got a few catches that make an already (icky) recursive
> > function worse to use.
>
> > First of all, I want to be able to only choose things so that the
> > outer 'result sets' have the same length. For example, if you'd have
> > (, ), you might pick (a, a) with a simple algorythm, the
> > basic behaviour of sets reducing it to (a) and thus having an improper
> > length. I could add yet another loop after calculating everything to
> > throw out any result sets with the improper length, but that would be
> > highly inefficient.
>
> > Second, I'd hope to be able to say that objX should be assumed to have
> > made the choice z. In the first example I mentioned, if I said that
> > 'obj1 == a', the only result sets that would come out would be (a, d)
> > and (a, e).
>
> def cross_nodups(*args):
> 'Cross product after eliminating repeat elements, keeping constant
> size'
> ans = [[]]
> for arg in args:
> ans = [x+[y] for x in ans for y in arg if y not in x]
> return ans
>
> def choose_first(obj1, *args):
> 'Assume a choice of a first object'
> return cross_nodups(obj1, *args[1:])
>
> >>> print cross_nodups('ab', 'acd', 'fg')
>
> [['a', 'c', 'f'], ['a', 'c', 'g'], ['a', 'd', 'f'], ['a', 'd', 'g'],
> ['b', 'a', 'f'], ['b', 'a', 'g'], ['b', 'c', 'f'], ['b', 'c', 'g'],
> ['b', 'd', 'f'], ['b', 'd', 'g']]
>
> >>> print choose_first('a', s1,s2,s3)
>
> [['a', 'c', 'f'], ['a', 'c', 'g'], ['a', 'd', 'f'], ['a', 'd', 'g']]
>
> > (and hopefully not rely on
> > recursion
>
> Easy exercise of transforming recursion to iteration left to the
> reader.
>
> Raymond

Wonderful, thank you Raymond!

I only had one problem with it still (damn I'm picky) and despite
prodding around in that generator expression which absolutely defies
my logic, I've been able to get it working.

In my situation, the choices are always sets rather than strings.
While it shouldn't make a difference (both are iterable), my sets
contain strings.. which end up being cut in pieces and matched
seperately with everything. I've solved this as follows:

def cross_nodups(*args):
'Cross product after eliminating repeat elements, keeping constant
size'
ans = [[]]
for arg in args:
ans = [x+[y] for x in ans for y in arg if y not in x]
return ans

def choose_first(obj1, *args):
'Assume a choice of a first object'
return cross_nodups(frozenset((obj1,)), *args[1:])

Gives results:

>>> choose_first("H", set(["H", "R"]), set(["H", "R", "K", "S"]), set(["H", 
>>> "R", "K", "S"]))
set([frozenset(['H', 'S', 'R']), frozenset(['H', 'K', 'R']),
frozenset(['H', 'K', 'S'])])
>>> choose_first("HA", set(["HA", "RA"]), set(["HA", "RA", "KA", "SA"]), 
>>> set(["HA", "RA", "KA", "SA"]))
set([frozenset(['KA', 'HA', 'RA']), frozenset(['SA', 'HA', 'RA']),
frozenset(['KA', 'HA', 'SA'])])

rather than

>>> choose_first("HA", set(["HA", "RA"]), set(["HA", "RA", "KA", "SA"]), 
>>> set(["HA", "RA", "KA", "SA"]))
set([frozenset(['A', 'SA', 'HA']), frozenset(['H', 'KA', 'SA']),
frozenset(['H', 'KA', 'RA']), frozenset(['A', 'KA', 'HA']),
frozenset(['H', 'HA', 'RA']), frozenset(['H', 'SA', 'HA']),
frozenset(['A', 'SA', 'RA']), frozenset(['A', 'KA', 'SA']),
frozenset(['A', 'HA', 'RA']), frozenset(['H', 'KA', 'HA']),
frozenset(['H', 'SA', 'RA']), frozenset(['A', 'KA', 'RA'])])

Now, this works great! Although I am still torn apart on a possible
optimization (that I'm not sure is an optimization yet):

- should I use the original cross_nodups() function you thought up and
convert all of its contents to a proper set of sets (a secondary loop
afterwards). This seems more efficient since I would not be doing a
lot of frozenset() and list() conversions while looping.
- however, the list() and frozenset() construct should reduce looping
quite a bit and essentially prevent a lot of iterations that would be
created due to the doubles in the original functions output.

Of course that depends on the contents, so for simplicities sake, say
that the algorythm is to run with 5-10 choices to make, each choice
being out of averaged 6 items that may or may not conflict with other
items.

Again, thank you very much Raymond, your snippet makes my monstrosity
quite ready for /dev/null. :)

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


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Fri, 26 Oct 2007 19:19:46 +1000, Ben Finney wrote:
> > Nor should we. A function or type name should be short but
> > explicit, and 'Decimal' is about as short as I'd want.
> 
> You don't like str, int, float, list, set, dict, or bool?

They'd all make lousy names for a decimal type.

-- 
 \  "Whatever you do will be insignificant, but it is very |
  `\ important that you do it."  -- Mahatma Gandhi |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An efficient, pythonic way to calculate result sets

2007-10-26 Thread happyhondje
> def cross_nodups(*args):
> 'Cross product after eliminating repeat elements, keeping constant
> size'
> ans = [[]]
> for arg in args:
> ans = [x+[y] for x in ans for y in arg if y not in x]
> return ans
>
> def choose_first(obj1, *args):
> 'Assume a choice of a first object'
> return cross_nodups(frozenset((obj1,)), *args[1:])

Oops, crap, I pasted the unchanged cross_nodups() you wrote. My
adjusted variety:

def cross_nodups(*args):
'Cross product after eliminating repeat elements, keeping constant
size'
ans = [[]]
for arg in args:
ans = [frozenset(list(x)+[y]) for x in ans for y in arg if y
not in x]
return set(ans)

Anyhow, thank you! :)

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


Re: tuples within tuples

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

> 
> [cut]
>>
>> Without a better example or explanation of what you are trying to do
>> it is difficult
> 
> You're right.
> Actually i'm parsing an xml file using pyrxp, which returns something
> like this:
> (tagName, attributes, list_of_children, spare)
> Where list_of_children might "be a list with elements that are 4-
> tuples or plain strings".
> 
> In other terms, if I have something like this:
> ('bobloblaw')
> it's parsed like this:
> ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)...
> 
> Fact is that my xml is much more deep... and I'm not sure how to
> resolve it
> 
Probably you want some sort of visitor pattern.

e.g. (warning untested pseudo code ahead)

def walkTree(tree, visitor):
tag, attrs, children, spare = tree
fn = getattr(visitor, 'visit_'+tag, None)
if not fn: fn = visitor.visitDefault
fn(tag, attrs, children, spare)

for child in children:
if isinstance(child, tuple):
walktree(child, visitor)
else:
visitor.visitContent(child)

class Visitor:
   def visitDefault(self, t, a, c, s): pass
   def visitContent(self, c): pass

... then when you want to use it you subclass Visitor adding appropriate 
visit_tagA, visit_tabB methods for the tags which interest you. You walk 
the tree, and store whatever you want to save in your visitor subclass 
instance.

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


Re: "Standard" Full Text Search Engine

2007-10-26 Thread aaron . watters
On Oct 26, 8:53 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Martin Marcher wrote:
> > Hello,
>
> > is there something like a standard full text search engine?
> > any hints?
>
> There are several python lucene implementations available, and recently here
> a project called NUCULAR turned up. And there is ZCatalog, the
> full-text-indexing technology used in Zope, but which should be usable
> outside of zope.

Thanks for the NUCULAR mention (http://nucular.sourceforge.net).  It
certainly doesn't meet all the requirements requested (very few users
yet, some
features missing).  Please give it a look, however.  It's easy to use
and fast.  How fast it is compared to others I can't say, especially
since
some of the numbers I see quoted out there are really incredible (how
can an indexer by faster than "cp"?) -- I suspect some sort of
trickery,
frankly.

Anyway, if you want a feature like proximity searching or
some sort of internationalization support (it works with unicode, but
that's probably not enough), please let me know.  I focused on
the core indexing and retrieval functionality, and I think a lot of
additional features can be added easily.

fwiw,  -- Aaron Watters

===
% make love
don't know how to make love. stopping.

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


distutils error dealing with rpms?

2007-10-26 Thread cesar.ortiz
Hi all,

I am trying to generate an distribution with distutils, using in the
setup() invocation the parameters 'packages' and 'data_files'.
If I use bdist, the tar.gz contains all the files, but I I use
bdist_rpm the data_files are not included in the rpm.

has anyone face this before?
I am using redhad, with rpm 4.4.2 and python 2.4.

Thank you, César

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


Re: Dual Python Installed Environments..

2007-10-26 Thread Neil Wallace
On Thu, 25 Oct 2007 14:45:51 -0700, sam wrote:

> Hi..
> 
> I'm looking to install dual versions of python 2.3, 2.4 on the same box.
> I'm trying to figure out if there's something I'm missing, some kind of
> gotchas that I haven't seen.
> 
> I'm also trying to figure out how to allow my script to determine which
> version to use???
> 
> Thanks

Here's one that tripped me up...
I altered the symlink at /usr/bin/python to point to Python 2.2 which I 
installed in my home folder (see below for the reason.. in case you are 
wondering) this broke some packages in my distribution (Ubuntu).
I could see the broken packages, and didn't need them anymore, but I was 
unable to remove them as the removal scripts were (presumably) python 2.4+

Much head scratching at the time.

Neil.
Reason - I had written some CGI scripts and tested them thoroughly on my
localhost version of the site. However I uploaded the files, and some of
them didn't work, my sites server (not under my full control) runs Python
2.2, so I downloaded 2.2, and made it default so that localhost used this
version so I could retest and ammend etc..

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


Re: NUCULAR fielded text searchable indexing

2007-10-26 Thread aaron . watters
On Oct 17, 7:20 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > (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.

Sorry you feel that way about the name, Steve :(.
I thought it was funny and eye catching.
I'm glad you remember Gadfly (http://gadfly.sourceforge.net).
Still distributed with many packages (including Zope, I think).
Still getting 5-20 downloads a day on sourceforge.
Not bad for a package released back in '94, eh?

   -- Aaron Watters

===
The method employed I would gladly explain,
 While I have it so clear in my head,
If I had but the time and you had but the brain--
 But much yet remains to be said.
-- http://www.xfeedme.com/nucular/gut.py/go?FREETEXT=snark

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


Interpreter hook during evaluation

2007-10-26 Thread WilliamKF
Hello,

I would like access to a hook inside Python that would allow me to
register a C++ function to be called periodically during the
evaluation of a Python script.

Does any such thing exist today in Python? I poked around but didn't
find anything.

I want to do this for interrupt handling. I'd like to be able to
interrupt long running Python commands. I have a hook which would
throw a C++ exception if an interrupt is detected. I would then catch
this at the place where my application which embeds Python invokes a
Python command. My hook is written to be very fast, so calling it
every Python instruction would not be that bad in terms of
performance.

I'd like to avoid changing the existing Python implementation, which
is why I'm looking for a hook. Otherwise, a user would not be able to
substitute in their own Python implementation if they so desire
instead of taking the default on our app uses.

Thanks for the ideas.

-William

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


Re: renice

2007-10-26 Thread Dan
On Oct 26, 4:30 am, mokhtar <[EMAIL PROTECTED]> wrote:
> Hi
>
> Is it possible to renice the python process executing the current python
> script ?:confused:
> --
> View this message in 
> context:http://www.nabble.com/renice-tf4695834.html#a13422771
> Sent from the Python - python-list mailing list archive at Nabble.com.

On UNIX:
>>> import os
>>> os.system("renice -n %d %d" % ( new_nice, os.getpid() ) )
(untested)

I don't know if windows has the concept of renice...

-Dan

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


Re: Cross-platform GUI development

2007-10-26 Thread Sion Arrowsmith
bramble  <[EMAIL PROTECTED]> wrote:
> [ GTK is ] free
>software, so contributors can try and make the L&F more native if it's
>really that big a deal.

But the people who care about Windows native L&F are not the people
with the resources (time, money, probably experience) to address
this issue. And the people who do probably don't care. If you're
developing an app where it matters, it's much easier to just go with
the option that gives the right L&F out of the box.

>One reason I'm not crazy about wx because I don't like the idea of
>adding yet another API layer into the mix. Wx seems quite large, and
>if issues arise, debugging a GUI that calls another GUI does not seem
>like a fun way to spend your time.

I used to maintain a couple of commercial wxPython apps which were
only ever meant to run on Windows, and the native L&F was the
primary driver behind the choice of wx. Because Linux is my
development platform of choice, I wound up trying to run them there
as well. For a supposedly cross-platform library, it required a lot
of porting effort. And, as you say, when things go wrong it's
difficult to know whether to lay it at the feet of wxPython, wx or
GTK. (And then bear in mind that GTK is layered on top of X)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

[ANN] Dabo 0.8.2 Released

2007-10-26 Thread Ed Leafe
We are pleased to announce the release of Dabo 0.8.2, the latest  
version of our desktop application framework. It is available on our  
download page: http://dabodev.com/download

If you're not familiar with Dabo, it is the leading framework for  
building desktop applications in Python. You can get more information  
about Dabo on our website: http://dabodev.com

Probably the biggest change is in the way we will be handling  
updates and releases. We will no longer maintain separate 'stable'  
and 'development' versions, as the 'stable' got out-of-date so  
quickly that the name became ironic. Instead, we will only have a  
single development branch.

What's made this possible is the incorporation of Web Update into  
the framework. This will check our servers regularly for updates, and  
notify you if any are available. If you want to grab those updates,  
you simply need to click the 'OK' button, and your framework is  
updated for you. Of course, nothing is ever updated without you  
knowing about it, and you can turn the whole thing off if you so desire.

We are also including DaboDemo and the visual tools in the download,  
instead of making you grab those separately. We plan on integrating  
Web Update-like features into these in the near future.

As usual, there have been a bunch of minor changes and bugfixes;  
instead of including them here, you can see them at: http:// 
svn.dabodev.com/dabo/tags/dabo-0.8.2/ChangeLog

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

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


Re: "Standard" Full Text Search Engine

2007-10-26 Thread Martin Marcher
2007/10/26, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> On Oct 26, 8:53 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > Martin Marcher wrote:
> Thanks for the NUCULAR mention (http://nucular.sourceforge.net).  It
> certainly doesn't meet all the requirements requested (very few users
> yet, some features missing).  Please give it a look, however.  It's easy to 
> use
> and fast.  How fast it is compared to others I can't say, especially
> since some of the numbers I see quoted out there are really incredible (how
> can an indexer by faster than "cp"?) -- I suspect some sort of
> trickery,
> frankly.

For starters I think I will go with nucular. It seems good enough,
lightweight and easy to use.

> Anyway, if you want a feature like proximity searching or
> some sort of internationalization support (it works with unicode, but
> that's probably not enough), please let me know.  I focused on
> the core indexing and retrieval functionality, and I think a lot of
> additional features can be added easily.

I don't know much about the internals of search engines but I'll
probably report back with a few suggestions after some time of usage
:)


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Windows Installation

2007-10-26 Thread Bjoern Schliessmann
Wildemar Wildenburger wrote:

> Of course, but that would constitute "common practice". 

Ah, okay. That was what I actually meant ;)

> "Best practice" in my book is the one that causes the least
> trouble, which names-with-whitespace clearly don't. Though by this
> day and age, I admit that programs causing the trouble are the
> culprits and can be declared broken, not the admission of
> whitesapce. 

The last app I saw that had problems with whitespace was Worms 2
(1997). YMMV (and I'm interested in it).

Regards,


Björn

-- 
BOFH excuse #165:

Backbone Scoliosis

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


Re: pure python data compression (zip)

2007-10-26 Thread Meff
Hi René,
What about to use the GE863-PRO? It comes with ARM9 inside, helps with
200MIPS and will run embedded Linux. We will launch a version with
connectors, SIM card holder and RF connector on 
http://www.telemobilityforum.com/eng/
in Monza next days.
I call it an embedded Linux with integrated GPRS module. By using the
embedded Linux you will able to use C code as well. Please feel free
to contact me and to ask for a starter kit with 30% discount.

Best regards

Harald Naumann
Technical Director

Round Solutions GmbH & Co KG
Im Steingrund 3 * D-63303 Dreieich * Germany
Tel:  +49 (0)6103 270440 Fax: +49 (0)27044199
Email: harald.naumann (at) roundsolutions.com
Homepage: www.roundsolutions.com


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


Re: "Standard" Full Text Search Engine

2007-10-26 Thread Paul Rubin
"Martin Marcher" <[EMAIL PROTECTED]> writes:
> is there something like a standard full text search engine?
> 
> I'm thinking of the equivalent for python like lucene is for java or
> ferret for rails. Preferrably something that isn't exactly a clone of
> one of those but more that is python friendly in terms of the API it
> provides.

Ferret is basically a Lucene clone, originally written in Ruby but
with the intensive parts later rewritten in C for speed since the Ruby
version was too slow.  There was something similar done in Python
(PyLucene, I think) that was also pretty slow.

Solr (a wrapper around Lucene) has a reasonable set of Python
bindings.  Solr has become very popular among web developers because
it's pretty easy to set up and use.  However, its flexibility is not
all that great.

Nucular looks promising though still in a fairly early stage.
Suggestion for Aaron: it would be great if Nucular used the same
directives as Solr (i.e. say  instead of  and fix other
such gratuitous differences) and implemented more Solr/Lucene features.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to/help installing impure packages

2007-10-26 Thread owl
I love easy_install.

I love watching it search and complete.
It's when it doesn't complete that causes me grief.
I don't program a lot these days and am relatively new to python but I
often wind up installing packages on both unix and windows machines
and often the 'build' part of the install fails with not being able to
find the compiler or compile problems.

If there are any articles/pointers that talk about this, i.e. how to
troubleshoot, I'd love to know.

If I was writing such an article I'd start with:
- how easy_install uses distutils (even this is an assumption on my
part)
- where it looks in the env. for stuff on both unix/linux/windows
- what files to tweak to help it find stuff if your env. is different.
- i.e. can I config some file to have packages not try and compile but
use pure python if possible?
- i.e. w/o speedups
- how to work around problems such as easy_install failing because a
site is down
- i.e. how to manually download, 'unpack' & 'build'
- since packages fail to build, how to set things up to download &
keep things around when they fail so you can tinker with it until you
get it working!

I love python, and nothing against impure packages, but when they
cause problems it starts to 'tarnish the dream' of an agnostic
language.

Thoughts?

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


Re: Interpreter hook during evaluation

2007-10-26 Thread ThunderBug
> I would like access to a hook inside Python that would allow me to
> register a C++ function to be called periodically during the
> evaluation of a Python script.
>
> ... so calling it
> every Python instruction would not be that bad in terms of
> performance.
>

I too could make good use of such a hook.




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


python logging config file doesn't allow filters?

2007-10-26 Thread Matthew Wilson
The python logging module is a beautiful masterpiece.  I'm studying
filters and the config-file approach.  Is it possible to define a filter
somehow and then refer to it in my config file?

TIA

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


Re: Interpreter hook during evaluation

2007-10-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hello,
> 
> I would like access to a hook inside Python that would allow me to
> register a C++ function to be called periodically during the
> evaluation of a Python script.
> 
> Does any such thing exist today in Python? I poked around but didn't
> find anything.
> 
> I want to do this for interrupt handling. I'd like to be able to
> interrupt long running Python commands. I have a hook which would
> throw a C++ exception if an interrupt is detected. I would then catch
> this at the place where my application which embeds Python invokes a
> Python command. My hook is written to be very fast, so calling it
> every Python instruction would not be that bad in terms of
> performance.
> 
> I'd like to avoid changing the existing Python implementation, which
> is why I'm looking for a hook. Otherwise, a user would not be able to
> substitute in their own Python implementation if they so desire
> instead of taking the default on our app uses.

trace.

http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html


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


Re: elementtree w/utf8

2007-10-26 Thread Tim Arnold

"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Thu, 25 Oct 2007 17:15:36 -0400, Tim Arnold wrote:
>
>> Hi, I'm getting the by-now-familiar error:
>> return codecs.charmap_decode(input,errors,decoding_map)
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in 
>> position
>> 4615: ordinal not in range(128)
>>
>> the html file I'm working with is in utf-8, I open it with codecs, try to
>> feed it to TidyHTMLTreeBuilder, but no luck. Here's my code:
>> from elementtree import ElementTree as ET
>> from elementtidy import TidyHTMLTreeBuilder
>>
>> fd = codecs.open(htmfile,encoding='utf-8')
>> tidyTree =
>> TidyHTMLTreeBuilder.TidyHTMLTreeBuilder(encoding='utf-8')
>> tidyTree.feed(fd.read())
>> self.tree = tidyTree.close()
>> fd.close()
>>
>> what am I doing wrong? Thanks in advance.
>
> You feed decoded data to `TidyHTMLTreeBuilder`.  As the `encoding`
> argument suggests this class wants bytes not unicode.  Decoding twice
> doesn't work.
>
> Ciao,
> Marc 'BlackJack' Rintsch

well now that you say it, it seems so obvious...
some day I will get the hang of this encode/decode stuff. When I read about 
it, I'm fine, it makes sense, etc. maybe even a little boring. And then I 
write stuff like the above!

Thanks to you and Diez for straightening me out.
--Tim


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


ctypes on arm linux

2007-10-26 Thread Samuel M. Smith
I have built python 1.5.1 from source for an embedded ARM9 debian  
linux Sarge distribution but
ctypes doesn't build.  Anybody have any idea what the problem is? Do  
I have to have the libffi package

installed.
See my errors below.
I looked and ffi.h exists in three places

/usr/local/src/Python-2.5.1/Modules/_ctypes/libffi_arm_wince/ffi.h
/usr/local/src/Python-2.5.1/Modules/_ctypes/libffi_msvc/ffi.h
/usr/local/src/Python-2.5.1/build/temp.linux-armv4l-2.5/libffi/ 
include/ffi.h



with two different definitions for ffi_closure
typedef struct {
  char tramp[FFI_TRAMPOLINE_SIZE];
  ffi_cif   *cif;
  void (*fun)(ffi_cif*,void*,void**,void*);
  void  *user_data;
} ffi_closure __attribute__((aligned (8)));

typedef struct {
  char tramp[FFI_TRAMPOLINE_SIZE];
  ffi_cif   *cif;
  void (*fun)(ffi_cif*,void*,void**,void*);
  void  *user_data;
} ffi_closure;

is the __attribute__ syntax causing a problem


building '_ctypes' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict- 
prototypes -fPIC -I. -I/usr/local/src/Python-2.5.1/./Include -Ibuild/ 
temp.linux-armv4l-2.5/libffi/include -Ibuild/temp.linux-armv4l-2.5/ 
libffi -I/usr/local/src/Python-2.5.1/Modules/_ctypes/libffi/src -I./ 
Include -I. -I/usr/local/include -I/usr/local/src/Python-2.5.1/ 
Include -I/usr/local/src/Python-2.5.1 -c /usr/local/src/Python-2.5.1/ 
Modules/_ctypes/_ctypes.c -o build/temp.linux-armv4l-2.5/usr/local/ 
src/Python-2.5.1/Modules/_ctypes/_ctypes.o
In file included from /usr/local/src/Python-2.5.1/Modules/_ctypes/ 
_ctypes.c:126:
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:71: error:  
syntax error before "ffi_closure"
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:71: warning: no  
semicolon at end of struct or union
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:78: error:  
syntax error before '}' token
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:78: warning:  
type defaults to `int' in declaration of `ffi_info'
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:78: warning:  
data definition has no type or storage class
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:94: error:  
syntax error before "ffi_info"
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:94: warning: no  
semicolon at end of struct or union
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:101: error:  
conflicting types for `restype'
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:76: error:  
previous declaration of `restype'
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:109: error:  
syntax error before '}' token
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:109: warning:  
type defaults to `int' in declaration of `CFuncPtrObject'
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:109: warning:  
data definition has no type or storage class
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:165: error:  
syntax error before '*' token
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:168: warning:  
type defaults to `int' in declaration of `AllocFunctionCallback'
/usr/local/src/Python-2.5.1/Modules/_ctypes/ctypes.h:168: warning:  
data definition has no type or storage class
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c: In function  
`c_void_p_from_param':
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:1330: error:  
`func' undeclared (first use in this function)
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:1330: error:  
(Each undeclared identifier is reported only once
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:1330: error:  
for each function it appears in.)
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:1331: error:  
syntax error before ')' token

/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c: At top level:
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2470: error:  
syntax error before '*' token
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2471: warning:  
function declaration isn't a prototype
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c: In function  
`CFuncPtr_set_errcheck':
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2472: error:  
`ob' undeclared (first use in this function)
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2477: error:  
`self' undeclared (first use in this function)

/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c: At top level:
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2484: error:  
syntax error before '*' token
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2485: warning:  
function declaration isn't a prototype
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c: In function  
`CFuncPtr_get_errcheck':
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2486: error:  
`self' undeclared (first use in this function)

/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c: At top level:
/usr/local/src/Python-2.5.1/Modules/_ctypes/_ctypes.c:2495: error:  
syntax error before '*' token
/usr/local/src/Python

Re: Eclipse Plugins

2007-10-26 Thread Heikki Toivonen
Martin Marcher wrote:
> 2007/10/26, Robert Rawlins - Think Blue <[EMAIL PROTECTED]>:
>> For my other languages, such as HTML, ColdFusion, JAVA etc I make good use
>> of the Eclipse SDK, and I'm looking for some advice on the best and most
>> popular python plug-ins available, what would you suggest? I downloaded one
>> called PyDev which looked ok but nothing too exciting.

I'm a very happy user of PyDev. The main reason I got PyDev was to get
automatic error reporting in the editor (it uses PyLint for this, you
need to install PyLint first). The debugger is also pretty good
(supports even multiple threads). Exceptions could perhaps be handled
better, and getting a shell in the debugger context is only available in
the commercial extension to PyDev I think.

Having come from (X)Emacs, perhaps my IDE needs are primitive. I've
tried to use some automatic refactoring tools but support that that is
pretty primitive for Python at the moment.

PyDev is open source, and the developer is pretty responsive, so if you
could describe what is missing there is a good chance it would get
implemented. I even fixed two bugs myself, my first ever real Java
contribution...

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


Re: Bypassing __getattribute__ for attribute access

2007-10-26 Thread Adam Donahue
Thank you all for the detailed replies, I appreciate it.  I only read
up on this yesterday morning, but I feel I've gotten a lot of insight
in a short time thanks to your contributions to this thread.  Useful
all around!

Adam

On Oct 26, 2:50 am, Bruno Desthuilliers  wrote:
> Chris Mellon a écrit :
>
> > On Thu, 2007-10-25 at 23:13 +0200, Bruno Desthuilliers wrote:
> > 
>
> 
>
> >> Dynamically adding methods to classes is pretty
> >> straightforward, the tricky point is to dynamically add methods to
> >> instances, since the descriptor protocol is only triggered for class
> >> attributes. But you obviously found how to do it using func.__get__(obj,
> >> type(obj)) !-)
>
> > This is the greasy, getting your hands dirty way. I vastly prefer (and
> > reccomend) using the new module:
>
> Indeed.


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

*** Will DEVASTATE and BANKRUPT any Brit daring to get out of line ***

2007-10-26 Thread lemnitzer
http://www.ft.com/cms/s/0/56cb5b92-10a7-11dc-96d3-000b5df10621.html?nclick_check=1

Harvard legal expert vows to sue lecturers boycotting Israel

By Jon Boone

Published: June 2 2007 03:00

A top American lawyer has threatened to wage a legal war against
British academics who seek to cut links with Israeli universities.

Alan Dershowitz, a Harvard law professor renowned for his staunch
defence of Israel and high-profile legal victories, including his role
in the O.J. Simpson trial, vowed to "devastate and bankrupt" lecturers
who supported such boycotts.

This week's annual conference of Britain's biggest lecturers' union,
the University and College Union, backed a motion damning the
"complicity of Israeli academia in the occupation [of Palestinian
land]".

It also obliged the union's executive to encourage members to
"consider the moral implications of existing and proposed links with
Israeli academic institutions".

Prof Dershowitz said he had started work on legal moves to fight any
boycott.

He told the Times Higher Educational Supplement that these would
include using a US law - banning discrimination on the basis of
nationality - against UK universities with research ties to US
colleges. US academics might also be urged to accept honorary posts at
Israeli colleges in order to become boycott targets.

"I will obtain legislation dealing with this issue, imposing sanctions
that will devastate and bankrupt those who seek to impose bankruptcy
on Israeli academics," he told the journal.

Sue Blackwell, a UCU activist and member of the British Committee for
Universities of Palestine, said: "This is the typical response of the
Israeli lobby which will do anything to avoid debating the real issue
- the 40-year occupation of Palestine." Jewish groups have attacked
the UCU vote, which was opposed by Sally Hunt, its general secretary.

C The Financial Times Limited 2007

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


Re: "Standard" Full Text Search Engine

2007-10-26 Thread Paul Boddie
On 26 Okt, 19:33, Paul Rubin  wrote:
>
> Ferret is basically a Lucene clone, originally written in Ruby but
> with the intensive parts later rewritten in C for speed since the Ruby
> version was too slow.  There was something similar done in Python
> (PyLucene, I think) that was also pretty slow.

You're thinking of Lupy, whose authors/supporters then seemed to
switch to Xapian:

http://www.divmod.org/projects/lupy

Meanwhile, PyLucene doesn't seem particularly slow to me. Provided you
can build the software (it requires gcj), it seems to work rapidly and
reliably - the only problem I've ever had was related to a threading
bug in Python 2.3 which was subsequently fixed by the Python core
developers.

Paul

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


Intellectual TERRORism by Alan Dershowitz Re: *** Will DEVASTATE and BANKRUPT any Brit daring to get out of line ***

2007-10-26 Thread lemnitzer
Intellectual terrorism
By Ghada Karmi
10/26/2007
The newest and least attractive import from America, following on
behind Coca-Cola, McDonald's and Friends, is the pro-Israel lobby. The
latest target of this US-style campaign is the august Oxford Union.

This week, two Israeli colleagues and I were due to appear at the
union to participate in an important debate on the one-state solution
in Israel-Palestine. Also invited was the American Jewish scholar and
outspoken critic of Israel, Norman Finkelstein. At the last minute,
however, the union withdrew its invitation to him, apparently
intimidated by threats from various pro-Israel groups.

The Harvard Jewish lawyer and indefatigable defender of Israel, Alan
Dershowitz, attacked the topic of the debate as well as the Oxford
Union itself. In an article headlined "Oxford Union is dead", he
accused it of having become "a propaganda platform for extremist
views", and castigated its choice of what he termed anti-Israel and
anti-Semitic speakers.

Yet Dershowitz could have restored the balance as he saw it; he was
the first person invited by the Oxford Union to oppose the motion but
he declined due, as he put it, to "the terms of the debate and my
proposed teammates".

Dershowitz's article attacking the Oxford Union appeared in the
Jerusalem Post in Israel and Frontpage magazine in the US. [Because of
British defamation laws Cif has been advised not to provide a link -
Ed.]

Dershowitz and Finkelstein were protagonists in a much-publicised
academic row in the US, though it is unclear whether this has any
relevance to the Oxford Union spat.

In solidarity with Finkelstein and to oppose this gross interference
in British democratic life, the three of us on the "one state" side -
myself, Avi Shlaim, of St Anthony's College, Oxford, and the Israeli
historian Ilan Pappe - decided to withdraw from the debate. This was
not an easy decision, since the topic was timely and necessary given
the current impasse in the Israeli-Palestinian peace process, where
innovative solutions are in short supply.

Dershowitz and the other pro-Israel activists may rejoice at their
success in derailing an important discussion. But it is of little
comfort to those of us who care about freedom of speech in this
country. Last May, Dershowitz interfered in British academic life when
the University and College Union voted overwhelmingly to debate the
merits of boycotting Israeli institutions. He teamed up with a British
Jewish lawyer, Anthony Julius, and others, threatening to "devastate
and bankrupt" anyone acting against Israeli universities.

In another example of these bullying tactics, the Royal Society of
Medicine, one of Britain's most venerable medical institutions, came
under an attack this month, unprecedented in its 200 year history. It
had invited Dr Derek Summerfield, a psychiatrist (who has also
documented Israel's medical abuses against Palestinians in the
Occupied Territories), to its conference on Religion, Spirituality and
Mental Health. The RSM was immediately bombarded with threats from pro-
Israel doctors demanding Dr Summerfield's removal on the grounds that
he was and biased, and that the RSM's charitable status would be
challenged if he remained. Intimidated, the RSM asked Dr Summerfield
to withdraw, although they later reinstated him.

The power of the Israel lobby in America is legendary. It demonstrates
its influence at many levels. Campus Watch is a network that monitors
alleged anti-Israel activity in US academic institutions. The
difficulties of promotion in the US for scholars deemed anti-Israeli
are notorious. The notable Palestinian academic, Edward Said, was
subjected to an unrelenting campaign by pro-Israel groups at Columbia
University with threats on his life. His successor, Rashid Khalidi, is
the current object of the same campaign of vilification and attack.
Finkelstein himself has been denied tenure at his university and
everywhere else. The authors of a recent study of the Israel lobby's
influence on US foreign policy have been called anti-Semites and white
supremacists. Former president Jimmy Carter's book, Palestine: peace
not apartheid, has earned him the label of "Jew-hater" and Nazi
sympathiser. The British publisher, Pluto Press, is likely to be
dropped by its American distributors, the University of Michigan
Press, because pro-Israel groups accuse it of including "anti-
Semitic" (ie pro-Palestinian/critical of Israel) books on its list.

Such activities are familiar in the US. People there are hardened or
resigned to having their freedom of expression limited by the pro-
Israel lobby, and the threats of Dershowitz would cause no surprise to
anyone. But Britain is different, naively innocent in the face of US-
style assaults on its scholars and institutions. No wonder that those
who have been attacked give in so quickly, nervous of something they
do not understand. The UCU leadership, shocked and intimidated by the
ferocious reaction to the boycott m

Re: *** Will DEVASTATE and BANKRUPT any Brit daring to get out of line ***

2007-10-26 Thread lemnitzer
http://www.fpp.co.uk/online/07/06/Dershowitz.html

Look at the facial expression of Alan Dershowitz
<-

Financial times
Monday, June 4, 2007
Harvard legal expert vows to sue ["bankrupt"] lecturers boycotting
Israel
By Jon Boone

A TOP American lawyer has threatened to wage a legal war against
British academics who seek to cut links with Israeli universities.

Alan Dershowitz, a Harvard law professor renowned for his staunch
defence of Israel and high-profile legal victories, including his role
in the O.J. Simpson trial, vowed to "devastate and bankrupt" lecturers
who supported such boycotts.

This week's annual conference of Britain's biggest lecturers' union,
the University and College Union, backed a motion damning the
"complicity of Israeli academia in the occupation [of Palestinian
land]".

It also obliged the union's executive to encourage members to
"consider the moral implications of existing and proposed links with
Israeli academic institutions".

Prof Dershowitz said he had started work on legal moves to fight any
boycott.

He told the Times Higher Educational Supplement that these would
include using a US law - banning discrimination on the basis of
nationality - against UK universities with research ties to US
colleges. US academics might also be urged to accept honorary posts at
Israeli colleges in order to become boycott targets.

"I will obtain legislation dealing with this issue, imposing sanctions
that will devastate and bankrupt those who seek to impose bankruptcy
on Israeli academics," he told the journal.

Sue Blackwell, a UCU activist and member of the British Committee for
Universities of Palestine, said: "This is the typical response of the
Israeli lobby which will do anything to avoid debating the real issue
- the 40-year occupation of Palestine." Jewish groups have attacked
the UCU vote, which was opposed by Sally Hunt, [How unfortunate: you
only have to change two letters...] its general secretary.

On Oct 26, 11:37 am, [EMAIL PROTECTED] wrote:
> http://www.ft.com/cms/s/0/56cb5b92-10a7-11dc-96d3-000b5df10621.html?n...
>
> Harvard legal expert vows to sue lecturers boycotting Israel
>
> By Jon Boone
>
> Published: June 2 2007 03:00
>
> A top American lawyer has threatened to wage a legal war against
> British academics who seek to cut links with Israeli universities.
>
> Alan Dershowitz, a Harvard law professor renowned for his staunch
> defence of Israel and high-profile legal victories, including his role
> in the O.J. Simpson trial, vowed to "devastate and bankrupt" lecturers
> who supported such boycotts.
>
> This week's annual conference of Britain's biggest lecturers' union,
> the University and College Union, backed a motion damning the
> "complicity of Israeli academia in the occupation [of Palestinian
> land]".
>
> It also obliged the union's executive to encourage members to
> "consider the moral implications of existing and proposed links with
> Israeli academic institutions".
>
> Prof Dershowitz said he had started work on legal moves to fight any
> boycott.
>
> He told the Times Higher Educational Supplement that these would
> include using a US law - banning discrimination on the basis of
> nationality - against UK universities with research ties to US
> colleges. US academics might also be urged to accept honorary posts at
> Israeli colleges in order to become boycott targets.
>
> "I will obtain legislation dealing with this issue, imposing sanctions
> that will devastate and bankrupt those who seek to impose bankruptcy
> on Israeli academics," he told the journal.
>
> Sue Blackwell, a UCU activist and member of the British Committee for
> Universities of Palestine, said: "This is the typical response of the
> Israeli lobby which will do anything to avoid debating the real issue
> - the 40-year occupation of Palestine." Jewish groups have attacked
> the UCU vote, which was opposed by Sally Hunt, its general secretary.
>
> C The Financial Times Limited 2007


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


Re: [ANN] Dabo 0.8.2 Released

2007-10-26 Thread Ed Leafe
On Oct 26, 2007, at 1:23 PM, Dennis Lee Bieber wrote:

>>  We are also including DaboDemo and the visual tools in the download,
>> instead of making you grab those separately. We plan on integrating
>> Web Update-like features into these in the near future.
>>
>   Let's see if I have this right before doing an "empty trash"... I
> can delete the directory I had for "stable" (containing three
> TortoiseSVN enabled subdirectories: Dabo, DaboIDE, DaboDemo), along  
> with
> the DaboIDE and DaboDemo subdirectories I had under "dev"...

That's right. The 'stable' branches are still available in  
Subversion, but only read-only. No changes will be made to these from  
now on.

You can continue to use Subversion if you wish, but note that the  
URLs have changed, since the framework, demo and visual tools are all  
in the same trunk:

  svn checkout http://svn.dabodev.com/dabo/trunk/dabo
  svn checkout http://svn.dabodev.com/dabo/trunk/ide
  svn checkout http://svn.dabodev.com/dabo/trunk/demo


-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


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


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread Shane Geiger

D = lambda x: decimal.Decimal(str(x))

>> D(3.2)
Decimal("3.2")



Steven D'Aprano wrote:
> On Fri, 26 Oct 2007 19:19:46 +1000, Ben Finney wrote:
>
>   
>>> Of course we can intruduce a single character function name as an alias
>>> for the Decimal type constructor, but even then we have to use both
>>> parentheses and quotes for each and every decimal constant. We cannot
>>> make it shorter than D("12.34")
>>>   
>> Nor should we. A function or type name should be short but explicit, and
>> 'Decimal' is about as short as I'd want.
>> 
>
> You don't like str, int, float, list, set, dict, or bool?
>
> Or for that matter, enum
> http://www.python.org/dev/peps/pep-0354/
>
> *wink*
>
>
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
url:http://www.ncee.net
version:2.1
end:vcard

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

Rare Footage: An Intellectually and spiritually enlightening discussion with Rabbis of Neturei Karta

2007-10-26 Thread lemnitzer
Hour long RARE video of the Great Rabbis, Unfortunately, the sound is
poor quality.

http://www.youtube.com/watch?v=3dSHl3C9kgY
http://www.youtube.com/watch?v=jOVJr-ATnOw


On Oct 26, 11:37 am, [EMAIL PROTECTED] wrote:
> http://www.ft.com/cms/s/0/56cb5b92-10a7-11dc-96d3-000b5df10621.html?n...
>
> Harvard legal expert vows to sue lecturers boycotting Israel
>
> By Jon Boone
>
> Published: June 2 2007 03:00
>
> A top American lawyer has threatened to wage a legal war against
> British academics who seek to cut links with Israeli universities.
>
> Alan Dershowitz, a Harvard law professor renowned for his staunch
> defence of Israel and high-profile legal victories, including his role
> in the O.J. Simpson trial, vowed to "devastate and bankrupt" lecturers
> who supported such boycotts.
>
> This week's annual conference of Britain's biggest lecturers' union,
> the University and College Union, backed a motion damning the
> "complicity of Israeli academia in the occupation [of Palestinian
> land]".
>
> It also obliged the union's executive to encourage members to
> "consider the moral implications of existing and proposed links with
> Israeli academic institutions".
>
> Prof Dershowitz said he had started work on legal moves to fight any
> boycott.
>
> He told the Times Higher Educational Supplement that these would
> include using a US law - banning discrimination on the basis of
> nationality - against UK universities with research ties to US
> colleges. US academics might also be urged to accept honorary posts at
> Israeli colleges in order to become boycott targets.
>
> "I will obtain legislation dealing with this issue, imposing sanctions
> that will devastate and bankrupt those who seek to impose bankruptcy
> on Israeli academics," he told the journal.
>
> Sue Blackwell, a UCU activist and member of the British Committee for
> Universities of Palestine, said: "This is the typical response of the
> Israeli lobby which will do anything to avoid debating the real issue
> - the 40-year occupation of Palestine." Jewish groups have attacked
> the UCU vote, which was opposed by Sally Hunt, its general secretary.
>
> C The Financial Times Limited 2007


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


Re: Eclipse Plugins

2007-10-26 Thread cyberco
> PyDev is open source, and the developer is pretty responsive, so if you
> could describe what is missing there is a good chance it would get
> implemented. I even fixed two bugs myself, my first ever real Java
> contribution...
>
> --
>   Heikki Toivonen

I can second that. I'm a happy PyDev user myself for any Python module
that is more than 100 lines long. The nice things is that it has a lot
of the same keybindings as the Eclipse Java editor has (duplicating
lines/blocks, organising imports, indent/dedent, etc). In cases where
PyDev needs a patch the main developer is always there to help you
out.

2B

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


Editing MS Word

2007-10-26 Thread tonylabarbara

Hi;

I'm trying to edit MS Word tables with a python script. Here's a snippet:

import string

def msw2htmlTables():

input = "/usr/home/me/test.doc"

input = open(input,'r')

word = "whatever"

inputFlag = 0

splitString = []

for line in input:

# Check first the inputFlag, since we only want to delete the top

if inputFlag == 0:

splitString = line.split(word)

try:

keep = splitString[1]

except:

keep = "nada"

print len(splitString)

inputFlag = 1

elif inputFlag == 1:

# This means we've deleted the top junk. Let's search for the bottom junk.

splitString = line.split(word)

try:

keep = splitString[0]

inputFlag = 2

print len(splitString)

except:

keep += line

elif inputFlag == 2:

# This means everything else is junk.

pass

Now, if var "word" is "orange", it will never pring the length of splitString. 
If it's "dark", it will. The only difference is the way they appear in the 
document. "orange" appears with a space character to the left and some MS 
garbage character to the right, while "dark" appears with a space character to 
the left and a comma to the right. Furthermore, if I use MSW junk characters as 
the definition of "word" (such as " Ù ", which is what I really need to 
search), it never even compiles (complains of an unpaired quote). It appears 
that python doesn't like MSW's junk characters. What shall I do?

TIA,

Tony


Email and AIM finally together. You've gotta check out free AOL Mail! - 
http://mail.aol.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: tuples within tuples

2007-10-26 Thread korovev76
On 26 Ott, 19:23, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
 > > (A,B,C,D)
> > that could be
> > ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
>
> "C" isn't a tuple in your example either. It is a one-element list
> (the single element INSIDE the list is a tuple whose third element is a
> list containing a non-terminated string -- so the entire structure is
> invalid)
>

i'm not sure what u mean with "the entire structure is invalid"...
that's exactly what I got while parsing...


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


Re: Hack request: rational numbers

2007-10-26 Thread Anton Mellit
> Hi!
>
> I am using rational numbers from the gmpy module and I find that creating
> one in Python using
>
 mpq(3,4)
>
> is rather clumsy. Clearly, minimal representation of this rational number
> is
>
>3/4
>
> but in Python this expression has different meaning.

Hi,
I am writing an interface module with the PARI library and I had the
same question. So I implemented division operator for my new type
which of course did not work if both division arguments are integers.
Say 3/4 gives zero. But I discovered very simple hack. I add the
following string to my module initialization function:

PyInt_Type.tp_as_number->nb_divide = gen_div;

Here gen_div is the function I use for division of objects of my new type.

This solution is pretty nice since I do not have to make changes into
python or interactive shell. It is even better to make a function
which would 'turn on/off' my division. It is strange that it is only
possible to do such things in C code, I cannot do it from python.

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


Re: "sem_post: Invalid argument"

2007-10-26 Thread Jonathan Gardner
On Oct 25, 2:19 pm, robert <[EMAIL PROTECTED]> wrote:
> Jonathan Gardner wrote:
> > On Oct 25, 12:56 pm, robert <[EMAIL PROTECTED]> wrote:
> >> On a server the binary (red hat) installed python2.4 and also a
> >> fresh compiled python2.5 spits "sem_post: Invalid argument".
> >> What is this and how can this solved?
> >> ...
> >> Python 2.4.3 (#1, Jun  6 2006, 21:10:41)
> >> [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-54)] on linux2
> >> ...
> >> server [~]# uname -a
> >> Linux server 2.4.34.1-p4-smp-bigmem-JWH #1 SMP Mon Mar 19 03:26:57
> >> JST 2007 i686 i686 i386 GNU/Linux
>
> > Are you sure you have compatible binaries? Or did you install a random
> > RPM without checking for dependencies?
>
> Should be compatible - but I am not sure if the kernel was
> recompiled on this machine. And at least the fresh ./configure'ed
> and compiled py2.5, which yields the same problem, should be
> maximum compatible. Maybe because this machine is a "smp-bigmem" ..
>

At this point, I would start digging into the error messages
themselves. Maybe a shout out to the developers of whatever code is
generating that error message. When you understand under what
conditions that error message is thrown, perhaps it will yield some
insight into what python is doing differently than everything else.

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


Re: how to/help installing impure packages

2007-10-26 Thread Jonathan Gardner
On Oct 26, 10:35 am, owl <[EMAIL PROTECTED]> wrote:
> I love easy_install.
>
> I love watching it search and complete.
> It's when it doesn't complete that causes me grief.
> I don't program a lot these days and am relatively new to python but I
> often wind up installing packages on both unix and windows machines
> and often the 'build' part of the install fails with not being able to
> find the compiler or compile problems.
>
> If there are any articles/pointers that talk about this, i.e. how to
> troubleshoot, I'd love to know.
>
> If I was writing such an article I'd start with:
> - how easy_install uses distutils (even this is an assumption on my
> part)
> - where it looks in the env. for stuff on both unix/linux/windows
> - what files to tweak to help it find stuff if your env. is different.
> - i.e. can I config some file to have packages not try and compile but
> use pure python if possible?
> - i.e. w/o speedups
> - how to work around problems such as easy_install failing because a
> site is down
> - i.e. how to manually download, 'unpack' & 'build'
> - since packages fail to build, how to set things up to download &
> keep things around when they fail so you can tinker with it until you
> get it working!

I would enjoy seeing an article like this as well.

However, in the meantime, feel free to report your error messages to
the authors of the modules in question or even here. I am sure someone
would be willing to give some advice. At the very least, they need to
know that all is not perfect out in user-land.

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


Re: tuples within tuples

2007-10-26 Thread Michael L Torrie
[EMAIL PROTECTED] wrote:
> On 26 Ott, 19:23, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>  > > (A,B,C,D)
>>> that could be
>>> ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
>> "C" isn't a tuple in your example either. It is a one-element list
>> (the single element INSIDE the list is a tuple whose third element is a
>> list containing a non-terminated string -- so the entire structure is
>> invalid)
>>
> 
> i'm not sure what u mean with "the entire structure is invalid"...
> that's exactly what I got while parsing...

Your structure is correct.  Dennis just didn't read all the matching
parens and brackets properly.

> 
> 


-- 
Michael Torrie
Assistant CSR, System Administrator
Chemistry and Biochemistry Department
Brigham Young University
Provo, UT 84602
+1.801.422.5771

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


Re: how to/help installing impure packages

2007-10-26 Thread kyosohma
On Oct 26, 12:35 pm, owl <[EMAIL PROTECTED]> wrote:
> I love easy_install.
>
> I love watching it search and complete.
> It's when it doesn't complete that causes me grief.
> I don't program a lot these days and am relatively new to python but I
> often wind up installing packages on both unix and windows machines
> and often the 'build' part of the install fails with not being able to
> find the compiler or compile problems.
>
> If there are any articles/pointers that talk about this, i.e. how to
> troubleshoot, I'd love to know.
>
> If I was writing such an article I'd start with:
> - how easy_install uses distutils (even this is an assumption on my
> part)
> - where it looks in the env. for stuff on both unix/linux/windows
> - what files to tweak to help it find stuff if your env. is different.
> - i.e. can I config some file to have packages not try and compile but
> use pure python if possible?
> - i.e. w/o speedups
> - how to work around problems such as easy_install failing because a
> site is down
> - i.e. how to manually download, 'unpack' & 'build'
> - since packages fail to build, how to set things up to download &
> keep things around when they fail so you can tinker with it until you
> get it working!
>
> I love python, and nothing against impure packages, but when they
> cause problems it starts to 'tarnish the dream' of an agnostic
> language.
>
> Thoughts?

You can check out the "official" website on Easy Install:

http://peak.telecommunity.com/DevCenter/EasyInstall

More informative links follow:

http://www.ibm.com/developerworks/linux/library/l-cppeak3.html
http://wiki.vpslink.com/index.php?title=Python_easy_install
http://gnosis.cx/publish/programming/charming_python_b23.html

As for doing your own compiling, I have some instructions for using
the open source compiler, MinGW, on my website: 
http://www.pythonlibrary.org/distribution.htm

I should research this and add it to the page. But if you come up with
any tips or tricks, let me know and I'll put them on there.

Mike

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


Re: tuples within tuples

2007-10-26 Thread Stargaming
On Fri, 26 Oct 2007 14:26:24 -0600, Michael L Torrie wrote:

> [EMAIL PROTECTED] wrote:
[snip]
 ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
   ^
Syntax error behind ``'bobloblaw``.

>>> "C" isn't a tuple in your example either. It is a one-element
>>> list
>>> (the single element INSIDE the list is a tuple whose third element is
>>> a list containing a non-terminated string -- so the entire structure
>>> is invalid)
>>>
>>>
>> i'm not sure what u mean with "the entire structure is invalid"...
>> that's exactly what I got while parsing...
> 
> Your structure is correct.  Dennis just didn't read all the matching
> parens and brackets properly.

He certainly is -- *you* are misreading *him*. The nit he's picking is 
the non-terminated string (quotation mark/apostrophe missing).

Nit-picking'ly,
Stargaming
-- 
http://mail.python.org/mailman/listinfo/python-list


Going past the float size limits?

2007-10-26 Thread jimmy . musselwhite
Hello all
It would be great if I could make a number that can go beyond current
size limitations. Is there any sort of external library that can have
infinitely huge numbers? Way way way way beyond say 5x10^350 or
whatever it is?

I'm hitting that "inf" boundary rather fast and I can't seem to work
around it.

Thanks!

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


Re: Python Windows Installation

2007-10-26 Thread Fuzzyman
On Oct 25, 6:36 pm, TheFlyingDutchman <[EMAIL PROTECTED]> wrote:
> On Oct 24, 11:22 pm, Tim Roberts <[EMAIL PROTECTED]> wrote:
>
> > TheFlyingDutchman <[EMAIL PROTECTED]> wrote:
>
> > >I am trying to install Python 2.5 on Windows XP. It installs into the
> > >root directory on C:\ instead of C:\Python25 which it shows by default
> > >as what it plans to install to. Selecting D:\Python25 on a previous
> > >iteration put the exe in D:\ and did not create a Python25 directory.
>
> > Where did you get the installer?  I've installed Python on Windows many,
> > many times, and have never seen this issue.
> > --
> > Tim Roberts, [EMAIL PROTECTED]
> > Providenza & Boekelheide, Inc.
>
> from python.org.   I doubt many people get this or it would be fixed
> but it still is shocking how it can prompt me that the installation
> directory exists - showing that it fully knows where it is supposed to
> install it - and then go ahead and install it to the root directory
> and claim success. It also uninstalls Python if you ask it to so any
> screwy settings from a previous install should be removed after the
> uninstall, but it also fails to install correctly after an uninstall.

I've never had this problem with the Python.org windows installer.

However I did once use a machine where Python had been installed into
'c:\Program Files\Python24'. It caused no end of problems...

Michael Foord
http://www.manning.com/foord

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


Re: renice

2007-10-26 Thread Carl Banks
On Oct 26, 12:46 pm, Dan <[EMAIL PROTECTED]> wrote:
> On Oct 26, 4:30 am, mokhtar <[EMAIL PROTECTED]> wrote:
>
> > Hi
>
> > Is it possible to renice the python process executing the current python
> > script ?:confused:
> > --
> > View this message in 
> > context:http://www.nabble.com/renice-tf4695834.html#a13422771
> > Sent from the Python - python-list mailing list archive at Nabble.com.
>
> On UNIX:>>> import os
> >>> os.system("renice -n %d %d" % ( new_nice, os.getpid() ) )


Hmm.  That seems to be the hard way, since you can set the nice value
of the current process (almost) directly:

import os
nice_adder = new_nice - os.nice(0)
os.nice(nice_adder)


But I suppose it could be useful in situations where you need
privleges you don't currently have. E.g.:

os.system("sudo renice -n %s %s" % (new_nice, os.getpid()))


Carl Banks


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


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread Matimus
> - Traling characters at the end of a literal are already used (the L
>   for long).

The trailing L is going away in Python 3.0. For your consideration may
I suggest a '$' prefix. Though, I'm not sure I even support the idea
of a decimal literal, and I'm not even sure if I support the idea of
using a prefix '$' to identify that literal, it seems somewhat
fitting.

So...
Decimal("12.34") -> $12.34

Pros:
 - Easier to see than appended character (I think)
 - Notation is fitting when dealing with monetary values
 - Easy to remember
Cons:
 - Maybe too clever for its own good. Some people may be confused to
find out that it isn't actually a monetary type.

I'm sure there are more...

Matt


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


The Comprehensive History of Zionists (VERY THOROUGH and SUCCINCT VIDEO TUTORIAL)

2007-10-26 Thread thermate2
The Comprehensive History of Zionists (VERY THOROUGH and SUCCINCT
VIDEO TUTORIAL)

http://www.youtube.com/watch?v=YTkluxTOXzQ


On Oct 26, 11:55 am, [EMAIL PROTECTED] wrote:
> Hour long RARE video of the Great Rabbis, Unfortunately, the sound is
> poor quality.
>
> http://www.youtube.com/watch?v=3dSHl3C9kgYhttp://www.youtube.com/watch?v=jOVJr-ATnOw
>
> On Oct 26, 11:37 am, [EMAIL PROTECTED] wrote:
>
> >http://www.ft.com/cms/s/0/56cb5b92-10a7-11dc-96d3-000b5df10621.html?n...
>
> > Harvard legal expert vows to sue lecturers boycotting Israel
>
> > By Jon Boone
>
> > Published: June 2 2007 03:00
>
> > A top American lawyer has threatened to wage a legal war against
> > British academics who seek to cut links with Israeli universities.
>
> > Alan Dershowitz, a Harvard law professor renowned for his staunch
> > defence of Israel and high-profile legal victories, including his role
> > in the O.J. Simpson trial, vowed to "devastate and bankrupt" lecturers
> > who supported such boycotts.
>
> > This week's annual conference of Britain's biggest lecturers' union,
> > the University and College Union, backed a motion damning the
> > "complicity of Israeli academia in the occupation [of Palestinian
> > land]".
>
> > It also obliged the union's executive to encourage members to
> > "consider the moral implications of existing and proposed links with
> > Israeli academic institutions".
>
> > Prof Dershowitz said he had started work on legal moves to fight any
> > boycott.
>
> > He told the Times Higher Educational Supplement that these would
> > include using a US law - banning discrimination on the basis of
> > nationality - against UK universities with research ties to US
> > colleges. US academics might also be urged to accept honorary posts at
> > Israeli colleges in order to become boycott targets.
>
> > "I will obtain legislation dealing with this issue, imposing sanctions
> > that will devastate and bankrupt those who seek to impose bankruptcy
> > on Israeli academics," he told the journal.
>
> > Sue Blackwell, a UCU activist and member of the British Committee for
> > Universities of Palestine, said: "This is the typical response of the
> > Israeli lobby which will do anything to avoid debating the real issue
> > - the 40-year occupation of Palestine." Jewish groups have attacked
> > the UCU vote, which was opposed by Sally Hunt, its general secretary.
>
> > C The Financial Times Limited 2007


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


Re: Going past the float size limits?

2007-10-26 Thread Chris Mellon
On 10/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello all
> It would be great if I could make a number that can go beyond current
> size limitations. Is there any sort of external library that can have
> infinitely huge numbers? Way way way way beyond say 5x10^350 or
> whatever it is?
>
> I'm hitting that "inf" boundary rather fast and I can't seem to work
> around it.
>

What in the world are you trying to count?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Going past the float size limits?

2007-10-26 Thread Guilherme Polo
2007/10/26, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> Hello all
> It would be great if I could make a number that can go beyond current
> size limitations. Is there any sort of external library that can have
> infinitely huge numbers? Way way way way beyond say 5x10^350 or
> whatever it is?

Check the decimal module

>
> I'm hitting that "inf" boundary rather fast and I can't seem to work
> around it.
>
> Thanks!
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Going past the float size limits?

2007-10-26 Thread J. Cliff Dyer
[EMAIL PROTECTED] wrote:
> Hello all
> It would be great if I could make a number that can go beyond current
> size limitations. Is there any sort of external library that can have
> infinitely huge numbers? Way way way way beyond say 5x10^350 or
> whatever it is?
>
> I'm hitting that "inf" boundary rather fast and I can't seem to work
> around it.
>
> Thanks!
>
>   
hmm.

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32

>>> 5 * (10 ** 700)
5
0
0
0
0
0
0
0
0
0
000L


Do you really need more than 700 places of precision?  Once your numbers
are that large, surely you can use integer math, right? (FYI 5 * (10 **
1) works just as well.

Cheers,
Cliff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Going past the float size limits?

2007-10-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hello all
> It would be great if I could make a number that can go beyond current
> size limitations. Is there any sort of external library that can have
> infinitely huge numbers? Way way way way beyond say 5x10^350 or
> whatever it is?
> 
> I'm hitting that "inf" boundary rather fast and I can't seem to work
> around it.

http://gmpy.sourceforge.net/

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


Re: Going past the float size limits?

2007-10-26 Thread Matt McCredie
> It would be great if I could make a number that can go beyond current
> size limitations. Is there any sort of external library that can have
> infinitely huge numbers? Way way way way beyond say 5x10^350 or
> whatever it is?
>
> I'm hitting that "inf" boundary rather fast and I can't seem to work
> around it.


You have a couple of options.
1. Use long if that is appropriate for your data, they can be as large
as you want (eventually you will reach memory constraints, but that
isn't likely)
2. There is a decimal type, which is based on long (I think) and can
have a decimal portion.

to use longs:
x = 5 * 10**350

to use decimal:
import decimal
x = decimal.Decimal("5e350")

You will probably want to read up on  the decimal module.

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


Re: Python Windows Installation

2007-10-26 Thread Bjoern Schliessmann
Fuzzyman wrote:

> However I did once use a machine where Python had been installed
> into 'c:\Program Files\Python24'. It caused no end of problems...

What, "it"? The machine or the folder? What kinds of problems?

Regards,


Björn

-- 
BOFH excuse #170:

popper unable to process jumbo kernel

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


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread Ben Finney
Matimus <[EMAIL PROTECTED]> writes:

> The trailing L [for 'long' literals] is going away in Python 3.0.

Yes. On the other hand, we are gaining '0b' for binary literals,
to go along with '0o' for octal and '0x' for hexadecimal.

So, the original poster might get further by proposing an '0dNNN.NNN'
syntax for 'decimal.Decimal' literals. At least the syntax would be
consistent and wouldn't add a new punctuation character to the
language...

> For your consideration may I suggest a '$' prefix.

... unlike this one.

-- 
 \ "The illiterate of the future will not be the person who cannot |
  `\ read. It will be the person who does not know how to learn."  |
_o__) -- Alvin Toffler |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread J. Cliff Dyer
Matimus wrote:
>> - Traling characters at the end of a literal are already used (the L
>>   for long).
>> 
>
> The trailing L is going away in Python 3.0. For your consideration may
> I suggest a '$' prefix. Though, I'm not sure I even support the idea
> of a decimal literal, and I'm not even sure if I support the idea of
> using a prefix '$' to identify that literal, it seems somewhat
> fitting.
>
> So...
> Decimal("12.34") -> $12.34
>
> Pros:
>  - Easier to see than appended character (I think)
>  - Notation is fitting when dealing with monetary values
>  - Easy to remember
> Cons:
>  - Maybe too clever for its own good. Some people may be confused to
> find out that it isn't actually a monetary type.
> I'm sure there are more...
>   
- Too U.S. centric.  Euro would be a slight improvement, as it doesn't
privilege one country, but still too region-centric.  Generic currency
marker from ISO 8859-1 would be even less unnecessarily specific, but
also too obscure.
- Looks funny if you use more or fewer than 2 decimal places. 
- Sacrifices clarity of meaning for brevity.
>   
> Matt
My only problem with Decimal("12.34") is the quotation marks.  It makes
it look like a string type.

Cheers,
Cliff

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


Re: Proposal: Decimal literals in Python.

2007-10-26 Thread J. Cliff Dyer
Ben Finney wrote:
> Matimus <[EMAIL PROTECTED]> writes:
>
>   
>> The trailing L [for 'long' literals] is going away in Python 3.0.
>> 
>
> Yes. On the other hand, we are gaining '0b' for binary literals,
> to go along with '0o' for octal and '0x' for hexadecimal.
>
> So, the original poster might get further by proposing an '0dNNN.NNN'
> syntax for 'decimal.Decimal' literals. 
It would rather be remarkably inconsistent and confusing. 

Python 3.0a1 (py3k:57844, Aug 31 2007, 16:54:27) [MSC v.1310 32 bit
(Intel)] on win32

>>> type(0b1)

>>> type(0o1)

>>> type(0x1)

>>> assert 0b1 is 0x1
>>>


>>> type(0d1)

>>> assert 0b1 is 0d1
Traceback (most recent call last):
  File "", line 1, in 
assert 0b1 is 0d1
AssertionError



It would also be unkind to people with dyslexia.

Cheers,
Cliff

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


Re: Going past the float size limits?

2007-10-26 Thread jimmy . musselwhite
On Oct 26, 6:56 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 10/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > Hello all
> > It would be great if I could make a number that can go beyond current
> > size limitations. Is there any sort of external library that can have
> > infinitely huge numbers? Way way way way beyond say 5x10^350 or
> > whatever it is?
>
> > I'm hitting that "inf" boundary rather fast and I can't seem to work
> > around it.
>
> What in the world are you trying to count?

The calculation looks like this

A = 0.35
T = 0.30
C = 0.25
G = 0.10

and then I basically continually multiply those numbers together. I
need to do it like 200,000+ times but that's nuts. I can't even do it
1000 times or the number rounds off to 0.0. I tried taking the inverse
of these numbers as I go but then it just shoots up to "inf".

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


911 Was a Zionist Job, feel the sadism of the zionists, people tumbling down from the top

2007-10-26 Thread thermate2
911 was a zionist job video
http://www.youtube.com/watch?v=D6PErp5TBpM

On Oct 26, 3:50 pm, [EMAIL PROTECTED] wrote:
> The Comprehensive History of Zionists (VERY THOROUGH and SUCCINCT
> VIDEO TUTORIAL)
>
> http://www.youtube.com/watch?v=YTkluxTOXzQ
>
> On Oct 26, 11:55 am, [EMAIL PROTECTED] wrote:
>
> > Hour long RARE video of the Great Rabbis, Unfortunately, the sound is
> > poor quality.
>
> >http://www.youtube.com/watch?v=3dSHl3C9kgYhttp://www.youtube.com/watc...
>
> > On Oct 26, 11:37 am, [EMAIL PROTECTED] wrote:
>
> > >http://www.ft.com/cms/s/0/56cb5b92-10a7-11dc-96d3-000b5df10621.html?n...
>
> > > Harvard legal expert vows to sue lecturers boycotting Israel
>
> > > By Jon Boone
>
> > > Published: June 2 2007 03:00
>
> > > A top American lawyer has threatened to wage a legal war against
> > > British academics who seek to cut links with Israeli universities.
>
> > > Alan Dershowitz, a Harvard law professor renowned for his staunch
> > > defence of Israel and high-profile legal victories, including his role
> > > in the O.J. Simpson trial, vowed to "devastate and bankrupt" lecturers
> > > who supported such boycotts.
>
> > > This week's annual conference of Britain's biggest lecturers' union,
> > > the University and College Union, backed a motion damning the
> > > "complicity of Israeli academia in the occupation [of Palestinian
> > > land]".
>
> > > It also obliged the union's executive to encourage members to
> > > "consider the moral implications of existing and proposed links with
> > > Israeli academic institutions".
>
> > > Prof Dershowitz said he had started work on legal moves to fight any
> > > boycott.
>
> > > He told the Times Higher Educational Supplement that these would
> > > include using a US law - banning discrimination on the basis of
> > > nationality - against UK universities with research ties to US
> > > colleges. US academics might also be urged to accept honorary posts at
> > > Israeli colleges in order to become boycott targets.
>
> > > "I will obtain legislation dealing with this issue, imposing sanctions
> > > that will devastate and bankrupt those who seek to impose bankruptcy
> > > on Israeli academics," he told the journal.
>
> > > Sue Blackwell, a UCU activist and member of the British Committee for
> > > Universities of Palestine, said: "This is the typical response of the
> > > Israeli lobby which will do anything to avoid debating the real issue
> > > - the 40-year occupation of Palestine." Jewish groups have attacked
> > > the UCU vote, which was opposed by Sally Hunt, its general secretary.
>
> > > C The Financial Times Limited 2007


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


Re: Going past the float size limits?

2007-10-26 Thread Stéphane Larouche
  gmail.com> writes:

> The calculation looks like this
> 
> A = 0.35
> T = 0.30
> C = 0.25
> G = 0.10
> 
> and then I basically continually multiply those numbers together. I
> need to do it like 200,000+ times but that's nuts. I can't even do it
> 1000 times or the number rounds off to 0.0. I tried taking the inverse
> of these numbers as I go but then it just shoots up to "inf".

I suggest you add the logarithm of those numbers.

Stéphane

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

Re: Going past the float size limits?

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

> The calculation looks like this
>
> A = 0.35
> T = 0.30
> C = 0.25
> G = 0.10
>
> and then I basically continually multiply those numbers together. I
> need to do it like 200,000+ times but that's nuts. I can't even do it
> 1000 times or the number rounds off to 0.0. I tried taking the inverse
> of these numbers as I go but then it just shoots up to "inf".

>>> import gmpy
>>> A = gmpy.mpf('0.35')
>>> B = gmpy.mpf('0.30')
>>> C = gmpy.mpf('0.25')
>>> D = gmpy.mpf('0.10')
>>> result = gmpy.mpf(1)
>>> for n in xrange(20):
...   result *= A
...   result *= B
...   result *= C
...   result *= D
...
>>> result
mpf('7.27023409768722186651e-516175')

It's reasonably fast, too.  The above loop took a fraction of a second
to run on an oldish computer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Going past the float size limits?

2007-10-26 Thread Grant Edwards
On 2007-10-26, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>> What in the world are you trying to count?
>
> The calculation looks like this
>
> A = 0.35
> T = 0.30
> C = 0.25
> G = 0.10

The bases in DNA?

> and then I basically continually multiply those numbers together. I
> need to do it like 200,000+ times but that's nuts.

Exactly.  It sure looks like what you're doing is nuts.

> I can't even do it 1000 times or the number rounds off to 0.0.
> I tried taking the inverse of these numbers as I go but then
> it just shoots up to "inf".

Can you explain what it is you're trying to calculate?

-- 
Grant Edwards
[EMAIL PROTECTED]

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


Re: Going past the float size limits?

2007-10-26 Thread jimmy . musselwhite
On Oct 26, 8:03 pm, Stéphane Larouche <[EMAIL PROTECTED]>
wrote:
>   gmail.com> writes:
>
> > The calculation looks like this
>
> > A = 0.35
> > T = 0.30
> > C = 0.25
> > G = 0.10
>
> > and then I basically continually multiply those numbers together. I
> > need to do it like 200,000+ times but that's nuts. I can't even do it
> > 1000 times or the number rounds off to 0.0. I tried taking the inverse
> > of these numbers as I go but then it just shoots up to "inf".
>
> I suggest you add the logarithm of those numbers.
>
> Stéphane

Well I'd add the logarithms if it was me that made the algorithm. I
don't think I understand it all that well. My professor wrote it out
and I don't want to veer away and add the logs of the values because I
don't know if that's the same thing or not.

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

Re: Good Book

2007-10-26 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>The Python Cookbook would probably be another good resource. While I
>don't like the Dummies series' name, the Python Dummies book is a good
>introduction, although it doesn't have enough examples, in my opinion.

Could you explain what examples you would have liked more of in _Python
for Dummies_?
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Going past the float size limits?

2007-10-26 Thread [EMAIL PROTECTED]
On Oct 26, 6:29 pm, [EMAIL PROTECTED] wrote:
> On Oct 26, 6:56 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
>
> > On 10/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > Hello all
> > > It would be great if I could make a number that can go beyond current
> > > size limitations. Is there any sort of external library that can have
> > > infinitely huge numbers? Way way way way beyond say 5x10^350 or
> > > whatever it is?
>
> > > I'm hitting that "inf" boundary rather fast and I can't seem to work
> > > around it.
>
> > What in the world are you trying to count?
>
> The calculation looks like this
>
> A = 0.35
> T = 0.30
> C = 0.25
> G = 0.10
>
> and then I basically continually multiply those numbers together. I
> need to do it like 200,000+ times but that's nuts. I can't even do it
> 1000 times or the number rounds off to 0.0. I tried taking the inverse
> of these numbers as I go but then it just shoots up to "inf".

As mentioned elsewhere, gmpy is a possible solution. You can do
the calculations with unlimited precision rationals without
introducing any rounding errors and then convert the final
answer to unlimited precision floating point without ever
hitting 0 or inf:

>>> import gmpy
>>> A = gmpy.mpq(35,100)
>>> b = A**20
>>> c = gmpy.mpf(b)
>>> gmpy.fdigits(c)
'4.06321735803245162316e-91187'

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


  1   2   >