PermissionError: [Errno 13] in Python

When doing; …you’re trying to open a directory as a file, which may (and on most non UNIX file systems will) fail. Your other example though; should work well if you just have the permission on a.txt. You may want to use a raw (r-prefixed) string though, to make sure your path does not contain … Read more

What is the python keyword “with” used for? [duplicate]

In python the with keyword is used when working with unmanaged resources (like file streams). It is similar to the using statement in VB.NET and C#. It allows you to ensure that a resource is “cleaned up” when the code that uses it finishes running, even if exceptions are thrown. It provides ‘syntactic sugar’ for … Read more

File open and close in python

The mile-high overview is this: When you leave the nested block, Python automatically calls f.close() for you. It doesn’t matter whether you leave by just falling off the bottom, or calling break/continue/return to jump out of it, or raise an exception; no matter how you leave that block. It always knows you’re leaving, so it … Read more

Where is BeautifulSoup4 hiding?

Try import bs4. It’s unfortunate there’s no correspondence between PyPI package name and import name. After that the class names are the same as before eg. soup = bs4.BeautifulSoup(doc) will work. If that still doesn’t work, try pip install again and note the path to the package install. Then in your python console run import … Read more

Permanently add a directory to PYTHONPATH?

You need to add your new directory to the environment variable PYTHONPATH, separated by a colon from previous contents thereof. In any form of Unix, you can do that in a startup script appropriate to whatever shell you’re using (.profile or whatever, depending on your favorite shell) with a command which, again, depends on the … Read more

How is Anaconda related to Python?

Anaconda is a python and R distribution. It aims to provide everything you need (Python-wise) for data science “out of the box”. It includes: The core Python language 100+ Python “packages” (libraries) Spyder (IDE/editor – like PyCharm) and Jupyter conda, Anaconda’s own package manager, used for updating Anaconda and packages Your course may have recommended … Read more