Friday, April 1, 2016

Design docs from Google Sheets to wherever you want. (Python)

Hey all,

I was sick this past week, so I had a bit of trouble writing anything... Or doing work.

Or anything, really. It was great. By "great" I mean absolutely horrible, my goodness. I'm still not over it, while writing this things get a bit blurry every once in a while, it's not a good feeling.

Anyway, I wanted to make a short post about how to get a document from Google Sheets, parse it, and output it in a format of your choosing using Python.

First off, you need a document like this one:

I don't know about you, but I do a lot of design using Google Sheets to make sure things are balanced.

Click File -> Download as -> Comma separated values (.csv)
You should now have a file that looks kinda like this one:

Don't worry, we have computers to go through this stuff.

So all we need to do is write that Python script, right?
Fortunately, Python has a bunch of handy functions to parse long files like these.

Things that we'll need:
  1. import sys. (Get file names from command line)
  2. readlines() from file object.
  3. split() which will separate our comma separated values. (Split on ',')

A first run of this file should look like so:


This skeleton will do the following:
  1. Open files as specified by the script as it was called from the command line. Example: "python script.py inputfile.csv outputfile.txt" will read in file "inputfile.csv" and spit out file "outputfile.txt"
  2. For each line, it will separate out the words (which were separated by commas) into an array.

How about a practical use of this format? I'll show you the file I used it for:


For reference, the output file looked as so:


Note that this file is designed to be consumed by my game engine: JFramework, so your output may differ. This file is literally every single attack, in Chang-e, all of them. Some 135 I think?

So with this format, as you can see, you can take in a file from Google Sheets and turn it into any file you want using Python.

If you have any questions, let me know, I'll update this entry with any comments I get.

Also: Toodaloo -> Toodles, Boogaloo -> Boogles?

Jimmy

No comments:

Post a Comment