Import the module and create an object of the class LocalVariable. Call the save method with the name and the value of a variable as argument to store your data locally and call any of the methods from the list below to read the value.
- read_int (var_name)
- read_float (var_name)
- read_str (var_name)
- read_bool (var_name)
- read_list (var_name)
- read_tuple (var_name)
- read_set (var_name)
- read_dict (var_name)
## Sample 01:
import PyVariable data = Variables.LocalVariable() data.save("Name", "John") # This will store the variable Name with the value John LocalName = data.read_str("Name") # This will read the value of Name from cloud and store in LocalName print(LocalName) # This will print John
##Sample 02: This program counts how many times you runned this program.
import PyVariable count = 0 data = Variables.LocalVariable() count = data.read_int("count") # This will read the value of count and store in count variable count = count + 1 data.save("count", count) # This will store the variable count with the value John print("This program ran" + str(count) + "times") # do something below ;)
Step1: Go to https://console.firebase.google.com/
Step2: Login with your google account.
Step3: Click on Add Project
Step4: Enter any name (The name doesn’t matter at all).
Step5: Disable Google Analytics and click on continue.
Step6: After the the database creation is finished, click on continue and you’ll see a window like this.
Step7: Click on Realtime Database on the left.
Step8: Click on Create Database and select your nearest location.
Step9: After clicking Next, Select Start in test mode and click on Enable
Step10: Finally, just copy this url as shown in the image.
Step11: Now go to your code and import the module Variables.
Step12: After that create an object of the class CloudVariable with the url you copied as argument.
Everything is now ready. Simply call the save method with the name and the value of a variable as argument to store your data online and call the read method with the name of your variable as argument to read the value. Note: The returned value will automatically be in your desired data type.
Here is a sample code –
import PyVariable data = Variables.CloudVariable(The_Url_You_Copied) data.save("Name", "John") # This will store the variable Name with the value John LocalName = data.read("Name") # This will read the value of Name from cloud and store in LocalName print(LocalName) # This will print John