Поместите следующее в начало вашего файла cron.py:
#!/usr/bin/python
import os, sys
sys.path.append('/path/to/') # the parent directory of the project
sys.path.append('/path/to/project') # these lines only needed if not on path
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings'
# imports and code below
Я пытался подражать функции сжатия словаря, появляется на этом блоге: https://writings.stephenwolfram.com/2018/11/logic-explainability-and-the-future-of-understanding /
Вот - то, что я сделал:
DictionaryCompress[expr_, count_, size_, func_] := Module[
{t, s, rule, rule1, rule2},
t = Tally@Level[expr, Depth[expr]];
s = Sort[
Select[{First@#, Last@#, Depth[First@#]} & /@
t, (#[[2]] > count && #[[3]] > size) &], #1[[2]]*#1[[3]] < #2[[
2]]*#2[[2]] &];
rule = MapIndexed[First[#1] -> func @@ #2 &, s];
rule = (# //. Cases[rule, Except[#]]) & /@ rule;
rule1 = Select[rule, ! FreeQ[#, Plus] &];
rule2 = Complement[rule, rule1];
rule = rule1 //. (Reverse /@ rule2);
rule = rule /. MapIndexed[ Last[#1] -> func @@ #2 &, rule];
{
expr //. rule,
Reverse /@ rule
}
];
poly = Sum[Subscript[c, k] x^k, {k, 0, 4}];
sol = Solve[poly == 0, x];
expr = x /. sol;
Column[{Column[
MapIndexed[
Style[TraditionalForm[Subscript[x, First[#2]] == #], 20] &, #[[
1]]], Spacings -> 1],
Column[Style[#, 20] & /@ #[[2]], Spacings -> 1, Frame -> All]
}] &@DictionaryCompress[expr, 1, 1,
Framed[#, Background -> LightYellow] &]