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 list |
|---|---|---|---|---|---|---|---|---|---|
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 4,684,418 | <p>We stumbled over a bug in Django with big sitemaps (10.000 items). Seems Django is trying to load them all in memory when generating the sitemap: <a href="http://code.djangoproject.com/ticket/11572" rel="nofollow">http://code.djangoproject.com/ticket/11572</a> - effectively kills the apache process when Google pays ... | 1 | 2011-01-13T19:37:37Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Client Server programming in python? | 487,229 | <p>Here is source code for multithreaed server and client in python.</p>
<p>In the code client and server closes connection after the job is finished.
I want to keep the connections alive and send more data over the same connections to <strong>avoid overhead of closing and opening sockets every time</strong>.</p>
<p>... | 8 | 2009-01-28T10:55:51Z | 487,255 | <p>I'm not sure I understand the question, but don't call <code>close()</code> if you don't want to close the connection...</p>
| 2 | 2009-01-28T11:08:09Z | [
"python",
"multithreading",
"client",
"sockets"
] |
Client Server programming in python? | 487,229 | <p>Here is source code for multithreaed server and client in python.</p>
<p>In the code client and server closes connection after the job is finished.
I want to keep the connections alive and send more data over the same connections to <strong>avoid overhead of closing and opening sockets every time</strong>.</p>
<p>... | 8 | 2009-01-28T10:55:51Z | 487,281 | <p>Spawning a new thread for every connection is a <strong>really bad</strong> design choice.
What happens if you get hit by a lot of connections?</p>
<p>In fact, using threads to wait for network IO is not worth it. Your program gets really complex and you get absolutely <strong>no benefit</strong> since waiting for ... | 18 | 2009-01-28T11:19:49Z | [
"python",
"multithreading",
"client",
"sockets"
] |
Client Server programming in python? | 487,229 | <p>Here is source code for multithreaed server and client in python.</p>
<p>In the code client and server closes connection after the job is finished.
I want to keep the connections alive and send more data over the same connections to <strong>avoid overhead of closing and opening sockets every time</strong>.</p>
<p>... | 8 | 2009-01-28T10:55:51Z | 487,284 | <p>For an example of a client the keeps a TCP connection open and uses a familiar protocol,
look at the <a href="http://svn.python.org/view/python/trunk/Lib/telnetlib.py?rev=63788&view=log" rel="nofollow">source</a> of the <a href="http://docs.python.org/library/telnetlib.html#module-telnetlib" rel="nofollow">telne... | 0 | 2009-01-28T11:20:54Z | [
"python",
"multithreading",
"client",
"sockets"
] |
pyqt import problem | 487,484 | <p>I am having some trouble doing this in Python:</p>
<pre><code>from PyQt4 import QtCore, QtGui
from dcopext import DCOPClient, DCOPApp
</code></pre>
<p>The traceback I get is</p>
<pre><code>from dcopext import DCOPClient, DCOPApp
File "/usr/lib/python2.5/site-packages/dcopext.py", line 35, in <module>
from ... | 2 | 2009-01-28T12:44:30Z | 487,568 | <p>The <code>dcopext</code> module is part of <a href="http://www.riverbankcomputing.co.uk/software/pykde/intro" rel="nofollow">PyKDE3</a>, the Python bindings for KDE3 which uses Qt 3.x, while you're using PyQt/Qt 4.x. </p>
<p>You need to upgrade to <a href="http://techbase.kde.org/Development/Languages/Python/Using_... | 1 | 2009-01-28T13:14:55Z | [
"python",
"pyqt",
"dcop"
] |
Transfering object through Pyro | 487,553 | <p>I'm using Pyro in a project, and can't seem to understand how to transfer a complete object over the wire. The object is <strong>not</strong> distributed (my distributed objects works perfectly fine), but should function as an argument to an already available distributed object. </p>
<p>My object is a derived from ... | 4 | 2009-01-28T13:07:31Z | 487,720 | <p>Operations is a class attribute, not the object attribute. That is why it's not transferred. Try setting it in <code>__init__</code> via <code>self.operations = <whatever></code>.</p>
| 4 | 2009-01-28T14:04:50Z | [
"python",
"distributed"
] |
Transfering object through Pyro | 487,553 | <p>I'm using Pyro in a project, and can't seem to understand how to transfer a complete object over the wire. The object is <strong>not</strong> distributed (my distributed objects works perfectly fine), but should function as an argument to an already available distributed object. </p>
<p>My object is a derived from ... | 4 | 2009-01-28T13:07:31Z | 487,740 | <p>Your receiving method, <strong>apply</strong>, has the same name as the built-in Python function.</p>
| 1 | 2009-01-28T14:10:33Z | [
"python",
"distributed"
] |
Inventory Control Across Multiple Servers .. Ideas? | 487,642 | <p>We currently have an inventory management system that was built in-house. It works great, and we are constantly innovating it. </p>
<p>This past Fall, we began selling products directly on one of our websites via a Shopping Cart checkout.</p>
<p>Our inventory management system runs off a server in the office, whil... | 0 | 2009-01-28T13:39:54Z | 487,660 | <p>One possibility would be to expose a web service interface on your inventory management system that allows the transactions used by the web shopfront to be accessed remotely. With a reasonably secure VPN link or ssh tunnel type arrangement, the web shopfront could get stock levels, place orders or execute searches ... | 1 | 2009-01-28T13:45:27Z | [
"python",
"tracking",
"inventory"
] |
Inventory Control Across Multiple Servers .. Ideas? | 487,642 | <p>We currently have an inventory management system that was built in-house. It works great, and we are constantly innovating it. </p>
<p>This past Fall, we began selling products directly on one of our websites via a Shopping Cart checkout.</p>
<p>Our inventory management system runs off a server in the office, whil... | 0 | 2009-01-28T13:39:54Z | 487,674 | <p>I don't see the problem... You have an application running on one server that manages your database locally. There's no reason a remote server can't also talk to that database.</p>
<p>Of course, if you don't have a database and are instead using a homegrown app to act as some sort of faux-database, I recommend that... | 0 | 2009-01-28T13:50:56Z | [
"python",
"tracking",
"inventory"
] |
Inventory Control Across Multiple Servers .. Ideas? | 487,642 | <p>We currently have an inventory management system that was built in-house. It works great, and we are constantly innovating it. </p>
<p>This past Fall, we began selling products directly on one of our websites via a Shopping Cart checkout.</p>
<p>Our inventory management system runs off a server in the office, whil... | 0 | 2009-01-28T13:39:54Z | 706,707 | <p>I'm not sure if there is any one really good solution for your problem. I think the way you are doing it now works fine, but if you don't agree then I don't know what to tell you.</p>
| 0 | 2009-04-01T18:03:48Z | [
"python",
"tracking",
"inventory"
] |
Inventory Control Across Multiple Servers .. Ideas? | 487,642 | <p>We currently have an inventory management system that was built in-house. It works great, and we are constantly innovating it. </p>
<p>This past Fall, we began selling products directly on one of our websites via a Shopping Cart checkout.</p>
<p>Our inventory management system runs off a server in the office, whil... | 0 | 2009-01-28T13:39:54Z | 3,858,221 | <p>I know you wanted to find a solution that works with your existing code, but have you considered a third party multi channel manager system? As your business grows and the scale of your orders increase, it may become easier to use a multi channel manager system such as Mailware. As an <a href="http://www.mailware.co... | 1 | 2010-10-04T18:54:38Z | [
"python",
"tracking",
"inventory"
] |
How can I get interactive Python to avoid using readline while allowing utf-8 input? | 487,800 | <p>I use a terminal (9term) that does command-line editing itself - programs that use readline just get in its way. It's fully utf-8 aware. How can I make an interactive python session disable readline while retaining utf-8 input and output?</p>
<p>Currently I use:</p>
<pre><code>LANG=en_GB.UTF-8 export LANG
cat | py... | 3 | 2009-01-28T14:26:28Z | 487,891 | <p>In the past, I've disabled Python readline by rebuilding it from source: <code>configure --disable-readline</code></p>
<p>This might be overkill, though, for your situation.</p>
| 2 | 2009-01-28T14:51:43Z | [
"python",
"utf-8",
"interactive"
] |
Is there a standard way to list names of Python modules in a package? | 487,971 | <p>Is there a straightforward way to list the names of all modules in a package, without using <code>__all__</code>?</p>
<p>For example, given this package:</p>
<pre><code>/testpkg
/testpkg/__init__.py
/testpkg/modulea.py
/testpkg/moduleb.py
</code></pre>
<p>I'm wondering if there is a standard or built-in way to do... | 57 | 2009-01-28T15:11:32Z | 487,981 | <p>print dir(module)</p>
| 0 | 2009-01-28T15:13:17Z | [
"python",
"module",
"package"
] |
Is there a standard way to list names of Python modules in a package? | 487,971 | <p>Is there a straightforward way to list the names of all modules in a package, without using <code>__all__</code>?</p>
<p>For example, given this package:</p>
<pre><code>/testpkg
/testpkg/__init__.py
/testpkg/modulea.py
/testpkg/moduleb.py
</code></pre>
<p>I'm wondering if there is a standard or built-in way to do... | 57 | 2009-01-28T15:11:32Z | 489,489 | <pre><code>import module
help(module)
</code></pre>
| 11 | 2009-01-28T21:35:25Z | [
"python",
"module",
"package"
] |
Is there a standard way to list names of Python modules in a package? | 487,971 | <p>Is there a straightforward way to list the names of all modules in a package, without using <code>__all__</code>?</p>
<p>For example, given this package:</p>
<pre><code>/testpkg
/testpkg/__init__.py
/testpkg/modulea.py
/testpkg/moduleb.py
</code></pre>
<p>I'm wondering if there is a standard or built-in way to do... | 57 | 2009-01-28T15:11:32Z | 489,649 | <p>Maybe this will do what you're looking for?</p>
<pre><code>import imp
import os
MODULE_EXTENSIONS = ('.py', '.pyc', '.pyo')
def package_contents(package_name):
file, pathname, description = imp.find_module(package_name)
if file:
raise ImportError('Not a package: %r', package_name)
# Use a set b... | 14 | 2009-01-28T22:14:44Z | [
"python",
"module",
"package"
] |
Is there a standard way to list names of Python modules in a package? | 487,971 | <p>Is there a straightforward way to list the names of all modules in a package, without using <code>__all__</code>?</p>
<p>For example, given this package:</p>
<pre><code>/testpkg
/testpkg/__init__.py
/testpkg/modulea.py
/testpkg/moduleb.py
</code></pre>
<p>I'm wondering if there is a standard or built-in way to do... | 57 | 2009-01-28T15:11:32Z | 681,980 | <pre><code>def package_contents(package_name):
package = __import__(package_name)
return [module_name for module_name in dir(package) if not module_name.startswith("__")]
</code></pre>
| -2 | 2009-03-25T14:58:11Z | [
"python",
"module",
"package"
] |
Is there a standard way to list names of Python modules in a package? | 487,971 | <p>Is there a straightforward way to list the names of all modules in a package, without using <code>__all__</code>?</p>
<p>For example, given this package:</p>
<pre><code>/testpkg
/testpkg/__init__.py
/testpkg/modulea.py
/testpkg/moduleb.py
</code></pre>
<p>I'm wondering if there is a standard or built-in way to do... | 57 | 2009-01-28T15:11:32Z | 1,310,912 | <p>Using <a href="http://docs.python.org/library/pkgutil.html">python2.3 and above</a>, you could also use the <code>pkgutil</code> module:</p>
<pre><code>>>> import pkgutil
>>> [name for _, name, _ in pkgutil.iter_modules(['testpkg'])]
['modulea', 'moduleb']
</code></pre>
<p><strong>EDIT:</strong> ... | 124 | 2009-08-21T09:21:02Z | [
"python",
"module",
"package"
] |
Is there a standard way to list names of Python modules in a package? | 487,971 | <p>Is there a straightforward way to list the names of all modules in a package, without using <code>__all__</code>?</p>
<p>For example, given this package:</p>
<pre><code>/testpkg
/testpkg/__init__.py
/testpkg/modulea.py
/testpkg/moduleb.py
</code></pre>
<p>I'm wondering if there is a standard or built-in way to do... | 57 | 2009-01-28T15:11:32Z | 15,833,780 | <p><strike>Don't know if I'm overlooking something, or if the answers are just out-dated but;</strike></p>
<p>As stated by user815423426 this only works for live objects and the listed modules are only modules that were imported before.</p>
<p>Listing modules in a package seems really easy using <a href="http://docs.... | 5 | 2013-04-05T12:18:29Z | [
"python",
"module",
"package"
] |
Is there a standard way to list names of Python modules in a package? | 487,971 | <p>Is there a straightforward way to list the names of all modules in a package, without using <code>__all__</code>?</p>
<p>For example, given this package:</p>
<pre><code>/testpkg
/testpkg/__init__.py
/testpkg/modulea.py
/testpkg/moduleb.py
</code></pre>
<p>I'm wondering if there is a standard or built-in way to do... | 57 | 2009-01-28T15:11:32Z | 36,764,029 | <p>Based on cdleary's example, here's a recursive version listing path for all submodules:</p>
<pre><code>import imp, os
def iter_submodules(package):
file, pathname, description = imp.find_module('isc_datasources')
for dirpath, _, filenames in os.walk(pathname):
for filename in filenames:
... | 0 | 2016-04-21T08:33:14Z | [
"python",
"module",
"package"
] |
Django: ModelMultipleChoiceField doesn't select initial choices | 488,036 | <p>ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below) work in my example:</p>
<p><a href="http://code.djangoproject.com/ticket/5247#comment:6">http://code.djangoproject.com/ticket/5247#comment:6</a></p>
<p>My models and form:</p>
<pre><code>class Company(models.Mo... | 18 | 2009-01-28T15:30:02Z | 488,113 | <p>You will need to add an <code>__init__</code> method to <code>Action_Form</code> to set your initial values, remembering to call <code>__init__</code> on the base <code>ModelForm</code> class via <strong>super</strong>.</p>
<pre><code>class Action_Form(forms.ModelForm):
def __init__(self, *args, **kwargs):
... | 8 | 2009-01-28T15:45:06Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Django: ModelMultipleChoiceField doesn't select initial choices | 488,036 | <p>ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below) work in my example:</p>
<p><a href="http://code.djangoproject.com/ticket/5247#comment:6">http://code.djangoproject.com/ticket/5247#comment:6</a></p>
<p>My models and form:</p>
<pre><code>class Company(models.Mo... | 18 | 2009-01-28T15:30:02Z | 1,530,632 | <p>I'm replying for 1)</p>
<blockquote>1. How can I make ModelMultipleChoiceField take those "initial" values?</blockquote>
<p>This could be done in your <code>Action_Form</code> <code>__init__</code> method using ModelMultipleChoiceField <code>initial</code> attribute.</p>
<p>As it says in the Django source code (<... | 18 | 2009-10-07T10:01:37Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Django: ModelMultipleChoiceField doesn't select initial choices | 488,036 | <p>ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below) work in my example:</p>
<p><a href="http://code.djangoproject.com/ticket/5247#comment:6">http://code.djangoproject.com/ticket/5247#comment:6</a></p>
<p>My models and form:</p>
<pre><code>class Company(models.Mo... | 18 | 2009-01-28T15:30:02Z | 3,915,048 | <p>If previous answer wasn't straight-forward enough, I try to answer 1) again:</p>
<blockquote>
<ol>
<li>How can I make ModelMultipleChoiceField take those "initial" values?</li>
</ol>
</blockquote>
<p>You can leave <code>Action_Form</code> as it was in the original question, and just use this to render exactl... | 8 | 2010-10-12T13:13:25Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Django: ModelMultipleChoiceField doesn't select initial choices | 488,036 | <p>ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below) work in my example:</p>
<p><a href="http://code.djangoproject.com/ticket/5247#comment:6">http://code.djangoproject.com/ticket/5247#comment:6</a></p>
<p>My models and form:</p>
<pre><code>class Company(models.Mo... | 18 | 2009-01-28T15:30:02Z | 20,661,777 | <p>Answer to (1) question!</p>
<p>This will not work:</p>
<pre><code>self.fields['from_company'].initial = [c.pk for c in Contact.object.filter()]
</code></pre>
<p>But this will <strong>really work</strong>:</p>
<pre><code>self.initial['from_company'] = [c.pk for c in Contact.object.filter()]
</code></pre>
| 5 | 2013-12-18T15:14:45Z | [
"python",
"django",
"django-models",
"django-forms"
] |
ZipFile complains, is there a way around using the zipfile module? | 488,054 | <p>I am trying to decompress some MMS messages sent to me zipped. The problem is that sometimes it works, and others not. And when it doesnt work, the python zipfile module complains and says that it is a bad zip file. But the zipfile decompresses fine using the unix unzip command.</p>
<p>This is what ive got</p>
<pr... | 1 | 2009-01-28T15:34:11Z | 488,074 | <p>You should very probably open the file in binary mode, when writing zipped data into it. That is, you should use</p>
<pre><code>zippedfile = open('%stemp/tempfile.zip' % settings.MEDIA_ROOT, 'wb+')
</code></pre>
| 4 | 2009-01-28T15:37:03Z | [
"python",
"zip",
"popen",
"zipfile"
] |
ZipFile complains, is there a way around using the zipfile module? | 488,054 | <p>I am trying to decompress some MMS messages sent to me zipped. The problem is that sometimes it works, and others not. And when it doesnt work, the python zipfile module complains and says that it is a bad zip file. But the zipfile decompresses fine using the unix unzip command.</p>
<p>This is what ive got</p>
<pr... | 1 | 2009-01-28T15:34:11Z | 488,261 | <p>You might have to close and reopen the file, or maybe seek to the start of the file after writing it.</p>
<pre><code>filename = '%stemp/tempfile.zip' % settings.MEDIA_ROOT
zippedfile = open(filename , 'wb+')
zippedfile.write(string)
zippedfile.close()
z = zipfile.ZipFile(filename,"r")
</code></pre>
<p>You say the ... | 0 | 2009-01-28T16:21:03Z | [
"python",
"zip",
"popen",
"zipfile"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 488,402 | <p>According to <a href="http://bytes.com/groups/python/22914-os-environ-os-path-chdir" rel="nofollow">this discussion</a>, you cannot do it. What are you trying to accomplish?</p>
| 3 | 2009-01-28T16:46:09Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 488,407 | <p>You are forking a new process and cannot change the environment of the parent process as you cannot do if you start a new shell process from the shell</p>
| 2 | 2009-01-28T16:46:48Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 488,419 | <p>I don't believe you can do this; there are two work-arounds I can think of.</p>
<ol>
<li><p>The <code>os.putenv</code> function sets the environment for processes you start with, i.e. os.system, popen, etc. Depending on what you're trying to do, perhaps you could have one master Python instance that sets the varia... | 4 | 2009-01-28T16:48:48Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 488,475 | <p>Under Windows it's possible for you to make changes to environment variables persistent via the registry with <a href="http://code.activestate.com/recipes/416087/">this recipe</a>, though it seems like overkill.</p>
<p>To echo Brian's question, what are you trying to accomplish? There is probably an easier way.</p... | 5 | 2009-01-28T17:09:48Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 488,713 | <blockquote>
<p>make them stick by committing them to
the system?</p>
</blockquote>
<p>I think you are a bit confused here. There is no 'system' environment. Each process has their own environment as part its memory. A process can only change its own environment. A process can set the initial environment for pr... | 7 | 2009-01-28T18:16:58Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 488,904 | <p>You might want to try <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">Python Win32 Extensions</a>, developed by Mark Hammond, which is included in the <a href="http://www.activestate.com/activepython/downloads" rel="nofollow">ActivePython</a> (or can be installed separately). You can learn how to p... | 2 | 2009-01-28T19:05:00Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 490,350 | <p>Think about it this way.</p>
<p>You're not setting shell environment variables.</p>
<p>You're spawning a subshell with some given environment variable settings; this subshell runs your application with the modified environment.</p>
| 2 | 2009-01-29T02:57:14Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 490,404 | <p>From within Python? No, it can't be done!</p>
<p>If you are not bound to Python, you should consider using shell scripts (sh, bash, etc). The "source" command allows you to run a script that modifies the environment and will "stick" like you want to the shell you "sourced" the script in. What's going on here is ... | 1 | 2009-01-29T03:38:25Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 18,283,127 | <p>You can using SETX at the command-line.</p>
<p>By default these actions go on the USER env vars.
To set and modify SYSTEM vars use the /M flag</p>
<pre><code>import os
env_var = "BUILD_NUMBER"
env_val = "3.1.3.3.7"
os.system("SETX {0} {1} /M".format(env_var,env_val))
</code></pre>
| 1 | 2013-08-16T22:35:26Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 36,040,437 | <p>Seems like there is simplier solution for Windows</p>
<pre><code>import subprocess
subprocess.call(['setx', 'Hello', 'World!'], shell=True)
</code></pre>
| 0 | 2016-03-16T15:41:30Z | [
"python",
"environment-variables"
] |
How do I make environment variable changes stick in Python? | 488,366 | <p>From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?</p>
<p>The reason I need to do this is because at the studio where I work, too... | 10 | 2009-01-28T16:36:47Z | 38,419,436 | <p>In case someone might need this info. I realize this was asked 7 yrs ago, but even I forget how sometimes. .</p>
<p>Yes there is a way to make them "stick" in windows. Simply go control panel, system, advanced system settings,when the system properties window opens you should see an option (button) for Environment ... | 0 | 2016-07-17T08:45:49Z | [
"python",
"environment-variables"
] |
Can a python script persistently change a Windows environment variable? (elegantly) | 488,449 | <p>Following on from my <a href="http://stackoverflow.com/questions/488294/how-can-i-make-a-windows-batch-file-which-changes-an-environment-variable">previous question</a>, is it possible to make a Python script which persistently changes a Windows environment variable? </p>
<p>Changes to os.environ do not persist onc... | 6 | 2009-01-28T17:00:53Z | 488,535 | <p>Your long-winded solution is probably the best idea; I don't believe this is possible from Python directly. This article suggests another way, using a temporary batch file:</p>
<p><a href="http://code.activestate.com/recipes/159462/" rel="nofollow">http://code.activestate.com/recipes/159462/</a></p>
| 1 | 2009-01-28T17:24:23Z | [
"python",
"windows",
"scripting",
"batch-file"
] |
Can a python script persistently change a Windows environment variable? (elegantly) | 488,449 | <p>Following on from my <a href="http://stackoverflow.com/questions/488294/how-can-i-make-a-windows-batch-file-which-changes-an-environment-variable">previous question</a>, is it possible to make a Python script which persistently changes a Windows environment variable? </p>
<p>Changes to os.environ do not persist onc... | 6 | 2009-01-28T17:00:53Z | 488,696 | <p>You might want to try <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">Python Win32 Extensions</a>, developed by Mark Hammond, which is included in the <a href="http://www.activestate.com/activepython/downloads" rel="nofollow">ActivePython</a> (or can be installed separately). You can learn how to p... | 5 | 2009-01-28T18:10:53Z | [
"python",
"windows",
"scripting",
"batch-file"
] |
Can a python script persistently change a Windows environment variable? (elegantly) | 488,449 | <p>Following on from my <a href="http://stackoverflow.com/questions/488294/how-can-i-make-a-windows-batch-file-which-changes-an-environment-variable">previous question</a>, is it possible to make a Python script which persistently changes a Windows environment variable? </p>
<p>Changes to os.environ do not persist onc... | 6 | 2009-01-28T17:00:53Z | 488,737 | <p>Windows sets Environment variables from values stored in the Registry for each process independently.</p>
<p>However, there is a tool in the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=49AE8576-9BB9-4126-9761-BA8011FABF38&displaylang=en" rel="nofollow">Windows XP Service Pack 2 Support Too... | 3 | 2009-01-28T18:25:05Z | [
"python",
"windows",
"scripting",
"batch-file"
] |
Can a python script persistently change a Windows environment variable? (elegantly) | 488,449 | <p>Following on from my <a href="http://stackoverflow.com/questions/488294/how-can-i-make-a-windows-batch-file-which-changes-an-environment-variable">previous question</a>, is it possible to make a Python script which persistently changes a Windows environment variable? </p>
<p>Changes to os.environ do not persist onc... | 6 | 2009-01-28T17:00:53Z | 594,917 | <p>My solution using win32api:</p>
<pre><code>import os, sys, win32api, win32con
'''Usage: appendenv.py envvar data_to_append'''
def getenv_system(varname, default=None):
'''
Author: Denis Barmenkov <barmenkov at bpc.ru>
Copyright: this code is free, but if you want to use it,
please... | 3 | 2009-02-27T14:16:08Z | [
"python",
"windows",
"scripting",
"batch-file"
] |
Can a python script persistently change a Windows environment variable? (elegantly) | 488,449 | <p>Following on from my <a href="http://stackoverflow.com/questions/488294/how-can-i-make-a-windows-batch-file-which-changes-an-environment-variable">previous question</a>, is it possible to make a Python script which persistently changes a Windows environment variable? </p>
<p>Changes to os.environ do not persist onc... | 6 | 2009-01-28T17:00:53Z | 19,640,752 | <p>This <a href="http://code.activestate.com/recipes/577621/" rel="nofollow">link</a> provides a solution that uses the built-in <code>winreg</code> library.</p>
<p>(copypasta)</p>
<pre><code>import sys
from subprocess import check_call
if sys.hexversion > 0x03000000:
import winreg
else:
import _winreg as ... | 1 | 2013-10-28T17:00:31Z | [
"python",
"windows",
"scripting",
"batch-file"
] |
about one to many relationship in datastore and dereferncing in google app engine? | 488,498 | <p>i have a one to many relationship between two entities the first one is a satellite and the second one is channel and the satellite form returns a satellite name which i want to appear in another html page with the channel data where you can say that this channel is related to that satellite
how to make this</p>
| 4 | 2009-01-28T17:17:57Z | 492,750 | <p>This sounds like a good case for using the ReferenceProperty that is part of the Datastore API of App Engine. Here's an idea to get you started:</p>
<pre><code>class Satellite(db.Model):
name = db.StringProperty()
class Channel(db.Model):
satellite = db.ReferenceProperty(Satellite, collection_name='channels')... | 6 | 2009-01-29T18:13:02Z | [
"python",
"google-app-engine"
] |
MS Outlook CDO/MAPI Blocking Python File Output? | 488,504 | <p>Here is an example of the problem I am running into. I am using the Python Win32 extensions to access an Outlook mailbox and retrieve messages.</p>
<p>Below is a script that should write "hello world" to a text file. I need to grab some messages from an Outlook mailbox and I noticed something weird. After I atta... | 1 | 2009-01-28T17:19:56Z | 489,403 | <p>answering my own question. it looks like your working directory gets changed when you read the email. If you set it back, your file i/o works fine.</p>
<p>the correct script would look like this:</p>
<pre><code>#!/usr/bin/env python
import os
from win32com.client import Dispatch
fh = open('foo.txt', 'w')
fh.wr... | 1 | 2009-01-28T21:12:38Z | [
"python",
"winapi",
"outlook",
"mapi",
"cdo"
] |
MS Outlook CDO/MAPI Blocking Python File Output? | 488,504 | <p>Here is an example of the problem I am running into. I am using the Python Win32 extensions to access an Outlook mailbox and retrieve messages.</p>
<p>Below is a script that should write "hello world" to a text file. I need to grab some messages from an Outlook mailbox and I noticed something weird. After I atta... | 1 | 2009-01-28T17:19:56Z | 491,245 | <p>Yes, the directory change is a known gotcha when using CDO/MAPI. It is "documented" somewhere in MSDN (eg <a href="http://support.microsoft.com/kb/269170" rel="nofollow">http://support.microsoft.com/kb/269170</a>). You can reproduce it easily in Python like this:</p>
<pre>
<code>
import os
import win32com.client
p... | 1 | 2009-01-29T11:15:22Z | [
"python",
"winapi",
"outlook",
"mapi",
"cdo"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 488,695 | <p>I don't know Python, but for the averaging part, do you mean an exponentially decaying low-pass filter of the form</p>
<pre><code>y_new = y_old + (input - y_old)*alpha
</code></pre>
<p>where alpha = dt/tau, dt = the timestep of the filter, tau = the time constant of the filter? (the variable-timestep form of this ... | 4 | 2009-01-28T18:10:09Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 488,700 | <p>I did a bit of googling and I found the following sample code (http://osdir.com/ml/python.matplotlib.general/2005-04/msg00044.html):</p>
<pre><code>def ema(s, n):
"""
returns an n period exponential moving average for
the time series s
s is a list ordered from oldest (index 0) to most
recent (i... | 8 | 2009-01-28T18:12:07Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 488,825 | <p>My python is a little bit rusty (anyone can feel free to edit this code to make corrections, if I've messed up the syntax somehow), but here goes....</p>
<pre><code>def movingAverageExponential(values, alpha, epsilon = 0):
if not 0 < alpha < 1:
raise ValueError("out of range, alpha='%s'" % alpha)
... | 5 | 2009-01-28T18:46:59Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 488,941 | <p>EDIT:
It seems that <a href="http://www.scipy.org/scipy/scikits/browser/trunk/timeseries/scikits/timeseries/lib/moving_funcs.py"><code>mov_average_expw()</code></a> function from <a href="http://pytseries.sourceforge.net/lib/moving_funcs.html">scikits.timeseries.lib.moving_funcs</a> submodule from <a href="http://sc... | 15 | 2009-01-28T19:15:34Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 21,739,006 | <p>I found the above code snippet by @earino pretty useful - but I needed something that could continuously smooth a stream of values - so I refactored it to this:</p>
<pre class="lang-py prettyprint-override"><code>def exponential_moving_average(period=1000):
""" Exponential moving average. Smooths the values in ... | 2 | 2014-02-12T20:35:05Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 24,398,487 | <p>In matplotlib.org examples (<a href="http://matplotlib.org/examples/pylab_examples/finance_work2.html" rel="nofollow">http://matplotlib.org/examples/pylab_examples/finance_work2.html</a>) is provided one good example of Exponential Moving Average (EMA) function using numpy:</p>
<pre><code>def moving_average(x, n, t... | 4 | 2014-06-25T00:38:56Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 31,955,317 | <p>Here is a simple sample I worked up based on <a href="http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages" rel="nofollow">http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages</a></p>
<p>Note that unlike in their spreadsheet, I don't calc... | 0 | 2015-08-12T03:00:42Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
calculate exponential moving average in python | 488,670 | <p>I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this?</p>
<p>I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. M... | 14 | 2009-01-28T18:01:44Z | 32,933,590 | <p>I'm always calculating EMAs with Pandas:</p>
<p>Here is an example how to do it:</p>
<pre><code>import pandas as pd
import numpy as np
def ema(values, period):
values = np.array(values)
return pd.ewma(values, span=period)[-1]
values = [9, 5, 10, 16, 5]
period = 5
print ema(values, period)
</code></pre>
... | 2 | 2015-10-04T12:42:55Z | [
"python",
"signal-processing",
"average",
"digital-filter"
] |
Validating Python Arguments in Subclasses | 488,772 | <p>I'm trying to validate a few python arguments. Until we get the new static typing in Python 3.0, what is the best way of going about this.</p>
<p>Here is an example of what I am attempting:</p>
<pre><code>class A(object):
@accepts(int, int, int)
def __init__(a, b, c):
pass
class B(A):
@accepts... | 0 | 2009-01-28T18:31:42Z | 488,946 | <p>You might want to play around with the <code>inspect</code> module. It will let you enumerate superclasses, argument lists, and other fun stuff. It seems that you might want to inspect the argument list of the superclass <code>__init__</code> method and compare it against what you have in the subclass. I'm not sure ... | 0 | 2009-01-28T19:17:18Z | [
"python",
"inheritance",
"decorator",
"static-typing"
] |
Validating Python Arguments in Subclasses | 488,772 | <p>I'm trying to validate a few python arguments. Until we get the new static typing in Python 3.0, what is the best way of going about this.</p>
<p>Here is an example of what I am attempting:</p>
<pre><code>class A(object):
@accepts(int, int, int)
def __init__(a, b, c):
pass
class B(A):
@accepts... | 0 | 2009-01-28T18:31:42Z | 488,996 | <p>Why not just define an <code>any</code> value, and decorate the subclass constructor with <code>@accepts(any, any, any, int)</code>? Your decorator won't check parameters marked with <code>any</code>, and the <code>@accepts</code> on the superclass constructor will check all the arguments passed up to it by subclass... | 1 | 2009-01-28T19:32:30Z | [
"python",
"inheritance",
"decorator",
"static-typing"
] |
Given an rpm package name, query the yum database for updates | 489,113 | <p>I was imagining a 3-line Python script to do this but the yum Python API is impenetrable. Is this even possible?</p>
<p>Is writing a wrapper for 'yum list package-name' the only way to do this?</p>
| 5 | 2009-01-28T20:12:07Z | 490,314 | <p><a href="http://fpaste.org/paste/2453">http://fpaste.org/paste/2453</a></p>
<p>and there are many examples of the yum api and some guides to getting started with it here:</p>
<p><a href="http://yum.baseurl.org/#DeveloperDocumentationExamples">http://yum.baseurl.org/#DeveloperDocumentationExamples</a></p>
| 7 | 2009-01-29T02:36:40Z | [
"python",
"rpm",
"yum"
] |
Given an rpm package name, query the yum database for updates | 489,113 | <p>I was imagining a 3-line Python script to do this but the yum Python API is impenetrable. Is this even possible?</p>
<p>Is writing a wrapper for 'yum list package-name' the only way to do this?</p>
| 5 | 2009-01-28T20:12:07Z | 490,410 | <p>As Seth points out, you can use the updates APIs to ask if something is available as an update. For something that's close to what the "yum list" does you probably want to use the doPackageLists(). Eg.</p>
<pre><code>import os, sys
import yum
yb = yum.YumBase()
yb.conf.cache = os.geteuid() != 1
pl = yb.doPackageLi... | 5 | 2009-01-29T03:41:55Z | [
"python",
"rpm",
"yum"
] |
Python super() raises TypeError | 489,269 | <p>In Python 2.5.2, the following code raises a TypeError:</p>
<pre><code>>>> class X:
... def a(self):
... print "a"
...
>>> class Y(X):
... def a(self):
... super(Y,self).a()
... print "b"
...
>>> c = Y()
>>> c.a()
Traceback (most recent call last):
File "<std... | 98 | 2009-01-28T20:47:10Z | 489,278 | <p>The reason is that super() only operates on new-style classes, which in the 2.x series means extending from object.</p>
| 121 | 2009-01-28T20:48:26Z | [
"python",
"super"
] |
Python super() raises TypeError | 489,269 | <p>In Python 2.5.2, the following code raises a TypeError:</p>
<pre><code>>>> class X:
... def a(self):
... print "a"
...
>>> class Y(X):
... def a(self):
... super(Y,self).a()
... print "b"
...
>>> c = Y()
>>> c.a()
Traceback (most recent call last):
File "<std... | 98 | 2009-01-28T20:47:10Z | 500,110 | <p>In addition, don't use super() unless you have to. It's not the general-purpose "right thing" to do with new-style classes that you might suspect.</p>
<p>There are times when you're expecting multiple inheritance and you might possibly want it, but until you know the hairy details of the MRO, best leave it alone an... | 13 | 2009-02-01T03:23:05Z | [
"python",
"super"
] |
Python super() raises TypeError | 489,269 | <p>In Python 2.5.2, the following code raises a TypeError:</p>
<pre><code>>>> class X:
... def a(self):
... print "a"
...
>>> class Y(X):
... def a(self):
... super(Y,self).a()
... print "b"
...
>>> c = Y()
>>> c.a()
Traceback (most recent call last):
File "<std... | 98 | 2009-01-28T20:47:10Z | 9,974,607 | <p>I tried the various X.a() methods; however, they seem to require an instance of X in order to perform a(), so I did X().a(self), which seems more complete than the previous answers, at least for the applications I've encountered. It doesn't seem to be a good way of handling the problem as there is unnecessary constr... | 1 | 2012-04-02T10:18:40Z | [
"python",
"super"
] |
Why am I getting the following error in Python "ImportError: No module named py"? | 489,497 | <p>I'm a Python newbie, so bear with me :)</p>
<p>I created a file called test.py with the contents as follows:</p>
<pre><code>test.py
import sys
print sys.platform
print 2 ** 100
</code></pre>
<p>I then ran <code>import test.py</code> file in the interpreter to follow an example in my book.
When I do this, I get th... | 11 | 2009-01-28T21:37:27Z | 489,501 | <p>You don't specify the extension when importing. Just do:</p>
<pre><code>import test
</code></pre>
| 5 | 2009-01-28T21:39:12Z | [
"python"
] |
Why am I getting the following error in Python "ImportError: No module named py"? | 489,497 | <p>I'm a Python newbie, so bear with me :)</p>
<p>I created a file called test.py with the contents as follows:</p>
<pre><code>test.py
import sys
print sys.platform
print 2 ** 100
</code></pre>
<p>I then ran <code>import test.py</code> file in the interpreter to follow an example in my book.
When I do this, I get th... | 11 | 2009-01-28T21:37:27Z | 489,503 | <p>Instead of:</p>
<pre><code>import test.py
</code></pre>
<p>simply write:</p>
<pre><code>import test
</code></pre>
<p>This assumes test.py is in the same directory as the file that imports it.</p>
| 26 | 2009-01-28T21:39:36Z | [
"python"
] |
Why am I getting the following error in Python "ImportError: No module named py"? | 489,497 | <p>I'm a Python newbie, so bear with me :)</p>
<p>I created a file called test.py with the contents as follows:</p>
<pre><code>test.py
import sys
print sys.platform
print 2 ** 100
</code></pre>
<p>I then ran <code>import test.py</code> file in the interpreter to follow an example in my book.
When I do this, I get th... | 11 | 2009-01-28T21:37:27Z | 489,540 | <p>As others have mentioned, you don't need to put the file extension in your import statement. Recommended reading is the <a href="http://docs.python.org/tutorial/modules.html" rel="nofollow">Modules section of the Python Tutorial</a>.</p>
<p>For a little more background into the error, the interpreter thinks you're ... | 2 | 2009-01-28T21:47:51Z | [
"python"
] |
Why am I getting the following error in Python "ImportError: No module named py"? | 489,497 | <p>I'm a Python newbie, so bear with me :)</p>
<p>I created a file called test.py with the contents as follows:</p>
<pre><code>test.py
import sys
print sys.platform
print 2 ** 100
</code></pre>
<p>I then ran <code>import test.py</code> file in the interpreter to follow an example in my book.
When I do this, I get th... | 11 | 2009-01-28T21:37:27Z | 489,547 | <p>This strange-looking error is a result of how Python imports modules. </p>
<p><strong>Python sees</strong>: </p>
<pre><code>import test.py
</code></pre>
<p><strong>Python thinks</strong> (simplified a bit):</p>
<blockquote>
<p>import module test.</p>
<ul>
<li>search for a test.py in the module search p... | 5 | 2009-01-28T21:48:36Z | [
"python"
] |
Is there a way to make a user-defined Python function act like a built-in statement? | 489,524 | <p>Is it possible to make a user-defined Python function act like a statement? In other words, I'd like to be able to say:</p>
<pre><code>myfunc
</code></pre>
<p>rather than:</p>
<pre><code>myfunc()
</code></pre>
<p>and have it get called anyway -- the way that, say, <code>print</code> would.</p>
<p>I can already ... | 1 | 2009-01-28T21:43:58Z | 489,529 | <p>No, it is not possible.</p>
<p>As you can see from the <a href="http://docs.python.org/3.0/reference/simple_stmts.html#simple-statements" rel="nofollow">Language Reference</a>, there is no room left for extensions of the list of simple statements in the specification.</p>
<p>Moreover, <code>print</code> as a state... | 9 | 2009-01-28T21:45:29Z | [
"python"
] |
Is there a way to make a user-defined Python function act like a built-in statement? | 489,524 | <p>Is it possible to make a user-defined Python function act like a statement? In other words, I'd like to be able to say:</p>
<pre><code>myfunc
</code></pre>
<p>rather than:</p>
<pre><code>myfunc()
</code></pre>
<p>and have it get called anyway -- the way that, say, <code>print</code> would.</p>
<p>I can already ... | 1 | 2009-01-28T21:43:58Z | 489,543 | <p>If what you're looking for is to add a new statement (like <code>print</code>) to Python's language, then this would not be easy. You'd probably have to modify lexer, parser and then recompile Python's C sources. A lot of work to do for a questionable convenience.</p>
| 3 | 2009-01-28T21:48:16Z | [
"python"
] |
Is there a way to make a user-defined Python function act like a built-in statement? | 489,524 | <p>Is it possible to make a user-defined Python function act like a statement? In other words, I'd like to be able to say:</p>
<pre><code>myfunc
</code></pre>
<p>rather than:</p>
<pre><code>myfunc()
</code></pre>
<p>and have it get called anyway -- the way that, say, <code>print</code> would.</p>
<p>I can already ... | 1 | 2009-01-28T21:43:58Z | 489,550 | <p>Not if you want to pass in arguments. You could do something build an object that ABUSES the <code>__str__</code> method, but it is highly not recommended. You can also use other operators like overload the <code><<</code> operator like <code>cout</code> does in C++.</p>
| 2 | 2009-01-28T21:49:13Z | [
"python"
] |
Is there a way to make a user-defined Python function act like a built-in statement? | 489,524 | <p>Is it possible to make a user-defined Python function act like a statement? In other words, I'd like to be able to say:</p>
<pre><code>myfunc
</code></pre>
<p>rather than:</p>
<pre><code>myfunc()
</code></pre>
<p>and have it get called anyway -- the way that, say, <code>print</code> would.</p>
<p>I can already ... | 1 | 2009-01-28T21:43:58Z | 489,566 | <p>In Python 2.x print is not a function it is a statement just as if, while and def are statements.</p>
| 1 | 2009-01-28T21:56:11Z | [
"python"
] |
Is there a way to make a user-defined Python function act like a built-in statement? | 489,524 | <p>Is it possible to make a user-defined Python function act like a statement? In other words, I'd like to be able to say:</p>
<pre><code>myfunc
</code></pre>
<p>rather than:</p>
<pre><code>myfunc()
</code></pre>
<p>and have it get called anyway -- the way that, say, <code>print</code> would.</p>
<p>I can already ... | 1 | 2009-01-28T21:43:58Z | 489,611 | <p>I would not implement this, but if I was implementing this, I would give code with myfunc a special extension, write an import hook to parse the file, add the parenthesis to make it valid Python, and feed that into the interpreter.</p>
| 3 | 2009-01-28T22:05:38Z | [
"python"
] |
Is there a way to make a user-defined Python function act like a built-in statement? | 489,524 | <p>Is it possible to make a user-defined Python function act like a statement? In other words, I'd like to be able to say:</p>
<pre><code>myfunc
</code></pre>
<p>rather than:</p>
<pre><code>myfunc()
</code></pre>
<p>and have it get called anyway -- the way that, say, <code>print</code> would.</p>
<p>I can already ... | 1 | 2009-01-28T21:43:58Z | 494,066 | <p>This probably isn't going to cover your problem, but I'll mention it anyway. If <code>myfunc</code> is part of a module, and you are using it like this:</p>
<pre><code>from mymodule import myfunc
myfunc # I want this to turn into a function call
</code></pre>
<p>Then you could instead do this:</p>
<pre><code>impo... | 0 | 2009-01-30T00:30:34Z | [
"python"
] |
Is there a way to make a user-defined Python function act like a built-in statement? | 489,524 | <p>Is it possible to make a user-defined Python function act like a statement? In other words, I'd like to be able to say:</p>
<pre><code>myfunc
</code></pre>
<p>rather than:</p>
<pre><code>myfunc()
</code></pre>
<p>and have it get called anyway -- the way that, say, <code>print</code> would.</p>
<p>I can already ... | 1 | 2009-01-28T21:43:58Z | 7,842,942 | <p>Not possible in a planned way, or without a lot of work.</p>
<p>If you are bold and adventurous, read this wikipedia article about meta circular evaluation. Python has pretty good inspection and reflection on its own compiler/evaluater objects, you may be able to cobble something together along these lines.</p>
<b... | 1 | 2011-10-20T22:18:54Z | [
"python"
] |
Connecting to MySQL with Python 2.6...how? | 489,807 | <p>All my searches, including <a href="http://stackoverflow.com/questions/372885/how-to-connect-to-a-mysql-database-from-python">this question</a> on Stack, point me to MySQLdb. Unfortunately MySQLdb doesn't have a version for Python 2.6.</p>
<p>What am I to do?</p>
| 1 | 2009-01-28T22:57:04Z | 489,825 | <p>Have you tried compiling it for Python 2.6? The APIs change very little in minor releases, so it's likely to Just Work (TM).</p>
<p>Edit: According to <a href="http://mail.python.org/pipermail/python-list/2008-November/516315.html" rel="nofollow">this post</a>, it does work and the poster mentions that Windows bi... | 2 | 2009-01-28T23:01:13Z | [
"python",
"mysql"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 489,924 | <p>Locking a file is usually a platform-specific operation, so you may need to allow for the possibility of running on different operating systems. For example:</p>
<pre><code>import os
def my_lock(f):
if os.name == "posix":
# Unix or OS X specific locking here
elif os.name == "nt":
# Windows ... | 5 | 2009-01-28T23:45:51Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 490,032 | <p>Coordinating access to a single file at the OS level is fraught with all kinds of issues that you probably don't want to solve.</p>
<p>Your best bet is have a separate process that coordinates read/write access to that file.</p>
| 9 | 2009-01-29T00:24:06Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 490,102 | <p>There is a cross-platform file locking module here: <a href="https://pypi.python.org/pypi/portalocker" rel="nofollow">Portalocker</a></p>
<p>Although as Kevin says, writing to a file from multiple processes at once is something you want to avoid if at all possible.</p>
<p>If you can shoehorn your problem into a da... | 25 | 2009-01-29T01:01:50Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 490,919 | <p>Locking is platform and device specific, but generally, you have a few options:</p>
<ol>
<li>use flock(), or equivilent (if your os supports it). This is advisory locking, unless you check for the lock, its ignored.</li>
<li>Use a lock-copy-move-unlock methodology, where you copy the file, write the new data, then... | 7 | 2009-01-29T08:46:38Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 498,505 | <p>Alright, so I ended up going with the code I wrote <a href="http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/">here, on my website</a> (<a href="https://github.com/dmfrey/FileLock">also available on GitHub</a>). I can use it in the following fashion:</p>
<pre><code>from filelock impo... | 65 | 2009-01-31T08:30:04Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 2,872,043 | <p>Kernel-level file locking is an extremly complex subject, since different types of locks have very different semantic, and the main lock of unix systems (fcntl) has horrible flaws.</p>
<p>But I've just released a python library which deals with the issue in a very portable way. It can achieve shared/exclusive file ... | 0 | 2010-05-20T08:20:23Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 3,343,885 | <p>I prefer <strong><a href="https://github.com/smontanaro/pylockfile">lockfile</a></strong> â Platform-independent file locking</p>
| 15 | 2010-07-27T13:04:47Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 18,317,453 | <p>I found a simple and worked(!) <a href="https://github.com/bmc/grizzled-python/blob/master/grizzled/io/filelock.py" rel="nofollow">implementation</a> from grizzled-python.</p>
<p>Simple use os.open(..., O_EXCL) + os.close() didn't work on windows.</p>
| 1 | 2013-08-19T15:22:58Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 25,172,660 | <p>I have been working on a situation like this where I run multiple copies of the same program from within the same directory/folder and logging errors. My approach was to write a "lock file" to the disc before opening the log file. The program checks for the presence of the "lock file" before proceeding, and waits i... | 0 | 2014-08-07T01:01:51Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 34,124,007 | <p>I have been looking at several solutions to do that and my choice has been
<a href="http://docs.openstack.org/developer/oslo.concurrency/" rel="nofollow">oslo.concurrency</a></p>
<p>It's powerful and relatively well documented. It's based on fasterners.</p>
<p>Other solutions:</p>
<ul>
<li><a href="https://pypi.p... | 2 | 2015-12-06T23:09:02Z | [
"python",
"file-locking"
] |
Locking a file in Python | 489,861 | <p>I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.</p>
| 81 | 2009-01-28T23:20:03Z | 39,708,102 | <p>you may find <a href="https://bachiraoun.github.io/pylocker/" rel="nofollow">pyloker</a> very useful. It can be used to lock a file or for locking mechanisms in general and can be accessed from multiple Python processes at once. </p>
<p>If you want simply to lock a file here's how it works </p>
<pre><code>import u... | 0 | 2016-09-26T16:41:45Z | [
"python",
"file-locking"
] |
How can I extract x, y and z coordinates from geographical data by Python? | 489,901 | <p>I have geographical data which has 14 variables. The data is in the following format:</p>
<blockquote>
<p>QUADNAME: rockport_colony_SD RESOLUTION: 10 ULLAT: 43.625<br />
ULLON: -97.87527466 LRLAT: 43.5<br />
LRLON: -97.75027466 HDATUM: 27<br />
ZMIN: 361.58401489 ZMAX:
413.3840026... | 0 | 2009-01-28T23:36:31Z | 490,065 | <p>Given a <a href="http://docs.python.org/library/codecs.html#streamreader-objects" rel="nofollow">StreamReader</a> named reader, this should give you a list of (float, float, float). I suggest a list of 3-tuples because it'll probably be more convenient and more efficient to walk through, unless for some reason you ... | 2 | 2009-01-29T00:40:57Z | [
"python",
"extraction",
"geography"
] |
How can I extract x, y and z coordinates from geographical data by Python? | 489,901 | <p>I have geographical data which has 14 variables. The data is in the following format:</p>
<blockquote>
<p>QUADNAME: rockport_colony_SD RESOLUTION: 10 ULLAT: 43.625<br />
ULLON: -97.87527466 LRLAT: 43.5<br />
LRLON: -97.75027466 HDATUM: 27<br />
ZMIN: 361.58401489 ZMAX:
413.3840026... | 0 | 2009-01-28T23:36:31Z | 490,347 | <p>Something like this might work if the data is all in a big flat text file:</p>
<pre><code>import re
data = """
QUADNAME: rockport_colony_SD RESOLUTION: 10 ULLAT: 43.625
ULLON: -97.87527466 LRLAT: 43.5
LRLON: -97.75027466 HDATUM: 27
ZMIN: 361.58401489 ZMAX: 413.38400269 ZMEAN: 396.1293335 ZSIGMA: 12.36359215 PMETHO... | 4 | 2009-01-29T02:55:42Z | [
"python",
"extraction",
"geography"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,020 | <pre><code># Over-explaining a bit:
def magic(numList): # [1,2,3]
s = map(str, numList) # ['1','2','3']
s = ''.join(s) # '123'
s = int(s) # 123
return s
# How I'd probably write it:
def magic(numList):
s = ''.join(map(str, numList))
return int(s)
# As a one-li... | 92 | 2009-01-29T00:21:26Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,024 | <p>pseudo-code:</p>
<pre>int magic(list nums)
{
int tot = 0
while (!nums.isEmpty())
{
int digit = nums.takeFirst()
tot *= 10
tot += digit
}
return tot
}</pre>
| 3 | 2009-01-29T00:22:17Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,029 | <pre><code>def magic(numbers):
return int(''.join([ "%d"%x for x in numbers]))
</code></pre>
| 5 | 2009-01-29T00:23:31Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,031 | <p>Two solutions:</p>
<pre><code>>>> nums = [1, 2, 3]
>>> magic = lambda nums: int(''.join(str(i) for i in nums)) # Generator exp.
>>> magic(nums)
123
>>> magic = lambda nums: sum(digit * 10 ** (len(nums) - 1 - i) # Summation
... for i, digit in enumerate(nums))
>>> mag... | 31 | 2009-01-29T00:23:42Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,250 | <pre><code>def magic(number):
return int(''.join(str(i) for i in number))
</code></pre>
| 5 | 2009-01-29T02:04:01Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,312 | <p>This seems pretty clean, to me.</p>
<pre><code>def magic( aList, base=10 ):
n= 0
for d in aList:
n = base*n + d
return n
</code></pre>
| 3 | 2009-01-29T02:34:59Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,392 | <p>This method works in 2.x as long as each element in the list is only a single digit. But you shouldn't actually use this. It's horrible.</p>
<pre><code>>>> magic = lambda l:int(`l`[1::3])
>>> magic([3,1,3,3,7])
31337
</code></pre>
| 2 | 2009-01-29T03:31:57Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 490,400 | <p>Using a generator expression:</p>
<pre><code>def magic(numbers):
digits = ''.join(str(n) for n in numbers)
return int(digits)
</code></pre>
| 2 | 2009-01-29T03:37:16Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 493,944 | <p>Just for completeness, here's a variant that uses <code>print()</code> (works on Python 2.6-3.x):</p>
<pre><code>from __future__ import print_function
try: from cStringIO import StringIO
except ImportError:
from io import StringIO
def to_int(nums, _s = StringIO()):
print(*nums, sep='', end='', file=_s)
... | 3 | 2009-01-29T23:26:56Z | [
"python"
] |
Convert list of ints to one number? | 489,999 | <p>I have a list of integers that I would like to convert to one number like:</p>
<pre><code>numList = [1, 2, 3]
num = magic(numList)
print num, type(num)
>>> 123, <type 'int'>
</code></pre>
<p>What is the best way to implement the <em>magic</em> function?</p>
<p><strong>EDIT</strong> <br>
I did find... | 29 | 2009-01-29T00:16:23Z | 37,451,273 | <p>A one-liner without needing to cast to and from <code>str</code></p>
<pre><code>def magic(num):
return sum(e * 10**i for i, e in enumerate(num[::-1]))
</code></pre>
| 0 | 2016-05-26T03:52:47Z | [
"python"
] |
QScintilla scrollbar | 490,130 | <p>When I add a QsciScintilla object to my main window the horizontal scrollbar is active and super wide (tons of apparent white space). Easy fix?</p>
| 1 | 2009-01-29T01:10:18Z | 490,198 | <p>Easy fix:</p>
<pre><code>sc.SendScintilla(sc.SCI_SETHSCROLLBAR, 0)
</code></pre>
| 1 | 2009-01-29T01:36:37Z | [
"python",
"qt",
"scintilla"
] |
split a multi-page pdf file into multiple pdf files with python? | 490,195 | <p>I'd like to take a multi-page pdf file and create separate pdf files per page.</p>
<p>I've downloaded <a href="http://www.reportlab.org/index.html">reportlab</a> and have browsed the documentation, but it seems aimed at pdf generation, I haven't yet seen anything about processing pdf's themselves.</p>
<p>Is there ... | 20 | 2009-01-29T01:35:48Z | 490,203 | <p>pyPdf can handle this nicely (c.f. <a href="http://pybrary.net/pyPdf/">http://pybrary.net/pyPdf/</a> )</p>
<pre>
from pyPdf import PdfFileWriter, PdfFileReader
inputpdf = PdfFileReader(open("document.pdf", "rb"))
for i in xrange(inputpdf.numPages):
output = PdfFileWriter()
output.addPage(inputpdf.getPage(... | 46 | 2009-01-29T01:38:47Z | [
"python",
"pdf"
] |
split a multi-page pdf file into multiple pdf files with python? | 490,195 | <p>I'd like to take a multi-page pdf file and create separate pdf files per page.</p>
<p>I've downloaded <a href="http://www.reportlab.org/index.html">reportlab</a> and have browsed the documentation, but it seems aimed at pdf generation, I haven't yet seen anything about processing pdf's themselves.</p>
<p>Is there ... | 20 | 2009-01-29T01:35:48Z | 35,910,519 | <p>also, you can use PDFSplitterX at <a href="https://www.coolutils.com/PDFSplitterXPython" rel="nofollow">https://www.coolutils.com/PDFSplitterXPython</a></p>
<p>example</p>
<pre><code>import win32com.client
import os.path
c = win32com.client.Dispatch("PDFSplitter.PDFSplitterX")
src="C:\\test\\test.pdf";
dest="C:\... | 0 | 2016-03-10T07:49:15Z | [
"python",
"pdf"
] |
What is the most pythonic way to make a bound method act like a function? | 490,429 | <p>I'm using a Python API that expects me to pass it a function. However, for various reasons, I want to pass it a method, because I want the function to behave different depending on the instance it belongs to. If I pass it a method, the API will not call it with the correct 'self' argument, so I'm wondering how to t... | 3 | 2009-01-29T03:55:06Z | 490,437 | <p>Will passing in the method bound to a instance work? If so, you don't have to do anything special.</p>
<pre><code>In [2]: class C(object):
...: def method(self, a, b, c):
...: print a, b, c
...:
...:
In [3]: def api_function(a_func):
...: a_func("One Fish", "Two Fish", "Blue Fish")
... | 8 | 2009-01-29T03:58:53Z | [
"python",
"function",
"methods",
"closures"
] |
What is the most pythonic way to make a bound method act like a function? | 490,429 | <p>I'm using a Python API that expects me to pass it a function. However, for various reasons, I want to pass it a method, because I want the function to behave different depending on the instance it belongs to. If I pass it a method, the API will not call it with the correct 'self' argument, so I'm wondering how to t... | 3 | 2009-01-29T03:55:06Z | 490,465 | <p>You may want to clarify your question. As Ryan points out,</p>
<pre><code>def callback(fn):
fn('Welcome')
callback(a1.hello)
callback(a2.hello)
</code></pre>
<p>will result in <code>hello</code> being called with the correct <code>self</code> bound, <code>a1</code> or <code>a2</code>. If you are not experien... | 0 | 2009-01-29T04:19:17Z | [
"python",
"function",
"methods",
"closures"
] |
django-cart or Satchmo? | 490,439 | <p>I'm looking to implement a very basic shopping cart. <a href="http://www.satchmoproject.com/">Satchmo</a> seems to install a <strong>lot</strong> of applications and extra stuff that I don't need. I've heard others mention <a href="http://code.google.com/p/django-cart/">django-cart</a>. Has anyone tried this Djan... | 23 | 2009-01-29T04:00:49Z | 490,446 | <p>I think the reason there aren't really many out-of-the-box solutions is because most people who use Django are power users. They tend to want to roll out their own solutions, especially considering how easy it is to do in Django.</p>
<p>To answer your question, <a href="http://demo.djwarehouse.org/" rel="nofollow">... | 5 | 2009-01-29T04:04:28Z | [
"python",
"django",
"e-commerce",
"satchmo"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.