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 |
|---|---|---|---|---|---|---|---|---|---|
Is there a Python equivalent to Perl's Data::Dumper? | 2,540,567 | <p>Is there a Python module that can be used in the same way as Perl's <a href="http://search.cpan.org/~smueller/Data-Dumper-2.125/Dumper.pm"><code>Data::Dumper</code></a> module?</p>
<p><strong>Edit:</strong> Sorry, I should have been clearer. I was mainly after a module for inspecting data rather than persisting.</p... | 25 | 2010-03-29T19:09:48Z | 2,540,799 | <p>I think the closest you will find is the <a href="http://docs.python.org/library/pprint.html" rel="nofollow">pprint</a> module.</p>
<pre><code>>>> l = [1, 2, 3, 4]
>>> l.append(l)
>>> d = {1: l, 2: 'this is a string'}
>>> print d
{1: [1, 2, 3, 4, [...]], 2: 'this is a string'}
&... | 3 | 2010-03-29T19:50:09Z | [
"python",
"module",
"object-dumper"
] |
Is there a Python equivalent to Perl's Data::Dumper? | 2,540,567 | <p>Is there a Python module that can be used in the same way as Perl's <a href="http://search.cpan.org/~smueller/Data-Dumper-2.125/Dumper.pm"><code>Data::Dumper</code></a> module?</p>
<p><strong>Edit:</strong> Sorry, I should have been clearer. I was mainly after a module for inspecting data rather than persisting.</p... | 25 | 2010-03-29T19:09:48Z | 2,540,861 | <ul>
<li><p>For serialization, there are many options. </p>
<ul>
<li><p>One of the best is JSON, which is a language-agnostic standard for serialization. It is available in 2.6 in the stdlib <a href="http://docs.python.org/library/json.html" rel="nofollow"><code>json</code></a> module and before that with the same API... | 3 | 2010-03-29T20:01:30Z | [
"python",
"module",
"object-dumper"
] |
Is there a Python equivalent to Perl's Data::Dumper? | 2,540,567 | <p>Is there a Python module that can be used in the same way as Perl's <a href="http://search.cpan.org/~smueller/Data-Dumper-2.125/Dumper.pm"><code>Data::Dumper</code></a> module?</p>
<p><strong>Edit:</strong> Sorry, I should have been clearer. I was mainly after a module for inspecting data rather than persisting.</p... | 25 | 2010-03-29T19:09:48Z | 7,255,148 | <p>I too have been using Data::Dumper for quite some time and have gotten used to its way of displaying nicely formatted complex data structures. pprint as mentioned above does a pretty decent job, but I didn't quite like its formatting style. That plus pprint doesn't allow you to inspect objects like Data::Dumper does... | 1 | 2011-08-31T09:37:18Z | [
"python",
"module",
"object-dumper"
] |
Is there a Python equivalent to Perl's Data::Dumper? | 2,540,567 | <p>Is there a Python module that can be used in the same way as Perl's <a href="http://search.cpan.org/~smueller/Data-Dumper-2.125/Dumper.pm"><code>Data::Dumper</code></a> module?</p>
<p><strong>Edit:</strong> Sorry, I should have been clearer. I was mainly after a module for inspecting data rather than persisting.</p... | 25 | 2010-03-29T19:09:48Z | 8,753,070 | <p>Here is a simple solution for dumping nested data made up of dictionaries, lists, or tuples (it works quite well for me):</p>
<pre><code>def printStruct(struc, indent=0):
if isinstance(struc, dict):
print ' '*indent+'{'
for key,val in struc.iteritems():
if isinstance(val, (dict, list, tuple)):
... | 2 | 2012-01-06T03:35:59Z | [
"python",
"module",
"object-dumper"
] |
Is there a Python equivalent to Perl's Data::Dumper? | 2,540,567 | <p>Is there a Python module that can be used in the same way as Perl's <a href="http://search.cpan.org/~smueller/Data-Dumper-2.125/Dumper.pm"><code>Data::Dumper</code></a> module?</p>
<p><strong>Edit:</strong> Sorry, I should have been clearer. I was mainly after a module for inspecting data rather than persisting.</p... | 25 | 2010-03-29T19:09:48Z | 9,626,727 | <p>As far as inspecting your object goes, I found this a useful equivalent of Data:Dumper:</p>
<p><a href="https://salmon-protocol.googlecode.com/svn-history/r24/trunk/salmon-playground/dumper.py" rel="nofollow">https://salmon-protocol.googlecode.com/svn-history/r24/trunk/salmon-playground/dumper.py</a></p>
<p>It can... | 1 | 2012-03-08T23:30:21Z | [
"python",
"module",
"object-dumper"
] |
How to URL encode this so I can pass it to Facebook Share? | 2,540,944 | <p>This is the URL I want to share:</p>
<pre><code>http://mydomain.com/#url=http://stackoverflow.com
</code></pre>
<p>Inside my site, I do this in Django so that everything will work:</p>
<pre><code>http://mydomain.com/#url={{external|urlencode}}
</code></pre>
<p>However, when I pass it to Facebook Share, everythin... | 0 | 2010-03-29T20:15:16Z | 2,541,524 | <p>I think the problem is, that you first urlencode the last part of url, which you then include into another url.</p>
<p>try use <code>urllib</code> for that:</p>
<pre><code>import urllib
urllib.quote("http://mydomain.com/#url=http://stackoverflow.com")
</code></pre>
<p>or when you have to unquote something:</p>
<... | 0 | 2010-03-29T21:51:29Z | [
"javascript",
"python",
"html",
"django",
"encoding"
] |
Can't import pygame to Netbeans on Mac | 2,541,254 | <p>I am running python 2.6.5 and pygame 1.9.1 It seems to me I've tried everything but it keeps showing 'module not found' errors... Please help!</p>
| 0 | 2010-03-29T21:01:55Z | 2,908,642 | <p>Well I've just finished installing it on my Mac - you have to watch out for the Python Platform under Tools and File. The default is Jython, but you want to change it to point to your python version in the Frameworks file of your Library.</p>
<p>Does that make sense?</p>
| 1 | 2010-05-25T21:26:39Z | [
"python",
"netbeans",
"import",
"module",
"pygame"
] |
Pairwise crossproduct in Python | 2,541,401 | <p>How can I get the list of cross product <em>pairs</em> from a list of arbitrarily long lists in Python?</p>
<h2>Example</h2>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
</code></pre>
<p><code>crossproduct(a,b)</code> should yield <code>[[1, 4], [1, 5], [1, 6], ...]</code>.</p>
| 47 | 2010-03-29T21:27:38Z | 2,541,412 | <p>You're looking for <a href="http://docs.python.org/library/itertools.html#itertools.product">itertools.product</a> if you're on (at least) Python 2.6.</p>
<pre><code>>>> import itertools
>>> a=[1,2,3]
>>> b=[4,5,6]
>>> itertools.product(a,b)
<itertools.product object at 0x1004... | 68 | 2010-03-29T21:29:02Z | [
"python",
"list"
] |
Pairwise crossproduct in Python | 2,541,401 | <p>How can I get the list of cross product <em>pairs</em> from a list of arbitrarily long lists in Python?</p>
<h2>Example</h2>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
</code></pre>
<p><code>crossproduct(a,b)</code> should yield <code>[[1, 4], [1, 5], [1, 6], ...]</code>.</p>
| 47 | 2010-03-29T21:27:38Z | 2,541,422 | <p>Since you asked for a list:</p>
<pre><code>[(x, y) for x in a for y in b]
</code></pre>
<p>But you can avoid the overhead of a list if you're just looping through these by using generators instead:</p>
<pre><code>((x, y) for x in a for y in b)
</code></pre>
<p>Behaves identically in a <code>for</code> loop but d... | 54 | 2010-03-29T21:30:37Z | [
"python",
"list"
] |
Pairwise crossproduct in Python | 2,541,401 | <p>How can I get the list of cross product <em>pairs</em> from a list of arbitrarily long lists in Python?</p>
<h2>Example</h2>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
</code></pre>
<p><code>crossproduct(a,b)</code> should yield <code>[[1, 4], [1, 5], [1, 6], ...]</code>.</p>
| 47 | 2010-03-29T21:27:38Z | 19,832,454 | <p>Using generators there is no need for itertools, simply:</p>
<pre><code>gen = ((x, y) for x in a for y in b)
for u, v in gen:
print u, v
</code></pre>
| 8 | 2013-11-07T09:39:33Z | [
"python",
"list"
] |
Exposing a pointer in Boost.Python | 2,541,446 | <p>I have this very simple C++ class:</p>
<pre><code>class Tree {
public:
Node *head;
};
BOOST_PYTHON_MODULE(myModule)
{
class_<Tree>("Tree")
.def_readwrite("head",&Tree::head)
;
}
</code></pre>
<p>I want to access the head variable from Python, but the message I see is: </p>
<... | 10 | 2010-03-29T21:34:41Z | 2,541,549 | <p>Of course, I find the answer ten minutes after asking the question...here's how it's done:</p>
<pre><code>class_<Tree>("Tree")
.add_property("head",
make_getter(&Tree::head, return_value_policy<reference_existing_object>()),
make_setter(&Tree::head, return_value_policy<reference... | 17 | 2010-03-29T21:55:41Z | [
"c++",
"python",
"boost",
"boost-python"
] |
Return template as string - Django | 2,541,485 | <p>I'm still not sure this is the correct way to go about this, maybe not, but I'll ask anyway. I'd like to re-write wordpress (justification: because I can) albeit more simply myself in Django and I'm looking to be able to configure elements in different ways on the page. So for example I might have:</p>
<ul>
<li>Blo... | 1 | 2010-03-29T21:43:05Z | 2,541,507 | <p>The <code>include</code> template tag can take a variable containing the template to include, so you could loop through a sequence containing the various sub-templates and include them in turn, maybe using a dict to map friendly names to template filenames.</p>
| 1 | 2010-03-29T21:48:13Z | [
"python",
"django",
"django-models",
"django-templates",
"django-views"
] |
Return template as string - Django | 2,541,485 | <p>I'm still not sure this is the correct way to go about this, maybe not, but I'll ask anyway. I'd like to re-write wordpress (justification: because I can) albeit more simply myself in Django and I'm looking to be able to configure elements in different ways on the page. So for example I might have:</p>
<ul>
<li>Blo... | 1 | 2010-03-29T21:43:05Z | 2,541,529 | <p>First, some puzzelement.</p>
<pre><code> InstanceNum = models.IntegerField() # all models have primary keys.
</code></pre>
<p>In Django, all model are assigned an integer primary key. </p>
<p>The comment doesn't make sense, since you don't need to add a primary key like this. The PageItem already has a primary ... | 2 | 2010-03-29T21:51:48Z | [
"python",
"django",
"django-models",
"django-templates",
"django-views"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,537 | <p>You're deleting items from list1 while you're iterating over it.</p>
<p>That's asking for trouble.</p>
<p>Try this:</p>
<pre><code>>>> list1 = [1,2,3,4,5,6]
>>> list2 = []
>>> list2 = list1[:] # we copy every element from list1 using a slice
>>> del list1[:] # we delete every e... | 8 | 2010-03-29T21:53:09Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,548 | <p>Exactly as ChristopheD says.</p>
<p>Could do this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1 = []
</code></pre>
<p>That'll clear list1.</p>
<p><strong>Edit</strong> He/she has updated their post. I'll leave this up as a slight alternative.</p>
| 1 | 2010-03-29T21:55:41Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,552 | <p>You shouldn't modify a list while you iterate over it. This causes the iterator to point at the wrong item. After the first item is handled, the iterator is pointing at index = 1, but because you've removed an item, the next item is now at index zero, so it will be skipped. This is why you are only handling every ot... | 3 | 2010-03-29T21:56:14Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,555 | <p>Using a list comprehension:</p>
<pre><code>list2 = [item for item in list1]
</code></pre>
<p>Bind the name <code>list2</code> to the the same object as <code>list1</code>:</p>
<pre><code>list2 = list1
</code></pre>
<p>(Note that if you modify the contents of <code>list1</code>, <code>list2</code> will be change ... | 1 | 2010-03-29T21:56:43Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,557 | <p>The reason is that you're (appending and) <strong>removing</strong> from the first list whereby it gets smaller. So the iterator stops before the whole list could be walked through.</p>
<p>To achieve what you want, do this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
# You couldn't just make 'list1_copy ... | 8 | 2010-03-29T21:57:11Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,558 | <p>Try this instead:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
list2.extend(list1)
list1[:] = []
</code></pre>
| 1 | 2010-03-29T21:57:11Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,582 | <p>Essential debugging skill: Add <code>print</code> statements. (or <code>print</code> functions in Python 3)</p>
<pre><code>>>> list1= [1, 2, 3, 4, 5, 6]
>>> for item in list1:
... print item
... list1.remove(item)
... print list1
...
1
[2, 3, 4, 5, 6]
3
[2, 4, 5, 6]
5
[2, 4, 6]
</co... | 4 | 2010-03-29T22:02:31Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,586 | <p>There is also the humble copy function (or deepcopy if you have complex objects and not just integers in your list):</p>
<pre><code>from copy import copy
list2 = copy(list1)
</code></pre>
<p>You might get a more appropriate answer if you explain what you're trying to accomplish (unless you're just learning about ... | 1 | 2010-03-29T22:03:06Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,625 | <p>As you can see in other answers, you are trying to modify the list while iterating over it. This doesn't work. There are many ways to copy one list to another. I did some tests to see how fast each approach is:</p>
<pre><code>>>> timeit.Timer('list2 = list1[:]', 'list1 = range(10**3)').timeit(10**6)
3.9134... | 1 | 2010-03-29T22:11:52Z | [
"python",
"list"
] |
iterating through a list removing items, some items are not removed | 2,541,528 | <p>I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:</p>
<pre><code>list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
</code></pre>
<p>But if I run it my output looks like this:</p>
... | 7 | 2010-03-29T21:51:47Z | 2,541,648 | <p>@potatocubed: Many of the answers given solve the trivial example you gave ("move list1 to list2"), but don't really explain the "why" of the deeper problem, which is modifying a list as you iterate over it. Study S.Lott's answer...</p>
| 0 | 2010-03-29T22:21:41Z | [
"python",
"list"
] |
Access to content of Lotus Notes database without Lotus Notes software installed | 2,541,702 | <p>I am looking for a programatic way to access content in a Lotus Notes database (.nsf file) without having Lotus Notes software installed.</p>
<p>Python would be preferred but I'm also willing to look at other languages e.g. C/C++ or other means e.g. SQL</p>
<p>From what I have read, all of the methods e.g. Python ... | 0 | 2010-03-29T22:34:20Z | 2,542,163 | <p>The short answer is, unfortunately you will need the Notes client installed. There are a few ways to access data from an NSF such as NotesSQL, COM, C/C++, but all rely on the Lotus C API at the core, and you'll need a notes client and a notes ID file to gain access via that API. </p>
| 3 | 2010-03-30T00:35:04Z | [
"python",
"lotus-notes",
"lotus"
] |
Access to content of Lotus Notes database without Lotus Notes software installed | 2,541,702 | <p>I am looking for a programatic way to access content in a Lotus Notes database (.nsf file) without having Lotus Notes software installed.</p>
<p>Python would be preferred but I'm also willing to look at other languages e.g. C/C++ or other means e.g. SQL</p>
<p>From what I have read, all of the methods e.g. Python ... | 0 | 2010-03-29T22:34:20Z | 2,551,002 | <p>Like Ken says, inevitably there has to be a server in the mix. If you're searching for specific text in a Notes / Domino application, and looking to replace it, there's a tool out there which does this: Teamstudio Configurator.</p>
<p>Configurator also has an API (written in Lotusscript, which is very like old-skoo... | 0 | 2010-03-31T06:56:53Z | [
"python",
"lotus-notes",
"lotus"
] |
Access to content of Lotus Notes database without Lotus Notes software installed | 2,541,702 | <p>I am looking for a programatic way to access content in a Lotus Notes database (.nsf file) without having Lotus Notes software installed.</p>
<p>Python would be preferred but I'm also willing to look at other languages e.g. C/C++ or other means e.g. SQL</p>
<p>From what I have read, all of the methods e.g. Python ... | 0 | 2010-03-29T22:34:20Z | 2,607,921 | <p>If this is a one-time need, you may be able to find sites that will do some simple Domino/Notes hosting for free. If you could put the NSF up to a service like that, you could then use Domino URL's (REST) to extract the data and search for links, etc.</p>
| 1 | 2010-04-09T13:44:56Z | [
"python",
"lotus-notes",
"lotus"
] |
Why am I getting a " instance has no attribute '__getitem__' " error? | 2,541,718 | <p>Here's the code:</p>
<pre><code>class BinaryTree:
def __init__(self,rootObj):
self.key = rootObj
self.left = None
self.right = None
root = [self.key, self.left, self.right]
def getRootVal(root):
return root[0]
def setRootVal(newVal):
root[0] = newVal
... | 11 | 2010-03-29T22:38:11Z | 2,541,775 | <p>Because you declared your methods wrong:</p>
<p>Lets have a look what happens if you call <code>tree.getRootVal()</code>. <code>.getRootVal()</code> is declared this way:</p>
<pre><code>def getRootVal(root):
return root[0]
</code></pre>
<p>As you probably know, the first parameter passed to a method is always... | 22 | 2010-03-29T22:48:17Z | [
"python"
] |
Why am I getting a " instance has no attribute '__getitem__' " error? | 2,541,718 | <p>Here's the code:</p>
<pre><code>class BinaryTree:
def __init__(self,rootObj):
self.key = rootObj
self.left = None
self.right = None
root = [self.key, self.left, self.right]
def getRootVal(root):
return root[0]
def setRootVal(newVal):
root[0] = newVal
... | 11 | 2010-03-29T22:38:11Z | 2,541,777 | <p>Your first problem is that <code>root</code> should be <code>self.root</code>.</p>
<p>Your second problem is that here:</p>
<pre><code>def getLeftChild(root):
return root[1]
</code></pre>
<p>You are redefining root with a new meaning.</p>
| 1 | 2010-03-29T22:48:39Z | [
"python"
] |
Why am I getting a " instance has no attribute '__getitem__' " error? | 2,541,718 | <p>Here's the code:</p>
<pre><code>class BinaryTree:
def __init__(self,rootObj):
self.key = rootObj
self.left = None
self.right = None
root = [self.key, self.left, self.right]
def getRootVal(root):
return root[0]
def setRootVal(newVal):
root[0] = newVal
... | 11 | 2010-03-29T22:38:11Z | 2,541,783 | <p>As PreludeAndFugue says, you should fix the formatting. But from what I can gather, there is at least one error in your class methods in BinaryTree: most of them don't even take <code>self</code> as a parameter. Fix that and maybe you might be a bit better off.</p>
| 0 | 2010-03-29T22:49:34Z | [
"python"
] |
Most secure way to generate a random session ID for a cookie? | 2,541,742 | <p>I'm writing my own sessions controller that issues a unique id to a user once logged in, and then verifies and authenticates that unique id at every page load. What is the most secure way to generate such an id? Should the unique id be completely random? Is there any downside to including the user id as part of t... | 6 | 2010-03-29T22:42:53Z | 2,541,757 | <p>The best way would be to <a href="http://docs.python.org/library/uuid.html" rel="nofollow">generate a UUID</a>, using the <a href="http://docs.python.org/library/uuid.html#uuid.uuid1" rel="nofollow"><code>uuid.uuid1</code></a> function:</p>
<blockquote>
<p>Generate a UUID from a host ID, sequence number, and the ... | -1 | 2010-03-29T22:45:39Z | [
"python",
"cookies",
"session",
"security"
] |
Most secure way to generate a random session ID for a cookie? | 2,541,742 | <p>I'm writing my own sessions controller that issues a unique id to a user once logged in, and then verifies and authenticates that unique id at every page load. What is the most secure way to generate such an id? Should the unique id be completely random? Is there any downside to including the user id as part of t... | 6 | 2010-03-29T22:42:53Z | 2,541,787 | <p>Use the <a href="http://docs.python.org/library/uuid.html" rel="nofollow">UUID</a> module in 2.5 and higher. This way they can't be guessed since they are not sequential. If you want them to be really secure you could salt them with the user's id and then SHA1 hash them, <a href="http://docs.python.org/library/base6... | 3 | 2010-03-29T22:50:08Z | [
"python",
"cookies",
"session",
"security"
] |
Most secure way to generate a random session ID for a cookie? | 2,541,742 | <p>I'm writing my own sessions controller that issues a unique id to a user once logged in, and then verifies and authenticates that unique id at every page load. What is the most secure way to generate such an id? Should the unique id be completely random? Is there any downside to including the user id as part of t... | 6 | 2010-03-29T22:42:53Z | 2,541,800 | <p>Go buy Bruce Schneier's <a href="http://www.schneier.com/book-sandl.html">Secrets and Lies</a> and his <a href="http://www.schneier.com/book-practical.html">Practical Cryptography</a>. Go ahead and order Ross Anderson's <a href="http://www.cl.cam.ac.uk/~rja14/book.html">Security Engineering 2nd Ed.</a> while you're... | 7 | 2010-03-29T22:51:54Z | [
"python",
"cookies",
"session",
"security"
] |
Most secure way to generate a random session ID for a cookie? | 2,541,742 | <p>I'm writing my own sessions controller that issues a unique id to a user once logged in, and then verifies and authenticates that unique id at every page load. What is the most secure way to generate such an id? Should the unique id be completely random? Is there any downside to including the user id as part of t... | 6 | 2010-03-29T22:42:53Z | 2,542,128 | <p>If the only information in the cookie is an identifier, essentially a label, the only attack you're trying to protect from is an attacker guessing what it is. So use some random bytes. Enough random bytes that it's "unguessable."</p>
<p>Then squish the random bytes into something that fits within the confines of ... | 4 | 2010-03-30T00:22:25Z | [
"python",
"cookies",
"session",
"security"
] |
Most secure way to generate a random session ID for a cookie? | 2,541,742 | <p>I'm writing my own sessions controller that issues a unique id to a user once logged in, and then verifies and authenticates that unique id at every page load. What is the most secure way to generate such an id? Should the unique id be completely random? Is there any downside to including the user id as part of t... | 6 | 2010-03-29T22:42:53Z | 12,245,882 | <p>You can use <a href="http://docs.python.org/library/os.html#os.urandom" rel="nofollow">os.urandom</a>:</p>
<blockquote>
<p>os.urandom(n)</p>
<p>Return a string of n random bytes suitable for cryptographic use.</p>
<p>This function returns random bytes from an OS-specific randomness source.
The returne... | 4 | 2012-09-03T10:16:14Z | [
"python",
"cookies",
"session",
"security"
] |
Most secure way to generate a random session ID for a cookie? | 2,541,742 | <p>I'm writing my own sessions controller that issues a unique id to a user once logged in, and then verifies and authenticates that unique id at every page load. What is the most secure way to generate such an id? Should the unique id be completely random? Is there any downside to including the user id as part of t... | 6 | 2010-03-29T22:42:53Z | 21,591,203 | <p><a href="http://docs.python.org/2/library/random.html" rel="nofollow">http://docs.python.org/2/library/random.html</a></p>
<p>"Warning: The pseudo-random generators of this [random] module should not be used for security purposes. Use os.urandom() or SystemRandom if you require a cryptographically secure pseudo-ran... | 0 | 2014-02-05T23:54:27Z | [
"python",
"cookies",
"session",
"security"
] |
Most secure way to generate a random session ID for a cookie? | 2,541,742 | <p>I'm writing my own sessions controller that issues a unique id to a user once logged in, and then verifies and authenticates that unique id at every page load. What is the most secure way to generate such an id? Should the unique id be completely random? Is there any downside to including the user id as part of t... | 6 | 2010-03-29T22:42:53Z | 29,989,100 | <p>I would avoid the random factor completely. What I've generally done is:</p>
<ul>
<li>Generate a sequential <code>session_id</code> (which I store locally).</li>
<li>When the user logs in, sign <code>session_id</code> with a private key (I use <code>itsdangerous</code> for this).</li>
<li>When I get a request, if t... | 0 | 2015-05-01T14:48:03Z | [
"python",
"cookies",
"session",
"security"
] |
how best do I find the intersection of multiple sets in python? | 2,541,752 | <p>I have a list of sets:</p>
<pre><code>setlist = [s1,s2,s3...]
</code></pre>
<p>I want s1 â© s2 â© s3 ...</p>
<p>I can write a function to do it by performing a series of pairwise <code>s1.intersection(s2)</code>, etc.</p>
<p>Is there a recommended, better, or built-in way?</p>
| 98 | 2010-03-29T22:44:19Z | 2,541,807 | <p>If you don't have Python 2.6 or higher, the alternative is to write an explicit for loop:</p>
<pre><code>def set_list_intersection(set_list):
if not set_list:
return set()
result = set_list[0]
for s in set_list[1:]:
result &= s
return result
set_list = [set([1, 2]), set([1, 3]), set([1, 4])]
pr... | 7 | 2010-03-29T22:53:30Z | [
"python",
"set",
"set-intersection"
] |
how best do I find the intersection of multiple sets in python? | 2,541,752 | <p>I have a list of sets:</p>
<pre><code>setlist = [s1,s2,s3...]
</code></pre>
<p>I want s1 â© s2 â© s3 ...</p>
<p>I can write a function to do it by performing a series of pairwise <code>s1.intersection(s2)</code>, etc.</p>
<p>Is there a recommended, better, or built-in way?</p>
| 98 | 2010-03-29T22:44:19Z | 2,541,814 | <p>From Python version 2.6 on you can use multiple arguments to <a href="http://docs.python.org/library/stdtypes.html#set.intersection"><code>set.intersection()</code></a>, like</p>
<pre><code>u = set.intersection(s1, s2, s3)
</code></pre>
<p>If the sets are in a list, this translates to:</p>
<pre><code>u = set.inte... | 186 | 2010-03-29T22:55:34Z | [
"python",
"set",
"set-intersection"
] |
how best do I find the intersection of multiple sets in python? | 2,541,752 | <p>I have a list of sets:</p>
<pre><code>setlist = [s1,s2,s3...]
</code></pre>
<p>I want s1 â© s2 â© s3 ...</p>
<p>I can write a function to do it by performing a series of pairwise <code>s1.intersection(s2)</code>, etc.</p>
<p>Is there a recommended, better, or built-in way?</p>
| 98 | 2010-03-29T22:44:19Z | 2,541,823 | <p>As of 2.6, <code>set.intersection</code> takes arbitrarily many iterables. </p>
<pre><code>>>> s1 = set([1, 2, 3])
>>> s2 = set([2, 3, 4])
>>> s3 = set([2, 4, 6])
>>> s1 & s2 & s3
set([2])
>>> s1.intersection(s2, s3)
set([2])
>>> sets = [s1, s2, s3]
>... | 19 | 2010-03-29T22:58:49Z | [
"python",
"set",
"set-intersection"
] |
how best do I find the intersection of multiple sets in python? | 2,541,752 | <p>I have a list of sets:</p>
<pre><code>setlist = [s1,s2,s3...]
</code></pre>
<p>I want s1 â© s2 â© s3 ...</p>
<p>I can write a function to do it by performing a series of pairwise <code>s1.intersection(s2)</code>, etc.</p>
<p>Is there a recommended, better, or built-in way?</p>
| 98 | 2010-03-29T22:44:19Z | 2,557,047 | <p>Here I'm offering a generic function for multiple set intersection trying to take advantage of the best method available:</p>
<pre><code>def multiple_set_intersection(*sets):
"""Return multiple set intersection."""
try:
return set.intersection(*sets)
except TypeError: # this is Python < 2.6 o... | 1 | 2010-03-31T22:50:38Z | [
"python",
"set",
"set-intersection"
] |
how best do I find the intersection of multiple sets in python? | 2,541,752 | <p>I have a list of sets:</p>
<pre><code>setlist = [s1,s2,s3...]
</code></pre>
<p>I want s1 â© s2 â© s3 ...</p>
<p>I can write a function to do it by performing a series of pairwise <code>s1.intersection(s2)</code>, etc.</p>
<p>Is there a recommended, better, or built-in way?</p>
| 98 | 2010-03-29T22:44:19Z | 9,492,293 | <p>Clearly <code>set.intersection</code> is what you want here, but in case you ever need a generalisation of "take the sum of all these", "take the product of all these", "take the xor of all these", what you are looking for is the <code>reduce</code> function:</p>
<pre><code>from operator import and_
from functools ... | 5 | 2012-02-29T01:18:36Z | [
"python",
"set",
"set-intersection"
] |
Copying 2D lists in python | 2,541,865 | <p>Hi I want to copy a 2D list, so that if I modify 1 list, the other is not modified.</p>
<p>For 1 D list, I just do this:</p>
<pre><code>a = [1,2]
b = a[:]
</code></pre>
<p>And now if I modify b, a is not modified.</p>
<p>But this doesn't work for 2D list:</p>
<pre><code>a = [[1,2],[3,4]]
b = a[:]
</code></pre>
... | 12 | 2010-03-29T23:10:34Z | 2,541,874 | <pre><code>b = [x[:] for x in a]
</code></pre>
| 24 | 2010-03-29T23:11:48Z | [
"python"
] |
Copying 2D lists in python | 2,541,865 | <p>Hi I want to copy a 2D list, so that if I modify 1 list, the other is not modified.</p>
<p>For 1 D list, I just do this:</p>
<pre><code>a = [1,2]
b = a[:]
</code></pre>
<p>And now if I modify b, a is not modified.</p>
<p>But this doesn't work for 2D list:</p>
<pre><code>a = [[1,2],[3,4]]
b = a[:]
</code></pre>
... | 12 | 2010-03-29T23:10:34Z | 2,541,882 | <p>For a more general solution that works regardless of the number of dimensions, use <code>copy.deepcopy()</code>:</p>
<pre><code>import copy
b = copy.deepcopy(a)
</code></pre>
| 26 | 2010-03-29T23:13:01Z | [
"python"
] |
Is there a good way of automatically generating javascript client code from server side python | 2,541,954 | <p>I basically want to be able to:</p>
<ul>
<li>Write a few functions in python (with the minimum amount of extra meta data)</li>
<li>Turn these functions into a web service (with the minimum of effort / boiler plate)</li>
<li>Automatically generate some javascript functions / objects for rpc (this should prevent me f... | 4 | 2010-03-29T23:35:32Z | 2,541,966 | <p>Yes there is, there is <a href="http://pyjs.org/">Pyjamas</a>. Some people bill this as the "<a href="http://code.google.com/webtoolkit/">GWT</a> for Python"</p>
| 6 | 2010-03-29T23:37:47Z | [
"javascript",
"python",
"rpc"
] |
Is there a good way of automatically generating javascript client code from server side python | 2,541,954 | <p>I basically want to be able to:</p>
<ul>
<li>Write a few functions in python (with the minimum amount of extra meta data)</li>
<li>Turn these functions into a web service (with the minimum of effort / boiler plate)</li>
<li>Automatically generate some javascript functions / objects for rpc (this should prevent me f... | 4 | 2010-03-29T23:35:32Z | 2,571,876 | <p>It looks like using a javascript XML RPC client (there is jquery plugin for this) together with an XML RPC server is a good way to go.</p>
<p>The jquery plugin will introspect your rpc service and will populate method names make it impossible to mis type the name of a method call without getting early warning. It w... | 0 | 2010-04-03T16:34:59Z | [
"javascript",
"python",
"rpc"
] |
Read/Write a file from/to network folder/share using Python? | 2,542,025 | <p>How to Write/Read a file to/from a network folder/share using python? The application will run under Linux and network folder/share can be a Linux/Windows System.</p>
<p>Also, how to check that network folder/share has enough space before writing a file?</p>
<p>What things should i consider?</p>
| 1 | 2010-03-29T19:33:57Z | 2,542,026 | <p>Mount the shares using Samba, check the free space on the share using <code>df</code> or <code>os.statvfs</code> and read/write to it like any other folder.</p>
| 1 | 2010-03-29T22:21:51Z | [
"python",
"network-shares"
] |
Why am I getting a SyntaxError in the Python interpreter? | 2,542,066 | <p>This code works when I try it from a .py file, but fails in the command line interpreter and Idle.</p>
<pre><code>>>> try:
... fsock = open("/bla")
... except IOError:
... print "Caught"
... print "continue"
File "<stdin>", line 5
print "continue"
^
SyntaxError: invalid syntax
<... | 1 | 2010-03-30T00:05:29Z | 2,542,070 | <p>With Python 3, <code>print</code> is a function and not a statement, so you would need parentheses around the arguments, as in <code>print("continue")</code>, if you were using Python 3.</p>
<p>The caret, however, is pointing to an earlier position than it would be with Python 3, so you must be using Python 2.x ins... | 5 | 2010-03-30T00:07:12Z | [
"python",
"syntax-error"
] |
Why am I getting a SyntaxError in the Python interpreter? | 2,542,066 | <p>This code works when I try it from a .py file, but fails in the command line interpreter and Idle.</p>
<pre><code>>>> try:
... fsock = open("/bla")
... except IOError:
... print "Caught"
... print "continue"
File "<stdin>", line 5
print "continue"
^
SyntaxError: invalid syntax
<... | 1 | 2010-03-30T00:05:29Z | 2,542,088 | <p>You need to leave a blank line to close the <code>except</code> block. The <code>...</code> indicates it is still trying to put code in that block, even though you dedent it. This is just a quirk of the interactive interpreter. </p>
| 3 | 2010-03-30T00:10:19Z | [
"python",
"syntax-error"
] |
Why am I getting a SyntaxError in the Python interpreter? | 2,542,066 | <p>This code works when I try it from a .py file, but fails in the command line interpreter and Idle.</p>
<pre><code>>>> try:
... fsock = open("/bla")
... except IOError:
... print "Caught"
... print "continue"
File "<stdin>", line 5
print "continue"
^
SyntaxError: invalid syntax
<... | 1 | 2010-03-30T00:05:29Z | 2,542,090 | <p>Try this one in the interpreter:</p>
<pre><code>try:
fsock = open("/bla")
except IOError:
print "Caught"
print "continue"
</code></pre>
<p>Important here is the empty line after the indentation. I'm using the python 2.6 interpreter and it throws the same Syntax error as you.</p>
<p>This is because the in... | 2 | 2010-03-30T00:10:46Z | [
"python",
"syntax-error"
] |
Why isn't my os.rename working? | 2,542,116 | <p>I'm trying to rename some files, but getting a baffling error*. When I run this:</p>
<pre><code>if os.path.isfile(fullPath):
print 'fmf exists'
print fullPath
print newFilePath
os.rename(fullPath,newFilePath)
</code></pre>
<p>I get the following error:</p>
<pre><code>fmf exists
(correct fullPath)... | 1 | 2010-03-30T00:16:59Z | 2,542,124 | <p>You can still get the exception if you try to copy to a directory that does not exist.</p>
| 1 | 2010-03-30T00:21:01Z | [
"python",
"rename"
] |
Why isn't my os.rename working? | 2,542,116 | <p>I'm trying to rename some files, but getting a baffling error*. When I run this:</p>
<pre><code>if os.path.isfile(fullPath):
print 'fmf exists'
print fullPath
print newFilePath
os.rename(fullPath,newFilePath)
</code></pre>
<p>I get the following error:</p>
<pre><code>fmf exists
(correct fullPath)... | 1 | 2010-03-30T00:16:59Z | 2,542,131 | <p>I can't see the full inner workings of your code, so here's my two cents worth:</p>
<p>Your newFilePath may contain a directory that doesn't exist. If that is the case, then depending on your operating system, your program is unable to create a file in a directory that doesn't exist. That could be your error.</p>
... | 1 | 2010-03-30T00:22:39Z | [
"python",
"rename"
] |
Why isn't my os.rename working? | 2,542,116 | <p>I'm trying to rename some files, but getting a baffling error*. When I run this:</p>
<pre><code>if os.path.isfile(fullPath):
print 'fmf exists'
print fullPath
print newFilePath
os.rename(fullPath,newFilePath)
</code></pre>
<p>I get the following error:</p>
<pre><code>fmf exists
(correct fullPath)... | 1 | 2010-03-30T00:16:59Z | 13,981,219 | <p>It seems like the poster solved his problem, but I had the same symptom and the cause appeared to be different. The file I was trying to rename had just been created in a subprocess call on the previous line. If I ran my script again, I didn't have the rename problem, since the file had been created in the previous ... | 0 | 2012-12-20T22:00:19Z | [
"python",
"rename"
] |
Why isn't my os.rename working? | 2,542,116 | <p>I'm trying to rename some files, but getting a baffling error*. When I run this:</p>
<pre><code>if os.path.isfile(fullPath):
print 'fmf exists'
print fullPath
print newFilePath
os.rename(fullPath,newFilePath)
</code></pre>
<p>I get the following error:</p>
<pre><code>fmf exists
(correct fullPath)... | 1 | 2010-03-30T00:16:59Z | 29,908,783 | <p>I had the same error when my new filename contained forward slashes, which are confused with directory separators in Unix and Linux. For example, renaming a file to "4/27/2015.txt" leads to a directory that doesn't exist and results in "No such file or directory". You can solve this by replacing the forward slashes ... | 0 | 2015-04-28T01:34:07Z | [
"python",
"rename"
] |
Subclassed django models with integrated querysets | 2,542,157 | <p>Like in <a href="http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-name/929982#929982">this question</a>, except I want to be able to have querysets that return a mixed body of objects:</p>
<pre><code>>>> Product.objects.all()
[<Simple... | 7 | 2010-03-30T00:33:59Z | 2,543,894 | <p>Okay, this works: <a href="https://gist.github.com/348872" rel="nofollow">https://gist.github.com/348872</a></p>
<p>The tricky bit was this. </p>
<pre><code>class A(Top):
pass
def newA(cls, *args, **kwargs):
# [all that code you wrote for A.__new__]
A.__new__ = staticmethod(newA)
</code></pre>
<p>Now, ... | 1 | 2010-03-30T08:50:52Z | [
"python",
"django",
"django-models",
"django-queryset",
"metaclass"
] |
Subclassed django models with integrated querysets | 2,542,157 | <p>Like in <a href="http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-name/929982#929982">this question</a>, except I want to be able to have querysets that return a mixed body of objects:</p>
<pre><code>>>> Product.objects.all()
[<Simple... | 7 | 2010-03-30T00:33:59Z | 2,544,208 | <p>Basically what you're trying to do is to return the different child classes, while querying a shared base class. That is: you want the leaf classes. Check this snippet for a solution: <a href="http://www.djangosnippets.org/snippets/1034/" rel="nofollow">http://www.djangosnippets.org/snippets/1034/</a></p>
<p>Also b... | 4 | 2010-03-30T09:48:25Z | [
"python",
"django",
"django-models",
"django-queryset",
"metaclass"
] |
Subclassed django models with integrated querysets | 2,542,157 | <p>Like in <a href="http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-name/929982#929982">this question</a>, except I want to be able to have querysets that return a mixed body of objects:</p>
<pre><code>>>> Product.objects.all()
[<Simple... | 7 | 2010-03-30T00:33:59Z | 9,194,509 | <p>Simply stick @staticmethod before the <code>__new__</code> method.</p>
<pre><code>@staticmethod
def __new__(cls, *args, **kwargs):
print args, kwargs
return super(License, cls).__new__(cls, *args, **kwargs)
</code></pre>
| 1 | 2012-02-08T13:45:34Z | [
"python",
"django",
"django-models",
"django-queryset",
"metaclass"
] |
Subclassed django models with integrated querysets | 2,542,157 | <p>Like in <a href="http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-name/929982#929982">this question</a>, except I want to be able to have querysets that return a mixed body of objects:</p>
<pre><code>>>> Product.objects.all()
[<Simple... | 7 | 2010-03-30T00:33:59Z | 9,198,412 | <p>You want one of these:</p>
<p><a href="http://code.google.com/p/django-polymorphic-models/" rel="nofollow">http://code.google.com/p/django-polymorphic-models/</a><br>
<a href="https://github.com/bconstantin/django_polymorphic" rel="nofollow">https://github.com/bconstantin/django_polymorphic</a></p>
<p>There are do... | 2 | 2012-02-08T17:29:30Z | [
"python",
"django",
"django-models",
"django-queryset",
"metaclass"
] |
Subclassed django models with integrated querysets | 2,542,157 | <p>Like in <a href="http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-name/929982#929982">this question</a>, except I want to be able to have querysets that return a mixed body of objects:</p>
<pre><code>>>> Product.objects.all()
[<Simple... | 7 | 2010-03-30T00:33:59Z | 15,819,364 | <p>Another approach that I recently found: <a href="http://jeffelmore.org/2010/11/11/automatic-downcasting-of-inherited-models-in-django/" rel="nofollow">http://jeffelmore.org/2010/11/11/automatic-downcasting-of-inherited-models-in-django/</a></p>
| 1 | 2013-04-04T18:51:57Z | [
"python",
"django",
"django-models",
"django-queryset",
"metaclass"
] |
Python 3: receive user input including newline characters | 2,542,171 | <p>I'm trying to read in the following text from the command-line in Python 3 (copied verbatim, newlines and all):</p>
<pre><code>lcbeika
rraobmlo
grmfina
ontccep
emrlin
tseiboo
edosrgd
mkoeys
eissaml
knaiefr
</code></pre>
<p>Using <code>input</code>, I can only read in the first word as once it reads the first newli... | 4 | 2010-03-30T00:37:11Z | 2,542,182 | <p>You can <code>import sys</code> and use the methods on <code>sys.stdin</code> for example:</p>
<pre><code>text = sys.stdin.read()
</code></pre>
<p>or:</p>
<pre><code>lines = sys.stdin.readlines()
</code></pre>
<p>or:</p>
<pre><code>for line in sys.stdin:
# Do something with line.
</code></pre>
| 8 | 2010-03-30T00:39:35Z | [
"python",
"input",
"python-3.x"
] |
Python 3: receive user input including newline characters | 2,542,171 | <p>I'm trying to read in the following text from the command-line in Python 3 (copied verbatim, newlines and all):</p>
<pre><code>lcbeika
rraobmlo
grmfina
ontccep
emrlin
tseiboo
edosrgd
mkoeys
eissaml
knaiefr
</code></pre>
<p>Using <code>input</code>, I can only read in the first word as once it reads the first newli... | 4 | 2010-03-30T00:37:11Z | 2,542,191 | <p>if you are passing the text into your script as a file , you can use <code>readlines()</code></p>
<p>eg</p>
<pre><code>data=open("file").readlines()
</code></pre>
<p>or you can use <code>fileinput</code></p>
<pre><code>import fileinput
for line in fileinput.input():
print line
</code></pre>
| -2 | 2010-03-30T00:42:17Z | [
"python",
"input",
"python-3.x"
] |
Get a user's timezone in Python + Pylons | 2,542,206 | <p>Is there a way to get the timezone of the connecting user using Pylons, and to adjust the content before rendering accordingly? Or can this only be done by JS?</p>
<p>Thanks.</p>
| 2 | 2010-03-30T00:47:15Z | 2,542,216 | <p>You can't get the client's timezone using server-side code, you can, however:</p>
<ol>
<li>use Javascript: <code>Date.getTimezoneOffset();</code></li>
<li>use geolocation to determine where the user is located and deduce the timezone from the location</li>
</ol>
| 2 | 2010-03-30T00:51:03Z | [
"python",
"timezone",
"pylons"
] |
Python calling pipe.communicate() in a thread | 2,542,423 | <p>Using Python 2.6.1 on Mac OS X 10.6.2, I've the following problem:</p>
<p>I have a threaded process (a Thread class), and each of those threads has a pipe (a subprocess.Popen) something likeso:</p>
<pre><code> from threading import Thread
cmd = "some_cmd"
class Worker(Thread):
def run(self):
pipe = ... | 3 | 2010-03-30T02:05:01Z | 2,543,343 | <p>Using multiple threads <strong>and</strong> multiple processes will often cause problems, particularly (though not exclusively) on Unix-based systems; I recommend you just avoid mixing the two.</p>
| 1 | 2010-03-30T06:57:22Z | [
"python",
"multithreading",
"deadlock",
"multiprocessing"
] |
Python calling pipe.communicate() in a thread | 2,542,423 | <p>Using Python 2.6.1 on Mac OS X 10.6.2, I've the following problem:</p>
<p>I have a threaded process (a Thread class), and each of those threads has a pipe (a subprocess.Popen) something likeso:</p>
<pre><code> from threading import Thread
cmd = "some_cmd"
class Worker(Thread):
def run(self):
pipe = ... | 3 | 2010-03-30T02:05:01Z | 2,546,107 | <p>If you call <code>sys.exit()</code> in the main thread, other threads will terminate at the next opportunity (on most operating systems). However, if they're in a blocking call (such as communicate()), they will wait until the blocking call completes before terminating. Control-C works because it causes the operat... | 1 | 2010-03-30T14:45:19Z | [
"python",
"multithreading",
"deadlock",
"multiprocessing"
] |
Find elements based on xsd type with lxml | 2,542,580 | <p>I am trying to get a list of elements with a specific xsd type with lxml 2.x and I can't figure out how to traverse the xsd for specific types.</p>
<p>Example of schema:</p>
<pre><code><xsd:element name="ServerOwner" type="srvrs:string90" minOccurs="0">
<xsd:element name="HostName" type="srvrs:string35" m... | 6 | 2010-03-30T02:49:59Z | 2,542,806 | <p>Really the only special support lxml has for XML Schema, as seen <a href="http://codespeak.net/lxml/validation.html#xmlschema" rel="nofollow">here</a>, is to tell you if some document is valid according to some schema or not. Anything more sophisticated you'll have to do yourself.</p>
<p>This should be a relatively... | 4 | 2010-03-30T04:01:15Z | [
"python",
"xml",
"xsd",
"lxml"
] |
Python-daemon doesn't kill its kids | 2,542,610 | <p>When using <a href="http://pypi.python.org/pypi/python-daemon/">python-daemon</a>, I'm creating subprocesses likeso:</p>
<pre><code>import multiprocessing
class Worker(multiprocessing.Process):
def __init__(self, queue):
self.queue = queue # we wait for things from this in Worker.run()
...
q = multip... | 19 | 2010-03-30T02:59:56Z | 2,594,275 | <p>Atexit won't do the trick -- it only gets run on successful non-signal termination -- see the note near the top of the <a href="http://docs.python.org/library/atexit.html" rel="nofollow" title="atexit() docs">docs</a>. You need to set up signal handling via one of two means.</p>
<p>The easier-sounding option: set t... | 2 | 2010-04-07T16:44:18Z | [
"python",
"daemon",
"multiprocessing",
"children",
"zombie-process"
] |
Python-daemon doesn't kill its kids | 2,542,610 | <p>When using <a href="http://pypi.python.org/pypi/python-daemon/">python-daemon</a>, I'm creating subprocesses likeso:</p>
<pre><code>import multiprocessing
class Worker(multiprocessing.Process):
def __init__(self, queue):
self.queue = queue # we wait for things from this in Worker.run()
...
q = multip... | 19 | 2010-03-30T02:59:56Z | 2,610,911 | <p>Your options are a bit limited. If doing <code>self.daemon = True</code> in the constructor for the <code>Worker</code> class does not solve your problem and trying to catch signals in the Parent (ie, <code>SIGTERM, SIGINT</code>) doesn't work, you may have to try the opposite solution - instead of having the parent... | 30 | 2010-04-09T21:04:08Z | [
"python",
"daemon",
"multiprocessing",
"children",
"zombie-process"
] |
Python-daemon doesn't kill its kids | 2,542,610 | <p>When using <a href="http://pypi.python.org/pypi/python-daemon/">python-daemon</a>, I'm creating subprocesses likeso:</p>
<pre><code>import multiprocessing
class Worker(multiprocessing.Process):
def __init__(self, queue):
self.queue = queue # we wait for things from this in Worker.run()
...
q = multip... | 19 | 2010-03-30T02:59:56Z | 2,611,032 | <p>can't you just store the parent pid when the child is first created (let's say in <code>self.myppid</code>) and when <code>self.myppid</code> is diferent from <code>getppid()</code> means that the parent died.</p>
<p>you could also use signals to avoid the need to keep checking if the parent has changed. I don't kn... | 3 | 2010-04-09T21:23:02Z | [
"python",
"daemon",
"multiprocessing",
"children",
"zombie-process"
] |
In python, what is the fastest way to determine if a string is an email or an integer? | 2,542,642 | <p>I'd like to be able to pull users from a database using either a supplied e-mail address or the user id (an integer). To do this, I have to detect if the supplied string is an integer, or an e-mail. Looking for the fastest way to do this. Thanks.</p>
<pre><code>def __init__(self, data):
#populate class data
... | 1 | 2010-03-30T03:11:01Z | 2,542,659 | <p>The canonical way to handle this in Python is to try first, ask forgiveness later: </p>
<pre><code>def _fetchInfo(self, data):
try:
data=int(data)
sql='SELECT ... WHERE id = %s'
args=[data]
except ValueError:
sql='SELECT ... WHERE email = %s'
args=[data]
# Thi... | 4 | 2010-03-30T03:16:41Z | [
"python",
"string",
"integer"
] |
In python, what is the fastest way to determine if a string is an email or an integer? | 2,542,642 | <p>I'd like to be able to pull users from a database using either a supplied e-mail address or the user id (an integer). To do this, I have to detect if the supplied string is an integer, or an e-mail. Looking for the fastest way to do this. Thanks.</p>
<pre><code>def __init__(self, data):
#populate class data
... | 1 | 2010-03-30T03:11:01Z | 2,542,662 | <p>You can use the <a href="http://docs.python.org/library/functions.html#isinstance" rel="nofollow">isinstance</a> function:</p>
<pre><code>if isinstance(data, int):
# it's an id
else:
# it's a string
</code></pre>
<p>Though personally, I'd just have two methods, <code>fetchById</code> and <code>fetchByEmail</... | 2 | 2010-03-30T03:17:10Z | [
"python",
"string",
"integer"
] |
In python, what is the fastest way to determine if a string is an email or an integer? | 2,542,642 | <p>I'd like to be able to pull users from a database using either a supplied e-mail address or the user id (an integer). To do this, I have to detect if the supplied string is an integer, or an e-mail. Looking for the fastest way to do this. Thanks.</p>
<pre><code>def __init__(self, data):
#populate class data
... | 1 | 2010-03-30T03:11:01Z | 2,542,759 | <p>You said both were strings, right? This would work, too.</p>
<pre><code>if data.isdigit():
# it's an id
else:
# it's not
</code></pre>
| 2 | 2010-03-30T03:45:56Z | [
"python",
"string",
"integer"
] |
In python, what is the fastest way to determine if a string is an email or an integer? | 2,542,642 | <p>I'd like to be able to pull users from a database using either a supplied e-mail address or the user id (an integer). To do this, I have to detect if the supplied string is an integer, or an e-mail. Looking for the fastest way to do this. Thanks.</p>
<pre><code>def __init__(self, data):
#populate class data
... | 1 | 2010-03-30T03:11:01Z | 2,544,020 | <pre><code>if '@' in data:
# email
else:
# id
</code></pre>
| 1 | 2010-03-30T09:15:57Z | [
"python",
"string",
"integer"
] |
No matter what I do, django-admin.py is not found, even though it's in my path | 2,542,674 | <p>I have added C:\Python26\Lib\site-packages\django\bin to my path, I have started a new cmd session in Windows 7, but when I try to do 'python django-admin.py ...' it says there is no file django-admin.py. When I type path, there is the full path to ...\django\bin. This is driving me nuts. Clearly it's there, but it... | 3 | 2010-03-30T03:20:26Z | 2,542,702 | <p>The python interpreter does <em>not</em> look everywhere on your path to find the script. It does look everywhere for imports, but not for scripts.</p>
<p>Try typing <code>django-admin.py</code>, just <code>django-admin.py</code> and not <code>python django-admin.py</code>, and it should work. Windows should find i... | 5 | 2010-03-30T03:27:02Z | [
"python",
"django"
] |
No matter what I do, django-admin.py is not found, even though it's in my path | 2,542,674 | <p>I have added C:\Python26\Lib\site-packages\django\bin to my path, I have started a new cmd session in Windows 7, but when I try to do 'python django-admin.py ...' it says there is no file django-admin.py. When I type path, there is the full path to ...\django\bin. This is driving me nuts. Clearly it's there, but it... | 3 | 2010-03-30T03:20:26Z | 2,543,312 | <p><code>python -mdjango-admin</code> looks like what you're looking for. <code>-m</code> tells Python to find a module on <code>sys.path</code> and run <em>that module</em> as "the main script" -- which seems exactly your goal!</p>
| 4 | 2010-03-30T06:52:16Z | [
"python",
"django"
] |
No matter what I do, django-admin.py is not found, even though it's in my path | 2,542,674 | <p>I have added C:\Python26\Lib\site-packages\django\bin to my path, I have started a new cmd session in Windows 7, but when I try to do 'python django-admin.py ...' it says there is no file django-admin.py. When I type path, there is the full path to ...\django\bin. This is driving me nuts. Clearly it's there, but it... | 3 | 2010-03-30T03:20:26Z | 2,718,527 | <p>I had the same problem, and python -mdjango-admin works. but i had to define PYTHONHOME & PYTHONPATH first</p>
| 0 | 2010-04-27T03:33:15Z | [
"python",
"django"
] |
No matter what I do, django-admin.py is not found, even though it's in my path | 2,542,674 | <p>I have added C:\Python26\Lib\site-packages\django\bin to my path, I have started a new cmd session in Windows 7, but when I try to do 'python django-admin.py ...' it says there is no file django-admin.py. When I type path, there is the full path to ...\django\bin. This is driving me nuts. Clearly it's there, but it... | 3 | 2010-03-30T03:20:26Z | 7,886,131 | <p>This python command will search syspath for the django module in question:</p>
<pre><code>python -m django.bin.django-admin
</code></pre>
| 3 | 2011-10-25T07:42:05Z | [
"python",
"django"
] |
No matter what I do, django-admin.py is not found, even though it's in my path | 2,542,674 | <p>I have added C:\Python26\Lib\site-packages\django\bin to my path, I have started a new cmd session in Windows 7, but when I try to do 'python django-admin.py ...' it says there is no file django-admin.py. When I type path, there is the full path to ...\django\bin. This is driving me nuts. Clearly it's there, but it... | 3 | 2010-03-30T03:20:26Z | 14,559,937 | <p>I realize this is old, but came across the same issue.
On Windows, your path should include the following:</p>
<p>C:\Python27\;C:\Python27\Scripts</p>
<p>This is assuming python 2.7.3 is installed and django 1.4.3</p>
| 4 | 2013-01-28T10:25:58Z | [
"python",
"django"
] |
Is it possible to write an IM server in python? (be able to handle the heavy connections) | 2,542,718 | <p>i wanna write an IM server in python, but i'm not sure if python can handle the heavy connections?</p>
<p>Thanks in advance.</p>
| 2 | 2010-03-30T03:31:41Z | 2,542,728 | <p><a href="http://omegle.com/" rel="nofollow">Omegle</a> is written in Python and as of writing is sustaining 7,057 concurrent online users.</p>
<p>It's not so much about the choice of language, but the efficiency of your code and how well it is optimized.</p>
<pre><code>while true:
# nothing
</code></pre>
<p>i... | 2 | 2010-03-30T03:34:44Z | [
"python",
"instant-messaging"
] |
Is it possible to write an IM server in python? (be able to handle the heavy connections) | 2,542,718 | <p>i wanna write an IM server in python, but i'm not sure if python can handle the heavy connections?</p>
<p>Thanks in advance.</p>
| 2 | 2010-03-30T03:31:41Z | 2,542,732 | <p>Yes, you could :)</p>
<p>For example: SecondLife has written a library to support non-blocking IO, you can find it at: <a href="http://eventlet.net/" rel="nofollow">http://eventlet.net/</a></p>
<p>The beauty of Python is, you can optimize the code when it's needed. If some part of your code is executed a lot you c... | 2 | 2010-03-30T03:36:53Z | [
"python",
"instant-messaging"
] |
Is it possible to write an IM server in python? (be able to handle the heavy connections) | 2,542,718 | <p>i wanna write an IM server in python, but i'm not sure if python can handle the heavy connections?</p>
<p>Thanks in advance.</p>
| 2 | 2010-03-30T03:31:41Z | 3,446,940 | <p><a href="http://www.gevent.org" rel="nofollow">gevent</a> is a Python network library based on libevent that is capable of handling thousands of connections. Read the <a href="http://www.gevent.org/intro.html" rel="nofollow">introduction here</a>.</p>
| 1 | 2010-08-10T07:36:57Z | [
"python",
"instant-messaging"
] |
Class Decorators, Inheritance, super(), and maximum recursion | 2,542,747 | <p>I'm trying to figure out how to use decorators on subclasses that use <code>super()</code>. Since my class decorator creates another subclass a decorated class seems to prevent the use of <code>super()</code> when it changes the <code>className</code> passed to <code>super(className, self)</code>. Below is an exampl... | 7 | 2010-03-30T03:42:58Z | 2,542,817 | <p>Are you sure you want to use a class decorator and not simply inheritance? For instance, instead of a decorator to replace your class with a subclass introducing some methods, perhaps you want a mixin class and to use multiple inheritance to create the final class?</p>
<p>This would be accomplished by something lik... | 2 | 2010-03-30T04:06:14Z | [
"python",
"decorator"
] |
Class Decorators, Inheritance, super(), and maximum recursion | 2,542,747 | <p>I'm trying to figure out how to use decorators on subclasses that use <code>super()</code>. Since my class decorator creates another subclass a decorated class seems to prevent the use of <code>super()</code> when it changes the <code>className</code> passed to <code>super(className, self)</code>. Below is an exampl... | 7 | 2010-03-30T03:42:58Z | 2,543,256 | <p>Basically, you can see the problem after entering your code sample at the interactive Python prompt:</p>
<pre><code>>>> SubClassAgain
<class '__main__._DecoratedClass'>
</code></pre>
<p>i.e., the name <code>SubClassAgain</code> is now bound (in global scope, in this case) to a class that in fact <st... | 4 | 2010-03-30T06:36:43Z | [
"python",
"decorator"
] |
Class Decorators, Inheritance, super(), and maximum recursion | 2,542,747 | <p>I'm trying to figure out how to use decorators on subclasses that use <code>super()</code>. Since my class decorator creates another subclass a decorated class seems to prevent the use of <code>super()</code> when it changes the <code>className</code> passed to <code>super(className, self)</code>. Below is an exampl... | 7 | 2010-03-30T03:42:58Z | 2,543,291 | <p>As you might already be aware, the problem arises from the fact that the name <code>SubClassAgain</code> in <code>SubClassAgain.print_class</code> is scoped to the current module's global namespace. <code>SubClassAgain</code> thus refers to the class <code>_DecoratedClass</code> rather than the class that gets decor... | 2 | 2010-03-30T06:45:36Z | [
"python",
"decorator"
] |
Class Decorators, Inheritance, super(), and maximum recursion | 2,542,747 | <p>I'm trying to figure out how to use decorators on subclasses that use <code>super()</code>. Since my class decorator creates another subclass a decorated class seems to prevent the use of <code>super()</code> when it changes the <code>className</code> passed to <code>super(className, self)</code>. Below is an exampl... | 7 | 2010-03-30T03:42:58Z | 2,545,561 | <p>The decorator creates a kind-of diamond inheritance situation. You can avoid these problems by not using <code>super()</code>. Changing <code>SubClassAgain</code> to the following will prevent infinite recursion:</p>
<pre><code>@class_decorator
class SubClassAgain(BaseClass):
def print_class(self):
Base... | 3 | 2010-03-30T13:32:56Z | [
"python",
"decorator"
] |
Class Decorators, Inheritance, super(), and maximum recursion | 2,542,747 | <p>I'm trying to figure out how to use decorators on subclasses that use <code>super()</code>. Since my class decorator creates another subclass a decorated class seems to prevent the use of <code>super()</code> when it changes the <code>className</code> passed to <code>super(className, self)</code>. Below is an exampl... | 7 | 2010-03-30T03:42:58Z | 2,545,579 | <p>How about simply promoting <code>_DecoratedClass</code>'s <code>__bases__</code> up to the <code>__bases__</code> of <code>SubClassAgain</code>?</p>
<pre><code>def class_decorator(cls):
class _DecoratedClass(cls):
def __init__(self):
return super(_DecoratedClass, self).__init__()
_Decora... | 0 | 2010-03-30T13:34:50Z | [
"python",
"decorator"
] |
How do you determine which file is imported in Python with an "import" statement? | 2,542,809 | <p>How do you determine which file is imported in Python with an "import" statement? </p>
<p>I want to determine that I am loading the correct version of a locally modified .py file. Basically the equivalent of "which" in a POSIX environment.</p>
| 4 | 2010-03-30T04:02:18Z | 2,542,833 | <p>I figured it out. Imported modules have a <code>__file__</code> field that is the file that was loaded. Combine that with <code>__import__</code>, I defined a function:</p>
<p><code>which = lambda str : __import__(str).__file__</code>.</p>
| 2 | 2010-03-30T04:11:58Z | [
"python",
"import"
] |
How do you determine which file is imported in Python with an "import" statement? | 2,542,809 | <p>How do you determine which file is imported in Python with an "import" statement? </p>
<p>I want to determine that I am loading the correct version of a locally modified .py file. Basically the equivalent of "which" in a POSIX environment.</p>
| 4 | 2010-03-30T04:02:18Z | 2,542,840 | <p>Look at its <code>__file__</code> attribute.</p>
| 5 | 2010-03-30T04:13:23Z | [
"python",
"import"
] |
How do you determine which file is imported in Python with an "import" statement? | 2,542,809 | <p>How do you determine which file is imported in Python with an "import" statement? </p>
<p>I want to determine that I am loading the correct version of a locally modified .py file. Basically the equivalent of "which" in a POSIX environment.</p>
| 4 | 2010-03-30T04:02:18Z | 2,542,850 | <p>Start python with the <code>-v</code> parameter to enable debugging output. When you then import a module, Python will print out where the module was imported from:</p>
<pre><code>$ python -v
...
>>> import re
# /usr/lib/python2.6/re.pyc matches /usr/lib/python2.6/re.py
import re # precompiled from /usr/li... | 9 | 2010-03-30T04:17:20Z | [
"python",
"import"
] |
How do you determine which file is imported in Python with an "import" statement? | 2,542,809 | <p>How do you determine which file is imported in Python with an "import" statement? </p>
<p>I want to determine that I am loading the correct version of a locally modified .py file. Basically the equivalent of "which" in a POSIX environment.</p>
| 4 | 2010-03-30T04:02:18Z | 2,544,537 | <p>Put an explicit version identifier in each module.</p>
<pre><code>__version__ = "Some.version.String"
</code></pre>
<p>Put these in every module you write, without exception.</p>
<pre><code>import someModule
print someModule.__version__
</code></pre>
<p>This is (a) explicit, (b) easy to manage. You can also use... | 0 | 2010-03-30T10:52:30Z | [
"python",
"import"
] |
What is the most efficient way to populate class attributes with a row from a database query? | 2,542,887 | <p>Looking to have a database query set all the instance variables in a class:</p>
<p>Example:</p>
<pre><code>def populate(self, if):
#Perform mysql query
self._name = row['name']
self._email = row['email']
...
</code></pre>
<p>What's the fastest way to do this? Or is this not recommended (with a b... | 2 | 2010-03-30T04:36:15Z | 2,542,930 | <ul>
<li><p>It makes your code the most readable and predictable to do it manually like this. That way you know exactly what attributes exist and what attributes do not pretty easily.</p></li>
<li><p>You can use <code>setattr</code> to automate tons of these. </p>
<p>One fairly nice way would be to define a list <cod... | 4 | 2010-03-30T04:53:24Z | [
"python",
"pylons",
"mysql"
] |
What is the most efficient way to populate class attributes with a row from a database query? | 2,542,887 | <p>Looking to have a database query set all the instance variables in a class:</p>
<p>Example:</p>
<pre><code>def populate(self, if):
#Perform mysql query
self._name = row['name']
self._email = row['email']
...
</code></pre>
<p>What's the fastest way to do this? Or is this not recommended (with a b... | 2 | 2010-03-30T04:36:15Z | 2,542,932 | <p>Look at <a href="http://www.sqlalchemy.org/" rel="nofollow">sqlalchemy</a> it's the most popular database abstraction for python.<br>
If you really like the active record pattern there is a layer you can put on top of it called <a href="http://elixir.ematia.de/trac/wiki" rel="nofollow">elixir</a>.</p>
<p>I use sqla... | 3 | 2010-03-30T04:53:39Z | [
"python",
"pylons",
"mysql"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 2,543,112 | <p>It is not a Python lib. But <a href="http://ipinfodb.com/">http://ipinfodb.com/</a> provides a webservice that can be easily wrapped by Python code with urllib for example.</p>
<pre><code>http://api.ipinfodb.com/v3/ip-city/?key=<your_api_key>&ip=74.125.45.100
http://api.ipinfodb.com/v3/ip-country/?key=<... | 12 | 2010-03-30T05:55:24Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 2,543,132 | <p><strong><a href="http://www.hostip.info/">Hostip.info</a></strong> is an open-source project with the goal to build/maintain a database <strong><em>mapping IP addresses to cities</em></strong>. Their <em>about</em> page explains the data sources relied on to populate this database.</p>
<p>Using HostIP, there are tw... | 38 | 2010-03-30T05:59:44Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 2,543,677 | <p>You may find these modules useful: <a href="http://www.maxmind.com/app/python">MaxMind's GeoIP</a> and its <a href="http://code.google.com/p/pygeoip/">pure version</a>, as well <a href="http://pytz.sourceforge.net/">pytz</a>.</p>
| 7 | 2010-03-30T08:12:51Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 5,812,108 | <p>I'm using ipinfodb, is free (registration required) and has 2 queries per sec limit and seems to be accurate. </p>
<p>try:</p>
<p><a href="http://api.ipinfodb.com/v3/ip-city/?key=" rel="nofollow">http://api.ipinfodb.com/v3/ip-city/?key=</a>{{API_KEY}}&ip=190.188.221.244&timezone=true</p>
<p>returns:</p>
... | 1 | 2011-04-27T23:58:17Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 9,514,310 | <p>"<em><a href="http://code.google.com/p/geopy/" rel="nofollow">Geopy</a> makes it easy for developers to locate the coordinates of addresses, cities, countries, and landmarks across the globe using third-party geocoders and other data sources, such as wikis.</em></p>
<p><em>geopy currently includes support for six g... | 1 | 2012-03-01T10:13:40Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 26,165,487 | <p>I posted this in another question that had been buried, but linked here: </p>
<pre><code>#!/usr/bin/env python
from urllib2 import urlopen
from contextlib import closing
import json
# Automatically geolocate the connecting IP
url = 'http://freegeoip.net/json/'
try:
with closing(urlopen(url)) as response:
... | 5 | 2014-10-02T16:42:43Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 27,367,390 | <p>Found <a href="https://freegeoip.net/" rel="nofollow">https://freegeoip.net/</a>; python sample below.</p>
<pre><code>import requests
FREEGEOPIP_URL = 'http://freegeoip.net/json/'
SAMPLE_RESPONSE = """{
"ip":"108.46.131.77",
"country_code":"US",
"country_name":"United States",
"region_code":"NY",
... | 3 | 2014-12-08T21:35:11Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 28,165,957 | <p><a href="http://ip-api.com/docs/api:json" rel="nofollow">IP API</a> is also very nice way to do it.</p>
<p><img src="http://i.stack.imgur.com/85xSO.png" alt="enter image description here"></p>
| 3 | 2015-01-27T08:20:41Z | [
"python",
"geolocation",
"timezone"
] |
What python libraries can tell me approximate location and time zone given an IP address? | 2,543,018 | <p>Looking to implement better geo-location with Python.</p>
| 37 | 2010-03-30T05:22:48Z | 37,829,887 | <p>I think <a href="https://freegeoip.net/" rel="nofollow">freegeip</a> is a good option. Below is the Python 3.4.2 code for getting location and time zone. </p>
<pre><code>>>> import requests
>>> ip = '141.70.111.66'
>>> url = 'http://freegeoip.net/json/'+ip
>>> r = requests.get... | 0 | 2016-06-15T08:22:46Z | [
"python",
"geolocation",
"timezone"
] |
python on 32 bit | 2,543,120 | <p>Hi I am running Windows XP, on 32bit. How do I install python? When I run the installation file, it gives me an error saying "installation package not supported by processor type" does python need 64 bit to execute? </p>
| 0 | 2010-03-30T05:56:57Z | 2,543,131 | <p>No it doesn't require 64-bit. The <a href="http://www.python.org/download/" rel="nofollow">download page</a> has both 32-bit and 64-bit downloads.</p>
| 3 | 2010-03-30T05:59:06Z | [
"python",
"windows-xp"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.