itools 0.20.2 released

2008-01-05 Thread J. David Ibáñez

itools is a Python library, it groups a number of packages into a single
meta-package for easier development and deployment:

  itools.catalog  itools.i18n itools.uri
  itools.csv  itools.ical itools.vfs
  itools.datatypesitools.odf  itools.web
  itools.gettext  itools.pdf  itools.workflow
  itools.git  itools.rest itools.xliff
  itools.handlers itools.rss  itools.xml
  itools.html itools.stl
  itools.http itools.tmx

This release brings a couple API enhancements.

The context.check_form_input method from itools.web has been improved.
Before it just tested whether the input data was valid or not; now, if
everything is fine, it returns the deserialized values.

The Catalog.get_unique_values method has been added to the programming
interface of the IndexSearch engine.  It returns all the values stored
in the catalog for a given field.


Resources
-

Download
http://download.ikaaro.org/itools/itools-0.20.2.tar.gz
http://download.ikaaro.org/itools/itools-0.20.2.win32-py2.5.exe
http://download.ikaaro.org/itools/itools-0.20.2.win32-py2.4.exe

Home
http://www.ikaaro.org/itools

Mailing list
http://mail.ikaaro.org/mailman/listinfo/itools

Bug Tracker
http://bugs.ikaaro.org/



-- 
J. David Ibáñez
Itaapy http://www.itaapy.com Tel +33 (0)1 42 23 67 45
9 rue Darwin, 75018 Paris  Fax +33 (0)1 53 28 27 88
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Request for loading zipped modules in some context

2008-01-05 Thread Kay Schluehr
When trying to import a module from a filesystem directory there are
several possibilities. Most obviously one can use an import statement
but if this is not sufficient one has also API functions. However
these API functions don't seem to be consistent with each other.

If one uses the builtin __import__ function one can import the module
in some context i.e. one can pass locals and globals:

