Comments (7)
The binary flag for read/write bits help avoid corrupting binary files (e.g. jpeg) on Windows machines, but I've found that it also helps avoid cross-platform headaches when transferring text files between *nix and Windows. I'll admit I can't explain the precise reasons (I'm guessing it's because of differences in the newline character), but I've noticed the binary flag occasionally resolves problems on Windows when shuffling text files between OS. @hbillings That's why we decided a while back it'd just be safer to always use it across the board (and pound it into the heads of all our poor unfortunate students :)
That said, this might be causing more headaches than it's worth in a teaching context (I know we got questions about it every year as well). You might consider dropping it. If and when folks get bit by this in their Python careers, no doubt they'll be able to sort through it by pinging you all or PyJournos :)
Just be sure to test those scripts and data ahead of class if you wind up using Windows machines again!
from pycar.
+1 indeed. It's that thing that I forgot came up last year until we came to it this year.
from pycar.
According to Serdar, who is the one who pounded this into @esagara and me, nothing unexpected happens if you read/write a regular file with the binary option, but if you try to read/write a binary file without the binary option, it causes Bad Things. So it's safer just to always use "rb" and "wb." (Note that I haven't researched this myself, so perhaps there's something else to it, but I tend to trust anyone who smokes cigars with me.)
from pycar.
So in porting the exercises to Python3, I found that trying to read the text files with "rb" was throwing an error. I had to remove the "b" to get it to work. Does anyone know if Python3 handles the binary flag differently for text files? Is this no longer a concern?
from pycar.
@tommeagher I got bit by this too. The "short" answer is that text vs. binary data handling is saner in Python3 -- in a way that now requires the usage of the binary mode only when you actually need bytes of data (rather than encoded characters). In olden 2.x days, the 'b' was often used to ensure file reads worked properly on certain platforms such as Windows, although the flag was generally ignored on Unix-like systems.
A more thorough explanation is here: http://python3porting.com/preparing.html#separate-binary-data-and-strings
from pycar.
This is also helpful imho: https://docs.python.org/3/library/functions.html#open
from pycar.
@zstumgoren got it. This is really helpful. So it seems then this discussion is now moot. Thanks for the advice!
from pycar.
Related Issues (20)
- Refactor project 2 HOT 20
- Use Jupyter notebooks to teach all projects HOT 1
- Final review of code and docs before we land in Jacksonville
- Software requirements HOT 3
- Refresh the intro slide deck
- BeautifulSoup4 may need to be upgraded HOT 3
- Change scraper_notebook.ipynb and scraper_notebook_complete.ipynb to use DictWriter HOT 3
- fix mistakes in scraper README
- Add instructions for getting Jupyter running HOT 4
- Add link to basic instructions for running .py scripts HOT 2
- Rework basics exercise HOT 5
- Refactor exercises to have better variable names HOT 5
- Change basics to include if statements HOT 1
- Tweak ending to solitaire example HOT 3
- sort dataframe before deduplicating HOT 1
- freshen the README and schedule with info for 2019 HOT 2
- what's the deal with the API section in Project 2? HOT 6
- Add newline='' argument to open? HOT 2
- What can be better next year? HOT 3
- Ducks HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycar.