Thursday, 22 March 2018

Toy Examples: How os.walk Works

One of the many things a programmer needs to do is walk a directory tree and do stuff to the files and folders in it, even if it’s just list them. This is a recursive exercise and those can be mind-bending to code, and if done badly can mess up all sorts of low-level things. It’s best left to the kind of people who have actually read Knuth. Fortunately someone on the Python project did, and they gave us os.walk. (It’s in the os module, and is called walk().)

Unfortunately, the almost identical explanations of how to use os.walk mostly miss the point. All of them - that I’ve found - print out a directory and file listing. Which is not what I wanted to do with it.

When you execute os.walk(starting_point), for a directory called ‘starting_point’, it returns a triple consisting of: the path for starting_point a list of the subdirectories of starting_point a list of the files in starting_point.

os.walk works in a loop. Outside a loop, it doesn’t do much. Here’s how to use it in Python:

for current_directory, subdirectories, files in os.walk(starting_point): (do stuff)

What happens? The first time execution hits os.walk, it returns a triple like this:

current_directory = starting_point
subdirectories .... of starting_point
files ... in starting point

If you want to do something to all the files in the starting_point directory, you loop like this

for file in files: do stuff to file

If you want to do something to the subdirectories, unless it’s to list them, don’t. Wait for a moment, because...

The second time execution hits os.walk, it steps one directory down the tree, like this:

current_directory = first_subdirectory_in_starting_point
subdirectories .... of first_subdirectory_in_starting_point
files ... in first_subdirectory_in_starting_point

Now you can ‘do stuff to file’ for the files in first_subdirectory_in_starting_point.

What happens if there’s a subdirectory in first_subdirectory? The next time os.walk is executed it will return

current_directory = first_subdirectory_of_first_subdirectory_in_starting_point
subdirectories .... of first_subdirectory_of_first_subdirectory_in_starting_point
files ... in first_subdirectory_of_first_subdirectory_in_starting_point

Why don’t you do anything to the directories? Because os.walk is using that list to walk through them, so if you change names or permissions or something, before you have walked to the directory, os.walk (probably) won’t work.

If you want to mess with the subdirectories themselves, the chances are you need to run os_walk in the reverse direction (look that up).

The toy example of a directory listing just doesn’t expose the inner workings clearly enough. It can leave you thinking you have to do stuff with the directories as well as the files, but you don’t, of course.

Someone who has worked a lot with recursive Python functions will, should they have got all that experience before needing os.walk, grok os.walk fairly quickly. They will read the description and look at the examples and match that against the way they know Python array-returning programs have worked in the past, and say after a moment ‘Oh, sure, it does this and that, and you always have to use it in a loop’.

Catch is, walking a directory tree is one of the first things a programmer wants to do. And grokking recursive-return functions like os.walk is not simple. Being able to picture a recursive process is one of those big-jump differences between code-bashers and actual programmers. A toy example isn’t going to cut it.

Monday, 19 March 2018

February 2018 Review

February is dance month. I saw Pina Bausch’s Viktor, Maria Pages’ Yo Carmen, and Jesus Carmona’s Impetus. Mother loved Carmona, Sis liked Pages, and I thought Viktor was wonderfully and sometimes disturbingly surreal. Each time I had lunch at Santore. My judgement: go for the pizzas.

February is also MoT month. I have used the same local garage, Mullen Speed Test, for a long long time. This time I needed new front tyres.

Mostly I went to work, went to the gym or went home, crawled into bed by 20:45 at the latest and slept.

I finished reading the first volume of Hegel’s Aesthetics, read Neil Gaiman’s American Gods and Nick Garlick’s Storm Horse. Gaiman has sold enough, so I’m going to commend Storm Horse to you. Don’t be put off by it looking like a children’s novel. It isn’t: it’s a sparely told story about a young boy, and that spareness gives it a bracing, adult feel. I was so absorbed I did not notice the commute on the train.

Towards the end of the month, I quit treating myself after the gym to make up for the crappy Christmas I’d had. No more breakfast deals at Paul, and no more sandwich and tea from Pret at elevenses. That was all costing a lot of money. And it was keeping my weight a little heavier than I would like. The real progress got made in March, so you’ll have to wait for that bit.

I finished series two of House and started on series 3. No movies. Too damn cold.

Monday, 12 March 2018

It Seems We Don't Touch Enough. I Wonder Why?

There was a recent article by Paula Cocozza in the Guardian called No hugging: are we living through a crisis of touch?

