About 74,000 results
Open links in new tab
  1. Python math module - Stack Overflow

    in front of each function, either import just what you need (from math import sin,cos,exp,log) or import math as m which allows you to use m.sin, m.cos, m.exp, m.log, ... – Max Commented Mar 4, 2024 at 18:59

  2. python - Use 'import module' or 'from module import ... - Stack …

    Oct 28, 2014 · In simple words, this is all about programmer convenience. At the core level, they simply import all functionality of the module. import module: When you use import module then to use methods of this module you have to write module.method(). Every time you use any method or property then you have to refer to the module.

  3. python - What exactly does "import - Stack Overflow

    Mar 2, 2010 · from yadda.yadda import * is most useful when hacking at things in the Python command line, e.g. when you're using Python as a calculator and you just type out from math import *. In a module, it's asking for trouble. Also, if you import a single-file module (as opposed to a directory), from ... import * won't import symbols whose names begin ...

  4. python - Pycharm cannot import math module - Stack Overflow

    Oct 23, 2017 · Check that you are pointing to the correct python file within Settings > Project > Project Interpreter. When I've had this problem in the past my interpreter was pointing at python3.6 and not python within the bin folder of my venv. I simply dropped the interpreter and added it again pointing to the venv-name/bin/python

  5. Importing modules in Python - best practice - Stack Overflow

    import sys, os, re, itertools avoids name collisions and provides a very succinct way to import a bunch of standard modules. from math import * lets me write sin(x) instead of math.sin(x) in math-heavy code. This gets a bit dicey when I also import numpy, which doubles up on some of these, but it doesn't overly concern me, since they are ...

  6. Python 3x : Importing Math library python - Stack Overflow

    Jan 8, 2019 · When you import math, Python walks through the directories in sys.path and imports the first file called math.py (or a directory called math with an __init__.py file inside) that it sees. The first entry in sys.path is the current directory, so it sees your math.py first. See the documentation for modules or for the import statement.

  7. python - Is there a way to use " from math import - Stack Overflow

    Apr 30, 2021 · According to Python import docs the use of from module import * is a wild card form and is not allowed to be used in class or function definition. In addition, it isn't a good practice to use this syntax, see this documentation to understand the risks.

  8. python - "from math import sqrt" works but "import math" does …

    Jun 4, 2015 · import math math.sqrt() will import the math module into its own namespace. This means that function names have to be prefixed with math. This is good practice because it avoids conflicts and won't overwrite a function that was already imported into the current namespace. Alternatively: from math import * sqrt()

  9. Is there a Python library to list primes? - Stack Overflow

    Nov 11, 2012 · import gmpy2 def primes(): n = 2 while True: yield n n = gmpy2.next_prime(n) If you will be searching through primes repeatedly, creating and reusing a table of all primes below a reasonable limit (say 1,000,000) will be faster.

  10. Python : name 'math' is not defined Error? - Stack Overflow

    Feb 1, 2015 · from math import * # This imports all the functions and the classes from math # log method is also imported. # But there is nothing defined with name math So, When you try using math.log. It gives you error, so : replace math.log with log. Or . replace from math import * with import math. This should solve the problem.

Refresh