python中的减号_我的python把减号和破折号混淆了

我尝试使用“python get”运行以下python_时间戳.py-f格沙姆_输入.xvg-1−0.1348-2−0.1109“。但是,python似乎把小数前的减号和破折号弄错了,并显示了这个错误:“File”get_时间戳.py“,第21行,英寸

值1=浮点(arg)

值错误:float()的文本无效:−0.1348

"

你能帮我知道怎么解决吗?在

谢谢。在#!/usr/bin/env python

"""

Given two values, looks in a 3 column-file (output of sham.pl)

which time frame matches closest.

"""

import sys

USAGE = "USAGE: get_timestamp.py -f -1 -2 \n"

# Parse arguments

read_input, read_value1, read_value2 = False, False, False

input_file, value1, value2 = None, None, None

for arg in sys.argv[1:]:

if read_input:

read_input = False

input_file = arg

elif read_value1:

read_value1 = False

value1 = float(arg)

elif read_value2:

read_value2 = False

value2 = float(arg)

if arg[0] == "-":

if arg == "-f":

read_input = True

continue

elif arg == "-1":

read_value1 = True

continue

elif arg == "-2":

read_value2 = True

else:

print USAGE

sys.stderr.write('ERROR: Option not recognized: %s\n' %arg)

sys.exit(1)

if not input_file:

print USAGE

sys.stderr.write('ERROR: You forgot to provide an input file.\n')

sys.exit(1)

# Open sham output

x_values, y_values, time_values = [], [], []

fhandle = open(input_file)

for line in fhandle:

if line[0] != "#" and len(line.split()) == 3:

t,x,y = line.split()

x_values.append(float(x))

y_values.append(float(y))

time_values.append(float(t))

fhandle.close()

def find_common_frame(min_x, min_y):

for xval in min_x:

xframe = xval[0]

for yval in min_y:

yframe = yval[0]

if xframe == yframe:

return (xframe, xval[1], yval[1])

return (None, None, None)

# If you cannot find anything, try increasing the nval variable

nval = 50

min_x = sorted(enumerate(x_values), key=lambda x: abs(x[1]-value1))[:nval]

min_y = sorted(enumerate(y_values), key=lambda x: abs(x[1]-value2))[:nval]

frame, x, y = find_common_frame(min_x, min_y)

if not frame:

print "No timestamp found.."

sys.exit(0)

print "## T = %s (%s, %s)" %(time_values[frame], x, y)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值