PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 17, 2022

[FIXED] How to capture jupyter cell output without supressing live printing?

 August 17, 2022     capture, jupyter-notebook, output, python     No comments   

Issue

In jupyter there is a magic function that allows to capture and parse output of a cell:

%%capture capt_out
# cell body that prints interesting stuff every second
# another cell
# code for printing or processing output (i.e for plots):
print(capt_out)

The problem is, I need to see the output live (because this is a Darknet model training and I need to know how much progress has been made) and then parse it to create plots based on it.

Is there an easy way to capture the output without suppressing printing?


Solution

This is not a general solution, but works for my situation:

!./darknet detector some_parameters 2>&1 | tee some_file.txt

Since my jupyter cell runs a binary through bash, I can simply use tee command to save output to file without suppressing live printing. Then I read this file with python

with open(some_file.txt, r) as f:
   text = f.read()

2>&1 redirects stderr to stdout.



Answered By - Huxwell
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing