Re: catching empty strings (I guess that's what they are)

2007-07-09 Thread Alex Martelli
lower()) I prefer yours (it's simpler IMHO), but if I was doing a code review I would accept either of these. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamic method

2007-07-10 Thread Alex Popescu
> > myClass.method = method_for_class > > inst = myClass( ) > inst.method( 'hello' ) I think a solution may be using the new module and the function instancemethod: instancemethod(function, instance, class) This function will return a method object, bound to instance, or unbound if instance is None. function must be callable. ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: stripping the first byte from a binary file

2007-07-11 Thread Alex Popescu
() and write() methods in a similar way to remove > > the first byte? For whatever reason I can't seem to make it work > > myself. Thanks again. > > Funny. I just happened to read ESR's "how to ask questions the smart way" and > your posts match quite a few o

Re: stripping the first byte from a binary file

2007-07-11 Thread Alex Popescu
I know seek is just about positioning and nothing else. So, in fact the problem boils down to os support for deleting a bytes. bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: stripping the first byte from a binary file

2007-07-11 Thread Alex Popescu
On Jul 11, 7:45 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Alex Popescu wrote: > > On Jul 11, 4:15 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > >> > Forgive my newbie ignorance, but I am wondering why the other method

Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-11 Thread Alex Martelli
sks: the latter group may be the ones who "dread errors", and therefore miss the "making mistakes, experiencing failures, and learning from them" that is "how we improve". Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Lists in classes

2007-07-12 Thread Alex Popescu
becomes a class field/member. For defining instance members you need to always prefix those with self (this) in the contexts it is available (f.e. in the instance method context). bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: web page text extractor

2007-07-12 Thread Alex Popescu
',text) > >return text > > -- > Andre Engels, [EMAIL PROTECTED] > ICQ: 6260644 -- Skype: a_engels Andre I think that unfortunately your solution will not ignore inlined scripting, inlined styling, etc. On the otherside, I don't think there are many solutions available, other than the Lynx approach somebody has already suggested. bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: Can a low-level programmer learn OOP?

2007-07-13 Thread Alex Martelli
ign (unless you consider microcode "HW", and, personally, I don't;-). [[Fortunately as a part of the CE minor I did learn Fortran, Lisp and Pascal, and a few machine-languages too, so I wasn't totally blown away when I found myself earning a living by programming rather than by designing chips, but that's another story:-)]] Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting values out of a CSV

2007-07-14 Thread Alex Popescu
sult in the same performance or at least have clear/ documented performance. I don't think we really want to see in code something like: if threshold: do_it_with_list_function else: do_it_with_list_comprehension bests, ./alex -- .w( the_mindstorm )p. > -- > Gabriel Genelli

Re: Lists in classes

2007-07-15 Thread Alex Popescu
On Jul 13, 6:02 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Alex Popescu a écrit : > (snip) > > > > > You are defining the list in the class context and so it becomes a > > class field/member. > > 'attribute' is the pythonic term. Thank

Re: Trying to choose between python and java

2007-07-15 Thread Alex Popescu
r your app (at least not if they don't have an idea about your environment, your existing pl knowledge, your app, etc.). bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: Circular import problem

2007-07-15 Thread Alex Popescu
grooves is a class/function defined inside the > module, you don't need to import it before using it. I am a bit confused: I think the above should be: if MMA.grooves in a class/function defined inside the module MMA, you don't need to import the class/function before using it, but o

Re: Getting values out of a CSV

2007-07-15 Thread Alex Popescu
On Jul 15, 3:00 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Alex Popescu wrote: > > On Jul 14, 5:55 am, "Gabriel Genellina" <[EMAIL PROTECTED]> > > wrote: > >> So, as always, one should measure in each specific case if optimization is > >>

Re: Circular import problem

2007-07-15 Thread Alex Popescu
On Jul 15, 10:08 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Sun, 15 Jul 2007 08:49:54 -0300, Alex Popescu > <[EMAIL PROTECTED]> escribió: > > > > >> > But, I still don't understand how python can access a function in a > >

Re: Accessing Python variables in an extension module

2007-07-15 Thread Alex Martelli
; me. If they're global variables of a certain module XYZ, your C code may "import" XZY (or look it up in the C API equivalent of the sys.modules dict) and get those variables as attributes of object XYZ. Is that what you mean by ``variables defined in your Python program''...? Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to choose between python and java

2007-07-15 Thread Alex Martelli
James T. Dennis <[EMAIL PROTECTED]> wrote: ... > You can start writing all your code now as: print() --- calling > the statement as if it were a function. Then you're future Python ...except that your output format will thereby become disgusting...: >>> name

Re: how to implementation latent semantic indexing in python..

2007-07-15 Thread Alex Martelli
78ncp <[EMAIL PROTECTED]> wrote: > hi... > how to implementation algorithm latent semantic indexing in python > programming...?? You may get more responses (as in, >0!-) if you give some URL about what this algorithm is supposed to do. Alex -- http://mail.python.org/mailm

Re: Accessing Python variables in an extension module

2007-07-16 Thread Alex Martelli
MD <[EMAIL PROTECTED]> wrote: > Hi Alex, >Thanks for your reply. It was exactly what I was looking for. Two > additional questions > 1) Is there anyway to find out which modules a variable belongs to > when I have only its name (and its not qualified with the

Re: how to find available classes in a file ?

2007-07-16 Thread Alex Popescu
7;t checked it yet. bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessing Python variables in an extension module

2007-07-16 Thread Alex Martelli
MD <[EMAIL PROTECTED]> wrote: > Hi Alex, > Thanks for the answer. Are there any C defines (for e.g. STRING, > BOOLEAN) corresponding to each Python type? No, I know of no such "defines" -- what good would they do? Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: how to find available classes in a file ?

2007-07-17 Thread Alex Popescu
On Jul 17, 4:41 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu > <[EMAIL PROTECTED]> escribió: > > > On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]> > > wrote: > >> I want to hav

Re: Can a low-level programmer learn OOP?

2007-07-17 Thread Alex Martelli
; OOP languages that still follow the variable=>memory address containing > object structure. C++, definitely. But most OO languages, like Java &c, use a more modern "object reference" naming scheme, just like Python, FP languages, etc. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: how to find available classes in a file ?

2007-07-18 Thread Alex Popescu
On Jul 17, 4:41 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu > <[EMAIL PROTECTED]> escribió: > > > On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]> > > wrote: > >> I want to hav

Re: how to find available classes in a file ?

2007-07-18 Thread Alex Popescu
On Jul 17, 4:41 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu > <[EMAIL PROTECTED]> escribió: > > > On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]> > > wrote: > >> I want to hav

Re: Posted messages not appearing in this group

2007-07-18 Thread Alex Popescu
en checking with gmane I've noticed that all my posts got in (and now I am trying to figure out how can I apologize for multiple posts :-) ). bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to find available classes in a file ?

2007-07-18 Thread Alex Popescu
Alex Popescu gmail.com> writes: > > On Jul 17, 4:41 am, "Gabriel Genellina" yahoo.com.ar> > wrote: > > En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu > > gmail.com> escribi > I apologize for posting the previous message a couple of time

Re: how to implementation latent semantic indexing in python..

2007-07-18 Thread Alex Martelli
patents supposed to last 17 years, anyway? A patent granted in 1989 should have expired in 2006, I believe (though IANAL, so...). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: type conversions for comparison operators

2007-07-18 Thread Alex Martelli
llow heterogeneous order-comparisons any more (they can't be removed in 2.* without breaking backwards compatibility -- 3.0 is allowed to break backwards compatibility, but 2.* isn't). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Real-time Update

2007-07-19 Thread Alex Martelli
eep losing links. <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965> . Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: A way to re-organize a list

2007-07-19 Thread Alex Martelli
x27;a', 1), ('A', 'a', 2), ('A', 'a', 3), ('A', 'b', 1), ('A', 'b', 2)], [('B', 'a', 1), ('B', 'b', 1)]] However, you want a second level of grouping -- so, instead of the plain list(ss), you need to apply this concept again: >>> [[list(sss) for k,sss in gb(ss,itm(1))] for k, ss in gb(l, itm(0))] [[[('A', 'a', 1), ('A', 'a', 2), ('A', 'a', 3)], [('A', 'b', 1), ('A', 'b', 2)]], [[('B', 'a', 1)], [('B', 'b', 1)]]] ...and there you are. May be more readable with a little auxiliary function to capture what I just called "this concept" with a readable name: >>> def group(s, i): return [list(ss) for k, ss in gb(s, itm(i))] ... >>> [group(ss,1) for ss in group(l,0)] [[[('A', 'a', 1), ('A', 'a', 2), ('A', 'a', 3)], [('A', 'b', 1), ('A', 'b', 2)]], [[('B', 'a', 1)], [('B', 'b', 1)]]] This does one more "list(...)" step, but if your lists aren't huge the readability may be worth the small slow-down. Alex -- http://mail.python.org/mailman/listinfo/python-list

