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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Python2.6 xmpp Jabber Error | 1,301,303 | <p>I am using xmpp with python and I want create a simple client to communicate with a gmail
id. </p>
<pre><code>#!/usr/bin/python
import xmpp
login = 'Your.Login' # @gmail.com
pwd = 'YourPassword'
cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5223) )
cnx.auth(login,pwd, 'botty')
cnx.send... | 4 | 2009-08-19T17:06:20Z | 4,012,698 | <p>i think you must write this. i test it in python 2.7 with xmpppy 0.5.0rc1 and work IT very nice :P :) :</p>
<pre><code>import xmpp
login = 'your mail@gmail.com' # @gmail.com
pwd = 'your pass'
text='Hello worlD!'
tojid='your friend @gmail.com'
jid = xmpp.protocol.JID(login)
cl = xmpp.Client(jid.getDomain()... | 1 | 2010-10-25T07:49:01Z | [
"python",
"xmpp"
] |
C# equivalent of rotating a list using python slice operation | 1,301,316 | <p>In python, I can take a list my_list and rotate the contents:</p>
<pre><code>>>> my_list = list(range(10))
>>> my_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> new_list = my_list[1:] + my_list[:1]
>>> new_list
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
</code></pre>
<p>What's the equivalent way i... | 33 | 2009-08-19T17:08:16Z | 1,301,347 | <p>You can easily use LINQ to do this:</p>
<pre><code>// Create the list
int[] my_list = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
IEnumerable<int> new_list =
my_list.Skip(1).Concat(my_list.Take(1));
</code></pre>
<p>You could even add this as an extension method like so:</p>
<pre><code>public static IEnumerable<... | 18 | 2009-08-19T17:11:57Z | [
"c#",
"python",
"algorithm"
] |
C# equivalent of rotating a list using python slice operation | 1,301,316 | <p>In python, I can take a list my_list and rotate the contents:</p>
<pre><code>>>> my_list = list(range(10))
>>> my_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> new_list = my_list[1:] + my_list[:1]
>>> new_list
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
</code></pre>
<p>What's the equivalent way i... | 33 | 2009-08-19T17:08:16Z | 1,301,350 | <pre><code>List<int> list1;
List<int> list2 = new List<int>(list1);
</code></pre>
<p>or you can</p>
<pre><code>list2.AddRange(list1);
</code></pre>
<p>To get a distinct list using LINQ</p>
<pre><code>List<int> distinceList = list2.Distinct<int>().ToList<int>();
</code></pre>
| 1 | 2009-08-19T17:12:19Z | [
"c#",
"python",
"algorithm"
] |
C# equivalent of rotating a list using python slice operation | 1,301,316 | <p>In python, I can take a list my_list and rotate the contents:</p>
<pre><code>>>> my_list = list(range(10))
>>> my_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> new_list = my_list[1:] + my_list[:1]
>>> new_list
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
</code></pre>
<p>What's the equivalent way i... | 33 | 2009-08-19T17:08:16Z | 1,301,351 | <p>The closest thing in C# would be to use the <a href="http://msdn.microsoft.com/en-us/library/bb358985.aspx">Enumerable.Skip</a> and <a href="http://msdn.microsoft.com/en-us/library/bb503062.aspx">Enumerable.Take</a> extension methods. You could use these to build your new list.</p>
| 9 | 2009-08-19T17:12:27Z | [
"c#",
"python",
"algorithm"
] |
C# equivalent of rotating a list using python slice operation | 1,301,316 | <p>In python, I can take a list my_list and rotate the contents:</p>
<pre><code>>>> my_list = list(range(10))
>>> my_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> new_list = my_list[1:] + my_list[:1]
>>> new_list
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
</code></pre>
<p>What's the equivalent way i... | 33 | 2009-08-19T17:08:16Z | 1,301,362 | <pre><code>var newlist = oldlist.Skip(1).Concat(oldlist.Take(1));
</code></pre>
| 39 | 2009-08-19T17:14:13Z | [
"c#",
"python",
"algorithm"
] |
C# equivalent of rotating a list using python slice operation | 1,301,316 | <p>In python, I can take a list my_list and rotate the contents:</p>
<pre><code>>>> my_list = list(range(10))
>>> my_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> new_list = my_list[1:] + my_list[:1]
>>> new_list
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
</code></pre>
<p>What's the equivalent way i... | 33 | 2009-08-19T17:08:16Z | 18,866,531 | <p>To rotate array, do <code>a.Slice(1, null).Concat(a.Slice(null, 1))</code>. </p>
<p>Here's my stab at it. <code>a.Slice(step: -1)</code> gives a reversed copy as <code>a[::-1]</code>.</p>
<pre><code>/// <summary>
/// Slice an array as Python.
/// </summary>
/// <typeparam name="T"></typeparam&... | 1 | 2013-09-18T07:45:41Z | [
"c#",
"python",
"algorithm"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 1,301,369 | <h2>Single Underscore</h2>
<p>Names, in a class, with a leading underscore are simply to indicate to other programmers that the attribute or method is intended to be private. However, nothing special is done with the name itself.</p>
<p>To quote <a href="http://www.python.org/dev/peps/pep-0008/">PEP-8</a>:</p>
<blo... | 635 | 2009-08-19T17:15:53Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 1,301,384 | <p>Single leading underscores is a convention. there is no difference from the interpreter's point of view if whether names starts with a single underscore or not. </p>
<p>Double leading and trailing underscores are used for built-in methods, such as <code>__init__</code>, <code>__bool__</code>, etc.</p>
<p>Double le... | 3 | 2009-08-19T17:17:11Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 1,301,409 | <p><code>__foo__</code>: this is just a convention, a way for the Python system to use names that won't conflict with user names.</p>
<p><code>_foo</code>: this is just a convention, a way for the programmer to indicate that the variable is private (whatever that means in Python).</p>
<p><code>__foo</code>: this has ... | 171 | 2009-08-19T17:21:29Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 1,301,456 | <p>Your question is good, it is not only about methods. Functions and objects in modules are commonly prefixed with one underscore as well, and can be prefixed by two.</p>
<p>But __double_underscore names are not name-mangled in modules, for example. What happens is that names beginning with one (or more) underscores ... | 2 | 2009-08-19T17:31:04Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 1,301,557 | <p>Excellent answers so far but some tidbits are missing. A single leading underscore isn't exactly <em>just</em> a convention: if you use <code>from foobar import *</code>, and module <code>foobar</code> does not define an <code>__all__</code> list, the names imported from the module <strong>do not</strong> include th... | 225 | 2009-08-19T17:52:36Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 8,822,881 | <p>Sometimes you have what appears to be a tuple with a leading underscore as in </p>
<pre><code>def foo(bar):
return _('my_' + bar)
</code></pre>
<p>In this case, what's going on is that _() is an alias for a localization function that operates on text to put it into the proper language, etc. based on the locale... | 15 | 2012-01-11T16:28:22Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 12,629,901 | <p><code>._variable</code> is semiprivate and meant just for convention</p>
<p><code>.__variable</code> is often incorrectly considered superprivate, while it's actual meaning is just to namemangle to <strong>prevent accidental access</strong><a href="https://www.youtube.com/watch?v=HTLu2DFOdTg&t=33m8s">[1]</a></p... | 82 | 2012-09-27T20:56:44Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 16,006,566 | <p>If one really wants to make a variable read-only, IMHO the best way would be to use property() with only getter passed to it. With property() we can have complete control over the data.</p>
<pre><code>class PrivateVarC(object):
def get_x(self):
pass
def set_x(self, val):
pass
rwvar = ... | 6 | 2013-04-15T01:58:14Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 25,454,077 | <p>Here is a simple illustrative example on how double underscore properties can affect an inherited class. So with the following setup:</p>
<pre><code>class parent(object):
__default = "parent"
def __init__(self, name=None):
self.default = name or self.__default
@property
def default(self):
... | 0 | 2014-08-22T19:15:48Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 27,481,645 | <p><strong>Single underscore at the beginning:</strong></p>
<p>Python doesn't have real private methods, so one underscore at the start of a method or attribute name means you shouldn't access this method, because it's not part of the API.</p>
<pre><code>class BaseForm(StrAndUnicode):
def _get_errors(self):
... | 47 | 2014-12-15T10:10:20Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
The meaning of a single- and a double-underscore before an object name in Python | 1,301,346 | <p>I want to clear this up once and for all. Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also explain the difference between a single and a double leading underscore. Also, does that meaning stay the same whether the object in question is a variable, a f... | 668 | 2009-08-19T17:11:57Z | 28,385,489 | <p>âPrivateâ instance variables that cannot be accessed except from inside an object donât exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a method or ... | 1 | 2015-02-07T17:57:10Z | [
"python",
"naming-conventions",
"private",
"underscores",
"double-underscore"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,370 | <p>You should give the <a href="http://www.gnu.org/software/screen/screen.html">screen</a> utility a look. While it's not an IDE it is some kind of window manager on the terminal -- i.e. you can have multiple windows and switch between them, which makes especially tasks like this much easier.</p>
| 9 | 2009-08-19T17:16:14Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,379 | <p>You can <a href="http://linux.com/archive/articles/57727" rel="nofollow">execute shell commands</a> <a href="http://www.vim.org/htmldoc/tips.html" rel="nofollow">from within <code>vim</code></a>.</p>
| 6 | 2009-08-19T17:17:02Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,385 | <p>You could run <a href="http://www.realvnc.com/products/free/4.1/man/Xvnc.html" rel="nofollow">XVNC</a> over ssh, which is actually passably responsive for doing this sort of thing and gets you a windowing GUI. I've done this quite effectively over really asthmatic Jetstart DSL services in New Zealand (128K up/ 128K... | 1 | 2009-08-19T17:17:28Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,418 | <p>Using emacs with python-mode you can execute the script with C-c C-c</p>
| 5 | 2009-08-19T17:23:27Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,423 | <p>put this line in your .vimrc file:</p>
<pre><code>:map <F2> :w\|!python %<CR>
</code></pre>
<p>now hitting <code><F2></code> will save and run your python script</p>
| 18 | 2009-08-19T17:24:01Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,501 | <p>When working with Vim on the console, I have found that using "tabs" in Vim, instead of having multiple Vim instances suspended in the background, makes handling multiple files in Vim more efficient. It takes a bit of getting used to, but it works really well.</p>
| 1 | 2009-08-19T17:41:08Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,550 | <p>Well, apart from using one of the more capable console editors (Emacs or vi would come to mind), why do you have to edit it on the web server itself? Just edit it remotely if constant FTP/WebDAV transfer would seem to cumbersome. </p>
<p>Emacs has <a href="http://www.emacswiki.org/emacs/TrampMode" rel="nofollow">Tr... | 0 | 2009-08-19T17:50:44Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 1,301,621 | <p>you can try <a href="http://ipython.scipy.org/moin/" rel="nofollow">ipython</a>. using its edit command, it will bring up your editor (nano/vim/etc), you write your script, and then on exiting you're returned to the ipython prompt and the script is automatically executed. </p>
| 4 | 2009-08-19T18:03:18Z | [
"python",
"shell",
"vi"
] |
Python IDE on Linux Console | 1,301,352 | <p>This may sound strange, but I need a better way to build python scripts than opening a file with nano/vi, change something, quit the editor, and type in <code>python script.py</code>, over and over again.</p>
<p>I need to build the script on a webserver without any gui. Any ideas how can I improve my workflow?</p>
| 10 | 2009-08-19T17:12:36Z | 2,596,979 | <p>There are actually 2 questions. First is polling for a console IDE for python and the second is a better dev/test/deploy workflow.</p>
<p>For while there are many ways you can write python code in the console, I find a combination of screen, vim and python/ipython is the best as they are usually available on most s... | 1 | 2010-04-08T01:23:21Z | [
"python",
"shell",
"vi"
] |
Python: Why are some of Queue.queue's method "unreliable"? | 1,301,416 | <p>In the <code>queue</code> class from the <code>Queue</code> module, there are a few methods, namely, <code>qsize</code>, <code>empty</code> and <code>full</code>, whose documentation claims they are "not reliable".</p>
<p>What exactly is not reliable about them?</p>
<p>I did notice that <a href="http://docs.python... | 6 | 2009-08-19T17:22:43Z | 1,301,445 | <p>I don't know which Queue module you're referring to, please can you provide a link?</p>
<p>One possible source of unreliability: Generally, a queue is read by one thread and written by another. If you are the only thread accessing a queue, then reliable implementations of qsize(), empty() and full() are possible.... | 2 | 2009-08-19T17:28:50Z | [
"python",
"multithreading",
"queue"
] |
Python: Why are some of Queue.queue's method "unreliable"? | 1,301,416 | <p>In the <code>queue</code> class from the <code>Queue</code> module, there are a few methods, namely, <code>qsize</code>, <code>empty</code> and <code>full</code>, whose documentation claims they are "not reliable".</p>
<p>What exactly is not reliable about them?</p>
<p>I did notice that <a href="http://docs.python... | 6 | 2009-08-19T17:22:43Z | 1,301,463 | <p>Yes, the docs use "unreliable" here to convey exactly this meaning: for example, in a sense, <code>qsize</code> doesn't tell you how many entries there are "right now", a concept that is not necessarily very meaningful in a multithreaded world (except at specific points where synchronization precautions are being t... | 9 | 2009-08-19T17:31:55Z | [
"python",
"multithreading",
"queue"
] |
Python: Why are some of Queue.queue's method "unreliable"? | 1,301,416 | <p>In the <code>queue</code> class from the <code>Queue</code> module, there are a few methods, namely, <code>qsize</code>, <code>empty</code> and <code>full</code>, whose documentation claims they are "not reliable".</p>
<p>What exactly is not reliable about them?</p>
<p>I did notice that <a href="http://docs.python... | 6 | 2009-08-19T17:22:43Z | 20,586,846 | <p>This is one case of unreliability in line with what Alex Martelli suggested:
<a href="http://stackoverflow.com/questions/20586673/joinablequeue-empty-unreliable-whats-the-alternative">JoinableQueue.empty() unreliable? What's the alternative?</a></p>
| 0 | 2013-12-14T18:41:14Z | [
"python",
"multithreading",
"queue"
] |
Setting timezone in Python | 1,301,493 | <p>Is it possible with Python to set the timezone just like this in PHP:</p>
<pre><code>date_default_timezone_set("Europe/London");
$Year = date('y');
$Month = date('m');
$Day = date('d');
$Hour = date('H');
$Minute = date('i');
</code></pre>
<p>I can't really install any other modules etc as I'm using shared web hos... | 21 | 2009-08-19T17:38:31Z | 1,301,528 | <pre><code>>>> import os, time
>>> time.strftime('%X %x %Z')
'12:45:20 08/19/09 CDT'
>>> os.environ['TZ'] = 'Europe/London'
>>> time.tzset()
>>> time.strftime('%X %x %Z')
'18:45:39 08/19/09 BST'
</code></pre>
<p>To get the specific values you've listed:</p>
<pre><code>>... | 38 | 2009-08-19T17:46:03Z | [
"python",
"timezone"
] |
Setting timezone in Python | 1,301,493 | <p>Is it possible with Python to set the timezone just like this in PHP:</p>
<pre><code>date_default_timezone_set("Europe/London");
$Year = date('y');
$Month = date('m');
$Day = date('d');
$Hour = date('H');
$Minute = date('i');
</code></pre>
<p>I can't really install any other modules etc as I'm using shared web hos... | 21 | 2009-08-19T17:38:31Z | 25,706,099 | <p>It's not an answer, but...</p>
<p>To get <code>datetime</code> components individually, better use <a href="https://docs.python.org/2.7/library/datetime.html#datetime.datetime.timetuple" rel="nofollow">datetime.timetuple</a>:</p>
<pre><code>time = datetime.now()
time.timetuple()
#-> time.struct_time(
# tm_ye... | 0 | 2014-09-07T00:42:23Z | [
"python",
"timezone"
] |
I'd like some advice on packaging this as an egg and uploading it to pypi | 1,301,689 | <p>I wrote some code that I'd like to package as an egg. This is my directory structure:</p>
<pre>
src/
src/tests
src/tests/test.py # this has several tests for the movie name parser
src/torrent
src/torrent/__init__.py
src/torrent/movienameparser
src/torrent/movienameparser/__init__.py # this contains the code
</pre>
... | 2 | 2009-08-19T18:12:03Z | 1,302,680 | <p>It would be better to distribute it as a tarball (<code>.tar.gz</code>), not as an egg. Eggs are primarily for binary distribution, such as when using compiled C extensions. In source-only distributions, they are just unnecessary complexity.</p>
<p>If you just want to throw your code out into the world, the MIT or ... | 3 | 2009-08-19T21:21:08Z | [
"python",
"setuptools",
"distutils",
"egg",
"pypi"
] |
I'd like some advice on packaging this as an egg and uploading it to pypi | 1,301,689 | <p>I wrote some code that I'd like to package as an egg. This is my directory structure:</p>
<pre>
src/
src/tests
src/tests/test.py # this has several tests for the movie name parser
src/torrent
src/torrent/__init__.py
src/torrent/movienameparser
src/torrent/movienameparser/__init__.py # this contains the code
</pre>
... | 2 | 2009-08-19T18:12:03Z | 1,302,722 | <p>I won't get into licensing discussion here, but it's typical to include LICENSE file at the root of your package source code, along with other customary things like README, etc.</p>
<p>I usually organize packages the same way they will be installed on the target system. The standard package layout convention is exp... | 6 | 2009-08-19T21:29:42Z | [
"python",
"setuptools",
"distutils",
"egg",
"pypi"
] |
I'd like some advice on packaging this as an egg and uploading it to pypi | 1,301,689 | <p>I wrote some code that I'd like to package as an egg. This is my directory structure:</p>
<pre>
src/
src/tests
src/tests/test.py # this has several tests for the movie name parser
src/torrent
src/torrent/__init__.py
src/torrent/movienameparser
src/torrent/movienameparser/__init__.py # this contains the code
</pre>
... | 2 | 2009-08-19T18:12:03Z | 3,469,637 | <p>Include ez_setup file from <a href="http://peak.telecommunity.com/dist/ez_setup.py" rel="nofollow">setuptools website</a> and include, at the top of your setup.py:</p>
<pre><code>from ez_setup import use_setuptools
use_setuptools()
</code></pre>
<p>This script is an helper for people who doesn't have setuptools. I... | 0 | 2010-08-12T16:04:05Z | [
"python",
"setuptools",
"distutils",
"egg",
"pypi"
] |
Counting python method calls within another method | 1,301,735 | <p>I'm actually trying doing this in Java, but I'm in the process of teaching myself python and it made me wonder if there was an easy/clever way to do this with wrappers or something.</p>
<p>I want to know how many times a specific method was called inside another method. For example:</p>
<pre><code>def foo(z):
... | 7 | 2009-08-19T18:19:20Z | 1,301,835 | <p>After your response - here's a way with a decorator factory...</p>
<pre><code>import inspect
def make_decorators():
# Mutable shared storage...
caller_L = []
callee_L = []
called_count = [0]
def caller_decorator(caller):
caller_L.append(caller)
def counting_caller(*args, **kwarg... | 1 | 2009-08-19T18:37:17Z | [
"python",
"profiling"
] |
Counting python method calls within another method | 1,301,735 | <p>I'm actually trying doing this in Java, but I'm in the process of teaching myself python and it made me wonder if there was an easy/clever way to do this with wrappers or something.</p>
<p>I want to know how many times a specific method was called inside another method. For example:</p>
<pre><code>def foo(z):
... | 7 | 2009-08-19T18:19:20Z | 1,301,845 | <p>This defines a decorator to do it:</p>
<pre><code>def count_calls(fn):
def _counting(*args, **kwargs):
_counting.calls += 1
return fn(*args, **kwargs)
_counting.calls = 0
return _counting
@count_calls
def foo(x):
return x
def bar(y):
foo(y)
foo(y)
bar(1)
print foo.calls
</... | 6 | 2009-08-19T18:38:06Z | [
"python",
"profiling"
] |
Counting python method calls within another method | 1,301,735 | <p>I'm actually trying doing this in Java, but I'm in the process of teaching myself python and it made me wonder if there was an easy/clever way to do this with wrappers or something.</p>
<p>I want to know how many times a specific method was called inside another method. For example:</p>
<pre><code>def foo(z):
... | 7 | 2009-08-19T18:19:20Z | 1,301,926 | <p>Sounds like almost the textbook example for decorators!</p>
<pre><code>def counted(fn):
def wrapper(*args, **kwargs):
wrapper.called+= 1
return fn(*args, **kwargs)
wrapper.called= 0
wrapper.__name__= fn.__name__
return wrapper
@counted
def foo():
return
>>> foo()
>&... | 13 | 2009-08-19T18:52:56Z | [
"python",
"profiling"
] |
django admin: company branches must manage only their records across many models | 1,301,757 | <p>One company with many branches across the world using the same app. Each branch's supervisor, signing into the same /admin, should see and be able to manage only their records across many models (blog, galleries, subscribed users, clients list, etc.). </p>
<p>How to solve it best within django? I need a flexible an... | 0 | 2009-08-19T18:24:10Z | 1,301,871 | <p>There is a nice tutorial <a href="http://www.ibm.com/developerworks/opensource/library/os-django-admin/" rel="nofollow">here</a> on Django Admin. It includes customizing the Admin to add row-level permissions (which, as i understand it, is what you want).</p>
| 1 | 2009-08-19T18:42:39Z | [
"python",
"django",
"django-admin",
"personalization"
] |
Why is Standard Input is not displayed as I type in Mac OS X Terminal application? | 1,301,887 | <p>I'm confused by some behavior of my Mac OS X Terminal and my Django <code>manage.py</code> shell and pdb.</p>
<p>When I start a new terminal, the Standard Input is displayed as I type. However, if there is an error, suddenly Standard Input does not appear on the screen. This error continues until I shut down that t... | 10 | 2009-08-19T18:44:56Z | 1,307,696 | <p>Try installing readline on Mac OS X:</p>
<pre><code>$ sudo easy_install readline
</code></pre>
<p>This is a blind guess, but perhaps it solves your problem.</p>
| -1 | 2009-08-20T17:29:42Z | [
"python",
"django",
"osx",
"shell",
"terminal"
] |
Why is Standard Input is not displayed as I type in Mac OS X Terminal application? | 1,301,887 | <p>I'm confused by some behavior of my Mac OS X Terminal and my Django <code>manage.py</code> shell and pdb.</p>
<p>When I start a new terminal, the Standard Input is displayed as I type. However, if there is an error, suddenly Standard Input does not appear on the screen. This error continues until I shut down that t... | 10 | 2009-08-19T18:44:56Z | 2,018,573 | <p>If you exit pdb you can type reset and standard input echo will return. I'm not sure if you can execute something similar within pdb. It will erase what is currently displayed however.</p>
| 3 | 2010-01-07T06:16:29Z | [
"python",
"django",
"osx",
"shell",
"terminal"
] |
Why is Standard Input is not displayed as I type in Mac OS X Terminal application? | 1,301,887 | <p>I'm confused by some behavior of my Mac OS X Terminal and my Django <code>manage.py</code> shell and pdb.</p>
<p>When I start a new terminal, the Standard Input is displayed as I type. However, if there is an error, suddenly Standard Input does not appear on the screen. This error continues until I shut down that t... | 10 | 2009-08-19T18:44:56Z | 2,623,452 | <p>Maybe this is because there was an error while running Django. Sometimes it happens that the std input disappears because <code>stty</code> was used. You can manually hide your input by typing:</p>
<p><code>$ stty -echo</code></p>
<p>Now you won't see what you typed. To restore this and solve your problem just typ... | 19 | 2010-04-12T16:03:17Z | [
"python",
"django",
"osx",
"shell",
"terminal"
] |
Django popup box Error?? Running development web server | 1,302,040 | <p>I have my Django site up and running, and everything works fine EXCEPT:</p>
<p>When I first go to my site <a href="http://127.0.0.1:8000" rel="nofollow">http://127.0.0.1:8000</a></p>
<p>A popup box comes up and says</p>
<p>"The page at <a href="http://127.0.0.1:8000" rel="nofollow">http://127.0.0.1:8000</a> says"... | 0 | 2009-08-19T19:09:35Z | 1,302,799 | <p>You must have a Javascript alert box in your template somewhere.</p>
| 1 | 2009-08-19T21:46:32Z | [
"python",
"django",
"webserver"
] |
cutdown uuid further to make short string | 1,302,057 | <p>I need to generate unique record id for the given unique string.</p>
<p>I tried using uuid format which seems to be good. </p>
<p>But we feel that is lengthly. </p>
<p>so we need to cutdown the uuid string 9f218a38-12cd-5942-b877-80adc0589315 to smaller. By removing '-' we can save 4 chars. What is the safest pa... | 5 | 2009-08-19T19:13:04Z | 1,302,076 | <p>Why not instead just convert it to a base 64 string? You can cut it down to 22 characters that way.</p>
<p><a href="http://stackoverflow.com/questions/772802/storing-uuid-as-base64-string">http://stackoverflow.com/questions/772802/storing-uuid-as-base64-string</a></p>
| 9 | 2009-08-19T19:17:50Z | [
"c#",
"python",
"string",
"uniqueidentifier",
"uuid"
] |
cutdown uuid further to make short string | 1,302,057 | <p>I need to generate unique record id for the given unique string.</p>
<p>I tried using uuid format which seems to be good. </p>
<p>But we feel that is lengthly. </p>
<p>so we need to cutdown the uuid string 9f218a38-12cd-5942-b877-80adc0589315 to smaller. By removing '-' we can save 4 chars. What is the safest pa... | 5 | 2009-08-19T19:13:04Z | 1,302,155 | <p>If you are using MS-SQL you should probably just use the uniqueindentifier datatype, it is both compact (16 bytes) and since the SQL engine knows about it it can optimize indexes and queries using it. </p>
| 2 | 2009-08-19T19:29:14Z | [
"c#",
"python",
"string",
"uniqueidentifier",
"uuid"
] |
cutdown uuid further to make short string | 1,302,057 | <p>I need to generate unique record id for the given unique string.</p>
<p>I tried using uuid format which seems to be good. </p>
<p>But we feel that is lengthly. </p>
<p>so we need to cutdown the uuid string 9f218a38-12cd-5942-b877-80adc0589315 to smaller. By removing '-' we can save 4 chars. What is the safest pa... | 5 | 2009-08-19T19:13:04Z | 1,302,160 | <p>A UUID has 128 bits. Have you considered doing a CRC of it? That could get it down to 16 or 32 bits easily, and would use all the original information. If a CRC isn't good enough, you could always use the first few bytes of a proper hash (SHA256, for example).</p>
<p>If you really want to just cut down the UUID, th... | 1 | 2009-08-19T19:30:13Z | [
"c#",
"python",
"string",
"uniqueidentifier",
"uuid"
] |
cutdown uuid further to make short string | 1,302,057 | <p>I need to generate unique record id for the given unique string.</p>
<p>I tried using uuid format which seems to be good. </p>
<p>But we feel that is lengthly. </p>
<p>so we need to cutdown the uuid string 9f218a38-12cd-5942-b877-80adc0589315 to smaller. By removing '-' we can save 4 chars. What is the safest pa... | 5 | 2009-08-19T19:13:04Z | 1,302,532 | <p>An UUID provides (almost) 128 bits of uniqueness. You may shorten it to 16 binary bytes, or 22 base64-encoded characters. I wouldn't recommend removing any part of a UUID, otherwise, it just loses its sense. UUIDs were designed so that all the 128 bits have meaning. If you want less than that, you should use some ot... | 1 | 2009-08-19T20:44:20Z | [
"c#",
"python",
"string",
"uniqueidentifier",
"uuid"
] |
cutdown uuid further to make short string | 1,302,057 | <p>I need to generate unique record id for the given unique string.</p>
<p>I tried using uuid format which seems to be good. </p>
<p>But we feel that is lengthly. </p>
<p>so we need to cutdown the uuid string 9f218a38-12cd-5942-b877-80adc0589315 to smaller. By removing '-' we can save 4 chars. What is the safest pa... | 5 | 2009-08-19T19:13:04Z | 1,302,665 | <p>The UUID is 128 bits or 16 bytes. With no encoding, you could get it as low as 16 bytes. UUIDs are commonly written in hexadecimal, making them 32 byte readable strings. With other encodings, you get different results:</p>
<ol>
<li>base-64 turns 3 8-bit bytes into 4 6-bit characters, so 16 bytes of data becomes 22 ... | 2 | 2009-08-19T21:17:05Z | [
"c#",
"python",
"string",
"uniqueidentifier",
"uuid"
] |
How do I parse timezones with UTC offsets in Python? | 1,302,161 | <p>Let's say I have a timezone like "2009-08-18 13:52:54-04". I can parse most of it using a line like this:</p>
<pre><code>datetime.strptime(time_string, "%Y-%m-%d %H:%M:%S")
</code></pre>
<p>However, I can't get the timezone to work. There's a %Z that handles textual timezones ("EST", "UTC", etc) but I don't see an... | 6 | 2009-08-19T19:30:17Z | 1,302,176 | <p>use <a href="http://babel.edgewall.org/" rel="nofollow">Babel</a>, specifically <a href="http://babel.edgewall.org/wiki/ApiDocs/babel.dates#babel.dates:parse%5Fdatetime" rel="nofollow">parse_datetime</a>.</p>
| 2 | 2009-08-19T19:34:23Z | [
"python",
"datetime"
] |
How do I parse timezones with UTC offsets in Python? | 1,302,161 | <p>Let's say I have a timezone like "2009-08-18 13:52:54-04". I can parse most of it using a line like this:</p>
<pre><code>datetime.strptime(time_string, "%Y-%m-%d %H:%M:%S")
</code></pre>
<p>However, I can't get the timezone to work. There's a %Z that handles textual timezones ("EST", "UTC", etc) but I don't see an... | 6 | 2009-08-19T19:30:17Z | 1,302,228 | <p>You can do that directrly on the constructor: <code>class datetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[, </code><strong>tzinfo</strong><code>]]]]])</code>, tzinfo being a <a href="http://docs.python.org/library/datetime.html#datetime.tzinfo" rel="nofollow"><code>datetime.tzinfo</code></a... | 0 | 2009-08-19T19:45:02Z | [
"python",
"datetime"
] |
How do I parse timezones with UTC offsets in Python? | 1,302,161 | <p>Let's say I have a timezone like "2009-08-18 13:52:54-04". I can parse most of it using a line like this:</p>
<pre><code>datetime.strptime(time_string, "%Y-%m-%d %H:%M:%S")
</code></pre>
<p>However, I can't get the timezone to work. There's a %Z that handles textual timezones ("EST", "UTC", etc) but I don't see an... | 6 | 2009-08-19T19:30:17Z | 1,302,248 | <p>I ran across the same issue recently and worked around it using this code:</p>
<pre><code>gmt_offset_str = time_string[-3:]
gmt_offset_seconds = int(gmt_offset_str)*60*60
timestamp = time.strptime(time_string[:-4], '%Y-%m-%d %H:%M:%S')
return time.localtime(time.mktime(timestamp)-gmt_offset_seconds)
</code></pre>
... | 0 | 2009-08-19T19:49:52Z | [
"python",
"datetime"
] |
How do I parse timezones with UTC offsets in Python? | 1,302,161 | <p>Let's say I have a timezone like "2009-08-18 13:52:54-04". I can parse most of it using a line like this:</p>
<pre><code>datetime.strptime(time_string, "%Y-%m-%d %H:%M:%S")
</code></pre>
<p>However, I can't get the timezone to work. There's a %Z that handles textual timezones ("EST", "UTC", etc) but I don't see an... | 6 | 2009-08-19T19:30:17Z | 2,496,144 | <p>Maybe you could use <a href="http://labix.org/python-dateutil">dateutil.parser.parse</a>? That method is also mentioned on <a href="http://wiki.python.org/moin/WorkingWithTime#ParsingISO8601withpython-dateutil">wiki.python.org/WorkingWithTime</a>.</p>
<pre><code>>>> from dateutil.parser import parse
>&g... | 21 | 2010-03-22T22:10:47Z | [
"python",
"datetime"
] |
Python PEP8 printing wrapped strings without indent | 1,302,364 | <p>There is probably an easy answer for this, just not sure how to tease it out of my searches.</p>
<p>I adhere to <a href="http://www.python.org/dev/peps/pep-0008/">PEP8</a> in my python code, and I'm currently using OptionParser for a script I'm writing. To prevent lines from going beyond a with of 80, I use the bac... | 11 | 2009-08-19T20:10:40Z | 1,302,379 | <p>try this:</p>
<pre><code>if __name__=='__main__':
usage = '%prog [options]\nWithout any options, will display 10 random ' \
'users of each type.'
parser = OptionParser(usage)
</code></pre>
| 1 | 2009-08-19T20:13:04Z | [
"python",
"wrapping",
"pep8"
] |
Python PEP8 printing wrapped strings without indent | 1,302,364 | <p>There is probably an easy answer for this, just not sure how to tease it out of my searches.</p>
<p>I adhere to <a href="http://www.python.org/dev/peps/pep-0008/">PEP8</a> in my python code, and I'm currently using OptionParser for a script I'm writing. To prevent lines from going beyond a with of 80, I use the bac... | 11 | 2009-08-19T20:10:40Z | 1,302,381 | <p>Use <a href="http://docs.python.org/tutorial/introduction.html#strings">automatic string concatenation</a> + <a href="http://docs.python.org/reference/lexical%5Fanalysis.html#implicit-line-joining">implicit line continuation</a>:</p>
<pre><code>long_string = ("Line 1 "
"Line 2 "
"Line ... | 28 | 2009-08-19T20:13:19Z | [
"python",
"wrapping",
"pep8"
] |
Python PEP8 printing wrapped strings without indent | 1,302,364 | <p>There is probably an easy answer for this, just not sure how to tease it out of my searches.</p>
<p>I adhere to <a href="http://www.python.org/dev/peps/pep-0008/">PEP8</a> in my python code, and I'm currently using OptionParser for a script I'm writing. To prevent lines from going beyond a with of 80, I use the bac... | 11 | 2009-08-19T20:10:40Z | 1,302,382 | <p>This works:</p>
<pre><code>if __name__=='__main__':
usage = ('%prog [options]\nWithout any options, will display 10 random '
'users of each type.')
parser = OptionParser(usage)
</code></pre>
<p>Although I'd lay it out like this:</p>
<pre><code>if __name__=='__main__':
usage = ('%prog [options]\n'
... | 3 | 2009-08-19T20:13:40Z | [
"python",
"wrapping",
"pep8"
] |
Django: do I need to restart Apache when deploying? | 1,302,411 | <p>I just noted an annoying factor: Django requires either a restart of the server or <a href="http://en.wikipedia.org/wiki/Common%5FGateway%5FInterface" rel="nofollow">CGI</a> access to work. The first option is not feasible if you don't have access to the Apache server process. The second, as far as I know, is detrim... | 1 | 2009-08-19T20:20:04Z | 1,302,419 | <p>Use the WSGI standard, through <a href="http://code.google.com/p/modwsgi/" rel="nofollow"><code>mod_wsgi</code></a>. You don't have to restart Apache, merely update the mtime on the .wsgi file. </p>
| 6 | 2009-08-19T20:22:11Z | [
"python",
"django"
] |
Django: do I need to restart Apache when deploying? | 1,302,411 | <p>I just noted an annoying factor: Django requires either a restart of the server or <a href="http://en.wikipedia.org/wiki/Common%5FGateway%5FInterface" rel="nofollow">CGI</a> access to work. The first option is not feasible if you don't have access to the Apache server process. The second, as far as I know, is detrim... | 1 | 2009-08-19T20:20:04Z | 1,304,627 | <p>I usually don't restart the server, but force-reload the configuration. On an Ubuntu Hardy server, that is</p>
<pre><code>sudo /etc/init.d/apache2 force-reload
</code></pre>
<p>and it's done almost immediately.</p>
| 0 | 2009-08-20T07:56:19Z | [
"python",
"django"
] |
Django: do I need to restart Apache when deploying? | 1,302,411 | <p>I just noted an annoying factor: Django requires either a restart of the server or <a href="http://en.wikipedia.org/wiki/Common%5FGateway%5FInterface" rel="nofollow">CGI</a> access to work. The first option is not feasible if you don't have access to the Apache server process. The second, as far as I know, is detrim... | 1 | 2009-08-19T20:20:04Z | 1,305,415 | <p>For how to deal with source code reloading when using Apache/mod_wsgi, read:</p>
<p><a href="http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode" rel="nofollow">http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode</a></p>
<p><a href="http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.... | 0 | 2009-08-20T11:02:30Z | [
"python",
"django"
] |
Produce multiple files from a single file in python | 1,302,499 | <p>I have a file like below.</p>
<blockquote>
<p>Sequence A.1.1 Bacteria<br />
ATGCGCGATATAGGCCT<br />
ATTATGCGCGCGCGC </p>
<p>Sequence A.1.2 Virus<br />
ATATATGCGCCGCGCGTA<br />
ATATATATGCGCGCCGGC </p>
<p>Sequence B.1.21 Chimpanzee<br />
ATATAGCGCGCGCGCGAT<br />
ATATATATGCGCG </p>
<p>Se... | 0 | 2009-08-19T20:36:42Z | 1,302,556 | <p>It's not 100% clear what you want to do, but something like:</p>
<pre><code>currout = None
seqname2file = dict()
for line in open('thefilewhosenameyoudonottellus.txt'):
if line.startswith('Sequence '):
seqname = line[9] # A or B or C
if seqname not in seqname2file:
filename = 'outputfileforseq... | 1 | 2009-08-19T20:48:25Z | [
"python",
"file"
] |
Produce multiple files from a single file in python | 1,302,499 | <p>I have a file like below.</p>
<blockquote>
<p>Sequence A.1.1 Bacteria<br />
ATGCGCGATATAGGCCT<br />
ATTATGCGCGCGCGC </p>
<p>Sequence A.1.2 Virus<br />
ATATATGCGCCGCGCGTA<br />
ATATATATGCGCGCCGGC </p>
<p>Sequence B.1.21 Chimpanzee<br />
ATATAGCGCGCGCGCGAT<br />
ATATATATGCGCG </p>
<p>Se... | 0 | 2009-08-19T20:36:42Z | 1,302,561 | <p>I'm not sure exactly what you want the output to be, but it sounds like you need something like:</p>
<pre><code>#!/usr/bin/python
# Open the input file
fhIn = open("input_file.txt", "r")
# Open the output files and store their handles in a dictionary
fhOut = {}
fhOut['A'] = open("sequence_a.txt", "w")
fhOut['B'] ... | 0 | 2009-08-19T20:49:11Z | [
"python",
"file"
] |
python for firefox extensions? | 1,302,567 | <p>Can I use python in firefox extensions? Does it work?</p>
| 23 | 2009-08-19T20:50:25Z | 1,302,574 | <p><strong>Yes</strong>, through an extension for mozilla, Python Extension (pythonext).</p>
<p>Originally hosted in <a href="http://pyxpcomext.mozdev.org/" rel="nofollow">mozdev</a>, PythonExt project have move to Google code, <strong>you can see it in <a href="http://code.google.com/p/pythonext/" rel="nofollow">Pyth... | 23 | 2009-08-19T20:51:38Z | [
"python",
"firefox",
"plugins",
"firefox-addon"
] |
What is the simplest way (in python) to print to a remote IPP/CUPS server or printer? | 1,302,650 | <p>I have a postscript file and want it to be printed on a IPP capable device (or CUPS server). What is the minimal code and dependencies I could get away with to do that.</p>
<p>Using LPR or libcups gives me lot of cross-plattform dependencies. So my first approach was to implement a minimal subset of IPP (the protoc... | 6 | 2009-08-19T21:11:42Z | 1,302,659 | <p>you need to add remote printer to CUPS:</p>
<pre><code>lpadmin -p printername -E -v //IPADDRESS/spool -m driver.ppd
</code></pre>
<p>where driver.ppd is the driver to print with</p>
<p>ps: this could also work for programatic access, if printer is set before.</p>
| 0 | 2009-08-19T21:16:13Z | [
"python",
"printing",
"cups",
"ipp-protocol"
] |
What is the simplest way (in python) to print to a remote IPP/CUPS server or printer? | 1,302,650 | <p>I have a postscript file and want it to be printed on a IPP capable device (or CUPS server). What is the minimal code and dependencies I could get away with to do that.</p>
<p>Using LPR or libcups gives me lot of cross-plattform dependencies. So my first approach was to implement a minimal subset of IPP (the protoc... | 6 | 2009-08-19T21:11:42Z | 28,203,190 | <p>There's a python wrapper for CUPS <code>ipptool</code> available at github:</p>
<ul>
<li><a href="https://github.com/ezeep/pyipptool" rel="nofollow">https://github.com/ezeep/pyipptool</a></li>
<li><a href="https://www.ezeep.com/blog/pyipptool-released" rel="nofollow">https://www.ezeep.com/blog/pyipptool-released</a... | 0 | 2015-01-28T21:57:15Z | [
"python",
"printing",
"cups",
"ipp-protocol"
] |
Convert a nested dataset to a flat dataset, while retaining enough data to convert it back to nested set | 1,302,653 | <p>Say I have a dataset like</p>
<pre><code>(1, 2, (3, 4), (5, 6), (7, 8, (9, 0)))
</code></pre>
<p>I want to convert it to a (semi) flat representation like,</p>
<pre><code>(
(1, 2),
(1, 2, 3, 4),
(1, 2, 5, 6),
(1, 2, 7, 8),
(1, 2, 7, 8, 9, 0),
)
</code></pre>
<p>If you use this, (taken from SO)</p>
<pre><code>de... | 0 | 2009-08-19T21:12:45Z | 1,302,780 | <p>How about a using a different "flat" representation, one which can be converted back:</p>
<pre><code>[1, 2, '(', 3, 4, ')', '(', 5, 6, ')', '(', 7, 8, '(', 9, 0, ')', ')']
</code></pre>
| 0 | 2009-08-19T21:41:06Z | [
"python",
"algorithm"
] |
Convert a nested dataset to a flat dataset, while retaining enough data to convert it back to nested set | 1,302,653 | <p>Say I have a dataset like</p>
<pre><code>(1, 2, (3, 4), (5, 6), (7, 8, (9, 0)))
</code></pre>
<p>I want to convert it to a (semi) flat representation like,</p>
<pre><code>(
(1, 2),
(1, 2, 3, 4),
(1, 2, 5, 6),
(1, 2, 7, 8),
(1, 2, 7, 8, 9, 0),
)
</code></pre>
<p>If you use this, (taken from SO)</p>
<pre><code>de... | 0 | 2009-08-19T21:12:45Z | 1,302,817 | <p>This will give the example output. Don't know if that's really the best way of representing the model you want, though...</p>
<pre><code>def combineflatten(seq):
items= tuple(item for item in seq if not isinstance(item, tuple))
yield items
for item in seq:
if isinstance(item, tuple):
... | 2 | 2009-08-19T21:50:03Z | [
"python",
"algorithm"
] |
How can I convert a URL query string into a list of tuples using Python? | 1,302,688 | <p>I am struggling to convert a url to a nested tuple.</p>
<pre><code># Convert this string
str = 'http://somesite.com/?foo=bar&key=val'
# to a tuple like this:
[(u'foo', u'bar'), (u'key', u'val')]
</code></pre>
<p>I assume I need to be doing something like:</p>
<pre><code> url = 'http://somesite.com/?foo=bar&a... | 8 | 2009-08-19T21:23:16Z | 1,302,696 | <p>I believe you are looking for the <a href="http://docs.python.org/library/urlparse.html"><code>urlparse</code></a> module.</p>
<blockquote>
<p>This module defines a standard
interface to break Uniform Resource
Locator (URL) strings up in components
(addressing scheme, network location,
path etc.), to comb... | 26 | 2009-08-19T21:25:00Z | [
"python",
"url",
"parsing"
] |
How can I convert a URL query string into a list of tuples using Python? | 1,302,688 | <p>I am struggling to convert a url to a nested tuple.</p>
<pre><code># Convert this string
str = 'http://somesite.com/?foo=bar&key=val'
# to a tuple like this:
[(u'foo', u'bar'), (u'key', u'val')]
</code></pre>
<p>I assume I need to be doing something like:</p>
<pre><code> url = 'http://somesite.com/?foo=bar&a... | 8 | 2009-08-19T21:23:16Z | 1,303,900 | <p>Andrew's answer was really informative and helpful. A less adept way to grab those params would be with a regular expression--something like this:</p>
<p>import re</p>
<pre><code>re_param = re.compile(r'(?P<key>w\+)=(?P<value>w\+)')
url = 'http://somesite.com/?foo=bar&key=val''
params_list = re_pa... | 0 | 2009-08-20T04:07:40Z | [
"python",
"url",
"parsing"
] |
What possible values does datetime.strptime() accept for %Z? | 1,302,701 | <p>Python's datetime.strptime() is documented as supporting a timezone in the %Z field. So, for example:</p>
<pre><code>In [1]: datetime.strptime('2009-08-19 14:20:36 UTC', "%Y-%m-%d %H:%M:%S %Z")
Out[1]: datetime.datetime(2009, 8, 19, 14, 20, 36)
</code></pre>
<p>However, "UTC" seems to be the only timezone I can ge... | 10 | 2009-08-19T21:26:21Z | 1,302,762 | <p>This is from the <code>time</code> module, but I'm almost certain it applies to <code>datetime</code>:</p>
<blockquote>
<p>Support for the %Z directive is based
on the values contained in tzname and
whether daylight is true. Because of
this, it is platform-specific except
for recognizing UTC and GMT which... | 3 | 2009-08-19T21:36:54Z | [
"python",
"datetime"
] |
What possible values does datetime.strptime() accept for %Z? | 1,302,701 | <p>Python's datetime.strptime() is documented as supporting a timezone in the %Z field. So, for example:</p>
<pre><code>In [1]: datetime.strptime('2009-08-19 14:20:36 UTC', "%Y-%m-%d %H:%M:%S %Z")
Out[1]: datetime.datetime(2009, 8, 19, 14, 20, 36)
</code></pre>
<p>However, "UTC" seems to be the only timezone I can ge... | 10 | 2009-08-19T21:26:21Z | 1,302,793 | <p>I gather they are GMT, UTC, and whatever is listed in time.tzname.</p>
<pre><code>>>> for t in time.tzname:
... print t
...
Eastern Standard Time
Eastern Daylight Time
>>> datetime.strptime('2009-08-19 14:20:36 Eastern Standard Time', "%Y-%m-%d %H:%M:%S %Z")
datetime.datetime(2009, 8, 19, 14, ... | 9 | 2009-08-19T21:44:04Z | [
"python",
"datetime"
] |
Python thread dump | 1,302,991 | <p>Is there a way to get a thread dump from a running Python process?
Similar to kill -3 on a Java process.</p>
| 5 | 2009-08-19T22:35:59Z | 1,303,362 | <p>I havent seen anything built-in, but I have seen <a href="http://bzimmer.ziclix.com/2008/12/17/python-thread-dumps/" rel="nofollow">a solution here</a> which can be exposed via http console. The solution iterates over all threads and outputs the stack.</p>
| 2 | 2009-08-20T00:31:18Z | [
"python"
] |
How to populate a list with items.count() from a queryset sorted by a datetime field | 1,302,999 | <p>I had a hard time formulating the title, so please edit it if you have a better one :)</p>
<p>I'm trying to display some statistics using the pygooglechart. And I am using Django to get the database items out of the database.</p>
<p>The database items has a datetime field wich i want to "sort on". What i really wa... | 0 | 2009-08-19T22:37:48Z | 1,303,361 | <p><a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/" rel="nofollow">django aggregation</a> </p>
| 0 | 2009-08-20T00:30:58Z | [
"python",
"django",
"pygooglechart"
] |
How to populate a list with items.count() from a queryset sorted by a datetime field | 1,302,999 | <p>I had a hard time formulating the title, so please edit it if you have a better one :)</p>
<p>I'm trying to display some statistics using the pygooglechart. And I am using Django to get the database items out of the database.</p>
<p>The database items has a datetime field wich i want to "sort on". What i really wa... | 0 | 2009-08-19T22:37:48Z | 1,304,749 | <p>Assuming you're running Django 1.1 or a fairly recent checkout, you can use the new <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/" rel="nofollow">aggregation features</a>. Something like:</p>
<pre><code>counts = MyModel.objects.values('datettimefield').annotate(Count('datettimefield'))
</code... | 2 | 2009-08-20T08:25:01Z | [
"python",
"django",
"pygooglechart"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,040 | <p>I'm sure that there's a CRC32 implementation in Python, but that may be too short (8 hex digits). On the upside, it's very quick.</p>
<p>Found it, <a href="http://docs.python.org/library/binascii.html#binascii.crc32" rel="nofollow">binascii.crc32</a></p>
| 3 | 2009-08-19T22:48:21Z | [
"python",
"hash"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,045 | <p>If you do have a collision, how are you going to tell that it actually happened?</p>
<p>If I were you, I would use hashlib to <code>sha1()</code> the <code>repr()</code>, and then just get a limited substring of it (first 16 characters, for example).</p>
<p>Unless you are talking about huge numbers of these object... | 1 | 2009-08-19T22:48:52Z | [
"python",
"hash"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,050 | <p>The builtin hash function of strings is fairly collision free, and also fairly short. It has <code>2**32</code> values, so it is fairly unlikely that you encounter collisions (if you use its abs value, it will have only <code>2**31</code> values).</p>
<p>You have been asking for the shortest hash function. That wou... | 26 | 2009-08-19T22:49:21Z | [
"python",
"hash"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,061 | <p>Short hashes mean you may have same hash for two different files. Same may happen for big hashes too, but its way more rare.
Maybe these file names should vary based on other references, like microtime (unless these files may be created too quickly).</p>
| 0 | 2009-08-19T22:53:17Z | [
"python",
"hash"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,063 | <p>You can make any hash you like shorter by simply truncating it. md5 is always 32 hex digits, but an arbitrary substring of it (or any other hash) has the proper qualities of a hash: equal values produce equal hashes, and the values are spread around a bunch.</p>
| 7 | 2009-08-19T22:53:53Z | [
"python",
"hash"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,188 | <p>We use hashlib.sha1.hexdigest(), which produces even longer strings, for cache objects with good success. Nobody is actually looking at cache files anyway.</p>
| 1 | 2009-08-19T23:33:05Z | [
"python",
"hash"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,524 | <p>Condsidering your use case, if you don't have your heart set on using separate cache files and you are not too far down that development path, you might consider using the <code>shelve</code> module.</p>
<p>This will give you a persistent dictionary (stored in a single dbm file) in which you store your objects. Pic... | 1 | 2009-08-20T01:37:17Z | [
"python",
"hash"
] |
Shortest hash in python to name cache files | 1,303,021 | <p>What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save <em>cache files</em> for some objects. The objects must have unique repr() so they are used to 'seed' the filename. I want to produce a possibly unique filename for each object (not that many). The... | 15 | 2009-08-19T22:43:51Z | 1,303,619 | <p>The <a href="http://en.wikipedia.org/wiki/Birthday%5Fparadox#Cast%5Fas%5Fa%5Fcollision%5Fproblem">birthday paradox</a> applies: given a good hash function, the expected number of hashes before a collision occurs is about sqrt(N), where N is the number of different values that the hash function can take. (The wikiped... | 33 | 2009-08-20T02:12:31Z | [
"python",
"hash"
] |
Interface with remote computers using Python | 1,303,047 | <p>I've just become the system admin for my research group's cluster and, in this respect, am a novice. I'm trying to make a few tools to monitor the network and need help getting started implementing them with python (my native tongue).</p>
<p>For example, I would like to view who is logged onto remote machines. By h... | 5 | 2009-08-19T22:49:09Z | 1,303,101 | <p>Here's a simple, cheap solution to get you started</p>
<pre><code>from subprocess import *
p = Popen('ssh servername who', shell=True, stdout=PIPE)
p.wait()
print p.stdout.readlines()
</code></pre>
<p>returns (eg)</p>
<pre><code>['usr pts/0 2009-08-19 16:03 (kakapo)\n',
'usr pts/1 2009-08... | 2 | 2009-08-19T23:07:16Z | [
"python",
"networking",
"monitoring"
] |
Interface with remote computers using Python | 1,303,047 | <p>I've just become the system admin for my research group's cluster and, in this respect, am a novice. I'm trying to make a few tools to monitor the network and need help getting started implementing them with python (my native tongue).</p>
<p>For example, I would like to view who is logged onto remote machines. By h... | 5 | 2009-08-19T22:49:09Z | 1,303,109 | <p>I've been using <a href="http://sourceforge.net/projects/pexpect/" rel="nofollow">Pexpect</a>, which let's you ssh into machines, send commands, read the output, and react to it, with success. I even started an open-source project around it, <a href="http://bitbucket.org/inerte/proxpect/" rel="nofollow">Proxpect</a>... | 2 | 2009-08-19T23:08:31Z | [
"python",
"networking",
"monitoring"
] |
Interface with remote computers using Python | 1,303,047 | <p>I've just become the system admin for my research group's cluster and, in this respect, am a novice. I'm trying to make a few tools to monitor the network and need help getting started implementing them with python (my native tongue).</p>
<p>For example, I would like to view who is logged onto remote machines. By h... | 5 | 2009-08-19T22:49:09Z | 1,303,114 | <p>This covers the bases. Notice the use of sudo for things that needed more privileges. We configured sudo to allow those commands for that user without needing a password typed.</p>
<p>Also, keep in mind that you should run ssh-agent to make this "make sense". But all in all, it works really well. Running <code>... | 0 | 2009-08-19T23:09:26Z | [
"python",
"networking",
"monitoring"
] |
Interface with remote computers using Python | 1,303,047 | <p>I've just become the system admin for my research group's cluster and, in this respect, am a novice. I'm trying to make a few tools to monitor the network and need help getting started implementing them with python (my native tongue).</p>
<p>For example, I would like to view who is logged onto remote machines. By h... | 5 | 2009-08-19T22:49:09Z | 1,303,116 | <p>The <a href="http://pexpect.sourceforge.net/pexpect.html" rel="nofollow">pexpect</a> module can help you interface with ssh. More or less, here is what your example would look like.</p>
<pre><code>child = pexpect.spawn('ssh servername')
child.expect('Password:')
child.sendline('ABCDEF')
(output,status) = child.send... | 1 | 2009-08-19T23:09:44Z | [
"python",
"networking",
"monitoring"
] |
Interface with remote computers using Python | 1,303,047 | <p>I've just become the system admin for my research group's cluster and, in this respect, am a novice. I'm trying to make a few tools to monitor the network and need help getting started implementing them with python (my native tongue).</p>
<p>For example, I would like to view who is logged onto remote machines. By h... | 5 | 2009-08-19T22:49:09Z | 1,303,117 | <p>Fabric is a simple way to automate some simple tasks like this, the version I'm currently using allows you to wrap up commands like so:</p>
<pre><code>run('whoami', fail='ignore')
</code></pre>
<p>you can specify config options (config.fab_user, config.fab_password) for each machine you need (if you want to automa... | 0 | 2009-08-19T23:09:52Z | [
"python",
"networking",
"monitoring"
] |
Interface with remote computers using Python | 1,303,047 | <p>I've just become the system admin for my research group's cluster and, in this respect, am a novice. I'm trying to make a few tools to monitor the network and need help getting started implementing them with python (my native tongue).</p>
<p>For example, I would like to view who is logged onto remote machines. By h... | 5 | 2009-08-19T22:49:09Z | 1,303,155 | <p>If your needs overgrow simple "<code>ssh remote-host.example.org who</code>" then there is an awesome python library, called <a href="http://en.wikipedia.org/wiki/RPyC" rel="nofollow">RPyC</a>. It has so called "classic" mode which allows to almost transparently execute Python code over the network with several line... | 1 | 2009-08-19T23:22:59Z | [
"python",
"networking",
"monitoring"
] |
Graph databases and RDF triplestores: storage of graph data in python | 1,303,105 | <p>I need to develop a graph database in python (I would enjoy if anybody can join me in the development. I already have a bit of code, but I would gladly discuss about it).</p>
<p>I did my research on the internet. in Java, <a href="http://neo4j.org/">neo4j</a> is a candidate, but I was not able to find anything abou... | 16 | 2009-08-19T23:07:36Z | 1,304,636 | <p>I think the solution really depends on exactly what it is you want to do with the graph once you have managed to store it on disk/in database, and this is a little unclear in your question. However, a couple of things you might wish to consider are:</p>
<ul>
<li>if you just want to persist the graph without using ... | 3 | 2009-08-20T07:59:20Z | [
"python",
"graph",
"database",
"graph-databases"
] |
Graph databases and RDF triplestores: storage of graph data in python | 1,303,105 | <p>I need to develop a graph database in python (I would enjoy if anybody can join me in the development. I already have a bit of code, but I would gladly discuss about it).</p>
<p>I did my research on the internet. in Java, <a href="http://neo4j.org/">neo4j</a> is a candidate, but I was not able to find anything abou... | 16 | 2009-08-19T23:07:36Z | 1,304,985 | <p>Hmm, maybe you should take a look at <a href="http://www.cubicweb.org" rel="nofollow">CubicWeb</a></p>
| 1 | 2009-08-20T09:22:03Z | [
"python",
"graph",
"database",
"graph-databases"
] |
Graph databases and RDF triplestores: storage of graph data in python | 1,303,105 | <p>I need to develop a graph database in python (I would enjoy if anybody can join me in the development. I already have a bit of code, but I would gladly discuss about it).</p>
<p>I did my research on the internet. in Java, <a href="http://neo4j.org/">neo4j</a> is a candidate, but I was not able to find anything abou... | 16 | 2009-08-19T23:07:36Z | 1,372,443 | <p>Regarding Neo4j, did you notice the existing <a href="http://wiki.neo4j.org/content/Python" rel="nofollow">Python bindings</a>? As for the disk storage, take a look at <a href="http://www.mail-archive.com/user@lists.neo4j.org/msg01128.html" rel="nofollow">this thread</a> on the <a href="http://neo4j.org/community/li... | 1 | 2009-09-03T09:39:41Z | [
"python",
"graph",
"database",
"graph-databases"
] |
Graph databases and RDF triplestores: storage of graph data in python | 1,303,105 | <p>I need to develop a graph database in python (I would enjoy if anybody can join me in the development. I already have a bit of code, but I would gladly discuss about it).</p>
<p>I did my research on the internet. in Java, <a href="http://neo4j.org/">neo4j</a> is a candidate, but I was not able to find anything abou... | 16 | 2009-08-19T23:07:36Z | 1,990,600 | <p>I have used both <a href="http://jena.sourceforge.net/">Jena</a>, which is a Java framework, and <a href="http://www.franz.com/agraph/allegrograph/">Allegrograph</a> (Lisp, Java, Python bindings). Jena has sister projects for storing graph data and has been around a long, long time. Allegrograph is quite good and ... | 5 | 2010-01-02T04:24:43Z | [
"python",
"graph",
"database",
"graph-databases"
] |
Graph databases and RDF triplestores: storage of graph data in python | 1,303,105 | <p>I need to develop a graph database in python (I would enjoy if anybody can join me in the development. I already have a bit of code, but I would gladly discuss about it).</p>
<p>I did my research on the internet. in Java, <a href="http://neo4j.org/">neo4j</a> is a candidate, but I was not able to find anything abou... | 16 | 2009-08-19T23:07:36Z | 4,986,634 | <p>Greetings from your Serius Cybernetics Intelligent Agent!</p>
<p>Some useful links...</p>
<ul>
<li><p><a href="http://rads.stackoverflow.com/amzn/click/0596153813" rel="nofollow">Programming the Semantic Web</a></p></li>
<li><p><a href="http://semprog.com/content/" rel="nofollow">SEMANTIC PROGRAMMING</a></p></li>
... | 2 | 2011-02-13T20:23:11Z | [
"python",
"graph",
"database",
"graph-databases"
] |
Graph databases and RDF triplestores: storage of graph data in python | 1,303,105 | <p>I need to develop a graph database in python (I would enjoy if anybody can join me in the development. I already have a bit of code, but I would gladly discuss about it).</p>
<p>I did my research on the internet. in Java, <a href="http://neo4j.org/">neo4j</a> is a candidate, but I was not able to find anything abou... | 16 | 2009-08-19T23:07:36Z | 6,726,392 | <p>Redland (http://librdf.org) is probably the solution you're looking for. It has Python bindings too.</p>
| 0 | 2011-07-17T19:56:52Z | [
"python",
"graph",
"database",
"graph-databases"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 1,303,252 | <h1>Python 2</h1>
<p>Use <code>isinstance(obj, basestring)</code> for an object-to-test <code>obj</code>.</p>
<p><a href="http://docs.python.org/library/functions.html#basestring">Docs</a>.</p>
| 181 | 2009-08-19T23:53:12Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 1,303,266 | <p>To check if an object <code>o</code> is a string type of a subclass of a string type:</p>
<pre><code>isinstance(o, basestring)
</code></pre>
<p>because both <code>str</code> and <code>unicode</code> are subclasses of <code>basestring</code>.</p>
<p>To check if the type of <code>o</code> is exactly <code>str</code... | 92 | 2009-08-19T23:58:15Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 1,313,335 | <p>I might deal with this in the duck-typing style, like others mention. How do I know a string is really a string? well, obviously by <em>converting</em> it to a string!</p>
<pre><code>def myfunc(word):
word = unicode(word)
...
</code></pre>
<p>If the arg is already a string or unicode type, real_word will ... | 4 | 2009-08-21T17:50:16Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 14,504,067 | <p>You can test it by concatenating with an empty string:</p>
<pre><code>def is_string(s):
try:
s += ''
except:
return False
return True
</code></pre>
<p><strong>Edit</strong>:</p>
<p>Correcting my answer after comments pointing out that this fails with lists</p>
<pre><code>def is_string(s):
return ... | 0 | 2013-01-24T14:48:52Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 22,501,512 | <pre><code>isinstance(your_object, basestring)
</code></pre>
<p>will be True if your object is indeed a string-type. 'str' is reserved word.</p>
<p>my apologies,
the correct answer is using 'basestring' instead of 'str' in order of it to include unicode strings as well - as been noted above by one of the other respon... | 2 | 2014-03-19T09:35:26Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 23,692,403 | <h1>Python 2 and 3</h1>
<h3>(cross-compatible)</h3>
<p>If you want to check with no regard for Python version (2.x vs 3.x), use <a href="http://pythonhosted.org/six/"><strong><code>six</code></strong></a> (<a href="https://pypi.python.org/pypi/six/">PyPI</a>) and it's <code>string_types</code> attribute:</p>
<pre><c... | 37 | 2014-05-16T03:57:49Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 25,798,563 | <pre><code>if type(varA) == str or type(varB) == str:
print 'string involved'
</code></pre>
<p>from
EDX - online course
MITx: 6.00.1x Introduction to Computer Science and Programming Using Python</p>
| -3 | 2014-09-11T23:38:26Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 26,535,728 | <h1>Python 3</h1>
<p>In Python 3.x <code>basestring</code> is not available anymore, as <code>str</code> is the sole string type (with the semantics of Python 2.x's <code>unicode</code>).</p>
<p>So the check in Python 3.x is just:</p>
<pre><code>isinstance(obj_to_test, str)
</code></pre>
<p>This follows <a href="ht... | 36 | 2014-10-23T19:19:58Z | [
"python",
"string",
"types",
"compatibility"
] |
How to find out if a Python object is a string? | 1,303,243 | <p>How can I check if a Python object is a string (either regular or Unicode)?</p>
| 195 | 2009-08-19T23:50:58Z | 26,963,019 | <p>For a nice duck-typing approach for string-likes that has the bonus of working with both Python 2.x and 3.x:</p>
<pre><code>def is_string(obj):
try:
obj + ''
return True
except TypeError:
return False
</code></pre>
<p><a href="http://stackoverflow.com/users/920374/wisefish">wisefish... | 0 | 2014-11-16T22:51:39Z | [
"python",
"string",
"types",
"compatibility"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.