Desktop Site
This article has not yet passed wikiHow's quality review process. Learn more

How to Create a Simplistic Sub Language with Python



This article has been tagged as a stub.


That means it's off to a good start, but still has room to grow into a more helpful resource. Until the article reaches its full potential, it will be hidden from search results. Can you help it flourish? If you think the article offers complete and accurate instructions, feel free to remove this tag.

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.

Ok,
Close
This article has not yet passed wikiHow's quality review process. Learn more

EditSteps

  1. 1
    Download 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.
  2. 2
    Create 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
  3. 3
    Create 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
  4. 4
    Create 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
  5. 5
    Create 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

Did this article help you?

Yes
No