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 |
|---|---|---|---|---|---|---|---|---|---|
Extract URLs out of email in Python | 1,792,366 | <pre><code>Dear Sam Adams
Thanks for your submission to ourdirectory.com
URL: http://myurlok.us
Please click below link to confirm your submission.
http://www.ourdirectory.com/confirm.aspx?id=1247778154270076
Once we receive your comfirmation, your site will be included for process!
regards,
http://www.ourdirectory.... | 1 | 2009-11-24T19:27:51Z | 1,792,439 | <p>regex:</p>
<pre><code>"http://www.ourdirectory.com/confirm.aspx\?id=[0-9]+$"
</code></pre>
<p>or without regex, parse the email line by line and test if the string contains "http://www.ourdirectory.com/confirm.aspx?id=" and if it does, that's your URL.</p>
<p>Of course, if your input is actually the HTML source i... | 0 | 2009-11-24T19:39:44Z | [
"python",
"email",
"url"
] |
Extract URLs out of email in Python | 1,792,366 | <pre><code>Dear Sam Adams
Thanks for your submission to ourdirectory.com
URL: http://myurlok.us
Please click below link to confirm your submission.
http://www.ourdirectory.com/confirm.aspx?id=1247778154270076
Once we receive your comfirmation, your site will be included for process!
regards,
http://www.ourdirectory.... | 1 | 2009-11-24T19:27:51Z | 1,792,452 | <p>If it's HTML email with hyperlinks you could use the HTMLParse library as a shortcut.</p>
<pre><code>import HTMLParser
class parseLinks(HTMLParser.HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href':
... | 2 | 2009-11-24T19:42:22Z | [
"python",
"email",
"url"
] |
Extract URLs out of email in Python | 1,792,366 | <pre><code>Dear Sam Adams
Thanks for your submission to ourdirectory.com
URL: http://myurlok.us
Please click below link to confirm your submission.
http://www.ourdirectory.com/confirm.aspx?id=1247778154270076
Once we receive your comfirmation, your site will be included for process!
regards,
http://www.ourdirectory.... | 1 | 2009-11-24T19:27:51Z | 1,793,998 | <p>@OP, if your email is always standard, </p>
<pre><code>f=open("emailfile")
for line in f:
if "confirm your submission" in line:
print f.next().strip()
f.close()
</code></pre>
| 1 | 2009-11-25T00:51:10Z | [
"python",
"email",
"url"
] |
Extract URLs out of email in Python | 1,792,366 | <pre><code>Dear Sam Adams
Thanks for your submission to ourdirectory.com
URL: http://myurlok.us
Please click below link to confirm your submission.
http://www.ourdirectory.com/confirm.aspx?id=1247778154270076
Once we receive your comfirmation, your site will be included for process!
regards,
http://www.ourdirectory.... | 1 | 2009-11-24T19:27:51Z | 1,795,616 | <p>This solution works only if the source is not HTML.</p>
<pre><code>def extractURL(self,fileName):
wordsInLine = []
tempWord = []
urlList = []
#open up the file containing the email
file=open(fileName)
for line in file:
#create a list that contains is each word in each line
... | 0 | 2009-11-25T09:12:00Z | [
"python",
"email",
"url"
] |
Extract URLs out of email in Python | 1,792,366 | <pre><code>Dear Sam Adams
Thanks for your submission to ourdirectory.com
URL: http://myurlok.us
Please click below link to confirm your submission.
http://www.ourdirectory.com/confirm.aspx?id=1247778154270076
Once we receive your comfirmation, your site will be included for process!
regards,
http://www.ourdirectory.... | 1 | 2009-11-24T19:27:51Z | 33,380,780 | <p>Check this out. </p>
<p>I wrote a post for the same. The code in this post can extract URLs from an email file, whether it is plain-text or html content-types, or quoted-printable or base 64 or 7bit encodings.</p>
<p><a href="http://stackoverflow.com/questions/33380726/python-how-to-extract-urls-plain-html-quote-p... | 0 | 2015-10-28T00:16:27Z | [
"python",
"email",
"url"
] |
What is the fool proof way to convert some string (utf-8 or else) to a simple ASCII string in python | 1,792,602 | <p>Inside my python scrip, I get some string back from a function which I didn't write. The encoding of it varies. I need to convert it to ascii format. Is there some fool-proof way of doing this? I don't mind replacing the non-ascii chars with blanks or something else...</p>
| 4 | 2009-11-24T20:08:18Z | 1,792,655 | <p>You say "the encoding of it varies". I guess that by "it" you mean a Python 2.x "string", which is really a sequence of bytes.</p>
<p>Answer part one: if you do not know the encoding of that encoded string, then <strong>no</strong>, there is no way at all to do anything meaningful with it*. If you <em>do</em> know ... | 5 | 2009-11-24T20:18:01Z | [
"python",
"utf-8",
"ascii",
"decode"
] |
What is the fool proof way to convert some string (utf-8 or else) to a simple ASCII string in python | 1,792,602 | <p>Inside my python scrip, I get some string back from a function which I didn't write. The encoding of it varies. I need to convert it to ascii format. Is there some fool-proof way of doing this? I don't mind replacing the non-ascii chars with blanks or something else...</p>
| 4 | 2009-11-24T20:08:18Z | 1,792,657 | <p>If all you want to do is preserve ASCII-compatible characters and throw away the rest, then in most encodings that boils down to removing all characters that have the <em>high bit</em> set -- i.e., characters with value over 127. This works because nearly all character sets are extensions of 7-bit ASCII.</p>
<p>If ... | 1 | 2009-11-24T20:18:06Z | [
"python",
"utf-8",
"ascii",
"decode"
] |
What is the fool proof way to convert some string (utf-8 or else) to a simple ASCII string in python | 1,792,602 | <p>Inside my python scrip, I get some string back from a function which I didn't write. The encoding of it varies. I need to convert it to ascii format. Is there some fool-proof way of doing this? I don't mind replacing the non-ascii chars with blanks or something else...</p>
| 4 | 2009-11-24T20:08:18Z | 1,793,458 | <p>I'd try to normalize the string then encode it. What about :</p>
<pre><code>import unicodedata
s = u"éèêà ùçÃ"
print unicodedata.normalize('NFKD',s).encode('ascii','ignore')
</code></pre>
<p><strong>This works only if you have unicode as input.</strong> Therefor, you must know what can of encoding the functi... | 3 | 2009-11-24T22:42:26Z | [
"python",
"utf-8",
"ascii",
"decode"
] |
What is the fool proof way to convert some string (utf-8 or else) to a simple ASCII string in python | 1,792,602 | <p>Inside my python scrip, I get some string back from a function which I didn't write. The encoding of it varies. I need to convert it to ascii format. Is there some fool-proof way of doing this? I don't mind replacing the non-ascii chars with blanks or something else...</p>
| 4 | 2009-11-24T20:08:18Z | 1,793,902 | <p>If you want an ASCII string that unambiguously represents what you have got, <strong>without losing any information</strong>, the answer is simple:</p>
<p>Don't muck about with encode/decode, use the <strong><code>repr()</code></strong> function (Python 2.X) or the <strong><code>ascii()</code></strong> function (Py... | 3 | 2009-11-25T00:19:45Z | [
"python",
"utf-8",
"ascii",
"decode"
] |
What is the fool proof way to convert some string (utf-8 or else) to a simple ASCII string in python | 1,792,602 | <p>Inside my python scrip, I get some string back from a function which I didn't write. The encoding of it varies. I need to convert it to ascii format. Is there some fool-proof way of doing this? I don't mind replacing the non-ascii chars with blanks or something else...</p>
| 4 | 2009-11-24T20:08:18Z | 5,642,048 | <p>What's meant by "foolproof" is that the function does not fail with even the most obscure, impossible input -- meaning, you could feed the function random binary data and IT WOULD NEVER FAIL, NO MATTER WHAT. That's what "foolproof" means.</p>
<p>The function should then proceed do its best to convert to the destin... | 2 | 2011-04-12T21:50:53Z | [
"python",
"utf-8",
"ascii",
"decode"
] |
Updating value in binary file with Python | 1,792,701 | <p>I'm trying to figure out how to update the data in a binary file using Python.</p>
<p>I'm already comfortable reading and writing complete files using "array", but I'm having trouble with in place editing.</p>
<p>Here's what I've tried:</p>
<pre><code>my_file.seek(100)
my_array = array.array('B')
my_array.append... | 2 | 2009-11-24T20:26:11Z | 1,792,725 | <p>According to <a href="http://docs.python.org/library/functions.html#open">the documentation of <code>open()</code></a>, you should open the file in <code>'rb+'</code> mode to avoid the truncating behavior.</p>
| 5 | 2009-11-24T20:29:59Z | [
"python"
] |
Updating value in binary file with Python | 1,792,701 | <p>I'm trying to figure out how to update the data in a binary file using Python.</p>
<p>I'm already comfortable reading and writing complete files using "array", but I'm having trouble with in place editing.</p>
<p>Here's what I've tried:</p>
<pre><code>my_file.seek(100)
my_array = array.array('B')
my_array.append... | 2 | 2009-11-24T20:26:11Z | 1,792,734 | <p>Are you opening the file in <code>'r+b'</code> mode?</p>
| 1 | 2009-11-24T20:30:49Z | [
"python"
] |
How to treat a returned/stored string like a raw string in Python? | 1,792,807 | <p>I am trying to <code>.split()</code> a hex string i.e. <code>'\xff\x00'</code> to get a list i.e. <code>['ff', '00']</code> </p>
<p>This works if I split on a raw string literal i.e. <code>r'\xff\x00'</code> using <code>.split('\\x')</code> but not if I split on a hex string stored in a variable or returned from a ... | 1 | 2009-11-24T20:43:44Z | 1,792,821 | <pre><code>x = '\xff\x00'
y = ['%02x' % ord(c) for c in x]
print y
</code></pre>
<p>Output:</p>
<pre><code>['ff', '00']
</code></pre>
| 6 | 2009-11-24T20:46:42Z | [
"python",
"string",
"escaping"
] |
How to treat a returned/stored string like a raw string in Python? | 1,792,807 | <p>I am trying to <code>.split()</code> a hex string i.e. <code>'\xff\x00'</code> to get a list i.e. <code>['ff', '00']</code> </p>
<p>This works if I split on a raw string literal i.e. <code>r'\xff\x00'</code> using <code>.split('\\x')</code> but not if I split on a hex string stored in a variable or returned from a ... | 1 | 2009-11-24T20:43:44Z | 1,793,184 | <p>Here is a solution in the spirit of the original question:</p>
<pre><code>x = '\xff\x00'
eval("r"+repr(x)).split('\\x')
</code></pre>
<p>It will return the same thing as <code>r'\xff\x00'.split('\\x')</code>: <code>['', 'ff', '00']</code>.</p>
| 0 | 2009-11-24T21:54:21Z | [
"python",
"string",
"escaping"
] |
Weird MySQL Python mod_wsgi Can't connect to MySQL server on 'localhost' (49) problem | 1,792,918 | <p>There have been similar questions on StackOverflow about this, but I haven't found quite the same situation. This is on a OS X Leopard machine using MySQL</p>
<p>Some starting information:</p>
<pre><code>MySQL Server version 5.1.30
Apache/2.2.13 (Unix)
Python 2.5.1
mod_wsgi 3
</code></pre>
<p>mysqladmin also ... | 5 | 2009-11-24T21:05:57Z | 1,793,768 | <p>Not too much out there on this. Just a random guess but try using:</p>
<p>DATABASE_HOST = 'localhost'
instead of 127.0.0.1</p>
<p>and/or try commenting out in your my.ini:</p>
<p>bind-address 127.0.0.1</p>
<p>worth a shot.</p>
| 0 | 2009-11-24T23:45:30Z | [
"python",
"mysql",
"django",
"mod-wsgi",
"mysql-error-2003"
] |
Weird MySQL Python mod_wsgi Can't connect to MySQL server on 'localhost' (49) problem | 1,792,918 | <p>There have been similar questions on StackOverflow about this, but I haven't found quite the same situation. This is on a OS X Leopard machine using MySQL</p>
<p>Some starting information:</p>
<pre><code>MySQL Server version 5.1.30
Apache/2.2.13 (Unix)
Python 2.5.1
mod_wsgi 3
</code></pre>
<p>mysqladmin also ... | 5 | 2009-11-24T21:05:57Z | 2,147,548 | <p>Bit odd that the telnet connection works. Maybe some more ways to trouble shot:</p>
<pre><code>shell> perror 49
OS error code 49: Can't assign requested address
</code></pre>
<p>I would check the localhost interface first, check if it has IPv4 address. Far fetched maybe, but I had troubles ones when I didable... | 0 | 2010-01-27T14:24:40Z | [
"python",
"mysql",
"django",
"mod-wsgi",
"mysql-error-2003"
] |
Weird MySQL Python mod_wsgi Can't connect to MySQL server on 'localhost' (49) problem | 1,792,918 | <p>There have been similar questions on StackOverflow about this, but I haven't found quite the same situation. This is on a OS X Leopard machine using MySQL</p>
<p>Some starting information:</p>
<pre><code>MySQL Server version 5.1.30
Apache/2.2.13 (Unix)
Python 2.5.1
mod_wsgi 3
</code></pre>
<p>mysqladmin also ... | 5 | 2009-11-24T21:05:57Z | 5,552,089 | <p>I came across this error and it was due to an SELinux denial. /usr/bin/httpd didn't have permission to connect to port 3306. I corrected the issue with:</p>
<pre><code>setsebool httpd_can_network_connect_db on
</code></pre>
<p>Seems to work great and should be more secure than just disabling SELinux. As Avinash... | 9 | 2011-04-05T12:50:24Z | [
"python",
"mysql",
"django",
"mod-wsgi",
"mysql-error-2003"
] |
Weird MySQL Python mod_wsgi Can't connect to MySQL server on 'localhost' (49) problem | 1,792,918 | <p>There have been similar questions on StackOverflow about this, but I haven't found quite the same situation. This is on a OS X Leopard machine using MySQL</p>
<p>Some starting information:</p>
<pre><code>MySQL Server version 5.1.30
Apache/2.2.13 (Unix)
Python 2.5.1
mod_wsgi 3
</code></pre>
<p>mysqladmin also ... | 5 | 2009-11-24T21:05:57Z | 12,031,052 | <p>I was getting the exact same error message in Django:</p>
<pre><code>OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (49)")
</code></pre>
<p>To fix it, I had to explicitly set the mysql port to 3306 in the django settings file.</p>
| 1 | 2012-08-20T00:25:45Z | [
"python",
"mysql",
"django",
"mod-wsgi",
"mysql-error-2003"
] |
operation in arrays | 1,793,214 | <p>I have a question, as I perform mathematical operations with an array of lists such as I get the sum of each array list getting a new list with the Valar for the sum of each list in the array.</p>
<p>thanks for any response</p>
| 0 | 2009-11-24T21:58:00Z | 1,793,232 | <p>Try a list comprehension:</p>
<pre><code>>>> list_of_lists = [[1,2],[3,4]]
>>> [sum(li) for li in list_of_lists]
[3, 7]
</code></pre>
| 3 | 2009-11-24T22:00:12Z | [
"python"
] |
operation in arrays | 1,793,214 | <p>I have a question, as I perform mathematical operations with an array of lists such as I get the sum of each array list getting a new list with the Valar for the sum of each list in the array.</p>
<p>thanks for any response</p>
| 0 | 2009-11-24T21:58:00Z | 1,793,289 | <p>If you're going to manipulate lists of numbers to perform some mathematical calculos, you'd better use <a href="http://numpy.scipy.org/" rel="nofollow">Numpy</a>'s arrays:</p>
<pre><code>>>> import numpy
>>> a = numpy.array([1,2,3])
>>> b = numpy.array([2,6])
>>> a_list = [a,b]
&... | 1 | 2009-11-24T22:12:01Z | [
"python"
] |
operation in arrays | 1,793,214 | <p>I have a question, as I perform mathematical operations with an array of lists such as I get the sum of each array list getting a new list with the Valar for the sum of each list in the array.</p>
<p>thanks for any response</p>
| 0 | 2009-11-24T21:58:00Z | 1,793,307 | <p>You can also try <strong>map</strong>ping the lists with the built-in <strong>sum</strong> function.</p>
<pre><code>>>> a = [11, 13, 17, 19, 23]
>>> b = [29, 31, 37, 41, 43]
>>> c = [47, 53, 59, 61, 67]
>>> d = [71, 73, 79, 83, 89]
>>> map(sum, [a, b, c, d])
<map obje... | 2 | 2009-11-24T22:15:03Z | [
"python"
] |
operation in arrays | 1,793,214 | <p>I have a question, as I perform mathematical operations with an array of lists such as I get the sum of each array list getting a new list with the Valar for the sum of each list in the array.</p>
<p>thanks for any response</p>
| 0 | 2009-11-24T21:58:00Z | 1,794,030 | <p>What I understand is that you have a list of list -- in effect, matrix. You want the sum of each row. I agree with other answerers that you should use numpy.</p>
<p>we can create a mulidimensional array:</p>
<pre><code>>>> import numpy
>>> a = numpy.array([[1,2,3], [4,5,6], [7,8,9]])
>>>... | 1 | 2009-11-25T01:01:05Z | [
"python"
] |
Minimal binary diff for similar 1000 byte blocks with static noise? | 1,793,253 | <p>I need a minimal diff for similar 1000 byte blocks. These blocks will have at most 20% of the bits different. The flipped bits will be like radio static -- randomly flipped bits with a uniform distribution over the whole block. Here's my pseudo code using XOR and lzo compression:</p>
<pre><code>minimal_diff=lzo(XOR... | 1 | 2009-11-24T22:03:37Z | 1,793,900 | <p>Have you tried standard compression algorithms already? What performance do you see? You should get fairly good compression ratios on the xor of the old and new blocks, due to the high bias towards 0s.</p>
<p>Other than the standard options, one alternative that springs to mind is encoding each diff as a list of va... | 0 | 2009-11-25T00:19:15Z | [
"python",
"algorithm",
"diff"
] |
Minimal binary diff for similar 1000 byte blocks with static noise? | 1,793,253 | <p>I need a minimal diff for similar 1000 byte blocks. These blocks will have at most 20% of the bits different. The flipped bits will be like radio static -- randomly flipped bits with a uniform distribution over the whole block. Here's my pseudo code using XOR and lzo compression:</p>
<pre><code>minimal_diff=lzo(XOR... | 1 | 2009-11-24T22:03:37Z | 1,793,947 | <p>if its truly random noise then it does not really compress. This means that if you have 8,000 bits (1,000 bytes x 8 bits / byte) and every individual bit has 1/5 (20%) probability of flipping, then you can't encode the changed bits in less than 8,000 x (-4/5 x ln2 4/5 + -1/5 x ln2 1/5) = 8,000 x (-4/5 x -0.322 + -1/... | 3 | 2009-11-25T00:36:21Z | [
"python",
"algorithm",
"diff"
] |
How to join components of a path when you are constructing a URL in Python | 1,793,261 | <p>For example, I want to join a prefix path to resource paths like /js/foo.js.</p>
<p>I want the resulting path to be relative to the root of the server. In the above example if the prefix was "media" I would want the result to be /media/js/foo.js.</p>
<p>os.path.join does this really well, but how it joins paths i... | 44 | 2009-11-24T22:06:07Z | 1,793,282 | <pre><code>>>> import urlparse
>>> urlparse.urljoin('/media/', 'js/foo.js')
'/media/js/foo.js'
</code></pre>
<p>Note that you will get different results from <code>/js/foo.js</code> and <code>js/foo.js</code> because the former begins with a slash which signifies that it already begins at the website... | 67 | 2009-11-24T22:10:12Z | [
"python",
"url"
] |
How to join components of a path when you are constructing a URL in Python | 1,793,261 | <p>For example, I want to join a prefix path to resource paths like /js/foo.js.</p>
<p>I want the resulting path to be relative to the root of the server. In the above example if the prefix was "media" I would want the result to be /media/js/foo.js.</p>
<p>os.path.join does this really well, but how it joins paths i... | 44 | 2009-11-24T22:06:07Z | 1,793,283 | <p>The <strong>basejoin</strong> function in the <strong>urllib</strong> package might be what you're looking for.</p>
<pre><code>basejoin = urljoin(base, url, allow_fragments=True)
Join a base URL and a possibly relative URL to form an absolute
interpretation of the latter.
</code></pre>
<p>Edit: I didn't no... | 6 | 2009-11-24T22:10:23Z | [
"python",
"url"
] |
How to join components of a path when you are constructing a URL in Python | 1,793,261 | <p>For example, I want to join a prefix path to resource paths like /js/foo.js.</p>
<p>I want the resulting path to be relative to the root of the server. In the above example if the prefix was "media" I would want the result to be /media/js/foo.js.</p>
<p>os.path.join does this really well, but how it joins paths i... | 44 | 2009-11-24T22:06:07Z | 1,794,540 | <p>Since, from the comments the OP posted, it seems he <strong>doesn't</strong> want to preserve "absolute URLs" in the join (which is one of the key jobs of <code>urlparse.urljoin</code>;-), I'd recommend avoiding that. <code>os.path.join</code> would also be bad, for exactly the same reason.</p>
<p>So, I'd use some... | 21 | 2009-11-25T04:05:12Z | [
"python",
"url"
] |
How to join components of a path when you are constructing a URL in Python | 1,793,261 | <p>For example, I want to join a prefix path to resource paths like /js/foo.js.</p>
<p>I want the resulting path to be relative to the root of the server. In the above example if the prefix was "media" I would want the result to be /media/js/foo.js.</p>
<p>os.path.join does this really well, but how it joins paths i... | 44 | 2009-11-24T22:06:07Z | 11,326,230 | <p>This does the job nicely:</p>
<pre><code>def urljoin(*args):
"""
Joins given arguments into a url. Trailing but not leading slashes are
stripped for each argument.
"""
return "/".join(map(lambda x: str(x).rstrip('/'), args))
</code></pre>
| 5 | 2012-07-04T09:28:13Z | [
"python",
"url"
] |
How to join components of a path when you are constructing a URL in Python | 1,793,261 | <p>For example, I want to join a prefix path to resource paths like /js/foo.js.</p>
<p>I want the resulting path to be relative to the root of the server. In the above example if the prefix was "media" I would want the result to be /media/js/foo.js.</p>
<p>os.path.join does this really well, but how it joins paths i... | 44 | 2009-11-24T22:06:07Z | 15,279,799 | <p>Like you say, <code>os.path.join</code> joins paths based on the current os. <code>posixpath.join</code> is the underlying module that is used on posix systems:</p>
<pre><code>>>> os.path.join is posixpath.join
True
>>> posixpath.join('/media/', 'js/foo.js')
'/media/js/foo.js'
</code></pre>
<p>So... | 19 | 2013-03-07T19:15:45Z | [
"python",
"url"
] |
How to join components of a path when you are constructing a URL in Python | 1,793,261 | <p>For example, I want to join a prefix path to resource paths like /js/foo.js.</p>
<p>I want the resulting path to be relative to the root of the server. In the above example if the prefix was "media" I would want the result to be /media/js/foo.js.</p>
<p>os.path.join does this really well, but how it joins paths i... | 44 | 2009-11-24T22:06:07Z | 29,197,423 | <p>I know this is a bit more than the OP asked for, However I had the pieces to the following url, and was looking for a simple way to join them:</p>
<pre><code>>>> url = 'https://api.foo.com/orders/bartag?spamStatus=awaiting_spam&page=1&pageSize=250'
</code></pre>
<p>Doing some looking around:</p>
... | 1 | 2015-03-22T17:19:25Z | [
"python",
"url"
] |
django, datetime and timezones | 1,793,386 | <p>I am using: datetime.now() to get the current time in an Event app that lets you create an event that has an end date, then all of the events are displayed in a calendar and if an event is passed due it is displayed in red. </p>
<p>My issue is that I have some users in different timezones than me saying that the e... | 4 | 2009-11-24T22:32:04Z | 1,793,514 | <p>You will need your users to specify their timezone in their user profile. This can then be used to calculate local times correctly.</p>
<p>Check out <a href="http://opensourcehacker.com/2008/06/30/relativity-of-time-shortcomings-in-python-datetime-and-workaround/" rel="nofollow">Relativity of time â shortcomings ... | 4 | 2009-11-24T22:53:36Z | [
"python",
"django"
] |
django, datetime and timezones | 1,793,386 | <p>I am using: datetime.now() to get the current time in an Event app that lets you create an event that has an end date, then all of the events are displayed in a calendar and if an event is passed due it is displayed in red. </p>
<p>My issue is that I have some users in different timezones than me saying that the e... | 4 | 2009-11-24T22:32:04Z | 1,818,630 | <p>Try storing the UTC Datetime instead then make the necessary adjustments based on the user's timezone:</p>
<pre><code>import datetime
def getUtcNow():
return datetime.datetime(*time.gmtime()[:6])
</code></pre>
| 0 | 2009-11-30T09:01:23Z | [
"python",
"django"
] |
django, datetime and timezones | 1,793,386 | <p>I am using: datetime.now() to get the current time in an Event app that lets you create an event that has an end date, then all of the events are displayed in a calendar and if an event is passed due it is displayed in red. </p>
<p>My issue is that I have some users in different timezones than me saying that the e... | 4 | 2009-11-24T22:32:04Z | 4,719,815 | <p>I worked on a library to work with user timezones transparently. You should just use a Field and some timezone utils and you should get everything converted to the user timezone everytime you do a request or a query.</p>
<p>The library is named <a href="https://github.com/FernandoEscher/django-timezones" rel="nofol... | 0 | 2011-01-18T01:56:59Z | [
"python",
"django"
] |
How to use long integers in Python to build a range? | 1,793,426 | <p>I am trying to build a range with an upper bound bigger than limit of integer in Python. I was looking for something like the following:</p>
<pre><code>import sys
start = 100;
step = 100;
limit = sys.maxint + 1;
result = xrange(start, limit, step);
</code></pre>
<p>However, <code>xrange</code> parameters are limit... | 0 | 2009-11-24T22:38:30Z | 1,793,490 | <p><code>xrange</code> is trivial to roll out on your own, so you can do just that:</p>
<pre><code>def xlongrange(start, limit, step):
n = start
while n < limit:
yield n
n += step
</code></pre>
| 9 | 2009-11-24T22:48:26Z | [
"python"
] |
Problems PUTting binary data to Django | 1,793,556 | <p>I am trying to build a RESTful api with Django to share mp3s -- right up front: it's a toy app, never going into production, so it doesn't need to scale or worry (I hope) about copyright devils.
My problem now is that I have a Django view that I want to be the endpoint for HTTP PUT requests. The headers of the PUT ... | 1 | 2009-11-24T23:03:25Z | 1,806,179 | <p>It does appear that the issue is in the dev server's handling of large requests. After deploying to apache with mod_wsgi, this problem goes away. Still lots of open questions for me about RESTful file uploads...</p>
| 0 | 2009-11-26T23:55:29Z | [
"python",
"django",
"http"
] |
Python nested lists and recursion problem | 1,793,603 | <p>I posted this question under an alter yesterday not realising my account was still active after 9 months, sorry for the double post, i've fixed an error in my example pointed out by jellybean and i'll elaborate further on the context of the problem.</p>
<p>I'm trying to process a first order logic formula represent... | 0 | 2009-11-24T23:13:43Z | 1,794,427 | <p>You have:</p>
<pre><code> elif len(form) == 2:
result = self.checkDistributivity(form[1], result)
print result
</code></pre>
<p>Shouldn't that be:</p>
<pre><code> elif len(form) == 2:
result_1 = self.checkDistributivity(form[1], result)
result_2 = self.checkDistributivity(for... | 0 | 2009-11-25T03:24:24Z | [
"python",
"recursion",
"boolean-logic"
] |
Python nested lists and recursion problem | 1,793,603 | <p>I posted this question under an alter yesterday not realising my account was still active after 9 months, sorry for the double post, i've fixed an error in my example pointed out by jellybean and i'll elaborate further on the context of the problem.</p>
<p>I'm trying to process a first order logic formula represent... | 0 | 2009-11-24T23:13:43Z | 1,795,967 | <p>First, two general remarks about your code:</p>
<ul>
<li>Use <code>return True</code> instead of <code>return 1</code>.</li>
<li>Use <code>isinstance(form, list)</code> instead of <code>isinstance(form, type([]))</code>.</li>
</ul>
<p>Second, some other observations:</p>
<ul>
<li>I assume you also want to get rid... | 3 | 2009-11-25T10:20:25Z | [
"python",
"recursion",
"boolean-logic"
] |
Python: Analyzing complex statements during execution | 1,793,660 | <p>I am wondering if there is any way to get some meta information about the interpretation of a python statement during execution.</p>
<p>Let's assume this is a complex statement of some single statements joined with <b>or</b> (A, B, ... are boolean functions)</p>
<pre><code>if A or B and ((C or D and E) or F) or G ... | 3 | 2009-11-24T23:23:01Z | 1,793,714 | <p>As far as I remember, Python does not return True or False per se:</p>
<blockquote>
<p>Important exception: the Boolean
operations <code>or</code> and <code>and</code> always return
one of their operands.</p>
</blockquote>
<p>The Python Standard Library - <a href="http://docs.python.org/library/stdtypes.html... | 1 | 2009-11-24T23:34:07Z | [
"python",
"logic",
"interpreter"
] |
Python: Analyzing complex statements during execution | 1,793,660 | <p>I am wondering if there is any way to get some meta information about the interpretation of a python statement during execution.</p>
<p>Let's assume this is a complex statement of some single statements joined with <b>or</b> (A, B, ... are boolean functions)</p>
<pre><code>if A or B and ((C or D and E) or F) or G ... | 3 | 2009-11-24T23:23:01Z | 1,793,861 | <p>"""I do not want to debug, it's really about knowing which part of this or-chain triggered the statement at runtime.""": you might need to explain what is the difference between "debug" and "knowing which part".</p>
<p>Do you mean that you the observer need to be told at runtime what is going on (why??) so that you... | 0 | 2009-11-25T00:10:10Z | [
"python",
"logic",
"interpreter"
] |
Python: Analyzing complex statements during execution | 1,793,660 | <p>I am wondering if there is any way to get some meta information about the interpretation of a python statement during execution.</p>
<p>Let's assume this is a complex statement of some single statements joined with <b>or</b> (A, B, ... are boolean functions)</p>
<pre><code>if A or B and ((C or D and E) or F) or G ... | 3 | 2009-11-24T23:23:01Z | 1,794,254 | <p>The Python interpreter doesn't give you a way to introspect the evaluation of an expression at runtime. The <code>sys.settrace()</code> function lets you register a callback that is invoked for every line of source code, but that's too coarse-grained for what you want to do.</p>
<p>That said, I've experimented wit... | 0 | 2009-11-25T02:15:36Z | [
"python",
"logic",
"interpreter"
] |
Python: Analyzing complex statements during execution | 1,793,660 | <p>I am wondering if there is any way to get some meta information about the interpretation of a python statement during execution.</p>
<p>Let's assume this is a complex statement of some single statements joined with <b>or</b> (A, B, ... are boolean functions)</p>
<pre><code>if A or B and ((C or D and E) or F) or G ... | 3 | 2009-11-24T23:23:01Z | 1,794,522 | <p>Could you recode your original code:</p>
<pre><code>if A or B and ((C or D and E) or F) or G and H:
</code></pre>
<p>as, say:</p>
<pre><code>e = Evaluator()
if e('A or B and ((C or D and E) or F) or G and H'):
</code></pre>
<p>...? If so, there's hope!-). The Evaluator class, upon <code>__call__</code>, would ... | 3 | 2009-11-25T03:58:54Z | [
"python",
"logic",
"interpreter"
] |
Python: Analyzing complex statements during execution | 1,793,660 | <p>I am wondering if there is any way to get some meta information about the interpretation of a python statement during execution.</p>
<p>Let's assume this is a complex statement of some single statements joined with <b>or</b> (A, B, ... are boolean functions)</p>
<pre><code>if A or B and ((C or D and E) or F) or G ... | 3 | 2009-11-24T23:23:01Z | 1,795,326 | <p>I would just put something like this before the big statement (assuming the statement is in a class):</p>
<pre><code>for i in ("A","B","C","D","E","F","G","H"):
print i,self.__dict__[i]
</code></pre>
| 0 | 2009-11-25T07:54:37Z | [
"python",
"logic",
"interpreter"
] |
Python HTML scraping | 1,793,663 | <p>It's not really scraping, I'm just trying to find the URLs in a web page where the class has a specific value. For example:</p>
<pre><code><a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
</code></pre>
<p>I want to get the href value. Any ideas on how to do this? Maybe regex? Could you post s... | 3 | 2009-11-24T23:23:25Z | 1,793,682 | <p>Aargh, not <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">regex for parsing HTML</a>!</p>
<p>Luckily in Python we have <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> or <a href="http://codespeak.ne... | 9 | 2009-11-24T23:27:31Z | [
"python",
"html",
"regex",
"screen-scraping",
"html-content-extraction"
] |
Python HTML scraping | 1,793,663 | <p>It's not really scraping, I'm just trying to find the URLs in a web page where the class has a specific value. For example:</p>
<pre><code><a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
</code></pre>
<p>I want to get the href value. Any ideas on how to do this? Maybe regex? Could you post s... | 3 | 2009-11-24T23:23:25Z | 1,793,686 | <p>Regex is usally a bad idea, try using <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a></p>
<p>Quick example:</p>
<pre><code>html = #get html
soup = BeautifulSoup(html)
links = soup.findAll('a', attrs={'class': 'myclass'})
for link in links:
#process link
</code></pre>
| 16 | 2009-11-24T23:28:17Z | [
"python",
"html",
"regex",
"screen-scraping",
"html-content-extraction"
] |
Python HTML scraping | 1,793,663 | <p>It's not really scraping, I'm just trying to find the URLs in a web page where the class has a specific value. For example:</p>
<pre><code><a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
</code></pre>
<p>I want to get the href value. Any ideas on how to do this? Maybe regex? Could you post s... | 3 | 2009-11-24T23:23:25Z | 1,793,687 | <p>Regex would be a bad choice. HTML is not a regular language. How about <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>?</p>
| 2 | 2009-11-24T23:28:20Z | [
"python",
"html",
"regex",
"screen-scraping",
"html-content-extraction"
] |
Python HTML scraping | 1,793,663 | <p>It's not really scraping, I'm just trying to find the URLs in a web page where the class has a specific value. For example:</p>
<pre><code><a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
</code></pre>
<p>I want to get the href value. Any ideas on how to do this? Maybe regex? Could you post s... | 3 | 2009-11-24T23:23:25Z | 1,793,696 | <p>read Parsing Html The Cthulhu Way <a href="http://www.codinghorror.com/blog/archives/001311.html" rel="nofollow">http://www.codinghorror.com/blog/archives/001311.html</a></p>
| 0 | 2009-11-24T23:30:07Z | [
"python",
"html",
"regex",
"screen-scraping",
"html-content-extraction"
] |
Python HTML scraping | 1,793,663 | <p>It's not really scraping, I'm just trying to find the URLs in a web page where the class has a specific value. For example:</p>
<pre><code><a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
</code></pre>
<p>I want to get the href value. Any ideas on how to do this? Maybe regex? Could you post s... | 3 | 2009-11-24T23:23:25Z | 1,793,720 | <p>Regex should not be used to parse HTML. See <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags">the first answer to this question</a> for an explanation :)</p>
<p>+1 for BeautifulSoup.</p>
| 1 | 2009-11-24T23:35:00Z | [
"python",
"html",
"regex",
"screen-scraping",
"html-content-extraction"
] |
Python HTML scraping | 1,793,663 | <p>It's not really scraping, I'm just trying to find the URLs in a web page where the class has a specific value. For example:</p>
<pre><code><a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
</code></pre>
<p>I want to get the href value. Any ideas on how to do this? Maybe regex? Could you post s... | 3 | 2009-11-24T23:23:25Z | 1,793,737 | <p>The thing is I know the structure of the HTML page, and I just want to find that specific kind of links (where class="myclass"). BeautifulSoup anyway?</p>
| 0 | 2009-11-24T23:39:08Z | [
"python",
"html",
"regex",
"screen-scraping",
"html-content-extraction"
] |
Python HTML scraping | 1,793,663 | <p>It's not really scraping, I'm just trying to find the URLs in a web page where the class has a specific value. For example:</p>
<pre><code><a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
</code></pre>
<p>I want to get the href value. Any ideas on how to do this? Maybe regex? Could you post s... | 3 | 2009-11-24T23:23:25Z | 1,793,937 | <p>If your task is just this simple, just use string manipulation (without even regex)</p>
<pre><code>f=open("htmlfile")
for line in f:
if "<a class" in line and "myClass" in line and "href" in line:
s = line [ line.index("href") + len('href="') : ]
print s[:s.index('">')]
f.close()
</code></... | 1 | 2009-11-25T00:32:35Z | [
"python",
"html",
"regex",
"screen-scraping",
"html-content-extraction"
] |
How to make uniques in Django Models? And also index a column in Django | 1,793,957 | <p>This is my simple Django database model. It's for a 5-star rating system.</p>
<pre><code>class Rating(models.Model):
content = models.OneToOneField(Content, primary_key=True)
ip = models.CharField(max_length=200, blank=True)
rating = models.IntegerField(default=0)
</code></pre>
<p>As you can see, it i... | 8 | 2009-11-25T00:40:54Z | 1,794,072 | <p>Regarding your first question:
You should look at <a href="http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together" rel="nofollow">unique_together</a>, since this could solve your issue.</p>
<pre><code>class Rating(models.Model):
content = models.OneToOneField(Content, primary_key=True)
ip ... | 11 | 2009-11-25T01:18:17Z | [
"python",
"mysql",
"django",
"django-models"
] |
How to make uniques in Django Models? And also index a column in Django | 1,793,957 | <p>This is my simple Django database model. It's for a 5-star rating system.</p>
<pre><code>class Rating(models.Model):
content = models.OneToOneField(Content, primary_key=True)
ip = models.CharField(max_length=200, blank=True)
rating = models.IntegerField(default=0)
</code></pre>
<p>As you can see, it i... | 8 | 2009-11-25T00:40:54Z | 1,794,228 | <p>About the indexes: you don't need to do anything for <code>content</code>, since it is a primary key, it will be indexed. For <code>ip</code>, just add <code>db_index=True</code> to the <code>CharField</code> constructor call:</p>
<pre><code>ip = models.CharField(max_length=200, blank=True, db_index=True)
</code><... | 5 | 2009-11-25T02:07:55Z | [
"python",
"mysql",
"django",
"django-models"
] |
How to make uniques in Django Models? And also index a column in Django | 1,793,957 | <p>This is my simple Django database model. It's for a 5-star rating system.</p>
<pre><code>class Rating(models.Model):
content = models.OneToOneField(Content, primary_key=True)
ip = models.CharField(max_length=200, blank=True)
rating = models.IntegerField(default=0)
</code></pre>
<p>As you can see, it i... | 8 | 2009-11-25T00:40:54Z | 1,794,461 | <p>BTW, if, as it appears from your terminology, you're using IP addresses as standing for users' identities, <strong>please don't</strong> -- it's a seriously horrible idea. Users coming in through their ISP will get their IPs changed at random times, so they might vote twice; users on a laptop connecting at various ... | 7 | 2009-11-25T03:36:55Z | [
"python",
"mysql",
"django",
"django-models"
] |
Passing SQLite variables in Python | 1,793,970 | <p>I am writing a app in python and utilzing sqlite. I have a list of strings which I would like to add too the database, where each element represents some data which coincides with the column it will be put. </p>
<p>currently I have something like this</p>
<pre><code>cursor.execute("""insert into credit
... | 4 | 2009-11-25T00:44:23Z | 1,793,987 | <p>Use parameters to <code>.execute()</code>:</p>
<pre><code>query = """
INSERT INTO credit
(bank, number, card, int1, value, type, int2)
VALUES
(?, ?, ?, ?, ?, ?, ?)
"""
data = ['Citi', '5567', 'visa', 6000, 9.99, '23', 9000]
cursor.execute(query, data)
</code></pre>
<p>Accordi... | 9 | 2009-11-25T00:47:59Z | [
"python",
"sqlite"
] |
How to use numpy with portaudio to extract bass, mid treble | 1,794,010 | <p>As in this example <a href="http://stackoverflow.com/questions/259451/how-to-extract-frequency-information-from-an-input-audio-stream-using-portaudio">http://stackoverflow.com/questions/259451/how-to-extract-frequency-information-from-an-input-audio-stream-using-portaudio</a> I'm curious about portaudio and numpy.... | 1 | 2009-11-25T00:54:49Z | 1,794,432 | <p>The <a href="https://svn.enthought.com/enthought/browser/Chaco/trunk/examples/advanced/spectrum.py" rel="nofollow">Fourier Transform</a>, mentioned in the selected answer to the SO question you point to, gives you the "spectrum" -- a large collection of values giving the sound intensity in each of various ranges/sli... | 1 | 2009-11-25T03:26:19Z | [
"python",
"audio",
"numpy",
"fft",
"portaudio"
] |
How to use numpy with portaudio to extract bass, mid treble | 1,794,010 | <p>As in this example <a href="http://stackoverflow.com/questions/259451/how-to-extract-frequency-information-from-an-input-audio-stream-using-portaudio">http://stackoverflow.com/questions/259451/how-to-extract-frequency-information-from-an-input-audio-stream-using-portaudio</a> I'm curious about portaudio and numpy.... | 1 | 2009-11-25T00:54:49Z | 5,673,442 | <p>Actually, you would not use a Fourier transform to do this.</p>
<p>Splitting any audio signal in bass, mid and treble is usually done using filters. A <a href="http://en.wikipedia.org/wiki/Audio_filter" rel="nofollow">filter</a> is a signal processing device that attenuates certain frequency ranges. Filters can be ... | 1 | 2011-04-15T07:08:39Z | [
"python",
"audio",
"numpy",
"fft",
"portaudio"
] |
Python on Rails? | 1,794,179 | <p>Would it be possible to translate the Ruby on Rails code base to Python?</p>
<p>I think many people like Python more than Ruby, but find Ruby on Rails features better (as a whole) than the ones in Python web frameworks.</p>
<p>So that, would it be possible? Or does Ruby on Rails utilize language-specific features ... | 16 | 2009-11-25T01:56:10Z | 1,794,205 | <p>I think one of the things that people like about RoR is the domain-specific language (DSL) style of programming. This is something that Ruby is much better at than Python.</p>
| 13 | 2009-11-25T02:02:14Z | [
"python",
"ruby-on-rails",
"metaprogramming",
"code-translation"
] |
Python on Rails? | 1,794,179 | <p>Would it be possible to translate the Ruby on Rails code base to Python?</p>
<p>I think many people like Python more than Ruby, but find Ruby on Rails features better (as a whole) than the ones in Python web frameworks.</p>
<p>So that, would it be possible? Or does Ruby on Rails utilize language-specific features ... | 16 | 2009-11-25T01:56:10Z | 1,794,250 | <p>Many of the methodology used in Rails has been translated into Django. Have you tried it?</p>
<p><a href="http://www.djangoproject.com/">http://www.djangoproject.com/</a></p>
| 16 | 2009-11-25T02:14:22Z | [
"python",
"ruby-on-rails",
"metaprogramming",
"code-translation"
] |
Python on Rails? | 1,794,179 | <p>Would it be possible to translate the Ruby on Rails code base to Python?</p>
<p>I think many people like Python more than Ruby, but find Ruby on Rails features better (as a whole) than the ones in Python web frameworks.</p>
<p>So that, would it be possible? Or does Ruby on Rails utilize language-specific features ... | 16 | 2009-11-25T01:56:10Z | 1,794,252 | <p>I know that Rails does not necessarily = MVC per se, but I think a lot of what makes Rails productive is that it enforces (well, strongly encourages) MVC development, so you might find something similar if you look for Python MVC, such as this previous post here on Stack: <a href="http://stackoverflow.com/questions/... | 2 | 2009-11-25T02:14:52Z | [
"python",
"ruby-on-rails",
"metaprogramming",
"code-translation"
] |
Python on Rails? | 1,794,179 | <p>Would it be possible to translate the Ruby on Rails code base to Python?</p>
<p>I think many people like Python more than Ruby, but find Ruby on Rails features better (as a whole) than the ones in Python web frameworks.</p>
<p>So that, would it be possible? Or does Ruby on Rails utilize language-specific features ... | 16 | 2009-11-25T01:56:10Z | 1,794,268 | <p><a href="http://blog.ianbicking.org/what-really-makes-rails-work.html">This is a great blog post</a>. Rails developers chose a framework, and coding in Ruby is the afterthought. </p>
<p>Python developers chose the language for the language, not the framework. On the other hand, that made a lot lower bar to entry... | 11 | 2009-11-25T02:21:22Z | [
"python",
"ruby-on-rails",
"metaprogramming",
"code-translation"
] |
Accessing xrange internal structure | 1,794,346 | <p>I'm trying to use ctypes to extract data from internal python structures. Namely, I'm trying to read the 4 fields in an xrange:</p>
<pre><code>typedef struct {
PyObject_HEAD
long start;
long step;
long len;
} rangeobject;
</code></pre>
<p>Is there any standard way of getting at such field... | 4 | 2009-11-25T02:53:00Z | 1,794,387 | <p>The ctypes module isn't meant for accessing Python internals. ctypes lets you deal with C libraries in C terms, but coding in Python.</p>
<p>You probably want a C extension, which in many ways is the opposite of ctypes. With a C extension, you deal with Python code in Python terms, but code in C.</p>
<p>UPDATED:... | 0 | 2009-11-25T03:07:16Z | [
"python",
"ctypes",
"cpython",
"xrange"
] |
Accessing xrange internal structure | 1,794,346 | <p>I'm trying to use ctypes to extract data from internal python structures. Namely, I'm trying to read the 4 fields in an xrange:</p>
<pre><code>typedef struct {
PyObject_HEAD
long start;
long step;
long len;
} rangeobject;
</code></pre>
<p>Is there any standard way of getting at such field... | 4 | 2009-11-25T02:53:00Z | 1,795,498 | <p>You can access data you need without <code>ctypes</code>:</p>
<pre><code>>>> obj = xrange(1,11,2)
>>> obj.__reduce__()[1]
(1, 11, 2)
>>> len(obj)
5
</code></pre>
<p>Note, that <code>__reduce__()</code> method is exactly for serialization. Read <a href="http://docs.python.org/library/pick... | 5 | 2009-11-25T08:47:17Z | [
"python",
"ctypes",
"cpython",
"xrange"
] |
Python : fork and exec a process to run on different terminal | 1,794,536 | <p>I am trying to simulate a a network consisting of several clients and servers. I have written node.py which contains client-server code. I want to run multiple instances node.py. But I don't want to do it manually so I have written another file spawn.py which spawns multiple instances of node.py using fork and exec.... | 1 | 2009-11-25T04:04:57Z | 1,794,673 | <pre><code>shell #1:
for p in 1 2 3 4 5
do
python node.py > $p.log 2>&1
done
shell #2:
tail -F 1.log
shell #3:
tail -F 2.log
etc...
</code></pre>
| 0 | 2009-11-25T04:39:55Z | [
"python",
"process"
] |
Python : fork and exec a process to run on different terminal | 1,794,536 | <p>I am trying to simulate a a network consisting of several clients and servers. I have written node.py which contains client-server code. I want to run multiple instances node.py. But I don't want to do it manually so I have written another file spawn.py which spawns multiple instances of node.py using fork and exec.... | 1 | 2009-11-25T04:04:57Z | 1,794,679 | <p>If you want "real" (pseudo-;-) terminals, and are using X11 (almost every GUI interface on Linux does;-), you could exec <code>xterm -e python node.py</code> instead of just <code>python node.py</code> -- substitute for <code>xterm</code> whatever terminal emulator program you prefer, of course (I'm sure they all ha... | 1 | 2009-11-25T04:42:39Z | [
"python",
"process"
] |
How can I read the memory of another process in Python in Windows? | 1,794,579 | <p>I'm trying to write a Python script that reads a series of memory locations of a particular process.</p>
<p>How can I do this in Python?</p>
<p>I'll be using Windows if it matters. I have the processes PID that I'm attempting to read/edit.</p>
<p>Am I going to have to revert to calling ReadProcessMemory() and us... | 8 | 2009-11-25T04:15:40Z | 1,794,686 | <p>I didn't see anything in the standard python libraries but I found an example using ctypes like you suggested on another site:</p>
<pre><code>from ctypes import *
from ctypes.wintypes import *
OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kerne... | 10 | 2009-11-25T04:44:59Z | [
"python"
] |
How can I read the memory of another process in Python in Windows? | 1,794,579 | <p>I'm trying to write a Python script that reads a series of memory locations of a particular process.</p>
<p>How can I do this in Python?</p>
<p>I'll be using Windows if it matters. I have the processes PID that I'm attempting to read/edit.</p>
<p>Am I going to have to revert to calling ReadProcessMemory() and us... | 8 | 2009-11-25T04:15:40Z | 1,794,691 | <p>Yes, <code>ctypes</code> (or <a href="http://python.net/crew/skippy/win32/Downloads.html" rel="nofollow"><code>win32all</code></a>) and <code>ReadProcessMemory</code> are exactly the way to go. Were you looking for something extra/different? What, in particular?</p>
| 0 | 2009-11-25T04:45:20Z | [
"python"
] |
How can I read the memory of another process in Python in Windows? | 1,794,579 | <p>I'm trying to write a Python script that reads a series of memory locations of a particular process.</p>
<p>How can I do this in Python?</p>
<p>I'll be using Windows if it matters. I have the processes PID that I'm attempting to read/edit.</p>
<p>Am I going to have to revert to calling ReadProcessMemory() and us... | 8 | 2009-11-25T04:15:40Z | 1,794,927 | <p>See <a href="http://www.windowsreference.com/windows-xp/dos-commands-and-equivalent-linux-commands/" rel="nofollow">http://www.windowsreference.com/windows-xp/dos-commands-and-equivalent-linux-commands/</a></p>
<p>You can use tasklist.exe to list processes, then scrape the results. Then use taskkill.exe (or tstskil... | -1 | 2009-11-25T05:50:34Z | [
"python"
] |
Is there a cross-platform way to open a file browser in Python? | 1,795,111 | <p>I'm thinking something along the lines of the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module, but for file browsers. In Windows I'd like to open explorer, in GNOME on Linux I want to open nautilus, Konqueror on KDE, etc. I'd prefer not to kludge it up if I can avoid it. ;-)</p>
| 10 | 2009-11-25T06:56:36Z | 1,795,258 | <p>This is a complete stab in the dark, but take a look at <a href="http://www.wxpython.org/" rel="nofollow">wxPython</a> which provides Python bindings to the underlying <a href="http://wxwidgets.org/" rel="nofollow">wxWidgets</a> library. It has been a long time since I last looked at it, but there might be something... | 0 | 2009-11-25T07:36:46Z | [
"python",
"cross-platform",
"operating-system"
] |
Is there a cross-platform way to open a file browser in Python? | 1,795,111 | <p>I'm thinking something along the lines of the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module, but for file browsers. In Windows I'd like to open explorer, in GNOME on Linux I want to open nautilus, Konqueror on KDE, etc. I'd prefer not to kludge it up if I can avoid it. ;-)</p>
| 10 | 2009-11-25T06:56:36Z | 1,795,293 | <p>I don't know if a ready-to-use module exists, but if there is, it should be on the Activestate's python cookbok (<a href="http://code.activestate.com/recipes/langs/python/" rel="nofollow">http://code.activestate.com/recipes/langs/python/</a>)</p>
<p>Also, at least in gnome and on mac os, you can execute "gnome-open... | 0 | 2009-11-25T07:45:50Z | [
"python",
"cross-platform",
"operating-system"
] |
Is there a cross-platform way to open a file browser in Python? | 1,795,111 | <p>I'm thinking something along the lines of the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module, but for file browsers. In Windows I'd like to open explorer, in GNOME on Linux I want to open nautilus, Konqueror on KDE, etc. I'd prefer not to kludge it up if I can avoid it. ;-)</p>
| 10 | 2009-11-25T06:56:36Z | 1,795,849 | <blockquote>
<p>I'd prefer not to kludge it up if I can avoid it.</p>
</blockquote>
<p>Weeell I think you are going to need a little bit of platform-sniffing kludge, but hopefully not as much as the ghastly command-sniffing <code>webbrowser</code> module. Here's a first stab at it:</p>
<pre><code>if sys.platform=='... | 15 | 2009-11-25T09:56:24Z | [
"python",
"cross-platform",
"operating-system"
] |
Is there a cross-platform way to open a file browser in Python? | 1,795,111 | <p>I'm thinking something along the lines of the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module, but for file browsers. In Windows I'd like to open explorer, in GNOME on Linux I want to open nautilus, Konqueror on KDE, etc. I'd prefer not to kludge it up if I can avoid it. ;-)</p>
| 10 | 2009-11-25T06:56:36Z | 1,796,726 | <p>You can do this with the Tkinter library built into Python. Try the following:</p>
<pre><code>import Tkinter
from tkFileDialog import askopenfilename
root = Tkinter.Tk()
root.withdraw() # hide the main GUI window for our example
filename = askopenfilename()
</code></pre>
<p>If the user doesn't pick a file, the fil... | 0 | 2009-11-25T12:51:31Z | [
"python",
"cross-platform",
"operating-system"
] |
how to simulate the concept of object identity in Haskell | 1,795,186 | <p>I am considering the design of an interpreter for Python like object oriented language in Haskell. One particular problem I am facing is related to the concept of object identity. If we consider Python's <code>id(object)</code> function, the definition suggests that it returns the "identity" of an object. This is an... | 0 | 2009-11-25T07:16:42Z | 1,795,338 | <p>I assume that your interpreter will work within the <code>State</code> monad. Probably the state will consist of a collection of live objects and whatnot. What you can do, is keep track of a list of available (non-used) <code>id</code>s (represented as <code>Int</code>s) and annotate every <code>Object</code> with a... | 4 | 2009-11-25T07:57:29Z | [
"python",
"haskell",
"interpreter"
] |
how to simulate the concept of object identity in Haskell | 1,795,186 | <p>I am considering the design of an interpreter for Python like object oriented language in Haskell. One particular problem I am facing is related to the concept of object identity. If we consider Python's <code>id(object)</code> function, the definition suggests that it returns the "identity" of an object. This is an... | 0 | 2009-11-25T07:16:42Z | 1,795,342 | <p>The answer to this question depends on how you are going to implement these objects you want to get id's from. How is it going to look if two variables contain the same object? You basically need to store references to "mutable" objects in the variables, the question is how exactly you do this. If you would just ass... | 3 | 2009-11-25T07:58:00Z | [
"python",
"haskell",
"interpreter"
] |
python code to convert mail from pst to eml format | 1,795,202 | <p>Is there any python code to convert outlook pst mails to eml format. Please also suggest for any such code in some other language. Thank you. </p>
| 0 | 2009-11-25T07:23:20Z | 1,795,706 | <pre><code>import subprocess
def convert_pst_to_mbox(pstfilename, outputfolder):
subprocess.call(['readpst', '-o', outputfolder, '-r', pstfilename])
</code></pre>
<p>Of course, you must install <a href="http://www.five-ten-sg.com/libpst/" rel="nofollow">libpst utilities</a> for that to work.</p>
| 1 | 2009-11-25T09:27:29Z | [
"python",
"eml",
"pst"
] |
converting basic HTML to RML (Reportlab Markup Language) | 1,795,349 | <p>Is there any Python library or some sample code which demonstrates how to convert basic HTML into RML (Reportlab Markup Language www.reportlab.org)? I can think of using a regular HTML parser and adding some home grown code to generate the RML, but I guess there will be a lot of cases to handle in such a conversion.... | 2 | 2009-11-25T07:59:24Z | 1,842,295 | <p>You shouldn't have much trouble doing this. Aside from some differences in element names, it's pretty straightforward: just ignore any HTML elements that can't be easily converted/you don't care about converting to RML and do the rest. I'm sure the ReportLab folks would be glad if you contributed even a basic HTM... | 1 | 2009-12-03T19:26:14Z | [
"python",
"reportlab"
] |
converting basic HTML to RML (Reportlab Markup Language) | 1,795,349 | <p>Is there any Python library or some sample code which demonstrates how to convert basic HTML into RML (Reportlab Markup Language www.reportlab.org)? I can think of using a regular HTML parser and adding some home grown code to generate the RML, but I guess there will be a lot of cases to handle in such a conversion.... | 2 | 2009-11-25T07:59:24Z | 25,283,895 | <p>simple converter ( <a href="http://linuxminded.xs4all.nl/dpc/html2rml/" rel="nofollow">Convert HTML to RML </a></p>
| 0 | 2014-08-13T10:32:25Z | [
"python",
"reportlab"
] |
can NLTK/pyNLTK work "per language" (i.e. non-english), and how? | 1,795,410 | <p>How can I tell NLTK to treat the text in a particular language?</p>
<p>Once in a while I write a specialized NLP routine to do POS tagging, tokenizing and etc. on a non-english (but still hindo-European) text domain.</p>
<p>This question seem to address only different corpora, not the change in code/settings:
<a h... | 8 | 2009-11-25T08:17:32Z | 1,900,596 | <p>I'm not sure what you're referring to as the changes in code/settings. NLTK mostly relies on machine learning and the "settings" are usually extracted from the training data.</p>
<p>When it comes to POS tagging the results and tagging will be dependant on the tagger you use/train. Should you train your own you'll o... | 6 | 2009-12-14T12:15:51Z | [
"python",
"nlp",
"nltk"
] |
Are there any good summarizers for a web-page? | 1,795,520 | <p>Suppose I give you a URL...can you analyze the words and spit out the "keywords" of that page?
(besides using meta-tags)</p>
<p>Are there good open-source summarizers out there? (preferably Python)</p>
| 1 | 2009-11-25T08:52:31Z | 1,795,537 | <p>A simple text summarizer: <a href="http://pythonwise.blogspot.com/2008/01/simple-text-summarizer.html" rel="nofollow">http://pythonwise.blogspot.com/2008/01/simple-text-summarizer.html</a></p>
<p>Algorithm:</p>
<pre><code>1. For each word, calculate it's frequency in the document
2. For each sentence in the docume... | 2 | 2009-11-25T08:55:32Z | [
"python",
"text"
] |
Are there any good summarizers for a web-page? | 1,795,520 | <p>Suppose I give you a URL...can you analyze the words and spit out the "keywords" of that page?
(besides using meta-tags)</p>
<p>Are there good open-source summarizers out there? (preferably Python)</p>
| 1 | 2009-11-25T08:52:31Z | 1,800,130 | <p>Frequency counts will get you some of the way but Natural Language Processing will provide better results as it uses linguistic techniques to provide more accuracy.</p>
<p>Topia.termextract uses a Parts-Of-Speech (POS) tagging algorithm and is available from PyPi <a href="http://pypi.python.org/pypi/topia.termextra... | 1 | 2009-11-25T21:37:10Z | [
"python",
"text"
] |
In Google App Engine, what happens when I change the Class related to a persisted object? | 1,795,668 | <p>My model class looks as follows:</p>
<pre><code>from google.appengine.ext import db
class SnapShotBase(db.Model):
'''
The base class from which all entity snapshots will inherit.
'''
version = db.IntegerProperty()
def __init__(self):
pass
</code></pre>
<p>Imagine I already have persist... | 0 | 2009-11-25T09:20:10Z | 1,796,136 | <p>Model instances aren't stored using standard serialization such as Pickle. The properties (such as 'version' in your example) are encoded and stored as a Protocol Buffer, and when you load an entity from the datastore, the Protocol Buffer is decoded and used to build a new Model instance.</p>
<p>As a result, you ca... | 3 | 2009-11-25T10:51:53Z | [
"python",
"google-app-engine"
] |
Regular Expression to match a string only when certain characters don't exist | 1,796,053 | <p>So, here's my question:</p>
<p>I have a crawler that goes and downloads web pages and strips those of URLs (for future crawling). My crawler operates from a whitelist of URLs which are specified in regular expressions, so they're along the lines of:</p>
<pre>(http://www.example.com/subdirectory/)(.*?)</pre>
<p>.... | 0 | 2009-11-25T10:34:21Z | 1,796,081 | <p>You will need to crawl the pages upto <code>?param=1&param=5</code> </p>
<p>because normally param=1 and param=2 could give you completely different web page. </p>
<p>pick up one the wordpress website to confirm that.</p>
<p>Try like this one, It will try to match just before # char</p>
<pre><code>(http://ww... | 0 | 2009-11-25T10:42:09Z | [
"python",
"regex",
"url"
] |
Regular Expression to match a string only when certain characters don't exist | 1,796,053 | <p>So, here's my question:</p>
<p>I have a crawler that goes and downloads web pages and strips those of URLs (for future crawling). My crawler operates from a whitelist of URLs which are specified in regular expressions, so they're along the lines of:</p>
<pre>(http://www.example.com/subdirectory/)(.*?)</pre>
<p>.... | 0 | 2009-11-25T10:34:21Z | 1,796,084 | <pre><code>(http://www.example.com/)([^=?#]*?)
</code></pre>
<p>Should do it, this will allow any URL that does not contain the characters you don't want. </p>
<p>It might however be a little bit hard to extend this approach. A better option is to have the system work two-tiered, i.e. one set of matching regex, and o... | 1 | 2009-11-25T10:42:21Z | [
"python",
"regex",
"url"
] |
Regular Expression to match a string only when certain characters don't exist | 1,796,053 | <p>So, here's my question:</p>
<p>I have a crawler that goes and downloads web pages and strips those of URLs (for future crawling). My crawler operates from a whitelist of URLs which are specified in regular expressions, so they're along the lines of:</p>
<pre>(http://www.example.com/subdirectory/)(.*?)</pre>
<p>.... | 0 | 2009-11-25T10:34:21Z | 1,796,089 | <p>This expression should be what you're looking for:</p>
<pre><code>(http://www.example.com/subdirectory/)([^=?#]*)$
</code></pre>
<p>[^=\?#] Will match anything except for the characters you specified.</p>
<p>For Example:</p>
<ul>
<li><a href="http://www.example.com/subdirectory/" rel="nofollow">http://www.exampl... | 0 | 2009-11-25T10:43:05Z | [
"python",
"regex",
"url"
] |
Regular Expression to match a string only when certain characters don't exist | 1,796,053 | <p>So, here's my question:</p>
<p>I have a crawler that goes and downloads web pages and strips those of URLs (for future crawling). My crawler operates from a whitelist of URLs which are specified in regular expressions, so they're along the lines of:</p>
<pre>(http://www.example.com/subdirectory/)(.*?)</pre>
<p>.... | 0 | 2009-11-25T10:34:21Z | 1,796,090 | <p>I'm not sure of what you want. If you wan't to match anything that doesn't containst any ?, #, and = then the regex is</p>
<pre><code>([^=?#]*)
</code></pre>
| 0 | 2009-11-25T10:43:27Z | [
"python",
"regex",
"url"
] |
Regular Expression to match a string only when certain characters don't exist | 1,796,053 | <p>So, here's my question:</p>
<p>I have a crawler that goes and downloads web pages and strips those of URLs (for future crawling). My crawler operates from a whitelist of URLs which are specified in regular expressions, so they're along the lines of:</p>
<pre>(http://www.example.com/subdirectory/)(.*?)</pre>
<p>.... | 0 | 2009-11-25T10:34:21Z | 1,800,043 | <p>As an alternative there's always the urlparse module which is designed for parsing urls.</p>
<pre><code>from urlparse import urlparse
urls= [
'http://www.example.com/subdirectory/',
'http://www.example.com/subdirectory/index.php',
'http://www.example.com/subdirectory/somepage?param=1&param=5#print'... | 0 | 2009-11-25T21:22:31Z | [
"python",
"regex",
"url"
] |
werkzeug mapping urls to views (via endpoint) | 1,796,063 | <p>Starting using werkzeug, i try to map urls (from a file urls.py) to views (from a folder views and then in different files to manage differents kinds of view), my folder organisation looks like that : </p>
<pre><code>myapp/
application.py
urls.py
views/
__init__.py
common.py
places.py
... | 2 | 2009-11-25T10:37:24Z | 1,796,295 | <p>Here is a simplified example:</p>
<pre><code>import views
def app(environ, start_response):
urls = url_map.bind_to_environ(environ)
request = Request(environ)
endpoint, params = urls.match()
names = endpoint.split('.')
view = views
for name in names:
if not hasattr(view, name):
... | 3 | 2009-11-25T11:19:06Z | [
"python",
"werkzeug"
] |
werkzeug mapping urls to views (via endpoint) | 1,796,063 | <p>Starting using werkzeug, i try to map urls (from a file urls.py) to views (from a folder views and then in different files to manage differents kinds of view), my folder organisation looks like that : </p>
<pre><code>myapp/
application.py
urls.py
views/
__init__.py
common.py
places.py
... | 2 | 2009-11-25T10:37:24Z | 1,798,003 | <pre><code>import letters # our views module
url_map = Map([
Rule('/letters', endpoint=letters.index),
Rule('/letters/<int:item_id>', endpoint=letters.item),
Rule('/letters/<string:section_slug>', endpoint=letters.index),
Rule('/letters/<string:section_slug>/<int:item_id>',
... | 3 | 2009-11-25T16:09:05Z | [
"python",
"werkzeug"
] |
werkzeug mapping urls to views (via endpoint) | 1,796,063 | <p>Starting using werkzeug, i try to map urls (from a file urls.py) to views (from a folder views and then in different files to manage differents kinds of view), my folder organisation looks like that : </p>
<pre><code>myapp/
application.py
urls.py
views/
__init__.py
common.py
places.py
... | 2 | 2009-11-25T10:37:24Z | 11,110,981 | <p>I'm not sure if it is preferred way to tackle this problem (I haven't found any similar example in werkzeug repo and I'm still only playing with this lib) but it is also possible to simply subclass Rule:</p>
<pre><code>class CoolRule(Rule):
def __init__(self, view, *args, **kwargs):
self.view = view
... | 1 | 2012-06-19T23:36:18Z | [
"python",
"werkzeug"
] |
Point Django at different Python version | 1,796,105 | <p>Django application requires a later version of Python. I just installed it to <code>2.5</code> (from <code>2.4</code>) and now when I do a <code>python</code> at the command line, it says <code>2.5.2</code>. </p>
<p>Having said that, Django still says <code>Python Version: 2.4.3</code>. </p>
<p>How do I correct th... | 3 | 2009-11-25T10:46:36Z | 1,796,228 | <p>django uses /usr/bin/env python IIRC.<br>
So, wherever your path points (which python) is the python that gets used. dependent upon your system, you can point your path to the python that you want to use. However, on some OS (CentOS for example) this is a bad idea.</p>
| 0 | 2009-11-25T11:08:54Z | [
"python",
"django",
"path"
] |
Point Django at different Python version | 1,796,105 | <p>Django application requires a later version of Python. I just installed it to <code>2.5</code> (from <code>2.4</code>) and now when I do a <code>python</code> at the command line, it says <code>2.5.2</code>. </p>
<p>Having said that, Django still says <code>Python Version: 2.4.3</code>. </p>
<p>How do I correct th... | 3 | 2009-11-25T10:46:36Z | 1,796,381 | <p>How are you running Django? If it's via the development server, you can explicitly choose the version of Python you're using - <code>python2.5 manage.py runserver</code>.</p>
<p>However, if you're using <code>mod_python</code> or <code>mod_wsgi</code> these are fixed to the version of Python that was used when they... | 3 | 2009-11-25T11:34:19Z | [
"python",
"django",
"path"
] |
Point Django at different Python version | 1,796,105 | <p>Django application requires a later version of Python. I just installed it to <code>2.5</code> (from <code>2.4</code>) and now when I do a <code>python</code> at the command line, it says <code>2.5.2</code>. </p>
<p>Having said that, Django still says <code>Python Version: 2.4.3</code>. </p>
<p>How do I correct th... | 3 | 2009-11-25T10:46:36Z | 1,796,427 | <p>You have it backwards.</p>
<p>Django is added to Python's environment.</p>
<p>When you install a new Python, you must reinstall everything -- including Django -- for the new Python.</p>
<p>Once you have the new Django in the new Python, your <code>PATH</code> settings determine which Python you're using. </p>
<... | 5 | 2009-11-25T11:44:52Z | [
"python",
"django",
"path"
] |
Check whether a connection exists to a remote host using paramiko | 1,796,106 | <p>I'm using single object of <code>paramiko.SSHClient()</code> for executing a command on a remote machine. When I use <code>ssh.exec_command(cmd)</code>, and the connection to remote host is lost, <code>ssh.exec_command</code> hangs up.</p>
<p>Is there a way to check for connection existence before <code>ssh.exec_co... | 2 | 2009-11-25T10:46:44Z | 1,799,779 | <p>If you have a long running SSH connection, you may want to use the <a href="http://www.openbsd.org/cgi-bin/man.cgi?query=ssh%5Fconfig" rel="nofollow">Keep Alive</a> parameter via <a href="http://www.lag.net/paramiko/docs/paramiko.Transport-class.html#set%5Fkeepalive" rel="nofollow">Transport.set_keepalive</a>.</p>
| 2 | 2009-11-25T20:35:36Z | [
"python",
"ssh",
"paramiko"
] |
Check whether a connection exists to a remote host using paramiko | 1,796,106 | <p>I'm using single object of <code>paramiko.SSHClient()</code> for executing a command on a remote machine. When I use <code>ssh.exec_command(cmd)</code>, and the connection to remote host is lost, <code>ssh.exec_command</code> hangs up.</p>
<p>Is there a way to check for connection existence before <code>ssh.exec_co... | 2 | 2009-11-25T10:46:44Z | 1,843,448 | <p>As an alternate possibility, maybe <a href="http://codespeak.net/execnet/" rel="nofollow">execnet</a> would work. It wraps the command line ssh command instead, so it's definitely not the paramiko approach... just a though.</p>
| 0 | 2009-12-03T22:28:05Z | [
"python",
"ssh",
"paramiko"
] |
When I send a post request in python...how do I | 1,796,109 | <p>Have a "check"?</p>
<p>For example...
I would have a dictionary with the parameters to sent to the POST.</p>
<pre><code>params = {'text':'how are you?', 'subject':'hi'}
</code></pre>
<p>then I would have </p>
<pre><code>opener.open('theurl',urllib.urlencode(params))
</code></pre>
<p>The question is...those para... | 1 | 2009-11-25T10:47:11Z | 1,796,130 | <p>Radio buttons has values too</p>
<pre><code><input type="radio" name="music" value="Rock" checked="checked"> Rock<br>
<input type="radio" name="music" value="Pop"> Pop<br>
<input type="radio" name="music" value="Metal"> Metal<br>
</code></pre>
<p>for that case {"music":"Rock"} i... | 2 | 2009-11-25T10:50:56Z | [
"python",
"http",
"post",
"send"
] |
How can I get a list of all classes within current module in Python? | 1,796,180 | <p>I've seen plenty of examples of people extracting all of the classes from a module, usually something like:</p>
<pre><code># foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
</code></pre>
<p>Awesome.</p>
<p>Bu... | 170 | 2009-11-25T10:59:46Z | 1,796,234 | <p>I don't know if there's a 'proper' way to do it, but your snippet is on the right track: just add <code>import foo</code> to foo.py, do <code>inspect.getmembers(foo)</code>, and it should work fine.</p>
| 7 | 2009-11-25T11:09:18Z | [
"python",
"reflection",
"inspect"
] |
How can I get a list of all classes within current module in Python? | 1,796,180 | <p>I've seen plenty of examples of people extracting all of the classes from a module, usually something like:</p>
<pre><code># foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
</code></pre>
<p>Awesome.</p>
<p>Bu... | 170 | 2009-11-25T10:59:46Z | 1,796,247 | <p>Try this:</p>
<pre><code>import sys
current_module = sys.modules[__name__]
</code></pre>
<p>In your context:</p>
<pre><code>import sys, inspect
def print_classes():
for name, obj in inspect.getmembers(sys.modules[__name__]):
if inspect.isclass(obj):
print(obj)
</code></pre>
<p>And even be... | 215 | 2009-11-25T11:12:22Z | [
"python",
"reflection",
"inspect"
] |
How can I get a list of all classes within current module in Python? | 1,796,180 | <p>I've seen plenty of examples of people extracting all of the classes from a module, usually something like:</p>
<pre><code># foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
</code></pre>
<p>Awesome.</p>
<p>Bu... | 170 | 2009-11-25T10:59:46Z | 1,796,252 | <p>What about</p>
<pre><code>g = globals().copy()
for name, obj in g.iteritems():
</code></pre>
<p>?</p>
| 12 | 2009-11-25T11:13:14Z | [
"python",
"reflection",
"inspect"
] |
How can I get a list of all classes within current module in Python? | 1,796,180 | <p>I've seen plenty of examples of people extracting all of the classes from a module, usually something like:</p>
<pre><code># foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
</code></pre>
<p>Awesome.</p>
<p>Bu... | 170 | 2009-11-25T10:59:46Z | 1,796,298 | <p>There was a <a href="http://www.python.org/dev/peps/pep-3130/" rel="nofollow">PEP</a> for a feature like this, but it was rejected.</p>
| 2 | 2009-11-25T11:20:19Z | [
"python",
"reflection",
"inspect"
] |
How can I get a list of all classes within current module in Python? | 1,796,180 | <p>I've seen plenty of examples of people extracting all of the classes from a module, usually something like:</p>
<pre><code># foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
</code></pre>
<p>Awesome.</p>
<p>Bu... | 170 | 2009-11-25T10:59:46Z | 5,520,896 | <pre><code>import pyclbr
print(pyclbr.readmodule(__name__).keys())
</code></pre>
<p>Note that the stdlib's Python class browser module uses static source analysis, so it only works for modules that are backed by a real <code>.py</code> file.</p>
| 5 | 2011-04-02T03:22:33Z | [
"python",
"reflection",
"inspect"
] |
How can I get a list of all classes within current module in Python? | 1,796,180 | <p>I've seen plenty of examples of people extracting all of the classes from a module, usually something like:</p>
<pre><code># foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
</code></pre>
<p>Awesome.</p>
<p>Bu... | 170 | 2009-11-25T10:59:46Z | 32,794,385 | <p>I was able to get all I needed from the <a href="https://docs.python.org/2/library/functions.html#dir" rel="nofollow"><code>dir</code></a> built in plus <a href="https://docs.python.org/2/library/functions.html#getattr" rel="nofollow"><code>getattr</code></a>.</p>
<pre><code># Works on pretty much everything, but b... | 1 | 2015-09-26T06:35:41Z | [
"python",
"reflection",
"inspect"
] |
How can I get a list of all classes within current module in Python? | 1,796,180 | <p>I've seen plenty of examples of people extracting all of the classes from a module, usually something like:</p>
<pre><code># foo.py
class Foo:
pass
# test.py
import inspect
import foo
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print obj
</code></pre>
<p>Awesome.</p>
<p>Bu... | 170 | 2009-11-25T10:59:46Z | 35,506,869 | <p>Another solution which works in Python 2 and 3:</p>
<pre><code>#foo.py
import sys
class Foo(object):
pass
def print_classes():
current_module = sys.modules[__name__]
for key in dir(current_module):
if isinstance( getattr(current_module, key), type ):
print(key)
# test.py
import fo... | 1 | 2016-02-19T13:47:04Z | [
"python",
"reflection",
"inspect"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.