Hi, I'm using import hooks according to PEP 302, in order to load
python files from a game PAK file. The game is C++ using embedded and
extended Python (v2.33) and Boost. The importing works fine, but
after modules are imported I can't reload them. I've tried
'reload(foo)' and 'PyImport_Reloa dModule(pModPtr )', but both return
'ImportError: No module named foo'.
Is it safe to assume that reload doesn't respect the import hook?
That seems like a problem. Is there any work-around?
thanks
Here is my hook object code:
class myImportHandler :
def find_module(sel f, fullname, path=None):
return self # returns the loader object
def _get_code(self, fullname): # load code from game PAK
if (fullname in sys.builtin_mod ule_names):
return False,None
codeString = loadImportModul e(fullname) # CALLING C++ FUNCTION
bIsPackage = False # not using PACKAGES
if len(codeString) :
codeString2 = codeString.repl ace('\\r\','\')
code = compile(codeStr ing2, fullname, 'exec')
else:
code=None
return bIsPackage,code
def normal_import(s elf, fullname): # for built-ins
file,pathname,d esc=imp.find_mo dule(fullname)
return imp.load_module (fullname,file, pathname,desc)
def load_module(sel f, fullname):
try:
mod = sys.modules[fullname] # check if module is
already loaded in sys.module?
except KeyError:
ispkg, code = self._get_code( fullname)
if code==None: # failed importing from game
PAK
return self.normal_imp ort(fullname)
mod = imp.new_module( fullname) # create new module
sys.modules[fullname] = mod
mod.__file__ = '<%s>' % self.__class__. __name__
mod.__loader__ = self
if ispkg:
mod.__path__ = []
exec code in mod.__dict__
return mod 0 1331 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ellinghaus, Lance |
last post by:
> > Other surprises: Deprecating reload()
>Reload doesn't work the way most people think
>it does: if you've got any references to the old module,
>they stay around. They aren't replaced.
>It was a good idea, but the implementation simply
>doesn't do what the idea promises.
I agree that it does not really work as most people think it does, but how
|
by: Carlos Ribeiro |
last post by:
I am looking for information on packages & import hooks, including
simple examples on how to implement a simple import hook. Quick
googling turns out some documents, such as:
-- PEP 302:
http://www.python.org/peps/pep-0302.html
-- What's new on Python 2.3:
http://www.python.org/doc/2.3.4/whatsnew/section-pep302.html
|
by: Steve Holden |
last post by:
This is even stranger: it makes it if I import the module a second time:
import dbimp as dbimp
import sys
if __name__ == "__main__":
dbimp.install()
#k = sys.modules.keys()
#k.sort()
#for kk in k:
|
by: Lonnie Princehouse |
last post by:
So, it turns out that reload() fails if the module being reloaded isn't
in sys.path.
Maybe it could fall back to module.__file__ if the module isn't found
in sys.path??
.... or reload could just take an optional path parameter...
Or perhaps I'm the only one who thinks this is silly:
>>> my_module = imp.load_module(module_name, *imp.find_module(module_name,path))
|
by: Shane Hathaway |
last post by:
Here's a heretical idea.
I'd like a way to import modules at the point where I need the
functionality, rather than remember to import ahead of time. This might
eliminate a step in my coding process. Currently, my process is I
change code and later scan my changes to make matching changes to the
import statements. The scan step is error prone and time consuming.
By importing inline, I'd be able to change code without the extra scan...
| |
by: John Salerno |
last post by:
I understand that after you import something once, you can reload it to
pick up new changes. But does reload work with from statements? I tried
this:
from X import *
and then did my testing. I changed X and tried to reload it, but that
didn't seem to work. I figure the reason is because the module itself
doesn't exist as an object, only its names do. But I couldn't figure out
how to pick up my new changes at this point. I think...
|
by: alf |
last post by:
Hi,
wonder if in the python I could treat modules imorts like classes
instances. It means I could import it twice or more times under
different names.
--
alfz1
|
by: bernhard.voigt |
last post by:
Hey!
I'm using ipython as my python shell and often run scripts with the
magic command %run:
In : %run script.py
If modules are loaded within the script these are not reloaded when I
rerun the script. Hence, when I changed some of the modules loaded, I
have to call
|
by: Patrick C |
last post by:
Someone suggested I use reload when trying to reopen a script i've written (the suggestion was made in response to the problem ive reposted below)
however when i do reload(modolename) i only get this...
>>> reload(eps)
<module 'eps' from 'eps.pyc'>
i know this is incredibly amateur to say, but the person who suggested it had their reload bolded and in color, as if it was recognized function such as import. Reload didn't do that for me....
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |