2,190 Posted Topics
Re: [QUOTE=;][/QUOTE] Try [CODE]if userInput in ['r', 'R']: # ----- or ----- if userInput.lower() == "r": [/CODE] | |
Re: I used a for loop just for a little variety. And I would also think it should be (but that is just my opinion) [CODE]p p l l aa <-- not reversed cc <-- reversed e e s s [/CODE] | |
Re: [QUOTE]tuple_dict = {} receives "TypeError: unhashable type: 'list'"[/QUOTE] I would suggest that you print the values and note also that a list can not be used as a dictionary's key. If that is indeed what you want to do, convert to a tuple first. [CODE]def histogram(s): tuple_dict = {} ## … | |
Re: [QUOTE=;][/QUOTE] And please do a reasonable number of tests of your code before posting. This is a truncated version of the function to point out the error: [CODE]def isprime(n): for ctr in range(2,n): ## do not use 'i', 'l', 'O' as they can look like numbers if n%ctr==0: return 'Not … | |
Re: This code can be simplified. [CODE]if 2 <= c_no <= 10: gpa(c_no) # ## replaces, (and note that the "pass" does nothing) if c_no==2: #if the no of courses inputed is 2 gpa(2) elif c_no==3: #if the no of courses inputed is 3 gpa(3) elif c_no==4: #if the no of … | |
Re: The "self.deck.deal([player])" would be a good place to check except self.deck, self.deck = BJ_Deck(), does not have a deal() function. Generally you want to check every time before you deal or hit as you will also catch it if the burn card or the hit card reduce the deck to … | |
Re: [QUOTE=alokdhari;1515806]n yea... m new to python !![/QUOTE]This is not high school nor does anyone want to become a personal assistant for the lazy [url]http://tinyurl.com/6eavfzu[/url] | |
Re: What does the function normDistProb return? The first attempt to debug this should be to print it [CODE]for i in range(0,12): listProbFog.append(normDistProb(dayValues[i], fogAve[i], fogVar[i])) print normDistProb(dayValues[i], fogAve[i], fogVar[i]) print listProbFog # the other lists are just extra cruft until you get this problem solved [/CODE] | |
Re: [QUOTE=;][/QUOTE] You have to retrieve and store the RadioButton object. This code stores the grid() object: [CODE]# Radiobutton(canvas, variable=xy, value=x,command=self.move).grid(row=row,column=column) # # instead use # self.rb =Radiobutton(canvas, variable=xy, value=x,command=self.move, image=xxx.) self.rb.grid(row=row,column=column) # using "row" and "column" as names is confusing # # and then self.rb.configure(image=yyy) [/CODE]For configure options see [url]http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tk/button.n.html[/url] | |
Re: [QUOTE=;][/QUOTE] Split() each record. Don't use the first element of the list, join([1:]), in the first file. And, similarly, don't use the last element in the second file. | |
Re: [QUOTE=;][/QUOTE] [QUOTE]there are 31 days in the month so i'm trying to take the last 5 days in this case[/QUOTE]That would be something along the lines of: [CODE]print range(32)[-5:][/CODE] | |
Re: [QUOTE=tonyjv;1510895]Use 'quotes as outer quotes or double the " inside quotes.[/QUOTE] What space? [CODE]str_out = 'cat /home/myfile.txt |grep -m 1 "my game" ' ## ^<-- this space??? proc = subprocess.Popen([str_out], stdout=subprocess.PIPE, shell=True) # # in Python found = False for rec in open("/home/myfile.txt", "r"): if (not found) and ("my game" … | |
Re: Try it the other way around? [CODE]inCur = gp.SearchCursor(myFeatureClass2,'COLLECTED_BY = "%s"' % (str(Name)), \ "", "", "DATE_COLLECTED A") [/CODE]Generally, the name is also stored as "obrien" so you can find O'Brien, O'brien, Obrien, etc. I don't know if this is possible here or not. | |
Re: Also, form the habit of using a list instead of if/elif. It is more straightforward as all of the conditions are on one line. And verb[-2:] is just shorthand for verb[-2:len(verb)], just as verb[:-2] is shorthand for verb[0:-2]. [CODE]verb = input("Write the verb here: ") if verb[-2:] in ['ar', 'er', … | |
Re: [QUOTE=;][/QUOTE] A second dictionary is not required. Create a tuple containing item1 and item2 and look up in the dictionary. If found, you have a match. If you want to keep the keys in the same order as the file, use the [URL=http://code.activestate.com/recipes/107747-ordered-dictionary/]ordered dictionary[/URL]. For Python 2.7 it is in … | |
Re: If you are confident that the string is not wrap- ped around (on 2 lines), then reading the file one record at a time and searching it is the accepted way to go. You have to look at every character in the file no matter how you do it. | |
Re: You must install the version of PIL for the Python version that you have on your system. You are trying to install PIL for Python2.6. Python2.6 can not be found on your system. Keying "python -V" (capital V, not lower case) on the command line will give you the Python … | |
Re: [QUOTE=;][/QUOTE] An example for splitting a sentence [url]http://www.java2s.com/Code/Python/String/Asentenceissplitupintoalistofwords.htm[/url] | |
Re: [QUOTE=;][/QUOTE] You never exit the "while True" so it is an infinite loop. Once you eliminate that, you should be able to print the final word_list list which will be a series of numbers. Sort the list and count each of the sequences of the same number. You should also … | |
Re: [QUOTE=;][/QUOTE] I am aware of 2 existing packages, [URL=http://www.parallelpython.com/]parallel python[/URL] and [URL=http://github.com/mattharrison/coreit]coreit[/URL], but haven't tried either. Let us know how it goes. | |
Re: [QUOTE=;][/QUOTE] You want to start testing at the third element & checking the prior two. What you have will error because when the last element is reached, there is no +1 (also do not use "i", "l", or "O" as single digit variables as they can look like numbers). [CODE]## … | |
Re: You should state what it is you want to do. No offense but there are other solutions and perhaps someone here can come up with a workable solution. Generally you would use (although I can't really understand what you are asking): [CODE]class myClass: def __init__(self, methodName="This is the result"): self.methodName … | |
Re: [QUOTE=;][/QUOTE] Isn't nodeTable a list of classes? So you would access it like this: [CODE] for node in nodeTable: #if node != 0 and Node.visited == False: #nearestNode = node[theNetwork] #listOfNeighbours.append(nearestNode) print node.distFromSource, node.previous. node.visited [/CODE]That is if your class is constructed correctly, which it is not, so that is … | |
Re: [QUOTE=;][/QUOTE] You have to define current distance from source, or distance for pairs, i.e. from node1 to node2 = x, node2 to node3 = y, etc. | |
Re: [QUOTE=;][/QUOTE] [QUOTE]1) change the button sizes to be all the same size (buttons are labeled decrease, surrender, remain, etc...) [/QUOTE]You can use width and height on buttons the same way as done with Text in your program. Reference sites [URL=http://infohost.nmt.edu/tcc/help/pubs/tkinter/index.html]here[/URL] and [URL=http://effbot.org/tkinterbook/]here[/URL][CODE]from Tkinter import * class PreferencesWindow(object): def __init__(self, master): … | |
Re: Split on "study", or a normal split on space(s) will also work as the number.txt will be -1, or the study's description will be everything except the last element. | |
Re: [QUOTE=;][/QUOTE] A second way is to use a StringVar(). See the "textvariable" write up at [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/button.html[/url] | |
Re: You can't combine grid() and pack() but must use one or the other. Also, AFAIK, one radio button must be selected (a default selection or you can't choose 'none' when using radio buttons), and the others can be deselected. [CODE]from Tkinter import * class App: def __init__(self, parent): self.my_parent = … | |
Re: You will have to put trace points in your program to see where it is hanging. I doubt it is here. Also, do not use "list" as a variable name as it is already used to name a function that returns a list, and that could be the problem because … | |
Re: These are quotes for anyone who hasn't heard of Steven Wright. # "I spilled spot remover on my dog. Now he's gone." # "I stayed up all night playing poker with tarot cards. I got a full house, and four people died." # "I'm living on a one-way dead-end street. … | |
Re: Code tags added. [QUOTE=Dogge3;1493407]I want to create a function wich prints all numbers over 1000000. So the user can input for example 500 and that dosent print but if you input 1005000 it prints. My code far is. [/QUOTE] [CODE]v = [600,6300330,47, 1000001] for x in v if x >1000000: … | |
Re: There is a discrepancy in these 2 statements. Is preorder a list, so preorder[0] can be None, or is preorder a string, i.e the second statement below? [CODE] if (preorder[0] or inorder[0]) is None: if preorder is not None: [/CODE] | |
Re: Run the input files one at a time, i.e. run the program using the first file and check the output, then run the program again using the second file and check the output file, etc. | |
Re: Use a for() loop with step=3. [CODE]DNA= "ATCGATCGATCGATC" for ctr in range(0, len(DNA), 3): print DNA[ctr:ctr+3] [/CODE] | |
Re: The health variable would be the same as the location and inventory variables. Using a class makes this simple. Instead of "money", "rope", "shiny_stone", etc. I would suggest using a dictionary. [CODE] vars_dict = ["money":[0, "5 dollars sits upon the dresser."], "rope":[0, "a pile of tangles rope is in the … | |
Re: [URL=http://www.doughellmann.com/PyMOTW/socket/multicast.html]Doug Hellmann's[/URL] write-up. | |
Re: Test the code you have before posting it here. For example, in the Deck class, there is an indentation error, and the variable "c" [c = Card(rank, suit)] is an instance of the class Card. To access the rank and suit from the Deck class, you would use self._cards[ctr].rank and … | |
Re: I'm not sure I understand your question but if you want to use multiple class instances, one per dog, try something like this. [CODE]if __name__ == "__main__": dogs = list() dog_name = "" first_inp = "Name: ('quit' to exit) " second_inp = "Breed: " while dog_name.lower() != "quit": dog_name = … | |
Re: [QUOTE]However,i only can not figure out.....am I stupid??stupid logic?? can anyone help me?It is urgent..[/QUOTE]No one cares if you are stupid or are stupid twice and have waited 'till the last minute. Ask a specific question. For starters, break this into functions. For example, use one function to choose a … | |
Re: Sorry, I don't have must experience with that. I only use SetBackgroundColour, etc. | |
Re: [QUOTE]try and convert the value from the numctrl to a decimal[/QUOTE]You can not convert a float to decimal.Decimal because floats are inaccurate past a certain number of digits. You will have to get/enter the value as a string and convert. | |
Re: It is getting difficult to tell if something is a duplicate. What always runs but never walks, often murmurs, never talks, has a bed but never sleeps, has a mouth but never eats? | |
Re: To be complete, Linux requires style=wx.TE_PROCESS_ENTER [CODE]import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, -1, mytitle, size=mysize) self.SetBackgroundColour("white") s = "Enter the price:" label = wx.StaticText(self, -1, s, pos=(10,10),) self.edit = wx.TextCtrl(self, -1, pos=(10, 30), \ size=(100, 25), style=wx.TE_PROCESS_ENTER) # respond to enter key when focus is … | |
Re: Use a while() loop that checks for the answer. Also, you should print what options are available as an answer instead of making the enterer guess. This is not intended as a complete answer. [CODE]while intro not in ["yes", "no"]: intro = input("Want to play a game of number guess? … | |
Re: You should use a dictionary for all queries, deletes, etc. %s opens the DB to SQL injection.[CODE]c.execute("select titre, code, date from codes where id=:d_key", {"d_key":idrow}) x=cur.fetchall() # # multiple select fields c.execute("select titre, code, date from codes where id=:d_key and col=:d_col", {"d_key":idrow, "d_col":column_var}) # c.execute("delete from codes where id=:d_key", {"d_key":idrow}) … | |
Re: join() interleaves a list with a constant so self.currentOutDir.join(self.counterStr) would produce self.counterStr[0]+self.currentOutDir+self.counterStr[1]+self.currentOutDir+self.counterStr[2]...etc. A simple example: [CODE]x = ["1", "2", "3"] print "a".join(x) # x = "123" print "b".join(x) [/CODE] | |
Re: You would first compare the ID returned to record[0], the original ID. If it has changed, you can use UPDATE [CODE]cur.execute("UPDATE People SET SQL_id_tag==:update_id", {"update_id": new_id_variable}) con.commit() [/CODE] | |
Re: This just says that there is no column in the DB named "a.sequence". There is no way to tell any more from a single line of code. | |
Re: You are obviously not passing the ball object to Bounce ([URL=http://www.python.org/dev/peps/pep-0008/]Python naming conventions[/URL]), so look at the places that call Bounce and see if the ball object is actually being passed. | |
Re: [QUOTE]The errors I receive: shutil.copy(files, dest)[/QUOTE]Print "files" and "dest" somewhere in the program, also type(files), type(dest); [QUOTE]TypeError: cannot concatenate 'str' and 'list' objects[/QUOTE] to see which is not a string |
The End.