![]() Gameguard rev1512 unpacked modules python code#But sometimes you may want to actually reload this in, especially if you’ve maybe changed the code and you don’t want to restart the interpreter. Let me show you what that looks like.Ġ2:01 One of the choices is to go ahead and restart the interpreter, which is something that you’ve done a lot now, exiting out and restarting again. ![]() For one, you can restart the interpreter, and you’ve practiced that multiple times.Ġ1:52 Or there is a module that you can import called importlib, and it includes a function called reload(). Well, what if you needed to reload this?Ġ1:40 Is it possible to reload a module? If you really needed to, there’s two choices here. It only is going to import it once and it doesn’t need to re-import it again, so it’s sort of an efficiency thing. So, why would it not rerun this code? Well, that’s the thing. Gameguard rev1512 unpacked modules python mod#Now what if you import mod again inside the same session?Ġ1:19 Nothing happens. Initially as it imported mod, it went ahead and did the print() statement inside there using the f-string, and inside here mod.a is available. ![]() Okay, down here in the terminal, what happens if I start the REPL and import mod?Ġ1:06 Well, you can see it here. In fact, modify it a little bit and use an f-string.Ġ0:52 And that can show that every time that this module is imported, it would print this out, right? So, save this extra line. Just keep a simple print() statement for printing a out. That’s usually okay.Ġ0:33 Let me have you take a look at that.Ġ0:36 Go ahead and reopen mod.py, and inside of it I’m going to have you go ahead and clear out this if _name_ = '_main_'. Usually the executable statements are only for initialization, and it makes sense that these statements will only be executed the first time a module is imported. Even if you were to try, a module is only loaded once per interpreter session, and that’s going to work fine for functions and class definitions and importing all those objects initially.Ġ0:17 But sometimes modules can contain executable statements as well. ![]() Up to now, you’ve been simply importing a module once. 00:00 In this video, I’ll show you about reloading a module. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |