Given [1,2,3,4,5], how can i do something like 1/1, 1/2, 1/3,1/4,1/5, ...., 3/1,3/2,3/3,3/4,3/5,.... 5/1,5/2,5/3,5/4,5/5
I would like to store all the results, find the minimum, and return the two numbers used to find the minimum. So in the case i've described above i would like to return (1,5).
So basically I would like to do somethin...
The question is in the title.
I'd like to do in Python what I do in this example in C:
#include <stdio.h>
int main() {
int i;
for (i=0; i<10; i++) printf(".");
return 0;
}
Output:
..........
In Python:
>>> for i in xrange(0,10): print '.'
.
.
.
.
.
.
.
.
.
.
>>> for i in xrange(0,10): print '.',
. . . . . . . . . .
...
########################################
# some comment
# other comment
########################################
block1 {
value=data
some_value=some other kind of data
othervalue=032423432
}
block2 {
value=data
some_value=some other kind of data
othervalue=032423432
}
...
How to print the following code to a .txt file
y = '10.1.1.' # /24 network,
for x in range(255):
x += 1
print y + str(x) # not happy that it's in string, but how to print it into a.txt
There's copy paste, but would rather try something more interesting.
...
This has always confused me. It seems like this would be nicer:
my_list = ["Hello", "world"]
print my_list.join("-")
# Produce: "Hello-world"
Than this:
my_list = ["Hello", "world"]
print "-".join(my_list)
# Produce: "Hello-world"
Is there a specific reason it does it like this?
...
I have a sequence of x, y and z -coordinates, which I need to manipulate. They are in one list of three tuples, like {(x1, y1, z1), (x2, y2, z2), ...}.
I need addition, multiplication and logarithm to manipulate my data.
I would like to study a module, which is as powerful as Awk -language.
...
My primary language right now is D, and I'm in the process of learning Python because it's required for a course I'm taking. While I understand why dynamic languages would be a breath of fresh air for people programming in static languages without type inference or templates (IMHO templates are to a large extent compile-time duck typing...
I want to know what is the current url of active tab in running firefox instance from python module. Does FireFox have any API for this and does python know to work with it?
...
Background:
I working on an application on Google App Engine. Its been going really well until I hit one of their limitations in file size -- 1MB. One of the components of my application resizes images, which have been uploaded by users. The files are directly uploaded to S3 (http://developer.amazonwebservices.com/connect/entry.jspa?ext...
I am writing a Python utility that needs to parse a large, regularly-updated CSV file I don't control. The utility must run on a server with only Python 2.4 available. The CSV file does not quote field values at all, but the Python 2.4 version of the csv library does not seem to give me any way to turn off quoting, it just allows me to...
I have the following code:
import math
import pygame
from pygame.locals import *
# Initialize PyGame
pygame.init()
pygame.display.set_mode((800,600))
quit = False
roundtime = 20 # ms
nextupdate = pygame.time.get_ticks() + roundtime
framenum = 0
# Watering radius
r = 25
# Time step
dt = 1 # min
field = [0.0]*80*60
while not quit:
...
Updated:
EDIT! I have coded the program wrongly. Instead of returning the Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 should = only those numbers between 1 & 20), I have written for the program to display all Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 displays = First 20 Fibonacci numbers). ...
I'd like to register a protocol handler, like "myapp:", across OS X, Linux, and Windows, so that when someone clicks a url like "myapp://some/params" in a web browser, a python script will be called and passed in those params.
Obviously this would require something being installed on each machine to enable it, but just trying to figure ...
It's a small thing, really: I have this function that converts dict objects to xml.
Here's the function:
def dictToXml(d):
from xml.sax.saxutils import escape
def unicodify(o):
if o is None:
return u'';
return unicode(o)
lines = []
def addDict(node, offset):
for name, value in node....
I have a file like:
<space>
<space>
line1
<space>
column 1 column 2 column 3 ...
.
.
.
<space>
<space>
How to remove this extra spaces?
I need to extract the heading which will be on line1. Also, I need to extract column 1, column 2, column 3 etc.
At the end of last column content there is '\n'.How to get rid of it ???
H...
I am new to XML-RPC.
#client code
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
x,y = arg1,arg2
print proxy.fun1(x,y)
print proxy.fun2(x,y)
What server should do:
load fun1
register fun1
return result
unload fun1
and then do same with fun2.
What is the best way to do this?
I have figured out a way to d...
Surely there is a better way to do this?
results = []
if not queryset is None:
for obj in queryset:
results.append((getattr(obj,field.attname),obj.pk))
The problem is that sometimes queryset is None which causes an exception when I try to iterate over it. In this case, I just want result to be set to an empty list. This co...
Hi,
I'm new to python, so please excuse what is probably a pretty dumb question.
Basically, I have a single global variable, called _debug, which is used to determine whether or not the script should output debugging information. My problem is, I can't set it in a different python script than the one that uses it.
I have two scripts:...
How to get rid of '\n' at the end of a line ?
...
Looking to dabble with GAE and python, and I'd like to know what are some of the best tools for this - thanks!
...