newbie question

B

Bermi

i have this program
===================
from sys import *
import math
import math, Numeric
from code import *
from string import *
from math import *
from dataSet import *
from string import *

def drawAsciiFile():
_fileName=str(argv[1])
__localdataSet=DataSet(_fileName)

#_PlotCols=string.split(str(argv[2]),' ')
#_PlotColsInt=[]
'''for s in _PlotCols:
_PlotColsInt.append(int(s))
CountourPlots(__localdataSet,_PlotColsInt)
'''
print
__data=__localdataSet.GetData()
print max(__data[:,11])
if __name__ == "__main__":
drawAsciiFile()
================================

how i can link it to read my file examle.txt?

thanks
michael
 
T

Tim Roberts

Bermi said:
i have this program
===================
from sys import *
import math
import math, Numeric
from code import *
from string import *
from math import *
from dataSet import *
from string import *

I know you said you are a newbie. That means there is still time for you
to learn to do things the proper way. Change all of that to:

import sys
import math
import Numeric
import dataSet

You don't need to import string at all, and you will probably never use
"code".

def drawAsciiFile():
_fileName=str(argv[1])

argv is already an array of strings. The "str" is useless.
__localdataSet=DataSet(_fileName)

#_PlotCols=string.split(str(argv[2]),' ')
#_PlotColsInt=[]
'''for s in _PlotCols:
_PlotColsInt.append(int(s))
CountourPlots(__localdataSet,_PlotColsInt)
'''
print
__data=__localdataSet.GetData()
print max(__data[:,11])
if __name__ == "__main__":
drawAsciiFile()
================================

how i can link it to read my file examle.txt?

Instead of referring to argv inside your function, you should pass the file
name as a parameter. That way, at a later time, you can pass it file names
from sources other than argv. Also, there is no point in using leading
underscores for local variables. That's only interesting for members of
the class.

You are splitting argv[2]. Ordinarily, sys.argv has already been split.
That is, "xxx.py file 1 3 5 7" will produce 6 elements in sys.argv. If you
really want the columns as a single parameter, you'll have to use quoting:
xxx.py file "1 3 5 7"

Something like this, maybe:

def drawAsciiFile(filename, columns):
localdataSet = DataSet.DataSet( filename )
PlotCols = [int(s) for s in columns.split()]
ContourPlots( localdataSet, PlotCols )

if __name__ == "__main__":
if len(sys.argv) < 2:
print 'Usage: xxxx.py filename "3 5 7"' )
drawAsciiFile( sys.argv[1], sys.argv[2] )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,051
Latest member
noblesalt

Latest Threads

Top