About 2,030,000 results
Open links in new tab
  1. Python - Does it matter if i import modules before or after defining ...

    Sep 24, 2015 · When you import a module you are actually running it's code, that is, in most cases, just defining new symbols, but could be also to trigger some side effect; thus it …

  2. Create and Import modules in Python - GeeksforGeeks

    Dec 29, 2019 · In Python, a module is a self-contained Python file that contains Python statements and definitions, like a file named GFG.py, can be considered as a module named …

  3. Creating and Importing Modules in Python - Stack Abuse

    Aug 17, 2023 · We can define this function in a module then import it into the various programs without having to copy its code each time. In this article, we will see how to create Python …

  4. Importing Modules Within Python Function - Data Magic AI Blog

    Feb 2, 2024 · Importing a module within a function in Python, rather than at the beginning of a file, is a practice that has both advantages and disadvantages, and its appropriateness depends …

  5. 5. The import system — Python 3.13.3 documentation

    4 days ago · Python code in one module gains access to the code in another module by the process of importing it. The import statement is the most common way of invoking the import …

  6. python - Why should imports be made at the beginning

    Oct 20, 2018 · If you do the import in a function, you may end up in a situation where you are trying to use the module before importing it. Importing a module can take time. Putting the …

  7. python - Import statement inside class/function definition - is it …

    I believe that it's best practice (according to some PEP's) that you keep import statements at the beginning of a module. You can add import statements to an __init__.py file, which will import …

  8. Which should be defined first: functions or classes?

    Sep 16, 2021 · # Example 2 import module from module import this def someFunc(arg): # A regular global function pass class someThing: def __init__(self): # init function stuff here pass …

  9. Is it bad practice to put imports in a function? : r/learnpython

    Jan 3, 2023 · The only time I know where it's a potentially good to import in functions are: You're importing OS-specific modules for use in certain functions and are deciding externally which …

  10. But only define function ONCE Functions and Modules • Purpose of modules is function definitions § Function definitions are written in module file § Import the module to call the …

  11. Some results have been removed
Refresh