Oh man.
In countless ways social touch is being nudged from our lives. In the UK, doctors were warned last month to avoid comforting patients with hugs lest they provoke legal action, and a government report found that foster carers were frightened to hug children in their care for the same reason. In the US the girl scouts caused a furore last December when it admonished parents for telling their daughters to hug relatives because “she doesn’t owe anyone a hug”. Teachers hesitate to touch pupils. And in the UK, in a loneliness epidemic, half a million older people go at least five days a week without seeing or touching a soul.
Half a million people cannot be an epidemic is a widespread infectious disease. If it’s confined to older people it can’t be widespread. And loneliness isn’t infectious. Sloppy writing and using mainstream media tropes is, however, infectious, and Paula Cocozza has caught it bad. Start her on David Hume’s Treatise on Human Understanding stat.

Doctors were were recently advised by the Medical Defence Union, which provides legal advice to doctors, to 'err on the side of caution' regarding physical contact with patients. Which is what an organisation dedicated to litigation defence would and should say. Since foster children actually belong to the local Council, not the foster parents, I can imagine some Councils advising against touching foster children for the same reason: 'err on the side of caution'. Teachers work in permanent fear of being sacked and replaced by someone younger and cheaper, or of displeasing the all-powerful Head Teacher, and any flimsy allegation will do. That’s been going on since at least the 1990’s. I have a lot of sympathy for the American Girl Guides saying “She doesn’t owe anyone a hug”. To awkward and insecure teenagers, old people can be smelly, feel odd, and generally be icky. I feel much the same way about almost all of the human race.

So this is two issues: one about the legal hazards of dealing with people in these crazy times, and another about the fact that many people find many other people icky and don't want to touch them. Ms Cocozza actually quotes someone saying as much:
“Of course we are moving away from touch!” exclaims Francis McGlone, a professor in neuroscience at Liverpool John Moores university and a leader in the field of affective touch. He is worried. “We have demonised touch to a level at which it sparks off hysterical responses, it sparks off legislative processes, and this lack of touch is not good for mental health.” He has heard of teachers asking children to stick on a plaster themselves, rather than touch them and risk a complaint. “We seem to have been creating a touch-averse world,” he says. “It’s time to recover the social power of touch.”
Does Ms Cocozza's suggest we deal with the cynical misandry masquerading as 'feminism' which is the source of all this, and with the legal profession that enables it, and the click-seeking media which gives it all publicity. Nope. This is the Guardian: misandry is not the problem, but men: after all, no men, no misandry. The answer is to bring on the private sector and the science. The science is essential. It proves that touch is just a drug like, oh, Prozac, and therefore that hugs and touches can and should be transactional within a managed environment. One of those businesses describing itself as providing...
a structured event which explores affection, intimacy, boundaries and verbal/non-verbal communication… strictly non-sexual so that you can relax and meet new people in a fun and warm-hearted environment...You'll have the opportunity to rediscover nurturing touch and affection, let go of hidden agendas, gently explore any challenges around touch and gain tools for more satisfactory touch in your life”,
(No link. This is a blog, not a billboard.)

Sadly, that doesn't "recover the social power of touch", but on the contrary privatises it. I don't think that's what the good Professor McGlone had in mind.

One point slips by in the article like a thief in the night. “Even stranger touch, when it’s wanted, is pretty good,” Linden points out.” When it’s wanted. There’s everything right about the condition, and everything wrong with the reality in which that condition applies. Because the reality is that the number of people whom we want to touch is almost zero. A random man who isn’t one of the hot 1% can safely bet that the next woman he passes will not under any circumstances want him to touch her. This applies even if she’s his wife and double if they’ve been married for more than three years. Equally, a random woman can safely assume that the next man she passes will be repulsed by her touch, unless she’s one of 2% of women who have the looks or personality to make it a pleasure.

It gets worse. Just because you had touching rights yesterday, doesn't mean you do today. If you have to ask if you do, you fail the confidence test. If you assume you do, but you aren't wanted today, well, then, you're now her bitch, because she can use this against you at any time over the next forty years. Just ask Garrison Keillor.

How the heck did we get here?

Well, cynical misandry, an enabling legal profession, and click-seeking media is part of the answer.

Another part is that the majority of the human race is just gross and icky and should keep its hands to itself. Men who are not confident, exciting, good-looking or wealthy (pick 'confidence' and one other) should keep their hands to themselves. I'm serious. Women don't want them, but they might settle for them. I'm also serious when I say that women who aren't feminine, charming, and under an old-money size 12 should pretty much keep their hands to themselves as well. Those women have known forever that men are prepared to settle for them, but who wants to be settled for? Nobody wants to settle for who their touch comes from. That touch has to be wanted.

Also, significance is inversely proportional to frequency. The fewer touches we get, the more significant each one is. A woman who is down to one slight touch a week is going to be fairly irate if her weekly ration is an accident from some featureless dork. Better nothing than that. If she's getting some hot guy tingly-touches every week, then the odd featureless dork is bearable.

Then there's the fact that touch is not an unadulterated good. It can be and is routinely used to deceive, manipulate, placate, distract, mislead and seduce. That's why children wriggle away from Mommy's cuddle when they are cross and want to stay cross: they don't want Mommy hug-drugging them into a stupor. That’s why women who have stopped caring, don’t want to hug their partner: they don’t want to be made to feel good about him by some cheap hormonal circus trick. It's why you should be very suspicious when anyone puts their arm around you: they are probably setting you up for something. It's why PUAs talk about 'kino'. One of the 243 reasons women have sex is to manage their partner, to keep the poor dolt reasonably happy. Adult-on-adult touch is all about the agenda. That's because adult life is all about the agenda.

Set aside the hormonal natural highs, and what am I supposed to do with a hug? When it’s over, I’m still in the same bad position that made someone think a hug might be in order. I don’t need hugs-'n-drugs, I need actual help. In other words, a suspiciously large proportion of touch may not be given for the benefit of the receiver, but for the benefit of the giver. They hug the suffering-us so that they will feel better about us feeling bad. It’s like tossing a coin into the charity bucket and having the coin bounce right back. The doctors weren't touching you reassuringly so you would feel better: they were touching you so you wouldn't get emotional or make a scene. And actually, both of those can be true at the same time.

Capitalist, managed hugs might have no past and no future, like a visit to a hooker in a foreign town, but a genuine hug is not in the singular: it’s one of many in the past and in the future. Real hugs are part of a relationship. The hug is a symbol, and the reality is the relationship that hug confirms still exists now, and so opens the possibility that it may exist tomorrow. When the hugs, the sex, the touches, stop today, the relationship is dead tomorrow. It's what the touch means that matters: the drugs are just a boost.

It’s not the lack of touch from his wife and children that is bad for a husband and father. It’s what that lack of touch means: that his wife hasn’t been attracted to him for years and his children don’t find him a source of strength and assurance.

It’s not the lack of touch in our lives that is bad for us. It’s that we don’t know or even see anyone whose touch we want. It’s being surrounded by people whose physical presence is bearable only if they don’t come into contact with us. If they stay quiet, shower frequently, don’t eat smelly food, or stink of drink or drugs. Day after day, month after month, with no object of desire in sight.

That's not a crisis. That's the human condition.

So maybe you civilians should pay for the hugs-'n-drugs. I’m at disadvantage: the injunction to avoid ‘mood-altering chemicals’ includes hormones. Sunshine is okay. Also chocolate. Random blasts of some chemical with a Greek name and a complicated structure whose operation is not well understood are discouraged.

Friday, 9 March 2018

This Post Delayed By Something I Ate or Drank

I felt hyper on Thursday and not in a good way. My feelings were all over the place, but none of them wanted to walk in the sunshine. Once I recognised it, it felt like I had had an accidental encounter with something alcoholic. The grapes with my morning yoghurt? Was that a wine vinegar with the rocket at lunchtime? I don't know, but it took twenty-four hours and two bars of chocolate to clear. I feel okay now. TSIR - This Shit Is Real.

Monday, 5 March 2018

Why You Should Replace Your ISP's Modem-Router

Last year I had a long-running problem with Talk-Talk, who could not find out why my broadband speeds had been so slow. They were in fact in breach of the contract, that’s how slow it was, but I wasn’t hammering the bandwidth at the time, so didn’t notice. I had a Bright Sparks engineer visit, I had BT replace the copper into the house from the distribution pole. Still nothing. So I retired the modem they had sent me a few years ago, and used the modem in the Netgear D6400 I was using as a router. It has wireless-AC and Talk-Talk’s router only had wireless-N.

Hey presto! Instant speed and reliability increase. The problem must have been with the Talk-Talk router: one of those faults that hides in the shadows when an engineer pokes around with a stick. That lasted for about 120 days, and then the connection started to go. I could watch the Netgear sign on, and see the downstream signal/noise sink down, go below zero and drop the connection. By now, I had learned not to call the helplines, who start talking about freaking micro-filters, and diagnosed a faulty modem chip: the rest of the router was just fine.

So I swapped in the Huawei modem-router Talk-Talk had finally managed to send me while they were not finding out what was wrong with my connection. I turned off the wireless and hooked it into the Netgear. Line reliability restored, with a speed of 4600 mbps. Um yeah. Let’s see if it improves after a week or so.


So after having read many reviews about the Billion routers, I bought an 8800NL R2. £55 plus change from Amazon, with delivery via Doodle. It needs to be connected to a computer via LAN cable to be configured at start-up, but otherwise, plug it into the ADSL socket, hook it up to the Netgear. Take a look at the line speed.

8190 mbps.

Out of the box.

Boom. For real.

It’s currently at 9120 mbs. Never had that before.

This proves what I’ve often suspected. It’s in the ISP’s interests to send you something half-way reliable with speeds towards the lower end of what they promise. That way it naturally restricts the amount of their network bandwidth you can take. If it drops out fairly frequently, that’s a plus as well because they can always restrict your line speed even more while they "test for quality of connection". Oddly, you’ll never go above about half of their quoted maximum.

There are reasons Talk-Talk is cheap. A call centre in Guam is one of them. Second-rate Huawei modem-routers is another.

You can’t do anything about the call centre. You can buy a decent modem.

(Caveat: the Billion has wireless-N. That didn’t matter because I use the Netgear as a router. If you need wireless-AC, you will need a different model.)

Thursday, 1 March 2018

Being Your Own Mental Point of Origin

“Be your own mental point of origin” is one of those phrases that for a long time I never really understood. Something about it kept slipping through my fingers.

Recently I saw a video called 15 Sacrifices You Need To Make If You Want To Be Rich

Alux can have some silly videos, but this is a good one, though you need to get past the Alux Lady’s voice and listen to what she is saying. It comes down to this: if you want to be rich, it’s going to take a lot of work over many years, and that work is not going to leave you a lot of time to give a wife and children the attention they deserve, or to hang out with loser friends, go for junk entertainment, and dozen other time-wasters, and even maybe for your health and sleep. You’re going to need to defer some of those things, such as family, and just plain drop others until you’ve achieved your goal or made an honest effort and failed.

This applies to a lot more than making a lot of money. It applies to training and competing for an Olympic medal; acquiring the skills and connections needed to establish yourself as an artist, writer, photographer or other creative; establishing oneself in a profession, trade or industry; or even working up from an entry-level job to one that pays enough to let live in your own place and save some money.

Now imagine someone leaving university and pursuing whatever demanding goal it was for ten years or so. Maybe they succeeded, maybe they didn’t. Either way, they know what it is to have an absorbing, sometimes frustrating but sometimes satisfying life that has nothing to do with women and children. If they were successful, they will place a high value on that. The idea that ‘all this success is just meaningless’ is a social cliche, not an emotional reality: the meaning isn’t in the reward, it’s in the competition. So they will still place a high value on the process, even if the results were disappointing. The idea that failed strivers reject all the behaviours they learned as ‘empty and meaningless’ is a cliche for losers. Nobody who has spent ten years filtering out junk, drama and losers is going to embrace any of it. They have turned into a person with self-discipline and self-respect, and those are things nobody trades.

So a lot of those temporary sacrifices are going to be permanent, but won’t be sacrifices, not to someone who has succeeded or put in an honest effort at achieving their goals. Because doing that changes the kind of person you were.

You can see where this is going. A man pursuing a goal over an extended period is going to look a lot like a MGTOW-with-short-term-relationships. If he doesn’t blow it by turning Beta when he makes his goal, he will be a de facto MGTOW-with-short-term-relationships for life. Not because he isn’t ‘Alpha enough’ to handle long-term relationships, but because he has evolved an idea of value in which the cost of LTR’s is not worth the benefit.

Anything that looks like MGTOW brand is anathema those Men’s Writers whose audience is men who want to know how to manage long-term relationships with women. That audience does not want to be told to get themselves a demanding goal. It wants to be told how to bump along with what it has, but with less pain per bump. It wants long-term relationships with women, because those are a substitute for demanding goals. (Though if they have a family and try to raise two decent kids, well, that’s a demanding goal. Such a pity most parents don’t treat it like one.) What those men want to hear is that they should not be the servants and ATMs of their wife and children. What they need to know is how to work that trick: how to have a life of their own, but no too much of a life that might cause them to look at their marriage and wonder what exactly they are getting from it that’s so much better than what they can get from their own devices? And don’t nudge and wink and talk about sex, or no-one will take you seriously.

Having-a-life-but-not-too-much-of-a-life is what’s meant by “being your own mental point of origin”. Because if you have a demanding goal, that goal is your mental point of origin, not yourself. Until you decide to change it.