> those modules are already imported when Python gets to your code, so > the only "overhead" you're saving is a little typing.
I don't understand this. Could you please elaborate? - if sys or os are not imported for any other causes how are they already imported? Maybe I'm wrong here, and accessing the filesystem and reading the module into memory represents no cost. My mistake, in that case. > wow. that's one lousy optimization... > here's a *shorter* piece of code, which is also readable and portable, and > a lot easier to type on most keyboards: > import os > __filename__ = os.path.basename(__file__) It may be lousy, but it requires no imports. And, as I said in the answer to Steve, I _know_ there are many ways to achieve this, including yours. But in your rush to pin-point lousy code, you didn't read that, I suppose. -- http://mail.python.org/mailman/listinfo/python-list