Categories
Applications Coding Tutorials

The missing piece in my Python scripts

My quest to automate parts of my workflows usually involves writing Python scripts to streamline some of my tasks as a Happiness Engineer.

One output has confused me for far longer than it should have, and I was shown the light today (in the form of a pretty simple solution).

My dilemma

Many of my scripts generate template documents. These include meeting agendas, hangout notes, and team reports. These documents include a couple components that I’ve largely automated using Python, such as –

  • Calculating dates and times in reports (sometimes including timezone conversions);
  • Taking inputs I provide in response to command line prompts, running calculations, and adding those to fields in my reports; and so on.

Many of my documents have a static list of team members that I ping much like Twitter mentions when I publish them as posts on internal blogs (we use internal blogs quite a lot, as you can imagine). Those lists each need to be updated manually every time there’s a change in the team composition, in each of the documents the list appears in.

Although the team composition doesn’t change frequently, I often find myself re-using a script for a team report, or hangout agenda, for example, in another group I work with. This means another set of documents where I need to manually create a list of people, and maintain that.

An example could be something like this:

Pinging: @john-doe, @maryjacobs, @davesmith, @janestuart, @tomwright, @steverobinson

The solution

Currently, the first part of generating this sort of list of people is creating a .csv file that looks something like this:

first_name,last_name,username
John,Doe,john-doe
Mary,Smith-Robinson,maryjacobs
Dave,Smith,davesmith
Jane,Stuart,janestuart
Tom,Wright,tomwright
Steve,Robinson,steverobinson

I was planning on using Python Classes to do this, but quickly realised that I don’t understand Classes nearly well enough to using this feature for this aspect of my documents.

I realised that there’s actually a simpler solution using .csv files and the csv module available in Python instead, after watching Corey Schafer‘s tutorial on this, here:

As an aside, Schafer’s tutorials are wonderful!

I was able to borrow from Schafer’s solutions to write a script that produced a list that looks something like this:

Pinging: ['@john-doe', '@maryjacobs', '@davesmith', '@janestuart', '@tomwright', '@steverobinson']

My script looked like this:

import csv

with open('people.csv', 'r') as csv_file:
    csv_reader = csv.DictReader(csv_file)

    members = []

    for line in csv_reader:
        wpuser = f"@{line['wp_user']}"
        members.append(wpuser)

print(f'Pinging: {members}')

I couldn’t work out how to just generate a list of usernames separated by spaces. I ran into a similar issue with other scripts where I similarly loop over a list of items to produce some sort of list-generated output.

In other words, I couldn’t figure out how to output the list of usernames without the []' characters you see in my initial output.

So, I asked for help on reddit where JohnnyJordaan pointed me to this StackOverflow post that includes a couple solutions to a similar question. I had searched for a solution to my challenge, but didn’t come across this answer (or anything like it).

Clearly, I need to work on my Googling skills when it comes to finding solutions to my coding challenges.

Anyway, the solution that JohnnyJordaan suggested is pretty simple. Instead of using something like print(f'Pinging: {members}'), I could rather join the items in the list with a statement like this:

print(f'Pinging: {", ".join(members)}')

As I suspected, the solution is pretty simple. It just eluded me, completely. So thank you to JohnnyJordaan for the pointer!

I also like the * that came up in one of the StackOverflow solutions, but it doesn’t work with the f strings that I tend to use. Still, there are other ways to use them. Trey Hunner has an interesting post about these operators here (if you’re interested).

Categories
Business and work Mindsets Wellbeing

The lonely side of remote work

Rian linked to an interesting article about the challenges of working remotely titled “What Most Remote Companies Don’t Tell You About Remote Work“. I started reading it to get a sense of it, then sent it to my Pocket queue to read later.

This is how the article begins, it will give you an idea of what to expect:

Articles about the remote work lifestyle have tended to focus on drinking piña coladas on the beach, traveling the world, and otherwise enjoying a life that inspires envy in your social media following.

This is not one of those articles.

As an Automattician, I work completely remotely, although I’ve chosen to work from home. I think I’m pretty well suited to remote work. I much prefer working remotely to being in an office environment. There are downsides, sure, but the benefits far outweigh the challenges, at least for me.

Categories
Mindsets Writing

Facing a blank page

A blank page can be a little intimidating as a writer. Staring at a blank page and being unable to fill it with something intelligible is a common experience of writer’s block, the bane of most writers. I say “most” because there are probably some writers who find the challenge of writer’s block to be just the thing they need to break through it.

I’m not one of those writers.

Lately I’ve realized that despite all the writing that I do in my day job, I don’t do much personal writing. When I realise this and decide to start writing more frequently, I go utterly blank.

Well, that isn’t entirely accurate. I have ideas that I want to write about but they seem to fade awfully quickly and seem silly the next day so I shelve them.

One of my most effective muses when I do write is my collection of feeds and I came across a very appropriate item that I want to share. Brain Pickings has a post titled “Facing the Blank Page: Celebrated Writers on How to Overcome Creative Block” that includes a video with snippets of interviews from various writers about the dreaded blank page:

It is a highlights video drawing on a series of slightly longer interviews with each writer that were published by the Louisiana Channel on YouTube:

I think I resonated most with Philipp Meyer’s and Lydia Davis’ thoughts about the blank page but each interview is worth watching if you, like me, find yourself staring at a blank page frustratingly often.

You can find the Brain Pickings post with selected quotes here:

Facing the Blank Page: Celebrated Writers on How to Overcome Creative Block

Image credit: Pixabay

Categories
Events and Life Mindsets

Feminism from a tone-deaf male’s perspective

Feminism isn’t new to me. I have been aware of and supported the movement for about a long as I have had a sense of gender roles in our society. I think of myself as being respectful of gender equality and a woman’s right and ability to do pretty much whatever she sets her mind to do. I don’t believe my respect, recognition or permission is required. I believe women have as much a right to determine their own destinies as men do and that women’s rights are inherent.

Tone deaf, reading lips

At the same time, I am conscious of my tendency to be very male in my thinking. I wrote about this in a recent, private discussion on Facebook and I thought I’d repeat some of what I wrote to give you a better sense of what I mean. I was writing about participating in discussions about feminism as a man, a fairly risky exercise:

The problem with this topic for me is that it is a linguistic minefield shrouded in mystery.

It’s not to say that I’m insensitive to much of what feminism stands for but I am still a male raised by parents with certain perspectives on roles and relationships. It isn’t to say that my parents believed in submissive women and strong, manly men but they did the best they could as products of their upbringings.

I firmly believe in gender equality and women having as much choice over their destinies as men. At the same time, I also know some of my perceptions and subconscious beliefs are probably relatively patriarchal. I make conscious efforts to change my thinking but I make mistakes all the time.

When I read conversations like this my first instinct is to shut up and move away as quickly and quietly as I can. I just know that opening my mouth is a mistake because I am going to offend people, usually without intending to or even being aware of it.

Just adding a perspective from a flawed male who has definitely missed something important that everyone else seems to take as a given.

One of the commentators mentioned anger at the treatment women receive from men and I had a few thoughts about that too:

Actually I think women are fully entitled to be angry about a lot of things. There are times when I am glad that I am male because I don’t know how women put up with the crap men do, seemingly all the time. So angry is ok too because sometimes men only pay attention when faced with rage.

I think the conversation tends to go sideways when men who support gender equality (and what goes with it) become the targets of all that rage because we are more receptive to it. The men who make being male an embarrassment so often, just don’t care and your anger reinforces their attitudes.

The crux of the issue, for me at least, is this:

For sure but it seems, from my perspective, that when men try and participate in a discussion about feminism, the amount of care we have to take with language we use is analogous to a ritualistic tea ceremony.

It just doesn’t seem possible to have a meaningful discussion using imperfect language that almost certainly carries a legacy tone, irrespective of the underlying intentions and beliefs.

The discussion about mansplaining largely confuses me. It is probably because I lack an awareness of how to effectively listen (active listening? I’m a man, I am almost genetically coded to struggle with this) and explain perspectives without appearing to be condescending.

I know I definitely speak more than I should listen and have a tendency to forget to just listen. It doesn’t mean I don’t have a useful perspective or support gender equality (for example). It just means I sometimes use verbal crayons to express it.

What gender inequality means to me

There are many themes in feminist debates that I come across now and then which seem too extreme for me. I suppose that is bound to happen, particularly in debates about feminism and gender equality and the nuances in gender discrimination. Fortunately or unfortunately, most of those nuances elude me. While I understand that there are feminists who have adopted extreme positions on a range of topics including marriage and men opening doors for women, I don’t agree with those positions.

There is probably a lot in what I have written that only highlights the concerns many feminists raise about men and our problematic behaviours (things like mansplaining, which I think I have a basic understanding of but which can be pretty nuanced in itself). My efforts to outline support for feminism and gender equality probably only exacerbate the situation in some activists’ eyes and I accept that.

I grew up in a relatively liberal cultural context. Even then, I am almost coded to think about gender roles and relationships in certain ways that may seem anachronistic to many. There may be some sort of gender-neutral ideal for how people “should” talk and relate to each other. I don’t know what it is and I’m not sure I want to.

I recognise that men and women are different in many ways. We are physically different. Our brains seem to work a little differently and our bodies, generally, seem to handle some things better than others. None of those differences make one gender better than another or subordinate to the other, fundamentally. But, we are different and those differences are part of what make us remarkable.

There are some differences that are profound and deeply troubling to me as a man. As aware as I like to think I am, I have had very little insight into the daily challenges women face, just being women. Actually, scratch that, girls and women! These challenges are, to me, at the centre of gender equality and they were spelled out in a 2015 blog post by Gretchen Kelly titled “The Thing All Women Do That You Don’t Know About”:

This post is perfect for me. What I have come to accept is that I often need things to be spelled out to me and Kelly does a great job with that in her post. Below are some extracts that really stood out for me. The first touches on this need to spell stuff out for us men. We really can be utterly tone deaf:

Maybe it is so much our norm that it didn’t occur to us that we would have to tell them.

It occurred to me that they don’t know the scope of it and they don’t always understand that this is our reality. So, yeah, when I get fired up about a comment someone makes about a girl’s tight dress, they don’t always get it. When I get worked up over the everyday sexism I’m seeing and witnessing and watching… when I’m hearing of the things my daughter and her friends are experiencing… they don’t realize it’s the tiny tip of a much bigger iceberg.

When I think about the experiences Kelly writes about, I cringe. I cringe when I think my wife may be experiencing stuff like this every day. I cringe when I realise that I don’t even ask her whether she does? I especially cringe when I think about what our daughter may face as she grows up.

Guys, this is what it means to be a woman.

We are sexualized before we even understand what that means.

We develop into women while our minds are still innocent.

We get stares and comments before we can even drive—from adult men.

We feel uncomfortable but don’t know what to do, so we go about our lives. We learn at an early age, that to confront every situation that makes us squirm is to possibly put ourselves in danger. We are aware that we are the smaller, physically weaker sex—that boys and men are capable of overpowering us if they choose to. So we minimize and we de-escalate.

Glimpses of women’s daily challenges

What Kelly writes about is, to me, the scariest thing about how men and women tend to relate to each other. Whether a woman (womyn?) approves of marriage as a structured relationship or takes offence because I haven’t assumed an appropriately remorseful and submissive posture when dealing with her falls into the category of issues that may never be particularly meaningful to me. That may be unreasonably dismissive and patronising. I see it as an issue between the woman and whoever she is relating to.

What makes a deep impression on me and forces me to think deeply about how I live my life and relate to women are stories like Kelly’s. They speak about the fabric of our society and about the legacy we are leaving for our children.

Just a flawed male doing my part

I make a point of teaching our children (a boy and a girl) that they can both achieve great things. I love that my daughter admires Wonder Woman, a character I see as powerful, intelligent and confident. I also don’t particularly care whether my kids choose the pink or blue Kinder Joy eggs, only that they enjoy the treat.

I will keep teaching my son to let women enter before him and, when he is old enough, to open doors for women and to respect them (like my father taught me). If a woman takes offence at that, she will have missed his intention to be respectful and courteous. I don’t want him to grow up being ashamed of being male either.

