Slack seems to always wrap code blocks. It makes python particularly shit to read.
It depends on the terminal. Some will actually preserve the line breaks vs soft wraps. Those terminals will reflow the text when you resize the window.
But if you already have the file you might as well run something like `xclip <file` to copy its contents directly to the clipboard.
As for attaching a file, I'm usually screenshotting small amounts of code - usually of the ephemeral variety.