2,190 Posted Topics
Re: "row" is a string, and strings are immutable, i.e. can not be changed, so you have to catch the return and use it. [CODE]for row in open('C:\\test.xml','r'): if 'RecCount' in row: print row new_row = row.replace('RecCount','12345') print new_row [/CODE] | |
Re: We usually get the palindrome homework questions earlier in the year. To solve your problem, add some print statements at the very least: [CODE]s=input("Enter alphabetic characters: ") def palindrome(s): index=0 c=True while index<len(s): print "comparing", s[index], s[-1-index], "for index", index if s[index]==s[-1-index]: index +=1 print "returning True" return True print … | |
Re: You do not return the amount from getInput ([URL=http://www.python.org/dev/peps/pep-0008/]Python naming conventions[/URL]) so you have no amount to work with. Also, one function will suffice for deposits and withdrawals. This is an example only. [CODE]def deposit_withdrawal(this_task, amount, balance): if this_task == "d": return balance + amount else: return balance - amount … | |
Re: I'm not real sure either but perhaps something more on the line of (forgive the clumsiness of the code. I'm in a hurry)[code]def is_palindrome(string_in): if string_in[0] == string_in[-1]: return True, string_in[1:-1] return False, string_in ##---------------------------------------------------------- if __name__ == "__main__": s = raw_input("Enter palindrome string ") orig_s = s ok=1 while … | |
Re: Split on the comma and test for length. If the length is one, then a total was entered, otherwise it is a series of numbers. One alternative is to use [URL=http://www.ferg.org/easygui/easygui.html#-multenterbox]easygui[/URL], with one box for the total and a second entry box for individual numbers, so which ever box has … | |
Re: Should you be using "the_word", since that is what is returned from random_word()? | |
Re: Print projData, and type(projData) to see what it is. Read "Basics"[URL=http://hetland.org/writing/instant-python.html]in this page[/URL] especially the use of a for() statement, for some help with using lists. [URL=http://www.python.org/dev/peps/pep-0008/]Python naming conventions/style guide[/URL]. | |
Re: You might want to consider 2 [URL=http://en.wikibooks.org/wiki/Python_Programming/Sets]sets,[/URL] as the logic may be easier to understand. key_set = your current keys value_set = your current values, each one added as an individual item [CODE]for key in key_set: ## there are fewer keys than values if key in value_set: print key, "found" … | |
Re: [code] if timeholder != time:[/code]This will always be true on the first pass as timeholder is a string and time is a builtin class/module. Print type(time) and type(timeholder) to show this. [CODE] timeholder = time[/CODE]This statement then copies the time class to timeholder, so the two will always be equal … | |
Re: You should be getting an error in the sumsDivs() function because you return the variable "sum" which is never declared or defined, and is a reserved word so should not be used as a variable name. Also, you call sumsDivs(number), but never change the value of number within the while() … | |
Re: Print sql_key and that should provide some insight. You are creating a string, and not querying an SQL database, so [URL=http://docs.python.org/release/2.5.2/lib/typesseq-strings.html]string formatting[/URL] is required. The following assumes that all fields are strings and not integers or floats. [CODE]sql_key = "select company_name, param_key,com_value from key_financial_ratio where param_key = %s and com_value … | |
Re: If you can not use a built-in method to reverse the string (or list if you prefer), please state what the requirements are, otherwise: reverse_word = input_word[::-1] ## [begin:end:step=-1] | |
Re: I doubt anyone is familiar with cslgraphics, and would not have it installed. You will have to provide more info about the cslgraphics package. Also "Please help me with, creating an checker board" is way too vague to respond to. | |
Re: You have two different file pointers to the same file, one for reading and one for writing (and you open it again on every pass through the while() loop). The results are unpredictable for a situation like that. Read the file into memory and then close the file. You can … | |
Re: You would also have to test for the length of each item: [CODE]db = [["a", "b", "c"], ["apple", "bean", "cat"], ['d', 'e', 'f']] for each_list in db: output_list = [] for item in each_list: if len(item) > 1: print item else: output_list.append(item) if len(output_list): print "".join(output_list) [/CODE] | |
Re: [code]subprocess.call(['python link_config_idu12.py %s'%addr],shell=True)[/CODE]"addr" is not defined in the code you posted. [quote]But, i see that what i expect is not happening.[/quote]What does this mean? To set a list element, you access by the offset, i.e [CODE]test_list = [0, 0, 0, 0] print "Before", test_list for y in range(5): test_list[y] = … | |
Re: Start by getting the file name, opening it, and reading it one record at a time [URL]http://diveintopython.org/file_handling/file_objects.html[/URL]. Split each line into words and use a dictionary [URL]http://diveintopython.org/native_data_types/index.html#odbchelper.dict[/URL] to store each unique word. Once that is done, add a routine to use this dictionary to count the number of times the … | |
Re: [QUOTE]Is there something I am doing wrong?[/Quote]There is no way to tell what you are doing. You didn't post any code to comment on. Take a look at vegaseat's example [URL=http://www.daniweb.com/code/snippet216557.html]here[/URL] and see if it helps you. | |
Re: This is a linked list type of problem, where every question is linked to another for a yes or no response. Each question is assigned a unique number. It does not matter what the number is, it is just a unique identifier for each question. So you can have multiple … | |
Re: Use split and then join: [CODE]s = "abc def ghi jkl" split_s = s.split() print "\t".join(split_s) [/CODE] | |
Re: This will produce a unique number for each file name. [CODE]for ctr, fname in enumerate(files): print ctr, fname [/CODE] | |
Re: Also, calculate (p0 * math.e) once before the for() instead of every pass calculating it again. You should be using one for() loop, since they all do the same thing. [CODE]numeratorPos1 = 0 numeratorPos2 = 0 denominatorPos = 0 p0_math_e = p0 * math.e for x in range(0, n): y … | |
Re: You are coding the button callback incorrectly. When you produce 102 lines of code with no testing, it is very difficult to find which line is segfaulting amongst all that code. Apparently no one else wanted to sift through all of this either. For starters, break this up using functions … | |
![]() | Re: find() will locate a character [CODE]found = 0 while found > -1: found = text_to_output("\r") [/CODE] You can then use split() and/or replace to create the modified output. [CODE]print text_to_output.split("\r") [/CODE] ![]() |
Re: Usually that means that two items point to the same memory address, but without knowing more about "plant" (whether it is a string, list, etc.), and the same for Nplant (a list or list of lists?), there is no way to tell. Insert this code after appending, which prints the … | |
Re: self.itemEvens will contain the object for the last button created in the for() loop. Instead, store each individual button object in a dictionary or list. You can then delete whichever button object you choose. | |
Re: See examples for pickle [URL=http://www.doughellmann.com/PyMOTW/pickle/]here[/URL]. Pickle stores Python objects, like a dictionary. In order to load a pickle file, you first have to dump it in pickle format. So, first check that the file exists. Other than that, I have no idea what "[I] need help in the open function" … | |
Re: [QUOTE]but I am unable to get the latest version to compile[/QUOTE]What distro are you using as it is in most repositories. | |
Re: [QUOTE]is there a way for me to link the movie file to the text in the listbox[/QUOTE]Each listbox entry corresponds to a number, i.e. curselection returns the line number. You can link the number selected to a file using a dictionary. | |
Re: Hopefully we will evolve and continue the journey at some other "Earth", i.e. the end of humanity on this Earth. Perhaps not even in this time/space single continuum. We should also start a poll on what the next catastrophe will be once 2012 has passed. | |
Re: You should supply both the row and column to the grid [url]http://effbot.org/tkinterbook/grid.htm[/url] | |
Re: It is not clear whether you want to run a Python program that will populate icons which will then run other Python programs as subprocesses of the main program, or you want to launch desktops apps with the icon and use Python to generate those icons for some reason. Why … | |
Re: The first thing you have to do is decide which GUI toolkit you wish to code for as you will have to move, or destroy/remove the original rectangle graphic and draw/display it in a different location depending on the toolkit. A pretty standard example using Tkinter: [CODE]import Tkinter as tk … | |
Re: You should eliminate the pass-through functions. [CODE]class DemoImpl(QtGui.QMainWindow): def __init__(self, *args): super(DemoImpl, self).__init__(*args) uic.loadUi('K:\QTProjects\pos\mainwindow.ui', self) self.btnLogin.clicked.connect(self.createConnection) def createConnection(self): db = QtSql.QSqlDatabase.addDatabase('QSQLITE') db.setDatabaseName(':memory:') if not db.open(): QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Unable to establish a database connection.\nThis example needs SQLite support. Please read the Qt SQL driver documentation for information how to … | |
Re: Take a look at [URL=http://effbot.org/tkinterbook/entry.htm]Effbot's tutorial[/URL] for an entry box to find out how you set and get the text as there are at least two ways to do it. | |
Re: Also you are using "is" instead of equal. "is" tests for the same object, so can not be relied upon for an equal condition. Finally, the statement [CODE]else: if p is primes[len(primes)]: [/CODE] is unnecessary. The for loop takes care of that. So, you could use an indicator like this … | |
Re: The easiest way to do this is with a pass-through function. [CODE]from Tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() self.opt1 = Button(frame, text="Opt1", command=self.opt_1) self.opt1.pack(side=TOP) self.opt2 = Button(frame, text="Opt2", command=self.opt_2) self.opt2.pack(side=BOTTOM) def opt_def(self, opt): print 'You have choosen option', opt def opt_1(self): self.opt_def(1) def opt_2(self): … | |
Re: The following slightly modified code displays correctly for me on a Slackware Linux system. [CODE]import Tkinter def addmovie(root): addboard = Tkinter.Toplevel() addboard.title("Add a movie") addboard.geometry("600x600") #addboard(padx=10, pady=10) print "add" #adding the title lbtitle = Tkinter.Label(addboard, text = "Enter the movie's title:") lbtitle.grid(row = 1, column = 1) entitle = Tkinter.Entry(addboard) … | |
Re: [QUOTE] It also doesn't seem to be part of the QTGui module either, even though the Class reference says it is.[/QUOTE]If it is part of QtGui then you access it like this QtGui.QFileDialog.getOpenFileName(). There has to be hundreds of examples on the web that you can copy as well. | |
Re: [QUOTE] fileStats = os.stat(files) TypeError: Can't convert 'tuple' object to str implicitly[/QUOTE]This says that "files" is tuple. Print "type(files)" and files itself if you want to on the line before the error. | |
Re: Try [url=http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess]subprocess[/url] or [URL=http://www.noah.org/wiki/pexpect]pexpect[/URL] depending on what you want to do. | |
Re: First, do not read the entire file at one time, i.e. readlines(), instead: [CODE]for rec in open(file_name, "r"): if key in mydictionary: mydict[key]+=1 else: mydictionary[key] = 1 [/CODE]If that doesn't help then you will have to switch an SQL file on disk. SQLite is simple to use for something like … | |
Re: Would be great if you could sent a TV signal through this first with a routine to define and remove popups. We will probably be there some day soon. | |
Re: This is a simple dictionary with 'iamge' pointing to 'i am ge'. Most of the online tutorials cover dictionaries. | |
Re: This link is in "Similiar Threads" [URL=http://www.daniweb.com/forums/thread292949.html]Create a Python Dictionary From a CSV File using CSV Module in Python[/URL] | |
Re: You should first test that the button is active, as you may be trying to delete a button that doesn't exits. So, a dictionary to store the button makes sense as you can look it up before trying to delete. [CODE]import wx class Test: def __init__(self): app = wx.App(False) frame … | |
Re: I don't have a lot of time, but here is a simple example to start you, using Tkinter. The other GUI toolkits, WxPython and QT, would be similar. [CODE]from Tkinter import * root = Tk() root.title('Rectangle Test') canvas = Canvas(root, width =300, height=300) ## top_left_x, top_left_y, bottom_right_x, bottom_right_y points_list = … | |
Re: Generally speaking you open a new frame, not a new mainframe. There is no way to tell how the class is called from the sample, but you would access variables the same way as with any other class. [CODE]##--- Not tested class Window_Test(): def __init__(self): x=10 ## instance of the … | |
Re: Start with the second element and use index-1. Also, you should check for less than the first element as well as greater than the last element. [CODE]nums_list = [1,5,9,11,13,21,27,29,32] for index in range(1, len(nums_list)): if num > nums_list[index-1] and num < nums_list[index]: ## or if nums_list[index-1] < num < nums_list[index]: … | |
Re: Since there aren't any (or almost no) virus protection programs for Linux/BSD/Mac, and millions of users (especially in the server area), they would be a prime target if malware could be developed to target those OS's. It's an open door, but so far the few who have been able to … |
The End.