2,190 Posted Topics

Member Avatar for amarmasic21

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

Member Avatar for woooee
0
152
Member Avatar for fuatm16

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 …

Member Avatar for woooee
0
331
Member Avatar for lakhan.p

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

Member Avatar for woooee
0
83
Member Avatar for ask2

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

Member Avatar for ask2
0
188
Member Avatar for siddhant3s

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.

Member Avatar for sneekula
0
773
Member Avatar for Arrorn

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 …

Member Avatar for woooee
0
104
Member Avatar for dilipkk

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.

Member Avatar for woooee
0
239
Member Avatar for WhizKidd

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 …

Member Avatar for WhizKidd
0
1K
Member Avatar for breatheasier

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

Member Avatar for Gribouillis
0
153
Member Avatar for wccarithers

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]

Member Avatar for jlm699
0
2K
Member Avatar for Sohvkhan

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 …

Member Avatar for woooee
0
2K
Member Avatar for rapid_gezer

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

Member Avatar for woooee
0
382
Member Avatar for Sohvkhan

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 …

Member Avatar for sneekula
0
1K
Member Avatar for sardarji

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 …

Member Avatar for woooee
0
182
Member Avatar for super zach

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]

Member Avatar for lllllIllIlllI
0
145
Member Avatar for Sohvkhan

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 …

Member Avatar for woooee
0
155
Member Avatar for leegeorg07

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.

Member Avatar for woooee
0
107
Member Avatar for lcc_551

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

Member Avatar for jrcagle
0
189
Member Avatar for artmansoft

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 …

Member Avatar for jrcagle
0
1K
Member Avatar for tobycatlin

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]

Member Avatar for NarendraRoy
0
4K
Member Avatar for TheOneElectroni

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 …

Member Avatar for TheOneElectroni
0
326
Member Avatar for icu222much

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

Member Avatar for icu222much
0
205
Member Avatar for RMartins

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.

Member Avatar for woooee
0
93
Member Avatar for sony_b

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

Member Avatar for woooee
0
145
Member Avatar for eyewirejets

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 …

Member Avatar for jrcagle
0
118
Member Avatar for thehivetyrant

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

Member Avatar for thehivetyrant
0
122
Member Avatar for memphis1234

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').

Member Avatar for yilmazhuseyin
0
1K
Member Avatar for besktrap

If you are using pack(), not grid, then you want side=LEFT. See this tutorial [url]http://effbot.org/tkinterbook/pack.htm[/url]

Member Avatar for woooee
0
71
Member Avatar for mruane

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 …

Member Avatar for gbrokaw
0
103
Member Avatar for MaxManus

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.

Member Avatar for scru
0
4K
Member Avatar for Deepak.G

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]

Member Avatar for Stefano Mtangoo
0
3K
Member Avatar for abczxy124

I reported it. Note that it is the first post for ClemG and is possibly just a test post for future spam postings.

Member Avatar for Stefano Mtangoo
0
140
Member Avatar for Stefano Mtangoo

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 …

Member Avatar for Stefano Mtangoo
0
128
Member Avatar for vjp08

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 …

Member Avatar for scru
0
166
Member Avatar for drew7py

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 …

Member Avatar for drew7py
0
17K
Member Avatar for l_w

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 …

Member Avatar for l_w
0
143
Member Avatar for strobon

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.

Member Avatar for woooee
0
110
Member Avatar for mruane

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 …

Member Avatar for mruane
0
70
Member Avatar for wheatontrue

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

Member Avatar for wheatontrue
0
84
Member Avatar for Ghostenshell

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 …

Member Avatar for woooee
0
159
Member Avatar for wotthe2000

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]

Member Avatar for Ghostenshell
0
153
Member Avatar for adam291086

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]

Member Avatar for adam291086
0
172
Member Avatar for Clipper34

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"

Member Avatar for woooee
0
130
Member Avatar for Gribouillis

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]

Member Avatar for Gribouillis
0
139
Member Avatar for Aue

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

Member Avatar for Aue
0
125
Member Avatar for mn_kthompson

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.

Member Avatar for sneekula
0
135
Member Avatar for red999

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

Member Avatar for paddy3118
0
187
Member Avatar for Stefano Mtangoo

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 …

Member Avatar for Stefano Mtangoo
0
2K
Member Avatar for Ghostenshell

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

Member Avatar for Stefano Mtangoo
0
972
Member Avatar for int3grate

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.

Member Avatar for woooee
0
289

The End.