Re: I'm a python addict !

2009-01-26 Thread J. Cliff Dyer
On Mon, 2009-01-26 at 09:52 -0800, Paul McGuire wrote: > On Jan 26, 10:54 am, "J. Cliff Dyer" wrote: > > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > > > Want to change the type/behavior of an object from class A to class > > > B? H

Re: I'm a python addict !

2009-01-26 Thread J. Cliff Dyer
On Mon, 2009-01-26 at 12:37 -0800, Paul McGuire wrote: > On Jan 26, 2:06 pm, "J. Cliff Dyer" wrote: > > > > Thanks. That makes sense. But your example creates a new instance of > > the new class each time, rather than changing the class of a persistent > >

Re: is None vs. == None

2009-01-27 Thread J. Cliff Dyer
On Fri, 2009-01-23 at 19:31 -0500, Benjamin Kaplan wrote: > > > On Fri, Jan 23, 2009 at 7:28 PM, Gary Herron > wrote: > Steven D'Aprano wrote: > > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > > > >> Hi -- Some time ago I ran across a co

Re: v = json.loads("{'test':'test'}")

2009-01-27 Thread J. Cliff Dyer
r which quote character is being used, and require those characters to be escaped, and not the other (but then does "te \'st" render as r"te'st" or r"te\'st"?) and only close the string when the appropriate quote is found. Not an impossible task, but certainly more complex than the current parsing requirements for JSON. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: English-like Python

2009-02-03 Thread J. Cliff Dyer
does :)) x = Beep Does that assign the name x to the Beep object or does it assign the result of a Beep call to x? There's no virtue in making ridiculously simple things even simpler if it makes the interesting things impossible. def tone_sequence(sound): sequence = DialTone.follo

Re: English-like Python

2009-02-03 Thread J. Cliff Dyer
On Tue, 2009-02-03 at 08:33 -0700, Joe Strout wrote: > J. Cliff Dyer wrote: > > > But what if your language allows functions to be used as first class > > objects? (Mine does :)) > > > > x = Beep > > > > Does that assign the name x to the Beep ob

Re: RedHat 4

2009-02-16 Thread J. Cliff Dyer
nary with 2.5 if you do install it yourself. Instead, install it to python2.5, and set the shebang line (#!) on your scripts to point to /usr/local/bin/python2.5 (or wherever you install it). Cheers, Cliff On Mon, 2009-02-16 at 07:28 -0800, Germán Gutiérrez wrote: > Hi, > > I ne

Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread J. Cliff Dyer
On Mon, 2009-02-16 at 00:28 -0500, Nicolas Dandrimont wrote: > * pyt...@bdurham.com [2009-02-16 00:17:37 -0500]: > > > I need to test strings to determine if one of a list of chars is > > in the string. A simple example would be to test strings to > > determine if they have a vowel (aeiouAEIOU)

Re: wxPython and Croatian characters

2009-02-16 Thread J. Cliff Dyer
ow wxpython works in this regard. So: s = u"Matični broj" # instead of "Matični broj" text = wx.StaticText(self, -1, s,(0,100)) # or if that doesn't work try this: #text = wx.StaticText(self, -1, s.encode('utf-8'), (0,100)) Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there something easier than ORM?

2009-02-17 Thread J. Cliff Dyer
On Tue, 2009-02-17 at 06:15 -0800, 一首诗 wrote: > Thanks for your reply. > > With sqlalchemy, an mapped must living in a session, you have no way > to disconnect it with its session. > > For example : > > #- > user = session.query(User).first() > session.expung

Re: pydoc enforcement.

2008-12-01 Thread J. Cliff Dyer
n > the Python source I would start for implementing such an idea? > > Thanks > > Ken For the reasons already stated, I think it's probably a bad idea to enforce this at compile time. I think it's a great idea to make sure that this information is present in all your code, but unless you want to see useless stubs, the correct time to enforce this is at commit time. Don't accept any improperly documented patches. Syntax is not enough to ensure what you want to ensure. The semantics have to be right as well. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Pyhon (with wxPython) on Windows' cygwin: can it be done fully ?

2008-12-01 Thread J. Cliff Dyer
On Sat, 2008-11-29 at 13:31 -0800, Lie wrote: > pdb and logging is too much for beginners, which most likely does not > yet understand the workings of the debugger and logger (and pdb's many > quirks). Don't forget that we're all beginners once. Python's learning > curve shouldn't raise with time,

Re: pydoc enforcement.

2008-12-02 Thread J. Cliff Dyer
as just a thought. > > Ken > > > > On Tue, Dec 2, 2008 at 3:03 AM, J. Cliff Dyer <[EMAIL PROTECTED]> > wrote: > > > On Sun, 2008-11-30 at 16:27 -0800, [EMAIL PROTECTED] > wrote: > > I've been thinking abo

Re: "as" keyword woes

2008-12-08 Thread J. Cliff Dyer
ith the four line conditional import are all you need for each import, and best of all, it's completely hidden from your users, until they want to migrate to python 2.6, and then all they have to do is change all references to Foo.as to point to Foo.as_type. But by observing step 1 above, th

Re: how to get a beep, OS independent ?

2008-12-08 Thread J. Cliff Dyer
file("/dev/tty0") nonstdout.write("\a") nonstdout.flush() (same permissions caveats apply) On the other hand, the OP was looking for a cross-platform solution. I don't think Windows has a /dev/tty0, but I don't work on windows, so I can't help with cross platform issues. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python now coming from Perl

2008-12-09 Thread J. Cliff Dyer
m, encode them to your favorite encoding. Better yet, use codecs.open(file, encoding='utf-16') in place of open(file), pass an encoding argument, and be done with it. When you create strings in your code, always use u'stuff' rather than 'stuff' and ur'stu\f

Re: newbie question: if var1 == var2:

2008-12-12 Thread J. Cliff Dyer
On Thu, 2008-12-11 at 13:44 -0600, Kirk Strauser wrote: > At 2008-12-11T17:24:44Z, rdmur...@bitdance.com writes: > > > >>> ' ab c \r\n'.rstrip('\r\n') > > ' ab c ' > > >>> ' ab c \n'.rstrip('\r\n') > > ' ab c ' > > >>> ' ab c '.rstrip('\r\n') > > ' ab c ' > >

Re: Removing None objects from a sequence

2008-12-15 Thread J. Cliff Dyer
*I* know about the precedence rule, but a newbie or a tired programmer > might not. He might want to reverse the truth value of argument b but > instead has just reversed the whole expression. Probably in a slightly > convoluted code like this: > > if a is not(b and c): >... > A newbie might make that mistake, but a tired programmer would be testing for equality rather than identity in that case, and if she weren't, she'd have to fix her code in the morning anyway. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

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

2008-12-16 Thread J. Cliff Dyer
if you can. > > - Hendrik > It's a good thing *its* got that heat-sink sieve- its -> it has Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: help I'm getting delimited

2008-12-18 Thread J. Cliff Dyer
On Wed, 2008-12-17 at 06:28 -0800, aka wrote: > Hi John, thanks. > You're right, I didn't past the method header because I thought it > didn't matter when the input filename is hardcoded. > The try/except isn't very helpful indeed so I commented it out. > You're right I wrongly referred to the Uni

Re: Factoring Polynomials

2008-12-18 Thread J. Cliff Dyer
On Thu, 2008-12-18 at 11:52 -0800, eric wrote: > On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: > > I am trying to write a simple application to factor polynomials. I > > wrote (simple) raw_input lines to collect the a, b, and c values from > > the user, but I dont know how to implement the qua

Re: confused about __str__ vs. __repr__

2008-12-18 Thread J. Cliff Dyer
object chooses to recursively call __str__ on its elements, it is free to do so, but since that causes ambiguity (as many people have pointed out), python has (wisely) chosen to use repr instead. If I wanted to implement a list-like class that doesn't show it's elements at all when printed, but instead shows its length, I am free to do so. For example: >>> hl = HiddenList(1,2,3) >>> hl >>> hl[1] 2 (Implementation of HiddenList left as an exercise for the reader.) If you want to implement a list-like object that returns the str of its elements, go right ahead, or implement a function that digs into containers and creates its own list representation for them. But that's not how python works by default, nor should it be, for reasons already explained by others. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: __init__.py and package help

2009-01-05 Thread J. Cliff Dyer
On Mon, 2009-01-05 at 11:49 -0800, TechieInsights wrote: > Ok I have read all of the tutorials and documents I could find. I am > running Python 2.6 on windows. The problem I am having with packages > is that they don't show up! > > Simple example of what isn't working... > Structure- > > pyte

Re: python is great

2009-01-06 Thread J. Cliff Dyer
On Tue, 2009-01-06 at 10:36 -0700, Joe Strout wrote: > I've actually been rather frustrated by Python lately. OFF TOPIC!!! Please try to stay within the subject presented by the subject header. The subject in question is "python is great," not "python is frustrating." Speaking of which, python

Re: subclassing 'list'

2009-01-06 Thread J. Cliff Dyer
On Tue, 2009-01-06 at 12:34 -0800, 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

Creating new instances of subclasses.

2009-01-07 Thread J. Cliff Dyer
eld(Field): def __new__(cls, a): return object.__new__(cls, a) Is there a cleaner way to do this? The main problem is that Field.__new__ gets in the way of properly constructing the subclasses once I've used it to select the proper subclass in the first place. Cheers, Cliff -- Oook, J. Cliff Dyer Carolina Digital Library and Archives UNC Chapel Hill -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating new instances of subclasses.

2009-01-09 Thread J. Cliff Dyer
Thanks for the solutions everyone! I'm not sure which I'll end up using, but I think I've got a better grasp of the problem now. Cool stuff. Cheers, Cliff On Thu, 2009-01-08 at 06:52 -0800, Paul McGuire wrote: > On Jan 7, 12:00 pm, Paul McGuire wrote: > > On Jan 7,

Re: Problem with -3 switch

2009-01-09 Thread J. Cliff Dyer
On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > Aivar Annamaa wrote: > >> As was recently pointed out in a nearly identical thread, the -3 > >> switch only points out problems that the 2to3 converter tool can't > >> automatically fix. Changing print to print() on the other hand is > >> ea

Re: Error

2008-10-21 Thread J. Cliff Dyer
On Tue, 2008-10-21 at 09:34 -0400, Philip Semanchuk wrote: > On Oct 21, 2008, at 9:05 AM, Amie wrote: > > > Hi, > > > > what does is the meaning of this error: int object is unsubscriptable. > > This is the code that I have written that seems to give me that: > > > > def render_sideMenu(self, ctx

Re: Changing the middle of strings in a list--I know there is a better way.

2008-10-21 Thread J. Cliff Dyer
tring.split(substr)) location_lines = [replace_by_location(x, 'CHANGED', 15, 22) for x in lines] match_lines = [replace_by_match(x, '199', 'CHANGED') for x in lines] print location_lines print match_lines Cheers, Cliff > #My Current Code > > #

Re: using "private" parameters as static storage?

2008-11-13 Thread J. Cliff Dyer
> ... self._count += 1 > ... return " ".join("spam" for _ in xrange(self._count)) > ... > ... __call__ = spam > ... Interesting. I hadn't thought of making __call__ a synonym for an existing method. I think I like that, but I'm not quite sure. There's something that nags at me about having two ways to do the same thing, but I like giving the method a more descriptive name than __call__. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: using "private" parameters as static storage?

2008-11-13 Thread J. Cliff Dyer
._count = counter_start ... def __call__(self): ... self._count += 1 ... return ("spam " * self._count).rstrip() ... >>> foo = Foo() >>> foo() 'spam' >>> foo() 'spam spam' >>> Essentially, this has the same behavior as the other two. But it looks cleaner, and you don't have to worry about coupling separate functions, or refering to a function by name within itself (because you have self to work with). But the "object" semantics are essentially the same, and state is just as legitimately preserved on a function object as a Foo object. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Problems Writing £ (pound sterling) To MS SQL Server using pymssql

2008-11-17 Thread J. Cliff Dyer
On Mon, 2008-11-17 at 14:52 +, Darren Mansell wrote: > Hi. > > I'm relatively new to python so please be gentle :) > > I'm trying to write a £ symbol to an MS SQL server using pymsssql . This > works but when selecting the data back (e.g. using SQL management > studio) the £ symbol is repla

Re: Problems Writing £ (pound sterling) To MS SQL Server using pymssql

2008-11-17 Thread J. Cliff Dyer
lude æ. So what you are seeing is best thought of as two garbage characters, one of which happens (by coincidence only) to be the same as your original character. If you decode the bytes returned properly (as UTF-8), you will get the bytes you put in, for all characters. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: "Battleship" style game

2009-02-25 Thread J. Cliff Dyer
On Wed, 2009-02-25 at 15:54 -0500, Shawn Milochik wrote: > On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch wrote: > > > Not really. The point about properties is that you *can* make attribute > > access trigger getter or setter code. > > > > But not that you do unless there is an actual reason

Re: Mangle function name with decorator?

2009-03-18 Thread J. Cliff Dyer
ror @GET def foo(x): return "Got", x @POST def foo(x) return "Posted to", x This is definitely not functional code, but might get you in the right direction on __getattribute__. __getattr__ might also work for you. I haven't worked too much

Re: Another of those "is" issues.

2009-03-24 Thread J. Cliff Dyer
hat is by changing the __class__ attribute on c. class A(object): x = 4 def __init__(self): self.y = 5 class B(object): x = u'cow' def __init__(self): self.y = u'goat' >>> c = A() >>> c.x 4 >>> c.y 5 >>> c.__class__ = B >>> # Note that neither c nor x were changed in the last step ... c.x # Class attribute found on B now u'cow' >>> c.y # Instance attribute: already initialized from A.__init__ 5 >>> c.__init__() # Reinitialize c, now using B.__init__ >>> c.y # Re-initialized instance attribute u'goat' Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Mangle function name with decorator?

2009-03-25 Thread J. Cliff Dyer
On Wed, 2009-03-18 at 08:18 -0700, Adam wrote: > On Mar 18, 10:33 am, "J. Cliff Dyer" wrote: > > You might be interested in redefining __getattribute__(self, attr) on > > your class. This could operate in conjunction with the hash tables > > (dictionaries)

Re: Introducing Python to others

2009-03-26 Thread J. Cliff Dyer
gt; from StringIO import StringIO to >>> from cStringIO import StringIO 3) Functions as first-class variables (which could connect to a discussion of decorators or of dictionaries as dispatch tables). 4) List comprehensions 5) Generators using yield 6) Also very handy is the interactive inte

