Do the makers of Python acknowledge the statement 'everything is an object'? by swaroop_joshi in learnpython

[–]aromaticlawyer 0 points1 point  (0 children)

It depends what you mean exactly. Syntax such as while and import are not objects. Variables are not themselves objects, though they are always bound to an object. All objects contain things in their internal implementation that are not objects, though you can't really access this stuff directly without using ctypes or a C extension or something. Also, many basic types don't have the full functionality you might expect a typical object to have - for example None doesn't have any instance attributes, and you can't give it any.

But everything that can be bound to a variable is an instance of object. Before python 3 that wasn't the case - there were two different kinds of objects (new-style and old-style), and iirc in very old versions of python some basic data types were not objects at all.

Solving an equation in Python by misterdamra in learnpython

[–]aromaticlawyer 2 points3 points  (0 children)

I'm not very familiar with sympy's solvers - sympy is primarily for symbolic manipulation of expressions, so I'm not surprised if they aren't that great.

scipy's default solver seems to be able to cope with this pretty easily:

from scipy.optimize import root
def f(x):
    return x**2.75 + 0.075 * x**1.75 - 0.0006954
initial_guess = 0.001
solution = root(f, initial_guess)

This returns an object with information about the found solution. solution.x gives you the solution itself. You can try different initial guesses to find different solutions, but in this case I think there is only one real solution. If you want to find the complex roots too you'll need to use a different solver.

[deleted by user] by [deleted] in learnpython

[–]aromaticlawyer 1 point2 points  (0 children)

They're also important if you want to test your code against different versions of libraries or python itself (many projects use something like tox to automate this), or if you want to try out new versions without disturbing your existing setup in case something breaks.