Re: C#3.0 and lambdas

2005-09-22 Thread Steven Bethard
Reinhold Birkenfeld wrote: > > This is Open Source. If you want an initiative, start one. +1 QOTW. STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: C#3.0 and lambdas

2005-09-23 Thread Steven Bethard
Erik Wilsher wrote: > And I think the discussion that followed proved your point perfectly > Fredrik. Big discussion over fairly minor things, but no "big > picture". Where are the initiatives on the "big stuff" (common > documentation format, improved build system, improved web modules, > rew

Re: subprocess considered harmfull?

2005-09-25 Thread Steven Bethard
Uri Nix wrote: > Using the following snippet: > p = > subprocess.Popen(nmake,stderr=subprocess.PIPE,stdout=subprocess.PIPE, \ >universal_newlines=True, bufsize=1) > os.sys.stdout.writelines(p.stdout) > os.sys.stdout.writelines(p.stderr) > Works fine on the command li

Re: Dynamically adding and removing methods

2005-09-25 Thread Steven Bethard
Steven D'Aprano wrote: > py> class Klass: > ... pass > ... > py> def eggs(self, x): > ... print "eggs * %s" % x > ... > py> inst = Klass() # Create a class instance. > py> inst.eggs = eggs # Dynamically add a function/method. > py> inst.eggs(1) > Traceback (most recent call last): > Fil

Re: Dynamically adding and removing methods

2005-09-28 Thread Steven Bethard
Terry Reedy wrote: > "Ron Adam" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Actually I think I'm getting more confused. At some point the function >>is wrapped. Is it when it's assigned, referenced, or called? > > > When it is referenced via the class. > If you lookup i

Re: Parser suggestion

2005-09-29 Thread Steven Bethard
Jorge Godoy wrote: > From Google I found almost all of those. But do you have any suggestion on > which one would be better to parse Fortran code? Or more productive to use > for this task? > [snip] > >>PyParsing >> http://pyparsing.sourceforge.net/ Well, I've never had to parse Fortan code,

Re: Feature Proposal: Sequence .join method

2005-09-29 Thread Steven Bethard
David Murmann wrote: > Hi all! > > I could not find out whether this has been proposed before (there are > too many discussion on join as a sequence method with different > semantics). So, i propose a generalized .join method on all sequences > with these semantics: > > def join(self, seq): >

Re: pywordnet install problems

2005-09-30 Thread Steven Bethard
vdrab wrote: > hello pythoneers, > > I recently tried to install wordnet 2.0 and pywordnet on both an ubuntu > linux running python 2.4 and a winXP running activePython 2.4.1, and I > get the exact same error on both when I try to "from wordnet import *" > : > > running install > error: invalid P

Re: pywordnet install problems

2005-10-03 Thread Steven Bethard
vdrab wrote: > I had WordNet 2.0 installed but just now I tried it with 1.7.1 as well > and the result was the same. It's a shame, glossing over the pywordnet > page really made me want to give it a try. > Are there any workarounds you can recommend ? What's your wordnet setup like? I have mine i

Re: Class property

2005-10-11 Thread Steven Bethard
Laszlo Zsolt Nagy wrote: > class A(object): >cnt = 0 >a_cnt = 0 >def __init__(self): >A.cnt += 1 >if self.__class__ is A: >A.a_cnt += 1 > class B(A): >pass > print A.cnt,A.a_cnt # 0,0 > b = B() > print A.cnt,A.a_cnt # 1,0 > a = A() > print A.c

Re: override a property

2005-10-18 Thread Steven Bethard
Robin Becker wrote: > ## my silly example > class ObserverProperty(property): > def __init__(self,name,observers=None,validator=None): > self._name = name > self._observers = observers or [] > self._validator = validator or (lambda x: x) > self._pName = '_' + nam

Re: sqlstring -- a library to build a SELECT statement

2005-10-19 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Jason Stitt wrote: > >>Using // for 'in' looks really weird, too. It's too bad you can't >>overload Python's 'in' operator. (Can you? It seems to be hard-coded >>to iterate through an iterable and look for the value, rather than >>calling a private method like some other

Re: classmethods, class variables and subclassing

2005-10-21 Thread Steven Bethard
Andrew Jaffe wrote: > Hi, > > I have a class with various class-level variables which are used to > store global state information for all instances of a class. These are > set by a classmethod as in the following (in reality the setcvar method > is more complicated than this!): > > class sup(

Re: Tricky Areas in Python

2005-10-24 Thread Steven Bethard
Alex Martelli wrote: > >>>class Base(object) >>>def getFoo(self): ... >>>def setFoo(self): ... >>>foo = property(getFoo, setFoo) >>> >>>class Derived(Base): >>>def getFoo(self): >> [snip] > the solution, in Python 2.4 and earlier, is to use > one extra

Re: [OT] Re: output from external commands

2005-10-24 Thread Steven Bethard
darren kirby wrote: > quoth the Fredrik Lundh: > >>(using either on the output from glob.glob is just plain silly, of course) > [snip] > > It is things like this that make me wary of posting to this list, either to > help another, or with my own q's. All I usually want is help with a specific

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Steven Bethard
Antoon Pardon wrote: > Christopher Subich schreef : > >> Antoon Pardon wrote: >>> >>>from decimal import Decimal >>> >>>Zero = Decimal(0) >>> >>>cmp( ( ) , Zero) >>> -1 >>> >>>cmp(Zero, 1) >>> -1 >>> >>>cmp(1, ( ) ) >>> -1 >> >> I'd argue that the wart here is that cmp doesn't throw an exception,

Re: data hiding/namespace pollution

2005-10-31 Thread Steven Bethard
Alex Hunsley wrote: > The two main versions I've encountered for data pseudo-hiding > (encapsulation) in python are: > > method 1: > > _X - (single underscore) - just cosmetic, a convention to let someone > know that this data should be private. > > > method 2: > > __X - (double unders

Re: Attributes of builtin/extension objects

2005-11-02 Thread Steven Bethard
George Sakkis wrote: > - Where do the attributes of a datetime.date instance live if it has > neither a __dict__ nor __slots__ ? > - How does dir() determine them ? py> from datetime import date py> d = date(2003,1,23) py> dir(date) == dir(d) True py> for attr_name in ['day', 'month', 'year']: ...

Re: __slots__ and class attributes

2005-11-03 Thread Steven Bethard
Ewald R. de Wit wrote: > I'm running into a something unexpected for a new-style class > that has both a class attribute and __slots__ defined. If the > name of the class attribute also exists in __slots__, Python > throws an AttributeError. Is this by design (if so, why)? > > class A( object ):

Re: __new__

2005-11-08 Thread Steven Bethard
James Stroud wrote: > Hello All, > > I'm running 2.3.4 > > I was reading the documentation for classes & types >http://www.python.org/2.2.3/descrintro.html > And stumbled on this paragraph: > > """ > __new__ must return an object. There's nothing that requires that it return a > new obj

Re: derived / base class name conflicts

2005-11-16 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > so the following would not result in any conflicts > > class A: >def __init__(self): > self.__i= 0 > > class B(A): >def __init__(self): > A.__init__(self) > self.__i= 1 > Be careful here. The above won't result in any conflicts, but related

Re: Proposal for adding symbols within Python

2005-11-16 Thread Steven Bethard
Pierre Barbier de Reuille wrote: > Proposal > > > First, I think it would be best to have a syntax to represent symbols. > Adding some special char before the name is probably a good way to > achieve that : $open, $close, ... are $ymbols. How about using the prefix "symbol." instead of "

Re: Python Library Reference - question

2005-11-17 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > The "Python LIbrary Reference" at > http://docs.python.org/lib/contents.html seems to be an important > document. I have two questions > > Q1. How do you search inside "Python LibraryReference" ? Does it exist > in pdf or chm form? One other option. Go to google and us

how to organize a module that requires a data file

2005-11-17 Thread Steven Bethard
Ok, so I have a module that is basically a Python wrapper around a big lookup table stored in a text file[1]. The module needs to provide a few functions:: get_stem(word, pos, default=None) stem_exists(word, pos) ... Because there should only ever be one lookup table, I feel lik

Re: how to organize a module that requires a data file

2005-11-17 Thread Steven Bethard
Terry Hancock wrote: > On Thu, 17 Nov 2005 12:18:51 -0700 > Steven Bethard <[EMAIL PROTECTED]> wrote: > >>My problem is with the text file. Where should I keep it? >> >>I can only think of a few obvious places where I could >>find the text file at import

Re: how to organize a module that requires a data file

2005-11-17 Thread Steven Bethard
Larry Bates wrote: > Personally I would do this as a class and pass a path to where > the file is stored as an argument to instantiate it (maybe try > to help user if they don't pass it). Something like: > > class morph: > def __init__(self, pathtodictionary=None): > if pathtodictiona

textwrap.dedent() drops tabs - bug or feature?

2005-11-17 Thread Steven Bethard
So I've recently been making pretty frequent use of textwrap.dedent() to allow me to use triple-quoted strings at indented levels of code without getting the extra spaces prefixed to each line. I discovered today that not only does textwrap.dedent() strip any leading spaces, but it also substi

Re: How to convert a "long in a string" to a "long"?

2005-11-18 Thread Steven Bethard
[EMAIL PROTECTED] wrote: 0xL > > 4294967295L > > OK, this is what I want, so I tried > > s = long("0xL") > ValueError: invalid literal for long(): 0xL >>> int("0x", 0) 4294967295L STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: textwrap.dedent() drops tabs - bug or feature?

2005-11-19 Thread Steven Bethard
Peter Hansen wrote: > Steven Bethard wrote: > >> Note that even though the tabs are internal, they are still removed by >> textwrap.dedent(). The documentation[1] says: > > ... > >> So it looks to me like even if this is a "feature" it is undocument

the name of a module in which an instance is created?

2005-11-21 Thread Steven Bethard
The setup: I'm working within a framework (designed by someone else) that requires a number of module globals to be set. In most cases, my modules look like: (1) a class definition (2) the creation of one instance of that class (3) binding of the instance methods to the appropriate module global

Re: the name of a module in which an instance is created?

2005-11-22 Thread Steven Bethard
Mardy wrote: > I'm not sure I got your problem correctly, however see if this helps: > > $ cat > test.py > class myclass: > name = __module__ > ^D > [snip] > > >>> import test > >>> a = test.myclass() > >>> a.name > 'test' > > This works, as we define "name" to be a class attribute. > Is th

defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-22 Thread Steven Bethard
[Duncan Booth] > >>> aList = ['a', 1, 'b', 2, 'c', 3] > >>> it = iter(aList) > >>> zip(it, it) >[('a', 1), ('b', 2), ('c', 3)] [Alan Isaac] > That behavior is currently an accident. >http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1121416 [Bengt Richter] > That sa

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: >> > ii. The other problem is easier to explain by example. >> > Let it=iter([1,2,3,4]). >> > What is the result of zip(*[it]*2)? >> > The current answer is: [(1,2),(3,4)], >> > but it is impossible to determine this from the docs, >> > which would allow [(1,3),(2,4)] inste

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-23 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Steven Bethard wrote: > >>[EMAIL PROTECTED] wrote: >> >>>>>ii. The other problem is easier to explain by example. >>>>>Let it=iter([1,2,3,4]). >>>>>What is the result of zip(*[it]*2)? >>>>>The

Re: Death to tuples!

2005-11-28 Thread Steven Bethard
Dan Bishop wrote: > Mike Meyer wrote: > >>Is there any place in the language that still requires tuples instead >>of sequences, except for use as dictionary keys? > > The % operator for strings. And in argument lists. > > def __setitem__(self, (row, column), value): >... Interesting that b

Re: Death to tuples!

2005-11-28 Thread Steven Bethard
Mike Meyer wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > >>Dan Bishop wrote: >> >>>Mike Meyer wrote: >>> >>> >>>>Is there any place in the language that still requires tuples instead >>>>of sequences, except for

Re: python speed

2005-11-30 Thread Steven Bethard
David Rasmussen wrote: > Harald Armin Massa wrote: > >> Dr. Armin Rigo has some mathematical proof, that High Level Languages >> like esp. Python are able to be faster than low level code like >> Fortran, C or assembly. > > Faster than assembly? LOL... :) I think the claim goes something along t

Re: [newbie] super() and multiple inheritance

2005-12-01 Thread Steven Bethard
hermy wrote: > As I understand it, using super() is the preferred way to call > the next method in method-resolution-order. When I have parameterless > __init__ methods, this works as expected. > However, how do you solve the following simple multiple inheritance > situation in python ? > > class

aligning a set of word substrings to sentence

2005-12-01 Thread Steven Bethard
I've got a list of word substrings (the "tokens") which I need to align to a string of text (the "sentence"). The sentence is basically the concatenation of the token list, with spaces sometimes inserted beetween tokens. I need to determine the start and end offsets of each token in the sente

Re: aligning a set of word substrings to sentence

2005-12-01 Thread Steven Bethard
Fredrik Lundh wrote: > Steven Bethard wrote: >> I feel like there should be a simpler solution (maybe with the re >> module?) but I can't figure one out. Any suggestions? > > using the finditer pattern I just posted in another thread: > > tokens = ['She

Re: aligning a set of word substrings to sentence

2005-12-01 Thread Steven Bethard
Paul McGuire wrote: > "Steven Bethard" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>I've got a list of word substrings (the "tokens") which I need to align >>to a string of text (the "sentence"). The sentence i

Re: aligning a set of word substrings to sentence

2005-12-02 Thread Steven Bethard
Fredrik Lundh wrote: > Steven Bethard wrote: > > >>>>I feel like there should be a simpler solution (maybe with the re >>>>module?) but I can't figure one out. Any suggestions? >>> >>>using the finditer pattern I just posted in another t

Re: aligning a set of word substrings to sentence

2005-12-02 Thread Steven Bethard
Michael Spencer wrote: > Steven Bethard wrote: > >> I've got a list of word substrings (the "tokens") which I need to >> align to a string of text (the "sentence"). The sentence is basically >> the concatenation of the token list, with spaces s

Re: aligning a set of word substrings to sentence

2005-12-02 Thread Steven Bethard
Steven Bethard wrote: > Michael Spencer wrote: > >> Steven Bethard wrote: >> >>> I've got a list of word substrings (the "tokens") which I need to >>> align to a string of text (the "sentence"). The sentence is >>>

Re: hash()

2005-12-05 Thread Steven Bethard
Tim Peters wrote: > First, if `st` is a string, `st[::-1]` is a list. I hate to question the great timbot, but am I missing something? >>> 'abcde'[::-1] 'edcba' STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterating over test data in unit tests

2005-12-05 Thread Steven Bethard
Ben Finney wrote: > Maybe I need to factor out the iteration into a generic iteration > function, taking the actual test as a function object. That way, the > dataset iterator doesn't need to know about the test function, and > vice versa. > > def iterate_test(self, test_func, test_params=

Re: i=2; lst=[i**=2 while i<1000]

2005-12-06 Thread Steven Bethard
Daniel Schüle wrote: > I am wondering if there were proposals or previous disscussions in this > NG considering using 'while' in comprehension lists > > # pseudo code > i=2 > lst=[i**=2 while i<1000] I haven't had much need for anything like this. Can't you rewrite with a list comprehension so

Re: Unexpected behavior of read only attributes and super

2005-12-06 Thread Steven Bethard
Samuel M. Smith wrote: > The dict class has some read only attributes that generate an exception > if I try to assign a value to them. > I wanted to trap for this exception in a subclass using super but it > doesn't happen. > > class SD(dict): >pass > [snip] > s = SD() > super(SD,s).__set

Re: Documentation suggestions

2005-12-07 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Iain> I like the Global Module Index in general - it allows quick access > Iain> to exactly what I want. I would like a minor change to it though > Iain> - stop words starting with a given letter rolling over to another > Iain> column (for example, os.pat

Re: ElementTree - Why not part of the core?

2005-12-07 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > ElementTree on the other hand provides incredibly easy access to XML > elements and works in a more Pythonic way. Why has the API not been > included in the Python core? While I fully agree that ElementTree is far more Pythonic than the dom-based stuff in the core, thi

Re: Unexpected behavior of read only attributes and super

2005-12-07 Thread Steven Bethard
Samuel M. Smith wrote: > On 06 Dec, 2005, at 20:53, Steven Bethard wrote: >> You can always shadow class-level attributes in the instance dict. >> (That's what you were doing.) If you want to (try to) replace an >> attribute in the class dict, you need to use the class

Re: Documentation suggestions

2005-12-07 Thread Steven Bethard
Aahz wrote: > In article <[EMAIL PROTECTED]>, > A.M. Kuchling <[EMAIL PROTECTED]> wrote: > >>So now we're *really* stuck. The RefGuide doesn't describe the rules; >>the PEP no longer describes them either; and probably only Guido can >>write the new text for the RefGuide. (Or are the semantics t

Re: ElementTree - Why not part of the core?

2005-12-08 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I think the key here is ElementTree's Pythoninc API. While it's clearly > possible to install it as a third-party package, I think there's a clear > best-of-breed aspect here that suggests it belongs in the standard > distribution simply to discourage continued use of DO

Re: Unexpected behavior of read only attributes and super

2005-12-08 Thread Steven Bethard
Samuel M. Smith wrote: > If you would care to elaborate on the how the lookup differs with > method descriptor it would be most appreciated. For the more authoritative guide, see: http://users.rcn.com/python/download/Descriptor.htm The basic idea is that a descriptor is an object that sits

Re: How to find the type ...

2005-12-09 Thread Steven Bethard
Lad wrote: > How can I find out in Python whether the operand is integer or a > character and change from char to int ? Python doesn't have a separate character type, but if you want to convert a one-character string to it's ASCII number, you can use ord(): >>> ord('A'), ord('z') (65, 122) The

Re: slice notation as values?

2005-12-10 Thread Steven Bethard
Antoon Pardon wrote: > So lets agree that tree['a':'b'] would produce a subtree. Then > I still would prefer the possibility to do something like: > > for key in tree.iterkeys('a':'b') > > Instead of having to write > > for key in tree['a':'b'].iterkeys() > > Sure I can now do it like this:

Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Alex Martelli wrote: Steven Bethard <[EMAIL PROTECTED]> wrote: (2) lambda a: a.lower() My first thought here was to use str.lower instead of the lambda, but of course that doesn't work if 'a' is a unicode object: Right, but string.lower works (after an 'import string&#x

Re: More baby squeaking - iterators in a class

2004-12-31 Thread Steven Bethard
Bulba! wrote: Thanks to everyone for their responses, but it still doesn't work re returning next() method: class R3: def __init__(self, d): self.d=d self.i=len(d) def __iter__(self): d,i = self.d, self.i while i>0: i-=1 yield d[i]

Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Alex Martelli wrote: Steven Bethard <[EMAIL PROTECTED]> wrote: py> class C(object): ... def __init__(self): ... self.plural = lambda n: int(n != 1) ... py> c = C() py> c.__class__.plural(1) Traceback (most recent call last): File "", line 1, in ? AttributeE

Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Steven Bethard
Alex Martelli wrote: Paul L. Du Bois <[EMAIL PROTECTED]> wrote: def fn(gen): """Turns a generator expression into a callable.""" def anonymous(*args): return gen.next() return anonymous def args(): """Works with fn(); yields args passed to anonymous().""" while True: yield sys._getfr

Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Steven Bethard
Simo Melenius wrote: map (def x: if foo (x): return baz_1 (x) elif bar (x): return baz_2 (x) else: global hab hab.append (x) return baz_3 (hab), [1,2,3,4,5,6]) I think this would probably have to be wri

Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Adam DePrince wrote: Lets not forget the "real reason" for lambda ... the elegance of orthogonality. Why treat functions differently than any other object? We can operate on every other class without having to involve the namespace, why should functions be any different? Yup. I think in most o

Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Hans Nowak wrote: Adam DePrince wrote: In sort, we must preserve the ability to create an anonymous function simply because we can do so for every other object type, and functions are not special enough to permit this special case. Your reasoning makes sense... lambda enables you to create a funct

Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Steven Bethard
Paul Rubin wrote: [EMAIL PROTECTED] (Alex Martelli) writes: We should have an Evilly Cool Hack of the Year, and I nominate Paul du Bois's one as the winner for 2004. Do I hear any second...? The year's not over yet :). Ok, now that we're past 0:00:00 UTC, I'll second that nomination! ;) Steve P.S.

Re: Looping using iterators with fractional values

2005-01-01 Thread Steven Bethard
Mark McEahern wrote: drife wrote: Hello, Making the transition from Perl to Python, and have a question about constructing a loop that uses an iterator of type float. How does one do this in Python? Use a generator: >>> def iterfloat(start, stop, inc): ... f = start ... while f <= stop:

Re: I need some advice/help on running my scripts

2005-01-01 Thread Steven Bethard
Sean wrote: My problem is that many of the example scripts are run on Linux machines and I am using Win XP Pro. Here is a specific example of what is confusing me. If I want to open a file from the dos prompt in some script do I just write the name of the file I want to open (assuming it is in th

Re: UserDict deprecated

2005-01-01 Thread Steven Bethard
Uwe Mayer wrote: Saturday 01 January 2005 22:48 pm Hans Nowak wrote: I am curious, what would you do with a class that derives from both file and dict? I was writing a class that read /writes some binary file format. I implemented the functions from the file interface such that they are refering to

PEP 288 ponderings

2005-01-01 Thread Steven Bethard
PEP 288 was mentioned in one of the lambda threads and so I ended up reading it for the first time recently. I definitely don't like the idea of a magical __self__ variable that isn't declared anywhere. It also seemed to me like generator attributes don't really solve the problem very cleanly

Re: PEP 288 ponderings

2005-01-02 Thread Steven Bethard
Raymond Hettinger wrote: [Steven Bethard] (2) Since in all the examples there's a one-to-one correlation between setting a generator attribute and calling the generator's next function, aren't these generator attribute assignments basically just trying to define the 'next'

Re: arbitrary number of arguments in a function declaration

2005-01-02 Thread Steven Bethard
rbt wrote: How do I set up a function so that it can take an arbitrary number of arguments? If you haven't already, you should check out the Tutorial: http://docs.python.org/tut/node6.html#SECTION00673 How might I make this dynamic so that it can handle any amount of expenses? de

Re: Lambda as declarative idiom (was RE: what is lambda used for in real code?)

2005-01-03 Thread Steven Bethard
Roman Suzi wrote: I wish lambdas will not be deprecated in Python but the key to that is dropping the keyword (lambda). If anybody could think of a better syntax for lambdas _with_ arguments, we could develop PEP 312 further. Some suggestions from recent lambda threads (I only considered the ones

Re: Hlelp clean up clumpsy code

2005-01-04 Thread Steven Bethard
It's me wrote: Another newbie question. There must be a cleaner way to do this in Python: section of C looking Python code a = [[1,5,2], 8, 4] a_list = {} i = 0 for x in a: if isinstance(x, (int, long)): x = [x,] for w in [y for y in x]: i = i + 1 a_list[w]

Re: search backward

2005-01-04 Thread Steven Bethard
Robert wrote: I need to find the location of a short string in a long string. The problem however is that i need to search backward. Does anybody know how to search in reverse direction? How about str.rfind? py> s = 'abc:def:abc' py> s.rfind('abc') 8 Steve -- http://mail.python.org/mailman/listinfo

why does UserDict.DictMixin use keys instead of __iter__?

2005-01-04 Thread Steven Bethard
Sorry if this is a repost -- it didn't appear for me the first time. So I was looking at the Language Reference's discussion about emulating container types[1], and nowhere in it does it mention that .keys() is part of the container protocol. Because of this, I would assume that to use UserDict.Di

Re: why does UserDict.DictMixin use keys instead of __iter__?

2005-01-04 Thread Steven Bethard
Nick Coghlan wrote: Steven Bethard wrote: Sorry if this is a repost -- it didn't appear for me the first time. So I was looking at the Language Reference's discussion about emulating container types[1], and nowhere in it does it mention that .keys() is part of the container protocol.

Re: why does UserDict.DictMixin use keys instead of __iter__?

2005-01-04 Thread Steven Bethard
John Machin wrote: Steven Bethard wrote: So I was looking at the Language Reference's discussion about emulating container types[1], and nowhere in it does it mention that .keys() is part of the container protocol. I don't see any reference to a "container protocol". S

Re: Lambda as declarative idiom (was RE: what is lambda used for in real code?)

2005-01-04 Thread Steven Bethard
Bengt Richter wrote: On Mon, 03 Jan 2005 18:54:06 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote: Roman Suzi wrote: I wish lambdas will not be deprecated in Python but the key to that is dropping the keyword (lambda). If anybody could think of a better syntax for lambdas _with_ arguments, we

Re: Lambda as declarative idiom (was RE: what is lambda used for in real code?)

2005-01-04 Thread Steven Bethard
Roman Suzi wrote: On Mon, 3 Jan 2005, Steven Bethard wrote: Roman Suzi wrote: I wish lambdas will not be deprecated in Python but the key to that is dropping the keyword (lambda). If anybody could think of a better syntax for lambdas _with_ arguments, we could develop PEP 312 further. Some

Re: why does UserDict.DictMixin use keys instead of __iter__?

2005-01-04 Thread Steven Bethard
John Machin wrote: OK, I'll rephrase: what is your interest in DictMixin? My interest: I'm into mappings that provide an approximate match capability, and have a few different data structures that I'd like to implement as C types in a unified manner. The plot includes a base type that, similarly to

Re: what is lambda used for in real code?

2005-01-06 Thread Steven Bethard
I wrote: * Functions I don't know how to rewrite Some functions I looked at, I couldn't figure out a way to rewrite them without introducing a new name or adding new statements. [snip] inspect.py: def formatargspec(args, varargs=None, varkw=None, ... formatvara

Re: Securing a future for anonymous functions in Python

2005-01-07 Thread Steven Bethard
Alan Gauld wrote: On Thu, 06 Jan 2005 21:02:46 -0600, Doug Holton <[EMAIL PROTECTED]> wrote: used, but there are people who do not like "lambda": http://lambda-the-ultimate.org/node/view/419#comment-3069 The word "lambda" is meaningless to most people. Of course so is "def", which might be why Gu

Re: python3: 'where' keyword

2005-01-07 Thread Steven Bethard
Andrey Tatarinov wrote: Hi. It would be great to be able to reverse usage/definition parts in haskell-way with "where" keyword. Since Python 3 would miss lambda, that would be extremly useful for creating readable sources. Usage could be something like: >>> res = [ f(i) for i in objects ] where

Re: python3: 'where' keyword

2005-01-07 Thread Steven Bethard
Steven Bethard wrote: How often is this really necessary? Could you describe some benefits of this? I think the only time I've ever run into scoping problems is with lambda, e.g. [lambda x: f(x) for x, f in lst] instead of [lambda x, f=f: for x, f in lst] Sorry, bad example,

switching an instance variable between a property and a normal value

2005-01-07 Thread Steven Bethard
I'd like to be able to have an instance variable that can sometimes be accessed as a property, and sometimes as a regular value, e.g. something like: py> class C(object): ... def usevalue(self, x): ... self.x = x ... def usefunc(self, func, *args, **kwds): ... self._func,

Re: Display Function Code Body?

2005-01-07 Thread Steven Bethard
Haibao Tang wrote: What I would like to do is to write a function like disp(), when typed, it can give you the code infomation. Check the docs entitled "Retrieving source code": http://docs.python.org/lib/inspect-source.html Depending on what you want, you may be able to use inspect.getsource: py>

Re: switching an instance variable between a property and a normal value

2005-01-07 Thread Steven Bethard
Robert Brewer wrote: Steven Bethard wrote: I'd like to be able to have an instance variable that can sometimes be accessed as a property, and sometimes as a regular value, e.g. something like: ... py> c.x is c.x # I'd like this to be False You'd like 'c.x is c.x

Re: Notification of PEP Updates

2005-01-07 Thread Steven Bethard
Bengt Richter wrote: On Sat, 08 Jan 2005 03:28:34 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote: I can't recall which thread this came up in, so I'm starting a new one. . . Barry Warsaw has kindly added a "peps" topic to the python-checkins mailing list. If you want to be notified only when PEP's

Re: switching an instance variable between a property and a normal value

2005-01-07 Thread Steven Bethard
Robert Brewer wrote: Steven Bethard wrote: I'm playing around with a mapping type that uses setdefault as suggested in http://www.python.org/moin/Python3_2e0Suggestions. The default value for a missing key is either a simple value, or a value generated from a function. If it's

Re: Securing a future for anonymous functions in Python

2005-01-07 Thread Steven Bethard
Alan Gauld wrote: On Fri, 07 Jan 2005 08:44:57 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: The unfamiliar argument doesn't work for me. After all most people are unfamiliar with complex numbers (or imaginary) numbers complex numbers. Lambdas, on the other hand, show up in all kin

Re: Speed revisited

2005-01-08 Thread Steven Bethard
Bulba! wrote: Following advice of two posters here (thanks) I have written two versions of the same program, and both of them work, but the difference in speed is drastic, about 6 seconds vs 190 seconds for about 15000 of processed records, taken from 2 lists of dictionaries. I've read "Python Per

Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steven Bethard
Robert Kern wrote: Andrey Tatarinov wrote: anyway list comprehensions are just syntaxic sugar for >>> for var in list: >>> smth = ... >>> res.append(smth) (is that correct?) so there will be no speed gain, while map etc. are C-implemented It depends. Try def square(x): return x*

Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steven Bethard
John Machin wrote: Steven Bethard wrote: Note that list comprehensions are also C-implemented, AFAIK. Rather strange meaning attached to "C-implemented". The implementation generates the code that would have been generated had you written out the loop yourself, with a speed boost (com

Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Steve Bethard wrote: Robert Kern wrote: def square(x): return x*x map(square, range(1000)) versus [x*x for x in range(1000)] Hint: function calls are expensive. $ python -m timeit -s "def square(x): return x*x" "map(square, range(1000))" 1000 loops, best of 3:

Re: else condition in list comprehension

2005-01-10 Thread Steven Bethard
Luis M. Gonzalez wrote: It's me wrote: z = [i + (2, -2)[i % 2] for i in range(10)] But then why would you want to use such feature? Wouldn't that make the code much harder to understand then simply: z=[] for i in range(10): if i%2: z.append(i-2) else: z.append(i+2) Or are

Re: syntax error in eval()

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

[OT] Re: Old Paranoia Game in Python

2005-01-10 Thread Steven Bethard
Terry Reedy wrote: Never saw this specific game. Some suggestions on additional factoring out of duplicate code. def next_page(this_page): print "\n" if this_page == 0: page = 0 return The following elif switch can be replaced by calling a selection from a list of functions: [None,

Re: Python3: on removing map, reduce, filter

2005-01-10 Thread Steven Bethard
David M. Cooke wrote: Steven Bethard <[EMAIL PROTECTED]> writes: Some timings to verify this: $ python -m timeit -s "def square(x): return x*x" "map(square, range(1000))" 1000 loops, best of 3: 693 usec per loop $ python -m timeit -s "[x*x for x in range(1000)]&quo

stretching a string over several lines (Re: PyChecker messages)

2005-01-10 Thread Steven Bethard
Frans Englich wrote: Also, another newbie question: How does one make a string stretch over several lines in the source code? Is this the proper way? (1) print "asda asda asda asda asda asda " \ "asda asda asda asda asda asda " \ "asda asda asda asda asda asda" A couple of other op

Re: Handing a number of methods to the same child class

2005-01-11 Thread Steven Bethard
Dave Merrill wrote: Somewhat silly example: I know you've hedged this by calling it a "silly" example, but I would like to point out that your set_X methods are unnecessary -- since Python allows you to overload attribute access, getters and setters are generally unnecessary. class Address:

Re: property () for Java Programmers ?

2005-01-12 Thread Steven Bethard
michael wrote: Hi there, I am somewhat confused by the following : class C(object): def getx(self): return self.__x def setx(self, value): self.__x = "extended" + value def delx(self): del self.__x x = property(getx, setx, delx, "I'm the 'x' property.") So far so good :-) But what t

  1   2   3   4   5   6   7   8   9   10   >