IndexError: list index out of range

2016-12-12 Thread Elnaz
hi i am begginer in python. I have written a code and given this error: IndexError: list index out of range In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block and every 8-block is n. so n=0:7;(h=int(n/4)) I want to rotate 0 to 7 bits for 2 bits: 0,1,2,3,4,5,6,7--->2,3,4,5,6

Nested functions, how do they work (stack related)

2016-12-12 Thread Veek M
I was reading the wiki on 'Call stack' because I wanted to understand what a traceback object was. My C/C++ isn't good enough to deal with raw python source since I have no background in CS. Also, you just can't dive into the python src - it takes a good deal of reading and background.. (the ty

Re: Method to know if object support being weakreferenced ?

2016-12-12 Thread Gregory Ewing
Matthias Bussonnier wrote: I search for a method capable of telling me whether an object can be weakreferenced. Objects that can be weakly referenced have a __weakref__ attribute. So you could use hasattr(obj, '__weakref__'). -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Gregory Ewing
Ned Batchelder wrote: if a C++ constructor raises an exception, will the corresponding destructor be run, or not? (No, because it never finished making an object of type T.) So it just leaks any memory that's been allocated by the partially-run constructor? -- Greg -- https://mail.python.org/m

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Chris Angelico
On Tue, Dec 13, 2016 at 4:45 PM, Steven D'Aprano wrote: > I don't understand the point of bringing up Javascript. Ben has already said > that we shouldn't feel the need to mindlessly copy C++ terminology. Is it your > position that we *should* copy Javascript terminology? Why Javascript and not >

Re: Method to know if object support being weakreferenced ?

2016-12-12 Thread Steven D'Aprano
On Tuesday 13 December 2016 15:57, Matthias Bussonnier wrote: [...] > I could of course write a function that try/except and return False/True > depending on the result, but that seem suboptimal as how can I know that the > TypeError does come from not being able to take a weak reference ? And not

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Steven D'Aprano
On Tuesday 13 December 2016 10:23, Chris Angelico wrote: > On Tue, Dec 13, 2016 at 10:17 AM, Ben Finney > wrote: >> If the differences didn't matter I would agree that “overly pedantic” is >> fair. But those differences trip up newcomers. Thinking of >> ‘Foo.__init__’ leads people to wonder where

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Steven D'Aprano
On Tuesday 13 December 2016 12:12, Ned Batchelder wrote: > On Monday, December 12, 2016 at 6:17:43 PM UTC-5, Ben Finney wrote: >> Ned Batchelder writes: >> >> > Claiming that __init__ isn't a constructor seems overly pedantic to >> > me. >> >> Whereas to me, claiming that ‘Foo.__init__’ is a co

Method to know if object support being weakreferenced ?

2016-12-12 Thread Matthias Bussonnier
Hi all, I was recently had to use weakreferences, using the weakref module, and came across the fact that some object cannot be weakreferenced. If you try to do so you get greated by a TypeError, which is a totally expected and documented behavior. As I tend to prefer the "Look before you le

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Ned Batchelder
On Monday, December 12, 2016 at 6:17:43 PM UTC-5, Ben Finney wrote: > Ned Batchelder writes: > > > Claiming that __init__ isn't a constructor seems overly pedantic to > > me. > > Whereas to me, claiming that ‘Foo.__init__’ is a constructor seems > needlessly confusing. > ... > * A constructor s

Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify (was: The right way to 'call' a class attribute inside the same class)

2016-12-12 Thread Juan C.
I agree with you, I'll post here the same thing I said in there for another member: On Mon, Dec 12, 2016 at 6:59 PM, Thomas 'PointedEars' Lahn wrote: > > Using the Python official doc link you provided, it cl

Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify (was: The right way to 'call' a class attribute inside the same class)

2016-12-12 Thread Ben Finney
Chris Angelico writes: > On Tue, Dec 13, 2016 at 10:17 AM, Ben Finney > wrote: > > If the differences didn't matter I would agree that “overly > > pedantic” is fair. But those differences trip up newcomers. Thinking > > of ‘Foo.__init__’ leads people to wonder where the ‘self’ attribute > > cam

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Chris Angelico
On Tue, Dec 13, 2016 at 10:17 AM, Ben Finney wrote: > If the differences didn't matter I would agree that “overly pedantic” is > fair. But those differences trip up newcomers. Thinking of > ‘Foo.__init__’ leads people to wonder where the ‘self’ attribute came > from – am I not meant to be construc

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Ben Finney
Ned Batchelder writes: > Claiming that __init__ isn't a constructor seems overly pedantic to > me. Whereas to me, claiming that ‘Foo.__init__’ is a constructor seems needlessly confusing. * Classes already have a constructor, ‘Foo.__new__’. If we call something else the constructor, what do w

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Steve D'Aprano
On Tue, 13 Dec 2016 07:15 am, Ned Batchelder wrote: > Claiming that __init__ isn't a constructor seems overly pedantic to me. > What's true is that Python's constructors (__init__) are different than > C++ constructors. In C++, you don't have an object of type T until the > constructor has finish

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Juan C.
On Mon, Dec 12, 2016 at 6:59 PM, Thomas 'PointedEars' Lahn wrote: > Using the Python official doc link you provided, it clearly states that `__new__` is the one called to "create a new instance of class [...]

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Ned Batchelder
On Monday, December 12, 2016 at 4:31:00 PM UTC-5, Gregory Ewing wrote: > Ned Batchelder wrote: > > In C++, you don't have an object of type T until the > > constructor has finished. In Python, you have an object of type T before > > __init__ has been entered. > > That distinction seems a bit pedan

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Steve D'Aprano
On Tue, 13 Dec 2016 03:17 am, Chris Angelico wrote: > You could check "foo" in self.__dict__, but I don't know of any > real-world situations where you need to. vars(self) is probably the better way to access self's namespace, rather than directly self.__dict__. Unfortunately vars() doesn't under

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Gregory Ewing
Ned Batchelder wrote: In C++, you don't have an object of type T until the constructor has finished. In Python, you have an object of type T before __init__ has been entered. That distinction seems a bit pedantic as well. Inside a C++ constructor you have access to something having all the fiel

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Thomas 'PointedEars' Lahn
Juan C. wrote: > On Mon, Dec 12, 2016 at 12:34 PM, Thomas 'PointedEars' Lahn > wrote: >> To call something means generally in programming, and in Python, to >> execute it as a function instead: In the code above, the class object >> referred to by “Box” is called twice in order to instantiate twi

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Ned Batchelder
On Monday, December 12, 2016 at 12:58:30 PM UTC-5, Juan C. wrote: > Since we are talking about Python terminology I believe that calling > `__init__` a constructor is also wrong. I've already seem some > discussions regarding it and the general consensus is that `__init__` > shouldn't be called con

Re: SIP install error on windows

2016-12-12 Thread Phil Thompson
On 12 Dec 2016, at 7:29 pm, Xristos Xristoou wrote: > > > hello i want to install sip on windows bit using python > 32 bit. > i download sip from this link https://www.riverbankcomputing.com > i try to install from cmd line : > > C:\WINDOWS\system32>cd C:\Users\username\Desktop\sip-4.17 > > C

Re: SIP install error on windows

2016-12-12 Thread Xristos Xristoou
Τη Δευτέρα, 12 Δεκεμβρίου 2016 - 9:29:38 μ.μ. UTC+2, ο χρήστης Xristos Xristoou έγραψε: > hello i want to install sip on windows bit using python > 32 bit. > i download sip from this link https://www.riverbankcomputing.com > i try to install from cmd line : > > C:\WINDOWS\system32>cd C:\Users\u

Re: SIP install error on windows

2016-12-12 Thread Phil Thompson
On 12 Dec 2016, at 7:38 pm, Bob Gailer wrote: > > On Dec 12, 2016 2:30 PM, "Xristos Xristoou" wrote: >> >> >> hello i want to install sip on windows bit using python >> 32 bit. >> i download sip from this link https://www.riverbankcomputing.com >> i try to install from cmd line : >> >> C:\WIN

Re: SIP install error on windows

2016-12-12 Thread Bob Gailer
On Dec 12, 2016 2:30 PM, "Xristos Xristoou" wrote: > > > hello i want to install sip on windows bit using python > 32 bit. > i download sip from this link https://www.riverbankcomputing.com > i try to install from cmd line : > > C:\WINDOWS\system32>cd C:\Users\username\Desktop\sip-4.17 > > C:\Use

SIP install error on windows

2016-12-12 Thread Xristos Xristoou
hello i want to install sip on windows bit using python 32 bit. i download sip from this link https://www.riverbankcomputing.com i try to install from cmd line : C:\WINDOWS\system32>cd C:\Users\username\Desktop\sip-4.17 C:\Users\username\Desktop\sip-4.17>python configure.py install and take th

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread John Gordon
In "Juan C." writes: > The instructor said that the right way to call a class attribute is to use > 'Class.class_attr' notation, but on the web I found examples where people > used 'self.class_attr' to call class attributes. Class instances may override class attributes by creating local attri

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Juan C.
On Mon, Dec 12, 2016 at 12:34 PM, Thomas 'PointedEars' Lahn wrote: > First of all, the proper term for what you are doing there is _not_ “call”; > you are _accessing_ an attribute instead. Indeed, `accessing` seems better. I was looking for a better word but couldn't find at the moment. > To cal

Re: Django broken pipe error

2016-12-12 Thread justin walters
On Mon, Dec 12, 2016 at 7:27 AM, roma wrote: > Thanks Justin, > > I believe, the whole database story has no influence on the broken pipe > error. I've commented out the whole block and leave only return line: > return HttpResponse(res, content_type="text/plain; charset=utf-8") > The error is sti

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Juan C.
On Sun, Dec 11, 2016 at 11:34 PM, Steve D'Aprano wrote: > So... in summary: > > > When *assigning* to an attribute: > > - use `self.attribute = ...` when you want an instance attribute; > > - use `Class.attribute = ...` when you want a class attribute in > the same class regardless of which sub

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Chris Angelico
On Tue, Dec 13, 2016 at 1:34 AM, Thomas 'PointedEars' Lahn wrote: > ³ How can one tell the difference in Python between a pre-initialized, >inherited attribute value and one own that is just equal to the inherited >one? In ECMAScript, this.hasOwnProperty("foo") would return “false” if >

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Thomas 'PointedEars' Lahn
Thomas 'PointedEars' Lahn wrote: > Note that (AIUI) in this example the instances of the class referred by > “C” do not have an *own* “foo” property in the beginning, so until bar() > is called on them, they inherit that property (and its value) from that > class.³ For proper *Python* terminology

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Thomas 'PointedEars' Lahn
Juan C. wrote: > I'm watching a Python course and was presented a topic regarding classes. > One of the examples were: > > box.py > > class Box: > serial = 100 > > def __init__(self, from_addr, to_addr): > self.from_addr = from_addr > self.to_addr = to_addr > sel

Re: Django broken pipe error

2016-12-12 Thread roma
On Wednesday, December 7, 2016 at 6:15:41 PM UTC+1, justin walters wrote: > On Wed, Dec 7, 2016 at 1:08 AM, wrote: > > > Thank you Justin, > > > > I'm on the dev server and should present results in this way. > > > > Yes, I use manage.py runserver --insecure to start the server (from > > PyCharm)