Python misadventures - how no () made me :(

avatar
(Edited)

It turns out that the simple Python program I was trying to get running wouldn't run because of a typo in the text book I'm using: Python Crash Course (well it certainly crashed this week).

I'd jumped ahead to the chapter on Data visualization using Matplotlib and Plotly, and was getting along just fine coding a simple random die rolling and result plotting program, and everything was going well until I hit 'classes' (which I'd skipped from an earlier chapter) when I had to abruptly learn the 'writing a little program and saving it in the same directory and then calling it from another program thing' - all completely new to me, as was/ still is 'importing' various libraries.

Anyway, I had my initial 'die' program saved, and it seemed to be being called OK by the next 'viz' program I'd basically copied out of the text book, but every time I ran it, it just kept coming up with a 'variable not defined' error, and I had no idea what that meant.

I mean with my basically hacking together an understanding it could have been something not being downloaded properly, my not knowing what the difference between a terminal or a console or a notebook is in Anaconda (which I'm using as a programming environment but not at all familiar with), it could have been a typo, but I'd quadruple checked the code in the text book: bang on, and got someone else to check it too!

So why didn't it work?

A fucking typo in the text book

You fucking what?

A fucking typo in the fucking text book

And I don't mean the kind of typo that's down to some code being updated since with a Python upgrade, I mean the type of typo that missed out '()' at the end of a line of code, rendering the whole program unworkable.

The kind of thing an experienced programmer would have picked up on immediately, but a newbie, like me, like the kind of person this fucking text book is written for isn't going to pick up on.

Spot the difference:

From the text book (what I'd typed out and what wouldn't work!)
1.jpg

The actual code (everything else the same) that finally worked

2.jpg

Upsides are that I've learnt the following:

  1. If I get a 'something undefined' error message in the future, I'll be sure to double check my bracket structure.
  2. I'll just pull everything from Github from now on - the code was correct there, hence why it now works, and hence why I was able to make this comparison. Hence why I'm not too upset about the text book being wrong - it's pretty poor though TBH.
  3. Maybe I need to get over my old school 'type and think' style of learning and just cut and paste more in general?
  4. I think I need to learn to let things go a bit - I ended Sunday on something of a high as most things had 'worked' for me - Monday was a completely different story, I was up until 22.30 (that's VERY late for me) trying to puzzle out why that code wouldn't work (I just hadn't assumed it would literally be a typo in the text book) and getting no where, that was very shit!
  5. I'd better get used to being frustrated, I KNOW there is A LOT more like this to come!

At least I'm back on track now....

On a happy note, at least I've got my histogram of my die roll, and in html. I think I understand all of what's going on here with the code too, at least at some level!

Capture.JPG

Now all I need to do is to stop interrupting myself every 30 minutes to document my stilted coding progress and I might actually be able to code something actually vaguely useful by the end of the year, or at least by Spring 2020!

P.S. Big thanks to @samuel-swinton who gave me some help with this and confirmed I wasn't going nuts!



0
0
0.000
19 comments
avatar

In more recent versions of python you don't actually need the () in a class.

Posted using Partiko Android

0
0
0.000
avatar

It's a minefield, I wonder why it's needed here then?!?

0
0
0.000
avatar

Maybe the visualization tool is using an older version. Versioning is definitely a struggle in python. At work, we run our code in virtual environments and all packages we import are version controlled.

Posted using Partiko Android

0
0
0.000
avatar

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

0
0
0.000
avatar

Haha, best way to learn. Maybe the guys who did the listings were part of the BBC Micro / ZX Spectrum team who did the listings for CV&G.

If you don't know what I'm talking about.. well, the old mags from the early 80's always had game listings in them, and they rarely worked due to bugs.

I think they were intentionally put there to piss us off, but had the side effect of making their readers programmers and debuggers.

@steevc will know exactly what I'm talking about!

0
0
0.000
avatar

Oh I know about that. The listings were all specific to different computers and it was really hard to convert them, especially if they had graphics. I used to buy several magazines each month, but we had no on-line stuff to read then.

0
0
0.000
avatar

They used to say, 'bugs will be fixed in the next issue'.

When the next issue came we had either lost interest or fixed em ourselves!

0
0
0.000
avatar

I've seen a few on-line tutorials where they get corrections via the comments. Some actually write the article in Jupyter so it is all code they have had to run.

I remember C&VG had a Spectrum game that was all in machine code and it was just pages of hex! Practically impossible to type all that in without mistakes and it's not like you could learn anything from it.

0
0
0.000
avatar

I remember C&VG had a Spectrum game that was all in machine code and it was just pages of hex!

LOL, can't remember that one. One mnemonic wrong and it's crash time! Some of the newbies didn't save before they ran the code.. oops.

0
0
0.000
avatar

Oh that sounds like such a joyful experience!

I think this was just due to publication deadlines, maybe?

0
0
0.000
avatar

It's a learning experience. Typing in listings is okay, but it's best to understand what it all means. Of course you need to figure out what the error messages mean. There are tutorials just about that.

0
0
0.000
avatar

It’s a slow old process when all I’ve got is evenings and weekends, but I’m getting there I think!

Filtering the best learning resources is also a challenge!

0
0
0.000
avatar

Man! I bet a lot of precious time was wasted by your checking a gazillion times over stupid brackets. I don't know Python but I do know JavaScript and every little detail counts when coming to scripts. You oughta write a note to the author of the book about this "typo". Well, I'm glad you're on track now. What a hurdle that was!!

Posted using Partiko Android

0
0
0.000
avatar

Hi @revisesociology!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 4.804 which ranks you at #1452 across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 93 contributions, your post is ranked at #18.

Evaluation of your UA score:
  • Some people are already following you, keep going!
  • The readers like your work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

0
0
0.000
avatar

Hi, @revisesociology!

You just got a 1.56% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

0
0
0.000
avatar

Congratulations @revisesociology! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You distributed more than 43000 upvotes. Your next target is to reach 44000 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

The new SteemFest⁴ badge is ready
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
0
0
0.000