Oh, except one problem: the csv.DictWriter lets you tell it what order
you want the columns output in. With your version, they just show up
in whatever order Python wants them.
On May 28, 2010, at 2:33 AM, Peter Otten wrote:
I think it's simpler and therefore more appropriate to use a norm
Aha, now this is the clever solution that I didn't find "outside the
box". :)
On May 28, 2010, at 2:33 AM, Peter Otten wrote:
I think it's simpler and therefore more appropriate to use a normal
csv.writer here:
import csv
import sys
data = {'a': [1, 2, 3], 'c': [7, 8, 9], 'b': [4, 5, 6]}
w
Using the csv.DictReader and csv.DictWriter lets you read and write
lists of dictionaries from files containing tabular data. I have a
system that naturally generates tabular data in the form of a
dictionary of lists: the dictionary key is the name of the column, and
then the value is a li
On Feb 17, 2010, at 4:17 PM, Sander Sweers wrote:
On 17 February 2010 22:37, David Perlman wrote:
As far as I can tell, this should always work. So wouldn't it be
nice if
there were a less convoluted way to get this??
There is pytz [1] which should provide a simpler way to m
*(t[4]-u[4]) + (t[5]-u[5])
return datetime.timedelta(seconds=osec)
As far as I can tell, this should always work. So wouldn't it be nice
if there were a less convoluted way to get this??
On Feb 17, 2010, at 3:12 PM, Kent Johnson wrote:
On Wed, Feb 17, 2010 at 3:48 PM, David Perlman
wrote:
Surel
ion already; it doesn't
require any kind of fancy calculations about global politics or
anything.
On Feb 17, 2010, at 3:12 PM, Kent Johnson wrote:
On Wed, Feb 17, 2010 at 3:48 PM, David Perlman
wrote:
Surely there is a way to simply print out the local time, date and
time zone
with
ithout subclassing tzinfo. This makes
me feel like I MUST be missing something obvious, because it shouldn't
require so much coding just to find out what the current local time
and timezone is!
On Feb 17, 2010, at 1:42 PM, William Witteman wrote:
On Wed, Feb 17, 2010 at 12:44:02PM -0600
I have been really scratching my head over this, it seems like there
*should* be a nice easy way to do what I want but I can't find it for
the life of me.
What I would like to do would be something like this:
>>> datetime.datetime.now().isoformat()
'2010-02-17T12:13:17.913260-06:00'
But wha
If I make a subclass of a built-in class, like this:
class mylist(list):
def __init__(self):
list.__init__(self)
Then it is valid for me to do this:
>>> x=mylist()
>>> x.hello=3
>>>
But I can't do this:
>>> y=list()
>>> y.hello=3
Traceback (most recent call last):
File "", line
Maybe there's a prettier way to do this, but I did it explicitly like
this because the "transpose" I needed was specific to the structure of
the game payoff matrix; it isn't a normal mathematical transpose. I
agree that it's hard to read but I'm not sure the specific needs of
this applicat
Oh my goodness, it really is that easy! I guess I assumed that was
too simple to work. Silly me. Thanks Andre!
On Oct 15, 2009, at 10:31 AM, Andre Engels wrote:
On Thu, Oct 15, 2009 at 5:14 PM, David Perlman
wrote:
I'm trying to figure out how to define a class so that its
inst
I'm trying to figure out how to define a class so that its instances
have a method that return a different object of the same class.
In particular, I'm trying to run a simple prisoner's dilemma game, and
I want to make a "game" object that has a method which returns the
"game" object with t
OK, I thought I had this one fixed but it was weirder than I thought.
I think I understand what's going on, but I wanted to check with the
experts here.
I have the following class definition, which does not subclass anything:
class oneStim:
def __init__(self, time, mods=[], dur=None, fo
Yeah, this seems to be the best answer in this situation. :)
On Sep 10, 2009, at 4:17 PM, Kent Johnson wrote:
I would skip the cleverness of trying to subclass string. You can use
str(z).rjust(20) as above, or use string formatting:
'%20s' % z
--
-dave---
Well, here's what I am really doing:
class oneStim(str):
def __init__(self, time, mods=[], dur=None, format='%1.2f'):
self.time=time
self.mods=mods
self.dur=dur
self.format=format
def __cmp__(self,other):
return cmp(self.time,other.time)
def _
I'm not sure why I'm getting an error at the end here:
>>> class dummy:
... def __init__(self,dur=0):
... self.dur=dur
...
>>> z=dummy(3)
>>> z.dur
3
>>> z=dummy(dur=3)
>>> z.dur
3
That worked fine, of course.
>>> class dummy2(str):
... def __init__(self,dur=0):
...
I have successfully used the builtin "wave" module to read an audio
file in as a string of bytes:
>>> x=wave.open('DaCWL.wav','rb')
>>> x.getparams()
(1, 2, 44100, 15440, 'NONE', 'not compressed')
>>> samp=x.readframes(15440)
>>> type(samp)
The x.getparams() indicates that there is one audio
I am thinking about writing a program which will involve, among other
things, displaying a plot of a series of numbers. The idea is that
you could click on the points and move them to change the numbers.
Reverse-plotting, I suppose. It need not be complex; the numbers
will all be zero or
As far as making something run automatically at various times, if
you're certain that you want to do it in a Mac-only way, Apple's
recommended method for timing jobs is described here:
http://developer.apple.com/macosx/launchd.html
"Getting started with launchd"
otherwise use cron or at, as Tom
Also keep in mind that if you want your code to work, your grammar
and punctuation in code has to be absolutely flawless. Writing
English well is excellent practice for writing code well; writing
English poorly is excellent practice for writing code poorly.
You get what you pay for. If you
Then maybe you could write a regex that matches every regex that does
not match itself.
ha! sorry, couldn't resist.
On Jul 23, 2007, at 11:29 AM, Bill Campbell wrote:
> On Mon, Jul 23, 2007, James Hartley wrote:
>> On 7/23/07, Shidan <[EMAIL PROTECTED]> wrote:
>>> I'm looking for a Python mod
Maybe this reference will help:
http://xahlee.org/perl-python/sort_list.html
Just the first part of the discussion there.
On Jul 9, 2007, at 9:54 AM, Sara Johnson wrote:
> Sorry to be so confusing. Just realized a dumb mistake I made. It
> doesn't need to be resorted alphabetically and numeri
I think what you want to do is start from the beginning with two
separate lists, sort each one however you want, and then either join
them with zip() or simply reference them as (list1[n], list2[n]).
I believe there's also a way to use zip() to separate your list of
tuples into separate list
I think it's a little strange and possibly problematic that type(1)
is 'int' and type(True) is 'bool' but
1 == True
specifically evaluates to True even though anything else, even if it
evaluates to True when cast as a boolean, is not == True.
>>> 1 == True
True
>>> 2 == True
False
>>> 0 ==
On Mar 6, 2007, at 4:28 PM, wesley chun wrote:
>> >>> x=('i' in 'i')
>> >>> x
>> True
>> >>> y='i'
>> >>> x==y
>> False
>
> you're right when you talk about "casting" altho that's not what
> python does. it merely performs an object value comparison when you
> use '=='. for example, change
On Mar 6, 2007, at 11:03 AM, Alan Gauld wrote:
> It's doing the latter and since anything that's not 'empty' in
> Python evaluates to true we wind up checking whether
> true == (item in word)
>
> So if the item is in word we get true == true which is true.
>
> HTH,
Sorry, but this still doesn't ma
OK, I'm new to python too so I don't assume I know what I'm talking
about yet, but this looks like a mess to me. What exactly does "item
== item in word2" evaluate to? Does "in" or "==" have higher
precedence?
I can't figure out how this would ever work at all. It seems like
it's either
On Mar 2, 2007, at 9:56 AM, Alan Gauld wrote:
> Why not use a Set?
>
> s = Set([somefun(i) for i in some-iterator])
>
> Might be slow for big lists though...
I'm curious why using a Set would be slower than doing it in a loop?
In either case, the processor has to scan through all the data
l
If you want to play around with this stuff, you can first import sys,
and then insert this line in the except clause:
print repr(sys.exc_info())
(or some other way of getting the details out of the returned tuple.)
That will tell you exactly what brought you to the except clause.
On Feb 28, 200
This question isn't well posed. There is no such thing as an F1
"character".
Data is sent over telnet connections as 8-bit bytes. You can send
any combination of 8-bit bytes you want by coding them in a number of
different ways, such as chr(xx) like you wrote below, or '\xnn' or
whatever
I found this by "using Google". You should be able to make a simple
modification (I can think of a couple of ways to do it) to have it
pad the end with "None". It is 100% iterator input and output.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279
On Feb 25, 2007, at 7:06 AM, C
Keep in mind that things generally become extremely reliable only
after extensive real-world testing. TANSTAAFL
On Feb 25, 2007, at 1:14 AM, Kirk Bailey wrote:
> This has to be baby carriage reliable and simple for the business road
> warrior who has not a geekified bone in their body.
--
234567890)
> _t1 = _timer()
> return _t1 - _t0
> """
> I get these results:
>
> for computeBin(12345678901234567890)
> 1000 loops, best of 3: 448 usec per loop
>
> for computeBin(1234567890)
> 1 loops, best of 3: 59.7 usec per loop
>
>
I suspect the function I sent out earlier, using octal conversion and
a lookup table, will be faster. But it would be very interesting to
see some simple benchmarks.
On Feb 20, 2007, at 10:47 PM, Dick Moores wrote:
> I was surprised to be unable to find a function in Python for
> converting
You're way off base... :)
On Feb 19, 2007, at 9:25 AM, Johan Geldenhuys wrote:
> Here is what I have:
>
data
> '\xa5\x16\x0b\x0b\x00\xd5\x01\x01\x01\x00\x00\xe3\x84(\x01\xc6\x00
> \x00\x17\x
> 01C\xc7'
data[0]
> '\xa5'
len(data[0])
> 1
>
> You see that data[0] is only one by
This kind of thing is usually handled at the level of the OS's
routing table. Routing tables have an entry called "metric" that is
used to weight the different routes, so that when there are multiple
possible links available, the one with the lowest metric is used
first. In Unix at least,
36 matches
Mail list logo