【问题标题】:Python: How to solve bracket not closed errorPython:如何解决括号未关闭错误
【发布时间】:2022-08-06 06:17:56
【问题描述】:

按照教程,我在使用完全相同的代码时遇到错误 \"(\" is not closed :

compiled_sol = compile_standard(
  {
      \"language\": \"Solidity\",
      \"sources\": {\"SimpleStorage.sol\": {\"content\" = simple_storage_file}}
  }
)

不知道哪里出错了得到这些错误:

\"{\" was not closedPylance
Expected parameter namePylance

Expected parameter namePylance

    标签: python


    【解决方案1】:

    尝试将“=”替换为“:”我希望这可以解决问题。

    【讨论】:

      【解决方案2】:

      正如@adammaly004 提到的,你不能在python 字典中有=。将 "content" = simple_storage_file 替换为 "content": simple_storage_file 应该可以解决您的问题。

      完整示例:

      compiled_sol = compile_standard(
        {
            "language": "Solidity",
            "sources": {"SimpleStorage.sol": {"content": simple_storage_file}}
        }
      )
      
      

      【讨论】:

      • 如果在现有的dict 中定义键/值,则可以使用等号,如d['key1'] = 'val1',但不能使用更高效的{…} 构造函数,如上所述。可能是 OP 感到困惑的地方(?)。
      【解决方案3】:

      事情是你不能在一个字典中有一个“=”,你从{}而不是这个dict()构造它

      这是两者的示例

      1.

      compiled_sol = compile_standard(
          {
              "language": "Solidity",
              "sources": {
                  "SimpleStorage.sol": {
                      "content": simple_storage_file
                  }
              }
          }
      )
      

      您不能在上面的构造函数中使用“=”符号 2.

      compiled_sol = compile_standard(
          dict(
              languages="Solidity",
              sources = dict(
                  SimpleStorage.sol = dict(
                      content = simple_storage_file)
              )
          )
      )
      

      在您的情况下,第二种方法将不起作用,因为当您在 Python 认为它类似于模块或类的东西中有 . 时,您在 SimpleStorage 中有一个 . 所以这就是为什么这种方法不适用于这种情况

      但是很方便知道

      【讨论】:

        【解决方案4】:

        我也面临同样的问题。我修复之前的代码

        from django.urls import include, re_path
        from EmployeeApp import views
        
        urlpatterns = [
            re_path(r'^department/$',views.departmentApi),
            re_path(r'^department/([0-9]+)$',views.departmentApi)
        
             re_path(r'^employee/$',views.employeeApi),
            re_path(r'^employee/([0-9]+)$',views.employeeApi)
        ] 
        
        
        ```
         i was getting this error, "[" is not closed 
        File "F:\Programming\DjangoAngularTutorial\DjangoAPI\EmployeeApp\urls.py", line 6
            re_path(r'^department/([0-9]+)$',views.departmentApi)
        
        

        我通过在第 6 行添加

        from django.urls import include, re_path
        from EmployeeApp import views
        
        urlpatterns = [
            re_path(r'^department/$',views.departmentApi),
            re_path(r'^department/([0-9]+)$',views.departmentApi),
        
             re_path(r'^employee/$',views.employeeApi),
            re_path(r'^employee/([0-9]+)$',views.employeeApi)
        ]  
        
        
        

        【讨论】:

          猜你喜欢
          • 2021-05-27
          • 1970-01-01
          • 1970-01-01
          • 2020-05-10
          • 1970-01-01
          • 2014-03-19
          • 2015-03-23
          • 2014-09-05
          • 1970-01-01
          相关资源
          最近更新 更多