3,386 Posted Topics
Re: [QUOTE=toll_booth;1329918]But I don't want a StringVar; I want a Canvas image.[/QUOTE] You could use concepts from this vegaseats post of clickable shapes: [url]http://www.daniweb.com/forums/post1322031.html#post1322031[/url] You could tag all squares as named shapes and change another tag between '','X' and 'O' to mark what shape must be drawn there, when clicked, if … | |
Re: you are trying to append line to file x, but the x is set to tuple ("myfile","w") at previous line. How could it work? Do you mean to do something like: [CODE]import sys def seperate_atoms(f):#Enter .pdb file in with quotations with open(f,'r') as myfile: crudepdb= [line.strip() for line in myfile … | |
Re: It would be easier to help you in your problem if you posted your code and error message you are getting. | |
Re: Let's say we have a line from origin (0,0) to point (10,0) and another line to (0,10), intuitively they are equal length and actually when the lines are horizontal and vertical you can only substract the differing values: 10-0 = 10. But you can also in this case to use … | |
Here is code which I wrote to experiment how hard it is to get Royal Flush in Poker. | |
Re: Please use the **Code** button to keep indentations in code) Reply: normal way is to use for with range for number in range(1,9): # use the last bit of number (even/odd) to get alternation, # 0 is considered True (even numbers) print -number if (number & 1) else number | |
Re: Do not use unconditional except, you stop for example key interrupt. Check the error code you get without except, say it is TheErrorType then do [CODE]try: #your stuff with potential for interrupt as little lines as possible except TheErrorType as e: print 'Got error %s in the input, ignoring' % … | |
Re: I did this code to get words unique to files listed by id dictionary: [CODE]import string import random # Sherlock Holmes and Alice in Wonderland filenames = {'doc001':'advsh12.txt', 'doc002' : '11.txt'} words = dict() words_and_docids = dict() allwords = set() notthese = string.punctuation + string.digits samplesize = 64 for docid … | |
Re: [QUOTE=griswolf;1329627]snippsat: I agree, your fixed code works ok, but not as pythonic as it could be. (No blame: Neither is mine, completely; and you were starting from KrazyKitsune's code). I was responding to KrazyKitsune asking [B][I]So how do we do it?[/I][/B] Since he did not seem to have your fix … | |
Re: Something like this? [CODE]grail = [{'Emin': ({'file13.txt': 1}, {'Emin': [38]})}, {'Gun': ({'file13.txt': 2}, {'Gun': [43, 71]})}, {'I': ({'file13.txt': 1}, {'I': [47]})}, {'Uday': ({'file13.txt': 3}, {'Uday': [1, 28, 66]})}, {'Uday': ({'file18.txt': 2}, {'Uday': [43, 48]})}, {'ad': ({'file18.txt': 1}, {'ad': [5]})}] print [ linenumber for lines in (item["Uday"][1]["Uday"] for item in grail … | |
Re: because it is not defined locally and you are not calling object method self.hasFlush. | |
Re: Are you sure you want to return the function as value of the same function? | |
Re: for j in range(i, 0, -1): def bubble(l): l[j], l[j-1] = l[j-1], l[j] for j in range(len(l)-1, i, -1): return l k = j def selection(l): for i in range(0, len(l)): if not swapped: break for i in range(0, len(l)): if l[j] > l[j-1]: break k = i def insertion(l): … | |
Re: Rethink formula you are dealing with weighted average. Also you need numbers from user input strings. | |
Re: MenuButton menuFile has not option hiAgain at line 23. Just read last message from your program and last line from tkinter. You should use small letters and underscores for method names if possible see PEP 8 document. | |
Re: Well known subset sum problem: [url]http://www2-fs.informatik.uni-tuebingen.de/~reinhard/krypto/English/4.5.1.e.html[/url] [url]http://en.wikipedia.org/wiki/Subset_sum_problem[/url] | |
Re: Linux window manager matchbox? | |
Re: If you explain tuples, it is good to explain how to write one element tuple: [B]One element tuple: singleton[/B] If you write expression or value in parenthesis, that will not make tuple. So to make tuple you need comma, so we put one: [CODE]>>> single=('single') >>> print single single >>> … | |
Re: Shouldn't you ask parameters before creating the car, not after? Why the getters and setters? It is concidered unpythonic. Use mycar.mod = instead of mycar.set_yearmod() and mycar.mod instead of the getter. | |
Re: Regex I would not use also, but find itertools.groupby often usefull: [CODE]import itertools as it words = ['cataaaaac', 'poolooo'] for test in words: groups = ((len(list(letters)), group) for group, letters in it.groupby(test, lambda x: x) ) maxnum, letter = max(groups) print test, maxnum, '*', letter , 'index: ',test.find(maxnum * letter)[/CODE] | |
Re: Looks like you have the game ready, only write the main loop. Do not be afraid to experiment. You can also see [url]http://www.daniweb.com/code/snippet217028.html[/url] | |
Re: [QUOTE=woooee;1321866]Create 2 lists, one per column, and use the shuffle function of random on both,[/QUOTE] One column randomization with shuffle should be enough, as reading order don't need maybe to randomize. | |
Re: [QUOTE=pleasecompile;1318644]Thanks for the reply, woooee. Could you add more code comments? Does variable 'fb' stand for float pointer? What is 'rb'? Python 8.6 array documentation does not define 'rb'. Is 'fname' a text file that I need to have in the directory? What is the difference between lines 5 and … | |
Re: Your should use lists (maybe dictionary) and loops. Looks like you need to dig into this: [url]http://docs.python.org/tutorial/controlflow.html#for-statements[/url] You can then tighten your code around 90% by doing things like: [CODE]fenceLines = [] for linenum in range(int(input("Enter number of lines of fence. "))): fenceLines.append(int(input("Enter line %s lineal feet. " % linenum))) … | |
Re: And what is contents of the line 1, the interpreter complains about. | |
Re: How does the termination condition become realized? Is there limit of maximum number of turns? | |
Re: I did little clean up for your code, looks like you have compressed my [URL="http://www.daniweb.com/code/snippet289548.html"]between function[/URL]. The lambdas looked little out of place and I changed them to normal defs to be more understandable for people without Lisp or similar experience, hope I did not break anything: [CODE]import urllib sock … | |
Re: Thanks for fix, even full page dials on top. What a luxury! I would like though something less verbose instead of "You are currently viewing page 13 of this multi-page discussion thread;" for mobile use. | |
Re: [CODE]x = 1234 y = str(x) a = list(y) print ', '.join(repr(var) for var in (x,y,a)) [/CODE] | |
Re: If you like things to keep in order, consider list or tuple instead of dictionary. | |
Re: You have not called any function, therefore you can not return. | |
Re: Standard answer îs that for fixed values use dictionary lookup, otherwise use if...elif...else.. Learn to use 'in' check in condions. If you want we can recode some meaningfull switch using C snippet in Python. | |
Re: keep set of words that has been chosen to trigger and exclude them from triggering searches again, like I suggested in StackOverflow earlier. Then do something like [CODE]triggerword = sort([w for w in wordlist if w not in triggeredwords] , key=len)[-1][/CODE] | |
Re: If you would have list of words in sentence sorted in length order, it would be simple wouldn't it? | |
Re: You have defined getlist. You have not defined getList. | |
Re: Difficult to see for what you are after with such scrambled data, but maybe something like this? [CODE]relevant_weeks = [['[11', " '05/10/2009'", " '06/10/2009'", " '07/10/2009'", " '08/10/2009'", " '09/10/2009']", ''], ['[10', " '28/09/2009'", " '29/09/2009'", " '30/09/2009'", " '01/10/2009'", " '02/10/2009']", ''], ['[27', " '25/01/2010'", " '26/01/2010'", " '27/01/2010'", … | |
Re: Like: [CODE]with open('mixorder.csv') as inp, open('order.csv','w') as outp : inplist = [[word.strip('"\n') for word in line.split(',')] for line in inp ] for ln, line in enumerate(inplist): if line[0]: line[2]="ORDRE "+ line[0] elif line[1]: line[2]="Family " + line[1] elif line[2]: default2=line[2] else: line[2]=default2 inplist[ln] = line[2:] outp.write('\n'.join(',\t'.join(repr(w) for w in line) … | |
Re: Have you prooved the regular del statement. When object is not referenced it is put for garbage collection. | |
Re: It means you are processing string, not list or tuple. Try to chance to end of line to [code]in reference.split.(',')][/code] | |
| |
Re: Did you check what value dlg.showmodal() has before if? | |
Re: That looks like SQL for me. Maybe you could print out result2 so we have real Python input? Or the result of [CODE]c.exectute("SELECT REF_ENTRY_VALUE FROM actual_data_table") result = c.fetchall() print result [/CODE]if the result2 does not contain all your data | |
Re: [CODE]from random import randint thenumberasstring = str(randint(1<<32-1,1<<33-1)) print thenumberasstring norepeats = '' for n1,n2 in zip(thenumberasstring,thenumberasstring[1:]+' '): if n1 != n2: norepeats += n1 print norepeats [/CODE] And when you ask better and show some coding effort we can write real code.:twisted: | |
Re: Had to code it myself to understand what it does better, here my simple version. It could be put to function with parameters t and var, of course. I left out the unpythonic type stuff. I understand your desire of flexibility, but maybe readability suffers. [CODE]t = '''<a href="test.php">some link</a> … | |
Re: Did you try: [CODE]clean = [] for rows in top10: for x in rows: for i in x: i = str(i) i = i.encode('ascii','ignore') clean.append(i)[/CODE] | |
Re: You can add key for sorting to sorted, for example sorted(dictionary,key = reversed) | |
Re: Making one simple text window to edit the email and one send button should not be so difficult. Then you can use the [URL="http://docs.python.org/library/email"]email module[/URL]([url]http://docs.python.org/library/email-examples.html[/url]). | |
Re: [CODE]import os myext='.kml' for filename in (fn for fn in os.listdir(os.curdir) if fn.endswith(myext)): print filename # replace with your activity [/CODE] |
The End.