Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.
To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.
In other words, which language "just works" with the most modules?
...
I have the following models in my Django app. How can I from the Team model find all the User objects who have accepted as True in the Membership model? I know I need to use Team.objects.filter(), but I'm not sure how to check the value of the accepted field.
from django.contrib.auth.models import User
class Team(models.Model):
memb...
As some of you may know in python2.7/3.2 we'll get OrderedDict with PEP372 however one of the reason the PEP existed was because everyone did their own implementation and they were all sightly incompatible.
So which one of the 8 current implementations link text is backwards compatible with the 2.7 odict from python 2.7 in a way we can...
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".
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 new one to call again the execut...
For instance, say I wanted a function to escape a string for use in HTML (as in Django's escape filter):
def escape(string):
"""
Returns the given string with ampersands, quotes and angle
brackets encoded.
"""
return string.replace('&', '&').replace('<', '<').replace('>', '>').repla...
I have a private method def __pickSide(self): in a parent class that I would like to override in the child class. However, the child class still calls the inherited def __pickSide(self):. How can I override the function? The child class's function name is exactly the same as the parent's function name.
...
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.
text(x, y, 'Summary', backgroundcolor = 'm', color = 'k')
This gives me a magenta background and then text that is almost just as pink. Any ideas what I'm doing wrong?
Many th...
I have this code in Python
inputted = input("Enter in something: ")
print("Input is {0}, including the return".format(inputted))
that outputs
Enter in something: something
Input is something
, including the return
I am not sure what is happening; if I use variables that don't depend on user input, I do not get the newline after for...
In the book Programming Collective Intelligence I found the following function to compute the PageRank:
def calculatepagerank(self,iterations=20):
# clear out the current PageRank tables
self.con.execute("drop table if exists pagerank")
self.con.execute("create table pagerank(urlid primary key,score)")
self.con.execute("...
I've got the following code and I'm not sure how to add the QGraphicsScene to my layout..
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.view = QGraphicsView()
self....
Hello all - many thanks again to people who have kindly offered help (especially to Mark for his outstanding response to my previous question).
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?
All the best,
Geddes
...
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?
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 server is all written in C#. ...
(tl;dr: What's the best learning path to go from PHP/Python web development to application development for Windows CE?)
I'm a self-taught programmer, and I tend to learn by starting from the goal and researching backwards until I get to a point I know. However, I now have a project involving barcode scanners on a pocket-pc, and I'm at a...
In Python, if I want to get the first n characters of a string minus the last character, I do:
output = 'stackoverflow'
print output[:-1]
What's the Ruby equivalent?
...
I set a variable MAX_REQUEST = 100 in settings.py
I write a middleware which may lower this value for request origining from a proxy ip address by the following code:
settings.MAX_REQUEST = 10
However, looks like the above modification affects all legitimate users.
Is it normal?
...
When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'.
However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.
Here are examples of how I trying to install PIL using virtualenv:
# virtualenv --no-site-packages...
Here's my code:
# B. both_ends
# Given a string s, return a string made of the first 2
# and the last 2 chars of the original string,
# so 'spring' yields 'spng'. However, if the string length
# is less than 2, return instead the empty string.
def both_ends(s):
if len(s) <= 2:
return ""
else:
return s[0] + s[1] + s[len(s)-2]...
Hi, everyone.
I am debugging a python module with homemade c extensions. The output seems correct when I print it with 'p' in pdb. But if I use a normal print statement or pickle it, the output is wrong. What could be causing pdb to show different values than normal execution? I can even step to the print statement in debug mode, an...
I am trying to call gawk (the GNU implementation of AWK) from Python in this manner.
import os
import string
import codecs
ligand_file=open( "2WTKA_ab.txt", "r" ) #Open the receptor.txt file
ligand_lines=ligand_file.readlines() # Read all the lines into the array
ligand_lines=map( string.strip, ligand_lines )
ligand_file.close()
for ...
This is my first effort on solving the exercise. I gotta say, I'm kind of liking Python. :D
# D. verbing
# Given a string, if its length is at least 3,
# add 'ing' to its end.
# Unless it already ends in 'ing', in which case
# add 'ly' instead.
# If the string length is less than 3, leave it unchanged.
# Return the resulting string.
def...