I'm new to python and wanted to do something I normally do in matlab/R all the time, but couldn't figure it out from the docs.
I'd like to slice an array not as 0:3 which includes elements 0,1,2 but as an explicit vector of indices such as 0,3
For example, say I had this data structure
a = [1, 2, 3, 4, 5]
I'd like the second and thi...
Possible Duplicate:
Whats the best way to implement an enum in Python?
What is the Python idiom for a list of differently indexed names (like Enum in C/C++ or Java)?
Clarification: I want a property of a value to be set to a restricted range, such as card suites Heart, Club, Spade, Diamond. I could represent it with an int in...
Hi,
I am running AppEngine locally.I use some filters on the following attribute of my object :
class Blah(db.Model):
access_code = db.StringProperty()
Then I run my filter in the view:
cac = Blah.all().filter(
'access_code =', 'value_to_find').fetch(1)
When doing so, I get the following error : BadValueError: Filtering o...
I have a Python program that creates an excel sheet, but I have been asked by one of the users to modify it so that if he hits print it will print out to landscape mode, without him having to specify this. Is there some way to set the sheet to landscape in XLWT or some similar Python library for excel?
Thank you.
...
Consider the following file\directory structure:
project\
| django_project\
| | __init__.py
| | django_app1\
| | | __init__.py
| | | utils\
| | | | __init__.py
| | | | bar1.py
| | | | ...
| | | ...
| | django_app2\
| | | __init__.py
| | | bar2.py
| | | ...
| | ...
| scripts\
| | __init__.py
| |...
After running a query on the datastore, I copy the results to a new list as I interrogate, merge and prune the results. When I'm finished, I'd like to sort the new list, but I'm seeing the following error...
TypeError: 'LiveRouteStatus' object is unsubscriptable
LiveRouteStatus is a Model class that I query, and while the actual code i...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'djangobb', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'ro...
stack = []
closed = []
currNode = problem.getStartState()
stack.append(currNode)
while (len(stack) != 0):
node = stack.pop()
if problem.isGoalState(node):
print "true"
closed.append(node)
else:
child = problem.getSuccessors(node)
if not child == 0:
stack.append(child)
...
I'm using the Python shell in Django to make some queries. The results keep getting truncated. I get the message, "remaining elements truncated." How can I see all the results? Or, how can I write the results to a file?
...
Hi
I have been working to build a complex data structure which would return a dictionary. Currently that class return string object of the form
{
cset : x,
b1 : y,
b2 : z,
dep : {
cset : x1,
b1 : y1,
b2 : z1,
dep : {
cset : ...
I wrote a script to take files of data that is in columns and plot it depending on which column the user wants to view. Well, I noticed that the plots look crazy, and have all the wrong numbers because python is ignoring the exponential.
My numbers are in the format: 1.000000E+1 OR 1.000000E-1
What dtype is that? I am using numpy.ge...
This is the problem:
Function Name: randomSentenceRedux
Parameters:
1.string – a string object to manipulate
Return Value:
A transformed string where the words from the original sentence are in a random order.
Test Case(s):
>>>print randomSentenceRedux("My name is Sally Sue")
My is name Sue Sally
>>>print randomSentenceRedux("he...
How to print in python in one line.
Suppose I have iteration
for iten in range(1,100):
print item
It give me
1
2
3
4
......
but I want to be result like this
1 2 3 4 5 ...................
By the way...... How to refresh it every time so it print mi in one place just change the number.
...
Hi,
I've been developing on my laptop.
Now, I've uploaded my development project from Django 1.2/Python 2.7 up to Dreamhost created using the Passenger setup. I am using South for migration.
I modified settings.py to access MySQL. Got Admin working.
Questions:
1) Where is the std out shown when you hit the site? (all my print st...
I don't need the laziness of itertools.groupby. I just want to group my list into a dict of lists as such:
dict([(a, list(b)) for a,b in itertools.groupby(mylist, mykeyfunc)])
Is there a standard function that already does this?
...
When using the shell, this confused me (the permissions did not reflect changes):
>>> user = User.objects.get(username='test')
>>> user.get_all_permissions()
set([])
>>> p = Permission.objects.get(codename="add_slide")
>>> user.user_permissions.add(p)
>>> user.save()
>>> user.get_all_permissions()
set([])
>>> user = User.objects.get(use...
I'm trying to use feedparser (an excellent library) to parse WordPress export files, and a (minor) inconsistency between WordPress version is causing me a huge headache.
WordPress 2.x doesn't include atom:link tags in the XML output (without_atom_tags.xml). When parsed, namespaced elements are available without the prefix:
>>> feed = ...
This is a really unfortunate situation. Maya 2011 comes with 2.6.4 and this code does not work in it:
pipe = subprocess.Popen( 'p4 -G edit C:/somefile.txt', stdout=subprocess.PIPE).stdout
try:
while 1:
record = marshal.load( pipe )
list.append( record )
except EOFError:
pass
Various 2.5 versions work and the ...
Hi,
In my code (python2.6, PyQt4) I do something like this:
def myRun():
doStuff
thread = QtCore.QThread()
thread.run = myRun
thread.start()
On my gentoo machine, this works perfectly. On a ubunut (9.10, Karmic Koala) it does not work, it says:
Type Error: myRun() takes no arguments (1 given)
Did something change in QT? How can ...
If I have a script that writes 1000 lines to file and then continues regular expressions against that file, however only the last 100 lines of text written will be available. One way around this is to close and reopen the file. Is there a way to reload a file after being written to or should I just make a write close open module? It may ...