So i am trying to get a file of just the binary in ex23. i have added a few lines just to have a file called raw.txt and write the binary to it. it is defined as raw = open("raw.txt:, “wb”)
if i print the line raw_bytes it works. but if i try the following i never get the raw bytes in the file:
the file only writes the encoded format. Can you please help me understand why?
here is my code:
script, encoding, error = sys.argv
raw = open(“raw.txt”, “wb”)
cooked = open(“cooked.txt”, “w”)
def main(language_file, encoding, errors):
print(">>>>> main", repr(language_file))
line = language_file.readline()
print_line(line, encoding, errors)
return main(language_file, encoding, errors)
def print_line(line, encoding, errors):
next_lang = line.strip()
raw_bytes = next_lang.encode(encoding, errors=errors)
cooked_string = raw_bytes.decode(encoding, errors=errors)
print(raw_bytes, "<===>", cooked_string)
languages = open(“languages.txt”, encoding=“utf-8”)
main(languages, encoding, error)
Mate, put this around your code
[/code1] #remove 1
I dont mean to ask stupid questions but around which code?
Can anyone help me with this?
If you want the code to be more visible as code you can wrap it with this text formating before and after your code.
It will look like this:
However. I have problem with blank lines when using this formating.
I have used this one “>” in front of every line.
It looks ok in Firefox.
Sorry have been away. You need to set it out like this
paste code in here
and no you are not stupid.
Actually, just skip that part of the exercise. It doesn’t really make sense. My original intention was that you’d write out the converted bytes as a Python string with the \x00 kind of syntax but then after it was published that kind of got clobbered and the resulting exercise doesn’t make sense. The file already is in binary, so there’s no conversion going on.