Re: Pulling numbers from ASCII filename not working

2006-01-25 Thread Bengt Richter
On 24 Jan 2006 10:44:32 -0800, "IamIan" <[EMAIL PROTECTED]> wrote: >I searched the archives but couldn't find anyone else with this >problem. Basically I'm grabbing all ASCII files in a directory and >doing geoprocessing on them. I need to calculate a z-factor based on >the latitude of the ASCII f

Re: Possible memory leak?

2006-01-25 Thread Giovanni Bajo
Steven D'Aprano wrote: > But the real killer is this one line: > > row=row+chr(num/64) > > Bad, bad BAD idea. Every time you add two strings together, Python > has to copy BOTH strings. As row gets huge, this takes longer and > longer to do. This is no longer true as of CPython 2.4 though. I'm no

Re: list comprehention

2006-01-25 Thread Mathijs
23 jan 2006 ta (Steven D'Aprano) shuo le: >> This is the type of solution I was hoping to see: one-liners, with no >> use of local variables. > > Because you like unreadable, incomprehensible, unmaintainable code? For practical use: no! But I'm just learning python and to understand sets/lists/

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote: > i put this together to fix a bunch of files with wierd names, please > gimme feedback, i am a newbie Others have already made comments, here is some more food for thought. You should consider factoring out some repeated code into functions. E.g.: # warning: untested

Re: file_name_fixer.py

2006-01-25 Thread Fredrik Lundh
Steven D'Aprano wrote: > You should consider factoring out some repeated code > into functions. E.g.: > > # warning: untested!!! > def replace_all(s, old, new): > """Replaces all instances of substring old with > substring new.""" > if old == new: > # make no changes >

What's wrong?

2006-01-25 Thread kishkin
Hello everyone! I wanted to write python script with defined function. From that script I wanted to call C module, which in it's turn call defined python function. Sounds simple. But I've got some troubles in realization. I'm beginner at python so it's normal, I think. :) Here's the code. I'll ap

Re: Possible memory leak?

2006-01-25 Thread Steven D'Aprano
Giovanni Bajo wrote: > Steven D'Aprano wrote: > > >>But the real killer is this one line: >> >>row=row+chr(num/64) >> >>Bad, bad BAD idea. Every time you add two strings together, Python >>has to copy BOTH strings. As row gets huge, this takes longer and >>longer to do. > > > This is no longer

Re: What's wrong?

2006-01-25 Thread Steven D'Aprano
kishkin wrote: > Hello everyone! > > I wanted to write python script with defined function. From that script > I wanted to call C module, which in it's turn call defined python > function. Sounds simple. But I've got some troubles in realization. I'm > beginner at python so it's normal, I think.

Re: What's wrong?

2006-01-25 Thread Fredrik Lundh
"kishkin" <[EMAIL PROTECTED]> wrote: > I wanted to write python script with defined function. From that script > I wanted to call C module, which in it's turn call defined python > function. Sounds simple. But I've got some troubles in realization. I'm > beginner at python so it's normal, I think.

Re: Oddities of Tkinter

2006-01-25 Thread Eric Brunel
On 24 Jan 2006 12:37:01 -0800, Tuvas <[EMAIL PROTECTED]> wrote: > I thought I mentioned that I'm running in linux, and yes, there are > threads involved. I just don't know why on one machine that it would > run so differently than another. The only secure way I found to make Tkinter mix with threa

Re: What's wrong?

2006-01-25 Thread kishkin
:)) Oа course it PyCallable_Check there!!! :)) And error is that PyCallable_Check returned 0. power.c compiles without errors. error is here: --- [EMAIL PROTECTED] 1]$ make -f makefile.power gcc power.c -g -I/usr/local/include/python2.4 -fpic -shared -o power.so [

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
Fredrik Lundh wrote: > or you can use a more well-suited function: > > # replace runs of _ and . with a single character > newname = re.sub("_+", "_", newname) > newname = re.sub("\.+", ".", newname) You know, I really must sit down and learn how to use reg exes one of these days. B

Re: What's wrong?

2006-01-25 Thread kishkin
Thank you for fast response! And I'm sorry for bad style of asking questions! -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-25 Thread Steven D'Aprano
Replying to myself... the first step towards perdition... Steven D'Aprano wrote: > We really don't know what the optimization recognises, how it works, or > how fast a difference it makes. Of course, by "we" I mean "those of us who haven't seen and understood the CPython source code, or run de

Re: Possible memory leak?

2006-01-25 Thread Fredrik Lundh
Steven D'Aprano wrote: > > Steven D'Aprano wrote: > > > > > >>But the real killer is this one line: > >> > >>row=row+chr(num/64) > >> > >>Bad, bad BAD idea. Every time you add two strings together, Python > >>has to copy BOTH strings. As row gets huge, this takes longer and > >>longer to do. > > >

Mining strings from a HTML document.

2006-01-25 Thread Derick van Niekerk
Hi, I am new to Python and have been doing most of my work with PHP until now. I find Python to be *much* nicer for the development of local apps (running on my machine) but I am very new to the Python way of thinking and I don't realy know where to start other than just by doing it...so far I'm j

Re: What's wrong?

2006-01-25 Thread Fredrik Lundh
"kishkin" wrote: > Thank you for fast response! And I'm sorry for bad style of asking > questions! did you (with the help of your compiler) figure out what was wrong? -- http://mail.python.org/mailman/listinfo/python-list

Re: Oddities of Tkinter

2006-01-25 Thread tooper
Tuvas, I fully agree with Eric's post above. You may additionnaly have to kill the main window before exit, to avoid a nasty thread related error message and occasionally some zombie procs: import Tkinter,atexit top=Tkinter.Tk() .../... atexit.register(lambda top=top: top.destroy()) top.mainloop(

Re: file_name_fixer.py

2006-01-25 Thread Fredrik Lundh
Steven D'Aprano wrote: > > or you can use a more well-suited function: > > > > # replace runs of _ and . with a single character > > newname = re.sub("_+", "_", newname) > > newname = re.sub("\.+", ".", newname) > > You know, I really must sit down and learn how to use > reg exes one o

Re: What's wrong?

2006-01-25 Thread Fredrik Lundh
"kishkin" wrote: > :)) O? course it PyCallable_Check there!!! :)) And error is that > PyCallable_Check returned 0. > > power.c compiles without errors. > > error is here: > --- > [EMAIL PROTECTED] 1]$ make -f makefile.power > gcc power.c -g -I/usr/local/include/pyt

Re: customized instance dictionaries, anyone?

2006-01-25 Thread Bengt Richter
On 24 Jan 2006 09:30:00 -0800, [EMAIL PROTECTED] wrote: >some time after posting my `Linkdict recipe`__ to aspn__ >-- basically, a dictionary with run-time delegational >lookup, but this is not important here -- i thought gee >that would be fun to make such a customized dictionary >thingie an inst

writing arrays to binary file

2006-01-25 Thread Sheldon
Hi everyone, I have a short program the writes the output data to an acsii file: import sys import os import string import gisdata from Numeric import * def latlon(area_id, i, j): lon_file = "lon_%s.dat" % area_id flon= open(lon_file, 'wa') lat_file = "lat_%s.dat" % area_id

Re: writing arrays to binary file

2006-01-25 Thread Fredrik Lundh
Sheldon wrote: > I have a short program the writes the output data to an acsii file: > > import sys > import os > import string > import gisdata > from Numeric import * > > def latlon(area_id, i, j): > lon_file = "lon_%s.dat" % area_id > flon= open(lon_file, 'wa') > lat_file

Re: writing arrays to binary file

2006-01-25 Thread Travis E. Oliphant
Sheldon wrote: > Hi everyone, > > I have a short program the writes the output data to an acsii file: > > import sys > import os > import string > import gisdata > from Numeric import * > > def latlon(area_id, i, j): > lon_file = "lon_%s.dat" % area_id > flon= open(lon_file, 'wa'

Re: What's wrong?

2006-01-25 Thread kishkin
Man! It's alive! :) Now next question: where are you living? I must know that for buy you some beer!! Thanks a lot!!! -- http://mail.python.org/mailman/listinfo/python-list

Re: Python code written in 1998, how to improve/change it?

2006-01-25 Thread Bengt Richter
On Tue, 24 Jan 2006 14:58:27 -0600, [EMAIL PROTECTED] wrote: > >Wolfgang> So basically if I want to write a long-running program in >Wolfgang> Python, it would make sense to code all functions that are >Wolfgang> likely to be called more than once as generators... > >If they need to re

Re: file_name_fixer.py

2006-01-25 Thread Richie Hindle
[Fredrik] > so re.sub("([_.])\\1+", "\\1", newname) replaces runs consisting > of either a . or an _ followed by one or more copies of itself, with > a single instance of itself. ...and this: >>> def isprime(n): >>> return n > 1 and not re.match(r'(xx+)\1+$', 'x'*n) finds prime numbers. I'

Apache with Python 2.4 Need Help !!!

2006-01-25 Thread pycraze
Hi, I am currently using Fedora Core - 3 with apache 2.0 Web Server and Python 2.4 . I have numerous dependencies when i want to use Python 2.4 version with Apache 2.0 Web Server . I have installed the mod-python module , for apache , which is one of the package i got while installing Fedor

Re: file_name_fixer.py

2006-01-25 Thread Thomas Heller
Richie Hindle <[EMAIL PROTECTED]> writes: > [Fredrik] >> so re.sub("([_.])\\1+", "\\1", newname) replaces runs consisting >> of either a . or an _ followed by one or more copies of itself, with >> a single instance of itself. > > ...and this: > def isprime(n): return n > 1 and not re

Re: Using non-ascii symbols

2006-01-25 Thread Bengt Richter
On Tue, 24 Jan 2006 04:09:00 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >On the page http://wiki.python.org/moin/Python3%2e0Suggestions >I noticed an interesting suggestion: > >"These operators ≤ ≥ ≠ should be added to the language having the >following meaning: > > <= >=

Re: writing arrays to binary file

2006-01-25 Thread Sheldon
Thanks Travis, I don't have the new NumPy yet but this tofile() method should work fine. /Sheldon -- http://mail.python.org/mailman/listinfo/python-list

Re: Python code written in 1998, how to improve/change it?

2006-01-25 Thread Wolfgang Keller
> > So basically if I want to write a long-running program in > > Python, it would make sense to code all functions that are > > likely to be called more than once as generators... This was meant as a question. > If they need to resume their calculations from where they left off after the > last

Re: Python code written in 1998, how to improve/change it?

2006-01-25 Thread Fredrik Lundh
Wolfgang Keller wrote: > > > So basically if I want to write a long-running program in > > > Python, it would make sense to code all functions that are > > > likely to be called more than once as generators... > > This was meant as a question. > > > If they need to resume their calculations from w

ActivePython & SSL

2006-01-25 Thread Fuzzyman
Hello all, In the past I've used the ActivePython distribution for windows. Particularly their chm help manual is excellent. I have heard that the ActivePython distribution *doesn't* include SSL support compiled in for windows. Can anyone confirm or deny this rumour for me ? All the best, Fuzz

Re: Dynamic pull down menus (CGI)

2006-01-25 Thread Fuzzyman
[EMAIL PROTECTED] wrote: > You will be quite limited without the use of JavaScript to perform this > kind of dynamic functionality. HTML alone cannot do this. You can use > dynamically generated Javascript, AJAX, Flash or Java. > > One possible would be to just use HTML forms and add in an extra b

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
On Wed, 25 Jan 2006 10:37:12 +, Richie Hindle wrote: > > [Fredrik] >> so re.sub("([_.])\\1+", "\\1", newname) replaces runs consisting >> of either a . or an _ followed by one or more copies of itself, with >> a single instance of itself. > > ...and this: > def isprime(n): ret

sending keystrokes to gtk window

2006-01-25 Thread sven
hi list, i'd like to send keystrokes to a (terminal) window. the windowmanager is gnome (ubuntu). what i want to do is to control dvgrab which can be started in interactive mode. thx in advance, sven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python code written in 1998, how to improve/change it?

2006-01-25 Thread Wolfgang Keller
> what makes you think that resuming a generator won't involve function > calls ? That was not what I wrote. I referred to what Peter Hansen <[EMAIL PROTECTED]> wrote in [EMAIL PROTECTED]: > I believe the more modern approach to this is to use generators in some > way, yield each other as the

Trying to understand logging.Filter

2006-01-25 Thread Rene Pijlman
I'd expect the program below to put only one line with "Eat me" in the log file. However, I get this with Python 2.4.2 in WingIDE on Windows XP: Eat me Ignore me My understanding is: 1. Event "Ignore me" is logged to logger 'spam'. 2. Logger 'spam' has no handler associated with it, so this l

Re: logging into secure website with script

2006-01-25 Thread Fuzzyman
dpoehls wrote: > Hello there, > > I am new to python, and shell scriping in general..I have done quite a > bit of php, but that it about it. Anyhow, I am wondering if it would be > possible to write a python script that would login to a password > enabled site (qmailadmin) and then be able to add

Re: append to the end of a dictionary

2006-01-25 Thread Magnus Lycka
Tim Chase wrote: > orderedDict = [(k,mydict[k]) for k in mydict.keys().sorted()] Wrong. As you stated, sorted() is a function, not a method. orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())] It's great that many people try to help out on comp.lang.python, the community won't s

Re: append to the end of a dictionary

2006-01-25 Thread Magnus Lycka
Tim Chase wrote: > I would lean towards using tuples, as in > > ports = [('5631','udp'), ('5632', 'tcp'), ('3389','tcp'), ('5900','tcp')] > > which you can then drop into your code: > > for (port, protocol) in ports: > print port, protocol > #do more stuff > > This allows yo

Re: append to the end of a dictionary

2006-01-25 Thread Magnus Lycka
Paul Rubin wrote: > ports = [('5631', 'udp'), > ('5632': 'tcp'), > ('3389': 'tcp'), > ('5900': 'tcp')] Change the colons to commas, and this will work... -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird generator id() behaviour (was Re: Python code written in1998, howto improve/change it?)

2006-01-25 Thread Bengt Richter
On Wed, 25 Jan 2006 12:33:17 +1300, Carl Cerecke <[EMAIL PROTECTED]> wrote: >Adding a continue statemtent after the yield statements yields :-) a >speed increase. Still not as good as functions though. (about 30% slower) > >Cheers, >Carl > >Carl Cerecke wrote: >> Carl Cerecke wrote: >> Generator

Re: Using non-ascii symbols

2006-01-25 Thread Ido Yehieli
I still remember it not being supported on most or all big Iron servers at my previuos uni (were mostly SunOS, Digital UNIX among others) -- http://mail.python.org/mailman/listinfo/python-list

Re: append to the end of a dictionary

2006-01-25 Thread Justin Azoff
Magnus Lycka wrote: > orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())] orderedListOfTuples = sorted(mydict.items()) > It's great that many people try to help out on comp.lang.python, > the community won't survive otherwise, but I think it's important > to test answers before

Re: ZODB and Zope on one Linux machine, how?

2006-01-25 Thread Rene Pijlman
Rene Pijlman: >Option 3: >Use separate Python installations for Zope and the application. Install >ZODB in the application's Python installation, not in Zope's. For the record, on zodb-dev I got this advice: "This is the only sane option". -- René Pijlman Wat wil jij worden? http://www.carrier

Re: append to the end of a dictionary

2006-01-25 Thread Sion Arrowsmith
Magnus Lycka <[EMAIL PROTECTED]> wrote: >orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())] Or: orderedListOfTuples = [(k,v) for k,v in sorted(mydict.items())] (k, mydict[k]) sets off warning bells for me that mydict.items() should be in use, which are nearly as loud as the on

Re: append to the end of a dictionary

2006-01-25 Thread Fuzzyman
Tim Chase wrote: > > I seem to be unable to find a way to appends more keys/values to the end > > of a dictionary... how can I do that? > > > > E.g: > > > > mydict = {'a':'1'} > > > > I need to append 'b':'2' to it to have: > > > > mydict = {'a':'1','b':'2'} > > my understanding is that the order

