473,545 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("ran dom_name")
my_module.__fil e__ = module_path

exec open(module_pat h, "r") in my_module.__dic t__

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(Co ntroller):
def index(self):
something.do_so mething()

when MyController.in dex 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 1303

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_modu le = new.module("ran dom_name")
Gabrielemy_modu le.__file__ = module_path
Gabrieleexec open(module_pat h, "r") in my_module.__dic t__

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_modu le = new.module("ran dom_name")
Gabrielemy_modu le.__file__ = module_path
Gabrieleexec open(module_pat h, "r") in my_module.__dic t__

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.apac he.import_modul e() 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
4912
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 to scroll down a page. So far I failed to simulate this behaviour with expect. The program performs a loop with:
2
1980
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 gcc 2.95.2. The gcc version, I've installed on my computer, is 3.xx and I don't have the source files of the libraries. Can I link those libraries...
18
8022
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 objects, again allocated using "new". From my tests I deduce that a considerable part of the computational time is spent on the memory allocation, which...
24
2831
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 a class called polynomial. Its a nothing little class right now, with just int variables, a basic container class. Im using it as I go through...
1
2572
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 nessesary (at least to me). What follows is an example taken from the FLTK tutorial: ------------- #include <FL/Fl.H> #include <FL/Fl_Window.H>
2
1244
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 SimpleCompositor object.
4
2619
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 since this "value" type is all set to go. Is this because value types are stored on the stack so the memory initialization is already taken care of? ...
24
2801
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
3791
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 the end of the app for example: class test { public: int x;
0
7473
marktang
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...
0
7813
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7431
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...
0
7761
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 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...
0
5976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5337
isladogs
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...
0
4949
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...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.