[BangPypers] Life lessons shared by Jesse Noller

2015-10-29 Thread Abdul Muneer
Hi,
Jesse Noller talks about the turn of events in his life since last couple
of years : http://jessenoller.com/blog/2015/9/27/a-lot-happens.
Valuable lessons for everyone.
Regards,
Abdul Muneer

--
Twitter: @abdulmuneer <http://twitter.com/#%21/abdulmuneer>
___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] List of n but same objects

2014-12-11 Thread Abdul Muneer
Hi Rajiv,
Premise 1:
Every time you *create* an object, it has a new id. Examples:
 a = list ()
 b = list()
 id(a), id(b)
(140688241027768, 140688241027840)

 p = dict()
 q = dict()
 id(p), id(q)
(140688241071280, 140688241071560)

 x = iter(range(10))
 y = iter(range(10))
 id(x), id(y)
(140688241024208, 140688241024272)


Premise 2:
Every time you associate the same object to multiple names, they all will
point to same object. Examples:
 a = list()
 b = a
 id(a), id(b)
(140688241028200, 140688241028200)
 p = dict()
 q = p
 id(p), id(q)
(140688241071840, 140688241071840)
 x = iter(range(10))
 y = x
 id(x), id(y)
(140688241024464, 140688241024464)


In your problem, Case 1 and Case 3 follow the pattern [an_object]*3 which
results in [an_object, an_object, an_object] where as Case 2 follows the
pattern [create_object(), create_object(), create_object()]
Note that in Case 3, iter(x) is evaluated before multiplying.

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer

On Thu, Dec 11, 2014 at 4:21 PM, Rajiv Subramanian M rajiv.m1...@gmail.com
wrote:

 Hi Shreyas,

 Thanks for your answer.
 For the questions numered 2 and 3 do you have any thoughts?

 2. Is there any other possibility or way (like * operator does here) by
 which we can obtain the same result as in CASE 1?
 3. Does only list and listiterators objects can behave this way? what other
 python datatypes can behave this way?



 On Thu, Dec 11, 2014 at 4:14 PM, Kulkarni, Shreyas shy...@gmail.com
 wrote:

  When you call iter(x) it returns you a listiterator object. Every time
 you
  call iter(x) it *creates* a new listiterator and returns it back. The
  differences you are seeing in your cases are not because of how lists of
  list operators work, but because of how they are called.
 
  In case-1, iter(x) gets called once, and the same returned object is used
  when you do '* 3' on the list.
  In case-2, you are calling iter(x) three times, so naturally you get 3
  different iterators - three different objects with different base
 addresses
  in memory.
 
  Case-3 is how python typically works - when you do an assignment, python
  doesn't create a copy, but a reference. So when you say y = [x] * 3; y is
  essentially a list with 3 references to the same memory location pointed
 to
  by x. So when you update one value, all three refs point to the same
  location, and hence you are seeing what you are seeing.
  If you want deep copy instead of shallow one with references, take a look
  at 'copy' module and copy.deepcopy method in particular.
 
  shreyas
 
 
  On Dec 11, 2014, at 3:58 PM, Rajiv Subramanian M rajiv.m1...@gmail.com
  wrote:
 
   Hello Group,
  
   I am Rajiv, Python/Django developer in a startup, Bangalore. Today
 when I
   experimenting with python I came across the following
  
   CASE 1:
  
   x = range(10)
  
   [iter(x)] * 3
  
   [listiterator object at 0x7f6aa5594850,
  
   listiterator object at 0x7f6aa5594850,
  
   listiterator object at 0x7f6aa5594850]
  
  
   Thing to Note:
  
   Here all the 3 listiterator object in the list is actually a same
 single
   instance residing at the memory location 0x7f6aa5594850
  
  
   CASE 2:
  
   [iter(x), iter(x), iter(x)]
  
   [listiterator object at 0x7f6aa5594890,
  
   listiterator object at 0x7f6aa55948d0,
  
   listiterator object at 0x7f6aa5594910]
  
  
   Thing to Note:
   In this case literally I created called the iter(x) for 3 times so it
   created 3 different listiterator object.
  
   CASE 3:
   x = [1, 2, 3]
   y = [x] * 3
   y
   [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
   y[0][0] = 5
   y
   [[5, 2, 3], [5, 2, 3], [5, 2, 3]]
   x
   [5, 2, 3]
  
   Things to Note:
   As like in first case, here the list objects inside the list y are not
  the
   duplicates of x but the x itself
  
  
   Question:
   1. How in the first case i.e   [iter(x)] * 3  creates a list of 3 but
 the
   same objects?
   2. Is there any other possibility or way (like * operator does here) by
   which we can obtain the same result as in CASE 1?
   3. Does only list and listiterators objects can behave this way? what
  other
   python datatypes can behave this way?
  
   ~ Regards
   Rajiv M
   ___
   BangPypers mailing list
   BangPypers@python.org
   https://mail.python.org/mailman/listinfo/bangpypers
 
  ___
  BangPypers mailing list
  BangPypers@python.org
  https://mail.python.org/mailman/listinfo/bangpypers
 



 --

   [image: --]
 Rajiv Subramanian M
 [image: http://]about.me/rajiv.m1991
  http://about.me/rajiv.m1991?promo=email_sig
 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Moving from python 2.6 to 2.7

2014-10-07 Thread Abdul Muneer
Hi,
As far as I know, nothing written in python should break. If you are
upgrading OS too, then you should be watchful as some of the c libraries
can introduce version conflicts.
We had faced such a problem with pyactivemq at our office. Pyactivemq
depends on activemq-cpp library which in turn depends on a few system
libraries. The problem was that the development of pyactivemq stagnated
while activemq-cpp moved on the version checks caused conflicts. If I used
a version of activemq-cpp that satisfies pyactivemq, activemq-cpp had
problems with system libraries as they too had moved on to newer versions.
IIRC, I solved it by changing the regex that looks for the versions.
Regards,
Abdul Muneer

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer

On Tue, Oct 7, 2014 at 3:53 PM, Kulkarni, Shreyas shy...@gmail.com wrote:

 Hi guys,

 We are planning to move our production environment from 2.6 to 2.7 on one
 of the projects. While I understand it's not a significant upgrade, this
 being a production environment, I was wondering what aspects of 2.6 might
 break under 2.7 and what I should be watching out for. I tried searching
 about it, but didn't hit anything useful.

 Anyone here has any suggestions, or has experienced any difficulties after
 bumping the version to 2.7?

 Thanks in advance.


 shreyas
 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Need help Extracting data properly in python

2014-02-20 Thread Abdul Muneer
There is an old python package which does it neatly
http://www.astro.rug.nl/~breddels/python/tableio.html

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Wed, Feb 19, 2014 at 5:59 PM, Kulkarni, Shreyas shy...@gmail.com wrote:

 if this is a valid tab-seperated file, you could try parsing it using csv
 module with dialect set to '\t' or 'excel-tab' maybe?

 shreyas

 On Feb 19, 2014, at 5:43 PM, kamalakar06 . foxrun2...@gmail.com wrote:

  I have a file like this(Tabular data) :
 
  0 1   CEN/4 1.e33.000e3 4.000e-3
   1.000e-3 3.000e3 5.000e3
 
   112.000e3  3.000e4 6.000e3
1.000e4  1.000e4 1.000e5
 
12   1.00e4 1.000e5  1.000e6
 2.00e42.000e5  1.000e4
 
  0 2  CEN/41.e33.000e3  4.000e-3
 1.000e-3 3.000e3  5.000e3
 
  41   2.000e3  3.000e4 6.000e3
  1.000e4  1.000e41.000e5
 
   50  1.00e4 1.000e5  1.000e6
  2.00e4 2.000e5  1.000e4
 
 
 
  I want to extract the data column wise. How do i do that
 
  My code is like this :
 
  import os
 
  f1=open('newdata1.txt','w')
  L = []
  for index, line in enumerate(open('Trial_1.txt','r')):
 #print index
 if index  0: #skip first 5 lines
 continue
 else:
 line =line.split()
 L.append('%s\t%s\t %s\t %s\t%s\n' %(line[0],
  line[1],line[2],line[3],line[4]))
 
 
  f1.writelines(L)
 
  f1.close()
 
 
 
  Output looks like this:
 
  0 1   CEN/4 1.e33.000e3
  1.000e-3 3.000e3 5.000e3
 
 
  Now the code is not extracting the column data properly,since there is
 tab
  space after first line . How to give tab space in python wherever space
 is
  there to extract the data properly.Where to modify my code.
  ___
  BangPypers mailing list
  BangPypers@python.org
  https://mail.python.org/mailman/listinfo/bangpypers

 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Issue with list comprehension

2013-11-07 Thread Abdul Muneer
Hi,
_sum=sum([n for n in itertools.takewhile(lambda x: x  400, fib)])
TypeError: 'int' object is not callable

Probably 'sum' might have been used earlier in the code to store the value
of some integer. sum is a builtin function but the moment you assign
sum=(x+y) or something, you have lost that function. If you are doubtful,
do `from __builtin__ import * ` to reclaim your builtin variables and
functions.

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Thu, Oct 31, 2013 at 12:22 PM, Asokan Pichai paso...@gmail.com wrote:

 import itertools

 def fib():
   a, b = 0, 1
   while True:
   yield b
   a, b = b, a+b

 print sum(itertools.takewhile(lambda x: x  400, fib))
 ---
 I tried the above; and it worked too (986)

 Asokan Pichai
 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Do you pin your requirements.txt ?

2013-09-12 Thread Abdul Muneer
I also pin requirements. But when I do 'pip freeze', I remove the packages
that are installed as a dependency to main libraries which were explicitly
installed.

Packages from pypi may specify dependency as = and it will fetch the
latest. But if you had pinned those too, it can cause conflicts especially
if you upgrade the main component. Had run into issues because of this
while working on a pylons project.

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Thu, Sep 12, 2013 at 6:16 PM, Aditya Laghate adi...@thinrhino.net.inwrote:

 On Thu, Sep 12, 2013 at 05:50:27PM +0530, Vineet Naik wrote:
  I always pin requirements. Here is a related article on the topic -
  http://nvie.com/posts/pin-your-packages/

 Interesting blog link.

 I did like the idea of using '==' instead of '='
 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] https://github.com/pythonhacker/ladies.py

2013-09-08 Thread Abdul Muneer
+1

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Sun, Sep 8, 2013 at 11:52 AM, T S KAMATH tsk.kam...@gmail.com wrote:

 Hi..

 Its was in bad taste and treated as such, proper apology demanded and
 given.. hence we hope all the concerned party rest this.. or take it up in
 private.

 ..a full apology from Anand is  on the maillist, posted at 9:50AM 8 Sep
 2013.

 rgds
 Srikanth

 On 08-Sep-2013, at 11:15 AM, Pratham Gadre pratham.ga...@gmail.com
 wrote:

 Audrey,

 We would like to hear your thoughts on the antics pulled by Anand Pillai
 (member of PSF).

 ref:
 https://mail.python.org/pipermail/bangpypers/2013-September/thread.html
 Mails with the subject : https://github.com/pythonhacker/ladies.py

 Most of us, don't like the way he is hiding behind his style of sarcastic
 humor, but for
 fear of being called an outcast from the community, we don't have the guts
 to come out
 in the open.

 Being a member / moderator / owner of various e-groups (tech  non-tech) in
 India,
 I know very well, how quickly one can become an outcast for speaking out.
 Especially,
 against somebody popular like Anand.

 I would personally, recommend, that a proper warning be served to Anand for
 his
 misconduct.

 I sincerely hope that Anand is given his due for his uncalled and
 unwarranted 'sarcastic humor'.

 I am taking the trouble to escalate this issue, since Anand is a member of
 PSF and President of
 Indian Python Software Society. People with attitude like his should not be
 allowed to hold such
 posts.

 Regards
 Pratham

 PS: If somebody has cloned the code repository by Anand, please share the
 code with pyladies.
 If you don't want to get entangled in this mess, email the code to me, I
 will guarantee your anonymity.

 Anand, in the meanwhile please read :
 http://www.pyladies.com/CodeOfConduct/


 On Sat, Sep 7, 2013 at 9:03 PM, Daniel Greenfeld pyda...@gmail.com
 wrote:

  As a PSF member I'm going to delurk right now. That's because as an
  admirer/supporter of the India Python community, I'm rather shocked and
  saddened by this thread.
 
  Angry. Furious. Demanding of real apologies.
 
  Svashka is standing up for what's right. I'm behind what she says 100%.
 
 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] https://github.com/pythonhacker/ladies.py

2013-09-08 Thread Abdul Muneer
Ouch, there was mail that came just before i hit send. I +1-ed what Mr.
Kamath said.

Its was in bad taste and treated as such, proper apology demanded and
given.. hence we hope all the concerned party rest this.. or take it up in
private.

It might be a politically incorrect thing for person holding a position to
resort to humor (because it may not be humor for ALL audience). But I do
not consider that as damaging as blowing it out of proportion. Let's not
linger on the negativity for too long as it is toxic.
Please cheer up, dear folks. Hug each other..
Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Sun, Sep 8, 2013 at 12:18 PM, Abdul Muneer abdulmun...@gmail.com wrote:

 +1

 Regards,
 Abdul Muneer

 --
 Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


 On Sun, Sep 8, 2013 at 11:52 AM, T S KAMATH tsk.kam...@gmail.com wrote:

 Hi..

 Its was in bad taste and treated as such, proper apology demanded and
 given.. hence we hope all the concerned party rest this.. or take it up in
 private.

 ..a full apology from Anand is  on the maillist, posted at 9:50AM 8 Sep
 2013.

 rgds
 Srikanth

 On 08-Sep-2013, at 11:15 AM, Pratham Gadre pratham.ga...@gmail.com
 wrote:

 Audrey,

 We would like to hear your thoughts on the antics pulled by Anand Pillai
 (member of PSF).

 ref:
 https://mail.python.org/pipermail/bangpypers/2013-September/thread.html
 Mails with the subject : https://github.com/pythonhacker/ladies.py

 Most of us, don't like the way he is hiding behind his style of sarcastic
 humor, but for
 fear of being called an outcast from the community, we don't have the guts
 to come out
 in the open.

 Being a member / moderator / owner of various e-groups (tech  non-tech)
 in
 India,
 I know very well, how quickly one can become an outcast for speaking out.
 Especially,
 against somebody popular like Anand.

 I would personally, recommend, that a proper warning be served to Anand
 for
 his
 misconduct.

 I sincerely hope that Anand is given his due for his uncalled and
 unwarranted 'sarcastic humor'.

 I am taking the trouble to escalate this issue, since Anand is a member of
 PSF and President of
 Indian Python Software Society. People with attitude like his should not
 be
 allowed to hold such
 posts.

 Regards
 Pratham

 PS: If somebody has cloned the code repository by Anand, please share the
 code with pyladies.
 If you don't want to get entangled in this mess, email the code to me, I
 will guarantee your anonymity.

 Anand, in the meanwhile please read :
 http://www.pyladies.com/CodeOfConduct/


 On Sat, Sep 7, 2013 at 9:03 PM, Daniel Greenfeld pyda...@gmail.com
 wrote:

  As a PSF member I'm going to delurk right now. That's because as an
  admirer/supporter of the India Python community, I'm rather shocked and
  saddened by this thread.
 
  Angry. Furious. Demanding of real apologies.
 
  Svashka is standing up for what's right. I'm behind what she says 100%.
 
 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers

 ___
 BangPypers mailing list
 BangPypers@python.org
 https://mail.python.org/mailman/listinfo/bangpypers



___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] problem with python classes

2013-05-09 Thread Abdul Muneer
Hi,

If it is necessary that the calculation has to be performed by ClassOne,
use a classmethod.

class ClassOne(object):
def __init__(self, value):
self.value = value

@classmethod
def calculate_value(cls, value):
do something
return new_value

and in ClassTwo, change the relevant line to this one.

self.values.append(ClassOne.calculate_value(inputvalues))



Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Thu, May 9, 2013 at 9:11 PM, hiharry danny hrd...@gmail.com wrote:

 i have python 2.7.4..now suppose i have two new-style base classes ,
 i.e. class ClassName(object):
 and the two base classes are related by __init__ constructor where the
 __init__ constructor of one base class is accessed by the __init property
 of the other base class , for example :

 class ClassOne(object):
 def __init__(self,value):
   self.value = value

 class ClassTwo(object):
  def __init__(self,inputvalues):
 self.values = []
  for i in inputvalues:
  self.values.append(ClassOne(inputvalues))

 if this be the case , then without using inheritance property of OOP ,i,e,
 without creating further new subclasses , how can I access other user
 defined methods of ClassOne class via Class Two class. The ouput value will
 be returned by a user defined method of ClassTwo but the computation will
 be done by a method of ClassOne which is called by the user defined method
 of class two ...?

 so what will be the solution ?
 ___
 BangPypers mailing list
 BangPypers@python.org
 http://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Need help for python coding

2013-04-18 Thread Abdul Muneer
Hi Kamalakar,
You can use os.path.join() to join the user input to a base path. Python
will take care of unix/windows differentiation and append slashes
accordingly.

 import os
 base_path = os.getcwd()
 base_path
