Re: How donwnload youtube videos?
On Sun, Oct 5, 2014 at 1:41 PM, Dymond Simon wrote: > Uhm, ı have to download youtube videos ı was tried urlretrive but doesn't > work ı have no idea that's why.So there is my question, "we cant donwload > youtube videos directly ? ". > Look up youtube-dl - it's written in Python. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
How donwnload youtube videos?
Hi guys .. Uhm, ı have to download youtube videos ı was tried urlretrive but doesn't work ı have no idea that's why.So there is my question, "we cant donwload youtube videos directly ? ". -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue in printing top 20 dictionary items by dictionary value
On 2014-10-05 02:11, Denis McMahon wrote: On Sat, 04 Oct 2014 09:11:43 +, Shiva wrote: I have written a function that -reads a file -splits the words and stores it in a dictionary as word(key) and the total count of word in file (value). I want to print the words with top 20 occurrences in the file in reverse order - but can't figure it out. Here is my function: Once you've generated your dictionary, use a list comprehension to turn it into a list of tuples of ( word, count ). Sort the list of tuples according to the count element. Select the top 20. copy it to a new list and reverse that list. now loop through the second list and print results. You don't need a list comprehension to turn it into a list of tuples, and you don't need to sort and reverse as separate steps. In fact, there's a class in the collections module that'll do virtually all of the work for you! -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue in printing top 20 dictionary items by dictionary value
On Sat, 04 Oct 2014 09:11:43 +, Shiva wrote: > I have written a function that -reads a file -splits the words and > stores it in a dictionary as word(key) and the total count of word in > file (value). > > I want to print the words with top 20 occurrences in the file in reverse > order - but can't figure it out. Here is my function: Once you've generated your dictionary, use a list comprehension to turn it into a list of tuples of ( word, count ). Sort the list of tuples according to the count element. Select the top 20. copy it to a new list and reverse that list. now loop through the second list and print results. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: "High water" Memory fragmentation still a thing?
Christian Heimes python.org> writes: > > The article doesn't state if the writer is referring to virtual memory > or resident set size. Actually the article mentions the following recipe: resource.getrusage(resource.RUSAGE_SELF).ru_maxrss which means the author is probably looking at resident set size. Regards Antoine. -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue in printing top 20 dictionary items by dictionary value
On 10/04/2014 10:36 AM, Shiva wrote: What I don't understand is: for w in eachword: textstorage[w]=textstorage.get(w, 0) + 1 How does textstorage.get(w,0)+1 give the count of the word?? Very long-winded explanation: (But to shorten it a bit, I'm going to use ts in place of textstorage. Also lhs = left-hand-side and rhs = right-hand-side.) What we're trying to do here is to update the word count. We could (erroneously) write it as: ts[w] = ts[w] + 1 If w already exists in the ts dictionary, this works fine. But if it does not it will abort with a KeyError when it comes to the ts[w] on the rhs of the assignment. The get() method is an alternate way of accessing the value of a key in a dictionary, but with a default value given as well. Now let's break down the statement ts[w] = ts.get(w, 0) + 1 Case 1: w already exists in the ts dictionary: ts.get(w, 0) gets the value of ts[w] (the current word count), adds 1, which is then used to update the word-count value of ts[w] (on the lhs of the assignment). case2: w does not exist in the ts dictionary: ts.get(w, 0) gives the default value of 0, and 1 is added to that. ts[w] on the lhs of the assignment does not exist, so a new entry is created in the ts dictionary with the given w as the key, and the value is initialized with the 1 from the get()+1. Make sense? -=- Larry -=- -- https://mail.python.org/mailman/listinfo/python-list
Re: Looking for volunteers developing wsgi Webmailer Application!
Because the world really needs this crap that is developed in php5, or big Personal Information Management Systems like Horde, what often nobody needs. Am 04.10.2014 um 19:52 schrieb Denis McMahon: > On Sat, 04 Oct 2014 17:52:18 +0200, Tamer Higazi wrote: > >> I am planing to develop on longer time a n open source Webmailer written >> in Python (not 2.7.x) with: > > Because the world really needs another webmailer spamengine. > -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue in printing top 20 dictionary items by dictionary value
On 2014-10-04 18:36, Shiva wrote: > It works : > orderedwords = sorted(textstorage.keys(), key=textstorage.get) > > The method textstorage.get will accept a word and return it's value > which in this instance is the count. > > What I don't understand is: > > for w in eachword: > textstorage[w]=textstorage.get(w, 0) + 1 > > How does textstorage.get(w,0)+1 give the count of the word?? > What textstorage.get(w, 0) says is: if the word is in the dict, return its count, else return 0. -- https://mail.python.org/mailman/listinfo/python-list
Re: "High water" Memory fragmentation still a thing?
On Fri, Oct 3, 2014 at 1:01 PM, Skip Montanaro wrote: > On Fri, Oct 3, 2014 at 1:36 PM, Croepha > wrote: > >> Long running Python jobs that consume a lot of memory while >> running may not return that memory to the operating system >> until the process actually terminates, even if everything is >> garbage collected properly. > The problem boils down to how the program dynamically allocates > and frees memory, and how the malloc subsystem interacts with > the kernel through the brk and sbrk system calls. (Anywhere I > mention "brk", you can mentally replace it with "sbrk". They do > the same thing - ask for memory from or return memory to the > kernel - using a different set of units, memory addresses or > bytes.) In the general case, programmers call malloc (or > calloc, or realloc) to allocate a chunk of storage from the > heap. (I'm ignoring anything special which Python has layered > on top of malloc. It can mitigate problems, but I don't think > it will fundamentally change the way malloc interacts with the > kernel.) The malloc subsystem maintains a free list (recently > freed bits of memory) from which it can allocate memory without > traipsing off to the kernel. If it can't return a chunk of > memory from the free list, it will (in the most simpleminded > malloc implementation) call brk to grab a new (large) chunk of > memory. The system simply moves the end of the program's > "break", effectively increasing or decreasing the (virtual) size > of the running program. That memory is then doled out to the > user by malloc. If, and only if, every chunk of memory in the > last chunk allocated by a call to brk is placed on malloc's free > list, *and* if the particular malloc implementation on your box > is smart enough to coalesce adjacent chunks of freed memory back > into brk-sized memory chunks, can brk be called once again to > reduce the program's footprint. Actually, ISTR hearing that glibc's malloc+free will use mmap+munmap to allocate and release chunks of memory, to avoid fragmentation. Digging around on the 'net a bit, it appears that glibc's malloc does do this (so on most Linux systems), but only for contiguous chunks of memory above 128K in size. Here's a pair of demonstration programs (one in C, one in CPython 3.4), which when run under strace on a Linux system, appear to show that mmap and munmap are being used: http://stromberg.dnsalias.org/~strombrg/malloc-and-sbrk.html HTH -- https://mail.python.org/mailman/listinfo/python-list
Re: Looking for volunteers developing wsgi Webmailer Application!
On Sat, 04 Oct 2014 17:52:18 +0200, Tamer Higazi wrote: > I am planing to develop on longer time a n open source Webmailer written > in Python (not 2.7.x) with: Because the world really needs another webmailer spamengine. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: "High water" Memory fragmentation still a thing?
Steven D'Aprano wrote: > [Aside: The thing that people fail to understand is that the GIL is not in > fact something which *prevents* multi-tasking, but it *enables* cooperative > multi-tasking: > > http://www.dabeaz.com/python/GIL.pdf > > although that's not to say that there aren't some horrible performance > characteristics of the GIL. David Beazley has identified issues with the > GIL which suggest room for improving the GIL and avoiding "GIL battles" > which are responsible for much of the overhead of CPU-bound threads. Any C > programmers who want to hack on the interpreter core?] Didn't the "new GIL" fix some of these problems? Sturla -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Basics
On Sat, 04 Oct 2014 11:09:58 +1000, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Sat, Oct 4, 2014 at 8:54 AM, Seymore4Head >> wrote: > >>> for i in range(1,10): >>> print (str(i)*i) >> >> Seymour, please don't do this. When you "help" someone by just giving >> him the answer to a homework problem, you get him past his immediate >> issue of "I need to submit my homework for this problem". That lets >> him get through his course without understanding the code he's >> creating > [...] > > In fairness to Seymour, at this extremely basic level, it's really hard to > explain to somebody how to solve a problem without giving them the answer. > > While I don't condone mindless parroting of work that others have done, > remember that for tens of thousands of years, being shown how to do > something, then imitating that, has been the most effective way for people > to learn. Dropping hints is typically the least effective learning method. This has gotta be the most civilised newsgroup on the Net. Kudos to you stalwarts who keep it that way. Personally, I thought Tobiah's hint, printing 'a'*4, would be just what the OP needed. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue in printing top 20 dictionary items by dictionary value
It works : orderedwords = sorted(textstorage.keys(), key=textstorage.get) The method textstorage.get will accept a word and return it's value which in this instance is the count. What I don't understand is: for w in eachword: textstorage[w]=textstorage.get(w, 0) + 1 How does textstorage.get(w,0)+1 give the count of the word?? Thanks, Shiva -- https://mail.python.org/mailman/listinfo/python-list
Re: A little more: decimal_portion
On Sun, 05 Oct 2014 01:46:03 +1000, Steven D'Aprano wrote: >Seymore4Head wrote: > >> A little more: decimal_portion >> >> Write a function that takes two number parameters and returns a float >> that is the decimal portion of the result of dividing the first >> parameter by the second. (For example, if the parameters are 5 and 2, >> the result of 5/2 is 2.5, so the return value would be 0.5) >> >> http://imgur.com/a0Csi43 >> >> def decimal_portion(a,b): >> return float((b/a)-((b//a))) >> >> print (decimal_portion(5,2)) >> >> I get 0.4 and the answer is supposed to be 0.5. > >Hint: given arguments a=5, b=2, you want 5/2. What do you calculate? Look at >the order of the arguments a and b in the function def line, and in the >calculations you perform. > >Once you fix that, I can suggest a more efficient way of calculating the >answer: use the modulo operator % > >Given arguments 5 and 2, you want 0.5 == 1/2, and 5%2 returns 1. > >Given arguments 6 and 2, you want 0.0 == 0/2, and 6%2 returns 0. > >Given arguments 8 and 3, you want 0.... == 2/3, and 8%3 returns 2. > > >P.S. the usual name for this function is "fraction part", sometimes "fp". Yeah, I caught my mistake. Thanks for the suggestions. I was expecting a lesson in rounding errors, so I had ruled out the error was on my part. (Something I should never do) -- https://mail.python.org/mailman/listinfo/python-list
Looking for volunteers developing wsgi Webmailer Application!
Hi people! I am planing to develop on longer time a n open source Webmailer written in Python (not 2.7.x) with: bottle.py zca, zope.interface Mail sasl and/or dovecot python-slimta-piperelay a wsgi webmailer which could be easily added in uWSGI. I am looking for people, who'd like to contribute got some time... Cheers, Tamer -- https://mail.python.org/mailman/listinfo/python-list
Re: A little more: decimal_portion
Seymore4Head wrote: > A little more: decimal_portion > > Write a function that takes two number parameters and returns a float > that is the decimal portion of the result of dividing the first > parameter by the second. (For example, if the parameters are 5 and 2, > the result of 5/2 is 2.5, so the return value would be 0.5) > > http://imgur.com/a0Csi43 > > def decimal_portion(a,b): > return float((b/a)-((b//a))) > > print (decimal_portion(5,2)) > > I get 0.4 and the answer is supposed to be 0.5. Hint: given arguments a=5, b=2, you want 5/2. What do you calculate? Look at the order of the arguments a and b in the function def line, and in the calculations you perform. Once you fix that, I can suggest a more efficient way of calculating the answer: use the modulo operator % Given arguments 5 and 2, you want 0.5 == 1/2, and 5%2 returns 1. Given arguments 6 and 2, you want 0.0 == 0/2, and 6%2 returns 0. Given arguments 8 and 3, you want 0.... == 2/3, and 8%3 returns 2. P.S. the usual name for this function is "fraction part", sometimes "fp". -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: A little more: decimal_portion
On Sun, 5 Oct 2014 01:24:40 +1000, Chris Angelico wrote: >On Sun, Oct 5, 2014 at 1:16 AM, Seymore4Head > wrote: >> I did. I included a screenshot of me doing just that. >> The formula seems to work in the shell, but does not work as a >> function, or I am missing something subtle again. > >Ah, I don't generally click screenshots. > >Have the function print out exactly what it's doing at each step. See >how that compares to your hand-worked version. You'll see the problem. > >ChrisA That worked. Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: A little more: decimal_portion
On Sun, Oct 5, 2014 at 1:16 AM, Seymore4Head wrote: > I did. I included a screenshot of me doing just that. > The formula seems to work in the shell, but does not work as a > function, or I am missing something subtle again. Ah, I don't generally click screenshots. Have the function print out exactly what it's doing at each step. See how that compares to your hand-worked version. You'll see the problem. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: A little more: decimal_portion
On Sun, 5 Oct 2014 01:07:39 +1000, Chris Angelico wrote: >On Sun, Oct 5, 2014 at 12:58 AM, Seymore4Head > wrote: >> A little more: decimal_portion >> >> Write a function that takes two number parameters and returns a float >> that is the decimal portion of the result of dividing the first >> parameter by the second. (For example, if the parameters are 5 and 2, >> the result of 5/2 is 2.5, so the return value would be 0.5) >> >> http://imgur.com/a0Csi43 >> >> def decimal_portion(a,b): >> return float((b/a)-((b//a))) >> >> print (decimal_portion(5,2)) >> >> I get 0.4 and the answer is supposed to be 0.5. > >Work out exactly what your program is doing, step by step. Print out >the intermediate steps in the calculation, and compare what the >program's doing to what you expect to be happening. What's (b/a)? >What's (b//a)? What's (b/a)-((b//a))? > >ChrisA I did. I included a screenshot of me doing just that. The formula seems to work in the shell, but does not work as a function, or I am missing something subtle again. -- https://mail.python.org/mailman/listinfo/python-list
Re: A little more: decimal_portion
On Sun, Oct 5, 2014 at 12:58 AM, Seymore4Head wrote: > A little more: decimal_portion > > Write a function that takes two number parameters and returns a float > that is the decimal portion of the result of dividing the first > parameter by the second. (For example, if the parameters are 5 and 2, > the result of 5/2 is 2.5, so the return value would be 0.5) > > http://imgur.com/a0Csi43 > > def decimal_portion(a,b): > return float((b/a)-((b//a))) > > print (decimal_portion(5,2)) > > I get 0.4 and the answer is supposed to be 0.5. Work out exactly what your program is doing, step by step. Print out the intermediate steps in the calculation, and compare what the program's doing to what you expect to be happening. What's (b/a)? What's (b//a)? What's (b/a)-((b//a))? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
A little more: decimal_portion
A little more: decimal_portion Write a function that takes two number parameters and returns a float that is the decimal portion of the result of dividing the first parameter by the second. (For example, if the parameters are 5 and 2, the result of 5/2 is 2.5, so the return value would be 0.5) http://imgur.com/a0Csi43 def decimal_portion(a,b): return float((b/a)-((b//a))) print (decimal_portion(5,2)) I get 0.4 and the answer is supposed to be 0.5. -- https://mail.python.org/mailman/listinfo/python-list
[RELEASED] Python 3.2.6rc1, Python 3.3.6rc1
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the release of Python 3.2.6rc1 and 3.3.6rc1. Both are release candidates for security-fix releases, which are provide source-only on python.org. The list of security-related issues fixed in the releases is given in the changelogs: https://hg.python.org/cpython/raw-file/v3.2.6rc1/Misc/NEWS https://hg.python.org/cpython/raw-file/v3.3.6rc1/Misc/NEWS To download the pre-releases visit one of: https://www.python.org/downloads/release/python-326rc1/ https://www.python.org/downloads/release/python-336rc1/ These are pre-releases, please report any bugs to http://bugs.python.org/ The final releases are scheduled one week from now. Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and contributors) -BEGIN PGP SIGNATURE- Version: GnuPG v2 iEYEARECAAYFAlQv9GsACgkQN9GcIYhpnLC93gCfVm74lhOysPYCO0fy9/l5LUfJ bUYAn2u1EygfsPw2oa4CSoj5t0TYUJq7 =HnOK -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: pyqt darg and drop
On Saturday, October 4, 2014 3:35:33 PM UTC+5:30, Sachin Tiwari wrote: > Hi > > > > I want to drag and drop push multiple push buttons but its working for only > for last button. And I want to connect them by a wire. > > > > Please help. > > > > import sys > > from PyQt4 import QtGui, QtCore > > > > > > class Button(QtGui.QPushButton): > > def mouseMoveEvent(self, e): > > if e.buttons() != QtCore.Qt.RightButton: > > return > > > > mimeData = QtCore.QMimeData() > > mimeData.setText('%d,%d' % (e.x(), e.y())) > > > > pixmap = QtGui.QPixmap.grabWidget(self) > > > > painter = QtGui.QPainter(pixmap) > > painter.setCompositionMode(painter.CompositionMode_DestinationIn) > > painter.fillRect(pixmap.rect(), QtGui.QColor(0, 0, 0, 127)) > > painter.end() > > > > drag = QtGui.QDrag(self) > > drag.setMimeData(mimeData) > > drag.setPixmap(pixmap) > > drag.setHotSpot(e.pos()) > > if drag.exec_(QtCore.Qt.CopyAction & QtCore.Qt.MoveAction) == > QtCore.Qt.MoveAction: > > print 'moved' > > else: > > print 'copied' > > > > def mousePressEvent(self, e): > > QtGui.QPushButton.mousePressEvent(self, e) > > if e.button() == QtCore.Qt.LeftButton: > > print 'press' > > > > > > > > class Example(QtGui.QWidget): > > def __init__(self): > > super(Example, self).__init__() > > self.initUI() > > > > > > def initUI(self): > > self.setAcceptDrops(True) > > > > button = Button('Button', self) > > button1 = Button('Button1', self) > > button.move(100, 65) > > button1.move(200, 65) > > > > self.buttons = [button] > > > > self.setWindowTitle('Copy or Move') > > self.setGeometry(300, 300, 280, 150) > > > > > > def dragEnterEvent(self, e): > > e.accept() > > > > > > def dropEvent(self, e): > > mime = e.mimeData().text() > > x, y = map(int, mime.split(',')) > > > > if e.keyboardModifiers() & QtCore.Qt.ShiftModifier: > > button = Button('Button', self) > > button1 = Button('Button1', self) > > button.move(e.pos()-QtCore.QPoint(x, y)) > > button1.move(e.pos()-QtCore.QPoint(x, y)) > > button.show() > > button1.show() > > self.buttons.append(button) > > self.buttons.append(button1) > > e.setDropAction(QtCore.Qt.CopyAction) > > else: > > e.source().move(e.pos()-QtCore.QPoint(x, y)) > > e.setDropAction(QtCore.Qt.MoveAction) > > e.accept() > > > > > > if __name__ == '__main__': > > app = QtGui.QApplication(sys.argv) > > ex = Example() > > ex.show() Change this line, if drag.exec_(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction: -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue in printing top 20 dictionary items by dictionary value
Am 04.10.2014 um 11:11 schrieb Shiva: > Hi All, > > I have written a function that > -reads a file > -splits the words and stores it in a dictionary as word(key) and the total > count of word in file (value). > > I want to print the words with top 20 occurrences in the file in reverse > order - but can't figure it out. As python is a high-level language with a comprehensive standard library, there ought to be a built-in method to sort stuff... Wait, but there ist: sorted(iterable[, key][, reverse]) The tricky part is: a dictionary is not storing the order of its entries. But you could just go with the list of your keys, sorted by the count of your words and then go from there. > Here is my function: > > def print_top(filename): > > #Open a file > path = '/home/BCA/Documents/LearnPython/ic/' > fname = path + filename > print ('filename: ',fname) > filetext = open(fname) > > #Read the file > textstorage={} > > #print(type(textstorage)) > readall = filetext.read().lower() > eachword = set(readall.split()) > > #store split words as keys in dictionary > for w in eachword: > textstorage[w] = readall.count(w) > > #print top 20 items in dictionary by decending order of val > # This bit is what I can't figure out. orderedwords = sorted(textstorage.keys(), key=textstorage.get, reverse=True) toptwenty = orderedwords[:20] for dkey in toptwenty: print(dkey,textstorage[dkey]) The interesting part is the "key=textstorage.get"-portion. This defines according to what "key" two values of the iterable (the keys of the dict) should be compared. The method textstorage.get will accept a word and return the count of that word. This count is used to sort the words - in reverse order. Another remark: Your algorithm works, but imagine this: Your text could be more than a few lines long and contain more than a few different words. When you convert your text into the set of alle the words you have to walk through it once. You only type one line into python, but this is what python has to do at that point. Afterwards, for every single word, you use the count-method of the complete text. This also walks through the whole text - each time. So if your text has N different words you walk through it N+2 times (your readall line also walks completely through it!). It is possible to solve your problem while only walking through the text only a few (independent of N) times or even only a single time! And the larger your text gets, the more important this gets. This is not an issue in python but in all of computer science. So try and rethink your algorithm with that goal in mind: Only walk through the text once. Python makes strong use on iterators, also file objects can be used as iterators. The count in your dictionary can be updated while you walk through the text. The get-method has a keyword argument for creating default values, which might be useful here. Another thing worth of mentioning is, that python has exactly this kind of machinery already built-in (collections.Counter), but you should try and implement a simple version of it yourself as exercise. Alexander -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue in printing top 20 dictionary items by dictionary value
Shiva wrote: > Hi All, > > I have written a function that > -reads a file > -splits the words and stores it in a dictionary as word(key) and the total > count of word in file (value). > > I want to print the words with top 20 occurrences in the file in reverse > order - but can't figure it out. Here is my function: > > def print_top(filename): > > #Open a file > path = '/home/BCA/Documents/LearnPython/ic/' > fname = path + filename > print ('filename: ',fname) > filetext = open(fname) > > #Read the file > textstorage={} > > #print(type(textstorage)) > readall = filetext.read().lower() > eachword = set(readall.split()) > > #store split words as keys in dictionary > for w in eachword: > textstorage[w] = readall.count(w) Using count() here is very inefficient. A better approach is to increment the dict value: for w in readall.split(): textstorage[w] = textstorage.get(w, 0) + 1 > > #print top 20 items in dictionary by decending order of val > # This bit is what I can't figure out. > > for dkey in (textstorage.keys()): > print(dkey,sorted(textstorage[dkey]))?? Apart from the fact that you are sorting characters in the word at that point the sorting effort is already too late -- you need to sort the dict keys by the corresponding dict values. It is possible to write a get_value() function such that sorted(textstorage, key=get_value, reverse=True) gives the keys in the right order, but perhaps it is simpler to convert textstorage into a list of (count, word) pairs first, something like pairs = [(42, "blue"), (17, "red"), (77, "black"), ...] When you sort that list most_common_words = sorted(pairs, reverse=True) you automatically get (count, word) pairs in the right order and can print the first 20 with for count, word in most_common_words[:20]: print(word, count) PS: Once you have it all working have a look at collections.Counter... -- https://mail.python.org/mailman/listinfo/python-list
pyqt darg and drop
Hi I want to drag and drop push multiple push buttons but its working for only for last button. And I want to connect them by a wire. Please help. import sys from PyQt4 import QtGui, QtCore class Button(QtGui.QPushButton): def mouseMoveEvent(self, e): if e.buttons() != QtCore.Qt.RightButton: return mimeData = QtCore.QMimeData() mimeData.setText('%d,%d' % (e.x(), e.y())) pixmap = QtGui.QPixmap.grabWidget(self) painter = QtGui.QPainter(pixmap) painter.setCompositionMode(painter.CompositionMode_DestinationIn) painter.fillRect(pixmap.rect(), QtGui.QColor(0, 0, 0, 127)) painter.end() drag = QtGui.QDrag(self) drag.setMimeData(mimeData) drag.setPixmap(pixmap) drag.setHotSpot(e.pos()) if drag.exec_(QtCore.Qt.CopyAction & QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction: print 'moved' else: print 'copied' def mousePressEvent(self, e): QtGui.QPushButton.mousePressEvent(self, e) if e.button() == QtCore.Qt.LeftButton: print 'press' class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): self.setAcceptDrops(True) button = Button('Button', self) button1 = Button('Button1', self) button.move(100, 65) button1.move(200, 65) self.buttons = [button] self.setWindowTitle('Copy or Move') self.setGeometry(300, 300, 280, 150) def dragEnterEvent(self, e): e.accept() def dropEvent(self, e): mime = e.mimeData().text() x, y = map(int, mime.split(',')) if e.keyboardModifiers() & QtCore.Qt.ShiftModifier: button = Button('Button', self) button1 = Button('Button1', self) button.move(e.pos()-QtCore.QPoint(x, y)) button1.move(e.pos()-QtCore.QPoint(x, y)) button.show() button1.show() self.buttons.append(button) self.buttons.append(button1) e.setDropAction(QtCore.Qt.CopyAction) else: e.source().move(e.pos()-QtCore.QPoint(x, y)) e.setDropAction(QtCore.Qt.MoveAction) e.accept() if __name__ == '__main__': app = QtGui.QApplication(sys.argv) ex = Example() ex.show() -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Basics
On Sat, 04 Oct 2014 11:09:58 +1000, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Sat, Oct 4, 2014 at 8:54 AM, Seymore4Head >> wrote: > >>> for i in range(1,10): >>> print (str(i)*i) >> >> Seymour, please don't do this. When you "help" someone by just giving >> him the answer to a homework problem, you get him past his immediate >> issue of "I need to submit my homework for this problem". That lets him >> get through his course without understanding the code he's creating > [...] > > In fairness to Seymour, at this extremely basic level, it's really hard > to explain to somebody how to solve a problem without giving them the > answer. > > While I don't condone mindless parroting of work that others have done, > remember that for tens of thousands of years, being shown how to do > something, then imitating that, has been the most effective way for > people to learn. Dropping hints is typically the least effective > learning method. I think Chris as demonstrated that you even at this basic level you can help without giving the answer, by asking a series of leading questions that result in the student providing the answer. -- One possible reason that things aren't going according to plan is that there never was a plan in the first place. -- https://mail.python.org/mailman/listinfo/python-list
Issue in printing top 20 dictionary items by dictionary value
Hi All, I have written a function that -reads a file -splits the words and stores it in a dictionary as word(key) and the total count of word in file (value). I want to print the words with top 20 occurrences in the file in reverse order - but can't figure it out. Here is my function: def print_top(filename): #Open a file path = '/home/BCA/Documents/LearnPython/ic/' fname = path + filename print ('filename: ',fname) filetext = open(fname) #Read the file textstorage={} #print(type(textstorage)) readall = filetext.read().lower() eachword = set(readall.split()) #store split words as keys in dictionary for w in eachword: textstorage[w] = readall.count(w) #print top 20 items in dictionary by decending order of val # This bit is what I can't figure out. for dkey in (textstorage.keys()): print(dkey,sorted(textstorage[dkey]))?? -- https://mail.python.org/mailman/listinfo/python-list
Re: "High water" Memory fragmentation still a thing?
dieter : > Without memory compaction, long running processes tend to suffer from > "memory fragmentation": while sufficient free memory is available, it > is available only in small blocks, not large enough for some memory > requests Now this is a question for the computer scientists. The problem is quite amenable to purely mathematical/statistical treatment. No doubt they've been at it for decades. My personal hunch is that GC in general works best with an ample amount of RAM, where "ample" means, say, ten times the minimum amount needed. As a bonus, I'm guessing the ample room would also all but remove the memory fragmentation issue. Marko -- https://mail.python.org/mailman/listinfo/python-list