首页 > 解决方案 > 如何使用 brython 在 python 脚本中导入 python 模块

问题描述

我打算创建一个使用 Brython 将 .xlsx 文件转换为 .csv 文件的小应用程序。我使用了 Brython,所以我可以用 python 而不是 javascript 编写代码。但是,由于某种原因,我无法上传熊猫。这是我的代码:

<!DOCTYPE html>


<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Brython Examples</title>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython.js" integrity="sha256-rA89wPrTJJQFWJaZveKW8jpdmC3t5F9rRkPyBjz8G04=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython_stdlib.js" integrity="sha256-Gnrw9tIjrsXcZSCh/wos5Jrpn0bNVNFJuNJI9d71TDs=" crossorigin="anonymous"></script>
</head>


<body onload="brython()">
    <p>Click on the "Choose File" button to upload a file:</p>

    <form action="/action_page.php">
        <input type="file" id="myFile" name="filename" >
    </form>

 <script type="text/python" >
    #importing pandas as pd 
    import pandas as pd 

    # Read and store content 
    # of an excel file 
    read_file = pd.read_excel ("myfile.xlsx") 

    # Write the dataframe object 
    # into csv file 
    read_file.to_csv ("Test.csv", 
                    index = None, 
                    header=True) 
        
    # read csv file and convert 
    # into a dataframe object 
    df = pd.DataFrame(pd.read_csv("Test.csv")) 


</script>

</body>
</html> 

这是我从 Firefox 控制台得到的错误。

这是我得到的错误

标签: javascriptpythonhtmlbrython

解决方案


推荐阅读