0

I have a program that reads a csv file and filters the data in it, then writes a new csv with the filtered data. I need to make this code available and executable within a web browser, but so far the only way I've seen to do it involves some use of JavaScript. I've never tried anything like this so any information to point me in the right direction is much appreciated!! Thanks! Here's a draft of the code if that helps.

readFile    = input("--Enter name of file to be read: ")
writeFile   = input("--Enter name of file to be written: ")
with open(readFile,'r') as readFile:
    
    print("Reading File...\n")
    
    for eachline in readFile:                               # converting columns to lists
        parts = eachline.strip('\n').split(',')
        column1.append(parts[0])
        column2.append(parts[1])
      
    del column1[0]                                          # deleting the header of the column
    del column2[0]
                                                        
    for i in range(len(column1)):                           # converting strings to int/float
        column1[i]  = float(column1[i]) 
        column2[i] = float(column2[i])


###########  data filter  #####################

with open(writeFile,'w') as writeFile:
    
    print("Writing new file...\n")
    
    for x in range(len(biglist2[1])):                       # will iterate as many times as there are rows in csv
        
        for y in range(len(biglist2)):                      # will iterate as many times as there are columns in csv (3)
            
            if y == 2:                                      
                writeFile.write(str(biglist2[y][x]))
            
            else:
                writeFile.write(str(biglist2[y][x])+',')
                
        writeFile.write('\n')


print("Program Complete!\n")
2
  • Better create API using FLASK rather than thinking to put the code on the browser. There are some projects like bruthon brython.info, but I am not sure how much it is compatible, also you can't simply write to sidk from browser because of permission, you need to handle it ina different way. Commented Jul 9, 2021 at 4:48
  • You might try VPython vpython.org They have online python coding via glowscript.org Commented Jul 9, 2021 at 6:00

1 Answer 1

1

You don't. Web browsers don't run Python, they run Javascript. You'll have to rewrite your code. And by the way, Javascript code in a browser can't open arbitrary files like that. It would be a huge security hole.

Perhaps you should really have your HTML code upload the file to your server, where you can run your Python code and send the data back.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.