say for example I realise that it’s shawarma not pies, and want to make an easy fix without troubling the python code
Would it be too messy to store the response in separate text files & read them in with Python?
And don’t forget this bit!
hmm that’s a lot of files. maybe though - it’s a thought because then could just reference them by name
Or maybe one file with some kind of headers for each response.
Are you making a front end and want the formatted text to be displayed with bullet points?
Or is it just a pop-up in Excel at the minute?
A few screenshots might help
Maybe Python is over engineering this?
Sounds to me like you could easily knock this up in an Access “database” with some VBA
I tried VBA, it’s horrible all that object oriented stuff
will try some screenshots later
the python is great for scraping data from about 5 different lab pdfs, and a dump from our own system which for unknown reasons can only be a pdf. I’m keeping the scraped data in a python dictionary.
then there’s an excel template spreadsheet with all the possible fields I could want to report on. python fills them from the dictionary. some will be left blank, that’s ok.
so at this point I have a nice looking spreadsheet, automatically populated. happy with thing up to this point, to my amazement it works.
what I want to do next is build a .doc with pre-written text paragraphs based on the different values in the spreadsheet cells- just not sure of the best way to do this.
it’s not a straight if A then B, it’s more if A but not B and C is less than D, then text xxx , etc
Guessing you’re not using classes, instances and attributes in Python then?
So this spreadsheet, I’m guessing, has patient data in it; from which you wish to create a letter to them, as a .DOC file.
I’d store them as text files and have Python read them in as dictionaries. Have your BMI phrases stored as “BMI_letter.txt” and then Python can use those letter up to the underscore to save the dictionary dynamically
I’d save all of the text files in a sub-directory of the Python application in let’s say a folder called “parameters”
For BMI, I might have something like;
(Float(‘-inf’, 0) : “Something went wrong”
(0, 184) : “Eat more shawarma”
(185, 249) : “Keep doing what you do!”
(250, 299) : “Slow down at those hotel nights”
(300, 399) : “Eat less shawarma”
(400, float(‘inf’)) : “I didn’t realise elephants were here!”
Then just have some logic to read that in to a “master” dictionary of dictionaries
Yep exactly that
Thanks for those tips, that sounds great, I’ll try it
Nice pun
Does the Excel “look like” the letter?
Or is it just data?
If the latter, get that read into a Pandas dataframe, then iterate over that to produce a letter per observation
You could use aspose-words to do that.
just being trying to get my head round all this " init self " stuff. Not there yet. Is it just good discipline, or does it actually make better code?
dunders = double underscores
I’m guessing you’ve just got a massive piece of code that’s not broken up into functions in sub directories.
Do you use
if _ name _ = _ main _ then:
At all?
erm…
so no, but I have broken up the main bit of code by writing other .py files for some parts and importing them into the main bit
How’ve you done that?
With an “import myCoolFunction from Utils as mcf”
Or something like that?
yep, like that: in the main program, at the start:
import read_lab_report.py
and then later on:
data.extend(read_lab_report.scan_pdf(filename))
where data is the dictionary containing all the stuff for the report, filename is the path to the pdf with the actual results, scan_pdf is a function in read_lab_report.py
dunno if that’s a good way to do it but seems it’s breaking the thing up into manageable modules
You could go to town on it
Do you know about eggs and wheels?
And a requirements file for the virtual environment?
But … sounds good what you’ve done
Have you built coverage tests and got a report spat out once it’s built?
Get some of those functions decorated and parameterized.
I’d also expect all of your functions to have lovely docstrings, so we can document the application using Sphinx
Can hear these words coming out, but am not sure what they mean
obv I’m just a hobby jogger
did read an interesting thing about objects though on the back of what you said: that if you set a=40 it creates an object “40” , and then if you set b=a it doesn’t create another object, just makes a note that the object “40” has been referenced twice. Then if you do stuff like a+=1 and b = something else, it makes a note that the object “40” is no longer referenced anywhere and destroys it… is that right?
Maybe neither does Poet, but they impress at the interview, and a contractor is gone before they find out…