from dotenv import load_dotenv
import os
from googleapiclient.discovery import build
import json
load_dotenv()
class Channel:
"""Класс для ютуб-канала"""
youtube = build('youtube', 'v3', developerKey=os.getenv("API_YOU_TUBE"))
def __init__(self, channel_id: str) -> None:
"""Экземпляр инициализируется id канала. Дальше все данные будут подтягиваться по API."""
self.__channel_id = channel_id
self.title = self.get_data_init()["items"][0]["snippet"]["title"]
self.description = self.get_data_init()["items"][0]["snippet"]["description"]
self.url = "https://www.youtube.com/channel/" + self.get_data_init()["items"][0]["id"]
self.subscriber_count = self.get_data_init()["items"][0]["statistics"]["subscriberCount"]
self.video_count = self.get_data_init()["items"][0]["statistics"]["videoCount"]
self.view_count = self.get_data_init()["items"][0]["statistics"]["viewCount"]
def print_info(self) -> None:
"""Выводит в консоль информацию о канале."""
channel = self.youtube.channels().list(id=self.__channel_id, part='snippet,statistics').execute()
print(channel)
def get_data_init(self):
channel = self.youtube.channels().list(id=self.__channel_id, part='snippet,statistics').execute()
return channel
@staticmethod
def get_service():
return Channel.youtube
def to_json(self, data):
with open(data, "w") as f:
f.write(str(self.get_data_init()))
def __repr__(self):
return f"{self.__channel_id}, {self.subscriber_count}"
moscowpython = Channel('UC-OVMPlMA3-YCIeg4z5z23A')
moscowpython.__channel_id = 'Новое название'
print(moscowpython.__channel_id)
print(moscowpython)
# не выдает никаких ошибок, хотя должна AttributeError```
Изменено:
вот так выдает ошибку:
moscowpython = Channel('UC-OVMPlMA3-YCIeg4z5z23A')
print(moscowpython.__channel_id)
moscowpython.__channel_id = 'Новое название'
print(moscowpython.__channel_id)
print(moscowpython)
а вот так нет:
moscowpython = Channel('UC-OVMPlMA3-YCIeg4z5z23A')
# print(moscowpython.__channel_id)
moscowpython.__channel_id = 'Новое название'
print(moscowpython.__channel_id)
print(moscowpython)
主页
/
user-535297
extract's questions
(venv) damir@damir-WARD-H202:~/Desktop/electronics-shop-project-main$ python3 homework-1/main.py
Traceback (most recent call last):
File "/home/damir/Desktop/electronics-shop-project-main/homework-1/main.py", line 1, in <module>
from src.item import Item
ModuleNotFoundError: No module named 'src'
├── homework-1
│ ├── main.py
│ └── README.md
├── homework-2
│ ├── main.py
│ └── README.md
├── homework-3
│ ├── main.py
│ └── README.md
├── homework-4
│ ├── main.py
│ └── README.md
├── homework-5
│ ├── main.py
│ └── README.md
├── homework-6
│ ├── main.py
│ └── README.md
├── pyproject.toml
├── README.md
├── src
│ ├── __init__.py
│ ├── item.py
│ └── items.csv
└── tests
├── __init__.py
└── test_item.py
对象列表:
[操作(441945886,2019年8月26日,已执行),操作(41428829,2019年7月3日,已执行),操作(939719570,2018年6月30日,已执行),...]
您需要按日期过滤它,以便最近的交易位于列表的开头。
课程本身:
class Operation():
def __init__(self, oper_id, state, date, operationAmount, description, from_card, to_card):
self.oper_id = oper_id
self.state = state
self.date = self.fix_date(date)
self.operationAmount = operationAmount
self.description = description
self.from_card = from_card
self.to_card = to_card
def fix_date(self, date):
if isinstance(date, str):
dt = datetime.fromisoformat(date)
return dt.strftime('%d.%m.%Y')
else:
return None
...
while player.count_used_words() != basic_word.count_subwords():
print(f"{player.count_used_words()} and {basic_word.count_subwords()}") # проверка длин
user_word = input("Слово: ").lower()
if player.check_used_word(user_word) == True:
print("Это слово уже использовано")
elif user_word == "stop" or "стоп":
break
else:
if basic_word.check_word_in_list(user_word) == True:
player.add_word(user_word)
print("Верно!")
else:
print("Слово не верно!")
print(f"Игра завершена, вы угадали {player.count_used_words()}")
为什么当程序陷入elif块时,游戏就结束了,虽然user_word变量没有stop或stop这个词,但根本就不是正确的词
为什么会有这样奇怪的行为,如果变量与 stop/stop 这几个词无关,为什么要调用 Break
ps我解决了问题,但我仍然不明白为什么这个块起作用,尽管理论上它不应该起作用
if input_user_level == 1:
user_level = words_easy
elif input_user_level == 2:
user_level = words_medium
elif input_user_level == 3:
user_level = words_hard