Posts: 146 Threads: 65 Joined: Aug 2019 I can import two classes (nothing abnormal), but the problem is that I need to call the method of each class using only one return or more, I tried the instructions below, but without success: - Exemple One from apps.document.views import classone, classtwo class Runcode: def screen(): # exemple one : return classone.ClassOne.view(), classone.ClassOne.view() - Exemple Two from apps.document.views import classone, classtwo class Runcode: def screen(): # exemple two : return classone.ClassOne.view() return classtwo.ClassTwo.view() Posts: 6,920 Threads: 22 Joined: Feb 2020 Does the first try not work because you are getting two classOne's? This works fine for me: class X: def letter(self): return 'X' class Y: def letter(self): return 'Y' class Z: def duals(self): return X().letter(), Y().letter() print(Z().duals()) Posts: 146 Threads: 65 Joined: Aug 2019 (Apr-29-2020, 07:56 PM)deanhystad Wrote: Does the first try not work because you are getting two classOne's? This works fine for me: class X: def letter(self): return 'X' class Y: def letter(self): return 'Y' class Z: def duals(self): return X().letter(), Y().letter() print(Z().duals()) Okay, it was just a matter of type but they are different classes (classeone and classetwo). Thank you for the example shown above, I made the correction and I need the solution to be in accordance with the writing of the two examples above. In the first example I get the following error? from apps.document.views import header, footer class Runcode: def screen(): return header.Header.view(), footer.Footer.view() Output I get: ('\n\n\n \n\n \n \n \n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n \n \n \n\n \n \n ', '\n \n \n \n \n\n ') Posts: 8,197 Threads: 162 Joined: Sep 2016 Apr-30-2020, 09:48 AM (This post was last modified: Apr-30-2020, 09:49 AM by buran.) as usual in your threads you provide insufficient/partial information. The problem is what is returned by both class methods view() which we don't know anything about. the output you get is exactly as expected - a tuple of 2 elements, strings. Posts: 146 Threads: 65 Joined: Aug 2019 (Apr-30-2020, 09:48 AM)buran Wrote: as usual in your threads you provide insufficient/partial information. The problem is what is returned by both class methods view() which we don't know anything about. the output you get is exactly as expected - a tuple of 2 elements, strings. Hello Buran, As you can see he is calling the same method but from different classes. In each class with its view () methods there is an attribute that stores pure html code, which is triggered on the return of each view method, in isolation. Posts: 8,197 Threads: 162 Joined: Sep 2016 as far as I understand - header.Header.view() returns '\n\n\n \n\n \n \n \n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n \n \n \n\n \n \n ' and footer.Footer.view() returns '\n \n \n \n \n\n '. You expect some html, but actually you get that. why - we cannot say, because we haven't seen your classes. Posts: 6,920 Threads: 22 Joined: Feb 2020 So is it working or not? You are getting a tuple holding the return values for the two calls. Is that success? Posts: 146 Threads: 65 Joined: Aug 2019 (Apr-30-2020, 01:00 PM)buran Wrote: as far as I understand - header.Header.view() returns '\n\n\n \n\n \n \n \n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n \n \n \n\n \n \n ' and footer.Footer.view() returns '\n \n \n \n \n\n '. You expect some html, but actually you get that. why - we cannot say, because we haven't seen your classes. let's consider this code below, initially: from apps.document.views import header, footer class Runcode: def screen(): v_html = ( header.Header.view(), footer.Footer.view() ) return v_html Class Header : # Class Header : modelo de cabeƧalho html. class Header: # class-method : view def view(): # class-attribute : v_html5 = """ <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="description" content=""/> <meta name="keywords" content=""/> <!--Import Google Icon --> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!--Import Material Design Icons--> <link href="https://cdn.materialdesignicons.com/2.8.94/css/materialdesignicons.min.css" rel="stylesheet"> <!--Import Google Font --> <link href="https://fonts.googleapis.com/css?family=Catamaran&display=swap" rel="stylesheet"> <!-- Favicon --> <link href="" rel="shortcut icon"/> <!--Import framework bootstrap--> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <!--Custom framework design--> <link href="http://127.0.0.1:8080/document/assets/css/custom.css" rel="stylesheet" type="text/css"> <!-- Page Title --> <title>document</title> </head> <body> """ return v_html5 Class Footer : # Class Header : modelo de cabeƧalho html. class Footer: # class-method : def view(): # class-attribute : v_html5 = """ <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> </body> </html> """ return v_html5 Erro : ('\n\n\n \n\n \n \n \n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n \n \n \n\n \n \n ', '\n \n \n \n \n\n ') Posts: 6,920 Threads: 22 Joined: Feb 2020 Header and Footer are not classes. You use the word class, but you do not use any of the class coding conventions. Posts: 8,197 Threads: 162 Joined: Sep 2016 again, you present some hypothetical code, claiming it's not working. However, despite all problems, and there are huge problems with your code, it's working class Header: # class-method : view def view(): # class-attribute : v_html5 = """ <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="description" content=""/> <meta name="keywords" content=""/> <!--Import Google Icon --> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!--Import Material Design Icons--> <link href="https://cdn.materialdesignicons.com/2.8.94/css/materialdesignicons.min.css" rel="stylesheet"> <!--Import Google Font --> <link href="https://fonts.googleapis.com/css?family=Catamaran&display=swap" rel="stylesheet"> <!-- Favicon --> <link href="" rel="shortcut icon"/> <!--Import framework bootstrap--> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <!--Custom framework design--> <link href="http://127.0.0.1:8080/document/assets/css/custom.css" rel="stylesheet" type="text/css"> <!-- Page Title --> <title>document</title> </head> <body> """ return v_html5 class Footer: # class-method : def view(): # class-attribute : v_html5 = """ <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> </body> </html> """ return v_html5 class Runcode: def screen(): v_html = ( Header.view(), Footer.view() ) return v_html print(Runcode.screen()) Output: ('\n<!DOCTYPE html>\n<html lang="en" dir="ltr">\n <head>\n \n <meta charset="utf-8">\n <meta http-equiv="X-UA-Compatible" content="ie=edge">\n <meta name="viewport" content="width=device-width, initial-scale=1.0"/>\n <meta name="description" content=""/>\n <meta name="keywords" content=""/>\n \n <!--Import Google Icon -->\n <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">\n \n <!--Import Material Design Icons-->\n <link href="https://cdn.materialdesignicons.com/2.8.94/css/materialdesignicons.min.css" rel="stylesheet">\n \n <!--Import Google Font -->\n <link href="https://fonts.googleapis.com/css?family=Catamaran&display=swap" rel="stylesheet">\n \n <!-- Favicon -->\n <link href="" rel="shortcut icon"/>\n \n <!--Import framework bootstrap-->\n <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">\n \n <!--Custom framework design-->\n <link href="http://127.0.0.1:8080/document/assets/css/custom.css" rel="stylesheet" type="text/css">\n \n <!-- Page Title -->\n <title>document</title>\n \n </head>\n <body>\n ', '\n <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>\n <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>\n <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>\n </body>\n</html>\n ') |