Re: Want to win a 500 tablet?
On 09/26/2014 05:03 PM, Seymore4Head wrote: > On Fri, 26 Sep 2014 18:55:54 -0400, Seymore4Head > wrote: > >> I am taking "An Introduction to Interactive Programming in Python" at >> coursera.org. From their announcments page: >> >> Week one of the video contest is open >> >> For those of you that are interested in helping your peers, the >> student video tutorial competition is an excellent opportunity. The >> week one submission thread is up in the "student video tutorial >> forum." Feel free to browse the current tutorials or make your own. >> The deadline for submission of this week's videos is 23:00 UTC on >> Thursday. The overall winner of this competition will receive a $500 >> tablet computer so give it a try if you are interested! > > BTW this was the most informative tutorial I found. > https://www.youtube.com/watch?v=LpTzLnryDq8 I personally find that video tutorials don't work for me at all. Give me a web page any day that I can read and re-read at my own pace (fast or slow). -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter and gtk problem
On 09/26/2014 12:15 PM, Paula Estrella wrote: > Hello, we are working on ubuntu 12.04 LTS; we use gtk to take screenshots > and we added a simple interface to select a file using tkFileDialog but it > doesn't work; is it possible that tkinter and gtk are incompatible? a test > script to open a file with tkFileDialog works fine but if we import gtk > even if we don't use it, the dialog box doesn't respond to mouse events > anymore; if we comment the import gtk it does work > > Anyone knows what might be going on or how to solve that? Just use the Gtk to show a file dialog box. As dieter says, you can't mix event loops easily across multiple platforms. You might be able to set up a gtk timer or idle event to pump the tkinter event loop manually, but that's probably overly complicated and prone to failure. PyGtk isn't that much harder to learn and work with than tkinter. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about uninstallation.
On 28.09.2014 03:07, Gregory Johannes-Kinsbourg wrote: both Python 2 & 3 (I’m on OS X 10.10 btw) and first of all was curious to know if they will clash I am also quite new to the python business, and had the same kind of questions (how to install/uninstall a package, will different versions clash, should I use "pip install" or "pip3 install", etc). And then I discovered virtualenv and virtualenvwrapper and everything was much easier. Here is a resource that helped me: http://simononsoftware.com/virtualenv-tutorial-part-2/ I don't know about mac but on linux it works like a charm Fabien -- https://mail.python.org/mailman/listinfo/python-list
Re: Storage Cost Calculation
Steven D'Aprano wrote: > The Model B supported more graphics modes, had a six-pin DIN connector > for a monitor (both the A and B had UHF output for connecting to a > television, but only the B supported a dedicated monitor), had support > for an optional floppy disk controller and even an optional hard drive > controller. It also had RS-232 and Centronics parallel interfaces, a > 20-pin "user port" for I/O, and even support for a second CPU! The > Model A didn't support any of those. I won't disagree with most of those, but the graphics modes were simply a function of the available memory as RAM was shared between programs and graphics. The model A couldn't do the higher resolution graphics modes as they took too much out of the main memory (up to 20k which would have been tricky with 16k total RAM). > At the time, the BBC Micro memory was (I think) expandable: the Model > B could be upgraded to 128K of memory, double what Bill Gates > allegedly said was the most anyone would ever need. (He probably > didn't say that.) So what we need is to find out what an upgrade would > have cost. The memory expansion in the original BBC Micro was mostly ROM. The total addressable space was 64k, but 16k of that was the Acorn operating system and another 16k was paged ROM: by default you got BBC Basic but you could install up to 4 16k ROMs for languages such as BCPL or Logo or to drive external processor cards. That isn't to say of course that you couldn't expand the RAM: a company I worked for in the 80s that wrote the BCPL and Logo ROMs also manufactured a 1MB RAM card with battery backup. Later on the B+ had 64k of RAM and the B+128 had 128k of RAM and in each case the additional RAM was paged in as necessary but I don't think the RAM in the B was ever expandable. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about uninstallation.
In article , Chris Angelico wrote: > On Sun, Sep 28, 2014 at 11:07 AM, Gregory Johannes-Kinsbourg > wrote: > > Anyway, I’ve basically ended up installing both Python 2 & 3 (I’m on OS X > > 10.10 btw) and first of all was curious to know if they will clash with > > each when being used in terminal and how do i safely remove 3 (figure i’ll > > learn 2 first, then re-install 3). According to the manual I should remove > > the files from the application folder (fair enough) but also the framework > > (surely I should leave that for python 2?) > They shouldn't clash. You'll invoke one as python2 and the other as > python3. However, as Yosemite hasn't been released yet, you may find > that you have problems that nobody's run into yet. To get a better > understanding of Python, separately from any OS X issues, you may want > to make yourself a Linux computer to test on - it's usually not hard > to install a virtualization system and create a Linux machine inside > your Mac (or just get an actual physical machine). There have been > some issues with OS X and Python, in various versions; not being a Mac > person myself, I can't say what the least problematic version is. That's odd advice. There's no need to install Linux to run Python on OS X; it works perfectly fine there and is fully supported there. Python 2 and Python 3 co-exist just fine on OS X, actually, with Python framework builds as is provided by python.org installers, even better than on Linux as scripts are installed to separate bin directories for Py2 and Py3. And, while OS X 10.10 Yosemite is still a few weeks away from its expected official release data, you can be sure that the current releases of Python have been tested with the public beta and with developer previews. The most recent release of Python 2 (2.7.8) and the upcoming release of Python 3.4.2 (3.4.2rc1 is now available for testing) should fully support Yosemite. There are some minor issues with older binary versions centering around building extension modules if you need full universal support; most people don't. There are somewhat more serious issues if you try to build older versions of Python from source. For more details, see http://bugs.python.org/issue21811. I know that MacPorts has backported these fixes to their older versions of Python, if you need them; no idea about other third-party distributors. -- Ned Deily, n...@acm.org -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about uninstallation.
On Mon, Sep 29, 2014 at 9:17 AM, Ned Deily wrote: > That's odd advice. > ... And, while OS X 10.10 Yosemite is still a few weeks away from its > expected official release data, you can be sure that the current > releases of Python have been tested with the public beta and with > developer previews. It's due to the issues there've been in the past. How can someone who doesn't know Python be sure of whether an issue is due to the mess that can happen when two Pythons are installed from different places (the system Python and homebrew, as is often the case), or is actually an attribute of Python? Also, I didn't know Yosemite was that close, so I thought it was still more in flux. So maybe my concerns were a little ... well, overcautious. If someone's willing to state with some degree of confidence that Python X.Y.Z will work perfectly on OS X 10.10, then there's no problem. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about uninstallation.
In article , Chris Angelico wrote: > On Mon, Sep 29, 2014 at 9:17 AM, Ned Deily wrote: > > That's odd advice. > > ... And, while OS X 10.10 Yosemite is still a few weeks away from its > > expected official release data, you can be sure that the current > > releases of Python have been tested with the public beta and with > > developer previews. > It's due to the issues there've been in the past. How can someone who > doesn't know Python be sure of whether an issue is due to the mess > that can happen when two Pythons are installed from different places > (the system Python and homebrew, as is often the case), or is actually > an attribute of Python? It's pretty easy to avoid such issues: pick one Python instance of each version (2 and 3) and stick with it, be it one of the system-supplied Pythons, a python.org Python, or a third-party Python like from MacPorts, homebrew, Anaconda, et al. In that respect, OS X is no different than any Linux distribution. > Also, I didn't know Yosemite was that close, so I thought it was still > more in flux. So maybe my concerns were a little ... well, > overcautious. It's good to be cautious but better to be "informed cautious". Public betas have been available since July; developer previews before that. And, while Apple has not announced an official release date yet, they have said "Fall 2014" and, given the history of recent OS X releases and the current rumor mill, one would be advised to not bet against an October release date. > If someone's willing to state with some degree of confidence that > Python X.Y.Z will work perfectly on OS X 10.10, then there's no > problem. Let's just say that I will personally be *very* sad if 2.7.8 and 3.4.2 don't work as well or better on 10.10 as they do on 10.9.x and earlier supported OS X releases. -- Ned Deily, n...@acm.org -- https://mail.python.org/mailman/listinfo/python-list
trouble building data structure
greetings, i'm writing a program to scan a data file. from each line of the data file i'd like to add something like below to a dictionary. my perl background makes me want python to autovivify, but when i do: file_data = {} [... as i loop through lines in the file ...] file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } i get: Traceback (most recent call last): File "foo.py", line 45, in file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } KeyError: '91b152ce64af8af91dfe275575a20489' what is the pythonic way to build my "file_data" data structure above that has the above structure? on http://en.wikipedia.org/wiki/Autovivification there is a section on how to do autovivification in python, but i want to learn how a python programmer would normally build a data structure like this. here is the code so far: #!/usr/bin/python import argparse import os ASCII_NUL = chr(0) HOSTNAME = 0 MD5SUM = 1 FSDEV= 2 INODE= 3 NLINKS = 4 SIZE = 5 PATH = 6 file_data = {} if __name__ == "__main__": parser = argparse.ArgumentParser(description='scan files in a tree and print a line of information about each regular file') parser.add_argument('--file', '-f', required=True, help='File from which to read data') parser.add_argument('--field-separator', '-s', default=ASCII_NUL, help='Specify the string to use as a field separator in output. The default is the ascii nul character.') args = parser.parse_args() file = args.file field_separator = args.field_separator with open( file, 'rb' ) as f: for line in f: line = line.rstrip('\n') if line == 'None': continue fields = line.split( ASCII_NUL ) hostname = fields[ HOSTNAME ] md5sum = fields[ MD5SUM ] fsdev= fields[ FSDEV ] inode= fields[ INODE ] nlinks = int( fields[ NLINKS ] ) size = int( fields[ SIZE ] ) path = fields[ PATH ] if size < ( 100 * 1024 * 1024 ): continue ### print "'%s' '%s' '%s' '%s' '%s' '%s' '%s'" % ( hostname, md5sum, fsdev, inode, nlinks, size, path, ) file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } thanks, david -- Our decisions are the most important things in our lives. *** Live in a world of your own, but always welcome visitors. -- https://mail.python.org/mailman/listinfo/python-list
Re: trouble building data structure
On Mon, Sep 29, 2014 at 10:04 AM, David Alban wrote: > file_data = {} > > [... as i loop through lines in the file ...] > > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > > what is the pythonic way to build my "file_data" data structure above that > has the above structure? The easiest way would be with a defaultdict. It's a subclass of dictionary that does what you're looking for. You'd use it something like this: from collections import defaultdict file_data = defaultdict(dict) # then continue with the program as normal # including the loop and assignments that you have above Any time it's asked to look up an MD5 that doesn't exist yet, it'll create a new dictionary by calling dict(), and that sets up the next level for you. Docs are here: https://docs.python.org/2/library/collections.html#collections.defaultdict https://docs.python.org/3/library/collections.html#collections.defaultdict You can also use the setdefault() method of the regular dictionary, which makes sense if you have just a few places where you need this behaviour. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: trouble building data structure
On 9/28/14 8:04 PM, David Alban wrote: i'm writing a program to scan a data file. from each line of the data file i'd like to add something like below to a dictionary. my perl background makes me want python to autovivify, but when i do: file_data = {} [... as i loop through lines in the file ...] file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } i get: Traceback (most recent call last): File "foo.py", line 45, in file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } KeyError: '91b152ce64af8af91dfe275575a20489' what is the pythonic way to build my "file_data" data structure above that has the above structure? If you want file_data to be a dictionary of dictionaries, use a defaultdict: file_data = collections.defaultdict(dict) This is Python's version of autovivification. When you access a key that doesn't exist, the defaultdict will use the callable you gave it (in this case, dict) to create the new value as needed. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list