How Do I Update the .replit File From Within My Python Code?

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?

1 Like

…Probably? Why would you want to do that?

@QwertyQwerty88 So I can change the entrypoint of the repl midway through a program.

…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.

1 Like

…And how would changing the entrypoint be useful there?

(sorry if this is getting annoying)

1 Like

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?

2 Likes

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.

1 Like

@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?

2 Likes

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()).

2 Likes

@NuclearPasta0 This is what I am working on currently.


Then how would I use os.system() to create that entrypoint?

1 Like

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.

1 Like

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

1 Like

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

1 Like

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()
1 Like

2 Likes