<div class="gmail_quote">On Mon, Jan 11, 2010 at 11:26 AM, Dave Angel <span dir="ltr"><<a href="mailto:davea@ieee.org">davea@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">Victor Subervi wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Sun, Jan 10, 2010 at 3:09 PM, MRAB <<a href="mailto:python@mrabarnett.plus.com" target="_blank">python@mrabarnett.plus.com</a>> wrote:<br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
browser = form.getfirst('browser', 'all')<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
except:<br>
browser = headers()<br>
<br>
try:<br>
<br>
</blockquote>
A bare except, and if an exception _does_ occur, they'll be a NameError<br>
because 'headers' isn't defined.<br>
<br>
<slap with large halibut/><br>
<br>
</blockquote>
<br>
<br>
Oh, not the large halibut again! (I will be cleaning them up ;)<br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
os.chdir('%s/..' % cwd)<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
sys.path.append(os.getcwd())<br>
from templateFrame import top, bottom<br>
os.chdir(cwd)<br>
<br>
Why doesn't it work if I move the bottom imports to the top? The form<br>
values get lost, even though I chdir to cwd.<br>
<br>
I try to avoid changing the directory.<br>
<br>
</blockquote></blockquote>
<br>
It's either that or copying them all over to the other dir, which is even<br>
worse, since I don't want to maintain identical scripts.<br>
Thanks,<br>
beno<br>
<br>
<br>
</blockquote></div></div>
You miss the point. Rather than doing chdir to change the current directory, in order to use getcwd in your sys.path.append, calculate the appropriate directory yourself, and use it directly, without changing the current directory. Brute force would be something like (untested):<br>
<br>
sys.path.append(os.path.join(os.getcwd(), ".."))<br>
<br>
You could get trickier by stripping off the last node of the directory path, but it shouldn't be necessary.<br>
<br>
Incidentally, I'd tend to use os.path.dirname( __main__.file ) rather than os.getcwd(). That way it'd work even if current directory was changed by something else. In other words (untested):<br>
<br>
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))<br>
<br>
this will add the parent directory of the current module to the os.path.<br></blockquote><div><br>Well put. Thanks!<br>beno<br>
</div></div>