strange problems with code generation
John Machin
sjmachin at lexicon.net
Fri Dec 1 21:16:32 EST 2006
Eric_Dexter at msn.com wrote:
> I am writing out zero byte files with this (using python 2.5). I have
> no idea why I am having that problem
Which output file(s) do you mean, temp.orc or temp.sco or both?
Two possible causes outlined below.
> I am also looking for an example
> of readlines where I can choose a number of lines say lines 12 to 14
> and then write them back to disk.
To the same file? There was a long thread on updating text files very
recently.
> any help would be apreaceted.
Have you considered deploying a spelling checker?
>
> import sys as sys2
> import os as os2
Why the obfuscation?
>
> 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"
and which is line 14?? According to my count, it is the blank line
after "outfile2 = open('temp.orc', 'w') "!!
> print(from_file)
> fromfile = os2.path.basename(from_file)
> print(fromfile)
>
> orcfilename = fromfile[:-4] + '.orc'
> print(orcfilename)
> infile2 = open(orcfilename, 'r')
> outfile2 = open('temp.orc', 'w')
>
> for line in infile2:
> outfile2.write(line)
>
>
> infile = open(fromfile, 'r')
infile is not used
> outfile = open('temp.sco','w')
>
> data = sys2.stdin.readlines()
> print(data)
and how many lines were there in data when you printed it?
> for linenumber in range(fromline, toline):
Consider the possibility that fromline >= toline (which may be caused
by either or both not being of a numerical type).
Did you mean range(fromline, toline + 1) ?
do this:
print repr(fromline), type(fromline)
print repr(toline), type(toline)
BTW, print is a *statement*, not a function!
> outfile.writeline(data[linenumber])
outfile.writeline() ???
| Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
| Type "help", "copyright", "credits" or "license" for more
information.
| >>> f = open('fubar.txt', 'w')
| >>> f.writeline('bzzzzt!\n')
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| AttributeError: 'file' object has no attribute 'writeline'
So, the body of your loop wasn't executed (or you overlooked the
exception, or that wasn't the code that was executed) -- so it looks
like the range was empty (or the problem occurred further upstream).
> https://sourceforge.net/projects/dex-tracker
> http://www.dexrow.com
>
>
> os2.startfile('temp.bat')
and what does this do?? Read temp.orc and/or temp.sco before you've
closed the file(s)?
Where is the code that was used to call this playscoreinrange function?
HTH,
John
More information about the Python-list
mailing list