Python on VS Code
2016-05-06 23:38
330 查看
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 seehttp://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的学习笔记(四)(MySQL数据库的操作)
- python爬虫 之 wooyun公开漏洞
- python小白-day15 Django基础
- python中的enumerate()函数
- 一步步分析百度音乐的播放地址,利用Python爬虫批量下载
- Python的学习笔记(三)(文件处理)
- 输入和输出
- PIP安装Python的scipy,scrapy等包出现“failed building wheel for xxx”问题解决办法
- python 迭代器与生成器 详解
- python小白-day15 web框架
- python运算符
- Python正则表达式指南
- python中的json的基本使用方法
- python中的json的基本使用方法
- python中的json的基本使用方法
- 理解 Python 的执行方式,与字节码 bytecode 玩耍 (下)
- python 爬取一页商品数据
- python数据分析师面试题选
- 轻松自动化---selenium-webdriver(python) (一)
- 好吧我承认最近一直入门python! 关于python3 和 python2 List 的一点区别 以及python 通过enumerate 内建函数遍历List