Forum: Python 17 Hours Ago |
| Replies: 27 Views: 730 What type of objects does the query return? You may have to convert to a list to access it in this way. query = db.GqlQuery("SELECT *" .....etc.
print type(query)
ctr = 0
for q in query:
if... |
Forum: Python 4 Days Ago |
| Replies: 2 Views: 229 I don't use regex as a rule and it is not necessary in this case. found = False
fp = open(fname, 'r')
for num, line in enumerate(fp):
line = line.strip()
if line.startswith(search_term):... |
Forum: Python 4 Days Ago |
| Replies: 4 Views: 172 One thing, you can not open a directory, so you should test that it is a file. import os
a = []
a = os.listdir('.')
for t in a:
if os.path.isfile(t):
f = open(t,'r')
print... |
Forum: Python 4 Days Ago |
| Replies: 6 Views: 228 if option==3:
active<>"on"This will print "True" if active != 'on' and print "False" otherwise. <> has been deprecated so use "!=" instead. I think you want if option==3:
... |
Forum: Python 10 Days Ago |
| Replies: 1 Views: 262 effbot's tutorial turns up as the first hit for a Google of "tkinter scrollbars". Since we don't know what you want to attach it to, effbot would be the place to start. This is effbot's code for a... |
Forum: Python 12 Days Ago |
| Replies: 5 Views: 206 It would generally be something in this ballpark file_pointer = open("Handylist.csv", "r")
name_in = raw_input("Enter the name")
for rec in file_pointer:
substrs = rec.split()
name =... |
Forum: Python 12 Days Ago |
| Replies: 6 Views: 245 Just read it, line by line, as a normal file, unless it is not a text file, in which case you would have to read and convert to text. See 2.4.5 here... |
Forum: Python 12 Days Ago |
| Replies: 6 Views: 245 It's pretty straight forward, and since I'm sick and not doing much today... test_data = [ "c The random seed used to shuffle this instance was seed=1755086696",
"p cnf 1200 4919",
... |
Forum: Python 22 Days Ago |
| Replies: 3 Views: 220 The first two posts found in a search of this forum, after your post which is the first/latest, have working solutions that you should be able to adapt. |
Forum: Python 27 Days Ago |
| Replies: 4 Views: 416 A quick example of a spiral using deque. It still has a few problems (works best with a square and prints too many) but shows the general concept. from collections import deque
... |
Forum: Python 30 Days Ago |
| Replies: 2 Views: 205 It is easier to code than to explain. This will only work if you use a fixed width font. A proportional font would require more work. It is a little bit tricky in that you want to print one... |
Forum: Python 30 Days Ago |
| Replies: 10 Views: 563 if "EMERGENCY" or "Help" or "!" in heading:
pass
elif ("no idea" in body) or (not Code() in body):
pass |
Forum: Python 31 Days Ago |
| Replies: 2 Views: 502 I think you could check for a number in the second position, if I understand correctly that overlays use numbers and updates/adds use a letter. if len(line.strip()) and \
not... |
Forum: Python 31 Days Ago |
| Replies: 3 Views: 344 So you are obviously using PyQT4 built for Python 2.6. The error message confirms it. Ask how to install PyQT for both 2.6 and 3.x on the Ubuntu or PyQt forum. Some one has done this and if there... |
Forum: Python 33 Days Ago |
| Replies: 4 Views: 344 Python does not have static variables, but does have global variables, which those are not. They are class objects and would be called using
Atom.cartesian
both inside and outside the class. In... |
Forum: Python 34 Days Ago |
| Replies: 4 Views: 344 You have both class instances and class objects. The variables
cartesian = dict()
bondList = list()
atomName = str()
atomicNum = int()
would point to the same variable (block... |
Forum: Python Nov 6th, 2009 |
| Replies: 9 Views: 879 There are several online pages to do that.
http://primes.utm.edu/curios/includes/primetest.php
is one found on this very good page
http://primes.utm.edu/
Your program works correctly, at least... |
Forum: Python Oct 27th, 2009 |
| Replies: 5 Views: 417 Google came up with this site which has a link to download source code. I hope you didn't pay $99.95 for the book! http://www.jbpub.com/catalog/9780763746025/ |
Forum: Python Oct 22nd, 2009 |
| Replies: 2 Views: 265 You can set the encoding for the file
fp = codecs.open('test', encoding='utf-8', mode='w')
Or you can change the default encoding for the system
sys.setdefaultencoding('utf-8')
You may have... |
Forum: Python Oct 19th, 2009 |
| Replies: 8 Views: 228 Using for() loops is easier. This is somewhat of a brute force method but works fine for smaller lists. L1=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
L2=[1,2,3,4,11]
L3=[]
for number in L2:
... |
Forum: Python Oct 16th, 2009 |
| Replies: 6 Views: 3,423 Roman to integer. Note that it will take something like XXIXV and convert it. If someone already has a routine to check for valid input, please post it. And I'm afraid we've just eliminated one... |
Forum: Python Oct 15th, 2009 |
| Replies: 12 Views: 508 Dictionaries are indexed via a hash and so make it easy to look up things, in this case the stock symbol, without going through the sub-strings in each list. Also, they provide a convenient way to... |
Forum: Python Oct 15th, 2009 |
| Replies: 6 Views: 277 Can you use a list instead of all of those variables? Otherwise, try the code below which tests each button individually instead of the confusing and, and, or, etc. in your code. Speaking of... |
Forum: Python Oct 14th, 2009 |
| Replies: 13 Views: 1,049 You would have to step through the unicode and count the number of actual letters, and then add enough spaces to the string to make it the length you want. This appears to work, but you'll have to... |
Forum: Python Oct 11th, 2009 |
| Replies: 1 Views: 301 That's not a good example to copy (although the book ultimately solves that problem if memory serves.). Find one using the canvas widget as it uses a top left corner (x,y) and a bottom right corner.... |
Forum: Python Oct 10th, 2009 |
| Replies: 2 Views: 272 You would generally use a for loop to iterate through a list. I'm creating one output string, but you could also print within the for loop. Also, please do not use "i", "l" or "o" as single letter... |
Forum: Python Oct 2nd, 2009 |
| Replies: 4 Views: 268 A dictionary with the letter as the key is the straight forward way to do this. Otherwise use a function with a for loop to pass the letter and the string to the function.import string
... |
Forum: Python Oct 1st, 2009 |
| Replies: 3 Views: 312 Your problem is here for n in range(num_iterations):
print "n before =", n
n = B*10
print "n after =", n You use "n" twice and are always multiplying the same number,... |
Forum: Python Sep 15th, 2009 |
| Replies: 4 Views: 923 For exactness, use the decimal class. My take on the program using decimal. Note that decimal.Decimal is imported as "dec" to avoid confusion with the variable names. Also, I am not a decimal... |
Forum: Python Sep 14th, 2009 |
| Replies: 5 Views: 333 There is an error on this line, no colon
for line in objconfigfile.readlines()
I would suggest that you print every line because
if line == None:
will probably never be true, but you will have... |
Forum: Python Sep 12th, 2009 |
| Replies: 6 Views: 665 For future coding conundrums, an "or" can be viewed as an if / elif, and "and" can be viewed as two nested if statements, which you would adapt to while() statements.
while overwrite != 'Y'.lower()... |
Forum: Python Sep 3rd, 2009 |
| Replies: 29 Views: 1,294 My attempt. Once again, if not correct, post back with more info. The trick (I think) is to split each string on the "\n" to create individual rows, and is similiar to Gribouillis' solution but... |
Forum: Python Aug 12th, 2009 |
| Replies: 3 Views: 288 Use the codebox
"Display some text in a monospaced font, with no line wrapping.
This function is suitable for displaying code and text that is
formatted using spaces.
The text parameter should... |
Forum: Python Jun 24th, 2009 |
| Replies: 1 Views: 414 You use a StringVar and include the function in the class. Here is a simple example. Note that the same StringVar is used for the second label and the entry box. Take a look at this page... |
Forum: Python Jun 23rd, 2009 |
| Replies: 2 Views: 319 You can do this two different ways.items = {'sword':['sword', 3, 15],
'axe':['axe', 5, 25],
'bow and arrow':['bow and arrow', 4, 20]}
##---- the easiest to understand... |
Forum: Python Jun 15th, 2009 |
| Replies: 5 Views: 257 Yes that should have been one to get the next value. A good example of why we don't use "i". |
Forum: Python Jun 15th, 2009 |
| Replies: 9 Views: 1,018 A google will yield a lot of hits. The python wiki is always a good place to start. http://wiki.python.org/moin/GuiProgramming |
Forum: Python Jun 2nd, 2009 |
| Replies: 4 Views: 20,564 The standard solution for anagrams is to sort on the letters. So 'ogd' sorted is 'dgo', and a lookup of the 'dgo' key in the dictionary yields the list ["dog", "god"]. Your code would only return... |
Forum: Python May 21st, 2009 |
| Replies: 4 Views: 495 Please don't spam this site or someone will report you and you will be banned. Since the OP didn't say which toolkit or OS was involved, it is obvious that there is no way to recommend anything,... |
Forum: Python May 21st, 2009 |
| Replies: 5 Views: 663 This was the second entry from a Google for "python list write"
http://www.daniweb.com/forums/thread173615.html
and effbot is usually in search results. This explains writelines(), but... |