some pythonic questions

got some questions … again (python related)

  1. i have this kind of function:
    def w_BM(string):
    string+= “/X42/X4D”

just to append some text to an existing string, but it appears not to work

  1. if i read a bmp file in binary mode, it’s like /x00/x4D (and so on)
    if i convert a integer i looks like 0x00 0x4d
    so how do i write some hex stuff in binary mode??
def func(string):
    string+="text to add"
    return(string)

You have to return the string afterwards. string += don’t change the string passed in to the function (strings are constants in python btw). It makes a new string and assign it to the local string variable in the function.

Thx Lah for your quick answer!!!
and agoose 77 of course!!!

my idea is to do some basic image creation in blender with pure python

You then might look up python documentation on bytearrays.

If you’re looking to convetr between string and binary lookup the python struct module. For converting binary to and from hex I think you want the binascii module.