473,397 Members | 2,077 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,397 software developers and data experts.

strange problems with code generation

I am writing out zero byte files with this (using python 2.5). I have
no idea why I am having that problem, 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. any help would be apreaceted.

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)
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')
outfile = open('temp.sco','w')

data = sys2.stdin.readlines()
print(data)
for linenumber in range(fromline, toline):
outfile.writeline(data[linenumber])

https://sourceforge.net/projects/dex-tracker
http://www.dexrow.com
os2.startfile('temp.bat')

Dec 2 '06 #1
6 2119
Er*********@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

Dec 2 '06 #2

John Machin wrote:
Er*********@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
temp bat is

csound temp.orc temp.sco

and it plays the new files I can try closing the other files first. I
am sure the readlines code is crashing it. Because I have moved it
befour the code that is reading a line at a time and it would not even
write the second zero byte file. The comment line is an old line that
I did not update when I made changes. The code that calls it was
auto-generated but boa-constructer .44 (I haven't updated it yet).
#Boa:Dialog:Dialog2

import wx
import csoundroutines2

def create(parent):
return Dialog2(parent)

[wxID_DIALOG2, wxID_DIALOG2BUTTON1, wxID_DIALOG2STATICTEXT1,
wxID_DIALOG2STATICTEXT2, wxID_DIALOG2TEXTCTRL1, wxID_DIALOG2TEXTCTRL2,

] = [wx.NewId() for _init_ctrls in range(6)]

class Dialog2(wx.Dialog):
From_File = ''
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Dialog.__init__(self, id=wxID_DIALOG2, name='', parent=prnt,
pos=wx.Point(759, 203), size=wx.Size(420, 72),
style=wx.DEFAULT_DIALOG_STYLE, title='play csound lines')
self.SetClientSize(wx.Size(412, 38))
self.Bind(wx.EVT_RIGHT_DCLICK, self.OnDialog2RightDclick)

self.textCtrl1 = wx.TextCtrl(id=wxID_DIALOG2TEXTCTRL1,
name='textCtrl1',
parent=self, pos=wx.Point(56, 8), size=wx.Size(100, 21),
style=0,
value='test')

self.textCtrl2 = wx.TextCtrl(id=wxID_DIALOG2TEXTCTRL2,
name='textCtrl2',
parent=self, pos=wx.Point(216, 8), size=wx.Size(100, 21),
style=0,
value='')

self.staticText1 = wx.StaticText(id=wxID_DIALOG2STATICTEXT1,
label='from line', name='staticText1', parent=self,
pos=wx.Point(8, 8), size=wx.Size(41, 13), style=0)
self.staticText1.SetToolTipString('From Line')
self.staticText1.SetBackgroundStyle(wx.BG_STYLE_SY STEM)
self.staticText1.SetForegroundColour(wx.Colour(255 , 0, 0))

self.staticText2 = wx.StaticText(id=wxID_DIALOG2STATICTEXT2,
label='To Line', name='staticText2', parent=self,
pos=wx.Point(168, 8), size=wx.Size(34, 13), style=0)
self.staticText2.SetForegroundColour(wx.Colour(255 , 0, 0))

self.button1 = wx.Button(id=wxID_DIALOG2BUTTON1, label='play',
name='button1', parent=self, pos=wx.Point(328, 8),
size=wx.Size(75, 23), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_DIALOG2BUTTON1)

def __init__(self, parent):
self._init_ctrls(parent)

def OnDialog2RightDclick(self, event):
fromline = int(self.textCtrl1.GetValue(self))
toline = int(self.textCtrl2.GetValue(self))
csoundroutines2.playscoreinrange(From_File, fromline,
toline)#needs filename

def OnButton1Button(self, event):
fromline = int(self.textCtrl1.GetValue())
toline = int(self.textCtrl2.GetValue())
csoundroutines2.playscoreinrange(self.From_File, fromline,
toline)#needs filename
https://sourceforge.net/projects/dex-tracker

Dec 2 '06 #3
You say "I am sure the readlines code is crashing it." I can't imagine
how you can be sure of anything, but yes, it is a possibility that
sys.stdin.readlines() might behave strangely when called from a GUI
kit. Why from sys.stdin anyway?

You have two *known* definite problems (not closing your output files,
and no such attribute as "writeline") -- *fix* them, and try again.

Do try to test that function in isolation.
Put print statements in as I suggested. Comment out the .bat file
invocation.
Try calling the function from the interactive interpteter. Check if the
files are being created, with the right size. If it works, add back the
..bat file invocation. If that works, try it from your GUI.

IOW, try to attack your problem methodically.

AND try to answer at least some of the questions that helpers might ask
you, like what does "print(data)" produce -- they're not asked out of
idle curiosity.

HTH,
John

Dec 2 '06 #4
I never see anything from print(data). The example I tried to adapt
using readlines may be a little old or something. I did close all the
files to prevent problems when I figure out what is wrong with what I
have.

John Machin wrote:
You say "I am sure the readlines code is crashing it." I can't imagine
how you can be sure of anything, but yes, it is a possibility that
sys.stdin.readlines() might behave strangely when called from a GUI
kit. Why from sys.stdin anyway?

You have two *known* definite problems (not closing your output files,
and no such attribute as "writeline") -- *fix* them, and try again.

Do try to test that function in isolation.
Put print statements in as I suggested. Comment out the .bat file
invocation.
Try calling the function from the interactive interpteter. Check if the
files are being created, with the right size. If it works, add back the
.bat file invocation. If that works, try it from your GUI.

IOW, try to attack your problem methodically.

AND try to answer at least some of the questions that helpers might ask
you, like what does "print(data)" produce -- they're not asked out of
idle curiosity.

HTH,
John
Dec 2 '06 #5
It is left over from the example I stold it from, I remove it and see
if that helps.
Dennis Lee Bieber wrote:
On 1 Dec 2006 17:24:18 -0800, "Er*********@msn.com"
<Er*********@msn.comdeclaimed the following in comp.lang.python:
data = sys2.stdin.readlines()

And what do you expect to read from stdin? Do you even have an
attached console to read?
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Dec 2 '06 #6
I changed that and the writelines and I am very close now. thanks.
Dennis Lee Bieber wrote:
On 1 Dec 2006 17:24:18 -0800, "Er*********@msn.com"
<Er*********@msn.comdeclaimed the following in comp.lang.python:
data = sys2.stdin.readlines()

And what do you expect to read from stdin? Do you even have an
attached console to read?
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Dec 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
3
by: Roman S. Golubin1709176985 | last post by:
All how do you do! Who what cases uses for C# programming? I have an experience with Microsoft Visio several days. He has a problem with interface inheritance... óan who that other advise? ...
2
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
8
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
17
by: Manlio Perillo | last post by:
Regards. On my system: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32, Windows XP I have this problem: >>> n = 61409 + 1 >>> data = 'x' * n
5
by: Brian | last post by:
void generation_loop() { int generation = 1; double x = 0.25; double y = 0.50; double z = 0.25; double AA, AB, BB; double p = (y/(y+z))/2; AA = pow(p,2); AB = 2*p*(1-p);
0
by: aepheus | last post by:
I use the following code to create a file for the user to download: Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "text/ris";...
6
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.