title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 1,057,418 | <p>The usual aproach is to store the request object in a thread-local reference using a middleware. Then you can access this from anywhere in you app, including the Form.clean() method.</p>
<p>Changing the signature of the Form.clean() method means you have you own, modified version of Django, which may not be what yo... | 13 | 2009-06-29T09:34:58Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 1,057,640 | <p>The answer by Ber - storing it in threadlocals - is a very bad idea. There's absolutely no reason to do it this way.</p>
<p>A much better way is to override the form's <code>__init__</code> method to take an extra keyword argument, <code>request</code>. This stores the request in the <em>form</em>, where it's requi... | 128 | 2009-06-29T10:36:55Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 2,566,785 | <p>You can't always use this method (and its probably bad practice), but if you are only using the form in one view you could scope it inside the view method itself.</p>
<pre><code>def my_view(request):
class ResetForm(forms.Form):
password = forms.CharField(required=True, widget=forms.PasswordInput())
... | 1 | 2010-04-02T13:10:40Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 6,001,699 | <p>I ran into this particular problem when customizing the admin. I wanted a certain field to be validated based on the particular admin's credentials.</p>
<p>Since I did not want to modify the view to pass the request as an argument to the form, the following is what I did:</p>
<pre><code>class MyCustomForm(forms.Mo... | 6 | 2011-05-14T12:03:34Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 6,062,628 | <p><strong>UPDATED 10/25/2011</strong>: I'm now using this with a metaclass instead of method, as Django 1.3 displays some weirdness otherwise.</p>
<pre><code>class MyModelAdmin(admin.ModelAdmin):
form = MyCustomForm
def get_form(self, request, obj=None, **kwargs):
ModelForm = super(MyModelAdmin, self)... | 24 | 2011-05-19T17:39:58Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 6,416,524 | <p>fresh cheese from cheesebaker@pypi: <a href="http://pypi.python.org/pypi?%3aaction=display&name=django-contrib-requestprovider&version=1.0.1" rel="nofollow">django-requestprovider</a></p>
| 3 | 2011-06-20T19:41:16Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 9,974,165 | <p>I have another answer to this question as per your requirement you want to access the user into the clean method of the form.
You can Try this.
View.py</p>
<pre><code>person=User.objects.get(id=person_id)
form=MyForm(request.POST,instance=person)
</code></pre>
<p>forms.py</p>
<pre><code>def __init__(self,*arg,**k... | 1 | 2012-04-02T09:46:31Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 16,975,043 | <p>The answer by <a href="http://stackoverflow.com/a/1057640/1623530http://stackoverflow.com/a/1057640/1623530">Daniel Roseman</a> is still the best. However, I would use the first positional argument for the request instead of the keyword argument for a few reasons:</p>
<ol>
<li>You don't run the risk of overriding a... | 3 | 2013-06-07T01:51:29Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 25,930,538 | <p>For what it's worth, if you're using <strong>Class Based Views</strong>, instead of function based views, override <a href="https://docs.djangoproject.com/en/1.7/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.get_form_kwargs"><code>get_form_kwargs</code></a> in your editing view. Example c... | 16 | 2014-09-19T09:20:59Z | [
"python",
"django"
] |
How do I access the request object or any other variable in a form's clean() method? | 1,057,252 | <p>I am trying to request.user for a form's clean method, but how can I access the request object? Can I modify the clean method to allow variables input?</p>
| 74 | 2009-06-29T08:49:45Z | 33,746,731 | <p>For Django admin, in Django 1.8</p>
<pre><code>class MyModelAdmin(admin.ModelAdmin):
...
form = RedirectForm
def get_form(self, request, obj=None, **kwargs):
form = super(MyModelAdmin, self).get_form(request, obj=obj, **kwargs)
form.request = request
return form
</code></pre>
| 5 | 2015-11-16T23:47:56Z | [
"python",
"django"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 1,057,446 | <p>Add the <code>__all__</code> Variable to <code>__init__.py</code> containing:</p>
<pre><code>__all__ = ["bar", "spam", "eggs"]
</code></pre>
<p>See also <a href="http://docs.python.org/tutorial/modules.html">http://docs.python.org/tutorial/modules.html</a></p>
| 69 | 2009-06-29T09:42:33Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 1,057,467 | <p>See that your <code>__init__.py</code> defines <code>__all__</code>. The <a href="http://docs.python.org/tutorial/modules.html#packages" rel="nofollow">modules - packages</a> doc says </p>
<blockquote>
<p>The <code>__init__.py</code> files are required to make Python treat the directories as containing packages; ... | 3 | 2009-06-29T09:47:46Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 1,057,534 | <p>List all python (<code>.py</code>) files in the current folder and put them as <code>__all__</code> variable in <code>__init__.py</code></p>
<pre><code>from os.path import dirname, basename, isfile
import glob
modules = glob.glob(dirname(__file__)+"/*.py")
__all__ = [ basename(f)[:-3] for f in modules if isfile(f)]... | 215 | 2009-06-29T10:06:25Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 1,057,765 | <p>Make the Foo directory a package by adding an <code>__init__.py</code>. In that <code>__init__.py</code> add:</p>
<pre><code>import bar
import eggs
import spam
</code></pre>
<p>Since you want it dynamic (which may or may not be a good idea), list all py-files with list dir and import them with something like this:... | 30 | 2009-06-29T11:10:40Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 4,933,232 | <p>Look at the pkgutil module from the standard library. It will let you do exactly what you want as long as you have an <code>__init__.py</code> file in the directory. The <code>__init__.py</code> file can be empty.</p>
| 1 | 2011-02-08T12:51:32Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 8,556,471 | <p>Expanding on Mihail's answer, I believe the non-hackish way (as in, not handling the file paths directly) is the following:</p>
<ol>
<li>create an empty <code>__init__.py</code> file under <code>Foo/</code></li>
<li>Execute</li>
</ol>
<pre class="lang-py prettyprint-override"><code>import pkgutil
import sys
def ... | 27 | 2011-12-19T02:11:12Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 9,560,906 | <p>I got tired of this problem myself, so I wrote a package called automodinit to fix it. You can get it from <a href="http://pypi.python.org/pypi/automodinit/" rel="nofollow">http://pypi.python.org/pypi/automodinit/</a>. </p>
<p>Usage is like this:</p>
<ol>
<li>Include the <code>automodinit</code> package into your ... | 14 | 2012-03-05T02:24:09Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 11,729,584 | <p>I have also encountered this problem and this was my solution:</p>
<pre><code>import os
def loadImports(path):
files = os.listdir(path)
imps = []
for i in range(len(files)):
name = files[i].split('.')
if len(name) > 1:
if name[1] == 'py' and name[0] != '__init__':
... | 5 | 2012-07-30T21:06:25Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 20,753,073 | <h2>Python, include all files under a directory:</h2>
<p>For newbies who just can't get it to work who need their hands held.</p>
<ol>
<li><p>Make a folder /home/el/foo and make a file <code>main.py</code> under /home/el/foo Put this code in there:</p>
<pre><code>from hellokitty import *
spam.spamfunc()
ham.hamfunc... | 17 | 2013-12-24T00:08:56Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 24,196,410 | <p><a href="http://stackoverflow.com/a/1057534/281545">Anurag Uniyal answer</a> with suggested improvements!</p>
<pre><code>#!/usr/bin/python
# -*- encoding: utf-8 -*-
import os
import glob
all_list = list()
for f in glob.glob(os.path.dirname(__file__)+"/*.py"):
if os.path.isfile(f) and not os.path.basename(f).s... | 3 | 2014-06-13T01:28:24Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 24,526,390 | <p>This is the best way i've found so far:</p>
<pre><code>from os.path import dirname, join, isdir, abspath, basename
from glob import glob
pwd = dirname(__file__)
for x in glob(join(pwd, '*.py')):
if not x.startswith('__'):
__import__(basename(x)[:-3], globals(), locals())
</code></pre>
| 3 | 2014-07-02T08:30:27Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 27,006,389 | <p>I've created a module for that, which doesn't rely on <code>__init__.py</code> (or any other auxiliary file) and makes me type only the following two lines:</p>
<pre><code>import importdir
importdir.do("Foo", globals())
</code></pre>
<p>Feel free to re-use or contribute: <a href="http://gitlab.com/aurelien-lourot/... | 0 | 2014-11-18T23:46:56Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 27,015,444 | <p>Anurag's example with a couple of corrections:</p>
<pre><code>import os, glob
modules = glob.glob(os.path.join(os.path.dirname(__file__), "*.py"))
__all__ = [os.path.basename(f)[:-3] for f in modules if not f.endswith("__init__.py")]
</code></pre>
| 3 | 2014-11-19T11:13:09Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 36,231,122 | <p>I know I'm updating a quite old post, and I tried using <code>automodinit</code>, but found out it's setup process is broken for python3. So, based on Luca's answer, I came up with a simpler answer - which might not work with .zip - to this issue, so I figured I should share it here:</p>
<p>within the <code>__init_... | 1 | 2016-03-26T02:54:58Z | [
"python",
"python-import"
] |
Loading all modules in a folder in Python | 1,057,431 | <p>Could someone provide me with a good way of importing a whole directory of modules?<br />
I have a structure like this:</p>
<pre><code>/Foo
bar.py
spam.py
eggs.py
</code></pre>
<p>I tried just converting it to a package by adding <code>__init__.py</code> and doing <code>from Foo import *</code> but it ... | 122 | 2009-06-29T09:38:15Z | 37,684,402 | <pre><code>import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
for imp, module, ispackage in pkgutil.walk_packages(path=__path__, prefix=__name__+'.'):
__import__(module)
</code></pre>
| 1 | 2016-06-07T16:15:03Z | [
"python",
"python-import"
] |
How to code a Download/Upload Speed Monitor in PHP,Python, or Java? | 1,057,449 | <p>I have to code a up/download speed monitor. It will obtain the current download and upload transfer speed of the computer which it has been installed and post it to another server periodically.
c
But I don't have an idea about how to catch instant transfer rates of a computer. As you know some of network monitoring ... | 3 | 2009-06-29T09:43:13Z | 1,057,517 | <p>You don't say which operating system you're interested in.</p>
<p>A quick google turned up this: <a href="http://excess.org/speedometer/" rel="nofollow">http://excess.org/speedometer/</a></p>
<p>"Measure and display the rate of data across a network connection or data being stored in a file"</p>
<p>Opensource, wr... | 3 | 2009-06-29T10:02:50Z | [
"java",
"php",
"python",
"networking"
] |
How to code a Download/Upload Speed Monitor in PHP,Python, or Java? | 1,057,449 | <p>I have to code a up/download speed monitor. It will obtain the current download and upload transfer speed of the computer which it has been installed and post it to another server periodically.
c
But I don't have an idea about how to catch instant transfer rates of a computer. As you know some of network monitoring ... | 3 | 2009-06-29T09:43:13Z | 1,063,081 | <p><a href="http://netresearch.ics.uci.edu/kfujii/jpcap/doc/index.html" rel="nofollow">JPCAP</a> (a java packet capture library-sniffer) is suitable for this job and I've done it.</p>
| 1 | 2009-06-30T11:02:21Z | [
"java",
"php",
"python",
"networking"
] |
Django/Python: How do i transfer a class's attributes to another via a for loop? (Form->Model Instance) | 1,057,477 | <p>I wish to update a model instance from a form I have.</p>
<p>The form is a ModelForm, so it has the same attributes as the model instance, how do I transfer the attributes from the form instance to the model instance instead of doing this:</p>
<p>modelinstance.name = form.name
.
.
.
.</p>
<p>A for loop perhaps? :... | 1 | 2009-06-29T09:50:48Z | 1,057,495 | <p>Call the save() method of the form.
Specifically instantiate the form with keyword argument <code>instance</code> like this:</p>
<pre><code>>>> a = Article.objects.get(pk=1)
>>> f = ArticleForm(instance=a)
>>> f.save()
</code></pre>
<p>Taken from here: <a href="http://docs.djangoproject.... | 6 | 2009-06-29T09:56:00Z | [
"python",
"django"
] |
How to do windows API calls in Python 3.1? | 1,057,496 | <p>Has anyone found a version of <a href="http://python.net/crew/mhammond/win32/" rel="nofollow">pywin32</a> for python 3.x? The latest available appears to be for 2.6.</p>
<p>Alternatively, how would I "roll my own" windows API calls in Python 3.1?</p>
| 5 | 2009-06-29T09:56:42Z | 1,057,573 | <p>You should be able to do everything with <a href="http://docs.python.org/library/ctypes.html">ctypes</a>, if a bit cumbersomely.</p>
<p>Here's an example of getting the "common application data" folder:</p>
<pre><code>from ctypes import windll, wintypes
_SHGetFolderPath = windll.shell32.SHGetFolderPathW
path_buf ... | 8 | 2009-06-29T10:14:52Z | [
"python",
"winapi",
"python-3.x"
] |
How to do windows API calls in Python 3.1? | 1,057,496 | <p>Has anyone found a version of <a href="http://python.net/crew/mhammond/win32/" rel="nofollow">pywin32</a> for python 3.x? The latest available appears to be for 2.6.</p>
<p>Alternatively, how would I "roll my own" windows API calls in Python 3.1?</p>
| 5 | 2009-06-29T09:56:42Z | 1,057,742 | <p>There are pywin32 available for 3.0. Python 3.1 was release two days ago, so if you need pywin32 for that you either need to wait a bit, or compile them from source.</p>
<p><a href="http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063">http://sourceforge.net/project/showfiles.php?group_i... | 5 | 2009-06-29T11:04:52Z | [
"python",
"winapi",
"python-3.x"
] |
How to call a data member of the base class if it is being overwritten as a property in the derived class? | 1,057,518 | <p>This question is similar to <a href="http://stackoverflow.com/questions/1021464/python-how-to-call-a-property-of-the-base-class-if-this-property-is-being-overwr">this other one</a>, with the difference that the data member in the base class is <em>not</em> wrapped by the descriptor protocol.</p>
<p>In other words, ... | 5 | 2009-06-29T10:03:17Z | 1,057,601 | <p>Defining</p>
<pre><code>def __init__(self):
self.foo = 5
</code></pre>
<p>in <code>Base</code> makes <code>foo</code> a member (attribute) of the <em>instance</em>, not of the class. The <em>class</em> <code>Base</code> has no knowledge of <code>foo</code>, so there is no way to access it by something like a <... | 4 | 2009-06-29T10:24:25Z | [
"python",
"inheritance",
"overloading",
"descriptor"
] |
How to call a data member of the base class if it is being overwritten as a property in the derived class? | 1,057,518 | <p>This question is similar to <a href="http://stackoverflow.com/questions/1021464/python-how-to-call-a-property-of-the-base-class-if-this-property-is-being-overwr">this other one</a>, with the difference that the data member in the base class is <em>not</em> wrapped by the descriptor protocol.</p>
<p>In other words, ... | 5 | 2009-06-29T10:03:17Z | 1,057,603 | <p>once you have property with same name 'foo' it overrides the behaviour of access of name 'foo'
only way out seems that you explicitly set 'foo' in <strong>dict</strong></p>
<p>btw: I use python 2.5 hence had to change code a bit</p>
<pre><code>class Base(object):
def __init__(self):
self.foo = 5
class... | 0 | 2009-06-29T10:25:12Z | [
"python",
"inheritance",
"overloading",
"descriptor"
] |
How to call a data member of the base class if it is being overwritten as a property in the derived class? | 1,057,518 | <p>This question is similar to <a href="http://stackoverflow.com/questions/1021464/python-how-to-call-a-property-of-the-base-class-if-this-property-is-being-overwr">this other one</a>, with the difference that the data member in the base class is <em>not</em> wrapped by the descriptor protocol.</p>
<p>In other words, ... | 5 | 2009-06-29T10:03:17Z | 1,057,656 | <p>Life is simpler if you use delegation instead of inheritance. This is Python. You aren't obligated to inherit from <code>Base</code>.</p>
<pre><code>class LooksLikeDerived( object ):
def __init__( self ):
self.base= Base()
@property
def foo(self):
return 1 + self.base.foo # always wor... | 9 | 2009-06-29T10:41:40Z | [
"python",
"inheritance",
"overloading",
"descriptor"
] |
How to call a data member of the base class if it is being overwritten as a property in the derived class? | 1,057,518 | <p>This question is similar to <a href="http://stackoverflow.com/questions/1021464/python-how-to-call-a-property-of-the-base-class-if-this-property-is-being-overwr">this other one</a>, with the difference that the data member in the base class is <em>not</em> wrapped by the descriptor protocol.</p>
<p>In other words, ... | 5 | 2009-06-29T10:03:17Z | 1,058,209 | <pre><code>class Foo(object):
def __new__(cls, *args, **kw):
return object.__new__(cls, *args, **kw)
def __init__(self):
self.foo = 5
class Bar(Foo):
def __new__(cls, *args, **kw):
self = object.__new__(cls, *args, **kw)
self.__foo = Foo.__new__(Foo)
return self
... | 1 | 2009-06-29T13:13:45Z | [
"python",
"inheritance",
"overloading",
"descriptor"
] |
How to call a data member of the base class if it is being overwritten as a property in the derived class? | 1,057,518 | <p>This question is similar to <a href="http://stackoverflow.com/questions/1021464/python-how-to-call-a-property-of-the-base-class-if-this-property-is-being-overwr">this other one</a>, with the difference that the data member in the base class is <em>not</em> wrapped by the descriptor protocol.</p>
<p>In other words, ... | 5 | 2009-06-29T10:03:17Z | 1,061,081 | <p>Honestly, the thing to look at here is that you're trying to twist your code around a design that is simply poor. The property descriptors handle the request for a 'foo' attribute, and you want to bypass these completely, which is just wrong. You're already causing Base.<strong>init</strong> to assign foobar._foo = ... | 0 | 2009-06-29T23:31:53Z | [
"python",
"inheritance",
"overloading",
"descriptor"
] |
Using pipes to communicate data between two anonymous python scripts | 1,057,576 | <p>Consider this at the windows commandline.</p>
<pre><code>scriptA.py | scriptB.py
</code></pre>
<p>I want to send a dictionary object from scriptA.py to scriptB.py by pickle:ing it and sending it over a pipe. But I don't know how to accomplish this.</p>
<p>I've read some posts about this subject here, but usually ... | 1 | 2009-06-29T10:15:31Z | 1,057,597 | <p>When you say this to a shell</p>
<pre><code>scriptA.py | scriptB.py
</code></pre>
<p>The shell connects them with a pipe. You do NOTHING and it works perfectly.</p>
<p>Everything that <code>scriptA.py</code> writes to sys.stdout goes to <code>scriptB.py</code></p>
<p>Everything that <code>scriptB.py</code> read... | 6 | 2009-06-29T10:23:27Z | [
"python",
"windows",
"pipe"
] |
Using pipes to communicate data between two anonymous python scripts | 1,057,576 | <p>Consider this at the windows commandline.</p>
<pre><code>scriptA.py | scriptB.py
</code></pre>
<p>I want to send a dictionary object from scriptA.py to scriptB.py by pickle:ing it and sending it over a pipe. But I don't know how to accomplish this.</p>
<p>I've read some posts about this subject here, but usually ... | 1 | 2009-06-29T10:15:31Z | 1,057,598 | <p>The pipe just puts stdout of A to stdin of B.</p>
<p>A does:</p>
<pre><code>import sys
sys.stdout.writelines(output)
</code></pre>
<p>B just does:</p>
<pre><code>import sys
input = sys.stdin.readlines()
</code></pre>
| 2 | 2009-06-29T10:23:28Z | [
"python",
"windows",
"pipe"
] |
Using pipes to communicate data between two anonymous python scripts | 1,057,576 | <p>Consider this at the windows commandline.</p>
<pre><code>scriptA.py | scriptB.py
</code></pre>
<p>I want to send a dictionary object from scriptA.py to scriptB.py by pickle:ing it and sending it over a pipe. But I don't know how to accomplish this.</p>
<p>I've read some posts about this subject here, but usually ... | 1 | 2009-06-29T10:15:31Z | 1,057,602 | <p>When you are piping something, you are (generally) feeding the standard output of one program into the standard input of another. I think you should keep trying this path.</p>
<p>If you're having trouble just being able to read the output of your first script with your second, check out <a href="http://stackoverflo... | 0 | 2009-06-29T10:24:29Z | [
"python",
"windows",
"pipe"
] |
Bad pipe filedescriptor when reading from stdin in python | 1,057,638 | <p><strong>Duplicate of <a href="http://stackoverflow.com/questions/466801/python-piping-on-windows-why-does-this-not-work">this</a> question. Vote to close.</strong></p>
<p>Consider this at the windows commandline.</p>
<pre><code>scriptA.py | scriptB.py
</code></pre>
<p>In scriptA.py:</p>
<pre><code>sys.stdout.wri... | 2 | 2009-06-29T10:36:37Z | 1,057,681 | <p>It seems that stdin/stdout redirect does not work when starting from a file association.
This is not specific to python, but a problem caused by win32 cmd.exe.</p>
<p>See: <a href="http://mail.python.org/pipermail/python-bugs-list/2004-August/024920.html">http://mail.python.org/pipermail/python-bugs-list/2004-Augus... | 7 | 2009-06-29T10:48:54Z | [
"python",
"windows",
"pipe"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 1,057,715 | <p>There's <a href="http://en.wikipedia.org/wiki/Matplotlib" rel="nofollow">Matplotlib</a> for plots and the <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv module</a> for reading <a href="http://en.wikipedia.org/wiki/Microsoft_Excel" rel="nofollow">Excel</a> data (assuming you can dump to <a href=... | 3 | 2009-06-29T10:58:24Z | [
"python",
"excel",
"matlab",
"numpy"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 1,057,748 | <p>Depending on what kind of computations you are doing with <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> (and on which toolboxes you are using), Python could be a good alternative to MATLAB.</p>
<p>Python + <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> + <a href="htt... | 11 | 2009-06-29T11:06:15Z | [
"python",
"excel",
"matlab",
"numpy"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 1,057,797 | <p>If you come from the <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> world, <a href="http://www.scipy.org/PyLab" rel="nofollow">Pylab</a> will ease your transition. Once you have converted your data to ASCII, <code>pylab.load()</code> will do the rest:</p>
<pre><code>pylab.load(fname, commen... | 3 | 2009-06-29T11:22:04Z | [
"python",
"excel",
"matlab",
"numpy"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 1,059,072 | <p>I had a look at <a href="http://mlabwrap.sourceforge.net/" rel="nofollow">mlabwrap</a> as a step to easing some <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> developers into using Python more.</p>
<p>But I have been unable to cleanly build it, and I don't run production installs here, so I... | 2 | 2009-06-29T15:55:29Z | [
"python",
"excel",
"matlab",
"numpy"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 1,173,639 | <p>There are probably hundreds of ways you could import text data into Python.</p>
<p>But since you want to replace <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a>, you're going be using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> and probably <a href="http://en.wikipe... | 3 | 2009-07-23T18:30:04Z | [
"python",
"excel",
"matlab",
"numpy"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 4,027,010 | <p>If you saved you data in <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> format, use:</p>
<pre><code>from scipy.io import loadmat
datafile = "yourfile.mat"
data = loadmat(datafile, matlab_compatible=True)
var1 = data['nameOfYourVariable'].squeeze()
var2 = data['nameOfYourOtherVariable'].squ... | 1 | 2010-10-26T18:56:15Z | [
"python",
"excel",
"matlab",
"numpy"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 9,805,334 | <blockquote>
<p>"I don't know if Python is a credible alternative to MATLAB"</p>
</blockquote>
<p>For me (experimental physics) Python is not only a full replacement for <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> (when including <a href="http://en.wikipedia.org/wiki/SciPy" rel="nofollow"... | 1 | 2012-03-21T13:12:26Z | [
"python",
"excel",
"matlab",
"numpy"
] |
Using Python to replace MATLAB: how to import data? | 1,057,666 | <p>I want to use some Python libraries to replace MATLAB. How could I import Excel data in Python (for example using <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) to use them?</p>
<p>I don't know if Python is a credible alternative to MATLAB, but I want to try it. Is there a a tutorial?</p>
| 11 | 2009-06-29T10:44:24Z | 25,717,165 | <p>Pandas is a Python data analysis library that can import/export from Excel pretty easily. Here's how to do it:</p>
<p><a href="http://pandas.pydata.org/pandas-docs/stable/10min.html#excel" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/10min.html#excel</a></p>
<p>Crash course:</p>
<pre><code>import pa... | 2 | 2014-09-08T03:44:12Z | [
"python",
"excel",
"matlab",
"numpy"
] |
python+encryption: Encrypting session key using public key | 1,057,768 | <p>I want to encrypt the session key using the public key. How does the PGP software do this?
Can somebody specify the procedure or function of encryption in Python?</p>
| 3 | 2009-06-29T11:11:15Z | 1,059,366 | <p>See <a href="http://ubuntuforums.org/showthread.php?t=687173" rel="nofollow">this post</a> for background information about the basic technology. That post is about encryption in general - for information about using gpg from Python, see <a href="http://stackoverflow.com/questions/1020320/how-to-do-pgp-in-python-gen... | 1 | 2009-06-29T17:03:04Z | [
"python",
"encryption",
"public-key"
] |
python+encryption: Encrypting session key using public key | 1,057,768 | <p>I want to encrypt the session key using the public key. How does the PGP software do this?
Can somebody specify the procedure or function of encryption in Python?</p>
| 3 | 2009-06-29T11:11:15Z | 1,060,144 | <p>There's also the PyCrypto module that looks exactly like what you are looking for: <a href="http://www.dlitz.net/software/pycrypto/" rel="nofollow">http://www.dlitz.net/software/pycrypto/</a> the API docs are here: <a href="http://www.dlitz.net/software/pycrypto/apidoc/" rel="nofollow">http://www.dlitz.net/software/... | 2 | 2009-06-29T19:48:44Z | [
"python",
"encryption",
"public-key"
] |
python+encryption: Encrypting session key using public key | 1,057,768 | <p>I want to encrypt the session key using the public key. How does the PGP software do this?
Can somebody specify the procedure or function of encryption in Python?</p>
| 3 | 2009-06-29T11:11:15Z | 1,184,661 | <p>See <a href="http://stackoverflow.com/questions/90413/what-is-the-best-easiest-to-use-encryption-library-in-python">What is the best/easiest to use encryption library in python</a>, which mentions a <a href="http://stackoverflow.com/questions/90413/what-is-the-best-easiest-to-use-encryption-library-in-python/90959#9... | 0 | 2009-07-26T13:56:02Z | [
"python",
"encryption",
"public-key"
] |
How can I import a package using __import__() when the package name is only known at runtime? | 1,057,843 | <p>I have a messages folder(package) with <code>__init__.py</code> file and another module <code>messages_en.py</code> inside it. In <code>__init__.py</code> if I import <code>messages_en</code> it works, but <code>__import__</code> fails with "ImportError: No module named messages_en"</p>
<pre><code>import messages_e... | 13 | 2009-06-29T11:35:00Z | 1,057,891 | <p><code>__import__</code> is an internal function called by import statement. In everyday coding you don't need (or want) to call <code>__import__</code></p>
<p>from python documentation:</p>
<p>For example, the statement <code>import spam</code> results in bytecode resembling the following code:</p>
<pre><code>spa... | 13 | 2009-06-29T11:46:41Z | [
"python",
"python-import"
] |
How can I import a package using __import__() when the package name is only known at runtime? | 1,057,843 | <p>I have a messages folder(package) with <code>__init__.py</code> file and another module <code>messages_en.py</code> inside it. In <code>__init__.py</code> if I import <code>messages_en</code> it works, but <code>__import__</code> fails with "ImportError: No module named messages_en"</p>
<pre><code>import messages_e... | 13 | 2009-06-29T11:35:00Z | 1,057,898 | <p>If it is a path problem, you should use the <code>level</code> argument (from <a href="http://docs.python.org/2/library/functions.html?highlight=__import__#__import__">docs</a>):</p>
<pre><code>__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module
Level is used to determine whether to perform... | 19 | 2009-06-29T11:49:01Z | [
"python",
"python-import"
] |
How can I import a package using __import__() when the package name is only known at runtime? | 1,057,843 | <p>I have a messages folder(package) with <code>__init__.py</code> file and another module <code>messages_en.py</code> inside it. In <code>__init__.py</code> if I import <code>messages_en</code> it works, but <code>__import__</code> fails with "ImportError: No module named messages_en"</p>
<pre><code>import messages_e... | 13 | 2009-06-29T11:35:00Z | 1,057,908 | <p>You could try this:</p>
<pre><code>messages == __import__('Foo.messages_en', fromlist=['messages_en'])
</code></pre>
| 0 | 2009-06-29T11:53:31Z | [
"python",
"python-import"
] |
How can I import a package using __import__() when the package name is only known at runtime? | 1,057,843 | <p>I have a messages folder(package) with <code>__init__.py</code> file and another module <code>messages_en.py</code> inside it. In <code>__init__.py</code> if I import <code>messages_en</code> it works, but <code>__import__</code> fails with "ImportError: No module named messages_en"</p>
<pre><code>import messages_e... | 13 | 2009-06-29T11:35:00Z | 2,799,005 | <p>Be sure to append the modules directory to your python path.</p>
<p>Your path (the list of directories Python goes through to search for modules and files) is stored in the path attribute of the sys module. Since the path is a list you can use the append method to add new directories to the path. </p>
<p>For insta... | 3 | 2010-05-09T20:07:42Z | [
"python",
"python-import"
] |
How can I import a package using __import__() when the package name is only known at runtime? | 1,057,843 | <p>I have a messages folder(package) with <code>__init__.py</code> file and another module <code>messages_en.py</code> inside it. In <code>__init__.py</code> if I import <code>messages_en</code> it works, but <code>__import__</code> fails with "ImportError: No module named messages_en"</p>
<pre><code>import messages_e... | 13 | 2009-06-29T11:35:00Z | 13,175,052 | <p>Adding the globals argument is sufficient for me:</p>
<pre><code>__import__('messages_en', globals=globals())
</code></pre>
<p>In fact, only <code>__name__</code> is needed here:</p>
<pre><code>__import__('messages_en', globals={"__name__": __name__})
</code></pre>
| 14 | 2012-11-01T10:22:54Z | [
"python",
"python-import"
] |
How can I import a package using __import__() when the package name is only known at runtime? | 1,057,843 | <p>I have a messages folder(package) with <code>__init__.py</code> file and another module <code>messages_en.py</code> inside it. In <code>__init__.py</code> if I import <code>messages_en</code> it works, but <code>__import__</code> fails with "ImportError: No module named messages_en"</p>
<pre><code>import messages_e... | 13 | 2009-06-29T11:35:00Z | 30,736,067 | <p>You need to manually import the top package of your dynamic package path.</p>
<p>For example in the beginning of the file i write:</p>
<pre><code>import sites
</code></pre>
<p>then later in code this works for me:</p>
<pre><code>target = 'some.dynamic.path'
my_module = __import__ ('sites.%s.fabfile' % target, fr... | 0 | 2015-06-09T15:12:53Z | [
"python",
"python-import"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,057,953 | <p>I don't think what you want is directly possible in Python. </p>
<p>You could, however, try one of the following.</p>
<ol>
<li>When generating <code>to_import_from.py</code>, add the non-generated stuff there too. This way,
all methods are in the same class definition.</li>
<li>Have <code>to_import_from.py</code> ... | 5 | 2009-06-29T12:09:07Z | [
"python",
"import",
"methods"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,057,956 | <p>I'm sorry that this is kind of a <a href="https://stackoverflow.fogbugz.com/default.asp?W29025" rel="nofollow">"You shouldn't be putting nails in the wall" answer</a>, but you're missing the point of python class definitions. You should rather put the class with all its methods in its own python file, and in your <c... | 3 | 2009-06-29T12:09:24Z | [
"python",
"import",
"methods"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,057,967 | <p>you can do this with the <code>__getattr__</code> method</p>
<p>external.py</p>
<pre><code>def external_function(arg):
print("external", arg)
</code></pre>
<p>main.py:</p>
<pre><code>import external
class Instrument(object):
def __getattr__(self, name):
if hasattr(external, name):
re... | 4 | 2009-06-29T12:12:21Z | [
"python",
"import",
"methods"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,057,976 | <p>What you're doing is extending a base class with some "machine-generated" code.</p>
<p>Choice 1. Extend a base class with machine-generated code.</p>
<p>machine_generated.py</p>
<pre><code># Start of boilerplate #
import main_module
class Instrument_Implementation( main_module.Instrument_Abstraction ):
def d... | 2 | 2009-06-29T12:13:30Z | [
"python",
"import",
"methods"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,058,132 | <p>It's easier than you think:</p>
<pre><code>class Instrument(Object):
def __init__(self):
self.flag = True
def direct_method(self,arg1):
self.external_method(arg1, arg2)
import to_import_from
Instrument.external_method = to_import_from.external_method
</code></pre>
<p>Done!</p>
<p>Althoug... | 6 | 2009-06-29T12:57:04Z | [
"python",
"import",
"methods"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,058,212 | <p>Here's my try. I think a nicer approach could be made with metaclasses...</p>
<p>to_import_from.py :</p>
<pre><code>def external_method(self, arg1, arg2):
if self.flag:
print "flag is set"
else :
print "flag is not set"
</code></pre>
<p>instrument.py :</p>
<pre><code>import imp
import os
... | 0 | 2009-06-29T13:14:46Z | [
"python",
"import",
"methods"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,058,221 | <p>Technically, yes this is possible, but solving it this way is not really idiomatic python, and there are likely better solutions. Here's an example of how to do so:</p>
<pre><code>import to_import_from
class Instrument(object):
locals().update(dict((k,v) for (k,v) in
to_import_from.__dict... | 0 | 2009-06-29T13:15:57Z | [
"python",
"import",
"methods"
] |
Importing methods for a Python class | 1,057,934 | <p>I wonder if it's possible to keep methods for a Python class in a different file from the class definition, something like this:</p>
<p><code>main_module.py:</code></p>
<pre><code>class Instrument(Object):
# Some import statement?
def __init__(self):
self.flag = True
def direct_method(self,arg1... | 8 | 2009-06-29T12:01:57Z | 1,059,377 | <p>People seem to be overthinking this. Methods are just function valued local variables in class construction scope. So the following works fine:</p>
<pre><code>class Instrument(Object):
# load external methods
from to_import_from import *
def __init__(self):
self.flag = True
def direct_metho... | 4 | 2009-06-29T17:06:06Z | [
"python",
"import",
"methods"
] |
Execute a prepared statement in sqlalchemy | 1,058,037 | <p>I have to run 40K requests against a username:</p>
<pre><code>SELECT * from user WHERE login = :login
</code></pre>
<p>It's slow, so I figured I would just use a prepared statement.</p>
<p>So I do</p>
<pre><code>e = sqlalchemy.create_engine(...)
c = e.connect()
c.execute("PREPARE userinfo(text) AS SELECT * from ... | 1 | 2009-06-29T12:29:11Z | 1,058,123 | <p>From <a href="http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg08278.html" rel="nofollow" title="Connection Already Closed">this discussion</a>, it might be a good idea to check your paster debug logs in case there is a better error message there.</p>
| 1 | 2009-06-29T12:54:30Z | [
"python",
"sqlalchemy"
] |
Execute a prepared statement in sqlalchemy | 1,058,037 | <p>I have to run 40K requests against a username:</p>
<pre><code>SELECT * from user WHERE login = :login
</code></pre>
<p>It's slow, so I figured I would just use a prepared statement.</p>
<p>So I do</p>
<pre><code>e = sqlalchemy.create_engine(...)
c = e.connect()
c.execute("PREPARE userinfo(text) AS SELECT * from ... | 1 | 2009-06-29T12:29:11Z | 1,058,199 | <p>Not sure how to solve your cursor related error message, but I dont think a prepared staement will solve your performance issue - as long as your using SQL server 2005 or later the execution plan for <code>SELECT * from user WHERE login = $login</code> will already be re-used and there will be no performance gain fr... | 1 | 2009-06-29T13:12:23Z | [
"python",
"sqlalchemy"
] |
What should I call this function composition? | 1,058,273 | <p>What should 'foo' be called, given the following?</p>
<p>x.items is a set, y.values is a set.</p>
<p>function a(key) returns an ordered list of x.items</p>
<p>function b(x.item) returns a single y.value</p>
<p>Define foo(a, b), which returns a function, d, such that d(key) returns a list of y.values defined by: ... | 1 | 2009-06-29T13:22:43Z | 1,058,290 | <p>I would call it <strong>function compositor</strong> or something like that</p>
| 1 | 2009-06-29T13:25:49Z | [
"python",
"math",
"functional-programming"
] |
What should I call this function composition? | 1,058,273 | <p>What should 'foo' be called, given the following?</p>
<p>x.items is a set, y.values is a set.</p>
<p>function a(key) returns an ordered list of x.items</p>
<p>function b(x.item) returns a single y.value</p>
<p>Define foo(a, b), which returns a function, d, such that d(key) returns a list of y.values defined by: ... | 1 | 2009-06-29T13:22:43Z | 1,058,328 | <p>The synergy engine.</p>
| 0 | 2009-06-29T13:31:41Z | [
"python",
"math",
"functional-programming"
] |
What should I call this function composition? | 1,058,273 | <p>What should 'foo' be called, given the following?</p>
<p>x.items is a set, y.values is a set.</p>
<p>function a(key) returns an ordered list of x.items</p>
<p>function b(x.item) returns a single y.value</p>
<p>Define foo(a, b), which returns a function, d, such that d(key) returns a list of y.values defined by: ... | 1 | 2009-06-29T13:22:43Z | 1,058,402 | <p>Here's are example names for a, b, and foo that might help (I don't like these, but they're sort of like what I'm getting at):</p>
<pre>
items_by_key(key)
value_by_item(item)
values_by_key(items_by_key, value_by_item)
</pre>
| 0 | 2009-06-29T13:44:00Z | [
"python",
"math",
"functional-programming"
] |
What should I call this function composition? | 1,058,273 | <p>What should 'foo' be called, given the following?</p>
<p>x.items is a set, y.values is a set.</p>
<p>function a(key) returns an ordered list of x.items</p>
<p>function b(x.item) returns a single y.value</p>
<p>Define foo(a, b), which returns a function, d, such that d(key) returns a list of y.values defined by: ... | 1 | 2009-06-29T13:22:43Z | 1,100,571 | <pre><code> function a(key) returns an ordered list of x.items
function b(x.item) returns a single y.value
</code></pre>
<p>Except for the ordering, a() is in practice a filter, i.e. it "filters" or "selects" items from x.items according to a key. b() is a normal map, or function. Thus, I would choose for 'foo' the n... | 2 | 2009-07-08T21:14:27Z | [
"python",
"math",
"functional-programming"
] |
What should I call this function composition? | 1,058,273 | <p>What should 'foo' be called, given the following?</p>
<p>x.items is a set, y.values is a set.</p>
<p>function a(key) returns an ordered list of x.items</p>
<p>function b(x.item) returns a single y.value</p>
<p>Define foo(a, b), which returns a function, d, such that d(key) returns a list of y.values defined by: ... | 1 | 2009-06-29T13:22:43Z | 1,107,216 | <p>I would call that function <strong>permuted_values</strong></p>
<p>What you are doing is equivalent to iterating over a hash map using a permutation based on your key.</p>
| 1 | 2009-07-10T01:02:41Z | [
"python",
"math",
"functional-programming"
] |
How to add hooks in twisted.web (or twisted.web2)? | 1,058,300 | <p>How can I add a hook before and after processing a request on twisted.web (twisted.web2 is fine too)? The equivalent of webpy's:</p>
<pre><code>app = web.application(urls, globals())
app.add_processor(web.loadhook(my_attach_callback))
app.add_processor(web.unloadhook(my_detach_callback))
</code></pre>
<p>Thanks!</... | 2 | 2009-06-29T13:27:28Z | 4,069,597 | <p>One approach Twisted Web allows is to insert an extra resource into the resource hierarchy the only purpose of which is to run your custom hooks, rather than to actually handle a segment of the request URL as resources typically do.</p>
<p>You can find an implementation of this approach in <a href="http://twistedma... | 1 | 2010-11-01T14:09:38Z | [
"python",
"callback",
"hook",
"twisted"
] |
Unicode problems with web pages in Python's urllib | 1,058,302 | <p>I seem to have the all-familiar problem of correctly reading and viewing a web page. It looks like Python reads the page in UTF-8 but when I try to convert it to something more viewable (iso-8859-1) I get this error:</p>
<pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 2: ordi... | 1 | 2009-06-29T13:27:41Z | 1,058,532 | <p>That text is indeed iso-88591-1, and I can decode it without a problem, and indeed your code runs without a hitch.</p>
<p>Your error, however, is an ENCODE error, not a decode error. And you don't do any encoding in your code, so. Possibly you have gotten encoding and decoding confused, it's a common problem.</p>
... | 1 | 2009-06-29T14:11:18Z | [
"python",
"unicode"
] |
Unicode problems with web pages in Python's urllib | 1,058,302 | <p>I seem to have the all-familiar problem of correctly reading and viewing a web page. It looks like Python reads the page in UTF-8 but when I try to convert it to something more viewable (iso-8859-1) I get this error:</p>
<pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 2: ordi... | 1 | 2009-06-29T13:27:41Z | 1,058,592 | <p>As noted by Lennart, your problem is not the decoding. It is trying to encode into "ascii", which is often a problem with <code>print</code> statements. I suspect the line</p>
<pre><code>print str
</code></pre>
<p>is your problem. You need to encode the str into whatever your console is using to have that line w... | 3 | 2009-06-29T14:21:03Z | [
"python",
"unicode"
] |
Unicode problems with web pages in Python's urllib | 1,058,302 | <p>I seem to have the all-familiar problem of correctly reading and viewing a web page. It looks like Python reads the page in UTF-8 but when I try to convert it to something more viewable (iso-8859-1) I get this error:</p>
<pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 2: ordi... | 1 | 2009-06-29T13:27:41Z | 1,058,995 | <p>It doesn't look like Python is "reading it in UTF-8" at all. As already pointed out, you have an encoding problem, NOT a decoding problem. It is impossible for that error to have arisen from that line that you say. When asking a question like this, always give the full traceback and error message.</p>
<p>Kathy's su... | 2 | 2009-06-29T15:42:05Z | [
"python",
"unicode"
] |
Coding a coroutine in Python to display "odd" and "even" numbers inifinitely | 1,058,383 | <p>I have scratchy ideas of Generators, Iterators and Coroutines. (from PEPs and other tutorials). I want to implement a coroutine- in which routine1 will print odd and routine2 will print even numbers infinitely in a fashion such as:</p>
<pre><code>routine1:
print odd
yield to routine2
routune2:
print ev... | 0 | 2009-06-29T13:42:04Z | 1,058,481 | <p>You yield back to the method that called you. Hence you can't yield to routine 1. You just yield. You could let routine 1 call routine 2, and routine 2 can yield and hence return back to routine 1.</p>
| 1 | 2009-06-29T13:59:03Z | [
"python"
] |
Coding a coroutine in Python to display "odd" and "even" numbers inifinitely | 1,058,383 | <p>I have scratchy ideas of Generators, Iterators and Coroutines. (from PEPs and other tutorials). I want to implement a coroutine- in which routine1 will print odd and routine2 will print even numbers infinitely in a fashion such as:</p>
<pre><code>routine1:
print odd
yield to routine2
routune2:
print ev... | 0 | 2009-06-29T13:42:04Z | 1,058,610 | <p><a href="http://www.python.org/dev/peps/pep-0342/" rel="nofollow">PEP 342</a>, "Coroutines via Enhanced Generators", gives as its example 3 'A simple co-routine scheduler or "trampoline" that lets coroutines "call" other coroutines by yielding the coroutine they wish to invoke.' -- you don't need that much generalit... | 2 | 2009-06-29T14:24:11Z | [
"python"
] |
Flags in Python | 1,058,434 | <p>I'm working with a large matrix (250x250x30 = 1,875,000 cells), and I'd like a way to set an arbitrary number of flags for each cell in this matrix, in some manner that's easy to use and reasonably space efficient.</p>
<p>My original plan was a 250x250x30 list array, where each element was something like: <code>["F... | 4 | 2009-06-29T13:49:38Z | 1,058,452 | <p><a href="http://en.wikipedia.org/wiki/Bit%5Farray" rel="nofollow">BitSet</a> is what you want, since it allows you to store many flags at once using only an fixed size integer (Int type)</p>
| 1 | 2009-06-29T13:53:34Z | [
"python",
"matrix",
"numpy",
"flags"
] |
Flags in Python | 1,058,434 | <p>I'm working with a large matrix (250x250x30 = 1,875,000 cells), and I'd like a way to set an arbitrary number of flags for each cell in this matrix, in some manner that's easy to use and reasonably space efficient.</p>
<p>My original plan was a 250x250x30 list array, where each element was something like: <code>["F... | 4 | 2009-06-29T13:49:38Z | 1,058,466 | <p>Your solution is fine if every single cell is going to have a flag. However if you are working with a sparse dataset where only a small subsection of your cells will have flags what you really want is a dictionary. You would want to set up the dictonary so the key is a tuple for the location of the cell and the va... | 7 | 2009-06-29T13:56:34Z | [
"python",
"matrix",
"numpy",
"flags"
] |
Flags in Python | 1,058,434 | <p>I'm working with a large matrix (250x250x30 = 1,875,000 cells), and I'd like a way to set an arbitrary number of flags for each cell in this matrix, in some manner that's easy to use and reasonably space efficient.</p>
<p>My original plan was a 250x250x30 list array, where each element was something like: <code>["F... | 4 | 2009-06-29T13:49:38Z | 1,058,488 | <p>Consider using Flyweight pattern to share cell properties:</p>
<p><a href="http://en.wikipedia.org/wiki/Flyweight%5Fpattern" rel="nofollow">http://en.wikipedia.org/wiki/Flyweight_pattern</a></p>
| 3 | 2009-06-29T14:00:25Z | [
"python",
"matrix",
"numpy",
"flags"
] |
Flags in Python | 1,058,434 | <p>I'm working with a large matrix (250x250x30 = 1,875,000 cells), and I'd like a way to set an arbitrary number of flags for each cell in this matrix, in some manner that's easy to use and reasonably space efficient.</p>
<p>My original plan was a 250x250x30 list array, where each element was something like: <code>["F... | 4 | 2009-06-29T13:49:38Z | 1,058,506 | <p>You can define some constants with different, power of two values as:</p>
<pre><code>FLAG1 = 0x01
FLAG8 = 0x02
FLAG12 = 0x04
...
</code></pre>
<p>And use them with boolean logic to store the flags in only one integer, p.e.:</p>
<pre><code>flags = FLAG1 | FLAG8
</code></pre>
<p>To check if a flag is enabled, you ... | 5 | 2009-06-29T14:04:42Z | [
"python",
"matrix",
"numpy",
"flags"
] |
Flags in Python | 1,058,434 | <p>I'm working with a large matrix (250x250x30 = 1,875,000 cells), and I'd like a way to set an arbitrary number of flags for each cell in this matrix, in some manner that's easy to use and reasonably space efficient.</p>
<p>My original plan was a 250x250x30 list array, where each element was something like: <code>["F... | 4 | 2009-06-29T13:49:38Z | 1,058,524 | <p>I would generally use a <a href="http://numpy.scipy.org/" rel="nofollow">numpy</a> array (presumably of short ints, 2 bytes each, since you may need more than 256 distinct values) -- that would take less than 4MB for the <2 million cells.</p>
<p>If for some reason I couldn't afford the numpy dependency (e.g on A... | 4 | 2009-06-29T14:09:34Z | [
"python",
"matrix",
"numpy",
"flags"
] |
Flags in Python | 1,058,434 | <p>I'm working with a large matrix (250x250x30 = 1,875,000 cells), and I'd like a way to set an arbitrary number of flags for each cell in this matrix, in some manner that's easy to use and reasonably space efficient.</p>
<p>My original plan was a 250x250x30 list array, where each element was something like: <code>["F... | 4 | 2009-06-29T13:49:38Z | 1,058,542 | <p>Taking Robbie's suggestion one step further...</p>
<pre><code>flags = set()
x, y, flag = 34, 201, 3
flags.add((x, y, flag)) # set flag 3 at position (34, 201)
if (3, 2, 1) in flags: # check if flag 1 is at position (3, 2)
# do something
else:
# do something else
</code></pre>
<p>You can also create a helpe... | 1 | 2009-06-29T14:13:39Z | [
"python",
"matrix",
"numpy",
"flags"
] |
How to get a nested element in beautiful soup | 1,058,599 | <p>I am struggling with the syntax required to grab some hrefs in a td.
The table, tr and td elements dont have any class's or id's.</p>
<p>If I wanted to grab the anchor in this example, what would I need?</p>
<p>< tr >
< td > < a >...</p>
<p>Thanks</p>
| 10 | 2009-06-29T14:22:55Z | 1,058,691 | <p>Something like this?</p>
<pre>
<code>
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)
anchors = [td.find('a') for td in soup.findAll('td')]
</code>
</pre>
<p>That should find the first "a" inside each "td" in the html you provide. You can tweak <code>td.find</code> to be more specific or else u... | 11 | 2009-06-29T14:37:15Z | [
"python",
"beautifulsoup"
] |
How to get a nested element in beautiful soup | 1,058,599 | <p>I am struggling with the syntax required to grab some hrefs in a td.
The table, tr and td elements dont have any class's or id's.</p>
<p>If I wanted to grab the anchor in this example, what would I need?</p>
<p>< tr >
< td > < a >...</p>
<p>Thanks</p>
| 10 | 2009-06-29T14:22:55Z | 1,058,693 | <p>As per the docs, you first make a parse tree:</p>
<pre><code>import BeautifulSoup
html = "<html><body><tr><td><a href='foo'/></td></tr></body></html>"
soup = BeautifulSoup.BeautifulSoup(html)
</code></pre>
<p>and then you search in it, for example for <code><... | 12 | 2009-06-29T14:37:27Z | [
"python",
"beautifulsoup"
] |
How do I select a random element from an array in Python? | 1,058,712 | <p>The first examples that I googled didn't work. This should be trivial, right?</p>
| 34 | 2009-06-29T14:42:22Z | 1,058,725 | <pre><code>import random
random.choice([1, 2, 3])
</code></pre>
| 20 | 2009-06-29T14:44:32Z | [
"python",
"arrays",
"random"
] |
How do I select a random element from an array in Python? | 1,058,712 | <p>The first examples that I googled didn't work. This should be trivial, right?</p>
| 34 | 2009-06-29T14:42:22Z | 1,058,727 | <pre><code>import random
random.choice (mylist)
</code></pre>
| 88 | 2009-06-29T14:44:38Z | [
"python",
"arrays",
"random"
] |
How do I select a random element from an array in Python? | 1,058,712 | <p>The first examples that I googled didn't work. This should be trivial, right?</p>
| 34 | 2009-06-29T14:42:22Z | 1,058,764 | <p>Here's the documentation link: <a href="http://docs.python.org/library/random.html#random.choice">http://docs.python.org/library/random.html#random.choice</a></p>
| 7 | 2009-06-29T14:50:57Z | [
"python",
"arrays",
"random"
] |
How to append two strings in Python? | 1,058,902 | <p>I have done this operation millions of times, just using the <code>+</code> operator! I have no idea why it is not working this time, it is overwriting the first part of the string with the new one! I have a list of strings and just want to concatenate them in one single string! If I run the program from Eclipse it... | 2 | 2009-06-29T15:22:32Z | 1,058,922 | <p>You should use the following and forget about this nightmare:</p>
<pre><code>''.join(list_of_strings)
</code></pre>
| 19 | 2009-06-29T15:26:25Z | [
"python",
"string"
] |
How to append two strings in Python? | 1,058,902 | <p>I have done this operation millions of times, just using the <code>+</code> operator! I have no idea why it is not working this time, it is overwriting the first part of the string with the new one! I have a list of strings and just want to concatenate them in one single string! If I run the program from Eclipse it... | 2 | 2009-06-29T15:22:32Z | 1,058,952 | <p>I just gave it a quick look. It seems your problem arises when you are printing the text. I haven't done such things for a long time, but probably you only get the last line when you print. If you check the actual variable, I'm sure you'll find that the value is correct.</p>
<p>By last line, I'm talking about the \... | 5 | 2009-06-29T15:32:06Z | [
"python",
"string"
] |
How to append two strings in Python? | 1,058,902 | <p>I have done this operation millions of times, just using the <code>+</code> operator! I have no idea why it is not working this time, it is overwriting the first part of the string with the new one! I have a list of strings and just want to concatenate them in one single string! If I run the program from Eclipse it... | 2 | 2009-06-29T15:22:32Z | 1,058,957 | <p>While the two answers are correct (use " ".join()), your problem (besides <em>very</em> ugly python code) is this:</p>
<p>Your strings end in "\r", which is a carriage return. Everything is fine, but when you print to the console, "\r" will make printing continue from the start <em>of the same line</em>, hence over... | 31 | 2009-06-29T15:32:26Z | [
"python",
"string"
] |
How to append two strings in Python? | 1,058,902 | <p>I have done this operation millions of times, just using the <code>+</code> operator! I have no idea why it is not working this time, it is overwriting the first part of the string with the new one! I have a list of strings and just want to concatenate them in one single string! If I run the program from Eclipse it... | 2 | 2009-06-29T15:22:32Z | 1,058,974 | <p>The problem is not with the concatenation of the strings (although that could use some cleaning up), but in your printing. The \r in your string has a special meaning and will overwrite previously printed strings.</p>
<p>Use repr(), as such:</p>
<pre><code>...
print "line value : ", repr(lineList[count])
temp = li... | 11 | 2009-06-29T15:37:49Z | [
"python",
"string"
] |
How to append two strings in Python? | 1,058,902 | <p>I have done this operation millions of times, just using the <code>+</code> operator! I have no idea why it is not working this time, it is overwriting the first part of the string with the new one! I have a list of strings and just want to concatenate them in one single string! If I run the program from Eclipse it... | 2 | 2009-06-29T15:22:32Z | 1,058,982 | <p>'\r' is the carriage return character. When you're printing out a string, a '\r' will cause the next characters to go at the start of the line.</p>
<p>Change this:</p>
<pre><code>print "ediMsg : ",ediMsg
</code></pre>
<p>to:</p>
<pre><code>print "ediMsg : ",repr(ediMsg)
</code></pre>
<p>and you will se... | 8 | 2009-06-29T15:39:59Z | [
"python",
"string"
] |
How to append two strings in Python? | 1,058,902 | <p>I have done this operation millions of times, just using the <code>+</code> operator! I have no idea why it is not working this time, it is overwriting the first part of the string with the new one! I have a list of strings and just want to concatenate them in one single string! If I run the program from Eclipse it... | 2 | 2009-06-29T15:22:32Z | 1,059,010 | <p>Your problem <strong>is</strong> printing, and it <strong>is not</strong> string manipulation. Try using '\n' as last char instead of '\r' in each string in:</p>
<pre><code>lineList = [
"UNH+1+TCCARQ:08:2:1A+%CONVID%'&\r",
"ORG+1A+77499505:PARAF0103+++A+FR:EUR++11730788+1A'&\r",
"DUM'&\r",
... | 7 | 2009-06-29T15:44:39Z | [
"python",
"string"
] |
Mule vs ActiveMQ for Python | 1,058,986 | <p>I need to manged several servers, network services, appalication server (Apache, Tomcat) and manage them (start stop, install software).</p>
<p>I would like to use Python, since C++ seems to complex and less productive for thing task. In am not sure which middleware to use. ActiveMQ and Mule seem to be a good choic... | -1 | 2009-06-29T15:40:41Z | 1,059,225 | <p><strong>An example python "script" that manages various services on multiple remote servers:</strong></p>
<p>What follows is a hacked together script that can be used to manage various services on servers that you have SSH access to.</p>
<p>You will ideally want to have an ssh-agent running, or you will be typing ... | 1 | 2009-06-29T16:29:14Z | [
"python",
"messaging"
] |
wxPython RichTextCtrl much slower than tkInter Text? | 1,059,214 | <p>I've made a small tool that parses a chunk of text, does some simple processing (retrieves values from a dictionary, a few regex, etc.) and then spits the results.</p>
<p>In order to make easier to read the results, I made two graphic ports, one with tkInter and other with wxPython, so the output is nicely displaye... | 0 | 2009-06-29T16:26:18Z | 1,070,836 | <p>It kind of avoids the question slightly, but could you use wxStyledTextCtrl instead?</p>
| 0 | 2009-07-01T19:14:24Z | [
"python",
"performance",
"wxpython",
"tkinter",
"richtextediting"
] |
wxPython RichTextCtrl much slower than tkInter Text? | 1,059,214 | <p>I've made a small tool that parses a chunk of text, does some simple processing (retrieves values from a dictionary, a few regex, etc.) and then spits the results.</p>
<p>In order to make easier to read the results, I made two graphic ports, one with tkInter and other with wxPython, so the output is nicely displaye... | 0 | 2009-06-29T16:26:18Z | 1,189,222 | <p>I'm copying here the comment that solved the problem:</p>
<blockquote>
<p>Have you tried using Freeze() and
Thaw() to only update the display
after you are done appending the
coloured text? â mghie Jun 30 at 7:20</p>
</blockquote>
| 1 | 2009-07-27T16:32:18Z | [
"python",
"performance",
"wxpython",
"tkinter",
"richtextediting"
] |
Searching across multiple tables (best practices) | 1,059,253 | <p>I have property management application consisting of tables:</p>
<pre><code>tenants
landlords
units
properties
vendors-contacts
</code></pre>
<p>Basically I want one search field to search them all rather than having to select which category I am searching. Would this be an acceptable solution (technology wise?)<... | 2 | 2009-06-29T16:36:05Z | 1,059,280 | <p>Why not create a view which is a union of the tables which aggregates the columns you want to search on into one, and then search on that aggregated column?</p>
<p>You could do something like this:</p>
<pre><code>select 'tenants:' + ltrim(str(t.Id)), <shared fields> from Tenants as t union
select 'landlords:... | 7 | 2009-06-29T16:42:14Z | [
"python",
"sql",
"mysql",
"postgresql",
"pylons"
] |
Searching across multiple tables (best practices) | 1,059,253 | <p>I have property management application consisting of tables:</p>
<pre><code>tenants
landlords
units
properties
vendors-contacts
</code></pre>
<p>Basically I want one search field to search them all rather than having to select which category I am searching. Would this be an acceptable solution (technology wise?)<... | 2 | 2009-06-29T16:36:05Z | 1,059,284 | <p>You should be fine, and there's really no other good (easy) way to do this. Just make sure the fields you are searching on are properly indexed though.</p>
| 1 | 2009-06-29T16:42:44Z | [
"python",
"sql",
"mysql",
"postgresql",
"pylons"
] |
Searching across multiple tables (best practices) | 1,059,253 | <p>I have property management application consisting of tables:</p>
<pre><code>tenants
landlords
units
properties
vendors-contacts
</code></pre>
<p>Basically I want one search field to search them all rather than having to select which category I am searching. Would this be an acceptable solution (technology wise?)<... | 2 | 2009-06-29T16:36:05Z | 1,059,286 | <p>You want to use <a href="http://www.postgresql.org/docs/8.3/static/textsearch.html" rel="nofollow">the built-in full text search</a> or a separate product like <a href="http://lucene.apache.org/java/docs/" rel="nofollow">Lucene</a>. This is optimised for unstructured searches over heterogeneous data.</p>
<p>Also, d... | 4 | 2009-06-29T16:43:21Z | [
"python",
"sql",
"mysql",
"postgresql",
"pylons"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.