python - errors after upgrading to python3.4 on mac -


after completing upgrading python 2.7 3.4 on mac (10.10.3), can't compile codes.

    python 3.4.3 (v3.4.3:9b73f1c3e601, feb 23 2015, 02:52:03)      [gcc 4.2.1 (apple inc. build 5666) (dot 3)] on darwin     type "copyright", "credits" or "license()" more information.     >>> ================================ restart ================================     >>>      traceback (most recent call last):       file "/users/tpmac/prebs.py", line 31, in <module>         doc = file(os.path.join(subdir,f)).read()     nameerror: name 'file' not defined     >>>  

these codes working python 2.7 on system.

there no builtin file in python3, has been removed use open:

open(os.path.join(subdir,f)).read() 

it better use with when opening file:

 open(os.path.join(subdir,f)) fle:        doc = fle.read() 

there comprehensive guide here on porting code python2 3


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -