Hi,
I'm currently using boost::python:: import() to import Python modules,
so I'm not sure exactly which Python API function it is calling to
import these files. I posted to the Boost.Python mailing list with
this question and they said I'd probably get a better answer here, so
here it goes...
If I do the following:
using namespace boost::python;
import( "__main__" ).attr( "new_global " ) = 40.0f;
import( "__main__" ).attr( "another_global " ) = 100.0f:
Notice that I'm importing twice. What would be the performance
consequences of this? Do both import operations query the disk for the
module and load it into memory? Will the second call simply reference
a cached version of the module loaded at the first import() call?
Thanks. 2 2207
On Fri, 24 Oct 2008 12:23:18 -0700, Robert Dailey wrote:
Hi,
I'm currently using boost::python:: import() to import Python modules, so
I'm not sure exactly which Python API function it is calling to import
these files. I posted to the Boost.Python mailing list with this
question and they said I'd probably get a better answer here, so here it
goes...
If I do the following:
using namespace boost::python;
import( "__main__" ).attr( "new_global " ) = 40.0f; import( "__main__"
).attr( "another_global " ) = 100.0f:
Notice that I'm importing twice. What would be the performance
consequences of this? Do both import operations query the disk for the
module and load it into memory? Will the second call simply reference a
cached version of the module loaded at the first import() call?
Thanks.
I think it does not reload the module. Running python with verbose mode:
blah@blah-laptop:~$ python -v
(snip)
>>import xml
import xml # directory /usr/local/lib/python2.6/xml
# /usr/local/lib/python2.6/xml/__init__.pyc matches /usr/local/lib/
python2.6/xml/__init__.py
import xml # precompiled from /usr/local/lib/python2.6/xml/__init__.pyc
>>import xml
It's also mentioned in the docs: (paraphrased to clarify the points)
'''
The system maintains a table of modules that have been ...
initialized.... When a module name is found..., step (1) is finished. If
not, a search for a module ... . When ... found, it is loaded.
''' http://www.python.org/doc/2.5.2/ref/import.html
On Oct 24, 2:23*pm, Robert Dailey <rcdai...@gmail .comwrote:
Hi,
I'm currently using boost::python:: import() to import Python modules,
so I'm not sure exactly which Python API function it is calling to
import these files. I posted to the Boost.Python mailing list with
this question and they said I'd probably get a better answer here, so
here it goes...
If I do the following:
using namespace boost::python;
import( "__main__" ).attr( "new_global " ) = 40.0f;
import( "__main__" ).attr( "another_global " ) = 100.0f:
Notice that I'm importing twice. What would be the performance
consequences of this? Do both import operations query the disk for the
module and load it into memory? Will the second call simply reference
a cached version of the module loaded at the first import() call?
Thanks.
Docs:
Note
For efficiency reasons, each module is only imported once per
interpreter session. Therefore, if you change your modules, you must
restart the interpreter – or, if it’s just one module you want to test
interactively, use reload(), e.g. reload(modulena me). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: OKB (not okblacke) |
last post by:
I'm fooling around with some MUD server code, and I want to add a
"reload" command that will let MUD wizards reload the server modules,
so that changes to the MUD parser and such can be effected without
having to shut down and restart the server.
Now, what I want to do at the top of my main module, instead of
just "import somemodule", is something like this:
try:
reload(somemodule)
|
by: Active8 |
last post by:
I did this once and can't remember how <blush> so I read the
reportlab user guid. It says to unzip the reportlab archive - this
is on w2k, BTW, with Python23 - to a directory and make a file
called reportlab.pth in the pythod dir. The only line in this file
is supposed to be the path to the reportlib dir.
Then I'm instructed to open the ... ok I'll close and reopen ... the
python cmd line interpreter and type
import reportlab
|
by: qwweeeit |
last post by:
The pythonic way of programming requires, as far as I know, to spread a
big application in plenty of more manageable scripts, using import or
from ... import to connect the various modules.
In some cases there is a further complication: module importing through
an indirect mechanism, like: exec "from " + xxx + " import *".
A part the fact that I have not understood the "real" difference
between import and from ... import (or also from......
|
by: Brian K. |
last post by:
I am trying to split up and secure a database that we've been using on
a network for a few years, following the procedure listed in Q304932
from microsoft.
I create a new blank database for the front end, and am able to import
tables and link from the backend. Queries come in ok too. When I
tried to import Modules, forms, and reports, most of them failed with
the error: "File Not Found:...
|
by: T. Crane |
last post by:
Hi,
When troubleshooting code that's saved in a text file, I often find that I
want to make a change to it, re-save it, then reimport it. However, just
typing
import myTestCode
doesn't always seem to import the newer version. Is it supposed to? I find
that right now I often have to close my iPython window, then reopen it and
| |
by: rbygscrsepda |
last post by:
Hi, I'm a newbie at Python. :) Right now it's not letting me import *
from any relative package name--i.e., a name that starts with a dot.
For instance, none of the following work:
from . import *
from .sibiling import *
from .. import *
from ..parent_sibling import *
....and so on. The same error occurs:
|
by: rkmr.em |
last post by:
Hi
I have a function data, that I need to import from a file
data, in the directory data
If I do this from python interactive shell (linux fedora core 8) from
dir /home/mark it works fine:
cwd = data
os.chdir(cwd)
print os.getcwd()
|
by: Hussein B |
last post by:
Hey,
Suppose I have a Python application consists of many modules (lets say
it is a Django application).
If all the modules files are importing sys module, how many times the
sys module will be compiled and executed?
Only once (the first time the PVM locates, compiles and executes the
sys module)? or once for each module importing sys?
Thanks.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |