zoukankan      html  css  js  c++  java
  • 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)) 
    
  • 相关阅读:
    mac 10.15.7 修改PATH
    oc 属性类型一般用法
    ubuntu解压zip文件名乱码
    telnet 退出
    docker 根据容器创建镜像
    mac android adb device 没有显示设备
    Yii2 查看所有的别名 alias
    Yii2 App Advanced 添加 .gitignore
    ubuntu 18.04 搜狗突然就提示乱码
    An error occured while deploying the file. This probably means that the app contains ARM native code and your Genymotion device cannot run ARM instructions. You should either build your native code to
  • 原文地址:https://www.cnblogs.com/steven-yang/p/5467490.html
Copyright © 2011-2022 走看看