2,190 Posted Topics
Re: The reason SchoolMember's __init__ is called to define self.name=name and self.age=age. You could also do this in the Teacher and Student classes. It doesn't matter where it happens as SchoolMember is inherited. I have changed the Student class to illustrate.[CODE]#!/usr/bin/python # Filename: inherit.py class SchoolMember: '''Represents any school member.''' def … | |
Re: Putting a quote around the field name works with SQLite. I don't know about MS Access. This is the well known example that has been changed to use a field name with a space in it (always a bad idea).[CODE]import sqlite3 as sqlite ##---------------------------------------------------------------------- def add_rec(cur, con): cur.execute("INSERT INTO test … | |
Re: You can also convert a1 and a3 to a set and use set intersection and difference. | |
Re: You can print the variables named operation, difficulty, etc. You will have to declare them first before the if statements, otherwise they only exist within the if statement's code block. print "\t\t\tWelcome to my Mathematics Game" operation="" difficulty="" Also instead of if difficulty == "Easy" or difficulty == "easy" or … | |
Re: I know nothing about twill, but find "EMail" in what? You would also have to give it a file name or a string, etc. to search in. You would want to tell it if you want a search or a match as well. Looks like Google time. Also, see if … | |
Re: If you are using raw_input or the variable is already a string, then try isdigit(). This of course assumes that you aren't using floating point numbers. If you are then you will have to use a try/except converting the string to a float.[CODE]get_num=raw_input("Enter a number ") print get_num, if get_num.isdigit(): … | |
Re: The list has to be in order, so sort it as the first statement in the function[code]def binarySearch(list1,faces): list1.sort() first = 0 last = len(list1) - 1 while first <= last: mid = (first + last) / 2 if faces == list1[mid]: return mid elif faces < list1[mid]: last = … | |
Re: Try running everything after "if name[-4:] == ".tif":" in a separate function. The memory should be garbage collected when the function exits. | |
Re: Also, take a look at pyprocessing which will run each in a separate process. [url]http://developer.berlios.de/projects/pyprocessing[/url] | |
Re: Pass m to the second script as a function parameter or to the __init__() function of the class. If that doesn't do what you want, post back.[CODE]m = Mine(2,3) m.PrintMe() m.ChangeMe(10,11) m.PrintMe() #Call to script SecondaryScript here.... SecondaryScript.foo(m) SecondaryScript.ClassFoo(m)[/CODE] | |
![]() | Re: Here is a link on how to import modules from the Dive Into Python online book [url]http://www.diveintopython.org/object_oriented_framework/importing_modules.html[/url] An online tutorial or book is a good way to start learning. When you just copy something and screw it up, you have no idea what to do, so the place to begin … |
Re: [QUOTE=docaholic;641823]the list being [23, 764, 12, 54, 83, 2, 543, 890, 1235, 453, 98][/quote] The easiest to understand is to use three new lists. In some kind of loop, append the first number to list1, the second to list2 and the third to list3. Rinse and repeat until the end. … | |
Re: First while list2[k] != -1: will never exit because -1 is not in list2 so you will always exceed the limits of the loop. Generally, this is done with a for loop.[CODE]list2 = [23, 764, 12, 54, 83, 2, 543, 890, 1235, 453, 98] stop = len(list2) for k in … | |
Re: First, you have a function to check the pin, but never ask for one. Also, you have to have some amount of money on file for known pins, so there has to be a dictionary or whatever that keeps track of the pin and the balance for that pin so … | |
Re: You can also use rfind to find the rightmost "-", which returns the location of the character. A slice using this location+1 will give you the string after the final "-", and you can use isdigit to tell if there are alpha characters.[CODE]def numbers_only(str_in): new_str="" if False == str_in.isdigit(): for … | |
Re: Try one of the online books or tutorials. This is a link to the "Dive Into Python" chapter on string formatting [url]http://diveintopython.org/native_data_types/formatting_strings.html[/url] | |
Re: And if you are using a list, then the individual variable for each random number isn't necessary.[CODE]computer_list = [] for j in range(0, 4): computer_list.append(random.randint(0, 30)) print "The computer's numbers are", computer_list # # # To enter all 4 numbers on one line, use the split method numbers = raw_input("Enter … | |
Re: range([start,] stop[, step]) -> list of integers I'm just guessing but the definition would have to be something like this, although the actual code may be in C/C++[CODE]def range_test(*args_in): if len(args_in) == 1: stop=int(args_in[0]) start=0 step=1 print "one arg found", start, stop, step else: ## compare for length==2 and then … | |
Re: Take a look at the control variables section at the following link. A control variable can be linked to several widgets and will update the widget automatically. [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/url] | |
Re: I would do something like this. Note that in your original code, the first word, "God", would never be found because you don't allow for a4==0.[CODE]a1="God Godess Borother Sister Family DemiGod" a1_list=a1.lower().split() a5=[] input_word=raw_input("PRINT A WORD ") for each_word in a1_list: if input_word in each_word: a5.append(each_word) print a5[/CODE] | |
Re: Unfortunately, threading or pyprocessing if the only way that I know [url]http://pyprocessing.berlios.de/doc/index.html[/url] | |
Re: Generally, /python/site-python is used for individual packages. You may have to create the directory, but then could place your other directories under this one, and assuming the system knows where /python is, you could then add the path /python/site-python to $PYTHONPATH or just append your other directories to sys.path. | |
Re: You can put as many lines as you want into a listbox. If there are more lines than the listbox will display, then you also want to add a scrollbar.[CODE]import Tkinter top = Tkinter.Tk() top.geometry( "100x100+10+10" ) top.minsize( 200, 200 ) listbox = Tkinter.Listbox( top, height=6, width=20, font=('Fixed', 14) ) … | |
Re: You can use sys.path.append() in each program to append to the PYTHONPATH if that is what you mean. It is difficult to understand what is going on without code. If this does not answer your question please post some example code or pseudo-code with an explanation of what each program … | |
Re: getch in Python is not easy. One implementation found on the web uses termios[CODE] import termios, sys, os TERMIOS = termios def getkey(): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO new[6][TERMIOS.VMIN] = 1 new[6][TERMIOS.VTIME] = 0 termios.tcsetattr(fd, TERMIOS.TCSANOW, new) c = … | |
Re: I don't use Tkinter but it doesn't print because the function "check()" has no idea what type1 is. Run the code below. I have changed check() so that it just prints "type1". It now knows what to print and so you get some output. I think you have to use … | |
Re: It appears from your code that MS Access is SQL. If so, you can use ORDERBY. A Google for "access orderby" should get you started. | |
Re: Use a dictionary with the key="ABCD". If the key is found in the dictionary compare the values. If the current rec has a lower value, replace the rec for that dictionary item. | |
Re: What you have done is the easiest way to do it because you have control. Remember that you have to parse the string no matter what the method. Even when Python has a method to do it, the string still has to be parsed, so you should have no problem … | |
Re: I would do it in a similiar way. Provided all of the pages can be stored in memory, the following creates a junk_list that stores pages until the next "ND" is found. It then prints the first and last pages in junk_list and blanks junk_list. You could also store the … | |
Re: There is no way to tell without code and a complete message but "AttributeError: 'ShortAnswerQuestion' object has no attribute 'question_id' " usually applies to a class (don't know if you use one or not). So instead of declaring a variable as self.question_id, it is defined as question_id and so is … | |
Re: line = file.readline() reads to the end of the file and then stops. Adding a "print line" statement after each readline[s] is the best way to tell what is going on. | |
Re: I don't use Tkinter much, but AFAIK you have to use threading for something like this. A simple example from effbot [url]http://effbot.org/zone/tkinter-threads.htm[/url] | |
Re: You can do this using sys.argv - use getDirPath.py 'mypath' and inside the program print sys.argv, type(sys.argv) As for drag and drop, Python is geared more towards a GUI, so you want FileDialog in Tkinter or QFileDialog in qt and the wx tool kit probably has something similiar, to select … | |
Re: You can use the split() method. substrs=line.split() if (substrs[0]=="call") and (substrs[1].startswith("%"): You will probably have to check for a length of 2 or more and may want to convert to lower case before comparing to "call", but that is the general idea. | |
Re: [QUOTE]out_file = open("address.txt", "w")[/QUOTE]Change this to out_file = open("address.txt", "a") You want to "a"=append to, not "w"=write over. And to start you out[CODE]if choice == 2: in_file = open("address.txt", "r") text = in_file.readlines() in_file.close() print text[/CODE] | |
Re: It's just personal preference, but I prefer to work with numbers in this type of code. So the following is an example of using the ord() of the character as the key in a conversion dictionary.[CODE]#!/usr/bin/python # -*- coding: utf-8 -*- x_list=[u'Ä', u'Â'] print ord(x_list[0]), ord(x_list[1]) ord_dic={194:'A', 196:'A', 197:'A', 199:'C'} … | |
Re: For completeness, list comprehension string="airplane" now_a_list=[x for x in string] | |
Re: If there are a lot of words to look up, use sets. They are indexed and are much faster than a list. reference_list=[ "AA", "AB", "BB", "AC", "BC" ] ref_set=set(reference_list) lookup_set=set(["AB", "BB", "CC"]) print lookup_set.intersection(ref_set) print lookup_set.difference(ref_set) | |
Re: A similiar question was recently asked. See if this helps. [url]http://www.daniweb.com/forums/thread128927.html[/url] | |
Re: Doug Hellman's module of week shows how to read output, and use stdin, stdout, stderr. Don't know if it will solve your problem or not, but if you can read it you can write to a file, send e-mail, etc. Some systems buffer the output, so you may have to … | |
Re: The dictionary principle remains the same. It doesn't matter if there are multiple words or just one word. dictionary key = what is in file = Store2 "Soap of Marseille" --> look up "Soap of Marseille" so store_dic["Soap of Marseille"] = "SOM" If you are unsure of punctuation, use isalpha … | |
Re: A few print statements should simplify things[CODE]import sys ##python ./myScript.py -b -e 'test_name' print sys.argv, "\n" file_found=0 for j in range(1, len(sys.argv)): print " arg", j, sys.argv[j] if not sys.argv[j].startswith("-"): print " name is", sys.argv[j] file_found=1 if (" -c" not in sys.argv) and (" -u" not in sys.argv): print "\n … | |
Re: Sorry for the late post. I just noticed this. Your button line should read self.connect(button, SIGNAL("clicked()"), self, SLOT("close()")) I'm thinking of doing a PyQt tutorial, or at least a list to links on using PyQt(4), thread on DaniWeb. Do you have any links that might be of interest? | |
Re: You can split and create new list with the numbers as the first part of the rec and then use the builtin sort method, or convert to a list of lists as below. Whichever is easier in this case.[CODE]data_as_lists = [ line.strip().split() for line in data ] ## convert to … | |
Re: Total price would be a separate variable that you add price to. If you want to process more than one person at a time and give a grand total, there would have to be a while loop somewhere in the program. | |
Re: Add some print statements. And I've formated your snippet with code statements in the way that I think it would have to be indented, but there is no way to tell.[CODE]def divide(dividend, divisor): n = dividend - divisor print "n =", n while n > 0: print "entering while statement" … | |
Re: Although I don't use wxPython, you should be able to use a dictionary to clean up the code. Something like this. Again I don't use this toolkit so it may require tuning.[CODE]import wx class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(450, 350)) hbox = wx.BoxSizer(wx.HORIZONTAL) … | |
Re: You want to search for wxpyton file dialog [url]http://www.wxpython.org/docs/api/wx.FileDialog-class.html[/url] |
The End.