2,190 Posted Topics
Re: This may be a good time to learn to use a class as it works much better for this type of program. Here is some simple code to get you started. If it is easier to understand, you could also use a dictionary to hold the deck of cards, with … | |
Re: Take a look at Vegaseat's example of moving rectangles using canvas. [url]http://www.daniweb.com/forums/thread147502.html[/url] | |
Re: A personal preference would be to use a list for the printed portion.[CODE]word = "alphabetical" ## simulate getting a word from the file guess_list = [] for j in range(0, len(word)): guess_list.append("_") # # Ask for a guess, etc. # Guess is incorrect guess_word = "".join(guess_list) print guess_word # # … | |
Re: This is the errant code. If it finds any file that fulfills the requirements, the whole path is zipped (and is re_zipped multiple times if more than one file is found). Perhaps you want to append the file name to a list, and zip those files only. You could also … | |
Re: [QUOTE]I would like to know if there is an easier way than what I just did[/QUOTE]Would raise red flags for a beginning homework assignment like above, but you can use operator to sort on any list element[CODE]import operator data = [ 'kick me 989', 'bodybody 344', 'Santa Clause 0943', 'Bart … | |
Re: Here is link to a good summary with examples, it's Part 1 of ?. [url]http://www.ibm.com/developerworks/linux/library/l-python3-1/index.html?ca=drs-[/url] I'm using print() instead of print in 2.5 to re-train, and that simple thing is more difficult than it should be. Guess I will buy a 3.0 book when a good one comes out and … | |
Re: Using a simple if[CODE]test_file = [ 'User-Agent: Googlebot', '#Disallow: /', 'Disallow: /comments', 'Disallow: /user', 'Disallow: /poll', 'Disallow: /print', 'Disallow: /search', '', 'User-Agent: Cogger', '#Disallow: /', 'Disallow: /comments', 'Disallow: /user', 'Disallow: /poll', 'Disallow: /print', 'Disallow: /search', '', 'User-Agent: ia_archive', 'Disallow: /comments', 'Disallow: /user', 'Disallow: /poll', 'Disallow: /print', 'Disallow: /search' ] found_list … | |
Re: Just an educated guess, but you would have os.system call the pdf browser with the file name (but this is on Linux). os.system('Acrobat c:\resume.pdf') | |
Re: Which tutorial are you using? I have never seen it used with import MySQLdb but it may be that I just don't know about that alternative way. | |
Re: There is also xvkbd, but it is a console program and so is accessed via: os.system('xvkbd -test "string to type" ') [url]http://homepage3.nifty.com/tsato/xvkbd/[/url] | |
Re: [QUOTE]i have highlighted part of the code,were it stops.[/QUOTE]What does 'stop' mean? What is the error message? The message will tell you what the problem is. Also, you want to consider breaking the program into functions so you don't have one large mess that you can't figure out. A good … | |
Re: It should be pool = 30 The [] turn pool into a list and you want an integer variable. | |
Re: First, here is the way I __think__ your code looks when properly formatted.[CODE]#!/usr/bin/python ##import string ## string is deprecated import re import random import sys import time import fileinput tn = time.time() t = str(tn) ss = "5571" lv = open("/usr/local/https/data/session1.txt","r") lvr = lv.readlines() l_lvr = len(lvr) #print lvr l_list … | |
Re: I get errors on the following line because there is no file on the first pass through the program. So you should first get the program to run properly if there is no file found, without manually changing the code, .[code]a = Petty(p.load(f))[/code]and the following lines yield a name not … | |
Re: You could also get the python version print sys.version_info and then use the appropriate "print input_var" or "print(input_var)" depending on whether version is > 2.5. | |
Re: First, if this is just a one-time thing for you, you can use Links to download and save the page as text only. [url]http://www.jikos.cz/~mikulas/links/download/binaries/[/url] Also, I assume you know about BeautifulSoup and that is more than you want. To answer your questions 1. Stops after 10 iterations (as the saying … | |
Re: [QUOTE]it now makes the last word the longest?[/QUOTE]Add some print statements and you should be able to see what is going on.[CODE]for word in splicedsent: print "\ncomparing word %s, length=%d, longest=%s" % \ (word, len(word), longestLength) if len(word) > longestLength: longestword=word print "length > longest is true"[/CODE] | |
Re: This part prints the usage blurb and exits if you don't include usage options on the command line. "h", "t", and "a" are the usage options and are directly below the quoted code.[CODE]def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h:t:a") except getopt.GetoptError: usage() return[/CODE] | |
Re: As has already been hinted, you are probably expected to use 2 lists. The first contains letters and the second contains the number for the corresponding letter. You could also use a list of lists, with each sub-list containing the letter and number, but that is probably more than you … | |
Re: I've flagged this as a bad post. Since this is the first time, hopefully it was done correctly. This was the message: This post is from someone who posted a link to their homework assignment, with no attempt to code anything themselves, and then asked for the answer. Further, they … | |
Re: Assuming that the server belongs to your ISP, you want to first ask them if Python is supported. It usually is, and they probably have some examples of the types of things they allow. Unlike using IDLE, the program file would be run from the command line or another program … | |
Re: If it is easier to get your head around, you can use a dictionary of lists, with the dictionary key as the row number, each containing x columns. You could also take this one step further and use a dictionary of dictionaries with row and column number as keys.[CODE]def populate_array(rows, … | |
Re: Note the last line [QUOTE]_mysql_exceptions.ProgrammingError: (1146, "Table 'router.table_name' doesn't exist")[/QUOTE]It is looking for "table_name" not the contents of the variable. So you want to insert the actual name which can be done in a number of ways along the general line of the following. This is just your statement with … | |
Re: [CODE]binary = int(raw_input("Enter a binary number:")) for i in range(binary): print "for loop is testing", i, "in range", binary if (binary != 0 or binary != 1): print binary, "not equal to 0 or 1" binary = int(raw_input("Enter a binary number:")) else: print binary, "equal to 0 or 1"[/CODE] | |
Re: I've added some print statements so you can see what is going on. First, the file name used for the zip file output is printed to make sure you are using the correct file name (if you submit "C:\\Test\\ZipDir" then the output file will be under "C:\\Test\\" and will be … | |
Re: Instead of the seek method, you could also use a dictionary to assign a number to each word, and then pick a random integer and print the word associated with that integer. IMHO it is preferable to use numbers whenever possible as that is the native language of the computer.[CODE]from … | |
Re: For the first part, use a class and declare variables that are global within the class. Classes are included in Python for a reason. You will want to use a class for programs that go beyond one simple function. For example:[CODE]class TestClass: def __init__(self, input_a): self.A=input_a ## global self.B=0 ## … | |
Re: I use a class 99% of the time. Once the program gets beyond the simple function level, it organizes the code IMHO. Also, a class doesn't have any of the global variable problems. | |
Re: I would suggest the following print statements to clarify things.[CODE]print "length of self.__fields =", fieldlength for counter1 in range(fieldlength): if self.__fields[counter1] == field: print "counter1 == field" for counter2 in range(rowlength): #print self.__rows[counter2][counter1] if self.__rows[counter2][counter1] == value: return1 = counter2 matchcount = matchcount + 1 print "The Match count is … | |
Re: [QUOTE]But now I want to be able to save it in file, preferably in form like this: number;name[/QUOTE]It's a simple combination so a common text file will work just fine. There is also the advantage of being able to verify what you have written to the file via any text … | |
Re: Also, you open the file and read the entire file for each ID entered. This is time consuming (in computer time) and so you should consider reading the file once and placing the records in a dictionary, indexed on ID, and using the dictionary to look up the info as … | |
Re: You're making it too difficult. Store the previous record in memory.[CODE]prev_line = "" for line in infile: linesplit = line.split(",") line = line[:-1] if line startswith("Line"): write stuff if line startswith("$GPGGA"): calculate and write stuff if line startswith("EOL") outfile.write("%s\n" % (prev_line)) <========== ## copying = last thing in this loop … | |
Re: [QUOTE]Installing setuptools... Downloading [url]http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c8-py2.6.egg[/url] <===== BAD URL - try it yourself Traceback (most recent call last): File "<string>", line 267, in <module> File "<string>", line 198, in main File "<string>", line 146, in download_setuptools File "/usr/local/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/local/lib/python2.6/urllib2.py", line 389, in open … | |
Re: You don't initialize Total2 to zero for each run through the outer loop[CODE]#sum each 5 fields over the raw: for step in range (6, N, 5): Total2=0 <-------------------------- for i in range (step-5, step, 1): Total2 += float(fields2[i]) # do something print i, step, Total2[/CODE] | |
Re: [QUOTE]I cannot use pytesser for this[/QUOTE]Why not? The odds of finding someone who would start from scratch instead of using existing code is pretty small. Look for something that exists (is proven) and can use whatever image format you have, as the code would have to process a given image … | |
Re: You could also split, subtract 3 (for the end fields) from the length of the sub-string list, which would yield the number of elements to join for the city name. Providing each record is exactly the same. Or, you can start from the other end yr=substrs[-1] q3_2008=substrs[-2] q3_2007=substrs[-3] | |
Re: You would use a dictionary as a container. The key would be the time stamp. Each key would have a list that would be initialized to something like ["*", "*", "*"], assuming there aren't any "*"s in the file. The first file would replace the first "*", or zero element, … | |
Re: The easiest way to understand it is to break each part down and give it a separate variable name.[CODE]""" dictFoldersNew = {"A":{"XYZ": [["Name1", "UID1"], ["Name2", "UID2"]], "PLM": [["Number1", "UUID1"], ["Number2", "UID2"]], "RST": [["ID1", "UUID1"], ["ID2", "UID2"]]}, "B": [["IDB1", "UID1"], ["IDB2", "UID2"]], "C": [["IDC1", "UID1"], ["IDC2", "UID2"]], "D": [["IDD1", "UID1"], ["IDD2", … | |
Re: Enumerate is one way to do it.[CODE]for ctr, word in enumerate(words): word = clearup(word) if word not in dictionary: print "%s : line %d" % (word, ctr)[/CODE] | |
Re: I use JEdit and BlueFish. JEdit is the only editor that I know of that allows you to configure the cursor. If you are going back and forth to the screen, it is difficult to pick up that single flashing line, so I like the transparent box cursor, in a … | |
Re: Or you could append a copy of the list [CODE]import random # faces of a dice dice = [1, 2, 3, 4, 5, 6] rolls = [] for k in range(3): random.shuffle(dice) #test print dice rolls.append(dice[:]) # test print rolls # """ My test [5, 2, 4, 6, 1, 3] … | |
Re: You might also want to consider a dictionary, with the guess as the key, and the Yes/No response as the value. It's simplier to understand in this case IMHO. Also, in the following code snippet, you don't use "i" for anything. That is you perform the same exact compare for … | |
Re: [QUOTE]which came first, the chicken or the egg?[/QUOTE]Dinosaurs laid eggs, so eggs. Why does Hawaii have an interstate highway system. Why do we park on the driveway and drive on the parkway. | |
Re: You want to take another look at the error message as you would not get to the input statement. The program will stop at "def main()" and "def getfibnum()" Also, take a look at this statement firstnum = 1 = language firstnum can either equal 1 or language, but not … | |
Re: First try "import Tkinter" with a capital "T". If that doesn't work, post the code you used and an exact copy of the error message. If you have to install, install python-pmw. It will install TCL, Tk, and Tkinter as dependencies if they aren't installed, and you will likely want … | |
Re: You can use a variable named something like self.red_light_on. Set it to True when the light changes to red, and False on a change to green or yellow. Then[CODE]if not self.red_light_on: canvas.move(car1,x,0) canvas.update()[/CODE] | |
Re: You want to use a counter, incremented by +1, to access that element of each one of the lists. This can be done in fewer lines of code but this is the easiest to understand.[CODE]combined_list = [] stop = len(list_1) for ctr in range(0, stop): junk_list = [] junk_list.append( list_1[ctr] … | |
Re: If you run the above code, it will not work as expected. You want if shipweight <= 2: as the first if, and the following elif's should use and elif shipweight >2 and shipweight <6: Also, what if the weight equals 6? This code doesn't allow for that. BTW, the … | |
Re: Definitely use a dictionary or SQL database if there are a lot of entries. It is hundreds or thousands of times faster depending. The time consuming part of the code is looping through the list twice. Using a try/except to check the list once with no "in" statement is a … | |
Re: I would take a look at the following lines. In the first line of code, "i < 100 and 255", what is "and 255" supposed to do? Also, I would add the print statement before the second line of code to see what is happening. [CODE]# select regions where red … |
The End.