2,190 Posted Topics
Re: You can use a class to do that in the following way. You could also use a list or dictionary as a container for the 10 variables and pass one list/dictionary instead of 10 variables. IMHO using the class method is preferred. [CODE]class test_class: def __init__(self): self.a="dog" self.b="cat" self.c=1 print … | |
Re: As stated previously, it is difficult to tell without code tags (use the "#" in the icon list). One problem is the two lines below: one is the function definition and the other is the calling line of that function. It is unlikely that this is the problem however. It … | |
Re: os.path.walk has a callback function. Note this is untested code. Now that you know what to look for it should be fairly easy to find examples.[CODE]import os def processDirectory ( args, dirname, filenames ): print 'Directory',dirname for filename in filenames: print ' File',filename # top_level_dir = "/usr/local" os.path.walk(top_level_dir, processDirectory, None … | |
Re: You want to use .set() but it must be with a Tkinter control variable. Look for the paragraph that starts with "For example, you could link an Entry widget to a Label widget" and the "Entry" paragraph at this link. The New Mexico Tech Tkinter pages are well done. [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html[/url] | |
Re: os.system should work if you just want to run a command. If that doesn't work then subprocess is the next step up. os.system("perl test.pl -testconfig <config file> > test.log 2>&1") | |
Re: ctn_no has to be an integer instead of a string-note that all of the dictionary indexes are now integers and not strings so that you have to use an integer to find something in the dictionary. Also, if ctn_no can not be converted to an integer, you will get an … | |
Re: Key "python" into a terminal. If you get the python prompt (>>>) then you have Python installed. Ctrl-D exits python. Most distros will have it installed in /usr/bin, so you can also check for a /usr/bin/python2.x file. | |
Re: Have you tested the code below to see if it does what you think. I don't know myself but it is unclear at best and if you have to explain it, will you be able. The following untested code breaks it down into steps[CODE]def leap_year(self, year): if (year % 4 … | |
Re: [QUOTE]i get to down as far as the tax equation and it won't run, [/QUOTE]And you'll have to be more specific. "Won't run" does not say enough and where in hell is the tax equation. Include the error message at the very least (which I am sure is a syntax … | |
Re: [QUOTE]Firstly, I can't get the '\n' from the line before putting it in a list.[/QUOTE]I don't think "firstly" is a word, but I'm not sure. var=var.strip() will remove all whitespace before and after the text for the variable var. Whitespace is spaces, tabs, newlines, etc. As for the "too many … | |
Re: GUI's are specific to the OS. What GUIs are available for the IPod and how are you packaging your programs. I don't know what's available for IPods but if there is something like py2exe, you may be able to enbed the graphics in the executable. Also, TCL/Tk/Tkinter, GTK et all … | |
Re: Is it defined as a CollapsiblePane, see here [url]http://www.wxpython.org/docs/api/frames.html[/url] You can also check with the wxpython mailing list if you don't find an answer here [url]http://www.wxpython.org/maillist.php[/url] | |
Re: There are no doubt other and probably better ways to do this, but try print url.split("/") You want the 3rd item, or result[2]. You can then add it to a list or dictionary if it is not already in the list or dictionary. | |
Re: You can also read all of the file into memory, process it once to search for the string, and then process it a second time to write it to a file if necessary.[CODE]data = open(filename, "r").readlines() found = 0 for rec in data: if ("sa001:" in rec) or ("SA001:") in … | |
Re: KDE and Gnome both have startup options in the menu. If you are using some other desktop manager then you may have to add it to /etc/init.d depending on which Linux distro you are using. | |
Re: When the users makes a choice, i.e. choice = input("What do you wish to produce?")-1 you should test for bounds. (choice < 1) or (choice > max) would yield an error and ask the user to choose again. | |
Re: Did you find a solution to this? If not, ask on the Ubuntu forum [url]http://ubuntuforums.org/forumdisplay.php?f=39[/url] You probably have to install one of the libcairo or libcairo dev packages. | |
Re: I am assuming that every other record is a county followed by population housing location. This is how to use a readline() loop, (and is untested code):[CODE]def process_county(r_list): print "County =", r_list[0] print "Housing Loc =", r_list[1] fp=open(filename, "r") r_list=[] rec=fp.readline() ##county rec while rec: r_list.append(rec) rec=fp.readline() ## housing rec … | |
Re: How is the swipper connected to the computer. If it is through a serial port, then you can use pyserial and detect when there is data in the serial port to be read. Without more info there is no way to help. | |
Re: Not too many people will open an attached pdf file. What is wrong with plain text and posting it with the thread? It can't be that long. This is the Dr Python forum which will likely know more about this. [url]http://sourceforge.net/forum/?group_id=83074[/url] | |
Re: I almost never read a thread that starts with "Please help me". It is too vague to even bother with. This was one of the results of a google for "python ascii" . You can also use the ord() function (google for it) on each character to see if the … | |
Re: Or put them both in the same dictionary. There is only 100 or so-times 2[CODE]# small dictionary of chemical symbols symbol_dic = { 'C': 'carbon', 'H': 'hydrogen', 'N': 'nitrogen', 'Li': 'lithium', 'Be': 'beryllium', 'B': 'boron' } keys_list=symbol_dic.keys() for key in keys_list: symbol_dic[symbol_dic[key]]=key[/CODE] | |
Re: NoneType usually means you are trying to use a variable that has not been defined. Without code and the error message it is impossible to tell anything at all. | |
Re: With most GUI's you can pass parameters with the function call, so button 1 would use button_press("1") and button 2 would use button_press("2"). If this does not work with the graphics you are using, use a pass-through function [code]def button_pressed(): ##do common stuff here def button_one(): print "button one pressed" … | |
Re: [QUOTE]I'm in a computer security class and am working on a project involving linux viruses.[/QUOTE]That's a little difficult to believe. If you want to know how to combat viruses, then look at Bastille or Security-Enhanced Linux from the NSA. | |
Re: easygui is a better solution for a simple interface. If you want to learn how to program using GUIs, use Tkinter or one of the other toolsboxes. [url]http://www.ferg.org/easygui/[/url] | |
Re: The link [url]http://www.daniweb.com/forums/thread94059.html&highlight=five+click+house[/url] yields a 404 File Not Found. Try one of these (and learn how to search) [url]http://www.daniweb.com/forums/thread94059.html[/url] [url]http://www.daniweb.com/forums/thread40738.html[/url] | |
Re: Are you really too lazy to Google for "python install gasp on windows" | |
Re: [QUOTE=jliu66;508074]So when you make the change to the attritutes of objects, it will change other attributes in other copied objects.[/QUOTE] This is what a copy is. I think you may want separate instances of the class.[CODE]class some_class: def __init__(self, msg): print msg self.var=0 if __name__== "__main__": class_list=[some_class("test "+str(x)) for x … | |
Re: The standard way is[code]if not os.path.isfile(full_file_name): CREATE Table[/code] | |
Re: The Python Cookbook is the first place to look. The following link states "- Added conversion to and from Julian Day number". I haven't tried it. [url]http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117215[/url] | |
Re: Some online books and tutorials are here [url]http://www.python-eggs.org/?row=0[/url] click on the Python link here [url]http://ubuntuforums.org/showthread.php?t=333867#5[/url] Google will list many, many more. | |
Re: A split on a number followed by a letter is the obvious place to start. It would be nice if all of the symbols were camel case, but I don't think you can rely on that. For the "OOH" in "C6H3Cl2COOH" (no pun intended), you can look for a match … | |
Re: Somewhere in the function you will have to add x (list item value) to a cumulative total and compare it to goal. If total is greater than goal then return number of days (can also be a total or the for loop index+1 or iter if you use a for … | |
Re: Since no one else has answered, I use one string to do the job, but don't think that this is Pythonic or "SQLic". So [QUOTE]cursor.execute(""" INSERT INTO %s (name, gender, job, level, str, dex, intel, cha, luc) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) """, (CharAccount, CharName, … | |
Re: I think you would use a function and pass variables to it. So if the Laplace operator is a+b-c you could do something like[CODE]def laplace_func(a, b, c): return a+b-c # if __name__ == '__main__': laplace_list=[ [1 ,2 ,3], [3, 2, 1], [1, 3, 2]] for eachlist in laplace_list: result = … | |
Re: Try one or more of the "Learning Python" links here. There are a lot of tutorials available elsewhere on the web [url]http://python-eggs.org/?row=0[/url] | |
Re: "So the result of printSubs([1,2,3])" You would increment a counter or use a for() loop in the range of 0-->len(list_passed) to append an increasing number of items to the "sublist_list" based on another counter or for() loop. So the first pass would append one/each individual item, the second pass would … | |
Re: main() in the first program block calls itself, so yes it is an infinite loop. I think what you want is [code]if __name__ == "__main__": main()[/code] This calls main() once and then exits when main() is finished - assuming you also removed main() from def main() Also, you can do … | |
Re: It is possibly the video header that is resizing. You should be able to resize and move the window manually depending on your operating system. Something along the lines of wx.Frame.__init__(self, parent, -1, title, pos=(10,10), size=(640, 480), etc should work also (with the emphasis on 'should'). | |
Re: They are not printable characters (probably) and so who knows where they come from. To test this, try printing the decimal value of each character. It might just be a bunch of decimal zeroes (which is zero, the printable zero is decimal 48), or EOFs, or garbage created by some … | |
Re: You have to convert the background color to a transparent color. With imagemagick you would use the convert -transparency options, but whatever method you choose, the computer does not know what is background and what is not so you have to tell it what to do. Here is Google's result … | |
Re: I have never heard of, let alone used graphics22. That being said, in general you have to declare a string variable, (which is different from a python string variable in Tkinter), and then use the graphics22 variation of "setText". Likewise, to retrieve text you would use some form of "getText". … | |
Re: [quote] How can I combine 30 attributes into a tuple as you mentioned above so that I loop through thousands of people?[/quote]You don't have to use a tuple. That was just a convenient container for the example presented above. As vegaseat already stated, a little more info would be helpful. … | |
Re: I am guessing that there are no replys here because the problem was not explained well enough. Perhaps a simple step by step example or some pseudo-code will garner more response. Example: User enters data Data is saved when user clicks save button etc | |
Re: You can also combine them and Python's garbage collector will then automatically close the file for you for line in open(fname, "r"): ## One line at a time ## or data = open(fname, "r").readlines() for line in data: | |
Re: Use string.split() instead and split on the commas. Python has a csv module (comma separated variables), but it looks like that would be overkill here. | |
Re: I would not use root permissions, but make this an exception to the redundancy rule and create a redundant program/function with a different name that does what you want. | |
Re: Have you seen this link. If all else fails you will have to convert to some known image format (pbm/netpbm?) and display that. [url]http://effbot.org/tkinterbook/bitmapimage.htm[/url] | |
Re: Here is an example using Tkinter. A Google for "graph python" will turn up all kinds of examples [url]http://www.daniweb.com/code/snippet583.html[/url] |
The End.