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
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
4,595
<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...
10
2008-08-07T11:21:56Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
5,719
<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>
1
2008-08-08T06:06:33Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
5,746
<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>
1
2008-08-08T06:48:52Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
12,454
<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...
2
2008-08-15T16:38:59Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
12,557
<p>The notion of tuples are highly expressive:</p> <ul> <li><p>Pragmatically, they are great for packing and unpacking values (<code>x,y=coord</code>).</p></li> <li><p>In combination with dictionaries (hash tables), they allow forms of mapping that would otherwise require many levels of association. For example, cons...
7
2008-08-15T18:00:37Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
6,477,369
<p>[1, 2, 3] is a list in which one can add or delete items.<br> (1, 2, 3) is a tuple in which once defined, modification cannot be done.</p>
2
2011-06-25T11:14:19Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
26,250,158
<p><code>[1,2,3]</code> is a list.</p> <p><code>(1,2,3)</code> is a tuple and immutable.</p>
1
2014-10-08T06:02:42Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
28,888,938
<p>Basically, <code>(1, 2, 3)</code> is a tuple, while <code>[1, 2, 3]</code> is a list. </p> <p>A tuple is a non-mutable data type which means you are not able to change its contents once it has been created. Tuples are mostly used in order to return more than one value from a function. For example:</p> <pre><code>d...
0
2015-03-05T22:21:55Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
33,058,118
<p>open a console and run python. Try this:</p> <pre><code> &gt;&gt;&gt; list = [1, 2, 3] &gt;&gt;&gt; dir(list) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delsli ce__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getit em__', '__getslice__', '...
1
2015-10-10T19:30:36Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
35,496,153
<p><code>(1,2,3)</code> is a tuple while <code>[1,2,3]</code> is a list. A tuple is an immutable object while a list is mutable.</p>
0
2016-02-19T02:15:31Z
[ "python", "list", "tuples" ]
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
1,983
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p>
31
2008-08-05T07:18:55Z
38,062,967
<p><code>(1,2,3)</code> is a tuple and <code>[1,2,3]</code> is a list. You either of the two represent sequences of numbers but note that tuples are immutable and list are mutable Python objects. </p>
0
2016-06-27T20:48:38Z
[ "python", "list", "tuples" ]
File size differences after copying a file to a server vía FTP
2,311
<p>I have created a PHP-script to update a webserver 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 I ...
26
2008-08-05T13:40:47Z
2,316
<p>Do you need to open the locfile in binary using <code>rb</code>?</p> <pre><code>f = open (locfile, "rb") </code></pre>
14
2008-08-05T13:45:38Z
[ "php", "python", "ftp", "webserver" ]
File size differences after copying a file to a server vía FTP
2,311
<p>I have created a PHP-script to update a webserver 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 I ...
26
2008-08-05T13:40:47Z
2,317
<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...
2
2008-08-05T13:45:47Z
[ "php", "python", "ftp", "webserver" ]
File size differences after copying a file to a server vía FTP
2,311
<p>I have created a PHP-script to update a webserver 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 I ...
26
2008-08-05T13:40:47Z
2,510
<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>
0
2008-08-05T15:59:24Z
[ "php", "python", "ftp", "webserver" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
2,937
<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...
189
2008-08-05T22:34:25Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
2,941
<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...
0
2008-08-05T22:40:17Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
2,980
<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...
2
2008-08-06T00:29:36Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
12,166
<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>
13
2008-08-15T11:56:02Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
12,167
<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>
2
2008-08-15T12:00:37Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
15,938
<p>For the GUI itself:</p> <p><a href="http://wiki.python.org/moin/PyQt" rel="nofollow">PyQT</a> is pretty much the reference.</p> <p>Another way to develop a rapid user interface is to write a web app, have it run locally and display the app in the browser.</p> <p>Plus, if you go for the Tkinter option suggested by...
3
2008-08-19T09:45:44Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
31,859
<p>Another system (not mentioned in the accepted answer yet) is PyInstaller, which worked for a PyQt project of mine when py2exe would not. I found it easier to use.</p> <p><a href="http://www.pyinstaller.org/">http://www.pyinstaller.org/</a></p> <p>Pyinstaller is based on Gordon McMillan's Python Installer. Which is...
39
2008-08-28T08:41:45Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
How can I create a directly-executable cross-platform GUI app using Python?
2,933
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and poi...
171
2008-08-05T22:26:00Z
265,570
<p>There's also <a href="http://pygtk.org/">PyGTK</a>, which is basically a Python wrapper for the Gnome Toolkit. I've found it easier to wrap my mind around than Tkinter, coming from pretty much no knowledge of GUI programming previously. It works pretty well and has some good tutorials. Unfortunately there isn't a...
7
2008-11-05T15:53:19Z
[ "python", "user-interface", "deployment", "tkinter", "release-management" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
3,071
<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...
925
2008-08-06T03:57:16Z
[ "python" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
4,605
<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>
145
2008-08-07T11:35:23Z
[ "python" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
834,451
<pre><code>locals()["myfunction"]() </code></pre> <p>or</p> <pre><code>globals()["myfunction"]() </code></pre> <p><a href="http://docs.python.org/library/functions.html#locals">locals</a> returns a dictionary with a current local symbol table. <a href="http://docs.python.org/library/functions.html#globals">globals</...
266
2009-05-07T12:45:13Z
[ "python" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
9,272,378
<p>For what it's worth, if you needed to pass the function (or class) name and app name as a string, then you could do this:</p> <pre><code>myFnName = "MyFn" myAppName = "MyApp" app = sys.modules[myAppName] fn = getattr(app,myFnName) </code></pre>
12
2012-02-14T05:55:36Z
[ "python" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
12,025,554
<p>Just a simple contribution. If the class that we need to instance is in the same file, we can use something like this:</p> <pre><code># Get class from globals and create an instance m = globals()['our_class']() # Get the function (from the instance) that we need to call func = getattr(m, 'function_name') # Call i...
46
2012-08-19T09:40:43Z
[ "python" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
14,072,943
<p>none of what was suggested helped me. I did discover this though.</p> <pre><code>&lt;object&gt;.__getattribute__(&lt;string name&gt;)(&lt;params&gt;) </code></pre> <p>I am using python 2.66 </p> <p>Hope this helps</p>
8
2012-12-28T16:56:45Z
[ "python" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
19,393,328
<p>Given a string, with a complete python path to a function, this is how I went about getting the result of said function:</p> <pre><code>import importlib function_string = 'mypackage.mymodule.myfunc' mod_name, func_name = function_string.rsplit('.',1) mod = importlib.import_module(mod_name) func = getattr(mod, func_...
39
2013-10-16T00:24:22Z
[ "python" ]
Calling a function of a module from a string with the function's name in Python
3,061
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string whose contents are <code>"bar"</code>. What is the best way to go about calling <code>foo.bar()</code>?</p> <p>I need to...
761
2008-08-06T03:36:08Z
22,959,509
<p>The answer (I hope) no one ever wanted</p> <p>Eval like behavior</p> <pre><code>getattr(locals().get("foo") or globals().get("foo"), "bar")() </code></pre> <p>Why not add auto-importing</p> <pre><code>getattr( locals().get("foo") or globals().get("foo") or __import__("foo"), "bar")() </code></pre> ...
17
2014-04-09T10:17:41Z
[ "python" ]
Programmatically talking to a Serial Port in OS X or Linux
3,976
<p>I have a Prolite LED sign that I like to set up to show scrolling search queries from a apache logs and other fun statistics. The problem is, my G5 does not have a serial port, so I have to use a usb to serial dongle. It shows up as /dev/cu.usbserial and /dev/tty.usbserial . </p> <p>When i do this everything seems ...
12
2008-08-06T21:00:01Z
4,128
<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...
0
2008-08-06T23:40:43Z
[ "python", "linux", "osx", "serial-port" ]
Programmatically talking to a Serial Port in OS X or Linux
3,976
<p>I have a Prolite LED sign that I like to set up to show scrolling search queries from a apache logs and other fun statistics. The problem is, my G5 does not have a serial port, so I have to use a usb to serial dongle. It shows up as /dev/cu.usbserial and /dev/tty.usbserial . </p> <p>When i do this everything seems ...
12
2008-08-06T21:00:01Z
4,162
<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>
4
2008-08-07T00:19:03Z
[ "python", "linux", "osx", "serial-port" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
4,958
<p>Focus on the shorter time needed for development/prototype and possibly easier maintenance (none of this may apply against Ruby).</p>
2
2008-08-07T16:50:43Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
4,978
<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 ...
11
2008-08-07T17:04:25Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
5,014
<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...
3
2008-08-07T17:30:10Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
15,291
<p>I agree with mreggen. Tell them by working in Python you can get things done faster. Getting things done faster possibly means money saved by the client. In the least it means that you are working with a language you a more comfortable in, meaning faster development, debugging, and refactoring time. There will be le...
0
2008-08-18T22:06:02Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
15,296
<p>It's one of the preferred languages over at Google - It's several years ahead of Ruby in terms of "maturity" (what ever that really means - but managers like that). Since it's prefered by Google you can also run it on the Google App Engine.</p> <p>Mircosoft is also embracing Python, and will have a v2.0 of IronPyth...
4
2008-08-18T22:10:13Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
21,221
<p>The best sell of Python I've ever seen was by a manager in our group who had a young daughter. He used a quote attributed to Einstein:</p> <blockquote> <p>If you can't explain something to a six-year-old, you really don't understand it yourself.</p> </blockquote> <p>The next few slides of his presentation demon...
6
2008-08-21T21:24:10Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
9,420,311
<p>Give them a snippet of code in each (no more than a page) that performs some cool function that they will like. (e.g show outliers in a data set).</p> <p>Show them each page. One in PHP, Ruby and Python.</p> <p>Ask them which they find easiest to understand/read.</p> <p>Tell them thats why you want to use Python....
0
2012-02-23T19:59:12Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How to sell Python to a client/boss/person with lots of cash
4,942
<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>
5
2008-08-07T16:43:21Z
32,847,801
<p>Though <em>All 3 languages are versatile and used worldwide by programmers</em>, Python still have some advantages over the other two. Like From my personal experience :-</p> <blockquote> <ol> <li>Non-programmers love it (most of 'em choose Python as their first computer language,check this infographic <a href=...
0
2015-09-29T15:18:37Z
[ "php", "python", "ruby-on-rails", "ruby" ]
How do you set up Python scripts to work in Apache 2.0?
5,102
<p>I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?</p> <p>My dev box is OS X, production - Centos.</p>
14
2008-08-07T18:24:12Z
5,129
<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...
12
2008-08-07T18:40:53Z
[ "python", "apache", "apache2" ]
How do you set up Python scripts to work in Apache 2.0?
5,102
<p>I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?</p> <p>My dev box is OS X, production - Centos.</p>
14
2008-08-07T18:24:12Z
5,165
<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 ...
8
2008-08-07T19:02:57Z
[ "python", "apache", "apache2" ]
How do you set up Python scripts to work in Apache 2.0?
5,102
<p>I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?</p> <p>My dev box is OS X, production - Centos.</p>
14
2008-08-07T18:24:12Z
5,168
<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 ...
5
2008-08-07T19:05:58Z
[ "python", "apache", "apache2" ]
How do you set up Python scripts to work in Apache 2.0?
5,102
<p>I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?</p> <p>My dev box is OS X, production - Centos.</p>
14
2008-08-07T18:24:12Z
14,791,003
<p>The problem for me wasn't in Apache set up, but in understanding how mod_apache actually uses the .py files. Module-level statements (including those in a <code>if __name__=='__main__'</code> section) are <em>not</em> executed--I assumed that the stdout from running the script at the commandline would be what the se...
0
2013-02-09T20:05:07Z
[ "python", "apache", "apache2" ]
Does anyone have experience creating a shared library in MATLAB?
5,136
<p>A researcher has created a small simulation in MATLAB, and we want to make it accessible to others. My plan is to take the simulation, clean up a few things, and turn it into a set of functions. Then, I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to ca...
6
2008-08-07T18:47:58Z
5,302
<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>
4
2008-08-07T20:57:20Z
[ "python", "c", "matlab" ]
Does anyone have experience creating a shared library in MATLAB?
5,136
<p>A researcher has created a small simulation in MATLAB, and we want to make it accessible to others. My plan is to take the simulation, clean up a few things, and turn it into a set of functions. Then, I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to ca...
6
2008-08-07T18:47:58Z
16,189
<p>Perhaps try <a href="http://python.net/crew/theller/ctypes/" rel="nofollow">ctypes </a>instead of SWIG. If it has been included as a part of Python 2.5, then it must be good :-)</p>
1
2008-08-19T13:51:47Z
[ "python", "c", "matlab" ]
Does anyone have experience creating a shared library in MATLAB?
5,136
<p>A researcher has created a small simulation in MATLAB, and we want to make it accessible to others. My plan is to take the simulation, clean up a few things, and turn it into a set of functions. Then, I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to ca...
6
2008-08-07T18:47:58Z
138,534
<p>I'd also try ctypes first. </p> <ol> <li>Use the Matlab compiler to compile the code into C. </li> <li>Compile the C code into a DLL.</li> <li>Use ctypes to load and call code from this DLL</li> </ol> <p>The hardest step is probably 1, but if you already know Matlab and have used the Matlab compiler, you should no...
2
2008-09-26T09:55:39Z
[ "python", "c", "matlab" ]
Does anyone have experience creating a shared library in MATLAB?
5,136
<p>A researcher has created a small simulation in MATLAB, and we want to make it accessible to others. My plan is to take the simulation, clean up a few things, and turn it into a set of functions. Then, I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to ca...
6
2008-08-07T18:47:58Z
1,659,332
<p>One thing to remember is that the Matlab compiler does not actually compile the Matlab code into native machine instructions. It simply wraps it into a standalone executable or a library with its own runtime engine that runs it. You would be able to run your code without Matlab installed, and you would be able to ...
5
2009-11-02T03:43:54Z
[ "python", "c", "matlab" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
5,319
<p>erm.. HTML? (trying to be funny here... while we wait for real answers..)</p>
8
2008-08-07T21:10:27Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
5,320
<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...
1
2008-08-07T21:11:28Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
5,340
<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...
3
2008-08-07T21:24:26Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
5,343
<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...
5
2008-08-07T21:25:26Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
6,616
<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>
3
2008-08-09T04:44:41Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
7,496
<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>...
0
2008-08-11T03:11:55Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
8,109
<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...
1
2008-08-11T19:17:41Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
8,114
<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>
4
2008-08-11T19:21:14Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
1,607,717
<p>I would go with XSLT, therefore it could be embedded in other interfaces as well.</p>
0
2009-10-22T14:39:51Z
[ "python", "user-interface", "markup" ]
Cross Platform, Language Agnostic GUI Markup Language?
5,313
<p>I learned Swing back in the day but now I've moved to Python and want to make some apps with GUIs. I haven't had the time to learn a new GUI API so I've been using Jython, but I would prefer to use CPython. </p> <p>It would be great if I can have one simple markup that allows me to switch GUI libraries. It would ...
11
2008-08-07T21:07:24Z
10,751,568
<p>If you switch to .NET then you can use a common GUI language, for example Razor in MVC (if you are doing web development), and have a choice of C# or VB or a number of other languages.</p>
0
2012-05-25T09:09:28Z
[ "python", "user-interface", "markup" ]
Convert Bytes to Floating Point Numbers in Python
5,415
<p>I have a binary file that I have to parse and I'm using Python. Is there a way to take 4 bytes and convert it to a single precision floating point number?</p>
21
2008-08-07T22:24:27Z
5,435
<p>You'll want the <a href="https://docs.python.org/3.4/library/struct.html" rel="nofollow">struct</a> package.</p>
13
2008-08-07T22:35:48Z
[ "python", "floating-point" ]
Convert Bytes to Floating Point Numbers in Python
5,415
<p>I have a binary file that I have to parse and I'm using Python. Is there a way to take 4 bytes and convert it to a single precision floating point number?</p>
21
2008-08-07T22:24:27Z
73,281
<pre><code>&gt;&gt;&gt; import struct &gt;&gt;&gt; struct.pack('f', 3.141592654) b'\xdb\x0fI@' &gt;&gt;&gt; struct.unpack('f', b'\xdb\x0fI@') (3.1415927410125732,) &gt;&gt;&gt; struct.pack('4f', 1.0, 2.0, 3.0, 4.0) '\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@' </code></pre>
32
2008-09-16T14:59:37Z
[ "python", "floating-point" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
5,430
<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...
24
2008-08-07T22:32:23Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
8,020
<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...
-1
2008-08-11T17:58:28Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
2,013,263
<p>The below code will make Python output to console as UTF-8 even on Windows. </p> <p>The console will display the characters well on Windows 7 but on Windows XP it will not display them well, but at least it will work and most important you will have a consistent output from your script on all platforms. You'll be a...
7
2010-01-06T13:38:39Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
4,637,795
<p>Despite the other plausible-sounding answers that suggest changing the code page to 65001, that <a href="http://bugs.python.org/issue1602">does not work</a>. (Also, changing the default encoding using <code>sys.setdefaultencoding</code> is <a href="http://stackoverflow.com/questions/3578685/how-to-display-utf-8-in-w...
19
2011-01-09T05:07:56Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
10,667,978
<p>If you're not interested in getting a reliable representation of the bad character(s) you might use something like this (working with python >= 2.6, including 3.x):</p> <pre><code>from __future__ import print_function import sys def safeprint(s): try: print(s) except UnicodeEncodeError: if ...
10
2012-05-19T18:48:28Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
32,176,732
<p><strong>Update:</strong> <a href="https://docs.python.org/3.6/whatsnew/3.6.html#pep-528-change-windows-console-encoding-to-utf-8" rel="nofollow">Python 3.6</a> implements <a href="https://www.python.org/dev/peps/pep-0528/" rel="nofollow">PEP 528: Change Windows console encoding to UTF-8</a>: <em>the default console ...
13
2015-08-24T07:35:32Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
34,306,583
<p>Kind of related on the answer by J. F. Sebastian, but more direct.</p> <p>If you are having this problem when printing to the console/terminal, then do this:</p> <pre><code>&gt;set PYTHONIOENCODING=UTF-8 </code></pre>
-1
2015-12-16T07:53:43Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
35,903,736
<p>Like Giampaolo Rodolà's answer, but even more dirty: I really, really intend to spend a long time (soon) understanding the whole subject of encodings and how they apply to Windoze consoles, </p> <p>For the moment I just wanted sthg which would mean my program would NOT CRASH, and which I understood ... and also wh...
1
2016-03-09T22:14:15Z
[ "python", "unicode" ]
Python, Unicode, and the Windows console
5,419
<p>When I try to print a Unicode string in a Windows console, I get a <code>UnicodeEncodeError: 'charmap' codec can't encode character ....</code> error. I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatical...
72
2008-08-07T22:26:58Z
37,229,972
<p>James Sulak asked,</p> <blockquote> <p>Is there any way I can make Python automatically print a ? instead of failing in this situation?</p> </blockquote> <p>Other solutions recommend we attempt to modify the Windows environment or replace Python's <code>print()</code> function. The answer below comes closer to ...
-1
2016-05-14T17:47:35Z
[ "python", "unicode" ]
Get size of a file before downloading in Python
5,909
<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...
28
2008-08-08T13:35:19Z
5,927
<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>
6
2008-08-08T13:41:43Z
[ "python", "urllib" ]
Get size of a file before downloading in Python
5,909
<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...
28
2008-08-08T13:35:19Z
5,935
<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...
16
2008-08-08T13:47:26Z
[ "python", "urllib" ]
Get size of a file before downloading in Python
5,909
<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...
28
2008-08-08T13:35:19Z
5,938
<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...
4
2008-08-08T13:51:23Z
[ "python", "urllib" ]
Get size of a file before downloading in Python
5,909
<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...
28
2008-08-08T13:35:19Z
5,985
<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...
19
2008-08-08T14:21:51Z
[ "python", "urllib" ]
Get size of a file before downloading in Python
5,909
<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...
28
2008-08-08T13:35:19Z
25,502,448
<p>In Python3:</p> <pre><code>&gt;&gt;&gt; import urllib.request &gt;&gt;&gt; site = urllib.request.urlopen("http://python.org") &gt;&gt;&gt; print("FileSize: ", site.length) </code></pre>
1
2014-08-26T09:31:46Z
[ "python", "urllib" ]
Best way to abstract season/show/episode data
5,966
<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">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>print tvdbinsta...
10
2008-08-08T14:05:45Z
6,125
<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...
3
2008-08-08T16:45:50Z
[ "python", "data-structures" ]
Best way to abstract season/show/episode data
5,966
<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">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>print tvdbinsta...
10
2008-08-08T14:05:45Z
6,805
<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...
0
2008-08-09T15:13:14Z
[ "python", "data-structures" ]
Best way to abstract season/show/episode data
5,966
<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">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>print tvdbinsta...
10
2008-08-08T14:05:45Z
8,165
<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={} ...
0
2008-08-11T20:07:59Z
[ "python", "data-structures" ]
Best way to abstract season/show/episode data
5,966
<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">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>print tvdbinsta...
10
2008-08-08T14:05:45Z
9,080
<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...
0
2008-08-12T17:55:22Z
[ "python", "data-structures" ]
Best way to abstract season/show/episode data
5,966
<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">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>print tvdbinsta...
10
2008-08-08T14:05:45Z
10,778
<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...
5
2008-08-14T07:08:19Z
[ "python", "data-structures" ]
Pylons error - 'MySQL server has gone away'
8,154
<p>[I hope this isn't too obscure&hellip; I'll ask the newsgroup if nobody knows here]</p> <p>I'm using Pylons (a python framework) to serve a simple web application, but it seems to die from time to time, with this in the error log: <code>(2006, 'MySQL server has gone away')</code></p> <p>I did a bit of checking, an...
10
2008-08-11T19:59:32Z
15,261
<p>You might want to check MySQL's timeout variables:</p> <pre><code>show variables like '%timeout%'; </code></pre> <p>You're probably interested in <code>wait_timeout</code> (less likely but possible: <code>interactive_timeout</code>). On Debian and Ubuntu, the defaults are 28800 (MySQL kills connections after 8 ho...
2
2008-08-18T21:35:39Z
[ "python", "mysql", "pylons" ]
Pylons error - 'MySQL server has gone away'
8,154
<p>[I hope this isn't too obscure&hellip; I'll ask the newsgroup if nobody knows here]</p> <p>I'm using Pylons (a python framework) to serve a simple web application, but it seems to die from time to time, with this in the error log: <code>(2006, 'MySQL server has gone away')</code></p> <p>I did a bit of checking, an...
10
2008-08-11T19:59:32Z
46,442
<p>I think I fixed it. It's turns out I had a simple config error. My ini file read:</p> <pre><code>sqlalchemy.default.url = [connection string here] sqlalchemy.pool_recycle = 1800 </code></pre> <p>The problem is that my <code>environment.py</code> file declared that the engine would only map keys with the prefix: <c...
6
2008-09-05T18:07:50Z
[ "python", "mysql", "pylons" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
8,699
<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>
74
2008-08-12T11:40:13Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
9,171
<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...
2
2008-08-12T19:34:44Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
10,846
<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 ...
7
2008-08-14T09:48:59Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
27,974
<p><a href="http://xmlsoft.org/python.html">libxml2</a> has a number of advantages:</p> <ol> <li>Compliance to the <a href="http://www.w3.org/TR/xpath">spec</a></li> <li>Active development and a community participation </li> <li>Speed. This is really a python wrapper around a C implementation. </li> <li>Ubiquity. The ...
106
2008-08-26T13:06:39Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
1,732,475
<p>Use LXML. LXML uses the full power of libxml2 and libxslt, but wraps them in more "Pythonic" bindings than the Python bindings that are native to those libraries. As such, it gets the full XPath 1.0 implementation. Native ElemenTree supports a limited subset of XPath, although it may be good enough for your needs.</...
35
2009-11-13T23:11:17Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
2,122,709
<p>Another option is <a href="http://code.google.com/p/py-dom-xpath/">py-dom-xpath</a>, it works seamlessly with minidom and is pure Python so works on appengine.</p> <pre><code>import xpath xpath.find('//item', doc) </code></pre>
23
2010-01-23T09:30:19Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
3,547,727
<p>Another library is 4Suite: <a href="http://sourceforge.net/projects/foursuite/" rel="nofollow">http://sourceforge.net/projects/foursuite/</a></p> <p>I do not know how spec-compliant it is. But it has worked very well for my use. It looks abandoned.</p>
3
2010-08-23T12:57:47Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
3,547,741
<p>You can use:</p> <p><strong>PyXML</strong>:</p> <pre><code>from xml.dom.ext.reader import Sax2 from xml import xpath doc = Sax2.FromXmlFile('foo.xml').documentElement for url in xpath.Evaluate('//@Url', doc): print url.value </code></pre> <p><strong>libxml2</strong>:</p> <pre><code>import libxml2 doc = libxml2...
9
2010-08-23T13:00:01Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
13,504,511
<p>Sounds like an lxml advertisement in here. ;) ElementTree is included in the std library. Under 2.6 and below its xpath is pretty weak, but in <a href="http://docs.python.org/2/library/xml.etree.elementtree.html#xpath-support">2.7 much improved</a>:</p> <pre class="lang-py prettyprint-override"><code>import xml.e...
30
2012-11-22T01:05:52Z
[ "python", "xml", "dom", "xpath", "nodes" ]
How to use Xpath in Python?
8,692
<p>What is the library? Is there a full implementation? How is the library used? Where is its website?</p>
164
2008-08-12T11:28:36Z
33,716,764
<p>You can use the simple <code>soupparser</code> from <code>lxml</code></p> <h2>Example:</h2> <pre><code>from lxml.html.soupparser import fromstring tree = fromstring("&lt;a&gt;Find me!&lt;/a&gt;") print tree.xpath("//a/text()") </code></pre>
3
2015-11-15T05:31:21Z
[ "python", "xml", "dom", "xpath", "nodes" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
8,972
<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>
1
2008-08-12T15:32:05Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
8,974
<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...
6
2008-08-12T15:37:24Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
8,976
<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...
1
2008-08-12T15:37:59Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
9,358
<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...
11
2008-08-13T00:44:26Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
10,845
<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>
25
2008-08-14T09:46:21Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
28,711
<p>If you can use IronPython, there is TagLibSharp. <a href="http://stackoverflow.com/questions/28664/what-is-the-besta-very-good-meta-data-reader-library#28687">It can be used from any .NET language</a>.</p>
0
2008-08-26T17:48:49Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
102,285
<p>I used <a href="http://eyed3.nicfit.net/">eyeD3</a> the other day with a lot of success. I found that it could add artwork to the ID3 tag which the other modules I looked at couldn't. You'll have to download the tar and execute <code>python setup.py install</code> from the source folder. </p> <p>Relevant example...
75
2008-09-19T14:30:41Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
1,936,720
<p>I looked the above answers and found out that they are not good for my project because of licensing problems with GPL.</p> <p>And I found out this: <a href="http://pyid3lib.sourceforge.net/" rel="nofollow">PyID3Lib</a>, while that particular <em>python binding</em> release date is old, it uses the <a href="http://i...
4
2009-12-20T19:32:11Z
[ "python", "mp3", "metadata" ]
Accessing mp3 Meta-Data with Python
8,948
<p>What is the best way to retrieve mp3 metadata in python? I've seen a couple frameworks out there, but I'm unsure as to which would be the best to use.... Any ideas?</p>
81
2008-08-12T15:16:00Z
4,559,380
<p>check this one out:</p> <p><a href="https://github.com/Ciantic/songdetails">https://github.com/Ciantic/songdetails</a></p> <p>Usage example:</p> <pre><code>&gt;&gt;&gt; import songdetails &gt;&gt;&gt; song = songdetails.scan("data/song.mp3") &gt;&gt;&gt; print song.duration 0:03:12 </code></pre> <p>Saving change...
7
2010-12-30T01:40:52Z
[ "python", "mp3", "metadata" ]