代码之家  ›  专栏  ›  技术社区  ›  Jas

语法错误:变量批注的语法无效

  •  8
  • Jas  · 技术社区  · 7 年前

    code runner

    text: str = "slkdfjsd"
    

    CTRL-ALT-N

        text: str = "slkdfjsd"
            ^
    SyntaxError: invalid syntax
    

    更多详细信息:

    $ /usr/bin/env python3 --version
    Python 3.6.6 :: Anaconda, Inc.
    

    [Running] /usr/bin/env python3 "/home/myuser/dev/projects/python-snippets/text-summarization"
      File "/home/myuser/dev/projects/python-snippets/text-summarization", line 44
        text: str = "slkdfjsd"
            ^
    SyntaxError: invalid syntax
    

    代码运行程序插件文档说:

    $pythonPath Python: Select Interpreter command )

    sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)
    

    >python: select interpreter 我已经选择了。

    >python:选择解释器

    python

    {
        "git.autofetch": true,
        "terminal.integrated.rendererType": "dom",
        "code-runner.executorMap": {
            "javascript": "node",
            "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
            "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
            "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
            "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
            "php": "php",
            "python": "/home/user/home/user/dev/anaconda3/envs/pymachine/bin/python",
            "perl": "perl",
            "perl6": "perl6",
            "ruby": "ruby",
            "go": "go run",
            "lua": "lua",
            "groovy": "groovy",
            "powershell": "powershell -ExecutionPolicy ByPass -File",
            "bat": "cmd /c",
            "shellscript": "bash",
            "fsharp": "fsi",
            "csharp": "scriptcs",
            "vbscript": "cscript //Nologo",
            "typescript": "ts-node",
            "coffeescript": "coffee",
            "scala": "scala",
            "swift": "swift",
            "julia": "julia",
            "crystal": "crystal",
            "ocaml": "ocaml",
            "r": "Rscript",
            "applescript": "osascript",
            "clojure": "lein exec",
            "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
            "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
            "racket": "racket",
            "ahk": "autohotkey",
            "autoit": "autoit3",
            "dart": "dart",
            "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
            "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
            "haskell": "runhaskell",
            "nim": "nim compile --verbosity:0 --hints:off --run"
          }
    }
    

    [Running] /usr/bin/env python3 "/home/myuser/dev/projects/python-snippets/text-summarization"
    
    1 回复  |  直到 7 年前
        1
  •  4
  •   Taku    7 年前

    3.6+


    SyntaxError docs

    text

    https://tio.run/##K6gsycjPM/7/X4OrJLWixEqhuKRIwVZBXf3/fwA

    (
    text: str = ''
    

    :

      File ".code.tio", line 2
        text: str = ''
            ^
    SyntaxError: invalid syntax
    

    text: str {

    {
    text: str = ''
    

      File ".code.tio", line 2
        text: str = ''
                  ^
    SyntaxError: invalid syntax