Re: Eval Problem

2009-04-07 Thread J. Cliff Dyer
ode26.html Something like the following might work: print eval(line, {'tableTop': tableTop}) Cheers, Cliff On Tue, 2009-04-07 at 08:38 -0400, Victor Subervi wrote: > > I have excluded the code where I call the separate text files for > printing normal text. They work. It's m

Re: extract Infobox contents

2009-04-08 Thread J. Cliff Dyer
On Wed, 2009-04-08 at 01:57 +0100, Rhodri James wrote: > On Tue, 07 Apr 2009 12:46:18 +0100, J. Clifford Dyer > wrote: > > > On Mon, 2009-04-06 at 23:41 +0100, Rhodri James wrote: > >> On Mon, 06 Apr 2009 23:12:14 +0100, Anish Chapagain > >> wrote: > >> > >> > Hi, > >> > I was trying to extrac

Re: Lambda alternative?

2009-04-17 Thread J. Cliff Dyer
"copyright", "credits" or "license" for more information. >>> import cPickle as p >>> class Foo(object): ... a = lambda self, x: x+1 >>> foo.a(1) 2 >>> type(foo.a) >>> p.dumps(foo) 'ccopy_reg\n_reconstructor\np1\n(c__main__\nFoo\np2\nc__builtin__ \nobject\np3\nNtRp4\n.' Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] large db question about no joins

2009-04-17 Thread J. Cliff Dyer
On Thu, 2009-04-16 at 14:11 -0700, John Fabiani wrote: > Daniel Fetchinson wrote: > > > Hi folks, I've come across many times the claim that 'joins are bad' > > for large databases because they don't scale > > IMO that's bull... OK. That makes four legs so far > -- > http://mail.python.org

Re: Restart generator when it is exhausted.

2009-04-28 Thread J. Cliff Dyer
ble, when the loop calls iterable.__iter__(), it gets a fresh iterator, so it can loop over the file again. The important thing is that when you call x.__iter__() (which you do when entering a loop), you get a fresh iterator that won't just call StopIteration right away. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: dict is really slow for big truck

2009-04-29 Thread J. Cliff Dyer
native, but lo and behold, they are the same, at least in the cases I was trying to account for. ' a b c '.split() == ' a b c '.strip().split() == 'a b c'.split() Thanks for pointing this out. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: for with decimal values?

2009-05-05 Thread J. Cliff Dyer
back up is an exercise for the reader. def general_xrange(start, stop, step=1): target = stop * step if start * step > target: raise ValueError i = start while i * step < target: yield i i += step Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: list comprehension question

2009-05-05 Thread J. Cliff Dyer
hidden breakage. But if you have one of those in your data structure, why are you trying to flatten it anyway? Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension question

2009-05-05 Thread J. Cliff Dyer
On Tue, 2009-05-05 at 12:15 -0400, J Kenneth King wrote: > Emile van Sebille writes: > > > On 5/1/2009 7:31 AM J Kenneth King said... > >> Chris Rebert writes: > >>> b = [] > >>> for pair in a: > >>> for item in pair: > >>> b.append(item) > >> > >> This is much more clear than a nest

Re: unicode bit me

2009-05-08 Thread J. Cliff Dyer
On Fri, 2009-05-08 at 07:53 -0700, anuraguni...@yahoo.com wrote: > #how can I print a list of object which may return unicode > representation? > # -*- coding: utf-8 -*- > > class A(object): > > def __unicode__(self): > return u"©au" > > __str__ = __repr__ = __unicode__ > Your

Re: php to python code converter

