Ask coding questions

← Back to all posts
How do I show a file to a user?
normalF

I want to show a file to a user like the '.txt' file in https://replit.com/@youtubemirror/fileExample#main.py via a string or link in the console. How would I go about this without having to share the repl? (A way to download with python would work too.) Cheers!

Answered by EthanMartin223 [earned 5 cycles]
View Answer
Voters
normalF
Comments
hotnewtop
EthanMartin223

Try varhere = f.read()

normalF

That might work, but I'm looking more for a solution that would work more for both images and text (like clicking a file in the IDE) where it prints out a link to it. So far the link just links back to the output. @EthanMartin223

EthanMartin223

@youtubemirror maybe do a check to see what type the file is. if the file is txt use read, or if file is img then use PIL img.show?
example: https://replit.com/@EthanMartin223/youtubemirror#main.py

Glitchez

let me get this straight, you want to display the file to the user in the console?

normalF

I would prefer if it could be a link to the file in it's directory, similar to how you can click on a file path in the IDE to jump to that file. @Glitchez

Glitchez

@youtubemirror I think it would make more sense displaying your file contents in a html page using flask.

Glitchez

@youtubemirror I do not think it is even possible to display images in the console. Sure you can use some module or something but not by default. What I recommend for images if you are determined to not use html consider looking at Pygame because it has a very easy method for displaying images and text even if they are meant for games.

EthanMartin223

@Glitchez The one benefit to Glitchez's answer is if you put the link to the file in your HTML page using an <a href='filename'> tag users could download the file as you stated that could be an option too. This way ALL file types would be covered under the users OS default file opening system.