2,190 Posted Topics
Re: 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. | |
Re: 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 … | |
Re: Take a look at [URL=http://hetland.org/writing/instant-python.html]this tutorial[/URL], especially the references to "self". | |
Re: [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 … | |
Re: 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. | |
Re: 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, … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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) """ … | |
Re: [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 … | |
Re: 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 … | |
Re: 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]). | |
Re: 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" … | |
Re: 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 … | |
Re: 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, … | |
Re: "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 … | |
Re: 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 … | |
Re: [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. | |
Re: Pass x to the file2 function. [CODE]from file2 import * x = 6 file2Funct(x) ## ##file2.py ## def file2Function(x): print x [/CODE] | |
Re: 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 … | |
Re: 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. | |
Re: [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. | |
Re: 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] | |
Re: 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]) | |
Re: [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 ## ... ## ... … | |
Re: 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). | |
Re: 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 … | |
Re: Please mark this thread "solved" so the helpful volunteers don't waste their time reading a solved thread. | |
Re: 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 … | |
Re: 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] … | |
Re: 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 … | |
Re: 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. | |
Re: Try either destroy or withdraw on the old label and see if it does what you want. | |
Re: 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') … | |
Re: "/ 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] | |
Re: [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. | |
Re: 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 … | |
Re: 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] | |
Re: Create 2 lists, one per column, and use the shuffle function of random on both, | |
Re: 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] | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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, … | |
Re: [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 … | |
Re: Divide by 3, multiply the result by 3, and compare to the original number, assuming that you are using integers only. | |
Re: 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] |
The End.