Saturday’s Python Lesson
I have been dabbling more and more with Python. Python is a programming language (that, FWIW, comes pre-installed on a Mac) that is used by a lot of data scientists. As programming languages go it isn’t too hard to learn and is really versatile. One of the things that makes it so versatile is that it can use outside modules and libraries easily and there seems to be a module that will do just about anything you can want.
Why
A few years back I tried to convince L to use the import function built into Blackboard (MacEwan’s LMS [Learning Management System]) to import quiz questions and move from paper-based marking to a more automated workflow. It didn’t work, but in the process I did build a php module to build quizzes.
Then COVID happened.
But, no, before you jump to conclusions, I didn’t manage to convince her to use the bulk import even though she started to use the quiz modules to deliver and mark the quiz. Baby steps.
Then Moodle happened.
MacEwan is in the process of giving up on Blackboard and transitioning to Moodle — which is an open-source LMS. As it happens L has another, temporary, teaching gig at a different institution that also uses Moodle — this was a lot of additional work and learning, so she was starting to come around to the idea I might be able to help.
As a result, eventually, with great sighs and heaving shoulders, she gave in to my pestering and allowed me to upload one of her quizzes… and lo and behold she was impressed at the ease! Minus a few technical glitches.
My End
What I had done was use the format info from my previous php project. Then I used her docx file and by saving it as a text file I was able to do a few search and replaces via regex to create an upload compatible file. Blackboard wants files to look like:
TF True or false? For Niklas Luhmann, the individual agent is not integral to society. TRUE
MC In the sentence "Maybe I got mine, but you'll all get yours.", what part of speech is "yours"? pronoun CORRECT adjective INCORRECT preposition INCORRECT noun INCORRECT
Version One
…of my process was simply to build the regex. Luckily she used a pretty standard format to write the questions so I just had to find the pattern and use it to change it to the proper format.
TRUE/FALSE
True or false? For Niklas Luhmann, the individual agent is not integral to society.
True
FalsePRONOUNS
In the sentence “Maybe I got mine, but you’ll all get yours.”, what part of speech is “yours”?
pronoun
preposition
noun
adjective
Find:
(.*?)\n\n(.*?)\n(.*?)\n(.*?)\n(.*?)\n\n
Replace with:
MC\t\1\t\2\tCORRECT\t\3\tINCORRECT\t\4\tINCORRECT\t\5\tINCORRECT\n
In English this says find: anything (group1) followed by 2 line breaks followed by anything (group2) followed by 1 line break followed by anything (group3) followed by 1 line break followed by anything (group4) followed by 1 line break followed by anything (group5) followed by 2 line breaks
Replace it with: MC tab Group1 tab Group2 tab CORRECT tab Group3 tab INCORRECT tab Group4 tab INCORRECT tab Group5 tab INCORRECT line break
Easy, right? It was slightly different for the True/False questions as there was only two answers but followed the same principles.
Version Two
…added a python script that looked for the ALL CAPS and split the file into two separate files. At which point I also wrote in a search and replace of ‘’ and “” into ' and " since Blackboard didn’t like the special characters.
Version Three
…combined the original regexes with the python script and did it all in one pass. Success! I also added a randomization bit so she could leave the first Multiple Choice answer as the Correct one and the script would randomize them before upload.
Of course when I went to demo the speed and efficiency of my “wondrous creation” to L I forgot to convert the docx to a txt file and it failed. But I soldiered on, did the necessary step and then proceeded — but the “burning shame” of failure remained and so…
Version Four
…added a docx import module and that’s where I am now.
Given an Word docx file with sections delineated by titles in ALL CAPS, this script will divided it into several text files named after the sections, convert curly quotes , format the questions in Multiple Choice or True/False format, and randomize the MC answers.
The resulting files can be uploaded to Blackboard’s question pool for use in multiple quizzes. Of course now I have to do it all over agin for Moodle as it uses a completely different import format 🙂
# import necessary modules
import os
import random
import re
import pypandoc
# NOTE Sections must be in ALL CAPS. They must be named TRUE FALSE (or TRUE / FALSE)
# or else be in the Multiple Choice format.
# set directory to current path of python file
directory_path = os.path.dirname(__file__)
# get file name
print('Enter the filename (without.docx):')
filename = input()
# set docx file and output file
docxFilename = directory_path + "/" + filename + ".docx"
outputfilename = directory_path + "/" + filename + ".txt"
# use pandoc to convert docx to txt
output = pypandoc.convert_file(
docxFilename, 'plain', outputfile=outputfilename,
extra_args=['--wrap=preserve'])
assert output == ""
# Open the converted file
filecontents = open(
directory_path + "/" + filename + ".txt", "r")
# Assigns the variable filecontents the contents of filename.txt, not just the location of the file
filecontents = str(filecontents.read())
# Finds all the ALL CAPS in the file and makes a list (section) of all the sections
sectionname = re.compile(
r'\n(?=[A-Z])([/A-Z\s]+)\n')
section = re.split(sectionname, filecontents)
# Removes the preamble in list and starts with first ALL CAPS section
section.pop(0)
# Loops for the number of sections in the file, starting at the first split
# looking for every 2nd section (the contents rather than the title)
for i in range(0, len(section)+1, 2):
# Set section name and strip out extra characters
sectionname = section[i-2][:-1]
sectionname = re.sub("[/|\s]", "", sectionname)
# Opens a file with the name of ALL CAPS sections; if it does not exist, it creates one
writeFile = open(
directory_path + "/" + "split-files/"+sectionname+".txt", "w+")
# sets text to item (contents) in the list after ALL CAPS delimiter
text = section[i-1]
# strips out curly quotes
text = text.replace('“', '"').replace(
'‘', "'").replace('”', '"').replace('’', "'")
# if the sectionname is TRUEFALSE then...
# then use regex to format questions as TF otherwise format as MC
if sectionname == "TRUEFALSE":
# Substitute all patterns in one go
text = re.sub(r'(.*?)\n\n(.*?)\n\n(.*?)(\n\n|\n\Z|\Z)',
lambda x: 'TF \t' + x.group(1) + '\t' + x.group(2).upper() + '\n', text)
writeFile.write(text)
else:
# else loop though text, match pattern and name capture groups. Uses ?P<name> to name groups
for m in re.finditer(r'(?P<qq>.*?)\n\n(?P<one>.*?)\n\n(?P<two>.*?)\n\n(?P<three>.*?)\n\n(?P<four>.*?)(\n\n|\n\Z|\Z)', text):
question = m.group('qq')
# write capture groups of answer into a list so we can randomize it
qlist = [m.group('one') + "\tCORRECT", m.group(
'two') + "\tINCORRECT", m.group('three') + "\tINCORRECT", m.group('four') + "\tINCORRECT"]
# randomize list
random.shuffle(qlist)
# construct question and answers
text = "MC\t" + question + "\t" + qlist[0] + "\t" + qlist[1] + "\t" + \
qlist[2] + "\t" + qlist[3] + "\t\n"
# Write to file
writeFile.write(text)
writeFile.close() # Finally, it closes the text file
Instagram Since Last Time


