如何将以下代码打印到.txt文件
y = '10.1.1.' # /24 network, for x in range(255): x += 1 print y + str(x) # not happy that it's in string, but how to print it into a.txt
有复制粘贴,但宁愿尝试更有趣的东西.
f = open('myfile.txt', 'w') for x in range(255): ip = "10.1.1.%s\n" % str(x) f.write(ip) f.close()