1,175 Posted Topics
If you own a stopwatch, here is your chance to benchmark the various versions of Python on recursion performance. The Ackermann function gives the old computer quite a workout. | |
![]() | |
Re: I think the last time Google bothered to visit DaniWeb was about a year ago. | |
Re: You can also read up on Fibonacci numbers here: [url]http://www.daniweb.com/code/snippet216645.html[/url] Mentions the slow recursive function and the faster generator function. BTW, the generator function is 25,000 times faster than the recursive function when calculating the first 30 members of the Fibonacci series. | |
Re: Some simple changes will do: [code=python]comments = [] inComment = False for i, line in enumerate(open(filename)): if "//***" in line: inComment = not inComment elif inComment: # changed to elif print( "comment found at line %d" %i ) # test # optionally strip trailing '\n' char line = line.rstrip() comments.append((i, … | |
Re: [QUOTE=leegeorg07;986975]Oh, well I can't find it in 2.6 or newer, maybe as sravan said that its outdated python org decided not to include it anymore[/QUOTE]The binary windows installer of Pyhon26 or Python31 both have tkinter. In fact in Python31 Tkinter has been spruced up with the module ttk. Vegaseat left … ![]() | |
Re: The Python module re is your friend: [code=python]# finding a search word in a text file using regex module re import re search = 'like' # also matches 'like!', but not 'likely' pattern = r"\b%s\b" % search #print(pattern) # for testing only --> \blike\b rc = re.compile(pattern, re.IGNORECASE) test_text = … | |
Re: While men die doing stupid things to satisfy the demands of their spouces, our nursing homes are filling up with feeble old biddies, barely a man in sight. Yes, women live longer than men. | |
Re: Judge: "I know you, don’t I? Defendant: "Uh, yes. " Judge: "All right, tell me, how do I know you?" Defendant: "Judge, do I have to tell you? " Judge: "Of course, you might be obstructing justice not to tell me." Defendant: "Okay. I am your bookie." | |
Re: Please use an editor, hard to see what your indents are with that lousy pyshell! | |
Re: [QUOTE=sravan953;984775]What woooee said was correct: [code='python'] overwrite="" while(overwrite!="Y".lower() and overwrite!="N".lower()): overwrite=raw_input() [/code][/QUOTE]Here "Y".lower() does not make any sense since it is simply 'y' ![]() | |
Re: To do well in the search engine market you have to be quick, nimble and innovative. I don't think Google has much to fear from Microsoft. | |
Re: I would stay away from module cturtle and use Python's own thoroughly tested module turtle. Here is a small code sample that shows you how to handle the turtle direction properly: [code=python]import math import turtle as tu base_length = 200 # the two sides are equal in an Isoceles triangle … | |
Re: You have to read up on the slicing operator in the Python Manual. Generally you can slice a sequence with [start: end: step] By default start=0, end=len(seq), step=1 step=-1 goes from the end to the beginning of the sequence, hence your reverse. For some nice slicing examples see post #4 … | |
Re: If you are used to Python2 code, then Python3 is full of surprises. However they all make the language better! So, keep an open mind, use the 2to3.py utility and try to make the old code work. | |
Re: This approach should work: [code=python]# def replace_one_two(name): """Switch letters in 2nd and 3rd position""" left = name[1] right = name[2] name.remove(left) name.remove(right) name.insert(1, right) name.insert(2, left) return name def replace_three_four(name): """Switch letters in 3rd and 4th position""" left = name[2] right = name[3] name.remove(left) name.remove(right) name.insert(2, right) name.insert(3, left) return … | |
Re: The early Gray Computers were cooled with flourinated hydrocarbon liquid. My problem would be the mess it makes when it leaks. | |
Re: public DBBase() { } } interesting C code. | |
Re: It works well on my Windows XP computer! What does .swf stand for? | |
Re: Does not look like C code to me! What does it do here? | |
Re: Right now you simply have to use one of the many image view utilities to convert your jpg files to gif files. | |
Re: Courier is the most common font to space all character equal. | |
Re: Looking through IDLE's source code (should be right on your drive) might give you some insight into code highlighting. | |
Re: You might also take a look at: [url]http://www.daniweb.com/forums/thread20774.html[/url] | |
Re: Here is an example how to do something like this with PIL: [code=python]# create an empty image with PIL and put pixels inside from PIL import Image # use a (r, g, b) tuple to represent colors red = (255,0,0) white = (255,255,255) # create a new 256x256 pixel image … | |
Re: Take a quick look at: [url]http://www.daniweb.com/forums/showpost.php?p=954810&postcount=53[/url] | |
Re: Try this: print(10^2) print(10**2) | |
Re: I don't understand what you are asking for. Could you explain, maybe give a short example? | |
Re: Looks like you have a wife that lets you play with the computer. Hang on to her for another 47years!! | |
Re: You are way ahead of me on this. Looks like a very interesting project! What are you using to control the motor with the serial port? | |
Re: # optionally scroll to the bottom of the listbox lines = listbox.size() listbox.yview_scroll(lines, 'units') | |
Re: Something like ... [code=python] toolbar.AddSimpleTool(wx.ID_SAVE, self.getBMP(wx.ART_FILE_SAVE), "Save", " Save the text file") [/code]... shows you the text "Save" as a popup hint | |
Re: Python25 has sqlite3 builtin, so you could use that. | |
Re: PMW has not been updated since 2007. Do you really want to go with this stale old thing? | |
Re: Sometimes a few test prints are a real eye opener: [code=python]test = [[11,22,33,44,55,66]] print(test[0]) # [11, 22, 33, 44, 55, 66] print(test[0][0]) # 11 print(test[0][1]) # 22 [/code] | |
Re: The source string has to be a string of bytes, just like you would get from a binary read of a file. So try: [code=python]import quopri enctext = quopri.encodestring(b'hello') print(enctext) print(type(enctext)) [/code] | |
Re: Is the directory there and do you have access to it? | |
Re: Set up a formatted string before you send it to the Textbox. Here is an example: [code=python]# example to set up a table formatted string import math # set up the format strings (use - for left justified) header = "%-12s %-12s %-12s \n" line_fs = "%-12f %-12.4f %-12.4f \n" … | |
Re: Most computer languages would give you the same problem. The computer tries to represent a floating point number as a binary internally. To compare floating point numbers you need to use fuzzy logic. Here as an function to use: [code=python]def fuzzyequals(a, b, delta=0.0000001): """ returns True if a is between … | |
Re: Be aware that sorting strings will not necessarily behave as you would expect: [code=python]myfiles = [ 'a1.txt', 'a2.txt', 'a3.txt', 'a4.txt', 'a5.txt', 'a6.txt', 'a7.txt', 'a8.txt', 'a9.txt', 'a10.txt', 'a11.txt' ] print(myfiles) print('-'*60) myfiles_sorted = sorted(myfiles) print(myfiles_sorted) """my result --> ['a1.txt', 'a2.txt', 'a3.txt', 'a4.txt', 'a5.txt', 'a6.txt', 'a7.txt', 'a8.txt', 'a9.txt', 'a10.txt', 'a11.txt'] ------------------------------------------------------------ ['a1.txt', … | |
Re: In Python most everything is an objects, so you are using OOP from the start. If you talking about the use of classes, then basically you have another tool to organize larger programs. You can collect functions that belong together under the class header. These function are commonly called methods … | |
Re: The solution depends on the GUI toolkit you are using. | |
Re: Just a note: avoid using 'file' for an identifier, since it is a built-in Python function. | |
Re: Most likely maintenance time, those are scheduled most often on weekends. | |
Re: [QUOTE=ddanbe;903205]Elvis shook up the world, MJ beat it and made it thrill.[/QUOTE]Nicely said! | |
Re: It would be nice to get the game going and put in some test prints or send it through a debugger. However, without the module gameobjects it is hard to get the needed vector2 stuff. Also looks like there is a mixed tab/space indentation issue. | |
|
The End.