Elementary string-formatting

2008-01-12 Thread Odysseus
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin from the Terminal on Mac OS X v10.4.11. P.S. Is there a preferable technique for forcing floating-point division of two integers to that used above, multiplying by "100.0" first? What about if I just wanted a ratio: is "float(n / m)" better than "1.0 * n / m"? -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-formatting

2008-01-13 Thread Odysseus
le I was writing the message. Thanks for the reality check. -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-formatting

2008-01-13 Thread Odysseus
operator will still behave as usual? -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-formatting

2008-01-13 Thread Odysseus
In article <[EMAIL PROTECTED]>, Gary Herron <[EMAIL PROTECTED]> wrote: > Odysseus wrote: > > > > print '%2u %6u %4.2f' % \ > > (i, wordcounts[i], 100.0 * wordcounts[i] / wordcounts[0]) > > > Using 4.2 is the problem. The first digit (your

Re: Elementary string-formatting

2008-01-14 Thread Odysseus
In article <[EMAIL PROTECTED]>, John Machin <[EMAIL PROTECTED]> wrote: > > div operator? The integer division operator is // Yes, sorry, that's what I meant. -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Elementary string-parsing

2008-02-03 Thread Odysseus
dlist[1]: dlist[1] = m + 1 break m += 1 tlist = dlist[3].split(":") found[name][k] = timegm((int(dlist[2]), int(dlist[1]), int(dlist[0]), int(tlist[0]), int(tlist[1]), int(tlist[2]), -1, -1, 0)) i += 1 The function appears to be working OK as is, but I would welcome any & all suggestions for improving it or making it more idiomatic. -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
rned up hundreds of passing mentions, but I couldn't find a definition or explanation.) > > As already said, that ``while`` loop should be a ``for`` loop. But if you > put `m_abbrevs` into a `list` you can replace the loop with a single call > to its `index()` method: ``dlist[1] = m_abbrevs.index(dlist[1]) + 1``. I had gathered that lists shouldn't be used for storing constants. Is that more of a suggestion than a rule? I take it tuples don't have an "index()" method. Thanks for the detailed advice. I'll post back if I have any trouble implementing your suggestions. -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
he underlying platform's C library for the date parsing, and some of these libraries are buggy. There's nothing to be done about this short of a new, portable implementation of strptime()." If it works, however, it'll be a lot tidier than what I was doing. I'll make a point of testing it on its own, with a variety of inputs. > Note that the %Z is a problematic entry... > ValueError: time data did not match format: data=03 Feb 2008 > 20:35:46 PST fmt=%d %b %Y %H:%M:%S %Z All the times are UTC, so fortunately this is a non-issue for my purposes of the moment. May I assume that leaving the zone out will cause the time to be treated as UTC? Thanks for your help, and for bearing with my elementary questions and my fumbling about. -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article <[EMAIL PROTECTED]>, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Mon, 04 Feb 2008 09:43:04 GMT, Odysseus > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > > > > > Thanks, that will be very useful. I was casting abo

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
s way I turned the > comment into code that checks the assertion in the comment. Good idea to check, although this is actually only one of many assumptions I make about the data -- but what happens if the assertion fails? The program stops and the interpreter reports an AssertionError on line whatever? > [I]f you can make the source simpler and easier to understand by > using the `index()` method, use a list. :-) Understood; thanks for all the tips. -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list