#🔒 Opening and reading a file
36 messages · Page 1 of 1 (latest)
@remote maple
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
You can use open to open a file
do u know how to open a file in python ? 
No
Look at the open function
welp can u do the user will input password and username bit and just print them out after they done inputting ? 
Yes but i want them to be able to sign in and not need to register everytime
so lets get to knowing how to do filework 
first off, we need to open a file to work with it
we do this using open
Ohhh
open is a function, like print
If you cant tell im not the best with coding
every1 starts somewhere
Ive used the open function now how do i write in it?
Wait nvm it says the file name is not defined
file = open()
# do file operations here
file.close()
this the basic of the basic
looking at the docs would be a good start
when you use open, you need specify the file name and the mode : 'r' for reading and 'w' for writing
those the 2 important arguments ye
and it'd be good to learn to use the with statement right from the get-go
with open(...) as fp: ...
open returns a file object, which has the methods write and read (depending on the mode)
this ensures that the file gets closed if there's an exception in the block
but you don't really need the second argument when you're just opening a file for reading since that is the default
Okay thank you
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.