I am trying to call some functions from one file in another file on python, but whenever I do that I keep getting an error. This is the code I have for the first file called myfile.py
def readfile('C:\Users\kprab\Documents\python\data.asc'):
# to read in the data from a file
import pylab
from numpy import genfromtxt
# get data
data = genfromtxt('C:\Users\kprab\Documents\python\data.asc', delimiter=',')
print data
def proj(data):
# to create an image from data
import numpy
from matplotlib import pyplot as plt
x = data
plt.imshow(x, cmap='gray', interpolation='nearest', vmin=0, vmax=255)
plt.savefig('text.png')
plt.show()
and then I am trying to call these function in another file but with different data. This codes looks like the following:
import myfile
a = myfile.readfile('C:\Users\kprab\Documents\python\HPOPUP2_201507071256_1')
print a
b = myfile.proj(a)
print b
and the error I get is
def readfile('C:\Users\kprab\Documents\python\data.asc'):
^
SyntaxError: invalid syntax
Any help is appreciated. Thanks!
def readfile('C:\Users\kprab\Documents\python\data.asc'):doesn't make any sense. You need to give a name to use for the parameter, not the string you intend to pass it later.