2,190 Posted Topics

Member Avatar for thatoneguyx

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 …

Member Avatar for thatoneguyx
0
105
Member Avatar for dinilkarun

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 …

Member Avatar for woooee
0
1K
Member Avatar for MikeyFTW
Member Avatar for SUBHABRATAIISC

You can also convert a1 and a3 to a set and use set intersection and difference.

Member Avatar for woooee
0
83
Member Avatar for MikeyFTW

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 …

Member Avatar for woooee
0
120
Member Avatar for aditi1184

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 …

Member Avatar for aditi1184
0
393
Member Avatar for linkrulesx10

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(): …

Member Avatar for linkrulesx10
0
5K
Member Avatar for docaholic

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 = …

Member Avatar for woooee
0
71
Member Avatar for Edwards8

Try running everything after "if name[-4:] == ".tif":" in a separate function. The memory should be garbage collected when the function exits.

Member Avatar for woooee
0
435
Member Avatar for ALPHA_Wolf

Also, take a look at pyprocessing which will run each in a separate process. [url]http://developer.berlios.de/projects/pyprocessing[/url]

Member Avatar for woooee
0
187
Member Avatar for tzushky

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]

Member Avatar for woooee
0
87
Member Avatar for leegeorg07

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 …

Member Avatar for jlm699
0
105
Member Avatar for docaholic

[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. …

Member Avatar for woooee
0
84
Member Avatar for Mazille

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 …

Member Avatar for Mazille
0
1K
Member Avatar for muddpigeon

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 …

Member Avatar for teddies
0
229
Member Avatar for dinilkarun

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 …

Member Avatar for woooee
0
418
Member Avatar for krazineurons

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]

Member Avatar for krazineurons
0
156
Member Avatar for LaurenceB

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 …

Member Avatar for LaurenceB
0
90
Member Avatar for Wumbate

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 …

Member Avatar for woooee
0
157
Member Avatar for Agni

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]

Member Avatar for woooee
0
197
Member Avatar for SUBHABRATAIISC

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]

Member Avatar for ssharish2005
0
86
Member Avatar for tzushky

Unfortunately, threading or pyprocessing if the only way that I know [url]http://pyprocessing.berlios.de/doc/index.html[/url]

Member Avatar for tzushky
0
150
Member Avatar for bitmaster20

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.

Member Avatar for bitmaster20
-1
158
Member Avatar for mg0959

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) ) …

Member Avatar for woooee
0
2K
Member Avatar for devstudio.2007

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 …

Member Avatar for woooee
0
94
Member Avatar for FreezeBlink

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 = …

Member Avatar for FreezeBlink
0
190
Member Avatar for gertblue

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 …

Member Avatar for woooee
0
280
Member Avatar for webamateur

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.

Member Avatar for woooee
0
96
Member Avatar for dr_kac

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.

Member Avatar for paddy3118
0
191
Member Avatar for reyev

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 …

Member Avatar for reyev
0
138
Member Avatar for parmenio79

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 …

Member Avatar for rikxik
0
90
Member Avatar for ankuj.gupta

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 …

Member Avatar for woooee
0
87
Member Avatar for franziss

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.

Member Avatar for woooee
0
157
Member Avatar for alexisellis

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]

Member Avatar for lllllIllIlllI
0
127
Member Avatar for reyev

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 …

Member Avatar for reyev
0
164
Member Avatar for indu_shreenath

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.

Member Avatar for bvdet
0
106
Member Avatar for inkcoder

[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]

Member Avatar for inkcoder
0
102
Member Avatar for edholden

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'} …

Member Avatar for edholden
0
257
Member Avatar for cheechand

For completeness, list comprehension string="airplane" now_a_list=[x for x in string]

Member Avatar for lllllIllIlllI
0
72
Member Avatar for cheechand

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)

Member Avatar for woooee
0
113
Member Avatar for simionpetrus

A similiar question was recently asked. See if this helps. [url]http://www.daniweb.com/forums/thread128927.html[/url]

Member Avatar for woooee
0
45
Member Avatar for ms_melagiri

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 …

Member Avatar for woooee
0
499
Member Avatar for elhallouf

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 …

Member Avatar for elhallouf
0
162
Member Avatar for elhallouf

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 …

Member Avatar for woooee
0
83
Member Avatar for dangermini

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?

Member Avatar for woooee
0
4K
Member Avatar for dr_kac

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 …

Member Avatar for bvdet
0
139
Member Avatar for jhartley3

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.

Member Avatar for slate
0
106
Member Avatar for jhartley3

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" …

Member Avatar for slate
0
110
Member Avatar for dinilkarun

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) …

Member Avatar for woooee
0
567
Member Avatar for Fuse

You want to search for wxpyton file dialog [url]http://www.wxpython.org/docs/api/wx.FileDialog-class.html[/url]

Member Avatar for woooee
0
408

The End.