前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python on VS Code

Python on VS Code

作者头像
绿巨人
发布2018-05-16 17:55:30
1.1K0
发布2018-05-16 17:55:30
举报

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)) 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-05-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • install python extension
  • use markdown as document
  • create a python project
  • integrate with git
  • run a python file
  • debug
  • print Chinese words, but see question marks in the output console
  • Threading
    • Example: Execute at most 10 threads in a thread pool
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档