I see what you’re saying. I answered your email but this is what I was saying when I said post the code here.
So, at the top I do this:
script, input_encoding, error = sys.argv
That “explodes” your command line arguments into the script level variables:
These variables are now available to READ in the whole script everywhere. You don’t have to pass them to the functions to use them. In the lines where I do this:
I am setting a key=value style of argument to that function. These work like the positional arguments in my last post (add(a,b)) but they are given a name. So, this is like giving an optional setting to the function for how it’s supposed to handle errors. Go check out the docs to see what is available:
I understand errors = error, but the PDF version of the book, as well as the video, has errors = errors. That is the source of my confusion. In my screen capture, lines 17 and 19 that contain errors = error are my attempt at playing with the code and trying to understand it before posting to the forum. My apologies for the confusion.
So, should the code read errors = errors (plural) or errors = error (singular)? If it is the latter, I understand.
am gonna answer what i understand from the ex23
look remember in last time when we said that when we define a function , the arguments we enter are just place holders for the real arguments (aka parameters ,place holders) ok you don’t then look at this ex:
#know am gonna call the function(aka run it , use it)
talking(me, him) #this will print : me talking to him #calling it again with deffernt parameters(aka arguments ,informaly place holders)
tlking(Roky, Morty) #this will print : Roky talking to Morty
Notice : that the parameters in the function defintion only hold the places or define the arguments in the code only and has nothing to do with calling it .
Now lets tallk about the ex23:
start reading from the line before the end there we define languges , then we give it to main function as the first argument and we place 2 new place holders in the second and 3er argument of main . main is defined to take the second and third argument from argv so it will do . now when we call the main function at the last line of the code it will start runing from the first line after its definiton and it will not use the place holders of its defintion but it will use the new place holders(aka parameters,arguments) we give it when we call it at the end of the code so it uses them now not the the once in the definiton. that is why we use encoding .
about the …=sys.argv is just like saying from sys that you impoted get argv and set it to those variables in the lefet of the equal (=) . and it works like that and you can use it no since about it just remember it it is mentiond in the 3 editon that it cantake up to 5 arguments if i still remeber it right.
about the errors = errors and encoding = utf-8 , i don’t know , but try to take one errors and = and see what will happen and take the encoding and leave the utf-8 and chk what happens. if not understood then check the open function usage in python 3 ,or jow to use function(argument , argument2=argument3) in paython 3
put any funtcion and arguments instaid of there names i have writed and check them online . and let me know about them here please as i have never incounter them in python2
if you still have any dbouts about what i wrote above please aske more i will then explain more untill i make my ideas clear to be understood .
@bestever. I appreciate your response. Thank you! @zedshaw provided a detailed explanation as well, so I have a much better understanding than when I generated my original post. Now, if I could just figure this 3rd study drill out, I will be cooking with gas! @zedshaw expected this to take a week, and he sure wasn’t lying.
I may move on and come back to this when I have better knowledge. However, I don’t want to go far without understanding this exercise completely.
sometimes you just need to ignore some parts of the exercise and but after reading it and try to understand it , and then pass to the next exercise . after a few exercises if you understand them well just continue to finish the book but if you find some problem that you couldn’t solve and you remember that the book solve it with a way that you did not understand and you passed it ,then comeback to it and once you will ready it again you will understand it this time (understanding something is just to know when and how to use this thing and nothing more )
Definitely don’t think you have to do every exercise completey before continuing on. It’s more that you do what you can, move on and do a few more exercises, and then previous study drills make more sense.