Python on VS Code
install python extension
- Press F1, and input "ext install python".
- Then the icon at the leftmost side of the status bar is saying that something is being installed.
- Need to wait a while.
- Use command "ext" + a space to see installed extensions.
use markdown as document
VS Code supports markdown files.
Ctrl+K, V : markdown: Open Preview to the side
Ctrl+Shift+V : markdown: Toggle Preview
create a python project
- Select File -> Open Folder...
- Create a tasks.json file under the .vscode folder in the project folder
- Input below in the task.json file
// A task runner that runs a python program
{
"version": "0.1.0",
"command": "python",
"showOutput": "always",
"windows": {
"command": "python.exe"
},
"args": ["${file}"]
}
integrate with git
- Make sure you have a repository on the server.
- Install a git tool
- Go to the project directory, open a command window, and run:
# initialize a git repository
git init
# set a remote with name origin
git remote add origin [https://github.com/<username>/<repository>]
# fetch the master branch files from the remote
git pull origin master
- Start VS Code
- Use the Git panel to work with the remote.
run a python file
- Open the python file.
- Press Ctrl+Shift+B.
debug
- F9 : add/remove a breakpoint.
- F5 or Ctrl + F5 : start debug
- F5 : continue
- F10 : step over
- F11 : step into
- Shift + F11 : step out
- Ctrl + Shift + F10 : restart
- Shift + F5 : stop
print Chinese words, but see question marks in the output console
The issue can be resolved by the following code:
import io
import os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
Threading
Please see
http://www.tutorialspoint.com/python/python_multithreading.htm
Example: Execute at most 10 threads in a thread pool
from concurrent.futures import *
...
with ThreadPoolExecutor(max_workers=10) as executor:
for url in urls :
try:
i += 1
future = executor.submit(self.get_url, url)
future.add_done_callback(threadCallbackHandler(url).handle_callback)
except Exception as e:
print("Failed {0}. {1}".format(url, e))
# wait all threads finish.
executor.shutdown(wait=True)
class threadCallbackHandler:
def __init__(self, url):
self.url = url
def handle_callback(self, future) :
try:
if (future.exception() != None):
print("Failed {0}. Exception : {1}".format(self.url, future.exception()))
except CancelledError as e:
print("Cancelled {0}".format(self.url))
print("Done {0}".format(self.url))
Python on VS Code的更多相关文章
- Converting Python Virtual Machine Code to C
Converting Python Virtual Machine Code to C
- python 调用 C++ code
本文以实例code讲解python 调用 C++的方法. 1. 如果没有参数传递从python传递至C++,python调用C++的最简单方法是将函数声明为C可用函数,然后作为C code被pytho ...
- Pycharm创建Django项目显示python non-zero exit code(1)错误
好久时间没有做Django的项目了,今天创建项目竟然报Non-zero exit code(1)错误 查明原因是因为pip不是最新版本,需要执行以下命令:python -m pip install - ...
- python shopping incomplete code
#shopping code#shopping.py#导入登录模块import login# shop car beginningsalary = input("请输入工资:\t" ...
- python en(de)code
python爬虫 代码写挺长的,也是边学边写,但一直搞不清楚python的encode(编码)和decode(解码).以下是我的探究之路. 一.当然先看官方文档 地址如下 里面提到encode函数'R ...
- python单线程爬虫code
广度优先算法: # -*- coding: utf-8 -*- import urllib import urllib.request from bs4 import BeautifulSoup im ...
- facebook视频上传python 返回错误code:100,'type':OAuthException
首先重新获取访问口令token: https://developers.facebook.com/tools/debug/accesstoken/?q=EAAYDuzyd3eYBAK9lZCErZBl ...
- python参数Sample Code
import time import datetime import getopt import sys try: opts, args = getopt.getopt(sys.argv[1:], & ...
- Python with VS Code
1. 基本的代码结构为: 2.
随机推荐
- HTML5新特性之跨文档消息传输
1.同域限制 所谓“同域限制”是指,出于安全考虑,浏览器只允许脚本与同样协议.同样域名.同样端口的地址进行通信. 2.window.postMessage方法 浏览器限制不同窗口(包括iFrame窗口 ...
- JSONP跨域请求数据报错 “Unexpected token :”的解决办法
原文 http://www.cnphp6.com/archives/65409 Jquery使用ajax方法实现jsonp跨域请求数据的时候报错 “Uncaught SyntaxError: Une ...
- angularjs, nodejs, express, gulp, karma, jasmine 前端方案整合
今年转向做前端开发,主要是做angularjs开发,期间接触了nodejs平台,从此一发不可收拾. npm丰富的插件库,express 开发框架, grunt, gulp构建工具,karma测试管理工 ...
- sizeof()用法汇总
sizeof()功能:计算数据空间的字节数 1.与strlen()比较 strlen()计算字符数组的字符数,以"\0"为结束判断,不计算为'\0'的数组元素. ...
- [z] 人工智能和图形学、图像处理方面的各种会议的评级
转载自:『http://www.cvchina.info/2010/08/31/conference-ranking-byar/』 澳大利亚政府和澳大利亚研究理事会做的,有一定考价值. 会议名称 会议 ...
- wireshark解密本地https流量笔记
此方式支持firefox,chrome 建立path变量 SSLKEYLOGFILE=c:\ssl.key 重启firefox chrome,访问https网站会自动生成ssl session key ...
- 【软件分析与挖掘】Multiple kernel ensemble learning for software defect prediction
摘要: 利用软件中的历史缺陷数据来建立分类器,进行软件缺陷的检测. 多核学习(Multiple kernel learning):把历史缺陷数据映射到高维特征空间,使得数据能够更好地表达: 集成学习( ...
- 使用Python画ROC曲线以及AUC值
from:http://kubicode.me/2016/09/19/Machine%20Learning/AUC-Calculation-by-Python/ AUC介绍 AUC(Area Unde ...
- MyBatis知多少(10)应用程序数据库
应用程序数据库往往是最小.最简单.也最易于使用的数据库.这种数据库往往是我们这些开发人员通常不介意使用甚至非常乐意使用的.应用程序数据库通常与我们的应用程序处于同一个项目中,两者一齐设计和实现.正是因 ...
- 在android中如何通过点击edittext之外的部分使软键盘隐藏
我们知道在android中点击edittext框就会自动弹出软键盘,那怎么通过点击edittext之外的部分使软键盘隐藏呢?(微信聊天时的输入框就是这个效果,这个给用户的体验还是很不错的) 首先我们要 ...