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 |
|---|---|---|---|---|---|---|---|---|---|
Add Quotes in url string from file | 543,199 | <p>I need script to add quotes in url string from url.txt</p>
<p>from <code>http://www.site.com/info.xx</code> to <code>"http://www.site.com/info.xx"</code></p>
| 2 | 2009-02-12T20:54:42Z | 543,445 | <p>If '<code>url.txt</code>' contains a list of urls, one url per line then:</p>
<ul>
<li><p>quote the first non-whitespace character sequence:</p>
<pre><code>$ perl -pe"s~\S+~\"$&\"~" url.txt
</code></pre></li>
<li><p>or trim whitespaces and quote the rest:</p>
<pre><code>$ perl -nE"$_=trim; say qq(\"$_\")" url... | 0 | 2009-02-12T21:42:06Z | [
"python",
"ruby",
"perl"
] |
Add Quotes in url string from file | 543,199 | <p>I need script to add quotes in url string from url.txt</p>
<p>from <code>http://www.site.com/info.xx</code> to <code>"http://www.site.com/info.xx"</code></p>
| 2 | 2009-02-12T20:54:42Z | 781,210 | <p>A simple Perl script:</p>
<pre><code>#!/usr/bin/perl
use strict;
use warnings;
while (my $line = <>) {
$line =~ s/\s*(.*)\s*/$1/;
print qq/"$line"\n/;
}
</code></pre>
| 0 | 2009-04-23T10:54:29Z | [
"python",
"ruby",
"perl"
] |
Python string formatting | 543,399 | <p>I see you guys using</p>
<pre><code>url = '"%s"' % url # This part
>>> url = "http://www.site.com/info.xx"
>>> print url
http://www.site.com/info.xx
>>> url = '"%s"' % url
>>> print url
"http://www.site.com/info.xx"
</code></pre>
<p>Is it advanced Python? Is there a tutorial fo... | 2 | 2009-02-12T21:34:14Z | 543,416 | <p>It is not advanced, you can use ' or " to define a string.</p>
<p>Check the <a href="http://docs.python.org/reference/lexical_analysis.html#strings" rel="nofollow">documentation</a>.</p>
| 0 | 2009-02-12T21:37:33Z | [
"python"
] |
Python string formatting | 543,399 | <p>I see you guys using</p>
<pre><code>url = '"%s"' % url # This part
>>> url = "http://www.site.com/info.xx"
>>> print url
http://www.site.com/info.xx
>>> url = '"%s"' % url
>>> print url
"http://www.site.com/info.xx"
</code></pre>
<p>Is it advanced Python? Is there a tutorial fo... | 2 | 2009-02-12T21:34:14Z | 543,417 | <p>That line of code is using Python string formatting. You can read up more on how to use it here: <a href="http://docs.python.org/library/stdtypes.html#string-formatting" rel="nofollow">http://docs.python.org/library/stdtypes.html#string-formatting</a></p>
| 8 | 2009-02-12T21:37:36Z | [
"python"
] |
Python string formatting | 543,399 | <p>I see you guys using</p>
<pre><code>url = '"%s"' % url # This part
>>> url = "http://www.site.com/info.xx"
>>> print url
http://www.site.com/info.xx
>>> url = '"%s"' % url
>>> print url
"http://www.site.com/info.xx"
</code></pre>
<p>Is it advanced Python? Is there a tutorial fo... | 2 | 2009-02-12T21:34:14Z | 543,427 | <p>No, but <code>//</code> for comments sure is advanced Python. Try a <code>#</code> prefix for comments.</p>
| 4 | 2009-02-12T21:39:37Z | [
"python"
] |
Python string formatting | 543,399 | <p>I see you guys using</p>
<pre><code>url = '"%s"' % url # This part
>>> url = "http://www.site.com/info.xx"
>>> print url
http://www.site.com/info.xx
>>> url = '"%s"' % url
>>> print url
"http://www.site.com/info.xx"
</code></pre>
<p>Is it advanced Python? Is there a tutorial fo... | 2 | 2009-02-12T21:34:14Z | 543,453 | <p>It's common string formatting, and very useful. It's analogous to C-style printf formatting. See <a href="http://docs.python.org/library/stdtypes.html#string-formatting">String Formatting Operations</a> in the Python.org docs. You can use multiple arguments like this:</p>
<pre><code>"%3d\t%s" % (42, "the answer to ... | 10 | 2009-02-12T21:43:26Z | [
"python"
] |
Using different versions of python for different projects in Eclipse | 543,466 | <p>So, I'm slowly working in some Python 3.0, but I still have a lot of things that rely on 2.5. </p>
<p>But, in Eclipse, every time I change projects between a 3.0 and a 2.5, I need to go through </p>
<p>Project -> Properties -> project type.</p>
<p><strong>Issue 1:</strong> if I just switch the interpreter in the ... | 12 | 2009-02-12T21:45:27Z | 545,718 | <p>OK --</p>
<p>It definitely seems like "interpreter" is a property of your "workspace". I hadn't really considered that too much because I always thought of the workspace as "a folder in which I keep whatever" instead of a consistent unified environment for one kind of development. </p>
<p>Also, you can't switch be... | 1 | 2009-02-13T12:14:14Z | [
"python",
"eclipse"
] |
Using different versions of python for different projects in Eclipse | 543,466 | <p>So, I'm slowly working in some Python 3.0, but I still have a lot of things that rely on 2.5. </p>
<p>But, in Eclipse, every time I change projects between a 3.0 and a 2.5, I need to go through </p>
<p>Project -> Properties -> project type.</p>
<p><strong>Issue 1:</strong> if I just switch the interpreter in the ... | 12 | 2009-02-12T21:45:27Z | 545,880 | <p>You can set the interpreter version on a per-script basis through the Run Configurations menu.</p>
<p>To do this go to Run -> Run Configurations, and then make a new entry under Python Run. Fill in your project name and the main script, and then go to the Interpeter tab and you can pick which interpreter you want t... | 7 | 2009-02-13T13:16:16Z | [
"python",
"eclipse"
] |
Struct with a pointer to its own type in ctypes | 543,483 | <p>I'm trying to map a struct definition using ctypes:</p>
<pre><code>struct attrl {
struct attrl *next;
char *name;
char *resource;
char *value;
};
</code></pre>
<p>I'm unsure what to do with the "next" field of the struct... | 3 | 2009-02-12T21:47:04Z | 543,539 | <p>You need the equivalent of a forward declaration, <a href="http://python.net/crew/theller/ctypes/tutorial.html#incomplete-types" rel="nofollow">as described here</a>.</p>
| 3 | 2009-02-12T21:54:01Z | [
"python",
"ctypes"
] |
Why is KeyboardInterrupt not working in python? | 543,534 | <p>Why doesn't code like the following catch CTRL-C?</p>
<pre><code>MAXVAL = 10000
STEP_INTERVAL = 10
for i in range(1, MAXVAL, STEP_INTERVAL):
try:
print str(i)
except KeyboardInterrupt:
break
print "done"
</code></pre>
<p>My expectation is -- if CTRL-C is pressed while program is running, ... | 3 | 2009-02-12T21:53:42Z | 543,598 | <p>It does break out of the loop and print "done". </p>
| 0 | 2009-02-12T22:00:13Z | [
"python"
] |
Why is KeyboardInterrupt not working in python? | 543,534 | <p>Why doesn't code like the following catch CTRL-C?</p>
<pre><code>MAXVAL = 10000
STEP_INTERVAL = 10
for i in range(1, MAXVAL, STEP_INTERVAL):
try:
print str(i)
except KeyboardInterrupt:
break
print "done"
</code></pre>
<p>My expectation is -- if CTRL-C is pressed while program is running, ... | 3 | 2009-02-12T21:53:42Z | 543,605 | <p>It works.</p>
<p>I'm using Ubuntu Linux, and you?
Test it again using something like MaxVal = 10000000</p>
| 1 | 2009-02-12T22:01:18Z | [
"python"
] |
Why is KeyboardInterrupt not working in python? | 543,534 | <p>Why doesn't code like the following catch CTRL-C?</p>
<pre><code>MAXVAL = 10000
STEP_INTERVAL = 10
for i in range(1, MAXVAL, STEP_INTERVAL):
try:
print str(i)
except KeyboardInterrupt:
break
print "done"
</code></pre>
<p>My expectation is -- if CTRL-C is pressed while program is running, ... | 3 | 2009-02-12T21:53:42Z | 543,628 | <p>Sounds like the program is done by the time control-c has been hit, but your operating system hasn't finished showing you all the output. .</p>
| 14 | 2009-02-12T22:04:34Z | [
"python"
] |
Why is KeyboardInterrupt not working in python? | 543,534 | <p>Why doesn't code like the following catch CTRL-C?</p>
<pre><code>MAXVAL = 10000
STEP_INTERVAL = 10
for i in range(1, MAXVAL, STEP_INTERVAL):
try:
print str(i)
except KeyboardInterrupt:
break
print "done"
</code></pre>
<p>My expectation is -- if CTRL-C is pressed while program is running, ... | 3 | 2009-02-12T21:53:42Z | 543,912 | <p>code flow is as follows:</p>
<ol>
<li><code>for</code> grabs new object from list (generated by <code>range</code>) and sets <code>i</code> to it</li>
<li><code>try</code></li>
<li><code>print</code></li>
<li>go back to <code>1</code></li>
</ol>
<p>If you hit CTRL-C in the part 1 it is outside the <code>try</code>... | 11 | 2009-02-12T23:01:11Z | [
"python"
] |
Mapping a global variable from a shared library with ctypes | 544,173 | <p>I'd like to map an int value <code>pbs_errno</code> declared as a global in the library <code>libtorque.so</code> using ctypes.</p>
<p>Currently I can load the library like so:</p>
<pre><code>from ctypes import *
libtorque = CDLL("libtorque.so")
</code></pre>
<p>and have successfully mapped a bunch of the functio... | 12 | 2009-02-13T00:11:38Z | 546,128 | <p>There's a section in the ctypes docs about accessing values exported in dlls:</p>
<p><a href="http://docs.python.org/library/ctypes.html#accessing-values-exported-from-dlls">http://docs.python.org/library/ctypes.html#accessing-values-exported-from-dlls</a></p>
<p>e.g.</p>
<pre>
def pbs_errno():
return c_int.i... | 15 | 2009-02-13T14:30:16Z | [
"python",
"ctypes"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 544,487 | <p>Maybe this isn't the answer you're looking for, but if all you need is to turn the key into bits, it looks like it's Base64 encoded. Look at the <code>codecs</code> module (I think) in the standard Python library.</p>
| 1 | 2009-02-13T02:13:10Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 544,625 | <p>A public key contains both a modulus(very long number, can be 1024bit, 2058bit, 4096bit) and a public key exponent(much smaller number, usually equals one more than a two to some power). You need to find out how to split up that public key into the two components before you can do anything with it. </p>
<p>I don't ... | 2 | 2009-02-13T03:44:34Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 545,237 | <p>The data between the markers is the base64 encoding of the ASN.1 DER-encoding of a PKCS#8 PublicKeyInfo containing an PKCS#1 RSAPublicKey.</p>
<p>That is a lot of standards, and you will be best served with using a crypto-library to decode it (such as M2Crypto as <a href="http://stackoverflow.com/questions/544433/h... | 23 | 2009-02-13T08:54:06Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 545,249 | <p><del>I think <a href="http://www.freenet.org.nz/ezPyCrypto" rel="nofollow">ezPyCrypto</a> might make this a little easier. The high-level methods of the <strong>key</strong> class includes these two methods which I hope will solve your problem:</del> </p>
<ul>
<li><del><a href="http://www.freenet.org.nz/ezPyCrypto/... | 1 | 2009-02-13T09:01:22Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 546,476 | <p>Use <a href="http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.X509-module.html">M2Crypto</a>. Here's how to verify for RSA and any other algorithm supported by OpenSSL:</p>
<pre><code>pem = """-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ... | 27 | 2009-02-13T15:59:41Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 25,032,181 | <p>More on the DER decoding. </p>
<p>DER encoding always follows a TLV triplet format: (Tag, Length, Value) </p>
<ul>
<li>Tag specifies the type (i.e. data structure) of the value </li>
<li>Length specifies the number of byte this value field occupies</li>
<li>Value is the actual value which could be another triplet<... | 1 | 2014-07-30T08:34:34Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 25,195,849 | <p>I try the code given by joeforker but it does not work.
Here is my example code and it works fine.</p>
<pre><code>from Crypto.Signature import PKCS1_v1_5
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA
pem = """-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5sr... | -1 | 2014-08-08T03:59:08Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
How do you verify an RSA SHA1 signature in Python? | 544,433 | <p>I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:</p>
<pre><code>-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW
nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl
XnAVX5B4ec6cJfKKmpL... | 27 | 2009-02-13T01:50:48Z | 29,301,357 | <p>Using M2Crypto, the above answers does not work. Here is a tested example.</p>
<pre><code>import base64
import hashlib
import M2Crypto as m2
# detach the signature from the message if it's required in it (useful for url encoded data)
message_without_sign = message.split("&SIGN=")[0]
# decode base64 the signatu... | 0 | 2015-03-27T13:03:19Z | [
"python",
"cryptography",
"rsa",
"sha1",
"signature"
] |
Python plotting: How can I make matplotlib.pyplot stop forcing the style of my markers? | 544,542 | <p>I am trying to plot a bunch of data points (many thousands) in Python using <a href="http://matplotlib.sourceforge.net/index.html">matplotlib</a> so I need each marker to be very small and precise. How do I get the smallest most simple marker possible? I use this command to plot my data:</p>
<pre><code> matplotli... | 8 | 2009-02-13T02:41:45Z | 544,610 | <p>If you haven't, you should try saving in a rasterizing engine -- save it to a PNG file and see if that fixes it. If you need a vector plot, try saving to PDF and converting with an external utility. I've also had problems before with the PS engine that were resolved by saving with the Agg or PDF engines and conver... | 2 | 2009-02-13T03:32:39Z | [
"python",
"coding-style",
"matplotlib"
] |
Python plotting: How can I make matplotlib.pyplot stop forcing the style of my markers? | 544,542 | <p>I am trying to plot a bunch of data points (many thousands) in Python using <a href="http://matplotlib.sourceforge.net/index.html">matplotlib</a> so I need each marker to be very small and precise. How do I get the smallest most simple marker possible? I use this command to plot my data:</p>
<pre><code> matplotli... | 8 | 2009-02-13T02:41:45Z | 638,511 | <p>For nice-looking vectorized output, don't use the <code>'.'</code> marker style. Use e.g. <code>'o'</code> (circle) or <code>'s'</code> (square) (see <code>help(plot)</code> for the options) and set the <code>markersize</code> keyword argument to something suitably small, e.g.:</p>
<pre><code>plot(x, y, 'ko', marke... | 10 | 2009-03-12T12:58:58Z | [
"python",
"coding-style",
"matplotlib"
] |
Python plotting: How can I make matplotlib.pyplot stop forcing the style of my markers? | 544,542 | <p>I am trying to plot a bunch of data points (many thousands) in Python using <a href="http://matplotlib.sourceforge.net/index.html">matplotlib</a> so I need each marker to be very small and precise. How do I get the smallest most simple marker possible? I use this command to plot my data:</p>
<pre><code> matplotli... | 8 | 2009-02-13T02:41:45Z | 1,248,476 | <p>Have you tried the ',' point shape? Maybe you can play with markersize as well, with this shape?</p>
| 4 | 2009-08-08T09:57:43Z | [
"python",
"coding-style",
"matplotlib"
] |
problem ordering by votes with django-voting | 544,597 | <p>I have a model Post, and a model Vote. Vote (form django-voting) is essentially just a pointer to a Post and -1, 0, or 1. </p>
<p>There is also Tourn, which is a start date and an end date. A Post made between the start and end of a Tourn is submitted to that tournament.</p>
<p>For the sake of rep calculation, I'm... | 1 | 2009-02-13T03:25:23Z | 547,787 | <p>I think you need to assign <code>posts</code> to the return value of <code>posts.extra()</code>:</p>
<pre><code>posts = posts.extra(select={'score': """
SELECT SUM(vote)
FROM %s
WHERE content_type_id = %s
AND object_id = %s.id
... | 3 | 2009-02-13T21:34:47Z | [
"python",
"django",
"django-voting"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 544,944 | <p>Short answer: no. </p>
<p>Long answer: this is possible with some ugly hacks using traceback, inspect and the like, but it's generally probably not recommended for production code. For example see: </p>
<ul>
<li><a href="http://groups.google.com/group/comp.lang.python/msg/237dc92f3629dd9a?pli=1">http://groups.goog... | 23 | 2009-02-13T06:38:01Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 544,954 | <p>As far as I know, that will require some introspection. You can try using the inspect module.</p>
<p>There are a few simple things you may want to try before that:</p>
<ol>
<li>
This is not the exact code that should be used. You will have to retrieve the variable name from __dict__ before printing.
<p... | 1 | 2009-02-13T06:43:23Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 544,957 | <p>You could store the canonical name as an attribute of the instance, and then assign it to a variable with the same name. This might work:</p>
<pre><code>class MyEnum(object):
def __new__(cls, name):
try:
return getattr(MyEnum, name)
except AttributeError:
e = super(MyEnum... | 3 | 2009-02-13T06:43:56Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 544,966 | <p>To add to <a href="http://stackoverflow.com/questions/544919/python-can-i-print-original-var-name/544944#544944">@Jay's answer</a>, some concepts...</p>
<p>Python "variables" are simply references to values. Each value occupies a given memory location (see <code>id()</code>) </p>
<pre><code>>>> id(1)
100... | 21 | 2009-02-13T06:45:43Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 544,968 | <p>Erlang has a concept called "atoms" -- they are similar to string constants or enumerations. Consider using a string constant as the value of your enum -- the same as the name of the enum.</p>
| 0 | 2009-02-13T06:46:47Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 545,089 | <p>Just use the text you want to print as the value of the enum, as in</p>
<pre><code>class MyEnum (object):
valueA = "valueA"
valueB = "valueB"
</code></pre>
<p>comparing strings for identity is almost as efficient in Python as is comparing integer values (this is due to the fact the strings are immutable as... | 5 | 2009-02-13T07:47:56Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 545,663 | <p>There is no such thing as a unique or original variable name
<a href="http://www.amk.ca/quotations/python-quotes/page-8">http://www.amk.ca/quotations/python-quotes/page-8</a></p>
<blockquote>
<p>The same way as you get the name of that cat you found on your porch: the cat (object) itself cannot tell you its name,... | 17 | 2009-02-13T11:50:19Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 545,742 | <p>On second thought:</p>
<p>Since Python does not provide native Enum types, you should not ask for one, but instead use other, more powerful construct to build your program. Otherwise, the next step will invariably be "Why does Python not have a <code>switch ...:</code> statement, and how do I best emulate it?"</p>
... | 3 | 2009-02-13T12:28:17Z | [
"python",
"variables"
] |
Can I print original variable's name in Python? | 544,919 | <p>I have enum and use the variables like <code>myEnum.SomeNameA</code>, <code>myEnum.SomeNameB</code>, etc. When I return one of these variables from a function, can I print their names (such as <code>myEnum.SomeNameA</code>) instead of the value they returned?</p>
| 31 | 2009-02-13T06:30:06Z | 593,251 | <p>There are two answers to this question: <em>Yes</em> and <em>No</em>.</p>
<pre>
Can you do it? -- Yes (in most cases)
Is it worth it? -- No (in most cases)
</pre>
<h3>How to do it:</h3>
<p>It depends on an implementation of enums. For example:</p>
<pre><code>class Enum:
A = 1
B = 2
</code></pre>
<p>It... | 4 | 2009-02-27T01:51:36Z | [
"python",
"variables"
] |
Best method for reading newline delimited files in Python and discarding the newlines? | 544,921 | <p>I am trying to determine the best way to handle getting rid of newlines when reading in newline delimited files in Python.</p>
<p>What I've come up with is the following code, include throwaway code to test.</p>
<pre><code>import os
def getfile(filename,results):
f = open(filename)
filecontents = f.readline... | 68 | 2009-02-13T06:31:11Z | 544,932 | <pre><code>lines = open(filename).read().splitlines()
</code></pre>
| 169 | 2009-02-13T06:35:50Z | [
"python",
"file",
"readline"
] |
Best method for reading newline delimited files in Python and discarding the newlines? | 544,921 | <p>I am trying to determine the best way to handle getting rid of newlines when reading in newline delimited files in Python.</p>
<p>What I've come up with is the following code, include throwaway code to test.</p>
<pre><code>import os
def getfile(filename,results):
f = open(filename)
filecontents = f.readline... | 68 | 2009-02-13T06:31:11Z | 544,935 | <pre><code>for line in file('/tmp/foo'):
print line.strip('\n')
</code></pre>
| 7 | 2009-02-13T06:36:08Z | [
"python",
"file",
"readline"
] |
Best method for reading newline delimited files in Python and discarding the newlines? | 544,921 | <p>I am trying to determine the best way to handle getting rid of newlines when reading in newline delimited files in Python.</p>
<p>What I've come up with is the following code, include throwaway code to test.</p>
<pre><code>import os
def getfile(filename,results):
f = open(filename)
filecontents = f.readline... | 68 | 2009-02-13T06:31:11Z | 544,958 | <p>I'd do it like this:</p>
<pre><code>f = open('test.txt')
l = [l for l in f.readlines() if l.strip()]
f.close()
print l
</code></pre>
| 2 | 2009-02-13T06:43:59Z | [
"python",
"file",
"readline"
] |
Best method for reading newline delimited files in Python and discarding the newlines? | 544,921 | <p>I am trying to determine the best way to handle getting rid of newlines when reading in newline delimited files in Python.</p>
<p>What I've come up with is the following code, include throwaway code to test.</p>
<pre><code>import os
def getfile(filename,results):
f = open(filename)
filecontents = f.readline... | 68 | 2009-02-13T06:31:11Z | 545,188 | <p>Here's a generator that does what you requested. In this case, using rstrip is sufficient and slightly faster than strip.</p>
<pre><code>lines = (line.rstrip('\n') for line in open(filename))
</code></pre>
<p>However, you'll most likely want to use this to get rid of trailing whitespaces too.</p>
<pre><code>lines... | 19 | 2009-02-13T08:35:46Z | [
"python",
"file",
"readline"
] |
Best method for reading newline delimited files in Python and discarding the newlines? | 544,921 | <p>I am trying to determine the best way to handle getting rid of newlines when reading in newline delimited files in Python.</p>
<p>What I've come up with is the following code, include throwaway code to test.</p>
<pre><code>import os
def getfile(filename,results):
f = open(filename)
filecontents = f.readline... | 68 | 2009-02-13T06:31:11Z | 545,574 | <p>I use this</p>
<pre><code>def cleaned( aFile ):
for line in aFile:
yield line.strip()
</code></pre>
<p>Then I can do things like this.</p>
<pre><code>lines = list( cleaned( open("file","r") ) )
</code></pre>
<p>Or, I can extend cleaned with extra functions to, for example, drop blank lines or skip co... | 3 | 2009-02-13T11:07:27Z | [
"python",
"file",
"readline"
] |
Best method for reading newline delimited files in Python and discarding the newlines? | 544,921 | <p>I am trying to determine the best way to handle getting rid of newlines when reading in newline delimited files in Python.</p>
<p>What I've come up with is the following code, include throwaway code to test.</p>
<pre><code>import os
def getfile(filename,results):
f = open(filename)
filecontents = f.readline... | 68 | 2009-02-13T06:31:11Z | 548,697 | <p>Just use generator expressions:</p>
<pre><code>blahblah = (l.rstrip() for l in open(filename))
for x in blahblah:
print x
</code></pre>
<p>Also I want to advise you against reading whole file in memory -- looping over generators is much more efficient on big datasets.</p>
| 4 | 2009-02-14T07:43:58Z | [
"python",
"file",
"readline"
] |
Best method for reading newline delimited files in Python and discarding the newlines? | 544,921 | <p>I am trying to determine the best way to handle getting rid of newlines when reading in newline delimited files in Python.</p>
<p>What I've come up with is the following code, include throwaway code to test.</p>
<pre><code>import os
def getfile(filename,results):
f = open(filename)
filecontents = f.readline... | 68 | 2009-02-13T06:31:11Z | 6,978,940 | <p>What do you think about this approach?</p>
<pre><code>with open(filename) as data:
datalines = (line.rstrip('\r\n') for line in data)
for line in datalines:
...do something awesome...
</code></pre>
<p>Generator expression avoids loading whole file into memory and <code>with</code> ensures closing t... | 8 | 2011-08-08T07:26:31Z | [
"python",
"file",
"readline"
] |
Switching Printer Trays | 544,923 | <p>I know this question has been asked before, but there was no clear answer. </p>
<p>How do I change the printer tray programmatically?</p>
<p>I am trying to use python to batch print some PDFs. I need to print different pages from different trays. The printer is a Ricoh 2232C. Is there a way to do it through an... | 5 | 2009-02-13T06:32:56Z | 544,963 | <p>There is no easy way to do this, since you indicate you want to choose specific pages from the pdf and print them to specific bins using Acrobat Reader </p>
<p>Example: Print page 1 on letterhead bin 1, page 2 on stock bin 2</p>
<p>Acrobat Reader only allows printing of the whole document from the command line:</... | 1 | 2009-02-13T06:45:28Z | [
"python",
"winapi"
] |
Switching Printer Trays | 544,923 | <p>I know this question has been asked before, but there was no clear answer. </p>
<p>How do I change the printer tray programmatically?</p>
<p>I am trying to use python to batch print some PDFs. I need to print different pages from different trays. The printer is a Ricoh 2232C. Is there a way to do it through an... | 5 | 2009-02-13T06:32:56Z | 545,183 | <p>That's not possible using plain PDF, as you have create new <em>print job</em> for any particular bin and tray combination (and not all printers allow you to do that, Xerox 4x and DP Series allows you to do such things).</p>
<p>My best bet would be juggling with PostScript: convert PDF to PostScript, where you have... | 1 | 2009-02-13T08:33:27Z | [
"python",
"winapi"
] |
Switching Printer Trays | 544,923 | <p>I know this question has been asked before, but there was no clear answer. </p>
<p>How do I change the printer tray programmatically?</p>
<p>I am trying to use python to batch print some PDFs. I need to print different pages from different trays. The printer is a Ricoh 2232C. Is there a way to do it through an... | 5 | 2009-02-13T06:32:56Z | 551,704 | <p>Ok, I figured this out. The answer is: <br/>
<br/>
1. you need a local printer (if you need to print to a network printer, download the drivers and add it as a local printer)<br/>
2. use win32print to get and set default printer<br/>
3. also using win32print, use the following code:<br/>
<br/></p>
<pre><code>im... | 5 | 2009-02-15T22:09:30Z | [
"python",
"winapi"
] |
Switching Printer Trays | 544,923 | <p>I know this question has been asked before, but there was no clear answer. </p>
<p>How do I change the printer tray programmatically?</p>
<p>I am trying to use python to batch print some PDFs. I need to print different pages from different trays. The printer is a Ricoh 2232C. Is there a way to do it through an... | 5 | 2009-02-13T06:32:56Z | 14,751,866 | <p>You already have a Ricoh machine, just get yourself the Ricoh Print&Share software and there you can define what trays you want to use!</p>
<p>These videos show you how to set up the Ricoh Print&Share software:</p>
<ul>
<li><a href="http://www.youtube.com/watch?v=6iXuU4b5mh4" rel="nofollow">http://www.yout... | 0 | 2013-02-07T13:08:33Z | [
"python",
"winapi"
] |
Kerberos authentication with python | 545,294 | <p>I need to write a script in python to check a webpage, which is protected by kerberos. Is there any possibility to do this from within python and how? The script is going to be deployed on a linux environment with python 2.4.something installed.</p>
<p>dertoni</p>
| 10 | 2009-02-13T09:15:43Z | 545,499 | <p>I think that <code>python-krbV</code> and most Linux distributions also have a <code>python-kerberos</code> package. For example, Debian has one of the same name. Here's the documentation on <a href="http://packages.debian.org/testing/python/python-kerberos" rel="nofollow">it</a></p>
<p>Extract from link:</p>
<blo... | 11 | 2009-02-13T10:33:42Z | [
"python",
"security",
"kerberos"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 545,398 | <p>If you just want to hash the contents of the files, ignoring the filenames then you can use</p>
<pre><code>cat $FILES | md5sum
</code></pre>
<p>Make sure you have the files in the same order when computing the hash:</p>
<pre><code>cat $(echo $FILES | sort) | md5sum
</code></pre>
<p>But you can't have directories... | 3 | 2009-02-13T09:54:41Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 545,403 | <p>Try to make it in two steps:</p>
<ol>
<li>create a file with hashes for all files in a folder</li>
<li>hash this file</li>
</ol>
<p>Like so:</p>
<pre><code># for FILE in `find /folder/of/stuff -type f | sort`; do sha1sum $FILE >> hashes; done
# sha1sum hashes
</code></pre>
<p>Or do it all at once:</p>
<pr... | 0 | 2009-02-13T09:57:08Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 545,404 | <p>You could <code>sha1sum</code> to generate the list of hash values and then <code>sha1sum</code> that list again, it depends on what exactly it is you want to accomplish.</p>
| 0 | 2009-02-13T09:57:21Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 545,410 | <p>I would pipe the results for individual files through <code>sort</code> (to prevent a mere reordering of files to change the hash) into <code>md5sum</code> or <code>sha1sum</code>, whichever you choose.</p>
| 1 | 2009-02-13T09:58:39Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 545,413 | <p>One possible way would be:<pre>
sha1sum path/to/folder/* | sha1sum
</pre></p>
<p>If there is a whole directory tree, you're probably better off using find and xargs. One possible command would be <pre>
find path/to/folder -type f -print0 | xargs -0 sha1sum | sha1sum
</pre></p>
<p><b>Edit</b>: Good point, it's prob... | 48 | 2009-02-13T09:59:36Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 545,420 | <ul>
<li><p>Commit the directory to git, use the commit hash. See <a href="http://david.hardeman.nu/software.php#metastore">metastore</a> for a way to also control permissions.</p></li>
<li><p>Use a file system intrusion detection tool like <a href="http://sourceforge.net/projects/aide/">aide</a>.</p></li>
<li><p>hash ... | 11 | 2009-02-13T10:04:00Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 545,567 | <p>What's wrong with a <code>tar -c /path/to/folder | sha1sum</code>?</p>
| 5 | 2009-02-13T11:04:56Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 4,796,653 | <p>There is a python script for that:</p>
<p><a href="http://code.activestate.com/recipes/576973-getting-the-sha-1-or-md5-hash-of-a-directory/" rel="nofollow">http://code.activestate.com/recipes/576973-getting-the-sha-1-or-md5-hash-of-a-directory/</a></p>
<p>If you change the names of a file without changing their al... | 2 | 2011-01-25T17:12:41Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 31,702,032 | <p>Another tool to achieve this:</p>
<p><a href="http://md5deep.sourceforge.net/" rel="nofollow">http://md5deep.sourceforge.net/</a></p>
<p>As is sounds: like md5sum but also recursive, plus other features.</p>
| 1 | 2015-07-29T13:35:42Z | [
"python",
"linux",
"bash",
"hash"
] |
Linux: compute a single hash for a given folder & contents? | 545,387 | <p>Surely there must be a way to do this easily! </p>
<p>I've tried the linux command-line apps sha1sum & md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. </p>
<p>I need to generate a single hash for the entire contents of a folder (no... | 33 | 2009-02-13T09:51:40Z | 36,270,989 | <p>I've written a Groovy script to do this:</p>
<pre><code>import java.security.MessageDigest
public static String generateDigest(File file, String digest, int paddedLength){
MessageDigest md = MessageDigest.getInstance(digest)
md.reset()
def files = []
def directories = []
if(file.isDirectory())... | 1 | 2016-03-28T20:53:26Z | [
"python",
"linux",
"bash",
"hash"
] |
Using base class constructor as factory in Python? | 545,419 | <p>I'm using base class constructor as factory and changing class in this constructor/factory to select appropriate class -- is this approach is good python practice or there are more elegant ways? </p>
<p>I've tried to read help about metaclasses but without big success.</p>
<p>Here example of what I'm doing.</p>
<... | 5 | 2009-02-13T10:03:19Z | 545,444 | <p>I think the second approach using a factory function is a lot cleaner than making the implementation of your base class depend on its subclasses.</p>
| 0 | 2009-02-13T10:14:23Z | [
"python",
"factory"
] |
Using base class constructor as factory in Python? | 545,419 | <p>I'm using base class constructor as factory and changing class in this constructor/factory to select appropriate class -- is this approach is good python practice or there are more elegant ways? </p>
<p>I've tried to read help about metaclasses but without big success.</p>
<p>Here example of what I'm doing.</p>
<... | 5 | 2009-02-13T10:03:19Z | 545,446 | <p>I would stick with the factory function approach. It's very standard python and easy to read and understand. You could make it more generic to handle more options in several ways such as by passing in the discriminator function and a map of results to classes. </p>
<p>If the first example works it's more by luck... | 12 | 2009-02-13T10:15:37Z | [
"python",
"factory"
] |
Using base class constructor as factory in Python? | 545,419 | <p>I'm using base class constructor as factory and changing class in this constructor/factory to select appropriate class -- is this approach is good python practice or there are more elegant ways? </p>
<p>I've tried to read help about metaclasses but without big success.</p>
<p>Here example of what I'm doing.</p>
<... | 5 | 2009-02-13T10:03:19Z | 545,456 | <p>I usually have a seperate factory class to do this. This way you don't have to use meta classes or assignments to <code>self.__class__</code></p>
<p>I also try to avoid to put the knowledge about which classes are available for creation into the factory. Rather, I have all the available classes register themselves ... | 1 | 2009-02-13T10:19:40Z | [
"python",
"factory"
] |
Using base class constructor as factory in Python? | 545,419 | <p>I'm using base class constructor as factory and changing class in this constructor/factory to select appropriate class -- is this approach is good python practice or there are more elegant ways? </p>
<p>I've tried to read help about metaclasses but without big success.</p>
<p>Here example of what I'm doing.</p>
<... | 5 | 2009-02-13T10:03:19Z | 545,480 | <p>The following links may be helpful:
<a href="http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html#factory" rel="nofollow">http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html#factory</a>
<a href="http://code.activestate.com/recipes/86900/" rel="nofollow">http://code.activestate.com/recipes/... | 3 | 2009-02-13T10:26:50Z | [
"python",
"factory"
] |
Using base class constructor as factory in Python? | 545,419 | <p>I'm using base class constructor as factory and changing class in this constructor/factory to select appropriate class -- is this approach is good python practice or there are more elegant ways? </p>
<p>I've tried to read help about metaclasses but without big success.</p>
<p>Here example of what I'm doing.</p>
<... | 5 | 2009-02-13T10:03:19Z | 545,786 | <p>You shouldn't need metaclasses for this. Take a look at the <a href="http://docs.python.org/reference/datamodel.html#object.__new__"><code>__new__</code></a> method. This will allow you to take control of the creation of the object, rather than just the initialisation, and so return an object of your choosing.</p>... | 11 | 2009-02-13T12:49:18Z | [
"python",
"factory"
] |
Using base class constructor as factory in Python? | 545,419 | <p>I'm using base class constructor as factory and changing class in this constructor/factory to select appropriate class -- is this approach is good python practice or there are more elegant ways? </p>
<p>I've tried to read help about metaclasses but without big success.</p>
<p>Here example of what I'm doing.</p>
<... | 5 | 2009-02-13T10:03:19Z | 3,100,217 | <p>Yeah, as mentioned by @scooterXL, factory function is the best approach in that case, but I like to note a case for factories as classmethods.</p>
<p>Consider the following class hierarchy:</p>
<pre><code>class Base(object):
def __init__(self, config):
""" Initialize Base object with config as dict.""... | 2 | 2010-06-23T08:53:37Z | [
"python",
"factory"
] |
Tool (or combination of tools) for reproducible environments in Python | 545,730 | <p>I used to be a java developer and we used tools like ant or maven to manage our development/testing/UAT environments in a standardized way. This allowed us to handle library dependencies, setting OS variables, compiling, deploying, running unit tests, and all the required tasks. Also, the scripts generated guarantee... | 9 | 2009-02-13T12:20:56Z | 545,743 | <p>Other than <a href="http://peak.telecommunity.com/DevCenter/EasyInstall" rel="nofollow">easy_install</a>?</p>
<p>For our Linux servers, we use easy_install and yum.</p>
<p>For our Windows development laptops, we use easy_install and a few MSI's for some projects.</p>
<p>Most of the Python libraries we use are sou... | 2 | 2009-02-13T12:28:45Z | [
"python",
"continuous-integration",
"installation",
"development-environment",
"automated-deploy"
] |
Tool (or combination of tools) for reproducible environments in Python | 545,730 | <p>I used to be a java developer and we used tools like ant or maven to manage our development/testing/UAT environments in a standardized way. This allowed us to handle library dependencies, setting OS variables, compiling, deploying, running unit tests, and all the required tasks. Also, the scripts generated guarantee... | 9 | 2009-02-13T12:20:56Z | 545,746 | <p>I also work with both java and python.
For python development the maven equivalent is setuptools (<a href="http://peak.telecommunity.com/DevCenter/setuptools" rel="nofollow">http://peak.telecommunity.com/DevCenter/setuptools</a>). For web application development I use this in combination with paster (<a href="http:/... | 3 | 2009-02-13T12:29:30Z | [
"python",
"continuous-integration",
"installation",
"development-environment",
"automated-deploy"
] |
Tool (or combination of tools) for reproducible environments in Python | 545,730 | <p>I used to be a java developer and we used tools like ant or maven to manage our development/testing/UAT environments in a standardized way. This allowed us to handle library dependencies, setting OS variables, compiling, deploying, running unit tests, and all the required tasks. Also, the scripts generated guarantee... | 9 | 2009-02-13T12:20:56Z | 545,747 | <p>You will want <a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">easy_setup</a> to get the eggs (roughly what Maven calls an artifact).</p>
<p>For setting up your environment, have a look at <a href="http://blog.ianbicking.org/working-env.html" rel="nofollow">working-env.py</a></p>
<p>Python is not co... | 2 | 2009-02-13T12:30:18Z | [
"python",
"continuous-integration",
"installation",
"development-environment",
"automated-deploy"
] |
Tool (or combination of tools) for reproducible environments in Python | 545,730 | <p>I used to be a java developer and we used tools like ant or maven to manage our development/testing/UAT environments in a standardized way. This allowed us to handle library dependencies, setting OS variables, compiling, deploying, running unit tests, and all the required tasks. Also, the scripts generated guarantee... | 9 | 2009-02-13T12:20:56Z | 545,839 | <p>I do exactly this with a combination of setuptools and Hudson. I know Hudson is a java app, but it can run Python stuff just fine.</p>
| 0 | 2009-02-13T13:06:36Z | [
"python",
"continuous-integration",
"installation",
"development-environment",
"automated-deploy"
] |
Tool (or combination of tools) for reproducible environments in Python | 545,730 | <p>I used to be a java developer and we used tools like ant or maven to manage our development/testing/UAT environments in a standardized way. This allowed us to handle library dependencies, setting OS variables, compiling, deploying, running unit tests, and all the required tasks. Also, the scripts generated guarantee... | 9 | 2009-02-13T12:20:56Z | 545,912 | <ol>
<li><p><a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> to create a contained virtual environment (prevent different versions of Python or Python packages from stomping on each other). There is increasing buzz from people moving to this tool. The author is the same as the older working-env.py menti... | 18 | 2009-02-13T13:24:24Z | [
"python",
"continuous-integration",
"installation",
"development-environment",
"automated-deploy"
] |
Tool (or combination of tools) for reproducible environments in Python | 545,730 | <p>I used to be a java developer and we used tools like ant or maven to manage our development/testing/UAT environments in a standardized way. This allowed us to handle library dependencies, setting OS variables, compiling, deploying, running unit tests, and all the required tasks. Also, the scripts generated guarantee... | 9 | 2009-02-13T12:20:56Z | 546,992 | <p>We would be remiss not to also mention <a href="http://www.blueskyonmars.com/projects/paver/" rel="nofollow">Paver</a>, which was created by Kevin Dangoor of <a href="http://www.turbogears.org/" rel="nofollow">TurboGears</a> fame. The project is still in alpha, but it appears very promising. A snippet from the pro... | 2 | 2009-02-13T18:00:31Z | [
"python",
"continuous-integration",
"installation",
"development-environment",
"automated-deploy"
] |
Tool (or combination of tools) for reproducible environments in Python | 545,730 | <p>I used to be a java developer and we used tools like ant or maven to manage our development/testing/UAT environments in a standardized way. This allowed us to handle library dependencies, setting OS variables, compiling, deploying, running unit tests, and all the required tasks. Also, the scripts generated guarantee... | 9 | 2009-02-13T12:20:56Z | 2,831,204 | <p>You might want to check our <a href="http://www.viewtier.com/products/devenv/index.htm" rel="nofollow"><strong>Devenv</strong></a>. It allows you to standardize the build environments for development, QA and UAT. It's free as in "free beer".</p>
<p>HTH</p>
| 0 | 2010-05-14T00:53:17Z | [
"python",
"continuous-integration",
"installation",
"development-environment",
"automated-deploy"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 546,331 | <p>Use the python datetime module to add a timedelta of six months to datetime.today() .</p>
<p><a href="http://docs.python.org/library/datetime.html" rel="nofollow">http://docs.python.org/library/datetime.html</a></p>
<p>You will of course have to solve the issue raised by Johannes WeiÃ-- what <em>do</em> you mean ... | 0 | 2009-02-13T15:20:59Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 546,332 | <p>What do you mean by '6 months'. Is 2009-02-13 + 6 months == 2009-08-13 or is it 2009-02-13 + 6*30 days?</p>
<pre><code>import mx.DateTime as dt
#6 Months
dt.now()+dt.RelativeDateTime(months=6)
#result is '2009-08-13 16:28:00.84'
#6*30 days
dt.now()+dt.RelativeDateTime(days=30*6)
#result is '2009-08-12 16:30:03.35... | 10 | 2009-02-13T15:21:07Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 546,339 | <p>Just use the <em>timetuple</em> method to extract the months, add your months and build a new dateobject. If there is a already existing method for this I do not know it.</p>
<pre><code>import datetime
def in_the_future(months=1):
year, month, day = datetime.date.today().timetuple()[:3]
new_month = month +... | 6 | 2009-02-13T15:23:42Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 546,347 | <p><a href="http://labix.org/python-dateutil">Dateutil package</a> has implementation of such functionality. But be aware, that this will be <em>naive</em>, as others pointed already.</p>
| 7 | 2009-02-13T15:26:05Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 546,353 | <p>There's no direct way to do it with Python's datetime.</p>
<p>Check out the relativedelta type at <a href="http://labix.org/python-dateutil#head-ba5ffd4df8111d1b83fc194b97ebecf837add454">python-dateutil</a>. It allows you to specify a time delta in months.</p>
| 6 | 2009-02-13T15:29:05Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 546,354 | <p>Well, that depends what you mean by 6 months from the current date.</p>
<ol>
<li><p>Using natural months:</p>
<pre><code>(day, month, year) = (day, (month+6)%12, year+(month+6)/12)
</code></pre></li>
<li><p>Using a banker's definition, 6*30:</p>
<pre><code>date += datetime.timedelta(6*30)
</code></pre></li>
</ol>... | 36 | 2009-02-13T15:29:24Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 546,356 | <pre><code>import datetime
print (datetime.date.today() + datetime.timedelta(6*365/12)).isoformat()
</code></pre>
| 57 | 2009-02-13T15:29:46Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 1,750,124 | <p>The QDate class of PyQt4 has an addmonths function.</p>
<pre><code>>>>from PyQt4.QtCore import QDate
>>>dt = QDate(2009,12,31)
>>>required = dt.addMonths(6)
>>>required
PyQt4.QtCore.QDate(2010, 6, 30)
>>>required.toPyDate()
datetime.date(2010, 6, 30)
</code></pre>... | 2 | 2009-11-17T16:37:16Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 2,075,926 | <p>Modified Johannes Wei's answer in the case 1new_month = 121. This works perfectly for me. The months could be positive or negative.</p>
<pre><code>def addMonth(d,months=1):
year, month, day = d.timetuple()[:3]
new_month = month + months
return datetime.date(year + ((new_month-1) / 12), (new_month-1) %... | 0 | 2010-01-16T02:02:04Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 2,366,759 | <p>This is what I came up with. It moves the correct number of months and years but ignores days (which was what I needed in my situation).</p>
<pre><code>import datetime
month_dt = 4
today = datetime.date.today()
y,m = today.year, today.month
m += month_dt-1
year_dt = m//12
new_month = m%12
new_date = datetime.date(... | 0 | 2010-03-02T21:06:05Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 2,560,837 | <p>I use this function to change year and month but keep day:</p>
<pre><code>def replace_month_year(date1, year2, month2):
try:
date2 = date1.replace(month = month2, year = year2)
except:
date2 = datetime.date(year2, month2 + 1, 1) - datetime.timedelta(days=1)
return date2
</code></pre>
<p... | 0 | 2010-04-01T13:55:51Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 3,197,505 | <p>So, here is an example of the <code>dateutil.relativedelta</code> which I found useful for iterating through the past year, skipping a month each time to the present date:</p>
<pre><code>>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> today = datetime.datetime... | 6 | 2010-07-07T17:59:32Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 3,463,303 | <p>This solution works correctly for December, which most of the answers on this page do not.
You need to first shift the months from base 1 (ie Jan = 1) to base 0 (ie Jan = 0) before using modulus ( % ) or integer division ( // ), otherwise November (11) plus 1 month gives you 12, which when finding the remainder ( 12... | 9 | 2010-08-11T22:18:29Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 4,406,260 | <p>I found this solution to be good. (This uses the <a href="https://dateutil.readthedocs.org/en/latest/">python-dateutil extension</a>)</p>
<pre><code>from datetime import date
from dateutil.relativedelta import relativedelta
six_months = date.today() + relativedelta(months=+6)
</code></pre>
<p>The advantage of th... | 410 | 2010-12-10T06:22:36Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 4,873,454 | <p>I think it would be safer to do something like this instead of manually adding days:</p>
<pre><code>import datetime
today = datetime.date.today()
def addMonths(dt, months = 0):
new_month = months + dt.month
year_inc = 0
if new_month>12:
year_inc +=1
new_month -=12
return dt.repla... | 0 | 2011-02-02T10:45:33Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 4,875,773 | <p>I solved this problem like this:</p>
<pre><code>import calendar
from datetime import datetime
moths2add = 6
now = datetime.now()
current_year = now.year
current_month = now.month
#count days in months you want to add using calendar module
days = sum(
[calendar.monthrange(current_year, elem)[1] for elem in range(c... | 1 | 2011-02-02T14:44:44Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 5,254,091 | <pre><code>import datetime
'''
Created on 2011-03-09
@author: tonydiep
'''
def add_business_months(start_date, months_to_add):
"""
Add months in the way business people think of months.
Jan 31, 2011 + 1 month = Feb 28, 2011 to business people
Method: Add the number of months, roll back the date unt... | 1 | 2011-03-10T00:29:32Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 5,643,283 | <p>I know this was for 6 months, however the answer shows in google for "adding months in python" if you are adding one month:</p>
<pre><code>import calendar
date = datetime.date.today() //Or your date
datetime.timedelta(days=calendar.monthrange(date.year,date.month)[1])
</code></pre>
<p>this would count the day... | 7 | 2011-04-13T00:54:07Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 5,954,712 | <p>my modification to tony diep's answer, possibly marginally more elegant:</p>
<pre><code>def add_months(date, months):
month = date.month + months - 1
year = date.year + (month / 12)
month = (month % 12) + 1
day = date.day
while (day > 0):
try:
new_date = date.replace(year=... | 0 | 2011-05-10T18:33:26Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 6,123,390 | <p>I have a better way to solve the 'February 31st' problem:</p>
<pre><code>def add_months(start_date, months):
import calendar
year = start_date.year + (months / 12)
month = start_date.month + (months % 12)
day = start_date.day
if month > 12:
month = month % 12
year = year + 1... | 2 | 2011-05-25T11:00:03Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 6,251,949 | <p>Modified the AddMonths() for use in Zope and handling invalid day numbers:</p>
<pre><code>def AddMonths(d,x):
days_of_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
newmonth = ((( d.month() - 1) + x ) % 12 ) + 1
newyear = d.year() + ((( d.month() - 1) + x ) // 12 )
if d.day() > days_o... | 2 | 2011-06-06T12:25:22Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 7,020,175 | <pre><code>import time
def add_month(start_time, months):
ret = time.strptime(start_time, '%Y-%m-%d')
t = list(ret)
t[1] += months
if t[1] > 12:
t[0] += 1 + int(months / 12)
t[1] %= 12
return int(time.mktime(tuple(t)))
</code></pre>
| 2 | 2011-08-11T02:28:22Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 8,689,734 | <p>Rework of an earlier answer by user417751. Maybe not so pythonic way, but it takes care of different month lengths and leap years. In this case 31 January 2012 + 1 month = 29 February 2012. </p>
<pre><code>import datetime
import calendar
def add_mths(d, x):
newday = d.day
newmonth = (((d.month - 1) + x) % ... | 0 | 2011-12-31T18:10:56Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 10,750,881 | <p>In this function, n can be positive or negative.</p>
<pre><code>def addmonth(d, n):
n += 1
dd = datetime.date(d.year + n/12, d.month + n%12, 1)-datetime.timedelta(1)
return datetime.date(dd.year, dd.month, min(d.day, dd.day))
</code></pre>
| 0 | 2012-05-25T08:15:20Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 16,792,632 | <p>We probably should use dateutil.relativedelta</p>
<p>however for academic interest I will just add that before I discovered it I was goint to use this:</p>
<p>try:<br>
vexpDt = K.today.replace(K.today.year + (K.today.month+6)//12, (K.today.month+5)%12+1, K.today.day)<br>
except:<br>
&... | -1 | 2013-05-28T12:53:59Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 19,269,236 | <pre><code> def addDay(date, number):
for i in range(number)
#try to add a day
try:
date = date.replace(day = date.day + 1)
#in case it's impossible ex:january 32nd add a month and restart at day 1
except:
#add month part
... | -1 | 2013-10-09T10:17:35Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 19,677,636 | <p>Yet another solution - hope someone will like it:</p>
<pre><code>def add_months(d, months):
return d.replace(year=d.year+months//12).replace(month=(d.month+months)%12)
</code></pre>
<p>This solution doesn't work for days 29,30,31 for all cases, so more robust solution is needed (which is not so nice anymore :)... | 0 | 2013-10-30T08:51:09Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 30,224,798 | <p>From <a href="http://stackoverflow.com/a/1495548/605356">this answer</a>, see <a href="https://github.com/bear/parsedatetime" rel="nofollow">parsedatetime</a>. Code example follows. More details: <a href="https://gist.github.com/johnnyutahh/24f9a48a331fd36a4e97#file-parsedatetime_unittest-py" rel="nofollow">unit tes... | 1 | 2015-05-13T20:40:56Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 32,493,325 | <p>How about this? Not using another library (<code>dateutil</code>) or <code>timedelta</code>?
building on <a href="http://stackoverflow.com/users/60711/vartec">vartec</a>'s answer I did this and I believe it works:</p>
<pre><code>import datetime
today = datetime.date.today()
six_months_from_today = datetime.date(to... | 2 | 2015-09-10T04:44:56Z | [
"python",
"datetime"
] |
How do I calculate the date six months from the current date using the datetime Python module? | 546,321 | <p>I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?</p>
<p>The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a r... | 143 | 2009-02-13T15:16:25Z | 34,831,191 | <p>This is what I do when I need to add months or years and don't want to import more libraries.</p>
<pre><code>import datetime
__author__ = 'Daniel Margarido'
# Check if the int given year is a leap year
# return true if leap year or false otherwise
def is_leap_year(year):
if (year % 4) == 0:
if (year %... | -1 | 2016-01-16T19:30:27Z | [
"python",
"datetime"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.