Hi, this is a program I wrote to calculate pythagorean triplets. When I run the program it prints each set of triplets twice beacuse of the if statement. is there any way I can tell the program to only print a new set of triplets once. thanks.
import math
def main():
for x in range (1, 1000):
for y in range (1, 1000):
...
I want to experiment/play around with non-relational databases, it'd be best if the solution was:
portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a configuration tool for first time usag...
I'm new to Python and am trying to understand its approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?
def f(n, x):
n = 2
x.append(4)
print 'In f():', n, x
def main():
n = 1
x = [0,1,2,3]
print 'Before:', n, x
f(n, x)
pr...
I had always assumed that a file would leak if it was opened without being closed, but I just verified that if I enter the following lines of code, the file will close:
>>> f = open('somefile.txt')
>>> del f
Just out of sheer curiosity, how does this work? I notice that file doesn't include a __del__ method.
...
Hi, I'm trying to make successive calls of some profiler code however on the second call to the function the update time of the profile file changes but the actual profiler stats stay the same. This isn't the code I'm running but it's as simplified an example I can come up with that shows the same behaviour.
On running, the first time c...
psyco seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way.
Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use psyco for all Python code? Does it make mistakes sometimes and ruins the correctness of the ...
I have to know what key is pressed, but not need the code of the Character, i want to know when someone press the 'A' key even if the key obtained is 'a' or 'A', and so with all other keys.
I can't use PyGame or any other library (including Tkinter). Only Python Standard Library. And this have to be done in a terminal, not a graphical i...
I have a dict where each key references an int value. What's the best way to sort the keys into a list depending on the values?
...
How can I convert strings which can denote decimal or rational numbers to floats
>>> ["0.1234", "1/2"]
['0.1234', '1/2']
I'd want [0.1234, 0.5].
eval is what I was thinking but no luck:
>>> eval("1/2")
0
...
Trying to understand super(). From the looks of it, both child classes can be created just fine. Im curious as to what difference there actually is in this code:
class Base(object):
def __init__(self):
print "Base created"
class ChildA(Base):
def __init__(self):
Base.__init__(self)
class ChildB(Base):
def _...
I am FTPing a zip file from a remote FTP site using Python's ftplib. I then attempt to write it to disk. The file write works, however most attempts to open the zip using WinZip or WinRar fail; both apps claim the file is corrupted. Oddly however, when right clicking and attempting to extract the file using WinRar, the file will extract....
I'm wondering what the common project/application structure is when the user model extended/sub-classed and this Resulting User model is shared and used across multiple apps.
I'd like to reference the same user model in multiple apps.
I haven't built the login interface yet, so I'm not sure how it should fit together.
The following c...
If I learn python 3.0 and code in it, will my code be still compatible with Python 2.6 (or 2.5 too!)?
Remarkably similar to:
If I'm Going to Learn Python, Should I Learn 2.x or Just Jump Into 3.0?
...
I am developing a simple game in PyGame... A rocket ship flying around and shooting stuff.
Question: Why does pygame stop emitting keyboard events when too may keys are pressed at once?
About the Key Handling: The program has a number of variables like KEYSTATE_FIRE, KEYSTATE_TURNLEFT, etc...
When a KEYDOWN event is handled, it ...
Hi,
I'm trying to write a TTL decorator in python.
Basically I give it raise an exception if the function doesn't
answer in the selected time.
You can find the thead2 snippets on http://sebulba.wikispaces.com/recipe+thread2
from thread2 import Thread
""" A TTL decorator. """
class Worker(Thread):
def __init__(self, q, f, args, k...
I'm noticing a pretty strange bug with tkinter, and I am wondering if it's because there's something in how the python interacts with the tcl, at least in Win32.
Here I have a super simple program that displays a gif image. It works perfectly.
from Tkinter import *
canvas = Canvas(width=300, height=300, bg='white')
canvas.pack()
...
Hi,
I have some code which I've been using to query MySQL, and I'm hoping to use it with SQLite. My real hope is that this will not involve making too many changes to the code. Unfortunately, the following code doesn't work with SQLite:
cursor.execute(query)
rows = cursor.fetchall()
data = []
for row in rows
data.append(row["column...
I want to design a website that can send and receive sms.
How should I approach the problem ?
What are the resources available ?
I know php,python what else do I need or are the better options available?
How can experiment using my pc only?[somthing like localhost]
What are some good hosting services for this? [edit this]
[Add more que...
Do you know of any tool that could assist me in obfuscating python code?
...
I'm a beginner in python. I have a huge text file (hundreds of GB) and I want to convert the file into csv file. In my text file, I know the row delimiter is a string "<><><><><><><>". If a line contains that string, I want to replace it with ". Is there a way to do it without having to read the old file and rewriting a new file.
Normal...