python-import

How to call every function in an imported python module

故事扮演 提交于 2021-01-28 11:41:03
问题 I have a program that I wrote that is creating and maintaining an array and I have another module that I wrote that has functions to manipulate the array. Is it possible to call every function in the imported module without having to hard code every function call? Meaning something like this: #Some way I don't know of to get a list of function objects listOfFunctions = module.getAllFunctions() for function in listOfFunctions: array.function() I want to do this so I don't have to update my

Import a variable from setup.py from an external script

邮差的信 提交于 2021-01-28 06:01:09
问题 I have a setup.py file like this (not in pwd, not in Python path, a random file somewhere): import ext_modules config = { 'name': 'mesos.executor', 'version': '1.4.1', 'description': 'Mesos native executor driver implementation', 'author': 'Apache Mesos', 'author_email': 'dev@mesos.apache.org', 'url': 'http://pypi.python.org/pypi/mesos.executor', 'namespace_packages': [ 'mesos' ], 'packages': [ 'mesos', 'mesos.executor' ], 'package_dir': { '': 'src' }, 'install_requires': [ 'mesos.interface =

ModuleNotFoundError when attempting to import from outside of directory

允我心安 提交于 2021-01-27 19:13:59
问题 I'm working on a Flask app and attempting to run my test file but unable to do so. My current app structure is: Project ── app │ ├── __init__.py │ ├── forms.py │ ├── model.py │ ├── models.py │ ├── static │ │ ├── css │ │ ├── fonts │ │ ├── img │ │ ├── js │ │ └── uploads │ ├── templates │ │ ├── client │ │ │ ├── client-base.html │ │ │ ├── client-inventory.html │ │ │ ├── client-login.html │ │ │ ├── client-macros.html │ │ │ ├── client-main.html │ │ │ └── client-signup.html │ │ └── user │ │ ├── user

How to make IDLE automatically import modules at start?

老子叫甜甜 提交于 2021-01-27 17:51:35
问题 Often when I am using the IDLE shell I import the pickle module. Is it possible to make it automatically import pickle when I start it? 回答1: You can use the -c or - r argument: From idle -h : -c cmd run the command in a shell, or -r file run script from file For example: idle -c 'import pickle, sys' Or: idle -r ~/my_startup.py Where my_startup.py might contain: import pickle, sys You can either create a shell alias to always use this, or create a separate script; the procedure for this

Import error geopandas, fiona

这一生的挚爱 提交于 2021-01-27 16:36:03
问题 I have an error with import geopandas, fiona. When I'm trying to import geopandas import geopandas as gpd It returns me --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-8-77a0d94ee2c6> in <module>() 5 #ret = add(1,3) 6 #print(ret) ----> 7 import geopandas as gpd ~\Anaconda3\lib\site-packages\geopandas\__init__.py in <module>() 2 from geopandas.geodataframe import GeoDataFrame 3 ----> 4 from geopandas.io

Importing external package once in my module without it being added to the namespace

不羁岁月 提交于 2021-01-27 13:14:38
问题 I apologize for not being able to phrase my question more easily. I am writing a large package that makes extensive use of pandas in almost every function. My first instinct, naturally, was to create an __init__.py as import pandas # then import my own submodules and other things And then, every time I use pandas in a function, call it from the submodules as from . import pandas as pd or from .. import pandas , or something like that. However, if I do this, when I load my package, pandas

Performance between “from package import *” and “import package”

强颜欢笑 提交于 2021-01-27 03:52:32
问题 Is there any performance difference between from package import * and import package ? 回答1: No, the difference is not a question of performance. In both cases, the entire module must be parsed, and any module-level code will be executed. The only difference is in namespaces: in the first, all the names in the imported module will become names in the current module; in the second, only the package name is defined in the current module. That said, there's very rarely a good reason to use from

Cannot import sqlite3 in Python3

泪湿孤枕 提交于 2021-01-27 02:59:26
问题 I am unable to import the sqlite3 module in Python, version 3.5.0. Here's what I get: >>> import sqlite3 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module> from sqlite3.dbapi2 import * File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module> from _sqlite3 import * ImportError: No module named '_sqlite3' I know, I know, there are PLENTY of StackOverflow posts and support forums across

Cannot import sqlite3 in Python3

旧街凉风 提交于 2021-01-27 02:59:06
问题 I am unable to import the sqlite3 module in Python, version 3.5.0. Here's what I get: >>> import sqlite3 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module> from sqlite3.dbapi2 import * File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module> from _sqlite3 import * ImportError: No module named '_sqlite3' I know, I know, there are PLENTY of StackOverflow posts and support forums across

Import “Path.to.own.script” could not be resolved Pylance (reportMissingImports) in VS Code using python 3.9x on Lubuntu 20.04

谁说我不能喝 提交于 2021-01-21 09:25:29
问题 It is a similar situation I'd encountered several months ago using pylint prior to pylance: My python 3.9x - script (using VS Code on Lubuntu 20.04 LTS ) starts with the following import of custom "tools": import sys sys.path.append( '/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts/' ) import General.Misc.general_tools as tools Now, Pylance states Import "General.Misc.general_tools" could not be resolvedPylance (reportMissingImports) even though when executing