title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
1,450,398
<p>There's a few ways to do it.</p> <ul> <li><p><a href="http://docs.python.org/library/sys.html#sys.stdin"><code>sys.stdin</code></a> is a file-like object on which you can call functions <code>read</code> or <code>readlines</code> if you want to read everything or you want to read everything and split it by newline ...
433
2009-09-20T05:53:17Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
1,454,400
<p>You could use the <a href="http://docs.python.org/library/fileinput.html"><code>fileinput</code></a> module:</p> <pre><code>import fileinput for line in fileinput.input(): pass </code></pre> <p><a href="http://docs.python.org/library/fileinput.html"><code>fileinput</code></a> will loop through all the lines i...
637
2009-09-21T13:01:14Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
3,289,051
<pre><code>import sys for line in sys.stdin: print line </code></pre>
210
2010-07-20T10:30:06Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
5,185,255
<p>Python also has built-in functions <code>input()</code> and <code>raw_input()</code>. See the Python documentation under <a href="http://docs.python.org/library/functions.html">Built-in Functions</a> or the Stack-Overflow documentation under <a class='doc-link' href="http://stackoverflow.com/documentation/python/809...
127
2011-03-03T19:05:48Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
7,608,205
<p>The answer proposed by others:</p> <pre><code>for line in sys.stdin: print line </code></pre> <p>is very simple and pythonic, but it must be noted that the script will wait until EOF before starting to iterate on the lines of input.</p> <p>This means that <code>tail -f error_log | myscript.py</code> will not pr...
75
2011-09-30T09:08:09Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
11,887,913
<p>This will echo standard input to standard output:</p> <pre><code>import sys line = sys.stdin.readline() while line: print line, line = sys.stdin.readline() </code></pre>
26
2012-08-09T16:31:57Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
17,927,520
<p>Building on all the anwers using <code>sys.stdin</code>, you can also do something like the following to read from an argument file if at least one argument exists, and fall back to stdin otherwise:</p> <pre><code>import sys f = open(sys.argv[1]) if len(sys.argv) &gt; 1 else sys.stdin for line in f: # Do yo...
19
2013-07-29T15:04:35Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
18,470,058
<p>Try this:</p> <pre><code>import sys print sys.stdin.read().upper() </code></pre> <p>and check it with:</p> <pre><code>$ echo "Hello World" | python myFile.py </code></pre>
5
2013-08-27T15:43:43Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
24,855,121
<p>You can read from stdin and then store inputs into <strong>"data"</strong> as follows:</p> <pre><code>data = "" for line in sys.stdin: data += line </code></pre>
8
2014-07-20T21:33:46Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
26,633,637
<p>I had some issues when getting this to work for reading over sockets piped to it. When the socket got closed it started returning empty string in an active loop. So this is my solution to it (which I only tested in linux, but hope it works in all other systems)</p> <pre><code>import sys, os sep=os.linesep while se...
3
2014-10-29T14:57:06Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
34,990,251
<p>The following chip of code will help you :</p> <pre><code>input_str = sys.stdin.read() print input_str.split() </code></pre>
5
2016-01-25T10:26:38Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
37,714,330
<p>Regarding this:</p> <p><code>for line in sys.stdin:</code></p> <p>I just tried it on python 2.7 (following someone else's suggestion) for a very large file, and I don't recommend it, precisely for the reasons mentioned above (nothing happens for a long time). </p> <p>I ended up with a slightly more pythonic solut...
2
2016-06-08T23:02:16Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
38,670,261
<blockquote> <h1>How do you read from stdin in Python?</h1> <p>I'm trying to do some of the code golf challenges, but they all require the input to be taken from stdin. How do I get that in Python?</p> </blockquote> <h2>TLDR: Golfed, compatible in 2, 3, Windows, Unix</h2> <p>Say you have a file with some lines...
0
2016-07-30T04:10:43Z
[ "python", "stdin" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
38,939,362
<p>Read from <code>sys.stdin</code>, but to <strong>read binary data on Windows</strong>, you need to be extra careful, because <code>sys.stdin</code> there is opened in text mode and it will corrupt <code>\r\n</code> replacing them with <code>\n</code>.</p> <p>The solution is to set mode to binary if Windows + Python...
1
2016-08-14T05:12:41Z
[ "python", "stdin" ]
How to get the name of a running Python script?
1,450,478
<p>How do I get the name of a running Python script?</p> <p>I tried <code>os.__file__</code> but that returns the name of the file where <code>os</code> resides.</p>
4
2009-09-20T06:59:54Z
1,450,484
<p><code>sys.argv[0]</code> should give you the name of the script.</p>
1
2009-09-20T07:04:20Z
[ "python" ]
How to get the name of a running Python script?
1,450,478
<p>How do I get the name of a running Python script?</p> <p>I tried <code>os.__file__</code> but that returns the name of the file where <code>os</code> resides.</p>
4
2009-09-20T06:59:54Z
1,450,485
<pre><code>&gt;&gt; import os &gt;&gt; import sys &gt;&gt; print sys.argv[0] </code></pre> <p>or if you just want the script and not the full path</p> <pre><code>&gt;&gt; &gt;&gt; print os.path.basename(sys.argv[0]) </code></pre>
10
2009-09-20T07:04:33Z
[ "python" ]
How to get the name of a running Python script?
1,450,478
<p>How do I get the name of a running Python script?</p> <p>I tried <code>os.__file__</code> but that returns the name of the file where <code>os</code> resides.</p>
4
2009-09-20T06:59:54Z
1,450,693
<p>Use</p> <pre><code>thisFile = __file__ </code></pre> <p>It's magic!</p>
17
2009-09-20T10:01:22Z
[ "python" ]
How to get the name of a running Python script?
1,450,478
<p>How do I get the name of a running Python script?</p> <p>I tried <code>os.__file__</code> but that returns the name of the file where <code>os</code> resides.</p>
4
2009-09-20T06:59:54Z
1,451,141
<pre><code>sys.path[0] </code></pre> <p>returns the path of the script that launched the Python interpreter. </p> <p>If you read this script directly, it will return the path of the script. If the script was imported from another script, it will return the path of that script.</p>
0
2009-09-20T14:27:57Z
[ "python" ]
How to get the name of a running Python script?
1,450,478
<p>How do I get the name of a running Python script?</p> <p>I tried <code>os.__file__</code> but that returns the name of the file where <code>os</code> resides.</p>
4
2009-09-20T06:59:54Z
1,451,204
<p>It depends on what you mean by "a running python script".</p> <p><code>__file__</code> will give you the name of the currently executing file. If that's a module, you'll get where it was imported from e.g. blahblah.pyc</p> <p><code>sys.argv[0]</code> will give you the name of the script that is being run, even if ...
3
2009-09-20T14:53:59Z
[ "python" ]
How to check form entry for special characters in python?
1,450,522
<p>Let's say I have a form field for "Name". I want to display an error message if it contains special characters such as $,#,etc. The only acceptable characters should be any alphanumeric, the hyphen "-", and the apostrophe "'". I am not sure how i should search the name for these non-acceptable characters, especia...
2
2009-09-20T07:29:31Z
1,450,538
<pre><code>import re p = r"^[\w'-]+$" if re.search(p, name): # it's okay else: # display error </code></pre>
1
2009-09-20T07:44:24Z
[ "python", "forms" ]
How to check form entry for special characters in python?
1,450,522
<p>Let's say I have a form field for "Name". I want to display an error message if it contains special characters such as $,#,etc. The only acceptable characters should be any alphanumeric, the hyphen "-", and the apostrophe "'". I am not sure how i should search the name for these non-acceptable characters, especia...
2
2009-09-20T07:29:31Z
1,450,539
<p>You can use regular expressions to validate your string, like this:</p> <pre><code>import re if re.search(r"^[\w\d'-]+$", name): # success </code></pre> <p>Another way:</p> <pre><code>if set("#$").intersection(name): print "bad chars in the name" </code></pre>
3
2009-09-20T07:45:05Z
[ "python", "forms" ]
wx.StaticBitmap or wx.DC: Which is better to use for constantly changing images?
1,450,639
<p>I would like to have a python gui that loads different images from files. I've seen many exmples of loading an image with some code like:</p> <pre><code>img = wx.Image("1.jpg", wx.BITMAP_TYPE_ANY, -1) sb = wx.StaticBitmap(rightPanel, -1, wx.BitmapFromImage(img)) sizer.Add(sb) </code></pre> <p>It seems to be suited...
1
2009-09-20T09:09:31Z
1,450,677
<p>You don't have to delete the <code>StaticBitmap</code>, you can just set another bitmap to it using it's <code>SetBitmap</code> method.</p> <p>If the new image has different dimensions you will probably have to do an explicit <code>Layout</code> call on it's parent so that the sizers would adjust.</p>
0
2009-09-20T09:48:31Z
[ "python", "user-interface", "image", "wxpython" ]
wx.StaticBitmap or wx.DC: Which is better to use for constantly changing images?
1,450,639
<p>I would like to have a python gui that loads different images from files. I've seen many exmples of loading an image with some code like:</p> <pre><code>img = wx.Image("1.jpg", wx.BITMAP_TYPE_ANY, -1) sb = wx.StaticBitmap(rightPanel, -1, wx.BitmapFromImage(img)) sizer.Add(sb) </code></pre> <p>It seems to be suited...
1
2009-09-20T09:09:31Z
1,450,759
<p>I read here: <a href="http://docs.wxwidgets.org/trunk/classwx%5Fstatic%5Fbitmap.html" rel="nofollow">http://docs.wxwidgets.org/trunk/classwx%5Fstatic%5Fbitmap.html</a></p> <p>"Native implementations on some platforms are only meant for display of the small icons in the dialog boxes. In particular, under Windows 9x ...
0
2009-09-20T10:46:34Z
[ "python", "user-interface", "image", "wxpython" ]
wx.StaticBitmap or wx.DC: Which is better to use for constantly changing images?
1,450,639
<p>I would like to have a python gui that loads different images from files. I've seen many exmples of loading an image with some code like:</p> <pre><code>img = wx.Image("1.jpg", wx.BITMAP_TYPE_ANY, -1) sb = wx.StaticBitmap(rightPanel, -1, wx.BitmapFromImage(img)) sizer.Add(sb) </code></pre> <p>It seems to be suited...
1
2009-09-20T09:09:31Z
1,450,832
<p>If you have rapidly changing big images, or you would like some custom effect in future, it better to write your own control and doing painting using paintDC, and it is not that hard.</p> <p>Doing your own drawing you can correctly scale, avoid flicker and may be do blend of one image into other if you like :)</p>
1
2009-09-20T11:32:35Z
[ "python", "user-interface", "image", "wxpython" ]
Setting a colour scale in ipython
1,450,874
<p>I am new to python and am having trouble finding the correct syntax to use. I want to plot some supernovae data onto a hammer projection. The data has coordinates alpha and beta. For each data point there is also a value delta describing a property of the SN. I would like to create a colour scale that ranges from m...
2
2009-09-20T11:58:37Z
1,450,966
<p>If you are thinking of a fixed color table, just map your delta values into the index range for that table. For example, you can construct a color table with color names recognized by your plot package:</p> <pre><code>&gt;&gt;&gt; colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] </code></pr...
2
2009-09-20T12:57:37Z
[ "python" ]
Setting a colour scale in ipython
1,450,874
<p>I am new to python and am having trouble finding the correct syntax to use. I want to plot some supernovae data onto a hammer projection. The data has coordinates alpha and beta. For each data point there is also a value delta describing a property of the SN. I would like to create a colour scale that ranges from m...
2
2009-09-20T11:58:37Z
1,451,311
<p>I'm not familiar with plotting, but a nice method for generating rainbow colors is using the HSV (hue, saturation, value) colorspace. Set saturation and value to the maximum values, and vary the hue.</p> <pre><code>import colorsys def color(value): return colorsys.hsv_to_rgb(value / delta.max / (1.1), 1, 1) </...
1
2009-09-20T15:45:57Z
[ "python" ]
Setting a colour scale in ipython
1,450,874
<p>I am new to python and am having trouble finding the correct syntax to use. I want to plot some supernovae data onto a hammer projection. The data has coordinates alpha and beta. For each data point there is also a value delta describing a property of the SN. I would like to create a colour scale that ranges from m...
2
2009-09-20T11:58:37Z
1,451,981
<p>Using the wavelen2rgb function of Johnny Lin's Python Library (as gimel suggested), the following code plots the SNs as filled circles. The code uses Tkinter which is always available with Python. You can get wavelen2rgb.py <a href="http://www.johnny-lin.com/py%5Fcode/wavelen2rgb.py" rel="nofollow">here</a>.</p> <p...
1
2009-09-20T20:52:18Z
[ "python" ]
Paste text to active window linux
1,450,892
<p>I want to write application which paste some text to active window on some keystroke. How can i do this with Python or C++ ?</p> <p>Update: Sorry people. I think i don't describe problem clearly. I want to write app, which will work like a daemon and on some global keystroke paste some text to current active appli...
1
2009-09-20T12:09:16Z
1,451,337
<p>Interacting between multiple applications interfaces can be tricky, so it may help to provide more information on specifically what you are trying to do. </p> <p>Nonetheless, you have a few options if you want to use the clipboard to accomplish this. On Windows, the Windows API provides <a href="http://msdn.micros...
1
2009-09-20T15:53:53Z
[ "c++", "python", "linux", "x11" ]
Paste text to active window linux
1,450,892
<p>I want to write application which paste some text to active window on some keystroke. How can i do this with Python or C++ ?</p> <p>Update: Sorry people. I think i don't describe problem clearly. I want to write app, which will work like a daemon and on some global keystroke paste some text to current active appli...
1
2009-09-20T12:09:16Z
1,451,804
<p>If you use Tkinter (a GUI library that works in Linux, MACOS, Windows and everywhere), and make any widget (for example a text widget), the copy (ctrl-c) and paste (ctrl-v) commands automatically work. For example the following code shows a Text widget, where you can type multi-line text, and copy and paste to other...
0
2009-09-20T19:30:39Z
[ "c++", "python", "linux", "x11" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
1,450,900
<p>Use <code>re.sub</code>, like so:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.sub("\D", "", "aas30dsa20") '3020' </code></pre> <p><code>\D</code> matches any non-digit character so, the code above, is essentially replacing every non-digit character for the empty string.</p> <p>Or you can use <code>filte...
104
2009-09-20T12:18:48Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
1,450,905
<p>Use a generator expression:</p> <pre><code>&gt;&gt;&gt; s = "foo200bar" &gt;&gt;&gt; new_s = "".join(i for i in s if i in "0123456789") </code></pre>
1
2009-09-20T12:21:49Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
1,450,907
<p>Ugly but works:</p> <pre><code>&gt;&gt;&gt; s 'aaa12333bb445bb54b5b52' &gt;&gt;&gt; a = ''.join(filter(lambda x : x.isdigit(), s)) &gt;&gt;&gt; a '1233344554552' &gt;&gt;&gt; </code></pre>
2
2009-09-20T12:23:03Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
1,450,911
<p>along the lines of bayer's answer:</p> <pre><code>''.join(i for i in s if i.isdigit()) </code></pre>
9
2009-09-20T12:23:17Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
1,450,912
<p>You can use filter:</p> <pre><code>filter(lambda x: x.isdigit(), "dasdasd2313dsa") </code></pre> <p>On python3.0 you have to join this (kinda ugly :( )</p> <pre><code>''.join(filter(lambda x: x.isdigit(), "dasdasd2313dsa")) </code></pre>
11
2009-09-20T12:24:05Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
1,450,913
<pre><code>s=''.join(i for i in s if i.isdigit()) </code></pre> <p>Another generator variant.</p>
44
2009-09-20T12:24:18Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
1,451,407
<p>In Python 2.*, by far the fastest approach is the <code>.translate</code> method:</p> <pre><code>&gt;&gt;&gt; x='aaa12333bb445bb54b5b52' &gt;&gt;&gt; import string &gt;&gt;&gt; all=string.maketrans('','') &gt;&gt;&gt; nodigs=all.translate(all, string.digits) &gt;&gt;&gt; x.translate(all, nodigs) '1233344554552' &gt...
77
2009-09-20T16:37:19Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
14,092,390
<p>The op mentions in the comments that he wants to keep the decimal place. This can be done with the re.sub method (as per the second and IMHO best answer) by explicitly listing the characters to keep e.g.</p> <pre><code>&gt;&gt;&gt; re.sub("[^0123456789\.]","","poo123.4and5fish") '123.45' </code></pre>
3
2012-12-30T16:31:51Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
15,202,183
<pre><code>x.translate(None, string.digits) </code></pre> <p>will delete all digits from string. To delete letters and keep the digits, do this:</p> <pre><code>x.translate(None, string.letters) </code></pre>
6
2013-03-04T13:00:04Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
26,517,161
<p>A fast version for Python 3:</p> <pre><code># xx3.py from collections import defaultdict import string _NoneType = type(None) def keeper(keep): table = defaultdict(_NoneType) table.update({ord(c): c for c in keep}) return table digit_keeper = keeper(string.digits) </code></pre> <p>Here's a performanc...
2
2014-10-22T21:09:42Z
[ "python", "string" ]
Python: removing characters except digits from string
1,450,897
<p>How can i remove all characters except numbers from string?</p>
72
2009-09-20T12:14:17Z
39,235,227
<p>You can easily do it using Regex</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.sub("\D","","£70,000") 70000 </code></pre>
0
2016-08-30T19:03:44Z
[ "python", "string" ]
Python's json module, converts int dictionary keys to strings
1,450,957
<p>I have found that when the following is run, python's json module (included since 2.6) converts int dictionary keys to strings.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; releases = {1: "foo-v0.1"} &gt;&gt;&gt; json.dumps(releases) '{"1": "foo-v0.1"}' </code></pre> <p>Is there any easy way to preserve th...
56
2009-09-20T12:52:40Z
1,450,981
<p>No, there is no such thing as a Number key in JavaScript. All object properties are converted to String.</p> <pre><code>var a= {1: 'a'}; for (k in a) alert(typeof k); // 'string' </code></pre> <p>This can lead to some curious-seeming behaviours:</p> <pre><code>a[999999999999999999999]= 'a'; // this even works...
41
2009-09-20T13:08:01Z
[ "python", "json" ]
Python's json module, converts int dictionary keys to strings
1,450,957
<p>I have found that when the following is run, python's json module (included since 2.6) converts int dictionary keys to strings.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; releases = {1: "foo-v0.1"} &gt;&gt;&gt; json.dumps(releases) '{"1": "foo-v0.1"}' </code></pre> <p>Is there any easy way to preserve th...
56
2009-09-20T12:52:40Z
1,451,857
<p>This is one of those subtle differences among various mapping collections that can bite you.</p> <p>In Python (and apparently in Lua) the keys to a mapping (dictionary or table, respectively) are object references. In Python they must be immutable types, or they must be objects which implement a <code>__hash__</co...
43
2009-09-20T19:56:46Z
[ "python", "json" ]
Python's json module, converts int dictionary keys to strings
1,450,957
<p>I have found that when the following is run, python's json module (included since 2.6) converts int dictionary keys to strings.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; releases = {1: "foo-v0.1"} &gt;&gt;&gt; json.dumps(releases) '{"1": "foo-v0.1"}' </code></pre> <p>Is there any easy way to preserve th...
56
2009-09-20T12:52:40Z
1,513,957
<p>I've gotten bitten by the same problem. As others have pointed out, in JSON, the mapping keys must be strings. You can do one of two things. You can use a less strict JSON library, like <a href="http://deron.meranda.us/python/demjson/" rel="nofollow">demjson</a>, which allows integer strings. If no other program...
6
2009-10-03T14:54:08Z
[ "python", "json" ]
Python's json module, converts int dictionary keys to strings
1,450,957
<p>I have found that when the following is run, python's json module (included since 2.6) converts int dictionary keys to strings.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; releases = {1: "foo-v0.1"} &gt;&gt;&gt; json.dumps(releases) '{"1": "foo-v0.1"}' </code></pre> <p>Is there any easy way to preserve th...
56
2009-09-20T12:52:40Z
3,742,888
<p>Alternatively you can also try converting dictionary to a list of [(k1,v1),(k2,v2)] format while encoding it using json, and converting it back to dictionary after decoding it back. <pre><code> &gt;&gt;&gt;&gt; import json &gt;&gt;&gt;&gt; json.dumps(releases.items()) '[[1, "foo-v0.1"]]' &gt;&gt;&gt;&gt; release...
14
2010-09-18T18:17:49Z
[ "python", "json" ]
Python's json module, converts int dictionary keys to strings
1,450,957
<p>I have found that when the following is run, python's json module (included since 2.6) converts int dictionary keys to strings.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; releases = {1: "foo-v0.1"} &gt;&gt;&gt; json.dumps(releases) '{"1": "foo-v0.1"}' </code></pre> <p>Is there any easy way to preserve th...
56
2009-09-20T12:52:40Z
34,346,202
<p>Answering your subquestion:</p> <p>It can be accomplished by using <code>json.loads(jsonDict, object_hook=jsonKeys2str)</code></p> <pre><code>def jsonKeys2str(x): if isinstance(x, dict): return {int(k):v for k,v in x.items()} return x </code></pre> <p>This function will also work for nested di...
3
2015-12-17T23:28:25Z
[ "python", "json" ]
Python's json module, converts int dictionary keys to strings
1,450,957
<p>I have found that when the following is run, python's json module (included since 2.6) converts int dictionary keys to strings.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; releases = {1: "foo-v0.1"} &gt;&gt;&gt; json.dumps(releases) '{"1": "foo-v0.1"}' </code></pre> <p>Is there any easy way to preserve th...
56
2009-09-20T12:52:40Z
38,626,091
<p>You can write your <code>json.dumps</code> by yourself, here is a example from <a href="https://github.com/damnever/djson" rel="nofollow">djson</a>: <a href="https://github.com/damnever/djson/blob/master/djson/encoder.py" rel="nofollow">encoder.py</a>. You can use it like this:</p> <pre><code>assert dumps({1: "abc"...
0
2016-07-28T02:17:43Z
[ "python", "json" ]
Security concerns with a Python PAM module?
1,451,224
<p>I'm interested in writing a PAM module that would make use of a popular authentication mechanism for Unix logins. Most of my past programming experience has been in Python, and the system I'm interacting with already has a Python API. I googled around and found <a href="http://pam-python.sourceforge.net/" rel="nofol...
12
2009-09-20T15:02:52Z
1,451,379
<p>The security concerns that you mention aren't, per se, about "allowing the user to invoke Python code" which runs with high access levels, but allowing the user to exercise any form of <em>control</em> over the running of such code -- most obviously by injecting or altering the code itself, but, more subtly, also by...
16
2009-09-20T16:20:40Z
[ "python", "security", "pam", "suid" ]
How to stream binary data in python
1,451,349
<p>I want to stream a binary data using python. I do not have any idea how to achieve it. I did created python socket program using <code>SOCK_DGRAM</code>. Problem with <code>SOCK_STREAM</code> is that it does not work over internet as our isp dont allow tcp server socket. </p> <p>I want to transmit screen shots per...
1
2009-09-20T16:01:16Z
1,451,356
<p>There are two problems here.</p> <p>First problem, you will need to be able to address the remote party. This is related to what you referred to as "does not work over Internet as most ISP don't allow TCP server socket". It is usually difficult because the other party could be placed behind a NAT or a firewall.</...
2
2009-09-20T16:06:13Z
[ "python", "sockets" ]
How to stream binary data in python
1,451,349
<p>I want to stream a binary data using python. I do not have any idea how to achieve it. I did created python socket program using <code>SOCK_DGRAM</code>. Problem with <code>SOCK_STREAM</code> is that it does not work over internet as our isp dont allow tcp server socket. </p> <p>I want to transmit screen shots per...
1
2009-09-20T16:01:16Z
1,451,365
<p>SOCK_STREAM is the correct way to stream data.</p> <p>What you're saying about ISPs makes very little sense; they don't control whether or not your machine listens on a certain port on an interface. Perhaps you're talking about firewall/addressing issues?</p> <p>If you insist on using UDP (and you shouldn't becaus...
3
2009-09-20T16:09:33Z
[ "python", "sockets" ]
Python: How to find presence of every list item in string
1,451,390
<p>What is the most pythonic way to find presence of every directory name <code>['spam', 'eggs']</code> in path e.g. <code>"/home/user/spam/eggs"</code></p> <p>Usage example (doesn't work but explains my case):</p> <pre><code>dirs = ['spam', 'eggs'] path = "/home/user/spam/eggs" if path.find(dirs): print "All dir...
3
2009-09-20T16:28:05Z
1,451,404
<pre><code>names = ['spam', 'eggs'] dir = "/home/user/spam/eggs" # Split into parts parts = [ for part in dir.split('/') if part != '' ] # Rejoin found paths dirs = [ '/'.join(parts[0:n]) for (n, name) in enumerate(parts) if name in names ] </code></pre> <p>Edit : If you just want to verify whether all dirs exist...
2
2009-09-20T16:36:26Z
[ "python", "list", "path" ]
Python: How to find presence of every list item in string
1,451,390
<p>What is the most pythonic way to find presence of every directory name <code>['spam', 'eggs']</code> in path e.g. <code>"/home/user/spam/eggs"</code></p> <p>Usage example (doesn't work but explains my case):</p> <pre><code>dirs = ['spam', 'eggs'] path = "/home/user/spam/eggs" if path.find(dirs): print "All dir...
3
2009-09-20T16:28:05Z
1,451,426
<p>A one liner using generators (using textual lookup and not treating names as anything to do with the filesystem - your request is not totally clear to me)</p> <pre><code>[x for x in dirs if x in path.split( os.sep )] </code></pre>
0
2009-09-20T16:46:09Z
[ "python", "list", "path" ]
Python: How to find presence of every list item in string
1,451,390
<p>What is the most pythonic way to find presence of every directory name <code>['spam', 'eggs']</code> in path e.g. <code>"/home/user/spam/eggs"</code></p> <p>Usage example (doesn't work but explains my case):</p> <pre><code>dirs = ['spam', 'eggs'] path = "/home/user/spam/eggs" if path.find(dirs): print "All dir...
3
2009-09-20T16:28:05Z
1,451,453
<p>Looks line you want something like...:</p> <pre><code>if all(d in path.split('/') for d in dirs): ... </code></pre> <p>This one-liner style is inefficient since it keeps splitting path for each d (and split makes a list, while a set is better for membership checking). Making it into a 2-liner:</p> <pre><code>p...
5
2009-09-20T16:59:44Z
[ "python", "list", "path" ]
Python: How to find presence of every list item in string
1,451,390
<p>What is the most pythonic way to find presence of every directory name <code>['spam', 'eggs']</code> in path e.g. <code>"/home/user/spam/eggs"</code></p> <p>Usage example (doesn't work but explains my case):</p> <pre><code>dirs = ['spam', 'eggs'] path = "/home/user/spam/eggs" if path.find(dirs): print "All dir...
3
2009-09-20T16:28:05Z
1,451,458
<p>Maybe this is what you want?</p> <pre><code>dirs = ['spam', 'eggs'] path = "/home/user/spam/eggs" present = [dir for dir in dirs if dir in path] </code></pre>
1
2009-09-20T17:01:14Z
[ "python", "list", "path" ]
Python: How to find presence of every list item in string
1,451,390
<p>What is the most pythonic way to find presence of every directory name <code>['spam', 'eggs']</code> in path e.g. <code>"/home/user/spam/eggs"</code></p> <p>Usage example (doesn't work but explains my case):</p> <pre><code>dirs = ['spam', 'eggs'] path = "/home/user/spam/eggs" if path.find(dirs): print "All dir...
3
2009-09-20T16:28:05Z
1,451,910
<h3><a href="http://docs.python.org/library/stdtypes.html#set.issubset"><code>set.issubset</code></a>:</h3> <pre><code>&gt;&gt;&gt; set(['spam', 'eggs']).issubset('/home/user/spam/eggs'.split('/')) True </code></pre>
9
2009-09-20T20:14:12Z
[ "python", "list", "path" ]
Python MySQL - SELECTs work but not DELETEs?
1,451,782
<p>I'm new to Python and Python's MySQL adapter. I'm not sure if I'm missing something obvious here:</p> <pre><code>db = MySQLdb.connect(# db details omitted) cursor = self.db.cursor() # WORKS cursor.execute("SELECT site_id FROM users WHERE username=%s", (username)) record = cursor.fetchone() # DOES NOT SEEM TO WOR...
7
2009-09-20T19:22:23Z
1,451,914
<p>I'd guess that you are using a storage engine that supports transactions (e.g. InnoDB) but you don't call <code>db.commit()</code> after the DELETE. The effect of the DELETE is discarded if you don't commit.</p> <p>See <a href="http://mysql-python.sourceforge.net/FAQ.html#my-data-disappeared-or-won-t-go-away">http...
11
2009-09-20T20:14:52Z
[ "python", "mysql", "select", "sql-delete" ]
Python MySQL - SELECTs work but not DELETEs?
1,451,782
<p>I'm new to Python and Python's MySQL adapter. I'm not sure if I'm missing something obvious here:</p> <pre><code>db = MySQLdb.connect(# db details omitted) cursor = self.db.cursor() # WORKS cursor.execute("SELECT site_id FROM users WHERE username=%s", (username)) record = cursor.fetchone() # DOES NOT SEEM TO WOR...
7
2009-09-20T19:22:23Z
1,457,166
<p>To your code above, just add a call to <code>self.db.commit()</code>.</p> <p>The feature is far from an annoyance:</p> <p>It saves you from data corruption issues when there are errors in your queries.</p>
0
2009-09-21T22:11:48Z
[ "python", "mysql", "select", "sql-delete" ]
Python MySQL - SELECTs work but not DELETEs?
1,451,782
<p>I'm new to Python and Python's MySQL adapter. I'm not sure if I'm missing something obvious here:</p> <pre><code>db = MySQLdb.connect(# db details omitted) cursor = self.db.cursor() # WORKS cursor.execute("SELECT site_id FROM users WHERE username=%s", (username)) record = cursor.fetchone() # DOES NOT SEEM TO WOR...
7
2009-09-20T19:22:23Z
1,457,696
<p>Perhaps you are violating a foreign key constraint.</p>
1
2009-09-22T01:22:50Z
[ "python", "mysql", "select", "sql-delete" ]
Python MySQL - SELECTs work but not DELETEs?
1,451,782
<p>I'm new to Python and Python's MySQL adapter. I'm not sure if I'm missing something obvious here:</p> <pre><code>db = MySQLdb.connect(# db details omitted) cursor = self.db.cursor() # WORKS cursor.execute("SELECT site_id FROM users WHERE username=%s", (username)) record = cursor.fetchone() # DOES NOT SEEM TO WOR...
7
2009-09-20T19:22:23Z
13,190,265
<p>The problem might be that you are not committing the changes. it can be done by <code>conn.commit()</code></p> <p>read more on this <a href="http://sahanlm.blogspot.com/2012/10/mysqldb-does-not-commit-then-read-this.html" rel="nofollow">here</a></p>
0
2012-11-02T06:14:42Z
[ "python", "mysql", "select", "sql-delete" ]
Simple file transfer over wifi between computer and mobile phone using python
1,451,849
<p>I'd like to be able to transfer files between my mobile phone and computer. The phone is a smartphone that can run python 2.5.4 and the computer is running windows xp (with python 2.5.4 and 3.1.1). </p> <p>I'd like to have a simple python program on the phone that can send files to the computer and get files from...
4
2009-09-20T19:53:18Z
1,451,872
<p>There are <a href="http://mail.python.org/pipermail/python-list/2008-February/649168.html" rel="nofollow">a couple of examples</a> out there, but you have to keep in mind that, IIRC, PyBluez will work only on Linux.</p> <blockquote> <p>I've previously done OBEX-related things, mostly fetching things from mobile...
0
2009-09-20T20:01:05Z
[ "python", "mobile-phones", "file-transfer" ]
Simple file transfer over wifi between computer and mobile phone using python
1,451,849
<p>I'd like to be able to transfer files between my mobile phone and computer. The phone is a smartphone that can run python 2.5.4 and the computer is running windows xp (with python 2.5.4 and 3.1.1). </p> <p>I'd like to have a simple python program on the phone that can send files to the computer and get files from...
4
2009-09-20T19:53:18Z
1,452,284
<p>I would use <a href="http://www.lag.net/paramiko/" rel="nofollow">paramiko</a>. It's secure fast and really simple. How bout this?</p> <p>So we start by importing the module, and specifying the log file:</p> <pre><code>import paramiko paramiko.util.log_to_file('/tmp/paramiko.log') </code></pre> <p>We open an SSH...
3
2009-09-20T23:12:10Z
[ "python", "mobile-phones", "file-transfer" ]
Simple file transfer over wifi between computer and mobile phone using python
1,451,849
<p>I'd like to be able to transfer files between my mobile phone and computer. The phone is a smartphone that can run python 2.5.4 and the computer is running windows xp (with python 2.5.4 and 3.1.1). </p> <p>I'd like to have a simple python program on the phone that can send files to the computer and get files from...
4
2009-09-20T19:53:18Z
1,457,187
<p>I ended up using python's ftplib on the phone and FileZilla, an ftp sever, on the computer. Advantages are high degree of simplicity, although there may be security issues.</p> <p>In case anyone cares, here's the guts of the client side code to send and receive files. Actual implementation has a bit more infrastru...
0
2009-09-21T22:18:09Z
[ "python", "mobile-phones", "file-transfer" ]
Simple scraping of youtube xml to get a Python list of videos
1,452,144
<p>I have an xml feed, say:</p> <p><a href="http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/" rel="nofollow">http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/</a></p> <p>I want to get the list of hrefs for the videos:</p> <pre><code> ['http://www.youtube.com/watch?v=aJvVkBcbFFY', 'ht....', ... ] </c...
1
2009-09-20T22:02:27Z
1,452,164
<pre><code>import urllib from xml.dom import minidom xmldoc = minidom.parse(urllib.urlopen('http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/')) links = xmldoc.getElementsByTagName('link') hrefs = [] for links in link: if link.getAttribute('rel') == 'alternate': hrefs.append( link.getAttribute('hre...
1
2009-09-20T22:19:08Z
[ "python", "xml", "youtube" ]
Simple scraping of youtube xml to get a Python list of videos
1,452,144
<p>I have an xml feed, say:</p> <p><a href="http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/" rel="nofollow">http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/</a></p> <p>I want to get the list of hrefs for the videos:</p> <pre><code> ['http://www.youtube.com/watch?v=aJvVkBcbFFY', 'ht....', ... ] </c...
1
2009-09-20T22:02:27Z
1,452,167
<p>Have a look at <a href="http://www.feedparser.org/" rel="nofollow">Universal Feed Parser</a>, which is an open source RSS and Atom feed parser for Python.</p>
3
2009-09-20T22:19:28Z
[ "python", "xml", "youtube" ]
Simple scraping of youtube xml to get a Python list of videos
1,452,144
<p>I have an xml feed, say:</p> <p><a href="http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/" rel="nofollow">http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/</a></p> <p>I want to get the list of hrefs for the videos:</p> <pre><code> ['http://www.youtube.com/watch?v=aJvVkBcbFFY', 'ht....', ... ] </c...
1
2009-09-20T22:02:27Z
1,452,170
<p>In such a simple case, this should be enough:</p> <pre><code>import re, urllib2 request = urllib2.urlopen("http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/") text = request.read() videos = re.findall("http:\/\/www\.youtube\.com\/watch\?v=[\w-]+", text) </code></pre> <p>If you want to do more complicated s...
3
2009-09-20T22:20:52Z
[ "python", "xml", "youtube" ]
Simple scraping of youtube xml to get a Python list of videos
1,452,144
<p>I have an xml feed, say:</p> <p><a href="http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/" rel="nofollow">http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/</a></p> <p>I want to get the list of hrefs for the videos:</p> <pre><code> ['http://www.youtube.com/watch?v=aJvVkBcbFFY', 'ht....', ... ] </c...
1
2009-09-20T22:02:27Z
1,452,219
<pre><code>from xml.etree import cElementTree as ET import urllib def get_bass_fishing_URLs(): results = [] data = urllib.urlopen( 'http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/') tree = ET.parse(data) ns = '{http://www.w3.org/2005/Atom}' for entry in tree.findall(ns + 'entry'): for lin...
7
2009-09-20T22:44:03Z
[ "python", "xml", "youtube" ]
Detecting symlinks (mklink) on Vista/7 in Python without Pywin32
1,452,148
<p>Currently the buildout recipe collective.recipe.omelette uses junction.exe on all versions of Windows to create symlinks. However junction.exe does not come with Windows by default and most importantly does not support creating symlinks to files (only directories) which causes a problem with quite a few Python packa...
3
2009-09-20T22:06:20Z
1,452,321
<p>Could you use <code>ctypes</code> to access the various needed functions and structures? <a href="http://bugs.python.org/file14878/windows%20symlink%20draft%209.patch" rel="nofollow">this patch</a>, currently under discussion, is intended to add symlink functionality to module <code>os</code> under Vista and Window...
2
2009-09-20T23:35:01Z
[ "python", "windows", "windows-vista", "pywin32" ]
Detecting symlinks (mklink) on Vista/7 in Python without Pywin32
1,452,148
<p>Currently the buildout recipe collective.recipe.omelette uses junction.exe on all versions of Windows to create symlinks. However junction.exe does not come with Windows by default and most importantly does not support creating symlinks to files (only directories) which causes a problem with quite a few Python packa...
3
2009-09-20T22:06:20Z
1,452,480
<p>On windows junctions and symbolic links have the attribute <code>FILE_ATTRIBUTE_REPARSE_POINT</code> (0x400) for reparse points. If you get the file's attributes, then detect this on?</p> <p>You could use ctypes (as stated in the other answer) to access <a href="http://msdn.microsoft.com/en-us/library/aa364944%28VS...
2
2009-09-21T01:10:33Z
[ "python", "windows", "windows-vista", "pywin32" ]
Detecting symlinks (mklink) on Vista/7 in Python without Pywin32
1,452,148
<p>Currently the buildout recipe collective.recipe.omelette uses junction.exe on all versions of Windows to create symlinks. However junction.exe does not come with Windows by default and most importantly does not support creating symlinks to files (only directories) which causes a problem with quite a few Python packa...
3
2009-09-20T22:06:20Z
1,616,216
<p>See <a href="https://github.com/jaraco/jaraco.windows/blob/master/jaraco/windows/filesystem/__init__.py" rel="nofollow">jaraco.windows.filesystem</a> (part of the <a href="http://pypi.python.org/pypi/jaraco.windows" rel="nofollow">jaraco.windows package</a>) for extensive examples on symlink operations in Windows wi...
4
2009-10-23T22:13:35Z
[ "python", "windows", "windows-vista", "pywin32" ]
Detecting symlinks (mklink) on Vista/7 in Python without Pywin32
1,452,148
<p>Currently the buildout recipe collective.recipe.omelette uses junction.exe on all versions of Windows to create symlinks. However junction.exe does not come with Windows by default and most importantly does not support creating symlinks to files (only directories) which causes a problem with quite a few Python packa...
3
2009-09-20T22:06:20Z
4,610,520
<p>You could leverage the Tcl you have available with Tkinter, as that has a 'file link' command that knows about junctions, unlike Pythons os module.</p>
0
2011-01-06T00:03:08Z
[ "python", "windows", "windows-vista", "pywin32" ]
TurtleGraphics Python - Constraining random-moving turtle in a circle?
1,452,311
<p>How would I be able to make a randomly moving turtle be constrained inside a circle with a radius of 50, the circles center being at (0, 0)? So if the turtle is currently at location (x, y), it's distance from the center is math.sqrt(x ** 2 + y ** 2). Whenever the turtle's distance from the center is more than 50, h...
0
2009-09-20T23:28:50Z
1,452,345
<p>Where you're coding:</p> <pre><code> if -width/2 &lt;= x &lt;= width/2 and -height/2 &lt;= y &lt;= height/2: </code></pre> <p>you really mean "if point(x, y) is inside the permitted area". So, when "the permitted area" is "a circle with radius 50 centered at origin", comparing the squares of distances and radiu...
1
2009-09-20T23:45:25Z
[ "python", "turtle-graphics" ]
Evaluation of boolean expressions in Python
1,452,489
<p>What truth value do objects evaluate to in Python?</p> <p><strong>Related Questions</strong></p> <ul> <li><a href="http://stackoverflow.com/questions/1087135/boolean-value-of-objects-in-python">Boolean Value of Objects in Python</a>: Discussion about overriding the way it is evaluated</li> </ul>
5
2009-09-21T01:15:21Z
1,452,492
<p><strong>Update</strong>: Removed all duplicate infomation with Meder's post </p> <p>For custom objects in Python &lt; 3.0 <code>__nonzero__</code> to change how it is evaluated. In Python 3.0 this is <code>__bool__</code> (<a href="http://stackoverflow.com/questions/1087135/boolean-value-of-objects-in-python/108716...
7
2009-09-21T01:17:14Z
[ "python", "object", "boolean" ]
Evaluation of boolean expressions in Python
1,452,489
<p>What truth value do objects evaluate to in Python?</p> <p><strong>Related Questions</strong></p> <ul> <li><a href="http://stackoverflow.com/questions/1087135/boolean-value-of-objects-in-python">Boolean Value of Objects in Python</a>: Discussion about overriding the way it is evaluated</li> </ul>
5
2009-09-21T01:15:21Z
1,452,500
<blockquote> <p>Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false:</p> <ul> <li><p>None</p></li> <li><p>False</p></li> <li><p>zero of any numeric type, for example, <code>0</code>, <...
15
2009-09-21T01:21:22Z
[ "python", "object", "boolean" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
1,452,667
<p>There are tons, which ones are "good" depend on what you need.</p> <p>There's Ruby on Rails, which is pretty handy.</p> <p>For python there's django.</p> <p>For PHP (I spend a lot of time dealing with PHP), you can look at:</p> <ul> <li>symfony</li> <li>cakePHP</li> <li>Solar</li> <li>Zend Framework</li> </ul> ...
1
2009-09-21T02:48:15Z
[ "java", "php", "python", "ruby-on-rails" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
1,452,670
<p>There is no single "right" answer to this question. As a Java programmer of some 10+ years when asked this question my usual answer is... PHP. There are several reasons for this:</p> <ul> <li>Low resource usage (Apache, nginx);</li> <li>Cheaper hosting;</li> <li>Really low barrier to entry;</li> <li>It's really Web...
7
2009-09-21T02:48:41Z
[ "java", "php", "python", "ruby-on-rails" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
1,452,676
<p>You've already tagged your question with "java", "php", "python", and "ruby-on-rails", so researching and learning more about those tools would probably help to answer your question.</p> <p>However, I believe that <em>rapidly building</em> an application is almost never actually the correct goal. Normally, what yo...
4
2009-09-21T02:49:17Z
[ "java", "php", "python", "ruby-on-rails" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
1,452,739
<p><a href="http://www.djangoproject.com/" rel="nofollow">Django</a> has a few notable 'rapid' items including <a href="http://images.google.com/images?hl=en&amp;client=firefox-a&amp;rls=org.mozilla%3Aen-US%3Aofficial&amp;hs=0Ku&amp;q=django%20admin&amp;um=1&amp;ie=UTF-8&amp;sa=N&amp;tab=wi" rel="nofollow">automaticall...
8
2009-09-21T03:13:51Z
[ "java", "php", "python", "ruby-on-rails" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
1,452,751
<p>Speaking only in terms of speed of development, Ruby on Rails is the fastest one out there.</p>
1
2009-09-21T03:19:34Z
[ "java", "php", "python", "ruby-on-rails" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
1,452,994
<p>I would vote for <a href="http://grails.org/" rel="nofollow">Grails</a>.</p>
1
2009-09-21T05:20:41Z
[ "java", "php", "python", "ruby-on-rails" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
1,453,699
<p>I would say part of the learning curve will go into understanding concepts. I have been learning about web-apps for some months now, and with my improved understanding of concepts right now, most frameworks show very much similarities. Here are my results so far:</p> <ul> <li>PHP: Great to learn about concepts for...
2
2009-09-21T09:53:14Z
[ "java", "php", "python", "ruby-on-rails" ]
How to rapidly build a Web Application?
1,452,652
<p>To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: </p> <ul> <li>Faster to learn. </li> <li>Ease of use. </li> <li>Have widgets for rapid development(From a GUI perspective). </li> <li>Database integration.</li> </ul> <p>I would ...
3
2009-09-21T02:44:48Z
15,717,155
<p>You can build an runnable Java Web application within 5 to 10 minutes by using the following online Java web application generator:</p> <p><a href="http://www.webappexpress.net" rel="nofollow">http://www.webappexpress.net</a></p>
0
2013-03-30T09:48:55Z
[ "java", "php", "python", "ruby-on-rails" ]
Creating Simultaneous Loops in Python
1,452,694
<p>I want to create a loop who has this sense:</p> <pre> for i in xrange(0,10): for k in xrange(0,10): z=k+i print z where the output should be 0 2 4 6 8 10 12 14 16 18 </pre>
3
2009-09-21T02:59:57Z
1,452,705
<p>What you want is two arrays and one loop, iterate over each array once, adding the results.</p>
0
2009-09-21T03:03:34Z
[ "python", "loops" ]
Creating Simultaneous Loops in Python
1,452,694
<p>I want to create a loop who has this sense:</p> <pre> for i in xrange(0,10): for k in xrange(0,10): z=k+i print z where the output should be 0 2 4 6 8 10 12 14 16 18 </pre>
3
2009-09-21T02:59:57Z
1,452,706
<p>You can do this in python - just have to make the tabs right and use the xrange argument for step.</p> <p><code>for i in xrange(0, 20, 2); print i </code></p>
2
2009-09-21T03:04:02Z
[ "python", "loops" ]
Creating Simultaneous Loops in Python
1,452,694
<p>I want to create a loop who has this sense:</p> <pre> for i in xrange(0,10): for k in xrange(0,10): z=k+i print z where the output should be 0 2 4 6 8 10 12 14 16 18 </pre>
3
2009-09-21T02:59:57Z
1,452,709
<p>The <a href="http://docs.python.org/library/itertools.html"><code>itertools</code></a> module contains an <a href="http://docs.python.org/library/itertools.html#itertools.izip"><code>izip</code></a> function that combines iterators in the desired way:</p> <pre><code>from itertools import izip for (i, k) in izip(xr...
10
2009-09-21T03:04:48Z
[ "python", "loops" ]
Creating Simultaneous Loops in Python
1,452,694
<p>I want to create a loop who has this sense:</p> <pre> for i in xrange(0,10): for k in xrange(0,10): z=k+i print z where the output should be 0 2 4 6 8 10 12 14 16 18 </pre>
3
2009-09-21T02:59:57Z
1,452,711
<p>You can use <a href="http://docs.python.org/library/functions.html#zip"><code>zip</code></a> to turn multiple lists (or iterables) into pairwise* tuples:</p> <pre><code>&gt;&gt;&gt; for a,b in zip(xrange(10), xrange(10)): ... print a+b ... 0 2 4 6 8 10 12 14 16 18 </code></pre> <p>But <code>zip</code> will no...
11
2009-09-21T03:05:18Z
[ "python", "loops" ]
Creating Simultaneous Loops in Python
1,452,694
<p>I want to create a loop who has this sense:</p> <pre> for i in xrange(0,10): for k in xrange(0,10): z=k+i print z where the output should be 0 2 4 6 8 10 12 14 16 18 </pre>
3
2009-09-21T02:59:57Z
1,452,731
<p>What about this?</p> <pre><code>i = range(0,10) k = range(0,10) for x in range(0,10): z=k[x]+i[x] print z </code></pre> <p>0 2 4 6 8 10 12 14 16 18</p>
1
2009-09-21T03:10:50Z
[ "python", "loops" ]
RTSP library in Python or C/C++?
1,452,710
<p>I am trying to find any RTSP streaming library for Python or C/C++. </p> <p>If not is there any other solutions for real time streaming? How much easy or difficult it is to implement RTSP in Python or C/C++ and where to get started?</p>
2
2009-09-21T03:05:07Z
1,452,756
<p>With Python and Twisted, you could use <a href="http://www.flumotion.net/doc/flumotion/reference/trunk/flumotion.twisted.rtsp-module.html" rel="nofollow">this module</a>.</p>
2
2009-09-21T03:20:39Z
[ "c++", "python", "c", "rtsp" ]
RTSP library in Python or C/C++?
1,452,710
<p>I am trying to find any RTSP streaming library for Python or C/C++. </p> <p>If not is there any other solutions for real time streaming? How much easy or difficult it is to implement RTSP in Python or C/C++ and where to get started?</p>
2
2009-09-21T03:05:07Z
1,453,259
<p>try <a href="http://www.live555.com" rel="nofollow">live555</a>. They have a lots of libraries and modules for implementing rtp and rtsp (as well as sip) into your c and c++ programs</p>
4
2009-09-21T07:33:35Z
[ "c++", "python", "c", "rtsp" ]
Is there an C++ equivalent to Python's "import bigname as b"?
1,452,883
<p>I've always liked Python's</p> <pre><code>import big_honkin_name as bhn </code></pre> <p>so you can then just use <code>bhn.thing</code> rather than the considerably more verbose <code>big_honkin_name.thing</code> in your source.</p> <p>I've seen two type of namespace use in C++ code, either:</p> <pre><code>usin...
4
2009-09-21T04:18:50Z
1,452,891
<p><a href="http://stackoverflow.com/questions/75538/hidden-features-of-c/78484#78484">StackOverflow to the rescue!</a> Yes you can. In short:</p> <pre><code>namespace bhn = big_honkin_name; </code></pre>
12
2009-09-21T04:24:32Z
[ "c++", "python", "namespaces", "alias" ]
Is there an C++ equivalent to Python's "import bigname as b"?
1,452,883
<p>I've always liked Python's</p> <pre><code>import big_honkin_name as bhn </code></pre> <p>so you can then just use <code>bhn.thing</code> rather than the considerably more verbose <code>big_honkin_name.thing</code> in your source.</p> <p>I've seen two type of namespace use in C++ code, either:</p> <pre><code>usin...
4
2009-09-21T04:18:50Z
1,452,894
<p>It is easy..</p> <pre><code>namespace bhn = big_honkin_name; </code></pre>
6
2009-09-21T04:25:49Z
[ "c++", "python", "namespaces", "alias" ]
Is there an C++ equivalent to Python's "import bigname as b"?
1,452,883
<p>I've always liked Python's</p> <pre><code>import big_honkin_name as bhn </code></pre> <p>so you can then just use <code>bhn.thing</code> rather than the considerably more verbose <code>big_honkin_name.thing</code> in your source.</p> <p>I've seen two type of namespace use in C++ code, either:</p> <pre><code>usin...
4
2009-09-21T04:18:50Z
1,452,896
<p>You can use</p> <pre><code>using big_honkin_name::fn; </code></pre> <p>to import all functions named <code>fn</code> from the namespace <code>big_honkin_name</code>, so that you can then write</p> <pre><code>int a = fn(27); </code></pre> <p>But that doesn't let you shrink down the name itself. To do (something ...
2
2009-09-21T04:26:27Z
[ "c++", "python", "namespaces", "alias" ]
Is there an C++ equivalent to Python's "import bigname as b"?
1,452,883
<p>I've always liked Python's</p> <pre><code>import big_honkin_name as bhn </code></pre> <p>so you can then just use <code>bhn.thing</code> rather than the considerably more verbose <code>big_honkin_name.thing</code> in your source.</p> <p>I've seen two type of namespace use in C++ code, either:</p> <pre><code>usin...
4
2009-09-21T04:18:50Z
1,452,905
<pre><code>namespace bhn = big_honkin_name; </code></pre> <p>There's another way to use namespaces too:</p> <pre><code>using big_honkin_name::fn; int a = fn(27); </code></pre>
11
2009-09-21T04:28:42Z
[ "c++", "python", "namespaces", "alias" ]
Is there an C++ equivalent to Python's "import bigname as b"?
1,452,883
<p>I've always liked Python's</p> <pre><code>import big_honkin_name as bhn </code></pre> <p>so you can then just use <code>bhn.thing</code> rather than the considerably more verbose <code>big_honkin_name.thing</code> in your source.</p> <p>I've seen two type of namespace use in C++ code, either:</p> <pre><code>usin...
4
2009-09-21T04:18:50Z
1,454,622
<pre><code>using namespace big_honkin_name; </code></pre> <p>Is not a bad thing. Not at all. Used judiciously, bringing namespaces into scope <em>improves</em> clarity of code by removing unnecessary clutter.</p> <p>(Unless it's in a header file in which case it's <em>very</em> poor practice.)</p> <p>But yes, as o...
1
2009-09-21T13:53:32Z
[ "c++", "python", "namespaces", "alias" ]
Why doesn't a python dict.update() return the object?
1,452,995
<p>I 'm trying to do :</p> <pre><code>award_dict = { "url" : "http://facebook.com", "imageurl" : "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count" : 1, } def award(name, count, points, desc_string, my_size, parent) : if my_size &gt; count : a = { "name" : n...
56
2009-09-21T05:20:43Z
1,452,998
<p>Its not that it isn't acceptable, but rather that <code>dicts</code> weren't implemented that way.</p> <p>If you look at Django's ORM, it makes extensive use of chaining. Its not discouraged, you could even inherit from <code>dict</code> and only override <code>update</code> to do update and <code>return self</code...
2
2009-09-21T05:24:41Z
[ "python", "language-features", "language-design", "monads" ]
Why doesn't a python dict.update() return the object?
1,452,995
<p>I 'm trying to do :</p> <pre><code>award_dict = { "url" : "http://facebook.com", "imageurl" : "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count" : 1, } def award(name, count, points, desc_string, my_size, parent) : if my_size &gt; count : a = { "name" : n...
56
2009-09-21T05:20:43Z
1,453,011
<p>Python's API, by convention, distinguishes between procedures and functions. Functions compute new values out of their parameters (including any target object); procedures modify objects and don't return anything (i.e. they return None). So procedures have side effects, functions don't. update is a procedure, hence ...
24
2009-09-21T05:29:52Z
[ "python", "language-features", "language-design", "monads" ]
Why doesn't a python dict.update() return the object?
1,452,995
<p>I 'm trying to do :</p> <pre><code>award_dict = { "url" : "http://facebook.com", "imageurl" : "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count" : 1, } def award(name, count, points, desc_string, my_size, parent) : if my_size &gt; count : a = { "name" : n...
56
2009-09-21T05:20:43Z
1,453,013
<p>Python's mostly implementing a pragmatically tinged flavor of <a href="http://en.wikipedia.org/wiki/Command-query%5Fseparation">command-query separation</a>: mutators return <code>None</code> (with pragmatically induced exceptions such as <code>pop</code>;-) so they can't possibly be confused with accessors (and in ...
105
2009-09-21T05:31:28Z
[ "python", "language-features", "language-design", "monads" ]
Why doesn't a python dict.update() return the object?
1,452,995
<p>I 'm trying to do :</p> <pre><code>award_dict = { "url" : "http://facebook.com", "imageurl" : "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count" : 1, } def award(name, count, points, desc_string, my_size, parent) : if my_size &gt; count : a = { "name" : n...
56
2009-09-21T05:20:43Z
10,731,332
<pre><code>&gt;&gt;&gt; dict_merge = lambda a,b: a.update(b) or a &gt;&gt;&gt; dict_merge({'a':1, 'b':3},{'c':5}) {'a': 1, 'c': 5, 'b': 3} </code></pre> <p>Note that as well as returning the merged dict, it modifies the first parameter in-place. So dict_merge(a,b) will modify a.</p> <p>Or, of course, you can do it al...
5
2012-05-24T04:50:13Z
[ "python", "language-features", "language-design", "monads" ]
Why doesn't a python dict.update() return the object?
1,452,995
<p>I 'm trying to do :</p> <pre><code>award_dict = { "url" : "http://facebook.com", "imageurl" : "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count" : 1, } def award(name, count, points, desc_string, my_size, parent) : if my_size &gt; count : a = { "name" : n...
56
2009-09-21T05:20:43Z
16,070,292
<pre><code>import itertools dict_merge = lambda *args: dict(itertools.chain(*[d.iteritems() for d in args])) </code></pre>
1
2013-04-17T21:07:50Z
[ "python", "language-features", "language-design", "monads" ]
Why doesn't a python dict.update() return the object?
1,452,995
<p>I 'm trying to do :</p> <pre><code>award_dict = { "url" : "http://facebook.com", "imageurl" : "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count" : 1, } def award(name, count, points, desc_string, my_size, parent) : if my_size &gt; count : a = { "name" : n...
56
2009-09-21T05:20:43Z
34,782,171
<p><em>not enough reputation for comment left on top answer</em></p> <p>@beardc this doesn't seem to be CPython thing. PyPy gives me "TypeError: keywords must be strings"</p> <p>The solution with <code>**kwargs</code> only works because the dictionary to be merged only has <strong>keys of type string</strong>.</p> <...
2
2016-01-14T05:14:42Z
[ "python", "language-features", "language-design", "monads" ]
Should I create mapper objects or use the declarative syntax in SQLAlchemy?
1,453,219
<p>There are two (three, but I'm not counting <a href="http://elixir.ematia.de/trac/wiki">Elixir</a>, as its not "official") ways to define a persisting object with <a href="http://www.sqlalchemy.org">SQLAlchemy</a>:</p> <h3><a href="http://www.sqlalchemy.org/docs/05/mappers.html">Explicit syntax for mapper objects</a...
32
2009-09-21T07:19:43Z
1,453,881
<p>"What I'm not completely sure, is which approach is more maintainable for a business application?"</p> <p>Can't be answered in general.</p> <p>However, consider this.</p> <p>The Django ORM is strictly declarative -- and people like that.</p> <p>SQLAlchemy does several things, not all of which are relevant to all...
19
2009-09-21T10:39:11Z
[ "python", "sqlalchemy" ]
Should I create mapper objects or use the declarative syntax in SQLAlchemy?
1,453,219
<p>There are two (three, but I'm not counting <a href="http://elixir.ematia.de/trac/wiki">Elixir</a>, as its not "official") ways to define a persisting object with <a href="http://www.sqlalchemy.org">SQLAlchemy</a>:</p> <h3><a href="http://www.sqlalchemy.org/docs/05/mappers.html">Explicit syntax for mapper objects</a...
32
2009-09-21T07:19:43Z
1,453,888
<p>In our team we settled on declarative syntax.</p> <p>Rationale:</p> <ul> <li><code>metadata</code> is trivial to get to, if needed: <code>User.metadata</code>.</li> <li>Your <code>User</code> class, by virtue of subclassing <code>Base</code>, has a nice ctor that takes kwargs for all fields. Useful for testing and...
13
2009-09-21T10:40:24Z
[ "python", "sqlalchemy" ]