Wait, you CAN use braces with Python?!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a few weeks ago I made a video talking about Easter eggs in Python and one of those was a from dund the future Easter egg that talked about the idea that python is never going to have braces in it but it turns out that you can actually use Python with braces With a Little Help from an external Library a few years ago someone made a project called python which is available on the python package index which allows you to use Python with braces and not having to worry about indentation so in this video we're going to be having a look at that and seeing if you can genuinely get rid of colons and indentation all together of course if you like the video at any point then consider like it to let me know and maybe subscribing if you want to see more videos like this if you're feeling particularly generous you can become either a member or a patron using the links in the description below with all out of the way out with indentation and in with braces to get started with python first you need to install it and thankfully that's pretty easy CU you can just do it with Pip so you can do pip install bython uh although actually using the correct command would be good I already have it installed you can see we're using version 0.8 today and I imagine you probably will as well because this package hasn't been updated since 2018 so I feel like a lot of people have heard about this recently because I've heard it come up quite a few times um but this isn't a new thing this hasn't been updated for about 6 years um so yeah worth keeping that in mind and to start using it you need to create a file uh you don't have to use the buy extension if you don't want to but that's just what's recommended in the docs so that's what I'm doing and I'm going to show you a really simple example and then I'm going to go over a bit more of a a complicated one and show you how to convert between the two so go to the example in there read me for this so we have a print message and you'll see kind of immediately that there's a bit of a problem with this in that you can't have like code linting on while you're doing this because of course if you use Python it's going to complain about you using curly brackets uh instead of well colons and indentations and stuff uh so that's one thing you going to have to get used to thankfully on vs codee at least if you have plain text if I just do this if you do a Cod brackets like that it will actually automatically indent for you which does put into question how useful bython actually is if you are using an editor but you know we can we can skip aside that for now and then we do four I in oops in range n of times and you do get a little bit of auto complete you get like Sublime start auto complete uh python is awesome like that and then we could do the semicolon you don't have to but uh it's just a little bit of flare so if name equals Main and do the I almost did a c on there print message and then 10 and then like that this is our uh really simple program in order to run it we could just do Python and then the name of the file so script. by and you'll see it runs so what it does is it transpiles the the bython code into python code and then runs that python code in the python interpreter and if you want to see uh what the code is that it's made you could do py uh python DC and then script. by and this will simply compile the code rather than run it you could open script.py and you can see what it's done so by default there's a lot of white space around I think the way it like gets really it it like just you know clears these lines out and replaces this with colons and then it gets it actually gets rid of semicolons weirdly even though they use semicolons in the thing uh but yeah you can see there's not a huge amount of changes that have taken place it's mainly just pretty much find and replace to be completely honest and we'll see examples of the implementation of this not exactly being the most complex uh a little bit later but I do want to go over a few other things first so we have bython Das ha and we can see the full thing so we can keep the generated python files I believe what that does is if I do this it will run it and then it will output the file yeah there you go so it's basically compile and run uh which is kind of a nice thing to have and then you got yeah you got pile there you got some other like verose things lower true what that add support for lower case oh true for oh so you can add support for lower case true and false okay that's cool I didn't know you could do that until this and you could also run it with python 2 if you want be using das2 or double- python 2 and if you're compiling and you don't want your file to be called you know the file name. py you can also Supply A- o um to compile it to so if you want to give it a custom name you can do that as well uh so that's all the basics of bython I have made uh a little guessing game using it so you can see I've gone kind of a you know a little bit full or a little bit extra I guess I don't know what you want to call it but I've done kind of everything so I've done the semicolons I've done the brackets and I've done uh using brackets around if statements and while statements and all that actually I could probably do while true there but I didn't know was a thing uh and this is this is just like a really simple uh game so you you know guess a number between one and 10 with three tries and it uses various while loops and conditionals and while El's and stuff like that to do it and if you run this uh it works nope python it works fine or it doesn't of course it does why doesn't that work okay so this is one of the problems I was having earlier I thought I'd fixed it but I guess not so the ER uh the issue we're getting is ination error expected and ination block after the L statement on line 32 which is this here if we look at the compiled code we can see that it hasn't compiled this properly at all and I'm not in entirely sure why it hasn't properly compiled it I think it's something to do with this in here um although actually no it's the it's clearly IND the indentations but I think that something to do with it so what I was doing before I did try and do something like this to see how competent it was and I did something like this as well to see if it could handle this uh cuz I didn't know how it was implemented if you run that now then I will get the same thing if I comment can I comment it out for a second no BL Tex the comment thing doesn't work okay fine um yeah if we do this like this I can probably compile it and you'll see uh we can see that it just yeah completely breaks um so it is very much a try not a try accept um what am I calling it find replace job where it just replaces open parentheses or open curly brackets with colons and you can actually see that what what it's done here in the uh the string as well and then it replaces the uh or just like removes uh the closing brackets completely the problem is it doesn't seem to be very smart about how it does this so the way I managed to get it to work before is by doing that and then well obviously doing this and that just kind of worked previously um so if I do thing is I can't even do the string do format uh so if I get rid of this and then if I do I and then close that and then brackets number like that that should be a bit better oh got to close the thing you know that would probably help that should be a bit better it should be able to handle that part oh and it looks as it's actually going to be run fine now do that there we go it runs fine now I think it was this string formatting yes so F strings are off the table I did manage to get it to work once with f strings it was working previously uh I don't know why it's not anymore before a game oh I won that was simple yes I do want to try again too low too high yay I won again and then if we do like um hello we can see that it's an valid guess uh okay I'm going to like not win one act actively trying not to win there we go so no more get is number of three if you do it again so it all works fine it's all able to run okay obviously the the exact code isn't formatted yeah it doesn't get rid of like it doesn't it's not really like a c style thing it is more just brackets you did get a lot of white space because of that but you can see that you do have to take care when moving things from from python to python I wonder now now I fix that will this work I want to do it one more time oh it does I think it actually is going to work now okay there you go so you can do slightly more advanced things provided that your F string Expressions aren't breaking everything so yeah you are limited to this which is a bit unfortunate but you it is what it is I suppose I also have not tried it with a dictionary um let's see how it handles this it might not actually handle it at all uh one and then two two something like that just a really simple one and it breaks it can't do dictionaries oh that's really unfortunate actually U I suppose you can do dictionaries because you can do dict 1 = 1 2 = 2 and then that will work fine uh but then you have to do a function call and that's not really readable wow yeah I didn't even try and test it yeah that's not good is it I did not even try and do that before this and uh H yeah that's an interesting one you have to keep in mind so you can't use f strings you can't use dictionaries in their raw form but at the very least you don't have to worry about indentation and yeah just to prove I've uh done this here I've unindented this here if you run it it compiles and it's indented over woo so the other thing I wanted to show you in this video was converting from a python file to a bython file because that's also possible so I have this conversion. piy which which is exactly the same thing I just wanted to name it uh distinctly so uh it was kind of obvious what was going on on the sidebar but if you use pi2 buy and this is also available uh when you pip andall bython so it exposes two separate commands and then I don't know if I loaded the help for this okay there's there's not much you can do you can kind of input something and that's about it uh so if we do PI 2 by and then conversion. Pi we will then get this conversion buy file out and you can see it's more or less done what we wanted it to do so you can see yeah the the brackets around if statements or while statements are optional the semicolons are optional I guess it just treats them the same actually no it doesn't treat them the same even because it gets rid of them when you translate from python to python uh but yeah python can handle you know semicolon is just fine so I suppose it doesn't really bother but it just puts stuff within within curly brackets it doesn't kind of make use of more advanced syntaxes which is sort of annoying but I get yeah I suppose it does it based on the white space within the file rather than anything else again probably another find and replace job uh to be honest I haven't actually looked at the source code so it might I might be not giving the author enough credit but uh yeah that does seem like that's what it is to me let me know in the comments what you think of this I think it's probably a little bit too Limited to really use though I don't think it was really intended to be used in production I think it's just a bit of fun you know I've sort of been ripping it apart a bit but I I don't think it's a a serious attempt to actually change the Dynamics of python I think it's just a fun little experiment and a fun little cool thing to say hey I can use Python with braces uh which is cool in of a sense um but yeah it has its issues for sure I'd like to say huge thank you to my amazing patrons and members on screen now espe mazard rushman the third for being so generous if you want to get fooled despite the fact that it's not April Fool's Day and you can watch last week's video where I successfully pulled the wall over some people's eyes which I'm very happy about and also got a significantly lower like to dislike ratio than normal which I was expecting um but thankfully it wasn't too bad so you can go watch that if you want to be for or if you want a more serious video can watch the video before that where I talked about those Easter eggs like I mentioned at the start of the video and I'll will see you in the next video for whatever we next
Info
Channel: Carberra
Views: 3,204
Rating: undefined out of 5
Keywords: pyfhon, pytho, pytbon, pytjon, ptyhon, pytyon, ptthon, pyyhon, pythn, pythoh, pythpn, ython, pytgon, pyhon, pytohn, phthon, oython, pthon, pyghon, pythoj, pythno, pythkn, ypthon, pytuon, lython, pyrhon, pythom, pythob, puthon, pgthon, python, pyhton, pythln, pythin, pytnon, pyton
Id: rdkyPCrxLmM
Channel Id: undefined
Length: 13min 2sec (782 seconds)
Published: Mon Apr 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.