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
Making a wxPython application multilingual
1,043,708
<p>I have a application written in wxPython which I want to make multilingual. Our options are</p> <ol> <li>using gettext <a href="http://docs.python.org/library/gettext.html" rel="nofollow">http://docs.python.org/library/gettext.html</a></li> <li>seprating out all UI text to a messages.py file, and using it to transl...
2
2009-06-25T12:49:08Z
1,069,016
<p>Gettext is the way to go, in your example you can also use gettext to "avoid storing the translations in the code":</p> <pre><code>wx.MessageBox(messages.GREET_SO) </code></pre> <p>might be the same with gettext as:</p> <pre><code>wx.MessageBox(_("GREET_SO")) or wx.MessageBox(_("messages.GREET_SO")) </code></pre>...
1
2009-07-01T12:58:30Z
[ "python", "internationalization", "multilingual", "gettext" ]
What is the most secure python "password" encryption
1,043,735
<p>I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he h...
5
2009-06-25T12:52:58Z
1,043,759
<p>If it's a web game, can't you store the codes server side and send them to the client when he completed a task? What's the architecture of your game?</p> <p>As for encryption, maybe try something like <a href="http://twhiteman.netfirms.com/des.html" rel="nofollow">pyDes</a>?</p>
2
2009-06-25T12:58:45Z
[ "python", "security", "encryption" ]
What is the most secure python "password" encryption
1,043,735
<p>I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he h...
5
2009-06-25T12:52:58Z
1,043,762
<p>The most secure encryption is no encryption. Passwords should be reduced to a hash. This is a one-way transformation, making the password (almost) unrecoverable.</p> <p>When giving someone a code, you can do the following to be <em>actually</em> secure. </p> <p>(1) generate some random string.</p> <p>(2) give ...
5
2009-06-25T12:59:12Z
[ "python", "security", "encryption" ]
What is the most secure python "password" encryption
1,043,735
<p>I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he h...
5
2009-06-25T12:52:58Z
1,046,926
<p>Your question isn't quite clear. Where do you want the decryption to occur? One way or another, the plaintext has to surface since you need players to eventually know it.</p> <p>Pick a <a href="http://en.wikipedia.org/wiki/Stream%5Fcipher" rel="nofollow">cipher</a> and be done with it.</p>
0
2009-06-26T01:13:02Z
[ "python", "security", "encryption" ]
What is the most secure python "password" encryption
1,043,735
<p>I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he h...
5
2009-06-25T12:52:58Z
1,047,013
<p>If your script can decode the passwords, so can someone breaking in to your server. Encryption is only really useful when someone enters a password to unlock it - if it remains unlocked (or the script has the password to unlock it), the encryption is pointless</p> <p>This is why hashing is more useful, since it is ...
5
2009-06-26T02:01:28Z
[ "python", "security", "encryption" ]
How to do cleanup reliably in python?
1,044,073
<p>I have some ctypes bindings, and for each body.New I should call body.Free. The library I'm binding doesn't have allocation routines insulated out from the rest of the code (they can be called about anywhere there), and to use couple of useful features I need to make cyclic references.</p> <p>I think It'd solve if ...
3
2009-06-25T13:53:08Z
1,044,297
<p>What you want to do, that is create an object that allocates things and then deallocates automatically when the object is no longer in use, is almost impossible in Python, unfortunately. The <strong>del</strong> statement is not guaranteed to be called, so you can't rely on that. </p> <p>The standard way in Python ...
3
2009-06-25T14:33:21Z
[ "python", "ctypes", "cyclic-reference" ]
How to do cleanup reliably in python?
1,044,073
<p>I have some ctypes bindings, and for each body.New I should call body.Free. The library I'm binding doesn't have allocation routines insulated out from the rest of the code (they can be called about anywhere there), and to use couple of useful features I need to make cyclic references.</p> <p>I think It'd solve if ...
3
2009-06-25T13:53:08Z
1,044,393
<p>If weakrefs aren't broken, I guess this may work:</p> <pre><code>from weakref import ref pointers = set() class Pointer(object): def __init__(self, cfun, ptr): pointers.add(self) self.ref = ref(ptr, self.cleanup) self.data = cast(ptr, c_void_p).value # python cast it so smart, but it c...
0
2009-06-25T14:52:06Z
[ "python", "ctypes", "cyclic-reference" ]
How to do cleanup reliably in python?
1,044,073
<p>I have some ctypes bindings, and for each body.New I should call body.Free. The library I'm binding doesn't have allocation routines insulated out from the rest of the code (they can be called about anywhere there), and to use couple of useful features I need to make cyclic references.</p> <p>I think It'd solve if ...
3
2009-06-25T13:53:08Z
1,045,020
<p>In CPython, <code>__del__</code> <em>is</em> a reliable destructor of an object, because it will always be called when the reference count reaches zero (note: there may be cases - like circular references of items with <code>__del__</code> method defined - where the reference count will never reaches zero, but that ...
0
2009-06-25T16:55:14Z
[ "python", "ctypes", "cyclic-reference" ]
BeanStalkd on Solaris doesnt return anything when called from the python library
1,044,473
<p>i am using Solaris 10 OS(x86). i installed beanstalkd and it starts fine by using command "beanstalkd -d -l hostip -p 11300".</p> <p>i have Python 2.4.4 on my system i installed YAML and beanstalkc python libraries to connect beanstalkd with python my problem is when i try to write some code:</p> <p>import beansta...
2
2009-06-25T15:06:41Z
1,044,719
<p>It seems that the python-client listens to the server, but the server has nothing to say.</p> <p>Is there something to read for the client?</p> <p>Is there a consumer AND a producer ?</p> <p><a href="http://parand.com/say/index.php/2008/10/12/beanstalkd-python-basic-tutorial/" rel="nofollow">Look at this</a></p>
1
2009-06-25T15:51:37Z
[ "python", "solaris", "yaml", "beanstalkd" ]
BeanStalkd on Solaris doesnt return anything when called from the python library
1,044,473
<p>i am using Solaris 10 OS(x86). i installed beanstalkd and it starts fine by using command "beanstalkd -d -l hostip -p 11300".</p> <p>i have Python 2.4.4 on my system i installed YAML and beanstalkc python libraries to connect beanstalkd with python my problem is when i try to write some code:</p> <p>import beansta...
2
2009-06-25T15:06:41Z
1,048,086
<p>After looking in the code (beanstalkc):</p> <p>your client has send his 'list-tubes' message, and is waiting for an answer. (until you kill it) your server doesn't answer or can't send the answer to the client. (or the answer is shorter than the client expect)</p> <p>is a network-admin at your side (or site) :-)</...
1
2009-06-26T08:56:06Z
[ "python", "solaris", "yaml", "beanstalkd" ]
BeanStalkd on Solaris doesnt return anything when called from the python library
1,044,473
<p>i am using Solaris 10 OS(x86). i installed beanstalkd and it starts fine by using command "beanstalkd -d -l hostip -p 11300".</p> <p>i have Python 2.4.4 on my system i installed YAML and beanstalkc python libraries to connect beanstalkd with python my problem is when i try to write some code:</p> <p>import beansta...
2
2009-06-25T15:06:41Z
1,093,128
<p>I might know what is wrong: don't start it in daemon (-d) mode. I have experienced the same and by accident I found out what is wrong.</p> <p>Or rather, I don't know what is wrong, but it works without running it in daemon mode.</p> <p>./beanstalkd -p 9977 &amp; </p> <p>as an alternative.</p>
1
2009-07-07T15:46:41Z
[ "python", "solaris", "yaml", "beanstalkd" ]
Unable to solve a Python error message
1,044,705
<p><strong>The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming":</strong></p> <pre><code>def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: "...
1
2009-06-25T15:49:33Z
1,044,717
<p>Try modifying these lines:</p> <pre><code> print "%2d. %8.2f %8.2f %8.2f" % \ # mistake probably here (i, lyhennys, korkoera, kuukausiera) </code></pre> <p>to this line:</p> <pre><code> print "%2d. %8.2f %8.2f %8.2f" % (i, lyhennys, korkoera, kuukausiera) </code></pre> <p>Also, ...
2
2009-06-25T15:51:33Z
[ "python" ]
Unable to solve a Python error message
1,044,705
<p><strong>The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming":</strong></p> <pre><code>def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: "...
1
2009-06-25T15:49:33Z
1,044,721
<p>You can't have <em>anything</em>, even whitespace, after the line continuation character.</p> <p>Either delete the whitespace, or wrap the entire line in a pair of parentheses. <a href="http://docs.python.org/reference/lexical%5Fanalysis.html#implicit-line-joining">Python implicitly joins lines between parentheses...
6
2009-06-25T15:51:49Z
[ "python" ]
Unable to solve a Python error message
1,044,705
<p><strong>The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming":</strong></p> <pre><code>def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: "...
1
2009-06-25T15:49:33Z
1,044,731
<p>Try rewriting this:</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % \ # mistake probably here (i, lyhennys, korkoera, kuukausiera) </code></pre> <p>To this:</p> <pre><code>print ("%2d. %8.2f %8.2f %8.2f" % (i, lyhennys, korkoera, kuukausiera)) </code></pre> <p><code>\</code> should wor...
2
2009-06-25T15:54:11Z
[ "python" ]
Unable to solve a Python error message
1,044,705
<p><strong>The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming":</strong></p> <pre><code>def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: "...
1
2009-06-25T15:49:33Z
1,044,744
<p>Replace:</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % \ (i, lyhennys, korkoera, kuukausiera) </code></pre> <p>By:</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( i, lyhennys, korkoera, kuukausiera) </code></pre> <p>General remark: always use English for identifiers</p>
2
2009-06-25T15:56:44Z
[ "python" ]
Unable to solve a Python error message
1,044,705
<p><strong>The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming":</strong></p> <pre><code>def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: "...
1
2009-06-25T15:49:33Z
1,044,754
<p>Several answers already gave you the crux of your problem, but I want to make a plug for my favorite way to get logical line continuation in Python, when feasible:</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( # no mistake here i, lyhennys, korkoera, kuukausiera) </code></pre> <p>i.e., inst...
10
2009-06-25T15:57:51Z
[ "python" ]
Unable to solve a Python error message
1,044,705
<p><strong>The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming":</strong></p> <pre><code>def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: "...
1
2009-06-25T15:49:33Z
1,044,758
<p>In general, I find I don't use line continuation in Python. You can make it cleaner with parentheses and so on.</p>
1
2009-06-25T15:58:18Z
[ "python" ]
Unable to solve a Python error message
1,044,705
<p><strong>The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming":</strong></p> <pre><code>def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: "...
1
2009-06-25T15:49:33Z
1,044,759
<p>"\" means "this line continue to the next line" and it can't have any character after it. There probably is a space right after.</p> <p>Two solution :</p> <p>Ensure there is not spaces after;</p> <p>Rewrite the statement on one line :</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % (i, lyhennys, korkoera, kuukau...
0
2009-06-25T15:58:25Z
[ "python" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,044,859
<p>Double stars (<code>**</code>) are exponentiation. So "2 times 2" and "2 to the power 2" are the same. Change the numbers and you'll see a difference.</p>
29
2009-06-25T16:24:35Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,044,864
<p>2**2 = 2 power-of 2</p> <p>2*2 = 2 times 2 </p>
2
2009-06-25T16:25:28Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,044,865
<p>The <code>**</code> operator in Python is really "power;" that is, <code>2**3 = 8</code>.</p>
1
2009-06-25T16:25:38Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,044,866
<p>Try:</p> <pre><code>2**3*2 </code></pre> <p>and</p> <pre><code>2*3*2 </code></pre> <p>to see the difference.</p> <p><code>**</code> is the operator for "power of". In your particular operation, 2 to the power of 2 yields the same as 2 times 2. </p>
83
2009-06-25T16:25:55Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,044,867
<pre><code> 2**2 means 2 squared (2^2) 2*2 mean 2 times 2 (2x2) </code></pre> <p>In this case they happen to have the same value, but...</p> <pre><code> 3**3*4 != 3*3*4 </code></pre>
11
2009-06-25T16:25:57Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,044,869
<p>The top one is a "power" operator, so in this case it is the same as 2 * 2 equal to is 2 to the power of 2. If you put a 3 in the middle position, you will see a difference.</p>
1
2009-06-25T16:26:09Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,044,933
<p>To specifically answer your question <strong>Why is the code1 used if we can use code2?</strong> I might suggest that the programmer was thinking in a mathematically broader sense. Specifically, perhaps the broader equation is a power equation, and the fact that both first numbers are "2" is more coincidence than ma...
4
2009-06-25T16:36:26Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
1,045,786
<p>A double asterisk means to the power of. A single asterisk means multiplied by. 2<sup>2</sup> is the same as 2x2 which is why both answers came out as 4.</p>
1
2009-06-25T19:32:23Z
[ "python", "syntax" ]
What's the difference between "2*2" and "2**2" in Python?
1,044,854
<p>What is the difference between the following codes?</p> <p><strong>code1</strong>:</p> <pre><code>var=2**2*3 </code></pre> <p><strong>code2:</strong></p> <pre><code>var2=2*2*3 </code></pre> <p>I see no difference. This raises the following question.</p> <p><strong>Why is the code1 used if we can use code2?</s...
33
2009-06-25T16:23:16Z
12,082,829
<p>Power has more precedence than multiply, so:</p> <pre><code>2**2*3 = (2^2)*3 2*2*3 = 2*2*3 </code></pre>
1
2012-08-22T23:36:53Z
[ "python", "syntax" ]
Unable to understand a line of Python code exactly
1,044,889
<p><a href="http://stackoverflow.com/questions/1044705/unable-to-solve-a-python-error-message/1044754#1044754">Alex's answer</a> has the following line when translated to English</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( i, payment, interest, monthPayment) </code></pre> <p>I am unsure about th...
1
2009-06-25T16:30:45Z
1,044,915
<p>the %8.2f means allow 8 character spaces to hold the number given by the corrisponding variable holding a float, and then have decimal precision of 2.</p>
0
2009-06-25T16:33:54Z
[ "python", "syntax" ]
Unable to understand a line of Python code exactly
1,044,889
<p><a href="http://stackoverflow.com/questions/1044705/unable-to-solve-a-python-error-message/1044754#1044754">Alex's answer</a> has the following line when translated to English</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( i, payment, interest, monthPayment) </code></pre> <p>I am unsure about th...
1
2009-06-25T16:30:45Z
1,044,925
<p>The last % is an operator that takes the string before it and the tuple after and applies the formatting as you note. See the <a href="http://docs.python.org/library/stdtypes.html#index-586" rel="nofollow">Python tutorial</a> for more details.</p>
4
2009-06-25T16:35:08Z
[ "python", "syntax" ]
Unable to understand a line of Python code exactly
1,044,889
<p><a href="http://stackoverflow.com/questions/1044705/unable-to-solve-a-python-error-message/1044754#1044754">Alex's answer</a> has the following line when translated to English</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( i, payment, interest, monthPayment) </code></pre> <p>I am unsure about th...
1
2009-06-25T16:30:45Z
1,044,935
<p>The % is an operator which makes a format string. A simple example would be:</p> <pre><code>"%s is %s" % ( "Alice", "Happy" ) </code></pre> <p>Which would evaluate to the string <code>"Alice is Happy"</code>. The format string that is provided defines how the values you pass are put into the string; the syntax is ...
1
2009-06-25T16:37:08Z
[ "python", "syntax" ]
Unable to understand a line of Python code exactly
1,044,889
<p><a href="http://stackoverflow.com/questions/1044705/unable-to-solve-a-python-error-message/1044754#1044754">Alex's answer</a> has the following line when translated to English</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( i, payment, interest, monthPayment) </code></pre> <p>I am unsure about th...
1
2009-06-25T16:30:45Z
1,044,936
<p>The 8 in 8.2 is the width<br /> "Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger"<br /> The 2 is the number of decimal places</p> <p>The final % just links the format s...
7
2009-06-25T16:37:12Z
[ "python", "syntax" ]
Unable to understand a line of Python code exactly
1,044,889
<p><a href="http://stackoverflow.com/questions/1044705/unable-to-solve-a-python-error-message/1044754#1044754">Alex's answer</a> has the following line when translated to English</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( i, payment, interest, monthPayment) </code></pre> <p>I am unsure about th...
1
2009-06-25T16:30:45Z
1,044,975
<p>The % after a string tells Python to attempt to fill in the variables on the left side of the '%' operator with the items in the list on the right side of the '%' operator.</p> <p>The '%' operator knows to find the variable in the string by looking for character in the string starting with %. </p> <p>Your confusi...
1
2009-06-25T16:45:13Z
[ "python", "syntax" ]
Unable to understand a line of Python code exactly
1,044,889
<p><a href="http://stackoverflow.com/questions/1044705/unable-to-solve-a-python-error-message/1044754#1044754">Alex's answer</a> has the following line when translated to English</p> <pre><code>print "%2d. %8.2f %8.2f %8.2f" % ( i, payment, interest, monthPayment) </code></pre> <p>I am unsure about th...
1
2009-06-25T16:30:45Z
1,045,007
<p>As usual, a quote of the doc is required - <a href="http://docs.python.org/library/stdtypes.html#string-formatting" rel="nofollow">string-formatting</a>:</p> <blockquote> <p>String and Unicode objects have one unique built-in operation: <strong>the % operator</strong> (modulo). This is also known as the <em>strin...
1
2009-06-25T16:52:04Z
[ "python", "syntax" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,174
<p>The line</p> <pre><code>a, b = b, b+a </code></pre> <p>Doesn't easily translate. It's something like this. You could simplify it. This is the literal meaning.</p> <pre><code>t1 = b t2 = b+a a = t1 b = t2 </code></pre>
4
2009-06-25T17:23:04Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,182
<p>I'd do it this way:</p> <pre><code>public class FibonacciAlgorithm { private int a = 0; private int b = 1; public FibonacciAlgorithm() { } public int increment() { int temp = b; b = a + b; a = temp; return value; } public int getValue() { ret...
7
2009-06-25T17:23:51Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,184
<p>public Integer increment() { a = b; b = a + b; return value; }</p> <p>Is certainly wrong. I think switching the first two lines should do the trick</p>
-1
2009-06-25T17:23:52Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,186
<p>You need to store the value of either a or b in a temporary variable first;</p> <pre><code> public Integer increment() { int temp = a; a = b; b = temp + b; return value; } </code></pre>
2
2009-06-25T17:24:19Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,201
<p>Java integers can only store the first 46 Fibonacci numbers, use a lookup table.</p>
1
2009-06-25T17:28:20Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,208
<p>I'll just translate your earlier code:</p> <pre><code>public void fibb(int max) { int a = 0; int b = 1; while (a &lt; max) { System.out.println(a); int temp = a + b; a = b; b = temp; } } </code></pre>
0
2009-06-25T17:29:50Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,252
<p>Don't you want to create a function to return the nth Fibnoacci number? This is how I remember it being taught when I was a kid:</p> <pre><code>public int Fibb(int index) { if (index &lt; 2) return 1; else return Fibb(index-1)+Fibb(index-2); }; </code></pre> <p>Given the definition being the first pair of ...
0
2009-06-25T17:39:21Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,259
<p>The main problem with your Python-to-Java translation is that Python's assignment statement up there is executed all at once, while Java's are executed serially. Python's statement is equivalent to saying this:</p> <pre><code>Make a list out of 'b' and 'a + b' Make another list out of references to 'a' and 'b' Ass...
0
2009-06-25T17:40:39Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
1,045,871
<p>There was a recursive solution posted above, but this solution is tail recursive so it grows linearly.</p> <pre><code>public class Fibonacci { public long fibonacci(int number) { return fib(0,1,number); } private long fib(long result, long next, int n) { if (n == 0) return r...
0
2009-06-25T19:49:48Z
[ "java", "python" ]
How to create Fibonacci Sequence in Java
1,045,151
<p>I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:</p> <pre><code>a = 0 b = 1 while b &lt; 10: print b a, b = b, b+a </code></pre> <p>The problem is that ...
5
2009-06-25T17:20:15Z
2,616,189
<p>i'll do this</p> <pre><code>fib = 100; for(int a = 1, b = 0;a &lt;= fib;a += b, b = (a-b)) { System.out.print(a + ","); } </code></pre>
0
2010-04-11T06:01:41Z
[ "java", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,349
<p>I would not convert unless you are converting as part of an enterprise-wide switch from one language to another. Even then I would avoid converting until absolutely necessary. If it works, why change it? </p>
1
2009-06-25T18:01:24Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,351
<p>Quote: "If it doesn't break, don't fix it."</p> <p>Unless your company is moving towards .NET and/or there are no more qualified Python developer available anymore, then don't.</p>
13
2009-06-25T18:01:33Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,356
<p>Leave them as Python unless you hear a very good <em>business</em> reason to convert.</p>
6
2009-06-25T18:02:34Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,361
<p>There's IronPython , a python implementation for .NET. You could port it to that if you really need to get away from the "standard" python vm and onto the .NET platform</p>
8
2009-06-25T18:03:48Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,378
<p>If you're the only Python developer in a C# shop, then it makes plenty of sense to convert. If you quit tomorrow, no one will be able to maintain these systems.</p>
3
2009-06-25T18:06:03Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,446
<p>Changing languages just for the sake of changing languages is rarely a good idea. If the app is doing its obj then let it do its job. If you've got a corporate mandate to only use C#, that may be a different story (estimate the work involved, give the estimate to management, let them decide to pursue it or write u...
4
2009-06-25T18:20:37Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,479
<p>i will convert it from language a to language b for 1 million dollars. &lt;--- this would be the only business reason I would consider legit.</p>
-1
2009-06-25T18:26:16Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,512
<p>As long as the application is running fine there is no reason to switch to C#.</p>
1
2009-06-25T18:32:02Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,532
<p>The only thing I can think of is the performance boost C# will give you.</p>
0
2009-06-25T18:36:13Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,561
<p>Some reasons that come to mind:</p> <ul> <li>Performance </li> <li>Easier to find developers</li> <li>Huge huge huge developer and tools ecosystem</li> </ul> <p>But I second what the others have stated: if it ain't broke, don't fix it. Unless your boss is saying, "hey, we're moving all our crap to .NET", or you're...
0
2009-06-25T18:41:48Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,045,606
<p><strong>IF</strong> you are looking for reasons to convert them, I can think of a few. These don't necessarily mean you <em>should</em>, these are just possible reasons in the "recode" corner.</p> <ul> <li><strong>Maintainability</strong></li> </ul> <p>If you have a dev-shop that is primarily C# focused, then have...
1
2009-06-25T18:54:54Z
[ "c#", ".net", "python" ]
Is there any good reason to convert an app written in python to c#?
1,045,334
<p>I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python?</p>
2
2009-06-25T17:59:20Z
1,046,028
<p>Short and to the point answer: No, there is no reason.</p>
1
2009-06-25T20:23:25Z
[ "c#", ".net", "python" ]
How do you create an incremental ID in a Python Class
1,045,344
<p>I would like to create a unique ID for each object I created - here's the class:</p> <blockquote> <pre><code>class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active </code></pre> </block...
7
2009-06-25T18:00:22Z
1,045,368
<p>First, use Uppercase Names for Classes. lowercase names for attributes.</p> <pre><code>class Resource( object ): class_counter= 0 def __init__(self, name, position, type, active): self.name = name self.position = position self.type = type self.active = active self.id...
9
2009-06-25T18:04:54Z
[ "python", "class" ]
How do you create an incremental ID in a Python Class
1,045,344
<p>I would like to create a unique ID for each object I created - here's the class:</p> <blockquote> <pre><code>class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active </code></pre> </block...
7
2009-06-25T18:00:22Z
1,045,433
<p>Using count from <a href="http://docs.python.org/library/itertools.html">itertools</a> is great for this:</p> <pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; counter = itertools.count() &gt;&gt;&gt; a = next(counter) &gt;&gt;&gt; print a 0 &gt;&gt;&gt; print next(counter) 1 &gt;&gt;&gt; print next(counter) 2 ...
6
2009-06-25T18:16:54Z
[ "python", "class" ]
How do you create an incremental ID in a Python Class
1,045,344
<p>I would like to create a unique ID for each object I created - here's the class:</p> <blockquote> <pre><code>class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active </code></pre> </block...
7
2009-06-25T18:00:22Z
1,045,491
<p>Are you aware of the <a href="http://docs.python.org/library/functions.html#id" rel="nofollow">id function</a> in python, and could you use it instead of your counter idea?</p> <pre><code>class C(): pass x = C() y = C() print(id(x), id(y)) #(4400352, 16982704) </code></pre>
5
2009-06-25T18:28:23Z
[ "python", "class" ]
How do you create an incremental ID in a Python Class
1,045,344
<p>I would like to create a unique ID for each object I created - here's the class:</p> <blockquote> <pre><code>class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active </code></pre> </block...
7
2009-06-25T18:00:22Z
1,045,724
<p>Concise and elegant:</p> <pre><code>import itertools class resource_cl(): newid = itertools.count().next def __init__(self): self.id = resource_cl.newid() ... </code></pre>
25
2009-06-25T19:16:23Z
[ "python", "class" ]
How do you create an incremental ID in a Python Class
1,045,344
<p>I would like to create a unique ID for each object I created - here's the class:</p> <blockquote> <pre><code>class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active </code></pre> </block...
7
2009-06-25T18:00:22Z
11,548,525
<p>Another note on id() and rethinking other's answer about it. id() may return a unique number, if and only if it remembers every id ever returned even if an object is deleted; which it (id()) does not do. So therefore...</p> <p>In support of what others were saying that id() does not return a unique number; It is tr...
0
2012-07-18T19:04:12Z
[ "python", "class" ]
How do you create an incremental ID in a Python Class
1,045,344
<p>I would like to create a unique ID for each object I created - here's the class:</p> <blockquote> <pre><code>class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active </code></pre> </block...
7
2009-06-25T18:00:22Z
11,548,577
<p>I like to use generators for ids. Allow the generator to maintain a list of ids already used.</p> <pre><code># devplayer@gmail.com # 2012-07(jul)-19 class MakeUniqueStr(object): ''' unqstr = MakeUniqueStr(default_name='widget', sep='_') print(repr(unqstr('window'))) print(repr(unqstr('window'))) ...
0
2012-07-18T19:08:24Z
[ "python", "class" ]
How do you create an incremental ID in a Python Class
1,045,344
<p>I would like to create a unique ID for each object I created - here's the class:</p> <blockquote> <pre><code>class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active </code></pre> </block...
7
2009-06-25T18:00:22Z
11,548,746
<p>Ids sometimes benefit from using some fields of the object you wanted to reference. This is a old style database technique.</p> <p>for example if you have a app that keeps records for incoming customer phone calls, then possible use an id generated by time = some thing else</p> <pre><code>ident = '%s:%.4s:%.9s' % ...
0
2012-07-18T19:18:57Z
[ "python", "class" ]
Can I use Win32 COM to replace text inside a word document?
1,045,628
<p>I have to perform a large number of replacements in some documents, and the thing is, I would like to be able to automate that task. Some of the documents contain common strings, and this would be pretty useful if it could be automated. From what I read so far, COM could be one way of doing this, but I don't know if...
4
2009-06-25T18:58:32Z
1,045,690
<p>Checkout this link: <a href="http://python.net/crew/pirx/spam7/" rel="nofollow">http://python.net/crew/pirx/spam7/</a></p> <p>The links on the left side point to the documentation. </p> <p>You can generalize this using the object model, which is found here: </p> <p><a href="http://msdn.microsoft.com/en-us/library...
2
2009-06-25T19:09:40Z
[ "python", "winapi", "com", "ms-word", "replace" ]
Can I use Win32 COM to replace text inside a word document?
1,045,628
<p>I have to perform a large number of replacements in some documents, and the thing is, I would like to be able to automate that task. Some of the documents contain common strings, and this would be pretty useful if it could be automated. From what I read so far, COM could be one way of doing this, but I don't know if...
4
2009-06-25T18:58:32Z
1,045,701
<p>If <a href="http://mail.python.org/pipermail/python-list/2004-April/259213.html" rel="nofollow">this mailing list post</a> is right, accessing the document's text is a simple as:</p> <pre><code>MSWord = win32com.client.Dispatch("Word.Application") MSWord.Visible = 0 MSWord.Documents.Open(filename) docText = MSWord...
3
2009-06-25T19:11:42Z
[ "python", "winapi", "com", "ms-word", "replace" ]
Can I use Win32 COM to replace text inside a word document?
1,045,628
<p>I have to perform a large number of replacements in some documents, and the thing is, I would like to be able to automate that task. Some of the documents contain common strings, and this would be pretty useful if it could be automated. From what I read so far, COM could be one way of doing this, but I don't know if...
4
2009-06-25T18:58:32Z
1,045,710
<p>See if <a href="http://www.devshed.com/c/a/Python/Windows-Programming-in-Python/2/">this</a> gives you a start on word automation using python.</p> <p>Once you open a document, you could do the following.<br /> After the following code, you can Close the document &amp; open another.</p> <pre><code>Selection.Find.C...
8
2009-06-25T19:13:28Z
[ "python", "winapi", "com", "ms-word", "replace" ]
Can I use Win32 COM to replace text inside a word document?
1,045,628
<p>I have to perform a large number of replacements in some documents, and the thing is, I would like to be able to automate that task. Some of the documents contain common strings, and this would be pretty useful if it could be automated. From what I read so far, COM could be one way of doing this, but I don't know if...
4
2009-06-25T18:58:32Z
1,045,808
<p>I like the answers so far; <br /> here's a tested example (slightly modified from <a href="http://www.programmingforums.org/post105986.html">here</a>) <br /> that replaces all occurrences of a string in a Word document:</p> <pre><code>import win32com.client def search_replace_all(word_file, find_str, replace_str):...
10
2009-06-25T19:36:43Z
[ "python", "winapi", "com", "ms-word", "replace" ]
Can I use Win32 COM to replace text inside a word document?
1,045,628
<p>I have to perform a large number of replacements in some documents, and the thing is, I would like to be able to automate that task. Some of the documents contain common strings, and this would be pretty useful if it could be automated. From what I read so far, COM could be one way of doing this, but I don't know if...
4
2009-06-25T18:58:32Z
1,063,746
<p>You can also achieve this using <strong>VBScript</strong>. Just type the code into a file named <code>script.vbs</code>, then open a command prompt (Start -> Run -> Cmd), then switch to the folder where the script is and type: <pre><code>cscript script.vbs </code></pre></p> <pre><code> strFolder = "C:\Files" Const...
2
2009-06-30T13:39:50Z
[ "python", "winapi", "com", "ms-word", "replace" ]
Formatting output when writing a list to textfile
1,045,699
<p>i have a list of lists that looks like this:</p> <pre><code>dupe = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696',...
1
2009-06-25T19:11:36Z
1,045,720
<p>If this is your actual answer, you can:</p> <ol> <li>Output one line per every two elements in dupe. This is easier. Or, </li> <li>If your data isn't as structured (so you may you can make a dictionary where your long hash is the key, and the tail end of the string is your output. Make sense?</li> </ol> <p>In idea...
0
2009-06-25T19:15:28Z
[ "python", "list" ]
Formatting output when writing a list to textfile
1,045,699
<p>i have a list of lists that looks like this:</p> <pre><code>dupe = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696',...
1
2009-06-25T19:11:36Z
1,045,749
<p>Use a dict to group them:</p> <pre><code>data = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], \ ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], \ ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], \ ['b5cc17d3a35877ca8b76f0b2e07497039c250696', ...
0
2009-06-25T19:23:47Z
[ "python", "list" ]
Formatting output when writing a list to textfile
1,045,699
<p>i have a list of lists that looks like this:</p> <pre><code>dupe = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696',...
1
2009-06-25T19:11:36Z
1,045,751
<p>i take it your last question didn't solve your problem?</p> <p>instead of putting each list with repeating ID's and directories in seperate lists, why not make the file element of the list another sub list which contains all the files which have the same id and directory.</p> <p>so dupe would look like this:</p> ...
1
2009-06-25T19:24:01Z
[ "python", "list" ]
Formatting output when writing a list to textfile
1,045,699
<p>i have a list of lists that looks like this:</p> <pre><code>dupe = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696',...
1
2009-06-25T19:11:36Z
1,045,774
<p>First, group the lines by the "key" (the first two elements of each array):</p> <pre><code>dupedict = {} for a, b, c in dupe: dupedict.setdefault((a,b),[]).append(c) </code></pre> <p>Then print it out:</p> <pre><code>for key, values in dupedict.iteritems(): print ' '.join(key), ', '.join(values) </code></pre>...
2
2009-06-25T19:28:20Z
[ "python", "list" ]
Formatting output when writing a list to textfile
1,045,699
<p>i have a list of lists that looks like this:</p> <pre><code>dupe = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696',...
1
2009-06-25T19:11:36Z
1,045,785
<pre><code>from collections import defaultdict dupe = [ ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\...
1
2009-06-25T19:32:10Z
[ "python", "list" ]
HTTPS log in with urllib2
1,045,886
<p>I currently have a little script that downloads a webpage and extracts some data I'm interested in. Nothing fancy.</p> <p>Currently I'm downloading the page like so:</p> <pre><code>import commands command = 'wget --output-document=- --quiet --http-user=USER --http-password=PASSWORD https://www.example.ca/page.aspx...
5
2009-06-25T19:52:48Z
1,045,905
<p><a href="http://mail.python.org/pipermail/python-list/2003-July/213402.html">this</a> says, it should be straight forward</p> <blockquote> <p>[as] long as your local Python has SSL support.</p> </blockquote> <p>If you use just HTTP Basic Authentication, you must set different handler, as described <a href="http:...
5
2009-06-25T19:57:16Z
[ "python", "authentication", "https", "urllib2" ]
HTTPS log in with urllib2
1,045,886
<p>I currently have a little script that downloads a webpage and extracts some data I'm interested in. Nothing fancy.</p> <p>Currently I'm downloading the page like so:</p> <pre><code>import commands command = 'wget --output-document=- --quiet --http-user=USER --http-password=PASSWORD https://www.example.ca/page.aspx...
5
2009-06-25T19:52:48Z
1,046,153
<p>The urllib2 documentation has an example of working with Basic Authentication:</p> <p><a href="http://docs.python.org/library/urllib2.html#examples" rel="nofollow">http://docs.python.org/library/urllib2.html#examples</a></p>
1
2009-06-25T20:40:35Z
[ "python", "authentication", "https", "urllib2" ]
HTTPS log in with urllib2
1,045,886
<p>I currently have a little script that downloads a webpage and extracts some data I'm interested in. Nothing fancy.</p> <p>Currently I'm downloading the page like so:</p> <pre><code>import commands command = 'wget --output-document=- --quiet --http-user=USER --http-password=PASSWORD https://www.example.ca/page.aspx...
5
2009-06-25T19:52:48Z
32,503,699
<p>The <a href="http://www.python-requests.org/en/latest/" rel="nofollow">requests</a> module provides a modern API to HTTP/HTTPS capabilities.</p> <pre class="lang-python prettyprint-override"><code>import requests url = 'https://www.someserver.com/toplevelurl/somepage.htm' res = requests.get(url, auth=('USER', 'PA...
1
2015-09-10T13:47:25Z
[ "python", "authentication", "https", "urllib2" ]
Install pyCurl in ActivePython-2.6?
1,045,906
<p>I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6. </p> <p>I have had no problems installing any other modules so far, but am getting errors installing pyCurl. The error...
5
2009-06-25T19:57:17Z
1,045,951
<p>It looks like <code>curl-config</code> isn't in your path. Try running it from the command line and adjust the <code>PATH</code> environment variable as needed so that Python can find it.</p>
0
2009-06-25T20:04:36Z
[ "python", "libcurl", "pycurl", "activepython" ]
Install pyCurl in ActivePython-2.6?
1,045,906
<p>I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6. </p> <p>I have had no problems installing any other modules so far, but am getting errors installing pyCurl. The error...
5
2009-06-25T19:57:17Z
1,046,375
<p>I couldn't find a curl-config to add to the path, which makes sense as it's not a module that can be called (as far as I can tell)</p> <p>The answer ended up being a bit of a hack, but it works. </p> <p>As I had pyCurl working in my native python2.6 install, I simply copied the curl and pycurl items from the nativ...
1
2009-06-25T21:35:21Z
[ "python", "libcurl", "pycurl", "activepython" ]
Install pyCurl in ActivePython-2.6?
1,045,906
<p>I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6. </p> <p>I have had no problems installing any other modules so far, but am getting errors installing pyCurl. The error...
5
2009-06-25T19:57:17Z
1,400,996
<pre><code>$ apt-cache depends python-pycurl python-pycurl Depends: libc6 Depends: libcurl3-gnutls Depends: libgnutls26 Depends: libidn11 Depends: libkrb53 Depends: libldap-2.4-2 Depends: zlib1g Depends: python Depends: python Depends: python-central [...] </code></pre> <p>So first install the depe...
2
2009-09-09T17:31:03Z
[ "python", "libcurl", "pycurl", "activepython" ]
Install pyCurl in ActivePython-2.6?
1,045,906
<p>I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6. </p> <p>I have had no problems installing any other modules so far, but am getting errors installing pyCurl. The error...
5
2009-06-25T19:57:17Z
12,514,310
<p>Following dependencies are needed for installing pycurl:</p> <pre><code>apt-cache depends python-pycurl python-pycurl Depends: libc6 Depends: libcurl3-gnutls Depends: libgcrypt11 Depends: python2.7 Depends: python Depends: python Suggests: libcurl4-gnutls-dev Suggests: python-pycurl-dbg Conflicts: &lt;python2.3-py...
5
2012-09-20T14:02:16Z
[ "python", "libcurl", "pycurl", "activepython" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,099
<p><strong>correct for most circumstances</strong></p> <p>The runtime/language/compiler will abstract those details unless you are dealing directly with word sizes or binary at a low level.</p> <p>Even byteorder is abstracted by the NIC/Network stack in the kernel. It is translated for you. When programming sockets i...
15
2009-06-25T20:34:25Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,100
<p>You will need to care about "endian-ness" only if you send and receive raw C structs over the wire like</p> <pre> ret = send(socket, &myStruct, sizeof(myStruct)); </pre> <p>However this is not a recommended practice.</p> <p>It's recommended that you define a protocol between the parties such it doesn't matter th...
0
2009-06-25T20:34:35Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,113
<p>In C++, you have to be very careful if you want to write code that works indifferently on 32 or 64 bits. Many people wrongly assume that <code>int</code> can store a pointer, for example.</p>
0
2009-06-25T20:35:52Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,128
<p>Knowing how things work, be it how the virtual machine works, and how it works on your platform, or how certain C++ constructs are transformed into assembly will always make you a better programmer, because you will understand why things should be done the way they are.</p> <p>You need to understand things like mem...
14
2009-06-25T20:37:48Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,141
<p>If you are programming in Python or in Java, the interpreter and the virtual machine respectively abstract this layer of the architecture. You then need not to worry if it's running on a 32 or 64 bits architecture.</p> <p>The same cannot be said for C++, in which you'll have to ask yourself sometimes if you are run...
1
2009-06-25T20:39:10Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,149
<p>In Java and Python, architecture details are abstracted away so that it is in fact more or less impossible to write architecture-dependant code.</p> <p>With C++, this is an entirely different matter - you can certainly write code that does not depend on architecture details, but you have be careful to avoid pitfall...
3
2009-06-25T20:40:07Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,180
<p><strong>You sometimes must bother.</strong></p> <p>You can be surprised when these low-level details suddenly jump out and bite you. For example, Java standardized <code>double</code> to be 64 bit. However, Linux JVM uses the "extended precision" mode, when the double is 80 bit as long as it's in the CPU register. ...
5
2009-06-25T20:46:39Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,182
<p>As long as you do things correctly, you almost never need to know for most languages. On many, you never need to know, as the language behavior doesn't vary (Java, for example, specifies the runtime behavior precisely).</p> <p>In C++ and C, doing things correctly includes not making assumptions about int. Don't p...
2
2009-06-25T20:46:48Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,209
<p>The last time I looked at the Java language spec, it contained a ridiculous gotcha in the section on integer boxing.</p> <pre><code>Integer a = 100; Integer b = 100; System.out.println(a == b); </code></pre> <p>That is guaranteed to print <code>true</code>.</p> <pre><code>Integer a = 300; Integer b = 300; Syste...
6
2009-06-25T20:53:07Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,298
<p>With java and .net you don't really have to bother with it unless you are doing very low level stuff like twiddling bits. If you are using c, c++, fortran you might get by but I would actually recommend using things like "stdint.h" where you use definitive declares like uint64_t and uint32_t so as to be explicit. Al...
0
2009-06-25T21:12:29Z
[ "java", "c++", "python", "64bit", "32-bit" ]
Would one have to know the machine architecture to write code?
1,046,068
<p>Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?</p> <p>IMHO, unless I'm programming something to do with fairly low-level stuff then I don't h...
6
2009-06-25T20:30:22Z
1,046,737
<p>A 32 bit machine will allow you to have a maximum of 4 GB of addressable virtual memory. (In practice, it's even less than that, usually 2 GB or 3 GB depending on the OS and various linker options.) On a 64 bit machine, you can have a HUGE virtual address space (in any practical sense, limited only by disk) and a ...
0
2009-06-25T23:43:56Z
[ "java", "c++", "python", "64bit", "32-bit" ]
python classes that refer to each other
1,046,150
<p>I have two classes that refer to each other, but obviously the compiler complains. Is there any way around this?</p> <p><strong>EDIT</strong></p> <p>Actually my code is slightly different than what Hank Gay uses. So python can definitely deal with some kinds of circular references, but it tosses an error in the ...
3
2009-06-25T20:40:08Z
1,046,174
<p>UPDATE: He changed the question after my answer. The currently accepted solution is better in light of the new question.</p> <p>What are you saying is the problem?</p> <pre><code>class A(object): def __init__(self): super(A, self).__init__() def b(self): return B() class B(object): ...
1
2009-06-25T20:45:15Z
[ "python", "django", "oop" ]
python classes that refer to each other
1,046,150
<p>I have two classes that refer to each other, but obviously the compiler complains. Is there any way around this?</p> <p><strong>EDIT</strong></p> <p>Actually my code is slightly different than what Hank Gay uses. So python can definitely deal with some kinds of circular references, but it tosses an error in the ...
3
2009-06-25T20:40:08Z
1,046,366
<p>As long as you are working within a method you can access the class object.</p> <p>Thus the example above has no problems if <code>creator.register(Y)</code> is moved inside <code>__init__</code>. However, you cannot have circular references to classes outside of methods.</p>
3
2009-06-25T21:31:27Z
[ "python", "django", "oop" ]
python classes that refer to each other
1,046,150
<p>I have two classes that refer to each other, but obviously the compiler complains. Is there any way around this?</p> <p><strong>EDIT</strong></p> <p>Actually my code is slightly different than what Hank Gay uses. So python can definitely deal with some kinds of circular references, but it tosses an error in the ...
3
2009-06-25T20:40:08Z
1,046,418
<p>In python, the code in a class is run when the class is loaded.</p> <p>Now, what the hell does that mean? ;-)</p> <p>Consider the following code:</p> <pre><code>class x: print "hello" def __init__(self): print "hello again" </code></pre> <p>When you load the module that contains the code, python will pri...
11
2009-06-25T21:46:20Z
[ "python", "django", "oop" ]
python classes that refer to each other
1,046,150
<p>I have two classes that refer to each other, but obviously the compiler complains. Is there any way around this?</p> <p><strong>EDIT</strong></p> <p>Actually my code is slightly different than what Hank Gay uses. So python can definitely deal with some kinds of circular references, but it tosses an error in the ...
3
2009-06-25T20:40:08Z
1,046,426
<p>The error is that execution of <code>creator.register(Y)</code> is attempted during the (executable) definition of class X, and at that stage, class Y is not defined. Understand this: <code>class</code> and <code>def</code> are statements that are executed (typically at import time); they are not "declarations". </p...
1
2009-06-25T21:48:00Z
[ "python", "django", "oop" ]
python classes that refer to each other
1,046,150
<p>I have two classes that refer to each other, but obviously the compiler complains. Is there any way around this?</p> <p><strong>EDIT</strong></p> <p>Actually my code is slightly different than what Hank Gay uses. So python can definitely deal with some kinds of circular references, but it tosses an error in the ...
3
2009-06-25T20:40:08Z
1,046,653
<p>The problem is most likely not Python. I would think it is an SQL issue. The classes are via an abstraction layer converted to an SQL query to create a table. You are trying to reference from one table another one that at the time does not exist yet.</p> <p>In SQL you would solve this by creating the table first w...
0
2009-06-25T23:09:59Z
[ "python", "django", "oop" ]
wxpython: How can I redraw something when a window is retored?
1,046,157
<p>In my wx.Frame based wxpython application, I draw some lines on a panel when some events occur by creating wx.ClientDC instances when needed. The only problem is, if the window is minimized and then restored, the lines disappear! Is there some kind of method that I should override or event to bind to that will allow...
1
2009-06-25T20:42:18Z
1,046,259
<p>When the window is restored it is (on some platforms) repainted using EVT_PAINT handler.</p> <p>The solution is e.g. to draw the same lines in OnPaint(). Or buffer what you draw. See the wxBufferedDC class.</p>
0
2009-06-25T21:03:45Z
[ "python", "wxpython" ]
wxpython: How can I redraw something when a window is retored?
1,046,157
<p>In my wx.Frame based wxpython application, I draw some lines on a panel when some events occur by creating wx.ClientDC instances when needed. The only problem is, if the window is minimized and then restored, the lines disappear! Is there some kind of method that I should override or event to bind to that will allow...
1
2009-06-25T20:42:18Z
1,047,603
<p>only place you must be drawing is on wx.EVT_PAINT, so bind to that event in <strong>init</strong> of panel e.g.</p> <pre><code>self.Bind(wx.EVT_PAINT, self._onPaint) </code></pre> <p>in _onPaint, use wx.PaintDC to to draw e.g.</p> <pre><code>dc = wx.PaintDC(self) dc.DrawLine(0,0,100,100) </code></pre>
1
2009-06-26T06:17:42Z
[ "python", "wxpython" ]
python observer pattern
1,046,190
<p>I'm new to python but I've run into a hitch when trying to implement a variation of the observer pattern.</p> <pre><code>class X(models.Model): a = models.ForeignKey(Voter) b = models.CharField(max_length=200) # Register Y.register(X) </code></pre> <p>This doesn't seem to work because it says X i...
3
2009-06-25T20:48:47Z
1,046,226
<p>There is nothing wrong with running (limited) code in the class definition:</p> <pre><code>class X(object): print("Loading X") </code></pre> <p>However, you can not refer to X because it is not yet fully defined.</p>
4
2009-06-25T20:56:36Z
[ "python", "django" ]
python observer pattern
1,046,190
<p>I'm new to python but I've run into a hitch when trying to implement a variation of the observer pattern.</p> <pre><code>class X(models.Model): a = models.ForeignKey(Voter) b = models.CharField(max_length=200) # Register Y.register(X) </code></pre> <p>This doesn't seem to work because it says X i...
3
2009-06-25T20:48:47Z
1,046,229
<p>In python, code defined in a class block is executed and only <strong>then</strong>, depending on various things---like what has been defined in this block---a class is created. So if you want to relate one class with another, you'd write:</p> <pre><code>class X(models.Model): a = models.ForeignKey(Voter) b...
5
2009-06-25T20:57:25Z
[ "python", "django" ]
Python - Subprocess - How to call a Piped command in Windows?
1,046,474
<p>How do I run this command with subprocess?</p> <p>I tried:</p> <pre><code>proc = subprocess.Popen( '''ECHO bosco|"C:\Program Files\GNU\GnuPG\gpg.exe" --batch --passphrase-fd 0 --output "c:\docume~1\usi\locals~1\temp\tmptlbxka.txt" --decrypt "test.txt.gpg"''', stdin=subprocess.PIPE, stdout=subprocess.PI...
5
2009-06-25T22:04:16Z
1,046,522
<p>First and foremost, you don't actually need a pipe; you are just sending input. You can use <a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate">subprocess.communicate</a> for that.</p> <p>Secondly, don't specify the command as a string; that's messy as soon as filenames with spaces...
11
2009-06-25T22:18:50Z
[ "python", "subprocess", "pipe", "echo", "popen" ]