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的更多相关文章

  1. Converting Python Virtual Machine Code to C

    Converting Python Virtual Machine Code to C

  2. python 调用 C++ code

    本文以实例code讲解python 调用 C++的方法. 1. 如果没有参数传递从python传递至C++,python调用C++的最简单方法是将函数声明为C可用函数,然后作为C code被pytho ...

  3. Pycharm创建Django项目显示python non-zero exit code(1)错误

    好久时间没有做Django的项目了,今天创建项目竟然报Non-zero exit code(1)错误 查明原因是因为pip不是最新版本,需要执行以下命令:python -m pip install - ...

  4. python shopping incomplete code

    #shopping code#shopping.py#导入登录模块import login# shop car beginningsalary = input("请输入工资:\t" ...

  5. python en(de)code

    python爬虫 代码写挺长的,也是边学边写,但一直搞不清楚python的encode(编码)和decode(解码).以下是我的探究之路. 一.当然先看官方文档 地址如下 里面提到encode函数'R ...

  6. python单线程爬虫code

    广度优先算法: # -*- coding: utf-8 -*- import urllib import urllib.request from bs4 import BeautifulSoup im ...

  7. facebook视频上传python 返回错误code:100,'type':OAuthException

    首先重新获取访问口令token: https://developers.facebook.com/tools/debug/accesstoken/?q=EAAYDuzyd3eYBAK9lZCErZBl ...

  8. python参数Sample Code

    import time import datetime import getopt import sys try: opts, args = getopt.getopt(sys.argv[1:], & ...

  9. Python with VS Code

    1. 基本的代码结构为: 2.

随机推荐

  1. [ linux ] pad远程

    ---恢复内容开始--- ssh: serverauditor vnc:vnc viewer ubuntu: sudo apt-get install x11vnc sudo apt-get inst ...

  2. webClient请求JAVA超时解决方案

    private class MyWebClient: WebClient { protected override WebRequest GetWebRequest(Uri uri) { WebReq ...

  3. 康力优蓝机器人 -- 优友U05类人型机器人发布

    [寒武计划]优友U05类人型机器人发布: http://digi.tech.qq.com/a/20151124/043234.htm?pgv_ref=aio2015&ptlang=2052 北 ...

  4. 部署tomcat在windows服务器下,将tomcat控制台日志记录到日志文件中

    在Linux系统中,Tomcat 启动后默认将很多信息都写入到 catalina.out 文件中,我们可以通过tail  -f  catalina.out 来跟踪Tomcat 和相关应用运行的情况. ...

  5. wireshark解密本地https流量笔记

    此方式支持firefox,chrome 建立path变量 SSLKEYLOGFILE=c:\ssl.key 重启firefox chrome,访问https网站会自动生成ssl session key ...

  6. Word2010撤销按钮失效,Ctrl+Z失效解决办法

    1.打开注册表编辑器.按Win+R,在运行框中键入regedit,然后单击“确定”. 2.在注册表编辑器中,展开到下列注册表子项: HKEY_CURRENT_USER\Software\Microso ...

  7. CSS3实现倒计时

    CSS3实现倒计时小程序,界面如下: 代码如下: <style> body,html{ margin:0px; height:100%; } body{background: #000; ...

  8. 在Visual Studio 2010中进行“项目重命名”的有效工具

    地址:http://www.cnblogs.com/dudu/archive/2011/12/11/visual_studio_2010_project_rename.html 提示:这个工具一次 r ...

  9. fusioncharts图例(legend)属性

    图例用来在多系列图和混合图中将图形和对应的系列名称联系起来.      从v3.2开始,每个系列的名称前面会展示对应的icon图标,这些图标具有交互作用,用户可以通过点击这些图标来显示或者隐藏对应的数 ...

  10. codeforces MUH and Cube Walls

    题意:给定两个序列a ,b, 如果在a中存在一段连续的序列使得 a[i]-b[0]==k, a[i+1]-b[1]==k.... a[i+n-1]-b[n-1]==k 就说b串在a串中出现过!最后输出 ...