Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Beginner question? Classes, variables, ...

Reply
Thread Tools

Beginner question? Classes, variables, ...

 
 
=?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?=
Guest
Posts: n/a
 
      06-28-2006
The problem:

I have two classes:

class X:
def __init__(self):
pass

class Y:
def __init__(self):
self.a=1
self.b=X()

and I would like to make 'a' visible inside 'x'. Is there a way to refer to
the Y class from the X? To make things easier , each class is in a
different file, so class X is imported. Or the only way I have is to
pass 'a' as a variable in each method call of 'b' ('a' can take different
values that affect to the behaviour of 'b').

Thanks in advance.
--
Ángel Gutiérrez Rodr*guez - http://www.velocityreviews.com/forums/(E-Mail Removed)
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qu*mica F*sica y Anal*tica
Universidad de Oviedo - c/Julián Claver*a 8 33006 - Oviedo
Asturias - Spain
E-mail: (E-Mail Removed) Telf.: +34-985103687
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      06-28-2006
Ángel Gutiérrez Rodr*guez wrote:

> The problem:
>
> I have two classes:
>
> class X:
> def __init__(self):
> pass
>
> class Y:
> def __init__(self):
> self.a=1
> self.b=X()
>
> and I would like to make 'a' visible inside 'x'. Is there a way to refer
> to the Y class from the X? To make things easier , each class is in a
> different file, so class X is imported. Or the only way I have is to
> pass 'a' as a variable in each method call of 'b' ('a' can take different
> values that affect to the behaviour of 'b').


You mean the behavior of X here I guess - b is just a name, there isn't much
behavior in it.

Pass X the instance of Y:

class X:
def __init__(self, my_y):
self.my_y

def foo(self):
print self.my_y.a

class Y:
def __init__(self):
self.a=1
self.b=X(self)

Then in X you can work with whatever Y contains.



Diez
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      06-28-2006
On Wed, 28 Jun 2006 10:35:10 +0200, "Diez B. Roggisch"
<(E-Mail Removed)> declaimed the following in comp.lang.python:

> class X:
> def __init__(self, my_y):
> self.my_y

self.my_y = my_y

--
Wulfraed Dennis Lee Bieber KD6MOG
(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      06-28-2006
Dennis Lee Bieber wrote:

> On Wed, 28 Jun 2006 10:35:10 +0200, "Diez B. Roggisch"
> <(E-Mail Removed)> declaimed the following in comp.lang.python:
>
>> class X:
>> def __init__(self, my_y):
>> self.my_y

> self.my_y = my_y


*argl*

Thanks

No tea so far...

Diez
 
Reply With Quote
 
=?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?=
Guest
Posts: n/a
 
      06-28-2006
That wa sneat! Thanks!

--
Ángel Gutiérrez Rodr*guez - (E-Mail Removed)
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qu*mica F*sica y Anal*tica
Universidad de Oviedo - c/Julián Claver*a 8 33006 - Oviedo
Asturias - Spain
E-mail: (E-Mail Removed) Telf.: +34-985103687
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner's Beginner william nelson Ruby 7 04-11-2011 11:23 PM
Beginner can't get a wireless VPN connect? Russell DeMarco Wireless Networking 2 03-18-2005 10:35 PM
Beginner can't connect Laptop to wireless network Russell DeMarco Wireless Networking 2 03-17-2005 03:31 PM
No Class at ALL!!! beginner/beginner question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= ASP .Net 7 02-03-2005 02:47 PM
Tutorial for beginner/ Tutorial voor beginner Rensjuh C++ 7 09-02-2004 12:41 AM



Advertisments