我有一个.c文件,其中包含以下行
uint32 num_of_entries = 65;
我正在编写一个自动化脚本以打开并创建类似的'c'文件,并编写以下行:“ uint32 num_of_entries =” int(65)
两个文件看起来都很相似,但是脚本创建的文件会引发未定义的引用。我认为这是因为我是如何以字符串格式编写的。如果是这种情况,是否需要将字符串更改为任何数据类型?
我将其写为file.write("uint32 num_of_entries = " + int(65))
答案 0 :(得分:1)
您很接近,但是您需要使用f字符串或.format()
函数来格式化输出:
# Using an f-string
file.write(f"uint32 num_of_entries = {65}")
# Using the `.format()` function:
file.write("uint32 num_of_entries = {0}".format(65))