Re: is this possible?

2005-07-23 Thread Steven D'Aprano
stall *something* -- compared to even the most impoverished Linux distro, Windows is very much "batteries not included", and while Python does come with many batteries, a full-blown postscript interpreter is not one of them. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a dictionary from an object

2005-07-23 Thread Steven D'Aprano
ticularly useful behaviour. How do you use it? py> D = dictobj("hello world") py> D {} py> D.obj 'hello world' py> D["food"] = "spam" py> D {'food': 'spam'} py> D["food"] Traceback (most recent call last): File "", line 1, in ? File "", line 5, in __getitem__ AttributeError: 'str' object has no attribute 'food' -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: find a specified dictionary in a list

2005-07-23 Thread Steven D'Aprano
On Fri, 22 Jul 2005 12:42:04 +, Odd-R. wrote: > On 2005-07-22, John Machin <[EMAIL PROTECTED]> wrote: >> Odd-R. wrote: >>> I have this list: >>> >>> [{'i': 'milk', 'oid': 1}, {'i': 'butter', 'oid': 2},{'i':'cake','oid':3}] >>> >>> All the dictionaries of this list are of the same form, and a

Re: Getting a dictionary from an object

2005-07-23 Thread Steven Bethard
Thanos Tsouanas wrote: > I would like to have a quick way to create dicts from object, so that a > call to foo['bar'] would return obj.bar. > > The following works, but I would prefer to use a built-in way if one > exists. Is there one? Maybe I'm not understanding your problem, but have you look

Re: dictionary that discards old items

2005-07-23 Thread Steven Bethard
[Raymond Hettinger] >>class Cache(dict): >> def __init__(self, n, *args, **kwds): >> self.n = n >> self.queue = collections.deque() >> dict.__init__(self, *args, **kwds) [Bengt Richter] > Minor comment: There is a potential name collision problem for keyword > n=something, >

Re: tuple to string?

2005-07-23 Thread Steven D'Aprano
On Sat, 23 Jul 2005 23:26:19 +1000, John Machin wrote: > Steven D'Aprano wrote: > >> >> >>>>>''.join(map(lambda n: chr(n), (0x73, 0x70, 0x61, 0x6D))) >> >> 'spam' > > Why the verbal diarrhoea? One line is hardly

Re: tuple to string?

2005-07-23 Thread Steven D'Aprano
, first served" is a precedence rule? I'm not being academic here. I have used both these languages extensively, admittedly many years ago. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Lists & "pointers"

2005-07-23 Thread Steven D'Aprano
;>> DM2 {1: [0, 1], 2: [4, 5]} So far so good. But now look: >>> DM1[1].append(999) >>> DM1 {1: [0, 1, 999], 2: [4, 5], 3: [0, 2]} >>> DM2 {1: [0, 1, 999], 2: [4, 5]} The difference is that although copy makes a copy of the top level of the dict, it DOESN'T make copies of the individual objects within the dict. This doesn't matter is the objects are immutable, but if they are lists or other dicts, you can get surprises like the above. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a dictionary from an object

2005-07-23 Thread Steven D'Aprano
__str__ File "", line 4, in __str__ ... File "", line 4, in __str__ File "", line 4, in __str__ RuntimeError: maximum recursion depth exceeded -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: consistency: extending arrays vs. multiplication ?

2005-07-23 Thread Steven D'Aprano
ations, they are list operations. Lists in Python can contain anything, not just numeric values. Python doesn't have built-in mathematical arrays, otherwise known as matrices. There are modules that do that, but I haven't used them. Google on Numeric Python. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a dictionary from an object

2005-07-23 Thread Steven D'Aprano
On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote: > On Sat, Jul 23, 2005 at 11:22:21PM +1000, Steven D'Aprano wrote: >> On Sat, 23 Jul 2005 11:48:27 +0300, Thanos Tsouanas wrote: >> > Hello. >> > >> > I would like to have a quick way to create

Re: [path-PEP] Path inherits from basestring again

2005-07-23 Thread Steven D'Aprano
\path\name.txt" else: print longname -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a dictionary from an object

2005-07-24 Thread Steven D'Aprano
On Sun, 24 Jul 2005 12:03:47 +0300, Thanos Tsouanas wrote: > On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote: >> On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote: >> > >> > print foo %do >> > >> > where do is a dictobj

Re: Getting a dictionary from an object

2005-07-24 Thread Steven D'Aprano
On Sun, 24 Jul 2005 12:07:02 +0300, Thanos Tsouanas wrote: > On Sat, Jul 23, 2005 at 06:59:43PM -0600, Steven Bethard wrote: >> Thanos Tsouanas wrote: >> > I would like to have a quick way to create dicts from object, so that a >> > call to foo['bar']

Re: tuple to string?

2005-07-24 Thread Steven D'Aprano
hematical convention is that modulus has lower precedence than addition, eg in "clock arithmetic" we expect that three hours after ten is one: 10+3 modulo 12 is 1, not 13. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: tuple to string?

2005-07-24 Thread Steven D'Aprano
of -- whether or not it was unthinkable for the precedence of % to be anything but that of multiplication and division. Surely the precedence rules of other languages have some relevance to that question. Still, the subject is rapidly losing whatever interest it may have had. -- Steven. --

Re: Getting a dictionary from an object

2005-07-24 Thread Steven Bethard
Thanos Tsouanas wrote: > Steven Bethard wrote: > >>Maybe I'm not understanding your problem, but have you looked at the >>builtin "vars()"? > > I didn't know about it, but I knew about object.__dict__ which is, as I > see equivalent with vars(obje

Re: Problem loading a file of words

2005-07-25 Thread Steven D'Aprano
always gives an error, specifically: > (Note: ccehimnostyz is for zymotechnics, which is in the > large dictionary) > > > *--beginning of example--* > Enter a scrambled word : ccehimnostyz Traceback (most recent call last): > File "unscram.py", line 62, in ? > results = dictionary[sort_string(lookup)] > KeyError: 'ccehimnostyz' > *--end of example--* If this error is always happening for the LAST line in the text file, I'm guessing there is no newline after the word. So when you read the text file and build the dictionary, you inadvertently remove the "s" from the word before storing it in the dictionary. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to write a line in a text file

2005-07-25 Thread Steven D'Aprano
casional security advisory for applications which use insufficiently-random temporary file names. Does anyone have anything suitable for a "safe-overwrite" module? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a dictionary from an object

2005-07-25 Thread Steven Bethard
Thanos Tsouanas wrote: > On Sun, Jul 24, 2005 at 02:14:15PM -0600, Steven Bethard wrote: > >>How about something like: >> dict((name, getattr(obj, name)) for name in dir(obj)) > > Pretty!!! > >>Looks like this will get instance attributes, class attri

Re: how to write a line in a text file

2005-07-25 Thread Steven D'Aprano
Wade wrote: > Steven D'Aprano wrote: > >>I'm usually opposed to creeping featuritis in programming languages ("it >>would be really cool if Python had a built-in command to do my entire >>application") but safe over-writing of files does c

Re: how to write a line in a text file

2005-07-26 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote: > Tue, Jul 26, 2005 at 01:41:36PM +1000, Steven D'Aprano пишет: > >>Long ago, when dinosaurs roamed the Earth, (a.k.a. >>"before OS X on the Macintosh") Apple suggested a bit >>of Pascal code for safely updating a file: >> &

Re: Suggestions for Python XML library which can search and insert

2005-07-26 Thread Steven D'Aprano
s? What error do you get when you try it? Or are you just opposed to for loops on philosophical grounds? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug Report / Patch (1159139 cgi.py invalid REQUEST_METHOD set)

2005-07-26 Thread Steven Bethard
Joe wrote: > Back in March I submitted a patch for cgi.py to sourceforge to fix a problem > with the handling of an invalid REQUEST_METHOD. > > I thought I followed all the steps to properly submit the bug and patch but > the patch is still sitting there in limbo. Patches get processed when peo

Re: how to write a line in a text file

2005-07-27 Thread Steven D'Aprano
lead to data loss, but I prefer to take a modicum of care not to destroy their data. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: [Beginner] Calling a function by its name in a string

2005-07-27 Thread Steven D'Aprano
d hand it to them without a word of warning about the consequences. And then we all act surprised when we learn about the latest virus or security hole that allows a hostile user to use a music player or paint program to take over the entire operating system. Or whatever. "We're all adult

Re: anything to do

2005-07-27 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > is there any place which lists jobs to be done...you know minor jobs > and requests thats nobody has found time to do. Not all of these are pure Python, so you may have to wade through a bit to avoid the C ones, but a good place to look is the Python trackers on source

Re: can list comprehensions replace map?

2005-07-27 Thread Steven Bethard
David Isaac wrote: > I ran into a need for something like map(None,x,y) > when len(x)>len(y). I cannot it seems use 'zip' because I'll lose > info from x. I almost never run into this situation, so I'd be interested to know why you need this. Here's one possible solution: py> import itertools

Re: all possible combinations

2005-07-28 Thread Steven D'Aprano
f there is any policy of prohibiting specialist modules just because they don't have universal need. And no, I'm not volunteering. I may, if I get an itch, but at this moment in my life I'm not that fussed one way or another. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: functions without parentheses

2005-07-28 Thread Steven D'Aprano
On Thu, 28 Jul 2005 00:59:51 -0700, Jerry He wrote: > Hi, > Is it possible to create a function that you can use > without parenthesizing the arguments? What problem are you trying to solve that requires this sort of syntax, and why can't it be solved with parentheses? -- Ste

Re: Create a variable "on the fly"

2005-07-28 Thread Steven Bethard
Paul D.Smith wrote: > 2. A simple Python config which searches for all shell environment variables > named "MY_..." and instantiates then as Python variables. my_vars = dict((k, v) for k, v in os.environ.iteritems() if k.startswith('MY_')) globals().update(my_vars)

Re: functions without parentheses

2005-07-28 Thread Steven Bethard
Jerry He wrote: > def examine(str): > . > . > > Is there some way to define it so that I can call it > like > > examine "string" > instead of examine("string")? What do you want to happen when someone types: examine ??? Or better yet, what if you do something like:

Re: functions without parentheses

2005-07-29 Thread Steven D'Aprano
ing") if > examine as an expression evaluates to an object that has a __invisbinop__ > method. Why would you want to? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-29 Thread Steven Bethard
Steve Holden wrote: > >>> tt = "".join([chr(i) for i in range(256)]) Or: tt = string.maketrans('', '') STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Hiding

2005-07-29 Thread Steven Bethard
Jason Drew wrote: > Also, I think using file("C:\file.txt") is now preferred > to open("C:\file.txt"). Guido has said he wants to keep open() around as the way to open a file-like object, with the theory that in the future open might also support opening non-files (e.g. urls). So open("C:\file.

Re: On fighting fire with fire...

2005-07-29 Thread Steven D'Aprano
t." At worst they might complain to their friends afterwards. But on the Internet, people who deserve that tongue-lashing think that because they can retaliate, they should retaliate -- and that's where the risk of escalation from punitive raid to unproductive flame war lies. -- S

Re: On fighting fire with fire...

2005-07-29 Thread Steven D'Aprano
displayed is almost as bad as aggressive flaming, and far worse than Robert's self-depreciating humour. In any case, I don't agree with you that all people deserve the same amount of respect. Respect is rare currency, and has to be earned, not just given away to anyone. -- Steven

Comparison of functions

2005-07-30 Thread Steven D'Aprano
lt; b False So I'm puzzled about how Python compares the two. If we compare a and b again, we will always get the same answer. But if we create a new pair of anonymous functions with lambda, and compare them, it is the luck of the draw each time whether the first compares bigger or smaller than the second. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
rts like being unable to sort lists with some objects, while being able to make meaningless comparisons like ''.join >= [].append. I'm not sure what the solution to this ugly state of affairs is. I'm not even sure if there is a solution. But I'm willing to make a good effort to *look*, and even though you were joking, I don't appreciate being told not to. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 14:20:50 +0200, tiissa wrote: > Steven D'Aprano wrote: >> Playing around with comparisons of functions (don't ask), I discovered an >> interesting bit of unintuitive behaviour: >> >>>>>a = lambda y: y >>>>>b = l

Re: [path-PEP] Path inherits from basestring again

2005-07-30 Thread Steven D'Aprano
en given that, I'm not convinced that it is a good idea to turn '/' into a join-path operator. I don't have any good reasons for objecting either, just a funny little feeling in the back of my head that says that no good can ever come from allowing Path("C:\Windows")/"cmd.com". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP on path module for standard library

2005-07-30 Thread Steven D'Aprano
ely deletes it, whatever it is, without you >> having to do the if file/if directory dance. I suppose it would need >> a politically correct name. >> which you really have to do every time you delete. > > *grin* Any naming suggestions? force_delete() -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
ns are NOT the same, and it is an ugliness in an otherwise beautiful language that Python treats them as the same. Mathematically, 1 == 1.0 == 1+0j but in the dictionary "1" should sort before "1.0" which sorts before "1.0+0.0j". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
an the number four? Why does hundred come before ten? What does it mean to say that elephant is less than mouse? When you can answer those questions, you will be enlightened. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
order > them, > not on a one-dimensional scale. Of course you can order them. You are confusing order with magnitude. The two are not identical, although they are similar enough in some contexts as to cause confusion. I admit that I haven't fully grasped all the subtleties of the general ordering problem. Fortunately, my needs are much less lofty. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 16:13:22 +, Adriano Varoli Piazza wrote: > Steven D'Aprano ha scritto: > >> It was easy. I never once asked myself whether some complex number was >> greater or less than another, I just asked "which one comes first in a >> lexicograph

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
this time, I'm not sure how to implement a better solution, or even if there is a better solution, but I am giving it some thought. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 17:57:20 +, Adriano Varoli Piazza wrote: > Steven D'Aprano ha scritto: > >> Do you understand the difference between partial and total ordering, or >> weakly and strongly ordered? When you do understand them, come back and >> tell me

Re: How to convert a string like '777' to an octal integer like 0777?

2005-07-31 Thread Steven D'Aprano
ding zero, and in hex if you use a leading 0x or 0X. >>> 010 8 >>> 0x10 16 >>> 010 + 0x10 24 As John pointed out, you don't have to use octal for chmod. You can use decimal, or hex -- anything that is an integer. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: namespaces

2005-07-31 Thread Steven D'Aprano
the module namespace. Then after you are finished with the bindings, delete them: import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) def translate(text): return text.translat

