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. iOS 内存管理机制和循环引用处理方法

    简述 ARC: 自动引用计数, Automatic Reference Counting MRC: Mannul Reference Counting ARC工作原理 1.当每次创建一个新实例时,AR ...

  2. SAP顾问发展

    关于SAP顾问发展的话题也不仅仅是一次的谈起,但是我想对于自己的规划很多人是否有没有深刻的考虑过.这对于你我来说都非常的重要,那么作为我来说,我仅仅把自己的观点阐述以供大家思考,希望对大家能有所帮助. ...

  3. 为Eclipse添加Java和Android SDK源代码

    1.添加jdk源码进入eclipse Ctrl + Click -->Attached Source 路径:D:\Program Files\Java\jdk1.8.0_45\src.zip 2 ...

  4. 精选19款华丽的HTML5动画和实用案例

    下面是本人收集的19款超酷HTML5动画和实用案例,觉得不错,分享给大家. 1.HTML5 Canvas火焰喷射动画效果 还记得以前分享过的一款HTML5烟花动画HTML5 Canvas烟花特效,今天 ...

  5. -webkit-min-device-pixel-ratio的常见值对照

    -webkit-min-device-pixel-ratio为1.0 所有非Retina的Mac 所有非Retina的iOS设备 Acer Iconia A500 Samsung Galaxy Tab ...

  6. Skynet Pomelo Erlang Elixir 的认识

    1.skynet pomelo(node.js) elixir(erlang) 周末研究总结 手游这两年发展来看,感觉对实时性要求越来越高,有同事在研究Elixir开发,google得知这东西是基于e ...

  7. WinStore之Application Data

    一.Application Data简介 Applicaion Data相当于桌面应用的注册表,存储一些用户配置信息,如运行时状态,用户喜好等,需要注意的时,当卸载应用时,这些数据会被删除,所以不要存 ...

  8. 使用 Portable Class Library(可移植类库)开发 Universal Windows App

    今天在这里跟大家聊聊关于 Windows Universal 应用夸平台的问题,首先Universal Windows App的定义相信大家已经有所了解了(如果你是一个刚刚接触 Universal A ...

  9. BAPI 调用相当于BAPI_TRANSACTION_COMMIT 的方法

    为什么.net调用SAP的BAPI接口需要调用BAPI_TRANSACTION_COMMIT呢?首先得明白BAPI_TRANSACTION_COMMIT这个BAPI的作用.它功劳很大,在SAP里面很多 ...

  10. ReentrantLock的使用

    class BoundedBuffer { final Lock lock = new ReentrantLock(); final Condition notFull = lock.newCondi ...