如何让用户命名" copied_holter.ecg"他们自己?我提供了这个名字,但我希望用户选择他们想要的任何东西。
class MyParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
parser = MyParser(util_help)
parser.add_argument('filename', help='The full path/to/holter_file that you would like to parse.', action="store")
parser.add_argument('packet_start', help='The offset location of the start packet ID in base 10 decimal', action="store", type = int)
parser.add_argument('packet_end', help='The offset location of the end packet ID in base 10 decimal', action = "store", type = int)
parser.add_argument('new_filename', help='The name of the new file with the copied holter data chosen by user.', action = "store")
args = parser.parse_args()
start = args.packet_start
end = args.packet_end
if start % 5 != 0:
start = int(5*round(float(start)/5))
if end % 5 != 0:
end = int(5*round(float(end)/5))
try:
print("Beginning copying of holter data...")
# Output the specific holter data
output_file = open(new_filename+".ecg", 'w')
答案 0 :(得分:1)
从arg解析file_name
,然后使用类似:
output_file = open(file_name+".ecg", "w")
答案 1 :(得分:-1)
你需要做的就是上线
output_file = open(file_name+".ecg", "w")
替换为
output_file = open(args.new_filename, 'w')