Dataset Viewer
Auto-converted to Parquet Duplicate
Search is not available for this dataset
id
int64
469
72M
question
stringlengths
11
150
body
stringlengths
22
48.7k
answer
stringlengths
20
59.4k
embedding
sequencelengths
384
384
535
Continuous Integration System for a Python Codebase
<p>I am starting to work on a hobby project with a <strong>Python</strong> codebase and I would like to set up some form of continuous integration (i.e. running a battery of test-cases each time a check-in is made and sending nag e-mails to responsible persons when the tests fail) similar to <strong>CruiseControl</stro...
<p>We run <a href="http://buildbot.net/trac" rel="noreferrer">Buildbot - Trac</a> at work. I haven't used it too much since my codebase isn't part of the release cycle yet. But we run the tests on different environments (OSX/Linux/Win) and it sends emails β€” and it's written in Python.</p>
[ -0.05872442573308945, -0.04423551261425018, -0.055181585252285004, 0.0013319650897756219, -0.05609998479485512, -0.12781426310539246, -0.07270757108926773, 0.05584420636296272, -0.09619002044200897, 0.011250924319028854, -0.02283351495862007, 0.006450799759477377, 0.08161547780036926, -0.0...
594
cx_Oracle: How do I iterate over a result set?
<p>There are several ways to iterate over a result set. What are the tradeoff of each?</p>
<p>The canonical way is to use the built-in cursor iterator.</p> <pre><code>curs.execute('select * from people') for row in curs: print row </code></pre> <hr> <p>You can use <code>fetchall()</code> to get all rows at once.</p> <pre><code>for row in curs.fetchall(): print row </code></pre> <p>It can be conv...
[ -0.021542774513363838, 0.10579828917980194, -0.0492791086435318, -0.002201908500865102, -0.01329115778207779, 0.04330158978700638, 0.01789134182035923, 0.10232941061258316, 0.04561940208077431, 0.010781007818877697, 0.02089501917362213, 0.024002138525247574, 0.06050004065036774, -0.0717330...
766
Python and MySQL
<p>I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as Django or PySQL, I generally fail when installing them on my computer so maybe it's good I can't install on the host.</p> ...
<p>MySQLdb is what I have used before.</p> <p>If you host is using Python version 2.5 or higher, support for sqlite3 databases is built in (sqlite allows you to have a relational database that is simply a file in your filesystem). But buyer beware, sqlite is not suited for production, so it may depend what you are tr...
[ -0.005056446418166161, -0.0617218017578125, -0.029078692197799683, 0.0380852073431015, -0.10221108794212341, -0.057689134031534195, -0.0004748091159854084, 0.025314636528491974, -0.028782596811652184, -0.010911412537097931, -0.042986128479242325, 0.04879327863454819, 0.08302947878837585, -...
1,829
How do I make a menu that does not require the user to press [enter] to make a selection?
<p>I've got a menu in Python. That part was easy. I'm using <code>raw_input()</code> to get the selection from the user. </p> <p>The problem is that <code>raw_input</code> (and input) require the user to press <kbd>Enter</kbd> after they make a selection. Is there any way to make the program act immediately upon a key...
<p><strong>On Windows:</strong></p> <pre><code>import msvcrt answer=msvcrt.getch() </code></pre>
[ -0.028170861303806305, -0.03516143932938576, -0.00807343702763319, 0.014501090161502361, -0.06017032265663147, -0.010309271514415741, 0.05218518152832985, 0.03913488984107971, -0.0010847625089809299, -0.018306534737348557, 0.013658195734024048, -0.034183043986558914, 0.10658743232488632, -...
2,311
File size differences after copying a file to a server vΓ­a FTP
<p>I have created a PHP-script to update a web server that is live inside a local directory. I'm migrating the script into Python. It works fine for the most part, but after a PUT command, the size of the file appears to change. Thus, the size of the file is different from that of the file on the server. </p> <p>Once ...
<p>Do you need to open the locfile in binary using <code>rb</code>?</p> <pre><code>f = open (locfile, "rb") </code></pre>
[ 0.008465638384222984, -0.012878390960395336, -0.0498034842312336, 0.025510508567094803, 0.07123596221208572, -0.055958181619644165, -0.04330196604132652, 0.04214857891201973, 0.0306306891143322, 0.07248230278491974, 0.02467171847820282, 0.05719351768493652, -0.022725826129317284, -0.044472...
972
Adding a method to an existing object instance in Python
<p>How do I add a method to an existing object (i.e., not in the class definition) in Python?</p> <p>I understand that it's not generally considered good practice to do so, except in some cases.</p>
<p>In Python, there is a difference between functions and bound methods.</p> <pre><code>&gt;&gt;&gt; def foo(): ... print &quot;foo&quot; ... &gt;&gt;&gt; class A: ... def bar( self ): ... print &quot;bar&quot; ... &gt;&gt;&gt; a = A() &gt;&gt;&gt; foo &lt;function foo at 0x00A98D70&gt; &gt;&gt;&gt; a.b...
[ -0.05934213474392891, 0.022202536463737488, -0.04230020195245743, 0.024714544415473938, -0.09349798411130905, -0.05669301748275757, -0.001670153229497373, 0.02238517627120018, -0.0454307496547699, 0.022595416754484177, 0.03989506512880325, 0.07576527446508408, 0.03222396597266197, -0.01146...
1,854
How to identify which OS Python is running on
<p>What do I need to look at to see whether I'm on Windows or Unix, etc.?</p>
<pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.name 'posix' &gt;&gt;&gt; import platform &gt;&gt;&gt; platform.system() 'Linux' &gt;&gt;&gt; platform.release() '2.6.22-15-generic' </code></pre> <p>The output of <a href="https://docs.python.org/library/platform.html#platform.system" rel="noreferrer"><code>platfor...
[ 0.03942202404141426, -0.049274418503046036, -0.047646664083004, -0.04202395677566528, 0.06858862936496735, -0.020487040281295776, 0.02741522341966629, 0.0028701985720545053, -0.001189762493595481, -0.024163609370589256, 0.021461039781570435, -0.010219909250736237, -0.02200360596179962, -0....
469
How can I find the full path to a font from its display name on a Mac?
<p>I am using the Photoshop's javascript API to find the fonts in a given PSD.</p> <p>Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc.</p> <p>This is all happening in a python program running on OSX so I guess I'm looking for one of:</p> <...
<p>Unfortunately the only API that isn't deprecated is located in the ApplicationServices framework, which doesn't have a bridge support file, and thus isn't available in the bridge. If you're wanting to use ctypes, you can use ATSFontGetFileReference after looking up the ATSFontRef.</p> <p>Cocoa doesn't have any nati...
[ -0.11462126672267914, 0.027748119086027145, -0.036889661103487015, 0.025442061945796013, -0.004515254870057106, -0.08879219740629196, 0.010381417348980904, 0.05948428809642792, -0.006306905299425125, -0.07225438207387924, 0.05664337798953056, 0.020010288804769516, 0.07603701949119568, -0.0...
4,942
How to sell Python to a client/boss/person
<p>When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it?</p>
<p>This is one of those cases that really boil down to personal preference or situational details. If you're more comfortable and experienced with Python, then say so. Are they asking you to justify it because they're more comfortable with one of the other environments? After you're done, will the system be passed off ...
[ -0.075514055788517, 0.007503089029341936, -0.09369491040706635, -0.03715220093727112, 0.018824536353349686, -0.0822109803557396, 0.0032141939736902714, 0.06648333370685577, -0.07544343918561935, 0.05732763558626175, 0.015158533118665218, 0.06176063418388367, 0.07255249470472336, -0.0374175...
5,419
Python, Unicode, and the Windows console
<p>When I try to <code>print</code> a string in a Windows console, sometimes I get an error that says <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code>. I assume this is because the Windows console cannot handle all Unicode characters.</p> <p>How can I work around this? For example, how can I...
<p><strong>Note:</strong> This answer is sort of outdated (from 2008). Please use the solution below with care!!</p> <hr> <p>Here is a page that details the problem and a solution (search the page for the text <em>Wrapping sys.stdout into an instance</em>):</p> <p><a href="http://wiki.python.org/moin/PrintFails" rel...
[ 0.0025160349905490875, -0.05243263766169548, -0.025348931550979614, 0.028634754940867424, -0.10519483685493469, 0.018387198448181152, -0.042757805436849594, -0.007403934840112925, -0.013411211781203747, 0.0029275782871991396, 0.04941261187195778, -0.011644736863672733, 0.05396382138133049, ...
5,909
Get size of a file before downloading in Python
<p>I'm downloading an entire directory from a web server. It works OK, but I can't figure how to get the file size before download to compare if it was updated on the server or not. Can this be done as if I was downloading the file from a FTP server?</p> <pre><code>import urllib import re url = "http://www.someurl.co...
<p>I have reproduced what you are seeing:</p> <pre><code>import urllib, os link = "http://python.org" print "opening url:", link site = urllib.urlopen(link) meta = site.info() print "Content-Length:", meta.getheaders("Content-Length")[0] f = open("out.txt", "r") print "File on disk:",len(f.read()) f.close() f = ope...
[ 0.0069312299601733685, 0.04520424082875252, -0.03435501828789711, 0.08599794656038284, 0.04702037572860718, -0.087661974132061, -0.017674246802926064, 0.05503243952989578, 0.010930675081908703, 0.05142443999648094, 0.024842802435159683, 0.07179050147533417, -0.03398341313004494, -0.0749770...
773
How do I use itertools.groupby()?
<p>I haven't been able to find an understandable explanation of how to actually use Python's <code>itertools.groupby()</code> function. What I'm trying to do is this:</p> <ul> <li>Take a list - in this case, the children of an objectified <code>lxml</code> element</li> <li>Divide it into groups based on some criteria<...
<p><strong>IMPORTANT NOTE:</strong> You <em>may</em> have to <strong>sort your data</strong> first.</p> <hr /> <p>The part I didn't get is that in the example construction</p> <pre><code>groups = [] uniquekeys = [] for k, g in groupby(data, keyfunc): groups.append(list(g)) # Store group iterator as a list uniq...
[ -0.09724272042512894, 0.02429025061428547, 0.027550822123885155, 0.002642358187586069, 0.03149470314383507, -0.0014979798579588532, 0.04510776698589325, -0.01710405945777893, -0.06999397277832031, -0.03494247421622276, 0.036102768033742905, -0.017169157043099403, 0.03113550692796707, -0.07...
502
Get a preview JPEG of a PDF on Windows?
<p>I have a cross-platform (Python) application which needs to generate a JPEG preview of the first page of a PDF.</p> <p>On the Mac I am spawning <a href="http://web.archive.org/web/20090309234215/http://developer.apple.com:80/documentation/Darwin/Reference/ManPages/man1/sips.1.html" rel="noreferrer">sips</a>. Is th...
<p>ImageMagick delegates the PDF->bitmap conversion to GhostScript anyway, so here's a command you can use (it's based on the actual command listed by the <code>ps:alpha</code> delegate in ImageMagick, just adjusted to use JPEG as output):</p> <pre><code>gs -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT \ -dM...
[ -0.07626603543758392, -0.016132481396198273, -0.03482050076127052, 0.004131009802222252, 0.061187129467725754, -0.08954198658466339, -0.08742201328277588, -0.00883434060961008, -0.024882376194000244, -0.09493515640497208, -0.006579338572919369, -0.004245436284691095, 0.06389964371919632, 0...
5,966
Best way to abstract season/show/episode data
<p>Basically, I've written an API to www.thetvdb.com in Python. The current code can be found <a href="http://github.com/dbr/tvdb_api/tree/master/tvdb_api.py" rel="noreferrer">here</a>.</p> <p>It grabs data from the API as requested, and has to store the data somehow, and make it available by doing:</p> <pre><code>pr...
<p>OK, what you need is <code>classobj</code> from new module. That would allow you to construct exception classes dynamically (<code>classobj</code> takes a string as an argument for the class name). </p> <pre><code>import new myexc=new.classobj("ExcName",(Exception,),{}) i=myexc("This is the exc msg!") raise i </cod...
[ -0.1041533499956131, 0.020315570756793022, -0.02648266777396202, -0.0024649298284202814, 0.02521594427525997, -0.0781412199139595, -0.031732868403196335, 0.0019574542529881, -0.04468442499637604, -0.03972099348902702, 0.006215882487595081, 0.00046770970220677555, 0.08524303883314133, -0.01...
1,476
How do you express binary literals in Python?
<p>How do you express an integer as a binary number with Python literals?</p> <p>I was easily able to find the answer for hex:</p> <pre><code>&gt;&gt;&gt; 0x12AF 4783 &gt;&gt;&gt; 0x100 256 </code></pre> <p>and octal:</p> <pre><code>&gt;&gt;&gt; 01267 695 &gt;&gt;&gt; 0100 64 </code></pre> <p><strong>How do you us...
<p>For reference&mdash;<em>future</em> Python possibilities:<br> Starting with Python 2.6 you can express binary literals using the prefix <strong>0b</strong> or <strong>0B</strong>:</p> <pre><code>&gt;&gt;&gt; 0b101111 47 </code></pre> <p>You can also use the new <strong>bin</strong> function to get the binary repre...
[ 0.03389197215437889, 0.03416256979107857, -0.016776518896222115, 0.000031027364457258955, -0.03931425139307976, -0.09027628600597382, -0.00674758804962039, 0.06575716286897659, -0.06032461300492287, -0.019955884665250778, -0.05503786727786064, -0.033547669649124146, 0.11389853060245514, 0....
13,941
Python Sound ("Bell")
<p>I'd like to have a python program alert me when it has completed its task by making a beep noise. Currently, I use <code>import os</code> and then use a command line speech program to say &quot;Process complete&quot;. I much rather it be a simple &quot;bell.&quot;</p> <p>I know that there's a function that can be...
<p>Have you tried :</p> <pre><code>import sys sys.stdout.write('\a') sys.stdout.flush() </code></pre> <p>That works for me here on Mac OS 10.5</p> <p>Actually, I think your original attempt works also with a little modification:</p> <pre><code>print('\a') </code></pre> <p>(You just need the single quotes around th...
[ -0.04550822451710701, -0.01719401590526104, 0.028451239690184593, -0.02007727324962616, -0.014286400750279427, -0.041157033294439316, 0.07316304743289948, -0.017142491415143013, -0.06113475561141968, -0.06838344782590866, 0.004882259760051966, -0.06785082817077637, 0.01793815940618515, 0.0...
12,592
Can you check that an exception is thrown with doctest in Python?
<p>Is it possible to write a <code>doctest</code> unit test that will check that an exception is raised?<br /> For example, if I have a function <code>foo(x)</code> that is supposed to raise an exception if <code>x &lt; 0</code>, how would I write the <code>doctest</code> for that?</p>
<p>Yes. You can do it. The <a href="https://docs.python.org/3/library/doctest.html" rel="noreferrer">doctest module documentation</a> and Wikipedia has an <a href="http://en.wikipedia.org/wiki/Doctest#Example_2:_doctests_embedded_in_a_README.txt_file" rel="noreferrer">example</a> of it.</p> <pre><code> &gt;&gt;&gt; ...
[ -0.03350399434566498, 0.04097212851047516, -0.003313262714073062, 0.0022288637701421976, -0.02345469780266285, 0.013247179798781872, -0.08950527757406235, 0.05788271874189377, -0.04340958967804909, 0.0556173138320446, 0.018063656985759735, -0.013497394509613514, 0.13403058052062988, -0.043...
18,418
Elegant way to remove items from sequence in Python?
<p>When I am writing code in Python, I often need to remove items from a list or other sequence type based on some criteria. I haven't found a solution that is elegant and efficient, as removing items from a list you are currently iterating through is bad. For example, you can't do this:</p> <pre><code>for name in na...
<p>Two easy ways to accomplish just the filtering are:</p> <ol> <li><p>Using <code>filter</code>:</p> <p><code>names = filter(lambda name: name[-5:] != "Smith", names)</code></p></li> <li><p>Using list comprehensions:</p> <p><code>names = [name for name in names if name[-5:] != "Smith"]</code></p></li> </ol> <p>Not...
[ -0.08196520805358887, 0.13107861578464508, 0.06869945675134659, -0.02503133751451969, 0.02326507307589054, -0.11552789062261581, 0.06952786445617676, -0.07347093522548676, -0.002908298745751381, 0.007006646599620581, 0.03249647095799446, 0.08862211555242538, 0.021367622539401054, -0.017244...
14,389
Regex and unicode
<p>I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example), grabs the episode name (from the www.thetvdb.com API) and automatically renames them into something nicer (Show Name - [01x02].avi)</p> <p>The script works fine, that is until you try and use it on files that have Unicode s...
<p>Use a subrange of <code>[\u0000-\uFFFF]</code> for what you want.</p> <p>You can also use the <code>re.UNICODE</code> compile flag. <a href="http://docs.python.org/lib/re-syntax.html" rel="noreferrer">The docs</a> say that if <code>UNICODE</code> is set, <code>\w</code> will match the characters <code>[0-9_]</code>...
[ -0.05794582515954971, -0.03245515376329422, 0.05186701938509941, -0.061324771493673325, -0.02776331640779972, 0.05187924578785896, 0.055461663752794266, -0.031919337809085846, 0.0037047092337161303, -0.053434379398822784, -0.01686592772603035, -0.037114232778549194, 0.019623342901468277, 0...
15,798
How do I validate xml against a DTD file in Python
<p>I need to validate an XML string (and not a file) against a DTD description file. </p> <p>How can that be done in <code>python</code>?</p>
<p>Another good option is <a href="http://lxml.de/validation.html" rel="noreferrer">lxml's validation</a> which I find quite pleasant to use.</p> <p>A simple example taken from the lxml site:</p> <pre><code>from StringIO import StringIO from lxml import etree dtd = etree.DTD(StringIO("""&lt;!ELEMENT foo EMPTY&gt;""...
[ -0.043945878744125366, 0.05896557867527008, 0.008077316917479038, -0.061039675027132034, -0.016048654913902283, -0.09339183568954468, 0.0023063323460519314, 0.03164196386933327, -0.037777822464704514, -0.03116982989013195, 0.019609900191426277, -0.025718150660395622, 0.08333678543567657, -...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
213

Spaces using MartinElMolon/stackoverflow_preguntas_con_embeddings 3