Strings Module for Memory Optimization
Posted: Tue Jul 09, 2019 2:26 pm
According to the official documentation, assigning a string to a variable instead of passing directly in a function is more efficient because the string will be saved in flash, example:
var = "My string is a good string"
print(var)
is better than:
print("My string is a good string")
at least it is what i understood.
So, knowing that, i'v been thinking if it is more memory efficient to save all the big strings you will be using in the project in a single module for reference, like a strings.py file, example:
strings.py file:
string1 = "this is string!
stirng2 = "this is another string"
string_to_print = "this string is the best string"
and in the main code:
import strings
print(string.string_to_print)
Am i crazy or it makes sense?
var = "My string is a good string"
print(var)
is better than:
print("My string is a good string")
at least it is what i understood.
So, knowing that, i'v been thinking if it is more memory efficient to save all the big strings you will be using in the project in a single module for reference, like a strings.py file, example:
strings.py file:
string1 = "this is string!
stirng2 = "this is another string"
string_to_print = "this string is the best string"
and in the main code:
import strings
print(string.string_to_print)
Am i crazy or it makes sense?