Re: [Tutor] dictionary keys

2014-04-08 Thread Peter Otten
Alex Kleider wrote: > On 2014-04-08 14:34, Peter Otten wrote: > >> That's a change in Python 3 where dict.keys() no longer creates a list, >> but >> instead creates a view on the underlying dict data thus saving time and >> space. In the rare case where you actually need a list you can >> explici

Re: [Tutor] question about strip() and list comprehension

2014-04-08 Thread Danny Yoo
> > > if line.strip() > > Is that stripping the line of white space at the same time that it is > testing it? > > Two features about Python: 1. Strings are immutable, so the above is computing what a whitespace-stripped line would look like. So that means that 'line.strip()' is doing just a com

Re: [Tutor] dictionary keys

2014-04-08 Thread Alex Kleider
On 2014-04-08 14:34, Peter Otten wrote: That's a change in Python 3 where dict.keys() no longer creates a list, but instead creates a view on the underlying dict data thus saving time and space. In the rare case where you actually need a list you can explicitly create one with ips = list(ipD

Re: [Tutor] question about strip() and list comprehension

2014-04-08 Thread Steven D'Aprano
On Tue, Apr 08, 2014 at 02:38:13PM -0600, Jared Nielsen wrote: > Hello, > Could someone explain why and how this list comprehension with strip() > works? > > f = open('file.txt') > t = [t for t in f.readlines() if t.strip()] > f.close() > print "".join(t) > > I had a very long file of strings fil

Re: [Tutor] question about strip() and list comprehension

2014-04-08 Thread Ben Finney
Jared Nielsen writes: > I had a very long file of strings filled with blank lines I wanted to > remove. I did some Googling and found the above code snippet The code you found is one of several syntactic shortcuts in Python, which allow creating a sequence directly from an expression in your cod

Re: [Tutor] question about strip() and list comprehension

2014-04-08 Thread Walter Prins
Hi, On 8 April 2014 22:38, Jared Nielsen wrote: > Hello, > Could someone explain why and how this list comprehension with strip() > works? > > f = open('file.txt') > t = [t for t in f.readlines() if t.strip()] > f.close() > print "".join(t) > > I had a very long file of strings filled with blank

Re: [Tutor] question about strip() and list comprehension

2014-04-08 Thread Danny Yoo
> Could someone explain why and how this list comprehension with strip() > works? > > f = open('file.txt') > t = [t for t in f.readlines() if t.strip()] > f.close() > print "".join(t) Hi Jared, Let me rewrite this without the list comprehension, while preserving behavior. #

Re: [Tutor] dictionary keys

2014-04-08 Thread Peter Otten
Alex Kleider wrote: > I've got a fairly large script that uses a dictionary (called 'ipDic') > each > value of which is a dictionary which in turn also has values which are > not > simple types. > Instead of producing a simple list, > """ > ips = ipDic.keys() > print(ips) > """ > yields > """ > di

[Tutor] dictionary keys

2014-04-08 Thread Alex Kleider
I've got a fairly large script that uses a dictionary (called 'ipDic') each value of which is a dictionary which in turn also has values which are not simple types. Instead of producing a simple list, """ ips = ipDic.keys() print(ips) """ yields """ dict_keys(['61.147.107.120', '76.191.204.54',

[Tutor] question about strip() and list comprehension

2014-04-08 Thread Jared Nielsen
Hello, Could someone explain why and how this list comprehension with strip() works? f = open('file.txt') t = [t for t in f.readlines() if t.strip()] f.close() print "".join(t) I had a very long file of strings filled with blank lines I wanted to remove. I did some Googling and found the above co

Re: [Tutor] Block highlighters in python

2014-04-08 Thread Steven D'Aprano
On Tue, Apr 08, 2014 at 11:18:40AM +0530, Santosh Kumar wrote: > Is there a way by which we can highlight a block in the python ? > > i have a huge code and i want to see a block of ``if`` code. How do i > achieve this in VIM or any other editor. > > Note: In perl if i put my cursor on one "{" it

Re: [Tutor] Inheritance in classes

2014-04-08 Thread Steven D'Aprano
On Tue, Apr 08, 2014 at 11:14:36AM +0530, Santosh Kumar wrote: > Can i mask the parent attibutes in the child. let me give a quick example. > > In [1]: class a: >...: value1 = 1 >...: value2 = 2 >...: > > In [2]: class b(a): >...: value3 = 3 >...: All of value1, v

Re: [Tutor] Constructs

2014-04-08 Thread Steven D'Aprano
On Tue, Apr 08, 2014 at 11:10:57AM +0530, Santosh Kumar wrote: > 1 #!/usr/bin/python > 2 > 3 class shape: > 4 def __init__(self,x,y): > 5 self.x = x > 6 self.y = y > 7 description = "This shape has not been described yet" > 8 author = "Nobody has claimed to make this s

Re: [Tutor] Inheritance in classes

2014-04-08 Thread David Palao
2014-04-08 7:44 GMT+02:00 Santosh Kumar : > Can i mask the parent attibutes in the child. let me give a quick example. > > In [1]: class a: >...: value1 = 1 >...: value2 = 2 >...: > > In [2]: class b(a): >...: value3 = 3 >...: > > In [3]: obj1 = b() > > In [4]: obj1.

Re: [Tutor] Block highlighters in python

2014-04-08 Thread Alan Gauld
On 08/04/14 06:48, Santosh Kumar wrote: Is there a way by which we can highlight a block in the python ? i have a huge code and i want to see a block of ``if`` code. How do i achieve this in VIM or any other editor. Note: In perl if i put my cursor on one "{" it will hightlight the other closed

Re: [Tutor] Inheritance in classes

2014-04-08 Thread Alan Gauld
On 08/04/14 06:44, Santosh Kumar wrote: Can i mask the parent attibutes in the child. let me give a quick example. In [1]: class a: ...: value1 = 1 ...: value2 = 2 ...: In [2]: class b(a): ...: value3 = 3 ...: Note that these are class variables and not instan

Re: [Tutor] Constructs

2014-04-08 Thread Alan Gauld
On 08/04/14 06:40, Santosh Kumar wrote: 1 #!/usr/bin/python 2 3 class shape: 4 def __init__(self,x,y): 5 self.x = x 6 self.y = y 7 description = "This shape has not been described yet" 8 author = "Nobody has claimed to make this shape yet" 9 10 def __i