Re: Making a small change to a large XML document

2007-09-25 Thread Paddy
On Sep 24, 11:38 pm, Dan Stromberg <[EMAIL PROTECTED]> wrote:
> Say I want to take an existing XML document, and change the value="9997"
> and value="9998" to two different numbers, without changing any of the
> rest of the document - not even changing comments or indentation, if
> avoidable.
>
> What's the best way of doing it in python?
>
>   
> 
> 
> 
> 
>   
>
> My .xml file is full of such beans.
>
> I've played around with minidom a little in the past, and I'm targetting
> python 2.5.1.
>
> Thanks!

If it was machine formatted, regular XML, on a unix box then I'd use
sed:

  sed -e 's/value="9997"/value="zzz"/g;s/value="9998"/value="ZZZ"/g' \
infile > outfile

It would work for what you said, but if other modifications are
needed
then it is short enough to throw away if necessary and write a larger
script in Python.

- Paddy.

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


Re: Google and Python

2007-09-25 Thread Hendrik van Rooyen
"Nick Craig-Wood"  wrote:

> Passing file descriptors between processes is one of those things I've
> always meant to have a go with, but the amount of code (in Advanced
> Programming in the Unix Environment) needed to implement it is rather
> disconcerting!  A python module to do it would be great!

I must be missing something here.

What is the advantage of passing the open file rather than just the
fully qualified file name and having the other process open the
file itself?

I would tend to not go this route, but would opt for one "file owner"
process and use a message based protocol if heavy sharing is envisaged.
It feels "more right" to me than to have different processes read and write 
to the same thing.  I can imagine big Dragons with sharp teeth...

- Hendrik

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


Re: An Editor that Skips to the End of a Def

2007-09-25 Thread A.T.Hofkamp
On 2007-09-25, Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:
> In message <[EMAIL PROTECTED]>, Neil Cerutti wrote:

> That's like saying, about a program that, when given "2 + 2", outputs "5",
> that _of course_ it knows the correct answer is "4", it just chooses
> to "modify" the answer before outputting it.
>
> Why does it "choose" to modify your position when you exit insert mode? Does
> the phrase "broken as designed" mean anything to you?

Try to insert 1 character in the middle of a line. You'll end up at the same
position. Now press 'j' (one line down), then '.' (do it again).
I believe that's why.

Great when you have nicely formatted columns of code underneath each other.


(try doing that with your GUI editor with 2 strokes per line of code).



Of course, the same works for a find/edit cycle ('n', check whether edit is
appropiate, and if so: '.')
This combining of commands is what makes the editor powerful.

The cost of that power is a command/insert mode and a steep learning curve.


You may not like the keyboard interface, but that doesn't mean the editor is
not well-designed for its task. In the same way, having the ability to use
multiple input devices doesn't automatically make the editor better.

For example, ever wondered why you on earth you need CTL-C and CTL-V to
copy/paste? Why not simply select with the mouse, then right-click to paste?

All editors have their good and their bad sides. Assuming that anything you
don't like is badly designed is a bit too simple in my opinion.

> And the downside is that the largest single proportion of those commands end
> up being variations on "enter insert mode". Because most of the keystrokes
> you enter during an editing session are in fact text to be input into the
> file, not commands to manipulate that text. So in a modal editor, having to

Depends on what you are doing. When entering new code, yes. When maintaining
code, no (lots of small changes).

In one way or another, you'll have to tell the editor what you want. The cost
of that is either a command/insert mode (vi/vim), a CTL/SHIFT/META-key
combination (emacs), or mouse/menu/submenu/subsubmenu (GUI editors).

I don't know what is best. Probably a matter of taste.


Albert

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


Re: Python script to optimize XML text

2007-09-25 Thread Stefan Behnel
Gabriel Genellina wrote:
> En Mon, 24 Sep 2007 17:36:05 -0300, Robert Dailey <[EMAIL PROTECTED]>
> escribi�:
> 
>> I'm currently seeking a python script that provides a way of
>> optimizing out
>> useless characters in an XML document to provide the optimal size for the
>> file. For example, assume the following XML script:
>>
>> 
>> 
>> 
>>
>> 
>> 
>>
>> By running this through an XML optimizer, the file would appear as:
>>
>> 
> 
> ElementTree does that almost for free.

As the OP is currently using lxml.etree (and as this was a cross-post to
c.l.py and lxml-dev), I already answered on the lxml list.

This is just to mention that the XMLParser of lxml.etree accepts keyword
options to ignore plain whitespace content, comments and processing
instructions, and that you can provide a DTD to tell it what whitespace-only
content really is "useless" in the sense of your specific application.

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

Re: Google and Python

2007-09-25 Thread Paul Rubin
"Hendrik van Rooyen" <[EMAIL PROTECTED]> writes:
> What is the advantage of passing the open file rather than just the
> fully qualified file name and having the other process open the
> file itself?

The idea is that the application is a web server.  The socket listener
accepts connections and hands them off to other processes.  That is,
the file descriptors are handles on network connections that were
opened by the remote client, not disk files that can be opened
locally.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange behavious of the logging module?

2007-09-25 Thread Peter Otten
Vinay Sajip wrote:

> This is a known bug, and not specifically related to logging, though
> it sometimes manifests itself via logging:
> 
> http://bugs.python.org/issue1180193

Yup, thanks for looking into it.

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


Re: Google and Python

2007-09-25 Thread Stefan Behnel
Hendrik van Rooyen wrote:
> "Nick Craig-Wood"  wrote:
> 
>> Passing file descriptors between processes is one of those things I've
>> always meant to have a go with, but the amount of code (in Advanced
>> Programming in the Unix Environment) needed to implement it is rather
>> disconcerting!  A python module to do it would be great!
> 
> I must be missing something here.
> 
> What is the advantage of passing the open file rather than just the
> fully qualified file name and having the other process open the
> file itself?

A "file descriptor" under Unix is not necessarily an open file that you can
find on the hard-disk. It might also be a socket connection or a pipe, or it
might be a file that was opened or created with specific rights or in an
atomic step (like temporary files).

Many things are (or look like or behave like) files in Unix, that's one of its
real beauties.

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


obtaining multiple values from a function.

2007-09-25 Thread Shriphani
hello all,

If I have a function that loops over a few elements and is expected to
throw out a few tuples as the output, then what should I be using in
place of return ?
Shriphani Palakodety.

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


Re: strange behavious of the logging module?

2007-09-25 Thread Christian Meesters
Peter Otten wrote:

> Vinay Sajip wrote:
> 
>> This is a known bug, and not specifically related to logging, though
>> it sometimes manifests itself via logging:
>> 
>> http://bugs.python.org/issue1180193
> 
> Yup, thanks for looking into it.
> 
> Peter
Thanks Vinay, but I am curious how issue 1180193 is related to the "bug"
Peter and me described: I do not have any *.pyc file around. As I kept
changing the file during development I used to call the program directly
using a link in my PATH. Hence no *.pyc file got created at all. 

However, does anybody know a suggestion for a work-around?

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


Re: obtaining multiple values from a function.

2007-09-25 Thread Peter Otten
Shriphani wrote:

> If I have a function that loops over a few elements and is expected to
> throw out a few tuples as the output, then what should I be using in
> place of return ?

Use a generator and have it /yield/ rather than /return/ results:

>>> def f(items):
... for item in items:
... yield item.isdigit(), item.isupper()
... 
>>> for result in f("AAA bbb 111".split()):
... print result
... 
(False, True)
(False, False)
(True, False)

This is a very memory-efficient approach, particularly if the input items
are created on the fly, e. g. read from a file one at a time.

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


Re: obtaining multiple values from a function.

2007-09-25 Thread Ben Finney
Shriphani <[EMAIL PROTECTED]> writes:

> If I have a function that loops over a few elements and is expected to
> throw out a few tuples as the output, then what should I be using in
> place of return ?

If it makes sense for the set of results to be returned all at once,
then return the object that collects them all together — a list of
tuples, for example.


If, instead, it makes sense for the results to be iterated over, you
can write a function that yields results one at a time, without
necessarily knowing in advance what the entire set will be::

>>> def fib(max_result):
... """ Yield numbers in the Fibonacci sequence
... to a maximum value of max_result. """
... prev_results = [0, 0]
... result = 1
... while result < max_result:
... yield result
... prev_results = [prev_results[1], result]
... result = sum(prev_results)
...

The function, when called, will return a generator object that you can
either iterate over::

>>> fib_generator = fib(100)
>>> for n in fib_generator:
... print n
...
1
1
2
3
5
8
13
21
34
55
89

or directly call its 'next' method to get one result at a time until
it raises a 'StopIteration' exception::

>>> fib_generator = fib(5)
>>> fib_generator.next()
1
>>> fib_generator.next()
1
>>> fib_generator.next()
2
>>> fib_generator.next()
3
>>> fib_generator.next()
Traceback (most recent call last):
  File "", line 1, in ?
StopIteration

-- 
 \"I have one rule to live by: Don't make it worse."  -- Hazel |
  `\  Woodcock |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: strange behavious of the logging module?

2007-09-25 Thread Peter Otten
Christian Meesters wrote:

> Peter Otten wrote:
> 
>> Vinay Sajip wrote:
>> 
>>> This is a known bug, and not specifically related to logging, though
>>> it sometimes manifests itself via logging:
>>> 
>>> http://bugs.python.org/issue1180193
>> 
>> Yup, thanks for looking into it.
>> 
>> Peter
> Thanks Vinay, but I am curious how issue 1180193 is related to the "bug"
> Peter and me described: I do not have any *.pyc file around. As I kept
> changing the file during development I used to call the program directly
> using a link in my PATH. Hence no *.pyc file got created at all. 

The problem is not caused by the pyc-file for your script, but by
the logging/__init__.pyc file in your python installation. You
can check if you are affected by the bug by typing

>>> logging.info.func_code.co_filename
'logging/__init__.py'
>>> logging._srcfile
'/usr/lib/python2.5/logging/__init__.py'

in the interpreter. If you get different paths like in "logging" and
"/usr/lib/python2.5/logging" in the above example you are affected.

> However, does anybody know a suggestion for a work-around?

You could try setting

logging._srcfile = logging.info.func_code.co_filename

manually, but that might break other things. Or you recreate the pyc-files
of your distribution. Again, I don't know what might break...

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


sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Mark Summerfield
Hi,

Below is a PEP proposal for a sorteddict. It arises out of a
discussion on this list that began a few weeks ago with the subject of
"An ordered dictionary for the Python library?", and a similar one on
the P3K mailing list with the subject "ordered dict for p3k
collections?".

If there is positive feedback I will submit the PEP to the reviewers,
so if you think it is a good idea please say so. (I'm sure that if you
_don't_ like it you'll tell me anyway:-)

PEP: XXX
Title: Sorted Dictionary
Version: $Revision$
Last-Modified: $Date$
Author: Mark Summerfield
Status: Draft
Type: Standards Track
Content-Type: text/plain
Created: 25-Sep-2007
Python-Version: 2.6
Post-History:


Abstract

This PEP proposes the addition of a sorted dictionary class to the
standard library's collections module.


Rationale

When handling collections of key-value data, it is often
convenient to
access the data in key order.  One way to do this is to use an
unsorted
data structure (e.g., a Python dict), and then sort the keys as
needed.
Another way is to use a sorted data structure (e.g., a sorteddict
as
proposed in this PEP), and simply access the keys, knowing that
they
are always in sorted order.

Both approaches make sense in the right circumstances, but Python
currently only supports the first approach out of the box.  A
sorteddict never needs sorting and is ideal for creating indexes
to
data where the keys are based on some property of the data.
Adding a
sorteddict to the collections module would not add significantly
to the
size of Python's standard library, but would provide a very useful
data
structure.


Specification

The proposed sorteddict has the same API to the builtin dict, so
can be
used as a drop-in replacement.  The only behavioural difference
being
that any list returned by the sorteddict (whether of keys, values,
or
items) will be in key order, and similarly any iterator returned
will
iterate in key order.

In addition, the keys() method has two optional arguments:

keys(firstindex : int = None, secondindex : int = None) -> list of
keys

The parameter names aren't nice, but using say "start" and "end"
would
be misleading since the intention is for the parameters to work
like
they do in range(), e.g.

sd.keys()   # returns a list of all the sorteddict's keys
sd.keys(10) # returns a list of the first 10 keys
sd.keys(19, 35) # returns a list of the 19th-34th keys
inclusive

If an out of range index is given, an IndexError exception is
raised.

Since the sorteddict's data is always kept in key order, indexes
(integer offsets) into the sorteddict make sense.  Five additional
methods are proposed to take advantage of this:

key(index : int) -> value

item(index : int) -> (key, value)

value(index : int) -> key

set_value(index : int, value)

delete(index : int)

Items and values can still be accessed using the key, e.g.,
sd[key],
since all the dict's methods are available.


Examples

To keep a collection of filenames on a case-insensitive file
system in
sorted order, we could use code like this:

files = collections.sorteddict.sorteddict()
for name in os.listdir("."):
files[name.lower()] = name

We can add new filenames at any time, safe in the knowledge that
whenever we call files.values(), we will get the files in
case-insensitive alphabetical order.

To be able to iterate over a collection of data items in various
predetermined orders, we could maintain two or more sorteddicts:

itemsByDate = collections.sorteddict.sorteddict()
itemsByName = collections.sorteddict.sorteddict()
itemsBySize = collections.sorteddict.sorteddict()
for item in listOfItems:
itemsByDate["%s\t%17X" % (item.date, id(item))] = item
itemsByName["%s\t%17X" % (item.name, id(item))] = item
itemsBySize["%s\t%17X" % (item.size, id(item))] = item

Here we have used the item IDs to ensure key uniqueness.

Now we can iterate in date or name order, for example:

for item in itemsByDate:
print item.name, item.date


Implementation

A pure Python implementation is available at:

http://pypi.python.org/pypi/sorteddict


Copyright

This document has been placed in the public domain.

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


Re: Google and Python

2007-09-25 Thread Bryan Olson
Alex Martelli wrote:
> Bryan Olson <[EMAIL PROTECTED]> wrote:
>...
>>> YouTube (one of Google's most valuable properties) is essentially
>>> all-Python (except for open-source infrastructure components such as
>>> lighttpd).  Also, at Google I'm specifically "Uber Tech Lead, Production
>>> Systems": while I can't discuss details, my main responsibilities relate
>>> to various software projects that are part of our "deep infrastructure",
>>> and our general philosophy there is "Python where we can, C++ where we
>>> must". 
>> Good motto. So is most of Google's code base now in
>> Python? About what is the ratio of Python code to C++
>> code? Of course lines of code is kine of a bogus measure.
>> Of all those cycles Google executes, about what portion
>> are executed by a Python interpreter?
> 
> I don't have those numbers at hand, and if I did they would be
> confidential: you know that Google doesn't release many numbers at all
> about its operations, most particularly not about our production
> infrastructure (not even, say, how many server we have, in how many data
> centers, with what bandwidth, and so on).
> 
> Still, I wouldn't say that "most" of our codebase is in Python: 

Can you see how that motto, "Python where we can, C++ where
we must," might lead people to a false impression of how much
Google uses Python versus C++, especially on "production
systems"? I tried to Google-up that motto; your post seems
to be Google's first disclosure of it.

[...]
> To me, on the contrary, it seems
> self-evident that if a company X enjoys great success employing
> technique Y, this *DOES* make something of a case for another company Z
> to seriously consider and probably try out Y, when attempting tasks
> analogous to those X has had success with, to see if some of the success
> could not be replicable in Z's own similar tasks. 

Similar tasks to what made Google a great success? I'm not
seeing many of those.

People seem to think they should duplicate the way Google
does things, but without deep understanding of how and why
they work for Google. An impossible task, because it's
about the most un-Googley thing anyone could do.

> This is the heart of
> "benchmarking" and "industry best practices" -- and why many companies
> in the role of X aren't all that forthcoming about publicizing all the
> details of their Y's, just in case Z's endeavours should put Z in
> competition with X (this always needs to be balanced with the many
> _advantages_ connected to publicizing some of those Y's, of course).

In the case of Google, there's way, way too much hidden for
people to reason based on what Google does. In this thread,
did you notice how far wrong people went about how Google's
stuff works?


> Such empirical support, while of course far from infallible (one will
> always have to take into consideration many details, and the devil is in
> the details), tends to perform vastly better in supporting decision
> making than purely abstract considerations bereft of any such empirical
> underpinnings.

Wikipedia is in PHP, Slashdot in Perl, Basecamp in Ruby. They
all rock, but more importantly, we can look under the hood. If
Wikipedia makes a weaker case for PHP than Google for Python,
it's largely because the whole story is never as neat as a
trickle of selective disclosures.


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


Re: Google and Python

2007-09-25 Thread Bryan Olson
Paul Rubin wrote:
> You can also pass the open sockets around between processes instead of
> reverse proxying, using the SCM_RIGHTS message on Unix domain sockets
> under Linux, or some similar mechanism under other Unixes (no idea
> about Windows).  Python does not currently support this but one of
> these days I want to get around to writing a patch.

Windows can do it, but differently. What a surprise.
I just looked it up: WSADuplicateSocket() is the key.
Windows and Unix modules with the same Python interface
would rock.


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


hacking,anti-hacking,registry tweaks,compter tricks

2007-09-25 Thread e.expelliarmus

check this out buddies. kool website for:
* hacking and anti hacking tricks
* anti hackng tricks.
* registry tweaks
* orkut tricks
* small virus
* computer tricks
and loads of different tricks...
www.realm-of-tricks.blogspot.com
www.registrydecoded.blogspot.com

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


Inserting an element into existing xml file

2007-09-25 Thread Anand
Hi,

I'm new to Python. we are using python2.4.

I wanted to insert an element into an existing xml file. Can anyone
help me with this?
I've seen lxml and elementTree in python2.5 has some API's to insert
into existing xml file.
We cant use python 2.5 due to some limitations. So how can we do it in
2.4?

Thanks in Advance,
Anand

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


Re: An Editor that Skips to the End of a Def

2007-09-25 Thread Bjoern Schliessmann
Lawrence D'Oliveiro wrote:
> That's like saying, about a program that, when given "2 + 2",
> outputs "5", that _of course_ it knows the correct answer is "4",
> it just chooses to "modify" the answer before outputting it.

No. Which laws say how transitions between modes have to be? Thus, I
know laws saying 2 and 2 is 4.
 
> Why does it "choose" to modify your position when you exit insert
> mode? Does the phrase "broken as designed" mean anything to you?

Does the phrase "everything I don't like is stupid" mean anything to
you? Honestly, if you don't like it, either propose improvement or
stop using it (and complaining about it). Your preference with user
interfaces is obviously different. (Personally, I prefer single
strokes to breaking my fingers with Esc-Meta-Alt-Control-Shift.
:) )
 
> Why do you need so many ways to enter insert mode?

It can be convenient. For you apprently not, though.
 
> And the downside is that the largest single proportion of those
> commands end up being variations on "enter insert mode". Because
> most of the keystrokes you enter during an editing session are in
> fact text to be input into the file, not commands to manipulate
> that text. 

Strange -- mostly, this is not the case for me. When refactoring
code for example, I jump around, copy, paste and modify many times.

> So in a modal editor, having to jump in and out of insert mode all
> the time just adds to the number of keystrokes you have to type.

Much better than accessing special functions with finger breaking
key combinations. IMHO.

Regards,


Björn

-- 
BOFH excuse #226:

A star wars satellite accidently blew up the WAN.

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


Re: obtaining multiple values from a function.

2007-09-25 Thread Paul Rudin
Ben Finney <[EMAIL PROTECTED]> writes:


>
> If, instead, it makes sense for the results to be iterated over, you
> can write a function that yields results one at a time, without
> necessarily knowing in advance what the entire set will be::
>
> >>> def fib(max_result):

Going off on a tangent a bit, but I was idly considering the absence
of itertools.ireduce the other day. A problem is that reduce gives a
single result, so it's not clear what ireduce would do (perhaps why
it's not there). One obvious candidate would be to give the whole
sequence of partial reductions. I'm not sure if this would be
generally useful, but it would give a succinct way to do the Fibonacci
sequence:

itertools.ireduce(operator.add, itertools.count())

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread A.T.Hofkamp
On 2007-09-25, Mark Summerfield <[EMAIL PROTECTED]> wrote:
> If there is positive feedback I will submit the PEP to the reviewers,
> so if you think it is a good idea please say so. (I'm sure that if you
> _don't_ like it you'll tell me anyway:-)

I like the idea, ie +1.

> This PEP proposes the addition of a sorted dictionary class to the
> standard library's collections module.

You don't seem to mention the sort criterium. I'd suggest to use the __lt__
operator, which you probably intended since it is commonly used.

Also, can I specify a custom sort function, as with list.sort() ?

> In addition, the keys() method has two optional arguments:
>
> keys(firstindex : int = None, secondindex : int = None) -> list of

Not sure this is a good idea. Wouldn't simply

mysorteddict.keys()[firstindex:secondindex]

be much better? It can do all you propose, and more (with iterators/generators
and such). I see no need to implement it inside the sorteddict as well.


> Since the sorteddict's data is always kept in key order, indexes
> (integer offsets) into the sorteddict make sense.  Five additional
> methods are proposed to take advantage of this:
>
> key(index : int) -> value
>
> item(index : int) -> (key, value)
>
> value(index : int) -> key
>
> set_value(index : int, value)
>
> delete(index : int)

I wouldn't do this. It breaks compability with the normal dict. A beginning
user will expect dict and sorteddict to behave the same (except for
sortedness), including their set of supporting functions imho.

Otherwise, please make a case for them (and maybe even a new PEP to get them in
both types of dicts).

> Examples
>
> To keep a collection of filenames on a case-insensitive file
> system in
> sorted order, we could use code like this:
>
> files = collections.sorteddict.sorteddict()
> for name in os.listdir("."):
> files[name.lower()] = name

The more interesting case would be to you preserve case of the files within the
keys.

I usually need this data structure with an A* algorithm implementation, where I
need to obtain the cheapest solution found so far.

> for item in listOfItems:
> itemsByDate["%s\t%17X" % (item.date, id(item))] = item
> itemsByName["%s\t%17X" % (item.name, id(item))] = item
> itemsBySize["%s\t%17X" % (item.size, id(item))] = item

Wouldn't a line like "itemsBySize[(item.size, id(item))] = item" do as well?

(or with a custom sort function on items?)

> Now we can iterate in date or name order, for example:
>
> for item in itemsByDate:
> print item.name, item.date

Hmm, not with dict:

>>> for x in {1:10, 2:20}:
...   print x
...
1
2

So you should get your "%s\t%17X" strings here.


Sincerely,
Albert
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: obtaining multiple values from a function.

2007-09-25 Thread Carsten Haese
On Tue, 2007-09-25 at 10:41 +0100, Paul Rudin wrote:
> Going off on a tangent a bit, but I was idly considering the absence
> of itertools.ireduce the other day. A problem is that reduce gives a
> single result, so it's not clear what ireduce would do (perhaps why
> it's not there). One obvious candidate would be to give the whole
> sequence of partial reductions. I'm not sure if this would be
> generally useful, but it would give a succinct way to do the Fibonacci
> sequence:
> 
> itertools.ireduce(operator.add, itertools.count())

Let's try it:

>>> def ireduce(op, iterable, partial=0):
...   for nxt in iterable:
... partial = op(partial, nxt)
... yield partial
... 
>>> import operator
>>> from itertools import islice, count
>>> 
>>> for x in islice(ireduce(operator.add, count()), 0, 10):
...   print x
... 
0
1
3
6
10
15
21
28
36
45

That's not the Fibonacci sequence.

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


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


ANN: 555-BOOM! version 0.6

2007-09-25 Thread Greg Ewing
I have released a post-competition version of my PyWeek 5 game competition 
entry, 555-BOOM!.

http://www.cosc.canterbury.ac.nz/greg.ewing/python/PyWeek5/index.html

This version has been tidied up in various ways, and a few more levels added. I 
have made a number of improvements to the level editor; it should be easier and 
less confusing to use now. Documentation for the level editor is included.

What is it?

This is a game involving telephones, relays, rotary switches, and other 
electrical things that make nice whirring and clicking noises. As well as 
challenging yourself to solve the puzzles, you can also use the comprehensive 
built-in level editor to create new puzzles for yourself and others, or just to 
play around and have fun with the parts.

--
Gregory Ewing
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Albow 1.1 and Humerus 1.0

2007-09-25 Thread Greg Ewing
I have released an updated version of my Albow gui library for PyGame, 
incorporating improvements made to it for my PyWeek 5 entry, and also Humerus, 
a 
skeleton game framework built on Albow.

http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/

What is it?

Albow is a rather basic, no-frills widget set for creating a GUI using PyGame. 
It has been developed over the course of my last three PyWeek game competition 
entries. I am documenting and releasing it as a separate package so that others 
may benefit from it, and so that it will be permissible for use in future 
PyGame 
entries.

--
Gregory Ewing
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie completely confused

2007-09-25 Thread Roel Schroeven
Jeroen Hegeman schreef:
> Thanks for the comments,
> 
>> (First, I had to add timing code to ReadClasses: the code you posted
>> doesn't include them, and only shows timings for ReadLines.)
>>
>> Your program uses quite a bit of memory. I guess it gets harder and
>> harder to allocate the required amounts of memory.
> 
> Well, I guess there could be something in that, but why is there a  
> significant increase after the first time? And after that, single- 
> trip time pretty much flattens out. No more obvious increases.

Sorry, I have no idea.

>> If I change this line in ReadClasses:
>>
>>  built_classes[len(built_classes)] = HugeClass(long_line)
>>
>> to
>>
>>  dummy = HugeClass(long_line)
>>
>> then both times the files are read and your data structures are built,
>> but after each run the data structure is freed. The result is that  
>> both
>> runs are equally fast.
> 
> Isnt't the 'del LINES' supposed to achieve the same thing? And  
> really, reading 30MB files should not be such a problem, right? (I'm  
> also running with 1GB of RAM.)

'del LINES' deletes the lines that are read from the file, but not all 
of your data structures that you created out of them.
Now, indeed, reading 30 MB files should not be a problem. And I am 
confident that just reading the data is not a problem. To make sure I 
created a simple test:

import time

input_files = ["./test_file0.txt", "./test_file1.txt"]

total_start = time.time()
data = {}
for input_fn in input_files:
 file_start = time.time()
 f = file(input_fn, 'r')
 data[input_fn] = f.read()
 f.close()
 file_done = time.time()
 print '%s: %f to read %d bytes' % (input_fn, file_done - 
file_start, len(data))
total_done = time.time()
print 'all done in %f' % (total_done - total_start)


When I run that with test_file0.txt and test_file1.txt as you described 
(each 30 MB), I get this output:

./test_file0.txt: 0.26 to read 1 bytes
./test_file1.txt: 0.251000 to read 2 bytes
all done in 0.521000

Therefore I think the problem is not in reading the data, but in 
processing it and creating the data structures.

>> You read the files, but don't use the contents; instead you use
>> long_line over and over. I suppose you do that because this is a test,
>> not your actual code?
> 
> Yeah ;-) (Do I notice a lack of trust in the responses I get? Should  
> I not mention 'newbie'?)

I didn't mean to attack you; it's just that the program reads 30 MB of 
data, twice, but doesn't do anything with it. It only uses the data that 
was stored in long_lines, and which never is replaced. That is very 
strange for real code, but as a test it can have it's uses. That's why I 
asked.

> Let's get a couple of things out of the way:
> - I do know about meaningful variable names and case-conventions,  
> but ... First of all I also have to live with inherited code (I don't  
> like people shouting in their code either), and secondly (all the  
> itemx) most of these members normally _have_ descriptive names but  
> I'm not supposed to copy-paste the original code to any newsgroups.

Ok.

> - I also know that a plain 'return' in python does not do anything  
> but I happen to like them. Same holds for the sys.exit() call.

Ok.

> - The __init__ methods normally actually do something: they  
> initialise some member variables to meaningful values (by calling the  
> clear() method, actually).
> - The __clear__ method normally brings objects back into a well- 
> defined 'empty' state.
> - The __del__ methods are actually needed in this case (well, in the  
> _real_ code anyway). The python code loads a module written in C++  
> and some of the member variables actually point to C++ objects  
> created dynamically, so one actually has to call their destructors  
> before unbinding the python var.

That sounds a bit weird to me; I would think such explicit memory 
management belongs in the C++ code instead of in the Python code, but I 
must admit that I know next to nothing about extending Python so I 
assume you are right.

> All right, thanks for the tips. I guess the issue itself is still  
> open, though.

I'm afraid so. Sorry I can't help.

One thing that helped me in the past to speed up input is using memory 
mapped I/O instead of stream I/O. But that was in C++ on Windows; I 
don't know if the same applies to Python on Linux.

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Andrew Durdin
On 9/25/07, Mark Summerfield <[EMAIL PROTECTED]> wrote:
>
> Since the sorteddict's data is always kept in key order, indexes
> (integer offsets) into the sorteddict make sense.  Five additional
> methods are proposed to take advantage of this:
>
> key(index : int) -> value
>
> item(index : int) -> (key, value)
>
> value(index : int) -> key
>
> set_value(index : int, value)
>
> delete(index : int)

But what about using non-sequential integer keys (something I do quite often)?

e.g. sorteddict({1:'a', 3:'b': 5:'c', 99:'d'})[3]  should return 'b', not 'd'.

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


Re: obtaining multiple values from a function.

2007-09-25 Thread Paul Rudin
Carsten Haese <[EMAIL PROTECTED]> writes:


> ...
> That's not the Fibonacci sequence.

Bah, you're right of course, I should be more more careful before
posting these things. 

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


ANN: PyPE 2.8.7

2007-09-25 Thread Josiah Carlson

=== What is PyPE? ===
PyPE (Python Programmers' Editor) was written in order to offer a
lightweight but powerful editor for those who think emacs is too much
and idle is too little. Syntax highlighting is included out of the box,
as is multiple open documents via tabs.

Beyond the basic functionality, PyPE offers an expandable source tree,
filesystem browser, draggable document list, todo list, filterable
function list, find and replace bars (no dialog to find or replace simple
strings), recordable and programmable macros, spell checker,
reconfigurable menu hotkeys, triggers, find in files, external process
shells, and much more.

=== More Information ===

If you would like more information about PyPE, including screenshots,
where to download the source or windows binaries, bug tracker, contact
information, or a somewhat complete listing of PyPE's features, visit
PyPE's home on the web:

http://pype.sf.net/index.shtml

If you have any questions about PyPE, please contact me, Josiah Carlson,
aka the author of PyPE, at jcarlson at uci.edu (remember to include
"PyPE" in the subject).


PyPE 2.8.7 includes the following changes and bugfixes since release
2.8.5:

# PyPE 2.8.7 -
(fixed) some bugs related to the parsers module movement.
(fixed) ordering of user profile path discovery to not break when confronted
with insane 'HOME' environment variable on Windows (will use USERPROFILE or
HOMEDRIVE/HOMEPATH first).
(fixed) unrepr mechansim can now handle negative value storage for disabled
realtime options, etc.


# PyPE 2.8.6 -
(fixed) a bug with "Wrap Try/Except" as per emailed bug report from Ian York.
(added) ability to choose what port PyPE will listen on via --port= .
(fixed) workspaces in wxPython 2.8+, patch thanks to Craig Mahaney.
(added) explicit exclude dirs for find in files, patch thanks to Craig
Mahaney.
(added) paste and down mechanism to paste and move the cursor down, patch
thanks to Craig Mahaney.
(added) delete right mechanism to delete everything from the cursor to the end
of the line, patch thanks to Craig Mahaney.
(added) delete line mechanism to delete the current line, patch thanks to
Craig Mahaney.
(added) paste rectangle command for rectangular pasting, patch thanks to Craig
Mahaney.
(fixed) support for alternate background colors thanks to bug report from
Craig Mahaney.
(added) macro support to Craig Mahaney's added functionality.
(added) implementation for regular expression replacements, possibly to be
integrated as part of a 'replace in all open documents' in the future.
(added) automatic spellcheck for text and tex documents of up to 200,000 byes
in size.  Will only spellcheck if the user has enabled "check syntax" in the
"Realtime Options".
(fixed) issue when trying to save language settings when cursor position is
not to be saved.
(added) support for \chapter section delimiter in *tex files.
(fixed) issue that prevented the highest level source listing from being
sorted in the Name and Line sorted source trees.
(changed) rather than reading and executing a file for configuration loading,
we now use a variant of the 'unrepr()' mechanism with support for True/False.
(changed) find/replace bar now uses variant of 'unrepr()' rather than the
compiler module directly.
(changed) moved parsers.py to plugins and stopped using import * to get its
contents.
-- 
http://mail.python.org/mailman/listinfo/python-list


buttons keep jumping, frame loads on top of itself

2007-09-25 Thread Mridula Ramesh
hi.

my actual code is a bit too long to post here, but this is how the code
works : the application loads, the first screen appears. it is to view the
records in a database, so you can scroll and view records by clicking on the
standard navigation buttons ( |<, <<, >>, >| ).

the problem is that since all my navigation code is in one class, and the
display class is called from class navigation() to make frame and the
buttons, the frame and buttons are reloaded afresh each time.  this means
that if the text fields' lengths vary, the frame messily tends to move
around to accommodate them.

1. is it wrong (ie. inefficient/ slower/ BAD pgming practice!) to reload the
frame and its children widgets every time?
2. is there a way to clear the frame of the child widgets? - this would
solve the problem of the Jumping Buttons! frame.destroy() seems to be
crashing my application.

thank you for your patience!

regards,
mridula.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Inserting an element into existing xml file

2007-09-25 Thread Stefan Behnel
Anand wrote:
> I'm new to Python. we are using python2.4.
> 
> I wanted to insert an element into an existing xml file. Can anyone
> help me with this?
> I've seen lxml and elementTree in python2.5 has some API's to insert
> into existing xml file.
> We cant use python 2.5 due to some limitations. So how can we do it in
> 2.4?

Install lxml and read the tutorial. It should be easy to grasp, as the API is
very simple.

http://codespeak.net/lxml/tutorial.html
http://codespeak.net/lxml/tutorial.html#elements-are-lists

It's compatible to ElementTree, which you can also install on Python 2.4 (it's
what later became part of Python 2.5).

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Mark Summerfield
On 25 Sep, 10:53, "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote:
> On 2007-09-25, Mark Summerfield <[EMAIL PROTECTED]> wrote:
>
> > If there is positive feedback I will submit the PEP to the reviewers,
> > so if you think it is a good idea please say so. (I'm sure that if you
> > _don't_ like it you'll tell me anyway:-)
>
> I like the idea, ie +1.
>
> > This PEP proposes the addition of a sorted dictionary class to the
> > standard library's collections module.
>
> You don't seem to mention the sort criterium. I'd suggest to use the __lt__
> operator, which you probably intended since it is commonly used.

You are right that I implicitly use __lt__ (or __cmp__ if there's no
__lt__).

> Also, can I specify a custom sort function, as with list.sort() ?

No. That would make comparing two sorteddicts problematic. You can
always use munged string keys as my second example shows.

> > In addition, the keys() method has two optional arguments:
>
> > keys(firstindex : int = None, secondindex : int = None) -> list of
>
> Not sure this is a good idea. Wouldn't simply
>
> mysorteddict.keys()[firstindex:secondindex]
>
> be much better? It can do all you propose, and more (with iterators/generators
> and such). I see no need to implement it inside the sorteddict as well.

The reason for making it part of th

> > Since the sorteddict's data is always kept in key order, indexes
> > (integer offsets) into the sorteddict make sense.  Five additional
> > methods are proposed to take advantage of this:
>
> > key(index : int) -> value
>
> > item(index : int) -> (key, value)
>
> > value(index : int) -> key
>
> > set_value(index : int, value)
>
> > delete(index : int)
>
> I wouldn't do this. It breaks compability with the normal dict. A beginning
> user will expect dict and sorteddict to behave the same (except for
> sortedness), including their set of supporting functions imho.
>
> Otherwise, please make a case for them (and maybe even a new PEP to get them 
> in
> both types of dicts).
>
> > Examples
>
> > To keep a collection of filenames on a case-insensitive file
> > system in
> > sorted order, we could use code like this:
>
> > files = collections.sorteddict.sorteddict()
> > for name in os.listdir("."):
> > files[name.lower()] = name
>
> The more interesting case would be to you preserve case of the files within 
> the
> keys.
>
> I usually need this data structure with an A* algorithm implementation, where 
> I
> need to obtain the cheapest solution found so far.
>
> > for item in listOfItems:
> > itemsByDate["%s\t%17X" % (item.date, id(item))] = item
> > itemsByName["%s\t%17X" % (item.name, id(item))] = item
> > itemsBySize["%s\t%17X" % (item.size, id(item))] = item
>
> Wouldn't a line like "itemsBySize[(item.size, id(item))] = item" do as well?
>
> (or with a custom sort function on items?)
>
> > Now we can iterate in date or name order, for example:
>
> > for item in itemsByDate:
> > print item.name, item.date
>
> Hmm, not with dict:
>
> >>> for x in {1:10, 2:20}:
>
> ...   print x
> ...
> 1
> 2
>
> So you should get your "%s\t%17X" strings here.
>
> Sincerely,
> Albert


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


Re: Inserting an element into existing xml file

2007-09-25 Thread Anand
On Sep 25, 3:20 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Anand wrote:
> > I'm new to Python. we are using python2.4.
>
> > I wanted to insert an element into an existing xml file. Can anyone
> > help me with this?
> > I've seen lxml and elementTree in python2.5 has some API's to insert
> > into existing xml file.
> > We cant use python 2.5 due to some limitations. So how can we do it in
> > 2.4?
>
> Install lxml and read the tutorial. It should be easy to grasp, as the API is
> very simple.
>
> http://codespeak.net/lxml/tutorial.htmlhttp://codespeak.net/lxml/tutorial.html#elements-are-lists
>
> It's compatible to ElementTree, which you can also install on Python 2.4 (it's
> what later became part of Python 2.5).
>
> Stefan


Hi Stefan,

First of all thanks for your reply.

I'm Afraid to say, I can't use lxml or elementTree as it requires many
legal approvals and there is high chances of not getting it through.
So Do you have any other method / idea just by using plain 2.4 to
accomplish the task

Cheers,
Anand

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Mark Summerfield
On 2007-09-25, Andrew Durdin wrote:
> On 9/25/07, Mark Summerfield <[EMAIL PROTECTED]> wrote:
> > Since the sorteddict's data is always kept in key order, indexes
> > (integer offsets) into the sorteddict make sense.  Five additional
> > methods are proposed to take advantage of this:
> >
> > key(index : int) -> value
> >
> > item(index : int) -> (key, value)
> >
> > value(index : int) -> key
> >
> > set_value(index : int, value)
> >
> > delete(index : int)
>
> But what about using non-sequential integer keys (something I do quite
> often)?
>
> e.g. sorteddict({1:'a', 3:'b': 5:'c', 99:'d'})[3]  should return 'b', not
> 'd'.
>
> Andrew

The sorteddict really does work in key order, so:

d = sorteddict({1:'a', 3:'b', 5:'c', 99:'d'})
d.items()
[(1, 'a'), (3, 'b'), (5, 'c'), (99, 'd')]

If you do d[3] you will get 'd' since that is the 4th sequential item.
If you want to get the item with _key_ 3 then use value():

d.value(3)
'd'


PS In my previous reply I got my example wrong a second time: should have 
been:
for item in itemsByDate.values():...



-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu

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


Re: ANN: PyPE 2.8.7

2007-09-25 Thread stef
Josiah Carlson wrote:
> === What is PyPE? ===
> PyPE (Python Programmers' Editor) was written in order to offer a
> lightweight but powerful editor for those who think emacs is too much
> and idle is too little. Syntax highlighting is included out of the box,
> as is multiple open documents via tabs.
>
>   
sounds very good,
so now I want to try it ...
... the windows ansi zip file is corrupted :-(
... the unicode version crashes :-(

This is what the log file tells:
Traceback (most recent call last):
  File "pype.py", line 110, in ?
  File "zipextimporter.pyc", line 78, in load_module
  File "configuration.pyc", line 149, in ?
Exception: Unable to create config directory: 'G:\\.pype'

I don't have a G-drive ;-)

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Mark Summerfield
On 2007-09-25, Andrew Durdin wrote:
> On 9/25/07, Mark Summerfield <[EMAIL PROTECTED]> wrote:
> > Since the sorteddict's data is always kept in key order, indexes
> > (integer offsets) into the sorteddict make sense.  Five additional
> > methods are proposed to take advantage of this:
> >
> > key(index : int) -> value
> >
> > item(index : int) -> (key, value)
> >
> > value(index : int) -> key
> >
> > set_value(index : int, value)
> >
> > delete(index : int)
>
> But what about using non-sequential integer keys (something I do quite
> often)?
>
> e.g. sorteddict({1:'a', 3:'b': 5:'c', 99:'d'})[3]  should return 'b', not
> 'd'.
>
> Andrew

Hmmm, managed to confuse myself with 'b' and 'd'!

d = sorteddict({1:"one", 3:"three", 5:"five", 99:"ninetynine"})

d.items()

[(1, 'one'), (3, 'three'), (5, 'five'), (99, 'ninetynine')]

d[3], d.value(3)

('three', 'ninetynine')

So using [] returns the value for the given key and using value()
returns the value for the given index position.

-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu

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


Re: ANN: PyPE 2.8.7

2007-09-25 Thread stef
Another problem,
I tried to run PyPE in my "old IDE",
and get the following error:

Traceback (most recent call last):
  File "D:\temp\PyPE-2.8.7-src\PyPE-2.8.7\pype.py", line 20, in ?
wxversion.ensureMinimal(v)
  File "P:\Python\lib\site-packages\wxversion.py", line 178, in 
ensureMinimal
raise VersionError("wxversion.ensureMinimal() must be called before 
wxPython is imported")
VersionError: wxversion.ensureMinimal() must be called before wxPython 
is imported
> cheers,
> Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Duncan Booth
Mark Summerfield <[EMAIL PROTECTED]> wrote:

> When handling collections of key-value data, it is often
> convenient to access the data in key order.  One way to do this is
> to use an unsorted data structure (e.g., a Python dict), and then
> sort the keys as needed. Another way is to use a sorted data
> structure (e.g., a sorteddict as proposed in this PEP), and simply
> access the keys, knowing that they are always in sorted order.

Please define 'sorted order' and make sure it is customisable.

> keys(firstindex : int = None, secondindex : int = None) ->
>  list of keys

I don't really see the point of this, but general support for slicing
might be interesting: 

   sd[start:end] -> list of values for all keys such that start <= key <
   end (using the appropriate definition of 'sorted order'). 


> key(index : int) -> value
> 
> item(index : int) -> (key, value)
> 
> value(index : int) -> key

I'm confused: the key method returns a value and the value method
returns a key??? 

> 
> set_value(index : int, value)
> 
> delete(index : int)

All of those can of course be replaced with a single method that returns
the key at a specified index and then using that key. Yes that would be
less efficient, but I'd rather have as close to a standard dictionary
interface as possible. 

> Examples
> 
> To keep a collection of filenames on a case-insensitive file
> system in sorted order, we could use code like this:
> 
> files = collections.sorteddict.sorteddict()
> for name in os.listdir("."):
> files[name.lower()] = name
> 
> We can add new filenames at any time, safe in the knowledge that
> whenever we call files.values(), we will get the files in
> case-insensitive alphabetical order.

I don't see this as a terribly useful example since you don't explain 
why we need to keep filenames in case-insensitive alphabetical order at 
all. If we want to print a list of filenames we can sort them once when 
printing them, why do we need to keep them 'always sorted'?

> To be able to iterate over a collection of data items in various
> predetermined orders, we could maintain two or more sorteddicts:
> 
> itemsByDate = collections.sorteddict.sorteddict()
> itemsByName = collections.sorteddict.sorteddict()
> itemsBySize = collections.sorteddict.sorteddict()
> for item in listOfItems:
> itemsByDate["%s\t%17X" % (item.date, id(item))] = item
> itemsByName["%s\t%17X" % (item.name, id(item))] = item
> itemsBySize["%s\t%17X" % (item.size, id(item))] = item

I think perl might make you use strings as keys, fortunately Python 
doesn't. What I really don't like about this is that you've copied the 
date, so if you mutate item.date the itemsByDate are no longer sorted.

Again it sounds like sorting for printing will be less overhead that 
keeping them always sorted. You need to come up with examples where 
there is an actual benefit to not sorting for output.

> Here we have used the item IDs to ensure key uniqueness.

If you are going to do this then it really does need to be:

   itemsByDate = sorteddict(items, key=lambda self, k: self[k].date)

so that you can maintain sorted order when mutating an item. How the 
dictionary knows that its contents have been mutated is another question 
entirely.

> 
> Now we can iterate in date or name order, for example:
> 
> for item in itemsByDate:
> print item.name, item.date

Which we can do just as well with an ordinary dictionary:

   for item in sorted(items, key=byDate):
   ...

given an appropriate definition of byDate.

The cases I can think of where a sorteddict might be useful would be 
things like collecting web server statistics and maintaining a regularly 
updated display of the top n pages. You need a combination of factors 
for this to be useful: frequent updates, and frequent extraction of 
sorted elements + the requirement to access elements as a dictionary.

Also, none of your use cases target any of the additional fripperies you 
threw into your proposal.
-- 
http://mail.python.org/mailman/listinfo/python-list


What is a good way of having several versions of a python module installed in parallell?

2007-09-25 Thread Joel Hedlund
Hi!

I write, use and reuse a lot of small python programs for variuos purposes in 
my work. These use a growing number of utility modules that I'm continuously 
developing and adding to as new functionality is needed. Sometimes I discover 
earlier design mistakes in these modules, and rather than keeping old garbage I 
often rewrite the parts that are unsatisfactory. This often breaks backwards 
compatibility, and since I don't feel like updating all the code that relies on 
the old (functional but flawed) modules, I'm left with a hack library that 
depends on halting versions of my utility modules. The way I do it now is that 
I update the programs as needed when I need them, but this approach makes me 
feel a bit queasy. It seems to me like I'm thinking about this in the wrong way.

Does anyone else recognize this situation in general? How do you handle it? 

I have a feeling it should be possible to have multiple versions of the modules 
installed simultaneously, and maybe do something like this: 

mymodule/
+ mymodule-1.1.3/
+ mymodule-1.1.0/
+ mymodule-0.9.5/
- __init__.py

and having some kind of magic in __init__.py that let's the programmer choose 
version after import:

import mymodule
mymodule.require_version("1.1.3")

Is this a good way of thinking about it? What would be an efficient way of 
implementing it?

Cheers!
/Joel Hedlund
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Jeremy Sanders
Mark Summerfield wrote:

> If there is positive feedback I will submit the PEP to the reviewers,
> so if you think it is a good idea please say so. (I'm sure that if you
> _don't_ like it you'll tell me anyway:-)

It would be nice to have the ability to use numerical indexes and the key,
but I don't think they should share the same methods.

A useful use case would be to make a LRU (least recently used) dictionary,
where the keys are time-based (e.g. an incrementing counter). You should be
able to identify the least recently used object for discarding by just
accessing the last item in the dictionary.

By the way, I think a LRU cache dictionary would be a great addition to the
standard library.

Is there any speed advantage from implementing the sorteddict as a red-black
tree or something similar in C?

Jeremy

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


Re: What is a good way of having several versions of a python module installed in parallell?

2007-09-25 Thread Diez B. Roggisch
Joel Hedlund wrote:

> Hi!
> 
> I write, use and reuse a lot of small python programs for variuos purposes
> in my work. These use a growing number of utility modules that I'm
> continuously developing and adding to as new functionality is needed.
> Sometimes I discover earlier design mistakes in these modules, and rather
> than keeping old garbage I often rewrite the parts that are
> unsatisfactory. This often breaks backwards compatibility, and since I
> don't feel like updating all the code that relies on the old (functional
> but flawed) modules, I'm left with a hack library that depends on halting
> versions of my utility modules. The way I do it now is that I update the
> programs as needed when I need them, but this approach makes me feel a bit
> queasy. It seems to me like I'm thinking about this in the wrong way.
> 
> Does anyone else recognize this situation in general? How do you handle
> it?
> 
> I have a feeling it should be possible to have multiple versions of the
> modules installed simultaneously, and maybe do something like this:
> 
> mymodule/
> + mymodule-1.1.3/
> + mymodule-1.1.0/
> + mymodule-0.9.5/
> - __init__.py
> 
> and having some kind of magic in __init__.py that let's the programmer
> choose version after import:
> 
> import mymodule
> mymodule.require_version("1.1.3")
> 
> Is this a good way of thinking about it? What would be an efficient way of
> implementing it?

Use setuptools. It can exactly do that - install different versions parallel
as eggs, and with a pre-import require-statment you require the desired
one.

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Paul Hankin
Recall sorted...
sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted
list

So why not construct sorteddicts using the same idea of sortedness?

sorteddict((mapping | sequence | nothing), cmp=None, key=None,
reverse=None)

Then we can specify the exact behaviour of sorteddicts: it's the same
as a regular dict, except when the order of keys is important they're
ordered as if they were sorted by sorted(keys, cmp=sd._cmp,
key=sd._key, reverse=sd._reverse). Here I imagine cmp, key and reverse
are stored in the new sorteddict as attributes _cmp, _key, _reverse -
obviously the actual implementation may differ.

This has the benefit of making sorteddict's behaviour explicit and
easy to understand, and doesn't introduce a new sorting API when we
already have a perfectly decent one.

The only problem here is the **kwargs form of the dict constructor
doesn't translate as we're using keyword args to pass in the sort
criterion. Perhaps someone has an idea of how this can be solved. If
nothing else, this constructor could be dropped for sorteddicts, and
sorteddict(dict(**kwargs), cmp=..., key=..., reverse=...) when that
behaviour is wanted.

I don't like the integral indexing idea or the slicing: indexing and
slicing are already part of python and it's bad to have different
syntax for the same concept on sorteddicts. I'd say it's not an
important enough for sorteddicts anyway.

--
Paul Hankin

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Mark Summerfield
On 25 Sep, 12:11, Jeremy Sanders  wrote:
> Mark Summerfield wrote:
> > If there is positive feedback I will submit the PEP to the reviewers,
> > so if you think it is a good idea please say so. (I'm sure that if you
> > _don't_ like it you'll tell me anyway:-)
>
> It would be nice to have the ability to use numerical indexes and the key,
> but I don't think they should share the same methods.

They don't; you use [] for key index and key(), value(), or item() for
index access.

> A useful use case would be to make a LRU (least recently used) dictionary,
> where the keys are time-based (e.g. an incrementing counter). You should be
> able to identify the least recently used object for discarding by just
> accessing the last item in the dictionary.

You could do that with a sorteddict simply by using datetime.date
objects or timestamp strings for keys. You could get the first or last
item (no matter what its key). For example:

d = sorteddict({1200:"lunch", 1100:"elevensies", 1600:"tea",
1900:"dinner"})
d.items()
[(1100, 'elevensies'), (1200, 'lunch'), (1600, 'tea'), (1900,
'dinner')]
d.item(0), d.item(-1)
((1100, 'elevensies'), (1900, 'dinner'))

So you could remove the last item using d.delete(-1).

> By the way, I think a LRU cache dictionary would be a great addition to the
> standard library.
>
> Is there any speed advantage from implementing the sorteddict as a red-black
> tree or something similar in C?

I'm sure that a C-based implementation using red-black or AVL trees or
skiplists would be faster, but right now I'm just trying to get an
acceptable API.

Corrections to my original PEP:

   value(index : int) -> value # I incorrectly had the return value as
key

Also, now in the second example I use a tuple of string, int ID rather
than strings.

> Jeremy
>
> --
> Jeremy Sandershttp://www.jeremysanders.net/


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


Re: Inserting an element into existing xml file

2007-09-25 Thread Marc 'BlackJack' Rintsch
On Tue, 25 Sep 2007 03:30:05 -0700, Anand wrote:

> I'm Afraid to say, I can't use lxml or elementTree as it requires many
> legal approvals and there is high chances of not getting it through.

In what environment is it hard to get something BSD licensed through!?

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


Re: ANN: 555-BOOM! version 0.6

2007-09-25 Thread Markus Gritsch
Hi Greg,

thank you for this great game!  I like it very much.

Just one thing: Your telephone uses numbers ordered like in this
picture http://www.michaelsiebert.com/img_kontakt/telephone.jpg, so
dialing e.g. 7 triggers 3 impulses.  However, where I live (Austria,
Europe) the telephones had the numbers located like this
http://www.fliesen-niemann.de/img/upload/800px-Telephone-modele-W48.jpg,
so dialing e.g. 7 resulted in 7 impulses.

It would be nice, if the telephone type could be configured in the
menu of the game.

Kind regards,
Markus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Mark Summerfield
On 25 Sep, 12:19, Paul Hankin <[EMAIL PROTECTED]> wrote:
> Recall sorted...
> sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted
> list
>
> So why not construct sorteddicts using the same idea of sortedness?
>
> sorteddict((mapping | sequence | nothing), cmp=None, key=None,
> reverse=None)
>
> Then we can specify the exact behaviour of sorteddicts: it's the same
> as a regular dict, except when the order of keys is important they're
> ordered as if they were sorted by sorted(keys, cmp=sd._cmp,
> key=sd._key, reverse=sd._reverse). Here I imagine cmp, key and reverse
> are stored in the new sorteddict as attributes _cmp, _key, _reverse -
> obviously the actual implementation may differ.
>
> This has the benefit of making sorteddict's behaviour explicit and
> easy to understand, and doesn't introduce a new sorting API when we
> already have a perfectly decent one.
>
> The only problem here is the **kwargs form of the dict constructor
> doesn't translate as we're using keyword args to pass in the sort
> criterion. Perhaps someone has an idea of how this can be solved. If
> nothing else, this constructor could be dropped for sorteddicts, and
> sorteddict(dict(**kwargs), cmp=..., key=..., reverse=...) when that
> behaviour is wanted.
>
> I don't like the integral indexing idea or the slicing: indexing and
> slicing are already part of python and it's bad to have different
> syntax for the same concept on sorteddicts. I'd say it's not an
> important enough for sorteddicts anyway.
>
> --
> Paul Hankin


This makes a lot of sense to me. But how do you envisage it would be
implemented?


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


Re: database persistence with mysql, sqlite

2007-09-25 Thread M.-A. Lemburg
On 2007-09-23 01:11, coldpizza wrote:
> Hi,
> 
> I want to run a database query and then display the first 10 records
> on a web page. Then I want to be able to click the 'Next' link on the
> page to show the next 10 records, and so on.
> 
> My question is how to implement paging, i.e. the 'Next/Prev' NN
> records without reestablishing a database connection every time I
> click Next/Prev? Is it at all possible with cgi/mod_python?
> 
> For example, in a NON-web environment, with sqlite3 and most other
> modules, I can establish a database connection once, get a cursor
> object on which I run a single 'SELECT * FROM TABLE' statement and
> then use cursor.fetchmany(NN) as many times as there are still results
> left from the initial query.
> 
> How do I do the same for the web? I am not using any high-level
> framework. I am looking for a solution at the level of cgi or
> mod_python (Python Server Pages under Apache). To call
> cursor.fetchmany(NN) over and over I need to pass a handle to the
> database connection but how do I keep a reference to the cursor object
> across pages? I use mysql and sqlite3 as databases, and I am looking
> for an approach that would work with both database types (one at a
> time). So far I have successfully used the following modules for
> database access: sqlite3, mysqld, and pyodbc.
> 
> So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1
> and  L2 define the range for the 'Next' and 'Previous' commands. I
> have to run the query every time a click a 'Next/Prev' link. But I am
> not sure that this is the best and most efficient way. I suppose using
> CURSOR.FETCHMANY(NN) would probably be faster and nicer but how do I
> pass an object reference across pages? Is it possible without any
> higher-level libraries?
> 
> What would be the proper way to do it on a non-enterprise scale?

Depends on what "enterprise" scale means to you :-)

The easiest way to get excellent performance for such queries is
using a long running process, mod_scgi and have the browser
send a session cookie for you to use to identify the request.
You can then open the connection and keep it open while the user
browses the site.

If you want to save yourself from most of the details,
just use Zope or Plone + e.g. our mxODBC Zope DA for the
database connection (it works with all the databases
you mention on Windows, Linux and Mac OS X).

Even if you don't want to code things using Zope/Plone,
you should still consider it for taking care of all the
middleware logic and then write your application as
separate package which you hook into Zope/Plone using
"external methods" or "Python scripts" (in their Zope
sense).

> Would SqlAlchemy or SqlObject make things easier with regard to
> database persistence?

Not really: they don't provide the session mechanisms you
would need.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Sep 25 2007)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
-- 
http://mail.python.org/mailman/listinfo/python-list


Raw string printing

2007-09-25 Thread Alexandre Badez
Hy !

I would like to do something like:

s = r"a\tb\n"

print s
# result with
a\tb\n

print unraw(s) # <= this is the "magic" function I'm searching for
# result with
ab
n

Does any of you know how to do it properly ?

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


Re: An Editor that Skips to the End of a Def

2007-09-25 Thread Steve Holden
Bjoern Schliessmann wrote:
> Lawrence D'Oliveiro wrote:
>> That's like saying, about a program that, when given "2 + 2",
>> outputs "5", that _of course_ it knows the correct answer is "4",
>> it just chooses to "modify" the answer before outputting it.
> 
> No. Which laws say how transitions between modes have to be? Thus, I
> know laws saying 2 and 2 is 4.
>  
>> Why does it "choose" to modify your position when you exit insert
>> mode? Does the phrase "broken as designed" mean anything to you?
> 
> Does the phrase "everything I don't like is stupid" mean anything to
> you? Honestly, if you don't like it, either propose improvement or
> stop using it (and complaining about it). Your preference with user
> interfaces is obviously different. (Personally, I prefer single
> strokes to breaking my fingers with Esc-Meta-Alt-Control-Shift.
> :) )
>  
Does "this non-Python related twaddle is boring the shit out of me" mean 
anything to you both?

[...]

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

Sorry, the dog ate my .sigline

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


Re: Raw string printing

2007-09-25 Thread Peter Otten
Alexandre Badez wrote:

> I would like to do something like:
> 
> s = r"a\tb\n"

> print unraw(s) # <= this is the "magic" function I'm searching for
> # result with
> ab
> n
> 
> Does any of you know how to do it properly ?

>>> print r"a\tb\nx".decode("string-escape")
a   b
x

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


Re: Raw string printing

2007-09-25 Thread Alexandre Badez
On Sep 25, 2:24 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> Alexandre Badez wrote:
> > I would like to do something like:
>
> > s = r"a\tb\n"
> > print unraw(s) # <= this is the "magic" function I'm searching for
> > # result with
> > ab
> > n
>
> > Does any of you know how to do it properly ?
> >>> print r"a\tb\nx".decode("string-escape")
>
> a   b
> x
>
> Peter

THANKS :D


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


Re: Newbie completely confused

2007-09-25 Thread Roel Schroeven
Roel Schroeven schreef:
> import time
> 
> input_files = ["./test_file0.txt", "./test_file1.txt"]
> 
> total_start = time.time()
> data = {}
> for input_fn in input_files:
>  file_start = time.time()
>  f = file(input_fn, 'r')
>  data[input_fn] = f.read()
>  f.close()
>  file_done = time.time()
>  print '%s: %f to read %d bytes' % (input_fn, file_done - 
> file_start, len(data))

... that should of course be len(data[input_fn]) ...

> total_done = time.time()
> print 'all done in %f' % (total_done - total_start)
> 
> 
> When I run that with test_file0.txt and test_file1.txt as you described 
> (each 30 MB), I get this output:
> 
> ./test_file0.txt: 0.26 to read 1 bytes
> ./test_file1.txt: 0.251000 to read 2 bytes
> all done in 0.521000

... and then that becomes:

./test_file0.txt: 0.29 to read 3317 bytes
./test_file1.txt: 0.231000 to read 3317 bytes
all done in 0.521000


-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

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


Re: strange behavious of the logging module?

2007-09-25 Thread Vinay Sajip
On 25 Sep, 09:40, Peter Otten <[EMAIL PROTECTED]> wrote:
> You could try setting
>
> logging._srcfile =logging.info.func_code.co_filename
>
> manually, but that might break other things. Or you recreate the pyc-files
> of your distribution. Again, I don't know what might break...
>

Recreating .pyc files should not break anything - this will get done
automatically, so deleting the .pyc and/or .pyo files in the Python/
Lib directory tree should be sufficient. See the issues linked to by

http://bugs.python.org/msg24988

In these cases, deleting the .pyc/.pyo files solved the problem.

Best regards,

Vinay

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


Re: sorting a list numbers stored as strings

2007-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2007 12:46:54 +0800, Delaney, Timothy (Tim) wrote:

> Carsten Haese wrote:
> 
>> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
>>> I'm sure that in some version of Python it would have given a
>>> ValueError (due to the default radix being 0) but it appears to have
>>> changed to a default radix of 10 somewhere along the way.
>> 
>> Not even Python 1.5.2 seems to have a problem with leading zeroes:
>> 
>> Python 1.5.2 (#1, Nov  6 1999, 14:53:40) [C] on sco_sv3 Copyright
>> 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> int("08")
>> 8
> 
> Yep - appears I must have been misremembering from another language
> (dunno which) or I misinterpreted the docs.

I also remember something in Python about leading zeroes leading to 
"surprising" effects... ah, I got it!


>>> int("020")
20
>>> 020
16


-- 
Steven.

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


ANNOUNCE: Exscript 0.9.9

2007-09-25 Thread Samuel
Introduction
-
Exscript is a scripting language for automating Telnet or SSH
sessions. It supports a wide range of features, such as
parallelization, AAA authentication methods, TACACS, and a very simple
template language.

This release comes with many new features, and the documentation was
also greatly improved. Please refer to the project page for
documentation.

A lot of changes were made since release 0.9.8, so 0.9.9 was added
before the final 1.0. Hopefully this will be the last release before
1.0 stable.

New since 0.9.8
--
* The SSH adapter was completely reworked and should now be on par
with the Telnet adapter.
* The telnet adapter now supports negotiation. This means that a
connection should now automatically choose a script-friendly terminal
type. (e.g. one that uses no color control characters).
* Exscript is now fully supported on Python >= 2.2.
* SSH support is now optional. The protocol adapters are now loaded
dynamically, such that SSH does not have to be installed if only
Telnet is used.
* The error handling of the parser was greatly improved, and more
errors should now be detected at compile time.
* Prompt recognition was further improved.
* It is now possible to use \r and \n in strings.
* Strings may now be concatenated using the "." operator.
* Added "in" and "not in" operators for searching through a list.
* Fixed: Escaping of some characters outside of code context did not
work.
* Fixed: Escaping quotes in a string would not work.
* Added support for using $-prefixed variable names in strings.
* Added the builtin variable "response", that now includes the
response of the last command.
* #-prefixed lines are now comments.
* Fixed a bug that some operations would not work when accessing the
iterator variable in the body of a loop tag.
* Fix: In several cases accessing a variable would fail.
* Added support for "while" and "until" loops.
* Added support for "into" keyword.
* Use friendlier thread names.

Dependencies
-
* Python 2.2 or greater
* Python-crypto
* Python-pexpect (optional, for SSH support)
* ssh (optional, for SSH support)

Download Exscript
--
Release: http://exscript.googlecode.com/files/exscript-0.9.9.tgz
SVN instructions: http://code.google.com/p/exscript/source

Links
--
Exscript project page: http://code.google.com/p/exscript/
Mailing list: http://groups.google.com/group/exscript
Bug tracker: http://code.google.com/p/exscript/issues/list
Browse the source: http://exscript.googlecode.com/svn/trunk/

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


PyQt disconnect signal / slot

2007-09-25 Thread Alexander Eisenhuth
Hello PyQt experts,

do i have to disconnect all signal/slots, after the emitting object is deleted, 
or does it the QObject destructor?

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


Re: PyQt disconnect signal / slot

2007-09-25 Thread Phil Thompson
On Tuesday 25 September 2007, Alexander Eisenhuth wrote:
> Hello PyQt experts,
>
> do i have to disconnect all signal/slots, after the emitting object is
> deleted, or does it the QObject destructor?

It's done for you - same as Qt.

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


Re: PyQt disconnect signal / slot

2007-09-25 Thread Alexander Eisenhuth
Phil, thanks for that quick reply

Phil Thompson schrieb:
> On Tuesday 25 September 2007, Alexander Eisenhuth wrote:
>> Hello PyQt experts,
>>
>> do i have to disconnect all signal/slots, after the emitting object is
>> deleted, or does it the QObject destructor?
> 
> It's done for you - same as Qt.
> 
> Phil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting a list numbers stored as strings

2007-09-25 Thread Hrvoje Niksic
"Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> writes:

> Yep - appears I must have been misremembering from another language
> (dunno which)

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


HTTPS request

2007-09-25 Thread Johny
If I need to log in to a site using https protocol must I use
certification file and key file?
The class HTTPSConnection syntax is
class HTTPSConnection( host[, port, key_file, cert_file])

and I do not know if it is nescessary or not.
Thanks for help.
L.

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


Re: Python script to optimize XML text

2007-09-25 Thread Robert Dailey
Hey guys,

Thanks for everyone's input. I wanted to learn regular expressions, however
I'm finding them to be quite evil. I think I've learned that it's always a
good idea to make regex a very LAST resort. This is my opinion I'm
developing on. In any case, I like the ideas mentioned here concerning using
the XML parser to do the job for me. Thanks again everyone, I think I'll be
going with the XML parser to do what I need.

Have a good day everyone.

On 9/25/07, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>
> Gabriel Genellina wrote:
> > En Mon, 24 Sep 2007 17:36:05 -0300, Robert Dailey <[EMAIL PROTECTED]>
> > escribi�:
> >
> >> I'm currently seeking a python script that provides a way of
> >> optimizing out
> >> useless characters in an XML document to provide the optimal size for
> the
> >> file. For example, assume the following XML script:
> >>
> >> 
> >> 
> >> 
> >>
> >> 
> >> 
> >>
> >> By running this through an XML optimizer, the file would appear as:
> >>
> >> 
> >
> > ElementTree does that almost for free.
>
> As the OP is currently using lxml.etree (and as this was a cross-post to
> c.l.py and lxml-dev), I already answered on the lxml list.
>
> This is just to mention that the XMLParser of lxml.etree accepts keyword
> options to ignore plain whitespace content, comments and processing
> instructions, and that you can provide a DTD to tell it what
> whitespace-only
> content really is "useless" in the sense of your specific application.
>
> Stefan
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: directpython question

2007-09-25 Thread Heikki Salo
veki wrote:
> Hello,
> I've got IBM Thinkpad 30 laptop with configuration:
> 
> IBM Thinkpad R30
> P3 Mobile Celeron 900mhz
> 128mb sdram pc133
> 15gb hdd
> cd-rom Teac cd-224e
> 56K V.90/92
> 10/100 Ethernet
> lpt port
> ps2 port
> 2 x usb port
> vga-out
> pcmcia
> 
> ,then I have been install directx 9.0c,Python 2.5 and directpython for
> python 2.5.On my two computers directpython works but on this
> laptop it don't want work e.g:
> 
> When I want execute this script on laptop:
> 
> import d3dx
> frame=d3dx.Frame(u'SOME FRAME')
> frame.mainloop()
> 
> I get this error:
> 
> Traceback (most recent call last):
>   File "C:\Python25\Lib\site-packages\veki1.py", line 2, in 
> fr=d3dx.Frame(u'SOME FRAME')
>   File "C:\Python25\lib\site-packages\directpy\d3dx.py", line 639, in
> __init__
> self._createDevice(area[2:4])
>   File "C:\Python25\lib\site-packages\directpy\d3dx.py", line 659, in
> _createDevice
> raise RuntimeError("No valid mode found")
> RuntimeError: No valid mode found
> 
> Regards,
> Vedran
> 
> 

As Tim already noted, your laptop apparently uses Trident 
CyberBlade Ai1 graphics card, which is quite old and designed 
for DirectX 6-8. This is not a problem if the device driver is 
up to date, but the newest I found seems to be from 2003. This 
can be a problem if it does not correctly support DirectX 9.0c 
(released in 2004).

You should see what the DirectX diagnostics tool says 
(dxdiag.exe - found in WINDIR\system32) and possibly update 
the driver. Then cross your fingers and see what happens.

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


Re: Confused about 'positive lookbehind assertion'

2007-09-25 Thread Robert Dailey
I think I get it... it's really just a way (so it seems) to make characters
get added to the found groups as they're matched. Thanks for your help.

On 9/25/07, Andrew Durdin <[EMAIL PROTECTED]> wrote:
>
> On 9/25/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I've been reading the python documentation on 'positive lookbehind
> > assertion' and I don't understand at all how it works. The python docs
> give
> > the following example:
> >
> > " (?<=abc)def will find a match in "abcdef", since the lookbehind will
> back
> > up 3 characters and check if the contained pattern matches."
> >
> > Can anyone emphasize more on what this RE operation does? Thanks.
>
> It ensures that the regex will only match following the string in the
> lookbehind group, but without capturing that string.
>
> As the docs say, "(?<=abc)def" will match "abcdef"; but it will not
> match "def" (as the "abc" is not there).  If it does match,  the 0th
> group in the match object will be "def".
>
> In contrast, the regex "abcdef" will also match "abcdef" and not
> "def", but the 0th group will be "abcdef".
>
> The negative lookbehind is the opposite -- e.g. "(? match "def" but not "abcdef".
>
> Cheers,
>
> Andrew
>
-- 
http://mail.python.org/mailman/listinfo/python-list

PyS60

2007-09-25 Thread croozeus
Does anybody in the group develop applications for symbian OS using
Python for Series 60?
I am interested in developing such applications..
Also i have the following site for the newbies to PyS60.

Regards,
Pankaj Nathani

Pys60 1.4.0 on Nokia 6680 4.04 2nd Edition FP2,Pys60 1.4.0 on Nokia
7610 2nd Edition

View my P60 at
http://croozeus.googlepages.com/py60

Py60 Resources
http://sourceforge.net/projects/pys60
_

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


Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Awesome description. This was more than helpful. I'm really grateful that
you took the time to outline that for me. I really understand it now.
However, as I mentioned in the lxml mailing list, I'm starting to learn more
towards regular expressions being a very LAST resort to solving problems
like this. In my specific case, I have a better choice which is the etree
parser. It does all of this for me (as you so kindly stated before). I hope
this is the correct attitude to have. Being a C++ developer, I normally
don't admire unmanageable and unreadable code (this is especially true with
regular expressions). They're very useful, but again I believe it should be
a last resort.

Thanks again for your help.

On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
> En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]>
> escribi�:
>
> > What I meant was that it's not an option because I'm trying to learn
> > regular
> > expressions. RE is just as built in as anything else.
>
> Ok, let's analyze what you want. You have for instance this text:
> ""
> which should become
> ""
>
> You have to match:
> (opening angle bracket)(any word)(closing angle bracket)(opening angle
> bracket)(slash)(same word as before)(closing angle bracket)
>
> This translates rather directly into this regular expression:
>
> r"<(\w+)>"
>
> where \w+ means "one or more alphanumeric characters or _", and being
> surrounded in () creates a group (group number one), which is
> back-referenced as \1 to express "same word as before"
> The matched text should be replaced by (opening <)(the word
> found)(slash)(closing >), that is: r"<\1/>"
> Using the sub function in module re:
>
> py> import re
> py> source = """
> ... 
> ... 
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)>", r"<\1/>", source)
>
> 
> 
> 
> 
>
> Now, a more complex example, involving tags with attributes:
>   -->  
>
> You have to match:
> (opening angle bracket)(any word)(any sequence of words,spaces,other
> symbols,but NOT a closing angle bracket)(closing angle bracket)(opening
> angle bracket)(slash)(same word as before)(closing angle bracket)
>
> r"<(\w+)([^>]*)>"
>
> [^>] means "anything but a >", the * means "may occur many times, maybe
> zero", and it's enclosed in () to create group 2.
>
> py> source = """
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
>
> 
> 
>
> Next step would be to allow whitespace wherever it is legal to appear -
> left as an exercise to the reader. Hint: use \s*
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Confused about 'positive lookbehind assertion'

2007-09-25 Thread Erik Jones

On Sep 24, 2007, at 9:38 PM, Robert Dailey wrote:

> Hi,
>
> I've been reading the python documentation on 'positive lookbehind  
> assertion' and I don't understand at all how it works. The python  
> docs give the following example:
>
> " (?<=abc)def will find a match in "abcdef", since the lookbehind  
> will back up 3 characters and check if the contained pattern matches."
>
> Can anyone emphasize more on what this RE operation does? Thanks.


Have you actually tried it out?

 >>> import re
 >>> r = re.compile(r'(?<=abc)def')
 >>> m1 = r.search('bcde')
 >>> m1.group()'def'
'def'
 >>> m2 = r.search('bcdefff')
 >>> m2 == None
True

So, it matches 'def' but only if it is immediately preceded by 'abc'.

Erik Jones

Software Developer | Emma®
[EMAIL PROTECTED]
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com


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


Clustering text-documents in bundles

2007-09-25 Thread exhuma.twn
Hi,

This *is* off-topic but with python being a language with a somewhat
scientific audience, I might get lucky ;)
I have a set of documents (helpdesk tickets in fact) and I would like
to automatically collect them in bundles so I can visualise some
statistics depending on content.

A while ago I wrote a very simple clustering library which can cluster
about everything where you can calculate some form of distance.
Meaning: You can supply a function that calculates numeric value given
two objects (helpdesk request text-body in this case). The closer the
two objects are related, the smaller the returned value with 0.0
meaning that the two objects are identical.

Is it possible to calculate a distance between two chunks of text? I
suppose one could simply do a simple word-count on the chunks
(removing common noise words of course). And then go from there. Maybe
even assigning different weighting to words. But maybe there is a well-
tested and useful algorithm already available?

Text processing is a very blurry area for me. I don't expect any
solutions for the problem right away. Maybe just some pointers as to
*what* I can google for. I'll pick the rest up from there.

Eventually I would like to have the possibility to say: "This set of
texts contains 20 requests dealing with emails, 30 requests dealing
with Office Applications and 210 requests dealing with databases". I
am aware that labelling the different text-bundles will have to be
done manually I suppose.  But I will aim for no more than 10 bundles
anyway. So that's OK.

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


Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Paul McGuire
On Sep 24, 11:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]>  
> escribi?:
>
> > What I meant was that it's not an option because I'm trying to learn  
> > regular
> > expressions. RE is just as built in as anything else.
>
> Ok, let's analyze what you want. You have for instance this text:
> ""
> which should become
> ""
>
> You have to match:
> (opening angle bracket)(any word)(closing angle bracket)(opening angle  
> bracket)(slash)(same word as before)(closing angle bracket)
>
> This translates rather directly into this regular expression:
>
> r"<(\w+)>"
>
> where \w+ means "one or more alphanumeric characters or _", and being  
> surrounded in () creates a group (group number one), which is  
> back-referenced as \1 to express "same word as before"
> The matched text should be replaced by (opening <)(the word  
> found)(slash)(closing >), that is: r"<\1/>"
> Using the sub function in module re:
>
> py> import re
> py> source = """
> ... 
> ... 
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)>", r"<\1/>", source)
>
> 
> 
> 
> 
>
> Now, a more complex example, involving tags with attributes:
>   -->  
>
> You have to match:
> (opening angle bracket)(any word)(any sequence of words,spaces,other  
> symbols,but NOT a closing angle bracket)(closing angle bracket)(opening  
> angle bracket)(slash)(same word as before)(closing angle bracket)
>
> r"<(\w+)([^>]*)>"
>
> [^>] means "anything but a >", the * means "may occur many times, maybe  
> zero", and it's enclosed in () to create group 2.
>
> py> source = """
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
>
> 
> 
>
> Next step would be to allow whitespace wherever it is legal to appear -  
> left as an exercise to the reader. Hint: use \s*
>
> --
> Gabriel Genellina

And let's hope the OP doesn't have to parse anything truly nasty like:



-- Paul

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


Re: Clustering text-documents in bundles

2007-09-25 Thread Paul Hankin
On Sep 25, 4:11 pm, "exhuma.twn" <[EMAIL PROTECTED]> wrote:
> Is it possible to calculate a distance between two chunks of text? I
> suppose one could simply do a simple word-count on the chunks
> (removing common noise words of course). And then go from there. Maybe
> even assigning different weighting to words. But maybe there is a well-
> tested and useful algorithm already available?

A good distance between two chunks of text is the number of changes
you have to make to one to transform it to the other. You should look
at 'difflib' with which you should be able to code up this sort of
distance (although the details will depend just on what your text
looks like).

--
Paul Hankin

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


comparing elements of a list with a string

2007-09-25 Thread Shriphani
Hello all,
I have a problem here. I have a list named list_of_files which
contains filenames with their timestamps attached to the name. If I
have a string "fstab", and I want to list out the files in whose names
the word fstab appears should I go about like this :

def listAllbackups(file):
list_of_files = os.listdir("/home/shriphani/backupdir")
for element in list_of_files:
 if element.find(file) != -1:
 date = ###
 time = 
  return (date, time)

The major trouble is that the return statement causes it to exit after
attempt one. How do I use the yield statement here?

Regards,
Shriphani Palakodety

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


Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Fortunately I don't have any XML that complex, however you make a good
point.

On 9/25/07, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
> On Sep 24, 11:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
> > En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]>
> > escribi?:
> >
> > > What I meant was that it's not an option because I'm trying to learn
> > > regular
> > > expressions. RE is just as built in as anything else.
> >
> > Ok, let's analyze what you want. You have for instance this text:
> > ""
> > which should become
> > ""
> >
> > You have to match:
> > (opening angle bracket)(any word)(closing angle bracket)(opening angle
> > bracket)(slash)(same word as before)(closing angle bracket)
> >
> > This translates rather directly into this regular expression:
> >
> > r"<(\w+)>"
> >
> > where \w+ means "one or more alphanumeric characters or _", and being
> > surrounded in () creates a group (group number one), which is
> > back-referenced as \1 to express "same word as before"
> > The matched text should be replaced by (opening <)(the word
> > found)(slash)(closing >), that is: r"<\1/>"
> > Using the sub function in module re:
> >
> > py> import re
> > py> source = """
> > ... 
> > ... 
> > ... 
> > ... 
> > ... """
> > py> print re.sub(r"<(\w+)>", r"<\1/>", source)
> >
> > 
> > 
> > 
> > 
> >
> > Now, a more complex example, involving tags with attributes:
> >   -->  
> >
> > You have to match:
> > (opening angle bracket)(any word)(any sequence of words,spaces,other
> > symbols,but NOT a closing angle bracket)(closing angle bracket)(opening
> > angle bracket)(slash)(same word as before)(closing angle bracket)
> >
> > r"<(\w+)([^>]*)>"
> >
> > [^>] means "anything but a >", the * means "may occur many times, maybe
> > zero", and it's enclosed in () to create group 2.
> >
> > py> source = """
> > ... 
> > ... 
> > ... """
> > py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
> >
> > 
> > 
> >
> > Next step would be to allow whitespace wherever it is legal to appear -
> > left as an exercise to the reader. Hint: use \s*
> >
> > --
> > Gabriel Genellina
>
> And let's hope the OP doesn't have to parse anything truly nasty like:
>
>  esolang:language>
>
> -- Paul
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Miles
On 9/25/07, Paul McGuire wrote:
> On Sep 24, 11:23 pm, Gabriel Genellina wrote:
> > py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
>
> And let's hope the OP doesn't have to parse anything truly nasty like:
>
>  esolang:language>

Or something mildly nasty, like 

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


Re: comparing elements of a list with a string

2007-09-25 Thread Evan Klitzke
On Tue, 2007-09-25 at 08:39 -0700, Shriphani wrote:
> Hello all,
> I have a problem here. I have a list named list_of_files which
> contains filenames with their timestamps attached to the name. If I
> have a string "fstab", and I want to list out the files in whose names
> the word fstab appears should I go about like this :
> 
> def listAllbackups(file):
> list_of_files = os.listdir("/home/shriphani/backupdir")
> for element in list_of_files:
>  if element.find(file) != -1:
>  date = ###
>  time = 
>   return (date, time)
> 
> The major trouble is that the return statement causes it to exit after
> attempt one. How do I use the yield statement here?

You can just replace the return statement with a yield statement,
nothing fancy is required. Also, as long as you're using the string.find
method to search for the file, I'd replace it with "if file in element",
which is a bit more idiomatic.

-- 
Evan Klitzke <[EMAIL PROTECTED]>

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


Re: What is a good way of having several versions of a python module installed in parallell?

2007-09-25 Thread Steve Holden
Diez B. Roggisch wrote:
> Joel Hedlund wrote:
> 
>> Hi!
>>
>> I write, use and reuse a lot of small python programs for variuos purposes
>> in my work. These use a growing number of utility modules that I'm
>> continuously developing and adding to as new functionality is needed.
>> Sometimes I discover earlier design mistakes in these modules, and rather
>> than keeping old garbage I often rewrite the parts that are
>> unsatisfactory. This often breaks backwards compatibility, and since I
>> don't feel like updating all the code that relies on the old (functional
>> but flawed) modules, I'm left with a hack library that depends on halting
>> versions of my utility modules. The way I do it now is that I update the
>> programs as needed when I need them, but this approach makes me feel a bit
>> queasy. It seems to me like I'm thinking about this in the wrong way.
>>
>> Does anyone else recognize this situation in general? How do you handle
>> it?
>>
>> I have a feeling it should be possible to have multiple versions of the
>> modules installed simultaneously, and maybe do something like this:
>>
>> mymodule/
>> + mymodule-1.1.3/
>> + mymodule-1.1.0/
>> + mymodule-0.9.5/
>> - __init__.py
>>
>> and having some kind of magic in __init__.py that let's the programmer
>> choose version after import:
>>
>> import mymodule
>> mymodule.require_version("1.1.3")
>>
>> Is this a good way of thinking about it? What would be an efficient way of
>> implementing it?
> 
> Use setuptools. It can exactly do that - install different versions parallel
> as eggs, and with a pre-import require-statment you require the desired
> one.
> 
> Diez

Of course a much simpler, less formal solution, is to install the 
libraries required by a program along with that program in its own 
directory. This more or less guarantees you will get out of sync.

Otherwise, three words:

   test driven development

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

Sorry, the dog ate my .sigline

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


Re: An Editor that Skips to the End of a Def

2007-09-25 Thread Peter Decker
On 9/25/07, Steve Holden <[EMAIL PROTECTED]> wrote:

> >> Why does it "choose" to modify your position when you exit insert
> >> mode? Does the phrase "broken as designed" mean anything to you?
> >
> > Does the phrase "everything I don't like is stupid" mean anything to
> > you? Honestly, if you don't like it, either propose improvement or
> > stop using it (and complaining about it). Your preference with user
> > interfaces is obviously different. (Personally, I prefer single
> > strokes to breaking my fingers with Esc-Meta-Alt-Control-Shift.
> > :) )
> >
> Does "this non-Python related twaddle is boring the shit out of me" mean
> anything to you both?

+1 QOTW!!

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTTPS request

2007-09-25 Thread Larry Bates
Johny wrote:
> If I need to log in to a site using https protocol must I use
> certification file and key file?
> The class HTTPSConnection syntax is
> class HTTPSConnection( host[, port, key_file, cert_file])
> 
> and I do not know if it is nescessary or not.
> Thanks for help.
> L.
> 
Depends on what the server requires.  You can do basic authenticate to a https: 
site if it supports it.

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


Re: comparing elements of a list with a string

2007-09-25 Thread Matimus

Shriphani wrote:
> Hello all,
> I have a problem here. I have a list named list_of_files which
> contains filenames with their timestamps attached to the name. If I
> have a string "fstab", and I want to list out the files in whose names
> the word fstab appears should I go about like this :
>
> def listAllbackups(file):
> list_of_files = os.listdir("/home/shriphani/backupdir")
> for element in list_of_files:
>  if element.find(file) != -1:
>  date = ###
>  time = 
>   return (date, time)
>
> The major trouble is that the return statement causes it to exit after
> attempt one. How do I use the yield statement here?

I would just do this:

[code]
from glob import glob
def listallbackupfiles(filename):
return glob("/home/shriphani/backupdir/*%s*"%filename)
[/code]

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


Re: comparing elements of a list with a string

2007-09-25 Thread Larry Bates
Shriphani wrote:
> Hello all,
> I have a problem here. I have a list named list_of_files which
> contains filenames with their timestamps attached to the name. If I
> have a string "fstab", and I want to list out the files in whose names
> the word fstab appears should I go about like this :
> 
> def listAllbackups(file):
> list_of_files = os.listdir("/home/shriphani/backupdir")
> for element in list_of_files:
>  if element.find(file) != -1:
>  date = ###
>  time = 
>   return (date, time)
> 
> The major trouble is that the return statement causes it to exit after
> attempt one. How do I use the yield statement here?
> 
> Regards,
> Shriphani Palakodety
> 

You should take a quick look at glob().  You may be able to use it to make life 
a lot easier.  Here is how you would do it if all your backup files begin with
fstab.

import glob
list_of_backup_files=glob.glob('/home/shriphani/backupdir/glob*')

If "fstab" can appear anywhere in the filename, this might not work for you.

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Steven Bethard
Mark Summerfield wrote:
> PEP: XXX
> Title: Sorted Dictionary
[snip]
> In addition, the keys() method has two optional arguments:
> 
> keys(firstindex : int = None, secondindex : int = None) -> list of keys
> 
> The parameter names aren't nice, but using say "start" and "end" would
> be misleading since the intention is for the parameters to work like
> they do in range(), e.g.
> 
> sd.keys()   # returns a list of all the sorteddict's keys
> sd.keys(10) # returns a list of the first 10 keys
> sd.keys(19, 35) # returns a list of the 19th-34th keys inclusive

You should use the range() names, "start" and "stop":

 >>> help(range)
 Help on built-in function range in module __builtin__:

 range(...)
 range([start,] stop[, step]) -> list of integers

But I also agree that this is probably not necessary given the existence 
of slicing and itertools.islice().

> Since the sorteddict's data is always kept in key order, indexes
> (integer offsets) into the sorteddict make sense.  Five additional
> methods are proposed to take advantage of this:
> 
> key(index : int) -> value
> 
> item(index : int) -> (key, value)
> 
> value(index : int) -> key
> 
> set_value(index : int, value)
> 
> delete(index : int)
> 
> Items and values can still be accessed using the key, e.g., sd[key],
> since all the dict's methods are available.

I agree with others that these APIs are really not necessary. Simply 
call keys(), values() or items() and then use that list if you really 
want indexing. If you're dealing with a lot of these kind of indexing 
behaviors, working with the plain list object will be faster anyway.

> Examples
> 
> To keep a collection of filenames on a case-insensitive file system in
> sorted order, we could use code like this:
> 
> files = collections.sorteddict.sorteddict()

The type should probably just be in collections directly. No need for a 
sub-package. So that would look like::

 files = collections.sorteddict()

I also strongly support Paul Hankin's proposal for the constructor API::

 sorteddict((mapping|sequence|..), cmp=None, key=None, reverse=False)

Being able to sort by a key= function would make sorteddict() 
dramatically more useful. I almost never use the builtin heap() because 
it doesn't support a key= function and I always need one. I suspect use 
cases for sorteddict() will be similar. For example::

 files = collections.sorteddict(key=lambda s: s.lower())
 for name in os.listdir("."):
 files[name] = ... some calculated value ...

Now the file names are in lower-case sorted order, but if you actually 
retrieve the keys, e.g. through .items(), you'll see the real filename, 
not the lower-cased ones.

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


Re: sorting a list numbers stored as strings

2007-09-25 Thread thebjorn
On Sep 25, 2:45 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Tue, 25 Sep 2007 12:46:54 +0800, Delaney, Timothy (Tim) wrote:
> > Carsten Haese wrote:
>
> >> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
> >>> I'm sure that in some version of Python it would have given a
> >>> ValueError (due to the default radix being 0) but it appears to have
> >>> changed to a default radix of 10 somewhere along the way.
>
> >> Not even Python 1.5.2 seems to have a problem with leading zeroes:
>
> >> Python 1.5.2 (#1, Nov  6 1999, 14:53:40) [C] on sco_sv3 Copyright
> >> 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> > int("08")
> >> 8
>
> > Yep - appears I must have been misremembering from another language
> > (dunno which) or I misinterpreted the docs.
>
> I also remember something in Python about leading zeroes leading to
> "surprising" effects... ah, I got it!
>
> >>> int("020")
> 20
> >>> 020
> 16

You can get the latter behavior using eval:

>>> eval("020")
16
>>> eval("09")
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1
09
^
SyntaxError: invalid token
>>>

This usually bites you in the @$$ when you're trying to store config
data as a Python datastructure in an external file -- so that you can
do config_data = eval(open('config.data').read()).

-- bjorn

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


Re: Nested For and While Statements

2007-09-25 Thread Zentrader
Scope had to do with "visibility" and not with how memory was
allocated.  Scope means, can this line of code access that block of
memory.  Note that in list comprehension, [x for x in (1, 2, 3)], the
for loop allocates memory the same way, but the scope changes so that
"x" is visible outside the for loop, so I guess we will have to agree
to disagree.

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


Invoking python through C++: How to?

2007-09-25 Thread Robert Dailey
Hi,

I have a python script that I would like to invoke through my C++
application. Does anyone know of a trivial way of doing this? Right now the
only idea I can come up with is using system("python myscript.py") in C++.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: M2Crypto 0.18 - new version, same old build bugs - more details

2007-09-25 Thread John Nagle
Heikki Toivonen wrote:
> John Nagle wrote:
> 
>>But notice that the -D entry didn't appear on the SWIG command line.
>>Neither did the "-includeall".  The "swig_opts" values around line
>>129 aren't actually being used.  I think that's left over from the code
>>intended
>>to allow builds with Python 2.3 and earlier.  The "self.swig_opts" up at
>>line 53 of "setup.py" seems to be controlling.  The patch was to
>>the obsolete code.
> 
> 
> Aha! Good find. I reopened
> https://bugzilla.osafoundation.org/show_bug.cgi?id=9404 and attached a
> patch that should address this for real this time. At least -includeall
> appears in my Ubuntu Dapper Drake environment. Could you give it a go
> and let me know how it works?

That's progress, but the build still doesn't work:

$ python setup.py build
running build
running build_py
running build_ext
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/local/include/python2.5 -I/usr/include -includeall 
-D__i386__ -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
/usr/include/openssl/opensslconf.h:13: Error: Unable to find 
'opensslconf-i386.h'
error: command 'swig' failed with exit status 1

Now that SWIG is being invoked with "-includeall", it has to have
all the include paths defined.  (Without "includeall", includes
are deferred until the C compile stage.) Note that the SWIG command line
specifies "/usr/include", but not "/usr/include/openssl".
Within M2Crypto's SWIG files, there's

_ec.i:%include 

which brings in "opensslconf.h" from /usr/include/openssl.
But that file has

#if defined(__i386__)
#include "opensslconf-i386.h"
#elif defined(__ia64__)
...

Since "opensslconf-i386.h" lives in /usr/include/openssl,
and that directory isn't mentioned on the SWIG command line,
the #include of "opensslconf-i386.h" fails.

And, no, adding

self.swig_opts.append('-DOPENSSL_NO_EC')
# Uncomment if you can't build with EC disabled

does not help.

As a test, I tried adding "-I/usr/include/openssl" to the SWIG command
line.  Building then gets further, but during a C compile, we get

SWIG/_m2crypto_wrap.c:2529:18: error: _lib.h: No such file or directory

and the build goes downhill from there, with many compile errors in the
GCC phase.  The gcc call

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes 
-fPIC -I/usr/local/include/python2.5 -c SWIG/_m2crypto_wrap.c -o 
build/temp.linux-i686-2.5/SWIG/_m2crypto_wrap.o -DTHREADING

is in the directory below SWIG, and doesn't include SWIG, so it's clear
why gcc couldn't find the file.

So those fixes were not enough.  Include file management in the M2Crypto build
clearly needs some work.

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread thebjorn
On Sep 25, 10:53 am, Mark Summerfield <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> Below is a PEP proposal for a sorteddict. It arises out of a
> discussion on this list that began a few weeks ago with the subject of
> "An ordered dictionary for the Python library?", and a similar one on
> the P3K mailing list with the subject "ordered dict for p3k
> collections?".
>
> If there is positive feedback I will submit the PEP to the reviewers,
> so if you think it is a good idea please say so. (I'm sure that if you
> _don't_ like it you'll tell me anyway:-)

I can't see much advantage over:

  for key in sorted(mydict):
  ...

A much simpler data-structure, that is also very useful, is a
dictionary that keeps insertion order -- it's also something that's a
tad bit more difficult to implement yourself than the above. My
personal implementation is documented at 
http://blog.tkbe.org/archive/python-property-set/
It's very tempting to add value access by numerical index (I did as
well), however I now think it's a mistake.

-1 from me.

-- bjorn




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


Script to extract text from PDF files

2007-09-25 Thread brad
I have a very crude Python script that extracts text from some (and I 
emphasize some) PDF documents. On many PDF docs, I cannot extract text, 
but this is because I'm doing something wrong. The PDF spec is large and 
complex and there are various ways in which to store and encode text. I 
wanted to post here and ask if anyone is interested in helping make the 
script better which means it should accurately extract text from most 
any pdf file... not just some.

I know the topic of reading/extracting the text from a PDF document 
natively in Python comes up every now and then on comp.lang.python... 
I've posted about it in the past myself. After searching for other 
solutions, I've resorted to attempting this on my own in my spare time. 
Using apps external to Python (pdftotext, etc.) is not really an option 
for me. If someone knows of a free native Python app that does this now, 
let me know and I'll use that instead!

So, if other more experienced programmer are interested in helping make 
the script better, please let me know. I can host a website and the 
latest revision and do all of the grunt work.

Thanks,

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


Re: comparing elements of a list with a string

2007-09-25 Thread Steve Holden
Larry Bates wrote:
> Shriphani wrote:
>> Hello all,
>> I have a problem here. I have a list named list_of_files which
>> contains filenames with their timestamps attached to the name. If I
>> have a string "fstab", and I want to list out the files in whose names
>> the word fstab appears should I go about like this :
>>
>> def listAllbackups(file):
>> list_of_files = os.listdir("/home/shriphani/backupdir")
>> for element in list_of_files:
>>  if element.find(file) != -1:
>>  date = ###
>>  time = 
>>   return (date, time)
>>
>> The major trouble is that the return statement causes it to exit after
>> attempt one. How do I use the yield statement here?
>>
>> Regards,
>> Shriphani Palakodety
>>
> 
> You should take a quick look at glob().  You may be able to use it to make 
> life 
> a lot easier.  Here is how you would do it if all your backup files begin with
> fstab.
> 
> import glob
> list_of_backup_files=glob.glob('/home/shriphani/backupdir/glob*')
> 
> If "fstab" can appear anywhere in the filename, this might not work for you.
> 
I don't see why

list_of_backup_files=glob.glob('/home/shriphani/backupdir/*fstab*')

shouldn't work. However, t answer the OP's question about yield (which 
nobody seems to have done fully yet):

1. Rewrite the function to become a generator function:

def listAllbackups(file):
 list_of_files = os.listdir("/home/shriphani/backupdir")
 for element in list_of_files:
  if file in element: # tidied this up too
  date = 1 ###
  time = 2 
  yield (date, time)

2. Create a generator by calling the function:

list_of_backup_files = listAllbackups("fstab")

3. Use the generator in an iterative context:

for file in list_of_backup_files:
 # do something

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

Sorry, the dog ate my .sigline

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


Re: Nested For and While Statements

2007-09-25 Thread metawilm
On Sep 25, 7:07 pm, Zentrader <[EMAIL PROTECTED]> wrote:
> Note that in list comprehension, [x for x in (1, 2, 3)], the
> for loop allocates memory the same way, but the scope changes so that
> "x" is visible outside the for loop,

How is this different? The variable spilling of list comprehension is
the same as for regular for loops. The (#) and (##) lines below don't
print the same value of j.

>>> for j in range(3):
...   print j, "first loop" (#)
...   for j in range(3):
... print " ", j, "2nd loop"
...   print j, "first loop, again?"  (##)


- Willem

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


Re: Clustering text-documents in bundles

2007-09-25 Thread Paul Rubin
"exhuma.twn" <[EMAIL PROTECTED]> writes:
> Is it possible to calculate a distance between two chunks of text? I
> suppose one could simply do a simple word-count on the chunks
> (removing common noise words of course). And then go from there. Maybe
> even assigning different weighting to words. But maybe there is a well-
> tested and useful algorithm already available?

There's a huge field of text mining that attempts to do things like
this.  http://en.wikipedia.org/wiki/Latent_semantic_analysis for some
info about one approach.  Manning & Schutz's book "Foundations of Statistical
Natural Language Processing" (http://nlp.stanford.edu/fsnlp/) is 
a standard reference about text processing.  They also have a
new one about information retrieval (downloadable as a pdf) that
looks very good: .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Paul Hankin
On Sep 25, 12:51 pm, Mark Summerfield <[EMAIL PROTECTED]>
wrote:
> On 25 Sep, 12:19, Paul Hankin <[EMAIL PROTECTED]> wrote:
>
>
>
> > Recall sorted...
> > sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted
> > list
>
> > So why not construct sorteddicts using the same idea of sortedness?
>
> > sorteddict((mapping | sequence | nothing), cmp=None, key=None,
> > reverse=None)
>
> > Then we can specify the exact behaviour of sorteddicts: it's the same
> > as a regular dict, except when the order of keys is important they're
> > ordered as if they were sorted by sorted(keys, cmp=sd._cmp,
> > key=sd._key, reverse=sd._reverse). Here I imagine cmp, key and reverse
> > are stored in the new sorteddict as attributes _cmp, _key, _reverse -
> > obviously the actual implementation may differ.
>
> > This has the benefit of making sorteddict's behaviour explicit and
> > easy to understand, and doesn't introduce a new sorting API when we
> > already have a perfectly decent one.
>
> > The only problem here is the **kwargs form of the dict constructor
> > doesn't translate as we're using keyword args to pass in the sort
> > criterion. Perhaps someone has an idea of how this can be solved. If
> > nothing else, this constructor could be dropped for sorteddicts, and
> > sorteddict(dict(**kwargs), cmp=..., key=..., reverse=...) when that
> > behaviour is wanted.
>
> > I don't like the integral indexing idea or the slicing: indexing and
> > slicing are already part of python and it's bad to have different
> > syntax for the same concept on sorteddicts. I'd say it's not an
> > important enough for sorteddicts anyway.
>
> > --
> > Paul Hankin
>
> This makes a lot of sense to me. But how do you envisage it would be
> implemented?

Here's a first go. Sorting occurs when the keys are iterated over,
making it fast (almost as a dict) for construction, insertion, and
deletion, but slow if you're iterating a lot. You should look at some
use cases to decide if this approach is best, or if a sorted
datastructure should be used instead, but my instinct is that this is
a decent approach. Certainly, you're unlikely to get a simpler
implementation :)

class sorteddict(dict):
"A sorted dictionary"
def __init__(self, arg=None, cmp=None, key=None, reverse=False):
if arg:
super(sorteddict, self).__init__(arg)
else:
super(sorteddict, self).__init__()
self._cmp = cmp
self._key = key
self._reverse = reverse
def keys(self):
return sorted(super(sorteddict, self).keys(), cmp=self._cmp,
key=self._key, reverse=self._reverse)
def iter_keys(self):
return (s for s in self.keys())
def items(self):
return [(key, self[key]) for key in self.keys()]
def iter_items(self):
return ((key, self[key]) for key in self.keys())
def values(self):
return [self[key] for key in self.keys()]
def iter_values(self):
return (self[key] for key in self.keys())
def __str__(self):
return '{' + ', '.join('%s: %s' % (repr(k), repr(v))
for k, v in self.iter_items()) + '}'
def __repr__(self):
return str(self)
def __iter__(self):
return self.iter_keys()

--
Paul Hankin

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


Survey about Visual Annotations for Software Models

2007-09-25 Thread Joerg Rech
Dear software practitioner,
  During software development, we often experience problems regarding
the compilability, quality (e.g., maintainability), or conformance of
our software. With a model-driven approach such as MDSD (Model-Driven
Software Development), we might work on a higher abstraction level
( i.e., software models), but we (will) still experience similar
problems during the development of our software models.

Therefore, in the context of the VIDE project, we are conducting a
survey about how software modeling environments should annotate
software models in order to provide additional information about these
problems. Our goal is to get feedback from you on several annotation
concepts and your opinion about other characteristics of defect
annotations.

Hence, we would like to invite you and members of your organization to
participate in the survey at http://www.online-poll.de/uc/vide-ma/.
Answering the survey should take about 20-30 minutes. The survey will
close on 1 October 2007.

We will draw five winners from all participants who finalized the
survey; they will get an Amazon gift certificate (either amazon.com or
from a local site) for $50.

Please pass information about this survey on to your colleagues and
managers as well as other contacts who might be interested in this
topic.

Many thanks in advance,
Joerg Rech and Axel Spriestersbach

---
Joerg Rech
Project Manager and Scientist
Speaker of the GI-Workgroup on Architecture and Design Patterns

Fraunhofer Institute for Experimental Software Engineering (IESE)
Tel.: +49 (0) 631/6800-2210 email: joerg.rech (at) iese.fraunhofer.de
XING: http://www.xing.com/profile/Joerg_Rech/
LinkedIn: http://www.linkedin.com/in/joergrech

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


Re: sorting a list numbers stored as strings

2007-09-25 Thread ZeD
thebjorn wrote:

>> >>> int("020")
>> 20
>> >>> 020
>> 16
> 
> You can get the latter behavior using eval:

why using eval when int has the "base" optional parameter?

>>> int("020")
20
>>> int("020", 8)
16
>>> int("09", 8)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: invalid literal for int() with base 8: '09'
>>>

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


RE: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Hamilton, William
> From: Paul Hankin
> 
> 
> Here's a first go. Sorting occurs when the keys are iterated over,
> making it fast (almost as a dict) for construction, insertion, and
> deletion, but slow if you're iterating a lot. You should look at some
> use cases to decide if this approach is best, or if a sorted
> datastructure should be used instead, but my instinct is that this is
> a decent approach. Certainly, you're unlikely to get a simpler
> implementation :)
> 
> class sorteddict(dict):
> "A sorted dictionary"
> def __init__(self, arg=None, cmp=None, key=None, reverse=False):
> if arg:
> super(sorteddict, self).__init__(arg)
> else:
> super(sorteddict, self).__init__()
> self._cmp = cmp
> self._key = key
> self._reverse = reverse
> def keys(self):
> return sorted(super(sorteddict, self).keys(), cmp=self._cmp,
> key=self._key, reverse=self._reverse)
> def iter_keys(self):
> return (s for s in self.keys())
> def items(self):
> return [(key, self[key]) for key in self.keys()]
> def iter_items(self):
> return ((key, self[key]) for key in self.keys())
> def values(self):
> return [self[key] for key in self.keys()]
> def iter_values(self):
> return (self[key] for key in self.keys())
> def __str__(self):
> return '{' + ', '.join('%s: %s' % (repr(k), repr(v))
> for k, v in self.iter_items()) + '}'
> def __repr__(self):
> return str(self)
> def __iter__(self):
> return self.iter_keys()


You could speed up keys() at the cost of memory if you maintained a list
of keys in the instance.  Doing so would let you use an "unsorted" flag
that gets set when a new key is added and checked when keys() is called.
If the flag is unset, just return a copy of the list.  Otherwise, sort
the list in place, return a copy, and unset the flag.  (Copies because
you don't want the master key list to be modified by code using the
class.)

The use case for this seems to be when you have a dictionary that you
need to often work through in sorted order.  Sorting the keys every time
keys() is called isn't an improvement over using a regular dict and
sorting the keys normally.  So the extra memory cost of maintaining an
internal keys list looks reasonable to me.



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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Steven Bethard
Paul Hankin wrote:
> On Sep 25, 12:51 pm, Mark Summerfield <[EMAIL PROTECTED]>
> wrote:
>> On 25 Sep, 12:19, Paul Hankin <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>> Recall sorted...
>>> sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted
>>> list
>>> So why not construct sorteddicts using the same idea of sortedness?
>>> sorteddict((mapping | sequence | nothing), cmp=None, key=None,
>>> reverse=None)
>>> Then we can specify the exact behaviour of sorteddicts: it's the same
>>> as a regular dict, except when the order of keys is important they're
>>> ordered as if they were sorted by sorted(keys, cmp=sd._cmp,
>>> key=sd._key, reverse=sd._reverse). Here I imagine cmp, key and reverse
>>> are stored in the new sorteddict as attributes _cmp, _key, _reverse -
>>> obviously the actual implementation may differ.
>>> This has the benefit of making sorteddict's behaviour explicit and
>>> easy to understand, and doesn't introduce a new sorting API when we
>>> already have a perfectly decent one.
>>> The only problem here is the **kwargs form of the dict constructor
>>> doesn't translate as we're using keyword args to pass in the sort
>>> criterion. Perhaps someone has an idea of how this can be solved. If
>>> nothing else, this constructor could be dropped for sorteddicts, and
>>> sorteddict(dict(**kwargs), cmp=..., key=..., reverse=...) when that
>>> behaviour is wanted.
>>> I don't like the integral indexing idea or the slicing: indexing and
>>> slicing are already part of python and it's bad to have different
>>> syntax for the same concept on sorteddicts. I'd say it's not an
>>> important enough for sorteddicts anyway.
>>> --
>>> Paul Hankin
>> This makes a lot of sense to me. But how do you envisage it would be
>> implemented?
> 
> Here's a first go. Sorting occurs when the keys are iterated over,
> making it fast (almost as a dict) for construction, insertion, and
> deletion, but slow if you're iterating a lot. You should look at some
> use cases to decide if this approach is best, or if a sorted
> datastructure should be used instead, but my instinct is that this is
> a decent approach. Certainly, you're unlikely to get a simpler
> implementation :)
> 
> class sorteddict(dict):
> "A sorted dictionary"
> def __init__(self, arg=None, cmp=None, key=None, reverse=False):
> if arg:
> super(sorteddict, self).__init__(arg)
> else:
> super(sorteddict, self).__init__()
> self._cmp = cmp
> self._key = key
> self._reverse = reverse
> def keys(self):
> return sorted(super(sorteddict, self).keys(), cmp=self._cmp,
> key=self._key, reverse=self._reverse)
> def iter_keys(self):
> return (s for s in self.keys())
> def items(self):
> return [(key, self[key]) for key in self.keys()]
> def iter_items(self):
> return ((key, self[key]) for key in self.keys())
> def values(self):
> return [self[key] for key in self.keys()]
> def iter_values(self):
> return (self[key] for key in self.keys())
> def __str__(self):
> return '{' + ', '.join('%s: %s' % (repr(k), repr(v))
> for k, v in self.iter_items()) + '}'
> def __repr__(self):
> return str(self)
> def __iter__(self):
> return self.iter_keys()

With this is the implementation, I'm definitely -1. Not because it's a 
bad implementation, but because if the iteration is always doing a sort, 
then there's no reason for a separate data structure. Just use sorted() 
directly on a regular dict. That has the advantage of being much more 
obvious about where the expensive operations are::

 for key in sorted(d, ...):
 ... whatever you want to do ...

IMHO, the only reason to introduce a sorteddict() is if it minimizes the 
cost of sorting the keys.

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


Re: Script to extract text from PDF files

2007-09-25 Thread Paul Hankin
On Sep 25, 6:41 pm, brad <[EMAIL PROTECTED]> wrote:
> I have a very crude Python script that extracts text from some (and I
> emphasize some) PDF documents. On many PDF docs, I cannot extract text,
> but this is because I'm doing something wrong. The PDF spec is large and
> complex and there are various ways in which to store and encode text. I
> wanted to post here and ask if anyone is interested in helping make the
> script better which means it should accurately extract text from most
> any pdf file... not just some.
>
> I know the topic of reading/extracting the text from a PDF document
> natively in Python comes up every now and then on comp.lang.python...
> I've posted about it in the past myself. After searching for other
> solutions, I've resorted to attempting this on my own in my spare time.
> Using apps external to Python (pdftotext, etc.) is not really an option
> for me. If someone knows of a free native Python app that does this now,
> let me know and I'll use that instead!

Googling for 'pdf to text python' and following the first link gives
http://pybrary.net/pyPdf/

--
Paul Hankin

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


Re: [Tutor] Take if offline

2007-09-25 Thread Shawn Milochik
Since everyone else is replying to the list, I'll (top) post this:

No, not really. He had to give everyone the rule once. Otherwise, he'd
have to do it a hundred times a day, and monitor every single post to
find out who he had to inform. He'd end up doing not much else with
his life, and would flee to a monastery and give up coding forever.
You wouldn't want that to happen, would you?




On 9/25/07, Michael Langford <[EMAIL PROTECTED]> wrote:
> I agree with Kent...
>
> --
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.TierOneDesign.com/
> Entertaining:
> http://www.ThisIsYourCruiseDirectorSpeaking.com
>
>
> On 9/25/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
> > Hansen, Mike wrote:
> > > Anytime someone posts in HTML, or posts without a subject, or
> > > accidentally
> > > hijacks a thread, or top-posts, or writes in caps, a couple of posters
> > > pop up
> > > and complain. Rather than posting to the entire list, I think it'd be
> > > best if
> > > you send your complaint directly to the "offending" user. I'd prefer to
> > > read
> > > about Python not read lessons in net/mail-list etiquette.
> >
> > Hmmm. So instead, whenever someone complains about netiquette on-list we
> > should post on-list complaining about it? I'm not sure that improves the
> > situation any, especially if it sparks a discussion. Perhaps you should
> > email your suggestion privately to the offending parties. :-)
> >
> > I definitely think this list is about how to be part of the Python
> > community, as well as how to program in Python. Knowing how to
> > participate in a mailing list is part of that. Maybe you could just skip
> > those posts, there are not that many of them.
> >
> > Kent
> > ___
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Please read:
http://milocast.com/2007/07/31/this-i-believe/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Script to extract text from PDF files

2007-09-25 Thread byte8bits
On Sep 25, 3:02 pm, Paul Hankin <[EMAIL PROTECTED]> wrote:
> Googling for 'pdf to text python' and following the first link 
> giveshttp://pybrary.net/pyPdf/

Doesn't work that well, I've tried it, you should too... the author
even admits this:

extractText() [#]

Locate all text drawing commands, in the order they are provided
in the content stream, and extract the text. This works well for some
PDF files, but poorly for others, depending on the generator used.
This will be refined in the future. Do not rely on the order of text
coming out of this function, as it will change if this function is
made more sophisticated. - source 
http://pybrary.net/pyPdf/pythondoc-pyPdf.pdf.html

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Hrvoje Niksic
Steven Bethard <[EMAIL PROTECTED]> writes:

> With this is the implementation, I'm definitely -1. Not because it's a
> bad implementation, but because if the iteration is always doing a
> sort, then there's no reason for a separate data structure.

Agreed.  A true sorted dict would keep its keys sorted in the first
place, a la C++ std::map.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Paul Hankin
On Sep 25, 7:58 pm, Steven Bethard <[EMAIL PROTECTED]> wrote:
> > Paul Hankin wrote:
> > ...
> > class sorteddict(dict):
> > "A sorted dictionary"
> > def __init__(self, arg=None, cmp=None, key=None, reverse=False):
> > if arg:
> > ...
>
> With this is the implementation, I'm definitely -1. Not because it's a
> bad implementation, but because if the iteration is always doing a sort,
> then there's no reason for a separate data structure. Just use sorted()
> directly on a regular dict. That has the advantage of being much more
> obvious about where the expensive operations are::
>
>  for key in sorted(d, ...):
>  ... whatever you want to do ...
>
> IMHO, the only reason to introduce a sorteddict() is if it minimizes the
> cost of sorting the keys.

I disagree with your reason for introducing a sorteddict - the main
reason should be if it makes code that uses it simpler and more
readable, with efficiency (within reasonable limits) being of
secondary importance. Unfortunately for sorteddict, your code is
simpler and more explicit for most obvious use cases.

But, with Bill's cached sorted key list it'll be reasonably efficient,
and it's likely possible to update the sorted cache more efficiently
than resorting if there's only been a small number of insertions since
the last sort, but I haven't the time to do a thorough job.

--
Paul Hankin

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


Re: [ANN] Release 0.65.1 of Task Coach

2007-09-25 Thread Dmitry Balabanov
2007/9/24, Frank Niessink <[EMAIL PROTECTED]>:
> Hi,
>
> I'm happy to announce release 0.65.1 of Task Coach. This release fixes
> one critical bug and two minor bugs. Since the critical bug may lead
> to data loss, I recommend users of release 0.65.0 to upgrade.
>
> Bugs fixed:
>
> * Saving a task file after adding attachments via the 'add attachment'
> menu or context menu fails.
> * Tooltip windows steals keyboard focus on some platforms.
> * Taskbar icon is not transparent on Linux.
>
>
> What is Task Coach?
>
> Task Coach is a simple task manager that allows for hierarchical
> tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is
> developed using Python and wxPython. You can download Task Coach from:
>
> http://www.taskcoach.org
>
> In addition to the source distribution, packaged distributions are
> available for Windows XP, Mac OSX, and Linux (Debian and RPM format).
>
> Note that Task Coach is alpha software, meaning that it is wise to back
> up your task file regularly, and especially when upgrading to a new
> release.
>
> Cheers, Frank
> --
> http://mail.python.org/mailman/listinfo/python-announce-list
>
> Support the Python Software Foundation:
> http://www.python.org/psf/donations.html
>


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


Re: Who can develop the following Python script into working application ?

2007-09-25 Thread Tobiah
Diez B. Roggisch wrote:
> Andrey Khavryuchenko schrieb:
>>  DBR> And as you said yourself:
>>
>>  DBR> """
>>  DBR> Frankly speaking I would prefer to pay for your kind assistance
>>  DBR> as it may take me to much time to learn some Python and 
>> understand the
>>  DBR> following script.
>>  DBR> """
>>
>>  DBR> Now, again: http://www.guru.com/ There you can get devlopers for
>>  DBR> money. So what again is your problem?
>>
>> Actually, I am a python (and django) developer, looking for a contract,
>> owning Nokia 770 and contacted original poster with no response.
> 
> Well, I presume the above quoted wasn't exactly true - in the end, the 
> whole attitude of the OP smelled after "I want you to do work for me for 
> free that I'm unwilling to bother myself with - as it would mean putting 
> effort into it."
> 
> Diez

Jeepers - It says right there in the quote that he is willing to pay.
I don't see why the OP is getting so much flack for his question, even
if it is thought to be a little off topic.


-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread chris . monsanto
On Sep 25, 1:35 pm, thebjorn <[EMAIL PROTECTED]>
wrote:
> On Sep 25, 10:53 am, Mark Summerfield <[EMAIL PROTECTED]>
> wrote:
>
> > Hi,
>
> > Below is a PEP proposal for a sorteddict. It arises out of a
> > discussion on this list that began a few weeks ago with the subject of
> > "An ordered dictionary for the Python library?", and a similar one on
> > the P3K mailing list with the subject "ordered dict for p3k
> > collections?".
>
> > If there is positive feedback I will submit the PEP to the reviewers,
> > so if you think it is a good idea please say so. (I'm sure that if you
> > _don't_ like it you'll tell me anyway:-)
>
> I can't see much advantage over:
>
>   for key in sorted(mydict):
>   ...
>
> A much simpler data-structure, that is also very useful, is a
> dictionary that keeps insertion order -- it's also something that's a
> tad bit more difficult to implement yourself than the above. My
> personal implementation is documented 
> athttp://blog.tkbe.org/archive/python-property-set/
> It's very tempting to add value access by numerical index (I did as
> well), however I now think it's a mistake.
>
> -1 from me.
>
> -- bjorn

I agree on both counts. When I saw this topic, I was hoping it would
be about a structure that remembers insertion order. Now if you
drafted a pep on THAT, I would stand behind it.

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


Overriding Logging Config FileHandler Filename

2007-09-25 Thread Kenneth Love
I have a Python logging config file that contains a RotatingFileHandler
handler.  In the args key, I have hard-coded the log filename.  Everything
works great.

However, I find that I now need to override this filename at application
runtime.  Is there a good way to do this?

Here is a bit of sample code that (hopefully) clarifies my question.

--- log.ini -
[loggers]
keys=root,processor

; Lots more stuff here: handlers, formatters, and loggers...

[handlers]
keys=consoleHandler,fileHandler

[handler_fileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=standard
args=('D:\Projects\Python\src\log.log', 'a', 9, 10)

-- mymain.py -
import logging.config

logging.config.fileConfig('log.ini')

# TODO: Override log filename with new name (e.g. 'd:\\logs\\mymain.py.log')

log = logging.getLogger('mymain')

log.info('START: mymain.py')
log.info('FINISH: mymain.py')
--

adTHANKSvance,
Kenneth Love

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Kenneth Love   | Oklahoma Tax Commission
DP Programmer/Analyst  | Information Technology
(405) 522 - 5864   | http://www.tax.ok.gov/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 


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


  1   2   >