How to use 'python save list to txt' in Python

Every line of 'python save list to txt' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
60def write_txt(str):
61 with open('answers_all.txt', 'a') as f:
62 f.write(str)

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

63def write_txt(path, fname, contents, flag=False):
64 make_directory(path)
65 full_path = os.path.join(path,fname)
66 log = open(full_path, 'a')
67 log.write(contents + '\n')
68 log.close()
69 if (flag):
70 print '-> [%s] has been written in %s.' % (contents, fname)

Related snippets