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. thinking in object pool

    1.背景 对象池为了避免频繁创建耗时或耗资源的大对象,事先在对象池中创建好一定数量的大对象,然后尽量复用对象池中的对象,用户用完大对象之后放回对象池. 2.问题 目前纵观主流语言的实现方式无外乎3个步 ...

  2. Android开发(51) 摄像头自动对焦。在OpenCV图像识别中连续拍照时自动对焦和拍照。

    概述 对焦,这里所说的“焦”是指“焦距”.在拍照时,一定是需要调焦的.一般会在目标位置最清晰的时候会停止对焦.最近在处理OpenCV进行图像识别时,需要连续的调焦(对焦),并在对焦完成后进行拍照,获取 ...

  3. JS/React 判断对象是否为空对象

    JS一般判断对象是否为空,我们可以采用: if(!x)的方式直接判断,但是如果是一个空对象,比如空的JSON对象,是这样的:{},简单的判断是不成功的,因为它已经占用着内存了,如果是JQuery的话, ...

  4. ODAC(V9.5.15) 学习笔记(十五)数据离线模式

    数据离线模式(Disconnected Mode)是指数据库只有在需要的时候才连接,数据的处理放在客户端内存缓冲区中完成.这样做最大的好处是减少了网络资源依赖,对数据库服务器的资源开销和压力也减少.如 ...

  5. caffe上使用hdf5格式文件以及回归(regression)问题

    最近用caffe做了一下regression问题,先用data layer中的data,float_data试了一下,data用来存放图片,float_data存放regression的values, ...

  6. UIWebView 操作

    网络开发中,当公司已经使用 HTML5 技术实现同时适应 Android 和 iOS 等多个平台的网页时,这时往往需要我们 iOS 平台能够嵌入网页并进行各种交互,那我们应该怎么做来实现这种需求呢? ...

  7. 最近想上游戏,弄了个工作室,名"柑谷工作室"

    最近想上游戏,弄了个工作室,名"柑谷工作室",名字取得有点随便,原因是好名字都让狗用了.想当年我用的龙纹工作室,现在龙纹两字也被人用了.人家有硅谷,然后我弄个柑谷,差不多吧.算了, ...

  8. JIRA数据库切换(HSQL Database到MySQL)

    没试过的版本,但是看着靠谱: 注:如果你之前配置过hsql版本,这次修改mysql数据操作会导致配置数据丢失,所以请注意备份 一. 创建名为jiradb的mysql数据,编码格式为utf-8 二.修改 ...

  9. thinkphp 3.2.3+Admin LTE后台框架

  10. EFW框架源代码版本升级记录说明

    回<[开源]EFW框架系列文章索引>        EFW框架源代码下载V1.3:http://pan.baidu.com/s/1c0dADO0 EFW框架实例源代码下载:http://p ...