<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Some Annoyances' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Some Annoyances' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Tue, 18 Jun 2013 14:58:30 -0700</pubDate>
    <lastBuildDate>Tue, 18 Jun 2013 14:58:31 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Some Annoyances</title>
      <link>http://www.programmersheaven.com/mb/python/278803/278803/some-annoyances/</link>
      <description>Hey, I spent some time and setup my local iis web server to facilitate the creation of ASP pages via Python.&lt;br /&gt;
&lt;br /&gt;
First off, it took me a while to integrate the concept of packages.&lt;br /&gt;
&lt;br /&gt;
I find myself having to place this code at the top of my file ...&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
&amp;lt;%
import sys

# Setup Environment Path ######
path = "c:\development"

try:
	sys.path.index(path)

except ValueError:
	sys.path.append(path)

###############################
%&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
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 B: IIS loses any information you append to the path when you restart the server process.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
from cls import ASP
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/278803/278803/some-annoyances/</guid>
      <pubDate>Sat, 23 Oct 2004 19:33:25 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Some Annoyances</title>
      <link>http://www.programmersheaven.com/mb/python/278803/278943/re-some-annoyances/#278943</link>
      <description>: Hey, I spent some time and setup my local iis web server to facilitate the creation of ASP pages via Python.&lt;br /&gt;
: &lt;br /&gt;
: First off, it took me a while to integrate the concept of packages.&lt;br /&gt;
: &lt;br /&gt;
: I find myself having to place this code at the top of my file ...&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: &amp;lt;%
: import sys
: 
: # Setup Environment Path ######
: path = "c:\development"
: 
: try:
: 	sys.path.index(path)
: 
: except ValueError:
: 	sys.path.append(path)
: 
: ###############################
: %&amp;gt;
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: 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 &lt;br /&gt;
&lt;br /&gt;
Can't help you here other that to suggest some kind of .ini file with an initialization function.&lt;br /&gt;
&lt;br /&gt;
: B: IIS loses any information you append to the path when you restart the server process.&lt;br /&gt;
&lt;br /&gt;
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?&lt;br /&gt;
&lt;br /&gt;
: 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:&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: from cls import ASP
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: 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.&lt;br /&gt;
: &lt;br /&gt;
: 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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
import cls.ASP as ASP&lt;br /&gt;
ASP = reload(cls.ASP)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;em&gt;&lt;span style="color: Blue;"&gt;&lt;span style="color: Red;"&gt;i&lt;/span&gt;nfidel&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
$ select * from users where clue &amp;gt; 0
no rows returned
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/278803/278943/re-some-annoyances/#278943</guid>
      <pubDate>Mon, 25 Oct 2004 08:25:29 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Some Annoyances</title>
      <link>http://www.programmersheaven.com/mb/python/278803/278958/re-some-annoyances/#278958</link>
      <description>: : Hey, I spent some time and setup my local iis web server to facilitate the creation of ASP pages via Python.&lt;br /&gt;
: : &lt;br /&gt;
: : First off, it took me a while to integrate the concept of packages.&lt;br /&gt;
: : &lt;br /&gt;
: : I find myself having to place this code at the top of my file ...&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;pre class="sourcecode"&gt;
: : &amp;lt;%
: : import sys
: : 
: : # Setup Environment Path ######
: : path = "c:\development"
: : 
: : try:
: : 	sys.path.index(path)
: : 
: : except ValueError:
: : 	sys.path.append(path)
: : 
: : ###############################
: : %&amp;gt;
: : &lt;/pre&gt;&lt;br /&gt;
: : &lt;br /&gt;
: : 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 &lt;br /&gt;
: &lt;br /&gt;
: Can't help you here other that to suggest some kind of .ini file with an initialization function.&lt;br /&gt;
: &lt;br /&gt;
: : B: IIS loses any information you append to the path when you restart the server process.&lt;br /&gt;
: &lt;br /&gt;
: 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?&lt;br /&gt;
: &lt;br /&gt;
: : 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:&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;pre class="sourcecode"&gt;
: : from cls import ASP
: : &lt;/pre&gt;&lt;br /&gt;
: : &lt;br /&gt;
: : 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.&lt;br /&gt;
: : &lt;br /&gt;
: : 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.&lt;br /&gt;
: &lt;br /&gt;
: 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:&lt;br /&gt;
: &lt;br /&gt;
: import cls.ASP as ASP&lt;br /&gt;
: ASP = reload(cls.ASP)&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;span style="font-size: large;"&gt;&lt;em&gt;&lt;span style="color: Blue;"&gt;&lt;span style="color: Red;"&gt;i&lt;/span&gt;nfidel&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: $ select * from users where clue &amp;gt; 0
: no rows returned
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
-You Wrote-&lt;br /&gt;
"Is there a way to hook the server process startup to initialize your sys.path there?"&lt;br /&gt;
&lt;br /&gt;
Well there is a file in all asp projects called global.asa. There is an Application_Start event in this file (which fires at the beginning of the web process creation), which I suppose could house the code. I'll have to see if python can hook into it. The solution I used so far, so that I am not rewritting the code, is to use an include statement ...&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
&amp;lt;!-- #include file="init.asp" --&amp;gt;

&amp;lt;%
# Other Python Code Here
%&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/278803/278958/re-some-annoyances/#278958</guid>
      <pubDate>Mon, 25 Oct 2004 09:14:49 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>