Forum Discussion

MrDysprosium's avatar
MrDysprosium
Contributor
7 years ago

Trying to open a file from a script within TC, is that even possible?

Opening a file in Python is pretty easy, but maybe I'm missing something here?

I'm thinking this is a limitation of TC, then again my Python is rusty, so maybe it's a syntactical error?

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Where does "test.txt" live on your hard drive?  I think you need to be a bit more explicit with the path.

     

    You can make it "relative" to the location of your project, in case the project is run from a different workstation.  I don't know python but your open call might be better done like

     

    open(Project.Path + '\Script\test.txt')
    • Marsha_R's avatar
      Marsha_R
      Champion Level 3

      We use Project.Path for the data files that TestComplete needs, but we also found that we needed directories that belong to our application and those can change depending on the user name or machine or other tedious things.  The solution for that was to write a script that checks our app for version and user, etc., and then updates some variables like ReportPath and LogPath so we have those available for all the other tests.  That script runs first in our setup routine.