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
Python: Which modules for a discussion site?
1,297,350
<p>A site should be ready in 6 days. I am not allowed to use any framework such as Django. I am going to use:</p> <p><strong>Python modules</strong></p> <ol> <li>HTMLGen to generate HTML code from class-based description</li> <li>SQLObject, relational tables onto Python's class model</li> <li>?</li> </ol> <p><strong...
1
2009-08-19T01:00:44Z
1,297,409
<p>How about Jinja for templating? It will be much faster than working with autogenerated html. <a href="http://pypi.python.org/pypi/Jinja2/2.0" rel="nofollow">http://pypi.python.org/pypi/Jinja2/2.0</a></p>
3
2009-08-19T01:30:11Z
[ "python", "postgresql", "module", "website" ]
Python: Which modules for a discussion site?
1,297,350
<p>A site should be ready in 6 days. I am not allowed to use any framework such as Django. I am going to use:</p> <p><strong>Python modules</strong></p> <ol> <li>HTMLGen to generate HTML code from class-based description</li> <li>SQLObject, relational tables onto Python's class model</li> <li>?</li> </ol> <p><strong...
1
2009-08-19T01:00:44Z
1,297,960
<p>I think <a href="http://turbogears.org/" rel="nofollow">TurboGears</a> started out as a project to collect best-of-breed packages together with some glue code to stitch them together. I think the latest incarnation uses Pylons, but perhaps only for the controller. At the very least, you can see the <a href="http:/...
1
2009-08-19T05:39:34Z
[ "python", "postgresql", "module", "website" ]
Django RSS Feed Problems
1,297,426
<p>I'm working on a blogging application, and trying to made just a simple RSS feed system function. However, I'm running into an odd bug that doesn't make a lot of sense to me. I understand what's likely going on, but I don't understand why. My RSS Feed class is below:</p> <pre><code>class RSSFeed(Feed): title = ...
3
2009-08-19T01:40:49Z
1,297,451
<p>Changing to:</p> <pre><code>class RSSFeed(Feed): title = settings.BLOG_NAME link = "/blog/" description = "Recent Posts" def items(self): return Story.objects.all().order_by('-created')[:10] </code></pre> <p>Fixed it. Not sure I totally understand it.. but whatev. :)</p>
4
2009-08-19T01:51:59Z
[ "python", "django", "django-rss" ]
Django RSS Feed Problems
1,297,426
<p>I'm working on a blogging application, and trying to made just a simple RSS feed system function. However, I'm running into an odd bug that doesn't make a lot of sense to me. I understand what's likely going on, but I don't understand why. My RSS Feed class is below:</p> <pre><code>class RSSFeed(Feed): title = ...
3
2009-08-19T01:40:49Z
1,303,273
<p>have you defined</p> <pre><code>def get_absolute_url(self): </code></pre> <p>in the model?</p> <p>also, it's nice to </p> <pre><code>if not obj: raise FeedDoesNotExist </code></pre> <p>to avoid errors when feed result is not present</p>
1
2009-08-20T00:02:14Z
[ "python", "django", "django-rss" ]
Read WordPerfect files with Python?
1,297,466
<p>I really need to work with information contained in <a href="https://en.wikipedia.org/wiki/WordPerfect#Summary" rel="nofollow">WordPerfect&nbsp;12</a> files without using WordPerfect's sluggish visual interface, but I can't find any detailed documentation about the file format or any Python modules for reading/writi...
1
2009-08-19T02:00:11Z
1,297,581
<p>OpenOffice.org should read WordPerfect files, I think.</p> <p>And you can <a href="http://udk.openoffice.org/python/scriptingframework/index.html" rel="nofollow">script OpenOffice with Python</a>.</p>
2
2009-08-19T02:39:00Z
[ "python", "wordperfect" ]
Read WordPerfect files with Python?
1,297,466
<p>I really need to work with information contained in <a href="https://en.wikipedia.org/wiki/WordPerfect#Summary" rel="nofollow">WordPerfect&nbsp;12</a> files without using WordPerfect's sluggish visual interface, but I can't find any detailed documentation about the file format or any Python modules for reading/writi...
1
2009-08-19T02:00:11Z
1,297,599
<p>The relevant part of your link is this:</p> <pre><code>os.system( "%s %s %s" % ( WPD_TO_TEXT_CMD, "/tmp/tmpfile", "/tmp/tmpfile.txt" ) ) </code></pre> <p>Which is making a system call to an outside program called "wp2txt". Googling for that program produces active hits.</p>
3
2009-08-19T02:44:23Z
[ "python", "wordperfect" ]
Read WordPerfect files with Python?
1,297,466
<p>I really need to work with information contained in <a href="https://en.wikipedia.org/wiki/WordPerfect#Summary" rel="nofollow">WordPerfect&nbsp;12</a> files without using WordPerfect's sluggish visual interface, but I can't find any detailed documentation about the file format or any Python modules for reading/writi...
1
2009-08-19T02:00:11Z
1,415,786
<p>OK, here's what I did. I read the file in binary mode, converted by the data into a string representation of the hex values, and used unofficial WordPerfect documentation to create regular expressions to swap out all the hex strings representing non-text formatting codes and meta data, then converted everything back...
1
2009-09-12T18:28:05Z
[ "python", "wordperfect" ]
Python sendto() not working on 3.1 (works on 2.6)
1,297,505
<p>For some reason, the following seems to work perfectly on my ubuntu machine running python 2.6 and returns an error on my windows xp box running python 3.1</p> <pre><code>from socket import socket, AF_INET, SOCK_DGRAM data = 'UDP Test Data' port = 12345 hostname = '192.168.0.1' udp = socket(AF_INET,SOCK_DGRAM) udp....
4
2009-08-19T02:14:45Z
1,297,536
<p>Related issue on the Python bugtracker: <a href="http://bugs.python.org/issue5421" rel="nofollow">http://bugs.python.org/issue5421</a></p>
4
2009-08-19T02:26:57Z
[ "python", "windows", "ubuntu", "udp", "sendto" ]
Python sendto() not working on 3.1 (works on 2.6)
1,297,505
<p>For some reason, the following seems to work perfectly on my ubuntu machine running python 2.6 and returns an error on my windows xp box running python 3.1</p> <pre><code>from socket import socket, AF_INET, SOCK_DGRAM data = 'UDP Test Data' port = 12345 hostname = '192.168.0.1' udp = socket(AF_INET,SOCK_DGRAM) udp....
4
2009-08-19T02:14:45Z
1,297,541
<p>In Python 3, the string (first) argument must be of type bytes or buffer, not str. You'll get that error message if you supply the optional flags parameter. Change data to:</p> <p>d<code>ata = b'UDP Test Data'</code></p> <p>You might want to file a bug report about that at the python.org bug tracker. [EDIT: alr...
6
2009-08-19T02:27:37Z
[ "python", "windows", "ubuntu", "udp", "sendto" ]
Writing a tail -f python script that doesn't utilize 100% CPU
1,297,563
<p>Here's a simple implementation of tail -f written in python. The problem with this is with the looping nature, this script likes to hog a lot of the CPU time. If it's something one would like to run as a forked process/daemon, it would be an inefficient start.</p> <p>What's a solution to have a CPU efficient tail -...
2
2009-08-19T02:33:32Z
1,297,591
<p>I don't know of an implementation that's going to be extremely efficient AND portable between Windows on one side, and just about every other system on the other. Just about everywhere, I'd use the <code>select</code> module of the standard library (which can be based on system level functionality such as select, kq...
0
2009-08-19T02:41:07Z
[ "python", "algorithm" ]
Python class method - Is there a way to make the calls shorter?
1,297,583
<p>I am playing around with Python, and I've created a class in a different package from the one calling it. In this class, I've added a class method which is being called from my main function. Again, they are in separate packages. The line to call the class method is much longer than I thought it would be from the...
4
2009-08-19T02:39:34Z
1,297,590
<pre><code>from config.TestClass import TestClass TestClass.add_key( "mykey", "newvalue" ) </code></pre>
13
2009-08-19T02:40:27Z
[ "python", "class-method" ]
Why there is a difference in "import" vs. "import *"?
1,297,766
<pre><code>"""module a.py""" test = "I am test" _test = "I am _test" __test = "I am __test" </code></pre> <p>=============</p> <pre><code>~ $ python Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin Type "help", "copyright", "credits" or "license" for more infor...
6
2009-08-19T04:08:36Z
1,297,784
<p>Variables with a leading "_" (underbar) are not <em>public names</em> and will not be imported when <code>from x import *</code> is used.</p> <p>Here, <code>_test</code> and <code>__test</code> are not <em>public</em> names.</p> <p>From the <a href="http://docs.python.org/reference/simple_stmts.html#the-import-sta...
21
2009-08-19T04:18:00Z
[ "python", "import" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
1,297,901
<p>Then what you need is not Django. What you need is exactly what <a href="http://code.google.com/p/micropy/" rel="nofollow">micropy</a> does.</p>
3
2009-08-19T05:09:31Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
1,297,911
<p>This is a simple CMS implemented in Django, as a single file. It was written by <a href="http://news.e-scribe.com/395">Paul Bissex</a>. Some of it has been "golfed" and could do with a bit of expansion, but it's still relatively easy to read.</p> <p>The source has vanished from his pastebin, but I saved it:</p> <p...
8
2009-08-19T05:14:57Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
1,297,931
<p>You might want to consider Simon Willison's library:</p> <ul> <li><a href="http://blog.simonwillison.net/post/57956850422/djng" rel="nofollow">djng—a Django powered microframework</a></li> </ul> <p>From the <a href="http://github.com/simonw/djng/tree/master" rel="nofollow">readme</a>:</p> <blockquote> <p>djng...
11
2009-08-19T05:27:30Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
1,298,303
<p>You also may want to take a look at <a href="http://webpy.org/" rel="nofollow">web.py</a>. (<a href="http://webpy.org/tutorial3.en" rel="nofollow">Tutorial</a>)</p> <p>It's another compact, but powerful web framework.</p> <p>Sample from the main page:</p> <pre><code>import web urls = ('/(.*)', 'hello') app = web...
1
2009-08-19T07:27:16Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
1,298,381
<p>Well, the easiest way to do that is to mimic the django project arbo in one file. So in one module, assure there is :</p> <pre><code>Root_module : Root_module.settings Root_module.urls Root_module.app_in_the_module Root_module.app_in_the_module.models Root_module.app_in_the_module.views </code><...
1
2009-08-19T07:50:39Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
2,709,778
<p>Getting started with Django can be pretty easy too. Here's a 10-line single-file Django webapp:</p> <pre><code>import os from django.conf.urls.defaults import patterns from django.http import HttpResponse filepath, extension = os.path.splitext(__file__) ROOT_URLCONF = os.path.basename(filepath) def yoohoo(request)...
9
2010-04-25T20:11:01Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
9,896,862
<p>Most of the single file django examples found over the web lack support for model since django somehow require models to be declared in models.py file in each <code>INSTALLED_APP</code>. Finally I found an example that include support for model:-</p> <p><a href="http://fahhem.com/blog/2011/10/django-models-without-...
2
2012-03-27T20:07:24Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
28,638,323
<p><a href="http://stackoverflow.com/a/1297911/4794">John's answer</a> quoting the <a href="http://news.e-scribe.com/395" rel="nofollow">jngo app</a> by Paul Bissex is impressive, but it's sadly broken under Django 1.7.</p> <p>I did a bunch of digging and <a href="https://github.com/donkirkby/udjango" rel="nofollow">c...
0
2015-02-20T21:14:20Z
[ "python", "django", "web-applications" ]
How do I write a single-file Django application?
1,297,873
<p>I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:</p> <pre><code>$ python myapp.py </code></pre> <p>You can assume I won't render HTML, so I don't need templates (I'll return <a href=...
11
2009-08-19T04:58:30Z
28,651,818
<p>Tested with Django 1.7</p> <pre><code>#!/usr/bin/env python import os import sys from django.conf import settings from django.conf.urls import patterns, include, url from django.http import HttpResponse filename = os.path.splitext(os.path.basename(__file__))[0] urlpatterns = patterns('', url(r'^$', '%s.home' ...
2
2015-02-21T21:55:11Z
[ "python", "django", "web-applications" ]
How useful would be a Smalltalk source code browser for other programming languages?
1,298,020
<p>I'm working on an IDE for python, ruby and php.</p> <p>Never having used Smallltalk myself (even it was very popular when I was at university) I wonder if the classic Smalltalk Browser which displays only one method is really an improvment or to classical file editing or not. </p> <p>I myself like to have the over...
4
2009-08-19T06:01:43Z
1,298,176
<p>It's a little bit of a simplification to say the class browser only shows one method. It actually shows a lot of methods in a much more organized way than raw source code usually does. Consider in which of these you think you'd have an easier time finding what you wanted:</p> <pre><code>class Thing def foo bl...
1
2009-08-19T06:49:11Z
[ "php", "python", "ruby", "ide", "smalltalk" ]
How useful would be a Smalltalk source code browser for other programming languages?
1,298,020
<p>I'm working on an IDE for python, ruby and php.</p> <p>Never having used Smallltalk myself (even it was very popular when I was at university) I wonder if the classic Smalltalk Browser which displays only one method is really an improvment or to classical file editing or not. </p> <p>I myself like to have the over...
4
2009-08-19T06:01:43Z
1,298,447
<p>I have a love/hate relationship with the Smalltalk browsers (Squeak in my case). At times I think they are the best things since sliced bread, and at others they make me grind my teeth. The problem with Smalltalk is that the browsers are basically all you have. You can of course write your own, but very few people g...
0
2009-08-19T08:12:01Z
[ "php", "python", "ruby", "ide", "smalltalk" ]
How useful would be a Smalltalk source code browser for other programming languages?
1,298,020
<p>I'm working on an IDE for python, ruby and php.</p> <p>Never having used Smallltalk myself (even it was very popular when I was at university) I wonder if the classic Smalltalk Browser which displays only one method is really an improvment or to classical file editing or not. </p> <p>I myself like to have the over...
4
2009-08-19T06:01:43Z
1,299,109
<p>The Smalltalk browser has two parts: the top one shows the packages, classes, protocols and methods/messages, the bottom one shows the content of one method. This is very usefull if you design/code your program thinking more on signatures and names, rather than as a web of lines of codes.</p> <p>If you concentrate ...
5
2009-08-19T10:50:19Z
[ "php", "python", "ruby", "ide", "smalltalk" ]
How useful would be a Smalltalk source code browser for other programming languages?
1,298,020
<p>I'm working on an IDE for python, ruby and php.</p> <p>Never having used Smallltalk myself (even it was very popular when I was at university) I wonder if the classic Smalltalk Browser which displays only one method is really an improvment or to classical file editing or not. </p> <p>I myself like to have the over...
4
2009-08-19T06:01:43Z
1,302,807
<p>VisualAge for Java used the Smalltalk Browser model for coding, and I thought they (IBM) did a great job of taking a typical file based language and lifting it up to a higher conceptual mode. Instantiations even had a great add-on to bring good refactoring tools to VAJ (people either don't know or forget for which ...
2
2009-08-19T21:47:58Z
[ "php", "python", "ruby", "ide", "smalltalk" ]
How useful would be a Smalltalk source code browser for other programming languages?
1,298,020
<p>I'm working on an IDE for python, ruby and php.</p> <p>Never having used Smallltalk myself (even it was very popular when I was at university) I wonder if the classic Smalltalk Browser which displays only one method is really an improvment or to classical file editing or not. </p> <p>I myself like to have the over...
4
2009-08-19T06:01:43Z
1,334,764
<p>Eclipse offers a Smalltalk like browser, the Java browsing perspective. Even though being a Smalltalker myself, I almost never use it. Why? The powerful part if the Smalltalk IDE is the debugger not the browser. When coding Smalltalk, I do everything test-first and then fix all missing methods in the debugger <em>wh...
3
2009-08-26T13:40:15Z
[ "php", "python", "ruby", "ide", "smalltalk" ]
How useful would be a Smalltalk source code browser for other programming languages?
1,298,020
<p>I'm working on an IDE for python, ruby and php.</p> <p>Never having used Smallltalk myself (even it was very popular when I was at university) I wonder if the classic Smalltalk Browser which displays only one method is really an improvment or to classical file editing or not. </p> <p>I myself like to have the over...
4
2009-08-19T06:01:43Z
22,278,806
<p>OK so this is ancient-but I simply can't believe no one thought of <em>opening several browsers.</em> I don't think I've ever seen anyone programming in a Smalltalk system with just the one. Class browsers, hierarchy browsers, protocol browsers... Yes, each one shows a single methods source at any one time but just ...
2
2014-03-09T05:31:02Z
[ "php", "python", "ruby", "ide", "smalltalk" ]
--home or --prefix in python package install?
1,298,036
<p>When you build and install a python package, you have two choices: --home and --prefix. I never really got the difference between the two (I always use --home) but if I understood correctly one is deprecated and the other is "the way to go"™.</p> <p>Am I wrong ?</p>
4
2009-08-19T06:06:25Z
1,299,203
<p>According to the <a href="http://docs.python.org/install/index.html#alternate-installation" rel="nofollow">Installing Python Modules</a> documentation, the "standard" way is to specify neither, and to let Python install it in either <code>/usr/local/lib/pythonX.Y/site-packages</code> on *nix or <code>C:\Python\</cod...
3
2009-08-19T11:07:14Z
[ "python", "installation" ]
Is there an easy way to use a python tempfile in a shelve (and make sure it cleans itself up)?
1,298,037
<p>Basically, I want an infinite size (more accurately, hard-drive rather than memory bound) dict in a python program I'm writing. It seems like the tempfile and shelve modules are naturally suited for this, however, I can't see how to use them together in a safe manner. I want the tempfile to be deleted when the shelv...
1
2009-08-19T06:07:17Z
1,298,162
<p>I would rather inherit from shelve.Shelf, and override the close method (*) to unlink the files. Notice that, depending on the specific dbm module being used, you may have more than one file that contains the shelf. One solution could be to create a temporary directory, rather than a temporary file, and remove anyth...
1
2009-08-19T06:46:26Z
[ "python", "shelve", "temporary-files" ]
Unescape/unquote binary strings in (extended) url encoding in python
1,298,319
<p>for analysis I'd have to unescape URL-encoded binary strings (non-printable characters most likely). The strings sadly come in the extended URL-encoding form, e.g. "%u616f". I want to store them in a file that then contains the raw binary values, eg. 0x61 0x6f here. </p> <p>How do I get this into binary data in pyt...
0
2009-08-19T07:33:14Z
1,298,400
<p>I guess you will have to write the decoder function by yourself. Here is an implementation to get you started:</p> <pre><code>def decode(file): while True: c = file.read(1) if c == "": # End of file break if c != "%": # Not an escape sequence ...
1
2009-08-19T07:57:10Z
[ "python", "binary", "urlencode" ]
Unescape/unquote binary strings in (extended) url encoding in python
1,298,319
<p>for analysis I'd have to unescape URL-encoded binary strings (non-printable characters most likely). The strings sadly come in the extended URL-encoding form, e.g. "%u616f". I want to store them in a file that then contains the raw binary values, eg. 0x61 0x6f here. </p> <p>How do I get this into binary data in pyt...
0
2009-08-19T07:33:14Z
1,298,424
<p>Here is a regex-based approach:</p> <pre><code># the replace function concatenates the two matches after # converting them from hex to ascii repfunc = lambda m: chr(int(m.group(1), 16))+chr(int(m.group(2), 16)) # the last parameter is the text you want to convert result = re.sub('%u(..)(..)', repfunc, '%u616f') p...
0
2009-08-19T08:06:15Z
[ "python", "binary", "urlencode" ]
Unescape/unquote binary strings in (extended) url encoding in python
1,298,319
<p>for analysis I'd have to unescape URL-encoded binary strings (non-printable characters most likely). The strings sadly come in the extended URL-encoding form, e.g. "%u616f". I want to store them in a file that then contains the raw binary values, eg. 0x61 0x6f here. </p> <p>How do I get this into binary data in pyt...
0
2009-08-19T07:33:14Z
1,301,097
<blockquote> <p>The strings sadly come in the extended URL-encoding form, e.g. "%u616f"</p> </blockquote> <p>Incidentally that's not anything to do with URL-encoding. It's an arbitrary made-up format produced by the JavaScript escape() function and pretty much nothing else. If you can, the best thing to do would be ...
3
2009-08-19T16:28:12Z
[ "python", "binary", "urlencode" ]
How to set initial size for a dictionary in Python?
1,298,636
<p>I'm putting around 4 million different keys into a Python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB of memory on my machine. After the dictionary is fully created, querying the dictionary is fast.</p> <p>I suspect that dictionary creation is so resource consuming as the dict...
12
2009-08-19T09:06:30Z
1,298,685
<p>You can try to separate key hashing from the content filling with <a href="http://docs.python.org/library/stdtypes.html#dict.fromkeys" rel="nofollow"><code>dict.fromkeys</code></a> classmethod. It'll create a <code>dict</code> of a known size with all values defaulting to either <code>None</code> or a value of your ...
3
2009-08-19T09:14:37Z
[ "python", "performance", "dictionary" ]
How to set initial size for a dictionary in Python?
1,298,636
<p>I'm putting around 4 million different keys into a Python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB of memory on my machine. After the dictionary is fully created, querying the dictionary is fast.</p> <p>I suspect that dictionary creation is so resource consuming as the dict...
12
2009-08-19T09:06:30Z
1,298,705
<p>If your datas need/can be stored on disc perhaps you can store your datas in a <a href="http://docs.python.org/library/bsddb.html" rel="nofollow">BSDDB database</a> or use <a href="http://docs.python.org/library/pickle.html#module-cPickle" rel="nofollow">Cpickle</a> to load/store your dictionnary</p>
2
2009-08-19T09:17:32Z
[ "python", "performance", "dictionary" ]
How to set initial size for a dictionary in Python?
1,298,636
<p>I'm putting around 4 million different keys into a Python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB of memory on my machine. After the dictionary is fully created, querying the dictionary is fast.</p> <p>I suspect that dictionary creation is so resource consuming as the dict...
12
2009-08-19T09:06:30Z
1,298,734
<p>If you know C, you can take a look at <a href="http://svn.python.org/view/python/trunk/Objects/dictobject.c?revision=74197&amp;view=markup">dictobject.c</a> and <a href="http://svn.python.org/view/python/trunk/Objects/dictnotes.txt?revision=53782&amp;view=markup">the Notes on Optimizing Dictionaries</a>. There you'l...
5
2009-08-19T09:22:38Z
[ "python", "performance", "dictionary" ]
How to set initial size for a dictionary in Python?
1,298,636
<p>I'm putting around 4 million different keys into a Python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB of memory on my machine. After the dictionary is fully created, querying the dictionary is fast.</p> <p>I suspect that dictionary creation is so resource consuming as the dict...
12
2009-08-19T09:06:30Z
1,298,739
<p>I tried :</p> <pre><code>a = dict.fromkeys((range(4000000))) </code></pre> <p>It creates a dictionary with 4 000 000 entries in about 3 seconds. After that, setting values are really fast. So I guess dict.fromkey is definitly the way to go.</p>
7
2009-08-19T09:24:25Z
[ "python", "performance", "dictionary" ]
How to set initial size for a dictionary in Python?
1,298,636
<p>I'm putting around 4 million different keys into a Python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB of memory on my machine. After the dictionary is fully created, querying the dictionary is fast.</p> <p>I suspect that dictionary creation is so resource consuming as the dict...
12
2009-08-19T09:06:30Z
1,298,905
<p>With performance issues it's always best to measure. Here are some timings:</p> <pre><code> d = {} for i in xrange(4000000): d[i] = None # 722ms d = dict(itertools.izip(xrange(4000000), itertools.repeat(None))) # 634ms dict.fromkeys(xrange(4000000)) # 558ms s = set(xrange(4000000)) dict.fromkeys(s) ...
21
2009-08-19T10:05:42Z
[ "python", "performance", "dictionary" ]
How to set initial size for a dictionary in Python?
1,298,636
<p>I'm putting around 4 million different keys into a Python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB of memory on my machine. After the dictionary is fully created, querying the dictionary is fast.</p> <p>I suspect that dictionary creation is so resource consuming as the dict...
12
2009-08-19T09:06:30Z
1,302,843
<p>Do you initialize all keys with new "empty" instances of the same type? Is it not possible to write a defaultdict or something that will create the object when it is accessed?</p>
1
2009-08-19T21:56:33Z
[ "python", "performance", "dictionary" ]
How can I call the svn.client.svn_client_list2 with python SVN API SWIG bindings?
1,298,869
<h1>The question</h1> <p>How do I call <a href="http://svn.collab.net/svn-doxygen/group__List.html#ga1" rel="nofollow"><code>svn_client_list2</code></a> C API function from python via SVN API SWIG bindings?</p> <h1>Problem description</h1> <p>I can find that function from the <code>svn.client</code> module, but <str...
0
2009-08-19T09:56:02Z
1,375,441
<p>It looks like you can't really do this at the moment. When I dug into bit into the SWIG bindings code and documentation it says that when you're using target language functions as the callback function, you need a typemap for it as it says in the <a href="http://www.swig.org/Doc1.3/SWIG.html#SWIG_nn30" rel="nofollo...
0
2009-09-03T19:29:19Z
[ "python" ]
Django - MySQLdb: Symbol not found: _mysql_affected_rows
1,299,013
<p>A colleague got this error message when trying to use MySQLdb from Django:</p> <pre><code>[...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/...
7
2009-08-19T10:31:47Z
1,299,266
<p>Yes, the MySQLDb egg was compiled against a different version of libmysqlclient than the version present in the system. You need to either get a proper egg (uninstalling the previous) or to build MySQLDb from scratch to compile it against the library present in your system.</p> <p>I don't know why but I think your ...
0
2009-08-19T11:18:35Z
[ "python", "mysql", "django" ]
Django - MySQLdb: Symbol not found: _mysql_affected_rows
1,299,013
<p>A colleague got this error message when trying to use MySQLdb from Django:</p> <pre><code>[...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/...
7
2009-08-19T10:31:47Z
1,303,895
<p>It might be best if you install mysql and it's Python bindings from scratch, I use the following steps whenever I need MySQLdb on OS X 10.4 or 10.5:</p> <ol> <li><p>Install <a href="http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg" rel="nofollow">MySQL</a> for your system, the dmg installer should be suffic...
6
2009-08-20T04:06:41Z
[ "python", "mysql", "django" ]
Django - MySQLdb: Symbol not found: _mysql_affected_rows
1,299,013
<p>A colleague got this error message when trying to use MySQLdb from Django:</p> <pre><code>[...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/...
7
2009-08-19T10:31:47Z
4,293,013
<p>I had trouble with Thierry's solution on 32-bit Python (2.6.5) on OS X 10.6.</p> <p>Upgrading to Python 2.7 64-bit version fixed the problem for me.</p>
0
2010-11-27T17:44:14Z
[ "python", "mysql", "django" ]
Django - MySQLdb: Symbol not found: _mysql_affected_rows
1,299,013
<p>A colleague got this error message when trying to use MySQLdb from Django:</p> <pre><code>[...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/...
7
2009-08-19T10:31:47Z
4,537,783
<p>Thiery's instructions worked just fine for me with the MySQL 10.6 dmg and MySQLdb ver 1.2.3</p> <p>It helps to start with a clean slate, so make sure you uninstall early versions of MySQL. Look at this post for uninstallation help <a href="http://stackoverflow.com/questions/1436425/how-do-you-uninstall-mysql-from-m...
0
2010-12-27T09:41:06Z
[ "python", "mysql", "django" ]
Django - MySQLdb: Symbol not found: _mysql_affected_rows
1,299,013
<p>A colleague got this error message when trying to use MySQLdb from Django:</p> <pre><code>[...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/...
7
2009-08-19T10:31:47Z
10,572,999
<p>It was Complicated and hard but it worked on <strong>MacOSX Lion</strong>.</p> <p>you will be using :</p> <pre><code>Xcode Brew Port Pip </code></pre> <p>make sure that you have Xcode(4.X) installed , and your mac is configured to find the executables because it will be used by <strong>Macports</strong> during th...
1
2012-05-13T15:38:51Z
[ "python", "mysql", "django" ]
Django - MySQLdb: Symbol not found: _mysql_affected_rows
1,299,013
<p>A colleague got this error message when trying to use MySQLdb from Django:</p> <pre><code>[...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/...
7
2009-08-19T10:31:47Z
12,278,125
<pre><code>sudo apt-get install python-mysqldb </code></pre> <p>make sure it should installed properly</p> <p>or you can use another alternative like <code>easy_install</code> </p>
-1
2012-09-05T09:15:46Z
[ "python", "mysql", "django" ]
Django - MySQLdb: Symbol not found: _mysql_affected_rows
1,299,013
<p>A colleague got this error message when trying to use MySQLdb from Django:</p> <pre><code>[...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/...
7
2009-08-19T10:31:47Z
17,581,431
<p>Try to run:</p> <pre><code>easy_install -U distribute pip install --upgrade mysql-python </code></pre> <p>Note: If you have any errors of missing symbols while compiling, you need to have mysql development libs to compile it.</p> <p>On Linux it's easy to install it:</p> <pre><code>sudo apt-get install mysql-deve...
0
2013-07-10T21:43:48Z
[ "python", "mysql", "django" ]
How to check if python is installed in windows from java?
1,299,018
<p>How can I check from inside a java program if python is installed in windows? Python does not add its path to the system Path and no assumption is to be made about the probable path of installation(i.e it can be installed anywhere).</p>
3
2009-08-19T10:32:51Z
1,299,042
<p>Have you tried querying the registry to check if it is installed? It is stored in </p> <p><code>software\python\pythoncore</code></p> <p>If the user has a (relatively) new version of python, that is installed with the MSI-package, you can use the <a href="http://msdn.microsoft.com/en-us/library/aa370101%28VS.85%29...
1
2009-08-19T10:38:31Z
[ "java", "python", "installation" ]
How to check if python is installed in windows from java?
1,299,018
<p>How can I check from inside a java program if python is installed in windows? Python does not add its path to the system Path and no assumption is to be made about the probable path of installation(i.e it can be installed anywhere).</p>
3
2009-08-19T10:32:51Z
1,299,046
<p>Most Python installers add keys to the Windows registry. Here's <a href="http://effbot.org/zone/python-register.htm" rel="nofollow">an article</a> about how to add that information, you can use it to see how to read the information.</p>
2
2009-08-19T10:38:46Z
[ "java", "python", "installation" ]
How to check if python is installed in windows from java?
1,299,018
<p>How can I check from inside a java program if python is installed in windows? Python does not add its path to the system Path and no assumption is to be made about the probable path of installation(i.e it can be installed anywhere).</p>
3
2009-08-19T10:32:51Z
1,299,061
<p>exec(String command) Executes the specified string command in a separate process. Check for Python from command</p>
0
2009-08-19T10:41:30Z
[ "java", "python", "installation" ]
How to check if python is installed in windows from java?
1,299,018
<p>How can I check from inside a java program if python is installed in windows? Python does not add its path to the system Path and no assumption is to be made about the probable path of installation(i.e it can be installed anywhere).</p>
3
2009-08-19T10:32:51Z
1,299,062
<p>Use the Java Runtime to exec the following command "python --version".</p> <p>If it works, you have Python, and the standard output is the version number.</p> <p>If it doesn't work, you don't have Python.</p>
2
2009-08-19T10:41:31Z
[ "java", "python", "installation" ]
How to check if python is installed in windows from java?
1,299,018
<p>How can I check from inside a java program if python is installed in windows? Python does not add its path to the system Path and no assumption is to be made about the probable path of installation(i.e it can be installed anywhere).</p>
3
2009-08-19T10:32:51Z
19,837,856
<p>this would work</p> <ul> <li>Process process = Runtime.getRuntime().exec("cmd /c C:\Python27\python --version");</li> </ul>
-1
2013-11-07T13:59:39Z
[ "java", "python", "installation" ]
Handling international dates in python
1,299,377
<p>I have a date that is either formatted in German for e.g, </p> <pre><code>2. Okt. 2009 </code></pre> <p>and also perhaps as </p> <pre><code>2. Oct. 2009 </code></pre> <p>How do I parse this into an ISO datetime (or python <code>datetime</code>)?</p> <p>Solved by using this snippet:</p> <pre><code>for l in loca...
4
2009-08-19T11:37:46Z
1,299,387
<p><a href="http://docs.python.org/library/locale.html">http://docs.python.org/library/locale.html</a></p> <p>The <code>datetime</code> module is already locale aware.</p> <p>It's something like the following</p> <pre><code># German locale loc= locale.setlocale(locale.LC_TIME,("de","de")) try: date= datetime.da...
7
2009-08-19T11:40:23Z
[ "python", "datetime", "internationalization" ]
Handling international dates in python
1,299,377
<p>I have a date that is either formatted in German for e.g, </p> <pre><code>2. Okt. 2009 </code></pre> <p>and also perhaps as </p> <pre><code>2. Oct. 2009 </code></pre> <p>How do I parse this into an ISO datetime (or python <code>datetime</code>)?</p> <p>Solved by using this snippet:</p> <pre><code>for l in loca...
4
2009-08-19T11:37:46Z
1,300,274
<p>Very minor point about your code snippet : I'm no python expert but I'd consider the whole flag to check for success + silently swallowing all exceptions to be bad form.</p> <p>try/expect/else does what you want in a cleaner way, I think :</p> <pre><code>for l in locale.locale_alias: try: locale.setloc...
1
2009-08-19T14:16:26Z
[ "python", "datetime", "internationalization" ]
Beginner at testing Python code, need help!
1,299,672
<p>I don't do tests, but I'd like to start. I have some questions :</p> <ol> <li>Is it ok to use the <code>unittest</code> module for that? From what I understand, the <code>unittest</code> module will run any method starting with <code>test</code>.</li> <li>if I have a separate directory for the tests ( consider a di...
3
2009-08-19T12:39:53Z
1,299,684
<p>It's fine to use <code>unittest</code>. This module will run methods beginning with <code>test</code> for classes which inherit from <code>unittest.TestCase</code>.</p> <p>There's no need to use the <code>imp</code> module - your test module would just import the code under test as normal. You might need to add the...
4
2009-08-19T12:43:02Z
[ "python", "testing" ]
Beginner at testing Python code, need help!
1,299,672
<p>I don't do tests, but I'd like to start. I have some questions :</p> <ol> <li>Is it ok to use the <code>unittest</code> module for that? From what I understand, the <code>unittest</code> module will run any method starting with <code>test</code>.</li> <li>if I have a separate directory for the tests ( consider a di...
3
2009-08-19T12:39:53Z
1,299,705
<p>I had a bit of problem with the whole seperate directory for tests issue. </p> <p>The way I solved it was by having a test runner in the source directory with the following code:</p> <pre><code>import sys, os, re, unittest # Run all tests in t/ def regressionTest(): path = os.path.abspath(os.path.dirname(sys...
2
2009-08-19T12:47:36Z
[ "python", "testing" ]
Beginner at testing Python code, need help!
1,299,672
<p>I don't do tests, but I'd like to start. I have some questions :</p> <ol> <li>Is it ok to use the <code>unittest</code> module for that? From what I understand, the <code>unittest</code> module will run any method starting with <code>test</code>.</li> <li>if I have a separate directory for the tests ( consider a di...
3
2009-08-19T12:39:53Z
1,300,554
<p>Another good way to start tests with your Python code is use the <a href="http://docs.python.org/library/doctest.html" rel="nofollow">doctest</a> module, whereby you include tests inside method and class comments. The neat bit is that these serve as code examples, and therefore, partial documentation. Extremely easy...
5
2009-08-19T15:05:28Z
[ "python", "testing" ]
Beginner at testing Python code, need help!
1,299,672
<p>I don't do tests, but I'd like to start. I have some questions :</p> <ol> <li>Is it ok to use the <code>unittest</code> module for that? From what I understand, the <code>unittest</code> module will run any method starting with <code>test</code>.</li> <li>if I have a separate directory for the tests ( consider a di...
3
2009-08-19T12:39:53Z
1,301,545
<p>As mentioned by Sebastian P., Mark Pilgrim's <em><a href="http://www.diveintopython.org/" rel="nofollow">Dive Into Python</a></em> has great chapters on <a href="http://www.diveintopython.org/unit%5Ftesting/index.html" rel="nofollow">unit testing</a> and <a href="http://www.diveintopython.org/unit%5Ftesting/stage%5F...
2
2009-08-19T17:50:17Z
[ "python", "testing" ]
Error while importing SQLObject on Windows
1,299,849
<p>I am getting following error while importing SQLObject on Window. Does anyone knows what is this error about and how to solve it?</p> <p>==============================</p> <pre><code> from sqlobject import * File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\__init__.py", line 5, in &lt;...
0
2009-08-19T13:14:48Z
1,300,442
<p>Looks like your <code>c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg</code> file may be truncated or otherwise damaged. How does it compare to a freshly downloaded one (in terms of both length and checksum)?</p>
0
2009-08-19T14:44:14Z
[ "python", "windows", "sqlobject" ]
upload file with Python Mechanize
1,299,855
<p>When I run the following script:</p> <pre><code>from mechanize import Browser br = Browser() br.open(url) br.select_form(name="edit_form") br['file'] = 'file.txt' br.submit() </code></pre> <p>I get: <em>ValueError: value attribute is readonly</em></p> <p>And I still get the same error when I add:</p> <pre><code>...
6
2009-08-19T13:15:20Z
1,299,896
<p><a href="http://twill.idyll.org/" rel="nofollow"><code>twill</code></a> is built on <code>mechanize</code> and makes scripting web forms a breeze. See <a href="http://stackoverflow.com/questions/1294862/python-www-macro">python-www-macro</a>.</p> <pre><code>&gt;&gt;&gt; from twill import commands &gt;&gt;&gt; print...
2
2009-08-19T13:24:04Z
[ "python", "file", "forms", "upload", "mechanize" ]
upload file with Python Mechanize
1,299,855
<p>When I run the following script:</p> <pre><code>from mechanize import Browser br = Browser() br.open(url) br.select_form(name="edit_form") br['file'] = 'file.txt' br.submit() </code></pre> <p>I get: <em>ValueError: value attribute is readonly</em></p> <p>And I still get the same error when I add:</p> <pre><code>...
6
2009-08-19T13:15:20Z
1,305,860
<p>This is how to do it properly with Mechanize:</p> <pre><code>br.form.add_file(open(filename), 'text/plain', filename) </code></pre>
11
2009-08-20T12:30:32Z
[ "python", "file", "forms", "upload", "mechanize" ]
Apache/Django freezing after a few requests
1,300,213
<p>I'm running Django through mod_wsgi and Apache (2.2.8) on Ubuntu 8.04.</p> <p>I've been running Django on this setup for about 6 months without any problems. Yesterday, I moved my database (postgres 8.3) to its own server, and my Django site started refusing to load (the browser spinner would just keep spinning).<...
1
2009-08-19T14:09:48Z
1,300,283
<p>It sounds a lot like there's something happening between django and your newly housed database.</p> <p>Just to eliminate apache from the mix, you should run it as the dev server (on some random port to stop people using it) and see if you still have issues. If you do, it's the database. If it behaves, it could be a...
0
2009-08-19T14:18:39Z
[ "python", "django", "postgresql", "apache2", "mod-wsgi" ]
Apache/Django freezing after a few requests
1,300,213
<p>I'm running Django through mod_wsgi and Apache (2.2.8) on Ubuntu 8.04.</p> <p>I've been running Django on this setup for about 6 months without any problems. Yesterday, I moved my database (postgres 8.3) to its own server, and my Django site started refusing to load (the browser spinner would just keep spinning).<...
1
2009-08-19T14:09:48Z
2,368,542
<p>Found it! I'm using eventlet in some other code and I imported one of my modules into a django model. So eventlet was taking over and putting everything to "sleep".</p>
0
2010-03-03T03:24:35Z
[ "python", "django", "postgresql", "apache2", "mod-wsgi" ]
HTTPResponse - Return organised data (table?)
1,300,310
<p>My Webservice is currently returning a HTTPResponse which contains thousands of data from a mySQL database (via a Objects.filter). It's currently just displating them in a very boring way!</p> <p>I'm looking to organised this data in some way. What would be ideal is two things:</p> <p>The possibility of having a t...
0
2009-08-19T14:22:21Z
1,300,421
<p>Do you need to return pure HTML (as opposed to, say, JSON and Javascript to show it)? If so, the <code>&lt;table&gt;</code> <a href="http://www.w3schools.com/html/html%5Ftables.asp" rel="nofollow">tag</a> of HTML seems to be what you want; and <a href="http://www.htmlcodetutorial.com/help/ftopic2394.html" rel="nofol...
1
2009-08-19T14:40:09Z
[ "python", "django" ]
Python re question - sub challenge
1,300,350
<p>I want to add a href links to all words prefixed with # or ! or @ If this is the text</p> <p>Check the #bamboo and contact @Fred re #bamboo #garden</p> <p>should be converted to:</p> <pre><code>Check the &lt;a href="/what/bamboo"&gt;#bamboo&lt;/a&gt; and contact &lt;a href="/who/fred"&gt;@Fred&lt;/a&gt; re &lt;a ...
1
2009-08-19T14:27:28Z
1,300,406
<p>I'd do it with a single match and a function picking the "place". I.e.:</p> <pre><code>import re places = {'#': 'what', '@': 'who', '!': 'why', } def replace(m): all = m.group(0) first, rest = all[0], all[1:] return '&lt;a href="/%s/%s"&gt;%s&lt;/a&gt;' % ( places[first], re...
5
2009-08-19T14:37:05Z
[ "python", "regex" ]
How to map one class against multiple tables with SQLAlchemy?
1,300,433
<p>Lets say that I have a database structure with three tables that look like this:</p> <pre><code>items - item_id - item_handle attributes - attribute_id - attribute_name item_attributes - item_attribute_id - item_id - attribute_id - attribute_value </code></pre> <p>I would like to be able to do this in SQ...
9
2009-08-19T14:42:39Z
1,300,603
<p>This is called the <a href="http://en.wikipedia.org/wiki/Entity-attribute-value_model">entity-attribute-value</a> pattern. There is an example about this under the SQLAlchemy examples directory: <a href="http://www.sqlalchemy.org/trac/browser/examples/vertical/">vertical/</a>.</p> <p>If you are using PostgreSQL, th...
8
2009-08-19T15:13:25Z
[ "python", "database", "database-design", "sqlalchemy" ]
How to map one class against multiple tables with SQLAlchemy?
1,300,433
<p>Lets say that I have a database structure with three tables that look like this:</p> <pre><code>items - item_id - item_handle attributes - attribute_id - attribute_name item_attributes - item_attribute_id - item_id - attribute_id - attribute_value </code></pre> <p>I would like to be able to do this in SQ...
9
2009-08-19T14:42:39Z
2,890,682
<p>The link to vertical/vertical.py is broken. The example had been renamed to <code>dictlike-polymorphic.py</code> and <code>dictlike.py.</code></p> <p>I am pasting in the contents of <code>dictlike.py</code>:</p> <pre><code>"""Mapping a vertical table as a dictionary. This example illustrates accessing and modifyi...
5
2010-05-23T04:36:12Z
[ "python", "database", "database-design", "sqlalchemy" ]
Best Python Library for Downloading and Extracting Addresses
1,300,479
<p>I've just been given a project which involves the following steps</p> <ol> <li>Grab an email from a POP3 address</li> <li>Open an attachment from the email</li> <li>Extract the To: email address</li> <li>Add this to a global suppression list </li> </ol> <p>I'd like to try and do this in Python even though I could ...
0
2009-08-19T14:51:12Z
1,300,517
<p>Two bits from the standard library: <a href="http://docs.python.org/library/poplib.html" rel="nofollow">poplib</a> to grab the email via POP3, <a href="http://docs.python.org/library/email.html" rel="nofollow">email</a> to slice and dice it as you wish.</p>
2
2009-08-19T14:59:24Z
[ "python", "email", "pop3" ]
Python - substr
1,300,610
<p>I need to be able to get the last digit of a number.</p> <p>i.e., I need 2 to be returned from: 12.</p> <p>Like this in PHP: <code>$minute = substr(date('i'), -1)</code> but I need this in Python.</p> <p>Any ideas</p>
1
2009-08-19T15:14:28Z
1,300,619
<pre><code>last_digit = str(number)[-1] </code></pre>
10
2009-08-19T15:16:16Z
[ "php", "python", "substr" ]
Python - substr
1,300,610
<p>I need to be able to get the last digit of a number.</p> <p>i.e., I need 2 to be returned from: 12.</p> <p>Like this in PHP: <code>$minute = substr(date('i'), -1)</code> but I need this in Python.</p> <p>Any ideas</p>
1
2009-08-19T15:14:28Z
1,300,625
<p>Use the <strong>%</strong> operator:</p> <pre><code> x = 12 % 10 # returns 2 y = 25 % 10 # returns 5 z = abs(-25) % 10 # returns 5 </code></pre>
8
2009-08-19T15:16:43Z
[ "php", "python", "substr" ]
Python - substr
1,300,610
<p>I need to be able to get the last digit of a number.</p> <p>i.e., I need 2 to be returned from: 12.</p> <p>Like this in PHP: <code>$minute = substr(date('i'), -1)</code> but I need this in Python.</p> <p>Any ideas</p>
1
2009-08-19T15:14:28Z
1,300,675
<p>Python distinguishes between strings and numbers (and actually also between numbers of different kinds, i.e., int vs float) so the best solution depends on what type you start with (str or int?) and what type you want as a result (ditto).</p> <p>Int to int: <code>abs(x) % 10</code></p> <p>Int to str: <code>str(x)[...
2
2009-08-19T15:23:38Z
[ "php", "python", "substr" ]
Multidimensional list(array) reassignment problem
1,300,648
<p>Good day coders and codereses,</p> <p>I am writing a piece of code that goes through a pile of statistical data and returns what I ask from it. To complete its task the method reads from one multidimensional array and writes into another one. The piece of code giving me problems is:</p> <pre><code>writer.variables...
1
2009-08-19T15:20:52Z
1,300,692
<p>The size of a slice with <code>0:5</code> is not 6 as you say: it's 5. The upper limit is excluded in slicing (as it most always is, in Python). Don't know whether that's your actual problem or just a typo in your question...</p>
2
2009-08-19T15:25:59Z
[ "python", "list", "numpy", "scipy", "netcdf" ]
Writing Python/Django view to "join" across three models/tables
1,300,657
<p>Just begin my Python/Django experience and i have a problem :-)</p> <p>So i have a model.py like this:</p> <pre><code>from django.db import models class Priority(models.Model): name = models.CharField(max_length=100) class Projects(models.Model): name = models.CharField(max_length=30) description = m...
1
2009-08-19T15:21:39Z
1,300,701
<p>There are many ways of accomplishing what you need. One of the easiest would be to keep a dictionary of number to string. Like this: 1->High, 2->Medium, 3->High.</p> <p>Keep this dictionary outside of your view functions so that you can access it from any of your view functions that need to get the priority.</p> <...
0
2009-08-19T15:27:21Z
[ "python", "django-views" ]
Writing Python/Django view to "join" across three models/tables
1,300,657
<p>Just begin my Python/Django experience and i have a problem :-)</p> <p>So i have a model.py like this:</p> <pre><code>from django.db import models class Priority(models.Model): name = models.CharField(max_length=100) class Projects(models.Model): name = models.CharField(max_length=30) description = m...
1
2009-08-19T15:21:39Z
1,300,789
<p>Your view doesn't have to do much.</p> <pre><code>tasks = Tasks.objects.all() </code></pre> <p>Provide this to your template.</p> <p>Your template can then do something like the following.</p> <pre><code>{% for t in tasks %} name: {{t.name}} description: {{t.description}} priority: **{{t.priority.nam...
2
2009-08-19T15:37:20Z
[ "python", "django-views" ]
Hierarchical data output from App Engine Datastore to JSON?
1,300,694
<p>I have a large hierarchical dataset in the App Engine Datastore. The hierarchy is preserved by storing the data in Entity groups, so that I can pull a whole tree by simply knowing the top element key like so:</p> <p><code>query = db.Query().ancestor(db.get(key))</code></p> <p>The question: How do I now output thi...
1
2009-08-19T15:26:07Z
1,300,783
<p>I imagine you're referring to <a href="http://code.google.com/p/google-app-engine-samples/source/browse/trunk/geochat/json.py?r=55" rel="nofollow">this code</a> and the "flattening" you mention is done by lines 51-52:</p> <pre><code> if isinstance(obj, db.GqlQuery): return list(obj) </code></pre> <p>while ...
1
2009-08-19T15:36:49Z
[ "python", "json", "google-app-engine", "gae-datastore" ]
Load blob image data into QPixmap
1,300,908
<p>I am writing a program using PyQt4 for front-end GUI and this program accesses a back-end database (which can be either MySQL or SQLite). I need to store some image data in the database and below is the Python code I use to import image files (in JPEG format) to a blob data field in the database:</p> <pre><code>def...
4
2009-08-19T15:52:53Z
1,300,979
<p>You can use the QImage.fromData static method to load an image from a string and then convert it to a pixmap:</p> <pre><code> image_data = get_image_data_from_blob() qimg = QtGui.QImage.fromData(image_data) pixmap = QtGui.QPixmap.fromImage(qimg) </code></pre>
6
2009-08-19T16:05:42Z
[ "python", "image", "pyqt", "blob", "qpixmap" ]
Load blob image data into QPixmap
1,300,908
<p>I am writing a program using PyQt4 for front-end GUI and this program accesses a back-end database (which can be either MySQL or SQLite). I need to store some image data in the database and below is the Python code I use to import image files (in JPEG format) to a blob data field in the database:</p> <pre><code>def...
4
2009-08-19T15:52:53Z
1,301,997
<p>The approach suggested by Ants Aasma works and actually it is also OK to just use the following code: </p> <pre><code>image_data = cPickle.loads(str(s)) # s is fetched from DB qp = QPixmap() qp.loadFromData(image_data) </code></pre> <p>Thanks a lot for all the help and information.</p>
1
2009-08-19T19:02:15Z
[ "python", "image", "pyqt", "blob", "qpixmap" ]
Load blob image data into QPixmap
1,300,908
<p>I am writing a program using PyQt4 for front-end GUI and this program accesses a back-end database (which can be either MySQL or SQLite). I need to store some image data in the database and below is the Python code I use to import image files (in JPEG format) to a blob data field in the database:</p> <pre><code>def...
4
2009-08-19T15:52:53Z
2,213,246
<p>After a good hour and a half of googleing to solve a similar problem, I ended up loading JPEGs in a compiled .exe with QT. I am using python3.1, and therefore could not use some of the previously mentioned solutions :</p> <ul> <li>tips working for py2exe (because I am using cxfreeze instead of py2exe, as py2exe wor...
0
2010-02-06T13:32:12Z
[ "python", "image", "pyqt", "blob", "qpixmap" ]
mod_python problem?
1,301,000
<p>I have been working on a website using mod_python, python, and SQL Alchemy when I ran into a strange problem: When I query the database for all of the records, it returns the correct result set; however, when I refresh the page, it returns me a result set with that same result set appended to it. I get more result s...
0
2009-08-19T16:08:45Z
1,301,029
<p>Not that I've ever heard of, but it's impossible to tell without some code to look at.</p> <p>Maybe you initialised your result set list as a global, or shared member, and then appended results to it when the application was called without resetting it to empty? A classic way of re-using lists accidentally is to pu...
0
2009-08-19T16:13:55Z
[ "python", "sqlalchemy", "mod-python" ]
mod_python problem?
1,301,000
<p>I have been working on a website using mod_python, python, and SQL Alchemy when I ran into a strange problem: When I query the database for all of the records, it returns the correct result set; however, when I refresh the page, it returns me a result set with that same result set appended to it. I get more result s...
0
2009-08-19T16:08:45Z
1,301,471
<p>I don't know about any of the technologies you are using. However, before you think that might be a possible bug in the packages you are using, you have to consider one thing.</p> <p><a href="http://en.wikipedia.org/wiki/Occam%27s%5Frazor" rel="nofollow">Occam's razor.</a></p> <p>Basically, "when you have two comp...
0
2009-08-19T17:34:23Z
[ "python", "sqlalchemy", "mod-python" ]
Fastest ways to key-wise add a list of dicts together in python
1,301,149
<p>Say I have a bunch of dictionaries </p> <pre><code>a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } </code></pre> <p>There's only two there, but the question is regarding an arbitary amount.</p> <p>What's the fastest way to find the mean value for each key? The dicts are quite sparse, so there will ...
3
2009-08-19T16:38:40Z
1,301,206
<p>It may be proven through profiling that this isn't quite the fastest but...</p> <pre><code>import collections a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } dicts = [a,b] totals = collections.defaultdict(list) avg = {} for D in dicts: for key,value in D.iteritems(): totals[key].append...
2
2009-08-19T16:48:07Z
[ "python", "dictionary" ]
Fastest ways to key-wise add a list of dicts together in python
1,301,149
<p>Say I have a bunch of dictionaries </p> <pre><code>a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } </code></pre> <p>There's only two there, but the question is regarding an arbitary amount.</p> <p>What's the fastest way to find the mean value for each key? The dicts are quite sparse, so there will ...
3
2009-08-19T16:38:40Z
1,301,211
<p>This works:</p> <pre><code>import collections data= [ {'x': 1.0, 'y': 0.5, 'z': 0.25 }, {'w': 0.5, 'x': 0.2 } ] tally = collections.defaultdict(lambda: (0.0, 0)) for d in data: for k,v in d.items(): sum, count = tally[k] tally[k] = (sum+v, count+1) results = {} for k, v in tally....
2
2009-08-19T16:48:34Z
[ "python", "dictionary" ]
Fastest ways to key-wise add a list of dicts together in python
1,301,149
<p>Say I have a bunch of dictionaries </p> <pre><code>a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } </code></pre> <p>There's only two there, but the question is regarding an arbitary amount.</p> <p>What's the fastest way to find the mean value for each key? The dicts are quite sparse, so there will ...
3
2009-08-19T16:38:40Z
1,301,218
<pre><code>&gt;&gt;&gt; def avg(items): ... return sum(items) / len(items) ... &gt;&gt;&gt; hashes = [a, b] &gt;&gt;&gt; dict([(k, avg([h.get(k) or 0 for h in hashes])) for k in set(sum((h.keys() for h in hashes), []))]) {'y': 0.25, 'x': 0.59999999999999998, 'z': 0.125, 'w': 0.25} </code></pre> <p>Explanation:</p...
1
2009-08-19T16:49:44Z
[ "python", "dictionary" ]
Fastest ways to key-wise add a list of dicts together in python
1,301,149
<p>Say I have a bunch of dictionaries </p> <pre><code>a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } </code></pre> <p>There's only two there, but the question is regarding an arbitary amount.</p> <p>What's the fastest way to find the mean value for each key? The dicts are quite sparse, so there will ...
3
2009-08-19T16:38:40Z
1,301,527
<p>It is possible that your bottleneck might be due to excessive memory use. Consider using iteritems to leverage the power of generators.</p> <p>Since you say your data is sparse, that will probably not be the most efficient. Consider this alternate usage of iterators:</p> <pre><code>dicts = ... #Assume this is yo...
0
2009-08-19T17:45:58Z
[ "python", "dictionary" ]
Fastest ways to key-wise add a list of dicts together in python
1,301,149
<p>Say I have a bunch of dictionaries </p> <pre><code>a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } </code></pre> <p>There's only two there, but the question is regarding an arbitary amount.</p> <p>What's the fastest way to find the mean value for each key? The dicts are quite sparse, so there will ...
3
2009-08-19T16:38:40Z
1,301,644
<p><a href="http://www.scipy.org/doc/api%5Fdocs/SciPy.sparse.sparse.html" rel="nofollow">scipy.sparse</a> supports sparse matrices -- the <a href="http://www.scipy.org/doc/api%5Fdocs/SciPy.sparse.sparse.dok%5Fmatrix.html" rel="nofollow"><code>dok_matrix</code></a> form seems reasonably suited to your needs (you'll have...
0
2009-08-19T18:05:44Z
[ "python", "dictionary" ]
Fastest ways to key-wise add a list of dicts together in python
1,301,149
<p>Say I have a bunch of dictionaries </p> <pre><code>a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } </code></pre> <p>There's only two there, but the question is regarding an arbitary amount.</p> <p>What's the fastest way to find the mean value for each key? The dicts are quite sparse, so there will ...
3
2009-08-19T16:38:40Z
1,302,027
<p>It's simple but this could work:</p> <pre><code>a = { 'x': 1.0, 'y': 0.5, 'z': 0.25 } b = { 'w': 0.5, 'x': 0.2 } ds = [a, b] result = {} for d in ds: for k, v in d.iteritems(): result[k] = v + result.get(k, 0) n = len(ds) result = dict((k, amt/n) for k, amt in result.iteritems()) print result </code...
0
2009-08-19T19:07:34Z
[ "python", "dictionary" ]
How to sort digits in a number?
1,301,156
<p>I'm trying to make an easy script in Python which takes a number and saves in a variable, sorting the digits in ascending and descending orders and saving both in separate variables. Implementing <a href="http://en.wikipedia.org/wiki/6174" rel="nofollow">Kaprekar's constant</a>.</p> <p>It's probably a pretty noobis...
2
2009-08-19T16:39:13Z
1,301,168
<pre><code>&gt;&gt;&gt; x = [4,5,81,5,28958,28] # first list &gt;&gt;&gt; print sorted(x) [4, 5, 5, 28, 81, 28958] &gt;&gt;&gt; x [4, 5, 81, 5, 28958, 28] &gt;&gt;&gt; x.sort() # sort the list in place &gt;&gt;&gt; x [4, 5, 5, 28, 81, 28958] &gt;&gt;&gt; x.append(1) # add to the list &gt;&gt;&gt; x [4, 5, 5, 28, 81, 28...
2
2009-08-19T16:41:17Z
[ "python", "numbers" ]
How to sort digits in a number?
1,301,156
<p>I'm trying to make an easy script in Python which takes a number and saves in a variable, sorting the digits in ascending and descending orders and saving both in separate variables. Implementing <a href="http://en.wikipedia.org/wiki/6174" rel="nofollow">Kaprekar's constant</a>.</p> <p>It's probably a pretty noobis...
2
2009-08-19T16:39:13Z
1,301,246
<p>Sort the digits in ascending and descending orders:</p> <pre><code>ascending = "".join(sorted(str(number))) descending = "".join(sorted(str(number), reverse=True)) </code></pre> <p>Like this:</p> <pre><code>&gt;&gt;&gt; number = 5896 &gt;&gt;&gt; ascending = "".join(sorted(str(number))) &gt;&gt;&gt; &gt;&gt;&gt;...
10
2009-08-19T16:55:37Z
[ "python", "numbers" ]
How to sort digits in a number?
1,301,156
<p>I'm trying to make an easy script in Python which takes a number and saves in a variable, sorting the digits in ascending and descending orders and saving both in separate variables. Implementing <a href="http://en.wikipedia.org/wiki/6174" rel="nofollow">Kaprekar's constant</a>.</p> <p>It's probably a pretty noobis...
2
2009-08-19T16:39:13Z
1,301,313
<p>I don't know the python syntax, but thinking the generically, I would convert the input string into a character array, they do a sort on the character array, and lastly pipe it out.</p>
1
2009-08-19T17:07:59Z
[ "python", "numbers" ]
How to sort digits in a number?
1,301,156
<p>I'm trying to make an easy script in Python which takes a number and saves in a variable, sorting the digits in ascending and descending orders and saving both in separate variables. Implementing <a href="http://en.wikipedia.org/wiki/6174" rel="nofollow">Kaprekar's constant</a>.</p> <p>It's probably a pretty noobis...
2
2009-08-19T16:39:13Z
1,303,841
<p>As Mark Rushakoff already mentioned (but didn't solve) in his answer, <code>str(n)</code> doesn't handle numeric <code>n</code> with leading zeros, which you need for <a href="http://en.wikipedia.org/wiki/6174" rel="nofollow">Kaprekar's operation</a>. hughdbrown's answer similarly doesn't work with leading zeros.</...
2
2009-08-20T03:46:54Z
[ "python", "numbers" ]
How to sort digits in a number?
1,301,156
<p>I'm trying to make an easy script in Python which takes a number and saves in a variable, sorting the digits in ascending and descending orders and saving both in separate variables. Implementing <a href="http://en.wikipedia.org/wiki/6174" rel="nofollow">Kaprekar's constant</a>.</p> <p>It's probably a pretty noobis...
2
2009-08-19T16:39:13Z
1,338,221
<p>Here's an answer to the title question in Perl, with a bias toward sorting 4-digit numbers for the Kaprekar algorithm. In the example, replace 'shift' with the number to sort. It sorts digits in a 4-digit number with leading 0's ($asc is sorted in ascending order, $dec is descending), and outputs a number with lea...
0
2009-08-27T00:05:21Z
[ "python", "numbers" ]
unable to import libxml2mod from the python script
1,301,167
<pre><code>File "/usr/local/lib/python2.5/site-packages/libxml2.py", line 1, in &lt;module&gt; import libxml2mod ImportError: /usr/local/lib/python2.5/site-packages/libxml2mod.so: undefined symbol:xmlTextReaderSetup &gt;&gt;&gt; import libxml2mod &gt;&gt;&gt; import libxml2 &gt;&gt;&gt; </code></pre> <p>o...
0
2009-08-19T16:40:58Z
1,302,196
<p>I can only suggest that your paths are different for some reason. Either that, or you are not using the same python interpreter in both cases.</p> <p>I have experienced this when I happen to have a couple of interpreters, and the wrong one is either default, or specified in the #! section of the script.</p>
2
2009-08-19T19:37:30Z
[ "python", "importerror" ]
What regex can I use to capture groups from this string?
1,301,257
<p>Assume the following strings:</p> <ul> <li><code>A01B100</code></li> <li><code>A01.B100</code></li> <li><code>A01</code></li> <li><code>A01............................B100</code> ( whatever between A and B )</li> </ul> <p>The thing is, the numbers should be <code>\d+</code>, and in all of the strings A will always...
1
2009-08-19T16:58:06Z
1,301,281
<pre><code>(?ms)^A(\d+)(?:[^\n\r]*B(\d+))?$ </code></pre> <p>Assuming one string per line:</p> <ul> <li><p>the [^\n\r]* is a non-greedy match for any characters (except newlines) after Axx, meaing it could gobble an intermediate Byy before the last B:</p> <p>A01...B01...B23</p></li> </ul> <p>would be matched, with ...
1
2009-08-19T17:02:59Z
[ "python", "regex" ]
What regex can I use to capture groups from this string?
1,301,257
<p>Assume the following strings:</p> <ul> <li><code>A01B100</code></li> <li><code>A01.B100</code></li> <li><code>A01</code></li> <li><code>A01............................B100</code> ( whatever between A and B )</li> </ul> <p>The thing is, the numbers should be <code>\d+</code>, and in all of the strings A will always...
1
2009-08-19T16:58:06Z
1,301,291
<pre><code>A\d+.*(B\d+)? </code></pre> <p>OK, so that provides something which passes all test cases... BUT it has some false positives.</p> <pre><code>A\d+(.*B\d+)? </code></pre> <p>It seems other characters should only appear if B(whatever) is after them, so use the above instead.</p> <pre><code>#perl test case h...
0
2009-08-19T17:04:41Z
[ "python", "regex" ]
What regex can I use to capture groups from this string?
1,301,257
<p>Assume the following strings:</p> <ul> <li><code>A01B100</code></li> <li><code>A01.B100</code></li> <li><code>A01</code></li> <li><code>A01............................B100</code> ( whatever between A and B )</li> </ul> <p>The thing is, the numbers should be <code>\d+</code>, and in all of the strings A will always...
1
2009-08-19T16:58:06Z
1,301,293
<pre><code>import re m = re.match(r"A(?P&lt;d1&gt;\d+)\.*(B(?P&lt;d2&gt;\d+))?", "A01.B100") print m.groupdict() </code></pre>
0
2009-08-19T17:04:45Z
[ "python", "regex" ]
What regex can I use to capture groups from this string?
1,301,257
<p>Assume the following strings:</p> <ul> <li><code>A01B100</code></li> <li><code>A01.B100</code></li> <li><code>A01</code></li> <li><code>A01............................B100</code> ( whatever between A and B )</li> </ul> <p>The thing is, the numbers should be <code>\d+</code>, and in all of the strings A will always...
1
2009-08-19T16:58:06Z
1,301,306
<ul> <li>Must <code>A</code> precede <code>B</code>? Assuming yes.</li> <li>Can <code>B</code> appear more than once? Assuming no. </li> <li>Can <code>B</code> appear except as part of a <code>B</code>-number group? Assuming no.</li> </ul> <p>Then,</p> <pre><code>A\d+.*?(B\d+)? </code></pre> <p>using the lazy .*? or...
3
2009-08-19T17:06:38Z
[ "python", "regex" ]
How can I make a Django query for the first occurrence of a foreign key in a column?
1,301,270
<p>Basically, I have a table with a bunch of foreign keys and I'm trying to query only the first occurrence of a particular key by the "created" field. Using the Blog/Entry example, if the Entry model has a foreign key to Blog and a foreign key to User, then how can I construct a query to select all Entries in which a ...
1
2009-08-19T17:01:11Z
1,301,376
<p><code>query = Entry.objects.filter(user=user).order_by('id')[0]</code></p> <p>Basically order by id (lowest to highest), and slice it to get only the first hit from the QuerySet.</p> <p>I don't have a Django install available right now to test my line, so please check the documentation if somehow I have a type abo...
1
2009-08-19T17:16:42Z
[ "python", "django", "foreign-keys" ]
How can I make a Django query for the first occurrence of a foreign key in a column?
1,301,270
<p>Basically, I have a table with a bunch of foreign keys and I'm trying to query only the first occurrence of a particular key by the "created" field. Using the Blog/Entry example, if the Entry model has a foreign key to Blog and a foreign key to User, then how can I construct a query to select all Entries in which a ...
1
2009-08-19T17:01:11Z
1,303,400
<p>Can't test it in this particular moment</p> <pre><code>Entry.objects.filter(user=user).distinct("blog").order_by("id") </code></pre>
0
2009-08-20T00:47:16Z
[ "python", "django", "foreign-keys" ]
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
1,301,357
<p>I think you need to call <code>sendInitPresence</code> before sending the first message:</p> <pre><code>... cnx.auth(login,pwd, 'botty') cnx.sendInitPresence() cnx.send( xmpp.Message( "YourFriend@gmail.com" ,"Hello World form Python" ) ) </code></pre>
0
2009-08-19T17:13:15Z
[ "python", "xmpp" ]
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
1,318,431
<p>Try this code snippet. I didn't handle the error conditions for simplicity's sake.</p> <pre><code>import xmpp login = 'Your.Login' # @gmail.com pwd = 'YourPassword' jid = xmpp.protocol.JID(login) cl = xmpp.Client(jid.getDomain(), debug=[]) if cl.connect(('talk.google.com',5223)): print "Connected" else: ...
1
2009-08-23T12:14:06Z
[ "python", "xmpp" ]
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
1,541,802
<p><a href="https://svn.tchoy.net/svn/jTalk/trunk/pyTalk/ConnectorThread.py">Here</a> is how it did on <a href="http://pytalk.trunat.fr/">my PyTalk client</a>.</p> <p><strong>Don't forget the @gmail.com in the userID.</strong></p> <p>I think you should try to connect talk.google.com on the 5222 port.</p> <p>Also try...
6
2009-10-09T04:31:51Z
[ "python", "xmpp" ]