Search Results

Showing results 1 to 40 of 45
Search took 0.01 seconds.
Search: Posts Made By: slate
Forum: Python Oct 25th, 2009
Replies: 17
Views: 475
Posted By slate
You can use the observer pattern.


class Observed(object):
def register_observer(self,observer):
self.observer=observer
def notify(self):
self.observer.update(self)
...
Forum: Python May 29th, 2009
Replies: 2
Views: 261
Posted By slate
Let me give you an example.
There are two files. The first is compute.py and has the code:

def sumup(a,b):
return a+b


And there is your program, main.py

import compute
Forum: Python May 29th, 2009
Replies: 3
Views: 505
Posted By slate
First of all, please read this (http://www.daniweb.com/forums/announcement114-3.html). It is on the very beginning of the forum. Your indent cannot be reconstructed from your post, so your code can...
Forum: Python May 29th, 2009
Replies: 7
Views: 471
Posted By slate
Your code is not intended in the function.

try:

def getText(inFile):
text=[ ]
file = open( inFile, "r" )

for line in wholefile:
line = line.strip()
Forum: Python May 26th, 2009
Replies: 5
Views: 339
Posted By slate
Have you checked the firewall?
Try open the server port higher (>5000).

Check out if minimal (http://www.prasannatech.net/2008/07/socket-programming-tutorial.html) implementations are working.
Forum: Python May 26th, 2009
Replies: 7
Views: 471
Posted By slate
If you simply drop the else part, then you will have all lines in the text, which do not begin with "<" and do not end with ":>"

for line in wholefile:
line = line.strip()
if...
Forum: Python May 26th, 2009
Replies: 7
Views: 471
Posted By slate
Please (http://www.daniweb.com/forums/announcement114-3.html) use code tag.

I see two problems with your code:
1. No data will be written to the text list. Its a logical thing, you know.:) If...
Forum: Python May 24th, 2009
Replies: 7
Views: 314
Posted By slate
I think this is, what you need:
http://www.pygame.org/docs/ref/key.html#pygame.key.get_pressed

Look at the comments, too.
Forum: Python May 24th, 2009
Replies: 4
Views: 383
Posted By slate
Maybe I do not see your problem clearly.

I thought the problem was, that your blue riflemen does not move.
In my previous post, I showed you how you can move it.

I took this answer from the...
Forum: Python May 23rd, 2009
Replies: 4
Views: 383
Posted By slate
Maybe reading a tutorial is helpful. I have never written a pygame game, all my answers come from googling pygame tutorial and getting the code from there.
For example, the problem in this thread is...
Forum: Python May 23rd, 2009
Replies: 1
Views: 468
Posted By slate
In your other thread (http://www.daniweb.com/forums/thread193501.html) the image shows up. I've checked.
Forum: Python May 23rd, 2009
Replies: 4
Views: 383
Posted By slate
You should check the type first, and if it is a keyboard event, than get the key pressed.

while True:
clock.tick(60)
p.update()
for event in pygame.event.get():
...
Forum: Python May 21st, 2009
Replies: 7
Views: 561
Posted By slate
This is not true, or you did not show us that. Your code does not produce the desired output, and it is not, that it has numbers instead of characters.

I think the problem:

is solved.

Please...
Forum: Python May 21st, 2009
Replies: 5
Views: 561
Posted By slate
o.write(temp[i])
o.write("\n"*2)
Forum: Python May 21st, 2009
Replies: 7
Views: 561
Posted By slate
You can use the magic of ascii:)

ord("a")==97
chr(97)=="a"
Forum: Python May 14th, 2009
Replies: 6
Views: 790
Posted By slate
http://docs.python.org/library/site.html
Forum: Python Mar 20th, 2009
Replies: 6
Views: 1,088
Posted By slate
Signal only woks in main thread, in the process that is.

Basically threading is not for "mortals". Not even in python. But you can be a hero:) I am not one.
For instance killing a thread from the...
Forum: Python Mar 20th, 2009
Replies: 6
Views: 1,088
Posted By slate
Maybe? (http://code.activestate.com/recipes/307871/)
Forum: Python Mar 18th, 2009
Replies: 6
Views: 614
Posted By slate
I don't think so.
This function is implemented in C based on the stdlib's int argc and char** argv variables.
Look...
Forum: Python Feb 10th, 2009
Replies: 3
Views: 620
Posted By slate
A syntactically marked group of lines is a statement in python. A statement with only one line is a simple statement (break, pass etc). A statement with more lines is a compound statement (if, for...
Forum: Python Feb 8th, 2009
Replies: 8
Views: 450
Posted By slate
Yes. The clear function can be just print("\n"*55).

You can put the questions and answers in a file like:


Q
What is the Binary number system?
A
The Binary number system is a number system...
Forum: Python Feb 8th, 2009
Replies: 14
Views: 802
Posted By slate
I reproduced your code. Changed the deprecated (and imho fuzzy) file read and write syntax.
It works as expected.

I think you consume the content of f in "do what you need" phase.

Either you...
Forum: Python Feb 7th, 2009
Replies: 4
Views: 471
Posted By slate
It should return 9 for 1953 and it does.

res: is the number which we will return
res=10 :put res so high that we can enter the loop

while res>9: we do looping while the return value is greater...
Forum: Python Feb 7th, 2009
Replies: 4
Views: 471
Posted By slate
I suppose you want to continue the process until the number becomes lower then ten.


def fadic(birth_number):
s=str(birth_number)
res=10
while res>9:
res=sum(int(c) for c...
Forum: Python Feb 7th, 2009
Replies: 8
Views: 450
Posted By slate
A good activity instead of learning:)

I suppose you have some file with the questions...
So it can be loaded into a structure
questions=[question1, question2,....]


questions=["1","2","3"] #...
Forum: Python Feb 6th, 2009
Replies: 3
Solved: my music player
Views: 710
Posted By slate
I think Python cannot pick a random file in a directory. If that is the question....
Maybe you can walk through the files, and after a random time you play the current music. But that does not make...
Forum: Python Feb 5th, 2009
Replies: 3
Views: 329
Posted By slate
http://www.joelonsoftware.com/articles/Unicode.html
http://stuff.vandervossen.net/archive/weblog/2003/07/unicode_in_python
http://effbot.org/zone/unicode-objects.htm
Forum: Python Feb 4th, 2009
Replies: 3
Views: 388
Posted By slate
Similar purpose game:
http://www.newgrounds.com/portal/view/236362
Forum: Python Feb 4th, 2009
Replies: 2
Views: 539
Posted By slate
''.join(chr(ord(c)+1) for c in s)
Forum: Python Aug 18th, 2008
Replies: 3
Views: 524
Posted By slate
You can use subprocess with shell on unix.

http://blog.doughellmann.com/2007/07/pymotw-subprocess.html
And
http://www.python.org/doc/current/lib/module-subprocess.html
Forum: Python Jun 18th, 2008
Replies: 16
Views: 1,627
Posted By slate
There are two issues here
First, a proxy instance (device) that delegates unoverridden attributes to the magic instance.
Second, the magic instance should execute functions in device instance.
...
Forum: Python Jun 17th, 2008
Replies: 16
Views: 1,627
Posted By slate
I cannot find anything usable in metaclass for that. I am not smart enough maybe.

Why should the Device inherit? The class in device can have an object reference to an attribute object and can...
Forum: Python Jun 17th, 2008
Replies: 16
Views: 1,627
Posted By slate
I think this is the case where metaclass is usable.
I've never thought that it is usable for anything at all:)
I am happy that I see a real use case for it.

I look up the metaclass...
Forum: Python Jun 17th, 2008
Replies: 16
Views: 1,627
Posted By slate
I am interested.
Can you give me a stripped down example? If you have time for that.

I have read the problem description several times, but could not understand it.

Maybe your solution is...
Forum: Python Jun 16th, 2008
Replies: 16
Views: 1,627
Posted By slate
Yes, please, try to elaborate on the problem.
Dynamic module loading can mean different things, but I think you need that.

For example wxpython uses the semantics:

import wxversion...
Forum: Python Jun 16th, 2008
Replies: 5
Solved: eval() problems
Views: 1,189
Posted By slate
Besides, that you do not have a "primary" module in the code...
Eval evaluates an expression in his own namespace and returns the result.
What you really want imho is to inject code.

Something...
Forum: Python Jun 12th, 2008
Replies: 5
Views: 901
Posted By slate
But if you want it to be verbose, than the following questions need to be answered imho:

Is this a real ID? One ID <-> One name?
You have to have an algo to make an ID from a name and make a name...
Forum: Python Jun 12th, 2008
Replies: 5
Views: 901
Posted By slate
If the ID-s don't have to be verbose, then you might consider the uuid module.
Forum: Python Jun 9th, 2008
Replies: 7
Views: 1,032
Posted By slate
The title of the forum is about duck typing. The problem at hand has nothing to do with it IMHO.

I agree. Re.findall function is not so well suited for taking a user input regular expression,...
Forum: Python Jun 8th, 2008
Replies: 5
Views: 715
Posted By slate
What is the problem with filtering?

I suppose you have a function, that tells if a list member contains cake. Does this function behave unexpectedly?

I think this function should look like:...
Showing results 1 to 40 of 45

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC