Can't open and read files after upgrade from 0.10 to 0.10.0 #248

Closed
oolon opened this Issue Jan 18, 2011 · 7 comments

Comments

Projects
None yet
2 participants

oolon commented Jan 18, 2011

Using IPython after upgrading from 0.10 to 0.10.1 made all my attempts to open and read text file just an error. Here is an example from a session:

[~]|4> txt = open('untitled').read()

TypeError Traceback (most recent call last)

/home/oolon/ in ()

TypeError: function takes at least 2 arguments (1 given)

[~]|5> txt = open('untitled', 'r').read()

TypeError Traceback (most recent call last)

/home/oolon/ in ()

TypeError: an integer is required

[~]|6> f = open('untitled', 'r')

TypeError Traceback (most recent call last)

/home/oolon/ in ()

TypeError: an integer is required
[~]|7>

There is nothing wrong with the file itself, a workaround using the subprocess module works:

]|8> from subprocess import Popen, PIPE, call
[
]|9> txt = Popen(['cat', 'untitled'], stdout=PIPE).communicate()[0]
[]|10> txt
<10> "\n[vec1[i]*vec2[i] for i in range(3)]\n[8, 12, -54]\n\nas a list comprehension:\n[str(round(355/113.0, i)) for i in range(1,6)]\n['3.1', '3.14', '3.142', '3.1416', '3.14159']\n vs map:\nmap(lambda x: str(round(355/113.0, x)), range(1,6))\n['3.1', '3.14', '3.142', '3.1416', '3.14159']\n\n\n"
[
]|11> len(txt)
<11> 281
[~]|12>

Owner

takluyver commented Jan 18, 2011

I can't replicate in a virtualenv. How did you upgrade? How was 0.10 installed originally? Are you just using ipython to invoke it? And have you tried removing it and installing it anew?

oolon commented Jan 18, 2011

I had upgraded with easy_install since Ubuntu repositories are still using 0.10, but I have since removed 0.10.1 and reinstalled 0.10 using aptitude and was still having the same problem until I removed my .ipython/ directory. I'm not sure yet what caused the bad ju ju but I'd guess it was something in the ipy_user_conf.py file which had been modified. Here is the diff:
33c33

< import ipy_profile_sh

# import ipy_profile_sh

57c57

< import_all("os sys")

#import_all("os sys")

73c73

< o.autoexec.append('%colors Linux')

#o.autoexec.append('%colors Linux')

76c76

< o.autoexec.append('from future import division')

#o.autoexec.append('from __future__ import division')
Owner

takluyver commented Jan 18, 2011

Which stages are you diffing between? Did you uncomment those lines with ipython 0.10, and installing 0.10.1 overwrote them with the default commented versions? Or did the upgrade uncomment them? If you install 0.10.1 again (don't feel compelled to do this if you're busy), does the same error occur?

oolon commented Jan 18, 2011

The diff was between the original out of the box version and the one that was giving me a problem. On a hunch I have since modified the file again but I kept #import_all("os sys") commented out and the problem did not return. So it looks like it was import_all() that was the problem. I took a look at the os module and it does have its own "open" method. To me it looks like it wouldn't be a problem, but it could easily be something above and beyond my current understanding.

oolon commented Jan 18, 2011

Hmmm, I guess it is the os module's open method that is at fault, open and os.open are not the same. I guess import_all("os", "sys") would import os.open as just 'open' and override the built-in 'open' function. If so you should be able to duplicate the issue by uncommenting the #import_all("os", "sys") line in ipy_user_lconf.py too.

oolon commented Jan 18, 2011

Ooops, sorry! I forgot to make it clear that the version doesn't matter, I was wrong about the 0.10.1 upgrade being at fault. 0.10 and 0.10.1 both had the same problem, I just first noticed it after the upgrade and jumped to a false conclusion. It is probably time to revisit the wisdom of import_all() in the config file.

Owner

takluyver commented Jan 18, 2011

OK, I see it. os.open expects a file number, rather than a name. Hence "an integer is required". So, yes, doing import_all("os") is a bad idea, and we should probably remove it from the config file, even in commented out form.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment