How to save the python code in command prompt? - python-3.8

I've typed a python code that calculates GST in command prompt and I want to save the code now.
As I'm using command prompt for the first time but unable to save the code. I've searched ways to save it but can't find solution to it.

You would need to save it as a python file and then call the script.
Assuming python is already installed, put your code in filename.py
Eg: print('Hello World!')
Then cd to the folder and type python filename.py
But you might want to check out jupyter notebooks
https://jupyter.org/

Related

How to read dataframe using shell file with wget?

I have a shell file wit code like this in it:
wget --load-cookies /tmp/cookies.txt \
"https://docs.google... train.tar.gz
How to run this file to get my data? I know pd.read_csv but in this case I dont really get how to run it. Im using visual studio code

Running python commands in a terminal in Google Colab

I've uploaded a directory of codes in Google Colabs. I need to run python command lines in a terminal that I'm unable to open.
I tried each and every solution suggested in How can I run shell (terminal) in Google Colab? but to no avail.
Updated 20220202
Can you try to execute your python scripts using the exclamation mark ! from Colab's cell directly?
I believe I encountered identical issue back in my Colab days, the process will hung or froze over some time, especially when I am dealing with GBs of datasets. So, ultimately I just ran using the exclamation mark directly from my Colab's cell to resolve the issue.
Have you tried this with the following syntax?
!pip install google-colab-shell
from google_colab_shell import getshell
getshell()
getshell(height=400)
I understood that you have tried the solution from another post, but just in case that you missed out the !, and ignored the warning message, and that exclamation mark was actually causing the shell not spawning.

after importing dill and dumping session , the notebook cannot be opened, the code cannot be retrieved

i worked on some experiment and wanted to find a way to save the lists of data i collected manually. i found dill and decided to use it .
installed via pip. typed in the following code:
import dill
dill.dump_session('notebook_env.db')
after that i closed the kernel and opened the notebook and to my shocking surprise got the following message:
Unreadable Notebook: /Users/nimrodros/Untitled.ipynb UnicodeDecodeError('utf-8', b'\x80\x03cdill._dill\n_import_module\nq\x00X\x08\x00\x00\x00__main__q\x01\x85q\x02Rq\x03}q\x04(X\x08\x00\x00\x00__name__q\x05h\x01X\x07\x00\x00\x00__doc__q\x06X#\x00\x00\x00Automatically created module for IPython interactive environmentq\x07X\x0b\x00\x00\x00__package__q\x08NX\x08\x00\x00\x00__spec__q\tNX\x0b\x00\x00\x00__builtin__q\nh\x00X\x08\x00\x00\x00builtinsq\x0b\x85q\x0cRq\rX\x03\x00\x00\x00_ihq\x0e]q\x0f(X\x00\x00\x00\x00q\x10X\x1a\x00\x00\x00eye_correction_middle_fallq\x11X\r\x00\x00\x00fuc=[1,2,3,4]q\x12X\x16\x00\x00\x00eye_correction_voltageq\x13X\r\x00\x00\x00fuc=[1,2,3,4]q\x14X/\x00\x00\x00import dill\ndill.dump_session(\'untitled.ipynb\')q\x15eX\x03\x00\x00\x00_ohq\x16}q\x17X\x03\x00\x00\x00_dhq\x18]q\x19X\x10\x00\x00\x00/Users/nimrodrosq\x1aaX\x02\x00\x00\x00Inq\x1bh\x0fX\x03\x00\x00\x00Outq\x1ch\x17X\x01\x00\x00\x00_q\x1dh\x10X\x02\x00\x00\x00__q\x1eh\x10X\x03\x00\x00\x00___q\x1fh\x10X\x02\x00\x00\x00_iq X\r\x00\x00\x00fuc=[1,2,3,4]q!X\x03\x00\x00\x00_iiq"X\x16\x00\x00\x00eye_correction_voltageq#X\x04\x00\x00\x00_iiiq$X\r\x00\x00\x00fuc=[1,2,3,4]q%%X\x03\x00\x00\x00_i1q&X\x1a\x00\x00\x00eye_correction_middle_fallq\'X\x03\x00\x00\x00_i2q(h%%X\x03\x00\x00\x00fucq)]q*(K\x01K\x02K\x03K\x04eX\x03\x00\x00\x00_i3q+h#X\x03\x00\x00\x00_i4q,h!X\x03\x00\x00\x00_i5q-X/\x00\x00\x00import dill\ndill.dump_session(\'untitled.ipynb\')q.X\x04\x00\x00\x00dillq/h\x00h/\x85q0Rq1ub.', 0, 1, 'invalid start byte')
why did this happen , and most importantly , how can i retrieve the code ? that data is already lost probably but i had valuable code there .
i believe if could open the file without running and just erase the line
import dill
dill.dump_session('notebook_env.db')
then i could again open the file without any problems . so maybe there's a way of doing that?
update
i tried to use
pip uninstall dill
hoped it would run the program again and stop when not recognizing dill , but it didn't go that way . still looking for a solution
update 2
tried to run the following on terminal :
iconv -f ISO-8859-1 -t UTF-8//TRANSLIT /Users/nimrodros/Untitled.ipynb -o /Users/nimrodros/New.ipynbh-MacBook-Pro-sl-nimrod:~ nimrodroTRANSLIT /Users/nimrodros/Untitled.ipynb -o /Users/nimrodros/New.ipynb
returned the following:
cdill._dill
_import_module
q__main__qqRq}q(__name__qhX__doc__qX#Automatically created module for IPython interactive environmentqX
__package__N__spec__q NX
__builtin__q
hbuiltinsq
q
fuc=[1,2,3,4]qX/import dillon_voltageqX
dill.dump_session('untitled.ipynb')qeX_ohq}qX_dhq]qX/Users/nimrodrofuc=[1,2,3,4]q%X_i1q&Xeye_correction_middle_fallq'X_i2q(h%Xfucq)]q*(KKKKeX_i3q+h#X_i4q,h!X_i5q-X/import dill
dill.dump_session('untitled.ipynb')q.Xdillq/hh/q0Rq1ub.iconv: -o: No such file or directory
iconv: /Users/nimrodros/New.ipynb: No such file or directory
h-MacBook-Pro-sl-nimrod:~ nimrodros$
the idea was to just convert it to a file that won't cause the notebook to crash so i could extract the valuable code. any ideas on how to continue?

write outputs from a script run into singularity

I can't get the output of a script run through singularity.
I have a python script, at the end of which the output is saved with:
...
with open('saveOut.pkl','wb') as myFile:
pickle.dump(myTable,myFile)
I want to run this script with singularity on a distant machine. Since I am learning singularity, I made a 'sand box' debian image (not compiled into a single 'img' file yet) in the directory /tmp/debian; in this image I copied the python script test.py in /usr/src and I run it with the command:
sudo singularity exec /tmp/debian python3.5 /usr/src/test.py
The problem:
It works well as long as I have only displayed results. with the pickle example described above, I don't get any saveOut.pkl file anywhere: this file is just not written anywhere but I don't see any message. I tried to write an explicit path in the python script. For instance /usr/src/saveOut.pkl, but this is the same.
How could I write a result ?
What was your expected result i.e. in which directory did you expect
to find the output file?
I expect a file saveOutput.pkl anywhere, in the container or not, I don't care the location. Currently I don't get it at all: neither in the container's current directory, nor in the container's /usr/src/, nor on the host, nor anywhere.
Did you look for it on the host or in the container?
both, I don't see it anywhere
What's happening here is that your python script is writing the pickle file to its current location (/usr/src/ in the container). Then, since the output from your script is not persistent (due to the sandbox not being writable on execution), it gets deleted at the end of the run.
I believe you could change your script:
with open('/opt/saveOut.pkl','wb') as myFile:
pickle.dump(myTable,myFile)
and then bind the local directory and get the output you're looking for:
sudo singularity exec -B ./:/opt /tmp/debian python3.5 /usr/src/test.py
This worked for me, anyway.

noob at MNIST and I do not know what to look for in the documentation

I am getting errors like
from: can't read /var/mail/tensorflow.examples.tutorials.mnist
from: can't read /var/mail/future
what am i doing wrong?
From the error messages, it sounds like you are trying to run a TensorFlow program by (i) typing commands into a bash (or other command) prompt, or (ii) running it using a command-line interpreter (e.g. by running source mnist.py).
To run a TensorFlow Python program, e.g. tensorflow/examples/tutorials/mnist/mnist.py you must run it under python, by entering the following command at a command-line prompt:
python tensorflow/examples/tutorials/mnist/mnist.py