304 Posted Topics
Re: 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, … | |
Re: 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. | |
Re: 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] | |
Re: [URL="http://code.activestate.com/recipes/307871/"]Maybe?[/URL] | |
Re: 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 … | |
Re: 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. | |
Re: Wxpython in Action seemed ok for me. It can be found in the " Python programming books" collection online, if you know where to look. | |
Re: 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 … | |
Re: Why not [URL="http://ask.metafilter.com/81659/How-can-I-get-an-average-of-several-images"]use[/URL] imagemagick? | |
Re: [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. | |
Re: 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 … | |
Re: 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. … | |
Re: 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 … | |
Re: 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. … | |
Re: 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] | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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() … | |
Re: 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] | |
Re: 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. | |
Re: 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. | |
Re: 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... … | |
![]() | Re: 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 … ![]() |
Re: 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... | |
Re: [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] | |
Re: Similar purpose game: [URL="http://www.newgrounds.com/portal/view/236362"]http://www.newgrounds.com/portal/view/236362[/URL] | |
Re: [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] | |
Re: [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)) … | |
Re: Can you show same code? Which gui toolkit you use? | |
Re: 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. | |
Re: 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] | |
Re: For a more general solution try python-magic. It is a wrapper for libmagic. | |
Re: 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! | |
Re: 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() … | |
Re: 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 … | |
Re: 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 … | |
Re: 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]. … | |
Re: 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 … | |
Re: 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] | |
Re: If the ID-s don't have to be verbose, then you might consider the uuid module. | |
Re: Have a look at staticmethod and classmethod built ins in the python documentation. | |
Re: 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. | |
Re: 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 | |
Re: 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 … | |
Re: 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 … | |
Re: 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] | |
Re: 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. | |
Re: 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? |
The End.