2,190 Posted Topics
Re: A dictionary may be a better container than a list of lists. If you give each square a unique number, from 1-81, then the neighbors are simple to find. square -1 and +1 for this row square -9 and + 9 for this column (square -9) -1 and + 1; … | |
Re: It is easier to code than to explain. This will only work if you use a fixed width font. A proportional font would require more work. It is a little bit tricky in that you want to print one sub-list based upon the "b" in the previous sub_list. I have … | |
Re: Generally, the structure is more like this. [CODE]import time count = 0 PrevTime = time.time() while count < 1000: count +=1 print ("It took ", time.time() - PrevTime) raw_input() [/CODE]Using "==" in a loop is dicey in more complicated loops, as the counter could be incremented more than once. If … | |
![]() | Re: I think you could check for a number in the second position, if I understand correctly that overlays use numbers and updates/adds use a letter. [CODE]if len(line.strip()) and \ not line.startswith("Found") and \ not line[1].isdigit():[/CODE] ![]() |
Re: [CODE] base = Rectangle(p1,p2)[/CODE] Can you draw a rectangle with only 2 points? The simple way to do this is to have the house rectangle on the horizontal (set both x values to the same integer), then you just have to set the x from the door click to the … | |
Re: A Google coughed up pyq, a download for quotes from Yahoo, and there are sure to be others. This question would probably get more answers on a trading forum, as this one is for coding only. | |
Re: You have both class instances and class objects. The variables cartesian = dict() bondList = list() atomName = str() atomicNum = int() would point to the same variable (block of memory) for all instances of the class, where self.atomName = name self.atomicNum = atNum are unique for each instance of … | |
Re: That's called string formatting [url]http://www.python.org/doc/2.5.2/lib/typesseq-strings.html[/url] (assuming you are using Python 2.5). A simple example: [CODE]year = 1 pop = 12345 for x in range(2): print "Year %d population = %d" % (year, pop) year += 1 pop += 12345 [/CODE] | |
Re: For starters, you can use one function to do the output. Also, store the output strings in a dictionary. You can then use a for loop to go through the if intFCITC_list[0-->10]<0: and send the appropriate string and starting time to the function to print. I only did the first … | |
Re: [quote]Why does it fill every spot instead of only one?[/quote]Because every row is the same block of memory = fieldb [code]for i in range(columns): fieldb.append('.') for i in range(rows): fielda.append(fieldb) # # These will all be the same because they all point to the same memory location for row in … | |
Re: You really should consider using a class for this. Otherwise it gets real convoluted real fast. If you want some assistance, post back. | |
Re: If you wanted to draw a box on the screen and display some sort of message, you would have to access the memory on the video card. Before toolkits like Tkinter that is the way it was done. In simple terms, you would copy that part of the screen, blank … | |
Re: Use the min function to find the smallest number. Is it just me, or is there one person with 100 different ID's who posts every homework problem here, saying they don't have a clue==don't even try. If you are lost then there is very little we can do to help … | |
Re: This is a modified version of your program that prints what you expect. I am not sure if it is what you want or not. [CODE]def tryit(start, end): number = start ## number >= start ## number <= end length = 1 print number, '->', ## end+1 because length starts … | |
Re: 88282440 PKD0 Test that the first byte is a digit, split on the space if true, and test that the second element starts with a "P", then print everything that starts with a "D" that follows if I follow your description (which was not very clear). You can also store … | |
Re: It should be simple with Python's gstreamer interface. [url]http://pygstdocs.berlios.de/[/url] | |
Re: It is generally done with a list. [CODE]def test_input(input_str): accept_list = [] for x in range(0, 10): accept_list.append(str(x)) accept_list.append("d") accept_list.append("r") for character in input_str: if character not in accept_list: return False return True # # test it input_string = "a" print input_string, test_input(input_string) input_string = "3A3" print input_string, test_input(input_string) input_string … | |
Re: First you are not returning a dictionary. I've added a print statement to show that. Also, take a look at "returns" and "arguments" here [url]http://www.penzilla.net/tutorials/python/functions/[/url] for the "something" function. [code]def junk(f): d1 = {} d2 = {} for line in f: columns = line.split(":") letters = columns[1] numbers = columns[2] … | |
Re: [QUOTE]The get an error when i try to execute this?[/QUOTE] Not enough info for anyone to help (could be an indentation error, or could be in the calcs). First add some print statements for the individual calcs to isolate the error, and post the specific error message. [CODE]def distance_between_points(p1, p2): … | |
Re: That is usually a directory problem, i.e. it can't find something because it is not in the current directory. For this line, give it the absolute path name tune = mp.newMedia("/complete/path/Therock.wav") If that doesn't work, check that something is printed so you know the program was started. Finally, if you … | |
Re: Do you have to use something like queue_draw() to update the widget? The pygtk.org site has been down for 2 days now, so can't look it up, but try it and see. [QUOTE]Do You mean I have to give whole my code and/or a screenshot of my wxglade window? [/QUOTE]Just … | |
Re: FWIW this will find all occurrences of a word in a string. Also note that if you are looking for "the" it will give a hit for "then". If you only want the word, you have to search with spaces added, " the " -assuming string.lower() and that punctuation is … | |
Re: Wouldn't this lead to an infinite loop. [CODE]def Prime(x,y): n=2 if x == 1: Prime(x+1,y) elif x == 2: print (2) Prime(x+1,y) elif x <= 0: print ("Number must be a positive integer" else: while n < n+1: ## <=====[/CODE] | |
Re: [QUOTE]Also, is there anyway in Python that you can test whether or not a line of data is binary?[/QUOTE]All data is binary. That's the way the computer does it. I am assuming that you mean bytes that are not text. If you look at an ASCII table like this one … | |
Re: [CODE]finderGuess = finderGuess - ((((finderGuess*((1+finderGuess)^numberMonths))/(((1+finderGuess)^numberMonths)-1))- (monthlyPayment/loanAmount))/(((((1+finderGuess)^numberMonths)-1) (finderguess*(numberMonths*((1+finderGuess)^(numberMonths-1)))+ (1+finderGuess)^((finderGuess*(1+finderGuess)^numberMonths)* (numberMonths*((1+finderGuess)^(numberMonths-1)))))/ ((((1+finderGuess)^numberMonths)-1)^2)))) [/CODE]I hope you are the only one who has to deal with this code. It may help to remember that the compiler can only do one thing at a time, unless you have a multi-core machine and an OS that … | |
Re: [QUOTE]I thought this path was suppose to be set by default. it's not so i'm trying to set it.[/QUOTE]You can modify it on startup by adding PYTHONPATH to your ~/.bash.rc file, or create one if you don't have it. export PYTHONPATH=$PYTHONPATH:/path/to/add:/second/path | |
Re: [QUOTE]i am a beginner. i have no idea how i can make Tic Tac Toe game. please help me.[/QUOTE] Take on something that is easier first. If you have no idea at all on how to start, then there is little that anyone can do. | |
Re: Some corrections to get you started, provided the indentation is correct.[CODE]def encrypted_message(): ## "message" has not been defined in this function char = message encrypted_message = "" ## encrypted_message = "" from the previous statement for char in encrypted_message: x = ord(char) if char.isalpha(): ## "key" has not been declared … ![]() | |
Re: Start with something like this (Not Tested).[CODE]energyFile = open("EnergySources.csv","r") state_dict = {} for line in energyFile: line = line.strip() fields = line.split(",") state = fields[0].strip() if state == "State": ## you didn't give us any idea where state name comes from state_name = fields[???] state_dict[state_name] = fields[1:] elif not len(state): … | |
Re: You want to use "readlines()",as readline reads one line at a time, where readlines() reads all data. Also, a print statement is added for clarity.[CODE]records = open(grades.txt,'r').readlines() table = [] newtable = [] for line in records: line = line[:-1] r = string.split(line,':') ## table.append(r) ## for x in table: … | |
Re: This question is better asked/searched on Ubuntu's forums. The answer is something in the neighborhood of copying the 3.0 install and changing to 3.1, to or use apt-get's install from source-I haven't done it but this might help [url]https://lists.ubuntu.com/archives/ubuntu-users/2005-July/042275.html[/url] [url]http://www.debian.org/doc/manuals/apt-howto/ch-sourcehandling.en.html[/url] If you do install from source, (not the same as … | |
Re: This is very simple to do. [CODE]print len(set([1,2,4,2,7]))[/CODE] | |
Re: [QUOTE]This week's lab is to design a hangman game. Your program should be able to open a text file which contains a list of words (one word on each line of the text file) and read the words into a list to contain all of the possible words.[/QUOTE]If you don't … ![]() | |
Re: Google came up with this site which has a link to download source code. I hope you didn't pay $99.95 for the book! [url]http://www.jbpub.com/catalog/9780763746025/[/url] | |
Re: First, you have to decide which GUI toolkit you want to use. Here's an example Google found using Tkinter [url]http://code.activestate.com/recipes/124894/[/url] | |
Re: You can pipe top to a file on Linux and then read the file. Apparently you can use WMI for MS WIndows but I have not used it [url]http://timgolden.me.uk/python/wmi_cookbook.html#running_processes[/url] | |
Re: Always use absolute path+file names.[CODE]filePath = "Dataset/parameter feature vectors" for fname in os.listdir(filePath): complete_name = os.path.join(filePath, fname) data_str = open(complete_name).read() index = data_str.find("female") if index != -1: females.append(index) print fname else: print "append the ones that aren't female to a males"[/CODE] | |
Re: When validating, you want to include, not exclude. So you want a list of data that is acceptable, and the input has to be in the list. That way, when another unit or type of data is introduced it is automatically an error. If your program excludes, then the new … | |
Re: Since you are testing 6 letters total, you want to use "len(w)-5" so you won't run out of letters. To set up an example using "aabbcc" as the simplest example, you only want the for loop to test the first letter. It will test a->a, b->b, and c->c. If you … | |
Re: You want to use a class structure for this, so each player can be an instance of the same class, and divide the code into several small functions. [QUOTE]Also, I don't know why but I can't input more than 3 armies for the attacking army, and more than 2 for … | |
Re: [QUOTE]I still don't understand why not 1 and not 2 and not 3 is the proper way to do this[/QUOTE]Alternatives would be: [CODE]while (play_choice < 1) or (play_choice > 3): while play_choice not in [1, 2, 3]: # Also, you can use .lower instead of 2 compares while play_again.lower() == … | |
Re: You can set the encoding for the file fp = codecs.open('test', encoding='utf-8', mode='w') Or you can change the default encoding for the system sys.setdefaultencoding('utf-8') You may have to use encode/decode, see here [url]http://farmdev.com/talks/unicode/[/url] | |
Re: Using for() loops is easier. This is somewhat of a brute force method but works fine for smaller lists. [CODE]L1=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] L2=[1,2,3,4,11] L3=[] for number in L2: for a_list in L1: if (number in a_list) and (a_list not in L3): L3.append(a_list) print L3 ## ## You can also delete from the … | |
Re: [QUOTE]Does anyone know how to change border colour of a widget [/QUOTE]Border colors, AFAIK, are the same as the widget color, so you would have to use an outside, empty widget of one color, and an inside widget of another color, although that is not quite what you want. The … | |
Re: This will get you started, but a dictionary would work much better for this. [CODE]elif stChoice == 2: for stock_list in portfolio: print "symbol = %s for %s" % (stock_list[1], stock_list[0]) rmv = raw_input("Type in the ticker name for the stock you wish to remove. ") for stock_list in portfolio: … | |
Re: [QUOTE]return an error message if the values entered aren't either the strings 'on' or 'off'[/QUOTE]Can you use a list instead of all of those variables? Otherwise, try the code below which tests each button individually instead of the confusing and, and, or, etc. in your code. Speaking of testing each … | |
Re: [QUOTE]Is there some way I can display the 'escape characters'[/QUOTE] Escape characters are generally < decimal 32 and > decimal 127 (in English), but you may have to adjust for your character set. This works for me.[CODE]# -*- coding: utf-8 -*- test_file = [ "about, approximately περίπου cinema σινεμά (το)", … | |
Re: This is a forum for the Python programming language. Your question should be asked at the swarmplayer site, or on a board for the distro that you are using. | |
Re: [QUOTE]self.database.execute('INSERT INTO contacts (fname) VALUES (null,?),' [fname]) AttributeError: 'contact' object has no attribute 'database'[/QUOTE]It means that you have not declared "self.database" anywhere in your program, and the interpreter does not know if it is a variable, file pointer, another class, etc. |
The End.