OSDC::Israel Conference 26-28 Feb. 2006

2005-11-21 Thread Amit Aronovitch
==
Open Source Developers' Conference,
26-28 February, 2006, Netanya, Israel
==
Announcement and Call for Papers

http://www.osdc.org.il/call_for_paper.html

About
--
The Open Source Developers' Conferences (OSDCs) are grassroots symposia
originating from Australia. The conference tries to bring together the
users of various OS technologies such as Perl, Python, Ruby, Tcl, PHP,
MySQL, PostgreSQL, Subversion and more.
The Israeli OSDC is organized by the Israeli Perl Mongers and the
Israeli Python user group.
 Our aim is to bring together practitioners, scholars, students,
programmers, researchers and managers from different areas to discuss
their views on various aspects of the Open Source technologies, to share
knowledge and to have fun while doing so.

Structure
--
The conference will last for 3 days with 3 parallel tracks of
presentations. Presentations will be given in either Hebrew or English,
depending on the speaker's preference (the language will be listed in
advance).

Call for Papers

Recommended Topics for Python Related Presentations:

* Python based web  content-management technology (e.g. Zope)
* Major or Interesting packages (e.g. Twisted)
* Language development and new implementations (e.g. PyPy)
* Interfacing other languages (e.g. boost-python)

 The examples given above are suitable for long presentations or
tutorials, but we also accept 40 and 20 minutes presentations, and 5
minute lightning talks.
 Any other topics which are interesting and relevant to Open Source
Developers are also welcome.

 For submitting proposals:  http://www.osdc.org.il/proposal.html

For updates and more details:

  http://www.osdc.org.il/index.html
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: How to draw a dash line in the Tkinter?

2005-11-21 Thread Fredrik Lundh
Shi Mu wrote:

   How to draw a dash line in the Tkinter?
 
  use the dash option.  e.g.
 
 canvas.create_line(xy, fill=red, dash=(2, 4))
 canvas.create_line(xy, fill=red, dash=(6, 5, 2, 4))
 
  (the tuple contains a number of line lengths; lengths at odd positions
  are drawn, lengths at even positions are gaps.  note that not all com-
  binations are supported on all platforms; if Tkinter cannot find an exact
  match, it will pick a the closest possible).

 where can I find the option settings for dash line?

in the post you replied to?

or here (same, but without examples):

http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_line-method

or here (using tcl syntax):

http://www.tcl.tk/man/tcl8.4/TkLib/GetDash.htm

/F



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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread [EMAIL PROTECTED]

Fredrik Lundh wrote:
 [EMAIL PROTECTED] wrote:

  Fredrik Lundh wrote:
   but you can easily generate an index when you need it:
  
   index = dict(d)
  
   name, type = index[pid]
   print name
  
   the index should take less than a microsecond to create, and since it
   points to the members of the original dict, it doesn't use much memory
   either...
  
  Using the same logic, we don't need types other than string in a  DBMS
  as we can always convert a string field into some other types when it
  is needed.

 No, that's not the same logic.  The dict() in my example doesn't convert be-
 tween data types; it provides a new way to view an existing data structure.
 There's no parsing involved, nor any type guessing.  And given the use case,
 it's more than fast enough, and doesn't copy any data.

 If you think that's the same thing as parsing strings, you've completely 
 missed
 the point.

Well, forget about the missing/not missing the point.

My point is, there are various of reasons why we need different data
types in an RDBMS, just the same as why we need list, dict. There is
nothing stop me from using a list as dict(just scan it till I find it),
why would I I create a dict(your new view of the same data) ? Coding
convenience, speed or whatever.

If I need the dict feature 90% of the time, and the list feature 10% of
the time. I want an ordered dict. Rather than a list and create this
new view every time and every where I want to use it as a dict.

parsing or not parsing is not the point, and parsing/converting is
still create a new view of an existing data structure.

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


Any college offering Python short term course?

2005-11-21 Thread arches73
Hi,

I want to learn Python.  I appreciate if someone point me to the 
colleges / institutions offering any type of course in Python 
programming in the Bay area CA. Please send me the links to my email.

Thanks,
Arches



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


python-dev Summary for 2005-10-01 through 2005-10-15

2005-11-21 Thread Tony Meyer
Title: python-dev Summary for 2005-10-01 through 2005-10-15Content-type: text/x-rstEncoding: utf-8python-dev Summary for 2005-10-01 through 2005-10-15
.. contents::[The HTML version of this Summary is available athttp://www.python.org/dev/summary/2005-10-01_2005-10-15.html]
=Announcements=QOTF: Quote of the FortnightFrom Phillip J. Eby: So, if threads are easy in Python compared to other
 langauges, it's *because of* the GIL, not in spite of it.Contributing thread:- `Pythonic concurrency http://mail.python.org/pipermail/python-dev/2005-October/057062.html
`__[SJB]GCC/G++ Issues on Linux: Patch availableChristoph Ludwig provided the previously `promised patch`_ to address some of the issues in compiling Python with GCC/G++ on Linux. The patch_ keeps ELF systems like x86 / Linux from having any dependencies on the C++ runtime, and allows systems that require main() to be a C++ function to be configured appropriately.
.. _promised patch: http://www.python.org/dev/summary/2005-07-01_2005-07-15.html#gcc-g-issues-on-linux.. _patch: 
http://python.org/sf/1324762Contributing thread:- `[C++-sig] GCC version compatibility 
http://mail.python.org/pipermail/python-dev/2005-October/057230.html`__[SJB]=Summaries=-Concurrency in Python-
Michael Sparks spent a bit of time descibing the current state and future goals of the Kamaelia_ project. Mainly, Kamaelia aims to make concurrency as simple and easy to use as possible. A scheduler manages a set of generators that communicate with each other through Queues. The long term goals include being able to farm the various generators off into thread or processes as needed, so that whether your concurrency model is cooperative, threaded or process-based, your code can basically look the same.
There was also continued discussion about how easy threads are. Shane Hathaway made the point that it's actually locking that's insanely difficult, and approaches that simplify how much you need to think about locking can keep threading relatively easy -- this was one of the strong points of ZODB. A fairly large camp also got behind the claim that threads are easy if you're limited to only message passing. There were also a few comments about how Python makes threading easier, 
e.g. through the GIL (see `QOTF: Quote of the Fortnight`_) and through threading.threads's encapsulation of thread-local resources as instance attributes... _Kamaelia: http://kamaelia.sourceforge.ne
Contributing threads:- `Pythonic concurrency - cooperative MT http://mail.python.org/pipermail/python-dev/2005-October/056898.html
`__- `Pythonic concurrency http://mail.python.org/pipermail/python-dev/2005-October/057023.html`__[SJB]
-Organization of modules for threading-A few people took issue with the current organization of the threading modules into Queue, thread and threading. Guido views Queue as an application of threading, so putting it in the threading module is inappropriate (though with a deeper package structure, it should definitely be a sibling). Nick Coghlan suggested that Queue should be in a threadtools module (in parallel with itertools), while Skip proposed a hierarchy of modules with thread and lock being in the lowest level one, and Thread and Queue being in the highest level. Aahz suggested (and Guido approved) deprecating the thread module and renaming it to _thread at least in Python 
3.0. It seems the deprecation may happen sooner though.Contributing threads:- `Making Queue.Queue easier to use http://mail.python.org/pipermail/python-dev/2005-October/057184.html
`__- `Autoloading? (Making Queue.Queue easier to use) http://mail.python.org/pipermail/python-dev/2005-October/057216.html
`__- `threadtools (was Re: Autoloading? (Making Queue.Queue easier to use)) http://mail.python.org/pipermail/python-dev/2005-October/057262.html
`__- `Threading and synchronization primitives http://mail.python.org/pipermail/python-dev/2005-October/057269.html`__
[SJB]-Speed of Unicode decoding-Tony Nelson found that decoding with a codec like mac-roman or iso8859-1 can take around ten times as long as decoding with utf-8. Walter Dörwald provided a patch_ that implements the mapping using a unicode string of length 256 where undefined characters are mapped to u\ufffd. This dropped the decode time for mac-roman to nearly the speed of the utf-8 decoding. Hye-Shik Chang showed off a fastmap decoder with comparable performance. In the end, Walter's patch was accepted.
.. patch: http://www.python.org/sf/1313939Contributing thread:- `Unicode charmap decoders slow 

Re: need help about time.sleep, timer

2005-11-21 Thread Sinan Nalkaya
Dennis Lee Bieber wrote:

On Fri, 18 Nov 2005 22:45:37 -0500, Peter Hansen [EMAIL PROTECTED]
declaimed the following in comp.lang.python:

  

It's quite unclear whether the last part, above, is one of your 
*requirements*, or a description of a problem you are having with your 
current approach.  Do you *want* it to wait forever if you don't enter 
anthing?



   As I understand it, he (?) wants to accumulate characters to be
passed to a certain function -- but the function is not to be invoked
until after a time period has expired; the time period resetting on each
character entered.

   Something I'd do with threads, queues, and sleep...

PSEUDOCODE

thread1:
   while not Shutdown:
   ch = getChar()
   q.put(ch)


thread2: #or main
   while not Shutdown:
   chars = []
   while True:
   sleep(max_interval)
   if q.empty(): break #no input since start of sleep
   while not q.empty():#collect all input from sleep
   chars.append(q.get())
   inp = .join(chars)
   function(inp)



  

i appreciate your comments and ideas. Dennis told exactly what i tried 
to say :), code seems to be fine but during sleep action i think the 
above code does not execute

if q.empty(): break #no input since start of sleep
while not q.empty():
chars.append(q.get())

i need something, while sleeping, executes the function that waits for 
input from keyboard.
i imagined something like that, i have a queu, it both stores the keys 
that pressed and pressing times of these keys, then i`ll proccess these 
times. here is scenario
input : 5
after 10 seconds later input 5 is being proccessed
return back to main function
input : 1
after 5 seconds , other input 5
after 5 more seconds , 15 is being proccessed
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web-based client code execution

2005-11-21 Thread Robin Becker
Paul Watson wrote:
..
 -- David
 
 
 This looks interesting, but looks even more fragile than CrackAJAX.
 
 http://www.aminus.org/blogs/index.php/phunt/2005/10/06/subway_s_new_ajax_framework
  
 
 
 All of this comes down to Javascript which will still not allow me to 
 read local, client files.  Right?

I think reading files is easy; just get the client browser to submit a 
form with the file as an upload. Hard part is getting the path(s) right.
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setattr for secondary attribute

2005-11-21 Thread Alex
Great! Thanks, it works (of course).

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 If I need the dict feature 90% of the time, and the list feature 10% of
 the time.

Wasn't your use case that you wanted to specify form fields in
a given order (LIST), render a default view of the form in that
order (LIST), and, later on, access the field specifiers in an
arbitrary order, based on their key (DICT).  Sure looks like it's
the LIST aspect that's important here...

(but assume that I have some other use case isn't a valid use
case)

 I want an ordered dict. Rather than a list and create this new view every
 time and every where I want to use it as a dict.

You want an ordered dict because you say you want one, not be-
cause it's the best way to address your use case.  That's fine, but
it's not really related to the question asked in the subject line.

 parsing or not parsing is not the point, and parsing/converting is
 still create a new view of an existing data structure.

Copying the entire data structure hardly qualifies as creating a
new view.  dict() doesn't do that; in this use case, it doesn't cost
you anything to use it.

Everything has a cost in Python.  Things aren't free just because
they're implemented by some other module.

But when things are free, they're often a good choice.

/F



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


Re: Aproximative string matching

2005-11-21 Thread Daniel Dittmar
javuchi wrote:
 I'm searching for a library which makes aproximative string matching,
 for example, searching in a dictionary the word motorcycle, but
 returns similar strings like motorcicle.
 
 Is there such a library?
 

agrep (aproximate grep) allows for a certain amount of errors and there 
exist Python bindings (http://www.bio.cam.ac.uk/~mw263/pyagrep.html)

Or google for agrep python.

Daniel

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread [EMAIL PROTECTED]

Fredrik Lundh wrote:
 [EMAIL PROTECTED] wrote:

  If I need the dict feature 90% of the time, and the list feature 10% of
  the time.

 Wasn't your use case that you wanted to specify form fields in
 a given order (LIST), render a default view of the form in that
 order (LIST), and, later on, access the field specifiers in an
 arbitrary order, based on their key (DICT).  Sure looks like it's
 the LIST aspect that's important here...
Yes. But whether LIST aspect or DICT is important is well, opinion. So
let's leave it there.

  I want an ordered dict. Rather than a list and create this new view every
  time and every where I want to use it as a dict.

 You want an ordered dict because you say you want one, not be-
 cause it's the best way to address your use case.  That's fine, but
 it's not really related to the question asked in the subject line.
Again, best way is decided by ME. If I am entering a coding contest
which is organized by YOU, that is a different story. As for related to
the subject line, since when I said my preference or use case has
anything to do with the subject line ? I have said in another post that
I don't think there should be  one in the standard library, which is
directly about the subject line.


  parsing or not parsing is not the point, and parsing/converting is
  still create a new view of an existing data structure.

 Copying the entire data structure hardly qualifies as creating a
 new view.  dict() doesn't do that; in this use case, it doesn't cost
 you anything to use it.
doesn't cost me anything ? That is good news to me.

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


writing a generic method

2005-11-21 Thread fj
I am new in Python programming. I try to connect to Python various
libraries written either in C of in Fortran. The job is not really hard
but I meet a trouble when trying to build up a generic routine like in
C++ or F90, i.e. a single routine name for various uses.

Here is an example with a Fortran 77 library:

static PyObject* mdb_get(PyObject *self, PyObject *args){
   const char *cname,*cprop;
   int lname,lprop;
   double x,z;
   int ix;
   if(PyArg_ParseTuple(args,s#s#d,cname,lname,cprop,lprop,x))
  mdbgetd_(cname,cprop,x,z,lname,lprop);
   else
if(PyArg_ParseTuple(args,s#s#i,cname,lname,cprop,lprop,ix))
  mdbgeti_(cname,cprop,ix,z,lname,lprop);
   else
  return NULL;
   return Py_BuildValue(d,z);
}

This method should be used as a single Python function mdb::get. It
should have two possible forms:
  mdb.get(H2O,h_l(T),300.)
  mdb.get(H2O,atom,2)

As you see, the third argument should be either a real or an integer.
Unfortunately, the result depends on the order of instructions because
Python automatically converts
integer into real and vice versa. For instance, the intructions above
are interpreted as follows :
   mdb.get(H2O,h_t(T),300.)  (correct)
   mdb.get(H2O,atom,2.)   (wrong because 2 and 2. are not
equivalent in my case)

So my question is : Is it possible to deactivate this automatic
conversion ?
Presently, the only solution I found was to write two functions
(mdb.getr and mdb.geti)

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Antoon Pardon
Op 2005-11-21, Christoph Zwerschke schreef [EMAIL PROTECTED]:
 [EMAIL PROTECTED] wrote:
 Personally, I have needs for ordered dict but I don't think it should
 be in standard library though, as different situation called for
 different behaviour for ordered and skewing my code to a standard lib
 way is no good.

 I have started the thread in the first place because I believed it is 
 pretty unabmiguous what an ordered dictionary is and how it should 
 behave. That's why I asked myself why something that straigthforward has 
 not been added to the standard lib yet. Maybe I'm wrong; I must admit 
 that I haven't meditated about it very much.

Well it doesn't seem that obvious, because the two recipes you have
gotten, do something different from what I understand as an ordered
dictionary.

The two recipes order the keys by insertion order.

My idea would have been that some order was defined
on your keys in advance and that when you iterated over
the dictionary, the results would be ordered in sequence
of key order.

 Do you have an example for different options of behavior?

Well you have two above. Maybe someone can think of something
else.

Which behaviour are you looking for?

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


unittest can not use function name 'test' ?

2005-11-21 Thread [EMAIL PROTECTED]
Hello

I found something strange in my unittest :
This code is ok (will report error ):

class MyTest1(unittest.TestCase):

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()


But if I add a function with the first name is 'test' it fails to
recognize the error:
class MyTest1(unittest.TestCase):
def test1(self):
pass

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()


Please help
pujo

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


Re: unittest can not use function name 'test' ?

2005-11-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 I found something strange in my unittest :
 This code is ok (will report error ):

 class MyTest1(unittest.TestCase):

 def runTest(self):
 self.assertEqual(2,3)
 pass

 if __name__ == '__main__':
 unittest.main()

 But if I add a function with the first name is 'test' it fails to
 recognize the error:

 class MyTest1(unittest.TestCase):
 def test1(self):
 pass

 def runTest(self):
 self.assertEqual(2,3)
 pass

 if __name__ == '__main__':
 unittest.main()

the runTest() method is a fallback, and is only used if you don't have any
test*() methods in your test case.  see e.g.

http://docs.python.org/lib/organizing-tests.html

/F



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


Re: Controlling windows gui applications from python

2005-11-21 Thread tim
Thanks for this tip, this looks like exactly what I need.

Is there a more extended documentation for watsup somewhere ?
I didn't find info on:
how to send keystrokes to a program.
how to control ComboBox elements...

trying out the examples, here are some problems I am running into:
I tried adapting the example4.py and example4a.py scripts for running an 
app of my own and clicking a button.
I commented out everything except for running the application and 
clicking a button.
here's what i left in:

###

from watsup.launcher import launchApp,terminateApp
from watsup.winGuiAuto import findTopWindows, 
findControl,getEditText,clickButton 
from watsup.performance import PerformanceCheck,PerformanceCheckError 
from time import sleep,time 

def main(myExecutable,myWantedText):
# find an instance of SimpleForm. If one isn't there, launch it
forms=findTopWindows(wantedText=myWantedText)
if forms:
form=forms[0]
else:
form=launchApp(myExecutable,wantedText=myWantedText)  
   
button=findControl(form,wantedText='Pref')
sleep(1)
clickButton(button) 
   #sleep(5)
   #terminateApp(form)
if __name__=='__main__':
print ' please run example4a or 4b'

###

when I un-comment the line : terminateApp(form) i get the following error:

Traceback (most recent call last):
  File 
C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py, 
line 310, in RunScript
exec codeObject in __main__.__dict__
  File C:\Python24\Lib\tim_vets\kip\examples\example4a_gnmidi.py, line 
3, in ?
main('C:\\tools\\MFiTool3.0_INTL_1.04.00\\MFiTool3.exe','MFi Tool 3')
  File C:\Python24\Lib\tim_vets\kip\examples\example4_gnmidi.py, line 
14, in main
button=findControl(form,wantedText='Pref')
  File C:\Python24\lib\site-packages\watsup\winGuiAuto.py, line 327, 
in findControl
raise WinGuiAutoError(EnumChildWindows failed with win32gui.error   +
WinGuiAutoError: EnumChildWindows failed with win32gui.error 853268, 
wantedText='Pref', wantedClass=None, selectionFunction=None, maxWait=1, 
retryInterval=0.1

with this line commented out, getting the 'Pref' button clicked works 
sometimes...
most of the times i get something like:

File example4_gnmidi.py, line 14, in main
button=findControl(form,wantedText='Pref')
  File C:\Python24\lib\site-packages\watsup\winGuiAuto.py, line 327, 
in findControl
raise WinGuiAutoError(EnumChildWindows failed with win32gui.error   +
WinGuiAutoError: EnumChildWindows failed with win32gui.error 1442992, 
wantedText='Pref', wantedClass=None, selectionFunction=None, maxWait=1, 
retryInterval=0.1

Opening the application is the only thing that always works...

thanks!

Simon Brunning wrote:

On 18/11/05, tim [EMAIL PROTECTED] wrote:
  

Hi all, I'm almost as new to this list as to python so I hope I don't
get a this has been answered a 100 times before or anything...

Currently I am using a program named 'Macro Scheduler' for automating
programs that don't have a command line version.
Its a simple scripting language that allows you to automate button
clicks, mouse movement, starting programs, checking the state of a
window, changing the focus, type text into an input field...etc.
Is there a way to do these things from within Python?



http://www.tizmoi.net/watsup/intro.html

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/



  



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


duplicate items in a list

2005-11-21 Thread Shi Mu
I used the following method to remove duplicate items in a list and
got confused by the error.

 a
[[1, 2], [1, 2], [2, 3]]
 noDups=[ u for u in a if u not in locals()['_[1]'] ]
Traceback (most recent call last):
  File interactive input, line 1, in ?
TypeError: iterable argument required
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Aproximative string matching

2005-11-21 Thread Fredrik Lundh
Tim Roberts wrote:

 I'm searching for a library which makes aproximative string matching,
 for example, searching in a dictionary the word motorcycle, but
 returns similar strings like motorcicle.
 
 Is there such a library?

 There is an algorithm called Soundex that replaces each word by a
 4-character string, such that all words that are pronounced similarly
 encode to the same string.

 The algorithm is easy to implement; you can probably find one by Googling.

Python used to ship with a soundex module, but it was removed
in 1.6, for various reasons.  here's a replacement:

http://orca.mojam.com/~skip/python/soundex.py

/F



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


Re: unittest can not use function name 'test' ?

2005-11-21 Thread [EMAIL PROTECTED]
Thanks Fredrik...

pujo

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Ben Sizer
Fredrik Lundh wrote:
 [EMAIL PROTECTED] wrote:
  Using the same logic, we don't need types other than string in a  DBMS
  as we can always convert a string field into some other types when it
  is needed.

 No, that's not the same logic.  The dict() in my example doesn't convert be-
 tween data types; it provides a new way to view an existing data structure.

This is interesting; I would have thought that the tuple is read and a
dictionary created by inserting each pair sequentially. Is this not the
case?

-- 
Ben Sizer

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


Re: Controlling windows gui applications from python

2005-11-21 Thread tim
Thanks for this tip, this looks like exactly what I need.

Is there a more extended documentation for watsup somewhere ?
I didn't find info on:
how to send keystrokes to a program.
how to control ComboBox elements...

trying out the examples, here are some problems I am running into:
I tried adapting the example4.py and example4a.py scripts for running an 
app of my own and clicking a button.
I commented out everything except for running the application and 
clicking a button.
here's what i left in:

###

from watsup.launcher import launchApp,terminateApp
from watsup.winGuiAuto import findTopWindows, 
findControl,getEditText,clickButton from watsup.performance import 
PerformanceCheck,PerformanceCheckError from time import 
sleep,time
def main(myExecutable,myWantedText):
   # find an instance of SimpleForm. If one isn't there, launch it
   forms=findTopWindows(wantedText=myWantedText)
   if forms:
   form=forms[0]
   else:
   form=launchApp(myExecutable,wantedText=myWantedText)   
button=findControl(form,wantedText='Pref')
   sleep(1)
   clickButton(button)   #sleep(5)
  #terminateApp(form)
if __name__=='__main__':
   print ' please run example4a or 4b'

###

when I un-comment the line : terminateApp(form) i get the following 
error:

Traceback (most recent call last):
 File 
C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py, 
line 310, in RunScript
   exec codeObject in __main__.__dict__
 File C:\Python24\Lib\tim_vets\kip\examples\example4a_gnmidi.py, line 
3, in ?
   main('C:\\tools\\MFiTool3.0_INTL_1.04.00\\MFiTool3.exe','MFi Tool 3')
 File C:\Python24\Lib\tim_vets\kip\examples\example4_gnmidi.py, line 
14, in main
   button=findControl(form,wantedText='Pref')
 File C:\Python24\lib\site-packages\watsup\winGuiAuto.py, line 327, in 
findControl
   raise WinGuiAutoError(EnumChildWindows failed with win32gui.error   +
WinGuiAutoError: EnumChildWindows failed with win32gui.error 853268, 
wantedText='Pref', wantedClass=None, selectionFunction=None, maxWait=1, 
retryInterval=0.1

with this line commented out, getting the 'Pref' button clicked works 
sometimes...
most of the times i get something like:

File example4_gnmidi.py, line 14, in main
   button=findControl(form,wantedText='Pref')
 File C:\Python24\lib\site-packages\watsup\winGuiAuto.py, line 327, in 
findControl
   raise WinGuiAutoError(EnumChildWindows failed with win32gui.error   +
WinGuiAutoError: EnumChildWindows failed with win32gui.error 1442992, 
wantedText='Pref', wantedClass=None, selectionFunction=None, maxWait=1, 
retryInterval=0.1

Opening the application is the only thing that always works...

thanks!


Simon Brunning wrote:

 On 18/11/05, tim [EMAIL PROTECTED] wrote:
  

 Hi all, I'm almost as new to this list as to python so I hope I don't
 get a this has been answered a 100 times before or anything...

 Currently I am using a program named 'Macro Scheduler' for automating
 programs that don't have a command line version.
 Its a simple scripting language that allows you to automate button
 clicks, mouse movement, starting programs, checking the state of a
 window, changing the focus, type text into an input field...etc.
 Is there a way to do these things from within Python?
   


 http://www.tizmoi.net/watsup/intro.html

 -- 
 Cheers,
 Simon B,
 [EMAIL PROTECTED],
 http://www.brunningonline.net/simon/blog/



  




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


Re: Problem printing in Win98

2005-11-21 Thread Dale Strickland-Clark
Maravilloso wrote:

 Hi
 
 I'm trying to automatically send a postscript file to be printed to the
 default printer in a Win98 PC, by means of using the instrucction:
 
   win32api.ShellExecute (0, print, file.ps, None, ., 0)
 
 but it raises an exception with the message:
 
   error: (31, 'ShellExecute', 'A device attached to the system is not
 functioning.')
 
 
 Curiously, that instruction does works on Win2K/XP, but trying to use
 this shortcut for easy printing in Win98 provokes such error. I've
 tried in different machines (all of them running with Win98) and I
 obtain the same output.
 
 Does anybody knows what happens with Win98 printing automation?
 Any idea?
 
 Thanks in advance

I presume this .ps file is a preformed postscript file that should be sent
to a postscript printer without further modification?

In this case, I think you should use copy instead of print. Something like
this:

win32api.ShellExecute(0, copy, file.ps prn, None, ., 0)

It has been a long time since I used Windows, especially 98, but if 'prn'
doesn't work, you might try one of: 'lpt', 'lpt1', 'lpt:', 'lpt1:'.


-- 
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk

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


Re: duplicate items in a list

2005-11-21 Thread Fredrik Lundh
Shi Mu wrote:

 I used the following method to remove duplicate items in a list and
 got confused by the error.

  a
 [[1, 2], [1, 2], [2, 3]]
  noDups=[ u for u in a if u not in locals()['_[1]'] ]

that's not portable, relies on CPython 2.4 implementation details, and
shouldn't be used unless you understand exactly why it shouldn't be
used.  please pick another solution from the cookbook page.

(fwiw, this shows why the activestate cookbook needs an editor, and
why user-annotated documention means that the documentation will
be no better than the dumbest contributor)

/F



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


tkinter and cygwin

2005-11-21 Thread [EMAIL PROTECTED]
Hi,

I've recently started learning python programming and have been
experimenting with a few basic GUI programs.  My work system is
cygwin/Windows XP.  I use X-windows in cygwin but when I run my
python/tkinter program from an x-win terminal , a normal XP window is
opened up.  Any text output from the program of course shows up in the
terminal I started the program from.  Is there a way to make python open
up a window in the X display instead of an XP window?  It's really
annoying because if I click on another window or terminal in the
X-window screen, the X-window display will then cover up the python GUI.

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


Re: duplicate items in a list

2005-11-21 Thread Fredrik Lundh
Shi Mu wrote:

 I used the following method to remove duplicate items in a list and
 got confused by the error.

  a
 [[1, 2], [1, 2], [2, 3]]
  noDups=[ u for u in a if u not in locals()['_[1]'] ]
 Traceback (most recent call last):
   File interactive input, line 1, in ?
 TypeError: iterable argument required

by the way, assuming that it doesn't really matter whether the
resulting list contains lists or tuples, here's a simple oneliner-plus-
optional-import solution:

# this is only needed if you're using 2.3 or earlier
 from sets import Set as set

 hasDups = [[1, 2], [1, 2], [2, 3]]

 noDups = list(set(map(tuple, hasDups)))

 noDups
[(1, 2), (2, 3)]

if you need an order-preserving implementation, see raymond's
example over at the cookbook.

/F



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


sort the list

2005-11-21 Thread Shi Mu
I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list
based on the second value in the item?
That is,
I want the list to be:
[[3,2],[1,4],[2,5],[3,9]]
-- 
http://mail.python.org/mailman/listinfo/python-list


OSDC::Israel Conference 26-28 Feb. 2006

2005-11-21 Thread Amit Aronovitch
==
Open Source Developers' Conference,
26-28 February, 2006, Netanya, Israel
==
Announcement and Call for Papers

http://www.osdc.org.il/call_for_paper.html

About
--
The Open Source Developers' Conferences (OSDCs) are grassroots symposia
originating from Australia. The conference tries to bring together the
users of various OS technologies such as Perl, Python, Ruby, Tcl, PHP,
MySQL, PostgreSQL, Subversion and more.
The Israeli OSDC is organized by the Israeli Perl Mongers and the
Israeli Python user group.
 Our aim is to bring together practitioners, scholars, students,
programmers, researchers and managers from different areas to discuss
their views on various aspects of the Open Source technologies, to share
knowledge and to have fun while doing so.

Structure
--
The conference will last for 3 days with 3 parallel tracks of
presentations. Presentations will be given in either Hebrew or English,
depending on the speaker's preference (the language will be listed in
advance).

Call for Papers

Recommended Topics for Python Related Presentations:

* Python based web  content-management technology (e.g. Zope)
* Major or Interesting packages (e.g. Twisted)
* Language development and new implementations (e.g. PyPy)
* Interfacing other languages (e.g. boost-python)

 The examples given above are suitable for long presentations or
tutorials, but we also accept 40 and 20 minutes presentations, and 5
minute lightning talks.
 Any other topics which are interesting and relevant to Open Source
Developers are also welcome.

 For submitting proposals:  http://www.osdc.org.il/proposal.html

For updates and more details:

  http://www.osdc.org.il/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
Ben Sizer wrote:

  No, that's not the same logic.  The dict() in my example doesn't convert be-
  tween data types; it provides a new way to view an existing data structure.

 This is interesting; I would have thought that the tuple is read and a
 dictionary created by inserting each pair sequentially. Is this not the
 case?

pointers to the members of each pair, yes.  but a pointer copy is a
cheap operation (for the given use case, we're only talking about a
few dozen pairs anyway, at the most).

this is a common fallacy; Python programmers underestimate the
cost of adding extra layers to their code (e.g. by using an ordered
dict data structure that has to incrementally update both a list and
a dictionary), and overestimate the cost of letting the C layer do
bulk operations.

(as an example, on my machine, using Foord's OrderedDict class
on Zwerschke's example, creating the dictionary in the first place
takes 5 times longer than the index approach, and accessing an
item takes 3 times longer.  you can in fact recreate the index 6
times before OrderedDict is faster; if you keep the index around,
the OrderedDict approach never wins...)

/F



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


Re: wxListBox and others after upgrade to MacOS X 10.4

2005-11-21 Thread isthar
Hi again

more data:

I upgraded to 2.6.x version of wxPython and tried to run my program (
using
wxversion.switch('2.6') of course) - no results.
Demo boudled with wxPython works well ( at least wxListBox )

BTW UI code was generated by wxGlade.

Help Help Help

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


Re: duplicate items in a list

2005-11-21 Thread Daniel Schüle
Shi Mu wrote:
 I used the following method to remove duplicate items in a list and
 got confused by the error.
 
 
a
 
 [[1, 2], [1, 2], [2, 3]]
 
noDups=[ u for u in a if u not in locals()['_[1]'] ]
 
 Traceback (most recent call last):
   File interactive input, line 1, in ?
 TypeError: iterable argument required

  a
[[1, 2], [1, 2], [2, 3]]
  c=[]
  for x in a:
... if x not in c: c.append(x)
...
  c
[[1, 2], [2, 3]]

or (Python 2.4)


  a
[[1, 2], [1, 2], [2, 3]]
  set([frozenset(u) for u in a])
set([frozenset([1, 2]), frozenset([2, 3])])

hth Daniel

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


Re: sort the list

2005-11-21 Thread Daniel Schüle
Shi Mu wrote:
 I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list
 based on the second value in the item?
 That is,
 I want the list to be:
 [[3,2],[1,4],[2,5],[3,9]]


  lst = [[1,4],[3,9],[2,5],[3,2]]
  lst
[[1, 4], [3, 9], [2, 5], [3, 2]]
 
 
  lst.sort(cmp = lambda x,y: cmp(x[1], y[1]))
  lst
[[3, 2], [1, 4], [2, 5], [3, 9]]
 

works for Python 2.4
in earlier Pythons just let cmp = .. away

Regards, Daniel

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


Re: termios.tcgetattr(fd) error: (22, 'Invalid argument')

2005-11-21 Thread Sinan Nalkaya
Petr Jakes wrote:

To provide  some feedback:
As Grant Edwards  posted in this list, I was running my code inside of
IDE that replaces sys.stdin with some other. While running the program
from a shell prompt, everything goes fine. 
Petr Jakes

  

have you tried it with root account ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sort the list

2005-11-21 Thread Shi Mu
On 11/21/05, Daniel Schüle [EMAIL PROTECTED] wrote:
 Shi Mu wrote:
  I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list
  based on the second value in the item?
  That is,
  I want the list to be:
  [[3,2],[1,4],[2,5],[3,9]]


   lst = [[1,4],[3,9],[2,5],[3,2]]
   lst
 [[1, 4], [3, 9], [2, 5], [3, 2]]
  
  
   lst.sort(cmp = lambda x,y: cmp(x[1], y[1]))
   lst
 [[3, 2], [1, 4], [2, 5], [3, 9]]
  

 works for Python 2.4
 in earlier Pythons just let cmp = .. away

 Regards, Daniel
what does let cmp = .. away mean?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sort the list

2005-11-21 Thread Fredrik Lundh
Shi Mu wrote:

 I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list
 based on the second value in the item?
 That is,
 I want the list to be:
 [[3,2],[1,4],[2,5],[3,9]]

since you seem to be using 2.3, the solution is to use a custom
compare function:

 L = [[1,4],[3,9],[2,5],[3,2]]
 def mycmp(a, b):
... return cmp(a[1], b[1])
...
 L.sort(mycmp)
 L
[[3, 2], [1, 4], [2, 5], [3, 9]]

under 2.4, you can use the key argument together with the item-
getter function to sort on a given column; look for itemgetter on
this page for some examples:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305304

/F



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


Re: sqlite utf8 encoding error

2005-11-21 Thread Greg Miller
Thanks again, I'll look into this method.

Greg Miller

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


Re: duplicate items in a list

2005-11-21 Thread Steven D'Aprano
On Mon, 21 Nov 2005 02:49:56 -0800, Shi Mu wrote:

 I used the following method to remove duplicate items in a list and
 got confused by the error.
 
 a
 [[1, 2], [1, 2], [2, 3]]
 noDups=[ u for u in a if u not in locals()['_[1]'] ]
 Traceback (most recent call last):
   File interactive input, line 1, in ?
 TypeError: iterable argument required

Confused by the error? I'm confused by your code!!!

If you want to remove duplicate items in a list, try something like this:


def remove_dups(L):
Removes duplicate items from list L in place.
# Work backwards from the end of the list.
for i in range(len(L)-1, -1, -1):
# Check to see if the current item exists elsewhere in 
# the list, and if it does, delete it.
if L[i] in L[:i]:
del L[i]

Instead of deleting duplicate items in place, we can create a new list
containing just the unique items:

def unique_items(L):
Returns a new list containing the unique items from L.
U = []
for item in L:
if item not in U:
U.append(item)
return U


The trick you are trying to do with _ is undocumented and, even if you get
it to work *now*, is probably not going to work in the future. Don't do it.


-- 
Steven.

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


Re[2]: termios.tcgetattr(fd) error: (22, 'Invalid argument')

2005-11-21 Thread Petr
To provide  some feedback:
As Grant Edwards  posted in this list, I was running my code inside of
IDE that replaces sys.stdin with some other. While running the program
from a shell prompt, everything goes fine. 
Petr Jakes

  

SN have you tried it with root account ?
Yes, I did. The problem was the IDE. Without IDE the filedescriptor
and its flags settings are working flawlessly.

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


Numeric array in unittest problem

2005-11-21 Thread [EMAIL PROTECTED]
hello,

I found that if I use Numeric.array into unittest it is not
consistance,
Is that normal ?

import Numeric
class myTest(unittest.TestCase):
def runTest(self):
a = Numeric.array([1,2])
b = Numeric.array([1,33])
self.assertEqual(a, b)
pass


This will not raise any error ???

Any idea?

Sincerely Yours,
pujo

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


Re: Underscores in Python numbers

2005-11-21 Thread Antoon Pardon
Op 2005-11-20, Roy Smith schreef [EMAIL PROTECTED]:
 [EMAIL PROTECTED] (David M. Cooke) wrote:

 One example I can think of is a large number of float constants used
 for some math routine. In that case they usually be a full 16 or 17
 digits. It'd be handy in that case to split into smaller groups to
 make it easier to match with tables where these constants may come
 from. Ex:
 
 def sinxx(x):
 computes sin x/x for 0 = x = pi/2 to 2e-9
 a2 = -0.1 4
 a4 =  0.00833 33315
 a6 = -0.00019 84090
 a8 =  0.0 27526
 a10= -0.0 00239
 x2 = x**2
 return 1. + x2*(a2 + x2*(a4 + x2*(a6 + x2*(a8 + x2*a10
 
 (or least that's what I like to write). Now, if I were going to higher
 precision, I'd have more digits of course.

 You have described, if memory serves, a Taylor series, and those 
 coefficients are 1/3!, 1/5!, 1/7!, etc.

Well if you had infinite precision numbers you might be right.
However in numerial analysis, one often uses numbers which
are slightly different, in order to have a more uniform error
spread over the interval used.

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


PyCommandEvent

2005-11-21 Thread Karsten
Hello,

I've got a question about Python Events. I want to generate a 
PyCommandEvent (included in the wx Package). This PyCommandEvent ought 
to be called when a method/function is called. I've seen some examples 
in the www how I can call the Event when an other Event is called. But 
this is not useful for me, because I want to generate a Event at runtime.
Example:
I've written a program which use the win32com interface of SAPI 5. When 
a word is recognated, this word will be transported to the major 
module by calling a method of a class within this method. When this 
method is called I want, that the method generate/process a PyCommandEvent.

this code I have now:
##
myEVT_SR_RECOGNITION = wx.NewEventType()
EVT_SR_RECOGNITION = wx.PyEventBinder(myEVT_SR_RECOGNITION, 1)

class COM_SR_REC:
def __init__(self):
print init COM_SR_REC
   
def OnRecognition(self,text):
print I heared:  + text
   make_event = MakeSREvent(text)

def MakeSREvent(self, text):
start_event = SR_Event(myEVT_SR_RECOGNITION,1)
start_event.WordRec(text)
self.GetEventHandler().ProcessEvent(start_event)
start_event.Skip()

class SR_Event(wx.PyCommandEvent):
def __init__(self, eventType, id):
wx.PyCommandEvent.__init__(self, eventType, id)
##

I think the class SR_EVENT works accurate. The problem is, that I can't 
call the Event by using 'GetEventHandler' because there is no 
EventHandler in class COM_SR_REC. 
How can I call/process the Event???
Is the rest of the code right???

Next Question:
How can I listen to those PyCommandEvents from other modules?

Thanks for help!

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


Re: Aproximative string matching

2005-11-21 Thread Tim Heaney
javuchi [EMAIL PROTECTED] writes:

 I'm searching for a library which makes aproximative string matching,
 for example, searching in a dictionary the word motorcycle, but
 returns similar strings like motorcicle.

 Is there such a library?

I kind of like the one at 

  http://www.personal.psu.edu/staff/i/u/iua1/python/apse/

which you might use something like

   import Apse
   ap = Apse.Approx('motorcycle', edit=1)
   ap.match(['motorcycle', 'motorcicle', 'motorscooter'])
  ['motorcycle', 'motorcicle']

That page mentions several alternatives, as well.

I hope this helps,

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


Re: Underscores in Python numbers

2005-11-21 Thread Scott David Daniels
Bruno Desthuilliers wrote:
 So even if it's far from a common use case for *most* Python users, it 
 may be a common use case for *some* Python users.
 
 Also, someone mentionned the use of Python as a configuration langage - 
 which is probably a much more common use case.
 
 So FWIW, I'd be +1 on adding it *if and only if*:
 - it's trivial to implement [1]
 - it doesn't break older code
 
 and +1 on the space as group delimiter BTW.
 
 [1]: I never wrote a language by myself, but I've played a bit with 
 parsers and lexers, and I _guess_ (which implies I may be wrong !-) it 
 wouldn't require much work to add support for a literal numeric 
 grouping syntax  in Python.

Since I've been trying to speed up the digit-scan code, I can say that
any ignorable will slow the loop (counting digits gives you an integral
logarithm to the base, and you can tell if you can convert quickly).
However, Unicode must have ignore ables apparently, so (at least in the
Unicode case) they may have to be dealt with.

Also, a parser hack won't do (for speed), you have to get the entire
number and translate it at one go.  The space smacks of expecting a
parser change, where you might expect:
  pi = (3.1415926535 8979323846 2643383279 5028841971 6939937510
  5820974944 5923078164 0628620899 8628034825 3421170679
  8214808651 3282306647 0938446095 5058223172 5359408128 )
to work (allowing any whitespace and line breaks and ...).
Also, it would be a trifle frustrating to translate:
  distance = (1 000 000 000 000 000
  000 000 000 000 000.)
Which looks like an integer for a long time.  I'd say if we go for
anything, we should follow the Ada lead of allowing underscore, only
allow single underscores (so 1__000 is an error).  I am happier with
those applications that want this using their own function, however:
  pi = FloatConv('3.1415926535 8979323846 2643383279 5028841971 '
   '6939937510 5820974944 5923078164 0628620899 '
   '8628034825 3421170679 8214808651 3282306647 '
   '0938446095 5058223172 5359408128')

Since the use case is long constants, can we generally agree they
should be named and set out as globals in the module?  And in such
a case, the cost of calling something like FloatConv (or whatever)
becomes negligible.  As to interactive use, I just don't see that
having things like IntConv, FloatConv around strings is a real
hardship -- for me the hardship is almost always trying to verify
the digits are typed in correctly, not the extra function call.

-- 
-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sort the list

2005-11-21 Thread Daniel Schüle
[...]

  lst = [[1,4],[3,9],[2,5],[3,2]]
  lst
[[1, 4], [3, 9], [2, 5], [3, 2]]
 
 
  lst.sort(cmp = lambda x,y: cmp(x[1], y[1]))
  lst
[[3, 2], [1, 4], [2, 5], [3, 9]]
 

works for Python 2.4
in earlier Pythons just let cmp = .. away

Regards, Daniel
 
 what does let cmp = .. away mean?

it means
lst.sort(lambda x,y: cmp(x[1], y[1]))

I can offer you some more brain food to digest ;)
maybe you can adapt this solution, but that depends
on your problem
I find it clear and I used it recently

  name, age, salary = name, age, salary
  people = [
... {name:oliver, age:25, salary:1800},
... {name:mischa, age:23, salary:0},
... {name:peter, age:22, salary:1500},
... ]
 
  def cmpFabrik(field):
... def cmpFunc(x,y):
... return cmp(x[field], y[field])
... return cmpFunc
  people.sort(cmp = cmpFabrik(name))
  people.sort(cmp = cmpFabrik(age))
  people.sort(cmp = cmpFabrik(salary))

it's not very OO but sometimes things are simple
and no need to create a class

Regards, Daniel

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


Cross-Platform ReadKey

2005-11-21 Thread Dustan
I found this site that has the code for readkey for Windows, Unix, and
in an updated version, Mac:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892 .  The
Mac object returns a character whether or not a key was pressed.  I
modified the Windows object to do the same when I downloaded it, but I
have no idea how to make the Unix object instantly return either the
character or an empty string. Any help???

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


Re: ownership problem?

2005-11-21 Thread Jeffrey Schwab
Fredrik Lundh wrote:
 Jeffrey Schwab wrote:
 
 
the problem isn't determining who owns it, the problem is determining
who's supposed to release it.  that's not a very common problem in a
garbage-collected language...

Yes it is.  Memory is only one type of resource.
 
 
 Python's garbage collector deals with objects, not memory.

But you don't want to spin and wait for the garbage collector to release 
the object that happens to be holding a thread lock...

I am not a Python Guru
 
 
 from the sound of it, you haven't written serious programs in any of the
 languages you mention.

You would be wrong there. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter and cygwin

2005-11-21 Thread Jason Tishler
John,

On Mon, Nov 21, 2005 at 08:18:09PM +0900, John wrote:
 I've recently started learning python programming and have been
 experimenting with a few basic GUI programs.  My work system is
 cygwin/Windows XP.  I use X-windows in cygwin but when I run my
 python/tkinter program from an x-win terminal , a normal XP window is
 opened up.

For better or worse, Cygwin's tcltk package is essentially a Win32
build.  So, the behavior you are observing is expected although not
necessarily desired.

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ownership problem?

2005-11-21 Thread Fredrik Lundh
Jeffrey Schwab wrote:

 the problem isn't determining who owns it, the problem is determining
 who's supposed to release it.  that's not a very common problem in a
 garbage-collected language...
 
 Yes it is.  Memory is only one type of resource.
 
  Python's garbage collector deals with objects, not memory.

 But you don't want to spin and wait for the garbage collector to release
 the object that happens to be holding a thread lock...

no, but arguing that sockets and thread locks are objects that suffer
from ownership problems is rather silly.  if their use isn't localized to a
single function or a single manager object, your design is flawed.

/F



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


Re: is parameter an iterable?

2005-11-21 Thread Fredrik Lundh
Steven D'Aprano wrote:

 Alas and alack, I have to write code which is backwards
 compatible with older versions of Python:

 Python 2.1.1 (#1, Aug 25 2001, 04:19:08)
 [GCC 3.0.1] on sunos5
 Type copyright, credits or license for more
 information.
   iter
 Traceback (most recent call last):
File stdin, line 1, in ?
 NameError: name 'iter' is not defined

 What should I do when I can't rely on functions that
 don't exist in older versions of Python?

python 2.1 doesn't support iterators, so that question doesn't
make much sense.

$ python2.1

 class iterable:
... def __iter__(self):
... print ITER
... return self
... def next(self):
... print NEXT
... return 1
...
 for i in iterable():
... print i
...
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: iterable instance has no attribute '__getitem__'

if you want to write code that runs under 2.1, you have to write
your code in terms of what 2.1 supports.   Python's compatibility
model means that code written for old versions still work in new
versions; it doesn't mean that code written for new versions will
always work properly (or raise proper exceptions) in old versions.

/F



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


Re: Raw string fu

2005-11-21 Thread 'Dang' Daniel Griffith
On 26 Oct 2005 12:27:53 -0700, Paul McGuire [EMAIL PROTECTED]
wrote:

Raw string fu?  A new martial art?
For the udon-aware.
--dang
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numeric array in unittest problem

2005-11-21 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
 hello,
 
 I found that if I use Numeric.array into unittest it is not
 consistance,
 Is that normal ?
 
 import Numeric
 class myTest(unittest.TestCase):
 def runTest(self):
 a = Numeric.array([1,2])
 b = Numeric.array([1,33])
 self.assertEqual(a, b)
 pass
 
 
 This will not raise any error ???

Code that doesn't execute at all generally raises no errors...

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


Re: sort the list

2005-11-21 Thread Fredrik Lundh
Daniel Schüle wrote:
  what does let cmp = .. away mean?

 it means
 lst.sort(lambda x,y: cmp(x[1], y[1]))

note that cmp= isn't needed under 2.4 either.  if you leave it out,
your code will be more portable.

/F



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

Re: ownership problem?

2005-11-21 Thread Jeffrey Schwab
Fredrik Lundh wrote:
 Jeffrey Schwab wrote:
 
 
the problem isn't determining who owns it, the problem is determining
who's supposed to release it.  that's not a very common problem in a
garbage-collected language...

Yes it is.  Memory is only one type of resource.

Python's garbage collector deals with objects, not memory.

But you don't want to spin and wait for the garbage collector to release
the object that happens to be holding a thread lock...
 
 
 no, but arguing that sockets and thread locks are objects that suffer
 from ownership problems is rather silly.

Why?  Are those resources somehow less important than memory?

 if their use isn't localized to a
 single function or a single manager object, your design is flawed.

!

I disagree.  Suppose some code is written to work with any file-like 
object.  Now suppose a file-like object is passed in that represents 
some URL.  The first time the object is read, the object opens a 
suitable network connection.  When is it safe to close that connection? 
  The client code can't say, because it doesn't even know any network 
connection has been opened.  In a language with deterministic 
destructors, the destructor can be relied on to close the connection as 
soon as the object goes out of scope.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Configure failing why?

2005-11-21 Thread Samuel M. Smith

I found a workaround,that is, to disable attribute caching using the  
noac nfs option.

#These two worked on tiger 10.4.3
exec -c console=ttyAM0,115200  
ip=10.0.2.155:10.0.2.150:10.0.2.1:255.255.255.0:ts7250  
nfsroot=10.0.2.150:/Data/nfsroot,noac

#fstab entry they have to match
10.0.2.150:/Data/nfsroot/ / nfs noac,noauto 0 0

#If use noac,sync,dirsync then gcc does not work
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help about time.sleep, timer

2005-11-21 Thread Steve Holden
Sinan Nalkaya wrote:
 Dennis Lee Bieber wrote:
 
 
On Fri, 18 Nov 2005 22:45:37 -0500, Peter Hansen [EMAIL PROTECTED]
declaimed the following in comp.lang.python:

 


It's quite unclear whether the last part, above, is one of your 
*requirements*, or a description of a problem you are having with your 
current approach.  Do you *want* it to wait forever if you don't enter 
anthing?

   


  As I understand it, he (?) wants to accumulate characters to be
passed to a certain function -- but the function is not to be invoked
until after a time period has expired; the time period resetting on each
character entered.

  Something I'd do with threads, queues, and sleep...

PSEUDOCODE

thread1:
  while not Shutdown:
  ch = getChar()
  q.put(ch)


thread2: #or main
  while not Shutdown:
  chars = []
  while True:
  sleep(max_interval)
  if q.empty(): break #no input since start of sleep
  while not q.empty():#collect all input from sleep
  chars.append(q.get())
  inp = .join(chars)
  function(inp)



 

 
 i appreciate your comments and ideas. Dennis told exactly what i tried 
 to say :), code seems to be fine but during sleep action i think the 
 above code does not execute
 
 if q.empty(): break #no input since start of sleep
   while not q.empty():
   chars.append(q.get())
 
 i need something, while sleeping, executes the function that waits for 
 input from keyboard.
 i imagined something like that, i have a queu, it both stores the keys 
 that pressed and pressing times of these keys, then i`ll proccess these 
 times. here is scenario
 input : 5
 after 10 seconds later input 5 is being proccessed
 return back to main function
 input : 1
 after 5 seconds , other input 5
 after 5 more seconds , 15 is being proccessed
 Thanks.

It sounds like you will have to learn how to do two things in parallel, 
which is normally done using threads. Unfortunately it also seems you 
would like the input thread to be terminated when the timer thread finds 
its time is up, and that's not particularly easy because there's no way 
to stop a thread from the outside once it's started.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Web-based client code execution

2005-11-21 Thread Paul Watson
Robin Becker wrote:
 Paul Watson wrote:
 ..
 
 -- David



 This looks interesting, but looks even more fragile than CrackAJAX.

 http://www.aminus.org/blogs/index.php/phunt/2005/10/06/subway_s_new_ajax_framework
  


 All of this comes down to Javascript which will still not allow me to 
 read local, client files.  Right?
 
 
 I think reading files is easy; just get the client browser to submit a 
 form with the file as an upload. Hard part is getting the path(s) right.

I need to walk the directory tree to find which files are of interest. 
It sounds like a client application (not browser) will be required.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any royal road to Bezier curves...?

2005-11-21 Thread Terry Hancock
On Sun, 20 Nov 2005 23:33:36 -0500
Warren Francis [EMAIL PROTECTED] wrote:
 I'm fairly new to Python (2-3 months) and I'm trying to
 figure out a simple  way to implement Bezier curves...  So
 far I've tried the following:
 
 http://runten.tripod.com/NURBS/
 ...which won't work because the only compiled binaries are
 for Windows 2000,  python 2.1.  I'm on Windows XP (for
 now), using Python 2.4.  I downloaded  the source
 distribution, but the header files aren't included, so I'm
 not  sure how to compile it.

