Hey All,
Using an example from the Python DOCs:
stocks = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00),
('2006-04-06', 'SELL', 'IBM', 500, 53.00),
]:
for t in stocks
c.execute('insert into stocks values (?,?,?,?,?)', t)
In my code, the stocks from above is g...
I'm experiencing a (for me) very weird problem in Python.
I have a class called Menu: (snippet)
class Menu:
"""Shows a menu with the defined items"""
menu_items = {}
characters = map(chr, range(97, 123))
def __init__(self, menu_items):
self.init_menu(menu_items)
def init_menu(self, menu_items):
i =...
"SystemError: com_backpatch: offset too large" thrown when executing the code generated by the following code.
f = open("test.py", "w")
f.write("def fn():\n a =1000\n")
for a in xrange(3000):
if a == 0:
f.write(" if a == "+str(a)+": \n print "+str(a)+"\n")
else:
f.write(" elif a == "+str(a)+": \n print...
I am working with some code that uses Traits UI to show a dialog from which the user is able to select two files:
class Files(HasTraits):
filename_1 = File(exists=True)
filename_2 = File(exists=True)
traits_ui = View(
'filename_1', 'filename_2',
title = 'Select Geometry Files',
buttons = ['OK', 'Ca...
Is it possible, when instantiating an object, to pass-in a class which the object should derive from?
For instance:
class Red(object):
def x(self):
print '#F00'
class Blue(object):
def x(self):
print '#00F'
class Circle(object):
def __init__(self, parent):
# here, we set Bar's parent to `parent`
...
I am trying to implement a PKI verification scheme, where a message string is signed with a private key on server, the signature is stored on the client along with the message string. The client then verifies the signature using a public key.
The restrictions of my environment are, the server is Google App Engine and the client is a Jav...
There's a file that I would like to make sure does not grow larger than 2 GB (as it must run on a system that uses ext 2). What's a good way to check a file's size bearing in mind that I will be writing to this file in between checks? In particular, do I need to worry about buffered, unflushed changes that haven't been written to disk ...
The full text of the error is:
TemplateSyntaxError at /
Caught an exception while rendering:
current transaction is aborted,
commands ignored until end of
transaction block
I've recently reinstalled all the software on my computer. The code used to work no problem before. It also still works no problem on a friend's comp...
Hello everybody!!!
I just created my first application for Google App Engines, which is called "Hello World". It was the first lesson from Google App Engines How-to-get-started tutorial. I tasted it on my computer (I am using Windows XP), and it was working just fine - whenever I would open a new window with my web browser (FireFox), I ...
I have some code of the form:
for i in range(nIterations):
y = f(y)
Where f is a function defined elsewhere. hopefully the idea of that code is that after it's run y will have had f applied to it nIterations times.
Is there a way in python to write this in a single line?
...
Hi, I have just started learning Python, and I'm trying to write a program for Conway's Game of Life. I'm trying to create a closed universe with boundary conditions(which are the opposite side/corner). I think I have done this, but I'm not iterating over the loop when it runs, and can't work out how to do this. Thanks very much in advan...
Hi, new to Python and had a question about dictionaries. I have a dictionary that I declared in a particular order and want to keep it in that order all the time. The keys/values can't really be kept in order based on their value, I just want it in the order that I declared it.
So if I have the dictionary:
d = {'ac':33, 'gw':20, 'ap':1...
I have a file a.txt in Mac OS, which has write perms to everybody:
sh-3.2# ls -hal a.txt
-rw-rw-rw- 1 root wheel 0B Dec 8 11:34 a.txt
sh-3.2# pwd
/var/root
however in python it gives me an error:
>>> fob=open("/var/root/a.txt","w")
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
fob=open("/va...
I'm trying to setup Fabric so that I can automatically deploy my Django app to my web server.
What I want to do is to pull the data from my Development machine (os X) to the server.
How do I correctly specify my path in the git url?
This is the error I'm getting:
$ git pull
fatal: '/Users/Bryan/work/tempReview_app/.': unable ...
This is in reference to a question I asked before here
I received a solution to the problem in that question but ended up needing to go with regex for this particular part.
I need a regular expression to search and replace a string for instances of two vowels in a row that are the same, so the "oo" in "took", or the "ee" in "bees" and ...
Hello everybody!!!
On Google App Engine I found this code that is fetching a web page's URL:
from google.appengine.api import urlfetch
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
doSomethingWithResult(result.content)
Is this the right code to fecth that page's HTML source? Does the resu...
#! /usr/bin/env python
import os
import stat
import sys
class chkup:
def set(file):
filepermission = os.stat(file)
user_read()
user_write()
user_exec()
def user_read():
"""Return True if 'file' is readable by user
"""
...
Run the following code from a directory that contains a directory named bar (containing one or more files) and a directory named baz (also containing one or more files). Make sure there is not a directory named foo.
import shutil
shutil.copytree('bar', 'foo')
shutil.copytree('baz', 'foo')
It will fail with:
$ python copytree_test.py...
I have Windows Vista 64-bit SP2. I am trying to use wxPython for GUI development with Python, because all my research pointed to that as the way to go. I have downloaded and installed the win64 wxPython. I get the same error every time.
Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "cop...
I have a catalog of items like so:
class Items(models.Model):
name=models.CharField()
type=models.ForeignKey(ItemType)
quantity=models.IntegerField()
price=models.DecimalField() # Simplified
[... other fields]
and it has some attributes governed by:
class ItemAttributes(models.Model):
name=models.CharField()
...