Monday, March 18, 2013

Pynote and Pypad

Have you ever wondered how to make a "notepad" in Python? Well I will show you how to make the very basics. Here we go.

So the first thing we want to do is a vairable that eqauls whatever we write. That way it will be easier to save it later:

a = input()

This is like what we did with the Pyculator, only with different uses.

Now we would be able to wright whatever we like and it would eqaul a.

Now we want to save what we wrote to a file off you choice. You can either save it as a .txt file or something random like .Alosisthebest.

This is how we do it


out_file = open("Pynote.pp", "wt")
out_file.write(a)
out_file.close()

Now we can see that every line has a out_file, all it does is it saves all this data, just in different ways.

Line 1: Tells Python what to save as (name .(name))
Line 2: Tells Python what in the code is going to be saved.
Line 3: Tells Python to not save anything more.

Now if we sve it as a file that can't be opened with any other program, we need to make a program that can open it.

It's pretty simple:


in_file = open("Pynote.pp", "rt")
text = in_file.read()
in_file.close()

print(text)

Let me explain this very simple code:

Line 1: Locate a file of a specific name and tells the next line to read it.
Line 2: Reads the text that the previous line located, but it doesn't show it.
Line 3: Tells Python to not locate or read any more files.
Line 5: Prints the text that the second line read.

Pictures showing:







So there you go, the very basics of a notepad.

Hope you develope this code to work even better. If you do please mail it to me at: NerdyAlos@gmail.com

No comments:

Post a Comment