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