-
2021-12-22 11:40:50
利用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 pymysql app = 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 notebook将文件保存为Markdown,HTML等文件格式
2021-01-20 01:50:31做课题和数据挖掘竞赛用python比较多,比较常用的是在服务器终端输入jupyter notebook –ip 0.0.0.0,打开jupyter notebook的一个后台,并在本地windows电脑浏览器进入该服务端写python代码。 将.ipynb和.py结合,... -
如何用jupyter打开H5文件?
2021-05-22 12:14:47<p><img alt="" height="521" src="undefined" width="657" /></p> -
怎么通过jupyter打开r文件
2020-12-04 02:04:57www.pxcodes.comnfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台通过jupyter打开r文件的方法:(推荐:jupyter使用教程)nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台1、安装在jupyter中运行R...www.pxcodes.com
nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台
通过jupyter打开r文件的方法:(推荐:jupyter使用教程)nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台
1、安装在jupyter中运行R程序需要的R包nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台#在R中运行如下代码,来安装依赖的R包
install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
#在R中运行如下代码,使得R在jupyter中可以被探测到。
IRkernel::installspec(user = FALSE)
报错,可以尝试:nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台> devtools::install_github('IRkernel/IRkernel',force = TRUE)
> install.packages("digest")
> devtools::install_github('IRkernel/IRkernel',force = TRUE)
2、开始在jupyter中使用RnfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台
进入到文件jupyter中,按着shift+右击,在powershell中打开,输入jupyter notebooknfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台
修改软件包下载地址,避免下载失败或者下载速度过慢,国内镜像地址:nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台# 通过如下命令设定镜像
options(repos = 'http://mirrors.ustc.edu.cn/CRAN/')
# 查看镜像是否修改
getOption('repos')
# 尝试下载R包
install.packages('ggplot2')
运行R代码nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台# 查看R内置数据集的前6行
head(iris)
输出可视化图形nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台pairs(iris[1:4])
更多python知识请关注python视频教程。nfC少儿编程网-Scratch_Python_教程_免费儿童编程学习平台
-
Jupyter ~ 像写文章般的 Coding (附:同一个ipynb文件,执行多语言代码)
2021-06-25 09:49:41前面用了很久Notebook来交互式编程了,此次说说几个其余的选项:htmlNotebook Markdown此次选Markdown模式(关于Markdown基础能够看以前...git Jupyter NBConvert生成HTML or Markdown不闲扯,继续说说NBConvert,默...前面用了很久Notebook来交互式编程了,此次说说几个其余的选项:html
Notebook Markdown
此次选Markdown模式(关于Markdown基础能够看以前写的Markdown Base)python
和代码同样,Shift+回车就能够预览了,怎么样是否是很酷的感受?
git
Jupyter NBConvert
生成HTML or Markdown
不闲扯,继续说说NBConvert,默认指令是把.ipynb文件生成html,eg: jupyter nbconvert *.ipynb
若是想要生成指定格式,就加 --to eg:jupyter nbconvert --to markdown *.ipynb编程
这两个是用的比较多的命令,其余的能够参考官方文档
markdown
打开html文件预览一下
编程语言
附带GUI方法:
ide
生成幻灯片
下面说下使用幻灯片演示:函数
先启用幻灯片视图:post
你能够本身设置显示方式,参考:3d
Slide:主页面,经过按左右方向键进行切换
Sub-Slide:副页面,经过按上下方向键进行切换
Fragment:一开始是隐藏的,按空格键或方向键后显示,实现动态效果
Notes:做为演讲者的备忘笔记,不在幻灯片中显示
Skip:不在幻灯片中显示
预览幻灯片:jupyter nbconvert xxx.ipynb --to slides --post serve
若是结合Markdown就真的和写文章同样了,经过上下左右箭头进行演示
魔法操做符
%lsmagic 能够获取全部支持的操做符,也能够参考这篇文章
我这边主要说一下怎么在Python的.ipynb,直接执行C#代码(Jupyter-lab是能够对Cell执行对应的代码)
在Cell使用%%script csharp就能够了
怎么知道对应的名字是什么呢?(通常都是编程语言的名字)
打开终端,输入 jupyter kernelspec list
到对应的目录下看一下便可肯定(友情提醒:隐藏文件请按 Ctrl+H)
NoteBook快捷键
Ctrl + Shift + P 查看快捷键
编辑模式快捷键
Tab键 智能提示
Ctrl + / 注释、取消注释
Shift + Tab键 显示函数提示
Shift + Enter 执行当前块代码
Alt + Endter 执行并插入一行在后面
上箭头、下箭头 移动聚焦的代码块
命令模式快捷键(在编辑框中按ESC便可进入)
f 查找替换
c 复制Cell
x 剪贴Cell
dd 删除代码块
a 在Cell前面插入一行
b 在Cell后面插入一行
m Cell切换成Markdown
v 在Cell后一行粘贴Cell
shift + v 在Cell前一行粘贴Cell
更多内容
导入一个文件里面的内容到Cell
eg: %load test.py
执行以后,内容就进来了,不用你一个个的复制了
你执行就能够定义了
Markdown基础
LaTex基础知识
之后有什么扩充的就加在这吧...
win一直不能打开
若是是安装的Conda,那防火墙放行一下python便可
PS:若是是经过pip安装的,那须要放行一下:jupyter-notebook.exe
思路:有问题就防火墙放行下对应的软件,不行再想办法
-
怎么更改jupyter打开的网页?
2021-06-23 11:01:06更改jupyter打开网页的方法:(推荐:jupyter使用教程)1、打开cmd,输入jupyter notebook --generate-config查看jupyter_notebook_config.py文件路径2、根据返回的路径打开 C:\Users\Administrator\.jupyter\jupyter_...更改jupyter打开网页的方法:(推荐:jupyter使用教程)
1、打开cmd,输入jupyter notebook --generate-config查看jupyter_notebook_config.py文件路径
2、根据返回的路径打开 C:\Users\Administrator\.jupyter\jupyter_notebook_config.py文件
3、在文件中任意位置添加:import webbrowser
webbrowser.register('2345Explorer', None, webbrowser.GenericBrowser(u'D:\\Program Files (x86)\\2345Soft\\2345Explorer\\2345Explorer.exe'))
c.NotebookApp.browser = '2345Explorer'
其中GenericBrowser里的参数是你安装的浏览器的路径
设置好之后在cmd里输入 jupyter notebook,你就会发现启动了相应的浏览器。
更多python知识请关注python视频教程。
-
补之前 如何改变jupyter打开文件的路径
2019-06-12 17:47:00如何改变jupyter打开文件的路径 第一种方法: 第二种方法 第三种方法 如何改变jupyter打开文件的路径 当我们直接打开jupyter时,直接加载的是我们的C盘文件 现在我们想打开其他盘文件夹有三种方法: 第一种... -
使用jupyter notebook直接打开.md格式的文件
2020-11-29 14:08:51jupyter notebook是一个比较比较不错的网页版python编辑器,但是,由于很多“技术文档”都是直接以markdown(.md格式的文件)的格式编写的,而且jupyter notebook的代码文件(.ipynb)也可以转换成.md格式的文件,更为... -
给Jupyter Notebook生成的html文件加导航栏
2021-06-23 11:01:03前面分享过用pyecharts + jupyter notebook制作...接着上回所说,使用jupyter notebook可以制作html格式的分析报告,但是这份报告可能会很长,使用鼠标滚轮翻的话,太费手指头了,我希望能有一个导航栏。像下面这... -
jupyter导出html文件隐藏代码
2021-11-04 18:25:27打开html源码,在他原来的style标签下面加上: <style> .jp-InputArea { display: None; } </style> -
用 jupyter notebook 打开 oui.txt 文件出现的问题及解决方案
2018-12-25 08:44:00问题背景:下载了2018 IEEE 最新的 oui.txt 文件。里面包含了 设备 MAC 地址的前六位对应的厂商。要做的工作是,将海量设备的 MAC 地址与 oui.txt 文件的信息比对,统计出 苹果,华为,小米,OPPO,VIVO 这5家厂商的... -
Jupyter使用与文件操作
2020-04-19 11:51:07• 用适当的统计分析方法对收集来的大量数据进行分析 • 提取有用信息和形成结论 • 对数据加以详细研究和概括总结的过程 数据分析的流程 目的明确——准备数据——数据解析——分析数据——获得结论——成果可视化 ... -
jupyter-django:将Jupyter Notebook与Django结合使用:演示
2021-02-04 07:24:38在Django中使用Jupyter Notebook 这些是我在上演讲时使用的笔记本。 在GitHub上,查看任何.ipynb文件以查看呈现的版本。 或者,克隆存储库,然后在Web浏览器中查看html目录的内容。 请注意,运行这些笔记本需要的... -
Jupyter Notebook 怎样打开指定文件夹(打开指定的工程目录)
2020-05-24 20:28:16直接将文件或文件夹用鼠标拖拽至jupyter快捷键。 方法二 先用CMD 运行以下代码即可 jupyter notebook [文件夹路径] 如果不行,进行一下操作 设置环境变量 将以下三个路径添加至path中 D:\program1\Anaconda D:\... -
解决jupyter无法正常读取xlsx及html文件的方法
2022-03-15 11:41:44使用地址读取文件,C盘下的路径用\\ 第一种方法安装openpyxl或者xlrd,这两个包都是对于excel文件的操作插件,安装方法就是在命令窗口输入pip install openpyxl或者 pip install xlrd。 第二种方法在记事本上... -
jupyter lab文件导出/下载方式
2020-12-20 12:09:42实际上,无论是jupyter lab...右键.ipynb文件,可选择”Open in New Browser Tab”或者”Copy Download Link”,前者是直接将该文件在浏览器中打开,该文件不是浏览器可识别的html文档,因此就会自动下载。后者意为复制 -
jupyter notebook 自动生成python和html文件
2021-06-10 04:37:39命令行中运行ipython locate profile default找到配置文件目录 切到.jupyte目录下新建文件 jupyter_notebook_config.py 粘贴代码到jupyter_notebook_config.py# Based off of# ... -
Jupyter Notebook 怎样打开指定文件夹 详解
2020-02-08 12:44:29电脑默认打开的是home文件 所以不行 参考链接就可以了: https://jingyan.baidu.com/article/7f41ecec78b8cb593d095ca8.html 命令如下: cd /d E:\python深度学习源码\deep-learning-with-python-notebooks-master ... -
Jupyter notebook 读取文件的问题
2019-04-14 23:01:00Jupyter notebook只能打开当前目录下的数据集(txt、CSV等),所以需要把数据集倒导入到当前目录下,导入的方法是 1.文件不大时 直接上传文件。pd.read_csv读取. 2.文件较大时 把数据集拷贝到Jupyter ... -
jupyter无法自动打开浏览器
2021-09-03 16:26:30问题 打开jupyter 的时候总是会遇到以下的窗口提示,...打开窗口中提示的路径,打开新生成的这个文件,在文件的最末尾添加上: import webbrowser webbrowser.register("chrome",None,webbrowser.GenericBrowser(u"C -
anaconda jupyter的打开方式
2021-05-06 20:07:26我搜了一阵子找不到jupyter的打开位置。 我只能退而求其次,在工程文件夹打开cmd,然后conda activate tensorflow1 jupyter-notebook解决 Microsoft Windows [版本 10.0.19042.928] (c) Microsoft Corporation。保留... -
jupyter notebook隐藏导出html文件中的代码
2021-11-04 18:26:02暴力破解。隐藏代码但保留代码运行结果: 打开html源码,在他原来的style标签下面加上: <style> .jp-InputArea { display: None; } </style> 就行了