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
#7
(Sep-19-2020, 08:58 PM)jefsummers Wrote: In line 12, inside the right parenthesis add
end = ''
Useless in this context as I'm trying to transpose a matrix, apparently. If I were just trying to print one row as a column your solution would be perfect, but I'm not.

How do I create a list of lists? This doesn't work.
import io,sys

with open(sys.argv[1], 'rb') as scus:
    baseAddr =58364 
    with open("sparks.txt", 'w') as writer:
        scus.seek(baseAddr)
        tblList1 = []
        cntr = 0
        while cntr < 16:
            tblList1.append(scus.read(16))
            cntr += 1
edit

I wrote code whose output must be seen to be believed.

Code 1:
import io,sys

with open(sys.argv[1], 'rb') as scus:
    baseAddr =58364 
    scus.seek(baseAddr)
    with open("sparks.txt", 'w') as writer:
        tblList1 = []
        cntr = 0
        while cntr < 16:
            tblList1.append(scus.read(16))
            #tblList1.insert(cntr, scus.read(16))
            cntr += 1
            for i in tblList1:
                for j in i:
                    print(hex(j)[2:].zfill(2) + "-", end='')
                print()
Output 1:
https://pastebin.com/9rr4XDsD

Code 2:
import io,sys

with open(sys.argv[1], 'rb') as scus:
    baseAddr =58364 
    scus.seek(baseAddr)
    with open("sparks.txt", 'w') as writer:
        tblList1 = []
        cntr = 0
        while cntr < 16:
            #tblList1.append(scus.read(16))
            tblList1.insert(cntr, scus.read(16))
            cntr += 1
            for i in tblList1:
                for j in i:
                    print(hex(j)[2:].zfill(2) + "-", end='')
                print()
Output 2:
https://pastebin.com/e6Aq26KB

I don't know if it's a "feature" of lists in Python, or something to do with the read() method used in binary mode, but it's apparently adding redundant lines over and over again. What should be a 16x16 list becomes a 138x16 list.

edit

Disregard, I am a moron. Here's the fixed code:
import io,sys

with open(sys.argv[1], 'rb') as scus:
    baseAddr =58364 
    scus.seek(baseAddr)
    with open("sparks.txt", 'w') as writer:
        tblList1 = []
        cntr = 0
        while cntr < 16:
            #tblList1.append(scus.read(16))
            tblList1.insert(cntr, scus.read(16))
            cntr += 1
        for i in tblList1:
            for j in i:
                print(hex(j)[2:].zfill(2) + "-", end='')
            print()
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Hard time trying to figure out the difference between two strings carecavoador 2 695 Aug-16-2023, 04:53 PM
Last Post: carecavoador
  Print names in x-axis of a time-series values hobbyist 4 1,257 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  How to print results of asyncio websockets at the same time? codingmonster 0 1,782 Jun-04-2021, 01:48 PM
Last Post: codingmonster
  Conceptualizing modulus. How to compare & communicate with values in a Dictionary Kaanyrvhok 7 4,060 Mar-15-2021, 05:43 PM
Last Post: Kaanyrvhok
  Print characters in a single line rather than one at a time hhydration 1 2,050 Oct-10-2020, 10:00 PM
Last Post: bowlofred
  How to print n days back date at give time Mekala 1 2,003 Oct-10-2020, 03:35 AM
Last Post: bowlofred
  Having hard time understanding the function self-returning itself twice jagasrik 2 2,521 Aug-15-2020, 08:50 PM
Last Post: deanhystad
  The count variable is giving me a hard time in this code D4isyy 2 1,989 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,823 Jul-23-2020, 01:30 PM
Last Post: palladium
  Having a hard time combining two parts of code. Coozeki 6 3,123 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