 that even that is too much okay yeah so hi everyone my name is Martin I'm running a work development agency in Singapore called Bitmask and well today as the final talk today I want to just give some very quick and easy super fast tips for Python beginners so I guess most of you will probably know all of this but I know that we have some beginners here today so this might be helpful for some of them okay tip number one is use virtual so maybe a quick show of hands who is using virtual and okay so that is probably 90% pretty good yeah I believe for newcomers this is the very first thing I do should probably teach yourself and it's not very difficult anyways so why should you use it it's to avoid the thing that we call dependency health so imagine you have two projects one project you need Django 1.5 the other project needs Django 1.6 and then in the morning you start working on the first project and the afternoon you want to switch to the other one and you would always have to pip install the old Django pip install the new Django and you would have to do it all the time waste time waste bandwidth waste this space so that's not a good solution virtual amp will help you to create isolated environments so as I said you can that is basically a result of avoiding dependency health now you have buckets of environments and they don't interfere with each other so they are isolated it also means that you won't pollute your global environment so I don't really know if this is really an issue but every time I do Sunoo pip install something I'm kind of scared what of my operating system is actually using requests version one point whatever and now I'm installing an older version for some reason am I breaking my operating system right now so maybe polluting your global environment might not be the best idea as well and you also it helps you to create reproducible environments so usually you will have this so-called requirements dot text file and with a tool like pip or easy install you can just say pip install everything that's in this requirements text and there's like 50 different packages in them and then you go and grab a tea and you come back five minutes later and everything has been installed so it's pretty good if you have a bigger team and you need everyone to be on the same page working on the same project so how do you use this you just run pip install virtual and you go into any project folder where you want to start working on your project and then you call this new command virtual and and you give it a name usually we would use the end and this will install a new folder called the end which contains its own Python library and whenever you run when you activate this environment which we will do with source the end been activate your shell will get will have some new environment variables and the path to the Python very Python executable will be changed to the one that is in this Vm folder here so when you run which Python your terminal it will no longer go to use a local Python or wherever it's installed it will go to projects my project the end been Python and then when you run pip install it will no longer end up in whatever is your global folder will end up in this Vm folder so that means all the crap that you have installed during this project you can easily delete it you can just delete the Vm folder and you can reinstall everything again start from scratch if you mess it up somehow and by typing deactivate you will stop using this virtual environment and you will go back to your global environment so yeah as I just said it creates a folder Vm what you can call it you can give it any name uses its own Python executable it installs packages only into that folder and by the way if you're running a virtual control system like it you should not add this folder to your repository because when you have many developers they might have different operating systems and they might compile the Python packages differently so you don't want to commit this into your repository that's everybody's own business to install the packages into this into their own virtual environments right so this is not not something that is shared with the team everybody sets this up on their own computer and yeah there's the link where you can use it so maybe a very quick demonstration so when I go to my project folder and I start a new folder and then I say virtual and Vm and now I have this Vm folder here and inside of the Vm folder there's a bin folder which has the Python executable and deactivate script so now I can use source Vm bin activate and usually you can see that your prompt changes and it tells you now you are basically running a virtual environment and now when I do like in so requests for example yeah okay I'm not online why is that I'm running my own spot okay never mind so yeah so it would it would be installed into the Vm lip Python site packages and then you would find all the things that you have installed in this folder so if you want to browse the code and one dive into the into the things that you are using you can actually have a look at it very easily okay so that's the first tip second tip is building on that so if you are using virtual and already you should also use virtual and wrapper raise of hands who knows about virtual and wrapper okay so that's like only maybe 30% and I would have expected that most people somehow don't use it I don't know why this is really awesome you will no longer have your VMs in that folder where you are currently working you will you will have a environment variable called work on home and a virtual and wrapper will help you to just install all your virtual environments into that single folder right which makes it is I find it easier that I know where are all my virtual environments where on my computer are they if I want to go into one of them want to delete them want to mess around with them I have one central folder I just go into that folder and I know where I am and you don't have to remember the past to this activate script like source projects my project been activated it's confusing so virtual and wrapper basically gives you one commands called work on and you say work on project one and boom the virtual environment was the name project one will be activated no matter where you are in your channel right now and so with yeah with zsh it has plug-in and I think with bash there's also way to set up auto completion for this so when you are like me and you have tons of virtual environments it's super easy to activate them by installing this is also pretty easy as usual pet install virtual and wrapper then you need to put a few for few lines into your bash profile or if you are using this I'm putting it into this HRC or you can put into bash RC any file that is executed when you start a new shell right so you would use these new and new environment variables here this is the most important one work on home and then when you have done that you can use this new command called MK virtual and so you don't have to use virtual and because virtual and creates a new virtual environment in the folder where you are right now right and pay virtual and creates a new virtual and in this folder work on home which is your central folder for your virtual environments and then you can activate it with work on and deactivated with deactivate as usual so when I run work on and have a press double tap I see all my virtual environments and if I activate one of them you can see that it has been activated and I don't have it doesn't matter in which folder I am right so I'm just going to my home folder and I can say work on this this one for example and that is activated so then I have this central folder here where all these virtual environments are together yeah go to the folder you don't know it you stay in the same folder so no matter where you're working currently you can work on you can just activate this environment and from then on this other Icelandic Python executable will be used but if you want to go to the floor yes you should you can see this one I can I think I'm not sure if this works why not I have done it for a long time I think you can put a dot file VN visit dot VN yeah that worked so when there is a dot VN file which has a name of one of your virtual environments and you CD into that folder the environment will automatically be started so you don't even have to type work on anymore I think this is a feature of the end but there's also the I'm in a different directory and I want to go to the directory of my project right there's the CD project oh yeah there's something like that and that's also there's also removed virtual and so you can delete them without having to go into your central folder and it's the CEO there's CD virtual and so if we want to have a look at that it's interesting it doesn't have a complete it doesn't seem to work I have never used it before it doesn't work you just if you just see virtual and it goes into the virtual that you're currently oh yeah oh the current activity that was when he said the CD virtual and building was friendly going to build these types of building which doesn't get I see okay that's pretty cool all right so sorry okay so because you use these tools all the time in every virtual and then okay okay I never use that because I always have a requirements text file anyways which I need to run when I start a new virtual and so I don't need hooks okay last tip lint your code Python already has this awesome pep8 coding conventions brought to us by our benevolent dictator uniform rossum and many more people probably and I think this is the one of the great things about the Python ecosystem you can look at anybody's code and it just looks familiar because most of the people are following the pep8 coding conventions so you don't have to waste time in your own company your own team to set up a central document where you decide how the code should look like it has already been decided for you and it will also find some nasty syntax errors for you and it keeps your code beautiful so there's a there's a tool that helps you sticking to beautiful code and it's called flake 8 so you would run it install flake 8 and then you can run this command flake 8 on the current folder and then it will look into all Python files and see if they are compliant with the pep8 conventions so let's try that so let's say I have a file here which has pretty bad code we will import star which you should never do and then we we will have a super long line and then we have some white space here and some white space here for example so that's pretty ugly and when I run flake 8 it finds this file and it finds the lines okay sorry sorry like this so it finds this file that code and tells me exactly on which line which syntax error has been found usually they are already very easy to understand so you don't have to go to some other documentation to find out what is this error all about so it's telling me oh I have invalid syntax why do I have any valid syntax okay what I actually wanted to do was this so now I'm flake 8 and it says I'm using star imports and this makes it very difficult for my IDE to figure out which which modules are imported right now like which which classes are available in this file because I don't know what's behind star right so I should be more precise about what I'm actually what I actually want to use so we will change that to this and then when I run it again it says decimal has been imported but it's never being used this is one of the most the one that I like the most because when your projects grow you tend to import all kinds of stuff you mess around and then you get to a final solution which is so easy and all the stuff that you have imported before is no longer being used so flake 8 makes it very easy and tells us that we are not using it at all so let's remove it right and then it's saying there's a line which is too long so with strings we can use something like this it's still too long it's here so we put it here and then we have a blank line at the end of the file finally it will not find any hours and we are good to commit our beautiful code yes okay sure yeah that's what I want to say last most editors have flake 8 plugins so for supply I guess you have one for eclipse probably as well and even for my ugly little vim when I press when I press F7 it leaves the file for me and says flake 8 is okay so let's introduce an error again and now it tells me line too long in this small window here when I the cursor jumps here immediately when I press enter it jumps back to the line that is wrong so when you have a file with lots and lots of errors you can just step through those press enter and you will jump to the error and you can fix them super fast yeah we did that as well in the beginning we were using two or three different ones but in the end we settled on flake 8 the latest version I think they have it covers everything and it has the best error outputs and I think there's even a way to exclude some of the errors if you say in my project I I don't care about line too long for example there's a way I forgot how to do it because I'm good with all the things that it suggests to me but if you really want to exclude some of the errors there's also a way to do it is probably the documentation yeah right yeah yeah that's it for me you're like plugging in a little bit if you do gender development you check out his youtube page for his company because they open source almost everything they do by the way is anyone here toying with the idea of visiting picon later this year in June okay because we are still as we are inside the beginning we are still looking for proposals for talks and I mean we have super awesome keynote speakers but that doesn't mean that everybody who's giving a talk has to be a super awesome rockstar programmer right I mean it's an event driven by us by the community for the community so anyone who's doing anything interesting I thought the talks today were all super interesting and they would have been good fits for picon talks so if you do something awesome like you should submit your talk for picon definitely yeah if you think you're doing something similar it like with this scope this will be a really good talk for picon as well you should consider submitting something it's good for the community so what what do you do now