comp.lang.python - 26 new messages in 8 topics - digest
comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en
comp.lang.python@googlegroups.com
Today's topics:
* question about input() and/or raw_input() - 11 messages, 7 authors
http://groups.google.com/group/comp.lang.python/t/310565f7979cee4c?hl=en
* What's wrong with scientific Python? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/20a7b4de875075c0?hl=en
* Python Scalability TCP Server + Background Game - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/8234bf03949a8164?hl=en
* graphical python - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/fbe4c24dcdbb015d?hl=en
* python-daemon for Python v3 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f93a6aca18b45b46?hl=en
* Help with simple code that has database defined - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b71867faf4711297?hl=en
* Documentation of dict views change request - 5 messages, 5 authors
http://groups.google.com/group/comp.lang.python/t/a8a0945f03a345db?hl=en
* How to write this as a list comprehension? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/0b63055a0d321622?hl=en
==============================================================================
TOPIC: question about input() and/or raw_input()
http://groups.google.com/group/comp.lang.python/t/310565f7979cee4c?hl=en
==============================================================================
== 1 of 11 ==
Date: Sun, Jan 19 2014 10:37 am
From: Roy Smith
In article <lbh4oc$nqv$1@reader1.panix.com>,
Grant Edwards <invalid@invalid.invalid> wrote:
> I can still remember the point in my first trip to the UK when I
> accidentally stumbled across darts on TV. Given the endless variety
> (and quantity) of pointless crap that people watch here in the US, I
> can't really explain why I was so baffled and amused by darts on TV --
> but I was.
What's so complicated?
points = 501
for dart in throws():
if points - dart == 0 and dart.is_double():
raise YouWin
if points - dart < 0:
continue
points -= dart
beer.drink()
== 2 of 11 ==
Date: Sun, Jan 19 2014 10:41 am
From: Chris Angelico
On Mon, Jan 20, 2014 at 4:50 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> The difference I was thinking of is:
>
> "%h" % 3.14 # this works
>
> vs.
>
> hex(3.14) # this raises
>
> In 3.5 both will raise.
Now you have me *thoroughly* intrigued. It's not %h (incomplete format
- h is a modifier), nor %H (unsupported format character). Do you mean
%x? As of 3.4.0b2, that happily truncates a float:
>>> "%x" % 3.14
'3'
Is that changing in 3.5? Seems a relatively insignificant point, tbh!
Anyway, no biggie.
ChrisA
== 3 of 11 ==
Date: Sun, Jan 19 2014 10:43 am
From: Chris Angelico
On Mon, Jan 20, 2014 at 5:37 AM, Roy Smith <roy@panix.com> wrote:
> What's so complicated?
>
> points = 501
> for dart in throws():
> if points - dart == 0 and dart.is_double():
> raise YouWin
> if points - dart < 0:
> continue
> points -= dart
> beer.drink()
assert victory
raise beer
ChrisA
== 4 of 11 ==
Date: Sun, Jan 19 2014 11:11 am
From: Grant Edwards
On 2014-01-19, Roy Smith <roy@panix.com> wrote:
> In article <lbh4oc$nqv$1@reader1.panix.com>,
> Grant Edwards <invalid@invalid.invalid> wrote:
>
>> I can still remember the point in my first trip to the UK when I
>> accidentally stumbled across darts on TV. Given the endless variety
>> (and quantity) of pointless crap that people watch here in the US, I
>> can't really explain why I was so baffled and amused by darts on TV --
>> but I was.
>
> What's so complicated?
>
> points = 501
> for dart in throws():
> if points - dart == 0 and dart.is_double():
> raise YouWin
> if points - dart < 0:
> continue
> points -= dart
> beer.drink()
That looks like an algorithm for _playing_ darts. That I understand.
I have two dartboards (one real, one electronic) and a coule decent
sets of darts. It's watching darts on TV that I don't get.
Actually, I don't really get watching any sort of sports on TV (even
the ones I play). But there was just something about darts on TV that
seemed particularly beyond the pale.
--
Grant Edwards grant.b.edwards Yow! But they went to MARS
at around 1953!!
gmail.com
== 5 of 11 ==
Date: Sun, Jan 19 2014 11:17 am
From: Mark Lawrence
On 19/01/2014 18:15, Grant Edwards wrote:
> On 2014-01-19, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> On 18/01/2014 18:41, Mark Lawrence wrote:
>>> On 18/01/2014 18:30, Roy Smith wrote:
>>>> Pardon me for being cynical, but in the entire history of the universe,
>>>> has anybody ever used input()/raw_input() for anything other than a
>>>> homework problem?
>>>
>>> Not me personally. I guess raw_input must have been used somewhere at
>>> some time for something, or it would have been scrapped in Python 3, not
>>> renamed to input.
>>
>> Actually, to go off at a tangent, I'm just getting into GUIs via
>> wxPython. I've discovered there are distinct advantages having to
>> write endless lines of code just to get a piece of data. For example
>> on a Sunday it helps pass the time between the two sessions of the
>> Masters Snooker final being shown on TV.
>
> Fair enough, but what do you do to pass the time _during_ Snooker
> being shown on TV?
>
> I can still remember the point in my first trip to the UK when I
> accidentally stumbled across darts on TV. Given the endless variety
> (and quantity) of pointless crap that people watch here in the US, I
> can't really explain why I was so baffled and amused by darts on TV --
> but I was.
>
Just no comparison, darts and snooker. This is excellent though
http://www.youtube.com/watch?v=sHnBppccI0o
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
== 6 of 11 ==
Date: Sun, Jan 19 2014 11:24 am
From: Larry Martell
On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> On 19/01/2014 18:15, Grant Edwards wrote:
>>
>> On 2014-01-19, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>>> Actually, to go off at a tangent, I'm just getting into GUIs via
>>> wxPython. I've discovered there are distinct advantages having to
>>> write endless lines of code just to get a piece of data. For example
>>> on a Sunday it helps pass the time between the two sessions of the
>>> Masters Snooker final being shown on TV.
>>
>>
>> Fair enough, but what do you do to pass the time _during_ Snooker
>> being shown on TV?
>>
>> I can still remember the point in my first trip to the UK when I
>> accidentally stumbled across darts on TV. Given the endless variety
>> (and quantity) of pointless crap that people watch here in the US, I
>> can't really explain why I was so baffled and amused by darts on TV --
>> but I was.
>>
>
> Just no comparison, darts and snooker. This is excellent though
> http://www.youtube.com/watch?v=sHnBppccI0o
Now that we're way off on the tangent of what some people consider
boring and others don't, I'm really looking forward to watching
curling in the upcoming Olympics.
== 7 of 11 ==
Date: Sun, Jan 19 2014 11:29 am
From: Mark Lawrence
On 19/01/2014 19:24, Larry Martell wrote:
> On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> On 19/01/2014 18:15, Grant Edwards wrote:
>>>
>>> On 2014-01-19, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>>>> Actually, to go off at a tangent, I'm just getting into GUIs via
>>>> wxPython. I've discovered there are distinct advantages having to
>>>> write endless lines of code just to get a piece of data. For example
>>>> on a Sunday it helps pass the time between the two sessions of the
>>>> Masters Snooker final being shown on TV.
>>>
>>>
>>> Fair enough, but what do you do to pass the time _during_ Snooker
>>> being shown on TV?
>>>
>>> I can still remember the point in my first trip to the UK when I
>>> accidentally stumbled across darts on TV. Given the endless variety
>>> (and quantity) of pointless crap that people watch here in the US, I
>>> can't really explain why I was so baffled and amused by darts on TV --
>>> but I was.
>>>
>>
>> Just no comparison, darts and snooker. This is excellent though
>> http://www.youtube.com/watch?v=sHnBppccI0o
>
> Now that we're way off on the tangent of what some people consider
> boring and others don't, I'm really looking forward to watching
> curling in the upcoming Olympics.
>
Curling, now there's another good reason to allow Scottish independance :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
== 8 of 11 ==
Date: Sun, Jan 19 2014 11:16 am
From: Ethan Furman
On 01/19/2014 10:41 AM, Chris Angelico wrote:
> On Mon, Jan 20, 2014 at 4:50 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
>> The difference I was thinking of is:
>>
>> "%h" % 3.14 # this works
>>
>> vs.
>>
>> hex(3.14) # this raises
>>
>> In 3.5 both will raise.
>
> Now you have me *thoroughly* intrigued. It's not %h (incomplete format
> - h is a modifier), nor %H (unsupported format character). Do you mean
> %x? As of 3.4.0b2, that happily truncates a float:
>
>>>> "%x" % 3.14
> '3'
>
> Is that changing in 3.5? Seems a relatively insignificant point, tbh!
Argh. Yes, %x or %X.
--
~Ethan~
== 9 of 11 ==
Date: Sun, Jan 19 2014 12:12 pm
From: Gene Heskett
On Sunday 19 January 2014 15:11:52 Larry Martell did opine:
> On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence <breamoreboy@yahoo.co.uk>
wrote:
> > On 19/01/2014 18:15, Grant Edwards wrote:
> >> On 2014-01-19, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> >>> Actually, to go off at a tangent, I'm just getting into GUIs via
> >>> wxPython. I've discovered there are distinct advantages having to
> >>> write endless lines of code just to get a piece of data. For
> >>> example on a Sunday it helps pass the time between the two sessions
> >>> of the Masters Snooker final being shown on TV.
> >>
> >> Fair enough, but what do you do to pass the time _during_ Snooker
> >> being shown on TV?
> >>
> >> I can still remember the point in my first trip to the UK when I
> >> accidentally stumbled across darts on TV. Given the endless variety
> >> (and quantity) of pointless crap that people watch here in the US, I
> >> can't really explain why I was so baffled and amused by darts on TV
> >> -- but I was.
> >
> > Just no comparison, darts and snooker. This is excellent though
> > http://www.youtube.com/watch?v=sHnBppccI0o
>
> Now that we're way off on the tangent of what some people consider
> boring and others don't, I'm really looking forward to watching
> curling in the upcoming Olympics.
I have Larry, and the suspense is not good for those with high blood
pressure.
Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>
Required reading:
<http://culturalslagheap.wordpress.com/2014/01/12/elemental/>
I've enjoyed just about as much of this as I can stand.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
law-abiding citizens.
== 10 of 11 ==
Date: Sun, Jan 19 2014 12:09 pm
From: Gene Heskett
On Sunday 19 January 2014 15:08:31 Roy Smith did opine:
> In article <lbh4oc$nqv$1@reader1.panix.com>,
>
> Grant Edwards <invalid@invalid.invalid> wrote:
> > I can still remember the point in my first trip to the UK when I
> > accidentally stumbled across darts on TV. Given the endless variety
> > (and quantity) of pointless crap that people watch here in the US, I
> > can't really explain why I was so baffled and amused by darts on TV --
> > but I was.
>
> What's so complicated?
>
> points = 501
> for dart in throws():
> if points - dart == 0 and dart.is_double():
> raise YouWin
> if points - dart < 0:
> continue
> points -= dart
> beer.drink()
Aren't you missing a fi there, or a next dart? ;-)
Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>
Required reading:
<http://culturalslagheap.wordpress.com/2014/01/12/elemental/>
Baseball is a skilled game. It's America's game - it, and high taxes.
-- The Best of Will Rogers
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
law-abiding citizens.
== 11 of 11 ==
Date: Sun, Jan 19 2014 12:22 pm
From: Larry Martell
On Sun, Jan 19, 2014 at 1:12 PM, Gene Heskett <gheskett@wdtv.com> wrote:
> On Sunday 19 January 2014 15:11:52 Larry Martell did opine:
>
>> On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence <breamoreboy@yahoo.co.uk>
> wrote:
>> > On 19/01/2014 18:15, Grant Edwards wrote:
>> >> On 2014-01-19, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> >>> Actually, to go off at a tangent, I'm just getting into GUIs via
>> >>> wxPython. I've discovered there are distinct advantages having to
>> >>> write endless lines of code just to get a piece of data. For
>> >>> example on a Sunday it helps pass the time between the two sessions
>> >>> of the Masters Snooker final being shown on TV.
>> >>
>> >> Fair enough, but what do you do to pass the time _during_ Snooker
>> >> being shown on TV?
>> >>
>> >> I can still remember the point in my first trip to the UK when I
>> >> accidentally stumbled across darts on TV. Given the endless variety
>> >> (and quantity) of pointless crap that people watch here in the US, I
>> >> can't really explain why I was so baffled and amused by darts on TV
>> >> -- but I was.
>> >
>> > Just no comparison, darts and snooker. This is excellent though
>> > http://www.youtube.com/watch?v=sHnBppccI0o
>>
>> Now that we're way off on the tangent of what some people consider
>> boring and others don't, I'm really looking forward to watching
>> curling in the upcoming Olympics.
>
> I have Larry, and the suspense is not good for those with high blood
> pressure.
Then don't watch the women:
http://oglympics.com/2010/02/16/women-of-curling-fire-on-ice/
==============================================================================
TOPIC: What's wrong with scientific Python?
http://groups.google.com/group/comp.lang.python/t/20a7b4de875075c0?hl=en
==============================================================================
== 1 of 3 ==
Date: Sun, Jan 19 2014 10:46 am
From: candide
http://cyrille.rossant.net/whats-wrong-with-scientific-python/
Any comments ?
== 2 of 3 ==
Date: Sun, Jan 19 2014 11:10 am
From: Mark Lawrence
On 19/01/2014 18:46, candide wrote:
>
> http://cyrille.rossant.net/whats-wrong-with-scientific-python/
>
> Any comments ?
>
Not worth reading as doesn't seem to have anything new to say. As for
Python 2 being obsolete, well I just give up :(
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
== 3 of 3 ==
Date: Sun, Jan 19 2014 11:23 am
From: Ben Finney
candide <pascal.ortiz@gmail.com> writes:
> http://cyrille.rossant.net/whats-wrong-with-scientific-python/
> Any comments ?
It's in need of a good summary.
--
\ "I have never imputed to Nature a purpose or a goal, or |
`\ anything that could be understood as anthropomorphic." --Albert |
_o__) Einstein, unsent letter, 1955 |
Ben Finney
==============================================================================
TOPIC: Python Scalability TCP Server + Background Game
http://groups.google.com/group/comp.lang.python/t/8234bf03949a8164?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Jan 19 2014 10:53 am
From: Philip Werner
On Sat, 18 Jan 2014 13:19:24 +0000, Mark Lawrence wrote:
> On 18/01/2014 12:40, phiwer@gmail.com wrote:
>
> [snip the stuff I can't help with]
>
> Here's the link you need to sort the problem with double spacing from
> google groups https://wiki.python.org/moin/GoogleGroupsPython
Thanks for the link. I've, hopefully, solved the issue by switching
to Pan instead of using google groups. :)
Regards,
Philip
== 2 of 2 ==
Date: Sun, Jan 19 2014 10:58 am
From: Chris Angelico
On Mon, Jan 20, 2014 at 5:53 AM, Philip Werner <phiwer@gmail.com> wrote:
> On Sat, 18 Jan 2014 13:19:24 +0000, Mark Lawrence wrote:
>
>> On 18/01/2014 12:40, phiwer@gmail.com wrote:
>>
>> [snip the stuff I can't help with]
>>
>> Here's the link you need to sort the problem with double spacing from
>> google groups https://wiki.python.org/moin/GoogleGroupsPython
>
> Thanks for the link. I've, hopefully, solved the issue by switching
> to Pan instead of using google groups. :)
Looking a lot more normal and readable now. Thanks!
Note that some people have experienced odd issues with Pan, possibly
relating to having multiple instances running simultaneously. You may
want to take care not to let it open up a duplicate copy of itself.
ChrisA
==============================================================================
TOPIC: graphical python
http://groups.google.com/group/comp.lang.python/t/fbe4c24dcdbb015d?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Jan 19 2014 11:30 am
From: buck
On Sunday, January 19, 2014 12:19:29 AM UTC-8, Ian wrote:
> On Sat, Jan 18, 2014 at 10:40 PM, buck <w***@gmail.com> wrote:
>
> > I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python.
>
> >
>
> > How would you go about this? pyQt, pygame and pyglet immediately come to mind, but if I go that route the number of people that I can share my work with becomes quite limited, as compared to the portability of javascript projects.
>
> >
>
> > I guess my question really is: has anyone had success creating an interactive graphical project in the browser using python?
>
> >
>
> > Is this a dream I should give up on, and just do this project in coffeescript/d3?
>
>
>
> You should be able to do something without much fuss using HTML 5 and
>
> either Pyjamas (which compiles Python code to Javascript) or Brython
>
> (a more or less complete implementation of Python within Javascript).
>
> For example, see the clock demo on the Brython web page.
>
>
>
> Pyjamas is the more established and probably more stable of the two
>
> projects, but you should be aware that there are currently two active
>
> forks of Pyjamas and some controversy surrounding the project
>
> leadership.
Thanks Ian.
Have you personally used pyjs successfully?
It's ominous that the examples pages are broken...
I was impressed with the accuracy of the Brython implementation. I hope they're able to decrease the web weight in future versions.
== 2 of 2 ==
Date: Sun, Jan 19 2014 12:20 pm
From: Ian Kelly
On Sun, Jan 19, 2014 at 12:30 PM, buck <workitharder@gmail.com> wrote:
> Thanks Ian.
> Have you personally used pyjs successfully?
> It's ominous that the examples pages are broken...
I don't have any personal experience with either project. I don't
know what's going on with pyjs.org currently, but the examples at the
pyj.be fork seem to be in working order.
==============================================================================
TOPIC: python-daemon for Python v3
http://groups.google.com/group/comp.lang.python/t/f93a6aca18b45b46?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 19 2014 11:30 am
From: Larry Martell
On Sun, Jan 19, 2014 at 3:30 AM, Asaf Las <roegltd@gmail.com> wrote:
> Hi Community
>
> Is there ported to Python v3 python-daemon package?
>
> https://pypi.python.org/pypi/python-daemon/
>
> i am afraid it is not as simple as correction of relative path input
> feature and except clauses in mentioned package.
I use this technique for demonizing:
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
And has been ported to 3:
http://www.jejik.com/files/examples/daemon3x.py
==============================================================================
TOPIC: Help with simple code that has database defined
http://groups.google.com/group/comp.lang.python/t/b71867faf4711297?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 19 2014 12:05 pm
From: Denis McMahon
On Sat, 18 Jan 2014 18:23:01 -0800, indar kumar wrote:
> I have to save students information in a database that is keeping
> continuously track of the information. Format is as follows:
You probably need to use one of the database modules.
> Note: if this name already exists there in database, just update the
> information of that(name) e.g course,grade and date. Otherwise, add it.
That sounds like an sql issue specific to your chosen database, not a
python issue.
> This is just part because this is what I know how to do, for rest have
> no idea
I suggest you get idea fast. Or ask your lecturers for advice. Or return
the advance you were paid on this coding job, because you don't seem to
have the skills to do it.
--
Denis McMahon, denismfmcmahon@gmail.com
==============================================================================
TOPIC: Documentation of dict views change request
http://groups.google.com/group/comp.lang.python/t/a8a0945f03a345db?hl=en
==============================================================================
== 1 of 5 ==
Date: Sun, Jan 19 2014 1:26 pm
From: Charles Hixson
Could it please be clearly documented that keys(), values(), and items()
are not writeable. I agree that this is how they should be, but it
would be still better if they were clearly documented as such. The
labeling of them as dynamic, while true, was a bit confusing here.
(I.e., it was talking about changing their value through other means of
access rather than directly through the returned values.)
P.S.: Is it reasonable to return the items() of a dict in order to pass
a read only copy of the values?
--
Charles Hixson
== 2 of 5 ==
Date: Sun, Jan 19 2014 1:40 pm
From: Roy Smith
In article <mailman.5728.1390166846.18130.python-list@python.org>,
Charles Hixson <charleshixsn@earthlink.net> wrote:
> Could it please be clearly documented that keys(), values(), and items()
> are not writeable.
We'll, technically, they are.
>>> d = {'foo': 1, 'bar':2}
>>> k = d.keys()
>>> k
['foo', 'bar']
>>> k[0] = "some other key"
>>> k
['some other key', 'bar']
Of course, this only changes the list that keys() returns, it doesn't
affect the dictionary itself (which, I assume, is what you were really
talking about).
Think this one through. How *could* altering what keys() returns
possibly affect the dict? If it did, that means you could do something
like:
some_dict.keys().append("some other key")
what would that mean? You've added a key, but what's the corresponding
value? I will admit, the picture becomes a bit fuzzier if you consider:
some_dict.items().append(("some other key", 42))
which you could at least imagine would affect the underlying dict.
== 3 of 5 ==
Date: Sun, Jan 19 2014 1:41 pm
From: Mark Lawrence
On 19/01/2014 21:26, Charles Hixson wrote:
> Could it please be clearly documented that keys(), values(), and items()
> are not writeable. I agree that this is how they should be, but it
> would be still better if they were clearly documented as such. The
> labeling of them as dynamic, while true, was a bit confusing here.
> (I.e., it was talking about changing their value through other means of
> access rather than directly through the returned values.)
>
> P.S.: Is it reasonable to return the items() of a dict in order to pass
> a read only copy of the values?
>
Just raise an issue here http://bugs.python.org/
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
== 4 of 5 ==
Date: Sun, Jan 19 2014 1:56 pm
From: Chris Angelico
On Mon, Jan 20, 2014 at 8:40 AM, Roy Smith <roy@panix.com> wrote:
> In article <mailman.5728.1390166846.18130.python-list@python.org>,
> Charles Hixson <charleshixsn@earthlink.net> wrote:
>
>> Could it please be clearly documented that keys(), values(), and items()
>> are not writeable.
>
> We'll, technically, they are.
>
> Of course, this only changes the list that keys() returns, it doesn't
> affect the dictionary itself (which, I assume, is what you were really
> talking about).
In Python 3, they return views, not lists. So they really are read-only.
On Mon, Jan 20, 2014 at 8:26 AM, Charles Hixson
<charleshixsn@earthlink.net> wrote:
> P.S.: Is it reasonable to return the items() of a dict in order to pass a
> read only copy of the values?
No, because it isn't a copy. At least, not in Python 3; if you're
using Python 2, then the wording of your subject line is inaccurate,
see above.
>>> d = {"a":1,"b":2,"c":3}
>>> i = d.items()
>>> del d["b"]
>>> list(i)
[('a', 1), ('c', 3)]
If you returned i from a function and expected it to be a copy, you'd
be in for a nasty shock. Try the .copy() method for a shallow copy, or
look up deepcopy if you need a recursive copy.
ChrisA
== 5 of 5 ==
Date: Sun, Jan 19 2014 3:22 pm
From: Terry Reedy
On 1/19/2014 4:41 PM, Mark Lawrence wrote:
> On 19/01/2014 21:26, Charles Hixson wrote:
>> Could it please be clearly documented that keys(), values(), and items()
>> are not writeable. I agree that this is how they should be, but it
>> would be still better if they were clearly documented as such. The
>> labeling of them as dynamic, while true, was a bit confusing here.
>> (I.e., it was talking about changing their value through other means of
>> access rather than directly through the returned values.)
>>
>> P.S.: Is it reasonable to return the items() of a dict in order to pass
>> a read only copy of the values?
>>
>
> Just raise an issue here http://bugs.python.org/
The relevant section is
4.10.1. Dictionary view objects¶
The objects returned by dict.keys(), dict.values() and dict.items() are
view objects.
The 'view object' are implicitly 'read-only' because no syntax is given
to write to them, but ahead and propose adding 'read-only' to make the
above explicitly say "read-only view objects".
--
Terry Jan Reedy
==============================================================================
TOPIC: How to write this as a list comprehension?
http://groups.google.com/group/comp.lang.python/t/0b63055a0d321622?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 19 2014 2:06 pm
From: Piet van Oostrum
John Allsup <pydev@allsup.co> writes:
> Hi,
>
> I'd agree with the advice that it's not the best idea: readability sucks
> here, but consider the following:
>
>
> import time
>
> def somefunc(a,b,c,d): # dummy function
> return "{} - {} - {} : {}".format(a,b,c,d)
> l = [(time.time(),"name {}".format(n)) for n in range(100)] # dummy data
>
> # the line in question
> labels = [somefunc(*(lambda t,n:
> (t.tm_mon,t.tm_mday,t.tm_wday,n))(time.localtime(x[0]),x[1])) for x in
> l]
>
>
> print(labels) # just to see the result
>
>
> If you find that hard to decipher, the consider the maintainability of
> code you write that uses such comprehensions. You need to include
> comments that explain what this does, and it is easier to write a
> longhand version using .append() and variable assignments. I presume
> performance won't be an issue determining the right approach, since then
> you'd be using C or C++.
I'll stay with
labels = [somefunc(mn, day, wd, name)
for then, name in mylist
for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]
where (sic!) the last part means as much as
where _, mn, dy, _, _, _, wd, _, _ = localtime(then)
I find the list comprehension preferable because it makes it more clear
that a new list is constructed from an existing list, something that is
not as immediately clear with the append construction.
--
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
==============================================================================
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