Num*_*bot 0 python variables io
我想将网络名称作为输入,然后我想要使用与变量相同的名称保存文件.有没有办法获取变量,然后将变量名称命名为文件?
例如,假设我将名为facebook的网络保存为字典.我可以以某种方式获取该变量名称并将其用作文件名吗?
这一切都在Python中.
谢谢!
您可以声明如下值:
# Let's create a file and write it to disk.
filename = "facebook.txt"
# Create a file object:
# in "write" mode
FILE = open(filename,"w")
# Write all the lines at once:
FILE.writelines("Some content goes here")
# Close
FILE.close()
Run Code Online (Sandbox Code Playgroud)