DEV Community


Posted on



I'm working on a project that will be very useful for many others.
When I was learning Python, I created a program that creates an account for the user.
It had two variables: username and password.
But every time I ran the program, the values of both variables weren't the same.
So, I'm creating this project, that will sove the problem.
The idea is to create a text file that will work as a server.

def CreateFile(name):
    with open(f"{name}.txt", "a+"):
      return 0

Enter fullscreen mode Exit fullscreen mode

This code will create a text file.
The next time you run the your code, it'll check if the file already exists.
If it does, nothing will happen.
To add informations to the file you can call the function Write():

def Write(name, value):
  with open(f"{name}.txt", "a") as file:
Enter fullscreen mode Exit fullscreen mode

As you may have noticed, the text file that you want to acess is a string, not a variable:

# this is
import LocalServer

# creates a text file named MyFile

# adds Hello, World! to MyFile.txt
LocalServer.Write("MyFile", "Hello, World!")
Enter fullscreen mode Exit fullscreen mode

You can test if some text is in your text file or add settings to it.
I'll keep working on this project so that it'll be complete.

Top comments (0)