Re: Apache with Python 2.4 Need Help !!!

2006-01-25 Thread Sybren Stuvel
pycraze enlightened us with: > I am currently using Fedora Core - 3 with apache 2.0 Web Server and > Python 2.4 . > > [...] i would like to know have apache released any version that can > be successfully use Python 2.4 ( with mod-python module ) using > Fedora Core -3 . I don't know about Fedora

Re: Trying to understand logging.Filter

2006-01-25 Thread Rene Pijlman
Rene Pijlman: >3. The event is dispatched to the root logger as well, Got it. The event is not dispatched to ancestor loggers, but to the handlers associated with ancestor loggers (Doc: "In addition to any handlers directly associated with a logger, all handlers associated with all ancestors of th

Re: sending keystrokes to gtk window

2006-01-25 Thread Johan Dahlin
sven wrote: > hi list, > i'd like to send keystrokes to a (terminal) window. > the windowmanager is gnome (ubuntu). > what i want to do is to control dvgrab which can be > started in interactive mode. > thx in advance, This is not entirely trivial to do. The best way to do that would be to use the

Best way to extract an item from a set of len 1

2006-01-25 Thread Tim Chase
When you have a set, known to be of length one, is there a "best" ("most pythonic") way to retrieve that one item? # given that I've got Python2.3.[45] on hand, # hack the following two lines to get a "set" object >>> import sets >>> set = sets.Set >>> s = set(['test'])

Fast generation of permutations

2006-01-25 Thread Frode Øijord
Hi all, given a sequence of n elements i need to generate all possible permutations of length k <= n. I found an elegant way to do this recursively: def comb(items, n): if n==0: yield [] else: for i in xrange(len(items)): for cc in comb(items[i+1:],n-1):

Re: Creating a more random int?

2006-01-25 Thread Magnus Lycka
Steven D'Aprano wrote: > But all joking aside, the random number generator used by Python is one of > the best in the world. What is at fault is your intuition about what > random numbers should look like, not the random number generator. This is a well known problem, and there are methods to dete

Re: append to the end of a dictionary

2006-01-25 Thread Sion Arrowsmith
I wrote: >orderedListOfTuples = [(k,v) for k,v in sorted(mydict.items())] > >(k, mydict[k]) sets off warning bells for me that mydict.items() >should be in use [ ... ] But apparently [ x for x in mylist ] doesn't yet trigger such a warning. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~

Re: Mining strings from a HTML document.

2006-01-25 Thread jay graves
Derick van Niekerk wrote: > What are the string functions I would use and how would I use them? I > saw something about html parsing in python, but that might be overkill. > Babysteps. Despite your reluctance, I would still recommend an HTML parsing module. I like BeautifulSoup. http://www.crummy.

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Fredrik Lundh
Tim Chase wrote: > I suppose I was looking for something like > > >>> item = s.aslist()[0] > > which feels a little more pythonic (IMHO). Is one solution > preferred for speed over others (as this is happening in a fairly > deeply nested loop)? the obvious solution is item = list(s)[0] but

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Peter Otten
Tim Chase wrote: > When you have a set, known to be of length one, is there a "best" > ("most pythonic") way to retrieve that one item? >>> s = set(["one-and-only"]) >>> item, = s >>> item 'one-and-only' This works for any iterable and guarantees that it contains exactly one item. The comma may

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Fuzzyman
That's cute. :-) Fuzzyman -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Rene Pijlman
Tim Chase: >When you have a set, known to be of length one, is there a "best" >("most pythonic") way to retrieve that one item? e = s.copy().pop() #:-) -- René Pijlman Wat wil jij worden? http://www.carrieretijger.nl -- http://mail.python.org/mailman/listinfo/python-list

Re: logging module question

2006-01-25 Thread Vinay Sajip
> but now I'd like to understand the design rational behind having each > logger in the object hierarchy log the same output by default. Anyone? Loggers are different to handlers. Loggers map to areas of the application, handlers map to output destinations. Loggers form a hierarchy based on names

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Alex Martelli
Tim Chase <[EMAIL PROTECTED]> wrote: ... > To get the item, i had to resort to methods that feel less than > the elegance I've come to expect from python: > > >>> item = [x for x in s][0] A shorter, clearer expression of the same idea: item = list(s)[0] or item = list(s).pop() > or

Re: Creating a more random int?

2006-01-25 Thread Grant Edwards
On 2006-01-25, Magnus Lycka <[EMAIL PROTECTED]> wrote: > P.S. Since I was a kid, I've heard people say: So you're born > on new years day--how unusual. Well, it happens to slightly less than 1/365th of the population[1], so it is rather unusual. Of course it's no more unusal that being born on J

Re: Apache with Python 2.4 Need Help !!!

2006-01-25 Thread rbt
Sybren Stuvel wrote: > pycraze enlightened us with: > >>I am currently using Fedora Core - 3 with apache 2.0 Web Server and >>Python 2.4 . >> >>[...] i would like to know have apache released any version that can >>be successfully use Python 2.4 ( with mod-python module ) using >>Fedora Core -3 .

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Rene Pijlman
Peter Otten: s = set(["one-and-only"]) item, = s item >'one-and-only' > >This works for any iterable and guarantees that it contains exactly one >item. Nice! >The comma may easily be missed, though. You could write: (item,) = s But I'm not sure if this introduces additional

Re: Mining strings from a HTML document.

2006-01-25 Thread Chris Lasher
I think Jay's advice is solid: you shouldn't rule out HTML parsing. It's not too scary and it's probably not overboard. Using a common HTML parsing library saves you from having to write and debug your own parser. Try looking at Dive Into Python's chapter on it, first. http://www.diveintopython.org

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Fredrik Lundh
Peter Otten wrote: > > When you have a set, known to be of length one, is there a "best" > > ("most pythonic") way to retrieve that one item? > > >>> s = set(["one-and-only"]) > >>> item, = s > >>> item > 'one-and-only' > > This works for any iterable and guarantees that it contains exactly one >

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Alex Martelli
Fredrik Lundh <[EMAIL PROTECTED]> wrote: ... > the obvious solution is > > item = list(s)[0] > > but that seems to be nearly twice as slow as [x for x in s][0] > under 2.4. hmm. Funny, and true on my laptop too: helen:~ alex$ python -mtimeit -s's=set([23])' 'x=list(s)[0]' 10 loops,

win32com early binding problem

2006-01-25 Thread Roland
Hello, I'm trying to use Sparx Systems Enterprise Architect OLE automation interface. There is no problem to get early binding interface using Microsoft Visual Basic. But using win32com makepy utility there problem is. Does anybody have an idea, what may disqualify python win32com from creating e

exception given by minidom.parse

2006-01-25 Thread ankit
I want to catch the exception given by minidom.parse. Please let me know what are the exceptions raised by minidom.parse() esp if some given file is not xml -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a more random int?

2006-01-25 Thread Dave Hansen
On Wed, 25 Jan 2006 15:21:43 - in comp.lang.python, Grant Edwards <[EMAIL PROTECTED]> wrote: >On 2006-01-25, Magnus Lycka <[EMAIL PROTECTED]> wrote: > >> P.S. Since I was a kid, I've heard people say: So you're born >> on new years day--how unusual. > >Well, it happens to slightly less than 1/

Re: Creating a more random int?

2006-01-25 Thread Fredrik Lundh
Grant Edwards wrote: > [1] Assuming birth dates are uniformly distributed. Which the > probably aren't in countries where a significant portion of > the population schedules births to fit the hospital/doctors > schedule. or in countries that use "nominal birth dates" for people born

Re: Python code written in 1998, how to improve/change it?

2006-01-25 Thread Magnus Lycka
Wolfgang Keller wrote: > The way I understand this, resuming a generator causes less overhead than the > inital overhead of a function call. I don't have Python 2.4 handy, but it doesn't seem to be true in 2.3. I'm not very proficient with generators though, so maybe I'm doing something stupid he

RE: win32com early binding problem

2006-01-25 Thread Stefan Schukat
win32com does only support late bound interfaces in python scripts. To support early bound interfaces a pyd has to be created. If you want to script early bound interfaces try ctypes.com aka. comtypes from Thomas Heller. Stefan > -Original Message- > From: [EMAIL PROTECTED] > [

Re: Fast generation of permutations

2006-01-25 Thread Jack Diederich
On Wed, Jan 25, 2006 at 03:33:48PM +0100, Frode ?ijord wrote: > Hi all, > given a sequence of n elements i need to generate all possible > permutations of length k <= n. > > I found an elegant way to do this recursively: > > def comb(items, n): > if n==0: yield [] > else: > for i

Re: Using non-ascii symbols

2006-01-25 Thread Peter Hansen
Dave Hansen wrote: > C uses ! as a unary logical "not" operator, so != for "not equal" just > seems to follow, um, logically. > > Pascal used <>, which intuitively (to me, anyway ;-) read "less than > or greater than," i.e., "not equal." For quantitative data, anyway, or things which can be ord

Re: Fast generation of permutations

2006-01-25 Thread Michael Amrhein
Frode Øijord schrieb: > Hi all, > given a sequence of n elements i need to generate all possible > permutations of length k <= n. > > I found an elegant way to do this recursively: > > def comb(items, n): > if n==0: yield [] > else: > for i in xrange(len(items)): > fo

Re: Creating a more random int?

2006-01-25 Thread Magnus Lycka
Grant Edwards wrote: > Well, it happens to slightly less than 1/365th of the > population[1], so it is rather unusual. Of course it's no more > unusal that being born on June 19th or November 3rd or any > other date you choose... Exactly. And I've never heard anyone say to my sons that it's so un

Re: Creating a more random int?

2006-01-25 Thread Tim Chase
> Exactly. And I've never heard anyone say to my sons that it's > so unusual that they are born on Jan 30th or June 27th! Now those born on Feb 29th...they're about a quarter as frequent :) -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: Fast generation of permutations

2006-01-25 Thread Michael Amrhein
Michael Amrhein schrieb: > Frode Øijord schrieb: >> Hi all, >> given a sequence of n elements i need to generate all possible >> permutations of length k <= n. >> >> I found an elegant way to do this recursively: >> >> def comb(items, n): >> if n==0: yield [] >> else: >> for i in x

Re: ActivePython & SSL

2006-01-25 Thread Trent Mick
[Fuzzyman wrote] > Hello all, > > In the past I've used the ActivePython distribution for windows. > Particularly their chm help manual is excellent. > > I have heard that the ActivePython distribution *doesn't* include SSL > support compiled in for windows. > > Can anyone confirm or deny this r

Re: Creating a more random int?

2006-01-25 Thread davbrow
Well it IS unusual actually (~1/365.25). Please tell them for me. -- Dave -- http://mail.python.org/mailman/listinfo/python-list

Python and XML Schema

2006-01-25 Thread Trond
I have a need to, given a XML document with XML Schema defined, to get the type of each element in the XML file based on the XML Schema URI given. IE, the element is of simple datatype string. Is there any existing Python libraries were I can parse the XML file, and for a given node ask for th

Re: Fast generation of permutations

2006-01-25 Thread Frode Øijord
Jack Diederich wrote: > You might want to look at a specific purpose library for poker hands: > http://pokersource.sourceforge.net/ Nah, evaluating the poker hands is the FUN part! I want to do that myself :) > If you really want to do combinations a C extension has already > been written (by m

Re: Fast generation of permutations

2006-01-25 Thread Terry Reedy
"Frode Øijord" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > However, this is way too slow for my needs. I try to use this to > generate all possible 5 card poker hands, but this takes around 17 > seconds on an Athlon 2200. That's a 2 orders of magnitude too slow for > my needs.

Re: Possible memory leak?

2006-01-25 Thread Tuvas
FYI, to all who asked, I was indeed just simply monitering the system memory. I changed my approach to one that uses arrays and simply joins the statements together at the end, it seems to have improved the speed. However, for some reason it still takes a small eternity to process on one computer,

Re: customized instance dictionaries, anyone?

2006-01-25 Thread [EMAIL PROTECTED]
thx! indeed, it worked -- took me some time to figure out how to implement the setting of attributes, too. i finally managed to get that done using super: custom dictionary, unchanged:: class CustomDict( dict ): defaultValue = 'THIS ITEM NOT AVAILABLE' def __getitem__( self,

Re: Creating a more random int?

2006-01-25 Thread davbrow
Steven, Have you considered you might want a less random distribution? If you just want to remove repeats so it 'seems' more random you could do that (replace any repeat with another random value not equal to the last value). It likely will not be as uniformly random as the original sequence but

Re: Fast generation of permutations

2006-01-25 Thread Paul Rubin
Frode Øijord <[EMAIL PROTECTED]> writes: > > cards = range(52) > > for (hand) in probstat.Combination(card, 5): > > pass > > Takes 1.3 seconds on my laptop instead of 17 seconds for the pure > > python version which is only one order of magnitude faster. > > This is *exactly* what i wanted! I ju

Re: Creating a more random int?

2006-01-25 Thread Grant Edwards
On 2006-01-25, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: > >> [1] Assuming birth dates are uniformly distributed. Which the >> probably aren't in countries where a significant portion of >> the population schedules births to fit the hospital/doctors >> schedule. >

Re: Fast generation of permutations

2006-01-25 Thread Paul Rubin
Paul Rubin writes: > Note that you're looking at 24x more hands than you really need to, Well, maybe not 24x. The exact number is more complicated. I'm still too sleepy to figure this out right now but may think about it later. -- http://mail.python.org/mailman/listin

remote file

2006-01-25 Thread yqyq22
How to open remote file ? example: \\server\share\file.txt thanks a lot -- http://mail.python.org/mailman/listinfo/python-list

Re: Some thougts on cartesian products

2006-01-25 Thread Terry Reedy
"Christoph Zwerschke" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Bryan Olson wrote: >> The claim "everything is a set" falls into the category of >> 'not even wrong'. > > No, it falls into the category of the most fundamental Mathematical > concepts. You actually *define* tuple

Re: Creating a more random int?

2006-01-25 Thread Fredrik Lundh
Grant Edwards wrote: > > Grant Edwards wrote: > > > >> [1] Assuming birth dates are uniformly distributed. Which the > >> probably aren't in countries where a significant portion of > >> the population schedules births to fit the hospital/doctors > >> schedule. > > > > or in countries

Re: remote file

2006-01-25 Thread Fredrik Lundh
"yqyq22" wrote: > How to open remote file ? example: \\server\share\file.txt like you'd open any other file: f = open(filename) e.g. f = open(r"\\server\share\file.txt") -- http://mail.python.org/mailman/listinfo/python-list

Re: Some thougts on cartesian products

2006-01-25 Thread Fredrik Lundh
Terry Reedy wrote: > You might so define, but Bryan and others might not. The > philosophical/methodological idea that 'everything is a set' has been very > fruitful but it is not a fact. Alternative ideas are 'everything is a > function' and 'everything is defined by axioms'. according to goog

Convert a long XML string into indented format

2006-01-25 Thread Laguna
Hi, I have an XML file in a single long string. How can I convert it into the nicely indented format as displayed by Internet Explorer using Python? Thanks, Laguna Input XML file (one continuous string without newline): */2 * * * * Output XML file: */2

Re: Possible memory leak?

2006-01-25 Thread Giovanni Bajo
Steven D'Aprano wrote: > No, that's not correct. You are making a false > assumption. Did you ever try to measure the code yourself? > This is from the "What's New" for Python 2.4: > > [quote] > String concatenations in statements of the form s = s + > "abc" and s += "abc" are now performed more

"pre-"*10 + "PEP": extension to the list comprehensions & genexps syntax

2006-01-25 Thread Gregory Petrosyan
This is revised version of "Arithmetic sequences in Python" proposal. I don't want this topic to become as bloated with offtopic as "ASiP". Please post here corresponding info only. Your (revised) comments (possibly already posted to "ASiP") are welcome. The first thing I want to mention is that,

  1   2   >