@SnoopJeDi/

ProfitableRecklessFlashdrives

Python

No description

fork
loading
Files
  • main.py
  • input.txt

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5849637695235306","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwppbXBvcnQgcmUKCnN0YXJ0ID0gJz5TSE9XIEVOQ0xPU1VSRSBJTkZPJwplbmQgPSAnPlNIT1cgRU5DTE9TVVJFIExFRCcKCiMgZmlyc3Qgd2F5LCBraW5kYSBzbG9wcHB5CndpdGggb3BlbignaW5wdXQudHh0JywgJ3InKSBhcyBmOgogICAgbGluZXMgPSBmLnJlYWRsaW5lcygpCiAgICB0cnk6CiAgICAgICAgc2lkeCA9IG5leHQoaWR4IGZvciBpZHgsIGxpbmUgaW4gZW51bWVyYXRlKGxpbmVzKSBpZiBsaW5lLnN0YXJ0c3dpdGgoc3RhcnQpKQogICAgICAgIGVpZHggPSBuZXh0KGlkeCBmb3IgaWR4LCBsaW5lIGluIGVudW1lcmF0ZShsaW5lcykgaWYgbGluZS5zdGFydHN3aXRoKGVuZCkpCiAgICAgICAgcmVzdWx0ID0gbGluZXNbc2lkeCsxOmVpZHhdCiAgICBleGNlcHQgU3RvcEl0ZXJhdGlvbjogIyBvbmUgb2YgdGhlIGluZGV4IGxpbmVzIGZhaWxlZAogICAgICAgIHJlc3VsdCA9ICdObyByZXN1bHQhJwoKcHJpbnQoKnJlc3VsdCkKCiMgc2Vjb25kIHdheSwgbXVjaCBuaWNlciEKd2l0aCBvcGVuKCdpbnB1dC50eHQnLCAncicpIGFzIGY6CiAgICBfLCBfLCBkYXRhID0gZi5yZWFkKCkucGFydGl0aW9uKHN0YXJ0KQogICAgcmVzdWx0LCBfLCBfID0gZGF0YS5wYXJ0aXRpb24oZW5kKQoKcHJpbnQocmVzdWx0KQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
import re

start = '>SHOW ENCLOSURE INFO'
end = '>SHOW ENCLOSURE LED'

# first way, kinda slopppy
with open('input.txt', 'r') as f:
    lines = f.readlines()
    try:
        sidx = next(idx for idx, line in enumerate(lines) if line.startswith(start))
        eidx = next(idx for idx, line in enumerate(lines) if line.startswith(end))
        result = lines[sidx+1:eidx]
    except StopIteration: # one of the index lines failed
        result = 'No result!'

print(*result)

# second way, much nicer!
with open('input.txt', 'r') as f:
    _, _, data = f.read().partition(start)
    result, _, _ = data.partition(end)

print(result)