How to Create a Simplistic Sub Language with Python
Many Python programmers start out trying to use the JSON python library or just writing text to a file to transfer data between files. In this article I will cover the basics of creating a sub-language(not a full programming language), with little-to-no syntax, just perfect for writing small data bases or save files.
CloseThis article has not yet passed wikiHow's quality review process. Learn more
Steps
-
1Download Python if you haven't already. Get some basic knowledge on Python first. Open up IDLE and create a new file named whatever you want.
-
2Create a 'Load' function, which will be used to load the file so the user can write and get data from the loaded file
- Add a parameter, the file name(fname) to the function, then create two globals: file and ln. Then set file to open the file (open(fname, "r+"), r+ stands for Read and write. Set ln to be file.readlines() so we can access to all the lines in the file. Lastly return file
-
3Create a 'var' function, which will be used to get variables from the file and into python itself
- Add a parameter, the line to scan(line) to the function, then get our previous globals. Set the variable 'text' to be ln[line](Gets the value of line line and saves it as text. Now return text
-
4Create a 'write' function, which will be used to add data to our file(since we've already can retrieve data from a loaded file)
- Add a parameter, the value to write in the file, get the global file and seek (file.seek(0, 2) to the end of the file then add file.write("\n%s"%value)(Which writes a newline, then the value to the file).Return file
-
5Create a 'end' function, which will be used to save the file and close it so we can access a different file.
- Get the global file and file.close() it, then return file
We could really use your help!
Instagram?
rate articles?

Adobe Photoshop?

lock-picking?

astrology relationships?

Article Info
Categories: Programming
Thanks to all authors for creating a page that has been read 1,350 times.
About this wikiHow