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 |
|---|---|---|---|---|---|---|---|---|---|
How do I disable and then re-enable a warning? | 2,390,766 | <p>I'm writing some unit tests for a Python library and would like certain warnings to be raised as exceptions, which I can easily do with the <a href="http://docs.python.org/library/warnings.html#warnings.simplefilter">simplefilter</a> function. However, for one test I'd like to disable the warning, run the test, the... | 11 | 2010-03-06T00:03:18Z | 2,391,106 | <p>Reading through the docs and few times and poking around the source and shell I think I've figured it out. The docs could probably improve to make clearer what the behavior is.</p>
<p>The warnings module keeps a registry at __warningsregistry__ to keep track of which warnings have been shown. If a warning (message)... | 8 | 2010-03-06T02:14:11Z | [
"python",
"warnings"
] |
How do I disable and then re-enable a warning? | 2,390,766 | <p>I'm writing some unit tests for a Python library and would like certain warnings to be raised as exceptions, which I can easily do with the <a href="http://docs.python.org/library/warnings.html#warnings.simplefilter">simplefilter</a> function. However, for one test I'd like to disable the warning, run the test, the... | 11 | 2010-03-06T00:03:18Z | 2,391,508 | <p>Brian is spot on about the <code>__warningregistry__</code>. So you need to extend <code>catch_warnings</code> to save/restore the global <code>__warningregistry__</code> too</p>
<p>Something like this may work</p>
<pre><code>class catch_warnings_plus(warnings.catch_warnings):
def __enter__(self):
supe... | 5 | 2010-03-06T05:57:10Z | [
"python",
"warnings"
] |
How do I disable and then re-enable a warning? | 2,390,766 | <p>I'm writing some unit tests for a Python library and would like certain warnings to be raised as exceptions, which I can easily do with the <a href="http://docs.python.org/library/warnings.html#warnings.simplefilter">simplefilter</a> function. However, for one test I'd like to disable the warning, run the test, the... | 11 | 2010-03-06T00:03:18Z | 9,659,509 | <p>Brian Luft is correct about <code>__warningregistry__</code> being the cause of the problem. But I wanted to clarify one thing: the way the <code>warnings</code> module appears to work is that it sets <code>module.__warningregistry__</code> for <em>each module</em> where <code>warn()</code> is called. Complicating t... | 5 | 2012-03-11T22:27:22Z | [
"python",
"warnings"
] |
How do I disable and then re-enable a warning? | 2,390,766 | <p>I'm writing some unit tests for a Python library and would like certain warnings to be raised as exceptions, which I can easily do with the <a href="http://docs.python.org/library/warnings.html#warnings.simplefilter">simplefilter</a> function. However, for one test I'd like to disable the warning, run the test, the... | 11 | 2010-03-06T00:03:18Z | 26,347,105 | <p>Following on from Eli Collins' helpful clarification, here is a modified version of the <code>catch_warnings</code> context manager that clears the warnings registry in a given sequence of modules when entering the context manager, and restores the registry on exit:</p>
<pre><code>from warnings import catch_warning... | 2 | 2014-10-13T19:04:57Z | [
"python",
"warnings"
] |
How to debug Apache XML-RPC client with Python server | 2,390,772 | <p>I am writing xmlrpc codes to communicate between Apache XML-RPC client and a Python SimpleXMLRPCServer. I have difficulty debugging it, because I can't find a way to see the request XML/response XML. Are there anyway I can see it dump to console or logged in file?</p>
| 0 | 2010-03-06T00:04:34Z | 2,391,001 | <p>Use a network packet sniffer like <a href="http://www.ethereal.com/" rel="nofollow">ethereal</a> or <a href="http://www.wireshark.org/" rel="nofollow">wireshark</a>.</p>
| 1 | 2010-03-06T01:30:00Z | [
"java",
"python",
"debugging",
"xml-rpc",
"simplexmlrpcserver"
] |
How to debug Apache XML-RPC client with Python server | 2,390,772 | <p>I am writing xmlrpc codes to communicate between Apache XML-RPC client and a Python SimpleXMLRPCServer. I have difficulty debugging it, because I can't find a way to see the request XML/response XML. Are there anyway I can see it dump to console or logged in file?</p>
| 0 | 2010-03-06T00:04:34Z | 17,291,520 | <p>You can also use <strong>verbose=True</strong> in python xmlrpc client
Example:</p>
<pre><code>s = xmlrpclib.ServerProxy('http://test.xmlrpc.wordtracker.com/',verbose=True,encoding='UTF-8')
</code></pre>
| 0 | 2013-06-25T07:27:55Z | [
"java",
"python",
"debugging",
"xml-rpc",
"simplexmlrpcserver"
] |
How to properly subclass dict and override __getitem__ & __setitem__ | 2,390,827 | <p>I am debugging some code and I want to find out when a particular dictionary is accessed. Well, it's actually a class that subclass <code>dict</code> and implements a couple extra features. Anyway, what I would like to do is subclass <code>dict</code> myself and add override <code>__getitem__</code> and <code>__seti... | 41 | 2010-03-06T00:24:33Z | 2,390,889 | <p>What you're doing should absolutely work. I tested out your class, and aside from a missing opening parenthesis in your log statements, it works just fine. There are only two things I can think of. First, is the output of your log statement set correctly? You might need to put a <code>logging.basicConfig(level=loggi... | 16 | 2010-03-06T00:42:16Z | [
"python",
"dictionary"
] |
How to properly subclass dict and override __getitem__ & __setitem__ | 2,390,827 | <p>I am debugging some code and I want to find out when a particular dictionary is accessed. Well, it's actually a class that subclass <code>dict</code> and implements a couple extra features. Anyway, what I would like to do is subclass <code>dict</code> myself and add override <code>__getitem__</code> and <code>__seti... | 41 | 2010-03-06T00:24:33Z | 2,390,913 | <p>That should not really change the result (which should work, for good logging threshold values) :
your <strong>init</strong> should be : </p>
<pre><code>def __init__(self,*args,**kwargs) : dict.__init__(self,*args,**kwargs)
</code></pre>
<p>instead, because if you call your method with DictWatch([(1,2),(2,3)]) ... | 6 | 2010-03-06T00:48:39Z | [
"python",
"dictionary"
] |
How to properly subclass dict and override __getitem__ & __setitem__ | 2,390,827 | <p>I am debugging some code and I want to find out when a particular dictionary is accessed. Well, it's actually a class that subclass <code>dict</code> and implements a couple extra features. Anyway, what I would like to do is subclass <code>dict</code> myself and add override <code>__getitem__</code> and <code>__seti... | 41 | 2010-03-06T00:24:33Z | 2,390,997 | <p>Another issue when subclassing <code>dict</code> is that the built-in <code>__init__</code> doesn't call <code>update</code>, and the built-in <code>update</code> doesn't call <code>__setitem__</code>. So, if you want all setitem operations to go through your <code>__setitem__</code> function, you should make sure ... | 43 | 2010-03-06T01:27:09Z | [
"python",
"dictionary"
] |
Django serializer for one object | 2,391,002 | <p>I'm trying to figure out a way to serialize some Django model object to JSON format, something like:</p>
<pre><code>j = Job.objects.get(pk=1)
##############################################
#a way to get the JSON for that j variable???
##############################################
</code></pre>
<p>I don't want:</p... | 8 | 2010-03-06T01:31:04Z | 2,391,041 | <p>The hash you are looking for should be in the object's <code>__dict__</code> attribute:</p>
<pre><code>>>> import json
>>> j = Job.objects.get(pk=1)
>>> json.dumps(j.__dict__)
</code></pre>
| 3 | 2010-03-06T01:46:02Z | [
"python",
"django",
"json"
] |
Django serializer for one object | 2,391,002 | <p>I'm trying to figure out a way to serialize some Django model object to JSON format, something like:</p>
<pre><code>j = Job.objects.get(pk=1)
##############################################
#a way to get the JSON for that j variable???
##############################################
</code></pre>
<p>I don't want:</p... | 8 | 2010-03-06T01:31:04Z | 2,391,243 | <p>How about just massaging what you get back from serializers.serialize? It is not that hard to trim off the square brackets from the front and back of the result.</p>
<pre><code>job = Job.objects.get(pk=1)
array_result = serializers.serialize('json', [job], ensure_ascii=False)
just_object_result = array_result[1:-1... | 15 | 2010-03-06T03:32:57Z | [
"python",
"django",
"json"
] |
Django serializer for one object | 2,391,002 | <p>I'm trying to figure out a way to serialize some Django model object to JSON format, something like:</p>
<pre><code>j = Job.objects.get(pk=1)
##############################################
#a way to get the JSON for that j variable???
##############################################
</code></pre>
<p>I don't want:</p... | 8 | 2010-03-06T01:31:04Z | 35,613,027 | <p>I would suggest using Django's <code>model_to_dict</code>. If I'm not mistaken, <code>serializers.serialize()</code> relies on it, too, but it only works for <code>list</code>, <em>not single model instance</em>. That's how you get a <code>dict</code> instance with your model fields out of a single model: </p>
<pre... | 0 | 2016-02-24T21:02:13Z | [
"python",
"django",
"json"
] |
How to perform a signed PUT request with OAuth in Python | 2,391,018 | <p>How is this meant to work? Where are all the oauth_* values meant to go if not in an encoded body like a POST request? In what form do you sign it?</p>
<p>All the Python OAuth libraries I can find only support GET and POST. Does anyone know any that support all methods?</p>
| 3 | 2010-03-06T01:36:32Z | 2,391,169 | <p><a href="http://github.com/simplegeo/python-oauth2/issues#issue/5" rel="nofollow">python-oauth2</a> supports all HTTP verbs -- as the comment I've linked to says, and I quote,</p>
<blockquote>
<p>We use PUT extensively at SimpleGeo
(our python-simplegeo package uses
python-oauth2 and PUT requests).</p>
<... | 0 | 2010-03-06T02:49:49Z | [
"python",
"oauth"
] |
Python XML need help with programming error | 2,391,037 | <p>I am having the below code.</p>
<pre><code>import xml.dom.minidom
def get_a_document(name):
return xml.dom.minidom.parse(name)
doc = get_a_document("sources.xml")
sources = doc.childNodes[1]
for e in sources.childNodes:
if e.nodeType == e.ELEMENT_NODE and e.localName == "source":
for source ... | 1 | 2010-03-06T01:43:03Z | 2,391,124 | <p>What's probably happening is you're running into the nodes containing the whitespace between your tags. It's not clear what you're trying to do, but it might work if you just remove the <code>source.nodeType == source.ELEMENT_NAME</code> part.</p>
| 1 | 2010-03-06T02:21:14Z | [
"python",
"xml"
] |
Python XML need help with programming error | 2,391,037 | <p>I am having the below code.</p>
<pre><code>import xml.dom.minidom
def get_a_document(name):
return xml.dom.minidom.parse(name)
doc = get_a_document("sources.xml")
sources = doc.childNodes[1]
for e in sources.childNodes:
if e.nodeType == e.ELEMENT_NODE and e.localName == "source":
for source ... | 1 | 2010-03-06T01:43:03Z | 2,391,137 | <p>[DOM Text node "u'\n '", DOM Element: source at 0x709f80, DOM Text node "u'\n '"]</p>
<p>Every new line is treated as a separate child entity when using the xml.dom.minidom library. Unfortunately, these new lines do not contain the value e.ELEMENT_NAME value. It seems that you have realized this, but the ulti... | 1 | 2010-03-06T02:32:16Z | [
"python",
"xml"
] |
Python, dynamically invoke script | 2,391,099 | <p>I want to run a python script from within another. By within I mean any state changes from the child script effect the parent's state. So if a variable is set in the child, it gets changed in the parent.</p>
<p>Normally you could do something like </p>
<pre><code>import module
</code></pre>
<p>But the issue is he... | 3 | 2010-03-06T02:12:23Z | 2,391,105 | <p>You can use the <a href="http://docs.python.org/library/functions.html#__import__"><code>__import__</code></a> function which allows you to import a module dynamically:</p>
<pre><code>module = __import__(sys.argv[1])
</code></pre>
<p>(You may need to remove the trailing <code>.py</code> or not specify it on the co... | 8 | 2010-03-06T02:13:38Z | [
"python",
"command"
] |
Python, dynamically invoke script | 2,391,099 | <p>I want to run a python script from within another. By within I mean any state changes from the child script effect the parent's state. So if a variable is set in the child, it gets changed in the parent.</p>
<p>Normally you could do something like </p>
<pre><code>import module
</code></pre>
<p>But the issue is he... | 3 | 2010-03-06T02:12:23Z | 2,392,763 | <p>While <code>__import__</code> certainly executes the specified file, it also stores it in the python modules list. If you want to reexecute the same file, you'd have to do a reload.</p>
<p>You can also take a look at the python <a href="http://docs.python.org/reference/simple_stmts.html#exec" rel="nofollow"><code>e... | 0 | 2010-03-06T14:29:15Z | [
"python",
"command"
] |
Some doubts on implementing custom error pages in Web2Py | 2,391,297 | <p>I'm trying to implement a decorator for custom error pages in web2py
as per one of the haiti Todos. Ref -
<a href="http://web2py.com/AlterEgo/default/show/75" rel="nofollow">http://web2py.com/AlterEgo/default/show/75</a></p>
<p>I'm trying to keep it as a module in /modules directory so that I can
import it into the... | 2 | 2010-03-06T03:57:08Z | 2,419,381 | <p><a href="http://groups.google.com/group/web2py/browse_thread/thread/93ec919b91ca0a84/58d77827d577c1fc#58d77827d577c1fc" rel="nofollow">Solved</a> through the web2py users mailing list.</p>
<blockquote>
<p>you can also use: onerror = load_import('onerror').onerror </p>
<blockquote>
<p>HTTP object wasn't ... | 1 | 2010-03-10T18:11:23Z | [
"python",
"web2py"
] |
Starting VirtualBox VM using Python | 2,391,511 | <p>How can I start a virtual machine from virtualbox as <em>headless</em> using <strong><code>pyvb</code></strong> modules?</p>
| 2 | 2010-03-06T05:57:38Z | 2,392,695 | <p>You can use the real python bindings instead (and not a wrapper that call the VBoxManager command line in a subprocess, say pyvb) relatively easily by using the <a href="http://www.virtualbox.org/svn/vbox/trunk/src/VBox/Frontends/VBoxShell/vboxshell.py" rel="nofollow">vboxshell.py</a> script from virtual box.</p>
<... | 9 | 2010-03-06T14:03:56Z | [
"python",
"virtualbox"
] |
Models in database speed vs static dictionaries speed | 2,391,788 | <p>I have a need for some kind of information that is in essence static. There is not much of this information, but alot of objects will use that information.</p>
<p>Since there is not a lot of that information (few dictionaries and some lists), I thought that I have 2 options - create models for holding that informat... | 1 | 2010-03-06T07:58:02Z | 2,391,789 | <p>If you need fast access from multiple processes, then a database is the best option for you.</p>
<p>However, if you just want to keep data in memory and access it from multiple places in the same process, then Python dictionaries will be faster than accessing a DB.</p>
| 0 | 2010-03-06T07:59:24Z | [
"python",
"django",
"dictionary"
] |
Models in database speed vs static dictionaries speed | 2,391,788 | <p>I have a need for some kind of information that is in essence static. There is not much of this information, but alot of objects will use that information.</p>
<p>Since there is not a lot of that information (few dictionaries and some lists), I thought that I have 2 options - create models for holding that informat... | 1 | 2010-03-06T07:58:02Z | 2,391,832 | <p>If the data is static, there is no need to keep going back to the database. Just read it the first time it is required and cache the result.</p>
<p>If there is some reason you can't cache the result in your app, you can always use memcached to avoid hitting the database.</p>
<p>The advantage of using memcached is ... | 1 | 2010-03-06T08:17:19Z | [
"python",
"django",
"dictionary"
] |
Models in database speed vs static dictionaries speed | 2,391,788 | <p>I have a need for some kind of information that is in essence static. There is not much of this information, but alot of objects will use that information.</p>
<p>Since there is not a lot of that information (few dictionaries and some lists), I thought that I have 2 options - create models for holding that informat... | 1 | 2010-03-06T07:58:02Z | 2,391,876 | <p>If they're truly never, ever going to change, then feel free to put them in your <code>settings.py</code> file as you would declare a normal Python dictionary.</p>
<p>However, if you want your information to be modifiable through the normal Django methods, then use the database for persistent storage, and then make... | 3 | 2010-03-06T08:30:33Z | [
"python",
"django",
"dictionary"
] |
Which GUI framework to learn when you know scripting and HCI | 2,391,825 | <p>I have some knowledge about Human computer interaction and some basic knowledge programming scripts (Python) that run from start to finish and automate some tasks I want to do or calculations. In the past I built interfaces in HTML with PHP behind it.</p>
<p>I would like my python scripts to evolve from the command... | 1 | 2010-03-06T08:14:14Z | 2,393,129 | <p><a href="http://wiki.python.org/moin/PyQt" rel="nofollow">PyQt</a> and/or the very similar Nokia-sponsored <a href="http://en.wikipedia.org/wiki/PySide" rel="nofollow">PySide</a> (with a more "relaxed" license, LGPL instead of GPL, and the same underlying toolkit, Qt) do offer the advantage of similarity with Nokia'... | 6 | 2010-03-06T16:13:29Z | [
"python",
"windows",
"android",
"user-interface",
"meego"
] |
Which GUI framework to learn when you know scripting and HCI | 2,391,825 | <p>I have some knowledge about Human computer interaction and some basic knowledge programming scripts (Python) that run from start to finish and automate some tasks I want to do or calculations. In the past I built interfaces in HTML with PHP behind it.</p>
<p>I would like my python scripts to evolve from the command... | 1 | 2010-03-06T08:14:14Z | 2,393,295 | <p>PyGTK fufills at least the first three points. I'm not sure on the fourth. It has a nice tutorial here: <a href="http://www.pygtk.org/pygtk2tutorial/index.html" rel="nofollow">http://www.pygtk.org/pygtk2tutorial/index.html</a></p>
| 1 | 2010-03-06T17:00:36Z | [
"python",
"windows",
"android",
"user-interface",
"meego"
] |
Which GUI framework to learn when you know scripting and HCI | 2,391,825 | <p>I have some knowledge about Human computer interaction and some basic knowledge programming scripts (Python) that run from start to finish and automate some tasks I want to do or calculations. In the past I built interfaces in HTML with PHP behind it.</p>
<p>I would like my python scripts to evolve from the command... | 1 | 2010-03-06T08:14:14Z | 9,457,151 | <p>I guess you are looking for <a href="http://glade.gnome.org/" rel="nofollow"><strong>Glade</strong></a>.</p>
<p>The site says:</p>
<blockquote>
<p>Glade is a RAD tool to enable quick & easy development of user
interfaces for the GTK+ toolkit and the GNOME desktop environment.</p>
<p>The user interface... | 0 | 2012-02-26T21:06:17Z | [
"python",
"windows",
"android",
"user-interface",
"meego"
] |
SQLite or flat text file? | 2,392,017 | <p>I process a lot of text/data that I exchange between Python, R, and sometimes Matlab.</p>
<p>My go-to is the flat text file, but also use SQLite occasionally to store the data and access from each program (not Matlab yet though). I don't use GROUPBY, AVG, etc. in SQL as much as I do these operations in R, so I don'... | 8 | 2010-03-06T09:30:49Z | 2,392,026 | <p>If all the languages support SQLite - use it. The power of SQL might not be useful to you right now, but it probably will be at some point, and it saves you having to rewrite things later when you decide you want to be able to query your data in more complicated ways.</p>
<p>SQLite will also probably be substantial... | 15 | 2010-03-06T09:35:32Z | [
"python",
"sql",
"database",
"file-format"
] |
SQLite or flat text file? | 2,392,017 | <p>I process a lot of text/data that I exchange between Python, R, and sometimes Matlab.</p>
<p>My go-to is the flat text file, but also use SQLite occasionally to store the data and access from each program (not Matlab yet though). I don't use GROUPBY, AVG, etc. in SQL as much as I do these operations in R, so I don'... | 8 | 2010-03-06T09:30:49Z | 2,392,131 | <p>A flat text file (e.g. in csv format) would be the most portable solution. Almost every program/library can work with this format: R and Python have good csv support and if your data set isn't too large you can even import the csv into Excel for smaller tasks.</p>
<p>However, text files are unhandily for larger dat... | 5 | 2010-03-06T10:19:04Z | [
"python",
"sql",
"database",
"file-format"
] |
How to detect mouse and keyboard inactivity in linux | 2,392,076 | <p>I am developing an app on python which will check for user inactivity. Is there a way to check for key press and mouse move events in linux?</p>
| 4 | 2010-03-06T09:56:43Z | 2,392,612 | <p>You could monitor the /dev/input/* files, when a key is pressed/the mouse is moved it is written to one of those files.</p>
<p>Try this for example:</p>
<pre><code>fh = file('/dev/input/mice')
while True:
fh.read(3)
print 'Mouse moved!'
</code></pre>
<p>Now that I think of it, it might be... | 4 | 2010-03-06T13:32:45Z | [
"python",
"linux",
"input",
"keyboard",
"mouse"
] |
Sending MESSAGE to a person on facebook using python | 2,392,111 | <p>I want to make a script that can be used to send messages to our friends on facebook.
How do I proceed? Which is the best module to use? </p>
| 6 | 2010-03-06T10:07:46Z | 2,392,258 | <p><a href="http://github.com/sciyoshi/pyfacebook/" rel="nofollow">PyFacebook</a> is a Python client library for the Facebook API.</p>
| 0 | 2010-03-06T11:11:45Z | [
"python",
"api",
"facebook",
"scripting"
] |
Sending MESSAGE to a person on facebook using python | 2,392,111 | <p>I want to make a script that can be used to send messages to our friends on facebook.
How do I proceed? Which is the best module to use? </p>
| 6 | 2010-03-06T10:07:46Z | 2,393,511 | <p>You may indeed want <a href="https://github.com/sciyoshi/pyfacebook/" rel="nofollow">pyfacebook</a> as another answer suggested, though the URL I'm giving (on github.com) is where the project (esp. its source;-) actually lives.</p>
<p>A simple survey of Python APIs for facebook is <a href="http://wiki.developers.fa... | 6 | 2010-03-06T18:02:52Z | [
"python",
"api",
"facebook",
"scripting"
] |
Integration testing: Start a blocking server during `unittest.setUp` before testing it? | 2,392,132 | <p>I'm writing a service using <a href="http://incubator.apache.org/thrift/" rel="nofollow">Thrift</a> and need to apply some tests to ensure that it operates/responds as expected. To accomplish this, the most robust approach seems to be to use the <code>unittest</code> module. </p>
<p>I'd like to start the service in... | 1 | 2010-03-06T10:19:12Z | 2,392,777 | <p>If <code>serve()</code> blocks, then your best bet is to spawn a thread in <code>setUp</code> to call <code>serve()</code>. Then you have to figure out how to stop Thrift in the <code>tearDown</code> method.</p>
| 0 | 2010-03-06T14:31:31Z | [
"python",
"unit-testing",
"blocking",
"thrift"
] |
Integration testing: Start a blocking server during `unittest.setUp` before testing it? | 2,392,132 | <p>I'm writing a service using <a href="http://incubator.apache.org/thrift/" rel="nofollow">Thrift</a> and need to apply some tests to ensure that it operates/responds as expected. To accomplish this, the most robust approach seems to be to use the <code>unittest</code> module. </p>
<p>I'd like to start the service in... | 1 | 2010-03-06T10:19:12Z | 2,393,480 | <p>The "complete isolation" that <code>unittest</code> provides is excellent for <em>unit</em> tests (what it's <em>designed</em> for) but not necessarily for <em>integration</em> tests -- I see the attraction of reusing <code>unittest</code> for those, I do it myself to take advantage of special test runners &c th... | 6 | 2010-03-06T17:49:58Z | [
"python",
"unit-testing",
"blocking",
"thrift"
] |
Calculating very large exponents in python | 2,392,235 | <p>Currently i am simulating my cryptographic scheme to test it. I have developed the code but i am stuck at one point. </p>
<p>I am trying to take: <code>g**x</code>
where </p>
<pre><code>g = 256 bit number
x = 256 bit number
</code></pre>
<p>Python hangs at this point, i have read alot of forums, threads etcc but... | 6 | 2010-03-06T11:02:52Z | 2,392,249 | <p>It's not hanging, it's just processing. It <em>will</em> eventually give you the answer, provided it doesn't run out of memory first.</p>
<p>I haven't heard of the result of such a process being used in cryptography though; usually it's the modulus of said power that matters. If it's the same in your case then you ... | 11 | 2010-03-06T11:08:32Z | [
"python"
] |
Calculating very large exponents in python | 2,392,235 | <p>Currently i am simulating my cryptographic scheme to test it. I have developed the code but i am stuck at one point. </p>
<p>I am trying to take: <code>g**x</code>
where </p>
<pre><code>g = 256 bit number
x = 256 bit number
</code></pre>
<p>Python hangs at this point, i have read alot of forums, threads etcc but... | 6 | 2010-03-06T11:02:52Z | 2,392,261 | <p>I'm not quite sure you appreciate the sheer magnitude of what you're asking Python to do. Raising something to a power <code>x</code> where <code>x</code> is 256 bits long, is doing the equivalent of 2**256 multiplications, or 115792089237316195423570985008687907853269984665640564039457584007913129639936 multiplicat... | 7 | 2010-03-06T11:12:23Z | [
"python"
] |
Calculating very large exponents in python | 2,392,235 | <p>Currently i am simulating my cryptographic scheme to test it. I have developed the code but i am stuck at one point. </p>
<p>I am trying to take: <code>g**x</code>
where </p>
<pre><code>g = 256 bit number
x = 256 bit number
</code></pre>
<p>Python hangs at this point, i have read alot of forums, threads etcc but... | 6 | 2010-03-06T11:02:52Z | 2,392,288 | <p>You shouldn't try to calculate x^y directly for huge values of y - as has already been pointed out, this is pretty difficult to do (takes lots of space and processing power). You need to look at algorithms that solve the problem for you with fewer multiplication operations. Take a look at: <a href="http://en.wikiped... | 8 | 2010-03-06T11:20:35Z | [
"python"
] |
python json loads and unicode | 2,392,501 | <p>I have the following case where I get the result of UTF-8 encoded HTTP response. I want to load the response content(JSON). However I don't know why I have to do 2 <code>json.loads</code> so that I get the final list:</p>
<pre><code>result = urllib2.urlopen(req).read()
print result, type(result)
#=> "[{\"pk\": 6... | 2 | 2010-03-06T12:54:33Z | 2,392,529 | <p>It looks like the <code>repr()</code> of the JSON string is what's being returned instead of the JSON string itself. So, something is broken on the server.</p>
| 3 | 2010-03-06T13:04:48Z | [
"python",
"json",
"unicode",
"utf-8",
"simplejson"
] |
Suppose I have this loop in Django...how do I display this? | 2,392,556 | <pre><code>{% for p in profiles %}
<div class="result">
{{ p.first_name }}
</div>
{% endfor %}
</code></pre>
<p>Suppose I have 1000 of these, in a huge list.
How would I make this code appear every 15 times?</p>
<pre><code><div class="menu">abc</div>
</code></pre>
| 0 | 2010-03-06T13:14:14Z | 2,392,562 | <p>You can use the <code>forloop.counter</code> value with a <code>divisibleby</code> filter in an <code>if</code> condition. See the documentation <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins" rel="nofollow">here</a></p>
| 1 | 2010-03-06T13:16:59Z | [
"javascript",
"python",
"css",
"django",
"templates"
] |
Suppose I have this loop in Django...how do I display this? | 2,392,556 | <pre><code>{% for p in profiles %}
<div class="result">
{{ p.first_name }}
</div>
{% endfor %}
</code></pre>
<p>Suppose I have 1000 of these, in a huge list.
How would I make this code appear every 15 times?</p>
<pre><code><div class="menu">abc</div>
</code></pre>
| 0 | 2010-03-06T13:14:14Z | 2,392,569 | <p>Use the <a href="http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#for" rel="nofollow">forloop.counter</a> variable with <a href="http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#divisibleby" rel="nofollow">divisbleby</a> filter.</p>
<pre><code>{% if forloop.counter|divisbleby:"15" %}
<... | 2 | 2010-03-06T13:19:13Z | [
"javascript",
"python",
"css",
"django",
"templates"
] |
replace multiple string in a file | 2,392,623 | <p>I am trying to replace multiple string in a file.</p>
<pre><code>fp1 = open(final,"w")
data = open(initial).read()
for key, value in mydict.items():
fp1.write(re.sub(key,value, data)
fp1.close()
</code></pre>
<p>But only my last key value get replaced. how can I replace all the key,value in the file.
Is there ... | 2 | 2010-03-06T13:37:18Z | 2,392,685 | <p>This should be better.</p>
<pre><code>fp1 = open(final,"w")
fp2 = open(initial, 'r')
data = fp2.read()
fp2.close()
for key, value in mydict.items():
data = data.replace(key, value)
fp1.write(data)
fp1.close()
</code></pre>
| 0 | 2010-03-06T14:01:21Z | [
"python"
] |
replace multiple string in a file | 2,392,623 | <p>I am trying to replace multiple string in a file.</p>
<pre><code>fp1 = open(final,"w")
data = open(initial).read()
for key, value in mydict.items():
fp1.write(re.sub(key,value, data)
fp1.close()
</code></pre>
<p>But only my last key value get replaced. how can I replace all the key,value in the file.
Is there ... | 2 | 2010-03-06T13:37:18Z | 2,392,850 | <pre><code>fp1 = open("final","w")
fp2 = open("file", 'r')
for line in fp2:
sline=line.rstrip().split()
for n,item in enumerate(sline):
if item in d:
sline[n]=d[item]
fp1.write(' '.join(sline) +"\n")
</code></pre>
| 0 | 2010-03-06T14:53:43Z | [
"python"
] |
replace multiple string in a file | 2,392,623 | <p>I am trying to replace multiple string in a file.</p>
<pre><code>fp1 = open(final,"w")
data = open(initial).read()
for key, value in mydict.items():
fp1.write(re.sub(key,value, data)
fp1.close()
</code></pre>
<p>But only my last key value get replaced. how can I replace all the key,value in the file.
Is there ... | 2 | 2010-03-06T13:37:18Z | 2,393,359 | <p>This is one task for which regular expressions can really help:</p>
<pre><code>import re
def replacemany(adict, astring):
pat = '|'.join(re.escape(s) for s in adict)
there = re.compile(pat)
def onerepl(mo): return adict[mo.group()]
return there.sub(onerepl, astring)
if __name__ == '__main__':
d = {'k1':... | 5 | 2010-03-06T17:21:01Z | [
"python"
] |
How do you run a python script from within notepad++? | 2,392,629 | <p>When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.</p>
| 39 | 2010-03-06T13:41:20Z | 2,392,658 | <p>if u have the NppExec plugin (is by default) hit F6 and add the command that exec your script </p>
<pre><code>python /path/to/script.py
</code></pre>
| 2 | 2010-03-06T13:54:23Z | [
"python",
"notepad++",
"nppexec"
] |
How do you run a python script from within notepad++? | 2,392,629 | <p>When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.</p>
| 39 | 2010-03-06T13:41:20Z | 2,392,662 | <p>You need to pass through the FULL_CURRENT_PATH environment variable to the program, as described in the <a href="http://npp-wiki.tuxfamily.org/index.php?title=External_Programs" rel="nofollow">notepad++ wiki</a>:</p>
<pre><code>python "$(FULL_CURRENT_PATH)"
</code></pre>
| 10 | 2010-03-06T13:55:05Z | [
"python",
"notepad++",
"nppexec"
] |
How do you run a python script from within notepad++? | 2,392,629 | <p>When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.</p>
| 39 | 2010-03-06T13:41:20Z | 3,071,177 | <p>Plugins <strong>NppExec</strong> Execute (<kbd>F6</kbd>) is much more powerful than plain Run (<kbd>F5</kbd>). Install NppExec via Plugins, Plugin Manager. Then in <kbd>F6</kbd> add/save the following:</p>
<pre><code>NPP_SAVE
cd "$(FULL_CURRENT_PATH)"
C:\Python34\python.exe -u "$(FULL_CURRENT_PATH)"
</code></pre>
... | 44 | 2010-06-18T15:56:22Z | [
"python",
"notepad++",
"nppexec"
] |
How do you run a python script from within notepad++? | 2,392,629 | <p>When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.</p>
| 39 | 2010-03-06T13:41:20Z | 13,709,225 | <h2>possible to use pdb too</h2>
<p>The answers above were very useful to get it working. However, once i could run the python programs, I also needed to interact with them. Two things I found out.</p>
<ol>
<li>Use "<strong>python -u -i $(FULL_CURRENT_PATH)</strong>" if you wish to interact with your program (like gi... | 6 | 2012-12-04T18:11:36Z | [
"python",
"notepad++",
"nppexec"
] |
How do you run a python script from within notepad++? | 2,392,629 | <p>When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.</p>
| 39 | 2010-03-06T13:41:20Z | 24,121,190 | <p>You can use PyNPP Plugin (<a href="https://github.com/mpcabd/PyNPP" rel="nofollow">https://github.com/mpcabd/PyNPP</a>) to achieve this.</p>
<p><em>I know this is old but the answer is for people coming from search.</em></p>
| 4 | 2014-06-09T13:18:42Z | [
"python",
"notepad++",
"nppexec"
] |
How do you run a python script from within notepad++? | 2,392,629 | <p>When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.</p>
| 39 | 2010-03-06T13:41:20Z | 32,467,585 | <p>Unless I'm missing something, the other answers discussing NppExec do not provide a way to run the script with a single keystroke or (the execute dialogue box always pops up when <kbd>F6</kbd> is pressed which must be accepted before the script is run).</p>
<p>After completing the steps in <a href="http://stackover... | 0 | 2015-09-08T21:32:11Z | [
"python",
"notepad++",
"nppexec"
] |
Do python packages (multi-file modules) behave exactly as one big module? | 2,392,704 | <p>I've just read an article that supposedly introduced me to a new concept: Up to now I was sure that python packages (i.e directories with an <code>__init__.py</code> file) behave exactly the same as java packages, that is - little namespaces to help arrange the code (minus java's "package" scoping).
But, according t... | 10 | 2010-03-06T14:07:39Z | 2,392,822 | <p>Maybe the point is simply that a package is just a specific type of module.</p>
<pre><code>/base
/animals
/__init__.py
/dog.py
</code></pre>
<p>It just means that anything that you define in or import into <code>__init__.py</code> will be visible inside the <code>animals</code> module.</p>
<p>... | 4 | 2010-03-06T14:45:47Z | [
"python",
"module",
"package",
"multifile"
] |
Do python packages (multi-file modules) behave exactly as one big module? | 2,392,704 | <p>I've just read an article that supposedly introduced me to a new concept: Up to now I was sure that python packages (i.e directories with an <code>__init__.py</code> file) behave exactly the same as java packages, that is - little namespaces to help arrange the code (minus java's "package" scoping).
But, according t... | 10 | 2010-03-06T14:07:39Z | 2,392,830 | <p>I can't really explain it well, but maybe the following code will help. If I leave your first file structure as it is, and instead modify the second to have the following in the animals.py file:</p>
<pre><code>class Dog:
def bark(self): pass
dog=Dog()
</code></pre>
<p>Then in both cases, </p>
<pre><code>from ... | 0 | 2010-03-06T14:47:53Z | [
"python",
"module",
"package",
"multifile"
] |
Do python packages (multi-file modules) behave exactly as one big module? | 2,392,704 | <p>I've just read an article that supposedly introduced me to a new concept: Up to now I was sure that python packages (i.e directories with an <code>__init__.py</code> file) behave exactly the same as java packages, that is - little namespaces to help arrange the code (minus java's "package" scoping).
But, according t... | 10 | 2010-03-06T14:07:39Z | 2,393,027 | <p>The author has oversimplified things. He's saying that everything under <code>animal</code> can be seen as being in the same module, although the fact is that names in <code>animal.dog</code> will be in their own namespace.</p>
| 4 | 2010-03-06T15:43:36Z | [
"python",
"module",
"package",
"multifile"
] |
Do python packages (multi-file modules) behave exactly as one big module? | 2,392,704 | <p>I've just read an article that supposedly introduced me to a new concept: Up to now I was sure that python packages (i.e directories with an <code>__init__.py</code> file) behave exactly the same as java packages, that is - little namespaces to help arrange the code (minus java's "package" scoping).
But, according t... | 10 | 2010-03-06T14:07:39Z | 7,966,472 | <p>Not a real answer, but as I'm not yet allowed to comment (sigh!):</p>
<p>Since diveintopython is much used/cited/referenced resource for Python programmers (at least when they begin with), you should really contact the author about this flaw as it will be misleading also to others. There is some contact information... | 1 | 2011-11-01T12:30:43Z | [
"python",
"module",
"package",
"multifile"
] |
SQLite, python, unicode, and non-utf data | 2,392,732 | <p>I started by trying to store strings in sqlite using python, and got the message:</p>
<blockquote>
<p>sqlite3.ProgrammingError: You must
not use 8-bit bytestrings unless you
use a text_factory that can interpret
8-bit bytestrings (like text_factory =
str). It is highly recommended that
you instead just ... | 57 | 2010-03-06T14:15:42Z | 2,392,773 | <p>Of course there is. But your data is already broken in the database, so you'll need to fix it:</p>
<pre><code>>>> print u'Sigur Rós'.encode('latin-1').decode('utf-8')
Sigur Rós
</code></pre>
| 6 | 2010-03-06T14:30:58Z | [
"python",
"sqlite",
"unicode",
"utf-8"
] |
SQLite, python, unicode, and non-utf data | 2,392,732 | <p>I started by trying to store strings in sqlite using python, and got the message:</p>
<blockquote>
<p>sqlite3.ProgrammingError: You must
not use 8-bit bytestrings unless you
use a text_factory that can interpret
8-bit bytestrings (like text_factory =
str). It is highly recommended that
you instead just ... | 57 | 2010-03-06T14:15:42Z | 2,392,803 | <blockquote>
<p>I'm still ignorant of whether there is a way to correctly convert 'ó' from latin-1 to utf-8 and not mangle it</p>
</blockquote>
<p>repr() and unicodedata.name() are your friends when it comes to debugging such problems:</p>
<pre><code>>>> oacute_latin1 = "\xF3"
>>> oacute_unicode ... | 31 | 2010-03-06T14:40:35Z | [
"python",
"sqlite",
"unicode",
"utf-8"
] |
SQLite, python, unicode, and non-utf data | 2,392,732 | <p>I started by trying to store strings in sqlite using python, and got the message:</p>
<blockquote>
<p>sqlite3.ProgrammingError: You must
not use 8-bit bytestrings unless you
use a text_factory that can interpret
8-bit bytestrings (like text_factory =
str). It is highly recommended that
you instead just ... | 57 | 2010-03-06T14:15:42Z | 2,395,414 | <p>UTF-8 is the default encoding of SQLite databases. This shows up in situations like "SELECT CAST(x'52C3B373' AS TEXT);". However, the SQLite C library doesn't actually check whether a string inserted into a DB is valid UTF-8.</p>
<p>If you insert a Python unicode object (or str object in 3.x), the Python sqlite3 ... | 19 | 2010-03-07T06:36:56Z | [
"python",
"sqlite",
"unicode",
"utf-8"
] |
SQLite, python, unicode, and non-utf data | 2,392,732 | <p>I started by trying to store strings in sqlite using python, and got the message:</p>
<blockquote>
<p>sqlite3.ProgrammingError: You must
not use 8-bit bytestrings unless you
use a text_factory that can interpret
8-bit bytestrings (like text_factory =
str). It is highly recommended that
you instead just ... | 57 | 2010-03-06T14:15:42Z | 2,589,423 | <p>I fixed this pysqlite problem by setting: </p>
<pre><code>conn.text_factory = lambda x: unicode(x, 'utf-8', 'ignore')
</code></pre>
<p>By default text_factory is set to unicode(), which will use the current default encoding (ascii on my machine)</p>
| 16 | 2010-04-07T01:17:44Z | [
"python",
"sqlite",
"unicode",
"utf-8"
] |
SQLite, python, unicode, and non-utf data | 2,392,732 | <p>I started by trying to store strings in sqlite using python, and got the message:</p>
<blockquote>
<p>sqlite3.ProgrammingError: You must
not use 8-bit bytestrings unless you
use a text_factory that can interpret
8-bit bytestrings (like text_factory =
str). It is highly recommended that
you instead just ... | 57 | 2010-03-06T14:15:42Z | 27,756,518 | <p>My unicode problems with Python 2.x (Python 2.7.6 to be specific) fixed this:</p>
<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
</code></pre>
<p>It also solved the error you are mentioning right at the beginn... | 2 | 2015-01-03T15:41:37Z | [
"python",
"sqlite",
"unicode",
"utf-8"
] |
pyqt signal problem | 2,392,793 | <p>I'm working on a plugin for Avogadro (chemistry software) that uses pyqt.
I've some problem with connecting a method to the clicked signal of a button.
I've my class: </p>
<pre><code>class Controller(object):
def __init__(self):
self.ui = MyDialog() # self.ui.run is a QPushButton
self.ui.run.cli... | 1 | 2010-03-06T14:37:10Z | 2,392,823 | <p>Unless they've considerably changed something recently, this doesn't seem like the way to connect signals in PyQt. I'm more used to:</p>
<pre><code>self.connect(self.ui.run, QtCore.SIGNAL("clicked()"),
self, QtCore.SLOT("on_run_click()"))
</code></pre>
| 1 | 2010-03-06T14:45:50Z | [
"python",
"pyqt4"
] |
pyqt signal problem | 2,392,793 | <p>I'm working on a plugin for Avogadro (chemistry software) that uses pyqt.
I've some problem with connecting a method to the clicked signal of a button.
I've my class: </p>
<pre><code>class Controller(object):
def __init__(self):
self.ui = MyDialog() # self.ui.run is a QPushButton
self.ui.run.cli... | 1 | 2010-03-06T14:37:10Z | 2,398,308 | <p>The problem is that Avogadro python wrappers don't support the new signal syntax as described in Tim's blog post:
<a href="http://timvdm.blogspot.com/2008/12/avogadro-gets-new-python-wrappers.html" rel="nofollow">http://timvdm.blogspot.com/2008/12/avogadro-gets-new-python-wrappers.html</a></p>
| 1 | 2010-03-07T22:43:36Z | [
"python",
"pyqt4"
] |
Python: Simple Dictionary referencing Problem | 2,392,920 | <p>I have a simple problem that i cannot solve. I have a dictionary:</p>
<pre><code>aa = {'ALA':'A'}
test = 'ALA'
</code></pre>
<p>I'm have trouble writing code where that value from test is taken and referenced in the dictionary aa and 'A' is printed.</p>
<p>I'm assuming i would have to use a for loop? something li... | 1 | 2010-03-06T15:12:24Z | 2,392,934 | <blockquote>
<p>I'm have trouble writing code where that value from test is taken and referenced in the dictionary aa and 'A' is printed.</p>
</blockquote>
<p>Do you mean this?</p>
<pre><code>print aa[test]
</code></pre>
<blockquote>
<p>Its taking the value from i and using it to reference aa i am having trouble... | 2 | 2010-03-06T15:15:51Z | [
"python",
"dictionary"
] |
Python: Simple Dictionary referencing Problem | 2,392,920 | <p>I have a simple problem that i cannot solve. I have a dictionary:</p>
<pre><code>aa = {'ALA':'A'}
test = 'ALA'
</code></pre>
<p>I'm have trouble writing code where that value from test is taken and referenced in the dictionary aa and 'A' is printed.</p>
<p>I'm assuming i would have to use a for loop? something li... | 1 | 2010-03-06T15:12:24Z | 2,392,957 | <p>Not sure what you are trying to do, but perhaps you mean:</p>
<pre><code>aa = {'ALA':'A'}
test = ['ALA'] ###Â note this is now a list!
for i in test:
if i in aa:
print i, aa[i] #### note i is the key, aa[i] is the value
</code></pre>
<p>note that you can make three different kinds of iterators from ... | 2 | 2010-03-06T15:24:04Z | [
"python",
"dictionary"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 2,392,942 | <p>If your items are grouped (i.e. similar items come together in a bunch), the most efficient method to use is <code>itertools.groupby</code>:</p>
<pre><code>>>> [(g[0], len(list(g[1]))) for g in itertools.groupby(['a', 'a', 'b', 'b', 'b'])]
[('a', 2), ('b', 3)]
</code></pre>
| 8 | 2010-03-06T15:18:04Z | [
"python"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 2,392,948 | <p>When Python 2.7 comes out you can use its <a href="http://docs.python.org/dev/library/collections.html#collections.Counter">collections.Counter class</a></p>
<p>otherwise see <a href="http://code.activestate.com/recipes/576611/">counter receipe</a></p>
<p>Under Python 2.7a3 </p>
<pre><code>from collections import... | 45 | 2010-03-06T15:20:11Z | [
"python"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 2,392,986 | <p>I know this isn't a one-liner... but to me I like it because it's clear to me that we pass over the initial list of values once (instead of calling count on it):</p>
<pre><code>>>> from collections import defaultdict
>>> l = ['a', 'a', 'b', 'b', 'b']
>>> d = defaultdict(int)
>>> ... | 2 | 2010-03-06T15:31:06Z | [
"python"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 2,393,043 | <p>Another way to do this would be</p>
<pre><code>mylist = [1, 1, 2, 3, 3, 3, 4, 4, 4, 4]
mydict = {}
for i in mylist:
if i in mydict: mydict[i] += 1
else: mydict[i] = 1
</code></pre>
<p>then to get the list of tuples,</p>
<pre><code>mytups = [(i, mydict[i]) for i in mydict]
</code></pre>
<p>This only goes ... | 1 | 2010-03-06T15:48:21Z | [
"python"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 2,393,202 | <p>the "old school way".</p>
<pre><code>>>> alist=['a', 'a', 'b', 'b', 'b']
>>> d={}
>>> for i in alist:
... if not d.has_key(i): d[i]=1 #also: if not i in d
... else: d[i]+=1
...
>>> d
{'a': 2, 'b': 3}
</code></pre>
| 1 | 2010-03-06T16:34:06Z | [
"python"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 2,393,255 | <pre><code>>>> mylist=['a', 'a', 'b', 'b', 'b']
>>> [ (i,mylist.count(i)) for i in set(mylist) ]
[('a', 2), ('b', 3)]
</code></pre>
| 6 | 2010-03-06T16:50:05Z | [
"python"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 2,393,390 | <p>A solution without hashing:</p>
<pre><code>def lcount(lst):
return reduce(lambda a, b: a[0:-1] + [(a[-1][0], a[-1][1]+1)] if a and b == a[-1][0] else a + [(b, 1)], lst, [])
>>> lcount([])
[]
>>> lcount(['a'])
[('a', 1)]
>>> lcount(['a', 'a', 'a', 'b', 'b'])
[('a', 3), ('b', 2)]
</code... | 0 | 2010-03-06T17:28:09Z | [
"python"
] |
How to get unique values with respective occurance count from a list in Python? | 2,392,929 | <p>I have a list which has repeating items and I want a list of the unique items with their frequency. </p>
<p>For example, I have ['a', 'a', 'b', 'b', 'b'], and I want [('a', 2), ('b', 3)]</p>
<p>Looking for a simple way to do this without looping twice. </p>
| 18 | 2010-03-06T15:14:45Z | 29,954,440 | <p>Convert any data structure into a pandas series s:</p>
<p>CODE:</p>
<pre><code>for i in sort(s.value_counts().unique()):
print i, (s.value_counts()==i).sum()
</code></pre>
| -1 | 2015-04-29T20:59:43Z | [
"python"
] |
How do I change Remote Desktop Services properties of AD users in .NET? | 2,392,949 | <p>I need to set properties related to Remote Desktop Services on Active Directory users in .NET (i.e., via System.DirectoryServices), but I can't see that these properties are exposed by the API? I know there is a COM interface for this purpose, IADsTSUserEx. Please show me how I can get at these properties in .NET :)... | 0 | 2010-03-06T15:20:39Z | 2,395,974 | <p>The .NET DirectoryServices API doesn't expose AD properties directly: instead, there's a big <code>Properties</code> collection on the <code>DirectoryEntry</code> class. If you can find out the names of the attributes in the underlying AD schema then you be able to find them in this collection.</p>
<p>This list sho... | 0 | 2010-03-07T10:52:13Z | [
".net",
"python",
"active-directory",
"directoryservices"
] |
How do I change Remote Desktop Services properties of AD users in .NET? | 2,392,949 | <p>I need to set properties related to Remote Desktop Services on Active Directory users in .NET (i.e., via System.DirectoryServices), but I can't see that these properties are exposed by the API? I know there is a COM interface for this purpose, IADsTSUserEx. Please show me how I can get at these properties in .NET :)... | 0 | 2010-03-06T15:20:39Z | 14,938,596 | <p>The problem with some of these properties is that you can see them on the UI via Active Directory Users and Computers, but you cannot set them (or see them) via ADSI Editor. </p>
<p>Usually, for properties that aren't directly available from a <code>DirectoryEntry</code> object, you can use its <code>Properties</co... | 0 | 2013-02-18T14:27:59Z | [
".net",
"python",
"active-directory",
"directoryservices"
] |
Where is the full JID value when using xmpppy? | 2,393,011 | <p>Where do I find the full JID value after connecting and authenticating against a Jabber server when using the <a href="http://xmpppy.sourceforge.net/" rel="nofollow">xmpppy</a> library?</p>
<p>I need the full JID for a subsequent <code>Iq</code> call to the server. Specifying the bare JID (user@domain.com) results... | 1 | 2010-03-06T15:37:21Z | 2,393,264 | <p>I don't see the JID being stored as such either, but in <a href="http://xmpppy.sourceforge.net/apidocs/xmpp.client-pysrc.html#Client.auth" rel="nofollow">auth's sources</a>, line 213, I see</p>
<pre><code>self._User,self._Password,self._Resource=user,password,resource
</code></pre>
<p>where <code>self</code> is th... | 1 | 2010-03-06T16:51:49Z | [
"python",
"xmpp",
"xmpppy"
] |
Where is the full JID value when using xmpppy? | 2,393,011 | <p>Where do I find the full JID value after connecting and authenticating against a Jabber server when using the <a href="http://xmpppy.sourceforge.net/" rel="nofollow">xmpppy</a> library?</p>
<p>I need the full JID for a subsequent <code>Iq</code> call to the server. Specifying the bare JID (user@domain.com) results... | 1 | 2010-03-06T15:37:21Z | 2,414,740 | <p>Use the non-underbar versions:</p>
<pre><code>c = xmpp.client.Client(...)
# connect
jid = xmpp.JID(node=c.User, domain=c.Server, resource=c.Resource)
</code></pre>
<p>However, there is no need to set a from address. The server will do this for you for all of the stanzas you send.</p>
| 2 | 2010-03-10T05:29:36Z | [
"python",
"xmpp",
"xmpppy"
] |
Setting up Linux to use a certain version of python for compile | 2,393,054 | <p>I'm running Ubuntu to compile a set of code which requires python 2.4.</p>
<p>How can I setup a terminal launcher so that when I open that launcher all python related commands will use python 2.4 instead of the python 2.6 that is defaulted in Ubuntu?</p>
| 2 | 2010-03-06T15:50:38Z | 2,393,098 | <p>Invoke the interpreter via <code>python2.4</code> instead of using the default.</p>
| 2 | 2010-03-06T16:02:42Z | [
"python",
"linux",
"development-environment",
"compilation"
] |
Setting up Linux to use a certain version of python for compile | 2,393,054 | <p>I'm running Ubuntu to compile a set of code which requires python 2.4.</p>
<p>How can I setup a terminal launcher so that when I open that launcher all python related commands will use python 2.4 instead of the python 2.6 that is defaulted in Ubuntu?</p>
| 2 | 2010-03-06T15:50:38Z | 2,393,229 | <p>Set a <code>bash</code> alias in that shell session: <code>alias python=python2.4</code> (assuming python2.4 is in your $PATH of course). This way you won't have to remember to explicitly type the <code>2.4</code> a zillion times in that terminal -- which is what bash aliases are for!-)</p>
| 4 | 2010-03-06T16:41:42Z | [
"python",
"linux",
"development-environment",
"compilation"
] |
Setting up Linux to use a certain version of python for compile | 2,393,054 | <p>I'm running Ubuntu to compile a set of code which requires python 2.4.</p>
<p>How can I setup a terminal launcher so that when I open that launcher all python related commands will use python 2.4 instead of the python 2.6 that is defaulted in Ubuntu?</p>
| 2 | 2010-03-06T15:50:38Z | 2,393,768 | <p>For a permenant system wide change put a symbolic link to the version you want in place of /usr/bin/python. ie</p>
<p><code>rm /usr/bin/python;
ln -s /usr/bin/python2.4 /usr/bin/python</code></p>
<p>gentoo has a program 'eselect' which is for just this kind of thing (listing versions of programs and setting the de... | 1 | 2010-03-06T19:10:18Z | [
"python",
"linux",
"development-environment",
"compilation"
] |
Setting up Linux to use a certain version of python for compile | 2,393,054 | <p>I'm running Ubuntu to compile a set of code which requires python 2.4.</p>
<p>How can I setup a terminal launcher so that when I open that launcher all python related commands will use python 2.4 instead of the python 2.6 that is defaulted in Ubuntu?</p>
| 2 | 2010-03-06T15:50:38Z | 10,455,166 | <p>Watch out for using the alias when wanting to use the python you want. If the python script uses $0 to figure out, how it was called, then uses that answer to execute another python script. The other script will be called with whatever version that matches the link name, not the version the link points to.</p>
| 0 | 2012-05-04T19:44:21Z | [
"python",
"linux",
"development-environment",
"compilation"
] |
Vim: sort classes in a python source file | 2,393,074 | <p>I have a <code>.py</code> file with lots of classes:</p>
<pre><code>class First(Second):
#code
class Third(Fourth):
#code
</code></pre>
<p>Is it possible to sort the definitions by class name in vim?</p>
| 1 | 2010-03-06T15:56:59Z | 2,393,155 | <p>Suggestion for manual sorting.</p>
<p>With a reasonable amount of classes, manual sorting is not so tedious. I also propose it since I think it makes much more sense to group superclasses together and make sure superclasses are defined before subclasses -- otherwise your module won't even be importable.</p>
<p>Ena... | 4 | 2010-03-06T16:19:30Z | [
"python",
"vim"
] |
Python: File formatting | 2,393,120 | <p>I have a for loop which references a dictionary and prints out the value associated with the key. Code is below:</p>
<pre><code>for i in data:
if i in dict:
print dict[i],
</code></pre>
<p>How would i format the output so a new line is created every 60 characters? and with the character count along the... | 0 | 2010-03-06T16:10:58Z | 2,393,139 | <p>It seems like you're looking for <a href="http://docs.python.org/library/textwrap.html" rel="nofollow"><code>textwrap</code></a></p>
<blockquote>
<p>The textwrap module provides two convenience functions, wrap() and
fill(), as well as TextWrapper, the class that does all the work, and
a utility function deden... | 0 | 2010-03-06T16:15:34Z | [
"python",
"file",
"formatting"
] |
Python: File formatting | 2,393,120 | <p>I have a for loop which references a dictionary and prints out the value associated with the key. Code is below:</p>
<pre><code>for i in data:
if i in dict:
print dict[i],
</code></pre>
<p>How would i format the output so a new line is created every 60 characters? and with the character count along the... | 0 | 2010-03-06T16:10:58Z | 2,393,172 | <pre><code># test data
data = range(10)
the_dict = dict((i, str(i)*200) for i in range( 10 ))
# your loops as a generator
lines = ( the_dict[i] for i in data if i in the_dict )
def format( line ):
def splitter():
k = 0
while True:
r = line[k:k+60] # take a 60 char block
if ... | 0 | 2010-03-06T16:28:28Z | [
"python",
"file",
"formatting"
] |
Python: File formatting | 2,393,120 | <p>I have a for loop which references a dictionary and prints out the value associated with the key. Code is below:</p>
<pre><code>for i in data:
if i in dict:
print dict[i],
</code></pre>
<p>How would i format the output so a new line is created every 60 characters? and with the character count along the... | 0 | 2010-03-06T16:10:58Z | 2,393,177 | <p>It's a finicky formatting problem, but I think the following code:</p>
<pre><code>import sys
class EveryN(object):
def __init__(self, n, outs):
self.n = n # chars/line
self.outs = outs # output stream
self.numo = 1 # next tag to write
self.tll = 0 # tot chars on this line
def w... | 1 | 2010-03-06T16:29:26Z | [
"python",
"file",
"formatting"
] |
Python: File formatting | 2,393,120 | <p>I have a for loop which references a dictionary and prints out the value associated with the key. Code is below:</p>
<pre><code>for i in data:
if i in dict:
print dict[i],
</code></pre>
<p>How would i format the output so a new line is created every 60 characters? and with the character count along the... | 0 | 2010-03-06T16:10:58Z | 2,394,059 | <p>I haven't tested it on actual data, but I believe the code below would do the job. It first builds up the whole string, then outputs it a 60-character line at a time. It uses the three-argument version of range() to count by 60.</p>
<pre><code>s = ''.join(dict[i] for i in data if i in dict)
for i in range(0, len(... | 0 | 2010-03-06T20:50:12Z | [
"python",
"file",
"formatting"
] |
How to extend the comments framework (django) by removing unnecesary fields? | 2,393,237 | <p>I've been reading on the django docs about the comments framework and how to customize it (http://docs.djangoproject.com/en/1.1/ref/contrib/comments/custom/)
In that page, it shows how to <em>add</em> new fields to a form. But what I want to do is to <strong>remove</strong> unnecesary fields, like URL, email (amongs... | 13 | 2010-03-06T16:43:00Z | 2,396,200 | <p>You can try <a href="http://docs.djangoproject.com/en/dev/ref/contrib/comments/#rendering-a-custom-comment-form" rel="nofollow">overriding the comment form with a custom template</a> that only shows the fields you want.</p>
| 2 | 2010-03-07T12:26:57Z | [
"python",
"django",
"django-comments"
] |
How to extend the comments framework (django) by removing unnecesary fields? | 2,393,237 | <p>I've been reading on the django docs about the comments framework and how to customize it (http://docs.djangoproject.com/en/1.1/ref/contrib/comments/custom/)
In that page, it shows how to <em>add</em> new fields to a form. But what I want to do is to <strong>remove</strong> unnecesary fields, like URL, email (amongs... | 13 | 2010-03-06T16:43:00Z | 3,421,386 | <p>I recently implemented the solution that Ofri mentioned, since I only wanted to accept a solitary "comment" field for a comment (like SO does, no "name", no "email" and no "url"). </p>
<p>To customize the default comment form and list display, I created a "comments" directory in my root "templates" directory and ov... | 12 | 2010-08-06T06:11:22Z | [
"python",
"django",
"django-comments"
] |
How to extend the comments framework (django) by removing unnecesary fields? | 2,393,237 | <p>I've been reading on the django docs about the comments framework and how to customize it (http://docs.djangoproject.com/en/1.1/ref/contrib/comments/custom/)
In that page, it shows how to <em>add</em> new fields to a form. But what I want to do is to <strong>remove</strong> unnecesary fields, like URL, email (amongs... | 13 | 2010-03-06T16:43:00Z | 6,890,337 | <p>A tidy summary of how to do this elegantly, through the actual comments framework subclassing approach, rather than hiding elements in a form/other untidy hacks, can be found <a href="http://stackoverflow.com/questions/1456267/django-comments-want-to-remove-user-url-not-expand-the-model-how-to/4766543#4766543">Djang... | 4 | 2011-07-31T15:24:11Z | [
"python",
"django",
"django-comments"
] |
How do you randomly generate x amount of values and store them? | 2,393,238 | <p>I found a suggestion on a Stack Overflow topic about problems beginners should do to learn a new language. A user posted a very nice list of problems from Beginner to advanced that should help you get to know a language. One of the problems is to create a phone book, with random phone numbers and random people on th... | -1 | 2010-03-06T16:43:44Z | 2,393,272 | <p>With Python, you can use the <a href="http://docs.python.org/library/random.html" rel="nofollow">random</a> module for generating random numbers. For storing phone numbers, names, contact etc, you can use a database, eg <a href="http://docs.python.org/library/sqlite3.html" rel="nofollow">SQLite</a></p>
| 0 | 2010-03-06T16:53:49Z | [
"python",
"ruby",
"random"
] |
How do you randomly generate x amount of values and store them? | 2,393,238 | <p>I found a suggestion on a Stack Overflow topic about problems beginners should do to learn a new language. A user posted a very nice list of problems from Beginner to advanced that should help you get to know a language. One of the problems is to create a phone book, with random phone numbers and random people on th... | -1 | 2010-03-06T16:43:44Z | 2,393,328 | <p>You need to define some more parameters before you can tackle this problem.</p>
<ul>
<li>Are phone numbers unique to each person?</li>
<li>How will you store names? First name and last name in different strings? All in one string?</li>
<li>Do you want to support fuzzy matching?</li>
<li>do you want to offer rever... | 1 | 2010-03-06T17:11:49Z | [
"python",
"ruby",
"random"
] |
How do I disable history in python mechanize module? | 2,393,299 | <p>I have a web scraping script that gets new data once every minute, but over the course of a couple of days, the script ends up using 200mb or more of memory, and I found out it's because mechanize is keeping an infinite browser history for the .back() function to use.</p>
<p>I have looked in the docstrings, and I f... | 10 | 2010-03-06T17:01:56Z | 2,393,395 | <p>You can pass an argument <code>history=whatever</code> when you instantiate the <code>Browser</code>; the default value is <code>None</code> which means the browser actually instantiates the <code>History</code> class (to allow <code>back</code> and <code>reload</code>). The simplest approach (will give an attribut... | 17 | 2010-03-06T17:29:05Z | [
"python",
"memory",
"mechanize"
] |
Python double iteration | 2,393,444 | <p>What is the pythonic way of iterating simultaneously over two lists?</p>
<p>Suppose I want to compare two files line by line (compare each <code>i</code>th line in one file with the <code>i</code>th line of the other file), I would want to do something like this:</p>
<pre><code>file1 = csv.reader(open(filename1),.... | 7 | 2010-03-06T17:42:28Z | 2,393,460 | <p>In lockstep (for Python â¥3):</p>
<pre><code>for line1, line2 in zip(file1, file2):
# etc.
</code></pre>
<p>As a "2D array":</p>
<pre><code>for line1 in file1:
for line2 in file2:
# etc.
# you may need to rewind file2 to the beginning.
</code></pre>
| 3 | 2010-03-06T17:44:49Z | [
"python"
] |
Python double iteration | 2,393,444 | <p>What is the pythonic way of iterating simultaneously over two lists?</p>
<p>Suppose I want to compare two files line by line (compare each <code>i</code>th line in one file with the <code>i</code>th line of the other file), I would want to do something like this:</p>
<pre><code>file1 = csv.reader(open(filename1),.... | 7 | 2010-03-06T17:42:28Z | 2,393,484 | <p>I vote for using <code>zip</code>. The <a href="http://docs.python.org/tutorial/datastructures.html#looping-techniques">manual</a> suggests "To loop over two or more sequences at the same time, the entries can be paired with the zip() function"</p>
<p>For example,</p>
<pre><code>list_one = ['nachos', 'sandwich', '... | 5 | 2010-03-06T17:50:57Z | [
"python"
] |
Python double iteration | 2,393,444 | <p>What is the pythonic way of iterating simultaneously over two lists?</p>
<p>Suppose I want to compare two files line by line (compare each <code>i</code>th line in one file with the <code>i</code>th line of the other file), I would want to do something like this:</p>
<pre><code>file1 = csv.reader(open(filename1),.... | 7 | 2010-03-06T17:42:28Z | 2,393,492 | <p>In Python 2, you should import <a href="http://docs.python.org/library/itertools.html?highlight=itertools#module-itertools">itertools</a> and use its <a href="http://docs.python.org/library/itertools.html?highlight=itertools#itertools.izip">izip</a>:</p>
<pre><code>with open(file1) as f1:
with open(file2) as f2:
... | 11 | 2010-03-06T17:53:38Z | [
"python"
] |
Python GUI framework for Mac OS X | 2,393,514 | <p>I'm trying to find a good "python GUI framework" for Mac OS X, but I haven't found anything good until now, only wxWidgets which I don't like and it's also unstable.</p>
<p>Any suggestions?</p>
| 5 | 2010-03-06T18:04:14Z | 2,393,530 | <p>I use <a href="http://www.riverbankcomputing.co.uk/software/pyqt/intro">pyqt</a> (<a href="http://www.pyside.org/">pyside</a> should be equivalent but with more relaxed license terms) and I find it pleasing and useful -- I also like the fact that (with no extra effort on my part) it gives me cross-platform apps!-)</... | 5 | 2010-03-06T18:08:16Z | [
"python",
"osx",
"user-interface"
] |
Python GUI framework for Mac OS X | 2,393,514 | <p>I'm trying to find a good "python GUI framework" for Mac OS X, but I haven't found anything good until now, only wxWidgets which I don't like and it's also unstable.</p>
<p>Any suggestions?</p>
| 5 | 2010-03-06T18:04:14Z | 2,393,536 | <p>For the most MacOSX you could use <a href="http://pyobjc.sourceforge.net/" rel="nofollow">PyObjc</a> which basically allows you to write Cocoa apps i python using Interface Builder etc.</p>
| 2 | 2010-03-06T18:09:28Z | [
"python",
"osx",
"user-interface"
] |
Python code to parse and inspect c++ | 2,393,527 | <p>Is there a library for Python that will allow me to parse c++ code?</p>
<p>For example, let's say I want to parse some c++ code and find the names of all classes and their member functions/variables. </p>
<p>I can think of a few ways to hack it together using regular expressions, but if there is an existing librar... | 4 | 2010-03-06T18:07:50Z | 2,393,568 | <p>How about <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a>?</p>
| 0 | 2010-03-06T18:16:00Z | [
"c++",
"python"
] |
Python code to parse and inspect c++ | 2,393,527 | <p>Is there a library for Python that will allow me to parse c++ code?</p>
<p>For example, let's say I want to parse some c++ code and find the names of all classes and their member functions/variables. </p>
<p>I can think of a few ways to hack it together using regular expressions, but if there is an existing librar... | 4 | 2010-03-06T18:07:50Z | 2,393,572 | <p>Parsing C++ accurately is light-years from something you can do with a regular expression.
You need a full C++ parser, and they're pretty hard to build. I've been involved in building one over several years, and track who is doing it; I don't know of any being attempted <em>in</em> Python. </p>
<p>The one I work o... | 4 | 2010-03-06T18:16:13Z | [
"c++",
"python"
] |
Python code to parse and inspect c++ | 2,393,527 | <p>Is there a library for Python that will allow me to parse c++ code?</p>
<p>For example, let's say I want to parse some c++ code and find the names of all classes and their member functions/variables. </p>
<p>I can think of a few ways to hack it together using regular expressions, but if there is an existing librar... | 4 | 2010-03-06T18:07:50Z | 2,393,575 | <p>In the past I've used for such purposes <a href="http://www.gccxml.org/HTML/Index.html">gccxml</a> (a C++ parser that emits easily-parseable XML) -- I hacked up my own Python interfaces to it, but now there's a <a href="http://pypi.python.org/pypi/pygccxml/0.6.9">pygccxml</a> which should package that up nicely for ... | 7 | 2010-03-06T18:16:40Z | [
"c++",
"python"
] |
Python code to parse and inspect c++ | 2,393,527 | <p>Is there a library for Python that will allow me to parse c++ code?</p>
<p>For example, let's say I want to parse some c++ code and find the names of all classes and their member functions/variables. </p>
<p>I can think of a few ways to hack it together using regular expressions, but if there is an existing librar... | 4 | 2010-03-06T18:07:50Z | 2,393,699 | <p>This is a little outside your question's scope perhaps... but depending on what you're trying to achieve, perhaps <a href="http://ctags.sourceforge.net/" rel="nofollow">Exuberant Ctags</a> is worth looking at.</p>
| 1 | 2010-03-06T18:47:52Z | [
"c++",
"python"
] |
Python code to parse and inspect c++ | 2,393,527 | <p>Is there a library for Python that will allow me to parse c++ code?</p>
<p>For example, let's say I want to parse some c++ code and find the names of all classes and their member functions/variables. </p>
<p>I can think of a few ways to hack it together using regular expressions, but if there is an existing librar... | 4 | 2010-03-06T18:07:50Z | 8,651,886 | <p>Have not tried, but using the Python bindings from LLVM's Clang parser may work; see <a href="http://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/" rel="nofollow">here</a>.</p>
| 1 | 2011-12-28T04:34:52Z | [
"c++",
"python"
] |
Python: Classname same as file/module name leads to inheritance issue? | 2,393,544 | <p>My code worked fine when it was all in one file. Now, I'm splitting up classes into different modules. The modules have been given the same name as the classes. Perhaps this is a problem, because <code>MainPage</code> is failing when it is loaded. Does it think that I'm trying to inherit from a module? Can module/cl... | 8 | 2010-03-06T18:10:48Z | 2,393,571 | <p>Yes, module names share the same namespace as everything else, and, yes, Python thinks you are trying to inherit from a module.</p>
<p>Change:</p>
<pre><code>class MainPage(BaseHandler):
</code></pre>
<p>to:</p>
<pre><code>class MainPage(BaseHandler.BaseHandler):
</code></pre>
<p>and you should be good to go. ... | 16 | 2010-03-06T18:16:04Z | [
"python",
"google-app-engine",
"class",
"import",
"module"
] |
Python: Classname same as file/module name leads to inheritance issue? | 2,393,544 | <p>My code worked fine when it was all in one file. Now, I'm splitting up classes into different modules. The modules have been given the same name as the classes. Perhaps this is a problem, because <code>MainPage</code> is failing when it is loaded. Does it think that I'm trying to inherit from a module? Can module/cl... | 8 | 2010-03-06T18:10:48Z | 2,393,574 | <p>First of all the filenames should be all lowercase. That's Python convention that helps to avoid confusion such as this, at least most of the time. </p>
<p>Next, your import from withing <code>MainHandler.py</code> is wrong. You are importing <code>BaseHandler</code> (the module) and referencing it as if it were ... | 14 | 2010-03-06T18:16:31Z | [
"python",
"google-app-engine",
"class",
"import",
"module"
] |
Python: Random sequence | 2,393,851 | <p>I have the following code:</p>
<pre><code>import string
import random
d =[random.choice(string.uppercase) for x in xrange(3355)]
s = "".join(d)
print s
</code></pre>
<p>At the moment it prints out a random sequence of letters from the alphabet. But, i need it to print out a sequence of letters containing only fo... | 1 | 2010-03-06T19:40:31Z | 2,393,856 | <p>just replace <code>string.uppercase</code> with the sequence (list or string, for example) containing your choices.</p>
| 1 | 2010-03-06T19:42:10Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.