class A:
def __init__(self, name):
self.name = name
self.inner = self.B(self)
def get_name(self):
return self.name
class B:
def __init__(self, parrent=None):
self.parrent = parrent
self.name = "val 2"
if parrent:
self.name = self.parrent.name
def test(self):
return self.name
def get_name(self):
return self.name.upper()
def set_name(self, val):
self.name = val
def make(self):
return self.parrent.B()
obj = A("val 1")
print(obj.get_name())
print(obj.inner.get_name())
o = []
for i in range(5):
o.append(obj.inner.make())
o[i].set_name(str("new val {}".format(i)))
for i in o:
print(i.get_name())
print(A("test").B().test())
val 1
VAL 1
NEW VAL 0
NEW VAL 1
NEW VAL 2
NEW VAL 3
NEW VAL 4
val 2
import re
s = "llldddrrrwwwwttttgggglllleeeeddddddddd"
f = re.findall(r"((\w)+?(?!\2))", s)
d = [w + "" + str(len(l)) for l, w in f]
print(s)
print(''.join(d))
llldddrrrwwwwttttgggglllleeeeddddddddd
l3d3r3w4t4g4l4e4d9
s = "llldddrrrwwwwttttgggg"
d = {}
for i in s:
d.setdefault(i, 0)
d[i] += 1
g = [''.join(map(lambda i: str(i), item)) for item in d.items()]
print(s)
print(''.join(g))
llldddrrrwwwwttttgggg
l3d3r3w4t4g4
def extractor(store):
for product in store:
price = 0
quantity = 0
for info in store[product]:
quantity += info["quantity"]
price += info["price"]
yield product, quantity, price
stock = {product: {"code": product, "quantity": quantity, "price": price}
for product, quantity, price in extractor(store)}
for product in goods:
print("Название - {}, Код - {code}, Кол-во - {quantity}, Стоимость - {price}"
.format(product, **stock[goods[product]]))
Название - Лампа, Код - 12345, Кол-во - 27, Стоимость - 42
Название - Стол, Код - 23456, Кол-во - 54, Стоимость - 1030
Название - Диван, Код - 34567, Кол-во - 3, Стоимость - 2350
Название - Стул, Код - 45678, Кол-во - 105, Стоимость - 292
import requests
proxies_list = [твои прокси]
for proxy_ip in proxies_list:
proxies = {
"http": proxy_ip,
"https": proxy_ip
}
headers = {}
url = "https://yandex.ru"
try:
response = requests.head(
url=url,
headers=headers,
proxies=proxies,
timeout=10)
# делай что-то с response
except Exception as err:
print("Proxy - {}, Err - {}".format(proxy_ip, err))
class UseCurrency():
def __init__(self, currency):
self.currency = getattr(Currency(), currency)
def get_currency(self):
return self.currency
class Currency():
USD = 1
GBP = 2
EURO = 3
CHF = 4
RUB = 5
UAH = 18
obj = UseCurrency("USD")
print(obj.get_currency())
roomlist
у тебя <class 'bs4.element.Tag'>
import requests
from bs4 import BeautifulSoup
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"}
url = "https://hamptonvolgograd.ru/nomera/"
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")
roomlist = soup.findAll("span", class_="h1")
for hostel in roomlist:
print(hostel.text.strip())
Номер с двуспальной кроватью (номер первой категории)
Номер с двумя кроватями (номер первой категории)
Номер с двуспальной кроватью и диваном-кроватью (Джуниор сюит)
Номер для людей с ограниченными возможностями (номер первой категории)
def simple_numbers(m, n):
for i in range(m, n):
for j in range(2, i):
if i % j == 0:
break
else:
yield i
def test(g, m, n):
lst = []
for i in simple_numbers(m, n):
lst.append(i)
if len(lst)>1:
if abs(lst[-1] - lst[-2]) == g:
return [lst[-1], lst[-2]]
return False
g = 6
m = 2
n = 1100000
rez = test(g, m, n)
if rez:
print("{} - {} = {}".format(rez[0], rez[1], g))
else:
print("No")
href_json = self._get_upload_link(disk_file_path=disk_file_path).get('href', '')
href = href_json['href']
href
ты уже вытащил вот тут .get('href', '')
href_json
по идее должна содержать url href_json['href']
class my_types:
def __init__(self):
self.my_types = [email_type, negotive_type, positive_type]
def check_types(self, check_type):
for my_type in self.my_types:
obj = my_type()
if obj.check_type(check_type):
return obj.type_name()
return "Unknown type"
class email_type(my_types):
def check_type(self, check_type):
if "@" in check_type:
return True
return False
def type_name(self):
return "email_type"
class negotive_type(my_types):
def check_type(self, check_type):
if "no" in check_type:
return True
return False
def type_name(self):
return "negotive_type"
class positive_type(my_types):
def check_type(self, check_type):
if "yes" in check_type:
return True
return False
def type_name(self):
return "positive_type"
check_types = ["test@", "yes", "no"]
obj = my_types()
for check_type in check_types:
print("{} - {}".format(check_type, obj.check_types(check_type)))
test@ - email_type
yes - positive_type
no - negotive_type