3,386 Posted Topics

Member Avatar for toll_booth

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

Member Avatar for toll_booth
-1
140
Member Avatar for dustbunny000

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 …

Member Avatar for Beat_Slayer
0
148
Member Avatar for mjs051

It would be easier to help you in your problem if you posted your code and error message you are getting.

Member Avatar for TrustyTony
0
9K
Member Avatar for lewashby

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 …

Member Avatar for Beat_Slayer
0
89
Member Avatar for TrustyTony
Member Avatar for TrustyTony
0
592
Member Avatar for pythonstudent

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

Member Avatar for cghtkh
0
106
Member Avatar for _neo_

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' % …

Member Avatar for _neo_
0
272
Member Avatar for csguy11

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 …

Member Avatar for TrustyTony
0
486
Member Avatar for KrazyKitsune

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

Member Avatar for Stefano Mtangoo
0
622
Member Avatar for gunneronaspooky
Member Avatar for udev

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 …

Member Avatar for udev
0
130
Member Avatar for xtra333

because it is not defined locally and you are not calling object method self.hasFlush.

Member Avatar for xtra333
0
2K
Member Avatar for pixelss
Member Avatar for pixelss
0
476
Member Avatar for sikais17

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): …

Member Avatar for sikais17
0
155
Member Avatar for Rocanlover1

Rethink formula you are dealing with weighted average. Also you need numbers from user input strings.

Member Avatar for TrustyTony
0
148
Member Avatar for a007s

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.

Member Avatar for a007s
0
3K
Member Avatar for guyfrompluto

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]

Member Avatar for Beat_Slayer
0
706
Member Avatar for gunneronaspooky
Member Avatar for kumarantechie
Member Avatar for lionaneesh

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

Member Avatar for redyugi
1
3K
Member Avatar for Ghostenshell

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.

Member Avatar for Ghostenshell
0
105
Member Avatar for sphynx_25

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]

Member Avatar for sphynx_25
0
2K
Member Avatar for James0l9l

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]

Member Avatar for TrustyTony
0
247
Member Avatar for pythonbegin

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

Member Avatar for pythonbegin
0
1K
Member Avatar for pleasecompile

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

Member Avatar for pleasecompile
0
453
Member Avatar for patton228

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

Member Avatar for patton228
0
156
Member Avatar for smohrchi
Member Avatar for smohrchi
0
152
Member Avatar for dankiller94

How does the termination condition become realized? Is there limit of maximum number of turns?

Member Avatar for woooee
0
180
Member Avatar for Beat_Slayer

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 …

Member Avatar for Beat_Slayer
1
570
Member Avatar for Ezzaral

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.

Member Avatar for ~s.o.s~
3
297
Member Avatar for rexona
Member Avatar for vegaseat
0
113
Member Avatar for debuitls

If you like things to keep in order, consider list or tuple instead of dictionary.

Member Avatar for TrustyTony
0
86
Member Avatar for James0l9l
Member Avatar for pwnmercury

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.

Member Avatar for vegaseat
0
236
Member Avatar for koveras vehcna

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]

Member Avatar for TrustyTony
0
135
Member Avatar for koveras vehcna

If you would have list of words in sentence sorted in length order, it would be simple wouldn't it?

Member Avatar for koveras vehcna
0
176
Member Avatar for James0l9l
Member Avatar for Xzarik

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

Member Avatar for TrustyTony
0
137
Member Avatar for acrocephalus

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

Member Avatar for acrocephalus
0
5K
Member Avatar for linuxoidoz

Have you prooved the regular del statement. When object is not referenced it is put for garbage collection.

Member Avatar for raptr_dflo
0
16K
Member Avatar for Xzarik

It means you are processing string, not list or tuple. Try to chance to end of line to [code]in reference.split.(',')][/code]

Member Avatar for Xzarik
0
157
Member Avatar for ultimatebuster
Member Avatar for acrocephalus
Member Avatar for ronparker

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

Member Avatar for TrustyTony
0
116
Member Avatar for acejhon

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

Member Avatar for TrustyTony
-2
285
Member Avatar for ultimatebuster

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

Member Avatar for TrustyTony
0
185
Member Avatar for fingerpainting

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]

Member Avatar for fingerpainting
0
254
Member Avatar for Axelro

You can add key for sorting to sorted, for example sorted(dictionary,key = reversed)

Member Avatar for Axelro
0
87
Member Avatar for radc

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

Member Avatar for radc
0
252
Member Avatar for Pinchanzee

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

Member Avatar for Pinchanzee
0
574

The End.