Ask coding questions

← Back to all posts
How to store user input into a file in Python
asfdfg

I'm trying to make a program that takes user input and stores it into a file and I want to know how to do that.

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
asfdfg
Comments
hotnewtop
Wumi4

For this, you can use the open() command in Python.

This is an example, the program ask the user for their name, then add that in a file called usernames.txt:

asfdfg

@Wumi4
Thanks, that really helped!

asfdfg

How to bring back that file when I need to use it?

SixBeeps

@asfdfg something like this

[deleted]

You should be able to learn how to do what you want from this page: https://www.programiz.com/python-programming/file-operation