Great content, I started using assert recently learning how to unittest, and never came into my mind that it can be used in this way, even allowing us to speed code in production. Thanks dude, you're awesome.
@wartem2 жыл бұрын
Really great that you also talked about how assertions affect code performance and how to disable them in production. Concise yet informative.
@RedShipsofSpainAgain Жыл бұрын
3:55 btw, it's probably not a good idea to name your json object "json", as that is just inviting trouble from confusion with the keyword also named json. Instead, name it something more descriptive like json_data, or even json_obj. But not just json.
@bassycounter Жыл бұрын
I didn't know about the __debug__ and using -O and -OO flags, that's pretty handy
@barnabykent669826 күн бұрын
Very clear for a beginner. Excellent content to noise ratio. Thank you.
@JongJong-oc1el7 ай бұрын
question. you use assert to check the assumption of the value is the right type as what i understood from your code. I am still beginner but my question if we can use assert for that way. Then i can use it in replacement for if...else in python? It looks better compared to using if..else and print according to the condition. what do you think with what understood from looking at the code in your video. I really thought assert() is part of unittest framework or from pytest.
@MustbeTheBassest2 жыл бұрын
Wait, I'm confused. This wouldn't be used in production code? Then how do you check inputs in production? I'm assuming you should?
@maxthexpfarmer39572 жыл бұрын
yeah don't use it in production
@MustbeTheBassest2 жыл бұрын
@@maxthexpfarmer3957 thanks, could you give any more details? Do you not check inputs in production?
@maxthexpfarmer39572 жыл бұрын
@@MustbeTheBassest I'm just a student, but this is how I would do it: data=input(`prompt`): while not `validation condition`: print(`error message`) data=input(`prompt`) #more code goes here
@caiolaytynher59942 жыл бұрын
In production, you always have the right input because you've wrote it in a way that it does not raise any exceptions. That is different from user input though, cuz you cannot be certain that the input is right. If you called a function that you've written inside your own code, and it doesn't crash it, then why you need to check again? Hope that is helpful.
@caiolaytynher59942 жыл бұрын
@@maxthexpfarmer3957 yeah, that right there is user input, and that always have to be checked, but the case explained in the video was about input passed in to a function inside the code, in a way that can't even be looped through. That's a thing that I also realized recently.
@tom_stephen2 жыл бұрын
So, if I could try to reconceptualise the lesson, `assert` advantage over `raiseError` is that you can turn it off through non-debug mode, while the latter would still run? Did I understand this correctly? And is there any more advantages to `assert` over second way?
@FrankSiler2 жыл бұрын
Good overview. The only thing I would worry about is that you keep referencing JSON. Python does not have a JSON type per se- in fact, you're using dict, which is natural, but I worry that folks just learning will get confused about the types and data flow.
@Indently2 жыл бұрын
Thanks for the constructive criticism, I mess up the names a lot when recording, even if I know exactly the difference, someone without experience might get confused, you're right.
@yourhardworkgone2 жыл бұрын
try..except..finally be like: hey man assert dominance
@РоБ-с8л11 ай бұрын
So clear, thx
@johncarrprogramming62 Жыл бұрын
Great explanation!
@GooogleGoglee2 жыл бұрын
Grazie Fede! Molto utile!
@renataalmiratoth3110 Жыл бұрын
its good at all but in my screen the error is name not being defined so my project is not gonna work
@Jerrinth3glitch2 жыл бұрын
definitely awesome
@renataalmiratoth3110 Жыл бұрын
i mean how come u can add a variable witouth even defining it?!
@jyvben1520 Жыл бұрын
timestamp would be nice, where in the video is that variable ? are you complaining about the message "invalid JSON", he should have said dictionary, as the parameter said data is type dictionary.
@BijouBakson Жыл бұрын
Thank you
@Indently Жыл бұрын
Welcome!
@P1ra8e2 жыл бұрын
Great video!, Can you provide me on a road map to encode my python code and add a licensing system into it? Thanks in advance!
@grzegorzryznar51012 жыл бұрын
Nice tric with this OO :)
@AstronomyAstropy2 жыл бұрын
Hi Indently, thanks I learned lot of things and I made my own functions, Combine and Mix code here: import random rl = random.randint(3, 4) def mix(var1, var2): return var1 + var2 + rl def combine(strvl1, strvl2): return str(strvl1+strvl2) a = 12 b = 7 n = 'Hello, bro what's your name? ' l = 'I am the guy who loves Python ' print(f"mixed numbers result is: {mix(var1=a,var2=b)} , random mixer number is {rl}") print(f"combined text result is: {combine(strvl1=n,strvl2=l)}") how i share you the code I don't know
@1234minecraft56785 ай бұрын
i dont believe that the presented use case for json is all that usefull. in my opinion you should build a dataclass and parse the json right into it. they you will know whether the input data fulfills your expectations. you might want to use a library called dacite to parse the json object to the dataclass. this way, you already covered all of the mentioned asserts regarding jsonl. there is a great article about this, which is called "parse dont validate"
@xushenxin Жыл бұрын
can you talk less? I feel really don't like to here people talking, just the content.
@Indently Жыл бұрын
I'm scared to think of how you talk to strangers in real life mate 😅