Python Forum
Having a hard time conceptualizing how to print something
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having a hard time conceptualizing how to print something
#1
I have a table of bytes (actually they're bit flags, but one concept at a time), as below.
FB 2C D2 93 40 00 00 00 00 00 00 00 EA C8 61 00 
F9 AA F0 D7 C0 00 00 00 00 00 00 00 FD 28 CA 00 
E2 49 B4 8B 50 00 00 00 00 00 00 00 F2 4B CE 00 
E8 99 A4 4B B0 00 00 00 00 00 00 00 E1 37 D7 00 
82 0E 00 C3 40 00 00 00 00 00 00 00 DE 89 19 00 
F5 F1 FB 1F F0 00 00 00 00 00 00 00 E3 FE E6 00 
FA E7 D2 DF D0 00 00 00 00 00 00 00 F5 EC F5 00 
FF F9 FF 1F F0 00 00 00 00 00 00 00 F4 BD 79 00 
FB C6 92 D3 20 00 00 00 00 00 00 00 FF FA FE 00 
FB C9 54 03 D0 00 00 00 00 00 00 00 FF 13 0A 00 
C9 96 92 CB B0 00 00 00 00 00 00 00 C5 1E BD 00 
FB EE D2 C3 77 00 00 00 00 00 07 FC EA E9 F9 00 
FD F9 FD 57 E0 00 00 00 00 00 00 00 F7 7D 7D 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I want to print it with the columns and rows switched, as done partially below.
FB F9 ...
2C AA ...
D2 F0 ...
93 D7 ...
40 C0 ...
00 00 ...
00 00 ...
00 00 ...
00 00 ...
00 00 ...
00 00 ...
00 00 ...
EA FD ...
C8 28 ...
61 CA ...
00 00 ...
I'm having a hard time mentally grasping how to track and iterate the seeks to do this.

My code:
import io,sys

with open(sys.argv[1], 'rb') as scus:
    baseAddr =58364 
    #scus.seek(baseAddr)
    #print(scus.read(1)[0], end='\' ')
    with open("sparks.txt", 'w') as writer:
       listCtr = 0
       entryCtr = 0
       while listCtr < 16:
           scus.seek(baseAddr + listCtr + entryCtr)
           print(hex(scus.read(1)[0])[2:].zfill(2) + "-")
           listCtr += 1
       print()
My output:
python extractSparkTalents.py SCUS_942.30
fb-
2c-
d2-
93-
40-
00-
00-
00-
00-
00-
00-
00-
ea-
c8-
61-
00-
It seems like it requires recursion, or maybe a specialized type of string splitting where you put line breaks between the strings.

I'm not sure if you can seek in lines in a text file either, and how writing behaves in such a case.

edit

Or maybe it requires stores, since it's sort of a sorting algorithm?
Reply


Messages In This Thread
Having a hard time conceptualizing how to print something - by MysticLord - Sep-19-2020, 07:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Hard time trying to figure out the difference between two strings carecavoador 2 698 Aug-16-2023, 04:53 PM
Last Post: carecavoador
  Print names in x-axis of a time-series values hobbyist 4 1,266 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  How to print results of asyncio websockets at the same time? codingmonster 0 1,784 Jun-04-2021, 01:48 PM
Last Post: codingmonster
  Conceptualizing modulus. How to compare & communicate with values in a Dictionary Kaanyrvhok 7 4,070 Mar-15-2021, 05:43 PM
Last Post: Kaanyrvhok
  Print characters in a single line rather than one at a time hhydration 1 2,055 Oct-10-2020, 10:00 PM
Last Post: bowlofred
  How to print n days back date at give time Mekala 1 2,006 Oct-10-2020, 03:35 AM
Last Post: bowlofred
  Having hard time understanding the function self-returning itself twice jagasrik 2 2,525 Aug-15-2020, 08:50 PM
Last Post: deanhystad
  The count variable is giving me a hard time in this code D4isyy 2 1,990 Aug-09-2020, 10:32 PM
Last Post: bowlofred
  Print a certain string only the first time it appears in a test file buttercup 5 2,833 Jul-23-2020, 01:30 PM
Last Post: palladium
  Having a hard time combining two parts of code. Coozeki 6 3,141 May-10-2020, 06:50 AM
Last Post: Coozeki

Forum Jump:

User Panel Messages

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