2,190 Posted Topics
Re: You use the same StringVar() if I understand what you want to do. Take a look at the following code and note how the StringVar() is declared and then attached to the second Label() and the Entry() box. Note that when the Entry() box changes the second Label() changes because … | |
Re: A simple test of the following code posted above shows that it will only find 'DTP' if it is at the beginning of the line. It should read as indicated. [CODE]f_in = ["xyz", "abcDTPxyz", "DTPabc"] for line in f_in: ## the if statement should read ## if line.find('DTP') > -1: … | |
Re: The answer is to develop good habits, one of which is to always use the complete path. It makes everything obvious. This also helps when you come back years later to debug a program because someone has moved something. | |
Re: There are so many examples on the web that I doubt anyone will respond. Try this link [url]http://lmgtfy.org/?q=tkinter+update+time[/url] | |
Re: A Python list will hold something like 2 trillion items, but is going to be pretty slow with a very large number or records in it. If your list is going to be 100 million records or more, then consider an SQLite database instead. If it's a paltry one million … | |
Re: [CODE]def find(): start = 1.0 while 1: find = text_to_be_found.get() [/CODE]It could be that you define "find" as a function and a variable. It could also be that "text_to_be_found" is not within the scope of the function. Print the result of text_to_be_found.get() and see if it is returning anything. | |
Re: [QUOTE]my code hangs or somehow don't write in the file[/QUOTE] Add some print statements to see where that is. A guess would be that it hangs because it can't find an address or something. There is nothing else to say as we don't even know what you mean by "client" … | |
Re: Your queries look fine, although I didn't go through all of the code. You may be looking for something that is not in the SQLite file. Design a smaller test program that looks for known items in the file so you can tell if it is the query language or … | |
Re: Roman to integer. Note that it will take something like XXIXV and convert it. If someone already has a routine to check for valid input, please post it. And I'm afraid we've just eliminated one standard homework question. Oh well, nothing lasts forever. [CODE]roman_to_decimal = { 'I': 1, 'V': 5, … | |
Re: The string "127558161.23" would not convert using the time module because it is not a 9 digit integer. Truncating the decimals yields the following result using gmtime() but is not close to the desired date and time. So it appears that the format is not "epoch second" which means a … | |
Re: From the PySQLite docs, a rather dated example; it allows case insensitive column access by name: [QUOTE]Highly optimized row_factory for column access by name ====================================================== A new function has been implemented that allows for case-insensitive column access by name with minimal performance and memory impact, unlike a dictionary or db_row-based … | |
Re: When someone presses the "Run" button, the callback would execute the code from the text-based program, either calling a function or class. You would of course have to import the other program as well. See the button widget here [url]http://effbot.org/tkinterbook/[/url] for info on callbacks. [QUOTE]yet choose the filename and directory … | |
Re: You would use threads, although I use multiprocessing so am not that familiar with threading but here is a link to Doug Hellmann's examples [url]http://www.doughellmann.com/PyMOTW/threading/index.html[/url] The kicker is that the variable used to store the downloaded link must be visible to all threads so the progress bar can calculate the … | |
Re: I would suggest using a dictionary with the individual records in file1 as the key pointing to a list of items found in the other files. | |
Re: It's not that difficult to roll your own. Check each character one at a time in each line and split and append to a list of lists as appropriate. [CODE]for ch in record: if ch.lower() in ["x", "y", "z"]: ## etc [/CODE] | |
Re: Look up the docs for sticky (you have to learn to help yourself). A hint is that there are no variables in your program named E, NE, etc. | |
Re: Try adding some print statements as below. [CODE]def file1(filename): d1 = dict() fp = open(filename) for line in fp: print "processing file1 line =", line process_line1(line, d1) return d1 def file2(filename): d2 = dict() fp = open(filename) for line in fp: print "processing file2 line =", line process_line(line, d2) return … | |
Re: [QUOTE]Problem: I get a double popped up dialog. Why is that? [/QUOTE]You would have to be calling it twice but without any code no one can help. Post a simple example. | |
Re: There was something similar on planet.python.org recently, and the suggestion was to help upgrade the documentation to get your feet wet and then move on to bug fixes. Contributing to the core of the language always looks good, as opposed to wrapping something that hasn't been done yet, i.e. it … | |
Re: Pass the class instance to the GUI program. An example with all classes in the same program. [CODE]import random class GUIClass: def __init__(self, class_instance): # create a text area named "textArea" # bind the function "OnEnterDown" to the Enter key self.ci = class_instance print self.ci.my_number, self.ci.my_word print "\n calling on_enter_down() … | |
Re: Try these simple functions, which just contain general SQL statements, and see what you get. This assumes that the table name is "postgres" (from your code") and the user name field is named "username" (again from your code). Since we don't know the table name or layout it is impossible … | |
Re: Some things that I see in datapull() [CODE]def datapull (username, password): ##-------------------------------------------------------------- ## cursor is never passed to the function ## and there isn't any db table named 'users' cursor.execute('select %s from users') % username ##-------------------------------------------------------------- ## dbcur is never passed to the function # ## and, username and password … | |
Re: You can read the entire file into a list, process the list once appending the record number to a dictionary of lists, with the "QA" field as the key. So if record #1 has QA=123 the dictionary would then be index_dict[123] = [1] for record #2 QA = 12 index … | |
Re: I've added a print statement which should clarify what you are actually doing. [CODE]p = [1, 2, 0, -1, 3, 4, 5] smaller = 0 bigger = 0 i = 0 while i < len(p): print "comparing", p[1], p if p[i] >= p: bigger += 1 print bigger i += … | |
Re: You could also replace the following: [code]reducedList = [n for n in listParagraph if len(n) == len(word)] ## replace with this reduced_list = [n for n in list_paragraph if word == n.lower()] if len(reduced_list): print "The word", "'" + word + "'", "occurs", len(reduced_list), "times in this section." else: print … | |
Re: You can use variables for this, if that is what you are after (untested code). [CODE]rotation_in = int(raw_input("Enter rotation ")) for el in rotationarray: if rotation_in == el[3]: print el for x in range(0, el[3]+1, el[4]): ## start, stop, step print x [/CODE] | |
Re: It helps to look at this pictorially. [CODE]0 1 2 3 4 5 6 7 8 9 10 11 <===== number in the list 1* 1 1 2* 2 2 3 4 4* 4 5 5 5 6 6* 6 7* 8 8 8* 9 9* 10 10* 11* [/CODE] … | |
![]() | Re: "filename" should contain the complete path, not just the file name. |
Re: You would use one separate class as a container for each item, containing the name, id, price, quantity, and any other info for that item. [CODE]class Item: """ contains all information for an item """ def __init__(self, ID, name, price, start_qty): self.ID = ID self.name = name self.price = price … | |
Re: If you are calling the programs from a Python program, you can simply pass the parameter as an arg to the program or to the function being called within the program. Subprocess works fine for this [url]http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess[/url] | |
Re: Note that #1 is "Create a new order". Start there. Are you going to use a GUI or the command line to enter the order? Once you have an order, then you have to store it either in memory or on disk, or both. Once you have the orders stored, … | |
Re: [QUOTE]My second condition is where all the columns have numbers in them.[/QUOTE]This would simply be an extension of your previous code. [CODE]def columns_full(x): """ Returns True if all columns are full Returns False if there are available spaces """ for col in range(5): if x[col][0] == "x": ## Not full … | |
Re: [QUOTE=tonyjv;1223002]Consider which of next words must be replaced if 'of' is in word list: [CODE]'''off shore switch off often "of course" of.'''[/CODE][/QUOTE] The simplest way to handle that is to use a dictionary of lists with the key being the length of the word and the list containing all words … | |
Re: You should re-think your logic for the first snippet. And please don't use "i", "l", or "O", especially when you are displaying programing snippets. There are 23 other letters. [CODE]def scanum(x): try: v=float(x) return x except: return False ret_val = scanum(0) if ret_val: print "True" else: print "False" [/CODE] | |
Re: [QUOTE] when moving (or tracing a line) between point A (with coordinates x1,y1) and B (with coordinates x2,y2).[/QUOTE]If you know how to get from A to B, can't you count the number of grids as you go. Assuming that each grid is the same size, you can then multiply, or … | |
Re: [QUOTE]Dictionary doesn't allow to sort the keys or values so in that case I need to transfer it to the list. Is it correct to do it this way?[/QUOTE]That is the way that it is usually done. In fact I can't think of any other way to order keys in … | |
Re: Try mechanize and see if that is any easier [url]http://wwwsearch.sourceforge.net/mechanize[/url] | |
Re: You would have to test each record for the specific info you want to keep, "Ship", "start_time", etc., and store it, probably in a dictionary. If the example you posted has not been "improved" for our readability then you can start writing once you hit *END*, headers first and then … | |
Re: [QUOTE]I tried to add more entry boxes and make them a difference size then the rest but using the width= under the if ipos: changes them all -__-. [/QUOTE]Just use a separate block of code to add the additional entry boxes that are a different size, or add a width … | |
Re: If you want to print one month and not keep the info, then use a list to store all of the values, monthly[0] += rainfall, etc. On the first day of a new month, print the results, zero the list, and start adding again. If you want to retain the … | |
Re: [QUOTE]Who would have ever imagined that John McCain will the best choice come this November.[/QUOTE]Whoever raises the most money wins. There are exceptions but very few. It appears that the Democrats are spending their money in the primary. So if McCain comes up with a right-wing vice presidential candidate and … | |
Re: [CODE]def sort(self, x):[/CODE] It is bad form to re-define reserved words like "sort" so use a more descriptive name (sort what?) and avoid the confusion. Also, you should include one function at a time and test it, then add another, etc. And why are all of the functions staticMethods? Perhaps … | |
Re: Sorry, but the question has to be more specific. For one thing, you want to use a loop to deal until the user says stop, so next you want a loop and some sort of input from the user. | |
Re: I would suggest that you print Dictionary to make sure that it is in the form you require. You only read the Search file one line at a time: [CODE]Dictionary = set(open("e:/assignment/dictionary.txt")) print Dictionary SearchFile = open(input("Please Enter a File Path: ")) WordList = set() ## WordList is a set … | |
Re: And you have to supply the path unless sample.txt is in your PYTHONPATH. [CODE]os.system("grep %s ./sample.txt" % variable) ## current directory [/CODE] | |
Re: I think you want to join() everything after the first sub-string if destination does indeed contain spaces, or simply split on the colon if you know that there is never more than one in the file. [CODE]for x in ["Branch: ltm_7.4\n", "Destination: Test 5\n"]: x = x.strip() substrs = x.split() … | |
Re: And no one has mentioned an SQLite file on disk because? You could also use dbm or anydbm if you don't want to try SQLite, but speed of these for that many records may or may not be a drawback. Also with these, each key has to be unique, but … | |
Re: As far as I can tell, both of these options work. [CODE]x=16 backslash = chr(92) part1 = '\x03\xa2' part2 = hex(x)[1:] command2 = "%s%s%s" % (part1, backslash, part2) command3 = part1 + backslash + part2 [/CODE] | |
Re: For future reference, a Google for "python find from one list in another list" listed this link among others [url]http://www.daniweb.com/code/post968722.html[/url] | |
Re: No testing is necessary. SQLite has been up and running for years and is fully reliable. Just write your code and go. |
The End.