need help opening a csv file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miguel22
    New Member
    • Jan 2008
    • 13

    need help opening a csv file

    first let me start by thanking everyone for their help. Well here is what I'm trying to do. I have a file in a directory lets say C:/Files/data.csv now in cell C21
    of the data.cvs I have a filename lets call this file test.sav which opens in PTI (a software that has Phyton built into it) this file is in a diferent driectory lets say C:/PTI_file/test.sav. Now I what to create a python file that will open the data.csv file read cellC21 and open the test.sav file in PTI. Just to clarify if you double click on test.sav it will open in PTI.
  • jlm699
    Contributor
    • Jul 2007
    • 314

    #2
    Originally posted by miguel22
    first let me start by thanking everyone for their help. Well here is what I'm trying to do. I have a file in a directory lets say C:/Files/data.csv now in cell C21
    of the data.cvs I have a filename lets call this file test.sav which opens in PTI (a software that has Phyton built into it) this file is in a diferent driectory lets say C:/PTI_file/test.sav. Now I what to create a python file that will open the data.csv file read cellC21 and open the test.sav file in PTI. Just to clarify if you double click on test.sav it will open in PTI.
    It should go something like this...

    [CODE=python]
    from subprocess import Popen

    row = 21
    col = 2 # column A = 0, B = 1, C = 2, etc.
    for num in range(row):
    fname = fh.readline().s plit(',')[col].strip()

    # At this point fname should contain whatever was in cell C21
    Popen(os.path.j oin('C:\\', 'PTI_file', fname))
    [/CODE]

    If I remember correctly Popen will open that program using whatever it natively gets opened with...

    Comment

    • miguel22
      New Member
      • Jan 2008
      • 13

      #3
      Thanks for the quick response; another question is how could I point to the CSV file. How would I start the code? Sorry my programming skill is very limited.

      Thanks

      Comment

      • jlm699
        Contributor
        • Jul 2007
        • 314

        #4
        Originally posted by miguel22
        how could I point to the CSV file. How would I start the code?
        Ooops! Sorry I forgot that little portion of the code...
        [CODE=python]fh = open(os.path.jo in('C:\\', 'Files', 'data.csv'), 'r')[/CODE]
        Note: I use os.path.join for all of my paths because it's a lot easier than worrying about the slashes.

        What type of program are you trying to build?
        The above is a simple script that can be run, if you're looking for something like a stand-alone application with a GUI you'll have to look forward to learning wxPython, which is amazing in the things it can do
        Last edited by jlm699; Jan 10 '08, 01:37 PM. Reason: Took a second look at what the question was

        Comment

        • miguel22
          New Member
          • Jan 2008
          • 13

          #5
          Let me start by thanking you for the help.

          OK here it goes!!!
          Basically I what to write this to help me at work.
          I work at a power utility.
          Here is what I have in mind.
          We have a website that has line outage data as well as generator outage data. This data is used to build cases to model the system. (Cases are built using PTI which has Python embedded in it as well as a database for the whole state). I what to write a program that goes on line grabs the information form the website for the time frame requested putt’s it in excel runs a macro. The excel file will tell python which case needs to open runs a series of commands in PSSE the saves that case with a new name that includes the date. Python then opens Must which is another program we use that is bases in excel. Runs the case through it gets the output and puts in a new excel book and saves it.

          What do you think?

          Thanks again

          Comment

          • jlm699
            Contributor
            • Jul 2007
            • 314

            #6
            Originally posted by miguel22
            I what to write a program that goes on line grabs the information form the website for the time frame requested putt’s it in excel runs a macro. The excel file will tell python which case needs to open runs a series of commands in PSSE the saves that case with a new name that includes the date. Python then opens Must which is another program we use that is bases in excel. Runs the case through it gets the output and puts in a new excel book and saves it.

            What do you think?
            I think that your task would be straight forward enough to create a script to do this, which would take an input (a requested time frame) and then perform the rest. It doesn't sound like you would need any kind of user interface for this so I would not suggest looking into wxPython.

            Comment

            • miguel22
              New Member
              • Jan 2008
              • 13

              #7
              Thanks realy preciate you help!!

              Comment

              Working...