Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

replaced http://physics.stackexchange.com/ with https://physics.stackexchange.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives? How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

The book "CODE The Hidden Language of Computer Hardware and Software" provides a very gentle introduction into how information is represented in computers — the word "byte" is not defined until page 180. To see through abstraction levels used in computers, the course "From NAND to Tetris" can help.

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

The book "CODE The Hidden Language of Computer Hardware and Software" provides a very gentle introduction into how information is represented in computers — the word "byte" is not defined until page 180. To see through abstraction levels used in computers, the course "From NAND to Tetris" can help.

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

The book "CODE The Hidden Language of Computer Hardware and Software" provides a very gentle introduction into how information is represented in computers — the word "byte" is not defined until page 180. To see through abstraction levels used in computers, the course "From NAND to Tetris" can help.

add links to introductory resources
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

The book "CODE The Hidden Language of Computer Hardware and Software" provides a very gentle introduction into how information is represented in computers — the word "byte" is not defined until page 180. To see through abstraction levels used in computers, the course "From NAND to Tetris" can help .

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

The book "CODE The Hidden Language of Computer Hardware and Software" provides a very gentle introduction into how information is represented in computers — the word "byte" is not defined until page 180. To see through abstraction levels used in computers, the course "From NAND to Tetris" can help .

answer what it's reading
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

'rb' mode enables you to read raw binary data from a file in Python:

with open(filename, 'rb') as file:
 raw_binary_data = file.read()

type(raw_binary_data) == bytes. bytes is an immutable sequence of bytes in Python.

Don't confuse bytes and their text representation: print(raw_binary_data) would show you the text representation of the data e.g., a byte 127 (base 10: decimal) that you can represent as
bin(127) == '0b1111111' (base 2: binary) or as hex(127) == '0x7f' (base 16: hexadecimal) is shown as b'\x7f' (seven ascii characters are printed). Bytes from the printable ascii range are represented as the corresponding ascii characters e.g., b'\x41' is shown as b'A' (65 == 0x41 == 0b1000001).

0x7f byte is not stored on disk as seven ascii binary digits 1111111, it is not stored as two ascii hex digits: 7F, it is not stored as three literal decimal digits 127. b'\x7f' is a text representation of the byte that may be used to specify it in Python source code (you won't find literal seven ascii characters b'\x7f' on disk too). This code writes a single byte to disk:

with open('output.bin', 'wb') as file:
 file.write(b'\x7f')

Some kind of characters must be used to represent the bytes, what are they?

OS interfaces (the way you access hardware such as disks) are defined in terms of bytes e.g., POSIX read(2) i.e., the byte is a fundamental unit here: you can read/write bytes directly -- you don't need any intermediate representation. Watch Richard Feynman. Why.

How bytes are represented physically is between OS drivers and the hardware -- it may be anything -- you don't need to worry about it: it is hidden behind the uniform OS interface. See How is data physically written, read and stored inside hard drives?

You could call os.read() directly in Python but you don't need it; file.read() does it for you (Python 3 file objects are implemented on top of POSIX interface directly. Python 2 I/O uses C stdio library that in turn uses OS interfaces to implement its functionality).

As you point out, it's up to the OS drivers and hardware to establish how bytes are written, but the Python interpreter would then be able to read them. So it's reading something - what is that? It's not reading magnetic orientation of particles on the disk, is it? It's reading something symbolic, and I want access to it.

It's reading bytes. A hard disk is a small computer and therefore interesting things may happen but it does not change that It's bytes all the way down (as far as "symbolic" or software is concerned).

added 2 characters in body
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
Loading
add video link
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
Loading
added 255 characters in body
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
Loading
answer how bytes are represented
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
Loading
typo
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
Loading
grammar
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
Loading
Source Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /