Python Forum
Showing and saving the output of a python file run through bash
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Showing and saving the output of a python file run through bash
#1
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.txt 
This 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 Smile

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)

Attached Files

.py   mycode.py (Size: 5.69 KB / Downloads: 236)
Reply
#2
You should tell Python to run the file, so from bash one can do:

python my_program.py > my_program_output.txt
From within Python one can print to file and write to file.
Rim likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
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 :/
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 349 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,091 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Saving the times a script is run to a file or ... 3Pinter 7 1,389 Oct-19-2022, 05:38 PM
Last Post: 3Pinter
  Code Assistance needed in saving the file MithunT 0 812 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Saving the print result in a text file Calli 8 1,786 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Saving progress in a Python program to use later Led_Zeppelin 9 2,158 Sep-11-2022, 01:32 PM
Last Post: snippsat
  Trying to determine attachment file type before saving off.. cubangt 1 2,143 Feb-23-2022, 07:45 PM
Last Post: cubangt
  saving and loading text from the clipboard with python program MaartenRo 2 1,657 Jan-22-2022, 05:04 AM
Last Post: MaartenRo
  Call a bash script from within a Python programme Pedroski55 6 2,439 Dec-06-2021, 01:53 PM
Last Post: DeaD_EyE
Photo how I write the output into xml file in python? 3lnyn0 1 2,225 Oct-31-2021, 05:40 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020