1
00:00:00,720 --> 00:00:06,720
As you know by now, Michael Python and see, Python had two different programming languages Micro Python

2
00:00:06,720 --> 00:00:13,020
has copied, Python is faithfully as possible to create a high level language programming experience

3
00:00:13,350 --> 00:00:14,430
for microcontrollers.

4
00:00:15,360 --> 00:00:20,810
There are differences between the two languages, which I would like to summarize in the next few minutes.

5
00:00:23,560 --> 00:00:30,830
Now, the differences between micro python and Python are documented in detail in the Python website.

6
00:00:31,390 --> 00:00:37,720
There you can find a full list of those differences, as well as code examples that demonstrate them.

7
00:00:38,290 --> 00:00:43,600
In this lecture, I will mention only some of those differences that I believe are more relevant for

8
00:00:43,600 --> 00:00:45,340
the purposes of this course.

9
00:00:46,950 --> 00:00:51,090
So let's begin with syntax in Python.

10
00:00:51,210 --> 00:00:58,230
You can do things like forget to put a space between a literal number and a keyword to form an expression,

11
00:00:58,410 --> 00:00:59,610
and they will be OK.

12
00:01:00,690 --> 00:01:04,260
Python has enough flexibility to forgive mistakes like this.

13
00:01:05,010 --> 00:01:06,450
The same mistake in my code.

14
00:01:06,450 --> 00:01:09,540
Python, however, will generate a syntax error.

15
00:01:10,380 --> 00:01:16,590
Mokra Python developers had to throw away the logic needed to deal with tab was like that in order to

16
00:01:16,590 --> 00:01:20,490
make it fit in the limited storage of the target devices.

17
00:01:24,120 --> 00:01:32,480
Another example of the differences between the two languages is how the self Keywood is handled when

18
00:01:32,490 --> 00:01:35,260
self is used in a function in Python.

19
00:01:36,030 --> 00:01:41,550
It does not count it as an additional argument, but Michael Python does.

20
00:01:42,060 --> 00:01:48,810
As a result, if you provide an incorrect number of arguments to a function that contains self Keywood,

21
00:01:49,170 --> 00:01:55,290
then the error message it will get in Python will be different to what you get in micro python.

22
00:01:55,980 --> 00:01:57,360
I've got an example here.

23
00:01:58,250 --> 00:01:59,460
You can see this example.

24
00:01:59,640 --> 00:02:07,530
I'm calling the same function calculator both in Python and Python, and I'm putting a single argument.

25
00:02:07,530 --> 00:02:10,190
I should have passed two arguments, but I made a mistake.

26
00:02:10,190 --> 00:02:16,800
It just a single argument here you can see them and coding the exact same function with this same parameter.

27
00:02:17,160 --> 00:02:21,750
But the messages that are coming back to indicate the error are different.

28
00:02:22,110 --> 00:02:30,030
So, see, Python is telling me that I've got one required argument missing where your python is telling

29
00:02:30,030 --> 00:02:36,540
me that in total that are supposed to be three arguments I've only given to in fact, I've given one.

30
00:02:36,810 --> 00:02:43,440
So you can see that the message that is coming through here in Python is or can be a bit confusing,

31
00:02:44,250 --> 00:02:48,190
which can throw you off and cause you to delay you debarking.

32
00:02:48,790 --> 00:02:54,810
As long as you are aware of the situation with the self key word, I think you'll be able to get past

33
00:02:55,050 --> 00:02:56,100
issues like this.

34
00:02:57,600 --> 00:03:04,650
Here's another subtle difference that has to do with formatting in this particular example of a floating

35
00:03:04,650 --> 00:03:05,640
point number.

36
00:03:06,060 --> 00:03:13,290
When you print out formatted floating point numbers, the result may differ between Python and C Python

37
00:03:13,680 --> 00:03:20,880
here, printing out this floating number and using the same exact commands between you, Python and

38
00:03:20,880 --> 00:03:23,640
C Python, you python being Mokra, Python.

39
00:03:23,790 --> 00:03:27,900
And you can see that what comes out is different in each occasion.

40
00:03:28,500 --> 00:03:34,740
In this case, the G operator, when used with C Python, applies the exponential format to a number

41
00:03:34,740 --> 00:03:35,390
in the output.

42
00:03:35,400 --> 00:03:38,820
The chief operator differs between the two implementations.

43
00:03:39,840 --> 00:03:43,920
OK, next example of differences is the string C.

44
00:03:43,920 --> 00:03:52,020
Python, as you may know, contains powerful string manipulation functions and not all of them are available

45
00:03:52,020 --> 00:03:53,470
on micro python.

46
00:03:54,090 --> 00:04:02,820
Two examples are start with and end with these allow you to check if a string starts or ends with a

47
00:04:02,820 --> 00:04:07,130
specific character or string of characters in Micro Python.

48
00:04:07,170 --> 00:04:14,570
These functions only work in their basic format without the start and end indexed parameters.

49
00:04:15,030 --> 00:04:21,780
In the example here in this slide, you can see that the call to the end with function fails when we

50
00:04:21,780 --> 00:04:27,620
use it with the three parameters, but work with a single parameter in Python.

51
00:04:27,630 --> 00:04:28,290
No problem.

52
00:04:28,440 --> 00:04:31,440
Either one will just work properly and as expected.

53
00:04:33,310 --> 00:04:34,390
All right, next up.

54
00:04:35,300 --> 00:04:43,310
We've got Jason, and this course will use the micropayment Jason module to work with Internet of Things

55
00:04:43,310 --> 00:04:51,770
services, unlike, say, Python and the Python version of the Jason module, you, Jason, does not

56
00:04:51,770 --> 00:04:55,940
throw an exception if an object is not serializable.

57
00:04:56,180 --> 00:05:02,600
And this means that if your program receives a JSON document from a Web service that is not valid,

58
00:05:02,870 --> 00:05:05,210
you will not be able to deal with it gracefully.

59
00:05:05,210 --> 00:05:11,690
Using an exception handler, you will have to deal with this manually or your program will just crash.

60
00:05:13,160 --> 00:05:20,660
All right, so these were just some of this subtle differences between see Python and the micro python

61
00:05:20,660 --> 00:05:23,000
implementation and of course, there are many more.

62
00:05:23,550 --> 00:05:32,570
The best place again, to learn about them and about the changes is the python documentation in the

63
00:05:32,570 --> 00:05:33,300
next lecture.

64
00:05:33,320 --> 00:05:37,210
I'll show you some of the best online resources for Macur Python.

65
00:05:37,340 --> 00:05:43,430
And these are the resources that you'll want to watch so that we can access them anytime that you with

66
00:05:43,440 --> 00:05:43,810
Michael.
