Pycharm keeps changing file open mode to wb... WHY?????

This is driving me nuts. Pycharm keeps automatically changing file open modes to 'wb' or 'rb'. Then invariably, on code I don't think I've modified in a long time, I get errors saying it expected a bytes like object because previously I had been treating it as in string mode. I'm guessing this has something to do with reformatting the file and python 2.6 back compatibility but I figured I'd ask if anybody knows how to change this behavior that keeps breaking my scripts???

Thanks,

Brad

5 comments

Hi Brad,

 

Please specify what do you mean by "python 2.6 back compatibility"? Can you also provide code sample or screencast showing your issue?

I assume you mean that something like `open('file.txt', 'r')` in your code changes to `open('file.txt', 'rb')` ?

0

Yes everywhere in the code in multiple projects I've had open('file.txt', 'r') changed to open('file.txt', 'rb'). Simple as that. I very rarely want to open files in binary mode so I'm 100% sure I'm not doing this. My question is how would this occur? I have very few plugins installed (bashsupport, cmd support, csv plugin, json viewer, r language support) so I don't think it's any of those. The whole 2.6 compatibility was a guess as to what is doing this but it's probably a red herring. 

0

This is very strange, PyCharm shouldn't do that. I've looked through code inspection and intention settings and found nothing that could change file modes in the code, unless I'm missing something.

Do you have a way to reliably reproduce this behavior? Like, running a code inspection or reformatting? Or you don't know when it's occurring?

0

It seems to have occurred a limited number of times but I can't reproduce it (heck it could be something non-pycharm though I can't think of anything else??? git?). I guess I'll assume that this was a one off deal and move on but I was sitting here scratching my head and figured I'd ask.

0

You did the right thing to ask, but as I've mentioned, PyCharm does not change the code in the way you describe. Maybe you have some other code analyzer tools or something similar running? Most likely the change was done from outside of PyCharm.

If it keeps happening, and you can't find any explanation, I suggest trying to reproduce the issue on another computer, to clear out possible unknown factors.

0

Please sign in to leave a comment.