1,175 Posted Topics

Member Avatar for sneekula

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.

0
234
Member Avatar for leegeorg07
Member Avatar for serkan sendur
Member Avatar for lllllIllIlllI

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.

Member Avatar for sneekula
0
211
Member Avatar for klabak85

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

Member Avatar for jice
0
150
Member Avatar for lifeworks

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

Member Avatar for sravan953
0
168
Member Avatar for edward_pedro

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

Member Avatar for vegaseat
0
150
Member Avatar for majestic0110

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.

Member Avatar for quicktpgo
1
268
Member Avatar for KernMilestone

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

Member Avatar for quicktpgo
0
553
Member Avatar for lllllIllIlllI
Member Avatar for nunos
Member Avatar for woooee
0
135
Member Avatar for nunos

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

Member Avatar for sravan953
0
1K
Member Avatar for tomtetlaw

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.

Member Avatar for kaninelupus
0
607
Member Avatar for hkseo100

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 …

Member Avatar for hkseo100
0
361
Member Avatar for nunos

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 …

Member Avatar for nunos
0
339
Member Avatar for Lingson

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.

Member Avatar for sneekula
0
4K
Member Avatar for patto78

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 …

Member Avatar for patto78
0
142
Member Avatar for Thinka

The early Gray Computers were cooled with flourinated hydrocarbon liquid. My problem would be the mess it makes when it leaks.

Member Avatar for sneekula
0
115
Member Avatar for xgmx
Member Avatar for subcom
Member Avatar for bumsfeld
Member Avatar for akennedy93612
0
422
Member Avatar for nanodano
Member Avatar for Lingson

Right now you simply have to use one of the many image view utilities to convert your jpg files to gif files.

Member Avatar for vegaseat
0
1K
Member Avatar for Lingson
Member Avatar for Lingson
0
223
Member Avatar for EAnder

Looking through IDLE's source code (should be right on your drive) might give you some insight into code highlighting.

Member Avatar for vegaseat
0
821
Member Avatar for mayanktalwar
Member Avatar for sneekula
0
70
Member Avatar for mediachicken

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 …

Member Avatar for Ene Uran
0
2K
Member Avatar for Dan08

Take a quick look at: [url]http://www.daniweb.com/forums/showpost.php?p=954810&postcount=53[/url]

Member Avatar for Dan08
0
314
Member Avatar for fallopiano
Member Avatar for sab786

I don't understand what you are asking for. Could you explain, maybe give a short example?

Member Avatar for woooee
0
97
Member Avatar for Ancient Dragon

Looks like you have a wife that lets you play with the computer. Hang on to her for another 47years!!

Member Avatar for Wasser
1
232
Member Avatar for Hagbard_Durden

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?

Member Avatar for Hagbard_Durden
1
248
Member Avatar for SoulMazer

# optionally scroll to the bottom of the listbox lines = listbox.size() listbox.yview_scroll(lines, 'units')

Member Avatar for SoulMazer
0
4K
Member Avatar for Stefano Mtangoo

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

Member Avatar for Stefano Mtangoo
0
136
Member Avatar for Stefano Mtangoo
Member Avatar for Dan08

PMW has not been updated since 2007. Do you really want to go with this stale old thing?

Member Avatar for Dan08
0
589
Member Avatar for pads_irl

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]

Member Avatar for sneekula
0
63
Member Avatar for foosion

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]

Member Avatar for foosion
0
374
Member Avatar for yuguang
Member Avatar for The Dude
Member Avatar for catcit

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

Member Avatar for woooee
0
240
Member Avatar for Lingson

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 …

Member Avatar for Lingson
0
143
Member Avatar for denniskhor

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

Member Avatar for sneekula
0
232
Member Avatar for bsod1

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 …

Member Avatar for bsod1
0
119
Member Avatar for rajasekhar1242
Member Avatar for catcit

Just a note: avoid using 'file' for an identifier, since it is a built-in Python function.

Member Avatar for vegaseat
0
113
Member Avatar for fleem
Member Avatar for vegaseat
0
129
Member Avatar for Ancient Dragon

[QUOTE=ddanbe;903205]Elvis shook up the world, MJ beat it and made it thrill.[/QUOTE]Nicely said!

Member Avatar for GrimJack
0
298
Member Avatar for pymatio

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.

Member Avatar for Clueless86
0
183
Member Avatar for penguin22

The End.