Re: Where is the document of python-mode.el

2005-09-14 Thread Fredrik Lundh
"JackPhil" <[EMAIL PROTECTED]> wrote:

> I searched in the python-mode.el, sf.net, python.org, and found nothing

what document?

if you want documentation, switching to a python buffer and typing
alt-X followed by "describe-mode" works for me (alternatively, press
control-H followed by M):

...

Python mode:
Major mode for editing Python files.

...

This mode knows about Python indentation, tokens, comments and
continuation lines.  Paragraphs are separated by blank lines only.

COMMANDS
key binding
--- ---
ESC  Prefix Command
LFD  py-newline-and-indent
DEL  py-delete-char
...

to get detailed information about a given command, use describe-key
or describe-function.  e.g. "describe-key backspace" (=DEL on my key-
board) gives me:

DEL runs the command py-delete-char:

Reduce indentation or delete character.
If point is at the leftmost column, deletes the preceding newline.

Else if point is at the leftmost non-blank character of a line that is
neither a continuation line nor a non-indenting comment line, or if
point is at the end of a blank line, reduces the indentation to match
that of the line that opened the current block of code.  The line that
opened the block is displayed in the echo area to help you keep track
of where you are.  With numeric count, outdents that many blocks (but
not past column zero).

Else the preceding character is deleted, converting a tab to spaces if
needed so that only a single column position is deleted.  Numeric
argument delets that many characters.

for variables, use describe-variable.  e.g. "describe-variable py-indent-
offset" displays:

py-indent-offset's value is 4

Documentation:
*Indentation increment.
Note that `C-c :' can usually guess a good value
when you're editing someone else's Python code.

(all this text comes from the python-mode.el file, so I'm a bit surprised
that you didn't find anything by looking inside it).

(if you need installation help, see the comments at the top of the python-
mode.el file.  look for the "INSTALLATION" heading)





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


Python linear algebra module -- requesting comments on interface

2005-09-14 Thread C. Barnes

Szabolcs Nagy wrote:
>nice interface, but with 3d apps i prefer cgkit's
approach, which has
>vec3, vec4, mat3, mat4 and quat types with lots of
useful functions for
>3d graphics (like mat4.looakAt(pos, target, up) or
mat3.toEulerXYZ())

>there are other libs with similar types and
functions:
>cgkit (http://cgkit.sourceforge.net/)

Thanks for the link!  I had planned on changing around
the constructors: using Matrix.zero(),
Matrix.identity(), and Matrix.random() static methods
(instead of module functions), and adding
Matrix.rotate(), Matrix.translate(), Matrix.scale()
for homogenous 4-matrices and with an optional arg
that would make a 3-matrix in special cases.  Then I
thought  I'd add affine_transform() and
homogeneous_transform() module methods, which could
transform several vectors at once if they are stored
in a matrix.

But I looked over cgkit's interface, and it is EXACTLY
what I wanted.  I guess my scientific programming
background made me think up too general of an
interface.  So I've cancelled this linear algebra
library.

If anyone needs the matrix decompositions, and you
can't find them elsewhere, you can always make your
own library.  I was planning on using the public
domain code from:

 http://math.nist.gov/javanumerics/jama/

ftp://math.nist.gov/pub/Jampack/Jampack/AboutJampack.html

 - Connelly Barnes




__ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


calling .Net Webservice using SOAPpy

2005-09-14 Thread Achim Domma (SyynX Solutions GmbH)
Hi,

I'm using SOAPpy to call a .Net Webservice. Using 
WSDL.Proxy(service_url) works fine but has to get the WSDL each time 
from the server.

If I try SOAPpy.SOAPProxy(service_url) the call fails with low level 
SOAP errors.

Was somebody able to call a .Net service without using WSDL.Proxy and 
could provide me with an example?

regards,
Achim

PS.: I could post error message, but I don't think that they are very 
helpfull.
-- 
http://mail.python.org/mailman/listinfo/python-list


retrieve data using FTP in Python

2005-09-14 Thread swarna pulavarty

Hi all, 
 
I am new to this Python group and to Python . I need to retrieve data from an arbitrary URL and save it to a file.
Can anyone tell me how to retrieve "any" data using FTP modules in Python ? And also, Can you suggest me some books and online references to get familiar with Python and especially FTP modules in Python ? 
 
Your help is appreciated !
 
Swarna.
		 
Yahoo! India Matrimony: Find your partner now.-- 
http://mail.python.org/mailman/listinfo/python-list

How to make python24.dll smaller ?

2005-09-14 Thread Stormbringer
Hello,

I am trying to make an executable for one of my applications with cx
freeze. All works ok although I must include python24.dll with it if I
want to redistribute it. The big problem is python24.dll size, it's 1.8
MB and I am sure I don't need much of what's in there.

I downloaded python source code and built the dll using the VC 7.1
project (directory PCBuild/), still can't figure out how I can tweak
the project so I get smaller dll - for example is there a way to find
out what modules are included, what is the approx size they take inside
the dll and how can I not include them by default ?

Thanks,
Andrei

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


Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread barnesc

Hi again,

Since my linear algebra library appears not to serve any practical
need (I found cgkit, and that works better for me), I've gotten bored
and went back to one of my other projects: reimplementing the Python
builtin classes list(), set(), dict(), and frozenset() with balanced
trees (specifically, counted B-trees stored in memory).

In short, this allows list lookup, insertion, deletion in O(log(N))
time.  It allows the set and dictionary types to be maintained in
order, and insert/lookup/remove operations here take O(log(N)) time
as well.  Getting the k least or k greatest elements takes
O(log(N)+k) time.

I'm about 50% done with the implementation of this module.

I thought I'd use this for Dijkstra's algorithm and some schedulers,
but then I noticed that a binary heap can be retrofitted to have the
DECREASE-KEY operation (see e.g. David Eppstein's priorityQueue).
Thus my B-tree based classes aren't really necessary, since there are
simpler heap implementations that do the same thing.

So my question is: are there any other *practical* applications of a
B-tree based list/set/dict ?  In other words, is this module totally
worth coding, or is it just academic wankery and theoretical flim
flam ? :)

Thanks for your comments/opinions/etc...

 - Connelly Barnes
   'Y29ubmVsbHliYXJuZXNAeWFob28uY29t'.decode('base64')


-
Detailed overview of the bcollections module (from the docstring)
-

"""
...

The bset() and bdict() classes improve upon the builtin set and
dictionary types by maintaining the elements in sorted order.

Generally, the b* classes are a factor of O(log(N)) slower[2] than the
corresponding builtin classes, except for certain operations:

 - For a bset(), it takes O(log(N)) time to get the minimum, maximum,
   or ith element.  Also, it takes O(log(N)+k) time to get the
   k first, k last, or any slice of k elements from the sorted set.
 - For a bdict(), dictionary keys can be retrieved in sorted order
   with the above time bounds.
 - For a blist(), items can be inserted and removed in O(log(N)) time.
   It takes O(log(N)+k) time to get, set, or delete a slice of k
   elements.

...

blist  - List implemented via B-tree.
bset   - Set implemented via B-tree.
 Additional methods:
   - s.min()- Minimum element
   - s.max()- Maximum element
   - s.index(x) - Index of x in sorted list of
  elements.
   - s.next(x)  - Least element which is > x
  (x need not be in the set).
   - s.previous(x)  - Greatest element which is < x
  (x need not be in the set).
   - s[i]   - Get element i from sorted list.
   - s[i:j] - Get slice from sorted list.
bfrozenset - Immutable set implemented via B-tree.
bdict  - Dict implemented via B-tree.
 Additional methods:
   - a.min()- Minimum key
   - a.max()- Maximum key
   - a.index(k) - Index of k in sorted list of
  keys.
   - s.next(x)  - Least key which is > x
  (x need not be an existing key).
   - s.previous(x)  - Greatest key which is < x
  (x need not be an existing key).
   - a.get_key_at(i)- Get key at index i from sorted
  list of keys.
   - a.get_key_at(i, j) - Get slice from sorted key list.
"""
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read stdout/stderr without blocking

2005-09-14 Thread Adriaan Renting

 
 
>>>Jacek Pop*awski <[EMAIL PROTECTED]> 09/13/05 9:23 am >>> 
Grant Edwards wrote: 
>On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> wrote: 
> 
>>>   ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s 
>>>   for file in ready[0]: 
>>>   try: 
>>>   text = os.read(file, 1024) 
>> 
>>How do you know here, that you should read 1024 characters? 
>>What will happen when output is shorter? 
> 
> 
>It will return however much data is available. 
| 
|My tests showed, that it will block. 
|

IIRC it only blocks if there's nothing to read, that's why the select.select is 
done, which has a 0.25s timeout.
Please also note the fcntl.fcntl(self._child_fd, fcntl.F_SETFL, os.O_NONBLOCK) 
I do in the beginning of my code.

I basically stole this system from subProcess and Pexpect, both use the same 
mechanic. I just mashed those two together so I can read stdout and stderr 
separately in (near) real time, and reply to questions the external process 
asks me (like password prompts). It works on Linux with Python 2.3.4, the OP 
seems to use a different platform so YMMV. You can poll instead of select I 
think, but probably also only on Unix, this is from an earlier version of my 
code:

##self.poll.register(self._child_fd)
##self.poll.register(self._errorpipe_end)
...
##if self._fd_eof and self._pipe_eof:
##return 0
##ready = self.poll.poll(250)
##for x in ready:
##text = ''
##if (x[1] & select.POLLOUT) or (x[1] & select.POLLPRI):
##try:
##text = os.read(x[0], 1024)
##except:
##if x[0] == self._child_fd:
##self._fd_eof   = 1
##elif x[0] == self._errorpipe_end:
##self._pipe_eof = 1
##if (x[1] & select.POLLNVAL) or (x[1] & select.POLLHUP) or (x[1] & 
select.POLLERR) or (text == ''):
##if x[0] == self._child_fd:
##self._fd_eof   = 1
##elif x[0] == self._errorpipe_end:
##self._pipe_eof = 1
##elif text:
...
##self.poll.unregister(self._child_fd)
##self.poll.unregister(self._errorpipe_end)

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

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


Re: read stdout/stderr without blocking

2005-09-14 Thread Adriaan Renting
Please note that popen uses pipes, which are block devices, not character 
devices, so the writes will be done in blocks instead of characters/lines, (you 
can only read something _after_ the application at the other end of the pipe 
has done a flush or written 8192 bytes.

When reading from a pty like pexpect does, your read will not block until the 
stdio block buffer is filled.

Maybe using popen is your problem?  The FAQ of Pexpect explains the problem 
very clearly.
 
 
>>>Jacek Pop*awski <[EMAIL PROTECTED]> 09/13/05 4:36 pm >>> 
|Grant Edwards wrote: 
|>You're right.  I must have been remembering the behavior of a 
|>network socket.  Apparently, you're supposed to read a single 
|>byte and then call select() again.  That seems pretty lame. 
| 
|I created another thread with single read(), it works, as long as I have 
| only one PIPE (i.e. stderr is redirected into stdout). 
|I wonder is it Python limitation or systems one (I need portable solution)? 
-- 
http://mail.python.org/mailman/listinfo/python-list 

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Paul Rubin
"Paddy" <[EMAIL PROTECTED]> writes:
> A work colleague circulated this interesting article about reducing
> software bugs by orders of magnitude:
>   http://www.spectrum.ieee.org/WEBONLY/publicfeature/sep05/0905ext.html

This gets a not found error.  Got a different link?

> Some methods they talk about include removing error prone and ambiguous
> expressions from their ADA based language Sparc - The example they give
> is on why they removed the increment operators x++, x-- .

There's a famous paper by John Hughes called "Why Functional
Programming Matters" that (cheap oversimplification) says you should
never modify the value of any variable.  So, no increments, not even
for loops (use recursion instead).
-- 
http://mail.python.org/mailman/listinfo/python-list


An interesting python problem

2005-09-14 Thread Johnny Lee
Hi,
   Look at the follow command in python command line, See what's
interesting?:)

>>> class A:
i = 0
>>> a = A()
>>> b = A()
>>> a.i = 1
>>> print a.i, b.i
1 0

---

>>> class A:
arr = []
>>> a = A()
>>> b = A()
>>> a
<__main__.A instance at 0x00C96698>
>>> b
<__main__.A instance at 0x00CA0760>
>>> A

>>> a.arr.append("haha")
>>> print a.arr , b.arr
['haha'] ['haha']
>>> a.arr = ["xixi"]
>>> print a.arr , b.arr
['xixi'] ['haha']
>>> A.arr
['haha']
>>> A.arr.append("xx")
>>> A.arr
['haha', 'xx']
>>> a.arr
['xixi']
>>> b.arr
['haha', 'xx']
>>> b.arr.pop()
'xx'
>>> b.arr
['haha']
>>> A.arr
['haha']

-

>>> class X:
def __init__(self):
self.arr = []
>>> m = X()
>>> n = X()
>>> m.arr.append("haha")
>>> print m.arr, n.arr
['haha'] []

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


Re: CGIHTTPServer, popen3, and windoze

2005-09-14 Thread Fuzzyman

Fuzzyman wrote:
> Hello all,
>
> I may well post this a  a bug on Monday (after testing with Python 2.3)
> - but I thought I'd post here to see if anyone has any ideas.
>

Hmm... testing on Python 2.3 I *don't* have the same problem - but it's
very frustrating under Python 2.4 (different machine). I wonder what
else is different ?

Fuzzyman
http://www.voidspace.org.uk/python

> The basic problem is that under Python 2.4 (and windoze XP SP2)
> CGIHTTPServer isn't passing the CGI environment variables to scripts it
> runs.
>
> I've checked that the environment variables all exist in os.environ
> before the subprocess is launched using popen3.
>
> I've *also* checked that when I launch a test subprocess using popen3
> myself, environment variables *are* passed on - so I'm a bit
> confused...
>
> I wonder if anyone can shed any light on this behavior ?
>
> All the best,
>
>
> Fuzzyman
> http://www.voidspace.org.uk/python
>
> P.S. I've also patched CGIHTTPServer so that it can handle paths wih
> spaces and CGIs in subdirectories of the 'cgi-bin' folder. I'll
> *suggest* these changes to the maintainers -  but my tests were on the
> original version.

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


Re: Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote:
 > Hi again,
 >
 > Since my linear algebra library appears not to serve any practical
 > need (I found cgkit, and that works better for me), I've gotten bored
 > and went back to one of my other projects: reimplementing the Python
 > builtin classes list(), set(), dict(), and frozenset() with balanced
 > trees (specifically, counted B-trees stored in memory).
[...]
 > So my question is: are there any other *practical* applications of a
 > B-tree based list/set/dict ?  In other words, is this module totally
 > worth coding, or is it just academic wankery and theoretical flim
 > flam ? :)

B-trees are specifically designed for disk storage. Seeking to a
page takes much longer than reading a page of several kilobytes.
B-trees read the keys for a many-way comparison in one seek.

For in-memory comparison-based dictionaries, Red-Black trees,
AVL trees, 2-3 trees, or skip-lists, are a better choice.


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


Re: help in simplification of code [string manipulation]

2005-09-14 Thread Christophe
John a écrit :
> Thanks for your replies...
> Solved my problem.

Even so, I made a big mistake here. The Split function is of no use 
because there is already a list of flags. Better do it like that :
libs = Split('glut GLU GL m')
env.Append (LIBS = libs)

BTW, Split is a scons function.

> Christophe wrote:
> 
>>John a écrit :
>>
>>>How could I simplify the code to get libs out of LDFLAGS
>>>or vice versa automatically in the following python/scons code?
>>>
>>>if sys.platform[:5] == 'linux':
>>> env.Append (CPPFLAGS = '-D__LINUX')
>>> env.Append (LDFLAGS  = '-lglut -lGLU -lGL -lm')
>>> env.Append(CPPPATH=['include', 'include/trackball'])
>>> libs = ['glut',
>>> 'GLU',
>>> 'GL',
>>> 'm',]
>>>
>>>
>>>Thanks,
>>>--j
>>>
>>
>>Why don't you use the LIBS var in the environment instead of the LDFLAGS
>>? And what use would be the libs var for you ?
>>
>>if sys.platform[:5] == 'linux':
>>  libs = ['glut',
>>  'GLU',
>>  'GL',
>>  'm',]
>>  env.Append (CPPFLAGS = '-D__LINUX')
>>  env.Append (LIBS = Split(libs))
>>  env.Append(CPPPATH=['include', 'include/trackball'])
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


network parameters

2005-09-14 Thread le dahut
Hi,

Is there a way to get network parameters (number of network interfaces,
ip address(es), DNS, gateway) on a linux station using python 2.3 ?

Klaas



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


Re: Python Database Scripts

2005-09-14 Thread Simon Brunning
On 13 Sep 2005 11:32:05 -0700, Chuck <[EMAIL PROTECTED]> wrote:
> BTW, where is the DB-API docs for python?

Google is your friend - , 1st hit.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An interesting python problem

2005-09-14 Thread bruno modulix
Johnny Lee wrote:
> Hi,
>Look at the follow command in python command line, See what's
> interesting?:)
> 
> 
class A:
> 
>   i = 0
> 
a = A()
b = A()
a.i = 1
print a.i, b.i
> 
> 1 0

Quite what I would expect. First you declare i as being a *class*
attribute of A, with value 0. Then you create 2 instances a and b of A.
Then you add to a an *instance* variable named i (that then shadows the
class variable of the same name), with value 1. Then you print a.i,
wihci is the instance variable i of a, and b.i, which is the class
variable i of A, with value 0.

> ---
> 
> 
class A:
> 
>   arr = []
> 
a = A()
b = A()
a
> 
> <__main__.A instance at 0x00C96698>
> 
b
> 
> <__main__.A instance at 0x00CA0760>
> 
A
> 
> 
> 
a.arr.append("haha")
print a.arr , b.arr
> 
> ['haha'] ['haha']

Now you create a class A with a *class* variable arr which is an empty
list, and 2 instances a and b of A. Then you append to a.arr - which is
A.arr, so when you print a.arr and b.arr, you in fact print A.arr

a.arr = ["xixi"]

Then you add an instance variable arr to a, shadowing A.arr

print a.arr , b.arr
> 
> ['xixi'] ['haha']

So now you print a.arr and A.arr (accessed thru b)

(snip)


> 
class X:
> 
>   def __init__(self):
>   self.arr = []
> 
m = X()
n = X()
m.arr.append("haha")
print m.arr, n.arr
> 
> ['haha'] []
> 

Here you define a class X with an *instance* variable arr, and two
instances m and n of X, then append to m.arr, which of course has no
impact on n.

I dont see anything interesting nor problematic here. If you understand
the difference between class attributes and instance attributes, the
difference between mutating an object and rebinding a name, and the
attribute lookup rules in Python, you'll find that all this is the
normal and expected behavior.

Or did I miss something ?

-- 
bruno desthuilliers - is Python much more readable than Perl ???
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round() wrong in Python 2.4?

2005-09-14 Thread Nils Grimsmo
I am running Debian unstable for 386. Python 2.4 is from the official
package archive, and seems to be compiled with GCC 4.0.2.

$ dpkg -l python2.4
ii  python2.4   2.4.1-4 ...

$ python2.4
Python 2.4.1+ (#2, Sep  4 2005, 21:58:51)
[GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ gcc-4.0 --version
gcc-4.0 (GCC) 4.0.2 20050725 (prerelease) (Debian 4.0.1-3)


Klem fra Nils

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


Re: Unexpected Behavior Iterating over a Mutating Object

2005-09-14 Thread bruno modulix
Dave Hansen wrote:
(snip code snippets and sensible explanations)

> Again, iterating over an item that is mutating seems like a Bad
> Idea(tm) to me.  

It as *always* been a bad idea to modify a list in place (I mean adding
or removing items) while iterating over it, whatever the language. If
you *really* need to do such a thing (for effeciency reasons - and then
it's usually in low-level C code), you'd better use indexed access, and
adjust the index as needed - but this results in tricky, hard to
maintain code.

> But I was curious: is this the intended behavior, or
> does this fall under what C programmers would call 'undefined
> behavior.'

Not being a Language Lawyer(tm), I can't tell for sure, but I'd think
it's the expected behavior. Anyway it's not a behavior I'd relie upon,
since it would be too much of a dirty trick anyway.

My 2 cents
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An interesting python problem

2005-09-14 Thread Johnny Lee

bruno modulix wrote:
>
> I dont see anything interesting nor problematic here. If you understand
> the difference between class attributes and instance attributes, the
> difference between mutating an object and rebinding a name, and the
> attribute lookup rules in Python, you'll find that all this is the
> normal and expected behavior.
>
> Or did I miss something ?
> 

No, you didn't miss anything as I can see. Thanks for your help:)

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


new programms

2005-09-14 Thread Burgs A. Polygonal


Come and gat some




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

Re: An interesting python problem

2005-09-14 Thread bruno modulix
Johnny Lee wrote:
> bruno modulix wrote:
> 
>>I dont see anything interesting nor problematic here. If you understand
>>the difference between class attributes and instance attributes, the
>>difference between mutating an object and rebinding a name, and the
>>attribute lookup rules in Python, you'll find that all this is the
>>normal and expected behavior.
>>
>>Or did I miss something ?
>>
> 
> 
> No, you didn't miss anything as I can see. Thanks for your help:)

You're welcome !-)

Ok, I guess all this is not that intuitive, specially when comes from
less dynamic languages. Python's object model is quite powerful, but one
need to have a good understanding of it to understand *why* it works
that way. There's an interesting slideshow about metaclasses and
descriptors that may help (if your brain is robust enough !-) :

http://www.python.org/pycon/dc2004/papers/24/metaclasses-pycon.pdf

HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to make python24.dll smaller ?

2005-09-14 Thread Stormbringer
Ok, for anyone interested on the issue: I have found the solution. I
commented out some module lines inside config.c (modules I know for
certain I will not use) and removed the module .c files from the
project.

Biggest save was when I removed the Asian character encodings, reduced
size by about 650 KB.

I also changed the build options to link against multithreaded libs,
not multithreaded dll libs (which makes python24.dll dependent on
msvcr71.dll which in turn is not present on some people's computers and
would have to be distributed in that case).

Final result: a 1.1 MB python24.dll which works with my frozen apps and
is not dependent on msvcr71.dll and compressed goes to around 440 KB.
And I'm sure that depending on the project I still could trim some more
modules out.

Andrei

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


Re: What XML lib to use?

2005-09-14 Thread Edvard Majakari
Kalle Anke <[EMAIL PROTECTED]> writes:

> I'm confused, I want to read/write XML files but I don't really understand 
> what library to use.
>
> I've used DOM-based libraries in other languages, is PyXML the library to 
> use?

It depends. Like there's no best car - "best" is very dependant on use of the
vehicle concerned in addition to personal preferences - there's no best XML
module either. Some seem very well in many respects, though :)

I recommend using EffBot's ElementTree. It's very simple to use (you get to do
stuff without thinking delicacies of parsing/generating), and it is
_fast_. Now let me repeat the last part - normally speed is of no concern
with the computers we have nowadays, but using eg. xml.minidom to process
files of size > 10 MB, your system might get very sluggish unless you are
quite careful in traversing the parse tree (and maybe even then).

Using a SAX / full-compliant DOM parser could be good for learning things,
though. As I said, depends a lot.

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What XML lib to use?

2005-09-14 Thread Paul Boddie
Kalle Anke wrote:
> I've used DOM-based libraries in other languages, is PyXML the library to
> use?

I would start off with minidom; a tutorial I once wrote can be found
here:

http://www.boddie.org.uk/python/XML_intro.html

That should demonstrate some minor differences between PyXML-style DOMs
and those for languages like Java. Should you need a faster DOM
implementation, you might want to look at libxml2dom:

http://www.boddie.org.uk/python/libxml2dom.html

It's a pure Python module that uses the lower levels of libxml2's own
Python bindings, so if you already have libxml2 plus bindings
installed, it should be very convenient. Although libxml2dom isn't by
any means complete, I do use it myself and would welcome any feedback
which would make it better.

Paul

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


Re: An interesting python problem

2005-09-14 Thread Adriaan Renting
In my mind all Python variables are some kind of "named pointers", I find that 
thinking this way helps me a lot in understanding what I'm doing. I know that 
this is not completely technically correct as in the first two examples there 
is actually a new a.i/a.arr created that shadows A.i, but thinking like this 
helps me. Are there fundamental flaws to think this way?

Example:
>>>class A: 
i = 0  ## Class A has a pointer named i pointing to (int 0 object)
   ## A.i -> (int 0 object)
>>>a = A() ## point a.i to the same thing A.i points to
   ## A.i -> (int 0 object)
   ## a.i -> (int 0 object)
>>>b = A() ## point b.i to the same thing A.i points to
   ## A.i -> (int 0 object)
   ## a.i -> (int 0 object)
   ## b.i -> (int 0 object)
>>>a.i = 1 ## point a.i to a new (int object)
   ## A.i -> (int 0 object)
   ## b.i -> (int 0 object)
   ## a.i -> (int 1 object)
 
>>>class A: 
arr = [] ## A.i -> (empty list object)
>>>a = A()  ## point a.arr to the same thing A.arr points to
## A.arr -> (empty list object)
## a.arr -> (empty list object)
>>>a.arr.append("haha") ## insert ("haha" string object) into (empty list 
>>>object) both a.i and A.i point to
## A.i -> (list object) -> ("haha" string object)
## a.i -> (list object) -> ("haha" string object)
>>>a.arr = ["xixi"] ## point a.arr to a new (list object) pointing to a new 
>>>("xixi" string object)
## A.i -> (list object) -> ("haha" string object)
## a.i -> (different list object) -> ("xixi" string 
object)
>>>A.arr.append("xx")   ## insert ("xx" string object) into (list object) A.i 
>>>points to
## A.i -> (list object) -> ("haha" string object),("xx" 
string object)
## a.i -> (different list object) -> ("xixi" string 
object)
etc. ...
 
- 
 
>>>class X: 
def __init__(self): 
self.arr = []   ## instances of Class X have a named pointer arr 
pointing to a new (empty list object)
## X.arr does not exist!
>>>m = X()  ## creates a new (empty list object) and has m.arr 
>>>point to it
## m.arr -> (empty list object)
>>>n = X()  ## creates a new (empty list object) and has n.arr 
>>>point to it
## m.arr -> (empty list object)
## n.arr -> (different empty list object)
>>>m.arr.append("haha") ## insert ("haha" string object) into (list object) m.i 
>>>points to
## m.i -> (list object) -> ("haha" string object)
## n.i -> (different empty list object)

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

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Jeremy Sanders
Robert Kern wrote:

> That's not what he's asking about. He's asking why his Python 2.3 rounds
> 0.0225 *up* to 0.023 while his Python 2.4 rounds *down* to 0.022. It's
> the change in behavior that he's concerned with and isn't just the usual
> floating point problem.

You can't rely on either being true, given the nature of the inexact
representation of the number, and the fact that python ignores quite a lot
of the IEEE stuff. Different optimisations (particularly with the 80 bit
floating point registers in x86), will lead to different represenations.
Any code which relies on a particular behaviour is broken.

Jeremy

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


Re: PyGTK or wXPython?

2005-09-14 Thread paron
Just a thought -- you might consider using a HTTP/browser UI. It's
graphically ugly, but it's familiar for users, and it goes
cross-platform very well.

Plus, if you decide to move the app to a Web server, you're already
done.

Ron

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Antoon Pardon
Op 2005-09-13, Robert Kern schreef <[EMAIL PROTECTED]>:
> Jeremy Sanders wrote:
>> Nils Grimsmo wrote:
>> 
>>>Why did round() change in Python 2.4?
>> 
>> It the usual floating point representation problem. 0.0225 cannot be
>> represented exactly:
>
> That's not what he's asking about. He's asking why his Python 2.3 rounds
> 0.0225 *up* to 0.023 while his Python 2.4 rounds *down* to 0.022. It's
> the change in behavior that he's concerned with and isn't just the usual
> floating point problem.

I would say the usual floating point problem is involved.

Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down.

0.0225 isn't representable and it happens that the actual number
you get differ. Now which number python should choose when it is
fed 0.0225, I don't know. But expressing the different behaviour
as a change in round, suggest that the O.P. would be wise to
learn about floating point problems

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


tk.createfilehandler() broken with threaded tcl?

2005-09-14 Thread klappnase
Hello everyone,

I am running into troubles with some of my scripts that make use of
tk.createfilehandler() to catch the output messages of subprocesses I
started with popen2.Popen4() (debian linux, python-2.3.5, tk-8.4.9).
Sometimes when those background processes are running it happens that
the gui freezes and the processlist shows the subprocess in zombie
state.
I've been using the same scripts without problems on mandrake (with
several versions of python and tk), so I came to think the problem may
be the debian build of python / tk. Now I found that on debian (unlike
mandrake) tcl/tk is build with --enable-threads, so I thought this
*might* be the cause for the problems.
I tried and replaced the call to tk.createfilehandler() with a "manual"
loop that reads Popen4.fromchild() to catch the output messages and the
problems seem to be gone, so it looks like using tk.createfilehandler()
with threaded tk is the problem.
Does anyone have an idea if this makes sense or am I on the wrong
track?

Best regards

Michael

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


Re: What XML lib to use?

2005-09-14 Thread paron
One more vote for Amara! I think it's unmatched for ease of use, if you
already know Python.

Ron

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


Re: Magic Optimisation

2005-09-14 Thread ABO
Bengt Richter wrote:
> On 5 Sep 2005 07:27:41 -0700, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
>
> >I still think there are savings to be had by looping inside the
> >try-except block, which avoids many setup/teardown exception handling
> >steps.  This is not so pretty in another way (repeated while on
> >check()), but I would be interested in your timings w.r.t. your current
[...]
> Why not let popleft trigger an exception out of while True instead,
> and prevent tasks from raising StopIteration, and let them yield a None
> to indicate keep scheduling with no special action, and something else
[...]

The rule of thumb with exceptions is use them for infrequent events. If
you keep to this you end up with clean and fast code.

Provided task.next() raises StopIteration less than about 25% of the
time it is called, it is cleaner and more efficient to use an exception
than to return None. It is also more efficient to handle terminating by
allowing popleft trigger an exception. Try the following;

def loop(self):
self_call_exit_funcs = self.call_exit_funcs
self_pool_popleft = self.pool.popleft
self_pool_append = self.pool.append
while True:
try:
task = self_pool_popleft()
task.next()
self_pool_append(task)
except StopIteration:
self_call_exit_funcs(task)
except IndexError:
break

There are other "optimisations" that could be applied that make this
code faster but uglier. For example, putting another "while True: loop
inside the try block to avoid the try block setup each iteration. Also,
exception handling is slower when you specify the exception class (it
has to check if the exception matches), so you might be able to arrange
this with an anonymous accept: block around the task.next() to handle
the StopIteration exception.

Another thing that disturbs me is the popfirst/append every iteration.
Depending on how many loops through all the tasks before one
"finishes", you might find it more efficient to do this;

def loop(self):
self_pool = self.pool
self_pool_remove = self_pool.remove
self_call_exit_funcs = self.call_exit_funcs
while self_pool:
try:
for task in self_pool:
task.next()
except:
self_pool_remove(task)
self_call_exit_funcs(task)

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


some advice about Python GUI apps

2005-09-14 Thread mitsura
Hi,

I am writing a program in Python and I am using wx.Python for the GUI.
I have no prior GUI and Python experience so that's why I turn to the
specialists for aid.
Basically, my app is a wx.tree object with items. You can click on each
item and set some properties of the item (Pydata). To set the
properties of an item you click on the item and then a 'Set item
properties' window pops up.
However, I am looking for a way that you can only open 1 property
window per item. If I click on an item the 'Set item properties'
windows open but when I return to the tree window and select the same
item, I can open an additional 'set properties' window. This leads to
all kind of C++ errors because these properties windows seems to
interfere for some reason. I don't have enough OO/Python/GUI knowledge
yet to fully understand what actually happens.
Basically, what I want is that when you want to open an items property
window and the window is alread open that in stead of opening a new
window, the window the is already open pops to the foreground. Any
ideay how I can implement this.

Another solution would be to start the properties windows in a
'synchronous' mode, meaning that if this window is open, that you can't
manipulate the tree window anymore (~like in Word when you open the
'open file' window, you can't edit your doc until you this window is
closed again).

I hope this makes some sense.

Any help much appreciated.

Kris

Ps.: any refs to good OO/Python GUI books are also welcome (or URLs)

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


Re: An interesting python problem

2005-09-14 Thread bruno modulix
Adriaan Renting wrote:
> In my mind all Python variables are some kind of "named pointers",

Technically, they are key/value pairs in a dictionnary, the key being
the name and the value a reference to an object.

> I
> find that thinking this way helps me a lot in understanding what I'm
> doing. I know that this is not completely technically correct as in the
> first two examples there is actually a new a.i/a.arr created that
> shadows A.i, but thinking like this helps me. Are there fundamental
> flaws to think this way?

You have 3 things to keep in mind here:
1/ in Python, a class is an object to, and an instance keeps a reference
to it's class object.
2/ a name is first looked up in the object's dict, then in it's class dict.
3/ when assigning to a non-existent instance attribute (ie : a.i = 1),
you're in fact just adding a new key/value pair *in the object's dict*.

> Example:
> 
class A: 
> 
> i = 0  ## Class A has a pointer named i pointing to (int 0 object)
>## A.i -> (int 0 object)

class A's dict contains a 'i' key referencing an int(0) object

a = A() ## point a.i to the same thing A.i points to
> 
>## A.i -> (int 0 object)
>## a.i -> (int 0 object)

Since 'i' is not in a's dict, 'i' is looked up in A's dict

b = A() ## point b.i to the same thing A.i points to
> 
>## A.i -> (int 0 object)
>## a.i -> (int 0 object)
>## b.i -> (int 0 object)

idem

a.i = 1 ## point a.i to a new (int object)
> 
>## A.i -> (int 0 object)
>## b.i -> (int 0 object)
>## a.i -> (int 1 object)
>  

A new 'i' key is added to a's dict, with a reference to a int(1) object
as value

(etc, snip...)


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An interesting python problem

2005-09-14 Thread Steve Holden
Adriaan Renting wrote:
> In my mind all Python variables are some kind of "named pointers", I find 
> that thinking this way helps me a lot in understanding what I'm doing. I know 
> that this is not completely technically correct as in the first two examples 
> there is actually a new a.i/a.arr created that shadows A.i, but thinking like 
> this helps me. Are there fundamental flaws to think this way?
> 
[...]
This is a very good way to think about it. Each name lives in a specific 
namespace, and the interpreter has a defined order of namespaces when it 
tries to resolve a name. But the data objects that the names point to 
live in what I like to think of as "object space", and in the CPython 
implementation are garbage collected when the last pointer to them is 
deleted (or, equivalently, goes out of scope).

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Antoon Pardon wrote:
> Op 2005-09-13, Robert Kern schreef <[EMAIL PROTECTED]>:
> 
>>Jeremy Sanders wrote:
>>
>>>Nils Grimsmo wrote:
>>>
Why did round() change in Python 2.4?
>>>
>>>It the usual floating point representation problem. 0.0225 cannot be
>>>represented exactly:
>>
>>That's not what he's asking about. He's asking why his Python 2.3 rounds
>>0.0225 *up* to 0.023 while his Python 2.4 rounds *down* to 0.022. It's
>>the change in behavior that he's concerned with and isn't just the usual
>>floating point problem.
> 
> I would say the usual floating point problem is involved.
> 
> Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down.
> 
> 0.0225 isn't representable and it happens that the actual number
> you get differ. Now which number python should choose when it is
> fed 0.0225, I don't know. But expressing the different behaviour
> as a change in round, suggest that the O.P. would be wise to
> learn about floating point problems

Uhh, Python didn't change anything between 2.3 and 2.4 wrt round(). The
reason he is seeing a difference is because the two executables were
built with different compilers. The fact that the version of Python was
different in the two cases obscures the real cause.

Saying that 0.0225 can't be represented exactly as a binary floating
point number is entirely true but is an incomplete answer. Yes,
obviously binary floating point representations are involved. But one
could always define a standard representation scheme that always gives
the same answer for the same input. The fact is that for some reason
there are two schemes being used. Another fact is that this has nothing
to do with difference in the versions of Python he is using. Most of
Python's floating point behavior is a platform-dependent accident (as
Tim Peters always says), and Nils is using two slightly different platforms.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Removing duplicates from a list

2005-09-14 Thread Rubinho
I've a list with duplicate members and I need to make each entry
unique.

I've come up with two ways of doing it and I'd like some input on what
would be considered more pythonic (or at least best practice).

Method 1 (the traditional approach)

for x in mylist:
if mylist.count(x) > 1:
mylist.remove(x)

Method 2 (not so traditional)

mylist = set(mylist)
mylist = list(mylist)

Converting to a set drops all the duplicates and converting back to a
list, well, gets it back to a list which is what I want.

I can't imagine one being much faster than the other except in the case
of a huge list and mine's going to typically have less than 1000
elements.  

What do you think?  

Cheers, 

Robin

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


Re: some advice about Python GUI apps

2005-09-14 Thread Franz Steinhaeusler
On 14 Sep 2005 04:26:11 -0700, [EMAIL PROTECTED] wrote:

>Hi,
>
>I am writing a program in Python and I am using wx.Python for the GUI.
>I have no prior GUI and Python experience so that's why I turn to the
>specialists for aid.

Hello Kris,

I think the specialists are in the wxPython-mailing list ;)
http://www.wxpython.org/maillist.php

>Basically, my app is a wx.tree object with items. You can click on each
>item and set some properties of the item (Pydata). To set the
>properties of an item you click on the item and then a 'Set item
>properties' window pops up.

You mean a wx.TreeCtrl?
I don't understand exactly what you mean with "properties".
Do you have a sample program?
Sorry for not helping much.

>However, I am looking for a way that you can only open 1 property
>window per item. If I click on an item the 'Set item properties'
>windows open but when I return to the tree window and select the same
>item, I can open an additional 'set properties' window. 
>This leads to
>all kind of C++ errors because these properties windows seems to
>interfere for some reason. I don't have enough OO/Python/GUI knowledge
>yet to fully understand what actually happens.
>Basically, what I want is that when you want to open an items property
>window and the window is alread open that in stead of opening a new
>window, the window the is already open pops to the foreground. Any
>ideay how I can implement this.
>
>Another solution would be to start the properties windows in a
>'synchronous' mode, meaning that if this window is open, that you can't
>manipulate the tree window anymore (~like in Word when you open the
>'open file' window, you can't edit your doc until you this window is
>closed again).

Is the properties window a wx.Dialog?
If you show it with ShowModal(), then you must 
finish with it, before you can select another tree node.

>I hope this makes some sense.
>
>Any help much appreciated.
>
>Kris
>
>Ps.: any refs to good OO/Python GUI books are also welcome (or URLs)

There is a wxPython book in process, and it is publication is estimated
around end of this year.
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software bugs aren't inevitable

2005-09-14 Thread Steven D'Aprano
On Wed, 14 Sep 2005 01:05:55 -0700, Paul Rubin wrote:

> There's a famous paper by John Hughes called "Why Functional
> Programming Matters" that (cheap oversimplification) says you should
> never modify the value of any variable.  So, no increments, not even
> for loops (use recursion instead).


Which works wonderfully as an academic exercise, but doesn't tend to work
so terribly well in the real world where the performance and
resource-requirement differences between iteration and recursion can be
significant.

For instance, try these two simple functions for the nth number
in the Fibonacci sequence:

def fibr(n):
"Recursive version of Fibonacci sequence."
if n == 0:  return 0
elif n == 1:  return 1
else:return fibr(n-1) + fibr(n-2)

def fibi(n):
"Simple iterative version of Fibonacci sequence."
if n == 0:  return 0
elif n == 1:  return 1
else:
Fn2 = 0
Fn1 = 1
for _ in range(2, n+1):
s = Fn2 + Fn1
Fn2, Fn1 = Fn1, s
return s

Try timing how long it takes to generate the 30th Fibonacci number
(832040) using both of those algorithms. Now try the 50th. (Warning: the
amount of work done by the recursive version increases at the same rate as
the Fibonacci sequence itself increases. That's not quite exponentially,
but it is fast enough to be very painful.)


-- 
Steven.


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


Re: some advice about Python GUI apps

2005-09-14 Thread mitsura
Hi,

the properties of the items are just virtual properties like e.g.
color, icon, gender.
Just image that an item represent a human. You can then click on the
item and start a 'Set Human Properties' windows (a frame with a
Notebook object with multiple tabs).
In the 'Set Human Properties' window you then have multiple properties
you can set/change like e.g. hair color, gender, skin tone, ... stuff
like that.

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


Re: Removing duplicates from a list

2005-09-14 Thread Thomas Guettler
Am Wed, 14 Sep 2005 04:38:35 -0700 schrieb Rubinho:

> I've a list with duplicate members and I need to make each entry
> unique.
> 
> I've come up with two ways of doing it and I'd like some input on what
> would be considered more pythonic (or at least best practice).

> mylist = set(mylist)
> mylist = list(mylist)
> 
> Converting to a set drops all the duplicates and converting back to a
> list, well, gets it back to a list which is what I want.
> 
> I can't imagine one being much faster than the other except in the case
> of a huge list and mine's going to typically have less than 1000
> elements.  
> 
> What do you think?  

Hi,

I would use "set":

mylist=list(set(mylist))

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Re: Why do Pythoneers reinvent the wheel?

2005-09-14 Thread Magnus Lycka
Claudio Grondi wrote:
> To name a simplest example:
> What should I do to find a piece of code taking an
> integer and giving a string with binary form of a
> number? How to put some available pieces of code
> together if the binary form is needed and the integer
> is provided as a string holding its hexadecimal form?
> What if the string is the binary representation of the
> integer value as internally stored in memory?
> What if I would like the binary form to be splitted
> in nibbles separated with one space and bytes with
> two spaces?

It's possible that you have a point in principle,
but these examples don't strengthen your point.

A function that turns e.g. 5 into '101' is trivial
and just a few lines of code. Finding that in some
kind of code catalog would certainly be more work
than to just code it. Besides, there are a number
of variants here, so a variant that makes everybody
happy when it concerns dealing with negative numbers,
range checks, possibly filling with zeros to a certain
length etc, would probably be both bigger and slower
than what the average Joe needs.

This is simply the wrong level of reuse. It's too
simple and too varied. To be able to express things
like that in code is very basic programing.

You create integers from numeric representation in
strings with the int() function. You should read
chapter 2 in the library reference again Claudio.
This is one of the most common builtin function.
int() accepts all bases you are likely to use and
then some.

Filtering out spaces is again trivial.
"0101 0110".replace(' ','') Also chapter 2 in the
library manual.

You should read this until you know it Claudio! It's
really one of the most important pieces of Python
documentation.

I might be wrong, but I suspect you just need to get
more routine in programming. Your reasoning sounds a
bit like: "I don't want to invent new sentences all the
time, there should be a catalog of useful sentences
that I can look up and use.

Sure, there are phrase books for tourists, but they are
only really interesting for people who use a language
on a very naive level. We certainly reuse words, and
it's also very useful to reuse complete texts, from
short poems to big books. Sure, many sentences are often
repeated, but the ability to create new sentences in
a natural language is considered a basic skill of the
user. No experienced user of a language use phrase
books, and if you really want to learn a language
properly, phrase books aren't nearly as useful as proper
texts.

There are simply so many possibly useful sentences, so
it would be much, much more work to try to catalog and
identify useful sentences than to reinvent them as we
need them.

It's just the same with the kinds of problems you described
above. With fundamental language skills, you'll solve these
problems much faster than you can look them up. Sure, the
first attempts might be less than ideal, especially if you
haven't read chapter 2 in the library manual, but you learn
much, much more from coding than from looking at code
snippets.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGTK or wXPython?

2005-09-14 Thread Thomas Guettler
Am Tue, 13 Sep 2005 07:01:57 -0700 schrieb TPJ:

>> Beside this, wxPython (and wxWidgets) is often told to be more complete,
>> better documented and better supported than GTK/PyGTK.
> 
> Is wxPython often told to be more documented? By who?
> 
> Several months ago I wanted to choose a nice GUI for Python (Tkinter
> was out of question). I choosed PyGTK for one reason - it was much,
> much better documented than wxPython.

Yes, the pyGTK documentation ist good. For me, the pyGTK API is
easier than the API of wxPython. 

I switched from wxPython to pyGTK.

I don't know if you can create standalone applications
for windows, without installing gtk on the client.

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Re: Removing duplicates from a list

2005-09-14 Thread Will McGugan
Rubinho wrote:
> I've a list with duplicate members and I need to make each entry
> unique.
> 
> I've come up with two ways of doing it and I'd like some input on what
> would be considered more pythonic (or at least best practice).
> 
> Method 1 (the traditional approach)
> 
> for x in mylist:
> if mylist.count(x) > 1:
> mylist.remove(x)
> 
> Method 2 (not so traditional)
> 
> mylist = set(mylist)
> mylist = list(mylist)
> 
> Converting to a set drops all the duplicates and converting back to a
> list, well, gets it back to a list which is what I want.
> 
> I can't imagine one being much faster than the other except in the case
> of a huge list and mine's going to typically have less than 1000
> elements.  

I would imagine that 2 would be significantly faster. Method 1 uses 
'count' which must make a pass through every element of the list, which 
would be slower than the efficient hashing that set does. I'm also not 
sure about removing an element whilst iterating, I think thats a no-no.

Will McGugan
-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software bugs aren't inevitable

2005-09-14 Thread Jerzy Karczmarczuk
Steven D'Aprano recommends iteration over recursion:
> For instance, try these two simple functions for the nth number
> in the Fibonacci sequence:
> 
> def fibr(n):
> "Recursive version of Fibonacci sequence."
> if n == 0:  return 0
> elif n == 1:  return 1
> else:return fibr(n-1) + fibr(n-2)
> 
> def fibi(n):
> "Simple iterative version of Fibonacci sequence."
> if n == 0:  return 0

etc.
> Try timing how long it takes to generate the 30th Fibonacci number
> (832040) using both of those algorithms. Now try the 50th. (Warning: the
> amount of work done by the recursive version increases at the same rate as
> the Fibonacci sequence itself increases. That's not quite exponentially,
> but it is fast enough to be very painful.)


First of all, the recursive version of Fibonacci IS EXPONENTIAL in complexity,
don't say such not-quite-truth as "not quite". But, what is more important:

If you don't know too much about the way the functional programming is
used nowadays, please refrain from giving nonsensical examples, since
NOBODY serious programs something in the style of your recursive version.
Such anti-advertizing of recursion says less about the recursion
than about yourself. Here you are a recursive version linear in n; it
returns the two last Fibonacci numbers of the sequence

def fibo(n):
  if n<2:
 return (n-1,n)
  else:
 (a,b)=fibo(n-1)
 return (b,a+b)

The exponential complexity, cascading version is a nice test case how to
use memoization, though, so it is not entirely senseless to learn it.

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


Re: Removing duplicates from a list

2005-09-14 Thread Peter Otten
Rubinho wrote:

> I've a list with duplicate members and I need to make each entry
> unique.
> 
> I've come up with two ways of doing it and I'd like some input on what
> would be considered more pythonic (or at least best practice).
> 
> Method 1 (the traditional approach)
> 
> for x in mylist:
> if mylist.count(x) > 1:
> mylist.remove(x)

That would be an odd tradition:

>>> mylist = [1, 2, 1, 3, 2, 3]
>>> for x in mylist:
... if mylist.count(x) > 1:
... mylist.remove(x)
...
>>> mylist
[2, 1, 2, 3] # oops!

See "Unexpected Behavior Iterating over a Mutating Object" 
http://mail.python.org/pipermail/python-list/2005-September/298993.html
thread for the most recent explanation.

Rather, the traditional approach for an algorithmic problem in Python is to
ask Tim Peters, see his recipe at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560/
(which predates Python's set class).

Peter

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Giles Brown
Paddy wrote:
> I was wondering what Praxis thought of Python, and how good it would be
> if a Praxis engineer gave a critique of Python as a part of a flow for
> producing low bug-count software.

I used to work at Praxis about 4 years ago and Perl was their scripting
language of choice at that time as I recall :)

> This is rather like how doctest can check the test and expected result
> given in a doc-string against the implementation given in the function;
> indeed I wrote up such an example at work and circulated it amongst the
> resident perl mongers. - Gosh it fealt good :-)

I am probably a bit out of date with this and never used it in anger,
but there are basically two levels of annotation.

The first is data flow and is used to specify what variables affect
what.  That is, you may specify for a function that the resulting
variable z is affected by the values of variable x and y (thats the
basic idea, there is a bit more to it of course).  The toolset checks
that your code matches your annotations.  It relies on not having the
different names for the same variable (not something you can guarantee
in Python really :).

The next level of annotations is for proving your code matches a
specification in Z.  So your annotations are part of that proof and can
again be checked automatically.

>
> So, How do I get feedback from Praxis, Do they already read
> comp.lang.py?

Are there no email links on: http://www.praxis-his.com/sparkada/ ?

Hth,
Giles Brown


> 
> Cheers,  Paddy.

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


Re: What XML lib to use?

2005-09-14 Thread Fredrik Lundh
Edvard Majakari wrote:

> Using a SAX / full-compliant DOM parser could be good for learning things,
> though. As I said, depends a lot.

since there are no *sane* reasons to use SAX or DOM in Python, that's mainly
a job security issue...

 



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


How can I find all the dependencies of a py?

2005-09-14 Thread could ildg
when  I run a.py, it uses b.py,c.py and a.py uses x.py,y.py
How could I find all the modules that a.py and all of its imported modules?
Is there any built in functions or any tools to do this?
Thank you~, I really want to know it.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to protect Python source from modification

2005-09-14 Thread Magnus Lycka
Frank Millman wrote:
> I have seen Twisted mentioned many times in this ng, but I have no idea
> what it actually does. Can someone tell me in simple terms what
> advantage it might give me over a multi-threaded socket server program.

More control. Less resource usage. Twisted also provides a very
flexible way of building network aware software which you will
appreciate if you ever consider using something else than sockets.

Using several process means using more memory, and inter process
communication isn't as fast as in-process communication. Using
threads is error prone and difficult to debug. There are also scaling
issues with threads in Python (but maybe not when most threads wait
for network connections).

Twisted is based on an event loop, just like GUI programs. But instead
of waiting for GUI events, such as button clicks, the Twisted app will
wait for network events, such as data received. With Twisted and
sockets, you write code that will implement handlers for such events.

A simple example is provided here:

#!/usr/bin/python
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.

from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor

### Protocol Implementation

# This is just about the simplest possible protocol
class Echo(Protocol):
 def dataReceived(self, data):
 """As soon as any data is received, write it back."""
 self.transport.write(data)


def main():
 f = Factory()
 f.protocol = Echo
 reactor.listenTCP(8000, f)
 reactor.run()

if __name__ == '__main__':
 main()

You see? You just subclass Protocol and override the relevant
event handler, and get the thing going! The factory will create
an Echo instance for each socket connection.

The problem in Twisted is that functions in this single thread that
are run inside the event loop must be fast--just as the event
handlers in your GUI app. Twisted helps you achieve this. For
instance, there is the concept of deferred execution, (described
in a paper available at http://python.fyxm.net/pycon/papers/deferex/ )
but you might want to use a separate thread for things like database
queries etc.

There are a lot of other batteries included, check out the Twisted
documentation at
http://twistedmatrix.com/projects/twisted/documentation/

You have to ask other Twisted users about scalability, but I think
it will scale well beyond your needs.

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


warning when doubly liked list is defined globally

2005-09-14 Thread chand
Hi.,

In my api.py file 'g_opt_list' is defined globally
g_opt_list =[[],[],[],[],[],[],[]]

when I run the py file, I am getting the Following Error

SyntaxWarning: name 'g_opt_list' is used prior to global declaration
SyntaxWarning: name 'layers' is used prior to global declaration

Please let me know how to remove these warnings.

I found that commenting 'g_opt_list' initialisation in "NEW" command
removes this warning message. But my requirement is that i want to
reset g_opt_list to empty list, whenever "NEW" command is called.


Here is the code which gives the error...

I have removed most of the unwanted code to reduce the size.

Let me know exact reason for this warning  and how to remove these
warnings..




import os,sys,re,string,math
g_opt_list =[[],[],[],[],[],[],[]]
SIG_STANDARD_HOME = "/home/chandras/SIGNALLING_STANDARD/ANSI_SS7/"
symbols=['(',')','{','}','[',']','.']
reverse_symbols=['<','>','~']
layers=['MTP3','SCCP','IOS','CDTAPM2','CDTAPC2','ISUP','IS-41D-SQA']

GUI_API_COMMAND_LIST = [
"NEW",
"ADD_OPTIONAL_PARAM",
]

Message_obj = Message()
def Process_GUI_Command(arg):
global Message_obj
global filename
out_file = file('/tmp/te.txt', 'w+')

if  arg[0]  ==  "NEW" :
global g_opt_list
for i in range(0,len(g_opt_list)):
g_opt_list[i] = []
return layerList

elifarg[0]  ==   "ADD_OPTIONAL_PARAM" :
global g_opt_list
global layers
global index
message_name = ""
add_delete_flag = 0

param_name = optional_parameter_name
g_opt_list[int(index)].append(optional_parameter_name)



def main():

print "### choice ",

if __name__ == '__main__':
main()

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


Dr. Dobb's Python-URL! - weekly Python news and links (Sep 13)

2005-09-14 Thread Diez B. Roggisch
QOTW:  "In my view, the doctrinaire', indeed religious, adherence to OO
purity has harmed our discipline considerably. Python was a nice breath
of fresh air when I discovered it exactly because it does not have this
slavish committment to an exclusively OO model." -- Tim Daneliuk

"[W]hen you add an item to the canvas, it's part of the canvas until you
remove it.  if performance drops, it's usually because you keep adding
new items without removing the old ones." -- Fredrik Lundh


An interesting CS puzzle that even provokes the interest of 
legendary bots:
   http://groups.google.com/group/comp.lang.python/msg/892850b258423549

If you ever wanted to know how to fake network connection troubles
without pulling the ethernet cable or dumping your access point in
the bathtub - here you go:
http://groups.google.com/group/comp.lang.python/msg/4c74934e88809a3a

There's a new compiler for python in town - you static typed languages
better watch out - we're getting closer!
http://groups.google.com/group/comp.lang.python/msg/130e711203d12acb

Django gets lots of attention lately - but is it on par with
ruby-on-rails already? Find out for yourself:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e827f741c2e25f30/

Lots of movement on the "easy-packaging and installing"-front.
py2exe and PyInstaller have new versions out:
   http://groups.google.com/group/comp.lang.python/msg/29bb876093c78e64
   http://groups.google.com/group/comp.lang.python/msg/698dcaf909ce3bac

Reluctant to share your little secrets? Here is how to utilize python
for encryption:
http://groups.google.com/group/comp.lang.python/msg/da511dc9cb4921c 
  
Ever felt the need for nice new wheels? Stefano Masini provokes a
discussion on why so many people seem to keep reinventing them with
python:
http://groups.google.com/group/comp.lang.python/msg/e652d2f771a49857

Shaving of milliseconds on loops in python is an uncommon need - but
if it arises in, for example, a game loop, here are tips on how to do so:
http://groups.google.com/group/comp.lang.python/msg/8c988e2b5991a4a1



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

"week-year" conversion to date

2005-09-14 Thread oyvgi
I was wondering if it there is an "easy" way to get the dd-mm- from
ww-.

I would like to get, for example the first day (date-month-year) in the
week i specify. Found plenty of ways to go th other way, but none that
give me the reverse.

Idealy I would like both the beginning date/time and the end date/time
of the specified week, but if i can just get a hold one of the or some
other defined time in this week i could probably work out the rest.

This is in Python :-)

dd = day in month
mm = month
 = year
ww = week #

Thanks for any and all help.

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


Re: Removing duplicates from a list

2005-09-14 Thread Rubinho
Peter Otten wrote:
> Rubinho wrote:
>
> > I've a list with duplicate members and I need to make each entry
> > unique.
> >
> > I've come up with two ways of doing it and I'd like some input on what
> > would be considered more pythonic (or at least best practice).
> >
> > Method 1 (the traditional approach)
> >
> > for x in mylist:
> > if mylist.count(x) > 1:
> > mylist.remove(x)
>
> That would be an odd tradition:

By tradition I wasn't really talking Python tradition; what I meant was
that the above pattern is similar to what would be generated by people
used to traditional programming languages.

>
> >>> mylist = [1, 2, 1, 3, 2, 3]
> >>> for x in mylist:
> ... if mylist.count(x) > 1:
> ... mylist.remove(x)
> ...
> >>> mylist
> [2, 1, 2, 3] # oops!

But you're absolutely right, it doesn't work! Oops indeed :)

I've gone with Thomas's suggestion above of: mylist=list(set(mylist))

Thanks, 

Robin

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


Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread barnesc

>barnesc at engr.orst.edu wrote:
> > So my question is: are there any other *practical* applications of a
> > B-tree based list/set/dict ?  In other words, is this module totally
> > worth coding, or is it just academic wankery and theoretical flim
> > flam ? :)
>
>B-trees are specifically designed for disk storage. Seeking to a
>page takes much longer than reading a page of several kilobytes.
>B-trees read the keys for a many-way comparison in one seek.
>
>For in-memory comparison-based dictionaries, Red-Black trees,
>AVL trees, 2-3 trees, or skip-lists, are a better choice.
>
>
>--
>--Bryan

-
Memory Usage
-

Here overhead is compared to a C array of > 1 million PyObject *s.

The B-tree is assumed to have a branch factor of ~1024.

A B-tree has an average of 1.5x overhead (2x at worst, 1x at best,
  using malloc).  This assumes that B-tree nodes contain a fixed
  size C array for storing values (which will be half-full on
  average), and that the child array is only allocated for internal
  nodes as needed.
Any balanced binary tree with left and right child pointers has
  a 6x overhead (using malloc, measured via a gcc win32 test program),
  or with a free list, a 3x overhead (though memory will not
  be returned until the data structure's destructor is called).
  I haven't tried using PyObject_Malloc(), but it should be in
  between these two factors.
A skip list has n values and n next pointers on the bottom level.
  In the ideal case (with respect to memory usage), we make the
  probability sufficiently small so that the higher levels take up a
  negligible amount of memory.  Thus we have a 4x overhead (using
  malloc, measured via a gcc win32 test program), or with a free list,
  an overhead slightly greater than 2x (again, memory will only be
  returned when the destructor is called).  I didn't test
  PyObject_Malloc(), but it should give an overhead between 2x and 4x.

Thus, on average, a > 1 million element B-tree uses 25% less memory
than any other balanced data structure which I am aware of, and 50%
more memory than a raw C array.


-
Speed
-

I have no idea how B-trees compare to skip lists (the likely
contender) in terms of speed.

To do this, one would need two high performance C implementations.

>From this, the Python performance can presumably be deduced (although
caching causes unpredictable effects, the faster C algorithm should be
faster in Python).

You could start with optimized parallel C implementations, such as
the ones by John-Mark Gurney:

 * http://resnet.uoregon.edu/~gurney_j/jmpc/btree.html
 * http://resnet.uoregon.edu/~gurney_j/jmpc/skiplist.html

He indicates that the skip list is slower than the B-tree, but doesn't
give any solid numbers.  Of course you'd have to check his code and
optimize it to death (Perhaps representing a sorted set of integers
using each respective data structure would be a good test).

Also note that my B-tree code currently has optimized special cases
for block insertions, deletions, and retrievals, since this is easy
(er, well, relatively speaking) to do in the B-tree case.  In the skip
list case, block retrievals are easy (though not as fast as B-tree
block retrievals due to pointer indirection and cache problems).  I
have no idea how to do a fast block insert or delete on a skip list.

--

Well, enough ivory tower silliness and academic blustering.



Are there any *practical* applications for in-memory balanced data
structures (e.g. skip list, AVL tree, RB tree, B tree) ?



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


test

2005-09-14 Thread s051509
This is just a try.

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


test

2005-09-14 Thread s051509

This is just a try.

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


Re: Windows Python 2.4: Unbuffered flag causes SyntaxError on interactive sessions?

2005-09-14 Thread Reinhold Birkenfeld
Irmen de Jong wrote:
> Michael Hoffman wrote:
>> Lonnie Princehouse wrote:
>> 
>>> C:\>python -u
>>> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
>>> on win32
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>
>> print 'hello'
>>>
>>>
>>>   File "", line 1
>>> print 'hello'
>>>  ^
>>> SyntaxError: invalid syntax
>> 
>> 
>> Worksforme:
>> 
>> C:\Python24>python.exe -u
>> Python 2.4.1 (#65, May 24 2005, 13:43:04) [MSC v.1310 32 bit (Intel)] on 
>> win32
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> print 'hello'
>> hello
>> 
>> Strange that your python build is from 30 March and mine is from 24 May.
> 
> 
> Problem also occurs on my machine using Win XP Home,
> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
> 
> 
> even just typing "print" at the interactive prompt causes a syntax error...

It __may__ be that this is caused by an error in the codecs machinery which is 
already
fixed in 2.4 CVS. Could you try this out?

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


Re: Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> The bset() and bdict() classes improve upon the builtin set and
> dictionary types by maintaining the elements in sorted order.
>
> Generally, the b* classes are a factor of O(log(N)) slower[2] than the
> corresponding builtin classes, except for certain operations:

'Improve upon' and 'are slower' (for essential operations) are mutually 
contradictory ;-).  Your classes differ from the builtin types by 
optimizing different operations.  No need to confuse and distract with an 
unnecessary false claim.

Terry J. Reedy



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


Re: "week-year" conversion to date

2005-09-14 Thread Rune Strand

year = '2005'
week = 50
weekday = 1 # Monday is 1

time_expr = '%s, %s, %s' % (year, week, weekday)
time_struct = time.strptime(time_expr, "%Y, %W, %w")
print time.strftime("%Y%m%d", time_struct)

But the datetime module may have an easier way

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


Re: PyGTK or wXPython?

2005-09-14 Thread Magnus Lycka
Rod W wrote:
> I'm just starting out on Python but my primary goal is to provide 
> applications with some user interface (GUI).
> 
> Can someone point me to a good comparison of whether I should use 
> wxPython (with wxGlade I assume) or PyGTK (with Glade I assume)?

What OS(es) do yo need to support?

I'm curious about PyGTK on Windows. It seems to me that the GTK+
Windows port is lagging behind a bit (no 2.8?), doesn't look or
behave quite as native windows apps do, is clunky to install, and
isn't as stable and complete as e.g. wxPython. Am I wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do Pythoneers reinvent the wheel?

2005-09-14 Thread konrad . hinsen
Stefano Masini wrote:

> There are a few ares where everybody seems to be implementing their
> own stuff over and over: logging, file handling, ordered dictionaries,
> data serialization, and maybe a few more.
> I don't know what's the ultimate problem, but I think there are 3 main 
> reasons:
> 1) poor communication inside the community (mhm... arguable)
> 2) lack of a rich standard library (I heard this more than once)
> 3) python is such an easy language that the "I'll do it myself" evil
> side lying hidden inside each one of us comes up a little too often,
> and prevents from spending more time on research of what's available.

I'd like to add one more that I haven't seen mentioned yet: ease of
maintenance and distribution.

Whenever I decide to use someone else's package for an important
project, I need to make sure it is either maintained or looks clean
enough that I can maintain it myself. For small packages, that alone is
often more effort than writing my own.

If I plan to distribute my code to the outside world, I also want to
minimize the number of dependencies to make installation simple enough.
This would only stop being a concern if a truly automatic package
installation system for Python existed for all common platforms - I
think we aren't there yet, in spite of many good ideas. And even then,
the maintenance issue would be even more critical with code distributed
to the outside world.

None of these issues is specific to Python, but with Python making new
developments that much simpler, they gain in weight relative to the
effort of development.

> It seems to me that this tendency is hurting python, and I wonder if
> there is something that could be done about it. I once followed a

I don't think it hurts Python. However, it is far from an ideal
situation, so thinking about alternatives makes sense. I think the best
solution would be self-regulation by the community. Whenever someone
discovers three date-format modules on the market, he/she could contact
the authors and suggest that they sit together and develop a common
version that satisfies everyone's needs, perhaps with adaptor code to
make the unified module compatible with everyone's individual modules.

Konrad.

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


Re: "week-year" conversion to date

2005-09-14 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>I was wondering if it there is an "easy" way to get the dd-mm- from
>ww-.

>I would like to get, for example the first day (date-month-year) in the
>week i specify. Found plenty of ways to go th other way, but none that
>give me the reverse.

>Idealy I would like both the beginning date/time and the end date/time
>of the specified week, but if i can just get a hold one of the or some
>other defined time in this week i could probably work out the rest.

>This is in Python :-)

>dd = day in month
>mm = month
> = year
>ww = week #

>Thanks for any and all help.

>>> import mx.DateTime
>>> d=mx.DateTime.DateTime(1992)+mx.DateTime.RelativeDateTime(weeks=15) 
>>> d

>>> d=mx.DateTime.DateTime(1992)+mx.DateTime.RelativeDateTime(weeks=51)
>>> d


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


Re: Removing duplicates from a list

2005-09-14 Thread Christian Stapfer
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I do this:
>
> def unique(keys):
>unique = []
>for i in keys:
>if i not in unique:unique.append(i)
>return unique
>
> I don't know what is faster at the moment.

This is quadratic, O(n^2), in the length n of the list
if all keys are unique.
Conversion to a set just might use a better sorting
algorithm than this (i.e. n*log(n)) and throwing out
duplicates (which, after sorting, are positioned
next to each other) is O(n). If conversion
to a set should turn out to be slower than O(n*log(n))
 [depending on the implementation], then you are well
advised to sort the list first (n*log(n)) and then
throw out the duplicate keys with a single walk over
the list. In this case you know at least what to
expect for large n...

Regards,
Christian


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


Writing at the beginning of a file

2005-09-14 Thread Thierry Lam
Let's say I already wrote a file and have the following:

testing
testing testing
testing testing testing

Is there an easy way to write something of variable length at the top
of the file?

For example,

6 testing written
testing
testing testing
testing testing testing

I tried to write some garbage on top right after opening the file and
then use seek to overwrite the garbage, but since the string to be
written can be of variable length, I'm not sure how much garbage I have
to write initially.

The other way to do what I want is to write the whole thing to a new
file, but I want to skip that method if there's an alternative way.

Another way of doing it is to buffer the whole file writing into some
variable, but that means I have to change 2000+ lines of codes and
change fp.write() to something else.

Any suggestions please?

Thanks
Thierry

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


Re: Magic Optimisation

2005-09-14 Thread Terry Reedy

"ABO" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> There are other "optimisations" that could be applied that make this
> code faster but uglier. For example, putting another "while True: loop
> inside the try block to avoid the try block setup each iteration.

In CPython, 'setting up' try-blocks is (intentionally) very fast, perhaps 
as fast or faster than one interation loop.

tjr



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


Re: Removing duplicates from a list

2005-09-14 Thread martijn
I do this:

def unique(keys):
unique = []
for i in keys:
if i not in unique:unique.append(i)
return unique

I don't know what is faster at the moment.

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


Re: What XML lib to use?

2005-09-14 Thread Paul Boddie
Fredrik Lundh wrote:
> since there are no *sane* reasons to use SAX or DOM in Python, that's mainly
> a job security issue...

While I doubt that anyone would really recommend exclusive DOM API
usage for significant XML processing tasks (or for anything other than
educational purposes), I think you're overstating some case or other
here. Interoperability is a pretty sane argument for using DOM-based
technologies, whether that be skills interoperability (possibly related
to job security) or just using many different technologies together.
For example, PyQt and PyKDE expose various DOMs of the purest
"non-Pythonic" kind; Mozilla exposes DOMs for XML and HTML; adding a
layer of PyXML varnish to any of these isn't a huge job. Using
different technologies with the same foundations shouldn't have to
involve breaking open yet another API for the "fun" of it.

Paul

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


Re: Magic Optimisation

2005-09-14 Thread Paul McGuire
Terry -

If setting up a try-block is as fast (or "takes as long") as one
iteration loop, then wont putting a try-block inside a loop double the
execution time?

-- Paul

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


Python Search Engine app

2005-09-14 Thread Harlin Seritt
Hi,

Is anyone aware of an available open-source/free search engine app
(something similar to HTDig) written in Python that is out there?
Googling has turned up nothing. Thought maybe I'd mine some of you
guys' minds on this.

thanks,

Harlin Seritt
Internet Villa: www.seritt.org

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


Re: python-dev Summary for 2005-08-01 through 2005-08-15

2005-09-14 Thread Steve Tregidgo
Hi,

on 2005-08-30 01:45 Tony Meyer said the following:
> [The HTML version of this Summary is available at
> http://www.python.org/dev/summary/2005-08-01_2005-08-15.html]
...
> Many revision control systems were extensively discussed, including
> `Subversion`_ (SVN), `Perforce`_, `Mercurial`_, and `Monotone`_.  Whichever
> system is moved to, it should be able to be hosted somewhere (if
> *.python.org, then it needs to be easily installable),
...

Take a look at the HTML version of this summary -- there's some oddness, 
possibly caused by the asterisk above.  After the paragraph ending 
"appropriate", we get this, linked by the asterisk:


System Message: WARNING/2 (./2005-08-01_2005-08-15.ht, line 65); backlink
Inline emphasis start-string without end-string.



Possibly a bug in reST, or something under-quoted?  Thought you might 
like to look.

Cheers,
Steve

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Grant Edwards
On 2005-09-14, Robert Kern <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:

>> 0.0225 isn't representable and it happens that the actual number
>> you get differ. Now which number python should choose when it is
>> fed 0.0225, I don't know. But expressing the different behaviour
>> as a change in round, suggest that the O.P. would be wise to
>> learn about floating point problems
>
> Uhh, Python didn't change anything between 2.3 and 2.4 wrt round().

That's what Antoon Pardon just said. The above paragraph says
that round() didn't change, and the fact that the OP thinks it
did indicates that the OP needs to learn more about FP.

-- 
Grant Edwards   grante Yow!  UH-OH!! We're out
  at   of AUTOMOBILE PARTS and
   visi.comRUBBER GOODS!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing at the beginning of a file

2005-09-14 Thread Paul McGuire
Thierry -

Check out the StringIO module.  It will allow you to buffer the whole
file into a string, and then give you a pseudo file pointer to the
string buffer, so that your "fp.write"s will work unchanged.

-- Paul

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


Re: Writing at the beginning of a file

2005-09-14 Thread Grant Edwards
On 2005-09-14, Thierry Lam <[EMAIL PROTECTED]> wrote:
> Let's say I already wrote a file and have the following:
>
> testing
> testing testing
> testing testing testing
>
> Is there an easy way to write something of variable length at the top
> of the file?

No.

[...]

> The other way to do what I want is to write the whole thing to a new
> file, but I want to skip that method if there's an alternative way.

There isn't.

> Another way of doing it is to buffer the whole file writing into some
> variable, but that means I have to change 2000+ lines of codes and
> change fp.write() to something else.
>
> Any suggestions please?

Looks like you've figured it out already.

-- 
Grant Edwards   grante Yow!  Are you selling NYLON
  at   OIL WELLS?? If so, we can
   visi.comuse TWO DOZEN!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing duplicates from a list

2005-09-14 Thread Rocco Moretti
Rubinho wrote:

> I can't imagine one being much faster than the other except in the case
> of a huge list and mine's going to typically have less than 1000
> elements.  

To add to what others said, I'd imagine that the technique that's going 
to be fastest is going to depend not only on the length of the list, but 
also the estimated redundancy. (i.e. a technique that gives good 
performance with a list that has only one or two elements duplicated 
might be painfully slow when there is 10-100 copies of each element.)

There really is no substitute for profiling with representitive data sets.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-dev Summary for 2005-08-01 through 2005-08-15

2005-09-14 Thread Steve Tregidgo
I wrote:
> Take a look at the HTML version of this summary...

Argh!  Sorry everyone, I meant to send that to just the python-dev 
summary chaps, not to the whole list.

An email mistake I should have grown out of years ago. :-(

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


Re: Removing duplicates from a list

2005-09-14 Thread Steven D'Aprano
On Wed, 14 Sep 2005 13:28:58 +0100, Will McGugan wrote:

> Rubinho wrote:
>> I can't imagine one being much faster than the other except in the case
>> of a huge list and mine's going to typically have less than 1000
>> elements.  
> 
> I would imagine that 2 would be significantly faster. 

Don't imagine, measure.

Resist the temptation to guess. Write some test functions and time the two
different methods. But first test that the functions do what you expect:
there is no point having a blindingly fast bug.


> Method 1 uses 
> 'count' which must make a pass through every element of the list, which 
> would be slower than the efficient hashing that set does. 

But count passes through the list in C and is also very fast. Is that
faster or slower than the hashing code used by sets? I don't know, and
I'll bet you don't either.


-- 
Steven.

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


Re: How to protect Python source from modification

2005-09-14 Thread Frank Millman

Magnus Lycka wrote:
> Frank Millman wrote:
> > I have seen Twisted mentioned many times in this ng, but I have no idea
> > what it actually does. Can someone tell me in simple terms what
> > advantage it might give me over a multi-threaded socket server program.
>
> More control. Less resource usage. Twisted also provides a very
> flexible way of building network aware software which you will
> appreciate if you ever consider using something else than sockets.
>

[snip Twisted tutorial]

Thanks a ton, Magnus, that really was a brilliant description.

Clearly I must find the time to look into Twisted properly.

Many thanks again

Frank

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Terry Reedy

"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Which works wonderfully as an academic exercise, but doesn't tend to work
> so terribly well in the real world where the performance and
> resource-requirement differences between iteration and recursion can be
> significant.

I think your comparison is incomplete.

Recursion and iteration are two syntaxes for the same operation: repetition 
with variation.  Indeed, iteration can be viewed as within-frame tail 
recursion.  Recursion usually takes more space for a stack of call 
frames -- unless the particular system optimizes the stack away for 
particular functions (by recursing within a frame!).  For a given 
algorithm -- defined by what actually gets computed -- the time difference 
is a small constant.  For Python, recursion is probably slower relative to 
iteration than for other languages because of the flexibility and slowness 
of function calls.

> For instance, try these two simple functions for the nth number
> in the Fibonacci sequence:

Abstractly, these are two algorithms for the same function.  One runs in 
exponential time because it wastefully calculates and tosses away an 
exponential number of subvalues.  The other runs in linear time because it 
calculates each subvalue once.  When one only wants Fib(n), and not the 
sequence leading up to it, even this is wasteful, for large enough n, since 
there is a third algorithm that caluculates Fib(n) directly by a simple 
formula (something like the interger part of the golden ratio to the nth 
power).

Now: I could (and probably someday will) write an iterative version of the 
exponential algorithm (using an explicit stack) that calculates each 
subvalue exactly as many times as the recursive version of that same 
algorithm.  And I could compare it to a recursive version of the more 
efficient linear algorithm (such as posted by Jerzy Karczmarczuk).  And I 
could claim that this shows hows iteration can waste time compared to 
recursion.

But that, I admit, would be an invalid conclusion.  And that, I claim, is 
also invalid when 'iteration' and 'recursion' are reversed, no matter how 
often repeated in texts and articles.  The difference is between the 
algorithms, not the differing syntactic expressions thereof.

Terry J. Reedy



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


Re: appended crontab entries with py script

2005-09-14 Thread rbt
On Tue, 2005-09-13 at 23:18 -0400, Mike Meyer wrote:
> rbt <[EMAIL PROTECTED]> writes:
> 
> > How can I safely append a crontab entry to a crontab file
> > progammatically with Python?
> 
> Well, one way would be to invoke the system crontab utility and use an
> "editor" that passes the file to your program, and reads the results
> back.
> 
> > I need to handle crontabs that currently have entries and crontabs that
> > are empty. Also, I'd like this to work across Linux and BSD systems.
> >
> > Any pointers?
> 
> I think most Free Unix systems use the Vixie cron, and the non-free
> ones have a "crontab" command (do some of them call it cron?) with the
> same API. So you're pretty safe using that.
> 
> If you want to assume that you're going to have the vixie cron, you
> could dig into it's guts to see what it does for locking, and do that
> by hand.
> 
> current_crontab.txt')
cur_cron.read()
cur_cron.close()
fp = file('current_crontab.txt', 'a')
print >> fp, "0 * * * * %s/.theft_recovery.py" %home
fp.close()
load = os.popen('crontab current_crontab.txt')
load.read()
load.close()

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


Re: Removing duplicates from a list

2005-09-14 Thread Will McGugan
Steven D'Aprano wrote:
> 
> 
> Don't imagine, measure.
> 
> Resist the temptation to guess. Write some test functions and time the two
> different methods. But first test that the functions do what you expect:
> there is no point having a blindingly fast bug.

Thats is absolutely correct. Although I think you do sometimes have to 
guess. Otherwise you would write multiple versions of every line of code.

> 
> 
> But count passes through the list in C and is also very fast. Is that
> faster or slower than the hashing code used by sets? I don't know, and
> I'll bet you don't either.


Sure. But if I'm not currently optimizing I would go for the method with 
the best behaviour, which usualy means hashing rather than searching. 
Since even if it is actualy slower - its not likely to be _very_ slow.


Will McGugan
-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list



Oblique Strategies

2005-09-14 Thread robin
The Oblique Strategies were originally a set of one-hundred cards,
each bearing a short phrase. They were devised by Brian Eno and Peter
Schmidt as ways of working through creative problems. When a blockage
occurs, draw a card, and see if it can direct you in a tangential way
that helps solve the problem.

I have created a Python implementation that includes two different
decks. Since one of these is my own, I can be sure this is an original
contribution for all of you Python coders stuck on a problem!

Surf:
http://noisetheatre.blogspot.com/2005/09/oblique-strategies.html

-
robin
noisetheatre.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: retrieve data using FTP in Python

2005-09-14 Thread Jaime Wyant
Try this from the interpreter:

import ftplib
help(ftplib)

The module is pretty easy to use.  If you'll be doing anything with
`http', then visit urllib2:

import urllib2
help(urllib2)

I think urllib2 will take `ftp' urls:
ftp://user:[EMAIL PROTECTED]/dir/file_to_get

hth,
jw
On 9/13/05, swarna pulavarty <[EMAIL PROTECTED]> wrote:
>  
> Hi all, 
>   
> I am new to this Python group and to Python . I need to retrieve data from
> an arbitrary URL and save it to a file. 
> Can anyone tell me how to retrieve "any" data using FTP modules in Python ?
> And also, Can you suggest me some books and online references to get
> familiar with Python and especially FTP modules in Python ?  
>   
> Your help is appreciated ! 
>   
> Swarna.
> 
>  
>  Yahoo! India Matrimony: Find your partner now. 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread Szabolcs Nagy
IMO sorted dict implementation can be useful, eg. one can get an
interval:
L = D['A' : 'K']

other useful data types:
linkedlist
queue, stack (well deque can do it efficiently in py 2.4)
prioritydict (for graph algorithms)
multimap, multiset (i've never used it but it's in the c++ stl)
mutable string (kind of list/array of chars, but with string functions)

nsz

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


Re: Tkinter add_cascade option_add

2005-09-14 Thread Bob Greschke
You can set the font for the labels on the menu bar, and you can set the 
font of the items in the drop down portion independently (except on Windows 
where you cannot control the font of the menu bar labels).  I just don't 
know how to set the font for the menu bar labels using an option_add 
command.

...option_add("*Menu*font", "Helvetica 12 bold")  works fine
...option_add("*Cascade*font", "Helvetica 12 bold")  does not,

because I can't figure out what to put in for "Cascade".  There must be 
something, because I can use font = "Helvetica 12 bold" in the add_cascade 
command OK (see below).

The program runs on Windows, Linux, Solaris, Mac.

Bob

"Eric Brunel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Tue, 13 Sep 2005 22:31:31 -0600, Bob Greschke <[EMAIL PROTECTED]> wrote:
>
>> Root.option_add("*?*font", "Helvetica 12 bold")
>>
>> Want to get rid of the "font =":
>> Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold")
>>
>> Does anyone know what ? should be to control the font of the cascade
>> menus (the labels on the menu bar)?  "*Menu*font" handles the part that
>> drops down, but I can't come up with the menu bar labels part.
>
> option_add('*Menu.font', 'helvetica 12 bold') works for me for all sorts 
> of menu items (cascade, commands, checkbuttons, whatever...).
>
> What is your platform? There may be a few limitations for menu fonts on 
> Windows.
>
> HTH
> -- 
> python -c "print ''.join([chr(154 - ord(c)) for c in 
> 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" 


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


Python on AIX 4.3.

2005-09-14 Thread David Gutierrez
Hello Everyone,
I'm trying to install Python on an aix 4.3.3. but keep on getting a failed 
attempt with the following errors.

ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_signal
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_wait
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_self
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_setscope
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_detach
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more 
information.
collect2: ld returned 8 exit status
make: 1254-004 The error code from the last command is 1.

Has anyone seen this before.

Thanks in Advance!

David


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


O'Reilly book on Twisted

2005-09-14 Thread Alessandro Bottoni
Most likely, you are already aware of this but, just in case...

O'Reilly is going to publish a nook on Twisted:

http://www.oreilly.com/catalog/twistedadn/

http://www.amazon.com/exec/obidos/tg/detail/-/0596100329/qid=1126714644/sr=1-1/ref=sr_1_1/102-3430080-1376942?v=glance&s=books

CU
---
Alessandro Bottoni
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List of integers & L.I.S. (SPOILER)

2005-09-14 Thread n00m

Tim Peters wrote:
> The chance that Raymond Hettinger is going to recode _your_
> functions in C is approximately 0 ;-)
Who is Raymond Hettinger?

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


Re: Python on AIX 4.3.

2005-09-14 Thread Fredrik Lundh
David Gutierrez wrote:

> I'm trying to install Python on an aix 4.3.3. but keep on getting a failed
> attempt with the following errors.
>
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
...
> Has anyone seen this before.

$ more README
...
AIX:A complete overhaul of the shared library support is now in
place.  See Misc/AIX-NOTES for some notes on how it's done.
(The optimizer bug reported at this place in previous releases
has been worked around by a minimal code change.) If you get
errors about pthread_* functions, during compile or during
testing, try setting CC to a thread-safe (reentrant) compiler,
like "cc_r".  For full C++ module support, set CC="xlC_r" (or
CC="xlC" without thread support).
...

so I guess the answer is yes.

 



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


Re: Python on AIX 4.3.

2005-09-14 Thread Alessandro Bottoni
David Gutierrez wrote:

> Hello Everyone,
> I'm trying to install Python on an aix 4.3.3. but keep on getting a failed
> attempt with the following errors.
> 
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
> ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_signal
> ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_wait
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_destroy
> ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_destroy
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
> ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_init
> ld: 0711-317 ERROR: Undefined symbol: .pthread_self
> ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
> ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_setscope
> ld: 0711-317 ERROR: Undefined symbol: .pthread_create
> ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_destroy
> ld: 0711-317 ERROR: Undefined symbol: .pthread_detach
> ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
> information.
> collect2: ld returned 8 exit status
> make: 1254-004 The error code from the last command is 1.
 
Are you trying to install a posix-thread- (pthread) -enabled Python
interpreter on a not-pthread machine? It looks like the pthread module is
missing.

HTH 
---
Alessandro Bottoni
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for ARM7?

2005-09-14 Thread Sybren Stuvel
Ken Seehart enlightened us with:
> I could try to unpack them on another (non-ARM7) linux box and then
> move the files over to the ARM7 device.

Yep, that should work.

> Better yet, can I unpack them on windows XP somehow?

Don't know.

> If for some reason that is not possible, i suppose my next step is
> to find a compatible ARM7 linux installation to unpack on another
> machine to steal files from.

Why? You can extract the files just fine on any ARM machine. It's the
code in the binaries that you can't execute on anything but ARM. Just
extracting some files can be done on any system.

> It there an easy to obtain the files I need without attempting to
> reintall linux?

Sure, just use a live CD.

>(any other commands that ipkg runs)

As I said: you can extract the files even without ipkg. Just untar
them and take a good look at the contents. You'll figure it out.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Django Vs Rails

2005-09-14 Thread Ian Bicking
Diez B. Roggisch wrote:
>   - rails/subway reflect over a existing table. They create OR-mappings
> based on that. You only specify exceptional attributes for these mappings.
>
>   - django specifies the whole meta-model in python - and _generates_
> the SQL/DDL to populate the DB. So obviously you have to be more verbose
> - otherwiese you won't have the fields you need.

Subway is built on SQLObject, and SQLObject can both create tables and
read schemas from an existing database.  I don't know what style is
preferred at the moment in Subway, but personally I always create my
tables with SQLObject because I always end up enumerating all the
features of the tables eventually anyway.

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


Re: network parameters

2005-09-14 Thread Sybren Stuvel
le dahut enlightened us with:
> Is there a way to get network parameters (number of network
> interfaces, ip address(es), DNS, gateway) on a linux station using
> python 2.3 ?

Sure.

- number of network interfaces, ip address(es), gateway: read from /proc
- DNS: read /etc/resolv.conf

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What XML lib to use?

2005-09-14 Thread Fredrik Lundh
Paul Boddie wrote:

> For example, PyQt and PyKDE expose various DOMs of the purest
> "non-Pythonic" kind; Mozilla exposes DOMs for XML and HTML

I didn't see anything about manipulating an application's internal
data structures in the original post, but I might have missed some-
thing.

For stand-alone XML manipulation in Python, my point still stands:
programs using DOM and SAX are more bloated and slower than
the alternatives.

 



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


Re: Software bugs aren't inevitable

2005-09-14 Thread Rocco Moretti
Terry Reedy wrote:

> But that, I admit, would be an invalid conclusion.  And that, I claim, is 
> also invalid when 'iteration' and 'recursion' are reversed, no matter how 
> often repeated in texts and articles.  The difference is between the 
> algorithms, not the differing syntactic expressions thereof.

There is a comparison in there about iteration vs. recursion, but it's 
probably not the one intended.

The algorithm one uses sometimes depends quite heavily on which mindset 
you're using. Some algorithms require much more mental effort to 
understand when in their recursive form versus the iterative form, and 
vice versa. If you're stuck thinking in only one form, you might miss 
the better algorithm because it is not as "simple" in that form.

The ideal case would be a programming language that allows you to write 
the algorithm in whatever form is simplest/most comfortable, and then 
automagically transforms it to the form that works the fastest under the 
hood.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Search Engine app

2005-09-14 Thread Alan Meyer

"Harlin Seritt" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>
> Is anyone aware of an available open-source/free search engine app
> (something similar to HTDig) written in Python that is out there?
> Googling has turned up nothing. Thought maybe I'd mine some of you
> guys' minds on this.
>
> thanks,
>
> Harlin Seritt
> Internet Villa: www.seritt.org

I'm not aware of such a thing.

I stand ready to be corrected, but I think Python would not be a
good language for writing search engines.  In the ones I've written
for custom projects - in C or PL/1, it has been necessary to
perform very high speed operations on highly compressed binary
structures - which is not Python's forte.

You might be able to put a Python interface over an engine written
in another language.

Alan 


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


Re: improvements for the logging package

2005-09-14 Thread skip
>> It does, in the "in-development" version of the documentation. Sorry it
>> was not in the 2.4 releases :-(

Thomas> Maybe it can be backported to 2.4.2 - is there still time for that?

Changed now in CVS.  When 2.4.2 is released it should be there.

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


Re: Python Search Engine app

2005-09-14 Thread gene tani
Yes, there's a bunch.  Google for "query parser" + python, "porter
stemming" "stopwords" "text indexer".  Maybe lucene has some python
bindings, hmm?

Harlin Seritt wrote:
> Hi,
>
> Is anyone aware of an available open-source/free search engine app
> (something similar to HTDig) written in Python that is out there?
> Googling has turned up nothing. Thought maybe I'd mine some of you
> guys' minds on this.
> 
> thanks,
> 
> Harlin Seritt
> Internet Villa: www.seritt.org

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


Re: Python Search Engine app

2005-09-14 Thread Fredrik Lundh
Harlin Seritt wrote:

> Is anyone aware of an available open-source/free search engine app
> (something similar to HTDig) written in Python that is out there?
> Googling has turned up nothing. Thought maybe I'd mine some of you
> guys' minds on this.

http://divmod.org/ has a couple of alternatives:

http://divmod.org/projects/lupy
http://divmod.org/projects/pyndex
http://divmod.org/projects/xapwrap





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


h2py.py and char literals

2005-09-14 Thread lsmithso
Python 2.3.4 on RedHat Linux FC3.

Tools/scripts/h2py.py doesn't translate C char literals. When I feed it
a .h file with the single line:

  #define GOO 'L'

It throws out:

   Skipping: GOO = ord()

And doesn't generate any code. I'm sure this used to work. I fixed it
by hacking h2py.py:

diff -Naur /usr/lib/python2.3/Tools/scripts/h2py.py h2py.py
--- /usr/lib/python2.3/Tools/scripts/h2py.py2005-02-02
17:22:30.0 +
+++ h2py.py 2005-09-14 17:58:31.0 +0100
@@ -95,7 +95,7 @@
 for p in ignores:
 body = p.sub(' ', body)
 # replace char literals by ord(...)
-body = p_char.sub('ord(\\0)', body)
+body = p_char.sub("ord('\\1')", body)
 # Compute negative hexadecimal constants
 start = 0
 UMAX = 2*(sys.maxint+1)


Is this a bug or am I being silly.

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Magnus Lycka
Nils Grimsmo wrote:
> (Is this due to the different GCC used?)

Yes, but there are probably other nasty values with the
other CGG. Basically, what the code does, for a positive
number, is to calculate floor(0.0225*1000.0+0.5)/1000.0.

As others have said: Don't trust this. If you use Python 2.4,
you can take advantage of the new decimal module, where no
floating point calculations are involved.

I tried with Python 2.2.3 on RH EL3, and for half a million
tested values that ended with 5 in the 4th decimal and used
ndigits=3, I got almost 3000 where it rounded towards zero,
and not towards infinity as the docs say. I.e. almost 0.6%
wrong.

Here is a more direct description of the problem in my system:
 >>> math.floor(4.0925*1.0*10.0*10.0*10.0+0.5)
4093.0
 >>> math.floor(4.0935*1.0*10.0*10.0*10.0+0.5)
4093.0
 >>> math.floor(4.0945*1.0*10.0*10.0*10.0+0.5)
4095.0

Your 2.4 system is still strange though. I tried the
program below on a range of systems: RH Linux, HP-UX,
AIX, Solaris, on Sparc, PowerPC, PA-RISC, Intel Pentium
and AMD 64, and they always gave the same results with
Python 2.2.3 or Python 2.3.1.

Program:

for N in (1000,2000,3000,5000,1,10,100):
 buggy=0
 for i in range(1,N,2):
 f=i/2000.0
 r=round(f,3)
 if r>> round(0.0225,3)
0.023

There have been problems with GCC's float() before though...
http://lists.debian.org/debian-gcc/2002/04/msg00056.html

> How do you correctly output floating-point numbers in 2.4?

There is no change here.
0.023 => 0.023 and 0.022 => 0.021999
in different Python versions. Use str() or %s etc.

BTW, the C source code looks like this:

static PyObject *
builtin_round(PyObject *self, PyObject *args)
{
double x;
double f;
int ndigits = 0;
int i;

if (!PyArg_ParseTuple(args, "d|i:round", &x, &ndigits))
return NULL;
f = 1.0;
i = abs(ndigits);
while  (--i >= 0)
f = f*10.0;
if (ndigits < 0)
x /= f;
else
x *= f;
if (x >= 0.0)
x = floor(x + 0.5);
else
x = ceil(x - 0.5);
if (ndigits < 0)
x *= f;
else
x /= f;
return PyFloat_FromDouble(x);
}

Perhaps one could argue that the code should be changed to
if (x >= 0.0)
x = floor(x + d + 0.5);
else
x = ceil(x - d - 0.5);
where d is a fairly small number, but this doesn't help in
the long run... For large enough floating point numbers,
the resolution of the floating point system gets bigger than
1! It might well be possible to make a round() function that
works just right in e.g. business accounting applications, where
money ranges between perhaps 0.01 and 1,000,000,000,000.00, but
it's much more difficult to make such a thing work for the
standard library, where we might want to use the whole range
available to floats.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >