244 Posted Topics

Member Avatar for rupeshpradhan

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 …

Member Avatar for shadwickman
0
154
Member Avatar for rustysynate

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!

Member Avatar for rustysynate
0
156
Member Avatar for The Champ

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 …

Member Avatar for shadwickman
0
107
Member Avatar for aakaashjois

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]

Member Avatar for shadwickman
0
133
Member Avatar for flip121

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 …

Member Avatar for flip121
0
83
Member Avatar for tomtetlaw

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?

Member Avatar for shadwickman
0
125
Member Avatar for rustysynate

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 …

Member Avatar for rustysynate
0
88
Member Avatar for sravan953

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 …

Member Avatar for Stefano Mtangoo
0
134
Member Avatar for tomtetlaw

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 …

Member Avatar for tomtetlaw
0
288
Member Avatar for leegeorg07

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 …

Member Avatar for leegeorg07
0
2K
Member Avatar for yamman13

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 …

Member Avatar for jlm699
0
68
Member Avatar for poeticinsanity

The constructor has two underscores on either side of the name. [icode]def __init__(self)[/icode].

Member Avatar for poeticinsanity
0
90
Member Avatar for max.yevs

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

Member Avatar for shadwickman
0
174
Member Avatar for dinilkarun

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 …

Member Avatar for lllllIllIlllI
0
139
Member Avatar for Whelk

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 …

Member Avatar for shadwickman
0
149
Member Avatar for shadwickman

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

Member Avatar for shadwickman
0
123
Member Avatar for Joe Hart

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 …

Member Avatar for shadwickman
0
167
Member Avatar for faniryharijaona

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 …

Member Avatar for faniryharijaona
0
111
Member Avatar for eyewirejets

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 …

Member Avatar for eyewirejets
0
86
Member Avatar for mbirame

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 …

Member Avatar for mbirame
0
1K
Member Avatar for srk619

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 (): …

Member Avatar for srk619
0
160
Member Avatar for TheBeast32

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 …

Member Avatar for Narue
0
197
Member Avatar for massivefermion

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 …

Member Avatar for BestJewSinceJC
0
122
Member Avatar for srk619

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.

Member Avatar for srk619
0
146
Member Avatar for BlueNN

Just a quick question, is this Python 3.0 or 2.6? EDIT: nevermind, that was the stupidest question...

Member Avatar for adam1122
0
114
Member Avatar for BlueNN

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 …

Member Avatar for BlueNN
0
145
Member Avatar for adling11

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

Member Avatar for rahul8590
0
75
Member Avatar for shadwickman

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 …

Member Avatar for shadwickman
0
2K
Member Avatar for Straightone

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 …

Member Avatar for GrimJack
0
2K
Member Avatar for Malestryx

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 …

Member Avatar for woooee
0
106
Member Avatar for silverflashh

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 …

Member Avatar for shadwickman
0
94
Member Avatar for tomtetlaw

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 …

Member Avatar for shadwickman
0
87
Member Avatar for wolih

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 …

Member Avatar for tomtetlaw
0
102
Member Avatar for tomtetlaw

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

Member Avatar for adam1122
0
105
Member Avatar for SDS20

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 …

Member Avatar for SDS20
0
129
Member Avatar for pythonnewbie1

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.

Member Avatar for jlm699
0
227
Member Avatar for kiddo39

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 …

Member Avatar for lllllIllIlllI
0
147
Member Avatar for tomtetlaw

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 …

Member Avatar for tomtetlaw
0
609
Member Avatar for sharat87

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 …

Member Avatar for sharat87
0
4K
Member Avatar for lilkid

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 …

Member Avatar for lilkid
0
164
Member Avatar for jessica2009

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

Member Avatar for woooee
0
139
Member Avatar for shadwickman

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

Member Avatar for shadwickman
0
116
Member Avatar for crumpet

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 …

Member Avatar for crumpet
0
154
Member Avatar for DisembodiedLoaf

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 …

Member Avatar for shadwickman
0
181
Member Avatar for jessica2009

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 …

Member Avatar for jessica2009
0
103
Member Avatar for akmed
Member Avatar for AHUazhu
0
127
Member Avatar for Se7Olutionyg

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 …

Member Avatar for shadwickman
0
130
Member Avatar for jworld2

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.

Member Avatar for jworld2
0
118
Member Avatar for shadwickman

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 …

Member Avatar for shadwickman
0
115
Member Avatar for shadwickman

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

Member Avatar for daviddoria
0
347

The End.