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 |
|---|---|---|---|---|---|---|---|---|---|
List of Dicts comparision to match between lists and detect value changes in Python | 2,412,562 | <p>I have a list of dictionaries that I get back from a web service call,</p>
<pre><code>listA = [{'name':'foo', 'val':'x'},
{'name':'bar', 'val':'1'},
{'name':'alice','val':'2'}]
</code></pre>
<p>I need to compare the results from the previous call to the service and pull out changes. So on the ne... | 1 | 2010-03-09T21:05:51Z | 2,412,670 | <p>First off, please turn that braindead format from your library into a real dict:</p>
<pre><code>>>> listA = [{'name':'foo', 'val':'x'},{'name':'bar', 'val':'1'},{'name':'alice','val':'2'}]
>>> listB = [{'name':'foo', 'val':'y'},{'name':'bar', 'val':'1'},{'name':'eve','val':'z'}]
>>> def d... | 0 | 2010-03-09T21:22:57Z | [
"python",
"comparison",
"list",
"dictionary"
] |
Python program doesn't quit when finished | 2,412,715 | <p>I have the following script 186.py:</p>
<pre><code>S=[]
study=set([524287])
tmax=10**7
D={}
DF={}
dudcount=0
callcount=0
def matchval(t1,t2):
if t1==t2:
global dudcount
dudcount+=1
else:
global callcount
callcount+=1
D.setdefault(t1,set([]))
D.setdefault(t2,... | 3 | 2010-03-09T21:29:47Z | 2,412,802 | <p>I ran the same code on my 2 GHz dual-core laptop with 2GB RAM and it took about 1 1/2 minutes in Cygwin. The memory usage got up over 600 MB before the program quit and it took about 2-4 seconds after <code>Done</code> appeared for the prompt to come up and the memory to be released. However, I didn't see any memory... | 5 | 2010-03-09T21:43:00Z | [
"python",
"linux",
"memory-leaks"
] |
Python program doesn't quit when finished | 2,412,715 | <p>I have the following script 186.py:</p>
<pre><code>S=[]
study=set([524287])
tmax=10**7
D={}
DF={}
dudcount=0
callcount=0
def matchval(t1,t2):
if t1==t2:
global dudcount
dudcount+=1
else:
global callcount
callcount+=1
D.setdefault(t1,set([]))
D.setdefault(t2,... | 3 | 2010-03-09T21:29:47Z | 2,412,815 | <p>There are no indications in what you've posted that match the described symptoms. Perhaps the indentation in the executed code is stuffed and you are really about to run another loop around the whole pile. Note that only brave people are going to bother trying to reproduce your problem when it takes 34 minutes to ru... | 1 | 2010-03-09T21:46:08Z | [
"python",
"linux",
"memory-leaks"
] |
Good ways to sort a queryset? - Django | 2,412,770 | <p>what I'm trying to do is this:</p>
<ul>
<li><p>get the 30 Authors with highest score ( <code>Author.objects.order_by('-score')[:30]</code> )</p></li>
<li><p>order the authors by <code>last_name</code></p></li>
</ul>
<hr>
<p>Any suggestions?</p>
| 54 | 2010-03-09T21:37:57Z | 2,412,831 | <p>What about</p>
<pre><code>import operator
auths = Author.objects.order_by('-score')[:30]
ordered = sorted(auths, key=operator.attrgetter('last_name'))
</code></pre>
<p>In Django 1.4 and newer you can order by providing multiple fields.<br>
Reference: <a href="https://docs.djangoproject.com/en/dev/ref/models/query... | 95 | 2010-03-09T21:48:45Z | [
"python",
"django",
"django-models"
] |
Good ways to sort a queryset? - Django | 2,412,770 | <p>what I'm trying to do is this:</p>
<ul>
<li><p>get the 30 Authors with highest score ( <code>Author.objects.order_by('-score')[:30]</code> )</p></li>
<li><p>order the authors by <code>last_name</code></p></li>
</ul>
<hr>
<p>Any suggestions?</p>
| 54 | 2010-03-09T21:37:57Z | 2,412,934 | <p>Here's a way that allows for ties for the cut-off score.</p>
<pre><code>author_count = Author.objects.count()
cut_off_score = Author.objects.order_by('-score').values_list('score')[min(30, author_count)]
top_authors = Author.objects.filter(score__gte=cut_off_score).order_by('last_name')
</code></pre>
<p>You may ge... | 2 | 2010-03-09T22:07:58Z | [
"python",
"django",
"django-models"
] |
Good ways to sort a queryset? - Django | 2,412,770 | <p>what I'm trying to do is this:</p>
<ul>
<li><p>get the 30 Authors with highest score ( <code>Author.objects.order_by('-score')[:30]</code> )</p></li>
<li><p>order the authors by <code>last_name</code></p></li>
</ul>
<hr>
<p>Any suggestions?</p>
| 54 | 2010-03-09T21:37:57Z | 2,413,908 | <p>I just wanted to illustrate that the built-in solutions (SQL-only) are not always the best ones. At first I thought that because Django's <code>QuerySet.objects.order_by</code> method accepts multiple arguments, you could easily chain them:</p>
<pre><code>ordered_authors = Author.objects.order_by('-score', 'last_n... | 7 | 2010-03-10T01:28:54Z | [
"python",
"django",
"django-models"
] |
Circular import issues with Django apps that have dependencies on each other | 2,412,995 | <p>I am writing a couple of django apps wich by design is coupled together. But i get sircular import problems. I know it might be bad design, so please give examples of better solutions, but i cant seem to find a better suited design. So if there isnt a better design, how to solve this one?</p>
<p>It is basically two... | 5 | 2010-03-09T22:16:34Z | 2,413,109 | <p>Both models do not need many-to-many fields.</p>
<p>Do not put both sides of a many-to-many relationship in your model.</p>
<p>When you put in one many-to-many relationship, <em>Django inserts the other side of the relationship for you</em>. </p>
<p><a href="http://docs.djangoproject.com/en/1.1/topics/db/queries/... | 7 | 2010-03-09T22:33:41Z | [
"python",
"django",
"design-patterns",
"import"
] |
timedelta convert to time or int and store it in GAE (python) datastore | 2,413,144 | <p>It looks like this has been covered somewhat in other questions, but I'm still fairly confused on how to actually do this. My lack of experience isn't helping much with that.</p>
<p>I have two DateTimeProperties - StartTime and EndTime. I'm subtracting StartTime from EndTime to get the Duration. From my previous qu... | 4 | 2010-03-09T22:37:50Z | 2,413,729 | <pre><code>import pickle
import datetime
...
delta = end_time - start_time
for_storage = pickle.dumps(delta)
#now you have a string representation of your timedelta object that you can store
#sometime later...
delta = pickle.loads(from_storage)
</code></pre>
<p>You'll still need to convert the delta to a time resol... | 0 | 2010-03-10T00:40:54Z | [
"python",
"google-app-engine"
] |
timedelta convert to time or int and store it in GAE (python) datastore | 2,413,144 | <p>It looks like this has been covered somewhat in other questions, but I'm still fairly confused on how to actually do this. My lack of experience isn't helping much with that.</p>
<p>I have two DateTimeProperties - StartTime and EndTime. I'm subtracting StartTime from EndTime to get the Duration. From my previous qu... | 4 | 2010-03-09T22:37:50Z | 2,414,553 | <p>This ultimately worked:</p>
<pre><code>delta = StartTime - EndTime
event_record.Duration = int((delta.microseconds)/1000)
</code></pre>
<p>basically, needed to get microseconds out of the timedelta and convert it to milliseconds.</p>
| 0 | 2010-03-10T04:37:14Z | [
"python",
"google-app-engine"
] |
timedelta convert to time or int and store it in GAE (python) datastore | 2,413,144 | <p>It looks like this has been covered somewhat in other questions, but I'm still fairly confused on how to actually do this. My lack of experience isn't helping much with that.</p>
<p>I have two DateTimeProperties - StartTime and EndTime. I'm subtracting StartTime from EndTime to get the Duration. From my previous qu... | 4 | 2010-03-09T22:37:50Z | 2,416,049 | <p>To make this as easy as possible to work with, there's two steps: Converting the timedelta to an int or a float, and storing it in the datastore. First things first, converting a timedelta to a microtime:</p>
<pre><code>def timedelta_to_microtime(td):
return td.microseconds + (td.seconds + td.days * 86400) * 1000... | 12 | 2010-03-10T10:20:29Z | [
"python",
"google-app-engine"
] |
timedelta convert to time or int and store it in GAE (python) datastore | 2,413,144 | <p>It looks like this has been covered somewhat in other questions, but I'm still fairly confused on how to actually do this. My lack of experience isn't helping much with that.</p>
<p>I have two DateTimeProperties - StartTime and EndTime. I'm subtracting StartTime from EndTime to get the Duration. From my previous qu... | 4 | 2010-03-09T22:37:50Z | 10,673,791 | <p>If you're going to store it as a <code>datetime</code> (which I agree is a good idea), I'd extend the <code>DateTimeProperty</code> - then you get various bits of parsing and validation for free.</p>
<p>Also, storing as <code>timedelta</code> as a <code>datetime</code> can be much easier than the other methods give... | 1 | 2012-05-20T13:25:12Z | [
"python",
"google-app-engine"
] |
Get decorated function object by string name | 2,413,271 | <pre><code>def log(func):
def wraper(*a, **kw):
return func(*a, **kw)
return wraper
@log
def f():
print 'f'
print locals()['f'] # - prints <function wraper at 0x00CBF3F0>.
</code></pre>
<p>How do you get the real f object (not decorator wrap)?</p>
| 1 | 2010-03-09T22:59:29Z | 2,413,296 | <p>You don't.<sup>1</sup> Store it if you need to access it later.</p>
<pre><code>def log(func):
def wrapper(*a, **kw):
return func(*a, **kw)
wrapper.func = func
return wrapper
@log
def f():
print 'f'
print f.func
</code></pre>
<p><sup><sup>1</sup> You could mess with the closure, but I can't recommend... | 5 | 2010-03-09T23:04:55Z | [
"python",
"string",
"function",
"decorator"
] |
Get decorated function object by string name | 2,413,271 | <pre><code>def log(func):
def wraper(*a, **kw):
return func(*a, **kw)
return wraper
@log
def f():
print 'f'
print locals()['f'] # - prints <function wraper at 0x00CBF3F0>.
</code></pre>
<p>How do you get the real f object (not decorator wrap)?</p>
| 1 | 2010-03-09T22:59:29Z | 2,413,460 | <p>The <a href="http://docs.python.org/library/functools.html">functools</a> module also provides a <code>wraps</code> decorator which makes sure that the wrapped function looks more like the real function: correct name, module, and docstring, for example.</p>
| 7 | 2010-03-09T23:37:17Z | [
"python",
"string",
"function",
"decorator"
] |
Get decorated function object by string name | 2,413,271 | <pre><code>def log(func):
def wraper(*a, **kw):
return func(*a, **kw)
return wraper
@log
def f():
print 'f'
print locals()['f'] # - prints <function wraper at 0x00CBF3F0>.
</code></pre>
<p>How do you get the real f object (not decorator wrap)?</p>
| 1 | 2010-03-09T22:59:29Z | 25,909,794 | <p>If you're running python 3.2 or above, and you use <a href="https://docs.python.org/3/library/functools.html#functools.wraps" rel="nofollow"><code>functools.wraps</code></a> then you will find the wrapped function on the <code>__wrapped__</code> attribute:</p>
<pre><code>from functools import wraps
def log(func):
... | 0 | 2014-09-18T10:07:32Z | [
"python",
"string",
"function",
"decorator"
] |
Web service API - which language is better? | 2,413,297 | <p>I wrote a web service API which services REST requests in php. It didn't take much time to actually setup this on apache. But, I am more comfortable writing python code rather than php code. Can python be used as a server-side scripting language like php? What changes are necessary to make it work with apache?</p>
... | 2 | 2010-03-09T23:04:55Z | 2,413,316 | <p>For a REST full API I would suggest that you take a look at <a href="http://www.tornadoweb.org/" rel="nofollow">Tornado</a>. It's what Facebook uses. It's fast, efficient and easy to work with (written i Python). You may use <a href="http://wiki.nginx.org/Main" rel="nofollow">nginx</a> as a proxy in front of it to s... | 3 | 2010-03-09T23:07:48Z | [
"php",
"python",
"web-services",
"rest",
"apache2"
] |
Web service API - which language is better? | 2,413,297 | <p>I wrote a web service API which services REST requests in php. It didn't take much time to actually setup this on apache. But, I am more comfortable writing python code rather than php code. Can python be used as a server-side scripting language like php? What changes are necessary to make it work with apache?</p>
... | 2 | 2010-03-09T23:04:55Z | 2,413,318 | <p>Yes Python can be used as server-side language (as well as Perl, Ruby or even C/C++). Just use mod_python for Apache <a href="http://www.modpython.org/" rel="nofollow">http://www.modpython.org/</a></p>
| 1 | 2010-03-09T23:08:31Z | [
"php",
"python",
"web-services",
"rest",
"apache2"
] |
Web service API - which language is better? | 2,413,297 | <p>I wrote a web service API which services REST requests in php. It didn't take much time to actually setup this on apache. But, I am more comfortable writing python code rather than php code. Can python be used as a server-side scripting language like php? What changes are necessary to make it work with apache?</p>
... | 2 | 2010-03-09T23:04:55Z | 2,413,346 | <p>Python is a very capable server-side language. Large sites (such as <a href="http://www.aginteractive.com/" rel="nofollow">AG Interactive</a>) use Python for server-side programming and have had great results. <a href="http://www.modpython.org/" rel="nofollow">mod_python</a> and <a href="http://code.google.com/p/m... | 2 | 2010-03-09T23:14:06Z | [
"php",
"python",
"web-services",
"rest",
"apache2"
] |
Web service API - which language is better? | 2,413,297 | <p>I wrote a web service API which services REST requests in php. It didn't take much time to actually setup this on apache. But, I am more comfortable writing python code rather than php code. Can python be used as a server-side scripting language like php? What changes are necessary to make it work with apache?</p>
... | 2 | 2010-03-09T23:04:55Z | 2,413,792 | <p>I'll dare to say that mod_wsgi is probably closer to the de-facto choice (vs. mod_python) if you're stuck with Apache as your web server these days. One benefit is that you'll find a wide range of active frameworks and libraries that are <a href="http://wsgi.org/wsgi/" rel="nofollow">WSGI</a> compatible. Please don... | 1 | 2010-03-10T00:59:02Z | [
"php",
"python",
"web-services",
"rest",
"apache2"
] |
how to convert a timedelta object into a datetime object | 2,413,391 | <p>What is the proper way to convert a timedelta object into a datetime object? I immediately think of something like <code>datetime(0)+deltaObj</code> but that's not very nice... isn't there a <code>toDateTime()</code> function or something of the sort?</p>
| 7 | 2010-03-09T23:22:45Z | 2,413,400 | <p>It doesn't make sense to convert a timedelta into a datetime, but it does make sense to pick an initial or starting datetime and add or subtract a timedelta from that.</p>
<pre><code>>>> import datetime
>>> today = datetime.datetime.today()
>>> today
datetime.datetime(2010, 3, 9, 18, 25, ... | 17 | 2010-03-09T23:25:01Z | [
"python",
"datetime",
"timedelta"
] |
Weighted standard deviation in NumPy? | 2,413,522 | <p><code>numpy.average()</code> has a weights option, but <code>numpy.std()</code> does not. Does anyone have suggestions for a workaround?</p>
| 36 | 2010-03-09T23:53:36Z | 2,413,568 | <p>There doesn't appear to be such a function in numpy/scipy yet, but there is a <a href="https://github.com/scipy/scipy/issues/1131" rel="nofollow">ticket</a> proposing this added functionality. Included there you will find <a href="http://projects.scipy.org/scipy/attachment/ticket/604/Statistics.py" rel="nofollow">St... | 6 | 2010-03-10T00:06:51Z | [
"python",
"numpy",
"weighted",
"standard-deviation"
] |
Weighted standard deviation in NumPy? | 2,413,522 | <p><code>numpy.average()</code> has a weights option, but <code>numpy.std()</code> does not. Does anyone have suggestions for a workaround?</p>
| 36 | 2010-03-09T23:53:36Z | 2,415,343 | <p>How about the following short "manual calculation"?</p>
<pre><code>def weighted_avg_and_std(values, weights):
"""
Return the weighted average and standard deviation.
values, weights -- Numpy ndarrays with the same shape.
"""
average = numpy.average(values, weights=weights)
variance = numpy.... | 57 | 2010-03-10T08:07:16Z | [
"python",
"numpy",
"weighted",
"standard-deviation"
] |
Weighted standard deviation in NumPy? | 2,413,522 | <p><code>numpy.average()</code> has a weights option, but <code>numpy.std()</code> does not. Does anyone have suggestions for a workaround?</p>
| 36 | 2010-03-09T23:53:36Z | 36,464,881 | <p>There is some functionality in <code>statsmodels</code> which can calculate weighted statistics: <a href="http://statsmodels.sourceforge.net/devel/generated/statsmodels.stats.weightstats.DescrStatsW.html" rel="nofollow"><code>statsmodels.stats.weightstats.DescrStatsW</code></a>:</p>
<pre><code>from statsmodels.stat... | 2 | 2016-04-07T00:57:27Z | [
"python",
"numpy",
"weighted",
"standard-deviation"
] |
Allow user to select a file or a folder in QFileDialog | 2,413,692 | <p>In PyQt you can do something like the following to allow the user to select a file</p>
<pre><code>filename = QtGui.QFileDialog.getOpenFileName(self, "Choose file..")
</code></pre>
<p>However I would like a <code>QFileDialog</code> to open in which the user would be able to select either a file or a directory. I'm ... | 3 | 2010-03-10T00:32:30Z | 2,416,052 | <p>From what I remember you need to write your own QFileDialog and set proper <a href="http://doc.trolltech.com/4.6/qfiledialog.html#FileMode-enum" rel="nofollow">mode</a>. I believe this should be <code>QFileDialog.ExistingFile & QFileDialog.Directory</code>.</p>
<p>You can try to write your own static method bas... | 0 | 2010-03-10T10:21:04Z | [
"python",
"pyqt"
] |
Stream a file to the HTTP response in Pylons | 2,413,707 | <p>I have a Pylons controller action that needs to return a file to the client. (The file is outside the web root, so I can't just link directly to it.) The simplest way is, of course, this:</p>
<pre><code> with open(filepath, 'rb') as f:
response.write(f.read())
</code></pre>
<p>That works, but it's obvio... | 6 | 2010-03-10T00:35:20Z | 2,413,943 | <p>The correct tool to use is shutil.copyfileobj, which copies from one to the other a chunk at a time.</p>
<p>Example usage:</p>
<pre><code>import shutil
with open(filepath, 'r') as f:
shutil.copyfileobj(f, response)
</code></pre>
<p>This will not result in very large memory usage, and does not require implemen... | 7 | 2010-03-10T01:35:25Z | [
"python",
"http",
"pylons"
] |
Stream a file to the HTTP response in Pylons | 2,413,707 | <p>I have a Pylons controller action that needs to return a file to the client. (The file is outside the web root, so I can't just link directly to it.) The simplest way is, of course, this:</p>
<pre><code> with open(filepath, 'rb') as f:
response.write(f.read())
</code></pre>
<p>That works, but it's obvio... | 6 | 2010-03-10T00:35:20Z | 2,778,095 | <p>The key here is that WSGI, and pylons by extension, work with iterable responses. So you should be able to write some code like (warning, untested code below!):</p>
<pre><code>def file_streamer():
with open(filepath, 'rb') as f:
while True:
block = f.read(4096)
if not block:
... | 1 | 2010-05-06T02:39:17Z | [
"python",
"http",
"pylons"
] |
Stream a file to the HTTP response in Pylons | 2,413,707 | <p>I have a Pylons controller action that needs to return a file to the client. (The file is outside the web root, so I can't just link directly to it.) The simplest way is, of course, this:</p>
<pre><code> with open(filepath, 'rb') as f:
response.write(f.read())
</code></pre>
<p>That works, but it's obvio... | 6 | 2010-03-10T00:35:20Z | 2,779,020 | <p>I finally got it to work using the <code>FileApp</code> class, thanks to <strong>Chris AtLee</strong> and <strong>THC4k</strong> (from <a href="http://stackoverflow.com/questions/836191/how-can-i-set-a-custom-response-header-for-pylons-static-public-files/837561#837561">this answer</a>). This method also allowed me ... | 5 | 2010-05-06T06:44:58Z | [
"python",
"http",
"pylons"
] |
email MIME Content-Disposition hyperlink | 2,413,734 | <p>Hi i an building an mbox file from a db blob and would like to add an hyperlink to the Attachement header</p>
<p>I am building the header like this</p>
<pre><code>msg=email.message_from_string(blob)
msg["Content-Disposition"]="attachment; filename=filename.txt;"
</code></pre>
<p>What do i need to add to add a htt... | 0 | 2010-03-10T00:41:34Z | 2,413,818 | <p>If the attachment is MIME encoded along with the message, you can't have an http/ftp hyperlink, because the file does not reside on any FTP or HTTP server.</p>
| 1 | 2010-03-10T01:06:08Z | [
"python",
"mime"
] |
email MIME Content-Disposition hyperlink | 2,413,734 | <p>Hi i an building an mbox file from a db blob and would like to add an hyperlink to the Attachement header</p>
<p>I am building the header like this</p>
<pre><code>msg=email.message_from_string(blob)
msg["Content-Disposition"]="attachment; filename=filename.txt;"
</code></pre>
<p>What do i need to add to add a htt... | 0 | 2010-03-10T00:41:34Z | 15,544,720 | <p>There is a way to do what you want. Look at Section 7.3.3 in RFC 1521, which defines the <code>external-body</code> subytpe:</p>
<pre><code>Content-Type: message/external-body;
name="logo.png";
site="ftp.example.com";
access-type=ANON-FTP;
directory="pub";
mod... | 1 | 2013-03-21T10:19:03Z | [
"python",
"mime"
] |
Would it be possible to integrate Python or Perl with Ruby? | 2,413,878 | <p>Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at <a href="http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/" rel="nofollow">http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/</a> and <a href="http://code.google.com/p/ruby-perl/" rel="nofollow">http://code.google.co... | 10 | 2010-03-10T01:20:36Z | 2,414,014 | <p>It might by possible, but not very practical. It would be significantly easier to port whatever modules you need from one to the other than it would be to embed one of the interpreters within the other.</p>
<p>If you absolutely have to use both languages in a project, your best option would probably the combinatio... | 2 | 2010-03-10T01:54:45Z | [
"python",
"ruby",
"perl"
] |
Would it be possible to integrate Python or Perl with Ruby? | 2,413,878 | <p>Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at <a href="http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/" rel="nofollow">http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/</a> and <a href="http://code.google.com/p/ruby-perl/" rel="nofollow">http://code.google.co... | 10 | 2010-03-10T01:20:36Z | 2,414,033 | <p>For a research project I wanted to use the fabulous matplotlib that's available for Python. I also found that library that you referred to. However, it doesn't look like something popular and well tested. So I decided to write the script that generated graphs using pure Python and called it from Ruby via popen. That... | 2 | 2010-03-10T01:59:43Z | [
"python",
"ruby",
"perl"
] |
Would it be possible to integrate Python or Perl with Ruby? | 2,413,878 | <p>Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at <a href="http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/" rel="nofollow">http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/</a> and <a href="http://code.google.com/p/ruby-perl/" rel="nofollow">http://code.google.co... | 10 | 2010-03-10T01:20:36Z | 2,414,056 | <p>My school (Georgia Tech), along with Bryn Mawr and Microsoft Research, are doing a project right now called <a href="http://wiki.roboteducation.org/Pyjama" rel="nofollow">Pyjama</a>. Basically, it uses the Microsoft DLR to allow you to freely mix Python and Ruby. I haven't tried it, but it sounds pretty cool.</p>
<... | 7 | 2010-03-10T02:06:05Z | [
"python",
"ruby",
"perl"
] |
Would it be possible to integrate Python or Perl with Ruby? | 2,413,878 | <p>Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at <a href="http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/" rel="nofollow">http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/</a> and <a href="http://code.google.com/p/ruby-perl/" rel="nofollow">http://code.google.co... | 10 | 2010-03-10T01:20:36Z | 2,414,092 | <p>You can write extensions for Ruby in C. </p>
<p>So, if Python has a C API, you can write a C extension for Ruby which uses this API. </p>
<p>I know nothing about the Python API or how large of a piece you want to integrate with, but if it is not too big, this could (possibly) give you a way to run Python code from... | 2 | 2010-03-10T02:16:42Z | [
"python",
"ruby",
"perl"
] |
Would it be possible to integrate Python or Perl with Ruby? | 2,413,878 | <p>Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at <a href="http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/" rel="nofollow">http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/</a> and <a href="http://code.google.com/p/ruby-perl/" rel="nofollow">http://code.google.co... | 10 | 2010-03-10T01:20:36Z | 2,454,933 | <p>Integrating dynamic languages is one of the goals of the <a href="http://www.parrot.org/" rel="nofollow">Parrot</a> project. It's a virtual machine that dynamic language compilers target. Once compiled to the same virtual machine, you should be able to used the "object" form in any of the languages no matter the obj... | 3 | 2010-03-16T14:05:04Z | [
"python",
"ruby",
"perl"
] |
Would it be possible to integrate Python or Perl with Ruby? | 2,413,878 | <p>Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at <a href="http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/" rel="nofollow">http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/</a> and <a href="http://code.google.com/p/ruby-perl/" rel="nofollow">http://code.google.co... | 10 | 2010-03-10T01:20:36Z | 2,484,435 | <p>Another strategy, as used by Facebook, is to expose APIs via <a href="http://incubator.apache.org/thrift/" rel="nofollow">Thrift</a>. You define lightweight service APIs and the RPCs are inter-process.</p>
| 1 | 2010-03-20T19:36:44Z | [
"python",
"ruby",
"perl"
] |
Python package with compiled code | 2,414,045 | <p>I'm looking into releasing a python package which includes an existing fortran or C program. The fortran/C program is compiled by running</p>
<pre><code>./configure
make
</code></pre>
<p>The python code calls the resulting binary through subprocess calls (i.e. the code is not really wrapped as such). What I would ... | 3 | 2010-03-10T02:02:26Z | 2,414,103 | <p>Don't make this too complex.</p>
<p>Just provide them as separate items with a README that says -- basically -- what you said in the question.</p>
<ol>
<li><p>Build the Fortran/C with <code>./configure; make; make install</code>.</p></li>
<li><p>Setup Python with <code>python setup.py install</code>.</p></li>
</ol... | 2 | 2010-03-10T02:19:03Z | [
"python",
"package"
] |
Python package with compiled code | 2,414,045 | <p>I'm looking into releasing a python package which includes an existing fortran or C program. The fortran/C program is compiled by running</p>
<pre><code>./configure
make
</code></pre>
<p>The python code calls the resulting binary through subprocess calls (i.e. the code is not really wrapped as such). What I would ... | 3 | 2010-03-10T02:02:26Z | 2,414,169 | <p>consider writing a <a href="http://cython.org" rel="nofollow">python C extension</a> as a wrapper for your C code, and a <a href="http://www.scipy.org/F2py" rel="nofollow">f2py</a> extension as a wrapper for your fortran code. Then you can just use them in your python code as fast calls instead of using subprocess.<... | 0 | 2010-03-10T02:44:22Z | [
"python",
"package"
] |
How do I make this sorting case insensitive? | 2,414,201 | <pre><code>def sortProfiles(p):
return sorted(p, key=itemgetter('first_name'))
</code></pre>
<p>I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. </p>
| 2 | 2010-03-10T02:58:29Z | 2,414,252 | <p>Here's a way:</p>
<pre><code>return sorted(p, key=lambda x: x['first_name'].lower())
</code></pre>
| 2 | 2010-03-10T03:10:22Z | [
"python",
"list",
"sorting",
"dictionary"
] |
How do I make this sorting case insensitive? | 2,414,201 | <pre><code>def sortProfiles(p):
return sorted(p, key=itemgetter('first_name'))
</code></pre>
<p>I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. </p>
| 2 | 2010-03-10T02:58:29Z | 2,414,253 | <pre><code>>>> from operator import itemgetter
>>> p = [{'fn':'bill'}, {'fn':'Bob'}, {'fn':'bobby'}]
>>> sorted(p, key=itemgetter('fn'))
[{'fn': 'Bob'}, {'fn': 'bill'}, {'fn': 'bobby'}]
>>> sorted(p, key=lambda x: x['fn'].lower())
[{'fn': 'bill'}, {'fn': 'Bob'}, {'fn': 'bobby'}]
>... | 7 | 2010-03-10T03:10:24Z | [
"python",
"list",
"sorting",
"dictionary"
] |
How do I make this sorting case insensitive? | 2,414,201 | <pre><code>def sortProfiles(p):
return sorted(p, key=itemgetter('first_name'))
</code></pre>
<p>I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. </p>
| 2 | 2010-03-10T02:58:29Z | 2,414,255 | <p>It looks like you want <code>sorted(p, key=lambda d: d['first_name'].lower())</code>.</p>
| 1 | 2010-03-10T03:10:39Z | [
"python",
"list",
"sorting",
"dictionary"
] |
How do I make this sorting case insensitive? | 2,414,201 | <pre><code>def sortProfiles(p):
return sorted(p, key=itemgetter('first_name'))
</code></pre>
<p>I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. </p>
| 2 | 2010-03-10T02:58:29Z | 2,414,260 | <pre><code>>>> def my_itemgetter(attr):
def get_attr(obj):
return obj.get(attr, "").lower()
return get_attr
>>> a= [{"a":"dA"},{"a":"ab"},{"a":"Ac"},{"a":"aa"}]
>>> sorted(a, key=my_itemgetter("a"))
[{'a': 'aa'}, {'a': 'ab'}, {'a': 'Ac'}, {'a': 'dA'}]
</code></pre... | 0 | 2010-03-10T03:11:55Z | [
"python",
"list",
"sorting",
"dictionary"
] |
How do I make this sorting case insensitive? | 2,414,201 | <pre><code>def sortProfiles(p):
return sorted(p, key=itemgetter('first_name'))
</code></pre>
<p>I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. </p>
| 2 | 2010-03-10T02:58:29Z | 2,414,269 | <pre><code>def sortProfiles(p):
return sorted(p, key=lambda el: el['first_name'].lower())
</code></pre>
| 1 | 2010-03-10T03:13:26Z | [
"python",
"list",
"sorting",
"dictionary"
] |
How do I make this sorting case insensitive? | 2,414,201 | <pre><code>def sortProfiles(p):
return sorted(p, key=itemgetter('first_name'))
</code></pre>
<p>I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. </p>
| 2 | 2010-03-10T02:58:29Z | 2,414,277 | <p>If you dislike <code>lambda</code>, you can use a named function as your key-extractor, e.g:</p>
<pre><code>def sortProfiles(p):
def lowerName(d):
return d['first_name'].lower()
return sorted(p, key=lowerName)
</code></pre>
<p>The <code>def</code> statement can appear just about anywhere another st... | 0 | 2010-03-10T03:15:30Z | [
"python",
"list",
"sorting",
"dictionary"
] |
How do I do this "order by" in Django, if I have foreign keys? | 2,414,369 | <p>Suppose my model is this:</p>
<pre><code>class Ego(models.Model):
event = models.ForeignKey(Event)
user = models.ForeignKey(User)
</code></pre>
<p>As you can see, this table has 2 columns, and they're both foreign keys.
How do I "order by" User.first_name? </p>
<p>Is this it? But it doesn't look like it.<... | 1 | 2010-03-10T03:42:23Z | 2,414,505 | <p>Solved.</p>
<p>I did this:</p>
<pre><code>Ego.objects.all().select_related.order_by("auth_user.first_name")
</code></pre>
| 3 | 2010-03-10T04:25:47Z | [
"python",
"mysql",
"database",
"django"
] |
Creating subtree from tree which is represented in xml - python | 2,414,458 | <p>I have an XML (in the form of tree), I require to create sub-tree out of it.</p>
<p>For ex:</p>
<pre><code><a>
<b>
<c>Hello</c>
<d>
<e>Hi</e>
</a>
</code></pre>
<p>Subtree would be </p>
<pre><code><root>
<a>
<b>
<c>Hello<... | 0 | 2010-03-10T04:12:28Z | 2,414,499 | <p><a href="http://docs.python.org/library/xml.etree.elementtree.html?highlight=etree#module-xml.etree.ElementTree" rel="nofollow">ElementTree</a> is good and simple for both "reading" and "writing".</p>
<p>Your first XML example (I edited your question just to add formatting so it would be readable!) is invalid, I as... | 3 | 2010-03-10T04:24:44Z | [
"python",
"xml",
"parsing",
"tree",
"subtree"
] |
How regex a empty string in python? | 2,414,472 | <p>I want that find empty tags, here is a example </p>
<pre><code>txt ="<lol1><><lol2>"
rgx = "<([a-zA-Z_0-9]+)>"
print re.findall(rgex, txt)
</code></pre>
<p>I get this</p>
<pre><code>['lol1', 'lol2']
</code></pre>
<p>I want</p>
<pre><code>['lol1', '', 'lol2']
</code></pre>
<p>How I can... | 0 | 2010-03-10T04:17:39Z | 2,414,485 | <p>Use <code>rgx = "<([a-zA-Z_0-9]*)>"</code></p>
<p>The key point is using <code>*</code>, which means "zero or more of the preceding", where you're using <code>+</code>, which means "one or more".</p>
| 7 | 2010-03-10T04:20:14Z | [
"python",
"regex"
] |
How regex a empty string in python? | 2,414,472 | <p>I want that find empty tags, here is a example </p>
<pre><code>txt ="<lol1><><lol2>"
rgx = "<([a-zA-Z_0-9]+)>"
print re.findall(rgex, txt)
</code></pre>
<p>I get this</p>
<pre><code>['lol1', 'lol2']
</code></pre>
<p>I want</p>
<pre><code>['lol1', '', 'lol2']
</code></pre>
<p>How I can... | 0 | 2010-03-10T04:17:39Z | 2,414,495 | <p>no need regex</p>
<pre><code>>>> s="txt ="<lol1><><lol2>"
>>> for i in txt.split(">"):
... if "<" in i:
... print i[i.find("<")+1:]
...
lol1
lol2
>>> [i[i.find("<")+1:] for i in txt.split(">") if "<" in i ]
['lol1', '', 'lol2']
</code></pre>... | 0 | 2010-03-10T04:23:02Z | [
"python",
"regex"
] |
How to make script/program to make it so an application is always running? | 2,414,616 | <p>I have a simple .exe that needs to be running continuously.</p>
<p>Unfortunately, sometimes it crashes unexpectedly, and there's nothing that can be done for this.</p>
<p>I'm thinking of like a C# program that scans the running application tree on a timer and if the process stops running it re-launches it... ? No... | 0 | 2010-03-10T04:56:22Z | 2,414,634 | <p>easiest way is to have you program see if an instance of itself is running and exit if it is. Set up a scheduled task to run it every couple of minutes.</p>
<pre><code>class Program
{
static void Main(string[] args)
{
if (IsRunning())
{
return;
}
else
{
... | 0 | 2010-03-10T05:01:15Z | [
"c#",
"c++",
"python"
] |
How to make script/program to make it so an application is always running? | 2,414,616 | <p>I have a simple .exe that needs to be running continuously.</p>
<p>Unfortunately, sometimes it crashes unexpectedly, and there's nothing that can be done for this.</p>
<p>I'm thinking of like a C# program that scans the running application tree on a timer and if the process stops running it re-launches it... ? No... | 0 | 2010-03-10T04:56:22Z | 2,414,661 | <p>It's fairly easy to do that, but the "crashes unexpectedly, and there's nothing that can be done for this" sounds highly suspect to me. Perhaps you mean the program in question is from a third party, and you need to work around problems they can't/won't fix?</p>
<p>In any case, there's quite a bit of <a href="http:... | 2 | 2010-03-10T05:07:45Z | [
"c#",
"c++",
"python"
] |
How to make script/program to make it so an application is always running? | 2,414,616 | <p>I have a simple .exe that needs to be running continuously.</p>
<p>Unfortunately, sometimes it crashes unexpectedly, and there's nothing that can be done for this.</p>
<p>I'm thinking of like a C# program that scans the running application tree on a timer and if the process stops running it re-launches it... ? No... | 0 | 2010-03-10T04:56:22Z | 2,414,677 | <p>The first solution would be to fix your EXE, so it does not crash. If you can not fix it now, you probably need to add exception handling, so you can catch the exception, and not close the EXE.</p>
<p>Second solution is to write simple guard programm that will start your simple .exe and will monitor specific proces... | 1 | 2010-03-10T05:12:03Z | [
"c#",
"c++",
"python"
] |
How to make script/program to make it so an application is always running? | 2,414,616 | <p>I have a simple .exe that needs to be running continuously.</p>
<p>Unfortunately, sometimes it crashes unexpectedly, and there's nothing that can be done for this.</p>
<p>I'm thinking of like a C# program that scans the running application tree on a timer and if the process stops running it re-launches it... ? No... | 0 | 2010-03-10T04:56:22Z | 2,414,689 | <p>One trick occasionally employed by malware in days past was to have two processes that each monitor the currently running processes and restart the other process if it is terminated.</p>
<p>The System.Diagnostics namespace has classes which can help, particularly "Process".</p>
<p>For example</p>
<pre><code>stati... | 0 | 2010-03-10T05:14:33Z | [
"c#",
"c++",
"python"
] |
How to make script/program to make it so an application is always running? | 2,414,616 | <p>I have a simple .exe that needs to be running continuously.</p>
<p>Unfortunately, sometimes it crashes unexpectedly, and there's nothing that can be done for this.</p>
<p>I'm thinking of like a C# program that scans the running application tree on a timer and if the process stops running it re-launches it... ? No... | 0 | 2010-03-10T04:56:22Z | 2,415,378 | <p>Your program needs to initially start your target process itself (with <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx" rel="nofollow">Process.Start</a>), then simply wait for it to terminate (with <a href="http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx" rel="nofollow">W... | 0 | 2010-03-10T08:18:17Z | [
"c#",
"c++",
"python"
] |
Error installing MySQL-python on MAC Snow Leopard, OS 10.6 | 2,414,658 | <p>I am trying to install the MySQL-python on MAC OS 10.6 (Snow leopard, 64 bit). I followed the steps:
1. Installed MySQL for Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive.
2. Downloaded MySQL-python-1.2.3c1.tar.gz and unzipped it
3. CD to MySQL-python-1.2.3c1 and built it as:
ARCHFLAGS="-arch x86_64" python setup.... | 0 | 2010-03-10T05:06:51Z | 2,420,149 | <p>The python 2.6.4 you are using is 32-bit only (definitely true if you downloaded the OS X installer from python.org). You can't override the architecture for extension modules; they have to be compatible with the base python. The <code>10.3</code> shows up because the python you are using was built with a deployme... | 1 | 2010-03-10T20:03:09Z | [
"python",
"mysql",
"osx"
] |
Python string class like StringBuilder in C#? | 2,414,667 | <p>Is there some string class in Python like <code>StringBuilder</code> in C#?</p>
| 43 | 2010-03-10T05:08:42Z | 2,414,673 | <p>you can try <a href="http://docs.python.org/library/stringio.html" rel="nofollow">StringIO</a> or <a href="http://www.python.org/doc/2.5.2/lib/module-cStringIO.html" rel="nofollow">cStringIO</a></p>
| 3 | 2010-03-10T05:11:08Z | [
"python",
"string"
] |
Python string class like StringBuilder in C#? | 2,414,667 | <p>Is there some string class in Python like <code>StringBuilder</code> in C#?</p>
| 43 | 2010-03-10T05:08:42Z | 2,414,675 | <p>There is no one-to-one correlation. For a really good article please see <a href="https://waymoot.org/home/python_string/">Efficient String Concatenation in Python</a>:</p>
<blockquote>
<p>Building long strings in the Python
progamming language can sometimes
result in very slow running code. In
this articl... | 37 | 2010-03-10T05:11:29Z | [
"python",
"string"
] |
Python string class like StringBuilder in C#? | 2,414,667 | <p>Is there some string class in Python like <code>StringBuilder</code> in C#?</p>
| 43 | 2010-03-10T05:08:42Z | 2,414,916 | <p>Python has several things that fulfill similar purposes: </p>
<ul>
<li>One common way to build large strings from pieces is to grow a list of strings and join it when you are done. This is a frequently-used Python idiom.
<ul>
<li>To build strings incorporating data with formatting, you would do the formatting separ... | 7 | 2010-03-10T06:21:54Z | [
"python",
"string"
] |
Python string class like StringBuilder in C#? | 2,414,667 | <p>Is there some string class in Python like <code>StringBuilder</code> in C#?</p>
| 43 | 2010-03-10T05:08:42Z | 13,345,099 | <p>I have used the code of Oliver Crow (link given by Andrew Hare) and adapted it a bit to tailor Python 2.7.3. (by using timeit package). I ran on my personal computer, Lenovo T61, 6GB RAM, Debian GNU/Linux 6.0.6 (squeeze). </p>
<p>Here is the result for 10,000 iterations:</p>
<pre>
method1: 0.0538418292999 secs
pr... | 19 | 2012-11-12T14:02:54Z | [
"python",
"string"
] |
Python string class like StringBuilder in C#? | 2,414,667 | <p>Is there some string class in Python like <code>StringBuilder</code> in C#?</p>
| 43 | 2010-03-10T05:08:42Z | 19,742,456 | <p>Using method 5 from above (The Pseudo File) we can get very good perf and flexibility</p>
<pre><code>from cStringIO import StringIO
class StringBuilder:
_file_str = None
def __init__(self):
self._file_str = StringIO()
def Append(self, str):
self._file_str.write(str)
def __s... | 7 | 2013-11-02T13:37:50Z | [
"python",
"string"
] |
Python string class like StringBuilder in C#? | 2,414,667 | <p>Is there some string class in Python like <code>StringBuilder</code> in C#?</p>
| 43 | 2010-03-10T05:08:42Z | 34,549,932 | <p>No need for StringBuilder in python. Simple concatenation works just as well without the performance penalty seen in C#.</p>
<pre><code>resultString = ""
resultString += "Append 1"
resultString += "Append 2"
</code></pre>
<p>See <a href="http://stackoverflow.com/a/13345099/407108">Antoine-tran's answer</a> for pe... | 0 | 2015-12-31T17:52:09Z | [
"python",
"string"
] |
Python string class like StringBuilder in C#? | 2,414,667 | <p>Is there some string class in Python like <code>StringBuilder</code> in C#?</p>
| 43 | 2010-03-10T05:08:42Z | 36,556,380 | <p>Relying on compiler optimizations is fragile. The benchmarks linked in the accepted answer and numbers given by Antoine-tran are not to be trusted. Andrew Hare makes the mistake of including a call to <code>repr</code> in his methods. That slows all the methods equally but obscures the real penalty in constructing t... | 2 | 2016-04-11T18:26:09Z | [
"python",
"string"
] |
Sort by key of dictionary inside a dictionary in Python | 2,414,763 | <p>How to sort the following dictionary by the value of "remaining_pcs" or "discount_ratio"?</p>
<pre><code>promotion_items = {
'one': {'remaining_pcs': 100, 'discount_ratio': 10},
'two': {'remaining_pcs': 200, 'discount_ratio': 20},
}
</code></pre>
<p><strong>EDIT</strong></p>
<p>What I mean is getting a so... | 4 | 2010-03-10T05:36:20Z | 2,414,776 | <p>Please see <a href="http://code.activestate.com/recipes/52306-to-sort-a-dictionary/" rel="nofollow">To sort a dictionary</a>:</p>
<blockquote>
<p>Dictionaries can't be sorted -- a
mapping has no ordering! -- so, when
you feel the need to sort one, you no
doubt want to sort its keys (in a
separate list).</... | 2 | 2010-03-10T05:39:30Z | [
"python",
"dictionary",
"sorting"
] |
Sort by key of dictionary inside a dictionary in Python | 2,414,763 | <p>How to sort the following dictionary by the value of "remaining_pcs" or "discount_ratio"?</p>
<pre><code>promotion_items = {
'one': {'remaining_pcs': 100, 'discount_ratio': 10},
'two': {'remaining_pcs': 200, 'discount_ratio': 20},
}
</code></pre>
<p><strong>EDIT</strong></p>
<p>What I mean is getting a so... | 4 | 2010-03-10T05:36:20Z | 2,414,790 | <p>If <code>'remaining_pcs'</code> and <code>'discount_ratio'</code> are the only keys in the nested dictionaries then:</p>
<pre><code>result = sorted(promotion_items.iteritems(), key=lambda pair: pair[1].items())
</code></pre>
<p>If there could be other keys then:</p>
<pre><code>def item_value(pair):
return pai... | 0 | 2010-03-10T05:43:41Z | [
"python",
"dictionary",
"sorting"
] |
Sort by key of dictionary inside a dictionary in Python | 2,414,763 | <p>How to sort the following dictionary by the value of "remaining_pcs" or "discount_ratio"?</p>
<pre><code>promotion_items = {
'one': {'remaining_pcs': 100, 'discount_ratio': 10},
'two': {'remaining_pcs': 200, 'discount_ratio': 20},
}
</code></pre>
<p><strong>EDIT</strong></p>
<p>What I mean is getting a so... | 4 | 2010-03-10T05:36:20Z | 2,414,795 | <p>You can only sort the <em>keys</em> (or items or values) of a dictionary, into a separate list (as I wrote years ago in the recipe that @Andrew's quoting). E.g., to sort keys according to your stated criteria:</p>
<pre><code>promotion_items = {
'one': {'remaining_pcs': 100, 'discount_ratio': 10},
'two': {'r... | 5 | 2010-03-10T05:44:20Z | [
"python",
"dictionary",
"sorting"
] |
Concepts and tools required to scale up algorithms | 2,414,915 | <p>I'd like to begin thinking about how I can scale up my algorithms that I write for data analysis so that they can be applied to arbitrarily large sets of data. I wonder what are the relevant concepts (threads, concurrency, immutable data structures, recursion) and tools (Hadoop/MapReduce, Terracota, and Eucalyptus) ... | 5 | 2010-03-10T06:21:50Z | 2,414,986 | <p>The main thing for scaling up to large data is to avoid situations where you're reading huge datasets into memory at once. In pythonic terms this generally means using iterators to consume the dataset in manageable pieces.</p>
| 3 | 2010-03-10T06:40:39Z | [
"python",
"multithreading",
"concurrency",
"hadoop"
] |
Concepts and tools required to scale up algorithms | 2,414,915 | <p>I'd like to begin thinking about how I can scale up my algorithms that I write for data analysis so that they can be applied to arbitrarily large sets of data. I wonder what are the relevant concepts (threads, concurrency, immutable data structures, recursion) and tools (Hadoop/MapReduce, Terracota, and Eucalyptus) ... | 5 | 2010-03-10T06:21:50Z | 2,415,028 | <p>While languages and associated technologies/frameworks are important for scaling, they tend to pale in comparison to the importance of the algorithms, data structure, and architectures. Forget threads: the number of cores you can exploit that way is just too limited -- you want separate processes exchanging message... | 9 | 2010-03-10T06:49:57Z | [
"python",
"multithreading",
"concurrency",
"hadoop"
] |
What is the fastest way to check whether a folder size is greater than a specific size? | 2,414,917 | <p>What will be the fastest way to check whether a folder size is beyond a specific size say 10 MB, 1 Gb , 10 GB etc, without actually calculating the folder size. Something like quota. A Pythonic solution will be great, but standard UNIX utilities also welcome</p>
| 2 | 2010-03-10T06:21:59Z | 2,414,931 | <p>Folder size is still the total size of the folder contents.</p>
<p>You may try to call <code>du -s foldername</code> from python</p>
| 1 | 2010-03-10T06:24:10Z | [
"python",
"linux",
"shell"
] |
What is the fastest way to check whether a folder size is greater than a specific size? | 2,414,917 | <p>What will be the fastest way to check whether a folder size is beyond a specific size say 10 MB, 1 Gb , 10 GB etc, without actually calculating the folder size. Something like quota. A Pythonic solution will be great, but standard UNIX utilities also welcome</p>
| 2 | 2010-03-10T06:21:59Z | 2,414,949 | <p>I'd have to say it's impossible. I don't believe any filesystems cache folder sizes. Whatever you do is going to have to walk the tree in some fashion or another. Using <code>du</code> is probably the fastest method since it's all going to be happening in C.</p>
<p>If you know the maximum filesize expected or suppo... | 2 | 2010-03-10T06:27:33Z | [
"python",
"linux",
"shell"
] |
What is the fastest way to check whether a folder size is greater than a specific size? | 2,414,917 | <p>What will be the fastest way to check whether a folder size is beyond a specific size say 10 MB, 1 Gb , 10 GB etc, without actually calculating the folder size. Something like quota. A Pythonic solution will be great, but standard UNIX utilities also welcome</p>
| 2 | 2010-03-10T06:21:59Z | 2,414,977 | <p>you can use <code>du -sb</code>, which still have to calculate folder size .eg</p>
<pre><code>threshold=1024000 #bytes
path="/your/path"
s=$(du -sb "$path")
set -- $s
size=$1
if [ "$size" -gt $threshold ];then
echo "size of $path greater than $threshold"
fi
</code></pre>
| 2 | 2010-03-10T06:37:57Z | [
"python",
"linux",
"shell"
] |
What is the fastest way to check whether a folder size is greater than a specific size? | 2,414,917 | <p>What will be the fastest way to check whether a folder size is beyond a specific size say 10 MB, 1 Gb , 10 GB etc, without actually calculating the folder size. Something like quota. A Pythonic solution will be great, but standard UNIX utilities also welcome</p>
| 2 | 2010-03-10T06:21:59Z | 2,415,043 | <pre><code>import os
from os.path import join, getsize
def getsize_limited(directory, limit):
total_size = 0
for root, dirs, files in os.walk(directory, topdown=False):
for name in files:
total_size += getsize(join(root, name))
if total_size > limit:
... | 4 | 2010-03-10T06:52:52Z | [
"python",
"linux",
"shell"
] |
Remove HTML tags in AppEngine Python Env (equivalent to Ruby's Sanitize) | 2,415,008 | <p>I am looking for a python module that will help me get rid of HTML tags but keep the text values. I tried BeautifulSoup before and I couldn't figure out how to do this simple task. I tried searching for Python modules that could do this but they all seem to be dependent on other libraries which does not work well on... | 1 | 2010-03-10T06:44:39Z | 2,415,073 | <p>Using lxml:</p>
<pre><code>htmlstring = '<b><a href="http://foo.com/">foo</a></b><img src="http://foo.com/bar.jpg" />'
from lxml.html import fromstring
mySearchTree = fromstring(htmlstring)
for item in mySearchTree.cssselect('a'):
print item.text
</code></pre>
| 1 | 2010-03-10T06:59:10Z | [
"python",
"google-app-engine",
"html-sanitizing"
] |
Remove HTML tags in AppEngine Python Env (equivalent to Ruby's Sanitize) | 2,415,008 | <p>I am looking for a python module that will help me get rid of HTML tags but keep the text values. I tried BeautifulSoup before and I couldn't figure out how to do this simple task. I tried searching for Python modules that could do this but they all seem to be dependent on other libraries which does not work well on... | 1 | 2010-03-10T06:44:39Z | 2,415,076 | <pre><code>>>> import BeautifulSoup
>>> html = '<b><a href="http://foo.com/">foo</a></b><img src="http://foo.com/bar.jpg" />'
>>> bs = BeautifulSoup.BeautifulSoup(html)
>>> bs.findAll(text=True)
[u'foo']
</code></pre>
<p>This gives you a list of (Unic... | 5 | 2010-03-10T06:59:51Z | [
"python",
"google-app-engine",
"html-sanitizing"
] |
Remove HTML tags in AppEngine Python Env (equivalent to Ruby's Sanitize) | 2,415,008 | <p>I am looking for a python module that will help me get rid of HTML tags but keep the text values. I tried BeautifulSoup before and I couldn't figure out how to do this simple task. I tried searching for Python modules that could do this but they all seem to be dependent on other libraries which does not work well on... | 1 | 2010-03-10T06:44:39Z | 2,415,078 | <pre><code>#!/usr/bin/python
from xml.dom.minidom import parseString
def getText(el):
ret = ''
for child in el.childNodes:
if child.nodeType == 3:
ret += child.nodeValue
else:
ret += getText(child)
return ret
html = '<b>this is <a href="http://foo.com/">... | 1 | 2010-03-10T07:00:52Z | [
"python",
"google-app-engine",
"html-sanitizing"
] |
Remove HTML tags in AppEngine Python Env (equivalent to Ruby's Sanitize) | 2,415,008 | <p>I am looking for a python module that will help me get rid of HTML tags but keep the text values. I tried BeautifulSoup before and I couldn't figure out how to do this simple task. I tried searching for Python modules that could do this but they all seem to be dependent on other libraries which does not work well on... | 1 | 2010-03-10T06:44:39Z | 2,418,708 | <p>If you don't want to use separate libs then you can import standard django utils. For example:</p>
<pre><code>from django.utils.html import strip_tags
html = '<b><a href="http://foo.com/">foo</a></b><img src="http://foo.com/bar.jpg'
stripped = strip_tags(html)
print stripped
# you got: f... | 4 | 2010-03-10T16:42:27Z | [
"python",
"google-app-engine",
"html-sanitizing"
] |
Remove HTML tags in AppEngine Python Env (equivalent to Ruby's Sanitize) | 2,415,008 | <p>I am looking for a python module that will help me get rid of HTML tags but keep the text values. I tried BeautifulSoup before and I couldn't figure out how to do this simple task. I tried searching for Python modules that could do this but they all seem to be dependent on other libraries which does not work well on... | 1 | 2010-03-10T06:44:39Z | 20,329,524 | <p>Late, but.</p>
<p>You can use Jinja2.Markup()</p>
<p><a href="http://jinja.pocoo.org/docs/api/#jinja2.Markup.striptags" rel="nofollow">http://jinja.pocoo.org/docs/api/#jinja2.Markup.striptags</a></p>
<pre><code>from jinja2 import Markup
Markup("<div>About</div>").striptags()
u'About'
</code></pre>
| 1 | 2013-12-02T13:29:47Z | [
"python",
"google-app-engine",
"html-sanitizing"
] |
Add directory to PYTHONPATH ( multiple drives ), for auto-complete | 2,415,014 | <p>I have 2 hard-drives, <code>C:\</code> and <code>D:\</code></p>
<p>Django imports correctly (which is in my <code>C</code> drive), but my application is on my <code>D</code> drive. I can't move it to the <code>C</code> drive because of some back-up software I'm running/</p>
<p>I'm trying to get auto-complete to wo... | 1 | 2010-03-10T06:45:52Z | 2,415,055 | <p>Have you tried adding <em>Additional import directories</em> in <strong>Edit/Preferences/</strong> under <strong>Languages/Python</strong> in Komodo?</p>
<p><strong>Edit</strong>: I think you can also add a .pth file in [komodo-install-dir]/lib/mozilla/python/ or C:\[PythonVersion]\Lib\site-packages\ containing all... | 2 | 2010-03-10T06:56:06Z | [
"python",
"autocomplete",
"pythonpath"
] |
Find element with attribute with minidom | 2,415,115 | <p>Given </p>
<pre><code><field name="frame.time_delta_displayed" showname="Time delta from previous displayed frame: 0.000008000 seconds" size="0" pos="0" show="0.000008000"/>
<field name="frame.time_relative" showname="Time since reference or first frame: 0.000008000 seconds" size="0" pos="0" show="0.000008... | 8 | 2010-03-10T07:11:21Z | 2,415,148 | <p>You don't -- the <a href="http://docs.python.org/library/xml.dom.html" rel="nofollow">DOM API</a>, somewhat poorly designed (by w3c, not by Python!-) doesn't have such a search function to do the iteration for you. Either accept the need to loop (not through <strong>every</strong> tag in general, but through all wit... | 2 | 2010-03-10T07:18:37Z | [
"python",
"xml",
"minidom"
] |
Find element with attribute with minidom | 2,415,115 | <p>Given </p>
<pre><code><field name="frame.time_delta_displayed" showname="Time delta from previous displayed frame: 0.000008000 seconds" size="0" pos="0" show="0.000008000"/>
<field name="frame.time_relative" showname="Time since reference or first frame: 0.000008000 seconds" size="0" pos="0" show="0.000008... | 8 | 2010-03-10T07:11:21Z | 2,415,154 | <p>I don't think you can. </p>
<p>From the parent <code>element</code>, you need to </p>
<pre><code>for subelement in element.GetElementsByTagName("field"):
if subelement.hasAttribute("frame.len"):
do_something()
</code></pre>
<p>Reacting to your comment from March 11, if the structure of your documents ... | 12 | 2010-03-10T07:19:52Z | [
"python",
"xml",
"minidom"
] |
Find element with attribute with minidom | 2,415,115 | <p>Given </p>
<pre><code><field name="frame.time_delta_displayed" showname="Time delta from previous displayed frame: 0.000008000 seconds" size="0" pos="0" show="0.000008000"/>
<field name="frame.time_relative" showname="Time since reference or first frame: 0.000008000 seconds" size="0" pos="0" show="0.000008... | 8 | 2010-03-10T07:11:21Z | 38,566,214 | <p>Wow, that regex is horrible! As of 2016, there is a <code>.getAttribute()</code> method for each <code>DOMElement</code> that makes things a bit easier, but you still have to iterate through the elements.</p>
<pre><code>l = []
for e in elements:
if e.hasAttribute('name') and e.getAttribute('name') == 'field.len... | 0 | 2016-07-25T11:11:46Z | [
"python",
"xml",
"minidom"
] |
How to install python modules and dependents easily? | 2,415,166 | <p>Are there any easy installation tools like "perl -MCPAN -e shell;" to install python modules and its dependents???</p>
| 4 | 2010-03-10T07:21:49Z | 2,415,187 | <p><a href="http://pip.openplans.org/">pip</a> is the most up to date tool to do this: you use it by issuing the command
<code>pip install <packagename></code></p>
<p>The "old" way of doing the same is to easy_install:</p>
<pre><code>easy_install <packagename>
</code></pre>
<p>If you have <code>easy_ins... | 6 | 2010-03-10T07:25:52Z | [
"python"
] |
python ConfigParser module | 2,415,586 | <p>I have the following ini file</p>
<pre><code>[Section]
value=test
</code></pre>
<p>When i use the ConfigParser Module :</p>
<pre><code>import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.ini')
str=config.get('Section', 'value')
if str == 'test':
print 1
else :
print 0
</code></p... | 0 | 2010-03-10T09:03:57Z | 2,415,620 | <p>try </p>
<pre><code>print str
</code></pre>
<p>and see what the value is.</p>
| 0 | 2010-03-10T09:09:10Z | [
"python",
"configparser"
] |
"Broken" unicode strings encoded in UTF-8? | 2,415,628 | <p>I have been studying unicode and its Python implementation now for two days, and I think I'm getting a glimpse of what it is about. Just to get confident, I'm asking if my assumptions for my current problems are correct.</p>
<p>In Django, forms give me unicode strings which I suspect to be "broken". Unicode strings... | 3 | 2010-03-10T09:10:26Z | 2,415,707 | <p><code>u'f\xa4hre'</code>is a unicode string, not encoded as anything. The unicode codepoint <code>0xa4</code> is the character <code>ä</code>. It is not really important that <code>ä</code> would also be encoded as byte <code>0xa4</code> in ISO-8859-1.</p>
<p>The unicode string can contain any unicode characters ... | 4 | 2010-03-10T09:24:04Z | [
"python",
"django",
"unicode",
"utf-8"
] |
"Broken" unicode strings encoded in UTF-8? | 2,415,628 | <p>I have been studying unicode and its Python implementation now for two days, and I think I'm getting a glimpse of what it is about. Just to get confident, I'm asking if my assumptions for my current problems are correct.</p>
<p>In Django, forms give me unicode strings which I suspect to be "broken". Unicode strings... | 3 | 2010-03-10T09:10:26Z | 2,415,719 | <p>Not exactly: after having been decoded, the unicode string is <em>unicode</em> which means, it may contain characters with codes beyond 255. How the interpreter represents these depends on the platform, but usually nowadays it uses character elements with a width of at least 16 bits. ISO-8859-1 is a proper subset of... | 1 | 2010-03-10T09:25:00Z | [
"python",
"django",
"unicode",
"utf-8"
] |
SQLAlchemy with multiple primary keys does not automatically set any | 2,415,842 | <p>I had a simple table:</p>
<pre><code>class test(Base):
__tablename__ = 'test'
id = Column(Integer, primary_key=True)
title = Column(String)
def __init__(self, title):
self.title = title
</code></pre>
<p>When using this table, id was set automatically. I want to add another field that is u... | 3 | 2010-03-10T09:46:21Z | 2,416,131 | <p>I have few problems here</p>
<p>1) What is a purpose of your hand-made <code>__init__</code>? If it does just what you wrote, you can omit constructor completely since SQLAlchemy machinery generates exactly the same constructor for all your models automagically. Although if you take some additional actions and thus... | 6 | 2010-03-10T10:35:17Z | [
"python",
"database",
"sqlalchemy",
"primary-key"
] |
please expain wx.grid.Grid.create() | 2,415,854 | <p>can any one please expain me the functionality of this function</p>
<pre><code>wx.grid.Grid.create()
</code></pre>
<p>i created a frame and inside that i create a grid using this function</p>
<p>every thing is fine but while closing that frame my whole application is closing </p>
<p>while closing i just need to ... | 0 | 2010-03-10T09:48:39Z | 2,415,901 | <p>Are you using <code>self.Destroy()</code>? If so, try <code>self.Close()</code> instead.</p>
<p>or bind <code>wx.EVT_CLOSE</code> to your custom close function</p>
<pre><code>self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self,event):
//do anything here
</code></pre>
| 0 | 2010-03-10T09:57:57Z | [
"python",
"wxpython"
] |
please expain wx.grid.Grid.create() | 2,415,854 | <p>can any one please expain me the functionality of this function</p>
<pre><code>wx.grid.Grid.create()
</code></pre>
<p>i created a frame and inside that i create a grid using this function</p>
<p>every thing is fine but while closing that frame my whole application is closing </p>
<p>while closing i just need to ... | 0 | 2010-03-10T09:48:39Z | 3,282,130 | <p>If the frame with the grid in it is the only top-level window, then closing it will close your application. If you close the only frame in any program, how would you open another? There's nothing left to click on.</p>
<hr>
<p>Mike Driscoll</p>
<p>Blog: <a href="http://blog.pythonlibrary.org" rel="nofollow">http... | 0 | 2010-07-19T14:46:49Z | [
"python",
"wxpython"
] |
Iterating through two lists in Django templates | 2,415,865 | <p>I want to do the below list iteration in django templates:</p>
<pre><code>foo = ['foo', 'bar'];
moo = ['moo', 'loo'];
for (a, b) in zip(foo, moo):
print a, b
</code></pre>
<p>django code:</p>
<pre><code>{%for a, b in zip(foo, moo)%}
{{a}}
{{b}}
{%endfor%}
</code></pre>
<p>I get the below error when I tr... | 18 | 2010-03-10T09:51:09Z | 2,415,934 | <p>It's possible to do</p>
<pre><code>{% for ab in mylist %}
{{ab.0}}
{{ab.1}}
{% endfor %}
</code></pre>
<p>but you cannot make a call to <code>zip</code> within the <code>for</code> structure. You'll have to store the zipped list in another variable first, then iterate over it.</p>
| 9 | 2010-03-10T10:02:28Z | [
"python",
"django",
"django-templates"
] |
Iterating through two lists in Django templates | 2,415,865 | <p>I want to do the below list iteration in django templates:</p>
<pre><code>foo = ['foo', 'bar'];
moo = ['moo', 'loo'];
for (a, b) in zip(foo, moo):
print a, b
</code></pre>
<p>django code:</p>
<pre><code>{%for a, b in zip(foo, moo)%}
{{a}}
{{b}}
{%endfor%}
</code></pre>
<p>I get the below error when I tr... | 18 | 2010-03-10T09:51:09Z | 4,238,261 | <p>You can use a zip in your view:</p>
<pre><code>list = zip(list1, list2)
return render_to_response('template.html', {'list': list, ... }
</code></pre>
<p>and in your template use</p>
<pre><code>{% for item1, item2 in list %}
</code></pre>
<p>to iterate through both lists.</p>
| 30 | 2010-11-21T14:09:58Z | [
"python",
"django",
"django-templates"
] |
Iterating through two lists in Django templates | 2,415,865 | <p>I want to do the below list iteration in django templates:</p>
<pre><code>foo = ['foo', 'bar'];
moo = ['moo', 'loo'];
for (a, b) in zip(foo, moo):
print a, b
</code></pre>
<p>django code:</p>
<pre><code>{%for a, b in zip(foo, moo)%}
{{a}}
{{b}}
{%endfor%}
</code></pre>
<p>I get the below error when I tr... | 18 | 2010-03-10T09:51:09Z | 4,731,704 | <p>I built <a href="https://github.com/gabrielgrant/django-multiforloop" rel="nofollow">django-multiforloop</a> to solve this problem. From the README:</p>
<p>With django-multiforloop installed, rendering this template</p>
<pre><code>{% for x in x_list; y in y_list %}
{{ x }}:{{ y }}
{% endfor %}
</code></pre>
<p>... | 4 | 2011-01-19T04:23:19Z | [
"python",
"django",
"django-templates"
] |
Iterating through two lists in Django templates | 2,415,865 | <p>I want to do the below list iteration in django templates:</p>
<pre><code>foo = ['foo', 'bar'];
moo = ['moo', 'loo'];
for (a, b) in zip(foo, moo):
print a, b
</code></pre>
<p>django code:</p>
<pre><code>{%for a, b in zip(foo, moo)%}
{{a}}
{{b}}
{%endfor%}
</code></pre>
<p>I get the below error when I tr... | 18 | 2010-03-10T09:51:09Z | 7,437,392 | <p>You can make the foo objects properties of the moo objects on the server side. </p>
<pre><code>for f, b in zip(foo, bar):
f.foosBar = b
context = {
"foo": foo
}
</code></pre>
<p>This is especially clean when the second list are properties of the first (which is typically the case). </p>
<pre><code>users... | 1 | 2011-09-15T21:00:32Z | [
"python",
"django",
"django-templates"
] |
Iterating through two lists in Django templates | 2,415,865 | <p>I want to do the below list iteration in django templates:</p>
<pre><code>foo = ['foo', 'bar'];
moo = ['moo', 'loo'];
for (a, b) in zip(foo, moo):
print a, b
</code></pre>
<p>django code:</p>
<pre><code>{%for a, b in zip(foo, moo)%}
{{a}}
{{b}}
{%endfor%}
</code></pre>
<p>I get the below error when I tr... | 18 | 2010-03-10T09:51:09Z | 14,857,664 | <p>Simply define zip as a <a href="https://docs.djangoproject.com/en/dev/howto/custom-template-tags/">template filter</a>:</p>
<pre><code>@register.filter(name='zip')
def zip_lists(a, b):
return zip(a, b)
</code></pre>
<p>Then, in your template:</p>
<pre><code>{%for a, b in first_list|zip:second_list %}
{{a}}
... | 16 | 2013-02-13T16:02:14Z | [
"python",
"django",
"django-templates"
] |
Iterating through two lists in Django templates | 2,415,865 | <p>I want to do the below list iteration in django templates:</p>
<pre><code>foo = ['foo', 'bar'];
moo = ['moo', 'loo'];
for (a, b) in zip(foo, moo):
print a, b
</code></pre>
<p>django code:</p>
<pre><code>{%for a, b in zip(foo, moo)%}
{{a}}
{{b}}
{%endfor%}
</code></pre>
<p>I get the below error when I tr... | 18 | 2010-03-10T09:51:09Z | 26,463,293 | <p>Here is modified {% for %} templatetag which allows iterating several lists at once izip-ing them before:</p>
<pre><code>import re
from itertools import izip
from django import template
from django.template.base import TemplateSyntaxError
from django.template.defaulttags import ForNode
register = template.Library... | 1 | 2014-10-20T10:18:02Z | [
"python",
"django",
"django-templates"
] |
Avoiding duplicated data in PostgreSQL database in Python | 2,415,884 | <p>I am working on PostgreSQL and psycopg2. Trying
to get feed data which is updated every after 10 mins
and keep this feeds contents in PostgreSQL database.My target is to retrieve
and print those data from that table.
But facing problem as duplicate data is also stored in the database every time I run that script ... | 1 | 2010-03-10T09:55:05Z | 2,416,171 | <p>Your code only has <code>INSERT</code>, so what do you think is going to happen when you fetch the same data for a second time?</p>
<p>Your update is failing because you're trying to insert a row which has an identical field value to one that already exists in a column with a unique constraint.</p>
<p>You either n... | 1 | 2010-03-10T10:41:25Z | [
"python",
"postgresql",
"psycopg2"
] |
Avoiding duplicated data in PostgreSQL database in Python | 2,415,884 | <p>I am working on PostgreSQL and psycopg2. Trying
to get feed data which is updated every after 10 mins
and keep this feeds contents in PostgreSQL database.My target is to retrieve
and print those data from that table.
But facing problem as duplicate data is also stored in the database every time I run that script ... | 1 | 2010-03-10T09:55:05Z | 2,416,247 | <p>You could try something like this:</p>
<pre><code>cur.execute("""
INSERT INTO locations_musiq1(location, location_title)
SELECT %s, %s WHERE NOT EXISTS
(SELECT location_title FROM locations_musiq1 WHERE location_title=%s);
""", (data.entries[i].title, data.entries[i].summary, data.entries[i].summary))... | 1 | 2010-03-10T10:56:00Z | [
"python",
"postgresql",
"psycopg2"
] |
Avoiding duplicated data in PostgreSQL database in Python | 2,415,884 | <p>I am working on PostgreSQL and psycopg2. Trying
to get feed data which is updated every after 10 mins
and keep this feeds contents in PostgreSQL database.My target is to retrieve
and print those data from that table.
But facing problem as duplicate data is also stored in the database every time I run that script ... | 1 | 2010-03-10T09:55:05Z | 2,419,022 | <p>Rahman. You are asking a second question in your comment that should probably be made into its own question instead.</p>
<p>Anyhow to return the results in a specified order, you need an order by clause. I don't see a timestamp column here but I assume that your feed data is formatted in XML. You could order by som... | 0 | 2010-03-10T17:24:24Z | [
"python",
"postgresql",
"psycopg2"
] |
Error in gui programming in python using tkinter | 2,415,950 | <pre><code>#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
import Tkinter
class simpleapp_tk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent=parent
def initialize(self):
self.grid()
self.entry=Tkinter.Entry(self)
self.entry.grid(colu... | 1 | 2010-03-10T10:04:20Z | 2,416,015 | <p>The main issue was that you forgot to call <code>app.initialize()</code>, but you also had a couple of typos. I've pointed out where in the comments in this fixed version.</p>
<pre><code>import Tkinter
class simpleapp_tk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
s... | 4 | 2010-03-10T10:13:27Z | [
"python"
] |
How to join the same table in sqlalchemy | 2,416,454 | <p>I'm trying to join the same table in sqlalchemy. This is a minimial version of what I tried:</p>
<pre><code>#!/usr/bin/env python
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.orm import mapper, sessionmaker, aliased
engine = create_engine('sqlite:///:memory:', echo=True)
metadata =... | 12 | 2010-03-10T11:30:41Z | 2,416,558 | <p>Your mapper should specificy the connection between the two items, here's an example: <a href="http://docs.sqlalchemy.org/en/latest/orm/relationships.html#adjacency-list-relationships" rel="nofollow">adjacency list relationships</a>.</p>
| 3 | 2010-03-10T11:47:07Z | [
"python",
"sqlalchemy"
] |
How to join the same table in sqlalchemy | 2,416,454 | <p>I'm trying to join the same table in sqlalchemy. This is a minimial version of what I tried:</p>
<pre><code>#!/usr/bin/env python
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.orm import mapper, sessionmaker, aliased
engine = create_engine('sqlite:///:memory:', echo=True)
metadata =... | 12 | 2010-03-10T11:30:41Z | 2,416,990 | <p>For query.[outer]join, you specify as list of joins (which is different to expression.[outer]join.) So I needed to put the 2 elements of the join, the table and the onclause in a tuple, like this:</p>
<pre><code>q = db_session.query(Device, ParentDevice)\
.outerjoin(
(ParentDevice, Device.pare... | 7 | 2010-03-10T12:59:35Z | [
"python",
"sqlalchemy"
] |
How to create a password entry field using Tkinter | 2,416,486 | <p>I am trying to code a login window using Tkinter but I'm not able to hide the password text in asterisk format. This means the password entry is plain text, which has to be avoided. Any idea how to do it?</p>
| 15 | 2010-03-10T11:35:46Z | 2,416,513 | <p>A quick google search yelded this</p>
<pre><code>widget = Entry(parent, show="*", width=15)
</code></pre>
<p>where:
<code>widget</code> is the text field, <code>parent</code> is the parent widget (a window, a frame, whatever), <code>show</code> is the character to echo (that is the character shown in the <code>Ent... | 26 | 2010-03-10T11:39:06Z | [
"python",
"tkinter"
] |
How to create a password entry field using Tkinter | 2,416,486 | <p>I am trying to code a login window using Tkinter but I'm not able to hide the password text in asterisk format. This means the password entry is plain text, which has to be avoided. Any idea how to do it?</p>
| 15 | 2010-03-10T11:35:46Z | 23,282,994 | <p>If you don't want to create a brand new Entry widget, you can do this:</p>
<pre><code>myEntry.config(show="*");
</code></pre>
<p>To make it back to normal again, do this:</p>
<pre><code>myEntry.config(show="");
</code></pre>
<p>I discovered this by examining the previous answer, and using the help function in th... | 8 | 2014-04-25T02:03:46Z | [
"python",
"tkinter"
] |
How to create a password entry field using Tkinter | 2,416,486 | <p>I am trying to code a login window using Tkinter but I'm not able to hide the password text in asterisk format. This means the password entry is plain text, which has to be avoided. Any idea how to do it?</p>
| 15 | 2010-03-10T11:35:46Z | 29,415,285 | <pre><code>widget-name = Entry(parent,show="*")
</code></pre>
<p>You can also use a bullet symbol:</p>
<pre><code>bullet = "\u2022" #specifies bullet character
widget-name = Entry(parent,show=bullet)#shows the character bullet
</code></pre>
| 2 | 2015-04-02T14:20:43Z | [
"python",
"tkinter"
] |
How to create a password entry field using Tkinter | 2,416,486 | <p>I am trying to code a login window using Tkinter but I'm not able to hide the password text in asterisk format. This means the password entry is plain text, which has to be avoided. Any idea how to do it?</p>
| 15 | 2010-03-10T11:35:46Z | 39,551,083 | <p>Here's a small, extremely simple demo app hiding and fetching the password using Tkinter.</p>
<pre><code>#Python 3.4 (For 2.7 change tkinter to Tkinter)
from tkinter import *
def show():
p = password.get() #get password from entry
print(p)
app = Tk()
password = StringVar() #Password variable
passEnt... | 0 | 2016-09-17T19:51:54Z | [
"python",
"tkinter"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.