How to get the filename in the right case ?

Fredrik Lundh fredrik at pythonware.com
Fri Sep 26 00:58:51 CEST 2008


Stef Mientki wrote:

 > 1. I've a multitab editor.
 > 2. When a breakpoint is reached,
 > 3. I check if the file specified in pdb output, is already open in one
 > of the editor tabs,
 > 4. if not, I open a new tab with the correct file,
 > 5. I focus the correct editor tab and jump to the line specified by
 > pdb.
 > 6. After that I should be able to inspect the surrounding of the
 > breakpoint, so I need the modules name.
 >
 > For 3 I need to compare filenames, the editor contains the case
 > sensitive name, pdb not.

pdb uses os.path.abspath and os.path.normcase to normalize filenames so 
they can be safely compared (see the canonic method in bdb.py).

I suggest you do the same in your editor; e.g:

     pdb_filename = ...

     for buffer in editor_buffers:
         filename = os.path.normcase(os.path.abspath(buffer.filename))
         if pdb == filename:
             ... found it ...
             break

</F>




More information about the Python-list mailing list