4,305 Posted Topics
Re: For testing purposes I would write it like this ... [code=python]class Man(object): def __init__(self, name): self.name = name def sit(self): print " is now sitting on bench" class Bench(object): def __init__(self): self.occupants = [] def accomodate(self, person): self.occupants.append(person) print person.name + " now accomodated" def listOccupants(self): for i in range(0, … | |
Re: I generally find it easier to use an endless while loop and break out: [code=python]# set up an endless loop ... while True: print "Please use W or L to input the results of the game" print win_loss_code = raw_input('Enter W for Win or L for Loss: ') win_loss_code = … | |
Re: Replace the commas by plus. What do you expect the user to enter? You may want to give some kind of a templet/hint in your prompt. | |
Re: Start a "Loan Modification" business, make sure your customers pay up front. | |
Re: BearofNH is right the correct usage is ... [code=python]import numpy qq = [1, 2, 3] ar = numpy.array(qq, dtype='f') print(ar) # [ 1. 2. 3.] [/code]It is always easy to run a little test program. It might also be easier to use something like this ... [code=python]qq = [x for … | |
Re: The tomatoes and onions on there should be relatively healthy. I love my Fatburger Turkeyburger! [url]http://www.fatburger.com/menu/[/url] | |
Re: If it is a something like a mutliple choice quiz, you can organize all the questions/answers into a list of tuples. Each tuple might have this order: (question, answer1, answer2, answer3, answer4, answer_code) Each of these tuples comes from a data file were each question looks like this: question answer1 … | |
![]() | Re: Strange that Ulipad does this, I find my installation very stable. There is Komodo Edit 5.0, but this free version does not come with the debugger. You could install a good external debugger like winpdb to use with it. Then there is Editra, however it is still in it's alpha … ![]() |
Re: The function s.strip() will do ... [code=python]s = repr("callbackfunctionname({'Last': 'Doe', 'First': 'John'})") print s # remove leading and trailing character '"' print(s.strip('"')) """ my output --> "callbackfunctionname({'Last': 'Doe', 'First': 'John'})" callbackfunctionname({'Last': 'Doe', 'First': 'John'}) """ [/code] | |
Re: The rule is that you need to define your function before you call it. The rule relaxes if you call one function from another function. Generally line up your imports, then your classes, and then your functions before you go at them. | |
Re: You can use a list comprehension to speed things up ... [code=python]# create a list of indexes for spaces in a text text = "According to Sigmund Freud fuenf comes between fear and sex." space_ix = [ix for ix, c in enumerate(text) if c == " "] print(space_ix) # [9, … | |
Re: Yes, you have to show some effort at first. | |
Re: Once girls get smarter than you, why should they put up with you? | |
Re: There is an indentation problem with one of the def statements. You are asking for total_hours twice and should ask for hourly_pay at least once. You need to pass the required arguments from and to the functions. | |
Re: You could convert the list to a string and use slice ... [code=python]q = [23, 'CL', '006', '2004', 'DBA8ORPU', '41', '8Y', 'S0111P', '2'] # slice off first and last character str_q = str(q)[1 : -1] print(str_q) """ my result --> 23, 'CL', '006', '2004', 'DBA8ORPU', '41', '8Y', 'S0111P', '2' """ … | |
Re: [QUOTE=Ancient Dragon;794114]people will show up with either credit or debit cards instead of money. Its almost that way now -- probably 3/4 my sales are with credit/debit cards. When I was first married in 1962 a pickup full of groceries would cost about $65.00 USD. Today I can't get just … | |
![]() | Re: I still like to use DrPython, but you need to instal the wxPython GUI toolkit first (something you should have anyway). DrPython has some neat downloadable plugins like 'codehelp' and 'run from buffer'. Simply extract the zip file into your Python folder. You can download it from: (Windows and Linux … ![]() |
Re: We help those who show a little effort at first. Hint, convert x to a string and iterate the string summing up the int value of each character. | |
Re: Rashakil Fol's approach shaves off a few precious fractional microseconds ... [code=python]# calculate the luminance of a color pixel # (psyco does not help to improve speed) def luminance1(pixel): """calculate and return the luminance of a denary pixel value""" r = pixel & 255 g = (pixel & (255 << … | |
Re: Don't give up, just keep going ... [code=python]s = "1#%$^5hbg458#$54bjyfuig324ghal&%90a11y$#6ty7" str_digits = ''.join([c for c in s if c.isdigit()]) str_nodigits = ''.join([c for c in s if not c.isdigit()]) str_comp = ''.join([c for c in str_digits if int(c) in (4,6,8,9)]) str_prime = ''.join([c for c in str_digits if int(c) in … | |
Re: I like C# in Windows Applications, and find the flow of the code much easier to follow than that of the corresponding C++ code . Some folks say that C# is a mix of Java and C++. I think of it as Delphi in a classy C++ coat, with the … | |
Re: 1) Compare the break indentation in p1move() to p2move() also keep your indentation levels uniform 2) [B]elif p1move1 != 'a' or 'b' or 'c' or 'd' or 'e' or 'f' or 'g':[/B] should be [B]elif p1move1 not in 'abcdefg':[/B] 3) There is a lot of unneeded code 4) All those … | |
Re: Portable Python from: [url]http://www.portablepython.com/[/url] Makes Python25 portable enough to run from a small USB flash drive. It comes with the very capable editor SciTE.exe preconfigured to run on portable Python. Simply run your Python code from SciTE (press the F5 key). You can plug this USB flash drive into any … | |
Re: What do you expect this dictionary to look like? Let's say muns = ['41', '82', '2', '61', '7', '33', ...] | |
Re: The .NET Framework combines a number of languages. If you want to create Windows GUI programs, C# would be the choice. I parked a number of Csharp snippets on DaniWeb, click the Code Snippets on the top of this page. Look the short code samples over, and see if you … | |
Re: The Tkinter widget Label has a default border width of 2, so use bd=0 like shown here: heading = tk.Label(self.heading_frame, image=savvy_bar1, bd=0) | |
Re: Function calls are time expensive in Python, so I modified Sneekula's count_char2() approach by replacing all those calls to islower(), isupper(), isdigit() and isspace(), and also changing the order of if/elif to use the most common character test first. The result is promising ... [code=python] # timing character count by … | |
Re: If you are using the wxPython GUI toolkit, I can help you. Take a cursory look at: [url]http://www.daniweb.com/forums/showpost.php?p=777681&postcount=104[/url] I am not certain if Tkinter has anything available to do that kind of thing. | |
Re: The {0} is new in Python30 and indexes a formatted print()... [code=python]print("the {0} goes {1}!".format("dog", "woof")) # the dog goes woof! print("{1} goes the {0}!".format("dog", "woof")) # woof goes the dog! [/code] For more details see also: [url]http://www.daniweb.com/forums/post761691-154.html[/url] | |
Re: I never knew what real happiness was until I got married, and by then it was too late. | |
Re: [QUOTE=The Dude;772588]A virtual archive of wills and other documents from some of historys famous people. [url]http://dude111.fileave.com/famous.pdf[/url][/QUOTE] Very interesting stuff. | |
Re: Very simple ... [code=python]list1 = ['1','2','3'] list2 = ['4','5','6'] list3 = ['7','8','9'] all = list1 + list2 + list3 print(all) # ['1', '2', '3', '4', '5', '6', '7', '8', '9'] del list1 del list2 del list3 [/code] Note: You should open a new thread for unrelated questions and give the … | |
Re: [QUOTE=evstevemd;768548]I use one tab or four spaces They give me no problem, so I guess: 1Tab = 4spaces[/QUOTE]I think Ene is right here, please don't use tabs for indentations, they are bound to mix with spaces! I actually noticed one of evstevemd's wxPython code samples that I copied and pasted … | |
Re: [QUOTE=Ancient Dragon;722923]... Something, or someone, had to create the universe -- it didn't just happen out of nothing. Even if you believe the Big Bang theory, someone had to create that mass that exploded. ...[/QUOTE]In that line of thinking, who created the creator? Big Bang only relates to the universe … | |
Re: I left a few notes on Python30 here: [url]http://www.daniweb.com/forums/showpost.php?p=761691&postcount=154[/url] Python30 will modernize the language. The I/O changes, like print() and input(), will effect us the most. Future posters will have to tell us which version of Python is used. | |
Re: Okay, this is what I tried ... [code=python]import random word = raw_input("Enter a word: ") wordsize = len(word) randomnumber = random.randrange(0, wordsize) c = word[randomnumber] print c, c.isdigit() """ one result after entering hello --> Enter a word: hello l False <--- this means that l is the letter l … | |
Re: I assume you used pygame-1.8.1release.win32-py2.6.msi | |
| |
Re: Kenneth C. Davis' "Don't Know Much About Mythology" strikes my fancy. | |
Re: Something like this can do ... [code]s = 'print "Hello!"' exec(s) [/code] | |
| |
Re: Here is an example ... [code=python]# using the module ctypes you can access DLLs written in C/C++ # ctypes converts between Python types and C types # there are two ways to write DLLs: # most common uses cdecl, import with cdll # Win and VB may use stdcall, import … | |
Re: Which editor are you using. My guess is that you are using PyScripter. | |
Re: Well, Microsoft could have come up with something less childish, but then they have pretty much a monopoly in the PC OS market. There was not really an incentive to do better. | |
Re: A little twist here, the Python24.dll contains all the PyEval routines and they are most likely written in C. So I wonder, if you couldn't access them directly from the dll in your C/C++ program. | |
Re: I might be fishing here, but is this a Macintosh binhex4 format file? | |
Re: Strange, in onCheck() I did a few testprints ... print self.player.Load(path) --> True print self.player.Play() --> False, should be True print self.player.Length() --> 0, should be > 0 It seems to load the media file correctly. Actually, when you load an .avi file and press stop the first frame shows. … | |
Re: To bad there are only 10 choices maximum to give a poll at DaniWeb. I guess string instruments have to put under guitar. I like the viola. |
The End.