Python将数据作为二进制字符串而不是日志文件中的文本读取

时间:2016-03-26 22:05:25

标签: python file text

我有一个包含计算机日志的文件。当我在notepad ++中打开它时,前几行看起来像这样 -

#####################
[2015/07/03, 13:26:40.368,  INFO, 00004588] Legacy mode. Epoch number not found. Allowing message.
[2015/07/03, 13:26:40.368,  INFO, 00004588] >>>AgentGetState() called.
[2015/07/03, 13:26:40.368,  INFO, 00004588] AgentGetState Returning 00000000.<<<
[2015/07/03, 13:26:54.660,  INFO, 00010404] Subject name = am4prdapp09.fc.core.windows.net
[2015/07/03, 13:26:54.660,  INFO, 00010404] Legacy mode. Epoch number not found. Allowing message.
######################

现在,我在python中阅读它们 -

f = open("log_file.log")
a = []
for i in f:
    a.append(i)

现在我看一下内容:

a[0]

这就是我所看到的 -

'\xff\xfe[\x002\x000\x001\x005\x00/\x000\x007\x00/\x000\x003\x00,\x00 \x001\x003\x00:\x002\x006\x00:\x004\x000\x00.\x003\x006\x008\x00,\x00 \x00 \x00I\x00N\x00F\x00O\x00,\x00 \x000\x000\x000\x000\x004\x005\x008\x008\x00]\x00 \x00
\x00j\x00e\x00c\x00t\x00 \x00n\x00a\x00m\x00e\x00 \x00=\x00 \x00a\x00m\x004\x00p\x00r\x00d\x00a\x00p\x00p\x000\x009\x00.\x00f\x00c\x00.\x00c\x00o\x00r\x00e\x00.\x00w\x00i\x00n\x00d\x00o\x00w\x00s\x00.\x00n\x00e\x00t\x00\r\x00\n'

我错过了什么?

1 个答案:

答案 0 :(得分:2)

尝试:

    var StudentSchema = new Schema({
    firstName: {
        type: String,
        trim: true,
        default: ''
        //validate: [validateLocalStrategyProperty, 'Please fill in your first name']
    },
    lastName: {
        type: String,
        trim: true,
        default: ''
        //validate: [validateLocalStrategyProperty, 'Please fill in your last name']
    },
    worksnap: {
        user: {
            type: Object
        },
        timeEntries: {
            type: Object
        },
     }
   });