title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How to import a python file in python script more than once | 276,679 | <p>Is it possible to import a python file more than once in a python script because i run a loop back to my driver file in a function by using the import command but it only works once? thanks</p>
<p><strong>edit:</strong> Resolved myself thanks</p>
| 1 | 2008-11-09T23:40:27Z | 276,696 | <p>You most probably should not use import for what you are trying to do.</p>
<p>Without further information I can only guess, but you should move the code in the module you import from the top level into a function, do the import once and than simply call the function from you loop.</p>
| 7 | 2008-11-09T23:51:56Z | [
"python"
] |
How to import a python file in python script more than once | 276,679 | <p>Is it possible to import a python file more than once in a python script because i run a loop back to my driver file in a function by using the import command but it only works once? thanks</p>
<p><strong>edit:</strong> Resolved myself thanks</p>
| 1 | 2008-11-09T23:40:27Z | 277,463 | <p>While Tom Ley's answer is the correct approach, it <em>is</em> possible to import a module more than once, using the reload built-in.</p>
<pre><code>module.py:
print "imported!"
>>> import module
imported!
>>> reload(module)
imported!
<module 'module' from 'module.pyc'>
</code></pre>
<p>No... | 1 | 2008-11-10T09:53:09Z | [
"python"
] |
Exposing a C++ API to Python | 276,761 | <p>I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.</p>
<p>The alternatives I tried were:</p>
<ul>
<li><p>Boost.Python</p>
<p>I liked the cleaner API produced by... | 34 | 2008-11-10T00:34:50Z | 277,306 | <p>I've used both (for the same project): Boost is better integrated with the STL, and especially C++ exceptions. Also, its memory management mechanism (which tries to bridge C++ memory management and Python GC) is way more flexible than SWIG's. However, SWIG has <em>much</em> better documentation, no external depend... | 19 | 2008-11-10T07:41:53Z | [
"c++",
"python",
"boost",
"swig"
] |
Exposing a C++ API to Python | 276,761 | <p>I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.</p>
<p>The alternatives I tried were:</p>
<ul>
<li><p>Boost.Python</p>
<p>I liked the cleaner API produced by... | 34 | 2008-11-10T00:34:50Z | 277,308 | <p><a href="http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/" rel="nofollow">pyrex</a> or <a href="http://cython.org/" rel="nofollow">cython</a> are also good and easy ways for mixing the two worlds.</p>
<p>Wrapping C++ using these tools is a bit trickier then wrapping C but it can be done. <a href="http://wi... | 5 | 2008-11-10T07:42:23Z | [
"c++",
"python",
"boost",
"swig"
] |
Exposing a C++ API to Python | 276,761 | <p>I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.</p>
<p>The alternatives I tried were:</p>
<ul>
<li><p>Boost.Python</p>
<p>I liked the cleaner API produced by... | 34 | 2008-11-10T00:34:50Z | 287,114 | <p>I suggest <a href="http://www.riverbankcomputing.co.uk/software/sip/intro">SIP</a>. SIP is better than SWIG due to the following reasons:</p>
<ol>
<li><p>For a given set of files, swig generates more duplicate (overhead) code than SIP. SIP manages to generate less duplicate (overhead) code by using a library file w... | 6 | 2008-11-13T14:45:33Z | [
"c++",
"python",
"boost",
"swig"
] |
Exposing a C++ API to Python | 276,761 | <p>I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.</p>
<p>The alternatives I tried were:</p>
<ul>
<li><p>Boost.Python</p>
<p>I liked the cleaner API produced by... | 34 | 2008-11-10T00:34:50Z | 288,689 | <p>I've used <a href="http://code.google.com/p/robin/">Robin</a> with great success. </p>
<p><strong>Great</strong> integration with C++ types, and creates a single .cpp file to compile and include in your shared object.</p>
| 18 | 2008-11-13T23:03:19Z | [
"c++",
"python",
"boost",
"swig"
] |
Exposing a C++ API to Python | 276,761 | <p>I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.</p>
<p>The alternatives I tried were:</p>
<ul>
<li><p>Boost.Python</p>
<p>I liked the cleaner API produced by... | 34 | 2008-11-10T00:34:50Z | 847,688 | <p>A big plus for Boost::Python is that it allows for tab completion in the ipython shell: You import a C++ class, exposed by Boost directly, or you subclass it, and from then on, it really behaves like a pure Python class.</p>
<p>The downside: It takes so long to install and use Boost that all the Tab-completion tim... | 2 | 2009-05-11T11:27:15Z | [
"c++",
"python",
"boost",
"swig"
] |
How to expose std::vector<int> as a Python list using SWIG? | 276,769 | <p>I'm trying to expose this function to Python using SWIG:</p>
<pre><code>std::vector<int> get_match_stats();
</code></pre>
<p>And I want SWIG to generate wrapping code for Python so I can see it as a list of integers.</p>
<p>Adding this to the .i file:</p>
<pre>
%include "typemaps.i"
%include "std_vector.i"... | 14 | 2008-11-10T00:38:59Z | 277,687 | <pre><code>%template(IntVector) vector<int>;
</code></pre>
| 14 | 2008-11-10T11:44:15Z | [
"c++",
"python",
"stl",
"swig"
] |
How to expose std::vector<int> as a Python list using SWIG? | 276,769 | <p>I'm trying to expose this function to Python using SWIG:</p>
<pre><code>std::vector<int> get_match_stats();
</code></pre>
<p>And I want SWIG to generate wrapping code for Python so I can see it as a list of integers.</p>
<p>Adding this to the .i file:</p>
<pre>
%include "typemaps.i"
%include "std_vector.i"... | 14 | 2008-11-10T00:38:59Z | 368,961 | <p>I don't have much experience with Swig, but are you #including your C++ header file in your .i file? Try one (or both) of</p>
<pre><code>%include "myvector.h"
%{
# include "myvector.h"
%}
</code></pre>
| 0 | 2008-12-15T16:40:34Z | [
"c++",
"python",
"stl",
"swig"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 277,191 | <p>As far as I know there is nothing out there that offers the sort of whiz-bang features that the Mono guys have implemented in their new shell, but that is not to say that the "basic" python interactive shell isn't a feature-complete and powerful application. I could see something like the C# shell being developed a... | 6 | 2008-11-10T06:21:04Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 277,234 | <p>Have you looked at <a href="http://ipython.scipy.org/moin/">ipython</a>? It's not quite as "gui". No smileys, sorry. ;-) It is a pretty good interactive shell for python though. </p>
<p>edit: I see you revised your question to emphasize the importance <strong>GUI</strong>. In that case, IPython wouldn't be a good m... | 7 | 2008-11-10T06:49:18Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 277,531 | <p>One project I'm aware of that provides similar features (inline plotting, customisable rendering) is <a href="http://fishsoup.net/software/reinteract/">Reinteract</a>. Another (though possibly a bit heavyweight for general usage) is <a href="http://www.sagemath.org/">SAGE</a> which provides functionality for web-ba... | 13 | 2008-11-10T10:23:00Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 278,322 | <p><a href="http://www.loria.fr/~rougier/pub/Software/pylab" rel="nofollow">Interactive pylab console</a>.</p>
| 3 | 2008-11-10T16:21:31Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 278,404 | <p>I think that a combination of Pycrust with matplotlib can do exactly what you need. Pycrust is part of the wxPython installation, and matplotlib should be insalled separately. Both are simple to install in about 5 minutes.</p>
<p>Read <a href="http://eli.thegreenplace.net/2008/07/26/matplotlib-plotting-with-python/... | 2 | 2008-11-10T16:41:18Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 280,287 | <p>You're looking for <a href="http://www.reinteract.org/" rel="nofollow">Reinteract</a>, which is a Python-based shell that <a href="http://tirania.org/blog/archive/2008/Nov-02.html" rel="nofollow">at least partially inspired</a> the C# shell you found. It's definitely still in-development, but already very useful.</p... | 3 | 2008-11-11T07:55:39Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 2,364,228 | <p>(Sorry for thread necromancy, but this page still comes up highly in a Google search and I assume there must be some interest in the subject.)</p>
<p>One GUI shell for Python which I believe is quite new is <a href="http://dreampie.sourceforge.net/">DreamPie</a>. It doesn't quite go as far as the screenshots in the... | 6 | 2010-03-02T15:23:54Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 6,101,558 | <p><a href="http://www.dreampie.org/" rel="nofollow">DreamPie</a> is my personal favorite. It doesn't appear to be any more restrictive than CSharpRepl. For example, the graph drawing example can be done if matplotlib is installed. There is an example screenshot to this effect on DreamPie's web site (<a href="http://... | 1 | 2011-05-23T18:53:17Z | [
"python",
"shell",
"user-interface"
] |
Is there a good Python GUI shell? | 277,170 | <p>I saw this the other day (scroll <em>all the way</em> down to see some of the clever stuff): </p>
<blockquote>
<p><a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/" rel="nofollow">http://www.mono-project.com/docs/tools+libraries/tools/repl/</a></p>
</blockquote>
<p>And wondered whether someth... | 12 | 2008-11-10T06:02:59Z | 16,783,547 | <p><a href="http://www.lighttable.com/" rel="nofollow">Light Table</a> is working on this. The IDE is simultaneously a REPL -- it has in-line plotting with iPython.</p>
| 0 | 2013-05-28T03:45:37Z | [
"python",
"shell",
"user-interface"
] |
Is there a more Pythonic way to merge two HTML header rows with colspans? | 277,187 | <p>I am using BeautifulSoup in Python to parse some HTML. One of the problems I am dealing with is that I have situations where the colspans are different across header rows. (Header rows are the rows that need to be combined to get the column headings in my jargon) That is one column may span a number of columns abo... | 1 | 2008-11-10T06:17:39Z | 277,280 | <p>Maybe look at the zip function for parts of the problem:</p>
<pre><code>>>> execfile('so_ques.py')
[[' '], [' '], ['bananas bunches'], [' '], [' cars'], [' cars'], [' cars'], [' '], [' trucks'], [' trucks'], [' trucks'], [' '], ['trains freight'], [' '], ['planes cargo'], [' '], [' all other'], [' '], [' '... | 1 | 2008-11-10T07:25:44Z | [
"python",
"beautifulsoup"
] |
Is there a more Pythonic way to merge two HTML header rows with colspans? | 277,187 | <p>I am using BeautifulSoup in Python to parse some HTML. One of the problems I am dealing with is that I have situations where the colspans are different across header rows. (Header rows are the rows that need to be combined to get the column headings in my jargon) That is one column may span a number of columns abo... | 1 | 2008-11-10T06:17:39Z | 277,390 | <p>Here is a modified version of your algorithm. <em>zip</em> is used to iterate over <strong>short</strong> lengths and headers and a <em>class object</em> is used to count and iterate the <strong>long</strong> items, as well as combine the headers. <em>while</em> is more appropriate for the inner loop.
(forgive the t... | 3 | 2008-11-10T09:05:10Z | [
"python",
"beautifulsoup"
] |
Is there a more Pythonic way to merge two HTML header rows with colspans? | 277,187 | <p>I am using BeautifulSoup in Python to parse some HTML. One of the problems I am dealing with is that I have situations where the colspans are different across header rows. (Header rows are the rows that need to be combined to get the column headings in my jargon) That is one column may span a number of columns abo... | 1 | 2008-11-10T06:17:39Z | 277,837 | <p>You've actually got a lot going on in this example.</p>
<ol>
<li><p>You've "over-processed" the Beautiful Soup Tag objects to make lists. Leave them as Tags.</p></li>
<li><p>All of these kinds of merge algorithms are hard. It helps to treat the two things being merged symmetrically.</p></li>
</ol>
<p>Here's a ve... | 2 | 2008-11-10T13:20:02Z | [
"python",
"beautifulsoup"
] |
Is there a more Pythonic way to merge two HTML header rows with colspans? | 277,187 | <p>I am using BeautifulSoup in Python to parse some HTML. One of the problems I am dealing with is that I have situations where the colspans are different across header rows. (Header rows are the rows that need to be combined to get the column headings in my jargon) That is one column may span a number of columns abo... | 1 | 2008-11-10T06:17:39Z | 280,181 | <p>I guess I am going to answer my own question but I did receive a lot of help. Thanks for all of the help. I made S.LOTT's answer work after a few small corrections. (They may be so small as to not be visible (inside joke)). So now the question is why is this more Pythonic? I think I see that it is less denser /... | 0 | 2008-11-11T06:41:52Z | [
"python",
"beautifulsoup"
] |
Is there a more Pythonic way to merge two HTML header rows with colspans? | 277,187 | <p>I am using BeautifulSoup in Python to parse some HTML. One of the problems I am dealing with is that I have situations where the colspans are different across header rows. (Header rows are the rows that need to be combined to get the column headings in my jargon) That is one column may span a number of columns abo... | 1 | 2008-11-10T06:17:39Z | 283,026 | <p>Well I have an answer now. I was thinking through this and decided that I needed to use parts of every answer. I still need to figure out if I want a class or a function. But I have the algorithm that I think is probably more Pythonic than any of the others. But, it borrows heavily from the answers that some ver... | 0 | 2008-11-12T04:20:19Z | [
"python",
"beautifulsoup"
] |
Python Argument Binders | 277,922 | <p>How can I bind arguments to a Python method to store a nullary functor for later invocation? Similar to C++'s <code>boost::bind</code>.</p>
| 39 | 2008-11-10T14:01:22Z | 277,932 | <p><a href="http://docs.python.org/2/library/functools.html#functools.partial"><code>functools.partial</code></a> returns a callable wrapping a function with some or all of the arguments frozen.</p>
<pre class="lang-py prettyprint-override"><code>import sys
import functools
print_hello = functools.partial(sys.stdout.... | 55 | 2008-11-10T14:06:47Z | [
"python"
] |
Python Argument Binders | 277,922 | <p>How can I bind arguments to a Python method to store a nullary functor for later invocation? Similar to C++'s <code>boost::bind</code>.</p>
| 39 | 2008-11-10T14:01:22Z | 277,933 | <p>I'm not overly familiar with boost::bind, but the <code>partial</code> function from <code>functools</code> may be a good start:</p>
<pre><code>>>> from functools import partial
>>> def f(a, b):
... return a+b
>>> p = partial(f, 1, 2)
>>> p()
3
>>> p2 = partial(f,... | 20 | 2008-11-10T14:07:14Z | [
"python"
] |
Python Argument Binders | 277,922 | <p>How can I bind arguments to a Python method to store a nullary functor for later invocation? Similar to C++'s <code>boost::bind</code>.</p>
| 39 | 2008-11-10T14:01:22Z | 278,056 | <p>Functors can be defined this way in Python. They're callable objects. The "binding" merely sets argument values.</p>
<pre><code>class SomeFunctor( object ):
def __init__( self, arg1, arg2=None ):
self.arg1= arg1
self.arg2= arg2
def __call___( self, arg1=None, arg2=None ):
a1= arg1 ... | 0 | 2008-11-10T14:57:19Z | [
"python"
] |
Python Argument Binders | 277,922 | <p>How can I bind arguments to a Python method to store a nullary functor for later invocation? Similar to C++'s <code>boost::bind</code>.</p>
| 39 | 2008-11-10T14:01:22Z | 278,217 | <p>If <code>functools.partial</code> is not available then it can be easily emulated:</p>
<pre><code>>>> make_printer = lambda s: lambda: sys.stdout.write("%s\n" % s)
>>> import sys
>>> print_hello = make_printer("hello")
>>> print_hello()
hello
</code></pre>
<p>Or</p>
<pre><code>... | 9 | 2008-11-10T15:50:43Z | [
"python"
] |
Python Argument Binders | 277,922 | <p>How can I bind arguments to a Python method to store a nullary functor for later invocation? Similar to C++'s <code>boost::bind</code>.</p>
| 39 | 2008-11-10T14:01:22Z | 279,892 | <p>This would work, too:</p>
<pre><code>def curry(func, *args):
def curried(*innerargs):
return func(*(args+innerargs))
curried.__name__ = "%s(%s, ...)" % (func.__name__, ", ".join(map(str, args)))
return curried
>>> w=curry(sys.stdout.write, "Hey there")
>>> w()
Hey there
</code>... | 7 | 2008-11-11T03:03:27Z | [
"python"
] |
Python Argument Binders | 277,922 | <p>How can I bind arguments to a Python method to store a nullary functor for later invocation? Similar to C++'s <code>boost::bind</code>.</p>
| 39 | 2008-11-10T14:01:22Z | 15,003,681 | <p>lambdas allow you to create a new unnamed function with less arguments and call the function!</p>
<pre><code>>>> def foobar(x,y,z):
... print "%d, %d, %d" % (x,y,z)
>>> foobar(1,2,3) # call normal function
>>> bind = lambda x: foobar(x, 10, 20) # bind 10 and 20 to foobar
>>>... | 5 | 2013-02-21T13:37:49Z | [
"python"
] |
Dictionary or If statements, Jython | 277,965 | <p>I am writing a script at the moment that will grab certain information from HTML using dom4j.</p>
<p>Since Python/Jython does not have a native <strong>switch</strong> statement I decided to use a whole bunch of <strong>if</strong> statements that call the appropriate method, like below:</p>
<pre><code>if type == ... | 4 | 2008-11-10T14:20:13Z | 277,972 | <p>To avoid specifying the tag and handler in the dict, you could just use a handler class with methods named to match the type. Eg</p>
<pre><code>class MyHandler(object):
def handle_extractTitle(self, dom):
# do something
def handle_extractMetaTags(self, dom):
# do something
def handle... | 14 | 2008-11-10T14:24:04Z | [
"python",
"switch-statement",
"jython"
] |
Dictionary or If statements, Jython | 277,965 | <p>I am writing a script at the moment that will grab certain information from HTML using dom4j.</p>
<p>Since Python/Jython does not have a native <strong>switch</strong> statement I decided to use a whole bunch of <strong>if</strong> statements that call the appropriate method, like below:</p>
<pre><code>if type == ... | 4 | 2008-11-10T14:20:13Z | 277,978 | <p>It depends on how many if statements we're talking about; if it's a very small number, then it will be more efficient than using a dictionary.</p>
<p>However, as always, I strongly advice you to do whatever makes your code look cleaner until experience and profiling tell you that a specific block of code needs to b... | 1 | 2008-11-10T14:26:14Z | [
"python",
"switch-statement",
"jython"
] |
Dictionary or If statements, Jython | 277,965 | <p>I am writing a script at the moment that will grab certain information from HTML using dom4j.</p>
<p>Since Python/Jython does not have a native <strong>switch</strong> statement I decided to use a whole bunch of <strong>if</strong> statements that call the appropriate method, like below:</p>
<pre><code>if type == ... | 4 | 2008-11-10T14:20:13Z | 277,980 | <p>Your use of the dictionary is not quite correct. In your implementation, all methods will be called and all the useless one discarded. What is usually done is more something like:</p>
<pre><code>switch_dict = {'extractTitle': extractTitle,
'extractMetaTags': extractMetaTags}
switch_dict[type](dom)
<... | 1 | 2008-11-10T14:27:35Z | [
"python",
"switch-statement",
"jython"
] |
Dictionary or If statements, Jython | 277,965 | <p>I am writing a script at the moment that will grab certain information from HTML using dom4j.</p>
<p>Since Python/Jython does not have a native <strong>switch</strong> statement I decided to use a whole bunch of <strong>if</strong> statements that call the appropriate method, like below:</p>
<pre><code>if type == ... | 4 | 2008-11-10T14:20:13Z | 277,981 | <p>With your code you're running your functions all get called.</p>
<pre>
handlers = {
'extractTitle': extractTitle,
'extractMetaTags': extractMetaTags
}
handlers[type](dom)
</pre>
<p>Would work like your original <code>if</code> code.</p>
| 2 | 2008-11-10T14:27:44Z | [
"python",
"switch-statement",
"jython"
] |
Dictionary or If statements, Jython | 277,965 | <p>I am writing a script at the moment that will grab certain information from HTML using dom4j.</p>
<p>Since Python/Jython does not have a native <strong>switch</strong> statement I decided to use a whole bunch of <strong>if</strong> statements that call the appropriate method, like below:</p>
<pre><code>if type == ... | 4 | 2008-11-10T14:20:13Z | 278,006 | <p>The efficiency question is barely relevant. The dictionary lookup is done with a simple hashing technique, the if-statements have to be evaluated one at a time. Dictionaries tend to be quicker.</p>
<p>I suggest that you actually have polymorphic objects that do extractions from the DOM.</p>
<p>It's not clear how... | 1 | 2008-11-10T14:36:53Z | [
"python",
"switch-statement",
"jython"
] |
How do I script an OLE component using Python? | 279,094 | <p>I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?</p>
<p>I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython?</p>... | 9 | 2008-11-10T20:41:41Z | 279,117 | <p>You need the <a href="http://python.net/crew/mhammond/win32/Downloads.html" rel="nofollow">win32com</a> package. Some examples:</p>
<pre><code>from win32com.client.dynamic import Dispatch
# Excel
excel = Dispatch('Excel.Application')
# Vim
vim = Dispatch('Vim.Application')
</code></pre>
<p>And then call whatever... | 2 | 2008-11-10T20:50:47Z | [
"python",
"windows",
"scripting",
"activex",
"ole"
] |
How do I script an OLE component using Python? | 279,094 | <p>I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?</p>
<p>I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython?</p>... | 9 | 2008-11-10T20:41:41Z | 279,120 | <p>You can find an example on <a href="http://www.boddie.org.uk/python/COM.html" rel="nofollow">this website</a>. OLE and is related to COM and ActiveX so you should look out for those terms. Do you have access this book from O'Reilly - <a href="http://oreilly.com/catalog/9781565926219/" rel="nofollow">Python Programmi... | 3 | 2008-11-10T20:51:43Z | [
"python",
"windows",
"scripting",
"activex",
"ole"
] |
How do I script an OLE component using Python? | 279,094 | <p>I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?</p>
<p>I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython?</p>... | 9 | 2008-11-10T20:41:41Z | 279,123 | <p>Please take a look at the <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">python-win32</a> package, and, in particular, at its win32com API.</p>
| 0 | 2008-11-10T20:52:07Z | [
"python",
"windows",
"scripting",
"activex",
"ole"
] |
How do I script an OLE component using Python? | 279,094 | <p>I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?</p>
<p>I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython?</p>... | 9 | 2008-11-10T20:41:41Z | 308,854 | <p>PythonWin (<a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">http://sourceforge.net/projects/pywin32/</a>), bundled with python-win32, comes with its own COM browser as part of its shell and debugging environment.</p>
| 0 | 2008-11-21T13:57:17Z | [
"python",
"windows",
"scripting",
"activex",
"ole"
] |
How do I script an OLE component using Python? | 279,094 | <p>I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?</p>
<p>I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython?</p>... | 9 | 2008-11-10T20:41:41Z | 363,885 | <p>win32com is a good package to use if you want to use the IDispatch interface to control your objects (slow). comtypes is a better, native python, package that uses the raw COM approach to talking to your controls. WxPython uses comtypes to give you an ActiveX container window from Python ... sweet.</p>
| 2 | 2008-12-12T19:33:01Z | [
"python",
"windows",
"scripting",
"activex",
"ole"
] |
How do I search for unpublished Plone content in an IPython debug shell? | 279,119 | <p>I like to use IPython's zope profile to inspect my Plone instance, but a few annoying permissions differences come up compared to inserting a breakpoint and hitting it with the admin user.</p>
<p>For example, I would like to iterate over the content objects in an unpublished testing folder. This query will return n... | 2 | 2008-11-10T20:51:35Z | 290,657 | <p>Just use catalog.search({'path':'Plone/testing'}). It performs the same query as catalog() but does not filter the results based on the current user's permissions.</p>
<p>IPython's zope profile does provide a method utils.su('username') to change the current user, but it does not recognize the admin user (defined i... | 1 | 2008-11-14T16:29:54Z | [
"python",
"plone"
] |
How do I search for unpublished Plone content in an IPython debug shell? | 279,119 | <p>I like to use IPython's zope profile to inspect my Plone instance, but a few annoying permissions differences come up compared to inserting a breakpoint and hitting it with the admin user.</p>
<p>For example, I would like to iterate over the content objects in an unpublished testing folder. This query will return n... | 2 | 2008-11-10T20:51:35Z | 427,914 | <p>here's the (<strong>very</strong> dirty) code I use to manage my plone app from the debug shell. It may requires some updates depending on your versions of Zope and Plone.</p>
<pre><code>from sys import stdin, stdout, exit
import base64
from thread import get_ident
from ZPublisher.HTTPRequest import HTTPRequest
fro... | 2 | 2009-01-09T12:37:52Z | [
"python",
"plone"
] |
Can anyone recommend a decent FOSS PDF generator for Python? | 279,129 | <p>I need a basic pdf generator that'll let me toss some images and text into a pdf file. The ability to have some basic drawing commands (lines and so forth) would also be a plus.</p>
<p>I did read through <a href="http://stackoverflow.com/questions/177799/what-is-a-good-pdf-report-generator-tool-for-python">this q... | 5 | 2008-11-10T20:53:34Z | 279,147 | <p>I think going through Latex is the easiest way, and not overkill at all. Generating a working PDF file is quite a difficult activity, whereas generating a Tex source is much easier. Any other typesetting change would probably work as well, such as going through reStructuredText or troff.</p>
| 1 | 2008-11-10T20:59:04Z | [
"python",
"pdf-generation"
] |
Can anyone recommend a decent FOSS PDF generator for Python? | 279,129 | <p>I need a basic pdf generator that'll let me toss some images and text into a pdf file. The ability to have some basic drawing commands (lines and so forth) would also be a plus.</p>
<p>I did read through <a href="http://stackoverflow.com/questions/177799/what-is-a-good-pdf-report-generator-tool-for-python">this q... | 5 | 2008-11-10T20:53:34Z | 279,165 | <p>For one of my projects, I have tested and/or implemented probably six or seven different methods of going from an image to a PDF in the last six months. Ultimately I ended up coming back to <a href="http://www.reportlab.org/downloads.html" rel="nofollow">ReportLab</a> (which I had initially avoided for reasons simi... | 5 | 2008-11-10T21:04:17Z | [
"python",
"pdf-generation"
] |
Can anyone recommend a decent FOSS PDF generator for Python? | 279,129 | <p>I need a basic pdf generator that'll let me toss some images and text into a pdf file. The ability to have some basic drawing commands (lines and so forth) would also be a plus.</p>
<p>I did read through <a href="http://stackoverflow.com/questions/177799/what-is-a-good-pdf-report-generator-tool-for-python">this q... | 5 | 2008-11-10T20:53:34Z | 279,167 | <p>Is the reportlab code not ok? The reason why using LaTeX might not be overkill is because pdf is a really low-level format. In pdf you do not get line-breaks automatically, you have to calculate line-widths yourself.</p>
| 0 | 2008-11-10T21:04:48Z | [
"python",
"pdf-generation"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 279,253 | <p>Be sure that dirBar has the <code>__init__.py</code> file -- this makes a directory into a Python package.</p>
| 259 | 2008-11-10T21:33:33Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 279,287 | <p>(This is from memory so someone edit if I make a typo, please.)</p>
<p>If you structure your project this way:</p>
<pre><code>src\
__init__.py
main.py
dirFoo\
__init__.py
Foo.py
dirBar\
__init__.py
Bar.py
</code></pre>
<p>Then from Foo.py you should be able to do:</p>
<pre><code>import di... | 64 | 2008-11-10T21:46:04Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 279,338 | <p>You could also add the sub directory to your python path so that it imports as a normal script.</p>
<pre><code>import sys
sys.path.append( <path to dirFoo> )
import Bar
</code></pre>
| 186 | 2008-11-10T22:04:27Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 279,389 | <p>This is the relevant PEP:</p>
<p><a href="http://www.python.org/dev/peps/pep-0328/">http://www.python.org/dev/peps/pep-0328/</a></p>
<p>In particular, presuming dirFoo is a directory up from dirBar...</p>
<p>In dirFoo\Foo.py:</p>
<pre><code>from ..dirBar import Bar
</code></pre>
| 32 | 2008-11-10T22:22:47Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 282,778 | <p>The easiest method is to use sys.path.append().</p>
<p>However, you may be also interested in the <a href="http://docs.python.org/library/imp.html?highlight=imp#module-imp">imp</a> module.
It provides access to internal import functions.</p>
<pre><code># mod_name is the filename without the .py/.pyc extention
py_m... | 41 | 2008-11-12T01:56:51Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 2,352,563 | <p>Add an <strong>_<em>init</em>_.py</strong> file:</p>
<pre><code>dirFoo\
Foo.py
dirBar\
__init__.py
Bar.py
</code></pre>
<p>Then add this code to the start of Foo.py:</p>
<pre><code>import sys
sys.path.append('dirBar')
import Bar
</code></pre>
| 5 | 2010-02-28T20:34:59Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 3,714,805 | <p>In my opinion the best choice is to put <strong>__ init __.py</strong> in the folder and call the file with</p>
<pre><code>from dirBar.Bar import *
</code></pre>
<p>It is not recommended to use sys.path.append() because something might gone wrong if you use the same file name as the existing python package. I have... | 11 | 2010-09-15T05:02:52Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 4,284,378 | <pre><code>import os, sys
lib_path = os.path.abspath(os.path.join('..', '..', '..', 'lib'))
sys.path.append(lib_path)
import mymodule
</code></pre>
| 87 | 2010-11-26T10:21:28Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 4,397,291 | <p>Just do Simple Things to import py file from different folder-</p>
<p>Let's you have a directory like-</p>
<pre><code>lib/abc.py
</code></pre>
<p>Then just keep a empty file in lib folder as named </p>
<pre><code>__init__.py
</code></pre>
<p>and then use </p>
<pre><code>from lib.abc import <Your Module name... | 71 | 2010-12-09T10:40:09Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 4,946,813 | <p>Look at the pkgutil module from the standard library. It may help you do what you want.</p>
| 2 | 2011-02-09T15:19:55Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 6,098,238 | <p>Assuming that both your directories are real python packages (do have the <code>__init__.py</code> file inside them), here is a safe solution for inclusion of modules relatively to the location of the script.</p>
<p>I assume that you want to do this because you need to include a set of modules with your script. I u... | 255 | 2011-05-23T14:00:43Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 7,262,716 | <pre><code>from .dirBar import Bar
</code></pre>
<p>instead of:</p>
<pre><code>from dirBar import Bar
</code></pre>
<p>just in case there could be another dirBar installed and confuse a foo.py reader.</p>
| 8 | 2011-08-31T20:02:15Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 7,520,383 | <p>Call me overly cautious but I like to make mine more portable because it's unsafe to assume that files will always be in the same place on every computer. Personally I have the code look up the file path first. I use linux so mine would look like this:</p>
<pre><code>import os, sys
from subprocess import Popen, PIP... | -12 | 2011-09-22T19:33:39Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 9,037,651 | <p>Here's a way to import a file from one level above, using the relative path.</p>
<p>Basically, just move the working directory up a level (or any relative location), add that to your path, then move the working directory back where it started.</p>
<pre><code>#to import from one level above:
cwd = os.getcwd()
os.ch... | 1 | 2012-01-27T17:43:59Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 13,963,800 | <h2>The quick-and-dirty way for Linux users</h2>
<p>If you are just tinkering around and don't care about deployment issues, you can use a symbolic link (assuming your filesystem supports it) to make the module or package directly visible in the folder of the requesting module.</p>
<pre><code>ln -s (path)/module_name... | 10 | 2012-12-20T01:07:43Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 14,803,823 | <p>The easiest way without any modification to your script is to set PYTHONPATH environment variable. Cause sys.path is initialized from these locations:</p>
<ol>
<li>the directory containing the input script (or the current
directory). </li>
<li>PYTHONPATH (a list of directory names, with the same
syntax as the shell... | 14 | 2013-02-10T23:21:51Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 25,010,192 | <p>Relative sys.path example:</p>
<pre><code># /lib/my_module.py
# /src/test.py
if __name__ == '__main__' and __package__ is None:
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../lib')))
import my_module
</code></pre>
<p>Based on <a href="http://stackoverflow.com/a/19190695/991267">t... | 4 | 2014-07-29T07:27:39Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 26,639,332 | <p>For this case to import Bar.py into Foo.py, first I'd turn these folders into python packages like so:</p>
<pre><code>dirFoo\
__init__.py
Foo.py
dirBar\
__init__.py
Bar.py
</code></pre>
<p>Then I would do it like this in Foo.py:</p>
<pre><code>from .dirBar import Bar
</code></pre>
<p>... | 7 | 2014-10-29T19:49:53Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 29,401,990 | <p>Well, as you mention, usually you want to have access to a folder with your modules relative to where your main script is run, so you just import them<br>
Solution:<br>
I have the script in <code>D:/Books/MyBooks.py</code> and some modules (like oldies.py) I need to import from subdirectory <code>D:/Books/includes</... | 2 | 2015-04-01T22:29:39Z | [
"python",
"relative-path",
"python-import"
] |
Import a module from a relative path | 279,237 | <p>How do I import a python module given its relative path?</p>
<p>For example, if <code>dirFoo</code> contains <code>Foo.py</code> and <code>dirBar</code>, and <code>dirBar</code> contains <code>Bar.py</code>, how do I import <code>Bar.py</code> into <code>Foo.py</code>?</p>
<p>Here's a visual representation:</p>
<... | 555 | 2008-11-10T21:28:48Z | 38,808,859 | <p>Another solution would be to install the <a href="https://pypi.python.org/pypi/py-require" rel="nofollow">py-require</a> package and then use the following in <code>Foo.py</code></p>
<pre><code>import require
Bar = require('./dirBar/Bar')
</code></pre>
| 1 | 2016-08-06T21:26:58Z | [
"python",
"relative-path",
"python-import"
] |
Python: How do I generate a keypress? | 279,434 | <p>I am opening a process (with os.popen() ) that, for some commands, detects certain keypresses (e.g. ESC - not the character, the key). Is there a way to send keypress events to the process?</p>
| 1 | 2008-11-10T22:41:30Z | 279,460 | <p>The obvious way would be to start the process in it's own shell.<br />
something like os.popen("sh command") </p>
| 0 | 2008-11-10T22:46:59Z | [
"python",
"keypress",
"popen"
] |
Python: How do I generate a keypress? | 279,434 | <p>I am opening a process (with os.popen() ) that, for some commands, detects certain keypresses (e.g. ESC - not the character, the key). Is there a way to send keypress events to the process?</p>
| 1 | 2008-11-10T22:41:30Z | 279,477 | <p>You probably want something like <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow"><code>Pexpect</code></a>. It's been around a while, and there may be a better alternative, now, but it will let you do what you want. </p>
<p>As far as I know, there is no easy way to do that kind of thing with os.popen or ... | 1 | 2008-11-10T22:52:35Z | [
"python",
"keypress",
"popen"
] |
Python: How do I generate a keypress? | 279,434 | <p>I am opening a process (with os.popen() ) that, for some commands, detects certain keypresses (e.g. ESC - not the character, the key). Is there a way to send keypress events to the process?</p>
| 1 | 2008-11-10T22:41:30Z | 279,627 | <p>What platform is this on? </p>
<p>You may have to actually feed events into the event loop, if it's running on Win32.</p>
| 0 | 2008-11-11T00:04:58Z | [
"python",
"keypress",
"popen"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 279,568 | <p>Use a generator function to generate an iterator.</p>
<pre><code>def foo_gen():
n = 0
while True:
n+=1
yield n
</code></pre>
<p>Then use it like</p>
<pre><code>foo = foo_gen().next
for i in range(0,10):
print foo()
</code></pre>
<p>If you want an upper limit:</p>
<pre><code>def foo_g... | 8 | 2008-11-10T23:37:00Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 279,586 | <p>A bit reversed, but this should work:</p>
<pre><code>def foo():
foo.counter += 1
print "Counter is %d" % foo.counter
foo.counter = 0
</code></pre>
<p>If you want the counter initialization code at the top instead of the bottom, you can create a decorator:</p>
<pre><code>def static_var(varname, value):
... | 376 | 2008-11-10T23:46:00Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 279,592 | <p>Other answers have demonstrated the way you should do this. Here's a way you shouldn't:</p>
<pre><code>>>> def foo(counter=[0]):
... counter[0] += 1
... print("Counter is %i." % counter[0]);
...
>>> foo()
Counter is 1.
>>> foo()
Counter is 2.
>>>
</code></pre>
<p>Default v... | 28 | 2008-11-10T23:47:53Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 279,596 | <pre>
_counter = 0
def foo():
global _counter
_counter += 1
print 'counter is', _counter
</pre>
<p>Python customarily uses underscores to indicate private variables. The only reason in C to declare the static variable inside the function is to hide it outside the function, which is not really idiomatic Python... | 5 | 2008-11-10T23:50:14Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 279,597 | <p>You can add attributes to a function, and use it as a static variable.</p>
<pre><code>def myfunc():
myfunc.counter += 1
print myfunc.counter
# attribute must be initialized
myfunc.counter = 0
</code></pre>
<p>Alternatively, if you don't want to setup the variable outside the function, you can use <code>hasatt... | 137 | 2008-11-10T23:53:00Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 279,598 | <p>Python doesn't have static variables but you can fake it by defining a callable class object and then using it as a function. <a href="http://stackoverflow.com/a/593046/4561887">Also see this answer</a>.</p>
<pre><code>class Foo(object):
# Class variable, shared by all instances of this class
counter = 0
def... | 16 | 2008-11-10T23:53:12Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 6,014,360 | <p>The <em>idiomatic</em> way is to use a <em>class</em>, which can have attributes. If you need instances to not be separate, use a singleton.</p>
<p>There are a number of ways you could fake or munge "static" variables into Python (one not mentioned so far is to have a mutable default argument), but this is not the... | 0 | 2011-05-16T07:36:30Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 10,941,940 | <p>I personally prefer the following to decorators. To each their own.</p>
<pre><code>def staticize(name, factory):
"""Makes a pseudo-static variable in calling function.
If name `name` exists in calling function, return it.
Otherwise, saves return value of `factory()` in
name `name` of calling func... | 1 | 2012-06-08T01:15:58Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 12,270,415 | <p>Here is a fully encapsulated version that doesn't require an external initialization call:</p>
<pre><code>def mystaticfun():
if "counter" not in vars(mystaticfun): mystaticfun.counter=-1
mystaticfun.counter+=1
print (mystaticfun.counter)
</code></pre>
<p>In Python, object members are dynamically stored... | 19 | 2012-09-04T19:51:35Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 16,214,510 | <p>One could also consider:</p>
<pre><code>def foo():
try:
foo.counter += 1
except AttributeError:
foo.counter = 1
</code></pre>
<p>Reasoning:</p>
<ul>
<li>much pythonic (<code>ask for forgiveness not permission</code>)</li>
<li>use exception (thrown only once) instead of <code>if</code> bran... | 86 | 2013-04-25T12:16:31Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 19,125,990 | <p>Prompted by <a href="http://stackoverflow.com/questions/19125515/function-instance-variables-inside-a-class/19125964">this question</a>, may I present another alternative which might be a bit nicer to use and will look the same for both methods and functions:</p>
<pre><code>@static_var2('seed',0)
def funccounter(st... | 2 | 2013-10-01T21:09:43Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 27,783,657 | <p>Many people have already suggested testing 'hasattr', but there's a simpler answer:</p>
<pre><code>def func():
func.counter = getattr(func, 'counter', 0) + 1
</code></pre>
<p>No try/except, no testing hasattr, just getattr with a default.</p>
| 15 | 2015-01-05T16:24:14Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 27,914,651 | <p>A static variable inside a Python method</p>
<pre><code>class Count:
def foo(self):
try:
self.foo.__func__.counter += 1
except AttributeError:
self.foo.__func__.counter = 1
print self.foo.__func__.counter
m = Count()
m.foo() # 1
m.foo() # 2
m.foo()... | 0 | 2015-01-13T03:58:38Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 28,401,932 | <pre><code>def staticvariables(**variables):
def decorate(function):
for variable in variables:
setattr(function, variable, variables[variable])
return function
return decorate
@staticvariables(counter=0, bar=1)
def foo():
print(foo.counter)
print... | 5 | 2015-02-09T02:27:39Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 31,784,304 | <p>Using an attribute of a function as static variable has some potential drawbacks:</p>
<ul>
<li>Every time you want to access the variable, you have to write out the full name of the function. </li>
<li>Outside code can access the variable easily and mess with the value.</li>
</ul>
<p>Idiomatic python for the secon... | 4 | 2015-08-03T09:50:37Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 34,023,168 | <p>Another (not recommended!) twist on the callable object like <a href="http://stackoverflow.com/a/279598/916373">http://stackoverflow.com/a/279598/916373</a>, if you don't mind using a funky call signature, would be to do</p>
<pre><code>class foo(object):
counter = 0;
@staticmethod
def __call__():
... | 1 | 2015-12-01T14:47:24Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 35,020,271 | <p>Sure this is an old question but I think I might provide some update.</p>
<p>It seems that the performance argument is obsolete.
The same test suite appears to give similar results for siInt_try and isInt_re2.
Of course results vary, but this is one session on my computer with python 3.4.4 on kernel 4.3.01 with Xe... | 1 | 2016-01-26T17:40:11Z | [
"python"
] |
What is the Python equivalent of static variables inside a function? | 279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing... | 311 | 2008-11-10T23:33:36Z | 38,712,809 | <p>A little bit more readable, but more verbose:</p>
<pre><code>>>> def func(_static={'counter': 0}):
... _static['counter'] += 1
... print _static['counter']
...
>>> func()
1
>>> func()
2
>>>
</code></pre>
| 1 | 2016-08-02T06:02:26Z | [
"python"
] |
How can one get the set of all classes with reverse relationships for a model in Django? | 279,782 | <p>Given:</p>
<pre><code>from django.db import models
class Food(models.Model):
"""Food, by name."""
name = models.CharField(max_length=25)
class Cat(models.Model):
"""A cat eats one type of food"""
food = models.ForeignKey(Food)
class Cow(models.Model):
"""A cow eats one type of food"""
... | 4 | 2008-11-11T01:42:39Z | 279,809 | <p>Some digging in the source code revealed:</p>
<p>django/db/models/options.py:</p>
<pre><code>def get_all_related_objects(self, local_only=False):
def get_all_related_many_to_many_objects(self, local_only=False)
</code></pre>
<p>And, using these functions on the models from above, you hypothetically get:</p>
<pr... | 14 | 2008-11-11T02:00:20Z | [
"python",
"django",
"django-models",
"django-orm"
] |
How can one get the set of all classes with reverse relationships for a model in Django? | 279,782 | <p>Given:</p>
<pre><code>from django.db import models
class Food(models.Model):
"""Food, by name."""
name = models.CharField(max_length=25)
class Cat(models.Model):
"""A cat eats one type of food"""
food = models.ForeignKey(Food)
class Cow(models.Model):
"""A cow eats one type of food"""
... | 4 | 2008-11-11T01:42:39Z | 279,952 | <p>Either </p>
<p>A) Use <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance" rel="nofollow">multiple table inheritance</a> and create a "Eater" base class, that Cat, Cow and Human inherit from.</p>
<p>B) Use a <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/... | 7 | 2008-11-11T03:48:52Z | [
"python",
"django",
"django-models",
"django-orm"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 279,942 | <p>pyglet has a lot of nice extras included with it (like image loading and sound). If you're starting out, I'd try pyglet first, and then switch to PyOpenGL if you feel like you want to get closer to the metal.</p>
<p>The real important question though is: what are you trying to accomplish? </p>
| 3 | 2008-11-11T03:38:00Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 279,970 | <p>As Tony said, this is really going to depend on your goals. If you're "tinkering" to try to learn about OpenGL or 3D rendering in general that I would dispense with all pleasantries and start working with PyOpenGL, which is as close are you're going to get to "raw" 3D programming using Python.</p>
<p>On the other ... | 26 | 2008-11-11T04:03:04Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 281,395 | <p>I promote pyglet because it has the nicest API I've yet seen on stuff like this.</p>
<p>Pyglet has opengl API as well. But it's often nicer to use the recently added vertex list support.</p>
<p>pyglet.gl</p>
| 3 | 2008-11-11T16:30:11Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 397,041 | <p>I would recommend Pyglet because it is very easy to get started and have something basic running, and then you can add more advanced techniques at your own pace.</p>
| 2 | 2008-12-29T02:52:47Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 408,981 | <p>I'd say that Pyglet is actually more evolved than PyOpenGL. It has a nice API of it's own, and it has a full wrapper around OpenGL accessed through the pyglet.gl module! PyOpenGL doesn't even wrap all the functions OpenGL has.
Pyglet also has a great library for rendering 2D with hardware acceleration through OpenGL... | 4 | 2009-01-03T12:25:09Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 2,396,038 | <p>pyglet's GL API is nowhere near as nice as PyOpenGL's - pyglet's is at the raw ctypes layer which means you'll need to learn ctypes as well. If you're planning on doing a bunch of OpenGL programming you'll want to use PyOpenGL. </p>
<p>The nice thing is you can mix the two just fine. Use pyglet to provide the GL co... | 2 | 2010-03-07T11:17:49Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 4,246,325 | <p>Start with pyglet. It contains the best high-level API, which contains all you need to get started, from opening a window to drawing sprites and OpenGL primitives using their friendly and powerful Sprite and Batch classes.</p>
<p>Later, you might also want to write your own lower-level code, that makes calls direct... | 22 | 2010-11-22T14:21:04Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 13,781,633 | <p>Hmm, i would suggest pyglet, it really provides everything needed by a game or application. </p>
<p>Mind you, you can do a lot of things pyglet does with PyOpenGL, for example to create a window all you need to do is:<br>
glutInitWindow(title)</p>
<p>Although i think glutInitDisplayMode has to be called before th... | 3 | 2012-12-08T20:30:29Z | [
"python",
"pyglet",
"pyopengl"
] |
PyOpenGl or pyglet? | 279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| 24 | 2008-11-11T03:17:03Z | 38,231,267 | <p>Try <a href="https://github.com/cprogrammer1994/ModernGL" rel="nofollow">ModernGL</a></p>
<p>pip install ModernGL</p>
<p>(currently windows only)</p>
<p>In case you are using windows, you should try this module.
I had problems using PyOpenGL, PyGame and PyGlet. These modules are mature but takes a lot of time to ... | 0 | 2016-07-06T18:31:05Z | [
"python",
"pyglet",
"pyopengl"
] |
Set permissions on a compressed file in python | 279,945 | <p>I have a file <code>test.txt</code> that is inside a zip archive <code>test.zip</code>. The permissions on <code>test.txt</code> are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell.</p>
<p><strong>ED... | 6 | 2008-11-11T03:40:17Z | 279,975 | <p>Per the documentation, unzip sets the permissions to those stored, under unix. Also, the shell umask is not used. Your best bet is to make sure the perms are set before you zip the file.</p>
<p>Since you can't do that, you will have to try and do what you were trying to do (and get it to work under Debian.)</p>
... | 1 | 2008-11-11T04:10:07Z | [
"python",
"zip",
"zipfile"
] |
Set permissions on a compressed file in python | 279,945 | <p>I have a file <code>test.txt</code> that is inside a zip archive <code>test.zip</code>. The permissions on <code>test.txt</code> are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell.</p>
<p><strong>ED... | 6 | 2008-11-11T03:40:17Z | 279,985 | <p>Extract to stdout (unzip -p) and redirect to a file? If there's more than one file in the zip, you could list the zip contents, and then extract one at a time.</p>
<pre><code>for n in `unzip -l test.zip | awk 'NR > 3 && NF == 4 { print $4 }'`; do unzip -p test.zip $n > $n; done
</code></pre>
<p>(yea... | 0 | 2008-11-11T04:16:56Z | [
"python",
"zip",
"zipfile"
] |
Set permissions on a compressed file in python | 279,945 | <p>I have a file <code>test.txt</code> that is inside a zip archive <code>test.zip</code>. The permissions on <code>test.txt</code> are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell.</p>
<p><strong>ED... | 6 | 2008-11-11T03:40:17Z | 596,455 | <p>I had a similar problem to you, so here is the code spinet from my stuff, this I believe should help here.</p>
<pre><code># extract all of the zip
for file in zf.filelist:
name = file.filename
perm = ((file.external_attr >> 16L) & 0777)
if name.endswith('/'):
outfile = os.path.join(dir... | 3 | 2009-02-27T20:12:53Z | [
"python",
"zip",
"zipfile"
] |
email body from a parsed email object in jython | 280,207 | <p>I have an object.</p>
<pre><code> fp = open(self.currentEmailPath, "rb")
p = email.Parser.Parser()
self._currentEmailParsedInstance= p.parse(fp)
fp.close()
</code></pre>
<p>self.currentEmailParsedInstance, from this object I want to get the body of an email, text only no HTML....</p>
<p>How do I do... | 4 | 2008-11-11T07:07:09Z | 280,238 | <p>This will get you the contents of the message</p>
<pre><code>self.currentEmailParsedInstance.get_payload()
</code></pre>
<p>As for the text only part you will have to strip HTML on your own, for example using BeautifulSoup.</p>
<p>Check <a href="http://www.python.org/doc/2.2.3/lib/module-email.Message.html" rel="... | 4 | 2008-11-11T07:27:54Z | [
"python",
"email",
"jython",
"parsing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.