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 |
|---|---|---|---|---|---|---|---|---|---|
Send an email using python script | 2,482,160 | <p>Today I needed to send email from a Python script. As always I searched Google and found the following script that fits to my need.</p>
<pre><code>import smtplib
SERVER = "localhost"
FROM = "sender@example.com"
TO = ["user@example.com"] # must be a list
SUBJECT = "Hello!"
TEXT = "This message was sent with Pyth... | 9 | 2010-03-20T06:13:18Z | 2,482,177 | <p>You have managed to shadow the stdlib <code>email</code> module by calling your script <code>email.py</code>. Rename your script to something not in the <a href="http://docs.python.org/library/index.html" rel="nofollow">stdlib</a> and try again.</p>
| 3 | 2010-03-20T06:20:23Z | [
"python",
"email"
] |
Send an email using python script | 2,482,160 | <p>Today I needed to send email from a Python script. As always I searched Google and found the following script that fits to my need.</p>
<pre><code>import smtplib
SERVER = "localhost"
FROM = "sender@example.com"
TO = ["user@example.com"] # must be a list
SUBJECT = "Hello!"
TEXT = "This message was sent with Pyth... | 9 | 2010-03-20T06:13:18Z | 2,482,445 | <p>Does your computer also have an open mail server listening on the default port?
smptlib provides methods to connect to an smtp mail server, but if your computer is not currently running one, then you cannot send mail to it.</p>
| 1 | 2010-03-20T08:49:44Z | [
"python",
"email"
] |
Seeking enlightenment - global variables in AppEngine (aeoid.get_current_user()) | 2,482,224 | <p>This may be a 'Python Web Programming 101' question, but I'm confused about some code in the aeoid project (http://github.com/Arachnid/aeoid). here's the code:</p>
<pre><code>_current_user = None
def get_current_user():
"""Returns the currently logged in user, or None if no user is logged in."""
global _cu... | 1 | 2010-03-20T06:49:31Z | 2,482,762 | <p>You are not the only one confused about globals on appengine. But I know the os.environ is unique to each request, so I think that could explain this code working right. If not, it might be so that the module this is in gets <a href="http://docs.python.org/library/functions.html#reload" rel="nofollow">forced reloade... | 0 | 2010-03-20T11:02:38Z | [
"python",
"google-app-engine",
"session",
"global-variables"
] |
Seeking enlightenment - global variables in AppEngine (aeoid.get_current_user()) | 2,482,224 | <p>This may be a 'Python Web Programming 101' question, but I'm confused about some code in the aeoid project (http://github.com/Arachnid/aeoid). here's the code:</p>
<pre><code>_current_user = None
def get_current_user():
"""Returns the currently logged in user, or None if no user is logged in."""
global _cu... | 1 | 2010-03-20T06:49:31Z | 2,482,847 | <p>The App Engine Python runtime is single-threaded - only a single request is processed, per runtime instance, at a time. As a result, you can use globals for request-specific parameters, so long as you take care to reset them at the beginning of each request, so they don't leak data from one request to another.</p>
| 2 | 2010-03-20T11:36:38Z | [
"python",
"google-app-engine",
"session",
"global-variables"
] |
Testing variable types in Python | 2,482,230 | <p>I'm creating an initialising function for the class 'Room', and found that the program wouldn't accept the tests I was doing on the input variables.</p>
<p>Why is this?</p>
<pre><code>def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = ... | 3 | 2010-03-20T06:52:16Z | 2,482,233 | <p>It's not a good idea testing for types like this. However, if you must, do:</p>
<pre><code>if isinstance(item, str):
# do your thing
</code></pre>
| 0 | 2010-03-20T06:54:44Z | [
"python",
"testing",
"variables"
] |
Testing variable types in Python | 2,482,230 | <p>I'm creating an initialising function for the class 'Room', and found that the program wouldn't accept the tests I was doing on the input variables.</p>
<p>Why is this?</p>
<pre><code>def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = ... | 3 | 2010-03-20T06:52:16Z | 2,482,240 | <p>Not answering the "why", but </p>
<ol>
<li><code>str</code> itself is a type already. You can use <code>type(self.code) != str</code></li>
<li>But a better way is to use <code>isinstance(self.code, str)</code>.</li>
</ol>
| 6 | 2010-03-20T06:56:49Z | [
"python",
"testing",
"variables"
] |
Testing variable types in Python | 2,482,230 | <p>I'm creating an initialising function for the class 'Room', and found that the program wouldn't accept the tests I was doing on the input variables.</p>
<p>Why is this?</p>
<pre><code>def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = ... | 3 | 2010-03-20T06:52:16Z | 2,482,254 | <p>Python is a dynamic language. It bad idea to test the types explicitly. In fact the code you write should in itself be such that you dont ever need to test the types of variables.</p>
<p>If you are coming from C/C++/Java then takes some time to get over that.</p>
| 7 | 2010-03-20T07:04:33Z | [
"python",
"testing",
"variables"
] |
Testing variable types in Python | 2,482,230 | <p>I'm creating an initialising function for the class 'Room', and found that the program wouldn't accept the tests I was doing on the input variables.</p>
<p>Why is this?</p>
<pre><code>def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = ... | 3 | 2010-03-20T06:52:16Z | 2,482,263 | <p>Couple of things:</p>
<ul>
<li><p>You have an incoming parameter named "type". This is masking the "type" built-in because it is a global, and locals trump globals. I assume this exception occurs because "type" has a string value.</p></li>
<li><p>Why are you printing error messages? The correct way to report an err... | 3 | 2010-03-20T07:06:18Z | [
"python",
"testing",
"variables"
] |
Testing variable types in Python | 2,482,230 | <p>I'm creating an initialising function for the class 'Room', and found that the program wouldn't accept the tests I was doing on the input variables.</p>
<p>Why is this?</p>
<pre><code>def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = ... | 3 | 2010-03-20T06:52:16Z | 2,482,287 | <p>Beside the ideas presented before you might want to check out <a href="http://code.activestate.com/recipes/454322-type-checking-decorator/" rel="nofollow">decorator based type checking</a> and <a href="http://www.wayforward.net/pycontract/" rel="nofollow">contracts</a>.</p>
<p>Historically there has been <a href="h... | 1 | 2010-03-20T07:21:11Z | [
"python",
"testing",
"variables"
] |
Testing variable types in Python | 2,482,230 | <p>I'm creating an initialising function for the class 'Room', and found that the program wouldn't accept the tests I was doing on the input variables.</p>
<p>Why is this?</p>
<pre><code>def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = ... | 3 | 2010-03-20T06:52:16Z | 2,483,277 | <p>In general don't type-check, but if it's a genuine precondition for the arguments then verify them using assert rather than printing errors to stdout.</p>
<pre><code>assert isinstance(code, str)
assert isinstance(name, str)
...
</code></pre>
| 1 | 2010-03-20T13:57:26Z | [
"python",
"testing",
"variables"
] |
Testing variable types in Python | 2,482,230 | <p>I'm creating an initialising function for the class 'Room', and found that the program wouldn't accept the tests I was doing on the input variables.</p>
<p>Why is this?</p>
<pre><code>def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = ... | 3 | 2010-03-20T06:52:16Z | 2,484,014 | <p>in python you just use the variables as if they where the type you want.
if for some reason you have a function you call with different types, you can wrap your code in a try/catch.</p>
<pre><code>def addOne(a):
'''
increments a with 1 if a is a number.
if a is a string, append '.' to it.
'''... | 0 | 2010-03-20T17:29:09Z | [
"python",
"testing",
"variables"
] |
Easiest way of unit testing C code with Python | 2,482,270 | <p>I've got a pile of C code that I'd like to unit test using Python's unittest library (in Windows), but I'm trying to work out the best way of interfacing the C code so that Python can execute it (and get the results back). Does anybody have any experience in the easiest way to do it?</p>
<p>Some ideas include:</p>
... | 13 | 2010-03-20T07:12:47Z | 2,482,281 | <p>Using ctypes would be my first instinct, though I must admit that if I was testing C code that was not going to be interfaced from Python in the first place, I would just use <a href="http://check.sourceforge.net/" rel="nofollow">check</a>. <a href="http://check.sourceforge.net/" rel="nofollow">Check</a> has the str... | 8 | 2010-03-20T07:19:18Z | [
"python",
"c",
"unit-testing",
"swig"
] |
Easiest way of unit testing C code with Python | 2,482,270 | <p>I've got a pile of C code that I'd like to unit test using Python's unittest library (in Windows), but I'm trying to work out the best way of interfacing the C code so that Python can execute it (and get the results back). Does anybody have any experience in the easiest way to do it?</p>
<p>Some ideas include:</p>
... | 13 | 2010-03-20T07:12:47Z | 2,489,948 | <p>I think that the exact solution depends on your code. Not all libraries are easily suitable for wrapping as a DLL. If your is, then <code>ctypes</code> is certainly the easiest way - just make a DLL out of your library and then test it with <code>ctypes</code>. An added bonus is that you now have your library conven... | 3 | 2010-03-22T03:59:26Z | [
"python",
"c",
"unit-testing",
"swig"
] |
Trac default language | 2,482,399 | <p>How can I set default language for trac. There's nothing about i18n in trac.ini</p>
| 1 | 2010-03-20T08:19:59Z | 2,482,434 | <p>Trac will use the locale provided by your http server by default. Easiest thing to do is just change the locale Apache is running under.</p>
<p>Or if you are running trac under mod_python you can modify the TracLocale option:</p>
<p>
SetHandler mod_python
PythonOption TracLocale "de_DE.UTF-8"
...
</... | 1 | 2010-03-20T08:43:21Z | [
"python",
"internationalization",
"trac"
] |
Trac default language | 2,482,399 | <p>How can I set default language for trac. There's nothing about i18n in trac.ini</p>
| 1 | 2010-03-20T08:19:59Z | 2,482,486 | <p>The stable release of trac, 0.11.X does not have support for localization. It is added in the upcoming 0.12 which is currently under development. Do you have 0.12 or did you download "latest stable" which is 0.11? In that case you will have to upgrade to get localization support.</p>
<p>The trac site itself appears... | 0 | 2010-03-20T09:14:53Z | [
"python",
"internationalization",
"trac"
] |
Label in PyQt4 GUI not updating with every loop of FOR loop | 2,482,437 | <p>I'm having a problem, where I wish to run several command line functions from a python program using a GUI. I don't know if my problem is specific to <strong>PyQt4</strong> or if it has to do with my bad use of python code. </p>
<p>What I wish to do is have a label on my GUI change its text value to inform the user... | 5 | 2010-03-20T08:45:13Z | 2,482,527 | <p>The label gets updated all right, <em>but the GUI isn't redrawn before the end of your loop.</em></p>
<p>Here's what you can do about it:</p>
<ul>
<li><p>Move your long-running loop to a secondary thread, drawing the GUI is happening in the main thread.</p></li>
<li><p>Call <code>app.processEvents()</code> in your... | 9 | 2010-03-20T09:41:28Z | [
"python",
"for-loop",
"label",
"pyqt4"
] |
Label in PyQt4 GUI not updating with every loop of FOR loop | 2,482,437 | <p>I'm having a problem, where I wish to run several command line functions from a python program using a GUI. I don't know if my problem is specific to <strong>PyQt4</strong> or if it has to do with my bad use of python code. </p>
<p>What I wish to do is have a label on my GUI change its text value to inform the user... | 5 | 2010-03-20T08:45:13Z | 2,482,528 | <p>You have a basic misunderstanding of how such a GUI works. A Qt GUI has to run in an event loop of its own. Your loop runs instead, and the GUI can't do its work between the executions of your loop. That is, while your <code>for</code> loop is running the GUI code doesn't get CPU time and won't update.</p>
<p>You c... | 2 | 2010-03-20T09:41:31Z | [
"python",
"for-loop",
"label",
"pyqt4"
] |
a general tree implementation in python | 2,482,602 | <p>I want to build a general tree whose root node contains 'n' children, and those children may contain other children.....</p>
| 22 | 2010-03-20T10:07:12Z | 2,482,610 | <p>A tree in Python is quite simple. Make a class that has data and a list of children. Each child is an instance of the same class. This is a general n-nary tree.</p>
<pre><code>class Node(object):
def __init__(self, data):
self.data = data
self.children = []
def add_child(self, obj):
... | 86 | 2010-03-20T10:11:15Z | [
"python",
"python-3.x"
] |
a general tree implementation in python | 2,482,602 | <p>I want to build a general tree whose root node contains 'n' children, and those children may contain other children.....</p>
| 22 | 2010-03-20T10:07:12Z | 7,334,634 | <p>I've published a Python [3] tree implementation on my site: <a href="http://www.quesucede.com/page/show/id/python_3_tree_implementation">http://www.quesucede.com/page/show/id/python_3_tree_implementation</a>.</p>
<p>Hope it is of use,</p>
<p>Ok, here's the code:</p>
<pre><code>import uuid
def sanitize_id(id):
... | 9 | 2011-09-07T13:27:07Z | [
"python",
"python-3.x"
] |
a general tree implementation in python | 2,482,602 | <p>I want to build a general tree whose root node contains 'n' children, and those children may contain other children.....</p>
| 22 | 2010-03-20T10:07:12Z | 23,332,885 | <pre><code>node = { 'parent':0, 'left':0, 'right':0 }
import copy
root = copy.deepcopy(node)
root['parent'] = -1
left = copy
</code></pre>
<p>just to show another thought on implementation if you stick to the "OOP"</p>
<pre><code>class Node:
def __init__(self,data):
self.data = data
self.child = {... | 0 | 2014-04-28T05:08:08Z | [
"python",
"python-3.x"
] |
How to check the read/write status of storage media in python? | 2,482,701 | <p>How can i check the read/ write permission of the file storing media? ie assume i have to write some file inside a directory and that directory may be available on read only media like (cd or dvd)or etc. So how can i check that storing media ( cd, hard disk) having a read only or read write both permission.</p>
<p>... | 0 | 2010-03-20T10:48:04Z | 2,482,713 | <p>Use the <code>win32api.GetFileAttributes</code> method.</p>
<p>P.S. also see <a href="http://stackoverflow.com/questions/659847/checking-file-attributes-in-python">this SO question</a></p>
| 0 | 2010-03-20T10:50:25Z | [
"python",
"windows-xp",
"filesystems"
] |
How to check the read/write status of storage media in python? | 2,482,701 | <p>How can i check the read/ write permission of the file storing media? ie assume i have to write some file inside a directory and that directory may be available on read only media like (cd or dvd)or etc. So how can i check that storing media ( cd, hard disk) having a read only or read write both permission.</p>
<p>... | 0 | 2010-03-20T10:48:04Z | 2,482,769 | <p>Use the <a href="http://docs.python.org/library/os.html#os.access" rel="nofollow">os.access(path, mode)</a> function. It should be much more portable than the win32api function. Though, I have no experience with it on non-POSIX systems.</p>
<p>On the other hand, why don't you just try to write the file and handle e... | 3 | 2010-03-20T11:07:07Z | [
"python",
"windows-xp",
"filesystems"
] |
How to check the read/write status of storage media in python? | 2,482,701 | <p>How can i check the read/ write permission of the file storing media? ie assume i have to write some file inside a directory and that directory may be available on read only media like (cd or dvd)or etc. So how can i check that storing media ( cd, hard disk) having a read only or read write both permission.</p>
<p>... | 0 | 2010-03-20T10:48:04Z | 2,482,800 | <pre><code>import os
from stat import *
if S_IMODE(os.stat(dir_name)) & S_IWRITE != 0:
</code></pre>
<p>is more portable, if not necessarily more readable.</p>
| 1 | 2010-03-20T11:19:12Z | [
"python",
"windows-xp",
"filesystems"
] |
How to set the size of a wx.aui.AuiManager Pane that is centered? | 2,482,914 | <p>I have three panes with the InfoPane center option.
I want to know how to set their size.</p>
<p>Using this code:</p>
<pre><code>import wx
import wx.aui
class MyFrame(wx.Frame):
def __init__(self, parent, id=-1, title='wx.aui Test',
pos=wx.DefaultPosition, size=(800, 600),
s... | 2 | 2010-03-20T12:02:37Z | 2,483,744 | <p>I've discovered what I want.
It was the wx.aui.AuiPaneInfo.dock_proportion property :)</p>
| 1 | 2010-03-20T16:08:44Z | [
"python",
"wxpython"
] |
Should I use fork or threads? | 2,482,926 | <p>In my script, I have a <strong>function foo</strong> which basically uses <strong>pynotify</strong> to notify user about something repeatedly after a time interval say 15 minutes. </p>
<pre><code>def foo:
while True:
"""Does something"""
time.sleep(900)
</code></pre>
<p>My main script has to in... | 6 | 2010-03-20T12:07:21Z | 2,482,978 | <p>Processes are much simpler. Just turn them loose and let the OS handle it. </p>
<p>Also, processes are often much more efficient. Processes do not share a common pool of I/O resources; they are completely independent. </p>
<p>Python's <code>subprocess.Popen</code> handles everything.</p>
| 3 | 2010-03-20T12:26:19Z | [
"python",
"coding-style"
] |
Should I use fork or threads? | 2,482,926 | <p>In my script, I have a <strong>function foo</strong> which basically uses <strong>pynotify</strong> to notify user about something repeatedly after a time interval say 15 minutes. </p>
<pre><code>def foo:
while True:
"""Does something"""
time.sleep(900)
</code></pre>
<p>My main script has to in... | 6 | 2010-03-20T12:07:21Z | 2,483,063 | <p>If by fork you mean os.fork then I would avoid using that. It is not cross platform and too low level - you would need to implement communication between the processes yourself.</p>
<p>If you want to use a separate process then use either the subprocess module or if you are on Python 2.6 or later the new <a href="... | 1 | 2010-03-20T12:53:18Z | [
"python",
"coding-style"
] |
Should I use fork or threads? | 2,482,926 | <p>In my script, I have a <strong>function foo</strong> which basically uses <strong>pynotify</strong> to notify user about something repeatedly after a time interval say 15 minutes. </p>
<pre><code>def foo:
while True:
"""Does something"""
time.sleep(900)
</code></pre>
<p>My main script has to in... | 6 | 2010-03-20T12:07:21Z | 2,483,065 | <p>I won't tell you which one to use, but here are some of the advantages of each:</p>
<p><strong>Threads</strong> can start more quickly than processes, and threads use fewer operating system resources than processes, including memory, file handles, etc. Threads also give you the option of communicating through shar... | 7 | 2010-03-20T12:53:38Z | [
"python",
"coding-style"
] |
Should I use fork or threads? | 2,482,926 | <p>In my script, I have a <strong>function foo</strong> which basically uses <strong>pynotify</strong> to notify user about something repeatedly after a time interval say 15 minutes. </p>
<pre><code>def foo:
while True:
"""Does something"""
time.sleep(900)
</code></pre>
<p>My main script has to in... | 6 | 2010-03-20T12:07:21Z | 2,483,475 | <p>For these kinds of problems, neither threads nor forked processes seem the right approach. If all you want to do is to once every 15 minutes notify the user of something, why not use an event loop like GLib's or Twisted's reactor ? This allows you to schedule operations that should run once in a while, and get on w... | 4 | 2010-03-20T14:58:47Z | [
"python",
"coding-style"
] |
Should I use fork or threads? | 2,482,926 | <p>In my script, I have a <strong>function foo</strong> which basically uses <strong>pynotify</strong> to notify user about something repeatedly after a time interval say 15 minutes. </p>
<pre><code>def foo:
while True:
"""Does something"""
time.sleep(900)
</code></pre>
<p>My main script has to in... | 6 | 2010-03-20T12:07:21Z | 2,483,480 | <p>Using multiple processes lets you exploit multiple CPU cores at the same time, while, in CPython, using threads doesn't (threads take turns using a single CPU core) -- so, if you have CPU intensive work and absolutely want to use threads, you should consider Jython or IronPython; with CPython, this consideration is ... | 4 | 2010-03-20T15:00:24Z | [
"python",
"coding-style"
] |
Python method to remove iterability | 2,482,996 | <p>Suppose I have a function which can either take an iterable/iterator or a non-iterable as an argument. Iterability is checked with <code>try: iter(arg)</code>.</p>
<p>Depending whether the input is an iterable or not, the outcome of the method will be different. Not when I want to pass a non-iterable as iterable in... | 5 | 2010-03-20T12:34:19Z | 2,483,003 | <p>Specialize it.</p>
<pre><code>def can_iter(arg):
if isinstance(arg, str):
return False
try:
...
</code></pre>
| 0 | 2010-03-20T12:37:13Z | [
"python",
"string",
"data-structures",
"iterator"
] |
Python method to remove iterability | 2,482,996 | <p>Suppose I have a function which can either take an iterable/iterator or a non-iterable as an argument. Iterability is checked with <code>try: iter(arg)</code>.</p>
<p>Depending whether the input is an iterable or not, the outcome of the method will be different. Not when I want to pass a non-iterable as iterable in... | 5 | 2010-03-20T12:34:19Z | 2,483,051 | <p>Whoo! It appears you want to be able to pass iterables as iterables, iterables as noniterables, noniterables as iterables, and noniterables as noniterables.
Since you want to be able to handle every possibility, and the computer can not (yet) read minds, you are going to have to tell the function how you want the a... | 2 | 2010-03-20T12:50:00Z | [
"python",
"string",
"data-structures",
"iterator"
] |
Python method to remove iterability | 2,482,996 | <p>Suppose I have a function which can either take an iterable/iterator or a non-iterable as an argument. Iterability is checked with <code>try: iter(arg)</code>.</p>
<p>Depending whether the input is an iterable or not, the outcome of the method will be different. Not when I want to pass a non-iterable as iterable in... | 5 | 2010-03-20T12:34:19Z | 2,483,122 | <p>The more I think about it, it seems like itâs not possible to do without type checking or passing argments to the function.</p>
<p>However, depending on the intention of the function, one way to handle it could be:</p>
<pre><code>from itertools import repeat
func(repeat(string_iterable))
</code></pre>
<p><code>... | 3 | 2010-03-20T13:10:36Z | [
"python",
"string",
"data-structures",
"iterator"
] |
Python method to remove iterability | 2,482,996 | <p>Suppose I have a function which can either take an iterable/iterator or a non-iterable as an argument. Iterability is checked with <code>try: iter(arg)</code>.</p>
<p>Depending whether the input is an iterable or not, the outcome of the method will be different. Not when I want to pass a non-iterable as iterable in... | 5 | 2010-03-20T12:34:19Z | 2,483,498 | <p>Well, one approach to tell the function how you would like to treat its arguments is to have sensible defaults (making the function treat everything by its original type by default), while being able to specify any tweaks you like with comfort (i.e. with a short and absent-by-default <code>fmt</code> string), like:<... | 0 | 2010-03-20T15:03:26Z | [
"python",
"string",
"data-structures",
"iterator"
] |
Python method to remove iterability | 2,482,996 | <p>Suppose I have a function which can either take an iterable/iterator or a non-iterable as an argument. Iterability is checked with <code>try: iter(arg)</code>.</p>
<p>Depending whether the input is an iterable or not, the outcome of the method will be different. Not when I want to pass a non-iterable as iterable in... | 5 | 2010-03-20T12:34:19Z | 2,483,649 | <p><strong>Don't check for iterability.</strong> It is a mistake to have a function check things about its elements types/capabilities in order to have a single function perform <em>different</em> tasks. If you want to do two different things, make two different functions.</p>
<p>It sounds like you have come to this c... | 0 | 2010-03-20T15:44:29Z | [
"python",
"string",
"data-structures",
"iterator"
] |
Euclidian Distances between points | 2,483,100 | <p>I have an array of points in numpy:</p>
<pre><code>points = rand(dim, n_points)
</code></pre>
<p>And I want to:</p>
<ol>
<li>Calculate all the l2 norm (euclidian distance) between a certain point and all other points</li>
<li>Calculate all pairwise distances.</li>
</ol>
<p>and preferably all numpy and no for's. ... | 3 | 2010-03-20T13:05:11Z | 2,483,398 | <p>This might help with the second part:</p>
<pre><code>import numpy as np
from numpy import *
p=rand(3,4) # this is column-wise so each vector has length 3
sqrt(sum((p[:,np.newaxis,:]-p[:,:,np.newaxis])**2 ,axis=0) )
</code></pre>
<p>which gives</p>
<pre><code>array([[ 0. , 0.37355868, 0.64896708, 1.14974... | 1 | 2010-03-20T14:33:08Z | [
"python",
"numpy",
"euclidean-distance"
] |
Euclidian Distances between points | 2,483,100 | <p>I have an array of points in numpy:</p>
<pre><code>points = rand(dim, n_points)
</code></pre>
<p>And I want to:</p>
<ol>
<li>Calculate all the l2 norm (euclidian distance) between a certain point and all other points</li>
<li>Calculate all pairwise distances.</li>
</ol>
<p>and preferably all numpy and no for's. ... | 3 | 2010-03-20T13:05:11Z | 2,484,580 | <p>If you're willing to use SciPy, the <code>scipy.spatial.distance</code> module (the functions <code>cdist</code> and/or <code>pdist</code>) do exactly what you want, with all the looping done in C. You can do it with broadcasting too but there's some extra memory overhead.</p>
| 4 | 2010-03-20T20:13:22Z | [
"python",
"numpy",
"euclidean-distance"
] |
How to give extra arguments for the Python itertools.ifilter function? | 2,483,118 | <p>In python I have the following function:</p>
<pre><code>def is_a_nice_element(element, parameter):
#do something
return True or False
</code></pre>
<p>Now I would like to filter a list with this function as predicate, giving a fixed parameter. Python has the itertools.ifilter function, but I can't figure o... | 0 | 2010-03-20T13:09:57Z | 2,483,138 | <p>Wrap it in a <code>lambda</code>:</p>
<pre><code>itertools.ifilter(lambda e: is_a_nice_element(e, 42), iterable)
</code></pre>
<p>42 is your extra argument, or whatever else you want it to be.</p>
| 2 | 2010-03-20T13:17:13Z | [
"python",
"ifilter",
"itertools"
] |
How to give extra arguments for the Python itertools.ifilter function? | 2,483,118 | <p>In python I have the following function:</p>
<pre><code>def is_a_nice_element(element, parameter):
#do something
return True or False
</code></pre>
<p>Now I would like to filter a list with this function as predicate, giving a fixed parameter. Python has the itertools.ifilter function, but I can't figure o... | 0 | 2010-03-20T13:09:57Z | 2,483,149 | <p>If you are using <code>ifilter</code> then parameter would need to be constant in which case you could use a default argument <code>parameter=something</code>. If you want parameter to vary, you'd need to use another method to take a dyadic predicate.</p>
<p>If you already have the list in hand, <code>ifilter</code... | -1 | 2010-03-20T13:20:15Z | [
"python",
"ifilter",
"itertools"
] |
How to give extra arguments for the Python itertools.ifilter function? | 2,483,118 | <p>In python I have the following function:</p>
<pre><code>def is_a_nice_element(element, parameter):
#do something
return True or False
</code></pre>
<p>Now I would like to filter a list with this function as predicate, giving a fixed parameter. Python has the itertools.ifilter function, but I can't figure o... | 0 | 2010-03-20T13:09:57Z | 2,483,407 | <p>I like <a href="http://docs.python.org/library/functools.html#functools.partial" rel="nofollow">functools.partial</a> much better than <code>lambda</code>.</p>
<pre><code>itertools.ifilter( partial(is_a_nice_element, parameter=X), iterable )
</code></pre>
| 3 | 2010-03-20T14:36:23Z | [
"python",
"ifilter",
"itertools"
] |
How to give extra arguments for the Python itertools.ifilter function? | 2,483,118 | <p>In python I have the following function:</p>
<pre><code>def is_a_nice_element(element, parameter):
#do something
return True or False
</code></pre>
<p>Now I would like to filter a list with this function as predicate, giving a fixed parameter. Python has the itertools.ifilter function, but I can't figure o... | 0 | 2010-03-20T13:09:57Z | 2,483,610 | <p>The solutions use <code>lambda</code> and <code>functools.partial</code> are quite correct and directly answer your question, but I don't think they are really the ideal solution.</p>
<p>Using <code>filter</code>/<code>itertools.ifilter</code>/<code>map</code>/<code>itertools.imap</code> with an anonymous function ... | 1 | 2010-03-20T15:34:15Z | [
"python",
"ifilter",
"itertools"
] |
Python development with Emacs? | 2,483,406 | <p>Anybody knows some actual documentation written? I can't find anything good for any of the 2 competing modes. Looks like Emacs is pretty much abandon when it comes to Python and it is a shame as there is no other programmable programming editor that comes close to Emacs.</p>
| 12 | 2010-03-20T14:35:54Z | 2,483,431 | <p>Maybe you looked in the wrong places? Did you try </p>
<ul>
<li><a href="http://www.emacswiki.org/cgi-bin/wiki/PythonMode" rel="nofollow">the Emacs Wiki page for Python modes</a></li>
<li><a href="http://www.emacswiki.org/emacs/PythonProgrammingInEmacs" rel="nofollow">the Python Programming in Emacs page</a></li>
... | 4 | 2010-03-20T14:44:10Z | [
"python",
"emacs"
] |
Python development with Emacs? | 2,483,406 | <p>Anybody knows some actual documentation written? I can't find anything good for any of the 2 competing modes. Looks like Emacs is pretty much abandon when it comes to Python and it is a shame as there is no other programmable programming editor that comes close to Emacs.</p>
| 12 | 2010-03-20T14:35:54Z | 2,483,465 | <p>Justin Lilly presented on <a href="http://us.pycon.org/2010/conference/schedule/event/129/">editors at PyCon 2010</a>. His <a href="http://github.com/justinlilly/jlilly_emacs">config</a> is on GitHub.</p>
| 5 | 2010-03-20T14:54:33Z | [
"python",
"emacs"
] |
Python development with Emacs? | 2,483,406 | <p>Anybody knows some actual documentation written? I can't find anything good for any of the 2 competing modes. Looks like Emacs is pretty much abandon when it comes to Python and it is a shame as there is no other programmable programming editor that comes close to Emacs.</p>
| 12 | 2010-03-20T14:35:54Z | 2,483,466 | <p>This blog recently had a 2 part series that I found very helpful. <a href="http://jesselegg.com/archives/2010/02/25/emacs-python-programmers-part-1/" rel="nofollow">Part 1</a> <a href="http://jesselegg.com/archives/2010/03/14/emacs-python-programmers-2-virtualenv-ipython-daemon-mode/" rel="nofollow">Part 2</a></p>
... | 7 | 2010-03-20T14:54:54Z | [
"python",
"emacs"
] |
Python development with Emacs? | 2,483,406 | <p>Anybody knows some actual documentation written? I can't find anything good for any of the 2 competing modes. Looks like Emacs is pretty much abandon when it comes to Python and it is a shame as there is no other programmable programming editor that comes close to Emacs.</p>
| 12 | 2010-03-20T14:35:54Z | 2,541,204 | <p>I started off doing Python development using the setup documented at <a href="http://www.enigmacurry.com/2009/01/21/autocompleteel-python-code-completion-in-emacs/" rel="nofollow">Ryan McGuire's tab completion page</a> and sort of branched out from there. Right now, I have extensively extended and patched that setu... | 2 | 2010-03-29T20:53:31Z | [
"python",
"emacs"
] |
Python - retrieving info from a syslog file | 2,483,421 | <p>I have been asked to write a program using python for an assignment.</p>
<p>I have been given a syslog file and I have to find things out about it</p>
<p>How do I find out how many attempts were made to login to the root account?</p>
<p>Any advice would be highly appreciated as I am very new to python and complet... | 1 | 2010-03-20T14:40:38Z | 2,483,438 | <p>You probably need to read the file, parsing each line. When you find a line that matches what you're interested in (failed root login, for example), you increment a counter.</p>
<p>Take a look at <a href="http://docs.python.org/release/2.5.2/tut/node9.html" rel="nofollow">how to read files</a> and possibly <a href=... | 0 | 2010-03-20T14:46:19Z | [
"python",
"login",
"count",
"syslog"
] |
Python - retrieving info from a syslog file | 2,483,421 | <p>I have been asked to write a program using python for an assignment.</p>
<p>I have been given a syslog file and I have to find things out about it</p>
<p>How do I find out how many attempts were made to login to the root account?</p>
<p>Any advice would be highly appreciated as I am very new to python and complet... | 1 | 2010-03-20T14:40:38Z | 2,483,469 | <p>You want <code>/var/log/auth.log</code>, not syslog. </p>
<p>It'll contain lines like like this: </p>
<pre><code>Mar 20 10:47:24 Opus su[15918]: pam_unix(su:auth): authentication failure; logname=lfaraone uid=1000 euid=0 tty=/dev/pts/25 ruser=lfaraone rhost= user=root
</code></pre>
<p>Basic, naive code to accomp... | 1 | 2010-03-20T14:55:47Z | [
"python",
"login",
"count",
"syslog"
] |
Python - retrieving info from a syslog file | 2,483,421 | <p>I have been asked to write a program using python for an assignment.</p>
<p>I have been given a syslog file and I have to find things out about it</p>
<p>How do I find out how many attempts were made to login to the root account?</p>
<p>Any advice would be highly appreciated as I am very new to python and complet... | 1 | 2010-03-20T14:40:38Z | 2,483,472 | <p>something like this</p>
<pre><code>#open the file , can be /var/log/messages, /var/log/maillog etc as defined in your system
f=open("mysyslogfile")
count=0
#go through the file
for line in f:
if "<unique pattern for checking root account login>" in line:
count+=1
#close the file
f.close()
print "to... | 0 | 2010-03-20T14:57:05Z | [
"python",
"login",
"count",
"syslog"
] |
MySQL UTC Date format | 2,483,569 | <p>I am pulling data from Twitter's API and the return date is UTC in the following form:</p>
<blockquote>
<p>Sat Jan 24 22:14:29 +0000 2009</p>
</blockquote>
<p>Can MySQL handle this format specifically or do I need to transform it? I am pulling the data using Python.</p>
| 1 | 2010-03-20T15:21:50Z | 2,483,584 | <p>Yes, if you are not willing to transform it in Python, MySQL can handle this with the <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date" rel="nofollow"><code>STR_TO_DATE()</code></a> function, as in the following example:</p>
<pre><code>INSERT INTO
your_table
VALU... | 3 | 2010-03-20T15:27:33Z | [
"python",
"mysql",
"twitter",
"utc"
] |
undo or reverse argsort(), python | 2,483,696 | <p>Given an array 'a' I would like to sort the array by columns "sort(a, axis=0)" do some stuff to the array and then undo the sort. By that I don't mean re sort but basically reversing how each element was moved. I assume argsort() is what I need but it is not clear to me how to sort an array with the results of argso... | 8 | 2010-03-20T15:55:37Z | 2,483,748 | <p>I'm not sure how best to do it in <code>numpy</code>, but, in pure Python, the reasoning would be:</p>
<p><code>aargsort</code> is holding a permutation of <code>range(len(a))</code> telling you where the items of <code>aSort</code> came from -- much like, in pure Python:</p>
<pre><code>>>> x = list('ciao... | 3 | 2010-03-20T16:10:04Z | [
"python",
"arrays",
"sorting",
"numpy"
] |
undo or reverse argsort(), python | 2,483,696 | <p>Given an array 'a' I would like to sort the array by columns "sort(a, axis=0)" do some stuff to the array and then undo the sort. By that I don't mean re sort but basically reversing how each element was moved. I assume argsort() is what I need but it is not clear to me how to sort an array with the results of argso... | 8 | 2010-03-20T15:55:37Z | 2,483,797 | <p>I was not able to follow your example, but the more abstract problem--i.e., how to sort an array then reverse the sort--is straightforward.</p>
<pre><code>import numpy as NP
# create an 10x6 array to work with
A = NP.random.randint(10, 99, 60).reshape(10, 6)
# for example, sort this array on the second-to-last colu... | 1 | 2010-03-20T16:24:28Z | [
"python",
"arrays",
"sorting",
"numpy"
] |
undo or reverse argsort(), python | 2,483,696 | <p>Given an array 'a' I would like to sort the array by columns "sort(a, axis=0)" do some stuff to the array and then undo the sort. By that I don't mean re sort but basically reversing how each element was moved. I assume argsort() is what I need but it is not clear to me how to sort an array with the results of argso... | 8 | 2010-03-20T15:55:37Z | 2,497,565 | <p>There are probably better solutions to the problem you are actually trying to solve than this (performing an argsort usually precludes the need to actually sort), but here you go:</p>
<pre><code>>>> import numpy as np
>>> a = np.random.randint(0,10,10)
>>> aa = np.argsort(a)
>>> ... | 18 | 2010-03-23T04:25:00Z | [
"python",
"arrays",
"sorting",
"numpy"
] |
undo or reverse argsort(), python | 2,483,696 | <p>Given an array 'a' I would like to sort the array by columns "sort(a, axis=0)" do some stuff to the array and then undo the sort. By that I don't mean re sort but basically reversing how each element was moved. I assume argsort() is what I need but it is not clear to me how to sort an array with the results of argso... | 8 | 2010-03-20T15:55:37Z | 10,831,155 | <p>For all those still looking for an answer:</p>
<pre><code>In [135]: r = rand(10)
In [136]: i = argsort(r)
In [137]: r_sorted = r[i]
In [138]: i_rev = zeros(10, dtype=int)
In [139]: i_rev[i] = arange(10)
In [140]: allclose(r, r_sorted[i_rev])
Out[140]: True
</code></pre>
| 5 | 2012-05-31T09:45:40Z | [
"python",
"arrays",
"sorting",
"numpy"
] |
Python: Does one of these examples waste more memory? | 2,483,761 | <p>In a Django view function which uses manual transaction committing, I have:</p>
<pre><code>context = RequestContext(request, data)
transaction.commit()
return render_to_response('basic.html', data, context) # Returns a Django ``HttpResponse`` object which is similar to a dictionary.
</code></pre>
<p>I think it is... | 0 | 2010-03-20T16:14:12Z | 2,483,774 | <p>You say, "there won't likely be many exceptions at that point in the function". This may not be true. Keep in mind that querysets are lazily fetched from the db, so in fact, a lot of your db activity could be inside the <code>render_to_response</code> call. </p>
<p>I'd use the second style. It's more correct in... | 3 | 2010-03-20T16:17:40Z | [
"python",
"django",
"memory-management"
] |
Python - Filter by Date | 2,483,822 | <p>How do I count how many logins were done per day on a system using the log file in Python?</p>
| -4 | 2010-03-20T16:32:04Z | 2,483,841 | <p>You don't need Python, the shell will do:</p>
<pre><code>grep "Login succeeded_or_whatever_the_log_says" logfile | wc -l
</code></pre>
<p>If you really insist on using Python, try</p>
<pre><code>print(sum(
1 for line in open('logfile')
if 'Login succeeded_or_whatever_the_log_says' in line))
</code... | 1 | 2010-03-20T16:41:20Z | [
"python",
"login"
] |
Python - Filter by Date | 2,483,822 | <p>How do I count how many logins were done per day on a system using the log file in Python?</p>
| -4 | 2010-03-20T16:32:04Z | 2,483,865 | <p>You can create dictionary with day as a key, and login count as a value.
Then read file line by line, extract date from each line and increase login count for that day.</p>
<p>I think something like this should work:</p>
<pre><code>login_cnts = {}
def get_date(line):
"""extract date from line, in this example... | -1 | 2010-03-20T16:48:42Z | [
"python",
"login"
] |
Python: Script works, but seems to deadlock after some time | 2,483,840 | <p>I have the following script, which is working for the most part <a href="http://pastebin.com/cs5VtPhC" rel="nofollow">Link to PasteBin</a> The script's job is to start a number of threads which in turn each start a subprocess with Popen. The output from each subprocess is as follows:</p>
<pre><code>1
2
3
.
.
.
n
... | 0 | 2010-03-20T16:41:18Z | 2,486,385 | <p>You have a few places in your script where you return without releasing your locks. This could cause a problem - lines: 97 and 99 - this is where try: finally: blocks can help you a lot as you can then ensure that the release is called properly.</p>
| 0 | 2010-03-21T08:14:23Z | [
"python",
"multithreading",
"subprocess",
"signals"
] |
Which dynamic language can easily use libraries from other languages? | 2,483,924 | <p>Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.</p>
<p>To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.</p>
<p>In other words, which language "just works" with ... | 1 | 2010-03-20T17:06:57Z | 2,483,932 | <p>all 3 languages have very good, clear facilities for just calling any executable in a subprocess (including executables like <code>python somethingelse.py</code> or <code>ruby somethingelse.rb</code>).</p>
<p>use what you know best.</p>
| 0 | 2010-03-20T17:10:26Z | [
"python",
"ruby",
"perl",
"module",
"dynamic-languages"
] |
Which dynamic language can easily use libraries from other languages? | 2,483,924 | <p>Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.</p>
<p>To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.</p>
<p>In other words, which language "just works" with ... | 1 | 2010-03-20T17:06:57Z | 2,483,934 | <p>The <a href="http://www.parrot.org/" rel="nofollow">Parrot VM</a> looks like the way to go for this purpose, since</p>
<blockquote>
<p>Parrot currently hosts a variety of
language implementations in various
stages of completion, including Tcl,
Javascript, Ruby, Lua, Scheme, PHP,
Python, Perl 6, APL, and a... | 6 | 2010-03-20T17:10:36Z | [
"python",
"ruby",
"perl",
"module",
"dynamic-languages"
] |
Which dynamic language can easily use libraries from other languages? | 2,483,924 | <p>Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.</p>
<p>To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.</p>
<p>In other words, which language "just works" with ... | 1 | 2010-03-20T17:06:57Z | 2,483,959 | <p>If you want to plug in a Perl module, the language which is best suited for this is Perl. Perl is able to represent the semantics and capabilities of code written in Perl correctly. This really shouldn't be a shock.</p>
<p>If you have a self-contained program you want to call from another program in its own process... | 3 | 2010-03-20T17:15:35Z | [
"python",
"ruby",
"perl",
"module",
"dynamic-languages"
] |
Which dynamic language can easily use libraries from other languages? | 2,483,924 | <p>Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.</p>
<p>To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.</p>
<p>In other words, which language "just works" with ... | 1 | 2010-03-20T17:06:57Z | 2,483,990 | <p>I'm going to answer on a more architectural level here. The question is what are you trying to do... do you want to write your business logic in Python and call a Perl function from Python? Or are you looking to execute a script? If so, how will the two communicate?</p>
<p>I suspect, but don't know, that Parrot VM ... | 0 | 2010-03-20T17:23:08Z | [
"python",
"ruby",
"perl",
"module",
"dynamic-languages"
] |
Which dynamic language can easily use libraries from other languages? | 2,483,924 | <p>Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.</p>
<p>To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.</p>
<p>In other words, which language "just works" with ... | 1 | 2010-03-20T17:06:57Z | 2,483,997 | <p>The Dynamic Language Runtime was specifically designed to allow one dynamic language to use objects and functions defined in another dynamic language. Currently Python and Ruby have DLR implementations, but I haven't heard anything about Perl.</p>
<p>To use the DLR you need either .NET or Mono.</p>
| 0 | 2010-03-20T17:24:26Z | [
"python",
"ruby",
"perl",
"module",
"dynamic-languages"
] |
Which dynamic language can easily use libraries from other languages? | 2,483,924 | <p>Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.</p>
<p>To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.</p>
<p>In other words, which language "just works" with ... | 1 | 2010-03-20T17:06:57Z | 2,483,999 | <p>Perl has very good support for other languages via the <a href="http://search.cpan.org/perldoc?Inline" rel="nofollow">Inline</a> set of modules.</p>
<p><a href="http://search.cpan.org/perldoc?Inline%3a%3aPython" rel="nofollow">Inline::Python</a> allows you to import Python modules, classes and functions into your P... | 9 | 2010-03-20T17:25:22Z | [
"python",
"ruby",
"perl",
"module",
"dynamic-languages"
] |
Which dynamic language can easily use libraries from other languages? | 2,483,924 | <p>Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.</p>
<p>To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.</p>
<p>In other words, which language "just works" with ... | 1 | 2010-03-20T17:06:57Z | 2,484,750 | <p>Most scripting languages can handle this kind of thing (by running external programs written in other languages,) but it seems as if your best bet might be shell scripting of some kind (Windows users call this "batch scripting," but the DOS syntax is horrible and not recommended.) UNIX programmers have been freely m... | 0 | 2010-03-20T20:58:03Z | [
"python",
"ruby",
"perl",
"module",
"dynamic-languages"
] |
How can I access the "through" object of a Django ManyToManyField? | 2,483,948 | <p>I have the following models in my Django app. How can I from the <code>Team</code> model find all the <code>User</code> objects who have accepted as True in the Membership model? I know I need to use <code>Team.objects.filter()</code>, but I'm not sure how to check the value of the <code>accepted</code> field.</p>
... | 0 | 2010-03-20T17:13:15Z | 2,483,971 | <p><code>Team.objects.filter(members__accepted__exact=True)</code></p>
<p>Take a look at <a href="http://www.djangoproject.com/documentation/models/many_to_many/" rel="nofollow">this</a>. It has a lot of great examples and explanations.</p>
| -1 | 2010-03-20T17:18:07Z | [
"python",
"django"
] |
How can I access the "through" object of a Django ManyToManyField? | 2,483,948 | <p>I have the following models in my Django app. How can I from the <code>Team</code> model find all the <code>User</code> objects who have accepted as True in the Membership model? I know I need to use <code>Team.objects.filter()</code>, but I'm not sure how to check the value of the <code>accepted</code> field.</p>
... | 0 | 2010-03-20T17:13:15Z | 2,484,618 | <p>Accepted members of a team:</p>
<pre><code>team_42.members.filter(membership__accepted=True)
</code></pre>
<p>Teams user <code>alice</code> has been accepted by:</p>
<pre><code>alice.team_set.filter(membership__accepted=True)
</code></pre>
<p>I believe you want to get the set of Team or User objects and not the ... | 1 | 2010-03-20T20:20:05Z | [
"python",
"django"
] |
Which implementation of OrderedDict should be used in python2.6? | 2,484,046 | <p>As some of you may know in python2.7/3.2 we'll get OrderedDict with <a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">PEP372</a> however one of the reason the PEP existed was because everyone did their own implementation and they were all sightly incompatible. </p>
<p>So which one of the 8 current i... | 6 | 2010-03-20T17:39:23Z | 2,485,457 | <p><a href="http://pypi.python.org/pypi/ordereddict/1.1" rel="nofollow">This package</a> (for Python 2.4 or better) claims to be "A drop-in substitute for Py2.7's new collections.OrderedDict that works in Python 2.4-2.6.", but I have not checked that claim.</p>
| 3 | 2010-03-21T01:17:35Z | [
"python",
"dictionary",
"pep"
] |
Looping an executable to get the result from Python script | 2,484,049 | <p>In my python script, I need to call within a for loop an executable, and waiting for that executable to write the result on the "output.xml".</p>
<p>How do I manage to use wait() & how do I know when one of my executable is finished generating the result to get the result? How do I close that process and open a... | 1 | 2010-03-20T17:39:42Z | 2,484,060 | <p><a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.wait" rel="nofollow"><code>Popen.wait()</code></a> will make the script wait until the process ends. There's no need to kill the process afterwards, since it will have already exited.</p>
| 1 | 2010-03-20T17:43:07Z | [
"python",
"linux",
"executable",
"system-calls"
] |
Looping an executable to get the result from Python script | 2,484,049 | <p>In my python script, I need to call within a for loop an executable, and waiting for that executable to write the result on the "output.xml".</p>
<p>How do I manage to use wait() & how do I know when one of my executable is finished generating the result to get the result? How do I close that process and open a... | 1 | 2010-03-20T17:39:42Z | 2,510,736 | <p>I think the easiest way to do is using <code>call</code>:</p>
<pre><code>import subprocess
retcode = subprocess.call('command', shell=True)
</code></pre>
<p>It waits for the process to terminate and assign the return code to the variable.
For more detailed description see <a href="http://docs.python.org/library/su... | 1 | 2010-03-24T19:16:38Z | [
"python",
"linux",
"executable",
"system-calls"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,484,179 | <p>That's what <a href="http://www.google.com/codesearch/p?hl=ja#Y-66DYr1B_Q/django/utils/html.py&q=lang%3apy%20escape%20django&sa=N&cd=1&ct=rc&l=30">Django does</a>:</p>
<pre><code>def escape(html):
"""Returns the given HTML with ampersands, quotes and carets encoded."""
return mark_safe(f... | 7 | 2010-03-20T18:16:07Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,484,183 | <p>Apparently it's pretty common to implement that via regex. You can find an example of this at <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330" rel="nofollow">ASPN</a> and <a href="http://rc98.net/multiple_replace" rel="nofollow">here</a>.</p>
| 3 | 2010-03-20T18:17:13Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,484,247 | <p>I prefer something clean like:</p>
<pre><code>substitutions = [
('<', '&lt;'),
('>', '&gt;'),
...]
for search, replacement in substitutions:
string = string.replace(search, replacement)
</code></pre>
| 9 | 2010-03-20T18:40:44Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,484,331 | <p>In accordance with bebraw's suggestion, here is what I ended up using (in a separate module, of course):</p>
<pre><code>import re
class Subs(object):
"""
A container holding strings to be searched for and replaced in
replace_multi().
Holds little relation to the sandwich.
"""
def __init__(... | 4 | 2010-03-20T19:04:13Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,484,369 | <p>Do you have an application that is running too slow and you profiled it to find that a line like this snippet is causing it to be slow? Bottlenecks occur at unexpected places.</p>
<p>The current snippet traverses the string 5 times, doing one thing each time. You are suggesting traversing it once, probably doing do... | 18 | 2010-03-20T19:17:05Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,484,405 | <p>You can use reduce:</p>
<pre><code>reduce(lambda s,r: s.replace(*r),
[('&', '&amp;'),
('<', '&lt;'),
('>', '&gt;'),
("'", '&#39;'),
('"', '&quot;')],
string)
</code></pre>
| 3 | 2010-03-20T19:29:22Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,484,483 | <p>How about we just test various ways of doing this and see which comes out faster (assuming we are only caring about the fastest way to do it).</p>
<pre><code>def escape1(input):
return input.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace("'", '&#39;').repla... | 14 | 2010-03-20T19:50:11Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,487,614 | <p>If you work with non-Unicode strings and Python < 3.0, try an alternate <code>translate</code> method:</p>
<pre><code># Python < 3.0
import itertools
def escape(a_string):
replacer= dict( (chr(c),chr(c)) for c in xrange(256))
replacer.update(
{'&': '&amp;',
'<': '&lt;'... | 1 | 2010-03-21T15:39:04Z | [
"python",
"performance",
"replace",
"idioms"
] |
Is str.replace(..).replace(..) ad nauseam a standard idiom in Python? | 2,484,156 | <p>For instance, say I wanted a function to escape a string for use in HTML (as in Django's <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape">escape filter</a>):</p>
<pre><code> def escape(string):
"""
Returns the given string with ampersands, quotes and angle
br... | 28 | 2010-03-20T18:11:12Z | 2,884,062 | <p>ok so i sat down and did the math. pls do not get mad at me i answer specifically discussing ΤÎΩΤÎÎÎÎ¥âs solution, but this would be somewhat hard to shoehorn inside a comment, so let me do it this way. i will, in fact, also air some considerations that are relevant to the OPâs question. </p>
<p>first up... | 1 | 2010-05-21T17:11:36Z | [
"python",
"performance",
"replace",
"idioms"
] |
How do I override a parent class's functions in python? | 2,484,215 | <p>I have a private method <code>def __pickSide(self):</code> in a parent class that I would like to override in the child class. However, the child class still calls the inherited <code>def __pickSide(self):</code>. How can I override the function? The child class's function name is exactly the same as the parent's fu... | 10 | 2010-03-20T18:30:38Z | 2,484,252 | <p>The problem you're seeing is that the double underscores mangle the function name even in calls. This prevents polymorphism from working properly since the name it is mangled to is based on the name of the class the method is defined in, and not the name of the class of the object that is being referenced. Replacing... | 5 | 2010-03-20T18:42:04Z | [
"python",
"inheritance",
"override",
"parent"
] |
How do I override a parent class's functions in python? | 2,484,215 | <p>I have a private method <code>def __pickSide(self):</code> in a parent class that I would like to override in the child class. However, the child class still calls the inherited <code>def __pickSide(self):</code>. How can I override the function? The child class's function name is exactly the same as the parent's fu... | 10 | 2010-03-20T18:30:38Z | 2,484,291 | <p>Let's look at the easiest example:</p>
<pre><code>from dis import dis
class A(object):
def __pick(self):
print "1"
def doitinA(self):
self.__pick()
class B(A):
def __pick(self):
print "2"
def doitinB(self):
self.__pick()
b = B()
b.doitinA() # prints 1
b.doitinB() # prints 2
dis... | 32 | 2010-03-20T18:52:14Z | [
"python",
"inheritance",
"override",
"parent"
] |
How do I override a parent class's functions in python? | 2,484,215 | <p>I have a private method <code>def __pickSide(self):</code> in a parent class that I would like to override in the child class. However, the child class still calls the inherited <code>def __pickSide(self):</code>. How can I override the function? The child class's function name is exactly the same as the parent's fu... | 10 | 2010-03-20T18:30:38Z | 2,484,303 | <ul>
<li><p>Using <code>__foo</code> names mangles the name of the method to make it more hassle to access it when you need to. I would recommend never using them, which makes things like testing go more smoothly.</p></li>
<li><p>There is no private in Python, and if there was, it would prevent you from doing this anyh... | 3 | 2010-03-20T18:55:29Z | [
"python",
"inheritance",
"override",
"parent"
] |
PyLab - changing text color and background fill color of text box | 2,484,256 | <p>Hey all,
I'm using PyLab to make some graphs in Python. I want to make a text box that is colored magenta with black text, but cannot get the text to be black.</p>
<pre><code>text(x, y, 'Summary', backgroundcolor = 'm', color = 'k')
</code></pre>
<p>This gives me a magenta background and then text that is almost j... | 3 | 2010-03-20T18:43:32Z | 2,484,338 | <p>it doesn't appear as though you're doing anything wrong:</p>
<pre><code>In [23]: pylab.text(0.25, 0.5, 'test', backgroundcolor='m', color='r')
In [24]: pylab.text(0.5, 0.5, 'test', backgroundcolor='m', color='k')
In [25]: pylab.text(0.75, 0.5, 'test', backgroundcolor='m', color='b')
</code></pre>
<p><img src="http... | 4 | 2010-03-20T19:06:11Z | [
"python",
"matplotlib"
] |
Prevent python from printing newline | 2,484,420 | <p>I have this code in Python</p>
<pre><code>inputted = input("Enter in something: ")
print("Input is {0}, including the return".format(inputted))
</code></pre>
<p>that outputs</p>
<pre><code>Enter in something: something
Input is something
, including the return
</code></pre>
<p>I am not sure what is happening; if... | 3 | 2010-03-20T19:33:46Z | 2,484,426 | <p>You are correct - a newline is included in <code>inputted</code>. To remove it, you can just call <code>strip("\r\n")</code> to remove the newline from the end:</p>
<pre><code>print("Input is {0}, including the return".format(inputted.strip("\r\n")))
</code></pre>
<p>This won't cause any issues if <code>inputted</... | 7 | 2010-03-20T19:35:42Z | [
"python",
"input",
"newline",
"user-input"
] |
Prevent python from printing newline | 2,484,420 | <p>I have this code in Python</p>
<pre><code>inputted = input("Enter in something: ")
print("Input is {0}, including the return".format(inputted))
</code></pre>
<p>that outputs</p>
<pre><code>Enter in something: something
Input is something
, including the return
</code></pre>
<p>I am not sure what is happening; if... | 3 | 2010-03-20T19:33:46Z | 2,484,427 | <pre><code>inputted = inputted.strip()
</code></pre>
<p><strong>Edit:</strong> As noted, this will kill <em>all</em> whitespace at the start and end. A way to get rid of only the trailing newline is:</p>
<pre><code>import re
inputted = re.sub("[\n\r]+$", "", inputted)
</code></pre>
| 2 | 2010-03-20T19:35:47Z | [
"python",
"input",
"newline",
"user-input"
] |
Prevent python from printing newline | 2,484,420 | <p>I have this code in Python</p>
<pre><code>inputted = input("Enter in something: ")
print("Input is {0}, including the return".format(inputted))
</code></pre>
<p>that outputs</p>
<pre><code>Enter in something: something
Input is something
, including the return
</code></pre>
<p>I am not sure what is happening; if... | 3 | 2010-03-20T19:33:46Z | 2,484,542 | <p>If you only want to stript the last line endings, you could use rstrip.<br>
<code>
inputted.rstrip ("\r\n")
</code></p>
| 3 | 2010-03-20T20:03:04Z | [
"python",
"input",
"newline",
"user-input"
] |
Prevent python from printing newline | 2,484,420 | <p>I have this code in Python</p>
<pre><code>inputted = input("Enter in something: ")
print("Input is {0}, including the return".format(inputted))
</code></pre>
<p>that outputs</p>
<pre><code>Enter in something: something
Input is something
, including the return
</code></pre>
<p>I am not sure what is happening; if... | 3 | 2010-03-20T19:33:46Z | 2,484,666 | <p>Your problem is actually Eclipse. Assuming that you use PyDev, I was able to reproduce the problem. When entering something in the Eclipse console, the problem occurs as described in your question. But when directly executing the very same script with the Python 3.1.1 interpreter, <code>inputted</code> does not incl... | 4 | 2010-03-20T20:31:19Z | [
"python",
"input",
"newline",
"user-input"
] |
How to optimize my PageRank calculation? | 2,484,445 | <p>In the book <a href="http://books.google.de/books?id=fEsZ3Ey-Hq4C&printsec=frontcover&dq=collective+intelligence&source=bl&ots=Sc_9UQFUBa&sig=UXsxcNJR6no436OZOBL4BwFuGrg&hl=de&ei=hxmlS_WqFNKtsAaWz7StCA&sa=X&oi=book_result&ct=result&resnum=3&ved=0CBsQ6AEwAg#v=onepage&am... | 3 | 2010-03-20T19:41:13Z | 2,485,421 | <p>Do you have enough RAM to hold the sparse matrix <code>(fromid, toid)</code> in some form? That would allow big optimizations (with big algorithmic changes). At least, caching in memory the <code>(fromid, numlinks)</code> that you now do with a <code>select count(*)</code> in your innermost loop should help (I'd i... | 0 | 2010-03-21T01:06:48Z | [
"python",
"sql",
"optimization",
"pagerank"
] |
How to optimize my PageRank calculation? | 2,484,445 | <p>In the book <a href="http://books.google.de/books?id=fEsZ3Ey-Hq4C&printsec=frontcover&dq=collective+intelligence&source=bl&ots=Sc_9UQFUBa&sig=UXsxcNJR6no436OZOBL4BwFuGrg&hl=de&ei=hxmlS_WqFNKtsAaWz7StCA&sa=X&oi=book_result&ct=result&resnum=3&ved=0CBsQ6AEwAg#v=onepage&am... | 3 | 2010-03-20T19:41:13Z | 2,485,468 | <p>If you have a very large database (e.g. # records ~ # pages in the WWW) using the database in a manner similar to what's suggested in the book makes sense, because you're not going to be able to keep all that data in memory.</p>
<p>If your dataset is small enough, you can (probably) improve your second version by n... | 2 | 2010-03-21T01:23:30Z | [
"python",
"sql",
"optimization",
"pagerank"
] |
How to optimize my PageRank calculation? | 2,484,445 | <p>In the book <a href="http://books.google.de/books?id=fEsZ3Ey-Hq4C&printsec=frontcover&dq=collective+intelligence&source=bl&ots=Sc_9UQFUBa&sig=UXsxcNJR6no436OZOBL4BwFuGrg&hl=de&ei=hxmlS_WqFNKtsAaWz7StCA&sa=X&oi=book_result&ct=result&resnum=3&ved=0CBsQ6AEwAg#v=onepage&am... | 3 | 2010-03-20T19:41:13Z | 2,485,475 | <p>I believe the majority of the time is being spent on these SQL queries:</p>
<pre><code>for (urlid,) in self.con.execute("select rowid from urllist"):
...
for (inlink,) in self.con.execute("select distinct fromid from link where toid=%d" % urlid):
...
numoutlinks[urlid]=self.con.execute("sele... | 1 | 2010-03-21T01:27:03Z | [
"python",
"sql",
"optimization",
"pagerank"
] |
How to optimize my PageRank calculation? | 2,484,445 | <p>In the book <a href="http://books.google.de/books?id=fEsZ3Ey-Hq4C&printsec=frontcover&dq=collective+intelligence&source=bl&ots=Sc_9UQFUBa&sig=UXsxcNJR6no436OZOBL4BwFuGrg&hl=de&ei=hxmlS_WqFNKtsAaWz7StCA&sa=X&oi=book_result&ct=result&resnum=3&ved=0CBsQ6AEwAg#v=onepage&am... | 3 | 2010-03-20T19:41:13Z | 2,511,880 | <p>I'm answering my own question, since in the end it came out that a mixture of all answers worked best for me:</p>
<pre><code> def calculatepagerank4(self,iterations=20):
# clear out the current PageRank tables
self.con.execute("drop table if exists pagerank")
self.con.execute("create table pagerank(u... | 0 | 2010-03-24T22:25:33Z | [
"python",
"sql",
"optimization",
"pagerank"
] |
How to display a QGraphicsScene? | 2,484,461 | <p>I've got the following code and I'm not sure how to add the QGraphicsScene to my layout..</p>
<pre><code>class MainForm(QDialog):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.scene = QGraphicsScene(self)
self.scene.setSceneRect(0, 0, 500, 500)
self... | 0 | 2010-03-20T19:45:06Z | 2,485,757 | <p>You have added a scene to view, and it's enough. But you should add the view to your MainForm and Layout. View is a kind of widget that can be displayed by your application, while scene is not a widget and cannot be added to layout, it's a component of view. In addition, you may need to add some graphics items(e.g. ... | 0 | 2010-03-21T03:12:27Z | [
"python",
"qt",
"pyqt"
] |
How to display a QGraphicsScene? | 2,484,461 | <p>I've got the following code and I'm not sure how to add the QGraphicsScene to my layout..</p>
<pre><code>class MainForm(QDialog):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.scene = QGraphicsScene(self)
self.scene.setSceneRect(0, 0, 500, 500)
self... | 0 | 2010-03-20T19:45:06Z | 2,486,576 | <p>You'll have to do something like this:</p>
<pre><code>...
layout = QVBoxLayout()
layout.addWidget(zoomSlider)
layout.addWidget(view)
self.setLayout(layout)
...
</code></pre>
| 2 | 2010-03-21T09:45:24Z | [
"python",
"qt",
"pyqt"
] |
Is it possible to plot implicit equations using Matplotlib? | 2,484,527 | <p>I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?</p>
| 16 | 2010-03-20T20:00:30Z | 2,484,594 | <p>I don't believe there's very good support for this, but you could try something like</p>
<pre><code>import matplotlib.pyplot
from numpy import arange
from numpy import meshgrid
delta = 0.025
xrange = arange(-5.0, 20.0, delta)
yrange = arange(-5.0, 20.0, delta)
X, Y = meshgrid(xrange,yrange)
# F is one side of the... | 16 | 2010-03-20T20:16:52Z | [
"python",
"matplotlib",
"equation",
"implicit",
"sympy"
] |
Is it possible to plot implicit equations using Matplotlib? | 2,484,527 | <p>I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?</p>
| 16 | 2010-03-20T20:00:30Z | 2,484,602 | <p>matplotlib does not plot equations; it plots serieses of points. You can use a tool like <code>scipyâ.optimize</code> to numerically calculate y points from x values (or vice versa) of implicit equations numerically or any number of other tools as appropriate.</p>
<hr>
<p>For example, here is an example where I ... | 6 | 2010-03-20T20:17:33Z | [
"python",
"matplotlib",
"equation",
"implicit",
"sympy"
] |
Is it possible to plot implicit equations using Matplotlib? | 2,484,527 | <p>I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?</p>
| 16 | 2010-03-20T20:00:30Z | 2,485,231 | <p>If you're willing to use something other than matplotlib (but still python), there's sage:</p>
<p>An example: <a href="http://sagenb.org/home/pub/1806" rel="nofollow">http://sagenb.org/home/pub/1806</a></p>
<p><a href="http://www.sagemath.org/doc/reference/sage/plot/contour_plot.html#sage.plot.contour_plot.implici... | 2 | 2010-03-20T23:48:53Z | [
"python",
"matplotlib",
"equation",
"implicit",
"sympy"
] |
Is it possible to plot implicit equations using Matplotlib? | 2,484,527 | <p>I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?</p>
| 16 | 2010-03-20T20:00:30Z | 2,486,980 | <p>Many thanks Steve, Mike, Alex. I have gone along with Steve's solution (please see code below). My only remaining issue is that the contour plot appears behind my gridlines, as opposed to a regular plot, which I can force to the front with zorder. Any more halp greatly appreciated.</p>
<p>Cheers,
Geddes</p>
<pre><... | 1 | 2010-03-21T12:04:56Z | [
"python",
"matplotlib",
"equation",
"implicit",
"sympy"
] |
Is it possible to plot implicit equations using Matplotlib? | 2,484,527 | <p>I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?</p>
| 16 | 2010-03-20T20:00:30Z | 2,492,042 | <p>Since you've tagged this question with sympy, I will give such an example.</p>
<p>From the documentation: <a href="http://docs.sympy.org/modules/plotting.html">http://docs.sympy.org/modules/plotting.html</a>.</p>
<pre><code>from sympy import var, Plot
var('x y')
Plot(x*y**3 - y*x**3)
</code></pre>
| 11 | 2010-03-22T12:10:15Z | [
"python",
"matplotlib",
"equation",
"implicit",
"sympy"
] |
Is it possible to plot implicit equations using Matplotlib? | 2,484,527 | <p>I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?</p>
| 16 | 2010-03-20T20:00:30Z | 11,197,791 | <p>There is an implicit equation (and inequality) plotter in the development version of sympy. It is created as a part of GSoC and it produces the plots as matplotlib figure instances.</p>
<p>In the next version of sympy (0.7.2) it will be available as:</p>
<pre><code>>>> from sympy.plotting import plot_impl... | 3 | 2012-06-25T21:42:41Z | [
"python",
"matplotlib",
"equation",
"implicit",
"sympy"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,484,591 | <p>A lot of us really <a href="http://stackoverflow.com/questions/859186/why-is-c-statically-typed/859226#859226">like working with strongly/statically-typed languages</a>. That's a big one there. </p>
| 11 | 2010-03-20T20:16:36Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,484,595 | <p>There are lots of differences, advantages as well as disadvantages. I guess the main advantages would be along the lines of</p>
<ul>
<li>Excellent Windows integration, including access to all standard GUI functions and other libraries.</li>
<li>JIT compilation, resulting in better performance than Python, in some o... | 9 | 2010-03-20T20:16:59Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,484,600 | <p>The JITer, and the fact that it can produce tighter code due to it supporting static typing. The JITer can be worked around by using one of the non-CPython implementations, or dropping to i386 and using psyco, but the static typing can't be worked around as trivially (nor do I believe that it should be).</p>
| 1 | 2010-03-20T20:17:22Z | [
"c#",
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.