DEV Community

Discussion on: Automatic Reporting in Python - Part 3: Packaging It Up

Collapse
 
kirefiel profile image
Leif-Erik

Hi, thanks for a great guide.

I am currently trying to get the argparse up and running in the script, but when I run it does not find the files. Is there any hardcoding of the filepath to the datafolder in the script that should have included?

Collapse
 
goyder profile image
goyder

Howdy! Glad you've found it useful.

If you could provide a full dump of the error code, I can better take a guess at the issue.

However, looking through the code, I now realise it assumes that an outputs folder is available in the folder. You could either:

  • Manually create an outputs folder (not a thorough fix)
  • Modify the code to check if the target folder exists, and create it if it doesn't, before writing to it.
Collapse
 
kirefiel profile image
Leif-Erik

Yeah it is really useful. I am a python noob, so it was like jumping out to swim in the deep end. But I have learned a lot by just playing around with it, trying to find out what everything does. Are you planning on doing a guide on how to include images/figures in a html report?

Below is the error I get.

Success When I have the files in the same folder as the script

PS C:\Users\lpe061\Dropbox\Python\Automatic Reporting> python Autoreport.py LAS318_results.csv LAS319_results.csv LAS320_results.csv
Successfully wrote "report.html" to folder "outputs".

When the files are in the "datasets" folder

PS C:\Users\lpe061\Dropbox\Python\Automatic Reporting> python Autoreport.py LAS318_results.csv LAS319_results.csv LAS320_results.csv
Traceback (most recent call last):
File "Autoreport.py", line 239, in
main()
File "Autoreport.py", line 202, in main
SampleResults(sample_name, results_filepath))
File "Autoreport.py", line 29, in init
self.df_results = csv_to_df(filepath) # Filesystem access
File "Autoreport.py", line 167, in csv_to_df
df = pd.read_csv(filepath, index_col=0)
File "C:\Users\lpe061\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
return read(filepath_or_buffer, kwds)
File "C:\Users\lpe061\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\lpe061\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 787, in __init
_
self.make_engine(self.engine)
File "C:\Users\lpe061\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\lpe061\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 1708, in __init
_
self.reader = parsers.TextReader(src, **kwds)
File "pandas_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.
cinit_
File "pandas_libs\parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: File b'LAS318_results.csv' does not exist
PS C:\Users\lpe061\Dropbox\Python\Automatic Reporting>

Thread Thread
 
goyder profile image
goyder

Hey Leif,

Thanks for the comparison of functional/non-functional calls - gives me a lot more context on where the issue might be.

You'll need to provide a relative path to the datasets (relative to the script) to get it to run if you have have your datasets under the folder - i.e. run python Autoreport.py datasets/LAS318_results.csv datasets/LAS319_results.csv datasets/LAS320_results.csv. In its current form, the script won't search any subfolders.

(It's curious to me that the FileNotFoundError is returning a byte string, indicated the b in front of the filepath... that makes me raise an eyebrow.)

I hadn't planned on adding any additional examples around how to publish images in the reports, but in previous projects I've added similar features. The key questions that I worked through were:

  • How do I present the images in the report? Do I present them all, just provide links, or have some kind of interactive tool?
  • Where do I store the images for access? Do I keep a local copy of all the images (and if so, how do I manage moving the report around)? Should I push all the images to be hosted somewhere else - or even inside the .html file somehow?

These questions are a little outside of Python and more into web dev, which I am definitely not an expert in. They're all very interesting options to explore, however.