Re: Urllib2 urlopen and read - difference

2010-04-15 Thread J. Cliff Dyer
l it has enough. So your opener returns as soon as the request is sent, and read() blocks if it doesn't have enough data to handle your request. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Urllib2 urlopen and read - difference

2010-04-15 Thread J. Cliff Dyer
l it has enough. So your opener returns as soon as the request is sent, and read() blocks if it doesn't have enough data to handle your request. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: question about list extension

2010-04-16 Thread J. Cliff Dyer
On Sat, 2010-04-17 at 00:37 +1000, Lie Ryan wrote: > On 04/16/10 23:41, J wrote: > > So, what I'm curious about, is there a list comprehension or other > > means to reduce that to a single line? > > from itertools import chain > def printout(*info): > print '\n'.join(map(str, chain(*info))) >

Re: Globally override built-in print function?

2010-04-16 Thread J. Cliff Dyer
On Fri, 2010-04-16 at 09:50 -0700, Dave W. wrote: > >>> old_print = __builtins__.print > >>> __builtins__.print = printhook > >>> yield > >>> __builtins__.print = old_print > > > >> I'm pretty sure this is semantically equivalent to my original > >> code, but I gave it a try anyway.

Re: Difficulty w/json keys

2010-04-23 Thread J. Cliff Dyer
You need to know what your input data actually looks like, and the best thing for that is a little bit of formatting. I bet you can figure out the problem yourself, once you see the structure of your data more clearly. I've reformatted the JSON for you to help out. On Fri, 2010-04-23 at 07:20

Re: how to select column

2010-04-26 Thread J. Cliff Dyer
our columns can have spaces within them, or are separated in other ways, you'll need something else. Cheers, Cliff On Mon, 2010-04-26 at 14:50 +, mannu jha wrote: > Dear all, > > I am new in python, can anyone help me that how can I select two > column out of 6 column from

Re: Python dot-equals (syntax proposal)

2010-04-30 Thread J. Cliff Dyer
That's kind of a nifty idea. However, python is currently under a syntax moratorium. No syntax changes will be accepted for at least 24 months starting from the release date of Python 3.1. See more details here: http://www.python.org/dev/peps/pep-3003/ Cheers, Cliff On Fri, 2010-04-30

Re: Frustration debugging serial code

2010-05-07 Thread J. Cliff Dyer
On Fri, 2010-05-07 at 15:36 -0400, William R. Wing wrote: > > Maybe I should have been more explicit. The first line in the Python > file is: > > > #!/usr/bin/env Python (alternatively #!/usr/bin/Python - same results > either way). > python should be lowercased when referring to the name of

Re: Frustration debugging serial code

2010-05-07 Thread J. Cliff Dyer
On Fri, 2010-05-07 at 15:36 -0400, William R. Wing wrote: > > Maybe I should have been more explicit. The first line in the Python > file is: > > > #!/usr/bin/env Python (alternatively #!/usr/bin/Python - same results > either way). > python should be lowercased when referring to the name of

Re: unittest not being run

2010-05-10 Thread J. Cliff Dyer
on of your `def test_T1(self):` line is off by one column, relative to pass, and by three columns relative to the other methods. Cheers, Cliff On Mon, 2010-05-10 at 13:38 +0100, John Maclean wrote: > hi, > > can some one explain why the __first__ test is not being run? > > #

Re: Regular expression

2010-05-18 Thread J. Cliff Dyer
Don't use regular expressions for that. s = '0x340x5A0x9B0xBA' return '0x' + ''.join(s.split('0x')) On Tue, 2010-05-18 at 06:48 -0700, Back9 wrote: > Hi, > > I have a string like this: > 0x340x5A0x9B0xBA > I want to extract 0x from the string but the first one. > > How I can use re for this cas

Re: how to preserve hex value

2010-05-19 Thread J. Cliff Dyer
in s) However, if you need an arbitrary number of zeros preserved, you're out of luck. They are semantically meaningless in python. (Is semantically meaningless redundant?) Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: optional optional args vs optional positional options

2010-06-02 Thread J. Cliff Dyer
+1 Options are options, arguments are arguments. An optional argument is not an option. It is an argument that can be left out. On Wed, 2010-06-02 at 12:42 +0200, Antoine Pitrou wrote: > On Wed, 2 Jun 2010 01:49:18 -0700 (PDT) > Michele Simionato wrote: > > > > Notice that optparse is bas

Re: super() woes (n00b)

2010-06-17 Thread J. Cliff Dyer
On Thu, 2010-06-17 at 16:36 +, Deadly Dirk wrote: > I cannot get right the super() function: > Python 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22) > [GCC 4.4.1] on linux2 > Type "copyright", "credits" or "license()" for more information. > No Subprocess > >>> class P: > def __init_

Re: Perl's @foo[3,7,1,-1] ?

2009-06-15 Thread J. Cliff Dyer
; But I think this is an obvious enough extension to the __getitem__ protocol > that I for one would vote +1 on it being added to Python sequence objects > (lists, tuples, strings). > I'd be +0. It won't change my life, but it seems like a decent idea. > > -- > Steven > Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Perl's @foo[3,7,1,-1] ?

2009-06-17 Thread J. Cliff Dyer
ple from doing a 'from package import *'. However, example code should always include relevant imports. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Perl's @foo[3,7,1,-1] ?

2009-06-22 Thread J. Cliff Dyer
On Mon, 2009-06-22 at 14:57 +0200, Jean-Michel Pichavant wrote: > J. Cliff Dyer wrote: > > On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > > > >> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > >> > >>>> What&

Re: How to output a complex List object to a file.

2009-06-22 Thread J. Cliff Dyer
Have you looked at the JSON module? On Mon, 2009-06-22 at 21:17 +0800, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure=[ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {I

Re: Procedures

2009-06-22 Thread J. Cliff Dyer
trace which will help you (or us) debug the problem. If you don't show us this information, we can't tell you what's going wrong. It will tell you (in ways that are crystal clear once you have a bit of practice reading them) exactly what went wrong. Can you show your code, as well as the complete error message you are receiving? My suggestions here, are essentially a paraphrasing of Eric Raymond's essay, "How to Ask Smart Questions." It is freely available on the web, and easily found via google. I recommend reading that, in order to get the most mileage out this news group. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Procedures

2009-06-23 Thread J. Cliff Dyer
were just defs. I changed the short defs > into sub-classes out of desperation, since I don't understand why the > main script is not recognizing functions that are in the same file. > > First is the shell input/output, then "ParseWork.py", the entire text &g

Re: Idioms and Anti-Idioms Question

2009-06-23 Thread J. Cliff Dyer
On Mon, 2009-06-22 at 22:52 +, Peter Billam wrote: > I wonder on what grounds PEP8 > says "The preferred place to break around a binary operator is > *after* the operator" ? > Perhaps it's just the "continutation marker" rationale? > > Regards, Peter > > -- > Peter Billam www.pjb.com

Re: Get name of class without instance

2009-06-24 Thread J. Cliff Dyer
On Wed, 2009-06-24 at 09:17 -0700, Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don

Re: It's ...

2009-06-24 Thread J. Cliff Dyer
, I'm just getting my feet wet, and I'll try not to ask too many > silly questions! > > First impressions are: (1) Python seems both elegant and practical; > and (2) Beazley seems a pleasantly unfussy introduction for someone > with at least a little programming exper

Re: It's ...

2009-07-01 Thread J. Cliff Dyer
On Tue, 2009-06-30 at 13:24 -0700, Beni Cherniavsky wrote: > On Jun 24, 11:40 pm, "J. Cliff Dyer" wrote: > > Also note that you can iterate over a file several times: > > > > f = open('foo.txt') > > for line in f: > > print line[0] # print

Re: Idioms and Anti-Idioms Question

2009-07-02 Thread J. Cliff Dyer
On Wed, 2009-07-01 at 17:19 +1200, Lawrence D'Oliveiro wrote: > In message , J. Cliff > Dyer wrote: > > > If the lines got separated, a leading + could disappear into its line > > without any errors showing up. A trailing + would raise a syntax error. > > Unle

Re: count

2009-07-09 Thread J. Cliff Dyer
Bearophile wins! (This only times the loop itself. It doesn't check for __len__) summer:5 0:00:00.51 bearophile:5 0:00:00.09 summer:50 0:00:00.30 bearophile:50 0:00:00.13 summer:500 0:00:00.77 bearophile:500 0:00:00.53 summer:5000 0:00:00.000575 bearophile:5000 0:00:00.00

Re: tough-to-explain Python

2009-07-09 Thread J. Cliff Dyer
On Thu, 2009-07-09 at 18:10 +, Steven D'Aprano wrote: > If programming is symbol manipulation, then you should remember that > the > user interface is also symbol manipulation, and it is a MUCH harder > problem than databases, sorting, searching, and all the other > problems > you learn abou

Re: Clarity vs. code reuse/generality

2009-07-10 Thread J. Cliff Dyer
pening more clearly. And it protects you if another caller (even one internal to the class) calls it with a different set of assumptions. At minimum, I think there's a heavy burden on an author to justify the use of AssertionErrors rather than other kinds of Exceptions. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Clarity vs. code reuse/generality

2009-07-10 Thread J. Cliff Dyer
On Fri, 2009-07-10 at 11:57 -0500, Robert Kern wrote: > On 2009-07-10 11:50, J. Cliff Dyer wrote: > > On Fri, 2009-07-10 at 02:57 +, Steven D'Aprano wrote: > >> On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote: > >> > >>> On Thu, 09 Jul

Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-10 Thread J. Cliff Dyer
On Thu, 2009-07-09 at 13:53 +, Friðrik Már Jónsson wrote: > Look at: > >len = len(text) > > You're overriding `len` (a built-in method), with an integer > (`len(text)`). You then call: > >for i in range(len(fields)): > > But `len` is no longer a callable, but merely an integer. >

Re: Nested Classes and Instances

2009-07-10 Thread J. Cliff Dyer
def __init__(self, color): self.color = color class Sign(object): def __init__(self, inscription): self.inscription = str(housenumber) (Something like that) Cheers, Cliff > Well, so far, so good. Now, what I'd like to achive is that the text of > the "sign"

Re: mail

2009-07-15 Thread J. Cliff Dyer
plit() >>> >>> if data[1] not in thingies: >>> # group data by data[1] >>> thingies[data[1]] = {} >>> >>> thingies[data[1]][data[3]] = data[5] Step two, extract the data from the list: >>> for key, data in thingies.items(): >>> print key, >>> for entry in data >>> print '%s = %s' % (entry, data[entry]), This should do what you want, minus some formatting issues. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: A Bug By Any Other Name ...

2009-07-17 Thread J. Cliff Dyer
rity, a.k.a. don't you have something better to do? Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread J. Cliff Dyer
On Mon, 2009-07-20 at 12:26 -0700, Phillip B Oldham wrote: > On Jul 20, 6:08 pm, Duncan Booth wrote: > > The main reason why you need both lists and tuples is that because a tuple > > of immutable objects is itself immutable you can use it as a dictionary > > key. > > Really? That sounds interest

Re: A Bug By Any Other Name ...

2009-08-03 Thread J. Cliff Dyer
, but it is not. You are proposing changing the parsing rules, which completely changes the scope of what is possible and what isn't with python syntax. All to solve a problem that, so far, hasn't been proven to exist in anything other than a speculative way. You're trying to turn an ocean liner around because you left your sunscreen on the dock. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: variable & scoping question.

2009-08-10 Thread J. Cliff Dyer
Learn the pythonic workaround of using None in your parameters whenever you want a default empty list, and don't let it bother you too much. Overall, python is a remarkably well designed language. This is one of the relatively rare warts that crept in because it enables a broader cleanliness of design. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: dictionary help

2009-08-10 Thread J. Cliff Dyer
u want your class to be able to do, and what the API will be for performing each of those functions. Then you should be able to begin implementing it, or at least come up with some more specific questions. > Thank you very much, > Krishna Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list

Re: How to create functors?

2009-08-19 Thread J. Cliff Dyer
On Wed, 2009-08-19 at 15:56 +0200, Bruno Desthuilliers wrote: > Terry Reedy a écrit : > > Robert Dailey wrote: > > > >> I'm using Python 2.6. And using the legacy syntax in the lambda does > >> not work either. I want to avoid using a def if possible. Thanks. > > > > In Python, writing > > > > n

Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread J. Cliff Dyer
tion as I think, and explain a clean, elegant implementation for this, many of my concerns would be alleviated, and I would change my -1 to a -0. Cheers, Cliff On Mon, 2009-08-24 at 00:01 +1000, Ben Finney wrote: > garabik-news-2005...@kassiopeia.juls.savba.sk writes: > > Why not

Re: Help with cumulative sum

2009-09-08 Thread J. Cliff Dyer
sum totals of nums""" # ??? list_of_numbers = [1, 24, 34, 28, 4, 1] cumulative_sum = summifier(list_of_numbers) assert(cumulative_sum == [1, 25, 59, 87, 91, 92]) If you can come up with the summifier function, you're all set. I gotta say, though, this smells like homework.

<    1   2   3   4