Re: It's ...

2009-06-25 Thread Kirk Strauser
o need to seek to the beginning, and files are closed when they are garbage collected (although I can't make myself not close output files after years of doing so), and map() is largely deprecated in favor of list comprehensions and generator functions. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: tricky nested list unpacking problem

2008-12-15 Thread Kirk Strauser
> [1, 2, 3, 5, 6, 10, 11, 7, 9, 1, 2, 3, 4, 5] >>>> '-'.join(str(num) for num in flattened) > '1-2-3-5-6-10-11-7-9-1-2-3-4-5' He doesn't want to flatten them directly. He's using [1,2,3] sort of like a regular expression, so that 1,[2,3],4 means "1,2,4

Re: tricky nested list unpacking problem

2008-12-15 Thread Kirk Strauser
use it to call unpack([1,2,3,5,[7,8,9]]) and unpack([1,2,3,6,[7,8,9]]), compile the results, and return them. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: (Very Newbie) Problems defining a variable

2008-12-12 Thread Kirk Strauser
> consider reversing the order Actually, I just wanted to point out a simplified version of the exact same algorithm. Given enough RAM and if the speed was indeed critical, you could turn that into a tuple of interest rates and jump straight to rate[balance] in O(1). -- Kirk Straus

Re: (Very Newbie) Problems defining a variable

2008-12-12 Thread Kirk Strauser
> return 0.0 How 'bout: def get_rate(balance): for threshold, rate in ((10, .0173), (5, .0149), (25000, .0124), (1, .0085), (0, .006)): if balance

Re: Removing None objects from a sequence

2008-12-12 Thread Kirk Strauser
erence exactly? "foo is not None" is actually surprising to me, since "not None" is True. "0 is True" is False, but "0 is not None" is True. Why is that? -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question: if var1 == var2:

2008-12-12 Thread Kirk Strauser
peol method because I seem to end up writing the inline version of "chomp" every time I iterate across a file. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question: if var1 == var2:

2008-12-11 Thread Kirk Strauser
At 2008-12-11T19:49:23Z, Steve Holden writes: > ... and it's so hard to write > > item = item[:-1] It's easy - and broken. Bad things happen if you're using something other than '\n' for EOL. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question: if var1 == var2:

2008-12-11 Thread Kirk Strauser
'.rstrip('\r\n') > ' ab c ' I didn't say it couldn't be done. I just like the Perl version better. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Do more imported objects affect performance

2008-12-11 Thread Kirk Strauser
tire module but want to call a function that many times, you can do something like: import timeit Timer = timeit.Timer for _ in xrange(100): Timer -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question: if var1 == var2:

2008-12-11 Thread Kirk Strauser
worry about losing leading or trailing spaces if those are important to you. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Its Libraries--Who's on First?

2008-11-18 Thread Kirk Strauser
At 2008-11-17T11:44:00Z, "W. eWatson" <[EMAIL PROTECTED]> writes: > See the post by Chris R. In general, it is incumbent on the asker to provide additional information as needed, rather than being the job of the would-be answerer to go searching for it. -- Ki

Re: Weird behavior with lexical scope

2008-11-06 Thread Kirk Strauser
At 2008-11-06T16:57:39Z, mrstevegross <[EMAIL PROTECTED]> writes: > class Outer: > class Inner: > def __init__(self): > pass > def __init__ (self): > a = Inner() > Outer() Try instead: class Outer: def __init__(self): a = self.Inner()

Re: Printing with interspersed element

2008-11-06 Thread Kirk Strauser
e [or screen] as > you go through the original string. Right? How about: def alternator(lst, sep): for index, item in enumerate(lst): if index: yield sep yield item for item in alternator(list_of_objects, 10): print item, -- Kirk Strauser The Day Compani

Re: Python/Numeric users be aware!

2008-10-29 Thread Kirk Strauser
At 2008-10-29T17:53:43Z, Benyang <[EMAIL PROTECTED]> writes: > It is totally screwed up on 64-bit linux machines: > [1 1 1 1 1 1 1 1 1 1] And on 64-bit FreeBSD machines. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Python barcode decoding

2008-10-28 Thread Kirk Strauser
erated, or scanned in from other material? If they're nice and crisp, I wrote a simple and pretty quick decoder at http://pypi.python.org/pypi/Daycos/1.0 . Look in the Daycos.Imageproc.Barcode module. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about scope

2008-10-28 Thread Kirk Strauser
alize initialize.initialize() def main(): if myGlobals.remote_device_enabled: process_device() -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: RegExp: "wontmatch"-function

2008-10-13 Thread Kirk Strauser
At 2008-10-13T16:40:07Z, [EMAIL PROTECTED] writes: def nomatch(value): return not(value == '' or pattern.match(value)) -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggestion for the PythonDevelopment for next version

2008-10-13 Thread Kirk Strauser
uct to overwrite it? What if I never use enumerate as it is and don't want to pay for the extra overhead of modify every object I'll ever get from an iterator? Thanks, but no. One of the things I love about Python is its lack of magic. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Append a new value to dict

2008-10-13 Thread Kirk Strauser
= 'dict' because it seems to more clearly indicate what I'm doing, and has fewer opportunities for types. Still, there is a performance penalty. Running "my way" 10,000,000 times took 8.7s, and "your way" only took 4.7s. If you're doing this in an i

Re: More regex help

2008-09-24 Thread Kirk Strauser
27;/foo') 'http://www.example.com/foo' >>> urllib.basejoin('http://www.example.com/path/to/deep/page', 'http://slashdot.org/foo') 'http://slashdot.org/foo' -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Suggestions for creating a PDF table

2008-07-28 Thread Kirk Strauser
d *almost* perfect, except that it doesn't support colspans. As I hope I demonstrated in the example, most of our reports depend on that ability. So, again, any thoughts on a PDF generator that can generate tables with the same kind of flexibility as HTML? -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Re: How do web templates separate content and logic?

2008-07-01 Thread Kirk Strauser
the function and all of the HTML print statements to the bottom. And then you realize you've written your very own page template, and that it's ugly, and that you should've used something different from the very beginning. That's why you don't embed HTML in Python, at lea

Django or TurboGears for a new project

2008-06-27 Thread Kirk Strauser
s any to find subject matter experts. Thanks, -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: newb question on strings

2008-06-27 Thread Kirk Strauser
ut of curiosity, what kind of processing? The only time I've really had to mess with escaping quotes involved SQL. There is *no* reason why you'd ever directly generate SQL strings yourself today unless you're writing a database connector. -- Kirk Strauser The Day Companies --

Re: question relateding to parsing dbf files.

2008-06-18 Thread Kirk Strauser
http://honeypot.net/project/xbasetopg . If that's too complicated, I've written a replacement in straight C but I haven't published it yet. I use these programs to sync our legacy FoxPro database to our new PostgreSQL servers on an hourly basis. Syncing 4GB of data ta

Re: dict order

2008-06-18 Thread Kirk Strauser
ict_two that's not in dict_one. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern Matching Over Python Lists

2008-06-17 Thread Kirk Strauser
item is a list: compare(item, function) def check(list): if list starts with [1, 2] and length of the list > 2: return True else: return False -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Good cross-host IPC?

2008-06-16 Thread Kirk Strauser
of the same problem space, but not all of our code is easily bent to its will. Is there another, more common way of doing this stuff? Popularity isn't the most important thing in the world, but I like the warm fuzzies of knowing that thousands of others are testing and using the same project as we are. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: accumulator generators

2008-05-30 Thread Kirk Strauser
them. So your bar is taking s, adding i to it, then assigning the value back to the local variable named s. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling instance methods from a decorator

2008-05-30 Thread Kirk Strauser
At 2008-05-30T17:40:17Z, "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > Of course you can get the self - just use the first paramter, because it > *is* self. Self is just a parameter - nothing special. If I blame it on being a long week, can I keep my geek card? --

Calling instance methods from a decorator

2008-05-30 Thread Kirk Strauser
;__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] There's no nice im_self to bounce off of or anything. I seem to be going about this all wrong. What's a good approach to get the desired effect? -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Subclassing list the right way?

2008-04-25 Thread Kirk Strauser
;>> class Foo(list): ... def __getitem__(self, index): ... return 5 ... >>> a = Foo([1, 2, 3, 4, 5]) >>> print a [1, 2, 3, 4, 5] >>> print a[2:4] [3, 4] >>> print a[3] 5 I first expected that to instead behave like: >>> print a [5, 5, 5, 5, 5

Re: Auto-parallelizing with decorators?

2007-07-06 Thread Kirk Strauser
In article <[EMAIL PROTECTED]>, Kirk Strauser <[EMAIL PROTECTED]> wrote: > I was thinking about how a lot of Lisp proponents claim that Lisp is > inherently parallelizable because its functions don't have (or are not > supposed to have) side effects, and therefore th

Re: Auto-parallelizing with decorators?

2007-07-06 Thread Kirk Strauser
f Windows has os.fork(), having never looked for it). I know something like this wouldn't be the easiest thing to implement, but honestly, having such beautiful constructs as map() and list comprehensions available is just begging for an application like this. -- Kirk Strauser -- http://mail.python.o

Auto-parallelizing with decorators?

2007-07-06 Thread Kirk Strauser
ts. However, if you take care to make your functions loosely coupled and not dependent on execution order, you could get a nice speedup every single time you give Python permission to schedule your repeated function calls. -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Recommended validating XML parser?

2007-05-07 Thread Kirk Strauser
3000 """, dtd=file('/etc/weightfile.dtd')) >>> print foo.weight 3000 ...or some variant on that theme. -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the name of a class

2006-08-01 Thread Kirk Strauser
Bruno Desthuilliers wrote: > Kirk Strauser wrote: >>>>> class foo(object): >>>>> pass >> >> how can I find its name, such as: >> >>>>> b = foo > I suppose you mean b = foo() ? Actually, I meant 'b = foo' in t

Re: Finding the name of a class

2006-08-01 Thread Kirk Strauser
;> print StateProcessor.__class__.__name__ type I'm looking for something that would print 'StateProcessor' but am not having much luck. -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Finding the name of a class

2006-08-01 Thread Kirk Strauser
ed method belongs to. This seems like it should be easy, but I think I've been staring at the problem too long. -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Re: Python article in Free Software Magazine

2006-01-04 Thread Kirk Strauser
Michele Simionato wrote: > when I think Zope is the less Pythonic application I have ever seen;) You do? Why so? I'm not arguing, but that's different than my experience with it and I'm curious about how you reached that conclusion. -- Kirk Strauser -- http://mail.python.or

Re: Python article in Free Software Magazine

2006-01-04 Thread Kirk Strauser
> Makes for a nice figure, too, which Free Software Magazine needs more of. ? -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Re: Python article in Free Software Magazine

2006-01-01 Thread Kirk Strauser
say to write for an audience with technical background. That article was meant for you, not your boss. :-) -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Python article in Free Software Magazine

2005-12-31 Thread Kirk Strauser
lling mechanism as pass-by-reference, because that's close enough for newcomers to get the gist of it. Anyway, the article's available under an open license. If you like it, feel free to pass it around. Enjoy! -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list

Pickling and inheritance are making me hurt

2005-02-04 Thread Kirk Strauser
ems like the problem is that _saveresults is only looking inside the same namespace as Search (where it's originally defined), even if it's actually been inherited by another class in a different module. Is there a way around this? -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list