python-module

Importing user defined modules in python from a directory

流过昼夜 提交于 2019-11-28 12:40:06
I'm trying to import a module I wrote in python that just prints out a list containing numbers. The issue I'm having is that I want to be able to import it from a separate directory but the answers I have read so far don't seem to be working for my situation. For example, given I want to import printnumbers.py from a directory in my documents folder I am supposed to implement the following: import sys sys.path.append('/home/jake/Documents') import printnumbers.py This snipit of code results in a "Import error" telling me that the specified module does not exist. I'm not exactly sure where to

Django 1.7 conflicting models

无人久伴 提交于 2019-11-28 10:44:13
I install my application in "project/apps/myapp" folder. Both apps and myapp folders have init .py files(Without any of them there is module missing error). Now I've the error: Exception Type: RuntimeError at / Exception Value: Conflicting 'person' models in application 'resume': <class 'apps.resume.models.Person'> and <class 'resume.models.Person'>. Django import the same model with two different pathes. How can I fix it? Full error log: Traceback: File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 98. resolver_match =

Utilising bluetooth on Mac with Python

梦想与她 提交于 2019-11-28 10:38:54
问题 I've practically scoured the entire web (metaphorically speaking) trying to find a way to work with Bluetooth via Python on Mac. PyBluez is not compatible, Lightblue is not being maintained (tried regardless), installed the PyObC framework (incl Bluetooth Framework), and attempted in both my 2.7.6 and 3.6.1 environments with MacOS 10.10.5. I often get errors similar to the below: Traceback (most recent call last): File "/Users/***/PycharmProjects/Bluey/main.py", line 1, in <module> import

How to debug a Python module run with python -m from the command line?

偶尔善良 提交于 2019-11-28 08:59:11
I know that a Python script can be debugged from the command line with python -m pdb my_script.py if my_script.py is a script intended to be run with python my_script.py . However, a python module my_module.py should be run with python -m my_module . Even scripts that contain relative imports should be run with python -m . How can I run python -m my_module under pdb 's control? The following does not work : python -m pdb -m my_module You can't do it now, because -m terminates option list python -h ... -m mod : run library module as a script (terminates option list) ... That means it's mod's

Playing remote audio files in Python? [closed]

我怕爱的太早我们不能终老 提交于 2019-11-28 08:45:04
I'm looking for a solution to easily play remote .mp3 files. I have looked at "pyglet" module which works on local files, but it seems it can't handle remote files. I could temporary download the .mp3 file but that's not reccomended due to how large the .mp3 files could appear to be. I rather want it to be for cross-platform instead of Windows-only etc. Example, playing a audio file from: http://example.com/sound.mp3 Just stream the file as it's downloads, my idea is a MP3 player in Python which opens Soundcloud songs. You can use GStreamer with python bindings (requires PyGTK). Then you can

ImportError: No module named backend_tkagg

喜夏-厌秋 提交于 2019-11-28 00:07:59
问题 I have such imports and code: import pandas as pd import numpy as np import statsmodels.formula.api as sm import matplotlib.pyplot as plt #Read the data from pydatasets repo using Pandas url = './file.csv' white_side = pd.read_csv(url) #Fitting the model model = sm.ols(formula='budget ~ article_size', data=white_side, subset=white_side['producer'] == "Peter Jackson") fitted = model.fit() print fitted.summary() After execution of this code I have such errors: /usr/bin/python2.7 /home/seth

python module for nslookup

不打扰是莪最后的温柔 提交于 2019-11-27 23:03:13
问题 Is there a python-module that's doing the same stuff as nslookup does? I am planning to use nslookup on digging some information regarding the domain of a URL to be scrapped. I know I can use os.sys to call nslookup but I am just wondering if there is a python-module for this already. Thanks in advance! 回答1: I'm using the following code: import socket ip_list = [] ais = socket.getaddrinfo("www.yahoo.com",0,0,0,0) for result in ais: ip_list.append(result[-1][0]) ip_list = list(set(ip_list)) Or

Determining the location of distutils data files programmatically in Python

雨燕双飞 提交于 2019-11-27 21:18:59
问题 I'm trying to include data files in distutils for my package and then refer to them using relative paths (following http://docs.python.org/distutils/setupscript.html#distutils-additional-files) My dir structure is: myproject/ mycode.py data/ file1.dat the code in mycode.py , which is actually a script in the package. It relies on accessing data/file1.dat , refer to it using that relative path. In setup.py , I have: setup( ... scripts = "myproject/mycode.py" data_files = [('data', 'myproject

How is the __name__ variable in a Python module defined?

微笑、不失礼 提交于 2019-11-27 21:11:40
I'm aware of the standard example : if you execute a module directly then it's __name__ global variable is defined as "__main__" . However, nowhere in the documentation can I find a precise description of how __name__ is defined in the general case. The module documentation says... Within a module, the module's name (as a string) is available as the value of the global variable __name__ . ...but what does it mean by "the module's name"? Is it just the name of the module (the filename with .py removed), or does it include the fully-qualified package name as well? How is the value of the __name_

Recursive version of 'reload'

泄露秘密 提交于 2019-11-27 21:11:34
When I'm developing Python code, I usually test it in an ad-hoc way in the interpreter. I'll import some_module , test it, find a bug, fix the bug and save, and then use the built-in reload function to reload(some_module) and test again. However, suppose that in some_module I have import some_other_module , and while testing some_module I discover a bug in some_other_module and fix it. Now calling reload(some_module) won't recursively re-import some_other_module . I have to either manually reimport the dependency (by doing something like reload(some_module.some_other_module) , or import some