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 to merge 200 csv files in Python | 2,512,386 | <p>Guys, I here have 200 separate csv files named from SH (1) to SH (200). I want to merge them into a single csv file. How can I do it?</p>
| 22 | 2010-03-25T00:24:29Z | 17,947,216 | <p>I'm just gonna through another code example in the basket</p>
<pre><code>from glob import glob
with open('singleDataFile.csv', 'a') as singleFile:
for csvFile in glob('*.csv'):
for line in open(csvFile, 'r'):
singleFile.write(line)
</code></pre>
| 6 | 2013-07-30T12:36:26Z | [
"python",
"csv",
"merge"
] |
how to merge 200 csv files in Python | 2,512,386 | <p>Guys, I here have 200 separate csv files named from SH (1) to SH (200). I want to merge them into a single csv file. How can I do it?</p>
| 22 | 2010-03-25T00:24:29Z | 25,889,148 | <p>A slight change to the code above as it does not actually work correctly.</p>
<p>It should be as follows...</p>
<pre><code>from glob import glob
with open('main.csv', 'a') as singleFile:
for csv in glob('*.csv'):
if csv == 'main.csv':
pass
else:
for line in open(csv, 'r... | 3 | 2014-09-17T11:19:53Z | [
"python",
"csv",
"merge"
] |
how to merge 200 csv files in Python | 2,512,386 | <p>Guys, I here have 200 separate csv files named from SH (1) to SH (200). I want to merge them into a single csv file. How can I do it?</p>
| 22 | 2010-03-25T00:24:29Z | 27,422,341 | <p>Quite easy to combine all files in a directory and merge them</p>
<pre><code>import glob
import csv
# Open result file
with open('output.txt','wb') as fout:
wout = csv.writer(fout,delimiter=',')
interesting_files = glob.glob("*.csv")
for filename in interesting_files:
print 'Processing',fil... | 0 | 2014-12-11T11:58:42Z | [
"python",
"csv",
"merge"
] |
How to chroot Django | 2,512,428 | <p>Can one run Django in a chroot? Notably, what's necessary in order to set up (for example) /var/www as a chroot'd directory and then have Django run in that chroot'd directory?</p>
<p>Thank you - I'm grateful for any input.</p>
| 1 | 2010-03-25T00:42:32Z | 2,512,563 | <p>You will have to add a Python interpreter to that directory and add Django to it ofcourse.</p>
<p>After you've got the environment set-up you will have to create a wrapper script that does something like <code>os.chroot('/var/www/')</code> and you're done :)</p>
<p>To create a sandboxed/chrooted environment for Py... | 2 | 2010-03-25T01:17:36Z | [
"python",
"django",
"security",
"chroot",
"jail"
] |
How to chroot Django | 2,512,428 | <p>Can one run Django in a chroot? Notably, what's necessary in order to set up (for example) /var/www as a chroot'd directory and then have Django run in that chroot'd directory?</p>
<p>Thank you - I'm grateful for any input.</p>
| 1 | 2010-03-25T00:42:32Z | 2,512,701 | <p>There are many reasons <a href="http://code.google.com/p/modwsgi/" rel="nofollow">mod_wsgi</a> is preferred for Python web app deployment. One is stability, another is the variety of configuration options... one of which is ability to chroot the mod_wsgi daemon (starting with version 3.00).</p>
<p>The chroot optio... | 3 | 2010-03-25T02:07:10Z | [
"python",
"django",
"security",
"chroot",
"jail"
] |
How do I mock a class property with mox? | 2,512,453 | <p>I have a class:</p>
<pre><code>class MyClass(object):
@property
def myproperty(self):
return 'hello'
</code></pre>
<p>Using <a href="http://code.google.com/p/pymox/" rel="nofollow"><code>mox</code></a> and <code>py.test</code>, how do I mock out <code>myproperty</code>?</p>
<p>I've tried:</p>
<pr... | 5 | 2010-03-25T00:48:25Z | 2,514,613 | <p>Have you read about <a href="http://docs.python.org/library/functions.html#property" rel="nofollow">property</a>? It's read-only, a "getter".</p>
<p>If you want a setter, you have two choices of how to create that.</p>
<p>Once you have both getter and setter, you can try again to mock out both of them.</p>
<pre>... | 3 | 2010-03-25T10:17:59Z | [
"python",
"mocking",
"properties",
"mox"
] |
How do I mock a class property with mox? | 2,512,453 | <p>I have a class:</p>
<pre><code>class MyClass(object):
@property
def myproperty(self):
return 'hello'
</code></pre>
<p>Using <a href="http://code.google.com/p/pymox/" rel="nofollow"><code>mox</code></a> and <code>py.test</code>, how do I mock out <code>myproperty</code>?</p>
<p>I've tried:</p>
<pr... | 5 | 2010-03-25T00:48:25Z | 2,519,772 | <p>When stubbing out class attributes <code>mox</code> uses <code>setattr</code>. Thus</p>
<pre><code>mock.StubOutWithMock(myinstance, 'myproperty')
myinstance.myproperty = 'goodbye'
</code></pre>
<p>is equivalent to</p>
<pre><code># Save old attribute so it can be replaced during teardown
saved = getattr(myinstance... | 9 | 2010-03-25T22:06:42Z | [
"python",
"mocking",
"properties",
"mox"
] |
FancyURLOpener failing since moving to python 3.1.2 | 2,512,538 | <p>I had an application that was downloading a .CSV file from a password-protected website then processing it futher.</p>
<p>I was using FancyURLOpener, and simply hardcoding the username and password. (Obviously, security is not a high priority in this particular instance).</p>
<p>Since downloading Python 3.1.2, thi... | 1 | 2010-03-25T01:10:06Z | 2,512,866 | <p>It's a known bug: <a href="http://bugs.python.org/issue8123" rel="nofollow">http://bugs.python.org/issue8123</a></p>
| 1 | 2010-03-25T03:16:31Z | [
"python",
"python-3.x"
] |
Idiots guide to app engine and memcache | 2,512,571 | <p>I am struggling to find a good tutorial or best practices document for the use of memcache in app engine. </p>
<p>I'm pretty happy with it on the level presented in the docs. Get an object by ID, checking memcache first, but I'm unclear on things like:</p>
<p>If you cache a query, is there an accepted method for... | 2 | 2010-03-25T01:20:09Z | 2,514,663 | <blockquote>
<p>If you cache a query, is there an
accepted method for ensuring that the
cache is cleared/updated when an
object stored in that query is
updated.</p>
</blockquote>
<p>Typically you wrap your reads with a conditional to retrieve the value from the main DB if it's not in the cache. Just wrap you... | 3 | 2010-03-25T10:26:05Z | [
"python",
"google-app-engine",
"memcached"
] |
Idiots guide to app engine and memcache | 2,512,571 | <p>I am struggling to find a good tutorial or best practices document for the use of memcache in app engine. </p>
<p>I'm pretty happy with it on the level presented in the docs. Get an object by ID, checking memcache first, but I'm unclear on things like:</p>
<p>If you cache a query, is there an accepted method for... | 2 | 2010-03-25T01:20:09Z | 5,571,331 | <p>About reference properties, let's say you have MainModel and RefModel with a reference property 'ref' that points to a MainModel instance. Whenever you cal ref_model.ref it does a datastore get operation and retrieves the object from datastore. It does not interact with memcache in any way.</p>
| 0 | 2011-04-06T18:38:25Z | [
"python",
"google-app-engine",
"memcached"
] |
Idiots guide to app engine and memcache | 2,512,571 | <p>I am struggling to find a good tutorial or best practices document for the use of memcache in app engine. </p>
<p>I'm pretty happy with it on the level presented in the docs. Get an object by ID, checking memcache first, but I'm unclear on things like:</p>
<p>If you cache a query, is there an accepted method for... | 2 | 2010-03-25T01:20:09Z | 9,012,657 | <p>One way to easily do this is by searching for any datastore put() call and set memcache after it. Next make sure to get data from memcache before attempting a datastore query.</p>
<p>Set memcache after writing to datastore:</p>
<pre><code>data.put()
memcache.set(user_id, data)
</code></pre>
<p>Try getting data fr... | 2 | 2012-01-26T00:53:00Z | [
"python",
"google-app-engine",
"memcached"
] |
Storing simulation results in a persistent manner for Python? | 2,512,609 | <p>Background: I'm running multiple simulations on a set of data. For each session, I'm allocating projects to students. The difference between each session is that I'm randomising the order of the students such that all the students get a shot at being assigned a project they want. I was writing out some of the alloca... | 2 | 2010-03-25T01:32:06Z | 2,512,649 | <p>Can't help you on the db stuff, as I'm a total newb and only know enough to query data from sqlite tables...</p>
<p>For persistence, though, could you use the pickle module to store your objects? Check the docs for the exact usage, but I think it's pretty much file(filename, 'wb').write(pickle.pickle(myobject)) to... | 0 | 2010-03-25T01:45:10Z | [
"python",
"sqlalchemy",
"persistence"
] |
Storing simulation results in a persistent manner for Python? | 2,512,609 | <p>Background: I'm running multiple simulations on a set of data. For each session, I'm allocating projects to students. The difference between each session is that I'm randomising the order of the students such that all the students get a shot at being assigned a project they want. I was writing out some of the alloca... | 2 | 2010-03-25T01:32:06Z | 2,512,799 | <p>A two-dimension display of data is a Relational database table with two keys.</p>
<p>In your example, the Student Key and the Session Key.</p>
<p>A "Composite key" is a piece of noise that you can ignore. It isn't helpful and isn't necessary. A composite key does not solve any problems well and create many diffi... | 3 | 2010-03-25T02:44:59Z | [
"python",
"sqlalchemy",
"persistence"
] |
Storing simulation results in a persistent manner for Python? | 2,512,609 | <p>Background: I'm running multiple simulations on a set of data. For each session, I'm allocating projects to students. The difference between each session is that I'm randomising the order of the students such that all the students get a shot at being assigned a project they want. I was writing out some of the alloca... | 2 | 2010-03-25T01:32:06Z | 2,519,764 | <p>The logical structure you have can be considered a <a href="http://www.databasedesignstudio.com/faq/Ternary.htm" rel="nofollow">Ternary Relationship</a>, where recommended to you table is corresponding to the <code>Attendance</code> relationship object. Therefore ideally you should also create you object model simil... | 1 | 2010-03-25T22:05:26Z | [
"python",
"sqlalchemy",
"persistence"
] |
Structure accessible by attribute name or index options | 2,512,671 | <p>I am very new to Python, and trying to figure out how to create an object that has values that are accessible either by attribute name, or by index. For example, the way os.stat() returns a stat_result or pwd.getpwnam() returns a struct_passwd. </p>
<p>In trying to figure it out, I've only come across C implementa... | 7 | 2010-03-25T01:55:29Z | 2,512,690 | <p>Python 2.6 introduced <a href="http://docs.python.org/library/collections.html#collections.namedtuple">collections.namedtuple</a> to make this easy. With older Python versions you can use the <a href="http://code.activestate.com/recipes/500261/">named tuple recipe</a>.</p>
<p>Quoting directly from the docs:</p>
<p... | 5 | 2010-03-25T02:01:22Z | [
"python",
"data-structures",
"namedtuple"
] |
Structure accessible by attribute name or index options | 2,512,671 | <p>I am very new to Python, and trying to figure out how to create an object that has values that are accessible either by attribute name, or by index. For example, the way os.stat() returns a stat_result or pwd.getpwnam() returns a struct_passwd. </p>
<p>In trying to figure it out, I've only come across C implementa... | 7 | 2010-03-25T01:55:29Z | 2,512,811 | <blockquote>
<p>an object that has values that are accessible either by attribute name, or by index</p>
</blockquote>
<p>I'm not sure what you're finding hard about this.</p>
<p>A collection accessible by index implements <code>__getitem__</code>.</p>
<p>A collection accessible by names implements <code>__getattr_... | 0 | 2010-03-25T02:54:57Z | [
"python",
"data-structures",
"namedtuple"
] |
Structure accessible by attribute name or index options | 2,512,671 | <p>I am very new to Python, and trying to figure out how to create an object that has values that are accessible either by attribute name, or by index. For example, the way os.stat() returns a stat_result or pwd.getpwnam() returns a struct_passwd. </p>
<p>In trying to figure it out, I've only come across C implementa... | 7 | 2010-03-25T01:55:29Z | 2,513,463 | <p>You can't use the same implementation as the result object of os.stat() and others. However Python 2.6 has a new factory function that creates a similar datatype called named tuple. A named tuple is a tuple whose slots can also be addressed by name. The named tuple should not require any more memory, according to th... | 3 | 2010-03-25T06:21:57Z | [
"python",
"data-structures",
"namedtuple"
] |
XML document being parsed as single element instead of sequence of nodes | 2,512,702 | <p>Given xml that looks like this:</p>
<pre><code><Store>
<foo>
<book>
<isbn>123456</isbn>
</book>
<title>XYZ</title>
<checkout>no</checkout>
</foo>
<bar>
<book>
<isbn>7890</isbn>
</book>
<title>XYZ2</title>
<... | 0 | 2010-03-25T02:07:28Z | 2,512,804 | <p>An XML document always has a single root element. If you don't care about the root element, just ignore it and look at its children instead!</p>
<p>For example, using the more modern element-tree (but minidom offers similar possibilities in this respect):</p>
<pre><code>try:
import xml.etree.cElementTree as et
... | 2 | 2010-03-25T02:48:50Z | [
"python",
"xml",
"minidom"
] |
XML document being parsed as single element instead of sequence of nodes | 2,512,702 | <p>Given xml that looks like this:</p>
<pre><code><Store>
<foo>
<book>
<isbn>123456</isbn>
</book>
<title>XYZ</title>
<checkout>no</checkout>
</foo>
<bar>
<book>
<isbn>7890</isbn>
</book>
<title>XYZ2</title>
<... | 0 | 2010-03-25T02:07:28Z | 2,512,972 | <p><code>xmldoc</code> is a parsed XML object. <code>toxml()</code> asks it to convert itself back to a string of XML text again. Explore a little further:</p>
<pre><code>>>> xmldoc.childNodes
[<DOM Element: Store at 0x212b788>]
>>> xmldoc.childNodes[0].childNodes
[<DOM Text node "u'\n'"&g... | 0 | 2010-03-25T03:52:23Z | [
"python",
"xml",
"minidom"
] |
Is this the correct way to convert a UTC datetime string into localtime? | 2,512,854 | <p>Is this the correct way to convert a UTC string into local time allowing for daylight savings? It looks ok to me but you never know :)</p>
<pre><code>import time
UTC_STRING = "2010-03-25 02:00:00"
stamp = time.mktime(time.strptime(UTC_STRING,"%Y-%m-%d %H:%M:%S"))
stamp -= time.timezone
now = time.localtime()
if n... | 1 | 2010-03-25T03:15:01Z | 2,512,917 | <p>timezone related calculations are not trivial and there are already good libraries available e.g. use <a href="http://pytz.sourceforge.net/">pytz</a>, using that you will be able to convert from any timezone to any other timezone with confidence. usage is as simple as this</p>
<pre><code>>>> warsaw = pytz.... | 5 | 2010-03-25T03:32:13Z | [
"python",
"time"
] |
Examples of use for PickledObjectField (django-picklefield)? | 2,513,018 | <p>surfing on the web, reading about <a href="http://blog.apps.chicagotribune.com/2010/02/26/best-practices/" rel="nofollow">django dev best practices</a> points to use <a href="http://github.com/shrubberysoft/django-picklefield/tree/master/src/" rel="nofollow">pickled model fields</a> with extreme caution.</p>
<p>But... | 1 | 2010-03-25T04:16:10Z | 2,513,044 | <p>You would use it to store... <a href="http://docs.python.org/library/pickle.html" rel="nofollow">almost-arbitrary Python objects</a>. In general there's little reason to use it; JSON is safer and more portable.</p>
| 3 | 2010-03-25T04:23:23Z | [
"python",
"django"
] |
Examples of use for PickledObjectField (django-picklefield)? | 2,513,018 | <p>surfing on the web, reading about <a href="http://blog.apps.chicagotribune.com/2010/02/26/best-practices/" rel="nofollow">django dev best practices</a> points to use <a href="http://github.com/shrubberysoft/django-picklefield/tree/master/src/" rel="nofollow">pickled model fields</a> with extreme caution.</p>
<p>But... | 1 | 2010-03-25T04:16:10Z | 2,514,056 | <p>You can definitely substitute a PickledObjectField with JSON and some extra logic to create an object out of the JSON. At the end of the day, your use case, when considering to use a PickledObjectField or JSON+logic, is serializing a Python object into your database. If you can trust the data in the Python object, a... | 3 | 2010-03-25T08:47:33Z | [
"python",
"django"
] |
Examples of use for PickledObjectField (django-picklefield)? | 2,513,018 | <p>surfing on the web, reading about <a href="http://blog.apps.chicagotribune.com/2010/02/26/best-practices/" rel="nofollow">django dev best practices</a> points to use <a href="http://github.com/shrubberysoft/django-picklefield/tree/master/src/" rel="nofollow">pickled model fields</a> with extreme caution.</p>
<p>But... | 1 | 2010-03-25T04:16:10Z | 2,515,116 | <p>We have a system of social-networks "backends" which do some generic stuff like "post message", "get status", "get friends" etc. The link between each backend class and user is django model, which keeps user, backend name and credentials. Now imagine how many auth systems are there: oauth, plain passwords, facebook'... | 3 | 2010-03-25T11:47:07Z | [
"python",
"django"
] |
Examples of use for PickledObjectField (django-picklefield)? | 2,513,018 | <p>surfing on the web, reading about <a href="http://blog.apps.chicagotribune.com/2010/02/26/best-practices/" rel="nofollow">django dev best practices</a> points to use <a href="http://github.com/shrubberysoft/django-picklefield/tree/master/src/" rel="nofollow">pickled model fields</a> with extreme caution.</p>
<p>But... | 1 | 2010-03-25T04:16:10Z | 32,024,991 | <p>The problems to be solved are the <strong>efficiency</strong> and the <strong>convenience</strong> of defining and handling a <strong>complex object consisting of many parts</strong>.</p>
<p>You can turn each part type into a Model and connect them via ForeignKeys.
Or you can turn each part type into a class, dicti... | 2 | 2015-08-15T13:04:30Z | [
"python",
"django"
] |
Encoding gives "'ascii' codec can't encode character ⦠ordinal not in range(128)" | 2,513,027 | <p>I am working through the Django RSS reader project <a href="http://code.djangoproject.com/browser/djangoproject.com/django_website/apps/aggregator/bin/update_feeds.py">here</a>. </p>
<p>The RSS feed will read something like "OKLAHOMA CITY (AP) â James Harden let". The RSS feed's encoding reads encoding="UTF-8" ... | 13 | 2010-03-25T04:19:23Z | 2,513,049 | <p><a href="https://docs.djangoproject.com/en/dev/ref/unicode/#conversion-functions" rel="nofollow">Django provides a couple of useful functions for converting back and forth between Unicode and bytestrings:</a></p>
<blockquote>
<p>from django.utils.encoding import smart_unicode, smart_str</p>
</blockquote>
| 4 | 2010-03-25T04:24:12Z | [
"python",
"django",
"unicode",
"character-encoding"
] |
Encoding gives "'ascii' codec can't encode character ⦠ordinal not in range(128)" | 2,513,027 | <p>I am working through the Django RSS reader project <a href="http://code.djangoproject.com/browser/djangoproject.com/django_website/apps/aggregator/bin/update_feeds.py">here</a>. </p>
<p>The RSS feed will read something like "OKLAHOMA CITY (AP) â James Harden let". The RSS feed's encoding reads encoding="UTF-8" ... | 13 | 2010-03-25T04:19:23Z | 8,684,956 | <p>If the data that you are receiving is, in fact, encoded in UTF-8, then it should be a sequence of bytes -- a Python 'str' object, in Python 2.X</p>
<p>You can verify this with an assertion:</p>
<pre><code>assert isinstance(content, str)
</code></pre>
<p>Once you know that that's true, you can move to the actual e... | 11 | 2011-12-30T23:14:10Z | [
"python",
"django",
"unicode",
"character-encoding"
] |
Encoding gives "'ascii' codec can't encode character ⦠ordinal not in range(128)" | 2,513,027 | <p>I am working through the Django RSS reader project <a href="http://code.djangoproject.com/browser/djangoproject.com/django_website/apps/aggregator/bin/update_feeds.py">here</a>. </p>
<p>The RSS feed will read something like "OKLAHOMA CITY (AP) â James Harden let". The RSS feed's encoding reads encoding="UTF-8" ... | 13 | 2010-03-25T04:19:23Z | 12,310,966 | <p>I encountered this error during a write of a file name with zip file. The following failed</p>
<pre><code>ZipFile.write(root+'/%s'%file, newRoot + '/%s'%file)
</code></pre>
<p>and the following worked</p>
<pre><code>ZipFile.write(str(root+'/%s'%file), str(newRoot + '/%s'%file))
</code></pre>
| 0 | 2012-09-07T02:33:20Z | [
"python",
"django",
"unicode",
"character-encoding"
] |
Django debug error | 2,513,237 | <p>I have the following in my model:</p>
<pre><code> class info(models.Model):
add = models.CharField(max_length=255)
name = models.CharField(max_length=255)
</code></pre>
<p>An in the views when i say
info_l = info.objects.filter(id=1)
logging.debug(info_l.name)</p>
<p>i get an... | 0 | 2010-03-25T05:22:23Z | 2,513,280 | <p><strong>1. Selecting Single Items</strong></p>
<p>It looks like you're trying to get a single object. Using <code>filter</code> will return a <code>QuerySet</code> object (as is happening in your code), which behaves more like a list (and, as you've noticed, lacks the <code>name</code> attribute).</p>
<p>You hav... | 2 | 2010-03-25T05:33:08Z | [
"python",
"django",
"django-views"
] |
Once I know the basic elements and syntax of Python, what should I do? | 2,513,260 | <p>Well, I have read several user guides and watched dozens and dozens of video tutorials on how to program with Python, and feel pretty confident about writing simple applications for it. My main point in my question is, where would I be able to learn more advanced programming knowledge about Python?</p>
| 2 | 2010-03-25T05:27:04Z | 2,513,277 | <p>How simple of applications are you making? Have you gone through the exercises in <a href="http://code.google.com/edu/languages/google-python-class/introduction.html" rel="nofollow">Google's Python Class</a>? I highly recommend going through those. If you really know what you are doing, you should breeze through the... | 3 | 2010-03-25T05:31:39Z | [
"python",
"wxpython"
] |
Once I know the basic elements and syntax of Python, what should I do? | 2,513,260 | <p>Well, I have read several user guides and watched dozens and dozens of video tutorials on how to program with Python, and feel pretty confident about writing simple applications for it. My main point in my question is, where would I be able to learn more advanced programming knowledge about Python?</p>
| 2 | 2010-03-25T05:27:04Z | 2,513,288 | <p>You could try something like <a href="http://books.google.ca/books?id=Q0s6Vgb98CQC&printsec=frontcover&dq=python+cookbook&source=bl&ots=hc337aSfpF&sig=eEGyhjju6hOtMuDHczJF3J3rqnI&hl=en&ei=TfWqS7ntL8uVtgf_9qDIBQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CAkQ6AEwAA" re... | 2 | 2010-03-25T05:34:18Z | [
"python",
"wxpython"
] |
Once I know the basic elements and syntax of Python, what should I do? | 2,513,260 | <p>Well, I have read several user guides and watched dozens and dozens of video tutorials on how to program with Python, and feel pretty confident about writing simple applications for it. My main point in my question is, where would I be able to learn more advanced programming knowledge about Python?</p>
| 2 | 2010-03-25T05:27:04Z | 2,513,304 | <p>You have given yourself an answer:</p>
<blockquote>
<p>and feel pretty confident about
writing simple applications for it</p>
</blockquote>
<p>go ahead and write more complex applications! </p>
<p>The issue here is that you do not feel challenged, and you assume that you are done with your basic learning. Jus... | 2 | 2010-03-25T05:40:13Z | [
"python",
"wxpython"
] |
Once I know the basic elements and syntax of Python, what should I do? | 2,513,260 | <p>Well, I have read several user guides and watched dozens and dozens of video tutorials on how to program with Python, and feel pretty confident about writing simple applications for it. My main point in my question is, where would I be able to learn more advanced programming knowledge about Python?</p>
| 2 | 2010-03-25T05:27:04Z | 2,513,730 | <p>If you like puzzles, you might check out <a href="http://projecteuler.net/" rel="nofollow">Project Euler</a>. It has a variety of interesting puzzles (some easy, some much harder) that take some logic and programming to solve. (Often you have to find a clever way to solve them, since brute-force methods will take ... | 0 | 2010-03-25T07:31:33Z | [
"python",
"wxpython"
] |
Once I know the basic elements and syntax of Python, what should I do? | 2,513,260 | <p>Well, I have read several user guides and watched dozens and dozens of video tutorials on how to program with Python, and feel pretty confident about writing simple applications for it. My main point in my question is, where would I be able to learn more advanced programming knowledge about Python?</p>
| 2 | 2010-03-25T05:27:04Z | 2,561,525 | <p>my favorite way in learning python is ( learning through projects ). <br>
put yourself a goal , like a software for example ( 6 years ago when i started to learn python i picked a messenger . so i had to read more about sockets, network programming , and interfaces libraries ) . start with it , look for examples an... | 1 | 2010-04-01T15:26:15Z | [
"python",
"wxpython"
] |
redirect prints to log file | 2,513,479 | <p>Okay. I have completed my first python program.It has around 1000 lines of code.
During development I placed plenty of <code>print</code> statements before running a command using <code>os.system()</code>
say something like,</p>
<pre><code>print "running command",cmd
os.system(cmd)
</code></pre>
<p>Now I have comp... | 13 | 2010-03-25T06:25:21Z | 2,513,487 | <p>Putting your own file-like in <code>sys.stdout</code> will let you capture the text output via <code>print</code>.</p>
| 1 | 2010-03-25T06:27:15Z | [
"python",
"logging",
"printing"
] |
redirect prints to log file | 2,513,479 | <p>Okay. I have completed my first python program.It has around 1000 lines of code.
During development I placed plenty of <code>print</code> statements before running a command using <code>os.system()</code>
say something like,</p>
<pre><code>print "running command",cmd
os.system(cmd)
</code></pre>
<p>Now I have comp... | 13 | 2010-03-25T06:25:21Z | 2,513,489 | <p>You should take a look at <a href="http://docs.python.org/library/logging.html">python logging module</a></p>
<hr>
<p>EDIT: Sample code:</p>
<pre><code>import logging
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, filename="logfile", filemode="a+",
format="%(ascti... | 21 | 2010-03-25T06:27:40Z | [
"python",
"logging",
"printing"
] |
redirect prints to log file | 2,513,479 | <p>Okay. I have completed my first python program.It has around 1000 lines of code.
During development I placed plenty of <code>print</code> statements before running a command using <code>os.system()</code>
say something like,</p>
<pre><code>print "running command",cmd
os.system(cmd)
</code></pre>
<p>Now I have comp... | 13 | 2010-03-25T06:25:21Z | 2,513,511 | <p>Python lets you capture and assign sys.stdout - as mentioned - to do this:</p>
<pre><code>old_stdout = sys.stdout
log_file = open("message.log","w")
sys.stdout = log_file
print "this will be written to message.log"
sys.stdout = old_stdout
log_file.close()
</code></pre>
| 19 | 2010-03-25T06:35:45Z | [
"python",
"logging",
"printing"
] |
redirect prints to log file | 2,513,479 | <p>Okay. I have completed my first python program.It has around 1000 lines of code.
During development I placed plenty of <code>print</code> statements before running a command using <code>os.system()</code>
say something like,</p>
<pre><code>print "running command",cmd
os.system(cmd)
</code></pre>
<p>Now I have comp... | 13 | 2010-03-25T06:25:21Z | 2,513,590 | <p>You can redirect replace sys.stdout with any object which has same interface as sys.stdout, in that object's write you can print to terminal and to file too. e.g. see this recipe <a href="http://code.activestate.com/recipes/119404-print-hook/" rel="nofollow">http://code.activestate.com/recipes/119404-print-hook/</a>... | 1 | 2010-03-25T06:56:59Z | [
"python",
"logging",
"printing"
] |
redirect prints to log file | 2,513,479 | <p>Okay. I have completed my first python program.It has around 1000 lines of code.
During development I placed plenty of <code>print</code> statements before running a command using <code>os.system()</code>
say something like,</p>
<pre><code>print "running command",cmd
os.system(cmd)
</code></pre>
<p>Now I have comp... | 13 | 2010-03-25T06:25:21Z | 2,513,766 | <p>A simple way to redirect stdout and stderr using the logging module is here:
<a href="http://stackoverflow.com/questions/616645/how-do-i-duplicate-sys-stdout-to-a-log-file-in-python/2216517#2216517">http://stackoverflow.com/questions/616645/how-do-i-duplicate-sys-stdout-to-a-log-file-in-python/2216517#2216517</a></p... | 2 | 2010-03-25T07:41:37Z | [
"python",
"logging",
"printing"
] |
redirect prints to log file | 2,513,479 | <p>Okay. I have completed my first python program.It has around 1000 lines of code.
During development I placed plenty of <code>print</code> statements before running a command using <code>os.system()</code>
say something like,</p>
<pre><code>print "running command",cmd
os.system(cmd)
</code></pre>
<p>Now I have comp... | 13 | 2010-03-25T06:25:21Z | 2,516,480 | <ul>
<li><p>Next time, you'll be happier if instead of using <code>print</code> statements at all you use the <code>logging</code> module from the start. It provides the control you want and you can have it write to stdout while that's still where you want it.</p></li>
<li><p>Many people here have suggested redirecting... | 7 | 2010-03-25T14:49:08Z | [
"python",
"logging",
"printing"
] |
why python find not working | 2,513,606 | <p>i am using <em>python 2.5.2</em>. The following code not working.</p>
<pre><code>def findValue(self, text, findText):
index = text.find(findText)
print index
</code></pre>
<p>Although the <code>findText</code> is present in <code>text</code>, but it still returns <code>None</code>.</p>
<p>I have printed... | 2 | 2010-03-25T06:59:46Z | 2,513,619 | <p>You aren't returning a value from your function, you are only printing it. This means that the return value for the function will be None.</p>
<p>Try adding <code>return index</code>at the end of your code.</p>
<pre><code>def myfind(self, text, findText):
index = text.find(findText)
return index
</code><... | 5 | 2010-03-25T07:02:51Z | [
"python",
"find"
] |
why python find not working | 2,513,606 | <p>i am using <em>python 2.5.2</em>. The following code not working.</p>
<pre><code>def findValue(self, text, findText):
index = text.find(findText)
print index
</code></pre>
<p>Although the <code>findText</code> is present in <code>text</code>, but it still returns <code>None</code>.</p>
<p>I have printed... | 2 | 2010-03-25T06:59:46Z | 2,513,626 | <p>Python doesn't automatically return the last variable, you need to explicitly use <code>return index</code></p>
<p>And If the <code>.find</code> is failing, it should return <code>-1</code> instead of <code>None</code>, So most probably, problem is in your return part, not in the <code>.find</code></p>
| 1 | 2010-03-25T07:04:56Z | [
"python",
"find"
] |
why python find not working | 2,513,606 | <p>i am using <em>python 2.5.2</em>. The following code not working.</p>
<pre><code>def findValue(self, text, findText):
index = text.find(findText)
print index
</code></pre>
<p>Although the <code>findText</code> is present in <code>text</code>, but it still returns <code>None</code>.</p>
<p>I have printed... | 2 | 2010-03-25T06:59:46Z | 2,529,152 | <p>I have fixed the issue.</p>
<p>The problem was i am calling code like</p>
<pre><code>for i in arr:
self.findValue(i,"someText")
</code></pre>
<p>As type of <code>i</code> is instance so this does not work. I have just changed it to:</p>
<pre><code>self.findValue(str(i),"someText")
</code></pre>
| 0 | 2010-03-27T11:50:45Z | [
"python",
"find"
] |
How to copy matplotlib figure? | 2,513,786 | <p>I have <code>FigureCanvasWxAgg</code> instance with a figure displayed on a frame. If user clicks on the canvas another frame with a new <code>FigureCanvasWxAgg</code> containing the same figure will be shown. By now closing the new frame can result in destroying the C++ part of the figure so that it won't be availa... | 8 | 2010-03-25T07:45:53Z | 3,120,753 | <p>I'm not familiar with the inner workings, but could easily imagine how disposing of a frame damages the figure data. Is it expensive to draw? Otherwise I'd take the somewhat chickenish approach of simply redrawing it ;)</p>
| 1 | 2010-06-25T19:07:47Z | [
"python",
"wxpython",
"copy",
"matplotlib"
] |
Loop over a file and write the next line if a condition is met | 2,513,847 | <p>Having a hard time fixing this or finding any good hints about it.
I'm trying to loop over one file, modify each line slightly, and then loop over a different file. If the line in the second file starts with the line from the first then the <em>following</em> line in the second file should be written to a third fil... | 2 | 2010-03-25T08:02:14Z | 2,513,910 | <p>After the first line in the <code>ids.txt</code> file has been processed, the file <code>seqres.txt</code> has been exhausted. There is something wrong with the nesting of your loops. Also, you're modifying the iterator inside the <code>for line in g</code> loop. Not a good idea. </p>
<p>If you really want to appen... | 0 | 2010-03-25T08:19:31Z | [
"python",
"string",
"file-io",
"iterator"
] |
Loop over a file and write the next line if a condition is met | 2,513,847 | <p>Having a hard time fixing this or finding any good hints about it.
I'm trying to loop over one file, modify each line slightly, and then loop over a different file. If the line in the second file starts with the line from the first then the <em>following</em> line in the second file should be written to a third fil... | 2 | 2010-03-25T08:02:14Z | 2,513,928 | <p>The problem is that you are only looping through file g once - after you have read through it the first time the file index position is left at the end of the file, so any further reads will fail with EOF. You would need to reopen g every time round the loop.</p>
<p>However this will be massively inefficient - you... | 1 | 2010-03-25T08:23:11Z | [
"python",
"string",
"file-io",
"iterator"
] |
Loop over a file and write the next line if a condition is met | 2,513,847 | <p>Having a hard time fixing this or finding any good hints about it.
I'm trying to loop over one file, modify each line slightly, and then loop over a different file. If the line in the second file starts with the line from the first then the <em>following</em> line in the second file should be written to a third fil... | 2 | 2010-03-25T08:02:14Z | 2,514,040 | <p>Here's a mostly flattened implementation. Depending on how many hits you're going to get for each ID, and how many entries there are in 'seqres' you could redesign it.</p>
<pre><code># Extract the IDs in the desired format and cache them
ids = [ x.lower()[0:4]+'_'+x[4] for x in open('ids.txt','rU')]
ids = set(ids)
... | 2 | 2010-03-25T08:43:13Z | [
"python",
"string",
"file-io",
"iterator"
] |
Loop over a file and write the next line if a condition is met | 2,513,847 | <p>Having a hard time fixing this or finding any good hints about it.
I'm trying to loop over one file, modify each line slightly, and then loop over a different file. If the line in the second file starts with the line from the first then the <em>following</em> line in the second file should be written to a third fil... | 2 | 2010-03-25T08:02:14Z | 2,515,239 | <p>For speed, you really want to avoid looping over the same file multiple times. This means you've turned into an O(N*M) algorithm, when you could be a using an O(N+M) one.</p>
<p>To achieve this, read your list of ids into a fast lookup structure, like a set. Since there are only 4600 this in-memory form shouldn't... | 1 | 2010-03-25T12:04:09Z | [
"python",
"string",
"file-io",
"iterator"
] |
Loop over a file and write the next line if a condition is met | 2,513,847 | <p>Having a hard time fixing this or finding any good hints about it.
I'm trying to loop over one file, modify each line slightly, and then loop over a different file. If the line in the second file starts with the line from the first then the <em>following</em> line in the second file should be written to a third fil... | 2 | 2010-03-25T08:02:14Z | 2,517,250 | <p>I think there is still progress to be made from the code you declare as final. You can make the result a little less nested and avoid a couple sort of silly things.</p>
<pre><code>from contextlib import nested
from itertools import tee, izip
# Stole pairwise recipe from the itertools documentation
def pairwise(ite... | 1 | 2010-03-25T16:14:15Z | [
"python",
"string",
"file-io",
"iterator"
] |
How can I programmatically determine (in Python) when someone connects into my windows 7 machine via RDP? | 2,514,450 | <p>This doesn't need to be a real time solution, but are there some log files or system messages that could be read to identify periods of time where someone was connected via RDP to a Windows 7 machine?</p>
<p>I'm building a watchdog script for a computer which will be deployed in a remote place and would like to add... | 2 | 2010-03-25T09:53:14Z | 2,514,528 | <p>Run with os.system or subprocess module</p>
<pre><code>C:\> netstat -n | find ":3389 "
TCP x.x.x.x:3389 y.y.y.y:zzz ESTABLISHED
</code></pre>
<p>Where, x.x.x.x is own IP and y.y.y.y is remote IP, and zzz is remote port.</p>
| 3 | 2010-03-25T10:03:26Z | [
"python",
"connection",
"logging",
"detection",
"rdp"
] |
How can I programmatically determine (in Python) when someone connects into my windows 7 machine via RDP? | 2,514,450 | <p>This doesn't need to be a real time solution, but are there some log files or system messages that could be read to identify periods of time where someone was connected via RDP to a Windows 7 machine?</p>
<p>I'm building a watchdog script for a computer which will be deployed in a remote place and would like to add... | 2 | 2010-03-25T09:53:14Z | 2,514,586 | <p>If you look at the <code>Event viewer</code> and the tab <code>Security</code> you can find when people login/logout there. Not sure if it gets logged if the session is just disconnected though.</p>
<p>This seems to be a Python library to access the event log: <a href="http://timgolden.me.uk/python/winsys/event_log... | 1 | 2010-03-25T10:13:15Z | [
"python",
"connection",
"logging",
"detection",
"rdp"
] |
how to count all distinct records in many-to-many relations in django ORM? | 2,514,910 | <pre><code>class Project(models.Model):
categories = models.ManyToManyField(Category)
class Category(models.Model):
name = models.CharField()
</code></pre>
<p>now, i make some queryset:</p>
<pre><code>query = Project.objects.filter(id__in=[1,2,3,4])
</code></pre>
<p>and i like to get list of all distinct categori... | 1 | 2010-03-25T11:12:24Z | 2,514,953 | <pre><code>Category.objects.filter(project__in=query).annotate(Count('project'))
</code></pre>
| 0 | 2010-03-25T11:18:56Z | [
"python",
"django",
"orm"
] |
Generate a table of contents from HTML with Python | 2,514,931 | <p>I'm trying to generate a table of contents from a block of HTML (not a complete file - just content) based on its <code><h2></code> and <code><h3></code> tags.</p>
<p>My plan so far was to:</p>
<ul>
<li><p>Extract a list of headers using <code>beautifulsoup</code></p></li>
<li><p>Use a regex on the con... | 5 | 2010-03-25T11:16:13Z | 2,514,985 | <p>Use <a href="http://codespeak.net/lxml/lxmlhtml.html" rel="nofollow"><code>lxml.html</code></a>.</p>
<ul>
<li>It can <a href="http://codespeak.net/lxml/lxmlhtml.html#really-broken-pages" rel="nofollow">deal with invalid html</a> just fine.</li>
<li>It is <a href="http://codespeak.net/lxml/performance.html" rel="nof... | 1 | 2010-03-25T11:24:09Z | [
"python",
"html",
"beautifulsoup",
"tableofcontents"
] |
Generate a table of contents from HTML with Python | 2,514,931 | <p>I'm trying to generate a table of contents from a block of HTML (not a complete file - just content) based on its <code><h2></code> and <code><h3></code> tags.</p>
<p>My plan so far was to:</p>
<ul>
<li><p>Extract a list of headers using <code>beautifulsoup</code></p></li>
<li><p>Use a regex on the con... | 5 | 2010-03-25T11:16:13Z | 2,515,273 | <p><a href="http://stackoverflow.com/questions/2210265/how-do-i-generate-a-table-of-contents-for-html-text-in-python">How do I generate a table of contents for HTML text in Python?</a></p>
<p>But I think you are on the right track and reinventing the wheel will be fun.</p>
| 0 | 2010-03-25T12:08:52Z | [
"python",
"html",
"beautifulsoup",
"tableofcontents"
] |
Generate a table of contents from HTML with Python | 2,514,931 | <p>I'm trying to generate a table of contents from a block of HTML (not a complete file - just content) based on its <code><h2></code> and <code><h3></code> tags.</p>
<p>My plan so far was to:</p>
<ul>
<li><p>Extract a list of headers using <code>beautifulsoup</code></p></li>
<li><p>Use a regex on the con... | 5 | 2010-03-25T11:16:13Z | 2,515,508 | <p>Some quickly hacked ugly piece of code:</p>
<pre><code>soup = BeautifulSoup(html)
toc = []
header_id = 1
current_list = toc
previous_tag = None
for header in soup.findAll(['h2', 'h3']):
header['id'] = header_id
if previous_tag == 'h2' and header.name == 'h3':
current_list = []
elif previous_t... | 2 | 2010-03-25T12:43:38Z | [
"python",
"html",
"beautifulsoup",
"tableofcontents"
] |
How to scroll text in Python/Curses subwindow? | 2,515,244 | <p>In my Python script which uses Curses, I have a subwin to which some text is assigned. Because the text length may be longer than the window size, the text should be scrollable.</p>
<p>It doesn't seem that there is any CSS-"overflow" like attribute for Curses windows. The Python/Curses docs are also rather cryptic ... | 14 | 2010-03-25T12:04:53Z | 2,515,827 | <p>Set the window.scrollok(True).</p>
<p><a href="http://docs.python.org/library/curses.html#curses.window.scrollok" rel="nofollow">Documentation</a></p>
| 0 | 2010-03-25T13:23:21Z | [
"python",
"scroll",
"curses"
] |
How to scroll text in Python/Curses subwindow? | 2,515,244 | <p>In my Python script which uses Curses, I have a subwin to which some text is assigned. Because the text length may be longer than the window size, the text should be scrollable.</p>
<p>It doesn't seem that there is any CSS-"overflow" like attribute for Curses windows. The Python/Curses docs are also rather cryptic ... | 14 | 2010-03-25T12:04:53Z | 2,523,020 | <p>OK with window.scroll it was too complicated to move the content of the window. Instead, curses.newpad did it for me.</p>
<p>Create a pad:</p>
<pre><code>mypad = curses.newpad(40,60)
mypad_pos = 0
mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
</code></pre>
<p>Then you can scroll by increasing/decreasing mypad_pos dep... | 18 | 2010-03-26T11:55:42Z | [
"python",
"scroll",
"curses"
] |
How to scroll text in Python/Curses subwindow? | 2,515,244 | <p>In my Python script which uses Curses, I have a subwin to which some text is assigned. Because the text length may be longer than the window size, the text should be scrollable.</p>
<p>It doesn't seem that there is any CSS-"overflow" like attribute for Curses windows. The Python/Curses docs are also rather cryptic ... | 14 | 2010-03-25T12:04:53Z | 16,521,573 | <p>Right, I was a bit confused on how to utilize pads (in order to scroll text), and still couldn't figure it out after reading this post; especially since I wanted to use it in a context of the content being an existing "array of lines". So I prepared a small example, that shows similarities (and differences) between ... | 2 | 2013-05-13T12:01:07Z | [
"python",
"scroll",
"curses"
] |
How to scroll text in Python/Curses subwindow? | 2,515,244 | <p>In my Python script which uses Curses, I have a subwin to which some text is assigned. Because the text length may be longer than the window size, the text should be scrollable.</p>
<p>It doesn't seem that there is any CSS-"overflow" like attribute for Curses windows. The Python/Curses docs are also rather cryptic ... | 14 | 2010-03-25T12:04:53Z | 30,828,996 | <p>This is the answer of this question:
<a href="http://stackoverflow.com/questions/30828804/how-to-make-a-scrolling-menu-in-python-curses">How to make a scrolling menu in python-curses</a></p>
<p>This code allows you to create a little scrolling menu in a box from a list of strings. <br>
You can also use this code ge... | 0 | 2015-06-14T11:50:13Z | [
"python",
"scroll",
"curses"
] |
How to scroll text in Python/Curses subwindow? | 2,515,244 | <p>In my Python script which uses Curses, I have a subwin to which some text is assigned. Because the text length may be longer than the window size, the text should be scrollable.</p>
<p>It doesn't seem that there is any CSS-"overflow" like attribute for Curses windows. The Python/Curses docs are also rather cryptic ... | 14 | 2010-03-25T12:04:53Z | 34,573,955 | <p>I wanted to use a scrolling pad to display content of some large text files but this didn't work well because texts can have line breaks and it was pretty hard to figure out how many characters to display at a time to fit the good number of columns and rows.</p>
<p>So I decided to first split my text files in lines... | 0 | 2016-01-03T06:25:44Z | [
"python",
"scroll",
"curses"
] |
How do I create new xml from ElementTree? | 2,515,253 | <p>Bit of a beginner question here:</p>
<p>Say I have a block of xml:</p>
<pre><code><root>
<district>
<house><room><door/><room></house>
</district>
<district>
<street>
<house>and so on</house>
</street>
</code></pre>
<p>etc.<... | 0 | 2010-03-25T12:05:59Z | 2,515,619 | <p>You can call <code>findall</code> on the elements returned by the first <code>findall</code>:</p>
<pre><code>>>> doc = """<root>
... <district>
... <house><room><door/></room></house>
... </district>
... <district>
... <street>
... <h... | 2 | 2010-03-25T12:57:14Z | [
"python",
"xml",
"elementtree"
] |
Injecting variables into the caller's scope? | 2,515,450 | <p>Can I define a function which, when called, inserts new locals into the caller's scope? I have a feeling that passing the caller's <em>locals()</em> into the function might work, but is there a way to do what I want <em>without</em> having to do this?</p>
| 15 | 2010-03-25T12:37:44Z | 2,516,425 | <p>By Python's rules, you cannot alter your caller's <code>locals</code>; in the current implementations, if you try (e.g. with the black magic Anurag suggests) you will not get an exception (though I'd like to add that error check to some future version), but it will be essentially inoperative if your caller is a func... | 7 | 2010-03-25T14:43:45Z | [
"python",
"variables",
"scope"
] |
Injecting variables into the caller's scope? | 2,515,450 | <p>Can I define a function which, when called, inserts new locals into the caller's scope? I have a feeling that passing the caller's <em>locals()</em> into the function might work, but is there a way to do what I want <em>without</em> having to do this?</p>
| 15 | 2010-03-25T12:37:44Z | 7,028,618 | <p>Check out the <a href="http://docs.python.org/library/inspect.html">inspect module</a>, it is used by <a href="https://bitbucket.org/jab/minimock/src/b7acbfeadbd2/minimock.py#cl-169">minimock</a> to mock the caller's scope.</p>
<p>This code ought to do what you want exactly:</p>
<pre><code>import inspect
def mess_... | 13 | 2011-08-11T15:29:04Z | [
"python",
"variables",
"scope"
] |
Changing python interpreter for emacs | 2,515,754 | <p>Emacs uses an older version of python(2.3) i have for the default python mode, is there a way for me to tell emacs to use the newer version that i have in my home directory?</p>
<p>btw I'm using a red hat distro and dont have root privileges.</p>
| 9 | 2010-03-25T13:14:51Z | 2,515,952 | <h2>Via .emacs:</h2>
<p>Try to add to your <code>~/.emacs</code> file:</p>
<pre><code>(setq python-python-command "~/your/python/bin-dir/python")
</code></pre>
<p>or </p>
<h2>Via the shell environment:</h2>
<p>The python command that is run by Emacs is typically <code>python</code>, so you can try the simple appro... | 6 | 2010-03-25T13:38:46Z | [
"python",
"emacs"
] |
Changing python interpreter for emacs | 2,515,754 | <p>Emacs uses an older version of python(2.3) i have for the default python mode, is there a way for me to tell emacs to use the newer version that i have in my home directory?</p>
<p>btw I'm using a red hat distro and dont have root privileges.</p>
| 9 | 2010-03-25T13:14:51Z | 2,520,486 | <p>It is good habit to check <strong>customize-group</strong> of things you wanna tweak. Just do:</p>
<pre><code>M-x customize-group RET python RET
</code></pre>
<p>you've got now multiple options of which one should be interesting:</p>
<pre><code>Python Python Command
</code></pre>
<p>You can customize it there an... | 10 | 2010-03-26T00:46:42Z | [
"python",
"emacs"
] |
PRTime to datetime in Python | 2,515,782 | <p>Hey guys, I'm writing a script that is retrieving information from places.sqlite (history) and realized that it store the time in PRTime format. Is there a method available in python which could convert this date time or do i have to make it myself?</p>
| 3 | 2010-03-25T13:17:55Z | 2,515,851 | <p>there isn't any built-in method, but it does seem quite trivial to implement:</p>
<pre><code>>>> t = 1221842272303080
>>> t /= 1e6
>>> t
1221842272.30308
>>> import datetime
>>> datetime.datetime.fromtimestamp(t)
datetime.datetime(2008, 9, 19, 17, 37, 52, 303080)
</code>... | 1 | 2010-03-25T13:25:50Z | [
"python",
"datetime"
] |
PRTime to datetime in Python | 2,515,782 | <p>Hey guys, I'm writing a script that is retrieving information from places.sqlite (history) and realized that it store the time in PRTime format. Is there a method available in python which could convert this date time or do i have to make it myself?</p>
| 3 | 2010-03-25T13:17:55Z | 2,515,860 | <p>PRTime is the number of microseconds since 1-Jan-1970 (see <a href="https://developer.mozilla.org/en/PRTime" rel="nofollow">https://developer.mozilla.org/en/PRTime</a>) so just do this to get UTC time</p>
<pre><code>datetime.datetime(1970, 1, 1) + datetime.timedelta(microseconds=pr_time)
</code></pre>
<p>e.g.</p>
... | 3 | 2010-03-25T13:26:28Z | [
"python",
"datetime"
] |
Perl for a Python programmer | 2,515,814 | <p>I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it <a href="http://stackoverflow.com/questions/2283034/python-for-a-perl-programmer">the other way around</a>.</p>
<p>My main concern is not about the language itself (I think... | 18 | 2010-03-25T13:21:32Z | 2,515,881 | <p>One area where Perl is more "convenient" is using it for one liners. Python can be used to produced one liners, but often its "clunky" (or ugly). Note that Perl is renowned for its "terseness" or "short and concise", often at the expense of readability. So coming from Python, you have to learn to get used to it.</p>... | 15 | 2010-03-25T13:29:39Z | [
"python",
"perl"
] |
Perl for a Python programmer | 2,515,814 | <p>I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it <a href="http://stackoverflow.com/questions/2283034/python-for-a-perl-programmer">the other way around</a>.</p>
<p>My main concern is not about the language itself (I think... | 18 | 2010-03-25T13:21:32Z | 2,516,030 | <p>I think <a href="http://rads.stackoverflow.com/amzn/click/0596520107" rel="nofollow">Learning Perl</a> from O'Reilly Media is a pretty good way to get started with Perl, even if you are already proficient in Python.</p>
<p>Especialy if you want to get to know the one-liner stuff (and this is what Perl is REALLY goo... | 4 | 2010-03-25T13:47:23Z | [
"python",
"perl"
] |
Perl for a Python programmer | 2,515,814 | <p>I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it <a href="http://stackoverflow.com/questions/2283034/python-for-a-perl-programmer">the other way around</a>.</p>
<p>My main concern is not about the language itself (I think... | 18 | 2010-03-25T13:21:32Z | 2,516,511 | <p>For best practices, check out <a href="http://books.google.com/books?id=gJf9tI2mytIC&lpg=PP1&dq=perl%20best%20practices&pg=PP1#v=onepage&q=&f=false">Perl Best Practices</a> by Damian Conway. Not all of the recommended practices make sense, but most of them do.</p>
<p>The <a href="http://www.per... | 14 | 2010-03-25T14:51:42Z | [
"python",
"perl"
] |
Perl for a Python programmer | 2,515,814 | <p>I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it <a href="http://stackoverflow.com/questions/2283034/python-for-a-perl-programmer">the other way around</a>.</p>
<p>My main concern is not about the language itself (I think... | 18 | 2010-03-25T13:21:32Z | 2,516,877 | <ul>
<li><p>Have a look at <a href="http://moose.perl.org"><code>Moose</code></a>. Its a <em>state of the art</em> OO framework akin to <a href="http://en.wikipedia.org/wiki/Common_Lisp_Object_System"><code>CLOS</code></a> and what will be available in <a href="http://en.wikipedia.org/wiki/Perl_6"><code>Perl6</code></... | 11 | 2010-03-25T15:31:18Z | [
"python",
"perl"
] |
Perl for a Python programmer | 2,515,814 | <p>I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it <a href="http://stackoverflow.com/questions/2283034/python-for-a-perl-programmer">the other way around</a>.</p>
<p>My main concern is not about the language itself (I think... | 18 | 2010-03-25T13:21:32Z | 2,517,465 | <p><a href="http://rads.stackoverflow.com/amzn/click/0321496949" rel="nofollow">Effective Perl Programming</a> is mostly for people who know the basics of Perl's syntax but need to learn the idioms. We also cover similar stuff in our <a href="http://www.effectiveperlprogramming.com/" rel="nofollow">Effective Perler</a>... | 3 | 2010-03-25T16:39:35Z | [
"python",
"perl"
] |
Perl for a Python programmer | 2,515,814 | <p>I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it <a href="http://stackoverflow.com/questions/2283034/python-for-a-perl-programmer">the other way around</a>.</p>
<p>My main concern is not about the language itself (I think... | 18 | 2010-03-25T13:21:32Z | 2,517,767 | <h3><a href="http://www.perl.org/books/impatient-perl/" rel="nofollow">Impatient Perl</a></h3>
<p>One of my favorite books for people who want to learn it and then <em>get stuff done</em> is <a href="http://www.perl.org/books/impatient-perl/" rel="nofollow">Impatient Perl</a> by Greg London, a free netbook available f... | 3 | 2010-03-25T17:11:25Z | [
"python",
"perl"
] |
Get information about a function in python, looking at source code | 2,516,034 | <p>the following code comes from the matplotlib gallery:</p>
<pre><code>#!/usr/bin/env python
from pylab import *
x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
</code></pre>
<p>I am new to python, and would like to change the content ... | 0 | 2010-03-25T13:48:33Z | 2,516,072 | <p><code>array</code> appears to be a function/class in <code>pylab</code>. You could do <code>help(array)</code> to find out more - this relies on the presence of a proper docstring for <code>array</code>.</p>
<p><code>from module import *</code> is a problematic idiom in several ways precisely for the reason that it... | 0 | 2010-03-25T13:54:45Z | [
"python",
"numpy"
] |
Get information about a function in python, looking at source code | 2,516,034 | <p>the following code comes from the matplotlib gallery:</p>
<pre><code>#!/usr/bin/env python
from pylab import *
x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
</code></pre>
<p>I am new to python, and would like to change the content ... | 0 | 2010-03-25T13:48:33Z | 2,516,090 | <p>As to your 1. that's due to bad habits of the person giving you that program. It should have been:</p>
<pre><code>#!/usr/bin/env python
import pylab
x = pylab.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y = pylab.array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
help(pylab.array)
</code... | 2 | 2010-03-25T13:56:15Z | [
"python",
"numpy"
] |
Get information about a function in python, looking at source code | 2,516,034 | <p>the following code comes from the matplotlib gallery:</p>
<pre><code>#!/usr/bin/env python
from pylab import *
x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
</code></pre>
<p>I am new to python, and would like to change the content ... | 0 | 2010-03-25T13:48:33Z | 2,516,091 | <p>(1) Fire up the python console and use the dir() function on whatever object/class/variable you want to know more about. It'll print out all methods and properties of the object.</p>
<pre><code>>> import pylab
>> x = pylab.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
>> dir(x)
</code></p... | 1 | 2010-03-25T13:56:23Z | [
"python",
"numpy"
] |
Get information about a function in python, looking at source code | 2,516,034 | <p>the following code comes from the matplotlib gallery:</p>
<pre><code>#!/usr/bin/env python
from pylab import *
x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
</code></pre>
<p>I am new to python, and would like to change the content ... | 0 | 2010-03-25T13:48:33Z | 2,516,411 | <ul>
<li><p>Use the <code>help</code> function to find out what an object can do.</p>
<pre><code>import pylab
help(pylab.array)
</code></pre></li>
<li><p>"What library it belongs to" is a sort of funny question. You can easily know what module you are using it from if you refactor your code not to use <code>import *</... | 1 | 2010-03-25T14:42:02Z | [
"python",
"numpy"
] |
Get information about a function in python, looking at source code | 2,516,034 | <p>the following code comes from the matplotlib gallery:</p>
<pre><code>#!/usr/bin/env python
from pylab import *
x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
</code></pre>
<p>I am new to python, and would like to change the content ... | 0 | 2010-03-25T13:48:33Z | 2,517,819 | <p>Replying to question #2, if your file looks like this:</p>
<pre><code>10 8.04
8 6.95
13 7.58
9 8.81
11 8.33
14 9.96
6 7.24
4 4.26
12 10.84
7 4.82
5 5.68
</code></pre>
<p>Then I would do like this:</p>
<pre><code>x_list = list()
y_list = list()
fp = open('coords.txt', 'r')
for line in fp:
line = line.strip() ... | 0 | 2010-03-25T17:17:08Z | [
"python",
"numpy"
] |
Django: Template composed of Templates | 2,516,479 | <p>In one of my Django templates, I have a chunk of HTML which repeats at several places in the page. Is there a way I could use another template for this chunk alone and "instantiate" the template where required? </p>
| 1 | 2010-03-25T14:49:05Z | 2,516,497 | <p>You need to read about <a href="http://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance" rel="nofollow">template inheritance</a>.</p>
<p>Or you can use <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#include" rel="nofollow">template composition</a>.</p>
<p>Inheritance is, ... | 3 | 2010-03-25T14:50:47Z | [
"python",
"html",
"django"
] |
Has anyone combined soap.py or suds with python-ntlm? | 2,516,553 | <p>I'd like to replace an app's current (badly busted and crufty) cURL-based (cURL <em>command-line</em> based!) SOAP client with suds or soap.py. Trouble is, we have to contact an MS CRM service, and therefore must use NTLM. For a variety of reasons the NTLM proxy is a bit of a pain to use, so I'm looking into <a href... | 7 | 2010-03-25T14:57:18Z | 2,516,663 | <p>Suds was <a href="https://fedorahosted.org/suds/ticket/84">fixed</a> to support it since 0.3.8.</p>
<p>Sources of python-suds-0.3.9\suds\transport\https.py says:</p>
<pre><code>class WindowsHttpAuthenticated(HttpAuthenticated):
"""
Provides Windows (NTLM) http authentication.
@ivar pm: The password man... | 6 | 2010-03-25T15:08:18Z | [
"python",
"soap",
"ntlm",
"suds",
"soappy"
] |
Has anyone combined soap.py or suds with python-ntlm? | 2,516,553 | <p>I'd like to replace an app's current (badly busted and crufty) cURL-based (cURL <em>command-line</em> based!) SOAP client with suds or soap.py. Trouble is, we have to contact an MS CRM service, and therefore must use NTLM. For a variety of reasons the NTLM proxy is a bit of a pain to use, so I'm looking into <a href... | 7 | 2010-03-25T14:57:18Z | 12,084,824 | <p>You can use CNTLM as a local proxy service which will handle all the NTLM authentication calls. Then you just reference the local CNTLM proxy IP and port with no authentication using soapy or urllib2... whatever really.</p>
<p>I've yet to find a python library that deals with complex proxies well.</p>
| 0 | 2012-08-23T04:40:05Z | [
"python",
"soap",
"ntlm",
"suds",
"soappy"
] |
Has anyone combined soap.py or suds with python-ntlm? | 2,516,553 | <p>I'd like to replace an app's current (badly busted and crufty) cURL-based (cURL <em>command-line</em> based!) SOAP client with suds or soap.py. Trouble is, we have to contact an MS CRM service, and therefore must use NTLM. For a variety of reasons the NTLM proxy is a bit of a pain to use, so I'm looking into <a href... | 7 | 2010-03-25T14:57:18Z | 12,084,855 | <p>Another approach would be to call your curl command during soap exceptions and then initiate a retry.</p>
<p>something like...</p>
<pre><code>curl -x websenseproxy:8080 --ntlm -U domain\user:password --insecure https://blah.com/prod/webservice.asmx?WSDL
</code></pre>
<p><code>#insecure</code> is used for self sig... | 1 | 2012-08-23T04:43:20Z | [
"python",
"soap",
"ntlm",
"suds",
"soappy"
] |
scoping error in recursive closure | 2,516,652 | <p>why does this work:</p>
<pre><code>def function1():
a = 10
def function2():
... | 8 | 2010-03-25T15:07:43Z | 2,516,809 | <p>In the non-working snippet, you assign to <code>a</code> when you say "<code>a -= 1</code>". Because of that, inside <code>function2</code>, <code>a</code> is local to that scope, not taken the enclosing scope. Python's closures are lexicalâit does not dynamically look for <code>a</code> in <code>function2</code>'... | 2 | 2010-03-25T15:23:43Z | [
"python",
"recursion",
"scope",
"closures"
] |
scoping error in recursive closure | 2,516,652 | <p>why does this work:</p>
<pre><code>def function1():
a = 10
def function2():
... | 8 | 2010-03-25T15:07:43Z | 2,516,870 | <p>The error doesn't seem to be very descriptive of the root problem. Mike explains the messages but that does not explain the root cause.</p>
<p>The actual problem is that in python you cannot assign to closed over variables. So in function2 'a' is read only. When you assign to it you create a new variable which, as ... | 12 | 2010-03-25T15:30:10Z | [
"python",
"recursion",
"scope",
"closures"
] |
scoping error in recursive closure | 2,516,652 | <p>why does this work:</p>
<pre><code>def function1():
a = 10
def function2():
... | 8 | 2010-03-25T15:07:43Z | 2,521,657 | <p>It should be noted that this is a syntax glitch in Python. Python itself (at the bytecode level) can assign to these variables just fine; there's simply no syntax in 2.x to indicate that you want to do so. It assumes that if you assign to a variable in a nesting level, you mean for it to be a local to it.</p>
<p>... | 4 | 2010-03-26T07:22:55Z | [
"python",
"recursion",
"scope",
"closures"
] |
Python string comparison | 2,516,787 | <p>I have a python function that makes a subprocess call to a shell script that outputs 'true' or 'false'. I'm storing the output from <code>subprocess.communicate()</code> and trying to do <code>return output == 'true'</code> but it returns <code>False</code> every time. I'm not too familiar with python, but reading... | 4 | 2010-03-25T15:21:40Z | 2,516,812 | <p>Are you sure that there isn't a terminating line feed character, making your string contain <code>"true\n"</code>? That seems likely.</p>
<p>You could try return <code>isdeployed.startswith("true")</code>, or some stripping.</p>
| 8 | 2010-03-25T15:23:59Z | [
"python",
"string",
"compare"
] |
Python string comparison | 2,516,787 | <p>I have a python function that makes a subprocess call to a shell script that outputs 'true' or 'false'. I'm storing the output from <code>subprocess.communicate()</code> and trying to do <code>return output == 'true'</code> but it returns <code>False</code> every time. I'm not too familiar with python, but reading... | 4 | 2010-03-25T15:21:40Z | 2,516,819 | <p>Have you tried to call </p>
<pre><code>isdeployed.strip()
</code></pre>
<p>before the comparision</p>
| 6 | 2010-03-25T15:24:45Z | [
"python",
"string",
"compare"
] |
Python's IDLE for Java | 2,517,129 | <p>Question: IS there and IDE like python's <a href="http://en.wikipedia.org/wiki/IDLE_%28Python%29" rel="nofollow">IDLE</a> for other languages? specifically I'd like one for java, but any programing just feels so much nicer with a debug system like IDLE's. </p>
<hr>
<p>Info:</p>
<p>The main feature I'm getting at ... | 2 | 2010-03-25T16:00:10Z | 2,517,451 | <p><a href="http://www.bluej.org/index.html" rel="nofollow">BlueJ</a> is probably the closest thing available in the Java community.</p>
| 1 | 2010-03-25T16:38:30Z | [
"java",
"python",
"ide",
"debugging"
] |
Python's IDLE for Java | 2,517,129 | <p>Question: IS there and IDE like python's <a href="http://en.wikipedia.org/wiki/IDLE_%28Python%29" rel="nofollow">IDLE</a> for other languages? specifically I'd like one for java, but any programing just feels so much nicer with a debug system like IDLE's. </p>
<hr>
<p>Info:</p>
<p>The main feature I'm getting at ... | 2 | 2010-03-25T16:00:10Z | 2,517,986 | <p>If you are talking about a REPL (Read Eval Print Loop), or some sort of console where you can test out code without having to compile the whole project/file, <a href="http://www.beanshell.org/" rel="nofollow">BeanShell</a> is the best I've found for Java. It isn't tightly integrated with an IDE, like IDLE, but with ... | 4 | 2010-03-25T17:38:26Z | [
"java",
"python",
"ide",
"debugging"
] |
Python's IDLE for Java | 2,517,129 | <p>Question: IS there and IDE like python's <a href="http://en.wikipedia.org/wiki/IDLE_%28Python%29" rel="nofollow">IDLE</a> for other languages? specifically I'd like one for java, but any programing just feels so much nicer with a debug system like IDLE's. </p>
<hr>
<p>Info:</p>
<p>The main feature I'm getting at ... | 2 | 2010-03-25T16:00:10Z | 2,518,050 | <p>I would like to add that <a href="http://www.jetbrains.com/idea/index.html" rel="nofollow">Intellij IDEA</a> has an interactive shell when at break points as well, it is a little calculator icon in the debug panel when at a break point. Also since <a href="http://groovy.codehaus.org/" rel="nofollow">Groovy</a> is a ... | 0 | 2010-03-25T17:48:07Z | [
"java",
"python",
"ide",
"debugging"
] |
Downloading RSS using python | 2,517,648 | <p>I have list of 200 rss feeds, which I have to downloading. It's continuous process - I have to download every post, nothing can be missing, but also no duplicates. So best practice should be remember last update of feed and control it for change in x-hour interval? And how to handle if downloader will be restarted? ... | 1 | 2010-03-25T17:00:42Z | 2,517,716 | <p>You can use <a href="http://www.feedparser.org" rel="nofollow">feedparser</a> to parse the feeds and store in a database the maximal published time per feed.</p>
<p>For a simple database you can use <a href="http://docs.python.org/library/shelve.html" rel="nofollow">shelve</a>.</p>
| 2 | 2010-03-25T17:06:37Z | [
"python"
] |
Downloading RSS using python | 2,517,648 | <p>I have list of 200 rss feeds, which I have to downloading. It's continuous process - I have to download every post, nothing can be missing, but also no duplicates. So best practice should be remember last update of feed and control it for change in x-hour interval? And how to handle if downloader will be restarted? ... | 1 | 2010-03-25T17:00:42Z | 2,517,985 | <p>Typically this is what you'd want to do:</p>
<ul>
<li>Fetch the feeds periodically and parse them using the <a href="http://www.feedparser.org/" rel="nofollow">universal feedparser</a> and store the entries somewhere.</li>
<li>Use ETags and IfModified headers when fetching feeds to avoid parsing feeds that have not... | 4 | 2010-03-25T17:38:14Z | [
"python"
] |
Why do I get a connection error / timeout when using python suds to connect to Microsoft CRM? | 2,517,939 | <p>When I try to connect to an MS CRM web service using suds/python-ntlm, I am getting a timeout on requests. However, the code that I'm trying to replace -- which calls out to the cURL command line app to do the same call -- succeeds.</p>
<p>Clearly something is different in the way that cURL is sending the command ... | 5 | 2010-03-25T17:32:29Z | 2,520,041 | <p>It looks like you might be having a problem with the location in the WSDL. If you check the debug output when it says it is sending:</p>
<pre><code>DEBUG:suds.transport.http:sending:
URL:http://client.service.host/MSCrmServices/2007/MetadataService.asmx
</code></pre>
<p>Note that the URL is http, and that does n... | 4 | 2010-03-25T23:01:52Z | [
"python",
"iis",
"soap",
"curl",
"suds"
] |
Why do I get a connection error / timeout when using python suds to connect to Microsoft CRM? | 2,517,939 | <p>When I try to connect to an MS CRM web service using suds/python-ntlm, I am getting a timeout on requests. However, the code that I'm trying to replace -- which calls out to the cURL command line app to do the same call -- succeeds.</p>
<p>Clearly something is different in the way that cURL is sending the command ... | 5 | 2010-03-25T17:32:29Z | 17,212,715 | <pre><code>svc_url = 'https://client.service.host/MSCrmServices/2007/MetadataService.asmx'
metadata_client = Client(wsdl_url, transport=ntlmTransport, location=svc_url, cache=None)
</code></pre>
<p>Adding <code>cache=None</code> actually do the trick.</p>
| 0 | 2013-06-20T11:41:45Z | [
"python",
"iis",
"soap",
"curl",
"suds"
] |
Weird Cron ls Behavior | 2,517,961 | <p>I have a Python script that is running a few ls commands. This script runs under cron all day. I use awk to write out the column that the filename is in when ls -l is executed.</p>
<p>When I run the script via command line the output looks like this</p>
<pre><code>-rw-rw---- 1 mysql adm 141 2010-03-25 08:56 ... | 1 | 2010-03-25T17:35:43Z | 2,518,019 | <p>Problem is with different locales between your account and root. You can change them temporarily by:</p>
<pre><code>$ LC_ALL="locale name" your-script
</code></pre>
| 3 | 2010-03-25T17:43:14Z | [
"python",
"cron"
] |
Weird Cron ls Behavior | 2,517,961 | <p>I have a Python script that is running a few ls commands. This script runs under cron all day. I use awk to write out the column that the filename is in when ls -l is executed.</p>
<p>When I run the script via command line the output looks like this</p>
<pre><code>-rw-rw---- 1 mysql adm 141 2010-03-25 08:56 ... | 1 | 2010-03-25T17:35:43Z | 2,518,022 | <p>If you're on GNU ls, you can pass <code>--time-style=long-iso</code>. More formats are <a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#Formatting-file-timestamps" rel="nofollow">here</a>.</p>
| 3 | 2010-03-25T17:44:16Z | [
"python",
"cron"
] |
How to convert an UTF string with scandinavian characters to ASCII? | 2,518,005 | <p>I would like to convert this string</p>
<pre><code>foo_utf = u'nästy chäräctörs with å and co.' # unicode
</code></pre>
<p>into this</p>
<pre><code>foo_ascii = 'nästy chäräctörs with å and co.' # ASCII
</code></pre>
<p>.</p>
<p>Any idea how to do this in Python (2.6)? I found <a href="http://docs.pyth... | 1 | 2010-03-25T17:41:18Z | 2,518,018 | <p>Try the <code>encode</code> method of string.</p>
<pre><code>>>> u'nästy chäräctörs with å and co.'.encode('latin-1')
'n\xe4sty ch\xe4r\xe4ct\xf6rs with \xe5 and co.'
</code></pre>
| 3 | 2010-03-25T17:43:07Z | [
"python",
"ascii",
"utf"
] |
How to convert an UTF string with scandinavian characters to ASCII? | 2,518,005 | <p>I would like to convert this string</p>
<pre><code>foo_utf = u'nästy chäräctörs with å and co.' # unicode
</code></pre>
<p>into this</p>
<pre><code>foo_ascii = 'nästy chäräctörs with å and co.' # ASCII
</code></pre>
<p>.</p>
<p>Any idea how to do this in Python (2.6)? I found <a href="http://docs.pyth... | 1 | 2010-03-25T17:41:18Z | 2,518,044 | <p>I don't think you can. Those "nästy chäräctörs" can't be encoded as ASCII, so you'll have to pick a different encoding (UTF-8 or Latin-1 or Windows-1252 or something).</p>
| 4 | 2010-03-25T17:47:03Z | [
"python",
"ascii",
"utf"
] |
How to convert an UTF string with scandinavian characters to ASCII? | 2,518,005 | <p>I would like to convert this string</p>
<pre><code>foo_utf = u'nästy chäräctörs with å and co.' # unicode
</code></pre>
<p>into this</p>
<pre><code>foo_ascii = 'nästy chäräctörs with å and co.' # ASCII
</code></pre>
<p>.</p>
<p>Any idea how to do this in Python (2.6)? I found <a href="http://docs.pyth... | 1 | 2010-03-25T17:41:18Z | 2,518,332 | <p>You can also use the unicodedata module (http://docs.python.org/library/unicodedata.html) provided in python to convert a lot of unicode values into an Ascii variant. IE fix the different "s and such. Follow that up by the encode() method and you can completely clean up a string. </p>
<p>The method you mainly what ... | 2 | 2010-03-25T18:30:46Z | [
"python",
"ascii",
"utf"
] |
How to convert an UTF string with scandinavian characters to ASCII? | 2,518,005 | <p>I would like to convert this string</p>
<pre><code>foo_utf = u'nästy chäräctörs with å and co.' # unicode
</code></pre>
<p>into this</p>
<pre><code>foo_ascii = 'nästy chäräctörs with å and co.' # ASCII
</code></pre>
<p>.</p>
<p>Any idea how to do this in Python (2.6)? I found <a href="http://docs.pyth... | 1 | 2010-03-25T17:41:18Z | 2,518,368 | <p>There are several options in the <code>codecs</code> module in python's stdlib, depending on how you want the extended characters handled:</p>
<pre><code>>>> import codecs
>>> u = u'nästy chäräctörs with å and co.'
>>> encode = codecs.get_encoder('ascii')
>>> encode(u)
'
Tr... | 3 | 2010-03-25T18:36:44Z | [
"python",
"ascii",
"utf"
] |
How to convert an UTF string with scandinavian characters to ASCII? | 2,518,005 | <p>I would like to convert this string</p>
<pre><code>foo_utf = u'nästy chäräctörs with å and co.' # unicode
</code></pre>
<p>into this</p>
<pre><code>foo_ascii = 'nästy chäräctörs with å and co.' # ASCII
</code></pre>
<p>.</p>
<p>Any idea how to do this in Python (2.6)? I found <a href="http://docs.pyth... | 1 | 2010-03-25T17:41:18Z | 2,518,712 | <p>This really is a Django question, and not a python one.
if the string is in one of your .py files, make sure that you have the following line on top of your file:
<code>-*- coding: utf-8 -*-</code></p>
<p>furthermore, your string needs to be of type "unicode" (u'foobar')</p>
<p>And then make sure that your html p... | 2 | 2010-03-25T19:27:23Z | [
"python",
"ascii",
"utf"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.