NURBS are not actually Bezier curves, AFAIK, they are a
superset of some kind (which means they're probably better
to use, but harder to implement).

 It appears there's some bezier functionality in the python
 that comes  Blender... but I'm not savvy enough yet to try
 and extract whatever makes  beziers work there, to make it
 work in my general-purpose Python programs.

Not a specific recommendation, and I don't know if it's
any more comprehensible, but you will find that Skencil also
implements Bezier curves (in 2D).  Skencil is mostly in
Python, but uses a lot of C, so I don't know if it handles
beziers in Python or C (I'm still learning my way around the
code, myself).

Inkscape, of course, does too, but in C.
http://www.inkscape.org

 Basically, I'd like to specify a curved path of an object
 through space.  3D  space would be wonderful, but I could
 jimmy-rig something if I could just  get 2D...  Are bezier
 curves really what I want after all?

Or NURBS, yeah, probably.


-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: sort the list

2005-11-21 Thread Giovanni Bajo
Fredrik Lundh wrote:

 I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list
 based on the second value in the item?
 That is,
 I want the list to be:
 [[3,2],[1,4],[2,5],[3,9]]

 since you seem to be using 2.3, the solution is to use a custom
 compare function:

  L = [[1,4],[3,9],[2,5],[3,2]]
  def mycmp(a, b):
 ... return cmp(a[1], b[1])
 ...
  L.sort(mycmp)
  L
 [[3, 2], [1, 4], [2, 5], [3, 9]]

 under 2.4, you can use the key argument together with the item-
 getter function to sort on a given column; look for itemgetter on
 this page for some examples:

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305304

To clarify, itemgetter is just an optimization. Even without it, you can
still use key:

 L = [[1,4],[3,9],[2,5],[3,2]]
 def mykey(e):
... return e[1]
...
 L.sort(key=mykey)
 L
[[3, 2], [1, 4], [2, 5], [3, 9]]

Using the key keyword argument can be easier to understand (sorting
against the second element == second element is the key).
-- 
Giovanni Bajo


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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fuzzyman

Fredrik Lundh wrote:
 Ben Sizer wrote:

   No, that's not the same logic.  The dict() in my example doesn't convert 
   be-
   tween data types; it provides a new way to view an existing data 
   structure.
 
  This is interesting; I would have thought that the tuple is read and a
  dictionary created by inserting each pair sequentially. Is this not the
  case?

[snip..]
 (as an example, on my machine, using Foord's OrderedDict class
 on Zwerschke's example, creating the dictionary in the first place
 takes 5 times longer than the index approach, and accessing an
 item takes 3 times longer.  you can in fact recreate the index 6
 times before OrderedDict is faster; if you keep the index around,
 the OrderedDict approach never wins...)


So, so long as you want to use the dictionary less than six times -
it's faster to store/access it as a list of tuples. ;-)

Everytime you want to access (or assign to) the data structure as a
dictionary, you have to re-create the index.

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

 /F

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


Re: duplicate items in a list

2005-11-21 Thread drochom
http://groups.google.com/group/comp.lang.python/browse_thread/thread/32e545ebba11dd4d/49a9f0cc799cc1f1#49a9f0cc799cc1f1

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


Re: Underscores in Python numbers

2005-11-21 Thread Micah Elliott
On Nov 19, Steven D'Aprano wrote:
 Perhaps Python should concatenate numeric literals at compile time:
 
 123 456 is the same as 123456.

+1 for readability.

But in support of no change, When was the last time you looked at long
sequences of python digits outside of your editor/IDE?  You probably
don't deal with them interactively (and if you do you probably paste
them in).

So reasonable editors could just color groups differently. E.g.:

123456789012345
^^^
red  blue red

-- 
_ _ ___
|V|icah |- lliott  [EMAIL PROTECTED]
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web-based client code execution

2005-11-21 Thread Fuzzyman

Paul Watson wrote:
 John J. Lee wrote:
[snip..]
 I appreciate your long list of references.  For this task, I think the
 first answer may have to be the one with which to go.  A standard
 application that talks through port 80 and perhaps can use proxies.

 My desire to have the code distributed through a web page is just to
 ensure that the user is running the correct version and has not hacked
 it in any way.  I suppose I can checksum the local client application
 and compare it with what is on the server.  Then, make a way to
 update... ARGH!


If you can run it as a client application (i.e. not through the browser
but still across the internet) - then this all seems quite easy to
achieve. It also allows you to access the local filesystem without
dropping out of Python or using ActiveX objects.

If you know the version of Python the machines are using (or create a
loader program using py2exe) then you only need dsitribute the 'pyc'
bytecode files. (Making it *much* harder to hack for the average user).

I don't know if anyone has released an 'auto-update' framework for
applications, but it would be a nice project. I guess each time it's
needed the requirements will be slightly different though - but there
are a lot of general principles.

All the best,

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

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


Re: Numeric array in unittest problem

2005-11-21 Thread [EMAIL PROTECTED]
Sorry Peter,

Try this

import unittest
import Numeric

class myTest(unittest.TestCase):
def runTest(self):
var1 = Numeric.array([1,22])
var2 = Numeric.array([1,33])
self.assertEqual(var1,var2)

if __name__ == '__main__':
unittest.main()


pujo

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


Re: best cumulative sum

2005-11-21 Thread David Isaac

[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 He seems to want scanl

Yes.  But it's not in Python, right?
(I know about Keller's version.)

Robert Kern wrote:
 Define better. More accurate? Less code?

Good point.
As Bonono (?) suggested: I'd most like a solution that
relies on a built-in to give me both of those.
(Pretty is good too.)  Like SciPy's cumsum.

Thanks,
Alan Isaac


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


Re: writing a generic method

2005-11-21 Thread fj
Nice !

Thank you very much : it works well with s#s#O

And also thank you for your advice to insert PyErr_Clear() when several
calls to PyArgParseTuple are performed in the same method.

bye

FJ

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   ...
 d = somedict_from_db()
 prefer=['f','a',b']
 
 def my_order(d):
for x in prefer:
  if x in d: yield x
s = frozenset(prefer)
for x in d:
  if x not in s: yield x

Yes, a much cleaner architecture (if you don't need any sorting on
non-preferred keys of d) than the ponderous general one I proposed.  A
'key' approach with this behavior would be:

def my_key(k):
try: return prefer.index(k)
except ValueError: return len(prefer)

Now, 'for x in sorted(d, key=my_key)' should be equivalent to 'for x in
my_order(d)' thanks to the stability of sorting when the 'key' callable
returns equal values.

Neither of these way-simpler approaches is (I suspect) optimal for
speed, in the unlikely event one cares about that.  The idea of
preprocessing the 'preferred' list once and for all outside of the
function (which I used heavily in my previous post) might yield some
speed-up, for example:

def my_key_fast(k, _aux=dict((k,i) for i,k in enumerate(prefer),
   _l=len(prefer)):
return _aux.get(k, _l)

It's very unlikely that this situation warrants such optimization, of
course, I'm just thinking aloud about abstract possibilities.


Alex

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


Re: writing a generic method

2005-11-21 Thread jepler
You could use a format like #s#sO, and then use PyFloat_Check,
PyFloat_AsDouble, and the equivalent PyInt macros to get the C value out of
the Python object.

You should be able to use the converter O to get what you want.  The
conversion function might look like:
int double_only(PyObject *o, double *d) {
if(!PyFloat_Check(o)) return 0;
*d = PyFloat_AsDouble(o);
}
and the call would be

if(PyArg_ParseTuple(args,s#s#O,cname,lname,cprop,lprop,double_only,x))
 mdbgetd_(cname,cprop,x,z,lname,lprop);
(untested)

I believe that if you write
if(PyArg_ParseTuple(...))
else(PyArg_ParseTuple(...))
you're missing a PyErr_Clear() before the second PyArg_ParseTuple().  Returning
non-NULL when an exception has been set in C code will lead to a hard-to-trace
failure down the road.

Jeff


pgpq4yB9LZ1AX.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

OSDC::Israel Conference 26-28 Feb. 2006

2005-11-21 Thread Amit Aronovitch
==
Open Source Developers' Conference,
26-28 February, 2006, Netanya, Israel
==
Announcement and Call for Papers

http://www.osdc.org.il/call_for_paper.html

About
--
The Open Source Developers' Conferences (OSDCs) are grassroots symposia
originating from Australia. The conference tries to bring together the
users of various OS technologies such as Perl, Python, Ruby, Tcl, PHP,
MySQL, PostgreSQL, Subversion and more.
The Israeli OSDC is organized by the Israeli Perl Mongers and the
Israeli Python user group.
 Our aim is to bring together practitioners, scholars, students,
programmers, researchers and managers from different areas to discuss
their views on various aspects of the Open Source technologies, to share
knowledge and to have fun while doing so.

Structure
--
The conference will last for 3 days with 3 parallel tracks of
presentations. Presentations will be given in either Hebrew or English,
depending on the speaker's preference (the language will be listed in
advance).

Call for Papers

Recommended Topics for Python Related Presentations:

* Python based web  content-management technology (e.g. Zope)
* Major or Interesting packages (e.g. Twisted)
* Language development and new implementations (e.g. PyPy)
* Interfacing other languages (e.g. boost-python)

 The examples given above are suitable for long presentations or
tutorials, but we also accept 40 and 20 minutes presentations, and 5
minute lightning talks.
 Any other topics which are interesting and relevant to Open Source
Developers are also welcome.

 For submitting proposals:  http://www.osdc.org.il/proposal.html

For updates and more details:

  http://www.osdc.org.il/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
Fuzzyman wrote:

 [snip..]
  (as an example, on my machine, using Foord's OrderedDict class
  on Zwerschke's example, creating the dictionary in the first place
  takes 5 times longer than the index approach, and accessing an
  item takes 3 times longer.  you can in fact recreate the index 6
  times before OrderedDict is faster; if you keep the index around,
  the OrderedDict approach never wins...)

 So, so long as you want to use the dictionary less than six times -
 it's faster to store/access it as a list of tuples. ;-)

nope.  that's not what I said.  I said that you can recreate the index
six times in the time it takes to create a single OrderedDict instance.
if you need to use index more than that, it's not that hard to keep a
reference to it.

 Everytime you want to access (or assign to) the data structure as a
 dictionary, you have to re-create the index.

the use case we're talking about here (field descriptors) doesn't involve
assigning to the data structure, once it's created.

I'll repeat this one last time: for the use cases presented by Zwerschke
and bonono, using a list as the master data structure, and creating the
dictionary on demand, is a lot faster than using a ready-made ordered
dict implementation.  if you will access things via the dictionary a lot,
you can cache the dictionary somewhere.  if not, you can recreate it
several times and still get a net win.

for other use cases, things may be different, but nobody has presented
such a use case yet.  as I said earlier, let's assume we have another use
case is not a valid use case.

/F



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


Re: Numeric array in unittest problem

2005-11-21 Thread Robert Kern
[EMAIL PROTECTED] wrote:
 hello,
 
 I found that if I use Numeric.array into unittest it is not
 consistance,
 Is that normal ?
 
 import Numeric
 class myTest(unittest.TestCase):
 def runTest(self):
 a = Numeric.array([1,2])
 b = Numeric.array([1,33])
 self.assertEqual(a, b)
 pass
 
 
 This will not raise any error ???
 
 Any idea?

unittest.TestCase.assertEqual() uses == to compare a and b. Numeric
arrays have rich comparisons and so return arrays, not booleans. Try it
in the interpreter. To get a boolean from a==b, use Numeric.alltrue(a==b).

-- 
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


Re: Numeric array in unittest problem

2005-11-21 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Sorry Peter,
 
 Try this
 
 import unittest
 import Numeric
 
 class myTest(unittest.TestCase):
 def runTest(self):
 var1 = Numeric.array([1,22])
 var2 = Numeric.array([1,33])
 self.assertEqual(var1,var2)
 
 if __name__ == '__main__':
 unittest.main()

Try this interactively and you'll see why:

 import Numeric
 a=Numeric.array([1,22])
 b=Numeric.array([1,33])
 c = a==b
 c
array([1, 0])
 assert(c)

i.e., thanks to element-by-element evaluation, == will generally return
a true value for ANY comparison of Numeric arrays, causing a very
frequent beginner's bug to be sure.  Try Numeric.alltrue(c), or
Numeric.allclose(a,b) ...


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


RE: Any college offering Python short term course?

2005-11-21 Thread bruce
hey...

i'm looking for classes (advanced) in python/php in the bay area as well...
actually i'm looking for the students/teachers/profs of these classes... any
idea as to how to find them. calling the various schools hasn't really been
that helpful. The schools/institutions haven't had a good/large selection...
it appears that some of the classes are taught by adjunct/part-time faculty,
and they're not that easy to get to...

if anybody knows of user-groups that also have this kind of talent, i'd
appreciate it as well...

send responses to the list as well!!!

thanks

-bruce


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of arches73
Sent: Sunday, November 20, 2005 4:04 PM
To: python-list@python.org
Subject: Any college offering Python short term course?


Hi,

I want to learn Python.  I appreciate if someone point me to the
colleges / institutions offering any type of course in Python
programming in the Bay area CA. Please send me the links to my email.

Thanks,
Arches



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

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


Re: sort the list

2005-11-21 Thread Duncan Booth
Daniel Schüle wrote:

 I can offer you some more brain food to digest ;)
 maybe you can adapt this solution, but that depends
 on your problem
 I find it clear and I used it recently
 
  name, age, salary = name, age, salary
  people = [
 ... {name:oliver, age:25, salary:1800},
 ... {name:mischa, age:23, salary:0},
 ... {name:peter, age:22, salary:1500},
 ... ]
 
  def cmpFabrik(field):
 ... def cmpFunc(x,y):
 ... return cmp(x[field], y[field])
 ... return cmpFunc
  people.sort(cmp = cmpFabrik(name))
  people.sort(cmp = cmpFabrik(age))
  people.sort(cmp = cmpFabrik(salary))
 
 it's not very OO but sometimes things are simple
 and no need to create a class

I thought you said you were using Python 2.4, so why didn't you just do 
this?:

 from operator import itemgetter
 people.sort(key=itemgetter('name'))
 people.sort(key=itemgetter('age'))
 people.sort(key=itemgetter('salary'))

and if you want to sort on multiple keys, this could be useful:

 def multikey(*args):
def makekey(v):
return tuple(a(v) for a in args)
return makekey

 people.sort(key=multikey(itemgetter('age'), itemgetter('name')))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Christoph Zwerschke
Ben Finney wrote:

  Another possibility: ordered dictionaries are not needed when Python
  2.4 has the 'sorted' builtin.

Christoph Zwerschke wrote:

  The 'sorted' function does not help in the case I have indicated,
  where I do not want the keys to be sorted alphabetically, but
  according to some criteria which cannot be derived from the keys
  themselves.

Mike Meyer wrote:

  And how would an ordered dictionary help in this case?

Maybe there is some confusion between an orderable and an ordered 
dictionary. When I talk about ordered dictionary, then in the simplest 
case I just set up my ordered dictionary with my preferred key order and 
it stays like that. This allows me to later iterate through the 
dictionary in this preferred order, while being still able to randomly 
access data from the dictionary at other places.

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Christoph Zwerschke
Fredrik Lundh wrote:
 (as an example, on my machine, using Foord's OrderedDict class
 on Zwerschke's example, creating the dictionary in the first place
 takes 5 times longer than the index approach, and accessing an
 item takes 3 times longer.  you can in fact recreate the index 6
 times before OrderedDict is faster; if you keep the index around,
 the OrderedDict approach never wins...)

You're right; I found creating a Larosa/Foord OrderedDict in this 
example to be even 8 times slower than an ordinary dict. However, two 
things need to be said here: 1) The dictionary in my exmaple was pretty 
small (only 3 items), so you are not really measuring the performance of 
the ordered dict, but mainly the overhead of using a user derived class 
in comparison with the built-in dict type. And 2) the implementation by 
Larosa/Foord is very slow and can be easily improved, for instance like 
that:

def __init__(self, init_val = ()):
 dict.__init__(self, init_val)
 self.sequence = [x[0] for x in init_val]

With this change, creating the ordered dictionary is considerably faster 
and for an average size dictionary, the factor of 8 pretty quickly 
converges against 1.

But of course, it will always be slower since it is constructed on top 
of the built-in dict. In end effect, you always have to maintain a 
sequence *plus* a dictionary, which will be always slower than a sheer 
dictionary. The ordered dictionary class just hides this uglyness of 
having to maintain a dictionary plus a sequence, so it's rather an issue 
of convenience in writing and reading programs than a performance issue.

It may be different if the ordered dict would be implemented directly as 
an ordered hash table in C.

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


Re: Immutable instances, constant values

2005-11-21 Thread George Sakkis
Steven D'Aprano wrote:

 Yes, that would be how I interpret constants: You want a name which can't
 be re-bound to something else.

 One work-around is to use the convention of writing the name in all caps:

 CONSTANT = some_value

 and then trust that your module user doesn't rebind CONSTANT. I'd like to
 see support for something a little stronger than just cross your fingers
 and hope, without necessarily going all the way to Pascal's full
 enforcement of constants. We're all adults here -- if somebody *really*
 wants to rebind CONSTANT, I'm not going to stop them, but I want them to
 jump through a hoop to do it, as a reminder that the module creator thinks
 they shouldn't be doing it.

Another workaround if you tradeoff strictness with convenience is
define a CONST  metaclass in which contants are accessed as attributes
and which raises an Exception in __setattr__:

class CONST(type):
def  __new__(cls, name, bases, dict):
def __setattr__(self,attr,val):
raise AttributeError('Cannot reassign constant %s.%s'
 % (name, attr))
cls.__setattr__ = __setattr__
return type.__new__(cls, name, bases, dict)


class PhysicsConstants(object):
__metaclass__ = CONST
c = 2.9979246e+08


 PhysicsConstants.c = 0
AttributeError: Cannot reassign constant PhysicsConstants.c


George

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Alex Martelli
Fredrik Lundh [EMAIL PROTECTED] wrote:
   ...
 (but assume that I have some other use case isn't a valid use
 case)

+1 QOTW


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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Christoph Zwerschke
Alex Martelli wrote:

 Note the plural in 'insertion orderS': some people care about the FIRST
 time a key was added to a dict, some about the LAST time it was added,
 some about the latest time it was 'first inserted' (added and wasn't
 already there) as long as it's never been deleted since that occasion --
 and these are just a few of the multifarious orders based on the time of
 insertions and deletions of keys.

Ok, I start to understand that ambiguity emerges when you delete and 
insert items. I didn't think much about this problem because  my use 
cases usually do not involve inserttion or deletion after the ordered 
dictionary has been created.

But I think the following rule is natural enough to consider it as THE 
standard behavior of ordered dictionaries:

Insertion: If the key exists: Don't change the order. If it does not 
exist: Append it to the sequence of keys. Deletion: Remove from the 
sequence of keys.

I think this is also the behavior of associative arrays in PHP or Perl 
and could be considered as the ONE unambiguous definition.

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


Re: best cumulative sum

2005-11-21 Thread Colin J. Williams
David Isaac wrote:
 [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
He seems to want scanl
 
 
 Yes.  But it's not in Python, right?
 (I know about Keller's version.)
 
 Robert Kern wrote:
 
Define better. More accurate? Less code?
 
 
 Good point.
 As Bonono (?) suggested: I'd most like a solution that
 relies on a built-in to give me both of those.
 (Pretty is good too.)  Like SciPy's cumsum.
 
 Thanks,
 Alan Isaac
 
 
Doesn't numarray handle this?

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


Re: about sort and dictionary

2005-11-21 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 most built-in function/method don't return the object but None. This
 I believe is the language creator's preference for everything being
 explicit. 

The list methods .sort() and .reverse() don't create copies,
but rather change the existing object. The reson for this is
to save RAM. If you have 512MB RAM and a 300 MB list, it's
nice that you can sort it without swapping virtual memory to
disk. That would slow down the sort operation a lot, and that
would be a shame, considering all the efforts that went into
Python's excellent sort implementation.

If you sort (or reverse) a list l, and don't need to keep the
unsorted list, you simply do l.sort() (or l.reverse()). If
you need to keep the original as well, you must make a copy
before the sort, like this: sorted_l = l[:]; sorted_l.sort().

If the sort operation had returned self, it would have been
easy to write:

sorted_l = l.sort()

and while sorted_l would contain what one might expect, it
would in fact just be another name referencing exactly the
same sorted list as l, and it would probably be surprising
that l was also sorted, and that subsequent changes would
show up in both sorted_l and l, and that sorted_l might not
be sorted and longer even though you only modified l. It's
this particular gotcha that the language creator wanted to
avoid.

With newer versions of Python, the builtin functions sorted()
and reversed() have been added, so those who think it's ugly
to call a list sorted before it actually *is* sorted, can
simply write:

sorted_l = sorted(l)

With older Python's you need to do the hard work to add this
to your program:

def sorted(l): s=l[:];s.sort();return s
def reversed(l): r=l[:];r.reverse();return r

Actually, I guess it's possible that sorted() is done so
that it works like below, but I don't think pre-sorted()
versions of Python support keyword arguments to list.sort()
anyway...

def sorted(l, *p, **kw): s=l[:];s.sort(*p, **kw);return s
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about sort and dictionary

2005-11-21 Thread George Sakkis
Shi Mu wrote:

 Got confused by the following code:
  a
[6, 3, 1]
  b
[4, 3, 1]
  c

 {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]}
  c[2].append(b.sort())
  c

 {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]}
 #why c can not append the sorted b??


In python 2.4, you can use the sorted() builtin instead:

c[2].append(sorted(b))

George

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


Re: about sort and dictionary

2005-11-21 Thread George Sakkis
Shi Mu wrote:

 Got confused by the following code:
  a
[6, 3, 1]
  b
[4, 3, 1]
  c

 {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]}
  c[2].append(b.sort())
  c

 {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]}
 #why c can not append the sorted b??


