Python Forum
Why is Python so hard to maintain
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is Python so hard to maintain
#14
(Aug-15-2019, 05:01 PM)buran Wrote:
(Aug-15-2019, 04:16 PM)RMJFlack Wrote: BUT in Python 3.7, struct.pack is changed to byte type from string, and I'm having a real tough time trying to fix the code to with with it.
struct.pack() in 3.3.
Quote:struct.pack(fmt, v1, v2, ...)

Return a bytes object containing the values v1, v2, ... packed according to the format string fmt. The arguments must match the values required by the format exactly.
struct.pack() in 3.7.
Quote:struct.pack(format, v1, v2, ...)

Return a bytes object containing the values v1, v2, … packed according to the format string format. The arguments must match the values required by the format exactly.

So, in both 3.3 and 3.7 struct.pack() returns bytes object. There is no change according to official docs. Probably the problem is somewhere else in your code.

Hmmm ... you are right, It is IS 4 years since I looked at this code, and it was originally in 2.7. So Im not sure what the 3.3 version was about.
It seems to me the best way forward is to move to 3.7
I just need to make sure that the file created by struct.pack() in 3.7 (with bytes output) is the same as in 2.7 with string output.
Would this be the correct 'conversion' code:
def pack2string(byt):
    s = ""
    for b in byt:
        s += chr(b)
    return s

pixels += pack2string(struct.pack('<BBB',b,g,r))
I believe that in 2.7 each pixel formatted by struct.pack() is a triple of chr; in 3.3 it is a triple of int. Is that correct?
Reply


Messages In This Thread
Why is Python so hard to maintain - by RMJFlack - Aug-15-2019, 02:33 PM
RE: Why is Python so hard to maintain - by wavic - Aug-15-2019, 02:57 PM
RE: Why is Python so hard to maintain - by RMJFlack - Aug-15-2019, 03:08 PM
RE: Why is Python so hard to maintain - by RMJFlack - Aug-15-2019, 03:42 PM
RE: Why is Python so hard to maintain - by snippsat - Aug-15-2019, 04:09 PM
RE: Why is Python so hard to maintain - by RMJFlack - Aug-15-2019, 04:16 PM
RE: Why is Python so hard to maintain - by buran - Aug-15-2019, 05:01 PM
RE: Why is Python so hard to maintain - by RMJFlack - Aug-15-2019, 05:48 PM
RE: Why is Python so hard to maintain - by buran - Aug-15-2019, 07:04 PM
RE: Why is Python so hard to maintain - by RMJFlack - Aug-15-2019, 10:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Hire a Python Programmer? It's hard because I don't know pythonforumuser 1 1,679 Feb-10-2020, 12:02 PM
Last Post: metulburr
  how hard to translate this to python? Skaperen 4 3,991 Oct-18-2017, 07:37 AM
Last Post: buran
  Should Learn Python The Hard Way's be in the forums list of books Yoriz 16 14,492 Nov-09-2016, 05:47 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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