我试图在我的程序中使用函数,但我不完全确定如何使用它们,我已经使用python一段时间但从未使用函数可以解释为什么这对我不起作用?
import csv
import operator
def SerachForCapitals():
#opens and reads txt file
sample = open('Capitals.txt', 'r')
csv1 = csv.reader(sample, delimiter = ',')
#asks user for an input
name = raw_input('enter a capital: ')
#sets the headings
print ""
print "Capital, Country"
print ""
#Finds capital row and prints it
for row in csv1:
if name == row[0]:
print row
print ' '
def AddInData():
#opens the text file
sample = open('capitals.txt','a+')
csv1 = csv.reader(sample, delimiter = ',')
#prints headings
print 'capital, country'
#ask ser for an input
change = raw_input('add data like line shown above:')
#adds input to text file
sample.write(change)
#closes the text file
sample.close()
#Menu choices
print '1. choose a capital'
print '2. enter data'
#Get an input from the user
menuC= raw_input('please choose a menu item: ')
if menuC == '1':
SearchForCapitals()
elif menuC == '2':
AddInData()
答案 0 :(得分:0)
除此之外,let jwtSvcSpy = jasmine.createSpyObj('jwtService', ['getToken']);
jwtSvcSpy.getToken.and.callFake(() => {
return Rx.Observable.of(new Response(
new ResponseOptions({
body: {
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0b3B0YWwuY29tIiwiZXhwIjoxNDI2NDIwODAwLCJodHRwOi8vdG9wdGFsLmNvbS9qd3RfY2xhaW1zL2lzX2FkbWluIjp0cnVlLCJjb21wYW55IjoiVG9wdGFsIiwiYXdlc29tZSI6dHJ1ZX0.yRQYnWzskCZUxPwaQupWkiUzKELZ49eM7oWxAQK_ZXw"
}
})
))
});
的函数定义有一个拼写错误,我的意思是该行
SearchForCapitals
应该是
def SerachForCapitals():
(注意def SearchForCapitals():
的拼写),你的代码对我来说非常合适。
如果这不能解决您的问题,您应该提供运行代码时获得的输出。