Suppose I have a class setup like this: -
class Foo:
-
Bar b
-
class Bar:
-
Foo f
-
How can I make this work, preferably in one file?
4 1324
I presume you mean something like this: -
class Foo():
-
-
def __init__(self):
-
b = Bar()
-
b.hello()
-
-
class Bar():
-
-
def hello(self):
-
print "hello"
-
-
f = Foo()
-
$> python test.py
hello
To others, how do you create those python code blocks? I have been trying but I cannot figure it out :s
I presume you mean something like this: -
class Foo():
-
-
def __init__(self):
-
b = Bar()
-
b.hello()
-
-
class Bar():
-
-
def hello(self):
-
print "hello"
-
-
f = Foo()
-
$> python test.py
hello
To others, how do you create those python code blocks? I have been trying but I cannot figure it out :s
Just start the block with [code=python]But I think he means something like -
class Foo():
-
def __init__(self):
-
self.b = Bar()
-
-
class Bar():
-
def __init__(self):
-
self.f = Foo()
-
-
f = Foo()
-
A fix would be something like -
class Foo():
-
def __init__(self, bar=None):
-
self.b = bar
-
if bar == None:
-
self.b = Bar(self)
-
-
class Bar():
-
def __init__(self, foo=None):
-
self.f = foo
-
if bar == None:
-
self.f = Foo(self)
-
-
f = Foo()
-
yes, sorry, I was thinking java when I wrote that. Thanks!
yes, sorry, I was thinking java when I wrote that. Thanks!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: T Koster |
last post by:
After a few years of programming C, I had come to believe that I finally
knew how to correctly organise my structure definitions in header files
for mutually dependent structures, but I find myself...
|
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c...
|
by: rammel |
last post by:
class1.h
-----------
#ifndef CLASS1_H_
#define CLASS1_H_
#include "class2.h" // inclusion
class class2; // and forward
class class1
{
private:
|
by: joshc |
last post by:
I've found some old posts on this issue but the answer was a bit vague
to me. The problem I am trying to solve is the following:
/***** a.h ***********/
#include "b.h"
/* Forward declaration...
|
by: xoinki |
last post by:
hi all,
I have 3 classes. class A, class B, and class C, class D, defined in 4 files A.cpp, B.cpp, C.cpp, D.cpp
inheritence hierarchy is as follows.
A--> B --> C
|
|
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |