3,386 Posted Topics

Member Avatar for atla

[QUOTE=richieking;1396557]try this [CODE]import time, a = 0 b = 0 FirstRun = True while 1: a = a + 1 #Adds one second if a > 59: #Accounts for minutes b = b + 1 a = a - 60 print("The current time is %d :%d"%( b ,a)) time.sleep(1) [/CODE] …

Member Avatar for richieking
0
170
Member Avatar for zoltan.magyar

Maybe this would help: [url]http://www.daniweb.com/forums/post1324253.html#post1324253[/url]

Member Avatar for TrustyTony
0
81
Member Avatar for Thropian

Here it is working, the image must be saved from garbage collection by saving somewhere, here we save it as variable of the canvas instanse. [CODE]from Tkinter import * myimage = 'Fhall.gif' class App: def __init__(self, master): frame = Frame(master) gif1 = PhotoImage(file = myimage) canvas = Canvas(frame, width = …

Member Avatar for Thropian
0
144
Member Avatar for knan
Member Avatar for yellowkaiq

Nice link -ordi-, nice complement for my code which produced words from numbers. The last version of code seems little scrambled, so I repost it here fixed: [CODE]import re numwords = {} def text2int(textnum): if not numwords: units = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", …

Member Avatar for yellowkaiq
0
207
Member Avatar for knan

Otherwise nice, but maybe v is not sequence. Here is other form with del. You must iterate over d.keys() as dictionary changes during iteration: [CODE]d={'a':[],'b':['1','2'],'c':[], 'd':False, 'e':'', 'f': 0.0} for k in d.keys(): try: if len(d[k])<1: del d[k] except: pass print d [/CODE]

Member Avatar for TrustyTony
0
18K
Member Avatar for danholding

For example like this, but start new thread and include link to old thread in your message. [CODE]list_of_mixup= ['name',123123,'sdfa',342] iter_list = iter(list_of_mixup) fine_list = [] while True: try: no_mix = (next(iter_list),next(iter_list)) except StopIteration: break else: fine_list.append(no_mix) print(fine_list) [/CODE]

Member Avatar for TrustyTony
0
106
Member Avatar for haojam

Are the data you want in result file? You want unique lines or what? Any example of desired output would enable me to help you.

Member Avatar for haojam
0
690
Member Avatar for tachyonshower

Are you using [URL="http://www.google.fi/url?sa=t&source=web&cd=1&ved=0CBgQFjAA&url=http%3A%2F%2Fwww.scipy.org%2F&ei=ggTnTP7OE4iWOuL6_Z0K&usg=AFQjCNFf2Wd0UuYsqpqBolRszpAqMeP-vA&sig2=n6dvUftlTbBBhWnY3qZt_A"]numpy and scipy[/URL] modules?

Member Avatar for tachyonshower
0
324
Member Avatar for Asset

For lines in file split the line from star. If part after star is number put that number of values to list value, then continue normaly. Change book if first part is title. Write out with json module.

Member Avatar for Asset
0
343
Member Avatar for Thropian

Maybe you are defining function in class and forgot to include self parameter, works, when I added it in init of my tkinter program [CODE]main.bind("<Up>", self.forward) [/CODE] and the def into the class. Also to my Photoimage post it worked, but must bind to master, not frame

Member Avatar for TrustyTony
0
149
Member Avatar for TrustyTony

Here another small snippet of mathematical nature returning all possible divisors of number. (set is, by the way, needed because of perfect squares Not possible to edit the snippet part but here the same with less stupid command line interface (not repeating the loop): [CODE]def divides(n): return sorted(set(sum( ([x,n/x] for …

Member Avatar for TrustyTony
1
875
Member Avatar for Safia Abdalla

In class you must allways have parameter when defining functions, which identifies the object, traditionally called self. Put those in place and post any other problems that may come! Also calling own methods is done like: self.doOpen (consider changing Capitals to _ according standard style: self.do_open)

Member Avatar for TrustyTony
0
462
Member Avatar for victordq

where is [B]except [/B]clause, you can have [B]try [/B]without [B]except[/B] ([B]else [/B]and [B]finally[/B] are optional) Your indents are huge, use PEP8 recommendation of 4 spaces. [CODE]def pegar_dados_serial(): ser = serial.Serial(port='COM4', baudrate=115200, timeout=2) #Rotina para leitura dos dados no receptor while True: try: for i in ser.read(): lista.append(ord(i)) if k == …

Member Avatar for richieking
0
3K
Member Avatar for keltik

[QUOTE=keltik;1393369]Hello, First of all: I'm more used to java, but at university we need to code something in python. I'm having serious problems filling a python-list with values. [CODE] for i in range(self.num_of_players) : self.player_hands[i]=["Testcard"] [/CODE] I want to fill the i-th player_hands-list with a String! Yes i declared a …

Member Avatar for keltik
0
174
Member Avatar for knan

To be at sure side add in beginning of your numeric Python 2 code: [CODE]from __future__ import division[/CODE] This makes 1/4 produce 0.25, not 0 (integer division). For integer division use // operator.

Member Avatar for knan
0
202
Member Avatar for n3red

You need not check already tested factors like 2. I would suggest for loop containing while and break out to quit the loop.

Member Avatar for TrustyTony
0
493
Member Avatar for WildBamaBoy

number>>5<<5 Shift out lowerst bits and shift zero bits in their place. That however truncates so maybe you like to add 16 before this.

Member Avatar for Gribouillis
0
2K
Member Avatar for parijat24

[CODE]# dict is not good name for a dict as it shadows the builtin type mydict = {'ENSTRUT00000047813': '1680', 'ENSTRUT00000047812': '2067', 'ENSTRUT00000047811': '2067', 'ENSTRUT00000047810': '2088', 'ENSTRUT00000047814': '738', 'ENSTRUT00000047808': '2208', 'ENSTRUT00000047809': '2001'} max_protein = max(mydict.items(), key = lambda x: int(x[1])) [0] print max_protein [/CODE]

Member Avatar for TrustyTony
0
172
Member Avatar for Naley2010

You forgot your code and error messages, don't forget to push (CODE) before pasting.

Member Avatar for richieking
0
156
Member Avatar for DanniStacey

Example call of function seems to have width value 4 and height 2, you should know a way to change them to 400 and 200

Member Avatar for richieking
0
90
Member Avatar for bob24bob
Member Avatar for bob3

I think you have many syntax errrors if you put that code to Python interpreter :)

Member Avatar for Netcode
0
161
Member Avatar for flamedragon00

if colon missing line 21, indention off I do not see anywhere counting of monthly average: [CODE]sum of month/count[/CODE] or [CODE]weighted sum/sum of weights[/CODE].

Member Avatar for flamedragon00
0
1K
Member Avatar for Azul-P
Member Avatar for Andrew1988

You could maybe use set as it is more effective. Use [B]not in[/B] condition to check the guesses. The moving limits are not hard to implement also and more effective. If user says too big, that value becomes value of 'less_than', otherwise our guess comes 'bigger_than', our next guess is …

Member Avatar for woooee
0
193
Member Avatar for bwbyron

import random PEG_HOLE = 10 PEGGED = "X" pegholes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] dice1 = random.randint(1,6) dice2 = random.randint(1,6) total = (dice1 + dice2) def roll_die(): dice1 = random.randint(1,6) dice2 = random.randint(1,6) total = (dice1 + dice2) return total def cpeg_holes(): pegholes = …

Member Avatar for TrustyTony
0
211
Member Avatar for Kagome

@group256: That is called print function, found in Python 3 or Python 2 by doing [CODE]from __future__ import print_function[/CODE]. [url]http://docs.python.org/library/functions.html#print[/url] Better way for saying the statement could be though: [CODE]print('(%s)' % n, end='')[/CODE]

Member Avatar for TrustyTony
0
245
Member Avatar for fannunziata1

These monkey's second name must be Erastoshtenes :) And the key opening/closing is called slice with step parameter. Then we have status of every door ready. Only these monkeys continue after square root of 1000 with only job of one door.

Member Avatar for TrustyTony
0
157
Member Avatar for convoluted

Why don't use regular, readable function: [CODE]def mystatic(self,label,size,font): text = wx.StaticText(self, -1, label, size=(size,-1)) text.SetBackgroundColour('#444444') text.SetForegroundColour('#ffffff') text.SetFont(font) return text [/CODE]

Member Avatar for convoluted
0
179
Member Avatar for evertron

I have difficulty in understanding what you mean in: [CODE] def getName(self): _Name = raw_input('Please give me your Name. ') # put in variable never used name = [] namlist.append(name) # add name==[] to local variable namlist never initialized return self._Name # return old name [/CODE]

Member Avatar for slate
0
137
Member Avatar for sallubhai
Member Avatar for ekkanh

Maybe this could help you to catch some file operation and using time.sleep: [CODE]import os import time dirname = 'test' try: os.mkdir(dirname) except: pass fn = os.path.join(dirname, 'test.txt') with open(fn, 'w') as f: f.write('Nothing') print 'Created %s (%s)' % (fn, time.asctime()) print os.listdir(dirname) time.sleep(8.30) os.remove(fn) print os.listdir(dirname) print 'Deleted %s …

Member Avatar for richieking
0
405
Member Avatar for stack111

Why random number? Can you say odd numbers from smallest to biggest until 33 inclusive? How could computer do the same?

Member Avatar for richieking
-1
175
Member Avatar for Mollier

Take out the while, the mainloop is your loop. Set timer event for printing if flag is set. Button event just sets/unsets flag.

Member Avatar for richieking
0
3K
Member Avatar for amandureja

Next time push the (code) button before pasting code. You must process file into list. Modify or delete. Write back with saving function. Usualy it is good to include option to quit without. You are missing also the user menu. Now user must import the module and use functions from …

Member Avatar for richieking
0
2K
Member Avatar for Gribouillis

This could be maybe transformed to one item lookahead of stream (like ungetch is C), which I have thought sometimes to be usefull.

Member Avatar for Gribouillis
0
598
Member Avatar for Smed

You can also use Pythons power to make the re for search: [CODE]makethis='3281-0(02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22) LEFT' also = '3281-0('+'|'.join('%02i' % num for num in range(2,23))+') LEFT' print also print makethis == also [/CODE]

Member Avatar for TrustyTony
0
76
Member Avatar for nejger

Or see my simple calculator snippet, which has GIF picture keyboard, which is easy to adapt: [url]http://www.daniweb.com/code/snippet282548.html[/url]

Member Avatar for TrustyTony
0
121
Member Avatar for Dinnerfortwo

With [CODE]global moves [/CODE]or by adding moves as one more parameter, which will change the caller's variable as list is mutable. Or by using legal_moves.moves instead of moves, but that is quite special way, which is not generally practiced.

Member Avatar for TrustyTony
0
85
Member Avatar for parijat24

I do not understand the first line of your result: [CODE]import sys with open(sys.argv[1] if sys.argv[1:] else 'test.txt','r') as infile: with open(sys.argv[2] if sys.argv[1:] else 'test_out.txt','w') as outfile: rec = (line.split(None, 1) for line in sorted(infile, key=lambda x:int(x[47:55]))) result = dict(rec) for key,item in sorted(result.items()): line = "%s %s" % …

Member Avatar for TrustyTony
0
133
Member Avatar for Friendly Lotus

Like this? [CODE]from Tkinter import * def colourUpdate(): colour.set('red' if colour.get()!='red' else 'blue') print colour.get() l.configure(fg=colour.get()) root = Tk() colour = StringVar() colour.set('red') btn = Button(root, text = "Click Me", command = colourUpdate) l = Label(root, textvariable=colour, fg = colour.get()) l.pack() btn.pack() root.mainloop() [/CODE] l is not the most recommendable …

Member Avatar for TrustyTony
0
15K
Member Avatar for br0wnm4n

This algorithm does not use modulo function but step of for loop check your algorithm!

Member Avatar for TrustyTony
0
142
Member Avatar for ekkanh

You just use it by its name, like [code]def work(here):print(here) work("Hi!")[/code]

Member Avatar for TrustyTony
-1
102
Member Avatar for wazaa

I would look from documentation of [B]collections module[/B] what means [ICODE]defaultdict(int)[/ICODE]

Member Avatar for wazaa
0
3K
Member Avatar for c2q

This is place for itertools.groupby in my opinion: [CODE]import itertools separator = set('.!? ') data = 'hello. world! hello.' result = [] for isin, group in itertools.groupby(data, lambda x: x not in separator): if isin: result.append(''.join(group)) print result [/CODE]

Member Avatar for ultimatebuster
0
624
Member Avatar for Smed

One way directly to print: [CODE]r =[[['steve',1, 40], ['steve',3, 20], ['steve',2, 30]], [['john',5, 50], ['john',6, 40], ['john',4, 30]]] print '\n'.join(' '.join(str(item) for item in deep) for sub in r for deep in sorted(sub)) [/CODE]

Member Avatar for TrustyTony
0
211
Member Avatar for nejger

I do not see your code and explanation of what you have tried/error messages, algorithm you are using. In sufficient data to help you.

Member Avatar for woooee
0
177
Member Avatar for singlem1905
Member Avatar for ds2000

[QUOTE]that is jython[/QUOTE] Jython -> can use java classes -> find password entry class for Java

Member Avatar for ds2000
0
2K

The End.