4,305 Posted Topics
Re: Using your example list [B]array=[['a','b'],['b','c'],['c','a']][/B] what do you expect the result to look like? | |
Re: This might help you ... [code]# test data (tab separated) data_test = """\ Tree Branches Leaves Height Cedar 12 80 100 Pine 9 70 80 Maple 15 100 120 """ fname = "file.txt" # write the test file fout = open(fname, "w") fout.write(data_test) fout.close() # read the test file back … | |
Re: Just a thought, I have used that trick before. You can use [CODE]canvas.move(canvas_object, xAmount, yAmount) root.update()[/CODE]to move the object you created right off the canvas to hide it. Then bring it or another object back. | |
Re: Well, you are close. A test print line will help ... [code]def sums(n): sum = 0 for i in range(0, n + 1, 1): sum = sum + i print i, sum # test return sum def main(): n = input('Enter a number: ') s = sums(n) print 'The sum … | |
Re: You don't want to change the dictionary you are iterating over. | |
Re: In the opening page of Python there is a big yellowish button near the top called appropriately [B]Start New Thread >[/B] | |
Re: Ronnicus, please put your code into code tags like this: [noparse][code][/noparse] ... your Python code here ... [noparse][/code][/noparse] If your function changes a value you want to use, you have to use return. Here is your correct approcach ... [code]test = 4 def change(): test = 5 return test print … | |
Re: You simply create a Python dictionary container where the English word is the key and the Spanish word is the value. For an example see: [url]http://www.daniweb.com/forums/showthread.php?p=1122938#post1122938[/url] | |
Re: [B]Jython[/B] comes to mind. It would allow you to run Python code under Java. | |
Re: Which GUI toolkit are you using? If it's wxPython take a look at: [url]http://www.daniweb.com/forums/post1154552.html#post1154552[/url] Once you have established the panel layout, simply put your widget on the desired panel. | |
| |
Re: [QUOTE=pyprog;1174074]I want to remove all the 1's from the sublists so l becomes [[2], [2], [2]] but have trouble keeping track of indices. Can someone help out? [CODE]l = [[1, 2, 1],[1, 1, 2],[2, 1, 1]] i = 0 for element in l: while i < len(element): if element[i] == … | |
Re: There really isn't a need for module datetime in your example ... [code]import time # create yyyymmdd string # uses today's time tuple by default today = time.strftime("%Y%m%d") print today # eg. 20100329 [/code] | |
A demo of the Tkinter listbox widget that shows you how to create the listbox, make it scrollable, position it within a grid, load it with data from a file, select a line of data with the mouse and display it. Also, sort the lines, add a line, delete a … | |
Re: I can't think of any practical use for this. | |
Re: That happens when your score file reads an empty line generated by a newline character in the last data line. To prevent this error simply skip any empty line like this ... [code] for line in scores.split('\n'): # skip any empty line if not line: continue userScore, score = line.split(',') … | |
Re: If I understand this right, you could also use this approach ... [code]# name, score text for the test test_text = """\ John, 88 Mark, 75 Frank, 79 Bob, 56""" fname = "myscores.txt" #write the multiline text to a test file fout = open(fname, "w") fout.write(test_text) fout.close() # read the … | |
Re: [B]file.writelines(str(new) + " passes" + "\n")[/B] expects a list as argument, use [B]file.write(str(new) + " passes" + "\n")[/B] to write a string Also, [B]file[/B] is a function name in Python2, it would be better to use something like variable name [B]fapp[/B] (for file append) | |
Re: To write out to file use ... [code] fileHandle = open ( 'scores.txt', 'w' ) fileHandle.write(str1) fileHandle.close() [/code]To append to an existig file use ... [code] fileHandle = open ( 'scores.txt', 'a' ) fileHandle.write(str1) fileHandle.close() [/code] | |
Re: Very smart homework problem. Now let's see some effort on your part to solve it! Hint ... [code]vowels = 'aeiouy' word = 'polarity' for letter in word: if letter in vowels: print( letter ) [/code] | |
Re: I think [B]Tom Gunn[/B] is an AI system that is down for the switch to Windows 7. | |
Re: So, what result to you want to get? If the highest final grade cannot exceed 100, then rewrite your if statments like this ... [code] if finalMark < 50: print "Fail" elif finalMark < 65: print "Pass" elif finalMark < 75: print "Credit" elif finalMark < 85: print "Distinction" elif … | |
Re: Seems to be homework, so what have you coded so far? | |
Re: I assume you want to create a [B]item_id: [item_name, price, quantity] [/B] dictionary? | |
Re: Since the data of the 2010 Olympics would be relatively small, you could go with a list of (event, country_gold, country_silver, country_bronze) tuples, as show in this example ... [code]# index constants EVENT = 0 GOLD = 1 SILVER = 2 BRONZE = 3 # [(event, country_gold, country_silver, country_bronze), ...] … | |
Re: I would gladly help, but your question is hard to understand. Could you elaborate some more? | |
Re: Thanks for the funny truth! | |
Re: This is one way to do it ... [code]# create a list of buttons # show click values in an entry try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def click(val): s = "Button " + val + " clicked" root.title(s) entry.insert('end', val) … | |
Re: Don't you think you should do something with your random x, y values? Please clean up your indentations. | |
Re: A lot depends on how you create your bitmap-button objects. | |
Re: You can download the graphics.py module from: [url]http://mcsp.wartburg.edu/zelle/python/graphics.py[/url] The module itself has some demo/test code in it. There is also a reference to Prof. Zelle's book that uses this module. Here is a typical example ... [code]# draw a circle on top of two rectangles # using module graphics from: … | |
![]() | Re: Some recommended changes, most of them are style changes ... [code]import time # it's customary to capitalize class names class NameList: def __init__(self, name): self.names = [] self.name = name print('Now constructing a', name, 'list!') def addNames(self): prompt = """\ Type a name to add to the list or "Q" … ![]() |
We take a look at the various functions of module time, counting seconds and milliseconds, measuring the time a simple for-loop takes, inspect a list of time data and ways to display it in a useful manner. An attempt is made to find the day of the week, given a … | |
Re: Well, with the code you gave us, the star could look a lot like a face. | |
Re: You got that sort of backwards. First you find a customer with a problem, then you write the software. | |
Re: It might be worthwhile pointing out which of the many possible GUI modules you are using. | |
Re: This may give you the hint you need ... [code]# create a list of buttons try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def click(val): s = "Button " + val + " clicked" root.title(s) root = tk.Tk() # create the list of … | |
Re: Try something like this ... [code]new_line = [1.2, 2.4, 1234.5] line_jn = ' '.join(['%15E' % x for x in new_line]) print(line_jn) # 1.200000E+00 2.400000E+00 1.234500E+03 [/code] | |
| |
Re: Hint ... prime numbers are only divisible by unity and themselves (by convention 1 is not considered a prime number) | |
Re: Your problem must be in the assign() function. | |
Re: Not quite sure why you want to synchronize the two spinboxes, but here is one way (with the option to synchronize just to one spinbox) ... [code]# pqt_spinbox_LCD2.py # create a PyQt form with 2 spinboxes and 2 LCD readouts # sychronize the 2 spinboxes # vegaseat from PyQt4.QtCore import … | |
Re: Study this little code example, it should give you a hint ... [code]# create a calculator key pad with Tkinter import Tkinter as tk # needs Python25 or higher from functools import partial def click(btn): # test the button command click entry.insert('end', btn) root = tk.Tk() # typical calculator button … | |
Re: [QUOTE=Paul Thompson;1160197]If i remember correctly wxPython is not looking to port to python 3.x any time soon. So if you are interested in using that then i would reccomend that you don't change. Personally i have not moved, i have tried it out but i never really found a reason … | |
Re: [url]http://www.daniweb.com/forums/post1155660.html#post1155660[/url] | |
Re: Does that mean she threw her throw towards the little prince? Wonder who the next Queen will be? ![]() | |
Re: Did you use the Windows installer [B]python-2.6.4.msi[/B] to install your version of Python? |
The End.