Marketing
Query String
store
on a computer.Your entire computer hard drive is comprised of files, is the most low-level way to store information, your computer runs on a file system
or file directory
control that how data is stored and retrieved.
Using a backend language you can access the majority of the computer files, and that gives you almost endless power!
Let's say that you have the bitcoin prices from the last day in a bitcoin_prices.csv
file with the following format:
📺 Five minute video explaining what is a CSV file
Basically, every line in the CSV file represents one price, for example:
1Currency,Date,Closing Price (USD),24h Open (USD),24h High (USD),24h Low (USD) 2BTC,2019-10-29,9455.7246926058,9228.0745024715,9551.7787262272,9125.7784571584
You can read the file with any backend programing language and interpret it based on the positions of the values:
1import csv, json 2 3file = open("bitcoin_prices.csv", "r") 4csv_f = csv.reader(file) 5 6prices = [] 7for row in csv_f: 8 prices.append({ 9 "ticker": row[0], 10 "price": row[2] 11 })
Let's say you are running a script that has a variable called todos
that contains a todo list:
1todos = ['make the bed', 'do the laundry', 'finish homework']
That variable is being stored in the RAM memory until you decide to save it to a text file or database. The RAM memory is not reliable because your computer could lose power at any moment (turned off).
You can save that variable into a todos.csv
file with the following python code:
1todos = ['make the bed', 'do the laundry', 'finish homework'] 2 3todos_as_csv = ','.join(todos) # convert the list into a string 4file = open('todos.csv', 'w+') # open the file for writing 'w', create if it doesn't exist 5file.write(todos_as_csv) # write the content 6file.close() # close the file
The code above will create or update a todos.csv
with content similar to this:
1make the bed, do the laundry, finish homework
Format | Explanation |
---|---|
CSV | Comma , separated values, one line for each row or different entity. |
JSON | Very similar to Javascript syntax, made especially for developers and the most used format when transmitting information over the internet (HTTP) |
Yaml or YML | The easiest format to understand, developers love it because it is fast but it's also very similar to a simple text file, it allows comments and uses indentation instead of commas or braces for delimitation |
XML | Very popular in the 90's and still being used in a lot of legacy software |
1import csv 2file = open("bitcoin_prices.csv", "r") 3file_content = csv.reader(file) 4for row in file_content: 5 print("First element: " + row[0]) 6 print("Second element: " + row[1]) 7 # etc..
1import json 2filePointer = open("bitcoin_prices.json", "r") 3data = json.load(filePointer) 4prices = [] 5for row in data: 6 print("First element: " + row["ticker"]) 7 print("Second element: " + row["date"]) 8 # etc..
1import yml #you have to install pip package pyyaml 2 3filePointer = open("bitcoin_prices.yml", "r") 4data = yaml.load(filePointer) 5prices = [] 6for row in data: 7 print("First element: " + row["ticker"]) 8 print("Second element: " + row["date"]) 9 # etc..
Here is a live demonstration loading all three types of files.