我需要使用懒惰翻译但我还需要翻译 - 如何处理?
这段代码正在做我需要的:
print ugettext_lazy('Hello world!')
Run Code Online (Sandbox Code Playgroud)
现在我想加入两个懒惰的翻译并单独翻译(我现在不会工作,为什么但是想要有两个翻译字符串).
print ugettext_lazy('Hello world!') + ' ' + ugettext_lazy('Have a fun!')
Run Code Online (Sandbox Code Playgroud)
我可以做这样的代码,但它产生的翻译比需要的多.
print ugettext_lazy('Hello world! Have a fun!')
Run Code Online (Sandbox Code Playgroud)
是否有可能有两个翻译字符串和延迟翻译?
我想确保端点 API 仅通过https提供信息:
我应该在 Google App Engine Java 或 Python27 中包含什么样的代码?
避免太快/无效重复标记的重要注意事项 - 请在回答前阅读。
请不要建议任何更改原始类代码的解决方案- 不允许更改代码反射和解析。
如何按照声明的顺序读取类属性?是解决方案 - 它需要替换所有类中的元类并增加开销 - 绝对不是反射使用。
考虑到我不能或不想更改代码来扫描类成员顺序。类可以具有或已经具有未知的元类 - 不可能无缘无故地添加元类或增加性能开销。
只能使用反射或者解析文件。
我想避免编写解析器并按声明顺序读取类属性。
如何在 Python 中使用反射(和简单的解析)?
让我举一些例子:
class A(object):
b = 1
a = 1
c = 1
Run Code Online (Sandbox Code Playgroud)
dir(A)给出字母顺序,但要求是声明顺序。如何做到这一点 - 请帮忙?
我写了一些基本的程序,我想提取波兰语单词的引理,这是非常重要的,因为波兰语使用屈折。
我正在创建简单的程序来加载数据并将单词转换为引理,但不知道该怎么做:
from nltk import corpus
pl = corpus.pl196x
print dir(pl)
print iter(pl.tagged_words()).next()
Run Code Online (Sandbox Code Playgroud)
例如,我想做这样的词形还原(忽略一些词形还原可能含糊不清——这在波兰语中是正常的):
kot, kota, kota, kotu, kotem, kocie, kocie == kot (singular male)
kotka, kotki, kotk?, kotce, kotk?, kotce, kotka == kot (singular female!)
koci?tko, koci?tka, koci?tko, koci?tku, koci?tkiem, koci?tku, koci?tko == kot (singular neutral)
etc. (plural males, plural females, plural neutrals)
Run Code Online (Sandbox Code Playgroud)
如何使用 pl196x 在或 nltk 中做这样的工作。
语料库的源数据包含这样的屈折变化和引理 - 所以它是可能的,但如何访问它:
<w id="pu147125" lemma="kot" ana="SSNA---------P">kot</w>
<w id="pr021633" lemma="kot" ana="SSAA---------P">kota</w>
etc.
Run Code Online (Sandbox Code Playgroud) 我想使用Git + Cygwin + Ssh从Github克隆我自己的存储库.
怎么做 - 我创建密钥,我在github.com上发布公钥,我做ssh-add?
我做错了什么?
$git clone git@github.com:ChameleonRed/test.git Cloning into 'test'... Warning: Permanently added the RSA host key for IP address '192.30.252.123' to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
记录更多细节:
OpenSSH_7.2p2, OpenSSL 1.0.2g 1 Mar 2016 debug1: Reading configuration data /etc/ssh_config debug1: Connecting to github.com [192.30.252.123] port 22. debug1: Connection established. debug1: identity file …
如何将每个日志文件名从 Filebeat 传递到 Logstash?
我想在 Graylog 中查看源文件名以进行深入分析。
我研究了文档但没有找到解释。你能帮助我吗?
如何传递字典和查询参数?
我可以做这样的代码。
prepared = session.prepare('select name from task where id = ?;')
bound = prepared.bind([1])
session.execute(bound)
Run Code Online (Sandbox Code Playgroud)
如何使用 dict 作为参数以及查询语法是什么?
这不起作用:
prepared = session.prepare('select name from task where id = %(id)s;')
bound = prepared.bind({"id": 1})
session.execute(bound)
Run Code Online (Sandbox Code Playgroud)
你能帮忙解决这个基本代码吗 - 看起来这是可能的,但我不知道有效的查询语法?
我正在研究编辑距离算法,但无法理解换位 - 这是什么意思?
http://www.nltk.org/_modules/nltk/metrics/distance.html
def edit_distance(s1, s2, transpositions=False):
Run Code Online (Sandbox Code Playgroud)
文档中没有明确解释。
你能举一些简单的例子来帮助我理解吗?
我想在一个循环中一次总结多个属性:
class Some(object):
def __init__(self, acounter, bcounter):
self.acounter = acounter
self.bcounter = bcounter
someList = [Some(x, x) for x in range(10)]
Run Code Online (Sandbox Code Playgroud)
我可以做一些比它更简单,更快速的事情吗?
atotal = sum([x.acounter for x in someList])
btotal = sum([x.bcounter for x in someList])
Run Code Online (Sandbox Code Playgroud) 如何使用所有 cpu 内核进行 asyncio - 除了 ProcessPoolExecutor 之外的任何其他选项?
我认为 asyncio 无法打破 GIL 限制(也许我错了),因此程序的执行速度将比踩踏版本快,但会在一个核心上执行。
我研究了一些例子,我发现一种方法是多处理和 ProcessPoolExecutor。
https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor
# 3. Run in a custom process pool:
with concurrent.futures.ProcessPoolExecutor() as pool:
result = await loop.run_in_executor(
pool, cpu_bound)
print('custom process pool', result)
Run Code Online (Sandbox Code Playgroud)
这很好,但需要在进程之间进行“pickle”,因此需要一些开销并对传递的参数进行一些优化以减少“pickle”序列化。
使用上面这个简单的模式,我写了这样的测试代码(如果你不喜欢它,你可以跳过这段代码阅读,因为它和以前一样)。顺便说一句,这是我解析文件问题的最快解决方案。这部分代码不是整个程序。
def _match_general_and_specific_file_chunk(file_name):
with codecs.open(file_name, encoding='utf8') as f:
while True:
lines = f.readlines(sizehint=10000)
if not lines:
break
for line in lines:
general_match = RE_RULES.match(line)
if general_match:
specific_match = RULES[general_match.lastindex].match(line)
groups = list(specific_match.groups())
continue
async def _async_process_executor_match_general_and_specific_read_lines_with_limit_file_chunk():
loop = asyncio.get_event_loop()
with ProcessPoolExecutor() …Run Code Online (Sandbox Code Playgroud) Google App Engine Python 中 IntegerProperty、LongProperty 的最大值是多少?
我希望编码和解码变量和可数位的比特流成二进制字符串, 数字,64个碱基编码的字符串.流的最大长度约为21 + 20 = 41位,但可以稍长43,45.
假设位将由某个数组表示.
bits = [1]
encoded = someEncoder(bits)
decoded = someDecoder(encoded)
assert bits == decoded
Run Code Online (Sandbox Code Playgroud)
比特流可以更长,例如:
import random
def generateRandomBits(l):
bitsBytes = random.getrandbits(l)
bits = []
for i in range(l):
bitsBytes
bits.append(int(bitsBytes >> i & 1))
return bits
bits = generateRandomBits(21)
# [0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1]
Run Code Online (Sandbox Code Playgroud)
考虑它是可变 …
python ×8
python-2.7 ×5
nlp ×2
nltk ×2
cassandra ×1
class ×1
cygwin ×1
django ×1
django-i18n ×1
filebeat ×1
git ×1
github ×1
graylog2 ×1
logstash ×1
polish ×1
python-3.x ×1
reflection ×1
ssh ×1
translation ×1