Efficiently removing duplicate rows from a 2-dimensional Numeric array

2007-07-19 Thread Alex Mont
values()) According to the profiler the loop takes about 7 seconds and the call to array() 10 seconds with N=1,700,000. Is there a faster way to do this using Numeric? -Alex Mont -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting between objects

2007-07-20 Thread Alex Popescu
ve differently or implement a new protocol described by the second object (I think this is the Pythonic way of calling it). bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Pythonic way for missing dict keys

2007-07-20 Thread Alex Popescu
bject() is evaluated at call time, and so if the initialization is expensive you will probably see surprises. thanks in advance, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic way for missing dict keys

2007-07-20 Thread Alex Popescu
Neil Cerutti <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > On 2007-07-20, Alex Popescu <[EMAIL PROTECTED]> wrote: >> Hi all! >> >> I am pretty sure this has been asked a couple of times, but I >> don't seem to find it on the archives (Google

Re: Pythonic way for missing dict keys

2007-07-20 Thread Alex Popescu
u expect that there is key in dict > I may be missing something but I think the 3 approaches are completely equivalent in terms of functionality. ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting dict keys

2007-07-20 Thread Alex Popescu
than all you have to do is: for k in my_dict.keys().sort(): # rest of the code If you just want to keep a list of ordered keys you can probably do something like: key_list = list(my_dict.keys()) key_list.sort() bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/lis

Re: Sorting dict keys

2007-07-20 Thread Alex Popescu
Miles <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > On 7/20/07, Alex Popescu <[EMAIL PROTECTED]> wrote: >> If you just want to iterate over your dict in an ordered manner than >> all you have to do is: >> >> for k in my_dict.keys().sort(): >>

Re: Pythonic way for missing dict keys

2007-07-21 Thread Alex Martelli
mpile("x in dic","","eval")) > 1 0 LOAD_NAME0 (x) > 3 LOAD_NAME1 (dic) > 6 COMPARE_OP 6 (in) > 9 RETURN_VALUE > > "dic.has_key(x)" goes throu

Re: Pythonic way for missing dict keys

2007-07-21 Thread Alex Popescu
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Alex Popescu a écrit : >> Jakub Stolarski <[EMAIL PROTECTED]> wrote in > > > [snip...] > > > d = dict() > answer = d.get('answer', 42) > answer in d > =>

RE: code packaging

2007-07-21 Thread Alex Popescu
ards, > Ryan Ginstrom > What "build" tools are available in Python? Any initial hints are highly appreciated. bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic way for missing dict keys

2007-07-22 Thread Alex Popescu
ad > I see... what that document doesn't describe is the alternatives to be used. And I see in that list a couple of functions that are probably used a lot nowadays (callable, reduce, etc.). bests, ./alex -- .w the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list

Re: code packaging

