0

I want to run a python program (kinda like this) from a browser

Anyway, as you see it has a few inputs, and i would like to "translate" that into a kind of form

def addNew():
     appendBase = open('dBase.cfg','a')
     uname = input('Username: ')
     pword = input('Password: ')
     appendBase.write(uname+','+pword+'\n')
     print('\nAdded new profile: \n'+uname+','+pword)
     appendBase.close()

Also i dont know how to get the print to the page, so it can show it

I've just started learning, so go easy on me, please

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

1 Answers1

-1

It is not possible to actually run this in the browser, for various reasons.

  1. you can't run python in browsers. only javascript
  2. you can't open local files from a browser
  3. there's no command line to input from some terminal

Most things you see on the web have two parts

  • a part that actually runs in the browser. Written in HTML and javascript
  • another part where the browser connects, to send and receive data. That can be done in any language, including python. However, that part is not visible in the browser

The two parts communicate using HTTP protocol. So, start by reading a bit on HTML/javascript (W3Schools is an easy way to get started). When you feel comfortable with that, practice with a python web framework (django is the most popular, but flask is the easiest to get started), and see how javascript uses HTTP to connect to that.

blue_note
  • 27,712
  • 9
  • 72
  • 90
  • 1
    1. Yes, you [can run python in a browser](http://www.skulpt.org/). 2. Yes, you [can open local files with JS](https://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file-with-javascript). 3. And yes, there is a command line in Sculpt that supports `input`. – DYZ Aug 29 '18 at 14:25