Python Forum
Read characters of line and return positions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read characters of line and return positions
#3
Iterating on deanhystad solution. It's more lines of code but presumably if you return to it in couple of weeks this makes much easier to remember what it's all about.

data = "0000009887465 000002250000000000089877000000000000.0002/28/202000000000.00000000000.00"

first_ID = slice(6, 13)
second_ID = slice(19, 22)
date = slice(53, 63)

extracted = f'{data[first_ID]} {data[second_ID]} {data[date]}'
print(extracted) -> 9887465 225 02/28/2020
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Read characters of line and return positions - by perfringo - Nov-04-2020, 09:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Special Characters read-write Prisonfeed 1 612 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 819 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,397 Feb-13-2022, 07:13 PM
Last Post: menator01
  Why not getting return on line #16? jahuja73 12 4,393 Feb-12-2021, 02:48 PM
Last Post: deanhystad
  read the first line in my script chubbychub 1 1,752 Nov-09-2020, 03:18 AM
Last Post: Larz60+
  Adding Sliced Positions Gizzmo28 1 1,598 Nov-05-2020, 02:46 AM
Last Post: bowlofred
  Print characters in a single line rather than one at a time hhydration 1 2,025 Oct-10-2020, 10:00 PM
Last Post: bowlofred
  Read/Sort Large text file avoiding line-by-line read using mmep or hdf5 Robotguy 0 2,048 Jul-22-2020, 08:11 PM
Last Post: Robotguy
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,684 May-15-2020, 01:37 PM
Last Post: snippsat
  How to Remove Non-ASCII Characters But Leave Line Breaks In Place? bmccollum 4 4,300 Apr-09-2020, 07:59 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020