Sunday Cats
Toes are many things
Long or short, hairy, or with warts
Unadorned or sporting rings
Often sporting colours of all sorts.
A toe’s big job is to keep you up-right
But when you stub your favourite toe
On that table leg just out of sight
We know that you’ll also scream with woe.
But all in all, your toe’s a friend
Something faithful, loyal
That you can count on in the end
That treats you right royal.
But if you are a ferocious cat
A sharp-toothed predator bursting with fight
When seeking prey, they are all of that,
But in addition,
Toes are
something
to bite
Saturday Review
I noticed the other day that a lot of people on various review sites were getting advanced copies of books from NetGalley and when I mentioned it to L she replied she had an account, but hadn’t used it much.
A quick perusal of the site turned up Scalzi’s new book The Kaiju Preservation Society which is due out in late March. The tile had intrigued me since I first heard it—I am not much of a Godzilla nerd. So I asked her to acquire that (and another) on the promise I would write the requisite review. So here is the review. Maybe I will make this a thing.
The Kaiju Preservation Society
John Scalzi
pub date: March 15, 2022
reviewed from eGalley
This review has been (moved to macblaze.ca/books/reviews/2022/the-kaiju-preservation-society)
Monday Reflections
Uhmmm…
I seemed to have missed Saturday. Speaking of missing things…
Writing progress
Uhmmmmm…
Not so much?
I have a friend who sets out every once in a while to do some sort of challenge… an illustration a day, a painting a week. She inevitably trails off and eventually stops.
A failure?
I think not. Because there are always some lovely drawings left behind to commemorate the attempt. Trying is never a failure. Not trying isn’t either. The idea of failure is an external force… at least that’s my excuse.
And I have some great outlines and background info now so that’s a positive. I am sure I will get back to it. Eventually. Maybe. No drama though…
Old and unfinished
I started this back in 2014. Theres about 2500 words more and then it just trails off. But I kinda like it.
Morning was definitely broken. Henry ‘Hank’ Hagar Jacobs slammed his index finger unerringly down on the cancel button of his alarm clock and buried his face in the remains of his pillow. It had been a life-long dream to hunt down the sonofabitch who’d invented mornings and show him the real meaning of life.
He kicked off the faded purple comforter and rolled his feet to the floor. From the scratched and dented blue and brass trunk at the foot of the futon he dug out a new pair of black cheenos, tags still hanging from the waist. He had a client to see this morning and you never get a second chance to not give a crap about making a good first impression.
Rubbing his eyes with the back of his knuckles, he staggered across the room to the small kitchen, plugged in the dingy electric kettle and sat on the edge of his table while he surveyed the jars and cans piled haphazardly on the counter. Spotting the nearly empty jar of instant coffee, he grabbed his mug from the pile in the sink and opened up 5 sugar packets from his stash, courtesy of corporate coffee, and poured them in. He dumped the last of the coffee in the mug, banging on the bottom of the jar, hoping it would be enough for a caffeine fix. The hot water went into the coffee jar and a few swishes ensured that he’d gotten all he could out of the efforts of Juan and his hardworking ass, before it joined the spoonfuls of sugar in the mug. Just the medicine I need. he thought as the sweet, syrupy liquid flowed down his throat.
As life started to seep back into his brain Hank stared sightlessly at the garishly stained red doors of the wooden cabinets. What in god’s name was that lunatic of a landlord thinking when he did that? For the forty-millionth time he resisted the urge to buy a can of black enamel spraypaint and rectify the situation. But I don’t want to start down that road, do I.
Mug empty, it went back into the sink and he gathered up a chipped but clean Denby bowl acquired recently from the local discount store and a bright yellow box of generic cereal and turned to the single chrome and vinyl chair at the table.
Jacobs brushed the pile of magazines and unopened mail to one side, a couple of them sliding to the already littered linoleum floor. The box of generic toasty Oaty O’s yielded most of a bowl of disgusting circles of dirt-flavoured breakfast before dumping the obligatory hated pile of cereal dust and chunks on top of his breakfast. He blew as much of it away as possible, gave up and glanced around the table.
“Fuck. I knew it. There is no spoon.”
Sunday Salad
Do you like to say arugula?
I do.
Ah-roooo-ga-la!
I also like to say synecdoche,
even though I don’t know how.
Ah-roooo-gala.
There I said it again.
Sin eck doh key
Rhymes with me.
And I like to say arugula.
You should too.
Sunday Dawg Day
Nature vs Nurture
Bouncy fluffy farmer’s pup
Fluffy bouncy baby sheep
Charging round the busy yard
Round the guarded field he leaps
Chasing angry butterflies
Head butting bossy relations
Unaware of their destinies
Or their impending integration
Dog & Sheep
Sheep & Dog
Alas friendship is not to be
For each will have a job to do
Sheep
Dog
Sheepdog
Ya, ya… it’s still morning and I’m not yet awake. It was better in my head. But it fulfils the remit of “poem” so there…
Saturday Reflection: Examine your source
Someone was trying to promote a Youtuber [Dr. John Campbell, RN, PhD] (https://www.youtube.com/c/Campbellteaching) as giving the expert advice on Covid. I poo-poo’d him and he took umbrance, accusing me of not even looking at his credentials:
Originally Posted by Midnight Son
He teaches Nursing in a Northern England University and is interviewed quite often on DW the German Television Network, about Covid issues.So look before you bark please.
I told him I did look… And I had, I’d dismissed the guy months before because…well…
Seriously you actively want people to turn to YouTube for the “truth” on a subject as broad and deep as this pandemic? If I want to find out what’s the deal with Log4J or why the latest Space X blew up I totally go to YouTube and watch a synopsis. But I don’t walk away thinking I know anything more than a supposed SME can dumb down and squeeze into the 20 minute video format. And who know just how educated the presenter is or what his agenda is? All I have is a briefest whiff of the issue.
But our egos always make fools of us don’t they? There is a humorous trope in Universities that involves the undergraduate — having taken 40 hours of any given subject — spouting off like he was going to solve the world’s ill in one brilliant stroke (see Good Will Hunting for a fictionalization of this — I’ve see it in real life). Sometime they grow out of it, sometimes they don’t.
This stuff is complex. 80% of the people on these forums (and in the “real” world) just can’t/won’t wrap their head around that and so are just looking for the quick fix. They are like the supplicant going to the parish priest looking for the meaning of life…if that priest actually knew it I highly doubt he would be a lowly parish priest. Instead the priest does what he is good at and explains it some way the poor sod is capable of grasping and sends him away to contemplate his own ignorance.
But what of the other 20% (he says liberally making up statistics)? Some give facts as they see them and leave it up to us to recognize the depth of our cluelessness and some valiantly try to impart the, admittedly greater, knowledge they hold—of course they too often express that understanding as “fact” thus adding to the level of general misinformation. But a few accurate units of knowledge doesn’t mean they—or any youtube/twitter/self-proclaimed virologist/generic expert — can correctly interpret what’s going on out there any more than the parish priest. It’s complex. Thousands and thousands of scientists from many, many disciplines complex.
I’ve got 6 years of studying renaissance drama under my belt, some of that at the graduate level, and I tell you it is with profound humility that I approach the topic of Shakespeare and Marlowe. The depths of what I don’t know astound me and just catching up on the scholarship I have missed over the last 20 years would probably break me.
Dr. Campbell is not a virologist. He is not a sociologist. He is not an expert in international relations, internal medicine, supply-chain management, economics, city management or even bio-chemistry. He doesn’t know how to make a vaccine, distribute it, budget it, or figure out how to get a scared and/or ignorant population to take it. He doesn’t know the social and psychological factors that differentiate Canada from the US, or Britain from Australia and the unique political systems that each follows, and he sure as h*ll doesn’t know what backwoods Africa or India is making of all this.
What he is, is a teacher. So he is trying. Unfortunately — unlike the ill-educated high school English teacher I had that harmlessly tried to convince us that Shakespeare thought all nuns were whores — he has a world wide audience and is frankly, to me, so far from harmless as to be an active danger to the public weal.
So ya. I do comprehend…at least that little bit. The rest I am, like the rest of us, desperately struggling with. Rant over.
Sunday Poem Day
Seeing Spots
Ferocious cloud leopard
hidden in the rocks
Invisible predator
silent and deadly
creep
creep
creep
creep
An explosion
of ferocity
Escape is impossible
entwined bodies roll and writhe
The prey is vanquished
Then Mama rises
knocking her kitten to the ground
Her long rough tongue
caresses the successful offspring
Learning to hunt is hard work.
Saturday Reflections
I know, I know 2 posts in a day…if you are looking for the annual book post scroll down.
But I think, once again, I will try to write “every day” in 2022. I did it back in 2012 (see link above) to bizarre effect and since have had sporadicly poor success at writing anything consistently.
The 2022 Rules
- I will try and write something coherent e.g. fiction of some sort.
- I believe I will take the weekends off from that stream and instead try to continue “Saturday Reflections” and maybe something like Sunday Poem-Day
- At this point (I have two days to decide) I think I will keep the weekday writing offline — or perhaps start a new blog/subdomain. I will update later.
- I will start with just tagging them writing and decided later if I want to move these maundering into a category (spoiler: I expect I will)
The point
Preventing brain fog? A curiosity to see if I can actually be more productive? An attempt to create a sense of order? A desire to be independently solvent (rich seems a bit much to ask for)? Ongoing Earl jealousy?
Today’s thoughts
Netflix, Youtube et al.
I mentioned on Earl’s blog that I had watched very few movies this past year. But what we have watched is a lot of sitcom-ish stuff like Modern Family, The Muppets, Letterkenney, Rick and Morty and a ton of British panel/comedy shows. It turns out I am increasing enjoying European (is British European anymore?) stuff.
Australia
Not really but the producers and original movie was Australian. What We Do in the Shadows is a mockumentary about vampires living in Staten Island. It also stars Matt Berry who is one of those sneaks-up-on-you-from-behind funny guys that I first encountered as a boss on The IT Crowd. Only 3 seasons but well worth a watch if you can find it!
L reminds me we also watched Aunty Donna’s Big Ol’ House of Fun. Very, very… err…pythonesque? Aunty Donna is a comedy trio from Australia and they are pretty darn funny in that bizarro way…
France
I highly recommend Lupin. Two series of 5 parts with a third promised. Very clever and suspenseful and with that perfect gentleman-thief vibe. If you know French at all you have the added enjoyment of arguing with the subtitle translator’s choices. Quite bizarre sometimes.
We also watched and enjoyed Dix pour cent which was strangely and, in my opinion, detrimentally translated to Call my Agent!. It has 4 seasons and a promised movie reunion coming soon. Very soap-opera but the French take keeps it from seeming inane like Dallas et al. We really enjoyed it.
Britain
We worked our way through Stephen Fry’s (and now Sandi Toksvig) QI. Funny and smart. And you learn (and relearn) so much…
8 out of 10 Cats Does Countdown is a must see. Countdown is a Jeopardy-type show involving solving anagrams and math problems and has been on the air forever. 8 out of 10 Cats was/is a comedy panel show hosted by Jimmy Carr with Sean Lock and Jon Richardson as team captains. Back in 2012 Channel 4 had a Mashup event where they mashed up a bunch of different shows from their channel into a special. 8 out of 10 Cats Does Countdown was a huge success and now is produced (alongside the originals) with 5–8 episodes every year.
We also started in on Mock the Week hosted by Dara Ó Briain and are slowly making our way to the present. There are currently 20 seasons starting way back in 2005 and we are somewhere in Season 10. Funny, irreverent and you learn a lot about Britain’s political and social scenes. We are still in the Obama era and I am looking forward to the Trump period…
TaskMaster has also been a highlight. Greg Davies and Alex Horne have made a fantastic series where celebrities are challenged to do ridiculous things. Another one we are all caught up in (12 series so far) and looking forward to the next season.
Suffice it say we have had our share of belly laughs this long dismal year. Thank god for British humour. And Youtube. And friends with Hulu.