Re: count strangeness

2011-05-22 Thread James Stroud
Chris Rebert wrote: On Sat, May 21, 2011 at 11:32 PM, James Stroud wrote: Chris Rebert wrote: WTF? Assuming your question is "Why is 1024 there twice?", the answer is The question is "Why is 1024 there at all?" It should be 10. Ah. This is why it's better to be

Re: count strangeness

2011-05-22 Thread James Stroud
Peter Otten wrote: James Stroud wrote: WTF? Put the code into a file, run it -- and be enlightened ;) Compare the follower to the last. tal 77% cat eraseme.py #! /usr/bin/env python class C: def __init__(self): self.data = [] def doit(self, count=[0]): for c in self.data

Re: count strangeness

2011-05-21 Thread James Stroud
James Stroud wrote: Chris Rebert wrote: WTF? Assuming your question is "Why is 1024 there twice?", the answer is The question is "Why is 1024 there at all?" It should be 10. James I mean 11, not 10--but you get the point. James -- http://mail.python.org/mailman/listinfo/python-list

Re: count strangeness

2011-05-21 Thread James Stroud
Peter Otten wrote: James Stroud wrote: WTF? Put the code into a file, run it -- and be enlightened ;) tal 72% python2.7 eraseme.py 1 2 4 8tal 73% cat eraseme.py #! /usr/bin/env python class C: def __init__(self): self.data = [] def doit(self, count=0): for c in self.data

Re: count strangeness

2011-05-21 Thread James Stroud
Chris Rebert wrote: WTF? Assuming your question is "Why is 1024 there twice?", the answer is The question is "Why is 1024 there at all?" It should be 10. James -- http://mail.python.org/mailman/listinfo/python-list

count strangeness

2011-05-21 Thread James Stroud
tal 65% python2.7 Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. py> class C(object): ... def __init__(self): ... self.data = [] ... def doit(self, count=0): ...

Re: Regex driving me crazy...

2010-04-07 Thread James Stroud
Patrick Maupin wrote: BTW, although I find it annoying when people say "don't do that" when "that" is a perfectly good thing to do, and although I also find it annoying when people tell you what not to do without telling you what *to* do, and although I find the regex solution to this problem to

Re: python as pen and paper substitute

