Yes, Python is dynamic, but my server farm, in this era of big business screwing the client and cutting all services and customer support, uses such crappy hardware that all normal code breaks, so I am forced to find work-arounds. Here is more complete code:<br>
<br>ourFile = string.split(__file__, "/")<br>p = ourFile[len(ourFile) - 1]<br>p = p[: - 9]<br>site = ourFile[4]<br>bitsFile = p + ".bits"<br>bitties = 0<br>
bits = []<br>
<br>Above, I define a bits file with bits of code that the broken python interpreter will not evaluate with normal text, so must be separated into its own file and called line by line and blended with separated files that quote only text. Pain in the hind end ;)<br>
<br>try:<br>  file = open(bitsFile, "r")<br>  for line in file:<br>    if len(line) > 2:<br>      bits.append(line)<br>      bitties += 1<br>except:<br>  pass<br>x = 1<br>while x <= bitties:<br>  file = open(p + str(x) + ".txt")<br>
  for line in file:<br>    print line<br>  print eval(bits[x - 1])<br>  x += 1<br><br>I have excluded the code where I call the separate text files for printing normal text. They work. It's my code that I cannot get to work. For example, if I take out the "eval" part of the above, it will nicely print the commands, such as this:<br>
<br>tableTop(123,456)<br><br>which is supposed to call said fn. If I place that line in the file calling the text files and the bits file it will execute just fine, but that inevitably makes my job harder. Ideas?<br>TIA,<br>
Victor<br><br><div class="gmail_quote">On Mon, Apr 6, 2009 at 6:37 PM, J. Clifford Dyer <span dir="ltr"><<a href="mailto:jcd@sdf.lonestar.org">jcd@sdf.lonestar.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 class="im">On Mon, 2009-04-06 at 15:11 -0400, Victor Subervi wrote:<br>
</div><div><div></div><div class="h5">> Hi:<br>
> I have this code:<br>
><br>
> x = 1<br>
> while x <= bitties:<br>
>   file = open(p + str(x) + ".txt")<br>
>   for line in file:<br>
>     print line<br>
>   print eval(bits[x - 1])<br>
>   x += 1<br>
><br>
> which throws this error:<br>
><br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: Traceback (most recent call<br>
> last):<br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: File<br>
> "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299,<br>
> in HandlerDispatch\n result = object(req)<br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: File<br>
> "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line<br>
> 96, in handler\n imp.load_module(module_name, fd, path, desc)<br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: File<br>
> "/var/www/vhosts/<a href="http://articles.13gems.com/httpdocs/index_frame.py" target="_blank">articles.13gems.com/httpdocs/index_frame.py</a>", line<br>
> 89, in ?\n print eval(bits[1])<br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: File "<string>", line 1<br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: tableBottom(348,180)<br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: ^<br>
> [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]<br>
> PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax<br>
><br>
<br>
</div></div><div><div></div><div class="h5">Hmm.  That's not the problem I get.  For me, your code raises:<br>
"NameError: name 'bitties' is not defined"<br>
<br>
It's easier for us to help you if you present a self-contained piece of<br>
code that exhibits the problem you've encountered.  Creating that code<br>
will often reveal the problem with the original code, and you will have<br>
solved your own problem.<br>
<br>
The other problem with your code is that you are using eval.  Eval leads<br>
to difficult-to-debug errors, and is usually unnecessary, given the<br>
dynamic nature of python.  If you need to access a class method using a<br>
string, you can use getattr.  If you need to dynamically select a<br>
function based on some condition known in another variable, you can use<br>
a dictionary to hash into the function.<br>
<br>
It's hard to say what might be appropriate for your situation, because<br>
your code fragment is so... fragmentary.<br>
<br>
Cheers,<br>
Cliff<br>
<br>
<br>
</div></div><font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>