304 Posted Topics

Member Avatar for txwooley

If I understand correctly, you want to have a strict order of poker hands. That means, there can be a tie only, when all the cards are the same, except the colour (pikk, tref ...) The hand value can be a 6 member tuple: [LIST] [*]First the formation value 0-9, …

Member Avatar for txwooley
0
344
Member Avatar for tomtetlaw

Honestly I do not know the answer. I think it is more difficult than it seems. Why do you need that? Maybe there is another way to solve the problem.

Member Avatar for _Nestor
0
65
Member Avatar for Kekalove

Better, with "real" for loop [code] for i in range(0,1): print(range(0,1010,10)) [/code] Or: [code] for i in range(0,1010,10): print(i) [/code]

Member Avatar for slate
-2
103
Member Avatar for dilipkk
Member Avatar for ls129

Int objects are immutable. The statement a+=5 creates a new object which is an int and not an instance of your class. That is why your a.reset() call does not work. Try playing around type(a) and id(a) in the different stages. What are you trying to accomplish? Or whas that …

Member Avatar for Gribouillis
0
167
Member Avatar for Gribouillis

I don't think so. This function is implemented in C based on the stdlib's int argc and char** argv variables. [URL="http://svn.python.org/view/python/trunk/Python/sysmodule.c?revision=69331&view=markup"]Look[/URL] at the makeargvobject function.

Member Avatar for Gribouillis
0
168
Member Avatar for artemis_f

Wxpython in Action seemed ok for me. It can be found in the " Python programming books" collection online, if you know where to look.

Member Avatar for lllllIllIlllI
0
128
Member Avatar for ask2

If the input is a "text" file and the replacement values are encoded the same way and has "reasonably" short lines, then the following will suffice. [code] params={'param1':1, 'param2':2} fi=open("a.txt") fo=open("a_processed.txt","w") for line in fi: for k,v in params.iteritems(): fo.write(line.replace(k,str(v))) fo.close() fi.close() [/code] You can also store the params in …

Member Avatar for ask2
0
188
Member Avatar for wc26482

Why not [URL="http://ask.metafilter.com/81659/How-can-I-get-an-average-of-several-images"]use[/URL] imagemagick?

Member Avatar for slate
0
48
Member Avatar for alicem

[code=python] ar=[1,2,3,255,0,1] fi=open("a.dat","wb") # windows needs binary open for i in ar: fi.write(chr(i)) fi.close() [/code] Look [URL="http://docs.python.org/tutorial/inputoutput.html"]why[/URL] win needs this.

Member Avatar for slate
0
67
Member Avatar for breatheasier

It seems, that most of the time is spent with this line: distance=mag((vector(pnewx,pnewy))-disk.pos) This line is repeated nlat*5000 times. If you compute the vector before the for disk in alldisks loop, you gain some speed. In my measurement appr. 30%. Some random remarks: Do not use star import (from anything …

Member Avatar for breatheasier
0
264
Member Avatar for Rooking

Google is your friend. [url]http://www.google.hu/search?q=wxPySimpleApp(&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:hu-HU:unofficial&client=firefox-a[/url] First url I get: [url]http://www.wxpython.org/docs/api/wx.PySimpleApp-class.html[/url] which says in the example: [code] app = wx.PySimpleApp() frame = wx.Frame(None, title='Hello World') frame.Show() app.MainLoop() [/code] So that in your code the last lines will look like: [code] application = wxPySimpleApp() w=Window() w.Show() application.MainLoop() [/code] I hope this helps. …

Member Avatar for slate
0
203
Member Avatar for mahela007

if you are on unix (or download tar and netcat) you can do it with netcat: [url]http://www.catonmat.net/blog/unix-utilities-netcat/[/url] [code] # On computer A with IP 192.168.1.10 $ tar -cf - /data | nc -l -p 6666 # On computer B $ nc 192.168.1.10 6666 | tar -xf - [/code] You can …

Member Avatar for slate
0
182
Member Avatar for smtareq

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 etc...) Expression (statement) is a kind of simple statement, that usually gives back a value. …

Member Avatar for Stefano Mtangoo
0
224
Member Avatar for Bidamin

Try to save the file to the path. Maybe you don't have "enough" backslash... [code] def test_path(p): f=open(p,"w") f.write("test\n") f.close() [/code]

Member Avatar for slate
0
809
Member Avatar for Ghostenshell

Sadly, I don't know this game. What does the program supposed to do? As I see in the program, the player rolls two dices and adds the values. If the sum is 7 or 11 he wins If the sum is 2,3,12 he looses Otherwise he rolls over and over …

Member Avatar for oldSoftDev
0
128
Member Avatar for drone626

Unable to reproduce on Linux myhost 2.6.27-11-generic #1 SMP i686 GNU/Linux Intel(R) Core(TM)2 Duo CPU E4600 @ 2.40GHz Python 2.5.2 [code] class Rational: def __init__(self, numerator,denominator): self.numerator= numerator self.denominator= denominator a=Rational(2**64,1) print a [/code] Works fine.

Member Avatar for drone626
0
126
Member Avatar for chebude

I reproduced your code. Changed the deprecated (and imho fuzzy) file read and write syntax. It works as expected. [U]I think you consume the content of f in "do what you need" phase.[/U] Either you should read in the content of f (f.read()), manipulate it, and write it out, or …

Member Avatar for chebude
0
173
Member Avatar for mruane

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,....] [code] questions=["1","2","3"] # as test qc=0 # actual question index print("press enter for the next question q and enter to quit") while True: print(questions[qc]) key=raw_input() …

Member Avatar for mruane
0
148
Member Avatar for Haze

Wow. I am puzzled. [code] instance.dispmenu()#displays menu dm=instance.dispmenu dm()#displays menu too dms='dispmenu' eval('instance.'+dms+'()')# displays menu too getattr(instance,"dispmenu")() # displays menu too [/code]

Member Avatar for jrcagle
0
132
Member Avatar for starzstar

Maybe I am not alone, but I could not get the problem. Please provide some simplified cases of what you want to achieve. Please use code tags and punctuation.

Member Avatar for Murtan
0
155
Member Avatar for anthology

I suppose you want to continue the process until the number becomes lower then ten. [code] def fadic(birth_number): s=str(birth_number) res=10 while res>9: res=sum(int(c) for c in s) s=str(res) return res [/code] The function works even in the wild future too. I don't know what to do with dates before Christ.

Member Avatar for anthology
1
260
Member Avatar for shadows09

Successfully downloaded the spec. It is a mastermind game. My advises: Write down the workflow of the actions. Take notice of the tries and so on.. On paper it is enough. [URL="http://www.google.hu/imgres?imgurl=http://www.highmarkmedicareservices.com/trials-ide/images/decision-diagram.gif&imgrefurl=http://www.highmarkmedicareservices.com/trials-ide/index.html&h=829&w=570&sz=15&tbnid=eHJvKkLfCgdegM::&tbnh=144&tbnw=99&prev=/images%3Fq%3Ddecision%2Bdiagramm&usg=__iMpRt0Esy-pGp9bEQ__2suFXwJY=&ei=1WiMSb2XMtKT_gbxjdnIDA&sa=X&oi=image_result&resnum=3&ct=image&cd=1"]Example[/URL] Write a function that decides if the secret number is good. No printing, just return True or False... …

Member Avatar for shadows09
0
115
Member Avatar for leegeorg07

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 much sense for me. Is the music directory too large? I would …

Member Avatar for leegeorg07
0
701
Member Avatar for abczxy124

You calculate it on a paper, then tell python to do the same?! Come on... give it a try.... Numpy has to have a function for it, I am sure...

Member Avatar for Stefano Mtangoo
0
140
Member Avatar for Stefano Mtangoo

[URL="http://www.joelonsoftware.com/articles/Unicode.html"]http://www.joelonsoftware.com/articles/Unicode.html[/URL] [URL="http://stuff.vandervossen.net/archive/weblog/2003/07/unicode_in_python"]http://stuff.vandervossen.net/archive/weblog/2003/07/unicode_in_python[/URL] [URL="http://effbot.org/zone/unicode-objects.htm"]http://effbot.org/zone/unicode-objects.htm[/URL]

Member Avatar for Stefano Mtangoo
0
133
Member Avatar for mruane

Similar purpose game: [URL="http://www.newgrounds.com/portal/view/236362"]http://www.newgrounds.com/portal/view/236362[/URL]

Member Avatar for mruane
0
89
Member Avatar for kiddo39
Member Avatar for nealpcarpenter

[code] import threading import time class getb(threading.Thread): def __init__ (self,printa): threading.Thread.__init__(self) self.printa=printa def run(self): while True: k=raw_input() if k=="b": self.printa.stop=True break class printa(threading.Thread): def __init__ (self): threading.Thread.__init__(self) self.stop=False def run(self): while not self.stop: print "a" time.sleep(10) t1=printa() t2=getb(t1) t1.start() t2.start() [/code]

Member Avatar for Freaky_Chris
0
219
Member Avatar for astrogirl77

[code] f = open('numbers.txt','r') #read in the file, elminate all ", ', the leading and trailing spaces, split by whitespace to a list, and convert to int numbs=map(int,f.read().replace('"','').replace(''','').strip().split()) f.close() f = open('modnumber.txt','r') mod=int(f.read().replace('"','').replace(''','')) # read in the file and convert into int f.close() total=sum(numbs) # sum numbs up f=open('result.txt','w') f.write(str(total%mod)) …

Member Avatar for slate
0
109
Member Avatar for JA5ONS
Member Avatar for slendergreen

Try subprocess.Popen stdout redirection to a file or to the web server input. However I would not expose a long running server process via web. I think it would be better to schedule the process and present the output.

Member Avatar for Gribouillis
0
127
Member Avatar for Gribouillis

You can use subprocess with shell on unix. [URL="http://blog.doughellmann.com/2007/07/pymotw-subprocess.html"]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/URL] And [URL="http://www.python.org/doc/current/lib/module-subprocess.html"]http://www.python.org/doc/current/lib/module-subprocess.html[/URL]

Member Avatar for slate
0
229
Member Avatar for agibbons
Member Avatar for slate
0
318
Member Avatar for magicMan123

problem1 is solved mainly in: [URL="http://www.daniweb.com/forums/thread140700.html"]http://www.daniweb.com/forums/thread140700.html[/URL] Try to code something!

Member Avatar for slate
0
187
Member Avatar for magicMan123

Pretty printing is left as an exercise. Edit: Error message on incomplete input. [code] inp="{({(){}()}{(){}()})({(){}()}{(){}()})({(){}()}{(){}()})}" levels=list() # list of item, level pairs stack=list() cl=0 #current level other={")":"(","}":"{"} for it in inp: if it in ("(","{"): stack.append((it,cl)) levels.append((it,cl)) cl+=1 else: if len(stack)==0 or other.get(it,'Impossible input')!=stack[-1][0]: print "Invalid input!" break else: m=stack.pop() …

Member Avatar for slate
0
318
Member Avatar for JA5ONS

Hello! If I would have this problem to solve I would do the following. [LIST=1] [*]Identify the data to be stored [*]Identify the processing workflows [*]Identify the other-future-unspoken requierements [*]Design logically [*]Find best tool to make the job done [*]Design tool specific code [/LIST] It is the ideal setting. We …

Member Avatar for slate
0
105
Member Avatar for mr pickles

Hello All! Maybe I am speaking for myself only, My motivation using this forum is to get credit from others. I expect from the site, to make giving and quering credit easy. My responses to the code snippets does not appear in my posting history. They don't appear in the …

Member Avatar for kceleb9
0
88
Member Avatar for Fuse

Help on function findall in module re: findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern [B]has more than one group[/B]. …

Member Avatar for paddy3118
0
138
Member Avatar for tzushky

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: [code=python] import wxversion wxversion.select("2.8") import wx [/code] You can use the following to import a module given on the command line: [code=python] exec …

Member Avatar for tzushky
0
180
Member Avatar for shadwickman

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 like this: [code=python] for item in names: exec "import " + item [/code]

Member Avatar for shadwickman
0
223
Member Avatar for elhallouf
Member Avatar for slate
0
248
Member Avatar for darkMatter2008

Have a look at staticmethod and classmethod built ins in the python documentation.

Member Avatar for darkMatter2008
0
101
Member Avatar for ronnix

The database has the string in some encoding. When a client program gets this string it is encoded in some way. Try playing with the client encoding and python's str().encode-decode. For encoding background [URL="http://www.joelonsoftware.com/articles/Unicode.html"]http://www.joelonsoftware.com/articles/Unicode.html[/URL] is a good start.

Member Avatar for slate
0
80
Member Avatar for pukebag

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: ffilt=lambda x: str(x).lower().find("cake")<>-1

Member Avatar for vegaseat
0
148
Member Avatar for jhartley3

As woooee said you should maintain a total price between the age inputs, and print it as the total price. [CODE=python ] def aquariumTicket(total = 0): age = input("What is your age?") if age < 3: price = 0 elif age >=3 and age <=12: price = 19.5 elif age …

Member Avatar for slate
0
106
Member Avatar for jhartley3

Well. There are two kind of problems in the snippet. Is the algorithm good (gives the right result in a reasonable time), the other is if the program implements this algorithm. The algo would be in some pseudo language: input: dividend, divisor nonnegativ integers counter=0 n=dividend-divisor while n>0 do n=n-divisor …

Member Avatar for slate
0
111
Member Avatar for inkcoder

THe line: [CODE=python]op = input(">")[/CODE] Takes the input AND evaluates it. That means inputing "1" results in eval("1") which is int("1'). Putting in something like "a" results in the interpreter looking for a name "a" and not finding it. For the beginning I recommend to use: [CODE=python]op=raw_input(">")[/CODE]

Member Avatar for sneekula
0
178
Member Avatar for Mackjan

I don't get the purpose of ordna. What is it supposed to do? To arrange a list could not entail adding members, I don't get it.

Member Avatar for Mackjan
0
84
Member Avatar for FreezeBlink

Can you tell me, why it is needed to delete from the list? Is it not good enough to construct another list with the desired members, and assign it to the original list?

Member Avatar for jrcagle
0
118

The End.