Initiate multiple class in class












0















I have multiple class in multiple files. for example,



File 1:



class gen_list ():
def gen_list_spice(self):
...


File 2:



class gen_postsim ():
def gen_postsim(self):
...


I am thinking to wrap it with another class which looks like this,



class char ()
def __init__ (self, type):
if (type == list):
....... (load gen_list only<-- this part i do not know how to write)
else
....... (load both)


in the top wrapper, I would like to for example if I give list I will be able to use gen_list_spice and otherwise, I will be able to use both gen_list_spice and gen_postsim when I just need to call the object char










share|improve this question

























  • Classes are delcared as "class Name:" note: no parentheses. Also, I completely don't understand your last sentence.

    – richflow
    Nov 20 '18 at 9:14











  • basically i would like to only load certain class based on my input from the wrapper and not all.

    – user1550596
    Nov 20 '18 at 9:18











  • Let me try to rephrase, based on my understanding of your question: based on the type of the argument in init, you want the class char to expose the methods from one class, or to expose the methods from two other classes? E.g. based on the init call, for it to inherit one class, or two classes?

    – Todor Minakov
    Nov 20 '18 at 9:31











  • What exactly do you mean by "load gen_list" and "load both". What would loading them do?

    – martineau
    Nov 20 '18 at 9:35


















0















I have multiple class in multiple files. for example,



File 1:



class gen_list ():
def gen_list_spice(self):
...


File 2:



class gen_postsim ():
def gen_postsim(self):
...


I am thinking to wrap it with another class which looks like this,



class char ()
def __init__ (self, type):
if (type == list):
....... (load gen_list only<-- this part i do not know how to write)
else
....... (load both)


in the top wrapper, I would like to for example if I give list I will be able to use gen_list_spice and otherwise, I will be able to use both gen_list_spice and gen_postsim when I just need to call the object char










share|improve this question

























  • Classes are delcared as "class Name:" note: no parentheses. Also, I completely don't understand your last sentence.

    – richflow
    Nov 20 '18 at 9:14











  • basically i would like to only load certain class based on my input from the wrapper and not all.

    – user1550596
    Nov 20 '18 at 9:18











  • Let me try to rephrase, based on my understanding of your question: based on the type of the argument in init, you want the class char to expose the methods from one class, or to expose the methods from two other classes? E.g. based on the init call, for it to inherit one class, or two classes?

    – Todor Minakov
    Nov 20 '18 at 9:31











  • What exactly do you mean by "load gen_list" and "load both". What would loading them do?

    – martineau
    Nov 20 '18 at 9:35
















0












0








0








I have multiple class in multiple files. for example,



File 1:



class gen_list ():
def gen_list_spice(self):
...


File 2:



class gen_postsim ():
def gen_postsim(self):
...


I am thinking to wrap it with another class which looks like this,



class char ()
def __init__ (self, type):
if (type == list):
....... (load gen_list only<-- this part i do not know how to write)
else
....... (load both)


in the top wrapper, I would like to for example if I give list I will be able to use gen_list_spice and otherwise, I will be able to use both gen_list_spice and gen_postsim when I just need to call the object char










share|improve this question
















I have multiple class in multiple files. for example,



File 1:



class gen_list ():
def gen_list_spice(self):
...


File 2:



class gen_postsim ():
def gen_postsim(self):
...


I am thinking to wrap it with another class which looks like this,



class char ()
def __init__ (self, type):
if (type == list):
....... (load gen_list only<-- this part i do not know how to write)
else
....... (load both)


in the top wrapper, I would like to for example if I give list I will be able to use gen_list_spice and otherwise, I will be able to use both gen_list_spice and gen_postsim when I just need to call the object char







python class






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 9:31









martineau

66.6k989180




66.6k989180










asked Nov 20 '18 at 8:59









user1550596user1550596

102




