Reputation: 502
I'm running code quite frequently when working in PyCharm. Problem is that the entire code manipulates data temporarily stored in excel (we'll be moving this to the database once the program is up and running). Loading data takes time.
Is there a way in PyCharm to keep variable in the initial memory (without running a piece of code in the console) even after the program finished running?
data = pd.read_excel(path, index_col=0)
I want to avoid reloading data every time I am running program.
Upvotes: 2
Views: 1566
Reputation: 502
I've found a dirty trick - I am aware this is a very, very non-pythonic and not appropriate way of doing this. But it does the trick for me in this example. Again this code is only temporarily used for testing and will be removed once I'm happy with the code.
Module I run is as follow:
data = pd.read_excel(path, index_col=0) #Data is loaded only once
while True:
reload(TestModule)
TestModule.test_function(data)
input("Press Enter to rerun the test")
Now in TestModule I have test_function where I can reload ModyfiedModule I am working on and any function I want to test.
TestModule:
def test_function(data):
from ModyfiedModule import MyClass
#Run bunch of tests from MyClass
#Code to test MyClass is here
In this case, I load data only once and I can modify MyClass module and perform various test defined in TestModule without need to reload data each time.
The only thing I need to do after modifying code is to save MyClass and TestModule and press Enter in the console to rerun the test.
Upvotes: 0
Reputation: 482
If working in PyCharm is not a neccesity, you could work in a jupyter notebook: https://jupyter.org/ You could load your data in a cell and work with it in the next cells. Once executed, the result of a cell is kept in memory.
Upvotes: 0
Reputation:
No, this feature has not been implemented yet and there is no way to do this.
Upvotes: 1