« first day (2355 days earlier)      last day (2592 days later) » 

10:02 PM
im back with a more "specific" question
when i write to a file using "wb", i get a bunch of random 00's or 33's at the end (values are in hex)
i have no idea why
 
what are you writing to the file?
 
[66,77,filesize,0,0,0,0,0,0,0,54,0,0,0,40,0,0,0,size,0,0,0,size,0,0,0,1,0,8,0,0,‌​0,0,0,size**2 + padding*size,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0]
using f.write(bytes(list_name))
and im using notepad++ to view the data in hex
 
only dead programmers are 100% sure. Do your work, try to write some code and ask specific and detailed question on errors or unwanted results please. This question is too broad you are asking someone to write a complete working class for you. — dparoli 5 mins ago
lol.
 
Marx would be proud if you just wrote a working class.
 
resolve : i think it might just be my notepad++ bugging out
 
10:06 PM
norton commander used to have a neat hex editor...
 
vim has a hex editor
 
is there vim for windows?
 
Well, it can be used as one. I think you need xxd available
 
and I think vim can just use a hex dump using xxd
 
@davidism what was confusing to me was the file size due to the extra padding needed in some cases
:/ 255 is being represented as "d19f"
hmm
 
10:15 PM
255 sounds like ff
 
yea i know
d19f isnt even close too far XD
 
d19f has more bits
2 bytes instead of 1, right?
 
yes
 
>>> int('d19f',base=16)
53663
>>> int('d1',base=16)
209
>>> int('9f',base=16)
159
 
yes
either way, its not 255
and im not sure why
in my list to which i do f.write(bytes(list)), i explicitly wrote ([..,..,255,..] (".." arent actually .., just any data which doesnt matter)
everything before and after the 255 is fine, just the 255
changing it to 254 produces d1 9e
changing it to 100 produces 64 which is correct
i dont understand
 
10:21 PM
Something about endianness perhaps? Vague guesses here
that's probably stupid
 
now im getting random data inside
 
"random"
 
i say random because i didnt specify it to be in there
its decimal value is nowhere in my lists
plus they are literally in random places
my list that im writing to the file "[204,243]", the output im getting in the file "d0 ac d1 93 00"
the only code inbetween is f.write(bytes(list))
 
which hopefully you don't actually call list ;)
 
no no i dont XD
its actually a list from another list
so using for i in grid:
f.write(bytes(i))
 
10:27 PM
are you sure the padding is correct?
 
yes im sure the padding is correct, dont know how to format it here
 
if your padding is off, your bytes will get shifted
@SylentNyte ctrl+k for a multiline message
(it indents every line by 4 spaces)
 
trial and error haha
 
you have 2 minutes to edit
 
Are you sure this is Python 3?
 
10:28 PM
 
@user2357112 yes
    for i in grid:
        f.write(bytes(i))
        print(i)
        f.write(bytes(temp))
    f.close()
the padding is off
just by a bit
 
you can't reply with a multiline code message, I think
 
there
thats my code
where i is:
"[137, 251]
[225, 8]"

respective of iteration
temp = [0,0]
output = c2 89 d1 9b 00 d1 81 08 00
 
Post a question on the main site, not chat, with a [mcve]. That'd probably consist of code that opens a file in wb mode and writes a single bytes object to the file, along with a hex dump of the file's contents after running the code.
I guess [mcve] doesn't work here.
 
[mcve] would be...?
 
MCVE. Shortest code necessary to demonstrate the error. Usually involves stripping out a lot of code important to your program's functionality but not important to reproducing the error.
 
got it
let me try some stuff beforehand tho
 
and make sure that notepad++ isn't a noisy channel
 
@AndrasDeak not too sure what you mean by this
if you're talking about when viewing the file, i re-open it every time
 
no, I'm just cautious with everything that has "notepad" in its name;)
 
10:41 PM
could it be something with python and its memory?
i restarted python and the first try it worked fine
second try, random values
nah its not, okay posting
 
I think in this case it'll be fine if you link it here (since discussion started here and you were explicitly asked to ask on main)
just don't one-box it because that's big
 
0
Q: "Random" HEX values when writing to files - Python 3

Sylent NyteThis is part of a script I'm writing to create random bitmap without using modules that create the file (this is going to be used by others who may not know how to use pip etc so I'm not using modules other than random). I created a square grid of a size determined by the user (2 for example): ...

hows that?
 
that's the one-box I was talking about :P
 
is it really too big?
 
import random is missing
@SylentNyte I meant that chat message of yours, but don't worry about it
 
10:54 PM
oh lmao, sorry
 
That's not an MCVE. You're missing relevant imports, and it could probably be made a lot more minimal. Also, the randomness is almost certainly unnecessary for reproducing the problem.
 
randomness is most certainly a problem since your issue is that your file doesn't reproduce your array
especially since we're talking about 2x2 arrays
 
Also, you don't explicitly say anywhere in the question that the file contents you've posted are a hex dump, or how you've produced the dump (for example, why are there quotes?).
 
scrub at asking questions
@AndrasDeak didn't realise it was you who posted, but the values are then set arent they?
after they are randomly generated that is
 
they're set, but the reason Ryan doesn't understand is partly because you're being confusing
and using random numbers as examples, and then calling different numbers "random" is certainly confusing
Imagine how someone unaware of the issue would read your question. Things like How to Ask also help
MCVE you've been pointed to
if you've got more time, read Jon Skeet's take on the subject
 
11:00 PM
i dont know how else to call them other than random
unwanted?
 
wrong
but you first have to specify your problem and question; right now only user2357112 and I know what your issue actually is
 
im rubbish at asking questions, though i try
 
it needs practice, but most importantly empathy towards others, imagining what information they minimally need to understand your issue
@user2357112 when its a fixed byte sequence, it works fine. but arent the values in the 2x2 fixed? — Sylent Nyte 3 mins ago
that's new to me ^
but yeah, they shouldn't change in the printing loop
 
yea
 
can't reproduce
 
11:11 PM
:////
 
2
[218, 189]
2
[192, 29]
$ xxd file.bmp
00000000: dabd c01d
>>> bytes([218, 189,192, 29])
b'\xda\xbd\xc0\x1d'
 
ran it again
 
and i notice that the two values that most occur are d1 d0
 
no repro in 3 runs
 
11:16 PM
Why is this a .bmp file, anyway? Your data doesn't match the BMP file format.
 
@user2357112 started around here
 
yea
i have this beforehand
f.write(bytes(header_info))
which writes fine, so i qouted that out of the code
 
That wasn't in the code you ran when you generated the output in the question, right?
 
no it wasnt in the code i ran
 
"i qouted that out of the code" - as in you're using string literals as comments?
 
11:20 PM
alt+3
double hashed
 
wim
what's the current gpg bindings for python?
3. other...? please specify
 
The code you run should be the exact same code you post. You should be able to literally copy-paste the code you ran into the question box, highlight it, hit the code-formatting button, and post it like that. If you don't want a bunch of commented-out code in your post, there shouldn't be a bunch of commented-out code in what you run.
 
I have a feeling that this will all end in a huge facepalm
 
DSM
@user2357112: did your avatar change recently? Something's flagging my "there's been a disturbance in the Force" sense, and that's my prime suspect.
 
@user2357112 okay
its exactly the same
literally#
same problem :/
think i might start a tally chart of the number of d0 and d1's i see
 
11:33 PM
@DSM: Some weird gravatar thing. I used to be purple, but suddenly their algorithm changed and they gave me a brown version one day. That was actually quite a while ago, but it's taking a while for the purple one to expire from various caches.
 
brb
restarting
 
I only remember the brown one, I guess I hadn't seen you around much before that
Don't you miss the old one? I'm sure the internet archive has it around
 
DSM
My current avatar arrived unexpectedly all the way from Hungary, and I'm confident that's the first time in the history of the human race those words have been put in that order.
 
haha, that's likely:D
 
Huh. You just asked the internet archive for an archived version of my avatar directly.
 
11:37 PM
well, I did go through the archived version of your profile, but yeah
since the hash is the same, so is the URL
 
update
renaming the file works
thus problem lies within changing the file over...?
makes no sense
rewritting the file
 
wim
nobody used gpg in python before?
 
DSM
Sorry.. I've barely used it outside of Python.
 
wim
they both look good, both documented and maintained, one is from vinay (dev of std lib logging) and one is from a core developer of Tor
I'm not clear on significant differences , and why both exists instead of whatever changes merged ..
 
DSM
@SylentNyte: it's far more likely that you're doing something silly than that everything is behaving mysteriously. I find that if I start from the assumption that I'm doing something wrong and look for it, I have better luck than otherwise.
 
11:41 PM
@DSM oh sugar
wait
guys
@AndrasDeak @user2357112 when opening a file in write mode, does it re-write the data?
 
it should, probably, yes
but you're using windows so all bets are off
 
lmao thx
but games run better
@AndrasDeak is this the same for wb?
 
Yes.
 
okay well screw it
ill just rename it some random gibberish everytime
oh no
 
That's the kind of mindset that gives you even more weird problems later.
 
11:45 PM
the problem still persists!
the dreaded d0
i see you lurking in my files ¬_¬
 
*switches it do d1 on Sylent's next run*
 
How are you even viewing hex dumps in Notepad++, anyway? I don't think that's built-in functionality. If you're using a plugin, you should say so.
 
@user2357112 using a plugin
 
What plugin?
 
@AndrasDeak :O IT WORKED ONCE
tho there appears to problems with my header info so i cant view it as an image
agh
 
DSM
11:51 PM
Just to be clear we have no within-Python evidence that anything is going wrong at all, right?
 
@DSM we do not, no
 
nope
I ran Sylent's mcve (3 times, no less!) and the python hex checks out with the file's hex dump
 
DSM
I once got into an argument with a DBA at NumberFirm where I was telling him that one of his tables had garbage content and he didn't want to hear it. But I was much more confident that something went wrong on his end -- a complex and notoriously flaky data pipeline -- than that sqlalchemy suddenly decided to give me deterministically corrupt rows midway through one particular table. :rolls_eyes:
 
I'm waiting for the plot twist ;)
 

« first day (2355 days earlier)      last day (2592 days later) »