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
Scale 2D coordinates and keep their relative euclidean distances intact?
2,450,035
<p>I have a set of points like: pointA(3302.34,9392.32), pointB(34322.32,11102.03), etc.</p> <p>I need to scale these so each x- and y-coordinate is in the range (0.0 - 1.0). I tried doing this by first finding the largest x value in the data set (maximum_x_value), and the largest y value in the set (minimum_y_value)....
5
2010-03-15T19:53:27Z
2,450,071
<p>You have to scale them by the same factor to keep the distances the same. </p> <p>I'd forget about subtracting the minimum (Note: this part is only true if the points are always positive, which is my usual use case), and just divide by the maximum of the two maxes:</p> <pre><code>maxval = max(max(A.x), max(A.y)) #...
3
2010-03-15T19:58:49Z
[ "python", "math", "coordinates", "scale" ]
Scale 2D coordinates and keep their relative euclidean distances intact?
2,450,035
<p>I have a set of points like: pointA(3302.34,9392.32), pointB(34322.32,11102.03), etc.</p> <p>I need to scale these so each x- and y-coordinate is in the range (0.0 - 1.0). I tried doing this by first finding the largest x value in the data set (maximum_x_value), and the largest y value in the set (minimum_y_value)....
5
2010-03-15T19:53:27Z
2,450,075
<p>You need to scale the <code>x</code> values and the <code>y</code> values by the same amount! I would suggest scaling by the larger of the two ranges (either <code>x</code> or <code>y</code>). In pseudocode, you'd have something like </p> <pre><code>scale = max(maximum_x_value - minimum_x_value, maximum...
9
2010-03-15T19:59:25Z
[ "python", "math", "coordinates", "scale" ]
Scale 2D coordinates and keep their relative euclidean distances intact?
2,450,035
<p>I have a set of points like: pointA(3302.34,9392.32), pointB(34322.32,11102.03), etc.</p> <p>I need to scale these so each x- and y-coordinate is in the range (0.0 - 1.0). I tried doing this by first finding the largest x value in the data set (maximum_x_value), and the largest y value in the set (minimum_y_value)....
5
2010-03-15T19:53:27Z
2,450,158
<p>Assuming you want your entire data set to be centered on <code>(0.5, 0.5)</code> with a range of <code>(0,1)</code> in both axes, it's easiest to think of the total transformation needed in three steps: </p> <ol> <li>Center the data on the origin:<br> <code>P.x -= (maxX - minX) / 2</code><br> <code>P.y -= (maxY - m...
4
2010-03-15T20:16:04Z
[ "python", "math", "coordinates", "scale" ]
Scale 2D coordinates and keep their relative euclidean distances intact?
2,450,035
<p>I have a set of points like: pointA(3302.34,9392.32), pointB(34322.32,11102.03), etc.</p> <p>I need to scale these so each x- and y-coordinate is in the range (0.0 - 1.0). I tried doing this by first finding the largest x value in the data set (maximum_x_value), and the largest y value in the set (minimum_y_value)....
5
2010-03-15T19:53:27Z
2,450,241
<p><strong>Step 1: Re-Locate the origin</strong><br> Let your new "origin" be (<code>minimum_x_value</code>, <code>minimum_y_value</code>). Shift all your data points by subtracting <code>minimum_x_value</code> from all x-coordinates and by subtracting <code>minimum_y_value</code> from all y-coordinates.</p> <p><stro...
3
2010-03-15T20:26:53Z
[ "python", "math", "coordinates", "scale" ]
String formatting error
2,450,188
<p>Using the code <code>print('{0} is not'.format('That that is not'))</code> in Python 3.1.1, I get the following error:</p> <pre><code>AttributeError: 'str' object has no attribute 'format' </code></pre> <p>when I delete the line Netbeans automatically inserted at the beginning:</p> <pre><code>from distutils.comma...
1
2010-03-15T20:19:57Z
2,450,296
<p>You must be running an older version of Python. This does work in Python 3.1.1+:</p> <pre><code>$ python3 Python 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; '{0} is not'.format('That that is not') 'That that is...
6
2010-03-15T20:36:38Z
[ "python", "string", "format" ]
Python Bitstream implementations
2,450,208
<p>I am writing a <a href="http://en.wikipedia.org/wiki/Huffman_coding">huffman</a> implementation in Python as a learning exercise. I have got to the point of writing out my variable length huffman codes to a buffer (or file). Only to find there does not seem to be a bitstream class implemented by Python! I have ha...
7
2010-03-15T20:22:37Z
2,450,235
<p>Correct. Most of the modules in the stdlib that need bitstreaming are written in C, with the details hidden away.</p>
1
2010-03-15T20:25:59Z
[ "python", "bitstream" ]
Python Bitstream implementations
2,450,208
<p>I am writing a <a href="http://en.wikipedia.org/wiki/Huffman_coding">huffman</a> implementation in Python as a learning exercise. I have got to the point of writing out my variable length huffman codes to a buffer (or file). Only to find there does not seem to be a bitstream class implemented by Python! I have ha...
7
2010-03-15T20:22:37Z
2,450,287
<p>No, as far as I know there's nothing in the standard library that helps you with bit-aligned operations. Python is not designed to fiddle with the small stuff ^^...</p> <p>But you could easily write your own bitstream-writer with the help of byte arrays:</p> <pre><code>&gt;&gt;&gt; from array import array &gt;&gt;...
1
2010-03-15T20:35:17Z
[ "python", "bitstream" ]
Python Bitstream implementations
2,450,208
<p>I am writing a <a href="http://en.wikipedia.org/wiki/Huffman_coding">huffman</a> implementation in Python as a learning exercise. I have got to the point of writing out my variable length huffman codes to a buffer (or file). Only to find there does not seem to be a bitstream class implemented by Python! I have ha...
7
2010-03-15T20:22:37Z
2,450,735
<p>You're right that there's nothing in the standard library, but have you tried the <a href="http://python-bitstring.googlecode.com">bitstring</a> module? It's pretty much designed for this kind of application, is stable and <a href="http://python-bitstring.googlecode.com/svn/tags/bitstring-1.3.0/doc/html/index.html">...
9
2010-03-15T21:49:28Z
[ "python", "bitstream" ]
Python Bitstream implementations
2,450,208
<p>I am writing a <a href="http://en.wikipedia.org/wiki/Huffman_coding">huffman</a> implementation in Python as a learning exercise. I have got to the point of writing out my variable length huffman codes to a buffer (or file). Only to find there does not seem to be a bitstream class implemented by Python! I have ha...
7
2010-03-15T20:22:37Z
30,532,453
<p>I'm perhaps a little late to the party, but there is this bitstream library:</p> <p><a href="https://pypi.python.org/pypi/bitstream/2.0.3" rel="nofollow">https://pypi.python.org/pypi/bitstream/2.0.3</a></p>
0
2015-05-29T14:40:08Z
[ "python", "bitstream" ]
decrypt excel files
2,450,530
<p>Hi I have 1000 encrypted workbooks which I would like to decrypt by providing a pwd. I could not find a decrypt method under apache poi or python's xlrd module.</p> <p>Does anyone know a library which could handle this (<code>wbc.decrypt(pwd)</code>). I would prefer a lib i could you use from a unix box.</p> <p>Th...
3
2010-03-15T21:12:45Z
2,450,773
<p>Use the COM bindings to call the <code>Unprotect</code> method.</p> <pre><code>import win32com.client excel = win32com.client.Dispatch('Excel.Application') workbook = excel.Workbooks.open(r'c:\mybook.xls', 'password') workbook.SaveAs('unencrypted.xls') </code></pre> <p>SaveAs can apply a new password. See: <a h...
5
2010-03-15T21:56:08Z
[ "python", "excel", "apache-poi" ]
decrypt excel files
2,450,530
<p>Hi I have 1000 encrypted workbooks which I would like to decrypt by providing a pwd. I could not find a decrypt method under apache poi or python's xlrd module.</p> <p>Does anyone know a library which could handle this (<code>wbc.decrypt(pwd)</code>). I would prefer a lib i could you use from a unix box.</p> <p>Th...
3
2010-03-15T21:12:45Z
6,175,793
<p><a href="http://poi.apache.org/" rel="nofollow">Apache POI</a> can read encrypted excel files for you, and write them out decrypted. See the <a href="http://poi.apache.org/encryption.html" rel="nofollow">Encryption</a> page to get started.</p>
1
2011-05-30T11:38:58Z
[ "python", "excel", "apache-poi" ]
How do you get SQLAlchemy to override MySQL "on update CURRENT_TIMESTAMP"
2,450,593
<p>I've inherited an older database that was setup with a "on update CURRENT_TIMESTAMP" put on a field that should only describe an item's creation. With PHP I have been using "timestamp=timestamp" on UPDATE clauses, but in SQLAlchemy I can't seem to force the system to use the set timestamp.</p> <p>Do I have no choi...
3
2010-03-15T21:22:41Z
2,454,848
<p>SQLAlchemy doesn't try to set the field because it thinks the value hasn't changed.</p> <p>You can tell SQLAlchemy to reassign the value by specifying the onupdate attribute on the Column:</p> <pre><code> Column('timestamp', ..., onupdate=literal_column('timestamp')) </code></pre> <p>This will result in SQLAlchem...
6
2010-03-16T13:53:43Z
[ "python", "mysql", "sqlalchemy" ]
How to resize QInputDialog, PyQt
2,450,682
<p>I am getting input with this here</p> <pre><code>areaInput = QtGui.QInputDialog.getText(self, "Copy Area", "New Area Name:", 0) </code></pre> <p>However I would like to make the dialog box larger, I've tried things such as</p> <pre><code>QtGui.QInputDialog.resize(400, 400) </code></pre> <p>However it says "the f...
1
2010-03-15T21:38:46Z
2,450,860
<p>That error implies that you're not calling an instance method with an instance.</p> <p><code>QtGui.QInputDialog.getText()</code> is a static method and doesn't return you a <code>QWidget</code> instance, so you can't call <code>resize()</code> on it.</p> <p>If you want to call <code>resize()</code>, you need to cr...
4
2010-03-15T22:17:47Z
[ "python", "qt", "pyqt" ]
How to resize QInputDialog, PyQt
2,450,682
<p>I am getting input with this here</p> <pre><code>areaInput = QtGui.QInputDialog.getText(self, "Copy Area", "New Area Name:", 0) </code></pre> <p>However I would like to make the dialog box larger, I've tried things such as</p> <pre><code>QtGui.QInputDialog.resize(400, 400) </code></pre> <p>However it says "the f...
1
2010-03-15T21:38:46Z
9,680,643
<p>I had the same problem. Mainly that the window was too narrow horizontally, making the text edit input field small. I ended up putting lots of whitespace after the text in the label argument. Worked fine for me.</p>
2
2012-03-13T08:37:20Z
[ "python", "qt", "pyqt" ]
How to resize QInputDialog, PyQt
2,450,682
<p>I am getting input with this here</p> <pre><code>areaInput = QtGui.QInputDialog.getText(self, "Copy Area", "New Area Name:", 0) </code></pre> <p>However I would like to make the dialog box larger, I've tried things such as</p> <pre><code>QtGui.QInputDialog.resize(400, 400) </code></pre> <p>However it says "the f...
1
2010-03-15T21:38:46Z
11,793,713
<p>it is possible by doing this:</p> <pre><code>dlg = QtGui.QInputDialog(self) dlg.setInputMode( QtGui.QInputDialog.TextInput) dlg.setLabelText("URL:") dlg.resize(500,100) ok = dlg.exec_() url = dlg.textValue() </co...
1
2012-08-03T10:14:45Z
[ "python", "qt", "pyqt" ]
How to write services with CPython?
2,450,839
<p>Does CPython have any library that helps to write binding-independent services?</p> <p>I have found some SOAP libraries for Python, but it misses the flexibility of choosing the binding at runtime.</p>
0
2010-03-15T22:12:35Z
2,451,371
<p>Packages such as <a href="http://docs.python.org/library/simplexmlrpcserver.html?highlight=xml%20rpc%20servers#module-SimpleXMLRPCServer" rel="nofollow">SimpleXMLRPCServer</a> (part of the Python standard library), <a href="http://www.freenet.org.nz/dojo/pyjson/" rel="nofollow">SimpleJSONRPCServer</a>, and probably ...
2
2010-03-16T00:17:34Z
[ "python", "soap", "service", "soa", "cpython" ]
Storing multiple discarded datas in a single variable using a string accumulator
2,450,898
<p>For an assignment for my intro to python course, we are to write a program that generates 100 sets of x,y coordinates.</p> <p>X must be a float between -100.0 and 100.0 inclusive, but not 0. Y is Y = ((1/x) * 3070) but if the absolute value of Y is greater than 100, both numbers must be discarded (BUT STORED) and a...
2
2010-03-15T22:26:34Z
2,450,975
<p>You can convert a number to a string like so:</p> <pre><code>x = 100.0 xstr = str(x) </code></pre> <p>You can add on to a string like so:</p> <pre><code>xstr += 'another string' </code></pre> <p>It's also ok to have an empty string:</p> <pre><code>emptystring = '' </code></pre> <p>Hopefully those ideas will ge...
0
2010-03-15T22:41:10Z
[ "python" ]
Storing multiple discarded datas in a single variable using a string accumulator
2,450,898
<p>For an assignment for my intro to python course, we are to write a program that generates 100 sets of x,y coordinates.</p> <p>X must be a float between -100.0 and 100.0 inclusive, but not 0. Y is Y = ((1/x) * 3070) but if the absolute value of Y is greater than 100, both numbers must be discarded (BUT STORED) and a...
2
2010-03-15T22:26:34Z
2,450,981
<p>You can turn the variable into a string representation using <code>str(y)</code>. To control formatting you can use string interpolation e.g. <code>"%.3f" % y</code>.</p> <p>You can add strings together and assign the results to a variable. E.g.:</p> <pre><code>string_a = string_b + string_c </code></pre> <p>or:<...
0
2010-03-15T22:41:52Z
[ "python" ]
Storing multiple discarded datas in a single variable using a string accumulator
2,450,898
<p>For an assignment for my intro to python course, we are to write a program that generates 100 sets of x,y coordinates.</p> <p>X must be a float between -100.0 and 100.0 inclusive, but not 0. Y is Y = ((1/x) * 3070) but if the absolute value of Y is greater than 100, both numbers must be discarded (BUT STORED) and a...
2
2010-03-15T22:26:34Z
2,450,984
<p>Very simple. You can "turn numbers into strings" using the formatting operator (<code>%</code>), as follows:</p> <pre><code>import random def getRandomX(): x = 0 while not x: x = random.uniform(-100.0, 100.0) return x def main(): discarded = '' for i in range(100): x = getRand...
0
2010-03-15T22:42:36Z
[ "python" ]
Storing multiple discarded datas in a single variable using a string accumulator
2,450,898
<p>For an assignment for my intro to python course, we are to write a program that generates 100 sets of x,y coordinates.</p> <p>X must be a float between -100.0 and 100.0 inclusive, but not 0. Y is Y = ((1/x) * 3070) but if the absolute value of Y is greater than 100, both numbers must be discarded (BUT STORED) and a...
2
2010-03-15T22:26:34Z
2,451,419
<p>"string accumulator" is not a Python "terms of art". Maybe the teacher meant "accumulate it all into a single string" (a horrible approach in Python), or maybe (if the course has already covered lists) he mean a <em>list</em> of strings (the proper Python approach).</p> <p>Other answers already cover the first pos...
1
2010-03-16T00:33:02Z
[ "python" ]
How can I make a wxPython app constantly update and execute code?
2,450,972
<p>Given the following simple program:</p> <pre><code>import wx class TestDraw(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) self.SetBackgroundColour("#FFFFFF") self.Bind(wx.EVT_PAINT,self.onPaint) self.SetDoubleBuffered(T...
0
2010-03-15T22:40:13Z
2,451,064
<p>Your can use a <a href="http://www.wxpython.org/docs/api/wx.Timer-class.html" rel="nofollow">wxTimer</a> to periodically call an <code>onTimer(self)</code> method.</p>
3
2010-03-15T22:59:40Z
[ "python", "user-interface", "wxpython" ]
Creating a Colormap Legend in Matplotlib
2,451,264
<p>I am using imshow() in matplotlib like so:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt mat = '''SOME MATRIX''' plt.imshow(mat, origin="lower", cmap='gray', interpolation='nearest') plt.show() </code></pre> <p>How do I add a legend showing the numeric value for the different shades of gray. Sa...
13
2010-03-15T23:47:26Z
2,451,315
<p>As usual, I figure it out right after I ask it ;). For posterity, here's my stab at it:</p> <pre><code>m = np.zeros((1,20)) for i in range(20): m[0,i] = (i*5)/100.0 print m plt.imshow(m, cmap='gray', aspect=2) plt.yticks(np.arange(0)) plt.xticks(np.arange(0,25,5), [0,25,50,75,100]) plt.show() </code></pre> <p>...
0
2010-03-16T00:01:00Z
[ "python", "matplotlib" ]
Creating a Colormap Legend in Matplotlib
2,451,264
<p>I am using imshow() in matplotlib like so:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt mat = '''SOME MATRIX''' plt.imshow(mat, origin="lower", cmap='gray', interpolation='nearest') plt.show() </code></pre> <p>How do I add a legend showing the numeric value for the different shades of gray. Sa...
13
2010-03-15T23:47:26Z
2,451,365
<p>There's a builtin <a href="http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.colorbar">colorbar() function</a> in pyplot.</p>
21
2010-03-16T00:15:41Z
[ "python", "matplotlib" ]
can't figure out serving static images in django dev environment
2,451,352
<p>I've read <a href="http://docs.djangoproject.com/en/dev/howto/static-files/" rel="nofollow">the article</a> (and few others on the subject), but still can't figure out how to show an image unless a link to a file existing on a web-service is hard-coded into the html template.</p> <p>I've got in <b>urls.py</b>:</p> ...
2
2010-03-16T00:12:30Z
2,451,389
<p>This looks buggy...:</p> <pre><code>r'^galleries/(landscapes)/(?P&lt;path&gt;.jpg)$' </code></pre> <p>this RE will only match image names with a single character begore the <code>jpg</code> suffix, not four (as in, e.g., <code>'160.jpg'</code>). Maybe you meant...</p> <pre><code>r'^galleries/(landscapes)/(?P&lt;...
5
2010-03-16T00:22:32Z
[ "python", "django", "image" ]
can't figure out serving static images in django dev environment
2,451,352
<p>I've read <a href="http://docs.djangoproject.com/en/dev/howto/static-files/" rel="nofollow">the article</a> (and few others on the subject), but still can't figure out how to show an image unless a link to a file existing on a web-service is hard-coded into the html template.</p> <p>I've got in <b>urls.py</b>:</p> ...
2
2010-03-16T00:12:30Z
2,451,473
<p>This is a long post, basically summarizing all the things I learned about Django in order to get static files to work (it took me a while to understand how all the different parts fit together). </p> <p>To serve static images in your development server (and later, your real server), you're going to have to do a few...
10
2010-03-16T00:51:42Z
[ "python", "django", "image" ]
can't figure out serving static images in django dev environment
2,451,352
<p>I've read <a href="http://docs.djangoproject.com/en/dev/howto/static-files/" rel="nofollow">the article</a> (and few others on the subject), but still can't figure out how to show an image unless a link to a file existing on a web-service is hard-coded into the html template.</p> <p>I've got in <b>urls.py</b>:</p> ...
2
2010-03-16T00:12:30Z
2,456,447
<p>Take this as a cross between the two previous answers, both of which are good. First, your regex is incorrect as Alex pointed out. I would suggest setting it as:</p> <pre><code> (r'^local_media/(?P&lt;path&gt;.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}), # static content </code></pre...
1
2010-03-16T17:01:20Z
[ "python", "django", "image" ]
What does the caret operator (^) in Python do?
2,451,386
<p>I ran across the caret operator in python today and trying it out, I got the following output:</p> <pre><code>&gt;&gt;&gt; 8^3 11 &gt;&gt;&gt; 8^4 12 &gt;&gt;&gt; 8^1 9 &gt;&gt;&gt; 8^0 8 &gt;&gt;&gt; 7^1 6 &gt;&gt;&gt; 7^2 5 &gt;&gt;&gt; 7^7 0 &gt;&gt;&gt; 7^8 15 &gt;&gt;&gt; 9^1 8 &gt;&gt;&gt; 16^1 17 &gt;&gt;&gt...
48
2010-03-16T00:21:41Z
2,451,392
<p>It's a bit-by-bit exclusive-or. Binary bitwise operators are documented in <a href="https://docs.python.org/2/reference/expressions.html#binary-bitwise-operations" rel="nofollow">chapter 5 of the Python Language Reference</a>.</p>
12
2010-03-16T00:23:37Z
[ "python", "operators", "caret" ]
What does the caret operator (^) in Python do?
2,451,386
<p>I ran across the caret operator in python today and trying it out, I got the following output:</p> <pre><code>&gt;&gt;&gt; 8^3 11 &gt;&gt;&gt; 8^4 12 &gt;&gt;&gt; 8^1 9 &gt;&gt;&gt; 8^0 8 &gt;&gt;&gt; 7^1 6 &gt;&gt;&gt; 7^2 5 &gt;&gt;&gt; 7^7 0 &gt;&gt;&gt; 7^8 15 &gt;&gt;&gt; 9^1 8 &gt;&gt;&gt; 16^1 17 &gt;&gt;&gt...
48
2010-03-16T00:21:41Z
2,451,393
<p>It's a bitwise <a href="http://en.wikipedia.org/wiki/Exclusive_or">XOR</a> (exclusive OR).</p> <p>It results to true if <strong>one</strong> (and only one) of the operands (evaluates to) true.</p> <p>To demonstrate:</p> <pre><code>&gt;&gt;&gt; 0^0 0 &gt;&gt;&gt; 1^1 0 &gt;&gt;&gt; 1^0 1 &gt;&gt;&gt; 0^1 1 </code>...
77
2010-03-16T00:23:59Z
[ "python", "operators", "caret" ]
What does the caret operator (^) in Python do?
2,451,386
<p>I ran across the caret operator in python today and trying it out, I got the following output:</p> <pre><code>&gt;&gt;&gt; 8^3 11 &gt;&gt;&gt; 8^4 12 &gt;&gt;&gt; 8^1 9 &gt;&gt;&gt; 8^0 8 &gt;&gt;&gt; 7^1 6 &gt;&gt;&gt; 7^2 5 &gt;&gt;&gt; 7^7 0 &gt;&gt;&gt; 7^8 15 &gt;&gt;&gt; 9^1 8 &gt;&gt;&gt; 16^1 17 &gt;&gt;&gt...
48
2010-03-16T00:21:41Z
2,451,434
<p>It invokes the <code>__xor__()</code> or <code>__rxor__()</code> method of the object as needed, which for integer types does a bitwise exclusive-or.</p>
31
2010-03-16T00:37:06Z
[ "python", "operators", "caret" ]
What does the caret operator (^) in Python do?
2,451,386
<p>I ran across the caret operator in python today and trying it out, I got the following output:</p> <pre><code>&gt;&gt;&gt; 8^3 11 &gt;&gt;&gt; 8^4 12 &gt;&gt;&gt; 8^1 9 &gt;&gt;&gt; 8^0 8 &gt;&gt;&gt; 7^1 6 &gt;&gt;&gt; 7^2 5 &gt;&gt;&gt; 7^7 0 &gt;&gt;&gt; 7^8 15 &gt;&gt;&gt; 9^1 8 &gt;&gt;&gt; 16^1 17 &gt;&gt;&gt...
48
2010-03-16T00:21:41Z
19,451,108
<p>Generally speaking, the symbol <code>^</code> is an <a href="https://en.wikipedia.org/wiki/Infix_notation" rel="nofollow">infix</a> version of the <code>__xor__</code> or <code>__rxor__</code> methods. Whatever data types are placed to the right and left of the symbol must implement this function in a compatible way...
7
2013-10-18T13:37:07Z
[ "python", "operators", "caret" ]
Deleting object in function
2,451,467
<p>Let's say I have created two objects from class <code>foo</code> and now want to combine the two. How, if at all possible, can I accomplish that within a function like this:</p> <pre><code>def combine(first, second): first.value += second.value del second #this doesn't work, though first.value *does* get ch...
1
2010-03-16T00:49:47Z
2,451,476
<p>No. All <code>del</code> does against names is unbind them. This only removes the local reference. The object will be destroyed when there are no references to it anywhere, or all the references are in a reference loop.</p>
4
2010-03-16T00:52:07Z
[ "python", "function", "python-3.x" ]
How can I draw to a MemoryDC using the GraphicsContext, and then blit that to a PaintDC?
2,451,610
<p>I'm looking to add double buffering to a drawing function like this.</p> <pre><code> dc = wx.PaintDC(self) gc = wx.GraphicsContext.Create(dc) #draw GraphicsPaths to the gc </code></pre> <p>I tried to first draw to a MemoryDC and then blit that back to the PaintDC:</p> <pre><code> dc = wx.MemoryDC() ...
0
2010-03-16T01:39:35Z
2,451,751
<p>You need to create a bitmap, not use wx.NullBitmap.</p> <pre><code>bitmap = wx.EmptyBitmap(w, h) dc = wx.MemoryDC(bitmap) </code></pre>
1
2010-03-16T02:28:49Z
[ "python", "wxpython", "graphicscontext" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
2,452,084
<p>It sounds like <code>MySQLdb</code> is somewhere on your <code>sys.path</code>, but not on your Eclipse project's <code>PYTHONPATH</code>; in other words, Eclipse thinks you're going to get an import error at runtime because you haven't fully configured it. Google seems to say that you can alter this setting in <cod...
9
2010-03-16T04:18:34Z
[ "python", "eclipse", "import" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
2,461,481
<p>I once had a similar problem on Windows (never encountered this on Linux though) and I discovered that I had to include the .egg directory of my library to my PYTHONPATH.</p> <p>For example my PYTHONPATH (Pydev/Interpreter - Python/Libraries) included:</p> <pre><code>C:\Python26\Lib\site-packages </code></pre> <p...
0
2010-03-17T10:35:03Z
[ "python", "eclipse", "import" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
2,999,489
<p>Fixed this by doing two things:</p> <p>1) Added MySQLdb egg to the PYTHONPATH under Window->Preferences->Preferences->PyDev->Python Interpreter.</p> <pre><code>C:\Python26\Lib\site-packages\MySQL_python-1.2.3c1-py2.6-win32.egg </code></pre> <p>2) Close and re-open the .py file that had the red x.</p>
5
2010-06-08T16:55:25Z
[ "python", "eclipse", "import" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
3,432,855
<p>Adding the egg works, but the error remains. The solution for that error can be found by adding</p> <pre><code>#@UnresolvedImport </code></pre> <p>To the import statement, as in:</p> <pre><code>import web #@UnresolvedImport </code></pre> <p>Source: <a href="http://klaith.wordpress.com/2009/06/12/pydev-unresolve...
0
2010-08-08T02:33:02Z
[ "python", "eclipse", "import" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
4,322,080
<p>This surely works I just tried it with Pmw package. Unzip package in site-packages. Then remove python interpreter from eclipse and then add it again. Your import errors shall go away. also you may want add module to forced builtins. See <a href="http://stackoverflow.com/questions/2112715/how-do-i-fix-pydev-undefine...
0
2010-12-01T07:21:51Z
[ "python", "eclipse", "import" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
12,980,991
<p>cdleary above provided the reason two years ago, but this may be easier. Basically, one reinstalls the interpreter.</p> <ol> <li>Select Window - > Preferences -> PyDev -> Interpreter - Python</li> <li>Select the python interpreter in the upper pane</li> <li>Click on Remove</li> <li>Click on Auto Config</li> <li>Agr...
9
2012-10-19T19:17:30Z
[ "python", "eclipse", "import" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
25,516,688
<p>I had a similar issue and the following is what I did to solve my issue. I have a Windows 8 Machine, Python 2.7 installed and running my stuff through eclipse.</p> <p><strong>Some Background:</strong> </p> <p>When I did an <code>easy install</code> it tries to install <code>MySQL-python 1.2.5</code> which failed w...
0
2014-08-26T23:24:57Z
[ "python", "eclipse", "import" ]
How do I handle an UnresolvedImport Eclipse (Python)
2,451,682
<p>When I write <code>import MySQLdb</code> in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? </p> <p>How can I help Eclipse know that MySQLdb is there?</p>
9
2010-03-16T02:03:54Z
34,087,632
<pre><code>import MySQLdb </code></pre> <p>If this code show error like this:</p> <blockquote> <p>Unresolved import: MySQLdb</p> </blockquote> <p>you should add <code>D:\Python27\Lib\site-packages\MySQLdb</code> to your <code>sys.path</code>.</p> <p><code>D:\Python27\Lib\site-packages\MySQLdb</code> is this locat...
0
2015-12-04T11:43:35Z
[ "python", "eclipse", "import" ]
How is it that json serialization is so much faster than yaml serialization in Python?
2,451,732
<p>I have code that relies heavily on yaml for cross-language serialization and while working on speeding some stuff up I noticed that yaml was insanely slow compared to other serialization methods (e.g., pickle, json).</p> <p>So what really blows my mind is that json is so much faster that yaml when the output is nea...
35
2010-03-16T02:23:12Z
2,452,043
<p>In general, it's not the complexity of the output that determines the speed of parsing, but the complexity of the accepted input. The JSON grammar is <a href="http://www.ietf.org/rfc/rfc4627.txt">very concise</a>. The YAML parsers are <a href="http://yaml.org/spec/1.2/spec.html#id2763452">comparatively complex</a>, ...
39
2010-03-16T04:03:56Z
[ "python", "json", "serialization", "yaml" ]
How is it that json serialization is so much faster than yaml serialization in Python?
2,451,732
<p>I have code that relies heavily on yaml for cross-language serialization and while working on speeding some stuff up I noticed that yaml was insanely slow compared to other serialization methods (e.g., pickle, json).</p> <p>So what really blows my mind is that json is so much faster that yaml when the output is nea...
35
2010-03-16T02:23:12Z
2,452,625
<p>A cursory look at python-yaml suggests its design is much more complex than cjson's:</p> <pre><code>&gt;&gt;&gt; dir(cjson) ['DecodeError', 'EncodeError', 'Error', '__doc__', '__file__', '__name__', '__package__', '__version__', 'decode', 'encode'] &gt;&gt;&gt; dir(yaml) ['AliasEvent', 'AliasToken', 'AnchorToken'...
13
2010-03-16T07:07:52Z
[ "python", "json", "serialization", "yaml" ]
How is it that json serialization is so much faster than yaml serialization in Python?
2,451,732
<p>I have code that relies heavily on yaml for cross-language serialization and while working on speeding some stuff up I noticed that yaml was insanely slow compared to other serialization methods (e.g., pickle, json).</p> <p>So what really blows my mind is that json is so much faster that yaml when the output is nea...
35
2010-03-16T02:23:12Z
2,457,207
<p>Speaking about efficiency, I used YAML for a time and felt attracted by the simplicity that some name/value assignments take on in this language. However, in the process I tripped so and so often about one of YAML’s finesses, subtle variations in the grammar that allow you to write special cases in a more concise ...
12
2010-03-16T18:53:32Z
[ "python", "json", "serialization", "yaml" ]
How is it that json serialization is so much faster than yaml serialization in Python?
2,451,732
<p>I have code that relies heavily on yaml for cross-language serialization and while working on speeding some stuff up I noticed that yaml was insanely slow compared to other serialization methods (e.g., pickle, json).</p> <p>So what really blows my mind is that json is so much faster that yaml when the output is nea...
35
2010-03-16T02:23:12Z
9,331,885
<p>In applications I've worked on, the type inference between strings to numbers (float/int) is where the largest overhead is for parsing yaml is because strings can be written without quotes. Because all strings in json are in quotes there is no backtracking when parsing strings. A great example where this would slo...
19
2012-02-17T16:25:50Z
[ "python", "json", "serialization", "yaml" ]
working with negative numbers in python
2,451,776
<p>I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him fo...
5
2010-03-16T02:37:52Z
2,451,820
<p>Too hard? Your TA is... well, the phrase would probably get me banned. Anyways, check to see if <code>numb</code> is negative. If it is then multiply <code>numa</code> by <code>-1</code> and do <code>numb = abs(numb)</code>. Then do the loop.</p>
3
2010-03-16T02:50:30Z
[ "python", "negative-number" ]
working with negative numbers in python
2,451,776
<p>I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him fo...
5
2010-03-16T02:37:52Z
2,451,825
<p>Perhaps you would accomplish this with something to the effect of</p> <pre><code>text = raw_input("please give 2 numbers to multiply separated with a comma:") split_text = text.split(',') a = int(split_text[0]) b = int(split_text[1]) # The last three lines could be written: a, b = map(int, text.split(',')) # but yo...
2
2010-03-16T02:52:30Z
[ "python", "negative-number" ]
working with negative numbers in python
2,451,776
<p>I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him fo...
5
2010-03-16T02:37:52Z
2,451,859
<p>The abs() in the while condition is needed, since, well, it controls the number of iterations (how would you define a negative number of iterations?). You can correct it by inverting the sign of the result if <code>numb</code> is negative.</p> <p>So this is the modified version of your code. Note I replaced the whi...
3
2010-03-16T03:03:16Z
[ "python", "negative-number" ]
working with negative numbers in python
2,451,776
<p>I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him fo...
5
2010-03-16T02:37:52Z
2,451,900
<p>How about something like that? (Uses no abs() nor mulitiplication)<br> Notes:</p> <ul> <li>the abs() function is only used for the optimization trick. This snippet can either be removed or recoded.</li> <li>the logic is less efficient since we're testing the sign of a and b with each iteration (price to pay to avo...
0
2010-03-16T03:13:52Z
[ "python", "negative-number" ]
working with negative numbers in python
2,451,776
<p>I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him fo...
5
2010-03-16T02:37:52Z
2,452,069
<p>Try this on your TA:</p> <pre><code># Simulate multiplying two N-bit two's-complement numbers # into a 2N-bit accumulator # Use shift-add so that it's O(base_2_log(N)) not O(N) for numa, numb in ((3, 5), (-3, 5), (3, -5), (-3, -5), (-127, -127)): print numa, numb, accum = 0 negate = False if numa &...
1
2010-03-16T04:13:00Z
[ "python", "negative-number" ]
working with negative numbers in python
2,451,776
<p>I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him fo...
5
2010-03-16T02:37:52Z
2,458,983
<p>Thanks everyone, you all helped me learn a lot. This is what I came up with using some of your suggestions</p> <pre><code>#this is apparently a better way of getting multiple inputs at the same time than the #way I was doing it text = raw_input("please give 2 numbers to multiply separated with a comma:") split_tex...
0
2010-03-16T23:42:41Z
[ "python", "negative-number" ]
working with negative numbers in python
2,451,776
<p>I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him fo...
5
2010-03-16T02:37:52Z
26,852,512
<pre><code>import time print ('Two Digit Multiplication Calculator') print ('===================================') print () print ('Give me two numbers.') x = int ( input (':')) y = int ( input (':')) z = 0 print () while x &gt; 0: print (':',z) x = x - 1 z = y + z time.sleep (.2) if x == 0: ...
-1
2014-11-10T20:34:49Z
[ "python", "negative-number" ]
String formatting named parameters?
2,451,821
<p>I know it's a really simple question, but I have no idea how to google it.</p> <p>how can I do</p> <pre><code>print '&lt;a href="%s"&gt;%s&lt;/a&gt;' % (my_url) </code></pre> <p>So that <code>my_url</code> is used twice? I assume I have to "name" the <code>%s</code> and then use a dict in the params, but I'm not ...
86
2010-03-16T02:50:31Z
2,451,826
<pre><code>print '&lt;a href="%(url)s"&gt;%(url)s&lt;/a&gt;' % {'url': my_url} </code></pre>
160
2010-03-16T02:52:46Z
[ "python", "string", "syntax" ]
String formatting named parameters?
2,451,821
<p>I know it's a really simple question, but I have no idea how to google it.</p> <p>how can I do</p> <pre><code>print '&lt;a href="%s"&gt;%s&lt;/a&gt;' % (my_url) </code></pre> <p>So that <code>my_url</code> is used twice? I assume I have to "name" the <code>%s</code> and then use a dict in the params, but I'm not ...
86
2010-03-16T02:50:31Z
2,451,911
<p>For building HTML pages, you want to use a templating engine, not simple string interpolation.</p>
4
2010-03-16T03:16:43Z
[ "python", "string", "syntax" ]
String formatting named parameters?
2,451,821
<p>I know it's a really simple question, but I have no idea how to google it.</p> <p>how can I do</p> <pre><code>print '&lt;a href="%s"&gt;%s&lt;/a&gt;' % (my_url) </code></pre> <p>So that <code>my_url</code> is used twice? I assume I have to "name" the <code>%s</code> and then use a dict in the params, but I'm not ...
86
2010-03-16T02:50:31Z
2,451,923
<p>As well as the dictionary way, it may be useful to know the following format:</p> <p><code>print '&lt;a href="%s"&gt;%s&lt;/a&gt;' % (my_url, my_url)</code></p> <p>Here it's a tad redundant, and the dictionary way is certainly less error prone when modifying the code, but it's still possible to use tuples for mult...
1
2010-03-16T03:20:56Z
[ "python", "string", "syntax" ]
String formatting named parameters?
2,451,821
<p>I know it's a really simple question, but I have no idea how to google it.</p> <p>how can I do</p> <pre><code>print '&lt;a href="%s"&gt;%s&lt;/a&gt;' % (my_url) </code></pre> <p>So that <code>my_url</code> is used twice? I assume I have to "name" the <code>%s</code> and then use a dict in the params, but I'm not ...
86
2010-03-16T02:50:31Z
2,452,382
<p>In Python 3, you might choose to use the new string formatting method.</p> <pre><code>print('&lt;a href="{0}"&gt;{0}&lt;/a&gt;'.format(my_url)) </code></pre> <p>which saves you from repeating the argument, or</p> <pre><code>print('&lt;a href="{url}"&gt;{url}&lt;/a&gt;'.format(url=my_url)) </code></pre> <p>if you...
32
2010-03-16T05:56:07Z
[ "python", "string", "syntax" ]
String formatting named parameters?
2,451,821
<p>I know it's a really simple question, but I have no idea how to google it.</p> <p>how can I do</p> <pre><code>print '&lt;a href="%s"&gt;%s&lt;/a&gt;' % (my_url) </code></pre> <p>So that <code>my_url</code> is used twice? I assume I have to "name" the <code>%s</code> and then use a dict in the params, but I'm not ...
86
2010-03-16T02:50:31Z
34,039,789
<p>You will be addicted to syntax.</p> <p>Also C# 6.0, EcmaScript developers has also familier this syntax.</p> <pre><code>In [1]: print '{firstname} {lastname}'.format(firstname='Mehmet', lastname='Ağa') Mehmet Ağa In [2]: print '{firstname} {lastname}'.format(**dict(firstname='Mehmet', lastname='Ağa')) Mehmet A...
3
2015-12-02T10:00:25Z
[ "python", "string", "syntax" ]
String formatting named parameters?
2,451,821
<p>I know it's a really simple question, but I have no idea how to google it.</p> <p>how can I do</p> <pre><code>print '&lt;a href="%s"&gt;%s&lt;/a&gt;' % (my_url) </code></pre> <p>So that <code>my_url</code> is used twice? I assume I have to "name" the <code>%s</code> and then use a dict in the params, but I'm not ...
86
2010-03-16T02:50:31Z
39,144,239
<h2>Solution in Python 3.6+</h2> <p>Python 3.6 introduces <em>literal string formatting</em>, so that you can format the named parameters without any repeating any of your named parameters outside the string:</p> <pre><code>print(f'&lt;a href="{my_url}"&gt;{my_url}&lt;/a&gt;') </code></pre> <p>See <a href="https://w...
0
2016-08-25T11:37:16Z
[ "python", "string", "syntax" ]
Why does my buffered GraphicsContext application have a flickering problem?
2,452,012
<pre><code>import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel): def __init__(self,parent=None,id=-1): wx.Pa...
1
2010-03-16T03:50:01Z
2,452,772
<p>If you're using a relatively modern wxWidgets, you can use <code>wx.BufferedPaintDC</code> and avoid having to muck around with the memory DC and painting and blitting on your own. Also, on windows, FULL_REPAINT_ON_RESIZE often causes flickering even when you're not resizing the window due to funny things going on ...
1
2010-03-16T07:47:21Z
[ "python", "wxpython", "graphicscontext" ]
Why does my buffered GraphicsContext application have a flickering problem?
2,452,012
<pre><code>import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel): def __init__(self,parent=None,id=-1): wx.Pa...
1
2010-03-16T03:50:01Z
2,478,953
<p>You get flicker because each <code>Refresh()</code> causes the background to get erased before calling <code>onPaint</code>. You need to bind to <code>EVT_ERASE_BACKGROUND</code> and make it a no-op.</p> <pre><code>class DoubleBufferTest(wx.Panel): def __init__(self,parent=None,id=-1): # ... existing c...
2
2010-03-19T16:36:53Z
[ "python", "wxpython", "graphicscontext" ]
how to get the index or the element itself of an element found with "if element in list"
2,452,093
<p>Does a direct way to do this exists?</p> <pre><code>if element in aList: #get the element from the list </code></pre> <p>I'm thinking something like this:</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 </code></pre>
2
2010-03-16T04:23:06Z
2,452,102
<p>(Note: this answer refers to the question text, not the example given in the code, which doesn't quite match.)</p> <p>Printing the element itself doesn't make any sense, because you already have it in the test:</p> <pre><code>if element in lst: print element </code></pre> <p>If you want the index, there's an ...
1
2010-03-16T04:26:03Z
[ "python", "list", "tuples" ]
how to get the index or the element itself of an element found with "if element in list"
2,452,093
<p>Does a direct way to do this exists?</p> <pre><code>if element in aList: #get the element from the list </code></pre> <p>I'm thinking something like this:</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 </code></pre>
2
2010-03-16T04:23:06Z
2,452,103
<pre><code>&gt;&gt;&gt; aList = [ ([1,2,3],4) , ([5,6,7],8) ] &gt;&gt;&gt; for i in aList: ... if [5,6,7] in i: ... print i[-1] ... 8 </code></pre>
0
2010-03-16T04:26:14Z
[ "python", "list", "tuples" ]
how to get the index or the element itself of an element found with "if element in list"
2,452,093
<p>Does a direct way to do this exists?</p> <pre><code>if element in aList: #get the element from the list </code></pre> <p>I'm thinking something like this:</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 </code></pre>
2
2010-03-16T04:23:06Z
2,452,105
<pre><code>&gt;&gt;&gt; aList = [ ([1,2,3],4) , ([5,6,7],8) ] &gt;&gt;&gt; element = [5,6,7] </code></pre> <p>if you only wish to check if the first element is present</p> <pre><code>&gt;&gt;&gt; any(element==x[0] for x in aList) True </code></pre> <p>to find the corresponding value</p> <pre><code>&gt;&gt;&gt; next...
1
2010-03-16T04:26:24Z
[ "python", "list", "tuples" ]
how to get the index or the element itself of an element found with "if element in list"
2,452,093
<p>Does a direct way to do this exists?</p> <pre><code>if element in aList: #get the element from the list </code></pre> <p>I'm thinking something like this:</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 </code></pre>
2
2010-03-16T04:23:06Z
2,452,108
<pre><code>L = [([1, 2, 3], 4), ([5, 6, 7], 8)] element = [5, 6, 7] for a, b in L: if a == element: print b break else: print "not found" </code></pre> <p>But it sounds like you want to use a dictionary:</p> <pre><code>L = [([1, 2, 3], 4), ([5, 6, 7], 8)] element = [5, 6, 7] D = dict((tuple(a), b) for a...
3
2010-03-16T04:27:21Z
[ "python", "list", "tuples" ]
how to get the index or the element itself of an element found with "if element in list"
2,452,093
<p>Does a direct way to do this exists?</p> <pre><code>if element in aList: #get the element from the list </code></pre> <p>I'm thinking something like this:</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 </code></pre>
2
2010-03-16T04:23:06Z
2,452,118
<p><code>[5, 6, 7]</code> is <em>not</em> an item of the <code>aList</code> you show, so the <code>if</code> will fail, and your question as posed just doesn't pertain. More generally, the loop implied in such an <code>if</code> tosses away the index anyway. A way to make your code snippet work would be, instead of t...
0
2010-03-16T04:29:04Z
[ "python", "list", "tuples" ]
how to get the index or the element itself of an element found with "if element in list"
2,452,093
<p>Does a direct way to do this exists?</p> <pre><code>if element in aList: #get the element from the list </code></pre> <p>I'm thinking something like this:</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 </code></pre>
2
2010-03-16T04:23:06Z
2,452,134
<p>One possible solution.</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] &gt;&gt;&gt; print(*[y for x,y in aList if element == x]) 8 </code></pre>
0
2010-03-16T04:34:39Z
[ "python", "list", "tuples" ]
how to get the index or the element itself of an element found with "if element in list"
2,452,093
<p>Does a direct way to do this exists?</p> <pre><code>if element in aList: #get the element from the list </code></pre> <p>I'm thinking something like this:</p> <pre><code>aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 </code></pre>
2
2010-03-16T04:23:06Z
2,452,188
<p>The code in your question is sort of weird. But, assuming you're learning the basics:</p> <h3>Getting the index of an element:</h3> <p>it's actually simple: <code>list.index(element)</code>. Assuming of course, the element only appears once. If it appears more than once, you can use the extra parameters:</p> <p><...
0
2010-03-16T04:50:01Z
[ "python", "list", "tuples" ]
Python: Create a duplicate of an array
2,452,321
<p>I have an double array</p> <pre><code>alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] </code></pre> <p>and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a <strong>seperate</strong> double array (n...
4
2010-03-16T05:34:56Z
2,452,325
<p>Usually you can do something like:</p> <pre><code>new_list = old_list[:] </code></pre> <p>So you could perhaps throw that in your singular for loop?</p> <pre><code>for x in range(10): alist2.append(alist[x][:]) </code></pre>
0
2010-03-16T05:37:00Z
[ "python", "list", "pointers", "arrays" ]
Python: Create a duplicate of an array
2,452,321
<p>I have an double array</p> <pre><code>alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] </code></pre> <p>and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a <strong>seperate</strong> double array (n...
4
2010-03-16T05:34:56Z
2,452,330
<p>make a copy of the list when append.</p> <pre><code> alist2.append(alist[x][:]) </code></pre>
1
2010-03-16T05:38:47Z
[ "python", "list", "pointers", "arrays" ]
Python: Create a duplicate of an array
2,452,321
<p>I have an double array</p> <pre><code>alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] </code></pre> <p>and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a <strong>seperate</strong> double array (n...
4
2010-03-16T05:34:56Z
2,452,331
<p>A list of lists is not usually a great solution for making a 2d array. You probably want to use numpy, which provides a very useful, efficient n-dimensional array type. numpy arrays can be copied.</p> <p>Other solutions that are usually better than a plain list of lists include a dict with tuples as keys (<code>d[1...
4
2010-03-16T05:39:11Z
[ "python", "list", "pointers", "arrays" ]
Python: Create a duplicate of an array
2,452,321
<p>I have an double array</p> <pre><code>alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] </code></pre> <p>and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a <strong>seperate</strong> double array (n...
4
2010-03-16T05:34:56Z
2,452,334
<p>You can use <code>somelist[:]</code>, that is a slice like <code>somelist[1:2]</code> from beginning to end, to create a (shallow) copy of a list. Applying this to your for-loop gives:</p> <pre><code>alist2 = [] for x in xrange(10): alist2.append(alist[x][:]) </code></pre> <p>This can also be written as a list ...
5
2010-03-16T05:39:59Z
[ "python", "list", "pointers", "arrays" ]
Python: Create a duplicate of an array
2,452,321
<p>I have an double array</p> <pre><code>alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] </code></pre> <p>and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a <strong>seperate</strong> double array (n...
4
2010-03-16T05:34:56Z
2,452,338
<p>I think <a href="http://docs.python.org/library/copy.html">copy.deepcopy()</a> is for just this case.</p>
9
2010-03-16T05:40:54Z
[ "python", "list", "pointers", "arrays" ]
Python: Create a duplicate of an array
2,452,321
<p>I have an double array</p> <pre><code>alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] </code></pre> <p>and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a <strong>seperate</strong> double array (n...
4
2010-03-16T05:34:56Z
2,452,339
<p>If you're already looping over the list anyway then just copying the inner lists as you go is easiest, as per <strong>seanmonstar</strong>'s answer.</p> <p>If you just want to do a deep copy of the list you could call <code>copy.deepcopy()</code> on it.</p>
1
2010-03-16T05:41:00Z
[ "python", "list", "pointers", "arrays" ]
XOR swap algorithm in python?
2,452,336
<p>I tried to implement <a href="http://en.wikipedia.org/wiki/XOR_swap_algorithm" rel="nofollow">XOR swap</a> in python.</p> <pre><code>x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s , %s'%(x,y)) </code></pre> <p>OUTPUT:</p> <pre><code>30 , 30 </code></pre> <p>I am not new to python but I am unable to explain this outp...
3
2010-03-16T05:40:42Z
2,452,342
<p>First, a tuple is created consisting of <code>x^y</code>, <code>x^y</code> and <code>x^y</code>. Then the tuple is unpacked into <code>x</code>, <code>y</code>, and <code>x</code>, causing both to be bound to the result of <code>x^y</code>.</p> <p>Save yourself the headache and do it the Pythonic way:</p> <pre><co...
13
2010-03-16T05:43:11Z
[ "python", "algorithm", "tuples" ]
XOR swap algorithm in python?
2,452,336
<p>I tried to implement <a href="http://en.wikipedia.org/wiki/XOR_swap_algorithm" rel="nofollow">XOR swap</a> in python.</p> <pre><code>x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s , %s'%(x,y)) </code></pre> <p>OUTPUT:</p> <pre><code>30 , 30 </code></pre> <p>I am not new to python but I am unable to explain this outp...
3
2010-03-16T05:40:42Z
2,452,343
<p>You can do this swap easily using the following:</p> <pre> x, y = 10, 20 x, y = y, x print((x,y)) </pre> <p>As for the behavior you're seeing, I'm pretty sure that's because the entire RHS is evaluated and then assigned to the LHS at the same time, and <code>x^y</code> is always 30 in that case.</p>
1
2010-03-16T05:43:13Z
[ "python", "algorithm", "tuples" ]
XOR swap algorithm in python?
2,452,336
<p>I tried to implement <a href="http://en.wikipedia.org/wiki/XOR_swap_algorithm" rel="nofollow">XOR swap</a> in python.</p> <pre><code>x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s , %s'%(x,y)) </code></pre> <p>OUTPUT:</p> <pre><code>30 , 30 </code></pre> <p>I am not new to python but I am unable to explain this outp...
3
2010-03-16T05:40:42Z
2,452,355
<p>The XOR swap algorithm only makes sense when you have two pointers to mutable objects. a and b are two references to immutable ints. </p> <p>EDIT (moving from comments as requested, and expanding):</p> <p>Python integers are immutable. So every time you "modify" one using XOR, new storage will be allocated (or r...
2
2010-03-16T05:46:24Z
[ "python", "algorithm", "tuples" ]
XOR swap algorithm in python?
2,452,336
<p>I tried to implement <a href="http://en.wikipedia.org/wiki/XOR_swap_algorithm" rel="nofollow">XOR swap</a> in python.</p> <pre><code>x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s , %s'%(x,y)) </code></pre> <p>OUTPUT:</p> <pre><code>30 , 30 </code></pre> <p>I am not new to python but I am unable to explain this outp...
3
2010-03-16T05:40:42Z
2,452,357
<p>While it's definitely best, as other answers say, to just <code>x, y = y, x</code>, if you're allergic to creating and unpacking tuples you <em>can</em> do it with successive x-oring... it just has to be successive, not <em>simultaneous</em> as you're doing!</p> <pre><code>&gt;&gt;&gt; x = 1234 &gt;&gt;&gt; y = 342...
9
2010-03-16T05:47:02Z
[ "python", "algorithm", "tuples" ]
XOR swap algorithm in python?
2,452,336
<p>I tried to implement <a href="http://en.wikipedia.org/wiki/XOR_swap_algorithm" rel="nofollow">XOR swap</a> in python.</p> <pre><code>x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s , %s'%(x,y)) </code></pre> <p>OUTPUT:</p> <pre><code>30 , 30 </code></pre> <p>I am not new to python but I am unable to explain this outp...
3
2010-03-16T05:40:42Z
2,452,374
<p>You need to transcribe the "algorithm" line for line.</p> <pre><code>&gt;&gt;&gt; x, y = 10, 20 &gt;&gt;&gt; x = x ^ y; print x, y 30 20 &gt;&gt;&gt; y = x ^ y; print x, y 30 10 &gt;&gt;&gt; x = x ^ y; print x, y 20 10 &gt;&gt;&gt; </code></pre> <p>You need to read the remainder of the Wikipedia article, which exp...
3
2010-03-16T05:53:41Z
[ "python", "algorithm", "tuples" ]
faking a filesystem / virtual filesystem
2,452,488
<p>I have a web service to which users upload python scripts that are run on a server. Those scripts process files that are on the server and I want them to be able to see only a certain hierarchy of the server's filesystem (best: a temporary folder on which I copy the files I want processed and the scripts).</p> <p>T...
2
2010-03-16T06:24:40Z
2,452,503
<p>You are probably best to use a virtual machine like VirtualBox or VMware (perhaps even creating one per user/session). </p> <p>That will allow you some control over other resources such as memory and network as well as disk</p> <p>The only python that I know of that has such features built in is the one on Google...
3
2010-03-16T06:31:07Z
[ "python", "security", "filesystems", "sandbox" ]
faking a filesystem / virtual filesystem
2,452,488
<p>I have a web service to which users upload python scripts that are run on a server. Those scripts process files that are on the server and I want them to be able to see only a certain hierarchy of the server's filesystem (best: a temporary folder on which I copy the files I want processed and the scripts).</p> <p>T...
2
2010-03-16T06:24:40Z
2,452,516
<p>Either a <a href="http://en.wikipedia.org/wiki/Chroot" rel="nofollow">chroot jail</a> or a higher-order security mechanism such as <a href="http://en.wikipedia.org/wiki/Security-Enhanced_Linux" rel="nofollow">SELinux</a> can be used to restrict access to specific resources. </p>
5
2010-03-16T06:36:40Z
[ "python", "security", "filesystems", "sandbox" ]
faking a filesystem / virtual filesystem
2,452,488
<p>I have a web service to which users upload python scripts that are run on a server. Those scripts process files that are on the server and I want them to be able to see only a certain hierarchy of the server's filesystem (best: a temporary folder on which I copy the files I want processed and the scripts).</p> <p>T...
2
2010-03-16T06:24:40Z
2,457,769
<p>This is inherently insecure software. By letting users upload scripts you are introducing a remote code execution vulnerability. You have more to worry about than just modifying files, whats stopping the python script from accessing the network or other resources?</p> <p>To solve this problem you need to use a ...
0
2010-03-16T20:14:57Z
[ "python", "security", "filesystems", "sandbox" ]
Newbie python error in regards to import
2,452,567
<p>I'm a python newbie and starting out with using the Bottle web framework on Google App Engine. I've been messing with the super small, super easy Hello World sample and have already ran into problems. Heh. I finally got the code to work with this...</p> <pre><code>import bottle from bottle import route from goog...
4
2010-03-16T06:50:03Z
2,452,577
<p><code>route</code> is part of the <code>bottle</code> module. </p> <p>The following should fix the problem</p> <pre><code>import bottle ... @bottle.route('/hello') def hello(): return "Hello World!" ... </code></pre>
3
2010-03-16T06:53:10Z
[ "python", "google-app-engine" ]
Newbie python error in regards to import
2,452,567
<p>I'm a python newbie and starting out with using the Bottle web framework on Google App Engine. I've been messing with the super small, super easy Hello World sample and have already ran into problems. Heh. I finally got the code to work with this...</p> <pre><code>import bottle from bottle import route from goog...
4
2010-03-16T06:50:03Z
2,452,639
<p>In your code you have two different ways of calling methods from bottle package.</p> <pre><code>route('/hello') </code></pre> <p>and </p> <pre><code>bottle.default_app() </code></pre> <p>First call requires <code>from bottle import route</code> or <code>from bottle import *</code> and second one requires <code>i...
8
2010-03-16T07:12:29Z
[ "python", "google-app-engine" ]
Newbie python error in regards to import
2,452,567
<p>I'm a python newbie and starting out with using the Bottle web framework on Google App Engine. I've been messing with the super small, super easy Hello World sample and have already ran into problems. Heh. I finally got the code to work with this...</p> <pre><code>import bottle from bottle import route from goog...
4
2010-03-16T06:50:03Z
2,452,859
<p>You can either just import bottle into you namespace, so every time you wish to use something from there you have <code>bottle.</code> as a prefix.</p> <pre><code>import bottle from google.appengine.ext.webapp import util @bottle.route('/') def index(): return "Hello World!" util.run_wsgi_app(bottle.default_...
2
2010-03-16T08:12:42Z
[ "python", "google-app-engine" ]
Newbie python error in regards to import
2,452,567
<p>I'm a python newbie and starting out with using the Bottle web framework on Google App Engine. I've been messing with the super small, super easy Hello World sample and have already ran into problems. Heh. I finally got the code to work with this...</p> <pre><code>import bottle from bottle import route from goog...
4
2010-03-16T06:50:03Z
2,455,902
<p>Regarding why </p> <pre><code>from bottle import * </code></pre> <p>does not do the trick: when you import like that, only names that are specified in bottle's <strong>__<em>all</em>__</strong> list are imported. So, if route is not there, you have to specify the import explicitly:</p> <pre><code>from bottle impo...
5
2010-03-16T15:54:45Z
[ "python", "google-app-engine" ]
Newbie python error in regards to import
2,452,567
<p>I'm a python newbie and starting out with using the Bottle web framework on Google App Engine. I've been messing with the super small, super easy Hello World sample and have already ran into problems. Heh. I finally got the code to work with this...</p> <pre><code>import bottle from bottle import route from goog...
4
2010-03-16T06:50:03Z
5,128,371
<p>I too learned to use Bottle with GAE, because of its very small size. What you can do is keep bottle directly with your main files, that will allow you to use 'import bottle', or put in a folder (to separate it from other files, give a neat structure), and add an empty <code>__init__.py</code> file to that folder. T...
0
2011-02-26T17:03:18Z
[ "python", "google-app-engine" ]
Organizing Python objects for retrieval
2,452,688
<p>I have a <code>Club</code> class and a <code>Player</code> Class. The player class has an attribute <code>Fav.clubs</code> which will have unique club values. So the user is supposed to enter various club names. Based on the club names I must retrieve those club objects and establish the relationship that this parti...
-1
2010-03-16T07:27:07Z
2,452,717
<p>Use a <code>dict</code> to store a map between strings and instances of <code>Club</code>:</p> <pre><code>clubmap = { 'basketball': Club("Basketball club"), 'chess': Club("Chess club"), } someplayer.joinclub(clubmap['basketball']) </code></pre>
0
2010-03-16T07:35:11Z
[ "python" ]
Organizing Python objects for retrieval
2,452,688
<p>I have a <code>Club</code> class and a <code>Player</code> Class. The player class has an attribute <code>Fav.clubs</code> which will have unique club values. So the user is supposed to enter various club names. Based on the club names I must retrieve those club objects and establish the relationship that this parti...
-1
2010-03-16T07:27:07Z
2,452,746
<p>Store all clubs in a dictionary called <code>all_clubs</code>. The key should be the club-name and the value the club object itself. Then you can do <code>all_clubs[clubname]</code> to retrieve the club object for a given name.</p> <p>The player might have an attribute <code>club_names</code> which is the list of t...
1
2010-03-16T07:40:51Z
[ "python" ]
Encrypting XML database in python
2,452,744
<p>i am using XML as my backend for the application...</p> <p>LXML is used to parse the xml.</p> <p>How can i encrypt this xml file to make sure that the data is protected......</p> <p>thanks in advance.</p>
0
2010-03-16T07:40:37Z
2,452,779
<p>As XML contains repetitive structure it is better to first <code>compress</code> and then <code>encrypt</code> it.</p> <p>Download and install <a href="http://twhiteman.netfirms.com/des.html" rel="nofollow">PyDes</a>.</p> <pre><code>from pyDes import * import bz2 def encrypt(data,password): k = des(password, ...
4
2010-03-16T07:50:18Z
[ "python", "xml", "encryption", "lxml" ]
Python library for converting plain text (ASCII) into GSM 7-bit character set?
2,452,861
<p>Is there a python library for encoding ascii data to 7-bit GSM character set (for sending SMS)?</p>
5
2010-03-16T08:13:08Z
2,452,957
<p>I could not find any library. But I think this should not need a library. Its somewhat easy to do.</p> <p><a href="http://bytes.com/topic/net/answers/116723-get-7-bit-character-gsm-03-38-a" rel="nofollow">Here</a> is <strong>Jon Skeet</strong> himself on the same topic.</p> <p>Example:</p> <pre><code>s = 'ABCDEFG...
0
2010-03-16T08:38:07Z
[ "python", "encoding", "sms" ]
Python library for converting plain text (ASCII) into GSM 7-bit character set?
2,452,861
<p>Is there a python library for encoding ascii data to 7-bit GSM character set (for sending SMS)?</p>
5
2010-03-16T08:13:08Z
2,453,027
<p>There is now :)</p> <p>Thanks to <a href="http://stackoverflow.com/users/37309/chad">Chad</a> for pointing out that this wasn't quite right</p> <h2>Python2 version</h2> <pre><code># -*- coding: utf8 -*- gsm = (u"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1bÆæßÉ !\"#¤%&amp;'()*+,-./0123456789:;&lt;...
10
2010-03-16T08:51:40Z
[ "python", "encoding", "sms" ]
Python library for converting plain text (ASCII) into GSM 7-bit character set?
2,452,861
<p>Is there a python library for encoding ascii data to 7-bit GSM character set (for sending SMS)?</p>
5
2010-03-16T08:13:08Z
27,454,852
<p>I got tips from gnibbler's answer. Here is a script I somehow made up after looking at an online converter: <a href="http://smstools3.kekekasvi.com/topic.php?id=288" rel="nofollow">http://smstools3.kekekasvi.com/topic.php?id=288</a>, and it works correctly for me. Both encoding and decoding.</p> <pre><code>#!/usr/b...
0
2014-12-13T02:18:00Z
[ "python", "encoding", "sms" ]
Beginner python - stuck in a loop
2,452,961
<p>I have two begininer programs, both using the 'while' function, one works correctly, and the other gets me stuck in a loop. The first program is this;</p> <pre><code>num=54 bob = True print('The guess a number Game!') while bob == True: guess = int(input('What is your guess? ')) if guess==num: p...
-1
2010-03-16T08:39:00Z
2,452,989
<p>In the second example, the user doesn't get a chance to enter a new guess inside the loop, so <code>a</code> and <code>b</code> remain the same. </p>
3
2010-03-16T08:43:11Z
[ "python", "python-3.x", "infinite-loop" ]
Beginner python - stuck in a loop
2,452,961
<p>I have two begininer programs, both using the 'while' function, one works correctly, and the other gets me stuck in a loop. The first program is this;</p> <pre><code>num=54 bob = True print('The guess a number Game!') while bob == True: guess = int(input('What is your guess? ')) if guess==num: p...
-1
2010-03-16T08:39:00Z
2,452,991
<p>In the second program you never give the user a chance to pick two new numbers if they're not equal. Put the lines where you get input from the user inside the loop, like this:</p> <pre><code>#try a function def func_tim(): bob = True while bob == True: #define vars a = int(input('Please in...
2
2010-03-16T08:43:27Z
[ "python", "python-3.x", "infinite-loop" ]
Beginner python - stuck in a loop
2,452,961
<p>I have two begininer programs, both using the 'while' function, one works correctly, and the other gets me stuck in a loop. The first program is this;</p> <pre><code>num=54 bob = True print('The guess a number Game!') while bob == True: guess = int(input('What is your guess? ')) if guess==num: p...
-1
2010-03-16T08:39:00Z
2,452,998
<p>in your 2nd program, if <code>b &gt; a</code>, you will go back to the loop because <code>bob</code> is still <code>true</code>. You forgot to ask the user to input again.. try it this way</p> <pre><code> def func_tim(): while 1: a = int(input('Please insert a number: ')) b = int(input('Please in...
2
2010-03-16T08:44:39Z
[ "python", "python-3.x", "infinite-loop" ]
Beginner python - stuck in a loop
2,452,961
<p>I have two begininer programs, both using the 'while' function, one works correctly, and the other gets me stuck in a loop. The first program is this;</p> <pre><code>num=54 bob = True print('The guess a number Game!') while bob == True: guess = int(input('What is your guess? ')) if guess==num: p...
-1
2010-03-16T08:39:00Z
2,453,000
<p>Your second program doesn't allow the user to reenter his guess if it's not correct. Put the <code>input</code> into the while loop. </p> <p>Additional hint: Don't make checks like <code>variable == True</code>, just say <code>while variable:</code>.</p>
2
2010-03-16T08:44:53Z
[ "python", "python-3.x", "infinite-loop" ]
ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction
2,453,186
<p>i have this simple type from an external webservice:</p> <pre><code>&lt;xsd:element name="card_number" maxOccurs="1" minOccurs="1"&gt; &lt;xsd:simpleType&gt; &lt;xsd:restriction base="tns:PanType"&gt; &lt;xsd:pattern value="\d{16}"&gt;&lt;/xsd:pattern&gt; &lt;xsd:whiteSpace value="collapse"&gt;&...
0
2010-03-16T09:26:02Z
2,453,455
<p>I'm not sure if this is still the case, but a quick google suggests that simpleTypes with user-defined restriction bases aren't supported by ZSI.</p> <p>If this is still the case, then you could modify the restriction for "card_number" to remove the base and update the restriction-facets within the simpleType-restr...
1
2010-03-16T10:12:13Z
[ "python", "xml", "soap", "zsi" ]
Matplotlib installation problems
2,453,324
<p>I need to install matplotlib in a remote linux machine, and I am a normal user there.</p> <p>I downlodad the source and run </p> <pre><code>python setup.py build </code></pre> <p>but I get errors, related with numpy, which is not installed, so I decieded to install it first. I download and compile with </p> <pre...
1
2010-03-16T09:54:08Z
2,454,832
<p>Hmm, I wonder if you just need the numpy directory in PYTHONPATH before executing the installer.</p> <pre><code>export PYTHONPATH="/path/to/numpy" </code></pre> <p>Then run the build command.</p>
0
2010-03-16T13:51:36Z
[ "python", "numpy", "matplotlib" ]
Matplotlib installation problems
2,453,324
<p>I need to install matplotlib in a remote linux machine, and I am a normal user there.</p> <p>I downlodad the source and run </p> <pre><code>python setup.py build </code></pre> <p>but I get errors, related with numpy, which is not installed, so I decieded to install it first. I download and compile with </p> <pre...
1
2010-03-16T09:54:08Z
2,455,317
<p>Since you are a user and not root on the remote machine, it may be that your environement is not configured correctly. Check that you can load numpy from the interperter.</p> <blockquote> <blockquote> <p>import numpy</p> </blockquote> </blockquote> <p>If that fails, you may need to add its installed locati...
1
2010-03-16T14:47:19Z
[ "python", "numpy", "matplotlib" ]
find the colour name from a hexadecimal colour code
2,453,344
<p>i want to find the name of a colour from the hexadecimal colour code. When i get a hex colour code i want to find the most matching colour name. for example for the code #c06040 , how to find out if it is a shade of brown, blue or yellow ?. so that i can find the colour of an object in the image without human interv...
8
2010-03-16T09:57:33Z
2,453,362
<p>The <a href="http://en.wikipedia.org/wiki/Web_colors" rel="nofollow">Wikipedia page for web colors</a> has quite a lot of them listed, as does <a href="http://www.w3schools.com/html/html_colornames.asp" rel="nofollow">w3schools</a> and the temptingly-named <a href="http://www.html-color-names.com/color-chart.php" re...
0
2010-03-16T10:00:24Z
[ "python", "image-processing" ]
find the colour name from a hexadecimal colour code
2,453,344
<p>i want to find the name of a colour from the hexadecimal colour code. When i get a hex colour code i want to find the most matching colour name. for example for the code #c06040 , how to find out if it is a shade of brown, blue or yellow ?. so that i can find the colour of an object in the image without human interv...
8
2010-03-16T09:57:33Z
2,453,370
<p><a href="http://en.wikipedia.org/wiki/X11_color_names" rel="nofollow">This page</a> on Wikipedia provides an example of lookup from name to hex codes. It would be fairly easy to lookup in the other direction. Whether there is a relationship between codes and names that suits you is up to you. You'll probably find...
0
2010-03-16T10:01:11Z
[ "python", "image-processing" ]