2009-05-08 Thread J. Cliff Dyer
On Fri, 2009-05-08 at 17:19 +0200, Pascal Chambon wrote: > PS : Am I the only one having most of answers rejected by the > antispam > system of python-list ? That's humiliating :p > I've had several messages not make it through. :( -- http://mail.python.org/mailman/listinfo/python-list

Re: How to see the code definiton in the shell ?

2009-05-13 Thread J. Cliff Dyer
On Wed, 2009-05-13 at 09:40 -0700, Mohan Parthasarathy wrote: > Hi, > > I am new to Python. I tried searching this but could not find an > answer. In the interactive shell, I write a new function and I want to > be able to see all the code that I wrote at a later time. Just typing > the function n

Re: Sorting a dictionary

2009-05-15 Thread J. Cliff Dyer
order. But they are processed in the order they appeared in the list. If you want to process the elements of the list in alphabetical order, you have to sort the list itself: >>> for x in sorted(['hat', 'socks', 'shirt', 'pants']): ... print x hat pants shirt socks Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: reseting an iterator

2009-05-22 Thread J. Cliff Dyer
> y = Y() >>> for c in y: ... print c ... 1 2 3 >>> for c in y: ... if c < 3: ... print c ... 1 2 >>> for c in y: ... print c ... 1 2 3 Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: While Statement

2009-05-22 Thread J. Cliff Dyer
when using python 2.6 with old-style division. Probably because python doesn't have to check the types of its arguments before deciding to do integer division. >>> a = timeit.Timer("(200 * 100.)/5") >>> b = timeit.Timer("(200 * 100)/5") >>> c = timeit.Timer("(200 * 100)//5") >>> d = timeit.Timer("(200 * 100.0)//5") >>> for each in a, b, c, d: ... each.timeit() ... 2.3681092262268066 2.417525053024292 0.81031703948974609 0.81548619270324707 Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about locals()

2009-05-22 Thread J. Cliff Dyer
alue print serialc_bin.sum() Any one of these seems like a better idea to me than trying to pollute your local namespace with an unknown number of variables. You have a collection of objects. It makes sense to store them in one of python's collection types, or create an object of your own to store them. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: reseting an iterator

2009-05-22 Thread J. Cliff Dyer
On Fri, 2009-05-22 at 10:54 -0700, Jan wrote: > On May 22, 9:46 am, "J. Cliff Dyer" wrote: > > > You don't need a reset method. There is no hard and fast rule that > > __iter__ must return the object itself. It just needs to return an > > iterator.

Re: Python and Flaming Thunder

2008-05-14 Thread J. Cliff Dyer
n, I usually don't agree much with both what you say and how you > say it, but I must admit that this one is, well... just brillant !-) > > (IOW: rofl, keyboard, and +1 QOTW) > -- > http://mail.python.org/mailman/listinfo/python-list > Agreed. Best. Synonym. EVAR.

Re: class problem, NoneType obj has no attribute

2008-05-16 Thread J. Cliff Dyer
self.movies = movies > return self > > > ? No. __init__ should not return anything (rather, it should return None, but it'll do that on its own without you telling it to return anything). The problem is that you are trying to create an object with __init__, but that is not what it does. It *initializes* objects that already exist. when you call a class, it creates a new instance using __new__(), and then initializes it using __init__(). So if you were really inclined to muck around. You could do something like cust1 = Customer.__new__(Customer) cust1.__init__('12', ['1','435', '2332']) But that would just be silly. What you really want is this: cust1 = Customer('12', ['1','435', '2332']) which does the same thing. Don't explicitly call under-under variables unless you really have to. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: class problem, NoneType obj has no attribute

2008-05-16 Thread J. Cliff Dyer
On Fri, 2008-05-16 at 06:04 -0700, globalrev wrote: > On 16 Maj, 13:54, Peter Otten <[EMAIL PROTECTED]> wrote: > > Christian Heimes wrote: > > > globalrev schrieb: > > >> cust1 = customer.__init__('12',['1','435','2332']) > > > > > cust1 = customer('12',['1','435','2332']) > > > > ... and before th

Re: Help with character encodings

2008-05-20 Thread J. Cliff Dyer
27;t using str.replace. You were using unicode.replace. Slight difference, but important.) If you do the replace on a plain string, it doesn't have to convert anything, so you don't get a UnicodeDecodeError. >>> x = x.encode('latin1') >>> x '\xad' >>> # Note the lack of a u before the ' above. >>> x.replace('\xad','-') '-' >>> Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: import X vs from x import *

2008-05-22 Thread J. Cliff Dyer
re are occasional packages where it is common practice to import *. Tkinter might be one of those. I don't have any experience with it. But don't make a habit of it. :) Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is math.pi slightly wrong?

