How to include contents of a page . py on another page . py

Asked

Viewed 212 times

2

How do I make a include or open a python page in another, for example in php:

include 'content/filename.php';

Load Html it loads the file more .py no, I’ve tried the command open

fp = open('content/header.py')
html = fp.read()
fp.close()
  • I don’t know if it’s clear... You have another file .py, and inside it wants to read html code?

  • yes, only that this code will also have python code

1 answer

2

In fact, you didn’t even have to go as far back as Paulo mentioned above. You can make a function that stores these values and in the other file you pull it:

from arquivo1 import funcao
a,b,c = funcao()

Also you can leave these values stored in variables and pull them by the other file as if they were normal functions.

  • Thanks works too well!

  • It’s not that "it works too': that’s the way to do things. Just not the most common in PHP, why PHP evolved from a language to page templates. In programming, Voce uses modules with functions - and each function is reusable

Browser other questions tagged

You are not signed in. Login or sign up in order to post.