5 Really Cool Python Functions

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ม.ค. 2025

ความคิดเห็น • 219

  • @Indently
    @Indently  7 หลายเดือนก่อน +70

    Hello everyone, I made an error with the type declarations for the permutations section. I forgot to run Mypy there and when I did it, I got a bunch of errors. Sorry about the inconvenience of that section, I will run Mypy next time to ensure I'm using the correct types (and not just use the code editor's hover feature which is a bit wonky).
    ALSO, as some of you have mentioned, I apologise about my poor example with "exec()". I thought I made it clear that you should never execute code or files that you do not trust, but then I proceeded to talk about examples about downloading files from the internet (which you really shouldn't do). I'm a one man team and I make mistakes as well sometimes. So I'm always grateful when you guys point things out :)

    • @markusklyver6277
      @markusklyver6277 7 หลายเดือนก่อน +2

      The error indicates that the code attempted to index or key on an object that does not support subscription operations, for example operations like indexing or slicing. You try to access permutations at index str, which does not make sense. The error occurs because permutations from the itertools module is not a generic type that can be subscripted with int or any other type. When you write permutations[int], it is interpreted as trying to subscript the permutations class.
      As for why it works inside the function, my hypothesis is: the type hint is part of a local variable annotation, which does not affect the actual execution. Python does not try to evaluate the type hint in a way that would cause an error. This is why you don't see an error when the type hint permutations[int] is used inside the function. Even though you use permutations[int] here, Python essentially ignores the type hint at runtime. Type hints are mostly used for static type checking and do not affect the execution of the code. Python's runtime type evaluation kicks in and tries to interpret permutations[int] as a valid type, which it is not, hence raising a TypeError saying "'type' object is not subscriptable". This is because, unlike inside a function, the interpreter processes annotations immediately when they are at the top level of a script or module.

    • @Indently
      @Indently  7 หลายเดือนก่อน +3

      I'm very familiar with what the error means, my shock came from the fact that I copied and pasted my code and it didn't work literally from one screen to the next xD

    • @david-komi8
      @david-komi8 7 หลายเดือนก่อน +1

      ​​​@@IndentlyI can feel that. That would scare the hell out of me if that happened to me. It seems like PyCharm indications are not always good, because of Python weird features.

    • @david-komi8
      @david-komi8 7 หลายเดือนก่อน

      ​@@markusklyver6277For you, my friend, I have to tell you that you are absolutely right. For some strange reason, Python tries to evaluate type annotations when they are in global scope. When the type annotations are inside a function, they just go directly into the ___annotations___ attribute and nothing else happens. A bit of a bizarre feature if you ask me xD

    • @david-komi8
      @david-komi8 7 หลายเดือนก่อน +1

      ​@@markusklyver6277My bad, I correct myself. The type annotations inside a function just dissapear xD (see by yourself if you want, they just disappear).

  • @PinkoLP
    @PinkoLP 7 หลายเดือนก่อน +228

    "exec is really cool because you can download text from the Internet and execute it" - My IT sec brain initiating a heart attack

    • @olivierbouchez9150
      @olivierbouchez9150 6 หลายเดือนก่อน +2

      Maybe he doesn’t know what code injection is?

    • @nicolasfiore
      @nicolasfiore 6 หลายเดือนก่อน +1

      Not exactly the same, but I have used curl several times in my life to do exactly that

    • @autumnblaze6267
      @autumnblaze6267 3 หลายเดือนก่อน

      isn't that just running a script (Python, Bash, whatever)? you download some text (often a bunch of files and all, but if you want, you can package it as one text file that you can just copy and paste from Pastebin and such) and execute it 😂
      running a precompiled program is even worse cos you can't even read what's inside - i.e. it's as dangerous as running... anything (the risk really depends on whether you trust the author and whether you take precautions like not running as root for starters)

    • @PinkoLP
      @PinkoLP 3 หลายเดือนก่อน

      @@autumnblaze6267 When you download a script manually, you can double check its contents and the file is not executable by default. If you download binaries, you ofc need trust in the authors, but given that you do you have checksums. With exec you have none of that, it instantly downloads and runs with no confirmation in between. What's more is, that one typo in the URL and you might have just spelled out a malicious website with the purpose of catching people that mistype such an URL offguard (I think that counts as waterholing). Or, if you have such an exec statement in one of your scripts, and say, you run it 5 years later again: what if e.g. the domain was sold, or the owner just decided to change the content. There is no telling what would happen. It's less about running stuff off the web, it's more about automating it that is problematic.

  • @snwbrdn777
    @snwbrdn777 7 หลายเดือนก่อน +183

    Mathematician here, I'd just like to mention that permutations and combinations are not interchangeable terms. For permutations, order matters and for combinations, order does not.

    • @josephbrandenburg4373
      @josephbrandenburg4373 7 หลายเดือนก่อน +10

      Bruh acting like a mathematician because he knows a fun fact from middle School pre algebra

    • @lydellackerman800
      @lydellackerman800 7 หลายเดือนก่อน +62

      @@josephbrandenburg4373 calm down joseph

    • @sadhlife
      @sadhlife 7 หลายเดือนก่อน +36

      ​@@josephbrandenburg4373 bruh acting like he knows the person by reading one comment made by them

    • @MrRahul15937
      @MrRahul15937 4 หลายเดือนก่อน

      Agree

    • @cyin974
      @cyin974 2 หลายเดือนก่อน

      ​@@josephbrandenburg4373Not just a fun fact, it's extremely important to differentiate both terms because combinations and permutations are used frequently in many fields, and they are in fact very different.

  • @ego-lay_atman-bay
    @ego-lay_atman-bay 7 หลายเดือนก่อน +19

    You gotta love it when the video shows your confusion with an error, instead of cutting it out (or rerecording to adress the error).

  • @BartoszDotryw
    @BartoszDotryw 7 หลายเดือนก่อน +128

    Javascript: eval is unsafe, don't use it!
    Indently: hey look, exec is awesome!

    • @MichaelGrantPhD
      @MichaelGrantPhD 7 หลายเดือนก่อน +27

      I can't think of a single use case for exec that is both safe and worthwhile. I was really surprised to see this at the top of the list.

    • @Indently
      @Indently  7 หลายเดือนก่อน +52

      While I understand your concern, I just want to mention that the title is "5 really cool functions", not "5 really safe functions". The whole video is based on functions I found really cool (even if exec is dangerous) :)

    • @BartoszDotryw
      @BartoszDotryw 7 หลายเดือนก่อน +3

      @@Indently fair, and you did state in the video it might be dangerous, but I still wouldn't consider such a dangerous function to be cool. Even if you don't pass unsafe data to it directly, you can't be 100% sure it won't be passed indirectly at some point, due to a bug or oversight.

    • @Indently
      @Indently  7 หลายเดือนก่อน +11

      That's a fair take!

    • @jonreznick5531
      @jonreznick5531 7 หลายเดือนก่อน +25

      @@Indently I would have led with "exec is really cool because it's insanely dangerous and might result in literally anything being executed on your system and danger is cool."

  • @MichaelGrantPhD
    @MichaelGrantPhD 7 หลายเดือนก่อน +295

    Your warnings about the misuse of exec were just not strong enough, in my view. Exec'ing user input? ABSOLUTELY NOT. Never do that, folks. The legitimate uses of exec that cannot be implemented in other ways are few to none. Please don't.

    • @hriscuvalerica4814
      @hriscuvalerica4814 7 หลายเดือนก่อน +5

      Isn't eval used in Jupyter . It's a cool curiosity

    • @TheRealMangoDev
      @TheRealMangoDev 7 หลายเดือนก่อน +1

      but its called eval!!!

    • @MoneyGrab
      @MoneyGrab 7 หลายเดือนก่อน

      ​@@hriscuvalerica4814well, maybe but jupyter notebook NEEDS eval, because how would it execute the code??

    • @logicaestrex2278
      @logicaestrex2278 7 หลายเดือนก่อน +7

      its in the standard library and many other places. as with anything, learn where to use it and where not too, and follow the one rule: dont be dogmatic, there are no real rules

    • @akasakasvault7597
      @akasakasvault7597 7 หลายเดือนก่อน +7

      @@logicaestrex2278 ok but never exec user input or at the very least, sanitize it. a user typing "import os; os.cls("rm -rf \")" is not something you want

  • @mrrobotman5299
    @mrrobotman5299 7 หลายเดือนก่อน +22

    Partial is really useful for tkinter callback functions when you need to pass additional arguments.

  • @josephs3973
    @josephs3973 7 หลายเดือนก่อน +24

    The problem with the permutations example is that you're using the wrong type hint. It should be annotated as Iterable[Tuple[str]]. The fact that it works inside the function is because the python interpreter doesn't enforce typing during runtime inside of functions, but it does in the main scope.

    • @Indently
      @Indently  7 หลายเดือนก่อน +5

      You're right, I absolutely gave them the wrong types, I forgot to run Mypy on this one.

  • @rondamon4408
    @rondamon4408 7 หลายเดือนก่อน +67

    10:00 I'm glad you showed an error. This is the real life

    • @briankristensendk
      @briankristensendk 7 หลายเดือนก่อน +4

      Any clue why this gave an error?

    • @rondamon4408
      @rondamon4408 7 หลายเดือนก่อน +1

      @@briankristensendk no, but actually is like to do an spike on it

    • @tidy5156
      @tidy5156 7 หลายเดือนก่อน +7

      ​@briankristensendk permutations is a function an not an object. Thus you can't put [str] at the end of it. Why the official docstring told otherwise idk. Or maybe it's just a function in this namesapace

    • @macong1217
      @macong1217 7 หลายเดือนก่อน +3

      @@briankristensendk Do it like this works `perms: "permutations[str]"`.

    • @EvanED
      @EvanED 7 หลายเดือนก่อน

      @@tidy5156 But then why *did* it work as an annotation in the function?

  • @Amstelchen
    @Amstelchen 7 หลายเดือนก่อน +19

    T-k as in toolkit and inter as in interoperability.

  • @khadgaa5443
    @khadgaa5443 7 หลายเดือนก่อน +28

    7:09 What's really cool I noticed is using "_" as a seperator for numbers. like 10_000 . I didn't know that before.

    • @DrDeuteron
      @DrDeuteron 7 หลายเดือนก่อน +2

      afaik it's "new".

    • @mirabilis
      @mirabilis 7 หลายเดือนก่อน

      Yes, 7 years "new". ;) It came with Python 3.6. ​@@DrDeuteron

    • @Jens1111
      @Jens1111 7 หลายเดือนก่อน

      Me too.

    • @DrDeuteron
      @DrDeuteron 7 หลายเดือนก่อน +1

      @@squishy-tomato that’s new in my book.

    • @Nbrother1234
      @Nbrother1234 3 หลายเดือนก่อน

      Also, you can put the underscore separator literally _anywhere_ in the number. 12_3456.7_8_9 = 123456.789 is valid.

  • @carmelostagno6352
    @carmelostagno6352 7 หลายเดือนก่อน +3

    Ciao Federico. Ti scrivo in italiano perché penso tu sia di origine italiana. Stai facendo un ottimo lavoro con questi suggerimenti e ‘trucchetti’. Conoscevo Python da anni ma c’è sempre qualcosa di nuovo da imparare e tu riesci a trasmettere le tue particolari conoscenze alla grande. Grazie per l’impegno e la chiarezza. Ogni tuo video è un appuntamento importante che aspetto con molto interesse. Buon lavoro e buona vita!

    • @Iuigi_t
      @Iuigi_t 7 หลายเดือนก่อน

      I think he is from Denmark.

    • @Kitulous
      @Kitulous 7 หลายเดือนก่อน

      @@Iuigi_t at 17:39 he has MacBook air **di** Federico and **Custodia** AirPods in the top left and an Italian keyboard layout in the top right

  • @brunocamposquenaoeoyoutuber
    @brunocamposquenaoeoyoutuber 7 หลายเดือนก่อน +12

    For "partial", just use a lambda.
    specify_name = lambda name: specifications("Green",name,10)

    • @sadhlife
      @sadhlife 7 หลายเดือนก่อน +12

      while partial and lambda are interchangeable in many cases, they are not the same.
      partial will capture the variables by value, and lambda will capture them by closure, essentially letting the lambda be reactive to changes in the variables being used inside it.
      sometimes you want early binding, sometimes you want late binding. both have their uses.

    • @phatboislym
      @phatboislym 7 หลายเดือนก่อน +2

      honestly, default values might be good enough

    • @brunocamposquenaoeoyoutuber
      @brunocamposquenaoeoyoutuber 7 หลายเดือนก่อน +4

      @@phatboislym Not if you want to do multiple partials or lambdas.

    • @chriskeo392
      @chriskeo392 7 หลายเดือนก่อน +1

      ​@@sadhlifelovely answer. 👑

    • @dimdimich
      @dimdimich 7 หลายเดือนก่อน +2

      Why not
      def specify_name(name):
      return specifications("Green", name, 10)
      ?

  • @carmelostagno6352
    @carmelostagno6352 7 หลายเดือนก่อน +4

    Grazie.

    • @Indently
      @Indently  7 หลายเดือนก่อน +4

      Thank you very much for your support :)

  • @lukchem
    @lukchem 7 หลายเดือนก่อน +4

    I call it t-k-inter because inter comes from interact since the tk functions allows the user to interact with the operating system by for example displaying a file choose window.

  • @Oler-yx7xj
    @Oler-yx7xj 7 หลายเดือนก่อน +5

    Exec (more so eval) is cool for all kinds of bodging, in leetcode style questions especially, say you have a string of ones and zeros and you want to get a number from it (and you forgot the proper way): peepend 0b to it and eval

    • @MichaelGrantPhD
      @MichaelGrantPhD 7 หลายเดือนก่อน +2

      For code golf that's fine, but for serious code ast.literal_eval is as far as I would go.

  • @Ohiostategenerationx
    @Ohiostategenerationx 7 หลายเดือนก่อน +5

    I like the exec function the most on this tutorial.

  • @soliver68
    @soliver68 7 หลายเดือนก่อน +26

    exec is evil 👹😉

    • @DrDeuteron
      @DrDeuteron 7 หลายเดือนก่อน +1

      "exec consider harmful" is the proper way to phrase it, with reverence to Edsger Dijkstra .
      See the wikipedia page "Considered_harmful" for the deets.

  • @3rdalbum
    @3rdalbum 4 หลายเดือนก่อน

    That AskOpenFilename function reminds me of the old EasyDialogs on MacPython, where you could easily show alert boxes, message boxes and other very basic dialog boxes without having to have an entire interface toolkit loaded. (That, itself, was also a bit like the Ask and Answer functions in Hypercard). Does Tkinter have a similar function to show a basic alert dialog box, perhaps with two or three options that can be selected?

  • @onetruetroy
    @onetruetroy 25 วันที่ผ่านมา

    Terrific video, one that makes you think and thoroughly research these functions before using them in a live environment. 😉
    -
    There are a handful of reasons to use exec(), eval(), or something similar. Got me it was math expression building. I originally did this with BASIC , dBase, etc. (interpreted only) when a formula was input, parsed, checked, and an executable was generated. This is great for entering a formula to graph without stopping the program to edit and run.

  • @cmyk8964
    @cmyk8964 หลายเดือนก่อน

    Clarification on permutations and combinations:
    • Permutations are *reorderings* of the elements. No repeats are allowed. There are n! (n factorial) permutations of n distinct objects.
    • Combinations are ways to choose k elements from a superset of n elements, where *the order doesn’t matter.* There are “n choose k” ways to do this.

  • @dipankarbanerjee1130
    @dipankarbanerjee1130 13 วันที่ผ่านมา +1

    1. Sir, can you tell me why are you doing
    names : list[str] =[ 'abc', 'bcd',...] or
    num : int = 87
    such type of variable declarations?? You could have declared like just names or num ... People do say its a good practice, even I use this during defining function arguments... But why is this a good practice? I really don't understand. Please help me.
    2. What's the name of your Python Interpreter/Compiler?

  • @pauldhartley
    @pauldhartley 7 หลายเดือนก่อน +2

    Amazing, thank you

  • @ego-lay_atman-bay
    @ego-lay_atman-bay 7 หลายเดือนก่อน +3

    Ah yes, it took me forever to learn that you don't actually need a tkinter window to show a file dialog (one mistake that a lot of tutorials I found online did). Oh, and the file dialog isn't just a cool function to get file paths, it's really cool for actual programs, letting users select their own files, or even ask users where they want to save a file.

  • @vladyslavkorenyak872
    @vladyslavkorenyak872 7 หลายเดือนก่อน +2

    Really like the askopenfilename!

  • @eboyd53
    @eboyd53 7 หลายเดือนก่อน +4

    Pronouncing "tkinter": I always say T K Inter as it is representative of TK Interface. TK is the GUI Tool Kit for the TCL scripting language and you often see it as TCL/TK.

  •  7 หลายเดือนก่อน +1

    I'm curious if partial is better than simply create a function with the arguments you want to variate which calls the original function with the given and the fixed arguments...

    • @brendanbennett6770
      @brendanbennett6770 7 หลายเดือนก่อน

      If you're using a wrapper function and you're setting the predefined arguments with variables and these change somewhere else in the code, then it will change in the function execution. With partial, these fixed arguments will stay the same for the whole execution.

  • @david-komi8
    @david-komi8 7 หลายเดือนก่อน +1

    I think the 10:00 error has something to do with the scope. For some reason, outside a function, it wants to subscript permutations instead of interpreting permutations as a type. The reason? I don't really know.

    • @qwerty11111122
      @qwerty11111122 7 หลายเดือนก่อน +2

      We need mCoding on the case!

    • @josephs3973
      @josephs3973 7 หลายเดือนก่อน +2

      It's using the wrong type annotation. It should be Iterable[Tuple[str]]. It works in the function because the interpreter doesn't enforce type annotations inside functions but it does in the main scope.

  • @Andrew-Wardle
    @Andrew-Wardle 7 หลายเดือนก่อน +3

    4:42 how did you highlight those 3 lines ?

    • @briankristensendk
      @briankristensendk 7 หลายเดือนก่อน +1

      I Think it is by pressing ctrl while dragging mouse, if i Remember correct.

    • @ego-lay_atman-bay
      @ego-lay_atman-bay 7 หลายเดือนก่อน +1

      I'm pretty sure the default in vscode is pressing alt, and dragging.

  • @alsaedwy
    @alsaedwy 7 หลายเดือนก่อน +2

    The macOS update bit made me laugh 😂

  • @alidev425
    @alidev425 7 หลายเดือนก่อน

    great content highly recommended 👍👍 keep it up

  • @davidgillies620
    @davidgillies620 6 หลายเดือนก่อน

    Note that partial application (run-time binding) isn't currying. Currying is converting a function with multiple arguments into a sequence of unary functions.

  • @largewallofbeans9812
    @largewallofbeans9812 7 หลายเดือนก่อน

    I've never used exec in any project, but I have used the very similar eval function for an expression parser for a calculator. For all I know, eval is safe **as long as you heavily modify the user input**, like how I did for my calculator.

  • @TheKnytemayor
    @TheKnytemayor 7 หลายเดือนก่อน +1

    2:50 I can very much relate. Also, I pronounce tkinter as T Kinter

  • @markusklyver6277
    @markusklyver6277 7 หลายเดือนก่อน +1

    The error indicates that the code attempted to index or key on an object that does not support subscription operations, for example operations like indexing or slicing. You try to access permutations at index str, which does not make sense. The error occurs because permutations from the itertools module is not a generic type that can be subscripted with int or any other type. When you write permutations[int], it is interpreted as trying to subscript the permutations class.
    As for why it works inside the function, my hypothesis is: the type hint is part of a local variable annotation, which does not affect the actual execution. Python does not try to evaluate the type hint in a way that would cause an error. This is why you don't see an error when the type hint permutations[int] is used inside the function. Even though you use permutations[int] here, Python essentially ignores the type hint at runtime. Type hints are mostly used for static type checking and do not affect the execution of the code. Python's runtime type evaluation kicks in and tries to interpret permutations[int] as a valid type, which it is not, hence raising a TypeError saying "'type' object is not subscriptable". This is because, unlike inside a function, the interpreter processes annotations immediately when they are at the top level of a script or module.

  • @Wonderdog888
    @Wonderdog888 4 หลายเดือนก่อน

    The part where you use partial i dont really understand the use of it. Wouldn't it be easier to set default values for variables inside the function? Im a newbie to Python just trying to see an real world scenario.

  • @stevedoesredstone3631
    @stevedoesredstone3631 7 หลายเดือนก่อน +1

    Does type hinting increase the speed of the program??

    • @MichaelCoombes776
      @MichaelCoombes776 7 หลายเดือนก่อน +3

      No, it doesn't affect the code in any way. It's mainly for checking that you pass the specified types to a function, and letting the IDE warn you if something is incorrect. Python will still run the code with whatever you give it,errors and all.

    • @TheSandkastenverbot
      @TheSandkastenverbot 26 วันที่ผ่านมา

      When you use Cython to create a binary executable from your python code, specifying types can make the code more time and memory efficient (by quite a lot in some cases). But the Python interpreter seems to just ignore them.

    • @stevedoesredstone3631
      @stevedoesredstone3631 26 วันที่ผ่านมา

      @TheSandkastenverbot So when using standard python, there is no use for type hints when it comes to performance?

  • @DogiMetal
    @DogiMetal 7 หลายเดือนก่อน +1

    „Hi, Bob!“

  • @drobacmichelle
    @drobacmichelle 7 หลายเดือนก่อน

    Hi!!
    For exemple 3, type statement generates a "SyntaxError: invalid syntax" in VSCode Jupyter Notebook cell.
    Does anyone know why?

  • @denizsincar29
    @denizsincar29 7 หลายเดือนก่อน +1

    I really hope that tkinter's file dialog makes native dialog. Because tkinter apps are not accessible for blind

    • @ego-lay_atman-bay
      @ego-lay_atman-bay 7 หลายเดือนก่อน +2

      It uses the native file dialog, as shown in the video. On mac, it open finder, on windows, it open windows explorer, and on linux, heck I have no idea.

  • @k.chriscaldwell4141
    @k.chriscaldwell4141 6 หลายเดือนก่อน

    Thank you.

  • @Suit9uy
    @Suit9uy 7 หลายเดือนก่อน

    It’s very useful

  • @jagatkrishna1543
    @jagatkrishna1543 7 หลายเดือนก่อน +2

    Thanks 🙏❤

  • @narkfestmojo6156
    @narkfestmojo6156 6 หลายเดือนก่อน

    I love exec, I use it to reload the config options while training a neural network, means I can adjust stuff like the learning rate, betas, decay rate, even datasets without having to restart the code; I wanted to do this early on and tried using a JSON file instead, absolutely hated it, with a python file I can easily use an editor (I really need to stop using Idle), make comments and have the program give me useful information if I screw up. With my code, exceptions in the config update function don't interrupt the execution, they just report the error and don't update the config. Don't wanna wake up and discover a night of training has been lost because of a silly mistake in the config file.

  • @Davixd3
    @Davixd3 7 หลายเดือนก่อน +4

    I call it tkinter, with all the letters. But I have no ideia. For all I know, it could be called ticke-inter

  • @funkdefied1
    @funkdefied1 7 หลายเดือนก่อน

    Partial is cool, but it seems obsolete. What’s its advantage over something like this?
    specify_amount = lambda amount : specifications(‘red’, ‘bob’, amount)

  • @waiitwhaat
    @waiitwhaat 7 หลายเดือนก่อน +3

    Holy smokes I'm gonna absolutely ABUSE the filedialog module from tkinter.

  • @redtonyred
    @redtonyred 7 หลายเดือนก่อน

    What is the advantage to use the partial over using kewordarguments with a default values?

    • @Indently
      @Indently  7 หลายเดือนก่อน +3

      With partial() you can use any function, even ones from external packages, and you can change the default values for any function in case the one's that are specified aren't good enough.

    • @klembokable
      @klembokable 7 หลายเดือนก่อน +1

      The default values being hard coded into the function definition seems like a relative disadvantage to me

    • @redtonyred
      @redtonyred 7 หลายเดือนก่อน

      @@klembokable but when you define the partial you also need to hardcode some values. in the given example the partial is partial(specifications, amount=10) a function with keywordarguments would be specifications(color, name, amount=10).

    • @klembokable
      @klembokable 7 หลายเดือนก่อน

      Personally I've only used bind(), for binding arguments to functions to hold for timed execution... and it seems to accomplish a similar task as partial

    • @glorytoarstotzka330
      @glorytoarstotzka330 7 หลายเดือนก่อน +2

      sometimes you cannot set a default keyword argument because you can't access that part of code or you can't know the value ahead of time
      screen = Screen.get_title('youtube')
      button1 = Button(screen, template1)
      button2 = Button(screen, template2)
      button3 = Button(screen, template3)
      ###
      screen = Screen.get_title('youtube')
      button = partial(Button, screen)
      button1 = button(template1)
      button2 = button(template2)
      button3 = button(template3)
      here you can't use defaults, and the point is that it's way less error prone because if you written in the first approach like a month ago, and written a lot more buttons and had other arguments potentially, if you are tasked to change them today, it's possible to miss one or two of them and you won't know unless you got unit tests that cover it

  • @KeyT3ch
    @KeyT3ch 4 หลายเดือนก่อน

    partial is just std::bind?

  • @VRchitecture
    @VRchitecture 7 หลายเดือนก่อน

    Hey, @Indently, seems you’ve made a mistake in the description. Shouldn’t it be “▶ Become Bob-ready with Python”?

  • @jakub_1999
    @jakub_1999 4 หลายเดือนก่อน +1

    i can use exec with pastbin😍

  • @willempye73
    @willempye73 7 หลายเดือนก่อน

    The partial function seems like pointlessly adding a dependancy to me.
    Can you just do
    def my_func(a, b, c):
    print(a, b, c)
    my_partial = lambda x, y: my_func(x, y, fixed_c_value)

    • @amogusenjoyer
      @amogusenjoyer 6 หลายเดือนก่อน

      What do you mean? It's in the standard library, in functools.
      Also, it's not really the same use case. It's nice to have an easy and standard way to "save" or store functions that could be called by signals, slots, or callbacks, with the necessary arguments for example.

  • @AsgerJon
    @AsgerJon 7 หลายเดือนก่อน

    Do not use stuff from random for encryption related situation, use the secrets module instead.

  • @glorytoarstotzka330
    @glorytoarstotzka330 7 หลายเดือนก่อน +4

    you can make a function that is aware of the name of the variable it is being assigned to:
    def ui_element():
    stack = inspect.stack()
    line = stack[1].code_context[0]
    match = re.search(r"(\w+)\s*=", line)
    if match:
    variable_name = match.group(1)
    if "button" in variable_name:
    return Button()
    else:
    return Widget()
    I don't recommend using this for stuff unless you learn more about the implications but you can use these to:
    - attempt to automatically load constants at the top of the file with matching names
    - return instances from different classes based on the name
    - run any specific arbitrary code specific to some variable names, e.g.: a variable named "screen_2" could use different default values for a Screen instance than a variable named "screen"
    you can do the same thing with arguments and parameters, but you write less and its less error prone this way. I recommend only using these on personal projects

    • @DrDeuteron
      @DrDeuteron 7 หลายเดือนก่อน +1

      I can see wanting to get instances based on a name...is there a way to do that by searching globals() or locals(), maybe with a getattr on dunder module?

    • @glorytoarstotzka330
      @glorytoarstotzka330 7 หลายเดือนก่อน

      ​@@DrDeuteron I think you theoretically could, you just read all the global variables and re-assign the value to whatever you want
      these are all really fun thought experiments, but I am scared that someone will actually use these things in a popular library and have important stuff be incompatible with other libraries that do something similar. it's important to note that this makes the code very non-modular and very hard to test, cuz it's essentially a overglorified singleton pattern or singleton with extra steps
      technically if you go super hard with automatic code generation and understanding how your code is used, you can go extremely hard and make it so you have to specify a fraction of everything, or have something be as intuitive as physically possible whilst still using code

    • @Julie9009
      @Julie9009 7 หลายเดือนก่อน

      @glorytoarstotzka330 That is really cool. Thank you

  • @iBoxRadio
    @iBoxRadio 7 หลายเดือนก่อน +1

    in 2 years there will be no more

  • @dzigayu4944
    @dzigayu4944 หลายเดือนก่อน

    I would be EXTREMELY cautious about running exec in a program, don't let it even sniff any sort of user input directly.

  • @briankristensendk
    @briankristensendk 7 หลายเดือนก่อน

    11:23 Why is there no A,B,A?

    • @mrrobotman5299
      @mrrobotman5299 7 หลายเดือนก่อน +1

      A, A, B is the same as A, B, A. In combinations (and permutatioms) the order doesn't matter.

  • @null-0x
    @null-0x 7 หลายเดือนก่อน +1

    Hello, Bob!

  • @nathaaaaaa
    @nathaaaaaa 7 หลายเดือนก่อน

    Exec is a major security flaw

  • @tamalchakraborty5346
    @tamalchakraborty5346 5 หลายเดือนก่อน

    I got the same error. Just removing the type or putting it in a function, solved it.

  • @123TRATRATRA
    @123TRATRATRA 7 หลายเดือนก่อน

    For the function sampe and choices, do they take the first answer out first? Your example with 2 Bob's is interesting, because if the first result is Bob, does that mean the second Bob have a 25% of winning again? or a 40% chance because the first Bob is still included making 2 Bob's able to win the second time?

  • @fatercoelho7476
    @fatercoelho7476 6 หลายเดือนก่อน

    exec is indeed powerfull and cool to know. It is however something you should REALLY avoid using. the last one is my favourite though, might save lots of headaches if a file is not where it should be, maybe every time a "file not found" error shows up i'll just handle it with that...

  • @lukchem
    @lukchem 7 หลายเดือนก่อน +1

    Damn do your software updates man

  • @Keithfert490
    @Keithfert490 7 หลายเดือนก่อน +1

    Hello, Bob

  • @stefanrankovic2514
    @stefanrankovic2514 7 หลายเดือนก่อน

    cant you just do:
    def specifications(colour,name,amount=10)->None:
    *the print statement*
    specifications('Red',' Bob')
    instead of using partial?

  • @s8muel
    @s8muel 7 หลายเดือนก่อน

    Hello Bob!

  • @standard0stuff
    @standard0stuff 7 หลายเดือนก่อน +4

    Tee-Kay-Inter

  • @Milkguy33
    @Milkguy33 7 หลายเดือนก่อน

    2:54 AI that can modify its own code....

  • @longphan6548
    @longphan6548 7 หลายเดือนก่อน +13

    That "partial" is weird...

    • @davidmurphy563
      @davidmurphy563 7 หลายเดือนก่อน +2

      Yeah, there wouldn't be a lot of point to it if you wrote the function as you could just add default
      parameter values. So really it's just if you're importing a function.
      Probably only practical if you've got a shell environment and you're running a function again and again without using a loop. But then you'd just cursor up...
      Honestly, I can't think of a real use case where it saves time other than it just happening to suit someone's coding style.

    • @mattshu
      @mattshu 7 หลายเดือนก่อน +1

      Yeahh I feel like it’s too extra for a corner case but maybe there are more useful cases

    • @joeferreti9442
      @joeferreti9442 7 หลายเดือนก่อน +1

      Why? It just let's you save a (sub)set of arguments for a function. It returns a new function object that wraps the original function.

    • @DrDeuteron
      @DrDeuteron 7 หลายเดือนก่อน +1

      I use partial all the time. Lets say I have a hyper spectral microwave radiometer, each channel has a fixed frequency so I want evaluate Planck Law (a function of temperature and frequency), I'm going to assign each channel a partial call to B(nu, T) so it just calls a function of temperature at it's fixed frequency.
      ofc you can do this with keywords or methods, but the partial function has fewer opportunities for bugs as it reduces the number of parameters in the call. which is hard appreciate in a toy example, but when you a 40 or maybe 400 channels and what not it just simplifies the interactions between various parts of the code.

    • @mitrotsky
      @mitrotsky 7 หลายเดือนก่อน +4

      Partial is extremely usefull in functional programming. But more practical usage is GUI. Slots accept a function as an object, therefore no arguments, and a partial allows you to pass a function with arguments.

  • @pixelcatcher123
    @pixelcatcher123 7 หลายเดือนก่อน +1

    Hello Bob

  • @Un_revealing
    @Un_revealing 7 หลายเดือนก่อน

    I call it T-Kinter

  • @trinxic-music1469
    @trinxic-music1469 7 หลายเดือนก่อน

    Hello, Bob.

  • @markschafer1457
    @markschafer1457 6 หลายเดือนก่อน

    Consider Customtkinter instead - themes built in, "better" styling, premade common things. otherwise very similar to tkinter.

    • @Indently
      @Indently  6 หลายเดือนก่อน

      Theme doesn't even matter in this context, it defaults to your system file finder

  • @AsgerJon
    @AsgerJon 7 หลายเดือนก่อน +1

    exec is for debugging situations. If your code still has exec in it, you are not finished writing code.

  • @remboldt03
    @remboldt03 7 หลายเดือนก่อน

    The _exec()_ functions seems way too risky to implement

  • @YubbyWaWa
    @YubbyWaWa 2 วันที่ผ่านมา

    It's pronounced "T-Kinter"😄

  • @AlexCernat
    @AlexCernat 7 หลายเดือนก่อน

    the real exec() in php is evil, and should be absolutely avoided
    i see that in python exec seems like an eval(), which is maybe eviler, because sooner or later someone will do like "fire in the hole", and the project will explode 😛

  • @finnthirud
    @finnthirud 7 หลายเดือนก่อน +2

    Robert'); DROP TABLE Students;--

    • @TrevorDBrown
      @TrevorDBrown 7 หลายเดือนก่อน +1

      We call him little Bobby Tables!

  • @MH-oc4de
    @MH-oc4de 14 วันที่ผ่านมา

    I'm sure there must be some good use for partial but your example is not good. It's more efficient/readable to just use kwargs and **kwargs to accomplish the same thing.

  • @jordanhenshaw
    @jordanhenshaw 5 หลายเดือนก่อน

    exec() seems like a really bad idea. Not sure why you don’t just uncomment it, lol. And you probably shouldn’t be executing external logic.

  • @evidence2839
    @evidence2839 7 หลายเดือนก่อน

    for partial, couldn't you just do;
    def partial(param1,param2):
    return function(param1,param2,"Blah blah blah")

  • @e3498-v7l
    @e3498-v7l 7 หลายเดือนก่อน

    partials seem completely unnecessary. The same can be achieved by wrapper functions that provide the predefined arguments.

  • @renren_does_programming
    @renren_does_programming 7 หลายเดือนก่อน

    Not 2nd but 7th Yessss

  • @landsgevaer
    @landsgevaer 7 หลายเดือนก่อน

    Hallå Bob!

  • @mazinayman4004
    @mazinayman4004 7 หลายเดือนก่อน +1

    Hello bob

  • @GLOBAL_TUTORIALS_2
    @GLOBAL_TUTORIALS_2 7 หลายเดือนก่อน

    Hello, bob

  • @Mahanth.
    @Mahanth. 7 หลายเดือนก่อน +2

    Nah, you pronounced tkinter its.... tkinter ! not tkinter... or tkinter...

    • @FebryanShino
      @FebryanShino 6 หลายเดือนก่อน

      actually it's tkinter, not tkinter

  • @DrDeuteron
    @DrDeuteron 7 หลายเดือนก่อน

    12:36. what? type is now a statement? I thought it was a function (actually, type and super and python's best functions, but I digress). Who is in charge over at python? This is unacceptable.

    • @Indently
      @Indently  7 หลายเดือนก่อน +1

      type is going to end up being the most versatile keyword in Python.

  • @GhostShadow.0316
    @GhostShadow.0316 7 หลายเดือนก่อน

    cant we just use lambda instead of partial?

    • @FasutonemuMyoji
      @FasutonemuMyoji 7 หลายเดือนก่อน

      maybe to replace his example, but the main use is to quick curry a function. you can look up how to or why you would want to curry a function and why it is different from lambda

  • @rishiraj2548
    @rishiraj2548 7 หลายเดือนก่อน

    👍👍

  • @Md.ShantoUjar
    @Md.ShantoUjar 7 หลายเดือนก่อน

    You also get errors this means you are really human.
    tkinter is T K inter

  • @_Funtime60
    @_Funtime60 6 หลายเดือนก่อน

    Is this an old April fools day video? I'm only on the second function and it's already bad. Exec should NEVER be used, if you need to use it go back and try again because you don't. And partial is just a more complicated overloaded function, unless python is missing this feature.

    • @amogusenjoyer
      @amogusenjoyer 6 หลายเดือนก่อน

      What does it have to do with function overloading? Overloading works by using function signatures, which isn't the case for partial.

    • @_Funtime60
      @_Funtime60 6 หลายเดือนก่อน

      @@amogusenjoyer you could just create an overloaded function that has the same purpose as the partial

    • @amogusenjoyer
      @amogusenjoyer 6 หลายเดือนก่อน

      @@_Funtime60 sure, but then why not just use partial? It's already in the standard library and it's also simpler to use and signals intent. You have to worry about the overloaded (and @overload is clunky in python anyways) function that you'd need, you don't have to change anything else in your codebase either. You just consume the same function signature but with the values you need (which also allows you store the functions with the right values they'll need when they get called).

    • @_Funtime60
      @_Funtime60 6 หลายเดือนก่อน +1

      @@amogusenjoyer ah, so it's just another compensation for pythons short comings. And overloads are much simpler if the language actually supports it. You don't need to bring in another class even if it is built-in.

  • @glorytoarstotzka330
    @glorytoarstotzka330 7 หลายเดือนก่อน

    I personally pronounce tkinter as "kinter" so "t" is silent. no idea if this is how it was meant to be pronounced

  • @Luna5829
    @Luna5829 7 หลายเดือนก่อน

    i pronounce it t-k-inter
    t and k being pronounced like the letters are

  • @RobBominaar
    @RobBominaar 7 หลายเดือนก่อน

    Jesus, can't you think of more RealWorld use cases. If you want to explain things, take the time do a bit more than what one can read in the docs. Otherwise, it's quite useless.

  • @thirdeye4654
    @thirdeye4654 7 หลายเดือนก่อน +1

    I still don't like seeing you using type annotations. It's so unnecessary, especially outside of rocket science and your simple examples. It makes the readability of Python code go to waste. :P

  • @DrDeuteron
    @DrDeuteron 7 หลายเดือนก่อน +2

    exec('os.system("rm -r *")') # Game Over, Man.
    or something like that.

    • @josephs3973
      @josephs3973 7 หลายเดือนก่อน

      rm -rf /

  • @murphygreen8484
    @murphygreen8484 7 หลายเดือนก่อน

    Hello Bob!

  • @logicmatthewlearning
    @logicmatthewlearning 27 วันที่ผ่านมา

    Hello Bob!