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
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
373,743
<p>There isn't a "pure python" way to do this because some other process would have to launch python in order to run your solution. Every platform will have one or twenty different ways to launch processes and monitor their progress. On unix platforms, cron is the old standard. On Mac OS X there is also launchd, whi...
2
2008-12-17T05:45:01Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
373,747
<p>Just in case, if you are using windows, there exists a pycron. Check out <a href="http://sourceforge.net/projects/pycron/" rel="nofollow">http://sourceforge.net/projects/pycron/</a> . For linux,I will go by either cron or sched.</p>
1
2008-12-17T05:49:29Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
373,789
<p><a href="http://turbogears.com/">TurboGears</a> ships with scheduled task capability based on <a href="http://www.razorvine.net/download/kronos.py">Kronos</a></p> <p>I've never used Kronos directly, but the scheduling in TG has a decent set of features and is solid.</p>
9
2008-12-17T06:23:28Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
374,207
<p>You could just use normal Python argument passing syntax to specify your crontab. For example, suppose we define an Event class as below:</p> <pre><code>from datetime import datetime, timedelta import time # Some utility classes / functions first class AllMatch(set): """Universal set - match everything""" ...
48
2008-12-17T10:48:11Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
2,216,614
<p>I have a minor fix for the <a href="http://stackoverflow.com/a/374207/50776">CronTab class run method suggested by Brian</a>.</p> <p>The timing was out by one second leading to a one-second, hard loop at the end of each minute.</p> <pre><code>class CronTab(object): def __init__(self, *events): self.eve...
4
2010-02-07T09:59:23Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
2,946,908
<p>More or less same as above but concurrent using gevent :)</p> <pre><code>"""Gevent based crontab implementation""" from datetime import datetime, timedelta import gevent # Some utility classes / functions first def conv_to_set(obj): """Converts to set allowing single integer to be provided""" if isinstan...
9
2010-06-01T02:01:21Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
3,292,913
<p>Check out <a href="http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html">Celery</a>, they have periodic tasks like cron.</p>
17
2010-07-20T18:03:41Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
3,490,779
<p>You can also try this: <a href="http://bitbucket.org/marnold/py-cron" rel="nofollow">http://bitbucket.org/marnold/py-cron</a></p>
0
2010-08-16T05:24:08Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
4,074,157
<p><a href="http://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python/374207#374207">Brian's solution</a> is working quite well. However, as others have pointed out, there is a subtle bug in the run code. Also i found it overly complicated for the needs.</p> <p>Here is my simpler and fu...
0
2010-11-02T00:27:45Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
4,523,531
<p>I took Brian's solution, made a few changes, added the beginnings of a standard crontab file parser, and put it at <a href="https://bitbucket.org/dbenamy/devcron" rel="nofollow">https://bitbucket.org/dbenamy/devcron</a>.</p>
0
2010-12-24T00:43:18Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
5,256,822
<p>maybe this has come up only after the question was asked; I thought I just mention it for completeness sake: <a href="https://apscheduler.readthedocs.org/en/latest/">https://apscheduler.readthedocs.org/en/latest/</a></p>
28
2011-03-10T07:46:32Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
12,360,518
<p>Another trivial solution would be:</p> <pre><code>from aqcron import At from time import sleep from datetime import datetime # Event scheduling event_1 = At( second=5 ) event_2 = At( second=[0,20,40] ) while True: now = datetime.now() # Event check if now in event_1: print "event_1" if now in eve...
1
2012-09-10T22:51:04Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
13,831,944
<p><em>"... Crontab module for read and writing crontab files and accessing the system cron automatically and simply using a direct API. ..."</em></p> <p><a href="http://pypi.python.org/pypi/python-crontab">http://pypi.python.org/pypi/python-crontab</a></p> <p>and also APScheduler, a python package. Already written &...
13
2012-12-12T02:39:58Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
16,204,433
<p>You can check out PiCloud's [1] Crons [2], but do note that your jobs won't be running on your own machine. It's also a service that you'll need to pay for if you use more than 20 hours of compute time a month.</p> <p>[1] <a href="http://www.picloud.com" rel="nofollow">http://www.picloud.com</a></p> <p>[2] <a href...
0
2013-04-25T00:23:47Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
16,786,600
<p>If you're looking for something lightweight checkout <a href="https://github.com/dbader/schedule">schedule</a>:</p> <pre><code>import schedule import time def job(): print("I'm working...") schedule.every(10).minutes.do(job) schedule.every().hour.do(job) schedule.every().day.at("10:30").do(job) while 1: ...
153
2013-05-28T07:48:31Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
19,099,711
<p>Check out luigi (<a href="https://github.com/spotify/luigi" rel="nofollow">https://github.com/spotify/luigi</a>). It's written in python and has a nice web UI for monitoring tasks. It also has a dependency graph. Might be overkill for what you need but it will probably do the trick.</p>
4
2013-09-30T16:57:26Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
20,948,123
<p>I have modified the script.</p> <ol> <li><p>Easy to use:</p> <pre><code>cron = Cron() cron.add('* * * * *' , minute_task) # every minute cron.add('33 * * * *' , day_task) # every hour cron.add('34 18 * * *' , day_task) # every day cron.run() </code></pre></li> <li><p>Try to start task in the first second ...
3
2014-01-06T10:38:03Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
34,103,997
<p>Jython? </p> <p>I just searched here and found that this word has not been mentioned on this page. Real multithreading (not multi-process), Futures, ExecutorService, and all the other tools in the concurrency toolbox, etc. </p>
0
2015-12-05T10:54:03Z
[ "python", "cron" ]
How do I get a Cron like scheduler in Python?
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can...
137
2008-12-17T00:56:31Z
35,833,199
<p>None of the listed solutions even attempt to parse a complex cron schedule string. So, here is my version, using <a href="https://github.com/taichino/croniter" rel="nofollow">croniter</a>. Basic gist:</p> <pre><code>schedule = "*/5 * * * *" # Run every five minutes nextRunTime = getNextCronRunTime(schedule) while ...
1
2016-03-06T22:06:16Z
[ "python", "cron" ]
How do I get the UTC time of "midnight" for a given timezone?
373,370
<p>The best I can come up with for now is this monstrosity:</p> <pre><code>&gt;&gt;&gt; datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) date...
20
2008-12-17T01:11:07Z
373,379
<p>Setting the TZ environment variable modifies what timezone Python's date and time functions work with.</p> <pre><code>&gt;&gt;&gt; time.gmtime() (2008, 12, 17, 1, 16, 46, 2, 352, 0) &gt;&gt;&gt; time.localtime() (2008, 12, 16, 20, 16, 47, 1, 351, 0) &gt;&gt;&gt; os.environ['TZ']='Australia/Melbourne' &gt;&gt;&gt; t...
0
2008-12-17T01:17:26Z
[ "python", "datetime", "timezone", "utc", "pytz" ]
How do I get the UTC time of "midnight" for a given timezone?
373,370
<p>The best I can come up with for now is this monstrosity:</p> <pre><code>&gt;&gt;&gt; datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) date...
20
2008-12-17T01:11:07Z
373,384
<p>Each time zone has a number, eg US/Central = -6. This is defined as the offset in hours from UTC. Since 0000 is midnight, you can simply use this offset to find the time in any time zone when it is midnight UTC. To access that, I believe you can use <pre> time.timezone</pre></p> <p>According to <a href="http://docs...
0
2008-12-17T01:20:06Z
[ "python", "datetime", "timezone", "utc", "pytz" ]
How do I get the UTC time of "midnight" for a given timezone?
373,370
<p>The best I can come up with for now is this monstrosity:</p> <pre><code>&gt;&gt;&gt; datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) date...
20
2008-12-17T01:11:07Z
381,788
<p>I think you can shave off a few method calls if you do it like this:</p> <pre><code>&gt;&gt;&gt; from datetime import datetime &gt;&gt;&gt; datetime.now(pytz.timezone("Australia/Melbourne")) \ .replace(hour=0, minute=0, second=0, microsecond=0) \ .astimezone(pytz.utc) </code></pre> <p>BUTâ€...
29
2008-12-19T18:29:13Z
[ "python", "datetime", "timezone", "utc", "pytz" ]
How do I get the UTC time of "midnight" for a given timezone?
373,370
<p>The best I can come up with for now is this monstrosity:</p> <pre><code>&gt;&gt;&gt; datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) date...
20
2008-12-17T01:11:07Z
11,236,372
<p><a href="http://stackoverflow.com/a/381788/4279">@hop's answer</a> is wrong on the day of transition from Daylight Saving Time (DST) e.g., Apr 1, 2012. To fix it <a href="http://pytz.sourceforge.net/#localized-times-and-date-arithmetic"><code>tz.localize()</code></a> could be used:</p> <pre><code>tz = pytz.timezone...
20
2012-06-27T23:57:46Z
[ "python", "datetime", "timezone", "utc", "pytz" ]
Secure, sandboxable user exposed programming language / environment?
373,406
<p>Beyond offering an API for my website, I'd like to offer users the ability to write simple scripts that would run on my servers . The scripts would have access to objects owned by the user and be able to manipulate, modify, and otherwise process their data.</p> <p>I'd like to be able to limit resources taken by the...
7
2008-12-17T01:38:54Z
373,415
<p>I use Lua for this, but it's directed at a Lua capable community. So my answer would be who are your users?</p> <p>If your users are internal, like my case, and proficient with Python use Python. However if this is something for the world wide web, I'd probably choose javascript, because its the lingua franca, (eve...
2
2008-12-17T01:48:12Z
[ "javascript", "python", "sandbox" ]
split string on a number of different characters
373,459
<p>I'd like to split a string using one or more separator characters.</p> <p>E.g. "a b.c", split on " " and "." would give the list ["a", "b", "c"].</p> <p>At the moment, I can't see anything in the standard library to do this, and my own attempts are a bit clumsy. E.g.</p> <pre><code>def my_split(string, split_char...
11
2008-12-17T02:06:01Z
373,474
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.split('[ .]', 'a b.c') ['a', 'b', 'c'] </code></pre>
37
2008-12-17T02:16:43Z
[ "python", "string", "split" ]
split string on a number of different characters
373,459
<p>I'd like to split a string using one or more separator characters.</p> <p>E.g. "a b.c", split on " " and "." would give the list ["a", "b", "c"].</p> <p>At the moment, I can't see anything in the standard library to do this, and my own attempts are a bit clumsy. E.g.</p> <pre><code>def my_split(string, split_char...
11
2008-12-17T02:06:01Z
373,576
<p>This one replaces all of the separators with the first separator in the list, and then "splits" using that character.</p> <pre><code>def split(string, divs): for d in divs[1:]: string = string.replace(d, divs[0]) return string.split(divs[0]) </code></pre> <p>output:</p> <pre><code>&gt;&gt;&gt; spl...
2
2008-12-17T03:31:13Z
[ "python", "string", "split" ]
split string on a number of different characters
373,459
<p>I'd like to split a string using one or more separator characters.</p> <p>E.g. "a b.c", split on " " and "." would give the list ["a", "b", "c"].</p> <p>At the moment, I can't see anything in the standard library to do this, and my own attempts are a bit clumsy. E.g.</p> <pre><code>def my_split(string, split_char...
11
2008-12-17T02:06:01Z
1,000,600
<p>Not very fast but does the job:</p> <pre><code>def my_split(text, seps): for sep in seps: text = text.replace(sep, seps[0]) return text.split(seps[0]) </code></pre>
1
2009-06-16T10:09:29Z
[ "python", "string", "split" ]
split string on a number of different characters
373,459
<p>I'd like to split a string using one or more separator characters.</p> <p>E.g. "a b.c", split on " " and "." would give the list ["a", "b", "c"].</p> <p>At the moment, I can't see anything in the standard library to do this, and my own attempts are a bit clumsy. E.g.</p> <pre><code>def my_split(string, split_char...
11
2008-12-17T02:06:01Z
19,211,830
<p>Solution without re:</p> <pre><code>from itertools import groupby sep = ' .,' s = 'a b.c,d' print [''.join(g) for k, g in groupby(s, sep.__contains__) if not k] </code></pre> <p>An explanation is here <a href="http://stackoverflow.com/a/19211729/2468006">http://stackoverflow.com/a/19211729/2468006</a></p>
2
2013-10-06T17:41:01Z
[ "python", "string", "split" ]
Running interactive commands in Paramiko
373,639
<p>I'm trying to run an interactive command through paramiko. The cmd execution tries to prompt for a password but I do not know how to supply the password through paramiko's exec_command and the execution hangs. Is there a way to send values to the terminal if a cmd execution expects input interactively?</p> <pre><...
20
2008-12-17T04:16:02Z
373,742
<p>I'm not familiar with paramiko, but this may work: </p> <pre><code>ssh_stdin.write('input value') ssh_stdin.flush() </code></pre> <p>For information on stdin:</p> <p><a href="http://docs.python.org/library/sys.html?highlight=stdin#sys.stdin" rel="nofollow">http://docs.python.org/library/sys.html?highlight=stdin#s...
3
2008-12-17T05:44:53Z
[ "python", "ssh", "paramiko" ]
Running interactive commands in Paramiko
373,639
<p>I'm trying to run an interactive command through paramiko. The cmd execution tries to prompt for a password but I do not know how to supply the password through paramiko's exec_command and the execution hangs. Is there a way to send values to the terminal if a cmd execution expects input interactively?</p> <pre><...
20
2008-12-17T04:16:02Z
373,870
<p>The full paramiko distribution ships with a lot of good <a href="https://github.com/paramiko/paramiko/tree/master/demos">demos</a>.</p> <p>In the demos subdirectory, <code>demo.py</code> and <code>interactive.py</code> have full interactive TTY examples which would probably be overkill for your situation.</p> <p>I...
22
2008-12-17T07:12:19Z
[ "python", "ssh", "paramiko" ]
Running interactive commands in Paramiko
373,639
<p>I'm trying to run an interactive command through paramiko. The cmd execution tries to prompt for a password but I do not know how to supply the password through paramiko's exec_command and the execution hangs. Is there a way to send values to the terminal if a cmd execution expects input interactively?</p> <pre><...
20
2008-12-17T04:16:02Z
3,096,204
<p>You need Pexpect to get the best of both worlds (expect and ssh wrappers).</p>
4
2010-06-22T18:51:33Z
[ "python", "ssh", "paramiko" ]
Running interactive commands in Paramiko
373,639
<p>I'm trying to run an interactive command through paramiko. The cmd execution tries to prompt for a password but I do not know how to supply the password through paramiko's exec_command and the execution hangs. Is there a way to send values to the terminal if a cmd execution expects input interactively?</p> <pre><...
20
2008-12-17T04:16:02Z
12,431,170
<p>I had the same problem trying to make an interactive ssh session using <a href="https://github.com/bitprophet/ssh/">ssh</a>, a fork of Paramiko.</p> <p>I dug around and found this article:</p> <p><a href="http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/">http://jessenoller.com/...
5
2012-09-14T19:58:35Z
[ "python", "ssh", "paramiko" ]
Running interactive commands in Paramiko
373,639
<p>I'm trying to run an interactive command through paramiko. The cmd execution tries to prompt for a password but I do not know how to supply the password through paramiko's exec_command and the execution hangs. Is there a way to send values to the terminal if a cmd execution expects input interactively?</p> <pre><...
20
2008-12-17T04:16:02Z
37,521,010
<p>Take a look at example and do in similar way </p> <p>(sorce from <a href="http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/" rel="nofollow">http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/</a>):</p> <pre><code> ssh.connect('127.0.0.1', use...
0
2016-05-30T08:28:50Z
[ "python", "ssh", "paramiko" ]
Running interactive commands in Paramiko
373,639
<p>I'm trying to run an interactive command through paramiko. The cmd execution tries to prompt for a password but I do not know how to supply the password through paramiko's exec_command and the execution hangs. Is there a way to send values to the terminal if a cmd execution expects input interactively?</p> <pre><...
20
2008-12-17T04:16:02Z
39,741,016
<pre><code>ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(server_IP,22,username, password) stdin, stdout, stderr = ssh.exec_command('/Users/lteue/Downloads/uecontrol-CXC_173_6456-R32A01/uecontrol.sh -host localhost ') alldata = "" while not stdout.channel.exit_status_...
0
2016-09-28T07:39:47Z
[ "python", "ssh", "paramiko" ]
Convert C++ Header Files To Python
374,217
<p>I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated.</p>
7
2008-12-17T10:53:00Z
375,098
<p>From what I can tell, h2py.py isn't intended to convert anything other than #define macros. I did run across <a href="http://sourceforge.net/projects/cppheaderparser/" rel="nofollow">cppheaderparser</a>, which might be worth a look.</p>
1
2008-12-17T16:18:18Z
[ "c++", "python", "data-structures", "enums", "header" ]
Convert C++ Header Files To Python
374,217
<p>I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated.</p>
7
2008-12-17T10:53:00Z
375,101
<p>Where did you get the idea that h2py had anything to do with structs or enums?</p> <p>From the source</p> <pre><code># Read #define's and translate to Python code. # Handle #include statements. # Handle #define macros with one argument. </code></pre> <p>The words 'enum' and 'struct' never appear in the module.</p...
-1
2008-12-17T16:19:19Z
[ "c++", "python", "data-structures", "enums", "header" ]
Convert C++ Header Files To Python
374,217
<p>I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated.</p>
7
2008-12-17T10:53:00Z
375,270
<p>I don't know h2py, but you may want to look at 'ctypes' and 'ctypeslib'. ctypes is included with python 2.5+, and is targeted at creating binary compatibility with c-structs.</p> <p>If you add ctypeslib, you get a sub-tool called codegen, which has a 'h2xml.py' script, and a 'xml2py.py', the combination of which w...
11
2008-12-17T17:06:54Z
[ "c++", "python", "data-structures", "enums", "header" ]
Convert C++ Header Files To Python
374,217
<p>I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated.</p>
7
2008-12-17T10:53:00Z
848,137
<p>Just found <a href="http://code.google.com/p/pycparser/" rel="nofollow">pycparser</a>. May be useful.</p>
2
2009-05-11T13:39:54Z
[ "c++", "python", "data-structures", "enums", "header" ]
How to retrieve the parent node using cElementTree?
374,245
<p>for the xml </p> <pre><code>&lt;grandparent&gt; &lt;parent1&gt; &lt;child&gt;data1&lt;/child&gt; &lt;/parent1&gt; &lt;parent2&gt; &lt;child&gt;data2&lt;/child&gt; &lt;/parent2&gt; &lt;/grandparent&gt; </code></pre> <p>I need the list containing tuples of parent,data for each parent in xml.</p> <...
8
2008-12-17T11:11:33Z
374,565
<p>It seems you can get access to the parent from the child using version 1.3 of ElementTree (check <a href="http://effbot.org/zone/element-xpath.htm" rel="nofollow">http://effbot.org/zone/element-xpath.htm</a>), by using xpath commands like <code>child.find('../parent')</code>. But I think python ships with version 1...
4
2008-12-17T13:46:40Z
[ "python", "celementtree" ]
How to retrieve the parent node using cElementTree?
374,245
<p>for the xml </p> <pre><code>&lt;grandparent&gt; &lt;parent1&gt; &lt;child&gt;data1&lt;/child&gt; &lt;/parent1&gt; &lt;parent2&gt; &lt;child&gt;data2&lt;/child&gt; &lt;/parent2&gt; &lt;/grandparent&gt; </code></pre> <p>I need the list containing tuples of parent,data for each parent in xml.</p> <...
8
2008-12-17T11:11:33Z
12,533,735
<pre><code>parent_map = dict((c, p) for p in tree.getiterator() for c in p) parent_map[el].remove(el) </code></pre>
5
2012-09-21T15:39:38Z
[ "python", "celementtree" ]
How to retrieve the parent node using cElementTree?
374,245
<p>for the xml </p> <pre><code>&lt;grandparent&gt; &lt;parent1&gt; &lt;child&gt;data1&lt;/child&gt; &lt;/parent1&gt; &lt;parent2&gt; &lt;child&gt;data2&lt;/child&gt; &lt;/parent2&gt; &lt;/grandparent&gt; </code></pre> <p>I need the list containing tuples of parent,data for each parent in xml.</p> <...
8
2008-12-17T11:11:33Z
38,211,083
<p>This syntax seemed to work for cElementTree </p> <pre><code>ET.fromstring("&lt;c&gt;&lt;a&gt;&lt;b&gt;&lt;/b&gt;&lt;/a&gt;&lt;/c&gt;").find('.//b/..') </code></pre> <p>No going to base parent, and using double slash then single slash in path.<br> (would have posted as a comment to above thread but it seems I have...
0
2016-07-05T19:20:56Z
[ "python", "celementtree" ]
conversion of unicode string in python
374,318
<p>I need to convert unicode strings in Python to other types such as unsigned and signed int 8 bits,unsigned and signed int 16 bits,unsigned and signed int 32 bits,unsigned and signed int 64 bits,double,float,string,unsigned and signed 8 bit,unsigned and signed 16 bit, unsigned and signed 32 bit,unsigned and signed 64...
3
2008-12-17T11:52:51Z
374,335
<p>use <a href="http://docs.python.org/library/functions.html#int"><code>int()</code></a> to convert the string to an integer. Python doesn't have different fixed-width integers so you'll just get one type of thing out.</p> <p>Then use <a href="http://docs.python.org/library/struct.html"><code>struct</code></a> to pac...
10
2008-12-17T11:58:56Z
[ "python", "string", "unicode", "unsigned", "signed" ]
Where is a python real project to be used as example for the unit-test part?
374,480
<p>I'm looking for a python project to use as example to copy the design of the unit test parts.</p> <p>The project should have these features:</p> <ol> <li>its code is almost fully unit tested</li> <li>the code is distributed in many packages, there are more that one level of packages </li> <li>all the test can be r...
4
2008-12-17T13:05:08Z
374,514
<p>Maybe <a href="http://code.google.com/p/python-nose/" rel="nofollow">Nose</a> itself?</p>
4
2008-12-17T13:23:52Z
[ "python", "unit-testing" ]
Where is a python real project to be used as example for the unit-test part?
374,480
<p>I'm looking for a python project to use as example to copy the design of the unit test parts.</p> <p>The project should have these features:</p> <ol> <li>its code is almost fully unit tested</li> <li>the code is distributed in many packages, there are more that one level of packages </li> <li>all the test can be r...
4
2008-12-17T13:05:08Z
374,521
<p>Well, your specs point directly at a somewhat famous open source project, the <a href="http://svn.python.org/view/python/trunk/Lib/" rel="nofollow">Python Library</a>. Have a look at <a href="http://svn.python.org/view/python/trunk/Lib/test/regrtest.py?rev=63042&amp;view=markup" rel="nofollow">python/trunk/Lib/test/...
1
2008-12-17T13:27:04Z
[ "python", "unit-testing" ]
Where is a python real project to be used as example for the unit-test part?
374,480
<p>I'm looking for a python project to use as example to copy the design of the unit test parts.</p> <p>The project should have these features:</p> <ol> <li>its code is almost fully unit tested</li> <li>the code is distributed in many packages, there are more that one level of packages </li> <li>all the test can be r...
4
2008-12-17T13:05:08Z
374,532
<p>First, read about <a href="http://www.python.org/doc/2.5.2/lib/module-unittest.html" rel="nofollow">unittest</a>. The documentation contains examples.</p> <p>Second, since you want packages (not modules) the list is shorter. There are 15 packages in Python 2.5 distribution. Pick One At Random. Here's a subset t...
0
2008-12-17T13:33:06Z
[ "python", "unit-testing" ]
Where is a python real project to be used as example for the unit-test part?
374,480
<p>I'm looking for a python project to use as example to copy the design of the unit test parts.</p> <p>The project should have these features:</p> <ol> <li>its code is almost fully unit tested</li> <li>the code is distributed in many packages, there are more that one level of packages </li> <li>all the test can be r...
4
2008-12-17T13:05:08Z
382,862
<p><a href="http://www.djangoproject.com/" rel="nofollow">Django</a> is a clean project that has a nice range of unit testing.</p> <p><a href="http://docs.djangoproject.com/en/dev/topics/testing/#topics-testing" rel="nofollow">Have a look</a> at how they propose you test your own projects.</p> <p><a href="http://code...
4
2008-12-20T03:43:25Z
[ "python", "unit-testing" ]
Where is a python real project to be used as example for the unit-test part?
374,480
<p>I'm looking for a python project to use as example to copy the design of the unit test parts.</p> <p>The project should have these features:</p> <ol> <li>its code is almost fully unit tested</li> <li>the code is distributed in many packages, there are more that one level of packages </li> <li>all the test can be r...
4
2008-12-17T13:05:08Z
32,449,439
<p>You can check python's source. Most of it is written in python. specially the unittest modules.</p> <p>&lt;rant>python module organization and unittest in particular is a black art. It reminds me of a mix of perl (odd, undocumented workarounds for every basic thing --the unittest manual never even show how to impor...
0
2015-09-08T04:49:19Z
[ "python", "unit-testing" ]
need help-variable creation in Python
374,572
<p>I want to create variables as <code>a1</code>,<code>a2</code>,<code>a3</code>...<code>a10</code>. For that I used a for loop. As the variable in loop increments I need to create a variable as above.</p> <p>Can anyone give me an idea?</p> <p>At the time of creation I also need to be able to assign values to them.</...
-1
2008-12-17T13:47:51Z
374,579
<p>Usually, we use a list, not a bunch of individual variables.</p> <pre><code>a = 10*[0] a[0], a[1], a[2], a[9] </code></pre>
13
2008-12-17T13:50:42Z
[ "python", "variables" ]
need help-variable creation in Python
374,572
<p>I want to create variables as <code>a1</code>,<code>a2</code>,<code>a3</code>...<code>a10</code>. For that I used a for loop. As the variable in loop increments I need to create a variable as above.</p> <p>Can anyone give me an idea?</p> <p>At the time of creation I also need to be able to assign values to them.</...
-1
2008-12-17T13:47:51Z
374,604
<p>You can use the exec function:</p> <pre><code>for i in range(0,10): exec("a%d=%d" % (i,i)) </code></pre> <p>Not very pythonic way of doing things.</p>
-1
2008-12-17T13:59:16Z
[ "python", "variables" ]
need help-variable creation in Python
374,572
<p>I want to create variables as <code>a1</code>,<code>a2</code>,<code>a3</code>...<code>a10</code>. For that I used a for loop. As the variable in loop increments I need to create a variable as above.</p> <p>Can anyone give me an idea?</p> <p>At the time of creation I also need to be able to assign values to them.</...
-1
2008-12-17T13:47:51Z
374,636
<p>Following what S.Lott said, you can also use a dict, if you really nead unique names and that the order of the items is not important:</p> <pre><code>data = {} for i in range(0, 10): data['a%d' % i] = i &gt;&gt;&gt;data {'a1': 1, 'a0': 0, 'a3': 3, 'a2': 2, 'a5': 5, 'a4': 4, 'a7': 7, 'a6': 6, 'a9': 9, 'a8': 8} </...
4
2008-12-17T14:11:45Z
[ "python", "variables" ]
need help-variable creation in Python
374,572
<p>I want to create variables as <code>a1</code>,<code>a2</code>,<code>a3</code>...<code>a10</code>. For that I used a for loop. As the variable in loop increments I need to create a variable as above.</p> <p>Can anyone give me an idea?</p> <p>At the time of creation I also need to be able to assign values to them.</...
-1
2008-12-17T13:47:51Z
374,803
<p><code>globals()</code> returns the global dictionary of variables:</p> <pre><code>for i in range(1,6): globals()["a%i" % i] = i print a1, a2, a3, a4, a5 # -&gt; 1 2 3 4 5 </code></pre> <p>But frankly: I'd never do this, polluting the namespace automagically is harmful. I'd rather use a list or a dict.</p...
2
2008-12-17T14:59:54Z
[ "python", "variables" ]
How can I find all the subsets of a set, with exactly n elements?
374,626
<p>I am writing a program in Python, and I realized that a problem I need to solve requires me, given a set <code>S</code> with <code>n</code> elements (|S|=n), to test a function on all possible subsets of a certain order <code>m</code> (i.e. with <em>m</em> number of elements). To use the answer to produce a partial ...
30
2008-12-17T14:09:18Z
374,645
<p><a href="http://docs.python.org/library/itertools.html#itertools.combinations">itertools.combinations</a> is your friend if you have Python 2.6 or greater. Otherwise, check the link for an implementation of an equivalent function.</p> <pre><code>import itertools def findsubsets(S,m): return set(itertools.combi...
73
2008-12-17T14:15:07Z
[ "python" ]
How can I find all the subsets of a set, with exactly n elements?
374,626
<p>I am writing a program in Python, and I realized that a problem I need to solve requires me, given a set <code>S</code> with <code>n</code> elements (|S|=n), to test a function on all possible subsets of a certain order <code>m</code> (i.e. with <em>m</em> number of elements). To use the answer to produce a partial ...
30
2008-12-17T14:09:18Z
374,652
<p>It seems like this recipe does the trick: <a href="http://code.activestate.com/recipes/500268/" rel="nofollow">http://code.activestate.com/recipes/500268/</a></p>
2
2008-12-17T14:18:19Z
[ "python" ]
How can I find all the subsets of a set, with exactly n elements?
374,626
<p>I am writing a program in Python, and I realized that a problem I need to solve requires me, given a set <code>S</code> with <code>n</code> elements (|S|=n), to test a function on all possible subsets of a certain order <code>m</code> (i.e. with <em>m</em> number of elements). To use the answer to produce a partial ...
30
2008-12-17T14:09:18Z
14,285,114
<p>Here's a one-liner that gives you all subsets of the integers [0..n], not just the subsets of a given length:</p> <pre><code>from itertools import combinations, chain allsubsets = lambda n: list(chain(*[combinations(range(n), ni) for ni in range(n+1)])) </code></pre> <p>so e.g.</p> <pre><code>&gt;&gt; allsubsets(...
16
2013-01-11T19:16:23Z
[ "python" ]
How can I find all the subsets of a set, with exactly n elements?
374,626
<p>I am writing a program in Python, and I realized that a problem I need to solve requires me, given a set <code>S</code> with <code>n</code> elements (|S|=n), to test a function on all possible subsets of a certain order <code>m</code> (i.e. with <em>m</em> number of elements). To use the answer to produce a partial ...
30
2008-12-17T14:09:18Z
14,906,199
<p>Here's some pseudocode - you can cut same recursive calls by storing the values for each call as you go and before recursive call checking if the call value is already present.</p> <p>The following algorithm will have all the subsets excluding the empty set.</p> <pre><code>list * subsets(string s, list * v) { ...
2
2013-02-16T02:10:51Z
[ "python" ]
How can I find all the subsets of a set, with exactly n elements?
374,626
<p>I am writing a program in Python, and I realized that a problem I need to solve requires me, given a set <code>S</code> with <code>n</code> elements (|S|=n), to test a function on all possible subsets of a certain order <code>m</code> (i.e. with <em>m</em> number of elements). To use the answer to produce a partial ...
30
2008-12-17T14:09:18Z
16,915,734
<p>Using the canonical function to get the <a href="http://en.wikipedia.org/wiki/Power_set">powerset</a> from the <a href="http://docs.python.org/2/library/itertools.html#recipes">the itertools recipe</a> page:</p> <pre><code>from itertools import chain, combinations def powerset(iterable): xs = list(iterable) # ...
26
2013-06-04T10:41:13Z
[ "python" ]
How can I find all the subsets of a set, with exactly n elements?
374,626
<p>I am writing a program in Python, and I realized that a problem I need to solve requires me, given a set <code>S</code> with <code>n</code> elements (|S|=n), to test a function on all possible subsets of a certain order <code>m</code> (i.e. with <em>m</em> number of elements). To use the answer to produce a partial ...
30
2008-12-17T14:09:18Z
36,796,196
<p><strong>Without using <code>itertools</code></strong>:</p> <p>In Python 3 you can use <code>yield from</code> to add a subset generator method to buit-in <code>set</code> class:</p> <pre><code>class SetWithSubet(set): def subsets(self): s1 = [] s2 = list(self) def recfunc(i=0): ...
0
2016-04-22T14:14:51Z
[ "python" ]
Should I use get_/set_ prefixes in Python method names?
374,763
<p>In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes.</p> <p>But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these met...
7
2008-12-17T14:49:54Z
374,856
<p>I think shorter is better, so I tend to prefer the later. But what's important is to consistent with your project: don't mix the two methods. If you jump into someone else's project, keep what the other developers chose initially.</p>
2
2008-12-17T15:16:03Z
[ "python", "coding-style" ]
Should I use get_/set_ prefixes in Python method names?
374,763
<p>In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes.</p> <p>But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these met...
7
2008-12-17T14:49:54Z
374,860
<p>I've seen it done both ways. Coming from an Objective-C background, I usually do <code>foo()/set_foo()</code> if I can't use a property (although I try to use properties whenever possible). It doesn't really matter that much, though, <em>as long as you're consistent</em>.</p> <p>(Of course, in your example, I would...
1
2008-12-17T15:17:01Z
[ "python", "coding-style" ]
Should I use get_/set_ prefixes in Python method names?
374,763
<p>In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes.</p> <p>But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these met...
7
2008-12-17T14:49:54Z
375,037
<p>You won't ever loose the chance to make your property behave like a getter/setter later by using <a href="http://users.rcn.com/python/download/Descriptor.htm" rel="nofollow">descriptors</a>. If you want to change a property to be read only you can also replace it with a getter method with the same name as the proper...
4
2008-12-17T16:01:57Z
[ "python", "coding-style" ]
Should I use get_/set_ prefixes in Python method names?
374,763
<p>In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes.</p> <p>But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these met...
7
2008-12-17T14:49:54Z
375,160
<p>If it's usable as a property (one value to get or set, and no other parameters, I usually do:</p> <pre><code>class Foo(object): def _get_x(self): pass def _set_x(self, value): pass x = property(_get_x, _set_x) </code></pre> <p>If the getter/setter is any more complex than that, I wou...
3
2008-12-17T16:35:53Z
[ "python", "coding-style" ]
Should I use get_/set_ prefixes in Python method names?
374,763
<p>In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes.</p> <p>But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these met...
7
2008-12-17T14:49:54Z
375,661
<p>If I have to use a getter/setter, I like it this way:</p> <p>Suppose you have a variable self._x. Then x() would return the value of self._x, and setX(x) would set the value of self._x</p>
0
2008-12-17T19:05:50Z
[ "python", "coding-style" ]
How do you test a file.read() error in Python?
374,768
<p>I have the following code (adapted from an example given in <a href="http://diveintopython.net/file_handling/file_objects.html#d0e14928" rel="nofollow">Dive Into Python</a>) that reads the entire contents of a file into a buffer.</p> <pre><code>buffer = "" try: file = open(postFileName, 'rU') try: ...
4
2008-12-17T14:51:23Z
374,821
<p>With a recent version of Python, you don't need to nest try-except and try-finally. try-except-finally has been unified:</p> <pre><code>try: non_existing_var except: print 'error' finally: print 'finished' </code></pre>
0
2008-12-17T15:05:38Z
[ "python", "file-io", "error-handling" ]
How do you test a file.read() error in Python?
374,768
<p>I have the following code (adapted from an example given in <a href="http://diveintopython.net/file_handling/file_objects.html#d0e14928" rel="nofollow">Dive Into Python</a>) that reads the entire contents of a file into a buffer.</p> <pre><code>buffer = "" try: file = open(postFileName, 'rU') try: ...
4
2008-12-17T14:51:23Z
374,853
<p>Googling a little bit got this <a href="http://www.python.org/doc/2.5/whatsnew/pep-341.html" rel="nofollow">Unified try/except/finally </a></p> <p>Hope it helps ;)</p>
0
2008-12-17T15:15:49Z
[ "python", "file-io", "error-handling" ]
How do you test a file.read() error in Python?
374,768
<p>I have the following code (adapted from an example given in <a href="http://diveintopython.net/file_handling/file_objects.html#d0e14928" rel="nofollow">Dive Into Python</a>) that reads the entire contents of a file into a buffer.</p> <pre><code>buffer = "" try: file = open(postFileName, 'rU') try: ...
4
2008-12-17T14:51:23Z
374,895
<p>I find that finally blocks are often overused. The file close (and a few other similar patterns) are so important that Python 3.0 will have a <strong>with</strong> statement just to cover this base in a slightly less obscure way.</p> <ul> <li><p>Do I need an except with a finally? </p> <p>That hits on the confusi...
6
2008-12-17T15:29:27Z
[ "python", "file-io", "error-handling" ]
How do you test a file.read() error in Python?
374,768
<p>I have the following code (adapted from an example given in <a href="http://diveintopython.net/file_handling/file_objects.html#d0e14928" rel="nofollow">Dive Into Python</a>) that reads the entire contents of a file into a buffer.</p> <pre><code>buffer = "" try: file = open(postFileName, 'rU') try: ...
4
2008-12-17T14:51:23Z
374,904
<p>I disagree with the other answers mentioning unifying the try / except / finally blocks. That would change the behaviour, as you wouldn't want the finally block to try to close the file if the open failed. The split blocks are correct here (though it may be better using the new "<code>with open(filename,'rU') as f...
3
2008-12-17T15:31:43Z
[ "python", "file-io", "error-handling" ]
How to send clip names using LiveAPI (of Ableton Live)
375,052
<p>When an audio or midi clip is played (triggered), its name needs to be sent using OSC to <a href="http://vvvv.org/" rel="nofollow">another application</a>.</p> <p><a href="http://www.assembla.com/wiki/show/live-api" rel="nofollow">LiveAPI</a> is an interface which allows one to explore and automate <a href="http://...
4
2008-12-17T16:05:31Z
491,274
<p>According to <a href="http://svn2.assembla.com/svn/live-api/trunk/docs/Ableton%20Live%20API/modules/Clip.Clip.html" rel="nofollow">the LiveAPI documentation</a>, the Clip object has a "name" attribute which holds the clip name. Presumably that's what you want to send in your OSC packets.</p> <p>Also, it's worth me...
2
2009-01-29T11:30:36Z
[ "python", "api", "osc", "ableton-live" ]
How to send clip names using LiveAPI (of Ableton Live)
375,052
<p>When an audio or midi clip is played (triggered), its name needs to be sent using OSC to <a href="http://vvvv.org/" rel="nofollow">another application</a>.</p> <p><a href="http://www.assembla.com/wiki/show/live-api" rel="nofollow">LiveAPI</a> is an interface which allows one to explore and automate <a href="http://...
4
2008-12-17T16:05:31Z
496,286
<p>I know about Max 4 Live, but as I see it, it's kind of a different thing. Yes, it will probably be able to interface with Live to do all the stuff which people do now with LiveAPI. Some even think that M4L may not even go through LiveAPI, and use some internal interface instead (since Ableton and Cycling 74 are deve...
0
2009-01-30T16:57:08Z
[ "python", "api", "osc", "ableton-live" ]
How do I get the time a file was last modified in Python?
375,154
<p>Assuming the file exists (using <code>os.path.exists(filename)</code> to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference.</p>
30
2008-12-17T16:33:41Z
375,168
<p><a href="http://docs.python.org/library/os.html#os.stat">os.stat()</a></p> <pre><code>import os filename = "/etc/fstab" statbuf = os.stat(filename) print "Modification time:",statbuf.st_mtime </code></pre> <p>Linux does not record the creation time of a file (<a href="http://unix.stackexchange.com/q/24441/61642">...
30
2008-12-17T16:38:08Z
[ "python", "file", "time" ]
How do I get the time a file was last modified in Python?
375,154
<p>Assuming the file exists (using <code>os.path.exists(filename)</code> to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference.</p>
30
2008-12-17T16:33:41Z
375,186
<pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; f = os.path.getmtime('test1.jpg') &gt;&gt;&gt; f 1223995325.0 </code></pre> <p>since the beginning of (epoch)</p>
79
2008-12-17T16:41:59Z
[ "python", "file", "time" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
375,503
<p>One solution is to make another process to perform your read of the process, or make a thread of the process with a timeout.</p> <p>Here's the threaded version of a timeout function:</p> <p><a href="http://code.activestate.com/recipes/473878/">http://code.activestate.com/recipes/473878/</a></p> <p>However, do you...
8
2008-12-17T18:16:48Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
375,511
<p>The <a href="http://www.python.org/doc/2.5.2/lib/module-select.html" rel="nofollow">select</a> module helps you determine where the next useful input is.</p> <p>However, you're almost always happier with separate threads. One does a blocking read the stdin, another does wherever it is you don't want blocked.</p>
1
2008-12-17T18:19:25Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
437,888
<p>Try the <a href="http://www.lysator.liu.se/~bellman/download/asyncproc.py">asyncproc</a> module. For example:</p> <pre><code>import os from asyncproc import Process myProc = Process("myprogram.app") while True: # check to see if process has ended poll = myProc.wait(os.WNOHANG) if poll != None: ...
19
2009-01-13T03:36:16Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
1,810,703
<p>I have often had a similar problem; Python programs I write frequently need to have the ability to execute some primary functionality while simultaneously accepting user input from the command line (stdin). Simply putting the user input handling functionality in another thread doesn't solve the problem because <code...
56
2009-11-27T21:33:52Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
4,800,541
<p>Use select &amp; read(1). </p> <pre><code>import subprocess #no new requirements def readAllSoFar(proc, retVal=''): while (select.select([proc.stdout],[],[],0)[0]!=[]): retVal+=proc.stdout.read(1) return retVal p = subprocess.Popen(['/bin/ls'], stdout=subprocess.PIPE) while not p.poll(): print (r...
12
2011-01-26T01:02:08Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
4,896,288
<p><a href="http://stackoverflow.com/questions/375427/non-blocking-read-on-a-stream-in-python/4025909#4025909"><code>fcntl</code></a>, <a href="http://stackoverflow.com/questions/375427/non-blocking-read-on-a-stream-in-python/375511#375511"><code>select</code></a>, <a href="http://stackoverflow.com/questions/375427/non...
263
2011-02-04T09:14:38Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
5,749,687
<p>I add this problem to read some subprocess.Popen stdout. Here is my non blocking read solution:</p> <pre><code>import fcntl def non_block_read(output): fd = output.fileno() fl = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK) try: return output.read() e...
3
2011-04-21T20:51:57Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
5,750,194
<p>You can do this really easily in <a href="http://twistedmatrix.com/trac/">Twisted</a>. Depending upon your existing code base, this might not be that easy to use, but if you are building a twisted application, then things like this become almost trivial. You create a <code>ProcessProtocol</code> class, and override ...
15
2011-04-21T21:54:55Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
11,362,426
<p>Disclaimer: this works only for tornado</p> <p>You can do this by setting the fd to be nonblocking and then use ioloop to register callbacks. I have packaged this in an egg called <a href="http://pypi.python.org/pypi/tornado_subprocess/0.1.3">tornado_subprocess</a> and you can install it via PyPI:</p> <pre><code>e...
7
2012-07-06T12:42:26Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
15,424,877
<p>Existing solutions did not work for me (details below). What finally worked was to implement readline using read(1) (based on <a href="http://stackoverflow.com/a/883166/2039589">this answer</a>). The latter does not block:</p> <pre><code>from subprocess import Popen, PIPE from threading import Thread def process_ou...
5
2013-03-15T04:40:40Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
16,256,473
<p>I have created a library based on <a href="http://stackoverflow.com/a/4896288/242451">J. F. Sebastian's solution</a>. You can use it.</p> <p><a href="https://github.com/cenkalti/what" rel="nofollow">https://github.com/cenkalti/what</a></p>
0
2013-04-27T20:14:51Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
16,425,237
<p>EDIT: This implementation still blocks. Use J.F.Sebastian's <a href="http://stackoverflow.com/a/4896288/2359288">answer</a> instead.</p> <p><strike>I tried the <a href="http://stackoverflow.com/a/4896288/2359288">top answer</a>, but the additional risk and maintenance of thread code was worrisome.</p> <p>Looking t...
0
2013-05-07T17:38:40Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
17,051,876
<p>Here is my code, used to catch every output from subprocess ASAP, including partial lines. It pumps at same time and stdout and stderr in almost correct order.</p> <p>Tested and correctly worked on Python 2.7 linux &amp; windows. </p> <pre><code>#!/usr/bin/python # # Runner with stdout/stderr catcher # from sys im...
3
2013-06-11T19:09:11Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
19,703,560
<p>Working from J.F. Sebastian's answer, and several other sources, I've put together a simple subprocess manager. It provides the request non-blocking reading, as well as running several processes in parallel. It doesn't use any OS-specific call (that I'm aware) and thus should work anywhere.</p> <p>It's available fr...
0
2013-10-31T10:09:25Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
20,697,159
<p>Python 3.4 introduces new <a href="http://www.python.org/dev/peps/pep-0411/">provisional API</a> for asynchronous IO -- <a href="http://docs.python.org/3/library/asyncio.html"><code>asyncio</code> module</a>. </p> <p>The approach is similar to <a href="http://stackoverflow.com/a/5750194/4279"><code>twisted</code>-b...
24
2013-12-20T05:50:15Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
27,887,083
<p>I recently stumbled upon on the same problem I need to read one line at time from stream ( tail run in subprocess ) in non-blocking mode I wanted to avoid next problems: not to burn cpu, don't read stream by one byte (like readline did ), etc</p> <p>Here is my implementation <a href="https://gist.github.com/grubbe...
0
2015-01-11T12:33:31Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
28,019,908
<p>why bothering thread&amp;queue? unlike readline(), BufferedReader.read1() wont block waiting for \r\n, it returns ASAP if there is any output coming in.</p> <pre><code>#!/usr/bin/python from subprocess import Popen, PIPE, STDOUT import io def __main__(): try: p = Popen( ["ping", "-n", "3", "127.0.0.1"]...
-1
2015-01-19T07:39:26Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
28,264,979
<p>In my case I needed a logging module that catches the output from the background applications and augments it(adding time-stamps, colors, etc.).</p> <p>I ended up with a background thread that does the actual I/O. Following code is only for POSIX platforms. I stripped non-essential parts. </p> <p>If someone is goi...
0
2015-02-01T16:32:43Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
34,832,502
<p>Here is a module that supports non-blocking reads and background writes in python:</p> <p><a href="https://pypi.python.org/pypi/python-nonblock" rel="nofollow">https://pypi.python.org/pypi/python-nonblock</a></p> <p>Provides a function,</p> <p>nonblock_read which will read data from the stream, if available, othe...
-2
2016-01-16T21:47:15Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
35,052,424
<p>Adding this answer here since it provides ability to set non-blocking pipes on Windows and Unix.</p> <p>All the <code>ctypes</code> details are thanks to <a href="http://stackoverflow.com/questions/34504970">@techtonik's answer</a>.</p> <p>There is a slightly modified version to be used both on Unix and Windows sy...
1
2016-01-28T03:37:45Z
[ "python", "io", "subprocess", "nonblocking" ]
Non-blocking read on a subprocess.PIPE in python
375,427
<p>I'm using the <a href="http://docs.python.org/library/subprocess.html">subprocess module</a> to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before...
327
2008-12-17T17:56:34Z
37,418,460
<p>This version of non-blocking read <strong>doesn't</strong> require special modules and will work out-of-the-box on majority of Linux distros.</p> <pre><code>import os import sys import time import fcntl import subprocess def async_read(fd): # set non-blocking flag while preserving old flags fl = fcntl.fcnt...
0
2016-05-24T15:55:16Z
[ "python", "io", "subprocess", "nonblocking" ]
Prevent ftplib from Downloading a File in Progress?
375,620
<p>We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file...
4
2008-12-17T18:54:03Z
375,650
<p>You can't know when the OS copy is done. It could slow down or wait.</p> <p>For absolute certainty, you really need two files.</p> <ul> <li>The massive file.</li> <li>And a tiny trigger file.</li> </ul> <p>They can mess with the massive file all they want. But when they touch the trigger file, you're downloadin...
0
2008-12-17T19:03:45Z
[ "python", "ftp", "ftplib" ]
Prevent ftplib from Downloading a File in Progress?
375,620
<p>We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file...
4
2008-12-17T18:54:03Z
375,705
<p>As you say you have 0 control over the servers and can't make your clients post trigger files as suggested by S. Lott, you must deal with the imperfect solution and risk incomplete file transmission, perhaps by waiting for a while and compare file sizes before and after.</p> <p>You can try to rename as you suggeste...
0
2008-12-17T19:19:30Z
[ "python", "ftp", "ftplib" ]
Prevent ftplib from Downloading a File in Progress?
375,620
<p>We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file...
4
2008-12-17T18:54:03Z
375,716
<p>If you are dealing with multiple files, you could get the list of all the sizes at once, wait ten seconds, and see which are the same. Whichever are still the same should be safe to download.</p>
0
2008-12-17T19:23:06Z
[ "python", "ftp", "ftplib" ]
Prevent ftplib from Downloading a File in Progress?
375,620
<p>We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file...
4
2008-12-17T18:54:03Z
375,800
<p><strong>“Damn the torpedoes! Full speed ahead!”</strong></p> <p>Just download the file. If it is a large file then after the download completes wait as long as is reasonable for your scenario and continue the download from the point it stopped. Repeat until there is no more stuff to download.</p>
5
2008-12-17T19:49:01Z
[ "python", "ftp", "ftplib" ]
How do I create a wx.Image object from in-memory data?
375,820
<p>I'm writing a GUI application in Python using wxPython and I want to display an image in a static control (<code>wx.StaticBitmap</code>).</p> <p>I can use <a href="http://www.wxpython.org/docs/api/wx-module.html#ImageFromStream" rel="nofollow"><code>wx.ImageFromStream</code></a> to load an image from a file, and th...
4
2008-12-17T19:54:46Z
375,836
<p>Since in Python you use Duck Typing you can write your own stream class and hand an instance of that class to ImageFromStream. I think you only need to implement the read method and make it return your data.</p>
0
2008-12-17T20:01:11Z
[ "python", "wxpython", "wxwidgets" ]
How do I create a wx.Image object from in-memory data?
375,820
<p>I'm writing a GUI application in Python using wxPython and I want to display an image in a static control (<code>wx.StaticBitmap</code>).</p> <p>I can use <a href="http://www.wxpython.org/docs/api/wx-module.html#ImageFromStream" rel="nofollow"><code>wx.ImageFromStream</code></a> to load an image from a file, and th...
4
2008-12-17T19:54:46Z
375,852
<p>You should be able to use <code>StringIO</code> to wrap the buffer in a memory file object.</p> <pre><code>... import StringIO buf = open("test.jpg", "rb").read() # buf = get_image_data() sbuf = StringIO.StringIO(buf) image = wx.ImageFromStream(sbuf) ... </code></pre> <p><code>buf</code> can be replaced with any...
8
2008-12-17T20:08:11Z
[ "python", "wxpython", "wxwidgets" ]
How do you override vim options via comments in a python source code file?
376,111
<p>I would like to set some vim options in one file in the comments section.</p> <p>For example, I would like to set this option in one file</p> <pre><code>set syntax=python </code></pre> <p>The file does not have a .py extension and I am not interested in making my vim installation recognise all files with this ext...
15
2008-12-17T21:37:46Z
376,200
<p>You're wanting a <a href="http://vim.wikia.com/wiki/Modeline_magic">modeline</a> The linked article should explain far better than I can.</p>
23
2008-12-17T22:02:51Z
[ "python", "vim" ]
How do you override vim options via comments in a python source code file?
376,111
<p>I would like to set some vim options in one file in the comments section.</p> <p>For example, I would like to set this option in one file</p> <pre><code>set syntax=python </code></pre> <p>The file does not have a .py extension and I am not interested in making my vim installation recognise all files with this ext...
15
2008-12-17T21:37:46Z
376,225
<p>I haven't used vim much, but I think what you want is to add a line like the following to the end of your file:</p> <pre><code># vim: set syntax=python: </code></pre>
9
2008-12-17T22:13:05Z
[ "python", "vim" ]
How do you override vim options via comments in a python source code file?
376,111
<p>I would like to set some vim options in one file in the comments section.</p> <p>For example, I would like to set this option in one file</p> <pre><code>set syntax=python </code></pre> <p>The file does not have a .py extension and I am not interested in making my vim installation recognise all files with this ext...
15
2008-12-17T21:37:46Z
34,433,933
<p>You override the Vim options by adding the modeline near the top or the bottom of the file, such as:</p> <pre><code>// vim: set syntax=python: </code></pre> <p>or:</p> <pre><code>/* vim: set syntax=python: */ </code></pre> <p>or like:</p> <pre><code># vim: set syntax=python ts=4 : </code></pre> <p>Other exampl...
1
2015-12-23T10:48:11Z
[ "python", "vim" ]