2,190 Posted Topics
Re: [QUOTE]There's also a second part where I should define a SortedSet class [/QUOTE]Verify with the teacher that the set will only contain integers, floats, and strings, and whether there will be more than one type of these in the set.. If you have lists mixed in with integers mixed in … | |
Re: With Tkinter (if you are using Tkinter) it would be something like text.insert(INSERT, "click here!", "a") or listbox1.insert() As for "refreshed automatically", there is nothing automatic. You will have to define what event causes a refresh. You can tie it to a button press or a file write, etc. Any … | |
Re: Two or three print statements should do the trick. Note that string is no longer used. It should be linea=linea.split(';') instead of linea=string.split(linea,';'), etc.[code] fINI='f:\\pulldpto.ini' fINI=open(fINI,'r') while 1: linea=fINI.readline() if not linea:break linea=string.split(linea,';') print "linea after split =", linea print " setting", variabl1[string.strip(linea[0])], "to zero" variabl1[string.strip(linea[0])]=0 print " setting", variable3[string.strip(linea[0])], … | |
Re: The general idea is to store the replacement values in a container like a dictionary, isolate the string that you want to test, and replace it if it is in the replacement dictionary. As stated above you could store them in a separate text file and read into a dictionary. … | |
Re: A list of python books online [url]http://linkmingle.com/list/List-of-Free-Online-Python-Books-freebooksandarticles[/url] Also, Doug Hellmann's "Python Module of the Week" is excellent [url]http://www.doughellmann.com/PyMOTW/[/url] But if you want to know something specific, this is the place to ask. | |
Re: Put the roll statement under one of the while loops roll = random.randint(1,6) Now, it is only executed once at the beginning of the program. Also, instead of all of the if/elif you can use a list or dictionary and increment, for example counter_list[roll] += 1 You will have to … | |
Re: It could very well be overkill depending. Some more info would help, but I would suggest that you start with some of your own code to find out what you want and don't want to do. Once some of the parameters are defined, it will be an easier decision. | |
Re: You would use a [6][6] list of lists.[CODE]list_6x6=[] ## outer 'matrix' junk = [] for k in range(0, 6): ## inner list with length=6 junk.append(j*6 + k) list_6x6.append(junk) for single_list in list_6x6: print single_list[/CODE]Also, you can use a dictionary instead of those if/elif.[code] if bok =='A'; index = 0 elif … | |
Re: [QUOTE]loop over all files(named output10000 - output10000000) get all the values at all positions[/QUOTE]For this example of data 2.825 1.00697992588 2.875 0.952989176901 2.925 0.91428970229 2.975 0.890110513425 If it is the first number, "2.825", that you want to use as the key with the second number being the values, I would … | |
Re: While you can use a single or double quote within Python, databases are not so forgiving. If Jim699's post works it is because of the different use of quotation marks. If that doesn't work, try[code]SQL_str = 'INSERT INTO table (column1, column2) VALUES ("start finish","now later")' cursor.execute(SQL_str) [/code] | |
Re: Also you probably want to indent everything under __main__, as well as use something other than "list" as a variable name as it is a reserved word. The way you have it, the code under __main__ is executed, and when finished, the wihile loop is executed, If it makes it … | |
Re: [QUOTE]but i do not know how to seperate the whole file into the 49 different months. and thake their averages.[/QUOTE]I'm not going to read the whole problem; it's way too long. Post some sample input data and state specifically what you do not understand. In the code you posted, it … | |
Re: You have the right idea. To add it to your program, add another if statement to the smallest & largest calcs using your num %2==0 idea. This code is not tested.[CODE] else: if num > largest: #found new largest largest = num loc_largest = location if num < smallest: #found … | |
Re: There is something in the README that comes with Python explaining how to install to a different path, but it would be simpler to install for your distro. Can you install software or do have to do it yourself because you don't have root? If you can install, then what … | |
Re: Take a look as post #3 in the "starting python" topic at the top of the topics list on the Daniweb page. Basically, it would be[CODE]def function_name(catalog_f_name, write_filename): catalog_f=sextractor.open(catalog_f_name) catalog=catalog_f.readlines() sys.stdout=open(write_filename, 'w') for star in catalog: print star['X_IMAGE'] sys.stdout=sys.__stdout__ ## this calls the function with the appropriate names function_name('Z2.cat', 'Z2X.txt')[/CODE] | |
Re: The problem is that you never call the function avg.[CODE]while True: location = location + 1 num = input("enter number ") if num == "done": #check for end of input print "the largest is ", largest print "at location ", loc_largest print "the smallest is ", smallest print "at location … | |
![]() | Re: I think you have something like 30 minutes to edit the post. After that it is toggled to off. I suppose to keep old posts from being edited endlessly. |
Re: [QUOTE]The standard deviation is The standard deviation is <function SD at 0x020EB630>[/QUOTE]Don't use the same name for the function and the variable returned, hence "<function SD" at 0x020EB630> | |
Re: It looks like Nothing is used to declare a variable for use at a later time. Since you don't have to declare variables in Python, you should be able to just ignore it. If you want a variable to be persistent, then you will have to define it with some … | |
![]() | Re: Try BitBuffer first [url]http://pypi.python.org/pypi/BitBuffer/0.1[/url] You can also use array [url]http://docs.python.org/lib/module-array.html[/url] [CODE]## "H"=unsigned short int, see the docs a1 = array.array('H') fp = open(filename, 'rb') a1.fromfile(fp, 1) print a1 a1.fromfile(fp, 1) print a1[/CODE] |
Re: I added print statements to Opacity() and nothing printed, meaning it never gets called. You might have to test for the location of the mouse cursor when the left button is pressed, or attach something to one particular widget. Sorry, I have never done anything like this so can't help … | |
Re: [QUOTE]What if I want to control how much my loop will increment by? For example: [code]for i in range (1, 30) if (apple == fruit) i = i + 6 elif (grape == fruit) i = i + 2[/code][/QUOTE]Use a while loop with a variable defined outside the loop. [code]ctr … | |
Re: Start with some code to read the file, as well as the file you want to write to. Also, how large is the input file? Hint, you will want probably want to use some kind of a container to hold the 3 items you want to write. | |
Re: Generally, you would do a merge type program. Read in both files, compare and change, then write to a third file, which will be the merged file. So some pseudo-code if "hb15b01" in record, find record in second file to change (let's say it has "hb15b00"), change "hb15b00" to "hb15b01" … | |
Re: You can use a while loop, something along the lines of[CODE]found = 0 while not found: print "Please use W or L to input the results of the game" print win_loss_code = raw_input('Enter W for Win or L for Loss: ') win_loss_code = win_loss_code.lower() if win_loss_code == "w": print "You … | |
Re: "records" should be a dictionary (code has not been tested)[CODE]# A list of entries # Each element will be a dictionary records = {} next_number=1 # User input user = "" while user!="0": #display menu print print " Film Database" print "-----------------" print "1 -- Add Entry" print "2 -- … | |
Re: You should increment height, otherwise it's an infinite loop. In general you want to use a for() or while() loop and append to a list on each loop. Add print statements to print what you don't get (especially 'height' and 'start'). | |
Re: If you are using pack(), not grid, then you want side=LEFT. See this tutorial [url]http://effbot.org/tkinterbook/pack.htm[/url] | |
Re: Scru just posted the same thing as I was (well except that I would use floats, unless income is whole dollars only), so I will submit an idea to simplify entry.[CODE]x = [] ## will contain the entries total = 0 for j in range(1, 5): income = float(raw_input("Enter Income … | |
Re: A slight modification.[CODE]for index, item in enumerate(arr): if item > 100: return index, item[/CODE]See here for info on lists [url]http://effbot.org/zone/python-list.htm[/url] Edit: Damn, this is probably homework. My mistake. Using enumerate will probably red flag it though. | |
Re: I think this does what you want with the host write function but the code is truncated [url]http://code.activestate.com/recipes/152043/[/url] | |
Re: I reported it. Note that it is the first post for ClemG and is possibly just a test post for future spam postings. | |
Re: You also want a conn.comit() after inserting. And you should take advantage of using a class, plus change the first statement to use python. #!/usr/bin/python # SQLite command to be used with the applications import sqlite3 as sqlite class SqliteCommands: def ___init__(self, parent): self.parent = parent def list_all_recs( self, t_name … | |
Re: I think this probably has to do with Python's garbage collection. The file might not be closed at the exact moment you close it. You can let the program sleep for say one second, or try putting the read() through the close() in a function and call the function. All … | |
Re: rcw is a list of lists. You want to write strings to a file so you have to add one more level.[CODE]for record in rcw: bird = record.strip().split() ## add this to each record outgroup.write("%s" % (dID[bird[3]]) ## assuming this is a string ## bird is a list for field … | |
Re: This is a well know and well documented result on PCs due to the use of binary numbers. Our base 10 system also has problems (with numbers like 1/3 or Pi). The explaination at python.org is here [url]www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate[/url] and [url]http://www.lahey.com/float.htm[/url] A google for "floating point precision" or something similiar will … | |
Re: You would use a simple bash file for this and create an icon to the bash file. You could use python, but it would simply call bash to run the program. | |
Re: Another way to go at it[CODE]edge = "# "*8 + "#" center = "# " + ". "*7 + "#" print edge for j in range(0, 6): print center print edge [/CODE]In any case, you want each line to be a single string, so if you want it all in … | |
Re: You would generally use a dictionary for this (and please do not use "l", "i", or "o" for single digit variables--they look too much like numbers). The dictionary key would point to a list ["abstract", "title", "ID"] [CODE]class classic: def __init__(self,text): text ="TI -xxTI -yy TI -z" self.class_dic = {} … | |
Re: It is more common to iterate the file one record at a time instead of the read() and split().[CODE]import random outfile = open('numbers.txt', 'w') for count in range(20): ##Get random numbers rebmun = random.randint(1,99) outfile.write(str(rebmun) + '\n') outfile.close() numbers={} fp = open('numbers.txt','r') for rec in fp: numbers[rec.strip()] = "test" print … | |
Re: Using an SQLite database is the simpliest and best. It comes with Python and a tutorial is here [url]http://www.devshed.com/c/a/Python/Using-SQLite-in-Python/[/url] | |
Re: You return the string "error". It is an empty string unless the following is true.[CODE]for element in find_text(item): if extra+element.tag.replace(' ','') in Results[0].keys(): if element.text >= Results[0][extra+element.tag.replace(' ','')]: error = error + "Error with "+item.tag+" "+element.tag+" value = "+element.text +" \n" else: continue[/CODE] | |
Re: I once Googled for "python web crawler". There were many but this is the only one saved [url]http://www-128.ibm.com/developerworks/linux/library/l-spider/[/url] "See Example 4: Web site crawler" | |
Re: This will only execute actionDefault once.[CODE]do_action = 0 if testA: actionA() if testB: actionB() if textC: actionC() else: do_action=1 else: do_action=1 else: do_action=1 if do_action: actionDefault()[/CODE] | |
Re: [QUOTE]I just happen to have it handy:[/QUOTE]We all have interesting little snippets lying around. Too bad we can't find some way to create some sort of central index, but it is more than I have time for. [code]Image Files tif to gif SQLite database - create database - modify record … | |
Re: A cardinal rule is don't mix tabs and spaces for the obvious reason that everyone does not have the same tab settings. The unoffical poll for this forum is that most people use spaces only. Most editors/IDE can be set to indent with either. | |
Re: [QUOTE]I want the program to say that after the first year the value would be(50*1.05=52.5) and the second year would be (50*1.05^2+52.5=107.625) and the third year would be (50*1.05^3+107.625=165.50625)[/QUOTE]That does not appear to be correct IMO. In the second year you have the same $50 drawing interest twice for the … | |
Re: You have to give each field in the SQLite db a name so you can access each one individually, and define it as a variable length character field, integer, etc.. Select where sql_date == date_today kind of thing. Assuming that everything is a string...[code]## Create a connection to the database … | |
Re: Python has the built in isupper() and islower() (also isdigit, isspace, ispunct) [url]http://www.python.org/doc/2.5.2/lib/module-curses.ascii.html[/url][CODE]test=["AabcdEFg.", "jKLmnopR?" ] upper_total=0 lower_total=0 neither_total=0 for rec in test: for chr in rec: if chr.isupper(): upper_total += 1 elif chr.islower(): lower_total += 1 else: neither_total += 1 print "%d Upper Case, %d lower case, and %d neither" … | |
Re: At one time you could pass a float to seek() and it would convert to a long long. I don't know if that still works or not. It would be doubtful if you are using 2.6 or 3.0. |
The End.