Re: Safely move an element into a heap
I'm not sure what you expect as an answer, but if you mean the heap as in the data structure, you can not just arbitrarily move one key where you want as it will destroy the heap property. Giampaolo Rodola' wrote: Hi, I wanted to know if does exist a safe way to, given a heap, move an arbitrary element to the first position of the heap. Something like: >>> heap = [0,3,6,8,10] >>> heapq.move_to_first_position(heap, 4) >>> heap = [10, 0,3,6,8] --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
lookfor = 'dfsdf' for item, value in kev.items(): if lookfor in value: print item print value.index(lookfor) break # assuming you only want one result You can also skip the 'if' verification in which case you need to catch ValueError exception in case there is no such entry in the current list. Hope it helps. lee wrote: hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie "dfsdf" in my dict, how can i find it is the third item in the internal list of phno of that dictionary? thanks you. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Setting urllib2 what IP to use
Hi, I have an interface (let's say eth0) which has more than one IP. Is there any way I can choose - from a parameter or something - what ip to use? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Using trace module from command line
Hi, I'm trying to profile an application and I want to test the trace module from command line but I can't really get it working. I have generated a result file with the command python -m trace --count --file blah.blah main.py -a us -c ../../conf/config.xml and then tried to read it using python -m trace -r -f blah.blah But nothing is displayed... What am I doing wrong? Thanks in advance, Alexandru Palade -- http://mail.python.org/mailman/listinfo/python-list
Re: very rare python expression
Nothing strange about that syntax (though some spaces might helped you out). The '&' operator is a bit-wise operator (http://docs.python.org/ref/bitwise.html). 甜瓜 wrote: Howdy everyone, I saw a strange python code in pygame project. What does "while not(x&528or x in l):" mean? Below code works in python2.5, so "x&528" is not HTML strings. # snake.py code: import pygame as p,random p.init() q=p.display T=16 b=q.set_mode([256]*2).fill l=[] d=a=x=1 c=p.event.get while not(x&528or x in l): l=l[a!=x:]+[x] while a&528or a in l:a=random.randrange(512) b(0) [b(99,(o%T*T,o/32*T,T,T))for o in l+[a]] q.flip() p.time.wait(199) for e in c(2): v=e.key-272 n=((v&2)-1)*[1,32][v<3] if-n-d and 0http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking out a module for Subversion
As for the open source IDE you can always try Eclipse with PyDev extension. Dudeja, Rajat wrote: Hi, I'm new to Python. I only have read "Byte of Python" by Swaroop C H just to be familiar with sytax of python. I've installed Python 2.5 from Active State and using its PythonWin Editor / interpreter. This, unfortunaltely, does not help in debugging. I'm looking for an open source IDE / editor that has source level debugging. Please suggest some tool. I'm intending to write a testing tool that uses Subversion. Is there some module available for subversion, out of the box, that I can import in my script? Regards, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and ! de! lete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to troubleshoot hanging script?
Hi, Just a thought, I'm not sure it's the best way. You can start an alarm just before the line you *think* it's wrong and cancel it after that. If it's activated then you probably have pinpointed the location. Have a look at the signals module http://docs.python.org/lib/module-signal.html, the alarm function. Hope it helps. kj wrote: Hi! I have a Pythonoob question. I have a script that hangs indefinitely at random times; the only thing to do at this point is to kill it. I'm looking for suggestions on how to troubleshoot and debug the problem. I'm not even sure of where exactly the script is hanging, though I suspect it is right around when it tries to read from a pipe (generated by popen). (I arrived at this guess by putting print statements all over the place, but I'm not sure this is a very reliable way to pinpoint the error.) So the first thing I'd like to do is find out exactly where the script is hanging. It would be nice if I could just hit Ctrl-C (which sends SIGINT from the terminal) when the script is hanging, to kill it and get a backtrace, but when this script hangs it becomes unresponsive to Ctrl-C! The only way to kill it is with something like % pkill -KILL my_script.py or even % pkill -TERM my_script.py ...or -ABRT or -QUIT. I tried to exploit this by adding this to the script: import signal def term_handler(signum, frame): raise KeyboardInterrupt signal.signal(signal.SIGTERM, term_handler) ...but this did not help at all; in fact, after this addition, the script no longer responded to pkill -TERM. TIA! Kynn -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd math related issue.
However, you should be carefully because using an %i modifier for a what-should-be a float value truncates the value in a way you may not expect. What I mean is that if you have sent 2 out of 3 bytes, the math will be 200/3 which with the %i modifier will print 66, rather than 66.6 (or at least 67 which is closer - have a look at the round() function). Another thing, you could have just added a dot after the constant in order to promote the expression to be evaluated as float. As in percentage = bytes_transferred / /self/.__sessions[path].total_bytes * 100. (notice the last dot) Fredrik Lundh wrote: Robert Rawlins wrote: I’ve got what seems to me to be a totally illogical math issue here which I can’t figure out. Take a look at the following code: /self/.__logger.info(/"%i / %i"/ % (bytes_transferred, /self/.__sessions[path].total_bytes)) percentage = bytes_transferred / /self/.__sessions[path].total_bytes * 100 /self/.__logger.info(/"%i"/ % percentage) Seems fairly straight forward, you would think. It takes two values and calculates the percentage of one from the other, however, percentage always comes back as ‘0’ for some reason, look at this log output. if you divide two integers, you'll get an integer back (in Python 2.X, at least). quick fix: percentage = bytes_transferred * 100 / total_bytes -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
String flags - redundant?
Hi to everyone, I'm rather a Python newbie, so I've put myself a question. Are these two statements (performance-wise) equal? r""" Text """ and """ Text """ I mean using the raw flag speeds up things because the interpreter doesn't need to look after escape sequences? Or it's rather optimized? I'm asking you this because I want to know how my """-style comments should be written in order not to affect the performance. And another short question... Are there any flags to specify variables intercalation in a string? I mean "I have x apples", how can i specify for the interpreter to substitute x with it's value? (in case *x* is a variable). And if this flag exists is it better to use "I have " + x + " apples" or the above mentioned way? Thank you for your time, Alex. -- http://mail.python.org/mailman/listinfo/python-list