python-import

Where to put large Python lists

冷暖自知 提交于 2021-02-11 15:57:38
问题 I'm writing a python program that uses a list of all of the words in an English dictionary, so we're talking a few megabytes. I would like a clean way of including the list as a constant without it getting in the way of the source code. I would put it in a JSON file or something, but I'm using PySimpleGUI, and I want to take advantage of its ability to turn the code into a Windows EXE file, and I doubt it could do that with an external text file. So, in order of preference I would like to do

how to automatically create table based on CSV into postgres using python

做~自己de王妃 提交于 2021-02-11 15:37:12
问题 I am a new Python programmer and trying to import a sample CSV file into my Postgres database using python script. I have CSV file with name abstable1 it has 3 headers: absid, name, number I have many such files in a folder I want to create a table into PostgreSQL with the same name as the CSV file for all. Here is the code which I tried to just create a table for one file to test: import psycopg2 import csv import os #filePath = 'c:\\Python27\\Scripts\\abstable1.csv' conn = psycopg2.connect(

how to automatically create table based on CSV into postgres using python

断了今生、忘了曾经 提交于 2021-02-11 15:35:17
问题 I am a new Python programmer and trying to import a sample CSV file into my Postgres database using python script. I have CSV file with name abstable1 it has 3 headers: absid, name, number I have many such files in a folder I want to create a table into PostgreSQL with the same name as the CSV file for all. Here is the code which I tried to just create a table for one file to test: import psycopg2 import csv import os #filePath = 'c:\\Python27\\Scripts\\abstable1.csv' conn = psycopg2.connect(

Install package using pip from git into site-packages

筅森魡賤 提交于 2021-02-11 14:31:14
问题 I installed a Python package using pip from git. In order to achieve this, I added the command -e git+<link>#<egg> to my requirements.txt. Pip installs this package, but not in the way I would like to have it. First problem: I use a virtual environment. Usually, packages end up in <env>/Lib/site-packages . This one does not, it ends up in <env>/src . This makes it more to difficult to import. Second problem: The src folder also gets created within my actual project, the one I am working on.

module 'a' has no attribute func()

放肆的年华 提交于 2021-02-11 13:46:30
问题 I have 2 modules: a: import another_module def func(): b: import a x=a.func() This is showing error: module 'a' has no attribute 'func'. What i am doing wrong in importing a.ipynb 回答1: Make sure your module is names 'a.py', and it is in the same folder as b, otherwise, in the place where all the other modules are stored. 来源: https://stackoverflow.com/questions/61870325/module-a-has-no-attribute-func

how can I import [.myfolder.pyfile] as [something else]?

↘锁芯ラ 提交于 2021-02-11 12:47:46
问题 let's say I have project |__ utilities | |__ foo.py | |__ boost_extensions | |__ myclass.cpp | |__ myclass.so | |__ someotherstuff | |__ bar.py | |__ mylib.py | |__ __main__.py Is it possible to do something like this in main .py import .utilities.foo as Foo # this function will pass Foo to C++ and initialize it to a global variable initCppFunction(Foo) I've tried this but it gives me an invalid syntax error (I'm trying to do this due to some problems with importing python modules from boost

ImportError: cannot import name 'context' from 'tensorflow.python.eager' (unknown location)

拈花ヽ惹草 提交于 2021-02-10 14:51:01
问题 I created virtual environment and installed both tensorflow and tensorflow-gpu. After that I installed keras. And then I checked in my conda terminal by importing keras and I was able to import keras in it. However, using jupyter notebook if I try to import keras then it gives me below error. import keras ImportError Traceback (most recent call last) <ipython-input-5-88d96843a926> in <module> ----> 1 import keras ~\Anaconda3\lib\site-packages\keras\__init__.py in <module> 1 from __future__

Dealing with module name collision

南笙酒味 提交于 2021-02-08 15:18:38
问题 Occasionally, module name collisions happen between the application and an internal file in a third-party package. For example, a file named profile.py in the current folder will cause jupyter notebook to crash as it attempts to import it instead of its own profile.py . What's a good way to avoid this problem, from the perspective of the package user? (Or is this something that the package developer should somehow prevent?) Note: while a similar problem occurs due to a collision between

iPython: cannot import module named sklearn

扶醉桌前 提交于 2021-02-08 13:37:09
问题 I am able to import sklearn using the python interpreter, but when I try to do the same in an iPython notebook, iPython throws an ImportError. Any idea what is causing this issue? I need to use a module in iPython. I'm not sure if this will be helpful, but here is a subset of the packages that I have installed on my machine. I followed the instructions here regarding the installation process: http://shanshanchen.com/2013/05/29/install-numpy-scipy-scikit-learn-on-mac-os-x-for-data-miners/ 回答1:

Assembling Python module on fly, dynamic import

元气小坏坏 提交于 2021-02-07 18:17:00
问题 I'm trying to get myself familiar with importlib hooks. I want to implement an ability to directly import non-pythonic files written in other language, and maintain source maps, so raising SyntaxError s with line numbers will still give meaningful stacktraces. My approach to loading foreign files is assembling Pythonic source, then compiling it and executing it in the desired context. I've read in the documentation that implementing importlib.abc.SourceLoader seems to be my choice — however,