A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/310063.html below:

Accessing class variable at class creation time

Accessing class variable at class creation time Accessing class variable at class creation timeDave Hansen iddw at hotmail.com
Mon Sep 26 15:14:24 EDT 2005
On 23 Sep 2005 14:01:21 -0700, "Carlos" <carlosjosepita at gmail.com>
wrote:

>Hi!
>
>class A:
>  X = 2
>  def F():
>    print A.X
>  F()
>
>The above fails because the name A is not
>yet at global scope when the reference A.X

Maybe I'm missing something.  Python 2.4.1#65 under Win32 Idle 1.1.1
gives me the following:

--begin included file---
>>> class A:
	X = 2
	def F():
		print A.X
	F()

	
2
---end included file---

But what good is F?  You can't call A.F() because methods need an
instance, and calling A.F(instance) or instance.F() throws a TypeError
(argument count) exception.

Regards,

                               -=Dave
-- 
Change is inevitable, progress is not.

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4