小编Oma*_*tos的帖子

在Javascript中格式化十六进制

如何格式化十六进制以在javascript中始终以4位数显示?

例如,我将十进制转换为十六进制:

port = 23
function d2h(d) {return (+d).toString(16);}
d2h(port)
Run Code Online (Sandbox Code Playgroud)

我成功地将"23"转换为十六进制值"17".但是,我希望格式化为"0017"(四位数 - 在17之前追加0).

所有信息将不胜感激.

javascript hex

4
推荐指数
1
解决办法
5131
查看次数

读取文件并将值存储到python中的变量中

假设我有一个文件名(test.txt),其中包含以下数据:

AA11 BB11 CC11 DD11
AA22 BB22 CC22 DD22
AA33 BB44 CC44 DD33
Run Code Online (Sandbox Code Playgroud)

在bash(shell脚本)中我可以执行以下操作:

cat test.txt | while read a b c d 
do
echo "this is the first column $a "
echo "this is the second column $b "
echo "this is the third column $c "
echo "this is the fifth column $d "
done
Run Code Online (Sandbox Code Playgroud)

我怎么能用python做同样的事情?如何在变量中存储每列的值,然后在存储和操作它们的值时逐行读取文件?

python variables bash

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

bash ×1

hex ×1

javascript ×1

python ×1

variables ×1