473,385 Members | 1,942 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,385 software developers and data experts.

passing values to a program

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
3 1227
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
2
by: Morgan | last post by:
Thanks to all of you because I solved the problem related with my previous post. I simply made confusion with pointers to pointers and then succeeded passing the reference to the first element...
4
by: hello smith | last post by:
I have a lot of functions that add values to an array. They alos update a global variable of type int. Currently, I use a global variable to hold this array. All functions access this array...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
17
by: Christopher Benson-Manica | last post by:
Does the following program exhibit undefined behavior? Specifically, does passing a struct by value cause undefined behavior if that struct has as a member a pointer that has been passed to...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
5
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the...
5
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the...
3
by: Archanak | last post by:
Hi, Any limits exists while passing values of checkbox to another program? Here is the code: <script type="text/javascript"> function valuate() {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.