Re: PEP 354: Enumerations in Python

2006-02-28 Thread Toby Dickenson
On Monday 27 February 2006 02:49, Ben Finney wrote:

 Coercing a value from an enumeration to a ``str`` results in the
 string that was specified for that value when constructing the
 enumeration::

That sentence seems to assume that all enumeration values will have been 
specified as strings. Thats reasonable, but your description of the creation 
of an enumeration doesnt specify that.

 An enumerated type is created from a sequence of arguments to the
 type's constructor::
 
  Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
  Grades = enum('A', 'B', 'C', 'D', 'F')

s/arguments/strings/

?

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


Re: Using graphviz to visualize trace.py output, anybody?

2005-11-01 Thread Toby Dickenson
 Maybe there is some other tool that I am not aware of which can create
 this kind of trace. I use eclipse with pydev plugin on MacOS 10.3.9

kcachegrind

http://kcachegrind.sourceforge.net/cgi-bin/show.cgi

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


Re: Sorting with only a partial order definition

2005-10-27 Thread Toby Dickenson
On Thursday 27 October 2005 11:08, Lasse Vågsæther Karlsen wrote:

 What I was wondering about is if there is an algorithm that would do 
 what I want? Ie. help me pick the nodes so as to minimize the number of 
 edges. 

To rephrase your question, you want a sorting algorithm that minimises the 
number of comparisons (because a comparison involves asking a human), and 
which takes advantage of any pre-existing rough ordering.

