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
Count Parenthesis in a file with a Python program?
1,878,167
<p>I Wanna fix a function through it i can count how many times are used the:(,),[,] if the counts of ( are equal to those of ) and if the counts of [ are equal to those of ] then i have valid syntax!</p> <p>my first -dissapointed- try:</p> <pre><code>filename=input("Give a file name:") def parenthesis(filename): ...
0
2009-12-10T01:45:40Z
1,878,234
<p>I believe, You are looking for balanced symbol checker. It is better to use stack.</p> <ol> <li><p>Make an empty stack,</p></li> <li><p>For each symbol in the string:</p> <p>2.1 If the symbol is an opening symbol, push it on the stack.</p> <p>2.2 If it is a closing symbol, then</p> <p>2.2.1 If the stack is empty...
1
2009-12-10T02:08:06Z
[ "python", "exception", "file", "parentheses" ]
Count Parenthesis in a file with a Python program?
1,878,167
<p>I Wanna fix a function through it i can count how many times are used the:(,),[,] if the counts of ( are equal to those of ) and if the counts of [ are equal to those of ] then i have valid syntax!</p> <p>my first -dissapointed- try:</p> <pre><code>filename=input("Give a file name:") def parenthesis(filename): ...
0
2009-12-10T01:45:40Z
1,879,063
<p>All of these answers are wrong and will not work in all cases, so either use python parser e.g. tokenize etc or just use this</p> <p>count = min(text.count("("), text.count(")"))</p>
0
2009-12-10T06:38:29Z
[ "python", "exception", "file", "parentheses" ]
Count Parenthesis in a file with a Python program?
1,878,167
<p>I Wanna fix a function through it i can count how many times are used the:(,),[,] if the counts of ( are equal to those of ) and if the counts of [ are equal to those of ] then i have valid syntax!</p> <p>my first -dissapointed- try:</p> <pre><code>filename=input("Give a file name:") def parenthesis(filename): ...
0
2009-12-10T01:45:40Z
1,879,289
<p>Please excuse the length of this reply.</p> <p>If I understand you correctly, you want to do simple syntax checking of parentheses to make sure they are balanced correctly. In your question you specify a test based on simple counting, but as others have pointed out, this does not catch things like "([)]".</p> <p>I...
2
2009-12-10T07:48:05Z
[ "python", "exception", "file", "parentheses" ]
Python directory searching and organizing by dict
1,878,247
<p>Hey all, this is my first time recently trying to get into the file and os part of Python. I am trying to search a directory then find all sub directories. If the directory has no folders, add all the files to a list. And organize them all by dict.</p> <p>So for instance a tree could look like this</p> <ul> <li>St...
0
2009-12-10T02:14:46Z
1,878,335
<p>There is a basic problem with the way you want to structure the data. If <code>dir1/subdir1</code> contains subdirectories and files, should <code>dict['dir1']['subdir1']</code> be a list or a dictionary? To access further subdirectories with <code>...['subdir2']</code> it needs to be a dictionary, but on the other ...
1
2009-12-10T02:41:40Z
[ "python", "path", "directory", "subdirectory", "os.walk" ]
Python directory searching and organizing by dict
1,878,247
<p>Hey all, this is my first time recently trying to get into the file and os part of Python. I am trying to search a directory then find all sub directories. If the directory has no folders, add all the files to a list. And organize them all by dict.</p> <p>So for instance a tree could look like this</p> <ul> <li>St...
0
2009-12-10T02:14:46Z
1,878,474
<p>I don't know why you would want to do this. You should be able to do your processing using <code>os.path.walk</code>, but in case you really need such a structure, you can do (untested):</p> <pre><code>import os def dirfunc(fdict, dirname, fnames): tmpdict = fdict keys = dirname.split(os.sep)[:-1] for...
1
2009-12-10T03:31:49Z
[ "python", "path", "directory", "subdirectory", "os.walk" ]
Python directory searching and organizing by dict
1,878,247
<p>Hey all, this is my first time recently trying to get into the file and os part of Python. I am trying to search a directory then find all sub directories. If the directory has no folders, add all the files to a list. And organize them all by dict.</p> <p>So for instance a tree could look like this</p> <ul> <li>St...
0
2009-12-10T02:14:46Z
1,879,011
<p>Maybe you want something like:</p> <pre><code>def explore(starting_path): alld = {'': {}} for dirpath, dirnames, filenames in os.walk(starting_path): d = alld dirpath = dirpath[len(starting_path):] for subd in dirpath.split(os.sep): based = d d = d[subd] if dirnames: for dn in...
3
2009-12-10T06:27:11Z
[ "python", "path", "directory", "subdirectory", "os.walk" ]
RabbitMQ gives a "access refused, login refused for user" error when attempting to follow the celery tutorial
1,878,306
<p>I'm attempting to follow the <a href="http://ask.github.com/celery/introduction.html#usage" rel="nofollow">celery tutorial</a>, but I run into a problem when I run <code>python manage.py celeryd</code>: my RabbitMQ server (installed on a virtual machine on my dev box) won't let my user login.</p> <p>I get the follo...
4
2009-12-10T02:31:55Z
1,949,851
<p>Are you running django? If so, then try this:</p> <pre><code>&gt;&gt;&gt; from carrot.connection import DjangoBrokerConnection &gt;&gt;&gt; c = DjangoBrokerConnection() &gt;&gt;&gt; c.connection </code></pre> <p>Does it give the same thing? Are you sure you're connecting to the right hostname, and that the usernam...
5
2009-12-22T23:19:28Z
[ "python", "django", "rabbitmq", "amqp", "celery" ]
What signal can be connected to an initial dialog display in pyqt4 (qt)
1,878,353
<p>I have an application in which I would like to connect whatever signal is emitted when a pyqt4 dialog is displayed in order to do execute an initial method. I don't want the method to be called in the <code>__init__</code> method for a number of reasons. I've spent quite some time searching but I have yet to find an...
1
2009-12-10T02:49:02Z
1,879,368
<p>There is no signal emitted on first display, instead, you will have to intercept the first <code>resizeEvent</code> or <code>paintEvent</code> by overloading these methods (as you don't want to initialize from the <code>__init__</code> method).</p> <p>Another option would be to add your own <code>showAndInit</code>...
3
2009-12-10T08:08:46Z
[ "python", "qt", "pyqt4" ]
Add tuple to list of tuples in Python
1,878,470
<p>I am new to python and don't know the best way to do this.</p> <p>I have a list of tuples which represent points and another list which represents offsets. I need a set of all the combinations that this forms. Here's some code:</p> <pre><code>offsets = [( 0, 0),( 0,-1),( 0, 1),( 1, 0),(-1, 0)] points = [( 1, 5),( ...
13
2009-12-10T03:29:54Z
1,878,486
<p>Pretty simple:</p> <pre><code>&gt;&gt;&gt; rslt = [] &gt;&gt;&gt; for x, y in points: ... for dx, dy in offsets: ... rslt.append( (x+dx, y+dy) ) ... &gt;&gt;&gt; rslt [(1, 5), (1, 4), (1, 6), (2, 5), (0, 5), (3, 3), (3, 2), (3, 4), (4, 3), (2, 3), (8, 7), (8, 6), (8, 8), (9, 7), (7, 7)] </code></pre> ...
11
2009-12-10T03:35:49Z
[ "python", "tuples" ]
Add tuple to list of tuples in Python
1,878,470
<p>I am new to python and don't know the best way to do this.</p> <p>I have a list of tuples which represent points and another list which represents offsets. I need a set of all the combinations that this forms. Here's some code:</p> <pre><code>offsets = [( 0, 0),( 0,-1),( 0, 1),( 1, 0),(-1, 0)] points = [( 1, 5),( ...
13
2009-12-10T03:29:54Z
1,878,488
<pre><code>result = [(x+dx, y+dy) for x,y in points for dx,dy in offsets] </code></pre> <p>For more, see <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions">list comprehensions</a>.</p>
25
2009-12-10T03:37:00Z
[ "python", "tuples" ]
Add tuple to list of tuples in Python
1,878,470
<p>I am new to python and don't know the best way to do this.</p> <p>I have a list of tuples which represent points and another list which represents offsets. I need a set of all the combinations that this forms. Here's some code:</p> <pre><code>offsets = [( 0, 0),( 0,-1),( 0, 1),( 1, 0),(-1, 0)] points = [( 1, 5),( ...
13
2009-12-10T03:29:54Z
1,878,492
<p>If you don't care about duplicates in the result:</p> <pre><code>result = [] for ox, oy in offsets: for px, py in points: result.append((px + ox, py + oy)) </code></pre> <p>If you do care about duplicates in the result:</p> <pre><code>result = set() for ox, oy in offsets: for px, py in points: ...
4
2009-12-10T03:39:31Z
[ "python", "tuples" ]
Add tuple to list of tuples in Python
1,878,470
<p>I am new to python and don't know the best way to do this.</p> <p>I have a list of tuples which represent points and another list which represents offsets. I need a set of all the combinations that this forms. Here's some code:</p> <pre><code>offsets = [( 0, 0),( 0,-1),( 0, 1),( 1, 0),(-1, 0)] points = [( 1, 5),( ...
13
2009-12-10T03:29:54Z
1,878,842
<p>Personally, I like Alok's answer. However, for fans of <a href="http://docs.python.org/library/itertools.html#itertools.product">itertools</a>, the itertools-based equivalent (in Python 2.6 and later) is:</p> <pre><code>import itertools as it ps = [(x+dx, y+dy) for (x, y), (dx, dy) in it.product(points, offsets)] ...
7
2009-12-10T05:42:35Z
[ "python", "tuples" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
1,878,760
<p>Try this</p> <pre><code>&gt;&gt;&gt; status=type('status',(object,),{})() &gt;&gt;&gt; status.foo=3 &gt;&gt;&gt; status.foo 3 </code></pre> <p>You don't have to give the class a name if you don't want to</p> <pre><code>&gt;&gt;&gt; status=type('',(object,),{})() &gt;&gt;&gt; status.__class__.__name__ '' </code></...
3
2009-12-10T05:15:09Z
[ "python" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
1,878,775
<p>From the <a href="http://docs.python.org/tutorial/classes.html#odds-and-ends">Python Official Documentation</a>:</p> <blockquote> <p>9.7. Odds and Ends</p> <p>Sometimes it is useful to have a data type similar to the Pascal “record” or C “struct”, bundling together a few named data items. An em...
14
2009-12-10T05:21:33Z
[ "python" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
1,878,786
<p>The mystery here is the difference between <strong><em>objects</em></strong> and <strong><em>class instances</em></strong>. </p> <p>In Python, everything is an object. Classes are objects, integers are objects, types are objects, and class instances are objects. When you say <code>object()</code> you're getting a p...
2
2009-12-10T05:25:06Z
[ "python" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
1,878,789
<p>I had the same question once. I asked it in a mailing list, and Alex Martelli pointed out that <code>object</code> is the basis of all inheritance in Python; if <code>object()</code> created a class instance with its own dictionary, then every object in Python would have to have its own dictionary, and that would w...
8
2009-12-10T05:26:03Z
[ "python" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
1,878,803
<p>The most concise way to make "a generic object to which you can assign/fetch attributes" is probably:</p> <pre><code>b = lambda:0 </code></pre> <p>As most other answers point out, there are many other ways, but it's hard to beat this one for conciseness (<code>lambda:0</code> is exactly the same number of characte...
17
2009-12-10T05:31:21Z
[ "python" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
1,880,526
<p>I personally think that the cleanest solution is what you already guessed:</p> <pre><code>class Scratch(object): pass s = Scratch() s.whatever = 'you want' </code></pre> <p>I know you said that you don't want a <code>__dict__</code>, but that confuses me as I can't see a reason to care about that. You don't ...
4
2009-12-10T12:04:01Z
[ "python" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
21,100,151
<p>Of course there's always a <a href="http://stackoverflow.com/a/2970722/623735"><code>namedtuple</code></a>. It's cheap and fast, but immutable -- you must know your attribute names and values in advance, and you can't alter their values later. But at least it has the struct/object attribute getters. And it'll work ...
2
2014-01-13T19:53:35Z
[ "python" ]
struct objects in python
1,878,710
<p>I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style)</p> <pre><code>&gt;&gt;&gt; status = object() &gt;&gt;&gt; status.foo = 3 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'object' object ...
8
2009-12-10T04:55:04Z
40,026,445
<p>If you want the semantics of a Javascript object, you could consider using the <a href="http://github.com/pcattori/namespaces" rel="nofollow">namespaces library</a>. You just need to <code>pip install namespaces</code> first.</p> <pre><code>&gt;&gt;&gt; import namespaces as ns &gt;&gt;&gt; b = ns.Namespace() &gt;&g...
1
2016-10-13T16:32:22Z
[ "python" ]
How to Determine The Module a Particular Exception Class is Defined In
1,878,801
<p>Note: i edited my Q (in the title) so that it better reflects what i actually want to know. In the original title and in the text of my Q, i referred to the source of the thrown exception; what i meant, and what i should have referred to, as pointed out in one of the high-strung but otherwise helpful response below...
2
2009-12-10T05:31:17Z
1,878,833
<p>Usually, I just read the documentation. Part of the documentation for a Python module or function is a list of the exceptions it defines. If it doesn't list anything, I just assume I'm looking for a Python builtin exception.</p> <p>By the way, the StopIteration exception is the standard way for any Python "iterab...
4
2009-12-10T05:39:29Z
[ "python", "exception", "exception-handling", "module" ]
How to Determine The Module a Particular Exception Class is Defined In
1,878,801
<p>Note: i edited my Q (in the title) so that it better reflects what i actually want to know. In the original title and in the text of my Q, i referred to the source of the thrown exception; what i meant, and what i should have referred to, as pointed out in one of the high-strung but otherwise helpful response below...
2
2009-12-10T05:31:17Z
1,878,834
<p>Usually I wrap the bare minimum that I can in a try..except block, e.g.:</p> <pre><code>try: os.rename('foo', 'bar') except EnvironmentError: ... try: open('bar') except EnvironmentError: ... </code></pre> <p>This way I can handle each exception appropriately and separately.</p>
1
2009-12-10T05:40:09Z
[ "python", "exception", "exception-handling", "module" ]
How to Determine The Module a Particular Exception Class is Defined In
1,878,801
<p>Note: i edited my Q (in the title) so that it better reflects what i actually want to know. In the original title and in the text of my Q, i referred to the source of the thrown exception; what i meant, and what i should have referred to, as pointed out in one of the high-strung but otherwise helpful response below...
2
2009-12-10T05:31:17Z
1,878,871
<blockquote> <p>the second [[exception was thrown]] from a python core module</p> </blockquote> <p>False: it was thrown from a call to <code>cursor.next</code>, <strong>exactly</strong> like the first one was thrown from a call to <code>cursor.execute</code> -- it's hard to say why you're baldly asserting this count...
5
2009-12-10T05:52:19Z
[ "python", "exception", "exception-handling", "module" ]
How to Determine The Module a Particular Exception Class is Defined In
1,878,801
<p>Note: i edited my Q (in the title) so that it better reflects what i actually want to know. In the original title and in the text of my Q, i referred to the source of the thrown exception; what i meant, and what i should have referred to, as pointed out in one of the high-strung but otherwise helpful response below...
2
2009-12-10T05:31:17Z
1,878,872
<p>Exception is somehow part of the function signature. The 1st thing to do is to read the documentation, the list of exception it can throw should be given. That's the case in most modules.</p> <p>In your code, you should catch the minimum exception and just have one general catch at the top of your code (in your mai...
1
2009-12-10T05:52:38Z
[ "python", "exception", "exception-handling", "module" ]
How to Determine The Module a Particular Exception Class is Defined In
1,878,801
<p>Note: i edited my Q (in the title) so that it better reflects what i actually want to know. In the original title and in the text of my Q, i referred to the source of the thrown exception; what i meant, and what i should have referred to, as pointed out in one of the high-strung but otherwise helpful response below...
2
2009-12-10T05:31:17Z
1,878,929
<p>You could use python's <code>inspect</code> module and generic Exception handling like so:</p> <pre><code>from inspect import getmodule try: # attempt some task except Exception, e: print getmodule(e) </code></pre> <p>Which will spit out the module and its path like so:</p> <pre><code>&lt;module 'some.mod...
1
2009-12-10T06:08:10Z
[ "python", "exception", "exception-handling", "module" ]
Should I take a Python CS class using Windows or Mac?
1,878,904
<p>I'll be taking a Python-based computer science class next semester using my MacBook Pro. It will be centered around a custom-designed <a href="http://myro.roboteducation.org/" rel="nofollow">package</a> for this class. The problem is that this package is being sponsored by Microsoft Research, so it was obviously des...
2
2009-12-10T05:59:57Z
1,878,914
<p>If the class expects the code to run on Windows then I would install a VM with Windows on it since it is possible that some things may not work quite the same way (especially if you are doing system-specific things like file-system access or executing OS commands).</p> <p>Classwork/homework always goes smoother whe...
9
2009-12-10T06:03:17Z
[ "python", "windows", "osx", "compatibility" ]
Should I take a Python CS class using Windows or Mac?
1,878,904
<p>I'll be taking a Python-based computer science class next semester using my MacBook Pro. It will be centered around a custom-designed <a href="http://myro.roboteducation.org/" rel="nofollow">package</a> for this class. The problem is that this package is being sponsored by Microsoft Research, so it was obviously des...
2
2009-12-10T05:59:57Z
1,878,917
<p>Definitely start with Mac. If it turns out that it really does need Windows, you can switch once you're sure. But Python development is definitely more natural on a Unix-based machine.</p> <p>Most online graders will let you submit multiple times, and the first assignment is usually easy, so you should know pretty ...
4
2009-12-10T06:04:30Z
[ "python", "windows", "osx", "compatibility" ]
Should I take a Python CS class using Windows or Mac?
1,878,904
<p>I'll be taking a Python-based computer science class next semester using my MacBook Pro. It will be centered around a custom-designed <a href="http://myro.roboteducation.org/" rel="nofollow">package</a> for this class. The problem is that this package is being sponsored by Microsoft Research, so it was obviously des...
2
2009-12-10T05:59:57Z
1,878,925
<p>If they will be testing your code on windows then you really need to be targeting that platform. However if you feel more comfortable on the Mac, do your dev there but also run a virtual win machine so you can test on the target platform. I would suggest the excellent <a href="http://www.virtualbox.org/" rel="nofoll...
3
2009-12-10T06:07:03Z
[ "python", "windows", "osx", "compatibility" ]
Should I take a Python CS class using Windows or Mac?
1,878,904
<p>I'll be taking a Python-based computer science class next semester using my MacBook Pro. It will be centered around a custom-designed <a href="http://myro.roboteducation.org/" rel="nofollow">package</a> for this class. The problem is that this package is being sponsored by Microsoft Research, so it was obviously des...
2
2009-12-10T05:59:57Z
1,878,930
<p>From <a href="http://wiki.roboteducation.org/MacOSX%5FSetup" rel="nofollow">their site</a> it looks like Mac is fully supported (up to 10.5 -- it's true that 10.6 is different enough to give occasional problems... I haven't upgraded yet even though I did buy a family pack of 10.5 to 10.6 upgrades, as I'm not looking...
3
2009-12-10T06:08:19Z
[ "python", "windows", "osx", "compatibility" ]
Should I take a Python CS class using Windows or Mac?
1,878,904
<p>I'll be taking a Python-based computer science class next semester using my MacBook Pro. It will be centered around a custom-designed <a href="http://myro.roboteducation.org/" rel="nofollow">package</a> for this class. The problem is that this package is being sponsored by Microsoft Research, so it was obviously des...
2
2009-12-10T05:59:57Z
1,878,937
<p>Go Mac and never go back.</p> <p>More seriously, a Mac offers UNIX environment, and Windows offers blue screens.</p>
0
2009-12-10T06:09:28Z
[ "python", "windows", "osx", "compatibility" ]
Should I take a Python CS class using Windows or Mac?
1,878,904
<p>I'll be taking a Python-based computer science class next semester using my MacBook Pro. It will be centered around a custom-designed <a href="http://myro.roboteducation.org/" rel="nofollow">package</a> for this class. The problem is that this package is being sponsored by Microsoft Research, so it was obviously des...
2
2009-12-10T05:59:57Z
1,885,103
<p>Develop and test on a Mac. If it works on the Mac, then test it on Windows before submitting. Done this tons of times with my own programming courses, albeit with a different set of languages and technologies.</p>
2
2009-12-11T00:37:09Z
[ "python", "windows", "osx", "compatibility" ]
Order a list of files by size via python
1,879,081
<p>Example dump from the list of a directory:</p> <pre><code>hello:3.1 GB world:1.2 MB foo:956.2 KB </code></pre> <p>The above list is in the format of FILE:VALUE UNIT. How would one go about ordering each line above according to file size?</p> <p>I thought perhaps to parse each line for the unit via the pattern ":V...
1
2009-12-10T06:42:13Z
1,879,101
<pre><code>thelines = ['hello:3.1 GB', 'world:1.2 MB', 'foo:956.2 KB'] mult = dict(KB=2**10, MB=2**20, GB=2**30) def getsize(aline): fn, size = aline.split(':', 1) value, unit = size.split(' ') multiplier = mult[unit] return float(value) * multiplier thelines.sort(key=getsize) print thelines </code></pre> <...
9
2009-12-10T06:47:53Z
[ "python", "arrays", "hash", "dictionary", "order" ]
wxPython - How to get the ID of a widget when you passed in -1?
1,879,694
<p>I'm doing a little wxPython work today and I've got this piece of code (I've stripped out the irrelevant parts):</p> <pre><code> def CreateRowOne(self, pan): hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(wx.Button(pan, -1, "250 Words"), 1, wx.EXPAND | wx.ALL) hbox1.Add(wx.B...
1
2009-12-10T09:09:44Z
1,879,731
<blockquote> <blockquote> <p>Am I going to have to manually assign the ID numbers?</p> </blockquote> </blockquote> <p>No, putting <code>-1</code> or using <code>wx.NewId()</code> will give you autogenerated ID.</p> <p>and You can always get id with <code>button1.GetID()</code> or <code>button1.Id</code> back ...
2
2009-12-10T09:18:02Z
[ "python", "wxpython" ]
wxPython - How to get the ID of a widget when you passed in -1?
1,879,694
<p>I'm doing a little wxPython work today and I've got this piece of code (I've stripped out the irrelevant parts):</p> <pre><code> def CreateRowOne(self, pan): hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(wx.Button(pan, -1, "250 Words"), 1, wx.EXPAND | wx.ALL) hbox1.Add(wx.B...
1
2009-12-10T09:09:44Z
1,881,764
<p>I recommend <em>not</em> doing "sizer.Add(wx.Button(...))". It's better to separate widget creation and layout. Is there a compelling reason to write your code the way you have? Why not write it like this:</p> <pre><code>button1=wx.Button(pan, wx.ID_ANY, ...) button2=wx.Button(pan, wx.ID_ANY, ...) ... hbox1.Add(bu...
1
2009-12-10T15:29:29Z
[ "python", "wxpython" ]
wxPython - How to get the ID of a widget when you passed in -1?
1,879,694
<p>I'm doing a little wxPython work today and I've got this piece of code (I've stripped out the irrelevant parts):</p> <pre><code> def CreateRowOne(self, pan): hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(wx.Button(pan, -1, "250 Words"), 1, wx.EXPAND | wx.ALL) hbox1.Add(wx.B...
1
2009-12-10T09:09:44Z
1,899,745
<p>You can get id by control.GetID() but you do not need to get ID to bind, you can just do this</p> <pre><code>self.btn.Bind(wx.EVT_BUTTON, self._onBtnClick) </code></pre> <p>It is preferable(id should be implementation detail) and short e.g. in this sample</p> <pre><code>import wx app = wx.PySimpleApp() frame = w...
3
2009-12-14T08:53:03Z
[ "python", "wxpython" ]
Python Ascendance and descendance
1,879,851
<p>I apologize in advance for the basic level of my question. I would like to the print the:</p> <ul> <li>total number and identity of nodes that have 0 child, 1 child, 2 children, 3 children.</li> <li>total number of node that have 0 parent, 1 parent, 2 parents, 3 parents.</li> </ul> <p>here is my simple script. tha...
0
2009-12-10T09:37:50Z
1,879,959
<p>You can either create a map and do it yourself or use itertools.groupBy</p> <p>1) Do-it-yourself way:</p> <pre><code>nodes_by_num_children={} for node in search: children=len(node.get_children()) if children not in nodes_by_num_children: nodes_by_num_children[children]=[] nodes_by_num_children[children]....
1
2009-12-10T09:58:35Z
[ "python" ]
Python Ascendance and descendance
1,879,851
<p>I apologize in advance for the basic level of my question. I would like to the print the:</p> <ul> <li>total number and identity of nodes that have 0 child, 1 child, 2 children, 3 children.</li> <li>total number of node that have 0 parent, 1 parent, 2 parents, 3 parents.</li> </ul> <p>here is my simple script. tha...
0
2009-12-10T09:37:50Z
1,879,973
<pre><code>from collections import defaultdict by_parents = defaultdict(list) by_children = defaultdict(list) for node in search_nodes(): parents = node.get_parents() by_parents[len(parents)].append(node) children = node.get_children() by_children[len(children)].append(node) </code></pre>
1
2009-12-10T10:01:34Z
[ "python" ]
DJANGO : Update div with AJAX
1,879,872
<p>I am building a chat application. So far I am adding chat messages with jquery $.post() and this works fine.</p> <p>Now I need to retrieve the latest chat message from the table and append the list on the chat page. I am new to Django, so please go slow.</p> <p>So how do I get data from the chat table back to the ...
5
2009-12-10T09:42:32Z
1,879,991
<p>Since you're already using an AJAX post, why don't you return the data from that and insert it into the div? The view that accepts the post can return a rendered template or JSON, and your javascript can insert it in the callback.</p>
2
2009-12-10T10:07:08Z
[ "jquery", "python", "ajax", "django", "django-templates" ]
DJANGO : Update div with AJAX
1,879,872
<p>I am building a chat application. So far I am adding chat messages with jquery $.post() and this works fine.</p> <p>Now I need to retrieve the latest chat message from the table and append the list on the chat page. I am new to Django, so please go slow.</p> <p>So how do I get data from the chat table back to the ...
5
2009-12-10T09:42:32Z
1,881,894
<p>My favorite technique for this kind of thing is to use an <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags">inclusion tag</a></p> <p>basically you make a separate template for rendering the individual objects in the page template</p> <p>page template:</p> <pre><code>{% load...
13
2009-12-10T15:48:54Z
[ "jquery", "python", "ajax", "django", "django-templates" ]
DJANGO : Update div with AJAX
1,879,872
<p>I am building a chat application. So far I am adding chat messages with jquery $.post() and this works fine.</p> <p>Now I need to retrieve the latest chat message from the table and append the list on the chat page. I am new to Django, so please go slow.</p> <p>So how do I get data from the chat table back to the ...
5
2009-12-10T09:42:32Z
1,883,266
<p>There's a lot going on in order to make this process work...</p> <ul> <li>The client regularly polls the server for new chat entries</li> <li>The server checks for and only replies with the newest </li> <li>The client receives the newest entries and appends them to the DOM</li> </ul> <p>This can be confusing when ...
2
2009-12-10T19:11:31Z
[ "jquery", "python", "ajax", "django", "django-templates" ]
Retrieve the source of a dynamic website using python (bypassing onclick)
1,879,876
<p>I wish to retrieve the source of a website, that is dynamically generated upon clicking a link. The link itself is as below:</p> <pre><code>&lt;a onclick="function(); return false" href="#"&gt;Link&lt;/a&gt; </code></pre> <p>This stops me from directly querying for a URL that would allow me to get the dynamically ...
0
2009-12-10T09:43:03Z
1,879,911
<p>You will probably have to reverse engineer the JavaScript to work out what is going on.</p> <p>Can you provide the site and the link in question?</p>
2
2009-12-10T09:49:54Z
[ "javascript", "python", "onclick", "urllib2", "urllib" ]
Retrieve the source of a dynamic website using python (bypassing onclick)
1,879,876
<p>I wish to retrieve the source of a website, that is dynamically generated upon clicking a link. The link itself is as below:</p> <pre><code>&lt;a onclick="function(); return false" href="#"&gt;Link&lt;/a&gt; </code></pre> <p>This stops me from directly querying for a URL that would allow me to get the dynamically ...
0
2009-12-10T09:43:03Z
1,880,945
<p>I don't immediately see any content-generation or link-following code in that script; all <code>importText</code> does is toggle whether a few divs are shown.</p> <p>If you want to study the calls the webapp makes to do a particular action, in order to reproduce them from a bot, you're probably best off looking at ...
1
2009-12-10T13:24:41Z
[ "javascript", "python", "onclick", "urllib2", "urllib" ]
Decoding packed data into a structure
1,879,914
<p>What would the best way of unpacking a python string into fields</p> <p>I have data received from a tcp socket, it is packed as follows, I believe it will be in a string from the socket recv function</p> <p>It has the following format</p> <p>uint8 - header<br> uint8 - length<br> uint32 - typeID<br> uint16 -param1...
3
2009-12-10T09:50:46Z
1,879,940
<p>use <a href="http://docs.python.org/library/struct.html" rel="nofollow"><code>struct</code></a> module</p>
4
2009-12-10T09:55:12Z
[ "python", "string", "unpack" ]
Decoding packed data into a structure
1,879,914
<p>What would the best way of unpacking a python string into fields</p> <p>I have data received from a tcp socket, it is packed as follows, I believe it will be in a string from the socket recv function</p> <p>It has the following format</p> <p>uint8 - header<br> uint8 - length<br> uint32 - typeID<br> uint16 -param1...
3
2009-12-10T09:50:46Z
1,879,955
<p>Take a look at the module '<a href="http://docs.python.org/library/struct.html" rel="nofollow">struct</a>'.</p>
0
2009-12-10T09:57:43Z
[ "python", "string", "unpack" ]
Decoding packed data into a structure
1,879,914
<p>What would the best way of unpacking a python string into fields</p> <p>I have data received from a tcp socket, it is packed as follows, I believe it will be in a string from the socket recv function</p> <p>It has the following format</p> <p>uint8 - header<br> uint8 - length<br> uint32 - typeID<br> uint16 -param1...
3
2009-12-10T09:50:46Z
1,880,427
<p>Is this the best way of doing this or is there a better way</p> <p>It is likely that there will be strings with other formats which will require a different unpacking scheme</p> <p>field1 = struct.unpack('B',data[0])<br> field2 = struct.unpack('B',data[1])<br> field3 = struct.unpack('!I',data[2:6])<br> field4 = st...
1
2009-12-10T11:41:50Z
[ "python", "string", "unpack" ]
Decoding packed data into a structure
1,879,914
<p>What would the best way of unpacking a python string into fields</p> <p>I have data received from a tcp socket, it is packed as follows, I believe it will be in a string from the socket recv function</p> <p>It has the following format</p> <p>uint8 - header<br> uint8 - length<br> uint32 - typeID<br> uint16 -param1...
3
2009-12-10T09:50:46Z
1,880,563
<p>The struct module is designed to unpack heterogeneous data to a tuple based on a format string. It makes more sense to unpack the whole struct at once rather than trying to pull out one field at a time. Here is an example:</p> <pre><code>fields = struct.unpack('!BBI4H20sIB', data) </code></pre> <p>Then you can acc...
6
2009-12-10T12:09:30Z
[ "python", "string", "unpack" ]
Decoding packed data into a structure
1,879,914
<p>What would the best way of unpacking a python string into fields</p> <p>I have data received from a tcp socket, it is packed as follows, I believe it will be in a string from the socket recv function</p> <p>It has the following format</p> <p>uint8 - header<br> uint8 - length<br> uint32 - typeID<br> uint16 -param1...
3
2009-12-10T09:50:46Z
1,880,886
<p>This is an answer to your question-as-an-answer:</p> <p>It certainly can't be the best way, because it DOESN'T WORK. <code>struct.unpack()</code> always returns a tuple. To pluck out the single item in that tuple, you need to do either <code>field1 = struct.unpack('B',data[0])[0]</code> or <code>field1, = struct.un...
4
2009-12-10T13:09:30Z
[ "python", "string", "unpack" ]
How to run the program generated by pyuic4?
1,880,039
<p>I'm new to PyQt though I know python a bit.. I wanted to Qt designer for GUI programming since it'll make my job easier. I've taken a simple dialog in Qt designer and converted using pyuic4.</p> <pre><code>from PyQt4 import QtCore, QtGui class Ui_Form1(object): def setupUi(self, Form1): Form1.setObject...
0
2009-12-10T10:20:22Z
1,880,132
<p>You may pass <code>-x</code> parameter to pyuic. It will generate addtional code to make the script executable.</p> <p><hr></p> <p>In real application you should better write a subclass of <code>QMainWindow</code> which could look like this:</p> <pre><code># Store this code in the file MyMainWindow.py from PyQt4....
3
2009-12-10T10:41:12Z
[ "python", "qt", "pyqt", "qt-designer" ]
Use Python to insert xml markup around the difference of two strings
1,880,356
<p>I have an <code>oldstring</code>:</p> <pre><code>'foobarba &lt;span class="foo"&gt;z&lt;/span&gt;' </code></pre> <p>and a <code>newstring</code>:</p> <pre><code>'foodbar ba&lt;span class="foo"&gt;z&lt;/span&gt;' </code></pre> <p>a string is given for a classname, it could be <code>"foo"</code> again, let's say <...
0
2009-12-10T11:25:09Z
1,880,432
<p>Use <code>difflib</code> from the stdlib to find differences between your strings, then just insert your span tags around the diffs.</p>
1
2009-12-10T11:43:19Z
[ "python", "html", "parsing", "string" ]
Using a file to store optparse arguments
1,880,404
<p>I've been using optparse for a while now, and would like to add the ability to load the arguments from a config file. </p> <p>So far the best I can think of is a wrapper batch script with the arguments hardcoded... seems clunky.</p> <p>What is the most elegant way to do this? </p>
14
2009-12-10T11:35:10Z
1,880,422
<p>That's what the <code>set_defaults</code> function is for. <a href="http://docs.python.org/library/optparse.html#optparse.OptionParser.set%5Fdefaults" rel="nofollow">http://docs.python.org/library/optparse.html#optparse.OptionParser.set%5Fdefaults</a></p> <p>Create a file that's the dictionary of default values.</...
3
2009-12-10T11:40:56Z
[ "python", "optparse" ]
Using a file to store optparse arguments
1,880,404
<p>I've been using optparse for a while now, and would like to add the ability to load the arguments from a config file. </p> <p>So far the best I can think of is a wrapper batch script with the arguments hardcoded... seems clunky.</p> <p>What is the most elegant way to do this? </p>
14
2009-12-10T11:35:10Z
1,880,642
<p>I agree with S.Lott's idea of using a config file, but I'd recommend using the built-in <a href="http://docs.python.org/library/configparser.html">ConfigParser</a> (configparser in 3.0) module to parse it, rather than a home-brewed solution.</p> <p>Here's a brief script that illustrates ConfigParser and <a href="ht...
21
2009-12-10T12:23:42Z
[ "python", "optparse" ]
Using a file to store optparse arguments
1,880,404
<p>I've been using optparse for a while now, and would like to add the ability to load the arguments from a config file. </p> <p>So far the best I can think of is a wrapper batch script with the arguments hardcoded... seems clunky.</p> <p>What is the most elegant way to do this? </p>
14
2009-12-10T11:35:10Z
1,883,991
<p>You can use <a href="http://argparse.googlecode.com/svn/trunk/doc/ArgumentParser.html#fromfile-prefix-chars"><code>argparse</code></a> module for that:</p> <pre><code>&gt;&gt;&gt; open('args.txt', 'w').write('-f\nbar') &gt;&gt;&gt; parser = argparse.ArgumentParser(fromfile_prefix_chars='@') &gt;&gt;&gt; parser.add_...
7
2009-12-10T21:00:38Z
[ "python", "optparse" ]
Using a file to store optparse arguments
1,880,404
<p>I've been using optparse for a while now, and would like to add the ability to load the arguments from a config file. </p> <p>So far the best I can think of is a wrapper batch script with the arguments hardcoded... seems clunky.</p> <p>What is the most elegant way to do this? </p>
14
2009-12-10T11:35:10Z
2,211,056
<p>I had a similar problem, but also wanted to specific the config file as an argument. Inspired by S. Lott's answer, I came up with the following code.</p> <p>Example terminal session:</p> <pre>$ python defaultconf.py # use hard-coded defaults False $ python defaultconf.py --verbose # verbose on command line True $ ...
4
2010-02-05T22:59:12Z
[ "python", "optparse" ]
Using a file to store optparse arguments
1,880,404
<p>I've been using optparse for a while now, and would like to add the ability to load the arguments from a config file. </p> <p>So far the best I can think of is a wrapper batch script with the arguments hardcoded... seems clunky.</p> <p>What is the most elegant way to do this? </p>
14
2009-12-10T11:35:10Z
6,657,174
<p>Read the arguments in the same commandline format from a file e.g. @commands, then use your original parser to parse them. </p> <pre><code>options, args = parser.parse_args() if args[0][0] == '@': # script.py @optfile with open(args[0][1:]) as f: fa = [l.strip() for l in f] fa = fa + args[1:] # pu...
2
2011-07-11T21:57:59Z
[ "python", "optparse" ]
Using a file to store optparse arguments
1,880,404
<p>I've been using optparse for a while now, and would like to add the ability to load the arguments from a config file. </p> <p>So far the best I can think of is a wrapper batch script with the arguments hardcoded... seems clunky.</p> <p>What is the most elegant way to do this? </p>
14
2009-12-10T11:35:10Z
7,755,372
<p>I've built a lot of scripts with flags and options lately, and I've come up with the solution described <a href="http://www.maurobianchi.it/node/66" rel="nofollow">here</a>.</p> <p>Basically I instance an optionparser with a special flag that tells to try and load options from a file, so you can use normally your s...
0
2011-10-13T14:06:45Z
[ "python", "optparse" ]
Large functionality change based on variables
1,880,619
<p>I'm in a situation where I've got a project that has a large number of Django views across quite a few different apps. The same codebase and database is being used by a large number of clients. There are a few site-specific use-cases that are coming in and this requires quite a bit of custom code to be written.</p> ...
1
2009-12-10T12:20:24Z
1,881,051
<p>The most pythonic way would be to use classes for your views and then use inheritance to override specific parts of each view. In your description you describe something which sounds exactly like inheritance.</p> <p>There are two relevant SO questions you might want to look at <a href="http://stackoverflow.com/que...
3
2009-12-10T13:41:38Z
[ "django", "python" ]
pythonic way to explode a list of tuples
1,880,683
<p>I need to do the opposite of this</p> <p><a href="http://stackoverflow.com/questions/756550/multiple-tuple-to-two-pair-tuple-in-python">http://stackoverflow.com/questions/756550/multiple-tuple-to-two-pair-tuple-in-python</a></p> <p>Namely, I have a list of tuples</p> <pre><code>[(1,2), (3,4), (5,6)] </code></pre>...
5
2009-12-10T12:31:24Z
1,880,706
<p>The most efficient way to do it is this:</p> <pre><code>tuples = [(1,2), (3,4), (5,6)] [item for t in tuples for item in t] </code></pre> <p>output</p> <pre><code>[1, 2, 3, 4, 5, 6] </code></pre> <p>Here is <a href="http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python/95299...
17
2009-12-10T12:35:39Z
[ "python", "list" ]
pythonic way to explode a list of tuples
1,880,683
<p>I need to do the opposite of this</p> <p><a href="http://stackoverflow.com/questions/756550/multiple-tuple-to-two-pair-tuple-in-python">http://stackoverflow.com/questions/756550/multiple-tuple-to-two-pair-tuple-in-python</a></p> <p>Namely, I have a list of tuples</p> <pre><code>[(1,2), (3,4), (5,6)] </code></pre>...
5
2009-12-10T12:31:24Z
1,880,707
<pre><code>l = [(1,2), (3,4), (5,6)] reduce (lambda x,y: x+list(y), l, []) </code></pre>
2
2009-12-10T12:35:41Z
[ "python", "list" ]
pythonic way to explode a list of tuples
1,880,683
<p>I need to do the opposite of this</p> <p><a href="http://stackoverflow.com/questions/756550/multiple-tuple-to-two-pair-tuple-in-python">http://stackoverflow.com/questions/756550/multiple-tuple-to-two-pair-tuple-in-python</a></p> <p>Namely, I have a list of tuples</p> <pre><code>[(1,2), (3,4), (5,6)] </code></pre>...
5
2009-12-10T12:31:24Z
1,880,797
<pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; tp = [(1,2),(3,4),(5,6)] &gt;&gt;&gt; lst = list(itertools.chain(*tp)) &gt;&gt;&gt; lst [1, 2, 3, 4, 5, 6] </code></pre> <p>Of course, if you don't need a list but an iterator, you can drop the <code>list()</code> conversion call.</p>
6
2009-12-10T12:52:46Z
[ "python", "list" ]
How to upgrade the version of Python used by Apache?
1,880,746
<p>On a Red hat box, I upgraded Python from 2.3 to 2.6.4 and changed the symlink to <code>python</code> so when I type in <code>python</code> the 2.6.4 interpreter comes up.</p> <p>However my .py file works from the command-line, but not in the browser. It seemed like a <code>sys.path</code> issue so I opened the file...
2
2009-12-10T12:42:41Z
1,881,774
<p>On RH box Apache probably runs as root user. Login as root and see which version of python root sees.</p> <p>HIH</p> <p>..richie</p>
0
2009-12-10T15:30:06Z
[ "python", "apache", "upgrade", "sys.path" ]
How to upgrade the version of Python used by Apache?
1,880,746
<p>On a Red hat box, I upgraded Python from 2.3 to 2.6.4 and changed the symlink to <code>python</code> so when I type in <code>python</code> the 2.6.4 interpreter comes up.</p> <p>However my .py file works from the command-line, but not in the browser. It seemed like a <code>sys.path</code> issue so I opened the file...
2
2009-12-10T12:42:41Z
1,881,796
<p>If you're using <a href="http://www.modpython.org/" rel="nofollow"><code>mod_python</code></a> or <a href="http://code.google.com/p/modwsgi/" rel="nofollow"><code>mod_wsgi</code></a>, you should reinstall them as they've probably been built to the python version you had when they were first installed on the system (...
2
2009-12-10T15:32:58Z
[ "python", "apache", "upgrade", "sys.path" ]
How to upgrade the version of Python used by Apache?
1,880,746
<p>On a Red hat box, I upgraded Python from 2.3 to 2.6.4 and changed the symlink to <code>python</code> so when I type in <code>python</code> the 2.6.4 interpreter comes up.</p> <p>However my .py file works from the command-line, but not in the browser. It seemed like a <code>sys.path</code> issue so I opened the file...
2
2009-12-10T12:42:41Z
1,882,006
<p>Apache isn't calling python directly, so the path is irrelevant. You will probably want to build yourself a new mod_wsgi to link against python 2.6.4.</p>
1
2009-12-10T16:01:06Z
[ "python", "apache", "upgrade", "sys.path" ]
Does 'p' have a special meaning in Django?
1,880,753
<p>Why are p and p8 different in the following code?</p> <p>The beginning of a view function (in file views.py in a Django app named "proteinSearch" with a model named "Protein" that has a field named "description"):</p> <pre><code>def searchForProteins2(request, searchStr): p8 = Protein.objects.filter( descripti...
2
2009-12-10T12:44:16Z
1,880,815
<p>When you are in Debugging mode (pdb or ipdb), at that momemt 'p' is meant for a specific functionality, i.e. evaluating an expression expr.</p> <p>Like, </p> <pre><code>ipdb&gt; x = 1 ipdb&gt; p x 1 ipdb&gt; p x==True True ipdb&gt; p x==1 True </code></pre> <p>In Django, 'p' will simply means a variable.</p> <p>...
13
2009-12-10T12:57:04Z
[ "python", "django" ]
How to get the absolute path of a file using tkFileDialog?
1,881,202
<p>I am using:</p> <pre><code>file = tkFileDialog.askopenfile(parent=root, mode='rb', filetypes=[('Subrip Subtitle File','*.srt')], title='Choose a subtitle file') </code></pre> <p>to get a file object specified by the user. </p> <p>Is there any way I can get the absolute path of this file from the file obje...
5
2009-12-10T14:06:48Z
1,881,211
<p><a href="http://docs.python.org/library/os.path.html#os.path.abspath" rel="nofollow"><code>os.path.abspath</code></a> should do what you want, if I understand your question correctly.</p>
3
2009-12-10T14:08:47Z
[ "python", "file", "tkinter", "dialog" ]
How to get the absolute path of a file using tkFileDialog?
1,881,202
<p>I am using:</p> <pre><code>file = tkFileDialog.askopenfile(parent=root, mode='rb', filetypes=[('Subrip Subtitle File','*.srt')], title='Choose a subtitle file') </code></pre> <p>to get a file object specified by the user. </p> <p>Is there any way I can get the absolute path of this file from the file obje...
5
2009-12-10T14:06:48Z
1,881,313
<pre><code>file = tkFileDialog.askopenfile(parent=root,mode='rb',filetypes=[('Subrip Subtitle File','*.srt')],title='Choose a subtitle file') abs_path = os.path.abspath(file.name) </code></pre>
12
2009-12-10T14:25:18Z
[ "python", "file", "tkinter", "dialog" ]
pyExcelerator has problems reading some files
1,881,253
<p>I've got a problem using pyExcelerator when reading some xls-files.</p> <p>There're some python scripts i wrote, that use this library to parse XLS-files and populate database with info.</p> <p>The templates for the files these scripts parse may vary and i sometimes reconfigure the script to handle them. With the...
0
2009-12-10T14:13:47Z
1,881,293
<p>You might wish to give xlrd a try... it started (I believe) as a fork of pyExcelerator, so incorporating requires few code changes, but it is actively maintained:</p> <p><a href="http://pypi.python.org/pypi/xlrd" rel="nofollow">http://pypi.python.org/pypi/xlrd</a></p> <p><a href="http://www.python-excel.org/" rel=...
1
2009-12-10T14:21:02Z
[ "python", "excel", "xls", "pyexcelerator" ]
pyExcelerator has problems reading some files
1,881,253
<p>I've got a problem using pyExcelerator when reading some xls-files.</p> <p>There're some python scripts i wrote, that use this library to parse XLS-files and populate database with info.</p> <p>The templates for the files these scripts parse may vary and i sometimes reconfigure the script to handle them. With the...
0
2009-12-10T14:13:47Z
1,906,419
<p>I'm the author of xlrd. It <strong>r</strong>ea**d**s XLS files and is not a fork of anything. I maintain a package called xlwt which <strong>w</strong>ri**t**es XLS files and is a fork of pyExcelerator. The parse_xls functionality in pyExcelerator was deprecated to the point of removal from xlwt. Use xlrd instead.<...
2
2009-12-15T10:13:22Z
[ "python", "excel", "xls", "pyexcelerator" ]
What is the best way to get a stacktrace when using multiprocessing?
1,881,338
<p>I'm wondering about the best way to get a stacktrace when there is an exception inside a function executed via the multiprocessing module. Here's an example:</p> <pre><code>import multiprocessing def square(x): raise Exception("Crash.") return x**2 if __name__ == '__main__': pool = multiprocessing.Poo...
15
2009-12-10T14:28:34Z
1,881,690
<p>It looks like you should avoid raising the exception from your main function. Instead, you can catch it, treat it as a value returned to the main program, then raise it there. <a href="http://nedbatchelder.com/blog/200711/rethrowing%5Fexceptions%5Fin%5Fpython.html">Re-throwing exceptions in Python</a> has more det...
10
2009-12-10T15:21:13Z
[ "python", "multiprocessing" ]
What is the best way to get a stacktrace when using multiprocessing?
1,881,338
<p>I'm wondering about the best way to get a stacktrace when there is an exception inside a function executed via the multiprocessing module. Here's an example:</p> <pre><code>import multiprocessing def square(x): raise Exception("Crash.") return x**2 if __name__ == '__main__': pool = multiprocessing.Poo...
15
2009-12-10T14:28:34Z
24,741,045
<p>In Python 3.4, full traceback is provided.</p> <p><a href="http://bugs.python.org/issue13831" rel="nofollow">http://bugs.python.org/issue13831</a></p>
2
2014-07-14T16:16:07Z
[ "python", "multiprocessing" ]
Is there any scripting SVG editor?
1,881,476
<p>I would like to edit SVG files using some scripting language (preferably Python). In particular, I would like to merge two SVG files, add some annotations, and arrange them in a larger image. Is there any software available for such purposes?</p> <p>Thanks,</p> <p>Bartosz</p> <h2>UPDATE</h2> <p>I finally decided...
7
2009-12-10T14:52:38Z
1,881,483
<p>You could use something like <a href="http://lxml.de/" rel="nofollow">lxml</a> - after all SVG files are XML. It's available from PyPI pip: <a href="https://pypi.python.org/pypi/lxml/" rel="nofollow">https://pypi.python.org/pypi/lxml/</a></p>
4
2009-12-10T14:54:11Z
[ "python", "svg", "vector-graphics" ]
Is there any scripting SVG editor?
1,881,476
<p>I would like to edit SVG files using some scripting language (preferably Python). In particular, I would like to merge two SVG files, add some annotations, and arrange them in a larger image. Is there any software available for such purposes?</p> <p>Thanks,</p> <p>Bartosz</p> <h2>UPDATE</h2> <p>I finally decided...
7
2009-12-10T14:52:38Z
1,881,514
<p>I don't know if you could do what you describe, but <a href="http://www.inkscape.org/" rel="nofollow">Inkscape</a> supports some degree of <a href="http://wiki.inkscape.org/wiki/index.php/ScriptingHOWTO" rel="nofollow">scripting with Python</a>.</p>
3
2009-12-10T14:58:27Z
[ "python", "svg", "vector-graphics" ]
Is there any scripting SVG editor?
1,881,476
<p>I would like to edit SVG files using some scripting language (preferably Python). In particular, I would like to merge two SVG files, add some annotations, and arrange them in a larger image. Is there any software available for such purposes?</p> <p>Thanks,</p> <p>Bartosz</p> <h2>UPDATE</h2> <p>I finally decided...
7
2009-12-10T14:52:38Z
25,435,657
<p>Very late answer, but in case it helps anyone, I have written an very small extension for Inkscape that allows writing short python code snippets from within Inkscape. </p> <pre><code>* http://www.smanohar.com/inkscape.php </code></pre> <p>You can type up to 5 lines and iterate over objects in the current selecti...
1
2014-08-21T20:46:53Z
[ "python", "svg", "vector-graphics" ]
Python stacktrace help
1,881,485
<p>I have this stack trace error when I try view some data in my Python website, could some one clue me up as to what the problem is I am so lost </p> <pre><code> Environment: Request Method: GET Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/ Django Version: 1.1.1 Python Versio...
0
2009-12-10T14:54:24Z
1,881,526
<p>Look at the last line:</p> <p>In</p> <pre><code>/var/www/mywesbite/src/mywebsite/../mywesbite/shop/models.py </code></pre> <p>in the <code>__unicode__</code> method you have a line:</p> <pre><code>return ", ".join((str(self.account),self.date.strftime("%b. %d, %Y, %H:%M %p"))) </code></pre> <p>and that <code>se...
1
2009-12-10T14:59:50Z
[ "python", "django", "stack-trace" ]
Python stacktrace help
1,881,485
<p>I have this stack trace error when I try view some data in my Python website, could some one clue me up as to what the problem is I am so lost </p> <pre><code> Environment: Request Method: GET Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/ Django Version: 1.1.1 Python Versio...
0
2009-12-10T14:54:24Z
1,881,528
<p>The significant piece is in the last few lines (remember that the most recent call, ie: the one that cause the error, is always printed last in a stacktrace):</p> <pre><code> File "/var/www/mywesbite/src/mywebsite/../mywesbite/shop/models.py", line 1105, in __unicode__ return ", ".join((str(self.account),...
5
2009-12-10T14:59:55Z
[ "python", "django", "stack-trace" ]
Python stacktrace help
1,881,485
<p>I have this stack trace error when I try view some data in my Python website, could some one clue me up as to what the problem is I am so lost </p> <pre><code> Environment: Request Method: GET Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/ Django Version: 1.1.1 Python Versio...
0
2009-12-10T14:54:24Z
1,881,794
<p>Well the problem is in the <strong>unicode</strong> method of the PasswordResetRequest model defined in shop/models.py. You try to access self.date on this object and it doesn't have a date attribute.</p> <p>Maybe if you paste your model I could help more...</p>
0
2009-12-10T15:32:27Z
[ "python", "django", "stack-trace" ]
Python stacktrace help
1,881,485
<p>I have this stack trace error when I try view some data in my Python website, could some one clue me up as to what the problem is I am so lost </p> <pre><code> Environment: Request Method: GET Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/ Django Version: 1.1.1 Python Versio...
0
2009-12-10T14:54:24Z
1,883,383
<p>there was no reference of date is should of been issued</p>
0
2009-12-10T19:29:24Z
[ "python", "django", "stack-trace" ]
how (in maya) can i get the 3D position of the mouse?
1,881,592
<p>i have created a dragger context in maya using the following code, pos holds my 2D coordinates of mouse cursor, i want to convert it into 3D coordinate to be the source of the ray i want to launch,, i want it either through python scripting or through the python api,, </p> <pre><code>import maya.cmds as mc mc.drag...
0
2009-12-10T15:07:33Z
2,377,884
<p>Have you reviewed the projection (-pr) options for the draggerContext? </p> <p>Mouse co-ordinates is data across 2 dimensions, and the projection options are methods to resolve how the 3rd dimension is mapped. For rays, maybe one of the following options is relevant to your question:</p> <p>xAxis project to cl...
0
2010-03-04T08:47:50Z
[ "python", "scripting", "3d", "maya", "autodesk" ]
how (in maya) can i get the 3D position of the mouse?
1,881,592
<p>i have created a dragger context in maya using the following code, pos holds my 2D coordinates of mouse cursor, i want to convert it into 3D coordinate to be the source of the ray i want to launch,, i want it either through python scripting or through the python api,, </p> <pre><code>import maya.cmds as mc mc.drag...
0
2009-12-10T15:07:33Z
8,246,719
<p>Actually, you might wanna look into the <strong>space(sp)</strong> flag in the <strong>draggerContext</strong> command help.</p> <pre><code>mc.draggerContext('sampleContext', dragCommand='getCursorPos()', space='world') def getCursorPos(): print mc.draggerContext( 'testContext', query=1, dragPoint=1) </code><...
1
2011-11-23T17:43:52Z
[ "python", "scripting", "3d", "maya", "autodesk" ]
How to transfer a file between two FTP servers?
1,881,752
<p>I have two ftp servers with fxp enabled on both, I'm just wondering how I would transfer a file between the two servers in Python? I was told curl wouldnt do it, but maybe ftplib will do.</p> <p>so, the file (file.txt) is in '/personal/' FTP1 and I want to transfer that to FTP2 also to the same place, '/personal/'<...
2
2009-12-10T15:28:53Z
1,881,806
<p>The simplest thing to is call the shell from within python, and then scp your file from one computer to the other. It shouldn't be very costly, almost nothing compared with the transfer costs, so don't worry about performance. </p> <p>Just try </p> <pre><code>os.system('scp myfile othermachine.jack.com:/transfers'...
0
2009-12-10T15:34:08Z
[ "python", "ftp", "ftplib" ]
How to transfer a file between two FTP servers?
1,881,752
<p>I have two ftp servers with fxp enabled on both, I'm just wondering how I would transfer a file between the two servers in Python? I was told curl wouldnt do it, but maybe ftplib will do.</p> <p>so, the file (file.txt) is in '/personal/' FTP1 and I want to transfer that to FTP2 also to the same place, '/personal/'<...
2
2009-12-10T15:28:53Z
1,884,573
<p>You should use ftplib (<a href="http://docs.python.org/library/ftplib.html" rel="nofollow">http://docs.python.org/library/ftplib.html</a>)</p>
2
2009-12-10T22:36:49Z
[ "python", "ftp", "ftplib" ]
How to unpickle from C code
1,881,851
<p>I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code.<br> I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing abo...
1
2009-12-10T15:41:09Z
1,881,867
<p>take a look at module <code>struct</code> ?</p>
0
2009-12-10T15:44:00Z
[ "python", "c" ]
How to unpickle from C code
1,881,851
<p>I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code.<br> I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing abo...
1
2009-12-10T15:41:09Z
1,881,871
<p>You might want to use something more standardized, like <a href="http://www.json.org/" rel="nofollow">JSON</a>. You have a JSON module in Python 2.6. There are 6 different JSON modules for C. </p> <p>You might want to use something more C-like, like the Python <code>struct</code> module. It can build a C-compat...
5
2009-12-10T15:44:49Z
[ "python", "c" ]
How to unpickle from C code
1,881,851
<p>I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code.<br> I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing abo...
1
2009-12-10T15:41:09Z
1,881,878
<p>Check out the chapter on Serializing Data in Mark Pilgrim's <a href="http://diveintopython3.org/serializing.html" rel="nofollow">Dive Into Python</a>. He states there that "The pickle protocol is Python-specific; there is no guarantee of cross-language compatibility. You probably couldn’t take the [...] pickle fil...
1
2009-12-10T15:46:11Z
[ "python", "c" ]
How to unpickle from C code
1,881,851
<p>I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code.<br> I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing abo...
1
2009-12-10T15:41:09Z
1,881,942
<p>If it's just a matrix, you could just write it out as a CSV file. Look at the Python csv module for this. <a href="http://docs.python.org/library/csv.html" rel="nofollow">http://docs.python.org/library/csv.html</a></p>
3
2009-12-10T15:53:38Z
[ "python", "c" ]
How to unpickle from C code
1,881,851
<p>I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code.<br> I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing abo...
1
2009-12-10T15:41:09Z
1,882,086
<p>If you absolutely must use pickling, you can embed Python in your C program and unpickle in C via Python.</p> <ul> <li><a href="http://www.linuxjournal.com/article/8497" rel="nofollow">A quick example from Linux Journal</a></li> <li><a href="http://docs.python.org/extending/extending.html#calling-python-functions-f...
1
2009-12-10T16:12:01Z
[ "python", "c" ]
How to unpickle from C code
1,881,851
<p>I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code.<br> I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing abo...
1
2009-12-10T15:41:09Z
1,882,093
<p>Besides JSON, there are also the <a href="http://code.google.com/p/protobuf/" rel="nofollow"><strong>Google Protocol Buffers</strong></a> which have 'native' support (from Google) for Python, C++ and Java -- and a number of third-party bindings to other languages including C.</p>
0
2009-12-10T16:12:35Z
[ "python", "c" ]
How to unpickle from C code
1,881,851
<p>I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code.<br> I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing abo...
1
2009-12-10T15:41:09Z
1,882,121
<p><a href="http://code.google.com/p/protobuf/" rel="nofollow">Protocol Buffers</a> are an interesting approach to serialize information in a cross-language way that's also quite compact and fast (support for C, as opposed to C++, isn't part of the protobuf package as released, but linking in some C++ code may be accep...
2
2009-12-10T16:15:48Z
[ "python", "c" ]
Python: Httplib2 Module Not Found
1,882,465
<p>I tried to import the module but i am getting the error shown below:-</p> <pre><code>sh-3.2# python -V Python 2.6.4 sh-3.2# python -c "import httplib2" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: No module named httplib2 </code></pre> <p>How to fix this Error?...
13
2009-12-10T17:09:25Z
1,882,498
<p><a href="http://code.google.com/p/httplib2/downloads/list">Download</a> it?</p> <p>Make sure it's on your PYTHONPATH</p>
5
2009-12-10T17:13:18Z
[ "python", "httplib2" ]
Python: Httplib2 Module Not Found
1,882,465
<p>I tried to import the module but i am getting the error shown below:-</p> <pre><code>sh-3.2# python -V Python 2.6.4 sh-3.2# python -c "import httplib2" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: No module named httplib2 </code></pre> <p>How to fix this Error?...
13
2009-12-10T17:09:25Z
1,882,503
<p>I suppose you could start by installing <a href="http://code.google.com/p/httplib2/">httplib2</a>.</p>
8
2009-12-10T17:13:35Z
[ "python", "httplib2" ]
Python: Httplib2 Module Not Found
1,882,465
<p>I tried to import the module but i am getting the error shown below:-</p> <pre><code>sh-3.2# python -V Python 2.6.4 sh-3.2# python -c "import httplib2" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: No module named httplib2 </code></pre> <p>How to fix this Error?...
13
2009-12-10T17:09:25Z
1,882,512
<p>You need to install the httplib2 package from your package manager.</p> <p>On Ubuntu: <code>sudo apt-get install python-httplib2</code></p>
12
2009-12-10T17:14:26Z
[ "python", "httplib2" ]
Python: Httplib2 Module Not Found
1,882,465
<p>I tried to import the module but i am getting the error shown below:-</p> <pre><code>sh-3.2# python -V Python 2.6.4 sh-3.2# python -c "import httplib2" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: No module named httplib2 </code></pre> <p>How to fix this Error?...
13
2009-12-10T17:09:25Z
6,468,823
<p><code>httplib2</code> is not part of the Python standard library. It's an external package you must install yourself.</p> <p>using <a href="http://www.pip-installer.org/">pip</a>:</p> <pre><code>pip install httplib2 </code></pre>
25
2011-06-24T13:55:52Z
[ "python", "httplib2" ]
Python: Httplib2 Module Not Found
1,882,465
<p>I tried to import the module but i am getting the error shown below:-</p> <pre><code>sh-3.2# python -V Python 2.6.4 sh-3.2# python -c "import httplib2" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: No module named httplib2 </code></pre> <p>How to fix this Error?...
13
2009-12-10T17:09:25Z
39,599,078
<p>Suppose you can start by installing it like : </p> <pre><code>$ pip install httplib2 </code></pre> <p>you can try the same thing with <code>easy install</code> too, or if you wanted to install in locally and not over the network then go to <a href="https://github.com/jcgregorio/httplib2" rel="nofollow">httplib2 gi...
0
2016-09-20T16:14:28Z
[ "python", "httplib2" ]
How do I transfer data in .csv file into my sqlite database in django?
1,882,469
<p>This is my models.py</p> <pre><code>from django.db import models class School(models.Model): school = models.CharField(max_length=300) def __unicode__(self): return self.school class Lawyer(models.Model): firm_url = models.URLField('Bio', max_length=200) firm_name = models.CharField('Fi...
1
2009-12-10T17:10:35Z
1,882,533
<p>I created a complete script using this data as a test:</p> <pre><code>"http://www.graychase.com/aabbas","Gray &amp; Chase LLP","Amr A","Abbas","The George Washington University Law School","2005" "http://www.graychase.com/kadam","Gray &amp; Chase LLP","Karin","Adam","Ernst Moritz Arndt University Greifswald","2004"...
5
2009-12-10T17:17:09Z
[ "python", "django", "csv" ]
Creating an Python/py2app application that simply opens a terminal on launch?
1,882,644
<p>I've written a nice Python application that is basically an HTTP proxy for SMS modems, and I'd like to make it a double-clickable application on Macs. So far I've been including a .commmand file which is double-clickable, which basically consists of</p> <pre><code>cd `dirname $0` (sleep 8;open http://127.0.0.1:8080...
2
2009-12-10T17:33:06Z
1,883,260
<p>If you're looking for 'easy', try just giving your python script a <code>.command</code> suffix, and make sure it's executable. For example:</p> <pre><code>#!/usr/bin/env python # file: hello.command print 'hello world' </code></pre> <p>If you're looking for 'polished', then you probably want to learn about Laun...
1
2009-12-10T19:09:44Z
[ "python", "osx", "py2app" ]
Creating an Python/py2app application that simply opens a terminal on launch?
1,882,644
<p>I've written a nice Python application that is basically an HTTP proxy for SMS modems, and I'd like to make it a double-clickable application on Macs. So far I've been including a .commmand file which is double-clickable, which basically consists of</p> <pre><code>cd `dirname $0` (sleep 8;open http://127.0.0.1:8080...
2
2009-12-10T17:33:06Z
1,891,761
<p>Write an AppleScript application that launches Terminal and runs your Python script (which will be inside the application's bundle).</p>
0
2009-12-12T00:41:10Z
[ "python", "osx", "py2app" ]
Creating an Python/py2app application that simply opens a terminal on launch?
1,882,644
<p>I've written a nice Python application that is basically an HTTP proxy for SMS modems, and I'd like to make it a double-clickable application on Macs. So far I've been including a .commmand file which is double-clickable, which basically consists of</p> <pre><code>cd `dirname $0` (sleep 8;open http://127.0.0.1:8080...
2
2009-12-10T17:33:06Z
1,891,763
<p>If you don't actually need a terminal, but instead just want an app wrapper around a script, have a look at <a href="http://www.sveinbjorn.org/platypus" rel="nofollow">Platypus</a></p>
1
2009-12-12T00:43:09Z
[ "python", "osx", "py2app" ]
Importing Excel sheets, including formulae, into Django
1,883,098
<p>I have an Excel spreadsheet with calculations I would like to use in a Django web application. I do not need to present the spreadsheet as it appears in Excel. I only want to use the formulae embedded in it. What is the best way to do this?</p>
2
2009-12-10T18:39:35Z
1,883,874
<p>I think the only thing you can do is use some python/excel mechanism (the only one I could find was this: <a href="http://www.python-excel.org/" rel="nofollow">http://www.python-excel.org/</a>; the <a href="http://python-excel.googlegroups.com/web/python-excel.pdf" rel="nofollow">tutorial</a> makes me think it might...
0
2009-12-10T20:42:01Z
[ "python", "django", "excel" ]
Importing Excel sheets, including formulae, into Django
1,883,098
<p>I have an Excel spreadsheet with calculations I would like to use in a Django web application. I do not need to present the spreadsheet as it appears in Excel. I only want to use the formulae embedded in it. What is the best way to do this?</p>
2
2009-12-10T18:39:35Z
1,936,401
<p>You can control Excel with Python via COM. See this thread: <a href="http://stackoverflow.com/questions/441758/driving-excel-from-python-in-windows">http://stackoverflow.com/questions/441758/driving-excel-from-python-in-windows</a></p> <p>It might be a challenge to get this to work reliably as part of a Django app....
4
2009-12-20T17:23:16Z
[ "python", "django", "excel" ]
Importing Excel sheets, including formulae, into Django
1,883,098
<p>I have an Excel spreadsheet with calculations I would like to use in a Django web application. I do not need to present the spreadsheet as it appears in Excel. I only want to use the formulae embedded in it. What is the best way to do this?</p>
2
2009-12-10T18:39:35Z
1,937,261
<p>You need to use Excel to calculate the results? I mean, maybe you could run the Excel sheet from OpenOffice and use a pyUNO macro, which is somehow "native" python. </p> <p>A different approach will be to create a macro to generate some more friendly code to python, if you want Excel to perform the calculation is e...
0
2009-12-20T22:10:42Z
[ "python", "django", "excel" ]
Importing Excel sheets, including formulae, into Django
1,883,098
<p>I have an Excel spreadsheet with calculations I would like to use in a Django web application. I do not need to present the spreadsheet as it appears in Excel. I only want to use the formulae embedded in it. What is the best way to do this?</p>
2
2009-12-10T18:39:35Z
1,937,547
<p>In addition to the COM solution, <a href="http://pypi.python.org/pypi/xlrd" rel="nofollow">xlrd</a> is cross-platform. That might be more suitable, since I believe Linux is still the most common deployment environment for django. It's also a lighter-weight solution than pyUno.</p>
1
2009-12-20T23:57:08Z
[ "python", "django", "excel" ]