利用jupyter的cell是可以运行python文件的:

运行py文件例子:

In [ ]:%run lhr.py

加载了lhr.py文件,相当于导包。

In [ ]:%load lhr.py

把lhr.py的代码显示出来。

# %load app.py
from flask import Flask
from flask import render_template
from flask import request
from datetime import datetime
import re
import pymysqlapp = Flask(__name__)# @app.route("/")
# def home():
#     return 'Hello, Flask!'# @app.route("/hello/<name>")
# def hello_there(name):
#     return render_template(
#         "hello_there.html",
#         name = name,
#         date = datetime.now()
#     )# @app.route("/test2")
# def test2():
#     return render_template(
#         "test2.html"
#     )# @app.route("/api/data")
# def get_data():
#     return app.send_static_file("data.json")# Replace the existing home function with the one below
@app.route("/")
def home():return render_template("home.html")# New functions
@app.route("/about")
def about():return render_template("about.html")@app.route("/contact")
def contact():return render_template("contact.html")@app.route("/test2")
def test2():return render_template("test2.html")@app.route("/test3")
def test3():return render_template("test3.html")@app.route("/test4")
def test4():return render_template("test4.html")@app.route("/register")
def register():return render_template("register.html")@app.route("/result",methods = ['POST','GET'])
def result():if request.method=='POST':result = request.form
#         print(result.get("name"))
#         print(type(result.get("name")))
#         print(result.get("gender"))
#         print(type(result.get("gender")))
#         print(result.get("age"))
#         print(type(result.get("age")))
#         print(result.get("level"))
#         print(type(result.get("level")))mname = result.get("name") gender =  "男" if result.get("gender")==None else "女"age = result.get("age")level = result.get("level")print(mname,gender,age,level)print(f"insert into members values(null,{mname},{gender},{age},{level})")try:print(1)cursor.execute("use yacht_club")print(2)cursor.execute(f"insert into members values(null,'{mname}','{gender}',{age},{level})")print(3)conn.commit()print(4)except:print(5)return render_template("home.html")else:print(6)return render_template("register.html"
#             "result.html",result = result)if __name__ == '__main__':conn = pymysql.connect(host='localhost',port=3306,user='root',passwd='20010529',charset = 'utf8')           cursor = conn.cursor()app.run(host="192.168.126.1",port=5000,debug=True)cursor.close()conn.close()

怎样用jupyter运行py文件?相关推荐

  1. Jupyter 运行py文件 踩过的坑和方法

    在Github上下载的代码是.py格式的,需要用Jupyter运行. 搜了一下网上让用%run xx.py 但是这样程序的结果(图片)总是保存不下来,我也不知道为啥 后来在文件夹下开了一个.ipynb ...

  2. 2、运行.py文件、字符串、保留字符、行和缩进、多行语句、引号、注释、等待用户输入、同一行显示多条语句、命令行参数

    2Python基础语法 2.1运行.py文件 运行方式类似: $ python test.py 2.2Python标识符 在Python里,标识符由字母.数字.下划线组成. 在Python中,所有标识 ...

  3. python硬件交互_对Python的交互模式和直接运行.py文件的区别详解

    对Python的交互模式和直接运行.py文件的区别详解 看到类似C:\>是在Windows提供的命令行模式,看到>>>是在Python交互式环境下. 在命令行模式下,可以执行p ...

  4. cmd执行python 环境变量应该怎么写_python怎么运行py文件?.py文件cmd命令方法及环境变量配置教程...

    python是一款应用非常广泛的脚本程序语言,谷歌公司的网页就是用python编写.python在生物信息.统计.网页制作.计算等多个领域都体现出了强大的功能.python和其他脚本语言如java.R ...

  5. [debug] 命令行窗口运行.py文件,报错No module named XXX

    问题描述: 在PyCharm中运行.py文件正常,在命令行运行.py文件报错"No module named XXX" 原因分析 说到底是搜索路径的问题. PyCharm中运行的时 ...

  6. pyth命令_如何:在Windows上设置用于从命令行运行.py文件的Python可执行文件

    pyth命令 Summary: When you type script.py at the Command Prompt on Windows, the Python executable used ...

  7. python shell 运行py文件,python怎么运行py文件

    python运行py文件的方法:首先在资源管理器里复制一下py文件存放的路径,并打开命令行:然后切换到py文件的路径下面:接着输入"python 文件名.py":**后按下回车键, ...

  8. cmd中如何运行python文件_在cmd中运行.py文件: python的操作步骤

    在cmd中运行.py文件: python的操作步骤 1 打开cmd, 不改变运行的目录: 输入python 空格  调试好的python文件路径 或者python 空格  将python文件拖入cmd ...

  9. python为什么运行不了_python怎么运行py文件

    小编致力于为大家奉献最有效的经验,让大家能够解决掉问题,但是大家也都知道,每个人遇到的情况都是不一样的,大家在看小编经验的同时,除了跟随操作,也需要自己的思考,举一反三的解决问题,这样才会变得更加有内 ...

最新文章

  1. BZOJ 2429: [HAOI2006]聪明的猴子【最小生成树】
  2. Redis系列(二):Redis缓存穿透和缓存雪崩是什么?
  3. oracle 执行java_oracle调用JAVA类的方法
  4. 【转载】恼人的函数指针(一)
  5. Spring Cloud与Docker微服务架构实战--阅读笔记
  6. 中国大学MOOC-数据结构基础习题集、08-1、Talent and Virtue
  7. java nextprime_中国MOOC_零基础学Java语言_第7周 函数_1分解质因数
  8. OSChina 周六乱弹 ——程序员想让对象一辈子跟你的秘籍
  9. protoc执行命令
  10. 瞬态电压抑制二极管选型指导,一场走心的科普之旅
  11. 小米mix2 原生android,小米MIX2 安卓10 原生体验 LineageOS17.1 ROOT
  12. tomcat中的过滤器
  13. C语言自学记录-Class6-函数
  14. 评论抓取:Python爬取AppStore上的评论内容及星级,突破500条限制
  15. fastq转化成fasta格式
  16. UWP项目设计器界面打开报错的解决办法
  17. Excel把符合条件的数据全部提取出来
  18. 虚幻引擎图文笔记:蓝图中二项切换节点(Flip Flop)的用法
  19. 台式计算机显示器点不亮的原因,电脑点不亮原因及处理方法
  20. 全球与中国工业操作杆开关市场现状及未来发展趋势

热门文章

  1. 【快速改文件名后缀】和【谷歌浏览器网页图片一键下载插件】推荐
  2. 2023去水印小程序saas系统源码修复独立版v1.0.3+uniapp前端
  3. 通俗易懂的React事件系统工作原理
  4. R语言小白学习笔记3—R语言读取数据
  5. 初识R语言之数据读取篇
  6. python自动化脚本查找百度
  7. 归并排序算法(C语言实现)
  8. 目标跟踪(OTB100、GOT10K、LaSOT)数据集pysot测试结果
  9. 下载肝胆肿瘤TCGA原始数据
  10. JVM GC原理及调优的基本思路