Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 以微秒为单位的时间-日期差_Python_Datetime - Fatal编程技术网

Python 以微秒为单位的时间-日期差

Python 以微秒为单位的时间-日期差,python,datetime,Python,Datetime,我对Python非常陌生,我在计算两次之间的差异时遇到了问题 我有一个文件,其中包含一个列表,其中包含一条特定消息离开的时间和一条消息返回的时间。每一个都显示在不同的行上。每一个都以微秒为单位记录。我想取一张照片,找出两者之间的差异,然后打印结果 非常感谢你帮助我!我真的很感激 一般程序包括首先读取文件,例如: with open('/path/to/file') as input_file: for line in input_file: # 'line' is the

我对Python非常陌生,我在计算两次之间的差异时遇到了问题

我有一个文件,其中包含一个列表,其中包含一条特定消息离开的时间和一条消息返回的时间。每一个都显示在不同的行上。每一个都以微秒为单位记录。我想取一张照片,找出两者之间的差异,然后打印结果


非常感谢你帮助我!我真的很感激

一般程序包括首先读取文件,例如:

with open('/path/to/file') as input_file:
    for line in input_file:
        # 'line' is the contents of each line (including line termination characters)
        # ... the strings representing the times are obtained here ...
以微秒为单位的计算可以简单地用

int(time1_string)-int(time0_string)

类型转换很重要(它将字符串转换为数字,以便对其执行数学运算)。

您能发布一些示例数据和您迄今为止尝试过的内容吗?列表中有许多输入和输出消息,这会区分每次不同的集合吗?您需要在问题中添加一个具体的文件行示例,因为您的问题无法用可用信息完全回答。:)