473,322 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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.

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
7 1494
bartonc
6,596 Expert 4TB
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
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
6,596 Expert 4TB
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
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
6,596 Expert 4TB
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
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
6,596 Expert 4TB
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

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: Francis Avila | last post by:
A little annoyed one day that I couldn't use the statefulness of generators as "resumable functions", I came across Hettinger's PEP 288 (http://www.python.org/peps/pep-0288.html, still listed as...
17
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next...
13
by: Emmanuel | last post by:
Hi, I run across this problem, and couldn't find any solution (python 2.2.2) : Code : =========== from __future__ import generators >>> class titi:
24
by: Mahesh Padmanabhan | last post by:
Hi, When list comprehension was added to the language, I had a lot of trouble understanding it but now that I am familiar with it, I am not sure how I programmed in Python without it. Now I...
12
by: Thomas Lotze | last post by:
Hi, I'm trying to figure out what is the most pythonic way to interact with a generator. The task I'm trying to accomplish is writing a PDF tokenizer, and I want to implement it as a Python...
8
by: Thomas Stegen | last post by:
I have written a code generator. To be more specific it is a code generator generator. As in a generator that generates code generators. If you run the generator on its own source code you get a...
14
by: Steven D'Aprano | last post by:
I came across an interesting (as in the Chinese curse) problem today. I had to modify a piece of code using generator expressions written with Python 2.4 in mind to run under version 2.3, but I...
29
by: Ancient_Hacker | last post by:
A while back I had to recompile some old code, originally written by a really good programmer, but one prone to use every trick in the book, and then some. There was a statement, something like...
3
by: Sander Tekelenburg | last post by:
Situation: I store news articles as individual PHP files. Each file contains HTML and now and then some embedded PHP snippets. Serving those news articles on the Web works fine, through...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.