python-module

How to access a python module variable using a string [ django ]

雨燕双飞 提交于 2019-12-08 16:01:12
问题 I have a django application, with a module called "app" Now this module has a file called "urls.py" which has a variable called "HOME_URL " What I'm trying to do ? app_label = "app" url = __import__(app_label).urls.HOME_URL print url That obviously doesn't work, but I hope you got what I'm trying to do, If not please comment I will edit the question to contain more info. 回答1: You can use import_module to load a module relative to the root of a django project. from django.utils.importlib

How to use IPython magic within a script to auto reload modules?

拟墨画扇 提交于 2019-12-08 14:15:46
问题 I am trying to include some of the IPython built-in magic functions to auto reload modules when I am running a script. So I have tried this: if __IPYTHON__: %load_ext autoreload %autoreload 2 But IPython returns: %load_ext autoreload ^ SyntaxError: invalid syntax Any idea how to solve this? 回答1: Thank you for the link Gall!!! Whit your help I came up with the following solution: from IPython import get_ipython ipython = get_ipython() if '__IPYTHON__' in globals(): ipython.magic('load_ext

Python ImportError loading module within subfolder

こ雲淡風輕ζ 提交于 2019-12-08 03:24:13
问题 I have the following structure abc/ __init__.py settings.py tests/ __init__.py test.py in test.py , I am getting an ImportError for #test.py import abc.settings 回答1: You have two ways. Firstly, by setting the path variable import os import sys sys.path.insert(0, <Complete path of abc>) Or by using relative imports. 回答2: The variable sys.path is a list of strings that determines the interpreter’s search path for modules. It is initialized to a default path taken from the environment variable

Django no module named utils

风流意气都作罢 提交于 2019-12-08 00:44:29
问题 I know this question has been asked before but after looking into it I can't help but feel I missed something. So I previously had a problem getting django-compressor installed but after a bit of struggling i managed to get it installed. When I run my django application though it stops on execute_from_command_line(sys.argv) in my manage.py and throws this error: Traceback (most recent call last): File "C:\Users\PCDOM\Desktop\Power\pm_app\manage.py", line 17, in <module> execute_from_command

What's the best practice for incorporating third-party libraries in a python program?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 18:02:04
问题 Good afternoon. I am writing a small to medium-sized python program for my job. The task requires me to use the Excel libraries xlwt and xlrd , as well as a library for querying Oracle databases, called cx_Oracle . I am developing the project through a version control system, namely CVS. I was wondering what is the standard way to organize third-party libraries around a python project. Should the libraries xlwt, xlrd, and cx_Oracle be stored in a directory such as /usr/local/lib/python, which

requests.get in python giving connection timeout error

試著忘記壹切 提交于 2019-12-07 14:35:52
问题 Language Ver: Python 3.6.3 IDE Ver: PyCharm 2017.2.3 I was trying to parse a weather website to print weather for a place. As I am learning Python, previously I used urllib.request.urlopen(url).read() and it worked. Now, I am modifying the code to BeautifulSoup4 and requests module. Below is my code: from bs4 import * import requests url = "https://www.accuweather.com/en/in/dhenkanal/189844/weather-forecast/189844" data = requests.get(url) soup = BeautifulSoup(data.text, "html.parser") print

Installation error of python package using pip

徘徊边缘 提交于 2019-12-07 06:24:21
问题 I tried to install a python module called python-phonenumbers I got this error sudo pip install git+git://github.com/daviddrysdale/python-phonenumbers.git Cleaning up... Command /usr/bin/python -c "import setuptools; file ='/tmp/pip-YQ6XJC-build/setup.py';exec(compile(open( file ).read().replace('\r\n', '\n'), file , 'exec'))" install --record /tmp/pip-s3GdMz-record/install-record.txt --single-version-externally-managed failed with error code -9 in /tmp/pip-YQ6XJC-build Storing complete log

python calling a module that uses argparser

ぐ巨炮叔叔 提交于 2019-12-06 19:08:02
问题 This is probably a silly question, but I have a python script that current takes in a bunch of arguements using argparser and I would like to load this script as a module in another python script, which is fine. But I am not sure how to call the module as no function is defined; can I still call it the same way I do if I was just invoking it from cmd? Here is the child script: import argparse as ap from subprocess import Popen, PIPE parser = ap.ArgumentParser( description='Gathers parameters.

Django no module named utils

天涯浪子 提交于 2019-12-06 11:59:23
I know this question has been asked before but after looking into it I can't help but feel I missed something. So I previously had a problem getting django-compressor installed but after a bit of struggling i managed to get it installed. When I run my django application though it stops on execute_from_command_line(sys.argv) in my manage.py and throws this error: Traceback (most recent call last): File "C:\Users\PCDOM\Desktop\Power\pm_app\manage.py", line 17, in <module> execute_from_command_line(sys.argv) File "C:\Users\PCDOM\Desktop\Power\pm_app\env\lib\site-pac kages\django\core\management\_

Error importing a python module in Django

回眸只為那壹抹淺笑 提交于 2019-12-06 10:52:52
问题 In my Django project, the following line throws an ImportError: "No module named elementtree". from elementtree import ElementTree However, the module is installed (ie, I can run an interactive python shell, and type that exact line without any ImportError), and the directory containing the module is on the PYTHONPATH. But when I access any page in a browser, it somehow can't find the module, and throws the ImportError. What could be causing this? 回答1: Can you import elementtree within the