2010-04-06 Thread James Stroud
Manuel Graune wrote: Hello everyone, I am looking for ways to use a python file as a substitute for simple pen and paper calculations. At the moment I mainly use a combination of triple-quoted strings, exec and print (Yes, I know it's not exactly elegant). To clarify, I just start an editor, wri

s-expression parser in python

2010-04-06 Thread James Stroud
Hello All, I want to use an s-expression based configuration file format for a python program I'm writing. Does anyone have a favorite parser? I'm currently using sexpy.parse() (http://pypi.python.org/pypi/sexpy) which works very well but I don't know how secure it is. Does anyone have exper

Re: hashability

2009-08-12 Thread James Stroud
Steven D'Aprano wrote: Well there you go -- why on earth would you prohibit None as a dictionary key??? That's a serious failure. roentgen 1% python Python 2.5 (r25:51908, Sep 20 2006, 17:36:21) [GCC 3.4.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. py>

Re: hashability

2009-08-12 Thread James Stroud
Dennis Lee Bieber wrote: On Tue, 11 Aug 2009 17:54:36 -0700, James Stroud declaimed the following in gmane.comp.python.general: ... py> {C():4}[C()] Traceback (most recent call last): File ""

Re: hashability

2009-08-11 Thread James Stroud
Asun Friere wrote: On Aug 12, 3:32 pm, James Stroud wrote: You should be more imaginative. I'm by no means discounting that there might be some actual problem you're trying to solve here, but I honestly can't see it. There really is no need to get personal about this, so rat

Re: Frustrated with scopes

2009-08-11 Thread James Stroud
James Stroud wrote: > def stream_factory: > class Line(object): > __source = source > __join = join > # etc. > return Line > of course I meant "def stream_factory(lines, source, join=''.join):" James -- http://mail.python.org/mailman/listinfo/python-list

Re: Frustrated with scopes

2009-08-11 Thread James Stroud
andrew cooke wrote: Is there a way to make this work (currently scope and join are undefined at runtime when the inner class attributes are defined): class _StreamFactory(object): @staticmethod def __call__(lines, source, join=''.join): class Line(object): __source

Re: hashability

2009-08-11 Thread James Stroud
Asun Friere wrote: Perhaps the best solution would be for the unitiated to correct their misaprehensions Can you come give a class to my users? -- http://mail.python.org/mailman/listinfo/python-list

Re: hashability

2009-08-11 Thread James Stroud
Asun Friere wrote: On Aug 12, 12:15 pm, James Stroud wrote: I realize I left out my use. The intent of the function is to flag objects that will make useful keys for a persistent dictionary. The {C():4}[C()] example demonstrates why I want to avoid certain types of keys--I don't want use

Re: hashability

2009-08-11 Thread James Stroud
Carl Banks wrote: On Aug 11, 5:54 pm, James Stroud wrote: To prevent users of one of my libraries from falling into this and similar traps (which have potentially problematic consequences), Even so, I would consider whether some of your users might, like me, also find this terribly useful

hashability

2009-08-11 Thread James Stroud
Hello All, I wrote the function to test hashability of arbitrary objects. My reason is that the built-in python (2.5) hashing is too permissive for some uses. A symptom of this permissiveness comes from the ability to successfully hash() arbitrary objects: py> class C(object): pass ...

Python quirk in evaluation order

2009-07-31 Thread James Stroud
Python 2.5: mbi136-176 211% python *** Pasting of code with ">>>" or "..." has been enabled. ## ipython ## ###

Re: TkInter: Problem with propagation of resize events through geometry manager hierarchy?

2009-02-08 Thread James Stroud
ame widgets that might be helpful to you. There is no need to reinvent the wheel except for your own enlightenment. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: TkInter: Problem with propagation of resize events through geometry manager hierarchy?

2009-02-08 Thread James Stroud
that should terminate the event chain. This is a general technique to stop a lot of unwanted event propagation. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Is c.l.py becoming less friendly?

2009-02-07 Thread James Stroud
Tim Chase wrote: Is this where we tell you to shut up? ;-) Don't you mean STFU? -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: what IDE is the best to write python?

2009-02-01 Thread James Stroud
mcheun...@hotmail.com wrote: Hi all what IDE is the best to write python? thanks from Peter (mcheun...@hotmail.com) vim in one terminal, ipython in the other. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com

Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-29 Thread James Stroud
erformance increase. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: New to python, open source Mac OS X IDE?

2009-01-27 Thread James Stroud
joseph.a.mar...@gmail.com wrote: Greetings! I've heard enough raving about Python, I'm going to see for myself what all the praise is for! I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you even use an IDE for Python? Any recommendations on open source Python environments? Tha

Re: Start Python at client side from web app

2009-01-21 Thread James Stroud
Thomas Guettler wrote: Sorry, I described my problem not well. Here is more information: The main application is the intranet web application used with IE (ms windows client). But some action needs to be done on the client since you can't do it with html or javascript. 1. The user pushes a bu

Re: Start Python at client side from web app

2009-01-21 Thread James Stroud
code isn't ready, wait for the next interval. Use https for security and have a shared secret message to identify legitimate clients. If you try to push code the other way, you will need a perpetual socket open on the client side, making the client the server. James -- James Strou

Re: defining class functions

2009-01-19 Thread James Stroud
Astan Chee wrote: Hi, I have two classes in python that are in two different files/python scripts. Class A uses Class B like this: class B(object): def function1(self,something): pass def function2(self,something): print "hello one" print something class A(object):

Re: dynamic module import?

2009-01-18 Thread James Stroud
y put the import statements in a separate module (e.g. "importer_module" and do something like """another_module""" from importer_module import module If you simply don't want to import a bunch of modules, use an if/then statement. In any event, I adv

Re: Pythonic way to handle coordinates

2009-01-17 Thread James Stroud
D(sum(t) for t in zip(self, other)) py> p = Point3D([8, 7, 6]) py> p Point3D([8.0, 7.0, 6.0]) py> str(p) 'Point3D([8.0, 7.0, 6.0])' py> q = Point3D([5, 4, 3]) py> r = p + q py> r Point3D([13.0, 11.0, 9.0]) Now have fun with this stuff. I need t

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread James Stroud
* 10) itlist = [make_gen(i) for i in xrange(2)] print "what's in the bags:" print list(islice(itlist[0], 5)) print list(islice(itlist[1], 5)) James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: General direction

2009-01-15 Thread James Stroud
u start. 3. Consider PySQlite (http://trac.edgewall.org/wiki/PySqlite) before you think about a heavyweight database backend (once you realize that you will want a database for this project). James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Ang

Re: Suggested improvements for IDLE (non-official)

2009-01-14 Thread James Stroud
r wrote: I actually like the IDLE, but it could use a few improvements. If anybody else has suggestions by all means post them. 1.) The text widget and the prompt(>>>) should be separated. Trying to write a conditional in the interactive IDLE is a real PITA. Not to mention if you copy the workin

Re: Unexpected behavior with dictionary keys containment and a user-defined class

2009-01-12 Thread James Stroud
Rob Clewley wrote: Hi, the short version of my question is: when is a dictionary's __contains__ method behavior different to using the 'in' idiom? (because I have an example of a difference in my code). Never. Longer version: I have a user-defined class with a few overrides of special methods

Re: Unbinding Tkinter default bindings for Listbox

2009-01-12 Thread James Stroud
James Stroud wrote: tk.tk.call('bind', str(lb), '', "break") Which is equivalent to lb.bind('', "break") But I checked and overriding the default behavior of Listbox does not work (tk.tk.call('bind', "Listbox", '

Re: Unbinding Tkinter default bindings for Listbox

2009-01-12 Thread James Stroud
Roger wrote: I'm sorry for harassing the list but any suggestions would be greatly appreciated. =) I just checked the behavior you are describing. It seems that you want to unbind the event to stop the autoscrolling when you leave the listbox. E.g.: from Tkinter import * tk = Tk() lb = Lis

Re: Unbinding Tkinter default bindings for Listbox

2009-01-12 Thread James Stroud
James Stroud wrote: py> b.tk.call('bind', 'Listbox', '', _) You want b.tk.call('bind', 'Listbox', '', "") of course. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 900

Re: Unbinding Tkinter default bindings for Listbox

2009-01-12 Thread James Stroud
'\nset tk::Priv(x) %x\nset tk::Priv(y) %y\ntk::ListboxMotion %W [%W index @%x,%y]\n' py> b.tk.call('bind', 'Listbox', '', _) '' James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: hlep: a text search and rename question

2009-01-12 Thread James Stroud
James Stroud wrote: cue = iter(open('CDImage.cue').readlines()) It just occurred to me that this could simply be: cue = open('CDImage.cue') James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jam

Re: hlep: a text search and rename question

2009-01-12 Thread James Stroud
= [] for line in cue: if line.strip().startswith('FILE'): break for line in cue: if line.strip().startswith('TITLE'): titles.append(line.split('"')[-2]) flacs = glob.glob('*.flac') flacs.sort(key=lambda f: int(re.search(r'\d+', f).group(0

Re: drive a desktop app from python?

2009-01-09 Thread James Stroud
me) top = '.' suffix = '.jpg' os.path.walk(top, doit, suffix) Read the docs on os.path.walk, of course. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Generator metadata/attributes

2009-01-07 Thread James Stroud
acooke@gmail.com wrote: Hi, (I searched back and found some previous discussion on generator attributes that seemed to be related to callable generators - this is NOT that, as far as I can tell) I want to associate some data with a generator. This is in a decorator function, as it happens;

Re: Is it ok to type check a boolean argument?

2009-01-07 Thread James Stroud
Ben Finney wrote: Why are people so reluctant to make error message templates clearer with named placeholders? Because they can never remember they even exist. Thanks for the reminder. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it ok to type check a boolean argument?

2009-01-07 Thread James Stroud
Adal Chiriliuc wrote: Hello, Me and my colleagues are having an discussion about the best way to code a function (more Pythonic). Here is the offending function: def find(field, order): if not isinstance(order, bool): raise ValueError("order must be a bool") order_by = "asc" if

Re: Regular Expressions...

2009-01-07 Thread James Stroud
Ken D'Ambrosio wrote: Hi, all. As a recovering Perl guy, [snip] In Perl, I'd so something like m/^1(...)(...)/; Indeed it seems you are recovering from an especially bad case. I recommend two doses of the python cookbook per day for one to two months. Report back here after your first

Re: How to store passwords?

2009-01-07 Thread James Stroud
James Stroud wrote: If you check out sf.passerby.net and download the source, you will see a passerby.sf.net Shuffle things I did. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to store passwords?

2009-01-07 Thread James Stroud
James Stroud wrote: Oltmans wrote: I'm writing a program in which I will ask users to enter user name and password once only. It's a console based program that will run on Windows XP. Actually, I'm trying to provide the similar functionality as "Remember me" thing in b

Re: How to store passwords?

2009-01-07 Thread James Stroud
Oltmans wrote: I'm writing a program in which I will ask users to enter user name and password once only. It's a console based program that will run on Windows XP. Actually, I'm trying to provide the similar functionality as "Remember me" thing in browsers. For that, I will need to store user nam

Re: Oh! The people of all over the world!

2009-01-07 Thread James Stroud
likely morally unjust--but I can't stand antisemitism just like I can't stand hatred of Islam just like I can't stand hatred of Christians. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com --

Re: subclassing 'list'

2009-01-06 Thread James Stroud
akineko wrote: Hello everyone, I'm creating a class which is subclassed from list (Bulit-in type). It works great. However, I'm having a hard time finding a way to set a new value to the object (within the class). There are methods that alter a part of the object (ex. __setitem__()). But I coul

Re: __builtin__ quote

2009-01-06 Thread James Stroud
Steven Woody wrote: On Tue, Jan 6, 2009 at 4:42 PM, James Stroud wrote: py> import __builtin__ py> __builtin__.abs is abs True Does that mean someone did 'import * from __builtin__' when python startup? In terms of the exact implementation of the cPython interpreter, I

Re: __builtin__ quote

2009-01-06 Thread James Stroud
True James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: What would you like to see in a book about Matplotlib?

2009-01-06 Thread James Stroud
#x27;d like to explore of matplotlib and never had time to do? I want to program a lot of interactivity with the plots in my current application. Your suggestions are really appreciated :) And wish me good luck! Good luck! I can't wait to read your book! James -- James Stroud UCLA-

Re: assignment with [:]

2008-12-28 Thread James Stroud
James Stroud wrote: py> a = [1, 2, 3] py> a1 = a py> a1[:] = [x*3 for x in a1] py> a1 [3, 6, 9] py> a1 [3, 6, 9] This should have been: py> a = [1, 2, 3] py> a1 = a py> a1[:] = [x*3 for x in a1] py> a [3, 6, 9] py> a1 [3, 6, 9] James -- James

Re: assignment with [:]

2008-12-28 Thread James Stroud
py> a = [1, 2, 3] py> a1 = a py> a1 [1, 2, 3] py> a1 = [x*3 for x in a1] py> a1 [3, 6, 9] py> a [1, 2, 3] James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a function to remove escape characters from a string ?

2008-12-25 Thread James Stroud
Stef Mientki wrote: hello, Is there a function to remove escape characters from a string ? (preferable all escape characters except "\n"). thanks, Stef import string WANTED = string.printable[:-5] + "\n" def descape(s, w=WANTED): return "".join(c for c in s

Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread James Stroud
ying pedantry that has made usenet great: http://docs.python.org/dev/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi-dimension list

2008-12-24 Thread James Stroud
'] ['WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?'] -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: On Whose Desktop

2008-12-23 Thread James Stroud
Steve Holden wrote: Thanks to Barry Warsaw the "On Your Desktop" blog now has a new entry: Note the thumb trackball. It's the shiznizzle. Give one two weeks of your patience and you'll seriously consider having it implanted in your thigh so you don't have to worry about missing it when you tr

Re: Need help improving number guessing game

2008-12-15 Thread James Stroud
playover = input("PLAY AGAIN? Y/N: ") if playover.strip().lower() == "y": game['play'] = 1 setup(game) else: print("GOOD BYE. PLAY AGAIN SOON!") quit() Notice that I just made return values obsolete. You will also

Re: alt.possessive.its.has.no.apostrophe

2008-12-15 Thread James Stroud
Ben Finney wrote: James Stroud writes: Ben Finney wrote: James Stroud writes: Yes. I think it was the British who decided that the apostrophe rule for "it" would be reversed from normal usage relative to just about every other noun. It also seems an indefensible claim to say t

Re: Looking for the best way to translate an idiom

2008-12-14 Thread James Stroud
I V wrote: On Sun, 14 Dec 2008 21:08:33 -0800, James Stroud wrote: Yes. I think it was the British who decided that the apostrophe rule for "it" would be reversed from normal usage relative to just about every other noun. I'm not sure the purpose--maybe it was to give compulsive

Re: alt.possessive.its.has.no.apostrophe

2008-12-14 Thread James Stroud
Ben Finney wrote: James Stroud writes: Yes. I think it was the British who decided that the apostrophe rule for "it" would be reversed from normal usage relative to just about every other noun. Remember that “it” is a pronoun. I see no reversal: Ok. Pronouns are reversed.

Re: Looking for the best way to translate an idiom

2008-12-14 Thread James Stroud
Aahz wrote: In article , James Stroud wrote: In case its not obvious: Ah, so that's where Bruno's extra apostrophe came from! ;-) (Sorry about the spelling flame, but seeing three posts in quick succession with incorrect spelling of its/it's pushed me into making a public

Re: Looking for the best way to translate an idiom

2008-12-14 Thread James Stroud
James Stroud wrote: inspect.stack()[1][0].f_locals[name] = val I just double checked this. Because of the way locals are implemented in cPython, this won't have the desired affect. James -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for the best way to translate an idiom

2008-12-14 Thread James Stroud
drobi...@gmail.com wrote: I'm baffled by this discussion. What's wrong with a, dontcare, dontcare2 = f() a = a + 1 Simple, clear, and correct. 1. This can't apply to a generalized f() that may return an arbitrary number of arguments >= len(num_assignments_you_care_about). 2. The examp

Re: Looking for the best way to translate an idiom

2008-12-14 Thread James Stroud
James Stroud wrote: py> class mytuple(tuple): def magic(self, astr): names = astr.split() for name, val in zip(names, self): globals()[name] = val ... py> t = mytuple((1,2,3)) py> t.magic('a b') py> a 1 py> b 2 James In case its not obvious: def f()

Re: Looking for the best way to translate an idiom

2008-12-14 Thread James Stroud
Paul Moore wrote: I'm translating some code from another language (Lua) which has multiple function return values. So, In Lua, it's possible to define a function function f() return 1,2,3 end which returns 3 values. These can then be used/assigned by the caller: a,b,c = f()

Re: Need help improving number guessing game

2008-12-14 Thread James Stroud
It looks much better. But as Bruno suggests and as I alluded to earlier, you should get in the habit of forming verification loops on input channels that aren't already guaranteed to provide valid input messages. I'm not sure how to say that in English, but in python my example was: while True

Re: Optimizing methods away or not?

2008-12-14 Thread James Stroud
Steven D'Aprano wrote: class Parrot: def __init__(self, *args): print "Initialising instance..." if __debug__: self.verify() # check internal program state, not args if __debug__: def verify(self): print "Verifying..." +1 It looks good to

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
James Stroud wrote: Be assured that it takes on special intelligence to write unintelligible I meant "*no* special intelligence". -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
feba wrote: This is what I have so far. better? worse? Much better. I didn't check if it works. But you need to figure out a way to give up on your reliance on global variables. They will end up stifling you in the long run when you move to substantial projects. Also, you should start movin

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
uot;) quit() else: target = random.randint(1, 99) else: print("TOO LOW") return target -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
James Stroud wrote: 1. Refactor. You should look at your code and see where you repeat the same or similar patterns, see where they differ, make functions, and make the differences parameters to the function call: def guess(player, p1score, p2score): guess1 = int(input("\n>> &quo

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
premature optimization", but simply good coding style [ed: put in to fend off the "premature optimization is bad" puppets who infest this list]. Notice that the sequence of commands follows a logical sequence corresponding to decisions in the game. It makes the code more sensible, readable, and a little faster some times to boot. Good logic has the happy consequence of good speed most of the time. My code is typed real-time so is untested. No promise that there aren't typos but you will probably get the idea. But see if you can plug the these functions into the proper places and apply some of these techniques. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: internal circular class references

2008-12-10 Thread James Stroud
Ethan Furman wrote: Greetings List! I'm writing a wrapper to the datetime.date module to support having no date. Its intended use is to hold a date value from a dbf file, which can be empty. The class is functional at this point, but there is one thing I would like to change -- datetime.da

Re: How to pass out the result from iterated function

2008-12-10 Thread James Stroud
JD wrote: I got a iterated function like this: def iterSomething(list): has_something = False for cell in list: if something in cell: has_something = True output = something if has_something: iterSomething(output) else: final_out = outu

Re: filter iterable based on predicate take from another iterable

2008-12-10 Thread James Stroud
iterator without requiring making a list, you can simply use parentheses instead of brackets: agenerator = (v for f, v in izip(bar, foo) if not f(v)) This is perfectly lazy but not immune to problems when foo or bar is changed before the generator is fully consumed. James -- James Stroud

Re: Rich Comparisons Gotcha

2008-12-08 Thread James Stroud
Robert Kern wrote: James Stroud wrote: I think it skips straight to __eq__ if the element is not the first in the list. No, it doesn't skip straight to __eq__(). "y is 1" returns False, so (y==1) is checked. When y is a numpy array, this returns an array of bools. list.__con

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Robert Kern wrote: James Stroud wrote: py> 112 = [1, y] py> y in 112 Traceback (most recent call last): File "", line 1, in ValueError: The truth value of an array with more than one element is... but not py> ll1 = [y,1] py> y in ll1 True It's this discrepancy

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Robert Kern wrote: James Stroud wrote: I'm missing how a.all() solves the problem Rasmus describes, namely that the order of a python *list* affects the results of containment tests by numpy.array. E.g. "y in ll1" and "y in ll2" evaluate to different results in hi

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Steven D'Aprano wrote: On Sun, 07 Dec 2008 13:57:54 -0800, James Stroud wrote: Rasmus Fogh wrote: ll1 = [y,1] y in ll1 True ll2 = [1,y] y in ll2 Traceback (most recent call last): File "", line 1, in ValueError: The truth value of an array with more than one element is

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
James Stroud wrote: [cast to bool] for numpy works like a unary ufunc. Scratch that. Not thinking and typing at same time. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
vior should be for comparisons. I think the probability of that happening is about zero, though, because such a change would run counter to the dynamic nature of the language. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Luis Zarrabeitia wrote: Quoting James Stroud <[EMAIL PROTECTED]>: First, here is why the ability to throw an error is a feature: class Apple(object): def __init__(self, appleness): self.appleness = appleness def __cmp__(self, other): assert isinstance(other, Apple),

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
of complex numbers: would 4 + 4i be equal to sqrt(32)? Even in the realm of pure mathematics, the generality of objects (i.e. numbers) can not be assumed. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http:

Re: can graphs be made in python as we make in java

2008-12-07 Thread James Stroud
suku wrote: HI folks... i need some suggestion on making graphs. Will this be possible with normal python setup file or do i need to download add ons for that.. help me out I like pychart. It has the advantage of being pure python and makes very nice looking plots. You might also

Re: Brain going crazy with recursive functions

2008-12-07 Thread James Stroud
James Stroud wrote: def linear_search(array, truth_func, loc=(0,0)): idx1, idx2 = loc if idx1 >= len(array): return None if idx2 >= len(array[idx1]): return linear_search(array, truth_func, (idx1+1, 0)) value = array[idx1][idx2] tf = truth_func(value) if tf: retu

Re: Brain going crazy with recursive functions

2008-12-07 Thread James Stroud
[EMAIL PROTECTED] wrote: I'm trying to solve the 9-tile puzzle using as functional an approach as possible. I've recently finished reading SICP and am deliberately avoiding easy python-isms for the more convoluted scheme/functional methods. The following function is trivial to do with for loops

Re: operators as variables

2008-12-06 Thread James Stroud
macc_200 wrote: Hi, just starting programming and have an elementary question after playing around with lists but cannot find the answer with googling. I have a list of variables and I would like some of those variables to be integers and some to be operators so the list would look something l

Re: Guido's new method definition idea

2008-12-06 Thread James Stroud
Steven D'Aprano wrote: On Fri, 05 Dec 2008 20:35:07 -0800, James Stroud wrote: Daniel Fetchinson wrote: I'd like this new way of defining methods, what do you guys think? Consider the maverick who insists on class C: def me.method(arg): self.value = arg Replace "

Re: Guido's new method definition idea

2008-12-05 Thread James Stroud
Of course I meant class C: def me.method(arg): me.value = arg James -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido's new method definition idea

2008-12-05 Thread James Stroud
Daniel Fetchinson wrote: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html The proposal is to allow this: class C: def self.method( arg ): self.value = arg return self.value instead of this: class C: def method( self, arg ): self.value

Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread James Stroud
alex23 wrote: On Dec 6, 8:00 am, James Stroud <[EMAIL PROTECTED]> wrote: I think its a symptom of the language's maturing, getting popular, and a minority fraction* of the language's most devout advocates developing an egotism that complements their python worship in a most unsa

Re: dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud
James Stroud wrote: Terry Reedy wrote: because there is no bug to fix. I have suggesting closing. May I suggest to add something to this effect within the issue itself so others won't spend time trying to figure out why the "bug" is still open? Sorry, you did that.

Re: dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud
Terry Reedy wrote: because there is no bug to fix. I have suggesting closing. May I suggest to add something to this effect within the issue itself so others won't spend time trying to figure out why the "bug" is still open? If this is a more general feature of issues, then perhaps it would

Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread James Stroud
Andreas Waldenburger wrote: Is it me, or has c.l.p. developed a slightly harsher tone recently? (Haven't been following for a while.) Yep. I can only post here for about a week or two until someone blows a cylinder and gets ugly because they interpreted something I said as a criticism of the

Re: dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud
James Stroud wrote: Hello All, I subclassed dict and overrode __setitem__. When instances are unpickled, the __setstate__ is not called before the keys are assigned via __setitem__ in the unpickling protocol. I googled a bit and found that this a bug filed in 2003: http://bugs.python.org

dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud
ing' I'm still using python 2.5.1. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list

Re: RELEASED Python 3.0 final

2008-12-04 Thread James Stroud
Barry Warsaw wrote: On behalf of the Python development team and the Python community, I am happy to announce the release of Python 3.0 final. comp.lang.python3k ? -- http://mail.python.org/mailman/listinfo/python-list

  1   2   3   4   5   6   7   8   9   10   >