Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Return Multiple or one just
#11
@deanhystad, they can be used as class attributes. But you are right, I agree their code is problematic.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#12
(Apr-30-2020, 03:19 PM)deanhystad Wrote: Header and Footer are not classes. You use the word class, but you do not use any of the class coding conventions.

I only need to use it if I need it for parameter passing

(Apr-30-2020, 04:01 PM)buran Wrote: 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 ')

The problem is that in the answer it includes (\n) inside the html code, this is the problem that generates the error, because the html is all problematic according to your print.
Reply
#13
What error? You haven't shown any errors in this thread. Why are the new line characters problematic?
Reply
#14
when you print a tuple of 2 str elements, what you get is the representation of the str elements. That is why you see \n.

if you do
print('\n'.join(Runcode.screen()))
you get
Output:
<!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> <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>
or you can assign the returned values to names and work with these
my_header, my_footer = Runcode.screen()
print(my_header)
print(my_footer)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#15
I managed to solve by concatenating, example:

return classone.ClassOne.view() + classtwo.ClassTwo.view()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function - Return multiple values tester_V 10 4,439 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Return Object Created from Multiple Classes emerger 3 3,054 Oct-18-2018, 02:14 AM
Last Post: emerger
  Multiple "return" statements or "result" variable? WolfWayfarer 7 7,747 Jul-25-2018, 07:51 AM
Last Post: perfringo
  How to return multiple values from function in python pikkip 2 4,611 Jan-23-2017, 06:00 AM
Last Post: pikkip

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020