How can I change the data in the .replit
file (specifically the entrypoint
) from within a python file? Can I just use the regular read/write for files in Python?
…Probably? Why would you want to do that?
…And why would you want to do that?
Because I’m making a library that allows you to make websites from python, and I need to make a run()
function to run my code in the webview / some_repl.redcoder.repl.co domain.
…And how would changing the entrypoint
be useful there?
(sorry if this is getting annoying)
So the user can actually see the output of the website…
Okay I’m confused. How does changing the entrypoint (changes what file opens when you open the Repl in the workspace and changes the file to run on old Python Repls) let the user see the output of the website?
Because then the webview tab shows up. Is there a different way I should do this?
No, no, see, that doesn’t answer the question.
I don’t even understand what you’re trying to do here tbh… Is it supposed to be a Console Repl, that later opens a Webview? If so that won’t work.
@QwertyQwerty88 Let me start from the beginning – I want to make a library that people can use to create websites in Python and have no need for prior knowledge of HTML or CSS. To do this, I am working on a way to make a index.html
appear (and am close to doing that much), but would like to make this HTML file actually runnable on the users’ request. Such as, when you use app.run
in Flask, you make a webview tab pop up via the index.html
file. How should I make this webview tab pop up?
Okay, so a library. Something that you’d import, correct? Then changing .replit
file won’t help, but lemme go try something…
I would recommend against using the entrypoint
variable in .replit
because it’s prone to error, replit-specific, and not usually how a library works.
Instead, declare a function as part of your library API that runs whatever you need. (Anything that can be done with entrypoint
can be done with os.system()
).
@NuclearPasta0 This is what I am working on currently.
Then how would I use os.system()
to create that entrypoint
?
You don’t need entrypoint
because it is best to allow the programmer to decide when to run your library stuff. entrypoint
simply tells replit what file they should run the start command on (and some editor stuff I think). So figure out what command needs to be run with os.system()
. I don’t know what HTML template repls are like, you could take a look.
Okay @RedCoder, so if you want to make a library that opens a website, you could use the HTTP standard library:
from http.server import HTTPServer, BaseHTTPRequestHandler
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.handle_index()
elif self.path == '/about':
self.handle_about()
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b'Not Found')
def handle_index(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'Hello, this is the index page!')
def handle_about(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'This is the about page!')
def run_server():
httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()
but of course allow the user to specify the different routes. I’ll probably respond again later with some more code
Probably should work. It just leaves the program on, currently. No webview tab or anything opens (the port is set to 0000).
The link to the repl is: PyMash
Did you call the run
function?
Yes, I did (see main.py
).
import pymash
site = pymash.html()
site.add_line("h1","hello world")
site.run()