Re: rewrite for achieving speedup

2007-04-17 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: why would binding to a function-local name speeds up performance? Like any other constant-hoisting, pulling the lookup out of the loop speeds things up because otherwise Python must repeat the lookup each time through the loop (Python doesn't _know_

Re: python - dll access (ctypes or swig)

2007-04-17 Thread Alex Martelli
Larry Bates [EMAIL PROTECTED] wrote: recently learned that you can ship COM as either an .EXE or a .DLL (nobody has yet let me know why). The why is pretty obvious -- you may want to be able to instantiate a COM object either in-process, or in its own separate process, depending on that

Re: newbie question: how to read back the dictionary from a file?

2007-04-16 Thread Alex Martelli
lancered [EMAIL PROTECTED] wrote: Hi Dear all, I have some data here in the form of a dictionary, called vdic. Then I write them to a data file f using the write function as f.write(str(vdic)). The keys of this dictionary are integers and values are float numbers. Something like this:

Re: strange behaviour with keyword arguments and inheritance

2007-04-16 Thread Alex Martelli
Steve Holden [EMAIL PROTECTED] wrote: ... livibetter has a better solution. the reason is that you need to create a new list object everytime, am I right? Yes, specifically on every *call*. ...and livibetter's solution also creates a new list on every call to Child (that [] passed on

Re: script for seconds in given month?

2007-04-16 Thread Alex Martelli
edfialk [EMAIL PROTECTED] wrote: Hi, does anyone happen to know of a script that would return the number of seconds in a month if I give it a month and a year? My python is a little weak, but if anyone could offer some suggestions I think I could handle it myself, or if anyone happens to

Re: Python Feature Request: Add the using keyword which works like with in Visual Basic

2007-04-16 Thread Alex Martelli
Paul Boddie [EMAIL PROTECTED] wrote: Now I hear that the word with is being discussed for a different purpose in Py 3 as a result of a PEP and I don't want to conflict with that. The with keyword appears in 2.5 onwards. ...but needs a from __future__ import with_statement in 2.5 itself.

Re: How to better pickle an extension type

2007-04-16 Thread Alex Martelli
dgdev [EMAIL PROTECTED] wrote: I would like to pickle an extension type (written in pyrex). I have it working thus far by defining three methods: class C: # for pickling __getstate__(self): ... # make 'state_obj' return state_obj

Re: combination function in python

2007-04-15 Thread Alex Martelli
DanielJohnson [EMAIL PROTECTED] wrote: how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help. If you download and install gmpy, it's easy: import gmpy gmpy.comb(9,2) mpz(36) However,

Re: Append data to a list within a dict

2007-04-15 Thread Alex Martelli
Tina I [EMAIL PROTECTED] wrote: ... He he... at the age of 40 I'm well beyond school work ;) Why would that be? My wife's over 40, yet she's a student (currently at Stanford -- they were overjoyed to admit her, with lot of life experience as well as previous studies, apparently). She's not

Re: combination function in python

2007-04-15 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: You could take it up with the gmpy author and induce him to get gmpy included in the standard distro if you are so inclined. Alex Martelli knows more about that subject than I and it would be pointless for me to bug him about it. gmpy is LGPL

Re: Any Pythonistas in Mexico?

2007-04-15 Thread Alex Martelli
Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 12 Apr 2007 10:56:32 -0300, Marcpp [EMAIL PROTECTED] escribió: On 12 abr, 09:41, Hugo González Monteverde [EMAIL PROTECTED] wrote: Leí este mail viejísimo en una lista. Yo uso Python y también quería saber quién pythoneaba en México.

Re: Calling private base methods

2007-04-15 Thread Alex Martelli
Isaac Rodriguez [EMAIL PROTECTED] wrote: The fact that I had to resort to this trick is a big indication of course that genuinely private members (as opposed to a 'keep off' naming convention) are a bad idea in general. The fact that you had to resort to this trick is a big indication

Re: pyparsing Catch-22

2007-04-15 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: 1) Even though the download at sourceforge said the file name was: pyparsing-1.4.6.tar.gz it was downloaded to my Desktop as: pyparsing-1.4.6.tar Did os x 10.4.7 automatically unzip it for me? .gz means the file was compressed with gzip, but I didn't