Re: namespaces

2005-07-31 Thread Steven D'Aprano
On Sun, 31 Jul 2005 15:09:48 +0200, Paolino wrote: > Steven D'Aprano wrote: > >> def translate(text): >> import string >> all=string.maketrans('','') >> badcars=all.translate(all,string.letters+string.digits) >> t

Re: getting an empty tuple

2005-07-31 Thread Steven D'Aprano
ound" else: print "%d rows were found" % x Tuples can be empty: if len(x) == 0: print "no rows were found" or if you prefer: if x == (): print "no rows were found" But the cleanest, most Pythonic way is just to do a truth-test: if x: print "something was found" else: print "x is empty, false, blank, nothing..." -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

python-dev summary for 2005-07-01 to 2005-07-15

2005-07-31 Thread Steven Bethard
[The HTML version of this Summary is available at http://www.python.org/dev/summary/2005-07-01_2005-07-15.html] = Announcements = -- QOTF (Quotes of the Fortnight) -- Marc-Andre Lemburg provides perhaps the best summ

Re: namespaces

2005-07-31 Thread Steven D'Aprano
Rob Williscroft wrote: > Steven D'Aprano wrote in > news:[EMAIL PROTECTED] in > comp.lang.python: > > >>Quoting Rob Williscroft: >> >> >>> > def translate( text ) >>> > import string all=string.maketrans('

Re: namespaces

2005-08-01 Thread Steven D'Aprano
On Sun, 31 Jul 2005 21:03:36 -0700, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Most languages can create self-modifying code. That's not the >> question. The question is whether developers should write >> self-modifying code, not wheth

Re: need for speed

2005-08-01 Thread Steven D'Aprano
Make your code work. Make it work right. Then, and only then, make it run fast -- and only if it isn't already fast. Now that you have written your code, and you have made it work right, please tell us what the code is, and the results of profiling the code, and we will help you speed it up.

Re: multiple inheritance super()

2005-08-01 Thread Steven Bethard
Michele Simionato wrote: > I have found out that the more I use OOP, the less I > use inheritance" > > Just curious if others had a similar experience. Definitely. Though I think that's partly because I came from a Java background where it's a little more ingrained. Since Python relies heavil

Re: Comparison of functions

2005-08-01 Thread Steven Bethard
Steven D'Aprano wrote: > You are confusing mathematical ordering with sorting a list. Here, I will > sort some mixed complex and real numbers for you. If you look at them > closely, you will even be able to work out the algorithm I used to sort > them. > > 1 > 1+0j >

JOB: Python/web developer/network contract

2005-08-01 Thread Steven Arnold
Neosynapse Inc is seeking an experienced Python developer for a short- term engagement with a new Neosynapse government customer. The task will require 5-7 years of overall programming experience; at least two years of Python experience; experience writing web applications; and a good basic

Re: HTML/text formatting question

2005-08-03 Thread Steven Bethard
Dr. Who wrote: > I have a tool that outputs data in either html or text output. > > Currently I'm writing chucnks like: > > if html: > print '' > print '' > print '' > print 'Differences %s: %s' % (htypestr, lbl1) > if html: > ... I'd create two Formatter classes, one for HTML

Re: Bug in slice type

2005-08-11 Thread Steven Bethard
Bryan Olson wrote: > > class BuggerAll: > > def __init__(self, somelist): > self.sequence = somelist[:] > > def __getitem__(self, key): > if isinstance(key, slice): > start, stop, step = key.indices(len(self.sequence)) >

Re: performance of recursive generator

2005-08-11 Thread Steven Bethard
aurora wrote: > I love generator and I use it a lot. Lately I've been writing some > recursive generator to traverse tree structures. After taking closer > look I have some concern on its performance. > > Let's take the inorder traversal from > http://www.python.org/peps/pep-0255.html as an

Re: Why does __init__ not get called?

2005-08-11 Thread Steven Bethard
Rob Conner wrote: > By chance... does anyone know, if I wrote a class, and just wanted to > override __new__ just for the fun of it. What would __new__ look like > so that it behaves exactly the same as it does any other time. Simple: class C(object): def __new__(cls, *args, **kwargs):

Re: performance of recursive generator

2005-08-11 Thread Steven Bethard
aurora wrote: > This test somehow water down the n^2 issue. The problem is in the depth > of recursion, in this case it is only log(n). It is probably more > interesting to test: > > def gen(n): > if n: > yield n > for i in gen(n-1): > yield i You should be

Re: Why does __init__ not get called?

2005-08-11 Thread Steven Bethard
Steven Bethard wrote: > def __call__(cls, *args, **kwargs): > obj = cls.__new__() > if not isinstance(obj.__class__, cls): ^^ issubclass > return obj > obj.__class__.__init__(obj, *args, **kwargs) > return o

Re: How do these Java concepts translate to Python?

2005-08-11 Thread Steven Bethard
Ray wrote: > 1. Where are the access specifiers? (public, protected, private) There's no enforceable way of doing these. The convention is that names that begin with a single underscore are private to the class/module/function/etc. Hence why sys._getframe() is considered a hack -- it's not of

Re: How to Adding Functionality to a Class by metaclass(not by inherit)

2005-08-11 Thread Steven Bethard
kyo guan wrote: > How to Adding Functionality to a Class by metaclass(not by inherit) > [snip] > > class MetaFoo(type): > def __init__(cls, name, bases, dic): > super(MetaFoo, cls).__init__(name, bases, dic) > > for n, f in inspect.ge

Re: How do these Java concepts translate to Python?

2005-08-12 Thread Steven Bethard
bruno modulix wrote: >>but technically >>speaking, there are no public, protected, or private things. > > Yes there are: > object.name is public > object._name is protected > object.__name is private The double-underscore name-mangling is almost never worth it. It's supposed to stop name collis

Re: __getattribute__ for class object

2005-08-12 Thread Steven Bethard
Dan wrote: > Depending on what you want to do, it might be better to use properties > instead: > > class Meta(type): > x = property(lambda klass: 'Called for '+str(klass)) > > class Foo(object): > __metaclass__=Meta Also worth noting that you can inline the metaclass if you don't n

Re: Loading classes dynamically

2005-08-14 Thread Steven Bethard
Ramza Brown wrote: > try: > load = eval('%s(props)' % (props['plugin.generate'])) > except: > > It works, doesnt seem very safe. Where props['plugin.generate'] is a > class name string. And 'props' is the first arg in the constructor. Where is the class defined? The right answer to this

Re: class-call a function in a function -problem

2005-08-16 Thread Steven Bethard
wierus wrote: > class ludzik: > x=1 > y=2 > l=0 > def l(self): > ludzik.l=ludzik.x+ludzik.y > print ludzik.l > > def ala(self): > print ludzik.x > print ludzik.y > ludzik.l() Methods defined in a class expect an instance of that class as the first argument. When you write: l

Re: class-call a function in a function -problem

2005-08-16 Thread Steven Bethard
Larry Bates wrote: > def __init__(self, x=1, y=2) [snip] > self.x=x > self.y=y > self.a=0 > return > > def l(self): [snip] > self.a=self.x+self.y > print "In ludzik.l a=',self.a > return > > def ala(self): [snip] > self.l

Re: Bug in slice type

2005-08-18 Thread Steven Bethard
Michael Hudson wrote: > [EMAIL PROTECTED] writes: >> I'm fine with your favored behavior. What do we do next to get >> the doc fixed? > > I guess one of us comes up with some less misleading words. It's not > totally obvious to me what to do, seeing as the returned values *are* > indices is a sen

Re: Bug in slice type

2005-08-18 Thread Steven Bethard
I wrote: > I wanted to say something about what happens with a negative stride, to > indicate that it produces (9, -1, -2) instead of (-1, -11, -2), but I > wasn't able to navigate the Python documentation well enough. > > Looking at the Language Reference section on the slice type[1] (section

Re: dict duplicity

2005-08-18 Thread Steven Bethard
Randy Bush wrote: >for pKey, pVal in dict.iteritems(): > print \ > pKey[0], hash(pKey[0]), \ > pKey[1], hash(pKey[1]), \ > pKey[2], hash(pKey[2]), \ > "hash=", hash(pKey), \ > pVal[0], hash(pVal[0]), \ > pVal[1], hash(pVal[1]) > > whe

Re: Really virtual properties

2005-08-18 Thread Steven Bethard
Ben Finney wrote: > Not using the built-in property type. Here is a recipe for a > LateBindingProperty that does what you ask: > > Steven Bethard: > "This recipe provides a LateBindingProperty callable which allows > the getter and setter methods associated

Re: while c = f.read(1)

2005-08-19 Thread Steven Bethard
Antoon Pardon wrote: > But '', {}, [] and () are not nothing. They are empty containers. > And 0 is not nothing either it is a number. Suppose I have > a variable that is either None if I'm not registered and a > registration number if I am. In this case 0 should be treated > as any other number.

Re: stdin -> stdout

2005-08-19 Thread Steven Bethard
max(01)* wrote: > i was wondering, what's the simplest way to echo the standard input to > the standard output, with no modification. import sys for line in iter(sys.stdin.readline, ''): sys.stdout.write(line) Note that this uses the second form of iter(), which calls its first argument re

Re: stdin -> stdout

2005-08-19 Thread Steven Bethard
[email protected] wrote: > import sys > for l in sys.stdin: > sys.stdout.write(l) This is fine if you don't need the reads and writes of lines to run in lockstep. File iterators read into a buffer, so you'll probably read 4096 bytes from stdin before you ever write a line to stdout. If th

sequence slicing documentation

2005-08-19 Thread Steven Bethard
In trying to work out what's different between the start, stop and step of slice.indices() and the start, stop and step of sequence slicing[1] I found that some of the list slicing documentation[2] is vague. I'd like to submit a documentation fix, but I want to make sure I have it right. Her

Re: Proposed PEP: New style indexing, was Re: Bug in slice type

2005-08-20 Thread Steven Bethard
Bryan Olson wrote: > Steven Bethard wrote: > > Well, I couldn't find where the general semantics of a negative stride > > index are defined, but for sequences at least[1]: > > > > "The slice of s from i to j with step k is defined as the sequence of >

Re: trictionary?

2005-08-28 Thread Steven Bethard
Randy Bush wrote: > now i want to add a second count column, kinda like > > bin = {} > for whatever: >for [a, b] in foo: > x = 42 - a > if bin.has_key(x): >bin[x.b] += 1 > else: >bin[x.b] = 1 >bin[x.not b] = 0 > for x,

Re: trictionary?

2005-08-28 Thread Steven Bethard
Adam Tomjack wrote: > Steven Bethard wrote: > ... >> Using a two element list to store a pair of counts has a bad code >> smell to me. > ... > > Why is that? Note that "code smell"[1] doesn't mean that something is actually wrong, just that it might

Re: trictionary?

2005-08-29 Thread Steven Bethard
Adam Tomjack wrote: > I'd write it like this: > >bin = {} >for start, end, AS, full in heard: > week = int((start-startDate)/aWeek) > counters = bin.setdefault(week, [0, 0]) > if full: > counters[0] += 1 > else: > counters[1] += 1 > >for week,

Re: trictionary?

2005-08-29 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > import csv > temp1 = [] > temp2 = [] > reader = csv.reader(file(r"py_monsters.csv")) > for rec in reader: > temp1.append(rec) > for i in temp1[1:]: > temp2.append((i[0],dict(zip(temp1[0][1:],i[1:] > monsters = dict(temp2) I would tend to write this as: i

Re: trictionary?

2005-08-29 Thread Steven Bethard
Randy Bush wrote: > Steven Bethard wrote: >> It would probably help if you explained what the real problem is >> you're trying to solve. > > actually, that code fragment was meant to do that. it's pretty much > what i needed to do at that point, just the vari

Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-29 Thread Steven Bethard
Antoon Pardon wrote: > I think a properly implented find is better than an index. See the current thread in python-dev[1], which proposes a new method, str.partition(). I believe that Raymond Hettinger has shown that almost all uses of str.find() can be more clearly be represented with his pro

Re: regular expression unicode character class trouble

2005-09-04 Thread Steven Bethard
Diez B. Roggisch wrote: > Hi, > > I need in a unicode-environment the character-class > > set("\w") - set("[0-9]") > > or aplha w/o num. Any ideas how to create that? I'd use something like r"[^_\d\W]", that is, all things that are neither underscores, digits or non-alphas. In action: py> re

Re: __dict__ of object, Was: Regular Expression IGNORECASE different for findall and split?

2005-09-06 Thread Steven Bethard
Chris wrote: > but more of a basic question following, I was doing the following before: > > method = 'split' # came from somewhere else of course > result = re.__dict__[method].(REGEX, TXT) > > precompiling the regex > > r = compile(REGEX) > > does give an regex object which has th

Re: PEP-able? Expressional conditions

2005-09-07 Thread Steven Bethard
Kay Schluehr wrote: > Terry Reedy wrote: >> *If* bool(result_expression_i) == True for all i, (except maybe last >> default expression), which is true for some actual use cases, then the >> following expression evaluates to the result corresponding to the first >> 'true' condition (if there is one

Re: Inconsistent reaction to extend

2005-09-09 Thread Steven D'Aprano
0,000 large objects, plus the extra one. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: encryption with python

2005-09-09 Thread Steven D'Aprano
. Security by obscurity is very little security at all. If there is any motive at all to reverse-engineer the algorithm, people will reverse engineer the algorithm. Keeping a weak algorithm secret does not make it strong. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: encryption with python

2005-09-09 Thread Steven D'Aprano
the global variables in a database, otherwise each time you reload the Python script you start generating the same IDs over and over again. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

[pyparsing] make sure entire string was parsed

2005-09-10 Thread Steven Bethard
How do I make sure that my entire string was parsed when I call a pyparsing element's parseString method? Here's a dramatically simplified version of my problem: py> import pyparsing as pp py> match = pp.Word(pp.nums) py> def parse_num(s, loc, toks): ... n, = toks ... return int(n) + 10

Re: make sure entire string was parsed

2005-09-11 Thread Steven Bethard
Paul McGuire wrote: > Thanks for giving pyparsing a try! To see whether your input text > consumes the whole string, add a StringEnd() element to the end of your > BNF. Then if there is more text after the parsed text, parseString > will throw a ParseException. Thanks, that's exactly what I was

Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Steven D'Aprano
fore hand to find the exact cut-off, and expect that cut-off to vary according to the Python implementation and version. But a rough rule of thumb is, if you expect your code to fail more often than succeed, then test first, otherwise catch an exception. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: read from label

2005-09-12 Thread Steven D'Aprano
d like to give a little more detail about your problem. What sort of label? I assume you are using a GUI toolkit -- which one? You might also like to read this: http://www.catb.org/~esr/faqs/smart-questions.html -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Expected Value

2005-09-12 Thread Steven D'Aprano
might also find it useful to read this: http://www.catb.org/~esr/faqs/smart-questions.html -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: encryption with python

2005-09-12 Thread Steven D'Aprano
point is that *something has to be kept secret* for encryption security to work." Absolutely correct. But now think of the difference between having keys to your door locks, compared to merely keeping the principle of the door handle secret. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: make sure entire string was parsed

2005-09-12 Thread Steven Bethard
Paul McGuire wrote: >>>I have to differentiate between: >>> (NP -x-y) >>>and: >>> (NP-x -y) >>>I'm doing this now using Combine. Does that seem right? > > If your word char set is just alphanums+"-", then this will work > without doing anything unnatural with leaveWhitespace: > > from pyparsin

<    42   43   44   45   46   47   48   49   50   51   >