teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

文法の修正

2020/10/13 11:12

投稿

toast-uz
toast-uz

スコア3266

answer CHANGED
@@ -12,12 +12,9 @@
12
12
  import asyncio
13
13
 
14
14
  class Hoge:
15
- def __init__(self):
15
+ async def connect(self, uri):
16
- self.uri = 'ws://localhost:8000/'
16
+ self.ws : websockets.WebSocketCommonProtocol = await websockets.connect(uri)
17
17
 
18
- async def connect(self):
19
- self.ws : websockets.WebSocketCommonProtocol = await websockets.connect(self.uri)
20
-
21
18
  def __aiter__(self):
22
19
  return self
23
20
 
@@ -27,7 +24,7 @@
27
24
 
28
25
  async def main():
29
26
  hoge = Hoge()
30
- await hoge.connect()
27
+ await hoge.connect('ws://localhost:8000/')
31
28
  async for msg in hoge:
32
29
  print(msg)
33
30