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
django-cart or Satchmo?
490,439
<p>I'm looking to implement a very basic shopping cart. <a href="http://www.satchmoproject.com/">Satchmo</a> seems to install a <strong>lot</strong> of applications and extra stuff that I don't need. I've heard others mention <a href="http://code.google.com/p/django-cart/">django-cart</a>. Has anyone tried this Djan...
23
2009-01-29T04:00:49Z
490,534
<p>Well if you want to use django-cart you should view it as a starting point for developing your own. The last commit (r4) for the project was November 2006.</p> <p>By comparison, the last commit (r1922) to Satchmo was a couple of hours ago.</p> <p>With Satchmo you get code that is under active development and actu...
26
2009-01-29T05:04:35Z
[ "python", "django", "e-commerce", "satchmo" ]
django-cart or Satchmo?
490,439
<p>I'm looking to implement a very basic shopping cart. <a href="http://www.satchmoproject.com/">Satchmo</a> seems to install a <strong>lot</strong> of applications and extra stuff that I don't need. I've heard others mention <a href="http://code.google.com/p/django-cart/">django-cart</a>. Has anyone tried this Djan...
23
2009-01-29T04:00:49Z
493,895
<p>As mentioned above, Django-cart hasn't been updated in a long time so it is most likely not compatible with Django 1.0 and the more recent versions of Django. For that reason alone, I'd recommend sticking with something more recent.</p> <p>I'm biased because I'm a dev on Satchmo but I think the feeling of overkill ...
4
2009-01-29T23:05:52Z
[ "python", "django", "e-commerce", "satchmo" ]
django-cart or Satchmo?
490,439
<p>I'm looking to implement a very basic shopping cart. <a href="http://www.satchmoproject.com/">Satchmo</a> seems to install a <strong>lot</strong> of applications and extra stuff that I don't need. I've heard others mention <a href="http://code.google.com/p/django-cart/">django-cart</a>. Has anyone tried this Djan...
23
2009-01-29T04:00:49Z
700,439
<p>Seems that a new version of Django-cart has been released on 25th March. <a href="http://vaig.be/2009/03/django-cart-released.html" rel="nofollow">http://vaig.be/2009/03/django-cart-released.html</a></p> <p>Wonder how the new version fares with respect to Satchmo.</p>
1
2009-03-31T07:43:41Z
[ "python", "django", "e-commerce", "satchmo" ]
django-cart or Satchmo?
490,439
<p>I'm looking to implement a very basic shopping cart. <a href="http://www.satchmoproject.com/">Satchmo</a> seems to install a <strong>lot</strong> of applications and extra stuff that I don't need. I've heard others mention <a href="http://code.google.com/p/django-cart/">django-cart</a>. Has anyone tried this Djan...
23
2009-01-29T04:00:49Z
818,404
<p>I am using django-cart and it is not really an app - it is a start of an app. There are no views, and it totals about 150 lines of code. There is no doc but it is pretty clear how to use most of it. I am a little unsure of the intention of ItemManager or how that is supposed to be used. Comparing it to Satchm...
0
2009-05-04T00:24:15Z
[ "python", "django", "e-commerce", "satchmo" ]
django-cart or Satchmo?
490,439
<p>I'm looking to implement a very basic shopping cart. <a href="http://www.satchmoproject.com/">Satchmo</a> seems to install a <strong>lot</strong> of applications and extra stuff that I don't need. I've heard others mention <a href="http://code.google.com/p/django-cart/">django-cart</a>. Has anyone tried this Djan...
23
2009-01-29T04:00:49Z
16,063,883
<p><a href="http://www.satchmoproject.com/" rel="nofollow">Satchmo</a> has more features than <a href="http://code.google.com/p/django-cart/" rel="nofollow">django-cart</a>. If you are looking for simple and lightweight shopping cart application, try <a href="https://github.com/lazybird/django-carton" rel="nofollow">dj...
1
2013-04-17T15:16:30Z
[ "python", "django", "e-commerce", "satchmo" ]
Regex replace (in Python) - a simpler way?
490,597
<p>Any time I want to replace a piece of text that is part of a larger piece of text, I always have to do something like:</p> <pre><code>"(?P&lt;start&gt;some_pattern)(?P&lt;replace&gt;foo)(?P&lt;end&gt;end)" </code></pre> <p>And then concatenate the <code>start</code> group with the new data for <code>replace</code>...
42
2009-01-29T05:43:24Z
490,609
<p>Look in the Python <a href="http://docs.python.org/library/re.html">re documentation</a> for lookaheads <code>(?=...)</code> and lookbehinds <code>(?&lt;=...)</code> -- I'm pretty sure they're what you want. They match strings, but do not "consume" the bits of the strings they match.</p>
18
2009-01-29T05:51:21Z
[ "python", "regex" ]
Regex replace (in Python) - a simpler way?
490,597
<p>Any time I want to replace a piece of text that is part of a larger piece of text, I always have to do something like:</p> <pre><code>"(?P&lt;start&gt;some_pattern)(?P&lt;replace&gt;foo)(?P&lt;end&gt;end)" </code></pre> <p>And then concatenate the <code>start</code> group with the new data for <code>replace</code>...
42
2009-01-29T05:43:24Z
490,616
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s = "start foo end" &gt;&gt;&gt; s = re.sub("foo", "replaced", s) &gt;&gt;&gt; s 'start replaced end' &gt;&gt;&gt; s = re.sub("(?&lt;= )(.+)(?= )", lambda m: "can use a callable for the %s text too" % m.group(1), s) &gt;&gt;&gt; s 'start can use a callable for the replaced...
105
2009-01-29T05:56:21Z
[ "python", "regex" ]
Regex replace (in Python) - a simpler way?
490,597
<p>Any time I want to replace a piece of text that is part of a larger piece of text, I always have to do something like:</p> <pre><code>"(?P&lt;start&gt;some_pattern)(?P&lt;replace&gt;foo)(?P&lt;end&gt;end)" </code></pre> <p>And then concatenate the <code>start</code> group with the new data for <code>replace</code>...
42
2009-01-29T05:43:24Z
491,966
<p>The short version is that you <em>cannot use</em> variable-width patterns in lookbehinds using Python's <code>re</code> module. There is no way to change this:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.sub("(?&lt;=foo)bar(?=baz)", "quux", "foobarbaz") 'fooquuxbaz' &gt;&gt;&gt; re.sub("(?&lt;=fo+)bar(?=...
11
2009-01-29T15:11:48Z
[ "python", "regex" ]
Regex replace (in Python) - a simpler way?
490,597
<p>Any time I want to replace a piece of text that is part of a larger piece of text, I always have to do something like:</p> <pre><code>"(?P&lt;start&gt;some_pattern)(?P&lt;replace&gt;foo)(?P&lt;end&gt;end)" </code></pre> <p>And then concatenate the <code>start</code> group with the new data for <code>replace</code>...
42
2009-01-29T05:43:24Z
2,053,304
<p>I believe that the best idea is just to capture in a group whatever you want to replace, and then replace it by using the start and end properties of the captured group.</p> <p>regards</p> <p>Adrián</p> <pre><code>#the pattern will contain the expression we want to replace as the first group pat = "word1\s(.*)\s...
4
2010-01-12T23:39:10Z
[ "python", "regex" ]
Statistics & other add-on tools for Planet blog aggregator software
490,634
<p>The Planet software is often used for particular topics or large projects, to collect blogs that post on a particular theme. <a href="http://www.planetplanet.org/" rel="nofollow">http://www.planetplanet.org/</a></p> <p>I think there are lots of interesting add-ons that could be done for it but so far I haven't seen...
2
2009-01-29T06:09:33Z
7,552,287
<p>Answer: No, there are no addons afaik. You could write them. :-)</p>
0
2011-09-26T08:11:56Z
[ "python", "blogs", "add-on" ]
regex: Matching parts of a string when the string contains part of a regex pattern
490,762
<p>I want to reduce the number of patterns I have to write by using a regex that picks up any or all of the pattern when it appears in a string.</p> <p>Is this possible with Regex?</p> <pre><code>E.g. Pattern is: "the cat sat on the mat" I would like pattern to match on following strings: "the" "the cat" "the cat sa...
1
2009-01-29T07:21:53Z
490,767
<p>If you know the match always begins at the first character, it would be much faster to match the characters directly in a loop. I don't think Regex will do it anyway.</p>
1
2009-01-29T07:24:58Z
[ "python", "regex" ]
regex: Matching parts of a string when the string contains part of a regex pattern
490,762
<p>I want to reduce the number of patterns I have to write by using a regex that picks up any or all of the pattern when it appears in a string.</p> <p>Is this possible with Regex?</p> <pre><code>E.g. Pattern is: "the cat sat on the mat" I would like pattern to match on following strings: "the" "the cat" "the cat sa...
1
2009-01-29T07:21:53Z
490,785
<p>It could be fairly complicated:</p> <pre><code>(?ms)the(?=(\s+cat)|[\r\n]+)(:?\s+cat(?=(\s+sat)|[\r\n]+))?(:?\s+sat(?=(\s+on)|[\r\n]+))?(:?\s+on(?=(\s+the)|[\r\n]+))?(:?\s+the(?=(\s+mat)|[\r\n]+))?(:?\s+mat)?[\r\n]+ </code></pre> <p>Meaning:</p> <ul> <li>I want "<code>the</code>" only if followed by "<code>cat</c...
2
2009-01-29T07:35:42Z
[ "python", "regex" ]
regex: Matching parts of a string when the string contains part of a regex pattern
490,762
<p>I want to reduce the number of patterns I have to write by using a regex that picks up any or all of the pattern when it appears in a string.</p> <p>Is this possible with Regex?</p> <pre><code>E.g. Pattern is: "the cat sat on the mat" I would like pattern to match on following strings: "the" "the cat" "the cat sa...
1
2009-01-29T07:21:53Z
490,794
<p>This:</p> <pre><code>the( cat( sat( on( the( mat)?)?)?)?)? </code></pre> <p>would answer your question. Remove "optional group" parens "(...)?" for parts that are not optional, add additional groups for things that must match together.</p> <pre><code>the // complete match the cat ...
7
2009-01-29T07:42:14Z
[ "python", "regex" ]
regex: Matching parts of a string when the string contains part of a regex pattern
490,762
<p>I want to reduce the number of patterns I have to write by using a regex that picks up any or all of the pattern when it appears in a string.</p> <p>Is this possible with Regex?</p> <pre><code>E.g. Pattern is: "the cat sat on the mat" I would like pattern to match on following strings: "the" "the cat" "the cat sa...
1
2009-01-29T07:21:53Z
491,687
<p>Perhaps it would be easier and more logical to think about the problem a little differently..</p> <p>Instead of matching the pattern against the string.... how about using the string as the pattern and looking for it in the pattern.</p> <p>For example where</p> <p>string = "the cat sat on" pattern = "the cat sat ...
0
2009-01-29T14:01:49Z
[ "python", "regex" ]
MSN with Python
490,929
<p>I have plans to create a simple bot for a game I run and have it sit on MSN and answer queries. I want to use Python to do this and googled around and found <a href="http://msnp.sourceforge.net/" rel="nofollow">MSNP</a>. I thought "great" and "how awesome" but it appears that it's about 5 years old and oddly enough ...
2
2009-01-29T08:51:45Z
490,933
<p>I don't know of anything equivalent, but you can look at the source to <a href="http://developer.pidgin.im/wiki/WhatIsLibpurple" rel="nofollow">libpurple</a> and roll your own without a terrible amount of difficulty.</p>
1
2009-01-29T08:53:03Z
[ "python", "msn" ]
MSN with Python
490,929
<p>I have plans to create a simple bot for a game I run and have it sit on MSN and answer queries. I want to use Python to do this and googled around and found <a href="http://msnp.sourceforge.net/" rel="nofollow">MSNP</a>. I thought "great" and "how awesome" but it appears that it's about 5 years old and oddly enough ...
2
2009-01-29T08:51:45Z
491,368
<p>If you're prepared to do some hard work with the original source code, you could update it to support the current version of the MSN protocol:</p> <p><a href="http://msnpiki.msnfanatic.com/index.php/Main_Page" rel="nofollow">http://msnpiki.msnfanatic.com/index.php/Main_Page</a></p>
1
2009-01-29T12:16:13Z
[ "python", "msn" ]
MSN with Python
490,929
<p>I have plans to create a simple bot for a game I run and have it sit on MSN and answer queries. I want to use Python to do this and googled around and found <a href="http://msnp.sourceforge.net/" rel="nofollow">MSNP</a>. I thought "great" and "how awesome" but it appears that it's about 5 years old and oddly enough ...
2
2009-01-29T08:51:45Z
4,487,016
<p>You can use <a href="http://blitiri.com.ar/p/msnlib/" rel="nofollow"><code>msnlib</code></a>, which after a quick test seems to be up to date, and is quite a small and readable library in two files, with a reference implementation of a few cli chat clients and chat bots.</p>
1
2010-12-20T05:03:19Z
[ "python", "msn" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
492,073
<p>To enable code completion, go to Window > Preferences > Pydev > Editor > Code Completion, and check the 'Use Code Completion?' box, as well as the other boxes for what you want to complete on. It seems to take a second to load, the first time it has to complete something.</p> <p>Syntax coloring should just work by...
21
2009-01-29T15:32:20Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
495,297
<p>Well, I tried the Wing Professional and I think its really the best Py IDE out there.</p>
0
2009-01-30T12:03:46Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
495,362
<p>Between komodo and wingide i would go for wing. The license is not that expensive and the fact that it is commercial gives you a bigger probability of more updates and bug fixes. If you, like me, prefer a free solution, then stick with pydev. At least until aptana closes the free door :)</p>
0
2009-01-30T12:28:52Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
1,399,741
<p>Check to see if the 'P' icon is appearing for your items and in the top of your editor after opening it. If it's not appearing, it may be that there's a problem with the file association, so, go to window > preferences > general > editors > file associations and make sure that the .py files are associated with the P...
2
2009-09-09T13:38:23Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
1,836,524
<p>The typical reason that code completion doesn't work under PyDev is that the libraries aren't in the PYTHONPATH. If you go into the Project Properties, and setup PyDev PYTHONPATH preferences to include the places where the code you are trying to complete lives, it will work just fine...</p> <p>Project > Properties...
8
2009-12-02T23:07:53Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
4,665,424
<p>It sounds like you have to specify the location of the Python interpreter. Do this under Preferences > Pydev > Interpreter - Python. Create a new interpreter and point it to the Python interpreter executable.</p>
1
2011-01-12T04:47:00Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
17,847,161
<p>Make sure you use 'Open With' as 'Python Editor' by right clicking on the file - It worked for me </p>
4
2013-07-25T00:43:03Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
18,933,901
<p>Check your Theme configuration. Python highlighting uses Theme Colors</p>
0
2013-09-21T14:39:21Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
19,301,447
<p>In case anyone else makes the embarrassing mistake that I did: be sure your source code file actually ends with ".py". Even if its in a Python project, PyDev won't guess without the extension. </p>
0
2013-10-10T16:37:05Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
25,439,963
<p><strong>If you want to work with Eclipse please have a look at these pluggins.</strong></p> <p>-To make your eclipse editor work like vim. I use this plugin. <a href="http://vrapper.sourceforge.net/home/" rel="nofollow">http://vrapper.sourceforge.net/home/</a></p> <p>-Then if you do something with HTML...
0
2014-08-22T05:13:15Z
[ "python", "ide" ]
No code completion and syntax highlighting in Pydev
491,053
<p>I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?</p> <p>Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program. </p> <p>I prefer a SciTE kind of editor with simi...
12
2009-01-29T09:50:56Z
35,208,736
<p>When syntax highlighting was not working for me using PyDev, I discovered that there were somehow two 'Python Editor' associations defined for .py files in my installation of Eclipse/PyDev. From the Eclipse Main Menu, go to Window > Preferences > General > Editors > FileAssociations to see the file extension &lt;-...
0
2016-02-04T18:24:59Z
[ "python", "ide" ]
How can I pass a filename as a parameter into my module?
491,085
<p>I have the following code in .py file:</p> <pre><code>import re regex = re.compile( r"""ULLAT:\ (?P&lt;ullat&gt;-?[\d.]+).*? ULLON:\ (?P&lt;ullon&gt;-?[\d.]+).*? LRLAT:\ (?P&lt;lrlat&gt;-?[\d.]+)""", re.DOTALL|re.VERBOSE) </code></pre> <p>I have the data in .txt file as a sequence:</p> <pre><code>QUA...
5
2009-01-29T10:04:13Z
491,189
<p>You need to read the file in and then search the contents using the regular expression. The sys module contains a list, argv, which contains all the command line parameters. We pull out the second one (the first is the file name used to run the script), open the file, and then read in the contents.</p> <pre> import...
14
2009-01-29T10:50:05Z
[ "python", "command-line", "parameters", "module" ]
Can you recommend a Python SOAP client that can accept WS-Attachments?
491,404
<p>I've read mixed reviews of both <a href="https://fedorahosted.org/suds/" rel="nofollow">Suds</a> and <a href="http://pywebsvcs.sourceforge.net/" rel="nofollow">ZSI</a> -- two Python SOAP libraries. However, I'm unclear whether either of them can support WS-Attachments. I'd prefer to use Suds (appears to be more st...
3
2009-01-29T12:27:47Z
557,079
<p>For your requirements I'd have to recommend ZSI. From its documentation,</p> <blockquote> It can also be used to build applications using SOAP Messages with Attachments. </blockquote> <p>Their website is not as pretty as Suds but the package includes promising documentation.</p> <p>SOAPpy has support for attachme...
1
2009-02-17T14:33:38Z
[ "python", "soap" ]
Can you recommend a Python SOAP client that can accept WS-Attachments?
491,404
<p>I've read mixed reviews of both <a href="https://fedorahosted.org/suds/" rel="nofollow">Suds</a> and <a href="http://pywebsvcs.sourceforge.net/" rel="nofollow">ZSI</a> -- two Python SOAP libraries. However, I'm unclear whether either of them can support WS-Attachments. I'd prefer to use Suds (appears to be more st...
3
2009-01-29T12:27:47Z
557,164
<p>I believe <a href="http://trac.optio.webfactional.com/" rel="nofollow">soaplib</a> can handle attachments. I'm just not sure exactly how compliant it is with WS-Attachments because they don't trumpet it.</p> <p>Here's a sample client that, their words, allows "multi-part mime payloads":</p> <p><a href="http://tra...
1
2009-02-17T14:49:03Z
[ "python", "soap" ]
Can you recommend a Python SOAP client that can accept WS-Attachments?
491,404
<p>I've read mixed reviews of both <a href="https://fedorahosted.org/suds/" rel="nofollow">Suds</a> and <a href="http://pywebsvcs.sourceforge.net/" rel="nofollow">ZSI</a> -- two Python SOAP libraries. However, I'm unclear whether either of them can support WS-Attachments. I'd prefer to use Suds (appears to be more st...
3
2009-01-29T12:27:47Z
563,207
<p>In my experience Suds was the only Python package that actually works. I did not use attachments.</p>
0
2009-02-18T22:50:52Z
[ "python", "soap" ]
Python: Problem with local modules shadowing global modules
491,705
<p>I've got a package set up like so:</p> <pre><code>packagename/ __init__.py numbers.py tools.py ...other stuff </code></pre> <p>Now inside <code>tools.py</code>, I'm trying to import the standard library module <code>fractions</code>. However, the <code>fractions</code> module itself imports the <co...
9
2009-01-29T14:04:51Z
491,813
<p><a href="http://www.python.org/dev/peps/pep-0328/">absolute and relative imports</a> can be used since python2.5 (with <code>__future__</code> import) and seem to be what you're looking for.</p>
8
2009-01-29T14:33:14Z
[ "python" ]
Python: Problem with local modules shadowing global modules
491,705
<p>I've got a package set up like so:</p> <pre><code>packagename/ __init__.py numbers.py tools.py ...other stuff </code></pre> <p>Now inside <code>tools.py</code>, I'm trying to import the standard library module <code>fractions</code>. However, the <code>fractions</code> module itself imports the <co...
9
2009-01-29T14:04:51Z
492,041
<p>I try to avoid shadowing the standard library. How about renaming your module to "_numbers.py" ?</p> <p>And of course, you could still do:</p> <pre><code>import _numbers as numbers </code></pre>
4
2009-01-29T15:25:15Z
[ "python" ]
Using the input collected from raw_input in Python
491,837
<p>If I do the following in python,</p> <pre><code>string = raw_input('Enter the value') </code></pre> <p>it will return </p> <blockquote> <p>Enter the value</p> </blockquote> <p>and wait until I enter something into the prompt.</p> <p>Is there a way to retrieve/collect the input I entered in a variable <code>st...
0
2009-01-29T14:39:54Z
491,868
<p>This is very confusing ... I'm not familiar with a raw_string function in Python, but perhaps it's application-specific? </p> <p>Reading a line of input in Python can be done like this:</p> <pre><code>import sys line = sys.stdin.readline() </code></pre> <p>Then you have that line, terminating linefeed and all, in...
4
2009-01-29T14:46:31Z
[ "python", "raw-input" ]
Using the input collected from raw_input in Python
491,837
<p>If I do the following in python,</p> <pre><code>string = raw_input('Enter the value') </code></pre> <p>it will return </p> <blockquote> <p>Enter the value</p> </blockquote> <p>and wait until I enter something into the prompt.</p> <p>Is there a way to retrieve/collect the input I entered in a variable <code>st...
0
2009-01-29T14:39:54Z
491,874
<p>there's no <code>raw_string</code> function in python's stdlib. do you mean raw_input?</p> <pre><code>string = raw_input("Enter the value") # or just input in python3.0 print(string) </code></pre>
5
2009-01-29T14:47:52Z
[ "python", "raw-input" ]
Using the input collected from raw_input in Python
491,837
<p>If I do the following in python,</p> <pre><code>string = raw_input('Enter the value') </code></pre> <p>it will return </p> <blockquote> <p>Enter the value</p> </blockquote> <p>and wait until I enter something into the prompt.</p> <p>Is there a way to retrieve/collect the input I entered in a variable <code>st...
0
2009-01-29T14:39:54Z
491,882
<p>Is this what you want to do?</p> <pre><code>string = raw_input('Enter a value: ') string = string.strip() if string in dict: print dict[string] </code></pre>
3
2009-01-29T14:49:30Z
[ "python", "raw-input" ]
Using the input collected from raw_input in Python
491,837
<p>If I do the following in python,</p> <pre><code>string = raw_input('Enter the value') </code></pre> <p>it will return </p> <blockquote> <p>Enter the value</p> </blockquote> <p>and wait until I enter something into the prompt.</p> <p>Is there a way to retrieve/collect the input I entered in a variable <code>st...
0
2009-01-29T14:39:54Z
11,109,771
<p><code>import readline</code> provides a full terminal prompt to the <code>raw_input</code> function. You get control keys and history this way. Otherwise, it's no better than the <code>sys.stdin.readline()</code> option.</p> <pre><code>import readline while True: value = raw_input('Enter a value: ') value ...
0
2012-06-19T21:32:50Z
[ "python", "raw-input" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
491,956
<p>the \x.. sequence is something that's specific to python. It's not a universal byte escape sequence. </p> <p>How you actually enter in utf8-encoded non-ascii depends on your OS and/or your editor. <a href="http://tlt.its.psu.edu/suggestions/international/accents/codealt.html" rel="nofollow">Here's how you do it in ...
3
2009-01-29T15:10:26Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
491,967
<p>In the notation</p> <pre><code>u'Capit\xe1n\n' </code></pre> <p>the "\xe1" represents just one byte. "\x" tells you that "e1" is in hexadecimal. When you write</p> <pre><code>Capit\xc3\xa1n </code></pre> <p>into your file you have "\xc3" in it. Those are 4 bytes and in your code you read them all. You can see th...
69
2009-01-29T15:11:59Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
491,974
<p>Well, your favorite text editor does not realize that <code>\xc3\xa1</code> are supposed to be character literals, but interprets them as text. That's why you get the double backslashes in the last line -- it's now a real backslash + <code>xc3</code> etc in your file.</p> <p>If you want to read and write encoded fi...
4
2009-01-29T15:13:11Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
492,470
<p>You have stumbled over the general problem with encodings: How can I tell in which encoding a file is?</p> <p>Answer: You can't <em>unless</em> the file format provides for this. XML, for example, begins with:</p> <pre><code>&lt;?xml encoding="utf-8"?&gt; </code></pre> <p>This header was carefully chosen so that ...
4
2009-01-29T16:54:42Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
493,152
<p>So, I've found a solution for what I'm looking for, which is:</p> <pre><code>print open('f2').read().decode('string-escape').decode("utf-8") </code></pre> <p>There are some unusual codecs that are useful here. This particular reading allows one to take utf-8 representations from within python, copy them into an a...
12
2009-01-29T20:01:27Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
844,443
<p>Rather than mess with the encode, decode methods I find it easier to use the open method from the codecs module.</p> <pre><code>&gt;&gt;&gt;import codecs &gt;&gt;&gt;f = codecs.open("test", "r", "utf-8") </code></pre> <p>Then after calling f's read() function, an encoded unicode object is returned.</p> <pre><code...
468
2009-05-10T00:45:58Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
9,200,843
<pre><code># -*- encoding: utf-8 -*- # converting a unknown formatting file in utf-8 import codecs import commands file_location = "jumper.sub" file_encoding = commands.getoutput('file -b --mime-encoding %s' % file_location) file_stream = codecs.open(file_location, 'r', file_encoding) file_output = codecs.open(file...
12
2012-02-08T20:24:46Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
25,378,530
<p>Actually this is worked for me for reading a file with utf-8 encodeing in Py 3.2</p> <pre><code>import codecs f = codecs.open('file_name.txt', 'r', 'UTF-8') for line in f: print(line) </code></pre>
11
2014-08-19T08:09:28Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
25,915,686
<p>To read in an Unicode string and then send to HTML, I did this:</p> <pre><code>fileline.decode("utf-8").encode('ascii', 'xmlcharrefreplace') </code></pre> <p>Useful for python powered http servers.</p>
4
2014-09-18T14:38:14Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
35,320,036
<p>Now all you need in Python3 is <code>open(Filename, 'r', encoding='utf-8')</code></p> <p><em>[Edit on 2016-02-10 for requested clarification]</em></p> <p>Python3 added the <strong>encoding</strong> parameter to its open function. The following information about the open function is gathered from here: <a href="htt...
6
2016-02-10T16:03:00Z
[ "python", "unicode", "utf-8", "io" ]
Unicode (utf8) reading and writing to files in python
491,921
<p>I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).</p> <pre><code># the string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) </code></pre> <blockquote> <p>("u'Capit\xe1n'", "'Capit\xc3\xa1n'")</p> </blockquote> <pre><code...
189
2009-01-29T15:01:15Z
37,139,074
<p>I was trying to parse ical using python 2.7.9:<br></p> <blockquote> <p>from icalendar import Calendar<br></p> </blockquote> <p>but was getting:</p> <pre><code> Traceback (most recent call last): File "ical.py", line 92, in parse print "{}".format(e[attr]) UnicodeEncodeError: 'ascii' codec can't encode char...
0
2016-05-10T12:49:41Z
[ "python", "unicode", "utf-8", "io" ]
How can I order objects according to some attribute of the child in sqlalchemy?
492,223
<p>Here is the situation: I have a parent model say <code>BlogPost</code>. It has many <code>Comment</code>s. What I want is the list of <code>BlogPost</code>s ordered by the creation date of its' <code>Comment</code>s. I.e. the blog post which has the most newest comment should be on top of the list. Is this possible ...
3
2009-01-29T16:01:51Z
492,389
<p><a href="http://www.sqlalchemy.org/docs/05/mappers.html#controlling-ordering" rel="nofollow">http://www.sqlalchemy.org/docs/05/mappers.html#controlling-ordering</a></p> <blockquote> <p>As of version 0.5, the ORM does not generate ordering for any query unless explicitly configured.</p> <p>The “defaultâ...
3
2009-01-29T16:35:02Z
[ "python", "sqlalchemy" ]
How can I order objects according to some attribute of the child in sqlalchemy?
492,223
<p>Here is the situation: I have a parent model say <code>BlogPost</code>. It has many <code>Comment</code>s. What I want is the list of <code>BlogPost</code>s ordered by the creation date of its' <code>Comment</code>s. I.e. the blog post which has the most newest comment should be on top of the list. Is this possible ...
3
2009-01-29T16:01:51Z
1,227,979
<p>I had the same question as the parent when using the ORM, and GHZ's link contained the answer on how it's possible. In sqlalchemy, assuming BlogPost.comments is a mapped relation to the Comments table, you can't do:</p> <blockquote> <p>session.query(BlogPost).order_by(BlogPost.comments.creationDate.desc())</p> </...
1
2009-08-04T14:53:02Z
[ "python", "sqlalchemy" ]
How do I use ctypes to set a library's extern function pointer to a Python callback function?
492,377
<p>Some C libraries export function pointers such that the user of the library sets that function pointer to the address of their own function to implement a hook or callback.</p> <p>In this example library <code>liblibrary.so</code>, how do I set library_hook to a Python function using ctypes?</p> <p>library.h:</p> ...
3
2009-01-29T16:31:41Z
492,640
<p>This is tricky in ctypes because ctypes function pointers do not implement the <code>.value</code> property used to set other pointers. Instead, cast your callback function and the extern function pointer to <code>void *</code> with the <code>c_void_p</code> function. After setting the function pointer as <code>void...
9
2009-01-29T17:39:14Z
[ "python", "ctypes" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
492,399
<p>EDIT: Other posters are probably correct...there might be spaces mixed in with your tabs. Try doing a search&amp;replace to replace all tabs with a few spaces.</p> <p>Try this:</p> <pre><code>import sys def Factorial(n): # return factorial result = 1 for i in range (1,n): result = result * i ...
282
2009-01-29T16:37:18Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
492,402
<p>The line: <code>result = result * i</code> should be indented (it is the body of the for-loop).</p> <p>Or - you have mixed space and tab characters</p>
6
2009-01-29T16:38:04Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
492,419
<p>Are you sure you are not mixing tabs and spaces in your indentation white space? (That will cause that error.)</p> <p>Note, it is recommended that you don't use tabs in Python code. See the <a href="http://www.python.org/dev/peps/pep-0008/">style guide</a>. You should configure Notepad++ to insert spaces for tabs.<...
26
2009-01-29T16:41:15Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
492,437
<p>Whenever I've encountered this error, it's because I've somehow mixed up tabs and spaces in my editor. </p>
12
2009-01-29T16:45:19Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
513,524
<p>To easily check for problems with tabs/spaces you can actually do this:</p> <pre><code>python -m tabnanny yourfile.py </code></pre> <p>or you can just set up your editor correctly of course :-)</p>
97
2009-02-04T21:50:28Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
11,748,465
<p>Looks to be an indentation problem. You don't have to match curly brackets in Python but you <em>do</em> have to match indentation levels.</p> <p>The best way to prevent space/tab problems is to display invisible characters within your text editor. This will give you a quick way to prevent and/or resolve indentati...
3
2012-07-31T20:27:51Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
17,070,370
<p>After setting up your editor following pep8, you still have problems. A good trick to solve this is replacing your four spaces by one tab. Actually python does not support 4 spaces in place of 1 tab. </p>
-4
2013-06-12T16:12:26Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
17,091,012
<p>If you use Python's IDLE editor you can do as it suggests in one of similar error messages:</p> <p>1) select all, e.g. Ctrl + A</p> <p>2) Go to Format -> Untabify Region</p> <p>3) Double check your indenting is still correct, save and rerun your program.</p> <p>I'm using Python 2.5.4</p>
7
2013-06-13T15:26:00Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
21,769,961
<p>It could be because the function above it is not indented the same way. i.e.</p> <pre><code>class a: def blah: print("Hello world") def blah1: print("Hello world") </code></pre>
0
2014-02-14T02:52:13Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
22,199,531
<p>This is because there is a mix-up of both tabs and spaces. You can either remove all the spaces and replace them with tabs.</p> <p>Or, Try writing this:</p> <pre><code>#!/usr/bin/python -tt </code></pre> <p>at the beginning of the code. This line resolves any differences between tabs and spaces.</p>
0
2014-03-05T13:43:15Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
22,268,518
<p>in my case, the problem was the configuration of pydev on Eclipse</p> <p><img src="http://i.stack.imgur.com/Ve5TD.png" alt="pydev @ Eclipse"></p>
0
2014-03-08T11:13:10Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
22,540,604
<p>If you use notepad++, do a "replace" with extended search mode to find \t and replace with four spaces.</p>
2
2014-03-20T17:23:01Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
23,540,812
<p><strong>IMPORTANT</strong>: <strong><em>Spaces are the preferred method</em></strong> - see PEP008 <a href="https://www.python.org/dev/peps/pep-0008/#indentation">Indentation</a> and <a href="https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces">Tabs or Spaces?</a>. (Thanks to @Siha for this.)</p> <p>For <code>...
86
2014-05-08T11:44:49Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
24,435,179
<p>I had the same issue yesterday, it was indentation error, was using sublime text editor. took my hours trying to fix it and at the end I ended up copying the code into VI text editor and it just worked fine. ps python is too whitespace sensitive, make sure not to mix space and tab.</p>
1
2014-06-26T15:57:37Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
27,257,674
<p>If you use Komodo editor you can do as it suggests in one of similar error messages:</p> <p>1) select all, e.g. Ctrl + A</p> <p>2) Go to Code -> Untabify Region</p> <p>3) Double check your indenting is still correct, save and rerun your program.</p> <p>I'm using Python 3.4.2</p>
0
2014-12-02T19:47:04Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
28,186,679
<p>If you are using Sublime text for python development,you can avoid the error by using the package Anaconda.After installing Anaconda,</p> <blockquote> <ol> <li>open your file in sublime</li> <li>right click on the open spaces</li> <li>choose anaconda</li> <li>click on autoformat</li> <li>DONE Or Press C...
0
2015-01-28T07:18:27Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
28,989,269
<p>On <a href="https://atom.io/" rel="nofollow">Atom</a></p> <p>go to </p> <pre><code>Packages &gt; Whitespace &gt; Convert Spaces to Tabs </code></pre> <p>Then check again your file indentation:</p> <pre><code>python -m tabnanny yourFile.py </code></pre> <p>or</p> <pre><code>&gt;python &gt;&gt;&gt; help("yourFil...
2
2015-03-11T14:27:23Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
30,097,361
<p>If you are using Vim, hit escape and then type </p> <p>gg=G</p> <p>This auto indents everything and will clear up any spaces you have thrown in.</p>
2
2015-05-07T09:43:20Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
31,676,628
<p>for Atom Users, <code>Packages -&gt;whitspace -&gt; remove trailing whitespaces</code> this worked for me </p>
0
2015-07-28T12:41:15Z
[ "python", "indentation" ]
IndentationError: unindent does not match any outer indentation level
492,387
<p>When I compile the Python code below, I get </p> <blockquote> <p>IndentationError: unindent does not match any outer indentation level</p> </blockquote> <hr> <pre><code>import sys def Factorial(n): # Return factorial result = 0 for i in range (1,n): result = result * i print "factorial is "...
243
2009-01-29T16:34:46Z
33,681,996
<p>Just a addition. I had a similar problem with the both indentations in Notepad++.</p> <ol> <li>Unexcepted indentation</li> <li><p>Outer Indentation Level</p> <p>Go to ----> Search tab ----> tap on <strong>replace</strong> ----> hit the radio button <strong>Extended</strong> below ---> Now replace \t with four spac...
0
2015-11-12T21:42:44Z
[ "python", "indentation" ]
Using Python split to splice a variable together
492,452
<p>I have this list </p> <pre><code>["camilla_farnestam@hotmail.com : martin00", ""], </code></pre> <p>How do I split so it only be left with:</p> <pre><code>camilla_farnestam@hotmail.com:martin00 </code></pre>
1
2009-01-29T16:49:56Z
492,456
<p>Do you want to have: <code>aList[0]</code> ? </p> <p><strong>EDIT::</strong><br /> Oh, you have a tuple with the list in it! Now I see:</p> <pre><code>al = ["camilla_farnestam@hotmail.com : martin00", ""], #type(al) == tuple #len(al) == 1 aList = al[0] #type(aList) == list #len(aList) == 2 #Now you can type: aLis...
3
2009-01-29T16:51:45Z
[ "python", "split" ]
Using Python split to splice a variable together
492,452
<p>I have this list </p> <pre><code>["camilla_farnestam@hotmail.com : martin00", ""], </code></pre> <p>How do I split so it only be left with:</p> <pre><code>camilla_farnestam@hotmail.com:martin00 </code></pre>
1
2009-01-29T16:49:56Z
492,464
<p>Exactly. </p> <pre> $ python Python 2.6 (r26:66714, Dec 4 2008, 11:34:15) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> al = ["camilla_farnestam@hotmail.com : martin00", ""] >>> print al[0] camilla_farnestam@hot...
1
2009-01-29T16:53:49Z
[ "python", "split" ]
Using Python split to splice a variable together
492,452
<p>I have this list </p> <pre><code>["camilla_farnestam@hotmail.com : martin00", ""], </code></pre> <p>How do I split so it only be left with:</p> <pre><code>camilla_farnestam@hotmail.com:martin00 </code></pre>
1
2009-01-29T16:49:56Z
492,465
<p>Abgan, is probably correct, although if you still want a list, ie., </p> <pre><code>["camilla_farnestam@hotmail.com : martin00"] </code></pre> <p>you'd want:</p> <pre><code>the_list[:1] </code></pre>
0
2009-01-29T16:54:02Z
[ "python", "split" ]
Using Python split to splice a variable together
492,452
<p>I have this list </p> <pre><code>["camilla_farnestam@hotmail.com : martin00", ""], </code></pre> <p>How do I split so it only be left with:</p> <pre><code>camilla_farnestam@hotmail.com:martin00 </code></pre>
1
2009-01-29T16:49:56Z
492,467
<p>lists can be accessed by index or sliced into smaller lists.<br> <a href="http://diveintopython3.ep.io/native-datatypes.html" rel="nofollow">http://diveintopython3.ep.io/native-datatypes.html</a></p>
0
2009-01-29T16:54:16Z
[ "python", "split" ]
Using Python split to splice a variable together
492,452
<p>I have this list </p> <pre><code>["camilla_farnestam@hotmail.com : martin00", ""], </code></pre> <p>How do I split so it only be left with:</p> <pre><code>camilla_farnestam@hotmail.com:martin00 </code></pre>
1
2009-01-29T16:49:56Z
492,477
<p>comma at the end means that list is first member of a tuple, but to your question:</p> <pre><code>in_list = ["camilla_farnestam@hotmail.com : martin00", ""] result = ''.join(in_list[0].split(' ')) </code></pre>
2
2009-01-29T16:56:37Z
[ "python", "split" ]
Using Python split to splice a variable together
492,452
<p>I have this list </p> <pre><code>["camilla_farnestam@hotmail.com : martin00", ""], </code></pre> <p>How do I split so it only be left with:</p> <pre><code>camilla_farnestam@hotmail.com:martin00 </code></pre>
1
2009-01-29T16:49:56Z
492,502
<pre><code>al = ["camilla_farnestam@hotmail.com : martin00", ""], print al[0][0].replace(" : ", ":") </code></pre>
3
2009-01-29T17:03:32Z
[ "python", "split" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
492,711
<p>Your code works when run in an script because Python encodes the output to whatever encoding your terminal application is using. If you are piping you must encode it yourself.</p> <p>A rule of thumb is: Always use Unicode internally. Decode what you receive, and encode what you send.</p> <pre><code># -*- coding: u...
120
2009-01-29T18:03:18Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
1,169,209
<p>First, regarding this solution:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö".encode('utf-8') </code></pre> <p>It's not practical to explicitly print with a given encoding every time. That would be repetitive and error-prone.</p> <p>A better solution is to change <strong><code>sys.stdout</code></strong> ...
129
2009-07-23T02:05:58Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
4,027,726
<p>You may want to try changing the environment variable "PYTHONIOENCODING" to "utf_8." I have written a <a href="http://daveagp.wordpress.com/2010/10/26/what-a-character/">page on my ordeal with this problem</a>.</p> <p>Tl;dr of the blog post:</p> <pre class="lang-python prettyprint-override"><code>import sys, local...
81
2010-10-26T20:30:35Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
6,362,647
<pre><code>export PYTHONIOENCODING=utf-8 </code></pre> <p>do the job, but can't set it on python itself ...</p> <p>what we can do is verify if isn't setting and tell the user to set it before call script with :</p> <pre><code>if __name__ == '__main__': if (sys.stdout.encoding is None): print &gt;&gt; sys...
38
2011-06-15T18:40:18Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
9,717,454
<p>I could "automate" it with a call to:</p> <pre><code>def __fix_io_encoding(last_resort_default='UTF-8'): import sys if [x for x in (sys.stdin,sys.stdout,sys.stderr) if x.encoding is None] : import os defEnc = None if defEnc is None : try: import locale defEnc = loca...
2
2012-03-15T09:59:11Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
15,556,504
<p>There's one simple answer: switch to Python 3!</p>
0
2013-03-21T19:36:30Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
21,384,318
<p>On Ubuntu 12.10 and GNOME Terminal, no error is produced when the program is printing to stdout or hooked to a pipe for other programs. Both file encoding and terminal encoding is <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow">UTF-8</a>.</p> <pre><code>$ cat a.py # -*- coding: utf-8 -*- print "åäö" ...
0
2014-01-27T15:09:25Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
22,260,303
<p>I just thought I'd mention something here which I had to spent a long time experimenting with before I finally realised what was going on. This may be so obvious to everyone here that they haven't bothered mentioning it. But it would've helped me if they had, so on that principle...!</p> <p>NB: I am using <a href="...
0
2014-03-07T20:44:05Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
29,603,050
<p>An arguable sanitized version of Craig McQueen's answer.</p> <pre><code>import sys, codecs class EncodedOut: def __init__(self, enc): self.enc = enc self.stdout = sys.stdout def __enter__(self): if sys.stdout.encoding is None: w = codecs.getwriter(self.enc) sy...
0
2015-04-13T10:24:12Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
30,960,847
<p>I had a <a href="https://stackoverflow.com/questions/30857027/youtube-api-unicodeencodeerror-in-python-3-4">similar issue last week</a>. It was easy to fix in my IDE (PyCharm).</p> <p>Here was my fix:</p> <p>Starting from PyCharm menu bar: File -> Settings... -> Editor -> File Encodings, then set: "IDE Encoding", ...
4
2015-06-21T02:54:18Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Setting the correct encoding when piping stdout in Python
492,483
<p>When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:</p> <pre><code># -*- coding: utf-8 -*- print u"åäö" </code></pre> <p>will work fine when run normally, but fail with:</p> <blockquote> <p>UnicodeEncodeError: 'a...
224
2009-01-29T16:57:59Z
38,927,473
<p>For all the people who still not have working her code all because a Ñ comes in the string: use this <code>string.encode( "cp850" )</code> instead of <code>string.encode( "utf8" )</code></p>
0
2016-08-12T22:54:13Z
[ "python", "encoding", "terminal", "stdout", "python-2.x" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
492,620
<p>If this is some kind of network or file operation, you might also consider using nonblocking IO. This can be a better option if you're doing a lot of these types of operations at once (otherwise, you can bog your system down fairly quickly with a lot of threads). <a href="http://www.amk.ca/python/howto/sockets/soc...
3
2009-01-29T17:32:29Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
494,273
<p>You may use the <a href="http://docs.python.org/library/signal.html">signal</a> package if you are running on UNIX:</p> <pre><code>In [1]: import signal # Register an handler for the timeout In [2]: def handler(signum, frame): ...: print "Forever is over!" ...: raise Exception("end of time") ...: ...
92
2009-01-30T02:14:04Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
12,295,927
<p>Here is a slight improvement to the given thread-based solution.</p> <p>The code below supports <strong>exceptions</strong>:</p> <pre><code>def runFunctionCatchExceptions(func, *args, **kwargs): try: result = func(*args, **kwargs) except Exception, message: return ["exception", message] ...
0
2012-09-06T08:25:33Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
13,821,695
<p>I have a different proposal which is a pure function (with the same API as the threading suggestion) and seems to work fine (based on suggestions on this thread)</p> <pre><code>def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None): import signal class TimeoutError(Exception): pass...
26
2012-12-11T13:41:31Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
14,924,210
<p>You can use <code>multiprocessing.Process</code> to do exactly that.</p> <p><strong>Code</strong></p> <pre><code>import multiprocessing import time # bar def bar(): for i in range(100): print "Tick" time.sleep(1) if __name__ == '__main__': # Start bar as a process p = multiprocessing....
58
2013-02-17T18:00:10Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
17,808,494
<p>We can use signals for the same. I think the below example will be useful for you. It is very simple compared to threads. </p> <pre><code>import signal def timeout(signum, frame): raise myException #this is an infinite loop, never ending under normal circumstances def main(): print 'Starting Main ', w...
0
2013-07-23T11:10:10Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
28,526,150
<p>The <code>stopit</code> package, found on pypi, seems to handle timeouts well.</p> <p>I like the <code>@stopit.threading_timeoutable</code> decorator, which adds a <code>timeout</code> parameter to the decorated function, which does what you expect, it stops the function.</p> <p>Check it out on pypi: <a href="http...
0
2015-02-15T12:43:32Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
31,667,005
<blockquote> <h1>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it?</h1> </blockquote> <p>I posted a <a href="https://gist.github.com/aaronchall/6331661fe0185c30a0b4" rel="nofollow">gist</a> that solves this question/problem with a decorator and a <cod...
10
2015-07-28T03:43:52Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
34,999,808
<p>I had a need for <strong>nestable</strong> timed interrupts (which SIGALARM can't do) that won't get blocked by time.sleep (which the thread-based approach can't do). I ended up copying and lightly modifying code from here: <a href="http://code.activestate.com/recipes/577600-queue-for-managing-multiple-sigalrm-alarm...
1
2016-01-25T18:36:02Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
35,139,284
<p>I ran across this thread when searching for a timeout call on unit tests. I didn't find anything simple in the answers or 3rd party packages so I wrote the decorator below you can drop right into code:</p> <pre><code>import multiprocessing.pool import functools def timeout(max_timeout): """Timeout decorator, ...
14
2016-02-01T20:02:32Z
[ "python", "multithreading", "timeout", "python-multithreading" ]
Timeout on a function call
492,519
<p>I'm calling a function in Python which I know may stall and force me to restart the script. </p> <p>How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?</p>
95
2009-01-29T17:08:29Z
36,891,240
<pre><code>#!/usr/bin/python2 import sys, subprocess, threading proc = subprocess.Popen(sys.argv[2:]) timer = threading.Timer(float(sys.argv[1]), proc.terminate) timer.start() proc.wait() timer.cancel() exit(proc.returncode) </code></pre>
0
2016-04-27T13:27:21Z
[ "python", "multithreading", "timeout", "python-multithreading" ]