“public” or “private” attribute in Python ? What is the best way?

Typically, Python code strives to adhere to the Uniform Access Principle. Specifically, the accepted approach is: Expose your instance variables directly, allowing, for instance, foo.x = 0, not foo.set_x(0) If you need to wrap the accesses inside methods, for whatever reason, use @property, which preserves the access semantics. That is, foo.x = 0 now invokes … Read more

How to read html from a url in python 3

I looked at previous similar questions and got only more confused. In python 3.4, I want to read an html page as a string, given the url. In perl I do this with LWP::Simple, using get(). A matplotlib 1.3.1 example says: import urllib; u1=urllib.urlretrieve(url). python3 can’t find urlretrieve. I tried u1 = urllib.request.urlopen(url), which appears … Read more

Installing Pylab/Matplotlib

I’m trying to write a program that plots a graph, which made me look into Matplotlib. I found a tutorial that started out with this little program, that worked fine: Then I tried to run it on another computer, where it did not work at all. I tried to download Pylab and Matplotlib. When I … Read more

Python: Continuing to next iteration in outer loop

In a general case, when you have multiple levels of looping and break does not work for you (because you want to continue one of the upper loops, not the one right above the current one), you can do one of the following Refactor the loops you want to escape from into a function The … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)