当程序需要用户交互时,我有一行代码在cmd中响铃。我在python中使用print(' \ a')命令执行此操作。但是我想把这个命令放在配置选项后面,因为我不想在每个提示符上响铃。我怎样才能做到这一点??非常感谢。
答案 0 :(得分:0)
您可以采用多种方式执行此操作。一个是Object
。很多configparser
。
将铃声放入变量并在每个this.userTourList = this.af.database.list('/userProfiles/' + this.userId + '/tours/');
this.userTourList.subscribe((response) => {
if (response.length == 0) {
//Return an empty array anyway
return this.toursObservable.next(this.tours);
}
response.map((tourData) => {
//Create and fill a TourSnapshot component
let tourSnap = new TourSnapshot(tourData.name, tourData.$key);
tourSnap.description = tourData.description;
//[..]
this.tours.push(tourSnap);
//Return an array through my own observable
return this.toursObservable.next(this.tours);
});
}
之前加上前缀。您可以在需要时使用print
,在不使用时使用'\a'
。
在您的config.INI中,或任何其他方式从用户获取首选项:
''
对于所有地方,你可能想要铃声:
[DEFAULT]
bell_sound = True # or False
最好把它放到像if config['DEFAULT'].getboolean('bell_sound'):
bell = '\a' # yes
else:
bell = '' # no sound
# usage:
print('%shello' % bell)
print('{}{}'.format(bell, 'hello'))
s = input('{}{}'.format(bell, 'user input'))
这样的函数中,这样你就不必总是写那些打印/输入行。