Python

Moderators: None (Apply to moderate this forum)
Number of threads: 474
Number of posts: 1166

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: Some Annoyances Posted by infidel on 25 Oct 2004 at 8:25 AM
: Hey, I spent some time and setup my local iis web server to facilitate the creation of ASP pages via Python.
:
: First off, it took me a while to integrate the concept of packages.
:
: I find myself having to place this code at the top of my file ...
:
:
: <%
: import sys
: 
: # Setup Environment Path ######
: path = "c:\development"
: 
: try:
: 	sys.path.index(path)
: 
: except ValueError:
: 	sys.path.append(path)
: 
: ###############################
: %>
: 

:
: Because A: I do not feel like setting the PYTHONPATH environment variable (because I would have to literally modify it for each web app that uses python) and

Can't help you here other that to suggest some kind of .ini file with an initialization function.

: B: IIS loses any information you append to the path when you restart the server process.

That's because when you "import sys" you are just loading the sys module into memory. The appending of paths to sys.path is just adding another item to the in-memory list. I'm sure you knew that. Is there a way to hook the server process startup to initialize your sys.path there?

: The other annoyance I came across involves some sort of mysterious caching. When I set up a module called ASP.py in a folder called cls, I can easily import it like so:
:
:
: from cls import ASP
: 

:
: Initially calling functions from this module ran fine, but say I removed a function or modify a function; the changes do not reflect. I literally have to kill the web server process, which usually means restarting iis.
:
: I am wondering if this kind of behavior exists in python programs that are not strapped to a web server process? I can not help wondering if there is someway to invalidate a python module, so that the scripting engine must recompile it.

That's the normal way Python handles modules. The interpreter will only load a module the first time it encounters an "import" statement. The reason is to avoid recursive reference loops. If you "import A" and A does "import B" but B does "import A" then you can see the problem. You can force the interpreter to reload a module using the reload() function:

import cls.ASP as ASP
ASP = reload(cls.ASP)



infidel

$ select * from users where clue > 0
no rows returned


Thread Tree
iwilld0it Some Annoyances on 23 Oct 2004 at 7:33 PM
infidel Re: Some Annoyances on 25 Oct 2004 at 8:25 AM
iwilld0it Re: Some Annoyances on 25 Oct 2004 at 9:14 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.