In python 2.4, you can use the sorted() builtin instead:

c[2].append(sorted(b))

George

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Aahz
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:

I think you're wrong here.  People in the past who have requested or
implemented stuff they called 'ordered dicts' in the past had in mind
drastically different things, based on some combination of insertion
orders, keys, and _values_.  So, ambiguity is definitely present in the
phrase 'ordered dictionary', because there are so many different
criteria whereby the 'ordering' could take place.

Note the plural in 'insertion orderS': some people care about the FIRST
time a key was added to a dict, some about the LAST time it was added,
some about the latest time it was 'first inserted' (added and wasn't
already there) as long as it's never been deleted since that occasion --
and these are just a few of the multifarious orders based on the time of
insertions and deletions of keys.  

Ayup.  In our application, not only do we have ordered dicts, we also
have something called a sectioned dict, which is a dict-like object
that also looks like a regular class instance with attribute access.  The
section part actually has multiple dicts (the sections) which are
layered, so that a dict key in the top layer overrides the value of the
key in lower layers.  We traditionally have used it such that the
sections are accessed in MRU orders; last week, we added a new feature
that allows setting section values without changing section order (to
allow setting a default, essentially).
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numeric array in unittest problem

2005-11-21 Thread Robert Kern
Alex Martelli wrote:

import Numeric
a=Numeric.array([1,22])
b=Numeric.array([1,33])
c = a==b
c
 
 array([1, 0])
 
assert(c)
 
 i.e., thanks to element-by-element evaluation, == will generally return
 a true value for ANY comparison of Numeric arrays, causing a very
 frequent beginner's bug to be sure.

Indeed. This is why numarray and scipy_core have made arrays raise an
exception when someone tries to use them as truth values.

-- 
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


Advice on distutils and distribution policies

2005-11-21 Thread Mardy
Hi,
  I've built a small project (http://eligante.sf.net) which I'm actually
trying to package using distutils.
The directory structure is going to be like this:

eligante/
eligante.py
sitobase.py
personas.py
[...other python files...]
modulos/
mbox.py
gaim.py
[...other python files...]
web/
indice.py
cerca.py
[...other python files...]
stylo.css
testata.html
[and maybe, in the future, other HTML files]

The python files in the eligante/web directory are intended to be called
by a webserver (now Apache, but soon I'll switch to the python
module CGIHTTPServer for simplicity) as CGIs. Currently, these CGIs read
the testata.html file and use it as the beginning of their output, while
the style.css is served by the HTTP server.

However, I don't know if this directory layout is suitable for
site-packages, since at a first glance it looks to me that datafiles might
not be welcome under it. Is it so?
In that case, where should I move the .html files, and how should I access
them from inside python?

If, on the other hand, this layout is OK for site-packages, how do I
instruct distutils to put the .html and .css files under the eligante/web
directory?

Sorry for the long post, and thanks in advance for any help or suggestion.


-- 
Saluti,
Mardy
http://interlingua.altervista.org

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


ignore specific data

2005-11-21 Thread pkilambi
Hi I need help. What I want to do is If I read a file with some text
content...
I would like to ignore a block of lines and consider the rest..
so if the block starts with

start of block.
fjesdgsdhfgdlgjklfjdgkd
jhcsdfskdlgjkljgkfdjkgj
end of block

I want to ignore this while processing the file .This block could
appear anywhere in the file.It could at the start or end or even middle
of file content.

Hope I'm clear...

somethin like

f = open(file)
clean_data = ignore_block(f)

here ignore_data should filter the block

def ignore_data(f):
   .
   return data # may be an array of remaining lines...

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


Re: Numeric array in unittest problem

2005-11-21 Thread Roman Bertle
* Alex Martelli [EMAIL PROTECTED]:
  [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
  Sorry Peter,
  
  Try this
  
  import unittest
  import Numeric
  
  class myTest(unittest.TestCase):
  def runTest(self):
  var1 = Numeric.array([1,22])
  var2 = Numeric.array([1,33])
  self.assertEqual(var1,var2)
  
  if __name__ == '__main__':
  unittest.main()
 
 
  i.e., thanks to element-by-element evaluation, == will generally return
  a true value for ANY comparison of Numeric arrays, causing a very
  frequent beginner's bug to be sure.  Try Numeric.alltrue(c), or
  Numeric.allclose(a,b) ...

I extend unittest.TestCase as follows (uses numarray, not Numeric):


class NumTestCase(unittest.TestCase):

Extends TestCase with equality tests for numarrays.


def numAssertEqual(self, a1, a2):
Test for equality of numarray fields a1 and a2.

self.assertEqual(a1.shape, a2.shape)
self.assertEqual(a1.type(), a2.type())
self.assertTrue(N.alltrue(N.equal(a1.flat, a2.flat)))

def numAssertAlmostEqual(self, a1, a2):
Test for approximately equality of numarray fields a1 and a2.

self.assertEqual(a1.shape, a2.shape)
self.assertEqual(a1.type(), a2.type())
if a1.type() == 'Float64' or a1.type() == 'Complex64':
prec = 15
else:
prec = 7
if isinstance(a1.type(), N.ComplexType):
af1, af2 = a1.flat.real, a2.flat.real
for ind in xrange(af1.nelements()):
self.assertAlmostEqual(af1[ind], af2[ind], prec)
af1, af2 = a1.flat.imag, a2.flat.imag
for ind in xrange(af1.nelements()):
self.assertAlmostEqual(af1[ind], af2[ind], prec)
else:
af1, af2 = a1.flat, a2.flat
for ind in xrange(af1.nelements()):
self.assertAlmostEqual(af1[ind], af2[ind], prec)

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


the name of a module in which an instance is created?

2005-11-21 Thread Steven Bethard
The setup: I'm working within a framework (designed by someone else) 
that requires a number of module globals to be set.  In most cases, my 
modules look like:
(1) a class definition
(2) the creation of one instance of that class
(3) binding of the instance methods to the appropriate module globals

I'm trying to hide the complexity of step (3) by putting it in a common 
base class.  That way, when I'm writing a new module, I never have to 
see the step (3) code.  Right now, that code is in the __init__ method 
of the common base class and looks something like::

 setattr(mod, 'creole_%s' % name, self._call)
 setattr(mod, 'creole_%s_Initialize' % name, self._initialize)
 setattr(mod, 'creole_%s_Finish' % name, self._finish)

where 'mod' is the module and 'name' is the name of the module.

In the basic situation, where the instance is created in the same module 
as the class, I can figure out 'mod' and 'name' like::

 cls = type(self)
 name = cls.__module__
 mod = __import__(cls.__module__)

However, this fails whenever the instance is not created in the same 
module as the class was defined (e.g. when I've factored a common base 
class into another module, and only imported this class to do steps (2) 
and (3)).  How can I figure out 'name' if the class was created in a 
different module?

One option, of course, is to pass it explicitly, e.g.::

 import C
 instance = C(__name__, ...)

This isn't a horrible option, but it does mean that I'm not hiding all 
of the step (3) machinery anymore

Another option would be to declare a dummy class, e.g.::

 import C
 class Dummy(C):
 pass
 instance = Dummy(...)

Again, this isn't horrible, but it also fails to hide some of the step 
(3) machinery.

Any other possibilities?

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


Re: ignore specific data

2005-11-21 Thread skip

pkilambi I would like to ignore a block of lines and consider the
pkilambi rest..  so if the block starts with

pkilambi start of block.
pkilambi fjesdgsdhfgdlgjklfjdgkd
pkilambi jhcsdfskdlgjkljgkfdjkgj
pkilambi end of block

pkilambi I want to ignore this while processing the file .This block
pkilambi could appear anywhere in the file.It could at the start or end
pkilambi or even middle of file content.

How about (untested):

class FilterBlock:
def __init__(self, f, start, end):
self.f = f
self.start = start
self.end = end

def __iter__(self):
return self

def next(self):
line = self.f.next()
if line == self.start:
line = self.f.next()
while line != self.end:
line = self.f.next()
return line

Then use it like

filterfile = FilterBlock(open(somefile, r),
 start of block..,
 end of block)

for line in filterfile:
process(line)

I'm not sure what you mean by all the dots in your start of block line.  If
start of block can be followed by other text, just use 

if line.startswith(self.start):

instead of an exact comparison.

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


Re: Aproximative string matching

2005-11-21 Thread Diez B. Roggisch
Steven D'Aprano wrote:
 [EMAIL PROTECTED] wrote:
 
 This algorithm is called soundex. Here is one implementation example.

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52213

 here is another:
 http://effbot.org/librarybook/soundex.htm
 
 
 Soundex is *one* particular algorithm for approximate string matching. 
 It is optimised for matching Anglo-American names (like Smith/Smythe), 
 and is considered to be quite old and obsolete for all but the most 
 trivial applications -- or so I'm told.
 
 Soundex will not match arbitrary changes -- it will match both cat and 
 cet, but it won't match cat and mat.
 
 A more sophisticated approximate string matching algorithm will use the 
 Levenshtein distance. You can find a Useless implementation here:
 
 http://www.uselesspython.com/download.php?script_id=108
 
 
 Given a function levenshtein(s1, s2) that returns the distance between 
 two strings, you could use it for approximate matching like this:
 
 def approx_matching(strlist, target, dist=1):
 Matches approximately strings in strlist to
 a target string.
 
 Returns a list of strings, where each string
 matched is no further than an edit distance of
 dist from the target.
 
 found = []
 for s in strlist:
 if levenshtein(s, target) = dist:
 found.append(s)
 return s

I compute a relative metric based on th every same implementation like this:

def relative(a, b):
 
 Computes a relative distance between two strings. Its in the range
 (0-1] where 1 means total equality.
 @type a: string
 @param a: arg one
 @type b: string
 @param b: arg two
 @rtype: float
 @return: the distance
 
 d = levensthein(a,b)
 longer = float(max((len(a), len(b
 shorter = float(min((len(a), len(b
 r = ((longer - d) / longer) * (shorter / longer)
 return r


The idea is that otherwise e.g. cat and hippopothamus have a 
l-distance of only 3, which one would consider good at the first look.


Regards,

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


Re: Any royal road to Bezier curves...?

2005-11-21 Thread Tom Anderson
On Sun, 20 Nov 2005, Warren Francis wrote:

 Basically, I'd like to specify a curved path of an object through space. 
 3D space would be wonderful, but I could jimmy-rig something if I could 
 just get 2D...  Are bezier curves really what I want after all?

No. You want a natural cubic spline:

http://mathworld.wolfram.com/CubicSpline.html

This is a fairly simple curve, which can be fitted through a series of 
points (called knots) in space of any dimensionality, without the need to 
specify extra control points (unlike a Bezier curve), and which has the 
nice property of minimising the curvature of the curve - it's the shape 
you'd get if you ran a springy wire through your knots. It usually looks 
pretty good too.

Google will help you find python implementations.

There are other kinds of splines - Catmull-Rom, B-spline (a generalisation 
of a Bezier curve), Hermite - but they mostly don't guarantee to pass 
through the knots, which might make them less useful to you.

In the opposite direction on the mathematical rigour scale, there's what i 
call the blended quadratic spline, which i invented as a simpler and more 
malleable alternative to the cubic spline. It's a piecewise parametric 
spline, like the cubic, but rather than calculating a series of pieces 
which blend together naturally, using cubics and linear algebra, it uses 
simple quadratic curves fitted to overlapping triples of adjacent knots, 
then interpolates ('blends') between them to draw the curve. It looks very 
like a cubic spline, but the code is simpler, and the pieces are local - 
each piece depends only on nearby knots, rather than on all the knots, as 
in a cubic spline - which is a useful property for some jobs. Also, it's 
straightforward to add the ability to constrain the angle at which the 
curve passes through a subset of the knots (you can do it for some knots, 
while leaving others 'natural') by promoting the pieces to cubics at the 
constrained knots and constraining the appropriate derivatives. Let me 
know if you want more details on this. To be honest, i'd suggest using a 
proper cubic spline, unless you have specific problems with it.

tom

-- 
... a tale for which the world is not yet prepared
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Tom Anderson
On Sun, 20 Nov 2005, Alex Martelli wrote:

 Christoph Zwerschke [EMAIL PROTECTED] wrote:

 The 'sorted' function does not help in the case I have indicated, where 
 I do not want the keys to be sorted alphabetically, but according to 
 some criteria which cannot be derived from the keys themselves.

 Ah, but WHAT 'some criteria'?  There's the rub!  First insertion, last 
 insertion, last insertion that wasn't subsequently deleted, last 
 insertion that didn't change the corresponding value, or...???

All the requests for an ordered dictionary that i've seen on this group, 
and all the cases where i've needed on myself, want one which behaves like 
a list - order of first insertion, with no memory after deletion. Like the 
Larosa-Foord ordered dict.

Incidentally, can we call that the Larosa-Foord ordered mapping? Then it 
sounds like some kind of rocket science discrete mathematics stuff, which 
(a) is cool and (b) will make Perl programmers feel even more inadequate 
when faced with the towering intellectual might of Python. Them and their 
Scwartzian transform. Bah!

tom

-- 
Baby got a masterplan. A foolproof masterplan.
-- 
http://mail.python.org/mailman/listinfo/python-list


compiling Python under Windows

2005-11-21 Thread Philippe C. Martin
Hi,

I'm currently blocking on bzip2:

python is in c:\python.2.4.2
and bz2 is in c:\bzip2-1.0.3

Since the readme say subprojects should be two directories above PCbuild, I
assume I'm OK.

I added c:\bzip2-1.0.3 to the include and link path, but I get:

Performing Pre-Link Event ...
The system cannot find the path specified
NMAKE: fatal error U1052: file 'makefile.msc' not found

c:\bzip2-1.0.3 does hold a makefile.msc.

Any clue ?

Thanks,

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


Re: compiling Python under Windows

2005-11-21 Thread Philippe C. Martin
My mistake: The makefile (as written in the readme!) looks for bzip 1.0.2

Sorry,

Philippe



Philippe C. Martin wrote:

 Hi,
 
 I'm currently blocking on bzip2:
 
 python is in c:\python.2.4.2
 and bz2 is in c:\bzip2-1.0.3
 
 Since the readme say subprojects should be two directories above PCbuild,
 I assume I'm OK.
 
 I added c:\bzip2-1.0.3 to the include and link path, but I get:
 
 Performing Pre-Link Event ...
 The system cannot find the path specified
 NMAKE: fatal error U1052: file 'makefile.msc' not found
 
 c:\bzip2-1.0.3 does hold a makefile.msc.
 
 Any clue ?
 
 Thanks,
 
 Philippe

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


Re: Underscores in Python numbers

2005-11-21 Thread Eric Jacoboni
[EMAIL PROTECTED] (Bengt Richter) writes:

Eric Jacoboni, ne il y a 1435938104 secondes
 Um, about your sig ... ;-)

Well, i confess it's Ruby code... Maybe, one day, i will try to write
a Python Version (with DateTime, i guess?) but i'm afraid it doesn't
change the result.
-- 
Eric Jacoboni, ne il y a 1436041406 secondes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiling Python under Windows

2005-11-21 Thread Philippe C. Martin
Philippe C. Martin wrote:

 My mistake: The makefile (as written in the readme!) looks for bzip 1.0.2
 
PS: since bzip.org does not have 1.0.2 source anymore, can I just rename
1.0.3 ?

Regards,

Philippe


 Sorry,
 
 Philippe
 
 
 
 Philippe C. Martin wrote:
 
 Hi,
 
 I'm currently blocking on bzip2:
 
 python is in c:\python.2.4.2
 and bz2 is in c:\bzip2-1.0.3
 
 Since the readme say subprojects should be two directories above PCbuild,
 I assume I'm OK.
 
 I added c:\bzip2-1.0.3 to the include and link path, but I get:
 
 Performing Pre-Link Event ...
 The system cannot find the path specified
 NMAKE: fatal error U1052: file 'makefile.msc' not found
 
 c:\bzip2-1.0.3 does hold a makefile.msc.
 
 Any clue ?
 
 Thanks,
 
 Philippe

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


Re: ignore specific data

2005-11-21 Thread Mike Meyer
[EMAIL PROTECTED] writes:
 Hi I need help. What I want to do is If I read a file with some text
 content...
 I would like to ignore a block of lines and consider the rest..
 so if the block starts with

 start of block.
 fjesdgsdhfgdlgjklfjdgkd
 jhcsdfskdlgjkljgkfdjkgj
 end of block

 I want to ignore this while processing the file .This block could
 appear anywhere in the file.It could at the start or end or even middle
 of file content.

The best way depends on how you're going to use the data. For
instance, if you're going to be processing line at a time, you might
consider writing an interator:

# Untested code:

def filter(rawfile):
for line in rawfile:
if line == start of block..:
   break
yield line
for line in rawfile:
if line == end of block:
   break
for line in rawfile:
yield line

Then you use it like:

myfile = open(...)
for line in filter(myfile):
process(line)

This is a straightforward translation of your description, and avoids
loading the entire file into memory at once. You might be able to cons
up something more efficient from itertools.

   mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best cumulative sum

2005-11-21 Thread David Isaac

 Alan Isaac wrote:
 Like SciPy's cumsum.


Colin J. Williams [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Doesn't numarray handle this?

Sure.
One might say that numarray is in the process of becoming scipy.
But I was looking for a solution when these are available.
Something like:
def cumreduce(func, seq, init = None):
Return list of cumulative reductions.

Example use:
 cumreduce(operator.mul, range(1,5),init=1)
[1, 2, 6, 24]


:author: Alan Isaac
:license: public domain

if not seq:
cr = [init]*bool(init)
else:
cr = [seq[0]] * len(seq)
if init:
cr[0] = func(cr[0],init)
for idx in range(1,len(seq)):
cr[idx] = func(cr[idx-1],seq[idx])
return cr


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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Kay Schluehr
Fredrik Lundh wrote:

 huh?  if you want a list, use a list.

 d = [('a', {...}), ('b', {})]

If one wants uniform access to a nested data structure like this one
usually starts writing a wrapper class. I do not think the requirement
is anyhow deeper than a standard wrapper around such a list ( as a
model ) but the implementation may be different with respect to optimal
time complexitiy of element access. But the interface of the wrapper
class of d might resemble that of a dict. While the interface is that
of a dict the implementation is closer to a nested list. An ordered
dict would lower the impedance between a dict and a list. 

Kay

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


Help in File selector window in pygtk

2005-11-21 Thread Thierry Lam
Let's say I have a main window which has a File menu. When I click on
the File menu and the open button, I have a File selector window which
comes in front of my main window.  How do I make the main window
unselectable?

Thanks
Thierry

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


Re: ignore specific data

2005-11-21 Thread pkilambi
thanks for that. But this will check for the exact content of the
start of block.. or end of block. How about if the content is
anywhere in the line?

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


  1   2   >