Dataset Viewer
Auto-converted to Parquet Duplicate
prefix
stringclasses
1 value
input_text
stringlengths
10
172
target_text
stringlengths
18
33.9k
QA:
How can I find the full path to a font from its display name on a Mac?
<p>open up a terminal (Applications-&gt;Utilities-&gt;Terminal) and type this in:</p> <pre><code>locate InsertFontHere<br></code></pre> <p>This will spit out every file that has the name you want.</p> <p>Warning: there may be alot to wade through.</p>
QA:
How can I find the full path to a font from its display name on a Mac?
<p>I haven't been able to find anything that does this directly. I think you'll have to iterate through the various font folders on the system: <code>/System/Library/Fonts</code>, <code>/Library/Fonts</code>, and there can probably be a user-level directory as well <code>~/Library/Fonts</code>.</p>
QA:
Get a preview JPEG of a PDF on Windows?
<p>You can use ImageMagick's convert utility for this, see some examples in <a href="https://web.archive.org/web/20120413111338/http://studio.imagemagick.org/pipermail/magick-users/2002-May/002636.html" rel="nofollow">http://studio.imagemagick.org/pipermail/magick-users/2002-May/002636.html</a> :</p> <blockquote> <pre...
QA:
Continuous Integration System for a Python Codebase
<p>One possibility is Hudson. It's written in Java, but there's integration with Python projects:</p> <blockquote> <p><a href="http://redsolo.blogspot.com/2007/11/hudson-embraces-python.html" rel="nofollow">Hudson embraces Python</a></p> </blockquote> <p>I've never tried it myself, however.</p> <p>(<strong>Update...
QA:
Continuous Integration System for a Python Codebase
<p>We run <a href="http://buildbot.net/trac">Buildbot - Trac</a> at work, I haven't used it too much since my code base 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>
QA:
cx_Oracle: How do I iterate over a result set?
<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...
QA:
Continuous Integration System for a Python Codebase
<p>Second the Buildbot - Trac integration. You can find more information about the integration on the <a href="http://buildbot.net/trac/wiki/BuildbotAndTrac">Buildbot website</a>. At my previous job, we wrote and used the plugin they mention (tracbb). What the plugin does is rewriting all of the Buildbot urls so you c...
QA:
Using 'in' to match an attribute of Python objects in an array
<p>No, you were not dreaming. Python has a pretty excellent list comprehension system that lets you manipulate lists pretty elegantly, and depending on exactly what you want to accomplish, this can be done a couple of ways. In essence, what you're doing is saying "For item in list if criteria.matches", and from that ...
QA:
Using 'in' to match an attribute of Python objects in an array
<p>I think:</p> <pre><code>#!/bin/python<br>bar in dict(Foo)<br></code></pre> <p>Is what you are thinking of. When trying to see if a certain key exists within a dictionary in python (python's version of a hash table) there are two ways to check. First is the <strong><code>has_key()</code></strong> method attac...
QA:
Using 'in' to match an attribute of Python objects in an array
<p>Are you looking to get a list of objects that have a certain attribute? If so, a <a href="http://docs.python.org/tut/node7.html#SECTION007140000000000000000">list comprehension</a> is the right way to do this.</p> <pre><code>result = [obj for obj in listOfObjs if hasattr(obj, 'attributeName')]<br></code></pre>
QA:
Using 'in' to match an attribute of Python objects in an array
<p>What I was thinking of can be achieved using list comprehensions, but I thought that there was a function that did this in a slightly neater way.</p> <p>i.e. 'bar' is a list of objects, all of which have the attribute 'id'</p> <p>The mythical functional way:</p> <pre><code>foo = 12<br>foo in iter_attr(bar, ...
QA:
Class views in Django
<p>Sounds to me like you're trying to combine things that shouldn't be combined. If you need to do different processing in your view depending on if it's a User or Group object you're trying to look at then you should use two different view functions.</p> <p>On the other hand there can be common idioms you'd want t...
QA:
Python and MySQL
<p>I don't have any experience with <a href="http://www.SiteGround.com" rel="nofollow">http://www.SiteGround.com</a> as a web host personally. </p> <p>This is just a guess, but it's common for a shared host to support Python and MySQL with the MySQLdb module (e.g., GoDaddy does this). Try the following CGI script ...
QA:
How do I use Python's itertools.groupby()?
<p>Can you show us your code?</p> <p>The example on the Python docs is quite straightforward:</p> <pre><code>groups = [] uniquekeys = [] for k, g in groupby(data, keyfunc): groups.append(list(g)) # Store group iterator as a list uniquekeys.append(k) </code></pre> <p>So in your case, data is a list of no...
QA:
Python and MySQL
<p>I uploaded it and got an internal error</p> <pre><code>Premature end of script headers<br></code></pre> <p>After much playing around, I found that if I had</p> <pre><code>import cgi<br>import cgitb; cgitb.enable()<br>import MySQLdb<br></code></pre> <p>It would give me a much more useful answer and say th...
QA:
Adding a Method to an Existing Object Instance
<p>In Python monkey patching generally works by overwriting a class or functions signature with your own. Below is an example from the <a href="http://wiki.zope.org/zope2/MonkeyPatch">Zope Wiki</a>:</p> <pre><code>from SomeOtherProduct.SomeModule import SomeClass<br>def speak(self):<br> return "ook ook eee eee eee...
QA:
Adding a Method to an Existing Object Instance
<p>I don't know Python syntax, but I know Ruby can do it, and it is rather trivial. Let's say you want to add a method to Array that prints the length to standard out:</p> <pre><code>class Array<br> def print_length<br> puts length<br> end<br>end<br></code></pre> <p>If you don't want to modify the whole cla...
QA:
How do you express binary literals in Python?
<p>As far as I can tell Python, up through 2.5, only supports hexadecimal &amp; octal literals. I did find some discussions about adding binary to future versions but nothing definite.</p>
QA:
How do you express binary literals in Python?
<p>I am pretty sure this is one of the things due to change in Python 3.0 with perhaps bin() to go with hex() and oct().</p> <p>EDIT: lbrandy's answer is correct in all cases.</p>
QA:
How do you express binary literals in Python?
<pre><code>&gt;&gt;&gt; print int('01010101111',2) 687 &gt;&gt;&gt; print int('11111111',2) 255 </code></pre> <p>Another way.</p>
QA:
Python and MySQL
<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 ...
QA:
Any experiences with Protocol Buffers?
<P>If you are looking for user facing interaction, stick with xml. It has more support, understanding, and general acceptance currently. If it's internal, I would say that protocol buffers are a great idea.</P> <P>Maybe in a few years as more tools come out to support protocol buffers, then start looking towards that ...
QA:
How do I make a menu that does not require the user to press [enter] to make a selection?
<p><strong>On Linux:</strong></p> <ul> <li>set raw mode</li> <li>select and read the keystroke</li> <li>restore normal settings</li> </ul> <pre> import sys import select import termios import tty def getkey(): old_settings = termios.tcgetattr(sys.stdin) tty.setraw(sys.stdin.fileno()) select.select([sys.s...
QA:
How do I make a menu that does not require the user to press [enter] to make a selection?
<p><strong>On Windows:</strong></p> <pre><code>import msvcrt answer=msvcrt.getch() </code></pre>
QA:
How to check what OS am I running on in Python?
<pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; print 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>See: <a href="https://docs.python.org/2/library/platform.html">platform — Access to underlying platform’s ident...
QA:
How do I make a menu that does not require the user to press [enter] to make a selection?
<p>Wow, that took forever. Ok, here's what I've ended up with </p> <pre><code>#!C:\python25\python.exe<br>import msvcrt<br>print """Menu<br>1) Say Foo <br>2) Say Bar"""<br>while 1:<br> char = msvcrt.getch()<br> if char == chr(27): #escape<br> break<br> if char == "1":<br> print "foo"<br> ...
QA:
How to check what OS am I running on in Python?
<p>Dang -- lbrandy beat me to the punch, but that doesn't mean I can't provide you with the system results for Vista!</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.name 'nt' &gt;&gt;&gt; import platform &gt;&gt;&gt; platform.system() 'Windows' &gt;&gt;&gt; platform.release() 'Vista' </code></pre>
QA:
How to check what OS am I running on in Python?
<p>For the record here's the results on Mac:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.name 'posix' &gt;&gt;&gt; import platform &gt;&gt;&gt; platform.system() 'Darwin' &gt;&gt;&gt; platform.release() '8.11.1' </code></pre>
QA:
How do I make a menu that does not require the user to press [enter] to make a selection?
<p>The reason msvcrt fails in IDLE is because IDLE is not accessing the library that runs msvcrt. Whereas when you run the program natively in cmd.exe it works nicely. For the same reason that your program blows up on Mac and Linux terminals.</p> <p>But I guess if you're going to be using this specifically for wind...
QA:
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
<p>The list [1,2,3] is dynamic and flexible but that flexibility comes at a speed cost.</p> <p>The tuple (1,2,3) is fixed (immutable) and therefore faster.</p>
QA:
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
<p>From the <a href="http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types">Python FAQ</a>:</p> <blockquote> <p>Lists and tuples, while similar in many respects, are generally used in fundamentally different ways. Tuples can be thought of as being similar to Pascal records or C s...
QA:
File size differences after copying a file to a server vía FTP
<p>Do you need to open the locfile in binary using <code>rb</code>?</p> <pre><code>f = open (locfile, "rb") </code></pre>
QA:
File size differences after copying a file to a server vía FTP
<p>Well if you go under the properties of your file in Windows or a *nix environment, you will notice two sizes. One is the sector size, and one is the actual size. The sector size is the number of sectors in bytes that are used up on your hard disk. That is because two files cannot be in the same sector with most m...
QA:
File size differences after copying a file to a server vía FTP
<p>Small files take up a whole node on the filesystem whatever size that is.</p> <p>My host tends to report all small files as 4kb in ftp but in a shell gives an accurate size so it might be a 'feature' common to ftp clients.</p>
QA:
How can I create a directly-executable cross-platform GUI app using Python?
<p>First you will need some GUI library with Python bindings and then (if you want) some program that will convert your python scripts into standalone executables.</p> <p><strong>Cross-platform GUI libraries with Python bindings (Windows, Linux, Mac)</strong></p> <p>Of course, there are many, but the most popular tha...
QA:
How can I create a directly-executable cross-platform GUI app using Python?
<p>You don't need to <em>compile</em> python for Mac/Windows/Linux. It is an interpreted language, so you simply need to have the Python interpreter installed on the system of your choice (it is available for all three platforms).</p> <p>As for a GUI library that works cross platform, Python's <a href="http://www.t...
QA:
How can I create a directly-executable cross-platform GUI app using Python?
<p>Since python is installed on nearly every non-Windows OS by default now, the only thing you really need to make sure of is that all of the non-standard libraries you use are installed.</p> <p>Having said that, it is possible to build executables that include the python interpreter, and any libraries you use. Thi...
QA:
Adding a Method to an Existing Object Instance
<p>In Python, there is a difference between functions and bound methods.</p> <pre><code>&gt;&gt;&gt; def foo(): ... print "foo" ... &gt;&gt;&gt; class A: ... def bar( self ): ... print "bar" ... &gt;&gt;&gt; a = A() &gt;&gt;&gt; foo &lt;function foo at 0x00A98D70&gt; &gt;&gt;&gt; a.bar &lt;bound method...
QA:
How can I find the full path to a font from its display name on a Mac?
<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 na...
QA:
Calling a function of a module from a string with the function's name in Python
<p>Assuming module <code>foo</code> with method <code>bar</code>:</p> <pre><code>import foo methodToCall = getattr(foo, 'bar') result = methodToCall() </code></pre> <p>As far as that goes, lines 2 and 3 can be compressed to:</p> <pre><code>result = getattr(foo, 'bar')() </code></pre> <p>if that makes more sense for...
QA:
Programmatically talking to a Serial Port in OS X or Linux
<p>have you tried watching the traffic between the GUI and the serial port to see if there is some kind of special command being sent across? Also just curious, Python is sending ASCII and not UTF-8 or something else right? The reason I ask is because I noticed your quote changes for the strings and in some languages...
QA:
Programmatically talking to a Serial Port in OS X or Linux
<p><code>/dev/cu.xxxxx</code> is the "callout" device, it's what you use when you establish a connection to the serial device and start talking to it. <code>/dev/tty.xxxxx</code> is the "dialin" device, used for monitoring a port for incoming calls for e.g. a fax listener.</p>
QA:
Class views in Django
<p>If you're simply displaying data from models, why not use the <a href="https://docs.djangoproject.com/en/1.2/ref/generic-views/" rel="nofollow">Django Generic Views</a>? They're designed to let you easy show data from a model without having to write your own view and stuff about mapping URL paramaters to views, fetc...
QA:
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
<p>Tuples are a quick\flexible way to create <em>composite</em> data-types. Lists are containers for, well, lists of objects.</p> <p>For example, you would use a List to store a list of student details in a class.</p> <p>Each student detail in that list may be a 3-tuple containing their roll number, name and tes...
QA:
Adding a Method to an Existing Object Instance
<p>What you're looking for is <code>setattr</code> I believe. Use this to set an attribute on an object.</p> <pre><code>&gt;&gt;&gt; def printme(s): print repr(s)<br>&gt;&gt;&gt; class A: pass<br>&gt;&gt;&gt; setattr(A,'printme',printme)<br>&gt;&gt;&gt; a = A()<br>&gt;&gt;&gt; a.printme() # s becomes the implicit '...
QA:
Calling a function of a module from a string with the function's name in Python
<p>Patrick's solution is probably the cleanest. If you need to dynamically pick up the module as well, you can import it like:</p> <pre><code>m = __import__ ('foo') func = getattr(m,'bar') func() </code></pre>
QA:
How to sell Python to a client/boss/person with lots of cash
<p>Focus on the shorter time needed for development/prototype and possibly easier maintenance (none of this may apply against Ruby).</p>
QA:
How to sell Python to a client/boss/person with lots of cash
<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 ...
QA:
How to sell Python to a client/boss/person with lots of cash
<p>I would consider that using python on a new project is completely dependent on what problem you are trying to solve with python. If you want someone to agree with you that you should use python, then show them how python's features apply specifically to that problem.</p> <p>In the case of web development with py...
QA:
How do you set up Python scripts to work in Apache 2.0?
<p>There are two main ways of running Python on Apache. The simplest would be to use CGI and write normal Python scripts while the second is using a web framework like Django or Pylons.</p> <p>Using CGI is straightforward. Make sure your Apache config file has a cgi-bin set up. If not, follow their documentation (<a h...
QA:
How do you set up Python scripts to work in Apache 2.0?
<p>Yes, mod_python is pretty confusing to set up. Here's how I did it.</p> <p>In httpd.conf:</p> <pre><code>LoadModule python_module modules/mod_python.so<br><br>&lt;Directory "/serverbase/htdocs/myapp"&gt;<br> AddHandler mod_python .py<br> PythonHandler myapp<br> PythonDebug On<br></code></pre> <p>and in ...
QA:
How do you set up Python scripts to work in Apache 2.0?
<p>Are you running Python on UNIX or Windows?</p> <p>An alternative to mod_python and FastCGI is mod_wsgi. You can find out more at <a href="http://code.google.com/p/modwsgi/" rel="nofollow">modwsgi</a></p> <p>I have built and installed this on Solaris without problems. I had previously tried mod_python but ran into ...
QA:
Does anyone have experience creating a shared library in MATLAB?
<p>I won't help much but I remember that I was able to wrap MATLAB simulation into DLL and then call it from Delphi app. It work really well.</p> <p>Anyway: good luck!!!</p>
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<p>erm.. HTML? (trying to be funny here... while we wait for real answers..)</p>
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<p>The <a href="http://www.wxwidgets.org/" rel="nofollow" title="wxWidgets">wxWidgets</a> (formerly known as wxWindows) library might be what you're looking for. There's a particularly good port for Python, <a href="http://wxpython.org/" rel="nofollow" title="wxPython">wxPython</a>, as well as versions for different la...
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<P>Not sure if this is what you're looking for, but there's <A href="http://glade.gnome.org/" rel="nofollow">Glade</A> (or <A href="http://gladewin32.sourceforge.net/" rel="nofollow">Windows download</A>) which is a designer for GTK+. It generates an XML file which can then be used to build the GUI in a number of diffe...
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<p><a href="http://en.wikipedia.org/wiki/Qt_%28toolkit%29">Qt</a> (pronounced "cute" by its creators[1]) is a cross-platform application development framework, widely used for the development of GUI programs.</p> <p>Qt uses <strong>C++</strong> with several non-standard extensions implemented by an additional pre-pr...
QA:
Python, Unicode, and the Windows console
<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">Pri...
QA:
Convert Bytes to Floating Point Numbers in Python
<p>You'll want the <a href="https://docs.python.org/3.4/library/struct.html" rel="nofollow">struct</a> package.</p>
QA:
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
<P>As others have mentioned, Lists and tuples are both containers which can be used to store python objects. Lists are extensible and their contents can change by assignment, on the other hand tuples are immutable.</P> <P>Also, lists cannot be used as keys in a dictionary whereas tuples can. </P>
QA:
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
<p>If you can find a solution that works with tuples, use them, as it forces immutability which kind of drives you down a more functional path. You almost never regret going down the functional/immutable path.</p>
QA:
Get size of a file before downloading in Python
<p>The size of the file is sent as the Content-Length header. Here is how to get it with urllib:</p> <pre><code>&gt;&gt;&gt; site = urllib.urlopen("http://python.org")<br>&gt;&gt;&gt; meta = site.info()<br>&gt;&gt;&gt; print meta.getheaders("Content-Length")<br>['16535']<br>&gt;&gt;&gt;<br></code></pre>
QA:
Get size of a file before downloading in Python
<p>Using the returned-urllib-object method <code>info()</code>, you can get various information on the retrived document. Example of grabbing the current Google logo:</p> <pre><code>&gt;&gt;&gt; import urllib<br>&gt;&gt;&gt; d = urllib.urlopen("http://www.google.co.uk/logos/olympics08_opening.gif")<br>&gt;&gt;&gt; p...
QA:
Get size of a file before downloading in Python
<p>Also if the server you are connecting to supports it, look at <a href="http://en.wikipedia.org/wiki/HTTP_ETag" rel="nofollow">Etags</a> and the <a href="http://en.wikipedia.org/wiki/List_of_HTTP_headers#Requests" rel="nofollow">If-Modified-Since</a> and <a href="http://en.wikipedia.org/wiki/List_of_HTTP_headers#Requ...
QA:
Get size of a file before downloading in Python
<p>I have reproduced what you are seeing:</p> <pre><code>import urllib, os<br>link = "http://python.org"<br>print "opening url:", link<br>site = urllib.urlopen(link)<br>meta = site.info()<br>print "Content-Length:", meta.getheaders("Content-Length")[0]<br><br>f = open("out.txt", "r")<br>print "File on disk:",len(f.r...
QA:
Best way to abstract season/show/episode data
<p>Why not use SQLite? There is good support in Python and you can write SQL queries to get the data out. Here is the Python docs for <a href="http://docs.python.org/lib/module-sqlite3.html" rel="nofollow">sqlite3</a></p> <hr> <p>If you don't want to use SQLite you could do an array of dicts.</p> <pre><code>ep...
QA:
Any experiences with Protocol Buffers?
<p>Protocol buffers are intended to optimize communications between machines. They are really not intended for human interaction. Also, the format is binary, so it could not replace XML in that use case. </p> <p>I would also recommend <a href="http://en.wikipedia.org/wiki/JSON">JSON</a> as being the most compact tex...
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<p><a href="http://www.mozilla.org/projects/xul/" rel="nofollow">XML User Interface Language</a>. Don't know much about it so not sure if it meets your desires. Post back with your experience if you play with it.</p>
QA:
Best way to abstract season/show/episode data
<P>I have done something similar in the past and used an in-memory XML document as a quick and dirty hierachical database for storage. You can store each show/season/episode as an element (nested appropriately) and attributes of these things as xml attributes on the elements. Then you can use XQuery to get info back ou...
QA:
Get a preview JPEG of a PDF on Windows?
<p>Is the PC likely to have Acrobat installed? I think Acrobat installs a shell extension so previews of the first page of a PDF document appear in Windows Explorer's thumbnail view. You can get thumbnails yourself via the IExtractImage COM API, which you'll need to wrap. <a href="http://www.vbaccelerator.com/home/net/...
QA:
Get a preview JPEG of a PDF on Windows?
<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...
QA:
How do I use Python's itertools.groupby()?
<p>As Sebastjan said, <strong>you first have to sort your data. This is important.</strong></p> <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 uniquekeys.append...
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<p>I read a little on XML User Interface Language (XUL) and it looks really robust and well supported. The main problem for me is it's tied to the Gecko rendering engine so it's cross platform the way wxWidgets, QT and GTK+ are cross platform. Also, there Python bindings don't seem as good as those other libraries.</p>...
QA:
Python, Unicode, and the Windows console
<p>The cause of your problem is <strong>NOT</strong> the Win console not willing to accept Unicode (as it does this since I guess Win2k by default). It is the default system encoding. Try this code and see what it gives you:</p> <pre><code>import sys sys.getdefaultencoding() </code></pre> <p>if it says ascii, there's...
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<p>@Cristian and Antony Cramp: while XUL is a nice choice for UI development (cross-platform, open-source licensed, used in Firefox and other major software), it's certainly not language agnostic. You're tied to Gecko, with JS for scripting. There is experimental support for Python scripting, but it's only experimental...
QA:
Cross Platform, Language Agnostic GUI Markup Language?
<p>I seriously doubt you're going to find a markup language for GIU's that's <em>not</em> tied to a specific library. For such a thing to exist, there would need to be a standardized GUI markup language, with several implementations.</p>
QA:
Best way to abstract season/show/episode data
<p>I don't get this part here:</p> <blockquote> <p>This worked okay, but there was no easy way of checking if x[3][24] was supposed to exist or not (so I couldn't raise the season<em>not</em>found exception)</p> </blockquote> <p>There is a way to do it - called <strong>in</strong>:</p> <pre><code>&gt;&gt;&gt;x={} ...
QA:
Class views in Django
<p>Unless you want to do something a little complex, using the generic views are the way to go. They are far more powerful than their name implies, and if you are just displaying model data generic views will do the job.</p>
QA:
Python and MySQL
<p>You could try setting up your own python installation using <a href="http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python" rel="nofollow">Virtual Python</a>. Check out how to setup Django using it <a href="http://forums.site5.com/showthread.php?t=10236" rel="nofollow">here</a>. That was wr...
QA:
How to use Xpath in Python?
<p>The <a href="http://lxml.de/">lxml package</a> supports xpath. It seems to work pretty well, although I've had some trouble with the self:: axis. There's also <a href="http://pypi.python.org/pypi/Amara/1.1.6">Amara</a>, but I haven't used it personally.</p>
QA:
Accessing mp3 Meta-Data with Python
<p><a href="http://www.dotfunk.com/projects/mp3/" rel="nofollow">This toolkit</a> may do what you need. I can't say if it's the "best", but really, if it does what you need, that's all that matters, right?</p> <p>HTH</p>
QA:
Accessing mp3 Meta-Data with Python
<p>A simple example from the book Dive Into Python works ok for me, <a href="http://www.diveintopython.org/download/diveintopython-examples-5.4.zip" rel="nofollow">this</a> is the download link, the example is fileinfo.py. Don't know if it's the best, but it can do the basic job.</p> <p>The entire book is available on...
QA:
Accessing mp3 Meta-Data with Python
<p>It can depend on exactly what you want to do in addition to reading the metadata. If it is just simply the bitrate / name etc. that you need, and nothing else, something lightweight is probably best.</p> <p>If you're manipulating the mp3 past that PyMedia may be suitable.</p> <p>There are quite a few, whatever you...
QA:
Best way to abstract season/show/episode data
<p>Bartosz/To clarify "This worked okay, but there was no easy way of checking if x[3][24] was supposed to exist or not"</p> <p><code>x['some show'][3][24]</code> would return season 3, episode 24 of "some show". If there was no season 3, I want the pseudo-dict to raise tvdb<em>seasonnotfound, if "some show" doesn't e...
QA:
How to use Xpath in Python?
<p><a href="http://pyxml.sourceforge.net" rel="nofollow" title="PyXML">PyXML</a> works well. </p> <p>You didn't say what platform you're using, however if you're on Ubuntu you can get it with <code>sudo apt-get install python-xml</code>. I'm sure other Linux distros have it as well. </p> <p>If you're on a Mac, xpa...
QA:
Accessing mp3 Meta-Data with Python
<p>What you're after is the <a href="http://id3-py.sourceforge.net/">ID3</a> module. It's very simple and will give you exactly what you need. Just copy the ID3.py file into your site-packages directory and you'll be able to do something like the following:</p> <pre><code>from ID3 import * try: id3info = ID3('file...
QA:
How do I treat an integer as an array of bytes in Python?
<p>This will do what you want:</p> <pre><code>signum = status &amp; 0xff exitstatus = (status &amp; 0xff00) &gt;&gt; 8 </code></pre>
QA:
How do I treat an integer as an array of bytes in Python?
<p>You can unpack the status using <a href="http://docs.python.org/ref/shifting.html" rel="nofollow">bit-shifting</a> and <a href="http://docs.python.org/ref/bitwise.html" rel="nofollow">masking</a> operators.</p> <pre><code>low = status &amp; 0x00FF high = (status &amp; 0xFF00) &gt;&gt; 8 </code></pre> <p>I'm not a ...
QA:
How do I treat an integer as an array of bytes in Python?
<p>The folks before me've nailed it, but if you really want it on one line, you can do this:</p> <pre><code>(signum, exitstatus) = (status &amp; 0xFF, (status &gt;&gt; 8) &amp; 0xFF) </code></pre> <p>EDIT: Had it backwards.</p>
QA:
How do I treat an integer as an array of bytes in Python?
<p>To answer your general question, you can use <a href="http://en.wikipedia.org/wiki/Bit_twiddling" rel="nofollow">bit manipulation</a> techniques:</p> <pre><code>pid, status = os.wait() exitstatus, signum = status &amp; 0xFF, (status &amp; 0xFF00) &gt;&gt; 8 </code></pre> <p>However, there are also <a href="http://...
QA:
Best way to abstract season/show/episode data
<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...
QA:
Accessing mp3 Meta-Data with Python
<p>I've used <a href="https://bitbucket.org/lazka/mutagen">mutagen</a> to edit tags in media files before. The nice thing about mutagen is that it can handle other formats, such as mp4, FLAC etc. I've written several scripts with a lot of success using this API.</p>
QA:
How to use Xpath in Python?
<p>The latest version of <a href="http://effbot.org/zone/element-xpath.htm">elementtree</a> supports XPath pretty well. Not being an XPath expert I can't say for sure if the implementation is full but it has satisfied most of my needs when working in Python. I've also use lxml and PyXML and I find etree nice because ...
QA:
How should I unit test a code-generator?
<p>I started writing up a summary of my experience with my own code generator, then went back and re-read your question and found you had already touched upon the same issues yourself, focus on the execution results instead of the code layout/look.</p> <p>Problem is, this is hard to test, the generated code might not ...
QA:
How should I unit test a code-generator?
<p>Yes, results are the ONLY thing that matters. The real chore is writing a framework that allows your generated code to run independently... spend your time there.</p>
QA:
How should I unit test a code-generator?
<p>If you are running on *nux you might consider dumping the unittest framework in favor of a bash script or makefile. on windows you might consider building a shell app/function that runs the generator and then uses the code (as another process) and unittest that.</p> <p>A third option would be to generate the code a...
QA:
How should I unit test a code-generator?
<p>Recall that "unit testing" is only one kind of testing. You should be able to unit test the <strong>internal</strong> pieces of your code generator. What you're really looking at here is system level testing (a.k.a. regression testing). It's not just semantics... there are different mindsets, approaches, expectat...
QA:
How can I create a directly-executable cross-platform GUI app using Python?
<p>An alternative tool to py2exe is <a href="http://pypi.python.org/pypi/bbfreeze/">bbfreeze</a> which generates executables for windows and linux. It's newer than py2exe and handles eggs quite well. I've found it magically works better without configuration for a wide variety of applications.</p>
QA:
How can I create a directly-executable cross-platform GUI app using Python?
<p>I'm not sure that this is the best way to do it, but when I'm deploying Ruby GUI apps (not Python, but has the same "problem" as far as .exe's are concerned) on Windows, I just write a short launcher in C# that calls on my main script. It compiles to an executable, and I then have an application executable.</p>
QA:
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
<p>Whenever I need to pass in a collection of items to a function, if I want the function to not change the values passed in - I use tuples. </p> <p>Else if I want to have the function to alter the values, I use list. </p> <p>Always if you are using external libraries and need to pass in a list of values to a functio...
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
4