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 |
|---|---|---|---|---|---|---|---|---|---|
Find all decorated functions in a module | 2,144,109 | <p>Is it possible to find out if a function is decorated at runtime? For example could I find all functions in a module that are decorated by "example"?</p>
<pre><code>@example
def test1():
print "test1"
</code></pre>
| 5 | 2010-01-27T02:08:29Z | 2,144,135 | <p>In the general case it is not possible because the <code>example</code> decorator might not leave any trace that's detectable at runtime -- for example, it <strong>could</strong> be</p>
<pre><code>def example(f):
return f
</code></pre>
<p>If you do control the source for <code>example</code>, it's of course easy... | 9 | 2010-01-27T02:13:28Z | [
"python"
] |
Find all decorated functions in a module | 2,144,109 | <p>Is it possible to find out if a function is decorated at runtime? For example could I find all functions in a module that are decorated by "example"?</p>
<pre><code>@example
def test1():
print "test1"
</code></pre>
| 5 | 2010-01-27T02:08:29Z | 2,144,140 | <p>I don't think there's a general way since a decorator is a simple function call. Your code is identical to this:</p>
<pre><code>def test1():
print "test1"
test1 = example(test1)
</code></pre>
<p>You could probably detect specific decorators by disassembling and analysing (using the <code>dis</code> module). O... | 3 | 2010-01-27T02:14:20Z | [
"python"
] |
Find all decorated functions in a module | 2,144,109 | <p>Is it possible to find out if a function is decorated at runtime? For example could I find all functions in a module that are decorated by "example"?</p>
<pre><code>@example
def test1():
print "test1"
</code></pre>
| 5 | 2010-01-27T02:08:29Z | 2,144,270 | <p>If you can, monkeypatch the decorator at runtime to catch which functions are being passed to it:</p>
<pre><code>decfuncs = []
def decpatch(dec):
def catchdec(func, *args, **kwargs):
decfuncs.append(func)
return dec(func, *args, **kwargs)
return catchdec
somemodule.somedecorator = decpatch(somemodule.... | -1 | 2010-01-27T02:50:33Z | [
"python"
] |
Find all decorated functions in a module | 2,144,109 | <p>Is it possible to find out if a function is decorated at runtime? For example could I find all functions in a module that are decorated by "example"?</p>
<pre><code>@example
def test1():
print "test1"
</code></pre>
| 5 | 2010-01-27T02:08:29Z | 2,144,413 | <p>Since you have indicated that you are have control of the wrapper code, here is a simple example</p>
<pre><code>def example(f):
f.wrapped=True
return f
@example
def test1():
print "test1"
def test2():
print "test2"
print test1.wrapped
print hasattr(test2, 'wrapped')
</code></pre>
| 7 | 2010-01-27T03:36:07Z | [
"python"
] |
Find all decorated functions in a module | 2,144,109 | <p>Is it possible to find out if a function is decorated at runtime? For example could I find all functions in a module that are decorated by "example"?</p>
<pre><code>@example
def test1():
print "test1"
</code></pre>
| 5 | 2010-01-27T02:08:29Z | 5,917,845 | <p>You may find this recent question provides detailed information on 3 ways to do this:</p>
<p><a href="http://stackoverflow.com/q/5910703/711085">Howto get all methods of a python class with given decorator</a></p>
| 0 | 2011-05-06T22:54:10Z | [
"python"
] |
I'm using Hadoop for data processing with python, what file format should be used? | 2,144,171 | <p>I'm using Hadoop for data processing with python, what file format should be used?</p>
<p>I have project with a substantial amount of text pages.</p>
<p>Each text file has some header information that I need to preserve during the processing; however, I don't want the headers to interfere with the clustering algor... | 3 | 2010-01-27T02:21:22Z | 2,144,277 | <p>1) Files</p>
<p>If you use Hadoop Streaming, you have to use line-based text-files, data up to the first tab is passed to your mapper as key.</p>
<p>Just look at <a href="http://hadoop.apache.org/common/docs/r0.20.1/streaming.html" rel="nofollow">the documentation</a> for streaming.</p>
<p>You can also put you in... | 4 | 2010-01-27T02:52:12Z | [
"python",
"hadoop"
] |
I'm using Hadoop for data processing with python, what file format should be used? | 2,144,171 | <p>I'm using Hadoop for data processing with python, what file format should be used?</p>
<p>I have project with a substantial amount of text pages.</p>
<p>Each text file has some header information that I need to preserve during the processing; however, I don't want the headers to interfere with the clustering algor... | 3 | 2010-01-27T02:21:22Z | 2,149,550 | <p>If you're using Hadoop Streaming, your input can be in any line-based format; your mapper and reducer input comes from sys.stdin, which you read any way you want. You don't need to use the default tab-deliminated fields (although in my experience, one format should be used among all tasks for consistency when possi... | 1 | 2010-01-27T19:00:30Z | [
"python",
"hadoop"
] |
How can I access the current URI in python's mako templating system? | 2,144,284 | <p>I'd like to submit the form to the current URI, like this:</p>
<pre><code><form action="${CURRENT_URI}" method="post">
<input type="text" name="email" />
</form>
</code></pre>
<p>from within a mako template. But I am not sure what variable holds the current uri information. </p>
<p>Thanks.</p>
| 1 | 2010-01-27T02:55:29Z | 2,144,591 | <p>Actually, you don't need it. </p>
<pre><code><form action="" method="post">
<input type="text" name="email" />
</form>
</code></pre>
<p>If you leave the action empty, it will be posted to the current url.</p>
<p>However, if you need the current url for some other reason, it can be retrieved by c... | 1 | 2010-01-27T04:34:03Z | [
"python",
"pylons",
"mako"
] |
what is {% trans "This is the title." %} used for,i can't understand the api | 2,144,319 | <p>i know the {% trans %} is for translation,</p>
<p>and how can i translate {% trans "This is the title." %} to chinese.</p>
<p>thanks</p>
<hr>
<pre><code>D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm
in.py compilemessages
processing file django.po in D:\zjm_code\register2\... | 2 | 2010-01-27T03:06:12Z | 2,144,333 | <p><a href="http://docs.djangoproject.com/en/dev/topics/i18n/#topics-i18n" rel="nofollow">I18n in Django</a></p>
| 1 | 2010-01-27T03:09:04Z | [
"python",
"django"
] |
what is {% trans "This is the title." %} used for,i can't understand the api | 2,144,319 | <p>i know the {% trans %} is for translation,</p>
<p>and how can i translate {% trans "This is the title." %} to chinese.</p>
<p>thanks</p>
<hr>
<pre><code>D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm
in.py compilemessages
processing file django.po in D:\zjm_code\register2\... | 2 | 2010-01-27T03:06:12Z | 2,144,442 | <p>You don't follow the documentation?</p>
<p>3 steps:</p>
<ol>
<li><p>Add <code>{% load i18n %}</code> in the template (as MichaÅ LudwiÅski says). Put the <code>{% trans %}</code> in your templates, or <code>_</code> in python code, etc.</p></li>
<li><p>Build a translation dictionary:</p>
<ul>
<li><p>Run <code>dj... | 4 | 2010-01-27T03:48:51Z | [
"python",
"django"
] |
what is {% trans "This is the title." %} used for,i can't understand the api | 2,144,319 | <p>i know the {% trans %} is for translation,</p>
<p>and how can i translate {% trans "This is the title." %} to chinese.</p>
<p>thanks</p>
<hr>
<pre><code>D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm
in.py compilemessages
processing file django.po in D:\zjm_code\register2\... | 2 | 2010-01-27T03:06:12Z | 2,144,448 | <p>before you will try to use {% trans %} blocktag you need to type</p>
<pre><code>{% load i18n %}
</code></pre>
<p>then you can use the tag to type in the text you want to be translated (one thing is important - the text ought to be in main project language which is set in settings)</p>
<p>if you have already some ... | 3 | 2010-01-27T03:51:51Z | [
"python",
"django"
] |
assigning points to bins | 2,144,443 | <p>What is a good way to bin numerical values into a certain range? For example, suppose I have a list of values and I want to bin them into N bins by their range. Right now, I do something like this:</p>
<pre><code>from scipy import *
num_bins = 3 # number of bins to use
values = # some array of integers...
min_val ... | 4 | 2010-01-27T03:49:16Z | 2,144,477 | <p><code>numpy.histogram()</code> does exactly what you want.</p>
<p>The function signature is:</p>
<pre><code>numpy.histogram(a, bins=10, range=None, normed=False, weights=None, new=None)
</code></pre>
<p>We're mostly interested in <code>a</code> and <code>bins</code>. <code>a</code> is the input data that needs t... | 12 | 2010-01-27T03:59:54Z | [
"python",
"numpy",
"scipy",
"binning"
] |
assigning points to bins | 2,144,443 | <p>What is a good way to bin numerical values into a certain range? For example, suppose I have a list of values and I want to bin them into N bins by their range. Right now, I do something like this:</p>
<pre><code>from scipy import *
num_bins = 3 # number of bins to use
values = # some array of integers...
min_val ... | 4 | 2010-01-27T03:49:16Z | 2,170,025 | <p>This is fairly straightforward in numpy using broadcasting--my example below is four lines of code (not counting first two lines to create bins and data points, which would of course ordinarily be supplied.) </p>
<pre><code>import numpy as NP
# just creating 5 bins at random, each bin expressed as (x, y, z) alth... | 1 | 2010-01-31T00:08:56Z | [
"python",
"numpy",
"scipy",
"binning"
] |
my pythonpath has 'register2',why i can't import it | 2,144,451 | <pre><code>import sys
print sys.path
['D:\\zjm_code\\register2', 'C:\\WINDOWS\\system32\\python25.zip', 'D:\\Python25\\DLLs', 'D:\\Python25\\lib', 'D:\\Python25\\lib\\plat-win', 'D:\\Python25\\lib\\lib-tk', 'D:\\Python25', 'D:\\Python25\\lib\\site-packages']
</code></pre>
<p>and </p>
<pre><code>#from django.core.man... | 1 | 2010-01-27T03:52:30Z | 2,144,486 | <p>When directory <code>'D:\\zjm_code\\register2'</code> is on <code>sys.path</code>, this means you can import modules and packages that are <strong>INSIDE</strong> that directory.</p>
<p>To import the directory <code>register2</code> itself, two conditions:</p>
<ol>
<li>its <strong>parent</strong>, <code>'D:\\zjm_c... | 5 | 2010-01-27T04:01:32Z | [
"python",
"django"
] |
my pythonpath has 'register2',why i can't import it | 2,144,451 | <pre><code>import sys
print sys.path
['D:\\zjm_code\\register2', 'C:\\WINDOWS\\system32\\python25.zip', 'D:\\Python25\\DLLs', 'D:\\Python25\\lib', 'D:\\Python25\\lib\\plat-win', 'D:\\Python25\\lib\\lib-tk', 'D:\\Python25', 'D:\\Python25\\lib\\site-packages']
</code></pre>
<p>and </p>
<pre><code>#from django.core.man... | 1 | 2010-01-27T03:52:30Z | 2,144,493 | <p>lol because it tries to import something from register2 but it cannot since there isn't D:\zjm_code on the path..</p>
| 0 | 2010-01-27T04:03:46Z | [
"python",
"django"
] |
Why can't I use 'django-admin.py makemessages -l cn' | 2,144,503 | <p>print :</p>
<pre><code>D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm
in.py makemessages -l cn
Error: This script should be run from the Django SVN tree or your project or app
tree. If you did indeed run it from the SVN checkout or your project or applica
tion, maybe you are ju... | 7 | 2010-01-27T04:06:27Z | 2,144,521 | <ol>
<li>is <code>register2</code> your project or app tree?</li>
<li>did you make directory <code>register2\\locale</code>?</li>
</ol>
| 8 | 2010-01-27T04:13:16Z | [
"python",
"django"
] |
best way to add file way to my pythpath.which can be saved | 2,144,530 | <pre><code>import sys
print sys.path
sys.path+=['D:\\zjm_code']
print sys.path
</code></pre>
<p>it can't be save,how does do it.</p>
| 1 | 2010-01-27T04:15:03Z | 2,144,537 | <p>you can use append()</p>
<pre><code>import sys
sys.path.append("/mypath")
</code></pre>
<p>to save it permanently, you can export PYTHONPATH in the user shell initialization file (eg .bash_profile)</p>
<pre><code>PYTHONPATH=/path/to/module/directory:/path/to/module2/dir2
</code></pre>
<p>on Windows systems, you ... | 0 | 2010-01-27T04:17:46Z | [
"python"
] |
best way to add file way to my pythpath.which can be saved | 2,144,530 | <pre><code>import sys
print sys.path
sys.path+=['D:\\zjm_code']
print sys.path
</code></pre>
<p>it can't be save,how does do it.</p>
| 1 | 2010-01-27T04:15:03Z | 2,144,547 | <p>Where is environment variable <code>PYTHONPATH</code> defined in your working environment?</p>
<p>In Unix-like systems it would be in a bash script such as <code>~/.bashrc</code>.</p>
<p>In Windows it could be a <code>.BAT</code> or <code>.CMD</code> file but more often will be in the registry.</p>
<p>"Saving" a ... | 2 | 2010-01-27T04:19:56Z | [
"python"
] |
Python C interoperability | 2,144,542 | <p>I wish to wrap an existing C (pure C that is. No C++) library into Python so that I can call it from Python scripts. Which approach among the various available (C Api, SWIG etc.) would be the most suitable?</p>
| 2 | 2010-01-27T04:18:49Z | 2,144,549 | <p>SWIG is great for doing this. Here is a sample tutorial: <a href="http://www.swig.org/Doc1.3/Python.html" rel="nofollow">http://www.swig.org/Doc1.3/Python.html</a>.</p>
| 4 | 2010-01-27T04:20:44Z | [
"python",
"c",
"interop"
] |
Python C interoperability | 2,144,542 | <p>I wish to wrap an existing C (pure C that is. No C++) library into Python so that I can call it from Python scripts. Which approach among the various available (C Api, SWIG etc.) would be the most suitable?</p>
| 2 | 2010-01-27T04:18:49Z | 2,144,563 | <p>go with Ctypes, it is part of standard distribution and works very well.
basically you can wrap C structures and types in python classes, as well as functions. Some types and functionality is already provided by library. </p>
<p><a href="http://docs.python.org/library/ctypes.html" rel="nofollow">ctypes</a></p>
<p>... | 7 | 2010-01-27T04:24:56Z | [
"python",
"c",
"interop"
] |
Python C interoperability | 2,144,542 | <p>I wish to wrap an existing C (pure C that is. No C++) library into Python so that I can call it from Python scripts. Which approach among the various available (C Api, SWIG etc.) would be the most suitable?</p>
| 2 | 2010-01-27T04:18:49Z | 2,144,794 | <p>Since your code is "pure" C you might consider using <a href="http://wiki.python.org/moin/Pyrex" rel="nofollow">Pyrex</a>/Cython. This is not a voting issue and Cython has already been mentioned. I am just clarifying why it is a better choice for pure C.</p>
| 0 | 2010-01-27T05:37:59Z | [
"python",
"c",
"interop"
] |
Nested Choices in a python program | 2,144,630 | <p>I have a script that I wrote in python for testing out the sorting algorithms that I've implemented. The main part of the program asks the user to select on of the sort algorithms from a list. And then whether they would like to sort from a file of numbers or select a list of random numbers. I have it setup (i think... | 1 | 2010-01-27T04:44:40Z | 2,144,650 | <p>use raw_input()</p>
<pre><code>def fileOrRandom():
return raw_input("Would you like to read from file or random list? (A or B): ")
</code></pre>
<p>your while loop should look like this (after fixing the indentation)</p>
<pre><code>while True :
choice=raw_input("Your choice: ")
for i in range(2):
i... | 0 | 2010-01-27T04:50:46Z | [
"python",
"nested",
"options"
] |
Is it safe to use sys.platform=='win32' check on 64-bit Python? | 2,144,748 | <p>The usual check to differentiate between running Python-application on Windows and on other OSes (Linux typically) is to use conditional:</p>
<pre><code>if sys.platform == 'win32':
...
</code></pre>
<p>But I wonder is it safe to use today when 64-bit Python is more widely used in last years? Does 32 really mea... | 32 | 2010-01-27T05:21:53Z | 2,144,764 | <p>The caveats for Windows/32 and Windows/64 are the same, so they should use the same value. The only difference would be in e.g. <code>sys.maxint</code> and <code>ctypes</code>. If you need to distinguish between 32 and 64 regardless then <code>platform</code> is your best bet.</p>
| 1 | 2010-01-27T05:26:33Z | [
"python",
"windows",
"64bit",
"cross-platform",
"32bit-64bit"
] |
Is it safe to use sys.platform=='win32' check on 64-bit Python? | 2,144,748 | <p>The usual check to differentiate between running Python-application on Windows and on other OSes (Linux typically) is to use conditional:</p>
<pre><code>if sys.platform == 'win32':
...
</code></pre>
<p>But I wonder is it safe to use today when 64-bit Python is more widely used in last years? Does 32 really mea... | 32 | 2010-01-27T05:21:53Z | 2,144,990 | <p>Personally I use <a href="http://code.google.com/p/platinfo/" rel="nofollow">platinfo</a> for detecting the underlying platform.</p>
<pre><code>>>> from platinfo import PlatInfo
>>> pi = PlatInfo()
>>> pi.os
'win64'
>>> pi.arch
'x64'
>>> pi.name()
'win64-x64'
</code></pr... | 1 | 2010-01-27T06:32:06Z | [
"python",
"windows",
"64bit",
"cross-platform",
"32bit-64bit"
] |
Is it safe to use sys.platform=='win32' check on 64-bit Python? | 2,144,748 | <p>The usual check to differentiate between running Python-application on Windows and on other OSes (Linux typically) is to use conditional:</p>
<pre><code>if sys.platform == 'win32':
...
</code></pre>
<p>But I wonder is it safe to use today when 64-bit Python is more widely used in last years? Does 32 really mea... | 32 | 2010-01-27T05:21:53Z | 2,145,582 | <p><code>sys.platform</code> will be <code>win32</code> regardless of the bitness of the underlying Windows system, as you can see in <code>PC/pyconfig.h</code> (from the Python 2.6 source distribution):</p>
<pre><code>#if defined(MS_WIN64)
/* maintain "win32" sys.platform for backward compatibility of Python code,
... | 27 | 2010-01-27T09:07:15Z | [
"python",
"windows",
"64bit",
"cross-platform",
"32bit-64bit"
] |
Is it safe to use sys.platform=='win32' check on 64-bit Python? | 2,144,748 | <p>The usual check to differentiate between running Python-application on Windows and on other OSes (Linux typically) is to use conditional:</p>
<pre><code>if sys.platform == 'win32':
...
</code></pre>
<p>But I wonder is it safe to use today when 64-bit Python is more widely used in last years? Does 32 really mea... | 32 | 2010-01-27T05:21:53Z | 3,626,273 | <p>Notice that you cannot use either <code>sys.platform</code> or <code>os.name</code> for this on Jython:</p>
<pre><code>$ jython -c "import sys, os; print sys.platform; print os.name"
java1.6.0_20
java
</code></pre>
<p>I think there's a plan in Jython project to change <code>os.name</code> to report the underlying ... | 3 | 2010-09-02T10:37:36Z | [
"python",
"windows",
"64bit",
"cross-platform",
"32bit-64bit"
] |
How to know the encoding of a file in Python? | 2,144,815 | <p>Does anybody know how to get the encoding of a file in Python. I know that you can use the codecs module to open a file with a specific encoding but you have to know it in advance.</p>
<pre><code>import codecs
f = codecs.open("file.txt", "r", "utf-8")
</code></pre>
<p>Is there a way to detect automatically which e... | 15 | 2010-01-27T05:46:09Z | 2,144,833 | <p>You may use BOM (<a href="http://en.wikipedia.org/wiki/Byte_order_mark" rel="nofollow" title="BOM">http://en.wikipedia.org/wiki/Byte_order_mark</a>) to detect the encoding, or try this library:</p>
<p><a href="https://github.com/chardet/chardet" rel="nofollow">https://github.com/chardet/chardet</a></p>
| 6 | 2010-01-27T05:52:06Z | [
"python",
"encoding",
"character-encoding"
] |
How to know the encoding of a file in Python? | 2,144,815 | <p>Does anybody know how to get the encoding of a file in Python. I know that you can use the codecs module to open a file with a specific encoding but you have to know it in advance.</p>
<pre><code>import codecs
f = codecs.open("file.txt", "r", "utf-8")
</code></pre>
<p>Is there a way to detect automatically which e... | 15 | 2010-01-27T05:46:09Z | 2,144,852 | <p>Unfortunately there is no 'correct' way to determine the encoding of a file by looking at the file itself. This is a universal problem, not limited to python or any particular file system.</p>
<p>If you're reading an XML file, the first line in the file <em>might</em> give you a hint of what the encoding is.</p>
<... | 17 | 2010-01-27T05:58:05Z | [
"python",
"encoding",
"character-encoding"
] |
How to know the encoding of a file in Python? | 2,144,815 | <p>Does anybody know how to get the encoding of a file in Python. I know that you can use the codecs module to open a file with a specific encoding but you have to know it in advance.</p>
<pre><code>import codecs
f = codecs.open("file.txt", "r", "utf-8")
</code></pre>
<p>Is there a way to detect automatically which e... | 15 | 2010-01-27T05:46:09Z | 2,159,245 | <p>There is <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Beautiful%20Soup%20Gives%20You%20Unicode,%20Dammit" rel="nofollow">Unicode Dammit</a> from <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>, which uses <a href="https://pypi.python.org/pypi/char... | 2 | 2010-01-29T01:07:43Z | [
"python",
"encoding",
"character-encoding"
] |
How to know the encoding of a file in Python? | 2,144,815 | <p>Does anybody know how to get the encoding of a file in Python. I know that you can use the codecs module to open a file with a specific encoding but you have to know it in advance.</p>
<pre><code>import codecs
f = codecs.open("file.txt", "r", "utf-8")
</code></pre>
<p>Is there a way to detect automatically which e... | 15 | 2010-01-27T05:46:09Z | 9,600,161 | <p>Here is a small snippet to help you to guess the encoding. It guesses between latin1 and utf8 quite good. It converts a byte string to a unicode string.</p>
<pre><code># Attention: Order of encoding_guess_list is import. Example: "latin1" always succeeds.
encoding_guess_list=['utf8', 'latin1']
def try_unicode(strin... | 3 | 2012-03-07T10:57:41Z | [
"python",
"encoding",
"character-encoding"
] |
sqlite python insert with where condition | 2,144,840 | <p>from this post <a href="http://stackoverflow.com/questions/2130641/sqlite-python-insert">http://stackoverflow.com/questions/2130641/sqlite-python-insert</a> I learned inserting into tables but now I need to use where something like</p>
<p>cursor.execute("insert into table1(id) values (?) where ip=? and address=?",(... | 2 | 2010-01-27T05:54:56Z | 2,144,849 | <p>INSERT does not have a WHERE clause. I think you mean UPDATE.</p>
| 4 | 2010-01-27T05:57:27Z | [
"python",
"sqlite",
"insert"
] |
sqlite python insert with where condition | 2,144,840 | <p>from this post <a href="http://stackoverflow.com/questions/2130641/sqlite-python-insert">http://stackoverflow.com/questions/2130641/sqlite-python-insert</a> I learned inserting into tables but now I need to use where something like</p>
<p>cursor.execute("insert into table1(id) values (?) where ip=? and address=?",(... | 2 | 2010-01-27T05:54:56Z | 2,144,855 | <p>You can't use a <code>WHERE</code> clause in an <code>INSERT</code>. If you want to specify the values for particular fields to insert, put them in the values clause:</p>
<pre><code>cursor.execute("INSERT INTO table1(id, ip, address) VALUES (?, ?, ?)", (id, ip, addr))
</code></pre>
| 0 | 2010-01-27T05:58:20Z | [
"python",
"sqlite",
"insert"
] |
Using Django, why would REMOTE_ADDR return 127.0.0.1 on a web server? | 2,144,848 | <p>When getting the IP with <code>request.META['REMOTE_ADDR']</code> code. This works fine on the local system but when hosted on a web server the ip got is 127.0.0.1 - How can this be resolved?</p>
| 7 | 2010-01-27T05:57:21Z | 2,144,938 | <p>Your web server is probably behind a load balancer. You can try using request.META['HTTP_X_FORWARDED_FOR'].</p>
<p>Or better, look at the <a href="http://www.djangobook.com/en/1.0/chapter15/">django book, chapter 15</a> - <em>Whatâs Middleware?</em> and <em>Reverse Proxy Support (X-Forwarded-For Middleware)</em> ... | 9 | 2010-01-27T06:17:52Z | [
"python",
"django"
] |
Using Django, why would REMOTE_ADDR return 127.0.0.1 on a web server? | 2,144,848 | <p>When getting the IP with <code>request.META['REMOTE_ADDR']</code> code. This works fine on the local system but when hosted on a web server the ip got is 127.0.0.1 - How can this be resolved?</p>
| 7 | 2010-01-27T05:57:21Z | 2,315,308 | <p>If you are behind a proxy and running apache as the webserver you could use mod_rpaf. The proxy only needs to send X-Forwarded-For or X-Real-IP headers.</p>
<p><a href="http://stderr.net/apache/rpaf/" rel="nofollow">http://stderr.net/apache/rpaf/</a></p>
| 2 | 2010-02-23T00:22:20Z | [
"python",
"django"
] |
Python: multiple calls to __init__() on the same instance | 2,144,988 | <p>The <code>__init__()</code> function gets called when object is created.
Is it ok to call an object <code>__init__()</code> function again, after its been created?</p>
<pre><code>instance = cls(p1=1, p2=2)
# some code
instance.__init__(p1=123, p2=234)
# some more code
instance.__init__(p1=23, p2=24)
</code></pre>
... | 9 | 2010-01-27T06:31:45Z | 2,145,009 | <p>As far as I know, it does not cause any problems (<em>edit:</em> as suggested by the kosher usage of <code>super(...).__init__(...)</code>), but I think having a <code>reset()</code> method and calling it both in <code>__init__()</code> and when you need to reset would be cleaner.</p>
| 1 | 2010-01-27T06:36:36Z | [
"python",
"initialization"
] |
Python: multiple calls to __init__() on the same instance | 2,144,988 | <p>The <code>__init__()</code> function gets called when object is created.
Is it ok to call an object <code>__init__()</code> function again, after its been created?</p>
<pre><code>instance = cls(p1=1, p2=2)
# some code
instance.__init__(p1=123, p2=234)
# some more code
instance.__init__(p1=23, p2=24)
</code></pre>
... | 9 | 2010-01-27T06:31:45Z | 2,145,048 | <p>It's fine to call <code>__init__</code> more than once on an object, as long as <code>__init__</code> is coded with the effect you want to obtain (whatever that may be). A typical case where it happens (so you'd better code <code>__init__</code> appropriately!-) is when your class's <code>__new__</code> method retu... | 9 | 2010-01-27T06:48:39Z | [
"python",
"initialization"
] |
Python: multiple calls to __init__() on the same instance | 2,144,988 | <p>The <code>__init__()</code> function gets called when object is created.
Is it ok to call an object <code>__init__()</code> function again, after its been created?</p>
<pre><code>instance = cls(p1=1, p2=2)
# some code
instance.__init__(p1=123, p2=234)
# some more code
instance.__init__(p1=23, p2=24)
</code></pre>
... | 9 | 2010-01-27T06:31:45Z | 2,145,077 | <p>You can, but it's kind of breaking what <code>__init__</code> is intended to do. A lot of Python is really just convention, so you might as well follow then and expect <code>__init__</code> to only be called once. I'd recommend creating a function called <code>init</code> or <code>reset</code> or something which set... | 3 | 2010-01-27T06:58:24Z | [
"python",
"initialization"
] |
Have a Python CGI call a Perl CGI, passing original info (to limit searching private Mailman archives to logged-in users) | 2,145,097 | <p>I need to have a Python CGI script do some stuff (a little bit of security checking), and then end up calling a Perl CGI script, passing anything it received (e.g., POST info) onto the Perl script.</p>
<p>For background, my reason for doing this is that I'm trying to integrate Swish searching with Mailman list arch... | 1 | 2010-01-27T07:06:25Z | 2,145,328 | <p>I'm just going to state the obvious here because I don't have any detailed knowledge about your specific environment.</p>
<p>If your python script is a genuine CGI and not a mod_python script or similar then it is just a regular process spawned to handle the one request. You can use <code>os.execv</code> to replace... | 1 | 2010-01-27T08:14:51Z | [
"python",
"cgi",
"mailman"
] |
Is this a memory leak ( a program in python with sqlalchemy/sqlite) | 2,145,177 | <p>I have the following code runs over a large set of data (2M). It eats up all my 4G mem before finishing.</p>
<pre><code> for sample in session.query(CodeSample).yield_per(100):
for proj in projects:
if sample.filename.startswith(proj.abs_source):
sample... | 3 | 2010-01-27T07:29:44Z | 2,145,245 | <p>The session will keep track of all the <code>CodeSample</code> objects that you retrieve. So after iterating over 2M objects, the session keeps a reference to all of them. The session needs these references so it can write the correct changes to the database on <code>flush</code>. So I believe what you're seeing is ... | 1 | 2010-01-27T07:48:51Z | [
"python",
"memory",
"sqlalchemy",
"memory-leaks"
] |
Is this a memory leak ( a program in python with sqlalchemy/sqlite) | 2,145,177 | <p>I have the following code runs over a large set of data (2M). It eats up all my 4G mem before finishing.</p>
<pre><code> for sample in session.query(CodeSample).yield_per(100):
for proj in projects:
if sample.filename.startswith(proj.abs_source):
sample... | 3 | 2010-01-27T07:29:44Z | 2,157,879 | <p>Most DBAPIs, including psycopg2 and mysql-python, fully load all results into memory before releasing them to the client. SQLA's yield_per() option doesn't work around this, with one exception below, which is why its generally not a very useful option(edit: useful in the sense that it begins streaming results befo... | 5 | 2010-01-28T20:56:38Z | [
"python",
"memory",
"sqlalchemy",
"memory-leaks"
] |
Archiving (tar and compress) with metadata (user id, and ctime) in Python | 2,145,182 | <p>I am in the process of backing up a filesystem and I need to make sure that the metadata is conserved (the file owner and creation time). </p>
<p>The <code>tarfile</code> module in Python is really helpful, and I use it extensively in my solution. However, I cannot create the tar file with files conserving their me... | 1 | 2010-01-27T07:30:41Z | 2,145,233 | <p>"Presumably"? You mean you don't know? Have you <em>tried</em>? That said, as far as I know, tarfiles doesn't preserve ctime, and there would be little point in it, as ctime should be reset when you unpack. mtime is preserved, though, and the tarfile module handles mtime.</p>
<p>The python tarfile module uses TarIn... | 2 | 2010-01-27T07:45:20Z | [
"python",
"backup",
"metadata",
"tar",
"archiving"
] |
How can I run Python code on a windows system? | 2,145,232 | <p>I am used to using PHP and it is easy to set up, I can just run an exe package like Xampp and have apache and PHP running in 5 minutes on my windows system. Is there something similar to Python?</p>
| 2 | 2010-01-27T07:45:12Z | 2,145,252 | <p>Yes, you can find python from <a href="http://python.org" rel="nofollow">http://python.org</a></p>
<p>and If you like to make executable files from .py source file you may use <a href="http://py2exe.org" rel="nofollow">py2exe</a></p>
| 1 | 2010-01-27T07:50:23Z | [
"python",
"windows"
] |
How can I run Python code on a windows system? | 2,145,232 | <p>I am used to using PHP and it is easy to set up, I can just run an exe package like Xampp and have apache and PHP running in 5 minutes on my windows system. Is there something similar to Python?</p>
| 2 | 2010-01-27T07:45:12Z | 2,145,253 | <p>Download python installer and run python.</p>
| 0 | 2010-01-27T07:50:33Z | [
"python",
"windows"
] |
How can I run Python code on a windows system? | 2,145,232 | <p>I am used to using PHP and it is easy to set up, I can just run an exe package like Xampp and have apache and PHP running in 5 minutes on my windows system. Is there something similar to Python?</p>
| 2 | 2010-01-27T07:45:12Z | 2,145,254 | <p>Unlike PHP, Python's primary purpose is a general-purpose tool for running on the desktop/server, not necessarily as a web application. It has bindings to many powerful GUI toolkits (<code>Qt</code> and <code>wx</code> are two examples of free and popular toolkits that work great on Windows), and so on. Therefore yo... | 6 | 2010-01-27T07:50:36Z | [
"python",
"windows"
] |
How can I run Python code on a windows system? | 2,145,232 | <p>I am used to using PHP and it is easy to set up, I can just run an exe package like Xampp and have apache and PHP running in 5 minutes on my windows system. Is there something similar to Python?</p>
| 2 | 2010-01-27T07:45:12Z | 2,145,268 | <p>Nope no easy way out for you yet, Python is obviously not popular enough in Web dev. You should install mod_python and django. There are some nice step <a href="http://woommle.org/?p=21" rel="nofollow">here</a>.</p>
| 0 | 2010-01-27T07:53:06Z | [
"python",
"windows"
] |
How can I run Python code on a windows system? | 2,145,232 | <p>I am used to using PHP and it is easy to set up, I can just run an exe package like Xampp and have apache and PHP running in 5 minutes on my windows system. Is there something similar to Python?</p>
| 2 | 2010-01-27T07:45:12Z | 2,145,311 | <p>You don't say in your question what you are going to use Python <em>for</em>, so most answers above are completely correct in pointing out that you install Python by downloading it from Python.org. But you seem to expect more. Is it correct to assume you are going to use it to do web development?</p>
<p>In that cas... | 1 | 2010-01-27T08:03:09Z | [
"python",
"windows"
] |
How can I run Python code on a windows system? | 2,145,232 | <p>I am used to using PHP and it is easy to set up, I can just run an exe package like Xampp and have apache and PHP running in 5 minutes on my windows system. Is there something similar to Python?</p>
| 2 | 2010-01-27T07:45:12Z | 2,152,207 | <p>Here's my opinionated answer:</p>
<ol>
<li><p>Download and install <a href="http://www.activestate.com/activepython/" rel="nofollow">ActivePython</a></p></li>
<li><p>Open Command Prompt and type <code>pypm install django</code></p></li>
<li><p>Follow the <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial0... | 1 | 2010-01-28T03:57:58Z | [
"python",
"windows"
] |
Python / Django: Is it wise to use "Item" as a class name in Python (in Django in this case)? | 2,145,282 | <p>I'm creating this:</p>
<pre><code># models.py
class Item(models.Model):
sku = models.CharField(max_length=20)
class Attribute(models.Model):
item = models.ForeignKey(Item, related_name='items')
</code></pre>
<p>Is that going to cause naming collisions in Python? Like:</p>
<pre><code># views.py
some_obj... | 1 | 2010-01-27T07:56:11Z | 2,145,305 | <p>It does seem a bit generic, but no more so than "Attribute". I would give it a prefix based on the app if possible.</p>
| 3 | 2010-01-27T08:01:24Z | [
"python",
"django",
"naming-conventions",
"naming"
] |
Python / Django: Is it wise to use "Item" as a class name in Python (in Django in this case)? | 2,145,282 | <p>I'm creating this:</p>
<pre><code># models.py
class Item(models.Model):
sku = models.CharField(max_length=20)
class Attribute(models.Model):
item = models.ForeignKey(Item, related_name='items')
</code></pre>
<p>Is that going to cause naming collisions in Python? Like:</p>
<pre><code># views.py
some_obj... | 1 | 2010-01-27T07:56:11Z | 2,145,306 | <p>It's really not a problem. If you have some random object and feel 'items' is a suitable name for a method, then go ahead. It is not going to cause any collisions with names that happen to be used on other objects.</p>
<p>As long as you think the method name is not misleading and does not cause confusion, go ahead.... | 2 | 2010-01-27T08:01:34Z | [
"python",
"django",
"naming-conventions",
"naming"
] |
Python / Django: Is it wise to use "Item" as a class name in Python (in Django in this case)? | 2,145,282 | <p>I'm creating this:</p>
<pre><code># models.py
class Item(models.Model):
sku = models.CharField(max_length=20)
class Attribute(models.Model):
item = models.ForeignKey(Item, related_name='items')
</code></pre>
<p>Is that going to cause naming collisions in Python? Like:</p>
<pre><code># views.py
some_obj... | 1 | 2010-01-27T07:56:11Z | 2,145,322 | <p>A model isn't the same thing as a queryset, and neither of them is documented as being dict-like. There shouldn't be any problem with doing this.</p>
<p>If you are really worried, then make as much of this code public as possible, and get people using it :) If nothing else, the Django core team is really diligent a... | 2 | 2010-01-27T08:07:13Z | [
"python",
"django",
"naming-conventions",
"naming"
] |
Python / Django: Is it wise to use "Item" as a class name in Python (in Django in this case)? | 2,145,282 | <p>I'm creating this:</p>
<pre><code># models.py
class Item(models.Model):
sku = models.CharField(max_length=20)
class Attribute(models.Model):
item = models.ForeignKey(Item, related_name='items')
</code></pre>
<p>Is that going to cause naming collisions in Python? Like:</p>
<pre><code># views.py
some_obj... | 1 | 2010-01-27T07:56:11Z | 2,145,519 | <p>go with default item_set, problem-free :)</p>
| 1 | 2010-01-27T08:51:52Z | [
"python",
"django",
"naming-conventions",
"naming"
] |
Can Moblin run (and compile) Python scripts? | 2,145,334 | <p>I want to develop an app for Moblin for a competition.</p>
<p>The development environment needed by Moblin is too complicated to setup. It uses Anjuta as its IDE, but I could never make sense of the entire compilation toolchain.</p>
<p>However, I would like to know if Moblin could compile and run Python scripts. I... | 1 | 2010-01-27T08:16:47Z | 2,145,352 | <p>It does not need to compile them, as it contains a Python interpreter already.</p>
| 0 | 2010-01-27T08:20:50Z | [
"python",
"development-environment"
] |
Reduce strings in python to a specific point | 2,145,371 | <p>I have strings in my python application that look this way:</p>
<pre><code>test1/test2/foo/
</code></pre>
<p>Everytime I get such a string, I want to reduce it, beginning from the tail and reduced until the fist "/" is reached.</p>
<pre><code>test1/test2/
</code></pre>
<p>More examples:</p>
<pre><code>foo/foo/f... | 1 | 2010-01-27T08:24:13Z | 2,145,377 | <p><a href="http://docs.python.org/library/stdtypes.html#str.rsplit" rel="nofollow"><code>str.rsplit()</code></a> with the <code>maxsplit</code> argument. Or if this is a path, look in <code>os.path</code> or <code>urlparse</code>.</p>
| 5 | 2010-01-27T08:25:53Z | [
"python",
"string",
"path"
] |
Reduce strings in python to a specific point | 2,145,371 | <p>I have strings in my python application that look this way:</p>
<pre><code>test1/test2/foo/
</code></pre>
<p>Everytime I get such a string, I want to reduce it, beginning from the tail and reduced until the fist "/" is reached.</p>
<pre><code>test1/test2/
</code></pre>
<p>More examples:</p>
<pre><code>foo/foo/f... | 1 | 2010-01-27T08:24:13Z | 2,145,384 | <pre><code> newString = oldString[:oldString[:-1].rfind('/')]
# strip out trailing slash ----^ ^---- find last remaining slash
</code></pre>
| 5 | 2010-01-27T08:27:10Z | [
"python",
"string",
"path"
] |
Reduce strings in python to a specific point | 2,145,371 | <p>I have strings in my python application that look this way:</p>
<pre><code>test1/test2/foo/
</code></pre>
<p>Everytime I get such a string, I want to reduce it, beginning from the tail and reduced until the fist "/" is reached.</p>
<pre><code>test1/test2/
</code></pre>
<p>More examples:</p>
<pre><code>foo/foo/f... | 1 | 2010-01-27T08:24:13Z | 2,145,386 | <p>It sounds like the <a href="http://docs.python.org/library/os.path.html#os.path.dirname" rel="nofollow"><code>os.path.dirname</code></a> function might be what you're looking for. You may need to call it more than once:</p>
<pre><code>>>> import os.path
>>> os.path.dirname("test1/test2/")
'test1/t... | 6 | 2010-01-27T08:27:17Z | [
"python",
"string",
"path"
] |
Reduce strings in python to a specific point | 2,145,371 | <p>I have strings in my python application that look this way:</p>
<pre><code>test1/test2/foo/
</code></pre>
<p>Everytime I get such a string, I want to reduce it, beginning from the tail and reduced until the fist "/" is reached.</p>
<pre><code>test1/test2/
</code></pre>
<p>More examples:</p>
<pre><code>foo/foo/f... | 1 | 2010-01-27T08:24:13Z | 2,145,588 | <pre><code>>>> import os
>>> path="how/to/implement/this"
>>> os.path.split(path)
('how/to/implement', 'this')
>>> os.path.split(path)[0]
'how/to/implement'
</code></pre>
| 1 | 2010-01-27T09:08:18Z | [
"python",
"string",
"path"
] |
Reduce strings in python to a specific point | 2,145,371 | <p>I have strings in my python application that look this way:</p>
<pre><code>test1/test2/foo/
</code></pre>
<p>Everytime I get such a string, I want to reduce it, beginning from the tail and reduced until the fist "/" is reached.</p>
<pre><code>test1/test2/
</code></pre>
<p>More examples:</p>
<pre><code>foo/foo/f... | 1 | 2010-01-27T08:24:13Z | 2,145,733 | <pre><code>>>> os.path.split('how/to/implement/this'.rstrip('/'))
('how/to/implement', 'this')
>>> os.path.split('how/to/implement/this/'.rstrip('/'))
('how/to/implement', 'this')
</code></pre>
| 0 | 2010-01-27T09:36:03Z | [
"python",
"string",
"path"
] |
Reduce strings in python to a specific point | 2,145,371 | <p>I have strings in my python application that look this way:</p>
<pre><code>test1/test2/foo/
</code></pre>
<p>Everytime I get such a string, I want to reduce it, beginning from the tail and reduced until the fist "/" is reached.</p>
<pre><code>test1/test2/
</code></pre>
<p>More examples:</p>
<pre><code>foo/foo/f... | 1 | 2010-01-27T08:24:13Z | 2,145,768 | <pre><code>'/'.join(s.split('/')[:-1]+[''])
</code></pre>
| 0 | 2010-01-27T09:40:58Z | [
"python",
"string",
"path"
] |
Reduce strings in python to a specific point | 2,145,371 | <p>I have strings in my python application that look this way:</p>
<pre><code>test1/test2/foo/
</code></pre>
<p>Everytime I get such a string, I want to reduce it, beginning from the tail and reduced until the fist "/" is reached.</p>
<pre><code>test1/test2/
</code></pre>
<p>More examples:</p>
<pre><code>foo/foo/f... | 1 | 2010-01-27T08:24:13Z | 2,151,380 | <p>If you mean "/" as in path separator, the function you want is:</p>
<pre><code>os.path.dirname(your_argument)
</code></pre>
<p>If not, then you want:</p>
<pre><code>def your_function(your_argument):
result= your_argument.rstrip("/").rpartition("/")[0]
if result:
return result + "/"
return resu... | 0 | 2010-01-28T00:12:59Z | [
"python",
"string",
"path"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,517 | <p>Before blaming Python, you should really brush up some probability & statistics theory. Start by reading about the <a href="http://en.wikipedia.org/wiki/Birthday_paradox">birthday paradox</a></p>
<p>By the way, the <code>random</code> module in Python uses the <a href="http://en.wikipedia.org/wiki/Mersenne_twis... | 39 | 2010-01-27T08:51:38Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,533 | <p>If you don't want repetative one, generate sequential array and use <a href="http://docs.python.org/library/random.html#random.shuffle">random.shuffle</a></p>
| 34 | 2010-01-27T08:54:45Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,546 | <p>Python's random implementation is actually quite state of the art: </p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Mersenne_twister">http://en.wikipedia.org/wiki/Mersenne_twister</a> </li>
<li><a href="http://docs.python.org/library/random.html">http://docs.python.org/library/random.html</a></li>
</ul>
| 5 | 2010-01-27T08:57:51Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,551 | <h2>The Birthday Paradox, or why PRNGs produce duplicates more often than you might think.</h2>
<p><br>There are a couple of issues at play in the OP's problem. One is the <a href="http://en.wikipedia.org/wiki/Birthday_problem">birthday paradox</a> as mentioned above and the second is the nature of what you are gener... | 239 | 2010-01-27T08:58:59Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,600 | <p>True randomness definitely includes repetition of values before the whole set of possible values is exhausted. It would not be random otherwise, as you would be able to predict for how long a value would not be repeated.</p>
<p>If you ever rolled dice, you surely got 3 sixes in row quite often...</p>
| 14 | 2010-01-27T09:10:23Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,678 | <p>You have defined a random space of 4501 values (500-5000), and you are iterating 4500 times. You are basically guaranteed to get a collision in the test you wrote.</p>
<p>To think about it another way:</p>
<ul>
<li>When the result array is empty P(dupe) = 0</li>
<li>1 value in Array P(dupe) = 1/4500</li>
<li>2 v... | 1 | 2010-01-27T09:24:20Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,707 | <p>You are generating <code>4500</code> random numbers from a range <code>500 <= x <= 5000</code>. You then check to see for each number whether it has been generated before. The <a href="http://en.wikipedia.org/wiki/Birthday_problem" rel="nofollow">birthday problem</a> tells us what the probability is for two of... | 4 | 2010-01-27T09:30:04Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,145,723 | <p>That's not a repeater. A repeater is when you repeat the same <em>sequence</em>. Not just one number.</p>
| 3 | 2010-01-27T09:34:32Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,150,028 | <p>For anyone else with this problem, I used uuid.uuid4() and it works like a charm.</p>
| 0 | 2010-01-27T20:31:14Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 2,161,698 | <p>As an answer to the answer of Nimbuz:</p>
<p><a href="http://xkcd.com/221/">http://xkcd.com/221/</a></p>
<p><img src="http://imgs.xkcd.com/comics/random_number.png" alt="alt text"></p>
| 25 | 2010-01-29T11:56:23Z | [
"python",
"random",
"birthday-paradox"
] |
Random is barely random at all? | 2,145,510 | <p>I did this to test the randomness of randint:</p>
<pre><code>>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteratio... | 56 | 2010-01-27T08:50:51Z | 25,064,897 | <p>There is the birthday paradox. Taking this into account you realize that what you are saying is that finding "764, 3875, 4290, 4378, 764" or something like that is not very random because a number in that sequence repeats. The true way to do it is to compare sequences to each other. I wrote a python script to do thi... | 0 | 2014-07-31T17:03:54Z | [
"python",
"random",
"birthday-paradox"
] |
setup.py: installing just a pth file? | 2,145,779 | <p>As the final step in building a custom python, I need to add a <code>myproject.pth</code>.</p>
<p>Currently I'm doing this in a Makefile:</p>
<pre><code>install:
rm -f ../../lib/python2.6/site-packages/myproject.pth
cp myproject.pth ../../lib/python2.6/site-packages/myproject.pth
</code>... | 7 | 2010-01-27T09:43:18Z | 5,785,548 | <p>You're looking for the <a href="http://docs.python.org/distutils/setupscript.html#installing-additional-files" rel="nofollow">data_files</a> parameter to setup:</p>
<pre><code>from distutils import sysconfig
site_packages_path = sysconfig.get_python_lib()
setup(...,
data_files=[(site_packages_path, ["mypackage.p... | 3 | 2011-04-26T03:19:48Z | [
"python"
] |
setup.py: installing just a pth file? | 2,145,779 | <p>As the final step in building a custom python, I need to add a <code>myproject.pth</code>.</p>
<p>Currently I'm doing this in a Makefile:</p>
<pre><code>install:
rm -f ../../lib/python2.6/site-packages/myproject.pth
cp myproject.pth ../../lib/python2.6/site-packages/myproject.pth
</code>... | 7 | 2010-01-27T09:43:18Z | 36,383,223 | <p>Adapted from stderr's answer. Not sure if you're <em>supposed</em> to do this, but it works.</p>
<pre><code>from distutils import sysconfig
site_packages_path = sysconfig.get_python_lib()
import shutil
shutil.copy('mypackage.pth', site_packages_path)
setup(...)
</code></pre>
| 1 | 2016-04-03T08:31:01Z | [
"python"
] |
Convert Unicode/UTF-8 string to lower/upper case using pure & pythonic library | 2,145,826 | <p>I use Google App Engine and cannot use any C/C++ extension, just pure & pythonic library to do conversion of Unicode/UTF-8 strings to lower/upper case. str.lower() and string.lowercase() don't.</p>
| 6 | 2010-01-27T09:51:40Z | 2,145,841 | <p><code>str</code> encoded in UTF-8 and <code>unicode</code> are two different types. Don't use <code>string</code>, use the appropriate method on the unicode object:</p>
<pre><code>>>> print u'Ä'.upper()
Ä
</code></pre>
<p>Decode <code>str</code> to <code>unicode</code> before using:</p>
<pre><code>>... | 16 | 2010-01-27T09:54:02Z | [
"python",
"google-app-engine",
"case-conversion"
] |
Escape @ from python line command | 2,145,901 | <p>I don't know if this is a problem with python or with the shell (zsh on linux), I've an argument like this: "@xyz" that starts with a "@"</p>
<p>python the_script.py first_argument @second_argument third_arg</p>
<p>I tried to escape @ with \ or \\, or use "" but the program doesn't start. If I leave the @ from @se... | 2 | 2010-01-27T10:01:38Z | 2,145,935 | <ol>
<li><p>Perhaps the "@" is a glob character in zsh, <a href="https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6140012.ehtml" rel="nofollow">expanding to all symbolic links in the current directory</a>. Try escaping it with "@@"?</p></li>
<li><p>Try running the argument list with ... | 2 | 2010-01-27T10:07:26Z | [
"python",
"zsh"
] |
Python image processing of picture directly from the web | 2,145,955 | <p>I am writing python code to take an image from the web and calculate the standard deviation, ... and do other image processing with it. I have the following code:</p>
<pre><code>from scipy import ndimage
from urllib2 import urlopen
from urllib import urlretrieve
import urllib2
import Image
import ImageFi... | 3 | 2010-01-27T10:09:54Z | 2,146,346 | <p>PIL (Python Imaging Library) methods "fromstring" and "frombuffer" expect the image data in a raw, uncompacted, format.
When you do <code>page1.read()</code> you get the binary file data. In order to have PIL understanding it, you have to make this data mimick a file, and pass it to the "Image.open" method, which ... | 4 | 2010-01-27T11:16:23Z | [
"python",
"image",
"image-processing",
"urllib2"
] |
What is the equivalent of 'fread' from Matlab in Python? | 2,146,031 | <p>I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into 'blocks', and I'm having difficulty right from the off with the checksum at the top of the file.</p>
<p>What exactly is going on here in Matlab?</p>
<pre><c... | 8 | 2010-01-27T10:25:25Z | 2,146,087 | <blockquote>
<p>Really though, I want to know how to replicate <code>[A, count] = fread(fid, 3, 'uint32');</code></p>
</blockquote>
<p>In Matlab, one of <code>fread()</code>'s signatures is <code>fread(fileID, sizeA, precision)</code>. This reads in the first <code>sizeA</code> elements (not bytes) of a file, each o... | 2 | 2010-01-27T10:34:20Z | [
"python",
"matlab",
"numpy",
"readline",
"fread"
] |
What is the equivalent of 'fread' from Matlab in Python? | 2,146,031 | <p>I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into 'blocks', and I'm having difficulty right from the off with the checksum at the top of the file.</p>
<p>What exactly is going on here in Matlab?</p>
<pre><c... | 8 | 2010-01-27T10:25:25Z | 2,146,144 | <p>From the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fread.html">documentation of <code>fread</code></a>, it is a function to read binary data. The second argument specifies the size of the output vector, the third one the size/type of the items read.</p>
<p>In order to recreate this in Pytho... | 7 | 2010-01-27T10:44:25Z | [
"python",
"matlab",
"numpy",
"readline",
"fread"
] |
What is the equivalent of 'fread' from Matlab in Python? | 2,146,031 | <p>I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into 'blocks', and I'm having difficulty right from the off with the checksum at the top of the file.</p>
<p>What exactly is going on here in Matlab?</p>
<pre><c... | 8 | 2010-01-27T10:25:25Z | 2,146,485 | <p>The first part is covered by Torsten's answer... you're going to need <code>array</code> or <code>numarray</code> to do anything with this data anyway.</p>
<p>As for the %08X and the hex2dec stuff, %08X is just the print format for those unit32 numbers (8 digit hex, exactly the same as Python), and hex2dec('4D44525... | 0 | 2010-01-27T11:37:33Z | [
"python",
"matlab",
"numpy",
"readline",
"fread"
] |
What is the equivalent of 'fread' from Matlab in Python? | 2,146,031 | <p>I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into 'blocks', and I'm having difficulty right from the off with the checksum at the top of the file.</p>
<p>What exactly is going on here in Matlab?</p>
<pre><c... | 8 | 2010-01-27T10:25:25Z | 14,720,675 | <h2>Python Code for Reading a 1-Dimensional Array</h2>
<p>When replacing Matlab with Python, I wanted to read binary data into a <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html"><code>numpy.array</code></a>, so I used <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.from... | 7 | 2013-02-06T02:36:52Z | [
"python",
"matlab",
"numpy",
"readline",
"fread"
] |
Help parsing a page with python | 2,146,110 | <p>I would like to parse a webpage to can get the url of the video download. I use python and firebug but I cant get the url link.</p>
<p>Example:</p>
<p>The url where I have to get the video link is:
hxxp://www.rtve.es/mediateca/videos/20100125/saber-comer---salsa-verde-judiones-25-01-10/676590.shtml"</p>
<p>The vi... | 0 | 2010-01-27T10:37:28Z | 2,146,113 | <p>Use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow"><code>BeautifulSoup</code></a> or <a href="http://codespeak.net/lxml/" rel="nofollow"><code>lxml</code></a>.</p>
| 5 | 2010-01-27T10:38:04Z | [
"python",
"parsing",
"screen-scraping"
] |
Help parsing a page with python | 2,146,110 | <p>I would like to parse a webpage to can get the url of the video download. I use python and firebug but I cant get the url link.</p>
<p>Example:</p>
<p>The url where I have to get the video link is:
hxxp://www.rtve.es/mediateca/videos/20100125/saber-comer---salsa-verde-judiones-25-01-10/676590.shtml"</p>
<p>The vi... | 0 | 2010-01-27T10:37:28Z | 2,146,135 | <pre><code>import re
from urllib2 import urlopen
text = urlopen('http://www.rtve.es/mediateca/videos/20100125/saber-comer---salsa-verde-judiones-25-01-10/676590.shtm').read()
reg = re.compile(r'http://www\.rtv.*flv')
reg.findall(text)
</code></pre>
<p>Normallly you can use this one. But there is no your link inside.<... | 0 | 2010-01-27T10:42:00Z | [
"python",
"parsing",
"screen-scraping"
] |
Help parsing a page with python | 2,146,110 | <p>I would like to parse a webpage to can get the url of the video download. I use python and firebug but I cant get the url link.</p>
<p>Example:</p>
<p>The url where I have to get the video link is:
hxxp://www.rtve.es/mediateca/videos/20100125/saber-comer---salsa-verde-judiones-25-01-10/676590.shtml"</p>
<p>The vi... | 0 | 2010-01-27T10:37:28Z | 2,146,371 | <p>@OP, those videos are generated by javascript. For this topic, see <a href="http://stackoverflow.com/search?q=spidermonkey">here</a>. Or <a href="http://tinyurl.com/yk4q4mk" rel="nofollow">search google</a> for references.</p>
| 0 | 2010-01-27T11:21:08Z | [
"python",
"parsing",
"screen-scraping"
] |
__cmp__ method is this not working as expected in Python 2.x? | 2,146,225 | <pre><code>class x:
def __init__(self,name):
self.name=name
def __str__(self):
return self.name
def __cmp__(self,other):
print("cmp method called with self="+str(self)+",other="+str(other))
return self.name==other.name
# return False
instance1=x("hello")
instance2=... | 5 | 2010-01-27T10:58:23Z | 2,146,242 | <p><code>__cmp__()</code> is obsolescent. Define <code>__lt__()</code>, <code>__eq__()</code>, and <code>__gt__()</code> instead.</p>
<p>Even so, you're doing it wrong. You're supposed to return an integer.</p>
| 2 | 2010-01-27T11:00:17Z | [
"python",
"python-2.x",
"cmp"
] |
__cmp__ method is this not working as expected in Python 2.x? | 2,146,225 | <pre><code>class x:
def __init__(self,name):
self.name=name
def __str__(self):
return self.name
def __cmp__(self,other):
print("cmp method called with self="+str(self)+",other="+str(other))
return self.name==other.name
# return False
instance1=x("hello")
instance2=... | 5 | 2010-01-27T10:58:23Z | 2,146,245 | <p>the <code>__cmp__</code> method should return -1, 0 or 1, when self < other, self == other, self > other respectvelly.</p>
<p>You can do</p>
<pre><code>return cmp(self.name, other.name)
</code></pre>
<p>in your code for a proper result</p>
| 5 | 2010-01-27T11:01:16Z | [
"python",
"python-2.x",
"cmp"
] |
__cmp__ method is this not working as expected in Python 2.x? | 2,146,225 | <pre><code>class x:
def __init__(self,name):
self.name=name
def __str__(self):
return self.name
def __cmp__(self,other):
print("cmp method called with self="+str(self)+",other="+str(other))
return self.name==other.name
# return False
instance1=x("hello")
instance2=... | 5 | 2010-01-27T10:58:23Z | 2,146,246 | <p><code>__cmp__(x,y)</code> should return a negative number (e.g. -1) if <code>x < y</code>, a positive number (e.g. 1) if <code>x > y</code> and 0 if <code>x == y</code>. You should never return a boolean with it.</p>
<p>What you're overloading is <code>__eq__(x, y)</code>.</p>
| 9 | 2010-01-27T11:01:19Z | [
"python",
"python-2.x",
"cmp"
] |
__cmp__ method is this not working as expected in Python 2.x? | 2,146,225 | <pre><code>class x:
def __init__(self,name):
self.name=name
def __str__(self):
return self.name
def __cmp__(self,other):
print("cmp method called with self="+str(self)+",other="+str(other))
return self.name==other.name
# return False
instance1=x("hello")
instance2=... | 5 | 2010-01-27T10:58:23Z | 2,146,266 | <p>Lookup the documentation for <a href="http://docs.python.org/reference/datamodel.html#object.__cmp__" rel="nofollow"><code>__cmp__</code></a>, youre supposed to return an integer:</p>
<blockquote>
<p>Should return a negative integer if
self < other, zero if self == other, a
positive integer if self > other... | 0 | 2010-01-27T11:03:27Z | [
"python",
"python-2.x",
"cmp"
] |
__cmp__ method is this not working as expected in Python 2.x? | 2,146,225 | <pre><code>class x:
def __init__(self,name):
self.name=name
def __str__(self):
return self.name
def __cmp__(self,other):
print("cmp method called with self="+str(self)+",other="+str(other))
return self.name==other.name
# return False
instance1=x("hello")
instance2=... | 5 | 2010-01-27T10:58:23Z | 2,146,268 | <p>You're confusing <code>__cmp__</code> with <code>__eq__</code>.</p>
<p><a href="http://docs.python.org/reference/datamodel.html#object.__cmp__" rel="nofollow">From the documentation of <code>__cmp__</code>:</a></p>
<blockquote>
<p>Should return a negative integer if self < other, zero if self == other, a posi... | 4 | 2010-01-27T11:03:54Z | [
"python",
"python-2.x",
"cmp"
] |
Use of meta class in django | 2,146,363 | <p>Can someone please explain why is meta class used in the following example.</p>
<p>Ex:</p>
<pre><code>Class Employee (models.Model):
name = models.ForeignKey(name)
Gender = models.IntegerField()
class Meta:
ordering = ["Gender"]
</code></pre>
<p>Thanks...</p>
| 5 | 2010-01-27T11:19:54Z | 2,146,382 | <p>Django models use the <code>Meta</code> class to contain extra information about the model that would not necessarily be appropriate to contain within the model class itself. Note that this is <em>not</em> the same as Python's <code>metaclass</code>; that is a completely different topic.</p>
| 19 | 2010-01-27T11:21:50Z | [
"python",
"django",
"django-models"
] |
Use of meta class in django | 2,146,363 | <p>Can someone please explain why is meta class used in the following example.</p>
<p>Ex:</p>
<pre><code>Class Employee (models.Model):
name = models.ForeignKey(name)
Gender = models.IntegerField()
class Meta:
ordering = ["Gender"]
</code></pre>
<p>Thanks...</p>
| 5 | 2010-01-27T11:19:54Z | 2,146,386 | <p>Because author/programmer wants to sort results by value of Gender field.</p>
| 1 | 2010-01-27T11:22:17Z | [
"python",
"django",
"django-models"
] |
Use of meta class in django | 2,146,363 | <p>Can someone please explain why is meta class used in the following example.</p>
<p>Ex:</p>
<pre><code>Class Employee (models.Model):
name = models.ForeignKey(name)
Gender = models.IntegerField()
class Meta:
ordering = ["Gender"]
</code></pre>
<p>Thanks...</p>
| 5 | 2010-01-27T11:19:54Z | 2,146,401 | <p>In this case it defines the default field for ordering if you don't provide <code>ORDER_BY</code> in your query.</p>
| 2 | 2010-01-27T11:24:13Z | [
"python",
"django",
"django-models"
] |
Use of meta class in django | 2,146,363 | <p>Can someone please explain why is meta class used in the following example.</p>
<p>Ex:</p>
<pre><code>Class Employee (models.Model):
name = models.ForeignKey(name)
Gender = models.IntegerField()
class Meta:
ordering = ["Gender"]
</code></pre>
<p>Thanks...</p>
| 5 | 2010-01-27T11:19:54Z | 15,262,680 | <p>It is explained in Django Documentation for Models</p>
<pre><code>https://docs.djangoproject.com/en/dev/topics/db/models/
</code></pre>
<p>Give your model metadata by using an inner class Meta, like:</p>
<pre><code>Class Employee (models.Model):
....
class Meta:
ordering = ["attribute-X"]
</code>... | 0 | 2013-03-07T03:42:48Z | [
"python",
"django",
"django-models"
] |
Leading and Trailing '0' gives error | 2,146,381 | <pre><code>random.randint(50,9)
</code></pre>
<p>or</p>
<pre><code>random.randint(5,09)
</code></pre>
<p>give errors, although just</p>
<pre><code>random.randint(5,9)
</code></pre>
<p>..works!</p>
<p>Leading and trailing zero's aren't allowed in python without converting it to string or using x.f formatting?</p>
| 1 | 2010-01-27T11:21:51Z | 2,146,389 | <p>A leading <code>0</code> means that the value is an octal literal, but <code>09</code> is not a valid octal number.</p>
| 0 | 2010-01-27T11:22:41Z | [
"python",
"integer",
"octal"
] |
Leading and Trailing '0' gives error | 2,146,381 | <pre><code>random.randint(50,9)
</code></pre>
<p>or</p>
<pre><code>random.randint(5,09)
</code></pre>
<p>give errors, although just</p>
<pre><code>random.randint(5,9)
</code></pre>
<p>..works!</p>
<p>Leading and trailing zero's aren't allowed in python without converting it to string or using x.f formatting?</p>
| 1 | 2010-01-27T11:21:51Z | 2,146,400 | <p>oh, dear. "Trailing" zero gives error because <a href="http://docs.python.org/library/random.html#random.randint" rel="nofollow">first argument to <code>randint</code> should be smaller than the second</a>.</p>
<p>Leading zeros are used to represent octal numbers in python-2.x as in many other languages.</p>
| 6 | 2010-01-27T11:24:01Z | [
"python",
"integer",
"octal"
] |
Leading and Trailing '0' gives error | 2,146,381 | <pre><code>random.randint(50,9)
</code></pre>
<p>or</p>
<pre><code>random.randint(5,09)
</code></pre>
<p>give errors, although just</p>
<pre><code>random.randint(5,9)
</code></pre>
<p>..works!</p>
<p>Leading and trailing zero's aren't allowed in python without converting it to string or using x.f formatting?</p>
| 1 | 2010-01-27T11:21:51Z | 2,146,403 | <p>09 is not a valid dec integer in the second case
and in the first case - you have to give the function the lower number first</p>
| 0 | 2010-01-27T11:24:32Z | [
"python",
"integer",
"octal"
] |
HTTPS connection Python | 2,146,383 | <p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p>
<pre><code>import httplib
conn = ht... | 27 | 2010-01-27T11:22:00Z | 2,146,399 | <p>using </p>
<pre><code>class httplib.HTTPSConnection
</code></pre>
<p><a href="http://docs.python.org/library/httplib.html#httplib.HTTPSConnection">http://docs.python.org/library/httplib.html#httplib.HTTPSConnection</a></p>
| 9 | 2010-01-27T11:23:57Z | [
"python",
"ssl",
"https",
"httplib",
"pyopenssl"
] |
HTTPS connection Python | 2,146,383 | <p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p>
<pre><code>import httplib
conn = ht... | 27 | 2010-01-27T11:22:00Z | 2,146,415 | <p>Why haven't you tried httplib.HTTPSConnection? It doesn't do SSL validation but this isn't required to connect over https.
Your code works fine with https connection:</p>
<pre><code>>>> import httplib
>>> conn = httplib.HTTPSConnection("mail.google.com")
>>> conn.request("GET", "/")
>&... | 3 | 2010-01-27T11:27:02Z | [
"python",
"ssl",
"https",
"httplib",
"pyopenssl"
] |
HTTPS connection Python | 2,146,383 | <p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p>
<pre><code>import httplib
conn = ht... | 27 | 2010-01-27T11:22:00Z | 2,146,467 | <p><a href="http://docs.python.org/library/httplib.html">http://docs.python.org/library/httplib.html</a>:</p>
<blockquote>
<p>Note: HTTPS support is only available if the socket module was compiled with SSL support.</p>
</blockquote>
<pre><code>#!/usr/bin/env python
import httplib
c = httplib.HTTPSConnection("ccc.... | 50 | 2010-01-27T11:33:53Z | [
"python",
"ssl",
"https",
"httplib",
"pyopenssl"
] |
HTTPS connection Python | 2,146,383 | <p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p>
<pre><code>import httplib
conn = ht... | 27 | 2010-01-27T11:22:00Z | 2,146,593 | <p>Assuming SSL support is enabled for the <code>socket</code> module.</p>
<pre><code>connection1 = httplib.HTTPSConnection('www.somesecuresite.com')
</code></pre>
| 4 | 2010-01-27T11:55:50Z | [
"python",
"ssl",
"https",
"httplib",
"pyopenssl"
] |
HTTPS connection Python | 2,146,383 | <p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p>
<pre><code>import httplib
conn = ht... | 27 | 2010-01-27T11:22:00Z | 2,146,907 | <p>To check for <a href="http://docs.python.org/library/ssl.html">ssl support in Python 2.6+</a>:</p>
<pre><code>try:
import ssl
except ImportError:
print "error: no ssl support"
</code></pre>
<p>To connect via <a href="http://stackoverflow.com/questions/1935939/python-send-cmd-on-socket/1936923#1936923">http... | 7 | 2010-01-27T12:53:20Z | [
"python",
"ssl",
"https",
"httplib",
"pyopenssl"
] |
HTTPS connection Python | 2,146,383 | <p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p>
<pre><code>import httplib
conn = ht... | 27 | 2010-01-27T11:22:00Z | 30,399,825 | <pre><code>import requests
r = requests.get("https://stackoverflow.com")
data = r.content # Content of response
print r.status_code # Status code of response
print data
</code></pre>
| 3 | 2015-05-22T14:50:27Z | [
"python",
"ssl",
"https",
"httplib",
"pyopenssl"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.