Python misadventures - how no () made me :(
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!)
The actual code (everything else the same) that finally worked
Upsides are that I've learnt the following:
- If I get a 'something undefined' error message in the future, I'll be sure to double check my bracket structure.
- 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.
- Maybe I need to get over my old school 'type and think' style of learning and just cut and paste more in general?
- 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!
- 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!
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!
In more recent versions of python you don't actually need the () in a class.
Posted using Partiko Android
It's a minefield, I wonder why it's needed here then?!?
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
Phew! It's a learning curve! Good to know all of this early on!
Posted using Partiko Android
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!
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!
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.
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!
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.
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.
And @steevc - I’ll count myself lucky I’m learning in 2019!
Oh that sounds like such a joyful experience!
I think this was just due to publication deadlines, maybe?
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.
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!
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
I can laugh about it now... I know it goes with the territory!
Posted using Partiko Android
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:
Feel free to join our @steem-ua Discord server
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.
Congratulations @revisesociology! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
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:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!