我在脚本的开头声明了一些变量,因为我在许多不同的方法中使用它们(python中的“函数”?)。当我尝试访问它们时,我似乎无法获得它们的值=或者将它们设置为另一个值。例如:
int main(void){
int m, n, dis;
char m_check, n_check, dis_check;
do{
m = 0; n = 0; dis = 0;
m_check = ' '; n_check = ' '; dis_check = ' ';
printf("Please enter number of rows m in the matrix (integer): ");
if(scanf("%d%c", &m, &m_check) !=2 || m_check != '\n')
m_check = 'F';
printf("Please enter number of columns n in the matrix (integer): ");
if(scanf("%d%c", &n, &n_check) !=2 || n_check != '\n')
n_check = 'F';
printf("Should the random numbers come from a uniform or normal distribution?...
Please press 1 for uniform or 2 for normal: ");
if(scanf("%d%c", &dis, &dis_check) !=2 || dis_check != '\n' || dis != 1 || dis !=2)
dis_check = 'F';
}while(m_check == 'F' || n_check == 'F' || dis_check == 'F');
当我在baseFile = open('C:/Users/<redacted>/Documents/python dev/ATM/Data.ICSF', 'a+')
secFile = open('C:/Users/<redacted>/Documents/python dev/ATM/security.ICSF', 'a+')
def usrInput(raw_input):
if raw_input == "99999":
self.close(True)
else:
identity = raw_input
def splitValues(source, string):
if source == "ident":
usrTitle = string.split('>')[1]
usrFN = string.split('>')[2]
usrLN = string.split('>')[3]
x = string.split('>')[4]
usrBal = Decimal(x)
usrBalDisplay = str(locale.currency(usrBal))
elif source == "sec":
usrPIN = string.split('>')[1]
pinAttempts = string.split('>')[2]
def openAccount(identity):
#read all the file first. it's f***ing heavy but it'll do here.
plString = baseFile.read()
xList = plString.split('|')
parm = str(identity)
for i in xList:
substr = i[0:4]
if parm == substr:
print "success"
usrString = str(i)
else:
lNumFunds = lNumFunds + 1
splitValues("ident", usrString)
方法中放置baseFile
和secFile
时,我可以正常访问相应的文件。但是,当我将它们放在脚本的根目录时,如上例所示,我无法再访问该文件 - 尽管我仍然可以“看到”该变量。
这有什么理由吗?作为参考,我使用的是Python 2.7。
答案 0 :(得分:0)
方法(&#34;函数&#34;在python中?)
&#34;功能&#34;他们什么时候自由自在&#34 ;; &#34;方法&#34;当他们是一个班级的成员。所以,你的情况就是函数。
你所描述的确实在python中起作用。因此,我的诊断是你在调用read
之前已经在其他地方openAccount
发现了一些内容,因此读指针不在文件的开头。