Re: Introducing Python to others

2009-03-26 Thread Jervis Whitley
>> class Vector(list): >>> >>> ...   def __add__(self, other): >>> ...     return map(add, self, other) >>> ...>>> x = Vector([1,2]) I've used the complex type for a similar problem (2D Cartesian points) in the past, I saw the suggestion once on the pygame list. >>> x = complex(1,2) >

Re: Neatest way to do a case insensitive "in"?

2009-03-19 Thread Jervis Whitley
> > I agree that it's an alternative. There are a number of alternatives. > However the OP was asking for a "neater/easier" alternative. I argue > that introducing an external module/function to do the exact same thing > as a built-in type's method doesn't exactly qualify as a "neater/easier" > alt

Re: Neatest way to do a case insensitive "in"?

2009-03-19 Thread Jervis Whitley
On Fri, Mar 20, 2009 at 8:28 AM, Albert Hopkins wrote: > On Fri, 2009-03-20 at 07:25 +1100, Jervis Whitley wrote: >> > >> >    if stringA.lower() in stringB.lower(): >> >        bla bla bla >> > >> >>     from string import lower >> >

Re: Neatest way to do a case insensitive "in"?

2009-03-19 Thread Jervis Whitley
> >    if stringA.lower() in stringB.lower(): >        bla bla bla > from string import lower if lower(stringA) in lower(stringB): # was this what you were after? Cheers, Jervis -- http://mail.python.org/mailman/listinfo/python-list

Re: How to do this in Python?

2009-03-18 Thread Jervis Whitley
> What I was wondering > was whether a similar construct was considered for a while loop or even an > if clause, because then the above could be written like this: > >  if open(filename, 'rb') as f: >      while f.read(1000) as buf: >          # do something with 'buf' > see here, and the associat

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

2009-02-18 Thread Jervis Whitley
> > What happens when you have hundreds of megabytes, I don't know. > > I hope I never have to test a word that is hundreds of megabytes long for a vowel :) -- http://mail.python.org/mailman/listinfo/python-list

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

2009-02-17 Thread Jervis Whitley
> > This moves the for-loop out of slow Python into fast C and should be much, > much faster for very large input. > _Should_ be faster. Here is my test on an XP system Python 2.5.4. I had similar results on python 2.7 trunk. WORD = 'g' * 100 WORD2 = 'g' * 50 + 'U' BIGWORD = 'g' * 1 + 'U'

Re: Avoiding argument checking in recursive calls

2009-02-11 Thread Jervis Whitley
> > You've merely replaced the 'test n<0' with 'not check' at the expense > of an additional parameter that has to be passed each time (and the > additional test 'n<0' for the first iteration). > -- > http://mail.python.org/mailman/listinfo/python-list > I think you have missed the point. The OP s

Re: Avoiding argument checking in recursive calls

2009-02-11 Thread Jervis Whitley
> You've merely replaced the 'test n<0' with 'not check' at the expense > of an additional parameter that has to be passed each time (and the > additional test 'n<0' for the first iteration). > -- > http://mail.python.org/mailman/listinfo/python-list > I think you have missed the point. The OP stat

Re: Avoiding argument checking in recursive calls

2009-02-10 Thread Jervis Whitley
> I've done this: > > def _fact(n): >if n = 0: return 1 >return _fact(n-1)*n > > def fact(n): >if n < 0: raise ValueError >return _fact(n) > > but that's ugly. What else can I do? > > Hello, an idea is optional keyword arguments. def fact(n, check=False): if not check: if n <

Re: Use list name as string

2009-02-04 Thread Jervis Whitley
On Thu, Feb 5, 2009 at 2:37 PM, Vincent Davis wrote: > Jervis Whitley wrote "Although you should really solve your problem by > thinking about it > from a completely different angle, maybe subclassing your datatype and > adding a 'name' > attribute ? I'

Re: Use list name as string

2009-02-04 Thread Jervis Whitley
On Thu, Feb 5, 2009 at 3:57 AM, Vincent Davis wrote: > Sorry for not being clear > I would have something like this > x = [1, 2, 3,5 ,6 ,9,234] > Then > def savedata(dataname): .. > > savedata(x) > this would save a to a file called x.csv This is my problem, getting the > name to be x.csv

Re: what IDE is the best to write python?

2009-02-02 Thread Jervis Whitley
On Mon, Feb 2, 2009 at 2:46 PM, Chris Jones wrote: > On Sun, Feb 01, 2009 at 07:26:24PM EST, Ben Finney wrote: >> a...@pythoncraft.com (Aahz) writes: >> >> > Just to register a contrary opinion: I *hate* syntax highlighting >> >> On what basis? > > Real men hate syntax highlighting. > -- > http://

Re: Comparing dates?

2009-02-02 Thread Jervis Whitley
> Most > will have functions like str[pf]time that could be used to similar > effect. In mysql this is: str_to_date( '21/02/2008', '%d/%m/%Y') and oracle: to_date( '21/02/2008', 'dd-mm-') Cheers, -- http://mail.python.org/mailman/listinfo/python-list

problem with program - debugging leading nowhere

2009-01-30 Thread Jervis Whitley
-- Forwarded message -- From: Jervis Whitley Date: Sat, Jan 31, 2009 at 10:59 AM Subject: Re: problem with program - debugging leading nowhere To: Matthew Sacks Cc: python-list@python.org > > > > error message: > Traceback (most recent call last): > F

Re: problem with program - debugging leading nowhere

2009-01-30 Thread Jervis Whitley
> > > > error message: > Traceback (most recent call last): > File "", line 1, in > IndentationError: expected an indented block (, line 39) > > code: > http://pastebin.com/f2f971f91 > Hi, It looks like you have commented out a line on line 30, you need to place something in here, as python is

Re: search speed

2009-01-30 Thread Jervis Whitley
> > > Today this works fine, it saves me a lot of manuall work, but a seach > takes around 5 min, > so my questin is is there another way of search in a file > (Today i step line for line and check) > If the files you are searching are located at some other location on a network, you may find that

Re: verilog like class w/ bitslicing & int/long classtype

2009-01-29 Thread Jervis Whitley
On Fri, Jan 30, 2009 at 9:02 AM, wrote: > I'm trying to make a script environment with datatypes (or classes) > for accessing hardware registers. At the top level, I would like the > ability to bitwise ops if bit slice brackets are used, but if no > brackets are used, I would like it to write/re

Re: list subsetting

2009-01-21 Thread Jervis Whitley
On Thu, Jan 22, 2009 at 9:09 AM, Jeff McNeil wrote: > On Jan 21, 4:53 pm, culpritNr1 wrote: > > Hello All, > > > > Say I have a list like this: > > > > a = [0 , 1, 3.14, 20, 8, 8, 3.14] > > > > Is there a simple python way to count the number of 3.14's in the list in > > one statement? > > > > I

Re: Python DateTime Manipulation

2009-01-15 Thread Jervis Whitley
On Fri, Jan 16, 2009 at 9:19 AM, Kingston wrote: > I have a user input a date and time as a string that looks like: > "200901010100" but I want to do a manipulation where I subtract 7 days > from it. > > The first thing I tried was to turn the string into a time with the > format "%Y%m%d%H%M" and

Re: optimizing large dictionaries

2009-01-15 Thread Jervis Whitley
On Fri, Jan 16, 2009 at 8:39 AM, Per Freem wrote: > hello > > i have an optimization questions about python. i am iterating through > a file and counting the number of repeated elements. the file has on > the order > of tens of millions elements... > > > for line in file: > try: >elt = MyCla

Re: Programming friction

2009-01-13 Thread Jervis Whitley
On Wed, Jan 14, 2009 at 12:29 PM, killsto wrote: > > force. So lets say I am slowing down at a rate of -2m/s^2, if I hit 1, > the next number will be -1 and I shoot off in the other direction. How > do I fix this an still have backwards movement? > -- > http://mail.python.org/mailman/listinfo/pyt

Re: Object help

2009-01-11 Thread Jervis Whitley
On Mon, Jan 12, 2009 at 9:06 AM, killsto wrote: > > I would think something like: > > def newball(): > x = last_named_ball + 1 >ball_x = ball(size, etc) # this initializes a new ball >return ball_x > > But then that would just name a ball ball_x, not ball_1 or ball_2. > > Is it possib

Re: embedding python in wxpython

2008-12-30 Thread Jervis Whitley
On Wed, Dec 31, 2008 at 7:21 AM, Stef Mientki wrote: > 5lvqbw...@sneakemail.com wrote: > >> Hi, I've looked around for a way to allow a python console from within >> a wxPython application, but have only found stuff on embedded/ >> extending python with C/C++ or wxWidgets in C++, but not wxPython.