244 Posted Topics
Re: I don't have time to fully check through all the above code right now, but if you're interested in the guidelines for standardizing Python code, you can have a read through [URL="http://www.python.org/dev/peps/pep-0008/"]PEP 8[/URL]. And as just a speculation, if you're importing this module to use in another program, but don't … | |
Re: You haven't re-blitted the entire screen, i.e. refilled every pixel of it in order to fully wipe + refresh it. For this, add a [icode]screen.fill((0,0,0))[/icode] before you re-blit the rectangle. This will cover the screen in black again before redrawing the new rectangle. Hope that helps! | |
Re: Just as a late clarification, lists are fairly different in Python from Arrays in C. I find lists [i]much[/i] more pleasant to use, because: - they are dynamically resizable, and no set length needs to be declared upon initialization, but you can't assign a value to an index past the … | |
![]() | Re: I use wxGlade when I'm not making the interface purely by coding, and I'd definitely suggest it. It [i]did[/i] take me a little messing and tinkering around with to get the hang of it, but it's definitely worth the effort. Edit: Here's the wxGlade user manual: [URL="http://wxglade.sourceforge.net/manual/index.html"]http://wxglade.sourceforge.net/manual/index.html[/URL] and tutorial: [URL="http://wxglade.sourceforge.net/tutorial.php"]http://wxglade.sourceforge.net/tutorial.php[/URL] |
Re: Well for starters, your List construction will cause an error as there is a comma after the 3rd string, which is the last index so it shouldn't have the comma after it. Here's an example I think will help: [code=python] mylist = [ 'abcdefg', 'hijklmno', 'pqrstuv' ] listindex = 2 … | |
Re: Can't you just keep track of a virtual camera position tuple, then when everything blits to the pygame display, adjust them by the camera's position? | |
Re: There's always [URL="http://www.pygame.org/news.html"]pygame[/URL] if you want to check that out, and the PIL mixed with a GUI toolkit would also be a good bet. [URL="http://www.wxpython.org/"]wxPython [/URL]is my toolkit of choice. Your idea of "dynamic" image rotation simply would be a while loop continuously redrawing the image with a new rotation … | |
![]() | Re: My first thought would be to use a separate thread to handle a function waiting for user input. Then if it receives the signal to quit, it terminates the program. You can use the [icode]threading[/icode] module to accomplish this. I don't know if this is considered to be a no … |
Re: So what you mean is that you have a sort of 'map' saved as an image as either black or white - white being spaces available to move to, and black being blocked sections (obstacles)? If so, my idea would be to use the [URL="http://www.pythonware.com/products/pil/"]Python Imaging Library (PIL)[/URL] in order … | |
![]() | Re: I know that this is slightly unnecessary but I can't stand the sight of the above code. I don't know if your colour codes are right (I didn't test them), but this is just a [i]much[/i] cleaner way of writing your little program. Just putting the simplicity of Python to … ![]() |
Re: What exactly is the filename of the file you're trying to import? It shouldn't be "file" because that's already a reserved word in Python, so it'll cause problems. And you wrote "From", yet it should be all lowercase ("from"). Drop the .py extension of whatever file you're importing too, so … | |
Re: The constructor has two underscores on either side of the name. [icode]def __init__(self)[/icode]. | |
Re: How about: [code=python] for number in b: if number in a: a.remove(number) [/code] That should go through each number in b and remove it from a if it appears in a... | |
Re: I'm not entirely sure what you mean by a 'grid', but if you only want to accept numeric input, you can use a function like this to return it: [code=python] def getNum(): while True: n = raw_input('Enter a number:') try: n = float(n) # or int(n) if you want an … | |
Re: I've never tried this, nor has it crossed my mind. But it seems like it would be a great idea for sharing simple Python programs with friends without making them install Python first (damn you, Windows!). A [i]HUGE[/i] online undertaking using Python is EVE-Online, which is a MMORPG on an … | |
This technically isn't fully a Python-related question, but I couldn't find a better place to post it than here. I'm just curious about how to get/update weather information from the internet... like say that sidebar gadget in Vista that updates the weather and temperature from some online-source. The problem is, … | |
Re: Is it just me or does this make no sense? Just to clarify, the code you posted between your "code tag starts/ends here" tags is in what language? Obviously it's not Python, so what is this "correct format" you're taling about? Are you asking for a program to be written … | |
Re: Maybe if you just set it so that the function call to 'setlink' happens at the end of the '__init__' function. This will make the function call for 'setlink' happen automatically, but you will need to pass the cargo values to the class on initialization, otherwise it won't have the … | |
Re: I'm highly confused... so what are you asking to call? Assuming you have the attributes [i]__employee_name[/i] and [i]__employee_number[/i] on the class this function is a part of, this should run fine... So I'm going to assume that the objects in this list you mentioned are instances of this class, in … | |
Re: I haven't fully confirmed this, but it would involve a change to this section: [code=python] # For each item, create a CalendarEvent object for item in input_csv: hour, minute = item[2].split(':') event = CalendarEvent() event.interval_from_start = int(item[0]) event.description = item[1] event.hour = int(hour) event.minute = int(minute) event_list.append(event) [/code] You could … | |
Re: Please use CODE tags! It's pretty much essential for Python so I can tell if your indentation is off. That being said, I put your code in tags for you: [code=python] myinput = raw_input() # Grab raw keyboard input int_string = "12345.9876" for c in myinput : if c.isdigit (): … | |
Re: I started out a few days ago, and one of the first things I did was follow Narue's guide (a member here on DaniWeb). Here's the PDF of it: [url]http://www.daniweb.com/forums/attachment.php?attachmentid=1765&d=1142611276[/url] It uses [URL="http://www.nasm.us/"]NASM[/URL] and GCC (for Windows, use can use the [URL="http://www.mingw.org/"]MinGW[/URL] binaries for that). Narue's little guide was a … | |
Re: I can answer 1 and 3 for you right now. 1. As far as I know, Assembly IS machine language. It's the actual instructions that get passed to the CPU. Hence having to manually keep track of [i]a lot[/i] of things that high-level languages do for you automatically. 3. Assembly … | |
Re: Everyone else is right. Please show some effort of your own; attempt the problem and then post the code you have so far. We can try to point out hints from there. P.S. Remember to use CODE tags. We need to see your indentation. | |
Re: Just a quick question, is this Python 3.0 or 2.6? EDIT: nevermind, that was the stupidest question... | |
Re: Yeah, as soon as the script is done in the command prompt, it'll exit. So put something like waiting for input at the end so that it pauses the program. Alternatively, you could always make a batch (.bat ) file to run instead with the lines: [code] python "path\to\my\file.py" pause … | |
Re: [QUOTE=adling11;837746]please i need it[/QUOTE] Way to show tremendous effort on your part. Not only did you not attempt it yourself, you didn't even specify the architecture (can I assume x86?) or the compiler (NASM? MASM? etc). I can't really write too much code until I know those details. Don't try … | |
Hello! I just started trying to get the grasp of Assembly a few days ago, so I decided to write a program to print the Fibonacci numbers up to the 25th one. I'm using NASM, and it's for the x86 processor. I came up with this code, but it'll loop … | |
Re: To start, '==' is not how you assign a value to a variable. Use '=' for that, as '==' checks for equality. Change those first few lines that have that (the ones assigning the letter to decimal values). And, you can't assign a int value to a str value. You … | |
Re: PLEASE use code tags; re-edit your above post. As you can see, your indentation gets lost without them, and it's essential for Python. Shouldn't [code=python] if h <= 0: print "Can't work less than 1 hour a week!" [/code] be changed to [code=python] if h < 1: print "Can't work … | |
![]() | Re: Ah, are you using Python3.0 or 2.6? In 2.6, the above would be acceptable, but 3.0 does some major overhauls on the grammar, including changing the above, so it would need to be [code=python] print( "Hello Monty Python!" ) [/code] I would suggest downloading Python 2.6 and using that to … |
Re: Yay! I've been wanting to do this for a while, but never got around to completing this sort of thing on my own :) I'd enjoy working on a project like this (as long as its in Python, no Java or C++ please :P) P.S. There is a Game Development … | |
Re: I'd do this: [code=python] def CreateWarrior(name): def __init__( self ): self.attributes = { #ID "name": name, "age": 18, #Developed "strength": 0, ##Wrestling "reflexes": 0, "speed": 0, "intelligence": 0, "discipline": 0, "physcondition": 0, #Body "fat": 0, "muscle": 0, "hunger": 0, "sleepiness": 0, "health": 0, "damage": 0, #Psychological "mood": 0, # 0 … | |
Re: Nothing huge, but [code=python] print "You notice that the door is locked, so you should" print " probably find a key." [/code] should have the space on the end of the first line, just to keep it consistent with the lines above it. Also, "did'nt" and "definitley" are spelling errors. … | |
Re: What exactly do you want returned by the __len__ function? The length of the genre string, the title string, album string, etc? Or do you want it to return something to do with some of those strings being blank? Also, as far as I know, [icode]len()[/icode] is for strings, but … | |
Re: Um, I think you missed the part about code tags. You need to use them in order to preserve indentation! I can't be bothered to help until you've done that. | |
Re: I guess if you know how many pixels wide the image is, you could just figure out what indices correspond to the cut-off for each row in the list. Like if an image was 10 pixels wide, then items 0 - 9 in the list would correspond to the first … | |
Re: Can I see the rest of your code? I don't use Tk (I find wxPython to be much better), but what happens if you replace that line with [code=python] tk.FileDialog.askopenfilename() [/code] Of course, that would assume tk has a class named FileDialog and that you use Tkinter like [code=python] import … | |
Re: I don't know about awk, but I what would happen if you changed [code=python] ot, et = ex.communicate('''abc def ghi jkl mno''') [/code] to [code=python] ot, et = ex.communicate('abc\ndef\nghi\njkl\nmno') [/code] It just didn't seem to like something about the triple-quoted string. But of course I could be completely off seeing … | |
Re: EDIT: The below isn't too helpful as vegaseat posted a better (and full) verison. What do you mean by [code=python] d={"flight":T34712, From:ABERDEEN, scheduled 0800, remark landed} [/code] The other keys need to be enclosed in quotes to, so that [code=python] d['flight'] = 'T34712' d['from'] = 'ABERDEEN' #etc... [/code] The best … | |
Re: Well, I would love to help you, but your post contains no indentation *at all*. PLEASE post your code in CODE tags! I can't help you if any code you post doesn't contain your indentation. So, re-post your code (or edit the above, preferably) and wrap it in `[CODE]` tags! … | |
Hello, I've loved Python ever since I picked it up a couple years ago, but I have a question about the proper way to do something. There's a way of condensing an if/else conditional that has 2 options (True, False), for simple things. Assume that [icode]playerWins[/icode] is a boolean: [code=python] … | |
Re: I would say you could take the input string, and split it at each whitespace into a list. Index 0 would be the function name, and each index after would be the arguments. Like: [code=python] cmdlist = usercmd.split(' ') # split at each space [/code] This would make a list … | |
Re: Wrapping your code in the BB code tags is usually essential (keeps indentation), so remember to do it next time. [b]First Program[/b] For the first program, [icode]raw_input[/icode] returns a string, therefore when comparing the values, you're comparing something like [icode]"3" + "5" < "9"[/icode] (i.e. "35" < "9"). This is … | |
Re: Why not keep a list of lists for responses corresponding to each user answer? Such as: [code=python] responses = [ ["Q1, A", "Q1, B", "Q1, C" ], ["Q2, A", "Q2, B", "Q2, C" ], ["Q3, A", "Q3, B", "Q3, C" ] ] [/code] and if you collect the user input … | |
Re: please edit your first post and place your code in CODE=cpp tags. | |
Re: You can't use: [code=cpp] float theta, float cotheta, float sitheta, float distance, float velocity, float time, float height; [/code] Instead, just put [icode]float[/icode] once before the whole line. Like cikara21 said: [code=cpp] float theta, /*float*/ cotheta, /*float*/ sitheta, /*float*/ distance, /*float*/ velocity, /*float*/ time, /*float*/ height; [/code] Ah! Beaten to … | |
Re: Why don't you try using a wxListBox set with the style flag for allowing only a single item to be selected at once? It's a simple solution if you're using wxPython. | |
Hi, I was wondering what was wrong with the following code. It creates a [i]vector <int>[/i] and assigns it the values 0 - 51. Then it shuffles these values and prints it to the screen. When I compile it, I get no errors, but when it runs, it throws an … | |
Hi, I'm really confused now about how to return an int[] from a C++ function. Inside the function, I need to dynamically resize the array, but at the end I want the variable returned to be an array, not a pointer, but I have no idea how to do this: … |
The End.