You need timsort - the algorithm behind python lists sort() method.

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


Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Toby Dickenson
On Thursday 20 October 2005 11:53, Steve Holden wrote:

 Personally I'm still not convinced that your requirement reflects a 
 substantial use case (but then I'm getting used to that ;-). Just 
 because an ordering is partial that doesn't mean that two instances of a 
 class shouldn't be compared.

C++ has a cmp template function which can be implemented to define a total 
ordering for one type. This can be reliably used by implementations of 
ordered tree containers (for example) so that this container template class 
can only be instantiated for holding types that provide this comparison 
template function.

One disadvantage is that these template container classes can only hold one 
type.

ZODB's BTrees work in a similar way but use the regular python comparison 
function, and the lack of a guarantee of a total ordering can be a liability.
Described here in 2002, but I think same is true today:
http://mail.zope.org/pipermail/zodb-dev/2002-February/002304.html

A BTree might contain two objects that are incomparable. That is, they raise 
an exception when compared. However the user will not know this if by 
coincidence the BTree implementation has never needed to compare these two 
objects.

Now removing a third object from the container such that these two 
incomparable objects are adjacent in the BTree. There is a possibility that 
an exception might be raised when *reading* content from the BTree, since the 
BTree implementation now might need to compare this pair of objects.

 What would you have Python do when the programmer tries to perform an 
 invalid comparison (i.e. what are the exact semantics imposed when 
 __cmp__() returns None/raises an exception)?

Its too late to handle this by the time a specific comparison method of an 
individual object is being called. If you need a total ordering across a 
domain of objects then you need to involve some representation of that domain 
as a whole. 


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


Re: [path-PEP] Path inherits from basestring again

2005-07-27 Thread Toby Dickenson
On Wednesday 27 July 2005 05:37, Meyer, Tony wrote:

 I can see that this would make sense in some situations, but ISTM that it
 would make a great deal more sense (and be much more intuitive) to have
 concatenation include the separator character (i.e. be join).  

def functions_which_modifies_some_file_in_place(path):
 output = open(path+'.tmp', 'w')
 .

I dont want a seperator inserted between path and the new extension.


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



Re: System Independent Wallpaper Changer

2005-07-06 Thread Toby Dickenson
On Wednesday 06 July 2005 01:12, Terrance N. Phillip wrote:

 I've done some searching, and can't seem to find a programatic way of 
 getting *** that to happen.

http://www.google.com/search?q=setwallpaper+dcop

I hope this helps

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


Re: asynchronous comunication, wxPython and threads.

2005-06-21 Thread Toby Dickenson
On Tuesday 21 June 2005 14:22, Zunbeltz Izaola wrote:

 This comunication is done in a new thread not to frezee the GUI.
 The problem is that when Stop is done (it kills the thread) some
 confirmation sockets are mixed (are not receibed in the correct order
 although i use tcp).

I guess you are accessing the socket from both your GUI thread and 
communications thread. Dont do that. An action in the GUI thread should 
signal the communictions thread, then the communictions thread talks to the 
socket.

 I have been told not to do comunication in a new thread; instead, I should
 use asyncronus comunication.

Using non-blocking sockets in the GUI thread may cause the opposite problem to 
the one that led you to use threads in the first place: a blocking operation 
in the GUI may freeze the communications. Maybe that isnt a problem for you. 
If it is, I suggest sticking to two threads.

 What module should i use, asyncore, asynchat, twisted,(anohter) 

If you are talking to only one device, then using blocking sockets is a good 
approach. However Ive never written an application like this that didnt need 
to support a second (or third) machine sooner or later, and three 
communictions threads is starting to get ugly. A framework like Twisted will 
let you handle many machines in the one thread, but it still makes sense to 
keep a second one for the GUI.


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


Re: collect data using threads

2005-06-14 Thread Toby Dickenson
On Tuesday 14 June 2005 17:47, Peter Hansen wrote:
 Kent Johnson wrote:
  Peter Hansen wrote:
  That will not work, and you will get data loss, as Jeremy points out.
 
  Can you explain why not? self.data is still bound to the same list as x. 
  At least if the execution sequence is x = self.data
 self.data.append(a_piece_of_data)
  self.data = []
 
 Ah, since the entire list is being returned, you appear to be correct. 
 Interesting... this means the OP's code is actually appending things to 
 a list, over and over (presumably), then returning a reference to that 
 list and rebinding the internal variable to a new list.  If another 
 thread calls on_received() and causes new data to be appended to the 
 list between those two statements, then it will show up in the returned 
 list (rather magically, at least to my way of looking at it) and will 
 not in fact be lost.

But it might not show up until too late.

The consumer thread that called get_data presumably does something with that 
list, such as iterating over its contents. It might only show up after that 
iteration has finished, when the consumer has discarded its reference to the 
shared list.

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


Re: Python Impact Analysis Tool ?

2005-05-26 Thread Toby Dickenson
On Thursday 26 May 2005 13:46, [EMAIL PROTECTED] wrote:
 Hi
 
 I am a mainframe designer/progrmmer. What I need is a tool that shows
 me at design time what links to what so that I can understand the
 application. When a design change comes through I could say OK this
 change affects only A, B, and C out of the whole alphanet. Then I would
 be able to isolate what needs to be changed and unit tested..I am
 trying to improve programmer productivity at design time.

For physical dependencies between modules:

http://www.tarind.com/depgraph.html

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


Re: Windows distribution suggestions?

2005-05-17 Thread Toby Dickenson
On Tuesday 17 May 2005 09:35, Timothy Smith wrote:
 mate dont bugger around with all that. py2exe will make you a windows 
 native exe to run. and for updates you just need to update it's 
 library.zip.

py2exe is working great for me too. 

 My app contains three different programs (say alice.py, bob.py, and
 carol.py) that need to be independently launchable, and a dozen or
 so other .py files that get imported into those first three

One tip: make sure your three top-level scripts are as empty as possible: just 
import some other module and call a function. All your active code is then in 
some library.zip shared between the three, and you need never change 
alice.exe, bob.exe, and carol.exe

 use NSIS for the installer, it can do anything you want an  
 it's free. it couldn't be more simple, shoot me an email if you
 need more 

Ive not used NSIS, but I have had good results from the free WiX tools, at 
http://sourceforge.net/projects/wix/. Documentation is poor, but examples are 
plenty.

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


Re: Distributing applications

2005-03-02 Thread Toby Dickenson
On Wednesday 02 March 2005 14:12, Phillip Mills wrote:
 now any comments or references on the mechanics of creating 
 a self-contained distribution?

Run to http://starship.python.net/crew/theller/py2exe/


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


Re: Flow chart (function tree) cross references

2005-02-22 Thread Toby Dickenson
On Tuesday 22 February 2005 13:27, qwweeeit wrote:

 Does someone knows something about function tree generation and cross
 references?

for trees of *module* dependencies:
http://www.tarind.com/depgraph.html

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


Re: python connect to server using SSH protocol

2005-02-09 Thread Toby Dickenson
On Tuesday 08 February 2005 13:26, Simon Anders wrote:

 This is what I was about to reply as well. But I did a short test 
 program and encountered a problem:
 
 import os
 fi, foe = os.popen4 ('ssh dopey')
 print fi, 'ls'
 fi.close ()  # -- this is annoying
 for line in foe:
 print line,
 foe.close ()
 
 The above connects to a server, passes the command 'ls', which is 
 executed there, and prints the returned result.
 
 However, reading from foe succeeds only if fin has been closed before. 
 An fi.flush() seems to be not sufficient. 

But this version below does work. Im not sure whats happening when using the 
file as an iterator to make a difference.

import os, sys
fi, foe = os.popen4 ('ssh x')
print fi, 'ls'
fi.flush ()  # -- this is annoying
while 1:
b = foe.readline()
sys.stdout.write(b)


 But if one wants Python to  
 interactivly communicate with some shell on a remote machine, it is 
 inconvenient to have to close and reopen the connection all the time.

But this route carries a big deadlock risk. the rsync program can tunnel over 
ssh this way, but have first hand experience of
http://www.google.com/search?q=rsync+ssh+deadlock

In the script above, if 'ls' is replaced with a longer input then there is 
every chance that the fi stream will block before all of it is written, 
because this script hasnt started draining foe.

For a real python program using ssh (but not 'interactive'... data written to 
fi does not depend on data read from foe) see
http://dirstorage.sourceforge.net/replica.html
-- 
Toby Dickenson
-- 
http://mail.python.org/mailman/listinfo/python-list