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 |
|---|---|---|---|---|---|---|---|---|---|
Extracting data from MS Word | 505,925 | <p>I am looking for a way to extract / scrape data from Word files into a database. Our corporate procedures have Minutes of Meetings with clients documented in MS Word files, mostly due to history and inertia.</p>
<p>I want to be able to pull the action items from these meeting minutes into a database so that we can... | 5 | 2009-02-03T03:27:53Z | 506,134 | <p>Word has a little marker thingy that it puts at the end of every cell of text in a table. </p>
<p>It is used just like an end-of-paragraph marker in paragraphs: to store the formatting for the entire paragraph.</p>
<p>Just use the Left() function to strip it out, i.e. </p>
<pre><code> Left(Target, Len(Target)-1))... | 4 | 2009-02-03T05:52:44Z | [
"python",
"vba",
"ms-word",
"word-vba",
"pywin32"
] |
Extracting data from MS Word | 505,925 | <p>I am looking for a way to extract / scrape data from Word files into a database. Our corporate procedures have Minutes of Meetings with clients documented in MS Word files, mostly due to history and inertia.</p>
<p>I want to be able to pull the action items from these meeting minutes into a database so that we can... | 5 | 2009-02-03T03:27:53Z | 506,812 | <p>You could use OpenOffice. It can open word files, and also can run python macros.</p>
| 1 | 2009-02-03T11:52:04Z | [
"python",
"vba",
"ms-word",
"word-vba",
"pywin32"
] |
Extracting data from MS Word | 505,925 | <p>I am looking for a way to extract / scrape data from Word files into a database. Our corporate procedures have Minutes of Meetings with clients documented in MS Word files, mostly due to history and inertia.</p>
<p>I want to be able to pull the action items from these meeting minutes into a database so that we can... | 5 | 2009-02-03T03:27:53Z | 506,948 | <p>It is possible to programmatically save a Word document as HTML and to import the table(s) contained into Access. This requires very little effort.</p>
| 0 | 2009-02-03T12:46:49Z | [
"python",
"vba",
"ms-word",
"word-vba",
"pywin32"
] |
Is there a widely used STOMP adapter for Twisted? | 506,594 | <p>I checked out stomper and it didn't look complete. (I'm very new to Python) Is anybody out there using stomper in a production environment?</p>
<p>If not, I guess I'll have to roll out my own Twisted Stomp adapter.</p>
<p>Thanks in advance!</p>
| 2 | 2009-02-03T10:12:30Z | 511,246 | <p>Twisted Stomp adapter would be way too cool. Would you consider sharing it and keep us up to date with the development?</p>
<p>Cheers</p>
| 1 | 2009-02-04T13:02:58Z | [
"python",
"twisted",
"activemq",
"stomp"
] |
Is there a widely used STOMP adapter for Twisted? | 506,594 | <p>I checked out stomper and it didn't look complete. (I'm very new to Python) Is anybody out there using stomper in a production environment?</p>
<p>If not, I guess I'll have to roll out my own Twisted Stomp adapter.</p>
<p>Thanks in advance!</p>
| 2 | 2009-02-03T10:12:30Z | 561,901 | <p>There is a python library called <a href="https://github.com/oisinmulvihill/stomper" rel="nofollow">stomper</a> which I've used in the past with twisted (it comes with twisted example code). Disclaimer, I've worked on the code for stomper so I like it :)</p>
<p>These days I've moved away from stomp/ActiveMQ towards... | 7 | 2009-02-18T16:45:59Z | [
"python",
"twisted",
"activemq",
"stomp"
] |
Is there a widely used STOMP adapter for Twisted? | 506,594 | <p>I checked out stomper and it didn't look complete. (I'm very new to Python) Is anybody out there using stomper in a production environment?</p>
<p>If not, I guess I'll have to roll out my own Twisted Stomp adapter.</p>
<p>Thanks in advance!</p>
| 2 | 2009-02-03T10:12:30Z | 4,867,000 | <p>We just open-sourced one that's built on top of stomper: <a href="https://github.com/mozes/stompest" rel="nofollow">https://github.com/mozes/stompest</a></p>
| 1 | 2011-02-01T19:21:22Z | [
"python",
"twisted",
"activemq",
"stomp"
] |
Problem using django mptt | 507,006 | <p>I am having problem implementing django mptt.</p>
<p>Here is my model:</p>
<pre><code> class Company(models.Model):
name = models.CharField( max_length=100)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
mptt.register(Company, order_insertion_by=['name'])
</c... | 1 | 2009-02-03T13:09:04Z | 512,473 | <p>Django-mptt does not support multiple types of object in the same tree. You <em>could</em> have Financial and Company both inherit from the same parent class, and then build the tree out of instances of that parent class. You'd need to store a "content type" field on the parent class so you can cast instances of t... | 1 | 2009-02-04T17:37:51Z | [
"python",
"django",
"mptt",
"django-mptt"
] |
Problem using django mptt | 507,006 | <p>I am having problem implementing django mptt.</p>
<p>Here is my model:</p>
<pre><code> class Company(models.Model):
name = models.CharField( max_length=100)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
mptt.register(Company, order_insertion_by=['name'])
</c... | 1 | 2009-02-03T13:09:04Z | 12,845,637 | <p>I recommend django-polymorphic_tree </p>
| 0 | 2012-10-11T17:53:56Z | [
"python",
"django",
"mptt",
"django-mptt"
] |
Python xml minidom. generate <text>Some text</text> element | 507,405 | <p>I have the following code.</p>
<pre><code>from xml.dom.minidom import Document
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
main = doc.createElement('Text')
root.appendChild(main)
text = doc.createTextNode('Some text here')
main.appendChild(text)
print doc.toprettyxml(indent='\t')
</c... | 10 | 2009-02-03T14:59:17Z | 507,555 | <blockquote>
<p>Can this easily be done?</p>
</blockquote>
<p>It depends what exact rule you want, but generally no, you get little control over pretty-printing. If you want a specific format you'll usually have to write your own walker.</p>
<p>The DOM Level 3 LS parameter format-pretty-print in <a href="http://www... | 8 | 2009-02-03T15:30:32Z | [
"python",
"xml",
"minidom"
] |
Python xml minidom. generate <text>Some text</text> element | 507,405 | <p>I have the following code.</p>
<pre><code>from xml.dom.minidom import Document
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
main = doc.createElement('Text')
root.appendChild(main)
text = doc.createTextNode('Some text here')
main.appendChild(text)
print doc.toprettyxml(indent='\t')
</c... | 10 | 2009-02-03T14:59:17Z | 623,868 | <p>The pyxml package offers a simple solution to this by using the xml.dom.ext.PrettyPrint() function. It can also print to a file descriptor.</p>
<p>But the pyxml package is no longer maintained.</p>
<p>Oerjan Pettersen</p>
| 0 | 2009-03-08T16:48:22Z | [
"python",
"xml",
"minidom"
] |
Python xml minidom. generate <text>Some text</text> element | 507,405 | <p>I have the following code.</p>
<pre><code>from xml.dom.minidom import Document
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
main = doc.createElement('Text')
root.appendChild(main)
text = doc.createTextNode('Some text here')
main.appendChild(text)
print doc.toprettyxml(indent='\t')
</c... | 10 | 2009-02-03T14:59:17Z | 1,302,302 | <p>I was looking for exactly the same thing, and I came across this post. (the indenting provided in xml.dom.minidom broke another tool that I was using to manipulate the XML, and I needed it to be indented) I tried the accepted solution with a slightly more complex example and this was the result:</p>
<pre><code>In [... | 2 | 2009-08-19T19:58:11Z | [
"python",
"xml",
"minidom"
] |
Python xml minidom. generate <text>Some text</text> element | 507,405 | <p>I have the following code.</p>
<pre><code>from xml.dom.minidom import Document
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
main = doc.createElement('Text')
root.appendChild(main)
text = doc.createTextNode('Some text here')
main.appendChild(text)
print doc.toprettyxml(indent='\t')
</c... | 10 | 2009-02-03T14:59:17Z | 2,517,273 | <p>This solution worked for me without monkey patching or ceasing to use minidom: </p>
<pre><code>from xml.dom.ext import PrettyPrint
from StringIO import StringIO
def toprettyxml_fixed (node, encoding='utf-8'):
tmpStream = StringIO()
PrettyPrint(node, stream=tmpStream, encoding=encoding)
return tmpStream... | 0 | 2010-03-25T16:18:07Z | [
"python",
"xml",
"minidom"
] |
Python xml minidom. generate <text>Some text</text> element | 507,405 | <p>I have the following code.</p>
<pre><code>from xml.dom.minidom import Document
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
main = doc.createElement('Text')
root.appendChild(main)
text = doc.createTextNode('Some text here')
main.appendChild(text)
print doc.toprettyxml(indent='\t')
</c... | 10 | 2009-02-03T14:59:17Z | 12,146,051 | <p>This could be done with toxml(), using regular expressions to tidy things up.</p>
<pre><code>>>> from xml.dom.minidom import Document
>>> import re
>>> doc = Document()
>>> root = doc.createElement('root')
>>> _ = doc.appendChild(root)
>>> main = doc.createEleme... | 1 | 2012-08-27T16:43:31Z | [
"python",
"xml",
"minidom"
] |
Python xml minidom. generate <text>Some text</text> element | 507,405 | <p>I have the following code.</p>
<pre><code>from xml.dom.minidom import Document
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
main = doc.createElement('Text')
root.appendChild(main)
text = doc.createTextNode('Some text here')
main.appendChild(text)
print doc.toprettyxml(indent='\t')
</c... | 10 | 2009-02-03T14:59:17Z | 29,493,250 | <p>Easiest way to do this is to use prettyxml, and remove the \n and \t inside the tags. That way you keep your indent as you required in your example.</p>
<p><code>xml_output = doc.toprettyxml()
nojunkintags = re.sub('>(\n|\t)</', '', xml_output)
print nojunkintags</code></p>
| 0 | 2015-04-07T13:51:20Z | [
"python",
"xml",
"minidom"
] |
Python includes, module scope issue | 507,425 | <p>I'm working on my first significant Python project and I'm having trouble with scope issues and executing code in included files. Previously my experience is with PHP. </p>
<p>What I would like to do is have one single file that sets up a number of configuration variables, which would then be used throughout the co... | 2 | 2009-02-03T15:02:03Z | 507,576 | <p>As far as I know program-wide global variables/functions/classes/etc. does not exist in Python, everything is "confined" in some module (namespace). So if you want some functions or classes to be used in many parts of your code one solution is creating some modules like: "globFunCl" (defining/importing from elsewher... | 0 | 2009-02-03T15:35:06Z | [
"python",
"import",
"include",
"module"
] |
Python includes, module scope issue | 507,425 | <p>I'm working on my first significant Python project and I'm having trouble with scope issues and executing code in included files. Previously my experience is with PHP. </p>
<p>What I would like to do is have one single file that sets up a number of configuration variables, which would then be used throughout the co... | 2 | 2009-02-03T15:02:03Z | 507,582 | <p>In python, it is a common practice to have a bunch of modules that implement various functions and then have one single module that is the point-of-access to all the functions. This is basically the <a href="http://en.wikipedia.org/wiki/Facade_Pattern" rel="nofollow">facade pattern</a>.</p>
<p>An example: say you'r... | 6 | 2009-02-03T15:36:21Z | [
"python",
"import",
"include",
"module"
] |
Python includes, module scope issue | 507,425 | <p>I'm working on my first significant Python project and I'm having trouble with scope issues and executing code in included files. Previously my experience is with PHP. </p>
<p>What I would like to do is have one single file that sets up a number of configuration variables, which would then be used throughout the co... | 2 | 2009-02-03T15:02:03Z | 507,585 | <p>This is a two-step process:</p>
<ol>
<li>In your module globals.py import the items from wherever.</li>
<li>In all of your other modules, do "from globals import *"</li>
</ol>
<p>This brings all of those names into the current module's namespace.</p>
<p>Now, having told you how to do this, <em>let me suggest that... | 1 | 2009-02-03T15:36:36Z | [
"python",
"import",
"include",
"module"
] |
Python includes, module scope issue | 507,425 | <p>I'm working on my first significant Python project and I'm having trouble with scope issues and executing code in included files. Previously my experience is with PHP. </p>
<p>What I would like to do is have one single file that sets up a number of configuration variables, which would then be used throughout the co... | 2 | 2009-02-03T15:02:03Z | 507,635 | <p>This depends a bit on how you want to package things up. You can either think in terms of <em>files</em> or <em>modules</em>. The latter is "more pythonic", and enables you to decide exactly which items (and they can be anything with a name: classes, functions, variables, etc.) you want to make visible.</p>
<p>The ... | 0 | 2009-02-03T15:47:01Z | [
"python",
"import",
"include",
"module"
] |
Python includes, module scope issue | 507,425 | <p>I'm working on my first significant Python project and I'm having trouble with scope issues and executing code in included files. Previously my experience is with PHP. </p>
<p>What I would like to do is have one single file that sets up a number of configuration variables, which would then be used throughout the co... | 2 | 2009-02-03T15:02:03Z | 507,854 | <p>Others have talked about the right way to do this from Python.</p>
<p>Let me add, however, that having users change a source file to configure your application -- while common in the PHP world -- isn't very Pythonic. Consider using the <A HREF="http://docs.python.org/library/configparser.html" rel="nofollow">Config... | 0 | 2009-02-03T16:32:49Z | [
"python",
"import",
"include",
"module"
] |
How do i install pyCurl? | 507,927 | <p>I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.<... | 22 | 2009-02-03T16:50:24Z | 507,955 | <p>Depends on platform. Here on ubuntu it's as simple as:</p>
<pre><code>sudo aptitude install python-pycurl
</code></pre>
<p>It's common enough a package to think that most major Linux distributions will have it in their sources.</p>
<p>If you're on windows, you'll need <a href="http://curl.haxx.se/download.html">c... | 7 | 2009-02-03T16:56:48Z | [
"python",
"libcurl",
"pycurl",
"installation"
] |
How do i install pyCurl? | 507,927 | <p>I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.<... | 22 | 2009-02-03T16:50:24Z | 508,143 | <p>As it has been said already, it depends on the platform.</p>
<p>In general, I prefer to use only the Python interpreter itself that is packaged for my OS and install everything else in a <a href="http://pypi.python.org/pypi/virtualenv">virtual environment</a>, but this is a whole different story...
If you've got <a... | 7 | 2009-02-03T17:42:26Z | [
"python",
"libcurl",
"pycurl",
"installation"
] |
How do i install pyCurl? | 507,927 | <p>I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.<... | 22 | 2009-02-03T16:50:24Z | 551,418 | <p>According to <a href="http://bazaar-vcs.org/PyCurl">http://bazaar-vcs.org/PyCurl</a></p>
<blockquote>
<p>Since Windows does not come with
neither cURL or pycURL, Windows users
will have to install both.</p>
<p>cURL downloads:
<a href="http://curl.haxx.se/download.html">http://curl.haxx.se/download.html... | 11 | 2009-02-15T19:07:16Z | [
"python",
"libcurl",
"pycurl",
"installation"
] |
How do i install pyCurl? | 507,927 | <p>I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.<... | 22 | 2009-02-03T16:50:24Z | 5,385,014 | <p>You can try to download pycurl from here </p>
<p><a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p>
<blockquote>
<p>PycURL is a interface to the libcurl library.<br>
pycurl-7.19.0.win-amd64-py2.6.âexe [863 KB] [Python 2.6] [64 bit] [Dec ... | 12 | 2011-03-21T23:35:40Z | [
"python",
"libcurl",
"pycurl",
"installation"
] |
How do i install pyCurl? | 507,927 | <p>I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.<... | 22 | 2009-02-03T16:50:24Z | 10,699,666 | <p><strong>TL,DR</strong></p>
<p>Get a binary from this website: <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p>
<p>Direct links: <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/qjbh48zu/pycurl-7.19.0.win32-py2.6.exe" rel="nofollow"><code>2.6 3... | 14 | 2012-05-22T09:52:55Z | [
"python",
"libcurl",
"pycurl",
"installation"
] |
How do i install pyCurl? | 507,927 | <p>I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.<... | 22 | 2009-02-03T16:50:24Z | 19,478,322 | <p>I am using Anaconda(x64) and tried to install</p>
<pre><code>easy_install pycurl
</code></pre>
<p>but when I tried to load the module package, there is an error occured.</p>
<pre><code>import pycurl
Traceback (most recent call last):
File "<ipython-input-48-859fc1d70075>", line 1, in <module>
i... | 0 | 2013-10-20T14:09:20Z | [
"python",
"libcurl",
"pycurl",
"installation"
] |
How do i install pyCurl? | 507,927 | <p>I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.<... | 22 | 2009-02-03T16:50:24Z | 27,862,269 | <p>My environment is Windows 7 and Python 2.7. Although my Windows 7 is 64-bit, my Python 2.7 is 32-bit.</p>
<p>I had success by visiting <a href="http://pycurl.sourceforge.net/download/" rel="nofollow">http://pycurl.sourceforge.net/download/</a> and downloading and running pycurl-7.19.3.win32-py2.7.msi.</p>
| 0 | 2015-01-09T14:03:08Z | [
"python",
"libcurl",
"pycurl",
"installation"
] |
Fast PDF splitter library | 508,144 | <p>pyPdf is a great library to split, merge PDF files.
I'm using it to split pdf documents into 1 page documents. pyPdf is pure python and spends quite a lot of time in the _sweepIndirectReferences() method of the PdfFileWriter object when saving the extracted page. I need something with better performance. I've tried... | 4 | 2009-02-03T17:42:37Z | 508,190 | <p>pdfLaTex can do a lot of PDF managing and is <em>very</em> fast.</p>
<p>i've used it for some quite complex imposition worflows. the TeX language is really alien to programming, but it's easy to write a python script that generates the needed LaTex layout and processes it.</p>
| 0 | 2009-02-03T17:55:37Z | [
"python",
"c",
"pdf",
"pypdf"
] |
Fast PDF splitter library | 508,144 | <p>pyPdf is a great library to split, merge PDF files.
I'm using it to split pdf documents into 1 page documents. pyPdf is pure python and spends quite a lot of time in the _sweepIndirectReferences() method of the PdfFileWriter object when saving the extracted page. I need something with better performance. I've tried... | 4 | 2009-02-03T17:42:37Z | 508,420 | <p><a href="http://thierry.schmit.free.fr/spip/spip.php?article15" rel="nofollow">mbtPdfAsm</a> is a fast, open source command line tool for PDF processing.</p>
<p><a href="http://www.foolabs.com/xpdf/download.html" rel="nofollow">Xpdf</a> is also worth mentioning since it's GPL and written in C++. The source code is ... | 2 | 2009-02-03T18:53:10Z | [
"python",
"c",
"pdf",
"pypdf"
] |
Fast PDF splitter library | 508,144 | <p>pyPdf is a great library to split, merge PDF files.
I'm using it to split pdf documents into 1 page documents. pyPdf is pure python and spends quite a lot of time in the _sweepIndirectReferences() method of the PdfFileWriter object when saving the extracted page. I need something with better performance. I've tried... | 4 | 2009-02-03T17:42:37Z | 509,037 | <p>Have you tried using <a href="http://psyco.sourceforge.net/" rel="nofollow">Psyco</a> with pyPdf?</p>
| 1 | 2009-02-03T21:44:30Z | [
"python",
"c",
"pdf",
"pypdf"
] |
Fast PDF splitter library | 508,144 | <p>pyPdf is a great library to split, merge PDF files.
I'm using it to split pdf documents into 1 page documents. pyPdf is pure python and spends quite a lot of time in the _sweepIndirectReferences() method of the PdfFileWriter object when saving the extracted page. I need something with better performance. I've tried... | 4 | 2009-02-03T17:42:37Z | 509,904 | <p>Does it have to be python? My pure-Perl library <a href="http://search.cpan.org/dist/CAM-PDF/" rel="nofollow">CAM::PDF</a> is pretty fast at appending and deleting PDF document pages. It saves the sweeping for the very end, where possible.</p>
| 1 | 2009-02-04T02:47:53Z | [
"python",
"c",
"pdf",
"pypdf"
] |
get site name from a URL in python | 508,183 | <p>I am new to Python and it seems to have a lot of nice functions that I don't know about. What function can I use to get the root site name? For example, how would I get <em>faqs.org</em> if I gave the function the URL "<a href="http://ttp://www.faqs.org/docs/diveintopython/kgp_commandline.html" rel="nofollow">http:/... | 1 | 2009-02-03T17:53:30Z | 508,196 | <pre><code> >>> from urllib.parse import urlparse
>>> urlparse('http://www.cwi.nl:80/%7Eguido/Python.html').hostname
'www.cwi.nl'
</code></pre>
| 5 | 2009-02-03T17:57:18Z | [
"python"
] |
get site name from a URL in python | 508,183 | <p>I am new to Python and it seems to have a lot of nice functions that I don't know about. What function can I use to get the root site name? For example, how would I get <em>faqs.org</em> if I gave the function the URL "<a href="http://ttp://www.faqs.org/docs/diveintopython/kgp_commandline.html" rel="nofollow">http:/... | 1 | 2009-02-03T17:53:30Z | 508,203 | <p>The much overlooked <a href="http://www.python.org/doc/2.5.4/lib/module-urlparse.html" rel="nofollow">urlparse</a> module:</p>
<pre><code>from urlparse import urlparse
scheme, netloc, path, params, query, fragment = urlparse("http://www.faqs.org/docs/diveintopython/kgp_commandline.html")
print netloc
</code></pre>
| 2 | 2009-02-03T17:58:24Z | [
"python"
] |
get site name from a URL in python | 508,183 | <p>I am new to Python and it seems to have a lot of nice functions that I don't know about. What function can I use to get the root site name? For example, how would I get <em>faqs.org</em> if I gave the function the URL "<a href="http://ttp://www.faqs.org/docs/diveintopython/kgp_commandline.html" rel="nofollow">http:/... | 1 | 2009-02-03T17:53:30Z | 508,246 | <p>What version of Python are you learning with? Note that SilentGhost's answer is for Python 3.0, while Alabaster Codify's will work with the 2.x series.</p>
| 2 | 2009-02-03T18:08:01Z | [
"python"
] |
Is there a good dependency analysis tool for Python? | 508,277 | <p>Dependency analysis programs help us organize code by controlling the dependencies between modules in our code. When one module is a circular dependency of another module, it is a clue to find a way to turn that into a unidirectional dependency or merge two modules into one module.</p>
<p>What is the best dependenc... | 23 | 2009-02-03T18:18:07Z | 508,975 | <p>I don't know what is the <em>best</em> dependency analysis tool. You could look into <code>modulefinder</code> â it's a module in the standard library that determines the set of modules imported by a script.</p>
<p>Of course, with python you have problems of conditional imports, and even potentially scripts call... | 1 | 2009-02-03T21:30:33Z | [
"python",
"dependencies"
] |
Is there a good dependency analysis tool for Python? | 508,277 | <p>Dependency analysis programs help us organize code by controlling the dependencies between modules in our code. When one module is a circular dependency of another module, it is a clue to find a way to turn that into a unidirectional dependency or merge two modules into one module.</p>
<p>What is the best dependenc... | 23 | 2009-02-03T18:18:07Z | 509,194 | <p>I recommend using <a href="http://furius.ca/snakefood/">snakefood</a> for creating graphical dependency graphs of Python projects. It detects dependencies nicely enough to immediately see areas for refactorisation. Its usage is pretty straightforward if you read a little bit of documentation.</p>
<p>Of course, you ... | 24 | 2009-02-03T22:26:13Z | [
"python",
"dependencies"
] |
Is there a good dependency analysis tool for Python? | 508,277 | <p>Dependency analysis programs help us organize code by controlling the dependencies between modules in our code. When one module is a circular dependency of another module, it is a clue to find a way to turn that into a unidirectional dependency or merge two modules into one module.</p>
<p>What is the best dependenc... | 23 | 2009-02-03T18:18:07Z | 865,757 | <p>PyStructure â Automated Structure and Dependency Analysis of Python Code</p>
<p>This is used for PyDev's refactoring features. <a href="http://pystructure.ifs.hsr.ch/trac/" rel="nofollow">http://pystructure.ifs.hsr.ch/trac/</a></p>
| 1 | 2009-05-14T21:03:08Z | [
"python",
"dependencies"
] |
Why does Django only serve files containing a space? | 508,609 | <p>I'm writing a basic Django application. For testing / development purposes I'm trying to serve the static content of the website using Django's development server as per <a href="http://docs.djangoproject.com/en/dev/howto/static-files/#howto-static-files" rel="nofollow">http://docs.djangoproject.com/en/dev/howto/sta... | 1 | 2009-02-03T19:45:25Z | 508,852 | <p>You have wrong patterns order in <code>urls.py</code>.</p>
<p>When you try to retrieve path <em>without</em> space it matches:</p>
<pre><code>(r'^(?P<page_name>\S*)$', 'Blah.content.views.index'),
</code></pre>
<p>not <code>static.serve</code> and of course you have not such page, But when you try to access... | 10 | 2009-02-03T20:50:48Z | [
"python",
"django"
] |
AUTO_INCREMENT in sqlite problem with python | 508,627 | <p>I am using sqlite with python 2.5. I get a sqlite error with the syntax below. I looked around and saw AUTOINCREMENT on this page <a href="http://www.sqlite.org/syntaxdiagrams.html#column-constraint">http://www.sqlite.org/syntaxdiagrams.html#column-constraint</a> but that did not work either. Without AUTO_INCREMENT ... | 8 | 2009-02-03T19:49:59Z | 508,664 | <p>This is addressed in the <a href="http://www.sqlite.org/faq.html">SQLite FAQ</a>. <a href="http://www.sqlite.org/faq.html#q1">Question #1</a>.</p>
<p>Which states:</p>
<blockquote>
<p>How do I create an AUTOINCREMENT
field?</p>
<p>Short answer: A column declared
INTEGER PRIMARY KEY will
autoincrement... | 34 | 2009-02-03T19:56:53Z | [
"python",
"sqlite"
] |
AUTO_INCREMENT in sqlite problem with python | 508,627 | <p>I am using sqlite with python 2.5. I get a sqlite error with the syntax below. I looked around and saw AUTOINCREMENT on this page <a href="http://www.sqlite.org/syntaxdiagrams.html#column-constraint">http://www.sqlite.org/syntaxdiagrams.html#column-constraint</a> but that did not work either. Without AUTO_INCREMENT ... | 8 | 2009-02-03T19:49:59Z | 508,667 | <p>It looks like AUTO_INCREMENT should be AUTOINCREMENT see <a href="http://www.sqlite.org/syntaxdiagrams.html#column-constraint">http://www.sqlite.org/syntaxdiagrams.html#column-constraint</a></p>
| 10 | 2009-02-03T19:57:06Z | [
"python",
"sqlite"
] |
AUTO_INCREMENT in sqlite problem with python | 508,627 | <p>I am using sqlite with python 2.5. I get a sqlite error with the syntax below. I looked around and saw AUTOINCREMENT on this page <a href="http://www.sqlite.org/syntaxdiagrams.html#column-constraint">http://www.sqlite.org/syntaxdiagrams.html#column-constraint</a> but that did not work either. Without AUTO_INCREMENT ... | 8 | 2009-02-03T19:49:59Z | 508,684 | <p>You could try</p>
<pre>CREATE TABLE fileInfo
(
fileid INTEGER PRIMARY KEY AUTOINCREMENT,
name STRING,
status INTEGER NOT NULL
);</pre>
| 5 | 2009-02-03T20:01:05Z | [
"python",
"sqlite"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 261,008 | <p>For numeric data, <a href="http://numpy.scipy.org/" rel="nofollow">Numpy Arrays</a>:</p>
<pre><code>>>> matrix1 = array(([0,1],[1,3]))
>>> print matrix1
[[0 1]
[1 3]]
</code></pre>
<p>For general data (e.g. strings), you can use a list of lists, list of tuples, ...</p>
<pre><code>matrix2 = [['a'... | 3 | 2008-11-04T05:47:59Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 261,084 | <p>If you restrict yourself to the Python standard library, then a list of lists is the closest construct:</p>
<pre><code>arr = [[1,2],[3,4]]
</code></pre>
<p>gives a 2d-like array. The rows can be accessed as <code>arr[i]</code> for <code>i</code> in <code>{0,..,len(arr}</code>, but column access is difficult.</p>
... | 18 | 2008-11-04T06:37:50Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 261,340 | <p>To create a standard python array of arrays of arbitrary size:</p>
<pre><code>a = [[0]*cols for _ in [0]*rows]
</code></pre>
<p>It is accessed like this:</p>
<pre><code>a[0][1] = 5 # set cell at row 0, col 1 to 5
</code></pre>
<p>A small python gotcha that's worth mentioning: It is tempting to just type</p>
<p... | 13 | 2008-11-04T09:34:25Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 261,656 | <p>Multidimensional arrays are a little murky. There are few reasons for using them and many reasons for thinking twice and using something else that more properly reflects what you're doing. [Hint. your question was thin on context ;-) ]</p>
<p>If you're doing matrix math, then use <code>numpy</code>.</p>
<p>Howev... | 10 | 2008-11-04T12:04:00Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 264,562 | <p>Another option is to use a dictionary:</p>
<pre><code>>>> from collections import defaultdict
>>> array = defaultdict(int) # replace int with the default-factory you want
>>> array[(0,0)]
0
>>> array[(99,99)]
0
</code></pre>
<p>You'll need to keep track of the upper & lower ... | 0 | 2008-11-05T07:33:36Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 508,677 | <p>You can create it using nested lists:</p>
<pre><code>matrix = [[a,b],[c,d],[e,f]]
</code></pre>
<p>If it has to be dynamic it's more complicated, why not write a small class yourself?</p>
<pre><code>class Matrix(object):
def __init__(self, rows, columns, default=0):
self.m = []
for i in range(... | 11 | 2009-02-03T19:59:02Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 508,679 | <p>Take a look at <a href="http://numpy.scipy.org//">numpy</a></p>
<p>here's a code snippet for you</p>
<pre><code>import numpy as npy
d = npy.zeros((len(x)+1, len(y)+1, len(x)+len(y)+3))
d[0][0][0] = 0 # although this is unnecessary since zeros initialises to zero
d[i][j][k] = npy.inf
</code></pre>
<p>I don't thin... | 11 | 2009-02-03T20:00:21Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 508,681 | <p>Probably not relevant for you but if you are doing serious matrix work see <a href="http://numpy.scipy.org/" rel="nofollow">numpy</a></p>
| 4 | 2009-02-03T20:00:38Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 508,700 | <p>If you are OK using sparse arrays, you could use a dict to store your values. Python's dicts allow you to use tuples as keys, as such, you could assign to and access elements of the "sparse array" (which is really a dict here) like this:</p>
<pre><code>d = {}
d[0,2,7] = 123 # assign 123 to x=0, y=2, z=7
v = d[0,2,... | 5 | 2009-02-03T20:04:14Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 508,991 | <p>Here's a quick way to create a nested 3-dimensional list initialized with zeros:</p>
<pre><code># dim1, dim2, dim3 are the dimensions of the array
a =[[[0 for _ in range(dim1)] for _ in range(dim2)] for _ in range(dim1) ]
a[0][0][0] = 1
</code></pre>
<p>this is a list of lists of lists, a bit more flexible than an... | 2 | 2009-02-03T21:34:16Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 1,194,934 | <p>I've just stepped into a similar need and coded this:</p>
<pre><code>def nDimensionsMatrix(dims, elem_count, ptr=[]):
if (dims > 1):
for i in range(elem_count[dims-1]):
empty = []
ptr.append(empty)
nDimensionsMatrix(dims-1, elem_count, empty)
return ptr
elif dims == 1:
pt... | 0 | 2009-07-28T15:31:04Z | [
"java",
"python",
"arrays"
] |
Multidimensional array in Python | 508,657 | <p>I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:</p>
<pre><code>double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;
</code></pre>
<p>Further value... | 8 | 2009-02-03T19:54:37Z | 1,494,477 | <p>Easy, when using numpy:</p>
<pre><code>b = ones((2,3,4)) # creates a 2x3x4 array containing all ones.
</code></pre>
<p>'ones' can be replaced with 'zeros'</p>
| 0 | 2009-09-29T19:29:39Z | [
"java",
"python",
"arrays"
] |
Python time to age | 508,727 | <p>I'm trying to convert a date string into an age.</p>
<p>The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.</p>
<p>I have sucessfully converted the date using:</p>
<pre><code>>>> time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200... | 2 | 2009-02-03T20:12:06Z | 508,742 | <p>You need to use the module <code>datetime</code> and the object <a href="http://docs.python.org/library/datetime.html#datetime.timedelta" rel="nofollow"><code>datetime.timedelta</code></a></p>
<pre><code>from datetime import datetime
t1 = datetime.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +... | 16 | 2009-02-03T20:16:48Z | [
"python",
"datetime"
] |
Python time to age | 508,727 | <p>I'm trying to convert a date string into an age.</p>
<p>The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.</p>
<p>I have sucessfully converted the date using:</p>
<pre><code>>>> time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200... | 2 | 2009-02-03T20:12:06Z | 508,764 | <pre><code>from datetime import datetime, timedelta
datetime.now()
datetime.datetime(2009, 2, 3, 15, 17, 35, 156000)
datetime.now() - datetime(1984, 6, 29 )
datetime.timedelta(8985, 55091, 206000)
datetime.now() - datetime(1984, 6, 29 )
datetime.timedelta(8985, 55094, 198000) # my age...
</code></pre>
<p>timedelta(day... | 2 | 2009-02-03T20:21:39Z | [
"python",
"datetime"
] |
Python time to age | 508,727 | <p>I'm trying to convert a date string into an age.</p>
<p>The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.</p>
<p>I have sucessfully converted the date using:</p>
<pre><code>>>> time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200... | 2 | 2009-02-03T20:12:06Z | 508,797 | <p>In Python, <code>datetime</code> objects natively support subtraction:</p>
<pre><code>from datetime import datetime
age = datetime.now() - datetime.strptime(...)
print age.days
</code></pre>
<p>The result is a <a href="http://docs.python.org/library/datetime.html#datetime.timedelta" rel="nofollow">timedelta</a> ob... | 5 | 2009-02-03T20:30:17Z | [
"python",
"datetime"
] |
Python time to age | 508,727 | <p>I'm trying to convert a date string into an age.</p>
<p>The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.</p>
<p>I have sucessfully converted the date using:</p>
<pre><code>>>> time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200... | 2 | 2009-02-03T20:12:06Z | 508,881 | <p>Thanks guys, I ended up with the following:</p>
<pre><code>def getAge( d ):
""" Calculate age from date """
delta = datetime.now() - datetime.strptime(d, "%a, %d %b %Y %H:%M:%S +0200")
return delta.days + delta.seconds / 86400.0 # divide secs into days
</code></pre>
<p>Giving:</p>
<pre><code>>>&... | 0 | 2009-02-03T20:59:42Z | [
"python",
"datetime"
] |
Python time to age | 508,727 | <p>I'm trying to convert a date string into an age.</p>
<p>The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.</p>
<p>I have sucessfully converted the date using:</p>
<pre><code>>>> time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200... | 2 | 2009-02-03T20:12:06Z | 510,638 | <p>If you don't want to use datetime (e.g. if your Python is old and you don't have the module), you can just use the time module.</p>
<pre><code>s = "Mon, 17 Nov 2008 01:45:32 +0200"
import time
import email.utils # Using email.utils means we can handle the timezone.
t = email.utils.parsedate_tz(s) # Gets the time.mk... | 1 | 2009-02-04T09:24:29Z | [
"python",
"datetime"
] |
Python time to age | 508,727 | <p>I'm trying to convert a date string into an age.</p>
<p>The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.</p>
<p>I have sucessfully converted the date using:</p>
<pre><code>>>> time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200... | 2 | 2009-02-03T20:12:06Z | 25,426,694 | <p>Since Python 3.2, <code>datetime.strptime()</code> returns an aware datetime object if <code>%z</code> directive is provided:</p>
<pre><code>#!/usr/bin/env python3
from datetime import datetime, timezone, timedelta
s = "Mon, 17 Nov 2008 01:45:32 +0200"
birthday = datetime.strptime(s, '%a, %d %b %Y %H:%M:%S %z')
ag... | 0 | 2014-08-21T12:44:32Z | [
"python",
"datetime"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 508,839 | <p>You seem to assume its the library. Its open source, so it would be worth checking the code to see if it is.</p>
<p>You mention that you're sending a lot of data over HTTP. The inefficieny might be because of the library, but HTTP isn't the most efficient protocol for sending large amounts of data. Then again, i... | 1 | 2009-02-03T20:44:32Z | [
"python",
"http",
"curl",
"twisted"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 508,840 | <p>Often when I've had performance problems with httplib, the problem hasn't been with the httplib itself, but with how I'm using it. Here are a few common pitfalls:</p>
<p>(1) Don't make a new TCP connection for every web request. If you are making lots of request to the same server, instead of this pattern: </p>... | 21 | 2009-02-03T20:44:37Z | [
"python",
"http",
"curl",
"twisted"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 508,858 | <blockquote>
<p>Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else?</p>
</blockquote>
<p>Do you <em>suspect</em> it or are you <em>sure</em> that that it's <code>htt... | 18 | 2009-02-03T20:53:12Z | [
"python",
"http",
"curl",
"twisted"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 509,006 | <p>httplib2 is another option:
<a href="http://code.google.com/p/httplib2/" rel="nofollow">http://code.google.com/p/httplib2/</a></p>
<p>I have never benchmarked or profiled it in comparison to httplib, but I would also be interested in any findings there.</p>
<hr>
<p>Dec. 2012 update:
I no longer use httplib2. now... | 2 | 2009-02-03T21:38:43Z | [
"python",
"http",
"curl",
"twisted"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 509,486 | <p>PyCurl is awesome, and extremely high performance.</p>
| 5 | 2009-02-03T23:36:07Z | [
"python",
"http",
"curl",
"twisted"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 510,084 | <p>httplib2 is a very good option. Joe Gregorio has fixed many bugs of httplib.</p>
| 0 | 2009-02-04T04:37:50Z | [
"python",
"http",
"curl",
"twisted"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 515,335 | <p>As others answered httplib2 is a good alternative because it handles headers properly and can cache responses, but I doubt this would help in POST performance.</p>
<p>An alternative that might actually give you a performance boost for POST, especially on Windows, is the <a href="http://twistedmatrix.com/trac/ticket... | 1 | 2009-02-05T10:33:18Z | [
"python",
"http",
"curl",
"twisted"
] |
A replacement for python's httplib? | 508,817 | <p>I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using.</p>
<p>Could I improve performance by replacing httplib with something else? </p>
<p>I've seen th... | 9 | 2009-02-03T20:36:21Z | 6,769,260 | <p>It works on my windows machine:
With Py 2.3 (without IPv6 support) this is only the IPv4 address,
but with Py 2.4-2.6 the order is (on my Win XP host) the IPv6 address
first, then the IPv4 address. Since the IPv6 address is checked first,
this gives a timeout and causes the slow connect() call. </p>
<p>I have only ... | 0 | 2011-07-20T22:21:18Z | [
"python",
"http",
"curl",
"twisted"
] |
How to overwrite some bytes in the middle of a file with Python? | 508,983 | <p>I'd like to be able to overwrite some bytes at a given offset in a file using Python.</p>
<p>My attempts have failed miserably and resulted in:</p>
<ul>
<li>overwriting the bytes at the offset but also truncating the file just after (file mode = "w" or "w+") </li>
<li>appending the bytes at the end of the file (f... | 11 | 2009-02-03T21:31:53Z | 509,010 | <p>According to <a href="http://www.sthurlow.com/python/lesson10/" rel="nofollow">this python page</a> you can type file.seek to seek to a particualar offset. You can then write whatever you want.</p>
<p>To avoid truncating the file, you can open it with "a+" then seek to the right offset.</p>
| 3 | 2009-02-03T21:39:43Z | [
"python",
"file",
"patching"
] |
How to overwrite some bytes in the middle of a file with Python? | 508,983 | <p>I'd like to be able to overwrite some bytes at a given offset in a file using Python.</p>
<p>My attempts have failed miserably and resulted in:</p>
<ul>
<li>overwriting the bytes at the offset but also truncating the file just after (file mode = "w" or "w+") </li>
<li>appending the bytes at the end of the file (f... | 11 | 2009-02-03T21:31:53Z | 509,014 | <p>Try this:</p>
<pre><code>fh = open("filename.ext", "r+b")
fh.seek(offset)
fh.write(bytes)
fh.close()
</code></pre>
| 18 | 2009-02-03T21:39:57Z | [
"python",
"file",
"patching"
] |
How to overwrite some bytes in the middle of a file with Python? | 508,983 | <p>I'd like to be able to overwrite some bytes at a given offset in a file using Python.</p>
<p>My attempts have failed miserably and resulted in:</p>
<ul>
<li>overwriting the bytes at the offset but also truncating the file just after (file mode = "w" or "w+") </li>
<li>appending the bytes at the end of the file (f... | 11 | 2009-02-03T21:31:53Z | 509,036 | <p>Very inefficient, but I don't know any other way right now, that <strong>doesn't overwrite</strong> the bytes in the middle (as Ben Blanks one does):</p>
<pre><code>a=file('/tmp/test123','r+')
s=a.read()
a.seek(0)
a.write(s[:3]+'xxx'+s[3:])
a.close()
</code></pre>
<p>will write 'xxx' at offset 3: <code>123456789 -... | 0 | 2009-02-03T21:44:25Z | [
"python",
"file",
"patching"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 509,295 | <p>It's pretty simple really:</p>
<pre><code>a[start:end] # items start through end-1
a[start:] # items start through the rest of the array
a[:end] # items from the beginning through end-1
a[:] # a copy of the whole array
</code></pre>
<p>There is also the <code>step</code> value, which can be used wi... | 1,891 | 2009-02-03T22:48:24Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 509,297 | <p>The tutorial talks about it:</p>
<p><a href="http://docs.python.org/tutorial/introduction.html#strings">http://docs.python.org/tutorial/introduction.html#strings</a></p>
<p>(Scroll down a bit until you get to the part about slicing.) </p>
<p>The ASCII art diagram is helpful too for remembering how slices work:</... | 245 | 2009-02-03T22:49:04Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 509,377 | <p>Enumerating the possibilities allowed by the grammar:</p>
<pre><code>>>> seq[:] # [seq[0], seq[1], ..., seq[-1] ]
>>> seq[low:] # [seq[low], seq[low+1], ..., seq[-1] ]
>>> seq[:high] # [seq[0], seq[1], ..., seq[high-1]... | 180 | 2009-02-03T23:08:22Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 509,415 | <p>And a couple of things that weren't immediately obvious to me when I first saw the slicing syntax:</p>
<pre><code>>>> x = [1,2,3,4,5,6]
>>> x[::-1]
[6,5,4,3,2,1]
</code></pre>
<p>Easy way to reverse sequences!</p>
<p>And if you wanted, for some reason, every second item in the reversed sequence:... | 82 | 2009-02-03T23:15:02Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 522,212 | <p>I use the "an index points between elements" method of thinking about it myself, but one way of describing it which sometimes helps others get it is this:</p>
<pre><code>mylist[X:Y]
</code></pre>
<p>X is the index of the first element you want.<br />
Y is the index of the first element you <em>don't</em> want.</p>... | 20 | 2009-02-06T21:16:28Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 567,094 | <p>After using it a bit I realise that the simplest description is that it is exactly the same as the arguments in a for loop...</p>
<pre><code>(from:to:step)
</code></pre>
<p>any of them are optional</p>
<pre><code>(:to:step)
(from::step)
(from:to)
</code></pre>
<p>then the negative indexing just needs you to add ... | 33 | 2009-02-19T20:52:44Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 4,729,334 | <p>The answers above don't discuss slice assignment:</p>
<pre><code>>>> r=[1,2,3,4]
>>> r[1:1]
[]
>>> r[1:1]=[9,8]
>>> r
[1, 9, 8, 2, 3, 4]
>>> r[1:1]=['blah']
>>> r
[1, 'blah', 9, 8, 2, 3, 4]
</code></pre>
<p>This may also clarify the difference between slicing a... | 119 | 2011-01-18T21:37:57Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 7,315,935 | <p>Found this great table at <a href="http://wiki.python.org/moin/MovingToPythonFromOtherLanguages">http://wiki.python.org/moin/MovingToPythonFromOtherLanguages</a></p>
<pre><code>Python indexes and slices for a six-element list.
Indexes enumerate the elements, slices enumerate the spaces between the elements.
Index ... | 64 | 2011-09-06T06:50:08Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 9,827,284 | <p>This is just for some extra info...
Consider the list below </p>
<pre><code>>>> l=[12,23,345,456,67,7,945,467]
</code></pre>
<p>Few other tricks for reversing the list:</p>
<pre><code>>>> l[len(l):-len(l)-1:-1]
[467, 945, 7, 67, 456, 345, 23, 12]
>>> l[:-len(l)-1:-1]
[467, 945, 7, 67, ... | 16 | 2012-03-22T17:20:59Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 9,923,354 | <p>I find it easier to remember how it's works, then I can figure out any specific start/stop/step combination.</p>
<p>It's instructive to understand <code>range()</code> first:</p>
<pre><code>def range(start=0, stop, step=1): # illegal syntax, but that's the effect
i = start
while (i < stop if step > ... | 21 | 2012-03-29T10:15:12Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 13,005,464 | <p>In python 2.7</p>
<p>Slicing in python</p>
<pre><code>[a:b:c]
len = length of string, tuple or list
c -- default is +1. sign of c indicates forward or backward, absolute value of c indicates steps. Default is forward with step size 1. Positive means forward, negative means backward.
a -- when c is positive o... | 51 | 2012-10-22T05:33:39Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 14,682,039 | <pre><code>index:
------------>
0 1 2 3 4
+---+---+---+---+---+
| a | b | c | d | e |
+---+---+---+---+---+
0 -4 -3 -2 -1
<------------
slice:
<---------------|
|--------------->
: 1 2 3 4 :
+---+---+---+---+---+
| a | b | c | d | e |
+---+---+---+---+---+
: -4... | 13 | 2013-02-04T07:20:03Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 15,824,717 | <p>You can also use slice assignment to remove one or more elements from a list:</p>
<pre><code>r = [1, 'blah', 9, 8, 2, 3, 4]
>>> r[1:4] = []
>>> r
[1, 2, 3, 4]
</code></pre>
| 16 | 2013-04-05T01:59:41Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 16,267,103 | <p>Python slicing notation:</p>
<pre><code>a[start:end:step]
</code></pre>
<ul>
<li>For <code>start</code> and <code>end</code>, negative values are interpreted as being relative to the end of the sequence.</li>
<li>Positive indices for <code>end</code> indicate the position <em>after</em> the last element to be incl... | 19 | 2013-04-28T19:49:39Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 20,136,130 | <p>To get a certain piece of an iterable (like a list), here is an example:</p>
<pre><code>variable[number1:number2]
</code></pre>
<p>In this example, a positive number for number 1 is how many components you take off the front. A negative number is the exact opposite, how many you keep from the end. A positive numbe... | 4 | 2013-11-22T02:53:27Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 20,443,928 | <p>As a general rule, writing code with a lot of hardcoded index values leads to a readability
and maintenance mess. For example, if you come back to the code a year later, youâll
look at it and wonder what you were thinking when you wrote it. The solution shown
is simply a way of more clearly stating what your code ... | 15 | 2013-12-07T16:52:45Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 24,546,555 | <p>If you prefer a video and voiceover instead, the guy in <a href="http://youtu.be/tKTZoB2Vjuk?t=42m34s" rel="nofollow">the Google Python course (click here)</a> talks about slice syntax and some of its practical uses, starting from the time index 42:34; the link will take you to that point.</p>
| 6 | 2014-07-03T06:36:03Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 24,713,353 | <blockquote>
<h1>Explain Python's slice notation</h1>
</blockquote>
<p>In short, the colons (<code>:</code>) in subscript notation (<code>subscriptable[subscriptarg]</code>) make slice notation - which has the optional arguments, <code>start</code>, <code>stop</code>, <code>step</code>:</p>
<pre><code>sliceable[sta... | 62 | 2014-07-12T13:19:03Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 26,442,691 | <pre><code>#!/usr/bin/env python
def slicegraphical(s, lista):
if len(s) > 9:
print """Enter a string of maximum 9 characters,
so the printig would looki nice"""
return 0;
# print " ",
print ' '+'+---' * len(s) +'+'
print ' ',
for letter in s:
print '| {}'.format(le... | 3 | 2014-10-18T17:40:45Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 29,237,560 | <p>This is how I teach slices to newbies:</p>
<p><strong>Understanding difference between indexing and slicing:</strong></p>
<p>Wiki Python has this amazing picture which clearly distinguishes indexing and slicing.</p>
<p><img src="http://i.stack.imgur.com/o99aU.png" alt="enter image description here"></p>
<p>It is... | 11 | 2015-03-24T16:08:36Z | [
"python",
"list",
"slice"
] |
Explain Python's slice notation | 509,211 | <p>I need a good explanation (references are a plus) on Python's slice notation. </p>
<p>To me, this notation needs a bit of picking up. </p>
<p>It looks extremely powerful, but I haven't quite got my head around it.</p>
| 1,331 | 2009-02-03T22:31:02Z | 37,455,246 | <p>My brain seems happy to accept that <code>lst[start:end]</code> contains the <code>start</code>-th item. I might even say that it is a 'natural assumption'.</p>
<p>But occasionally a doubt creeps in and my brain asks for reassurance that it does not contain the <code>end</code>-th element.</p>
<p>In these moments ... | 0 | 2016-05-26T08:16:54Z | [
"python",
"list",
"slice"
] |
python reading lines w/o \n? | 509,446 | <p>Would this work on all platforms? i know windows does \r\n, and remember hearing mac does \r while linux did \n. I ran this code on windows so it seems fine, but do any of you know if its cross platform?</p>
<pre><code>while 1:
line = f.readline()
if line == "":
break
line = line[:-1]
print ... | 3 | 2009-02-03T23:23:57Z | 509,482 | <p>First of all, there is <a href="https://www.python.org/dev/peps/pep-0278/" rel="nofollow">universal newline support</a></p>
<p>Second: just use <code>line.strip()</code>. Use <code>line.rstrip('\r\n')</code>, if you want to preserve any whitespace at the beginning or end of the line.</p>
<p>Oh, and</p>
<pre><code... | 13 | 2009-02-03T23:34:39Z | [
"python",
"file",
"newline"
] |
python reading lines w/o \n? | 509,446 | <p>Would this work on all platforms? i know windows does \r\n, and remember hearing mac does \r while linux did \n. I ran this code on windows so it seems fine, but do any of you know if its cross platform?</p>
<pre><code>while 1:
line = f.readline()
if line == "":
break
line = line[:-1]
print ... | 3 | 2009-02-03T23:23:57Z | 509,485 | <p>Try this instead:</p>
<pre><code>line = line.rstrip('\r\n')
</code></pre>
| 4 | 2009-02-03T23:35:03Z | [
"python",
"file",
"newline"
] |
python reading lines w/o \n? | 509,446 | <p>Would this work on all platforms? i know windows does \r\n, and remember hearing mac does \r while linux did \n. I ran this code on windows so it seems fine, but do any of you know if its cross platform?</p>
<pre><code>while 1:
line = f.readline()
if line == "":
break
line = line[:-1]
print ... | 3 | 2009-02-03T23:23:57Z | 509,827 | <blockquote>
<p>line = line[:-1]</p>
</blockquote>
<p>A line can have no trailing newline, if it's the last line of a file.</p>
<p>As suggested above, try universal newlines with rstrip().</p>
| 0 | 2009-02-04T02:05:33Z | [
"python",
"file",
"newline"
] |
Python M2Crypto - generating a DSA key pair and separating public/private components | 509,449 | <p>Could anybody explain what is the cause of the following:</p>
<pre><code>>>> from M2Crypto import DSA, BIO
>>> dsa = DSA.gen_params(1024)
..+........+++++++++++++++++++++++++++++++++++++++++++++++++++*
............+.+.+..+.........+.............+.....................+.
...+.............+............. | 2 | 2009-02-03T23:25:04Z | 509,633 | <p>Call dsa.gen_key(), then save. You aren't actually generating the public key.</p>
<pre><code>>>> from M2Crypto import DSA, BIO
>>> dsa = DSA.gen_params(1024)
..+..etc
>>> mem = BIO.MemoryBuffer()
>>> dsa.gen_key()
>>> dsa.save_key_bio(mem, cipher=None)
1
>>> dsa... | 7 | 2009-02-04T00:35:25Z | [
"python",
"cryptography",
"rsa",
"m2crypto"
] |
Python quotient vs remainder | 509,710 | <p>The python 2.6 docs state that <code>x % y</code> is defined as the remainder of x / y (<a href="http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex" rel="nofollow">http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex</a>). I am not clear on what is really o... | -2 | 2009-02-04T01:05:46Z | 509,721 | <p>Modulo is performed in the integer context, not fractional (remainders are integers). Therefore:</p>
<pre><code>1 % 1 = 0 (1 times 1 plus 0)
1 % 2 = 1 (2 times 0 plus 1)
1 % 3 = 1 (3 times 0 plus 1)
6 % 3 = 0 (3 times 2 plus 0)
7 % 3 = 1 (3 times 2 plus 1)
8 % 3 = 2 (3 times 2 plus 2)
etc
</code></pre>
... | 10 | 2009-02-04T01:10:12Z | [
"python",
"modulo"
] |
Python quotient vs remainder | 509,710 | <p>The python 2.6 docs state that <code>x % y</code> is defined as the remainder of x / y (<a href="http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex" rel="nofollow">http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex</a>). I am not clear on what is really o... | -2 | 2009-02-04T01:05:46Z | 509,724 | <p>Wouldn't dividing 1 by an number larger than it result in 0 with remainder 1?</p>
<p>The number theorists in the crowd may correct me, but I think modulus/remainder is defined only on integers.</p>
| 3 | 2009-02-04T01:11:49Z | [
"python",
"modulo"
] |
Python quotient vs remainder | 509,710 | <p>The python 2.6 docs state that <code>x % y</code> is defined as the remainder of x / y (<a href="http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex" rel="nofollow">http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex</a>). I am not clear on what is really o... | -2 | 2009-02-04T01:05:46Z | 509,764 | <p>I think you can get the result you want by doing something like this:</p>
<pre><code>for i in range(2, 11):
print 1.0*(1 % i) / i
</code></pre>
<p>This computes the (integer) remainder as explained by others. Then you divide by the denominator again, to produce the fractional part of the quotient.</p>
<p>Note... | 8 | 2009-02-04T01:37:06Z | [
"python",
"modulo"
] |
Python quotient vs remainder | 509,710 | <p>The python 2.6 docs state that <code>x % y</code> is defined as the remainder of x / y (<a href="http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex" rel="nofollow">http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex</a>). I am not clear on what is really o... | -2 | 2009-02-04T01:05:46Z | 509,836 | <p>You've confused <a href="http://en.wikipedia.org/wiki/Division_(mathematics)" rel="nofollow">division</a> and <a href="http://en.wikipedia.org/wiki/Modular_arithmetic" rel="nofollow">modulus</a>.</p>
<p>"0.5, 0.333333, 0.25" etc. as I expected (1/2 = 0.5, etc)."</p>
<p>That's the result of <em>division</em>. </p>... | 4 | 2009-02-04T02:08:57Z | [
"python",
"modulo"
] |
Change directory to the directory of a Python script | 509,742 | <p>How do i change directory to the directory with my python script in? So far I figured out I should use <code>os.chdir</code> and <code>sys.argv[0]</code>. I'm sure there is a better way then to write my own function to parse argv[0].</p>
| 4 | 2009-02-04T01:24:43Z | 509,754 | <pre><code>os.chdir(os.path.dirname(__file__))
</code></pre>
| 14 | 2009-02-04T01:30:18Z | [
"python",
"scripting",
"directory"
] |
Change directory to the directory of a Python script | 509,742 | <p>How do i change directory to the directory with my python script in? So far I figured out I should use <code>os.chdir</code> and <code>sys.argv[0]</code>. I'm sure there is a better way then to write my own function to parse argv[0].</p>
| 4 | 2009-02-04T01:24:43Z | 509,987 | <p>Sometimes <code>__file__</code> is not defined, in this case you can try <code>sys.path[0]</code></p>
| 4 | 2009-02-04T03:47:25Z | [
"python",
"scripting",
"directory"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.