'/home/amuneer/workspace/playground'
 file_name = raw_input(Enter Filename\n)
Enter Filename
play
 complete_path = os.path.join(base_path, file_name)
 complete_path
'/home/amuneer/workspace/playground/play'



Note:if you are not using python3, use raw_input instead of input.
raw_input accepts the values as string and therefore people cannot do nasty
things by typing executable code.


Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Thu, Apr 18, 2013 at 6:15 PM, Kamalakar gs foxrun2...@gmail.com wrote:

 HI all,
 I have a query that i have doc which is  read through python.But instead of
 giving path and filename
 in the coding.I want to manipulate it like python has to ask USER for a
 specific filename so that python recognizes the directory internally and
 read the file .How do i do this.I have tried with
 filename = input (filename) but it just file name and will not recognises
 the path.

 For example:

 file name = input (file name: )

  file name = python

 it has to recognizes the path likeC:\users\desktop\python


 Thanks
 Regards
 Kamalakar
 ___
 BangPypers mailing list
 BangPypers@python.org
 http://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Reorder Dictionary Size in python

2013-04-17 Thread Abdul Muneer
Expecting this behaviour from built-in dict is not a good idea. However try
if garbage collection helps.
 import gc
 gc.collect()
I have not tried it out myself, though.

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Thu, Apr 18, 2013 at 5:53 AM, Anand Chitipothu anandol...@gmail.comwrote:

 On Wed, Apr 17, 2013 at 9:30 PM, Rahul R rahul8...@gmail.com wrote:

  As far as i know, python performs a lazy deletion of values , when we
  delete content from a dictionary (correct me if i am wrong) .  So, when
 we
  insert a lot of values the dictionary automatically expands. I don't see
  dict shrinking when we delete values from dictionary. In such case, is
  there a way to forcibly reduce the dictionary size ?
 

 Don't try to optimize something that is not required. Python core
 developers are smarted than you, trust them.

 Premature optimization is root cause of all evil.

 Anand
 ___
 BangPypers mailing list
 BangPypers@python.org
 http://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


[BangPypers] The FSF awards Fernando Perez, the creator of IPython

2013-03-25 Thread Abdul Muneer
Hi,
From fsf.org:

The Award for the Advancement of Free Software is given annually to an
individual who has made a great contribution to the progress and
development of free software, through activities that accord with the
spirit of free software.

This year, it was given to Dr. Fernando Perez, the creator of IPython.
IPython provides a rich architecture for interactive computing with a
debugger, editor, and python command-line interpreter all in one.

https://www.fsf.org/news/2012-free-software-award-winners-announced-2

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] wierd class behavior

2013-01-12 Thread Abdul Muneer
Thank you Anand for bringing up this thought provoking question!
Regardless of the possible explanations, it has to be said that this
behaviour is indeed confusing. This will conflict with the general idea of
LEGB scoping order (i.e. Local, Enclosing Function local, Global,
Built-in). The functions f and g apparently show conflicting behavior in
the way variables x and y are treated respectively.

To summarize the confusions:

   1. in *f*, print(x) statement under class definition causes an
   exception. Shouldn't it have accepted the *x* that was declared in its
   Enclosing function?
2. If we accept that as the default behaviour, why on earth is the *gety
   * function inside *g* returning value 1 instead of 2? (It would have
   returned 1 regardless of its class had a statement like 'y=1'!)

The following might explain this:

The original variable '*y*' in function *g* and the '*y*' inside
*gety*function are the same object! But the '
*y*' in the class Foo local is different. You can check it this way:

def g():
y = 1
*print 'id(y) originally in g:', id(y)*
class Foo():
y = 2
*print 'id(y) in class Foo:', id(y)*
def gety(self):
*print 'id(y) in function gety inside Foo:', id(y)*
return y
foo = Foo()
print (y, foo, foo.gety())

But why??
*
*
*The x in function f and y in function g, though may look identical to us,
are stored differently by python! *This can be seen from the disassembly of
both functions:

 dis(f)
  2   0 LOAD_CONST   1 (1)
  3 STORE_FAST   0 (x)

  3   6 LOAD_CONST   2 ('Foo')
  9 LOAD_CONST   4 (())
 12 LOAD_CONST   3 (code object Foo at
0x101102bb0, file class_check.py, line 3)
 15 MAKE_FUNCTION0
 18 CALL_FUNCTION0
 21 BUILD_CLASS
 22 STORE_FAST   1 (Foo)

  7  25 LOAD_FAST0 (x)
 28 LOAD_FAST1 (Foo)
 31 LOAD_ATTR0 (x)
 34 BUILD_TUPLE  2
 37 PRINT_ITEM
 38 PRINT_NEWLINE
 39 LOAD_CONST   0 (None)
 42 RETURN_VALUE



 dis(g)
 10   0 LOAD_CONST   1 (1)
  3 STORE_DEREF  0 (y)

 11   6 LOAD_CONST   2 ('Foo')
  9 LOAD_CONST   4 (())
 12 LOAD_CLOSURE 0 (y)
 15 BUILD_TUPLE  1
 18 LOAD_CONST   3 (code object Foo at
0x101102d30, file class_check.py, line 11)
 21 MAKE_CLOSURE 0
 24 CALL_FUNCTION0
 27 BUILD_CLASS
 28 STORE_FAST   0 (Foo)

 15  31 LOAD_FAST0 (Foo)
 34 CALL_FUNCTION0
 37 STORE_FAST   1 (foo)

 16  40 LOAD_DEREF   0 (y)
 43 LOAD_FAST1 (foo)
 46 LOAD_ATTR0 (y)
 49 LOAD_FAST1 (foo)
 52 LOAD_ATTR1 (gety)
 55 CALL_FUNCTION0
 58 BUILD_TUPLE  3
 61 PRINT_ITEM
 62 PRINT_NEWLINE
 63 LOAD_CONST   0 (None)
 66 RETURN_VALUE

It can be noticed that x is stored as STORE_FAST while y is stored as
STORE_DEREF.

The excellent 'Python Innards series' (which I can understand only very
little) explains this  in one of the articles
http://tech.blog.aknin.name/2010/06/05/pythons-innards-naming/ :

The secret sauce here is that at compilation time, if a variable is seen
to be resolved from a lexically nested function, it will not be stored and
will not be accessed using the regular naming opcodes. Instead, a special
object called a
cellhttp://docs.python.org/py3k/c-api/cell.html#cell-objectsis
created to store the value of the object. When various code objects
(the
outer function, the inner function, etc) will access this variable, the use
of the *_DEREF opcodes will cause the cell to be accessed rather than the
namespace of the accessing code object.

additional reference: Python Closure:
Link1http://ynniv.com/blog/2007/08/closures-in-python.html
Link2 http://www.shutupandship.com/2012/01/python-closures-explained.html,


Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer http://twitter.com/#%21/abdulmuneer


On Tue, Dec 4, 2012 at 4:26 PM, steve st...@lonetwin.net wrote:

 On Tuesday 04 December 2012 09:24 AM, Anand Chitipothu wrote:

 Python scoping rules when it comes to classes are so confusing.

 Can you guess what would be output of the following program?

 x = 1

 class Foo:
  print(x)


 Prints the global x


   x = x + 1
  print(x)

 Prints

Re: [BangPypers] Looking for Guest Speaker on Python and NLTK

2011-10-11 Thread Abdul Muneer
Hi,
Some course from stanford on ml and ai.
ml-class.org
ai-class.org

Join last date is already gone, but my friends are able to join even now..
Regards,
Abdul Muneer

--
Whom I'm Lookin' for is The One who sees!!


On Tue, Oct 11, 2011 at 4:42 PM, s|s supr.e.etse...@gmail.com wrote:

 I would have loved to conduct the session. Unfortunately, I am in
 Delhi and also I am conducting a session on databases on 22nd. I am
 sending some important links in this context.


 http://pypi.python.org/pypi/Fuzzy
 http://pypi.python.org/pypi/python-Levenshtein/
 http://www.nltk.org/

 http://streamhacker.com/2010/05/10/text-classification-sentiment-analysis-naive-bayes-classifier/
 http://nlp.lsi.upc.edu/freeling/
 https://github.com/djinn/freeling-python

 As criticism of NLP

 http://teddziuba.com/2008/11/avoiding-nlp-at-all-costs.html


 Hope you guys have a great session.







 --
 Supreet Sethi

 Ph IN: +919811143517
 Ph Skype: d_j_i_n_n
 Profile: http://www.google.com/profiles/supreet.sethi
 Twt: http://twitter.com/djinn
 ___
 BangPypers mailing list
 BangPypers@python.org
 http://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers