Re: porting C code

2005-01-14 Thread Duncan Booth
Lucas Raab wrote: Sorry, the third byte is what I meant. As for code samples, I hope the following will work: typedef unsigned long int word32 ; void mu(word32 *a) { int i ; word32 b[3] ; b[0] = b[1] = b[2] = 0 ; for( i=0 ; i32 ; i++ ) { b[0] = 1 ; b[1] = 1 ; b[2] = 1 ;

Re: OCAMl a more natural extension language for python?

2005-01-17 Thread Duncan Booth
Jelle Feringa // EZCT / Paris wrote: After reading about extending python with C/Fortran in the excellent Python Scripting for Computational Science book by Hans Langtangen, I'm wondering whether there's not a more pythonic way of extending python. And frankly I think there is: OCAML There

Re: Writing huge Sets() to disk

2005-01-17 Thread Duncan Booth
Martin MOKREJ© wrote: Hi, could someone tell me what all does and what all doesn't copy references in python. I have found my script after reaching some state and taking say 600MB, pushes it's internal dictionaries to hard disk. The for loop consumes another 300MB (as gathered by vmstat)

Re: why are these not the same?

2005-01-20 Thread Duncan Booth
Lowell Kirsh wrote: On a webpage (see link below) I read that the following 2 forms are not the same and that the second should be avoided. They look the same to me. What's the difference? Lowell def functionF(argString=abc, argList = None): if argList is None:

Re: circular iteration

2005-01-21 Thread Duncan Booth
Flavio codeco coelho wrote: hi, is there a faster way to build a circular iterator in python that by doing this: c=['r','g','b','c','m','y','k'] for i in range(30): print c[i%len(c)] thanks, Flávio import itertools c=['r','g','b','c','m','y','k'] circ =

Re: re Insanity

2005-01-22 Thread Duncan Booth
Tim Daneliuk wrote: I tried this: y=re.compile(r'\[PROMPT:.*\]') Which works fine when the text is exactly [PROMPT:whatever] but does not match on: something [PROMPT:foo] something [PROMPT:bar] something ... The overall goal is to identify the beginning and end of each

Re: best way to do a series of regexp checks with groups

2005-01-24 Thread Duncan Booth
Mark Fanty wrote: No nesting, but the while is misleading since I'm not looping and this is a bit awkward. I don't mind a few more key strokes, but I'd like clarity. I wish I could do if m = re.search(r'add (\d+) (\d+)', $line): do_add(m.group(1), m.group(2)) elif m =

Re: short programming projects for kids

2005-01-24 Thread Duncan Booth
bobdc wrote: I will be teaching an Introduction to Programming class to some middle school aged children and will be using Python, obviously. Does anyone have suggestions for simple little programs to create and analyze with them after I get past turtle graphics? Turtle graphics will be

Re: re.search - just skip it

2005-01-26 Thread Duncan Booth
wrote: Input is this: SET1_S_W CHAR(1) NOT NULL, SET2_S_W CHAR(1) NOT NULL, SET3_S_W CHAR(1) NOT NULL, SET4_S_W CHAR(1) NOT NULL, ; .py says: import re, string, sys s_ora = re.compile('.*S_W.*') lines = open(y.sql).readlines() for i in range(len(lines)): try: if

Re: how to comment out a block of code

2005-01-27 Thread Duncan Booth
Xah Lee wrote: is there a syntax to comment out a block of code? i.e. like html's !-- comment -- or perhaps put a marker so that all lines from there on are ignored? thanks. The simplest way is to select the block of code in your editor and use the 'comment-region' command. If this

Re: Who should security issues be reported to?

2005-01-28 Thread Duncan Booth
[EMAIL PROTECTED] wrote: I find this response a bit dissappointing frankly. Open Source people make such a big deal about having lots of people being able to look at source code and from that discover security problems, thus making it somehow making it better than proprietary source code.

Re: Who should security issues be reported to?

2005-01-28 Thread Duncan Booth
Paul Rubin wrote: Duncan Booth [EMAIL PROTECTED] writes: In other words, I'm intrigued how you managed to come up with something you consider to be a security issue with Python since Python offers no security. Perhaps, without revealing the actual issue in question, you could give an example

Re: a sequence question

2005-01-28 Thread Duncan Booth
Chris Wright wrote: 1) I want to iterate over a list N at a time sort of like: # Two at a time... won't work, obviously for a, b in [1,2,3,4]: ... print a,b ... Try this: l = [1, 2, 3, 4] for a, b in zip(*[iter(l)]*2): print a, b zip(*[iter(seq)]*N) will group by N

Re: naive doc question

2005-01-30 Thread Duncan Booth
Gabriel B. wrote: Is it just me that can't find a full reference in the docs? I wanted a list of all the methods of dict for example... where can i find it? Thanks, and sorry if this question is just dumb, i really can't find it If you want to find out about all the methods of dict

Re: Hash of class from instance

2005-02-02 Thread Duncan Booth
Joakim Storck wrote: Is there any way that I can find the hash value of a class from an instance? You only had to post the question once. It seems a strange thing to want, but just do: hash(a.__class__) -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding user's home dir

2005-02-03 Thread Duncan Booth
Peter Hansen wrote: Nemesis, please use the above recipe instead, as it makes the more reasonable (IMHO) choice of checking for a HOME environment variable before trying the expanduser(~) approach. This covers folks like me who, though stuck using Windows, despise the ridiculous Microsoft

Re: Calling a method using an argument

2005-02-03 Thread Duncan Booth
Diez B. Roggisch wrote: If you have more args, do this: def test(self, *args): return getattr(self, args[0])(*args[1:]) This would be cleaner written as: def test(self, method, *args): return getattr(self, method)(*args) and for complete generality: def test(self, method,

Re: dynamic func. call

2005-02-06 Thread Duncan Booth
[EMAIL PROTECTED] wrote: Try this: def myfunc(): print helo s = myfunc() a = eval(s) No, please don't try that. Good uses for eval are *very* rare, and this isn't one of them. Use the 'a = locals()[x]()' suggestion (or vars() instead of locals()), or even better put all the

Re: def __init__ question in a class definition

2005-02-07 Thread Duncan Booth
Miki Tebeka wrote: IE: is there any special significance to the __ in this case. http://docs.python.org/tut/tut.html specifically section 9.6 Also Python Reference Manual, section 2.3.2 Reserved classes of identifiers -- http://mail.python.org/mailman/listinfo/python-list

Re: Get importer module from imported module

2005-02-07 Thread Duncan Booth
dody suria wijaya wrote: I found this problem when trying to split a module into two. Here's an example: == #Module a (a.py): from b import * class Main: pass == == #Module b (b.py) def How(): Main_instance = module_a.Main() return

Re: Re[2]: Get importer module from imported module

2005-02-07 Thread Duncan Booth
dody suria wijaya wrote: import a inside b would not solve the problem, since there are many module a and module b does not know beforehand which module had imported it. Ok, I understand now what you are trying to achieve, but there isn't any concept relating a module back to the first

Re: xmlentities

2005-02-07 Thread Duncan Booth
Ola Natvig wrote: Does anyone know a good library for transfering non standard characters to enity characters in html. I want characters like and to be transformed to lt; and gt;. And the norwegian ø to oslash; You could use cgi.escape to handle , , and and then use error handling on

Re: variable declaration

2005-02-08 Thread Duncan Booth
Brian van den Broek wrote: Can it then be further (truly :-) ) said that if False: # thousands of lines of code here would effect the structure of the function object's bytecode, but not its behaviour when run? Or, at most, would cause a performance effect due to the bytecode

Re: pass named parameters to python

2005-02-08 Thread Duncan Booth
John Leslie wrote: I am converting a korn shell script to python and want to be able to pass named arguments into python e.g -firstparam -secondparam Can this be done? See the module 'optparse'. http://www.python.org/doc/current/lib/module-optparse.html --

Re: passing arguments like -JOB

2005-02-10 Thread Duncan Booth
John Leslie wrote: I am porting a script from Korn Shell to python and want to pass named parameters like -JOB 123456 -DIR mydir I can get it to work passing --JOB and --DIR but not -JOB and -DIR Any ideas? Unfortunately (for you), I think you will find most or all of the existing ways

Re: That horrible regexp idiom

2005-02-10 Thread Duncan Booth
Nick Coghlan wrote: I knew if/elif was a much better argument in favour of embedded assignment than while loops are. I know I'm going to regret posting this, but here is an alternative, very hackish way to do all those things people keep asking for, like setting variables in outer scopes

Re: goto, cls, wait commands

2005-02-10 Thread Duncan Booth
BOOGIEMAN wrote: I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? There isn't one. Why do you think you need this? Secondly, how

Re: - E02 - Support for MinGW Open Source Compiler

2005-02-14 Thread Duncan Booth
Ilias Lazaridis wrote: There is a OS-tool-chain supported on windows, cygwin. this depends on cygwin.dll, which is GPL licensed [or am I wrong?] It is GPL licensed with an amendment which prevents the GPL spreading to other open source software with which it is linked. In accordance

Re: - E02 - Support for MinGW Open Source Compiler

2005-02-15 Thread Duncan Booth
Ilias Lazaridis wrote: In accordance with section 10 of the GPL, Red Hat, Inc. permits programs whose sources are distributed under a license that complies with the Open Source definition to be linked with libcygwin.a without libcygwin.a itself causing the resulting program to be covered by

Re: super not working in __del__ ?

2005-02-16 Thread Duncan Booth
Fredrik Lundh wrote: in this case, def __del__(self): super(self.__class__, self).__del__() should do the trick. Only if nobody ever tries to subclass your class, and if they aren't going to subclass it why bother to use super in the first place. class Base(object): def

Re: super not working in __del__ ?

2005-02-16 Thread Duncan Booth
Ola Natvig wrote: def __del__(self): There should be a super(self.__class__, self)._del__() here if I'm not totaly wong, which could be the case here ;) print Base.__del__ There was one, but for some reason you trimmed it out of your quote: The original

Re: super not working in __del__ ?

2005-02-16 Thread Duncan Booth
Ola Natvig wrote: Duncan Booth wrote: class Base(object): def __del__(self): There should be a super(self.__class__, self)._del__() here if I'm not totaly wong, which could be the case here ;) print Base.__del__ Thanks to Brian Beck for pointing out I

Re: difference between class methods and instance methods

2005-02-17 Thread Duncan Booth
John M. Gabriele wrote: I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any

Re: Why doesn't join() call str() on its arguments?

2005-02-17 Thread Duncan Booth
news.sydney.pipenetworks.com wrote: I'm not sure if this has been raised in the thread but I sure as heck always convert my join arguments using str(). When does someone use .join() and not want all arguments to be strings ? Any examples ? This has already been raised, but maybe not in

Re: difference between class methods and instance methods

2005-02-17 Thread Duncan Booth
Diez B. Roggisch wrote: John wrote: ... hmm... bound methods get created each time you make a call to an instance method via an instance of the given class? No, they get created when you create an actual instance of an object. So only at construction time. Creating them means taking the

Re: namespace dictionaries ok?

2005-10-25 Thread Duncan Booth
Ron Adam wrote: James Stroud wrote: Here it goes with a little less overhead: example snipped But it's not a dictionary anymore so you can't use it in the same places you would use a dictionary. foo(**n) Would raise an error. So I couldn't do: def foo(**kwds):

Re: Syntax across languages

2005-10-25 Thread Duncan Booth
Tim Roberts wrote: - Nestable Pascal-like comments (useful): (* ... *) That's only meaningful in languages with begin-comment AND end-comment delimiters. Python has only begin-comment. Effectively, you CAN nest comments in Python: I believe that the OP is mistaken. In standard Pascal

Re: Weird import behavior

2005-10-25 Thread Duncan Booth
Tommytrojan wrote: import string import os class T: def __init__(self): try: print 'xxx nothing to do' except ImportError: print 'got an import error' import os as string print ' string module', string t=T()

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Duncan Booth
James Stroud wrote: On Tuesday 25 October 2005 00:31, Duncan Booth wrote: P.S. James, *please* could you avoid top-quoting Were it not for Steve Holden's providing me with a link off the list, I would have never known to what it is you are referring. I have read some relevant literature

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Duncan Booth
Grant Edwards wrote: Uh, no. Isn't what we're doing here top-quoting? The quoted stuff is at the top. Everything is in chronological order. I think what you're referring to is top-posting. Yes, Iain King already pointed this out. -- http://mail.python.org/mailman/listinfo/python-list

Re: String Identity Test

2005-11-01 Thread Duncan Booth
Thomas Moore wrote: I am confused at string identity test: snip Does that mean equality and identity is the same thing for strings? Definitely not. What is actually happening is that certain string literals get folded together at compile time to refer to the same string constant, but you

Re: NTFS reparse points

2005-11-03 Thread Duncan Booth
Stanislaw Findeisen wrote: (2) Does anybody have any idea (sample code?) on how to create a reparse point (the simpler, the better) using Python? The only sample code I've seen for creating reparse points is in c or c++ and its quite a messy operation. See

Re: recursive function call

2005-11-08 Thread Duncan Booth
Nicolas Vigier wrote: I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2, opt1=opt1, opt2=opt2,

RE: Pywin32: How to import data into Excel?

2005-11-08 Thread Duncan Booth
Tim Golden wrote: [Dmytro Lesnyak] I need to import some big data into Excel from my Python script. I have TXT file (~7,5 Mb). I'm using Pywin32 library for that, but if I first try to read the TXT file and then save the values one by one like xlBook.Sheets(sheet_name).Cells(i,j).Value =

Re: Default method arguments

2005-11-15 Thread Duncan Booth
Nicola Larosa wrote: # use new-style classes, if there's no cogent reason to do otherwise class A(object): def __init__(self, n): self.data = n def f(self, x = None) # do NOT use if not x ! if x is None: print self.data else:

Re: Default method arguments

2005-11-15 Thread Duncan Booth
Nicola Larosa wrote: Using None might be problematic if None could be a valid argument. That's like saying that NULL could be a significant value in SQL. In Python, None *is* the empty, not significant value, and should always be used as such. Specifically, never exchange None for False.

Re: Shutdown hook

2005-11-16 Thread Duncan Booth
Lawrence Oluyede wrote: Il 2005-11-15, Ben Finney [EMAIL PROTECTED] ha scritto: Steve [EMAIL PROTECTED] wrote: Does any one know if python has the ability to run a shutdown hook. When the Python runtime system wants to exit, it raises a SystemExit exception. Catch that exception at the

Re: Default method arguments

2005-11-16 Thread Duncan Booth
Steven D'Aprano wrote: I would like to see _marker put inside the class' scope. That prevents somebody from the outside scope easily passing _marker as an argument to instance.f. It also neatly encapsulates everything A needs within A. Surely that makes it easier for someone outside the

Re: Default method arguments

2005-11-16 Thread Duncan Booth
Steven D'Aprano wrote: My philosophy is, any time you have an object that has a magic meaning (e.g. as a sentinel), don't tempt your users to try to use it as if it were an ordinary object. In that case the simplest thing is to give _marker a more appropriate name such as

Re: about lambda

2005-11-20 Thread Duncan Booth
Shi Mu wrote: what does the following code mean? It is said to be used in the calculation of the overlaid area size between two polygons. map(lambda x:b.setdefault(x,[]),a) Thanks! Assuming b is a dict, it is roughly equivalent to the following (except that the variables beginning with _

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,

Re: about sort and dictionary

2005-11-22 Thread Duncan Booth
Magnus Lycka wrote: 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 One part you missed, sorted

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Duncan Booth
metiu uitem wrote: Say you have a flat list: ['a', 1, 'b', 2, 'c', 3] How do you efficiently get [['a', 1], ['b', 2], ['c', 3]] That's funny, I thought your subject line said 'list of tuples'. I'll answer the question in the subject rather than the question in the body: aList = ['a', 1,

Re: Converting a flat list to a list of tuples

2005-11-23 Thread Duncan Booth
Bengt Richter wrote: On Tue, 22 Nov 2005 13:26:45 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: Duncan Booth wrote: it = iter(aList) zip(it, it) [('a', 1), ('b', 2), ('c', 3)] snip is relying on undefined behaviour perhaps the new black ? Is it really undefined? If so, IMO it should

Re: sort the list

2005-11-23 Thread Duncan Booth
Neil Hodgson wrote: Since no-one mentioned it and its a favourite of mine, you can use the decorate-sort-undecorate method, or Schwartzian Transform That is what the aforementioned key argument to sort is: a built-in decorate-sort-undecorate. And crucially it is a built-in DSU which

Re: Why are there no ordered dictionaries?

2005-11-23 Thread Duncan Booth
Christoph Zwerschke wrote: Ok, I just did a little research an compared support for ordered dicts in some other languages: Just to add to your list: In Javascript Object properties (often used as an associative array) are defined as unordered although as IE seems to always store them in

Re: Why are there no ordered dictionaries?

2005-11-24 Thread Duncan Booth
Christoph Zwerschke wrote: Duncan Booth schrieb: In Javascript Object properties (often used as an associative array) are defined as unordered although as IE seems to always store them in the order of original insertion it wouldn't surprise me if there are a lot of websites depending

Re: return in loop for ?

2005-11-24 Thread Duncan Booth
Steve Holden wrote: Interestingly, I just saw a thread over at TurboGears(or is it this group, I forgot) about this multiple return issue and there are people who religiously believe that a function can have only one exit point. def f(): r = None for i in range(20): if i 10:

Re: Why is dictionary.keys() a list and not a set?

2005-11-24 Thread Duncan Booth
[EMAIL PROTECTED] wrote: Consider a dictionary with one million items. The following operations k = d.keys() v = d.values() creates two list objects, while i = d.items() creates just over one million objects. In your equivalent example, Sorry. I lose you here. Could you

Re: Why is dictionary.keys() a list and not a set?

2005-11-24 Thread Duncan Booth
[EMAIL PROTECTED] wrote: As for the (k,v) vs (v,k), I still don't think it is a good example. I can always use index to access the tuple elements and most other functions expect the first element to be the key. For example : a=d.items() do something about a b = dict(a) But using the

Re: return in loop for ?

2005-11-24 Thread Duncan Booth
Steven D'Aprano wrote: While outwardly they apear to offer a technique for making software more reliable there are two shortcomings I'm leery of. First, no verification program can verify itself; That's not a problem if there exists a verification program A which can't verify itself but

Re: return in loop for ?

2005-11-28 Thread Duncan Booth
Steven D'Aprano wrote: Since real source code verifiers make no such sweeping claims to perfection (or at least if they do they are wrong to do so), there is no such proof that they are impossible. By using more and more elaborate checking algorithms, your verifier gets better at correctly

Re: General question about Python design goals

2005-11-28 Thread Duncan Booth
Antoon Pardon wrote: So suppose I want a dictionary, where the keys are colours, represented as RGB triplets of integers from 0 to 255. A number of things can be checked by index-like methods. e.g. def iswhite(col): return col.count(255) == 3 def primary(col): return

Re: General question about Python design goals

2005-11-28 Thread Duncan Booth
Antoon Pardon wrote: I'm sure I could come up with an other example where I would like to have both some list method and use it as a dictionary key and again people could start about that implementation having some flaws and give better implementations. I'm just illustrating that some

Re: Death to tuples!

2005-11-28 Thread Duncan Booth
Antoon Pardon wrote: def func(x): ... if x in [1,3,5,7,8]: ... print 'x is really odd' ... dis.dis(func) ... 3 20 LOAD_FAST0 (x) 23 LOAD_CONST 2 (1) 26 LOAD_CONST 3 (3) 29

Re: General question about Python design goals

2005-11-28 Thread Duncan Booth
Antoon Pardon wrote: No I gave an example, you would implement differently. But even if you think my example is bad, that would make it a bad argument for tuples having list methods. That is not the same as being a good argument against tuples having list methods. Tuples don't have list

Re: Death to tuples!

2005-11-29 Thread Duncan Booth
Antoon Pardon wrote: The question is, should we consider this a problem. Personnaly, I see this as not very different from functions with a list as a default argument. In that case we often have a list used as a constant too. Yet python doesn't has a problem with mutating this list so that

Re: Why I need to declare import as global in function

2005-11-29 Thread Duncan Booth
wrote: I have remarq that this problem is raised when I execute code in an imported module (during importation) I think I will be able to isolate it and have a simple sample soon Meanwhile, try adding: import math to the top of TU_05_tools.py. --

Re: Why I need to declare import as global in function

2005-11-29 Thread Duncan Booth
Peter Otten wrote: Traceback (most recent call last): File ../tu.py, line 21, in run_tu execfile( filename ) File TU_05_010.py, line 8, in ? import TU_05_tools File ./TU_05_tools.py, line 4, in ? f() File ./TU_05_tools.py, line

Re: Death to tuples!

2005-11-29 Thread Duncan Booth
Dan Bishop wrote: Is there any place in the language that still requires tuples instead of sequences, except for use as dictionary keys? The % operator for strings. And in argument lists. def __setitem__(self, (row, column), value): ... Don't forget the exception specification in a

Re: Death to tuples!

2005-11-30 Thread Duncan Booth
Mike Meyer wrote: An object is compatible with an exception if it is either the object that identifies the exception, or (for exceptions that are classes) it is a base class of the exception, or it is a tuple containing an item that is compatible with the exception. Requiring a tuple here

Re: Why I need to declare import as global in function

2005-11-30 Thread Duncan Booth
[EMAIL PROTECTED] wrote: I think I understand my problem, but first the sample code extracted to my project. Rq : it's an automatic run of unitary test, the names of unitary test are parameter of main program imported file via the execfile function (an usage of import instead may be a

Re: Death to tuples!

2005-11-30 Thread Duncan Booth
Antoon Pardon wrote: But lets just consider. Your above code could simply be rewritten as follows. res = list() for i in range(10): res.append(i*i) I don't understand your point here? You want list() to create a new list and [] to return the same (initially empty) list

Re: Death to tuples!

2005-11-30 Thread Duncan Booth
Antoon Pardon wrote: The left one is equivalent to: __anon = [] def Foo(l): ... Foo(__anon) Foo(__anon) So, why shouldn't: res = [] for i in range(10): res.append(i*i) be equivallent to: __anon = list() ... res = __anon for i in range(10):

Re: convert string to raw string?

2004-12-06 Thread Duncan Booth
Phd wrote: I'm writing a regex related program that lets the user supplies the regex definition. Is there an easy way to convert a string into a raw string? A raw string is a feature of the syntax of Python. Python gives you several ways to write strings: single quoted, double quoted,

Re: Persistent objects

2004-12-12 Thread Duncan Booth
Paul Rubin wrote: Well, as you can see, this idea leaves a lot of details not yet thought out. But it's alluring enough that I thought I'd ask if anyone else sees something to pursue here. Have you looked at ZODB and ZEO? It does most of what you ask for, although not necessarily in the

Re: Keyword arguments - strange behaviour?

2004-12-21 Thread Duncan Booth
wrote: Can anyone explain the behaviour of python when running this script? def method(n, bits=[]): ... bits.append(n) ... print bits ... method(1) [1] method(2) [1, 2] It's the same in python 1.5, 2.3 and 2.4 so it's not a bug. But I expected the variable bits to be

Re: PHP vs. Python

2004-12-24 Thread Duncan Booth
Paul Rubin wrote: I've never heard of any large sites being done in Python, with or without scaling. By a large site I mean one that regularly gets 100 hits/sec or more. There are many sites like that out there. Those are the ones that need to be concerned about scaling. How exactly would

Re: Problem in threading

2004-12-29 Thread Duncan Booth
Gurpreet Sachdeva wrote: Also the difference of time is not much... How do we best optimize our task by using threads... please help... For most tasks splitting the processing into separate threads will result in an increase in the total time to complete the task. The only times when it

Re: Problem remotely shutting down a windows computer with python

2005-01-03 Thread Duncan Booth
Kartic wrote: Looks like this is the documented outcome. You could alternatively try setting a little XML-RPC app to invoke 'shutdown -s' on the remote PC from your PC (e.g. using Twisted Python). Or invoke 'shutdown -s -m \\machinename' on the local machine to shutdown a remote machine.

Re: Building unique comma-delimited list?

2005-01-06 Thread Duncan Booth
Roy Smith wrote: The best I've come up with is the following. Can anybody think of a simplier way? words = [foo, bar, baz, foo, bar, foo, baz] # Eliminate the duplicates; probably use set() in Python 2.4 d = dict() for w in words: d[w] = w if d.has_key

Re: Developing Commercial Applications in Python

2005-01-06 Thread Duncan Booth
Nick Vargish wrote: [EMAIL PROTECTED] writes: Can somebody there to point me any good commercial applications developed using python ? Python is used in several games, including Temple of Elemental Evil and the forthcoming Civilization 4. Humungous Games, which makes software for

Re: pulling info from website

2005-01-10 Thread Duncan Booth
bob wrote: i am trying to write a script for Xbox media center that will pull information from the bbc news website and display the headlines , how do i pull this info into a list??? Google for Python RSS reader and read some of the results. http://effbot.org/zone/effnews.htm probably

Re: syntax error in eval()

2005-01-10 Thread Duncan Booth
harold fellermann wrote: Python 2.4 (#1, Dec 30 2004, 08:00:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type help, copyright, credits or license for more information. class X : pass ... attrname = attr eval(X.%s = val % attrname , {X:X, val:5}) Traceback (most

Re: Death to tuples!

2005-12-01 Thread Duncan Booth
Antoon Pardon wrote: I know what happens, I would like to know, why they made this choice. One could argue that the expression for the default argument belongs to the code for the function and thus should be executed at call time. Not at definion time. Just as other expressions in the

Re: [[x,f(x)] for x in list that maximizes f(x)] --newbie help

2005-12-01 Thread Duncan Booth
wrote: In other words I am looking for a short version of the following: pair=[mylist[0],f(mylist[0])] for x in mylist[1:]: if f(x) pair[1]: pair=[x,f(x)] this is already very short, what else you want? May be this : max(((f(x), x) for x in mylist)) That is first

Re: [[x,f(x)] for x in list that maximizes f(x)] --newbie help

2005-12-02 Thread Duncan Booth
[EMAIL PROTECTED] wrote: Thanks. In that case, would it be easier to understand(beside the original iterative loop) if I use reduce and lambda ? You could try putting them side by side and seeing which is easiest for someone to understand: reduce(lambda (mv,mx), (v,x): mv v and (mv,mx) or

Re: General question about Python design goals

2005-12-02 Thread Duncan Booth
Alex Martelli wrote: Yep -- time tuples have also become pseudo-tuples (each element can be accessed by name as well as by index) a while ago, and I believe there's one more example besides stats and times (but I can't recall which one). Apart from time and os.stat all the uses seem to be

Re: Import path for unit tests

2005-12-02 Thread Duncan Booth
Ben Finney wrote: This works, so long as the foomodule is *not* in the path before the appended '..' directory. When writing unit tests for a development version of a package that is already installed at an older version in the Python path, this fails: the unit tests are not importing the

Re: i=2; lst=[i**=2 while i1000]

2005-12-06 Thread Duncan Booth
Daniel Schüle wrote: I am wondering if there were proposals or previous disscussions in this NG considering using 'while' in comprehension lists # pseudo code i=2 lst=[i**=2 while i1000] of course this could be easily rewritten into i=2 lst=[] while i1000: i**=2

Re: i=2; lst=[i**=2 while i1000]

2005-12-06 Thread Duncan Booth
Daniel Schüle wrote: hi, [...] # pseudo code i=2 lst=[i**=2 while i1000] of course this could be easily rewritten into i=2 lst=[] while i1000: i**=2 lst.append(i) Neither of these loops would terminate until memory is exhausted. Do you have a use case for a 'while' in a

Re: i=2; lst=[i**=2 while i1000]

2005-12-06 Thread Duncan Booth
Steve Holden wrote: lst=[i**=2 while i1000] of course this could be easily rewritten into i=2 lst=[] while i1000: i**=2 lst.append(i) ... Don't you have an interpreter you could run the code in to verify that it does indeed loop interminably? You seem to be assuming that the

Re: slice notation as values?

2005-12-09 Thread Duncan Booth
Antoon Pardon wrote: Will it ever be possible to write things like: a = 4:9 for key, value in tree.items('alfa.': 'beta.'): The first of these works fine, except you need to use the correct syntax: a = slice(4,9) range(10)[a] [4, 5, 6, 7, 8] The second also works fine, provide

Re: slice notation as values?

2005-12-09 Thread Duncan Booth
Antoon Pardon asked: If we have lst = range(10), we can write lst[slice(3,7)] instead of lst[3:7] Now my impression is that should we only have the upper notation, slices would be less usefull, because it would make using them more cumbersome. Quite right, but the syntax for

Re: slice notation as values?

2005-12-09 Thread Duncan Booth
Antoon Pardon wrote: If the user can write for key in tree['a':'b']: then he can write: for key in tree['a':'b'].iteritems(): No he can't. tree['a':'b'] would provide a list of keys that all start with an 'a'. Such a list doesn't have an iteritems method. It wouldn't even

Re: slice notation as values?

2005-12-10 Thread Duncan Booth
Antoon Pardon wrote: In general I use slices over a tree because I only want to iterate over a specific subdomain of the keys. I'm not iterested in make a tree over the subdomain. Making such a subtree would be an enormous waste of resources. Probably not unless you have really large data

Re: slice notation as values?

2005-12-11 Thread Duncan Booth
Brian Beck wrote: Antoon Pardon wrote: Will it ever be possible to write things like: a = 4:9 I made a silly recipe to do something like this a while ago, not that I'd recommend using it. But I also think it wouldn't be too far-fetched to allow slice creation using a syntax like the

Re: Problem with Lexical Scope

2005-12-12 Thread Duncan Booth
[EMAIL PROTECTED] wrote: I am using python2.4 and the following code throws a status variable not found in the inner-most function, even when I try to global it. def collect(fields, reducer): def rule(record): status = True def _(x, y): cstat = reducer(x,

Re: Problem with Lexical Scope

2005-12-12 Thread Duncan Booth
[EMAIL PROTECTED] wrote: reducer does have no side effects so I suppose short-circuting it would be the best thing. I think the only thing about the last example is that it starts things off with a zero. I think that would boink it. In that case, and assuming that fields contains at least one

Re: 0 in [True,False] returns True

2005-12-13 Thread Duncan Booth
wrote: if the purpose of the return value is to indicate a Boolean rather than an arbitrary integer. True, but if that is the only reason, Two built-in value of True/False(0/1) serves the need which is what is now(well sort of). Why have seperate types and distinguish them ? True == 1

  1   2   3   4   5   6   7   8   9   10   >