import os
import json
config = {}
with open('user_config.json', 'r', encoding="utf-8") as cf:
config = json.loads(cf.read())
print(config) # {u'userName': u'user', u'userId': u'0001'}
print(config.get("userName")) # user
print(config.get("userName1")) # None
# но намного лучше использовать неизменяемую структуру данних
# namedtuple
from collections import namedtuple
with open('user_config.json', 'r', encoding="utf-8") as cf:
config = json.loads(cf.read(),
object_hook=lambda d: namedtuple('CONFIG', d.keys())(*d.values()))
print(config.userName, config.userId)
plugins=python3
нужно поставить uwsgi-plugin-python3
In [1]: ', '.join(['my', 'super', 'list'])
Out[1]: 'my, super, list'
In [2]: import os
In [3]: os.path.join('path', 'to', 'script')
Out[3]: 'path/to/script'
In [4]: os.path.abspath(os.path.join('path', 'to', 'script'))
Out[4]: '/home/username/path/to/script'
In [5]: os.path.abspath(os.path.join('/', 'path', 'to', 'script'))
Out[5]: '/path/to/script'
$
.
├── mod
│ ├── __init__.py
│ └── supermod.py
└── use.py
#supermod.py
def foo(): print('foo')
#use.py
from mod.supermod import foo
foo()
from json import loads
import requests
w = 'кот'
d = requests.get('https://ru.wiktionary.org/w/api.php?action=query&titles=%s&prop=revisions&rvprop=content&format=json' % w)
print(loads(d.text))
t = l.add_xpath('ibp_power_w', "//div[@class='characteristic' and text()[contains(normalize-space(.), '%s')]]/following-sibling::div[@class = 'value']/text()" % u"Мощность (Вт)" )
print t.strip()