102













  • Classes are delcared as "class Name:" note: no parentheses. Also, I completely don't understand your last sentence.

    – richflow
    Nov 20 '18 at 9:14











  • basically i would like to only load certain class based on my input from the wrapper and not all.

    – user1550596
    Nov 20 '18 at 9:18











  • Let me try to rephrase, based on my understanding of your question: based on the type of the argument in init, you want the class char to expose the methods from one class, or to expose the methods from two other classes? E.g. based on the init call, for it to inherit one class, or two classes?

    – Todor Minakov
    Nov 20 '18 at 9:31











  • What exactly do you mean by "load gen_list" and "load both". What would loading them do?

    – martineau
    Nov 20 '18 at 9:35





















  • Classes are delcared as "class Name:" note: no parentheses. Also, I completely don't understand your last sentence.

    – richflow
    Nov 20 '18 at 9:14











  • basically i would like to only load certain class based on my input from the wrapper and not all.

    – user1550596
    Nov 20 '18 at 9:18











  • Let me try to rephrase, based on my understanding of your question: based on the type of the argument in init, you want the class char to expose the methods from one class, or to expose the methods from two other classes? E.g. based on the init call, for it to inherit one class, or two classes?

    – Todor Minakov
    Nov 20 '18 at 9:31











  • What exactly do you mean by "load gen_list" and "load both". What would loading them do?

    – martineau
    Nov 20 '18 at 9:35



















Classes are delcared as "class Name:" note: no parentheses. Also, I completely don't understand your last sentence.

– richflow
Nov 20 '18 at 9:14





Classes are delcared as "class Name:" note: no parentheses. Also, I completely don't understand your last sentence.

– richflow
Nov 20 '18 at 9:14













basically i would like to only load certain class based on my input from the wrapper and not all.

– user1550596
Nov 20 '18 at 9:18





basically i would like to only load certain class based on my input from the wrapper and not all.

– user1550596
Nov 20 '18 at 9:18













Let me try to rephrase, based on my understanding of your question: based on the type of the argument in init, you want the class char to expose the methods from one class, or to expose the methods from two other classes? E.g. based on the init call, for it to inherit one class, or two classes?

– Todor Minakov
Nov 20 '18 at 9:31





Let me try to rephrase, based on my understanding of your question: based on the type of the argument in init, you want the class char to expose the methods from one class, or to expose the methods from two other classes? E.g. based on the init call, for it to inherit one class, or two classes?

– Todor Minakov
Nov 20 '18 at 9:31













What exactly do you mean by "load gen_list" and "load both". What would loading them do?

– martineau
Nov 20 '18 at 9:35







What exactly do you mean by "load gen_list" and "load both". What would loading them do?

– martineau
Nov 20 '18 at 9:35














1 Answer
1






active

oldest

votes


















0














I don't know why you do this, but you can import a file in any part of your file.



File 1 which should be named as get_list.py



class ListGenerator():

def gen_list_spice(self):
pass


File 2 which should be named as gen_postsim.py



class PostsimGenerator():

def gen_postsim(self):
pass


And in your wrapper File:



class char():

def __init__(self, type):
if type == list:
from gen_list import ListGenerator
gl = ListGenerator()
gl.gen_list_spice()
else:
from gen_postsim import PostsimGenerator
from gen_list import ListGenerator
gp = PostsimGenerator()
gp.gen_postsim()


But it's not a good practice to do this. You can use functions rather than classes and import them in the file header.



In file gen_list.py



def gen_list_spice():
print("get list")
pass


In file gen_postsim.py



def gen_postsim():
print("gen postsim")
pass


In your wrapper file



from gen_list import gen_list_spice
from gen_postsim import gen_postsim

class char():

def __init__(self, type):
if type == list:
gen_list_spice()
else:
gen_list_spice()
gen_postsim()





share|improve this answer


























  • Thanks for your suggestion and help, its work. thanks

    – user1550596
    Nov 30 '18 at 7:27











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389419%2finitiate-multiple-class-in-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I don't know why you do this, but you can import a file in any part of your file.



File 1 which should be named as get_list.py



class ListGenerator():

def gen_list_spice(self):
pass


File 2 which should be named as gen_postsim.py



class PostsimGenerator():

def gen_postsim(self):
pass


And in your wrapper File:



class char():

def __init__(self, type):
if type == list:
from gen_list import ListGenerator
gl = ListGenerator()
gl.gen_list_spice()
else:
from gen_postsim import PostsimGenerator
from gen_list import ListGenerator
gp = PostsimGenerator()
gp.gen_postsim()


But it's not a good practice to do this. You can use functions rather than classes and import them in the file header.



In file gen_list.py



def gen_list_spice():
print("get list")
pass


In file gen_postsim.py



def gen_postsim():
print("gen postsim")
pass


In your wrapper file



from gen_list import gen_list_spice
from gen_postsim import gen_postsim

class char():

def __init__(self, type):
if type == list:
gen_list_spice()
else:
gen_list_spice()
gen_postsim()





share|improve this answer


























  • Thanks for your suggestion and help, its work. thanks

    – user1550596
    Nov 30 '18 at 7:27
















0














I don't know why you do this, but you can import a file in any part of your file.



File 1 which should be named as get_list.py



class ListGenerator():

def gen_list_spice(self):
pass


File 2 which should be named as gen_postsim.py



class PostsimGenerator():

def gen_postsim(self):
pass


And in your wrapper File:



class char():

def __init__(self, type):
if type == list:
from gen_list import ListGenerator
gl = ListGenerator()
gl.gen_list_spice()
else:
from gen_postsim import PostsimGenerator
from gen_list import ListGenerator
gp = PostsimGenerator()
gp.gen_postsim()


But it's not a good practice to do this. You can use functions rather than classes and import them in the file header.



In file gen_list.py



def gen_list_spice():
print("get list")
pass


In file gen_postsim.py



def gen_postsim():
print("gen postsim")
pass


In your wrapper file



from gen_list import gen_list_spice
from gen_postsim import gen_postsim

class char():

def __init__(self, type):
if type == list:
gen_list_spice()
else:
gen_list_spice()
gen_postsim()





share|improve this answer


























  • Thanks for your suggestion and help, its work. thanks

    – user1550596
    Nov 30 '18 at 7:27














0












0








0







I don't know why you do this, but you can import a file in any part of your file.



File 1 which should be named as get_list.py



class ListGenerator():

def gen_list_spice(self):
pass


File 2 which should be named as gen_postsim.py



class PostsimGenerator():

def gen_postsim(self):
pass


And in your wrapper File:



class char():

def __init__(self, type):
if type == list:
from gen_list import ListGenerator
gl = ListGenerator()
gl.gen_list_spice()
else:
from gen_postsim import PostsimGenerator
from gen_list import ListGenerator
gp = PostsimGenerator()
gp.gen_postsim()


But it's not a good practice to do this. You can use functions rather than classes and import them in the file header.



In file gen_list.py



def gen_list_spice():
print("get list")
pass


In file gen_postsim.py



def gen_postsim():
print("gen postsim")
pass


In your wrapper file



from gen_list import gen_list_spice
from gen_postsim import gen_postsim

class char():

def __init__(self, type):
if type == list:
gen_list_spice()
else:
gen_list_spice()
gen_postsim()





share|improve this answer















I don't know why you do this, but you can import a file in any part of your file.



File 1 which should be named as get_list.py



class ListGenerator():

def gen_list_spice(self):
pass


File 2 which should be named as gen_postsim.py



class PostsimGenerator():

def gen_postsim(self):
pass


And in your wrapper File:



class char():

def __init__(self, type):
if type == list:
from gen_list import ListGenerator
gl = ListGenerator()
gl.gen_list_spice()
else:
from gen_postsim import PostsimGenerator
from gen_list import ListGenerator
gp = PostsimGenerator()
gp.gen_postsim()


But it's not a good practice to do this. You can use functions rather than classes and import them in the file header.



In file gen_list.py



def gen_list_spice():
print("get list")
pass


In file gen_postsim.py



def gen_postsim():
print("gen postsim")
pass


In your wrapper file



from gen_list import gen_list_spice
from gen_postsim import gen_postsim

class char():

def __init__(self, type):
if type == list:
gen_list_spice()
else:
gen_list_spice()
gen_postsim()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 9:33

























answered Nov 20 '18 at 9:25









KeijackKeijack

1666




1666













  • Thanks for your suggestion and help, its work. thanks

    – user1550596
    Nov 30 '18 at 7:27



















  • Thanks for your suggestion and help, its work. thanks

    – user1550596
    Nov 30 '18 at 7:27

















Thanks for your suggestion and help, its work. thanks

– user1550596
Nov 30 '18 at 7:27





Thanks for your suggestion and help, its work. thanks

– user1550596
Nov 30 '18 at 7:27


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389419%2finitiate-multiple-class-in-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith