By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

code generator problem

P: 46
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import sys as sys2
  3. import os as os2
  4.  
  5. def playscoreinrange(from_file, fromline, toline):
  6.     "untested way to play a series of lines from a orc, sco combination line 14 may not be correct"
  7.     print(from_file)
  8.     fromfile = os2.path.basename(from_file)
  9.     infile = open(fromfile, 'r')
  10.     outfile = open('temp.sco','w')
  11.     orcfilename = fromfile[:-4] + '.orc'
  12.     infile2 = open(orcfilename, 'r')
  13.     outfile2 = open('temp.orc', 'w')
  14.     for line in infile2:
  15.         outfile2.write(line) 
  16.     data = sys2.stdin.readlines()
  17.     for linenumber in range(fromline, toline):
  18.         outfile.writeline(data[linenumber]) 
  19.     os2.startfile('temp.bat')
  20.  
https://sourceforge.net/projects/dex-tracker/
Dec 1 '06 #1
Share this Question
Share on Google+
7 Replies


bartonc
Expert 5K+
P: 6,596
Expand|Select|Wrap|Line Numbers
  1. open('temp.orc', 'w')
appears twice. that could be it. Also, it's good practice to call .close() on open files.
Dec 1 '06 #2

P: 46
Expand|Select|Wrap|Line Numbers
  1. 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.
Dec 1 '06 #3

bartonc
Expert 5K+
P: 6,596
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()
Dec 2 '06 #4

P: 46
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.

https://sourceforge.net/projects/dex-tracker
Dec 2 '06 #5

bartonc
Expert 5K+
P: 6,596
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import sys as sys2
  3. import os as os2
  4.  
  5. def playscoreinrange(from_file, fromline, toline):
  6.     "untested way to play a series of lines from a orc, sco combination line 14 may not be correct"
  7.     print(from_file)
  8.     fromfile = os2.path.basename(from_file)
  9.     infile = open(fromfile, 'r')
  10.     outfile = open('temp.sco','w')
  11.     orcfilename = fromfile[:-4] + '.orc'
  12.     infile2 = open(orcfilename, 'r')
  13.     outfile2 = open('temp.orc', 'w')
  14.     for line in infile2:
  15.         outfile2.write(line) 
  16.     data = sys2.stdin.readlines()
  17.     for linenumber in range(fromline, toline):
  18.         outfile.writeline(data[linenumber]) 
  19.     os2.startfile('temp.bat')
  20.  
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.
Dec 2 '06 #6

P: 46
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.readlines()

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

outfile.writeline(data[linenumber])

I changed that to

outfile.write(data[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.
Dec 2 '06 #7

bartonc
Expert 5K+
P: 6,596
I had asked somewhere else and they came up with this

data = sys2.stdin.readlines()

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

outfile.writeline(data[linenumber])

I changed that to

outfile.write(data[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.
Dec 2 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.