久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='psFPL'><tr id='psFPL'><dt id='psFPL'><q id='psFPL'><span id='psFPL'><b id='psFPL'><form id='psFPL'><ins id='psFPL'></ins><ul id='psFPL'></ul><sub id='psFPL'></sub></form><legend id='psFPL'></legend><bdo id='psFPL'><pre id='psFPL'><center id='psFPL'></center></pre></bdo></b><th id='psFPL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='psFPL'><tfoot id='psFPL'></tfoot><dl id='psFPL'><fieldset id='psFPL'></fieldset></dl></div>
    <bdo id='psFPL'></bdo><ul id='psFPL'></ul>
  • <legend id='psFPL'><style id='psFPL'><dir id='psFPL'><q id='psFPL'></q></dir></style></legend>

        <tfoot id='psFPL'></tfoot>

        <small id='psFPL'></small><noframes id='psFPL'>

      1. 帶有 async def 的 Python [無效語法]

        Python [Invalid syntax] with async def(帶有 async def 的 Python [無效語法])
        <tfoot id='bsiDD'></tfoot>

          <tbody id='bsiDD'></tbody>
      2. <i id='bsiDD'><tr id='bsiDD'><dt id='bsiDD'><q id='bsiDD'><span id='bsiDD'><b id='bsiDD'><form id='bsiDD'><ins id='bsiDD'></ins><ul id='bsiDD'></ul><sub id='bsiDD'></sub></form><legend id='bsiDD'></legend><bdo id='bsiDD'><pre id='bsiDD'><center id='bsiDD'></center></pre></bdo></b><th id='bsiDD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bsiDD'><tfoot id='bsiDD'></tfoot><dl id='bsiDD'><fieldset id='bsiDD'></fieldset></dl></div>

        <legend id='bsiDD'><style id='bsiDD'><dir id='bsiDD'><q id='bsiDD'></q></dir></style></legend>

                • <bdo id='bsiDD'></bdo><ul id='bsiDD'></ul>

                  <small id='bsiDD'></small><noframes id='bsiDD'>

                  本文介紹了帶有 async def 的 Python [無效語法]的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用 Python 編寫 discord 機器人,我遇到了這個機器人并將其拼湊在一起.

                  I am trying write discord bots using Python, I have come across and threw together this bot.

                  import discord
                  import asyncio
                  import random
                  
                  client = discord.Client()
                  inEmail = input("Email:")
                  inPassword = input("Passwd:")
                  
                  async def background_loop():
                      await client.wait_until_ready()
                      while not client.is_closed:
                          channel = client.get_channel("************")
                          messages = ["Hello!", "How are you doing?", "Testing!!"]
                          await client.send_message(channel, random.choice(messages))
                          await asyncio.sleep(120)
                  
                  client.loop.create_task(background_loop())
                  client.run(inEmail, inPassword)
                  

                  然而,當我嘗試運行它時,我收到了一個 SyntaxError:

                  Yet when I tried to run it, I received a SyntaxError:

                  File "1.py", line 7
                    async def background_loop():
                       ^
                  SyntaxError: invalid syntax
                  

                  這是為什么呢?我之前測試時從未收到過.

                  Why is that? I have never received that before when I tested it.

                  推薦答案

                  2021 年更新答案(discord.py 1.x - 2.x):

                  discord.py 目前支持 Python 3.5 及更高版本.如果您收到 SyntaxError,則表示您使用的是舊版本的 Python,并且不被 discord.py 支持.

                  Updated answer for 2021 (discord.py 1.x - 2.x):

                  discord.py currently supports Python 3.5 and up. If you receive a SyntaxError, it means you're using an older version of Python and isn't supported by discord.py.

                  首先,安裝更高版本的 Python(在此消息中首選 3.8.x),然后運行 ??python3.8 bot.pypy -3.8 bot.py(適用于 Windows).注意:安裝時不要忘記選擇Add Python to PATH".

                  First, install a later version of Python (3.8.x is preferred as of this message), and run python3.8 bot.py or py -3.8 bot.py (for Windows) when running your bot. Note: when installing, don't forget to choose "Add Python to PATH".

                  在 v3.3 中將異步請求引入 Python,如果如果您運行的是 v3.3 之前的 Python(包括 v2.X),則必須安裝更新版本的 Python.

                  Asynchronous requests were introduced to Python in v3.3, if you're running Python prior to v3.3 (including v2.X), you'll have to install a newer version of Python.

                  在您運行 Python 3.3 時:asyncio 不是標準庫的一部分,你需要從 pypi 手動安裝它:

                  Only if you are running Python 3.3: asyncio is not part of the stdlib, you'll need to install it manually from pypi:

                  pip install asyncio
                  

                  asyncawait 關鍵字僅對 Python 3.5 或更新版本有效.如果您使用的是 Python 3.3 或 3.4,則需要對代碼進行以下更改:

                  The async and await keywords are only valid for Python 3.5 or newer. If you're using Python 3.3 or 3.4, you will need to make the following changes to your code:

                  1. 使用 @asyncio.coroutine 裝飾器代替 async 語句:
                  1. Use the @asyncio.coroutine decorator instead of the async statement:

                  async def func():
                      pass
                  
                  # replace to:
                  
                  @asyncio.coroutine
                  def func():
                      pass
                  

                  1. 使用 yield from 而不是 await:
                  1. Use yield from instead of await:

                  await coroutine() 
                  
                  # replace to:
                  
                  yield from coroutine()
                  

                  這是您的函數需要更改為的示例(如果您使用的是 3.3-3.4):

                  Here is an example of what your function need to change into (if you're on 3.3-3.4):

                  import asyncio
                  
                  @asyncio.coroutine 
                  def background_loop():
                      yield from client.wait_until_ready()
                      while not client.is_closed:
                          channel = client.get_channel("************")
                          messages = ["Hello!", "How are you doing?", "Testing!!"]
                          yield from client.send_message(channel, random.choice(messages))
                          yield from asyncio.sleep(120)
                  

                  較新版本的 Python 3 仍然支持上述語法,但如果不需要支持 Python 3.3-3.4,建議使用 awaitasync.您可以參考這個 文檔,這里有一個簡短的片段:

                  The aforementioned syntax is still supported in newer versions of Python 3, but it is recommended to use await and async if there's no need to support for Python 3.3-3.4. You can refer back to this documentation, here's a short snippet:

                  async def 類型的協程是在 Python 3.5 中添加的,并且是如果不需要支持較舊的 Python 版本,建議使用.

                  The async def type of coroutine was added in Python 3.5, and is recommended if there is no need to support older Python versions.


                  旁白:

                  discord.py 目前支持 3.4.2-3.6.6,(不支持 3.3-3.4.1,截至 2019 年 1 月為 3.7).


                  Aside:

                  discord.py currently supports 3.4.2-3.6.6, (It does not support 3.3-3.4.1, 3.7 as of January 2019).

                  對于使用 discord.py 進行開發,我建議使用 discord.py 重寫分支:

                  For developing with discord.py, I suggest using the discord.py rewrite branch:

                  discord.py-重寫支持3.5.3-3.7.

                  discord.py-rewrite supports 3.5.3-3.7.

                  這篇關于帶有 async def 的 Python [無效語法]的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

                      <legend id='b8ol6'><style id='b8ol6'><dir id='b8ol6'><q id='b8ol6'></q></dir></style></legend>
                    1. <tfoot id='b8ol6'></tfoot>
                        <tbody id='b8ol6'></tbody>

                        <small id='b8ol6'></small><noframes id='b8ol6'>

                        <i id='b8ol6'><tr id='b8ol6'><dt id='b8ol6'><q id='b8ol6'><span id='b8ol6'><b id='b8ol6'><form id='b8ol6'><ins id='b8ol6'></ins><ul id='b8ol6'></ul><sub id='b8ol6'></sub></form><legend id='b8ol6'></legend><bdo id='b8ol6'><pre id='b8ol6'><center id='b8ol6'></center></pre></bdo></b><th id='b8ol6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='b8ol6'><tfoot id='b8ol6'></tfoot><dl id='b8ol6'><fieldset id='b8ol6'></fieldset></dl></div>

                        • <bdo id='b8ol6'></bdo><ul id='b8ol6'></ul>

                            主站蜘蛛池模板: 精品欧美一区二区精品久久久 | 91免费版在线 | 日韩中文字幕一区二区 | 精品久久久久国产免费第一页 | 一区二区三区免费网站 | 天天操天天玩 | 日韩精品视频中文字幕 | 在线观看亚洲专区 | 成年人免费在线视频 | 黄色一级片在线播放 | 日韩在线观看精品 | 欧美做暖暖视频 | 久久久久久国模大尺度人体 | 亚洲国产成人精品久久久国产成人一区 | 日本中出视频 | 国产一区二区久久 | 久久久久久国产精品免费免费 | 欧美一区二区免费 | 午夜在线免费观看 | 玩丰满女领导对白露脸hd | 欧美日韩久久久久 | 国产精品jizz在线观看老狼 | 一级做a爰片性色毛片16美国 | 91欧美激情一区二区三区成人 | 99久久精品免费 | 国产伦精品一区二区三区精品视频 | 自拍偷拍第1页 | 日本电影免费完整观看 | 午夜电影网| 欧美久久久 | 曰批视频在线观看 | 欧美午夜视频 | 午夜国产一级 | 欧美成人a∨高清免费观看 欧美日韩中 | 国产乱码精品一区二区三区中文 | 日韩在线一区二区三区 | 日韩成人在线免费视频 | 二区中文 | 午夜日韩 | 欧美日韩一区在线观看 | 黄片毛片免费观看 |