473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Question about the "new" module

Hi,

I'm using Python 2.5 to develop a simple MVC framework based on
mod_python. To load my controllers, I create new modules using the
"new" module like this:

# ....
my_module = new.module("random_name")
my_module.__file__ = module_path

exec open(module_path, "r") in my_module.__dict__

then I initialize the class defined inside the module and call a method
of this class based on the HTTP request.

All works fine but the imports. If my module contains something like
this:

import something

class MyController(Controller):
def index(self):
something.do_something()

when MyController.index is called an exception is raised "NoneType
object has not attribute do_something". Why does it happen ? I have to
load the module in different ways (but I'd like to force the reload
every time the module is loaded) ?

Gabriele

Dec 29 '06 #1
2 1293

GabrieleI'm using Python 2.5 to develop a simple MVC framework based
Gabrieleon mod_python. To load my controllers, I create new modules
Gabrieleusing the "new" module like this:

Gabriele# ....
Gabrielemy_module = new.module("random_name")
Gabrielemy_module.__file__ = module_path
Gabrieleexec open(module_path, "r") in my_module.__dict__

Gabrielethen I initialize the class defined inside the module and call
Gabrielea method of this class based on the HTTP request.

Why use the new module? Why not call __import__() or execfile()? Details
on their use are here:

http://docs.python.org/dev/lib/built-in-funcs.html

Skip
Dec 29 '06 #2

sk**@pobox.com wrote:
GabrieleI'm using Python 2.5 to develop a simple MVC framework based
Gabrieleon mod_python. To load my controllers, I create new modules
Gabrieleusing the "new" module like this:

Gabriele# ....
Gabrielemy_module = new.module("random_name")
Gabrielemy_module.__file__ = module_path
Gabrieleexec open(module_path, "r") in my_module.__dict__

Gabrielethen I initialize the class defined inside the module and call
Gabrielea method of this class based on the HTTP request.

Why use the new module? Why not call __import__() or execfile()? Details
on their use are here:

http://docs.python.org/dev/lib/built-in-funcs.html
Or why not use mod_python.apache.import_module() from mod_python
itself. It is designed as a way of users importing specific modules,
including the capability for modules to be reloaded if they have been
changed. See:
http://www.dscpl.com.au/wiki/ModPyth...oduleImporting

as well as the mod_python documentation.

Is recommended though to use mod_python 3.3 as soon as you can though
if you want the module reloading to always work. You can find
descriptions of problems with the module reloading in older versions of
mod_python at:
http://www.dscpl.com.au/wiki/ModPyth...ortingIsBroken

Note that module importer in mod_python 3.3 has been enhanced some what
over prior versions in addition to fixing problems. An important new
feature is being able to load modules based on their path with modules
with same names in different directories being properly distinguished,
something which is quite useful where modules are used in web
applications to represent pages. You may want to look at documentation
for it at:
http://www.modpython.org/live/mod_py...pi-apmeth.html

Graham

Dec 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: z0mb1e_fr | last post by:
I am writing a script to change a router config. The config is long and the result is that the display stops with a "--more--". Normally we type return to go to a new line or the space bar to go...
2
by: Philipp | last post by:
Hi, I am quite sure this question has answered here already several times, but I haven't found the answer yet. Anyway, here is the question again: I've got libraries (*.so) that are built with...
18
by: Leslaw Bieniasz | last post by:
Cracow, 28.10.2004 Hello, I have a program that intensively allocates and deletes lots of relatively small objects, using "new" operator. The objects themselves are composed of smaller...
24
by: Rv5 | last post by:
Rookie c++ question, but Ive spent the last 5 years doing Java, where everytime I created an object I used new. In c++ I can create my objects without and its confusing me just a little. I have...
1
by: sven_c_t | last post by:
Hi! Probably a newbie question. I´ve been working a bit with the widget toolkit FLTK and I have been wondering why there is such a heavy use of the new operator, when it does not seem to be...
2
by: PengYu.UT | last post by:
Hi, I saw the following code: Composition *quick = new Composition(new SimpleCompositor); SimpleCompositor and Composition are both classes. My question is how to delete the newed...
4
by: Ben R. | last post by:
I'm curious about the differeng behavior of the "new" keyword when dealing with value versus object types. If I'm correct, when I do: dim x as integer There's no need for "new" to be called...
24
by: M O J O | last post by:
Hi, Instead of doing this.... Public Class Form1 Public Shared Sub CreateAndShow() Dim f As New Form1 f.Show() End Sub
30
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.