title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
I need a beginners guide to setting up windows for python development
959,479
<p>I currently work with .NET exclusively and would like to have a go at python. To this end I need to set up a python development environment. I guide to this would be handy. I guess I would be doing web development so will need a web server and probably a database. I also need pointers to popular ORM's, an MVC framew...
9
2009-06-06T11:08:51Z
960,062
<p>If you've worked with Eclipse before you could give <a href="http://pydev.sourceforge.net/" rel="nofollow">Pydev</a> a try</p>
0
2009-06-06T16:26:38Z
[ "python", "windows", "development-environment" ]
I need a beginners guide to setting up windows for python development
959,479
<p>I currently work with .NET exclusively and would like to have a go at python. To this end I need to set up a python development environment. I guide to this would be handy. I guess I would be doing web development so will need a web server and probably a database. I also need pointers to popular ORM's, an MVC framew...
9
2009-06-06T11:08:51Z
986,203
<p>NOTE: I included a lot of links to frameworks, projects and what-not, but as a new user I was limited to 1 link per answer. If someone else with enough reputation to edit wants/can edit them into this answer instead of the footnotes, I'd be grateful.</p> <p>There are some Python IDE's such as Wing IDE[1], I believe...
1
2009-06-12T11:37:53Z
[ "python", "windows", "development-environment" ]
What is the fastest way to draw an image in Gtk+?
959,675
<p>I have an image/pixbuf that I want to draw into a gtk.DrawingArea and refresh frequently, so the blitting operation has to be fast. Doing it the easy way:</p> <pre><code>def __init__(self): self.drawing_area = gtk.DrawingArea() self.image = gtk.gdk.pixbuf_new_from_file("image.png") def area_expose_cb(self, are...
8
2009-06-06T13:28:59Z
960,498
<p>Are you really not generating enough raw speed/throughput? Or is it just that you're seeing flickering?</p> <p>If it's the latter, perhaps you should investigate double buffering for perfomring your updates instead? Basically the idea is to draw to an invisible buffer then tell the graphics card to use the new bu...
2
2009-06-06T20:46:53Z
[ "python", "gtk", "pygtk", "cairo" ]
What is the fastest way to draw an image in Gtk+?
959,675
<p>I have an image/pixbuf that I want to draw into a gtk.DrawingArea and refresh frequently, so the blitting operation has to be fast. Doing it the easy way:</p> <pre><code>def __init__(self): self.drawing_area = gtk.DrawingArea() self.image = gtk.gdk.pixbuf_new_from_file("image.png") def area_expose_cb(self, are...
8
2009-06-06T13:28:59Z
961,332
<p>Try creating Pixmap that uses the same colormap as your drawing area.</p> <pre><code>dr_area.realize() self.gc = dr_area.get_style().fg_gc[gtk.STATE_NORMAL] img = gtk.gdk.pixbuf_new_from_file("image.png") self.image = gtk.gdk.Pixmap(dr_area.window, img.get_width(), img.get_height()) self.image.draw_pixbuf(self.gc, ...
6
2009-06-07T06:29:24Z
[ "python", "gtk", "pygtk", "cairo" ]
What is the fastest way to draw an image in Gtk+?
959,675
<p>I have an image/pixbuf that I want to draw into a gtk.DrawingArea and refresh frequently, so the blitting operation has to be fast. Doing it the easy way:</p> <pre><code>def __init__(self): self.drawing_area = gtk.DrawingArea() self.image = gtk.gdk.pixbuf_new_from_file("image.png") def area_expose_cb(self, are...
8
2009-06-06T13:28:59Z
1,287,134
<p>It may be worth doing some benchmarking - if you draw with a small area is it still slow?</p> <p>If it is, it may be worth asking on pygtk or gtk mailing lists...</p>
0
2009-08-17T10:03:00Z
[ "python", "gtk", "pygtk", "cairo" ]
Any graphics library for unix that can draw histograms?
959,702
<p>A python program needs to draw histograms. It's ok to use 3rd party library (free). What is the best way to do that?</p>
1
2009-06-06T13:43:46Z
959,706
<p>You can use <a href="http://matplotlib.sourceforge.net/api/pyplot%5Fapi.html#matplotlib.pyplot.hist" rel="nofollow">matplotlib</a>.</p>
9
2009-06-06T13:46:26Z
[ "python", "unix", "graphics" ]
Any graphics library for unix that can draw histograms?
959,702
<p>A python program needs to draw histograms. It's ok to use 3rd party library (free). What is the best way to do that?</p>
1
2009-06-06T13:43:46Z
959,714
<p><a href="http://gnuplot-py.sourceforge.net/" rel="nofollow">Gnuplot.py</a> lets you use <a href="http://www.gnuplot.info/" rel="nofollow">Gnuplot</a> from python. </p>
3
2009-06-06T13:52:49Z
[ "python", "unix", "graphics" ]
Any graphics library for unix that can draw histograms?
959,702
<p>A python program needs to draw histograms. It's ok to use 3rd party library (free). What is the best way to do that?</p>
1
2009-06-06T13:43:46Z
960,258
<p>How much power do you need? How much external weight are you willing to take on? <a href="http://root.cern.ch/" rel="nofollow">ROOT</a> is accessible in python <a href="http://root.cern.ch/drupal/content/how-use-use-python-pyroot-interpreter" rel="nofollow">using PyROOT</a>. Heavy and a lot to learn to get the most ...
1
2009-06-06T18:30:56Z
[ "python", "unix", "graphics" ]
chunk_split in python
959,780
<p>I'm trying to find a pythonic way to do this PHP code:</p> <pre><code>chunk_split(base64_encode($picture)); </code></pre> <p><a href="http://us2.php.net/chunk%5Fsplit" rel="nofollow">http://us2.php.net/chunk_split</a></p> <p>chunk_split split the string into smaller chunks of 76 character long by adding a "\r\n" ...
0
2009-06-06T14:18:42Z
959,803
<pre><code>chunk_split = lambda s: '\r\n'.join(s[i:min(i+76, len(s))] for i in xrange(0, len(s), 76)) </code></pre>
1
2009-06-06T14:31:05Z
[ "php", "python" ]
chunk_split in python
959,780
<p>I'm trying to find a pythonic way to do this PHP code:</p> <pre><code>chunk_split(base64_encode($picture)); </code></pre> <p><a href="http://us2.php.net/chunk%5Fsplit" rel="nofollow">http://us2.php.net/chunk_split</a></p> <p>chunk_split split the string into smaller chunks of 76 character long by adding a "\r\n" ...
0
2009-06-06T14:18:42Z
959,809
<p>This should do it:</p> <pre><code>str.encode("base64").replace("\n", "\r\n") </code></pre>
2
2009-06-06T14:34:51Z
[ "php", "python" ]
How to ensure xml.dom.minidom can parse its own output?
959,782
<p>I'm trying to serialize some data to xml in a way that can be read back. I'm doing this by manually building a DOM via xml.dom.minidom, and writing it to a file using the included writexml method.</p> <p>Of particular interest is how I build the text nodes. I do this by initializing a Text object and then setting i...
0
2009-06-06T14:19:19Z
959,799
<p>The issue you're encountering, as explained in Python's <a href="http://docs.python.org/library/xml.dom.minidom.html" rel="nofollow">online docs</a>, is that of Unicode encoding:</p> <pre><code>Node.toxml([encoding]) Return the XML that the DOM represents as a string. With no argument, the XML header does not spec...
3
2009-06-06T14:29:45Z
[ "python", "xml", "dom", "escaping" ]
Django EmailMultiAlternatives and HTML e-mail display in Outlook 2003 on Win2003
959,985
<p>I'm using django.core.mail.EmailMultiAlternatives when sending e-mails from my django app in an attempt to make sure that the message downgrades to text if the e-mail client doesn't support HTML.</p> <p>Here is my send_email method:</p> <pre><code>def send_email(self, from_address, to_list, subject, msg_text, msg_...
2
2009-06-06T15:48:27Z
963,481
<p>I don't have an Outlook installation available to test this, so I'm wondering about the reason for the fifth line in your function.</p> <pre><code>self.msg.content_subtype = "html"</code></pre> <p>I don't know much about multipart email internals, but on my system that line causes both parts of the message have a ...
5
2009-06-08T05:02:20Z
[ "python", "html", "django", "email" ]
where can I find GladeGen?
960,049
<p>I'd like to design a GUI using Glade, and generate python code from it. The thing is, I can't find GladeGen. Does anyone know where it can be downloaded from?</p>
3
2009-06-06T16:18:05Z
960,057
<p>Why not use the GUI designer is something like Anjuta or the Glade program, write that out to <strong>glade XML</strong> and use the python bindings for libglade to use the XML file ... Kind of like XAML.</p> <p><strong>Edit, added some links to Glade.xml->python</strong></p> <p><a href="http://glc.sourceforge.net...
2
2009-06-06T16:23:17Z
[ "python", "gtk", "glade" ]
where can I find GladeGen?
960,049
<p>I'd like to design a GUI using Glade, and generate python code from it. The thing is, I can't find GladeGen. Does anyone know where it can be downloaded from?</p>
3
2009-06-06T16:18:05Z
960,245
<p>Google is your friend.</p> <p><a href="http://www.linuxjournal.com/article/7558" rel="nofollow">http://www.linuxjournal.com/article/7558</a></p>
2
2009-06-06T18:23:09Z
[ "python", "gtk", "glade" ]
where can I find GladeGen?
960,049
<p>I'd like to design a GUI using Glade, and generate python code from it. The thing is, I can't find GladeGen. Does anyone know where it can be downloaded from?</p>
3
2009-06-06T16:18:05Z
989,765
<p>My suggestion is - don't generate code. Glade 3.6 can now save in the GtkBuilder format (xml), which can be loaded in your code. This is much easier to deal with!</p> <p><a href="http://www.pygtk.org/pygtk2reference/class-gtkbuilder.html" rel="nofollow">http://www.pygtk.org/pygtk2reference/class-gtkbuilder.html</a>...
0
2009-06-13T02:16:26Z
[ "python", "gtk", "glade" ]
where can I find GladeGen?
960,049
<p>I'd like to design a GUI using Glade, and generate python code from it. The thing is, I can't find GladeGen. Does anyone know where it can be downloaded from?</p>
3
2009-06-06T16:18:05Z
24,479,543
<p>It seems to have been copied to this Bazaar repository in launchpad:</p> <p><a href="https://code.launchpad.net/~wattazoum/pydevtools/gladegen" rel="nofollow">launchpad.net/~wattazoum: gladegen : Code : Python dev tools</a></p> <p>(direct <a href="http://bazaar.launchpad.net/~wattazoum/pydevtools/gladegen/tarball/...
0
2014-06-29T19:36:40Z
[ "python", "gtk", "glade" ]
Python App Engine projects with sophisticated user-role-permission structures
960,125
<p>In followup to an <a href="http://stackoverflow.com/questions/948631/users-and-roles-in-context">earlier question</a>, I'd be interested to know whether anyone can recommend some open-source Python-based Google App Engine projects with complex user-role-permission models to consult as a reference. A link to the cod...
2
2009-06-06T17:14:01Z
965,605
<p>App-Engine-Patch ports the django permission model over to AppEngine. Scroll down to the Permissions section of this page: <a href="http://code.google.com/p/app-engine-patch/wiki/GettingStarted" rel="nofollow">http://code.google.com/p/app-engine-patch/wiki/GettingStarted</a>. The source code is available from that...
3
2009-06-08T15:50:45Z
[ "python", "google-app-engine", "roles" ]
How do I use 'F' keys in gtk Accelerators?
960,269
<p>I'm trying (in python) to use gtk.Widget.add_accelerator... what should I pass as accel_key to use the F keys? Have attempted to check the docs to no avail. Thanks</p>
2
2009-06-06T18:34:54Z
960,314
<p>Found it:</p> <pre><code>key,mods=gtk.accelerator_parse("F10") </code></pre>
1
2009-06-06T19:06:46Z
[ "python", "gtk", "accelerator" ]
How do I use 'F' keys in gtk Accelerators?
960,269
<p>I'm trying (in python) to use gtk.Widget.add_accelerator... what should I pass as accel_key to use the F keys? Have attempted to check the docs to no avail. Thanks</p>
2
2009-06-06T18:34:54Z
960,315
<p>Consider using <code>gtk.accelerator_parse()</code>. <a href="http://www.islascruz.org/html/index.php?Blog/SingleView/id/Pygtk%3A-About-keyboard-accelerators" rel="nofollow">Here is an informative post on dealing with keyboard codes in pygtk</a>.</p>
2
2009-06-06T19:07:01Z
[ "python", "gtk", "accelerator" ]
how can I add a QMenu and QMenuItems to a window from Qt Designer
960,467
<p>Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this.</p>
0
2009-06-06T20:33:32Z
960,479
<p>Adding menu editing for every widget in the designer would probably make a very awkward and inconvenient UI. There's really no place you can visualize it on.</p> <p>If you're editing a QMainWindow you can edit the menu bar and its popups because there's a proper place for them to be displayed in.</p>
0
2009-06-06T20:38:38Z
[ "python", "qt", "widget", "designer" ]
how can I add a QMenu and QMenuItems to a window from Qt Designer
960,467
<p>Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this.</p>
0
2009-06-06T20:33:32Z
960,506
<p>When you edit a QMainWindow you can right click the window and then choose "create menu bar".</p> <p>Or are you talking about a "context menu" aka "right click menu"?</p>
2
2009-06-06T20:48:02Z
[ "python", "qt", "widget", "designer" ]
how can I add a QMenu and QMenuItems to a window from Qt Designer
960,467
<p>Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this.</p>
0
2009-06-06T20:33:32Z
1,235,766
<p>I have a single main window with a QGraphicsView and lots of QGraphicsItem objects. Each type of the Items have a different context menu.</p> <p>I find that not being able to create the contextMenu's, or at least the actions that are in them a serious limitation of QtDesigner. It means that I can create about 10%...
2
2009-08-05T21:08:00Z
[ "python", "qt", "widget", "designer" ]
Python's file.read() on Ubuntu
960,487
<p>Python's <code>file.read()</code> function won't read anything. It always returns <code>''</code> no matter what's inside the file. What can it be? I know it must be something straightforward, but I can't figure it out.</p> <p><strong>UPD</strong>: I tried with 'r' and 'w+' modes.</p> <p><strong>UPD</strong>: The ...
1
2009-06-06T20:42:52Z
960,514
<p>Caveat: I'm just guessing as to behavior that is not 'working':</p> <p>If you're working in the Python interpreter, <br /> and you do something like this:</p> <pre><code>&gt;&gt;&gt; f = open('myfile.txt', 'r') &gt;&gt;&gt; f.read() </code></pre> <p>...you'll get the whole file printed to the screen.</p> <p>But...
2
2009-06-06T20:53:33Z
[ "python", "file", "ubuntu" ]
What is the proper way to compute the fully expanded width of wx.TreeCtrl
960,489
<p>The preferred size of the wx.TreeCtrl seems to be the minimum size into which all elements will fit when the tree is completely collapsed. Is there a good (ie cross-platform compatible) way to compute the width of the tree with everything expanded? My current solution is this:</p> <pre><code>def max_width(self): ...
2
2009-06-06T20:44:16Z
960,957
<p>I find that the <code>GetBestSize</code> seems to consider the collapsed items. For example, with the <code>wxTreeCtrl</code> in the demo (using Ubuntu, and wxPython 2.8.7.1), when I change the length of the inner text string (line 74 in my version of the demo) the return value of <code>self.tree.GetBestSize()</cod...
1
2009-06-07T01:11:04Z
[ "python", "wxpython", "size" ]
What is the proper way to compute the fully expanded width of wx.TreeCtrl
960,489
<p>The preferred size of the wx.TreeCtrl seems to be the minimum size into which all elements will fit when the tree is completely collapsed. Is there a good (ie cross-platform compatible) way to compute the width of the tree with everything expanded? My current solution is this:</p> <pre><code>def max_width(self): ...
2
2009-06-06T20:44:16Z
975,622
<p>This code works for me on both windows and linux:</p> <pre><code>def compute_best_size(self): if os.name == 'nt': best_size = (self.__max_width_win32(), -1) else: best_size = (self.__max_width(), -1) self.SetMinSize(best_size) def __max_width_win32(self): dc = wx.ScreenDC() dc.S...
0
2009-06-10T13:32:11Z
[ "python", "wxpython", "size" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
960,571
<p><a href="http://docs.python.org/library/itertools.html?highlight=itertools#itertools.permutations" rel="nofollow"><code>itertools.permutations</code></a> does exactly what you want. you might make of use of <a href="http://docs.python.org/library/functions.html?highlight=reversed#reversed" rel="nofollow"><code>rever...
0
2009-06-06T21:23:19Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
960,612
<p><strong>EDIT</strong>: changed completely to keep everything as a generator (never the whole list in memory). Should fulfill the requirements (only calculates half of the possible permutations (not the reverse ones). <strong>EDIT2</strong>: added shorter (and simpler) factorial function from <a href="http://importan...
3
2009-06-06T21:41:56Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
960,651
<p>How about this:</p> <pre><code>from itertools import permutations def rev_generator(plist): reversed_elements = set() for i in permutations(plist): if i not in reversed_elements: reversed_i = tuple(reversed(i)) reversed_elements.add(reversed_i) yield i &gt;&gt;&...
2
2009-06-06T22:01:06Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
960,686
<p>Here is code that does the trick. To get rid of the dups I noticed that for your list if the value of the first location is greater than the value of the last location then it will be a dup. I create a map to keep track of where each item was in the list to start with and then use that map to do the test. The code ...
2
2009-06-06T22:18:05Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
960,725
<p>this is an implementation of onebyone's suggestion</p> <p>from <a href="http://en.wikipedia.org/wiki/Permutation#Lexicographical_order_generation" rel="nofollow">http://en.wikipedia.org/wiki/Permutation#Lexicographical_order_generation</a> The following algorithm generates the next permutation lexicographically aft...
1
2009-06-06T22:44:03Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
960,730
<p>If you generate permutations in lexicographical order, then you don't need to store anything to work out whether the reverse of a given permutation has already been seen. You just have to lexicographically compare it to its reverse - if it's smaller then return it, if it's larger then skip it.</p> <p>There's probab...
10
2009-06-06T22:46:24Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
961,563
<p>Some setup code first:</p> <pre><code>try: from itertools import permutations except ImportError: # straight from http://docs.python.org/library/itertools.html#itertools.permutations def permutations(iterable, r=None): # permutations('ABCD', 2) --&gt; AB AC AD BA BC BD CA CB CD DA DB DC ...
1
2009-06-07T09:14:46Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
962,134
<p>This is a more concise and faster version of ChristopheD's accepted answer, which I liked a lot. Recursion is great. I made it enforce uniquenss of the incoming list by removing duplicates, however maybe it should just raise an exception instead.</p> <pre><code>def fac(x): return (1 if x==0 else x * fac(x-1)...
3
2009-06-07T15:46:56Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
963,022
<p>Here is my implementation:</p> <pre><code>a = [1,2,3,4] def p(l): if len(l) &lt;= 1: yield l else: for i in range(len(l)): for q in p([l[j] for j in range(len(l)) if j != i]): yield [l[i]] + q out = (i for i in p(a) if i &lt; i[::-1]) </code></pre> <p>P function is a regular permu funct...
2
2009-06-07T23:26:32Z
[ "python", "algorithm", "generator", "combinatorics" ]
How to generate permutations of a list without "reverse duplicates" in Python using generators
960,557
<p>This is related to question <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">How to generate all permutations of a list in Python</a></p> <p>How to generate all permutations that <em>match following criteria</em>: <strong>if two permutations are reverse of eac...
5
2009-06-06T21:15:22Z
1,985,841
<p>I have a marvelous followup to SilentGhost's proposal - posting a separate answer since the margins of a comment would be too narrow to contain code :-)</p> <p><code>itertools.permutations</code> is built in (since 2.6) and fast. We just need a filtering condition that for every (perm, perm[::-1]) would accept exa...
6
2009-12-31T15:32:12Z
[ "python", "algorithm", "generator", "combinatorics" ]
python3.0: imputils
960,646
<p>Why was the imputil module removed from python3.0 and what should be used in its place?</p>
4
2009-06-06T21:58:16Z
960,665
<p>According to <a href="http://www.python.org/dev/peps/pep-3108/#hardly-used-done">PEP 3108</a>, it was rarely used, undocumented and never updated to support absolute imports.</p>
9
2009-06-06T22:09:39Z
[ "python-3.x", "python" ]
python3.0: imputils
960,646
<p>Why was the imputil module removed from python3.0 and what should be used in its place?</p>
4
2009-06-06T21:58:16Z
960,759
<p>In Python 3.1, there is a module called <a href="http://doc.python.org/dev/py3k/library/importlib.html">importlib</a>, which should be a superior replacement for imputil.</p>
10
2009-06-06T23:04:26Z
[ "python-3.x", "python" ]
Python creating a dictionary of lists
960,733
<p>I want to create a dictionary whose values are lists. For example: </p> <pre><code>{ 1: ['1'], 2: ['1','2'], 3: ['2'] } </code></pre> <p>If I do:</p> <pre><code>d = dict() a = ['1', '2'] for i in a: for j in range(int(i), int(i) + 2): d[j].append(i) </code></pre> <p>I get a KeyError, because ...
131
2009-06-06T22:47:29Z
960,735
<p>Use <code>setdefault</code>:</p> <pre><code>d = dict() a = ['1', '2'] for i in a: for j in range(int(i), int(i) + 2): d.setdefault(j, []).append(i) print d # prints {1: ['1'], 2: ['1', '2'], 3: ['2']} </code></pre> <p>The rather oddly-named <code>setdefault</code> function says "Get the value with t...
18
2009-06-06T22:49:49Z
[ "python", "dictionary" ]
Python creating a dictionary of lists
960,733
<p>I want to create a dictionary whose values are lists. For example: </p> <pre><code>{ 1: ['1'], 2: ['1','2'], 3: ['2'] } </code></pre> <p>If I do:</p> <pre><code>d = dict() a = ['1', '2'] for i in a: for j in range(int(i), int(i) + 2): d[j].append(i) </code></pre> <p>I get a KeyError, because ...
131
2009-06-06T22:47:29Z
960,748
<p>You can build it with list comprehension like this:</p> <pre><code>&gt;&gt;&gt; dict((i, range(int(i), int(i) + 2)) for i in ['1', '2']) {'1': [1, 2], '2': [2, 3]} </code></pre> <p>And for the second part of your question use <a href="http://www.python.org/doc/2.5.2/lib/defaultdict-examples.html">defaultdict</a></...
34
2009-06-06T22:54:33Z
[ "python", "dictionary" ]
Python creating a dictionary of lists
960,733
<p>I want to create a dictionary whose values are lists. For example: </p> <pre><code>{ 1: ['1'], 2: ['1','2'], 3: ['2'] } </code></pre> <p>If I do:</p> <pre><code>d = dict() a = ['1', '2'] for i in a: for j in range(int(i), int(i) + 2): d[j].append(i) </code></pre> <p>I get a KeyError, because ...
131
2009-06-06T22:47:29Z
960,753
<p>You can use <a href="http://docs.python.org/library/collections.html#collections.defaultdict">defaultdict</a>:</p> <pre><code>&gt;&gt;&gt; from collections import defaultdict &gt;&gt;&gt; d = defaultdict(list) &gt;&gt;&gt; for i in a: ... for j in range(int(i), int(i) + 2): ... d[j].append(i) ... &gt;&gt;&gt;...
164
2009-06-06T23:00:39Z
[ "python", "dictionary" ]
Python creating a dictionary of lists
960,733
<p>I want to create a dictionary whose values are lists. For example: </p> <pre><code>{ 1: ['1'], 2: ['1','2'], 3: ['2'] } </code></pre> <p>If I do:</p> <pre><code>d = dict() a = ['1', '2'] for i in a: for j in range(int(i), int(i) + 2): d[j].append(i) </code></pre> <p>I get a KeyError, because ...
131
2009-06-06T22:47:29Z
961,154
<p>Your question has already been answered, but IIRC you can replace lines like:</p> <pre><code>if d.has_key(scope_item): </code></pre> <p>with:</p> <pre><code>if scope_item in d: </code></pre> <p>That is, <code>d</code> references <code>d.keys()</code> in that construction. Sometimes <code>defaultdict</code> isn't...
1
2009-06-07T03:51:47Z
[ "python", "dictionary" ]
PEP 302 Example: New Import Hooks
960,832
<p>Where can I find an example implementation of the "New Import Hooks" described in <a href="http://www.python.org/dev/peps/pep-0302/">PEP 302</a>?</p> <p>I would like to implement a custom finder and loader in the most forward compatible way possible. In other words, the implementation should work in python 2.x and...
12
2009-06-06T23:50:42Z
960,844
<p>You can find thousands of open-source examples e.g. with a <a href="http://www.google.com/codesearch?hl=en&amp;lr=&amp;q=&quot;imp.find_module&quot;+&quot;imp.load_module&quot;&amp;sbtn=Search" rel="nofollow">google code search</a>, here it is:</p> <pre><code>http://www.google.com/codesearch?hl=en&amp;lr=&amp;q="im...
4
2009-06-06T23:56:27Z
[ "python-3.x", "python", "http-status-code-302", "import-hooks" ]
Trie (Prefix Tree) in Python
960,963
<p>I don't know if this is the place to ask about algorithms. But let's see if I get any answers ... :)</p> <p>If anything is unclear I'm very happy to clarify things.</p> <p>I just implemented a <a href="http://en.wikipedia.org/wiki/Trie">Trie</a> in python. However, one bit seemed to be more complicated than it oug...
16
2009-06-07T01:14:07Z
960,971
<p>I don't see anything wrong with your approach. If you're looking for a spike solution, perhaps the action taken in case 4 is actually feasible for the first three cases, IE find the common prefix to <code>k</code> and <code>k'</code> and rebuild the node with that in mind. If it happens that the keys were prefixes...
2
2009-06-07T01:21:00Z
[ "python", "algorithm", "trie" ]
Trie (Prefix Tree) in Python
960,963
<p>I don't know if this is the place to ask about algorithms. But let's see if I get any answers ... :)</p> <p>If anything is unclear I'm very happy to clarify things.</p> <p>I just implemented a <a href="http://en.wikipedia.org/wiki/Trie">Trie</a> in python. However, one bit seemed to be more complicated than it oug...
16
2009-06-07T01:14:07Z
961,039
<p>At a glance, it sounds like you've implemented a <a href="http://portal.acm.org/citation.cfm?id=321481">Patricia Trie</a>. This approach also is called path compression in some of the literature. There should be copies of that paper that aren't behind the ACM paywall, which will include an insertion algorithm.</p> ...
18
2009-06-07T02:09:25Z
[ "python", "algorithm", "trie" ]
Trie (Prefix Tree) in Python
960,963
<p>I don't know if this is the place to ask about algorithms. But let's see if I get any answers ... :)</p> <p>If anything is unclear I'm very happy to clarify things.</p> <p>I just implemented a <a href="http://en.wikipedia.org/wiki/Trie">Trie</a> in python. However, one bit seemed to be more complicated than it oug...
16
2009-06-07T01:14:07Z
961,271
<p>Somewhat of a tangent, but if you are super worried about the number of nodes in your Trie, you may look at joining your word suffixes too. I'd take a look at the DAWG (Directed Acyclic Word Graph) idea: <a href="http://en.wikipedia.org/wiki/Directed_acyclic_word_graph" rel="nofollow">http://en.wikipedia.org/wiki/D...
2
2009-06-07T05:33:28Z
[ "python", "algorithm", "trie" ]
Trie (Prefix Tree) in Python
960,963
<p>I don't know if this is the place to ask about algorithms. But let's see if I get any answers ... :)</p> <p>If anything is unclear I'm very happy to clarify things.</p> <p>I just implemented a <a href="http://en.wikipedia.org/wiki/Trie">Trie</a> in python. However, one bit seemed to be more complicated than it oug...
16
2009-06-07T01:14:07Z
961,282
<p>I have a question regarding your implementation. What is the level of granularity that you decide to split your strings on to make the prefix tree. You could split stack as either s,t,a,c,k or st,ta,ac,ck and many other ngrams of it. Most prefix tree implementations take into account an alphabet for the language, ba...
2
2009-06-07T05:46:21Z
[ "python", "algorithm", "trie" ]
Trie (Prefix Tree) in Python
960,963
<p>I don't know if this is the place to ask about algorithms. But let's see if I get any answers ... :)</p> <p>If anything is unclear I'm very happy to clarify things.</p> <p>I just implemented a <a href="http://en.wikipedia.org/wiki/Trie">Trie</a> in python. However, one bit seemed to be more complicated than it oug...
16
2009-06-07T01:14:07Z
990,277
<p>Look at : Judy-arrays and the python interface at <a href="http://www.dalkescientific.com/Python/PyJudy.html" rel="nofollow">http://www.dalkescientific.com/Python/PyJudy.html</a></p>
1
2009-06-13T08:05:25Z
[ "python", "algorithm", "trie" ]
Python Comet Server
960,969
<p>I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very li...
30
2009-06-07T01:18:21Z
960,973
<p>I haven't done it, but <a href="http://www.rkblog.rk.edu.pl/w/p/django-and-comet/" rel="nofollow">this guy</a> has and writes a good article about it, with Django examples and pointers (which I haven't checked) to other frameworks.</p>
2
2009-06-07T01:22:44Z
[ "python", "cometd", "python-stackless" ]
Python Comet Server
960,969
<p>I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very li...
30
2009-06-07T01:18:21Z
961,191
<p>I've done tons of APIs using twisted for stuff like that, most of which are available on my <a href="http://github.com/dustin" rel="nofollow">github</a> account.</p> <p>Most are client-side, but <a href="http://github.com/dustin/slosh" rel="nofollow">slosh</a> is a server I wrote to do a realtime cheap pubsub sort ...
3
2009-06-07T04:18:34Z
[ "python", "cometd", "python-stackless" ]
Python Comet Server
960,969
<p>I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very li...
30
2009-06-07T01:18:21Z
1,216,820
<p><a href="http://www.orbited.org/">Orbited</a> seems as a nice solution. Haven't tried it though.</p> <hr> <p><em><strong>Update</strong>: things have changed in the last 2.5 years.</em></p> <p>We now have websockets in all major browsers, except IE (naturally) and a couple of very good abstractions over it, that ...
12
2009-08-01T15:27:37Z
[ "python", "cometd", "python-stackless" ]
Python Comet Server
960,969
<p>I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very li...
30
2009-06-07T01:18:21Z
1,309,560
<p>I recommend you use <a href="http://www.stream-hub.com/">StreamHub Comet Server</a> - its used by a lot of people - personally I use it with a couple of Django sites I run. You will need to write a tiny bit of Java to handle the streaming - I did this using <a href="http://www.jython.org/">Jython</a>. The front-en...
8
2009-08-21T00:41:01Z
[ "python", "cometd", "python-stackless" ]
Python Comet Server
960,969
<p>I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very li...
30
2009-06-07T01:18:21Z
1,690,327
<p>Here is a full-featured example of combining Django, Orbited,and Twisted to create a real-time (Comet) app: <a href="http://github.com/clemesha/hotdot">http://github.com/clemesha/hotdot</a> using Python.</p>
5
2009-11-06T20:49:39Z
[ "python", "cometd", "python-stackless" ]
Python Comet Server
960,969
<p>I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very li...
30
2009-06-07T01:18:21Z
2,303,584
<p>the orbited and redis solutions are nice, but not longer relevant when you have something like the PubSubHubbub that google released. This makes it very easy to be the publisher or the subscriber to a given feed. <a href="http://code.google.com/p/pubsubhubbub/" rel="nofollow">http://code.google.com/p/pubsubhubbub/</...
1
2010-02-20T20:21:08Z
[ "python", "cometd", "python-stackless" ]
Python Comet Server
960,969
<p>I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very li...
30
2009-06-07T01:18:21Z
2,612,344
<p><a href="http://blog.gevent.org/2009/10/10/simpler-long-polling-with-django-and-gevent/" rel="nofollow">Here's an example that does long-polling with gevent and Django</a>.</p> <p>It uses <a href="http://pypi.python.org/pypi/greenlet" rel="nofollow">greenlet</a> - stack switching functionality from Stackless packag...
1
2010-04-10T05:17:08Z
[ "python", "cometd", "python-stackless" ]
Get class that defined method
961,048
<p>How can I get the class that defined a method in Python?</p> <p>I'd want the following example to print "<code>__main__.FooClass</code>":</p> <pre><code>class FooClass: def foo_method(self): print "foo" class BarClass(FooClass): pass bar = BarClass() print get_class_that_defined_method(bar.foo_me...
35
2009-06-07T02:18:12Z
961,057
<pre><code>import inspect def get_class_that_defined_method(meth): for cls in inspect.getmro(meth.im_class): if meth.__name__ in cls.__dict__: return cls return None </code></pre>
44
2009-06-07T02:23:02Z
[ "python", "python-2.6", "python-datamodel" ]
Get class that defined method
961,048
<p>How can I get the class that defined a method in Python?</p> <p>I'd want the following example to print "<code>__main__.FooClass</code>":</p> <pre><code>class FooClass: def foo_method(self): print "foo" class BarClass(FooClass): pass bar = BarClass() print get_class_that_defined_method(bar.foo_me...
35
2009-06-07T02:18:12Z
13,628,116
<p>Thanks Sr2222 for pointing out I was missing the point...</p> <p>Here's the corrected approach which is just like Alex's but does not require to import anything. I don't think it's an improvement though, unless there's a huge hierarchy of inherited classes as this approach stops as soon as the defining class is fou...
3
2012-11-29T14:38:10Z
[ "python", "python-2.6", "python-datamodel" ]
Get class that defined method
961,048
<p>How can I get the class that defined a method in Python?</p> <p>I'd want the following example to print "<code>__main__.FooClass</code>":</p> <pre><code>class FooClass: def foo_method(self): print "foo" class BarClass(FooClass): pass bar = BarClass() print get_class_that_defined_method(bar.foo_me...
35
2009-06-07T02:18:12Z
26,391,792
<p>I started doing something somewhat similar, basically the idea was checking whenever a method in a base class had been implemented or not in a sub class. Turned out the way I originally did it I could not detect when an intermediate class was actually implementing the method.</p> <p>My workaround for it was quite s...
1
2014-10-15T20:44:40Z
[ "python", "python-2.6", "python-datamodel" ]
Reloading module giving NameError: name 'reload' is not defined
961,162
<p>I'm trying to reload a module I have already imported in Python 3. I know that you only need to import once and executing the <code>import</code> command again won't do anything. </p> <p>Executing <code>reload(foo)</code> is giving this error:</p> <pre><code>Traceback (most recent call last): File "(stdin)", l...
68
2009-06-07T03:55:15Z
961,165
<p>You deleted your __builtins__ variable. </p> <p>How to fix this? Don't delete __builtins__.</p> <blockquote> <p>Also can someone explain step by step what that error message means?</p> </blockquote> <p>It means python can't find the function "reload".</p> <blockquote> <p>reload (script4.py)</p> </blockquote>...
-9
2009-06-07T04:00:16Z
[ "python", "python-3.x" ]
Reloading module giving NameError: name 'reload' is not defined
961,162
<p>I'm trying to reload a module I have already imported in Python 3. I know that you only need to import once and executing the <code>import</code> command again won't do anything. </p> <p>Executing <code>reload(foo)</code> is giving this error:</p> <pre><code>Traceback (most recent call last): File "(stdin)", l...
68
2009-06-07T03:55:15Z
961,219
<p><a href="https://docs.python.org/2/library/functions.html#reload"><code>reload</code></a> is a builtin in Python 2, but not in Python 3, so the error you're seeing is expected.</p> <p>If you truly must reload a module in Python 3, you should use either:</p> <ul> <li><a href="https://docs.python.org/3/library/impor...
98
2009-06-07T04:41:25Z
[ "python", "python-3.x" ]
Reloading module giving NameError: name 'reload' is not defined
961,162
<p>I'm trying to reload a module I have already imported in Python 3. I know that you only need to import once and executing the <code>import</code> command again won't do anything. </p> <p>Executing <code>reload(foo)</code> is giving this error:</p> <pre><code>Traceback (most recent call last): File "(stdin)", l...
68
2009-06-07T03:55:15Z
8,691,152
<pre><code>import imp imp.reload(script4) </code></pre>
47
2012-01-01T00:02:09Z
[ "python", "python-3.x" ]
Reloading module giving NameError: name 'reload' is not defined
961,162
<p>I'm trying to reload a module I have already imported in Python 3. I know that you only need to import once and executing the <code>import</code> command again won't do anything. </p> <p>Executing <code>reload(foo)</code> is giving this error:</p> <pre><code>Traceback (most recent call last): File "(stdin)", l...
68
2009-06-07T03:55:15Z
33,409,066
<p><strong><em>For >= Python3.4:</em></strong></p> <pre><code>import importlib importlib.reload(module) </code></pre> <p><strong><em>For &lt;= Python3.3:</em></strong></p> <pre><code>import imp imp.reload(module) </code></pre> <p><strong><em>For Python2.x:</em></strong></p> <p>Use the in-built <code>reload()</code...
25
2015-10-29T08:19:33Z
[ "python", "python-3.x" ]
Reloading module giving NameError: name 'reload' is not defined
961,162
<p>I'm trying to reload a module I have already imported in Python 3. I know that you only need to import once and executing the <code>import</code> command again won't do anything. </p> <p>Executing <code>reload(foo)</code> is giving this error:</p> <pre><code>Traceback (most recent call last): File "(stdin)", l...
68
2009-06-07T03:55:15Z
40,119,302
<p>To expand on the previously written answers, if you want a single solution which will work across Python versions 2 and 3, you can use the following:</p> <pre><code>try: reload # Python 2.7 except NameError: try: from importlib import reload # Python 3.4+ except ImportError: from imp i...
0
2016-10-18T22:44:41Z
[ "python", "python-3.x" ]
Two values from one input in python?
961,263
<p>This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python? </p> <p>For instance, in C I can do something like this: <code>scanf("%d %d", &amp;var1, &amp;var2)</code>. However, I can't...
15
2009-06-07T05:27:53Z
961,276
<p>You can't really do it the C way (I think) but a pythonic way of doing this would be (if your 'inputs' have spaces in between them):</p> <pre><code>raw_answer = raw_input() answers = raw_answer.split(' ') # list of 'answers' </code></pre> <p>So you could rewrite your try to:</p> <pre><code>var1, var2 = raw_input(...
4
2009-06-07T05:39:01Z
[ "python", "variables", "input" ]
Two values from one input in python?
961,263
<p>This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python? </p> <p>For instance, in C I can do something like this: <code>scanf("%d %d", &amp;var1, &amp;var2)</code>. However, I can't...
15
2009-06-07T05:27:53Z
961,300
<p>The Python way to map</p> <pre><code>printf("Enter two numbers here: "); scanf("%d %d", &amp;var1, &amp;var2) </code></pre> <p>would be </p> <pre><code>var1, var2 = raw_input("Enter two numbers here: ").split() </code></pre> <p>Note that we don't have to explicitly specify <code>split(' ')</code> because <code>s...
28
2009-06-07T05:59:45Z
[ "python", "variables", "input" ]
Two values from one input in python?
961,263
<p>This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python? </p> <p>For instance, in C I can do something like this: <code>scanf("%d %d", &amp;var1, &amp;var2)</code>. However, I can't...
15
2009-06-07T05:27:53Z
961,322
<p>In <code>Python 2.*</code>, <code>input</code> lets the user enter any expression, e.g. a tuple:</p> <pre><code>&gt;&gt;&gt; a, b = input('Two numbers please (with a comma in between): ') Two numbers please (with a comma in between): 23, 45 &gt;&gt;&gt; print a, b 23 45 </code></pre> <p>In <code>Python 3.*</code>,...
8
2009-06-07T06:19:06Z
[ "python", "variables", "input" ]
Two values from one input in python?
961,263
<p>This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python? </p> <p>For instance, in C I can do something like this: <code>scanf("%d %d", &amp;var1, &amp;var2)</code>. However, I can't...
15
2009-06-07T05:27:53Z
961,329
<p>All input will be through a string. It's up to you to process that string after you've received it. Unless that is, you use the eval(input()) method, but that isn't recommended for most situations anyway.</p> <pre><code>input_string = raw_input("Enter 2 numbers here: ") a, b = split_string_into_numbers(input_string...
2
2009-06-07T06:26:38Z
[ "python", "variables", "input" ]
Two values from one input in python?
961,263
<p>This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python? </p> <p>For instance, in C I can do something like this: <code>scanf("%d %d", &amp;var1, &amp;var2)</code>. However, I can't...
15
2009-06-07T05:27:53Z
21,816,747
<p>Check this handy function:</p> <pre><code>def gets(*types): return tuple([types[i](val) for i, val in enumerate(raw_input().split(' '))]) # usage: a, b, c = gets(int, float, str) </code></pre>
1
2014-02-16T21:15:48Z
[ "python", "variables", "input" ]
Two values from one input in python?
961,263
<p>This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python? </p> <p>For instance, in C I can do something like this: <code>scanf("%d %d", &amp;var1, &amp;var2)</code>. However, I can't...
15
2009-06-07T05:27:53Z
30,421,198
<p>If you need to take two integers say a,b in python you can use map function.<br> Suppose input is,</p> <pre> 1 5 3 1 2 3 4 5 </pre> <p>where 1 represent test case, 5 represent number of values and 3 represents a task value and in next line given 5 values, we can take such input using this method in PYTH 2.x Versio...
1
2015-05-24T07:42:18Z
[ "python", "variables", "input" ]
how to multiply two different array of integers in python?
961,326
<p>i have taken input in two different lists by splitting a line having integers 1 2</p> <p>for eg 1 2</p> <p>3 4</p> <p>so now i have split it and kept it in lists , and want to multiply them like 1*3 +2*4, but when i try to do it , its giving me that it can only multiply integers and not lists !! help here</p> <...
2
2009-06-07T06:20:45Z
961,327
<p>You need:</p> <pre><code>&gt;&gt;&gt; a = [1,2] &gt;&gt;&gt; b = [3,4] &gt;&gt;&gt; sum(i*j for i, j in zip(a,b)) 11 </code></pre>
7
2009-06-07T06:22:43Z
[ "python" ]
how to multiply two different array of integers in python?
961,326
<p>i have taken input in two different lists by splitting a line having integers 1 2</p> <p>for eg 1 2</p> <p>3 4</p> <p>so now i have split it and kept it in lists , and want to multiply them like 1*3 +2*4, but when i try to do it , its giving me that it can only multiply integers and not lists !! help here</p> <...
2
2009-06-07T06:20:45Z
961,391
<p>You can do it in a pythonic way using sum, map and a lambda expression. </p> <pre><code>&gt;&gt;&gt; a = [1,2] &gt;&gt;&gt; b = [3,4] &gt;&gt;&gt; prod = lambda a, b: a*b &gt;&gt;&gt; sum(map(prod, a, b)) 11 </code></pre> <p>the <code>lambda a, b: a*b</code> bit also has a special name in python, <code>operator.mu...
2
2009-06-07T07:18:54Z
[ "python" ]
how to multiply two different array of integers in python?
961,326
<p>i have taken input in two different lists by splitting a line having integers 1 2</p> <p>for eg 1 2</p> <p>3 4</p> <p>so now i have split it and kept it in lists , and want to multiply them like 1*3 +2*4, but when i try to do it , its giving me that it can only multiply integers and not lists !! help here</p> <...
2
2009-06-07T06:20:45Z
961,413
<p>It has nothing to do with multiplying integers, but you should probably be using the <code>extend</code> method:</p> <pre><code> a.extend([int(i) for i in s.split(' ')]) b.extend([int(i) for i in s.split(' ')]) </code></pre> <p><code>append</code> just tacks its argument on to the list as its last element. ...
0
2009-06-07T07:32:01Z
[ "python" ]
how to multiply two different array of integers in python?
961,326
<p>i have taken input in two different lists by splitting a line having integers 1 2</p> <p>for eg 1 2</p> <p>3 4</p> <p>so now i have split it and kept it in lists , and want to multiply them like 1*3 +2*4, but when i try to do it , its giving me that it can only multiply integers and not lists !! help here</p> <...
2
2009-06-07T06:20:45Z
961,424
<p>Is this what you want?</p> <pre><code>t=raw_input() d =[] for j in range(0,int(t)): #c=0 #n=raw_input() s = raw_input() s1 =raw_input() a = [int(i) for i in s.split(' ')] b = [int(i) for i in s1.split(' ')] # &lt;--s1 not s d.append(sum(i*j for i, j in zip(a,b))) for i in d: print i...
1
2009-06-07T07:38:44Z
[ "python" ]
What does the percentage sign mean in Python 3.1
961,344
<p>In the tutorial there is an example for finding prime numbers.</p> <pre><code>&gt;&gt;&gt; for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print(n, 'equals', x, '*', n//x) ... break ... else: ... # loop fell through without finding a factor ......
24
2009-06-07T06:47:03Z
961,349
<p>In python 2.6 the '%' operator performed a modulus. I don't think they changed it in 3.0.1</p> <p>The modulo operator tells you the remainder of a division of two numbers. </p>
1
2009-06-07T06:49:41Z
[ "python" ]
What does the percentage sign mean in Python 3.1
961,344
<p>In the tutorial there is an example for finding prime numbers.</p> <pre><code>&gt;&gt;&gt; for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print(n, 'equals', x, '*', n//x) ... break ... else: ... # loop fell through without finding a factor ......
24
2009-06-07T06:47:03Z
961,351
<p>Modulus operator; gives the remainder of the left value divided by the right value. Like:</p> <p><code>3 % 1</code> would equal zero (since 3 divides evenly by 1)</p> <p><code>3 % 2</code> would equal 1 (since dividing 3 by 2 results in a remainder of 1).</p>
32
2009-06-07T06:50:49Z
[ "python" ]
What does the percentage sign mean in Python 3.1
961,344
<p>In the tutorial there is an example for finding prime numbers.</p> <pre><code>&gt;&gt;&gt; for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print(n, 'equals', x, '*', n//x) ... break ... else: ... # loop fell through without finding a factor ......
24
2009-06-07T06:47:03Z
961,352
<p>It checks if the modulo of the division. For example, in the case you are iterating over all numbers from 2 to n and checking if n is divisible by any of the numbers in between. Simply put, you are checking if a given number n is prime. (Hint: You could check up to n/2).</p>
1
2009-06-07T06:50:55Z
[ "python" ]
What does the percentage sign mean in Python 3.1
961,344
<p>In the tutorial there is an example for finding prime numbers.</p> <pre><code>&gt;&gt;&gt; for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print(n, 'equals', x, '*', n//x) ... break ... else: ... # loop fell through without finding a factor ......
24
2009-06-07T06:47:03Z
961,365
<p>The % does two things, depending on its arguments. In this case, it acts as the modulo operator, meaning when its arguments are numbers, it divides the first by the second and returns the <em>remainder</em>. <code>34 % 10 == 4</code> since 34 divided by 10 is three, with a remainder of four. </p> <p>If the first...
64
2009-06-07T06:58:52Z
[ "python" ]
What does the percentage sign mean in Python 3.1
961,344
<p>In the tutorial there is an example for finding prime numbers.</p> <pre><code>&gt;&gt;&gt; for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print(n, 'equals', x, '*', n//x) ... break ... else: ... # loop fell through without finding a factor ......
24
2009-06-07T06:47:03Z
8,027,142
<p>The modulus operator. The remainder when you divide two number.</p> <p>For Example:</p> <pre><code>&gt;&gt;&gt; 5 % 2 = 1 # remainder of 5 divided by 2 is 1 &gt;&gt;&gt; 7 % 3 = 1 # remainer of 7 divided by 3 is 1 &gt;&gt;&gt; 3 % 1 = 0 # because 1 divides evenly into 3 </code></pre>
1
2011-11-06T13:03:08Z
[ "python" ]
Identical Error Codes
961,465
<p>I use python 2.4.1 on Linux, and a python package written inside the company I work in, for establishing a connection between 2 hosts for test purposes.</p> <p>Upon establishing the connection the side defined as the client side failed when calling <code>socket.connect</code> with the correct parameters (I checked)...
2
2009-06-07T08:08:26Z
961,484
<p>It appears Python is exposing the error code from the OS - the interpretation of the code is OS-dependent.</p> <p>111 is <code>ECONNREFUSED</code> on many Linux systems, and on Cygwin.</p> <p>146 is <code>ECONNREFUSED</code> on Solaris.</p> <p>10061 is <code>WSAECONNREFUSED</code> in winerror.h - it's the Windows...
6
2009-06-07T08:19:49Z
[ "python", "error-handling", "sockets" ]
How to find out a^b of very large numbers in python?
961,533
<p>I am trying to find out <code>a^b</code> in python, of really large no.s </p> <p>My code is this:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) c.extend(pow(a,b)) for j in c: print j </code></pre> <p>And I am getting an error...
0
2009-06-07T08:50:01Z
961,633
<p>You should try <a href="http://gmpy.sourceforge.net/" rel="nofollow">GMPY</a>. Try something like:</p> <pre><code>import gmpy a = gmpy.mpz(10**10) b = a**10000000 </code></pre> <p>I don't know how much "big" your numbers are, this solution isn't that fast (but the result is big enough :P )</p>
1
2009-06-07T10:23:21Z
[ "python" ]
How to find out a^b of very large numbers in python?
961,533
<p>I am trying to find out <code>a^b</code> in python, of really large no.s </p> <p>My code is this:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) c.extend(pow(a,b)) for j in c: print j </code></pre> <p>And I am getting an error...
0
2009-06-07T08:50:01Z
961,655
<p>Another way you might want to try calculating exponents is by using logarithm laws.</p> <p>x^y = e^(y ln x)</p> <p>I can't say for certain but this might reduce the number of operations required to calculate large exponents.</p>
-1
2009-06-07T10:31:32Z
[ "python" ]
How to find out a^b of very large numbers in python?
961,533
<p>I am trying to find out <code>a^b</code> in python, of really large no.s </p> <p>My code is this:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) c.extend(pow(a,b)) for j in c: print j </code></pre> <p>And I am getting an error...
0
2009-06-07T08:50:01Z
961,681
<p>python integer ops are arbitrary precision If you want arbitrary precision floating point ops import Decimal</p> <pre><code>from decimal import * d=Decimal('2.0') print d**1234 </code></pre>
1
2009-06-07T10:43:00Z
[ "python" ]
How to find out a^b of very large numbers in python?
961,533
<p>I am trying to find out <code>a^b</code> in python, of really large no.s </p> <p>My code is this:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) c.extend(pow(a,b)) for j in c: print j </code></pre> <p>And I am getting an error...
0
2009-06-07T08:50:01Z
961,696
<p>10000**10000 prints in my machine in under a second.</p> <p>How large is your input.</p> <p>Your problem is not related to power function.</p> <p>Use </p> <pre><code>c.append() </code></pre> <p>instead of</p> <pre><code>c.extend() </code></pre> <p>c.extend takes an iterable (a list/tuple/set/custom iterables)...
2
2009-06-07T10:52:47Z
[ "python" ]
How to find out a^b of very large numbers in python?
961,533
<p>I am trying to find out <code>a^b</code> in python, of really large no.s </p> <p>My code is this:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) c.extend(pow(a,b)) for j in c: print j </code></pre> <p>And I am getting an error...
0
2009-06-07T08:50:01Z
961,785
<p>You are using extend wrong. A.extend( B ), requires that B is some iterable object( ie a list, tuple ). You really want to use append instead.</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a,b= (int(i) for i in n.split(' ')) c.append( pow(a,b) ) ## or you could extend c.exte...
3
2009-06-07T12:11:54Z
[ "python" ]
How to find out a^b of very large numbers in python?
961,533
<p>I am trying to find out <code>a^b</code> in python, of really large no.s </p> <p>My code is this:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) c.extend(pow(a,b)) for j in c: print j </code></pre> <p>And I am getting an error...
0
2009-06-07T08:50:01Z
6,312,357
<p><code>x**y</code> works greatly for exponents. If you want a more original solution, you can use:</p> <pre><code>def exp(base, exponent): round(exponent, 0) if exponent &lt; 0: return 1.0 / exp(base, -1 * exponent) if exponent == 0: return 1 if exponent &gt; 0: return base * exp(base, exponent -...
1
2011-06-10T21:41:12Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
961,636
<p>Try this:</p> <pre><code>str(i) </code></pre>
48
2009-06-07T10:23:58Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
961,638
<pre><code>&gt;&gt;&gt; str(10) '10' &gt;&gt;&gt; int('10') 10 </code></pre> <p>[Edit]</p> <p>Links to the documentation:<br> <a href="https://docs.python.org/2/library/functions.html#int"><code>int()</code></a><br> <a href="https://docs.python.org/2/library/functions.html#str"><code>str()</code></a></p> <p>[Edit]</...
1,037
2009-06-07T10:24:15Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
961,641
<pre><code>&gt;&gt;&gt; i = 5 &gt;&gt;&gt; s = str(5) &gt;&gt;&gt; print "Hello, world the number is " + s Hello, world the number is 5 </code></pre>
10
2009-06-07T10:24:40Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
961,652
<p>There is not typecast and no type coercion in Python. You have to convert your variable in a explicit way.</p> <p>To convert an object in string you use the <code>str()</code> function. It works with any object that has a method called <code>__str__()</code> defined. In fact</p> <pre><code>str(a) </code></pre> <...
28
2009-06-07T10:30:48Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
961,661
<p>To manage non-integer inputs:</p> <pre><code>number = raw_input() try: value = int(number) except ValueError: value = 0 </code></pre> <hr> <p>Ok, if I take your latest code and rewrite a bit to get it working with Python:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a...
12
2009-06-07T10:32:28Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
14,801,285
<pre><code>a=2 </code></pre> <p>you can use <code>str(a)</code> which gives you a string object of <code>int(2)</code></p>
18
2013-02-10T18:47:04Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
30,063,942
<p>The most decent way in my opinion is ``.</p> <pre><code>i = 32 --&gt; `i` == '32' </code></pre>
1
2015-05-05T21:55:46Z
[ "python" ]
Converting integer to string in Python?
961,632
<p>I want to convert an integer to a string in Python. I am typecasting it in vain:</p> <pre><code>t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j </code></pre> <p>When I try to conver...
649
2009-06-07T10:22:38Z
40,102,958
<p><strong>By using str()</strong> </p> <pre><code>integer_value=100 str(integer_value) </code></pre> <p><strong>By creating String</strong></p> <pre><code>integer_value = 100 s = "%d" % integer_value print s </code></pre>
0
2016-10-18T08:13:22Z
[ "python" ]
pygtk: How to set the height of pop-up window in gtk.EntryCompletion
961,735
<p>I use gtk.EntryCompletion to implement the autocomletion function. But the list is so long that the pop-up window touches the bottom of screen. And I cant find the method of set the height of pop-up window in doc of pygtk. How to set the height of pop-up window in gtk.EntryCompletion?</p>
2
2009-06-07T11:19:34Z
962,054
<p>I don't know if this applies to gtk.EntryCompletion widgets, but for cell like widgets you can control their height with the <code>cell.set_fixed_height_from_font(True)</code> method. </p> <p>Look at the <code>gtk.CellRendererText</code> API for details. </p>
0
2009-06-07T15:07:19Z
[ "python", "gtk", "pygtk" ]
pygtk: How to set the height of pop-up window in gtk.EntryCompletion
961,735
<p>I use gtk.EntryCompletion to implement the autocomletion function. But the list is so long that the pop-up window touches the bottom of screen. And I cant find the method of set the height of pop-up window in doc of pygtk. How to set the height of pop-up window in gtk.EntryCompletion?</p>
2
2009-06-07T11:19:34Z
7,963,132
<p>Maybe you can solve the problem using <code>gtk.EntryCompletion.set_minimum_key_length</code> to prevent long list of suggestions.</p>
0
2011-11-01T06:25:19Z
[ "python", "gtk", "pygtk" ]
How to spawn multiple python scripts from a python program?
961,838
<p>I want to spawn (fork?) multiple Python scripts from my program (written in Python as well).</p> <p>My problem is that I want to dedicate one terminal to each script, because I'll gather their output using <code>pexpect</code>.</p> <p>I've tried using <code>pexpect</code>, <code>os.execlp</code>, and <code>os.fork...
3
2009-06-07T12:59:37Z
961,864
<p>See the <a href="http://docs.python.org/library/subprocess.html#module-subprocess" rel="nofollow">subprocess module</a></p> <blockquote> <p>The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several othe...
4
2009-06-07T13:12:46Z
[ "python", "pexpect", "spawn", "tshark" ]
How to spawn multiple python scripts from a python program?
961,838
<p>I want to spawn (fork?) multiple Python scripts from my program (written in Python as well).</p> <p>My problem is that I want to dedicate one terminal to each script, because I'll gather their output using <code>pexpect</code>.</p> <p>I've tried using <code>pexpect</code>, <code>os.execlp</code>, and <code>os.fork...
3
2009-06-07T12:59:37Z
970,325
<p>I don't understand why you need expect for this. <code>tshark</code> should send its output to stdout, and only for some strange reason would it send it to stderr.</p> <p>Therefore, what you want should be:</p> <pre><code>import subprocess fp= subprocess.Popen( ("/usr/bin/tshark", "option1", "option2"), stdout=su...
0
2009-06-09T14:15:19Z
[ "python", "pexpect", "spawn", "tshark" ]
How to spawn multiple python scripts from a python program?
961,838
<p>I want to spawn (fork?) multiple Python scripts from my program (written in Python as well).</p> <p>My problem is that I want to dedicate one terminal to each script, because I'll gather their output using <code>pexpect</code>.</p> <p>I've tried using <code>pexpect</code>, <code>os.execlp</code>, and <code>os.fork...
3
2009-06-07T12:59:37Z
24,715,421
<p>You want to dedicate one terminal <strong><em>or</em></strong> one python shell?</p> <p>You already have some useful answers for Popen and Subprocess, you could also use pexpect if you're already planning on using it anyways.</p> <pre><code>#for multiple python shells import pexpect #make your commands however yo...
0
2014-07-12T17:14:43Z
[ "python", "pexpect", "spawn", "tshark" ]
python logarithm
961,972
<p>i want to find out a log10 of an integer in python and i get an error like math domain error </p> <p>my code is this w=math.log10(q*q1)/math.log10(2)</p> <p>where q1,q2 are integers</p> <p>yeah q1 is 0 sometimes</p>
1
2009-06-07T14:29:43Z
961,977
<p>Is q or q1 equal to zero or one of them negative?</p>
6
2009-06-07T14:31:53Z
[ "python" ]
python logarithm
961,972
<p>i want to find out a log10 of an integer in python and i get an error like math domain error </p> <p>my code is this w=math.log10(q*q1)/math.log10(2)</p> <p>where q1,q2 are integers</p> <p>yeah q1 is 0 sometimes</p>
1
2009-06-07T14:29:43Z
961,992
<p>math.log10(0) is minus infinity. See: <a href="http://en.wikipedia.org/wiki/Logarithm" rel="nofollow">http://en.wikipedia.org/wiki/Logarithm</a></p>
1
2009-06-07T14:37:40Z
[ "python" ]
python logarithm
961,972
<p>i want to find out a log10 of an integer in python and i get an error like math domain error </p> <p>my code is this w=math.log10(q*q1)/math.log10(2)</p> <p>where q1,q2 are integers</p> <p>yeah q1 is 0 sometimes</p>
1
2009-06-07T14:29:43Z
961,993
<p>You can only compute the logarithm of a positive number. Trying to compute the logarithm for a negative number or zero will result in a "math domain error" in Python.</p> <p>By the way: it looks like you're actually trying to compute a logarithm base 2. You can do this with <code>math.log</code>:</p> <pre><code>w=...
10
2009-06-07T14:37:51Z
[ "python" ]