Forum: Python 9 Days Ago |
| Replies: 3 Views: 189 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 14 Days Ago |
| Replies: 4 Views: 369 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 17 Days Ago |
| Replies: 2 Views: 177 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 17 Days Ago |
| Replies: 10 Views: 520 if "EMERGENCY" or "Help" or "!" in heading:
pass
elif ("no idea" in body) or (not Code() in body):
pass |
Forum: Python 18 Days Ago |
| Replies: 2 Views: 358 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 18 Days Ago |
| Replies: 3 Views: 293 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 20 Days Ago |
| Replies: 4 Views: 301 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 21 Days Ago |
| Replies: 4 Views: 301 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: Geeks' Lounge 21 Days Ago |
| Replies: 679 Views: 78,341 It's Christmas madness already. In 1999, the United States Postal Service issued a Slinky postage stamp (the spring toy that slinks down the stairs). In 2001, House Bill No.1893 of the 2001 Session... |
Forum: Python 33 Days Ago |
| Replies: 9 Views: 741 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: 368 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: 239 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: 219 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,340 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: 484 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: 265 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: 945 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: 264 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: 255 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: 264 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: 309 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: 802 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: 326 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: 626 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,281 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: 278 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: 379 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: 298 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: 255 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: 956 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,435 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: 478 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: 597 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... |
Forum: Python Apr 10th, 2009 |
| Replies: 2 Views: 1,615 If you want to print from the word to the end of the line, use index. This untested code will tell you if a word is found. You can then use .join to print out what you want.for line in logfile:
... |
Forum: Python Apr 7th, 2009 |
| Replies: 6 Views: 877 Please put your code between code tags (the "#" icon) as no one will be able to run your program without proper indents. Generally, you use a control variable, in your case a string control... |
Forum: Python Mar 24th, 2009 |
| Replies: 4 Views: 294 The problem may be that you are using the reserved word "file" and perhaps overloading it. file and open are basically the same for Python. So use something other than "file", check the contents of... |
Forum: Python Mar 19th, 2009 |
| Replies: 6 Views: 419 Verify with the teacher that the set will only contain integers, floats, and strings, and whether there will be more than one type of these in the set.. If you have lists mixed in with integers... |
Forum: Geeks' Lounge Mar 19th, 2009 |
| Replies: 679 Views: 78,341 That is too fantastic to believe. 1000 soldiers would have to kill 1748 people in one hour, and 10,000 would still have to kill 174.8 in one hour. And that's not even mentioning how difficult it... |
Forum: Python Feb 16th, 2009 |
| Replies: 3 Views: 397 Generally, you would do a merge type program. Read in both files, compare and change, then write to a third file, which will be the merged file. So some pseudo-code
if "hb15b01" in record, find... |
Forum: Python Feb 9th, 2009 |
| Replies: 5 Views: 2,179 A slight modification.for index, item in enumerate(arr):
if item > 100:
return index, itemSee here for info on lists http://effbot.org/zone/python-list.htm
Edit: Damn, this is... |