I've done something stupid in Python, in Jupyter notebook. I deleted the cell that had my functions in it, probably a couple of hours ago, and now I don't have them any more. However, I can still run them, so they are still loaded in the kernel.
Is there a way to find that loaded kernel somewhere so I could copy those functions back into my code?
Thanks!
I've looked on the internet for ideas but haven't found anything.
I found how to solve this. The .getsource does the work:
import inspect
lines = inspect.getsource(set_claims_rebates)
print(lines)
Related
Spyder crashed but I didn't saved the code I was working on. When I restarted Spyder, obviously my code was gone. I found out, that I somehow can get the code back with the command hist -g. I have tried this, but this only allows me to see statements like this: runfile('XXXX', wdir='XXX')
Is there a way to get my code back? Despite of one other question on stackoverflow i couldnt find anything related to my problem.
[Sorry if I understood something completly wrong or if I have grammar- or spellingerros. This is my first coding internship and English is not my native language, I'll try to improve both in the future :)]
I'm trying to run an automated test in Ride.py. This test works on my colleague's computer but for some reason does not work on mine. The test starts but at a certain point i get the following error:
[ ERROR ] Calling method 'start_keyword' of listener 'C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py' failed: IndexError: list index out of range
The interesting part is that this error occurs on the same spot ever time, but with a different test it happens at a different time.
I tried to google several things and nothing worked. One solution suggested there was a '#' commented somewhere and this caused the crash. I looked but I don't see a '#' commented anywhere.
Another suggestion lead me to believe my testrunneragent.py file must have been installed wrong. I went online to find the file and replaced it. This did not work either (reran the test before and after a restart of ride)
We tried to re-import the test files thinking perhaps something went wrong there. This did not help either.
Googling juts the last part (IndexError: list index out of range) gave me the suggestion it does not recognize all the lines of code in the back-end file. I would have no clue how to solve this as im not a major coder.
One difference between me and my colleague could be the versions. I downloaded python version 2.7.16 and ride 1.7.3.1. My colleague uses an older version of both python and RIDE. Perhaps the problem could be here?
https://paste.fedoraproject.org/paste/TLekH3az0m4wuUyM8C2RYw
I expect the test will run without failing (it is a happy flow) I have included some screenshots with code in the previous segment that might help
downgraded to the same version of Ride.py
This seems to have fixed the issue
I don't know how this happens or why,
but I'll be in a jupyter notebook grouping by things and I will very conciously type in dataframe.groupby, write some other code and hit ctrl+ enter
and there will be that damn error. Every single time, I will go back and delete the 'groupyouby' and type in groupby.
I doubt that anyone has run into this error,and I don't know how long it will be until someone else creates the mess of libraries that I have that resulted in this chinese water tourture like nightmare. I am here, to let you know, that you are not alone.
Also if someone has a fix that would be great. I got nothing for you other than that description above.
Grammarly was the cause of this.
If you use jupyter notebooks and have the grammarly extension. It will cause problems.
I am trying to use the netCDF4 package with python. I am ingesting close to 20mil records of data, 28 bytes each, and then I need to write the data to a netCDF4 file. Yesterday, I tried doing it all at once, and after an hour or so of execution, python stopped running the code with the very helpful error message:
Killed.
Anyway, doing this with subsections of the data, it becomes apparent that somewhere between 2,560,000 records and 5,120,000 records, the code doesn't have enough memory and has to start swapping. Performance is, of course, greatly reduced. So two questions:
1) Anyone know how to make this work more effeciently? One thing I am thinking is to somehow put subsections of data in incrementally, instead of doing it all at once. Anyone know how to do that? 2) I presume the "Killed" message happened when memory finally ran out, but I don't know. Can anyone shed any light on this?
Thanks.
Addendum: netCDF4 provides an answer to this problem, which you can see in the answer I have given to my own question. So for the moment, I can move forward. But here's another question: The netCDF4 answer will not work with netCDF3, and netCDF3 is not gone by a long shot. Anyone know how to resolve this problem in the framework of netCDF3? Thanks again.
It's hard to tell what you are doing without seeing code, but you could try using the sync command to flush the data in memory to disk after some amount of data has been written to the file:
http://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4.Dataset-class.html
There is a ready answer in netCDF4: declare the netCDF4 variable with some specified "chunksize". I used 10000, and everything proceeded very nicely. As I indicated in the edit to my answer, I would like to find a way to resolve this in netCDF3 also, since netDF3 is far from dead.
Is there a way to save the current Python session? I would like to be able to save all my Python variables, functions, and imported libraries. If possible, having the history saved would be nice. I have looked all over Google and Stackoverflow for a simple command to do this, but have found nothing quite fitting what I want. Some suggested downloading new software, which I don't want. Others had big scripts that they wrote to do this for them.
I'm looking for a no-nonsense easy to use command. Is there one? If not, how would you suggest to make one?
UPDATE: readline.write_history_file() and readline.read_history_file() save the history.
I think the closest thing you're going to find is ipython. I'm not sure if it does the variable saving thing, but I believe it does everything else you're asking for.
1.) After typing all commands just do CTRL+S.
2) Give a file name and say OK.
This works for Python Shell.