Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 6: LOLCat Factory
Lecture: LOLCat App on Linux
0:00 Here we are in Ubuntu,
0:02 let's try to call open and pass the folder and see what happens.
0:05 Couldn't get a file descriptor referring to the console,
0:11 that's not a super user experience,
0:13 so what are we going to do. Well, like I said,
0:16 we need to run a different open command on Linux,
0:19 different one on OS X and a different one on Windows,
0:21 now there are variety ways to determine what basic platform you are working on
0:26 we could go and import the OS module and say OS.name
0:30 and it will say pause x for Linux, and nt for Windows,
0:34 but it doesn't distinguish between OS X and Linux.
0:38 So we need another way which we can get with this platform module
0:41 so we can say if platform.system
0:45 now platform is another module we have to import so again
0:49 we'll let PyCharm do that.
0:51 You have to kind of experiment with it to see what it returns
0:54 but on OS X it returns Darwin, on Linux it returns Linux
0:58 and on Windows it returns Windows,
1:00 so that should be pretty easy,
1:02 let's say Darwin if it's Darwin we are going to do what
1:05 we have already been doing, that was great,
1:07 otherwise, we want to come here and say elif it returns Windows
1:13 we'll say start and elif if it returns Linux we'll say xdg-open
1:21 and finally we'll do an else and say print we don't support your OS.
1:28 And we could even show it to you.
1:32 Like so, now I suppose spelling Darwin correctly would help, wouldn't it?
1:36 Ok, so OS X, Darwin, Windows Windows, Linux Linux, let's try it.
1:43 Excellent, here are our cats let's have a look,
1:47 I are dune cat, I control the spice, kkkkkkkkk cat and so on
1:51 now notice one of these is actually off,
1:53 I know that one of these images actually is a gif not a jpg
1:56 and apparently this little viewer doesn't understand that
1:59 from the metadata in the header it just looks at that extension, whatever
2:03 that's not really a big problem
2:05 we'd have to check what the file extension is when we save it.
2:08 So pretty cool, we were able to use platform.sys
2:10 to determine what sub-process to call.