3,386 Posted Topics
Re: [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] … | |
Re: Maybe this would help: [url]http://www.daniweb.com/forums/post1324253.html#post1324253[/url] | |
Re: 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 = … | |
Re: And your code? That pseudo code is not yours, is it? | |
Re: 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", … | |
Re: 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] | |
Re: 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] | |
Re: 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. | |
Re: 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? | |
Re: 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. | |
Re: 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 | |
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 … | |
Re: 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) | |
Re: 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 == … | |
Re: [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 … | |
Re: 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. | |
Re: You need not check already tested factors like 2. I would suggest for loop containing while and break out to quit the loop. | |
Re: 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. | |
Re: [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] | |
Re: You forgot your code and error messages, don't forget to push (CODE) before pasting. | |
Re: 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 | |
Re: numInput is nowhere in program! | |
Re: I think you have many syntax errrors if you put that code to Python interpreter :) | |
Re: 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]. | |
Re: 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 … | |
Re: 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 = … | |
Re: @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] | |
Re: 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. | |
Re: 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] | |
Re: 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] | |
Re: Make if statement in midle of for using values as True=1 or False=0 | |
Re: 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 … | |
Re: Why random number? Can you say odd numbers from smallest to biggest until 33 inclusive? How could computer do the same? | |
Re: Take out the while, the mainloop is your loop. Set timer event for printing if flag is set. Button event just sets/unsets flag. | |
Re: 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 … | |
Re: This could be maybe transformed to one item lookahead of stream (like ungetch is C), which I have thought sometimes to be usefull. | |
Re: 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] | |
Re: 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] | |
Re: 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. | |
Re: 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" % … | |
Re: 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 … | |
Re: This algorithm does not use modulo function but step of for loop check your algorithm! | |
Re: You just use it by its name, like [code]def work(here):print(here) work("Hi!")[/code] | |
Re: I would look from documentation of [B]collections module[/B] what means [ICODE]defaultdict(int)[/ICODE] | |
Re: 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] | |
Re: 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] | |
Re: 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. | |
Re: [QUOTE]that is jython[/QUOTE] Jython -> can use java classes -> find password entry class for Java |
The End.