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: 361)
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
  System showing np.int64(xxx) as output leea2024 3 6,104 Aug-10-2024, 10:55 AM
Last Post: leea2024
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 996 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 8,258 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 2,074 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Saving the times a script is run to a file or ... 3Pinter 7 2,882 Oct-19-2022, 05:38 PM
Last Post: 3Pinter
  Code Assistance needed in saving the file MithunT 0 1,348 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Saving the print result in a text file Calli 8 3,964 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Saving progress in a Python program to use later Led_Zeppelin 9 4,556 Sep-11-2022, 01:32 PM
Last Post: snippsat
  Trying to determine attachment file type before saving off.. cubangt 1 3,560 Feb-23-2022, 07:45 PM
Last Post: cubangt
  saving and loading text from the clipboard with python program MaartenRo 2 2,858 Jan-22-2022, 05:04 AM
Last Post: MaartenRo

Forum Jump:

User Panel Messages

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