I am making a profile form in Django. There are a lot of optional extra profile fields but I would only like to show two at a time. How do I hide or remove the fields I do not wan to show dynamically?
Here is what I have so far:
class UserProfileForm(forms.ModelForm):
extra_fields = ('field1', 'field2', 'field3')
extra_field_t...
hey guys,
I'm new in python and I have a problem.
I have some measured data saved in a txt file.
the data is separated with tabs, it has this structure:
0 0 -11.007001 -14.222319 2.336769
i have always 32 datapoints per simulation (0,1,2,...,31) and i have 300 simulations (0,1,2...,299), so the data is sorted at first with the numbe...
Apologies, I am completely new to Django and Python.
I have 2 questions. First, how would I go about getting the last object created (or highest pk) in a list of objects? For example, I know that I could use the following to get the first object:
list = List.objects.all()[0]
Is there a way to get the length of List.objects? I've trie...
I'm having trouble getting my bot to login to a MediaWiki install on the intranet. I believe it is due to the http authentication protecting the wiki.
Facts:
The wiki root is: https://local.example.com/mywiki/
When visiting the wiki with a web browser, a popup comes up asking for enterprise credentials (I assume this is basic access ...
Hi!
I have following problem:
My application have 2 models:
1)
class ActiveList(models.Model):
user = models.ForeignKey(User, unique=True)
updatedOn = models.DateTimeField(auto_now=True)
def __unicode__(self):
return self.user.username
'''
GameClaim class, to store game requests.
'''
class GameClaim(models.Model)...
Hello all,
I am using the following call for executing the 'aspell' command on some strings in Python:
r,w,e = popen2.popen3("echo " +str(m[i]) + " | aspell -l")
I want to test the success of the function looking at the stdout File Object r. If there is no output the command is successful.
What is the best way to test that in Python?...
I have a python script which process a file line by line, if the line
matches a regex, it calls a function to handle it.
My question is is there a better write to refactor my script. The
script works, but as it is, i need to keep indent to the right of the
editor as I add more and more regex for my file.
Thank you for any idea.
Now my ...
I am looking to integrate some dynamically generated BI reports into a web app. The requirements are:
Able to view report based on JSON RPC XML, or some similar streaming data source (therefore, not requiring direct access to the DB). Why? Because many users have access to different copies of similar data. I.e. 3 companies, 5 projects....
I have a Model that looks something like this:
class Business(models.Model):
name = models.CharField('business name', max_length=100)
# ... some other fields
emails = models.ManyToManyField(Email, null=True)
phone_numbers = models.ManyToManyField(PhoneNumber, null=True)
urls = models.ManyToManyField(URL, null=True)
...
What's the best open source Python project for reading code and seeing how Python should be written? I'm at a crossroads in Python; I've written a lot of good code, but I want to write truly exceptional clean and intelligent code. I feel like the best way to do this is to read the source for a good project (if there are other ways, I'm o...
Java's InputStream provides a method named available which returns the number of bytes that can be read without blocking. How can I achieve this in Python?
...
The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).
I've thought about two unpythonic ways of doing it:
def pairs(lst):
n = len(lst)
for i in range(n):
yield lst[i],lst[(i+1)%n]
and:
def pairs(lst):
return zip(lst,lst[1:]+[lst[0]])...
When I run the code below outside of timeit(), it appears to complete instantaneously. However when I run it within the timeit() function, it takes much longer. Why?
>>> import timeit
>>> t = timeit.Timer("3**4**5")
>>> t.timeit()
16.55522028637718
Using:
Python 3.1 (x86) -
AMD Athlon 64 X2 -
WinXP (32 bit)
...
I've setup my gVim to have omnicompletion, but only for the standard library atm.. How do I include other libraries (Django, Pygame, etc...)?
Thanks!
...
I'm trying to output the content of a comment with genshi, but I can't figure out how to transform the newlines into HTML paragraphs.
Here's a test case of what it should look like:
input: 'foo\n\n\n\n\nbar\nbaz'
output: <p>foo</p><p>bar</p><p>baz</p>
I've looked everywhere for this function. I couldn't find it in genshi or in python...
First I write the integer using python:
out.write( struct.pack(">i", int(i)) );
I then read the integer using DataInputStream.readInt() in Java.
I works but when it tries to read the number 10, and probably some other numbers too,
it starts to read garbage.
Reading the numbers:
0, 4, 5, 0, 5, 13, 10, 1, 5, 6
Java reads:
0, 4, 5, 0, 5, 1...
How to recognize (in)appropriate images?
To facilitate, enable and easify photo and image moderation and administration targeting gae, I try get started with basic python image recognition ie basic semantic information what the image looks like to hold back doubtful material until human can judge it, and to approve the most that are goo...
I am using Django's generic views to create a blog site. The
templates I created, entry_archive_day, entry_archive_month,
entry_archive, and entry_detail all work perfectly.
But entry_archive_year does not. Instead, it is simply a valid page with no content (not a 404 or other error. It looks like it sees no objects in **object_lis...
I want to parse dates like these into a datetime object:
December 12th, 2008
January 1st, 2009
The following will work for the first date:
datetime.strptime("December 12th, 2008", "%B %dth, %Y")
but will fail for the second because of the suffix to the day number ('st'). So, is there an undocumented wildcard character in strptime...
I have a online file: http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe ,please donot download it, i want to determine the software version whether is changed, so i want more information about it. for example, using python,i can get this:
import urllib2,urllib
req = urllib2.Request('http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe') ...