code generator problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eric dexter
    New Member
    • Sep 2006
    • 46

    code generator problem

    I am trying to write a simple code generator to play part of a csound file but I am writing zero byte files out to the disk. It appears the filename is coming through o.k.

    Code:
    import sys as sys2
    import os as os2
    
    def playscoreinrange(from_file, fromline, toline):
        "untested way to play a series of lines from a orc, sco combination line 14 may not be correct"
        print(from_file)
        fromfile = os2.path.basename(from_file)
        infile = open(fromfile, 'r')
        outfile = open('temp.sco','w')
        orcfilename = fromfile[:-4] + '.orc'
        infile2 = open(orcfilename, 'r')
        outfile2 = open('temp.orc', 'w')
        for line in infile2:
            outfile2.write(line) 
        data = sys2.stdin.readlines()
        for linenumber in range(fromline, toline):
            outfile.writeline(data[linenumber]) 
        os2.startfile('temp.bat')
    https://sourceforge.net/projects/dex-tracker/
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Code:
    open('temp.orc', 'w')
    appears twice. that could be it. Also, it's good practice to call .close() on open files.

    Comment

    • eric dexter
      New Member
      • Sep 2006
      • 46

      #3
      Originally posted by bartonc
      Code:
      open('temp.orc', 'w')
      appears twice. that could be it. Also, it's good practice to call .close() on open files.

      I don't see it opening twice. One ends in .orc and one in .sco (unless I am completly missing it). Plus I am having the trouble with both temp.orc and temp.sco being created as zero byte files.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by eric dexter
        I don't see it opening twice. One ends in .orc and one in .sco (unless I am completly missing it). Plus I am having the trouble with both temp.orc and temp.sco being created as zero byte files.
        Yeah, I wasn't quite awake that early in the morning.
        Try closing the files before you call startfile()

        Comment

        • eric dexter
          New Member
          • Sep 2006
          • 46

          #5
          Originally posted by bartonc
          Yeah, I wasn't quite awake that early in the morning.
          Try closing the files before you call startfile()
          I added this

          infile.close()
          infile2.close()
          outfile.close()
          outfile2.close( )

          This probily stops problems that I am not having yet. I noticed that when the code that has the readlines in it is first that the second file does not appear to opened at all. but I am having trouble with both sections.

          Download Dex Tracker for free. tracker interface for csound. working sco editor, drum machine exc, support for vst and csound instruments.

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by eric dexter
            I am trying to write a simple code generator to play part of a csound file but I am writing zero byte files out to the disk. It appears the filename is coming through o.k.

            Code:
            import sys as sys2
            import os as os2
            
            def playscoreinrange(from_file, fromline, toline):
                "untested way to play a series of lines from a orc, sco combination line 14 may not be correct"
                print(from_file)
                fromfile = os2.path.basename(from_file)
                infile = open(fromfile, 'r')
                outfile = open('temp.sco','w')
                orcfilename = fromfile[:-4] + '.orc'
                infile2 = open(orcfilename, 'r')
                outfile2 = open('temp.orc', 'w')
                for line in infile2:
                    outfile2.write(line) 
                data = sys2.stdin.readlines()
                for linenumber in range(fromline, toline):
                    outfile.writeline(data[linenumber]) 
                os2.startfile('temp.bat')
            https://sourceforge.net/projects/dex-tracker/
            Since we don't have the files in question and don't know what you are inputing by hand into data, our ability to help you is somewhat limited.
            Presumably, temp.bat does something to the files you have just created.
            Since file.write() does buffering, it is possible that closing the file would have flushed any data to the disk. If you supply more info, it may be possible to find where you missing data is going.

            Comment

            • eric dexter
              New Member
              • Sep 2006
              • 46

              #7
              Originally posted by bartonc
              Since we don't have the files in question and don't know what you are inputing by hand into data, our ability to help you is somewhat limited.
              Presumably, temp.bat does something to the files you have just created.
              Since file.write() does buffering, it is possible that closing the file would have flushed any data to the disk. If you supply more info, it may be possible to find where you missing data is going.
              I had asked somewhere else and they came up with this

              data = sys2.stdin.read lines()

              stdin is output to the consul (spelling) so I removed that and

              outfile.writeli ne(data[linenumber])

              I changed that to

              outfile.write(d ata[linenumber])

              It would seem like a bug in python to have two files as zero byte when it is only the code for one of them that is messed up. Thanks for the help.

              Comment

              • bartonc
                Recognized Expert Expert
                • Sep 2006
                • 6478

                #8
                Originally posted by eric dexter
                I had asked somewhere else and they came up with this

                data = sys2.stdin.read lines()

                stdin is output to the consul (spelling) so I removed that and

                outfile.writeli ne(data[linenumber])

                I changed that to

                outfile.write(d ata[linenumber])

                It would seem like a bug in python to have two files as zero byte when it is only the code for one of them that is messed up. Thanks for the help.
                I do not believe that file.write() is the culprit here. I hope that your routine is working now. Sounds like it.

                Comment

                Working...