I teach my daughter that she can do all the things she wants to do, even if they are traditionally male activities. I will also encourage her to learn to defend herself because I don’t want her to ever feel vulnerable because she is a girl. Like Wonder Woman, I want my daughter to grow up feeling powerful, confident and beautiful. I want her to feel free to express her femininity and be compassionate and see those qualities as strengths.

So, yes, I am male. I don’t always listen (something my wife will attest to, enthusiastically) and I can be pretty tone-deaf when it comes to all the things that contribute to gender inequality. I don’t understand all the issues and am not aware of all the nuances. I may never be and I’m not sure I want to be. It seems like a sterile and neurotic world to live in.

Above all, though, I definitely want to help create a world where the fear and compromises Kelly writes about become unpleasant memories. My contributions are not intellectual and semantic. They are the conversations I have with our children about how to be good people and my continuous efforts to be a better husband to my long-suffering wife.

I am glad we live in Israel. Casting Gal Gadot as Wonder Woman was a perfect choice. She represents so many of the inspiring qualities I see in Israeli women every day: they are confident, capable and beautiful. They set a very different tone for our children and I think that makes a big difference too.

My wife asked me if I consider myself a feminist. She defined being a feminist as “advocating social, political, legal, and economic rights for women equal to those of men”. Maybe I am but that doesn’t mean that I am not a flawed male with residual neanderthal tendencies, just like the many men who work really hard to help build a new world where women’s inherent rights are self-evident, not the subject of debate.

Image credit: Lost in Translation by Kris Krug, licensed CC BY-NC-SA 2.0

Categories
Events and Life Mindsets

“I was giving up on the life my false self tells me I must live”

Dr Kelly Flanagan’s post titled “Why We Should All Just Give Up” resonates with me. I often feel as if I am fighting against some impossible force to get simple things done. My first thought is to fight and keep fighting until I have overcome the challenge, and that is sometimes just getting out of bed at the end of a demanding week. Then, sometimes, I remember an important practice: “let go, surrender”. When I do that, I feel like this:

Because I wasn’t giving up on life; I was giving up on the life my false self tells me I must live. I felt laughter begin to swell up from somewhere inside of me.

The sense of relief that I feel when I stop fighting to make something happen that probably has no intention happening and just let it all go (yes, I also hear that Frozen song when I write that!) can be profound. How often do we approach a task with an idea about how it has to be completed (or even that the task is the best thing we should do at that time) and then become so frustrated when it doesn’t work out the way we expected.

My usual response is to work harder to complete the task or find other ways to complete it. Letting go or surrendering is a potent practice but you can’t just walk away from every challenge. Most of the time the only direction is forward and in the face of things that terrify you but, like the famous Serenity Prayer, the wisdom lies in figuring out when to keep fighting and when to step back and surrender to the moment.

Take a breather
Take a breather

The better word for it is probably “surrendering” because it involves taking a breath, standing still and opening yourself to something other than the thing that you are fixated on and increasingly frustrated with. Often, when we let go of our insistence that something happen, we open ourselves to other things we didn’t realize were possible, let alone better.

Somehow, doing that, helps us be better humans and more capable of dealing with the next challenge that faces us.

Categories
Events and Life Mindsets

Create a 2015 you will want to remember

2014 has turned out to be a pretty challenging year and not necessarily in a happy way. I was about to say “not in a good way” but you have a choice how to view your challenges in your life. You can see them as curses sent to make you miserable or mountains to climb so you can learn something new; experience something better or just get to the other side.

I’ve had a pretty challenging 2014 and it wasn’t always easy to adopt a positive approach to my challenges but, ultimately, you have to make a choice. Either you tackle those challenges in some way or you let them determine how you will experience your life at that time. I read an inspiring post the other night titled “How to Ruin Your Life (Without Even Noticing That You Are)” which includes this cautionary note:

You ruin your life by letting your past govern it. It is common for certain things in life to happen to you. There will be heartbreak, confusion, days where you feel like you aren’t special or purposeful. There are moments that will stay with you, words that will stick. You cannot let these define you – they were simply moments, they were simply words. If you allow for every negative event in your life to outline how you view yourself, you will view the world around you negatively.

I have no idea what awaits me in 2015. I am certain I will face more challenges and my decisions about those challenges will probably vary. I do know that I will begin 2015 in a very different place (literally and figuratively) and I am very grateful about that. I have my wife and children with me and I am living in an amazing country with so much to offer us. The only choice I really have is to keep moving forward (or, like Dory says, “just keep swimming”) and to make better decisions about my future challenges.

Have a happy new year. Create a 2015 you will want to remember and not a year you will be glad to see the end of.

Categories
Mindsets

Challenging #FML

At first #FML was a rare sighting online and, slowly, it began to find more use as people tweeted about their misfortunes online. The term has its own website featuring everyday uses and it is probably one of the most depressing memes I’ve seen online.

https://twitter.com/clarewarwick/status/537892044753342464

Sure, some people have huge challenges in their lives and have every right to be pessimistic about their lives and yet so many of those people find a way to survive and even thrive because, when faced with the alternatives, they have no choice but to keep climbing that hill.

When I see people tweeting about their lives and hashtagging it #FML, it signals a deep pessimism about their lives even though the things they tweet about are pretty minor in the Grand Scheme of Things.

Is this about more 21st century problems we don’t seem to be able to handle because our expectations of our lives are so skewed? You may say that #FML is just an expression, a sort of grand #Fail but think about it for a moment: #FML doesn’t stand for “Forgot My Lunch” or “Faked My Laugh”. It stands for “F*#ck My Life”. That is a pretty nihilistic take on life, particularly when your challenges are lousy broadband for a couple hours, no soy lattes at your local coffee spot or Facebook going down for 15 minutes when you wanted to procrastinate most. Our words have a power we underestimate. They reframe how we perceive our world and the experiences we choose for ourselves.

Perhaps I’m reading too much into the meme. I’ve been thinking about this for a while and it just seems so destructive, particular when it comes to our thoughts about our life. Maybe #FML is appropriate if your life fundamentally sucks because your family rejects you; you don’t have a safe home; you are destitute or worse. Even then, I am inspired by people whose lives have been constant struggles to survive for a decade or more and yet they are some of the most optimistic people I know.

So you don’t drive an Audi, you don’t live in a fancy house with beautiful furniture and you don’t have the new iPhone 6 with a fast LTE connection so you can stream whatever you want. Heck, Twitter may even go down for 15 minutes and you’ll have to find something more meaningful to occupy those precious minutes.

What if your life doesn’t truly suck. What if you live a life with wonderful people and opportunities you would have thought fantasy a few years ago. What if you are (relatively) healthy and have all your limbs working as they should? What if you have a pretty solid roof over your head and fairly regular meals to sustain you and, in the midst of all of that, you have challenges to face and which, when overcome, leave you somewhat better off because of them?

Perhaps, instead of “F*#ck My Life”, #FML should stand for something else, something like:

Found My Laugh

Categories
Events and Life Mindsets

The only thing complaining achieves

I don’t often come across people who complain a lot and are otherwise upbeat about life and their path through it. Rather, the only thing complaining seems to achieve is reminding you how unhappy you are. Instead, either do something about whatever you are complaining about or change your expectations to suit your circumstances.

Sure, challenges are real (in a sense) and we have to acknowledge them before we can tackle them but just complaining about them doesn’t make them go away. If anything, complaining about something feeds it, magnifies it because we focus so much attention on it that we lose perspective.

This reminds me of that great discussion about fear in After Earth when Cypher Raige, Will Smith’s character, discusses fear with his son:

Fear is not real. The only place that fear can exist is in our thoughts of the future. It is a product of our imagination, causing us to fear things that do not at present and may not ever exist. That is near insanity Kitai. Do not misunderstand me, danger is very real, but fear is a choice. We are all telling ourselves a story and that day mine changed.

Not complaining isn’t easy. I do it far more often than I’d like but, at the same time, it helps to be mindful of when you are complaining, even if you don’t have a more productive way of dealing with the underlying issue. It all begins with that mindfulness because once you have that, you empower yourself to make a real change in your life, however small.

When that mindfulness becomes a habit, all those little changes accumulate and you begin to feel like you may just be steering the course of more and more of your life.

One thing for sure though: complaining doesn’t achieve anything but remind you how unhappy you are, how little influence you allow yourself to have over your life.