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

passing values to a program

P: n/a
I almost have this thing running like I want it to run but I want
the values to come from the program that calls this one. There are two
things I want to pass File_Name and CutString. They both need to go to
loadFile routine of Class WordGrid to replace constants. Thank you for
putting up with my quesitons in advance.
import wx
import wx.grid as gridlib

#---------------------------------------------------------------------------

class WordGrid(gridlib.Grid):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
self.loadFile()

self.CreateGrid(len(self.rows), self.widestRow)

for r, row in enumerate(self.rows):
for c, col in enumerate(row):
self.SetCellValue(r, c, col)
self.SetColSize(c, 10*self.widestCol)

for c, label in enumerate(self.header):
self.SetColLabelValue(c, label)

def loadFile(self):
#from_file
infile = open('test.sco', 'r')
foundHeader = False
self.rows = []
for line in infile:
if ";<sco_header>" in line:
#removefirst = line.split(' ')
self.header = line.split()
#foundHeader = 'true'
continue # we don't want to process this line any
further
else:
self.rows.append(line.split())

self.widestRow = max([len(r) for r in self.rows])
self.widestCol = max([len(c) for c in [r for r in self.rows]])

#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, -1, "Simple Grid Demo",
size=(640,480))
grid = WordGrid(self, log)

#---------------------------------------------------------------------------
#def main():

def main(From_File, string):
import sys
From_file = argv[1]
#split_string = argv2[2]
app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
pass

if __name__ == '__main__':
import sys
main('test.sco', 'sfd')

http://www.dexrow.com

Oct 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Er*********@msn.com wrote:
I almost have this thing running like I want it to run but I want
the values to come from the program that calls this one. There are two
things I want to pass File_Name and CutString. They both need to go to
loadFile routine of Class WordGrid to replace constants.
note that your code is already using "sys.argv" to read arguments from
the command line (inside the main function), so obviously you know how
to do that, and your code is passing arguments around (to both the
constructor and the main function), so obviously you know how to do that.

so what's the problem here? why not just use the mechanisms you already
know how to use?

</F>

Oct 19 '06 #2

P: n/a

Er*********@msn.com wrote:
I almost have this thing running like I want it to run but I want
the values to come from the program that calls this one. There are two
things I want to pass File_Name and CutString. They both need to go to
loadFile routine of Class WordGrid to replace constants. Thank you for
putting up with my quesitons in advance.
import wx
import wx.grid as gridlib

#---------------------------------------------------------------------------

class WordGrid(gridlib.Grid):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
self.loadFile()

self.CreateGrid(len(self.rows), self.widestRow)

for r, row in enumerate(self.rows):
for c, col in enumerate(row):
self.SetCellValue(r, c, col)
self.SetColSize(c, 10*self.widestCol)

for c, label in enumerate(self.header):
self.SetColLabelValue(c, label)

def loadFile(self):
#from_file
infile = open('test.sco', 'r')
foundHeader = False
self.rows = []
for line in infile:
if ";<sco_header>" in line:
#removefirst = line.split(' ')
self.header = line.split()
#foundHeader = 'true'
continue # we don't want to process this line any
further
else:
self.rows.append(line.split())

self.widestRow = max([len(r) for r in self.rows])
self.widestCol = max([len(c) for c in [r for r in self.rows]])

#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, -1, "Simple Grid Demo",
size=(640,480))
grid = WordGrid(self, log)

#---------------------------------------------------------------------------
#def main():

def main(From_File, string):
import sys
From_file = argv[1]
#split_string = argv2[2]
app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
pass

if __name__ == '__main__':
import sys
main('test.sco', 'sfd')

http://www.dexrow.com
Try this code, save it in file called test.py

def main(From_File, string):
print 'From_File: %s' % From_File
print 'string: %s' % string

if __name__ == '__main__':
import sys
print 'command line'
print sys.argv
main(sys.argv[1], sys.argv[2])

print 'hardcoded'
main('test.sco', 'sfd')

H:\>test.py arg1 arg2
command line
['H:\\test.py', 'arg1', 'arg2']
From_File: arg1
string: arg2
hardcoded
From_File: test.sco
string: sfd

argv is in namespace sys, but you don't tell that. Also I would
consider using a none built in and less generic name for the argument
'string' you're using.

Oct 19 '06 #3

P: n/a
If it is as simple as using the sys and dot befour the argv then I have
it made.. The example I was trying to get that from came from the
first edition programming python (I think they were using version 1.3).
thanks for the help I will give that a try.

https://sourceforge.net/project/stat...gn=dex-tracker
Fredrik Lundh wrote:
Er*********@msn.com wrote:
I almost have this thing running like I want it to run but I want
the values to come from the program that calls this one. There are two
things I want to pass File_Name and CutString. They both need to go to
loadFile routine of Class WordGrid to replace constants.

note that your code is already using "sys.argv" to read arguments from
the command line (inside the main function), so obviously you know how
to do that, and your code is passing arguments around (to both the
constructor and the main function), so obviously you know how to do that.

so what's the problem here? why not just use the mechanisms you already
know how to use?

</F>
Oct 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.