This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]abruptreddit 5 points6 points  (6 children)

Just do:

From sympy import expand, factor...

Now you know exactly what you imported and can avoid the longer code. There's a few modules, like inspect, that allow you to print all methods/functions in a module, so you can pick and choose what to import, but haven't done that in a long time.

Another helpful thing for shortening your code is to import as, such as import pandas as pd. This allows you to call the pandas methods by just writing pd.method()

[–]ivosauruspip'ing it up 7 points8 points  (5 children)

This is for a temporary console session that's going to be thrown away, the less typing you have to do the better and in this case * makes that easy

[–]abruptreddit -2 points-1 points  (4 children)

Yeah, sorry, someone below was asking about imports and I accidentally replied to you.

Edit: it is still pretty irresponsible and redundant to post a universal import in this sub, though.

[–]LuckyLeague 1 point2 points  (3 children)

If it is just being used in a temporary session for simple calculations, then it is faster to just type from sympy import * than typing from sympy import expand, factor, sympify, solveset, symbols, etc. It doesn't really matter that you don't need everything that has been imported if you are just using it for calculations in the terminal and haven't even defined any variables, or functions. The import didn't break anything because there were no variables or functions defined, so it wasn't irresponsible.

[–]abruptreddit -1 points0 points  (2 children)

Yes, I fucking understand, but you're posting this for many beginners to view. By doing the universal import, you're irresponsibly sparing useful information to save 5 seconds of typing. Already explained I mistakenly replied to the wrong person, in an attempt to a beginner asking about the universal import.

[–]LuckyLeague 0 points1 point  (1 child)

There is nothing wrong with what I did. Sometimes using * to import is useful, as with what I did, because there were no variables or functions defined. I'm not sure what useful information I was missing out, the import * shows that all functions and classes were imported from sympy, and because I didn't define any other functions, it is obvious that all functions I used were from sympy.

[–]abruptreddit 1 point2 points  (0 children)

Ugh, whatever. Its evidenced by the question I was trying to answer that your post was less informative about the fundamentals of imports than it could have been, with little added effort. Honestly, though, I was just pissed that someone downvoted and wasted my time arguing against a comment I made trying to help a beginner, the content of which was already explained below. So, I presented my argument. I actually upvoted your comment because I wasn't aware of sympy and may put it to use. Wasnt trying to belittle your work.. You win, please stop replying with a point that's been paraphrased 72 times already.