2,190 Posted Topics

Member Avatar for Ghostenshell

Pass the "driver" to a class function which appends to the list. The same for deleting from the list. You should try to keep all methods within the class.

Member Avatar for griswolf
0
156
Member Avatar for jayzee1989

squares() never saves or prints the perfect squares within the while loop, (or tests if the arg "num" is ever found as a perfect square if that is what you want to do. I can't tell as there are no comments in the code). Add a print statement which will …

Member Avatar for TrustyTony
0
109
Member Avatar for janaka_17

Take a look at [URL=http://hetland.org/writing/instant-python.html]this tutorial[/URL], especially the references to "self".

Member Avatar for woooee
0
89
Member Avatar for Ghostenshell

[CODE] 1 2 3 4 5 6 7?? The book has an example of 7 * 4 = 4 + 4 + 4 + 4 + 4 + 4.[/CODE]I hope that's a typo on your part, otherwise you should find another book. Sorry, couldn't pass that one up. You want …

Member Avatar for TrustyTony
0
143
Member Avatar for sss33

Next, read each record in the file and print it. After that, split each record and print that. Then decide how you can use this data.

Member Avatar for vegaseat
0
136
Member Avatar for KrazyKitsune

A simple example using Tkinter's after feature. You would probably want after to call a clean-up function to check for partial entries, etc., and then call quit(). [CODE]import Tkinter class TestClass(): def __init__(self): self.top = Tkinter.Tk() self.top.title("Test of Timing") self.top.geometry("200x150+10+10") label_1 = Tkinter.Label(self.top, text="Timer Test ").pack(side="left" ) entry_1 = Tkinter.Entry(self.top, …

Member Avatar for wikirifi
0
4K
Member Avatar for kerimabdullah

Griswolf's code assumes that you are looking for empty items in the list. If instead, you want to remove spaces within an item, i.e remove the space in "word1 word2", post back. [CODE]# help 2 I want to shorten below codes how to ## ## same as Griswolf's code: use …

Member Avatar for TrustyTony
0
126
Member Avatar for kumar_k

Please post what you have so far and some sample data. There is no point opening the file, etc. if you already know how to do that. Usually you would read the file one line at a time, strip the record of spaces and the newline, and then split the …

Member Avatar for kumar_k
0
142
Member Avatar for jimmy9pints

Same old, same old = add some print statements to tell you what is going on. [CODE] def fac(a,b): #defining the function that uses Euclid's method ctr = 0 while b>0: ctr += 1 a, b = b, a%b # changing the numbers a to b, and b to remainder …

Member Avatar for jimmy9pints
0
126
Member Avatar for noniterum03

Try to import Tkinter by itself to see if the problem is with Tkinter or matplotlib, or TCL & Tk are not installed. What is a "port install". Those packages should come pre-built from the standard Mac repositories. Generally speaking, a problem like this occurs when the library is installed …

Member Avatar for woooee
0
160
Member Avatar for danholding

[QUOTE]for lastmod_seconds, val in date_file_list:[/QUOTE]Obviously you should print at least part of date_file_list. No one here has ESP AFAIK, so no one can discern the contents of date_file_list, but what happens if no file is found. [CODE] date_file_tuple = lastmod_seconds, file date_file_list= tuple(date_file_tuple) date_file_set = set(date_file_list) date_file_list = list(date_file_set) """ …

Member Avatar for woooee
0
419
Member Avatar for doffing81

[QUOTE=doffing81;1330541]Let's create a continuing thread to program Crazy 8's from scratch for learning purposes! [B]DECK/CARD IDEA'S[/B] My simple starting suggestion: [CODE]deck = ['2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC', '2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD', '2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH', '2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS',][/CODE][/QUOTE]Start by downloading one of the existing packages, like [url]http://duo.tuxfamily.org/lang/en/about[/url] and look at the code. If you don't understand something, then post the question and …

Member Avatar for doffing81
0
1K
Member Avatar for AnnetteM

At one time there was a third party package named BitBuffer to work with binary files. I don't know if it is still around and maintained or not. You can also use [URL=http://docs.python.org/library/array.html]array[/URL] [CODE]filename = "binary_number.py" a_long = array.array('H') fp = open(filename, 'rb') a_long.fromfile(fp, 1) print a_long a_long.fromfile(fp, 1) print …

Member Avatar for woooee
0
4K
Member Avatar for bettersaid

You have to kill the process, and how you do that is dependent on the OS you are using. You should use subprocess instead (see os.kill() at [URL=http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess]Doug Hellmann's site[/URL]).

Member Avatar for bettersaid
0
78
Member Avatar for dustbunny000

And/or is two different things. If you want "a" or "b" then if either one is true the code is executed (the other can be false). If you want "a" and "b", the code is executed only if both are true. "And" is the same as two if() statements, "or" …

Member Avatar for TrustyTony
0
102
Member Avatar for pythonbegin

There are several different ways to do this. One is a dictionary pointing to a list that contains the number of records found for the key, and the thresholds found to test if greater than (if I am reading the question correctly). You could also use two dictionaries, one as …

Member Avatar for TrustyTony
0
104
Member Avatar for Wumbate

You can use update_idletasks() [CODE]import time from Tkinter import * class MyApp: def __init__(self, parent): self.myParent = parent ### (7) remember my parent, the root self.myContainer1 = Frame(parent) self.myContainer1.pack() self.button1 = Button(self.myContainer1) self.button1.configure(text="Button") self.button1.pack() self.button1.bind("<Button-1>", self.button1Click) self.lbl = Label(self.myContainer1) self.lbl.pack() self.button2 = Button(self.myContainer1) self.button2.configure(text="Quit", background="red") self.button2.pack() self.button2.bind("<Button-1>", self.button2Click) def button1Click(self, …

Member Avatar for D33wakar
0
29K
Member Avatar for dustbunny000

"z" is the same as a print statement will verify, although newx and newy do change. [CODE]for n in range(10): ## only print 10 times print "adding math.sin(%f) to %f" % (z, newx) newx=newx+math.sin(z) print "adding math.cos(%f) to %f" % (z, newy) newy=newy+math.cos(z) print newx print newy ## ## note …

Member Avatar for TrustyTony
0
78
Member Avatar for marcom10

Test with known numbers producing a known output to check your calculations. [CODE]##--- this statement print 'Monthly Payment:', '$',loan * rate * 1 + rate ** 12 / 1 + rate ** -1 ## ## is the same as --> there is no reason to multiply loan * rate times …

Member Avatar for woooee
0
116
Member Avatar for Synthuir

[QUOTE]time.sleep(), however, pauses the entire .py, rendering the ping/pong lines irrelevant and ultimately leading to a ping timeout.[/QUOTE]If I understand the question, you would use threading or multiprocessing to run the code that you don't want to sleep/pause. Since it runs as a separate process, time.sleep() won't affect it.

Member Avatar for lllllIllIlllI
0
237
Member Avatar for aspro648

Pass x to the file2 function. [CODE]from file2 import * x = 6 file2Funct(x) ## ##file2.py ## def file2Function(x): print x [/CODE]

Member Avatar for woooee
0
186
Member Avatar for toll_booth

You want to associate each button with a Tkinter StringVar. That way, you set (change) the contents of the StringVar and it is automatically displayed on the screeen. This is the start of a Tic-Tac_Toe game, to test button use, that I never finished. It uses a dictionary to keep …

Member Avatar for toll_booth
-1
140
Member Avatar for doffing81

See this link for a tutorial on input [url]http://www.pasteur.fr/formation/infobio/python/ch04s03.html[/url] and then test the integer for >0 and <6 to break from the while() loop.

Member Avatar for snippsat
0
101
Member Avatar for viandante

[QUOTE]I want to display in a treeview or listbox what I have in Sqlite[/QUOTE]I use [URL=http://code.activestate.com/recipes/52266-multilistbox-tkinter-widget/]MultiListbox[/URL] for that.

Member Avatar for woooee
0
890
Member Avatar for pythonstudent

You can also use some indicator that switches on and off for print positive or negative. [CODE]counter=1 positive = True while counter < 9: if positive: print counter else: print counter * -1 counter += 1 positive = not positive ## switch it [/CODE]

Member Avatar for cghtkh
0
106
Member Avatar for _neo_

Take a look at the [URL=http://docs.python.org/library/traceback.html]trackback docs[/URL]. You possibly want traceback.format_exc() or extract_tb(traceback[, limit])

Member Avatar for _neo_
0
272
Member Avatar for csguy11

[QUOTE]The error message, and not the error type, were of great help.[/QUOTE]i.e. include the entire error message (which usually shows the offending line). [CODE]""" ------------------------------------------------ Also, this code can be simplified Dictionary key lookup is simply if key in dictionary_name: """ ------------------------------------------------ self._inverted_index = {} #dictionary ## ... ## ... …

Member Avatar for TrustyTony
0
486
Member Avatar for KrazyKitsune

Sub/superscript is done by the program displaying the text, and different programs have different ways of doing it. The Tkinter text widget, for example, uses offset (positive is super, negative is sub).

Member Avatar for woooee
0
94
Member Avatar for jyothics23

I assume that you open the port, send the string, and read any returned bytes somewhere else in the code. Check out the PySerial [URL=http://pyserial.sourceforge.net/shortintro.html]intro[/URL] and see if it would work for you. There is no point in reinventing the wheel when you have packages that are already tested and …

Member Avatar for Tech B
0
2K
Member Avatar for matkod

Please mark this thread "solved" so the helpful volunteers don't waste their time reading a solved thread.

Member Avatar for woooee
0
7K
Member Avatar for xtra333

You don't have if 1 in self.myranks[kitten] and 1 in self.myranks[kat]: in any of the code you posted. Is there more than one version of this program? It apparently thinks that self.myranks[kitten] or [kat] is an integer. Do a print type(self.myranks[kitten]) before the offending line and see what prints. Then …

Member Avatar for xtra333
0
2K
Member Avatar for Tenck

The book teaches Python 2.x. In Python 3.x, print is a function, so the last line would be print(buildConnectionString(myParams)) In the future please include the actual error message, as it is almost impossible to debug when a program is larger, without knowing exactly what is wrong. [URL=http://diveintopython3.org/]Dive Into Python 3[/URL] …

Member Avatar for snippsat
0
287
Member Avatar for a007s

HelloCallBack is first defined as a variable, then as a function. [CODE]class Application(Frame): helloCallBack = None def helloCallBack(): tkMessageBox.showinfo ("Hello", "Hello, do you like my application?")[/CODE]Neither is correct, you want it to be a member of the class. Note also that you can not use both grid and pack, so …

Member Avatar for a007s
0
3K
Member Avatar for gunneronaspooky

I would suggest learning [URL=http://www.freenetpages.co.uk/hp/alan.gauld/tutfiles.htm]file read/write[/URL]. Then you can put 101 numbers in the file and read the file to test, instead of entering 100 numbers every time you want to test.

Member Avatar for gunneronaspooky
0
133
Member Avatar for Peter_TARAS
Member Avatar for Peter_TARAS
0
11K
Member Avatar for udev

For starters, break your code into smaller pieces and test each piece before moving on. As you have found out, debugging 96 lines of code is not easy. This line should be tested first as it does not do what you think. [CODE]##--- test this with a known value (word='the') …

Member Avatar for udev
0
128
Member Avatar for Hawkeye Python

"/ 730" has to be a float (or you have to convert somehow). [CODE]##1.0 - 2.718281828**(-(23**2)/730) a = 23**2 print a a *= -1 print a print "---------------" print a/730 a /= 730.0 print a print "---------------" b = 2.718281828**a print b print 1.0 - b [/CODE]

Member Avatar for vegaseat
0
275
Member Avatar for funfullson

[QUOTE]I want make relation with gsm modem.[/QUOTE]We don't know what this means. If you want to communicate via a serial port, check out USPP and PySerial, but however the signal enters your computer, you will have to have an interface to the port.

Member Avatar for nazza
0
195
Member Avatar for sphynx_25

As you probably have guessed by now, regular expression are considered bad style by some and so learning them is possibly a complete waste of time. If you aren't aware of Jamie Zawinski's (in)famous quote "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now …

Member Avatar for sphynx_25
0
2K
Member Avatar for sphynx_25

I would start with [URL=http://pypi.python.org/pypi/Scripy/0.9]Scripy[/URL] You can also use subprocess. Doug Hellmann has a nice write-up covering input and output pipes amount other things [url]http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess[/url]

Member Avatar for sphynx_25
0
238
Member Avatar for pythonbegin
Member Avatar for pythonbegin
0
1K
Member Avatar for pleasecompile

You can use [URL= http://docs.python.org/lib/module-array.html]array[/URL] or [URL=http://pypi.python.org/pypi/BitBuffer/0.1]BitBuffer[/URL] An eample using array [CODE]import array a_long = array.array('f') ## float (was 'L' for long hence var name) fp = open(fname, 'rb') a_long.fromfile(fp, 1) print a_long a_long.fromfile(fp, 1) print a_long fp.close() [/CODE]

Member Avatar for pleasecompile
0
453
Member Avatar for khess

Don't forget that the NSA maintains SELinux (maybe someone should tell the British Navy). I would guess that a study is the first step in the process towards moving away from expensive, proprietary software. A member of Congress would not really stand up and say "I think we might save …

Member Avatar for nmstategov
0
483
Member Avatar for patton228

You can/should use a dictionary for the values, although the code you have is fine if it works and you understand it. An example: [CODE]## replace the later code with a dictionary # A dictionary of lists. List elements are # position 0=price, 1=hinges, 2=latch, 3=stop # 4=screw gate, 5=eight …

Member Avatar for patton228
0
156
Member Avatar for dankiller94

You have to have a separate list of winning combinations, so one of the combinations would be ([0,0], [1,0], [2,0]) which would be 3 down if all 3 positions are either "X" or "O". Another way to do this is to number the squares and store each position in a …

Member Avatar for woooee
0
180
Member Avatar for koveras vehcna

All variables in create_mail are local to create_mail and can not be used in send_mail. One solution is to use one function only, which simplifies things. See [URL=http://www.penzilla.net/tutorials/python/functions/]here[/URL] for a starter on how to use funtions.[CODE]def create_mail(message): themail = MIMEMultipart() recipient = "xxxxxxx@hotmail.com" gmail_user = "asdassdsaadssd" gmail_pwd = "asdasdasasdasasd" subject …

Member Avatar for koveras vehcna
0
322
Member Avatar for linuxoidoz

[QUOTE]What's the Python function/method/whatever to destroy an object?[/QUOTE]Most of the tutorials for qt3 (if that is what you are using), use sys.exit(). [CODE]import sys import qt class MyWidget(qt.QVBox): def __init__(self, parent=None, name=None): qt.QVBox.__init__(self, parent, name) quit = qt.QPushButton("Quit", self, "quit") quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.SLOT("quit()")) lcd = qt.QLCDNumber(2, …

Member Avatar for raptr_dflo
0
16K
Member Avatar for koveras vehcna

[CODE] longestSentence = max((listOfWords for listOfWords in listOfSents if any(lt == word.lower() for word in listOfWords)), key = len) #get longest sentence -list format with every word of sentence being an actual element- longestSent=[longestSentence] for word in longestSent:#convert the list longestSentence to an actual string [/CODE]Break down the list comprehension …

Member Avatar for koveras vehcna
0
186
Member Avatar for acejhon

Divide by 3, multiply the result by 3, and compare to the original number, assuming that you are using integers only.

Member Avatar for woooee
0
80
Member Avatar for Laurence26

There is no way to tell since the code you use to import is not included. Here is a link to the "Dive Into Python" chapter on import [url]http://diveintopython.org/object_oriented_framework/importing_modules.html[/url]

Member Avatar for umbuty
0
172

The End.