2007-07-22 Thread Alex Popescu
On 7/22/07, Ryan Ginstrom <> wrote: > Hi Alex: > > Do you develop for Windows? Are you looking to automate a build > process? > > The standard library's build module is distutils: > http://docs.python.org/lib/module-distutils.html > > As I mentioned in m

Re: python - dll access (ctypes or swig)

2007-04-18 Thread Alex Martelli
ment" is one threading model, but it still means that your application and your in-process server must be compatible with it (again, we're discussing the fact that out-of-process servers, at a performance price, can do away with these minor limitations). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: What makes an iterator an iterator?

2007-04-18 Thread Alex Martelli
s many such iterator objects, and never raises StopIteration, thus obviously producing an unending loop. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Threads -

2007-04-18 Thread Alex Martelli
eeds, but I hope the general idea is clear. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: What makes an iterator an iterator?

2007-04-19 Thread Alex Martelli
, and calling the next method of the object (iterator) which is returned by that function when called:-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: What makes an iterator an iterator?

2007-04-19 Thread Alex Martelli
gt; > Thank you for that answer Alex, even though I didn't ask the question I > was wondering the same thing myself. You're welcome -- refreshing to see somebody who can actually understand and accept the answer, rather than going on unrelated tangents when one tries to help th

Re: comparison with None

2007-04-19 Thread Alex Martelli
ts of different types that compare equal; therefore that "documented behavior" is flat wrong and needs to be fixed. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: comparison with None

2007-04-19 Thread Alex Martelli
7;is' test cannot, one more weird reason why it's better): >>> class metaWeird(type): ... def __eq__(self, other): return True ... >>> class Weird: __metaclass__ = metaWeird ... >>> x = Weird() >>> type(x) == type(None) True (warning to all innocen

Re: List of Objects

2007-04-19 Thread Alex Martelli
mistaken about what "a list of classes" means. I'd rather get confirmation of that point before I address your question; if you use totally, irretrievably wrong terminology, miscommunication's likely:-(. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python un-plugging the Interpreter

2007-04-19 Thread Alex Martelli
a Python-like language to C, and allows one to > interact with it from Python with very little difficulty. ...and Boo, which is kind of a Python dialect in the same sense as Pyrex is, but has type inference as well as declarations, and (there being only one current implementation) compiles in

Re: Python un-plugging the Interpreter

2007-04-19 Thread Alex Martelli
e CPUs in cheap consumer products would change people's perceptions -- I wonder... Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Feature Request: Explicit variable declarations

2007-04-19 Thread Alex Martelli
Jorgen Grahn <[EMAIL PROTECTED]> wrote: > As a C and C++ programmer (not a C/C++ programmer), I have to say that Yeah, I wonder, what's C divided by C++ -- maybe about 0.731...? Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: comparison with None

2007-04-20 Thread Alex Martelli
Tommy Grav <[EMAIL PROTECTED]> wrote: > On Apr 19, 2007, at 11:00 PM, Alex Martelli wrote: > > > Alan Isaac <[EMAIL PROTECTED]> wrote: > > > >> currently documented behavior: > >> "objects of different types always compare unequal". >

Re: Calling private base methods

2007-04-20 Thread Alex Martelli
ly the case that experienced programmers, trained in a very different environment, had to be nearly coerced to respect encapsulation; so the enforced encapsulation mechanisms of languages born at that time may well have been warranted. Nowadays, I agree with your thesis that having extra mecha

Re: comparison with None

2007-04-20 Thread Alex Martelli
Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Fri, 20 Apr 2007 11:40:00 -0300, Alex Martelli <[EMAIL PROTECTED]> > escribió: > > > I'm still interested to know where that erroneous quote from Alan Isaac > > comes from, because if it's in Python

Re: Suggestion: str.itersplit()

2007-04-21 Thread Alex Martelli
.zip, .gz and .bz2 archives, understands the most-used options of GNU Tar, and is also much faster; for most purposes it is to be preferred to GNU Tar", to quote). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python for Vcard Parsing in UTF16

2007-04-21 Thread Alex Martelli
ourage), but I thought Apple's Address Book didn't, and, having just tried a VCard export from mine, it looks quite ASCII to me. Maybe you've set some kind of preference, or...? Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Flat DB seeking speed

2007-04-21 Thread Alex Martelli
have installed to build a new file of some dbm type). If by "keywords seeking" you mean performing full-text search, none of these modules are at all suitable. Perhaps you might want to try pylucene, <http://pylucene.osafoundation.org/>, or other such third-party modules, for the purpose -- it that IS indeed your purpose. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem redefining __getitem__ for str subclass

2007-04-21 Thread Alex Martelli
> > ie the last statement (s[1:2]) with a simple slice does not call the > new __getitem__ What am I missing. For backwards compatibility, slicing without a step on some ancient built-in types (including strings, but also lists) goes to __getslice__ (an otherwise obsolete method) instead

Re: Support for new items in set type

2007-04-21 Thread Alex Martelli
so popular). The main point here is that a relational DB's tables _should_ be already very well optimized for storing "sets", since those table ARE exactly nothing but sets of tuples (and a 1-item tuple is a tuple for all that:-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: recursion depth problem

2007-04-22 Thread Alex Martelli
gt;>>>>ch4(item, n+1) > >>>>> ch4(list(sys.argv[1])) ... > > for interest sake: is my method unredeemable? > > Let's just say that I don't currently see an obvious way of redeeming > it. ;-) Change the outer if into a while, and the recursive calls into proper assignments to n. They're both tail-recursive calls, so this won't change the semantics, as it happens. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Alex Martelli
t such black magic in production. The completely different way is: just don't. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries and dot notation

2007-04-22 Thread Alex Martelli
gt;> m.foo 23 >>> m.bar 45 >>> A module may be appropriate, since it's little more than a "wrapper around a dict to access items by dot notation":-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Alex Martelli
es -- and it's certainly > production code. Personally, I'd much rather give up super (not a big loss) and classic classes (a substantial net gain:-) than have to maintain such "black magic" in a production environment. Explicit is better than implicit, &c. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: script for seconds in given month?

2007-04-23 Thread Alex Martelli
edfialk <[EMAIL PROTECTED]> wrote: > Alex, very nice. That should be good enough for me. > The rest of you as well, thanks for all the help. > > I, unfortunately, failed to realize the actual platform the script is > for is IronPython. When trying to import calendar i

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Alex Martelli
gramming in Django a lot these days... ah well, consistency, hobgoblin, little minds, &c:-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python un-plugging the Interpreter

2007-04-24 Thread Alex Martelli
y, and I believe the underlying dotNet CLR does do threads nicely; we'll see what develops on that front, I guess. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Would You Write Python Articles or Screencasts for Money?

2007-04-24 Thread Alex Martelli
", and why I think the PSF should do likewise in this case. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python un-plugging the Interpreter

2007-04-24 Thread Alex Martelli
crosoft's own proprietary CLR (and also modify IronPython as you require, given the above-mentioned license). Other possible alternative starting points include pirate (the Python compiler for the Parrot virtual machine) -- I don't believe it's currently under active development (no more than, say, Jython), but I might well be wrong on this issue; and "Python dialects" ranging from Pyrex to Boo. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: gotcha or bug? random state reset on irrelevant import

2007-04-24 Thread Alex Martelli
te the random.Random class and you can call .seed on it as well as anything else, and no other module will infringe on "your" module's Random instance. The "global functions" of module random exist for those who *SPECIFICALLY* want globally shared behavior, of course. Alex -- http://mail.python.org/mailman/listinfo/python-list

key detect

2007-04-25 Thread Alex Taslab
Hi everybody, does anyone know how to detect a key press from a keyboard. Well I do know how to do that, but i need to detect just one press and ignore the others. I mean, my program checks an input from the outside (a sensor) and i emulate that signal as a keypress, but the sensor doesn`t send the

key detect

2007-04-25 Thread Alex Taslab
Hi everybody, does anyone know how to detect a key press from a keyboard. Well I do know how to do that, but i need to detect just one press and ignore the others. I mean, my program checks an input from the outside (a sensor) and i emulate that signal as a keypress, but the sensor doesn`t send the

Re: If Dict Contains a particular key

2007-04-25 Thread Alex Martelli
pass has_key exists only for backwards compatibility; the 'in' operator is preferable. $ python -mtimeit -s'd={}' 'd.has_key(23)' 100 loops, best of 3: 0.289 usec per loop $ python -mtimeit -s'd={}' '23 in d' 1000 loops, best of 3: 0.139

Re: If Dict Contains a particular key

2007-04-26 Thread Alex Martelli
adays, as in this case, he implemented it many, many years ago -- method get of the dict type, as others already said. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: If Dict Contains a particular key

2007-04-26 Thread Alex Martelli
at the same time, as long as you use the "new" way (meaning, in this case, the one that's been around for "only" about seven years...!!!) -- now that's a combination of factors that's reasonably typical of Python, but not quite so frequent in other languages!-) Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: My python annoyances so far

2007-04-26 Thread Alex Martelli
e exactly opposite principle, "Don't save anything you can recalculate"... of course, the best approach is generally a compromise, but it's good to be aware of the potentially high costs of caching:-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: EuroPython vs PyconUK

2007-04-26 Thread Alex Martelli
EuGeNe Van den Bulke <[EMAIL PROTECTED]> wrote: > Alex Martelli, brilliant speaker and Python evangelist (in my Shu Ha > eyes anyway), lives in the States and is Italian. Busy as you'd expect > from someone working for Google, decides to make the trip to Europe for > a Py

Re: Python keywords

2007-04-26 Thread Alex Martelli
#x27;or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield'] call help(kw) from an interpreter prompt for any one of these values for more information. E.g., >>> help('and') will give you section 5.1 (Boolean operations), all the way to help('yield') giving 6.8 (The yield statement). Some of the keywords have no specific info, e.g. help('as') will not be very informative:-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Generalized range

2007-04-26 Thread Alex Martelli
orithms such as Newton's root-finding approach and the like -- I shudder to think how many people with CS bachelor degrees and even post-grad degrees are just never taught these fundamentals, yet end up having to program _some_ floating point computations, mistakenly thinking they can...). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Generalized range

2007-04-27 Thread Alex Martelli
ould blame the > standards committee, not the compiler writers. Very few features of I was thinking of "Fortran IV" aka Fortran '66, where as I recall per the standard you were _supposed_ to only use integers in a DO, but several compilers supplied real loop variables as an extension, and got its implementation wrong. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Numbers and truth values

2007-04-28 Thread Alex Martelli
and-line dinosaurs, the people who prefer running python at a shell prompt (rather than more advanced things such as ipython, or IDEs such as PyDev, IDLE, etc, etc) this doesn't really tend to be that high a priority, as we're quite used to "not necessarily auto-integrated&qu

Re: Memory addressing

2007-04-28 Thread Alex Martelli
ty offered by ctype, as the higher-level stuff is plenty sufficient to get a lot of core dumps:-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: how can I put an Exception as the key of a hash table

2007-04-28 Thread Alex Martelli
considered as keys into a dict. There are of course ways to "collapse" them (e.g, use (type(e), str(e)) as the dict key, or, many others), but at any rate this does not appear to have anything to do with the problem you report. Could you perhaps post a complete, self-sufficient short script or interactive interpreter session, such as the few lines I've just copied and pasted above, to help us understand your problem? (More generally, <http://www.catb.org/~esr/faqs/smart-questions.html> has pretty good advice about "how to ask questions the smart way"). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: My Python annoyances

2007-04-28 Thread Alex Martelli
James Stroud <[EMAIL PROTECTED]> wrote: > André wrote: [snipping total repost of André's post] > > I'm really annoyed at Python - and not for the reasons already > > mentioned on this list. > > > > Everyone know that programming is supposed to be a dark art, nearly > > impossible to learn.

Re: Numbers and truth values

2007-04-28 Thread Alex Martelli
s reasonably short list (I feel much the same way about None, by the way). pychecker, pylint, and friends, are a much better way to detect and warn about all sort of anomalies of this kind. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: relative import broken?

2007-04-28 Thread Alex Martelli
t directory of temp should work fine. Since you don't give us the exact command line you're trying to execute, it's impossible to guess exactly what you're doing. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Portable SciPy v0.1 released

2007-04-28 Thread Alex Martelli
ance (and Catalunya, for those who prefer cava, etc -- basically, all regions that export champagne!-). Alex [1] yah, I do remember MSFT flirting with $60 [considering the early'03 split] at the end of '99 -- that was just Wall Street being crazy, and the fall from THOSE heights is N

Re: editing scripts on a mac

2007-04-28 Thread Alex Martelli
uding Python. Personally, I swear by VIM (the full downloaded version with GUI support and everything, see <http://macvim.org/OSX/index.php>) but unless you like the general approach of vi I guess you're more likely to swear AT it than BY it:-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Numbers and truth values

2007-04-28 Thread Alex Martelli
, so it can run just as well on (e.g) 2.2.1 (and earlier) as 2.2.2 (and later) -- breaking all of that code which always worked fine is a decision not to be taken as lightly as you appear to imply. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Any Good tools to create CSV Files?

2007-04-28 Thread Alex Martelli
johnny <[EMAIL PROTECTED]> wrote: > Any Good tools to create CSV Files? ReportLab only creates pdf > files. I need something to create CSV files. <http://docs.python.org/lib/module-csv.html> Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get HTTP error when using urlretrieve()

2007-04-28 Thread Alex Martelli
known host? connection timeout? HTTP error? I think <http://www.python.org/doc//lib/module-urllib.html> gives good information about these issues. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Numbers and truth values

2007-04-29 Thread Alex Martelli
of code in it", Foreman Acton's "Real computing made real", now out in a wonderfully cheap Dover edition: Acton makes this case better than I've ever seen it made elsewhere, and offers many excellent examples of how numerical computation SHOULD be done). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: relative import broken?

2007-04-29 Thread Alex Martelli
Alan Isaac <[EMAIL PROTECTED]> wrote: > "Alex Martelli" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > If you're running test1.py as your main module, then it's not part of a > > package, so the relative import should indee

Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread Alex Martelli
m. Use, instead, the DSU that is now build into Python: listofsets.sort(key=len) this will be faster (as well as more readable &c) than programming your own DSU, and is exactly the reason the key= parameter was added. I also suggest avoiding reduce in favor of a simple explicit loop. Alex --

Re: While we're talking about annoyances

2007-04-29 Thread Alex Martelli
l? sum is for summing NUMBERS -- using it on lists is O(N squared). So, this solution is asymptotically VERY slow, as well as obfuscated. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: While we're talking about annoyances

2007-04-29 Thread Alex Martelli
Michael Hoffman <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > >... > >>>>> decorated.sort() > >... > >>> def index(sequence): > >>> return sorted(range

Re: Master's Thesis Help Needed

2007-04-29 Thread Alex Martelli
RobJ <[EMAIL PROTECTED]> wrote: > http://pyschool.robj.webfactional.com/ Things start on a pretty bad note when I'm asked to select my OS: Ubuntu Linux Windows XP I'm running MacOSX. What now? Why is there no choice "none of the above"...?! Alex -- http://mai

Re: While we're talking about annoyances

2007-04-30 Thread Alex Martelli
be correct. And if it's not, it's not > because they're all O(N log N). And if it is, it's not because of the "one sort" versus "two sorts": by that sole criterion you just cannot guess (sensibly) at speed (measuring is much better, though it has its own pitfalls). Alex -- http://mail.python.org/mailman/listinfo/python-list

<    11   12   13   14   15   16   17   18   19   20   >