2008-05-23 Thread J. Cliff Dyer
On Thu, 2008-05-22 at 15:06 -0400, Dan Upton wrote: > Who wants to verify that that's correct to that many digits? ;) Verified. I checked it against the million digits on piday.org, by putting each into a string, stripping out spaces and newlines, and doing: >>> piday[:len(clpy)] == clpy False >

Re: Struct usages in Python

2008-05-28 Thread J. Cliff Dyer
On Wed, 2008-05-28 at 09:31 -0400, Alok Kumar wrote: > I am getting following error when tried as you suggested. > > self.event = [] #Create an empty list, bind to the name "event" under > the "self" namespace >self.event.append(Event()) #Create an event object and > append to the e

[OT] Re: FW: php vs python

2008-05-29 Thread J. Cliff Dyer
sleet slush And in some contexts (http://www.abc-of-snowboarding.com/snowtypes.asp) crud crust rime graupel hail That's 14. Inuits are unimaginative punks. ;) Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: help

2008-05-30 Thread J. Cliff Dyer
Take a look at django's built in pagination features: http://www.djangoproject.com/documentation/generic_views/ http://www.djangoproject.com/documentation/pagination/ Also, take a look at the django specific mailing list. [EMAIL PROTECTED] Cheers, Cliff On Fri, 2008-05-30 at 12:59 +000

Re: re.search much slower then grep on some regular expressions

2008-07-10 Thread J. Cliff Dyer
1 secs > test('file-2.txt') took 398.349623132 secs Sounds like a good strategy would be to find the smallest chunk of the file that matches can't cross, and iterate your search on units of those chunks. For example, if none of your regexes cross line boundaries, search each line of the file individually. That may help turn around the speed degradation you're seeing. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread J. Cliff Dyer
atements in question are: if name is not None: and if name: The difference? name='' if name is not None: print "name is not None." if name: print "name is." Give it a whirl. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: manipulating hex values

2008-04-01 Thread J. Cliff Dyer
adecimal" % a '1e is hexadecimal' py>>> "0x%x is hex prepended with 0x" % a '0x1e is hex prepended with 0x' >>> "0%o is octal prepended with 0" % a '036 is octal prepended with 0' You are making your life more complicated than you need to. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: String Literal to Blob

2008-04-15 Thread J. Cliff Dyer
It is published. On comp.lang.python. Google groups has it, so google (search) will find it. Cheers, Cliff On Tue, 2008-04-15 at 17:04 +0200, Victor Subervi wrote: > Gabriel; > > That's really nice code you wrote. I will rewrite my app accordingly, > after I catch a breathe

Re: Finally had to plonk google gorups.

2008-04-16 Thread J. Cliff Dyer
Linux (or any Open Source > > product), they shouldn't be used either (since I'm not paying for > > them). > > > I'm not saying people shouldn't use Google Groups. I'm saying that > Google can "justify" providing customer "supp

Re: Finally had to plonk google gorups.

2008-04-16 Thread J. Cliff Dyer
new messages to different folders by matching various criteria. In Evolution this is as easy as right clicking on a message from the list in your inbox, select "Create Rule From Message > Filter on Mailing List", and then choose a folder to redirect to. Reading by thread instead of by

Re: More Fun With MySQL and Images

2008-04-17 Thread J. Cliff Dyer
to open newfile in any piece of software of your choosing. It's no longer a well-formed jpeg, so it won't work. That's exactly what you're asking the browser to do. I guess this isn't really python related, so my apologies for that. Cheers, Cliff -- Oook, J. Cliff Dyer Carolina Digital Library and Archives UNC Chapel Hill -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't do a multiline assignment!

2008-04-17 Thread J. Cliff Dyer
; > ... > > > Thank you, you saved me from making that point. It doesn't even seem > like there's a need for each header to reference the same value (though > in this case they will, precisely because there is only one None object). > > regards > Steve Another possibility is to assign to a dict using a loop, if typing None over and over again is so onerous. options = ['cache_control', 'connection', 'date', 'pragma'] params = {} for option in options: params[option] = None And of course you could substitute your choice of appropriate __dict__ for params, if you want to access the options as free-standing objects. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Python-list Digest, Vol 55, Issue 296

2008-04-18 Thread J. Cliff Dyer
will always work on Python 2.5. If you're worried about wild code, bundle it with its own interpreter when you distribute it. It'll survive. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Another MySQL Images Question

2008-04-18 Thread J. Cliff Dyer
the "%s"es that you don't need, because you already parameterized that query. Your dbapi interface will provide appropriate quoting for whatever type of data you pass it. Cheers, Cliff On Fri, 2008-04-18 at 10:13 -0500, Victor Subervi wrote: > Hi; > If I grab an image

Re: py3k concerns. An example

2008-04-18 Thread J. Cliff Dyer
ro.py/go?FREETEXT=crack+open > I was with you on this issue right up until that last paragraph. You want it, but only if its free. That's ridiculous. Every thing a computer does requires processor cycles. Do you really mean to tell me that string interpolation has been a major bottleneck

Re: Colors for Rows

2008-04-29 Thread J. Cliff Dyer
with > this after defining bg as a list of the four colours: > > print '' % bg[z % 4], d > > I tried that just for fun. It gave a bg of ´f´. Again, how are you > incorporating d? If you add that print line to end of your original code, then you'll get the z%4-th element of bg, which would be one character, because bg is a string, but if you "define bg as a list of the four colours" first, as instructed, you'll get sensible results: bg = ['#ff', '#b2b2b2', '#33FF66', '#00'] for z in (0,1,2,3,4,5,6,7,8,9): print (' TIA, > Victor Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Colors for Rows

2008-04-29 Thread J. Cliff Dyer
On Tue, 2008-04-29 at 15:39 -0400, D'Arcy J.M. Cain wrote: > On Tue, 29 Apr 2008 15:03:23 -0400 > "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote: > > Or, if you aren't sure how many colors you'll be using, try the more > > robust: > > &g

Re: Custom Classes?

2008-04-30 Thread J. Cliff Dyer
x27;re trying to catch, it's better to leave off the try/except block, *especially* during development. Stack traces are full of good information. Second, you never initialize w, which causes the following problem. $ python Python 2.3.4 (#1, Nov 20 2007, 15:18:15) [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> w += 1 Traceback (most recent call last): File "", line 1, in ? NameError: name 'w' is not defined >>> Third, double-spacing your code makes it difficult to read. Take out blank lines, unless they add contextual hints which improve readability. Post working code, and I'll answer your actual question. Cheers, Cliff > -- Oook, J. Cliff Dyer Carolina Digital Library and Archives UNC Chapel Hill -- http://mail.python.org/mailman/listinfo/python-list

Re: confused about self, why not a reserved word?

2008-05-05 Thread J. Cliff Dyer
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... def Hello(sel): ... print "hi" ... >>> f = Foo() >>> f.Hel

Re: pygame music, cant read mp3?

2008-05-05 Thread J. Cliff Dyer
'\\uabcd' >>> u'\uabcd' u'\uabcd' >>> u'\ufoo' UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 0-4: end of string in escape sequence >>> '\xfoo' ValueError: invalid \x escape >>

Re: generator functions in another language

2008-05-05 Thread J. Cliff Dyer
On Mon, 2008-05-05 at 10:08 -0700, [EMAIL PROTECTED] wrote: > At some point, code goes "on" and "off" the processor, which knowledge > I do owe to spending money. Thus, if the group news is a localcy > (other dimension of currency), that's bounce check the house dollar. > What do [second person pl

[Fwd: Re: Am I missing something with Python not having interfaces?]

2008-05-07 Thread J. Cliff Dyer
-- Oook, J. Cliff Dyer Carolina Digital Library and Archives UNC Chapel Hill --- Begin Message --- On Wed, 2008-05-07 at 21:19 +0200, Daniel Marcel Eichler wrote: > Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll: > > > If so, then it looks like an Interface is a generi

Re: Parsing Email 'References' header.

2008-05-08 Thread J. Cliff Dyer
On Thu, 2008-05-08 at 14:53 +0200, Aspersieman wrote: > Hi > > I have a python script that parses email headers to extract information > from them. I need to get the _last_ messageid in the 'References' field > (http://cr.yp.to/immhf/thread.html) to create a threaded view of these > emails (the

Re: listen on TCP port

2008-05-08 Thread J. Cliff Dyer
On Thu, 2008-05-08 at 05:56 -0700, [EMAIL PROTECTED] wrote: > Hello, > is it possibble listening on TCP port by python and how? I am trying > chilkat but poorly :(. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > You just asked this exact same question yesterday, and got

Re: Am I missing something with Python not having interfaces?

2008-05-08 Thread J. Cliff Dyer
On Thu, 2008-05-08 at 13:25 -0400, J. Cliff Dyer wrote: > On Thu, 2008-05-08 at 19:11 +0200, Daniel Marcel Eichler wrote: > > Am Donnerstag 08 Mai 2008 13:02:52 schrieb J. Clifford Dyer: > > > > > > I didn't said that interfaces are a kind of duck-typing. In fact i

Re: Surprising difference in behavior between "import blah" and "from blah import thing"

2008-05-08 Thread J. Cliff Dyer
;The new improved thing" You rebind the name system.thing, but the object it was originally bound to is unaffected. Strings are immutable, so you couldn't change that object if you tried. thing is still bound to the original object. Another feature of this behavior is as follows: >&

Dynamic generation of images (was Re: Custom Classes?)

2008-05-09 Thread J. Cliff Dyer
On Thu, 2008-05-08 at 10:33 -0500, Victor Subervi wrote: > Okay, trying this again with everything working and no ValueError or > any other errors, here we go: > > Load this code. Unless you use a similar login() script, you will want > to edit your own values into the user, passwd, db and host: >

Re: observer pattern (notification chain synchronization)

2008-05-09 Thread J. Cliff Dyer
heers, Cliff On Fri, 2008-05-09 at 13:51 +, Alan Isaac wrote: > A question related to the observer pattern... > > Suppose I have a variant: there are stocks, mutual funds, and investors. Let > us say that funds are observers for multiple stocks, and investors are > observer

Re: python newbie: some surprises

2008-05-09 Thread J. Cliff Dyer
z.strip().endswith('z') and remove_first(w)) attach_list(q, r) reject(x) A colon on the correct line would help readability quite a bit. Yeah, I know I made it pretty ugly to begin with, and there are ways to improve it without the colon, but still, just because it could be removed doesn't necessarily mean it should. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: A question about python and xml

2008-05-09 Thread J. Cliff Dyer
ere are other options available, but those are straightforward to use, and well designed. Good luck with your site. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Case-insensitive string compare?

2008-09-05 Thread J. Cliff Dyer
behavior as the OP's original solution. The OP's solution retrieves the first matching value only. Mine gets one arbitrary matching value, determined by the algorithm used for constructing the search dict (not specified in my solution). What the OP actually said was that he can&#x

Re: Test if list contains another list

2008-09-09 Thread J. Cliff Dyer
to be numbers between 0 and 15, you can just do: if ''.join(map(hex, a)) in ''.join(map(hex, b)): return True Hmm... actually, with the '0x' prefix that hex() puts on numbers, I think this works for arbitrary integers. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: append on lists

2008-09-16 Thread J. Cliff Dyer
un on 8084, you can do the following import socket port = { 'www.example.com': 80, 'dev.example.com': 8084, }[socket.gethostname()] It's a handy idiom. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: improving a huge double-for cycle

2008-09-18 Thread J. Cliff Dyer
On Thu, 2008-09-18 at 07:57 -0500, Tim Chase wrote: > > Code: Select all > > for i in range(len(IN)): #scan all elements of the list IN > > for j in range(len(IN)): > > if i <> j: > > if IN[i].coordinates[0] == IN[j].coordinates[0]: > >if IN[i].coordinates[1]

Re: Python style: exceptions vs. sys.exit()

2008-10-03 Thread J. Cliff Dyer
On Fri, 2008-10-03 at 09:15 -0500, Grant Edwards wrote: > On 2008-10-03, greg <[EMAIL PROTECTED]> wrote: > > Lawrence D'Oliveiro wrote: > >> In message <[EMAIL PROTECTED]>, Steven D'Aprano > >> wrote: > >> > >> > (2) Even when the source is available, it is sometimes a legal trap to > >> > read i

Re: Another Screwy Problem

2010-01-09 Thread J. Cliff Dyer
practice. You leave yourself vulnerable not only to attacks, but to simple absent-mindedness as well. Using parameters in your execute statement will handle all necessary quoting for you, which eliminates the possibility of a bad query sneaking in. For more information, as I mentioned, look up SQL injection. Also, read this: http://xkcd.com/327/ Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: New to Python

2010-02-10 Thread J. Cliff Dyer
On Wed, 2010-02-10 at 13:18 -0800, Stephen Hansen wrote: > > The original code: > > > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > > ... will only work on Python 2.x, as print is being used

Re: Unit testing errors (testing the platform module)

2010-04-13 Thread J. Cliff Dyer
The problem is that the class of platform.__builtins__ is a dict, not a string containing the text "". Try replacing line 16 with this: self.assertEqual(type(platform.__builtins__), dict) Cheers, Cliff On Tue, 2010-04-13 at 15:01 +0100, John Maclean wrote: > I normally u

Re: Unit testing errors (testing the platform module)

2010-04-14 Thread J. Cliff Dyer
nvalid syntax Admittedly, this is a trivial benefit. If you're using a literal, you already know what type you're dealing with. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   >