Analytics Vidhya
Published in

Analytics Vidhya

How to write python code to generate simple html report for some scenarios like piping some output

This is a scenario which i faced in my real life work and it was one of the most exciting work also for generating a simple html report i wrote something complex and i was asked to create a function a bit similar to print and to identify if a table is coming pass a dict into the function

  1. As you can see i have to create a function file_appender which takes input data and output_path as arguments i wanted the function to be free and work with different output_paths so i haven’t restricted it to only output_html_path
  2. As we can see mp_print() function to identify if i am getting a table i am going to pass a dictionary with ‘table’ as key also in dictionary there may be other keys if you need them you just need to do a loop for keys and values and add to op_str which is string concatenation

3.As we can see table_html gives us a table in html syntax i am using it in mp_print if there is a dictionary with a key ‘table’.

So how simple the mp_print function is going to be in use?

So let’s see how the output is gonna look :) Also mp_print only writes to a file in html syntax so you can customize it by adding print statement inside mp_print like print(all_args) so that it will show output in your existing ide or console as well as write to a html file which can be rendered

The output looks decent

During this task when i created a complex type of print function my senior asked me that he said function can be complex but he wanted the freedom close to the print function which my first attempt lacked later i had to implement mp_print with only few conditionals

Its all about exploring,trying,running into errors,fixing em and getting a good output

Hope this helps please check below link for the file the code was for simple purpose the more the purpose the more complex code is going to be in most cases

https://drive.google.com/file/d/13iXKh01bXhj1b2mvodB20aRXxayE_tb3/view?usp=sharing

Happy learning !

--

--

--

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Recommended from Medium

Metamask authentication in Next.js with Clerk 🔒

I Met a Rich Programmer, He Gave Me 3 Life-Changing Pieces of Advice

3 Types of Programmers in this World: Which One Are You?

Js Program to swap two numbers

A quick way to do animations in React

How to build a simple HackerNews feed with styled-components

3 Qualities that are Inherited by Every Programmer

My Review of the DevAnywhere.io Mentorship Program

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kasinath Reddy

Kasinath Reddy

More from Medium

Python os.path.join and string format placeholder

How To Print Type Of Variable In Python — pythonpip.com

How To Create Python Tkinter Entry Widgets in 2022

Python __str__ and __repr__