Saturday, March 6, 2010

comp.lang.python - 8 new messages in 5 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* best practices: is collections.defaultdict my friend or not? - 4 messages, 3
authors
http://groups.google.com/group/comp.lang.python/t/4bfdc60d3f58c960?hl=en
* paypal wholesale all brand(UGGBOOTS,SHOES,CLOTHES,HANDBAG,WATCH,JEANS,JERSEY,
T-SHIRT,SHIRTS,HOODY,EYEGLASS,CAP,SHAWL,WALLT) and so on. - 1 messages, 1
author
http://groups.google.com/group/comp.lang.python/t/65ebce741710e478?hl=en
* My four-yorkshireprogrammers contribution - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/dea5c94f3d058e26?hl=en
* Initial RSON prototype parser in subversion - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/09ce33197b330e90?hl=en
* Fast GUI pipemeter: gprog - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/1692f771329d02d2?hl=en

==============================================================================
TOPIC: best practices: is collections.defaultdict my friend or not?
http://groups.google.com/group/comp.lang.python/t/4bfdc60d3f58c960?hl=en
==============================================================================

== 1 of 4 ==
Date: Fri, Mar 5 2010 6:53 pm
From: Paul Rubin


Pete Emerson <pemerson@gmail.com> writes:
> I found out that adding a two dimensional element without defining
> first dimension existing doesn't work:
>
>>>> data = {}
>>>> data['one']['two'] = 'three'

You can use a tuple as a subscript if you want:

data = {}
data['one','two'] = 'three'


== 2 of 4 ==
Date: Fri, Mar 5 2010 8:24 pm
From: Steven D'Aprano


On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote:

> Why isn't the behavior of collections.defaultdict the default for a
> dict?

Why would it be?

If you look up a key in a dict:

addressbook['Barney Rubble']

and you don't actually have Barney's address, should Python guess and
make something up?

In general, looking up a missing key is an error, and errors should never
pass silently unless explicitly silenced.

And for those cases where missing keys are not errors, you're spoiled for
choice:

dict.get
dict.setdefault
collections.defaultdict

try:
dict[key]
except KeyError:
do something else

Or even:

if key in dict:
dict[key]
else:
do something else


--
Steven


== 3 of 4 ==
Date: Fri, Mar 5 2010 9:36 pm
From: Pete Emerson


On Mar 5, 8:24 pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
> On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote:
> > Why isn't the behavior of collections.defaultdict the default for a
> > dict?
>
> Why would it be?
>
> If you look up a key in a dict:
>
> addressbook['Barney Rubble']
>
> and you don't actually have Barney's address, should Python guess and
> make something up?
>
> In general, looking up a missing key is an error, and errors should never
> pass silently unless explicitly silenced.
>
> And for those cases where missing keys are not errors, you're spoiled for
> choice:
>
> dict.get
> dict.setdefault
> collections.defaultdict
>
> try:
>     dict[key]
> except KeyError:
>     do something else
>
> Or even:
>
> if key in dict:
>     dict[key]
> else:
>     do something else
>
> --
> Steven

My frame of reference for the past 10 < N < 15 years has been doing
this sort of assignment in perl:

$hash{key1}{key2} = value

I definitely agree that looking up a missing key should give an error.
The lazy perl programmer in me just wants to make an assignment to a
missing second key without defining the first key first. I'm not
saying it's right, I'm saying that it's something I'm trying to
unlearn, as I'm being convinced that it's the "best way" to do it in
python.

I'll take a look at dict.get and dict.setdefault, thank you for those.

I'm learning, and you're all very helpful, and I appreciate it!

Pete


== 4 of 4 ==
Date: Fri, Mar 5 2010 9:42 pm
From: Pete Emerson


On Mar 5, 6:26 pm, MRAB <pyt...@mrabarnett.plus.com> wrote:
> Pete Emerson wrote:
> > I've been wrestling with dicts. I hope at the very least what I
> > discovered helps someone else out, but I'm interested in hearing from
> > more learned python users.
>
> > I found out that adding a two dimensional element without defining
> > first dimension existing doesn't work:
>
> >>>> data = {}
> >>>> data['one']['two'] = 'three'
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > KeyError: 'one'
> >>>> data['one'] = {}
> >>>> data['one']['two'] = 'three'
> >>>> print data
> > {'one': {'two': 'three'}}
>
> > And through some research, I discovered collections.defaultdict (new
> > in Python 2.5, FWIW):
>
> >>>> import collections
> >>>> data = collections.defaultdict(dict)
> >>>> data['one']['two'] = 'three'
> >>>> print data
> > defaultdict(<type 'dict'>, {'one': {'two': 'three'}})
>
> > Why isn't the behavior of collections.defaultdict the default for a
> > dict?
> > Am I just revelling in my bad perl habits by not wanting to declare a
> > previous level first?
> > Is this sort of "more rigid" way of doing things common throughout
> > python, and is it best that I not fight it, but embrace it?
>
> > Your thoughts and comments are very much appreciated. I think my brain
> > already knows some of the answers, but my heart ... well, perl and I
> > go way back. Loving python so far, though.
>
> Someone once wrote about a case where he was porting a frontend from
> Perl to Python. It called a backend and parsed the result. Sometimes
> converting one of the fields to a number would raise a ValueError
> because it would contain "ERR" instead of a number, which Perl, of
> course, would silently convert to 0!
>
> Python is all about refusing to guess, and complaining if there's an
> error. :-)

Perl is quite an amazing language, but it also definitely allows for
sloppy habits and poor coding behaviors, particularly for someone such
as me whose perl is completely self taught. I think that's why this
time around with python I'm trying to learn my prior experience and
seek help in areas where I suspect there is improvement to be made.
I'm really liking the rigid flexibility I'm experiencing with python
so far.

I'm thinking it's time for me to get a python reference or two, just
to kill a few trees. If anyone has any strong feelings about what
belongs in a "beginner but already learning quickly" library, please
toss them my way. I'll grep around the 'net for opinions on it, too.

Pete

==============================================================================
TOPIC: paypal wholesale all brand(UGGBOOTS,SHOES,CLOTHES,HANDBAG,WATCH,JEANS,
JERSEY,T-SHIRT,SHIRTS,HOODY,EYEGLASS,CAP,SHAWL,WALLT) and so on.
http://groups.google.com/group/comp.lang.python/t/65ebce741710e478?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Mar 5 2010 9:11 pm
From: brandmarket

paypal payment wholesale all brand
shoes(NIKE,ADIDAS,LV,GUCCI,CHANEL,PRADA,POLO,UGG BOOTS,D&G,DIOR )and
so on.
paypal payment wholesale all brand clothing(T-
SHIRT,JEANS,JERSEY,HOODIES,JACKETS,HARDY,SWEATER,SHIRTS )and so on .
http://www.globlepurchase.com
paypal payment all brand
watch(ROLEX,OMEGA,CHANEL,LV,CARTIER,IWC,GUCCI,RADO )and so on.
paypal payment all brand
handbag(LV,GUCCI,CHANEL,PRADA,POLO,COACH,FENDI,CHLOE,BUBERRY,JUICY)
and so on.
paypal payment brand CAP,SHAWL,BELT,WALLET,UNDER WEAR)and so on.

More detail land,address: http://www.globlepurchase.com

==============================================================================
TOPIC: My four-yorkshireprogrammers contribution
http://groups.google.com/group/comp.lang.python/t/dea5c94f3d058e26?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Mar 5 2010 10:55 pm
From: "D'Arcy J.M. Cain"


On Sat, 06 Mar 2010 14:19:03 +1300
Gregory Ewing <greg.ewing@canterbury.ac.nz> wrote:
> MRAB wrote:
> > By the standards of just a few years later, that's not so much a
> > microcomputer as a nanocomputer!
>
> Although not quite as nano as another design published
> in EA a couple of years earlier, the EDUC-8:

Byte Magazine once published plans for building a computer that had one
instruction. I believe it was a six bit address so that would make it
a max of 64 bytes. If I recall, the single instruction was "SUBTRACT
AND JUMP ON CARRY." Now that's nano!

--
D'Arcy J.M. Cain <darcy@druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

==============================================================================
TOPIC: Initial RSON prototype parser in subversion
http://groups.google.com/group/comp.lang.python/t/09ce33197b330e90?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Mar 5 2010 11:21 pm
From: Patrick Maupin


I have not yet added indentation sensitivity to the parser (although
the tokenizer saves the indentation information for the parser), but
the initial prototype parses all of JSON plus a lot of syntax
enhancements (comments, hex/binary/octal numbers, relaxed quoting
requirements for strings, trailing comments allowed, triple-quoted
strings, etc.)

I have also started the rson-discuss group on google for further
discussions on the actual syntax and initial implementation, if anyone
is interested, and have posted a message there with a bit more
information about the prototype status.

The project page is at http://code.google.com/p/rson/

Best regards,
Pat

==============================================================================
TOPIC: Fast GUI pipemeter: gprog
http://groups.google.com/group/comp.lang.python/t/1692f771329d02d2?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Mar 6 2010 12:21 am
From: Dan Stromberg


On Mar 4, 4:25 pm, Dan Stromberg <strom...@gmail.com> wrote:

> Python folk: Any guesses why a simple file.read(blocksize) would have
> such an affinity for returning 16K when redirected from /dev/zero?  If
> I run the program against a file on disk, it gets larger blocksizes
> fine.

Never mind - it was a bug in my code.

Now on a slower machine, it runs about 2.5 times faster than it did on
the faster machine.


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate