文件名测试.sh
echo $HOME
Run Code Online (Sandbox Code Playgroud)
以 root 权限运行 -> sudo test.sh
预期的
/home/username/
Run Code Online (Sandbox Code Playgroud)
但得到
/root
Run Code Online (Sandbox Code Playgroud) 我将这两个问题合二为一,因为它们可能是相关的。几天前,我开始在 main 函数之前的 [#actix_rt::main] 行中出现此错误:
proc macro `main` not expanded: cannot find proc-macro server in sysroot `C:\Users\zerok\.rustup\toolchains\stable-x86_64-pc-windows-gnu`
Run Code Online (Sandbox Code Playgroud)
与此同时,在 VSCode 中,我的 rust-analyzer 扩展开始失败。我卸载了它,重新启动 VSCode,然后重新安装。它不断地给出同样的错误:
Failed to spawn one or more proc-macro servers.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我编写的程序循环遍历一个范围并找到素数和回文数。作为学习 asyncio 的一部分,我尝试使用 async 重新构建它。但结果并不好。这里异步代码比同步代码花费的时间要长得多。
同步代码
import math
import time
def prime(n):
limit=int(math.sqrt(n))
for j in range(2,limit):
if(n%j==0):
return 0
return 1
def pallindrome(n):
n=str(n)
m=n[::-1]
if(m==n):
return 1
return 0
a, b, c = 999999999, 9999999, 0
start = time.time()
for i in range(a, b, -1):
if(pallindrome(i)):
if(prime(i)):
c+=1
print(i)
if(c==20):
break
print("took --> ", time.time()-start)
Run Code Online (Sandbox Code Playgroud)
结果 :
999727999
999686999
999676999
999565999
999454999
999434999
999272999
999212999
999070999
998979899
998939899
998898899
998757899
998666899
998565899
998333899
998282899
998202899
998171899
998121899
took …Run Code Online (Sandbox Code Playgroud) 我有一本像这样的字典
history = [
{'val':234, 'when':1691884800},
{'val':254, 'when':1692230400},
{'val':212, 'when':1691366400},
]
Run Code Online (Sandbox Code Playgroud)
我需要获取“when”值最高的“val”
现在我正在这样做:
maxval = [his['val'] for his in history if his['when']== max([his['when'] for his in history])][0]
Run Code Online (Sandbox Code Playgroud)
然而,当我必须浏览大约 300K 的此类词典时,效率非常低并且需要花费大量时间。有什么办法可以优化这部分吗?
python ×2
asynchronous ×1
bash ×1
dictionary ×1
linux ×1
palindrome ×1
primes ×1
qpdf ×1
rust ×1