#🔒 Opening and reading a file

36 messages · Page 1 of 1 (latest)

remote maple
#

Im trying to create a system in which the user will inout a password and username and this will be written in another file and will be saved for future user so that the user can sign in. How do i write a file and then use the file to check for previous username and passwords?

upper owlBOT
#

@remote maple

Python help channel opened

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.

austere ravine
#

You can use open to open a file

summer belfry
remote maple
#

No

austere ravine
#

Look at the open function

summer belfry
# remote maple No

welp can u do the user will input password and username bit and just print them out after they done inputting ? pithink

remote maple
#

Yes but i want them to be able to sign in and not need to register everytime

summer belfry
#

first off, we need to open a file to work with it

#

we do this using open

remote maple
#

How do open the file

#

Everytime i press open it just copys it to clipboard

summer belfry
#

wdym press open

#

its just a function u use in code

#

open()

remote maple
#

Ohhh

austere ravine
#

open is a function, like print

remote maple
#

If you cant tell im not the best with coding

summer belfry
#

every1 starts somewhere

remote maple
#

Ive used the open function now how do i write in it?

#

Wait nvm it says the file name is not defined

summer belfry
#

this the basic of the basic

steel radish
#

looking at the docs would be a good start

austere ravine
#

when you use open, you need specify the file name and the mode : 'r' for reading and 'w' for writing

summer belfry
#

those the 2 important arguments ye

steel radish
#

and it'd be good to learn to use the with statement right from the get-go

#

with open(...) as fp: ...

austere ravine
#

open returns a file object, which has the methods write and read (depending on the mode)

steel radish
#

this ensures that the file gets closed if there's an exception in the block

indigo birch
remote maple
#

Okay thank you

upper owlBOT
#
Python help channel closed for inactivity

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.