result = None
for field in MY_FIELDS:
query = Sheets.objects.all().annotate(
field_name=Value(field),
field_value=F(field),
).values(
'field_name',
'field_value'
).distinct()
if result is None:
result = query
else:
result = result.union(query, all=True)
print(result.values())
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
name text,
current_mood mood
);
INSERT INTO person VALUES ('Moe', 'happy');
SELECT * FROM person WHERE current_mood = 'happy';
name | current_mood
------+--------------
Moe | happy
(1 row)
from app import models
from django.contrib.postgres.aggregates import ArrayAgg
from collections import defaultdict
result = defaultdict(dict)
query = models.Product.objects.values(
'sku',
'plu',
).annotate(
pack_types=ArrayAgg('pack_type_id')
)
for row in query:
result[row['sku']][row['plu']] = row['pack_types']
INSERT INTO public.product (sku,plu,pack_type_id) VALUES
(1,'10',2),
(1,'10',3),
(1,'11',4),
(2,'10',5);
{
"1": {
"10": [
2,
3
],
"11": [
4
]
},
"2": {
"10": [
5
]
}
}
yf.download(tickers = nasdaq_tickers, period = 'max', interval = '1d', group_by = 'ticker', threads=False)
yf.download(tickers = nasdaq_tickers, period = 'max', interval = '1d', group_by = 'ticker', threads=10)
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Chrome will run in a virtual display.
# you will not see the browser.
browser = webdriver.Chrome()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()
import os
class File(models.Model):
file = models.FileField()
...
def filename(self):
return os.path.basename(self.file.name)
import os
import psycopg2
DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
first = []
second = []
first.append(1)
print(f'1) First: {first} Second: {second} ')
second = first
print(f'2) First: {first} Second: {second} ')<code></code>
first.append(2)
print(f'3) First: {first} Second: {second} ')
1) First: [1] Second: []
2) First: [1] Second: [1]
3) First: [1, 2] Second: [1, 2]
Process finished with exit code 0
first = []
second = []
first.append(1)
print(f'1) First: {first} Second: {second} ')
second = first[:]
print(f'2) First: {first} Second: {second} ')
first.append(2)
print(f'3) First: {first} Second: {second} ')
1) First: [1] Second: []
2) First: [1] Second: [1]
3) First: [1, 2] Second: [1]
Process finished with exit code 0
//*[@role='most_interest']//a[contains(text(), 'изнутри') or contains(text(), 'нативного')]
import json
result = [1, 2, 3, 'Тестовый текст']
with open('result.json', 'w', encoding='utf8') as f:
json.dump(result, f, ensure_ascii=False)
https://pentaschool.ru/trainer/p/4
page = 1
test = f'test/page/{page}'
import csv
from collections import defaultdict
result = defaultdict(int)
with open('1.csv') as f:
reader = csv.DictReader(f)
for row in reader:
full_address_tuple =(row['town'], row['street'], )
result[full_address_tuple] += 1
for key, value in result.items():
print(key, ' - ', value)
('town1', 'street1') - 1
('town1', 'street2') - 2
('town2', 'street2') - 1
('town2', 'street1') - 1
town,street
town1,street1
town1,street2
town1,street2
town2,street2
town2,street1
client
dev tun
proto udp
remote sweden.privateinternetaccess.com 1198
resolv-retry infinite
nobind
persist-key
persist-tun
cipher aes-128-cbc
auth sha1
tls-client
remote-cert-tls server
<auth-user-pass>
xxxxx - тут указать ваш логин сервиса
xxxxx - тут указать пароль сервиса
</auth-user-pass>
comp-lzo
verb 1
reneg-sec 0
disable-occ
<crl-verify>
-----BEGIN X509 CRL-----
... <--сюда вставить тело ключа из файла crl.rsa.2048.pem
-----END X509 CRL-----
</crl-verify>
<ca>
-----BEGIN CERTIFICATE-----
...<--сюда вставить тело сертификата из файла ca.rsa.2048.crt
-----END CERTIFICATE-----
</ca>