Re: ulimit on open sockets ?

2007-04-14 Thread Alex Martelli
Maxim Veksler [EMAIL PROTECTED] wrote: ... Thank you. I'm attaching the full code so far for reference, sadly it still doesn't work. It seems that select.select gets it's count of fd's not from the amount passed to it by the sub_list but from the kernel (or whatever) count for the process;

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Alex Martelli
faulkner [EMAIL PROTECTED] wrote: ... __future__ is used to access upcoming features, and changing the base offset is not [and never will be] slated for future development. zero has been used as the base offset in all real languages since the dawn of time, and isn't something that can be

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Alex Martelli
Sherm Pendley [EMAIL PROTECTED] wrote: Paddy [EMAIL PROTECTED] writes: I don't think we should add it to Python because it would make porting VB code easier. Great Cthulhu no! I chimed in because your first comment regarding Perl implied that it's commonplace for Perl programmers to

Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread Alex Martelli
Dennis Lee Bieber [EMAIL PROTECTED] wrote: ... In Python, the variable NAME does NOT define storage; unlike most other classical languages where the variable name is a storage address, and the value of the RHS is COPIED to that address. Python does not do such copying. Names are

Re: function with list argument defaulting to [] - what's going on here???

2007-04-14 Thread Alex Martelli
Mike [EMAIL PROTECTED] wrote: ... Why is r not being reset to the empty list on subsequent calls? It seems like it should be reinitialized when not explicitly provided. http://www.python.org/doc/faq/general/#why-are-default-values-shared-be tween-objects Alex --

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 14 Apr 2007 20:34:46 -0700, Dan Bishop wrote: On Apr 14, 10:55 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote: The FORTRAN family had started as 1-based (F95, and Ada, now allow for each array to have its own base = x : array

Re: function with list argument defaulting to [] - what's going on here???

2007-04-14 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: On Sun, 15 Apr 2007 05:29:01 +0200, BJörn Lindqvist wrote: This comes up so often that I wonder whether Python should issue a warning when it sees [] or {} as a default argument. What do people think? A misuse or good use of warnings? I

Re: Lists and Tuples and Much More

2007-04-14 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: It sure looks like t changed, and therefore t is NOT immutable--and the whole tuples are immutable mantra is a lie. However, the list http://mail.python.org/pipermail/python-list/2002-April/140258.html So, the statue that points to Hotel Belfiore had suddenly

Re: how to strip the domain name in python?

2007-04-13 Thread Alex Martelli
[EMAIL PROTECTED] wrote: Hi, I have a list of url names like this, and I am trying to strip out the domain name using the following code: http://www.cnn.com www.yahoo.com http://www.ebay.co.uk pattern = re.compile(http:(.*)\.(.*), re.S) match = re.findall(pattern, line) if

Re: ulimit on open sockets ?

2007-04-12 Thread Alex Martelli
On Apr 12, 2007, at 1:17 PM, Maxim Veksler wrote: ... Now, someone I work with suggested a simple work around Pass the list objects in groups of 1024 each time to the select.select structure. I think it's acceptable and good advice, the thing is I don't know how to implement this the

Re: passing class by reference does not work??

2007-04-11 Thread Alex Martelli
wswilson [EMAIL PROTECTED] wrote: Here is my code: class A(): val = 0 def b(item, a): a.val = a.val + 1 return item + a.val def c(): d = [1, 2, 3] print [b(item, A()) for item in d] c() I expected this to output [2, 4, 6]. However, it outputs [2,

Re: run function in separate process

2007-04-11 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... somebody points me to a web page/reference that says how to call a function then reclaim the whole memory back in python. Meanwhile, the best that I could do is fork a process, compute the results, and return them back to the parent process. This I That's my

Re: Exec Statement Question

2007-04-09 Thread Alex Martelli
Gregory Piñero [EMAIL PROTECTED] wrote: I'm curious why this code isn't working how I expect it to: import sys d=3 def func1(a,b,c): print a,b,c,d print sys.path exec func1(1,2,3) in {'func1':func1} returns: 1 2 3 3 [ sys.path stuff ] Since I'm telling exec

Re: shelve error

2007-04-09 Thread Alex Martelli
Peter Otten [EMAIL PROTECTED] wrote: Alex Martelli wrote: BTW, if you DO want to call shelve.open on a path f that may correspond to an arbitrary existing file (and want to toss away the previous contents of that file, if any) the correct way to call is then: s = shelve.open

Re: Classes with initialization

2007-04-09 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... Also: can someone enlighten me as to when code in class scope is run, exactly? It's run as a part of the execution of the class statement. if a class A has a metaclass M, then M.__init__ does not seem to get the code in A's class scope in its arguments

Re: RFC: Assignment as expression (pre-PEP)

2007-04-09 Thread Alex Martelli
Adam Atlas [EMAIL PROTECTED] wrote: Hasn't this been discussed many many times before? I think Guido has been favourable to the idea of allowing :=, but that was a long time ago, and I don't think anything ever came of it. Personally, if anything, I'd like to see more use of the 'as'

Re: ulimit on open sockets ?

2007-04-09 Thread Alex Martelli
Maxim Veksler [EMAIL PROTECTED] wrote: ValueError: filedescriptor out of range in select() Should I be using a different version of select or something? Or select typically supports 1024 FDs at most (a design limit of the underlying operating system). You may want to try poll instead

Re: RFC: Assignment as expression (pre-PEP)

2007-04-08 Thread Alex Martelli
Dustan [EMAIL PROTECTED] wrote: class Wrapper(object): def __init__(self, obj): self.obj = obj def getit(self): return self.obj def setit(self, obj): self.obj = obj return obj Yeah, that's substantialy the same

Re: how to remove multiple occurrences of a string within a list?

2007-04-08 Thread Alex Martelli
Ayaz Ahmed Khan [EMAIL PROTECTED] wrote: ... I am getting varying results on my system on repeated runs. What about itertools.ifilter()? Calling itertools.ifilter returns an iterator; if you never iterate on that iterator, that, of course, is going to be very fast (O(1), since it does not

Re: How do I get a slice of a string held in a tuple?

2007-04-08 Thread Alex Martelli
Lorenzo [EMAIL PROTECTED] wrote: ... elapsedTime = mydata[1] index = elapsedTime.find(real) # the index will have a value 0f 110 totaltime = elapsedTime[index:] ... Oops! I sent the wrong piece of code. The above is actually the work around which actually works. The bad

Re: shelve error

2007-04-08 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: On Apr 4, 10:22 pm, [EMAIL PROTECTED] wrote: how did you generate aaa.txt? Ok, I got it to work by supplying a filename that didn't previously exist. Neither the book I am reading, Beginning Python: From Novice to Professional nor the book I am using as a

Re: shelve error

2007-04-08 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: ... In my opinion, the most valuable thing you could do for a next printing would be to expand the index to 3 times its current length. Suggest that to O'Reilly: they're the one who prepare the index, not me; I only get to point out errors I may notice on it

Re: block scope?

2007-04-07 Thread Alex Martelli
Neal Becker [EMAIL PROTECTED] wrote: ... i = 5 for my i in xrange(4): if i: # skips first when i is 0 my i = 100 if i: print i # of course 100 break print i # i is between 0 3 here print i # i is 5 here

Re: block scope?

2007-04-07 Thread Alex Martelli
Steve Holden [EMAIL PROTECTED] wrote: What do you think the chances are of this being accepted for Python 3.0? It is indeed about the most rational approach, though of course it does cause problems with dynamic namespaces. What problems do you have in mind? The compiler already determines

Re: block scope?

2007-04-07 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: Thus the following example does not compile: class Test { public static void main(String[] args) { int i; for (int i = 0; i 10; i++) I'm ok

Re: itertools, functools, file enhancement ideas

2007-04-07 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: I just had to write some programs that crunched a lot of large files, both text and binary. As I use iterators more I find myself wishing for some maybe-obvious enhancements: 1. File iterator for blocks of chars: f = open('foo')

Re: block scope?

2007-04-07 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Alex Martelli [EMAIL PROTECTED] wrote: Steve Holden [EMAIL PROTECTED] wrote: What do you think the chances are of this being accepted for Python 3.0? It is indeed about the most rational approach, though of course it does

Re: block scope?

2007-04-07 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: exec? option 1: that just runs the compiler a bit later ... Besides exec, there's also locals(), i.e. locals['x'] = 5 can shadow a variable. Any bad results are probably deserved ;) locals['x']=5

Re: Why NOT only one class per file?

2007-04-06 Thread Alex Martelli
John Nagle [EMAIL PROTECTED] wrote: systems that didn't work that way, in which the program source was manipulated within the language environment, in a more structured fashion. Smalltalk, LISP, and (wierdly) Forth environments have been built that way. But it never really caught on. APL

Re: how to remove multiple occurrences of a string within a list?

2007-04-04 Thread Alex Martelli
Amit Khemka [EMAIL PROTECTED] wrote: On 3 Apr 2007 11:20:33 -0700, bahoo [EMAIL PROTECTED] wrote: Hi, I have a list like ['0024', 'haha', '0024'] and as output I want ['haha'] If I myList.remove('0024') then only the first instance of '0024' is removed. To remove all items

Re: Prevent Modification of Script?

2007-04-04 Thread Alex Martelli
Ben Finney [EMAIL PROTECTED] wrote: ts-dev [EMAIL PROTECTED] writes: Is it possible to prevent modification of a python file once its been deployed? Prevent modification by whom? You can't prevent modification by the person who owns the machine. It's in their possession, and

Re: compiling modules with VS 2008 for python 2.4 prepared with Visual Studio 2003

2007-04-04 Thread Alex Martelli
alf [EMAIL PROTECTED] wrote: Hi, I want to add some library but it can not be comipled? Here is an output: If you don't have the needed compiler installed (in this case, VS 2003, while it looks like your installation has VS 2005 instead), sure. D:\cl Microsoft (R) 32-bit C/C++ Optimizing

Re: pyc file [Newbie Question]

2007-04-04 Thread Alex Martelli
Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 03 Apr 2007 12:40:23 -0300, Jim Aikin [EMAIL PROTECTED] escribió: The Tutorial is very good, but there are numerous topics that it slides past (as it would have to do, in order to avoid being ten times as long). I haven't yet gotten

Re: function for counting items in a sequence

2007-04-04 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: Alex Martelli wrote: If we had a turn sequence into bag function somewhere (and it might be worth having it for other reasons): def bagit(seq): import collections d = collections.defaultdict(int) for x in seq: d[x] += 1

Re: Getting word frequencies from files which are in folder.

2007-04-04 Thread Alex Martelli
[EMAIL PROTECTED] wrote: This sounds suspiciously like a homework assignment. I don't think you'll get much help for this one, unless you show some code you wrote yourself already with a specific question about problems you're having Well you have some right. I will make it more

Re: passing options to __import__

2007-04-03 Thread Alex Martelli
Harold Fellermann [EMAIL PROTECTED] wrote: ... Within my program, I am importing a module via __import__(module_name,globals(),locals()) The globals() you're passing are those of the *importing* module, and have no effect on those of the *imported* module. and I want to pass comand line

Re: Sorting a multidimensional array by multiple keys

2007-04-02 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: Thomas Krüger wrote: Alex Martelli schrieb: Thomas Krüger [EMAIL PROTECTED] wrote: def sorter(a, b): return cmp(a.id, b.id) obj_lst.sort(sorter) A MUCH better way to obtain exactly the same semantics would be: def getid

Re: manually implementing staticmethod()?

2007-04-01 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: ... I'm using python 2.3.5. On Mar 29, 9:34 am, [EMAIL PROTECTED] (Alex Martelli) wrote: Simplest way: class smethod(object): def __init__(self, f): self.f=f def __call__(self, *a, **k): return self.f(*a, **k) Alex Interesting. That looks

Re: can a method access/set another's variables?

2007-04-01 Thread Alex Martelli
asdf1234234 [EMAIL PROTECTED] wrote: My code is: -a.py- import b class A: def __init__(self): pass Incidentally, these last two lines are totally, utterly useless. Do NOT define special methods like this -- just omit the whole def statement and you'll have identical

Re: Sorting a multidimensional array by multiple keys

2007-04-01 Thread Alex Martelli
Thomas Krüger [EMAIL PROTECTED] wrote: Rehceb Rotkiv schrieb: can I sort a multidimensional array in Python by multiple sort keys? A litte code sample would be nice! You can pass a function as argument to the sort method of a list. The function should take two arguments and return -1, 0

Re: Indentation for code readability

2007-03-30 Thread Alex Martelli
Thomas Krüger [EMAIL PROTECTED] wrote: BTW: having one way to do it is one of the main ideas of Python's philosophy. Yes, just like C's -- see point 4 in the Spirit of C summary taken from the ISO Standard for C and quoted e.g. at http://www.artima.com/cppsource/spiritofc.html . Of course,

Re: which methods to use?

2007-03-29 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: ... In general: - use a list comprehension when you need to calculate the list items - use slicing when you are copying an actual list, or if you don't care what type of object you get - use the list() function when your existing object might

Re: which methods to use?

2007-03-29 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... under what circumstances do we need to create a copy of a tuple :- btuple = atuple[:]. tuples are immutable, so wouldn't it be wasting memory? Nah -- btuple is atuple. The copy is a no-op, in this case. another query, in the docs, list(a) and a[:] does the

Re: Modal value of an array

2007-03-29 Thread Alex Martelli
Ben Finney [EMAIL PROTECTED] wrote: ... That's not the only case though. What do you expect to be returned for an input of [eggs, beans, beans, eggs, spam] ? Assuming you want *a* mode value, and any one will do (e.g. any of spam, eggs or beans is okay), I'd write it this way as a first

Re: gmpy floating point exception

2007-03-29 Thread Alex Martelli
Martin Manns [EMAIL PROTECTED] wrote: Hi, I am experiencing some trouble with gmpy v1.01. Multiplying an mpq with inf results in a floating point exception that exits python. Has this already been fixed in newer gmpy versions? No, I can reproduce the problem (on a Mac with an Intel CPU)

Re: What is the timeout value of HTTP

2007-03-29 Thread Alex Martelli
ken [EMAIL PROTECTED] wrote: Can you please tell me what is the timeout value of httplib.HTTP? i.e. how long python will wait for a response in the below code? h = httplib.HTTP(self.url, 8080) h.putrequest('GET', '/sample/?url=' + self.url) h.endheaders() HTTP per se

Re: Finding a module's sub modules at runtime

2007-03-29 Thread Alex Martelli
Joshua J. Kugler [EMAIL PROTECTED] wrote: still be nicely portable. It just seems that since Python is gathering that information anyway, it should make it available without me having to walk the directory tree. Sorry, where is Python gathering that information anyway? Unless I'm mistaken,

Re: manually implementing staticmethod()?

2007-03-29 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: Hi, Can someone show me how to manually implement staticmethod()? Here is Simplest way: class smethod(object): def __init__(self, f): self.f=f def __call__(self, *a, **k): return self.f(*a, **k) Alex --

Re: Finding a module's sub modules at runtime

2007-03-29 Thread Alex Martelli
Joshua J. Kugler [EMAIL PROTECTED] wrote: On Thursday 29 March 2007 07:33, Alex Martelli wrote: Joshua J. Kugler [EMAIL PROTECTED] wrote: still be nicely portable. It just seems that since Python is gathering that information anyway, it should make it available without me having

Re: Modal value of an array

2007-03-29 Thread Alex Martelli
Paddy [EMAIL PROTECTED] wrote: ... A bit more directly: foo = [spam, eggs, spam, spam, spam, beans, eggs] max(foo, key=foo.count) 'spam' Alex This doesn't call foo.count for duplicate entries by keeping a cache foo = [spam, eggs, spam, spam, spam, beans, eggs] def

Re: how can I clear a dictionary in python

2007-03-29 Thread Alex Martelli
Russ [EMAIL PROTECTED] wrote: This little squabble got me thinking. I normally just use the myDict={} method of clearing a dictionary when I know there are no other references to it. However, I wonder how the efficiency of relying on the garbage collector to clear a dictionary compares with

Re: Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread Alex Martelli
glomde [EMAIL PROTECTED] wrote: Hi, I tried to write a decorator for that should be for methods but for some reasons it doens seem to work when you try to do it on the __getattr__ method in a class. Could anybody give some hints why this is? ... a.test # This doesnt call the __get__ !!!

Re: Can't use class variable with private nested class

2007-03-27 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... class Outer: class Inner: printOnce = True def __init__(self): if Outer.Inner.printOnce: print 'Printing once.' Outer.Inner.printOnce = False

Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... So I'ld suggest to start with downloading the Enthought edition of Python, and you can judge for yourself within 10 minutes, if it's fast enough. cheers, Stef Mientki Is there a mac version??

Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Alex Martelli
Cameron Laird [EMAIL PROTECTED] wrote: ... If you're just trying to learn and check things out, it might be better to get a more recent Python from python.org (2.5 or 2.4.4) and the various other packages as and when you need them (you can use the MacEnthon list as a guide:-). You'll need

Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I've been told that Both Fortran and Python are easy to read, and are quite useful in creating scientific apps for the number crunching, but Incidentally, and a bit outside what you asked: if your number crunching involves anything beyond linear

Re: PyImport_ImportModule/embedding: surprising behaviors

2007-03-24 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], David Abrahams [EMAIL PROTECTED] wrote: I was under the impression that both the current directory *and* the python library directory were already, automatically, in sys.path, so I'm really surprised to see this. Am I doing

Re: Removing Python 2.4.4 on OSX

2007-03-24 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: On Mar 24, 9:40 pm, 7stud [EMAIL PROTECTED] wrote: On Mar 24, 8:18 pm, Michael Bentley [EMAIL PROTECTED] wrote: On Mar 24, 2007, at 12:30 PM, Robert Hicks wrote: I want to upgrade to 2.5 but I don't see any unistall instructions anywhere.

Re: Using remote source code

2007-03-24 Thread Alex Martelli
[EMAIL PROTECTED] wrote: Is there any possible way that I can place a .py file on the internet, and use that source code in an .py file on my computer? You can write an import hook in any way you like; see http://www.python.org/dev/peps/pep-0302/ . Here's a trivial example (bereft of much

Re: Join strings - very simple Q.

2007-03-24 Thread Alex Martelli
Hendrik van Rooyen [EMAIL PROTECTED] wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 23 Mar 2007 13:15:29 -0700, John Machin wrote: OK, I'll bite: This was new in late 2000 when Python 2.0 was released. Where have you been in the last ~6.5 years? Western civilization

Re: Exception passing

2007-03-23 Thread Alex Martelli
Thomas Dybdahl Ahle [EMAIL PROTECTED] wrote: Hi, I have a function, which looks like the following: connecting = False def func (): global connecting connecting = True try: # Do lot of network stuff except Exception, e: connecting = False raise e

Re: Idiom for running compiled python scripts?

2007-03-23 Thread Alex Martelli
Mark [EMAIL PROTECTED] wrote: ... so I could just do a python_compile_and_run myscript.py and it would do what I want, i.e. run myscript.pyc if available and valid, generate and run it if necessary. You can use python -c 'import myscript; myscript.main()' and variations thereon. Alex --

Re: Garbage collection

2007-03-22 Thread Alex Martelli
Tom Wright [EMAIL PROTECTED] wrote: real programs. I can't help thinking that there are some situations where you need a lot of memory for a short time though, and it would be nice to be able to use it briefly and then hand most of it back. Still, I see the practical difficulties with doing

Re: Garbage collection

2007-03-22 Thread Alex Martelli
Steve Holden [EMAIL PROTECTED] wrote: ... a. fork b. do the memory-hogging work in the child process c. meanwhile the parent just waits d. the child sends back to the parent the small results e. the child terminates f. the parent proceeds merrily I learned this

Re: design question: generator object with other attributes

2007-03-22 Thread Alex Martelli
Alan Isaac [EMAIL PROTECTED] wrote: Essentially I want a generator that I can query about its characteristics. (E.g., a random number generator that I want to be able to ask about is distributional parameters.) I am thinking of a class that wraps a generator. An object of this class will

Re: Python 3000 idea: reversing the order of chained assignments

2007-03-21 Thread Alex Martelli
John Nagle [EMAIL PROTECTED] wrote: Marcin Ciura wrote: Neither would I. I must have expressed myself not clearly enough. Currently x = y = z is roughly equivalent to x = z y = z I propose to change it to y = z x = z Actually, it is equivalent to y = z x =

Re: When is List Comprehension inappropriate?

2007-03-21 Thread Alex Martelli
Paddy [EMAIL PROTECTED] wrote: ... I have found that I have gone too far when I used listcomps for their sideeffects rather than wanting the list produced, for example the I agree. second listcomp below is an expression as statement I don't want the list produced - just the effect on

Re: When is List Comprehension inappropriate?

2007-03-20 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Alex Martelli [EMAIL PROTECTED] wrote: list(iterimage(etc etc)) is surely a better way to express identical semantics. More generally, [x for x in whatever] (whether x is a single name or gets peculiarly unpacked and repacked

Re: Still the __new__ hell ...

2007-03-20 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Alex Martelli [EMAIL PROTECTED] wrote: Steve Holden [EMAIL PROTECTED] wrote: basestring is a *type*. basestring type 'basestring' It's the base class of which both str and unicode are subclasses. I believe

Re: How many connections can accept a 'binded' socket?

2007-03-20 Thread Alex Martelli
Laurent Pointal [EMAIL PROTECTED] wrote: billiejoex a écrit : Hi, I'm writing a small asyncore-based server application serving a lot of clients. When I have to handle more than 1021 client simoultaneously the 'binded' socket object raises an error: [...] connections: 1018

Re: any ways to judge whether an object is initilized or not in a class

2007-03-20 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: ... There are plenty of reasons for preferring new style classes. If those reasons hold for you, then of course you should use new style classes. But that's not the same thing as saying that you should use new style classes *even when you don't

Re: Load three different modules which have the same name

2007-03-20 Thread Alex Martelli
Gabriel Genellina [EMAIL PROTECTED] wrote: ... example i could load Person from Person (in alpha) as, Person_Alpha or something like that in sys.modules? not sure how I might do that. Use the as clause when importing; it's almost the same phrase you wrote above: from alpha.Person

Re: Wanted: a python24 package for Python 2.3

2007-03-20 Thread Alex Martelli
Jonathan Fine [EMAIL PROTECTED] wrote: ... In other words, I'm asking for a python24 package that contains all (or most) of the modules that are new to Python 2.4. For subprocess specifically, see http://www.lysator.liu.se/~astrand/popen5/ . I don't think anybody's ever packaged up ALL the

Re: Documentation for str() could use some adjustment - Unicode issue

2007-03-20 Thread Alex Martelli
John Nagle [EMAIL PROTECTED] wrote: ... Are you looking at p. 109 of the 2nd edition of the Nutshell? No, I'm looking at the original edition from 2003. That was what Borders had in stock late last year. Eeek -- the 2nd edition came out in July 2006, and several months later

Re: dictionary.copy()?

2007-03-20 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: Here is some example code: d = {a:hello, b:[1, 2, 3]} x = d.copy() d[b][0]=10 print x output: {'a': 'hello', 'b': [10, 2, 3]} It looks like the key names of a dictionary store pointers to the values? Or does a dictionary object manage pointers to

Re: When is List Comprehension inappropriate?

2007-03-19 Thread Alex Martelli
Ben [EMAIL PROTECTED] wrote: I have recently learned how list comprehension works and am finding it extremely cool. I am worried, however, that I may be stuffing it into places that it does not belong. What's the most pythony way to do this: even = [] for x in range(0,width,2):

Re: Executing a list of functions

2007-03-19 Thread Alex Martelli
HMS Surprise [EMAIL PROTECTED] wrote: ... Why is apply deprecated? Because it does exacly the same job as just calling the function with *a/**k, and there should preferably be only one obvious way to perform a given task (this guiding principle leads to simplicity in the language, and is

Re: Documentation for str() could use some adjustment - Unicode issue

2007-03-19 Thread Alex Martelli
John Nagle [EMAIL PROTECTED] wrote: ... The real problem is the published books on Python: Learning Python, by Lutz and Ascher: str(string) -- returns the string representation of any object. Python in a Nutshell, by Martelli Doesn't really address the issue, but says that

Re: When is List Comprehension inappropriate?

2007-03-19 Thread Alex Martelli
BJörn Lindqvist [EMAIL PROTECTED] wrote: ... even2 = [(pos, col) for pos, col in iterimage(im, width, height, 2)] list(iterimage(etc etc)) is surely a better way to express identical semantics. More generally, [x for x in whatever] (whether x is a single name or gets peculiarly unpacked and

Re: Still the __new__ hell ...

2007-03-19 Thread Alex Martelli
Steve Holden [EMAIL PROTECTED] wrote: greg wrote: Paulo da Silva wrote: As a relatively inexperient in python, how could I know that a 'string' is an instance of basestring? isinstance(x, basestring) This works because basestring is defined as the tuple (str, unicode) and

Re: * operator--as in *args?

2007-03-18 Thread Alex Martelli
Gabriel Genellina [EMAIL PROTECTED] wrote: ... As far as it goes, yes. More generally, with any iterable x, the *x construct in function call will pass as positional arguments exactly those items which (e.g.) would be printed by the loop: for item in x: print x [[this applies

Re: list comprehension help

2007-03-18 Thread Alex Martelli
George Sakkis [EMAIL PROTECTED] wrote: On Mar 18, 12:11 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi I need to process a really huge text file (4GB) and this is what i need to do. It takes for ever to complete this. I read some where that list comprehension can fast up things. Can

Re: list comprehension help

2007-03-18 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... files (you see huge is really relative ;-)) on 2-4GB RAM boxes and setting a big buffer (1GB or more) reduces the wall time by 30 to 50% compared to the default value. BerkeleyDB should have a buffering Out of curiosity, what OS and FS

Re: class objects, method objects, function objects

2007-03-18 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: ... But the last part of the passage makes no sense to me: -- When the method object is called with an argument list, it is unpacked again, a new argument list is constructed from the instance object and the original argument list, and the function object

Re: struct.pack returns nothing

2007-03-18 Thread Alex Martelli
[EMAIL PROTECTED] wrote: If I build a strict with: import struct print struck.pack ('i', 1) it returns a '\n'. What's wrong with it??? :( You're trying to print a binary string that's hardly printable as-is. Try printing its repr(...) and you'll see all the binary zeros and one you

Re: Finding the insertion point in a list

2007-03-18 Thread Alex Martelli
7stud [EMAIL PROTECTED] wrote: On Mar 18, 2:23 am, Paul Rubin http://[EMAIL PROTECTED] wrote: Steve Holden [EMAIL PROTECTED] writes: max(i for i,t in enumerate(x) if t = y) Those are actually pretty direct. How about a solution (like the bisect one suggested almost as soon as

Re: list comprehension help

2007-03-18 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On 3/18/07, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In [EMAIL PROTECTED], Daniel Nogradi wrote: f = open('file.txt','r') for line in f: db[line.split(' ')[0]] = line.split(' ')[-1] db.sync() What is db

<    1   2   3   4   5   6   7   8   9   10   >