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 would I package and sell a Django app? | 164,901 | <p>Currently I am hosting a Django app I developed myself for my clients, but I am now starting to look at selling it to people for them to host themselves.</p>
<p>My question is this: How can I package up and sell a Django app, while protecting its code from pirating or theft? Distributing a bunch of .py files doesn'... | 30 | 2008-10-02T22:27:56Z | 164,959 | <p>You could package the whole thing up as an Amazon Machine Instance (AMI), and then have them run your app on <a href="http://aws.amazon.com/ec2/">Amazon EC2</a>. The nice thing about this solution is that Amazon will <a href="http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/index.html?paidamis-intro.h... | 9 | 2008-10-02T22:54:43Z | [
"python",
"django",
"distribution",
"piracy-prevention"
] |
How would I package and sell a Django app? | 164,901 | <p>Currently I am hosting a Django app I developed myself for my clients, but I am now starting to look at selling it to people for them to host themselves.</p>
<p>My question is this: How can I package up and sell a Django app, while protecting its code from pirating or theft? Distributing a bunch of .py files doesn'... | 30 | 2008-10-02T22:27:56Z | 164,987 | <p>Don't try and obfuscate or encrypt the code - it will never work.</p>
<p>I would suggest selling the Django application "as a service" - either host it for them, or sell them the code <em>and support</em>. Write up a contract that forbids them from redistributing it.</p>
<p>That said, if you were determined to obf... | 48 | 2008-10-02T23:10:21Z | [
"python",
"django",
"distribution",
"piracy-prevention"
] |
How would I package and sell a Django app? | 164,901 | <p>Currently I am hosting a Django app I developed myself for my clients, but I am now starting to look at selling it to people for them to host themselves.</p>
<p>My question is this: How can I package up and sell a Django app, while protecting its code from pirating or theft? Distributing a bunch of .py files doesn'... | 30 | 2008-10-02T22:27:56Z | 167,240 | <p>You'll never be able to keep the source code from people who really want it. It's best to come to grips with this fact now, and save yourself the headache later.</p>
| 7 | 2008-10-03T14:48:12Z | [
"python",
"django",
"distribution",
"piracy-prevention"
] |
How would I package and sell a Django app? | 164,901 | <p>Currently I am hosting a Django app I developed myself for my clients, but I am now starting to look at selling it to people for them to host themselves.</p>
<p>My question is this: How can I package up and sell a Django app, while protecting its code from pirating or theft? Distributing a bunch of .py files doesn'... | 30 | 2008-10-02T22:27:56Z | 395,813 | <p>One thing you might want to consider is what FogBugz does. Simply include a small binary (perhaps a C program) that is compiled for the target platforms and contains the code to validate the license. </p>
<p>This way you can keep the honest people honest with minimal headache on your part.</p>
| 3 | 2008-12-28T04:19:39Z | [
"python",
"django",
"distribution",
"piracy-prevention"
] |
How would I package and sell a Django app? | 164,901 | <p>Currently I am hosting a Django app I developed myself for my clients, but I am now starting to look at selling it to people for them to host themselves.</p>
<p>My question is this: How can I package up and sell a Django app, while protecting its code from pirating or theft? Distributing a bunch of .py files doesn'... | 30 | 2008-10-02T22:27:56Z | 445,887 | <p>"Encrypting" Python source code (or bytecode, or really bytecode for any language that uses it -- not just Python) is like those little JavaScript things some people put on web pages to try to disable the right-hand mouse button, declaring "now you can't steal my images!"</p>
<p>The workarounds are trivial, and wil... | 10 | 2009-01-15T07:01:38Z | [
"python",
"django",
"distribution",
"piracy-prevention"
] |
How would I package and sell a Django app? | 164,901 | <p>Currently I am hosting a Django app I developed myself for my clients, but I am now starting to look at selling it to people for them to host themselves.</p>
<p>My question is this: How can I package up and sell a Django app, while protecting its code from pirating or theft? Distributing a bunch of .py files doesn'... | 30 | 2008-10-02T22:27:56Z | 5,915,669 | <p>May I speak frankly, as a friend? Unless your app is Really Amazing, you may not get many buyers. Why waste the time on lawyers, obfuscation, licensing and whatnot? You stand to gain a better reputation by open-sourcing your code...and maintaining it.</p>
<p>Django comes from the open-source end of the spectrum fro... | 2 | 2011-05-06T18:40:40Z | [
"python",
"django",
"distribution",
"piracy-prevention"
] |
Detecting Mouse clicks in windows using python | 165,495 | <p>How can I detect mouse clicks regardless of the window the mouse is in?</p>
<p>Perferabliy in python, but if someone can explain it in any langauge I might be able to figure it out.</p>
<p>I found this on microsoft's site:
<a href="http://msdn.microsoft.com/en-us/library/ms645533(VS.85).aspx">http://msdn.microsoft... | 13 | 2008-10-03T02:51:44Z | 166,054 | <p>The windows way of doing it is to handle the <code>WM_LBUTTONDBLCLK</code> message. </p>
<p>For this to be sent, your window class needs to be created with the <code>CS_DBLCLKS</code> class style.</p>
<p>I'm afraid I don't know how to apply this in Python, but hopefully it might give you some hints.</p>
| 2 | 2008-10-03T09:13:27Z | [
"python",
"windows",
"mouse"
] |
Detecting Mouse clicks in windows using python | 165,495 | <p>How can I detect mouse clicks regardless of the window the mouse is in?</p>
<p>Perferabliy in python, but if someone can explain it in any langauge I might be able to figure it out.</p>
<p>I found this on microsoft's site:
<a href="http://msdn.microsoft.com/en-us/library/ms645533(VS.85).aspx">http://msdn.microsoft... | 13 | 2008-10-03T02:51:44Z | 166,144 | <p>Windows MFC, including GUI programming, is accessible with python using the <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">Python for Windows extensions</a> by Mark Hammond. <a href="http://www.onlamp.com/lpt/a/217" rel="nofollow">An O'Reilly Book Excerpt</a> from Hammond's and Robinson's <a href=... | 3 | 2008-10-03T09:56:35Z | [
"python",
"windows",
"mouse"
] |
Detecting Mouse clicks in windows using python | 165,495 | <p>How can I detect mouse clicks regardless of the window the mouse is in?</p>
<p>Perferabliy in python, but if someone can explain it in any langauge I might be able to figure it out.</p>
<p>I found this on microsoft's site:
<a href="http://msdn.microsoft.com/en-us/library/ms645533(VS.85).aspx">http://msdn.microsoft... | 13 | 2008-10-03T02:51:44Z | 168,996 | <p>The only way to detect mouse events outside your program is to install a Windows hook using <a href="http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx">SetWindowsHookEx</a>. The <a href="http://www.cs.unc.edu/Research/assist/developer.shtml">pyHook</a> module encapsulates the nitty-gritty details. Here's ... | 23 | 2008-10-03T21:38:15Z | [
"python",
"windows",
"mouse"
] |
Python object attributes - methodology for access | 165,883 | <p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of nami... | 22 | 2008-10-03T06:18:37Z | 165,892 | <p>I think most just access them directly, no need for get/set methods.</p>
<pre><code>>>> class myclass:
... x = 'hello'
...
>>>
>>> class_inst = myclass()
>>> class_inst.x
'hello'
>>> class_inst.x = 'world'
>>> class_inst.x
'world'
</code></pre>
<p>BTW, you ... | 3 | 2008-10-03T06:24:01Z | [
"python",
"oop",
"object",
"attributes"
] |
Python object attributes - methodology for access | 165,883 | <p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of nami... | 22 | 2008-10-03T06:18:37Z | 165,896 | <p>Python does not need to define accessors right from the beginning, since converting attributes into properties is quick and painless. See the following for a vivid demonstration:</p>
<p><a href="http://www.archive.org/details/SeanKellyRecoveryfromAddiction" rel="nofollow">Recovery from Addiction</a></p>
| 0 | 2008-10-03T06:26:39Z | [
"python",
"oop",
"object",
"attributes"
] |
Python object attributes - methodology for access | 165,883 | <p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of nami... | 22 | 2008-10-03T06:18:37Z | 165,901 | <p>Some people use getters and setters. Depending on which coding style you use you can name them getSpam and seteggs. But you can also make you attributes readonly or assign only. That's a bit awkward to do. One way is overriding the </p>
<pre><code>> __getattr__
</code></pre>
<p>and </p>
<pre><code>> __seta... | -2 | 2008-10-03T06:29:22Z | [
"python",
"oop",
"object",
"attributes"
] |
Python object attributes - methodology for access | 165,883 | <p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of nami... | 22 | 2008-10-03T06:18:37Z | 165,911 | <p>The generally accepted way of doing things is just using simple attributes, like so</p>
<pre><code>>>> class MyClass:
... myAttribute = 0
...
>>> c = MyClass()
>>> c.myAttribute
0
>>> c.myAttribute = 1
>>> c.myAttribute
1
</code></pre>
<p>If you do find yourself needing to be able to write getters and setter... | 20 | 2008-10-03T06:35:37Z | [
"python",
"oop",
"object",
"attributes"
] |
Python object attributes - methodology for access | 165,883 | <p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of nami... | 22 | 2008-10-03T06:18:37Z | 165,925 | <p>There is no real point of doing getter/setters in python, you can't protect stuff anyway and if you need to execute some extra code when getting/setting the property look at the property() builtin (python -c 'help(property)')</p>
| 0 | 2008-10-03T06:43:09Z | [
"python",
"oop",
"object",
"attributes"
] |
Python object attributes - methodology for access | 165,883 | <p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of nami... | 22 | 2008-10-03T06:18:37Z | 166,073 | <blockquote>
<p>Edit: Can you elaborate on the best-practices of naming attributes with a single or double leading underscore ? I see in most modules that a single underscore is used.</p>
</blockquote>
<p>Single underscore doesn't mean anything special to python, it is just best practice, to tell "hey you probably d... | 7 | 2008-10-03T09:23:40Z | [
"python",
"oop",
"object",
"attributes"
] |
Python object attributes - methodology for access | 165,883 | <p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of nami... | 22 | 2008-10-03T06:18:37Z | 166,098 | <p>With regards to the single and double-leading underscores: both indicate the same concept of 'privateness'. That is to say, people will know the attribute (be it a method or a 'normal' data attribute or anything else) is not part of the public API of the object. People will know that to touch it directly is to invit... | 51 | 2008-10-03T09:37:51Z | [
"python",
"oop",
"object",
"attributes"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 166,053 | <p>The Resource Kit has always included this. At least since Windows 2000.</p>
<p>Also, the cygwin package has a <code>sleep</code> - plop that into your PATH and include the <code>cygwin.dll</code> (or whatever it's called) and way to go!</p>
| 4 | 2008-10-03T09:13:05Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 166,058 | <p><code>SLEEP.exe</code> is included in most Resource Kits e.g. <a href="http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en" rel="nofollow">The Windows Server 2003 Resource Kit</a> which can be installed on Windows XP too.</p>
<pre><code>Usage: sleep ... | 14 | 2008-10-03T09:15:39Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 166,093 | <p>I faced a similar problem, but I just knocked up a very short C++ console application to do the same thing. Just run <em>MySleep.exe 1000</em> - perhaps easier than downloading/installing the whole resource kit.</p>
<pre class="lang-c prettyprint-override"><code>#include <tchar.h>
#include <stdio.h>
#in... | 14 | 2008-10-03T09:35:43Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 166,187 | <p>The usage of <a href="http://en.wikipedia.org/wiki/Ping_%28networking_utility%29" rel="nofollow">ping</a> is good, as long as you just want to "wait for a bit". This since you are dependent on other functions underneath, like your network working and the fact that there is nothing answering on 127.0.0.1. ;-) Maybe ... | 3 | 2008-10-03T10:08:15Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 166,290 | <p>If you have Python installed, or don't mind installing it (it has other uses too :), just create the following <strong>sleep.py</strong> script and add it somewhere in your PATH:</p>
<pre class="lang-py prettyprint-override"><code>import time, sys
time.sleep(float(sys.argv[1]))
</code></pre>
<p>It will allow sub-... | 16 | 2008-10-03T10:42:19Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 1,092,731 | <p>I have been using this C# sleep program. It might be more convenient for you if C# is your preferred language:</p>
<pre class="lang-cs prettyprint-override"><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace sleep
{
class Program
{
... | 3 | 2009-07-07T14:39:09Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 1,202,058 | <p>Even more lightweight than the Python solution is a Perl
one-liner. </p>
<p>To sleep for 7 seconds put this in the BAT script:</p>
<pre><code>perl -e "sleep 7"
</code></pre>
<p>This solution only provides a resolution of 1 second. </p>
<p>If you need higher resolution then use the Time::HiRes
module from CPAN. ... | 2 | 2009-07-29T18:12:24Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 1,304,768 | <p>You can use ping:</p>
<pre><code>ping 127.0.0.1 -n 11 -w 1000 >nul: 2>nul:
</code></pre>
<p>will wait 10 seconds.</p>
<p>The reason you have to use 11 is because the first ping goes out immediately, not after one second. The number should always be one more than the number of seconds you want to wait.</p>
... | 7 | 2009-08-20T08:28:55Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 1,811,248 | <p>Over at Server Fault, <a href="http://serverfault.com/questions/38318/better-way-to-wait-a-few-seconds-in-a-bat-file">a similar question was asked</a>, the solution there was:</p>
<pre><code>choice /d y /t 5 > nul
</code></pre>
| 10 | 2009-11-28T01:29:47Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 1,811,314 | <p>You could use the Windows <em>cscript WSH</em> layer and this <em>wait.js</em> JavaScript file:</p>
<pre><code>if (WScript.Arguments.Count() == 1)
WScript.Sleep(WScript.Arguments(0)*1000);
else
WScript.Echo("Usage: cscript wait.js seconds");
</code></pre>
| 9 | 2009-11-28T02:00:40Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 5,437,271 | <p>Just put this in your batch file where you want the wait.</p>
<pre><code>@ping 127.0.0.1 -n 11 -w 1000 > null
</code></pre>
| 5 | 2011-03-25T19:35:09Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 5,438,142 | <p>Depending on your compatibility needs, either use <code>ping</code>:</p>
<pre><code>ping -n <numberofseconds+1> localhost >nul 2>&1
</code></pre>
<p>e.g. to wait 5 seconds, use </p>
<pre><code>ping -n 6 localhost >nul 2>&1
</code></pre>
<p>or on Windows 7 or later use <code>timeout</cod... | 8 | 2011-03-25T21:04:54Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 5,483,958 | <p>The <a href="http://technet.microsoft.com/en-us/library/cc754891.aspx"><code>timeout</code></a> command is available from Vista onwards.</p>
<pre><code>c:\> timeout /?
TIMEOUT [/T] timeout [/NOBREAK]
Description:
This utility accepts a timeout parameter to wait for the specified
time period (in seconds... | 189 | 2011-03-30T08:38:43Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 5,822,491 | <p>Impressed with this one:</p>
<p><a href="http://www.computerhope.com/batch.htm#02" rel="nofollow">http://www.computerhope.com/batch.htm#02</a></p>
<pre><code>choice /n /c y /d y /t 5 >NUL
</code></pre>
<p>Technically you're telling the choice command to accept only y, default to y, to do so in 5 seconds, to dr... | 1 | 2011-04-28T17:15:08Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 6,806,192 | <p>I disagree with the answers I found here.</p>
<p>I use the following method entirely based on Windows XP capabilities to do a delay in a batch file:</p>
<p>DELAY.BAT:</p>
<pre><code>@ECHO OFF
REM DELAY seconds
REM GET ENDING SECOND
FOR /F "TOKENS=1-3 DELIMS=:." %%A IN ("%TIME%") DO SET /A H=%%A, M=1%%B%%100... | 15 | 2011-07-24T10:10:43Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 6,852,798 | <p>Using the <code>ping</code> method as outlined is how I do it when I can't (or don't want to) add more executables or install any other software.</p>
<p>You should be pinging something that isn't there, and using the <code>-w</code> flag so that it fails after that amount of time, not pinging something that <em>is<... | 21 | 2011-07-28T00:20:12Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 8,775,655 | <p>Or command line Python, for example, for 6 and a half seconds:</p>
<pre><code>python -c "import time;time.sleep(6.5)"
</code></pre>
| 1 | 2012-01-08T05:39:12Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 14,404,448 | <p>In Notepad, write:</p>
<pre><code>@echo off
set /a WAITTIME=%1+1
PING 127.0.0.1 -n %WAITTIME% > nul
goto:eof
</code></pre>
<p>Now save as wait.bat in the folder C:\WINDOWS\System32,
then whenever you want to wait, use:</p>
<pre><code>CALL WAIT.bat <whole number of seconds without quotes>
</code></pre>
| 4 | 2013-01-18T17:35:21Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 14,574,706 | <p>I like <a href="http://stackoverflow.com/a/6806192/2020158">Aacini's response</a>. I added to it to handle the day and also enable it to handle <a href="http://en.wikipedia.org/wiki/Centisecond" rel="nofollow" title="Centisecond">centiseconds</a> (<code>%TIME%</code> outputs <code>H:MM:SS.CC</code>):</p>
<pre><cod... | 3 | 2013-01-29T02:30:37Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 16,803,440 | <p>If you've got <a href="http://en.wikipedia.org/wiki/Windows_PowerShell" rel="nofollow">PowerShell</a> on your system, you can just execute this command:</p>
<pre><code>powershell -command "Start-Sleep -s 1"
</code></pre>
<hr>
<p>Edit: from <a href="http://stackoverflow.com/a/16803409/114200">my answer on a simila... | 4 | 2013-05-29T00:03:40Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 18,644,875 | <p>You can get fancy by putting the PAUSE message in the title bar:</p>
<pre><code>@ECHO off
SET TITLETEXT=Sleep
TITLE %TITLETEXT%
CALL :sleep 5
GOTO :END
:: Function Section
:sleep ARG
ECHO Pausing...
FOR /l %%a in (%~1,-1,1) DO (TITLE Script %TITLETEXT% -- time left^
%%as&PING.exe -n 2 -w 1000 127.1>NUL)
EXI... | 0 | 2013-09-05T19:58:32Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 20,994,851 | <p>From Vista on you have <a href="http://ss64.com/nt/timeout.html" rel="nofollow">TIMEOUT</a> and <a href="http://ss64.com/nt/sleep.html" rel="nofollow">SLEEP</a> commands , but to use them in XP or Win2003 you'll need <a href="http://www.microsoft.com/en-us/download/details.aspx?id=17657" rel="nofollow">Win2003 resou... | 1 | 2014-01-08T11:50:43Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 21,252,806 | <p>You can also use a .vbs file to do specific timeouts:</p>
<p>The code below creates the .vbs file, put this near the top of you rbatch code:</p>
<pre><code>echo WScript.sleep WScript.Arguments(0) >"%cd%\sleeper.vbs"
</code></pre>
<p><br />
The Code Below Then opens the .vbs and specifies how long to wait for:<... | 1 | 2014-01-21T08:28:47Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 21,433,296 | <p>Tested on XP SP3 and Win7, uses cscript. I put some safe guards to avoid del "" prompting. (/q would be dangerous)</p>
<p>wait 1 s: </p>
<blockquote>
<p>sleepOrDelayExecution 1000 </p>
</blockquote>
<p>wait 500 ms and then run stuff after:</p>
<blockquote>
<p>sleepOrDelayExecution 500 dir \ /s</p>
</blockqu... | 0 | 2014-01-29T14:01:10Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 21,586,700 | <p>Guys from my point of view this discussion is going a bit out of topic...
the best solution that should work on all windows versions after 2000 would be:</p>
<pre><code>timeout numbersofseconds /nobreak > nul
</code></pre>
| 2 | 2014-02-05T19:30:27Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 21,941,058 | <p>There is a better way to sleep using ping. You'll want to ping an address that does not exist, so you can specify a timeout with millisecond precision. Luckily, such an address is defined in a standard (RFC 3330), and it is <code>192.0.2.x</code>. This is not made-up, it really is an address with the sole purpose of... | 2 | 2014-02-21T17:24:23Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 24,022,832 | <p>Just use</p>
<blockquote>
<p>timeout /t </p>
</blockquote>
<p>For example, I mostly use it as</p>
<blockquote>
<p>timeout /t 2 /nobreak >NUL</p>
</blockquote>
<p>Which means the script will wait 2 seconds before continuing.
By default, a keystroke will put the timeout to 0 instantly, so put '/nobreak' after... | 4 | 2014-06-03T18:55:46Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 24,990,713 | <pre><code>ping -n X 127.0.0.1>nul
</code></pre>
<p>replace X with the number of seconds +1</p>
<p>example, if u were to wait 10 seconds, replace X with 11
wait 5 seconds, use 6</p>
<p>read earlier answers for miliseconds</p>
| -2 | 2014-07-28T07:51:43Z | [
"python",
"batch-file"
] |
Sleeping in a batch file | 166,044 | <p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of ... | 129 | 2008-10-03T09:10:29Z | 28,957,671 | <p>If you are on guest account, ping will not work from what I experienced. Use the following instead:</p>
<pre><code>timeout /t 5 /nobreak>nul
</code></pre>
<p>This will wait 5 seconds. To allow it to skip from pressing any key, remove /nobreak.</p>
| -3 | 2015-03-10T06:48:22Z | [
"python",
"batch-file"
] |
How can I capture all exceptions from a wxPython application? | 166,198 | <p>I'm writing a little debug app for a bit of kit we're developing and I'd like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way of effectively wrapping a wxPython app to catch any and all unhandled exceptions that would cause the app to crash?</p>
<p>Ideally I'd want to ca... | 6 | 2008-10-03T10:11:16Z | 166,213 | <p>There are various ways. You can put a try..catch block in the wxApplication::OnInit, however, that would not always work with Gtk. </p>
<p>A nice alternative would be to override the Application::HandleEvent in your wxApplication derived class, and write a code like this:</p>
<pre><code>void Application::HandleEve... | 1 | 2008-10-03T10:17:48Z | [
"python",
"exception",
"error-handling",
"wxwidgets",
"error-reporting"
] |
How can I capture all exceptions from a wxPython application? | 166,198 | <p>I'm writing a little debug app for a bit of kit we're developing and I'd like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way of effectively wrapping a wxPython app to catch any and all unhandled exceptions that would cause the app to crash?</p>
<p>Ideally I'd want to ca... | 6 | 2008-10-03T10:11:16Z | 166,246 | <p>For logging standard output, you can use a stdout wrapper, such as this one:</p>
<pre><code>from __future__ import with_statement
class OutWrapper(object):
def __init__(self, realOutput, logFileName):
self._realOutput = realOutput
self._logFileName = logFileName
def _log(self, text):
... | 6 | 2008-10-03T10:30:07Z | [
"python",
"exception",
"error-handling",
"wxwidgets",
"error-reporting"
] |
How can I capture all exceptions from a wxPython application? | 166,198 | <p>I'm writing a little debug app for a bit of kit we're developing and I'd like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way of effectively wrapping a wxPython app to catch any and all unhandled exceptions that would cause the app to crash?</p>
<p>Ideally I'd want to ca... | 6 | 2008-10-03T10:11:16Z | 190,233 | <p>For the exception handling, assuming your log file is opened as log:</p>
<pre><code>import sys
import traceback
def excepthook(type, value, tb):
message = 'Uncaught exception:\n'
message += ''.join(traceback.format_exception(type, value, tb))
log.write(message)
sys.excepthook = excepthook
</code></pre... | 9 | 2008-10-10T05:30:47Z | [
"python",
"exception",
"error-handling",
"wxwidgets",
"error-reporting"
] |
How can I capture all exceptions from a wxPython application? | 166,198 | <p>I'm writing a little debug app for a bit of kit we're developing and I'd like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way of effectively wrapping a wxPython app to catch any and all unhandled exceptions that would cause the app to crash?</p>
<p>Ideally I'd want to ca... | 6 | 2008-10-03T10:11:16Z | 372,826 | <p>You can use</p>
<blockquote>
<p>sys.excepthook</p>
</blockquote>
<p>(see <a href="http://docs.python.org/library/sys.html#sys.excepthook" rel="nofollow">Python docs</a>)</p>
<p>and assign some custom object to it, that would catch all exceptions not caught earlier in your code. You can then log any message to a... | 3 | 2008-12-16T21:33:00Z | [
"python",
"exception",
"error-handling",
"wxwidgets",
"error-reporting"
] |
How to build and deploy Python web applications | 166,334 | <p>I have a Python web application consisting of several Python packages. What is the best way of building and deploying this to the servers?</p>
<p>Currently I'm deploying the packages with Capistrano, installing the packages into a virtualenv with bash, and configuring the servers with puppet, but I would like to go... | 17 | 2008-10-03T10:57:44Z | 166,788 | <p>Would SCons do what you want?</p>
<p><a href="http://www.scons.org/" rel="nofollow">http://www.scons.org/</a></p>
| 0 | 2008-10-03T13:17:07Z | [
"python",
"deployment"
] |
How to build and deploy Python web applications | 166,334 | <p>I have a Python web application consisting of several Python packages. What is the best way of building and deploying this to the servers?</p>
<p>Currently I'm deploying the packages with Capistrano, installing the packages into a virtualenv with bash, and configuring the servers with puppet, but I would like to go... | 17 | 2008-10-03T10:57:44Z | 171,395 | <p><a href="http://pypi.python.org/pypi/pyinstall" rel="nofollow">pyinstall</a> looks like it should be a simpler solution for you. At least as far as packaging the python stuff and installing in virtualenv goes. I don't know of a pythonic way to do server configuration...</p>
| 0 | 2008-10-05T02:51:42Z | [
"python",
"deployment"
] |
How to build and deploy Python web applications | 166,334 | <p>I have a Python web application consisting of several Python packages. What is the best way of building and deploying this to the servers?</p>
<p>Currently I'm deploying the packages with Capistrano, installing the packages into a virtualenv with bash, and configuring the servers with puppet, but I would like to go... | 17 | 2008-10-03T10:57:44Z | 171,396 | <p><a href="http://www.blueskyonmars.com/projects/paver/" rel="nofollow">Paver</a> is a rake/make work alike for python. I don't know if this is what your looking for, still haven't found anything equivalent to puppet for python...</p>
| 1 | 2008-10-05T02:52:37Z | [
"python",
"deployment"
] |
How to build and deploy Python web applications | 166,334 | <p>I have a Python web application consisting of several Python packages. What is the best way of building and deploying this to the servers?</p>
<p>Currently I'm deploying the packages with Capistrano, installing the packages into a virtualenv with bash, and configuring the servers with puppet, but I would like to go... | 17 | 2008-10-03T10:57:44Z | 171,470 | <p>I use Mercurial as my SCM system, and also for deployment too. It's just a matter of cloning the repository from another one, and then a pull/update or a fetch will get it up to date.</p>
<p>I use several instances of the repository - one on the development server, one (or more, depending upon circumstance) on my ... | 0 | 2008-10-05T04:08:58Z | [
"python",
"deployment"
] |
How to build and deploy Python web applications | 166,334 | <p>I have a Python web application consisting of several Python packages. What is the best way of building and deploying this to the servers?</p>
<p>Currently I'm deploying the packages with Capistrano, installing the packages into a virtualenv with bash, and configuring the servers with puppet, but I would like to go... | 17 | 2008-10-03T10:57:44Z | 2,779,942 | <p>Depends on what Your infrastructure is. We're just using debian packages and buildbot to make them.</p>
<p>On other setups, I use <a href="http://docs.fabfile.org/" rel="nofollow">Fabric</a> scripts. As for format, I'm just using tbz2 files, but I've heard about people just depoloying eggs.</p>
<p>I'd strongly rec... | 2 | 2010-05-06T09:25:44Z | [
"python",
"deployment"
] |
Django, mod_python, apache and wacky sessions | 166,364 | <p>I am running a Django through mod_python on Apache on a linux box. I have a custom authentication backend, and middleware that requires authentication for all pages, except static content.</p>
<p>My problem is that after I log in, I will still randomly get the log in screen now and again. It seems to me that each a... | 1 | 2008-10-03T11:10:04Z | 166,509 | <p>Do you have standard database-driven sessions? Is caching enabled in settings?</p>
| 0 | 2008-10-03T12:04:32Z | [
"python",
"django",
"apache",
"session",
"mod-python"
] |
Django, mod_python, apache and wacky sessions | 166,364 | <p>I am running a Django through mod_python on Apache on a linux box. I have a custom authentication backend, and middleware that requires authentication for all pages, except static content.</p>
<p>My problem is that after I log in, I will still randomly get the log in screen now and again. It seems to me that each a... | 1 | 2008-10-03T11:10:04Z | 166,539 | <p>You are correct about how Apache handles the processes, and sometimes you'll get served by a different process. You can see this when you make a change to your site; new processes will pick up the change, but old processes will give you the old site. To get consistency, you have to restart Apache.</p>
<p>Assuming... | 2 | 2008-10-03T12:15:14Z | [
"python",
"django",
"apache",
"session",
"mod-python"
] |
Django, mod_python, apache and wacky sessions | 166,364 | <p>I am running a Django through mod_python on Apache on a linux box. I have a custom authentication backend, and middleware that requires authentication for all pages, except static content.</p>
<p>My problem is that after I log in, I will still randomly get the log in screen now and again. It seems to me that each a... | 1 | 2008-10-03T11:10:04Z | 171,460 | <p>I highly recommend you don't set MaxRequestsPerChild to 1, as that would cause so much overhead as each process gets killed off and respawns with every request.</p>
<p>Are you using apaches preform MPM or worker MPM? </p>
<p>Take a look at <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/?... | 0 | 2008-10-05T04:00:50Z | [
"python",
"django",
"apache",
"session",
"mod-python"
] |
Django, mod_python, apache and wacky sessions | 166,364 | <p>I am running a Django through mod_python on Apache on a linux box. I have a custom authentication backend, and middleware that requires authentication for all pages, except static content.</p>
<p>My problem is that after I log in, I will still randomly get the log in screen now and again. It seems to me that each a... | 1 | 2008-10-03T11:10:04Z | 699,045 | <p>If you are using some global variables to hold data of your custom authentication session, you need to change this to use either file, database or memcached. As stated above mod_python launches few processes and there's no shared memory between them.</p>
<p>I recommend using memcached for this, also use cookies to ... | 0 | 2009-03-30T21:12:26Z | [
"python",
"django",
"apache",
"session",
"mod-python"
] |
Django, mod_python, apache and wacky sessions | 166,364 | <p>I am running a Django through mod_python on Apache on a linux box. I have a custom authentication backend, and middleware that requires authentication for all pages, except static content.</p>
<p>My problem is that after I log in, I will still randomly get the log in screen now and again. It seems to me that each a... | 1 | 2008-10-03T11:10:04Z | 14,830,843 | <p>How to ensure that session is not cleared after Apache restart( or stop and start) ?</p>
<p>Because when I upgrade my source code and restart Apache, I refresh the web page and there I have to login again. Session is lost. </p>
<p>Session is stored in Memcache. No idea how and why its cleared. How to preserve the ... | 0 | 2013-02-12T10:53:25Z | [
"python",
"django",
"apache",
"session",
"mod-python"
] |
Clearing a list | 166,431 | <p>I find it annoying that I can't clear a list. In this example:</p>
<pre><code>a = []
a.append(1)
a.append(2)
a = []
</code></pre>
<p>The second time I initialize a to a blank list, it creates a new instance of a list, which is in a different place in memory, so I can't use it to reference the first, not to mentio... | 7 | 2008-10-03T11:37:23Z | 166,441 | <p>You are looking for:</p>
<pre><code>del L[:]
</code></pre>
| 26 | 2008-10-03T11:40:52Z | [
"python",
"memory-management",
"refactoring",
"list"
] |
Clearing a list | 166,431 | <p>I find it annoying that I can't clear a list. In this example:</p>
<pre><code>a = []
a.append(1)
a.append(2)
a = []
</code></pre>
<p>The second time I initialize a to a blank list, it creates a new instance of a list, which is in a different place in memory, so I can't use it to reference the first, not to mentio... | 7 | 2008-10-03T11:37:23Z | 166,462 | <p>I'm not sure why you're worried about the fact that you're referencing a new, empty list in memory instead of the same "pointer".</p>
<p>Your other list is going to be collected sooner or later and one of the big perks about working in a high level, garbage-collected language is that you don't normally need to worr... | 3 | 2008-10-03T11:45:20Z | [
"python",
"memory-management",
"refactoring",
"list"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 166,520 | <pre><code>import socket
socket.gethostbyname(socket.gethostname())
</code></pre>
<p>This won't work always (returns <code>127.0.0.1</code> on machines having the hostname in <code>/etc/hosts</code> as <code>127.0.0.1</code>), a paliative would be what gimel shows, use <code>socket.getfqdn()</code> instead. Of course ... | 222 | 2008-10-03T12:06:50Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 166,521 | <p>I'm afraid there aren't any good platform independent ways to do this other than connecting to another computer and having it send you your IP address. For example: <a href="http://www.findmyipaddress.info/locateipaddresses.html">findmyipaddress</a>. Note that this won't work if you need an IP address that's behi... | 5 | 2008-10-03T12:07:00Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 166,589 | <p>I just found this but it seems a bit hackish, however they say tried it on *nix and I did on windows and it worked.</p>
<pre><code>import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("gmail.com",80))
print(s.getsockname()[0])
s.close()
</code></pre>
<p>This assumes you have an internet ac... | 226 | 2008-10-03T12:35:13Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 166,591 | <p>You can use the <a href="http://pypi.python.org/pypi/netifaces">netifaces</a> module. Just type:</p>
<pre><code>easy_install netifaces
</code></pre>
<p>in your command shell and it will install itself on default Python installation.</p>
<p>Then you can use it like this:</p>
<pre><code>from netifaces import inter... | 62 | 2008-10-03T12:35:42Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 166,992 | <p>If you don't want to use external packages and don't want to rely on outside Internet servers, this might help. It's a code sample that I found on <a href="http://www.google.com/codesearch?hl=en&lr=&q=getMACAddrWin&sbtn=Search">Google Code Search</a> and modified to return required information:</p>
<pre... | 17 | 2008-10-03T13:54:11Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 1,267,524 | <pre class="lang-py prettyprint-override"><code>import socket
print([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1])
</code></pre>
<p>I'm using this, because one of the computers I was on had an /etc/hosts with duplicate entries and references to itself. socket.gethostb... | 100 | 2009-08-12T17:20:38Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 1,947,766 | <p>im using following module:</p>
<pre><code>#!/usr/bin/python
# module for getting the lan ip address of the computer
import os
import socket
if os.name != "nt":
import fcntl
import struct
def get_interface_ip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.in... | 21 | 2009-12-22T17:07:58Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 1,980,854 | <p>FYI I can verify that the method:</p>
<pre><code>import socket
addr = socket.gethostbyname(socket.gethostname())
</code></pre>
<p>Works in OS X (10.6,10.5), Windows XP, and on a well administered RHEL department server. It did not work on a very minimal CentOS VM that I just do some kernel hacking on. So for tha... | 5 | 2009-12-30T15:51:21Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 3,177,266 | <p>I use this on my ubuntu machines:</p>
<pre><code>import commands
commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:]
</code></pre>
| 26 | 2010-07-05T04:45:47Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 5,111,878 | <p>For a list of IP addresses on *nix systems,</p>
<pre><code>import subprocess
co = subprocess.Popen(['ifconfig'], stdout = subprocess.PIPE)
ifconfig = co.stdout.read()
ip_regex = re.compile('((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0... | 1 | 2011-02-24T23:31:49Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 6,327,620 | <p>One simple way to produce "clean" output via command line utils:</p>
<pre><code>import commands
ips = commands.getoutput("/sbin/ifconfig | grep -i \"inet\" | grep -iv \"inet6\" | " +
"awk {'print $2'} | sed -ne 's/addr\:/ /p'")
print ips
</code></pre>
<p>It will show all IPv4 addresses on ... | 8 | 2011-06-13T07:21:56Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 6,452,999 | <p>A machine can have multiple network interfaces (including the local loopback 127.0.0.1) you mentioned. As far as the OS is concerned, it's also a "real IP address". </p>
<p>If you want to track all of interfaces, have a look at the following Puthon package : <a href="http://alastairs-place.net/netifaces/" rel="nofo... | 0 | 2011-06-23T11:02:21Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 6,453,024 | <p><code>127.0.1.1</code> <em>is</em> your real IP address. More generally speaking, a computer can have any number of IP addresses. You can filter them for private networks - 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.</p>
<p>However, there is no cross-platform way to get all IP addresses. On Linux, yo... | 3 | 2011-06-23T11:04:19Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 6,453,053 | <p><strong>Socket API method</strong></p>
<pre><code>import socket
# from http://commandline.org.uk/python/how-to-find-out-ip-address-in-python/
def getNetworkIp():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('INSERT SOME TARGET WEBSITE.com', 0))
return s.getsockname()[0]
</code></pre>... | 43 | 2011-06-23T11:07:11Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 9,267,833 | <p>On Linux:</p>
<pre><code>>>> import socket, struct, fcntl
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sockfd = sock.fileno()
>>> SIOCGIFADDR = 0x8915
>>>
>>> def get_ip(iface = 'eth0'):
... ifreq = struct.pack('16sH14s', iface, socket.AF... | 33 | 2012-02-13T20:52:31Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 10,192,097 | <p>Ok so this is Windows specific, and requires the installation of the <a href="http://timgolden.me.uk/python/wmi/index.html" rel="nofollow">python WMI module</a>, but it seems much less hackish than constantly trying to call an external server. It's just another option, as there are already many good ones, but it mi... | 0 | 2012-04-17T13:21:38Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 10,325,724 | <p>I had to solve the problem "Figure out if an IP address is local or not", and my first thought was to build a list of IPs that were local and then match against it. This is what led me to this question. However, I later realized there is a more straightfoward way to do it: Try to bind on that IP and see if it works.... | 2 | 2012-04-26T00:32:06Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 10,350,424 | <p>This will work on most linux boxes:</p>
<pre><code>import socket, subprocess, re
def get_ipv4_address():
"""
Returns IP address(es) of current machine.
:return:
"""
p = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE)
ifc_resp = p.communicate()
patt = re.compile(r'inet\s*\w*\S*:\s*... | 4 | 2012-04-27T12:14:01Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 10,377,262 | <p>A slight refinement of the commands version that uses the IP command, and returns IPv4 and IPv6 addresses:</p>
<pre><code>import commands,re,socket
#A generator that returns stripped lines of output from "ip address show"
iplines=(line.strip() for line in commands.getoutput("ip address show").split('\n'))
#Turn t... | 3 | 2012-04-30T00:32:34Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 10,750,359 | <p>Another option is to ping whatismyip</p>
<p>the below script will return your public ip as a string - advantage is that they allow this
<a href="http://www.whatismyip.com/faq/automation.asp" rel="nofollow">http://www.whatismyip.com/faq/automation.asp</a></p>
<pre><code>def findIP():
headers = { 'User-Agent' :... | 0 | 2012-05-25T07:35:08Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 10,946,468 | <pre><code>import socket
socket.gethostbyname(socket.getfqdn())
</code></pre>
| 3 | 2012-06-08T09:42:20Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 10,992,813 | <p>This answer is my personal attempt to solve the problem of getting the LAN IP, since <code>socket.gethostbyname(socket.gethostname())</code> also returned 127.0.0.1. This method does not require Internet just a LAN connection. Code is for Python 3.x but could easily be converted for 2.x. Using UDP Broadcast:</p>
<p... | 3 | 2012-06-12T08:15:13Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 16,412,954 | <pre><code>import socket
[i[4][0] for i in socket.getaddrinfo(socket.gethostname(), None)]
</code></pre>
| 4 | 2013-05-07T06:54:33Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 18,542,718 | <p>Note: This is not using the standard library, but quite simple.</p>
<p>$ pip install pif</p>
<pre><code>from pif import get_public_ip
get_public_ip()
</code></pre>
| 1 | 2013-08-30T23:09:13Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 20,275,076 | <p>Well you can use the command "ip route" on GNU/Linux to know your current IP address.</p>
<p>This shows the IP given to the interface by the DHCP server running on the router/modem. Usually "192.168.1.1/24" is the IP for local network where "24" means the range of posible IP addresses given by the DHCP server withi... | 2 | 2013-11-28T21:37:56Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 20,312,936 | <p>Simple yet sweet!</p>
<pre><code>def getip():
import socket
hostname= socket.gethostname()
ip=socket.gethostbyname(hostname)
return(ip)
</code></pre>
| 0 | 2013-12-01T14:02:04Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 20,710,035 | <p>This is a variant of UnkwnTech's answer -- it provides a <code>get_local_addr()</code> function, which returns the primary LAN ip address of the host. I'm posting it because this adds a number of things: ipv6 support, error handling, ignoring localhost/linklocal addrs, and uses a TESTNET addr (rfc5737) to connect to... | 4 | 2013-12-20T18:41:48Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 23,822,431 | <p>Variation on ninjagecko's answer. This should work on any LAN that allows UDP broadcast and doesn't require access to an address on the LAN or internet.</p>
<pre><code>import socket
def getNetworkIp():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, ... | 3 | 2014-05-23T06:30:58Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 24,171,358 | <p>netifaces is available via pip and easy_install. (I know, it's not in base, but it could be worth the install.)</p>
<p>netifaces does have some oddities across platforms:</p>
<ul>
<li>The localhost/loop-back interface may not always be included (Cygwin).</li>
<li>Addresses are listed per-protocol (e.g., IPv4, IPv... | 2 | 2014-06-11T19:47:26Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 24,564,613 | <p>On Debian (tested) and I suspect most Linux's..</p>
<pre><code>import commands
RetMyIP = commands.getoutput("hostname -I")
</code></pre>
<p>On MS Windows (tested) </p>
<pre><code>import socket
socket.gethostbyname(socket.gethostname())
</code></pre>
| 7 | 2014-07-03T23:19:34Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 25,850,698 | <p>If the computer has a route to the Internet, this will <em>always</em> work to get the preferred local ip address, even if /etc/hosts is not set correctly.</p>
<pre><code>import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 0)) # connecting to a UDP address doesn't send packets... | 34 | 2014-09-15T14:43:47Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 27,788,672 | <p>A version I do not believe that has been posted yet.
I tested with python 2.7 on Ubuntu 12.04.</p>
<p>Found this solution at : <a href="http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/">http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-net... | 8 | 2015-01-05T22:03:07Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 28,950,776 | <p>This works on Linux and Windows on both Python 2 and 3. Requires a working local interface with a default route (0.0.0.0), but that's it - no routable net access necessary, doesn't try or need to be able to actually <em>get</em> anywhere else. (This combines a bunch of ideas from above with modifications to not need... | 18 | 2015-03-09T20:02:27Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 29,931,604 | <p>This isn't very Pythonic, but it works reliably on Windows.</p>
<pre><code>def getWinIP(version = 'IPv4'):
import subprocess
if version not in ['IPv4', 'IPv6']:
print 'error - protocol version must be "IPv4" or "IPv6"'
return None
ipconfig = subprocess.check_output('ipconfig')
my_ip ... | 0 | 2015-04-28T23:18:41Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 36,446,068 | <p>A Python 3.4 version utilizing the newly introduced asyncio package.</p>
<pre><code>async get_local_ip():
loop = asyncio.get_event_loop()
transport, protocol = await loop.create_datagram_endpoint(
asyncio.DatagramProtocol,
remote_addr=('8.8.8.8', 80))
result = transport.get_extra_info('s... | 1 | 2016-04-06T08:51:58Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 37,618,645 | <p>To get the ip address you can use a <em>shell command</em> directly in <strong>python</strong>:</p>
<pre><code>import socket, subprocess
hostname = socket.gethostname()
shell_cmd = "ifconfig | awk '/inet addr/{print substr($2,6)}'"
proc = subprocess.Popen([shell_cmd], stdout=subprocess.PIPE, shell=True)
(out, er... | 3 | 2016-06-03T15:48:32Z | [
"python",
"networking",
"ip-address"
] |
Finding local IP addresses using Python's stdlib | 166,506 | <p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| 290 | 2008-10-03T12:03:36Z | 38,814,772 | <p>I settled for using the service and/or API of <strong>ipfy</strong>: <a href="https://www.ipify.org" rel="nofollow">https://www.ipify.org</a>.</p>
<pre><code>#!/usr/bin/env python3
from urllib.request import urlopen
def public_ip():
data = urlopen('https://api.ipify.org').read()
return str(data, encoding=... | 0 | 2016-08-07T13:49:21Z | [
"python",
"networking",
"ip-address"
] |
Finding a public facing IP address in Python? | 166,545 | <p>How can I find the public facing IP for my net work in Python?</p>
| 14 | 2008-10-03T12:20:07Z | 166,552 | <p>This will fetch your remote IP address</p>
<pre><code>import urllib
ip = urllib.urlopen('http://automation.whatismyip.com/n09230945.asp').read()
</code></pre>
<p>If you don't want to rely on someone else, then just upload something like this PHP script:</p>
<pre><code><?php echo $_SERVER['REMOTE_ADDR']; ?>
... | 12 | 2008-10-03T12:22:07Z | [
"python",
"ip-address"
] |
Finding a public facing IP address in Python? | 166,545 | <p>How can I find the public facing IP for my net work in Python?</p>
| 14 | 2008-10-03T12:20:07Z | 166,563 | <p>whatismyip.org is better... it just tosses back the ip as plaintext with no extraneous crap.</p>
<pre><code>import urllib
ip = urllib.urlopen('http://whatismyip.org').read()
</code></pre>
<p>But yeah, it's impossible to do it easily without relying on something outside the network itself.</p>
| 8 | 2008-10-03T12:25:55Z | [
"python",
"ip-address"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.