761 Posted Topics
Re: This was the first result from googling "ubuntu install pygame": [URL="http://www.pygame.org/wiki/kubuntu"]http://www.pygame.org/wiki/kubuntu[/URL] One of the best things about Ubuntu(Linux in general) is that it has such a huge open-source user base that almost every question you have has a detailed guide online of how somebody else did it. | |
Re: The communicate method "reads all of the output and waits for child process to exit before returning" [[URL="http://blog.doughellmann.com/2007/07/pymotw-subprocess.html"]Source[/URL]], so in order to work with a program that expects multiple inputs you'll need to communicate with the stdin of the process as such: [code=python] proc = Popen('./Ex.sh', shell=True, stdin=PIPE, stdout=PIPE) proc.stdout.readline() … | |
Re: Use code tags when posting code in this forum, or else nobody will be willing to help you: [noparse][code=python] # Code goes in here [/code][/noparse] When using the [icode]__str__[/icode] method you have to make sure that you are returning a string. Here's an example of proper usage: [code=python] >>> class … | |
Re: Maybe it would be easiest to uninstall and re-install Python. Perhaps you should look at adopting a new IDE as well (I'm sorry I just can't stand IDLE!) | |
Re: I suggest learning the basics of Python before trying to use it as a web platform. I highly recommend [URL="http://diveintopython.org"]dive into python[/URL], which is a free book online that is geared for programmers that already know the basics of writing code in general (control flow, data structures, etc.) Python wasn't … | |
Re: I don't believe that there is... startfile simply launches the program as if it had been executed from the command prompt/shell... It doesn't return anything as far as I can tell, so my answer would be no. But perhaps there is a way. | |
Re: This isn't necessarily appropriate for the Python forum but: [code] len_x = size(x) for i = 1:len_x x(i) end [/code] Now forgive me, I haven't used Matlab in years; however if you need more help you'll find the [URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_product_page.html"]MATLAB docs here[/URL]. | |
Re: To use code tags: [noparse][code=python] # This is my PYTHON code # It goes between the code(=syntax) brackets [/code][/noparse] If you use code tags your question will be easier to read, thus easier to answer by our forum members | |
Re: [QUOTE=lorayyne;856567][code] N = int(raw_input('Welcome to the HTH-HTT Head-to-Head! How many times do you want to flip the coin per trial? I recommend at least 20: ')) trials = int(raw_input('How many trials do you want to run?: ')) while x < trials: coinflip.htthth(N) if coinflip.htthth('hthCount') == 1: hth += 1 x … | |
Re: Please follow the forum guidelines when posting, most importantly when you post code. If you don't use code tags the code turns out as it did above and nobody wants to look at the crazy wall of unformatted text. Use code tags like this when posting code in this forum: … | |
Re: [QUOTE=Undermine;857549]Would i just do something like if choice ==1 : do this if choice ==2: do this ect?[/QUOTE] Yeah pretty much. That's the most straight forward way to approach this problem [code=python] usr_inp = raw_input( 'Enter your choice (1-3): ' ) if usr_inp == '1': # do something for 1 … | |
Re: You're more likely to get help if you follow the posting guidelines for this forum, including but not limited to using code tags, showing effort, and providing simple examples of reproducible errors. After skimming over your crazy long post I'll give you an example of asking the user for input … | |
Re: Yeah, sure thing. I don't know if generating it will be as easy as your [icode]zeros[/icode] but here's an example: [code=python] >>> mtrx = [[(0,0),(0,1),(0,2),(0,3)], ... [(1,0),(1,1),(1,2),(1,3)], ... [(2,0),(2,1),(2,2),(2,3)], ... [(3,0),(3,1),(3,2),(3,3)]] >>> mtrx[2][1] (2, 1) >>> mtrx[2][1][0] 2 >>> mtrx[2][1][1] 1 >>> [/code] HTH | |
Re: Have you followed [URL="http://trac.edgewall.org/wiki/TracGuide#TheTracUserandAdministrationGuide"]the Guide[/URL] with step-by-step instructions of how to setup and use TRAC? There's a link to it right there on the first page. | |
Re: If you simply double click on a [icode].py[/icode] or a [icode].pyw[/icode] icon Python will open and run the script in a command window, just as vega mentioned above... Keep in mind however that if your program has bugs and crashes, the command window will close as soon as Python is … | |
Re: [QUOTE=adam1122;851692][icode]height = principal * 0.02 TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'[/icode] 0.02 is your float and * is your operand. That only leaves principal to be your NoneType. At another point, you are setting principal equal to the return value of a function that doesn't return anything. … | |
Re: Yeah I think [icode]split()[/icode] would probably be your best bet. Either that or [icode]replace[/icode]: [code=python] >>> some_text = '"http://www.nzherald.co.nz/nz/news/article.cfm?c_id=1&objectid=10568455&ref=rss" Man arrested after pointing fake gun at police (A 59-year-old man has been arrested after pointing an imitation gun at police from his car in Paekakariki, north of Wellington, this morning.\r\n\r\nWhen … | |
Re: Sure, we can help! Just remember to follow the [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]forum rules[/URL], and pay attention to the posted announcements ([URL="http://www.daniweb.com/forums/announcement114-3.html"]here[/URL] and [URL="http://www.daniweb.com/forums/announcement114-2.html"]here[/URL]), and there won't be any problems. [URL="http://www.daniweb.com/forums/post822799-3.html"]This post[/URL] by vegaseat should get you started... | |
Re: You'll have to adapt your code to the website's new layout/API/whatever. Maybe you could provide more details and a little code so that we have some idea of what you're talking about. | |
Re: If a call to the DLL returns '2' then that's not a Python error code, that's just what the DLL is returning. I'd suggest using the DLL in another language in the same way to see if you get the same error code. | |
Re: You'll have to write those sort algorithms yourself. Or search google. To sort a list in Python: [code=python] my_list = [1,5,2,8,3,4,7,6] my_list.sort() [/code] | |
Re: Please use code tags when posting code. [noparse][code=python] # Put your code inside here [/code][/noparse] As far as Python input methods you can use raw_input to prompt the user for input: [code=python] usr_inp = raw_input( 'Please enter a directory: ' ) print 'The user entered:', usr_inp [/code] | |
Re: [QUOTE=harrykokil;851366]i want to integrate the above code in this tkinter a window but its not working.[/QUOTE] What's not working? Are you getting an error? Your "tkinter a window" doesn't work for me. It never generates any windows and just hangs, so I'm not sure what you're looking for. | |
Re: [QUOTE=gnujohn;846401]# we should not be a service to solve interesting lab projects. This one clearly is just that, a request for help in CS 380.[/QUOTE] This is true, but thankfully the OP came with example code and exactly what his difficulty is. Most people come into this forum and simply … | |
Re: I think that you overlooked what adam was saying in his first post. If two straight lines are not parallel and are not the same line, then they must intersect as some point. Unless you need to figure out the exact point of intersection, you can simply use if-else logic … | |
Re: [QUOTE=daviddoria;850764]thanks, that's a good start for now, but eventually it would be nice to do [code] --files *.txt --Size 4.2 --Duration 5 [/code] Dave[/QUOTE] I'm not entirely clear on what you're trying to do, but if you want to get all files in a directory that are *.txt you can … | |
Re: [QUOTE=daviddoria;850691]Also, how do you handle required options? I saw a lot of threads about a philosophical debate of if options can be required, but no information on how to actually use them. Dave[/QUOTE] This is from the [URL="http://docs.python.org/library/optparse.html"]optparse doc[/URL]: [QUOTE]required option an option that must be supplied on the command-line; … | |
Re: You need to change the definition of con() to support the event details that get automatically passed to any bound method. The new definition should look like this: [code=python] def con(self, event=None): [/code] Note that I initialized event to None so that you can still call it yourself without needing … | |
Re: You should be using return values instead of global variables... see if this makes any sense, and if not ask questions. [code=python] >>> import random >>> def get_ran(): ... return random.randint(1,10) ... >>> get_ran() 5 >>> get_ran() 10 >>> get_ran() 4 >>> hp = 100 >>> hp -= get_ran() >>> … | |
Re: Well first problem is that you're never clearing the contents of your list [icode]b[/icode]. Also, you should move the summation of b outside of the for loop so that it only happens once you've found all the factors of the desired number... That should get you pointed in the right … | |
Re: Do you mean a binary number with 24 bits or an integer with 24 digits? | |
Re: [QUOTE=planetPlosion;850479]So, apparently the for statement makes my guesses worse. Thanks in advance[/QUOTE] Look at what [icode]range(15)[/icode] and [icode]range(1,15)[/icode] produce: [code=python] >>> range(15) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] >>> range(1,15) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … | |
Re: The "built in" module would be Tkinter, but if you're looking for something simple that will generate native-looking GUIs with minimal effort I would suggest wxPython. There's a wealth of tutorials and sample code in this forum that you are welcome to use (refer to the sticky wxPython samples thread … | |
Re: [QUOTE=phillip1882;850127][code]def fibonacci(a,b,n): [COLOR="Red"] a =a+b b = a+b[/COLOR] n= n-2 if n ==0: [COLOR="Red"] print b return b[/COLOR] elif n ==1: [COLOR="Red"] print a return a[/COLOR] else: fibonacci(a,b,n) x = fibonacci(1,1,7) print x [/code] i get none as the x value but a legitimate integer as the a or b … ![]() | |
Re: You use [icode]print[/icode] to print anything in Python. Since your functions are returning values, you can use [icode]print[/icode] to output those values. | |
Re: [QUOTE=max.yevs;849624]my apologies, once again i've found the answer before anyone could reply [code]x = [] for n in range(5): x.append(n)[/code][/QUOTE] You're taking the long way here. Look: [code=python] >>> x = range(5) >>> x [0, 1, 2, 3, 4] >>> [/code] | |
Re: The problem is that since you have [icode]elif guesscount == 4:[/icode] as a condition in an if/elif/else block, it never gets evaluated. The first two conditions are absolute: [code=python] if guess in word: print 'Yes' elif guess not in word: print 'No' [/code] The user's choice is either going to … | |
Re: You need to stop recursing your main function, it's going to get you in trouble. Here's an example using a while loop. [code=python]import time def main(): a = 0 while True: print (a) time.sleep(5) a += 1 main()[/code] EDIT: I didn't notice the other thread about this same problem, in … | |
Re: [QUOTE=khozamtho;847984]how to compile and run a python file,and how to change a directory in Python25.what should i import first in order to run a python code.like import math and ......[/QUOTE] If you are trying to run a python script that is titled [icode]my_script.py[/icode] from the command line (you could alternately … | |
Re: Here's a way to avoid printing the empty line: [code=python] for line in my_text: line = line.strip() if line: print line # The 'else' condition here is an empty line, which we don't print [/code] | |
Re: I'm sorry can you provide more detail? Your question isn't exactly clear... | |
Re: I don't understand your first question.. can you clarify what you mean by non-unique random numbers? That being said, I find the best way to have a program run continuously is a super loop. Example: [code=python] import time def main(): print "I'm the main function!" # Do some other stuff … | |
Re: Instead of sleeping for the user to see the end message you can place an input at the end of your program so that the user has to hit <Enter> to quit like this: [code=python] # This is the last line of code raw_input( "Press <Enter> to exit..." ) [/code] | |
Re: [QUOTE=-obol-;847982]how to split a string of words into pieces [/QUOTE] Use the [icode]split()[/icode] method like so: [code=python] >>> my_phrase = "the sun is shining" >>> my_phrase.split() ['the', 'sun', 'is', 'shining'] >>> [/code] [QUOTE=-obol-;847982]and print on separate lines[/QUOTE] As you can see from above, [icode]split()[/icode] returns a list containing each word … | |
![]() | Re: [QUOTE=leegeorg07;847599]i tried that in the cmd promt and it said that 'python wasnt a proper command'[/QUOTE] You need to use the full path to python.exe if it's not in your PATH variable... So instead of [icode]python path_to_2to3 my_program.py[/icode] you would need [icode]C:\\Python26\\python.exe path_to_2to3 my_program.py[/icode] Or which ever version of Python … ![]() |
Re: Try removing the following two lines from your board() function and placing them between num_players and board() at the bottom of your script like so: [code=python] Num_Humans() root = Tkinter.Tk() root.attributes('-topmost', True) Board() [/code] I hope that's what you were looking for EDIT: As far as tips here's my first: … | |
Re: Each tuple in that list has an instance of scrobble.Track, which contains an instance of scrobble.Artist; however the tuple itself does not have those attributes. I'm not entirely sure on the specifics of the scrobble module, but a way to unpack the tuple would be like this: [code=python] for tracks … | |
Re: [QUOTE=Mearah;846573] "cross platform (windows + linux)" This is possible. What you have to keep in mind, that if you are creating some GUI (with TkInter e.g) then it looks quite differentwith windows and linux, so you maybe could test the "look&feel" of your work with both os [/QUOTE] I'd go … | |
Re: [QUOTE=pong pong;846801]hi I want to write this code in do while or if else, or any other way except for loop. here is the code [CODE]for i in range(65,90): for j in range(65,90): for k in range(65,90): token=chr(i)+chr(j)+chr(k) block = ((i<<16)+(j<<8)+(k)) cblock = pow(block,e,n) table[token]=cblock[/CODE] can anyone please help me … ![]() | |
Re: [QUOTE=max.yevs;847064]anyone know the command to define n?[/QUOTE] [code=python] n = #something # For user input use: n = raw_input( 'This is a prompt: ' ) [/code] |
The End.