Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

attribute is accessed from Nonetype

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


shanthulinux at gmail

Aug 2, 2012, 3:28 AM

Post #1 of 9 (489 views)
Permalink
attribute is accessed from Nonetype

Hi ,All,
I am Shanthkumar. Good to see the mailing list for python programmers.
Please find my query below,

In my source code in a python file e.g xyz.py couple of classes are defined
also there is a wrapper class, a none object is declared in the file e.g
temp=None
from temp some attributes are being accessed in the files that are
importing xyz.py
even though temp is not initialised to any other object still it is none
object attributes are being accessed from None object.Is there any
significance of wrapper class here..?
Can you please help me.

--
Regards...,
Shanthkumara O.D.


d at davea

Aug 2, 2012, 4:04 AM

Post #2 of 9 (466 views)
Permalink
Re: attribute is accessed from Nonetype [In reply to]

On 08/02/2012 06:28 AM, Shanth Kumar wrote:
> Hi ,All,
> I am Shanthkumar. Good to see the mailing list for python programmers.

Welcome to the list.

> Please find my query below,
>
> In my source code in a python file e.g xyz.py couple of classes are defined
> also there is a wrapper class, a none object is declared in the file e.g
> temp=None
> from temp some attributes are being accessed in the files that are
> importing xyz.py
> even though temp is not initialised to any other object still it is none
> object attributes are being accessed from None object.Is there any
> significance of wrapper class here..?
> Can you please help me.
>
>
Once you actually supply some code. Build a small example illustrating
your problem, and explain better what is wrong/unexpected with how it
works. If an import of xyz.py is necessary, then show both files.

Are you surprised that the None object has attributes? It has at least
15 in Python 2.7. Or are you surprised that temp is different in other
modules than it is in xyz.py ? Or are you surprised that wrapping a
NoneType is possible?

Also, please use the names correctly and consistently. The None object
(yes, there is only one) is not the same as a none object. And there is
no standard type called Nonetype.

Finally, please avoid runon sentences. By the time we parse where the
periods are supposed to be, we just may lose the meaning you had in mind.



--

DaveA

--
http://mail.python.org/mailman/listinfo/python-list


ramit.prasad at jpmorgan

Aug 3, 2012, 12:01 AM

Post #3 of 9 (462 views)
Permalink
RE: attribute is accessed from Nonetype [In reply to]

> Also, please use the names correctly and consistently. The None object
> (yes, there is only one) is not the same as a none object. And there is
> no standard type called Nonetype.

To be fair, this is not very clear to a beginner.

>>> len(None) # Python 2.6
TypeError: object of type 'NoneType' has no len()


Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list


d at davea

Aug 3, 2012, 3:20 PM

Post #4 of 9 (460 views)
Permalink
Re: attribute is accessed from Nonetype [In reply to]

On 08/03/2012 03:01 AM, Prasad, Ramit wrote:
>> Also, please use the names correctly and consistently. The None object
>> (yes, there is only one) is not the same as a none object. And there is
>> no standard type called Nonetype.
> To be fair, this is not very clear to a beginner.
>
>>>> len(None) # Python 2.6
> TypeError: object of type 'NoneType' has no len()
>

I'm sorry, what's not clear? Nonetype is not the same as NoneType.
Python is case sensitive.


--

DaveA

--
http://mail.python.org/mailman/listinfo/python-list


rosuav at gmail

Aug 3, 2012, 3:41 PM

Post #5 of 9 (460 views)
Permalink
Re: attribute is accessed from Nonetype [In reply to]

On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel <d [at] davea> wrote:
> I'm sorry, what's not clear? Nonetype is not the same as NoneType.
> Python is case sensitive.

There isn't a NoneType either. I get a NameError.

ChrisA
--
http://mail.python.org/mailman/listinfo/python-list


d at davea

Aug 3, 2012, 4:03 PM

Post #6 of 9 (460 views)
Permalink
Re: attribute is accessed from Nonetype [In reply to]

On 08/03/2012 06:41 PM, Chris Angelico wrote:
> On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel <d [at] davea> wrote:
>> I'm sorry, what's not clear? Nonetype is not the same as NoneType.
>> Python is case sensitive.
> There isn't a NoneType either. I get a NameError.
>
> ChrisA

NoneType isn't in the builtin namespace. It's in the types module.

import types
a = types.Nonetype

It's still special, because None is a singleton. In any case there are
a number of places where the string "NoneType" is produced,

>>> type(None)
<type 'NoneType'>


>>> None + 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

>>> None[3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable

etc.

and it's in the docs, at least on page:
http://docs.python.org/library/constants.html

--

DaveA

--
http://mail.python.org/mailman/listinfo/python-list


steve+comp.lang.python at pearwood

Aug 3, 2012, 5:23 PM

Post #7 of 9 (461 views)
Permalink
Re: attribute is accessed from Nonetype [In reply to]

On Sat, 04 Aug 2012 08:41:20 +1000, Chris Angelico wrote:

> On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel <d [at] davea> wrote:
>> I'm sorry, what's not clear? Nonetype is not the same as NoneType.
>> Python is case sensitive.
>
> There isn't a NoneType either. I get a NameError.

Shame on you :-P

Ramit Prasad showed exactly how you can see NoneType in action in the
part of the post you snipped from your reply.

py> len(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'NoneType' has no len()


NoneType *is* a standard type. It's just not bound to a publicly
accessible name in the built-ins. But you can easily get access to the
class using either:

type(None)
None.__class__

or in Python 2.6 at least,

import types
types.NoneType

(although it has been removed from Python 3.2 for some reason).



--
Steven
--
http://mail.python.org/mailman/listinfo/python-list


steve+comp.lang.python at pearwood

Aug 3, 2012, 6:35 PM

Post #8 of 9 (460 views)
Permalink
Re: attribute is accessed from Nonetype [In reply to]

On Fri, 03 Aug 2012 19:03:20 -0400, Dave Angel wrote:

> On 08/03/2012 06:41 PM, Chris Angelico wrote:
>> On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel <d [at] davea> wrote:
>>> I'm sorry, what's not clear? Nonetype is not the same as NoneType.
>>> Python is case sensitive.
>> There isn't a NoneType either. I get a NameError.
>>
>> ChrisA
>
> NoneType isn't in the builtin namespace. It's in the types module.
>
> import types
> a = types.Nonetype
^^^^^^^^

Oh the irony. After criticising a beginner for getting the case wrong,
you have done exactly the same thing.

A form of Muphry's Law (the Iron Law of Nitpicking) perhaps?

http://en.wikipedia.org/wiki/Muphry%27s_law



--
Steven
--
http://mail.python.org/mailman/listinfo/python-list


d at davea

Aug 3, 2012, 6:58 PM

Post #9 of 9 (459 views)
Permalink
Re: attribute is accessed from Nonetype [In reply to]

On 08/03/2012 09:35 PM, Steven D'Aprano wrote:
> On Fri, 03 Aug 2012 19:03:20 -0400, Dave Angel wrote:
>
>> On 08/03/2012 06:41 PM, Chris Angelico wrote:
>>> On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel <d [at] davea> wrote:
>>>> I'm sorry, what's not clear? Nonetype is not the same as NoneType.
>>>> Python is case sensitive.
>>> There isn't a NoneType either. I get a NameError.
>>>
>>> ChrisA
>> NoneType isn't in the builtin namespace. It's in the types module.
>>
>> import types
>> a = types.Nonetype
> ^^^^^^^^
>
> Oh the irony. After criticising a beginner for getting the case wrong,
> you have done exactly the same thing.
>
> A form of Muphry's Law (the Iron Law of Nitpicking) perhaps?
>
> http://en.wikipedia.org/wiki/Muphry%27s_law
>
You are, of course right; I blew it. Thanks for pointing it out with
humor.


--

DaveA

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.