Loving the offtopic guys, sorry I have to go back to my problem now.. <br><br>In the module I want to import I have a few import statements for Maya commands that don't work outside Maya unless I use the Maya standalone interpreter. <br>
So before I import this module I need to make sure I import maya and  maya.standalone. <br>I make sure I place the correct paths in sys.path, but I get the following error:<br>    import maya.standalone<br>ImportError: /apps/Linux64/aw/maya2012/lib/python2.6/site-packages/maya/../../../../lib/libOGSDeviceOGL-2_7.so: undefined symbol: cgGetParameterBufferIndex<br>
Now, I've googled this error and couldn't find anything on it and I'd have no idea why it wouldn't work. It's not a python related error so I understand if you couldn't help me with this, but since you've asked :D<br>
<br>I am thinking of using eval for each line in the module i want to import (instead of importing it )  and just ignoring the maya related commands. <br>I can't and shouldn't edit any of these modules, I instead have to parse them and interpret the parameters types without actually executing the functions.. <br>
<br>Thanks a lot,<br>Andreea<br><br> <br><br><br><br><div class="gmail_quote">On 15 November 2011 18:58, Jean-Michel Pichavant <span dir="ltr"><<a href="mailto:jeanmichel@sequans.com">jeanmichel@sequans.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="HOEnZb"><div class="h5">David Riley wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Nov 15, 2011, at 12:35 PM, Andreea Babiuc wrote:<br>
<br>
  <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 15 November 2011 17:24, Chris Kaynor <<a href="mailto:ckaynor@zindagigames.com" target="_blank">ckaynor@zindagigames.com</a>> wrote:<br>
As with any Python code, you can wrap the import into a try: except block.<br>
<br>
try:<br>
 import badModule<br>
except:<br>
<br>
  pass # Or otherwise handle the exception - possibly importing an<br>
alternative module.<br>
<br>
<br>
Hmm, I know this might sound silly, but if it fails I still want to import the module and disable those lines of code that are related to the reason while the module failed to be imported in the first place.  Even if that makes the code not 100% correct.<br>

<br>
Does that make sense ?<br>
    <br>
</blockquote>
<br>
It makes sense.  It probably also makes sense to only do an "except ImportError", since if there are other errors (say, syntax errors in a module you're trying to import, rather than its absence, you probably want to know about it.<br>

<br>
To disable code that won't work without the module you're trying to import, you can always set flags in your module.  For example, I've got a project at work that can use a variety of communications interfaces, including using PySerial for serial port comms.  But if someone doesn't have PySerial installed, I want it to fail gracefully and just not support serial.  So I can do the following:<br>

<br>
<br>
try:<br>
   import serial<br>
   _serial_enabled = True<br>
except ImportError:<br>
   print("PySerial not installed - serial ports not supported!")<br>
   _serial_enabled = False<br>
<br>
<br>
And then elsewhere in my module, I can check the value of _serial_enabled to see if I should e.g. list the serial ports in available communications interfaces.<br>
<br>
Of course, if there's some other error in PySerial (maybe I installed a broken version with a syntax error?), that error will get propagated up, which is a good thing, because I'd rather know that PySerial is broken than just have it tell me it's not installed (which is what would happen if I simply caught all exceptions).  Your mileage may vary.<br>

<br>
- Dave<br>
<br>
  <br>
</blockquote></div></div>
If I'm not wrong the OP wants to disable the line *in the module being imported*, which is kindof silly and doesn't make sense to answer his question.<br>
<br>
Anreea, tell us why the module you are importing is failing and if this module is yours, we may provide you a proper way to handle this situation (though I'm pretty sure everything is in Dave's proposal).<span class="HOEnZb"><font color="#888888"><br>

<br>
JM<br></font></span>
PS : @Dave there is a way to avoiding adding symbols to your global namespace, assign None to the module's name on import errors. Then before using it, just test the module bool value : if serial: serial.whateverMethod()<br>

</blockquote></div><br><br clear="all"><br>-- <br>Blog: <a href="Http://andreeababiuc.ro">Http://andreeababiuc.ro</a><br>Photo Portfolio: <a href="http://royaa.daportfolio.com">http://royaa.daportfolio.com</a><br>