![Carberra](/img/default-banner.jpg)
- 417
- 2 358 111
Carberra
United Kingdom
Приєднався 13 лип 2019
Welcome to Carberra!
Regardless of whether you're a budding programmer looking to make your idea a reality, or an avid computer user expanding your knowledge base, this is the place for you. I mainly focus on the world of Python, but occasionally stroll outside the Pythonosphere when I feel like getting a little CrAzY.
When I started this channel, I was in my second year of my Computer Science degree. I have since graduated with a Master's, and now make content for those hoping to traverse a similar path!
Below is a series of links to other places you can find me. I hope to see you around somewhere!
Regardless of whether you're a budding programmer looking to make your idea a reality, or an avid computer user expanding your knowledge base, this is the place for you. I mainly focus on the world of Python, but occasionally stroll outside the Pythonosphere when I feel like getting a little CrAzY.
When I started this channel, I was in my second year of my Computer Science degree. I have since graduated with a Master's, and now make content for those hoping to traverse a similar path!
Below is a series of links to other places you can find me. I hope to see you around somewhere!
The CORRECT way to work with temporary files in Python
Working with temporary files can be a must in certain situations, but are you working with them correctly? If not, you're opening yourself up to security vulnerabilities. In this video, we'll be using the `tempfile` module to create temporary files easily and securely!
00:00 - Intro
01:01 - Creating a named temporary file [1]
04:13 - Creating a temporary directory [2]
04:57 - Creating a temp file within a temp directory
06:05 - Other interfaces in the tempfile module
07:25 - Using this with a Pytest fixture [3-4]
[1] docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
[2] docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory
[3] alembic.sqlalchemy.org/en/latest
[4] docs.pytest.org/en/stable
-
If you want to see more of me, join my Discord server!
discord.gg/5vVgQpK
I get a lot of people asking, so here's my setup!
• Visual Studio Code: ua-cam.com/video/PBQspYkkksU/v-deo.html
• Terminal: ua-cam.com/video/4RuGK3w6Mbs/v-deo.html
• Desk/recording gear: kit.co/Carberra
• PC build: uk.pcpartpicker.com/list/TmzGYN
Affiliations (I may earn a commission):
• Codecrafters -- 40% off any plan: app.codecrafters.io/join?via=parafoxia
• Keeper Password Manager -- 30% off your first year: keeper.io/r/EX4FB1C
-
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #howto
00:00 - Intro
01:01 - Creating a named temporary file [1]
04:13 - Creating a temporary directory [2]
04:57 - Creating a temp file within a temp directory
06:05 - Other interfaces in the tempfile module
07:25 - Using this with a Pytest fixture [3-4]
[1] docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
[2] docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory
[3] alembic.sqlalchemy.org/en/latest
[4] docs.pytest.org/en/stable
-
If you want to see more of me, join my Discord server!
discord.gg/5vVgQpK
I get a lot of people asking, so here's my setup!
• Visual Studio Code: ua-cam.com/video/PBQspYkkksU/v-deo.html
• Terminal: ua-cam.com/video/4RuGK3w6Mbs/v-deo.html
• Desk/recording gear: kit.co/Carberra
• PC build: uk.pcpartpicker.com/list/TmzGYN
Affiliations (I may earn a commission):
• Codecrafters -- 40% off any plan: app.codecrafters.io/join?via=parafoxia
• Keeper Password Manager -- 30% off your first year: keeper.io/r/EX4FB1C
-
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #howto
Переглядів: 2 864
Відео
Capturing a function's LOCAL variables?!
Переглядів 3,5 тис.21 годину тому
Trust me, this does actually have a use case! You would ordinarily not be able to access the local variables of a function unless you returned them, but this function captures the internal state of the decorated function at return time, allowing you to verify it's what it should be! Very neat, but definitely a hack! 00:00 - Intro [1] 01:06 - Demonstration [2] 03:13 - Implementing the capture fu...
Are descriptors the most MISUNDERSTOOD part of Python?
Переглядів 10 тис.14 днів тому
Descriptors, in many conversations I've had with people, are typically considered one of the most difficult parts of Python. I would posit however that they're moreso misunderstood rather than difficult once you get your head around them, there's not much to remember! They're also an incredibly powerful and important concept, as huge swathes of the Python standard library is written using them,...
5 SIMPLE Pytest tricks to improve your tests
Переглядів 3,1 тис.21 день тому
In production code, the tests are often as important as the code, if not more. Without proper testing, how will you know if your code will ever work in the wild? In this video, I share five top tips to improve your tests and to make sure they're working properly! 00:00 - Intro 00:41 - Context [1] 01:33 - Parametrization [2] 03:22 - Finding edge cases w/ Hypothesis [3] 05:41 - Tracking coverage ...
Numba makes your code FASTER with ONE decorator
Переглядів 4,1 тис.28 днів тому
Try Keeper Password Manager free for 30 days, then get 30% off when you upgrade using the code CARBERRA30: www.keepersecurity.com/personal.html - There has been plenty of discussion around Python's new JIT since it dropped, but did you know there are other ways of getting a JIT into Python? One of the simpler ways is by using Numba, which allows you to JIT functions by using a single decorator!...
I baked the Hello World cake (but everything went wrong)
Переглядів 487Місяць тому
I baked the Hello World cake (but everything went wrong)
Python's contextlib is a HIDDEN GEM
Переглядів 11 тис.2 місяці тому
Python's contextlib is a HIDDEN GEM
Partial functions in Python are SUPER NEAT
Переглядів 4,5 тис.2 місяці тому
Partial functions in Python are SUPER NEAT
SIMPLIFY your code with decorators (+ typing)
Переглядів 3,8 тис.2 місяці тому
SIMPLIFY your code with decorators ( typing)
Implementing OAuth 2.0 from SCRATCH
Переглядів 1,9 тис.3 місяці тому
Implementing OAuth 2.0 from SCRATCH
I tried a FREE Copilot alternative
Переглядів 2,3 тис.3 місяці тому
I tried a FREE Copilot alternative
HYBRID callables in Python?! - Jankfest
Переглядів 1,7 тис.3 місяці тому
HYBRID callables in Python?! - Jankfest
Using Redis/Redict/Valkey in Python (2024 tutorial)
Переглядів 2 тис.3 місяці тому
Using Redis/Redict/Valkey in Python (2024 tutorial)
My Visual Studio Code setup! (2024)
Переглядів 2,4 тис.4 місяці тому
My Visual Studio Code setup! (2024)
Wait, you CAN use braces with Python?!
Переглядів 3,3 тис.4 місяці тому
Wait, you CAN use braces with Python?!
The history of Visual Studio Code's WORST theme
Переглядів 47 тис.4 місяці тому
The history of Visual Studio Code's WORST theme
Is Python 4 ON THE WAY?! (April Fools)
Переглядів 3,2 тис.4 місяці тому
Is Python 4 ON THE WAY?! (April Fools)
Creating, renaming, and deleting branches - Git Good
Переглядів 4574 місяці тому
Creating, renaming, and deleting branches - Git Good
Ignoring files with .gitignore - Git Good
Переглядів 5825 місяців тому
Ignoring files with .gitignore - Git Good
Create an API in 20 MINUTES with FastAPI (2024 tutorial)
Переглядів 2 тис.5 місяців тому
Create an API in 20 MINUTES with FastAPI (2024 tutorial)
Pushing to and pulling from the remote - Git Good
Переглядів 4885 місяців тому
Pushing to and pulling from the remote - Git Good
Just because you can do something doesn’t mean you should. If you need to index an iterator, you shouldn’t be using one
Why not just index using enumerate?
You could do that, but you would need to iterate over the iterable yourself. Using islice, that much is taken care of for you.
Thank you 😊
"Python is a very simple language!" Sure! ;-)
len(text.split()) ??
Harris Scott Williams Donna Lopez Karen
Thanks! Merits over PyTest's built in tmp, tmpdir builtin fixtures?
Flush writes a fille’s buffers, emptying (flushing) the buffer. Normally you you would only do that to meet specific needs, such as capturing data that can’t be readily duplicated. Files are buffered at three levels: by Python, the system, and lastly internally on modern drives. Flushing a file in Python does NOT also flush the system or drive buffers. You can flush a file’s system buffers with the caveats that some circumstances could prevent that from occurring, and it doesn’t flush the drive’s internal buffers. Furthermore, flushing a file’s system buffers can be “costly”, because your script must wait for a physical write before continuing (worse on hard drives than SSDs). This is what the documentation says: “If you're starting with a buffered Python file object f, first do f. flush(), and then do os. sync(f. fileno()), to ensure that all internal buffers associated with fare written to disk.”
what did you need to use descriptors for in the real world?
I talk about it in my video on descriptors. It's basically a type-safe, lazy-evaluated config class.
unittest has it built-in.
1:02 "we dont have to import anything" then immediately imports temp file (i think you meant to say install anything but still funny)
Pahaha, managed to miss that in recording AND editing 😅
python --version doesn't detect it
docs on w+b: "The mode parameter defaults to 'w+b' so that the file created can be read and written without being closed. Binary mode is used so that it behaves consistently on all platforms without regard for the data that is stored.". keep up the good work!
Thanks for that explanation!
Thank you 😊
Please update the title to indicate that you are not rebuilding Sqlite but are just doing a code crafter exercise-and that, too, not completely! This is a useless video! Have some respect for yourself as a developer!
max **2 = sqrt(max). Way prettier
Your changing the return type so you’d still need to update some code, it might be better to add a flag that defaults to False and print the locals when it’s true
Why are you literally java-ing python😭😭😭
Shot in the dark here.. Does Svk say you anything 😂😂
If you want the total, you can use the total method instead of summing over the values.
Great video. The Validator example is immediately useful.
you can have `__init__(self, type_ :Type : int, f_val : Callable|None = None)` on the descriptor class to make it more generic. i.e the descriptor can get all sorts of arguments telling it how to behave. Knowing how to use that makes even more useful.
If summing the word count only, don't use Counter
The annotation improvements are very welcome, been avoiding upgrading the annotation support in odin because of the strings. The annotation parser is already fairly complex.
Amazing, I have never seen these in the wild. Couple of times I've used properties in convoluted ways where this would be better, config validation is a good example. I just want to be pedantic and nitpick that "value is not negative" is distinct from "value is positive" because the latter is ambiguous on whether 0 is included.
Very true, thanks for pointing that out! "Value just be greater than 0" is probably least ambiguous, rids the need for positive and negative completely.
I can't believe I've gone so long without learning about descriptiors. They do make a few things I've seen make sense. @Carberra a video on generics would be appreciated
Yeah same here! I only learned them in anger recently myself haha. A genetics video is planned!
If you want to cache an environ lookup, I’d try to get rid of `self` and maybe even cls. Handing it off to a static/class method would seem better. But yes descriptors are pretty awesome. The intro verbiage about them is scary and makes them seem complicated. They’re not. “Descriptor Guide” by Hettinger covers 90% of use cases in 2 easy pages.
Seeing this makes me glad that I keep things simple. This python reminds me of C#, which is odd.
Wow this is really useful for testing closure functions! Thanks for the video!
looks like a "hack", feels like a "hack", it's a "hack" :P naaaa, I'll skip this 🤪
@Carberra I don't expect I'll ever use this just this way, but I'm very glad to have seen you walk through it. Seeing how to use a simply written profiler to react to events and access frames is a very interesting capability I'm not at all sure I would have come across otherwise :) It definitely sheds some light on how profilers and debuggers must work under the hood. Thanks for doing this! :)
Limitless python
Aggh! You try to speak everything in one breath and start the sentence louder and become so quiter in the end !!! so annoying!!!!!!!!
@@khanra17 hey man, there are like, way more constructive ways to give this feedback. This is extremely rude
Also, I've seen you leave this same comment on multiple of his videos. That is, like, extremely weird lol
@@austinnar4494 You're more on the ball than I am lmao, I didn't even realise!
I find the way he explains concepts very clear compared to many other developer UA-camrs actually.
If you ever need something like this, you must be doing something wrong in your code and it's time to rethink the problem
I mean, I did say that in the video. You would only want to use this for testing.
@@Carberra Its a really cool concept to see under the hood of Python, but I still think your doing something very wrong if you need to use this in production. If your function doesn't return anything and doesn't modify any outside state (an object passed in/global state) then what use does the function have? If your function modifies some global state that prevents you from testing normally then you're doing something wrong and need to refactor to pass in the objects you will modify. And finally if you are modifying an object passed in then you should be able to read the object's state from outside the function after it has run in the test. I really love your videos and the way you explain concepts, but I do think its a bit silly to say this has legitimate uses.
@@carrotmanmatt ok, we get it. You don’t like it. Don’t use it. But for those of us who have a different viewpoint, this is a nice hacky thing to know about, if not to use. What if you have a function that has the signature you want, but it is not working? What if it is not your function and you want to observe its state? What if you keep your core simple and fix whatever weird bug is at hand, without introducing the permanent over-engineering you seem to prescribe, then yank it right back out? What if this technique rings a bell 2 years down when you are faced with a seemingly unrelated problem? Carberra only said not to use for real like 5 times.
@carrotmanmatt I only came up with this because I had an actual use case for it! At work, we have a function that sets up the Sentry SDK. This function takes in a number of configuration options, but calls sentry_sdk.init, then returns None. It also contains a closure function (enclosed function?) that is then passed to the init function. There's no sense in refactoring as the function never needs to return anything, and the enclosed function never needs to be run by anything else. This decorator allowed me to test the internal state and make sure all the internal configuration bits and pieces were functioning properly, and it also allowed me to rip the enclosed function out and test that to make sure it worked properly (thankfully, I confirmed it all already worked as expected). While you shouldn't use it in production code, using it to _test_ production code without making unnecessary modifications that affect UX is a valid use case for it. (Appreciate your kind words about the channel generally as well! 😄)
@@Carberra Still seems like a fairly odd use tbh. I feel like the cleaner solution would be to mock sentry_sdk.init.
The reason f_locals needs to be nonlocal is because the variable *name* is being assigned to. You can always access variables from the enclosing scope, but you cannot assign a new value to that name. You can, however, mutate variables without marking them nonlocal; if instead, you mutated that f_locals dict by using f_locals.update you could have omitted the nonlocal tag
Yeah that's what I was _trying_ to say and failed miserably lmao, thanks for that explanation!
@@Carberra haha np, and yeah I assumed you knew why, mostly just a hard thing to explain on the fly
Yeah it deffo can be haha. This is why I'm glad viewers leave comments like this, always good to have corrections/additional context! For myself as well as everyone else.
Yea, before the nonlocal keyword existed this was annoying. I typically did something like val = [None], then inside the function: val[0] = thing_I_want, and then outside refer to val[0] to get the value back. nonlocal makes this so much easier.
1:14 Not even close! :)) error-TOSSED-hen-ease Stressed syllable in caps. Not phenetics, pronounce as English words.
Fun fact: Eratosthenes was the first person to measure the size of the planet and got it to within 10% of the actual answer. Although we aren't totally certain on the length of the units he was using, the presumption is the Oympic Stade which is accurate. Regardless, the approach was sound. He put an upright stick in Alexandria at noon during solstice when the was no shadow and another in Syene at the same time where there was a shadow. Then by knowing the distance between the two spots and the angle of the shadow in Syene he could calculate the circumference of the planet with some basic trig. The dude rocked.
Absolute rip @ my pronunciation lmao. Pretty cool fact though! Guy seemed like he did quite a lot, amazed I'd never heard of him before now!
@@Carberra Was a cool dude. Chief librarian to Great Library of Alexandria. Worked out the Earth's axial tilt. Made the first world map. He invented the field of chronology, estimating dates between events like the battles and whatnot. He found the distance to the sun and moon - I'm not sure off hand how accurate he got with those. Rather amusingly and famously, there's an ancient text from 190BC or thereabouts mocking him for always only being second best at everything.
Bloody hell, we have a lot to thank him for! I guess as far as that text is concerned at least, he also invented how to a jack of all trades, master at none 😅
@@Carberra Yeah, I'm filing his CV under "rubbish at python" and moving on. ;) Been a long time since I watched it but I'm pretty sure Carl Sagan covered him in Cosmos.