![]() |
Showing and saving the output of a python file run through bash - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Showing and saving the output of a python file run through bash (/thread-35153.html) |
Showing and saving the output of a python file run through bash - Rim - Oct-04-2021 Hi all, I'm new to the world of Python, linux and programming in general so my question may be very basic but I can't find an answer anywhere. I'm running a python file (to do a regression so I'm expecting tables as result) on a virtual cluster using a shell file. The job launches and runs fine but I can't visualize the result (print them on prompt) nor create a file with the output. What could I do to see the results of my python file? Is there a command to put in the bash or in my Python code? I've already tried a couple of solutions that did not work like putting the following command in the bash python mycode.py > SomeFile.txtThis generated an empty txt file named SomeFile. I also tried adding the following lines in my Python code to get the results in tex and pickle files but it didn't work either: print(f"Output file: {results.data.htmlFileName}") results.writeLaTeX() print(f'LaTeX file: {results.data.latexFileName}') results.writePickle() print(f'Pickle file: {results.data.pickleFileName}')Thank you in advance for any help ![]() PS: To have a better idea of the Python code that I want to run on the cluster I attached the script mycode.py (small clarification: since it is the first code I run so as a test I only ask for 5 Monte Carlo draws but the objective is to ask for 100000 draws or more) RE: Showing and saving the output of a python file run through bash - perfringo - Oct-04-2021 You should tell Python to run the file, so from bash one can do: python my_program.py > my_program_output.txtFrom within Python one can print to file and write to file. RE: Showing and saving the output of a python file run through bash - Rim - Oct-05-2021 Thank you perfringo! That is exactly what I did. I just forgot to put it in my question here. The resulting txt file is empty :/ RE: Showing and saving the output of a python file run through bash - gerpark - Oct-06-2021 why not test it with a simple example. Create a script "hello.py" with one print statement like print("Hello World"). On bash (the line starts with a $) go to the directory of your script and type (the interpreters name is python or python3): python3 hello.py You should either see "Hello World" or some kind of error. |