4,305 Posted Topics

Member Avatar for mattloto

Using your example list [B]array=[['a','b'],['b','c'],['c','a']][/B] what do you expect the result to look like?

Member Avatar for vegaseat
0
1K
Member Avatar for wutwutwut

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 …

Member Avatar for vegaseat
0
210
Member Avatar for mattyd

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.

Member Avatar for TrustyTony
0
379
Member Avatar for The Dude
Member Avatar for kjock002

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 …

Member Avatar for Gribouillis
0
116
Member Avatar for gunbuster363
Member Avatar for kunal_00731

In the opening page of Python there is a big yellowish button near the top called appropriately [B]Start New Thread >[/B]

Member Avatar for vegaseat
-4
316
Member Avatar for deckchairboy
Member Avatar for bumsfeld
1
371
Member Avatar for Ronnicus

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 …

Member Avatar for bumsfeld
0
87
Member Avatar for ragavh

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]

Member Avatar for jcao219
0
170
Member Avatar for yesha27

[B]Jython[/B] comes to mind. It would allow you to run Python code under Java.

Member Avatar for jcao219
0
185
Member Avatar for Robbert

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.

Member Avatar for Robbert
0
88
Member Avatar for shusshoku
Member Avatar for pyprog

[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] == …

Member Avatar for vegaseat
0
143
Member Avatar for chazut

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]

Member Avatar for chazut
0
6K
Member Avatar for vegaseat

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 …

Member Avatar for Tcll
3
15K
Member Avatar for aot
Member Avatar for jozz3

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(',') …

Member Avatar for jozz3
0
113
Member Avatar for jozz3

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 …

Member Avatar for jozz3
0
2K
Member Avatar for Hoss212

[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)

Member Avatar for Murtan
0
148
Member Avatar for Simes

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]

Member Avatar for Simes
0
410
Member Avatar for john2oth

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]

Member Avatar for Gribouillis
-4
322
Member Avatar for jephthah

I think [B]Tom Gunn[/B] is an AI system that is down for the switch to Windows 7.

Member Avatar for jephthah
3
681
Member Avatar for ITgirl2010

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 …

Member Avatar for snippsat
0
165
Member Avatar for qwertyui
Member Avatar for GMUPATS

I assume you want to create a [B]item_id: [item_name, price, quantity] [/B] dictionary?

Member Avatar for vegaseat
0
89
Member Avatar for axa121

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), ...] …

Member Avatar for axa121
0
92
Member Avatar for jozz3

I would gladly help, but your question is hard to understand. Could you elaborate some more?

Member Avatar for vegaseat
0
111
Member Avatar for BestJewSinceJC
Member Avatar for pythonNerd159

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) …

Member Avatar for pythonNerd159
0
143
Member Avatar for Lylywhatever

Don't you think you should do something with your random x, y values? Please clean up your indentations.

Member Avatar for vegaseat
0
99
Member Avatar for duomaximus
Member Avatar for Lylywhatever

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: …

Member Avatar for Lylywhatever
0
381
Member Avatar for revellution

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" …

Member Avatar for revellution
0
124
Member Avatar for vegaseat

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 …

Member Avatar for Kanem
2
2K
Member Avatar for Lylywhatever
Member Avatar for Lylywhatever
Member Avatar for vegaseat
-1
105
Member Avatar for Mahen

You got that sort of backwards. First you find a customer with a problem, then you write the software.

Member Avatar for peter_budo
0
280
Member Avatar for ssmokincamaro

It might be worthwhile pointing out which of the many possible GUI modules you are using.

Member Avatar for ssmokincamaro
0
2K
Member Avatar for pythonNerd159

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 …

Member Avatar for pythonNerd159
0
134
Member Avatar for nasridine

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]

Member Avatar for vegaseat
0
95
Member Avatar for aks1810
Member Avatar for shivaaprs

Hint ... prime numbers are only divisible by unity and themselves (by convention 1 is not considered a prime number)

Member Avatar for vegaseat
-1
45
Member Avatar for jgehlot09
Member Avatar for leppapuu

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 …

Member Avatar for leaffan
0
1K
Member Avatar for pythonNerd159

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 …

Member Avatar for Alq Veers
-1
292
Member Avatar for SoulMazer

[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 …

Member Avatar for SoulMazer
0
159
Member Avatar for pythonNerd159
Member Avatar for pythonNerd159
0
128
Member Avatar for Ancient Dragon

Does that mean she threw her throw towards the little prince? Wonder who the next Queen will be?

Member Avatar for diafol
0
242
Member Avatar for larrywjr
Member Avatar for jcao219
0
244

The End.