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.
随机推荐
- asp.net首页设置
在web.config中设置首页 <configuration> <system.web> <compilation debug="true" tar ...
- [Z]The Boost C++ Libraries
看起来是个学习boost非常不错的材料,应该是boost的官方教程之类: http://theboostcpplibraries.com/
- GDC2014免费slide整理下载
GDC2014图形和程序相关的部分免费slide整理下载:)http://pan.baidu.com/s/1eQzMrxo gdc14_An Indie Approach to procedural ...
- HP P1008打印机如何打印特殊纸张
一.问题的提出 HP P1008中间有一个进纸槽,这是干什么的? 二.问题的分析 查说明,说这个进纸槽是叫做优先进纸槽,用于各种非常规的纸张的打印. 三.问题的解决 弄一张特殊尺寸的纸张,打开要编辑的 ...
- Log4net介绍
一.Log4net介绍 log4net是一个功能著名的开源日志记录组件.利用log4net可以方便地将日志信息记录到文件.控制台.Windows事件日志和数据库(包括MS Server,Access, ...
- REHL5.5 linux的postfix的邮件服务器配置 (笔记)
一.发送邮件服务器(smtp服务器) 1.系统安装时已经有postfix. 2.修改配置 1)vi main.cf //你可以先备份一下配置文件 myhostname = INMSC2//修改为你的主 ...
- WPF中模板选择和DataContext的一些使用
如图样: View结构 MainView(MainViewModel)|---Guide1View(Guide1ViewModel)|---Guide2View(Guide2ViewModel) |- ...
- ActivityGroup里面装的子Activity不执行OnActivityResult()的解决办法
转自http://blog.csdn.net/snakewarhead/article/details/7976831 tab activity 中调用startActivityForResult 以 ...
- [Design Patterns] 3. Software Pattern Overview
When you're on the way which is unknown and dangerous, just follow your mind and steer the boat. 软件模 ...
- debian系统root用户登录
Debian默认不允许root登录,所以修改之. 让Debian以root登录 1).首先修改gdm3的设定文件(/etc/gdm3/deamon.conf),在[security]字段后面追加如下一 ...