__import__( name[, globals[, locals[, fromlist[, level)

If one uses the imp module instead one has several different
possibilities to load a module ( load_source, load_compiled ) but none
of them imports the module in some context.

The situation becomes worse when using zipimport. The zipimport module
provides methods get_code and load_module.

 import zipimport
 importer = zipimport.zipimporter(myziparchive.zip)
 mod = importer.load_module(mymodule)
 mod
module 'mymodule' from 'myziparchive.zip\mymodule.py'

Using load_module returns a module object. One cannot initialize the
module in some context though. One can also use get_code and use a
code object:

 mod_code = importer.get_code(mymodule)
 mod_code
code object module at 00B05260, file myziparchive.zip
\mymodule.py, line 1
 eval(mod_code, locals(), globals())


One can evaluate the code object but this won't give you much. It
won't magically transform the code object into a module object being
returned and cached. Creating a module object from a code object isn't
possible AFAIK. The get_code method doesn't seem to be particular
usefull.

I'd like to see things being made more uniform - but uniform in the
sense of providing the most powerfull options all over the place.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mail

2008-01-05 Thread Steven D'Aprano
On Fri, 04 Jan 2008 23:03:15 -0800, sanjeet wrote:

 hi all,
  I am facing problem to fetch mail from internet mail server. Plz help
 me, how can do this?


Yes.

Everything you need to know to fix your problem can be found here:
www.catb.org/~esr/faqs/smart-questions.html


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


hello world

2008-01-05 Thread [EMAIL PROTECTED]
log on to

http://profiles.friendster.com/58431435
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import zlib in 2.5 fails

2008-01-05 Thread stuntgoat
I was able to recompile zlib

$./configure --shared

then recompile Python 2.5.1; I am now able to import the zlib module.

cheers

-sg

I was able to recompile zlib

$./configure --shared

then recompile Python 2.5.1; I am now able to import the zlib module.

cheers

-sg



On Jan 4, 5:17 pm, Zentrader [EMAIL PROTECTED] wrote:
 On Jan 4, 2:19 am, stuntgoat [EMAIL PROTECTED] wrote:

  import zlib works in Python 2.4 (debian etch AMD64 - default python
  version for that distro)

  I built python 2.5 from source; zlib is not importable.

 2.5 has been available for some time in the Debian repositories.
 Installing the .deb may provide better results.  Note that you might
 also have to upgrade the dependencies to a newer version.  apt-get
 will do all of this for you - man apt-get for all of the 
 details.http://packages.debian.org/etch/python2.5

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


Re: How a smart editor could make Postfix type declarations PEP3117 in Python3000 more readable

2008-01-05 Thread aspineux
On Jan 5, 4:39 am, aspineux [EMAIL PROTECTED] wrote:
 Hi

 I read the PEP 3117 about the new Postfix type declarations  in
 Python3000.
 THIS PEP as been REJECTED ! But ...

 The notation in the PEP is very ugly !  This make python code more
 difficult to read!

 Anyway when I switched to python (from C, C++, ..), I suffered a lot
 of the
 untyped python variables. And I think this is a good idea to include
 typing in python.

 Then I get this idea: The editor could hide the typing notation, just
 displaying hint !
 It could also auto-complete the type of any variable having already a
 type in
 the current function, and underline untyped variable or variable
 having multiple type inside the function.

 Just an idea !

And to go further the editor could do all the job of type checking,
using formatted comment to specify type, like in some existing
embedded documentation.


But then we are losing the brevity provided by the PEP.


Pydev (and certainly other) already does some interesting work to find
mistyped
(typed like in I made a typo) variable name.

TO ALL NEW IDEA RESISTANT :

Hopefully, in 1990 nobody said to someone that inventing a language
where bloc definition
is based on indentation was a s


Regards


 Alain Spineux

 Happy new year.

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


Re: Details about pythons set implementation

2008-01-05 Thread r . grimm
On Jan 4, 6:08 pm, Sion Arrowsmith [EMAIL PROTECTED]
wrote:
 Hrvoje Niksic  [EMAIL PROTECTED] wrote:

 BTW if you're using C++, why not simply use std::set?

 Because ... how to be polite about this? No, I can't. std::set is
 crap. The implementation is a sorted sequence -- if you're lucky,
 this is a heap or a C array, and you've got O(log n) performance.
 But the real killer is that requirement for a std::setT is that
 T::operator exists. Which means, for instance, that you can't
 have a set of complex numbers

 --

Hallo and Sorry for being OT.
As Arnaud pointed out, you must only overload the   Operator for the
requested type.
Something like
bool operator  ( const Type fir, const Type sec )
similar to python with __lt__ .
The rest of magic will be  done  by the  compiler/interpreter.
Assoziative Arrays (set,map,multi_set,multi_map) in the classical STL
are implemented as binary trees. Therefore the keys must be comparable
and the access time is O(log n ).
To get a dictionary with O(1), the most  STL implementation support a
extension called hash_set.
The new standard TR1 support unsorted_set ... . You can download it
from www.boost.org. Newer gcc runtimes also including the new
subnamespace tr1.
There is no need to implement set in c++ to get O(1).


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


Re: Fortran to Python

2008-01-05 Thread MartinRinehart


Jeroen Ruigrok van der Werven wrote:
 I got someone who asked me to make changes in an old Fortran program she is
 using for some calculations.

Why convert? Modern Fortran is an object oriented, structured language
with the singular advantage that it can run old Fortran programs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread caca

 Caching might help.

 If random_pick is called several times with the same list(s) then
 cache the result of
  [property(i) for i in a_list] against a_list.

 If random_pick is called several times with list(s) with multiple
 instances of list items then cache
  property(i) against i for i in a_list .

 You could do both.

 You might investigate wether property(i) could be implemented using a
 faster algorithm, maybe table lookup, or interpolation from initial
 table lookup.

 - Paddy.

Thanks, Paddy. Those are interesting general comments for the general
problem.
By the way, I noticed two things:

I forgot to write randint in the third approach:

  a=globalRNG.randint(1,len(a_list))

The warning The group you are posting to is a Usenet group. Messages
posted to this group will make your email address visible to anyone on
the Internet. means a person, but not a bot, may see my email
address, so it is safe to use my real address next time...

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


Re: cloud computing (and python)?

2008-01-05 Thread Lie
 I mean, really, I've been using web-mail and various varieties of
 remote
 storage for over a decade.  What is *new* about the concept?  (I see
 some
 hints above, but it's mixed in with a lot of other stuff...)

In essence, you're correct, this concept of cloud computing actually
have existed for some time, but there is a difference between the
classic cloud computing and new cloud computing. The classic cloud
computing is rather limited emails, bbs, newsgroup, etc while the new
cloud computing also refers to the newly available scope such as word
processing, image processing, and even video editing.

In essence they're the same, you store your files on their server, and
you used a webbased tools to access your file, but nowadays people
wouldn't consider the classic cloud computing a cloud computing
anymore, as they've become too normal.

It's not a completely meaningless marketing buzz phrase, the concept
has existed for some time, but the word is new.

Another way to look at this is: classic cloud computing are cloud
computing that is done because it can't be done the other way (what
use is an email address if you could only receive emails if your
desktop is always on, what use is a newsgroup if people could only
post if they are physically in front of the computer hosting the
newsgroup). While the new cloud computing refers to applications
that previously exist as desktop applications, but now ported to
become web-based applications, meaning the application could be usable
without the cloud, but some features like universal availability
could not be used.
-- 
http://mail.python.org/mailman/listinfo/python-list


Basic inheritance question

2008-01-05 Thread MartinRinehart
Working on parser for my language, I see that all classes (Token,
Production, Statement, ...) have one thing in common. They all
maintain start and stop positions in the source text. So it seems
logical to have them all inherit from a base class that defines those,
but this doesn't work:

import tok

class code:
def __init__( self, start, stop ):
startLoc = start
stopLoc = stop

class token(code):
pass

x = token( tok.Loc(0, 0), tok.Loc(3, 4) )

print x.startLoc.repr(), x.stopLoc.repr()

AttributeError: token instance has no attribute 'startLoc'

1) Is my design thinking good, or hopelessly unPythonic?

2) If it's good, how do you access base class data attributes? (The
doc is rich in method access info, impoverished when it comes to other
attributes.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fortran to Python

2008-01-05 Thread Jeroen Ruigrok van der Werven
-On [20080105 11:21], [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
Why convert? Modern Fortran is an object oriented, structured language
with the singular advantage that it can run old Fortran programs.

With all due respect to Fortran but I find the syntax to be utterly
horrendous. :)

Furthermore, the code is not really heavy number crunching in that it seems to
warrant explicit use in Fortran. At most it takes about 2 seconds on a current
day PC to calculate some of these values.

Furthermore it currently has a dependency on the Visual Numerics IMSL library.
For just some calculations to warrant the cost of both this library and a
Fortran compiler seems a bit excessive.

Given we use Matlab in-house, next to C# (and perhaps F# in the future), and
some Python it makes more sense to stick to your domain-specific knowledge
rather than maintaining some relic from the past.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
For ever, brother, hail and farewell...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Basic inheritance question

2008-01-05 Thread Jeroen Ruigrok van der Werven
-On [20080105 11:36], [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
class code:
def __init__( self, start, stop ):
startLoc = start
stopLoc = stop

Shouldn't this be:

self.startLoc = start
self.stopLoc = stop

?

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Open your Heart and push the limits...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Basic inheritance question

2008-01-05 Thread Paul Hankin
On Jan 5, 10:31 am, [EMAIL PROTECTED] wrote:
 ...
 class code:
     def __init__( self, start, stop ):
         startLoc = start
         stopLoc = stop
 ...

You've forgotten the explicit self.
 def __init__( self, start, stop ):
 self.startLoc = start
 self.stopLoc = stop

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


Re: Basic inheritance question

2008-01-05 Thread MartinRinehart


Jeroen Ruigrok van der Werven wrote:
 Shouldn't this be:

 self.startLoc = start
 self.stopLoc = stop

Thanks! Of course it should. Old Java habits die slowly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory Leaks and Heapy

2008-01-05 Thread Andrew MacIntyre
Yaakov Nemoy wrote:

 A couple of developers have mentioned that python might be fragmenting
 its memory space, and is unable to free up those pages.  How can I go
 about testing for this, and are there any known problems like this?
 If not, what else can I do to look for leaks?

Marc-Andre brought up pymalloc, but it is worth clarifying a couple of
issues related to its use:
- pymalloc only manages allocations up to (and including) 256 bytes;
   allocations larger than this are passed to the platform malloc to
   allocate.
- the work that was put in to allow return of empty arenas (in Python
   2.5) was geared to handling the general case of applications that
   created huge volumes of objects (usually at start up) and then destroy
   most of them.  There is no support that I'm aware of for any form of
   arena rationalisation in the case of sparsely occupied arenas.
- it has been my experience that pymalloc is a significant benefit over
   the platform malloc for the Python interpreter, both in terms of
   performance and gross memory consumption.  Prior to defaulting to
   using pymalloc (as of 2.3) CPython had run into issues with the
   platform malloc of just about every platform it had been ported to,
   heap fragmentation being particularly notable on Windows (though other
   platforms have also been subject to this).

While pymalloc is highly tuned for the general case behaviour of the
Python interpreter, just as platform malloc implementations have corner
cases so does pymalloc.

Be aware that ints and floats are managed via free lists with
memory allocation directly by the platform malloc() - these objects
are never seen by pymalloc, and neither type has support for
relinquishing surplus memory.  Be also aware that many C extensions
don't use pymalloc even when they could.

In addition to Marc-Andre's suggestions, I would suggest paying 
particular attention to the creation and retention of objects in your 
code - if something's no longer required, explicitly delete it.  It is
all too easy to lose sight of references to objects that hang around in
ways that defeat the gc support.  Watch out for things that might be
sensitive to thread-ids for example.

Careful algorithm planning can also be useful, leveraging object 
references to minimise duplicated data (and possibly get better 
performance).


-- 
-
Andrew I MacIntyre These thoughts are mine alone...
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic inheritance question

2008-01-05 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:
 Jeroen Ruigrok van der Werven wrote:

 self.startLoc = start
 self.stopLoc = stop
 
 Thanks! Of course it should. Old Java habits die slowly.

That's not really a Java habit. In Java and C++, personally I like
to write

this.startLoc = start
this.stopLoc = stop

It makes much clearer what a field and what a normal variable is
in those languages. 

Regards,


Björn

-- 
BOFH excuse #294:

PCMCIA slave driver

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


Re: Fortran to Python

2008-01-05 Thread Jeroen Ruigrok van der Werven
-On [20080104 19:21], Dennis Lee Bieber ([EMAIL PROTECTED]) wrote:
   If the FORTRAN is using single precision reals, I'd expect a
slow-down in Python just on that alone, as Python uses doubles as the
only float type. There is also the overhead of object access for each.

In this case it uses complex*16 and real*8. Is a real*8 a single precision
real?

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Everything has beauty, but not everyone sees it. - Confucius
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Fortran to Python

2008-01-05 Thread Robert Kern
Jeroen Ruigrok van der Werven wrote:
 -On [20080104 19:21], Dennis Lee Bieber ([EMAIL PROTECTED]) wrote:
  If the FORTRAN is using single precision reals, I'd expect a
 slow-down in Python just on that alone, as Python uses doubles as the
 only float type. There is also the overhead of object access for each.
 
 In this case it uses complex*16 and real*8. Is a real*8 a single precision
 real?

Double precision. These map to the Python complex and float types exactly.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: TextWrangler and new Python version (Mac)

2008-01-05 Thread MrJean1
On Jan 4, 3:33 pm, cf29 [EMAIL PROTECTED] wrote:
 I installed Python 2.5 on my Mac (OS X Tiger). When running scripts
 with the TextWrangler Run command it is using the system installed
 version of Python (2.3). If I run the scripts with the Apple Terminal
 it uses the new version (2.5).

 Is there any way to ask TextWrangler to use the new version of Python?


Chapter 12 of the TextWrangler User Manual under Unix Scripting:
Perl, Python, Ruby, Shells and More has several paragraphs on this
very issue.

/Jean Brouwers

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


Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 4, 7:55 pm, [EMAIL PROTECTED] wrote:
   Hello,
   This is a question for the best method (in terms of performance
 only) to choose a random element from a list among those that satisfy
 a certain property.

   This is the setting: I need to pick from a list a random element
 that satisfies a given property. All or none of the elements may have
 the property. Most of the time, many of the elements will satisfy the
 property, and the property is a bit expensive to evaluate. Chance of
 having the property are uniform among elements.

Here's some code that uses a cached random sorting of the list. It
assumes you'll want more than one random element. It never calls
'prop' on the same element twice, and it's O(n) even when the elements
that pass 'prop' are sparse. I hope this is useful to you!

import random

class RandomPicker(object):
def __init__(self, seq, prop=lambda x:True):
seq = list(seq)
random.shuffle(seq)
# Store with the item whether we've computed prop on it
already.
self.random_list = [(x, False) for x in seq]
self.prop = prop
def pick(self):
for i, (x, p) in enumerate(self.random_list):
if p or self.prop(x):
if not p:
# Record the fact that self.prop passed.
self.random_list[i] = (x, True)
# Chop off the items that prop failed on.
self.random_list = self.random_list[i:]
r = self.random_list
# Instead of shuffling the whole list again, just
insert
# x back in the list randomly. Since the remaining
elements
# are randomly sorted already, this is ok.
n = random.randint(0, len(r) - 1)
r[0], r[n] = r[n], r[0]
return x
# Nothing in the list passes the 'prop' test.
return None

# Example: pick 100 odd integers from 0 to 1000.
a = RandomPicker(xrange(1000), lambda x: x % 2 == 1)
print [a.pick() for i in xrange(100)]

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


Point Object

2008-01-05 Thread [EMAIL PROTECTED]
I am nes to python and need some help.  Can anyone lead me in the
right direction to create and print a Point object, and then use id to
print the object's unique identifier. Translate the hexadecimal form
into decimal and confirm that they match.

Any help woul be much appreciated.

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


Re: Question on os.tempnam() vulnerability

2008-01-05 Thread Jarek Zgoda
Grant Edwards pisze:

 you get a name instead of a file, so someone else can create that file 
 after you've called tempnam/tmpnam, but before you've actually gotten 
 around to create the file yourself.  which means that anyone on the 
 machine might be able to mess with your application's data.

 use the functions marked as safe in the tempfile module instead.
 
 Under Windows, is there a safe way to create a temp file that
 has a name that can be passed to a program which will then open
 it? I never figured out a way to do that and had to fall back
 on the unsafe tmpnam method.

I think it's all impossible to get only file name and feel safe. You
have to have both file name and a file object opened exclusively for
you. Any other way you'll get a possible race condition.

-- 
Jarek Zgoda
http://zgodowie.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Point Object

2008-01-05 Thread Marc 'BlackJack' Rintsch
On Sat, 05 Jan 2008 03:37:33 -0800, [EMAIL PROTECTED] wrote:

 I am nes to python and need some help.  Can anyone lead me in the
 right direction to create and print a Point object, and then use id to
 print the object's unique identifier. Translate the hexadecimal form
 into decimal and confirm that they match.

The right direction would be the tutorial in the docs I guess:

  http://docs.python.org/tut/tut.html

What do you mean by the hexadecimal form?  `id()` returns ordinary
`int`\s and not strings.

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


Re: TextWrangler and new Python version (Mac)

2008-01-05 Thread cf29
Thank you Jean, I could fix this problem. Creating the symbolic link
wasn't really obvious though.

They also say about the documentation:
*Extract the documentation files, and place them in some suitable
location, e.g.
~/Library/Python-Docs
*Edit your environment.plist file, and create an environment
variable
PYTHONDOCS to the location of the folder which contains the Python
documentation.

Is that the html version of the Python documentation?
Do you know more about this environment.plist file?
Where is it supposed to be? I didn't find any.

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


Re: fastest method to choose a random element

2008-01-05 Thread Arnaud Delobelle
On Jan 4, 7:55 pm, [EMAIL PROTECTED] wrote:
   Hello,
   This is a question for the best method (in terms of performance
 only) to choose a random element from a list among those that satisfy
 a certain property.

   This is the setting: I need to pick from a list a random element
 that satisfies a given property. All or none of the elements may have
 the property. Most of the time, many of the elements will satisfy the
 property, and the property is a bit expensive to evaluate. Chance of
 having the property are uniform among elements.

The generator function below yields an infinite sequence of randomly
picked elements from the list who satisfy the property, or nothing if
the list contains no element satisfying the property.  It guarantees
that each time, prop() will either not be called or will be called
just enough to find one single item that satisfies it.  The catch is
that you need to have an estimate for the number of items that satisfy
the property in the list.

import random
from itertools import islice, ifilter

def picker(lst, prop, np):
# lst: list of items to pick elements from
# prop: property that picked elements must fulfil
# np: (good estimate of) number of items that
# satisfy the property
random.shuffle(lst)
plst = [] # items we know fulfil prop
for item in ifilter(prop, lst):
# The next random item may be one already yielded
while True:
i = random.randrange(np)
if i = len(plst): break
yield plst[i]
# Or it may be a new one
plst.append(item)
if len(plst)  np: np = len(plst)
yield item
# Now we know all items fulfilling prop
if not plst: return
while True:
yield plst[random.randrange(len(plst))]


def test(picker, n=1000):
res = {}
for val in islice(picker, n):
res[val] = res.get(val, 0) + 1
return res


Example:

 p = picker(range(20), lambda x: x % 2, 10)
 test(p)
{1: 113, 3: 96, 5: 87, 7: 91, 9: 109, 11: 91, 13: 106, 15: 101, 17:
109, 19: 97}


 p = picker(range(20), lambda x: False, 10)
 p.next()
Traceback (most recent call last):
  File stdin, line 1, in module
StopIteration

I don't know if there is a good idea in there, I'll let you be the
judge :)

--
Arnaud

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


Welcome to my webside that provides help in English Study for Chinese..

2008-01-05 Thread nonamehuang
The address is http://englearn.zhan.cn.yahoo.com
And I need your advice. Well, maybe your help. You see. aha!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary/hash and '1' versus 1

2008-01-05 Thread Paddy
On Jan 4, 3:50 pm, Reedick, Andrew [EMAIL PROTECTED] wrote:
  From: Stephen Hansen [mailto:[EMAIL PROTECTED]
  Sent: Thursday, January 03, 2008 7:39 PM
  To: Reedick, Andrew
  Cc: [EMAIL PROTECTED]
  Subject: Re: dictionary/hash and '1' versus 1

  Well one important thing to learn while learning Python is that while the
  language is dynamically typed-- it is also /strongly/ typed. Every piece
  of data has an explicit type and it doesn't change unless you change it.

 Meh, mixing dynamic and strong typing is a mixed blessing.  You don't 
 find out that you screwed up the data types until the code block is actually 
 executed.  Reminds me of Nostradamus.  He may have predicted the future[1], 
 but the predictions are so vague/convoluted that you can only figure out the 
 predictions in hindsight.

  It relies on duck typing a lot, and doesn't care if you mix and match
  (even partially) compatible types as long as the operations are there,
  but one type will always be distinct and remain that type until you
  explicitly convert it.

  A single integer is distinctly different from a sequence of characters in
  some encoding that may just happen to contain representations of a
  number so they'll hash differently :)

 Depends on the context.  The machine encoding may be different, but 
 in human terms they should be the same.  Perl managed to achieve an 
 impressive blend of presenting data as human friendly or as machine bits when 
 it made sense to do so.  So much so, that Perl is probably the only language 
 I've used that will do what you mean instead of what you say.  Nice, but 
 frightening in some ways.

There are many character strings that contain numeric characters that
are not necessarily to be interpreted as an int or a float, such as
string representations of IP addresses, or numbers to other bases than
ten, complex numbers, telephone numbers, ...
You need to validate your input and convert and pass around the
correct type of data. Perl inherited this automatic conversion between
strings and numbers from simple shell scripting and the AWK language
that was around before Perl. I find that the follow-on need to have
separate comparisons for numbers or strings to be awkward in Perl.


  One type will basically never implicitly convert into another type.

  To me, this sounds like the function should have converted the type
  explicitly on return. Or maybe you need to convert it explicitly on
  receipt.

 Type casting is easy, IFF you remember to do so.  The problem was 
 that I missed the fact that one (important) function was returning a string 
 instead of an int, and since Python supports heterogenous data structures, 
 the human has to remember to keep the key's data type homongenous.
 That and Perl does so much automatic type conversion in such a 
 sensible way, that I stopped worrying about mixing data types, which is 
 making the Python transition a tad more error prone.  Because of Perl, I 
 almost consider automatic type casting to be the next you don't have to 
 manage your own memory that people loved about Java.  =O

Not really, it seems to me to be going the exact opposite way with
languages with automatic type conversions being seen as not suited for
larger programs.


  But if you are in a use-case where you really don't care and only
  want to hash strings, you can create a dict subclass easily that
  overrides __setitem__ to always str() the input. Check out the
  UserDict class.

 UserDict looks like it could be useful.  Thanks for the info.

  A similar method lets you make 'case-insensitive' dicts, for example.

  Were such a thing to happen automagically, you could get some
  weird situations, such as assert (key in dict) == (key in dict.keys())
  failing.

 I'm assuming that you would just need to overload the 'in' operator 
 and .keys() method to be case insensitive also.

 [1]  No, he didn't.

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


Re: Question on os.tempnam() vulnerability

2008-01-05 Thread Grant Edwards
On 2008-01-05, Jarek Zgoda [EMAIL PROTECTED] wrote:

 Under Windows, is there a safe way to create a temp file
 that has a name that can be passed to a program which will
 then open it? I never figured out a way to do that and had to
 fall back on the unsafe tmpnam method.

 I think it's all impossible to get only file name and feel
 safe. You have to have both file name and a file object opened
 exclusively for you. Any other way you'll get a possible race
 condition.

I know.  That's the point of my question: how do you do that
under Windows?

-- 
Grant Edwards   grante Yow!  HAIR TONICS, please!!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: nächstes Treffen von pyCologne am 9.1.2008 18: 30 Uhr

2008-01-05 Thread Christopher Arndt
Hallo liebe Pythonfreunde,

das nächste Treffen von pyCologne, der Python User Group Köln, findet
statt:

Datum:   Mittwoch, den 9.1.2008
Uhrzeit: 18:30 Uhr c.t.
Ort: Pool 0.14, Benutzerrechenzentrum (RRZK-B) der Universität
Köln,
 Berrenrather Str. 136, 50937 Köln

Das Programm für das nächste Treffen lautet:

   * Vortrag über MoinMoin (Reimar Bauer)
   * Vortrag über das Publisher/Subscriber-Pattern (Observer-Pattern)
 (Christopher Arndt)
   * Diskussion: Weitere Vorgehensweise und Verwendung des pyCologne
 Logos

Ab ca. 20:30 Uhr werden wir den Abend gemütlich in einem nahe
gelegenen
Restaurant/Kneipe ausklingen lassen.

Weitere Information zu pyCologne, inkl. Wegbeschreibung, Fotos und
Protokollen vergangener Treffen usw.,  findet ihr auf unserer Seite
im deutschen Python Wiki:

http://wiki.python.de/pyCologne

Bis bald,

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


Re: Tabnanny errors when Migrating Python 2.4 code to 2.5

2008-01-05 Thread Mike Driscoll
 I'm using Windows XP, using IDLE (which was mentioned already)

 in the context of editing/displaying code, not executing it. Does the
 problem occur before or after you edit a file with IDLE?

Actually, neither. I'm not editing the code. I open it in IDLE in 2.5
and attempt to run it through the Run menu Run Module menu item or
by pressing F5. It immediately fails with a tabnanny error. If I run
it from 2.4's IDLE, it works.

 and I
 downloaded the 2.5.1 exe/msi file from python.org to install it.

 What you downloaded doesn't answer the question about how you
 installed it. Do you still have your 2.4 installation?

Yes, I use both 2.4 and 2.5 as I migrate from one to the other. I've
attached a file that causes it consistently. On two systems with both
2.4 and 2.5 installed, it fails on line 206 when run from the IDLE
included with 2.5.

 I have yet to find a simple one which exhibits the issue to post. It
 seems to happen to my complex files, not the simple ones.

 So chop up a complex file ...
 Have you inspected the failing files using a text editor that can
 display tabs and spaces (e.g. PythonWin, TextPad)?

I just used Notepad++ to inspect the file and it does indeed have tabs
at line 206 rather than spaces. I take it that Python 2.5 is more
sensitive to that than is 2.4? I program almost exclusively in IDLE as
I'd read that this can happen in some text editors, but it seemed
implied that it didn't if you used IDLE. At least, that's what I got
from various Python books and the website:
http://www.python.org/idle/doc/idlemain.html

Anyway, thanks for the help.

Mike
# scrubber.pyw
#
# Author: Mike Driscoll
#
# Updated: 05/16/2007
#
# Deletes folders and files, ignores errors. The deletion functions
# run in a separate thread.


import wx
import os
import glob
import sys
import shutil
import time
import win32api

from threading import Thread

userid = win32api.GetUserName()

class ProfileScrubber(wx.App):
def __init__(self, redirect=True, filename=None):
wx.App.__init__(self, redirect, filename)

def OnInit(self):
self.frame = wx.Frame(None, -1, title='Profile Scrubber Beta 0.3', 
size=(400,500))

panel = wx.Panel(self.frame, -1)

# user list up-to-date as of 10/20/2006
user_list = self.getProfileList()

tempF = r'C:\Documents and Settings\%s\Local Settings\Temp' % userid
tempIntF = r'C:\Documents and Settings\%s\Local Settings\Temporary 
Internet Files' % userid

# Create the controls
descriptionLbl = wx.StaticText(panel, -1, ' Choose an option below:')
font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
descriptionLbl.SetFont(font)
genericPathLbl = wx.StaticText(panel, -1, 'Enter Path:')
self.path = wx.TextCtrl(panel, -1, '', size=(500,-1))

optionLbl = wx.StaticText(panel, -1, 'Other Folders to be Deleted:')
optionLbl.SetFont(font)
self.tempCkbx = wx.CheckBox(panel, -1, 'Temp', size=wx.DefaultSize)
self.tempCkbx.SetValue(True)
self.tempFilesCkbx = wx.CheckBox(panel, -1, 'Temporary Internet Files', 
size=wx.DefaultSize)
self.tempFilesCkbx.SetValue(True)
self.tempTxt = wx.TextCtrl(panel, -1, tempF, size=(500,-1))
self.tempTxt.Disable()
self.tempFilesTxt = wx.TextCtrl(panel, -1, tempIntF, size=(500,-1))
self.tempFilesTxt.Disable()

useridLbl = wx.StaticText(panel, -1, 'Choose the user \n(if 
different):')
self.user = wx.ComboBox(panel, -1, userid, None, (150, -1), user_list, 
wx.CB_DROPDOWN)
self.user.Bind(wx.EVT_COMBOBOX, self.comboChoice)

scrubBtn = wx.Button(panel, -1, 'Scrub')
self.Bind(wx.EVT_BUTTON, self.scrub, scrubBtn)
closeBtn = wx.Button(panel, -1, 'Close')
self.Bind(wx.EVT_BUTTON, self.close, closeBtn)

# create a checklistbox widget to list all the user profiles on the 
machine
profLbl = wx.StaticText(panel, -1, 'Please choose what profiles to 
remove:')
profLbl.SetFont(font)
self.profile_list = self.getProfileList()
self.profile_cblb = wx.CheckListBox(panel, -1, size=(100, -1), 
choices=self.profile_list)

# delete button
deleteBtn = wx.Button(panel, -1, 'Delete Profiles')
self.Bind(wx.EVT_BUTTON, self.deleteProfile, deleteBtn)

# Main sizer to hold all the lesser sizers
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(descriptionLbl)
mainSizer.Add((10,10))

# pathSizer holds the top set of widgets
pathSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
pathSizer.AddGrowableCol(1)
pathSizer.Add(genericPathLbl, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
pathSizer.Add(self.path, 0, wx.EXPAND)
pathSizer.Add(useridLbl, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
pathSizer.Add(self.user, 1)
pathSizer.Add((10,10))

Re: Request for help with Image color space conversion

2008-01-05 Thread ttest
 Reimplement colorsys.rgb_to_hsv() such that it operates on arrays instead of
 scalars. Only minor modifications are necessary.

 --
 Robert Kern

Thanks!  I'll try and see if a newcomer like me can get his head
around the array-centric modifications to colorsys.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread caca
On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:
 Hello, Paul and Arnaud.
 While I think about your answers: do you think there is any way to
 avoid shuffle?
 It may take unnecessary long on a long list most of whose elements
 have the property.

Umm...
You provide nice answers in the case many elements are picked from the
same list.
Any ideas for the case when the picker is called many times on a
program, but never twice with the same list?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread caca
Hello, Paul and Arnaud.
While I think about your answers: do you think there is any way to
avoid shuffle?
It may take unnecessary long on a long list most of whose elements
have the property.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on os.tempnam() vulnerability

2008-01-05 Thread Martin v. Löwis
 I know.  That's the point of my question: how do you do that
 under Windows?

When you create a new process, you have the option to inherit
file handles to the new process. So the parent should open the
file, and then inherit the handle to the new process.

The new process will need to know what the file handle it should
use. There are two basic options:
a) pass the file handle number as a string on the command line
b) make the handle either stdin or stdout of the new process,
   and have the new process ask for its stdin/stdout handle.

IOW, it's the same approach as on Unix.

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


Re: Fortran to Python

2008-01-05 Thread Evgenii Rudnyi
On Jan 4, 2:21 pm, Jeroen Ruigrok van der Werven [EMAIL PROTECTED]
nomine.org wrote:
 I got someone who asked me to make changes in an old Fortran program she is
 using for some calculations.
 The calculations are pretty standard aside from 2 calls to DLINCG (an IMSL
 numerical_libraries function to calculate an inverse matrix).

 What I wonder about, does anybody have a Fortran to Python conversion page
 somewhere to map some of the basic types to Python equivalents?
 What kind of speed difference should I expect?

When it comes to matrices the difference can be quite big. You can
find the comparison of NumPy, Fortran 77, C, and C++ for matrix
multiplication with and without optimized BLAS at

http://matrixprogramming.com/MatrixMultiply/

NumPy interfaces optimized BLAS, and you can find a LAPACK interface
in SciPy, so it is a good choice.

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


Re: Question on os.tempnam() vulnerability

2008-01-05 Thread Grant Edwards
On 2008-01-05, Martin v. Löwis [EMAIL PROTECTED] wrote:

 I know.  That's the point of my question: how do you do that
 under Windows?

 When you create a new process, you have the option to inherit
 file handles to the new process. So the parent should open the
 file, and then inherit the handle to the new process.

That's an answer, though not for the question I asked.  The
program that's being run requires a that it be passed a
filename on the command-line.

I'm not writing the program that is to open the file.  If I
were, I'd just make it a python module and call it instead of
running it in a separate process.

 IOW, it's the same approach as on Unix.

Not really.  Under Unix you can safely create a temp file with
a name that can be used to open the file.  I asked about a way
to do that under Windows as well.

-- 
Grant Edwards   grante Yow!  ... I live in a
  at   FUR-LINE FALLOUT SHELTER
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread ajaksu
Hi there :)

On Jan 5, 2:14 pm, [EMAIL PROTECTED] wrote:
 On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:

  Hello, Paul and Arnaud.
  While I think about your answers: do you think there is any way to
  avoid shuffle?
  It may take unnecessary long on a long list most of whose elements
  have the property.

I've been thinking about this one before you asked and only got a bad
solution: you don't need to shuffle the list if you can construct a
random list of indexes to loop through, but my timings show that I
can't do that faster than shuffle(range(x)) for worst cases (i.e.,
iterate thru the whole list) :)

The rather good news is that shuffling a list of arbitrary objects is
pretty fast (as compared to a list of integers).

OTOH, if you do know that the chances are high enough, you can try
choosing items randomly without substitution (adapted from random.py's
sample):

from random import random

def randpickuntil(lst, prop=bool):
selected = set()
for i in xrange(len(lst)):
j = int(random() * n)
while j in selected:
j = int(random() * n)
if prop(lst[j]):
return lst[j]
selected_add(j)


 Umm...
 You provide nice answers in the case many elements are picked from the
 same list.
 Any ideas for the case when the picker is called many times on a
 program, but never twice with the same list?

If the lists share items, a cache could help a lot. Otherwise, you'd
benefit more from finding a good way to test the property (could you
give a hint on what it is?). How do objects acquire that property, is
it a sum of independent factors?

HTH,
Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote:
 On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:

  Hello, Paul and Arnaud.
  While I think about your answers: do you think there is any way to
  avoid shuffle?
  It may take unnecessary long on a long list most of whose elements
  have the property.

You could generate a random shuffle of range(len(seq)) lazily, and use
that to iterate over your sequence.

import random
import itertools

def randxrange(n):
Generate the numbers 0 to n-1 in a random order
x = range(n)
for i in xrange(n):
r = random.randrange(n - i)
yield x[r]
x[r] = x[n - i - 1]

def shuffled(seq):
Generate the elements of seq in a random order
return (seq[i] for i in randxrange(len(seq)))

def pick_random(seq, prop):
return itertools.ifilter(prop, shuffled(seq)).next()

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


Re: Questions about subclassing an int

2008-01-05 Thread Francesco Guerrieri
On Jan 4, 2008 11:55 PM, Steven W. Orr [EMAIL PROTECTED] wrote:

 class S(int):
 def __init__(self, value):
self.value = value
 def addStr(self, str):
self.doc = str


The original question has already been answered,
I only want to suggest to avoid shadowing builtin names,
like str in the above example.

Bye,
Francesco
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 5:12 pm, Martin v. Löwis [EMAIL PROTECTED] wrote:
  Any other ideas?

 How about this:

 def random_pick(list, property):
     L = len(list)
     pos = start = random.randrange(L)
     while 1:
         x = list[pos]
         if property(x): return x
         pos = (pos + 1) % L
         if pos == start:
            raise ValueError, no such item

This might be acceptable for the OP's use, but it's strongly biased
towards values which follow a long stream of things that fail
property.

print [random_pick(range(100), lambda x:x  90)
for i in range(999)].count(91)

929

If it were uniform, it should be around 111.

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


Re: fastest method to choose a random element

2008-01-05 Thread ajaksu
 OTOH, if you do know that the chances are high enough, you can try
 choosing items randomly without substitution (adapted from random.py's
 sample):

Sorry, this works:

def randpickuntil(lst, prop=bool):
selected = set()
n = len(lst)
for i in xrange(n):
j = int(random() * n)
while j in selected:
j = int(random() * n)
if prop(lst[j]):
return lst[j]
selected.add(j)

Gotta say it's much faster on average than shuffle for moderately to
highly probable tests, but might become pathological (i.e. run for
minutes) for very large lists in which prop(x) is False for all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread Martin v. Löwis
 Any other ideas? 

How about this:

def random_pick(list, property):
L = len(list)
pos = start = random.randrange(L)
while 1:
x = list[pos]
if property(x): return x
pos = (pos + 1) % L
if pos == start:
   raise ValueError, no such item

Regards,
Martin


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


Re: Question on os.tempnam() vulnerability

2008-01-05 Thread Martin v. Löwis
 That's an answer, though not for the question I asked.

I think you'll have to pose a complete question again,
rather than how do I do that, if you want to get an
answer to your question.

 Not really.  Under Unix you can safely create a temp file with
 a name that can be used to open the file.  I asked about a way
 to do that under Windows as well.

Assuming you are still talking about

 is there a safe way to create a temp file that
has a name that can be passed to a program which will then open
it?

then also on Unix, the answer is: no, that's not possible.
I assume you are asking about a scenario such as:
a) the parent process creates a file
b) the parent process closes its handle to the file
c) the parent process creates a child process passing
   the file name
d) the child process opens the file, and is certain that it
   is still the same file

then this sequence cannot be implemented on Unix, either - another
process may remove the file and create a new one between b and d.

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


Re: Question on os.tempnam() vulnerability

2008-01-05 Thread Grant Edwards
On 2008-01-05, Fredrik Lundh [EMAIL PROTECTED] wrote:
 Grant Edwards wrote:

 IOW, it's the same approach as on Unix.
 
 Not really.  Under Unix you can safely create a temp file with
 a name that can be used to open the file.

 Unless I'm missing something, it's not possible to do this in a safe
 way in the shared temp directory; you can do that only by creating a 
 file in a directory that's under full control of your user.

Which is what I do.

 And *that* approach works on Windows as well, of course.

I was asking how to create a named temporary file under Windows
without a race condition.  I've re-read the tempfile module
documentation a couple more times, and it finally dawned on me
that I'd been misreading the following statement about
tempfiles created by NamedTemporaryFile/mkstemp:

  Whether the name can be used to open the file a second time,
   while the named temporary file is still open, varies across
   platforms (it can be so used on Unix; it cannot on Windows NT
   or later).

I don't know how many times I've read that and missed the
phrase while the named temporary file is still open.  I had
always read that as saying that the tempfile couldn't be opened
a second time under Windows.  I know, that would make the
availability of the path/name a moot point, but so many things
under Windows don't make sense to me that I just let it slide.

As Emily Litella used to say:

 Oh.  That's very different.  Never mind.

-- 
Grant Edwards   grante Yow!  It's hard being
  at   an ARTIST!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on os.tempnam() vulnerability

2008-01-05 Thread Fredrik Lundh
Grant Edwards wrote:

 IOW, it's the same approach as on Unix.
 
 Not really.  Under Unix you can safely create a temp file with
 a name that can be used to open the file.

Unless I'm missing something, it's not possible to do this in a safe
way in the shared temp directory; you can do that only by creating a 
file in a directory that's under full control of your user.

And *that* approach works on Windows as well, of course.

/F

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


Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote:
 On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:

  Hello, Paul and Arnaud.
  While I think about your answers: do you think there is any way to
  avoid shuffle?
  It may take unnecessary long on a long list most of whose elements
  have the property.

 Umm...
 You provide nice answers in the case many elements are picked from the
 same list.
 Any ideas for the case when the picker is called many times on a
 program, but never twice with the same list?

Here's a pragmatic optimisation for any algorithm: first test some
elements at random in case you get lucky or most of the elements are
good.

Eg, that optimisation applied to the naive shuffle algorithm.

import random
import itertools

def pick_random_fast(seq, prop):
L = len(seq)
stabs = 5
for i in xrange(stabs):
r = random.randrange(L)
if prop(seq[r]): return seq[r]
random.shuffle(seq)
return itertools.ifilter(prop, seq).next()

I've used 5 'stabs' here. Perhaps it should be a function of L, but I
suppose you can tune it for your data.

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


Re: Cursors in a Loop

2008-01-05 Thread Chris
On Jan 4, 4:32 pm, Carsten Haese [EMAIL PROTECTED] wrote:
 On Fri, 2008-01-04 at 00:03 -0800, Chris wrote:
  You should bind all variables to save the pool.

  cursor = connection.cursor()
  cursor.executemany(insert into as_siebel_hosts_temp
values (:whole, :lot, :of, :bind, :variables)
 
,[(i,)[0] for i in hostlist]
)
  connection.commit()
  connection.close()

 Huh? In the OP's example, the table one has one column. I'll openly
 admit that I don't know anything about Oracle, but that code doesn't
 make sense to me. Maybe you're trying to execute a multi-row insert, but
 that would be done with execute(), not executemany(), wouldn't it?

 Also, isn't [(i,)[0] for i in hostlist] exactly the same as [i for i
 in hostlist] which in turn is exactly the same as hostlist?

 --
 Carsten Haesehttp://informixdb.sourceforge.net

The OPs example has a formatted string, no idea what is in it...
My example creates a tuple out of each of the records you want to
insert and uses them in the bind variables.

You can do a loop through hostlist and do a single execute on each one
if you want.  It won't make a large impact.
The [(i,)[0] for i in hostlist] was mainly directed to you because
your structure ends up being a tuple inside a list which doesn't work
for cx_Oracle.  You need a straight tuple to bind to the statement.

My code creates a series of usable tuples for the executemany
function.
HTH,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic inheritance question

2008-01-05 Thread Lie
On Jan 5, 5:40 pm, [EMAIL PROTECTED] wrote:
 Jeroen Ruigrok van der Werven wrote:

  Shouldn't this be:

  self.startLoc = start
  self.stopLoc = stop

 Thanks! Of course it should. Old Java habits die slowly.

No, seriously it isn't Java habits only, most other languages wouldn't
need explicit calling of class name.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python web aps - A matter of security

2008-01-05 Thread lloyd
Hello,

I'm developing a Python-based web ap, but don't understand how to best organize 
the modules and set permissions for maximum security.

Here's how the Python code for my ap is organized:

1) I have Python modules in a project directory. The path to that directory is 
in a  *.pth file  in the .*/pythonx-y/site-packages directory. 

Question: who should own these modules; what groups should have access, and how 
should permissions be set?

2) I have high-level modules that import the worker-bee modules in the web root 
directory tree that are called by the webserver.

Questions: who should own these modules, what groups should have access, and 
how should permissions be set?

3) Is there a better way to organize my Python modules? Are there other 
security issues I should heed?

Many thanks,

Lloyd



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

MySQLdb and compatibility with vista 64 bits

2008-01-05 Thread revuesbio
Hello,
I try to install mysqldb on windows vista 64bits but there is a
failure when i try to import mysqldb in python 2.5 :
DLL load failed with error code 193

Is there a solution to this problem ?
Thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python interfaces

2008-01-05 Thread Peter Maas
Sion Arrowsmith wrote:
 hyperboreean  [EMAIL PROTECTED] wrote:
 Why doesn't python provide interfaces trough its standard library?
 
 Because they're pointless.

Wrong. I'm using Eclipse with the Java Development Tools (JDT) who do
a wonderful job using interfaces to perform lots of checking, warning
and code generation *nearly in real time while I am editing my code*.
Because JDT knows interfaces it knows what to do and to suggest.

 Java interfaces are a hack around the complexities of multiple
 inheritence.

A hack is something applied subsequently to solve a software problem while
avoiding large changes. Java interfaces originate from careful language
design. You are free to dislike Java interfaces but calling them a hack is
just plain wrong.

Once software becomes really big interfaces are very useful to handle
complexity. Ever wondered why the Zope people introduced interfaces in
their Python code?

 Interfaces used purely with the idea of type safety provide
 precious little gain for the added clutter and inconvenience.

An interface is a software specification allowing you to use a software
package without extensive code studies. This is a good thing. Interfaces
have nothing to do with multiple inheritance and are not about type safety
in the first place. They just tell you how to connect, how to plug in.

-- 
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python interfaces

2008-01-05 Thread Peter Maas
Sion Arrowsmith wrote:
 hyperboreean  [EMAIL PROTECTED] wrote:
 Why doesn't python provide interfaces trough its standard library?
 
 Because they're pointless.

Wrong. I'm using Eclipse with the Java Development Tools (JDT) who do
a wonderful job using interfaces to perform lots of checking, warning
and code generation *nearly in real time while I am editing my code*.
Because JDT knows interfaces it knows what to do and to suggest. An
interface is a software specification allowing you to use a software
package without extensive code studies. This is a good thing.

  Java interfaces are a hack around the complexities of multiple
  inheritence.

A hack is something applied subsequently to solve a software problem while
avoiding large changes. Java interfaces originate from careful language
design. You are free to dislike Java interfaces but calling them a hack is
just plain wrong.

Once software becomes really big interfaces are very useful to handle
complexity. Ever wondered why the Zope people introduced interfaces in
their Python code?

  Interfaces used purely with the idea of type safety provide
  precious little gain for the added clutter and inconvenience.

An interface is a software specification allowing you to use a software
package without extensive code studies. This is a good thing. Interfaces
have nothing to do with multiple inheritance. They just tell you how to
connect, how to plug in.

-- 
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 5:12 pm, Paul Hankin [EMAIL PROTECTED] wrote:
 On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote:

  On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:

   Hello, Paul and Arnaud.
   While I think about your answers: do you think there is any way to
   avoid shuffle?
   It may take unnecessary long on a long list most of whose elements
   have the property.

 You could generate a random shuffle of range(len(seq)) lazily, and use
 that to iterate over your sequence.

 import random
 import itertools

 def randxrange(n):
     Generate the numbers 0 to n-1 in a random order
     x = range(n)
     for i in xrange(n):
         r = random.randrange(n - i)
         yield x[r]
         x[r] = x[n - i - 1]

 def shuffled(seq):
     Generate the elements of seq in a random order
     return (seq[i] for i in randxrange(len(seq)))

 def pick_random(seq, prop):
     return itertools.ifilter(prop, shuffled(seq)).next()

At the risk of filling this thread with my posts, here's a much
simplified and faster version of this code that uses no extra storage.

import random

def pick_random(seq, prop):
L = len(seq)
for i in xrange(L):
r = random.randrange(L - i)
if prop(seq[r]):
return seq[r]
seq[r] = seq[L - i - 1]

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


Re: fastest method to choose a random element

2008-01-05 Thread Carl Banks
On Sat, 05 Jan 2008 08:14:46 -0800, caca wrote:

 On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:
 Hello, Paul and Arnaud.
 While I think about your answers: do you think there is any way to
 avoid shuffle?
 It may take unnecessary long on a long list most of whose elements have
 the property.
 
 Umm...
 You provide nice answers in the case many elements are picked from the
 same list.
 Any ideas for the case when the picker is called many times on a
 program, but never twice with the same list?

ISTM the best thing would be to reimplement the shuffle algorithm, but to 
stop shuffling as soon as you get a hit.  The drawback is that it's a 
destructive operation, but that doesn't sound like it's an issue for you.

Here's something for starters:

def random_element_with_property(x,test_property_func):
for i in xrange(len(x)-1):
j = random.randrange(i+1,len(x))
tmp = x[j]
if test_property_func(tmp):
return tmp
x[j] = x[i]
x[i] = tmp
return None


Then, for example, use it like this:

def odd(i): return i1
e = random_element_with_property(range(20),odd)



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


Re: fastest method to choose a random element

2008-01-05 Thread bukzor
On Jan 5, 9:12 am, Martin v. Löwis [EMAIL PROTECTED] wrote:
  Any other ideas?

 How about this:

 def random_pick(list, property):
 L = len(list)
 pos = start = random.randrange(L)
 while 1:
 x = list[pos]
 if property(x): return x
 pos = (pos + 1) % L
 if pos == start:
raise ValueError, no such item

 Regards,
 Martin

I thought about this, but in the sequence 00012 (and property =
bool) the 1 will be returned four times as often as the 2. Maybe
that's ok...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest method to choose a random element

2008-01-05 Thread Arnaud Delobelle
On Jan 5, 8:50 pm, Paul Hankin [EMAIL PROTECTED] wrote:
 On Jan 5, 5:12 pm, Paul Hankin [EMAIL PROTECTED] wrote:



  On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote:

   On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:

Hello, Paul and Arnaud.
While I think about your answers: do you think there is any way to
avoid shuffle?
It may take unnecessary long on a long list most of whose elements
have the property.

  You could generate a random shuffle of range(len(seq)) lazily, and use
  that to iterate over your sequence.

  import random
  import itertools

  def randxrange(n):
      Generate the numbers 0 to n-1 in a random order
      x = range(n)
      for i in xrange(n):
          r = random.randrange(n - i)
          yield x[r]
          x[r] = x[n - i - 1]

  def shuffled(seq):
      Generate the elements of seq in a random order
      return (seq[i] for i in randxrange(len(seq)))

  def pick_random(seq, prop):
      return itertools.ifilter(prop, shuffled(seq)).next()

 At the risk of filling this thread with my posts, here's a much
 simplified and faster version of this code that uses no extra storage.

 import random

 def pick_random(seq, prop):
     L = len(seq)
     for i in xrange(L):
         r = random.randrange(L - i)
         if prop(seq[r]):
             return seq[r]
         seq[r] = seq[L - i - 1]

 --
 Paul Hankin

Great!  This is so simple it must be the best way to do it.  Thanks
for that: I could feel there must be an elegant way, but I couldn't
put my finger on it.  The only downside, of course, is that it mutates
seq.  Moreover, it can be slightly modified to be a generator (in case
one wants to draw many elements from the sequence), improving vastly
on the generator function I proposed earlier.

def pick_random(seq, prop):
for i in xrange(len(seq), 0, -1):
r = random.randrange(i)
if prop(seq[r]):
return seq[r]
seq[r] = seq[i - 1]


# Generator version.
def random_picker(seq, prop):
for i in xrange(len(seq), 0, -1):
while True:
r = random.randrange(i)
if not prop(seq[r]): break
yield seq[r]
seq[r] = seq[i - 1]

--
Arnaud

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


Re: fastest method to choose a random element

2008-01-05 Thread bukzor
On Jan 5, 8:14 am, [EMAIL PROTECTED] wrote:
 On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:

  Hello, Paul and Arnaud.
  While I think about your answers: do you think there is any way to
  avoid shuffle?
  It may take unnecessary long on a long list most of whose elements
  have the property.

 Umm...
 You provide nice answers in the case many elements are picked from the
 same list.
 Any ideas for the case when the picker is called many times on a
 program, but never twice with the same list?


Here's my stab:

from random import randint, seed
from time import time
from sys import stdout
seed(time())

iterations = 0#DEBUG
def pick_random(seq, prop=bool):
temp = list(seq)
global iterations#DEBUG
while temp:
iterations += 1#DEBUG
i = randint(0, len(temp) - 1)
if prop(temp[i]): return temp[i]
else: del temp[i]


def generate_list(length):
l = list()
for x in xrange(length): l.append(randint(0,1) * randint(1,1000))
return l

count = 0
for x in xrange(1000):
count += 1
print pick_random(generate_list(1000)),

print
print AVERAGE ITERATIONS:, float(iterations) / count




The average number of iterations is 1/p where p is the chance of your
property being true. It's independent of list size! Just remove the
DEBUG lines and it's ready for use.

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


Re: Details about pythons set implementation

2008-01-05 Thread bukzor
On Jan 4, 2:15 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Fri, 04 Jan 2008 09:29:50 -0800, bukzor wrote:
  Why cant you implement  for complex numbers? Maybe I'm being naive, but
  isn't this the normal definition?
  a + bi  c + di iff sqrt(a**2 + b**2)  sqrt(c**2, d**2)

 No, it is not. Ordered comparisons are not defined for complex numbers.
 Which is bigger, 4+2j or 2+4j?

  How do you implement a set without sorting?

 With a hash table.

 Or if you are willing to limit yourself to sets of small integers, you
 can implement it using bit flipping. E.g. 5 is an element of the set if
 bit 5 is on.

  Are you expecting better than O(log n)?

 Sure.

 --
 Steven

Good Answers!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Details about pythons set implementation

2008-01-05 Thread bearophileHUGS
Sion Arrowsmith:
 Because ... how to be polite about this? No, I can't. std::set is
 crap. The implementation is a sorted sequence

What about using hash_map instead? You can use it with GCC too (but
you have to use a trick if you want to use string keys).

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary/hash and '1' versus 1

2008-01-05 Thread bearophileHUGS
Paddy:
 Not really, it seems to me to be going the exact opposite way with
 languages with automatic type conversions being seen as not suited for
 larger programs.

In Java you can add the number 1 to a string, and have it
automatically converted to string before the string join... What do
you think of that feature?

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Taskbar/System Tray

2008-01-05 Thread Sam Garson
hello group,

Using tkinter, is there any way to have the program not showing on the
taskbar, and even better showin in the system tray?
I realise tkinter does not have that much OS specific stuff but maybe there
is a way?

Thanks,

Sam

-- 
I intend to live forever - so far, so good.

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

Re: dictionary/hash and '1' versus 1

2008-01-05 Thread Steven D'Aprano
On Sat, 05 Jan 2008 15:07:10 -0800, bearophileHUGS wrote:

 Paddy:
 Not really, it seems to me to be going the exact opposite way with
 languages with automatic type conversions being seen as not suited for
 larger programs.
 
 In Java you can add the number 1 to a string, and have it automatically
 converted to string before the string join... What do you think of that
 feature?

You mean special-casing the int 1 so that this works?

# Faked!
 x = spam spam spam
 x = x + 1
 x
'spam spam spam1'


but not this?

 x = spam spam spam
 x = x + 2
TypeError: automatic conversion between strings and ints only works for 
the int 1


How bizarre.


The problem with automatic conversions between strings and integers is 
that it isn't clear what the user wants when they do something like this:

 x = '1' + 1

Should x be the string '11' or the int 2? Please justify your answer.


On the other hand, if the language includes separate operators for 
addition and concatenation (say, + and ) then that sort of auto-
conversion is no longer ambiguous:

 '2' + 3
5
 '2'  3
'23'




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


pymat and Matlab6.5

2008-01-05 Thread ali
i want matlab6.5-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Request for help with Image color space conversion

2008-01-05 Thread Robert Kern
ttest wrote:
 Reimplement colorsys.rgb_to_hsv() such that it operates on arrays instead of
 scalars. Only minor modifications are necessary.

 --
 Robert Kern
 
 Thanks!  I'll try and see if a newcomer like me can get his head
 around the array-centric modifications to colorsys.

If you hit any roadblocks, drop in on numpy-discussion, and we'll help you out.

   http://www.scipy.org/Mailing_Lists

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

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


Re: fastest method to choose a random element

2008-01-05 Thread caca
On Jan 5, 9:50 pm, Paul Hankin [EMAIL PROTECTED] wrote:
 On Jan 5, 5:12 pm, Paul Hankin [EMAIL PROTECTED] wrote:



  On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote:

   On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:

Hello, Paul and Arnaud.
While I think about your answers: do you think there is any way to
avoid shuffle?
It may take unnecessary long on a long list most of whose elements
have the property.

  You could generate a random shuffle of range(len(seq)) lazily, and use
  that to iterate over your sequence.

  import random
  import itertools

  def randxrange(n):
  Generate the numbers 0 to n-1 in a random order
  x = range(n)
  for i in xrange(n):
  r = random.randrange(n - i)
  yield x[r]
  x[r] = x[n - i - 1]

  def shuffled(seq):
  Generate the elements of seq in a random order
  return (seq[i] for i in randxrange(len(seq)))

  def pick_random(seq, prop):
  return itertools.ifilter(prop, shuffled(seq)).next()

 At the risk of filling this thread with my posts, here's a much
 simplified and faster version of this code that uses no extra storage.

 import random

 def pick_random(seq, prop):
 L = len(seq)
 for i in xrange(L):
 r = random.randrange(L - i)
 if prop(seq[r]):
 return seq[r]
 seq[r] = seq[L - i - 1]

 --
 Paul Hankin

This one is good. Someone commented that you destroy the list, but
that can be fixed:

 def pick_random(seq, prop):
 L = len(seq)
 for i in xrange(L):
 r = random.randrange(L - i)
 if prop(seq[r]):
 return seq[r]
 seq[r], seq[L - i - 1]= seq[L - i - 1],seq[r]

just pushing elements without the property to the end of the list
(list is mutated, true, but shuffle will do that too). In each
iteration of the for loop, there is only one random element, one check
of the property, and rebinding of elements without altering the lenght
of the list. This is optimal and has all the functionality.

Two more comments:
for buzcor: deleting an element in the middle of a list is costly
for martin: that is certainly enough for me

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


Language type systems (was: How a smart editor could make Postfix type declarations PEP3117 in Python3000 more readable)

2008-01-05 Thread Ben Finney
John Nagle [EMAIL PROTECTED] writes:

(I'm writing as someone who's used and liked very strictly typed
 languages like Ada and Modula.

Python is strictly typed (also known as strongly typed
URL:http://en.wikipedia.org/wiki/Strongly-typed), because its
objects know exactly what type they are and won't contort themselves
into another type unless there's an explicitly defined method for
doing so.

I think you mean you're accustomed to statically-typed languages,
where names are restricted at compile-time in what values they can
refer to. This is as opposed to Python being a dynamically-typed
language: names are not restricted in the type of object they can be
bound to, and the type of a value is determined when that value is
created URL:http://en.wikipedia.org/wiki/Type_system#Type_checking.

 Python actually does unusually well without declarations. Most
 languages that don't have declarations run into difficulties.
 Consider Basic, TCL, and Matlab, to name three rather diverse
 examples. Python managed to avoid the problems those languages
 have.)

Those three diverse examples are all weakly typed languages. Since
Python is strongly-typed and dynamically-typed, this could largely
explain the difference you see in Python doing unusually well without
declarations compared to those languages.

-- 
 \It is the responsibility of intellectuals to tell the truth |
  `\and expose lies.  -- Noam Chomsky |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MRO Error on Multiple Inheritance?

2008-01-05 Thread Ming
Thanks for the all the replies.  CPP2e is the Second Edition of the
book Core Python Programming.

On Jan 4, 6:13 pm, Ben Finney [EMAIL PROTECTED]
wrote:
 Ming [EMAIL PROTECTED] writes:
  I'm working through Wesley Chun's CPP2e and got this error on 13.11.1,
  pp 548 where his interpreter snippet shows no problems:

 I don't know what a CPP2e is. Is it a book? Can you give the ISBN?



  ActivePython 2.5.1.1 (ActiveState Software Inc.) b
  Python 2.5.1 (r251:54863, May  1 2007, 17:47:05) [
  win32
  Type help, copyright, credits or license f
   class A(object): pass
  ...
   class B(A): pass
  ...
   class C(B): pass
  ...
   class D(A, B): pass
  ...
  Traceback (most recent call last):
File stdin, line 1, in module
  TypeError: Error when calling the metaclass bases
  Cannot create a consistent method resolution
  order (MRO) for bases A, B

  (I submitted the problem to the author but I'm not sure I'll ever hear
  back.)  I'm guessing that this kind of diamond inheritance is
  prohibited by the interpreter, and that his lack of error messages
  from the interpretation is due to actually leaving out the class
  B(A): pass  Can someone shed light?  Thanks.

 That's not an example of diamond inheritance
 URL:http://en.wikipedia.org/wiki/Diamond_problem because classes A
 and B are not distinct classes with a *common* base. Instead, they're
 in a direct parent-child relationship.

 So there's no sense in defining class D to inherit from both A *and*
 B. To get a descendent of both those classes, inheriting from B is
 sufficient. It should rather be::

 class D(B): pass

 --
  \ Pinky, are you pondering what I'm pondering? Uh, I think so, |
   `\ Brain, but we'll never get a monkey to use dental floss.  -- |
 _o__)_Pinky and The Brain_ |
 Ben Finney

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


Re: Python web aps - A matter of security

2008-01-05 Thread Daniel Fetchinson
On 1/5/08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hello,

 I'm developing a Python-based web ap, but don't understand how to best
 organize the modules and set permissions for maximum security.

 Here's how the Python code for my ap is organized:

 1) I have Python modules in a project directory. The path to that directory
 is in a  *.pth file  in the .*/pythonx-y/site-packages directory.

 Question: who should own these modules; what groups should have access, and
 how should permissions be set?

 2) I have high-level modules that import the worker-bee modules in the web
 root directory tree that are called by the webserver.

 Questions: who should own these modules, what groups should have access, and
 how should permissions be set?

 3) Is there a better way to organize my Python modules? Are there other
 security issues I should heed?

 Many thanks,

 Lloyd

Are you using any of the many available web frameworks like
turbogears, django, etc?
If so your best option is probably to use the
authentication/authorization capabilities of these frameworks and then
you won't have to worry about it too much.

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


Boa constructor debugging - exec some code at breakpoint?

2008-01-05 Thread Joel
Hey there..
I'm using boa constructor to debug a python application. For my
application, I need to insert break points and execute some piece of
code interactively through shell or someother window when the
breakpoint has been reached. Unfortunately the shell I think is a
seperate process so whatever variables are set while executing in
debugger dont appear in the shell when I try to print using print
statement.

Can anyone tell me how can I do this?

Really appreciate any support, Thanks

Joel
P.S. Please CC a copy of reply to my email ID if possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language type systems (was: How a smart editor could make Postfix type declarations PEP3117 in Python3000 more readable)

2008-01-05 Thread Russ P.
Since
 Python is strongly-typed and dynamically-typed, this
 --

Hyphenating after ly is grammatically incorrect.

  \It is the responsibility of intellectuals to tell the truth |
   `\and expose lies.  -- Noam Chomsky

Never quote Noam Chomsky on truth. He wouldn't know it if it bit
him.

Nice post otherwise. I'm just fooling around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How a smart editor could make Postfix type declarations PEP3117 in Python3000 more readable

2008-01-05 Thread Kay Schluehr
On Jan 5, 7:07 am, John Nagle [EMAIL PROTECTED] wrote:

 Python doesn't really need explicit type declarations.
 They're not needed for correctness, and they're not needed for
 performance.  Take a look at Shed Skin, which is able to hard-compile Python
 using type inference without explicit type declarations.

ShedSkin is not Python.

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


list property fires get on append

2008-01-05 Thread ian
I've created a class that has a property which points at a private
list.  When I try to use the append() function on this list property,
the fget method is fired rather than the fset method.  If I directly
set my property to a literal list, the set method fires.

Here's a stripped down version of my code:

class Hierarchy(object):
_children = []

def __init__(self):
return

def get_children(self):
print(GETTING)
return self._children

def set_children(self, value):
print(SETTING)
self._children = value

children = property(get_children, set_children)

-USAGE--

import Hierarchy
hierarchy = Hierarchy.Hierarchy()
# this fires a get for some reason
hierarchy.children.append( Hierarchy.Hierarchy())
# this fires a set as expected
hierarchy.children = [Hierarchy.Hierarchy()]

--RESULT--

it prints:

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


Re: python interfaces

2008-01-05 Thread r . grimm
On Jan 4, 6:01 pm, Sion Arrowsmith [EMAIL PROTECTED]
wrote:
 hyperboreean  [EMAIL PROTECTED] wrote:
 Why doesn't python provide interfaces trough its standard library?

 Because they're pointless. Java interfaces are a hack around the
 complexities of multiple inheritence. Python does multiple
 inheritence Just Fine (give or take the subtleties of super()) so
 does not need them.

Hallo,
Interfaces are a extremly smart Design Principle in static typed
languages
like Java and C++.
C++ support Interfaces in a form of abstract base classes. They aren't
pointless.
They force the user of a framework to use it in a defined way. You
prescribe in
the base class the usage of a classsystem and allow only in derived
classes
to variate the behavior.
To appreciate Interfaces look at  the Template Methode Pattern (http://
en.wikipedia.org/wiki/Template_method_pattern )
or especially at the Non Virtual Interface ( 
http://www.gotw.ca/publications/mill18.htm
) Idiom from Herb Sutter.

To be short C++ support Interfaces and multiple inheritace.

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


[issue1526] DeprecationWarning in zipfile.py while zipping 113000 files

2008-01-05 Thread Alan McIntyre

Alan McIntyre added the comment:

The reported warning was being produced when writing the end of central
directory record, in ZipFile.close().

Based on a little experiment with 70k test text files, the default
archiver in OS X appears to just use the number of files mod 64k in the
end of central directory record. I tweaked the ZipFile close() method to
do this, and the resulting ZIP file appears to work just fine, both with
the OS X archiver and with ZipFile (without ZIP64 enabled).  

There's a blurb in the ZIP format description about this sort of thing:
If an archive is in ZIP64 format and the value in this field is 0x,
the size will be in the corresponding 8 byte zip64 end of central
directory field.  I don't know if that means the right thing is to
switch the archive to ZIP64 format if more than 64k files are added, though.

If I have time I'll go look at some other open source ZIP
implementations, but I won't swear I'll ever get around to it. :)

--
nosy: +alanmcintyre

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1526
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1739] Testing CIA.vc

2008-01-05 Thread Martin v. Löwis

New submission from Martin v. Löwis:

Will this text show up in CIA?

--
messages: 59284
nosy: loewis
severity: normal
status: open
title: Testing CIA.vc

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1739
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1739] Testing CIA.vc

2008-01-05 Thread Martin v. Löwis

Martin v. Löwis added the comment:

This is a followup, it should get truncated in CIA provided I manage to
type enough text so that it exceeds the 150 character limit. As the
first sentence had only 130 characters, I needed to add a second one.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1739
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1739] Testing CIA.vc

2008-01-05 Thread Martin v. Löwis

Martin v. Löwis added the comment:

Second try: This is a followup, it should get truncated in CIA provided
I manage to type enough text so that it exceeds the 150 character limit.
As the first sentence had only 130 characters, I needed to add a second one.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1739
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1739] Testing CIA.vc

2008-01-05 Thread Martin v. Löwis

Changes by Martin v. Löwis:


--
resolution:  - invalid

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1739
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1739] Testing CIA.vc

2008-01-05 Thread Martin v. Löwis

Martin v. Löwis added the comment:

Test complete.

--
status: open - closed

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1739
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1489] test_socket_ssl hanhs on Windows (deadlock)

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1489
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1223] httplib does not handle ssl end of file properly

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1223
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1589] New SSL module doesn't seem to verify hostname against commonName in certificate

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1589
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1637] urlparse.urlparse misparses URLs with query but no path

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1637
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1482] IMAP4 SSL isn't working

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1482
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1462525] URI parsing library

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1462525
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1424152] urllib/urllib2: HTTPS over (Squid) Proxy fails

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1424152
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1755841] Patch for [ 735515 ] urllib2 should cache 301 redir

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1755841
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue735515] urllib / urllib2 should cache 301 redirections

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila


Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue735515

___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1441530] socket read() can cause MemoryError in Windows

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1441530
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue920573] http libraries throw errors internally

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila


Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue920573

___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue900744] catch invalid chunk length in httplib read routine

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila


Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue900744

___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1486335] httplib: read/_read_chunked failes with ValueError sometime

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1486335
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1411097] httplib patch to make _read_chunked() more robust

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1411097
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1019808] wrong socket error returned

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1019808
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1229646] httplib error checking.

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1229646
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1448934] urllib2+https+proxy not working

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1448934
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1178141] urllib.py overwrite HTTPError code with 200

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1178141
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue970288] Fix for #876637 - Random stack corruption from socketmodule

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila


Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue970288

___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue976613] socket timeout problems on Solaris

2008-01-05 Thread vila

Changes by vila:


--
nosy: +vila


Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue976613

___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >