From worldsbiggestsabresfan at gmail.com Tue Jan 1 15:14:23 2013 From: worldsbiggestsabresfan at gmail.com (worldsbiggestsabresfan at gmail.com) Date: Tue, 1 Jan 2013 12:14:23 -0800 (PST) Subject: Considering taking a hammer to the computer... In-Reply-To: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> Message-ID: <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> OK, thank you all for your help yesterday! Here's where we are today (using python 3.3.0) He has everything running well except for the final calculations - he needs to be able to total the number of rooms in the hotel, as well as the number of occupied rooms. We have tried several different things and can't come up with a successful command. Any help you can give will be much appreciated!! Here's what he's got: #This program will calculate the occupancy rate of a hotel floor_number = 0 rooms_on_floor = 0 occupied_rooms = 0 total_rooms = 0 total_occupied = 0 number_of_floors = int(input("How many floors are in the hotel?: ")) while number_of_floors < 1: print ("Invalid input! Number must be 1 or more") number_of_floors = int(input("Enter the number of floors in the hotel: ")) for i in range(number_of_floors): floor_number = floor_number + 1 print() print ("For floor #",floor_number) rooms_on_floor = int(input("How many rooms are on the floor ?: " )) while rooms_on_floor < 10: print ("Invalid input! Number must be 10 or more") rooms_on_floor = int(input("Enter the number of rooms on floor: ")) occupied_rooms = int(input("How many rooms on the floor are occupied?: ")) #CALCULATE OCCUPANCY RATE FOR FLOOR occupancy_rate = occupied_rooms / rooms_on_floor print ("The occupancy rate for this floor is ",occupancy_rate) #CALCULATE OCCUPANCY RATE FOR HOTEL print() total_rooms = sum(rooms_on_floor) #DOESN'T WORK! total_occupied = sum(occupied_rooms) #DOESN'T WORK! hotel_occupancy = total_occupied / total_rooms vacant_rooms = total_rooms - total_occupied print ("The occupancy rate for this hotel is ",hotel_occupancy) print ("The total number of rooms at this hotel is ",total_rooms) print ("The number of occupied rooms at this hotel is ",total_occupied) print ("The number of vacant rooms at this hotel is ",vacant_rooms) From matt.walker.jones at gmail.com Tue Jan 1 15:46:50 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Tue, 1 Jan 2013 14:46:50 -0600 Subject: Considering taking a hammer to the computer... In-Reply-To: <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> Message-ID: rooms_on_floor is being set by the manual input for each floor iterated over in your for loop. My guess is your total_rooms value equals the rooms from the last floor you processed. Same goes for the occupied_rooms. You'll want a separate variable to increment after each occupied_rooms or rooms_on_floor is received from the user. something like...: rooms_on_floor = int(input("Enter the number of rooms on floor: ")) total_rooms += rooms_on_floor *Matt Jones* On Tue, Jan 1, 2013 at 2:14 PM, wrote: > OK, thank you all for your help yesterday! > > Here's where we are today (using python 3.3.0) > > He has everything running well except for the final calculations - he > needs to be able to total the number of rooms in the hotel, as well as the > number of occupied rooms. We have tried several different things and can't > come up with a successful command. Any help you can give will be much > appreciated!! > > Here's what he's got: > > #This program will calculate the occupancy rate of a hotel > floor_number = 0 > rooms_on_floor = 0 > occupied_rooms = 0 > total_rooms = 0 > total_occupied = 0 > > > > number_of_floors = int(input("How many floors are in the hotel?: ")) > while number_of_floors < 1: > print ("Invalid input! Number must be 1 or more") > number_of_floors = int(input("Enter the number of floors in the hotel: > ")) > > for i in range(number_of_floors): > floor_number = floor_number + 1 > print() > print ("For floor #",floor_number) > rooms_on_floor = int(input("How many rooms are on the floor ?: " )) > while rooms_on_floor < 10: > print ("Invalid input! Number must be 10 or more") > rooms_on_floor = int(input("Enter the number of rooms on floor: ")) > > occupied_rooms = int(input("How many rooms on the floor are occupied?: > ")) > > #CALCULATE OCCUPANCY RATE FOR FLOOR > occupancy_rate = occupied_rooms / rooms_on_floor > print ("The occupancy rate for this floor is ",occupancy_rate) > > #CALCULATE OCCUPANCY RATE FOR HOTEL > print() > total_rooms = sum(rooms_on_floor) #DOESN'T WORK! > total_occupied = sum(occupied_rooms) #DOESN'T WORK! > hotel_occupancy = total_occupied / total_rooms > vacant_rooms = total_rooms - total_occupied > print ("The occupancy rate for this hotel is ",hotel_occupancy) > print ("The total number of rooms at this hotel is ",total_rooms) > print ("The number of occupied rooms at this hotel is ",total_occupied) > print ("The number of vacant rooms at this hotel is ",vacant_rooms) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Tue Jan 1 15:28:27 2013 From: d at davea.name (Dave Angel) Date: Tue, 01 Jan 2013 15:28:27 -0500 Subject: Considering taking a hammer to the computer... In-Reply-To: <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> Message-ID: <50E346EB.2040502@davea.name> On 01/01/2013 03:14 PM, worldsbiggestsabresfan at gmail.com wrote: > OK, thank you all for your help yesterday! > > Here's where we are today (using python 3.3.0) > > He has everything running well except for the final calculations - he needs to be able to total the number of rooms in the hotel, as well as the number of occupied rooms. We have tried several different things and can't come up with a successful command. Any help you can give will be much appreciated!! There are two ways to get those totals, depending on whether you know how to work lists or not. If you do, then you should make a list of occupied_rooms, and sum() it at the end, and make a list of rooms_on_flow, and sum that at the end. But as you discovered, sum() won't work on an int (BTW, you should give the entire traceback instead of saying "doesn't work". In this case, it was obvious, but it might not be.) On the other hand, if you don't know what a list is, then you need to accumulate those numbers as you go. Either way, you need extra variables to represent the whole hotel, and you need to do something inside the loop to adjust those variables. -- DaveA From worldsbiggestsabresfan at gmail.com Tue Jan 1 16:57:09 2013 From: worldsbiggestsabresfan at gmail.com (worldsbiggestsabresfan at gmail.com) Date: Tue, 1 Jan 2013 13:57:09 -0800 (PST) Subject: Considering taking a hammer to the computer... In-Reply-To: References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> Message-ID: <0891c464-31a7-44bc-bd91-4f90348d9251@googlegroups.com> That's it!!! Thank you, Matt!! project done! :) Thank you all, very much. Happy New Year! From worldsbiggestsabresfan at gmail.com Tue Jan 1 16:57:09 2013 From: worldsbiggestsabresfan at gmail.com (worldsbiggestsabresfan at gmail.com) Date: Tue, 1 Jan 2013 13:57:09 -0800 (PST) Subject: Considering taking a hammer to the computer... In-Reply-To: References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> Message-ID: <0891c464-31a7-44bc-bd91-4f90348d9251@googlegroups.com> That's it!!! Thank you, Matt!! project done! :) Thank you all, very much. Happy New Year! From rosuav at gmail.com Tue Jan 1 17:01:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Jan 2013 09:01:12 +1100 Subject: Considering taking a hammer to the computer... In-Reply-To: <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> Message-ID: On Wed, Jan 2, 2013 at 7:14 AM, wrote: > floor_number = 0 > for i in range(number_of_floors): > floor_number = floor_number + 1 Matt's already given you the part you need (and it seems to have worked for you, yay!). Side point: Are you aware that i and floor_number are always going to have the same value? You can simplify this down to: for floor_number in range(number_of_floors): ChrisA From d at davea.name Tue Jan 1 17:34:26 2013 From: d at davea.name (Dave Angel) Date: Tue, 01 Jan 2013 17:34:26 -0500 Subject: Considering taking a hammer to the computer... In-Reply-To: References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> Message-ID: <50E36472.90001@davea.name> On 01/01/2013 05:01 PM, Chris Angelico wrote: > On Wed, Jan 2, 2013 at 7:14 AM, wrote: >> floor_number = 0 >> for i in range(number_of_floors): >> floor_number = floor_number + 1 > Matt's already given you the part you need (and it seems to have > worked for you, yay!). Side point: Are you aware that i and > floor_number are always going to have the same value? You can simplify > this down to: > > for floor_number in range(number_of_floors): > > ChrisA Actually, floor_number is one higher. The easiest way to fix that is to adjust the range() parms. for floor_number in range(1, 1+number_of_floors): Naturally, in some hotels that might not have any rooms on one of the floors. Divide by zero. -- DaveA From as at sci.fi Fri Jan 4 02:34:43 2013 From: as at sci.fi (Anssi Saari) Date: Fri, 04 Jan 2013 09:34:43 +0200 Subject: New to python, do I need an IDE or is vim still good enough? References: <50e186a2$0$6951$e4fe514c@news2.news.xs4all.nl> Message-ID: Ben Finney writes: > Hans Mulder writes: > >> Don't bother: Python comes with a free IDE named IDLE. > > And any decent Unix-alike (most OSen apart from Windows) comes with its > own IDE: the shell, a good text editor (Vim or Emacs being the primary > candidates), and a terminal multiplexor (such as ?tmux? or GNU Screen). Just curious since I read the same thing in a programming book recently (21st century C). So what's the greatness that terminal multiplexors offer over tabbed terminals? Especially for software development? For sure I use screen at the remote end of ssh connections where I don't want the application like irssi to die if the connection goes down but other than that? From rosuav at gmail.com Fri Jan 4 10:34:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 02:34:56 +1100 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: <50e186a2$0$6951$e4fe514c@news2.news.xs4all.nl> Message-ID: On Fri, Jan 4, 2013 at 6:34 PM, Anssi Saari wrote: > Ben Finney writes: > >> And any decent Unix-alike (most OSen apart from Windows) comes with its >> own IDE: the shell, a good text editor (Vim or Emacs being the primary >> candidates), and a terminal multiplexor (such as ?tmux? or GNU Screen). > > Just curious since I read the same thing in a programming book recently > (21st century C). So what's the greatness that terminal multiplexors > offer over tabbed terminals? Especially for software development? The main thing is that you'll need a _lot_ of terminals. On my Debian and Ubuntu GNOME-based systems, I tend to assign one desktop to each of several "modes", usually with my (tabbed) editor and browser on the first desktop. At the moment, desktop #3 (hit Ctrl-Alt-RightArrow twice) is for building Pike, running Gypsum, and git-managing Gypsum; desktop #2 is for my poltergeist controllers (MIDI to my keyboard), with a few different windows depending on what I'm doing; and desktop #1 is... everything else. SciTE, Google Chrome, a couple of Nautilus windows, and roughly twenty terminals doing various things like Command & Conquer Renegade, iptables management, SSH sessions to two other servers, the Yosemite project... wow, what a lot of random junk I have running on Sikorsky at the moment. It seems I currently have 25 instances of bash running, in addition to the non-bash windows. Tabbed terminals probably would work fine, but I've personally just never gotten accustomed to any. You will want some kind of system that lets you group related shell sessions together (eg one for 'make', one for running the app, and one for git, all relating to one project), and add more terminals to a group as required. The most important editing key is command recall (up arrow or similar), and keeping three or four different command histories per project is hugely advantageous. ChrisA From python.list at tim.thechases.com Fri Jan 4 11:59:23 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 Jan 2013 10:59:23 -0600 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: <50e186a2$0$6951$e4fe514c@news2.news.xs4all.nl> Message-ID: <50E70A6B.5040101@tim.thechases.com> On 01/04/13 01:34, Anssi Saari wrote: > Ben Finney writes: >> And any decent Unix-alike (most OSen apart from Windows) comes with its >> own IDE: the shell, a good text editor (Vim or Emacs being the primary >> candidates), and a terminal multiplexor (such as ?tmux? or GNU Screen). > > Just curious since I read the same thing in a programming book recently > (21st century C). So what's the greatness that terminal multiplexors > offer over tabbed terminals? Especially for software development? > > For sure I use screen at the remote end of ssh connections where I don't > want the application like irssi to die if the connection goes down but > other than that? The reattaching is a nice feature--especially since you can start some work in one location, then SSH into the box remotely and reattach, resuming where you left off. Other nice things include - if it's a remote machine, only connecting once. This is more a factor if you need to enter a password, rather than using passwordless public/private key auth. But even with passwordless key-pairs, you still have to type "ssh user at host" rather than "{prefix key}c" to create a new connection on the same machine. - the ability to monitor windows for activity/silence (at least GNU Screen offered this; I haven't dug for it yet in tmux which I'm learning). This is nice for backgrounding a compile and being notified when it goes silent (usually means it's done) or watching a long-running quiet process to get notification when it finally has some output. I used this feature a LOT back when I did C/C++ work. - both offer the ability to do screen-sharing with other parties, as well as granting them various permissions (user X can watch but not interact with the session, while user Y can issue commands to the terminal as well) which is nice for remotely pair programming, or teaching somebody the ropes or troubleshooting. - depending on your tabbed terminal windows, terminal multiplexors usually offer some split-screen abilities (last I checked, GNU Screen only offered horizontal splits; tmux had both vertical & horizontal splits). As a Vim user (which doesn't have a way to include a terminal window inside Vim unless you rebuild it with unofficial patches), this allows me to have an editor in one {screen|tmux} window and a shell in the other and be able to see them together. I don't use it much, but it's nice to have when I do need it. - tmux offers the ability to transmit keyboard input to all linked/synchronized windows, so you can connect to multiple servers and then issue the same commands and they get run across all of them. I believe Screen offers a similar ability to broadcast keystrokes to all windows, but with a clunkier interface. Sort of a poor-man's "clusterssh". I've not needed this one, but it's there in case you manage clusters or develop/deploy with them. Those are just a few of the things that come to mind. Some might be replicated by a tabbed terminal window; others less so. -tkc From cs at zip.com.au Fri Jan 4 20:38:17 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 5 Jan 2013 12:38:17 +1100 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <50E70A6B.5040101@tim.thechases.com> References: <50E70A6B.5040101@tim.thechases.com> Message-ID: <20130105013817.GA31930@cskk.homeip.net> On 01/04/13 01:34, Anssi Saari wrote: | Just curious since I read the same thing in a programming book recently | (21st century C). So what's the greatness that terminal multiplexors | offer over tabbed terminals? Especially for software development? Do you include tiling terminal emulators? I user iTerm2 a lot on Macs, and it does both tabs (one terminal visible at a time, switch sideways to change terminals) and tiling/panes: multiple terminals visible in split panes within the current window. So I have distinct windows, generally full screen, one per desktop, with desktops for work zones. One a given desktop, just the one window with a few panes panes and sometimes more tabs-with-panes. So superficially, little need for screen or tmux. However I use screen (tmux some time when I have time to learn to use it) for the following: - named sessions: I've a small shell script called "scr" to do some common things with "screen". With no arguments: [/Users/cameron]fleet*> scr 1 3455.ADZAPPER 2 59094.CONSOLE_FW1 3 28691.MACPORTS 4 3649.PORTFWD So 4 named screen sessions. To join one "scr ADZAPPER", for example. - detached or at any rate detachable mail editing I've got my mutt editor set to a script that forked the new message editing in screen session named after the subject line. Normally I just compose and send, and that is seamless. But if I have to put things off for a complex or delayed message, I can just detahc from the session and be back in mutt to get on with other things. I imagine I could apply this more widely in some contexts. Plenty of people use the split screen modes in screen or tmux; personally I find this a little fiddly because focus-follows-mouse doesn't work there (though I discovered the other day that vim's split modes can do focus follow mouse:-) But in a restricted environment (eg some hostile one with a crude terminal emulator without these nice tabs/panes) the splitting can be useful. On 04Jan2013 10:59, Tim Chase wrote: | - the ability to monitor windows for activity/silence (at least GNU | Screen offered this; I haven't dug for it yet in tmux which I'm | learning). This is nice for backgrounding a compile and being | notified when it goes silent (usually means it's done) or watching a | long-running quiet process to get notification when it finally has | some output. I used this feature a LOT back when I did C/C++ work. I used to do this: make foo; alert "MADE FOO (exit=$?)" where "alert" is a personal script to do the obvious. On a Mac it pops up a notification. Of course I need to do that at the start, alas. I used to use iTerm's tab header colouring to notice idleness, and it was very useful in certain circumstances, generally wordy and slow startups of multiple things. Don't seem to do it much at present. Cheers, -- Cameron Simpson Having been erased, The document you're seeking Must now be retyped. - Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html From roy at panix.com Fri Jan 4 20:59:44 2013 From: roy at panix.com (Roy Smith) Date: Fri, 04 Jan 2013 20:59:44 -0500 Subject: New to python, do I need an IDE or is vim still good enough? References: <50E70A6B.5040101@tim.thechases.com> Message-ID: In article , Cameron Simpson wrote: > On 01/04/13 01:34, Anssi Saari wrote: > | Just curious since I read the same thing in a programming book recently > | (21st century C). So what's the greatness that terminal multiplexors > | offer over tabbed terminals? Especially for software development? There's no doubt that you need access to multiple terminal sessions. Whether you achieve that with multiple terminal windows on your desktop, multiple desktops, tabbed terminals, or something like screen is entirely personal preference. From wayne at waynewerner.com Mon Jan 7 00:53:34 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Sun, 6 Jan 2013 23:53:34 -0600 (CST) Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: <50E70A6B.5040101@tim.thechases.com> Message-ID: On Fri, 4 Jan 2013, Roy Smith wrote: > In article , > Cameron Simpson wrote: > >> On 01/04/13 01:34, Anssi Saari wrote: >> | Just curious since I read the same thing in a programming book recently >> | (21st century C). So what's the greatness that terminal multiplexors >> | offer over tabbed terminals? Especially for software development? > > There's no doubt that you need access to multiple terminal sessions. > Whether you achieve that with multiple terminal windows on your desktop, > multiple desktops, tabbed terminals, or something like screen is > entirely personal preference. +1 I use a tiling WM (awesomewm), but I still find that tmux has its place. Usually I'll have a terminal per box that I'm working on, and a tmux session within that. This allows me to detach and reattach from any system I'm on. In addition, if I lose my connection, I don't have to figure out which processes I had in bg. There's also the neat ability (at least with tmux - I haven't used screen for a while now) to work across sessions - so I might have a personal session (with things like alpine and irssi), a dev session (with Vim, a python prompt, and a shell) - and I can either keep them separate if I need to focus, or join the windows if I need some help. One thing that I've noticed that tmux does poorly is handle the mouse for selecting. And as I haven't yet written or found a cross-platform/machine clipboard manager, using the tmux copy or xclip doesn't really help that much :P I'd say the main benefit (aside from tiling) is the attach/detach. Unless your machine powers off or you kill tmux/screen, your sessions will stay around. -W From cs at zip.com.au Tue Jan 1 05:12:57 2013 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 1 Jan 2013 21:12:57 +1100 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130101101257.GA11468@cskk.homeip.net> On 01Jan2013 03:46, Steven D'Aprano wrote: | On Sat, 29 Dec 2012 14:00:23 -0500, Mitya Sirenef wrote: | > [...] For instance, if I need to change | > a block inside parens, I type ci) (stands for change inside parens), | > while with a regular editor I'd have to do it manually and by the time | > I'm done, I'd forget the bigger picture of what I'm doing with the code. | | See, by the time I remembered what obscure (to me) command to type, or | searched the help files and the Internet, I'd have forgotten what the | hell it was I was trying to do. Well, the idea is that your fingers become familiar with the core commands. An issue of practice. The more complex vi commands are usually composed from smaller pieces, so the learning curve isn't as steep as it initially appears. Eg "%" jumps to that matching bracket. And _therefore_, "c%" changes all text from here to the matching bracket. There's a whole host of these. | With a GUI app, I can run the mouse over the menus and see a high-level | overview of everything the app can do in a matter of a second or two. Well, there is GVim, a GNome X11 interface to vim. I imagine it would offer that kind of mode. | (Perhaps three or five seconds if the app over-uses hierarchical menus.) | But with a text interface, commands are much less discoverable. I can | also use *spacial* memory to zero in on commands much more easily than | verbal memory -- I have no idea whether the command I want is called | "Spam" or "Ham" or "Tinned Bully Beef", but I know it's in the top | quarter of the "Lunch" menu, and I will recognise it when I see it. I must admit I find Apple's "help" search box neat this way - you can type a keyword is it will actually find the menu item for you. Not that I use this for vi, of course... | > Another example: >ap stands for "indent a paragraph (separated by blank | > lines)". And there are many dozens if not hundreds such commands that | > let you stay focused on the logic of your code. | | Ah yes, the famous "a for indent" mnemonic. *wink* No, ">" is indent: it means shift-right. For Python you'd set the shiftwidth to 4 (well, I use 2). But again, that's a grammar. Like the "change" example above it is ">" followed by a cursor motion. So I'm quite fond of ">}". "}" means jump to next blank line (or end of paragraph for a prose paradigm). So ">}" means shift right from here to the next blank line. When your fingers know the cursor motion commands, folding any of them into a compound command like "c" or ">" or "<" (guess what that one is) requires almost no though. It's almost like speaking - you don't think about grammar in your native language. | It seems to me, that by the time I would have searched for the right | command to use, decided which of the (multiple) matching commands is the | right one, then used the command, it would have been quicker and less | distracting to have just done the editing by hand. But now I'm just | repeating myself. To repeat yourself in "vi" you just type ".". See? So much faster than your paragraph above:-) Cheers, -- Cameron Simpson As your attorney, it is my duty to inform you that it is not important that you understand what I'm doing or why you're paying me so much money. What's important is that you continue to do so. - Hunter S. Thompson's Samoan Attorney From python.list at tim.thechases.com Tue Jan 1 09:23:03 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 01 Jan 2013 08:23:03 -0600 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <20130101101257.GA11468@cskk.homeip.net> References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> <20130101101257.GA11468@cskk.homeip.net> Message-ID: <50E2F147.1040305@tim.thechases.com> On 01/01/13 04:12, Cameron Simpson wrote: > I must admit I find Apple's "help" search box neat this way - you > can type a keyword is it will actually find the menu item for > you. Not that I use this for vi, of course... If you've not used it, Vim's ":helpgrep" command provides full Vim regexp power for searching Vim's help. > No, ">" is indent: it means shift-right. For Python you'd set > the shiftwidth to 4 For PEP8, you'd also want to set 'expandtab'. Just to bring my semi-OT reply back around to Python :-) -tkc From msirenef at lightbird.net Tue Jan 1 13:43:36 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Tue, 01 Jan 2013 13:43:36 -0500 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50E32E58.3000102@lightbird.net> On 12/31/2012 10:46 PM, Steven D'Aprano wrote: > On Sat, 29 Dec 2012 14:00:23 -0500, Mitya Sirenef wrote: > >> I think the general idea is that with editors like Vim you don't get >> distracted by having to do some kind of an editor task, letting you keep >> your full attention on the code logic. For instance, if I need to change >> a block inside parens, I type ci) (stands for change inside parens), >> while with a regular editor I'd have to do it manually and by the time >> I'm done, I'd forget the bigger picture of what I'm doing with the code. > > See, by the time I remembered what obscure (to me) command to type, or > searched the help files and the Internet, I'd have forgotten what the > hell it was I was trying to do. Well, almost. My memory is not quite that > bad, but it would certainly be a much bigger disruption to my coding than > just doing the edit by hand. I would agree with you if I had to look up a command every time I use it. The way it really works for me is that either I use a command often enough that I remember it from the first time I looked it up, and the memory is reinforced every time I use it, OR it's such a rare command that looking it up is not a problem (obviously if it's faster to do it by hand than to look it up, I can do that, as well, which in Vim means using lower level commands that still don't require you leaving the home row.) > > I do love the power of command line tools, but I think that for rich > applications like editors, the interface is so clunky that I'd rather use > a less-powerful editor, and do more editing manually, than try to > memorize "hundreds" of commands. Clunky is the last word I'd use to describe it (ok maybe for Emacs :-) I probably remember about 200 commands, plus or minus, but a lot of them fit into a consistent scheme which makes them much easier to remember: there's (change delete yank vis-select)*(inner outer)*(letter word WORD paragraph )]} ) (Where word includes 'keyword' characters and WORD is separated by spaces). So, these correspond to commands (cdyv)(ia)(lwWp)]}). Therefore, deleting 3 WORDs is 3daW (mnemonic: del a WORD 3 times). I think I have a pretty bad memory but I remembered all of these commands a few at a time without too much trouble. And they're extremely useful even now as I'm editing this email. > > With a GUI app, I can run the mouse over the menus and see a high-level > overview of everything the app can do in a matter of a second or two. > (Perhaps three or five seconds if the app over-uses hierarchical menus.) > But with a text interface, commands are much less discoverable. I can > also use *spacial* memory to zero in on commands much more easily than > verbal memory -- I have no idea whether the command I want is called > "Spam" or "Ham" or "Tinned Bully Beef", but I know it's in the top > quarter of the "Lunch" menu, and I will recognise it when I see it. It's not a binary choice, GVim has a customizable menu system with a simple text format for adding menus (from Vim manual): To create a new menu item, use the ":menu" commands. They are mostly like the ":map" set of commands but the first argument is a menu item name, given as a path of menus and submenus with a '.' between them. eg: :menu File.Save :w :inoremenu File.Save :w :menu Edit.Big\ Changes.Delete\ All\ Spaces :%s/[ ^I]//g > > On the other hand, it's a lot harder to use a GUI app over a slow SSH > connection to a remote machine in a foreign country over a flaky link > than it is to use a command line or text-interface app. With GVim, you can use gui menus just as easily when you open a file remotely. > > >> Another example: >ap stands for "indent a paragraph (separated by blank >> lines)". And there are many dozens if not hundreds such commands that >> let you stay focused on the logic of your code. > > Ah yes, the famous "a for indent" mnemonic. *wink* Well, 'a' is mnemonic for 'a', fittingly ;-). > is for indent, just as < is for dedent. 'a' is to distinguish from inner paragraph command, which omits blank lines after the paragraph (which matter for other commands, but not for indent/dedent.): >ip . - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From torriem at gmail.com Wed Jan 2 16:33:22 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 Jan 2013 14:33:22 -0700 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <50E32E58.3000102@lightbird.net> References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E32E58.3000102@lightbird.net> Message-ID: <50E4A7A2.4010104@gmail.com> On 01/01/2013 11:43 AM, Mitya Sirenef wrote: > Therefore, deleting 3 WORDs is 3daW (mnemonic: del a WORD 3 times). Interesting. I typically use just d3w. 3daW seems to delete 3 lines for me, the same result as d3. Another favorite command is d or c followed by a number and then the right arrow key, for manipulating letters instead of words. In any case, I can be way more productive with just a few commands (maybe 3 or 4 commands or concepts) in Vim than in almost any GUI editor. In my experience, Vim users almost always find this to be true for them as well. Vim really hits the sweet spot for productivity and usability. The only thing about Vim that I find clunky is how code folding macros work, and also code completion hacks (which I have never needed anyway). From msirenef at lightbird.net Wed Jan 2 17:48:45 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 02 Jan 2013 17:48:45 -0500 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <50E4A7A2.4010104@gmail.com> References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E32E58.3000102@lightbird.net> <50E4A7A2.4010104@gmail.com> Message-ID: <50E4B94D.7090401@lightbird.net> On 01/02/2013 04:33 PM, Michael Torrie wrote: > On 01/01/2013 11:43 AM, Mitya Sirenef wrote: >> Therefore, deleting 3 WORDs is 3daW (mnemonic: del a WORD 3 times). > > Interesting. I typically use just d3w. 3daW seems to delete 3 lines > for me, the same result as d3. Another favorite command is d or > c followed by a number and then the right arrow key, for manipulating > letters instead of words. d3w is a different command, it means delete 3 words *ahead* from cursor. e.g.: func() lst[] lst2[ind] foo bar Now put the cursor on letter 'c' (4th from beginning) and use the command 3daW, it should delete the 3 WORDs, leaving just the 'foo bar'. > > > In any case, I can be way more productive with just a few commands > (maybe 3 or 4 commands or concepts) in Vim than in almost any GUI > editor. In my experience, Vim users almost always find this to be true > for them as well. Vim really hits the sweet spot for productivity and > usability. The only thing about Vim that I find clunky is how code > folding macros work, and also code completion hacks (which I have never > needed anyway). Vim does have a lot of flaws, alas. The highest ones on my list is that python integration (as a scripting language) is wonky; python can't be run alongside Vim process; double-escaping is terrible (stuff like \blah); process of development is slowed down too much by over-emphasis on backwards compatibility; the way arguments and counts are implemented between mappings, commands and functions is byzantine and way overcomplicated.. That said, Vim is still 1k% better than emacs and 3k% better than anything else :-). It's really odd that large companies like google, microsoft, ibm, facebook don't all chip in to give Bram a few million to hire a few people and knock the Vim out into the stratosphere, given how much these companies' employees used Vim for many hours, daily, to great benefit for said companies. Oh well. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From wayne at waynewerner.com Wed Jan 2 21:37:54 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 2 Jan 2013 20:37:54 -0600 (CST) Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <50E4A7A2.4010104@gmail.com> References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E32E58.3000102@lightbird.net> <50E4A7A2.4010104@gmail.com> Message-ID: On Wed, 2 Jan 2013, Michael Torrie wrote: > On 01/01/2013 11:43 AM, Mitya Sirenef wrote: >> Therefore, deleting 3 WORDs is 3daW (mnemonic: del a WORD 3 times). > > Interesting. I typically use just d3w. 3daW seems to delete 3 lines > for me, the same result as d3. Another favorite command is d or > c followed by a number and then the right arrow key, for manipulating > letters instead of words. Right arrow and not l? Surely you jest! ;) > > In any case, I can be way more productive with just a few commands > (maybe 3 or 4 commands or concepts) in Vim than in almost any GUI > editor. In my experience, Vim users almost always find this to be true > for them as well. Vim really hits the sweet spot for productivity and > usability. The only thing about Vim that I find clunky is how code > folding macros work, and also code completion hacks (which I have never > needed anyway). Yep. That's how I feel. I had used ViEmu in Visual Studio for coding in .NET at work - but I found that the buffers & macros were more powerful. So now I do most of my programming in Vim, and only head to VS if I need autocomplete or some of it's auto-generation tools. (I'm even writing this email in Vim as my external editor from alpine ;) -W From gvanem at broadpark.no Thu Jan 3 04:59:19 2013 From: gvanem at broadpark.no (Gisle Vanem) Date: Thu, 03 Jan 2013 10:59:19 +0100 Subject: New to python, do I need an IDE or is vim still good enough? References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E32E58.3000102@lightbird.net> <50E4A7A2.4010104@gmail.com> Message-ID: <13DE714EECA3423CB68400FA9D3BB4BF@dev.null> "Wayne Werner" wrote: > Yep. That's how I feel. I had used ViEmu in Visual Studio for coding in .NET at > work - but I found that the buffers & macros were more powerful. So now I do > most of my programming in Vim, and only head to VS if I need autocomplete or > some of it's auto-generation tools. Learning X different IDEs for different languages and uses can be confusing. So if you use Visual-Studio a lot there is Python Tools for VS [1]. A great but kinda slow extension to VS. Sticking to VS is also useful if one does Swig and need to debug your crashing .pyd modules. [1] http://pytools.codeplex.com/ --gv From roy at panix.com Tue Jan 1 14:02:44 2013 From: roy at panix.com (Roy Smith) Date: Tue, 01 Jan 2013 14:02:44 -0500 Subject: New to python, do I need an IDE or is vim still good enough? References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Mitya Sirenef wrote: > Clunky is the last word I'd use to describe it (ok maybe for Emacs :-) > I probably remember about 200 commands, plus or minus, but a lot of them > fit into a consistent scheme which makes them much easier to remember At some point, it becomes muscle memory, which means you don't even consciously know what you're typing. Your brain just says, "delete the next three words" and your fingers move in some way which causes that to happen. This is certainly true with emacs, and I imagine it's just as true with people who use inferior editors :-) I used to do a bunch of pair programming with another emacs power user. Every once in a while, one of us would say something like, "What did you just do?", when the other performed some emacs technique one of us was not familiar with. Invariably, the answer would be, "I don't know", and you would have to back up and recreate the key sequence. Or, just run C-? l, which tells you the last 100 characters you typed. Case in point. I use C-? l moderately often, when I make some typo and I'm not sure what I did wrong. But, despite the fact that my fingers now how to perform "show me the last stuff I typed", I had to go hunting to find the actual keystrokes which does that when typing the above paragraph :-) From msirenef at lightbird.net Tue Jan 1 14:32:13 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Tue, 01 Jan 2013 14:32:13 -0500 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50E339BD.5060200@lightbird.net> On 01/01/2013 02:02 PM, Roy Smith wrote: > In article , > Mitya Sirenef wrote: > >> Clunky is the last word I'd use to describe it (ok maybe for Emacs :-) >> I probably remember about 200 commands, plus or minus, but a lot of them >> fit into a consistent scheme which makes them much easier to remember > > At some point, it becomes muscle memory, which means you don't even > consciously know what you're typing. Your brain just says, "delete the > next three words" and your fingers move in some way which causes that to > happen. This is certainly true with emacs, and I imagine it's just as > true with people who use inferior editors :-) > > I used to do a bunch of pair programming with another emacs power user. > Every once in a while, one of us would say something like, "What did you > just do?", when the other performed some emacs technique one of us was > not familiar with. Invariably, the answer would be, "I don't know", and > you would have to back up and recreate the key sequence. Or, just run > C-? l, which tells you the last 100 characters you typed. > > Case in point. I use C-? l moderately often, when I make some typo and > I'm not sure what I did wrong. But, despite the fact that my fingers > now how to perform "show me the last stuff I typed", I had to go hunting > to find the actual keystrokes which does that when typing the above > paragraph :-) That's true with Vim, as well, especially when I'm making a custom mapping and I can NEVER remember what some combination does, even though if I actually needed to use it, it pops right out, so to find out, I have to try it and then I say, "of course, dammit, I use this command 50 times every single day!"; so it's a curious case of one-directional memory. -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From wayne at waynewerner.com Wed Jan 2 22:17:13 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 2 Jan 2013 21:17:13 -0600 (CST) Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: <50E339BD.5060200@lightbird.net> References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E339BD.5060200@lightbird.net> Message-ID: On Tue, 1 Jan 2013, Mitya Sirenef wrote: > On 01/01/2013 02:02 PM, Roy Smith wrote: > That's true with Vim, as well, especially when I'm making a custom > mapping and I can NEVER remember what some combination does, even though > if I actually needed to use it, it pops right out, so to find out, I > have to try it and then I say, "of course, dammit, I use this command 50 > times every single day!"; so it's a curious case of one-directional > memory. I've found writing macros helps me a lot in this regard. I do qaq"aP fairly frequently. -W From msirenef at lightbird.net Wed Jan 2 22:48:46 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 02 Jan 2013 22:48:46 -0500 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: <50e25c10$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E339BD.5060200@lightbird.net> Message-ID: <50E4FF9E.6040102@lightbird.net> On 01/02/2013 10:17 PM, Wayne Werner wrote: > On Tue, 1 Jan 2013, Mitya Sirenef wrote: > >> On 01/01/2013 02:02 PM, Roy Smith wrote: >> That's true with Vim, as well, especially when I'm making a custom >> mapping and I can NEVER remember what some combination does, even though >> if I actually needed to use it, it pops right out, so to find out, I >> have to try it and then I say, "of course, dammit, I use this command 50 >> times every single day!"; so it's a curious case of one-directional >> memory. > > I've found writing macros helps me a lot in this regard. I do > qaq"aP > fairly frequently. > > -W > But how does that help remember commands? (I also use recording, but I use qq because it's easier to type and I have a Q mapping that plays back q register). -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From neilc at norwich.edu Wed Jan 2 13:43:56 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 2 Jan 2013 18:43:56 GMT Subject: New to python, do I need an IDE or is vim still good enough? References: Message-ID: On 2012-12-29, Roy Smith wrote: > emacs will parse that, highlight the filenames and line numbers > and if I type M-`, it'll take me to the line of the next error > (including opening the file if it's not already open). > > I assume other smart editors have similar capabilities. > Different tools have different combinations of these, or > slightly different implementations. Find one you like and > learn all of it's capabilities. It makes a huge difference in > how productive you are. I used that power all the time writing C and C++ code. It felt indespensable. But even though I can do the same with Python, it doesn't feel crucial when writing Python. The errors are more few. ;) -- Neil Cerutti From jussij at zeusedit.com Tue Jan 1 19:12:03 2013 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: Tue, 1 Jan 2013 16:12:03 -0800 (PST) Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: Message-ID: <4d7902cf-794f-471b-a90b-f1c688265cdc@googlegroups.com> FWIW on the Windows platform the Zeus IDE has support for Python: http://www.zeusedit.com/python.html Zeus does the standard Python syntax highlighting, code completion, smart indenting, class browsing, code folding etc. Zeus also has limited Python debugger support and is fully scriptable in Python. Jussi Jumppanen Author: Zeus Editor From maniandram01 at gmail.com Wed Jan 2 00:10:45 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 1 Jan 2013 21:10:45 -0800 (PST) Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: Message-ID: On Friday, 28 December 2012 01:31:16 UTC+5:30, mogul wrote: > 'Aloha! > > > > I'm new to python, got 10-20 years perl and C experience, all gained on unix alike machines hacking happily in vi, and later on in vim. > > > > Now it's python, and currently mainly on my kubuntu desktop. > > > > Do I really need a real IDE, as the windows guys around me say I do, or will vim, git, make and other standalone tools make it the next 20 years too for me? > > > > Oh, by the way, after 7 days I'm completely in love with this python thing. I should have made the switch much earlier! > > > > /mogul %-) I use Eclipse only because it has PEP 8 and Pylint integration. Ezio Melotti, core Python developer, said in personal chat, that he uses Kate. IDEs aren't that useful when coding in Python. From wayne at waynewerner.com Wed Jan 2 22:20:21 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 2 Jan 2013 21:20:21 -0600 (CST) Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: Message-ID: On Tue, 1 Jan 2013, Ramchandra Apte wrote: > On Friday, 28 December 2012 01:31:16 UTC+5:30, mogul wrote: >> 'Aloha! >> >> >> >> I'm new to python, got 10-20 years perl and C experience, all gained on unix alike machines hacking happily in vi, and later on in vim. >> >> >> >> Now it's python, and currently mainly on my kubuntu desktop. >> >> >> >> Do I really need a real IDE, as the windows guys around me say I do, or will vim, git, make and other standalone tools make it the next 20 years too for me? >> >> >> >> Oh, by the way, after 7 days I'm completely in love with this python thing. I should have made the switch much earlier! >> >> >> >> /mogul %-) > > I use Eclipse only because it has PEP 8 and Pylint integration. > Ezio Melotti, core Python developer, said in personal chat, that he uses Kate. > IDEs aren't that useful when coding in Python. I concur. I think it's because with a language that has 43(?) keywords and I believe it's 12 different statement types, you can easily fit it all in your head. What you can't fit in your head is found in the docstrings of whatever you're using. Give me an interactive interpreter, vim, and a web browser, and I'm more than fine. -W From neilc at norwich.edu Wed Jan 2 13:36:25 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 2 Jan 2013 18:36:25 GMT Subject: New to python, do I need an IDE or is vim still good enough? References: <9eecde1c-a8b1-473c-bbee-eebd069bf2b1@y5g2000pbi.googlegroups.com> Message-ID: On 2012-12-30, Jamie Paul Griffin wrote: > Stick with what you've been using for the last couple of > decades. These tools have stood the test of time for a good > reason: they're powerful, efficient and made for the task of > programming. There is a good Python plugin for Vim that will allow simple reindenting and a bunch of other cool cursor movement powers I don't even use. ctags will also work, though I've never really needed it. -- Neil Cerutti From msarro at gmail.com Wed Jan 2 13:47:05 2013 From: msarro at gmail.com (Matty Sarro) Date: Wed, 2 Jan 2013 13:47:05 -0500 Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: <9eecde1c-a8b1-473c-bbee-eebd069bf2b1@y5g2000pbi.googlegroups.com> Message-ID: That's really a question for you - do you want the features of an IDE? Aptana includes pydev, and is built on eclipse which is a great swiss-army-knife IDE. If you like KISS, vim is an excellent choice. Go with whichever you are more comfortable using. On Wed, Jan 2, 2013 at 1:36 PM, Neil Cerutti wrote: > On 2012-12-30, Jamie Paul Griffin wrote: > > Stick with what you've been using for the last couple of > > decades. These tools have stood the test of time for a good > > reason: they're powerful, efficient and made for the task of > > programming. > > There is a good Python plugin for Vim that will allow simple > reindenting and a bunch of other cool cursor movement powers I > don't even use. ctags will also work, though I've never really > needed it. > > -- > Neil Cerutti > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jrodkeyjr at gmail.com Fri Jan 4 11:28:43 2013 From: jrodkeyjr at gmail.com (jrodkeyjr at gmail.com) Date: Fri, 4 Jan 2013 08:28:43 -0800 (PST) Subject: New to python, do I need an IDE or is vim still good enough? In-Reply-To: References: Message-ID: <0ee53300-5208-4789-a009-e567175c21f4@googlegroups.com> If you are going to review an IDE, or multiple, I would recommend Komodo and Komodo Edit. On Thursday, December 27, 2012 2:01:16 PM UTC-6, mogul wrote: > 'Aloha! > > > > I'm new to python, got 10-20 years perl and C experience, all gained on unix alike machines hacking happily in vi, and later on in vim. > > > > Now it's python, and currently mainly on my kubuntu desktop. > > > > Do I really need a real IDE, as the windows guys around me say I do, or will vim, git, make and other standalone tools make it the next 20 years too for me? > > > > Oh, by the way, after 7 days I'm completely in love with this python thing. I should have made the switch much earlier! > > > > /mogul %-) From dihedral88888 at googlemail.com Tue Jan 1 03:40:04 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 1 Jan 2013 00:40:04 -0800 (PST) Subject: dict comprehension question. In-Reply-To: <50e253b8$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <724d4fea-606a-4503-b538-87442f6bcebc@ci3g2000vbb.googlegroups.com> <50e253b8$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1b55ebb1-738b-412e-9d14-8c87e7ea8ae9@googlegroups.com> On Tuesday, January 1, 2013 11:10:48 AM UTC+8, Steven D'Aprano wrote: > On Sat, 29 Dec 2012 18:56:57 -0500, Terry Reedy wrote: > > > > > On 12/29/2012 2:48 PM, Quint Rankid wrote: > > > > > >> Given a list like: > > >> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1] > > >> I would like to be able to do the following as a dict comprehension. > > >> a = {} > > >> for x in w: > > >> a[x] = a.get(x,0) + 1 > > >> results in a having the value: > > >> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1} > > > > > > Let me paraphrase this: "I have nice, clear, straightforward, > > > *comprehensible* code that I want to turn into an incomprehensible mess > > > with a 'comprehension." That is the ironic allure of comprehensions. > > > > But... but... one liner! ONE LINNNNNNEEEERRRRR!!!! Won't somebody think > > of the lines I'll save!!!! > > > > *wink* > > > > > > In case it's not obvious, I'm 100% agreeing with Terry here. List comps > > and dict comps are wonderful things, but they can't do everything, and > > very often even if they can do something they shouldn't because it makes > > the code inefficient or unreadable. > > > > There's nothing wrong with a two or three liner. > > > > > > > > -- > > Steven This is useful for not being choked in sorting a list by the notorious quick-sort. From dihedral88888 at googlemail.com Tue Jan 1 03:37:40 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 1 Jan 2013 00:37:40 -0800 (PST) Subject: father class name In-Reply-To: References: Message-ID: <96b4f50f-c544-4ca5-98e2-49eba723ca38@googlegroups.com> On Monday, December 31, 2012 12:18:48 PM UTC+8, contro opinion wrote: > here is my haha? class > class? haha(object): > ? def? theprint(self): > ? ? print "i am here" > The definition of a class named haha. > >>> haha().theprint() > i am here > >>> haha(object).theprint() > Traceback (most recent call last): > > ? File "", line 1, in > TypeError: object.__new__() takes no parameters > > why ? haha(object).theprint()? get wrong output? You don't have to type the base class object. From dihedral88888 at googlemail.com Tue Jan 1 03:37:40 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 1 Jan 2013 00:37:40 -0800 (PST) Subject: father class name In-Reply-To: References: Message-ID: <96b4f50f-c544-4ca5-98e2-49eba723ca38@googlegroups.com> On Monday, December 31, 2012 12:18:48 PM UTC+8, contro opinion wrote: > here is my haha? class > class? haha(object): > ? def? theprint(self): > ? ? print "i am here" > The definition of a class named haha. > >>> haha().theprint() > i am here > >>> haha(object).theprint() > Traceback (most recent call last): > > ? File "", line 1, in > TypeError: object.__new__() takes no parameters > > why ? haha(object).theprint()? get wrong output? You don't have to type the base class object. From vlastimil.brom at gmail.com Tue Jan 1 18:09:45 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 2 Jan 2013 00:09:45 +0100 Subject: ignore case only for a part of the regex? In-Reply-To: <50e262a1$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50e02485$0$3109$ba620e4c@news.skynet.be> <50e262a1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2013/1/1 Steven D'Aprano : > On Sun, 30 Dec 2012 10:20:19 -0500, Roy Smith wrote: > >> The way I would typically do something like this is build my regexes in >> all lower case and .lower() the text I was matching against them. I'm >> curious what you're doing where you want to enforce case sensitivity in >> one part of a header, but not in another. > > Well, sometimes you have things that are case sensitive, and other things > which are not, and sometimes you need to match them at the same time. I > don't think this is any more unusual than (say) wanting to match an > otherwise lowercase word whether or not it comes at the start of a > sentence: > > "[Pp]rogramming" > > is conceptually equivalent to "match case-insensitive `p`, and case- > sensitive `rogramming`". > > > By the way, although there is probably nothing you can (easily) do about > this prior to Python 3.3, converting to lowercase is not the right way to > do case-insensitive matching. It happens to work correctly for ASCII, but > it is not correct for all alphabetic characters. > > > py> 'Stra?e'.lower() > 'stra?e' > py> 'Stra?e'.upper() > 'STRASSE' > > > The right way is to casefold first, then match: > > py> 'Stra?e'.casefold() > 'strasse' > > > Curiously, there is an uppercase ? in old German. In recent years some > typographers have started using it instead of SS, but it's still rare, > and the official German rules have ? transform into SS and vice versa. > It's in Unicode, but few fonts show it: > > py> unicodedata.lookup('LATIN CAPITAL LETTER SHARP S') > '?' > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list Hi, just for completeness, the mentioned regex library can take care of casfolding in case insensitive matching (in all supported versions: Python 2.5-2.7 and 3.1-3.3); i.e.: # case sensitive match: >>> for m in regex.findall(ur"Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m ... Stra?e # case insensitive match: >>> for m in regex.findall(ur"(?i)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m ... STRA?E STRA?E Stra?e # case insensitive match with casefolding: >>> for m in regex.findall(ur"(?if)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m ... STRA?E STRASSE STRA?E Strasse Stra?e >>> >>> # after enabling the backwards incompatible modern matching behaviour, casefolding is by default turned on for case insensitive matches >>> for m in regex.findall(ur"(?V1i)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m ... STRA?E STRASSE STRA?E Strasse Stra?e >>> As a small addition, the originally posted pattern r'^Msg-(?:(?i)id):' would actually work as expected in this modern matching mode in regex - enabled with the V1 flag. In this case the flag-setting (?i) only affects the following parts of the pattern, not the whole pattern like in the current "re" and V0-compatibility-mode "regex" >>> regex.findall(r"(?V1)Msg-(?:(?i)id):", "the regex should match Msg-id:, Msg-Id:, ... but not msg-id:, MSG-ID: and so on") ['Msg-id:', 'Msg-Id:'] >>> regards, vbr From wxjmfauth at gmail.com Wed Jan 2 09:17:04 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 2 Jan 2013 06:17:04 -0800 (PST) Subject: ignore case only for a part of the regex? In-Reply-To: References: <50e02485$0$3109$ba620e4c@news.skynet.be> <50e262a1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0850b8a9-a488-4dcd-9882-003dc8971608@googlegroups.com> Le mercredi 2 janvier 2013 00:09:45 UTC+1, Vlastimil Brom a ?crit?: > 2013/1/1 Steven D'Aprano : > > > On Sun, 30 Dec 2012 10:20:19 -0500, Roy Smith wrote: > > > > > >> The way I would typically do something like this is build my regexes in > > >> all lower case and .lower() the text I was matching against them. I'm > > >> curious what you're doing where you want to enforce case sensitivity in > > >> one part of a header, but not in another. > > > > > > Well, sometimes you have things that are case sensitive, and other things > > > which are not, and sometimes you need to match them at the same time. I > > > don't think this is any more unusual than (say) wanting to match an > > > otherwise lowercase word whether or not it comes at the start of a > > > sentence: > > > > > > "[Pp]rogramming" > > > > > > is conceptually equivalent to "match case-insensitive `p`, and case- > > > sensitive `rogramming`". > > > > > > > > > By the way, although there is probably nothing you can (easily) do about > > > this prior to Python 3.3, converting to lowercase is not the right way to > > > do case-insensitive matching. It happens to work correctly for ASCII, but > > > it is not correct for all alphabetic characters. > > > > > > > > > py> 'Stra?e'.lower() > > > 'stra?e' > > > py> 'Stra?e'.upper() > > > 'STRASSE' > > > > > > > > > The right way is to casefold first, then match: > > > > > > py> 'Stra?e'.casefold() > > > 'strasse' > > > > > > > > > Curiously, there is an uppercase ? in old German. In recent years some > > > typographers have started using it instead of SS, but it's still rare, > > > and the official German rules have ? transform into SS and vice versa. > > > It's in Unicode, but few fonts show it: > > > > > > py> unicodedata.lookup('LATIN CAPITAL LETTER SHARP S') > > > '?' > > > > > > > > > > > > -- > > > Steven > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Hi, > > just for completeness, the mentioned regex library can take care of > > casfolding in case insensitive matching (in all supported versions: > > Python 2.5-2.7 and 3.1-3.3); i.e.: > > # case sensitive match: > > >>> for m in regex.findall(ur"Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > Stra?e > > > > # case insensitive match: > > >>> for m in regex.findall(ur"(?i)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > STRA?E > > STRA?E > > Stra?e > > > > # case insensitive match with casefolding: > > >>> for m in regex.findall(ur"(?if)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > STRA?E > > STRASSE > > STRA?E > > Strasse > > Stra?e > > >>> > > >>> > > > > # after enabling the backwards incompatible modern matching behaviour, > > casefolding is by default turned on for case insensitive matches > > >>> for m in regex.findall(ur"(?V1i)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > STRA?E > > STRASSE > > STRA?E > > Strasse > > Stra?e > > >>> > > > > > > As a small addition, the originally posted pattern r'^Msg-(?:(?i)id):' > > would actually work as expected in this modern matching mode in regex > > - enabled with the V1 flag. In this case the flag-setting (?i) only > > affects the following parts of the pattern, not the whole pattern like > > in the current "re" and V0-compatibility-mode "regex" > > > > >>> regex.findall(r"(?V1)Msg-(?:(?i)id):", "the regex should match Msg-id:, Msg-Id:, ... but not msg-id:, MSG-ID: and so on") > > ['Msg-id:', 'Msg-Id:'] > ------ Vlastimil: Excellent. ----- Steven: ..." It's in Unicode, but few fonts show it:" ... Das grosse Eszett is a member of the unicode subsets MES-2, WGL-4. Good - serious - fonts are via OpenType MES-2 or WGL-4 compliant. So, it is a no problem. I do not know (and I did not check) if the code point, 1e9e, is part of the utf32 table. jmf From wxjmfauth at gmail.com Wed Jan 2 09:17:04 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 2 Jan 2013 06:17:04 -0800 (PST) Subject: ignore case only for a part of the regex? In-Reply-To: References: <50e02485$0$3109$ba620e4c@news.skynet.be> <50e262a1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0850b8a9-a488-4dcd-9882-003dc8971608@googlegroups.com> Le mercredi 2 janvier 2013 00:09:45 UTC+1, Vlastimil Brom a ?crit?: > 2013/1/1 Steven D'Aprano : > > > On Sun, 30 Dec 2012 10:20:19 -0500, Roy Smith wrote: > > > > > >> The way I would typically do something like this is build my regexes in > > >> all lower case and .lower() the text I was matching against them. I'm > > >> curious what you're doing where you want to enforce case sensitivity in > > >> one part of a header, but not in another. > > > > > > Well, sometimes you have things that are case sensitive, and other things > > > which are not, and sometimes you need to match them at the same time. I > > > don't think this is any more unusual than (say) wanting to match an > > > otherwise lowercase word whether or not it comes at the start of a > > > sentence: > > > > > > "[Pp]rogramming" > > > > > > is conceptually equivalent to "match case-insensitive `p`, and case- > > > sensitive `rogramming`". > > > > > > > > > By the way, although there is probably nothing you can (easily) do about > > > this prior to Python 3.3, converting to lowercase is not the right way to > > > do case-insensitive matching. It happens to work correctly for ASCII, but > > > it is not correct for all alphabetic characters. > > > > > > > > > py> 'Stra?e'.lower() > > > 'stra?e' > > > py> 'Stra?e'.upper() > > > 'STRASSE' > > > > > > > > > The right way is to casefold first, then match: > > > > > > py> 'Stra?e'.casefold() > > > 'strasse' > > > > > > > > > Curiously, there is an uppercase ? in old German. In recent years some > > > typographers have started using it instead of SS, but it's still rare, > > > and the official German rules have ? transform into SS and vice versa. > > > It's in Unicode, but few fonts show it: > > > > > > py> unicodedata.lookup('LATIN CAPITAL LETTER SHARP S') > > > '?' > > > > > > > > > > > > -- > > > Steven > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Hi, > > just for completeness, the mentioned regex library can take care of > > casfolding in case insensitive matching (in all supported versions: > > Python 2.5-2.7 and 3.1-3.3); i.e.: > > # case sensitive match: > > >>> for m in regex.findall(ur"Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > Stra?e > > > > # case insensitive match: > > >>> for m in regex.findall(ur"(?i)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > STRA?E > > STRA?E > > Stra?e > > > > # case insensitive match with casefolding: > > >>> for m in regex.findall(ur"(?if)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > STRA?E > > STRASSE > > STRA?E > > Strasse > > Stra?e > > >>> > > >>> > > > > # after enabling the backwards incompatible modern matching behaviour, > > casefolding is by default turned on for case insensitive matches > > >>> for m in regex.findall(ur"(?V1i)Stra?e", u" STRA?E STRASSE STRA?E Strasse Stra?e "): print m > > ... > > STRA?E > > STRASSE > > STRA?E > > Strasse > > Stra?e > > >>> > > > > > > As a small addition, the originally posted pattern r'^Msg-(?:(?i)id):' > > would actually work as expected in this modern matching mode in regex > > - enabled with the V1 flag. In this case the flag-setting (?i) only > > affects the following parts of the pattern, not the whole pattern like > > in the current "re" and V0-compatibility-mode "regex" > > > > >>> regex.findall(r"(?V1)Msg-(?:(?i)id):", "the regex should match Msg-id:, Msg-Id:, ... but not msg-id:, MSG-ID: and so on") > > ['Msg-id:', 'Msg-Id:'] > ------ Vlastimil: Excellent. ----- Steven: ..." It's in Unicode, but few fonts show it:" ... Das grosse Eszett is a member of the unicode subsets MES-2, WGL-4. Good - serious - fonts are via OpenType MES-2 or WGL-4 compliant. So, it is a no problem. I do not know (and I did not check) if the code point, 1e9e, is part of the utf32 table. jmf From newsboost at gmail.com Tue Jan 1 06:00:32 2013 From: newsboost at gmail.com (someone) Date: Tue, 01 Jan 2013 12:00:32 +0100 Subject: pygame - importing GL - very bad... Message-ID: See this code (understand why I commented out first line): # from OpenGL.GL import * from OpenGL.GL import glEnable, GL_DEPTH_TEST, \ glShadeModel, GL_SMOOTH, glClearColor, \ GL_CULL_FACE, GL_BLEND, glBlendFunc, \ GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \ glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \ glLoadIdentity, glTranslate, glRotate, \ glMultMatrixf, glPushMatrix, glCallList, \ glPopMatrix, glDisable, GL_LIGHTING The reason why I commented out the first line is that I use "pylint" and it reports: "[W] Redefining built-in 'format'" for this line. From: http://www.logilab.org/card/pylintfeatures tell: W0621: Redefining name %r from outer scope (line %s) Used when a variable's name hide a name defined in the outer scope. I don't like to redefine already defined names so therefore I had to outcomment first line and then keep on adding stuff until I could run my program... But this SUCKS! I can see that pygame hasn't been updated for a long while - not many users use it? I'm not very happy about this... Any good / clever solution to this problem, so I avoid this nasty crappy work-around? Any ideas / suggestions ? Thanks. From rosuav at gmail.com Tue Jan 1 06:13:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Jan 2013 22:13:59 +1100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On Tue, Jan 1, 2013 at 10:00 PM, someone wrote: > See this code (understand why I commented out first line): > > # from OpenGL.GL import * > from OpenGL.GL import glEnable, GL_DEPTH_TEST, \ > glShadeModel, GL_SMOOTH, glClearColor, \ > GL_CULL_FACE, GL_BLEND, glBlendFunc, \ > GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \ > glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \ > glLoadIdentity, glTranslate, glRotate, \ > glMultMatrixf, glPushMatrix, glCallList, \ > glPopMatrix, glDisable, GL_LIGHTING > > Any good / clever solution to this problem, so I avoid this nasty crappy > work-around? You could simply import OpenGL.GL as GL and then use all those names as GL.glPopMatrix, GL.GL_LIGHTING, etc. I don't know if that's better or worse. ChrisA From steve+comp.lang.python at pearwood.info Tue Jan 1 06:49:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Jan 2013 11:49:41 GMT Subject: pygame - importing GL - very bad... References: Message-ID: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote: > See this code (understand why I commented out first line): > > # from OpenGL.GL import * [...] > The reason why I commented out the first line is that I use "pylint" and > it reports: "[W] Redefining built-in 'format'" for this line. > > From: http://www.logilab.org/card/pylintfeatures tell: W0621: Redefining > name %r from outer scope (line %s) Used when a variable's name hide a > name defined in the outer scope. > > I don't like to redefine already defined names so therefore I had to > outcomment first line and then keep on adding stuff until I could run my > program... But this SUCKS! I can see that pygame hasn't been updated for > a long while - not many users use it? I'm not very happy about this... from pygame import * del format pylint may still complain, but you can ignore it. By deleting the name "format", that will unshadow the builtin format. -- Steven From newsboost at gmail.com Tue Jan 1 18:49:36 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 00:49:36 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/01/2013 12:49 PM, Steven D'Aprano wrote: > On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote: > >> See this code (understand why I commented out first line): >> >> # from OpenGL.GL import * > [...] >> The reason why I commented out the first line is that I use "pylint" and >> it reports: "[W] Redefining built-in 'format'" for this line. >> >> From: http://www.logilab.org/card/pylintfeatures tell: W0621: Redefining >> name %r from outer scope (line %s) Used when a variable's name hide a >> name defined in the outer scope. >> >> I don't like to redefine already defined names so therefore I had to >> outcomment first line and then keep on adding stuff until I could run my >> program... But this SUCKS! I can see that pygame hasn't been updated for >> a long while - not many users use it? I'm not very happy about this... > > from pygame import * > del format Are you sure about this? Because I'm not (OTOH I'm maybe not as experienced in python as some of you)... Ipython log: -------- In [6]: test=format(43) In [7]: type(test) Out[7]: str In [8]: from pygame import * In [9]: test=format(43) In [10]: type(test) Out[10]: str In [11]: del format --------------------------------------------------------------------------- NameError Traceback (most recent call last) in () ----> 1 del format NameError: name 'format' is not defined -------- What does this mean? Why does it say 'format" cannot be deleted after I did the wildcard import ? > pylint may still complain, but you can ignore it. By deleting the name > "format", that will unshadow the builtin format. Are you sure? From nobody at nowhere.com Tue Jan 1 22:01:02 2013 From: nobody at nowhere.com (Nobody) Date: Wed, 02 Jan 2013 03:01:02 +0000 Subject: pygame - importing GL - very bad... References: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote: > In [11]: del format > --------------------------------------------------------------------------- > NameError Traceback (most recent call last) > in () > ----> 1 del format > > NameError: name 'format' is not defined > -------- > > What does this mean? Why does it say 'format" cannot be deleted after I > did the wildcard import ? You can't delete built-in names. It has nothing to do with the wildcard import. The PyOpenGL modules delete "format" from the module's variables as soon as they are finished with it, so the set of names created by the wildcard import doesn't include "format". From newsboost at gmail.com Tue Jan 1 22:43:15 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 04:43:15 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/02/2013 04:01 AM, Nobody wrote: > On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote: > >> In [11]: del format >> --------------------------------------------------------------------------- >> NameError Traceback (most recent call last) >> in () >> ----> 1 del format >> >> NameError: name 'format' is not defined >> -------- >> >> What does this mean? Why does it say 'format" cannot be deleted after I >> did the wildcard import ? > > You can't delete built-in names. Ah, ok - and cannot overwrite it too, I guess... A shame that pylint didn't knew about this. > It has nothing to do with the wildcard import. The PyOpenGL modules delete > "format" from the module's variables as soon as they are finished with > it, so the set of names created by the wildcard import doesn't include > "format". Ok, sounds to me like I can safely ignore this pylint warning in any case... Thanks! From wuwei23 at gmail.com Wed Jan 2 04:52:11 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Jan 2013 01:52:11 -0800 (PST) Subject: pygame - importing GL - very bad... References: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6de4da05-4eae-466a-92d2-360334152416@d2g2000pbd.googlegroups.com> On Jan 2, 1:01?pm, Nobody wrote: > You can't delete built-in names. Actually, you can. If you ever need to shoot yourself in the foot in this particular way, you can always do: del __builtins__.format Not saying you _should_, just that you _can_ :) From newsboost at gmail.com Wed Jan 2 09:04:26 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 15:04:26 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: <6de4da05-4eae-466a-92d2-360334152416@d2g2000pbd.googlegroups.com> References: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> <6de4da05-4eae-466a-92d2-360334152416@d2g2000pbd.googlegroups.com> Message-ID: On 01/02/2013 10:52 AM, alex23 wrote: > On Jan 2, 1:01 pm, Nobody wrote: >> You can't delete built-in names. > > Actually, you can. If you ever need to shoot yourself in the foot in > this particular way, you can always do: > > del __builtins__.format > > Not saying you _should_, just that you _can_ :) Ok, good to know (not saying I would ever try it) :-) From steve+comp.lang.python at pearwood.info Wed Jan 2 02:39:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Jan 2013 07:39:31 GMT Subject: pygame - importing GL - very bad... References: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50e3e432$0$21851$c3e8da3$76491128@news.astraweb.com> On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote: > On 01/01/2013 12:49 PM, Steven D'Aprano wrote: > > On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote: > > > >> See this code (understand why I commented out first line): > >> > >> # from OpenGL.GL import * > > [...] > >> The reason why I commented out the first line is that I use "pylint" > >> and it reports: "[W] Redefining built-in 'format'" for this line. > >> > >> From: http://www.logilab.org/card/pylintfeatures tell: W0621: > >> Redefining name %r from outer scope (line %s) Used when a variable's > >> name hide a name defined in the outer scope. > >> > >> I don't like to redefine already defined names so therefore I had to > >> outcomment first line and then keep on adding stuff until I could > >> run my program... But this SUCKS! I can see that pygame hasn't been > >> updated for a long while - not many users use it? I'm not very happy > >> about this... > > > > from pygame import * > > del format > > Are you sure about this? Because I'm not (OTOH I'm maybe not as > experienced in python as some of you)... In the general case of deleting global names that shadow builtin names, yes I am. In the specific case of importing * from pygame, no. I trusted you that pygame exports format. Unfortunately, it seems that you were fooled by an invalid warning from pylint, so we were both mistaken. > Ipython log: > > -------- > In [6]: test=format(43) > In [7]: type(test) > Out[7]: str > In [8]: from pygame import * > In [9]: test=format(43) > In [10]: type(test) > Out[10]: str > In [11]: del format > ------------------------------------------------------------------------ > NameError Traceback (most recent call last) > in () > ----> 1 del format > > NameError: name 'format' is not defined > -------- > > What does this mean? Why does it say 'format" cannot be deleted after I > did the wildcard import ? It means that there is no "format" in the current scope, which implies that pygame no longer has a "format" which can be imported. You don't need an import to shadow built-ins. See for example: py> format py> format = "NOBODY expects the Spanish Inquisition!" py> format # this shadows the built-in "format" 'NOBODY expects the Spanish Inquisition!' py> del format # get rid of the Spanish Inquisition py> format py> del format Traceback (most recent call last): File "", line 1, in NameError: name 'format' is not defined When a name is not discovered in the current scope, the builtin scope is checked before Python gives up and reports a NameError. But del only works on the current scope, to stop you from accidentally deleting the wrong object. > > pylint may still complain, but you can ignore it. By deleting the > > name "format", that will unshadow the builtin format. > > Are you sure? Since it turns out that pylint was actually wrong to complain, no format was actually imported, then yes you can safely ignore it :-) -- Steven From newsboost at gmail.com Wed Jan 2 09:06:57 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 15:06:57 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: <50e3e432$0$21851$c3e8da3$76491128@news.astraweb.com> References: <50e2cd55$0$30003$c3e8da3$5496439d@news.astraweb.com> <50e3e432$0$21851$c3e8da3$76491128@news.astraweb.com> Message-ID: On 01/02/2013 08:39 AM, Steven D'Aprano wrote: > On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote: >> What does this mean? Why does it say 'format" cannot be deleted after I >> did the wildcard import ? > > It means that there is no "format" in the current scope, which implies > that pygame no longer has a "format" which can be imported. > > You don't need an import to shadow built-ins. See for example: > > py> format > > py> format = "NOBODY expects the Spanish Inquisition!" > py> format # this shadows the built-in "format" > 'NOBODY expects the Spanish Inquisition!' > py> del format # get rid of the Spanish Inquisition > py> format > > py> del format > Traceback (most recent call last): > File "", line 1, in > NameError: name 'format' is not defined Ok, thank you very much - that was/is very illustrative... > When a name is not discovered in the current scope, the builtin scope is > checked before Python gives up and reports a NameError. But del only > works on the current scope, to stop you from accidentally deleting the > wrong object. Ok, I'll remember that in the future, thank you. >> > pylint may still complain, but you can ignore it. By deleting the >> > name "format", that will unshadow the builtin format. >> >> Are you sure? > > Since it turns out that pylint was actually wrong to complain, no format > was actually imported, then yes you can safely ignore it :-) Ok, I can see from your example that you're right. Nice to know the real explanation, thank you very much. :-) From __peter__ at web.de Tue Jan 1 07:56:41 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 Jan 2013 13:56:41 +0100 Subject: pygame - importing GL - very bad... References: Message-ID: someone wrote: > See this code (understand why I commented out first line): > > # from OpenGL.GL import * > from OpenGL.GL import glEnable, GL_DEPTH_TEST, \ > glShadeModel, GL_SMOOTH, glClearColor, \ > GL_CULL_FACE, GL_BLEND, glBlendFunc, \ > GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \ > glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \ > glLoadIdentity, glTranslate, glRotate, \ > glMultMatrixf, glPushMatrix, glCallList, \ > glPopMatrix, glDisable, GL_LIGHTING > > The reason why I commented out the first line is that I use "pylint" and > it reports: "[W] Redefining built-in 'format'" for this line. > > From: http://www.logilab.org/card/pylintfeatures tell: > W0621: Redefining name %r from outer scope (line %s) Used when a > variable's name hide a name defined in the outer scope. > > I don't like to redefine already defined names so therefore I had to > outcomment first line and then keep on adding stuff until I could run my > program... But this SUCKS! I can see that pygame hasn't been updated for > a long while - not many users use it? I'm not very happy about this... > > Any good / clever solution to this problem, so I avoid this nasty crappy > work-around? > > Any ideas / suggestions ? > Thanks. It turns out pylint is lying. The situation is equivalent to $ cat module.py for format in [42]: pass del format $ cat main.py original_format = format from module import * assert format is original_format $ python main.py The assert doesn't trigger, so format is not redefined. But pylint complains anyway: $ pylint main.py -rn No config file found, using default configuration ************* Module main W: 2: Redefining built-in 'format' C: 1: Missing docstring C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| (__.*__))$) W: 2: Wildcard import module If you can ignore the warning about the wildcard import you should be able to ignore the "redefining built-in" warning, too. Personally I would avoid putting magic comments like from module import * # pylint: disable=W0622 $ pylint main.py -rn No config file found, using default configuration ************* Module main I: 2: Locally disabling W0622 C: 1: Missing docstring C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| (__.*__))$) W: 2: Wildcard import module into the code. From wuwei23 at gmail.com Tue Jan 1 17:39:33 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 Jan 2013 14:39:33 -0800 (PST) Subject: pygame - importing GL - very bad... References: Message-ID: <999ace5e-0a5f-4ce2-a496-315301e6f817@r10g2000pbd.googlegroups.com> On Jan 1, 9:00?pm, someone wrote: > I can see that pygame hasn't been updated for > a long while - not many users use it? It helps if you look in the right place: pygame "Last Updated 2012-12-29": https://bitbucket.org/pygame/pygame/src pygame2: http://code.google.com/p/pgreloaded/ From newsboost at gmail.com Tue Jan 1 18:56:47 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 00:56:47 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: <999ace5e-0a5f-4ce2-a496-315301e6f817@r10g2000pbd.googlegroups.com> References: <999ace5e-0a5f-4ce2-a496-315301e6f817@r10g2000pbd.googlegroups.com> Message-ID: On 01/01/2013 11:39 PM, alex23 wrote: > On Jan 1, 9:00 pm, someone wrote: >> I can see that pygame hasn't been updated for >> a long while - not many users use it? > > It helps if you look in the right place: > > pygame "Last Updated 2012-12-29": https://bitbucket.org/pygame/pygame/src > pygame2: http://code.google.com/p/pgreloaded/ Maybe... But if you look for stable releases here: http://www.pygame.org/download.shtml You'll find the top option: 1.9.1 Packages (August 6th 2009) And then previous releases is just below 1.9.1: pygame-1.9.0release.tar.gz ~ 1.4M - August 1, 2009 pygame-1.8.1release.tar.gz ~ 1.4M - July 30, 2008 pygame-1.8.0release.tar.gz ~ 1.4M - March 29, 2008 pygame-1.7.1release.tar.gz ~ 1.3M - August 16, 2005 1.7.0 ~ no source release was made. pygame-1.6.2.tar.bz2 ~ 1140 kb - pygame-1.6.tar.gz ~ 832 kb - October 23, 2003 pygame-1.5.tar.gz ~ 736 kb - May 30, 2002 pygame-1.4.tar.gz ~ 808 kb - Jan 30, 2002 pygame-1.3.tar.gz ~ 731 kb - Dec 19, 2001 pygame-1.2.tar.gz ~ 708 kb - Sep 4, 2001 pygame-1.1.tar.gz ~ 644 kb - Jun 23, 2001 pygame-1.0.tar.gz ~ 564 kb - Apr 5, 2001 pygame-0.9.tar.gz ~ 452 kb - Feb 13, 2001 pygame-0.5.tar.gz ~ 436 kb - Jan 6 14, 2001 pygame-0.4.tar.gz ~ 420 kb - Dec 14, 2000 pygame-0.3b.tar.gz ~ 367 kb - Nov 20, 2000 pygame-0.2b.tar.gz ~ 408 kb - Nov 3, 2000 pygame-0.1a.tar.gz ~ 300 kb - Oct 28, 2000 Back to year 2000... Maybe they should get a grip on themselves and distribute a new stable releases in year 2013 - then it would at least SEEM to look as the project is not dead. But in any case, I'm happy with it - haven't experienced any big issues with pygame yet, so don't take this as I don't value what they do. Maybe they've made a great version back in 2009 and it's so good that there wasn't any need for a newer stable version before 2013. But it gives the impression that nothing happens, when so many years pass on... Anyway, thanks a lot to all... (And sorry I accidentally replied privately to some of you - in thunderbird I should hit the "followup"-button but maybe they've removed it and instead I keep on hitting "reply" - very confusing that the first button in thunderbird is reply instead of followup, which is what I always prefer to use (so other people can see the answers). Thanks you for pointing out that (at least) something did happen on 2012-12-29, when it looks a bit dead on the official homepage. From newsboost at gmail.com Tue Jan 1 18:49:04 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 00:49:04 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/01/2013 12:13 PM, Chris Angelico wrote: > On Tue, Jan 1, 2013 at 10:00 PM, someone wrote: >> See this code (understand why I commented out first line): >> >> # from OpenGL.GL import * >> from OpenGL.GL import glEnable, GL_DEPTH_TEST, \ >> glShadeModel, GL_SMOOTH, glClearColor, \ >> GL_CULL_FACE, GL_BLEND, glBlendFunc, \ >> GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \ >> glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \ >> glLoadIdentity, glTranslate, glRotate, \ >> glMultMatrixf, glPushMatrix, glCallList, \ >> glPopMatrix, glDisable, GL_LIGHTING >> >> Any good / clever solution to this problem, so I avoid this nasty crappy >> work-around? > > You could simply > > import OpenGL.GL as GL > > and then use all those names as GL.glPopMatrix, GL.GL_LIGHTING, etc. I > don't know if that's better or worse. You're right - but I forgot to write that even though this maybe should/is recommended many places then I've seen a lot of opengl code on the internet and IMHO NOBODY does that and it'll be a lot slower to type that in front of all the opengl commands... So this solution is not something I like too... But I can see some other people came up with good solutions, which I didn't knew about.. Thank you. From torriem at gmail.com Wed Jan 2 16:57:02 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 Jan 2013 14:57:02 -0700 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: <50E4AD2E.8090606@gmail.com> On 01/01/2013 04:49 PM, someone wrote: > On 01/01/2013 12:13 PM, Chris Angelico wrote: > > You could simply > > > > import OpenGL.GL as GL > You're right - but I forgot to write that even though this maybe > should/is recommended many places then I've seen a lot of opengl code on > the internet and IMHO NOBODY does that and it'll be a lot slower to type > that in front of all the opengl commands... > > So this solution is not something I like too... But I can see some other > people came up with good solutions, which I didn't knew about.. Why is this solution not to your liking? Python has namespaces for a reason. They both keep code separated and modular. Use them. At most you should import the most commonly-used symbols only, and refer to the rest through their respective namespaces (with whatever alias you've given the import). There is no additional typing burden. Despite your opinion, it is completely false that "NOBODY does [this]." In other words a decent python programmer rarely does "from blah import *." There's a reason why pylint flags this. Frankly the code you've seen on the internet that does this is not setting a good example. It's bad programming practice, plain and simple. I'm a bit surprised that others on this list in this thread intimated that it's okay to do import *. The only place where I've seen an import * that actually belonged was in an __init__.py that brought sub-module symbols into the main package namespace, and even then I figure there's got to be a better way. Maybe this is your own private pet project, but if you ever plan to involve others in your development, leaving the OpenGL symbols in their own namespaces will make code maintenance a lot easier down the line. Later on another developer may come along and if it's not easy to tell at a glance if a symbol is provided by another module or if it's something you defined, he's going to have a lot of unnecessary work. From bahamutzero8825 at gmail.com Wed Jan 2 17:30:02 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 02 Jan 2013 16:30:02 -0600 Subject: pygame - importing GL - very bad... In-Reply-To: <50E4AD2E.8090606@gmail.com> References: <50E4AD2E.8090606@gmail.com> Message-ID: <50E4B4EA.6020508@gmail.com> On 2013.01.02 15:57, Michael Torrie wrote: > Why is this solution not to your liking? Python has namespaces for a > reason. They both keep code separated and modular. Use them. At most > you should import the most commonly-used symbols only, and refer to the > rest through their respective namespaces (with whatever alias you've > given the import). There is no additional typing burden. > > Despite your opinion, it is completely false that "NOBODY does [this]." > In other words a decent python programmer rarely does "from blah import > *." There's a reason why pylint flags this. Frankly the code you've > seen on the internet that does this is not setting a good example. It's > bad programming practice, plain and simple. I'm a bit surprised that > others on this list in this thread intimated that it's okay to do import > *. The only place where I've seen an import * that actually belonged > was in an __init__.py that brought sub-module symbols into the main > package namespace, and even then I figure there's got to be a better way. This. I have some code that imports multiprocessing.connection and I do actually type out multiprocessing.connection.Client and it doesn't bother me one bit. Code is read a lot more than it is written, even if only one person ever sees it. The whole "less typing" thing is absurd, especially when IDEs have completion features and stdlib modules share similar or exact function names (is it subprocess.Popen or os.popen? I guess the author wanted to save 2 seconds typing while anyone who reads it has to spend 5-10 to find out which is being used) . I've been using full namespaces since I started learning Python, and I even do it at the interactive interpreter because it's just a habit. IMO, "from foo import *" should only ever be used for /intentional/ namespace pollution (and even then, there are probably better ways to do it). -- CPython 3.3.0 | Windows NT 6.2.9200.16461 From newsboost at gmail.com Wed Jan 2 21:02:52 2013 From: newsboost at gmail.com (someone) Date: Thu, 03 Jan 2013 03:02:52 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: <50E4AD2E.8090606@gmail.com> Message-ID: On 01/02/2013 11:30 PM, Andrew Berg wrote: > On 2013.01.02 15:57, Michael Torrie wrote: >> *. The only place where I've seen an import * that actually belonged >> was in an __init__.py that brought sub-module symbols into the main >> package namespace, and even then I figure there's got to be a better way. > This. > > I have some code that imports multiprocessing.connection and I do > actually type out multiprocessing.connection.Client and it doesn't > bother me one bit. Code is read a lot more than it is written, even if > only one person ever sees it. The whole "less typing" thing is absurd, > especially when IDEs have completion features and stdlib modules share Until about a week ago, actually I hadn't setup emacs to use code completion - maybe this will change now because it'll speed things up and code completion is just a wonderful thing making things easier + quicker to do. I also setup emacs to do use TAGS and a lot more things now. > similar or exact function names (is it subprocess.Popen or os.popen? I > guess the author wanted to save 2 seconds typing while anyone who reads > it has to spend 5-10 to find out which is being used) . I've been using Well, this is not a problem for opengl-commands, I think... Normally I do as you suggest and for the exact same reasons as you write. > full namespaces since I started learning Python, and I even do it at the > interactive interpreter because it's just a habit. IMO, "from foo import > *" should only ever be used for /intentional/ namespace pollution (and > even then, there are probably better ways to do it). But I don't do any pollution - only this "format", which was a false alert. And so far I'm so consequent to only use it for the opengl-commands. I would deem that this is what most opengl-programmers do. Try to search for opengl-code out there on the internet... Most people do as I write I do here, IMHO. But you have a point and generally I totally agree with you. This is just a particular exception (and the only one I have) where I disagree, because I do as I think the majority of opengl-programmers do - based on what I see posted on the internet. From newsboost at gmail.com Wed Jan 2 20:53:03 2013 From: newsboost at gmail.com (someone) Date: Thu, 03 Jan 2013 02:53:03 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/02/2013 10:57 PM, Michael Torrie wrote: > On 01/01/2013 04:49 PM, someone wrote: >> On 01/01/2013 12:13 PM, Chris Angelico wrote: >> > You could simply >> > >> > import OpenGL.GL as GL >> You're right - but I forgot to write that even though this maybe >> should/is recommended many places then I've seen a lot of opengl code on >> the internet and IMHO NOBODY does that and it'll be a lot slower to type >> that in front of all the opengl commands... >> >> So this solution is not something I like too... But I can see some other >> people came up with good solutions, which I didn't knew about.. > > Why is this solution not to your liking? Python has namespaces for a Because the amount of opengl-functions is HUGE, many people (at least on the internet) do as I and (IMHO) it takes up too much time to change a lot of code plus sometimes I grab/modify small code pieces from the internet and it makes my development SO MUCH faster just to make an exception here with star-import for opengl-commands. > reason. They both keep code separated and modular. Use them. At most > you should import the most commonly-used symbols only, and refer to the > rest through their respective namespaces (with whatever alias you've > given the import). There is no additional typing burden. There are SO MANY "common-only used" symbols, but I also once believed that I should do as you write (which I agree with you, is the correct way to do it). I'm not saying you're incorrect - I just say that it speeds up my development significantly to only use star-import for opengl-stuff. > Despite your opinion, it is completely false that "NOBODY does [this]." > In other words a decent python programmer rarely does "from blah import > *." There's a reason why pylint flags this. Frankly the code you've > seen on the internet that does this is not setting a good example. It's > bad programming practice, plain and simple. I'm a bit surprised that > others on this list in this thread intimated that it's okay to do import > *. The only place where I've seen an import * that actually belonged Generally you're completely correct. After having worked with opengl for some time however, I must say that my personal opinion is that the benefits of making an exception here outweights the disadvantages a lot - but only for the many MANY opengl-commands. > was in an __init__.py that brought sub-module symbols into the main > package namespace, and even then I figure there's got to be a better way. > > Maybe this is your own private pet project, but if you ever plan to > involve others in your development, leaving the OpenGL symbols in their > own namespaces will make code maintenance a lot easier down the line. As said, you're completely correct. Until now it's my own private project, though I'm considering making it open-source after some time. Right now I just need to develop as quick as possible because I have a lot of work to do. > Later on another developer may come along and if it's not easy to tell > at a glance if a symbol is provided by another module or if it's > something you defined, he's going to have a lot of unnecessary work. Don't worry about that - opengl programmers immediately see and recognize opengl-commands... This, I deem is absolutely not a problem - opengl programmers easily recognize opengl commands immediately. They also usually begin with GL_.... - hence it's quite easy to see what is an opengl command and everything that isn't an opengl-command is (as you suggest) NOT imported using "star"-import. From mcfletch at vrplumber.com Thu Jan 3 09:09:14 2013 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Thu, 03 Jan 2013 09:09:14 -0500 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: <50E5910A.1020501@vrplumber.com> On 13-01-02 08:53 PM, someone wrote: > On 01/02/2013 10:57 PM, Michael Torrie wrote: >> On 01/01/2013 04:49 PM, someone wrote: >>> On 01/01/2013 12:13 PM, Chris Angelico wrote: >>> > You could simply >>> > >>> > import OpenGL.GL as GL >>> You're right - but I forgot to write that even though this maybe >>> should/is recommended many places then I've seen a lot of opengl >>> code on >>> the internet and IMHO NOBODY does that and it'll be a lot slower to >>> type >>> that in front of all the opengl commands... >>> >>> So this solution is not something I like too... But I can see some >>> other >>> people came up with good solutions, which I didn't knew about.. >> >> Why is this solution not to your liking? Python has namespaces for a > > Because the amount of opengl-functions is HUGE, many people (at least > on the internet) do as I and (IMHO) it takes up too much time to > change a lot of code plus sometimes I grab/modify small code pieces > from the internet and it makes my development SO MUCH faster just to > make an exception here with star-import for opengl-commands. I'd agree on it being rather impractical/pointless/verbose to have every single OpenGL entry point and constant have an extra gl. or glu. or glut. added to the front. OpenGL/GLU/GLUT is already namespaced, but using C-style prefix namespacing (that is gl* glu* glut* and GL_*, GLU_*, GLUT_*), so adding Python style namespacing to the front of that makes it very verbose. OpenGL-using code is *littered* with OpenGL entry points and constants (and yes, I intend the slight slight), so that's going to make it rather annoying to work with. PyOpenGL's current approach is mostly attempting to maintain backward compatibility with the older revisions. wxPython actually rewrote its whole interface to go from * imports into namespaced lookups and then wrote a little migration tool that would attempt to rewrite your code for the new version. They also provided a transitional API so that code could mix-and-match the styles. For PyOpenGL that would look something like this: from OpenGL import gl, glu, glut gl.Rotate(...) gl.Clear(gl.COLOR_BUFFER_BIT) or, if you really needed PEP-8 compliance, and don't mind making the API look nothing like the original, we might even go to: from opengl import gl, glu, glut gl.rotate(...) gl.clear(gl.COLOR_BUFFER_BIT) Either of which would *also* make it possible for us to lazy-load the entry points and symbols (that would save quite a bit of ram). But I'm not actually likely to do this, as it makes it far more annoying to work with C-oriented references (and since PyOpenGL is primarily used by new OpenGL coders who need to lean heavily on references, that's a big deal). Currently you can often copy-and-paste C code into PyOpenGL and have it work properly as far as the OpenGL part is concerned (arrays and the like need to be rewritten, but that's not something I can control, really). People are already confused by the small variations from C OpenGL, making the API look entirely different wouldn't be a good direction to move, IMO. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From newsboost at gmail.com Fri Jan 4 20:10:34 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 02:10:34 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/03/2013 03:09 PM, Mike C. Fletcher wrote: > On 13-01-02 08:53 PM, someone wrote: >>>> So this solution is not something I like too... But I can see some >>>> other >>>> people came up with good solutions, which I didn't knew about.. >>> >>> Why is this solution not to your liking? Python has namespaces for a >> >> Because the amount of opengl-functions is HUGE, many people (at least >> on the internet) do as I and (IMHO) it takes up too much time to >> change a lot of code plus sometimes I grab/modify small code pieces >> from the internet and it makes my development SO MUCH faster just to >> make an exception here with star-import for opengl-commands. > I'd agree on it being rather impractical/pointless/verbose to have every > single OpenGL entry point and constant have an extra gl. or glu. or > glut. added to the front. OpenGL/GLU/GLUT is already namespaced, but Good to hear, I'm not alone, thanks. > using C-style prefix namespacing (that is gl* glu* glut* and GL_*, > GLU_*, GLUT_*), so adding Python style namespacing to the front of that > makes it very verbose. OpenGL-using code is *littered* with OpenGL > entry points and constants (and yes, I intend the slight slight), so > that's going to make it rather annoying to work with. > > PyOpenGL's current approach is mostly attempting to maintain backward > compatibility with the older revisions. wxPython actually rewrote its > whole interface to go from * imports into namespaced lookups and then > wrote a little migration tool that would attempt to rewrite your code > for the new version. They also provided a transitional API so that code > could mix-and-match the styles. For PyOpenGL that would look something > like this: > > from OpenGL import gl, glu, glut > > gl.Rotate(...) > gl.Clear(gl.COLOR_BUFFER_BIT) Ok, that's interesting. However, I like it the way it is, where I can copy/paste C-code from the web and change some small things and it'll work and fit into my needs. BUT I didn't know there was such a transitional API - interesting. I however don't want to be a first-mover - let's see if sufficiently many people will use this and then I'll consider doing it too. At the moment, I still think the star-import is good because it makes it easy to look for C-code and program it (=do it) like people would do it in C. > or, if you really needed PEP-8 compliance, and don't mind making the API > look nothing like the original, we might even go to: > > from opengl import gl, glu, glut > > gl.rotate(...) > gl.clear(gl.COLOR_BUFFER_BIT) Erhm, that's the same as above. Is that what you meant to write? > Either of which would *also* make it possible for us to lazy-load the > entry points and symbols (that would save quite a bit of ram). > > But I'm not actually likely to do this, as it makes it far more annoying > to work with C-oriented references (and since PyOpenGL is primarily used > by new OpenGL coders who need to lean heavily on references, that's a > big deal). Currently you can often copy-and-paste C code into PyOpenGL > and have it work properly as far as the OpenGL part is concerned (arrays > and the like need to be rewritten, but that's not something I can > control, really). People are already confused by the small variations Agree - that's something I like. > from C OpenGL, making the API look entirely different wouldn't be a good > direction to move, IMO. Well, I'm sometimes a bit annoyed that python doesn't give as many warnings/errors as one gets in C - for instance sometimes I copy/paste and forget to remove the trailing semi-colons. However after I began to use pylint and friends, this error will be caught. Then sometimes I forgot to add () for function calls, which in C would cause an error by the compiler but which python allows so one can get the object (which maybe is also a good reason, but at least in the beginning when I learned python, this was very annoying + confusing to me). Thanks for the comments about this transitional opengl-stuff - I was unaware of that. Currently it's not so interesting to me, I like it the way I do it now so I can quickly grab code pieces from C/C++ from the web and change it to suit my needs... From d at davea.name Fri Jan 4 20:30:47 2013 From: d at davea.name (Dave Angel) Date: Fri, 04 Jan 2013 20:30:47 -0500 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: <50E78247.8010307@davea.name> On 01/04/2013 08:10 PM, someone wrote: > On 01/03/2013 03:09 PM, Mike C. Fletcher wrote: >> > >> PyOpenGL's current approach is mostly attempting to maintain backward >> compatibility with the older revisions. wxPython actually rewrote its >> whole interface to go from * imports into namespaced lookups and then >> wrote a little migration tool that would attempt to rewrite your code >> for the new version. They also provided a transitional API so that code >> could mix-and-match the styles. For PyOpenGL that would look something >> like this: >> >> from OpenGL import gl, glu, glut >> >> gl.Rotate(...) >> gl.Clear(gl.COLOR_BUFFER_BIT) > > Ok, that's interesting. However, I like it the way it is, where I can > copy/paste C-code from the web and change some small things and it'll > work and fit into my needs. BUT I didn't know there was such a > transitional API - interesting. I however don't want to be a > first-mover - let's see if sufficiently many people will use this and > then I'll consider doing it too. At the moment, I still think the > star-import is good because it makes it easy to look for C-code and > program it (=do it) like people would do it in C. > >> or, if you really needed PEP-8 compliance, and don't mind making the API >> look nothing like the original, we might even go to: >> >> from opengl import gl, glu, glut >> >> gl.rotate(...) >> gl.clear(gl.COLOR_BUFFER_BIT) > > Erhm, that's the same as above. Is that what you meant to write? > No, it's not the same; here he did not capitalize the function names. Previously they look like class instantiations. > > > Well, I'm sometimes a bit annoyed that python doesn't give as many > warnings/errors as one gets in C - for instance sometimes I copy/paste > and forget to remove the trailing semi-colons. Trailing semi colons are legal in most cases. The semi-colon is a separator between statements, when one wants to put multiple statements on one line. > However after I began to use pylint and friends, this error will be > caught. Then sometimes I forgot to add () for function calls, which in > C would cause an error by the compiler Actually no. In C, a function name without parentheses is also a function pointer. Not exactly the same as a function object, though C++ gets a lot closer. But the real reason C catches that typo is that the types most likely don't match, depending on what you meant to do with the return value. > but which python allows so one can get the object (which maybe is also > a good reason, but at least in the beginning when I learned python, > this was very annoying + confusing to me). > Function objects are enormously useful, as you get more adept at using Python. -- DaveA From newsboost at gmail.com Sat Jan 5 05:49:39 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 11:49:39 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/05/2013 02:30 AM, Dave Angel wrote: >>> from opengl import gl, glu, glut >>> >>> gl.rotate(...) >>> gl.clear(gl.COLOR_BUFFER_BIT) >> >> Erhm, that's the same as above. Is that what you meant to write? >> > > No, it's not the same; here he did not capitalize the function names. > Previously they look like class instantiations. Ah, you're right. Sorry :-) >> Well, I'm sometimes a bit annoyed that python doesn't give as many >> warnings/errors as one gets in C - for instance sometimes I copy/paste >> and forget to remove the trailing semi-colons. > > Trailing semi colons are legal in most cases. The semi-colon is a > separator between statements, when one wants to put multiple statements > on one line. > >> However after I began to use pylint and friends, this error will be >> caught. Then sometimes I forgot to add () for function calls, which in >> C would cause an error by the compiler > > Actually no. In C, a function name without parentheses is also a > function pointer. Not exactly the same as a function object, though C++ > gets a lot closer. But the real reason C catches that typo is that the > types most likely don't match, depending on what you meant to do with > the return value. Ok, I think you're right. At least I find that C-compilers catches many errors/warnings which python don't say anything about. But also C require me to define/declarer the types of variables before I use them... OTOH I guess I like that python is faster to code in, compared to C... >> but which python allows so one can get the object (which maybe is also >> a good reason, but at least in the beginning when I learned python, >> this was very annoying + confusing to me). >> > > Function objects are enormously useful, as you get more adept at using > Python. Ok, I'll look forward to that. Recently I had some problems with pass-by-value vs pass-by-reference. I googled the problem and found that by default python passes by reference. I then debugged my program and finally found out that I should make a copy (a new object) of the variable, before I passed it to my function. And THIS solved my problem. But in C/C++ I think the default is to pass by value, so this error in my program was a bit unexpected... Anyway, I feel python is a great language for doing things much faster than I could possibly do in C/C++. I also have on my todo-list to take my opengl-program and make it into an executable. I mainly sit on a linux-pc but I want to distribute my opengl program for windows (which has most users). I've found something on google for py2app, cx_Freeze, bbfreeze and Freeze and I hope this cross-platform thing does not cause too many problems... I tried one of these tools a few weeks ago but I think I only succeeded with a very simple hello-world program... Anyway, that's a problem I'll investigate in a few months when I think/hope my opengl program is finished... From d at davea.name Sat Jan 5 06:23:22 2013 From: d at davea.name (Dave Angel) Date: Sat, 05 Jan 2013 06:23:22 -0500 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: <50E80D2A.3010805@davea.name> On 01/05/2013 05:49 AM, someone wrote: > On 01/05/2013 02:30 AM, Dave Angel wrote: > >> >> Function objects are enormously useful, as you get more adept at using >> Python. > > Ok, I'll look forward to that. Recently I had some problems with > pass-by-value vs pass-by-reference. I googled the problem and found > that by default python passes by reference. Pascal has two calling conventions (value and reference). C always calls by value. C++ adds a call by reference, and maybe later C standards have added it as well. Python always calls by object. In fact, one could argue that there are no values (in the C sense) in Python. All names, and all attributes, and all slots in collections, are references to objects. So when you call a function, what you're doing is telling the function how to reference the same object(s). The usual way to say that is that the function call binds a new name to an existing object. If that object is mutable, then perhaps you wanted to do a copy first. Or perhaps you didn't. As you say, you debugged the program to find out. > I then debugged my program and finally found out that I should make a > copy (a new object) of the variable, before I passed it to my > function. And THIS solved my problem. But in C/C++ I think the default > is to pass by value, so this error in my program was a bit > unexpected... Anyway, I feel python is a great language for doing > things much faster than I could possibly do in C/C++. > > I also have on my todo-list to take my opengl-program and make it into > an executable. I mainly sit on a linux-pc but I want to distribute my > opengl program for windows (which has most users). I've found > something on google for py2app, cx_Freeze, bbfreeze and Freeze and I > hope this cross-platform thing does not cause too many problems... I > tried one of these tools a few weeks ago but I think I only succeeded > with a very simple hello-world program... Anyway, that's a problem > I'll investigate in a few months when I think/hope my opengl program > is finished... > -- DaveA From rosuav at gmail.com Sat Jan 5 06:47:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 22:47:17 +1100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On Sat, Jan 5, 2013 at 9:49 PM, someone wrote: > Ok, I think you're right. At least I find that C-compilers catches many > errors/warnings which python don't say anything about. But also C require me > to define/declarer the types of variables before I use them... OTOH I guess > I like that python is faster to code in, compared to C... C has typed variables, so it's a compile-time error to try to put any other type into that variable. Python doesn't. That flexibility comes at the cost of error-catching. There are hybrid systems, but in general, type declarations imply variable declarations, and that's something that Python doesn't want. (I'm of the opinion that declarations aren't such a bad thing; they make some aspects of scoping easier. However, that's a design decision that Python is as unlikely to reverse as indentation-defined blocks.) > Ok, I'll look forward to that. Recently I had some problems with > pass-by-value vs pass-by-reference. I googled the problem and found that by > default python passes by reference. No, it doesn't. You can find good references on the subject in various places, but call-by-reference as implemented in Pascal simply doesn't exist in most modern languages, because its semantics are way confusing. The name given to this technique varies; here's a couple of links: http://effbot.org/zone/call-by-object.htm http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing ChrisA From newsboost at gmail.com Sat Jan 5 08:06:30 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 14:06:30 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/05/2013 12:47 PM, Chris Angelico wrote: > C has typed variables, so it's a compile-time error to try to put any > other type into that variable. Python doesn't. That flexibility comes > at the cost of error-catching. There are hybrid systems, but in > general, type declarations imply variable declarations, and that's > something that Python doesn't want. (I'm of the opinion that > declarations aren't such a bad thing; they make some aspects of > scoping easier. However, that's a design decision that Python is as > unlikely to reverse as indentation-defined blocks.) Understood. >> Ok, I'll look forward to that. Recently I had some problems with >> pass-by-value vs pass-by-reference. I googled the problem and found that by >> default python passes by reference. > > No, it doesn't. You can find good references on the subject in various > places, but call-by-reference as implemented in Pascal simply doesn't > exist in most modern languages, because its semantics are way > confusing. The name given to this technique varies; here's a couple of > links: > > http://effbot.org/zone/call-by-object.htm > http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing If you don't like calling it "pass-by-reference", perhaps you prefer calling it: ?call by object reference?... From: http://effbot.org/zone/call-by-object.htm In any case I think we understand each other. From rosuav at gmail.com Sat Jan 5 08:27:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 00:27:19 +1100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On Sun, Jan 6, 2013 at 12:06 AM, someone wrote: > On 01/05/2013 12:47 PM, Chris Angelico wrote: >> You can find good references on the subject in various >> places, but call-by-reference as implemented in Pascal simply doesn't >> exist in most modern languages, because its semantics are way >> confusing. The name given to this technique varies; here's a couple of >> links: >> >> http://effbot.org/zone/call-by-object.htm >> http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing > > If you don't like calling it "pass-by-reference", perhaps you prefer calling > it: ?call by object reference?... From: > http://effbot.org/zone/call-by-object.htm > > In any case I think we understand each other. That's one of the links I just posted :) It's not just a naming difference, though. With Pascal's pass-by-reference semantics, this code would act differently: def foo(x): x = 5 a = 2 foo(a) print(a) Python prints 2, because the assignment to x just rebinds the name inside foo. True pass-by-reference actually changes the caller's variable. C can achieve this by means of pointers; in Python, you can pass and mutate a list, thus: def foo(x): x[0] = 5 # Dereference the pointer, kinda x=[None] # Declare a pointer variable, ish x[0] = 2 foo(x) # Don't forget to drop the [0] when passing the pointer to another function print(x[0]) # Prints 5. See? We have pass-by-reference! But otherwise, rebinding names in the function has no effect on anything outside. Among other things, this guarantees that, in any situation, a name referencing an object can be perfectly substituted for any other name referencing the same object, or any other way of accessing the object. def foo(lst): lst[0]=len(lst) x = [10,20,30] y = x foo(x) # These two... foo(y) # ... are identical! This is a philosophy that extends through the rest of the language. A function returning a list can be directly dereferenced, as can a list literal: def foo(): return [0,1,4,9,16] print( ["Hello","world!","Testing","Testing","One","Two","Three"][foo()[2]] ) This is a flexibility and power that just doesn't exist in many older languages (C and PHP, I'm looking at you). Object semantics make more sense than any other system for a modern high level language, which is why many of them do things that way. ChrisA From newsboost at gmail.com Sat Jan 5 14:49:03 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 20:49:03 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/05/2013 02:27 PM, Chris Angelico wrote: > On Sun, Jan 6, 2013 at 12:06 AM, someone wrote: >> In any case I think we understand each other. > > That's one of the links I just posted :) It's not just a naming > difference, though. With Pascal's pass-by-reference semantics, this > code would act differently: > > def foo(x): > x = 5 > > a = 2 > foo(a) > print(a) > > Python prints 2, because the assignment to x just rebinds the name > inside foo. True pass-by-reference actually changes the caller's > variable. C can achieve this by means of pointers; in Python, you can I thought that python also used "true" pass-by-reference, although I haven't figured out exactly when I have this problem. I can just see that sometimes I get this problem and then I need to copy the variable, if I don't want the original data of the variable to be overwritten... > pass and mutate a list, thus: > > def foo(x): > x[0] = 5 # Dereference the pointer, kinda > > x=[None] # Declare a pointer variable, ish > x[0] = 2 > foo(x) # Don't forget to drop the [0] when passing the pointer to > another function > print(x[0]) # Prints 5. See? We have pass-by-reference! Yes, something like this has happened to me in my python code... Not sure if my example was exactly like this, but I remember something where I found this to be a problem that I had to fix. > But otherwise, rebinding names in the function has no effect on > anything outside. Among other things, this guarantees that, in any hmm. ok.... So it's not true pass-by-reference like I thought... That's interesting. > situation, a name referencing an object can be perfectly substituted > for any other name referencing the same object, or any other way of > accessing the object. > > def foo(lst): > lst[0]=len(lst) > > x = [10,20,30] > y = x > foo(x) # These two... > foo(y) # ... are identical! This is something I've experienced from my own coding, I think... > This is a philosophy that extends through the rest of the language. A > function returning a list can be directly dereferenced, as can a list > literal: > > def foo(): > return [0,1,4,9,16] > > print( ["Hello","world!","Testing","Testing","One","Two","Three"][foo()[2]] ) That prints out "One"... I think I understand - that's interesting too... > This is a flexibility and power that just doesn't exist in many older > languages (C and PHP, I'm looking at you). Object semantics make more > sense than any other system for a modern high level language, which is > why many of them do things that way. I agree, that I think python is really great and it's fast to do something useful. Not sure I still understand exactly all aspects of this pass-by-value and by-references, but in any case I know enough to watch out for this problem and once I see I have a problem, I can also take care of it and solve it by making a copy. I think maybe after 3-6-9 months more of working with python, I should be fully confident with this. Thanks for taking the time to explain a bit of this to me... From wuwei23 at gmail.com Sun Jan 6 06:37:37 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 6 Jan 2013 03:37:37 -0800 (PST) Subject: pygame - importing GL - very bad... References: Message-ID: <27092146-597f-457f-a38d-adfa90036d0b@i2g2000pbi.googlegroups.com> On Jan 6, 5:49?am, someone wrote: > I thought that python also used "true" pass-by-reference, although I > haven't figured out exactly when I have this problem. I can just see > that sometimes I get this problem and then I need to copy the variable, > if I don't want the original data of the variable to be overwritten... Generally I find it easier to call variables 'labels' or 'references'; you're not stashing a value into a slot, you're giving a name to an object. So you're never really passing values around, just labels that refer to an object. The confusion kicks in because there are two types of object: mutable and immutable. Mutable objects can change, immutable objects cannot. Operations on an immutable object will return a _new_ immutable object; the label used in an operation on an immutable object will refer to the new object, any other references to the original object will continue to refer to the original. Strings, numbers, tuples and frozensets are all immutable built-in types. >>> a = "alpha" >>> b = a >>> a = a + "bet" >>> a 'alphabet' >>> b 'alpha' With immutable types, you're safe to pass them into a function, act on them, and not have references in the outer scope reflect the change: >>> def double(x): return x * 2 ... >>> a = "alpha" >>> double(a) 'alphaalpha' >>> a 'alpha' Everything else, including user defined objects, tend to be mutable: >>> a = dict(foo=1,bar=2) >>> b = a >>> a['foo'] = 99 >>> a {'foo': 99, 'bar': 2} >>> b {'foo': 99, 'bar': 2} With mutable objects, you're _always_ operating on the _same_ object that everything is referring to, even when you pass it into a different scope: >>> def toggle_foo( x ): x['foo'] = not x['foo'] ... >>> a = dict(foo=True) >>> toggle_foo(a) >>> a {'foo': False} Note that the `toggle_foo` function doesn't return anything, nor is the value of a re-assigned. The object that a refers to is passed into `toggle_foo`, modified in place, and all references to it remain pointing to the same, now modified object. This is one of the big causes of unexpected behaviour to new Python users, but as you get a better understanding of how Python's object model works, you'll see it's really quite consistent and predictable. There are a couple of ways you can ensure you're always working with a copy of an object if you need to. For lists, the canonical way is: >>> a = [1,2,3] >>> b = a >>> a = [1, 2, 3] >>> b = a[:] # shallow copy of a >>> b.append(99) >>> b [1, 2, 3, 99] >>> a [1, 2, 3] `b = a[:]` uses slice notation to create a new list that contains everything in the original list, from start to end. This is called a "shallow" copy; `a` and `b` both refer to _different_ lists, but the objects within are the _same_ objects. For numbers, this isn't important, as they're immutable. For mutable objects, however, it's something you need to bear in mind: >>> a = [ [1,2], [3, 4] ] # list of lists >>> b = a[:] >>> b[0][0] = 99 >>> b [[99, 2], [3, 4]] >>> a [[99, 2], [3, 4]] So here, while `b` refers to copy of `a`, that copy contains the _same_ list objects that `a` does, so any changes to the internal lists will be reflected in both references, while any changes to `b` itself won't be: >>> b.append([5,6]) >>> b [[99, 2], [3, 4], [5, 6]] >>> a [[99, 2], [3, 4]] This is where the `copy` module comes to the rescue, providing a shallow copy function `copy`, as well as `deepcopy` that makes copies of all the objects within the object: >>> import copy >>> a = [ [1,2], [3, 4] ] # list of lists >>> b = copy.deepcopy(a) >>> b[0][0] = 99 >>> b [[99, 2], [3, 4]] >>> a [[1, 2], [3, 4]] If you plan on using the `copy` module, it's worthwhile readings it docs, as there are some nuances to it that I'm glossing over here. TBH, I don't recall every needing to use `copy` in my code. Hope this helps bring consistency where you currently find confusion :) From newsboost at gmail.com Sun Jan 6 07:46:51 2013 From: newsboost at gmail.com (someone) Date: Sun, 06 Jan 2013 13:46:51 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: <27092146-597f-457f-a38d-adfa90036d0b@i2g2000pbi.googlegroups.com> References: <27092146-597f-457f-a38d-adfa90036d0b@i2g2000pbi.googlegroups.com> Message-ID: On 01/06/2013 12:37 PM, alex23 wrote: > On Jan 6, 5:49 am, someone wrote: >> I thought that python also used "true" pass-by-reference, although I >> haven't figured out exactly when I have this problem. I can just see >> that sometimes I get this problem and then I need to copy the variable, >> if I don't want the original data of the variable to be overwritten... > > Generally I find it easier to call variables 'labels' or 'references'; > you're not stashing a value into a slot, you're giving a name to an > object. So you're never really passing values around, just labels that > refer to an object. Ok. > The confusion kicks in because there are two types of object: mutable > and immutable. Mutable objects can change, immutable objects cannot. Yes, I've seen that described before. > Operations on an immutable object will return a _new_ immutable > object; the label used in an operation on an immutable object will > refer to the new object, any other references to the original object > will continue to refer to the original. Strings, numbers, tuples and > frozensets are all immutable built-in types. > > >>> a = "alpha" > >>> b = a > >>> a = a + "bet" > >>> a > 'alphabet' > >>> b > 'alpha' Ok, I think I knew some of these things, however I didn't think so much about them before now. > With immutable types, you're safe to pass them into a function, act on > them, and not have references in the outer scope reflect the change: > > >>> def double(x): return x * 2 > ... > >>> a = "alpha" > >>> double(a) > 'alphaalpha' > >>> a > 'alpha' This is exactly what I've found out happens to me some times. Until now I've managed to fix my problems. But it's good to remember this thing with immutable vs. mutable types, which was something I didn't think much about before. I'll think about this difference in the future, thank you. > Everything else, including user defined objects, tend to be mutable: > > >>> a = dict(foo=1,bar=2) > >>> b = a > >>> a['foo'] = 99 > >>> a > {'foo': 99, 'bar': 2} > >>> b > {'foo': 99, 'bar': 2} Yes, I've noticed this a lot of times in my own coding... > With mutable objects, you're _always_ operating on the _same_ object > that everything is referring to, even when you pass it into a > different scope: > > >>> def toggle_foo( x ): x['foo'] = not x['foo'] > ... > >>> a = dict(foo=True) > >>> toggle_foo(a) > >>> a > {'foo': False} Exactly, what I've also experienced a few times. > Note that the `toggle_foo` function doesn't return anything, nor is > the value of a re-assigned. The object that a refers to is passed into > `toggle_foo`, modified in place, and all references to it remain > pointing to the same, now modified object. Yes, I notice that, thanks. > This is one of the big causes of unexpected behaviour to new Python > users, but as you get a better understanding of how Python's object > model works, you'll see it's really quite consistent and predictable. It was a bit surprising to me in the beginning - though I'm still a beginner (or maybe now almost an "intermediate" user), the good explanation you come with now wasn't something I've thought so much of before now. But I've clearly experienced many of the examples you write about here, in my own coding and I've usually been very careful about checking if my original object was modified un-intentionally. I think I can deal with this now. > There are a couple of ways you can ensure you're always working with a > copy of an object if you need to. For lists, the canonical way is: > > >>> a = [1,2,3] > >>> b = a > >>> a = [1, 2, 3] > >>> b = a[:] # shallow copy of a > >>> b.append(99) > >>> b > [1, 2, 3, 99] > >>> a > [1, 2, 3] > > `b = a[:]` uses slice notation to create a new list that contains > everything in the original list, from start to end. This is called a > "shallow" copy; `a` and `b` both refer to _different_ lists, but the > objects within are the _same_ objects. For numbers, this isn't Ok, good to know. > important, as they're immutable. For mutable objects, however, it's > something you need to bear in mind: > > >>> a = [ [1,2], [3, 4] ] # list of lists > >>> b = a[:] > >>> b[0][0] = 99 > >>> b > [[99, 2], [3, 4]] > >>> a > [[99, 2], [3, 4]] > > So here, while `b` refers to copy of `a`, that copy contains the > _same_ list objects that `a` does, so any changes to the internal > lists will be reflected in both references, while any changes to `b` > itself won't be: > > >>> b.append([5,6]) > >>> b > [[99, 2], [3, 4], [5, 6]] > >>> a > [[99, 2], [3, 4]] Yes, I've experienced this kind of thing before - but it's a very very good explanation you give me know. It makes me understand the problem much better, next time I experience it... > This is where the `copy` module comes to the rescue, providing a > shallow copy function `copy`, as well as `deepcopy` that makes copies > of all the objects within the object: > > >>> import copy > >>> a = [ [1,2], [3, 4] ] # list of lists > >>> b = copy.deepcopy(a) > >>> b[0][0] = 99 > >>> b > [[99, 2], [3, 4]] > >>> a > [[1, 2], [3, 4]] > > If you plan on using the `copy` module, it's worthwhile readings it > docs, as there are some nuances to it that I'm glossing over here. > TBH, I don't recall every needing to use `copy` in my code. I almost had to use this "copy.deepcopy" the other day, but I googled for it and then I found a way to avoid it... > Hope this helps bring consistency where you currently find confusion :) Yes, this is a VERY very good explanation. I was a bit confused about when I created my own user defined objects, but now you explained that these tend to be mutable which is also my experience. I'll still keep an extra eye out for this special way of sending objects back and forward between function, in order to un-intentionally overwrite some data... Thanks you very much for a very good and precise description of this phenomena of the python-language (or what I should call it) :-) From newsboost at gmail.com Tue Jan 1 18:50:04 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 00:50:04 +0100 Subject: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/01/2013 01:56 PM, Peter Otten wrote: > someone wrote: > It turns out pylint is lying. The situation is equivalent to > > $ cat module.py > for format in [42]: > pass > del format > > $ cat main.py > original_format = format > from module import * > assert format is original_format > $ python main.py > > The assert doesn't trigger, so format is not redefined. But pylint complains > anyway: > > $ pylint main.py -rn > No config file found, using default configuration > ************* Module main > W: 2: Redefining built-in 'format' > C: 1: Missing docstring > C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| > (__.*__))$) > W: 2: Wildcard import module > > If you can ignore the warning about the wildcard import you should be able In the case of opengl import, I'll ignore the wildcard import warning. But in other cases I'll likely look a bit into it and see if I can avoid it or at least change it to something like: "import OpenGL.GL as GL" etc. > to ignore the "redefining built-in" warning, too. Personally I would avoid > putting magic comments like > > from module import * # pylint: disable=W0622 Oh, I just learned something new now... How come I cannot type "#pylint: enable=W0622" in the line just below the import ? Not so intuitively/logically for me... > $ pylint main.py -rn > No config file found, using default configuration > ************* Module main > I: 2: Locally disabling W0622 > C: 1: Missing docstring > C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| > (__.*__))$) > W: 2: Wildcard import module > > into the code. Thank you very much... Another thing is that I don't understand this warning: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| > (__.*__))$) I get it everywhere... I don't understand how it wants me to label my variables... Maybe I should disable this warning to get rid of it... From __peter__ at web.de Wed Jan 2 07:07:36 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 Jan 2013 13:07:36 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... References: Message-ID: someone wrote: > On 01/01/2013 01:56 PM, Peter Otten wrote: >> from module import * # pylint: disable=W0622 > > Oh, I just learned something new now... How come I cannot type "#pylint: > enable=W0622" in the line just below the import ? With what intended effect? > Another thing is that I don't understand this warning: > > Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| > > (__.*__))$) > > I get it everywhere... I don't understand how it wants me to label my > variables... Maybe I should disable this warning to get rid of it... pylint wants global names to be uppercase (what PEP 8 recommends for constants) or "special" (two leading and two trailing underscores): THATS_OK = 42 __thats_ok_too__ = object() but_thats_not = "spam" From rosuav at gmail.com Wed Jan 2 09:32:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 01:32:57 +1100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On Wed, Jan 2, 2013 at 11:07 PM, Peter Otten <__peter__ at web.de> wrote: > someone wrote: >> Another thing is that I don't understand this warning: >> >> Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| >> > (__.*__))$) >> >> I get it everywhere... I don't understand how it wants me to label my >> variables... Maybe I should disable this warning to get rid of it... > > pylint wants global names to be uppercase (what PEP 8 recommends for > constants) or "special" (two leading and two trailing underscores): > > THATS_OK = 42 > __thats_ok_too__ = object() > but_thats_not = "spam" Okay, I have to ask... why? Does it have an exception for names of classes? I don't like linters that enforce too much style. Catch things that might be mis-coded (like C's classic "if (x = 1)"), but don't complain about my names. They're MY business. ChrisA From ian.g.kelly at gmail.com Wed Jan 2 12:52:11 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Jan 2013 10:52:11 -0700 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On Wed, Jan 2, 2013 at 7:32 AM, Chris Angelico wrote: > Okay, I have to ask... why? Does it have an exception for names of classes? Yes, and for module-level functions. > I don't like linters that enforce too much style. Catch things that > might be mis-coded (like C's classic "if (x = 1)"), but don't complain > about my names. They're MY business. pylint is configurable though, so you can disable any warnings you don't care about. My pylint macro has a fairly large number of -d options in it. From rosuav at gmail.com Wed Jan 2 12:57:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 04:57:12 +1100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On Thu, Jan 3, 2013 at 4:52 AM, Ian Kelly wrote: > On Wed, Jan 2, 2013 at 7:32 AM, Chris Angelico wrote: >> Okay, I have to ask... why? Does it have an exception for names of classes? > > Yes, and for module-level functions. Oh, okay. So the check's a lot more specific than the message implies - it applies only to non-callable module level names. I guess that's reasonable. >> I don't like linters that enforce too much style. Catch things that >> might be mis-coded (like C's classic "if (x = 1)"), but don't complain >> about my names. They're MY business. > > pylint is configurable though, so you can disable any warnings you > don't care about. My pylint macro has a fairly large number of -d > options in it. Yeah, same applies to most linters I think. You end up disagreeing with the author on half the points. Oh well. Doesn't make the tool useless, just means you need to fiddle with it to get it how you want it. ChrisA From ian.g.kelly at gmail.com Wed Jan 2 14:31:52 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Jan 2013 12:31:52 -0700 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On Wed, Jan 2, 2013 at 10:57 AM, Chris Angelico wrote: > Yeah, same applies to most linters I think. You end up disagreeing > with the author on half the points. Oh well. Doesn't make the tool > useless, just means you need to fiddle with it to get it how you want > it. It's a lot less work to disable a check than to implement a desired check that is missing, so to me it's better that a linter do too much by default than not enough. From newsboost at gmail.com Wed Jan 2 21:31:15 2013 From: newsboost at gmail.com (someone) Date: Thu, 03 Jan 2013 03:31:15 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/02/2013 08:31 PM, Ian Kelly wrote: > On Wed, Jan 2, 2013 at 10:57 AM, Chris Angelico wrote: >> Yeah, same applies to most linters I think. You end up disagreeing >> with the author on half the points. Oh well. Doesn't make the tool >> useless, just means you need to fiddle with it to get it how you want >> it. > > It's a lot less work to disable a check than to implement a desired > check that is missing, so to me it's better that a linter do too much > by default than not enough. I just started using pylint and some of the stuff it came up with is REALLY good - so I'll definately use pylint, pep8 (and friends) more in the future. And I think I'll also get to a point where I'll disable some of the checks - as one of you wrote: How I name my variables is (maybe) my own business and for instance I like a short variable name once in a while, e.g. "rx", "ry", "rz" for rotation around x- y- and z-axises and these variable names should not be changed. But can I ask you something: English is not my native language and I looked up what "linter" means - but it's not in my dictionary. What doet "linter" mean ? I don't suppose these exlanations are the same as you would give, in the context you're using? http://www.wordreference.com/definition/linter http://www.collinsdictionary.com/dictionary/american/linter http://www.merriam-webster.com/dictionary/linter ? From d at davea.name Wed Jan 2 21:56:44 2013 From: d at davea.name (Dave Angel) Date: Wed, 02 Jan 2013 21:56:44 -0500 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: <50E4F36C.70307@davea.name> On 01/02/2013 09:31 PM, someone wrote: > On 01/02/2013 08:31 PM, Ian Kelly wrote: >> On Wed, Jan 2, 2013 at 10:57 AM, Chris Angelico >> wrote: >>> Yeah, same applies to most linters I think. You end up disagreeing >>> with the author on half the points. Oh well. Doesn't make the tool >>> useless, just means you need to fiddle with it to get it how you want >>> it. >> >> It's a lot less work to disable a check than to implement a desired >> check that is missing, so to me it's better that a linter do too much >> by default than not enough. > > I just started using pylint and some of the stuff it came up with is > REALLY good - so I'll definately use pylint, pep8 (and friends) more > in the future. And I think I'll also get to a point where I'll disable > some of the checks - as one of you wrote: How I name my variables is > (maybe) my own business and for instance I like a short variable name > once in a while, e.g. "rx", "ry", "rz" for rotation around x- y- and > z-axises and these variable names should not be changed. > > But can I ask you something: English is not my native language and I > looked up what "linter" means - but it's not in my dictionary. What > doet "linter" mean ? > > I don't suppose these exlanations are the same as you would give, in > the context you're using? > > http://www.wordreference.com/definition/linter > http://www.collinsdictionary.com/dictionary/american/linter > http://www.merriam-webster.com/dictionary/linter > > ? > The first lint program I recall hearing of was available in the early 1980's, and was for the C language. At the time, the C language was extremely flexible (in other words, lots of ways to shoot yourself in the foot) and the compiler was mostly of the philosophy - if there's a way to make sense of the statement, generate some code, somehow. Anyway, lint made sense to me as the crud that gets mixed in with the real fabric. And a linter is a machine that identifies and removes that crud. Well, the lint program didn't remove anything, but it identified a lot of it. I didn't hear the term linter till decades later. -- DaveA From newsboost at gmail.com Fri Jan 4 20:23:05 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 02:23:05 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/03/2013 03:56 AM, Dave Angel wrote: > The first lint program I recall hearing of was available in the early > 1980's, and was for the C language. At the time, the C language was > extremely flexible (in other words, lots of ways to shoot yourself in > the foot) and the compiler was mostly of the philosophy - if there's a > way to make sense of the statement, generate some code, somehow. > > Anyway, lint made sense to me as the crud that gets mixed in with the > real fabric. And a linter is a machine that identifies and removes that > crud. Well, the lint program didn't remove anything, but it identified > a lot of it. I didn't hear the term linter till decades later. Aah, now I understand this "lintering" and where it came from - thanks a lot! :-) From newsboost at gmail.com Wed Jan 2 09:09:03 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 15:09:03 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/02/2013 01:07 PM, Peter Otten wrote: > someone wrote: > >> On 01/01/2013 01:56 PM, Peter Otten wrote: > >>> from module import * # pylint: disable=W0622 >> >> Oh, I just learned something new now... How come I cannot type "#pylint: >> enable=W0622" in the line just below the import ? > > With what intended effect? If I have a section with A LOT OF warnings and I don't want those in that section to show up ? Isn't that valid enough? >> Another thing is that I don't understand this warning: >> >> Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| >> > (__.*__))$) >> >> I get it everywhere... I don't understand how it wants me to label my >> variables... Maybe I should disable this warning to get rid of it... > > pylint wants global names to be uppercase (what PEP 8 recommends for > constants) or "special" (two leading and two trailing underscores): > > THATS_OK = 42 > __thats_ok_too__ = object() > but_thats_not = "spam" OMG... I don't want to type those underscores everywhere... Anyway, thank you very much for explaining the meaning of what it wants... From d at davea.name Wed Jan 2 09:26:32 2013 From: d at davea.name (Dave Angel) Date: Wed, 02 Jan 2013 09:26:32 -0500 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: <50E44398.8000704@davea.name> On 01/02/2013 09:09 AM, someone wrote: > On 01/02/2013 01:07 PM, Peter Otten wrote: >> someone wrote: >> >>> On 01/01/2013 01:56 PM, Peter Otten wrote: >> >>>> from module import * # pylint: disable=W0622 >>> >>> Oh, I just learned something new now... How come I cannot type >>> "#pylint: >>> enable=W0622" in the line just below the import ? >> >> With what intended effect? > > If I have a section with A LOT OF warnings and I don't want those in > that section to show up ? Isn't that valid enough? > >>> Another thing is that I don't understand this warning: >>> >>> Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)| >>> > (__.*__))$) >>> >>> I get it everywhere... I don't understand how it wants me to label my >>> variables... Maybe I should disable this warning to get rid of it... >> >> pylint wants global names to be uppercase (what PEP 8 recommends for >> constants) or "special" (two leading and two trailing underscores): >> >> THATS_OK = 42 >> __thats_ok_too__ = object() >> but_thats_not = "spam" > > OMG... I don't want to type those underscores everywhere... Anyway, > thank you very much for explaining the meaning of what it wants... > > > Global const values should be ALL_CAPS, so it's obvious that nobody intends to modify them. It's the non-const global attributes that expect to be underscored. You shouldn't have to use those underscores very often. After all, there is seldom a need for a non-const global value, right? Don't think of it as a pylint problem, but as a hint from pylint that perhaps you should use fewer globals. -- DaveA From steve+comp.lang.python at pearwood.info Wed Jan 2 18:52:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Jan 2013 23:52:27 GMT Subject: pylint, was Re: pygame - importing GL - very bad... References: Message-ID: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 Jan 2013 09:26:32 -0500, Dave Angel wrote: > On 01/02/2013 09:09 AM, someone wrote: >> On 01/02/2013 01:07 PM, Peter Otten wrote: >>> pylint wants global names to be uppercase (what PEP 8 recommends for >>> constants) or "special" (two leading and two trailing underscores): >>> >>> THATS_OK = 42 >>> __thats_ok_too__ = object() >>> but_thats_not = "spam" >> >> OMG... I don't want to type those underscores everywhere... Anyway, >> thank you very much for explaining the meaning of what it wants... >> >> >> >> > Global const values should be ALL_CAPS, so it's obvious that nobody > intends to modify them. Like math.pi I suppose? *wink* > It's the non-const global attributes that expect to be underscored. Pylint is wrong here. The double-leading-and-trailing-underscore naming scheme is reserved for Python itself. PEP 8 explicitly states not to invent your own "dunder" names: __double_leading_and_trailing_underscore__: "magic" objects or attributes that live in user-controlled namespaces. E.g. __init__, __import__ or __file__. Never invent such names; only use them as documented. The section on global variables does not say to use dunder names: http://www.python.org/dev/peps/pep-0008/#id31 If pylint says that global variables should be named like "__variable__", that is explicitly going against PEP 8. > You shouldn't have to use those underscores very often. After all, > there is seldom a need for a non-const global value, right? Don't think > of it as a pylint problem, but as a hint from pylint that perhaps you > should use fewer globals. That at least is good advice. -- Steven From ian.g.kelly at gmail.com Wed Jan 2 19:25:03 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Jan 2013 17:25:03 -0700 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 2, 2013 at 4:52 PM, Steven D'Aprano wrote: > If pylint says that global variables should be named like "__variable__", > that is explicitly going against PEP 8. It doesn't say that anywhere. It includes dunder names in the regex so that you don't get spurious warnings from pylint about the formatting of names like __all__, nothing more. From newsboost at gmail.com Wed Jan 2 21:24:25 2013 From: newsboost at gmail.com (someone) Date: Thu, 03 Jan 2013 03:24:25 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/03/2013 12:52 AM, Steven D'Aprano wrote: > On Wed, 02 Jan 2013 09:26:32 -0500, Dave Angel wrote: >> Global const values should be ALL_CAPS, so it's obvious that nobody >> intends to modify them. > > Like math.pi I suppose? *wink* :-) >> It's the non-const global attributes that expect to be underscored. > > Pylint is wrong here. Ok, forget my previous post - now I looked a bit deeper into it again. Consider this as an example: ------------------------ # Global mouse states = global constants: M_LEFT = 1 M_MIDDLE = 2 M_RIGHT = 3 M_WHEEL_UP = 4 M_WHEEL_DOWN = 5 class somethingWork: """ OpenGL something class """ def __init__(self, someInputFile): self.inputFile = someInputFile self.running = False # self.viewport = (800,600) self.viewport = (1024, 768) self.lightDone = False self.rx = 0 # rotation x self.ry = 0 # rotation y self.rz = 0 # rotation z .... etc ... ------------------------ What pylint says is: 1) class somethingWork: Invalid name "somethingWork" (should match [A-Z_][a-zA-Z0-9]+$), I'm not that good at regular exps, but I suppose it wants my class name to start with a capital letter ? 2) self.lightDone: Invalid name "lightDone" (should match [a-z_][a-z0-9_]{2,30}$) So I can now understand that pylint doesn't like my naming convention with a capital letter in the middle of the variable name, like: "lightDone" = a boolean value. I suppose pylint wants me to use (a little longer method) an underscore to separate words in long variable names... 3) self.rx / rself.ry / self.rz: Invalid name "rx" (should match [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an underscore ? I have a lot of these warnings... > The double-leading-and-trailing-underscore naming scheme is reserved for > Python itself. PEP 8 explicitly states not to invent your own "dunder" > names: > > __double_leading_and_trailing_underscore__: "magic" objects or > attributes that live in user-controlled namespaces. E.g. __init__, > __import__ or __file__. Never invent such names; only use them as > documented. I think I would also never use __something__ names... > The section on global variables does not say to use dunder names: > > http://www.python.org/dev/peps/pep-0008/#id31 Thanks a lot for this reference... > If pylint says that global variables should be named like "__variable__", > that is explicitly going against PEP 8. I don't think that is what it's saying... But I think it wants me to use more underscores, i.e. self.lightDone => self.light_done I think... >> You shouldn't have to use those underscores very often. After all, >> there is seldom a need for a non-const global value, right? Don't think >> of it as a pylint problem, but as a hint from pylint that perhaps you >> should use fewer globals. > > That at least is good advice. Ok, sorry for my previous post. This post better explains how I've named my variables. I don't like it complains about a simple and good variable name as self.rx, self.ry, self.rz and so on. These are IMHO very good variable names: rotation about x, y and z. Short and precise/accurate. I'm not sure if I'll agree with all the warnings it comes up with. But I think I could maybe introduce more use of underscores in the middle of my variable names, in the future... Thanks for the extra + good explanations. From tjreedy at udel.edu Wed Jan 2 21:48:49 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 Jan 2013 21:48:49 -0500 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/2/2013 9:24 PM, someone wrote: > What pylint says is: > > 1) class somethingWork: Invalid name "somethingWork" (should match > [A-Z_][a-zA-Z0-9]+$), I'm not that good at regular exps, but I suppose > it wants my class name to start with a capital letter ? Yes > > 2) self.lightDone: Invalid name "lightDone" (should match > [a-z_][a-z0-9_]{2,30}$) > > So I can now understand that pylint doesn't like my naming convention > with a capital letter in the middle of the variable name, like: > "lightDone" = a boolean value. I suppose pylint wants me to use (a > little longer method) an underscore to separate words in long variable > names... That is more conventional in the Python community (and is in pep 8, I believe) but still a choice. > 3) self.rx / rself.ry / self.rz: Invalid name "rx" (should match > [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an > underscore ? No, it allows underscores. As I read that re, 'rx', etc, do match. They are two chars in the indicated sets. I disagree with requiring 2 chars, as .x, .y, are sometimes quite appropriate. -- Terry Jan Reedy From __peter__ at web.de Thu Jan 3 04:00:42 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Jan 2013 10:00:42 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Terry Reedy wrote: >> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an >> underscore ? > > No, it allows underscores. As I read that re, 'rx', etc, do match. They No, it's one leading letter or underscore [a-z_] plus at least two letters, underscores or digits [a-z0-9_]{2,30} From newsboost at gmail.com Thu Jan 3 06:21:23 2013 From: newsboost at gmail.com (someone) Date: Thu, 03 Jan 2013 12:21:23 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/03/2013 10:00 AM, Peter Otten wrote: > Terry Reedy wrote: > >>> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an >>> underscore ? >> >> No, it allows underscores. As I read that re, 'rx', etc, do match. They > > No, it's one leading letter or underscore [a-z_] plus at least two letters, > underscores or digits [a-z0-9_]{2,30} Ah, [a-z0-9_]{2,30} means there should be at least two characters and maximum 30 characters here ? From __peter__ at web.de Thu Jan 3 06:39:12 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Jan 2013 12:39:12 +0100 Subject: Regular expression syntax, was Re: pylint, was Re: pygame - importing GL - very bad... References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: someone wrote: > On 01/03/2013 10:00 AM, Peter Otten wrote: >> Terry Reedy wrote: >> >>>> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with >>>> [an >>>> underscore ? >>> >>> No, it allows underscores. As I read that re, 'rx', etc, do match. They >> >> No, it's one leading letter or underscore [a-z_] plus at least two >> letters, underscores or digits [a-z0-9_]{2,30} > > Ah, [a-z0-9_]{2,30} means there should be at least two characters and > maximum 30 characters here ? Yes. See http://docs.python.org/2/library/re.html#regular-expression-syntax From newsboost at gmail.com Fri Jan 4 20:12:05 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 02:12:05 +0100 Subject: Regular expression syntax, was Re: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/03/2013 12:39 PM, Peter Otten wrote: > someone wrote: > >> On 01/03/2013 10:00 AM, Peter Otten wrote: >>> Terry Reedy wrote: >>> >>>>> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with >>>>> [an >>>>> underscore ? >>>> >>>> No, it allows underscores. As I read that re, 'rx', etc, do match. They >>> >>> No, it's one leading letter or underscore [a-z_] plus at least two >>> letters, underscores or digits [a-z0-9_]{2,30} >> >> Ah, [a-z0-9_]{2,30} means there should be at least two characters and >> maximum 30 characters here ? > > Yes. See > > http://docs.python.org/2/library/re.html#regular-expression-syntax Thanks - it's on my TODO-list to learn more about how to use these regexps... From mcfletch at vrplumber.com Thu Jan 3 09:19:19 2013 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Thu, 03 Jan 2013 09:19:19 -0500 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50E59367.1040306@vrplumber.com> On 13-01-02 09:48 PM, Terry Reedy wrote: ... > 2) self.lightDone: Invalid name "lightDone" (should match >> [a-z_][a-z0-9_]{2,30}$) >> >> So I can now understand that pylint doesn't like my naming convention >> with a capital letter in the middle of the variable name, like: >> "lightDone" = a boolean value. I suppose pylint wants me to use (a >> little longer method) an underscore to separate words in long variable >> names... > > That is more conventional in the Python community (and is in pep 8, I > believe) but still a choice. That seems like a improper error message from the tool. "Invalid name" does *not* properly describe that situation. The name is *not* "Invalid" in any sense of the word, and a "checker" that tells you it is is creating needless false-positives. An error checker should be saying something like: "self.lightDone: Does not match PEP8 recommended style" making it clear that this is *not* an error, it is a *style* related *warning*. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From tjreedy at udel.edu Thu Jan 3 11:52:33 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 03 Jan 2013 11:52:33 -0500 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: <50E59367.1040306@vrplumber.com> References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E59367.1040306@vrplumber.com> Message-ID: On 1/3/2013 9:19 AM, Mike C. Fletcher wrote: > On 13-01-02 09:48 PM, Terry Reedy wrote: > ... >> 2) self.lightDone: Invalid name "lightDone" (should match >>> [a-z_][a-z0-9_]{2,30}$) >>> >>> So I can now understand that pylint doesn't like my naming convention >>> with a capital letter in the middle of the variable name, like: >>> "lightDone" = a boolean value. I suppose pylint wants me to use (a >>> little longer method) an underscore to separate words in long variable >>> names... >> >> That is more conventional in the Python community (and is in pep 8, I >> believe) but still a choice. > That seems like a improper error message from the tool. "Invalid name" > does *not* properly describe that situation. The name is *not* > "Invalid" in any sense of the word, and a "checker" that tells you it is > is creating needless false-positives. An error checker should be saying > something like: > > "self.lightDone: Does not match PEP8 recommended style" > > making it clear that this is *not* an error, it is a *style* related > *warning*. I quite agree. Wanting 3 chars for attribute names is not even PEP-8 style but pylint-author style. I was really surprised at that. In that case, 'Does not match pylint recommended style.' or even 'configured styles'. I have not used pylint or pychecker as of yet. -- Terry Jan Reedy From newsboost at gmail.com Fri Jan 4 20:14:24 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 02:14:24 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> <50E59367.1040306@vrplumber.com> Message-ID: On 01/03/2013 05:52 PM, Terry Reedy wrote: >> That seems like a improper error message from the tool. "Invalid name" >> does *not* properly describe that situation. The name is *not* >> "Invalid" in any sense of the word, and a "checker" that tells you it is >> is creating needless false-positives. An error checker should be saying >> something like: >> >> "self.lightDone: Does not match PEP8 recommended style" >> >> making it clear that this is *not* an error, it is a *style* related >> *warning*. > > I quite agree. Wanting 3 chars for attribute names is not even PEP-8 > style but pylint-author style. I was really surprised at that. In that > case, 'Does not match pylint recommended style.' or even 'configured > styles'. I have not used pylint or pychecker as of yet. I agree with you all... Thanks, everyone - now I shall investigate pylint and friends in more detail on my own :-) From ian.g.kelly at gmail.com Wed Jan 2 21:55:07 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Jan 2013 19:55:07 -0700 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 2, 2013 at 7:24 PM, someone wrote: > 1) class somethingWork: Invalid name "somethingWork" (should match > [A-Z_][a-zA-Z0-9]+$), I'm not that good at regular exps, but I suppose it > wants my class name to start with a capital letter ? Yes, PEP-8 recommends CamelCase for class names. > 2) self.lightDone: Invalid name "lightDone" (should match > [a-z_][a-z0-9_]{2,30}$) > > So I can now understand that pylint doesn't like my naming convention with a > capital letter in the middle of the variable name, like: "lightDone" = a > boolean value. I suppose pylint wants me to use (a little longer method) an > underscore to separate words in long variable names... Also yes. > 3) self.rx / rself.ry / self.rz: Invalid name "rx" (should match > [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an > underscore ? It wants the name to be at least 3 characters long. From ben+python at benfinney.id.au Thu Jan 3 01:01:07 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 03 Jan 2013 17:01:07 +1100 Subject: pylint, was Re: pygame - importing GL - very bad... References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7wk3rux0t8.fsf@benfinney.id.au> Ian Kelly writes: > On Wed, Jan 2, 2013 at 7:24 PM, someone wrote: > > 1) class somethingWork: Invalid name "somethingWork" (should match > > [A-Z_][a-zA-Z0-9]+$), I'm not that good at regular exps, but I > > suppose it wants my class name to start with a capital letter ? > > Yes, PEP-8 recommends CamelCase for class names. PEP 8 discourages camelCase for names except for compatibility purposes, and recommends TitleCase for class names. -- \ ?I'm having amnesia and d?j? vu at the same time. I feel like | `\ I've forgotten this before sometime.? ?Steven Wright | _o__) | Ben Finney From clp2 at rebertia.com Thu Jan 3 01:33:36 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 Jan 2013 22:33:36 -0800 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: <7wk3rux0t8.fsf@benfinney.id.au> References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> <7wk3rux0t8.fsf@benfinney.id.au> Message-ID: On Wed, Jan 2, 2013 at 10:01 PM, Ben Finney wrote: > Ian Kelly writes: > >> On Wed, Jan 2, 2013 at 7:24 PM, someone wrote: >> > 1) class somethingWork: Invalid name "somethingWork" (should match >> > [A-Z_][a-zA-Z0-9]+$), I'm not that good at regular exps, but I >> > suppose it wants my class name to start with a capital letter ? >> >> Yes, PEP-8 recommends CamelCase for class names. > > PEP 8 discourages camelCase for names except for compatibility purposes, > and recommends TitleCase for class names. If we must quibble over meta-nomenclature... http://www.python.org/dev/peps/pep-0008/ : """ The following naming styles are commonly distinguished: [...] * CapitalizedWords (or CapWords, or CamelCase -- so named because of the bumpy look of its letters [3]). [?] * mixedCase (differs from CapitalizedWords by initial lowercase character!) """ The term "TitleCase" does not make an appearance in the document. Regards, Chris From newsboost at gmail.com Thu Jan 3 06:19:53 2013 From: newsboost at gmail.com (someone) Date: Thu, 03 Jan 2013 12:19:53 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/03/2013 03:55 AM, Ian Kelly wrote: > On Wed, Jan 2, 2013 at 7:24 PM, someone wrote: >> 3) self.rx / rself.ry / self.rz: Invalid name "rx" (should match >> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an >> underscore ? > > It wants the name to be at least 3 characters long. Uh, ok, thank you. I'll remember that. Doesn't this "[ ... ]" mean something optional? What does {2,30}$ mean? I think $ means that the {2,30} is something in the end of the sentence... From rosuav at gmail.com Thu Jan 3 06:27:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 22:27:50 +1100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 3, 2013 at 10:19 PM, someone wrote: > Doesn't this "[ ... ]" mean something optional? > > What does {2,30}$ mean? > > I think $ means that the {2,30} is something in the end of the sentence... You can find regular expression primers all over the internet, but to answer these specific questions: [...] means any of the characters in the range; the $ means "end of string"; and {2,30} means at least two, and at most thirty, of the preceding character. So you have to have one from the first group, then 2-30 from the second, for a total of 3-31 characters in your names. ChrisA From newsboost at gmail.com Fri Jan 4 20:11:26 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 02:11:26 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/03/2013 12:27 PM, Chris Angelico wrote: > On Thu, Jan 3, 2013 at 10:19 PM, someone wrote: >> Doesn't this "[ ... ]" mean something optional? >> >> What does {2,30}$ mean? >> >> I think $ means that the {2,30} is something in the end of the sentence... > > You can find regular expression primers all over the internet, but to > answer these specific questions: [...] means any of the characters in > the range; the $ means "end of string"; and {2,30} means at least two, > and at most thirty, of the preceding character. So you have to have > one from the first group, then 2-30 from the second, for a total of > 3-31 characters in your names. Got it, thanks! From janpeterr at freenet.de Sat Jan 5 07:49:11 2013 From: janpeterr at freenet.de (Jan Riechers) Date: Sat, 05 Jan 2013 14:49:11 +0200 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50E82147.9070307@freenet.de> On 05.01.2013 03:11, someone wrote: > On 01/03/2013 12:27 PM, Chris Angelico wrote: >> On Thu, Jan 3, 2013 at 10:19 PM, someone wrote: >>> Doesn't this "[ ... ]" mean something optional? >>> >>> What does {2,30}$ mean? >>> >>> I think $ means that the {2,30} is something in the end of the >>> sentence... >> >> You can find regular expression primers all over the internet, but to >> answer these specific questions: [...] means any of the characters in >> the range; the $ means "end of string"; and {2,30} means at least two, >> and at most thirty, of the preceding character. So you have to have >> one from the first group, then 2-30 from the second, for a total of >> 3-31 characters in your names. > > Got it, thanks! > > Just following the discussion which is very interesting, even so when not working with OpenGL (which looks like a nightmare with that naming space) :) But about the regular expressions (a bit deeper look into that): Like said of Chris: [a-z] defines a "catching group", in this case all ascii lowercase letters ranging from "a" to "z". If noting else is provided, the rule matches one letter if there is no range defined by something like: {} -> Target a range of a match/hit There are also a ? -> Lazy match * -> Gready match [A-Z][0-9]{1,3} means translated: Look for any uppercase letter in ascii(!) (not "???" or similiar) ranging from "A" to "Z". Now look for any digit (2nd catching group) with the addition to satisfy the rule ONLY if there are at least 1 to 3 digits found. Note: If there are 4 or more digits - the catching rule is still satisfied and will provide a match/hit. If there is a follow up group, the next evaluation is gone through if present and so forth. If the expression is satisfied, the match is returned. The lazy "?" and greedy "*" matches try to satisfy, as the naming implies, to match as less or as much of what you have asked for. For example the regular expression is valid: 0* -> Look for a zero, and be greedy as of how many zeros you want match which might follow. Regular expressions don't have to include catching groups in order to work. But when you use them yourself somehow, its quite simple I think. I guess you are anyhow busy mangling with pyLint, PEP-Standards and pyOpenGL - so good luck with that :) Jan Riechers From newsboost at gmail.com Sat Jan 5 08:09:41 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 14:09:41 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: <50e4c83b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/05/2013 01:49 PM, Jan Riechers wrote: > On 05.01.2013 03:11, someone wrote: > But about the regular expressions (a bit deeper look into that): > Like said of Chris: > > [a-z] > defines a "catching group", in this case all ascii lowercase letters > ranging from "a" to "z". If noting else is provided, the rule matches > one letter if there is no range defined by something like: > {} -> Target a range of a match/hit > > There are also a > ? -> Lazy match > * -> Gready match > > [A-Z][0-9]{1,3} means translated: > Look for any uppercase letter in ascii(!) (not "???" or similiar) > ranging from "A" to "Z". > > Now look for any digit (2nd catching group) with the addition to satisfy > the rule ONLY if there are at least 1 to 3 digits found. > Note: If there are 4 or more digits - the catching rule is still > satisfied and will provide a match/hit. Ok, thanks a lot for the elaboration... I think I need to work with it myself at some time to be sure of understanding it... > If there is a follow up group, the next evaluation is gone through if > present and so forth. If the expression is satisfied, the match is > returned. > > The lazy "?" and greedy "*" matches try to satisfy, as the naming > implies, to match as less or as much of what you have asked for. > > For example the regular expression is valid: > 0* -> Look for a zero, and be greedy as of how many zeros you want match > which might follow. > > Regular expressions don't have to include catching groups in order to work. > > But when you use them yourself somehow, its quite simple I think. > I guess you are anyhow busy mangling with pyLint, PEP-Standards and > pyOpenGL - so good luck with that :) You're right - I'm a bit "overbooked" at the moment - but thanks a lot for clarifyring this with the regexps :-) From newsboost at gmail.com Wed Jan 2 21:06:56 2013 From: newsboost at gmail.com (someone) Date: Thu, 03 Jan 2013 03:06:56 +0100 Subject: pylint, was Re: pygame - importing GL - very bad... In-Reply-To: References: Message-ID: On 01/02/2013 03:26 PM, Dave Angel wrote: > On 01/02/2013 09:09 AM, someone wrote: >> On 01/02/2013 01:07 PM, Peter Otten wrote: >> OMG... I don't want to type those underscores everywhere... Anyway, >> thank you very much for explaining the meaning of what it wants... >> >> >> > > Global const values should be ALL_CAPS, so it's obvious that nobody > intends to modify them. It's the non-const global attributes that > expect to be underscored. > > You shouldn't have to use those underscores very often. After all, > there is seldom a need for a non-const global value, right? Don't think I suppose you're right. > of it as a pylint problem, but as a hint from pylint that perhaps you > should use fewer globals. I had some bad code which I improved greatly now with thanks to pylint. I'll remember what you've written the next time I look at it - I think I don't use that many global non-const values now - I wrapped a lot of things into a class now. This is much better and I guess the correct "object-oriented" thing to do. I hope/think I'll get this warning a lot fewer times in the future. Thanks a lot for the explanation. From anilkumar.dannina at gmail.com Tue Jan 1 06:35:56 2013 From: anilkumar.dannina at gmail.com (anilkumar.dannina at gmail.com) Date: Tue, 1 Jan 2013 03:35:56 -0800 (PST) Subject: Handling Special characters in python Message-ID: I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. Waiting for your reply. Thanks, D Anil Kumar From steve+comp.lang.python at pearwood.info Tue Jan 1 07:01:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Jan 2013 12:01:51 GMT Subject: Handling Special characters in python References: Message-ID: <50e2d02f$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Jan 2013 03:35:56 -0800, anilkumar.dannina wrote: > I am facing one issue in my module. I am gathering data from sql server > database. In the data that I got from db contains special characters > like "endash". Python was taking it as "\x96". I require the same > character(endash). How can I perform that. Can you please help me in > resolving this issue. "endash" is not a character, it is six characters. On the other hand, "\x96" is a single byte: py> c = u"\x96" py> assert len(c) == 1 But it is not a legal Unicode character: py> import unicodedata py> unicodedata.name(c) Traceback (most recent call last): File "", line 1, in ValueError: no such name So if it is not a Unicode character, it is probably a byte. py> c = "\x96" py> print c ? To convert byte 0x96 to an n-dash character, you need to identify the encoding to use. (Aside: and *stop* using it. It is 2013 now, anyone who is not using UTF-8 is doing it wrong. Legacy encodings are still necessary for legacy data, but any new data should always using UTF-8.) CP 1252 is one possible encoding, but there may be others: py> uc = c.decode('cp1252') py> unicodedata.name(uc) 'EN DASH' -- Steven From chris at rebertia.com Tue Jan 1 13:30:06 2013 From: chris at rebertia.com (Chris Rebert) Date: Tue, 1 Jan 2013 10:30:06 -0800 Subject: Handling Special characters in python In-Reply-To: References: Message-ID: On Jan 1, 2013 3:41 AM, wrote: > > I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. 1. What library are you using to access the database? 2. To confirm, it's a Microsoft SQL Server database? 3. What OS are you on? -------------- next part -------------- An HTML attachment was scrubbed... URL: From anilkumar.dannina at gmail.com Tue Jan 1 23:46:56 2013 From: anilkumar.dannina at gmail.com (anilkumar.dannina at gmail.com) Date: Tue, 1 Jan 2013 20:46:56 -0800 (PST) Subject: Handling Special characters in python In-Reply-To: References: Message-ID: <90663ba3-2307-45ed-a1b7-c3dbe5130ebd@googlegroups.com> On Wednesday, January 2, 2013 12:00:06 AM UTC+5:30, Chris Rebert wrote: > On Jan 1, 2013 3:41 AM, wrote: > > > > > > I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. > > > 1. What library are you using to access the database? > > 2. To confirm, it's a Microsoft SQL Server database? > > 3. What OS are you on? 1. I am using "pymssql" module to access the database. 2. Yes, It is a SQL server database. 3. I am on Ubuntu 11.10 From anilkumar.dannina at gmail.com Tue Jan 1 23:46:56 2013 From: anilkumar.dannina at gmail.com (anilkumar.dannina at gmail.com) Date: Tue, 1 Jan 2013 20:46:56 -0800 (PST) Subject: Handling Special characters in python In-Reply-To: References: Message-ID: <90663ba3-2307-45ed-a1b7-c3dbe5130ebd@googlegroups.com> On Wednesday, January 2, 2013 12:00:06 AM UTC+5:30, Chris Rebert wrote: > On Jan 1, 2013 3:41 AM, wrote: > > > > > > I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. > > > 1. What library are you using to access the database? > > 2. To confirm, it's a Microsoft SQL Server database? > > 3. What OS are you on? 1. I am using "pymssql" module to access the database. 2. Yes, It is a SQL server database. 3. I am on Ubuntu 11.10 From clp2 at rebertia.com Wed Jan 2 01:32:34 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 1 Jan 2013 22:32:34 -0800 Subject: Handling Special characters in python In-Reply-To: <90663ba3-2307-45ed-a1b7-c3dbe5130ebd@googlegroups.com> References: <90663ba3-2307-45ed-a1b7-c3dbe5130ebd@googlegroups.com> Message-ID: On Jan 1, 2013 8:48 PM, wrote: > On Wednesday, January 2, 2013 12:00:06 AM UTC+5:30, Chris Rebert wrote: > > On Jan 1, 2013 3:41 AM, wrote: > > > > > I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. > > > > 1. What library are you using to access the database? > > 2. To confirm, it's a Microsoft SQL Server database? > > 3. What OS are you on? > > 1. I am using "pymssql" module to access the database. > 2. Yes, It is a SQL server database. > 3. I am on Ubuntu 11.10 Did you set "client charset" (to "UTF-8", unless you have good reason to choose otherwise) in freetds.conf? That should at least ensure that the driver itself is exchanging bytestrings via a well-defined encoding. If you want to work in Unicode natively (Recommended), you'll probably need to ensure that the columns are of type NVARCHAR as opposed to VARCHAR. Unless you're using SQLAlchemy or similar (which I personally would recommend using), you may need to do the .encode() and .decode()-ing manually, using the charset you specified in freetds.conf. Sorry my advice is a tad general. I went the alternative route of SQLAlchemy + PyODBC + Microsoft's SQL Server ODBC driver for Linux ( http://www.microsoft.com/en-us/download/details.aspx?id=28160 ) for my current project, which likewise needs to fetch data from MS SQL to an Ubuntu box. The driver is intended for Red Hat and isn't packaged nicely (it installs via a shell script), but after that was dealt with, things have gone smoothly. Unicode, in particular, seems to work properly. -------------- next part -------------- An HTML attachment was scrubbed... URL: From anilkumar.dannina at gmail.com Wed Jan 2 08:39:48 2013 From: anilkumar.dannina at gmail.com (anilkumar.dannina at gmail.com) Date: Wed, 2 Jan 2013 05:39:48 -0800 (PST) Subject: Handling Special characters in python In-Reply-To: References: <90663ba3-2307-45ed-a1b7-c3dbe5130ebd@googlegroups.com> Message-ID: <310c83c4-cfa2-4425-b291-d1a3604b3e29@googlegroups.com> On Wednesday, January 2, 2013 12:02:34 PM UTC+5:30, Chris Rebert wrote: > On Jan 1, 2013 8:48 PM, wrote: > > > On Wednesday, January 2, 2013 12:00:06 AM UTC+5:30, Chris Rebert wrote: > > > > On Jan 1, 2013 3:41 AM, wrote: > > > > > > > > > I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. > > > > > > > > > 1. What library are you using to access the database? > > > > 2. To confirm, it's a Microsoft SQL Server database? > > > > 3. What OS are you on? > > > > > > 1. I am using "pymssql" module to access the database. > > > 2. Yes, It is a SQL server database. > > > 3. I am on Ubuntu 11.10 > > Did you set "client charset" (to "UTF-8", unless you have good reason to choose otherwise) in freetds.conf? That should at least ensure that the driver itself is exchanging bytestrings via a well-defined encoding. > > > If you want to work in Unicode natively (Recommended), you'll probably need to ensure that the columns are of type NVARCHAR as opposed to VARCHAR. Unless you're using SQLAlchemy or similar (which I personally would recommend using), you may need to do the .encode() and .decode()-ing manually, using the charset you specified in freetds.conf. > > > Sorry my advice is a tad general. I went the alternative route of SQLAlchemy + PyODBC + Microsoft's SQL Server ODBC driver for Linux (http://www.microsoft.com/en-us/download/details.aspx?id=28160 ) for my current project, which likewise needs to fetch data from MS SQL to an Ubuntu box. The driver is intended for Red Hat and isn't packaged nicely (it installs via a shell script), but after that was dealt with, things have gone smoothly. Unicode, in particular, seems to work properly. Thanks Chris Rebert for your suggestion, I tried with PyODBC module, But at the place of "en dash(-)", I am getting '?' symbol. How can I overcome this. From anilkumar.dannina at gmail.com Wed Jan 2 08:39:48 2013 From: anilkumar.dannina at gmail.com (anilkumar.dannina at gmail.com) Date: Wed, 2 Jan 2013 05:39:48 -0800 (PST) Subject: Handling Special characters in python In-Reply-To: References: <90663ba3-2307-45ed-a1b7-c3dbe5130ebd@googlegroups.com> Message-ID: <310c83c4-cfa2-4425-b291-d1a3604b3e29@googlegroups.com> On Wednesday, January 2, 2013 12:02:34 PM UTC+5:30, Chris Rebert wrote: > On Jan 1, 2013 8:48 PM, wrote: > > > On Wednesday, January 2, 2013 12:00:06 AM UTC+5:30, Chris Rebert wrote: > > > > On Jan 1, 2013 3:41 AM, wrote: > > > > > > > > > I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. > > > > > > > > > 1. What library are you using to access the database? > > > > 2. To confirm, it's a Microsoft SQL Server database? > > > > 3. What OS are you on? > > > > > > 1. I am using "pymssql" module to access the database. > > > 2. Yes, It is a SQL server database. > > > 3. I am on Ubuntu 11.10 > > Did you set "client charset" (to "UTF-8", unless you have good reason to choose otherwise) in freetds.conf? That should at least ensure that the driver itself is exchanging bytestrings via a well-defined encoding. > > > If you want to work in Unicode natively (Recommended), you'll probably need to ensure that the columns are of type NVARCHAR as opposed to VARCHAR. Unless you're using SQLAlchemy or similar (which I personally would recommend using), you may need to do the .encode() and .decode()-ing manually, using the charset you specified in freetds.conf. > > > Sorry my advice is a tad general. I went the alternative route of SQLAlchemy + PyODBC + Microsoft's SQL Server ODBC driver for Linux (http://www.microsoft.com/en-us/download/details.aspx?id=28160 ) for my current project, which likewise needs to fetch data from MS SQL to an Ubuntu box. The driver is intended for Red Hat and isn't packaged nicely (it installs via a shell script), but after that was dealt with, things have gone smoothly. Unicode, in particular, seems to work properly. Thanks Chris Rebert for your suggestion, I tried with PyODBC module, But at the place of "en dash(-)", I am getting '?' symbol. How can I overcome this. From clp2 at rebertia.com Thu Jan 3 01:00:16 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 Jan 2013 22:00:16 -0800 Subject: Handling Special characters in python In-Reply-To: <310c83c4-cfa2-4425-b291-d1a3604b3e29@googlegroups.com> References: <90663ba3-2307-45ed-a1b7-c3dbe5130ebd@googlegroups.com> <310c83c4-cfa2-4425-b291-d1a3604b3e29@googlegroups.com> Message-ID: On Wed, Jan 2, 2013 at 5:39 AM, wrote: > On Wednesday, January 2, 2013 12:02:34 PM UTC+5:30, Chris Rebert wrote: >> On Jan 1, 2013 8:48 PM, wrote: >> > On Wednesday, January 2, 2013 12:00:06 AM UTC+5:30, Chris Rebert wrote: >> > > On Jan 1, 2013 3:41 AM, wrote: >> > > > I am facing one issue in my module. I am gathering data from sql server database. In the data that I got from db contains special characters like "endash". Python was taking it as "\x96". I require the same character(endash). How can I perform that. Can you please help me in resolving this issue. >> >> > > 1. What library are you using to access the database? >> > > 2. To confirm, it's a Microsoft SQL Server database? >> > > 3. What OS are you on? >> >> > 1. I am using "pymssql" module to access the database. >> > 2. Yes, It is a SQL server database. >> > 3. I am on Ubuntu 11.10 >> >> Did you set "client charset" (to "UTF-8", unless you have good reason to choose otherwise) in freetds.conf? That should at least ensure that the driver itself is exchanging bytestrings via a well-defined encoding. >> If you want to work in Unicode natively (Recommended), you'll probably need to ensure that the columns are of type NVARCHAR as opposed to VARCHAR. Unless you're using SQLAlchemy or similar (which I personally would recommend using), you may need to do the .encode() and .decode()-ing manually, using the charset you specified in freetds.conf. >> >> Sorry my advice is a tad general. I went the alternative route of SQLAlchemy + PyODBC + Microsoft's SQL Server ODBC driver for Linux (http://www.microsoft.com/en-us/download/details.aspx?id=28160 ) for my current project, which likewise needs to fetch data from MS SQL to an Ubuntu box. The driver is intended for Red Hat and isn't packaged nicely (it installs via a shell script), but after that was dealt with, things have gone smoothly. Unicode, in particular, seems to work properly. > > Thanks Chris Rebert for your suggestion, I tried with PyODBC module, But at the place of "en dash(-)", I am getting '?' symbol. How can I overcome this. I would recommend first trying the advice in the initial part of my response rather than the latter part. The latter part was more for completeness and for the sake of the archives, although I can give more details on its approach if you insist. Additionally, giving more information as to what exactly you tried would be helpful. What config / connection settings did you use? Of what datatype is the relevant column of the table? What's your code snippet look like? Etc.. Regards, Chris From animus.partum.universum at gmail.com Tue Jan 1 09:33:27 2013 From: animus.partum.universum at gmail.com (Omer Korat) Date: Tue, 1 Jan 2013 06:33:27 -0800 (PST) Subject: pickle module doens't work In-Reply-To: <4e0td81rm0gru7g5a3rmm6grr5aa2r101m@4ax.com> References: <4e0td81rm0gru7g5a3rmm6grr5aa2r101m@4ax.com> Message-ID: <959b2a1c-ef26-4b6b-b855-fdf29cafc681@googlegroups.com> I am using the nltk.classify.MaxEntClassifier. This object has a set of labels, and a set of probabilities: P(label | features). It modifies this probability given data. SO for example, if you tell this object that the label L appears 60% of the time with the feature F, then P(L | F) = 0.6. The point is, there is no way to access the probabilities directly. The object's 'classify' method uses these probabilities, but you can't call them as an object property. In order to adjust probabilities, you have to call the object's 'train' method, and feed classified data in. So is there any way to save a MaxEntClassifier object, with its classification probabilities, without having to call the 'train' method? From timr at probo.com Tue Jan 1 14:14:28 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 01 Jan 2013 11:14:28 -0800 Subject: pickle module doens't work References: <4e0td81rm0gru7g5a3rmm6grr5aa2r101m@4ax.com> <959b2a1c-ef26-4b6b-b855-fdf29cafc681@googlegroups.com> Message-ID: Omer Korat wrote: > >I am using the nltk.classify.MaxEntClassifier. This object has a set of >labels, and a set of probabilities: P(label | features). It modifies >this probability given data. SO for example, if you tell this object >that the label L appears 60% of the time with the feature F, then >P(L | F) = 0.6. > >The point is, there is no way to access the probabilities directly. >The object's 'classify' method uses these probabilities, but you can't >call them as an object property. Well, you have the source code, so you can certainly go look at the implementation and see what the data is based on. >In order to adjust probabilities, you have to call the object's 'train' >method, and feed classified data in. The "train" method is not actually an object method, it's a class method. It doesn't use any existing probabilities -- it returns a NEW MaxEntClassifier based entirely on the training set. >So is there any way to save a MaxEntClassifier object, with its >classification probabilities, without having to call the 'train' method? If you haven't called the "train" method, there IS no MaxEntClassifier object. Once you have called "train", you should be able to pickle the new MaxEntClassifier and fetch it back with its state intact. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From animus.partum.universum at gmail.com Wed Jan 2 09:08:37 2013 From: animus.partum.universum at gmail.com (Omer Korat) Date: Wed, 2 Jan 2013 06:08:37 -0800 (PST) Subject: pickle module doens't work In-Reply-To: References: <4e0td81rm0gru7g5a3rmm6grr5aa2r101m@4ax.com> <959b2a1c-ef26-4b6b-b855-fdf29cafc681@googlegroups.com> Message-ID: <3cc49c16-d901-4c27-9ba8-afbd2630b700@googlegroups.com> Yeah, right. I didn't think about that. I'll check in the source how the data is stored. Thanks for helping sort it all out. From usamazohad at gmail.com Tue Jan 1 10:40:35 2013 From: usamazohad at gmail.com (usamazohad at gmail.com) Date: Tue, 1 Jan 2013 07:40:35 -0800 (PST) Subject: got stuck in equation Message-ID: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> hi . . my name is usama khan i am the student of civil engeering and we got assignment to make a project program on flexible pavement design using python. i know very litle about programing. still learning from tutorials. u can call me a beginner. now i need to solve this equation so that i can put this in python but the formula of design is very complex Formula is : log(W18) = (Z)(S)+9.36log(SN+1) -2.0+(log(dpsi/(4.5-1.5))(/(.40+1094/(SN+1)^2.5)+2.32log(Mr-)-8.07 every thing is constant except this SN. . i want to seperate SN like SN= rest of the stuff. how can i seprate it because manualy its impossible to take SN out. so plz help me out From rosuav at gmail.com Tue Jan 1 11:03:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Jan 2013 03:03:19 +1100 Subject: got stuck in equation In-Reply-To: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: On Wed, Jan 2, 2013 at 2:40 AM, wrote: > hi . . my name is usama khan > i am the student of civil engeering and we got assignment to make a project program on flexible pavement design using python. > > i know very litle about programing. still learning from tutorials. u can call me a beginner. > now i need to solve this equation so that i can put this in python but the formula of design is very complex > > Formula is : > > log(W18) = (Z)(S)+9.36log(SN+1) -2.0+(log(dpsi/(4.5-1.5))(/(.40+1094/(SN+1)^2.5)+2.32log(Mr-)-8.07 > > every thing is constant except this SN. . i want to seperate SN like SN= rest of the stuff. how can i seprate it because manualy its impossible to take SN out. > so plz help me out This isn't a Python question, it's an algebra one. I don't know what Z, S, and so on are, but for the most part, the basic rule of solving equations applies: Do the same thing to both sides and it's still true. Work on it until you can isolate SN on one side. I don't know what this bit means, though: 2.32log(Mr-) Is this a transcription error? You can't subtract nullness from something. ChrisA From d at davea.name Tue Jan 1 11:42:28 2013 From: d at davea.name (Dave Angel) Date: Tue, 01 Jan 2013 11:42:28 -0500 Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: <50E311F4.2080501@davea.name> On 01/01/2013 11:03 AM, Chris Angelico wrote: > On Wed, Jan 2, 2013 at 2:40 AM, wrote: >> hi . . my name is usama khan >> i am the student of civil engeering and we got assignment to make a project program on flexible pavement design using python. >> >> i know very litle about programing. still learning from tutorials. u can call me a beginner. >> now i need to solve this equation so that i can put this in python but the formula of design is very complex >> >> Formula is : >> >> log(W18) = (Z)(S)+9.36log(SN+1) -2.0+(log(dpsi/(4.5-1.5))(/(.40+1094/(SN+1)^2.5)+2.32log(Mr-)-8.07 >> >> every thing is constant except this SN. . i want to seperate SN like SN= rest of the stuff. how can i seprate it because manualy its impossible to take SN out. >> so plz help me out > This isn't a Python question, it's an algebra one. I don't know what > Z, S, and so on are, but for the most part, the basic rule of solving > equations applies: Do the same thing to both sides and it's still > true. Work on it until you can isolate SN on one side. Such a rule may not be able to solve an equation when there SN appears more than once on the RHS, and where it's inside a transcental function. I don't consider this an algebra problem, but a programming problem. > I don't know what this bit means, though: > > 2.32log(Mr-) > > Is this a transcription error? You can't subtract nullness from something. > > ChrisA Mr- was apparently intended to mean "M sub r", the subgrade resilient modulus (in psi). Just a number. The only thing i know about any of this is from here: http://classes.engr.oregonstate.edu/cce/winter2012/ce492/Modules/06_structural_design/06-3_body.htm -- DaveA From rosuav at gmail.com Tue Jan 1 12:44:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Jan 2013 04:44:46 +1100 Subject: got stuck in equation In-Reply-To: <50E311F4.2080501@davea.name> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <50E311F4.2080501@davea.name> Message-ID: On Wed, Jan 2, 2013 at 3:42 AM, Dave Angel wrote: > On 01/01/2013 11:03 AM, Chris Angelico wrote: >> This isn't a Python question, it's an algebra one. I don't know what >> Z, S, and so on are, but for the most part, the basic rule of solving >> equations applies: Do the same thing to both sides and it's still >> true. Work on it until you can isolate SN on one side. > > Such a rule may not be able to solve an equation when there SN appears > more than once on the RHS, and where it's inside a transcental > function. I don't consider this an algebra problem, but a programming > problem. It's a tad more complicated than your average equation, and I haven't the time now to prove the point by actually solving it, but every operation that I can see in that formula can be reversed. The hairy bit is that there are two references to SN, so it's going to be a bit messy to untangle, and might end up as a higher-order equation. But you're likely right that other forms of solver may be more useful here. Algebra definitely _could_ be the solution, but it isn't necessarily the best. ChrisA From usamazohad at gmail.com Tue Jan 1 13:00:17 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 10:00:17 -0800 (PST) Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <50E311F4.2080501@davea.name> Message-ID: <74ed5f20-43ea-4962-849e-2f36e7fa4f9c@googlegroups.com> u r right bro. . am serving my time. .realy i dont need a short cut code. . nor its a programing class. . i have chosen tis project on my own so that we can aviod that graph procedure. . i guess the program i am making on python has many many things. .not just the iteration. .i am not that cheap really to cheat my DS(director of studies). .i swear. . as i told i am half civil engieer. .in 5 th semester presently. . am ready to learn. . .still learning from tutorialz of "tekboi" and "investros" and that book name "python programing for absolute begginers" kindly understand me. .i can give u my time. .u got me wrong. i just ask for the coding of solving this formula as its not in the book as well as tutorialz. :( thanks for the concern. . regards From usamazohad at gmail.com Tue Jan 1 13:00:17 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 10:00:17 -0800 (PST) Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <50E311F4.2080501@davea.name> Message-ID: <74ed5f20-43ea-4962-849e-2f36e7fa4f9c@googlegroups.com> u r right bro. . am serving my time. .realy i dont need a short cut code. . nor its a programing class. . i have chosen tis project on my own so that we can aviod that graph procedure. . i guess the program i am making on python has many many things. .not just the iteration. .i am not that cheap really to cheat my DS(director of studies). .i swear. . as i told i am half civil engieer. .in 5 th semester presently. . am ready to learn. . .still learning from tutorialz of "tekboi" and "investros" and that book name "python programing for absolute begginers" kindly understand me. .i can give u my time. .u got me wrong. i just ask for the coding of solving this formula as its not in the book as well as tutorialz. :( thanks for the concern. . regards From usamazohad at gmail.com Tue Jan 1 13:12:30 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 10:12:30 -0800 (PST) Subject: got stuck in equation In-Reply-To: <74ed5f20-43ea-4962-849e-2f36e7fa4f9c@googlegroups.com> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <50E311F4.2080501@davea.name> <74ed5f20-43ea-4962-849e-2f36e7fa4f9c@googlegroups.com> Message-ID: how shud i intiate this equation myself. .can u give me some links to solve that myself. . am ready already. .its a chalange for me now. . .i just requested for a code as i dont know nothing about iteration of that much complex equation not the entire program. . so kindly show me the way. .i will do it myself. .nd remember plz am nt that cheap to cheat. .cheater doesnot worry about grades. .just remember this. .he just wants to clear the subject. . i have cleared the subject with excellent marks. .just spoiling my end semester vacation to get good grade and expereince in programing. . . its totaly optional to go for project, internship or vacationz. .nd i have chosen up the project. . .i hope i have clearified your doubt regarding my amnitions and concerns. . ?? so kindly show me the way. .i will go myself on that way. .because i dont know what way should go for this beautiful complex equatuion. .:) From usamazohad at gmail.com Tue Jan 1 13:12:30 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 10:12:30 -0800 (PST) Subject: got stuck in equation In-Reply-To: <74ed5f20-43ea-4962-849e-2f36e7fa4f9c@googlegroups.com> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <50E311F4.2080501@davea.name> <74ed5f20-43ea-4962-849e-2f36e7fa4f9c@googlegroups.com> Message-ID: how shud i intiate this equation myself. .can u give me some links to solve that myself. . am ready already. .its a chalange for me now. . .i just requested for a code as i dont know nothing about iteration of that much complex equation not the entire program. . so kindly show me the way. .i will do it myself. .nd remember plz am nt that cheap to cheat. .cheater doesnot worry about grades. .just remember this. .he just wants to clear the subject. . i have cleared the subject with excellent marks. .just spoiling my end semester vacation to get good grade and expereince in programing. . . its totaly optional to go for project, internship or vacationz. .nd i have chosen up the project. . .i hope i have clearified your doubt regarding my amnitions and concerns. . ?? so kindly show me the way. .i will go myself on that way. .because i dont know what way should go for this beautiful complex equatuion. .:) From usamazohad at gmail.com Tue Jan 1 12:25:21 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 09:25:21 -0800 (PST) Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> am just a begginer bro. . jus learnt if elif while nd for loop. . can u just display me the coding u want. .it could save my time that i have while searchning SN out. . i will give u that dependable variables values. . nd SN range 4 inches to 13.5 inches log(w18)=50x10^6 Z=-1.645 S=0.45 dpsi=2.5 Mr=5800 now can u give me the coding of this equation as i need to save my time. . .i am learning from tutorials. . so its taking lot of time. kindly consider my request nd give me the code so that i can put it. .i dont want to losen up my grade. .am trying hard. . . Regards From usamazohad at gmail.com Tue Jan 1 12:25:21 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 09:25:21 -0800 (PST) Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> am just a begginer bro. . jus learnt if elif while nd for loop. . can u just display me the coding u want. .it could save my time that i have while searchning SN out. . i will give u that dependable variables values. . nd SN range 4 inches to 13.5 inches log(w18)=50x10^6 Z=-1.645 S=0.45 dpsi=2.5 Mr=5800 now can u give me the coding of this equation as i need to save my time. . .i am learning from tutorials. . so its taking lot of time. kindly consider my request nd give me the code so that i can put it. .i dont want to losen up my grade. .am trying hard. . . Regards From rosuav at gmail.com Tue Jan 1 12:51:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Jan 2013 04:51:27 +1100 Subject: got stuck in equation In-Reply-To: <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> Message-ID: On Wed, Jan 2, 2013 at 4:25 AM, Usama Khan wrote: > now can u give me the coding of this equation as i need to save my time. . .i am learning from tutorials. . so its taking lot of time. kindly consider my request nd give me the code so that i can put it. .i dont want to losen up my grade. .am trying hard. . . You don't want to lose your grade, so you ask someone else to do your work for you. You haven't said what sort of class this is, but I see two likely possibilities: 1) It's a programming class. Either you ought to be able to solve this in the class (in which case, look to your source material as it's almost certainly there - this is way more complicated maths than your average programming class wants as an ancillary), or you shouldn't be doing this part at all, and you can achieve the program's goal without actually running the maths. 2) It's a course on something else (engineering?), to which this formula is central. Then you ought to understand the mathematics of it, regardless of the code. Either way, posting urgent messages to python-list asking for someone to *give you the code* is NOT the way to do things. We'll help you to learn; we won't help you to get grades you haven't merited. There are plenty of Q'n'A web sites out there with low standards and no scruples, but please just make sure you never build a bridge that I'll be travelling over. Read this, it'll help explain what people think of these sorts of questions: http://www.catb.org/esr/faqs/smart-questions.html#homework ChrisA From maniandram01 at gmail.com Wed Jan 2 00:20:16 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 1 Jan 2013 21:20:16 -0800 (PST) Subject: got stuck in equation In-Reply-To: <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> Message-ID: On Tuesday, 1 January 2013 22:55:21 UTC+5:30, Usama Khan wrote: > am just a begginer bro. . jus learnt if elif while nd for loop. . > > > > can u just display me the coding u want. .it could save my time that i have while searchning SN out. . i will give u that dependable variables values. . > > > > nd SN range 4 inches to 13.5 inches > > > > log(w18)=50x10^6 > > Z=-1.645 > > S=0.45 > > dpsi=2.5 > > Mr=5800 > > > > now can u give me the coding of this equation as i need to save my time. . .i am learning from tutorials. . so its taking lot of time. kindly consider my request nd give me the code so that i can put it. .i dont want to losen up my grade. .am trying hard. . . > > > > Regards If you spend half a minute extra to write your sentences properly and not use SMS abbreviations, then it would save totally many minutes of other people's time. From maniandram01 at gmail.com Wed Jan 2 00:20:16 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 1 Jan 2013 21:20:16 -0800 (PST) Subject: got stuck in equation In-Reply-To: <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> Message-ID: On Tuesday, 1 January 2013 22:55:21 UTC+5:30, Usama Khan wrote: > am just a begginer bro. . jus learnt if elif while nd for loop. . > > > > can u just display me the coding u want. .it could save my time that i have while searchning SN out. . i will give u that dependable variables values. . > > > > nd SN range 4 inches to 13.5 inches > > > > log(w18)=50x10^6 > > Z=-1.645 > > S=0.45 > > dpsi=2.5 > > Mr=5800 > > > > now can u give me the coding of this equation as i need to save my time. . .i am learning from tutorials. . so its taking lot of time. kindly consider my request nd give me the code so that i can put it. .i dont want to losen up my grade. .am trying hard. . . > > > > Regards If you spend half a minute extra to write your sentences properly and not use SMS abbreviations, then it would save totally many minutes of other people's time. From wuwei23 at gmail.com Wed Jan 2 04:53:59 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Jan 2013 01:53:59 -0800 (PST) Subject: got stuck in equation References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> Message-ID: <72e3a4af-c25c-4ee6-9e7a-976e066bc84a@vb8g2000pbb.googlegroups.com> On Jan 2, 3:20?pm, Ramchandra Apte wrote: > If you spend half a minute extra to write your sentences properly > and not use SMS abbreviations, then it would save totally many > minutes of other people's time. But that is not the way of the brogrammer... :) From djc at news.invalid Wed Jan 2 09:44:55 2013 From: djc at news.invalid (DJC) Date: Wed, 02 Jan 2013 14:44:55 +0000 Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> <02785889-0bd1-4b93-8f75-bde14d6932d6@googlegroups.com> Message-ID: On 02/01/13 05:20, Ramchandra Apte wrote: > On Tuesday, 1 January 2013 22:55:21 UTC+5:30, Usama Khan wrote: >> am just a begginer bro. . jus learnt if elif while nd for loop. . >> can u just display me the coding u want. .it could save my time that i have while searchning SN out. . i will give u that dependable variables values. . >> now can u give me the coding of this equation as i need to save my time. .. .i am learning from tutorials. . so its taking lot of time. kindly consider my request nd give me the code so that i can put it. .i dont want to losen up my grade. .am trying hard. . . > If you spend half a minute extra to write your sentences properly and not use SMS abbreviations, then it would save totally many minutes of other people's time. +1 not to mention that a polite, respectful, and well written request might incline more people to offer help. From usamazohad at gmail.com Tue Jan 1 12:30:28 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 09:30:28 -0800 (PST) Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: Sn range is given in here. . www.dot.state.fl.us/rddesign/DS/08/IDx/514.pdf From usamazohad at gmail.com Tue Jan 1 12:30:28 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 09:30:28 -0800 (PST) Subject: got stuck in equation In-Reply-To: References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: Sn range is given in here. . www.dot.state.fl.us/rddesign/DS/08/IDx/514.pdf From roy at panix.com Tue Jan 1 12:47:49 2013 From: roy at panix.com (Roy Smith) Date: Tue, 01 Jan 2013 12:47:49 -0500 Subject: got stuck in equation References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: In article , Usama Khan wrote: > am just a begginer bro. That's fine, we were all beginners once. You will discover that people here are willing to invest a lot of time and effort helping beginners get started. > now can u give me the coding of this equation as i need to save my time. . .i > am learning from tutorials. . so its taking lot of time. kindly consider my > request nd give me the code so that i can put it. .i dont want to losen up my > grade. .am trying hard. . . You will also discover that people are not willing to invest any effort to help if you are not also willing to invest your own effort. Nobody is going to just give you some code for your homework assignment so you don't have to put any time into it. From d at davea.name Tue Jan 1 11:39:09 2013 From: d at davea.name (Dave Angel) Date: Tue, 01 Jan 2013 11:39:09 -0500 Subject: got stuck in equation In-Reply-To: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: <50E3112D.3050802@davea.name> On 01/01/2013 10:40 AM, usamazohad at gmail.com wrote: > hi . . my name is usama khan > i am the student of civil engeering and we got assignment to make a project program on flexible pavement design using python. > > i know very litle about programing. still learning from tutorials. u can call me a beginner. > now i need to solve this equation so that i can put this in python but the formula of design is very complex > > Formula is : > > log(W18) = (Z)(S)+9.36log(SN+1) -2.0+(log(dpsi/(4.5-1.5))(/(.40+1094/(SN+1)^2.5)+2.32log(Mr-)-8.07 > > every thing is constant except this SN. . i want to seperate SN like SN= rest of the stuff. how can i seprate it because manualy its impossible to take SN out. > so plz help me out Tk Solver is (or was) a program for getting numerical results from equations where you couldn't (or didn't want to) express the equation with the independent variable isolated on its own side of the equals sign. I don't know where it's available for purchase or download now; I do see references to it on the web, plus books still available about it. Apparently it's up to version 5. Anyway, since everything else is a constant, use some program like Tk Solver to get the value for SN, then the Python program becomes simply: SN = 4.7732 or whatever. On the other hand, perhaps you didn't mean the other values were constant, but rather known. For example, perhaps your program is supposed to ask the user for values to W18, to dpsi, etc., then it is to calculate one or more values for SN that make the equation work. SN might be "structural number" as indicated on this web page: http://classes.engr.oregonstate.edu/cce/winter2012/ce492/Modules/06_structural_design/06-3_body.htm The big equation on that page looks kinda like the one you present, though I didn't study every term. 1) Is there a finite range of values that SN might fall into? I know nothing about pavement design, other than what I just read there, but there might well be a specific range that's reasonable to expect. 2) Take the present equation, and subtract log(w18) from both sides. Now, you want a value for SN that produces zero, or something close for the left hand side. Call that side "error". Is the value "error" relatively predictable for changes in SN ? For example, in the simplest case, any increase in SN will result in an increase of error. The worst case would be where any tiny change in SN might result in enormous changes in a random direction to error. 3) Figure an acceptable value for error, so you'll know when you're close enough. 4) if the first three questions have good answers, then you could write a function that transforms FN into error. Then write a controlling loop that calls that function repeatedly, picking values for FN that will converge the error into ever-smaller value. The first iteration might go over the entire range, dividing it into maybe ten steps. Then pick the two smallest values for error, and treat those particular two FN values as your new range. Repeat until the error value is below the threshold figured in #3, or until you've iterated an unreasonable number of times. There are ways to improve on that, but they generally require you know the approximate behavior of the function. For example, Newton's method is a method of calculating square roots, starting with end points of 1 and N, and it converges more rapidly because it effectively calculates the slope of the curve over each range. -- DaveA From timr at probo.com Tue Jan 1 16:09:01 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 01 Jan 2013 13:09:01 -0800 Subject: got stuck in equation References: <2043e377-00d8-49d7-a35a-0c52c869f70f@googlegroups.com> Message-ID: usamazohad at gmail.com wrote: > >i know very litle about programing. still learning from tutorials. u can call >me a beginner. >now i need to solve this equation so that i can put this in python but the >formula of design is very complex > >Formula is : > >log(W18) = (Z)(S)+9.36log(SN+1) -2.0+(log(dpsi/(4.5-1.5))(/(.40+1094/(SN+1)^2.5)+2.32log(Mr-)-8.07 > >every thing is constant except this SN. . i want to seperate SN like SN= >rest of the stuff. how can i seprate it because manualy its impossible to >take SN out. Right. Algebraically, it isn't practical to solve this for SN. That probably means you're going to need a iterative solution. That is, you start with a guess, see how far off you are, and refine the guess until you narrow in on a solution. That means you'll have to figure out whether raising SN gets you closer or farther away from a solution. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From usamazohad at gmail.com Tue Jan 1 13:55:51 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 10:55:51 -0800 (PST) Subject: got stuck in equation Message-ID: <86062f4b-36c0-48d1-b97c-45d0cfa40f4e@googlegroups.com> kindly let me know how to solve complex equation in pyhton. . ?? nd then use that equation in program. . ?? am desperate to learn but i guess the posters are a bit angry with me that i asked the code for solving that equation. .plzz help me out,. . am here to learn. . !!!!!!! just dont knwo the way to solve complex eqauation. .can some answer me. . ? From usamazohad at gmail.com Tue Jan 1 14:02:13 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 11:02:13 -0800 (PST) Subject: how to solve complex equation? Message-ID: how to solve complex equation in pyhton? and then use it to make a program. . i have created new post as my last post is i guessed ranked as a cheater. .:( i know very litle about python as well as programing. . which equation am taliking u will be thinking. . i am giving u the link kindly c that equation. . n kindly let me know the way. . https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.python/cxG7DLxXgmo From jt at toerring.de Tue Jan 1 16:49:55 2013 From: jt at toerring.de (Jens Thoms Toerring) Date: 1 Jan 2013 21:49:55 GMT Subject: how to solve complex equation? References: Message-ID: Usama Khan wrote: > how to solve complex equation in pyhton? and then use it to make a program. > . i have created new post as my last post is i guessed ranked as a cheater. > .:( > i know very litle about python as well as programing. . > which equation am taliking u will be thinking. . i am giving u the link > kindly c that equation. . n kindly let me know the way. . > https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.python/cxG7DLxXgmo First of all, the equation given there is unusable (even the number of parentheses doesn't match up). Propbably it's meant to be the one someone else posted a link to: http://classes.engr.oregonstate.edu/cce/winter2012/ce492/Modules/06_structural_design/06-3_body.htm This thingy can't be solved on paper so you need some iterative algorithm to find the solution. So waht you do is modify the equa- tion so that you have 0 on one side and then consider the other side to be a function of SN+1. Now the problem you're left with is to find the value(s) of SN+1 (and thus of SN) where the func- tion has a zero-crossing. A commonly use algorithms for finding zero-crossings is Newton's method. You can find lots of sites on the internet describing it in all neccessary detail. It boils down to start with some guess for the result and then calculate the next, better approximation via xn+1 = xn - f(xn) / f'(xn) where f(xn)n) is the value of the function at point xn and f'(xn) the value of the derivative of f (with respect to x) also at xn. You repeat the process until the difference be- tween xn an the next, better approximation, xn+1, has become as small as you need it. So it's very simple to implement and the ugliest bit is pro- bably calculating the required derivative of the function with respect to SN+1 (wbich you can take to be x). Regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From newsboost at gmail.com Tue Jan 1 22:55:33 2013 From: newsboost at gmail.com (someone) Date: Wed, 02 Jan 2013 04:55:33 +0100 Subject: how to solve complex equation? In-Reply-To: References: Message-ID: On 01/01/2013 10:49 PM, Jens Thoms Toerring wrote: > Usama Khan wrote: >> how to solve complex equation in pyhton? and then use it to make a program. >> . i have created new post as my last post is i guessed ranked as a cheater. >> .:( > >> i know very litle about python as well as programing. . > >> which equation am taliking u will be thinking. . i am giving u the link >> kindly c that equation. . n kindly let me know the way. . > >> https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.python/cxG7DLxXgmo > > First of all, the equation given there is unusable (even the number > of parentheses doesn't match up). Propbably it's meant to be the > one someone else posted a link to: > > http://classes.engr.oregonstate.edu/cce/winter2012/ce492/Modules/06_structural_design/06-3_body.htm > > This thingy can't be solved on paper so you need some iterative > algorithm to find the solution. So waht you do is modify the equa- > tion so that you have 0 on one side and then consider the other > side to be a function of SN+1. Now the problem you're left with > is to find the value(s) of SN+1 (and thus of SN) where the func- > tion has a zero-crossing. A commonly use algorithms for finding > zero-crossings is Newton's method. You can find lots of sites on > the internet describing it in all neccessary detail. It boils > down to start with some guess for the result and then calculate > the next, better approximation via > > xn+1 = xn - f(xn) / f'(xn) > > where f(xn)n) is the value of the function at point xn and > f'(xn) the value of the derivative of f (with respect to x) > also at xn. You repeat the process until the difference be- > tween xn an the next, better approximation, xn+1, has become > as small as you need it. > > So it's very simple to implement and the ugliest bit is pro- > bably calculating the required derivative of the function with > respect to SN+1 (wbich you can take to be x). Exactly. I think a 5th semester engineering student should know this. If not, it's not the python-skills that is the problem. It's the (lack of) mathematical insight. I think maybe the OP should not demand people here to "show the solution", but begin with something much simpler and then as he becomes better and better with python, he can move towards more programmatically advanced code. The basic idea about an iterating loop, defining an objective function etc is not really advanced python. But I think the OP should start out with something more simple than what he tries to do here. Just starting out by iteratingly finding the solution to x^2-9 = 0 is a great starting place. After having studied, googled python examples on the internet, I think most people should be able to solve x^2-9=0 in a day for a guy who knows about programming in an arbitrary programming language other than python. It looks like laziness, when we don't see any attempts to show what has been tried to do, from the OP's point of view. The best way to get good feedback (IMHO) is to post some code and then post any errors/warnings that python is giving back. Don't just write: "Give me the code for doing this". From gherron at digipen.edu Tue Jan 1 17:46:56 2013 From: gherron at digipen.edu (Gary Herron) Date: Tue, 01 Jan 2013 14:46:56 -0800 Subject: how to solve complex equation? In-Reply-To: References: Message-ID: <50E36760.107@digipen.edu> On 01/01/2013 11:02 AM, Usama Khan wrote: > how to solve complex equation in pyhton? and then use it to make a program. . i have created new post as my last post is i guessed ranked as a cheater. .:( > > i know very litle about python as well as programing. . > > which equation am taliking u will be thinking. . i am giving u the link kindly c that equation. . n kindly let me know the way. . > > https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.python/cxG7DLxXgmo Please STOP asking this question, and try to understand the answers you have already been given. Short answer: This is NOT a python question, and you can't solve it in Python. Longer answer: This is a math question. Some equations can be solved with algebra, and some can't, in which case perhaps you need some sort of a technique for numerical approximation. Other's have indicated that your problem probably falls into the later category. What YOU need to do is investigate iterative techniques for numerical solutions and pick one. (And this Python list is CERTAINLY the wrong place for such math questions.) Once you know what solution technique you want to use, you could then come back to this group and ask for help implementing it. P.S. I have implemented several such techniques, and I have taught college courses involving such techniques, and I'll say this: What you ask is the subject of AT LEAST several hours of lectures and possibly several semesters worth of study. No one is going to put that kind of time into answering your question here. -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From rosuav at gmail.com Tue Jan 1 17:27:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Jan 2013 09:27:37 +1100 Subject: how to solve complex equation? In-Reply-To: References: Message-ID: On Wed, Jan 2, 2013 at 6:02 AM, Usama Khan wrote: > how to solve complex equation in pyhton? and then use it to make a program. . i have created new post as my last post is i guessed ranked as a cheater. .:( 1) Do you mean complex or complicated? Be strict with your language, lest you get completely wrong answers. Python *does* have support for complex numbers, but I don't think you need them here. (I may be wrong (again), though.) 2) Put some more thought into your posts. You're coming across sounding very sloppy. We're all on the internet, so we know how to read through typos, but a proliferation of them in a message with no capitalization, SMS abbreviations ("u" for "you"... congrats, you saved two whole keystrokes there - four, since you did that twice), etc, adds up to an overall picture of someone who cares little about how the posts come across. 3) We are all volunteers. Python-list gets a goodly amount of traffic every day. If you want a response, you need to make your post look interesting, fun, or productive (preferably more than one of the above). Make it look like we're going to spend a huge amount of time helping a black hole is one of the best ways to get ignored. http://www.catb.org/esr/faqs/smart-questions.html Since you haven't read that link from last time I posted it, I'll take the liberty of quoting a portion of its introduction. """If you give us an interesting question to chew on we'll be grateful to you; good questions are a stimulus and a gift. ...What we are, unapologetically, is hostile to people who seem to be unwilling to think or to do their own homework before asking questions. People like that are time sinks ? they take without giving back, and they waste time we could have spent on another question more interesting and another person more worthy of an answer. We call people like this ?losers? (and for historical reasons we sometimes spell it ?lusers?).""" If you want a response, don't look like a loser. ChrisA From wuwei23 at gmail.com Tue Jan 1 17:57:05 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 Jan 2013 14:57:05 -0800 (PST) Subject: how to solve complex equation? References: Message-ID: On Jan 2, 5:02?am, Usama Khan wrote: > i have created new post as my last post is i guessed ranked as a cheater. .:( Don't do this. Starting new threads on the same subject because you're not happy with the response you're getting elsewhere is a surefire way to end up in a lot of killfiles. > i know very litle about python as well as programing. . Then please stop asking people to write your code for you. For many of us. this is our *profession*. Generally, we're here to help others & ourselves understand Python better, not to work for free. If you don't have the time or the ability to produce what you want, and it has value to you, then offer to *pay* someone for their time & effort in writing the code for you. From usamazohad at gmail.com Tue Jan 1 18:08:17 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 15:08:17 -0800 (PST) Subject: how to solve complex equation? In-Reply-To: References: Message-ID: <408a21de-d22d-4d20-88de-981863f46a50@googlegroups.com> thanks :) no issues. . :) sorry for wasting ur precious time. . .sorry once again. . its mine problem now. . neither python. .nor the algebra. . . sorry guys. dont mind. .:) dont get me wrong. . From timr at probo.com Tue Jan 1 14:31:14 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 01 Jan 2013 11:31:14 -0800 Subject: the class problem References: Message-ID: contro opinion wrote: > >here is my haha class >class haha(object): > def theprint(self): > print "i am here" > >>>> haha().theprint() >i am here >>>> haha(object).theprint() >Traceback (most recent call last): > File "", line 1, in >TypeError: object.__new__() takes no parameters > >why haha(object).theprint() get wrong output? It doesn't -- that's the right output. What did you expect it to do? The line "class haha(object)" says that "haha" is a class that happens to derive from the "object" base class. The class is still simply called "haha", and to create an instance of the class "haha", you write "haha()". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From xdegaye at gmail.com Tue Jan 1 16:31:55 2013 From: xdegaye at gmail.com (Xavier de Gaye) Date: Tue, 1 Jan 2013 22:31:55 +0100 Subject: ANN: pdb-clone 1.2 released Message-ID: pdb-clone is a clone of pdb, the standard library python debugger. pdb-clone is at http://code.google.com/p/pdb-clone/ pdb-clone features: * Improve significantly pdb performance. With breakpoints, pdb-clone runs at 1.2 to 2 times the speed of the interpreter while pdb runs at 10 to 70-100 times the speed of the interpreter, see http://code.google.com/p/pdb-clone/wiki/Performances * Fix pdb long standing bugs entered in the Python issue tracker, see http://code.google.com/p/pdb-clone/wiki/News * Add a bdb comprehensive test suite (more than 70 tests) and run both pdb and bdb test suites. * Three versions of pdb-clone are supported: o The py3 version of pdb-clone runs on python3 from python 3.2 onward. o The py2.7 vesion runs on python 2.7. o The py2.4 version runs on all python versions from 2.4 to 2.7 included. In this version, the restart command only handles source code changes made to the main module. The pdb command line interface remains unchanged. All the versions of pdb-clone implement the most recent python3 features of pdb, as defined in the python3 pdb documentation. From usamazohad at gmail.com Tue Jan 1 18:01:24 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 15:01:24 -0800 (PST) Subject: numpy has got newtonsmethod? Message-ID: my question is can we import newtonsmethod from nympy or sciPy? From rosuav at gmail.com Tue Jan 1 18:10:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Jan 2013 10:10:48 +1100 Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: On Wed, Jan 2, 2013 at 10:01 AM, Usama Khan wrote: > my question is can we import newtonsmethod from nympy or sciPy? http://www.catb.org/esr/faqs/smart-questions.html#classic ChrisA From vlastimil.brom at gmail.com Tue Jan 1 18:56:45 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 2 Jan 2013 00:56:45 +0100 Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: 2013/1/2 Usama Khan : > my question is can we import newtonsmethod from nympy or sciPy? > -- > http://mail.python.org/mailman/listinfo/python-list Hi, After successfully installing SciPy http://www.scipy.org/Download you should be able to import the respective modules and use this functionality such as http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.newton.html you may also consider mpmath http://code.google.com/p/mpmath/ http://mpmath.googlecode.com/svn/trunk/doc/build/calculus/optimization.html SymPy http://sympy.org or maybe some OpenOpt software http://openopt.org or other related libraries/frameworks available in python. I am not at all competent to decide about the suitability for your originally posted problem, but I guess, you may be able to find it out based on your requirements and the features supported by these libraries. hth, vbr From usamazohad at gmail.com Tue Jan 1 19:28:56 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 16:28:56 -0800 (PST) Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: thanks. . but how to instal scipy. because its in .rar form. .i have extracted the files to the place where python2.7 is installed. . but everytime i write import sciPy. .it give me error. . nd regarding ur question. . its a long story telling u why i have just ask this breif question. . anyways thanks . .waiing for ur reply. . i just want to iterate my complex equation. . how can i import newtonsmethod from numpy as numpy is successfully insalled. .:) From usamazohad at gmail.com Tue Jan 1 19:28:56 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 16:28:56 -0800 (PST) Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: thanks. . but how to instal scipy. because its in .rar form. .i have extracted the files to the place where python2.7 is installed. . but everytime i write import sciPy. .it give me error. . nd regarding ur question. . its a long story telling u why i have just ask this breif question. . anyways thanks . .waiing for ur reply. . i just want to iterate my complex equation. . how can i import newtonsmethod from numpy as numpy is successfully insalled. .:) From wuwei23 at gmail.com Tue Jan 1 19:43:44 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 Jan 2013 16:43:44 -0800 (PST) Subject: numpy has got newtonsmethod? References: Message-ID: <3c83efd4-16b5-4092-89fd-89194c801f74@pu9g2000pbc.googlegroups.com> On Jan 2, 10:28?am, Usama Khan wrote: > but how to instal scipy. because its in .rar form. .i have extracted > the files to the place where python2.7 is installed. . but everytime > i write import sciPy. .it give me error. . If you want help, you have to remember we can't magically detect your development environment. Of course, you could always just read http://www.scipy.org/Installing_SciPy and report back with explicit information on _what didn't work_. > i just want to iterate my complex equation. . > how can i import newtonsmethod from numpy as numpy is successfully > insalled. .:) Repeating the question because you're not listening to the answers given is growing tedious. Vlastimil provided you with a _direct link_ to the relevant documentation: http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.newton.html If you can't import from scipy, then _fix that problem first_, because that's what you need to be able to do the rest. From vlastimil.brom at gmail.com Tue Jan 1 20:09:54 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 2 Jan 2013 02:09:54 +0100 Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: 2013/1/2 Usama Khan : > thanks. . > > but how to instal scipy. because its in .rar form. .i have extracted the files to the place where python2.7 is installed. . but everytime i write import sciPy. .it give me error. . > nd regarding ur question. . > > its a long story telling u why i have just ask this breif question. . anyways thanks . .waiing for ur reply. . > > i just want to iterate my complex equation. . > > how can i import newtonsmethod from numpy as numpy is successfully insalled. .:) > -- > http://mail.python.org/mailman/listinfo/python-list I assume (based on the traceback you posted), that you are using windows; in that case you can use the appropriate ready made installers for SciPy, instead of the source files; see.: http://sourceforge.net/projects/scipy/files/scipy/0.11.0/ e.g.: scipy-0.11.0-win32-superpack-python2.7.exe hth, vbr From usamazohad at gmail.com Tue Jan 1 19:42:13 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 16:42:13 -0800 (PST) Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: <109b80a1-8c8d-4db9-93aa-2f7d8f8fcec8@googlegroups.com> Traceback (most recent call last): File "C:/Python27/12.py", line 4, in import scipy # also has log File "C:/Python27\scipy\__init__.py", line 114, in raise ImportError(msg) ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python intepreter. >>> From usamazohad at gmail.com Tue Jan 1 19:42:13 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 16:42:13 -0800 (PST) Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: <109b80a1-8c8d-4db9-93aa-2f7d8f8fcec8@googlegroups.com> Traceback (most recent call last): File "C:/Python27/12.py", line 4, in import scipy # also has log File "C:/Python27\scipy\__init__.py", line 114, in raise ImportError(msg) ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python intepreter. >>> From steve+comp.lang.python at pearwood.info Tue Jan 1 21:04:24 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Jan 2013 02:04:24 GMT Subject: numpy has got newtonsmethod? References: <109b80a1-8c8d-4db9-93aa-2f7d8f8fcec8@googlegroups.com> Message-ID: <50e395a8$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Jan 2013 16:42:13 -0800, Usama Khan wrote: > Traceback (most recent call last): > File "C:/Python27/12.py", line 4, in > import scipy # also has log > File "C:/Python27\scipy\__init__.py", line 114, in > raise ImportError(msg) > ImportError: Error importing scipy: you cannot import scipy while > being in scipy source directory; please exit the scipy source > tree first, and relaunch your python intepreter. Please read the error message. It tells you exactly what you need to do. You cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python interpreter. Do you understand what a source directory is? It is a directory (a folder) with the source code in it. Leave the scipy directory, and re- start Python, then try importing scipy. -- Steven From usamazohad at gmail.com Tue Jan 1 19:34:50 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 16:34:50 -0800 (PST) Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: <450b8b01-71e3-44fd-a9a9-2e349a1b4c80@googlegroups.com> yeah i have read it sir CrisA. .:) thanks . .:) i wish i could make u watch my google search list of last two days nd idm downlaodng list of last two days. .text me ur email id. .i can show u my efforts. . :) From usamazohad at gmail.com Tue Jan 1 19:34:50 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 16:34:50 -0800 (PST) Subject: numpy has got newtonsmethod? In-Reply-To: References: Message-ID: <450b8b01-71e3-44fd-a9a9-2e349a1b4c80@googlegroups.com> yeah i have read it sir CrisA. .:) thanks . .:) i wish i could make u watch my google search list of last two days nd idm downlaodng list of last two days. .text me ur email id. .i can show u my efforts. . :) From wuwei23 at gmail.com Tue Jan 1 19:46:18 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 Jan 2013 16:46:18 -0800 (PST) Subject: numpy has got newtonsmethod? References: <450b8b01-71e3-44fd-a9a9-2e349a1b4c80@googlegroups.com> Message-ID: On Jan 2, 10:34?am, Usama Khan wrote: > i wish i could make u watch my google search list of last two days nd idm downlaodng list of last two days. .text me ur email id. .i can show u my efforts. . > :) I'm guessing it would show you flailing around and _not_ typing "numpy newton's method", because that's all it took to bring up the direct link to the scipy documentation on importing & using it (first link), as well as full code samples of variants implemented directly in numpy. From usamazohad at gmail.com Tue Jan 1 20:00:36 2013 From: usamazohad at gmail.com (Usama Khan) Date: Tue, 1 Jan 2013 17:00:36 -0800 (PST) Subject: numpy has got newtonsmethod? In-Reply-To: References: <450b8b01-71e3-44fd-a9a9-2e349a1b4c80@googlegroups.com> Message-ID: <46fc0a2b-059f-4fca-97bd-3700bbc78b1c@googlegroups.com> k thanks :) From rosuav at gmail.com Tue Jan 1 23:10:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Jan 2013 15:10:37 +1100 Subject: numpy has got newtonsmethod? In-Reply-To: <450b8b01-71e3-44fd-a9a9-2e349a1b4c80@googlegroups.com> References: <450b8b01-71e3-44fd-a9a9-2e349a1b4c80@googlegroups.com> Message-ID: On Wed, Jan 2, 2013 at 11:34 AM, Usama Khan wrote: > yeah i have read it sir CrisA. .:) > > thanks . .:) > > i wish i could make u watch my google search list of last two days nd idm downlaodng list of last two days. .text me ur email id. .i can show u my efforts. . > :) Well, my "email id" (I presume you mean "email address") is perfectly visible in the headers of all my posts to this list/newsgroup. But that doesn't give you the right to email me a list of everything you've searched for, downloaded, etc. Plus, it wouldn't help your case; your posts carry no indication that you have learned from your web searches, so it doesn't matter what you've done. Your posts also bear no suggestion that you have read esr's excellent article on asking questions, which is why I reiterated it. So don't show me your efforts. Show me that you've learned from them. ChrisA From vbhoj74 at gmail.com Tue Jan 1 21:42:56 2013 From: vbhoj74 at gmail.com (vbhoj74 at gmail.com) Date: Tue, 1 Jan 2013 18:42:56 -0800 (PST) Subject: Noob: Trying to run two python scrips on a pfsense/freeBSD for the OWL-Intuition-LC Message-ID: <31af8e4e-94af-4f8c-866f-145e3244c0ae@googlegroups.com> Hi, I wrote couple of scrips to work with OWL-intution-LC home/office electricity monitor. The concept of the first scrip (owl.py) to capture network multicast from the OWL gateway and write to a .csv file has been taken from a raspberrypi forum and further developed upon to work with sqlite. The second scrip (responder.py)keeps checking a mail account for any email queries received and responds with a detailed electricity report to the sender. I've been using owl.py since some days & works fine on the pfsense/freebsd, it has been set to start on boot using shellcmd. The second scrip also works when I execute manually from the shell, but it does not seems to start upon boot how I did for owl.py. I cannot find anything in /var/log/system.log about execution or failure of either scrips. This question may not exactly relate with python but any help would be appreciated. Another Q I wanted to ask or rather confirm, I think python does not log anything from scrip runtime/termination and that there is a log library that needs to be used. I find using the log library adding bulk to the code and for every line I suspect of failure in the code I would need to put in an exception to create log ? Is there a better way of logging where it just logs the reason on scrip termination ? I just want to log the msg it shows when manually run in a shell. - Thanks. From wrw at mac.com Tue Jan 1 22:18:42 2013 From: wrw at mac.com (wrw at mac.com) Date: Tue, 01 Jan 2013 22:18:42 -0500 Subject: Noob: Trying to run two python scrips on a pfsense/freeBSD for the OWL-Intuition-LC In-Reply-To: <31af8e4e-94af-4f8c-866f-145e3244c0ae@googlegroups.com> References: <31af8e4e-94af-4f8c-866f-145e3244c0ae@googlegroups.com> Message-ID: On Jan 1, 2013, at 9:42 PM, vbhoj74 at gmail.com wrote: > Hi, > > I wrote couple of scrips to work with OWL-intution-LC home/office electricity monitor. The concept of the first scrip (owl.py) to capture network multicast from the OWL gateway and write to a .csv file has been taken from a raspberrypi forum and further developed upon to work with sqlite. The second scrip (responder.py)keeps checking a mail account for any email queries received and responds with a detailed electricity report to the sender. > > I've been using owl.py since some days & works fine on the pfsense/freebsd, it has been set to start on boot using shellcmd. The second scrip also works when I execute manually from the shell, but it does not seems to start upon boot how I did for owl.py. I cannot find anything in /var/log/system.log about execution or failure of either scrips. > > This question may not exactly relate with python but any help would be appreciated. > > Another Q I wanted to ask or rather confirm, I think python does not log anything from scrip runtime/termination and that there is a log library that needs to be used. I find using the log library adding bulk to the code and for every line I suspect of failure in the code I would need to put in an exception to create log ? Is there a better way of logging where it just logs the reason on scrip termination ? I just want to log the msg it shows when manually run in a shell. - Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list Can't help with the mail script's failure to launch (although it may be because something in the script requires an environmental variable that hasn't been created when running in batch). But I can make a suggestion for logging. Operating systems have subtle differences, so this may not be a solution for you, but at least on OS-X (which at its heart is an amalgam of freebsd and netbsd), any print statement goes to the system log if the program is being run from batch rather than from an interactive terminal window. Thus, simple print statements scattered through the code should allow you to monitor the execution under normal circumstances. Of course, any abnormal termination will result in error messages in the same system log. -Bill From vbhoj74 at gmail.com Wed Jan 2 01:04:32 2013 From: vbhoj74 at gmail.com (Vineet Bhojnagarwala) Date: Tue, 1 Jan 2013 22:04:32 -0800 (PST) Subject: Noob: Trying to run two python scrips on a pfsense/freeBSD for the OWL-Intuition-LC In-Reply-To: References: <31af8e4e-94af-4f8c-866f-145e3244c0ae@googlegroups.com> Message-ID: <2231ba64-e18b-4460-bcb7-63c28745bde2@googlegroups.com> I've print statements in my code for troubleshooting purpose, but I do not find it in any of the logs in /var/log/, not even system.log. Anything that I need to do for it to write the log ? From vbhoj74 at gmail.com Wed Jan 2 01:04:32 2013 From: vbhoj74 at gmail.com (Vineet Bhojnagarwala) Date: Tue, 1 Jan 2013 22:04:32 -0800 (PST) Subject: Noob: Trying to run two python scrips on a pfsense/freeBSD for the OWL-Intuition-LC In-Reply-To: References: <31af8e4e-94af-4f8c-866f-145e3244c0ae@googlegroups.com> Message-ID: <2231ba64-e18b-4460-bcb7-63c28745bde2@googlegroups.com> I've print statements in my code for troubleshooting purpose, but I do not find it in any of the logs in /var/log/, not even system.log. Anything that I need to do for it to write the log ? From victorhooi at gmail.com Wed Jan 2 03:01:05 2013 From: victorhooi at gmail.com (Victor Hooi) Date: Wed, 2 Jan 2013 00:01:05 -0800 (PST) Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Message-ID: Hi, I'm using pysvn to checkout a specific revision based on date - pysvn will only accept a date in terms of seconds since the epoch. I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to seconds since epoch. According to the docs, mktime expects a 9-element tuple. My question is, how should I omit elements from this tuple? And what is the expected behaviour when I do that? For example, (zero-index), element 6 is the day of the week, and element 7 is the day in the year, out of 366 - if I specify the earlier elements, then I shouldn't really need to specify these. However, the docs don't seem to talk much about this. I just tried testing putting garbage numbers for element 6 and 7, whilst specifying the earlier elements: > time.mktime((2012, 5, 5, 23, 59, 59, 23424234, 5234234 ,0 )) It seems to have no effect what numbers I set 6 and 7 to - is that because the earlier elements are set? How should I properly omit them? Is this all documented somewhere? What is the minimum I need to specify? And what happens to the fields I don't specify? Cheers, Victor From vlastimil.brom at gmail.com Wed Jan 2 03:33:39 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 2 Jan 2013 09:33:39 +0100 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? In-Reply-To: References: Message-ID: 2013/1/2 Victor Hooi : > Hi, > > I'm using pysvn to checkout a specific revision based on date - pysvn will only accept a date in terms of seconds since the epoch. > > I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to seconds since epoch. > > According to the docs, mktime expects a 9-element tuple. > > My question is, how should I omit elements from this tuple? And what is the expected behaviour when I do that? > > For example, (zero-index), element 6 is the day of the week, and element 7 is the day in the year, out of 366 - if I specify the earlier elements, then I shouldn't really need to specify these. > > However, the docs don't seem to talk much about this. > > I just tried testing putting garbage numbers for element 6 and 7, whilst specifying the earlier elements: > >> time.mktime((2012, 5, 5, 23, 59, 59, 23424234, 5234234 ,0 )) > > It seems to have no effect what numbers I set 6 and 7 to - is that because the earlier elements are set? > > How should I properly omit them? Is this all documented somewhere? What is the minimum I need to specify? And what happens to the fields I don't specify? > > Cheers, > Victor > -- > http://mail.python.org/mailman/listinfo/python-list Hi, if you initially have the time information as string, you might use time.strptime(...) to extract this based on the supplied format; the output of this function is usable as input for mktime, the remaining fields are presumably handled consistently. see: http://docs.python.org/2/library/time.html#time.strftime >>> time.strptime("2012-3-17", "%Y-%m-%d") time.struct_time(tm_year=2012, tm_mon=3, tm_mday=17, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=77, tm_isdst=-1) >>> time.mktime(time.strptime("2012-3-17", "%Y-%m-%d")) 1331938800.0 >>> hth, vbr From davea at dejaviewphoto.com Wed Jan 2 09:06:51 2013 From: davea at dejaviewphoto.com (Dave Angel) Date: Wed, 02 Jan 2013 09:06:51 -0500 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? In-Reply-To: References: Message-ID: <50E43EFB.5080902@dejaviewphoto.com> On 01/02/2013 03:01 AM, Victor Hooi wrote: > Hi, > > I'm using pysvn to checkout a specific revision based on date - pysvn will only accept a date in terms of seconds since the epoch. > > I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to seconds since epoch. > > According to the docs, mktime expects a 9-element tuple. Actually, it expects a struct_time, but will work with a tuple. The easiest way to build a struct_time from your string would be using time.strptime(), as suggested by Vlastimil. > The other problem is one of timezone. I would assume that svn would be expecting all times to be in UTC, so to convert from struct_time in UTC to seconds since epoch, you'd use calendar.timegm() See the chart on http://docs.python.org/2/library/time From roy at panix.com Wed Jan 2 09:28:04 2013 From: roy at panix.com (Roy Smith) Date: Wed, 02 Jan 2013 09:28:04 -0500 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? References: Message-ID: In article , Victor Hooi wrote: > Hi, > > I'm using pysvn to checkout a specific revision based on date - pysvn will > only accept a date in terms of seconds since the epoch. > > I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to > seconds since epoch. In what timezone is "2012-02-01" supposed to be interpreted? You really can't do anything without knowing that. > According to the docs, mktime expects a 9-element tuple. Over the past couple of years, I have slowly come to embrace the Python datetime class. It makes all of this stuff so much easier. The one thing it's missing is the ability to parse date strings in a sane way (I don't consider strptime() to be sane). Installing dateutil (http://labix.org/python-dateutil) is de rigueur, if for no reason other than to get dateutil.parser.parse(). Once you've got that (and assuming your 2012-03-01 is in UTC) >>> epoch = parse("1970-01-01T00:00:00+0000") >>> t = parse("2012-03-17T00:00:00+0000") >>> (t - epoch).total_seconds() 1331942400.0 I never want to see another timetuple again. PS: you need Python 2.7 to get total_seconds(). But, then again, I consider Python 2.7 to be de rigueur as well. PPS: Some additional hints for staying sane while working with dates: 1) Do everything in UTC. 2) Even if you violate rule #1 at the edges, always, without exception, store dates in your database (and transmit them over your APIs) in UTC. 3) Run all your servers with their timezones set to UTC. 4) Run NTP everywhere. 5) If in doubt, see rule #2. 6) If it's absolutely impossible to obey rule #2, at least store and transmit time in a self-describing format (i.e. one which includes the timezone information). 7) If it's absolutely impossible to obey rule #6, run away from the project. From rosuav at gmail.com Wed Jan 2 09:51:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 01:51:15 +1100 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? In-Reply-To: References: Message-ID: On Thu, Jan 3, 2013 at 1:28 AM, Roy Smith wrote: > PPS: Some additional hints for staying sane while working with dates: I assume you mean timestamps. A date doesn't need to worry about UTC the way a timestamp does. Beyond that, I agree with most of your comments. > 3) Run all your servers with their timezones set to UTC. Not strictly necessary imo; as long as your application knows that it needs to work in UTC, it doesn't matter what the OS works in. But yes, it is a convenience. > 7) If it's absolutely impossible to obey rule #6, run away from the > project. Absolutely. ChrisA From roy at panix.com Wed Jan 2 12:27:30 2013 From: roy at panix.com (Roy Smith) Date: 2 Jan 2013 12:27:30 -0500 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? References: Message-ID: In article , Chris Angelico wrote: >> I assume you mean timestamps. A date doesn't need to worry about UTC >> the way a timestamp does. I'm not sure how a date and a timestamp differ in any significant way. A date is just a very low-precision time. >> 3) Run all your servers with their timezones set to UTC. > > Not strictly necessary imo; as long as your application knows that it > needs to work in UTC, it doesn't matter what the OS works in. But yes, > it is a convenience. Many small conveniences add up to conservation of sanity :-) I suppose what's really essential is a way to quickly see the current UTC time. That way, when you're looking at some event in a log file, it's easy to figure out, "that was 20 minutes ago", as opposed to, "that was 5 hours and 20 minutes ago". I run my desktop in New York time (so I know when I'm supposed to eat lunch), but I also have a second clock widget displaying UTC time just below it. Right now, it's 17:22. From rosuav at gmail.com Wed Jan 2 12:34:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 04:34:32 +1100 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? In-Reply-To: References: Message-ID: On Thu, Jan 3, 2013 at 4:27 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >>> I assume you mean timestamps. A date doesn't need to worry about UTC >>> the way a timestamp does. > > I'm not sure how a date and a timestamp differ in any significant > way. A date is just a very low-precision time. > > I suppose what's really essential is a way to quickly see the current > UTC time. That way, when you're looking at some event in a log file, > it's easy to figure out, "that was 20 minutes ago", as opposed to, > "that was 5 hours and 20 minutes ago". I run my desktop in New York > time (so I know when I'm supposed to eat lunch), but I also have a > second clock widget displaying UTC time just below it. Right now, > it's 17:22. The difference between "20 minutes ago" and "5 hours and 20 minutes ago" doesn't really come up when your resolution is 86400 seconds, as is the case with a date :) I have the same sort of thing. My desktop's clock is on local time (4:33AM), but my server tells me, when I type 'who', that "The current UTC (GMT) time is: Wed 17:33:35" (it doesn't bother with the date, only the day of week, as the main purpose of that time display is to help people synchronize on weekly events). ChrisA From d at davea.name Wed Jan 2 12:44:57 2013 From: d at davea.name (Dave Angel) Date: Wed, 02 Jan 2013 12:44:57 -0500 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? In-Reply-To: References: Message-ID: <50E47219.6020503@davea.name> On 01/02/2013 12:34 PM, Chris Angelico wrote: > On Thu, Jan 3, 2013 at 4:27 AM, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>>> I assume you mean timestamps. A date doesn't need to worry about UTC >>>> the way a timestamp does. >> I'm not sure how a date and a timestamp differ in any significant >> way. A date is just a very low-precision time. >> >> I suppose what's really essential is a way to quickly see the current >> UTC time. That way, when you're looking at some event in a log file, >> it's easy to figure out, "that was 20 minutes ago", as opposed to, >> "that was 5 hours and 20 minutes ago". I run my desktop in New York >> time (so I know when I'm supposed to eat lunch), but I also have a >> second clock widget displaying UTC time just below it. Right now, >> it's 17:22. > The difference between "20 minutes ago" and "5 hours and 20 minutes > ago" doesn't really come up when your resolution is 86400 seconds, as > is the case with a date :) Only 20.83 % of the time for that timezone. You might not notice it if you always log off by 7pm. > > I have the same sort of thing. My desktop's clock is on local time > (4:33AM), but my server tells me, when I type 'who', that "The current > UTC (GMT) time is: Wed 17:33:35" (it doesn't bother with the date, > only the day of week, as the main purpose of that time display is to > help people synchronize on weekly events). > > ChrisA -- DaveA From barry at barrys-emacs.org Thu Jan 3 18:46:55 2013 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 3 Jan 2013 23:46:55 +0000 Subject: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? In-Reply-To: References: Message-ID: <5350CCE9-5816-4538-BE67-8A81DAE15354@barrys-emacs.org> On 2 Jan 2013, at 08:01, Victor Hooi wrote: > Hi, > > I'm using pysvn to checkout a specific revision based on date - pysvn will only accept a date in terms of seconds since the epoch. > > I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to seconds since epoch. > > According to the docs, mktime expects a 9-element tuple. > > My question is, how should I omit elements from this tuple? And what is the expected behaviour when I do that? > > For example, (zero-index), element 6 is the day of the week, and element 7 is the day in the year, out of 366 - if I specify the earlier elements, then I shouldn't really need to specify these. > > However, the docs don't seem to talk much about this. > > I just tried testing putting garbage numbers for element 6 and 7, whilst specifying the earlier elements: > >> time.mktime((2012, 5, 5, 23, 59, 59, 23424234, 5234234 ,0 )) > > It seems to have no effect what numbers I set 6 and 7 to - is that because the earlier elements are set? > > How should I properly omit them? Is this all documented somewhere? What is the minimum I need to specify? And what happens to the fields I don't specify? See the python docs the tuple is fully documented. 6 and 7 are not needed to figure out the seconds so are ignored. Did you notice the parse_datetime.py that is in the pysvn Client Example? Its a rather over the top date and time parser I wrote a long long time ago. (Which is missing some imports, hmm I cannot have tested this for a long time). It can parse things like "yesterday 10:34". Barry From maniandram01 at gmail.com Wed Jan 2 08:12:30 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 2 Jan 2013 05:12:30 -0800 (PST) Subject: Python is awesome (Project Euler) In-Reply-To: References: Message-ID: <6df7a11c-ca9d-41af-8dbe-0110842a6220@googlegroups.com> On Monday, 31 December 2012 19:48:59 UTC+5:30, Roy Smith wrote: > If you haven't heard of it, you should check out Project Euler > > (http://projecteuler.net/). It's a series of (currently) 408 > > math-oriented programming problems, of varying degrees of difficulty. > > > > The tie-in to this group is just how many of them are trivial in Python. > > There's a whole slew of them which become one-liners due to Python's > > long int support. For example, http://projecteuler.net/problem=48. > > Datetime made me feel like I was cheating when I did > > http://projecteuler.net/problem=19. > > > > When you work with something as cool as Python every day, sometimes you > > lose sight of just how awesome it is. Thanks to everybody who has > > worked to make Python possible. Yup. From neilc at norwich.edu Wed Jan 2 14:11:24 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 2 Jan 2013 19:11:24 GMT Subject: Python is awesome (Project Euler) References: Message-ID: On 2012-12-31, Roy Smith wrote: > There's a problem I just worked where you need to find the last > 10 digits of some million-digit prime. Python's long ints > don't help you there. What does help you is figuring out a way > to solve the problem that's not brute-force. I think that's > what Euler is all about. I agree. The most interesting part of participating is finding out how my solution could've been improved or just completely replaced with zero programming in some memorable cases. My algebra has gotten a major workout, and I've had to resurrect the mostly-dead neurons in my skull in charge of calculus. Participants sometimes come up with terrible failures that nevertheless find the solution (I'm no exception, though I think I learn my lesson in the discussion groups). It's a limitation of the way answers are checked. Working to make a solution that's complete and extensible yields the most educational benefits, I think. -- Neil Cerutti From roy at panix.com Wed Jan 2 21:38:19 2013 From: roy at panix.com (Roy Smith) Date: Wed, 02 Jan 2013 21:38:19 -0500 Subject: Python is awesome (Project Euler) References: Message-ID: In article , Neil Cerutti wrote: > On 2012-12-31, Roy Smith wrote: > > There's a problem I just worked where you need to find the last > > 10 digits of some million-digit prime. Python's long ints > > don't help you there. What does help you is figuring out a way > > to solve the problem that's not brute-force. I think that's > > what Euler is all about. > > I agree. The most interesting part of participating is finding > out how my solution could've been improved Yeah, tell me about it. I was feeling pretty good about solving a three-digit problem (http://projecteuler.net/problem=104). I made some (so I thought) clever optimizations and got the answer in a little over a minute of run time. Then I looked at the discussion thread and discovered people were reporting their solution times in milli-seconds :-( From stringsatif1 at gmail.com Wed Jan 2 09:00:40 2013 From: stringsatif1 at gmail.com (stringsatif1 at gmail.com) Date: Wed, 2 Jan 2013 06:00:40 -0800 (PST) Subject: why the output is different when i am implementig multiline string Message-ID: >>> '''hello world''' 'hello\nworld' >>> fred=''' hello world''' >>> print(fred) hello world From rosuav at gmail.com Wed Jan 2 09:21:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 01:21:51 +1100 Subject: why the output is different when i am implementig multiline string In-Reply-To: References: Message-ID: On Thu, Jan 3, 2013 at 1:00 AM, wrote: >>>> '''hello > world''' > 'hello\nworld' >>>> fred=''' hello > world''' >>>> print(fred) > hello > world That's because repr() converts the newline into "\n", while print renders it literally. Check out repr() in the docs: http://docs.python.org/3/library/functions.html?highlight=repr#repr ChrisA From d at davea.name Wed Jan 2 09:22:16 2013 From: d at davea.name (Dave Angel) Date: Wed, 02 Jan 2013 09:22:16 -0500 Subject: why the output is different when i am implementig multiline string In-Reply-To: References: Message-ID: <50E44298.2090501@davea.name> On 01/02/2013 09:00 AM, stringsatif1 at gmail.com wrote: >>>> '''hello > world''' > 'hello\nworld' >>>> fred=''' hello > world''' >>>> print(fred) > hello > world What you're seeing has nothing to do with the triple quotes, and everything to do with how you're using the debugger. In one case, you just mention a value, and the debugger magically calls repr() on the expression. So it adds quotes around it, and turns embedded funny stuff into escape sequences, because that's what repr() does on a string. In the second case, you call Python's print function (assuming python 3, which you didn't specify). it does not call repr(), but just sends the characters direct to the console. if you want to see the escape characters in the second case, you should have either said: >>>fred or >>>print(repr(fred)) -- DaveA From stringsatif1 at gmail.com Wed Jan 2 10:10:58 2013 From: stringsatif1 at gmail.com (stringsatif1 at gmail.com) Date: Wed, 2 Jan 2013 07:10:58 -0800 (PST) Subject: why the output is different when i am implementig multiline string In-Reply-To: References: Message-ID: thanks dave.. From stringsatif1 at gmail.com Wed Jan 2 10:10:58 2013 From: stringsatif1 at gmail.com (stringsatif1 at gmail.com) Date: Wed, 2 Jan 2013 07:10:58 -0800 (PST) Subject: why the output is different when i am implementig multiline string In-Reply-To: References: Message-ID: thanks dave.. From stringsatif1 at gmail.com Wed Jan 2 10:11:13 2013 From: stringsatif1 at gmail.com (stringsatif1 at gmail.com) Date: Wed, 2 Jan 2013 07:11:13 -0800 (PST) Subject: why the output is different when i am implementig multiline string In-Reply-To: References: Message-ID: thanks cris From stringsatif1 at gmail.com Wed Jan 2 10:11:13 2013 From: stringsatif1 at gmail.com (stringsatif1 at gmail.com) Date: Wed, 2 Jan 2013 07:11:13 -0800 (PST) Subject: why the output is different when i am implementig multiline string In-Reply-To: References: Message-ID: thanks cris From khan.immran at gmail.com Wed Jan 2 09:04:53 2013 From: khan.immran at gmail.com (NewbiePythonic) Date: Wed, 2 Jan 2013 06:04:53 -0800 (PST) Subject: New in Python , Need a Mentor Message-ID: <89b75a8a-a2a4-4586-8eff-b9c429e796ed@googlegroups.com> Hello Friends, I am very new to python and loved the easiness with which we can deal with problems. I would like to take things seriously and develop some good web applications. But right now I am stuck and looking for a mentor who can help me out with improving my skills and knowledge . Looking forward to meet someone who can help me out. Thanks & Regards From rosuav at gmail.com Wed Jan 2 09:29:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 01:29:12 +1100 Subject: New in Python , Need a Mentor In-Reply-To: <89b75a8a-a2a4-4586-8eff-b9c429e796ed@googlegroups.com> References: <89b75a8a-a2a4-4586-8eff-b9c429e796ed@googlegroups.com> Message-ID: On Thu, Jan 3, 2013 at 1:04 AM, NewbiePythonic wrote: > Hello Friends, > > I am very new to python and loved the easiness with which we can deal with problems. I would like to take things seriously and develop some good web applications. But right now I am stuck and looking for a mentor who can help me out with improving my skills and knowledge . Looking forward to meet someone who can help me out. The best mentor for Python is actually your Python interpreter. As a modern high-level language, Python's pretty helpful at finding problems - anything that it detects as an error will be reported with a thrown exception, with full traceback. Get to know your interpreter via its interactive mode (on Windows, I strongly recommend IDLE - much better editing/recall facilities than the command-line Python has), and work through the tutorial: http://docs.python.org/3/tutorial/index.html After that, just do things and do things and do more things, and you'll be Pythonning like an expert in no time... or rather, in about a week or so. :) And when you run into difficulties, this newsgroup/mailing list will be happy to help out. Just remember to post a minimal test-case for your problem, and *copy and paste* the error message with the full traceback - that can be the difference between a protracted debugging session and an almost reflex response from someone who can spot the problem straight off. Have fun! The world's a lovely place... ChrisA From news4 at mystrobl.de Wed Jan 2 11:24:25 2013 From: news4 at mystrobl.de (Wolfgang Strobl) Date: Wed, 02 Jan 2013 17:24:25 +0100 Subject: New in Python , Need a Mentor References: <89b75a8a-a2a4-4586-8eff-b9c429e796ed@googlegroups.com> Message-ID: Chris Angelico : >On Thu, Jan 3, 2013 at 1:04 AM, NewbiePythonic wrote: >> Hello Friends, >> >> I am very new to python and loved the easiness with which we can deal with problems. I would like to take things seriously and develop some good web applications. But right now I am stuck and looking for a mentor who can help me out with improving my skills and knowledge . Looking forward to meet someone who can help me out. > >The best mentor for Python is actually your Python interpreter. As a >modern high-level language, Python's pretty helpful at finding >problems - anything that it detects as an error will be reported with >a thrown exception, with full traceback. Get to know your interpreter >via its interactive mode (on Windows, Right. In addition, i'd suggest applying the short recpie in (i.e. add that snippet to sitecustomize.py) and learn a little bit of pdb. This works everywhere and comes quite handy for inspecting code right after something throws an exception. >I strongly recommend IDLE - much >better editing/recall facilities than the command-line Python has), >and work through the tutorial: Well, this is certainly a matter of taste. I'd recommend using some small, language independent programmers editor and some modern distributed version control system right at the beginning. Put your code, even the smallest snippets, under version control, make that a habit. Write small doctests for your code from the very beginning. Try to construct your code so that it works equally well as a module and as a standalone script Don't start developing web applications, write some small utilities for your own needs, first. Personally, I suggest SciTE and TortoiseHG on Windows, but that too is, as I said, a matter of taste. -- Wir danken f?r die Beachtung aller Sicherheitsbestimmungen From rosuav at gmail.com Wed Jan 2 11:30:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jan 2013 03:30:09 +1100 Subject: New in Python , Need a Mentor In-Reply-To: References: <89b75a8a-a2a4-4586-8eff-b9c429e796ed@googlegroups.com> Message-ID: On Thu, Jan 3, 2013 at 3:24 AM, Wolfgang Strobl wrote: > Chris Angelico : >>I strongly recommend IDLE - much >>better editing/recall facilities than the command-line Python has), >>and work through the tutorial: > > Well, this is certainly a matter of taste. I'd recommend using some > small, language independent programmers editor and some modern > distributed version control system right at the beginning. Put your > code, even the smallest snippets, under version control, make that a > habit. Write small doctests for your code from the very beginning. Try > to construct your code so that it works equally well as a module and as > a standalone script Don't start developing web applications, write > some small utilities for your own needs, first. > > Personally, I suggest SciTE and TortoiseHG on Windows, but that too is, > as I said, a matter of taste. I don't edit code in IDLE, I just use it for interactive work. For actual script editing, agreed (though I use git rather than hg), but it really does help to have a way to *very* quickly test a line or two of code. ChrisA From fred.sells at adventistcare.org Wed Jan 2 12:24:42 2013 From: fred.sells at adventistcare.org (Sells, Fred) Date: Wed, 2 Jan 2013 17:24:42 +0000 Subject: New in Python , Need a Mentor In-Reply-To: References: <89b75a8a-a2a4-4586-8eff-b9c429e796ed@googlegroups.com> Message-ID: The need for a "python-aware" editor is the commonly held opinion, although the debate about which editor is endless. I use Eclipse + PyDev only because I found it first and like it. The only suggestion I would offer is to separate the business logic completely from the HTML request/response handler. It makes it much easier to debug. Other than that, ditto to everyone else's response. Fred. From newsboost at gmail.com Sat Jan 5 06:33:42 2013 From: newsboost at gmail.com (someone) Date: Sat, 05 Jan 2013 12:33:42 +0100 Subject: New in Python , Need a Mentor In-Reply-To: References: <89b75a8a-a2a4-4586-8eff-b9c429e796ed@googlegroups.com> Message-ID: On 01/02/2013 05:30 PM, Chris Angelico wrote: > On Thu, Jan 3, 2013 at 3:24 AM, Wolfgang Strobl wrote: >> Chris Angelico : >>> I strongly recommend IDLE - much >>> better editing/recall facilities than the command-line Python has), >>> and work through the tutorial: >> >> Well, this is certainly a matter of taste. I'd recommend using some >> small, language independent programmers editor and some modern >> distributed version control system right at the beginning. Put your >> code, even the smallest snippets, under version control, make that a >> habit. Write small doctests for your code from the very beginning. Try >> to construct your code so that it works equally well as a module and as >> a standalone script Don't start developing web applications, write >> some small utilities for your own needs, first. >> >> Personally, I suggest SciTE and TortoiseHG on Windows, but that too is, >> as I said, a matter of taste. > > I don't edit code in IDLE, I just use it for interactive work. For > actual script editing, agreed (though I use git rather than hg), but > it really does help to have a way to *very* quickly test a line or two > of code. I really REALLY like debugging with "eric"... http://eric-ide.python-projects.org/ From py at liquibits.com Wed Jan 2 14:21:10 2013 From: py at liquibits.com (rbit) Date: Wed, 2 Jan 2013 11:21:10 -0800 Subject: ANN: PyDTLS Message-ID: I would like to announce Datagram Transport Layer Security for Python. From the top of the project README: PyDTLS brings Datagram Transport Layer Security (DTLS - RFC 6347: http://tools.ietf.org/html/rfc6347) to the Python environment. In a nutshell, DTLS brings security (encryption, server authentication, user authentication, and message authentication) to UDP datagram payloads in a manner equivalent to what SSL/TLS does for TCP stream content. DTLS is now very easy to use in Python. If you're familiar with the ssl module in Python's standard library, you already know how. All it takes is passing a datagram/UDP socket to the *wrap_socket* function instead of a stream/TCP socket. Here's how one sets up the client side of a connection: import ssl from socket import socket, AF_INET, SOCK_DGRAM from dtls import do_patch do_patch() sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM)) sock.connect(('foo.bar.com', 1234)) sock.send('Hi there') The project is hosted at https://github.com/rbit/pydtls. PyPI has packages: http://pypi.python.org/pypi/Dtls/0.1.0. I hope it proves useful. Ray -------------- next part -------------- An HTML attachment was scrubbed... URL: From guido at python.org Tue Jan 8 09:53:38 2013 From: guido at python.org (Guido van Rossum) Date: Tue, 8 Jan 2013 06:53:38 -0800 Subject: ANN: PyDTLS In-Reply-To: References: Message-ID: This sounds exciting. Are you considering a Python 3 port? It might make a nice demo of PEP 3156. On Monday, January 7, 2013, rbit wrote: > I would like to announce Datagram Transport Layer Security for > Python. From the top of the project README: > > PyDTLS brings Datagram Transport Layer Security (DTLS - RFC 6347: > http://tools.ietf.org/html/rfc6347) to the Python environment. In a > nutshell, DTLS brings security (encryption, server authentication, > user authentication, and message authentication) to UDP datagram > payloads in a manner equivalent to what SSL/TLS does for TCP stream > content. > > DTLS is now very easy to use in Python. If you're familiar with the > ssl module in Python's standard library, you already know how. All it > takes is passing a datagram/UDP socket to the *wrap_socket* function > instead of a stream/TCP socket. Here's how one sets up the client side > of a connection: > > import ssl > from socket import socket, AF_INET, SOCK_DGRAM > from dtls import do_patch > do_patch() > sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM)) > sock.connect(('foo.bar.com', 1234)) > sock.send('Hi there') > > The project is hosted at https://github.com/rbit/pydtls, and licensed > under > the Apache license 2.0. PyPI has packages. I can be reached > at code AT liquibits DOT com for questions, feedback, etc. > >

Dtls 0.1.0 - > Datagram Transport Layer Security for Python. (07-Jan-13) > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From py at liquibits.com Tue Jan 8 23:39:00 2013 From: py at liquibits.com (rbit) Date: Tue, 8 Jan 2013 20:39:00 -0800 Subject: ANN: PyDTLS In-Reply-To: References: Message-ID: Thank you. I will gladly port to Python 3 if there is interest from the community. Regarding PEP 3156: asynchronous use of unreliable network protocols makes for an interesting use case. In particular, it forces applications to deal with packet loss under some circumstances. One such situation occurs during DTLS's handshaking phase: if no response is received from the peer after some period of time, we must assume that our most recent datagram has been lost, and so we need to retransmit. The event loop interface as outlined in the PEP makes this a bit difficult (as did the asyncore module). One possible way to make things easier would be by adding two parameters to add_reader: a callable to retrieve the current timeout, and a callable that is invoked if that timeout expires before the descriptor becomes readable. Each loop iteration would then collect all given timeouts, and pass the minimum of that set to whatever polling facility it invokes. If that timeout expires, the corresponding timeout handler would be invoked prior to the next loop iteration. The PEP also considers only stream transports when referring to "transport." Datagram transports do not, for example, have the property that calling t.write(b'abc'); t.write(b'def') is equivalent to calling t.write(b'abcdef'). I'm not sure what sort of impact this omission of datagram transports has for an implementation. Though I would certainly like to see datagram transports be treated as first-class citizens, despite not being nearly used as often as stream transports. I would hope that an implementer of, say, RTP over UDP, can tie into the same event loop as someone implementing a single-process, single-threaded Web server. Implementing DTLS as a tulip transport sounds interesting. Is the tulip package available somewhere so that I can try it out? Ray On Tue, Jan 8, 2013 at 6:53 AM, Guido van Rossum wrote: > This sounds exciting. Are you considering a Python 3 port? It might make a > nice demo of PEP 3156. > > > On Monday, January 7, 2013, rbit wrote: >> >> I would like to announce Datagram Transport Layer Security for >> Python. From the top of the project README: >> >> PyDTLS brings Datagram Transport Layer Security (DTLS - RFC 6347: >> http://tools.ietf.org/html/rfc6347) to the Python environment. In a >> nutshell, DTLS brings security (encryption, server authentication, >> user authentication, and message authentication) to UDP datagram >> payloads in a manner equivalent to what SSL/TLS does for TCP stream >> content. >> >> DTLS is now very easy to use in Python. If you're familiar with the >> ssl module in Python's standard library, you already know how. All it >> takes is passing a datagram/UDP socket to the *wrap_socket* function >> instead of a stream/TCP socket. Here's how one sets up the client side >> of a connection: >> >> import ssl >> from socket import socket, AF_INET, SOCK_DGRAM >> from dtls import do_patch >> do_patch() >> sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM)) >> sock.connect(('foo.bar.com', 1234)) >> sock.send('Hi there') >> >> The project is hosted at https://github.com/rbit/pydtls, and licensed >> under >> the Apache license 2.0. PyPI has packages. I can be reached >> at code AT liquibits DOT com for questions, feedback, etc. >> >>

Dtls 0.1.0 - >> Datagram Transport Layer Security for Python. (07-Jan-13) >> -- >> http://mail.python.org/mailman/listinfo/python-announce-list >> >> Support the Python Software Foundation: >> http://www.python.org/psf/donations/ > > > > -- > --Guido van Rossum (python.org/~guido) > > -- > http://mail.python.org/mailman/listinfo/python-list > From guido at python.org Wed Jan 9 00:09:33 2013 From: guido at python.org (Guido van Rossum) Date: Tue, 8 Jan 2013 21:09:33 -0800 Subject: ANN: PyDTLS In-Reply-To: References: Message-ID: On Tue, Jan 8, 2013 at 8:39 PM, rbit wrote: > Thank you. I will gladly port to Python 3 if there is interest from > the community. Python 3 is where it's at! :-) > Regarding PEP 3156: asynchronous use of unreliable network protocols > makes for an interesting use case. In particular, it forces > applications to deal with packet loss under some circumstances. But don't you have to deal with that when doing synchronous I/O as well? It's a datagram protocol after all. > One > such situation occurs during DTLS's handshaking phase: if no response > is received from the peer after some period of time, we must assume > that our most recent datagram has been lost, and so we need to > retransmit. Is this something the transport can handle, or does the protocol (and hence the application) need to be involved here? > The event loop interface as outlined in the PEP makes this > a bit difficult (as did the asyncore module). One possible way to make > things easier would be by adding two parameters to add_reader: a > callable to retrieve the current timeout, and a callable that is > invoked if that timeout expires before the descriptor becomes > readable. Each loop iteration would then collect all given timeouts, > and pass the minimum of that set to whatever polling facility it > invokes. If that timeout expires, the corresponding timeout handler > would be invoked prior to the next loop iteration. Hm, this would add a fair amount of complexity to the event loop. It's true that I don't have the complete story for timeouts yet, but I am hopeful that things like this can be implemented by using call_later() with some callback that does the retransmit (and resets some internal state), and cancelling that callback whenever a packet is received (i.e. in the protocol's datagram_received() method). > The PEP also considers only stream transports when referring to > "transport." Datagram transports do not, for example, have the > property that calling t.write(b'abc'); t.write(b'def') is equivalent > to calling t.write(b'abcdef'). Yeah, obviously this invariant only applies to stream protocols. The PEP currently doesn't really specify datagram support (it's just in the Open Issues section). > I'm not sure what sort of impact this > omission of datagram transports has for an implementation. Though I > would certainly like to see datagram transports be treated as > first-class citizens, despite not being nearly used as often as stream > transports. I would hope that an implementer of, say, RTP over UDP, > can tie into the same event loop as someone implementing a > single-process, single-threaded Web server. Yeah, at the level of the eventloop proper (the APIs that deal with callbacks, not futures, transports and protocols) datagrams won't be a problem. There will have to be separate specifications for the transport and protocol interfaces used with datagrams. > Implementing DTLS as a tulip transport sounds interesting. Is the > tulip package available somewhere so that I can try it out? Absolutely -- it is very much in flux, but you can check out the latest source from http://code.google.com/p/tulip/source/checkout using Mercurial. --Guido > Ray > > On Tue, Jan 8, 2013 at 6:53 AM, Guido van Rossum wrote: >> This sounds exciting. Are you considering a Python 3 port? It might make a >> nice demo of PEP 3156. >> >> >> On Monday, January 7, 2013, rbit wrote: >>> >>> I would like to announce Datagram Transport Layer Security for >>> Python. From the top of the project README: >>> >>> PyDTLS brings Datagram Transport Layer Security (DTLS - RFC 6347: >>> http://tools.ietf.org/html/rfc6347) to the Python environment. In a >>> nutshell, DTLS brings security (encryption, server authentication, >>> user authentication, and message authentication) to UDP datagram >>> payloads in a manner equivalent to what SSL/TLS does for TCP stream >>> content. >>> >>> DTLS is now very easy to use in Python. If you're familiar with the >>> ssl module in Python's standard library, you already know how. All it >>> takes is passing a datagram/UDP socket to the *wrap_socket* function >>> instead of a stream/TCP socket. Here's how one sets up the client side >>> of a connection: >>> >>> import ssl >>> from socket import socket, AF_INET, SOCK_DGRAM >>> from dtls import do_patch >>> do_patch() >>> sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM)) >>> sock.connect(('foo.bar.com', 1234)) >>> sock.send('Hi there') >>> >>> The project is hosted at https://github.com/rbit/pydtls, and licensed >>> under >>> the Apache license 2.0. PyPI has packages. I can be reached >>> at code AT liquibits DOT com for questions, feedback, etc. >>> >>>

Dtls 0.1.0 - >>> Datagram Transport Layer Security for Python. (07-Jan-13) >>> -- >>> http://mail.python.org/mailman/listinfo/python-announce-list >>> >>> Support the Python Software Foundation: >>> http://www.python.org/psf/donations/ >> >> >> >> -- >> --Guido van Rossum (python.org/~guido) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> -- --Guido van Rossum (python.org/~guido) From py at liquibits.com Wed Jan 9 02:38:01 2013 From: py at liquibits.com (rbit) Date: Tue, 8 Jan 2013 23:38:01 -0800 Subject: ANN: PyDTLS In-Reply-To: References: Message-ID: On Tue, Jan 8, 2013 at 9:09 PM, Guido van Rossum wrote: > But don't you have to deal with that when doing synchronous I/O as > well? It's a datagram protocol after all. No: when dealing with blocking sockets, the OpenSSL library activates its own retransmission timers, and the application never becomes aware of whether timeouts occurred. Since OpenSSL can't do this in the the case of non-blocking sockets, it becomes the application's problem to call back into OpenSSL at some point in the future (the very same time for which OpenSSL would have set its own timeout had the socket been blocking). OpenSSL exports functions DTLSv1_get_timeout and DTLSv1_handle_timeout to applications to address this case. The timeouts start at one second, and double for each encountered timeout, until the timeout ceiling of one minutes is reached. I'm using the term "application" here for any code that uses the OpenSSL library, but is not part of it. >> One >> such situation occurs during DTLS's handshaking phase: if no response >> is received from the peer after some period of time, we must assume >> that our most recent datagram has been lost, and so we need to >> retransmit. > > Is this something the transport can handle, or does the protocol (and > hence the application) need to be involved here? Given my current understanding of the PEP, I think this can be handled in the transport. Maybe there's some pitfall here that I can't quite see yet - even more reason for me to try to implement it. >> The event loop interface as outlined in the PEP makes this >> a bit difficult (as did the asyncore module). One possible way to make >> things easier would be by adding two parameters to add_reader: a >> callable to retrieve the current timeout, and a callable that is >> invoked if that timeout expires before the descriptor becomes >> readable. Each loop iteration would then collect all given timeouts, >> and pass the minimum of that set to whatever polling facility it >> invokes. If that timeout expires, the corresponding timeout handler >> would be invoked prior to the next loop iteration. > > Hm, this would add a fair amount of complexity to the event loop. It's > true that I don't have the complete story for timeouts yet, but I am > hopeful that things like this can be implemented by using call_later() > with some callback that does the retransmit (and resets some internal > state), and cancelling that callback whenever a packet is received > (i.e. in the protocol's datagram_received() method). Yes, ok, I can see how that could work, too. I thought that it might make sense to centralize handling timeouts in the event loop in order to prevent proliferation in the transports (since there are multiple event loop implementations, perhaps a mix-in would be good?). I think one will want to contain handshake (vs. application data) timeout handling at least to the transport, though, and not let it spill over into various protocols. I'm not sure yet where the right place is for cancelling a timeout callback. >> Implementing DTLS as a tulip transport sounds interesting. Is the >> tulip package available somewhere so that I can try it out? > > Absolutely -- it is very much in flux, but you can check out the > latest source from http://code.google.com/p/tulip/source/checkout > using Mercurial. All right, thanks, I'll check it out. Ray -------------- next part -------------- An HTML attachment was scrubbed... URL: From guido at python.org Wed Jan 9 11:10:07 2013 From: guido at python.org (Guido van Rossum) Date: Wed, 9 Jan 2013 08:10:07 -0800 Subject: ANN: PyDTLS In-Reply-To: References: Message-ID: On Tue, Jan 8, 2013 at 11:38 PM, rbit wrote: > On Tue, Jan 8, 2013 at 9:09 PM, Guido van Rossum wrote: >> But don't you have to deal with that when doing synchronous I/O as >> well? It's a datagram protocol after all. > > No: when dealing with blocking sockets, the OpenSSL library activates its > own retransmission timers, and the application never becomes aware of > whether timeouts occurred. Since OpenSSL can't do this in the the case of > non-blocking sockets, it becomes the application's problem to call back into > OpenSSL at some point in the future (the very same time for which OpenSSL > would have set its own timeout had the socket been blocking). OpenSSL > exports functions DTLSv1_get_timeout and DTLSv1_handle_timeout to > applications to address this case. The timeouts start at one second, and > double for each encountered timeout, until the timeout ceiling of one > minutes is reached. I'm using the term "application" here for any code that > uses the OpenSSL library, but is not part of it. Got it. >>> One >>> such situation occurs during DTLS's handshaking phase: if no response >>> is received from the peer after some period of time, we must assume >>> that our most recent datagram has been lost, and so we need to >>> retransmit. >> >> Is this something the transport can handle, or does the protocol (and >> hence the application) need to be involved here? > > Given my current understanding of the PEP, I think this can be handled in > the transport. Maybe there's some pitfall here that I can't quite see yet - > even more reason for me to try to implement it. Yes -- I won't considered the PEP ready for acceptance until several people have successfully implemented new protocols using it and agree that they can do everything they need. (I want to get started with a decent HTTP client and server myself.) >>> The event loop interface as outlined in the PEP makes this >>> a bit difficult (as did the asyncore module). One possible way to make >>> things easier would be by adding two parameters to add_reader: a >>> callable to retrieve the current timeout, and a callable that is >>> invoked if that timeout expires before the descriptor becomes >>> readable. Each loop iteration would then collect all given timeouts, >>> and pass the minimum of that set to whatever polling facility it >>> invokes. If that timeout expires, the corresponding timeout handler >>> would be invoked prior to the next loop iteration. >> >> Hm, this would add a fair amount of complexity to the event loop. It's >> true that I don't have the complete story for timeouts yet, but I am >> hopeful that things like this can be implemented by using call_later() >> with some callback that does the retransmit (and resets some internal >> state), and cancelling that callback whenever a packet is received >> (i.e. in the protocol's datagram_received() method). > > Yes, ok, I can see how that could work, too. I thought that it might make > sense to centralize handling timeouts in the event loop in order to prevent > proliferation in the transports (since there are multiple event loop > implementations, perhaps a mix-in would be good?). A mix-in for what? Each event loop presumably already has its own timer implementation; call_later() and call_repeatedly() are supported in one way or another by all other event loops I'm aware of. We'll have to have more experience with writing transports and protocols before we'll know what is really missing. > I think one will want to > contain handshake (vs. application data) timeout handling at least to the > transport, though, and not let it spill over into various protocols. I'm not > sure yet where the right place is for cancelling a timeout callback. This seems pretty unique to your TLS-over-UDP use case. I am quite sure that you can write a transport that suits your purpose with just the socket, callback and timer primitives in the PEP. >>> Implementing DTLS as a tulip transport sounds interesting. Is the >>> tulip package available somewhere so that I can try it out? >> >> Absolutely -- it is very much in flux, but you can check out the >> latest source from http://code.google.com/p/tulip/source/checkout >> using Mercurial. > > All right, thanks, I'll check it out. Looking forward to your feedback! -- --Guido van Rossum (python.org/~guido) From ndbecker2 at gmail.com Wed Jan 9 10:08:13 2013 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 09 Jan 2013 10:08:13 -0500 Subject: ANN: PyDTLS References: Message-ID: A bit OT, but the widespread use of rfc 6347 could have a big impact on my work. I wonder if it's likely to see widespread use? What are likely/possible use cases? Thank. From py at liquibits.com Wed Jan 9 15:04:41 2013 From: py at liquibits.com (rbit) Date: Wed, 9 Jan 2013 12:04:41 -0800 Subject: ANN: PyDTLS In-Reply-To: References: Message-ID: Neal, A network protocol that is unreliable (i.e., lacks retransmission of dropped packets) and lacks congestion control will certainly never be a common, general purpose protocol, due to the amount of work it imposes on its user. Implementing an AIMD congestion control algorithm is burdensome to an application, and only some use cases (like DNS) won't need congestion control. Use of the Datagram Congestion Control Protocol is a potential way out for applications, but DCCP (RFC 4340) isn't available on some common platforms, like Windows. That being said, if you find yourself in the kind of unique situation that requires a network protocol with characteristics different from TCP (namely prioritizing availability of data over its reliability), and you need network security as well, then RFC 6347 is really the only reasonable game in town over rolling your own solution. The following are some of the main use cases that force applications into datagram protocols: * Minimizing protocol overhead. TCP has relatively high overhead, for example, its 3-way handshake for connection establishment. One can see why DNS uses UDP. * Real-time data streaming. With this use case, it makes no sense to hold arrived data from the application, because prior packets are being recovered through retransmission. Such packets should just be forgotten about, especially if they fall within the margin of the error concealment strategy of the application. Any sort of audio and/or video transmission falls in this category. RTP is usually done over UDP (and is an illustrative use case for RFC 6347). * Anything that operates below the transport layer (layer 4 of the OSI model). Say you're writing a VPN at a virtual Ethernet level, transmitting Ethernet frames among machines. In that case, protocols that either implement reliability (say, HTTP over TCP) or consciously try to avoid it (say, RTP over UDP) sit above you, and you would neither want to duplicate their reliability functions, nor introduce this unwanted behavior, respectively. But you may want security for your VPN. I hope this helps. Ray On Wed, Jan 9, 2013 at 7:08 AM, Neal Becker wrote: > A bit OT, but the widespread use of rfc 6347 could have a big impact on my > work. > I wonder if it's likely to see widespread use? What are likely/possible > use > cases? > > Thank. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 9 16:45:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Jan 2013 08:45:01 +1100 Subject: ANN: PyDTLS In-Reply-To: References: Message-ID: On Thu, Jan 10, 2013 at 7:04 AM, rbit wrote: > The following are some of the main use cases that force applications into > datagram protocols: > > * Minimizing protocol overhead. TCP has relatively high overhead, > for example, its 3-way handshake for connection establishment. > One can see why DNS uses UDP. Yep. Related to that: One of our systems at work uses UDP rather than TCP in order to simplify the detection of node loss. Rather than working with TCP retry etc and handling the variety of different ways in which "the other node is down" could be reported, the nodes simply send UDP packets to each other, and keep track of the timestamp when one was last received. There's only one failure state: silence. Not sure if high-level protocol simplicity counts as the same thing or not; it's a different form of overhead. ChrisA From subhabangalore at gmail.com Wed Jan 2 15:13:24 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Wed, 2 Jan 2013 12:13:24 -0800 (PST) Subject: Graph Drawing Message-ID: <37d37762-250c-4d9d-bd97-c40fa97309ef@googlegroups.com> Dear Group, In networkx module we generally try to draw the graph as, >>> import networkx as nx >>> G=nx.Graph() >>> G.add_edge(1, 2, weight=4.7 ) >>> G.add_edge(1, 3, weight=4.5 ) ..... Now, if I want to retrieve the information of traversal from 1 to 3, I can give, G.edges() but I am looking for a command or function by which I can get not only the node names but also the weights. If anyone in the room can kindly suggest? Regards, Subhabrata. NB: Apology for any indentation error, etc. From winefrog at gmail.com Wed Jan 2 17:21:11 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 2 Jan 2013 14:21:11 -0800 (PST) Subject: avoding the accumulation of array when using loop. Message-ID: Hi all, Thanks to Hans, I have had a good progress on my problem. Followings are Hans's Idea: import numpy as np b = [] c = 4 f = open("text.file", "r") while c < 10: c = c + 1 f.seek(0,0) for columns in ( raw.strip().split() for raw in f ): b.append(columns[c]) y = np.array(b, float) print c, y It's a bit inefficient to read the same file several times. You might consider reading it just once. For example: import numpy as np b = [] f = open("text.file", "r") data = [ line.strip().split() for line in f ] f.close() for c in xrange(5, 11): for row in data: b.append(row[c]) y = np.array(b, float) print c, y ------------------------------------------------------------------------------- It is a great idea, but I found some problems. I want each individual array of y. However, these two codes prodce accumulated array such as [1,2,3], [1,2,3,4,5,6], [1,2,3,4,5,6,7,8,9] and so on. I have tried to initialize for loop for each time to produce array. This effort has not been very successful. Do you guys have any idea? I will really appreciate ant help and idea. Thanks, Isaac From d at davea.name Wed Jan 2 18:54:18 2013 From: d at davea.name (Dave Angel) Date: Wed, 02 Jan 2013 18:54:18 -0500 Subject: avoding the accumulation of array when using loop. In-Reply-To: References: Message-ID: <50E4C8AA.90408@davea.name> On 01/02/2013 05:21 PM, Isaac Won wrote: > Hi all, > > Thanks to Hans, I have had a good progress on my problem. > > Followings are Hans's Idea: > > import numpy as np > > b = [] > c = 4 > f = open("text.file", "r") > > while c < 10: > c = c + 1 > > > f.seek(0,0) > > for columns in ( raw.strip().split() for raw in f ): > b.append(columns[c]) > > y = np.array(b, float) > print c, y > > > It's a bit inefficient to read the same file several times. Don't bet on it. The OS and the libraries and Python each do some buffering, so it might be nearly as fast to just reread if it's a small file. And if it's a huge one, the list would be even bigger. So the only sizes where the second approach is likely better is the mid-size file. > You might consider reading it just once. For example: > > > import numpy as np > > b = [] > > > > f = open("text.file", "r") > > data = [ line.strip().split() for line in f ] > f.close() > > for c in xrange(5, 11): > for row in data: > b.append(row[c]) > > > y = np.array(b, float) > print c, y > ------------------------------------------------------------------------------- > > It is a great idea, but I found some problems. I want each individual array of y. However, these two codes prodce accumulated array such as [1,2,3], [1,2,3,4,5,6], [1,2,3,4,5,6,7,8,9] and so on. I have tried to initialize for loop for each time to produce array. This effort has not been very successful. > Do you guys have any idea? I will really appreciate ant help and idea. Your description is very confusing. But i don't see why you just don't just set b=[] inside the outer loop, rather than doing it at the begin of the program. for c in xrange(5, 11): b = [] for row in data: b.append(row[c]) -- DaveA From winefrog at gmail.com Wed Jan 2 21:41:46 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 2 Jan 2013 18:41:46 -0800 (PST) Subject: avoding the accumulation of array when using loop. In-Reply-To: References: Message-ID: <746cf8a0-94c0-43c2-9a59-2272b390f12e@googlegroups.com> On Wednesday, January 2, 2013 5:54:18 PM UTC-6, Dave Angel wrote: > On 01/02/2013 05:21 PM, Isaac Won wrote: > > > Hi all, > > > > > > Thanks to Hans, I have had a good progress on my problem. > > > > > > Followings are Hans's Idea: > > > > > > import numpy as np > > > > > > b = [] > > > c = 4 > > > f = open("text.file", "r") > > > > > > while c < 10: > > > c = c + 1 > > > > > > > > > f.seek(0,0) > > > > > > for columns in ( raw.strip().split() for raw in f ): > > > b.append(columns[c]) > > > > > > y = np.array(b, float) > > > print c, y > > > > > > > > > It's a bit inefficient to read the same file several times. > > > > Don't bet on it. The OS and the libraries and Python each do some > > buffering, so it might be nearly as fast to just reread if it's a small > > file. And if it's a huge one, the list would be even bigger. So the > > only sizes where the second approach is likely better is the mid-size file. > > > > > You might consider reading it just once. For example: > > > > > > > > > import numpy as np > > > > > > b = [] > > > > > > > > > > > > f = open("text.file", "r") > > > > > > data = [ line.strip().split() for line in f ] > > > f.close() > > > > > > for c in xrange(5, 11): > > > for row in data: > > > b.append(row[c]) > > > > > > > > > y = np.array(b, float) > > > print c, y > > > ------------------------------------------------------------------------------- > > > > > > It is a great idea, but I found some problems. I want each individual array of y. However, these two codes prodce accumulated array such as [1,2,3], [1,2,3,4,5,6], [1,2,3,4,5,6,7,8,9] and so on. I have tried to initialize for loop for each time to produce array. This effort has not been very successful. > > > Do you guys have any idea? I will really appreciate ant help and idea. > > > > Your description is very confusing. But i don't see why you just don't > > just set b=[] inside the outer loop, rather than doing it at the begin > > of the program. > > > > for c in xrange(5, 11): > > b = [] > > for row in data: > > b.append(row[c]) > > > > > > > > -- > > > > DaveA Hi Dave, I really appreciate your advice. It was really helpful. Isaac From winefrog at gmail.com Wed Jan 2 21:41:46 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 2 Jan 2013 18:41:46 -0800 (PST) Subject: avoding the accumulation of array when using loop. In-Reply-To: References: Message-ID: <746cf8a0-94c0-43c2-9a59-2272b390f12e@googlegroups.com> On Wednesday, January 2, 2013 5:54:18 PM UTC-6, Dave Angel wrote: > On 01/02/2013 05:21 PM, Isaac Won wrote: > > > Hi all, > > > > > > Thanks to Hans, I have had a good progress on my problem. > > > > > > Followings are Hans's Idea: > > > > > > import numpy as np > > > > > > b = [] > > > c = 4 > > > f = open("text.file", "r") > > > > > > while c < 10: > > > c = c + 1 > > > > > > > > > f.seek(0,0) > > > > > > for columns in ( raw.strip().split() for raw in f ): > > > b.append(columns[c]) > > > > > > y = np.array(b, float) > > > print c, y > > > > > > > > > It's a bit inefficient to read the same file several times. > > > > Don't bet on it. The OS and the libraries and Python each do some > > buffering, so it might be nearly as fast to just reread if it's a small > > file. And if it's a huge one, the list would be even bigger. So the > > only sizes where the second approach is likely better is the mid-size file. > > > > > You might consider reading it just once. For example: > > > > > > > > > import numpy as np > > > > > > b = [] > > > > > > > > > > > > f = open("text.file", "r") > > > > > > data = [ line.strip().split() for line in f ] > > > f.close() > > > > > > for c in xrange(5, 11): > > > for row in data: > > > b.append(row[c]) > > > > > > > > > y = np.array(b, float) > > > print c, y > > > ------------------------------------------------------------------------------- > > > > > > It is a great idea, but I found some problems. I want each individual array of y. However, these two codes prodce accumulated array such as [1,2,3], [1,2,3,4,5,6], [1,2,3,4,5,6,7,8,9] and so on. I have tried to initialize for loop for each time to produce array. This effort has not been very successful. > > > Do you guys have any idea? I will really appreciate ant help and idea. > > > > Your description is very confusing. But i don't see why you just don't > > just set b=[] inside the outer loop, rather than doing it at the begin > > of the program. > > > > for c in xrange(5, 11): > > b = [] > > for row in data: > > b.append(row[c]) > > > > > > > > -- > > > > DaveA Hi Dave, I really appreciate your advice. It was really helpful. Isaac From Kene.Meniru at illom.org Wed Jan 2 23:32:33 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Wed, 02 Jan 2013 23:32:33 -0500 Subject: Can't seem to start on this Message-ID: This sounds so simple but being new to python I am finding it hard to get started. I want to create a module which I will call "B". There will be other modules called "C", "D", etc, which will most likely be imported in "B". Then I want the user to import "B" ONLY into another file I will call "A" in which commands such as the following will be entered: snap_size = 10 LinearMark(name) LinearMark.put(name, length, rotation, (x,y,z)) The file "A" allows the user to enter commands that provide global variables as well as to use classes provided in modules "C", "D", etc, in the manner shown in the sample above. For example snap_size is a global setting. LinearMark(name) creates a linear mark of the provided name. LinearMark.put(...) places the LinearMark object using the provided parameters, etc. How can I make this possible? I am guessing I have to instantiate the classes in file "B" but typing LinearMark(name) in file "A" generates an error. Eventually I will provide a gui but I want to separate usage so there is no dependence on the gui to run this application. Please help. From msirenef at lightbird.net Wed Jan 2 23:46:00 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 02 Jan 2013 23:46:00 -0500 Subject: Can't seem to start on this In-Reply-To: References: Message-ID: <50E50D08.201@lightbird.net> On 01/02/2013 11:32 PM, Kene Meniru wrote: > This sounds so simple but being new to python I am finding it hard to get > started. I want to create a module which I will call "B". There will be > other modules called "C", "D", etc, which will most likely be imported in > "B". Then I want the user to import "B" ONLY into another file I will call > "A" in which commands such as the following will be entered: > > snap_size = 10 > LinearMark(name) > LinearMark.put(name, length, rotation, (x,y,z)) > > The file "A" allows the user to enter commands that provide global variables > as well as to use classes provided in modules "C", "D", etc, in the manner > shown in the sample above. For example snap_size is a global setting. > LinearMark(name) creates a linear mark of the provided name. > LinearMark.put(...) places the LinearMark object using the provided > parameters, etc. > > How can I make this possible? I am guessing I have to instantiate the > classes in file "B" but typing LinearMark(name) in file "A" generates an > error. Eventually I will provide a gui but I want to separate usage so there > is no dependence on the gui to run this application. > > Please help. > > Where is snap_size from? Where is LinearMark from? You don't need to instantiate LinearMark in B, do it in A. What error do you get when you instantiate LinearMark in A? Please paste. If LinearMark is imported in from C, you can do: B.py from C import LinearMark A.py from B import LinearMark lmark = LinearMark(name) lmark.put(...) Or do you want to use class method of LinearMark? Since you don't provide any code, it's really hard to tell what you're doing.... HTH, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From Kene.Meniru at illom.org Thu Jan 3 00:32:21 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 00:32:21 -0500 Subject: Can't seem to start on this References: <50E50D08.201@lightbird.net> Message-ID: Mitya Sirenef wrote: > > Where is snap_size from? Where is LinearMark from? You don't need to > instantiate LinearMark in B, do it in A. > I want to hide as much of the python syntax from the file "A" so the user just concentrates on using the classes as illustrated. snap_size is a global setting. LinearMark is a class in module "C" described as LMark but with the interface class as LinearMark in "B". > What error do you get when you instantiate LinearMark in A? Please > paste. > I am no longer getting errors. Am able to use the interface class described in "B" as follows: class Trogg(object): """ """ def __init__(self, ogle1, ogle2): """ """ self.ogle1 = ogle1 self.ogle2 = ogle2 print ogle1 print ogle2 In "A" I have the following: from buildes import Trogg Trogg("froken", "groky") I now get the proper output from running "A" which is: froken groky I guess if I save the instantiation of each LinearMark in "B" using perhaps a dictionary, I will be able to create as many as I want in "A" this way? > If LinearMark is imported in from C, you can do: > > B.py > from C import LinearMark > > A.py > from B import LinearMark > > lmark = LinearMark(name) > lmark.put(...) > > Or do you want to use class method of LinearMark? > > Since you don't provide any code, it's really hard to tell what you're > doing.... > > HTH, -m > Sorry, my problem is not so clear. I hope the information I have provided above will help you understand more. Thanks. From msirenef at lightbird.net Thu Jan 3 00:49:33 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Thu, 03 Jan 2013 00:49:33 -0500 Subject: Can't seem to start on this In-Reply-To: References: <50E50D08.201@lightbird.net> Message-ID: <50E51BED.1030008@lightbird.net> On 01/03/2013 12:32 AM, Kene Meniru wrote: > Mitya Sirenef wrote: > > >> >> Where is snap_size from? Where is LinearMark from? You don't need to >> instantiate LinearMark in B, do it in A. >> > > I want to hide as much of the python syntax from the file "A" so the user > just concentrates on using the classes as illustrated. snap_size is a global > setting. LinearMark is a class in module "C" described as LMark but with the > interface class as LinearMark in "B". Well, that might be ok depending on what you need the instances to do. Often instantiation provides some kind of customization that makes instance different from other instances. If you do that for your users, they won't be able to customize their instances, unless you provide a separate 'initialize' method, but then it's just as much work for the users to use that method as compared to passing args on instantiation. So, how many instances do you want to make.. what kind of different functionality / properties they will have? - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From Kene.Meniru at illom.org Thu Jan 3 07:53:08 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 07:53:08 -0500 Subject: Can't seem to start on this References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> Message-ID: Mitya Sirenef wrote: > So, how many instances do you want to make.. what kind of different > functionality / properties they will have? > > - mitya > I am porting a modeling system I created using POV-Ray scene description language available at sourceforge at http://sourceforge.net/projects/kobldes/ The user can create as many marks as possible (limited by memory available). The difference between each mark are the parameters provided i.e. name, length, and position in the scene. If the user wishes to customize part of the program they must update the classes or create new ones before using it in the scene. File "A" in my previous illustrations can be considered the scene file. From msirenef at lightbird.net Thu Jan 3 13:12:17 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Thu, 03 Jan 2013 13:12:17 -0500 Subject: Can't seem to start on this In-Reply-To: References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> Message-ID: <50E5CA01.3090200@lightbird.net> On 01/03/2013 07:53 AM, Kene Meniru wrote: > Mitya Sirenef wrote: > > >> So, how many instances do you want to make.. what kind of different >> functionality / properties they will have? >> >> - mitya >> > > I am porting a modeling system I created using POV-Ray scene description > language available at sourceforge at > http://sourceforge.net/projects/kobldes/ > > The user can create as many marks as possible (limited by memory available). > The difference between each mark are the parameters provided i.e. name, > length, and position in the scene. If the user wishes to customize part of > the program they must update the classes or create new ones before using it > in the scene. File "A" in my previous illustrations can be considered the > scene file. > > I'm not familiar with POV-Ray. I want to note that with python standard style, class names look like this: ClassName, instances look like this: instance_name; it sounds like you want LMark to be an instance? Or you want instances in A to use class naming style? Second, is the LMark instance only used to perform one set of actions? If that's the case, you can have users instantiate it in A and the __init__ method will do the set of actions you need -- this will be just as easy for the user as the alternative. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From Kene.Meniru at illom.org Thu Jan 3 14:30:13 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 14:30:13 -0500 Subject: Can't seem to start on this References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> <50E5CA01.3090200@lightbird.net> Message-ID: Mitya Sirenef wrote: > > I'm not familiar with POV-Ray. I want to note that with python standard > style, class names look like this: ClassName, instances look like this: > instance_name; it sounds like you want LMark to be an instance? Or you > want instances in A to use class naming style? > Think of "A" as an extension of the user interface. I want to make the user's life as easy as possible and in this case, part of that is to write as few text as possible. Using the abbreviated LMark is laziness on my part. I wanted to differentiate the boundary class LinearMark, which the user will type in "A" from the entity class LMark which will have the actual data about a linear mark object. LMark is actually called LinearMarkData. > Second, is the LMark instance only used to perform one set of actions? > If that's the case, you can have users instantiate it in A and the > __init__ method will do the set of actions you need -- this will be just > as easy for the user as the alternative. > > -m > So far this is working for me. I am not sure if you mean something different. I have a command in "A" like: Site("New Site", borderNum) # Creates a building site object in "B" In "B", the Site class (which is a subclass of the main class that coordinates the creation of the entire building) receives this call, processes the parameters with any required calculations and calls another class called SiteData (from module "C") which generates the object called "New Site" with the number of boundaries provided. Site then stores SiteData in a dictionary provided in its super class. The super class coordinates the creation of the entire building so all objects can interact with the properties of the objects in the dictionary (of building components). So in effect no instantiation is performed in "A". The user calls classes in "B" with the appropriate parameters to create the building components which are then created and stored for later access by other components. -- Kene :::::::::::::::::: KeMeniru at gmail.com From msirenef at lightbird.net Thu Jan 3 17:53:57 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Thu, 03 Jan 2013 17:53:57 -0500 Subject: Can't seem to start on this In-Reply-To: References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> <50E5CA01.3090200@lightbird.net> Message-ID: <50E60C05.5060506@lightbird.net> On 01/03/2013 02:30 PM, Kene Meniru wrote: > Mitya Sirenef wrote: > >> >> I'm not familiar with POV-Ray. I want to note that with python standard >> style, class names look like this: ClassName, instances look like this: >> instance_name; it sounds like you want LMark to be an instance? Or you >> want instances in A to use class naming style? >> > > Think of "A" as an extension of the user interface. I want to make the > user's life as easy as possible and in this case, part of that is to write > as few text as possible. Using the abbreviated LMark is laziness on my part. > I wanted to differentiate the boundary class LinearMark, which the user will > type in "A" from the entity class LMark which will have the actual data > about a linear mark object. LMark is actually called LinearMarkData. > >> Second, is the LMark instance only used to perform one set of actions? >> If that's the case, you can have users instantiate it in A and the >> __init__ method will do the set of actions you need -- this will be just >> as easy for the user as the alternative. >> >> -m >> > > So far this is working for me. I am not sure if you mean something > different. I have a command in "A" like: > > Site("New Site", borderNum) # Creates a building site object in "B" > > In "B", the Site class (which is a subclass of the main class that > coordinates the creation of the entire building) receives this call, > processes the parameters with any required calculations and calls another > class called SiteData (from module "C") which generates the object called > "New Site" with the number of boundaries provided. Site then stores SiteData > in a dictionary provided in its super class. The super class coordinates the > creation of the entire building so all objects can interact with the > properties of the objects in the dictionary (of building components). > > So in effect no instantiation is performed in "A". The user calls classes in > "B" with the appropriate parameters to create the building components which > are then created and stored for later access by other components. > Ok but if the user creates two sites, how does he then manipulate them, if you are not binding instances in A? (e.g. you are not doing site1 = Site("New Site")). If the user only ever needs one site, that's fine. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From Kene.Meniru at illom.org Thu Jan 3 18:48:27 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 18:48:27 -0500 Subject: Can't seem to start on this References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> <50E5CA01.3090200@lightbird.net> <50E60C05.5060506@lightbird.net> Message-ID: Mitya Sirenef wrote: > > Ok but if the user creates two sites, how does he then manipulate them, > if you are not binding instances in A? (e.g. you are not doing site1 = > Site("New Site")). > > If the user only ever needs one site, that's fine. > > -m > There can only be one site for each building(s) so the super object that coordinates the creation of the entire building, will check and deal with this situation. This is where the building knowledge kicks in and is part of why I am designing it this way. That is with an overall coordinator that has the knowledge of all objects being created and provides the means for them to communicate with each other. So onces there is a site object in the dictionary, an attempt to add a new one will be caught and an error reported to the user. -- Kene :::::::::::::::::: KeMeniru at gmail.com From Kene.Meniru at illom.org Thu Jan 3 19:08:57 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 19:08:57 -0500 Subject: Can't seem to start on this References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> <50E5CA01.3090200@lightbird.net> <50E60C05.5060506@lightbird.net> Message-ID: Mitya Sirenef wrote: > Ok but if the user creates two sites, how does he then manipulate them, > if you are not binding instances in A? (e.g. you are not doing site1 = > Site("New Site")). > > If the user only ever needs one site, that's fine. > > -m In case of situations where the user needs to manipulate an existing component like a side (wall) for a Space, this will be done using the name of the component to find it in the dictionary. So for example if user enters: LinearSide.put("Dining", (x,y,z)) # moves 'Dining' to x,y,z location The put function of the LinearSide boundary class finds "Dining" (which is an entity class called LinearSideData) in the dictionary and then allows this LinearSideData class to calculate its new location using the x,y,z values provided. -- Kene :::::::::::::::::: KeMeniru at gmail.com From msirenef at lightbird.net Thu Jan 3 19:35:13 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Thu, 03 Jan 2013 19:35:13 -0500 Subject: Can't seem to start on this In-Reply-To: References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> <50E5CA01.3090200@lightbird.net> <50E60C05.5060506@lightbird.net> Message-ID: <50E623C1.7030305@lightbird.net> On 01/03/2013 07:08 PM, Kene Meniru wrote: > LinearSide.put("Dining", (x,y,z)) # moves 'Dining' to x,y,z location > > The put function of the LinearSide boundary class finds "Dining" (which is > an entity class called LinearSideData) in the dictionary and then allows > this LinearSideData class to calculate its new location using the x,y,z > values provided. That's what I thought, just wanted to confirm. However, if your objective to make it as easy for the user as possible, is it not easier to bind dining to a name and then do this?: dining.move(x, y, z) -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From Kene.Meniru at illom.org Thu Jan 3 19:43:34 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 19:43:34 -0500 Subject: Can't seem to start on this References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> <50E5CA01.3090200@lightbird.net> <50E60C05.5060506@lightbird.net> <50E623C1.7030305@lightbird.net> Message-ID: Mitya Sirenef wrote: > That's what I thought, just wanted to confirm. > > However, if your objective to make it as easy for the user as possible, > is it not easier to bind dining to a name and then do this?: > > dining.move(x, y, z) > Absolutely. I just found that out after replying to your comment! It actually decreases typing. Also discovered the module Logging. Interesting using python indeed :-) -- Kene :::::::::::::::::: KeMeniru at gmail.com From msirenef at lightbird.net Thu Jan 3 20:05:34 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Thu, 03 Jan 2013 20:05:34 -0500 Subject: Can't seem to start on this In-Reply-To: References: <50E50D08.201@lightbird.net> <50E51BED.1030008@lightbird.net> <50E5CA01.3090200@lightbird.net> <50E60C05.5060506@lightbird.net> <50E623C1.7030305@lightbird.net> Message-ID: <50E62ADE.8010104@lightbird.net> On 01/03/2013 07:43 PM, Kene Meniru wrote: > Mitya Sirenef wrote: > >> That's what I thought, just wanted to confirm. >> >> However, if your objective to make it as easy for the user as possible, >> is it not easier to bind dining to a name and then do this?: >> >> dining.move(x, y, z) >> > Absolutely. I just found that out after replying to your comment! It > actually decreases typing. Also discovered the module Logging. Interesting > using python indeed :-) > I agree -- Python is really nice, I'm glad you seem to be enjoying it! -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From darcy at druid.net Thu Jan 3 08:20:31 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 3 Jan 2013 08:20:31 -0500 Subject: Can't seem to start on this In-Reply-To: References: Message-ID: <20130103082031.73a5b842@dilbert> On Wed, 02 Jan 2013 23:32:33 -0500 Kene Meniru wrote: > This sounds so simple but being new to python I am finding it hard to > get started. I want to create a module which I will call "B". There > will be other modules called "C", "D", etc, which will most likely be > imported in "B". Then I want the user to import "B" ONLY into another > file I will call "A" in which commands such as the following will be > entered: > > snap_size = 10 > LinearMark(name) > LinearMark.put(name, length, rotation, (x,y,z)) Sounds messy. > The file "A" allows the user to enter commands that provide global > variables as well as to use classes provided in modules "C", "D", OK, "global variables" is the clue that you need to rethink this. Try to stay away from global variables as much as possible except for maybe some simple setup variables within the same file. Consider something like this instead. In file B: class TopClass(object): def __init__(self, snap_size, var1 = None, var2 = None): self.snap_size = snap_size self.var1 = var1 if var2 is None: self.var2 = 7 self.var3 = "GO" self.var4 = "Static string" *add class methods here* In file A: class MyClass(TopClass): def __init__(self, var1): TopClass.__init__(self, 10, var1, 8) self.var3 = "STOP" x = MyClass(42) x.var4 = "Not so static after all" In this (untested) example you create your top class in B and then subclass it in A. Notice the different way of setting variables here. In MyClass we hard code snap_size to 10, we set var1 from the argument when we instantiate it, var2 is hard coded to 8 but could be left out if we wanted the default of 7, var3 is overwritten in MyClass and var4 is changed after the class is instantiated. Hope this gives you some ideas. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From Kene.Meniru at illom.org Thu Jan 3 09:06:55 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 09:06:55 -0500 Subject: Can't seem to start on this References: <20130103082031.73a5b842@dilbert> Message-ID: D'Arcy J.M. Cain wrote: > > OK, "global variables" is the clue that you need to rethink this. Try > to stay away from global variables as much as possible except for maybe > some simple setup variables within the same file. Consider something > like this instead. > The global variable is not part of the LinearMark object. It will be used by ALL objects created. I understand the uneasiness with this so maybe I will make it a function so it will be set with something like: SnapSize(num) > In file B: > > class TopClass(object): > def __init__(self, snap_size, var1 = None, var2 = None): > self.snap_size = snap_size > self.var1 = var1 > if var2 is None: self.var2 = 7 > self.var3 = "GO" > self.var4 = "Static string" > > *add class methods here* > > In file A: > > class MyClass(TopClass): > def __init__(self, var1): > TopClass.__init__(self, 10, var1, 8) > self.var3 = "STOP" > > x = MyClass(42) > x.var4 = "Not so static after all" > As I mentioned, the file "A" can be considered a scene file. I do not want the user to have to create classes there. I apologize for the lack of code. I will soon have some python code so my future questions will have some examples. Thanks for the comments. From darcy at druid.net Thu Jan 3 09:30:15 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 3 Jan 2013 09:30:15 -0500 Subject: Can't seem to start on this In-Reply-To: References: <20130103082031.73a5b842@dilbert> Message-ID: <20130103093015.2b46908f@dilbert> On Thu, 03 Jan 2013 09:06:55 -0500 Kene Meniru wrote: > > OK, "global variables" is the clue that you need to rethink this. > > Try to stay away from global variables as much as possible except > > for maybe some simple setup variables within the same file. > > Consider something like this instead. > > > > The global variable is not part of the LinearMark object. It will be > used by ALL objects created. I understand the uneasiness with this so > maybe I will make it a function so it will be set with something like: Applying to all objects in your file A is not an issue. See below. > SnapSize(num) That doesn't make it any less global. > As I mentioned, the file "A" can be considered a scene file. I do not I don't know what a "scene" file is. > want the user to have to create classes there. I apologize for the But you expect them to write Python code? Classes are a very powerful part of Python and if super classes are written well they can be very simple to write. Perhaps you found my examples too complicated. That was so I could illustrate a number of methods. I wouldn't expect you to use all of them in your code. Here is a simpler example that may meet your requirements. File B: class TopClass(object): def __init__(self, snap_size): self.snap_size = snap_size def put(self, ... In file A: class MyClass(TopClass): def __init__(self): TopClass.__init__(self, 10) x = MyClass() x.put(... Now you have a new class where every instance uses a snap size of 10. Notice that this class in what you call the user's code is only three lines. That's pretty simple for your "user." If you think that that is too complicated still then maybe the user shouldn't be writing any Python code and instead look at the various ways of parsing configuration files which they can write. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From Kene.Meniru at illom.org Thu Jan 3 09:59:04 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 09:59:04 -0500 Subject: Can't seem to start on this References: <20130103082031.73a5b842@dilbert> <20130103093015.2b46908f@dilbert> Message-ID: D'Arcy J.M. Cain wrote: >> As I mentioned, the file "A" can be considered a scene file. I do not > > I don't know what a "scene" file is. > A scene file is applicable to programs like POV-Ray at www.povray.org. It is a file that is used to describe 3D objects such as box, sphere, polygon, etc. My program specializes this situation and allows the user to describe building components to be used in constructing houses. > But you expect them to write Python code? ... Actually, I specifically do not want this. This is why in another thread (titled "Parsing files in python") I was proposing developing a new language with python-PLY. After the comments here and in the PLY group, I decided it would be easier to just port the application I have now before thinking in this direction so that I am clear in my mind what I want to do with python. > ... Here is a simpler example that may > meet your requirements. > > File B: > > class TopClass(object): > def __init__(self, snap_size): > self.snap_size = snap_size > > def put(self, ... > I understand where you are coming from and this is already being done but in modules "C", "D", etc, following my previous description. Module "B" will have the boundary classes which the user uses to interact with these other modules ("C", "D", etc.). > In file A: > > class MyClass(TopClass): > def __init__(self): > TopClass.__init__(self, 10) > > x = MyClass() > x.put(... > > Now you have a new class where every instance uses a snap size of 10. > Notice that this class in what you call the user's code is only three > lines. That's pretty simple for your "user." > If you can imagine creating hundreds of building components for each building described in the "A", then you will understand that for any user (who just wants to make buildings and not program), it is not desirable to use this method. Think of LaTeX and using simple symbols to tell the computer how to lay out text. I want to do the same for architecture/building engineering. > If you think that that is too complicated still then maybe the user > shouldn't be writing any Python code and instead look at the various > ways of parsing configuration files which they can write. > Yes, I guess that is the main thing. I do not want users to have to write python code unless they are interested in customizing how the program behaves or perhaps a building component. In that case any of the other modules can be updated instead of "A". Actually "A" will not be part of the packaged program. From darcy at druid.net Thu Jan 3 12:16:32 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 3 Jan 2013 12:16:32 -0500 Subject: Can't seem to start on this In-Reply-To: References: <20130103082031.73a5b842@dilbert> <20130103093015.2b46908f@dilbert> Message-ID: <20130103121632.6af0a3e4@dilbert> On Thu, 03 Jan 2013 09:59:04 -0500 Kene Meniru wrote: > Yes, I guess that is the main thing. I do not want users to have to > write python code unless they are interested in customizing how the That works too. It's just that you had users writing Python code but assumed that a three line subclass was beyond them. Not requiring them to write any Python code is a better option than the first one (global variables) that you proposed. That's all I am trying to say. > program behaves or perhaps a building component. In that case any of > the other modules can be updated instead of "A". Actually "A" will > not be part of the packaged program. Or "A" becomes the script that parses the config file and runs the other code. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From Kene.Meniru at illom.org Thu Jan 3 12:36:52 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 03 Jan 2013 12:36:52 -0500 Subject: Can't seem to start on this References: <20130103082031.73a5b842@dilbert> <20130103093015.2b46908f@dilbert> <20130103121632.6af0a3e4@dilbert> Message-ID: D'Arcy J.M. Cain wrote: > That works too. It's just that you had users writing Python code but > assumed that a three line subclass was beyond them. Not requiring them > to write any Python code is a better option than the first one (global > variables) that you proposed. That's all I am trying to say. > I understand. >> program behaves or perhaps a building component. In that case any of >> the other modules can be updated instead of "A". Actually "A" will >> not be part of the packaged program. > > Or "A" becomes the script that parses the config file and runs the > other code. > Yes. To be more precise, later I will create "A_Interface" to provide the user with an interface for creating the contents of "A". "A_Interface" will then parse "A", calling "B" as required to create the artifact. I had wanted to jump into "A_Interface" using something like urwid or PyQt but it makes sense to work with "A" directly for now. Thanks for taking the time to understand. From ssaratha60 at gmail.com Thu Jan 3 03:00:27 2013 From: ssaratha60 at gmail.com (ssaratha60 at gmail.com) Date: Thu, 3 Jan 2013 00:00:27 -0800 (PST) Subject: TAMIL SEXY VIDEOS AND ADDS Message-ID: <135c796d-1f43-4e29-8ad2-c2b805550cbd@googlegroups.com> LIVE SEX CHAT COME SEXY BOYS AND GIRLS in Sex lovers of LAHORE Sex with Local SEXY hot Girls/Women LIVE CHAT http://tamilsexyvidoes.blogspot.in/ Hi Friends This My Orkut Profile, I Request My All Friends, SEX CHAT Interest Girls and Boys My Amigos Profile Join Its Free http://tamilsexyvidoes.blogspot.in/ If u join as male u have to pay, so join as female its free. http://tamilsexyvidoes.blogspot.in/ From bahamutzero8825 at gmail.com Thu Jan 3 04:27:42 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 03 Jan 2013 03:27:42 -0600 Subject: Important questions about __future__ Message-ID: <50E54F0E.1030601@gmail.com> Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP 401, using print as a statement still raises a SyntaxError. Where is 'from __future__ import braces' implemented in CPython (it's not in __future__.py)? -- CPython 3.3.0 | Windows NT 6.2.9200.16461 From maniandram01 at gmail.com Thu Jan 3 04:43:44 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 3 Jan 2013 01:43:44 -0800 (PST) Subject: Important questions about __future__ In-Reply-To: References: Message-ID: <10b6d5fe-ad73-4564-92f0-0f29d83f0d30@googlegroups.com> On Thursday, 3 January 2013 14:57:42 UTC+5:30, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > > 401, using print as a statement still raises a SyntaxError. > > Where is 'from __future__ import braces' implemented in CPython (it's > > not in __future__.py)? > > -- > > CPython 3.3.0 | Windows NT 6.2.9200.16461 barry_as_FLUFL is probably simply a joke future statement (Barry is at the head of Python Development and would probably replace Guido in the future) (Guido is typically only active on python-ideas). from __future__ import braces is the Future statement (see http://docs.python.org/3/library/__future__.html) import __future__ simply imports __future__.py as a plain, ordinary module From maniandram01 at gmail.com Thu Jan 3 04:45:00 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 3 Jan 2013 01:45:00 -0800 (PST) Subject: Important questions about __future__ In-Reply-To: <10b6d5fe-ad73-4564-92f0-0f29d83f0d30@googlegroups.com> References: <10b6d5fe-ad73-4564-92f0-0f29d83f0d30@googlegroups.com> Message-ID: <3d168777-fbfc-412f-ad63-822da175b730@googlegroups.com> On Thursday, 3 January 2013 15:13:44 UTC+5:30, Ramchandra Apte wrote: > On Thursday, 3 January 2013 14:57:42 UTC+5:30, Andrew Berg wrote: > > > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > > > > > > 401, using print as a statement still raises a SyntaxError. > > > > > > Where is 'from __future__ import braces' implemented in CPython (it's > > > > > > not in __future__.py)? > > > > > > -- > > > > > > CPython 3.3.0 | Windows NT 6.2.9200.16461 > > barry_as_FLUFL is probably simply a joke future statement (Barry is at the head of Python Development and would probably replace Guido in the future) (Guido is typically only active on python-ideas). > > from __future__ import braces is the Future statement (see http://docs.python.org/3/library/__future__.html) > > import __future__ simply imports __future__.py as a plain, ordinary module Link should have been http://docs.python.org/3/reference/simple_stmts.html#future --- Happy, new, joyful, etc new boring year. From maniandram01 at gmail.com Thu Jan 3 04:45:00 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 3 Jan 2013 01:45:00 -0800 (PST) Subject: Important questions about __future__ In-Reply-To: <10b6d5fe-ad73-4564-92f0-0f29d83f0d30@googlegroups.com> References: <10b6d5fe-ad73-4564-92f0-0f29d83f0d30@googlegroups.com> Message-ID: <3d168777-fbfc-412f-ad63-822da175b730@googlegroups.com> On Thursday, 3 January 2013 15:13:44 UTC+5:30, Ramchandra Apte wrote: > On Thursday, 3 January 2013 14:57:42 UTC+5:30, Andrew Berg wrote: > > > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > > > > > > 401, using print as a statement still raises a SyntaxError. > > > > > > Where is 'from __future__ import braces' implemented in CPython (it's > > > > > > not in __future__.py)? > > > > > > -- > > > > > > CPython 3.3.0 | Windows NT 6.2.9200.16461 > > barry_as_FLUFL is probably simply a joke future statement (Barry is at the head of Python Development and would probably replace Guido in the future) (Guido is typically only active on python-ideas). > > from __future__ import braces is the Future statement (see http://docs.python.org/3/library/__future__.html) > > import __future__ simply imports __future__.py as a plain, ordinary module Link should have been http://docs.python.org/3/reference/simple_stmts.html#future --- Happy, new, joyful, etc new boring year. From maniandram01 at gmail.com Thu Jan 3 04:43:44 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 3 Jan 2013 01:43:44 -0800 (PST) Subject: Important questions about __future__ In-Reply-To: References: Message-ID: <10b6d5fe-ad73-4564-92f0-0f29d83f0d30@googlegroups.com> On Thursday, 3 January 2013 14:57:42 UTC+5:30, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > > 401, using print as a statement still raises a SyntaxError. > > Where is 'from __future__ import braces' implemented in CPython (it's > > not in __future__.py)? > > -- > > CPython 3.3.0 | Windows NT 6.2.9200.16461 barry_as_FLUFL is probably simply a joke future statement (Barry is at the head of Python Development and would probably replace Guido in the future) (Guido is typically only active on python-ideas). from __future__ import braces is the Future statement (see http://docs.python.org/3/library/__future__.html) import __future__ simply imports __future__.py as a plain, ordinary module From steve+comp.lang.python at pearwood.info Thu Jan 3 05:20:47 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Jan 2013 10:20:47 GMT Subject: Important questions about __future__ References: Message-ID: <50e55b7f$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 Jan 2013 03:27:42 -0600, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Yes, it re-enables <> and disables != as not equal: py> sys.version '3.3.0rc3 (default, Sep 27 2012, 18:44:58) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]' py> 1 <> 2 File "", line 1 1 <> 2 ^ SyntaxError: invalid syntax py> from __future__ import barry_as_FLUFL py> 1 <> 2 True > Where is > 'from __future__ import braces' implemented in CPython (it's not in > __future__.py)? It's defined in the C source code for the CPython compiler. Look in future.c. http://hg.python.org/cpython/file/944e86223d1f/Python/future.c -- Steven From ian.g.kelly at gmail.com Thu Jan 3 05:02:16 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Jan 2013 03:02:16 -0700 Subject: Important questions about __future__ In-Reply-To: <50E54F0E.1030601@gmail.com> References: <50E54F0E.1030601@gmail.com> Message-ID: On Thu, Jan 3, 2013 at 2:27 AM, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > 401, using print as a statement still raises a SyntaxError. I think it only replaces the != operator with <>. > Where is 'from __future__ import braces' implemented in CPython (it's > not in __future__.py)? Python/future.c From avrajit.chatterjee at gmail.com Thu Jan 3 07:01:42 2013 From: avrajit.chatterjee at gmail.com (Avrajit Chatterjee) Date: Thu, 3 Jan 2013 04:01:42 -0800 (PST) Subject: Python printout In-Reply-To: <4b917927-81e5-4bab-b29f-f95e83757130@googlegroups.com> References: <4b917927-81e5-4bab-b29f-f95e83757130@googlegroups.com> Message-ID: <9613fac9-21d0-4398-82a0-d4dcee60c311@googlegroups.com> On Tuesday, 27 November 2012 15:00:29 UTC+5:30, Avrajit Chatterjee wrote: > I have multiple list and want to invoke a single prinout which will give a print preview of all list in Grid format in a different pages. I have tried wx.lib.printout.PrintTable but it takes only one table at a time. Any clues how to achieve this? Didnt find any good way of doing it , hence printed all in a excel in background and used VBS win32 lib to print the excel sheet by selecting the print area. From bob.blanchett at gmail.com Thu Jan 3 07:17:26 2013 From: bob.blanchett at gmail.com (bob.blanchett) Date: Thu, 3 Jan 2013 04:17:26 -0800 (PST) Subject: Creating interactive command-line Python app? In-Reply-To: <1135168477.969110.290850@f14g2000cwb.googlegroups.com> References: <1135168477.969110.290850@f14g2000cwb.googlegroups.com> Message-ID: <198fde16-eb65-4425-9a81-147cdbd7fb07@googlegroups.com> This is exactly what you want: https://cliff.readthedocs.org/en/latest/ Bob/Julius Flywheel On Wednesday, December 21, 2005 11:34:38 PM UTC+11, planetthoughtful wrote: > Hello All, > > Newbie to Python, and I'm wondering if it's possible to create a Python > console app that prompts for further input on the command line when run > (in Windows XP, if that's important)? > > I've tried Googling, but the results are overwhelmingly about > interactive Python environments (IPython etc etc), instead of how to > achieve prompting at the command line when running your own Python app. > > Any help appreciated! > > Much warmth, > > planetthoughtful From python.list at tim.thechases.com Thu Jan 3 09:24:20 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 03 Jan 2013 08:24:20 -0600 Subject: Creating interactive command-line Python app? In-Reply-To: <198fde16-eb65-4425-9a81-147cdbd7fb07@googlegroups.com> References: <1135168477.969110.290850@f14g2000cwb.googlegroups.com> <198fde16-eb65-4425-9a81-147cdbd7fb07@googlegroups.com> Message-ID: <50E59494.7030404@tim.thechases.com> (original post from planetthoughtful didn't seem to arrive here, so replying to Bob's reply) > Newbie to Python, and I'm wondering if it's possible to create a > Python console app that prompts for further input on the command > line when run (in Windows XP, if that's important)? While Bob's suggestion of "cliff" sounds interesting, Python also offers the "cmd" module[1] in the standard library which does most of what I've needed in the past. If you've got the readline library available, it also supports autocompletion and command-line history which is a nice bonus. -tkc [1] http://docs.python.org/2/library/cmd.html # py2.x http://docs.python.org/3/library/cmd.html # py3.x Docs should be about the same From d at davea.name Thu Jan 3 09:41:31 2013 From: d at davea.name (Dave Angel) Date: Thu, 03 Jan 2013 09:41:31 -0500 Subject: Creating interactive command-line Python app? In-Reply-To: <50E59494.7030404@tim.thechases.com> References: <1135168477.969110.290850@f14g2000cwb.googlegroups.com> <198fde16-eb65-4425-9a81-147cdbd7fb07@googlegroups.com> <50E59494.7030404@tim.thechases.com> Message-ID: <50E5989B.1040805@davea.name> On 01/03/2013 09:24 AM, Tim Chase wrote: > (original post from planetthoughtful didn't seem to arrive here, so > replying to Bob's reply) > >> Newbie to Python, and I'm wondering if it's possible to create a >> Python console app that prompts for further input on the command >> line when run (in Windows XP, if that's important)? > > While Bob's suggestion of "cliff" sounds interesting, Python also > offers the "cmd" module[1] in the standard library which does most of > what I've needed in the past. If you've got the readline library > available, it also supports autocompletion and command-line history > which is a nice bonus. > > -tkc > > [1] > http://docs.python.org/2/library/cmd.html # py2.x > http://docs.python.org/3/library/cmd.html # py3.x > Docs should be about the same The two replies in 2005 mentioned both raw_input and the cmd module (in case that's what he was implying). They were posted within 90 minutes of the original. http://python.6.n6.nabble.com/Creating-interactive-command-line-Python-app-td910404.html I assume that cliff is much more recent, and Bob wanted to update the thread after 7 years. http://pypi.python.org/pypi/cliff -- DaveA From python.list at tim.thechases.com Thu Jan 3 13:15:12 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 03 Jan 2013 12:15:12 -0600 Subject: Creating interactive command-line Python app? In-Reply-To: <50E5989B.1040805@davea.name> References: <1135168477.969110.290850@f14g2000cwb.googlegroups.com> <198fde16-eb65-4425-9a81-147cdbd7fb07@googlegroups.com> <50E59494.7030404@tim.thechases.com> <50E5989B.1040805@davea.name> Message-ID: <50E5CAB0.2040207@tim.thechases.com> On 01/03/13 08:41, Dave Angel wrote: > The two replies in 2005 mentioned both raw_input and the cmd module (in > case that's what he was implying). They were posted within 90 minutes > of the original. Ah. 2005 would explain why my newsreader has purged them as ancient history :) Thanks for the clarification. -tkc From darcy at PyGreSQL.org Thu Jan 3 09:04:16 2013 From: darcy at PyGreSQL.org (D'Arcy J.M. Cain) Date: Thu, 3 Jan 2013 09:04:16 -0500 Subject: PyGreSQL 4.1 released Message-ID: <20130103090416.57516245@dilbert> ------------------------------- Release of PyGreSQL version 4.1 ------------------------------- It has been a long time coming but PyGreSQL v4.1 has been released. It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. If you are running NetBSD, look in the packages directory under databases. There is also a package in the FreeBSD ports collection which will probably be updated shortly. Please refer to `changelog.txt `_ for things that have changed in this version. Please refer to `readme.txt `_ for general information. This version has been built and unit tested on: - NetBSD - FreeBSD - openSUSE 12.2 - Windows 7 with both MinGW and Visual Studio - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit - Python 2.5, 2.6 and 2.7 32 and 64bit -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org IM:darcy at Vex.Net From walterhurry at lavabit.com Thu Jan 3 10:06:29 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 3 Jan 2013 15:06:29 +0000 (UTC) Subject: PyGreSQL 4.1 released References: Message-ID: On Thu, 03 Jan 2013 09:04:16 -0500, D'Arcy J.M. Cain wrote: > ------------------------------- > Release of PyGreSQL version 4.1 ------------------------------- > > It has been a long time coming but PyGreSQL v4.1 has been released. > > It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. > > If you are running NetBSD, look in the packages directory under > databases. There is also a package in the FreeBSD ports collection which > will probably be updated shortly. > > Please refer to `changelog.txt `_ > for things that have changed in this version. > > Please refer to `readme.txt `_ > for general information. > > This version has been built and unit tested on: > - NetBSD - FreeBSD - openSUSE 12.2 - Windows 7 with both MinGW and > Visual Studio - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit - Python 2.5, > 2.6 and 2.7 32 and 64bit Sounds good. Thanks for your efforts. Does it offer advantages oiver Psycopg2? From darcy at PyGreSQL.org Thu Jan 3 13:07:40 2013 From: darcy at PyGreSQL.org (D'Arcy J.M. Cain) Date: Thu, 3 Jan 2013 13:07:40 -0500 Subject: PyGreSQL 4.1 released In-Reply-To: References: Message-ID: <20130103130740.00bfe45a@dilbert> On Thu, 3 Jan 2013 15:06:29 +0000 (UTC) Walter Hurry wrote: > Sounds good. Thanks for your efforts. I wasn't alone but I accept your thanks on behalf of the team. > Does it offer advantages oiver Psycopg2? Well, it has two interfaces, the DB-API 2.0 and the "Classic" one. The classic one is basically the one PyGreSQL started life as before we had a standard interface. We kept it as it has some advantages over the portable one but offer both. As for other advantages, I prefer to hear those from people not involved with either project. -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org IM:darcy at Vex.Net From walterhurry at lavabit.com Thu Jan 3 15:31:57 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 3 Jan 2013 20:31:57 +0000 (UTC) Subject: PyGreSQL 4.1 released References: Message-ID: On Thu, 03 Jan 2013 13:07:40 -0500, D'Arcy J.M. Cain wrote: > On Thu, 3 Jan 2013 15:06:29 +0000 (UTC) > Walter Hurry wrote: >> Sounds good. Thanks for your efforts. > > I wasn't alone but I accept your thanks on behalf of the team. > >> Does it offer advantages oiver Psycopg2? > 0 > Well, it has two interfaces, the DB-API 2.0 and the "Classic" one. The > classic one is basically the one PyGreSQL started life as before we had > a standard interface. We kept it as it has some advantages over the > portable one but offer both. As for other advantages, I prefer to hear > those from people not involved with either project. 4.1 has just made it into the FreeBSD ports. I'll give it a try (thanks again, to you and your team). From modulok at gmail.com Thu Jan 3 14:52:19 2013 From: modulok at gmail.com (Modulok) Date: Thu, 3 Jan 2013 12:52:19 -0700 Subject: PyGreSQL 4.1 released In-Reply-To: <20130103090416.57516245@dilbert> References: <20130103090416.57516245@dilbert> Message-ID: > ------------------------------- > Release of PyGreSQL version 4.1 > ------------------------------- > > It has been a long time coming but PyGreSQL v4.1 has been released. > > It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. > > If you are running NetBSD, look in the packages directory under > databases. There is also a package in the FreeBSD ports collection > which will probably be updated shortly. > > Please refer to `changelog.txt `_ > for things that have changed in this version. > > Please refer to `readme.txt `_ > for general information. > > This version has been built and unit tested on: > - NetBSD > - FreeBSD > - openSUSE 12.2 > - Windows 7 with both MinGW and Visual Studio > - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit > - Python 2.5, 2.6 and 2.7 32 and 64bit This is good news. The PyGreSQL team is doing a great job! Pass on my congrats :D -Modulok- From michael.poeltl at univie.ac.at Sat Jan 5 07:23:55 2013 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Sat, 5 Jan 2013 13:23:55 +0100 Subject: PyGreSQL 4.1 released In-Reply-To: <20130103090416.57516245@dilbert> References: <20130103090416.57516245@dilbert> Message-ID: <20130105122355.GE1669@terra.cms.at> no python3 support yet? can you tell us when pygresql will be ready for python3? thx Michael * D'Arcy J.M. Cain [2013-01-03 15:05]: > ------------------------------- > Release of PyGreSQL version 4.1 > ------------------------------- > > It has been a long time coming but PyGreSQL v4.1 has been released. > > It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. > > If you are running NetBSD, look in the packages directory under > databases. There is also a package in the FreeBSD ports collection > which will probably be updated shortly. > > Please refer to `changelog.txt `_ > for things that have changed in this version. > > Please refer to `readme.txt `_ > for general information. > > This version has been built and unit tested on: > - NetBSD > - FreeBSD > - openSUSE 12.2 > - Windows 7 with both MinGW and Visual Studio > - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit > - Python 2.5, 2.6 and 2.7 32 and 64bit > > -- > D'Arcy J.M. Cain > PyGreSQL Development Group > http://www.PyGreSQL.org IM:darcy at Vex.Net > -- > http://mail.python.org/mailman/listinfo/python-list -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From darcy at PyGreSQL.org Sat Jan 5 08:44:17 2013 From: darcy at PyGreSQL.org (D'Arcy J.M. Cain) Date: Sat, 5 Jan 2013 08:44:17 -0500 Subject: PyGreSQL 4.1 released In-Reply-To: <20130105122355.GE1669@terra.cms.at> References: <20130103090416.57516245@dilbert> <20130105122355.GE1669@terra.cms.at> Message-ID: <20130105084417.0967faf5@dilbert> On Sat, 5 Jan 2013 13:23:55 +0100 Michael Poeltl wrote: > no python3 support yet? > can you tell us when pygresql will be ready for python3? Hard to say when (we all have day jobs) but it is planned for version 5.0. You can track our milestones at http://trac.vex.net:8000/pgtracker We will probably get version 4.2 released shortly and then branch 5.x and start working on Python 3 support. -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org IM:darcy at Vex.Net From darcy at druid.net Sun Jan 6 21:37:04 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 6 Jan 2013 21:37:04 -0500 Subject: PyGreSQL 4.1 released In-Reply-To: <20130105084417.0967faf5@dilbert> References: <20130103090416.57516245@dilbert> <20130105122355.GE1669@terra.cms.at> <20130105084417.0967faf5@dilbert> Message-ID: <20130106213704.56694f6e@dilbert> On Sat, 5 Jan 2013 08:44:17 -0500 "D'Arcy J.M. Cain" wrote: > We will probably get version 4.2 released shortly and then branch 5.x > and start working on Python 3 support. In fact, we found a few buglets and will be releasing 4.1.1 on Tuesday. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From rmorgan466 at gmail.com Thu Jan 3 09:43:54 2013 From: rmorgan466 at gmail.com (Rita) Date: Thu, 3 Jan 2013 09:43:54 -0500 Subject: building python from source Message-ID: For those building python from source what are some tests you do to make sure the compilation and installation is up to standard. For instance here are some thing I do: Tk functionality sqlite module Python is compiled with shared object (important for wsgi) Proper preloading of python libraries (set the proper -rpath flag for gcc) Any others? The people who manage distributions what do they check with for regression tests? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.walker.jones at gmail.com Thu Jan 3 09:53:00 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Thu, 3 Jan 2013 08:53:00 -0600 Subject: building python from source In-Reply-To: References: Message-ID: Run the unittests. the "test___all___.py" test runner can be found under your python installation directory's lib/python-X.X/test/. *Matt Jones* On Thu, Jan 3, 2013 at 8:43 AM, Rita wrote: > For those building python from source what are some tests you do to make > sure the compilation and installation is up to standard. For instance here > are some thing I do: > Tk functionality > sqlite module > Python is compiled with shared object (important for wsgi) > Proper preloading of python libraries (set the proper -rpath flag for gcc) > > Any others? The people who manage distributions what do they check with > for regression tests? > > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Thu Jan 3 11:35:10 2013 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 03 Jan 2013 16:35:10 +0000 Subject: running multiple django/bottle instances Message-ID: <50E5B33E.4050106@gmail.com> I'm working on a quite complex web app that uses django and bottle (bottle for the API which is also restful). Before I came they started to use a staging server to be able to try out things properly before they get published, but now we would like to have the possibility to see multiple branches at a time. First we thought about multiple servers, but actually since bottle and django can be made to run on different ports, I thought why not running everything on one server on different ports? We also use elasticsearch and couchdb for the data, but these two don't change that much and can just be a single instance. So what would be really great could be staging_server/branch_x staging_server/branch_y and something keeps track of all the various branches tracked, and run or keeps running bottle/django on different ports for the different branches. Is there something in the wonderful python world which I could bend to my needs? I'll probably have to script something myself anyway, but any suggestions is welcome, since I don't have much experience with web stuff.. From andrea.crotti.0 at gmail.com Mon Jan 7 05:26:16 2013 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Mon, 7 Jan 2013 10:26:16 +0000 Subject: running multiple django/bottle instances In-Reply-To: <50EA4424.7020900@gmail.com> References: <50E5B33E.4050106@gmail.com> <50EA4424.7020900@gmail.com> Message-ID: Not really, on the staging server we are using the django/bottle webserver.. Anyway I was thinking that a great possible solution might be to set up something like buildbot to: - checkout all the needed branches - run the various servers for all of them on different ports, where maybe the mapping port-branch is set from somewhere - run all the unit tests for them and make the results available With a similar configuration we would probably be very happy already, anyone doing something similar? 2013/1/7 Michel Kunkler : > As you are certainly running a production server like Apache, your problem > is actually not Python related. > If you want to run your applications on different ports, take a look on e.g. > Apaches virtual host configurations. > http://httpd.apache.org/docs/2.2/vhosts/examples.html > > Am 03.01.2013 17:35, schrieb Andrea Crotti: > >> I'm working on a quite complex web app that uses django and bottle >> (bottle for the API which is also restful). >> >> Before I came they started to use a staging server to be able to try out >> things properly before they get published, but now we would like to have >> the possibility to see multiple branches at a time. >> >> First we thought about multiple servers, but actually since bottle and >> django can be made to run on different ports, I thought why not running >> everything on one server on different ports? >> >> We also use elasticsearch and couchdb for the data, but these two >> don't change that much and can just be a single instance. >> >> So what would be really great could be >> >> staging_server/branch_x >> staging_server/branch_y >> >> and something keeps track of all the various branches tracked, and run >> or keeps running bottle/django on different ports for the different >> branches. >> >> Is there something in the wonderful python world which I could bend to >> my needs? >> >> I'll probably have to script something myself anyway, but any >> suggestions is welcome, since I don't have much experience with web >> stuff.. > > From rgacote at appropriatesolutions.com Thu Jan 3 13:53:44 2013 From: rgacote at appropriatesolutions.com (Ray Cote) Date: Thu, 3 Jan 2013 13:53:44 -0500 (EST) Subject: Missing something obvious with python-requests In-Reply-To: <857538.2991.1357238893647.JavaMail.rgacote@Ray-iMac-2011.local> Message-ID: <17769250.2995.1357239221470.JavaMail.rgacote@Ray-iMac-2011.local> Hello List: I seem to be missing something obvious in terms of using proxies with the requests module. I'm using requests 1.4 and Python 2.7. Have tried this on Centos 6 and Windows XP. Here's the sample code, right out of the manual: import requests proxies = { 'https': '192.168.24.25:8443', 'http': '192.168.24.25:8443', } a = requests.get('http://google.com/', proxies=proxies) When I look at the proxy log, I see a GET being performed -- when it should be a CONNECT. Does not matter if I try to get http or https google.com. Clearly I'm missing something fundamental here. But after two days of fiddling with the code and tracing through requests I'm still unclear as to why requests is not using the proxy information. Any help (or slap on the side of the head) appreciated. Thanks --Ray From barry at barrys-emacs.org Thu Jan 3 17:48:52 2013 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 3 Jan 2013 22:48:52 +0000 Subject: Missing something obvious with python-requests In-Reply-To: <17769250.2995.1357239221470.JavaMail.rgacote@Ray-iMac-2011.local> References: <17769250.2995.1357239221470.JavaMail.rgacote@Ray-iMac-2011.local> Message-ID: The shipped python library code does not work. See http://bugs.python.org/issue7291 for patches. Barry On 3 Jan 2013, at 18:53, Ray Cote wrote: > Hello List: > > I seem to be missing something obvious in terms of using proxies with the requests module. > I'm using requests 1.4 and Python 2.7. Have tried this on Centos 6 and Windows XP. > > Here's the sample code, right out of the manual: > > import requests > > proxies = { > 'https': '192.168.24.25:8443', > 'http': '192.168.24.25:8443', } > > a = requests.get('http://google.com/', proxies=proxies) > > > When I look at the proxy log, I see a GET being performed -- when it should be a CONNECT. > Does not matter if I try to get http or https google.com. > Clearly I'm missing something fundamental here. > But after two days of fiddling with the code and tracing through requests I'm still unclear as to why requests is not using the proxy information. > > Any help (or slap on the side of the head) appreciated. > Thanks > --Ray > > -- > http://mail.python.org/mailman/listinfo/python-list > From rgacote at appropriatesolutions.com Thu Jan 3 21:12:45 2013 From: rgacote at appropriatesolutions.com (Ray Cote) Date: Thu, 3 Jan 2013 21:12:45 -0500 (EST) Subject: Missing something obvious with python-requests In-Reply-To: Message-ID: <10009199.318.1357265564219.JavaMail.rgacote@Rays-Macbook.local> Thank you. --Ray ----- Original Message ----- From: "Barry Scott" To: "Ray Cote" Cc: python-list at python.org Sent: Thursday, January 3, 2013 5:48:52 PM Subject: Re: Missing something obvious with python-requests The shipped python library code does not work. See http://bugs.python.org/issue7291 for patches. Barry On 3 Jan 2013, at 18:53, Ray Cote wrote: > Hello List: > > I seem to be missing something obvious in terms of using proxies with the requests module. > I'm using requests 1.4 and Python 2.7. Have tried this on Centos 6 and Windows XP. > > Here's the sample code, right out of the manual: > > import requests > > proxies = { > 'https': '192.168.24.25:8443', > 'http': '192.168.24.25:8443', } > > a = requests.get('http://google.com/', proxies=proxies) > > > When I look at the proxy log, I see a GET being performed -- when it should be a CONNECT. > Does not matter if I try to get http or https google.com. > Clearly I'm missing something fundamental here. > But after two days of fiddling with the code and tracing through requests I'm still unclear as to why requests is not using the proxy information. > > Any help (or slap on the side of the head) appreciated. > Thanks > --Ray > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ray Cote, President Appropriate Solutions, Inc. We Build Software 603.924.6079 From rosuav at gmail.com Thu Jan 3 21:56:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Jan 2013 13:56:47 +1100 Subject: Missing something obvious with python-requests In-Reply-To: <17769250.2995.1357239221470.JavaMail.rgacote@Ray-iMac-2011.local> References: <857538.2991.1357238893647.JavaMail.rgacote@Ray-iMac-2011.local> <17769250.2995.1357239221470.JavaMail.rgacote@Ray-iMac-2011.local> Message-ID: On Fri, Jan 4, 2013 at 5:53 AM, Ray Cote wrote: > proxies = { > 'https': '192.168.24.25:8443', > 'http': '192.168.24.25:8443', } > > a = requests.get('http://google.com/', proxies=proxies) > > > When I look at the proxy log, I see a GET being performed -- when it should be a CONNECT. > Does not matter if I try to get http or https google.com. Not sure if it's related to your problem or not, but my understanding of a non-SSL request through a proxy is that it'll be a GET request (eg "GET http://google.com/ HTTP/1.0"). So the problem is only that it's still doing GET requests when it's an https query (which is where CONNECT is needed). ChrisA From hansmu at xs4all.nl Fri Jan 4 10:00:01 2013 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 04 Jan 2013 16:00:01 +0100 Subject: Missing something obvious with python-requests In-Reply-To: References: <857538.2991.1357238893647.JavaMail.rgacote@Ray-iMac-2011.local> <17769250.2995.1357239221470.JavaMail.rgacote@Ray-iMac-2011.local> Message-ID: <50e6ee72$0$6932$e4fe514c@news2.news.xs4all.nl> On 4/01/13 03:56:47, Chris Angelico wrote: > On Fri, Jan 4, 2013 at 5:53 AM, Ray Cote > wrote: >> proxies = { >> 'https': '192.168.24.25:8443', >> 'http': '192.168.24.25:8443', } >> >> a = requests.get('http://google.com/', proxies=proxies) >> >> >> When I look at the proxy log, I see a GET being performed -- when it should be a CONNECT. >> Does not matter if I try to get http or https google.com. > Not sure if it's related to your problem or not, but my understanding > of a non-SSL request through a proxy is that it'll be a GET request > (eg "GET http://google.com/ HTTP/1.0"). So the problem is only that > it's still doing GET requests when it's an https query (which is where > CONNECT is needed). It all depends on the proxy URL. It the proxy URL is http://192.168.24.25/, then the client should send GET requests to the proxy in both cases, and the proxy should send GET or CONNECT to the origin server, depending on whether origin URL uses SSL. If the proxy URL is https://192.168.24.25/, then the client should send CONNECT requests to the proxy, and the proxy should send GET or CONNECT as appropriate. Python-requests appears to implement only the first case. Hope this helps, -- HansM From rosuav at gmail.com Fri Jan 4 10:24:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 02:24:30 +1100 Subject: Missing something obvious with python-requests In-Reply-To: <50e6ee72$0$6932$e4fe514c@news2.news.xs4all.nl> References: <857538.2991.1357238893647.JavaMail.rgacote@Ray-iMac-2011.local> <17769250.2995.1357239221470.JavaMail.rgacote@Ray-iMac-2011.local> <50e6ee72$0$6932$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sat, Jan 5, 2013 at 2:00 AM, Hans Mulder wrote: > It the proxy URL is http://192.168.24.25/, then the client should send > GET requests to the proxy in both cases, and the proxy should send GET > or CONNECT to the origin server, depending on whether origin URL uses > SSL. > > If the proxy URL is https://192.168.24.25/, then the client should send > CONNECT requests to the proxy, and the proxy should send GET or CONNECT > as appropriate. Are you sure? This seems backward. As I understand it, a GET request to a proxy triggers a GET request to the origin server, and a CONNECT request to a proxy triggers a TCP socket connection to the origin host (which may not even be an HTTP/HTTPS server). This has nothing to do with the protocol used between the client and the proxy. ChrisA From subhabangalore at gmail.com Thu Jan 3 15:04:03 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Thu, 3 Jan 2013 12:04:03 -0800 (PST) Subject: Question on for loop Message-ID: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take, var1=banana, var2=apple, var3=mango but can we do something to assign the variables dynamically I was thinking of var_series=['var1','var2','var3'] for var in var_series: for fruit in fruits: print var,fruits If any one can kindly suggest. Regards, Subhabrata NB: Apology for some alignment mistakes,etc. From python at mrabarnett.plus.com Thu Jan 3 15:21:53 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 03 Jan 2013 20:21:53 +0000 Subject: Question on for loop In-Reply-To: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> Message-ID: <50E5E861.6040000@mrabarnett.plus.com> On 2013-01-03 20:04, subhabangalore at gmail.com wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: > print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may take, > var1=banana, > var2=apple, > var3=mango > > but can we do something to assign the variables dynamically I was thinking > of > var_series=['var1','var2','var3'] > for var in var_series: > for fruit in fruits: > print var,fruits > > If any one can kindly suggest. > > Regards, > Subhabrata > > NB: Apology for some alignment mistakes,etc. > Why would you want to do that? Creating names dynamically like that is a bad idea. Just keep them in a list, like they are already. From matt.walker.jones at gmail.com Thu Jan 3 15:28:06 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Thu, 3 Jan 2013 14:28:06 -0600 Subject: Question on for loop In-Reply-To: <50E5E861.6040000@mrabarnett.plus.com> References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> <50E5E861.6040000@mrabarnett.plus.com> Message-ID: Yeah, this seems like a bad idea. What exactly are you trying to do here? Maybe using a dictionary is what you want? d = { 'first' : 'banana', 'second' : 'apple', 'third' : 'mango' } for key, value in d.items(): print key, value However I'm still not sure why you'd want to do this. *Matt Jones* On Thu, Jan 3, 2013 at 2:21 PM, MRAB wrote: > On 2013-01-03 20:04, subhabangalore at gmail.com wrote: > >> Dear Group, >> If I take a list like the following: >> >> fruits = ['banana', 'apple', 'mango'] >> for fruit in fruits: >> print 'Current fruit :', fruit >> >> Now, >> if I want variables like var1,var2,var3 be assigned to them, we may take, >> var1=banana, >> var2=apple, >> var3=mango >> >> but can we do something to assign the variables dynamically I was thinking >> of >> var_series=['var1','var2','**var3'] >> for var in var_series: >> for fruit in fruits: >> print var,fruits >> >> If any one can kindly suggest. >> >> Regards, >> Subhabrata >> >> NB: Apology for some alignment mistakes,etc. >> >> Why would you want to do that? Creating names dynamically like that is > a bad idea. Just keep them in a list, like they are already. > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Jan 3 15:22:16 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Jan 2013 21:22:16 +0100 Subject: Question on for loop References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> Message-ID: subhabangalore at gmail.com wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: > print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may take, > var1=banana, > var2=apple, > var3=mango > > but can we do something to assign the variables dynamically I was thinking > of > var_series=['var1','var2','var3'] > for var in var_series: > for fruit in fruits: > print var,fruits > > If any one can kindly suggest. For that problem you need another data structure -- a dictionary: >>> lookup_fruits = {"var1": "banana", "var2": "apple", "var3": "mango"} >>> var_series = ["var1", "var2", "var3"] >>> for var in var_series: ... print var, lookup_fruits[var] ... var1 banana var2 apple var3 mango From donrosszx at gmail.com Thu Jan 3 18:22:38 2013 From: donrosszx at gmail.com (Don Ross) Date: Thu, 3 Jan 2013 15:22:38 -0800 (PST) Subject: Question on for loop In-Reply-To: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> Message-ID: <8ae59f96-3cbf-457b-82e4-8045c83d85cb@googlegroups.com> I'm interested to know why you're trying this as well. Is this something that would be helped by creating a class and then dynamically creating instances of that class? Something like... class Fruit: def __init__(self, name): self.name = name for fruit in ['banana', 'apple', 'mango']: varName = Fruit(fruit) # do stuff with varName On Thursday, January 3, 2013 2:04:03 PM UTC-6, subhaba... at gmail.com wrote: > Dear Group, > > If I take a list like the following: > > > > fruits = ['banana', 'apple', 'mango'] > > for fruit in fruits: > > print 'Current fruit :', fruit > > > > Now, > > if I want variables like var1,var2,var3 be assigned to them, we may take, > > var1=banana, > > var2=apple, > > var3=mango > > > > but can we do something to assign the variables dynamically I was thinking > > of > > var_series=['var1','var2','var3'] > > for var in var_series: > > for fruit in fruits: > > print var,fruits > > > > If any one can kindly suggest. > > > > Regards, > > Subhabrata > > > > NB: Apology for some alignment mistakes,etc. From wuwei23 at gmail.com Thu Jan 3 19:47:08 2013 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 Jan 2013 16:47:08 -0800 (PST) Subject: Question on for loop References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> Message-ID: On Jan 4, 6:04?am, subhabangal... at gmail.com wrote: > but can we do something to assign the variables dynamically I was thinking > of > var_series=['var1','var2','var3'] > for var in var_series: > ? for fruit in fruits: > ? ? ? ?print var,fruits Before trying to do this, write the next bit of code where you _use_ such variables. What do you do if there are no fruits? What do you do if there are 7000? You don't want variables to be optional, because otherwise you'll need to guard every usage with something like: if 'var2893' in locals(): ... Of course, you can also automate this, but why push values into a dictionary that exists for one purpose if you're not going to use it that way? If you need to deal with an unknown number of objects, use a list. If those objects have a name by which you can refer to them, use a dictionary. From steve+comp.lang.python at pearwood.info Fri Jan 4 00:48:24 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2013 05:48:24 GMT Subject: Question on for loop References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> Message-ID: <50e66d28$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: > print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may > take, var1=banana, > var2=apple, > var3=mango > > but can we do something to assign the variables dynamically Easy as falling off a log. You can't write "var1", "var2" etc. but you can write it as "var[0]", "var[1]" etc. var = ['banana', 'apple', 'mango'] print var[0] # prints 'banana' print var[1] # prints 'apple' print var[2] # prints 'mango' Of course "var" is not a very good variable name. "fruit" or "fruits" would be better. -- Steven From subhabangalore at gmail.com Tue Jan 15 14:30:16 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 15 Jan 2013 11:30:16 -0800 (PST) Subject: Question on for loop In-Reply-To: <50e66d28$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> <50e66d28$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <71096f2e-be87-449a-b5d9-7a02ded89a67@googlegroups.com> On Friday, January 4, 2013 11:18:24 AM UTC+5:30, Steven D'Aprano wrote: > On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: > > > > > Dear Group, > > > If I take a list like the following: > > > > > > fruits = ['banana', 'apple', 'mango'] > > > for fruit in fruits: > > > print 'Current fruit :', fruit > > > > > > Now, > > > if I want variables like var1,var2,var3 be assigned to them, we may > > > take, var1=banana, > > > var2=apple, > > > var3=mango > > > > > > but can we do something to assign the variables dynamically > > > > Easy as falling off a log. You can't write "var1", "var2" etc. but you > > can write it as "var[0]", "var[1]" etc. > > > > var = ['banana', 'apple', 'mango'] > > print var[0] # prints 'banana' > > print var[1] # prints 'apple' > > print var[2] # prints 'mango' > > > > > > > > Of course "var" is not a very good variable name. "fruit" or "fruits" > > would be better. > > > > > > > > > > -- > > Steven Actually in many cases it is easy if you get the variable of list value, I was trying something like, def func1(n): list1=["x1","x2","x3","x4","x5","x6","x7","x8","x9","x10"] blnk=[] for i in range(len(list1)): num1="var"+str(i)+"="+list1[i] blnk.append(num1) print blnk Regards, Subhabrata. From alister.ware at ntlworld.com Fri Jan 4 05:16:44 2013 From: alister.ware at ntlworld.com (Alister) Date: Fri, 04 Jan 2013 10:16:44 GMT Subject: Question on for loop References: <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> Message-ID: On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: > print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may > take, var1=banana, > var2=apple, > var3=mango > > but can we do something to assign the variables dynamically I was > thinking of var_series=['var1','var2','var3'] > for var in var_series: > for fruit in fruits: > print var,fruits > > If any one can kindly suggest. > > Regards, > Subhabrata > > NB: Apology for some alignment mistakes,etc. if you really want to do this (& I agree with the other replies that this is unlikely to be a good idea) then you could simply unpack the list var1,var2,var3=fruits of course if your list is of unknown length then this again becomes impractical. for most programming requirements there is a simple solution, if you find your approach is not easily implemented it is probably a good time to re- asses your approach, more of the than not you have been given a bum steer and are heading down the wrong road. See http://thedailywtf.com for an almost limitless supply of examples of programmers continuing down the wrong road ;-) -- There's nothing worse for your business than extra Santa Clauses smoking in the men's room. -- W. Bossert From ralf at systemexit.de Thu Jan 3 17:33:12 2013 From: ralf at systemexit.de (Ralf Schmitt) Date: Thu, 03 Jan 2013 23:33:12 +0100 Subject: [ANN] pypiserver 1.0.1 - minimal private pypi server Message-ID: <87r4m17v87.fsf@myhost.lan> Hi, I've just uploaded pypiserver 1.0.1 to the python package index. pypiserver is a minimal PyPI compatible server. It can be used to serve a set of packages and eggs to easy_install or pip. pypiserver is easy to install (i.e. just 'pip install pypiserver'). It doesn't have any external dependencies. http://pypi.python.org/pypi/pypiserver/ should contain enough information to easily get you started running your own PyPI server in a few minutes. The code is available on github: https://github.com/schmir/pypiserver Changes in version 1.0.1 ------------------------ - make 'pypi-server -Ux' work on windows ('module' object has no attribute 'spawnlp', https://github.com/schmir/pypiserver/issues/26) - use absolute paths in hrefs for root view (https://github.com/schmir/pypiserver/issues/25) - add description of uploads to the documentation - make the test suite work on python 3 - make pypi-server-standalone work with python 2.5 -- Cheers Ralf From invalid at invalid.invalid Thu Jan 3 18:25:51 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 3 Jan 2013 23:25:51 +0000 (UTC) Subject: Yet another attempt at a safe eval() call Message-ID: I've written a small assembler in Python 2.[67], and it needs to evaluate integer-valued arithmetic expressions in the context of a symbol table that defines integer values for a set of names. The "right" thing is probably an expression parser/evaluator using ast, but it looked like that would take more code that the rest of the assembler combined, and I've got other higher-priority tasks to get back to. How badly am I deluding myself with the code below? def lessDangerousEval(expr): global symbolTable if 'import' in expr: raise ParseError("operand expressions are not allowed to contain the string 'import'") globals = {'__builtins__': None} locals = symbolTable return eval(expr, globals, locals) I can guarantee that symbolTable is a dict that maps a set of string symbol names to integer values. -- Grant Edwards grant.b.edwards Yow! -- I have seen the at FUN -- gmail.com From python.list at tim.thechases.com Thu Jan 3 20:11:18 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 03 Jan 2013 19:11:18 -0600 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: Message-ID: <50E62C36.9080100@tim.thechases.com> On 01/03/13 17:25, Grant Edwards wrote: > def lessDangerousEval(expr): > global symbolTable > if 'import' in expr: > raise ParseError("operand expressions are not allowed to contain the string 'import'") > globals = {'__builtins__': None} > locals = symbolTable > return eval(expr, globals, locals) > > I can guarantee that symbolTable is a dict that maps a set of string > symbol names to integer values. For what definition of "safe"? Are CPython segfaults a problem? Blowing the stack? Do you aim to prevent exploitable things like system calls or network/file access? -tkc From invalid at invalid.invalid Thu Jan 3 21:34:14 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 02:34:14 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: Message-ID: On 2013-01-04, Tim Chase wrote: > On 01/03/13 17:25, Grant Edwards wrote: >> def lessDangerousEval(expr): >> global symbolTable >> if 'import' in expr: >> raise ParseError("operand expressions are not allowed to contain the string 'import'") >> globals = {'__builtins__': None} >> locals = symbolTable >> return eval(expr, globals, locals) >> >> I can guarantee that symbolTable is a dict that maps a set of string >> symbol names to integer values. > > For what definition of "safe"? Are CPython segfaults a problem? Not by themselves, no. > Blowing the stack? Not a problem either. I don't care if the program crashes. It's a pretty dumb assembler, and it gives up and exits after the first error anyway. > Do you aim to prevent exploitable things like system calls or > network/file access? Yes, that's mainly what I was wondering wondering about. -- Grant From steve+comp.lang.python at pearwood.info Fri Jan 4 02:47:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2013 07:47:41 GMT Subject: Yet another attempt at a safe eval() call References: Message-ID: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: > I've written a small assembler in Python 2.[67], and it needs to > evaluate integer-valued arithmetic expressions in the context of a > symbol table that defines integer values for a set of names. The > "right" thing is probably an expression parser/evaluator using ast, but > it looked like that would take more code that the rest of the assembler > combined, and I've got other higher-priority tasks to get back to. > > How badly am I deluding myself with the code below? Pretty badly, sorry. See trivial *cough* exploit below. > def lessDangerousEval(expr): > global symbolTable > if 'import' in expr: > raise ParseError("operand expressions are not allowed to contain > the string 'import'") > globals = {'__builtins__': None} > locals = symbolTable > return eval(expr, globals, locals) > > I can guarantee that symbolTable is a dict that maps a set of string > symbol names to integer values. Here's one exploit. I make no promises that it is the simplest such one. # get access to __import__ s = ("[x for x in (1).__class__.__base__.__subclasses__() " "if x.__name__ == 'catch_warnings'][0]()._module" ".__builtins__['__imp' + 'ort__']") # use it to get access to any module we like t = s + "('os')" # and then do bad things urscrewed = t + ".system('echo u r pwned!')" lessDangerousEval(urscrewed) At a minimum, I would recommend: * Do not allow any underscores in the expression being evaluated. Unless you absolutely need to support them for names, they can only lead to trouble. * If you must allow underscores, don't allow double underscores. Every restriction you apply makes it harder to exploit. * Since you're evaluating mathematical expressions, there's probably no need to allow quotation marks either. They too can only lead to trouble. * Likewise for dots, since this is *integer* maths. * Set as short as possible limit on the length of the string as you can bare; the shorter the limit, the shorter any exploit must be, and it is harder to write a short exploit than a long exploit. * But frankly, you should avoid eval, and write your own mini-integer arithmetic evaluator which avoids even the most remote possibility of exploit. So, here's my probably-not-safe-either "safe eval": def probably_not_safe_eval(expr): if 'import' in expr.lower(): raise ParseError("'import' prohibited") for c in '_"\'.': if c in expr: raise ParseError('prohibited char %r' % c) if len(expr) > 120: raise ParseError('expression too long') globals = {'__builtins__': None} locals = symbolTable return eval(expr, globals, locals) # fingers crossed! I can't think of any way to break out of these restrictions, but that may just mean I'm not smart enough. -- Steven From invalid at invalid.invalid Fri Jan 4 10:53:39 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 15:53:39 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-04, Steven D'Aprano wrote: > On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: > >> I've written a small assembler in Python 2.[67], and it needs to >> evaluate integer-valued arithmetic expressions in the context of a >> symbol table that defines integer values for a set of names. The >> "right" thing is probably an expression parser/evaluator using ast, but >> it looked like that would take more code that the rest of the assembler >> combined, and I've got other higher-priority tasks to get back to. >> >> How badly am I deluding myself with the code below? > > Pretty badly, sorry. I suspected that was the case. > See trivial *cough* exploit below. > > >> def lessDangerousEval(expr): >> global symbolTable >> if 'import' in expr: >> raise ParseError("operand expressions are not allowed to contain >> the string 'import'") >> globals = {'__builtins__': None} >> locals = symbolTable >> return eval(expr, globals, locals) >> >> I can guarantee that symbolTable is a dict that maps a set of string >> symbol names to integer values. > > > Here's one exploit. I make no promises that it is the simplest such one. > > # get access to __import__ > s = ("[x for x in (1).__class__.__base__.__subclasses__() " > "if x.__name__ == 'catch_warnings'][0]()._module" > ".__builtins__['__imp' + 'ort__']") > # use it to get access to any module we like > t = s + "('os')" > # and then do bad things > urscrewed = t + ".system('echo u r pwned!')" > > lessDangerousEval(urscrewed) > > > At a minimum, I would recommend: > > * Do not allow any underscores in the expression being evaluated. > Unless you absolutely need to support them for names, they can only > lead to trouble. I can disallow underscores in names. > [...] > * Since you're evaluating mathematical expressions, there's probably > no need to allow quotation marks either. They too can only lead to > trouble. > > * Likewise for dots, since this is *integer* maths. OK, quotes and dots are out as well. > * Set as short as possible limit on the length of the string as you > can bare; the shorter the limit, the shorter any exploit must be, > and it is harder to write a short exploit than a long exploit. > > * But frankly, you should avoid eval, and write your own mini-integer > arithmetic evaluator which avoids even the most remote possibility > of exploit. That's obviously the "right" thing to do. I suppose I should figure out how to use the ast module. > So, here's my probably-not-safe-either "safe eval": > > > def probably_not_safe_eval(expr): > if 'import' in expr.lower(): > raise ParseError("'import' prohibited") > for c in '_"\'.': > if c in expr: > raise ParseError('prohibited char %r' % c) > if len(expr) > 120: > raise ParseError('expression too long') > globals = {'__builtins__': None} > locals = symbolTable > return eval(expr, globals, locals) # fingers crossed! > > I can't think of any way to break out of these restrictions, but that may > just mean I'm not smart enough. Thanks! It's definitely an improvement. -- Grant Edwards grant.b.edwards Yow! -- I have seen the at FUN -- gmail.com From torriem at gmail.com Fri Jan 4 11:05:23 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 04 Jan 2013 09:05:23 -0700 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50E6FDC3.3030009@gmail.com> On 01/04/2013 08:53 AM, Grant Edwards wrote: > That's obviously the "right" thing to do. I suppose I should figure > out how to use the ast module. Or PyParsing. As for your program being "secure" I don't see that there's much to exploit. You're not running as a service, and you're not running your assembler as root, called from a normal user. The user has your code and can "exploit" it anytime he wants. From invalid at invalid.invalid Fri Jan 4 11:16:09 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 16:16:09 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-04, Michael Torrie wrote: > On 01/04/2013 08:53 AM, Grant Edwards wrote: >> That's obviously the "right" thing to do. I suppose I should figure >> out how to use the ast module. > > Or PyParsing. > > As for your program being "secure" I don't see that there's much to > exploit. There isn't. > You're not running as a service, and you're not running your > assembler as root, called from a normal user. The user has your code > and can "exploit" it anytime he wants. I'm just trying to prevent surprises for people who are running the assembler. We have to assume that they trust the assembler code to not cause damage intentionally. But, one would not expect them to have to worry that assembly language input fed to the assembler code might cause some sort of collateral damage. Sure, I can change the source code for gcc so that it wreaks havok when I invoke it. But, using the stock gcc compiler there shouldn't be any source file I can feed it that will cause it to mail my bank account info to somebody in Eastern Europe, install a keylogger, and then remove all my files. -- Grant Edwards grant.b.edwards Yow! I have a TINY BOWL in at my HEAD gmail.com From oscar.j.benjamin at gmail.com Sat Jan 5 10:56:31 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 5 Jan 2013 15:56:31 +0000 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4 January 2013 15:53, Grant Edwards wrote: > On 2013-01-04, Steven D'Aprano wrote: >> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: >> >> * But frankly, you should avoid eval, and write your own mini-integer >> arithmetic evaluator which avoids even the most remote possibility >> of exploit. > > That's obviously the "right" thing to do. I suppose I should figure > out how to use the ast module. Someone has already created a module that does this called numexpr. Is there some reason why you don't want to use that? >>> import numexpr >>> numexpr.evaluate('2+4*5') array(22, dtype=int32) >>> numexpr.evaluate('2+a*5', {'a':4}) array(22L) Oscar From rosuav at gmail.com Sat Jan 5 11:01:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 03:01:41 +1100 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 6, 2013 at 2:56 AM, Oscar Benjamin wrote: > On 4 January 2013 15:53, Grant Edwards wrote: >> On 2013-01-04, Steven D'Aprano wrote: >>> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: >>> >>> * But frankly, you should avoid eval, and write your own mini-integer >>> arithmetic evaluator which avoids even the most remote possibility >>> of exploit. >> >> That's obviously the "right" thing to do. I suppose I should figure >> out how to use the ast module. > > Someone has already created a module that does this called numexpr. Is > there some reason why you don't want to use that? > >>>> import numexpr >>>> numexpr.evaluate('2+4*5') > array(22, dtype=int32) >>>> numexpr.evaluate('2+a*5', {'a':4}) > array(22L) Is that from PyPI? It's not in my Python 3.3 installation. Obvious reason not to use it: Unaware of it. :) ChrisA From oscar.j.benjamin at gmail.com Sat Jan 5 11:17:16 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 5 Jan 2013 16:17:16 +0000 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5 January 2013 16:01, Chris Angelico wrote: > On Sun, Jan 6, 2013 at 2:56 AM, Oscar Benjamin > wrote: >> On 4 January 2013 15:53, Grant Edwards wrote: >>> On 2013-01-04, Steven D'Aprano wrote: >>>> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: >>>> >>>> * But frankly, you should avoid eval, and write your own mini-integer >>>> arithmetic evaluator which avoids even the most remote possibility >>>> of exploit. >>> >>> That's obviously the "right" thing to do. I suppose I should figure >>> out how to use the ast module. >> >> Someone has already created a module that does this called numexpr. Is >> there some reason why you don't want to use that? >> >>>>> import numexpr >>>>> numexpr.evaluate('2+4*5') >> array(22, dtype=int32) >>>>> numexpr.evaluate('2+a*5', {'a':4}) >> array(22L) > > Is that from PyPI? It's not in my Python 3.3 installation. Obvious > reason not to use it: Unaware of it. :) My apologies. I should have at least provided a link: http://code.google.com/p/numexpr/ I installed it from the ubuntu repo under the name python-numexpr. It is also on PyPI: http://pypi.python.org/pypi/numexpr numexpr is a well established project intended primarily for memory and cache efficient computations over large arrays of data. Possibly as a side effect, it can also be used to evaluate simple algebraic expressions involving ordinary scalar variables. Oscar From matt.newville at gmail.com Sat Jan 5 11:40:34 2013 From: matt.newville at gmail.com (matt.newville at gmail.com) Date: Sat, 5 Jan 2013 08:40:34 -0800 (PST) Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <074c2d8b-3734-43f8-b96f-9186506e412f@googlegroups.com> On Saturday, January 5, 2013 8:17:16 AM UTC-8, Oscar Benjamin wrote: > On 5 January 2013 16:01, Chris Angelico wrote: > > > On Sun, Jan 6, 2013 at 2:56 AM, Oscar Benjamin > > > wrote: > > >> On 4 January 2013 15:53, Grant Edwards wrote: > > >>> On 2013-01-04, Steven D'Aprano wrote: > > >>>> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: > > >>>> > > >>>> * But frankly, you should avoid eval, and write your own mini-integer > > >>>> arithmetic evaluator which avoids even the most remote possibility > > >>>> of exploit. > > >>> > > >>> That's obviously the "right" thing to do. I suppose I should figure > > >>> out how to use the ast module. > > >> > > >> Someone has already created a module that does this called numexpr. Is > > >> there some reason why you don't want to use that? > > >> > > >>>>> import numexpr > > >>>>> numexpr.evaluate('2+4*5') > > >> array(22, dtype=int32) > > >>>>> numexpr.evaluate('2+a*5', {'a':4}) > > >> array(22L) > > > > > > Is that from PyPI? It's not in my Python 3.3 installation. Obvious > > > reason not to use it: Unaware of it. :) > > > > My apologies. I should have at least provided a link: > > http://code.google.com/p/numexpr/ > > > > I installed it from the ubuntu repo under the name python-numexpr. It > > is also on PyPI: > > http://pypi.python.org/pypi/numexpr > > > > numexpr is a well established project intended primarily for memory > > and cache efficient computations over large arrays of data. Possibly > > as a side effect, it can also be used to evaluate simple algebraic > > expressions involving ordinary scalar variables. > > > > > > Oscar The asteval module http://pypi.python.org/pypi/asteval/0.9 and http://newville.github.com/asteval/ might be another alternative. It's not as fast as numexpr, but a bit more general. It uses the ast module to "compile" an expression into the AST, then walks through that, intercepting Name nodes and using a flat namespace of variables. It disallows imports and does not support all python constructs, but it is a fairly complete in supporting python syntax. It makes no claim at actually being safe from malicious attack, but should be safer than a straight eval(), and prevent accidental problems when evaluating user-input as code. If anyone can find exploits within it, I'd be happy to try to fix them. --Matt From matt.newville at gmail.com Sat Jan 5 11:40:34 2013 From: matt.newville at gmail.com (matt.newville at gmail.com) Date: Sat, 5 Jan 2013 08:40:34 -0800 (PST) Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <074c2d8b-3734-43f8-b96f-9186506e412f@googlegroups.com> On Saturday, January 5, 2013 8:17:16 AM UTC-8, Oscar Benjamin wrote: > On 5 January 2013 16:01, Chris Angelico wrote: > > > On Sun, Jan 6, 2013 at 2:56 AM, Oscar Benjamin > > > wrote: > > >> On 4 January 2013 15:53, Grant Edwards wrote: > > >>> On 2013-01-04, Steven D'Aprano wrote: > > >>>> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: > > >>>> > > >>>> * But frankly, you should avoid eval, and write your own mini-integer > > >>>> arithmetic evaluator which avoids even the most remote possibility > > >>>> of exploit. > > >>> > > >>> That's obviously the "right" thing to do. I suppose I should figure > > >>> out how to use the ast module. > > >> > > >> Someone has already created a module that does this called numexpr. Is > > >> there some reason why you don't want to use that? > > >> > > >>>>> import numexpr > > >>>>> numexpr.evaluate('2+4*5') > > >> array(22, dtype=int32) > > >>>>> numexpr.evaluate('2+a*5', {'a':4}) > > >> array(22L) > > > > > > Is that from PyPI? It's not in my Python 3.3 installation. Obvious > > > reason not to use it: Unaware of it. :) > > > > My apologies. I should have at least provided a link: > > http://code.google.com/p/numexpr/ > > > > I installed it from the ubuntu repo under the name python-numexpr. It > > is also on PyPI: > > http://pypi.python.org/pypi/numexpr > > > > numexpr is a well established project intended primarily for memory > > and cache efficient computations over large arrays of data. Possibly > > as a side effect, it can also be used to evaluate simple algebraic > > expressions involving ordinary scalar variables. > > > > > > Oscar The asteval module http://pypi.python.org/pypi/asteval/0.9 and http://newville.github.com/asteval/ might be another alternative. It's not as fast as numexpr, but a bit more general. It uses the ast module to "compile" an expression into the AST, then walks through that, intercepting Name nodes and using a flat namespace of variables. It disallows imports and does not support all python constructs, but it is a fairly complete in supporting python syntax. It makes no claim at actually being safe from malicious attack, but should be safer than a straight eval(), and prevent accidental problems when evaluating user-input as code. If anyone can find exploits within it, I'd be happy to try to fix them. --Matt From invalid at invalid.invalid Sun Jan 6 10:12:46 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 6 Jan 2013 15:12:46 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-05, Oscar Benjamin wrote: > On 4 January 2013 15:53, Grant Edwards wrote: >> On 2013-01-04, Steven D'Aprano wrote: >>> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: >>> >>> * But frankly, you should avoid eval, and write your own mini-integer >>> arithmetic evaluator which avoids even the most remote possibility >>> of exploit. >> >> That's obviously the "right" thing to do. I suppose I should figure >> out how to use the ast module. > > Someone has already created a module that does this called numexpr. Is > there some reason why you don't want to use that? 1) I didn't know about it, and my Googling didn't find it. 2) It's not part of the standard library, and my program needs to be distributed as a single source file. -- Grant From oscar.j.benjamin at gmail.com Sun Jan 6 19:08:07 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 7 Jan 2013 00:08:07 +0000 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 6 January 2013 15:12, Grant Edwards wrote: > On 2013-01-05, Oscar Benjamin wrote: >> On 4 January 2013 15:53, Grant Edwards wrote: >>> On 2013-01-04, Steven D'Aprano wrote: >>>> On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: >>>> >>>> * But frankly, you should avoid eval, and write your own mini-integer >>>> arithmetic evaluator which avoids even the most remote possibility >>>> of exploit. >>> >>> That's obviously the "right" thing to do. I suppose I should figure >>> out how to use the ast module. >> >> Someone has already created a module that does this called numexpr. Is >> there some reason why you don't want to use that? > > 1) I didn't know about it, and my Googling didn't find it. > > 2) It's not part of the standard library, and my program needs to be > distributed as a single source file. That's an unfortunate restriction. It also won't be possible to reuse the code from numexpr (for technical rather than legal reasons). Perhaps asteval will be more helpful in that sense. Otherwise presumably the shunting-yard algorithm comes out a little nicer in Python than in C (it would be useful if something like this were available on PyPI as a pure Python module): http://en.wikipedia.org/wiki/Shunting_yard_algorithm#C_example Oscar From invalid at invalid.invalid Fri Jan 4 11:38:03 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 16:38:03 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-04, Steven D'Aprano wrote: > On Thu, 03 Jan 2013 23:25:51 +0000, Grant Edwards wrote: > >> I've written a small assembler in Python 2.[67], and it needs to >> evaluate integer-valued arithmetic expressions in the context of a >> symbol table that defines integer values for a set of names. [...] [ my attaempt at a safer eval() ] > So, here's my probably-not-safe-either "safe eval": > > > def probably_not_safe_eval(expr): > if 'import' in expr.lower(): > raise ParseError("'import' prohibited") > for c in '_"\'.': > if c in expr: > raise ParseError('prohibited char %r' % c) > if len(expr) > 120: > raise ParseError('expression too long') > globals = {'__builtins__': None} > locals = symbolTable > return eval(expr, globals, locals) # fingers crossed! > > I can't think of any way to break out of these restrictions, but that may > just mean I'm not smart enough. I've added equals, backslash, commas, square/curly brackets, colons and semicolons to the prohibited character list. I also reduced the maximum length to 60 characters. It's unfortunate that parentheses are overloaded for both expression grouping and for function calling... def lessDangerousEval(expr): if 'import' in expr.lower(): raise ParseError("'import' prohibited in expression") for c in '_"\'.;:[]{}=\\': if c in expr: raise ParseError("prohibited char '%r' in expression" % c) if len(expr) > 60: raise ParseError('expression too long') globals = {'__builtins__': None} locals = symbolTable return eval(expr, globals, locals) # fingers crossed! Exploits anyone? -- Grant Edwards grant.b.edwards Yow! I'm ZIPPY the PINHEAD at and I'm totally committed gmail.com to the festive mode. From rosuav at gmail.com Fri Jan 4 11:51:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 03:51:23 +1100 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 5, 2013 at 3:38 AM, Grant Edwards wrote: > I've added equals, backslash, commas, square/curly brackets, colons and semicolons to the > prohibited character list. I also reduced the maximum length to 60 > characters. It's unfortunate that parentheses are overloaded for both > expression grouping and for function calling... I have to say that an expression evaluator that can't handle parens for grouping is badly flawed. Can you demand that open parenthesis be preceded by an operator (or beginning of line)? For instance: (1+2)*3+4 # Valid 1+2*(3+4) # Valid 1+2(3+4) # Invalid, this will attempt to call 2 You could explain it as a protection against mistaken use of algebraic notation (in which the last two expressions have the same meaning and evaluate to 15). Or, alternatively, you could simply insert the asterisk yourself, though that could potentially be VERY confusing. Without parentheses, your users will be forced to store intermediate results in variables, which gets tiresome fast. discriminant = b*b-4*a*c denominator = 2*a # Okay, this expression demands a square rooting, but let's pretend that's done. sol1 = -b+discriminant sol2 = -b-discrminant sol1 = sol1/denominator sol2 /= denominator # if they know about augmented assignment You can probably recognize the formula I'm working with there, but it's far less obvious and involves six separate statements rather than two. And this is a fairly simple formula. It'll get a lot worse in production. ChrisA From invalid at invalid.invalid Fri Jan 4 12:14:36 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 17:14:36 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-04, Chris Angelico wrote: > On Sat, Jan 5, 2013 at 3:38 AM, Grant Edwards wrote: >> I've added equals, backslash, commas, square/curly brackets, colons >> and semicolons to the prohibited character list. I also reduced the >> maximum length to 60 characters. It's unfortunate that parentheses >> are overloaded for both expression grouping and for function >> calling... > > I have to say that an expression evaluator that can't handle parens > for grouping is badly flawed. Indeed. That's why I didn't disallow parens. What I was implying was that since you have to allow parens for grouping, there's no simple way to disallow function calls. > Can you demand that open parenthesis be preceded by an operator (or > beginning of line)? Yes, but once you've parsed the expression to the point where you can enforce rules like that, you're probably most of the way to doing the "right" thing and evaluating the expression using ast or pyparsing or similar. > You can probably recognize the formula I'm working with there, but > it's far less obvious and involves six separate statements rather than > two. And this is a fairly simple formula. It'll get a lot worse in > production. In the general case, yes. For this assembler I could _probably_ get by with expressions of the form where op is '+' or '-'. But, whenever I try to come up with a minimal solution like that, it tends to get "enhanced" over the years until it's a complete mess, doesn't work quite right, and took more total man-hours than a general and "permanent" solution would have. Some might argue that repeated tweaking of and adding limitiations to a "safe eval" is just heading down that same road in a different car. They'd probably be right: in the end, it will probably have been less work to just do it with ast. But it's still interesting to try. :) -- Grant Edwards grant.b.edwards Yow! Are you the at self-frying president? gmail.com From rosuav at gmail.com Fri Jan 4 12:21:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 04:21:33 +1100 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 5, 2013 at 4:14 AM, Grant Edwards wrote: > On 2013-01-04, Chris Angelico wrote: >> On Sat, Jan 5, 2013 at 3:38 AM, Grant Edwards wrote: > >>> I've added equals, backslash, commas, square/curly brackets, colons >>> and semicolons to the prohibited character list. I also reduced the >>> maximum length to 60 characters. It's unfortunate that parentheses >>> are overloaded for both expression grouping and for function >>> calling... >> >> I have to say that an expression evaluator that can't handle parens >> for grouping is badly flawed. > > Indeed. That's why I didn't disallow parens. > > What I was implying was that since you have to allow parens for > grouping, there's no simple way to disallow function calls. Yeah, and a safe evaluator that allows function calls is highly vulnerable. >> Can you demand that open parenthesis be preceded by an operator (or >> beginning of line)? > > Yes, but once you've parsed the expression to the point where you can > enforce rules like that, you're probably most of the way to doing the > "right" thing and evaluating the expression using ast or pyparsing or > similar. > > Some might argue that repeated tweaking of and adding limitiations to > a "safe eval" is just heading down that same road in a different car. > They'd probably be right: in the end, it will probably have been less > work to just do it with ast. But it's still interesting to try. :) Yep, have fun with it. As mentioned earlier, though, security isn't all that critical; so in this case, chances are you can just leave parens permitted and let function calls potentially happen. ChrisA From invalid at invalid.invalid Fri Jan 4 13:09:34 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 18:09:34 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-04, Chris Angelico wrote: > On Sat, Jan 5, 2013 at 4:14 AM, Grant Edwards wrote: >> On 2013-01-04, Chris Angelico wrote: >>> On Sat, Jan 5, 2013 at 3:38 AM, Grant Edwards wrote: >> >>>> I've added equals, backslash, commas, square/curly brackets, colons >>>> and semicolons to the prohibited character list. I also reduced the >>>> maximum length to 60 characters. It's unfortunate that parentheses >>>> are overloaded for both expression grouping and for function >>>> calling... >>> >>> I have to say that an expression evaluator that can't handle parens >>> for grouping is badly flawed. >> >> Indeed. That's why I didn't disallow parens. >> >> What I was implying was that since you have to allow parens for >> grouping, there's no simple way to disallow function calls. > > Yeah, and a safe evaluator that allows function calls is highly vulnerable. > >>> Can you demand that open parenthesis be preceded by an operator (or >>> beginning of line)? >> >> Yes, but once you've parsed the expression to the point where you can >> enforce rules like that, you're probably most of the way to doing the >> "right" thing and evaluating the expression using ast or pyparsing or >> similar. >> >> Some might argue that repeated tweaking of and adding limitiations to >> a "safe eval" is just heading down that same road in a different car. >> They'd probably be right: in the end, it will probably have been less >> work to just do it with ast. But it's still interesting to try. :) > > Yep, have fun with it. As mentioned earlier, though, security isn't > all that critical; so in this case, chances are you can just leave > parens permitted and let function calls potentially happen. An ast-based evaluator wasn't as complicated as I first thought: the examples I'd been looking at implemented far more features than I needed. This morning I found a simpler example at http://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string The error messages are still pretty cryptic, so improving that will add a few more lines. One nice thing about the ast code is that it's simple to add code to allow C-like character constants such that ('A' === 0x41). Here's the first pass at ast-based code: import ast,operator operators = \ { ast.Add: operator.iadd, ast.Sub: operator.isub, ast.Mult: operator.imul, ast.Div: operator.idiv, ast.BitXor: operator.ixor, ast.BitAnd: operator.iand, ast.BitOr: operator.ior, ast.LShift: operator.lshift, ast.RShift: operator.rshift, ast.Invert: operator.invert, ast.USub: operator.neg, ast.UAdd: operator.pos, } def _eval_expr(node): global symbolTable if isinstance(node, ast.Name): if node.id not in symbolTable: raise ParseError("name '%s' undefined" % node.id) return symbolTable[node.id] elif isinstance(node, ast.Num): return node.n elif isinstance(node, ast.operator) or isinstance(node, ast.unaryop): return operators[type(node)] elif isinstance(node, ast.BinOp): return _eval_expr(node.op)(_eval_expr(node.left), _eval_expr(node.right)) elif isinstance(node, ast.UnaryOp): return _eval_expr(node.op)(_eval_expr(node.operand)) else: raise ParseError("error parsing expression at node %s" % node) def eval_expr(expr): return _eval_expr(ast.parse(expr).body[0].value) -- Grant Edwards grant.b.edwards Yow! A can of ASPARAGUS, at 73 pigeons, some LIVE ammo, gmail.com and a FROZEN DAQUIRI!! From rosuav at gmail.com Fri Jan 4 13:23:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 05:23:28 +1100 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 5, 2013 at 5:09 AM, Grant Edwards wrote: > The error messages are still pretty cryptic, so improving > that will add a few more lines. One nice thing about the ast code is > that it's simple to add code to allow C-like character constants such > that ('A' === 0x41). Here's the first pass at ast-based code: Looks cool, and fairly neat! Now I wonder, is it possible to use that to create new operators, such as the letter d? Binary operator, takes two integers... ChrisA From invalid at invalid.invalid Fri Jan 4 13:43:46 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 18:43:46 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-04, Chris Angelico wrote: > On Sat, Jan 5, 2013 at 5:09 AM, Grant Edwards wrote: >> The error messages are still pretty cryptic, so improving >> that will add a few more lines. One nice thing about the ast code is >> that it's simple to add code to allow C-like character constants such >> that ('A' === 0x41). Here's the first pass at ast-based code: > > Looks cool, and fairly neat! Now I wonder, is it possible to use that > to create new operators, such as the letter d? Binary operator, takes > two integers... I don't think you can define new operators. AFAICT, the lexing/parsing is done using the built-in Python grammar. You can control the behavior of the predefined operators and reject operators you don't like, but you can't add new ones or change precedence/syntax or anything like that. If you want to tweak the grammar itself, then I think you need to use something like pyparsing. -- Grant Edwards grant.b.edwards Yow! I own seven-eighths of at all the artists in downtown gmail.com Burbank! From rosuav at gmail.com Fri Jan 4 14:02:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 06:02:49 +1100 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 5, 2013 at 5:43 AM, Grant Edwards wrote: > On 2013-01-04, Chris Angelico wrote: >> On Sat, Jan 5, 2013 at 5:09 AM, Grant Edwards wrote: >>> The error messages are still pretty cryptic, so improving >>> that will add a few more lines. One nice thing about the ast code is >>> that it's simple to add code to allow C-like character constants such >>> that ('A' === 0x41). Here's the first pass at ast-based code: >> >> Looks cool, and fairly neat! Now I wonder, is it possible to use that >> to create new operators, such as the letter d? Binary operator, takes >> two integers... > > I don't think you can define new operators. AFAICT, the > lexing/parsing is done using the built-in Python grammar. You can > control the behavior of the predefined operators and reject operators > you don't like, but you can't add new ones or change precedence/syntax > or anything like that. > > If you want to tweak the grammar itself, then I think you need to use > something like pyparsing. Oh well, hehe. I've not seen any simple parsers that let you incorporate D&D-style dice notation ("2d6" means "roll two 6-sided dice and sum the rolls" - "d6" implies "1d6"). ChrisA From clp2 at rebertia.com Fri Jan 4 02:50:31 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 3 Jan 2013 23:50:31 -0800 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: Message-ID: On Thu, Jan 3, 2013 at 3:25 PM, Grant Edwards wrote: > > I've written a small assembler in Python 2.[67], and it needs to > evaluate integer-valued arithmetic expressions in the context of a > symbol table that defines integer values for a set of names. The > "right" thing is probably an expression parser/evaluator using ast, > but it looked like that would take more code that the rest of the > assembler combined, and I've got other higher-priority tasks to get > back to. > > How badly am I deluding myself with the code below? Given http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html and similar, I suspect the answer is "a fair bit". > def lessDangerousEval(expr): > global symbolTable > if 'import' in expr: > raise ParseError("operand expressions are not allowed to contain the string 'import'") > globals = {'__builtins__': None} > locals = symbolTable > return eval(expr, globals, locals) > > I can guarantee that symbolTable is a dict that maps a set of string > symbol names to integer values. Using the aformentioned article as a basis, I was able to get this doozy working, albeit under Python 3: $ python3 Python 3.3.0 (default, Nov 4 2012, 17:47:16) [GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.57))] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> expr = "[klass for klass in ().__class__.__bases__[0].__subclasses__() if klass.__name__ == 'Codec'][0].encode.__globals__['__builtins__']['__im'+'port__']('os').remove" >>> eval(expr, {'__builtins__': None}, {}) >>> Since the original attack was itself devised against Python 2.x, it's highly likely that similar convoluted attacks against 2.x remain possible, unless perhaps you were use a modified interpreter. Cheers, Chris From tjreedy at udel.edu Fri Jan 4 07:24:04 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jan 2013 07:24:04 -0500 Subject: Yet another attempt at a safe eval() call In-Reply-To: References: Message-ID: On 1/3/2013 6:25 PM, Grant Edwards wrote: > > I've written a small assembler in Python 2.[67], and it needs to > evaluate integer-valued arithmetic expressions in the context of a > symbol table that defines integer values for a set of names. The > "right" thing is probably an expression parser/evaluator using ast, > but it looked like that would take more code that the rest of the > assembler combined, and I've got other higher-priority tasks to get > back to. Will ast.literal_eval do what you want? -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Jan 4 08:33:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2013 13:33:41 GMT Subject: Yet another attempt at a safe eval() call References: Message-ID: <50e6da35$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Jan 2013 07:24:04 -0500, Terry Reedy wrote: > On 1/3/2013 6:25 PM, Grant Edwards wrote: >> >> I've written a small assembler in Python 2.[67], and it needs to >> evaluate integer-valued arithmetic expressions in the context of a >> symbol table that defines integer values for a set of names. The >> "right" thing is probably an expression parser/evaluator using ast, but >> it looked like that would take more code that the rest of the assembler >> combined, and I've got other higher-priority tasks to get back to. > > Will ast.literal_eval do what you want? No. Grant needs to support variables, not just literal constants, hence the symbol table. -- Steven From invalid at invalid.invalid Fri Jan 4 10:59:22 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jan 2013 15:59:22 +0000 (UTC) Subject: Yet another attempt at a safe eval() call References: <50e6da35$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-04, Steven D'Aprano wrote: > On Fri, 04 Jan 2013 07:24:04 -0500, Terry Reedy wrote: > >> On 1/3/2013 6:25 PM, Grant Edwards wrote: >>> >>> I've written a small assembler in Python 2.[67], and it needs to >>> evaluate integer-valued arithmetic expressions in the context of a >>> symbol table that defines integer values for a set of names. The >>> "right" thing is probably an expression parser/evaluator using ast, but >>> it looked like that would take more code that the rest of the assembler >>> combined, and I've got other higher-priority tasks to get back to. >> >> Will ast.literal_eval do what you want? > > No. Grant needs to support variables, not just literal constants, hence > the symbol table. Right. ast.literal_eval() doesn't even support arithmetic expressions involving only literal constats such as "3+1" (that's the bare minimum requirement). It would also be very highly desirable to allow expressions involving symblic constants such as "PC+1". Google has found me exapmles of ast-based code that does pretty much what I want, but I haven't tried it yet because of that solution's size and complexity. -- Grant Edwards grant.b.edwards Yow! I brought my BOWLING at BALL -- and some DRUGS!! gmail.com From alister.ware at ntlworld.com Fri Jan 4 13:13:08 2013 From: alister.ware at ntlworld.com (Alister) Date: Fri, 04 Jan 2013 18:13:08 GMT Subject: Yet another attempt at a safe eval() call References: <50e6da35$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 04 Jan 2013 13:33:41 +0000, Steven D'Aprano wrote: > On Fri, 04 Jan 2013 07:24:04 -0500, Terry Reedy wrote: > >> On 1/3/2013 6:25 PM, Grant Edwards wrote: >>> >>> I've written a small assembler in Python 2.[67], and it needs to >>> evaluate integer-valued arithmetic expressions in the context of a >>> symbol table that defines integer values for a set of names. The >>> "right" thing is probably an expression parser/evaluator using ast, >>> but it looked like that would take more code that the rest of the >>> assembler combined, and I've got other higher-priority tasks to get >>> back to. >> >> Will ast.literal_eval do what you want? > > No. Grant needs to support variables, not just literal constants, hence > the symbol table. as a thought why not processes the input string by exploding the literal constants into their numerical values as stage 1 this should result in a string that only contains numbers & mathematical symbols then reject any resultant string that contains any alpha characters. I have to agree that it is still a risky process. -- Loneliness is a terrible price to pay for independence. From sendtomrg at gmail.com Fri Jan 4 03:17:10 2013 From: sendtomrg at gmail.com (M.gowtham M.gowtham) Date: Fri, 4 Jan 2013 00:17:10 -0800 (PST) Subject: MRG.COM Message-ID: <4fa84d44-e0cb-42ca-93ce-7cd0bc1a307c@googlegroups.com> comp.lang.python From subbuuu at gmail.com Fri Jan 4 08:35:58 2013 From: subbuuu at gmail.com (user123) Date: Fri, 4 Jan 2013 05:35:58 -0800 (PST) Subject: Bias correction using histogram matching Message-ID: <69782000-dacd-4088-96ff-a1e5c29df109@googlegroups.com> I am trying to do the histogram matching of the simulated data to the observed data. The aim is to correct the bias in the simulated data by CDF matching CDFobs(y) = CDFsim(x). I could only reach to the stage of generating the CDFs. I got stuck in finding the transfer function. The image shows the CDF's and the the Transfer function in plot(c)http://s8.postimage.org/4txybzz8l/test.jpg. I am trying to replicate the same. Please help me in achieving the plot. Thanks in advance import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import interp1d import scipy.stats as st sim = st.gamma(1,loc=0,scale=0.8) # Simulated obs = st.gamma(2,loc=0,scale=0.7) # Observed x = np.linspace(0,4,1000) simpdf = sim.pdf(x) obspdf = obs.pdf(x) plt.plot(x,simpdf,label='Simulated') plt.plot(x,obspdf,'r--',label='Observed') plt.title('PDF of Observed and Simulated Precipitation') plt.legend(loc='best') plt.show() plt.figure(1) simcdf = sim.cdf(x) obscdf = obs.cdf(x) plt.plot(x,simcdf,label='Simulated') plt.plot(x,obscdf,'r--',label='Observed') plt.title('CDF of Observed and Simulated Precipitation') plt.legend(loc='best') plt.show() From sbremal at hotmail.com Fri Jan 4 10:50:58 2013 From: sbremal at hotmail.com (sbremal at hotmail.com) Date: Fri, 4 Jan 2013 15:50:58 +0000 Subject: 'subprocess.check_output' extra new line? Message-ID: Hi I wonder if the additional new line charachter at the end of the standard output capture is on purpose with 'subprocess.check_output'? >>> subprocess.check_output([ 'cygpath', 'C:\\' ]) '/cygdrive/c\n' If I do the same from the shell there is no extra new line (which is correct I believe): $ x=$(cygpath C:\\); echo "_${x}_" _/cygdrive/c_ Surely I have a workaround. I was more interested whether it was a design flaw. Cheers B. From rosuav at gmail.com Fri Jan 4 11:14:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 03:14:46 +1100 Subject: 'subprocess.check_output' extra new line? In-Reply-To: References: Message-ID: On Sat, Jan 5, 2013 at 2:50 AM, wrote: > > Hi > > I wonder if the additional new line charachter at the end of the standard output capture is on purpose with 'subprocess.check_output'? > >>>> subprocess.check_output([ 'cygpath', 'C:\\' ]) > '/cygdrive/c\n' > > If I do the same from the shell there is no extra new line (which is correct I believe): > > $ x=$(cygpath C:\\); echo "_${x}_" > _/cygdrive/c_ > > Surely I have a workaround. I was more interested whether it was a design flaw. What you may have there is the shell $( ) handling changing the program's output. Try piping the command into 'hd' or similar to see what it actually produces; it's entirely possible the \n is there, and the shell is stripping it. In any case, you can easily trim whitespace from inside Python. That would be your workaround, I think. ChrisA From sbremal at hotmail.com Fri Jan 4 12:51:33 2013 From: sbremal at hotmail.com (sbremal at hotmail.com) Date: Fri, 4 Jan 2013 17:51:33 +0000 Subject: 'subprocess.check_output' extra new line? In-Reply-To: References: , Message-ID: Very good point, you are absolutely right: # cygpath C:\\ | od -c 0000000 / c y g d r i v e / c \n 0000014 'bash' manual also confirms it: Command Substitution Command substitution allows the output of a command to replace the command name. There are two forms: $(command) or `command` Bash performs the expansion by executing command and replacing the command substitution with the ---> standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file) can be replaced by the equivalent but faster $(< file). When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by $, `, or \. The first backquote not preceded by a backslash terminates the command substitution. When using the $(command) form, all characters between the parentheses make up the command; none are treated specially. Command substitutions may be nested. To nest when using the backquoted form, escape the inner back- quotes with backslashes. If the substitution appears within double quotes, word splitting and pathname expansion are not per- formed on the results. Cheers B. ---------------------------------------- > Date: Sat, 5 Jan 2013 03:14:46 +1100 > Subject: Re: 'subprocess.check_output' extra new line? > From: rosuav at gmail.com > To: python-list at python.org > > On Sat, Jan 5, 2013 at 2:50 AM, wrote: > > > > Hi > > > > I wonder if the additional new line charachter at the end of the standard output capture is on purpose with 'subprocess.check_output'? > > > >>>> subprocess.check_output([ 'cygpath', 'C:\\' ]) > > '/cygdrive/c\n' > > > > If I do the same from the shell there is no extra new line (which is correct I believe): > > > > $ x=$(cygpath C:\\); echo "_${x}_" > > _/cygdrive/c_ > > > > Surely I have a workaround. I was more interested whether it was a design flaw. > > What you may have there is the shell $( ) handling changing the > program's output. Try piping the command into 'hd' or similar to see > what it actually produces; it's entirely possible the \n is there, and > the shell is stripping it. > > In any case, you can easily trim whitespace from inside Python. That > would be your workaround, I think. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list From andydtaylor at gmail.com Fri Jan 4 13:08:22 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Fri, 4 Jan 2013 10:08:22 -0800 (PST) Subject: Evaluate postgres boolean field Message-ID: Hi, I'm hoping for some help on a python script I need to query an api. I'm not a (Python) programmer ordinarily, but do plan to improve! Specifically I have a for loop evaluating a database row, which I think I can treat as a list. My [4] is a postgres boolean field, and I'm temporarily stuck on how to evaluate this to determine if I use the values in [1]. Could I have some advice on what to change? Also do let me know if you can recommend a good beginners python book. Data example: [13, 'Barbican Station', 'Barbican Station, London Underground Ltd., Aldersgate St, London, EC1A 4JA', '01010000E0E61000008851AB9E9803B9BF5BB6972294C2494000000000000000000000000000000000', True] Code: #!/usr/bin/python import psycopg2 #note that we have to import the Psycopg2 extras library! import psycopg2.extras import sys def main(): conn_string = "host='localhost' dbname='gisdb' user='postgres' password='#########'" # print the connection string we will use to connect print "Connecting to database\n ->%s" % (conn_string) conn = psycopg2.connect(conn_string) # HERE IS THE IMPORTANT PART, by specifying a name for the cursor # psycopg2 creates a server-side cursor, which prevents all of the # records from being downloaded at once from the server. cursor = conn.cursor('cursor_tube', cursor_factory=psycopg2.extras.DictCursor) cursor.execute('SELECT * FROM tubestations LIMIT 1000') # Because cursor objects are iterable we can just call 'for - in' on # the cursor object and the cursor will automatically advance itself # each iteration. # This loop should run 1000 times, assuming there are at least 1000 # records in 'my_table' row_count = 0 for row in cursor: row_count += 1 if row[4] = True print row[1] #print "row: %s %s\n" % (row_count, row) if __name__ == "__main__": main() Thanks! Andy From donarb at nwlink.com Fri Jan 4 13:50:50 2013 From: donarb at nwlink.com (donarb) Date: Fri, 4 Jan 2013 10:50:50 -0800 (PST) Subject: Evaluate postgres boolean field In-Reply-To: References: Message-ID: <9af870c7-6afb-40a9-becb-238f0e52a69d@googlegroups.com> On Friday, January 4, 2013 10:08:22 AM UTC-8, andyd... at gmail.com wrote: > Hi, > > I'm hoping for some help on a python script I need to query an api. I'm not a (Python) programmer ordinarily, but do plan to improve! > > Specifically I have a for loop evaluating a database row, which I think I can treat as a list. My [4] is a postgres boolean field, and I'm temporarily stuck on how to evaluate this to determine if I use the values in [1]. > > Could I have some advice on what to change? Also do let me know if you can recommend a good beginners python book. > > Data example: > > [13, 'Barbican Station', 'Barbican Station, London Underground Ltd., Aldersgate St, London, EC1A 4JA', '01010000E0E61000008851AB9E9803B9BF5BB6972294C2494000000000000000000000000000000000', True] > > > Code: > > #!/usr/bin/python > import psycopg2 > #note that we have to import the Psycopg2 extras library! > import psycopg2.extras > import sys > > def main(): > conn_string = "host='localhost' dbname='gisdb' user='postgres' password='#########'" > # print the connection string we will use to connect > print "Connecting to database\n ->%s" % (conn_string) > > conn = psycopg2.connect(conn_string) > > # HERE IS THE IMPORTANT PART, by specifying a name for the cursor > # psycopg2 creates a server-side cursor, which prevents all of the > # records from being downloaded at once from the server. > cursor = conn.cursor('cursor_tube', cursor_factory=psycopg2.extras.DictCursor) > cursor.execute('SELECT * FROM tubestations LIMIT 1000') > > # Because cursor objects are iterable we can just call 'for - in' on > # the cursor object and the cursor will automatically advance itself > # each iteration. > # This loop should run 1000 times, assuming there are at least 1000 > # records in 'my_table' > row_count = 0 > for row in cursor: > row_count += 1 > if row[4] = True > print row[1] > #print "row: %s %s\n" % (row_count, row) > > if __name__ == "__main__": > main() > > Thanks! > > > Andy Your code is pretty close to working, you just need to make a couple modifications. You are using the equals sign as an assignment, not a comparison, although the comparison and value are unnecessary since the field's value is either true or false. And you're missing a colon at the end of the condition. Note also that since you are using a DictCursor you can use column names to reference your row's fields, I guessed on the field names, but you should get the idea. for row in cursor: row_count += 1 if row['active']: print row['name'] From gordon at panix.com Fri Jan 4 14:06:52 2013 From: gordon at panix.com (John Gordon) Date: Fri, 4 Jan 2013 19:06:52 +0000 (UTC) Subject: Evaluate postgres boolean field References: Message-ID: In andydtaylor at gmail.com writes: > for row in cursor: > row_count += 1 > if row[4] = True > print row[1] Since row[4] is a boolean value, you should be able to just say: if row[4]: print row[1] -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From andydtaylor at gmail.com Sat Jan 5 07:24:14 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Sat, 5 Jan 2013 04:24:14 -0800 (PST) Subject: Evaluate postgres boolean field In-Reply-To: References: Message-ID: <5bc46274-c0ef-4d4b-9a44-87ef5ce468c0@googlegroups.com> Brilliant, thanks guys From jeltedeproft at hotmail.com Fri Jan 4 13:23:24 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Fri, 4 Jan 2013 10:23:24 -0800 (PST) Subject: problem with exam task for college Message-ID: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> hy everyone, for my exam this year i had to write a computer game on vpython (visualpython).we had to make a lunar lander game where the ship drops by gravity and is able to manouver to safely land on the moon.
right now i am completely stuck on trying to make the visual of the ship rotate.
i'm new to this forum, i guess i'll just paste my code here. Everything works fine on the game, except the rotation of the ship. however the when you press "up" the after rotating the velocity actually changes direction , but the visual doesn't. i'm getting kinda nervous because due date is coming, any help is appreciated, here is the code: from visual import * import time import math import random from datetime import datetime import operator class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter = brandstofmeter() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 while t<999999999: time.sleep(0.01) self.brandstofmeter.update self.ruimteschip.update(dt) t = t + dt class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter(object): def __init__(self): self.size = (25,45) axis = 0 self.pos = (220,345) self.view = brandstofmeter_view(self) def update(self): while True: if scene.kb.keys: s = scene.kb.getkey() if (s == 'up'): self.view.update(self) class brandstofmeter_view(object): def __init__(self,owner): self.owner = owner meter = box(pos = owner.pos,size = owner.size,color = color.green) def update (self,owner): self.size = self.size - (0,0.45) class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.acceleration = vector(0,-88,0) self.axis = (1,0,0) self.hoek = (90*math.pi)/180 self.graden = math.degrees(self.hoek) self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek)) self.velocity = vector(0,0,0) self.angle = (1,0,0) self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt a = 0 b = 0 if scene.kb.keys: a = a + 0.001 s = scene.kb.getkey() if (s == "up"): self.velocity = self.velocity + self.gas self.vlam.visible = True b = b + 2 if (s == "left"): self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) c = list(self.frame.axis) c[2] -= 0.1 c = tuple(c) c = self.frame.axis if (s == "right") : self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) c = list(self.frame.axis) c[2] += 0.1 c = tuple(c) c = self.frame.axis if (a == 0): self.vlam.visible = False if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 self.view.update(self) class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos From rosuav at gmail.com Fri Jan 4 13:59:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 05:59:06 +1100 Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: On Sat, Jan 5, 2013 at 5:23 AM, wrote: > hy everyone, for my exam this year i had to write a computer game on vpython (visualpython).we had to make a lunar lander game where the ship drops by gravity and is able to manouver to safely land on the moon.
right now i am completely stuck on trying to make the visual of the ship rotate.
i'm new to this forum, i guess i'll just paste my code here. Everything works fine on the game, except the rotation of the ship. however the when you press "up" the after rotating the velocity actually changes direction , but the visual doesn't. i'm getting kinda nervous because due date is coming, any help is appreciated, here is the code: Ha, I remember playing a game along those lines that was drawn in pure ASCII text... the visuals change, the concept doesn't :) > self.brandstofmeter = brandstofmeter() > self.ruimteschip = ruimteschip() I'm having trouble understanding these names, and am guessing they're either aggressively abbreviated or not English, but it's hard to tell which. It's conventional in Python code to capitalize separate words in class names, and to either capitalize or use underscores (more usually the latter) between words in instance variables and method names. Google tells me that brandstofmeter might mean "Babylon 9" and ruimteschip is German for "spaceship", but that would be more obvious if I were not trying to figure out what "brands-t-of-meter" might mean. > self.brandstofmeter.update > self.ruimteschip.update(dt) But I'm guessing that this right here is your problem. The second update method is called, but the first one isn't. Python evaluates the name, then does nothing with it. Unlike in BASIC, Python allows you to manipulate functions just like you do integers and strings, so actually _calling_ a function requires the parentheses, empty if you don't need any args: self.brandstofmeter.update() > for i in random.sample(range (-250,250),20): > for j in random.sample(range (-375,375),20): > sterren = points(pos = [i,j,0],size = 2, color=color.white) Without seeing the definition of points() anywhere, I can't say whether this is effective or not; or is that something from module visual? This is where "from x import *" can quickly get confusing - it's not obvious whether the name 'points' has come from your code or someone else's. The result is being put into sterren and then ignored. You can happily omit this if you don't need that return value; Python will quietly do nothing with it: points(pos = [i,j,0],size = 2, color=color.white) > class brandstofmeter_view(object): > def __init__(self,owner): > self.owner = owner > meter = box(pos = owner.pos,size = owner.size,color = color.green) > > def update (self,owner): > self.size = self.size - (0,0.45) Is self.size set anywhere? You may find that, when you fix the above problem with this method not being called, it begins bombing. What data type is self.size supposed to be? If it's a tuple, this won't work, and you'll need to do something like: self.size = (self.size[0], self.size[1]-0.45) Or alternatively, use a mutable type such as a list. (Possibly the vector that you use elsewhere will do. I'm not familiar with that class, so it may be that you can subtract a tuple from it.) > def update(self,dt): > self.velocity = self.velocity + (self.acceleration * dt) > self.pos = self.pos + self.velocity * dt Tip: Use augmented assignment for these sorts of statements. It's clearer what you're doing: self.velocity += self.acceleration * dt self.pos += self.velocity * dt Your class structure feels overengineered, to me. The model/view/controller system is overkill in most of the places it's used. Lots of your code is just passing information around from place to place; instead of the separate _view class, you could simply have a class ruimteschip that knows how to draw itself. Final comment: Your code is fairly well laid out, and your query is clear. Thanks! It's so much easier to read than something that's vague about what's actually wrong :) Just one thing. Your subject line doesn't actually say what's going on (though again, your honesty about it being an exam task is appreciated); something describing the problem would have been helpful. But that's fairly minor. Your post is a joy to answer. Thanks! Chris Angelico From rosuav at gmail.com Fri Jan 4 14:00:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 06:00:53 +1100 Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: On Sat, Jan 5, 2013 at 5:59 AM, Chris Angelico wrote: > Google tells me that brandstofmeter might mean "Babylon 9" And by the way, in case it didn't come across, I'm jesting there. What I mean is that Google didn't have any useful and obvious results indicating what this actually means. But I'm guessing it's a fuel or altitude gauge. ChrisA From joshua.landau.ws at gmail.com Fri Jan 4 14:18:53 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Fri, 4 Jan 2013 19:18:53 +0000 Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: On 4 January 2013 19:00, Chris Angelico wrote: > On Sat, Jan 5, 2013 at 5:59 AM, Chris Angelico wrote: > > Google tells me that brandstofmeter might mean "Babylon 9" > > And by the way, in case it didn't come across, I'm jesting there. What > I mean is that Google didn't have any useful and obvious results > indicating what this actually means. But I'm guessing it's a fuel or > altitude gauge. > It might measure a brand in femtometers ;). But, seriously, it's Dutch for Fuel Gauge. Google told me, in case you think I know Dutch, but it's in the Python Spirit either way. ruimteschip -> Spaceship hoek -> angle sterren -> stars poot -> leg vlam -> flame graden -> degrees maan -> moon I'd say they'd be good names if you're in the Netherlands. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Jan 4 14:30:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 06:30:42 +1100 Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: On Sat, Jan 5, 2013 at 6:18 AM, Joshua Landau wrote: > It might measure a brand in femtometers ;). LOL! > But, seriously, it's Dutch for Fuel Gauge. Google told me, in case you think > I know Dutch, but it's in the Python Spirit either way. > > ruimteschip -> Spaceship > hoek -> angle > sterren -> stars > poot -> leg > vlam -> flame > graden -> degrees > maan -> moon > > I'd say they'd be good names if you're in the Netherlands. Yep, I'd agree, those are fine names. I still would expect to see the class names in uppercase though; a single leading capital letter strongly suggests that it's a single-word name, where all-lowercase could just be rammed up together non-delimited. But yeah, that's a pretty minor point. Those name are well suited to their tasks. (And quite a few of them can be figured out from context without even turning to the translator, like hoek == angle.) ChrisA From jeltedeproft at hotmail.com Fri Jan 4 15:01:10 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Fri, 4 Jan 2013 12:01:10 -0800 (PST) Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: woow jeezes, thanks for the amazingly fast and detailed response, you guys are amazing. let's clear a few things up : 1) points is a module in vpython to make points, the points do in fact appear although its not really the effect i intended to have, the points are "lined up" in stead of randomly separated, if you know what i mean 2) sorry for the dutch names :) 3) i put the parenteces there and then i got a bunch of errors which i fixed 2 problems: a) my program seems to be stuck in the update phase of brandstoftank(=fuel tank), it doesnt get to the update of the spaceship b) the problem i originally described in my first post was not resolved, by means of elimination i could conclude that the problem situates itself in this lines : if (s == "left"): self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) c = list(self.frame.axis) c[2] -= 0.1 c = tuple(c) c = self.frame.axis if (s == "right") : self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) c = list(self.frame.axis) c[2] += 0.1 c = tuple(c) c = self.frame.axis i will put the full revisited code here : from visual import * import time import math import random from datetime import datetime import operator class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter_view = brandstofmeter_view() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 while t<999999999: time.sleep(0.01) self.brandstofmeter_view.update() self.ruimteschip.update(dt) t = t + dt class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter_view(object): def __init__(self): axis = 0 self.pos = (220,345) self.meter = box(pos = self.pos, lenght = 25, height = 45,color = color.green) def update (self): s = scene.kb.getkey() if (s == "up"): self.meter.height = self.meter.height - 1 class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.acceleration = vector(0,-88,0) self.axis = (1,0,0) self.hoek = (90*math.pi)/180 self.graden = math.degrees(self.hoek) self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek)) self.velocity = vector(0,0,0) self.angle = (1,0,0) self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt a = 0 b = 0 if scene.kb.keys: a = a + 0.001 s = scene.kb.getkey() if (s == "up"): self.velocity = self.velocity + self.gas self.vlam.visible = True b = b + 2 if (s == "left"): self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) c = list(self.frame.axis) c[2] -= 0.1 c = tuple(c) c = self.frame.axis if (s == "right") : self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) c = list(self.frame.axis) c[2] += 0.1 c = tuple(c) c = self.frame.axis if (a == 0): self.vlam.visible = False if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 self.view.update(self) class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos thanks again, are you guys getting paid for this or is this voluntarily? either way i really appreciate it From jeltedeproft at hotmail.com Fri Jan 4 15:01:10 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Fri, 4 Jan 2013 12:01:10 -0800 (PST) Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: woow jeezes, thanks for the amazingly fast and detailed response, you guys are amazing. let's clear a few things up : 1) points is a module in vpython to make points, the points do in fact appear although its not really the effect i intended to have, the points are "lined up" in stead of randomly separated, if you know what i mean 2) sorry for the dutch names :) 3) i put the parenteces there and then i got a bunch of errors which i fixed 2 problems: a) my program seems to be stuck in the update phase of brandstoftank(=fuel tank), it doesnt get to the update of the spaceship b) the problem i originally described in my first post was not resolved, by means of elimination i could conclude that the problem situates itself in this lines : if (s == "left"): self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) c = list(self.frame.axis) c[2] -= 0.1 c = tuple(c) c = self.frame.axis if (s == "right") : self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) c = list(self.frame.axis) c[2] += 0.1 c = tuple(c) c = self.frame.axis i will put the full revisited code here : from visual import * import time import math import random from datetime import datetime import operator class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter_view = brandstofmeter_view() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 while t<999999999: time.sleep(0.01) self.brandstofmeter_view.update() self.ruimteschip.update(dt) t = t + dt class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter_view(object): def __init__(self): axis = 0 self.pos = (220,345) self.meter = box(pos = self.pos, lenght = 25, height = 45,color = color.green) def update (self): s = scene.kb.getkey() if (s == "up"): self.meter.height = self.meter.height - 1 class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.acceleration = vector(0,-88,0) self.axis = (1,0,0) self.hoek = (90*math.pi)/180 self.graden = math.degrees(self.hoek) self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek)) self.velocity = vector(0,0,0) self.angle = (1,0,0) self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt a = 0 b = 0 if scene.kb.keys: a = a + 0.001 s = scene.kb.getkey() if (s == "up"): self.velocity = self.velocity + self.gas self.vlam.visible = True b = b + 2 if (s == "left"): self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) c = list(self.frame.axis) c[2] -= 0.1 c = tuple(c) c = self.frame.axis if (s == "right") : self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) c = list(self.frame.axis) c[2] += 0.1 c = tuple(c) c = self.frame.axis if (a == 0): self.vlam.visible = False if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 self.view.update(self) class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos thanks again, are you guys getting paid for this or is this voluntarily? either way i really appreciate it From rosuav at gmail.com Fri Jan 4 15:36:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 07:36:14 +1100 Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: On Sat, Jan 5, 2013 at 7:01 AM, wrote: > woow jeezes, thanks for the amazingly fast and detailed response, you guys are amazing. > > thanks again, are you guys getting paid for this or is this voluntarily? either way i really appreciate it We're all volunteers (and it's now 7:30AM Saturday and I've been up all night, so this post quite probably doesn't carry the hallmarks of intelligence). To be more strictly correct, we are members of a community - people helping people. Far as I know, there's not one person here who has never asked a question. I tend to join a mailing list to ask one or more questions, and hang around answering them long after my personal needs are satisfied, kinda like seeding back a torrent after you've downloaded it. We answer questions for a variety of reasons. Partly, because this is one of the best forms of help that the Python community can offer, which means that supporting Python in this way strengthens the language. Partly, because our names are connected to our posts, and we are seen to be helpful people (and, since the list/newsgroup is archived on the web, potential employers who search the web for our names will see us being helpful and knowledgeable). Partly, because we're repaying the community for the benefits we've gained from it. Partly, because in answering questions, we ourselves learn. And there are other reasons too. > 2) sorry for the dutch names :) No probs; as was said in several follow-ups, those are well-chosen names. > b) the problem i originally described in my first post was not resolved, by means of elimination i could conclude that the problem situates itself in this lines : > > c = list(self.frame.axis) > c[2] -= 0.1 > c = tuple(c) > c = self.frame.axis This code is looking quite messy, here. But the most obvious problem is that you're setting up 'c' to be the modified axis, and then... overwriting c with the old axis. Try doing the assignment the other way in the last line: self.frame.axis = c Alternatively, you could do the whole thing more cleanly by unpacking and then repacking the tuple: (x, y, z) = self.frame.axis self.frame.axis = (x, y, z-0.1) Two lines that do the job of the above four. Note that the parentheses are optional here; they look nice since axis is holding coordinates, but Python doesn't care. Hope that helps! ChrisA From python at mrabarnett.plus.com Fri Jan 4 14:17:30 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 04 Jan 2013 19:17:30 +0000 Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: <50E72ACA.8010707@mrabarnett.plus.com> On 2013-01-04 18:59, Chris Angelico wrote: > On Sat, Jan 5, 2013 at 5:23 AM, wrote: >> hy everyone, for my exam this year i had to write a computer game on vpython (visualpython).we had to make a lunar lander game where the ship drops by gravity and is able to manouver to safely land on the moon.
right now i am completely stuck on trying to make the visual of the ship rotate.
i'm new to this forum, i guess i'll just paste my code here. Everything works fine on the game, except the rotation of the ship. however the when you press "up" the after rotating the velocity actually changes direction , but the visual doesn't. i'm getting kinda nervous because due date is coming, any help is appreciated, here is the code: > > Ha, I remember playing a game along those lines that was drawn in pure > ASCII text... the visuals change, the concept doesn't :) > >> self.brandstofmeter = brandstofmeter() >> self.ruimteschip = ruimteschip() > > I'm having trouble understanding these names, and am guessing they're > either aggressively abbreviated or not English, but it's hard to tell > which. It's conventional in Python code to capitalize separate words > in class names, and to either capitalize or use underscores (more > usually the latter) between words in instance variables and method > names. Google tells me that brandstofmeter might mean "Babylon 9" and > ruimteschip is German for "spaceship", but that would be more obvious > if I were not trying to figure out what "brands-t-of-meter" might > mean. > [snip] Google Translate says it's Dutch: ruimteschip -> spaceship brandstofmeter -> fuel gauge From jeltedeproft at hotmail.com Sat Jan 5 07:24:15 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Sat, 5 Jan 2013 04:24:15 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: <9ba228d7-0654-412a-9b55-c2a07aedbe24@googlegroups.com> hy again,thanx, i updated my code with your more efficient approach :), so that possibly resolves problem number 2, but still leaves me with problem n?1, my code is still stuck in the first update of the fuel tank (brandstoftank), for the sake of your easyness i'll paste the code again from visual import * import time import math import random from datetime import datetime import operator class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter_view = brandstofmeter_view() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 while t<999999999: time.sleep(0.01) self.brandstofmeter_view.update() self.ruimteschip.update(dt) t = t + dt class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter_view(object): def __init__(self): axis = 0 self.pos = (220,345) self.meter = box(pos = self.pos, lenght = 25, height = 45,color = color.green) def update (self): s = scene.kb.getkey() if (s == "up"): self.meter.height = self.meter.height - 1 class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.acceleration = vector(0,-88,0) self.axis = (1,0,0) self.hoek = (90*math.pi)/180 self.graden = math.degrees(self.hoek) self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek)) self.velocity = vector(0,0,0) self.angle = (1,0,0) self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt a = 0 b = 0 if scene.kb.keys: a = a + 0.001 s = scene.kb.getkey() if (s == "up"): self.velocity = self.velocity + self.gas self.vlam.visible = True b = b + 2 if (s == "left"): self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) (x,y,z) = self.frame.axis self.frame.axis = (x,y,z-0.1) if (s == "right") : self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) (x,y,z) = self.frame.axis self.frame.axis = (x,y,z+0.1) if (a == 0): self.vlam.visible = False if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 self.view.update(self) class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos From rosuav at gmail.com Sat Jan 5 07:39:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 23:39:27 +1100 Subject: problem with exam task for college In-Reply-To: <9ba228d7-0654-412a-9b55-c2a07aedbe24@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> <9ba228d7-0654-412a-9b55-c2a07aedbe24@googlegroups.com> Message-ID: On Sat, Jan 5, 2013 at 11:24 PM, wrote: > hy again,thanx, i updated my code with your more efficient approach :), so that possibly resolves problem number 2, but still leaves me with problem n?1, my code is still stuck in the first update of the fuel tank (brandstoftank), for the sake of your easyness i'll paste the code again Not sure what you mean by "stuck", but is it that scene.kb.getkey() waits for a key? ChrisA From jeltedeproft at hotmail.com Sat Jan 5 08:14:54 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Sat, 5 Jan 2013 05:14:54 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: that's probably it, how do i solve it? From rosuav at gmail.com Sat Jan 5 08:32:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 00:32:21 +1100 Subject: problem with exam task for college In-Reply-To: References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: On Sun, Jan 6, 2013 at 12:14 AM, wrote: > that's probably it, how do i solve it? I'm afraid I can't help you there. Check out the docs for the getkey function and see if it can be put into non-blocking mode; if not, you may have to completely change your model. For instance, if I were writing this sort of game today, I'd probably use a GUI system that fires an event whenever a key is pressed/released, and then have a timer-tick for the descent, rather than explicit sleep() calls. But it depends on your UI facilities. The LANDER.BAS that I played with - yes, it was written in BASIC - was fully prompt-driven. To move to the next time unit, you had to answer all its prompts. Advantage: No need to code a Pause feature. Disadvantage: The game ended up way too scientific, like D&D combat. (It's amazing how your party of bumbling characters suddenly become lightning-fast strategists as soon as initiative is rolled!) ChrisA From jeltedeproft at hotmail.com Mon Jan 7 11:22:28 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Mon, 7 Jan 2013 08:22:28 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: <9d4db036-b840-4c2e-8cfb-edc2afb7bbaa@googlegroups.com> ok after another round of reparations, my update works again and it updates the fuel meter, but i still can't get the view of the spaceship to rotate, for now only the direction the spaceship accelerates when pressing "up" changes after a rotation, but the spaceship itself keeps pointing up. This is the code for the rotating : p.s : the problem has to be in this code because the update of the view of the position of the spaceship does work. def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt a = 0 b = 0 if scene.kb.keys: a = a + 0.001 s = scene.kb.getkey() if (s == "up"): if self.zicht.meter.height != 0: self.velocity = self.velocity + self.gas self.vlam.visible = True b = b + 2 self.zicht.meter.height = self.zicht.meter.height - 0.1 self.zicht.update if (s == "left"): self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) (x,y,z) = self.frame.axis self.frame.axis = (x,y,z-0.1) if (s == "right") : self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) (x,y,z) = self.frame.axis self.frame.axis = (x,y,z+0.1) if (a == 0): self.vlam.visible = False From vincent.vandevyvre at swing.be Mon Jan 7 12:40:26 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Mon, 07 Jan 2013 18:40:26 +0100 Subject: problem with exam task for college In-Reply-To: <9d4db036-b840-4c2e-8cfb-edc2afb7bbaa@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> <9d4db036-b840-4c2e-8cfb-edc2afb7bbaa@googlegroups.com> Message-ID: <50EB088A.6010107@swing.be> Le 07/01/13 17:22, jeltedeproft at hotmail.com a ?crit : > ok after another round of reparations, my update works again and it updates the fuel meter, but i still can't get the view of the spaceship to rotate, for now only the direction the spaceship accelerates when pressing "up" changes after a rotation, but the spaceship itself keeps pointing up. This is the code for the rotating : p.s : the problem has to be in this code because the update of the view of the position of the spaceship does work. > > > def update(self,dt): > self.velocity = self.velocity + (self.acceleration * dt) > self.pos = self.pos + self.velocity * dt > a = 0 > b = 0 > if scene.kb.keys: > a = a + 0.001 > s = scene.kb.getkey() > if (s == "up"): > if self.zicht.meter.height != 0: > self.velocity = self.velocity + self.gas > self.vlam.visible = True > b = b + 2 > self.zicht.meter.height = self.zicht.meter.height - 0.1 > self.zicht.update > if (s == "left"): > self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1)) > (x,y,z) = self.frame.axis > self.frame.axis = (x,y,z-0.1) > if (s == "right") : > self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1)) > (x,y,z) = self.frame.axis > self.frame.axis = (x,y,z+0.1) > if (a == 0): > self.vlam.visible = False Are you sure with this code: (x,y,z) = self.frame.axis ? frame.axis is a 'cvisual.vector' and this unpacking cause a program crashes with a segfault. For left-rigth moves of the LEM, this code seems works: -------------------------------------- if scene.kb.keys: key = scene.kb.getkey() if key == "left": # Set left deviation self.frame.axis -= (0, 0, 0.05) self.gas = vector(-sin(self.angle), cos(self.angle)) elif key == "right": # Set right deviation self.frame.axis += (0, 0, 0.05) self.gas = vector(sin(self.angle), cos(self.angle)) elif key == "up": self.deviate() def deviate(self): # Set modified velocity self.frame.velocity += self.gas self.frame.pos += self.frame.velocity # Reset falling velocity self.frame.velocity -= self.gas -------------------------------------- with angle = PI / 2.0 -- Vincent V.V. Oqapy . Qarte . PaQager From jeltedeproft_8 at hotmail.com Sun Jan 13 07:29:19 2013 From: jeltedeproft_8 at hotmail.com (jeltedeproft_8 at hotmail.com) Date: Sun, 13 Jan 2013 04:29:19 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: sorry for the extremely late reply, i have been very very busy :s i implemented the solution that was posted in the second to last post. but now it gets a little confusing because i think a couple terms where deleted that i refered to in other code blocks, so once again i''l post the full code here from visual import * import time import math import random from datetime import datetime import operator class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter = brandstofmeter() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 self.ruimteschip.updatemeter = False while t<999999999: time.sleep(0.01) self.ruimteschip.update(dt) t = t + dt if self.ruimteschip.updatemeter == True: self.brandstofmeter.update class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter(object): def __init__(self): axis = 0 self.pos = (210,345) self.length = 25 self.height = 45 self.meter = box(pos = self.pos, length = self.length, height = self.height,color = color.green) def update(self): self.height = self.height - 0.2 print "ok" class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.acceleration = vector(0,-88,0) self.axis = (1,0,0) self.hoek = (90*math.pi)/180 self.graden = math.degrees(self.hoek) self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek)) self.velocity = vector(0,0,0) self.angle = pi / 2 self.updatemeter = False self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame self.zicht = brandstofmeter() def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt if scene.kb.keys: key = scene.kb.getkey() if key == "left": # Set left deviation self.frame.axis -= (0, 0, 0.05) self.gas = vector(-sin(self.angle), cos(self.angle)) elif key == "right": # Set right deviation self.frame.axis += (0, 0, 0.05) self.gas = vector(sin(self.angle), cos(self.angle)) elif key == "up": self.deviate() def deviate(self): # Set modified velocity self.frame.velocity += self.gas self.frame.pos += self.frame.velocity # Reset falling velocity self.frame.velocity -= self.gas if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 self.view.update(self) class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos From jeltedeproft at hotmail.com Sun Jan 13 07:48:29 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Sun, 13 Jan 2013 04:48:29 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: corrected a bit, loop works, gas doesn't work from visual import * import time import math import random from datetime import datetime import operator class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter = brandstofmeter() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 self.ruimteschip.updatemeter = False while t<999999999: time.sleep(0.01) self.ruimteschip.update(dt) t = t + dt if self.ruimteschip.updatemeter == True: self.brandstofmeter.update class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter(object): def __init__(self): axis = 0 self.pos = (210,345) self.length = 25 self.height = 45 self.meter = box(pos = self.pos, length = self.length, height = self.height,color = color.green) def update(self): self.height = self.height - 0.2 print "ok" class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.acceleration = vector(0,-88,0) self.axis = (1,0,0) self.hoek = (90*math.pi)/180 self.graden = math.degrees(self.hoek) self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek)) self.velocity = vector(0,0,0) self.angle = pi / 2 self.updatemeter = False self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame self.zicht = brandstofmeter() def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt if scene.kb.keys: key = scene.kb.getkey() if key == "left": # linkerafwijking self.frame.axis -= (0, 0, 0.05) self.gas = vector(-sin(self.angle), cos(self.angle)) self.vlam.visible = True self.updatemeter = True elif key == "right": # rechterafwijking self.frame.axis += (0, 0, 0.05) self.gas = vector(sin(self.angle), cos(self.angle)) elif key == "up": self.deviate() self.vlam.visible = False self.updatemeter = False if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 self.view.update(self) def deviate(self): # zet veranderde snelheid self.frame.velocity += self.gas self.frame.pos += self.frame.velocity # Reset valsnelheid self.frame.velocity -= self.gas class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos self.frame.velocity = owner.velocity From jeltedeproft at hotmail.com Sun Jan 13 08:57:41 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Sun, 13 Jan 2013 05:57:41 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: <02d0ea1d-e810-4f30-8af1-320d675a2c65@googlegroups.com> this is again a newer version, right now the velocity does in fact turn, but the view doesn't follow, it keeps the ship vertical. i'm also having trouble letting the flame appear when pressing the "up" button and when the ship rotates the horizontal velocity keeps getting bigger and bigger i also have to make the game end when the ship hits the moon on the wrong place i'm kinda stressed out because this has to be done by the 15th i've been studying like crazy the past week. If anyone could help me out i will deeply appreciate it, here is the code from visual import * import time import math import random from datetime import datetime import operator class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter = brandstofmeter() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 self.ruimteschip.updatemeter = False while t<999999999: time.sleep(0.01) self.ruimteschip.update(dt) t = t + dt if self.ruimteschip.updatemeter == True: self.brandstofmeter.update class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter(object): def __init__(self): axis = 0 self.pos = (210,345) self.length = 25 self.height = 45 self.meter = box(pos = self.pos, length = self.length, height = self.height,color = color.green) def update(self): self.height = self.height - 0.2 print "ok" class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.acceleration = vector(0,-20,0) self.axis = (1,0,0) self.hoek = (90*math.pi)/180 self.graden = math.degrees(self.hoek) self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek)) self.velocity = vector(0,0,0) self.angle = pi / 2 self.updatemeter = False self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame self.zicht = brandstofmeter() def update(self,dt): self.velocity = self.velocity + (self.acceleration * dt) self.pos = self.pos + self.velocity * dt print self.velocity if scene.kb.keys: key = scene.kb.getkey() if key == "left": # linkerafwijking self.frame.axis -= (0, 0, 0.05) self.gas = vector(-sin(self.angle), cos(self.angle)) self.vlam.visible = True self.updatemeter = True elif key == "right": # rechterafwijking self.frame.axis += (0, 0, 0.05) self.gas = vector(sin(self.angle), cos(self.angle)) elif key == "up": self.velocity += self.gas self.frame.pos += self.velocity else: self.vlam.visible = False self.updatemeter = False self.velocity -= self.gas if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 self.view.update(self) class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis, velocity = owner.velocity) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos self.frame.velocity = owner.velocity From oscar.j.benjamin at gmail.com Sun Jan 13 12:28:42 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 13 Jan 2013 17:28:42 +0000 Subject: problem with exam task for college In-Reply-To: <02d0ea1d-e810-4f30-8af1-320d675a2c65@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> <02d0ea1d-e810-4f30-8af1-320d675a2c65@googlegroups.com> Message-ID: On 13 January 2013 13:57, wrote: > this is again a newer version, right now the velocity does in fact turn, but the view doesn't follow, it keeps the ship vertical. > > i'm also having trouble letting the flame appear when pressing the "up" button > > and when the ship rotates the horizontal velocity keeps getting bigger and bigger > > i also have to make the game end when the ship hits the moon on the wrong place > > i'm kinda stressed out because this has to be done by the 15th i've been studying like crazy the past week. If anyone could help me out i will deeply appreciate it, here is the code > [SNIP] > > def update(self,dt): > self.velocity = self.velocity + (self.acceleration * dt) > self.pos = self.pos + self.velocity * dt > print self.velocity > > if scene.kb.keys: > key = scene.kb.getkey() > if key == "left": > # linkerafwijking > self.frame.axis -= (0, 0, 0.05) > self.gas = vector(-sin(self.angle), cos(self.angle)) > self.vlam.visible = True > self.updatemeter = True > > elif key == "right": > # rechterafwijking > self.frame.axis += (0, 0, 0.05) > self.gas = vector(sin(self.angle), cos(self.angle)) > > elif key == "up": > self.velocity += self.gas > self.frame.pos += self.velocity > else: > self.vlam.visible = False > self.updatemeter = False > self.velocity -= self.gas > > if self.pos.x > 250: > self.pos.x = -250 > if self.pos.x < -250: > self.pos.x = 250 > self.view.update(self) [SNIP] The function above is poorly organised. You should break this into several logical steps: 1) Process keypresses to update discrete state variables (such as whether or not the ship is thrusting. 2) Compute from the discrete state variables of the system what the acceleration will be, e.g.: acceleration = gravity if thrusting: acceleration += gas 3) Only once the acceleration is known apply the formulas to update the continuous state (position/velocity) of your system. If you rearrange it like this then you will probably be able to fix the logic bugs in the function above. In particular it is important that there should be only one place where you actually change each kind of state variable (velocity is modified in three places in the function above and I'm sure that this is related to the bugs you are having). Similar considerations apply to updating the angle of the ship. Also the update formula for the position is wrong. If I've understood your physics correctly, you should be using the equations of constant acceleration (my students know these as the "suvat" equations). In that case the formula should look like: newposition = oldposition + oldvelocity*dt + acceleration*dt**2 newvelocity = oldvelocity + acceleration*dt Your code is missing the quadratic term at the end of the first line above. (Actually the situation would be more complicated than this when the ship is also rotating but I don't understand exactly what your rotation physics is supposed to be). Oscar From stefaang at gmail.com Mon Jan 14 07:57:47 2013 From: stefaang at gmail.com (stefaang at gmail.com) Date: Mon, 14 Jan 2013 04:57:47 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: <8649092b-fd1d-4131-84c3-9c7fc60183fa@googlegroups.com> Hi, I only skimmed through the code, but I think your problem resides at the "while True" in your brandstofmeter update(). This function never stops.. From jeltedeproft at hotmail.com Mon Jan 14 11:01:03 2013 From: jeltedeproft at hotmail.com (jeltedeproft at hotmail.com) Date: Mon, 14 Jan 2013 08:01:03 -0800 (PST) Subject: problem with exam task for college In-Reply-To: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> References: <6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com> Message-ID: <54dc9b58-8a7b-4a7a-a6d1-8d9a02a0477c@googlegroups.com> this is what i have right now, it tells me i can't multiply a vector with a vector, i have to find a way to multiply the speed with the updated angle (=hoek in dutch) code : from visual import * import time import math import random class lunar_lander(object): def __init__(self): scene.title = 'mini star wars' scene.width = 375 scene.height = 550 scene.center = (0,0) self.pos = (0,0) self.axis = 0 self.brandstofmeter = brandstofmeter() self.ruimteschip = ruimteschip() self.view = game_view(self) def play(self): t=0 dt=0.01 while t<999999999: time.sleep(0.01) self.brandstofmeter.update self.ruimteschip.update(dt) t = t + dt class game_view(object): def __init__(self,owner): autoscale=True box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white) box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white) box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white) box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white) maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red) maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green) maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red) maanc = curve(pos=[(80,-347),(140,-347)],color=color.green) maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-338)],color=color.red) for i in random.sample(range (-250,250),20): for j in random.sample(range (-375,375),20): sterren = points(pos = [i,j,0],size = 2, color=color.white) class brandstofmeter(object): def __init__(self): self.size = (25,45) axis = 0 self.pos = (220,345) self.view = brandstofmeter_view(self) def update(self): while True: if scene.kb.keys: s = scene.kb.getkey() if (s == 'up'): self.view.update(self) class brandstofmeter_view(object): def __init__(self,owner): self.owner = owner meter = box(pos = owner.pos,size = owner.size,color = color.green) def update (self,owner): self.size = self.size - (0,0.45) class ruimteschip(object): def __init__(self): self.pos = vector(0,330) self.axis = (1,0,0) self.view = ruimteschip_view(self) self.vlam = self.view.vlam self.frame = self.view.frame self.hoek = pi / 2 def update(self,dt): zwaartekracht = vector(0,-2,0) self.gas = vector(0,10,0) self.acceleration = zwaartekracht self.axis = (1,0,0) if scene.kb.keys: s = scene.kb.getkey() if (s == "up"): self.acceleration =+ self.gas * vector(math.cos(self.hoek),math.sin(self.hoek)) if (s == "left"): self.hoek =+ pi/12 if (s == "right") : self.hoek =- pi/12 self.pos = self.pos + self.acceleration if self.pos.x > 250: self.pos.x = -250 if self.pos.x < -250: self.pos.x = 250 if self.acceleration != (0,-2,0): self.vlam.visible = True else : self.vlam.visible = False self.view.update(self) class ruimteschip_view(object): def __init__(self,owner): self.owner = owner self.frame = frame(pos = owner.pos,axis = owner.axis) self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)]) self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(12,46),(9,44),(3,39),(0,39)]) self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)]) self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)]) self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)]) def update(self,owner): self.frame.axis = owner.axis self.frame.pos = owner.pos From tdldev at gmail.com Fri Jan 4 23:02:52 2013 From: tdldev at gmail.com (Verde Denim) Date: Fri, 04 Jan 2013 23:02:52 -0500 Subject: import of ttk Message-ID: <50E7A5EC.9080203@gmail.com> In reading through one of the learning articles, I have a bit of code that imports ttk, but I apparently don't have this installed. I've looked up the svn checkout for python-tk, and have checked it out (read-only), but still get the same error. I'm running 2.6.6 python, if that helps. The article I'm looking at is here - http://www.zetcode.com/gui/tkinter/introduction/ Any input is appreciated. From tjreedy at udel.edu Fri Jan 4 23:39:31 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jan 2013 23:39:31 -0500 Subject: import of ttk In-Reply-To: <50E7A5EC.9080203@gmail.com> References: <50E7A5EC.9080203@gmail.com> Message-ID: On 1/4/2013 11:02 PM, Verde Denim wrote: > In reading through one of the learning articles, I have a bit of code > that imports ttk, but I apparently don't have this installed. I've > looked up the svn checkout for python-tk, and have checked it out > (read-only), but still get the same error. I'm running 2.6.6 python, if > that helps. Show the line of code that did not work and the traceback. What system are you running on and what tcl/tk installation does it have? ttk is included with any 8.5 installation. tile is often included with 8.4 installations and should be picked up as well. The article I'm looking at is here - > http://www.zetcode.com/gui/tkinter/introduction/ -- Terry Jan Reedy From tdldev at gmail.com Sat Jan 5 14:21:32 2013 From: tdldev at gmail.com (Verde Denim) Date: Sat, 05 Jan 2013 14:21:32 -0500 Subject: import of ttk In-Reply-To: References: <50E7A5EC.9080203@gmail.com> Message-ID: <50E87D3C.4090401@gmail.com> On 01/04/2013 11:39 PM, Terry Reedy wrote: > On 1/4/2013 11:02 PM, Verde Denim wrote: >> In reading through one of the learning articles, I have a bit of code >> that imports ttk, but I apparently don't have this installed. I've >> looked up the svn checkout for python-tk, and have checked it out >> (read-only), but still get the same error. I'm running 2.6.6 python, if >> that helps. > > Show the line of code that did not work and the traceback. What system > are you running on and what tcl/tk installation does it have? ttk is > included with any 8.5 installation. tile is often included with 8.4 > installations and should be picked up as well. > > The article I'm looking at is here - >> http://www.zetcode.com/gui/tkinter/introduction/ > > The line is - 16 from ttk import Frame, Button, Style $ python tkinter_tut1.py Traceback (most recent call last): File "tkinter_tut1.py", line 16, in from ttk import Frame, Button, Style ImportError: No module named ttk I'm running on Debian Squeeze, and do show both 8.4 and 8.5 of tcl From tjreedy at udel.edu Sat Jan 5 17:29:51 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 Jan 2013 17:29:51 -0500 Subject: import of ttk In-Reply-To: <50E87D3C.4090401@gmail.com> References: <50E7A5EC.9080203@gmail.com> <50E87D3C.4090401@gmail.com> Message-ID: On 1/5/2013 2:21 PM, Verde Denim wrote: > On 01/04/2013 11:39 PM, Terry Reedy wrote: >> On 1/4/2013 11:02 PM, Verde Denim wrote: >>> In reading through one of the learning articles, I have a bit of code >>> that imports ttk, but I apparently don't have this installed. I've >>> looked up the svn checkout for python-tk, and have checked it out >>> (read-only), but still get the same error. I'm running 2.6.6 python, if >>> that helps. Upgrade to the latest 2.7 or even 3.3 if at all possible. >> Show the line of code that did not work and the traceback. What system >> are you running on and what tcl/tk installation does it have? ttk is >> included with any 8.5 installation. tile is often included with 8.4 >> installations and should be picked up as well. >> >> The article I'm looking at is here - >>> http://www.zetcode.com/gui/tkinter/introduction/ >> >> > The line is - > 16 from ttk import Frame, Button, Style > > $ python tkinter_tut1.py > Traceback (most recent call last): > File "tkinter_tut1.py", line 16, in > from ttk import Frame, Button, Style > ImportError: No module named ttk > > I'm running on Debian Squeeze, and do show both 8.4 and 8.5 of tcl On my Windows 2.7 installation, directory /Lib contains directory /lib-tk (which is added to the path). /lib-tk contains files Tkinter.py and ttk.py, among others. If you have ttk.py, then I do not think you should get that specific message; if there were a problem finding tcl/tk, it should say something else. If you do not have that file, as it seems, then your installation is incomplete. So check your /Lib/lib-tk. If you do not know where it is import sys print(sys.path) Portability note: In 3.x, /lib-tk was renamed /tkinter and removed from the path. Tkinter.py was renamed __init__.py to make the renamed /tkinter an importable package. So 'import Tkinter becomes 'import tkinter', while 'import ttk', etcetera, is now 'import tkinter.ttk', etcetera. 2to3 should make the fixes. -- Terry Jan Reedy From hossein.asgharian at gmail.com Sat Jan 5 03:35:26 2013 From: hossein.asgharian at gmail.com (Sia) Date: Sat, 5 Jan 2013 00:35:26 -0800 (PST) Subject: Need a specific sort of string modification. Can someone help? Message-ID: I have strings such as: tA.-2AG.-2AG,-2ag or .+3ACG.+5CAACG.+3ACG.+3ACG The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: tA.., and ... How can I do that? Thanks. From frank at chagford.com Sat Jan 5 04:15:59 2013 From: frank at chagford.com (Frank Millman) Date: Sat, 05 Jan 2013 11:15:59 +0200 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: On 05/01/2013 10:35, Sia wrote: > I have strings such as: > > tA.-2AG.-2AG,-2ag > or > .+3ACG.+5CAACG.+3ACG.+3ACG > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > tA.., > and > ... > > How can I do that? > Thanks. > Here is a naive solution (I am sure there are more elegant ones) - def strip(old_string): new_string = '' max = len(old_string) pos = 0 while pos < max: char = old_string[pos] if char in ('-', '+'): num_pos = pos+1 num_str = '' while old_string[num_pos].isdigit(): num_str += old_string[num_pos] num_pos += 1 pos = num_pos + int(num_str) else: new_string += old_string[pos] pos += 1 return new_string It caters for the possibility that the number following the +/- could be greater than 9 - I don't know if you need that. It works with your examples, except that the second one returns '....', which I think is correct - there are 4 dots in the original string. HTH Frank Millman From rosuav at gmail.com Sat Jan 5 04:27:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Jan 2013 20:27:46 +1100 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: On Sat, Jan 5, 2013 at 7:35 PM, Sia wrote: > I have strings such as: > > tA.-2AG.-2AG,-2ag > or > .+3ACG.+5CAACG.+3ACG.+3ACG > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > tA.., > and > ... > > How can I do that? Interesting. Are you guaranteed that there are no other plus or minus signs? Is the number after the sign just one digit? Assuming the answers to both are "yes", here's a one-liner: s=".+3ACG.+5CAACG.+3ACG.+3ACG" result = "".join([x[int(x[0])+1:] for x in ("0"+s).replace("-","+").split("+")]) Split on either - or +, then trim off that many characters from each (that's the list comp), then join them back into a string. ChrisA From roy at panix.com Sat Jan 5 09:12:31 2013 From: roy at panix.com (Roy Smith) Date: Sat, 05 Jan 2013 09:12:31 -0500 Subject: Need a specific sort of string modification. Can someone help? References: Message-ID: In article , Sia wrote: > I have strings such as: > > tA.-2AG.-2AG,-2ag > or > .+3ACG.+5CAACG.+3ACG.+3ACG Some kind of DNA binding site? A couple of questions. Are the numbers always single digits? How much data is there? Are we talking a few hundred 20-character strings, or all of Genbank? > The plus and minus signs are always followed by a number (say, i). I want > python to find each single plus or minus, remove the sign, the number after > it and remove i characters after that. So the two strings above become: > > tA.., > and > ... If I follow your description properly, the last output should be "...." (4 dots), right? This looks like it should work. I'm sure there's more efficient ways to do it, but for small inputs, this should be ok.? The general pattern here is a state machine. It's a good pattern to learn if you're going to be doing any kind of sequence analysis. See, for example, http://en.wikipedia.org/wiki/State_machine. # Build up the new string as a list (for efficiency) new = [] # Keep track of what state we're in. The three possible states # are 1) scanning for a region to be deleted, 2) looking for the # number, and 3) reading past the letters to be deleted. SCANNING = 1 NUMBER = 2 DROPPING = 3 state = SCANNING # If we are in state DROPPING, dropcount is the number of # letters remaining to be dropped. dropcount = 0 old = '.+3ACG.+5CAACG.+3ACG.+3ACG' for c in old: if state == SCANNING: if c in '+-': state = NUMBER else: new.append(c) elif state == NUMBER: # Assume the counts are all single digits. If not, then # we'll need a 4th state for accumulating the digits. dropcount = int(c) state = DROPPING else: assert state == DROPPING dropcount -= 1 if dropcount == 0: state = SCANNING print ''.join(new) From roy at panix.com Sat Jan 5 09:30:45 2013 From: roy at panix.com (Roy Smith) Date: Sat, 05 Jan 2013 09:30:45 -0500 Subject: Need a specific sort of string modification. Can someone help? References: Message-ID: In article , Chris Angelico wrote: > result = "".join([x[int(x[0])+1:] for x in ("0"+s).replace("-","+").split("+")]) That's exceedingly clever. But bordering on line noise. At the very least, I would break it up into a couple of lines to make it easier to understand (plus you can print out the intermediate values to see what's going on): chunks = ("0"+s).replace("-","+").split("+") result = "".join([x[int(x[0])+1:] for x in chunks] From rosuav at gmail.com Sat Jan 5 09:47:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 01:47:32 +1100 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: On Sun, Jan 6, 2013 at 1:30 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> result = "".join([x[int(x[0])+1:] for x in ("0"+s).replace("-","+").split("+")]) > > That's exceedingly clever. But bordering on line noise. At the very > least, I would break it up into a couple of lines to make it easier to > understand (plus you can print out the intermediate values to see what's > going on): > > chunks = ("0"+s).replace("-","+").split("+") > result = "".join([x[int(x[0])+1:] for x in chunks] Sure. You can always split a one-liner to taste, doesn't much matter where. You could split it majorly into half a dozen lines if you want, doesn't make a lot of diff. It'll work the same way :) ChrisA From roy at panix.com Sat Jan 5 10:03:06 2013 From: roy at panix.com (Roy Smith) Date: Sat, 05 Jan 2013 10:03:06 -0500 Subject: Need a specific sort of string modification. Can someone help? References: Message-ID: In article , Chris Angelico wrote: > On Sun, Jan 6, 2013 at 1:30 AM, Roy Smith wrote: > > In article , > > Chris Angelico wrote: > > > >> result = "".join([x[int(x[0])+1:] for x in > >> ("0"+s).replace("-","+").split("+")]) > > > > That's exceedingly clever. But bordering on line noise. At the very > > least, I would break it up into a couple of lines to make it easier to > > understand (plus you can print out the intermediate values to see what's > > going on): > > > > chunks = ("0"+s).replace("-","+").split("+") > > result = "".join([x[int(x[0])+1:] for x in chunks] > > Sure. You can always split a one-liner to taste, doesn't much matter > where. Well, there are better and worse places to split things. Consider these three statements: result = f1().f2().f3().f4().f5() result = f1(f2.f3(f4().f5())) result = f1(f2(3(f4(f5())))) Same number of function calls, but the middle one is clearly the most difficult to understand. The reason is because the scan direction keeps changing. The first one is strictly left-to-right. The last one is strictly inside-to-outside. The middle one is all over the place. That's why I chose to split this where I did. It was where the scan direction changed. Readability matters. From rosuav at gmail.com Sat Jan 5 10:09:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 02:09:24 +1100 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: On Sun, Jan 6, 2013 at 2:03 AM, Roy Smith wrote: > That's why I chose to split this where I did. It was where the scan > direction changed. Ah, good point. In any case, this is a fairly simple and clear way of doing things; it may or may not run faster than the explicit state machine, but IMHO it's a lot clearer to read a split() than something that changes state when a particular character is found. ChrisA From roy at panix.com Sat Jan 5 10:38:54 2013 From: roy at panix.com (Roy Smith) Date: Sat, 05 Jan 2013 10:38:54 -0500 Subject: Need a specific sort of string modification. Can someone help? References: Message-ID: In article , Chris Angelico wrote: > it may or may not run faster than the explicit state machine, Hmmm, hard to say. Both are O(n), but yours makes several more copies of the data than mine (the string addition, the replace(), the split(), the string slicing). We both make copies as we put fragments into a list, and when we do the join(). On the other hand, yours does all that inside the library, which is generally faster than random python code. Let's see: My way: real 0m2.097s user 0m2.078s sys 0m0.016s Your way: real 0m0.649s user 0m0.622s sys 0m0.025s You got me by a factor of 3 or 4. Not bad. And not terribly surprising. Once you've got things to the same O() group, pushing as much data manipulation as you can down into the library is usually a pretty effective optimization technique. > but IMHO it's a lot clearer to read a split() than something > that changes state when a particular character is found. Maybe. But being familiar with state machines is still a handy skill. DNA sequence analysis has lots of problems like "find a start codon which is within about 50 bases of a binding site, and then copy everything up until you find a stop codon". Things like that often map well to state machines. Especially if you're trying to do it in parallel in all three reading frames. From rosuav at gmail.com Sat Jan 5 10:57:29 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 02:57:29 +1100 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: On Sun, Jan 6, 2013 at 2:38 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> it may or may not run faster than the explicit state machine, > > You got me by a factor of 3 or 4. Not bad. You miss my point, though. I went for simple Pythonic code, and never measured its performance, on the expectation that it's "good enough". Written in C, the state machine is probably WAY faster than splitting and then iterating. My C++ MUD client uses code similar to that to parse TELNET and ANSI codes from a stream of bytes in a socket (and one of its "states" is that there's no more data available, so wait on the socket); the rewrite in a high level language divides the string on "\xFF" for TELNET and "\x1B" for ANSI, working them separately, and then afterward splits on "\n" to divide into lines. The code's much less convoluted, it's easier to test different parts (because I can simply call the ANSI parser with a block of text), and on a modern computer, you can't see the performance difference (since you spend most of your time waiting for socket data anyway). But it's gratifying to know that the obvious and brief way to do things is fast too :) >> but IMHO it's a lot clearer to read a split() than something >> that changes state when a particular character is found. > > Maybe. But being familiar with state machines is still a handy skill. > DNA sequence analysis has lots of problems like "find a start codon > which is within about 50 bases of a binding site, and then copy > everything up until you find a stop codon". Things like that often map > well to state machines. Especially if you're trying to do it in > parallel in all three reading frames. Sure. And if you're working with petabytes of data, these considerations become fairly important. When that happens, you start rewriting your algorithms in C, or using Cython, or something; at very least, you start rewriting clear and simple algorithms into more complex ones. But all this happens *after* the code has been tested and proven. All the rewrites can be verified as being identical to their reference implementations; you can test one piece at a time as you change them. It's ever so much easier to work that way. At work, we had one employee whose code was, shall we say, less than stellar. At one point, he embarked on a months-long rewrite of one of his modules; meanwhile, I was unable to adequately test code that called on it. Once the rewrite was finally complete, I discovered myriad bugs in my own code, ones that would have been found and fixed instantly if I'd had even a slow version of the code to work against. Starting with something you can easily debug helps enormously with that, because debugging doesn't demand mega-TPS throughput. ChrisA From ian.g.kelly at gmail.com Sat Jan 5 15:04:56 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 5 Jan 2013 13:04:56 -0700 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: On Sat, Jan 5, 2013 at 8:57 AM, Chris Angelico wrote: > You miss my point, though. I went for simple Pythonic code, and never > measured its performance, on the expectation that it's "good enough". > Written in C, the state machine is probably WAY faster than splitting > and then iterating. My C++ MUD client uses code similar to that to > parse TELNET and ANSI codes from a stream of bytes in a socket (and > one of its "states" is that there's no more data available, so wait on > the socket); the rewrite in a high level language divides the string > on "\xFF" for TELNET and "\x1B" for ANSI, working them separately, and > then afterward splits on "\n" to divide into lines. The code's much > less convoluted, it's easier to test different parts (because I can > simply call the ANSI parser with a block of text), and on a modern > computer, you can't see the performance difference (since you spend > most of your time waiting for socket data anyway). Anecdotally and somewhat off-topic, when I wrote my own MUD client in Python, I implemented both TELNET and ANSI parsing in Python using a state machine processing one byte at a time (actually two state machines - one at the protocol layer and one at the client layer; the telnet module is a modified version of the twisted.conch.telnet module). I was worried that the processing would be too slow in Python. When I got it running, it turned out that there was a noticeable lag between input being received and displayed. But when I profiled the issue it actually turned out that the rich text control I was using, which was written in C++, wasn't able to handle a large buffer gracefully. The parsing code in Python did just fine and didn't contribute to the lag issue at all. From rosuav at gmail.com Sat Jan 5 15:32:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 07:32:13 +1100 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: On Sun, Jan 6, 2013 at 7:04 AM, Ian Kelly wrote: > On Sat, Jan 5, 2013 at 8:57 AM, Chris Angelico wrote: >> You miss my point, though. I went for simple Pythonic code, and never >> measured its performance, on the expectation that it's "good enough". >> Written in C, the state machine is probably WAY faster than splitting >> and then iterating. My C++ MUD client uses code similar to that to >> parse TELNET and ANSI codes from a stream of bytes in a socket (and >> one of its "states" is that there's no more data available, so wait on >> the socket); the rewrite in a high level language divides the string >> on "\xFF" for TELNET and "\x1B" for ANSI, working them separately, and >> then afterward splits on "\n" to divide into lines. The code's much >> less convoluted, it's easier to test different parts (because I can >> simply call the ANSI parser with a block of text), and on a modern >> computer, you can't see the performance difference (since you spend >> most of your time waiting for socket data anyway). > > Anecdotally and somewhat off-topic, when I wrote my own MUD client in > Python, I implemented both TELNET and ANSI parsing in Python using a > state machine processing one byte at a time (actually two state > machines - one at the protocol layer and one at the client layer; the > telnet module is a modified version of the twisted.conch.telnet > module). I was worried that the processing would be too slow in > Python. When I got it running, it turned out that there was a > noticeable lag between input being received and displayed. But when I > profiled the issue it actually turned out that the rich text control I > was using, which was written in C++, wasn't able to handle a large > buffer gracefully. The parsing code in Python did just fine and > didn't contribute to the lag issue at all. The opposite decision, the same result. Performance was *good enough*. With Gypsum, my early performance problems were almost completely solved by properly handling the expose-event and only painting the parts that changed (I don't use a rich text control, I use a GTK2.DrawingArea). Text processing of something that's come over a network is seldom a problem; if it were, we'd see noticeably slower downloads over HTTPS than HTTP, and that just doesn't happen. I think (though I can't prove) that crypto written in C is probably more expensive than ANSI parsing written in Python. ChrisA From roy at panix.com Sat Jan 5 15:47:03 2013 From: roy at panix.com (Roy Smith) Date: Sat, 05 Jan 2013 15:47:03 -0500 Subject: Need a specific sort of string modification. Can someone help? References: Message-ID: In article , Chris Angelico wrote: > On Sun, Jan 6, 2013 at 7:04 AM, Ian Kelly wrote: > > On Sat, Jan 5, 2013 at 8:57 AM, Chris Angelico wrote: > >> You miss my point, though. I went for simple Pythonic code, and never > >> measured its performance, on the expectation that it's "good enough". > >> Written in C, the state machine is probably WAY faster than splitting > >> and then iterating. My C++ MUD client uses code similar to that to > >> parse TELNET and ANSI codes from a stream of bytes in a socket (and > >> one of its "states" is that there's no more data available, so wait on > >> the socket); the rewrite in a high level language divides the string > >> on "\xFF" for TELNET and "\x1B" for ANSI, working them separately, and > >> then afterward splits on "\n" to divide into lines. The code's much > >> less convoluted, it's easier to test different parts (because I can > >> simply call the ANSI parser with a block of text), and on a modern > >> computer, you can't see the performance difference (since you spend > >> most of your time waiting for socket data anyway). > > > > Anecdotally and somewhat off-topic, when I wrote my own MUD client in > > Python, I implemented both TELNET and ANSI parsing in Python using a > > state machine processing one byte at a time (actually two state > > machines - one at the protocol layer and one at the client layer; the > > telnet module is a modified version of the twisted.conch.telnet > > module). I was worried that the processing would be too slow in > > Python. When I got it running, it turned out that there was a > > noticeable lag between input being received and displayed. But when I > > profiled the issue it actually turned out that the rich text control I > > was using, which was written in C++, wasn't able to handle a large > > buffer gracefully. The parsing code in Python did just fine and > > didn't contribute to the lag issue at all. > > The opposite decision, the same result. Performance was *good enough*. > With Gypsum, my early performance problems were almost completely > solved by properly handling the expose-event and only painting the > parts that changed (I don't use a rich text control, I use a > GTK2.DrawingArea). Text processing of something that's come over a > network is seldom a problem; if it were, we'd see noticeably slower > downloads over HTTPS than HTTP, and that just doesn't happen. I think > (though I can't prove) that crypto written in C is probably more > expensive than ANSI parsing written in Python. > > ChrisA It's rare to find applications these days that are truly CPU bound. Once you've used some reasonable algorithm, i.e. not done anything in O(n^2) that could have been done in O(n) or O(n log n), you will more often run up against I/O speed, database speed, network latency, memory exhaustion, or some such as the reason your code is too slow. The upshot of this is that for most things, Python (even though it runs an order of magnitude slower than C), will always be *good enough*. I'm sure I've mentioned this before, but the application code for Songza.com is 100% Python. We pretty much can't even measure how much CPU time is spent running Python code. Everything is database, network, and (occasionally) disk throughput. From roy at panix.com Sun Jan 6 12:28:55 2013 From: roy at panix.com (Roy Smith) Date: Sun, 06 Jan 2013 12:28:55 -0500 Subject: Need a specific sort of string modification. Can someone help? References: Message-ID: In article , Roy Smith wrote: > It's rare to find applications these days that are truly CPU bound. > Once you've used some reasonable algorithm, i.e. not done anything in > O(n^2) that could have been done in O(n) or O(n log n), you will more > often run up against I/O speed, database speed, network latency, memory > exhaustion, or some such as the reason your code is too slow. Well, I just found a counter-example :-) I've been doing some log analysis. It's been taking a grovelingly long time, so I decided to fire up the profiler and see what's taking so long. I had a pretty good idea of where the ONLY TWO POSSIBLE hotspots might be (looking up IP addresses in the geolocation database, or producing some pretty pictures using matplotlib). It was just a matter of figuring out which it was. As with most attempts to out-guess the profiler, I was totally, absolutely, and embarrassingly wrong. It turns out we were spending most of the time parsing timestamps! Since there's no convenient way (I don't consider strptime() to be convenient) to parse isoformat strings in the standard library, our habit has been to use the oh-so-simple parser from the third-party dateutil package. Well, it turns out that's slow as all get-out (probably because it's trying to be smart about auto-recognizing formats). For the test I ran (on a few percent of the real data), we spent 90 seconds in parse(). OK, so I dragged out the strptime() docs and built the stupid format string (%Y-%m-%dT%H:%M:%S+00:00). That got us down to 25 seconds in strptime(). But, I could also see it was spending a significant amount in routines that looked like they were computing things like day of the week that we didn't need. For what I was doing, we only really needed the hour and minute. So I tried: t_hour = int(date[11:13]) t_minute = int(date[14:16]) that got us down to 12 seconds overall (including the geolocation and pretty pictures). I think it turns out we never do anything with the hour and minute other than print them back out, so just t_hour_minute = date[11:16] would probably be good enough, but I think I'm going to stop where I am and declare victory :-) From steve+comp.lang.python at pearwood.info Sun Jan 6 18:19:53 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Jan 2013 23:19:53 GMT Subject: Need a specific sort of string modification. Can someone help? References: Message-ID: <50ea0699$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 06 Jan 2013 12:28:55 -0500, Roy Smith wrote: > I've been doing some log analysis. It's been taking a grovelingly long > time, so I decided to fire up the profiler and see what's taking so > long. I had a pretty good idea of where the ONLY TWO POSSIBLE hotspots > might be (looking up IP addresses in the geolocation database, or > producing some pretty pictures using matplotlib). It was just a matter > of figuring out which it was. > > As with most attempts to out-guess the profiler, I was totally, > absolutely, and embarrassingly wrong. +1 QOTW Thank you for sharing this with us. -- Steven From python.list at tim.thechases.com Sat Jan 5 12:24:13 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 05 Jan 2013 11:24:13 -0600 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: <50E861BD.3060105@tim.thechases.com> On 01/05/13 02:35, Sia wrote: > I have strings such as: > > tA.-2AG.-2AG,-2ag > or > .+3ACG.+5CAACG.+3ACG.+3ACG > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > tA.., > and > ... With the same caveat as Frank posted about the second one being "...." (4 dots), I don't know how this version times out: import re r = re.compile(r"[-+](\d+)([^-+]*)") def modify(m): result = m.group(2)[int(m.group(1)):] return result for test, expected in ( ("tA.-2AG.-2AG,-2ag", "tA..,"), (".+3ACG.+5CAACG.+3ACG.+3ACG", "...."), ): s = r.sub(modify, test) print "%r -> %r (%r)" % ( test, s, expected ) assert s == expected, "Nope" (it passes the tests as modified to "....") -tkc From python.list at tim.thechases.com Sat Jan 5 13:49:06 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 05 Jan 2013 12:49:06 -0600 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: <50E861BD.3060105@tim.thechases.com> References: <50E861BD.3060105@tim.thechases.com> Message-ID: <50E875A2.6080405@tim.thechases.com> On 01/05/13 11:24, Tim Chase wrote: > I don't know how this version times out: > > import re > r = re.compile(r"[-+](\d+)([^-+]*)") > def modify(m): > result = m.group(2)[int(m.group(1)):] > return result Doh, I intended to change this after testing, making it just returm m.group(2)[int(m.group(1)):] rather than expending an intermediate variable I used for testing -tkc From msirenef at lightbird.net Sun Jan 6 01:32:46 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 06 Jan 2013 01:32:46 -0500 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: <50E91A8E.80609@lightbird.net> On 01/05/2013 03:35 AM, Sia wrote: > I have strings such as: > > tA.-2AG.-2AG,-2ag > or > .+3ACG.+5CAACG.+3ACG.+3ACG > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > tA.., > and > ... > > How can I do that? > Thanks. I think it's a bit cleaner and nicer to do something similar to itertools.takewhile but takewhile 'eats' a single next value. I was actually doing some stuff that also needed this. I wonder if there's a more elegant, robust way to do this? Here's what I got for now: class BIterator(object): """Iterator with 'buffered' takewhile.""" def __init__(self, seq): self.seq = iter(seq) self.buffer = [] self.end_marker = object() self.last = None def consume(self, n): for _ in range(n): self.next() def next(self): val = self.buffer.pop() if self.buffer else next(self.seq, self.end_marker) self.last = val return val def takewhile(self, test): lst = [] while True: val = self.next() if val is self.end_marker: return lst elif test(val): lst.append(val) else: self.buffer.append(val) return lst def joined_takewhile(self, test): return ''.join(self.takewhile(test)) def done(self): return bool(self.last is self.end_marker) s = ".+3ACG.+5CAACG.+3ACG.+3ACG" not_plusminus = lambda x: x not in "+-" isdigit = lambda x: x.isdigit() def process(s): lst = [] s = BIterator(s) while True: lst.extend(s.takewhile(not_plusminus)) if s.done(): break s.next() n = int(s.joined_takewhile(isdigit)) s.consume(n) return ''.join(lst) print(process(s)) Obviously it assumes the input is well-formed, but the logic would be very easy to change to, for example, check for s.done() after each step. - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From msirenef at lightbird.net Sun Jan 6 14:53:27 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 06 Jan 2013 14:53:27 -0500 Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: <50E91A8E.80609@lightbird.net> References: <50E91A8E.80609@lightbird.net> Message-ID: <50E9D637.7030002@lightbird.net> On 01/06/2013 01:32 AM, Mitya Sirenef wrote: > On 01/05/2013 03:35 AM, Sia wrote: >> I have strings such as: > > > > tA.-2AG.-2AG,-2ag > > or > > .+3ACG.+5CAACG.+3ACG.+3ACG > > > > The plus and minus signs are always followed by a number (say, i). I > want python to find each single plus or minus, remove the sign, the > number after it and remove i characters after that. So the two strings > above become: > > > > tA.., > > and > > ... > > > > How can I do that? > > Thanks. > > > I think it's a bit cleaner and nicer to do something similar to > itertools.takewhile but takewhile 'eats' a single next value. > I was actually doing some stuff that also needed this. I wonder if > there's a more elegant, robust way to do this? > > Here's what I got for now: > > > class BIterator(object): > """Iterator with 'buffered' takewhile.""" > > def __init__(self, seq): > self.seq = iter(seq) > self.buffer = [] > self.end_marker = object() > self.last = None > > def consume(self, n): > for _ in range(n): self.next() > > def next(self): > val = self.buffer.pop() if self.buffer else next(self.seq, > self.end_marker) > self.last = val > return val > > def takewhile(self, test): > lst = [] > while True: > val = self.next() > if val is self.end_marker: > return lst > elif test(val): > lst.append(val) > else: > self.buffer.append(val) > return lst > > def joined_takewhile(self, test): > return ''.join(self.takewhile(test)) > > def done(self): > return bool(self.last is self.end_marker) > > > s = ".+3ACG.+5CAACG.+3ACG.+3ACG" > not_plusminus = lambda x: x not in "+-" > isdigit = lambda x: x.isdigit() > > def process(s): > lst = [] > s = BIterator(s) > > while True: > lst.extend(s.takewhile(not_plusminus)) > if s.done(): break > s.next() > n = int(s.joined_takewhile(isdigit)) > s.consume(n) > > return ''.join(lst) > > > print(process(s)) > > > Obviously it assumes the input is well-formed, but the logic would be > very easy to change to, for example, check for s.done() after each step. > > - mitya > > > I've added some refinements: class BIterator(object): """Iterator with 'buffered' takewhile and takeuntil.""" def __init__(self, seq): self.seq = iter(seq) self.buffer = [] self.end_marker = object() self.last = None def __bool__(self): return self.last is not self.end_marker def __next__(self): val = self.buffer.pop() if self.buffer else next(self.seq, self.end_marker) self.last = val return val def consume(self, n): for _ in range(n): next(self) def takewhile(self, test): lst = [] while True: val = next(self) if val is self.end_marker: return lst elif test(val): lst.append(val) else: self.buffer.append(val) return lst def takeuntil(self, test): negtest = lambda x: not test(x) return self.takewhile(negtest) def joined_takewhile(self, test): return ''.join(self.takewhile(test)) def joined_takeuntil(self, test): return ''.join(self.takeuntil(test)) def process(s): s = BIterator(s) lst = [] plusminus = lambda x: x in "+-" isdigit = lambda x: x.isdigit() while s: lst.extend(s.takeuntil(plusminus)) next(s) n = s.joined_takewhile(isdigit) or 0 s.consume(int(n)) return ''.join(lst) s = ".+3ACG.+5CAACG.+3ACG.+3ACG" print(process(s)) -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From thebalancepro at gmail.com Sun Jan 6 21:48:51 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Sun, 6 Jan 2013 18:48:51 -0800 (PST) Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: <2ccd1e6e-37aa-46d0-a02a-baaa859c055b@googlegroups.com> Hi Sia, Here's another variation. It's within my tolerance for readability :-) and also quick, if that's an issue. It does 100,000 of your longer string in a couple of seconds on my venerable laptop. It handles only single-digit numbers. For multi-digit, I'd be inclined to have a look at takewhile and/or dropwhile, both in itertools (Python 2.7 and 3.x only.) from string import maketrans class redux: def __init__(self): intab = '+-' outtab = ' ' # two spaces self.trantab = maketrans(intab, outtab) def reduce_plusminus(self, s): list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r for r in s.translate(self.trantab).split()] return ''.join(list_form) if __name__ == "__main__": p = redux() print p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG") print p.reduce_plusminus("tA.-2AG.-2AG,-2ag") for n in range(100000): p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG") On Saturday, 5 January 2013 19:35:26 UTC+11, Sia wrote: > I have strings such as: > > > > tA.-2AG.-2AG,-2ag > > or > > .+3ACG.+5CAACG.+3ACG.+3ACG > > > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > > > tA.., > > and > > ... > > > > How can I do that? > > Thanks. From thebalancepro at gmail.com Sun Jan 6 22:40:02 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Sun, 6 Jan 2013 19:40:02 -0800 (PST) Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: <18ae74e7-780d-48d6-9575-b5f85541edfe@googlegroups.com> Hi Sia, Find a multi-digit method in this version: from string import maketrans from itertools import takewhile def is_digit(s): return s.isdigit() class redux: def __init__(self): intab = '+-' outtab = ' ' self.trantab = maketrans(intab, outtab) def reduce_plusminus(self, s): list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r for r in s.translate(self.trantab).split()] return ''.join(list_form) def reduce_plusminus_multi_digit(self, s): spl = s.translate(self.trantab).split() digits = [list(takewhile(is_digit, r)) for r in spl] numbers = [int(''.join(r)) if r else 0 for r in digits] skips = [len(dig) + num for dig, num in zip(digits, numbers)] return ''.join([s[r:] for r, s in zip(skips, spl)]) if __name__ == "__main__": p = redux() print p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG") print p.reduce_plusminus("tA.-2AG.-2AG,-2ag") print 'multi-digit...' print p.reduce_plusminus_multi_digit(".+3ACG.+5CAACG.+3ACG.+3ACG") print p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG") HTH, Nick On Saturday, 5 January 2013 19:35:26 UTC+11, Sia wrote: > I have strings such as: > > > > tA.-2AG.-2AG,-2ag > > or > > .+3ACG.+5CAACG.+3ACG.+3ACG > > > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > > > tA.., > > and > > ... > > > > How can I do that? > > Thanks. From thebalancepro at gmail.com Mon Jan 7 00:28:45 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Sun, 6 Jan 2013 21:28:45 -0800 (PST) Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: <18ae74e7-780d-48d6-9575-b5f85541edfe@googlegroups.com> References: <18ae74e7-780d-48d6-9575-b5f85541edfe@googlegroups.com> Message-ID: <101cfe8d-a1e8-4491-8b15-42c4927ccebb@googlegroups.com> Note that the multi-line version above tolerates missing digits: if the number is missing after the '+/-' it doesn't skip any letters. Brief explanation of the multi-digit version: +/- are converted to spaces and used to split the string into sections. The split process effectively swallows the +/- characters. The complication of multi-digits is that you need to skip the (possibly multiple) digits, which adds another stage to the calculation. In: +3ACG. -> . you skip 1 + 3 characters, 1 for the digit, 3 for the following letters as specified by the digit 3. In: -11ACGACGACGACG. -> G. You skip 2 + 11 characters, 2 digits in "12" and 11 letters following. And incidentally in: +ACG. -> ACG. there's no digit, so you skip 0 digits + 0 letters. Having split on +/- using .translate() and .split() I use takewhile to separate the zero or more digits from the following letters. If takewhile doesn't find any digits at the start of the sequence, it returns the empty list []. ''.join(list) swallows empty lists so dropwhile and ''.join() cover the no-digit case between them. If a lack of digits is a data error then it would be easy to test for-- just look for an empty list in 'digits'. I was pleasantly surprised to find that using list comprehensions, zip, join (all highly optimised in Python) and several intermediate lists still works at a fairly decent speed, despite using more stages to handle multi-digits. But it is about 4x slower than the less flexible 1-digit version on my hardware (about 25,000 per second.) Nick On Monday, 7 January 2013 14:40:02 UTC+11, Nick Mellor wrote: > Hi Sia, > > > > Find a multi-digit method in this version: > > > > from string import maketrans > > from itertools import takewhile > > > > def is_digit(s): return s.isdigit() > > > > class redux: > > > > def __init__(self): > > intab = '+-' > > outtab = ' ' > > self.trantab = maketrans(intab, outtab) > > > > > > def reduce_plusminus(self, s): > > list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r > > for r > > in s.translate(self.trantab).split()] > > return ''.join(list_form) > > > > def reduce_plusminus_multi_digit(self, s): > > spl = s.translate(self.trantab).split() > > digits = [list(takewhile(is_digit, r)) > > for r > > in spl] > > numbers = [int(''.join(r)) if r else 0 > > for r > > in digits] > > skips = [len(dig) + num for dig, num in zip(digits, numbers)] > > return ''.join([s[r:] for r, s in zip(skips, spl)]) > > > > if __name__ == "__main__": > > p = redux() > > print p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG") > > print p.reduce_plusminus("tA.-2AG.-2AG,-2ag") > > print 'multi-digit...' > > print p.reduce_plusminus_multi_digit(".+3ACG.+5CAACG.+3ACG.+3ACG") > > print p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG") > > > > > > HTH, > > > > Nick > > > > On Saturday, 5 January 2013 19:35:26 UTC+11, Sia wrote: > > > I have strings such as: > > > > > > > > > > > > tA.-2AG.-2AG,-2ag > > > > > > or > > > > > > .+3ACG.+5CAACG.+3ACG.+3ACG > > > > > > > > > > > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > > > > > > > > > > > tA.., > > > > > > and > > > > > > ... > > > > > > > > > > > > How can I do that? > > > > > > Thanks. From thebalancepro at gmail.com Mon Jan 7 00:30:06 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Sun, 6 Jan 2013 21:30:06 -0800 (PST) Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: Oops! "You skip 2 + 11 characters, 2 digits in "12" and 11 letters following. And incidentally in: " should read: "You skip 2 + 11 characters, 2 digits in "11" and 11 letters following. And incidentally in: " N On Saturday, 5 January 2013 19:35:26 UTC+11, Sia wrote: > I have strings such as: > > > > tA.-2AG.-2AG,-2ag > > or > > .+3ACG.+5CAACG.+3ACG.+3ACG > > > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > > > tA.., > > and > > ... > > > > How can I do that? > > Thanks. From john_ladasky at sbcglobal.net Mon Jan 7 00:39:37 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 6 Jan 2013 21:39:37 -0800 (PST) Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: <0781b010-1640-43dd-ab67-0a1055db61bc@googlegroups.com> On Saturday, January 5, 2013 12:35:26 AM UTC-8, Sia wrote: > I have strings such as: > > tA.-2AG.-2AG,-2ag > > .+3ACG.+5CAACG.+3ACG.+3ACG Just curious, do these strings represent DNA sequences? From thebalancepro at gmail.com Mon Jan 7 02:07:36 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Sun, 6 Jan 2013 23:07:36 -0800 (PST) Subject: Need a specific sort of string modification. Can someone help? In-Reply-To: References: Message-ID: <8a524329-3c3f-4575-8296-16f9567e1202@googlegroups.com> Hi Sia, Thanks for the problem! I hope you find these examples understandable. Below, find an inflexible but fairly fast single-digit method and a slower (but still respectable) multi-digit method that copes with entirely absent digits after +/- and multi-digit skips such as 12 or 37 or 186 following letters rather than just 3 or 5 or 9. Not knowing your problem domain I'm not sure if these larger skips are likely or even possible, nor whether it's likely that there will be no digit. Neither method flags the edge case where there are not enough letters to skip before the next +/-. They just swallow that chunk of the string entirely without error. Is that a problem? Python 2.7 or later. from string import maketrans from itertools import takewhile # function used by takewhile to detect digits def is_digit(s): return s.isdigit() class redux: def __init__(self): intab = '+-' outtab = ' ' self.trantab = maketrans(intab, outtab) # simple-minded, fast, 1-digit algorithm def reduce_plusminus(self, s): list_form = [r[int(r[0]) + 1:] if r[0].isdigit() else r for r in s.translate(self.trantab).split()] return ''.join(list_form) # multi-digit algorithm def reduce_plusminus_multi_digit(self, s): chunks = s.translate(self.trantab).split() digits = [list(takewhile(is_digit, r)) for r in chunks] # zero case ('else 0') is for missing digit(s) numbers = [int(''.join(r)) if r else 0 for r in digits] # how far to skip (number and skipped letters) skips = [len(dig) + num for dig, num in zip(digits, numbers)] return ''.join([sequence[skipover:] for skipover, sequence in zip(skips, chunks)]) if __name__ == "__main__": p = redux() print (p.reduce_plusminus(".+3ACG.+5CAACG.+3ACG.+3ACG")) print (p.reduce_plusminus("tA.-5AG.-2AG,-2ag")) print ('multi-digit...') print (p.reduce_plusminus_multi_digit(".+3ACG.+5CAACG.+3ACG.+3ACG")) print (p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG")) print (p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+ACG.+3ACG")) for n in range(100000): p.reduce_plusminus_multi_digit(".+12ACGACGACGACG.+5CAACG.+3ACG.+3ACG") Note that the multi-line version above tolerates missing digits: if the number is missing after the '+/-' it doesn't skip any letters. Explanation: String slicing is good in Python, but list comprehensions are often the most powerful and efficient way to transform data. If you've come from another language or you're a newb to programming, it's well worth getting grips with list comprehensions [a for b in lst]. First, +/- are converted to spaces. Splitting the string into a list, breaking at spaces, effectively swallows the +/- characters and leaves us with chunks of string from which to drop the specified number of letters. Having dropped the letters, we convert the transformed list back into a string. The single-digit version just assumes that the number is always present and always single-digit. If you allow multi-digits be ready to skip those multiple digits, as well as skipping letters, adding another stage to the calculation. E.g. in: +3ACG. -> . you skip 1 + 3 characters, 1 for the digit, 3 for the following letters as specified by the digit 3. In: -11ACGACGACGACG. -> G. You skip 2 + 11 characters, 2 characters in "11" and 11 characters following. And incidentally in: +ACG. -> ACG. there's no digit, so you skip 0 digits + 0 letters. If a lack of digits is a data error then it would be easy to test for-- just look for an empty list in the 'digits' list. For each chunk (stuff between +/-) I use takewhile to separate the zero or more initial digits from the following letters. itertools.takewhile is a nice tool for matching stuff until the first time a condition ceases to hold. In this case I'm matching digits up until the first non-digit. If takewhile doesn't find any digits at the start of the sequence, it returns the empty list []. ''.join(list) swallows empty lists so takewhile and ''.join() do behind-the-scenes leg-work for me in detecting the case of absent digit(s). For my money speed isn't bad for these two methods (again, I don't know your domain.) On my (ancient) hardware the 1-digit version does over 100,000/s for your longer string, the multi-digit about 35,000/s. HTH, Nick On Saturday, 5 January 2013 19:35:26 UTC+11, Sia wrote: > I have strings such as: > > > > tA.-2AG.-2AG,-2ag > > or > > .+3ACG.+5CAACG.+3ACG.+3ACG > > > > The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become: > > > > tA.., > > and > > ... > > > > How can I do that? > > Thanks. From yacinechaouche at yahoo.com Sat Jan 5 08:55:54 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sat, 5 Jan 2013 05:55:54 -0800 (PST) Subject: Couting the number of lines of code of a python program Message-ID: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> Hello. I'v written a small script that prints the number of lines of code of a python program to stdout (by module, function, class and method), the sources are available online here? https://www.assembla.com/code/tahar/subversion/nodes. The readme has an example usage as well as a trace of what the script prints. The problem is that I'm using the inspect module, because it provides a nice function inspect.getsourcelines that takes a python object and return its number of lines of code. BUT, it works on live objects, that means one has to first import the module he wants to process, and this can have side effects (example : GUI programs). So my question is how can one count the number of lines of code of a python program without importing it (static code analysis) ? Some people on IRC advised me to look for the AST module. Can you give me a little help on how to use this module to count the number of lines of code of a function/method ? Thanks in advance for your help. From rosuav at gmail.com Sat Jan 5 09:09:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 01:09:08 +1100 Subject: Couting the number of lines of code of a python program In-Reply-To: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> References: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> Message-ID: On Sun, Jan 6, 2013 at 12:55 AM, chaouche yacine wrote: > The > problem is that I'm using the inspect module, because it provides a > nice function inspect.getsourcelines that takes a python object and > return its number of lines of code. BUT, it works on live objects, that > means one has to first import the module he wants to process, and this > can have side effects (example : GUI programs). If you're using this entirely on your own code, one good way to solve the problem is to make your code always importable. Protect your top-level code with "if __name__=='__main__':" (and possibly put it into a function main() if that simplifies your code counting), and you should then be able to import it as-is, and all you'll do is define a bunch of functions/classes. But counting lines of code is a hairy thing to do. Do blank lines, comments, and multi-line strings count? ChrisA From yacinechaouche at yahoo.com Sat Jan 5 10:17:47 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sat, 5 Jan 2013 07:17:47 -0800 (PST) Subject: Couting the number of lines of code of a python program In-Reply-To: References: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> Message-ID: <1357399067.54894.YahooMailNeo@web125504.mail.ne1.yahoo.com> The idea started off as a volumetric information of my projects, but evolved to a sort of code browser that would display classes, methods and functions in a tree-like structure, and now I mostly want to use it with other people's code as a way to have the big picture. So I would say that it is used both for my programs (to get a feeling of their size) as much as it is used for others' code. > But counting lines of code is a hairy thing to do. Do blank lines, > comments, and multi-line strings count? The way I implmented it, they do not, particulary docstrings (even though it seems that many people think docstrings are actual code). My opinion on docstrings is that they're not instructions. I want to know how many lines of instructions a program has. Comments, blank lines and docstrings are not intructions. Here is my implementation : defcount_loc(lines):nb_lines =0docstring =Falseforline inlines:line =line.strip()ifline ==""\ orline.startswith("#")\ ordocstring andnot(line.startswith('"""')orline.startswith("'''"))\ or(line.startswith("'''")andline.endswith("'''")andlen(line)>3)\ or(line.startswith('"""')andline.endswith('"""')andlen(line)>3):continue# this is either a starting or ending docstringelifline.startswith('"""')orline.startswith("'''"):docstring =notdocstring continueelse:nb_lines +=1returnnb_lines ----- Original Message ----- From: Chris Angelico To: python-list at python.org Cc: Sent: Saturday, January 5, 2013 3:09 PM Subject: Re: Couting the number of lines of code of a python program On Sun, Jan 6, 2013 at 12:55 AM, chaouche yacine wrote: > The >? problem is that I'm using the inspect module, because it provides a > nice function inspect.getsourcelines that takes a python object and > return its number of lines of code. BUT, it works on live objects, that > means one has to first import the module he wants to process, and this > can have side effects (example : GUI programs). If you're using this entirely on your own code, one good way to solve the problem is to make your code always importable. Protect your top-level code with "if __name__=='__main__':" (and possibly put it into a function main() if that simplifies your code counting), and you should then be able to import it as-is, and all you'll do is define ams and bunch of functions/classes. But counting lines of code is a hairy thing to do. Do blank lines, comments, and multi-line strings count? ChrisA -- http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Jan 5 10:25:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 02:25:58 +1100 Subject: Couting the number of lines of code of a python program In-Reply-To: <1357399067.54894.YahooMailNeo@web125504.mail.ne1.yahoo.com> References: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> <1357399067.54894.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: On Sun, Jan 6, 2013 at 2:17 AM, chaouche yacine wrote: > defcount_loc(lines):nb_lines =0docstring =Falseforline inlines:line =line.strip()ifline ==""\ orline.startswith("#")\ ordocstring andnot(line.startswith('"""')orline.startswith("'''"))\ or(line.startswith("'''")andline.endswith("'''")andlen(line)>3)\ or(line.startswith('"""')andline.endswith('"""')andlen(line)>3):continue# this is either a starting or ending docstringelifline.startswith('"""')orline.startswith("'''"):docstring =notdocstring continueelse:nb_lines +=1returnnb_lines Ow-what? Something's gone wrong with all your whitespace, I think... can you paste again please? ChrisA From yacinechaouche at yahoo.com Sat Jan 5 10:38:06 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sat, 5 Jan 2013 07:38:06 -0800 (PST) Subject: Couting the number of lines of code of a python program In-Reply-To: References: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> <1357399067.54894.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: <1357400286.2321.YahooMailNeo@web125501.mail.ne1.yahoo.com> Sorry, I don't know what went wrong, here is another paste (hopefully this will work this time). If you prefer, this a link anchor to the function https://www.assembla.com/code/tahar/subversion/nodes/tahar.py?rev=8#ln340 def count_loc(lines): ??? nb_lines? = 0 ??? docstring = False ??? for line in lines: ??????? line = line.strip() ??????? if line == "" \ ?????????? or line.startswith("#") \ ?????????? or docstring and not (line.startswith('"""') or line.startswith("'''"))\ ?????????? or (line.startswith("'''") and line.endswith("'''") and len(line) >3)? \ ?????????? or (line.startswith('"""') and line.endswith('"""') and len(line) >3) : ??????????? continue ?????? ? ??????? # this is either a starting or ending docstring ??????? elif line.startswith('"""') or line.startswith("'''"): ??????????? docstring = not docstring ??????????? continue ??????? else: ??????????? nb_lines += 1 ??? return nb_lines ----- Original Message ----- From: Chris Angelico To: python-list at python.org Cc: Sent: Saturday, January 5, 2013 4:25 PM Subject: Re: Couting the number of lines of code of a python program On Sun, Jan 6, 2013 at 2:17 AM, chaouche yacine wrote: > defcount_loc(lines):nb_lines =0docstring =Falseforline inlines:line =line.strip()ifline ==""\ orline.startswith("#")\ ordocstring andnot(line.startswith('"""')orline.startswith("'''"))\ or(line.startswith("'''")andline.endswith("'''")andlen(line)>3)\ or(line.startswith('"""')andline.endswith('"""')andlen(line)>3):continue# this is either a starting or ending docstringelifline.startswith('"""')orline.startswith("'''"):docstring =notdocstring continueelse:nb_lines +=1returnnb_lines Ow-what? Something's gone wrong with all your whitespace, I think... can you paste again please? ChrisA -- http://mail.python.org/mailman/listinfo/python-list From d at davea.name Sat Jan 5 10:37:44 2013 From: d at davea.name (Dave Angel) Date: Sat, 05 Jan 2013 10:37:44 -0500 Subject: Couting the number of lines of code of a python program In-Reply-To: <1357399067.54894.YahooMailNeo@web125504.mail.ne1.yahoo.com> References: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> <1357399067.54894.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: <50E848C8.8020207@davea.name> On 01/05/2013 10:17 AM, chaouche yacine wrote: > > > Here is my implementation : > > defcount_loc(lines):nb_lines =0docstring =Falseforline inlines:line =line.strip()ifline ==""\ orline.startswith("#")\ ordocstring andnot(line.startswith('"""')orline.startswith("'''"))\ or(line.startswith("'''")andline.endswith("'''")andlen(line)>3)\ or(line.startswith('"""')andline.endswith('"""')andlen(line)>3):continue# this is either a starting or ending docstringelifline.startswith('"""')orline.startswith("'''"):docstring =notdocstring continueelse:nb_lines +=1returnnb_lines Wow, this is thoroughly garbled. Please configure your email (yahoo?) to use text mode email, to not delete spaces, to honor newlines, etc. > > > ----- Original Message ----- > From: Chris Angelico > To: python-list at python.org Why is the quoted part *after* your message? Please don't top-post on this list (or most of them). It gets too garbled after one or two generations. -- DaveA From roy at panix.com Sat Jan 5 10:40:42 2013 From: roy at panix.com (Roy Smith) Date: Sat, 05 Jan 2013 10:40:42 -0500 Subject: Couting the number of lines of code of a python program References: <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> <1357399067.54894.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: In article , Dave Angel wrote: > On 01/05/2013 10:17 AM, chaouche yacine wrote: > > > > > > > > Here is my implementation : > > > > defcount_loc(lines):nb_lines =0docstring =Falseforline inlines:line > > =line.strip()ifline ==""\ orline.startswith("#")\ ordocstring > > andnot(line.startswith('"""')orline.startswith("'''"))\ > > or(line.startswith("'''")andline.endswith("'''")andlen(line)>3)\ > > or(line.startswith('"""')andline.endswith('"""')andlen(line)>3):continue# > > this is either a starting or ending > > docstringelifline.startswith('"""')orline.startswith("'''"):docstring > > =notdocstring continueelse:nb_lines +=1returnnb_lines > > Wow, this is thoroughly garbled. Please configure your email (yahoo?) > to use text mode email, to not delete spaces, to honor newlines, etc. Nice to know that wasn't just another case of my using an antiquated news reader :-) From matttwall at gmail.com Sat Jan 5 09:30:39 2013 From: matttwall at gmail.com (matttwall at gmail.com) Date: Sat, 5 Jan 2013 06:30:39 -0800 (PST) Subject: Windows Installer Error Message-ID: <4cc9c08a-c123-4699-b082-52e96241717d@googlegroups.com> I am running on Windows 7 Professional x64 with latest service pack and I cannot get Python to install. I run the python-3.2.1.msi, and after I select the installation directory, I get a popup that says "There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor". 2.7.3, amd64, and older packages all do the exact same thing. From matttwall at gmail.com Sat Jan 5 09:35:50 2013 From: matttwall at gmail.com (matttwall at gmail.com) Date: Sat, 5 Jan 2013 06:35:50 -0800 (PST) Subject: Windows Installer Error In-Reply-To: <4cc9c08a-c123-4699-b082-52e96241717d@googlegroups.com> References: <4cc9c08a-c123-4699-b082-52e96241717d@googlegroups.com> Message-ID: <2428a000-bb74-4bdd-a169-ae8590ae9b4f@googlegroups.com> On Saturday, January 5, 2013 8:30:39 AM UTC-6, matt... at gmail.com wrote: > I am running on Windows 7 Professional x64 with latest service pack and I cannot get Python to install. I run the python-3.2.1.msi, and after I select the installation directory, I get a popup that says "There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor". 2.7.3, amd64, and older packages all do the exact same thing. NVM, I solved it just this very moment. I found this topic http://superuser.com/questions/478631/dll-could-not-be-run-for-msi-installers. It turns out I had to go to my Temp directory and give Full Control to the Everyone group. No idea why the MSI wouldn't have admin rights. From gabrieldenmark at gmail.com Sat Jan 5 10:47:20 2013 From: gabrieldenmark at gmail.com (Christian Gabriel) Date: Sat, 5 Jan 2013 07:47:20 -0800 (PST) Subject: Random List Loop?! Message-ID: Hi I have tried now for ages to make a loop that does the following: Makes a new list with 9 random values, from 9 different lists, with 9 elements. And makes sure that none of the elements repeat! Is there anyone that can help, with a very simple solution?? Best Christian From roy at panix.com Sat Jan 5 10:54:39 2013 From: roy at panix.com (Roy Smith) Date: Sat, 05 Jan 2013 10:54:39 -0500 Subject: Random List Loop?! References: Message-ID: In article , Christian Gabriel wrote: > Hi > > I have tried now for ages to make a loop that does the following: > > Makes a new list with 9 random values, from 9 different lists, with 9 > elements. > > And makes sure that none of the elements repeat! > > Is there anyone that can help, with a very simple solution?? > > Best > > Christian You want random.sample() http://docs.python.org/2/library/random.html#random.sample From rosuav at gmail.com Sat Jan 5 10:59:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 02:59:16 +1100 Subject: Random List Loop?! In-Reply-To: References: Message-ID: On Sun, Jan 6, 2013 at 2:47 AM, Christian Gabriel wrote: > Hi > > I have tried now for ages to make a loop that does the following: > > Makes a new list with 9 random values, from 9 different lists, with 9 elements. > > And makes sure that none of the elements repeat! > > Is there anyone that can help, with a very simple solution?? Sounds like a homework question to me. You've tried. What code have you come up with, and to what extent does it fall short of your goal? The nine different lists - do they have unique elements? Are you able to use sets? (If you haven't been taught what a set is, the answer's probably no.) ChrisA From oscar.j.benjamin at gmail.com Sat Jan 5 11:02:18 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 5 Jan 2013 16:02:18 +0000 Subject: Random List Loop?! In-Reply-To: References: Message-ID: On 5 January 2013 15:47, Christian Gabriel wrote: > Hi > > I have tried now for ages to make a loop that does the following: > > Makes a new list with 9 random values, from 9 different lists, with 9 elements. > > And makes sure that none of the elements repeat! > > Is there anyone that can help, with a very simple solution?? I'm sure that there is a simple solution but I don't fully understand your problem could you perhaps provide an example with actual numbers (perhaps use 3 instead of 9 so it's easier to follow)? In any case I suspect that you want something involving range() and random.shuffle() if that helps. Oscar From asim.r.p at gmail.com Sat Jan 5 13:25:41 2013 From: asim.r.p at gmail.com (Asim) Date: Sat, 5 Jan 2013 10:25:41 -0800 (PST) Subject: reduce expression to test sublist Message-ID: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> Hi All The following reduce expression checks if every element of list lst1 is present in list lst2. It works as expected for integer lists but for lists of strings, it always returns False. reduce( lambda x,y: (x in lst2) and (y in lst2), lst1) Moreover, for the lists of strings the following for-loop gives correct results when the above reduce expression doesn't. isSublist = True for i in lst1: isSublist = isSublist and (i in lst2) if not isSublist: isSublist = False break Can someone help me understand why? Asim From d at davea.name Sat Jan 5 13:58:10 2013 From: d at davea.name (Dave Angel) Date: Sat, 05 Jan 2013 13:58:10 -0500 Subject: reduce expression to test sublist In-Reply-To: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> References: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> Message-ID: <50E877C2.8090208@davea.name> On 01/05/2013 01:25 PM, Asim wrote: > Hi All > > The following reduce expression checks if every element of list lst1 is present in list lst2. It works as expected for integer lists but for lists of strings, it always returns False. > > reduce( lambda x,y: (x in lst2) and (y in lst2), lst1) > > Moreover, for the lists of strings the following for-loop gives correct results when the above reduce expression doesn't. > > isSublist = True > for i in lst1: > isSublist = isSublist and (i in lst2) > if not isSublist: > isSublist = False > break > > > Can someone help me understand why? > > Asim reduce only makes sense if the value you're reducing to is of the same type as the elements of the list you're iterating over. Since your lambda expression returns a boolean (True or False), it'll seem to work on some lists of ints. That's just a coincidence since the bools are compatible with ints, and maybe you've got a 0 or 1 in the list. But if your list has only strings, then True will never be that list. If you're trying to make a faster loop, then I suggest you look into set differences. Turn both lists into sets, and subtract them. Something like (untested): result = not bool( set(lst1) - set(lst2) ) -- DaveA From tjreedy at udel.edu Sat Jan 5 16:55:50 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 Jan 2013 16:55:50 -0500 Subject: reduce expression to test sublist In-Reply-To: <50E877C2.8090208@davea.name> References: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> <50E877C2.8090208@davea.name> Message-ID: On 1/5/2013 1:58 PM, Dave Angel wrote: > If you're trying to make a faster loop, then I suggest you look into set > differences. Turn both lists into sets, and subtract them. Something > like (untested): > > result = not bool( set(lst1) - set(lst2) ) This does not return False as soon as an item in set1 is found that is not in set2. set(lst1) < set(lst2) will, and directly return False/True. The OP is trying to compute the lst1 < lst2, where lst1 and lst2 are interpreted as sets, rather than as sequences with the lexicographic ordering default. -- Terry Jan Reedy From d at davea.name Sat Jan 5 17:05:20 2013 From: d at davea.name (Dave Angel) Date: Sat, 05 Jan 2013 17:05:20 -0500 Subject: reduce expression to test sublist In-Reply-To: References: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> <50E877C2.8090208@davea.name> Message-ID: <50E8A3A0.2010208@davea.name> On 01/05/2013 04:55 PM, Terry Reedy wrote: > On 1/5/2013 1:58 PM, Dave Angel wrote: > >> If you're trying to make a faster loop, then I suggest you look into set >> differences. Turn both lists into sets, and subtract them. Something >> like (untested): >> >> result = not bool( set(lst1) - set(lst2) ) > > This does not return False as soon as an item in set1 is found that is > not in set2. > > set(lst1) < set(lst2) > > will, and directly return False/True. The OP is trying to compute the > lst1 < lst2, where lst1 and lst2 are interpreted as sets, rather than > as sequences with the lexicographic ordering default. > Thanks. I wasn't aware that sets supported ordered comparison that way, though it makes perfect sense now that you point it out. -- DaveA From yacinechaouche at yahoo.com Sat Jan 5 14:59:56 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sat, 5 Jan 2013 11:59:56 -0800 (PST) Subject: reduce expression to test sublist In-Reply-To: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> References: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> Message-ID: <1357415996.1332.YahooMailNeo@web125505.mail.ne1.yahoo.com> Because reduce doesn't do what you want. You'd want "all". L1 = [1,2,3] L2 = ["A1","B2","C3",1,2,3] print all((x in L2 for x in L1)) # prints True L3 = ["A1","B2","C3"] print all((x in L2 for x in L3)) # prints True ----- Original Message ----- From: Asim To: python-list at python.org Cc: Sent: Saturday, January 5, 2013 7:25 PM Subject: reduce expression to test sublist Hi All The following reduce expression checks if every element of list lst1 is present in list lst2.? It works as expected for integer lists but for lists of strings, it always returns False. ? reduce( lambda x,y: (x in lst2) and (y in lst2), lst1) Moreover, for the lists of strings the following for-loop gives correct results when the above reduce expression doesn't. ? isSublist = True ? for i in lst1: ? ? ? isSublist = isSublist and (i in lst2) ? ? ? if not isSublist: ? ? ? ? isSublist = False ? ? ? ? break Can someone help me understand why? Asim -- http://mail.python.org/mailman/listinfo/python-list From jpiitula at ling.helsinki.fi Sat Jan 5 15:41:24 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 05 Jan 2013 22:41:24 +0200 Subject: reduce expression to test sublist References: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> Message-ID: Asim writes: > Hi All > > The following reduce expression checks if every element of list lst1 > is present in list lst2. It works as expected for integer lists but > for lists of strings, it always returns False. > > reduce( lambda x,y: (x in lst2) and (y in lst2), lst1) Possibly this: >>> True in [3, 1, 4] True >>> True in ["3", "1", "4"] False Since reduce(f, [a, b, c]) == f(f(a,b),c), your x will be True or False except in the innermost call where it is the first element of the list being reduced. It doesn't really work with integers either. Only in certain special cases: very short lst1, or True in lst2. > Moreover, for the lists of strings the following for-loop gives > correct results when the above reduce expression doesn't. > > isSublist = True > for i in lst1: > isSublist = isSublist and (i in lst2) > if not isSublist: > isSublist = False > break > > Can someone help me understand why? Consider reduce(lambda x, y: x and (y in whatever), ys, True). Maybe also consider all(y in whatever for y in ys). From tjreedy at udel.edu Sat Jan 5 16:55:59 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 Jan 2013 16:55:59 -0500 Subject: reduce expression to test sublist In-Reply-To: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> References: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> Message-ID: On 1/5/2013 1:25 PM, Asim wrote: > Hi All > > The following reduce expression checks if every element of list lst1 > is present in list lst2. It works as expected for integer lists but > for lists of strings, it always returns False. > > reduce( lambda x,y: (x in lst2) and (y in lst2), lst1) reduce(lambda x, y: x and (y in lst2), lst1, True) would work, but as other have said, you want to stops at the first False, which all() does, and if lst2 is a list of hashable items, x in set for O(1) rather than O(n) check. > Moreover, for the lists of strings the following for-loop gives > correct results when the above reduce expression doesn't. You should include data for testing. > > isSublist = True > for i in lst1: > isSublist = isSublist and (i in> lst2) If isSublist remains True, there is no need to rebind it > if not isSublist: > isSublist = False Setting isSublist False when it is False is redundant. > break Taking into account the comments: def is_sublist(a, b): b = set(b) # optional, depending on contents for item in a: if item not in b: return False else: # not needed because return above return True The code for all() is similar, except that all takes an iterable, so that the testing is done as part of the input iterable. def all(iterable): it = iter(iterable): for item in it: if not it: return False: else: return True def issublist(a, b): b = set(b) return all(item in b for item in a) -- Terry Jan Reedy From missive at hotmail.com Sat Jan 5 14:07:14 2013 From: missive at hotmail.com (Lee Harr) Date: Sat, 5 Jan 2013 23:37:14 +0430 Subject: python wiki gone? Message-ID: Have I just happened across wiki.python.org at a bad time, or is the wiki gone? When I go to wiki.python.org I get redirected to http://wiki.python.org/moin/ which is 404 Not Found. From bahamutzero8825 at gmail.com Sat Jan 5 14:59:48 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 05 Jan 2013 13:59:48 -0600 Subject: python wiki gone? In-Reply-To: References: Message-ID: <50E88634.2090605@gmail.com> On 2013.01.05 13:07, Lee Harr wrote: > When I go to wiki.python.org I get redirected to > http://wiki.python.org/moin/ > which is 404 Not Found. There's a security issue with moinmoin. The Python wiki is not the only wiki offline for this reason. -- CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE From tjreedy at udel.edu Sat Jan 5 17:00:38 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 Jan 2013 17:00:38 -0500 Subject: python wiki gone? In-Reply-To: <50E88634.2090605@gmail.com> References: <50E88634.2090605@gmail.com> Message-ID: On 1/5/2013 2:59 PM, Andrew Berg wrote: > On 2013.01.05 13:07, Lee Harr wrote: >> When I go to wiki.python.org I get redirected to >> http://wiki.python.org/moin/ >> which is 404 Not Found. > There's a security issue with moinmoin. The Python wiki is not the only > wiki offline for this reason. For anyone doing such a thing in the future: A replacement page "The Python wiki is off-line for maintenance." would have been nice. -- Terry Jan Reedy From yacinechaouche at yahoo.com Sat Jan 5 15:35:58 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sat, 5 Jan 2013 12:35:58 -0800 (PST) Subject: __builtins__ in bpython Message-ID: <1357418158.69916.YahooMailNeo@web125502.mail.ne1.yahoo.com> Hi. In the standard pytohon interpreter and in ipython, __builtins__ is a module, but in bpython it's a dictionnary. Was it redefined ? From wuwei23 at gmail.com Sun Jan 6 06:01:15 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 6 Jan 2013 03:01:15 -0800 (PST) Subject: __builtins__ in bpython References: Message-ID: On Jan 6, 6:35?am, chaouche yacine wrote: > Hi. In the standard pytohon interpreter and in ipython, __builtins__ is a module, but in bpython it's a dictionnary. Was it redefined ? I'd say it's a result of however bpython works and this: "By default, when in the __main__ module, __builtins__ is the built-in module builtins; when in any other module, __builtins__ is an alias for the dictionary of the builtins module itself. __builtins__ can be set to a user-created dictionary to create a weak form of restricted execution." http://docs.python.org/3/reference/executionmodel.html#naming-and-binding This is a guess, I've never used bpython, being really quite happy with iPython. Your best bet would be to ask the bpython dev or log an issue on its repository: https://bitbucket.org/bobf/bpython/issues From naccttemha at gmail.com Sat Jan 5 17:05:46 2013 From: naccttemha at gmail.com (Nac Temha) Date: Sun, 6 Jan 2013 00:05:46 +0200 Subject: Python programming philosophy Message-ID: Hello, I want to learn working principle of python as broadly. How to interpret the python? For example, what is pyc files and when does it occur? Can you explain them? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Jan 5 17:15:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 09:15:19 +1100 Subject: Python programming philosophy In-Reply-To: References: Message-ID: On Sun, Jan 6, 2013 at 9:05 AM, Nac Temha wrote: > Hello, > > I want to learn working principle of python as broadly. How to interpret the > python? For example, what is pyc files and when does it occur? > Can you explain them? Thanks in advance. The pyc files aren't really a philosophical point, they're just a cache of the compiled versions of .py files - the assumption being that if you import it as a module once, chances are you'll import it again later, and libraries tend not to change much. For the philosophy of Python, type this at the interactive prompt: import this ChrisA From yacinechaouche at yahoo.com Sat Jan 5 17:34:38 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sat, 5 Jan 2013 14:34:38 -0800 (PST) Subject: Python programming philosophy In-Reply-To: References: Message-ID: <1357425278.40939.YahooMailNeo@web125501.mail.ne1.yahoo.com> The compiler reads your source code and parses it into parse trees. This is first step. It then takes the parse trees and transform them into abstract syntax trees, which are like a DOM tree in an HTML file, and then transform that AST into a control flow graph, and finally a bytecode is produced out of that control flow graph. The pyc files you see are this bytecode, so they are produced at the end. Anytime you edit your .py file, a new .pyc file is created if you invoke the python interpreter myfile.py on the former. If your .py file doesn't change, the .pyc file stays the same. Just like with java, this allows you to write a single .py file that can work on any platform without changing the source file, because all the cross platform issues are handled by the virtual machine. ________________________________ From: Nac Temha To: python-list at python.org Sent: Saturday, January 5, 2013 11:05 PM Subject: Python programming philosophy Hello, I want to learn working principle of python as broadly. How to interpret the python? ?For example, what is pyc files and when does it occur? Can you explain them? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at googlemail.com Sat Jan 5 22:41:47 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 5 Jan 2013 19:41:47 -0800 (PST) Subject: Python programming philosophy In-Reply-To: References: Message-ID: chaouche yacine? 2013?1?6????UTC+8??6?34?38???? > The compiler reads your source code and parses it into parse trees. This is first step. It then takes the parse trees and transform them into abstract syntax trees, which are like a DOM tree in an HTML file, and then transform that AST into a control flow graph, and finally a bytecode is produced out of that control flow graph. The pyc files you see are this bytecode, so they are produced at the end. Anytime you edit your .py file, a new .pyc file is created if you invoke the python interpreter myfile.py on the former. If your .py file doesn't change, the .pyc file stays the same. > > Just like with java, this allows you to write a single .py file that can work on any platform without changing the source file, because all the cross platform issues are handled by the virtual machine. > > > > > ________________________________ > From: Nac Temha > To: pytho... at python.org > Sent: Saturday, January 5, 2013 11:05 PM > Subject: Python programming philosophy > > > Hello, > > > > I want to learn working principle of python as broadly. How to interpret the python? ?For example, what is pyc files and when does it occur? > Can you explain them? Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list Yes, check JYTHON tutorials to understand dynamic types. Java is still a fixed type computer language. From dihedral88888 at googlemail.com Sat Jan 5 22:41:47 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 5 Jan 2013 19:41:47 -0800 (PST) Subject: Python programming philosophy In-Reply-To: References: Message-ID: chaouche yacine? 2013?1?6????UTC+8??6?34?38???? > The compiler reads your source code and parses it into parse trees. This is first step. It then takes the parse trees and transform them into abstract syntax trees, which are like a DOM tree in an HTML file, and then transform that AST into a control flow graph, and finally a bytecode is produced out of that control flow graph. The pyc files you see are this bytecode, so they are produced at the end. Anytime you edit your .py file, a new .pyc file is created if you invoke the python interpreter myfile.py on the former. If your .py file doesn't change, the .pyc file stays the same. > > Just like with java, this allows you to write a single .py file that can work on any platform without changing the source file, because all the cross platform issues are handled by the virtual machine. > > > > > ________________________________ > From: Nac Temha > To: pytho... at python.org > Sent: Saturday, January 5, 2013 11:05 PM > Subject: Python programming philosophy > > > Hello, > > > > I want to learn working principle of python as broadly. How to interpret the python? ?For example, what is pyc files and when does it occur? > Can you explain them? Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list Yes, check JYTHON tutorials to understand dynamic types. Java is still a fixed type computer language. From sourabh8044 at gmail.com Sat Jan 5 23:35:01 2013 From: sourabh8044 at gmail.com (Sourabh Mhaisekar) Date: Sat, 5 Jan 2013 20:35:01 -0800 (PST) Subject: Python programming philosophy In-Reply-To: References: Message-ID: The main philosophy behind python (according to me) is rapid application development. The python gives you convinent and powerful tool to develop sophisticated application rapidly. You can find more details on http://www.python.org/about/success/ http://www.python.org/about/success/#rapid-application-development Have a great python time. - Sourabh From sourabh8044 at gmail.com Sat Jan 5 23:35:01 2013 From: sourabh8044 at gmail.com (Sourabh Mhaisekar) Date: Sat, 5 Jan 2013 20:35:01 -0800 (PST) Subject: Python programming philosophy In-Reply-To: References: Message-ID: The main philosophy behind python (according to me) is rapid application development. The python gives you convinent and powerful tool to develop sophisticated application rapidly. You can find more details on http://www.python.org/about/success/ http://www.python.org/about/success/#rapid-application-development Have a great python time. - Sourabh From phostu at gmail.com Sat Jan 5 21:16:34 2013 From: phostu at gmail.com (Vincent) Date: Sat, 5 Jan 2013 18:16:34 -0800 (PST) Subject: A question about thrift performance. Message-ID: Hi, all I have issue of thrift-performance in python, does anyone has an experience on thrift-in-python? My question in stackoverflow: http://stackoverflow.com/questions/14171227/why-is-thrift-binary-protocol-serialization-so-much-slow Copy the question to here(open stackoverflow to check pretty-print question content): I'm newbie on thrift. I wrote a thrift server in python, also client in python too. Here is my thrift defination: struct RatingByReport { 1: required string ticker, 2: required i32 cnt_institution, 3: optional list strong_buy, 4: optional list buy, 5: optional list neutral, 6: optional list sell, 7: optional list strong_sell, 8: optional i32 cnt_maintain, 9: optional i32 cnt_upgrade, 10: optional i32 cnt_downgrade, 11: optional i32 avg_score, 12: optional string adjustment } struct TableRatingByReport { 1: required list head, 2: required list body, 3: optional struct.CadaTranslation translation } service china{ void ping(), TableRatingByReport rating_byreport(1:string ticker) throws (1:struct.CadaInternalError error) } Here is my server side: handler = StockChinaHandler() processor = china.Processor(handler) #startup() transport = TSocket.TServerSocket(port=30303) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) #server = TProcessPoolServer.TProcessPoolServer(processor, transport, # tfactory, pfactory) print "Start server..." import cProfile print >>open('/tmp/test.log', 'w'), cProfile.run('server.serve()', sort='cumulative') #server.serve() print "done!" Client side: # Make socket transport = TSocket.TSocket('localhost', 30303) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = china.Client(protocol) # Connect! transport.open() client.ping() print "ping()" print msg msg = client.rating_byreport('2012-01-04') print msg transport.close() cProfile result: ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 230.968 230.968 :1() 1 0.000 0.000 230.968 230.968 TServer.py:74(serve) 3 0.000 0.000 225.967 75.322 TSocket.py:172(accept) 3 0.000 0.000 225.967 75.322 socket.py:194(accept) 3 225.967 75.322 225.967 75.322 {method 'accept' of '_socket.socket' objects} 5 0.003 0.001 4.993 0.999 china.py:140(process) 1 0.000 0.000 3.200 3.200 china.py:177(process_rating_byreport) 1 0.000 0.000 2.366 2.366 china.py:500(write) 1 0.003 0.003 2.366 2.366 ttypes.py:515(write) 1455 0.261 0.000 2.363 0.002 ttypes.py:364(write) 155556 0.246 0.000 1.995 0.000 TCompactProtocol.py:38(nested) 145880 0.298 0.000 1.640 0.000 TCompactProtocol.py:255(__writeString) 18 1.370 0.076 1.370 0.076 {method 'recv' of '_socket.socket' objects} 5 0.000 0.000 1.292 0.258 TCompactProtocol.py:306(readMessageBegin) 13 0.000 0.000 1.292 0.099 TCompactProtocol.py:286(__readUByte) 26 0.000 0.000 1.291 0.050 TTransport.py:54(readAll) 26 0.000 0.000 1.291 0.050 TTransport.py:154(read) 5 0.000 0.000 1.291 0.258 TSocket.py:101(read) In my case, TableRatingByReport instance got a body with 1400 rows(list\), and It cost over 3 seconds(function *process_rating_byreport*, which is auto generate by thift) to generate binnary content. I don't know why it is so slow. Using json to serialize the same data, It's only spend less than 200 ms. I'm wondering did I use the uncorrect way to manipulate thrift? Thanks. From sourabh8044 at gmail.com Sat Jan 5 23:45:11 2013 From: sourabh8044 at gmail.com (Sourabh Mhaisekar) Date: Sat, 5 Jan 2013 20:45:11 -0800 (PST) Subject: Good Python IDE Message-ID: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Hello All, I am recently started couple of projects in Python, one in Python GTK and one in Python Qt. I want a good IDE (For Windows ) for Python which gives support for Python as well as PyGtk and PyQt. Features I am looking for * Support for Core Python Auto-completion. * Support for PyGtk and PyQt * Support for either Bazaar (preferred) or CVS Thanks ! - Sourabh From io at noi.com Sun Jan 6 07:48:21 2013 From: io at noi.com (Tetsuya) Date: Sun, 06 Jan 2013 13:48:21 +0100 Subject: Good Python IDE References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: On 01/06/2013 05:45 AM, Sourabh Mhaisekar wrote: > Hello All, > I am recently started couple of projects in Python, one in Python GTK > and one in Python Qt. I want a good IDE (For Windows ) for Python which > gives support for Python as well as PyGtk and PyQt. > > Features I am looking for > * Support for Core Python Auto-completion. > * Support for PyGtk and PyQt > * Support for either Bazaar (preferred) or CVS > > Thanks ! > > - Sourabh > I develop only under GNU/Linux (using Vim, with some plugins like python-jedi and supertab for autocompletion, Gundo for undo management in a *very* smart way, etc..), but in the recent past I tried various IDEs. They're all ugly and/or cumbersome, but it seemed to me that the less ugly maybe is PyCharm, you could try that. From cjw at ncf.ca Sun Jan 6 08:08:43 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 06 Jan 2013 08:08:43 -0500 Subject: Good Python IDE In-Reply-To: References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: On 06/01/2013 7:48 AM, Tetsuya wrote: > On 01/06/2013 05:45 AM, Sourabh Mhaisekar wrote: >> Hello All, >> I am recently started couple of projects in Python, one in Python GTK > > and one in Python Qt. I want a good IDE (For Windows ) for Python which > > gives support for Python as well as PyGtk and PyQt. >> >> Features I am looking for >> * Support for Core Python Auto-completion. >> * Support for PyGtk and PyQt >> * Support for either Bazaar (preferred) or CVS >> >> Thanks ! >> >> - Sourabh >> > > I develop only under GNU/Linux (using Vim, with some plugins like > python-jedi and supertab for autocompletion, Gundo for undo management > in a *very* smart way, etc..), but in the recent past I tried various > IDEs. They're all ugly and/or cumbersome, but it seemed to me that the > less ugly maybe is PyCharm, you could try that. I would suggest that you look at PyScripter for Windows or Linuz when Wine is available. See: http://www.decalage.info/en/python/tutorial Colin W. From memilanuk at gmail.com Sun Jan 6 13:06:46 2013 From: memilanuk at gmail.com (Monte Milanuk) Date: Sun, 06 Jan 2013 10:06:46 -0800 Subject: Good Python IDE In-Reply-To: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: Lots of good options out there... currently I'm liking spyder or eclipse a lot. From a.klein at science-applied.nl Sun Jan 6 17:22:24 2013 From: a.klein at science-applied.nl (Almar Klein) Date: Sun, 6 Jan 2013 23:22:24 +0100 Subject: Good Python IDE In-Reply-To: References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: IEP has support for integrating the event loops of both GTK and Qt: https://code.google.com/p/iep/ No version control support though. - Almar On 6 January 2013 19:06, Monte Milanuk wrote: > Lots of good options out there... currently I'm liking spyder or eclipse a > lot. > > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Almar Klein, PhD Science Applied phone: +31 6 19268652 e-mail: a.klein at science-applied.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at akwebsoft.com Sun Jan 6 17:13:02 2013 From: tim at akwebsoft.com (Tim Johnson) Date: Sun, 6 Jan 2013 13:13:02 -0900 Subject: Good Python IDE In-Reply-To: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: <20130106221302.GL54763@mail.akwebsoft.com> * Sourabh Mhaisekar [130106 07:11]: > Hello All, > I am recently started couple of projects in Python, one in Python GTK and one in Python Qt. I want a good IDE (For Windows ) for Python which gives support for Python as well as PyGtk and PyQt. > > Features I am looking for > * Support for Core Python Auto-completion. > * Support for PyGtk and PyQt > * Support for either Bazaar (preferred) or CVS I haven't developed on windows in over 10 years, but as I recall, pythonwin worked well for me at the time. I don't recall whether the 2nd and 3rd features you refer to were available, but the first was. It is easy enough to try. Now I use vim for all of my work. I pretty-much hand-rolled my own IDE, which is typical of vimmers. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From io at noi.com Sun Jan 6 18:32:49 2013 From: io at noi.com (Tetsuya) Date: Mon, 07 Jan 2013 00:32:49 +0100 Subject: Good Python IDE References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: On 01/06/2013 11:13 PM, Tim Johnson wrote: > Now I use vim for all of my work. I pretty-much hand-rolled my own > IDE, which is typical of vimmers. I did like you, too. I use vim for everything: coding in python, django, js, html, C/C++, bash, even email (inside mutt, of course). Start with an empty ~/.vimrc, and then build up the configuration day by day, adding one single plugin at a time, driven by your daily needs, it's the better thing to do IMHO. Thus vim becomes a full fledged IDE for everything, and it does it *your* way, not *its* way. BTW, vim is available also under Windows. From ben+python at benfinney.id.au Sun Jan 6 19:25:54 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 07 Jan 2013 11:25:54 +1100 Subject: Good Python IDE References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: <7wtxqtdejx.fsf@benfinney.id.au> Tetsuya writes: > BTW, vim is available also under Windows. And this is one of the best reasons to learn either Vim or Emacs (or both, eventually): one should not be tied to any particular OS for access to one's development tools. Vim and Emacs are both general-purpose, highly-extensible and -extended, powerful editing tools. But more important than those is that they are both free software and (partly as a result of that freedom) well-supported by a mature community of developers. Core programming tools, like your text editor or your team's VCS, take significant investment. Don't needlessly squander that investment on a tool limited to a single language, a single vendor, or a single operating system. -- \ ?All good things are cheap; all bad are very dear.? ?Henry | `\ David Thoreau | _o__) | Ben Finney From tim at akwebsoft.com Sun Jan 6 19:59:37 2013 From: tim at akwebsoft.com (Tim Johnson) Date: Sun, 6 Jan 2013 15:59:37 -0900 Subject: Good Python IDE In-Reply-To: References: <8a6d17a5-447a-4da5-9ff4-53e0350ce19e@googlegroups.com> Message-ID: <20130107005937.GN54763@mail.akwebsoft.com> * Tetsuya [130106 14:43]: > On 01/06/2013 11:13 PM, Tim Johnson wrote: > > Now I use vim for all of my work. I pretty-much hand-rolled my own > > IDE, which is typical of vimmers. > > I did like you, too. > I use vim for everything: coding in python, django, js, html, C/C++, > bash, even email (inside mutt, of course). Yes, Yes... > Start with an empty ~/.vimrc, and then build up the configuration day by > day, adding one single plugin at a time, driven by your daily needs, > it's the better thing to do IMHO. > Thus vim becomes a full fledged IDE for everything, and it does it > *your* way, not *its* way. :) Great minds run in the same gutter ... > BTW, vim is available also under Windows. Where I started using it. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From reganrexman at gmail.com Sun Jan 6 01:05:42 2013 From: reganrexman at gmail.com (reganrexman) Date: Sun, 06 Jan 2013 00:05:42 -0600 Subject: SOLUTIONS MANUAL TO A Course in Modern Mathematical Physics by Peter Szekeres Message-ID: <9KCdnZs-_Z2riXTNnZ2dnUVZ_tKdnZ2d@giganews.com> I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTIONS MANUAL TO A First Course in Differential Equations (7th ed.) Zill & Diferential Equations (5th ed.)Zill & Cullen SOLUTIONS MANUAL TO 2500 Solved Problems in Fluid Mechanics & Hydraulics Schaums by Evett, cheng Liu SOLUTIONS MANUAL TO A Course in Game Theory by Osborne, Rubinstein SOLUTIONS MANUAL TO A Course in Modern Mathematical Physics by Peter Szekeres SOLUTIONS MANUAL TO A Course in Ordinary Differential Equations by Swift, Wirkus SOLUTIONS MANUAL TO A First Course in Abstract Algebra (7th Ed., John B. Fraleigh) SOLUTIONS MANUAL TO A First Course in Differential Equations - The Classic Fifth Edition By Zill, Dennis G SOLUTIONS MANUAL TO A First Course in Differential Equations, 9th Ed by Dennis G. Zill SOLUTIONS MANUAL TO A First Course In Probability 7th Edition by Sheldon M. Ross SOLUTIONS MANUAL TO A First Course in Probability Theory, 6th edition, by S. Ross. SOLUTIONS MANUAL TO A First Course in String Theory, 2004, Barton Zwiebach SOLUTIONS MANUAL TO A First Course in the Finite Element Method, 4th Edition logan SOLUTIONS MANUAL TO A Practical Introduction to Data Structures and Algorithm Analysis 2Ed by Shaffer SOLUTIONS MANUAL TO A Quantum Approach to Condensed Matter Physics (Philip L. Taylor & Olle Heinonen) SOLUTIONS MANUAL TO A Short Course in General Relativity 2e by J. Foster and J. D. Nightingale SOLUTIONS MANUAL TO A Short Introduction to Quantum Information and Quantum Computation by Michel Le Bellac SOLUTIONS MANUAL TO A Transition to Advanced Mathematics 5th E by Smith, Eggen, Andre SOLUTIONS MANUAL TO Accounting Principles 8e by Kieso, Kimmel SOLUTIONS MANUAL TO Accounting principles 8th Ed by Weygandt SOLUTIONS MANUAL TO Accounting, 23 Ed by Carl S. Warren, James M. Reeve, Jonathan Duchac SOLUTIONS MANUAL TO Accounting,8th Ed by Horngren,Harrison, Oliver SOLUTIONS MANUAL TO Adaptive Control, 2nd. Ed., by Astrom, Wittenmark SOLUTIONS MANUAL TO Adaptive Filter Theory (4th Ed., Simon Haykin) SOLUTIONS MANUAL TO Advanced Accounting 10E international ED by Beams , Clement, Anthony, Lowensohn SOLUTIONS MANUAL TO Advanced accounting 9th Ed by Hoyle, Schaefer SOLUTIONS MANUAL TO Advanced Calculus Gerald B. Folland SOLUTIONS MANUAL TO Advanced Digital Design with the Verilog HDL by Michael D. Ciletti SOLUTIONS MANUAL TO Advanced Dynamics (Greenwood) SOLUTIONS MANUAL TO Advanced Engineering Electromagnetics by Constantine A. Balanis SOLUTIONS MANUAL TO Advanced Engineering Mathematics 3rd ed zill SOLUTIONS MANUAL TO Advanced Engineering Mathematics 8Ed Erwin Kreyszig SOLUTIONS MANUAL TO Advanced Engineering Mathematics by Erwin Kreyszig, 9th ed SOLUTIONS MANUAL TO Advanced Engineering Mathematics, 6th Edition by Peter V. O'Neil SOLUTIONS MANUAL TO Advanced Engineering Mathematics,2E, by Zill, Cullen SOLUTIONS MANUAL TO Advanced Engineering Thermodynamics, 3rd Edition by Adrian Bejan SOLUTIONS MANUAL TO Advanced Financial Accounting by Baker SOLUTIONS MANUAL TO Advanced Financial Accounting 5 Ed by Baker SOLUTIONS MANUAL TO Advanced Industrial Economics by Martin SOLUTIONS MANUAL TO Advanced Industrial Economics, 2nd ED Stephen Martin SOLUTIONS MANUAL TO Advanced Macroeconomics 2nd edition by David Romer SOLUTIONS MANUAL TO Advanced Macroeconomics, by David Romer SOLUTIONS MANUAL TO Advanced Mechanics of Materials 6th ed by Boresi, Schmidt SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 3rd Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 4th Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics, 3rd Ed., by G. James SOLUTIONS MANUAL TO Advanced Organic Chemistry Part A- Structure and Mechanisms 5th E by Carey, Sundberg SOLUTIONS MANUAL TO Aircraft Structures for Engineering Students (4th Ed., T.H.G. Megson) SOLUTIONS MANUAL TO Algebra & Trigonometry and Precalculus, 3rd Ed By Beecher, Penna, Bittinger SOLUTIONS MANUAL TO Algebra Baldor SOLUTIONS MANUAL TO Algebra-By Thomas W. Hungerford SOLUTIONS MANUAL TO Algorithm Design (Jon Kleinberg & ????va Tardos) SOLUTIONS MANUAL TO An Interactive Introduction to Mathematical Analysis 2nd E (Jonathan Lewin) SOLUTIONS MANUAL TO An Introduction To Analysis 4th Ed by William Wade SOLUTIONS MANUAL TO An Introduction to Database Systems (8th Ed., C.J. Date) SOLUTIONS MANUAL TO An Introduction to Economic Dynamics by Ronald Shone SOLUTIONS MANUAL TO An Introduction to Modern Astrophysics (2nd Ed., Bradley W. Carroll & Dale A. Ostlie) SOLUTIONS MANUAL TO An Introduction to Numerical Analysis By Endre S??li,David F. Mayers SOLUTIONS MANUAL TO An Introduction to Ordinary Differential Equations (James C. Robinson) SOLUTIONS MANUAL TO An Introduction to Signals and Systems by John Stuller SOLUTIONS MANUAL TO An Introduction to Stochastic Modeling 3rd Ed by Taylor, Karlin SOLUTIONS MANUAL TO An Introduction to the Finite Element Method (3rd Ed., J. N. Reddy) SOLUTIONS MANUAL TO An Introduction to Thermal Physics by Schroeder, Daniel V SOLUTIONS MANUAL TO An Introduction to Thermodynamics and Statistical Mechanics (2nd Ed, Keith Stowe) SOLUTIONS MANUAL TO An Introduction to Wavelets through Linear Algebra by Frazier SOLUTIONS MANUAL TO Analog Integrated Circuit Design, by Johns, Martin SOLUTIONS MANUAL TO Analysis and Design of Analog Integrated Circuits (4th Edition) by Gray , Lewis , Meyer SOLUTIONS MANUAL TO Analysis With an Introduction to Proof 4th E by Lay SOLUTIONS MANUAL TO Analytical Chemistry, Higson SOLUTIONS MANUAL TO Analytical Mechanics 7E by Grant R. Fowles, George L. Cassiday SOLUTIONS MANUAL TO Antenna Theory 2nd edition by Balanis SOLUTIONS MANUAL TO Antenna Theory and Design, 2nd Ed Vol.1 by Stutzman, Thiele SOLUTIONS MANUAL TO Antennas for All Applications (3rd Ed., John Kraus & Ronald Marhefka) SOLUTIONS MANUAL TO Applied Calculus by Hallett,Gleason, Lock, Flath SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 7 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 8 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Econometric Time Series, 2nd Edition by Enders SOLUTIONS MANUAL TO Applied Finite Element Analysis 2ed, by LJ SEGERLIND SOLUTIONS MANUAL TO Applied Fluid Mechanics (6th Ed., Mott) SOLUTIONS MANUAL TO Applied Linear Regression 3rd Ed by Sanford Weisberg SOLUTIONS MANUAL TO Applied Numerical Analysis, 7th Edition, by Gerald, Wheatley SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists 2nd E by Chapra SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists( Steven C. Chapra) SOLUTIONS MANUAL TO Applied Partial Differential Equations (4th Ed., Haberman) SOLUTIONS MANUAL TO Applied Partial Differential Equations by J. David Logan SOLUTIONS MANUAL TO Applied Probability Models with Optimization Applications By Sheldon M. Ross SOLUTIONS MANUAL TO Applied Quantum Mechanics ( A. F. J. Levi ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers ( 2nd Ed., Douglas Montgomery & George Runger ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers (3rd Ed., Douglas Montgomery & George Runger) SOLUTIONS MANUAL TO Applied Strength of Materials (4th Ed., Mott) SOLUTIONS MANUAL TO Applied Strength of Materials (5th Ed., Mott) SOLUTIONS MANUAL TO Applying Maths in the Chemical and Biomolecular Sciences, Beddard SOLUTIONS MANUAL TO Artificial Intelligence A Modern Approach 2e by Russell, Norvig SOLUTIONS MANUAL TO Artificial Neural Networks by B. Yegnanarayana and S. Ramesh SOLUTIONS MANUAL TO Assembly Language for Intel-Based Computers ( 3rd Edition ) by Kip R. Irvine SOLUTIONS MANUAL TO Auditing and Assurance Services- An Integrated Approach 12E by Arens SOLUTIONS MANUAL TO Auditing and Assurance Services, 12th edition, Alvin A Arens, Randal J Elder, Mark Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 13 ed by Arens, Elder, Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 2nd Ed by Louwers SOLUTIONS MANUAL TO Automatic Control Systems 9 Ed by Kuo, Golnaraghi SOLUTIONS MANUAL TO Automatic Control Systems, 8E, by Kuo, Golnaraghi SOLUTIONS MANUAL TO Basic Econometrics 4 ed by Damodar N. Gujarati SOLUTIONS MANUAL TO Basic Electrical Engineering By Nagrath, D P Kothari SOLUTIONS MANUAL TO Basic Electromagnetics with Applications by Nannapaneni Narayana Rao SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 7th Ed by David Irwin SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 8th Edition by J. David Irwin, R. Mark Nelms SOLUTIONS MANUAL TO Basic Heat and Mass Transfer by A. F. Mills SOLUTIONS MANUAL TO Basic Principles and Calculations in Chemical engineering 7th Edition by David M. Himmelblau, James B. Riggs SOLUTIONS MANUAL TO Basic Probability Theory by Robert B. Ash SOLUTIONS MANUAL TO Bayesian Core by Christian P. Robert and Jean-Michel Marin SOLUTIONS MANUAL TO Bioprocess Engineering Principles (Pauline M. Doran) SOLUTIONS MANUAL TO Business Statistics - Decision Making 7th E by David F. Groebner SOLUTIONS MANUAL TO C++ for Computer Science and Engineering by Vic Broquard From reganrexman at gmail.com Sun Jan 6 01:05:47 2013 From: reganrexman at gmail.com (reganrexman) Date: Sun, 06 Jan 2013 00:05:47 -0600 Subject: SOLUTIONS MANUAL TO A Course in Modern Mathematical Physics by Peter Szekeres Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTIONS MANUAL TO A First Course in Differential Equations (7th ed.) Zill & Diferential Equations (5th ed.)Zill & Cullen SOLUTIONS MANUAL TO 2500 Solved Problems in Fluid Mechanics & Hydraulics Schaums by Evett, cheng Liu SOLUTIONS MANUAL TO A Course in Game Theory by Osborne, Rubinstein SOLUTIONS MANUAL TO A Course in Modern Mathematical Physics by Peter Szekeres SOLUTIONS MANUAL TO A Course in Ordinary Differential Equations by Swift, Wirkus SOLUTIONS MANUAL TO A First Course in Abstract Algebra (7th Ed., John B. Fraleigh) SOLUTIONS MANUAL TO A First Course in Differential Equations - The Classic Fifth Edition By Zill, Dennis G SOLUTIONS MANUAL TO A First Course in Differential Equations, 9th Ed by Dennis G. Zill SOLUTIONS MANUAL TO A First Course In Probability 7th Edition by Sheldon M. Ross SOLUTIONS MANUAL TO A First Course in Probability Theory, 6th edition, by S. Ross. SOLUTIONS MANUAL TO A First Course in String Theory, 2004, Barton Zwiebach SOLUTIONS MANUAL TO A First Course in the Finite Element Method, 4th Edition logan SOLUTIONS MANUAL TO A Practical Introduction to Data Structures and Algorithm Analysis 2Ed by Shaffer SOLUTIONS MANUAL TO A Quantum Approach to Condensed Matter Physics (Philip L. Taylor & Olle Heinonen) SOLUTIONS MANUAL TO A Short Course in General Relativity 2e by J. Foster and J. D. Nightingale SOLUTIONS MANUAL TO A Short Introduction to Quantum Information and Quantum Computation by Michel Le Bellac SOLUTIONS MANUAL TO A Transition to Advanced Mathematics 5th E by Smith, Eggen, Andre SOLUTIONS MANUAL TO Accounting Principles 8e by Kieso, Kimmel SOLUTIONS MANUAL TO Accounting principles 8th Ed by Weygandt SOLUTIONS MANUAL TO Accounting, 23 Ed by Carl S. Warren, James M. Reeve, Jonathan Duchac SOLUTIONS MANUAL TO Accounting,8th Ed by Horngren,Harrison, Oliver SOLUTIONS MANUAL TO Adaptive Control, 2nd. Ed., by Astrom, Wittenmark SOLUTIONS MANUAL TO Adaptive Filter Theory (4th Ed., Simon Haykin) SOLUTIONS MANUAL TO Advanced Accounting 10E international ED by Beams , Clement, Anthony, Lowensohn SOLUTIONS MANUAL TO Advanced accounting 9th Ed by Hoyle, Schaefer SOLUTIONS MANUAL TO Advanced Calculus Gerald B. Folland SOLUTIONS MANUAL TO Advanced Digital Design with the Verilog HDL by Michael D. Ciletti SOLUTIONS MANUAL TO Advanced Dynamics (Greenwood) SOLUTIONS MANUAL TO Advanced Engineering Electromagnetics by Constantine A. Balanis SOLUTIONS MANUAL TO Advanced Engineering Mathematics 3rd ed zill SOLUTIONS MANUAL TO Advanced Engineering Mathematics 8Ed Erwin Kreyszig SOLUTIONS MANUAL TO Advanced Engineering Mathematics by Erwin Kreyszig, 9th ed SOLUTIONS MANUAL TO Advanced Engineering Mathematics, 6th Edition by Peter V. O'Neil SOLUTIONS MANUAL TO Advanced Engineering Mathematics,2E, by Zill, Cullen SOLUTIONS MANUAL TO Advanced Engineering Thermodynamics, 3rd Edition by Adrian Bejan SOLUTIONS MANUAL TO Advanced Financial Accounting by Baker SOLUTIONS MANUAL TO Advanced Financial Accounting 5 Ed by Baker SOLUTIONS MANUAL TO Advanced Industrial Economics by Martin SOLUTIONS MANUAL TO Advanced Industrial Economics, 2nd ED Stephen Martin SOLUTIONS MANUAL TO Advanced Macroeconomics 2nd edition by David Romer SOLUTIONS MANUAL TO Advanced Macroeconomics, by David Romer SOLUTIONS MANUAL TO Advanced Mechanics of Materials 6th ed by Boresi, Schmidt SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 3rd Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 4th Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics, 3rd Ed., by G. James SOLUTIONS MANUAL TO Advanced Organic Chemistry Part A- Structure and Mechanisms 5th E by Carey, Sundberg SOLUTIONS MANUAL TO Aircraft Structures for Engineering Students (4th Ed., T.H.G. Megson) SOLUTIONS MANUAL TO Algebra & Trigonometry and Precalculus, 3rd Ed By Beecher, Penna, Bittinger SOLUTIONS MANUAL TO Algebra Baldor SOLUTIONS MANUAL TO Algebra-By Thomas W. Hungerford SOLUTIONS MANUAL TO Algorithm Design (Jon Kleinberg & ????va Tardos) SOLUTIONS MANUAL TO An Interactive Introduction to Mathematical Analysis 2nd E (Jonathan Lewin) SOLUTIONS MANUAL TO An Introduction To Analysis 4th Ed by William Wade SOLUTIONS MANUAL TO An Introduction to Database Systems (8th Ed., C.J. Date) SOLUTIONS MANUAL TO An Introduction to Economic Dynamics by Ronald Shone SOLUTIONS MANUAL TO An Introduction to Modern Astrophysics (2nd Ed., Bradley W. Carroll & Dale A. Ostlie) SOLUTIONS MANUAL TO An Introduction to Numerical Analysis By Endre S??li,David F. Mayers SOLUTIONS MANUAL TO An Introduction to Ordinary Differential Equations (James C. Robinson) SOLUTIONS MANUAL TO An Introduction to Signals and Systems by John Stuller SOLUTIONS MANUAL TO An Introduction to Stochastic Modeling 3rd Ed by Taylor, Karlin SOLUTIONS MANUAL TO An Introduction to the Finite Element Method (3rd Ed., J. N. Reddy) SOLUTIONS MANUAL TO An Introduction to Thermal Physics by Schroeder, Daniel V SOLUTIONS MANUAL TO An Introduction to Thermodynamics and Statistical Mechanics (2nd Ed, Keith Stowe) SOLUTIONS MANUAL TO An Introduction to Wavelets through Linear Algebra by Frazier SOLUTIONS MANUAL TO Analog Integrated Circuit Design, by Johns, Martin SOLUTIONS MANUAL TO Analysis and Design of Analog Integrated Circuits (4th Edition) by Gray , Lewis , Meyer SOLUTIONS MANUAL TO Analysis With an Introduction to Proof 4th E by Lay SOLUTIONS MANUAL TO Analytical Chemistry, Higson SOLUTIONS MANUAL TO Analytical Mechanics 7E by Grant R. Fowles, George L. Cassiday SOLUTIONS MANUAL TO Antenna Theory 2nd edition by Balanis SOLUTIONS MANUAL TO Antenna Theory and Design, 2nd Ed Vol.1 by Stutzman, Thiele SOLUTIONS MANUAL TO Antennas for All Applications (3rd Ed., John Kraus & Ronald Marhefka) SOLUTIONS MANUAL TO Applied Calculus by Hallett,Gleason, Lock, Flath SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 7 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 8 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Econometric Time Series, 2nd Edition by Enders SOLUTIONS MANUAL TO Applied Finite Element Analysis 2ed, by LJ SEGERLIND SOLUTIONS MANUAL TO Applied Fluid Mechanics (6th Ed., Mott) SOLUTIONS MANUAL TO Applied Linear Regression 3rd Ed by Sanford Weisberg SOLUTIONS MANUAL TO Applied Numerical Analysis, 7th Edition, by Gerald, Wheatley SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists 2nd E by Chapra SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists( Steven C. Chapra) SOLUTIONS MANUAL TO Applied Partial Differential Equations (4th Ed., Haberman) SOLUTIONS MANUAL TO Applied Partial Differential Equations by J. David Logan SOLUTIONS MANUAL TO Applied Probability Models with Optimization Applications By Sheldon M. Ross SOLUTIONS MANUAL TO Applied Quantum Mechanics ( A. F. J. Levi ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers ( 2nd Ed., Douglas Montgomery & George Runger ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers (3rd Ed., Douglas Montgomery & George Runger) SOLUTIONS MANUAL TO Applied Strength of Materials (4th Ed., Mott) SOLUTIONS MANUAL TO Applied Strength of Materials (5th Ed., Mott) SOLUTIONS MANUAL TO Applying Maths in the Chemical and Biomolecular Sciences, Beddard SOLUTIONS MANUAL TO Artificial Intelligence A Modern Approach 2e by Russell, Norvig SOLUTIONS MANUAL TO Artificial Neural Networks by B. Yegnanarayana and S. Ramesh SOLUTIONS MANUAL TO Assembly Language for Intel-Based Computers ( 3rd Edition ) by Kip R. Irvine SOLUTIONS MANUAL TO Auditing and Assurance Services- An Integrated Approach 12E by Arens SOLUTIONS MANUAL TO Auditing and Assurance Services, 12th edition, Alvin A Arens, Randal J Elder, Mark Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 13 ed by Arens, Elder, Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 2nd Ed by Louwers SOLUTIONS MANUAL TO Automatic Control Systems 9 Ed by Kuo, Golnaraghi SOLUTIONS MANUAL TO Automatic Control Systems, 8E, by Kuo, Golnaraghi SOLUTIONS MANUAL TO Basic Econometrics 4 ed by Damodar N. Gujarati SOLUTIONS MANUAL TO Basic Electrical Engineering By Nagrath, D P Kothari SOLUTIONS MANUAL TO Basic Electromagnetics with Applications by Nannapaneni Narayana Rao SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 7th Ed by David Irwin SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 8th Edition by J. David Irwin, R. Mark Nelms SOLUTIONS MANUAL TO Basic Heat and Mass Transfer by A. F. Mills SOLUTIONS MANUAL TO Basic Principles and Calculations in Chemical engineering 7th Edition by David M. Himmelblau, James B. Riggs SOLUTIONS MANUAL TO Basic Probability Theory by Robert B. Ash SOLUTIONS MANUAL TO Bayesian Core by Christian P. Robert and Jean-Michel Marin SOLUTIONS MANUAL TO Bioprocess Engineering Principles (Pauline M. Doran) SOLUTIONS MANUAL TO Business Statistics - Decision Making 7th E by David F. Groebner SOLUTIONS MANUAL TO C++ for Computer Science and Engineering by Vic Broquard From 2281570025 at qq.com Sun Jan 6 01:55:59 2013 From: 2281570025 at qq.com (=?utf-8?B?aU1hdGg=?=) Date: Sun, 6 Jan 2013 14:55:59 +0800 Subject: os.path.realpath(path) bug on win7 ? Message-ID: An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Jan 6 02:06:10 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 5 Jan 2013 23:06:10 -0800 Subject: os.path.realpath(path) bug on win7 ? In-Reply-To: References: Message-ID: On Sat, Jan 5, 2013 at 10:55 PM, iMath <2281570025 at qq.com> wrote: > > os.path.realpath(path) bug on win7 ? > > Temp.link is a Symbolic link > Its target location is C:\test\test1 > But > >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2') > 'C:\\Users\\SAMSUNG\\Temp.link\\test2' > > I thought the return value should be ' C:\\test\\test1\\test2' > > Is it a bug ? anyone can clear it to me ? What does os.path.islink('C:/Users/SAMSUNG/Temp.link') report? Cheers, Chris From redstone-cold at 163.com Sun Jan 6 03:11:47 2013 From: redstone-cold at 163.com (iMath) Date: Sun, 6 Jan 2013 00:11:47 -0800 (PST) Subject: os.path.realpath(path) bug on win7 ? In-Reply-To: References: Message-ID: <840d171b-342b-4a85-be0e-e7a7b490c8b6@googlegroups.com> ? 2013?1?6????UTC+8??3?06?10??Chris Rebert??? > On Sat, Jan 5, 2013 at 10:55 PM, iMath <2281570025 at qq.com> wrote: > > > > > > os.path.realpath(path) bug on win7 ? > > > > > > Temp.link is a Symbolic link > > > Its target location is C:\test\test1 > > > But > > > >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2') > > > 'C:\\Users\\SAMSUNG\\Temp.link\\test2' > > > > > > I thought the return value should be ' C:\\test\\test1\\test2' > > > > > > Is it a bug ? anyone can clear it to me ? > > > > What does os.path.islink('C:/Users/SAMSUNG/Temp.link') report? True > > > > Cheers, > > Chris From redstone-cold at 163.com Sun Jan 6 03:11:47 2013 From: redstone-cold at 163.com (iMath) Date: Sun, 6 Jan 2013 00:11:47 -0800 (PST) Subject: os.path.realpath(path) bug on win7 ? In-Reply-To: References: Message-ID: <840d171b-342b-4a85-be0e-e7a7b490c8b6@googlegroups.com> ? 2013?1?6????UTC+8??3?06?10??Chris Rebert??? > On Sat, Jan 5, 2013 at 10:55 PM, iMath <2281570025 at qq.com> wrote: > > > > > > os.path.realpath(path) bug on win7 ? > > > > > > Temp.link is a Symbolic link > > > Its target location is C:\test\test1 > > > But > > > >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2') > > > 'C:\\Users\\SAMSUNG\\Temp.link\\test2' > > > > > > I thought the return value should be ' C:\\test\\test1\\test2' > > > > > > Is it a bug ? anyone can clear it to me ? > > > > What does os.path.islink('C:/Users/SAMSUNG/Temp.link') report? True > > > > Cheers, > > Chris From victor.stinner at gmail.com Sun Jan 6 18:40:06 2013 From: victor.stinner at gmail.com (Victor Stinner) Date: Mon, 7 Jan 2013 00:40:06 +0100 Subject: os.path.realpath(path) bug on win7 ? In-Reply-To: References: Message-ID: It looks like the following issue: http://bugs.python.org/issue14094 Victor Le 6 janv. 2013 07:59, "iMath" <2281570025 at qq.com> a ?crit : > os.path.realpath(path) bug on win7 ? > > Temp.link is a Symbolic link > Its target location is C:\test\test1 > But > >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2') > 'C:\\Users\\SAMSUNG\\Temp.link\\test2' > > I thought the return value should be ' C:\\test\\test1\\test2' > > Is it a bug ? anyone can clear it to me ? > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From redstone-cold at 163.com Mon Jan 7 04:13:31 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 7 Jan 2013 01:13:31 -0800 (PST) Subject: os.path.realpath(path) bug on win7 ? In-Reply-To: References: Message-ID: ? 2013?1?7????UTC+8??7?40?06??Victor Stinner??? > It looks like the following issue: > > http://bugs.python.org/issue14094 > > Victor > > Le 6 janv. 2013 07:59, "iMath" <22815... at qq.com> a ?crit?: > > > > > os.path.realpath(path)??bug?on?win7?? > > Temp.link?is?a?Symbolic?link > Its?target?location?is?C:\test\test1 > But? > >>>?os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2') > 'C:\\Users\\SAMSUNG\\Temp.link\\test2' > > > I?thought?the?return?value?should?be?'?C:\\test\\test1\\test2' > > Is?it?a?bug???anyone?can?clear?it?to?me?? > > > -- > > http://mail.python.org/mailman/listinfo/python-list perhaps it is From redstone-cold at 163.com Mon Jan 7 04:13:31 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 7 Jan 2013 01:13:31 -0800 (PST) Subject: os.path.realpath(path) bug on win7 ? In-Reply-To: References: Message-ID: ? 2013?1?7????UTC+8??7?40?06??Victor Stinner??? > It looks like the following issue: > > http://bugs.python.org/issue14094 > > Victor > > Le 6 janv. 2013 07:59, "iMath" <22815... at qq.com> a ?crit?: > > > > > os.path.realpath(path)??bug?on?win7?? > > Temp.link?is?a?Symbolic?link > Its?target?location?is?C:\test\test1 > But? > >>>?os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2') > 'C:\\Users\\SAMSUNG\\Temp.link\\test2' > > > I?thought?the?return?value?should?be?'?C:\\test\\test1\\test2' > > Is?it?a?bug???anyone?can?clear?it?to?me?? > > > -- > > http://mail.python.org/mailman/listinfo/python-list perhaps it is From kurt at ugyldig.invalid Sun Jan 6 07:42:11 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 13:42:11 +0100 Subject: How to modify this script? Message-ID: <50e97123$0$294$14726298@news.sunsite.dk> http://www.tuxradar.com/content/save-time-gedit-snippets: To convert tab-separated text lines into a HTML-table: $< lines = $GEDIT_SELECTED_TEXT.split("\n"); output = '\n'; for line in lines: output += ''; columns = line.split("\t"); for item in columns: output += '' + item + ' ' output += '\n'; output += ''; return output > I would like to make a small modification (I'm not a programmer myself). Let's say I have these lines: Price table 1 Green apple $1 5 Green apples $4 10 Green apples $7 Since there's only one "field" in the first line, I want this output: Price table - insted of Price table How to? Thank you i advance. -- Venlig hilsen Kurt Hansen From rosuav at gmail.com Sun Jan 6 07:52:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Jan 2013 23:52:03 +1100 Subject: How to modify this script? In-Reply-To: <50e97123$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> Message-ID: On Sun, Jan 6, 2013 at 11:42 PM, Kurt Hansen wrote: > Since there's only one "field" in the first line, I want this output: > > Price table > > - insted of > > Price table > > How to? Thank you i advance. It's actually quite simple, as long as you don't mind the junk of colspan="1" on all the other cells. Just replace the innermost loop with: for item in columns: output += '' + item + ' ' Untested, but it ought to work - as long as you never have _more_ cells in the line. ChrisA From yacinechaouche at yahoo.com Sun Jan 6 07:58:15 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sun, 6 Jan 2013 04:58:15 -0800 (PST) Subject: How to modify this script? In-Reply-To: <50e97123$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> Message-ID: <1357477095.14190.YahooMailNeo@web125504.mail.ne1.yahoo.com> if len(columns) != 3: ?? colspan = 3 - len(columns) + 1 ?? output += '' % (colspan) + item + ' ' I did not test. Use with caution. ________________________________ From: Kurt Hansen To: python-list at python.org Sent: Sunday, January 6, 2013 1:42 PM Subject: How to modify this script? http://www.tuxradar.com/content/save-time-gedit-snippets: To convert tab-separated text lines into a HTML-table: $< lines = $GEDIT_SELECTED_TEXT.split("\n"); output = '\n'; for line in lines: ??? output += ''; ??? ??? columns = line.split("\t"); ??? for item in columns: ??? ??? output += '' + item + ' ' ??? ??? output += '\n'; output += ''; return output > I would like to make a small modification (I'm not a programmer myself). Let's say I have these lines: Price table 1 Green apple $1 5 Green apples $4 10 Green apples $7 Since there's only one "field" in the first line, I want this output: Price table - insted of Price table How to? Thank you i advance. -- Venlig hilsen Kurt Hansen -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt at ugyldig.invalid Sun Jan 6 08:34:58 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 14:34:58 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> Message-ID: <50e97d82$0$294$14726298@news.sunsite.dk> Den 06/01/13 13.52, Chris Angelico skrev: > On Sun, Jan 6, 2013 at 11:42 PM, Kurt Hansen wrote: >> Since there's only one "field" in the first line, I want this output: >> >> Price table >> >> - insted of >> >> Price table >> >> How to? Thank you i advance. > It's actually quite simple, as long as you don't mind the junk of > colspan="1" on all the other cells. I do, but I would like to test anyway ;-) Just replace the innermost loop > with: > > for item in columns: > output += '' + > item + ' ' "innermost"? I have replaced this with yours, but all the marked text are deleted: for item in columns: output += '' + item + ' ' > Untested, but it ought to work - as long as you never have _more_ > cells in the line. -- Regards Kurt Hansen From rosuav at gmail.com Sun Jan 6 08:44:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 00:44:13 +1100 Subject: How to modify this script? In-Reply-To: <50e97d82$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97d82$0$294$14726298@news.sunsite.dk> Message-ID: On Mon, Jan 7, 2013 at 12:34 AM, Kurt Hansen wrote: > "innermost"? I have replaced this with yours, but all the marked text are > deleted: Here's the full code, with my change: $< lines = $GEDIT_SELECTED_TEXT.split("\n"); output = '\n'; for line in lines: output += ''; columns = line.split("\t"); for item in columns: output += '' + item + ' ' output += '\n'; output += ''; return output > It's only one line of code that needs to be changed. Python loops (and other control structures) are defined by indentation, so the innermost loop is the one that starts furthest to the right. Chris Angelico From kurt at ugyldig.invalid Sun Jan 6 09:03:59 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 15:03:59 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97d82$0$294$14726298@news.sunsite.dk> Message-ID: <50e9844f$0$294$14726298@news.sunsite.dk> Den 06/01/13 14.44, Chris Angelico wrote: > On Mon, Jan 7, 2013 at 12:34 AM, Kurt Hansen wrote: >> "innermost"? I have replaced this with yours, but all the marked text are >> deleted: > > Here's the full code, with my change: > > $< > lines = $GEDIT_SELECTED_TEXT.split("\n"); > output = '\n'; I'm sorry to bother you, Chris, but applying the snippet with your code in Gedit still just deletes the marked, tab-separated text in the editor. -- Venlig hilsen Kurt Hansen From rosuav at gmail.com Sun Jan 6 09:20:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 01:20:25 +1100 Subject: How to modify this script? In-Reply-To: <50e9844f$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97d82$0$294$14726298@news.sunsite.dk> <50e9844f$0$294$14726298@news.sunsite.dk> Message-ID: On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen wrote: > I'm sorry to bother you, Chris, but applying the snippet with your code in > Gedit still just deletes the marked, tab-separated text in the editor. Ah, whoops. That would be because I had a bug in the code (that's why I commented that it was untested). Sorry about that! Here's a fixed version: $< lines = $GEDIT_SELECTED_TEXT.split("\n"); output = '\n'; for line in lines: output += ''; columns = line.split("\t"); for item in columns: output += '' + item + ' ' output += '\n'; output += ''; return output > Note that it's a single line: output += '' + item + ' ' If your newsreader (or my poster) wraps it, you'll need to unwrap that line, otherwise you'll get an IndentError. That version should work. ChrisA From kurt at ugyldig.invalid Sun Jan 6 09:30:15 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 15:30:15 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97d82$0$294$14726298@news.sunsite.dk> <50e9844f$0$294$14726298@news.sunsite.dk> Message-ID: <50e98a77$0$294$14726298@news.sunsite.dk> Den 06/01/13 15.20, Chris Angelico wrote: > On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen wrote: >> I'm sorry to bother you, Chris, but applying the snippet with your code in >> Gedit still just deletes the marked, tab-separated text in the editor. > Ah, whoops. That would be because I had a bug in the code (that's why > I commented that it was untested). Sorry about that! Here's a fixed > version: > [cut]> > Note that it's a single line: > > output += '' + item + ' ' > > If your newsreader (or my poster) wraps it, you'll need to unwrap that > line, otherwise you'll get an IndentError. Ahhh, I did'nt realize that. Now it works :-) > That version should work. It certainly does. I'll keep it and use it until at better solution is found. In the meantime I can just remove any unnecessary "colspan="1" with a macro. Thanks for your help. -- Venlig hilsen Kurt Hansen From rosuav at gmail.com Sun Jan 6 09:41:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 01:41:32 +1100 Subject: How to modify this script? In-Reply-To: <50e98a77$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97d82$0$294$14726298@news.sunsite.dk> <50e9844f$0$294$14726298@news.sunsite.dk> <50e98a77$0$294$14726298@news.sunsite.dk> Message-ID: On Mon, Jan 7, 2013 at 1:30 AM, Kurt Hansen wrote: > Den 06/01/13 15.20, Chris Angelico wrote: > >> On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen wrote: >>> >>> I'm sorry to bother you, Chris, but applying the snippet with your code >>> in >>> Gedit still just deletes the marked, tab-separated text in the editor. > > >> Ah, whoops. That would be because I had a bug in the code (that's why >> I commented that it was untested). Sorry about that! Here's a fixed >> version: >> > [cut]> > >> Note that it's a single line: >> >> output += '' + item + ' ' >> >> If your newsreader (or my poster) wraps it, you'll need to unwrap that >> line, otherwise you'll get an IndentError. > > > Ahhh, I did'nt realize that. Now it works :-) > >> That version should work. > > > It certainly does. I'll keep it and use it until at better solution is > found. In the meantime I can just remove any unnecessary "colspan="1" with a > macro. > > Thanks for your help. Excellent! You'll find that Subimal's solution doesn't have those colspan="1" lines, so take your pick as to which way you want to go. ChrisA From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jan 8 09:18:59 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 08 Jan 2013 15:18:59 +0100 Subject: How to modify this script? In-Reply-To: <50e98a77$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97d82$0$294$14726298@news.sunsite.dk> <50e9844f$0$294$14726298@news.sunsite.dk> <50e98a77$0$294$14726298@news.sunsite.dk> Message-ID: Am 06.01.2013 15:30 schrieb Kurt Hansen: > Den 06/01/13 15.20, Chris Angelico wrote: >> On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen wrote: >>> I'm sorry to bother you, Chris, but applying the snippet with your >>> code in >>> Gedit still just deletes the marked, tab-separated text in the editor. > >> Ah, whoops. That would be because I had a bug in the code (that's why >> I commented that it was untested). Sorry about that! Here's a fixed >> version: >> > [cut]> >> Note that it's a single line: >> >> output += '' + item + >> ' ' >> >> If your newsreader (or my poster) wraps it, you'll need to unwrap that >> line, otherwise you'll get an IndentError. > > Ahhh, I did'nt realize that. Now it works :-) > >> That version should work. > > It certainly does. I'll keep it and use it until at better solution is > found. That would be simple: Replace output += '' + item + ' ' with if len(columns) >= 3: output += '' else: output += '' output += item + ' ' (untested as well; keep the indentation in mind!) Thomas From kurt at ugyldig.invalid Wed Jan 9 04:21:08 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Wed, 09 Jan 2013 10:21:08 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97d82$0$294$14726298@news.sunsite.dk> <50e9844f$0$294$14726298@news.sunsite.dk> <50e98a77$0$294$14726298@news.sunsite.dk> Message-ID: <50ed3684$0$284$14726298@news.sunsite.dk> >> Den 06/01/13 15.20, Chris Angelico wrote: > >>> That version should work. > Am 06.01.2013 15:30 schrieb Kurt Hansen: > >> It certainly does. I'll keep it and use it until at better solution is >> found. On 08/01/13 15.18, Thomas Rachel wrote: > > That would be simple: > > Replace > > output += '' + item + > ' ' > > with > > if len(columns) >= 3: > output += '' > else: > output += '' > output += item + ' ' > > (untested as well; keep the indentation in mind!) Thanks, Thomas, but ... The script stops right bofore = 3: output += '' This, and the rest of the script code is put out as the result, not my test. -- Venlig hilsen Kurt Hansen From kurt at ugyldig.invalid Sun Jan 6 08:38:20 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 14:38:20 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> Message-ID: <50e97e4c$0$294$14726298@news.sunsite.dk> Den 06/01/13 13.58, chaouche yacine skrev: > if len(columns) != 3: > colspan = 3 - len(columns) + 1 > output += '' % (colspan) + item + ' ' > > I did not test. Use with caution. I've tried to put it in several different places in the script, but with no luck; remember that I'm not experienced, so please tell me exactly where it's surposed to be inserted. Could you eventually show the complete modified script? > > ------------------------------------------------------------------------ > *From:* Kurt Hansen > *To:* python-list at python.org > *Sent:* Sunday, January 6, 2013 1:42 PM > *Subject:* How to modify this script? > > http://www.tuxradar.com/content/save-time-gedit-snippets: > > To convert tab-separated text lines into a HTML-table: > > $< > lines = $GEDIT_SELECTED_TEXT.split("\n"); > output = '\n'; > > for line in lines: > output += ''; > > columns = line.split("\t"); > for item in columns: > output += '' + item + ' ' > > output += '\n'; > > output += ''; > return output > > > > I would like to make a small modification (I'm not a programmer myself). > Let's say I have these lines: > > Price table > 1 Green apple $1 > 5 Green apples $4 > 10 Green apples $7 > > Since there's only one "field" in the first line, I want this output: > > Price table > > - insted of > > Price table > > How to? Thank you i advance. > -- Venlig hilsen > Kurt Hansen > -- http://mail.python.org/mailman/listinfo/python-list > > -- Venlig hilsen Kurt Hansen From yacinechaouche at yahoo.com Sun Jan 6 09:01:47 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sun, 6 Jan 2013 06:01:47 -0800 (PST) Subject: How to modify this script? In-Reply-To: <50e97e4c$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> Message-ID: <1357480907.76364.YahooMailNeo@web125504.mail.ne1.yahoo.com> Well, I'm not answering your question since I am rewriting the script, because I prefer it this way :) def addline(line): ??? return "%s\n" % line def addcolumn(item,nb_columns): ??? if nb_columns != 3: ??????? return "%s" % (3 - nb_columns + 1, item) ??? return "%s" % item output = "\n" for line in file("data.txt"): ??? items = line.strip().split("\t") ??? columns = "" ??? for item in items : ??????? columns += addcolumn(item,len(items)) ??? output? += addline(columns) output += "
" print output printed >>>
Price table
1 Green apple $1
5 Green apples $4
10 Green apples $7
>>> ________________________________ From: Kurt Hansen To: python-list at python.org Sent: Sunday, January 6, 2013 2:38 PM Subject: Re: How to modify this script? Den 06/01/13 13.58, chaouche yacine skrev: > if len(columns) != 3: >? ???colspan = 3 - len(columns) + 1 >? ???output += '' % (colspan) + item + ' ' > > I did not test. Use with caution. I've tried to put it in several different places in the script, but with no luck; remember that I'm not experienced, so please tell me exactly where it's surposed to be inserted. Could you eventually show the complete modified script? > > ------------------------------------------------------------------------ > *From:* Kurt Hansen > *To:* python-list at python.org > *Sent:* Sunday, January 6, 2013 1:42 PM > *Subject:* How to modify this script? > > http://www.tuxradar.com/content/save-time-gedit-snippets: > > To convert tab-separated text lines into a HTML-table: > > $< > lines = $GEDIT_SELECTED_TEXT.split("\n"); > output = '\n'; > > for line in lines: >? ? ? output += ''; > >? ? ? columns = line.split("\t"); >? ? ? for item in columns: >? ? ? ? ? output += '' + item + ' ' > >? ? ? output += '\n'; > > output += ''; > return output >? > > > I would like to make a small modification (I'm not a programmer myself). > Let's say I have these lines: > > Price table > 1 Green apple $1 > 5 Green apples $4 > 10 Green apples $7 > > Since there's only one "field" in the first line, I want this output: > > Price table > > - insted of > > Price table > > How to? Thank you i advance. > -- Venlig hilsen > Kurt Hansen > -- http://mail.python.org/mailman/listinfo/python-list > > -- Venlig hilsen Kurt Hansen -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt at ugyldig.invalid Sun Jan 6 09:21:18 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 15:21:18 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> Message-ID: <50e9885e$0$294$14726298@news.sunsite.dk> Den 06/01/13 15.01, chaouche yacine wrote: > Well, I'm not answering your question since I am rewriting the script, > because I prefer it this way :) > > def addline(line): > return "%s\n" % line [cut] I surpose I shall put your code between $< and >? > printed > > >>> > > > > >
Price table
1 Green apple $1
5 Green apples $4
10 Green apples $7
> >>> Aha, so you tested it yourself? When running this in Gedit on four lines of tab-separated text the output is: %s\n" % line def addcolumn(item,nb_columns): if nb_columns != 3: return "%s" % (3 - nb_columns + 1, item) return "%s" % item output = "\n" for line in file("data.txt"): items = line.strip().split("\t") columns = "" for item in items : columns += addcolumn(item,len(items)) output += addline(columns) output += "
" print output > -- Venlig hilsen Kurt Hansen From yacinechaouche at yahoo.com Sun Jan 6 10:12:43 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sun, 6 Jan 2013 07:12:43 -0800 (PST) Subject: How to modify this script? In-Reply-To: <50e9885e$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> Message-ID: <1357485163.11230.YahooMailNeo@web125506.mail.ne1.yahoo.com> I'm not confident this would run on gedit. It works on a python interpreter if you have a file named data.txt in the same directory containing your sample data. It surely has to do with how gedit works then, because the "$" sign isn't used in python, this business should be a gedit convention. And sorry, I can't help on that, I'm not a user of gedit myself. Fortunately others have answered and I beleive one of the solutions worked for you. ________________________________ From: Kurt Hansen To: python-list at python.org Sent: Sunday, January 6, 2013 3:21 PM Subject: Re: How to modify this script? Den 06/01/13 15.01, chaouche yacine wrote: > Well, I'm not answering your question since I am rewriting the script, > because I prefer it this way :) > > def addline(line): >? ? ? return "%s\n" % line [cut] I surpose I shall put your code between $< and >? > printed > >? >>> > > > > >
Price table
1 Green apple $1
5 Green apples $4
10 Green apples $7
>? >>> Aha, so you tested it yourself? When running this in Gedit on four lines of tab-separated text the output is: %s\n" % line def addcolumn(item,nb_columns): ? ? if nb_columns != 3: ? ? ? ? return "%s" % (3 - nb_columns + 1, item) ? ? return "%s" % item output = "\n" for line in file("data.txt"): ? ? items = line.strip().split("\t") ? ? columns = "" ? ? for item in items : ? ? ? ? columns += addcolumn(item,len(items)) ? ? output? += addline(columns) output += "
" print output > -- Venlig hilsen Kurt Hansen -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt at ugyldig.invalid Mon Jan 7 11:42:40 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Mon, 07 Jan 2013 17:42:40 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> Message-ID: <50eafb00$0$287$14726298@news.sunsite.dk> Den 06/01/13 16.12, chaouche yacine skrev: > I'm not confident this would run on gedit. It works on a python > interpreter if you have a file named data.txt in the same directory > containing your sample data. > > It surely has to do with how gedit works then, because the "$" sign > isn't used in python, this business should be a gedit convention. And > sorry, I can't help on that, I'm not a user of gedit myself. Fortunately > others have answered and I beleive one of the solutions worked for you. It does not seem to be the case :-( Thank you for trying to help. > ------------------------------------------------------------------------ > *From:* Kurt Hansen > *To:* python-list at python.org > *Sent:* Sunday, January 6, 2013 3:21 PM > *Subject:* Re: How to modify this script? > > Den 06/01/13 15.01, chaouche yacine wrote: > > Well, I'm not answering your question since I am rewriting the script, > > because I prefer it this way :) > > > > def addline(line): > > return "%s\n" % line > [cut] > > I surpose I shall put your code between $< and >? > > > printed > > > > >>> > > > > > > > > > >
Price table
1 Green apple $1
5 Green apples $4
10 Green apples $7
> > >>> > > Aha, so you tested it yourself? > > When running this in Gedit on four lines of tab-separated text the > output is: > > %s\n" % line > > def addcolumn(item,nb_columns): > if nb_columns != 3: > return "%s" % (3 - nb_columns + 1, item) > return "%s" % item > > output = "\n" > for line in file("data.txt"): > items = line.strip().split("\t") > columns = "" > for item in items : > columns += addcolumn(item,len(items)) > output += addline(columns) > > > output += "
" > print output > > > -- Venlig hilsen > Kurt Hansen > -- http://mail.python.org/mailman/listinfo/python-list > > -- Venlig hilsen Kurt Hansen From yacinechaouche at yahoo.com Tue Jan 8 10:31:41 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Tue, 8 Jan 2013 07:31:41 -0800 (PST) Subject: How to modify this script? In-Reply-To: <50eafb00$0$287$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> <50eafb00$0$287$14726298@news.sunsite.dk> Message-ID: <1357659101.20095.YahooMailNeo@web125502.mail.ne1.yahoo.com> Well tell me how do you use this script in gedit, are you using it as a plugin ? are you putting this code somewhere ? I'll try to do the same on my side and try to understand how it works. ________________________________ From: Kurt Hansen To: python-list at python.org Sent: Monday, January 7, 2013 5:42 PM Subject: Re: How to modify this script? Den 06/01/13 16.12, chaouche yacine skrev: > I'm not confident this would run on gedit. It works on a python > interpreter if you have a file named data.txt in the same directory > containing your sample data. > > It surely has to do with how gedit works then, because the "$" sign > isn't used in python, this business should be a gedit convention. And > sorry, I can't help on that, I'm not a user of gedit myself. Fortunately > others have answered and I beleive one of the solutions worked for you. It does not seem to be the case :-( Thank you for trying to help. > ------------------------------------------------------------------------ > *From:* Kurt Hansen > *To:* python-list at python.org > *Sent:* Sunday, January 6, 2013 3:21 PM > *Subject:* Re: How to modify this script? > > Den 06/01/13 15.01, chaouche yacine wrote: >? > Well, I'm not answering your question since I am rewriting the script, >? > because I prefer it this way :) >? > >? > def addline(line): >? >? ? ? return "%s\n" % line > [cut] > > I surpose I shall put your code between $< and >? > >? > printed >? > >? >? >>> >? > >? > >? > >? > >? >
Price table
1 Green apple $1
5 Green apples $4
10 Green apples $7
>? >? >>> > > Aha, so you tested it yourself? > > When running this in Gedit on four lines of tab-separated text the > output is: > > %s\n" % line > > def addcolumn(item,nb_columns): >? ? ? if nb_columns != 3: >? ? ? ? ? return "%s" % (3 - nb_columns + 1, item) >? ? ? return "%s" % item > > output = "\n" > for line in file("data.txt"): >? ? ? items = line.strip().split("\t") >? ? ? columns = "" >? ? ? for item in items : >? ? ? ? ? columns += addcolumn(item,len(items)) >? ? ? output? += addline(columns) > > > output += "
" > print output >? > > -- Venlig hilsen > Kurt Hansen > -- http://mail.python.org/mailman/listinfo/python-list > > -- Venlig hilsen Kurt Hansen -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt at ugyldig.invalid Wed Jan 9 04:07:59 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Wed, 09 Jan 2013 10:07:59 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> <50eafb00$0$287$14726298@news.sunsite.dk> Message-ID: <50ed336f$0$284$14726298@news.sunsite.dk> Den 08/01/13 16.31, chaouche yacine skrev: > Well tell me how do you use this script in gedit, are you using it as a > plugin ? "Snippets" is a plugin, yes. It's included in the .app for Mac (v. 2.30.2), but not activated af default. Open "Tools" in the menu line and click "Manage snippets...". Here you can organize, add and edit snippets of texts. The feature ols? has the ability to work with Python code inside the snippet content. I am re-building a 15 years old homepage. The HTML code is handmade over the years and very varying, buggy etc., s? I would like to renew the HTML for the table structure in an easy way. Example: On this page: http://www.danacord.dk/frmsets/records/732-r.html I mark the content of the CD, copy it to the clipboard and paste it into the editing area in Gedit. cmd-a marks it all again and then I "run" the snippet upon the text, either using my self-defined hotkey or by pushing ctrl+space and select my snippet from a list. The copied text is inserted as clean text without any HTML. The Python-snippet we are discussing recognizes tabs to separate the columns and adds the apprpriate HTML-code to it. -- Regards Kurt Hansen From yacinechaouche at yahoo.com Wed Jan 9 05:23:08 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Wed, 9 Jan 2013 02:23:08 -0800 (PST) Subject: How to modify this script? In-Reply-To: <50ed336f$0$284$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> <50eafb00$0$287$14726298@news.sunsite.dk> <50ed336f$0$284$14726298@news.sunsite.dk> Message-ID: <1357726988.24875.YahooMailNeo@web125501.mail.ne1.yahoo.com> I figrued it out. Copy/paste exactly these lines in the snippets tool. You can bind it to a key as you may know, I bound it to Ctrl-E. So paste it in a new snippet (keep the original in a safe place), bind to a key, select the text you want to html-tableize and hit the key binding. In my case it worked. $< def addline(line): ??? return "%s\n" % line def addcolumn(item,nb_columns): ??? if nb_columns != 3: ??????? return "%s
" % (3 - nb_columns + 1, item) ??? return "%s" % item output = "\n" for line in """$GEDIT_SELECTED_TEXT""".split("\n"): ??? items = line.strip().split("\t") ??? columns = "" ??? for item in items : ??????? columns += addcolumn(item,len(items)) ??? output? += addline(columns) output += "" return output> Here's a screenshit, sorry screenshot :) http://h.dropcanvas.com/521xc/gedit.png The python support in gedit snippets is very poor when it comes to debugging because there are traceback printed in the console, that means gedit actually breaks without even noticing the user about what went wrong (ex. : your snippet is malformed or has errors). I had to debug it using pdb.set_trace directly inside its source code to figure out what was wrong in the snippet. If this doesn't work for you, please let me know. ________________________________ From: Kurt Hansen To: python-list at python.org Sent: Wednesday, January 9, 2013 10:07 AM Subject: Re: How to modify this script? Den 08/01/13 16.31, chaouche yacine skrev: > Well tell me how do you use this script in gedit, are you using it as a > plugin ? "Snippets" is a plugin, yes. It's included in the .app for Mac (v. 2.30.2), but not activated af default. Open "Tools" in the menu line and click "Manage snippets...". Here you can organize, add and edit snippets of texts. The feature ols? has the ability to work with Python code inside the snippet content. I am re-building a 15 years old homepage. The HTML code is handmade over the years and very varying, buggy etc., s? I would like to renew the HTML for the table structure in an easy way. Example: On this page: http://www.danacord.dk/frmsets/records/732-r.html I mark the content of the CD, copy it to the clipboard and paste it into the editing area in Gedit. cmd-a marks it all again and then I "run" the snippet upon the text, either using my self-defined hotkey or by pushing ctrl+space and select my snippet from a list. The copied text is inserted as clean text without any HTML. The Python-snippet we are discussing recognizes tabs to separate the columns and adds the apprpriate HTML-code to it. -- Regards Kurt Hansen -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt at ugyldig.invalid Wed Jan 9 06:04:15 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Wed, 09 Jan 2013 12:04:15 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> <50eafb00$0$287$14726298@news.sunsite.dk> <50ed336f$0$284$14726298@news.sunsite.dk> Message-ID: <50ed4eaf$0$284$14726298@news.sunsite.dk> Den 09/01/13 11.23, chaouche yacine skrev: > I figrued it out. Copy/paste exactly these lines in the snippets tool. > You can bind it to a key as you may know, I bound it to Ctrl-E. So paste > it in a new snippet (keep the original in a safe place), bind to a key, > select the text you want to html-tableize and hit the key binding. In my > case it worked. > > $< [cut] > def addline(line): Spooky behavior. Yes, the green-apple-example also works for me with your new script, BUT ...! Try to copy the table content on this page: http://www.danacord.dk/frmsets/records/732-r.html which is a realistic scenario. That's whar I am doing these days. Pasting it into Gedit and running the snippet blanks the edit area (on MY Mac at least). And yes: I have pasted your code excatly and I've double-checked for linewraps. Everything is okay. For your cenvenience I have put borders on the table online (see link above). You may ommit the rows after track 14. Not that it makes any differerence, but that block is surposed to be formatted differerent. I do that manually afterwards ... if not ... ;-) -- Regards Kurt Hansen From yacinechaouche at yahoo.com Wed Jan 9 13:25:45 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Wed, 9 Jan 2013 10:25:45 -0800 (PST) Subject: How to modify this script? In-Reply-To: <50ed4eaf$0$284$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> <50eafb00$0$287$14726298@news.sunsite.dk> <50ed336f$0$284$14726298@news.sunsite.dk> <50ed4eaf$0$284$14726298@news.sunsite.dk> Message-ID: <1357755945.50400.YahooMailNeo@web125504.mail.ne1.yahoo.com> Indeed, the console shows a traceback where data is misinterpreted, maybe due to my triple protective quotes around $GEDIT_SELECTED_TEXT. Try without them, like so (it worked for me) : $< def addline(line): ??? return "%s\n" % line def addcolumn(item,nb_columns): ??? if nb_columns != 3: ??????? return "%s" % (3 - nb_columns + 1, item) ??? return "%s" % item output = "\n" selected_text = $GEDIT_SELECTED_TEXT for line in selected_text.split("\n"): ??? items = line.strip().split("\t") ??? columns = "" ??? for item in items : ??????? columns += addcolumn(item,len(items)) ??? output? += addline(columns) output += "" return output> ________________________________ From: Kurt Hansen To: python-list at python.org Sent: Wednesday, January 9, 2013 12:04 PM Subject: Re: How to modify this script? Den 09/01/13 11.23, chaouche yacine skrev: > I figrued it out. Copy/paste exactly these lines in the snippets tool. > You can bind it to a key as you may know, I bound it to Ctrl-E. So paste > it in a new snippet (keep the original in a safe place), bind to a key, > select the text you want to html-tableize and hit the key binding. In my > case it worked. > > $< [cut] > def addline(line): Spooky behavior. Yes, the green-apple-example also works for me with your new script, BUT ...! Try to copy the table content on this page: http://www.danacord.dk/frmsets/records/732-r.html which is a realistic scenario. That's whar I am doing these days. Pasting it into Gedit and running the snippet blanks the edit area (on MY Mac at least). And yes: I have pasted your code excatly and I've double-checked for linewraps. Everything is okay. For your cenvenience I have put borders on the table online (see link above). You may ommit the rows after track 14. Not that it makes any differerence, but that block is surposed to be formatted differerent. I do that manually afterwards ... if not ... ;-) -- Regards Kurt Hansen -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt at ugyldig.invalid Thu Jan 10 23:35:49 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Fri, 11 Jan 2013 05:35:49 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> <50e9885e$0$294$14726298@news.sunsite.dk> <50eafb00$0$287$14726298@news.sunsite.dk> <50ed336f$0$284$14726298@news.sunsite.dk> <50ed4eaf$0$284$14726298@news.sunsite.dk> Message-ID: <50ef96a5$0$285$14726298@news.sunsite.dk> Kurt wrote: > > Spooky behavior. Yes, the green-apple-example also works for me with > your new script, BUT ...! > > Try to copy the table content on this page: > http://www.danacord.dk/frmsets/records/732-r.html > which is a realistic scenario. That's whar I am doing these days. > > Pasting it into Gedit and running the snippet blanks the edit area (on > MY Mac at least). > > And yes: I have pasted your code excatly and I've double-checked for > linewraps. Everything is okay. Chaouche replied: > > Indeed, the console shows a traceback where data is misinterpreted, > maybe due to my triple protective quotes around $GEDIT_SELECTED_TEXT. > Try without them, like so (it worked for me) : Yes!!! :-) Of course it would be nice if the script could be developed to take into account some of the antics I have made in my tables over the years, but with this script the basic codes of rows and columns is formatted properly; refinements of some collapsed fields with with line breaks a.o. is up to me now ;-). Thanks to you and others who have participated in this thread. -- Venlig hilsen Kurt Hansen From subimal.deb at gmail.com Sun Jan 6 09:22:29 2013 From: subimal.deb at gmail.com (Subimal Deb) Date: Sun, 6 Jan 2013 06:22:29 -0800 (PST) Subject: How to modify this script? In-Reply-To: <50e97123$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> Message-ID: <3b31ab41-f531-4c81-acf1-219d3c605935@googlegroups.com> Kurt, Try this: $< lines = $GEDIT_SELECTED_TEXT.split("\n"); output = '\n'; for line in lines: output += ''; columns = line.split("\t"); if len(columns)==1: output += '', line, '' else: for item in columns: output += '' + item + ' ' output += '\n'; output += ''; return output > ---------------- All I have done is to If there is one item in the tab-separated line : print the line as a row spanning 3 columns else: print the items in the line as an item in each column ---------------- I have not tried this snippet in Gedit - so use with caution. ---------------- good luck, Subimal Deb On Sunday, January 6, 2013 6:12:11 PM UTC+5:30, Kurt Hansen wrote: > http://www.tuxradar.com/content/save-time-gedit-snippets: > > > > To convert tab-separated text lines into a HTML-table: > > > > $< > > lines = $GEDIT_SELECTED_TEXT.split("\n"); > > output = '\n'; > > > > for line in lines: > > output += ''; > > > > columns = line.split("\t"); > > for item in columns: > > output += '' + item + ' ' > > > > output += '\n'; > > > > output += ''; > > return output > > > > > > > I would like to make a small modification (I'm not a programmer myself). > > Let's say I have these lines: > > > > Price table > > 1 Green apple $1 > > 5 Green apples $4 > > 10 Green apples $7 > > > > Since there's only one "field" in the first line, I want this output: > > > > Price table > > > > - insted of > > > > Price table > > > > How to? Thank you i advance. > > -- > > Venlig hilsen > > Kurt Hansen From kurt at ugyldig.invalid Sun Jan 6 09:40:34 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 15:40:34 +0100 Subject: How to modify this script? In-Reply-To: <3b31ab41-f531-4c81-acf1-219d3c605935@googlegroups.com> References: <50e97123$0$294$14726298@news.sunsite.dk> <3b31ab41-f531-4c81-acf1-219d3c605935@googlegroups.com> Message-ID: <50e98ce2$0$294$14726298@news.sunsite.dk> Den 06/01/13 15.22, Subimal Deb wrote: > Kurt, > Try this: > [cut] I've tested it on my original example: Price table 1 Green apple $1 5 Green apples $4 10 Green apples $7 With all four lines selected it makes an error. With only three (without the first line) it works all right. The error message says: Execution of the Python command (lines = 'Price table\n1\tGreen apple\t$1\n5\tGreen apples\t$4\n10\tGreen apples\t$7'.split("\n"); output = '\n'; for line in lines: output += ''; columns = line.split("\t"); if len(columns)==1: output += '' else: for item in columns: output += ' ' output += '\n'; output += '
', line, '
' + item + '
'; return output) failed: cannot concatenate 'str' and 'tuple' objects -- Venlig hilsen Kurt Hansen From rosuav at gmail.com Sun Jan 6 09:52:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 01:52:14 +1100 Subject: How to modify this script? In-Reply-To: <50e98ce2$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> <3b31ab41-f531-4c81-acf1-219d3c605935@googlegroups.com> <50e98ce2$0$294$14726298@news.sunsite.dk> Message-ID: On Mon, Jan 7, 2013 at 1:40 AM, Kurt Hansen wrote: > failed: cannot concatenate 'str' and 'tuple' objects The problem is this line: output += '', line, '' Change it to: output += '' + line + '' ChrisA From kurt at ugyldig.invalid Sun Jan 6 10:05:41 2013 From: kurt at ugyldig.invalid (Kurt Hansen) Date: Sun, 06 Jan 2013 16:05:41 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <3b31ab41-f531-4c81-acf1-219d3c605935@googlegroups.com> <50e98ce2$0$294$14726298@news.sunsite.dk> Message-ID: <50e992c5$0$294$14726298@news.sunsite.dk> Den 06/01/13 15.52, Chris Angelico skrev: > On Mon, Jan 7, 2013 at 1:40 AM, Kurt Hansen wrote: >> failed: cannot concatenate 'str' and 'tuple' objects > > The problem is this line: > > output += '', line, '' > > Change it to: > > output += '' + line + '' :-) Something happened allright, but ... Output with this change: ' + line + '' else: for item in columns: output += '' + item + ' ' output += '\n'; output += '
'; return output > -- Venlig hilsen Kurt Hansen From gklein at xs4all.nl Mon Jan 7 12:56:14 2013 From: gklein at xs4all.nl (Gertjan Klein) Date: Mon, 07 Jan 2013 18:56:14 +0100 Subject: How to modify this script? In-Reply-To: <50e97123$0$294$14726298@news.sunsite.dk> References: <50e97123$0$294$14726298@news.sunsite.dk> Message-ID: <50eb0c3e$0$6939$e4fe514c@news2.news.xs4all.nl> Kurt Hansen wrote: > To convert tab-separated text lines into a HTML-table: As you apparently didn't receive answers that worked for you I tried to get what you want to work and test it in Gedit. Here's the result: $< lines = $GEDIT_SELECTED_TEXT.split("\n"); output = '\n'; max_columns = 0 for line in lines: col_count = len(line.split("\t")) if col_count \> max_columns: max_columns = col_count for line in lines: if line == '': continue output += ''; columns = line.split("\t"); if len(columns) == 1: output += ('' % max_columns) + line + '\n' continue for item in columns: output += '' + item + '' output += '\n'; output += ''; return output > (Watch out for line wraps! I don't know how to stop Thunderbird from inserting them.) It really isn't all that difficult. The code determines the (maximum) number of columns present. It then processes each line; if one is found with exactly one column (i.e., no tabs), it applies a colspan equal to the maximum number of columns. This works for your test and similar data. As I said, this is copy/pasted from a working Gedit snippet. If it works for you, I'd try experimenting a bit -- what should happen when the number of columns is larger than 1 but less than the maximum? Programming isn't magic. You might start enjoying it. HTH, Gertjan. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jan 8 09:22:19 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 08 Jan 2013 15:22:19 +0100 Subject: How to modify this script? In-Reply-To: <50eb0c3e$0$6939$e4fe514c@news2.news.xs4all.nl> References: <50e97123$0$294$14726298@news.sunsite.dk> <50eb0c3e$0$6939$e4fe514c@news2.news.xs4all.nl> Message-ID: Am 07.01.2013 18:56 schrieb Gertjan Klein: > (Watch out for line wraps! I don't know how to stop Thunderbird from > inserting them.) Do "insert as quotation" (in German Thunderbird: "Als Zitat einf?gen"), or Strg-Shift-O. Then it gets inserted with a ">" before and in blue. Just remove the > and the space after it; the "non-breaking property" is kept. Example: columns = line.split("\t"); if len(columns) == 1: output += ('' % max_columns) + line + '\n' continue without and columns = line.split("\t"); if len(columns) == 1: output += ('' % max_columns) + line + '\n' continue with this feature. HTH, Thomas From gklein at xs4all.nl Tue Jan 8 11:22:38 2013 From: gklein at xs4all.nl (Gertjan Klein) Date: Tue, 08 Jan 2013 17:22:38 +0100 Subject: How to modify this script? In-Reply-To: References: <50e97123$0$294$14726298@news.sunsite.dk> <50eb0c3e$0$6939$e4fe514c@news2.news.xs4all.nl> Message-ID: <50ec47d5$0$6942$e4fe514c@news2.news.xs4all.nl> Thomas Rachel wrote: > Am 07.01.2013 18:56 schrieb Gertjan Klein: > >> (Watch out for line wraps! I don't know how to stop Thunderbird from >> inserting them.) > > Do "insert as quotation" (in German Thunderbird: "Als Zitat einf?gen"), > or Strg-Shift-O. Then it gets inserted with a ">" before and in blue. > > Just remove the > and the space after it; the "non-breaking property" is > kept. Ah, I didn't think of that, thanks. Laborious but manageable. But: > Example: Both your examples are wrapped, in the same way. (I checked the message source, it's not some setting on my end.) It appears that, although Thunderbirds editor remembers the "don't wrap" setting, wrapping still occurs before sending. (The wrapping-before-sending code uses a slightly different algorithm than the editor too, so messages often look different after sending. Thunderbirds editor is really bad.) A last attempt: two (equal) quotes, the second one with the leading "> " removed: > output += ('' % max_columns) + line + '\n' output += ('' % max_columns) + line + '\n' I'm curious how this will come out. Regards, Gertjan. From yacinechaouche at yahoo.com Sun Jan 6 08:01:58 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sun, 6 Jan 2013 05:01:58 -0800 (PST) Subject: Proof that nobody reads the tests Message-ID: <1357477318.76412.YahooMailNeo@web125502.mail.ne1.yahoo.com> Has anybody read the source code of /usr/lib/python2.7/test/inspect_fodder.py ? I wonder how did they let this into the official python distribution. I thought Guido was serious :) people of the PSF seem to have a certain sense of humour. Yassine. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Jan 6 08:14:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 00:14:11 +1100 Subject: Proof that nobody reads the tests In-Reply-To: <1357477318.76412.YahooMailNeo@web125502.mail.ne1.yahoo.com> References: <1357477318.76412.YahooMailNeo@web125502.mail.ne1.yahoo.com> Message-ID: On Mon, Jan 7, 2013 at 12:01 AM, chaouche yacine wrote: > Has anybody read the source code of > /usr/lib/python2.7/test/inspect_fodder.py ? > > I wonder how did they let this into the official python distribution. I > thought Guido was serious :) people of the PSF seem to have a certain sense > of humour. I don't understand your comments. It's full of Monty Python references; that's true of large slabs of Python code and documentation. ChrisA From yacinechaouche at yahoo.com Sun Jan 6 08:26:19 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sun, 6 Jan 2013 05:26:19 -0800 (PST) Subject: Proof that nobody reads the tests In-Reply-To: References: <1357477318.76412.YahooMailNeo@web125502.mail.ne1.yahoo.com> Message-ID: <1357478779.91395.YahooMailNeo@web125502.mail.ne1.yahoo.com> Oh :) sorry I didn't know they were references to monty python sketches. That explains it then :) ________________________________ From: Chris Angelico To: python-list at python.org Sent: Sunday, January 6, 2013 2:14 PM Subject: Re: Proof that nobody reads the tests On Mon, Jan 7, 2013 at 12:01 AM, chaouche yacine wrote: > Has anybody read the source code of > /usr/lib/python2.7/test/inspect_fodder.py ? > > I wonder how did they let this into the official python distribution. I > thought Guido was serious :) people of the PSF seem to have a certain sense > of humour. I don't understand your comments. It's full of Monty Python references; that's true of large slabs of Python code and documentation. ChrisA -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Jan 6 08:31:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 00:31:36 +1100 Subject: Proof that nobody reads the tests In-Reply-To: <1357478779.91395.YahooMailNeo@web125502.mail.ne1.yahoo.com> References: <1357477318.76412.YahooMailNeo@web125502.mail.ne1.yahoo.com> <1357478779.91395.YahooMailNeo@web125502.mail.ne1.yahoo.com> Message-ID: On Mon, Jan 7, 2013 at 12:26 AM, chaouche yacine wrote: > Oh :) sorry I didn't know they were references to monty python sketches. > That explains it then :) Check out the Argument Clinic some time :) ChrisA From darcy at druid.net Sun Jan 6 09:21:11 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 6 Jan 2013 09:21:11 -0500 Subject: Proof that nobody reads the tests In-Reply-To: <1357478779.91395.YahooMailNeo@web125502.mail.ne1.yahoo.com> References: <1357477318.76412.YahooMailNeo@web125502.mail.ne1.yahoo.com> <1357478779.91395.YahooMailNeo@web125502.mail.ne1.yahoo.com> Message-ID: <20130106092111.22152fb9@dilbert> On Sun, 6 Jan 2013 05:26:19 -0800 (PST) chaouche yacine wrote: > Oh :) sorry I didn't know they were references to monty python > sketches. That explains it then :) The name of the language itself is a reference to Monty Python. That is specifically what it was named after. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From missive at hotmail.com Sun Jan 6 08:42:37 2013 From: missive at hotmail.com (Lee Harr) Date: Sun, 6 Jan 2013 18:12:37 +0430 Subject: Ubuntu Python -dbg packages Message-ID: I am using: Ubuntu 12.10 Python 3.2.3 Qt 4.8.2 PyQt 4.9.3 I also have the ubuntu -dbg packages: python3-dbg python3-pyqt4-dbg I don't understand why python3-dbg cannot import the PyQt4 modules... $ python3 Python 3.2.3 (default, Oct 19 2012, 19:53:57) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.executable '/usr/bin/python3' >>> import PyQt4 >>> import PyQt4.QtCore >>> $ python3-dbg Python 3.2.3 (default, Oct 19 2012, 19:58:54) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys [60298 refs] >>> sys.executable '/usr/bin/python3-dbg' [60300 refs] >>> import PyQt4 [60323 refs] >>> PyQt4.__file__ '/usr/lib/python3/dist-packages/PyQt4/__init__.py' [60323 refs] >>> import PyQt4.QtCore Traceback (most recent call last): ? File "", line 1, in ImportError: No module named QtCore [150996 refs] >>> Also... The python3-pyqt4-dbg package seems to install to a different location, so I tried inserting that dir on to sys.path with unexpected results. $ python3-dbg Python 3.2.3 (default, Oct 19 2012, 19:58:54) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys [60298 refs] >>> sys.path.insert(1, '/usr/lib/debug/usr/lib/python3/dist-packages/') [60299 refs] >>> import PyQt4 [60335 refs] >>> PyQt4.__file__ '/usr/lib/python3/dist-packages/PyQt4/__init__.py' [60337 refs] >>> I noticed that there was no __init__.py in /usr/lib/debug/usr/lib/python3/dist-packages/PyQt4 so I added that and then... $ python3-dbg Python 3.2.3 (default, Oct 19 2012, 19:58:54) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys [60298 refs] >>> sys.path.insert(1, '/usr/lib/debug/usr/lib/python3/dist-packages') [60299 refs] >>> import PyQt4 [60324 refs] >>> PyQt4.__file__ '/usr/lib/debug/usr/lib/python3/dist-packages/PyQt4/__init__.py' [60328 refs] >>> import PyQt4.QtCore Segmentation fault (core dumped) Clearly, I am doing something wrong. Any hints? From tjreedy at udel.edu Sun Jan 6 14:29:08 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 06 Jan 2013 14:29:08 -0500 Subject: Ubuntu Python -dbg packages In-Reply-To: References: Message-ID: On 1/6/2013 8:42 AM, Lee Harr wrote: > > I am using: > Ubuntu 12.10 > Python 3.2.3 import has been considerably redone, and hopefully upgraded, in 3.3. > Qt 4.8.2 > PyQt 4.9.3 > > I also have the ubuntu -dbg packages: > python3-dbg > python3-pyqt4-dbg > > > > I don't understand why python3-dbg cannot import the PyQt4 modules... > > $ python3 > Python 3.2.3 (default, Oct 19 2012, 19:53:57) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> sys.executable > '/usr/bin/python3' >>>> import PyQt4 Is PyQtr.__file__ the same here, as below? >>>> import PyQt4.QtCore >>>> > > > $ python3-dbg > Python 3.2.3 (default, Oct 19 2012, 19:58:54) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys > [60298 refs] >>>> sys.executable > '/usr/bin/python3-dbg' > [60300 refs] >>>> import PyQt4 > [60323 refs] >>>> PyQt4.__file__ > '/usr/lib/python3/dist-packages/PyQt4/__init__.py' > [60323 refs] >>>> import PyQt4.QtCore > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named QtCore > [150996 refs] -- Terry Jan Reedy From missive at hotmail.com Sun Jan 6 15:21:09 2013 From: missive at hotmail.com (Lee Harr) Date: Mon, 7 Jan 2013 00:51:09 +0430 Subject: Ubuntu Python -dbg packages Message-ID: > On 1/6/2013 8:42 AM, Lee Harr wrote: >> >> I am using: >> Ubuntu 12.10 >> Python 3.2.3 > > import has been considerably redone, and hopefully upgraded, in 3.3. Ok, so now I tried python3.3-dbg but I don't think the pyqt modules are compiled for 3.3 and that may be preventing the import there. Those extension modules would need to be compiled for an exactly matching python interpreter, right? >> Qt 4.8.2 >> PyQt 4.9.3 >> >> I also have the ubuntu -dbg packages: >> python3-dbg >> python3-pyqt4-dbg >> >> >> >> I don't understand why python3-dbg cannot import the PyQt4 modules... > Is PyQtr.__file__ the same here, as below? Yes. It's the same. Sorry, that's what I meant to show there. $ python3 Python 3.2.3 (default, Oct 19 2012, 19:53:57) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import PyQt4 >>> PyQt4.__file__ '/usr/lib/python3/dist-packages/PyQt4/__init__.py' >>> >> $ python3-dbg >> Python 3.2.3 (default, Oct 19 2012, 19:58:54) >> [GCC 4.7.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import sys >> [60298 refs] >>>>> sys.executable >> '/usr/bin/python3-dbg' >> [60300 refs] >>>>> import PyQt4 >> [60323 refs] >>>>> PyQt4.__file__ >> '/usr/lib/python3/dist-packages/PyQt4/__init__.py' >> [60323 refs] >>>>> import PyQt4.QtCore >> Traceback (most recent call last): >>??? File "", line 1, in >> ImportError: No module named QtCore >> [150996 refs] So, python3-dbg _should_ be able to import this? Any ideas about the python3-pyqt4-dbg modules mentioned originally? From tjreedy at udel.edu Sun Jan 6 20:15:17 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 06 Jan 2013 20:15:17 -0500 Subject: Ubuntu Python -dbg packages In-Reply-To: References: Message-ID: On 1/6/2013 3:21 PM, Lee Harr wrote: > >> On 1/6/2013 8:42 AM, Lee Harr wrote: >>> >>> I am using: >>> Ubuntu 12.10 >>> Python 3.2.3 >> >> import has been considerably redone, and hopefully upgraded, in 3.3. > > > Ok, so now I tried python3.3-dbg but I don't think the pyqt > modules are compiled for 3.3 and that may be preventing > the import there. > > Those extension modules would need to be compiled for > an exactly matching python interpreter, right? For Windows visual C compiler, that is true. I do not know about gcc on *nix. I have gotten the impression that it is not necessarily so, except as the C api has changed in a way that affects the extension library. (Given that 3.3 is 3 months old, after 6 months of alpha/beta releases, and has some major improvements, it is past time for libraries that need recompiling to be so.) >>> I also have the ubuntu -dbg packages: >>> python3-dbg >>> python3-pyqt4-dbg >>> I don't understand why python3-dbg cannot import the PyQt4 modules... > >> Is PyQtr.__file__ the same here, as below? > > Yes. It's the same. > > Sorry, that's what I meant to show there. > > $ python3 > Python 3.2.3 (default, Oct 19 2012, 19:53:57) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import PyQt4 >>>> PyQt4.__file__ > '/usr/lib/python3/dist-packages/PyQt4/__init__.py' >>>> > > > >>> $ python3-dbg >>> Python 3.2.3 (default, Oct 19 2012, 19:58:54) >>> [GCC 4.7.2] on linux2 >>>>>> import PyQt4 >>> [60323 refs] >>>>>> PyQt4.__file__ >>> '/usr/lib/python3/dist-packages/PyQt4/__init__.py' >>> [60323 refs] >>>>>> import PyQt4.QtCore >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named QtCore >>> [150996 refs] > So, python3-dbg _should_ be able to import this? Given that python3 and python3-dbg import the same PyQt4 file, and that you spell PyQt4.QtCore the same (I checked), I am as surprised as you. Perhaps there is a bug in the import of the dbg build finding modules in packages, but that is so basic, that would surprise me also. Try running test/test_imp, _import, _importhooks, _importlib with both binaries (because you are looking for a different). On Windows, with 3.3, interactively in IDLE, I get >>> import test.test_imp as t; t.test_main() ... Ran 29 tests in 0.134s OK (skipped=1) ... Ran 48 tests in 0.953s OK (skipped=4) ... Ran 4 tests in 0.169s OK ... Ran 288 tests in 1.684s OK (skipped=2) Note that the above invocation runs in verbose mode, so if there is a difference, you can find the specific test. The skips are usually system specific. For instance, the one skip in the first batch is test_issue5604 (test.test_imp.ImportTests) ... skipped "can't run this test with mbcs as filesystem encoding" The others were for other posix-windows differences. > Any ideas about the python3-pyqt4-dbg modules mentioned originally? No. I stuck to what looked like might be easier. -- Terry Jan Reedy From missive at hotmail.com Mon Jan 7 20:01:01 2013 From: missive at hotmail.com (Lee Harr) Date: Tue, 8 Jan 2013 05:31:01 +0430 Subject: Ubuntu Python -dbg packages Message-ID: >> Ok, so now I tried python3.3-dbg but I don't think the pyqt >> modules are compiled for 3.3 and that may be preventing >> the import there. >> >> Those extension modules would need to be compiled for >> an exactly matching python interpreter, right? > > For Windows visual C compiler, that is true. I do not know about gcc on? > *nix. I have gotten the impression that it is not necessarily so, except? > as the C api has changed in a way that affects the extension library.? > (Given that 3.3 is 3 months old, after 6 months of alpha/beta releases,? > and has some major improvements, it is past time for libraries that need? > recompiling to be so.) Well... lets just say that with the ubuntu python3.3 package it doesn't work: $ python3.3 Python 3.3.0 (default, Sep 29 2012, 17:17:45)? [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import PyQt4 >>> import PyQt4.QtCore Traceback (most recent call last): ? File "", line 1, in ImportError: No module named 'PyQt4.QtCore' [plus a whole other problem...] Error in sys.excepthook: Traceback (most recent call last): ? File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in apport_excepthook ? ? from apport.fileutils import likely_packaged, get_recent_crashes ? File "/usr/lib/python3/dist-packages/apport/__init__.py", line 4, in ? ? from apport.report import Report ? File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in ? ? import apport.fileutils ? File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in ? ? from apport.packaging_impl import impl as packaging ? File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in ? ? import apt ? File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in ? ? import apt_pkg ImportError: No module named 'apt_pkg' Original exception was: Traceback (most recent call last): ? File "", line 1, in ImportError: No module named 'PyQt4.QtCore' >> So, python3-dbg _should_ be able to import this? > > Given that python3 and python3-dbg import the same PyQt4 file, and that? > you spell PyQt4.QtCore the same (I checked), I am as surprised as you.? Ok. I will file a Ubuntu bug report. > >>> import test.test_imp as t; t.test_main() This does not work for me: $ python3 Python 3.2.3 (default, Oct 19 2012, 19:53:57)? [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import test >>> test.test_imp Traceback (most recent call last): ? File "", line 1, in AttributeError: 'module' object has no attribute 'test_imp' $ python3.3 Python 3.3.0 (default, Sep 29 2012, 17:17:45)? [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import test >>> test.test_imp Traceback (most recent call last): ? File "", line 1, in AttributeError: 'module' object has no attribute 'test_imp' [plus that whole Error in sys.excepthook thing too...] Should this be another bug report for the ubuntu packages? From nospam at nospam.com Sun Jan 6 08:57:17 2013 From: nospam at nospam.com (RueTheDay) Date: Sun, 06 Jan 2013 07:57:17 -0600 Subject: Newbie problem with Python pandas Message-ID: <8qSdnfYwI8QgH3TNnZ2dnUVZ_uadnZ2d@giganews.com> I'm working my way through the examples in the O'Reilly book Python For Data Analysis and have encountered a snag. The following code is supposed to analyze some web server log data and produces aggregate counts by client operating system. ################### import json # used to process json records from pandas import DataFrame, Series import pandas as pd import matplotlib.pyplot as plt import numpy as np path = '/home/rich/code/sample.txt' records = [json.loads(line) for line in open(path)] #read in records one line at a time frame = DataFrame(records) cframe = frame[frame.a.notnull()] operating_system = np.where(cframe['a'].str.contains ('Windows'),'Windows', 'Not Windows') by_tz_os = cframe.groupby(['tz', operating_system]) agg_counts = by_tz_os.size().unstack().fillna(0) indexer = agg_counts.sum(1).argsort() count_subset = agg_counts.take(indexer)[-10:] print count_subset #################### I am getting the following error when running on Python 2.7 on Ubuntu 12.04: >>>>>> Traceback (most recent call last): File "./lp1.py", line 12, in operating_system = np.where(cframe['a'].str.contains ('Windows'),'Windows', 'Not Windows') AttributeError: 'Series' object has no attribute 'str' >>>>>>> Note that I was able to get the code to work fine on Windows 7, so this appears to be specific to Linux. A little Googling showed others have encountered this problem and suggested replacing the np.where with a find, as so: ######## operating_system = ['Windows' if a.find('Windows') > 0 else 'Not Windows' for a in cframe['a']] ######## This appears to solve the first problem, but then it fails on the next line with: >>>>>>>> Traceback (most recent call last): File "./lp1.py", line 14, in by_tz_os = cframe.groupby(['tz', operating_system]) File "/usr/lib/pymodules/python2.7/pandas/core/generic.py", line 133, in groupby sort=sort) File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 522, in groupby return klass(obj, by, **kwds) File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 115, in __init__ level=level, sort=sort) File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 705, in _get_groupings ping = Grouping(group_axis, gpr, name=name, level=level, sort=sort) File "/usr/lib/pymodules/python2.7/pandas/core/groupby.py", line 600, in __init__ self.grouper = self.index.map(self.grouper) File "/usr/lib/pymodules/python2.7/pandas/core/index.py", line 591, in map return self._arrmap(self.values, mapper) File "generated.pyx", line 1141, in pandas._tseries.arrmap_int64 (pandas/src/tseries.c:40593) TypeError: 'list' object is not callable >>>>>>>>> The problem looks to be with the pandas module and appears to be Linux- specific. Any ideas? I'm pulling my hair out over this. From miki.tebeka at gmail.com Sun Jan 6 11:05:59 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 6 Jan 2013 08:05:59 -0800 (PST) Subject: Newbie problem with Python pandas In-Reply-To: <8qSdnfYwI8QgH3TNnZ2dnUVZ_uadnZ2d@giganews.com> References: <8qSdnfYwI8QgH3TNnZ2dnUVZ_uadnZ2d@giganews.com> Message-ID: <733a78da-9393-4712-8255-a9942a5052b3@googlegroups.com> On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote: > I am getting the following error when running on Python 2.7 on Ubuntu > 12.04: > >>>>>> > > AttributeError: 'Series' object has no attribute 'str' I would *guess* that you have an older version of pandas on your Linux machine. Try "print(pd.__version__)" to see which version you have. Also, trying asking over at https://groups.google.com/forum/?fromgroups=#!forum/pydata which is more dedicated to pandas. From nospam at nospam.com Sun Jan 6 11:36:35 2013 From: nospam at nospam.com (RueTheDay) Date: Sun, 06 Jan 2013 10:36:35 -0600 Subject: Newbie problem with Python pandas References: <8qSdnfYwI8QgH3TNnZ2dnUVZ_uadnZ2d@giganews.com> <733a78da-9393-4712-8255-a9942a5052b3@googlegroups.com> Message-ID: <_dudnTTyxduONXTNnZ2dnUVZ_oCdnZ2d@giganews.com> On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote: > On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote: >> I am getting the following error when running on Python 2.7 on Ubuntu >> 12.04: >> >>>>>> >> >>>>>> >> AttributeError: 'Series' object has no attribute 'str' > I would *guess* that you have an older version of pandas on your Linux > machine. > Try "print(pd.__version__)" to see which version you have. > > Also, trying asking over at > https://groups.google.com/forum/?fromgroups=#!forum/pydata which is more > dedicated to pandas. Thank you! That was it. I had 0.7 installed (the latest in the Ubuntu repository). I downloaded and manually installed 0.10 and now it's working. Coincidentally, this also fixed a problem I was having with running a matplotlib plot function against a pandas Data Frame (worked with some chart types but not others). I'm starting to understand why people rely on easy_install and pip. Thanks again. From roy at panix.com Sun Jan 6 11:45:34 2013 From: roy at panix.com (Roy Smith) Date: Sun, 06 Jan 2013 11:45:34 -0500 Subject: Newbie problem with Python pandas References: <8qSdnfYwI8QgH3TNnZ2dnUVZ_uadnZ2d@giganews.com> <733a78da-9393-4712-8255-a9942a5052b3@googlegroups.com> <_dudnTTyxduONXTNnZ2dnUVZ_oCdnZ2d@giganews.com> Message-ID: In article <_dudnTTyxduONXTNnZ2dnUVZ_oCdnZ2d at giganews.com>, RueTheDay wrote: > On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote: > > > On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote: > >> I am getting the following error when running on Python 2.7 on Ubuntu > >> 12.04: > >> >>>>>> > >> >>>>>> > >> AttributeError: 'Series' object has no attribute 'str' > > I would *guess* that you have an older version of pandas on your Linux > > machine. > > Try "print(pd.__version__)" to see which version you have. > > > > Also, trying asking over at > > https://groups.google.com/forum/?fromgroups=#!forum/pydata which is more > > dedicated to pandas. > > Thank you! That was it. I had 0.7 installed (the latest in the Ubuntu > repository). I downloaded and manually installed 0.10 and now it's > working. Coincidentally, this also fixed a problem I was having with > running a matplotlib plot function against a pandas Data Frame (worked > with some chart types but not others). > > I'm starting to understand why people rely on easy_install and pip. > Thanks again. Yeah, Ubuntu is a bit of a mess when it comes to pandas and the things it depends on. Apt gets you numpy 1.4.1, which is really old. Pandas won't even install on top of it. I've got pandas (and numpy, and scipy, and matplotlib) running on a Ubuntu 12.04 box. I installed everything with pip. My problem at this point, however, is I want to replicate that setup in EMR (Amazon's Elastic Map-Reduce). In theory, I could just run "pip install numpy" in my mrjob.conf bootstrap, but it's a really long install process, building a lot of stuff from source. Not the kind of thing you want to put in a bootstrap for an ephemeral instance. Does anybody know where I can find a debian package for numpy 1.6? From nospam at nospam.com Sun Jan 6 12:15:45 2013 From: nospam at nospam.com (RueTheDay) Date: Sun, 06 Jan 2013 11:15:45 -0600 Subject: Newbie problem with Python pandas References: <8qSdnfYwI8QgH3TNnZ2dnUVZ_uadnZ2d@giganews.com> <733a78da-9393-4712-8255-a9942a5052b3@googlegroups.com> <_dudnTTyxduONXTNnZ2dnUVZ_oCdnZ2d@giganews.com> Message-ID: <_dudnTfyxdvcLHTNnZ2dnUVZ_oCdnZ2d@giganews.com> On Sun, 06 Jan 2013 11:45:34 -0500, Roy Smith wrote: > In article <_dudnTTyxduONXTNnZ2dnUVZ_oCdnZ2d at giganews.com>, > RueTheDay wrote: > >> On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote: >> >> > On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote: >> >> I am getting the following error when running on Python 2.7 on >> >> Ubuntu 12.04: >> >> >>>>>> >> >> >>>>>> >> >> AttributeError: 'Series' object has no attribute 'str' >> > I would *guess* that you have an older version of pandas on your >> > Linux machine. >> > Try "print(pd.__version__)" to see which version you have. >> > >> > Also, trying asking over at >> > https://groups.google.com/forum/?fromgroups=#!forum/pydata which is >> > more dedicated to pandas. >> >> Thank you! That was it. I had 0.7 installed (the latest in the Ubuntu >> repository). I downloaded and manually installed 0.10 and now it's >> working. Coincidentally, this also fixed a problem I was having with >> running a matplotlib plot function against a pandas Data Frame (worked >> with some chart types but not others). >> >> I'm starting to understand why people rely on easy_install and pip. >> Thanks again. > > Yeah, Ubuntu is a bit of a mess when it comes to pandas and the things > it depends on. Apt gets you numpy 1.4.1, which is really old. Pandas > won't even install on top of it. > > I've got pandas (and numpy, and scipy, and matplotlib) running on a > Ubuntu 12.04 box. I installed everything with pip. My problem at this > point, however, is I want to replicate that setup in EMR (Amazon's > Elastic Map-Reduce). In theory, I could just run "pip install numpy" in > my mrjob.conf bootstrap, but it's a really long install process, > building a lot of stuff from source. Not the kind of thing you want to > put in a bootstrap for an ephemeral instance. > > Does anybody know where I can find a debian package for numpy 1.6? Go here: http://neuro.debian.net/index.html#how-to-use-this-repository and add one their repositories to your sources. Then you can do use apt-get to install ALL the latest packages on your Ubuntu box - numpy, scipy, pandas, matplotlib, statsmodels, etc. I wish I found this a few days ago. From roy at panix.com Sun Jan 6 12:32:29 2013 From: roy at panix.com (Roy Smith) Date: Sun, 06 Jan 2013 12:32:29 -0500 Subject: Newbie problem with Python pandas References: <8qSdnfYwI8QgH3TNnZ2dnUVZ_uadnZ2d@giganews.com> <733a78da-9393-4712-8255-a9942a5052b3@googlegroups.com> <_dudnTTyxduONXTNnZ2dnUVZ_oCdnZ2d@giganews.com> <_dudnTfyxdvcLHTNnZ2dnUVZ_oCdnZ2d@giganews.com> Message-ID: In article <_dudnTfyxdvcLHTNnZ2dnUVZ_oCdnZ2d at giganews.com>, RueTheDay wrote: > On Sun, 06 Jan 2013 11:45:34 -0500, Roy Smith wrote: > > > In article <_dudnTTyxduONXTNnZ2dnUVZ_oCdnZ2d at giganews.com>, > > RueTheDay wrote: > > > >> On Sun, 06 Jan 2013 08:05:59 -0800, Miki Tebeka wrote: > >> > >> > On Sunday, January 6, 2013 5:57:17 AM UTC-8, RueTheDay wrote: > >> >> I am getting the following error when running on Python 2.7 on > >> >> Ubuntu 12.04: > >> >> >>>>>> > >> >> >>>>>> > >> >> AttributeError: 'Series' object has no attribute 'str' > >> > I would *guess* that you have an older version of pandas on your > >> > Linux machine. > >> > Try "print(pd.__version__)" to see which version you have. > >> > > >> > Also, trying asking over at > >> > https://groups.google.com/forum/?fromgroups=#!forum/pydata which is > >> > more dedicated to pandas. > >> > >> Thank you! That was it. I had 0.7 installed (the latest in the Ubuntu > >> repository). I downloaded and manually installed 0.10 and now it's > >> working. Coincidentally, this also fixed a problem I was having with > >> running a matplotlib plot function against a pandas Data Frame (worked > >> with some chart types but not others). > >> > >> I'm starting to understand why people rely on easy_install and pip. > >> Thanks again. > > > > Yeah, Ubuntu is a bit of a mess when it comes to pandas and the things > > it depends on. Apt gets you numpy 1.4.1, which is really old. Pandas > > won't even install on top of it. > > > > I've got pandas (and numpy, and scipy, and matplotlib) running on a > > Ubuntu 12.04 box. I installed everything with pip. My problem at this > > point, however, is I want to replicate that setup in EMR (Amazon's > > Elastic Map-Reduce). In theory, I could just run "pip install numpy" in > > my mrjob.conf bootstrap, but it's a really long install process, > > building a lot of stuff from source. Not the kind of thing you want to > > put in a bootstrap for an ephemeral instance. > > > > Does anybody know where I can find a debian package for numpy 1.6? > > Go here: > > http://neuro.debian.net/index.html#how-to-use-this-repository > > and add one their repositories to your sources. > > Then you can do use apt-get to install ALL the latest packages on your > Ubuntu box - numpy, scipy, pandas, matplotlib, statsmodels, etc. > > I wish I found this a few days ago. Cool, thanks! Really glad you're a few days ahead of me :-) From zigomania at gmail.com Sun Jan 6 11:03:43 2013 From: zigomania at gmail.com (marc.assin) Date: Sun, 6 Jan 2013 08:03:43 -0800 (PST) Subject: Newbee question about running a script Message-ID: Hello, I've just installed Python 2.7 on Windows 7 I've been able to write and run a script "Hello world" I wonder how I could specify a parameter on the command line from within the interpreter. Specifying a parameter on the DOS command line is no problem. Any hint, please ? From miki.tebeka at gmail.com Sun Jan 6 11:10:35 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 6 Jan 2013 08:10:35 -0800 (PST) Subject: Newbee question about running a script In-Reply-To: References: Message-ID: On Sunday, January 6, 2013 8:03:43 AM UTC-8, marc.assin wrote: > I wonder how I could specify a parameter on the command line from > within the interpreter. Guido wrote some advice a while back - http://www.artima.com/weblogs/viewpost.jsp?thread=4829 Import your module and call its main. The other way is to execute in another process: from subprocess import check_call import sys check_call([sys.executable, 'myscript.py', 'arg1', 'arg2']) From nobody at nowhere.org Sun Jan 6 11:43:11 2013 From: nobody at nowhere.org (Franck Ditter) Date: Sun, 06 Jan 2013 17:43:11 +0100 Subject: Problem with Unicode char in Python 3.3.0 Message-ID: Hi ! I work on MacOS-X Lion and IDLE/Python 3.3.0 I can't get the treble key (U1D11E) ! >>> "\U1D11E" SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-6: end of string in escape sequence How can I display musical keys ? Thanks, franck From __peter__ at web.de Sun Jan 6 12:03:36 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 06 Jan 2013 18:03:36 +0100 Subject: Problem with Unicode char in Python 3.3.0 References: Message-ID: Franck Ditter wrote: > I work on MacOS-X Lion and IDLE/Python 3.3.0 > I can't get the treble key (U1D11E) ! > >>>> "\U1D11E" > SyntaxError: (unicode error) 'unicodeescape' codec can't > decode bytes in position 0-6: end of string in escape sequence > > How can I display musical keys ? Try >>> "\U0001D11E" '?' From marduk at python.net Sun Jan 6 12:10:08 2013 From: marduk at python.net (marduk) Date: Sun, 06 Jan 2013 12:10:08 -0500 Subject: Problem with Unicode char in Python 3.3.0 In-Reply-To: References: Message-ID: <1357492208.26164.140661174087617.18BD6C48@webmail.messagingengine.com> On Sun, Jan 6, 2013, at 11:43 AM, Franck Ditter wrote: > Hi ! > I work on MacOS-X Lion and IDLE/Python 3.3.0 > I can't get the treble key (U1D11E) ! > > >>> "\U1D11E" > SyntaxError: (unicode error) 'unicodeescape' codec can't > decode bytes in position 0-6: end of string in escape sequence > You probably meant: >>> '\U0001d11e' For that synax you must use either '\uXXXX' or '\UXXXXXXXX' (i.e. specify either 4 or 8 hex digits). http://docs.python.org/2/howto/unicode#unicode-literals-in-python-source-code From nobody at nowhere.org Mon Jan 7 07:57:26 2013 From: nobody at nowhere.org (Franck Ditter) Date: Mon, 07 Jan 2013 13:57:26 +0100 Subject: Problem with Unicode char in Python 3.3.0 References: Message-ID: In article , marduk wrote: > On Sun, Jan 6, 2013, at 11:43 AM, Franck Ditter wrote: > > Hi ! > > I work on MacOS-X Lion and IDLE/Python 3.3.0 > > I can't get the treble key (U1D11E) ! > > > > >>> "\U1D11E" > > SyntaxError: (unicode error) 'unicodeescape' codec can't > > decode bytes in position 0-6: end of string in escape sequence > > > > You probably meant: > > >>> '\U0001d11e' > > > For that synax you must use either '\uXXXX' or '\UXXXXXXXX' (i.e. > specify either 4 or 8 hex digits). > > http://docs.python.org/2/howto/unicode#unicode-literals-in-python-source-code <<< print('\U0001d11e') Traceback (most recent call last): File "", line 1, in print('\U0001d11e') UnicodeEncodeError: 'UCS-2' codec can't encode character '\U0001d11e' in position 0: Non-BMP character not supported in Tk From rosuav at gmail.com Mon Jan 7 08:04:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 00:04:43 +1100 Subject: Problem with Unicode char in Python 3.3.0 In-Reply-To: References: Message-ID: On Mon, Jan 7, 2013 at 11:57 PM, Franck Ditter wrote: > <<< print('\U0001d11e') > Traceback (most recent call last): > File "", line 1, in > print('\U0001d11e') > UnicodeEncodeError: 'UCS-2' codec can't encode character '\U0001d11e' > in position 0: Non-BMP character not supported in Tk That's a different issue; IDLE can't handle non-BMP characters. Try it from the terminal if you can - on my Linux systems (Debians and Ubuntus with GNOME and gnome-terminal), the terminal is set to UTF-8 and quite happily accepts the full Unicode range. On Windows, that may well not be the case, though. ChrisA From tjreedy at udel.edu Mon Jan 7 08:12:57 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 07 Jan 2013 08:12:57 -0500 Subject: Problem with Unicode char in Python 3.3.0 In-Reply-To: References: Message-ID: On 1/7/2013 7:57 AM, Franck Ditter wrote: > <<< print('\U0001d11e') > Traceback (most recent call last): > File "", line 1, in > print('\U0001d11e') > UnicodeEncodeError: 'UCS-2' codec can't encode character '\U0001d11e' > in position 0: Non-BMP character not supported in Tk The message comes from printing to a tk text widget (the IDLE shell), not from creating the 1 char string. c = '\U0001d11e' works fine. When you have problems with creating and printing unicode, *separate* creating from printing to see where the problem is. (I do not know if the brand new tcl/tk 8.6 is any better.) The windows console also chokes, but with a different message. >>> c='\U0001d11e' >>> print(c) Traceback (most recent call last): File "", line 1, in File "C:\Programs\Python33\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\U0001d11e' in posit ion 0: character maps to Yes, this is very annoying, especially in Win 7. -- Terry Jan Reedy From tjreedy at udel.edu Tue Jan 8 03:40:47 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 Jan 2013 03:40:47 -0500 Subject: Problem with Unicode char in Python 3.3.0 In-Reply-To: References: Message-ID: On 1/7/2013 8:12 AM, Terry Reedy wrote: > On 1/7/2013 7:57 AM, Franck Ditter wrote: > >> <<< print('\U0001d11e') >> Traceback (most recent call last): >> File "", line 1, in >> print('\U0001d11e') >> UnicodeEncodeError: 'UCS-2' codec can't encode character '\U0001d11e' >> in position 0: Non-BMP character not supported in Tk > > The message comes from printing to a tk text widget (the IDLE shell), > not from creating the 1 char string. c = '\U0001d11e' works fine. When > you have problems with creating and printing unicode, *separate* > creating from printing to see where the problem is. (I do not know if > the brand new tcl/tk 8.6 is any better.) > > The windows console also chokes, but with a different message. > > >>> c='\U0001d11e' > >>> print(c) > Traceback (most recent call last): > File "", line 1, in > File "C:\Programs\Python33\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\U0001d11e' > in posit > ion 0: character maps to > > Yes, this is very annoying, especially in Win 7. The above is in 3.3, in which '\U0001d11e' is actually translated to a length 1 string. In 3.2-, that literal is translated (on 3.2- narrow builds, as on Windows) to a length 2 string surrogate pair (in the BMP). On printing, the pair of surrogates got translated to a square box used for all characters for which the font does not have a glyph. ?When cut and pasted, it shows in this mail composer as a weird music sign with peculiar behavior. 3 -s, 3 spaces, paste, 3 spaces, 3 -s, but it may disappear. --- ? --- So 3.3 is the first Windows version to get the UnicodeEncodeError on printing. -- Terry Jan Reedy From bv8bv8bv8 at gmail.com Sun Jan 6 12:41:18 2013 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sun, 6 Jan 2013 09:41:18 -0800 (PST) Subject: ??????????? when was jesus christ born Message-ID: <38f38a0b-91ab-4346-bf99-50a6cc664760@a8g2000vby.googlegroups.com> ? when was jesus christ born http://www.youtube.com/v/Qxjk3FGy71g?rel=0 than you From pwsteele at gmail.com Sun Jan 6 14:10:45 2013 From: pwsteele at gmail.com (Peter Steele) Date: Sun, 6 Jan 2013 11:10:45 -0800 (PST) Subject: Specifying two log files with one configuration file Message-ID: <4e6a4b79-5a4a-4e0b-818a-74cb7f0caf94@googlegroups.com> I want to configure the Python logging module to manage two separate log files, allowing me to do something like this: import logging import logging.config logging.config.fileConfig("mylogging.conf") root = logging.getLogger() test = logging.getLogger("test") root.debug("This is a message targeted to the root log file") test.debug("This is a message targeted to the test log file") I have been unable to get this to work. My current conf file looks like this: [formatters] keys: simple [handlers] keys: root,test [loggers] keys: root,test [formatter_simple] format=%(asctime)s - %(levelname)s - %(message)s [handler_root] class: handlers.RotatingFileHandler args: ('/var/log/root.log', 'a', 1024000, 14) formatter: simple [handler_test] class: handlers.RotatingFileHandler args: ('/var/log/test.log', 'a', 1024000, 14) formatter: simple [logger_root] level: DEBUG handlers: root qualname: [logger_test] level: DEBUG handlers: test qualname: With this setup, all of my log messages go to test.log. root.log is created, but nothing gets logged to it. What do I need in my logging conf file to have two separate log file destinations? From vinay_sajip at yahoo.co.uk Tue Jan 8 19:57:01 2013 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 9 Jan 2013 00:57:01 +0000 (UTC) Subject: Specifying two log files with one configuration file References: <4e6a4b79-5a4a-4e0b-818a-74cb7f0caf94@googlegroups.com> Message-ID: Peter Steele gmail.com> writes: > I have been unable to get this to work. My current conf file looks like this: Try with the following changes: [logger_test] level: DEBUG handlers: test propagate: 0 qualname: test The qualname: test is what identifies the logger as the logger named 'test', and propagate: 0 prevents the test message from being passed up to the root logger. Regards, Vinay Sajip From kalvinmanual at gmail.com Sun Jan 6 14:15:29 2013 From: kalvinmanual at gmail.com (kalvinmanual) Date: Sun, 06 Jan 2013 13:15:29 -0600 Subject: SOLUTIONS MANUAL TO Orbital Mechanics for Engineering Students 2nd ED by Curtis Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTIONS MANUAL TO Probability & Statistics for Engineers & Scientists (8th Ed., Walpole,Myers, Ye) SOLUTIONS MANUAL TO Probability and Statistical Inference ( 8th Ed, Hogg & Tanis ) SOLUTIONS MANUAL TO Probability and Statistical Inference (7th Ed., Hogg & Tanis) SOLUTIONS MANUAL TO Probability and Statistics for Engineering and the Sciences, 6th Ed., by Jay L. Devore SOLUTIONS MANUAL TO Probability and Statistics for Engineers 7 Ed Johnson Miller Freund SOLUTIONS MANUAL TO Probability and Statistics for Engineers 8th Ed by Miller, Freund SOLUTIONS MANUAL TO Probability and Statistics for Engineers and Scientists 3rd Ed by Hayter SOLUTIONS MANUAL TO Probability and Statistics in Engineering (4th Ed., Hines, Montgomery, Goldsman & Borror) SOLUTIONS MANUAL TO Probability and Stochastic Processes 2E, by Roy D. Yates , David J. Goodman SOLUTIONS MANUAL TO Probability Concepts in Engineering Emphasis on Applications to Civil and Environmental Engineering 2nd ED by Alfredo Ang and Wilson Tang SOLUTIONS MANUAL TO Probability For Risk Management, Hassett, Stewart SOLUTIONS MANUAL TO Probability Random Variables, and Stochastic Processes, 4th Ed., by Papoulis, Pillai SOLUTIONS MANUAL TO Probability, Random Variables and Stochastic Processes, 3rd Edition Athanasios Papoulis SOLUTIONS MANUAL TO Probability, Random Variables, and Random Signal Principles 4th Ed by Peyton, Peebles SOLUTIONS MANUAL TO Probability, Statistics, and Random Processes for Electrical Engineers 3rd E by A. Leon-Garcia SOLUTIONS MANUAL TO Probability, Statistics, and Random Processes for Engineers, Richard H. Williams SOLUTIONS MANUAL TO Problems and Solutions on Electromagnetism by Lim Yung-Kuo SOLUTIONS MANUAL TO Problems in general physics by I. E Irodov SOLUTIONS MANUAL TO Problems in General Physics vol.I & vol.II Irodov SOLUTIONS MANUAL TO Process Control Instrumentation Technology, 8 ed by Curtis D. Johnson SOLUTIONS MANUAL TO Process Dynamics and Control 2nd ED by Seborg, Edgar and Mellichamp SOLUTIONS MANUAL TO PROCESS SYSTEMS ANALYSIS AND by COUGHANOWR SOLUTIONS MANUAL TO Programmable Logic Controllers (James A. Rehg, Glenn J. Sartori) SOLUTIONS MANUAL TO Psychology and Life 16th ed by Gerrig and Zimbardo SOLUTIONS MANUAL TO Psychology and Life by Gerrig & Zimbardo ,16th edition SOLUTIONS MANUAL TO Quantitative Methods for Management by PINNEY, McWILLIAMS, ORMSBY, ATCHISON SOLUTIONS MANUAL TO Quantum Electronics for Atomic Physics by Warren Nagourney SOLUTIONS MANUAL TO Quantum Field Theory Mark Srednicki SOLUTIONS MANUAL TO Quantum Mechanics - B. Brinne SOLUTIONS MANUAL TO Quantum Mechanics: An Accessible Introduction (Robert Scherrer) SOLUTIONS MANUAL TO Quantum Physics of Atoms, Molecules, Solids, Nuclei and Particles 2 nd by Eisberg SOLUTIONS MANUAL TO Quantum Physics, 3rd Edition, by Stephen Gasiorowicz SOLUTIONS MANUAL TO Quantum theory of light 3 Ed by Rodney Loudon SOLUTIONS MANUAL TO Queueing Systems (Volume 1 - Theory) by Leonard Kleinrock, Richard Gail SOLUTIONS MANUAL TO Real Analysis 1st Edition by H. L. Royden SOLUTIONS MANUAL TO Real and Complex Analysis by Nguyen, Burckel SOLUTIONS MANUAL TO Recursive Methods in Economic Dynamics, (2002) by Irigoyen, Rossi- Hansberg, Wright SOLUTIONS MANUAL TO Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight) SOLUTIONS MANUAL TO RF Circuit Design: Theory & Applications, by Bretchko, Ludwig SOLUTIONS MANUAL TO Satellite Communications 2nd Ed By Timothy Pratt, Charles W. Bostian SOLUTIONS MANUAL TO Scientific Computing with Case Studies by Dianne P. O'Leary SOLUTIONS MANUAL TO Semiconductor Device Fundamentals by Pierret SOLUTIONS MANUAL TO SEMICONDUCTOR DEVICES Physics and Technology 2nd Ed by SZE SOLUTIONS MANUAL TO Semiconductor Physics and Applications by Balkanski, Wallis SOLUTIONS MANUAL TO Semiconductor Physics and Devices (3rd Ed., Donald A. Neamen) SOLUTIONS MANUAL TO Semiconductor Physics and Devices 4th E by Donald A. Neamen SOLUTIONS MANUAL TO Separation Process Principles 2nd ED by Seader, Henley SOLUTIONS MANUAL TO Separation Process Principles by Seader & Henley SOLUTIONS MANUAL TO SERWAY AND VUILLE???S COLLEGE PHYSICS NINTH EDITION SOLUTIONS MANUAL TO Shigley's Mechanical Engineering Design (8th Ed., Budynas) SOLUTIONS MANUAL TO Signal Processing and Linear Systems by Lathi SOLUTIONS MANUAL TO Signal Processing First by Mclellan, Schafer & Yoder SOLUTIONS MANUAL TO Signals and Systems 2e by Haykin & B Van Veen SOLUTIONS MANUAL TO Signals and Systems 2nd Edition Oppenheim, Willsky and Nawab SOLUTIONS MANUAL TO Signals and Systems Analysis of Signals Through Linear Systems by M.J. Roberts, M.J. Roberts SOLUTIONS MANUAL TO Signals and Systems, 2nd Edition, Oppenheim, Willsky, Hamid, Nawab SOLUTIONS MANUAL TO Signals and Systems: Analysis Using Transform Methods and MATLAB, 1st Ed., by M. J. Roberts SOLUTIONS MANUAL TO Signals, Systems & Transforms 4 ED by Phillips, Parr & Riskin SOLUTIONS MANUAL TO SILICON VLSI TECHNOLOGY Fundamentals, Practice and Modeling By Plummer, Griffin SOLUTIONS MANUAL TO Simply C# - An Application-Driven (TM) Tutorial Approach by Deitel SOLUTIONS MANUAL TO Single Variable Calculus Early Transcendentals, 4th Edition, JAMES STEWART SOLUTIONS MANUAL TO Single Variable Calculus Early Transcendentals, 5th Edition, JAMES STEWART SOLUTIONS MANUAL TO Skill - Assessment Exercises to Accompany Control Systems Engineering 3rd edt. by Norman S. Nise SOLUTIONS MANUAL TO Soil Mechanics 7th ed by R. F. Craig SOLUTIONS MANUAL TO Soil Mechanics Concepts and Applications, 2nd Ed., by Powrie SOLUTIONS MANUAL TO Solid State Electronic Devices (6th Ed., Ben Streetman, Sanjay Banerjee) SOLUTIONS MANUAL TO Solid State Electronics 5th ed by Ben Streetman, Sanjay Banerjee SOLUTIONS MANUAL TO Solid State Physics by Ashcroft & Mermin SOLUTIONS MANUAL TO Solid State Physics by Lazlo Mihaly, Michael C. Martin SOLUTIONS MANUAL TO Solving Applied Mathematical Problems with MATLAB by Xue, Chen SOLUTIONS MANUAL TO Solving ODEs with MATLAB (L. F. Shampine, I. Gladwell & S. Thompson) SOLUTIONS MANUAL TO South-Western Federal Taxation 2012 - Corporations, Partnerships, Estates and Trusts, 35th Ed by Hoffman, Maloney SOLUTIONS MANUAL TO Special Relativity (P.M. Schwarz & J.H. Schwarz) SOLUTIONS MANUAL TO Statics and Mechanics of Materials by Bedford, Fowler, Liechti SOLUTIONS MANUAL TO Statics and Mechanics of Materials, 2/E., By Russell C. Hibbeler SOLUTIONS MANUAL TO Statistical and Adaptive Signal Processing by Manolakis, Ingle, Kogon SOLUTIONS MANUAL TO Statistical Digital Signal Processing and Modeling ,Monson H. Hayes SOLUTIONS MANUAL TO Statistical Inference 2e by Casella G., Berger R.L. and Santana SOLUTIONS MANUAL TO Statistical Inference, Second Edition Casella-Berger SOLUTIONS MANUAL TO Statistical Physics of Fields by Mehran Kardar SOLUTIONS MANUAL TO Statistical Physics of Particles by Mehran Kardar SOLUTIONS MANUAL TO Statistics and Finance - An Introduction by David Ruppert SOLUTIONS MANUAL TO Statistics and Finance - An Introduction by David Ruppert SOLUTIONS MANUAL TO Statistics for Business and Economics 8 ED by Anderson, Sweeney SOLUTIONS MANUAL TO Statistics for Business and Economics 9 ED by Anderson, Sweeney SOLUTIONS MANUAL TO Statistics for Engineering and the Sciences 5th E by Mendenhall,Sincich SOLUTIONS MANUAL TO Statistics for Engineers and Scientists 2 E by Navidi SOLUTIONS MANUAL TO Steel Design, 4th Edition Segui SOLUTIONS MANUAL TO STEEL DESIGN, 5th Edition By WILLIAM T. SEGUI From jcasale at activenetwerx.com Sun Jan 6 14:44:08 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 6 Jan 2013 19:44:08 +0000 Subject: Numpy outlier removal Message-ID: I have a dataset that consists of a dict with text descriptions and values that are integers. If required, I collect the values into a list and create a numpy array running it through a simple routine:?data[abs(data - mean(data)) < m * std(data)] where m is the number of std deviations to include. The problem is I loos track of which were removed so the original display of the dataset is misleading when the processed average is returned as it includes the removed key/values. Ayone know how I can maintain the relationship and when I exclude a value, remove it from the dict? Thanks! jlc From hansmu at xs4all.nl Sun Jan 6 17:33:54 2013 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 06 Jan 2013 23:33:54 +0100 Subject: Numpy outlier removal In-Reply-To: References: Message-ID: <50e9fbd5$0$6848$e4fe514c@news2.news.xs4all.nl> On 6/01/13 20:44:08, Joseph L. Casale wrote: > I have a dataset that consists of a dict with text descriptions and values that are integers. If > required, I collect the values into a list and create a numpy array running it through a simple > routine: data[abs(data - mean(data)) < m * std(data)] where m is the number of std deviations > to include. > > > The problem is I loos track of which were removed so the original display of the dataset is > misleading when the processed average is returned as it includes the removed key/values. > > > Ayone know how I can maintain the relationship and when I exclude a value, remove it from > the dict? Assuming your data and the dictionary are keyed by a common set of keys: for key in descriptions: if abs(data[key] - mean(data)) >= m * std(data): del data[key] del descriptions[key] Hope this helps, -- HansM From jcasale at activenetwerx.com Sun Jan 6 17:50:07 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 6 Jan 2013 22:50:07 +0000 Subject: Numpy outlier removal In-Reply-To: <50e9fbd5$0$6848$e4fe514c@news2.news.xs4all.nl> References: , <50e9fbd5$0$6848$e4fe514c@news2.news.xs4all.nl> Message-ID: >Assuming your data and the dictionary are keyed by a common set of keys:? > >for key in descriptions: > ? ?if abs(data[key] - mean(data)) >= m * std(data): > ? ? ? ?del data[key] > ? ? ? ?del descriptions[key] Heh, yeah sometimes the obvious is too simple to see. I used a dict comp to rebuild the results with the comparison. Thanks! jlc From python at mrabarnett.plus.com Sun Jan 6 18:18:43 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 06 Jan 2013 23:18:43 +0000 Subject: Numpy outlier removal In-Reply-To: <50e9fbd5$0$6848$e4fe514c@news2.news.xs4all.nl> References: <50e9fbd5$0$6848$e4fe514c@news2.news.xs4all.nl> Message-ID: <50EA0653.2050104@mrabarnett.plus.com> On 2013-01-06 22:33, Hans Mulder wrote: > On 6/01/13 20:44:08, Joseph L. Casale wrote: >> I have a dataset that consists of a dict with text descriptions and values that are integers. If >> required, I collect the values into a list and create a numpy array running it through a simple >> routine: data[abs(data - mean(data)) < m * std(data)] where m is the number of std deviations >> to include. >> >> >> The problem is I loos track of which were removed so the original display of the dataset is >> misleading when the processed average is returned as it includes the removed key/values. >> >> >> Ayone know how I can maintain the relationship and when I exclude a value, remove it from >> the dict? > > Assuming your data and the dictionary are keyed by a common set of keys: > > for key in descriptions: > if abs(data[key] - mean(data)) >= m * std(data): > del data[key] > del descriptions[key] > It's generally a bad idea to modify a collection over which you're iterating. It's better to, say, make a list of what you're going to delete and then iterate over that list to make the deletions: deletions = [] for key in in descriptions: if abs(data[key] - mean(data)) >= m * std(data): deletions.append(key) for key in deletions: del data[key] del descriptions[key] From steve+comp.lang.python at pearwood.info Sun Jan 6 20:46:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2013 01:46:15 GMT Subject: Numpy outlier removal References: Message-ID: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 06 Jan 2013 19:44:08 +0000, Joseph L. Casale wrote: > I have a dataset that consists of a dict with text descriptions and > values that are integers. If required, I collect the values into a list > and create a numpy array running it through a simple routine:? > > data[abs(data - mean(data)) < m * std(data)] > > where m is the number of std deviations to include. I'm not sure that this approach is statistically robust. No, let me be even more assertive: I'm sure that this approach is NOT statistically robust, and may be scientifically dubious. The above assumes your data is normally distributed. How sure are you that this is actually the case? For normally distributed data: Since both the mean and std calculations as effected by the presence of outliers, your test for what counts as an outlier will miss outliers for data from a normal distribution. For small N (sample size), it may be mathematically impossible for any data point to be greater than m*SD from the mean. For example, with N=5, no data point can be more than 1.789*SD from the mean. So for N=5, m=1 may throw away good data, and m=2 will fail to find any outliers no matter how outrageous they are. For large N, you will expect to find significant numbers of data points more than m*SD from the mean. With N=100000, and m=3, you will expect to throw away 270 perfectly good data points simply because they are out on the tails of the distribution. Worse, if the data is not in fact from a normal distribution, all bets are off. You may be keeping obvious outliers; or more often, your test will be throwing away perfectly good data that it misidentifies as outliers. In other words: this approach for detecting outliers is nothing more than a very rough, and very bad, heuristic, and should be avoided. Identifying outliers is fraught with problems even for experts. For example, the ozone hole over the Antarctic was ignored for many years because the software being used to analyse it misidentified the data as outliers. The best general advice I have seen is: Never automatically remove outliers except for values that are physically impossible (e.g. "baby's weight is 95kg", "test score of 31 out of 20"), unless you have good, solid, physical reasons for justifying removal of outliers. Other than that, manually remove outliers with care, or not at all, and if you do so, always report your results twice, once with all the data, and once with supposed outliers removed. You can read up more about outlier detection, and the difficulties thereof, here: http://www.medcalc.org/manual/outliers.php https://secure.graphpad.com/guides/prism/6/statistics/index.htm http://www.webapps.cee.vt.edu/ewr/environmental/teach/smprimer/outlier/outlier.html http://stats.stackexchange.com/questions/38001/detecting-outliers-using-standard-deviations -- Steven From psimon at sonic.net Sun Jan 6 21:21:06 2013 From: psimon at sonic.net (Paul Simon) Date: Sun, 6 Jan 2013 18:21:06 -0800 Subject: Numpy outlier removal References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ea3199$0$80136$742ec2ed@news.sonic.net> "Steven D'Aprano" wrote in message news:50ea28e7$0$30003$c3e8da3$5496439d at news.astraweb.com... > On Sun, 06 Jan 2013 19:44:08 +0000, Joseph L. Casale wrote: > >> I have a dataset that consists of a dict with text descriptions and >> values that are integers. If required, I collect the values into a list >> and create a numpy array running it through a simple routine: >> >> data[abs(data - mean(data)) < m * std(data)] >> >> where m is the number of std deviations to include. > > I'm not sure that this approach is statistically robust. No, let me be > even more assertive: I'm sure that this approach is NOT statistically > robust, and may be scientifically dubious. > > The above assumes your data is normally distributed. How sure are you > that this is actually the case? > > For normally distributed data: > > Since both the mean and std calculations as effected by the presence of > outliers, your test for what counts as an outlier will miss outliers for > data from a normal distribution. For small N (sample size), it may be > mathematically impossible for any data point to be greater than m*SD from > the mean. For example, with N=5, no data point can be more than 1.789*SD > from the mean. So for N=5, m=1 may throw away good data, and m=2 will > fail to find any outliers no matter how outrageous they are. > > For large N, you will expect to find significant numbers of data points > more than m*SD from the mean. With N=100000, and m=3, you will expect to > throw away 270 perfectly good data points simply because they are out on > the tails of the distribution. > > Worse, if the data is not in fact from a normal distribution, all bets > are off. You may be keeping obvious outliers; or more often, your test > will be throwing away perfectly good data that it misidentifies as > outliers. > > In other words: this approach for detecting outliers is nothing more than > a very rough, and very bad, heuristic, and should be avoided. > > Identifying outliers is fraught with problems even for experts. For > example, the ozone hole over the Antarctic was ignored for many years > because the software being used to analyse it misidentified the data as > outliers. > > The best general advice I have seen is: > > Never automatically remove outliers except for values that are physically > impossible (e.g. "baby's weight is 95kg", "test score of 31 out of 20"), > unless you have good, solid, physical reasons for justifying removal of > outliers. Other than that, manually remove outliers with care, or not at > all, and if you do so, always report your results twice, once with all > the data, and once with supposed outliers removed. > > You can read up more about outlier detection, and the difficulties > thereof, here: > > http://www.medcalc.org/manual/outliers.php > > https://secure.graphpad.com/guides/prism/6/statistics/index.htm > > http://www.webapps.cee.vt.edu/ewr/environmental/teach/smprimer/outlier/outlier.html > > http://stats.stackexchange.com/questions/38001/detecting-outliers-using-standard-deviations > > > > -- > Steven If you suspect that the data may not be normal you might look at exploratory data analysis, see Tukey. It's descriptive rather than analytic, treats outliers respectfully, uses median rather than mean, and is very visual. Wherever I analyzed data both gaussian and with EDA, EDA always won. Paul From jcasale at activenetwerx.com Sun Jan 6 21:12:23 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Mon, 7 Jan 2013 02:12:23 +0000 Subject: Numpy outlier removal In-Reply-To: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> References: , <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: > In other words: this approach for detecting outliers is nothing more than? > a very rough, and very bad, heuristic, and should be avoided. Heh, very true but the results will only be used for conversational?purposes. I am making an assumption that the data is normally distributed and I do expect valid results to all be very nearly the same. > You can read up more about outlier detection, and the difficulties? > thereof, here: I much appreciate the links and the thought in the post. I'll admit I didn't realize outlier detection was as involved. Again, thanks! jlc From oscar.j.benjamin at gmail.com Sun Jan 6 21:29:27 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 7 Jan 2013 02:29:27 +0000 Subject: Numpy outlier removal In-Reply-To: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 7 January 2013 01:46, Steven D'Aprano wrote: > On Sun, 06 Jan 2013 19:44:08 +0000, Joseph L. Casale wrote: > >> I have a dataset that consists of a dict with text descriptions and >> values that are integers. If required, I collect the values into a list >> and create a numpy array running it through a simple routine: >> >> data[abs(data - mean(data)) < m * std(data)] >> >> where m is the number of std deviations to include. > > I'm not sure that this approach is statistically robust. No, let me be > even more assertive: I'm sure that this approach is NOT statistically > robust, and may be scientifically dubious. Whether or not this is "statistically robust" requires more explanation about the OP's intention. Thus far, the OP has not given any reason/motivation for excluding data or even for having any data in the first place! It's hard to say whether any technique applied is really accurate/robust without knowing *anything* about the purpose of the operation. Oscar From steve+comp.lang.python at pearwood.info Mon Jan 7 00:11:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2013 05:11:13 GMT Subject: Numpy outlier removal References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> On Mon, 07 Jan 2013 02:29:27 +0000, Oscar Benjamin wrote: > On 7 January 2013 01:46, Steven D'Aprano > wrote: >> On Sun, 06 Jan 2013 19:44:08 +0000, Joseph L. Casale wrote: >> >>> I have a dataset that consists of a dict with text descriptions and >>> values that are integers. If required, I collect the values into a >>> list and create a numpy array running it through a simple routine: >>> >>> data[abs(data - mean(data)) < m * std(data)] >>> >>> where m is the number of std deviations to include. >> >> I'm not sure that this approach is statistically robust. No, let me be >> even more assertive: I'm sure that this approach is NOT statistically >> robust, and may be scientifically dubious. > > Whether or not this is "statistically robust" requires more explanation > about the OP's intention. Not really. Statistics robustness is objectively defined, and the user's intention doesn't come into it. The mean is not a robust measure of central tendency, the median is, regardless of why you pick one or the other. There are sometimes good reasons for choosing non-robust statistics or techniques over robust ones, but some techniques are so dodgy that there is *never* a good reason for doing so. E.g. finding the line of best fit by eye, or taking more and more samples until you get a statistically significant result. Such techniques are not just non-robust in the statistical sense, but non-robust in the general sense, if not outright deceitful. -- Steven From oscar.j.benjamin at gmail.com Mon Jan 7 10:20:57 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 7 Jan 2013 15:20:57 +0000 Subject: Numpy outlier removal In-Reply-To: <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> Message-ID: On 7 January 2013 05:11, Steven D'Aprano wrote: > On Mon, 07 Jan 2013 02:29:27 +0000, Oscar Benjamin wrote: > >> On 7 January 2013 01:46, Steven D'Aprano >> wrote: >>> On Sun, 06 Jan 2013 19:44:08 +0000, Joseph L. Casale wrote: >>> >>> I'm not sure that this approach is statistically robust. No, let me be >>> even more assertive: I'm sure that this approach is NOT statistically >>> robust, and may be scientifically dubious. >> >> Whether or not this is "statistically robust" requires more explanation >> about the OP's intention. > > Not really. Statistics robustness is objectively defined, and the user's > intention doesn't come into it. The mean is not a robust measure of > central tendency, the median is, regardless of why you pick one or the > other. Okay, I see what you mean. I wasn't thinking of robustness as a technical term but now I see that you are correct. Perhaps what I should have said is that whether or not this matters depends on the problem at hand (hopefully this isn't an important medical trial) and the particular type of data that you have; assuming normality is fine in many cases even if the data is not "really" normal. > > There are sometimes good reasons for choosing non-robust statistics or > techniques over robust ones, but some techniques are so dodgy that there > is *never* a good reason for doing so. E.g. finding the line of best fit > by eye, or taking more and more samples until you get a statistically > significant result. Such techniques are not just non-robust in the > statistical sense, but non-robust in the general sense, if not outright > deceitful. There are sometimes good reasons to get a line of best fit by eye. In particular if your data contains clusters that are hard to separate, sometimes it's useful to just pick out roughly where you think a line through a subset of the data is. Oscar From robert.kern at gmail.com Mon Jan 7 10:35:05 2013 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 07 Jan 2013 15:35:05 +0000 Subject: Numpy outlier removal In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> Message-ID: On 07/01/2013 15:20, Oscar Benjamin wrote: > On 7 January 2013 05:11, Steven D'Aprano > wrote: >> On Mon, 07 Jan 2013 02:29:27 +0000, Oscar Benjamin wrote: >> >>> On 7 January 2013 01:46, Steven D'Aprano >>> wrote: >>>> On Sun, 06 Jan 2013 19:44:08 +0000, Joseph L. Casale wrote: >>>> >>>> I'm not sure that this approach is statistically robust. No, let me be >>>> even more assertive: I'm sure that this approach is NOT statistically >>>> robust, and may be scientifically dubious. >>> >>> Whether or not this is "statistically robust" requires more explanation >>> about the OP's intention. >> >> Not really. Statistics robustness is objectively defined, and the user's >> intention doesn't come into it. The mean is not a robust measure of >> central tendency, the median is, regardless of why you pick one or the >> other. > > Okay, I see what you mean. I wasn't thinking of robustness as a > technical term but now I see that you are correct. > > Perhaps what I should have said is that whether or not this matters > depends on the problem at hand (hopefully this isn't an important > medical trial) and the particular type of data that you have; assuming > normality is fine in many cases even if the data is not "really" > normal. "Having outliers" literally means that assuming normality is not fine. If assuming normality were fine, then you wouldn't need to remove outliers. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Mon Jan 7 12:58:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2013 17:58:42 GMT Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> Message-ID: <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 07 Jan 2013 15:20:57 +0000, Oscar Benjamin wrote: > There are sometimes good reasons to get a line of best fit by eye. In > particular if your data contains clusters that are hard to separate, > sometimes it's useful to just pick out roughly where you think a line > through a subset of the data is. Cherry picking subsets of your data as well as line fitting by eye? Two wrongs do not make a right. If you're going to just invent a line based on where you think it should be, what do you need the data for? Just declare "this is the line I wish to believe in" and save yourself the time and energy of collecting the data in the first place. Your conclusion will be no less valid. How do you distinguish between "data contains clusters that are hard to separate" from "data doesn't fit a line at all"? Even if the data actually is linear, on what basis could we distinguish between the line you fit by eye (say) y = 2.5x + 3.7, and the line I fit by eye (say) y = 3.1x + 4.1? The line you assert on the basis of purely subjective judgement can be equally denied on the basis of subjective judgement. Anyone can fool themselves into placing a line through a subset of non- linear data. Or, sadly more often, *deliberately* cherry picking fake clusters in order to fool others. Here is a real world example of what happens when people pick out the data clusters that they like based on visual inspection: http://www.skepticalscience.com/images/TempEscalator.gif And not linear by any means, but related to the cherry picking theme: http://www.skepticalscience.com/pics/1_ArcticEscalator2012.gif To put it another way, when we fit patterns to data by eye, we can easily fool ourselves into seeing patterns that aren't there, or missing the patterns which are there. At best line fitting by eye is prone to honest errors; at worst, it is open to the most deliberate abuse. We have eyes and brains that evolved to spot the ripe fruit in trees, not to spot linear trends in noisy data, and fitting by eye is not safe or appropriate. -- Steven From rosuav at gmail.com Mon Jan 7 14:43:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 06:43:46 +1100 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 8, 2013 at 4:58 AM, Steven D'Aprano wrote: > Anyone can fool themselves into placing a line through a subset of non- > linear data. Or, sadly more often, *deliberately* cherry picking fake > clusters in order to fool others. Here is a real world example of what > happens when people pick out the data clusters that they like based on > visual inspection: > > http://www.skepticalscience.com/images/TempEscalator.gif And sensible people will notice that, even drawn like that, it's only a ~0.6 deg increase across ~30 years. Hardly statistically significant, given that weather patterns have been known to follow cycles at least that long. But that's nothing to do with drawing lines through points, and more to do with how much data you collect before you announce a conclusion, and how easily a graph can prove any point you like. Statistical analysis is a huge science. So is lying. And I'm not sure most people can pick one from the other. ChrisA From jason at powerpull.net Tue Jan 8 21:22:51 2013 From: jason at powerpull.net (Jason Friedman) Date: Tue, 8 Jan 2013 19:22:51 -0700 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Statistical analysis is a huge science. So is lying. And I'm not sure > most people can pick one from the other. Chris, your sentence causes me to think of Mr. Twain's sentence, or at least the one he popularized: http://www.twainquotes.com/Statistics.html. From jason at powerpull.net Tue Jan 8 21:23:22 2013 From: jason at powerpull.net (Jason Friedman) Date: Tue, 8 Jan 2013 19:23:22 -0700 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Statistical analysis is a huge science. So is lying. And I'm not sure > most people can pick one from the other. Chris, your sentence causes me to think of Mr. Twain's sentence, or at least the one he popularized: http://www.twainquotes.com/Statistics.html. From oscar.j.benjamin at gmail.com Mon Jan 7 17:32:54 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 7 Jan 2013 22:32:54 +0000 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 7 January 2013 17:58, Steven D'Aprano wrote: > On Mon, 07 Jan 2013 15:20:57 +0000, Oscar Benjamin wrote: > >> There are sometimes good reasons to get a line of best fit by eye. In >> particular if your data contains clusters that are hard to separate, >> sometimes it's useful to just pick out roughly where you think a line >> through a subset of the data is. > > Cherry picking subsets of your data as well as line fitting by eye? Two > wrongs do not make a right. It depends on what you're doing, though. I wouldn't use an eyeball fit to get numbers that were an important part of the conclusion of some or other study. I would very often use it while I'm just in the process of trying to understand something. > If you're going to just invent a line based on where you think it should > be, what do you need the data for? Just declare "this is the line I wish > to believe in" and save yourself the time and energy of collecting the > data in the first place. Your conclusion will be no less valid. An example: Earlier today I was looking at some experimental data. A simple model of the process underlying the experiment suggests that two variables x and y will vary in direct proportion to one another and the data broadly reflects this. However, at this stage there is some non-normal variability in the data, caused by experimental difficulties. A subset of the data appears to closely follow a well defined linear pattern but there are outliers and the pattern breaks down in an asymmetric way at larger x and y values. At some later time either the sources of experimental variation will be reduced, or they will be better understood but for now it is still useful to estimate the constant of proportionality in order to check whether it seems consistent with the observed values of z. With this particular dataset I would have wasted a lot of time if I had tried to find a computational method to match the line that to me was very visible so I chose the line visually. > > How do you distinguish between "data contains clusters that are hard to > separate" from "data doesn't fit a line at all"? > In the example I gave it isn't possible to make that distinction with the currently available data. That doesn't make it meaningless to try and estimate the parameters of the relationship between the variables using the preliminary data. > Even if the data actually is linear, on what basis could we distinguish > between the line you fit by eye (say) y = 2.5x + 3.7, and the line I fit > by eye (say) y = 3.1x + 4.1? The line you assert on the basis of purely > subjective judgement can be equally denied on the basis of subjective > judgement. It gets a bit easier if the line is constrained to go through the origin. You seem to be thinking that the important thing is proving that the line is "real", rather than identifying where it is. Both things are important but not necessarily in the same problem. In my example, the "real line" may not be straight and may not go through the origin, but it is definitely there and if there were no experimental problems then the data would all be very close to it. > Anyone can fool themselves into placing a line through a subset of non- > linear data. Or, sadly more often, *deliberately* cherry picking fake > clusters in order to fool others. Here is a real world example of what > happens when people pick out the data clusters that they like based on > visual inspection: > > http://www.skepticalscience.com/images/TempEscalator.gif > > And not linear by any means, but related to the cherry picking theme: > > http://www.skepticalscience.com/pics/1_ArcticEscalator2012.gif > > > To put it another way, when we fit patterns to data by eye, we can easily > fool ourselves into seeing patterns that aren't there, or missing the > patterns which are there. At best line fitting by eye is prone to honest > errors; at worst, it is open to the most deliberate abuse. We have eyes > and brains that evolved to spot the ripe fruit in trees, not to spot > linear trends in noisy data, and fitting by eye is not safe or > appropriate. This is all true. But the human brain is also in many ways much better than a typical computer program at recognising patterns in data when the data can be depicted visually. I would very rarely attempt to analyse data without representing it in some visual form. I also think it would be highly foolish to go so far with refusing to eyeball data that you would accept the output of some regression algorithm even when it clearly looks wrong. Oscar From steve+comp.lang.python at pearwood.info Mon Jan 7 20:23:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Jan 2013 01:23:31 GMT Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 07 Jan 2013 22:32:54 +0000, Oscar Benjamin wrote: > An example: Earlier today I was looking at some experimental data. A > simple model of the process underlying the experiment suggests that two > variables x and y will vary in direct proportion to one another and the > data broadly reflects this. However, at this stage there is some > non-normal variability in the data, caused by experimental difficulties. > A subset of the data appears to closely follow a well defined linear > pattern but there are outliers and the pattern breaks down in an > asymmetric way at larger x and y values. At some later time either the > sources of experimental variation will be reduced, or they will be > better understood but for now it is still useful to estimate the > constant of proportionality in order to check whether it seems > consistent with the observed values of z. With this particular dataset I > would have wasted a lot of time if I had tried to find a computational > method to match the line that to me was very visible so I chose the line > visually. If you mean: "I looked at the data, identified that the range a < x < b looks linear and the range x > b does not, then used least squares (or some other recognised, objective technique for fitting a line) to the data in that linear range" then I'm completely cool with that. That's fine, with the understanding that this is the first step in either fixing your measurement problems, fixing your model, or at least avoiding extrapolation into the non-linear range. But that is not fitting a line by eye, which is what I am talking about. If on the other hand you mean: "I looked at the data, identified that the range a < x < b looked linear, so I laid a ruler down over the graph and pushed it around until I was satisfied that the ruler looked more or less like it fitted the data points, according to my guess of what counts as a close fit" that *is* fitting a line by eye, and it is entirely subjective and extremely dodgy for anything beyond quick and dirty back of the envelope calculations[1]. That's okay if all you want is to get something within an order of magnitude or so, or a line roughly pointing in the right direction, but that's all. [...] > I also think it would > be highly foolish to go so far with refusing to eyeball data that you > would accept the output of some regression algorithm even when it > clearly looks wrong. I never said anything of the sort. I said, don't fit lines to data by eye. I didn't say not to sanity check your straight line fit is reasonable by eyeballing it. [1] Or if your data is so accurate and noise-free that you hardly have to care about errors, since there clearly is one and only one straight line that passes through all the points. -- Steven From tjreedy at udel.edu Tue Jan 8 04:07:08 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 Jan 2013 04:07:08 -0500 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/7/2013 8:23 PM, Steven D'Aprano wrote: > On Mon, 07 Jan 2013 22:32:54 +0000, Oscar Benjamin wrote: > >> An example: Earlier today I was looking at some experimental data. A >> simple model of the process underlying the experiment suggests that two >> variables x and y will vary in direct proportion to one another and the >> data broadly reflects this. However, at this stage there is some >> non-normal variability in the data, caused by experimental difficulties. >> A subset of the data appears to closely follow a well defined linear >> pattern but there are outliers and the pattern breaks down in an >> asymmetric way at larger x and y values. At some later time either the >> sources of experimental variation will be reduced, or they will be >> better understood but for now it is still useful to estimate the >> constant of proportionality in order to check whether it seems >> consistent with the observed values of z. With this particular dataset I >> would have wasted a lot of time if I had tried to find a computational >> method to match the line that to me was very visible so I chose the line >> visually. > > > If you mean: > > "I looked at the data, identified that the range a < x < b looks linear > and the range x > b does not, then used least squares (or some other > recognised, objective technique for fitting a line) to the data in that > linear range" > > then I'm completely cool with that. If both x and y are measured values, then regressing x on y and y on x with give different answers and both will be wrong in that *neither* will be the best answer for the relationship between them. Oscar did not specify whether either was an experimentally set input variable. > But that is not fitting a line by eye, which is what I am talking about. With the line constrained to go through 0,0, a line eyeballed with a clear ruler could easily be better than either regression line, as a human will tend to minimize the deviations *perpendicular to the line*, which is the proper thing to do (assuming both variables are measured in the same units). -- Terry Jan Reedy From oscar.j.benjamin at gmail.com Tue Jan 8 08:50:59 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 8 Jan 2013 13:50:59 +0000 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8 January 2013 01:23, Steven D'Aprano wrote: > On Mon, 07 Jan 2013 22:32:54 +0000, Oscar Benjamin wrote: > > [...] >> I also think it would >> be highly foolish to go so far with refusing to eyeball data that you >> would accept the output of some regression algorithm even when it >> clearly looks wrong. > > I never said anything of the sort. > > I said, don't fit lines to data by eye. I didn't say not to sanity check > your straight line fit is reasonable by eyeballing it. I should have been a little clearer. That was the situation when I decided to just use a (digital) ruler - although really it was more of a visual bisection (1, 2, 1.5, 1.25...). The regression result was clearly wrong (and also invalid for the reasons Terry has described). Some of the problems were easily fixable and others were not. I could have spent an hour getting the code to make the line go where I wanted it to, or I could just fit the line visually in about 2 minutes. Oscar From maarten.sneep at knmi.nl Tue Jan 8 11:47:52 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Tue, 8 Jan 2013 08:47:52 -0800 (PST) Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7dafc98b-99c9-4727-bdb5-087dc846546c@googlegroups.com> On Tuesday, January 8, 2013 10:07:08 AM UTC+1, Terry Reedy wrote: > With the line constrained to go through 0,0, a line eyeballed with a > clear ruler could easily be better than either regression line, as a > human will tend to minimize the deviations *perpendicular to the line*, > which is the proper thing to do (assuming both variables are measured in > the same units). In that case use an appropriate algorithm to perform the fit. ODR comes to mind. http://docs.scipy.org/doc/scipy/reference/odr.html Maarten From maarten.sneep at knmi.nl Tue Jan 8 11:47:52 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Tue, 8 Jan 2013 08:47:52 -0800 (PST) Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7dafc98b-99c9-4727-bdb5-087dc846546c@googlegroups.com> On Tuesday, January 8, 2013 10:07:08 AM UTC+1, Terry Reedy wrote: > With the line constrained to go through 0,0, a line eyeballed with a > clear ruler could easily be better than either regression line, as a > human will tend to minimize the deviations *perpendicular to the line*, > which is the proper thing to do (assuming both variables are measured in > the same units). In that case use an appropriate algorithm to perform the fit. ODR comes to mind. http://docs.scipy.org/doc/scipy/reference/odr.html Maarten From steve+comp.lang.python at pearwood.info Tue Jan 8 19:02:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Jan 2013 00:02:11 GMT Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7513$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ecb382$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 08 Jan 2013 04:07:08 -0500, Terry Reedy wrote: >> But that is not fitting a line by eye, which is what I am talking >> about. > > With the line constrained to go through 0,0 a line eyeballed with a > clear ruler could easily be better than either regression line, as a > human will tend to minimize the deviations *perpendicular to the line*, > which is the proper thing to do (assuming both variables are measured > in the same units). It is conventional to talk about "residuals" rather than deviations. And it could even more easily be worse than a regression line. And since eyeballing is entirely subjective and impossible to objectively verify, the line that you claim minimizes the residuals might be very different from the line that I claim minimizes the residuals, and no way to decide between the two claims. In any case, there is a technique for working out ordinary least squares (OLS) linear regression using perpendicular offsets rather than vertical offsets: http://mathworld.wolfram.com/LeastSquaresFittingPerpendicularOffsets.html but in general, if you have to care about errors in the dependent variable, you're better off using a more powerful technique than just OLS. The point I keep making, that everybody seems to be ignoring, is that eyeballing a line of best fit is subjective, unreliable and impossible to verify. How could I check that the line you say is the "best fit" actually *is* the *best fit* for the given data, given that you picked that line by eye? Chances are good that if you came back to the data a month later, you'd pick a different line! As I have said, eyeballing a line is fine for rough back of the envelope type calculations, where you only care that you have a line pointing more or less in the right direction. But for anything where accuracy is required, line fitting by eye is down in the pits of things not to do, right next to "making up the answers you prefer". -- Steven From steve+comp.lang.python at pearwood.info Mon Jan 7 21:06:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Jan 2013 02:06:35 GMT Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50eb7f2a$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 08 Jan 2013 06:43:46 +1100, Chris Angelico wrote: > On Tue, Jan 8, 2013 at 4:58 AM, Steven D'Aprano > wrote: >> Anyone can fool themselves into placing a line through a subset of non- >> linear data. Or, sadly more often, *deliberately* cherry picking fake >> clusters in order to fool others. Here is a real world example of what >> happens when people pick out the data clusters that they like based on >> visual inspection: >> >> http://www.skepticalscience.com/images/TempEscalator.gif > > And sensible people will notice that, even drawn like that, it's only a > ~0.6 deg increase across ~30 years. Hardly statistically significant, Well, I don't know about "sensible people", but magnitude of an effect has little to do with whether or not something is statistically significant or not. Given noisy data, statistical significance relates to whether or not we can be confident that the effect is *real*, not whether it is a big effect or a small effect. Here's an example: assume that you are on a fixed salary with a constant weekly income. If you happen to win the lottery one day, and consequently your income for that week quadruples, that is a large effect that fails to have any statistical significance -- it's a blip, not part of any long- term change in income. You can't conclude that you'll win the lottery every week from now on. On the other hand, if the government changes the rules relating to tax, deductions, etc., even by a small amount, your weekly income might go down, or up, by a single dollar. Even though that is a tiny effect, it is *not* a blip, and will be statistically significant. In practice, it takes a certain number of data points to reach that confidence level. Your accountant, who knows the tax laws, will conclude that the change is real immediately, but a statistician who sees only the pay slips may take some months before she is convinced that the change is signal rather than noise. With only three weeks pay slips in hand, the statistician cannot be sure that the difference is not just some accounting error or other fluke, but each additional data point increases the confidence that the difference is real and not just some temporary aberration. The other meaning of "significant" has nothing to do with statistics, and everything to do with "a difference is only a difference if it makes a difference". 0.2? per decade doesn't sound like much, not when we consider daily or yearly temperatures that typically have a range of tens of degrees between night and day, or winter and summer. But that is misunderstanding the nature of long-term climate versus daily weather and glossing over the fact that we're only talking about an average and ignoring changes to the variability of the climate: a small increase in average can lead to a large increase in extreme events. > given that weather patterns have been known to follow cycles at least > that long. That is not a given. "Weather patterns" don't last for thirty years. Perhaps you are talking about climate patterns? In which case, well, yes, we can see a very strong climate pattern of warming on a time scale of decades, with no evidence that it is a cycle. There are, of course, many climate cycles that take place on a time frame of years or decades, such as the North Atlantic Oscillation and the El Nino Southern Oscillation. None of them are global, and as far as I know none of them are exactly periodic. They are noise in the system, and certainly not responsible for linear trends. -- Steven From rosuav at gmail.com Tue Jan 8 01:35:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 17:35:33 +1100 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: <50eb7f2a$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7f2a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 8, 2013 at 1:06 PM, Steven D'Aprano wrote: >> given that weather patterns have been known to follow cycles at least >> that long. > > That is not a given. "Weather patterns" don't last for thirty years. > Perhaps you are talking about climate patterns? Yes, that's what I meant. In any case, debate about global warming is quite tangential to the point about statistical validity; it looks quite significant to show a line going from the bottom of the graph to the top, but sounds a lot less noteworthy when you see it as a half-degree increase on about (I think?) 30 degrees, and even less when you measure temperatures in absolute scale (Kelvin) and it's half a degree in three hundred. Those are principles worth considering, regardless of the subject matter. If your railway tracks have widened by a full eight millimeters due to increased pounding from heavier vehicles travelling over it, that's significant and dangerous on HO-scale model trains, but utterly insignificant on 5'3" gauge. ChrisA From robert.kern at gmail.com Tue Jan 8 10:55:30 2013 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 08 Jan 2013 15:55:30 +0000 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7f2a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/01/2013 06:35, Chris Angelico wrote: > On Tue, Jan 8, 2013 at 1:06 PM, Steven D'Aprano > wrote: >>> given that weather patterns have been known to follow cycles at least >>> that long. >> >> That is not a given. "Weather patterns" don't last for thirty years. >> Perhaps you are talking about climate patterns? > > Yes, that's what I meant. In any case, debate about global warming is > quite tangential to the point about statistical validity; it looks > quite significant to show a line going from the bottom of the graph to > the top, but sounds a lot less noteworthy when you see it as a > half-degree increase on about (I think?) 30 degrees, and even less > when you measure temperatures in absolute scale (Kelvin) and it's half > a degree in three hundred. Why on Earth do you think that the distance from nominal surface temperatures to freezing much less absolute 0 is the right scale to compare global warming changes against? You need to compare against the size of global mean temperature changes that would cause large amounts of human suffering, and that scale is on the order of a *few* degrees, not hundreds. A change of half a degree over a few decades with no signs of slowing down *should* be alarming. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rosuav at gmail.com Tue Jan 8 15:14:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Jan 2013 07:14:51 +1100 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7f2a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 9, 2013 at 2:55 AM, Robert Kern wrote: > On 08/01/2013 06:35, Chris Angelico wrote: >> ... it looks >> quite significant to show a line going from the bottom of the graph to >> the top, but sounds a lot less noteworthy when you see it as a >> half-degree increase on about (I think?) 30 degrees, and even less >> when you measure temperatures in absolute scale (Kelvin) and it's half >> a degree in three hundred. > > Why on Earth do you think that the distance from nominal surface > temperatures to freezing much less absolute 0 is the right scale to compare > global warming changes against? You need to compare against the size of > global mean temperature changes that would cause large amounts of human > suffering, and that scale is on the order of a *few* degrees, not hundreds. > A change of half a degree over a few decades with no signs of slowing down > *should* be alarming. I didn't say what it should be; I gave three examples. And as I said, this is not the forum to debate climate change; I was just using it as an example of statistical reporting. Three types of lies. ChrisA From robert.kern at gmail.com Tue Jan 8 17:59:06 2013 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 08 Jan 2013 22:59:06 +0000 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7f2a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/01/2013 20:14, Chris Angelico wrote: > On Wed, Jan 9, 2013 at 2:55 AM, Robert Kern wrote: >> On 08/01/2013 06:35, Chris Angelico wrote: >>> ... it looks >>> quite significant to show a line going from the bottom of the graph to >>> the top, but sounds a lot less noteworthy when you see it as a >>> half-degree increase on about (I think?) 30 degrees, and even less >>> when you measure temperatures in absolute scale (Kelvin) and it's half >>> a degree in three hundred. >> >> Why on Earth do you think that the distance from nominal surface >> temperatures to freezing much less absolute 0 is the right scale to compare >> global warming changes against? You need to compare against the size of >> global mean temperature changes that would cause large amounts of human >> suffering, and that scale is on the order of a *few* degrees, not hundreds. >> A change of half a degree over a few decades with no signs of slowing down >> *should* be alarming. > > I didn't say what it should be; Actually, you did. You stated that "a ~0.6 deg increase across ~30 years [is h]ardly statistically significant". Ignoring the confusion between statistical significance and practical significance (as external criteria like the difference between the nominal temp and absolute 0 or the right criteria that I mentioned has nothing to do with statistical significance), you made a positive claim that it wasn't significant. > I gave three examples. You gave negligently incorrect ones. Whether your comments were on topic or not, you deserve to be called on them when they are wrong. > And as I said, > this is not the forum to debate climate change; I was just using it as > an example of statistical reporting. > > Three types of lies. FUD is a fourth. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Wed Jan 9 02:50:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Jan 2013 07:50:45 GMT Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] References: <50ea28e7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ea58f0$0$21851$c3e8da3$76491128@news.astraweb.com> <50eb0cd2$0$30003$c3e8da3$5496439d@news.astraweb.com> <50eb7f2a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ed2154$0$29898$c3e8da3$5496439d@news.astraweb.com> On Wed, 09 Jan 2013 07:14:51 +1100, Chris Angelico wrote: > Three types of lies. Oh, surely more than that. White lies. Regular or garden variety lies. Malicious lies. Accidental or innocent lies. FUD -- "fear, uncertainty, doubt". Half-truths. Lying by omission. Exaggeration and understatement. Propaganda. Misinformation. Disinformation. Deceit by emphasis. And manufactured doubt. E.g. the decades long campaign by the tobacco companies to deny that tobacco products caused cancer, when their own scientists were telling them that they did. Having learnt how valuable falsehoods are, those same manufacturers of doubt went on to sell their services to those who wanted to deny that CFCs destroyed ozone, and that CO2 causes warming. The old saw about "lies, damned lies and statistics" reminds me very much of a quote from Homer Simpson: "Pfff, facts, you can prove anything that's even remotely true with facts!" -- Steven From alan.spence at ntlworld.com Fri Jan 11 09:30:30 2013 From: alan.spence at ntlworld.com (Alan Spence) Date: Fri, 11 Jan 2013 14:30:30 +0000 Subject: [Offtopic] Line fitting [was Re: Numpy outlier removal] In-Reply-To: <50EF46F9.7020408@pearwood.info> References: <50EE93D2.4030504@tobix.eu> <50EE944C.7060102@tobix.eu> <50EEB002.6030904@pearwood.info> <50EF46F9.7020408@pearwood.info> Message-ID: <8C9BB585-C35A-47D0-A7A7-76B37E40F1BD@ntlworld.com> On 09 Jan 2013, at 00:02:11 Steven D'Aprano wrote: > The point I keep making, that everybody seems to be ignoring, is that > eyeballing a line of best fit is subjective, unreliable and impossible to > verify. How could I check that the line you say is the "best fit" > actually *is* the *best fit* for the given data, given that you picked > that line by eye? Chances are good that if you came back to the data a > month later, you'd pick a different line! It might bring more insight to the debate if you talk about parameter error and model error. Steven is correct if you consider only parameter error. However model error is often the main problem, and here using visual techniques might well improve your model selection even if it's not a real model but a visually based approximation to a model. However, if you only do it by eye, you end up in a space which is not rigorous from a modelling perspective and other issues can arise from this. Visual techniques might also help deal with outliers but again in an unrigorous manner. Visual techniques can also bring in real world knowledge (but this is really the same point as model selection). With regard to the original post on outliers, Steven made a lot of excellent points. However there are at least two important issues which he didn't mention. (1) You must think carefully and hard about the outliers. For example, can they recur, or have actions in the real world been taken that mean they can't happen again? Are they actually data errors? How you deal with them might be changed by these types of consideration. (2) It is best to fit your model with and without the outliers and see what impact it has on the real world application you're doing the analysis for. It's also good to try more than one set of excluded outliers to see just how stable the results are depending on how many outliers you remove. If the results change much, be very careful how you use the results. Alan From ghanashirts4sale at gmail.com Sun Jan 6 15:26:40 2013 From: ghanashirts4sale at gmail.com (kofi) Date: Sun, 6 Jan 2013 12:26:40 -0800 (PST) Subject: How do you call a function several times in this context?? Message-ID: <76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com> Using python 3.1, I have written a function called "isEvenDigit" Below is the code for the "isEvenDigit" function: def isEvenDigit(): ste=input("Please input a single character string: ") li=["0","2","4", "6", "8"] if ste in li: print("True") else: print("False") I am now trying to write a function that takes a string as an argument and makes several calls to the isEvenDigit function in order to calculate and return the number of even digits in the string.How do i do this please? This is what i have done so far. def isEvenDigit2(): number = input("Enter a digit: ") From benjamin.kaplan at case.edu Sun Jan 6 15:39:21 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 6 Jan 2013 12:39:21 -0800 Subject: How do you call a function several times in this context?? In-Reply-To: <76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com> References: <76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com> Message-ID: On Jan 6, 2013 12:33 PM, "kofi" wrote: > > Using python 3.1, I have written a function called "isEvenDigit" > > Below is the code for the "isEvenDigit" function: > > def isEvenDigit(): > ste=input("Please input a single character string: ") > li=["0","2","4", "6", "8"] > if ste in li: > print("True") > else: > print("False") > > I am now trying to write a function that takes a string as an argument and makes several calls to the isEvenDigit function in order to calculate and return the number of even digits in the string.How do i do this please? This is what i have done so far. > > def isEvenDigit2(): > number = input("Enter a digit: ") Use a loop and call the function in the body of the loop. In this case, you would use a for loop iterating over number. If you don't know how to use a for loop, I recommend you do the tutorial at http://docs.python.org/3.3/tutorial/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.ware at ntlworld.com Sun Jan 6 16:23:32 2013 From: alister.ware at ntlworld.com (Alister) Date: Sun, 06 Jan 2013 21:23:32 GMT Subject: How do you call a function several times in this context?? References: <76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com> Message-ID: On Sun, 06 Jan 2013 12:26:40 -0800, kofi wrote: > Using python 3.1, I have written a function called "isEvenDigit" > > Below is the code for the "isEvenDigit" function: > > def isEvenDigit(): > ste=input("Please input a single character string: ") > li=["0","2","4", "6", "8"] > if ste in li: > print("True") > else: > print("False") > > I am now trying to write a function that takes a string as an argument > and makes several calls to the isEvenDigit function in order to > calculate and return the number of even digits in the string.How do i do > this please? This is what i have done so far. > > def isEvenDigit2(): > number = input("Enter a digit: ") you need to investigate passing parameters to and from function as you are obviously a beginner I don't want to give you the answer to your task but hopefully steer you in the right direction. examine the code below & see if you can understand how it is working & how to apply it to your current project def double(value): result return result number=input('type a number') print (double(int(number))) this program is for explanation only and a function this simple should never be used in a real program, it is functionally equivalent to number=input('type a number') print (int(number)*2) -- Alex Haley was adopted! From jason at powerpull.net Sun Jan 6 16:33:26 2013 From: jason at powerpull.net (Jason Friedman) Date: Sun, 6 Jan 2013 14:33:26 -0700 Subject: How do you call a function several times in this context?? In-Reply-To: References: <76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com> Message-ID: > def double(value): > result > return result > > number=input('type a number') > print (double(int(number))) > I think what was meant: def double(value): result = 2 * value return result From joel.goldstick at gmail.com Sun Jan 6 17:01:21 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 6 Jan 2013 17:01:21 -0500 Subject: How do you call a function several times in this context?? In-Reply-To: References: <76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com> Message-ID: On Sun, Jan 6, 2013 at 4:33 PM, Jason Friedman wrote: > > def double(value): > > result > > return result > > > > number=input('type a number') > > print (double(int(number))) > > > > I think what was meant: > > def double(value): > result = 2 * value > return result > -- > http://mail.python.org/mailman/listinfo/python-list > #get the string of numbers outside your function: is_even number = input("type an integer') #Here is some code to loop through each digit for n in number: is_even_digit(n) # this function should test the number and print what you want for odd and even #This will pass each digit to your function. I renamed your function to reflect better python naming conventions -- Joel Goldstick -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.ware at ntlworld.com Sun Jan 6 17:35:55 2013 From: alister.ware at ntlworld.com (Alister) Date: Sun, 06 Jan 2013 22:35:55 GMT Subject: How do you call a function several times in this context?? References: <76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com> Message-ID: On Sun, 06 Jan 2013 14:33:26 -0700, Jason Friedman wrote: >> def double(value): >> result return result >> >> number=input('type a number') >> print (double(int(number))) >> >> > I think what was meant: > > def double(value): > result = 2 * value return result yes indeed thanks for correcting my typo -- Quigley's Law: Whoever has any authority over you, no matter how small, will atttempt to use it. From andydtaylor at gmail.com Sun Jan 6 16:38:29 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Sun, 6 Jan 2013 13:38:29 -0800 (PST) Subject: psycopg2 cursor.execute CREATE TABLE issue Message-ID: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> Hi all, I'm trying to create a process which will create a new table and populate it. But something is preventing this from working, and I don't know enough to figure it out, despite having spent most of today reading up. The code executes with no error, yet no table is created or populated. Can anyone offer me some advice? code below. Thanks, Andy #!/usr/bin/python import psycopg2 import sys def main(): db = psycopg2.connect( host = 'localhost', database = 'gisdb', user = 'postgres', password = 'L1ncoln0ut@' ) cursor = db.cursor() cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);") cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, "abc'def")) if __name__ == "__main__": main() From msirenef at lightbird.net Sun Jan 6 16:44:47 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 06 Jan 2013 16:44:47 -0500 Subject: psycopg2 cursor.execute CREATE TABLE issue In-Reply-To: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> Message-ID: <50E9F04F.7030802@lightbird.net> On Sun 06 Jan 2013 04:38:29 PM EST, andydtaylor at gmail.com wrote: > Hi all, > > I'm trying to create a process which will create a new table and populate it. > > But something is preventing this from working, and I don't know enough to figure it out, despite having spent most of today reading up. The code executes with no error, yet no table is created or populated. > > Can anyone offer me some advice? code below. > > Thanks, > > Andy > > #!/usr/bin/python > import psycopg2 > import sys > > def main(): > db = psycopg2.connect( > host = 'localhost', > database = 'gisdb', > user = 'postgres', > password = 'L1ncoln0ut@' > ) > cursor = db.cursor() > cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);") > cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, "abc'def")) > > if __name__ == "__main__": > main() To commit a transaction, you need to do a db.commit() call. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From rosuav at gmail.com Sun Jan 6 16:45:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 08:45:51 +1100 Subject: psycopg2 cursor.execute CREATE TABLE issue In-Reply-To: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> Message-ID: On Mon, Jan 7, 2013 at 8:38 AM, wrote: > But something is preventing this from working, and I don't know enough to figure it out, despite having spent most of today reading up. The code executes with no error, yet no table is created or populated. Standard databasing requirement: You need to commit your work. http://initd.org/psycopg/docs/connection.html#connection.commit Otherwise, the transaction gets rolled back, and nobody sees your changes. ChrisA From andydtaylor at gmail.com Sun Jan 6 16:53:32 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Sun, 6 Jan 2013 13:53:32 -0800 (PST) Subject: psycopg2 cursor.execute CREATE TABLE issue In-Reply-To: References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> Message-ID: <10bc4895-21e3-4a56-84fd-b0830e42acfa@googlegroups.com> Wow it's as simple as that! I'm afraid my database experience is in Microsoft Access in Windows and not at the command line, so that wasn't intuitive for me. Thanks again, Andy From msirenef at lightbird.net Sun Jan 6 17:14:34 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 06 Jan 2013 17:14:34 -0500 Subject: psycopg2 cursor.execute CREATE TABLE issue In-Reply-To: <10bc4895-21e3-4a56-84fd-b0830e42acfa@googlegroups.com> References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> <10bc4895-21e3-4a56-84fd-b0830e42acfa@googlegroups.com> Message-ID: <50E9F74A.70107@lightbird.net> On Sun 06 Jan 2013 04:53:32 PM EST, andydtaylor at gmail.com wrote: > Wow it's as simple as that! I'm afraid my database experience is in Microsoft Access in Windows and not at the command line, so that wasn't intuitive for me. > > Thanks again, > > Andy IIRC I made the same mistake when I was using psycopg for the first time. I think wrapper libraries like sqlalchemy usually have myrecord.save() method which is more intuitive. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From rosuav at gmail.com Sun Jan 6 17:19:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 09:19:50 +1100 Subject: psycopg2 cursor.execute CREATE TABLE issue In-Reply-To: <50E9F74A.70107@lightbird.net> References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> <10bc4895-21e3-4a56-84fd-b0830e42acfa@googlegroups.com> <50E9F74A.70107@lightbird.net> Message-ID: On Mon, Jan 7, 2013 at 9:14 AM, Mitya Sirenef wrote: > On Sun 06 Jan 2013 04:53:32 PM EST, andydtaylor at gmail.com wrote: >> >> Wow it's as simple as that! I'm afraid my database experience is in >> Microsoft Access in Windows and not at the command line, so that wasn't >> intuitive for me. >> > IIRC I made the same mistake when I was using psycopg for the first time. > I think wrapper libraries like sqlalchemy usually have myrecord.save() > method which is more intuitive. I recommend getting used to thinking in terms of transactions and commits. Instead of saving a record, commit a unit of work, which might involve several changes all at once. A good database (like PostgreSQL) will guarantee you that either the whole transaction has happened, or none of it has. And normally, once your commit call has returned (assuming it doesn't raise an error), you're guaranteed that the transaction has been completely written to durable storage. Of course, that depends on *having* durable storage, and many SSDs lie about what's been written, but that's outside the scope of this post! ChrisA From andydtaylor at gmail.com Sun Jan 6 16:53:32 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Sun, 6 Jan 2013 13:53:32 -0800 (PST) Subject: psycopg2 cursor.execute CREATE TABLE issue In-Reply-To: References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> Message-ID: <10bc4895-21e3-4a56-84fd-b0830e42acfa@googlegroups.com> Wow it's as simple as that! I'm afraid my database experience is in Microsoft Access in Windows and not at the command line, so that wasn't intuitive for me. Thanks again, Andy From walterhurry at lavabit.com Sun Jan 6 17:37:55 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Sun, 6 Jan 2013 22:37:55 +0000 (UTC) Subject: psycopg2 cursor.execute CREATE TABLE issue References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> Message-ID: On Sun, 06 Jan 2013 16:44:47 -0500, Mitya Sirenef wrote: > On Sun 06 Jan 2013 04:38:29 PM EST, andydtaylor at gmail.com wrote: >> Hi all, >> >> I'm trying to create a process which will create a new table and >> populate it. >> >> But something is preventing this from working, and I don't know enough >> to figure it out, despite having spent most of today reading up. The >> code executes with no error, yet no table is created or populated. >> >> Can anyone offer me some advice? code below. >> >> Thanks, >> >> Andy >> >> #!/usr/bin/python import psycopg2 import sys >> >> def main(): >> db = psycopg2.connect( >> host = 'localhost', database = 'gisdb', user = 'postgres', >> password = 'L1ncoln0ut@' >> ) >> cursor = db.cursor() >> cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num >> integer, data varchar);") >> cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, >> "abc'def")) >> >> if __name__ == "__main__": >> main() > > > To commit a transaction, you need to do a db.commit() call. Or set autocommit = True on the database connection object From yacinechaouche at yahoo.com Sun Jan 6 18:12:11 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Sun, 6 Jan 2013 15:12:11 -0800 (PST) Subject: Over 30 types of variables available in python ? Message-ID: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> booleans ints, floats, longs, complexes strings, unicode strings lists, tuples, dictionaries, dictionary views, sets, frozensets, buffers, bytearrays, slices functions, methods, code objects,modules,classes, instances, types, nulls (there is exactly one object of type Null which is None), tracebacks, frames generators, iterators, xranges, files, memoryviews, context managers, These are all listed in this page http://docs.python.org/2/library/stdtypes.html as built-in types. Am I getting anything wrong here ? I'm a bit confused about it. I have never seen so many types in the few programming languages I saw. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Jan 6 18:22:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Jan 2013 10:22:39 +1100 Subject: Over 30 types of variables available in python ? In-Reply-To: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: On Mon, Jan 7, 2013 at 10:12 AM, chaouche yacine wrote: > > booleans > ints, floats, longs, complexes > strings, unicode strings > lists, tuples, dictionaries, dictionary views, sets, frozensets, buffers, > bytearrays, slices > functions, methods, code objects,modules,classes, instances, types, nulls > (there is exactly one object of type Null which is None), tracebacks, frames > generators, iterators, xranges, > files, > memoryviews, > context managers, > > These are all listed in this page > http://docs.python.org/2/library/stdtypes.html as built-in types. Am I > getting anything wrong here ? I'm a bit confused about it. I have never seen > so many types in the few programming languages I saw. Not quite. Python has one type of variable: the name binding. Those are different types of objects. Since you can subclass object to make your own class, there's an infinite number of types available. But the ones you'll be using in most programs are: * boolean, int, float (and long, in Python 2, but in Python 3 that's the same as int) * Unicode strings * In Python 2, bytes strings * lists, tuples, dicts, maybe sets * functions * files The rest, you're unlikely to worry much about. The program will use them under the covers, but you don't need to concern yourself with the details. The only other thing you'll need to look at is the generic handling of object() and, by virtue of subclassing, every other object. ChrisA From d at davea.name Sun Jan 6 18:32:07 2013 From: d at davea.name (Dave Angel) Date: Sun, 06 Jan 2013 18:32:07 -0500 Subject: Over 30 types of variables available in python ? In-Reply-To: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: <50EA0977.5090105@davea.name> On 01/06/2013 06:12 PM, chaouche yacine wrote: > booleans > ints, floats, longs, complexes > strings, unicode strings > lists, tuples, dictionaries, dictionary views, sets, frozensets, buffers, bytearrays, slices > functions, methods, code objects,modules,classes, instances, types, nulls (there is exactly one object of type Null which is None), tracebacks, frames > generators, iterators, xranges, > files, > > memoryviews, > context managers, > > These are all listed in this page http://docs.python.org/2/library/stdtypes.html as built-in types. Am I getting anything wrong here ? I'm a bit confused about it. I have never seen so many types in the few programming languages I saw. > First, you're describing Python 2.x ; 3.x is different in a few ways. For one, int and long are combined into a single type. Variables don't have types. Only objects have types. A name can be bound to any object, regardless of its type, or to what it might have been previously bound. Otherwise, you're right. Python is a rich language, with "batteries included." There's a lot in the built-in space, but if you include the stdlib, it's really rich. And if you include the fact that objects you define yourself are first-class, there are very few limits. -- DaveA From tjreedy at udel.edu Sun Jan 6 19:45:38 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 06 Jan 2013 19:45:38 -0500 Subject: Over 30 types of variables available in python ? In-Reply-To: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: On 1/6/2013 6:12 PM, chaouche yacine wrote: > > booleans > ints, floats, longs, complexes > strings, unicode strings > lists, tuples, dictionaries, dictionary views, sets, frozensets, > buffers, bytearrays, slices > functions, methods, code objects,modules,classes, instances, types, > nulls (there is exactly one object of type Null which is None), > tracebacks, frames > generators, iterators, xranges, > files, > memoryviews, > context managers, > > These are all listed in this page > http://docs.python.org/2/library/stdtypes.html as built-in types. They would better be called classes. Every thing is Python is an instance of a class. 'Iterator' and 'context manager' are protocols that multiple classes can follow, not classes themselves. > Am I > getting anything wrong here ? I'm a bit confused about it. I have never > seen so many types in the few programming languages I saw. C has up to 8 integer types, Python 3 just 1. Most of the above are structures in C, which may or may not by typedef-ed, or classes in C++. If you counted all the structures and classes that come with C or C++, you would find a comparable number. C stdlib has a pointer to file structure type, which is equivalent to Python's file class. It is true that C does not come with hashed arrays (sets) and hashed associative arrays (dicts), but they are often needed. So C programmers either reinvent the wheel or include a third-party library. C also has frame structure, but they are normally hidden. C programmers do not have easy direct access. However, virus writers learn to work with them ;-(. -- Terry Jan Reedy From yacinechaouche at yahoo.com Mon Jan 7 03:53:26 2013 From: yacinechaouche at yahoo.com (chaouche yacine) Date: Mon, 7 Jan 2013 00:53:26 -0800 (PST) Subject: Over 30 types of variables available in python ? In-Reply-To: References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: <1357548806.71297.YahooMailNeo@web125501.mail.ne1.yahoo.com> Thanks for all your comments. It appears to me that there is a slight confusion between types and classes then, plus other entities (protocols ?) So my question is : is there a notion of "type" in python, like in other languages (integers, booleans, floats, strings, characters (in c)) ? if so, can you give a list of the available "types" ? The documentation (http://docs.python.org/2/library/stdtypes.html) states "The principal built-in types are numerics, sequences, mappings, files, classes, instances and exceptions." ________________________________ From: Terry Reedy To: python-list at python.org Sent: Monday, January 7, 2013 1:45 AM Subject: Re: Over 30 types of variables available in python ? On 1/6/2013 6:12 PM, chaouche yacine wrote: > > booleans > ints, floats, longs, complexes > strings, unicode strings > lists, tuples, dictionaries, dictionary views, sets, frozensets, > buffers, bytearrays, slices > functions, methods, code objects,modules,classes, instances, types, > nulls (there is exactly one object of type Null which is None), > tracebacks, frames > generators, iterators, xranges, > files, > memoryviews, > context managers, > > These are all listed in this page > http://docs.python.org/2/library/stdtypes.html as built-in types. They would better be called classes. Every thing is Python is an instance of a class. 'Iterator' and 'context manager' are protocols that multiple classes can follow, not classes themselves. > Am I > getting anything wrong here ? I'm a bit confused about it. I have never > seen so many types in the few programming languages I saw. C has up to 8 integer types, Python 3 just 1. Most of the above are structures in C, which may or may not by typedef-ed, or classes in C++. If you counted all the structures and classes that come with C or C++, you would find a comparable number. C stdlib has a pointer to file structure type, which is equivalent to Python's file class. It is true that C does not come with hashed arrays (sets) and hashed associative arrays (dicts), but they are often needed. So C programmers either reinvent the wheel or include a third-party library. C also has frame structure, but they are normally hidden. C programmers do not have easy direct access. However, virus writers learn to work with them ;-(. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Jan 7 04:52:02 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2013 09:52:02 GMT Subject: Over 30 types of variables available in python ? References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: <50ea9ac2$0$21851$c3e8da3$76491128@news.astraweb.com> On Mon, 07 Jan 2013 00:53:26 -0800, chaouche yacine wrote: > Thanks for all your comments. It appears to me that there is a slight > confusion between types and classes then, plus other entities (protocols > ?) In Python 3, types and classes are synonyms. They mean the same thing. In Python 2, there is a very subtle difference, due to the existence of "old style" or "classic" classes, for backward compatibility, which are not identical to "new style" classes, also known as types. But they are a "kind of type" -- although there are some differences, you can consider them to be the same sort of thing. > So my question is : is there a notion of "type" in python, like in other > languages (integers, booleans, floats, strings, characters (in c)) ? if > so, can you give a list of the available "types" ? Yes, and no. Yes, there is a notation of type in Python which is exactly the same sort of notation of type in other languages, such as C. The difference between C and Python is not in the notation of "type", but in the notation of "variable" or "name". In C, *variables* have a type. If you declare a variable x to be a float, then three things happen: * the C compiler creates a fixed memory location and calls it "x"; * the C compiler interprets the *value* of that memory location (which is actually just a bunch of bytes) as a float; * the C compiler will only ever place values into that memory location if it thinks that the value is a float, or compatible with a float. Because all values are bunches of bytes, you can (with a bit of effort) grab the bytes from any location, without caring what the type the compiler considers it. Sometimes this is useful; more often it is a source of bugs. In Python, *names* have no type, but *objects* (values) do. Because names are untyped, the one name (say, x) might be store a float one minute, then later have a list assigned to it, then a string, then a float again. But at any instant, whatever the value of x, it is an object, and objects always have a type no matter what name they are bound to. The type information is *part of the object*, rather than part of the name. Because Python considers all objects to be typed, there is no concept of extracting the raw bytes from a list. (Of course lists actually are made out of bytes, but you cannot access them from pure Python code.) So, yes, Python has types, just as C has types, but the difference is that Python associates the type with the *value* (object) rather than a storage location (variable). But no, we can't give a complete list of all types, because there is no limit to the number of types. There are a certain number of built-in types, plus many more types which are available from the standard library, plus an infinite number of custom types you can create yourself. You can get a list of the common built-in types and the standard library types from the Fine Manual: http://docs.python.org/2/library/ See also: http://docs.python.org/2/reference/datamodel.html There are also built-in types which are essentially undocumented, and used as implementation details of higher-level objects like functions, methods, and so forth. You are not expected to use these directly. Instead, you just use the function itself. If you are unfamiliar with Object Oriented Programming, you can broadly speaking consider types to be like smart structs that carry code around with them. There is no limit to the number of possible structs, and likewise there is no limit to the number of possible types. > The documentation (http://docs.python.org/2/library/stdtypes.html) > states "The principal built-in types are numerics, sequences, mappings, > files, classes, instances and exceptions." Yes, they are the principal types, but there are many others. There are three different built-in numeric types: int long float plus Decimal and Fraction in the standard library; There are two standard built-in sequence types: list tuple plus others in the standard library, such as namedtuple; There is one standard built-in mapping type: dict plus at least two more in the standard library, defaultdict and ordereddict; etc. You can read the docs more easily than I can copy the types out. -- Steven From marduk at python.net Mon Jan 7 09:32:33 2013 From: marduk at python.net (marduk) Date: Mon, 07 Jan 2013 09:32:33 -0500 Subject: Over 30 types of variables available in python ? In-Reply-To: <50ea9ac2$0$21851$c3e8da3$76491128@news.astraweb.com> References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> <50ea9ac2$0$21851$c3e8da3$76491128@news.astraweb.com> Message-ID: <1357569153.3330.140661174432761.5D8246E9@webmail.messagingengine.com> So I guess if one *really* wanted to compare C variables to Python variables, you could say that all python variables are of type void* except Python does all mallocs/frees and the casting for you. From d at davea.name Mon Jan 7 09:45:28 2013 From: d at davea.name (Dave Angel) Date: Mon, 07 Jan 2013 09:45:28 -0500 Subject: Over 30 types of variables available in python ? In-Reply-To: <1357569153.3330.140661174432761.5D8246E9@webmail.messagingengine.com> References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> <50ea9ac2$0$21851$c3e8da3$76491128@news.astraweb.com> <1357569153.3330.140661174432761.5D8246E9@webmail.messagingengine.com> Message-ID: <50EADF88.10605@davea.name> On 01/07/2013 09:32 AM, marduk wrote: > So I guess if one *really* wanted to compare C variables to Python > variables, you could say that all python variables are of type void* > except Python does all mallocs/frees and the casting for you. A better analogy would be to C++, and all names would be something like shared_ptr. And (except for old-style classes) all actual data is of a type derived from object. -- DaveA From rosuav at gmail.com Mon Jan 7 09:59:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 01:59:52 +1100 Subject: Over 30 types of variables available in python ? In-Reply-To: <50EADF88.10605@davea.name> References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> <50ea9ac2$0$21851$c3e8da3$76491128@news.astraweb.com> <1357569153.3330.140661174432761.5D8246E9@webmail.messagingengine.com> <50EADF88.10605@davea.name> Message-ID: On Tue, Jan 8, 2013 at 1:45 AM, Dave Angel wrote: > On 01/07/2013 09:32 AM, marduk wrote: >> So I guess if one *really* wanted to compare C variables to Python >> variables, you could say that all python variables are of type void* >> except Python does all mallocs/frees and the casting for you. > > A better analogy would be to C++, and all names would be something like > shared_ptr. And (except for old-style classes) all actual data > is of a type derived from object. But yes, a C pointer variable is closest to a Python local, with actual content always stored on the heap. ChrisA From rantingrickjohnson at gmail.com Fri Jan 11 00:20:05 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 10 Jan 2013 21:20:05 -0800 (PST) Subject: Over 30 types of variables available in python ? In-Reply-To: References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: <732cd13e-34f6-4dfc-a49e-c7607e9de21d@googlegroups.com> > On 1-7-2013 2:53:26 AM UTC-6, chaouche yacine wrote: > > Thanks for all your comments. It appears to me that there > is a slight confusion between types and classes then, plus > other entities (protocols ?) The only "confusion" stems from improper terminology. "Class" is the worst possible word to describe: /"the code written by a programmer to define an object"/. This epidemic of transforming words improperly is not only a python problem (as you well know). I believe it is high time we stop designing languages by propagating foolish terminology simply because we have no will to break the "status quo". And everybody needs to help push this cause along by refusing to use the word "class" and only use the words "object definition". This is something we can all do WITHOUT modifying the python source. This is how you get the snowball rolling. However, if we do this for long enough, language designers will start to realize that "class" is NOT the proper terminology and MAYBE they will consider terminology a bit more. Well, a boy can dream... We MUST separate the idea of: "an object that lives in memory" from the: "code that defines the object" AND we must do so by wielding intuitive terminology. "Just because person X decides to jump off a bridge, that action does not impose person Y to blindly follow" From rantingrickjohnson at gmail.com Fri Jan 11 00:20:05 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 10 Jan 2013 21:20:05 -0800 (PST) Subject: Over 30 types of variables available in python ? In-Reply-To: References: <1357513931.54941.YahooMailNeo@web125504.mail.ne1.yahoo.com> Message-ID: <732cd13e-34f6-4dfc-a49e-c7607e9de21d@googlegroups.com> > On 1-7-2013 2:53:26 AM UTC-6, chaouche yacine wrote: > > Thanks for all your comments. It appears to me that there > is a slight confusion between types and classes then, plus > other entities (protocols ?) The only "confusion" stems from improper terminology. "Class" is the worst possible word to describe: /"the code written by a programmer to define an object"/. This epidemic of transforming words improperly is not only a python problem (as you well know). I believe it is high time we stop designing languages by propagating foolish terminology simply because we have no will to break the "status quo". And everybody needs to help push this cause along by refusing to use the word "class" and only use the words "object definition". This is something we can all do WITHOUT modifying the python source. This is how you get the snowball rolling. However, if we do this for long enough, language designers will start to realize that "class" is NOT the proper terminology and MAYBE they will consider terminology a bit more. Well, a boy can dream... We MUST separate the idea of: "an object that lives in memory" from the: "code that defines the object" AND we must do so by wielding intuitive terminology. "Just because person X decides to jump off a bridge, that action does not impose person Y to blindly follow" From duncan.booth at invalid.invalid Mon Jan 7 06:14:21 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Jan 2013 11:14:21 GMT Subject: Over 30 types of variables available in python ? References: Message-ID: chaouche yacine wrote: > > booleans > ints, floats, longs, complexes > strings, unicode strings > lists, tuples, dictionaries, dictionary views, sets, frozensets, > buffers, bytearrays, slices functions, methods, code > objects,modules,classes, instances, types, nulls (there is exactly one > object of type Null which is None), tracebacks, frames generators, > iterators, xranges, files, > > memoryviews, > context managers, > > These are all listed in this page > http://docs.python.org/2/library/stdtypes.html as built-in types. Am I > getting anything wrong here ? I'm a bit confused about it. I have > never seen so many types in the few programming languages I saw. Instances aren't types (though types themselves are instances): every object in Python is an instance. If you want a list of types that exist in your particular copy of Python then you can print it out easily enough: ------------------------------------------------ def allsubclasses(base): mod = base.__module__ if mod in ('builtins', '__builtin__', 'exceptions'): yield getattr(base, '__qualname__', base.__name__) else: yield "{}.{}".format(base.__module__, getattr(base, '__qualname__', base.__name__)) for typ in type.__subclasses__(base): for t in allsubclasses(typ): yield t all_types = sorted(set(allsubclasses(object)), key=str.lower) print(len(all_types)) print(all_types) ------------------------------------------------ That won't show any types that haven't been imported, but it gives me 293 types that are all loaded on startup in Python 3.3 and 150 in Python 2.7. From kalvinmanual at gmail.com Sun Jan 6 19:07:11 2013 From: kalvinmanual at gmail.com (kalvinmanual) Date: Sun, 06 Jan 2013 18:07:11 -0600 Subject: INSTRUCTOR SOLUTIONS MANUAL :: Advanced Engineering Thermodynamics, 3rd Edition by Adrian Bejan Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. INSTRUCTOR SOLUTIONS MANUAL :: Field and Wave Electromagnetics 2nd Ed by David K. Cheng INSTRUCTOR SOLUTIONS MANUAL :: Financial Accounting 6th E with Annual Report by Libby, Short INSTRUCTOR SOLUTIONS MANUAL :: Financial Accounting 6th Ed by Harrison INSTRUCTOR SOLUTIONS MANUAL :: Financial Accounting An Integrated Approach, 6th Ed by Gibbins INSTRUCTOR SOLUTIONS MANUAL :: Financial Management- Principles and Applications, 10th Ed by Keown, Scott INSTRUCTOR SOLUTIONS MANUAL :: Financial Management- Theory and Practice 12 th ED by Brigham, Ehrhardt INSTRUCTOR SOLUTIONS MANUAL :: Financial Reporting and Analysis Using Financial Accounting Information 10th Ed by Gibson INSTRUCTOR SOLUTIONS MANUAL :: Financial Reporting and Analysis, 3E by Revsine, Collins, Johnson INSTRUCTOR SOLUTIONS MANUAL :: Finite Element Techniques in Structural Mechanics Ross INSTRUCTOR SOLUTIONS MANUAL :: First Course in Abstract Algebra, 3rd Ed by Joseph J. Rotman INSTRUCTOR SOLUTIONS MANUAL :: First Course in Probability (7th Ed., Sheldon Ross) INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics (5th Ed., White) INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics 4th Ed by Cohen, Kundu INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics 4th Edition by Frank M. White INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics and Thermodynamics of Turbomachinery (5th Ed., S.L. Dixon) INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics by CENGEL INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics Egon Krause INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics Fundamentals and Applications by ??engel & Cimbala INSTRUCTOR SOLUTIONS MANUAL :: Fluid Mechanics with Engineering Applications, 10th Edition, by Finnemore INSTRUCTOR SOLUTIONS MANUAL :: Foundations of Applied Combinatorics by Bender, Williamson INSTRUCTOR SOLUTIONS MANUAL :: Foundations of Colloid Science 2e , Hunter INSTRUCTOR SOLUTIONS MANUAL :: Foundations of Modern Macroeconomics 2nd Ed by Heijdra, Reijnders, Romp INSTRUCTOR SOLUTIONS MANUAL :: Fourier and Laplace Transform - Antwoorden INSTRUCTOR SOLUTIONS MANUAL :: Fractal Geometry Mathematical Foundations and Applications, 2nd Ed Kenneth Falcone INSTRUCTOR SOLUTIONS MANUAL :: fracture mechanics ; fundamentals and applications, 2E, by T.L. Anderson INSTRUCTOR SOLUTIONS MANUAL :: From Polymers to Plastics By A.K. van der Vegt INSTRUCTOR SOLUTIONS MANUAL :: Fundamental Methods of Mathematical Economics 4th E by Chiang,Wainwright INSTRUCTOR SOLUTIONS MANUAL :: Fundamental Quantum Mechanics for Engineers by Leon van Dommelen INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Advanced Accounting By Fischer, Taylor INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Aerodynamics ( 3 Ed., Anderson) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Aerodynamics (2 Ed., Anderson) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Aircraft Structural Analysis by Howard D. Curtis INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Applied Electromagnetics (5th Ed., Fawwaz T. Ulaby) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Chemical Reaction Engineering by Davis INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Complex Analysis ( 3rd Ed., E. Saff & Arthur Snider ) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Computer Organization and Architecture by Abd-El-Barr, El-Rewini INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Corporate Finance 8th edition by Ross INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Corporate Finance 9th edition by Ross INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Corporate Finance, 4th Edition (Brealey, Myers, Marcus) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Differential Equations 7E Kent Nagle, B. Saff, Snider INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Differential Equations and Boundary Value Problems, 6th Ed by Nagle ,Saff, Snider INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Digital Logic with VHDL Design (1st Ed., Stephen Brown Vranesic) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Digital Signal Processing Using Matlab 2nd Edition by Robert J. Schilling, Sandra L. Harris INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electric Circuits (2nd.ed.) by C.K.Alexander M.N.O.Sadiku INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electric Circuits (4E., Charles Alexander & Matthew Sadiku) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electromagnetics with Engineering Applications (Stuart Wentworth) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Electronic Circuit Design , Comer INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Engineering Economics 2nd E by Chan S. Park INSTRUCTOR SOLUTIONS MANUAL :: FUNDAMENTALS OF ENGINEERING ELECTROMAGNETICS, by DAVID CHENG INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Engineering Thermodynamics, 5th Ed (Michael J. Moran, Howard N. Shapiro) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Engineering Thermodynamics, 6th Ed (Michael J. Moran, Howard N. Shapiro) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Financial Management 12th edition James C. Van Horne, Wachowicz INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Fluid Mechanics 5th Ed Munson Young Okiishi INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Fluid Mechanics 6th Ed by Munson INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Fluid Mechanics, 4E (Bruce R. Munson, Donald F. Young, Theodore H.) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Heat and Mass Transfer - 5th Edition F.P. Incropera D.P. DeWitt INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Heat and Mass Transfer (4th Ed., Incropera, DeWitt) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Heat and Mass Transfer (6th Ed., Incropera, DeWitt) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Hydraulic Engineering Systems 4th E by Houghtalen,Akan,Hwang INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Investments, 5th E by Jordan, Miller INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Logic Design, 5th Ed., by Charles Roth INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Machine Component Design (3rd Ed., Juvinall) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Machine Component Design 4th Ed by Juvinall INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Machine Elements 2nd E by Bernard Hamrock INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Machine Elements by Bernard Hamrock INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Manufacturing 2nd Edition by Philip D. Rufe INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Materials Science and Engineering- An Integrated Approach, 3rd Ed by Callister INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Microelectronics by Behzad Razavi INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Modern Manufacturing 3rd Ed by Mikell P. Groover INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Modern Manufacturing: Materials, Processes, and Systems (2nd Ed., Mikell P. Groover) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Momentum, Heat and Mass Transfer, 4th Ed by Welty,Wilson INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Momentum, Heat and Mass Transfer, 5th Ed by Welty,Wilson INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Organic Chemistry, 5E, by T. W. Graham Solomons INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Physics (7th Ed., David Halliday, Robert Resnick & Jearl Walker) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Physics 9th Ed by Resnick, Walker, Halliday INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Physics, 8th Edition Halliday, Resnick, Walker INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Power Semiconductor Devices By Jayant Baliga INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Probability, with Stochastic Processes (3rd Ed., Saeed Ghahramani) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Quantum Mechanics (C.L. Tang) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Semiconductor Devices, 1st Edition by Anderson INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Signals and Systems Using the Web and Matlab (3rd Ed., Kamen & Bonnie S Heck) INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Solid-State Electronics by Chih-Tang Sah INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Structural Analysis 3rd Ed by Leet INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Thermal-Fluid Sciences, 2nd Ed. by Cengel INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Thermodynamics 5th Ed by Sonntag, Borgnakke and Van Wylen INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Thermodynamics 6th Ed by Sonntag, Borgnakke & Van Wylen INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Wireless Communication by Tse and Viswanath INSTRUCTOR SOLUTIONS MANUAL :: Fundamentals of Wireless Communication by Tse, Viswanath INSTRUCTOR SOLUTIONS MANUAL :: Gas Dynamics (3rd Ed., John & Keith) INSTRUCTOR SOLUTIONS MANUAL :: Heat and Mass Transfer: A Practical Approach (3rd. Ed., Cengel) INSTRUCTOR SOLUTIONS MANUAL :: Heat Transfer A Practical Approach ,Yunus A. Cengel 2d ed INSTRUCTOR SOLUTIONS MANUAL :: Heating, Ventilating and Air Conditioning Analysis and Design, 6th Edition McQuiston, Parker, Spitler INSTRUCTOR SOLUTIONS MANUAL :: Higher Algebra 3rd edition by Hall and Knight INSTRUCTOR SOLUTIONS MANUAL :: HIGH-SPEED NETWORKS AND INTERNETS 2 ED STALLINGS INSTRUCTOR SOLUTIONS MANUAL :: History of Mathematics: Brief Version (Victor J. Katz) INSTRUCTOR SOLUTIONS MANUAL :: Hydraulics in Civil and Environmental Engineering 4 E by Chadwick , Morfett INSTRUCTOR SOLUTIONS MANUAL :: Hydraulics in Civil and Environmental Engineering 4th Ed by Chadwick , Borthwick From ronaldmanualsea at gmail.com Sun Jan 6 22:38:35 2013 From: ronaldmanualsea at gmail.com (ronaldmanualsea) Date: Sun, 06 Jan 2013 21:38:35 -0600 Subject: INSTRUCTOR SOLUTIONS MANUAL :: Chemical, Biochemical, and Engineering Thermodynamics, 4th Ed by Sandler Message-ID: <6YOdnewdufSm3nfNnZ2dnUVZ_vWdnZ2d@giganews.com> Here are instructor's solutions manuals to the scientific textbooks in PDF format. They cover solutions to all problems. If you need any, let me know its title, edition and author. If your title is not listed here don't worry because it is a list of some.. NOTE: This service is NOT free, and Don't reply here, instead send an email to: ronaldmanualsea( at )gmail(dot)com. INSTRUCTOR SOLUTIONS MANUAL :: Intermediate Algebra - Concepts & Applications 8th Ed by Bittinger, Ellenbogen INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Accounting 3rd Ed by Marriott, Mellett INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Algorithms, 2nd Ed by Cormen, Leiserson INSTRUCTOR SOLUTIONS MANUAL :: Introduction To Analysis (3rdEd) -by William Wade INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Applied Modern Physics by Henok Abebe INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Chemical Engineering Thermodynamics (7th Ed., Smith & Van Ness) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Commutative Algebra by M. F. Atiyah INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Digital Signal Processing (in Serbian) by Lj. Milic and Z. Dobrosavljevic INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Econometrics (2nd ed., James H. Stock & Mark W. Watson) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electric Circuits 7th Edition by Dorf, Svaboda INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electric Circuits, 6E, Dorf INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electrodynamics (3rd Ed., David J. Griffiths) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Elementary Particles 2nd Ed by David Griffiths INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Environmental Engineering and Science (3rd Ed., Gilbert M. Masters & Wendell P. Ela) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Environmental Engineering and Science, Edition 2, Masters INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Ergonomics 2E by Robert Bridger INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Fluid Mechanics ( 7 E., Robert Fox, Alan McDonald & Philip ) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Fluid Mechanics (6E., Robert Fox, Alan McDonald & Philip) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to fluid mechanics 5th edition by Alan T. McDonald, Robert W Fox INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Graph Theory 2E - West INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Heat Transfer by Vedat S. Arpaci, Ahmet Selamet, Shu-Hsin Kao INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Java Programming, Comprehensive Version 7th Ed by Liang INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Linear Algebra, 3rd Ed., by Gilbert Strang INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Management Accounting, 14 ED by Horngren, Schatzberg INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Materials Science for Engineers (6th Ed., Shackelford) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Materials Science for Engineers 7th E by Shackelford INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Mathematical Statistics (6th Ed., Hogg, Craig & McKean) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Mechatronics and Measurements Systems 2nd Ed by Alciatore, Histand INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Nuclear And Particle Physics 2nd E by Bromberg, Das, Ferbel INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Operations Research - 7th ed by Frederick Hillier, Gerald Lieberman INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability 2nd Ed by Bertsekas and Tsitsiklis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability by Dimitri P. Bertsekas and John N. Tsitsiklis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability by Grinstead, Snell INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Quantum Mechanics (2nd Ed., David J. Griffiths) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Quantum Mechanics 1st edition (1995) by David J. Griffiths INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Queueing Theory 2nd Edition by R.B. Cooper INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Scientific Computation and Programming, 1st Edition by Daniel Kaplan INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Signal Processing by S. J. Orfanidis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Signal Processing by Sophocles J. Orfanidis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Solid State Physics 8th Ed by Kittel & Charles INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Statistical Physics by Kerson Huang INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Statistical Quality Control (5th Ed., Douglas C. Montgomery) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to the Theory of Computation by Ching Law INSTRUCTOR SOLUTIONS MANUAL :: Introduction to the Thermodynamics of Materials 3 E by Gaskell INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Thermal Systems Engineering Moran Shapiro Munson INSTRUCTOR SOLUTIONS MANUAL :: Introduction to VLSI Circuits and Systems, by John P. Uyemura INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Wireless Systems by P.M Shankar INSTRUCTOR SOLUTIONS MANUAL :: Introductory Econometrics A Modern Approach, 3Ed by Jeffrey Wooldridge INSTRUCTOR SOLUTIONS MANUAL :: Introductory Mathematical Analysis for Business, Economics and the Life and Social Sciences, 12th E By Haeussler,Paul,Wood INSTRUCTOR SOLUTIONS MANUAL :: Introductory Quantum Optics (Christopher Gerry & Peter Knight) INSTRUCTOR SOLUTIONS MANUAL :: Introdution to Solid State Physics, 8th Edition by Kittel INSTRUCTOR SOLUTIONS MANUAL :: Investment Analysis & Portfolio Management, 7e by Reilly, Brown INSTRUCTOR SOLUTIONS MANUAL :: Investment Analysis and Portfolio Management 7th Edition by Frank K. et al. Reilly INSTRUCTOR SOLUTIONS MANUAL :: Investments by Charles P. Jones INSTRUCTOR SOLUTIONS MANUAL :: IT Networking Labs by Tom Cavaiani INSTRUCTOR SOLUTIONS MANUAL :: Java How to program 7th Ed by Deitel INSTRUCTOR SOLUTIONS MANUAL :: Journey into Mathematics An Introduction to Proofs ,Joseph Rotman INSTRUCTOR SOLUTIONS MANUAL :: Kinematics, Dynamics, and Design of Machinery, 2nd Ed., Waldron & Kinzel INSTRUCTOR SOLUTIONS MANUAL :: Kinetics of Catalytic Reactions by M. Albert Vannice INSTRUCTOR SOLUTIONS MANUAL :: LabVIEW for Engineers by Larsen INSTRUCTOR SOLUTIONS MANUAL :: Laser Fundamentals (2nd Ed., William T. Silfvast) INSTRUCTOR SOLUTIONS MANUAL :: Learning SAS in the Computer Lab 3rd ED by Elliott, Morrell INSTRUCTOR SOLUTIONS MANUAL :: Lectures on Corporate Finance 2006, 2 Ed by Bossaerts, Oedegaard INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra - 2 Ed - Poole INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra and Its Applications 3rd ed by David C. Lay INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra Done Right, 2nd Ed by Sheldon Axler INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra with Applications (6th Ed., S. Leon) INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra with Applications 3rd Ed by Otto Bretscher INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra With Applications, 2nd Edition by W. Keith Nicholson INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra, by J. Hefferon INSTRUCTOR SOLUTIONS MANUAL :: Linear Circuit Analysis Time Domain, Phasor and Laplace.., 2nd Ed, Lin INSTRUCTOR SOLUTIONS MANUAL :: Linear Circuit Analysis, 2nd Ed by DeCarlo , Pen-Min Lin INSTRUCTOR SOLUTIONS MANUAL :: Linear dynamic systems and signals by Zoran Gajic INSTRUCTOR SOLUTIONS MANUAL :: Linear Systems And Signals, 1stE, B P Lathi INSTRUCTOR SOLUTIONS MANUAL :: Logic and Computer Design Fundamentals, 2E, by Morris Mano and Charles Kime INSTRUCTOR SOLUTIONS MANUAL :: Logic and Computer Design Fundamentals, 3d edition by Morris Mano and Charles Kime INSTRUCTOR SOLUTIONS MANUAL :: Logic and Computer Design Fundamentals, 4/E, by Morris Mano and Charles Kime From kalpanaganeshm at gmail.com Mon Jan 7 01:32:28 2013 From: kalpanaganeshm at gmail.com (kalpanaganeshm at gmail.com) Date: Sun, 6 Jan 2013 22:32:28 -0800 (PST) Subject: Help Support Python In-Reply-To: References: Message-ID: <0a6ff989-8f29-4d70-b558-3db49608a308@googlegroups.com> Informatics Outsourcing is an Offshore Intellectual Property Services company. They are providing Intellectual Property services for Bio Technology, Biochemistry, Drug Discovery, Chemistry, etc From gheskett at wdtv.com Mon Jan 7 01:43:29 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 7 Jan 2013 01:43:29 -0500 Subject: License status of pycollada? Message-ID: <201301070143.29641.gheskett@wdtv.com> Greetings all; Trying to collect all the dependencies of FreeCad-0.13, but it appears that pycollada is behind some sort of a login/paywall on github. Is anyone here familiar with how that works? Thanks. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: is up! My views Mr. Cole's Axiom: The sum of the intelligence on the planet is a constant; the population is growing. I was taught to respect my elders, but its getting harder and harder to find any... From clp2 at rebertia.com Mon Jan 7 05:29:46 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 7 Jan 2013 02:29:46 -0800 Subject: License status of pycollada? In-Reply-To: <201301070143.29641.gheskett@wdtv.com> References: <201301070143.29641.gheskett@wdtv.com> Message-ID: On Sunday, January 6, 2013, Gene Heskett wrote: > Greetings all; > > Trying to collect all the dependencies of FreeCad-0.13, but it appears that > pycollada is behind some sort of a login/paywall on github. Is anyone here > familiar with how that works? > Er, what? The repo seems freely browseable. Looks like it's under a standard 3-clause BSD-style license: https://github.com/pycollada/pycollada/blob/master/COPYING -- Cheers, Chris -- http://rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jterrace at gmail.com Tue Jan 8 12:24:16 2013 From: jterrace at gmail.com (Jeff Terrace) Date: Tue, 8 Jan 2013 09:24:16 -0800 Subject: License status of pycollada? Message-ID: Hi Gene, I'm the maintainer of pycollada. No such paywall exists, and a login is not required. I'm not sure how you came across that. As Chris said, it's a standard BSD license. I'd be happy to help with packaging, so feel free to contact me. Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Tue Jan 8 14:20:11 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 8 Jan 2013 14:20:11 -0500 Subject: License status of pycollada? In-Reply-To: References: Message-ID: <201301081420.11651.gheskett@wdtv.com> On Tuesday 08 January 2013 14:09:55 Jeff Terrace did opine: Message additions Copyright Tuesday 08 January 2013 by Gene Heskett > Hi Gene, > > I'm the maintainer of pycollada. No such paywall exists, and a login is > not required. I'm not sure how you came across that. > Google search. > As Chris said, it's a standard BSD license. I'd be happy to help with > packaging, so feel free to contact me. It doesn't seem to be that important at the moment. I did find the src tarball later on another site, but it bails out because something is missing, gene at coyote:~/src/pycollada-0.4$ python setup.py Traceback (most recent call last): File "setup.py", line 2, in from setuptools import find_packages, setup ImportError: No module named setuptools I should go look for setuptools. matplotlib also fails to configure, numpy is a version too old on 10.04.4 Ubuntu, with no update for it available for that old a Ubuntu. 10.04.4 LTS only has 1.3, so I am blocked there too. ATM, no biggie. Thanks for the email. I'm going to go make some swarf freehand. > Jeff Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: is up! My views The possession of a book becomes a substitute for reading it. -- Anthony Burgess I was taught to respect my elders, but its getting harder and harder to find any... From redstone-cold at 163.com Mon Jan 7 04:23:02 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 7 Jan 2013 01:23:02 -0800 (PST) Subject: how to detect the character encoding in a web page ? In-Reply-To: References: Message-ID: <570913d9-d0f6-4ad4-9400-194d008a8384@googlegroups.com> ? 2012?12?24????UTC+8??8?34?47??iMath??? > how to detect the character encoding in a web page ? > > such as this page > > > > http://python.org/ up to now , maybe chadet is the only way to let python automatically do it . From albert at spenarnc.xs4all.nl Mon Jan 14 07:50:23 2013 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 14 Jan 2013 12:50:23 GMT Subject: how to detect the character encoding in a web page ? References: <50d85daf$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50f3ff0f$0$6347$e4fe514c@dreader35.news.xs4all.nl> In article , Roy Smith wrote: >In article , > Alister wrote: > >> Indeed due to the poor quality of most websites it is not possible to be >> 100% accurate for all sites. >> >> personally I would start by checking the doc type & then the meta data as >> these should be quick & correct, I then use chardectect only if these >> fail to provide any result. > >I agree that checking the metadata is the right thing to do. But, I >wouldn't go so far as to assume it will always be correct. There's a >lot of crap out there with perfectly formed metadata which just happens >to be wrong. > >Although it pains me greatly to quote Ronald Reagan as a source of >wisdom, I have to admit he got it right with "Trust, but verify". It's Not surprisingly, as an actor, Reagan was as good as his script. This one he got from Stalin. >the only way to survive in the unicode world. Write defensive code. >Wrap try blocks around calls that might raise exceptions if the external >data is borked w/r/t what the metadata claims it should be. The way to go, of course. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From ronaldmanualsea at gmail.com Mon Jan 7 04:34:52 2013 From: ronaldmanualsea at gmail.com (ronaldmanualsea) Date: Mon, 07 Jan 2013 03:34:52 -0600 Subject: INSTRUCTOR SOLUTIONS MANUAL :: Design of Reinforced Concrete, 8th Ed by McCormac, Brown Message-ID: Here are instructor's solutions manuals to the scientific textbooks in PDF format. They cover solutions to all problems. If you need any, let me know its title, edition and author. If your title is not listed here don't worry because it is a list of some.. NOTE: This service is NOT free, and Don't reply here, instead send an email to: ronaldmanualsea( at )gmail(dot)com. INSTRUCTOR SOLUTIONS MANUAL :: Intermediate Accounting - IFRS Edition Vol.1 by Kieso, Weygandt, Warfield INSTRUCTOR SOLUTIONS MANUAL :: Intermediate Accounting 12th ed by Kieso INSTRUCTOR SOLUTIONS MANUAL :: Intermediate Accounting 13 ed by Kieso INSTRUCTOR SOLUTIONS MANUAL :: Intermediate Accounting Kieso 12th ed INSTRUCTOR SOLUTIONS MANUAL :: INTERMEDIATE ACCOUNTING, 6th Edition, by Spiceland, Sepe INSTRUCTOR SOLUTIONS MANUAL :: Intermediate Algebra - Concepts & Applications 8th Ed by Bittinger, Ellenbogen INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Accounting 3rd Ed by Marriott, Mellett INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Algorithms, 2nd Ed by Cormen, Leiserson INSTRUCTOR SOLUTIONS MANUAL :: Introduction To Analysis (3rdEd) -by William Wade INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Applied Modern Physics by Henok Abebe INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Chemical Engineering Thermodynamics (7th Ed., Smith & Van Ness) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Commutative Algebra by M. F. Atiyah INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Digital Signal Processing (in Serbian) by Lj. Milic and Z. Dobrosavljevic INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Econometrics (2nd ed., James H. Stock & Mark W. Watson) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electric Circuits 7th Edition by Dorf, Svaboda INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electric Circuits, 6E, Dorf INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Electrodynamics (3rd Ed., David J. Griffiths) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Elementary Particles 2nd Ed by David Griffiths INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Environmental Engineering and Science (3rd Ed., Gilbert M. Masters & Wendell P. Ela) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Environmental Engineering and Science, Edition 2, Masters INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Ergonomics 2E by Robert Bridger INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Fluid Mechanics ( 7 E., Robert Fox, Alan McDonald & Philip ) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Fluid Mechanics (6E., Robert Fox, Alan McDonald & Philip) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to fluid mechanics 5th edition by Alan T. McDonald, Robert W Fox INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Graph Theory 2E - West INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Heat Transfer by Vedat S. Arpaci, Ahmet Selamet, Shu-Hsin Kao INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Java Programming, Comprehensive Version 7th Ed by Liang INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Linear Algebra, 3rd Ed., by Gilbert Strang INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Management Accounting, 14 ED by Horngren, Schatzberg INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Materials Science for Engineers (6th Ed., Shackelford) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Materials Science for Engineers 7th E by Shackelford INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Mathematical Statistics (6th Ed., Hogg, Craig & McKean) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Mechatronics and Measurements Systems 2nd Ed by Alciatore, Histand INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Nuclear And Particle Physics 2nd E by Bromberg, Das, Ferbel INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Operations Research - 7th ed by Frederick Hillier, Gerald Lieberman INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability 2nd Ed by Bertsekas and Tsitsiklis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability by Dimitri P. Bertsekas and John N. Tsitsiklis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Probability by Grinstead, Snell INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Quantum Mechanics (2nd Ed., David J. Griffiths) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Quantum Mechanics 1st edition (1995) by David J. Griffiths INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Queueing Theory 2nd Edition by R.B. Cooper INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Scientific Computation and Programming, 1st Edition by Daniel Kaplan INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Signal Processing by S. J. Orfanidis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Signal Processing by Sophocles J. Orfanidis INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Solid State Physics 8th Ed by Kittel & Charles INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Statistical Physics by Kerson Huang INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Statistical Quality Control (5th Ed., Douglas C. Montgomery) INSTRUCTOR SOLUTIONS MANUAL :: Introduction to the Theory of Computation by Ching Law INSTRUCTOR SOLUTIONS MANUAL :: Introduction to the Thermodynamics of Materials 3 E by Gaskell INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Thermal Systems Engineering Moran Shapiro Munson INSTRUCTOR SOLUTIONS MANUAL :: Introduction to VLSI Circuits and Systems, by John P. Uyemura INSTRUCTOR SOLUTIONS MANUAL :: Introduction to Wireless Systems by P.M Shankar INSTRUCTOR SOLUTIONS MANUAL :: Introductory Econometrics A Modern Approach, 3Ed by Jeffrey Wooldridge INSTRUCTOR SOLUTIONS MANUAL :: Introductory Mathematical Analysis for Business, Economics and the Life and Social Sciences, 12th E By Haeussler,Paul,Wood INSTRUCTOR SOLUTIONS MANUAL :: Introductory Quantum Optics (Christopher Gerry & Peter Knight) INSTRUCTOR SOLUTIONS MANUAL :: Introdution to Solid State Physics, 8th Edition by Kittel INSTRUCTOR SOLUTIONS MANUAL :: Investment Analysis & Portfolio Management, 7e by Reilly, Brown INSTRUCTOR SOLUTIONS MANUAL :: Investment Analysis and Portfolio Management 7th Edition by Frank K. et al. Reilly INSTRUCTOR SOLUTIONS MANUAL :: Investments by Charles P. Jones INSTRUCTOR SOLUTIONS MANUAL :: IT Networking Labs by Tom Cavaiani INSTRUCTOR SOLUTIONS MANUAL :: Java How to program 7th Ed by Deitel INSTRUCTOR SOLUTIONS MANUAL :: Journey into Mathematics An Introduction to Proofs ,Joseph Rotman INSTRUCTOR SOLUTIONS MANUAL :: Kinematics, Dynamics, and Design of Machinery, 2nd Ed., Waldron & Kinzel INSTRUCTOR SOLUTIONS MANUAL :: Kinetics of Catalytic Reactions by M. Albert Vannice INSTRUCTOR SOLUTIONS MANUAL :: LabVIEW for Engineers by Larsen INSTRUCTOR SOLUTIONS MANUAL :: Laser Fundamentals (2nd Ed., William T. Silfvast) INSTRUCTOR SOLUTIONS MANUAL :: Learning SAS in the Computer Lab 3rd ED by Elliott, Morrell INSTRUCTOR SOLUTIONS MANUAL :: Lectures on Corporate Finance 2006, 2 Ed by Bossaerts, Oedegaard INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra - 2 Ed - Poole INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra and Its Applications 3rd ed by David C. Lay INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra Done Right, 2nd Ed by Sheldon Axler INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra with Applications (6th Ed., S. Leon) INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra with Applications 3rd Ed by Otto Bretscher INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra With Applications, 2nd Edition by W. Keith Nicholson INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra, by J. Hefferon INSTRUCTOR SOLUTIONS MANUAL :: Linear Circuit Analysis Time Domain, Phasor and Laplace.., 2nd Ed, Lin INSTRUCTOR SOLUTIONS MANUAL :: Linear Circuit Analysis, 2nd Ed by DeCarlo , Pen-Min Lin INSTRUCTOR SOLUTIONS MANUAL :: Linear dynamic systems and signals by Zoran Gajic INSTRUCTOR SOLUTIONS MANUAL :: Linear Systems And Signals, 1stE, B P Lathi INSTRUCTOR SOLUTIONS MANUAL :: Logic and Computer Design Fundamentals, 2E, by Morris Mano and Charles Kime INSTRUCTOR SOLUTIONS MANUAL :: Logic and Computer Design Fundamentals, 3d edition by Morris Mano and Charles Kime From redstone-cold at 163.com Mon Jan 7 04:45:58 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 7 Jan 2013 01:45:58 -0800 (PST) Subject: =?UTF-8?Q?Re=3A_regular_expression_=3A__the_dollar_sign_=28=24=29_work_w?= =?UTF-8?Q?ith_re=2Ematch=28=29_or_re=2Esearch=28=29__=EF=BC=9F?= In-Reply-To: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: ? 2012?9?26????UTC+8??3?38?50??iMath??? > I only know the dollar sign ($) will match a pattern from the > > end of a string,but which method does it work with ,re.match() or re.search() ? I thought re.match('h.$', 'hbxihi') will match ?hi? ,but it does not .so why ? From steve+comp.lang.python at pearwood.info Mon Jan 7 04:54:24 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2013 09:54:24 GMT Subject: regular expression : the dollar sign ($) work with re.match() or re.search() =?iso-2022-kr?q?=1B$=29C=0E#=3F=0F?= References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: <50ea9b4f$0$21851$c3e8da3$76491128@news.astraweb.com> On Mon, 07 Jan 2013 01:45:58 -0800, iMath wrote: > ? 2012?9?26????UTC+8??3?38?50??iMath??? >> I only know the dollar sign ($) will match a pattern from the >> >> end of a string,but which method does it work with ,re.match() or >> re.search() ? > > I thought re.match('h.$', 'hbxihi') will match ?hi? ,but it does not .so > why ? re.match only matches at the *start* of the string, so "h.$" tries to match: * start of string * literal h * any character * end of string You want re.search, which will search the entire string and match "hi" at the end of the string. -- Steven From markuschristen84 at gmail.com Mon Jan 7 04:50:05 2013 From: markuschristen84 at gmail.com (Markus Christen) Date: Mon, 7 Jan 2013 01:50:05 -0800 (PST) Subject: pyodbc utf-8 In-Reply-To: References: <075a81ce-9b72-400f-8beb-025a167efa5f@googlegroups.com> Message-ID: <4771353a-04b5-4677-bb37-0cd1c9090402@googlegroups.com> When i look at my output on my webpage, i can see this: W\xe4denswil but it have to be this: W?denswil you know now what i can see exactly... im using django and they told me its a python problem with utf-8. when i turn off debug, i cant see the page, it give me an error 500. the text "Danke f?r die..." on the bottom of my page is displayed correct. the error comes only when an umlaut is to post, out of the raw. From markuschristen84 at gmail.com Mon Jan 7 04:50:05 2013 From: markuschristen84 at gmail.com (Markus Christen) Date: Mon, 7 Jan 2013 01:50:05 -0800 (PST) Subject: pyodbc utf-8 In-Reply-To: References: <075a81ce-9b72-400f-8beb-025a167efa5f@googlegroups.com> Message-ID: <4771353a-04b5-4677-bb37-0cd1c9090402@googlegroups.com> When i look at my output on my webpage, i can see this: W\xe4denswil but it have to be this: W?denswil you know now what i can see exactly... im using django and they told me its a python problem with utf-8. when i turn off debug, i cant see the page, it give me an error 500. the text "Danke f?r die..." on the bottom of my page is displayed correct. the error comes only when an umlaut is to post, out of the raw. From 2281570025 at qq.com Mon Jan 7 05:35:20 2013 From: 2281570025 at qq.com (=?utf-8?B?aU1hdGg=?=) Date: Mon, 7 Jan 2013 18:35:20 +0800 Subject: =?utf-8?B?d2hhdOKAmXMgdGhlIGRpZmZlcmVuY2UgYmV0d2Vl?= =?utf-8?B?biBzb2NrZXQuc2VuZCgpIGFuZCBzb2NrZXQuc2Vu?= =?utf-8?B?ZGFsbCgpID8=?= Message-ID: An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Jan 7 08:17:50 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 07 Jan 2013 14:17:50 +0100 Subject: =?UTF-8?B?d2hhdOKAmXMgdGhlIGRpZmZlcmVuY2UgYmV0d2VlbiBzb2NrZXQ=?= =?UTF-8?B?LnNlbmQoKSBhbmQgc29ja2V0LnNlbmRhbGwoKSA/?= In-Reply-To: References: Message-ID: Am 07.01.2013 11:35 schrieb iMath: > what?s the difference between socket.send() and socket.sendall() ? > > It is so hard for me to tell the difference between them from the python doc > > so what is the difference between them ? > > and each one is suitable for which case ? > The docs are your friend. See http://docs.python.org/2/library/socket.html#socket.socket.sendall | [...] Unlike send(), this method continues to send data from string | until either all data has been sent or an error occurs. HTH, Thomas From steve+comp.lang.python at pearwood.info Mon Jan 7 10:28:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2013 15:28:18 GMT Subject: =?iso-8859-7?q?what=A2s?= the difference between socket.send() and socket.sendall() ? References: Message-ID: <50eae991$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 07 Jan 2013 18:35:20 +0800, iMath wrote: >

what?s the > difference between socket style="font-size: 12pt; ">.send() and socket.sendall() > ?

Please re-send your question as text, instead of as HTML (so-called "rich text"). Since many people are reading this forum via Usenet, sending HTML is considered abusive. This is a text newsgroup, not a binary newsgroup. If you *must* use a client that sends HTML, please make sure that it ALWAYS sends a plain text version of your message as well. But here are eight reasons you should not rely on fancy formatting (colours, fonts, bold, etc.) in text-based media such as email (or news): - HTML code in email is one of the top 3 signs of spam. Many people send "rich text" email straight to the trash as a way of eliminating spam. - HTML code in email is a privacy and security risk. For example, that means that the sender can track whether or not you have read the email using "web bugs" whether or not you consent to being tracked. There are viruses, spyware and other malware that can be transmitted through HTML code in email. For this reason, many people filter HTML email straight to the trash. - HTML code forces your choice in font, font size, colours, etc. on the reader. Some people prefer to read emails using their own choice of font rather than yours, and consider it rude for others to try to force a different font. Sending white text on coloured background is especially nasty, because it hurts readability of even for people with perfect vision. - Even if readers don't mind the use of "rich text" in principle, in practice once they have received enough emails with pink text on a purple and yellow background with blinking stars and dancing fairies all over the page, in pure self-defence they may disable or delete HTML emails. - Use of colour for emphasis discriminates against the approximately 10% of the male population who are colour-blind. - Use of italics or other formatting may discriminate against those who are blind and using screen readers to "read" their email. I once was on a maths mailing list for about three years before I realised that the most prolific and helpful person there was as blind as a bat. - Programming is a *text-based* activity. Code depends on WHAT you write, not its colour, or the font you use, or whether there are smiley faces in the background winking at you. So especially in programming circles, many people find HTML code in emails to be a distraction and an annoyance. Being able to express yourself in plain text without colours and fonts is a good practice for any programmer to get used to. - Even if you think that people who dislike HTML emails are wrong, or silly, or being precious, or completely nuts, nevertheless you should indulge us. You are asking for free advice. It does not pay for you to offend or annoy those you are asking for help. (Apologies to anyone on the "tutor" mailing list who has already seen this message earlier today.) -- Steven From rosuav at gmail.com Mon Jan 7 10:54:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 02:54:49 +1100 Subject: =?windows-1252?Q?Re=3A_what=92s_the_difference_between_socket=2Esend=28=29_an?= =?windows-1252?Q?d_socket=2Esendall=28=29_=3F?= In-Reply-To: <50eae991$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50eae991$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 8, 2013 at 2:28 AM, Steven D'Aprano wrote: > I > once was on a maths mailing list for about three years before I > realised that the most prolific and helpful person there was as > blind as a bat. And that, I think, is what s/he would have most wanted: three years (more, most likely) without any sort of special treatment. It's all very well to talk about anti-discrimination laws, but on the internet, nobody knows you're a bat, if I can mangle that expression without offending people. We have some excellent people on a couple of MUDs I'm on who are, similarly, blind and using screen-readers. Again, you don't even know that that's the case until/unless a question comes out about some piece of ASCII art (which there's a very VERY little of in Threshold), or some client-specific question hints at the fact that s/he is using one of the reader-friendly clients (which are fairly ugly to the sighted). As to the use of color for emphasis, though - I don't think the OP used it like that. I've no idea what the significance of white-on-blue words was, there; it completely eludes me. Maybe he was sending a secret message in the color codes? In any case, Steven's eight reasons are absolutely right; when HTML code isn't adding information, it should be stripped, and when it is adding information, you risk a large proportion of people not seeing it. So there's never a good time to use HTML. ChrisA From phihag at phihag.de Tue Jan 8 07:42:07 2013 From: phihag at phihag.de (Philipp Hagemeister) Date: Tue, 08 Jan 2013 13:42:07 +0100 Subject: =?UTF-8?B?d2hhdOKAmXMgdGhlIGRpZmZlcmVuY2UgYmV0d2VlbiBzb2NrZXQ=?= =?UTF-8?B?LnNlbmQoKSBhbmQgc29ja2V0LnNlbmRhbGwoKSA/?= In-Reply-To: References: Message-ID: <50EC141F.6010003@phihag.de> socket.socket.send is a low-level method and basically just the C/syscall method send(3) / send(2). It can send less bytes than you requested. socket.socket.sendall is a high-level Python-only method that sends the entire buffer you pass or throws an exception. It does that by calling send until everything has been sent or an error occurs. If you're using TCP with blocking sockets and don't want to be bothered by internals (this is the case for most simple network applications), use sendall. Otherwise, use send and make sure to read and process its return value. - Philipp On 01/07/2013 11:35 AM, iMath wrote: > what?s the difference between socket.send() and socket.sendall() ? > > It is so hard for me to tell the difference between them from the python doc > > so what is the difference between them ? > > and each one is suitable for which case ? > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: OpenPGP digital signature URL: From warem2888 at gmail.com Mon Jan 7 07:50:00 2013 From: warem2888 at gmail.com (Constantine) Date: Mon, 7 Jan 2013 04:50:00 -0800 (PST) Subject: "Gangnam Style" in line for UK dictionary inclusion Message-ID: <30ed15da-a17c-434c-956b-20d0f1cbea64@googlegroups.com> "Gangnam Style" in line for UK dictionary inclusion http://adf.ly/2836760/news.yahoo.com/gangnam-style-line-uk-dictionary-inclusion-134517741.html From GadgetSteve at hotmail.com Mon Jan 7 08:22:10 2013 From: GadgetSteve at hotmail.com (GadgetSteve) Date: Mon, 7 Jan 2013 05:22:10 -0800 (PST) Subject: "Gangnam Style" in line for UK dictionary inclusion In-Reply-To: <30ed15da-a17c-434c-956b-20d0f1cbea64@googlegroups.com> References: <30ed15da-a17c-434c-956b-20d0f1cbea64@googlegroups.com> Message-ID: On Monday, January 7, 2013 12:50:00 PM UTC, Constantine wrote: > "Gangnam Style" in line for UK dictionary inclusion http://adf.ly/2836760/news.yahoo.com/gangnam-style-line-uk-dictionary-inclusion-134517741.html And this has to do with python how? From d at davea.name Mon Jan 7 08:58:09 2013 From: d at davea.name (Dave Angel) Date: Mon, 07 Jan 2013 08:58:09 -0500 Subject: "Gangnam Style" in line for UK dictionary inclusion In-Reply-To: References: <30ed15da-a17c-434c-956b-20d0f1cbea64@googlegroups.com> Message-ID: <50EAD471.1040802@davea.name> On 01/07/2013 08:22 AM, GadgetSteve wrote: > On Monday, January 7, 2013 12:50:00 PM UTC, Constantine wrote: >> Trying to get control: http://AboutToTrashYou.invalid/28929293899994736760/news.yahoo.com/Whatever-you-like-it-wont&44work134517741.html > And this has to do with python how? When replying to obvious spam, please don't quote the original link (unless you thoroughly mangle it). That just doubles the exposure so more people are likely to click there. adfly is a well-known adware virus/trojan/annoyance. People on Windows machines may have to remove the crud it installs. -- DaveA From rodrick.brown at gmail.com Mon Jan 7 10:54:02 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Mon, 7 Jan 2013 10:54:02 -0500 Subject: When is overriding __getattr__ is useful? Message-ID: Can someone provide an example why one would want to override __getattr__ and __getattribute__ in a class? -------------- next part -------------- An HTML attachment was scrubbed... URL: From marduk at letterboxes.org Mon Jan 7 11:47:47 2013 From: marduk at letterboxes.org (Albert Hopkins) Date: Mon, 07 Jan 2013 11:47:47 -0500 Subject: When is overriding __getattr__ is useful? In-Reply-To: References: Message-ID: <1357577267.30134.140661174489109.6EAC5946@webmail.messagingengine.com> On Mon, Jan 7, 2013, at 10:54 AM, Rodrick Brown wrote: > Can someone provide an example why one would want to override __getattr__ > and __getattribute__ in a class? They're good for cases when you want to provide an "attribute-like" quality but you don't know the attribute in advance. For example, the xmlrpclib uses __getattr__ to "expose" XML-RPC methods over the wire when it doesn't necessarily know what methods are exposed by the service. This allows you do simply do >>> service.method(*args) And have the method "seem" like it's just a local method on an object. There are countless other examples. But that's just one that can be found in the standard library. From alain at dpt-info.u-strasbg.fr Mon Jan 7 11:01:33 2013 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 07 Jan 2013 17:01:33 +0100 Subject: Vigil, the eternal morally vigilant programming language Message-ID: <87vcb9yobm.fsf@dpt-info.u-strasbg.fr> I just came across Vigil, an extension to python for serious software engineers, at https://github.com/munificent/vigil and thought everybody in this group would be interested (sorry if it has been announced before). >From README: | Vigil is a very safe programming language, and an entry in the January | 2013 PLT Games competition. | | Many programming languages claim to take testing, contracts and safety | seriously, but only Vigil is truly vigilant about not allowing code | that fails to pass programmatic specifications. Enjoy. -- Alain. From rosuav at gmail.com Mon Jan 7 11:08:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 03:08:27 +1100 Subject: Vigil, the eternal morally vigilant programming language In-Reply-To: <87vcb9yobm.fsf@dpt-info.u-strasbg.fr> References: <87vcb9yobm.fsf@dpt-info.u-strasbg.fr> Message-ID: On Tue, Jan 8, 2013 at 3:01 AM, Alain Ketterlin wrote: > > I just came across Vigil, an extension to python for serious software > engineers, at https://github.com/munificent/vigil and thought everybody > in this group would be interested (sorry if it has been announced > before). It's the logical derivation of the principle that every program, once written, could be shortened by at least one instruction and contains at least one bug. From that, you can deduce that every program can be logically reduced to a single instruction that doesn't work. Vigil assists you with this logical reduction. ChrisA From tjreedy at udel.edu Tue Jan 8 03:12:21 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 Jan 2013 03:12:21 -0500 Subject: Vigil, the eternal morally vigilant programming language In-Reply-To: <87vcb9yobm.fsf@dpt-info.u-strasbg.fr> References: <87vcb9yobm.fsf@dpt-info.u-strasbg.fr> Message-ID: On 1/7/2013 11:01 AM, Alain Ketterlin wrote: > > I just came across Vigil, an extension to python for serious software > engineers, I hope that last part comes from a sense of humor. > at https://github.com/munificent/vigil and thought everybody > in this group would be interested (sorry if it has been announced > before). > > From README: > > | Vigil is a very safe programming language, and an entry in the January > | 2013 PLT Games competition. > | > | Many programming languages claim to take testing, contracts and safety > | seriously, but only Vigil is truly vigilant about not allowing code > | that fails to pass programmatic specifications. While the language is a joke (Procrustes would be a somewhat better name), the example illustrates the near uselessness of contract checking, at least for functions. The example fib(n) function 'swears' that the answer is a count (not negative). Ha, ha, very funny. A simple 'return 0' would satisfy that useless contract*. A correct fib(n) function must actually calculate fib(n), and in practice, that is not possible to check. Even checking that sorted(iterable) is correct (outside a test situation) is harder than it might first seem#. * In any of the many languages that use biased residue classes as a substitute for real integers, positive + positive = positive is not so trivial. So the function must return a negative to signal bad input or raise an exception either directly or by an input condition. The advantage of the directly exception is that the exception message can be tailored to the audience and situation. [Vigil would simply excise the calling function.] # Given sorted(iterable) where iterable gets some number of comparable items from stdin, how is the contract checker to determine that the output is indeed a permutation of the unmutated input items, before checking that they are are actually sorted. -- Terry Jan Reedy From kwakukwatiah at gmail.com Mon Jan 7 18:35:02 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Mon, 7 Jan 2013 17:35:02 -0600 Subject: help Message-ID: download wxpython but whenever I try to use it I get this I?m a beginner in python pls I need help. Traceback (most recent call last): File "C:/Python27/wxp.py", line 1, in import wx File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 45, in from wx._core import * File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, in import _core_ ImportError: DLL load failed: %1 is not a valid Win32 application. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 7 14:37:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 06:37:48 +1100 Subject: help In-Reply-To: References: Message-ID: On Tue, Jan 8, 2013 at 10:35 AM, wrote: > download wxpython but whenever I try to use it I get this I?m a beginner in > python pls I need help. > > ImportError: DLL load failed: %1 is not a valid Win32 application. Did you download the 64-bit version on a 32-bit system? Chris Angelico From ian.g.kelly at gmail.com Mon Jan 7 18:06:55 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 7 Jan 2013 16:06:55 -0700 Subject: help In-Reply-To: References: Message-ID: On Mon, Jan 7, 2013 at 12:37 PM, Chris Angelico wrote: > On Tue, Jan 8, 2013 at 10:35 AM, wrote: >> download wxpython but whenever I try to use it I get this I?m a beginner in >> python pls I need help. >> >> ImportError: DLL load failed: %1 is not a valid Win32 application. > > Did you download the 64-bit version on a 32-bit system? Or perhaps a 32-bit wxPython version with a 64-bit Python installation? From lampenregenschirm at web.de Mon Jan 7 13:26:32 2013 From: lampenregenschirm at web.de (Elli Lola) Date: Mon, 7 Jan 2013 19:26:32 +0100 (CET) Subject: test failed: test_urlwithfrag Message-ID: An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Mon Jan 7 18:09:12 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 08 Jan 2013 00:09:12 +0100 Subject: test failed: test_urlwithfrag In-Reply-To: References: Message-ID: <50eb5598$0$6979$e4fe514c@news.xs4all.nl> On 7-1-2013 19:26, Elli Lola wrote: > I never used python before and installed it today the first time, so I have no idea what > to do about this failure: > > > $ ./python -m test -v test_urlwithfrag [..snip..] > ImportError: No module named 'test.test_urlwithfrag' > > 1 test failed: > test_urlwithfrag The error message says it all, really: there is no regression test module called "test_urlwithfrag". (At least, not on my python 3.3 installation) Check the contents of your /Lib/test directory to see what is available instead. Irmen From tjreedy at udel.edu Tue Jan 8 03:44:47 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 Jan 2013 03:44:47 -0500 Subject: test failed: test_urlwithfrag In-Reply-To: References: Message-ID: On 1/7/2013 1:26 PM, Elli Lola wrote: > $ ./python -m test -v test_urlwithfrag > > == CPython 3.3.0 (default, Jan 4 2013, 23:08:00) [GCC 4.6.3] > == Linux-3.2.0-35-generic-pae-i686-with-debian-wheezy-sid little-endian > == /home/me/Programme/Python/Python-3.3.0/build/test_python_30744 > Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, > optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, > ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, > hash_randomization=1) > [1/1] test_urlwithfrag > test test_urlwithfrag crashed -- Traceback (most recent call last): > File "/home/me/Programme/Python/Python-3.3.0/Lib/test/regrtest.py", > line 1213, in runtest_inner > the_package = __import__(abstest, globals(), locals(), []) > ImportError: No module named 'test.test_urlwithfrag' > > 1 test failed: > test_urlwithfrag Read the message I sent you before. (To everyone else, I already explained that the error message means exactly what it says and listed the test_urlxxxx files that do exist. No need to repeat a third time.) -- Terry Jan Reedy From kevin.p.dwyer at gmail.com Sat Jan 19 09:07:57 2013 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 19 Jan 2013 14:07:57 +0000 Subject: test failed: test_urlwithfrag References: Message-ID: Terry Reedy wrote: > On 1/7/2013 1:26 PM, Elli Lola wrote: > >> $ ./python -m test -v test_urlwithfrag >> >> == CPython 3.3.0 (default, Jan 4 2013, 23:08:00) [GCC 4.6.3] >> == Linux-3.2.0-35-generic-pae-i686-with-debian-wheezy-sid little-endian >> == /home/me/Programme/Python/Python-3.3.0/build/test_python_30744 >> Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, >> optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, >> ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, >> hash_randomization=1) >> [1/1] test_urlwithfrag >> test test_urlwithfrag crashed -- Traceback (most recent call last): >> File "/home/me/Programme/Python/Python-3.3.0/Lib/test/regrtest.py", >> line 1213, in runtest_inner >> the_package = __import__(abstest, globals(), locals(), []) >> ImportError: No module named 'test.test_urlwithfrag' >> >> 1 test failed: >> test_urlwithfrag > > Read the message I sent you before. > > (To everyone else, I already explained that the error message means > exactly what it says and listed the test_urlxxxx files that do exist. No > need to repeat a third time.) > I encountered the OP's error message while building Python 3.3 today. $ make test FAIL: test_urlwithfrag (test.test_urllib2net.OtherNetworkTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/src/packages/BUILD/Python-3.3.0/Lib/test/test_urllib2net.py", line 165, in test_urlwithfrag "http://docs.python.org/glossary.html#glossary") AssertionError: 'http://docs.python.org/2/glossary.html' != 'http://docs.python.org/glossary.html#glossary' - http://docs.python.org/2/glossary.html ? -- + http://docs.python.org/glossary.html#glossary ? +++++++++ ---------------------------------------------------------------------- Ran 15 tests in 15.307s FAILED (failures=1, skipped=1) test test_urllib2net failed make: *** [test] Error 1 $ ./python -m test -v test_urllib2net == CPython 3.3.0 (default, Jan 19 2013, 13:46:53) [GCC 4.6.2] == Linux-3.1.10-1.16-desktop-x86_64-with-SuSE-12.1-x86_64 little-endian == /usr/src/packages/BUILD/Python-3.3.0/build/test_python_10447 Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1) [1/1] test_urllib2net test_urllib2net skipped -- Use of the 'network' resource not enabled 1 test skipped: test_urllib2net Those skips are all expected on linux. $ ./python -m test -v test_urlwithfrag == CPython 3.3.0 (default, Jan 19 2013, 13:46:53) [GCC 4.6.2] == Linux-3.1.10-1.16-desktop-x86_64-with-SuSE-12.1-x86_64 little-endian == /usr/src/packages/BUILD/Python-3.3.0/build/test_python_10453 Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1) [1/1] test_urlwithfrag test test_urlwithfrag crashed -- Traceback (most recent call last): File "/usr/src/packages/BUILD/Python-3.3.0/Lib/test/regrtest.py", line 1213, in runtest_inner the_package = __import__(abstest, globals(), locals(), []) ImportError: No module named 'test.test_urlwithfrag' 1 test failed: test_urlwithfrag The bug has been fixed - see http://bugs.python.org/issue16969 Cheers, Kev From jhsu802701 at gmail.com Mon Jan 7 13:45:19 2013 From: jhsu802701 at gmail.com (Jason Hsu) Date: Mon, 7 Jan 2013 10:45:19 -0800 (PST) Subject: OT: local technical community portals Message-ID: For the Minneapolis/St. Paul area of Minnesota, there is a technical community portal at http://tech.mn/. You'll see that this portal has links to user groups, networking events, jobs, etc. No, I didn't start this thread to tout this site. MY QUESTION: What are the local technical community portals for other places, such as Chicago, Silicon Valley, Los Angeles, San Diego, Dallas, Atlanta, Boston, etc.? From dreamprogu at gmail.com Mon Jan 7 14:08:47 2013 From: dreamprogu at gmail.com (P Dev) Date: Mon, 7 Jan 2013 11:08:47 -0800 (PST) Subject: I'm looking for a Junior level Django job (telecommute) Message-ID: <5ff5f9e8-03ea-45bf-8336-1bab357735ba@googlegroups.com> I'm looking for a Junior level Django job (telecommute) About me: - less than year of experience with Python/Django - Intermediate knowledge of Python/Django - Experience with Linux - Experience with Django ORM - Passion for developing high-quality software and Python language - I am able to use many aplications, for example (south, mptt, django-debug-toolbar etc.) - English: communicative, still learning I would like to develop my qualifications I can be reached anytime via email at dreamprogu at gmail.com Thank you. From kalvinmanual at gmail.com Mon Jan 7 16:21:00 2013 From: kalvinmanual at gmail.com (kalvinmanual) Date: Mon, 07 Jan 2013 15:21:00 -0600 Subject: INSTRUCTOR SOLUTIONS MANUAL :: Engineering Vibration 3rd Ed by Inman Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra and Its Applications 3rd ed by David C. Lay INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra Done Right, 2nd Ed by Sheldon Axler INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra with Applications (6th Ed., S. Leon) INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra with Applications 3rd Ed by Otto Bretscher INSTRUCTOR SOLUTIONS MANUAL :: Linear Algebra With Applications, 2nd Edition by W. Keith Nicholson INSTRUCTOR SOLUTIONS MANUAL :: Linear Circuit Analysis Time Domain, Phasor and Laplace.., 2nd Ed, Lin INSTRUCTOR SOLUTIONS MANUAL :: Linear Circuit Analysis, 2nd Ed by DeCarlo , Pen-Min Lin INSTRUCTOR SOLUTIONS MANUAL :: Linear dynamic systems and signals by Zoran Gajic INSTRUCTOR SOLUTIONS MANUAL :: Linear Systems And Signals, 1stE, B P Lathi INSTRUCTOR SOLUTIONS MANUAL :: Machine Design : An Integrated Approach (3rd Ed., Norton) INSTRUCTOR SOLUTIONS MANUAL :: Machines and Mechanisms - Applied Kinematic Analysis, 3E by David H. Myszka INSTRUCTOR SOLUTIONS MANUAL :: Managerial Accounting 11th Ed by Garrison & Noreen INSTRUCTOR SOLUTIONS MANUAL :: Managerial Accounting 13th E by Garrison, Noreen, Brewer INSTRUCTOR SOLUTIONS MANUAL :: Managing Business and Professional Communication 2nd ed Carley H. Dodd INSTRUCTOR SOLUTIONS MANUAL :: Managing Business Process Flows: Principles of Operations Management(2nd Ed., Anupind, Chopra, Deshmukh, et al) INSTRUCTOR SOLUTIONS MANUAL :: Managing Engineering and Technology (4th, Morse & Babcock) INSTRUCTOR SOLUTIONS MANUAL :: Manufacturing Processes for Engineering Materials (5th Ed. Kalpakjian & Smith) INSTRUCTOR SOLUTIONS MANUAL :: Materials - engineering, science, properties, and design INSTRUCTOR SOLUTIONS MANUAL :: Materials and Processes in Manufacturing (9th Ed., E. Paul DeGarmo, J. T. Black,Kohser) INSTRUCTOR SOLUTIONS MANUAL :: Materials for Civil and Construction Engineers 3rd ED by Mamlouk, Zaniewski INSTRUCTOR SOLUTIONS MANUAL :: Materials Science and Engineering- An Introduction ( 7th Ed., William D. Callister, Jr.) INSTRUCTOR SOLUTIONS MANUAL :: Materials Science and Engineering- An Introduction (6th Ed., William D. Callister, Jr.) INSTRUCTOR SOLUTIONS MANUAL :: MATH 1010 - Applied Finite Mathematics by D.W. Trim INSTRUCTOR SOLUTIONS MANUAL :: Mathematical Analysis, Second Edition by Tom M. Apostol INSTRUCTOR SOLUTIONS MANUAL :: Mathematical Methods for Physicists 5 Ed, Arfken INSTRUCTOR SOLUTIONS MANUAL :: Mathematical Methods for Physics and Engineering, (3rd Ed., Riley,Hobson) INSTRUCTOR SOLUTIONS MANUAL :: Mathematical Methods in the Physical Sciences; 3 edition by Mary L. Boas INSTRUCTOR SOLUTIONS MANUAL :: Mathematical Models in Biology An Introduction (Elizabeth S. Allman & John A. Rhodes) INSTRUCTOR SOLUTIONS MANUAL :: Mathematical Proofs - A Transition to Advanced Mathematics 2nd Ed by Chartrand, Polimeni, Zhang INSTRUCTOR SOLUTIONS MANUAL :: Mathematical Techniques 4th ED by D W Jordan & P Smith INSTRUCTOR SOLUTIONS MANUAL :: Mathematics for Economists, by Carl P. Simon , Lawrence E. Blume INSTRUCTOR SOLUTIONS MANUAL :: Mathematics for Management Science - A Bridging Course by Tulett INSTRUCTOR SOLUTIONS MANUAL :: Mathematics for Physicists by Susan Lea INSTRUCTOR SOLUTIONS MANUAL :: Matrix Analysis and Applied Linear Algebra by Meyer INSTRUCTOR SOLUTIONS MANUAL :: Matter and Interactions, 3rd Ed by Chabay, Sherwood INSTRUCTOR SOLUTIONS MANUAL :: McGraw-Hill Ryerson Calculus & Advanced Function by Dearling, Erdman, et all INSTRUCTOR SOLUTIONS MANUAL :: Mechanical Engineering Design 8th Ed by Shigley & Budynas INSTRUCTOR SOLUTIONS MANUAL :: Mechanical Engineering Design 9th Ed by Shigley & Budynas INSTRUCTOR SOLUTIONS MANUAL :: Mechanical Engineering Design, 7th Ed. by Mischke, Shigley INSTRUCTOR SOLUTIONS MANUAL :: Mechanical Measurements (6th Ed., Beckwith, Marangoni & Lienhard) INSTRUCTOR SOLUTIONS MANUAL :: Mechanical Vibrations ( Vol.1) 4th Ed., Rao INSTRUCTOR SOLUTIONS MANUAL :: Mechanical Vibrations (3rd Ed., Rao) INSTRUCTOR SOLUTIONS MANUAL :: Mechanical Vibrations 4th Ed SI Units by Rao INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Aircraft Structures, 2nd Ed by Sun INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Fluids (8th Ed., Massey) INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Fluids 3rd ED Vol 1 by Merle C. Potter INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials 5 edition by James M. Gere INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials (6th Ed., Riley, Sturges & Morris) INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials 4 E by Russell C. Hibbeler INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials 4th Ed by Beer Johnston INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials 8th E by Russell C. Hibbeler INSTRUCTOR SOLUTIONS MANUAL :: Mechanics Of Materials Beer Johnston 3rd INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials, 2nd Ed by Roy R. Craig INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials, 6E, by Russell C. Hibbeler INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials, 6th Edition - James M. Gere & Barry Goodno INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials, 7E, by Russell C. Hibbeler INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Materials, 7th Edition - James M. Gere & Barry Goodno INSTRUCTOR SOLUTIONS MANUAL :: Mechanics of Solids, ross INSTRUCTOR SOLUTIONS MANUAL :: Mechanism Design Analysis and Synthesis (4th Edition) by Erdman, Sandor, Kota INSTRUCTOR SOLUTIONS MANUAL :: MEMS and Microsystems Design, Manufacture and Nanoscale Engineering 2nd ED by Tai-Ran Hsu INSTRUCTOR SOLUTIONS MANUAL :: Microeconomic Analysis, 3rd Ed., by H. Varian INSTRUCTOR SOLUTIONS MANUAL :: Microeconomic Theory Basic Principles and Extensions 9E ( South-Western ) by Walter Nicholson INSTRUCTOR SOLUTIONS MANUAL :: Microeconomic Theory by Segal Tadelis Hara Chiaka Hara Steve Tadelis INSTRUCTOR SOLUTIONS MANUAL :: Microeconomic Theory, by Mas-Colell, Whinston, Green INSTRUCTOR SOLUTIONS MANUAL :: Microeconomics, 6th Ed by Pyndick, Rubinfeld INSTRUCTOR SOLUTIONS MANUAL :: Microelectronic Circuit Analysis and Design, 3rd Edition, by D. Neamen INSTRUCTOR SOLUTIONS MANUAL :: Microelectronic Circuit Design (3rd Ed., Richard Jaeger & Travis Blalock) INSTRUCTOR SOLUTIONS MANUAL :: Microelectronic Circuits By Adel Sedra 5th Edition INSTRUCTOR SOLUTIONS MANUAL :: Microelectronic Circuits, 4th Ed. by Sedra and Smith INSTRUCTOR SOLUTIONS MANUAL :: Microelectronic Circuits, 5th Ed. by Sedra and Smith INSTRUCTOR SOLUTIONS MANUAL :: Microelectronics Digital and Analog Circuits and Systems by Millman INSTRUCTOR SOLUTIONS MANUAL :: Microelectronics I & II by Dr.Chang INSTRUCTOR SOLUTIONS MANUAL :: Microelectronics,Solution MANUAL,5thEd,MAZ INSTRUCTOR SOLUTIONS MANUAL :: Microprocessors and Interfacing, Revised 2nd Edition by Douglas V Hall INSTRUCTOR SOLUTIONS MANUAL :: Microwave and Rf Design of Wireless Systems, 1st Edition, by Pozar INSTRUCTOR SOLUTIONS MANUAL :: Microwave Engineering, 2nd Ed., by David M. Pozar INSTRUCTOR SOLUTIONS MANUAL :: Microwave Engineering, 3rd Ed., by David M. Pozar INSTRUCTOR SOLUTIONS MANUAL :: Microwave Transistor Amplifiers Analysis and Design, 2nd Ed., by Guillermo Gonzalez INSTRUCTOR SOLUTIONS MANUAL :: Mobile Communications 2nd ed by Jochen Schiller INSTRUCTOR SOLUTIONS MANUAL :: Modern Control Engineering 3rd Ed. - K. OGATA INSTRUCTOR SOLUTIONS MANUAL :: Modern Control Engineering 4th Ed. - K. OGATA INSTRUCTOR SOLUTIONS MANUAL :: Modern Control Engineering 5 Ed. - K. OGATA INSTRUCTOR SOLUTIONS MANUAL :: Modern Control Systems 11E by Richard C Dorf and Robert H. Bishop INSTRUCTOR SOLUTIONS MANUAL :: Modern Control Systems 9 E by Richard C Dorf and Robert H. Bishop INSTRUCTOR SOLUTIONS MANUAL :: Modern Control Systems, 12th Ed by Dorf, Bishop INSTRUCTOR SOLUTIONS MANUAL :: Modern Digital and Analog Communication Systems, 3rd Ed., by Lathi INSTRUCTOR SOLUTIONS MANUAL :: Modern Digital Electronics 3 Ed by R P Jain INSTRUCTOR SOLUTIONS MANUAL :: Modern Digital Electronics,3E by R P JAIN INSTRUCTOR SOLUTIONS MANUAL :: Modern Digital Signal Processing-Roberto Cristi INSTRUCTOR SOLUTIONS MANUAL :: MODERN OPERATING SYSTEMS 2nd ed A.S.TANENBAUM INSTRUCTOR SOLUTIONS MANUAL :: Modern Organic Synthesis An Introduction by George Zweifel, Michael Nantz INSTRUCTOR SOLUTIONS MANUAL :: Modern Physics 2nd E by Randy Harris INSTRUCTOR SOLUTIONS MANUAL :: Modern Physics 4th ed by Mark Llewellyn INSTRUCTOR SOLUTIONS MANUAL :: Modern Physics for Scientists and Engineers 3rd E by Thornton and Rex INSTRUCTOR SOLUTIONS MANUAL :: MODERN POWER SYSTEM ANALYSIS 3rd E by Kothari,Nagrath INSTRUCTOR SOLUTIONS MANUAL :: Modern Quantum Mechanics (Revised Edition) by J. J. Sakurai INSTRUCTOR SOLUTIONS MANUAL :: Modern Thermodynamics - From Heat Engines to Dissipative Structures by Kondepudi, Prigogine INSTRUCTOR SOLUTIONS MANUAL :: Modern Thermodynamics - From Heat Engines to Dissipative Structures Vol 1 by Kondepudi, Prigogine INSTRUCTOR SOLUTIONS MANUAL :: Molecular Driving Forces 2nd ED ( vol.1 ) by Dill, Bromberg INSTRUCTOR SOLUTIONS MANUAL :: Molecular Symmetry and Group Theory by Robert L. Carter INSTRUCTOR SOLUTIONS MANUAL :: Multinational Business Finance 10 E by Stonehill, Moffett, Eiteman INSTRUCTOR SOLUTIONS MANUAL :: Multivariable Calculus, 4th Edition, JAMES STEWART INSTRUCTOR SOLUTIONS MANUAL :: Multivariable Calculus, 5th Edition, JAMES STEWART INSTRUCTOR SOLUTIONS MANUAL :: Multivariable Calculus, Applications and Theory by Kenneth Kuttler From victorhooi at gmail.com Mon Jan 7 17:10:10 2013 From: victorhooi at gmail.com (Victor Hooi) Date: Mon, 7 Jan 2013 14:10:10 -0800 (PST) Subject: Searching through two logfiles in parallel? Message-ID: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> Hi, I'm trying to compare two logfiles in Python. One logfile will have lines recording the message being sent: 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 the other logfile has line recording the message being received 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 The goal is to compare the time stamp between the two - we can safely assume the timestamp on the message being received is later than the timestamp on transmission. If it was a direct line-by-line, I could probably use itertools.izip(), right? However, it's not a direct line-by-line comparison of the two files - the lines I'm looking for are interspersed among other loglines, and the time difference between sending/receiving is quite variable. So the idea is to iterate through the sending logfile - then iterate through the receiving logfile from that timestamp forwards, looking for the matching pair. Obviously I want to minimise the amount of back-forth through the file. Also, there is a chance that certain messages could get lost - so I assume there's a threshold after which I want to give up searching for the matching received message, and then just try to resync to the next sent message. Is there a Pythonic way, or some kind of idiom that I can use to approach this problem? Cheers, Victor From oscar.j.benjamin at gmail.com Mon Jan 7 17:58:36 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 7 Jan 2013 22:58:36 +0000 Subject: Searching through two logfiles in parallel? In-Reply-To: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> References: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> Message-ID: On 7 January 2013 22:10, Victor Hooi wrote: > Hi, > > I'm trying to compare two logfiles in Python. > > One logfile will have lines recording the message being sent: > > 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 > > the other logfile has line recording the message being received > > 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 > > The goal is to compare the time stamp between the two - we can safely assume the timestamp on the message being received is later than the timestamp on transmission. > > If it was a direct line-by-line, I could probably use itertools.izip(), right? > > However, it's not a direct line-by-line comparison of the two files - the lines I'm looking for are interspersed among other loglines, and the time difference between sending/receiving is quite variable. > > So the idea is to iterate through the sending logfile - then iterate through the receiving logfile from that timestamp forwards, looking for the matching pair. Obviously I want to minimise the amount of back-forth through the file. > > Also, there is a chance that certain messages could get lost - so I assume there's a threshold after which I want to give up searching for the matching received message, and then just try to resync to the next sent message. > > Is there a Pythonic way, or some kind of idiom that I can use to approach this problem? Assuming that you can impose a maximum time between the send and recieve timestamps, something like the following might work (untested): def find_matching(logfile1, logfile2, maxdelta): buf = {} logfile2 = iter(logfile2) for msg1 in logfile1: if msg1.key in buf: yield msg1, buf.pop(msg1.key) continue maxtime = msg1.time + maxdelta for msg2 in logfile2: if msg2.key == msg1.key: yield msg1, msg2 break buf[msg2.key] = msg2 if msg2.time > maxtime: break else: yield msg1, 'No match' Oscar From victorhooi at gmail.com Mon Jan 7 18:41:02 2013 From: victorhooi at gmail.com (Victor Hooi) Date: Mon, 7 Jan 2013 15:41:02 -0800 (PST) Subject: Searching through two logfiles in parallel? In-Reply-To: References: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> Message-ID: Hi Oscar, Thanks for the quick reply =). I'm trying to understand your code properly, and it seems like for each line in logfile1, we loop through all of logfile2? The idea was that it would remember it's position in logfile2 as well - since we can assume that the loglines are in chronological order - we only need to search forwards in logfile2 each time, not from the beginning each time. So for example - logfile1: 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 05:00:08 Message sent - Value A: 3.3, Value B: 4.3, Value C: 2.3 05:00:14 Message sent - Value A: 1.0, Value B: 0.4, Value C: 5.4 logfile2: 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 05:00:12 Message received - Value A: 3.3, Value B: 4.3, Value C: 2.3 05:00:15 Message received - Value A: 1.0, Value B: 0.4, Value C: 5.4 The idea is that I'd iterate through logfile 1 - I'd get the 05:00:06 logline - I'd search through logfile2 and find the 05:00:09 logline. Then, back in logline1 I'd find the next logline at 05:00:08. Then in logfile2, instead of searching back from the beginning, I'd start from the next line, which happens to be 5:00:12. In reality, I'd need to handle missing messages in logfile2, but that's the general idea. Does that make sense? (There's also a chance I've misunderstood your buf code, and it does do this - in that case, I apologies - is there any chance you could explain it please?) Cheers, Victor On Tuesday, 8 January 2013 09:58:36 UTC+11, Oscar Benjamin wrote: > On 7 January 2013 22:10, Victor Hooi wrote: > > > Hi, > > > > > > I'm trying to compare two logfiles in Python. > > > > > > One logfile will have lines recording the message being sent: > > > > > > 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 > > > > > > the other logfile has line recording the message being received > > > > > > 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 > > > > > > The goal is to compare the time stamp between the two - we can safely assume the timestamp on the message being received is later than the timestamp on transmission. > > > > > > If it was a direct line-by-line, I could probably use itertools.izip(), right? > > > > > > However, it's not a direct line-by-line comparison of the two files - the lines I'm looking for are interspersed among other loglines, and the time difference between sending/receiving is quite variable. > > > > > > So the idea is to iterate through the sending logfile - then iterate through the receiving logfile from that timestamp forwards, looking for the matching pair. Obviously I want to minimise the amount of back-forth through the file. > > > > > > Also, there is a chance that certain messages could get lost - so I assume there's a threshold after which I want to give up searching for the matching received message, and then just try to resync to the next sent message. > > > > > > Is there a Pythonic way, or some kind of idiom that I can use to approach this problem? > > > > Assuming that you can impose a maximum time between the send and > > recieve timestamps, something like the following might work > > (untested): > > > > def find_matching(logfile1, logfile2, maxdelta): > > buf = {} > > logfile2 = iter(logfile2) > > for msg1 in logfile1: > > if msg1.key in buf: > > yield msg1, buf.pop(msg1.key) > > continue > > maxtime = msg1.time + maxdelta > > for msg2 in logfile2: > > if msg2.key == msg1.key: > > yield msg1, msg2 > > break > > buf[msg2.key] = msg2 > > if msg2.time > maxtime: > > break > > else: > > yield msg1, 'No match' > > > > > > Oscar From victorhooi at gmail.com Mon Jan 7 18:41:02 2013 From: victorhooi at gmail.com (Victor Hooi) Date: Mon, 7 Jan 2013 15:41:02 -0800 (PST) Subject: Searching through two logfiles in parallel? In-Reply-To: References: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> Message-ID: Hi Oscar, Thanks for the quick reply =). I'm trying to understand your code properly, and it seems like for each line in logfile1, we loop through all of logfile2? The idea was that it would remember it's position in logfile2 as well - since we can assume that the loglines are in chronological order - we only need to search forwards in logfile2 each time, not from the beginning each time. So for example - logfile1: 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 05:00:08 Message sent - Value A: 3.3, Value B: 4.3, Value C: 2.3 05:00:14 Message sent - Value A: 1.0, Value B: 0.4, Value C: 5.4 logfile2: 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 05:00:12 Message received - Value A: 3.3, Value B: 4.3, Value C: 2.3 05:00:15 Message received - Value A: 1.0, Value B: 0.4, Value C: 5.4 The idea is that I'd iterate through logfile 1 - I'd get the 05:00:06 logline - I'd search through logfile2 and find the 05:00:09 logline. Then, back in logline1 I'd find the next logline at 05:00:08. Then in logfile2, instead of searching back from the beginning, I'd start from the next line, which happens to be 5:00:12. In reality, I'd need to handle missing messages in logfile2, but that's the general idea. Does that make sense? (There's also a chance I've misunderstood your buf code, and it does do this - in that case, I apologies - is there any chance you could explain it please?) Cheers, Victor On Tuesday, 8 January 2013 09:58:36 UTC+11, Oscar Benjamin wrote: > On 7 January 2013 22:10, Victor Hooi wrote: > > > Hi, > > > > > > I'm trying to compare two logfiles in Python. > > > > > > One logfile will have lines recording the message being sent: > > > > > > 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 > > > > > > the other logfile has line recording the message being received > > > > > > 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 > > > > > > The goal is to compare the time stamp between the two - we can safely assume the timestamp on the message being received is later than the timestamp on transmission. > > > > > > If it was a direct line-by-line, I could probably use itertools.izip(), right? > > > > > > However, it's not a direct line-by-line comparison of the two files - the lines I'm looking for are interspersed among other loglines, and the time difference between sending/receiving is quite variable. > > > > > > So the idea is to iterate through the sending logfile - then iterate through the receiving logfile from that timestamp forwards, looking for the matching pair. Obviously I want to minimise the amount of back-forth through the file. > > > > > > Also, there is a chance that certain messages could get lost - so I assume there's a threshold after which I want to give up searching for the matching received message, and then just try to resync to the next sent message. > > > > > > Is there a Pythonic way, or some kind of idiom that I can use to approach this problem? > > > > Assuming that you can impose a maximum time between the send and > > recieve timestamps, something like the following might work > > (untested): > > > > def find_matching(logfile1, logfile2, maxdelta): > > buf = {} > > logfile2 = iter(logfile2) > > for msg1 in logfile1: > > if msg1.key in buf: > > yield msg1, buf.pop(msg1.key) > > continue > > maxtime = msg1.time + maxdelta > > for msg2 in logfile2: > > if msg2.key == msg1.key: > > yield msg1, msg2 > > break > > buf[msg2.key] = msg2 > > if msg2.time > maxtime: > > break > > else: > > yield msg1, 'No match' > > > > > > Oscar From oscar.j.benjamin at gmail.com Mon Jan 7 19:33:05 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 8 Jan 2013 00:33:05 +0000 Subject: Searching through two logfiles in parallel? In-Reply-To: References: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> Message-ID: On 7 January 2013 23:41, Victor Hooi wrote: > Hi Oscar, > > Thanks for the quick reply =). > > I'm trying to understand your code properly, and it seems like for each line in logfile1, we loop through all of logfile2? No we don't. It iterates once through both files but keeps a buffer of lines that are within maxdelta time of the current message. The important line is the line that calls iter(logfile2). Since logfile2 is replaced by an iterator when we break out of the inner for loop and then re-enter our place in the iterator is saved. If you can follow the interactive session below it should make sense: >>> a = [1,2,3,4,5] >>> for x in a: ... print x, ... 1 2 3 4 5 >>> for x in a: ... print x, ... 1 2 3 4 5 >>> it = iter(a) >>> next(it) 1 >>> for x in it: ... print x, ... 2 3 4 5 >>> next(it) Traceback (most recent call last): File "", line 1, in StopIteration >>> for x in it: ... print x, ... >>> it = iter(a) >>> for x in it: ... print x, ... if x == 2: break ... 1 2 >>> for x in it: ... print x, ... 3 4 5 I'll repeat the code (with a slight fix): def find_matching(logfile1, logfile2, maxdelta): buf = {} logfile2 = iter(logfile2) for msg1 in logfile1: if msg1.key in buf: yield msg1, buf.pop(msg1.key) continue maxtime = msg1.time + maxdelta for msg2 in logfile2: if msg2.key == msg1.key: yield msg1, msg2 break buf[msg2.key] = msg2 if msg2.time > maxtime: yield msg1, 'No match' break else: yield msg1, 'No match' Oscar > > The idea was that it would remember it's position in logfile2 as well - since we can assume that the loglines are in chronological order - we only need to search forwards in logfile2 each time, not from the beginning each time. > > So for example - logfile1: > > 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 > 05:00:08 Message sent - Value A: 3.3, Value B: 4.3, Value C: 2.3 > 05:00:14 Message sent - Value A: 1.0, Value B: 0.4, Value C: 5.4 > > logfile2: > > 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 > 05:00:12 Message received - Value A: 3.3, Value B: 4.3, Value C: 2.3 > 05:00:15 Message received - Value A: 1.0, Value B: 0.4, Value C: 5.4 > > The idea is that I'd iterate through logfile 1 - I'd get the 05:00:06 logline - I'd search through logfile2 and find the 05:00:09 logline. > > Then, back in logline1 I'd find the next logline at 05:00:08. Then in logfile2, instead of searching back from the beginning, I'd start from the next line, which happens to be 5:00:12. > > In reality, I'd need to handle missing messages in logfile2, but that's the general idea. > > Does that make sense? (There's also a chance I've misunderstood your buf code, and it does do this - in that case, I apologies - is there any chance you could explain it please?) > > Cheers, > Victor > > On Tuesday, 8 January 2013 09:58:36 UTC+11, Oscar Benjamin wrote: >> On 7 January 2013 22:10, Victor Hooi wrote: >> >> > Hi, >> >> > >> >> > I'm trying to compare two logfiles in Python. >> >> > >> >> > One logfile will have lines recording the message being sent: >> >> > >> >> > 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 >> >> > >> >> > the other logfile has line recording the message being received >> >> > >> >> > 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 >> >> > >> >> > The goal is to compare the time stamp between the two - we can safely assume the timestamp on the message being received is later than the timestamp on transmission. >> >> > >> >> > If it was a direct line-by-line, I could probably use itertools.izip(), right? >> >> > >> >> > However, it's not a direct line-by-line comparison of the two files - the lines I'm looking for are interspersed among other loglines, and the time difference between sending/receiving is quite variable. >> >> > >> >> > So the idea is to iterate through the sending logfile - then iterate through the receiving logfile from that timestamp forwards, looking for the matching pair. Obviously I want to minimise the amount of back-forth through the file. >> >> > >> >> > Also, there is a chance that certain messages could get lost - so I assume there's a threshold after which I want to give up searching for the matching received message, and then just try to resync to the next sent message. >> >> > >> >> > Is there a Pythonic way, or some kind of idiom that I can use to approach this problem? >> >> >> >> Assuming that you can impose a maximum time between the send and >> >> recieve timestamps, something like the following might work >> >> (untested): >> >> >> >> def find_matching(logfile1, logfile2, maxdelta): >> >> buf = {} >> >> logfile2 = iter(logfile2) >> >> for msg1 in logfile1: >> >> if msg1.key in buf: >> >> yield msg1, buf.pop(msg1.key) >> >> continue >> >> maxtime = msg1.time + maxdelta >> >> for msg2 in logfile2: >> >> if msg2.key == msg1.key: >> >> yield msg1, msg2 >> >> break >> >> buf[msg2.key] = msg2 >> >> if msg2.time > maxtime: >> >> break >> >> else: >> >> yield msg1, 'No match' >> >> >> >> >> >> Oscar > -- > http://mail.python.org/mailman/listinfo/python-list From darnold992000 at yahoo.com Tue Jan 8 14:16:09 2013 From: darnold992000 at yahoo.com (darnold) Date: Tue, 8 Jan 2013 11:16:09 -0800 (PST) Subject: Searching through two logfiles in parallel? References: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> Message-ID: <7662762a-1dca-4e9d-8a43-ccd34051fc8e@b8g2000yqh.googlegroups.com> i don't think in iterators (yet), so this is a bit wordy. same basic idea, though: for each message (set of parameters), build a list of transactions consisting of matching send/receive times. mildly tested: from datetime import datetime, timedelta sendData = '''\ 05:00:06 Message sent - Value A: 5.6, Value B: 6.2, Value C: 9.9 05:00:08 Message sent - Value A: 3.3, Value B: 4.3, Value C: 2.3 05:00:10 Message sent - Value A: 3.0, Value B: 0.4, Value C: 5.4 #orphan 05:00:14 Message sent - Value A: 1.0, Value B: 0.4, Value C: 5.4 07:00:14 Message sent - Value A: 1.0, Value B: 0.4, Value C: 5.4 ''' receiveData = '''\ 05:00:09 Message received - Value A: 5.6, Value B: 6.2, Value C: 9.9 05:00:12 Message received - Value A: 3.3, Value B: 4.3, Value C: 2.3 05:00:15 Message received - Value A: 1.0, Value B: 0.4, Value C: 5.4 07:00:18 Message received - Value A: 1.0, Value B: 0.4, Value C: 5.4 07:00:30 Message received - Value A: 1.0, Value B: 0.4, Value C: 5.4 #orphan 07:00:30 Message received - Value A: 17.0, Value B: 0.4, Value C: 5.4 #orphan ''' def parse(line): timestamp, rest = line.split(' Message ') action, params = rest.split(' - ' ) params = params.split('#')[0] return timestamp.strip(), params.strip() def isMatch(sendTime,receiveTime,maxDelta): if sendTime is None: return False sendDT = datetime.strptime(sendTime,'%H:%M:%S') receiveDT = datetime.strptime(receiveTime,'%H:%M:%S') return receiveDT - sendDT <= maxDelta results = {} for line in sendData.split('\n'): if not line.strip(): continue timestamp, params = parse(line) if params not in results: results[params] = [{'sendTime': timestamp, 'receiveTime': None}] else: results[params].append({'sendTime': timestamp, 'receiveTime': None}) for line in receiveData.split('\n'): if not line.strip(): continue timestamp, params = parse(line) if params not in results: results[params] = [{'sendTime': None, 'receiveTime': timestamp}] else: for tranNum, transaction in enumerate(results[params]): if isMatch(transaction['sendTime'],timestamp,timedelta(seconds=5)): results[params][tranNum]['receiveTime'] = timestamp break else: results[params].append({'sendTime': None, 'receiveTime': timestamp}) for params in sorted(results): print params for transaction in results[params]: print '\t%s' % transaction >>> ================================ RESTART ================================ >>> Value A: 1.0, Value B: 0.4, Value C: 5.4 {'sendTime': '05:00:14', 'receiveTime': '05:00:15'} {'sendTime': '07:00:14', 'receiveTime': '07:00:18'} {'sendTime': None, 'receiveTime': '07:00:30'} Value A: 17.0, Value B: 0.4, Value C: 5.4 {'sendTime': None, 'receiveTime': '07:00:30'} Value A: 3.0, Value B: 0.4, Value C: 5.4 {'sendTime': '05:00:10', 'receiveTime': None} Value A: 3.3, Value B: 4.3, Value C: 2.3 {'sendTime': '05:00:08', 'receiveTime': '05:00:12'} Value A: 5.6, Value B: 6.2, Value C: 9.9 {'sendTime': '05:00:06', 'receiveTime': '05:00:09'} >>> HTH, Don From oscar.j.benjamin at gmail.com Tue Jan 8 18:40:01 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 8 Jan 2013 23:40:01 +0000 Subject: Searching through two logfiles in parallel? In-Reply-To: <7662762a-1dca-4e9d-8a43-ccd34051fc8e@b8g2000yqh.googlegroups.com> References: <8990fb07-fbd2-47ab-8b83-97d34580ebe3@googlegroups.com> <7662762a-1dca-4e9d-8a43-ccd34051fc8e@b8g2000yqh.googlegroups.com> Message-ID: On 8 January 2013 19:16, darnold wrote: > i don't think in iterators (yet), so this is a bit wordy. > same basic idea, though: for each message (set of parameters), build a > list of transactions consisting of matching send/receive times. The advantage of an iterator based solution is that we can avoid loading all of both log files into memory. [SNIP] > > results = {} > > for line in sendData.split('\n'): > if not line.strip(): > continue > > timestamp, params = parse(line) > if params not in results: > results[params] = [{'sendTime': timestamp, 'receiveTime': > None}] > else: > results[params].append({'sendTime': timestamp, 'receiveTime': > None}) [SNIP] This kind of logic is made a little easier (and more efficient) if you use a collections.defaultdict instead of a dict since it saves needing to check if the key is in the dict yet. Example: >>> import collections >>> results = collections.defaultdict(list) >>> results defaultdict(, {}) >>> results['asd'].append(1) >>> results defaultdict(, {'asd': [1]}) >>> results['asd'].append(2) >>> results defaultdict(, {'asd': [1, 2]}) >>> results['qwe'].append(3) >>> results defaultdict(, {'qwe': [3], 'asd': [1, 2]}) Oscar From naccttemha at gmail.com Mon Jan 7 19:44:04 2013 From: naccttemha at gmail.com (Nac Temha) Date: Tue, 8 Jan 2013 02:44:04 +0200 Subject: Calculate Big Number Message-ID: Hello, How to *quickly* calculate large numbers. For example >>> (10**25) * (2**50) 11258999068426240000000000000000000000000L Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Mon Jan 7 19:52:33 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 8 Jan 2013 00:52:33 +0000 Subject: Calculate Big Number In-Reply-To: References: Message-ID: On 8 January 2013 00:44, Nac Temha wrote: > Hello, > How to quickly calculate large numbers. For example >>>> (10**25) * (2**50) > 11258999068426240000000000000000000000000L I just tested that line in the interpreter and it ran so quickly it seemed instantaneous (maybe my computer is faster than yours). Perhaps you could provide more of an explanation about what isn't fast enough and why? Oscar From python.list at tim.thechases.com Mon Jan 7 20:08:17 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 07 Jan 2013 19:08:17 -0600 Subject: Calculate Big Number In-Reply-To: References: Message-ID: <50EB7181.8060306@tim.thechases.com> On 01/07/13 18:44, Nac Temha wrote: > How to *quickly* calculate large numbers. For example >>>> (10**25) * (2**50) > 11258999068426240000000000000000000000000L that's how...just do the math. For any other sort of answer, you'd have to clarify your question. On my laptop, that operation came back as quickly as I could press -tkc From naccttemha at gmail.com Mon Jan 7 20:22:31 2013 From: naccttemha at gmail.com (Nac Temha) Date: Tue, 8 Jan 2013 03:22:31 +0200 Subject: Calculate Big Number In-Reply-To: <50EB7181.8060306@tim.thechases.com> References: <50EB7181.8060306@tim.thechases.com> Message-ID: Thanks for reply. I wonder how quickly calculate big numbers. Can you explain me as theoretical? Because this numbers overflow size of integer and double. On Tue, Jan 8, 2013 at 3:08 AM, Tim Chase wrote: > On 01/07/13 18:44, Nac Temha wrote: > >> How to *quickly* calculate large numbers. For example >> >>> (10**25) * (2**50) >>>>> >>>> 112589990684262400000000000000**00000000000L >> > > that's how...just do the math. For any other sort of answer, you'd have > to clarify your question. On my laptop, that operation came back as > quickly as I could press > > -tkc > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Mon Jan 7 20:39:31 2013 From: d at davea.name (Dave Angel) Date: Mon, 07 Jan 2013 20:39:31 -0500 Subject: Calculate Big Number In-Reply-To: References: <50EB7181.8060306@tim.thechases.com> Message-ID: <50EB78D3.9020606@davea.name> On 01/07/2013 08:22 PM, Nac Temha wrote: > Thanks for reply. I wonder how quickly calculate big numbers. Can you > explain me as theoretical? Because this numbers overflow size of integer > and double. Please don't top-post. It makes the context totally out of order. Python automatically promotes to long when doing integer arithmetic, and the numbers grow too big. And on version 3, there's no distinction. floats are not used, or there would be errors. Your "wonder statement" is not complete, so I'm not sure what you're asking. Could you elaborate? Are you asking to see the source code for the python interpreter that's responsible for this? Or an algorithm that it might use? Are you curious in a language-agnostic way how one might do multiple-precision arithmetic? I've written arithmetic packages in PL/I and in BASIC, plus implemented the microcoded math in one processor. So, for example, I might explain how one could compute X**Y when Y is a positive integer, without doing Y-1 multiplies. -- DaveA From d at davea.name Mon Jan 7 21:24:18 2013 From: d at davea.name (Dave Angel) Date: Mon, 07 Jan 2013 21:24:18 -0500 Subject: Calculate Big Number In-Reply-To: References: <50EB7181.8060306@tim.thechases.com> <50EB78D3.9020606@davea.name> Message-ID: <50EB8352.9080102@davea.name> (forwarding the private reply to the group) On 01/07/2013 09:03 PM, Nac Temha wrote: > Thanks. I using version 2.7 .I want to understand how to handling big > number. Just want to know logic. Without going into further details but I > want to learn logic of this issue. How to keep datas in python? Using data > structure? and datas how to handling for calculating? > > Since I don't understand your questions, I'll make some guesses. If these don't cover it, please reword your questions. I'll assume you do NOT want internal details of how the python interpreter manages it. I'll assume you DO want to know how to write your python program so that as much accuracy as possible is used in the calculations. First comment - as soon as you introduce a floating point (non-integer) value into the expression, you have the potential of losing precision. In general, when doing mixed arithmetic, python will convert the result to float. Lots can be written (and has been written) about floats, Decimals, quantization and rounding. I'm again assuming you're NOT asking about these. In Python 2.7, there are two kinds of integers, int and long. An int is limited to some processor-specific size, usually 32 or 64 bits. A long has no practical limit, though after a few hundred million digits, it gets pretty memory hungry and piggishly slow. A long is NOT related to the C type of the same name. If you have an integer in your source code that's larger than that limit, it'll automatically be promoted to long. If you want to see the type of a particular object, you can use type(myobj). For example, print type(2397493749328734972349873) will print: If you add, subtract, multiply or ** two int objects, and the result is too big for an int, it'll automatically be promoted to long. If you divide two integers with / the result is floored. Thus the result is an integer. That changes in Python 3, where you can get this result with //. If you call some library function on a long, it may or may not be able to handle it, check the docs. But in your own code, it's pretty easy to keep things clean. If you have more questions, please be specific. -- DaveA From roy at panix.com Mon Jan 7 20:41:20 2013 From: roy at panix.com (Roy Smith) Date: Mon, 07 Jan 2013 20:41:20 -0500 Subject: Calculate Big Number References: <50EB7181.8060306@tim.thechases.com> Message-ID: In article , Nac Temha wrote: > Thanks for reply. I wonder how quickly calculate big numbers. Can you > explain me as theoretical? Because this numbers overflow size of integer > and double. Now, that's a good question. The answer is that Python implements multiple-precision arithmetic. This is an awesome feature, as it means you never have to worry about integer overflow again. A good introduction to the subject can be found at http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic From rosuav at gmail.com Mon Jan 7 20:15:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 12:15:13 +1100 Subject: Calculate Big Number In-Reply-To: References: Message-ID: On Tue, Jan 8, 2013 at 11:44 AM, Nac Temha wrote: > Hello, > How to quickly calculate large numbers. For example >>>> (10**25) * (2**50) > 11258999068426240000000000000000000000000L Step 1: Find a girl. Step 2: Tell her she's one in a million. Step 3: Realize that that implies that there are several thousand girls just like her. Step 4: Start calculating large numbers in order to sound mushy and romantic. If she's a geek, tell her she's one in a googolplex. ChrisA From rtomek at ceti.pl Mon Jan 7 19:59:23 2013 From: rtomek at ceti.pl (Tomasz Rola) Date: Tue, 8 Jan 2013 01:59:23 +0100 (CET) Subject: Calculate Big Number In-Reply-To: References: Message-ID: On Tue, 8 Jan 2013, Nac Temha wrote: > Hello, > How to *quickly* calculate large numbers. For example > >>> (10**25) * (2**50) > 11258999068426240000000000000000000000000L > Um, Karatsuba multiplication? http://en.wikipedia.org/wiki/Karatsuba_algorithm Or see what GMP folks are doing: http://en.wikipedia.org/wiki/GNU_Multi-Precision_Library Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From d at davea.name Mon Jan 7 20:38:40 2013 From: d at davea.name (Dave Angel) Date: Mon, 07 Jan 2013 20:38:40 -0500 Subject: Calculate Big Number In-Reply-To: References: Message-ID: <50EB78A0.602@davea.name> On 01/07/2013 07:44 PM, Nac Temha wrote: > Hello, > How to *quickly* calculate large numbers. For example >>>> (10**25) * (2**50) > 11258999068426240000000000000000000000000L > > Since all of the terms are const, you could just use print "11258999068426240000000000000000000000000L" Or if you have some constraints on those numbers, you could preprocess the calculation with meatware. For example, if you wnated (10**var1) * (var2**var3), where var1, var2 and var3 are all ints, then you could save some time by doing: print str(var2**var3)+"0"*var1 Or you could write C code to do multiprecision arithmetic. Or ... What are your constraints? If you have to calculate an arbitrary expression of ints and longs, you'll spend a lot more time typing it in than the computer will calculating it. BTW, if you want a non-trivial answer, you should specify what Python version you're targeting. I arbitrarily chose 2.7 for my response.m -- DaveA From steve+comp.lang.python at pearwood.info Tue Jan 8 00:50:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Jan 2013 05:50:58 GMT Subject: Calculate Big Number References: Message-ID: <50ebb3c1$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 08 Jan 2013 02:44:04 +0200, Nac Temha wrote: > Hello, > How to *quickly* calculate large numbers. For example >>>> (10**25) * (2**50) > 11258999068426240000000000000000000000000L Timing how long that takes is trickier than it seems, because modern versions of Python include a keyhole optimizer that will optimize some, or all, of that calculation to constant(s). In Python 2.7: py> import dis py> code = compile("(10**25) * (2**50)", "", "single") py> dis.dis(code) 1 0 LOAD_CONST 5 (10000000000000000000000000L) 3 LOAD_CONST 6 (1125899906842624L) 6 BINARY_MULTIPLY 7 PRINT_EXPR 8 LOAD_CONST 4 (None) 11 RETURN_VALUE So, here's the best of five attempts to calculate the above in full, with no optimizations, one hundred thousand times: py> from timeit import Timer py> t1 = Timer("(a**b)*(c**d)", setup="a,b,c,d = 10, 25, 2, 50") py> min(t1.repeat(repeat=5, number=100000)) 0.5256571769714355 So that's about 5 microseconds on my (slow) computer. You can find the source code here: http://hg.python.org/cpython/file/944e86223d1f/Objects/longobject.c -- Steven From gvanem at broadpark.no Tue Jan 8 05:06:09 2013 From: gvanem at broadpark.no (Gisle Vanem) Date: Tue, 08 Jan 2013 11:06:09 +0100 Subject: Calculate Big Number References: <50ebb3c1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote: > py> from timeit import Timer > py> t1 = Timer("(a**b)*(c**d)", setup="a,b,c,d = 10, 25, 2, 50") > py> min(t1.repeat(repeat=5, number=100000)) > 0.5256571769714355 > > So that's about 5 microseconds on my (slow) computer. That's pretty fast. So is there still a need for a GMP python-binding like gmpy? http://code.google.com/p/gmpy/wiki/IntroductionToGmpy GMP can include optimized assembler for the CPU you're using. But I guess it needs more memory. Hence disk-swapping could be an issue on performance. --gv From casevh at gmail.com Tue Jan 8 11:33:03 2013 From: casevh at gmail.com (casevh at gmail.com) Date: Tue, 8 Jan 2013 08:33:03 -0800 (PST) Subject: Calculate Big Number In-Reply-To: References: <50ebb3c1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, January 8, 2013 2:06:09 AM UTC-8, Gisle Vanem wrote: > "Steven D'Aprano" wrote: > > > py> from timeit import Timer > > py> t1 = Timer("(a**b)*(c**d)", setup="a,b,c,d = 10, 25, 2, 50") > > py> min(t1.repeat(repeat=5, number=100000)) > > 0.5256571769714355 > > > > So that's about 5 microseconds on my (slow) computer. > > That's pretty fast. So is there still a need for a GMP python-binding like > gmpy? http://code.google.com/p/gmpy/wiki/IntroductionToGmpy > > GMP can include optimized assembler for the CPU you're using. But > I guess it needs more memory. Hence disk-swapping could be an issue > on performance. > gmpy will be faster than Python as the numbers get larger. The cutover varies depending on the platform, but usually occurs between 50 and 100 digits. casevh > > --gv From casevh at gmail.com Tue Jan 8 11:33:03 2013 From: casevh at gmail.com (casevh at gmail.com) Date: Tue, 8 Jan 2013 08:33:03 -0800 (PST) Subject: Calculate Big Number In-Reply-To: References: <50ebb3c1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, January 8, 2013 2:06:09 AM UTC-8, Gisle Vanem wrote: > "Steven D'Aprano" wrote: > > > py> from timeit import Timer > > py> t1 = Timer("(a**b)*(c**d)", setup="a,b,c,d = 10, 25, 2, 50") > > py> min(t1.repeat(repeat=5, number=100000)) > > 0.5256571769714355 > > > > So that's about 5 microseconds on my (slow) computer. > > That's pretty fast. So is there still a need for a GMP python-binding like > gmpy? http://code.google.com/p/gmpy/wiki/IntroductionToGmpy > > GMP can include optimized assembler for the CPU you're using. But > I guess it needs more memory. Hence disk-swapping could be an issue > on performance. > gmpy will be faster than Python as the numbers get larger. The cutover varies depending on the platform, but usually occurs between 50 and 100 digits. casevh > > --gv From redstone-cold at 163.com Mon Jan 7 19:44:20 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 7 Jan 2013 16:44:20 -0800 (PST) Subject: How to implement mouse gesture by python or pyqt ? Message-ID: <06fe2548-aa2c-4e66-8a59-474a7a4fc484@googlegroups.com> It would be better to give me some examples .thanks in advance ! P.S. which module or lib are needed ? From redstone-cold at 163.com Tue Jan 8 21:57:12 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 8 Jan 2013 18:57:12 -0800 (PST) Subject: How to implement mouse gesture by python or pyqt ? In-Reply-To: <06fe2548-aa2c-4e66-8a59-474a7a4fc484@googlegroups.com> References: <06fe2548-aa2c-4e66-8a59-474a7a4fc484@googlegroups.com> Message-ID: <4dc2d029-8b1a-494c-8c3e-fccb56ffff42@googlegroups.com> ? 2013?1?8????UTC+8??8?44?20??iMath??? > It would be better to give me some examples .thanks in advance ! > > > > P.S. which module or lib are needed ? what I wanna perhaps like this: when a right mouse button is pressed and we go down and right with a cursor. As in letter 'L'. Our mouse gesture will close the window. I googled such gesture examples on PyQt4 ,but hard to find one ,so your help will be greatly appreciated ! thanks inadvance ! From torriem at gmail.com Wed Jan 9 19:06:13 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 09 Jan 2013 17:06:13 -0700 Subject: How to implement mouse gesture by python or pyqt ? In-Reply-To: <4dc2d029-8b1a-494c-8c3e-fccb56ffff42@googlegroups.com> References: <06fe2548-aa2c-4e66-8a59-474a7a4fc484@googlegroups.com> <4dc2d029-8b1a-494c-8c3e-fccb56ffff42@googlegroups.com> Message-ID: <50EE05F5.4010506@gmail.com> On 01/08/2013 07:57 PM, iMath wrote: > ? 2013?1?8????UTC+8??8?44?20??iMath??? >> It would be better to give me some examples .thanks in advance ! >> >> >> >> P.S. which module or lib are needed ? > > what I wanna perhaps like this: when a right mouse button is pressed > and we go down and right with a cursor. As in letter 'L'. Our mouse > gesture will close the window. I googled such gesture examples on > PyQt4 ,but hard to find one ,so your help will be greatly appreciated > ! thanks inadvance ! My guess is that if you google for it you'll find a gesture recognition module for python. moosegesture.py is one such implementation. However it is up to you to tie it into your chosen GUI toolkit. It merely processes tuples of points in the gesture. Each GUI toolkit has mailing lists and forums that would help you know that information, which is not really python-specific. From redstone-cold at 163.com Wed Jan 9 21:41:37 2013 From: redstone-cold at 163.com (iMath) Date: Wed, 9 Jan 2013 18:41:37 -0800 (PST) Subject: How to implement mouse gesture by python or pyqt ? In-Reply-To: References: <06fe2548-aa2c-4e66-8a59-474a7a4fc484@googlegroups.com> <4dc2d029-8b1a-494c-8c3e-fccb56ffff42@googlegroups.com> Message-ID: <6f3ad1cd-75e3-4d7e-a3af-03d54aeb3556@googlegroups.com> ? 2013?1?10????UTC+8??8?06?13??Michael Torrie??? > On 01/08/2013 07:57 PM, iMath wrote: > > > ? 2013?1?8????UTC+8??8?44?20??iMath??? > > >> It would be better to give me some examples .thanks in advance ! > > >> > > >> > > >> > > >> P.S. which module or lib are needed ? > > > > > > what I wanna perhaps like this: when a right mouse button is pressed > > > and we go down and right with a cursor. As in letter 'L'. Our mouse > > > gesture will close the window. I googled such gesture examples on > > > PyQt4 ,but hard to find one ,so your help will be greatly appreciated > > > ! thanks inadvance ! > > > > My guess is that if you google for it you'll find a gesture recognition > > module for python. moosegesture.py is one such implementation. However > > it is up to you to tie it into your chosen GUI toolkit. It merely > > processes tuples of points in the gesture. Each GUI toolkit has mailing > > lists and forums that would help you know that information, which is not > > really python-specific. oh yes ,I find it moosegesture.py From redstone-cold at 163.com Wed Jan 9 21:41:37 2013 From: redstone-cold at 163.com (iMath) Date: Wed, 9 Jan 2013 18:41:37 -0800 (PST) Subject: How to implement mouse gesture by python or pyqt ? In-Reply-To: References: <06fe2548-aa2c-4e66-8a59-474a7a4fc484@googlegroups.com> <4dc2d029-8b1a-494c-8c3e-fccb56ffff42@googlegroups.com> Message-ID: <6f3ad1cd-75e3-4d7e-a3af-03d54aeb3556@googlegroups.com> ? 2013?1?10????UTC+8??8?06?13??Michael Torrie??? > On 01/08/2013 07:57 PM, iMath wrote: > > > ? 2013?1?8????UTC+8??8?44?20??iMath??? > > >> It would be better to give me some examples .thanks in advance ! > > >> > > >> > > >> > > >> P.S. which module or lib are needed ? > > > > > > what I wanna perhaps like this: when a right mouse button is pressed > > > and we go down and right with a cursor. As in letter 'L'. Our mouse > > > gesture will close the window. I googled such gesture examples on > > > PyQt4 ,but hard to find one ,so your help will be greatly appreciated > > > ! thanks inadvance ! > > > > My guess is that if you google for it you'll find a gesture recognition > > module for python. moosegesture.py is one such implementation. However > > it is up to you to tie it into your chosen GUI toolkit. It merely > > processes tuples of points in the gesture. Each GUI toolkit has mailing > > lists and forums that would help you know that information, which is not > > really python-specific. oh yes ,I find it moosegesture.py From kalvinmanual at gmail.com Mon Jan 7 19:56:42 2013 From: kalvinmanual at gmail.com (kalvinmanual) Date: Mon, 07 Jan 2013 18:56:42 -0600 Subject: INSTRUCTOR SOLUTIONS MANUAL :: Classical Electrodynamics 2nd edition by John David Jackson Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. INSTRUCTOR SOLUTIONS MANUAL :: Calculus 8th Edition by Varberg, Purcell, Rigdon INSTRUCTOR SOLUTIONS MANUAL :: Calculus - Early Transcendentals, 6th E, by Anton, Bivens, Davis INSTRUCTOR SOLUTIONS MANUAL :: Calculus - Early Transcendentals, 7E, by Anton, Bivens, Davis INSTRUCTOR SOLUTIONS MANUAL :: Calculus - Late Transcendentals Single Variable, 8th Ed by Anton, Bivens, Davis INSTRUCTOR SOLUTIONS MANUAL :: Calculus ( 9th Ed., Dale Varberg, Edwin Purcell & Steve Rigdon) INSTRUCTOR SOLUTIONS MANUAL :: Calculus 2nd edition-M. Spivak INSTRUCTOR SOLUTIONS MANUAL :: Calculus 3rd Ed by Michael Spivak INSTRUCTOR SOLUTIONS MANUAL :: Calculus 6th ed by James Stewart INSTRUCTOR SOLUTIONS MANUAL :: Calculus 8th Ed by Ron Larson, Robert P. Hostetler, Bruce H. Edwards INSTRUCTOR SOLUTIONS MANUAL :: Calculus A Complete Course 6th Edition by by R.A. Adams INSTRUCTOR SOLUTIONS MANUAL :: CALCULUS An Intuitive and Physical Approach 2nd ed by Morris Kline INSTRUCTOR SOLUTIONS MANUAL :: Calculus and its Applications (11th Ed., Larry J Goldstein, Schneider, Lay & Asmar) INSTRUCTOR SOLUTIONS MANUAL :: Calculus by Gilbert Strang INSTRUCTOR SOLUTIONS MANUAL :: Calculus early transcendentals 8th Ed, by Anton Bivens Davis INSTRUCTOR SOLUTIONS MANUAL :: Calculus Early Transcendentals, 5th Edition, JAMES STEWART INSTRUCTOR SOLUTIONS MANUAL :: Calculus George Thomas 10th ed Vol 1 INSTRUCTOR SOLUTIONS MANUAL :: Calculus of Variations MA 4311 LECTURE NOTES ( Russak ) INSTRUCTOR SOLUTIONS MANUAL :: Calculus On Manifolds by Spivak INSTRUCTOR SOLUTIONS MANUAL :: Calculus One & Several Variables 8e by S Salas INSTRUCTOR SOLUTIONS MANUAL :: Calculus Vol 2 by Apostol INSTRUCTOR SOLUTIONS MANUAL :: Calculus Volume 1 by J. Marsden, A. Weinstein INSTRUCTOR SOLUTIONS MANUAL :: Calculus With Analytic Geometry 4th ( Henry Edwards & David E. Penney) INSTRUCTOR SOLUTIONS MANUAL :: Calculus with Applications 8 Edition by Lial, Greenwell, Ritchey INSTRUCTOR SOLUTIONS MANUAL :: Calculus, 4th edition stewart INSTRUCTOR SOLUTIONS MANUAL :: Calculus, An Applied Approach, 7E, by Larson INSTRUCTOR SOLUTIONS MANUAL :: Calculus, Early Transcendentals 7 Ed by Edwards & Penney INSTRUCTOR SOLUTIONS MANUAL :: Calculus, Single and Multivariable, 4E.,Vol 1& Vol 2 by Hughes-Hallett,McCallum INSTRUCTOR SOLUTIONS MANUAL :: Calculus, Single Variable, 3E by Hughes-Hallett,McCallum INSTRUCTOR SOLUTIONS MANUAL :: Chemical and Engineering Thermodynamics 3Ed by Stanley I. Sandler INSTRUCTOR SOLUTIONS MANUAL :: Chemical Engineering Design (Coulson & Richardson's Chemical Engineering - Volume 6) - (4th Ed., Sinnott) INSTRUCTOR SOLUTIONS MANUAL :: Chemical Engineering Volume 1, 6th Edition, by Richardson, Coulson,Backhurst, Harker INSTRUCTOR SOLUTIONS MANUAL :: Chemical, Biochemical, and Engineering Thermodynamics, 4th Ed by Sandler INSTRUCTOR SOLUTIONS MANUAL :: Chemistry 2nd Edition Vol.1 by Julia Burdge INSTRUCTOR SOLUTIONS MANUAL :: Chemistry, 10th Ed by Chang INSTRUCTOR SOLUTIONS MANUAL :: Chip Design for Submicron VLSI CMOS Layout and Simulation, John P. Uyemura INSTRUCTOR SOLUTIONS MANUAL :: Cisco Technical Solution Series IP Telephony Solution Guide Version 2.0 INSTRUCTOR SOLUTIONS MANUAL :: Classical Dynamics of Particles and Systems, 5th Ed, by Marion, Thornton INSTRUCTOR SOLUTIONS MANUAL :: Classical Dynamics, A Contemporary Approach (Jorge V. Jose) INSTRUCTOR SOLUTIONS MANUAL :: Classical Electrodynamics 2nd edition by John David Jackson INSTRUCTOR SOLUTIONS MANUAL :: Classical Electrodynamics by John David Jackson INSTRUCTOR SOLUTIONS MANUAL :: Classical Electrodynamics by Kasper Van Wijk INSTRUCTOR SOLUTIONS MANUAL :: Classical Mechanics (Douglas Gregory) INSTRUCTOR SOLUTIONS MANUAL :: Classical Mechanics 2nd Ed by Goldstein INSTRUCTOR SOLUTIONS MANUAL :: CMOS Analog Circuit Design, 2ed by Phillip E. Allen, Douglas R. Holberg INSTRUCTOR SOLUTIONS MANUAL :: CMOS- Circuit Design, Layout, and Simulation, Revised 2nd Ed by R. Jacob Baker INSTRUCTOR SOLUTIONS MANUAL :: Cmos Digital Integrated Circuits , Sung-Mo Kang,Yusuf Leblebici INSTRUCTOR SOLUTIONS MANUAL :: CMOS Mixed-Signal Circuit Design, 2nd Ed by R. Jacob Baker INSTRUCTOR SOLUTIONS MANUAL :: CMOS VLSI Design Circuit & Design Perspective 3rd Ed by Haris & West INSTRUCTOR SOLUTIONS MANUAL :: College Algebra 8th Ed by Michael Sullivan INSTRUCTOR SOLUTIONS MANUAL :: COLLEGE ALGEBRA AND TRIGONOMETRY 6th E by Aufmann, Barker, Verity INSTRUCTOR SOLUTIONS MANUAL :: College Geometry A Discovery Approach 2nd E by David Kay INSTRUCTOR SOLUTIONS MANUAL :: College Physics 8 ED by Serway, Faughn, Vuille INSTRUCTOR SOLUTIONS MANUAL :: College Physics 9 ED by Serway, Faughn, Vuille INSTRUCTOR SOLUTIONS MANUAL :: Communication Networks, 2e, Alberto Leon-Garcia, Indra Widjaja INSTRUCTOR SOLUTIONS MANUAL :: Communication Systems (4th Ed., Simon Haykin) INSTRUCTOR SOLUTIONS MANUAL :: Communication Systems An Introduction to Signals and Noise in Electrical Communication, 4E, A. Bruce Carlson INSTRUCTOR SOLUTIONS MANUAL :: Communication Systems Engineering (2nd Ed., John G. Proakis & Masoud Salehi) INSTRUCTOR SOLUTIONS MANUAL :: Complex Variables and Applications 7 ed by JW Brown RV Churchill INSTRUCTOR SOLUTIONS MANUAL :: Complex Variables with Applications, 3rd ED by David A. Wunsch INSTRUCTOR SOLUTIONS MANUAL :: COMPUTATIONAL FINANCE A SCIENTIFIC PERSPECTIVE MILEN KASSABOV,CORNELIS A. LOS INSTRUCTOR SOLUTIONS MANUAL :: Computational Techniques for Fluid Dynamics Srinivas, K., Fletcher, C.A.J. INSTRUCTOR SOLUTIONS MANUAL :: Computer Architecture - A Quantitative Approach, 4th Ed by Hennessy, Patterson INSTRUCTOR SOLUTIONS MANUAL :: Computer Architecture Pipelined & Parallel Processor Design by Michael J Flynn INSTRUCTOR SOLUTIONS MANUAL :: Computer Graphics Using OpenGL 3rd E by Francis S Hill, Jr. & Stephen M Kelley INSTRUCTOR SOLUTIONS MANUAL :: Computer Networking A Top-Down Approach Featuring the Internet, 3E Kurose,Ross INSTRUCTOR SOLUTIONS MANUAL :: Computer Networking: A Top-Down Approach (4th Ed., James F. Kurose & Keith W. Ross) INSTRUCTOR SOLUTIONS MANUAL :: Computer Networks - A Systems Approach 3 ed by Peterson Davie INSTRUCTOR SOLUTIONS MANUAL :: Computer Networks - A Systems Approach 4 ed by Peterson Davie INSTRUCTOR SOLUTIONS MANUAL :: Computer Networks A Systems Approach, 2nd Edition, Larry Peterson, Bruce Davie INSTRUCTOR SOLUTIONS MANUAL :: Computer Networks, 4th Ed., by Andrew S. Tanenbaum INSTRUCTOR SOLUTIONS MANUAL :: Computer Organization 3rd Edition by Carl Hamacher , Zvonoko Vranesic ,Safwat Zaky INSTRUCTOR SOLUTIONS MANUAL :: Computer Organization and Architecture: Designing for Performance (7th Ed., William Stallings) INSTRUCTOR SOLUTIONS MANUAL :: Computer Organization and Design The Hardware Software Interface 4 ed by David A Patterson INSTRUCTOR SOLUTIONS MANUAL :: Computer Organization and Design The Hardware Software Interface, 3rd edition by David A Patterson and John L Hennessy INSTRUCTOR SOLUTIONS MANUAL :: Computer Science Illuminated 4th ed by Nell Dale, John Lewis INSTRUCTOR SOLUTIONS MANUAL :: Computer system architecture 3rd Ed Morris Mano INSTRUCTOR SOLUTIONS MANUAL :: Computer Systems Organization and Architecture by John D. Carpinelli INSTRUCTOR SOLUTIONS MANUAL :: Computer Vision A Modern Approach by Forsyth, Ponce INSTRUCTOR SOLUTIONS MANUAL :: Computer-Controlled Systems 3rd ED by Astrom, Wittenmark INSTRUCTOR SOLUTIONS MANUAL :: Concepts and Applications of Finite Element Analysis (4th Ed., Cook, Malkus, Plesha & Witt) INSTRUCTOR SOLUTIONS MANUAL :: Concepts in Thermal Physics 2nd Ed by Blundell INSTRUCTOR SOLUTIONS MANUAL :: Concepts of Physics (Volume 1 & 2) by H.C. Verma INSTRUCTOR SOLUTIONS MANUAL :: Concepts of Programming Languages 7th ED by Sebesta INSTRUCTOR SOLUTIONS MANUAL :: Construction Surveying and Layout 2ed by Crawford INSTRUCTOR SOLUTIONS MANUAL :: Contemporary Engineering Economics (4th Ed., Chan Park) INSTRUCTOR SOLUTIONS MANUAL :: Contemporary Engineering Economics 5th Ed by Chan S. Park INSTRUCTOR SOLUTIONS MANUAL :: Continuum Electromechanics by James R. Melcher INSTRUCTOR SOLUTIONS MANUAL :: Control Systems Engineering, 4E, by Norman Nise INSTRUCTOR SOLUTIONS MANUAL :: Control Systems Principles and Design 2e by M. Gopal INSTRUCTOR SOLUTIONS MANUAL :: Corporate Finance & MyFinanceLab Student Access Code Card, Global 2 Ed by Berk, DeMarzo INSTRUCTOR SOLUTIONS MANUAL :: Corporate Finance 8th edition by Ross INSTRUCTOR SOLUTIONS MANUAL :: Corporate Finance 9th edition by Ross INSTRUCTOR SOLUTIONS MANUAL :: Corporate Finance The Core plus MyFinanceLab Student Access Kit (Jonathan Berk & Peter DeMarzo) INSTRUCTOR SOLUTIONS MANUAL :: Corporate Finance, 7E, by Ross INSTRUCTOR SOLUTIONS MANUAL :: Corporations, Partnerships, Estates and Trusts ( 2011 ) by Hoffman, Maloney INSTRUCTOR SOLUTIONS MANUAL :: COST ACCOUNTING - Creating Value for Management 5th E by MICHAEL MAHER INSTRUCTOR SOLUTIONS MANUAL :: Cost Accounting-A Managerial Emphasis 13th Ed by Charles Horngren INSTRUCTOR SOLUTIONS MANUAL :: Cryptography and Network Security (4th Ed., William Stallings) From andydtaylor at gmail.com Mon Jan 7 20:00:38 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Mon, 7 Jan 2013 17:00:38 -0800 (PST) Subject: Difference between these two lists? Message-ID: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Hi, Python newbie here again - this is probably a quick one. What's the difference between the lines I've numbered 1. and 2. below, which produce the following results: Results: 1. [ANG, BAR, BPK, CTN, QGH, QHD, KXX] 2. ['ANG', 'BAR', 'BPK', 'CTN', 'QGH', 'QHD', 'KXX'] Code: cursor_from.execute('SELECT * FROM tubestations LIMIT 1000') stn_list_short = [] for row in cursor_from: if row[4]: # Station values for database stn_list_short.append(row[5]) 1. print stn_fields = '[%s]' % ', '.join(map(str, stn_list_short)) 2. print stn_list_short Thanks! Andy From andydtaylor at gmail.com Mon Jan 7 20:06:34 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Mon, 7 Jan 2013 17:06:34 -0800 (PST) Subject: Difference between these two lists? In-Reply-To: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> References: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Message-ID: I think I can answer my own question on reflection.... the first one is actually a string I think? I was confused by the square brackets around the placeholder %s. From rosuav at gmail.com Mon Jan 7 20:13:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 12:13:21 +1100 Subject: Difference between these two lists? In-Reply-To: References: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Message-ID: On Tue, Jan 8, 2013 at 12:06 PM, wrote: > I think I can answer my own question on reflection.... the first one is actually a string I think? I was confused by the square brackets around the placeholder %s. That's correct. Your first line is putting square brackets around a comma-joined list of strings; the second gives the representation of a list. They happen to be superficially similar. ChrisA From rosuav at gmail.com Mon Jan 7 20:11:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 12:11:36 +1100 Subject: Difference between these two lists? In-Reply-To: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> References: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Message-ID: On Tue, Jan 8, 2013 at 12:00 PM, wrote: > Hi, > > Python newbie here again - this is probably a quick one. What's the difference between the lines I've numbered 1. and 2. below, which produce the following results: > 1. print stn_fields = '[%s]' % ', '.join(map(str, stn_list_short)) > 2. print stn_list_short Your first line explicitly joins the strings with commas; the second implicitly calls repr() on the whole list, which does its best to produce a valid Python literal. Check out the docs on repr() for the details on that; you'll see different results depending on the content of the strings, but at very least they'll always be quoted. ChrisA From d at davea.name Mon Jan 7 20:21:10 2013 From: d at davea.name (Dave Angel) Date: Mon, 07 Jan 2013 20:21:10 -0500 Subject: Difference between these two lists? In-Reply-To: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> References: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Message-ID: <50EB7486.1060702@davea.name> On 01/07/2013 08:00 PM, andydtaylor at gmail.com wrote: > Hi, > > Python newbie here again - this is probably a quick one. What's the difference between the lines I've numbered 1. and 2. below, which produce the following results: > > Results: > 1. [ANG, BAR, BPK, CTN, QGH, QHD, KXX] > 2. ['ANG', 'BAR', 'BPK', 'CTN', 'QGH', 'QHD', 'KXX'] > > Code: > cursor_from.execute('SELECT * FROM tubestations LIMIT 1000') > > stn_list_short = [] > for row in cursor_from: > if row[4]: > # Station values for database > stn_list_short.append(row[5]) > > 1. print stn_fields = '[%s]' % ', '.join(map(str, stn_list_short)) > 2. print stn_list_short #2 is easy. it's just the standard way a list prints itself. It puts brackets at begin and end, and then calls repr() on each of the elements. Since those elements are str objects, each gets quotes around it. Then the list logic adds commas and puts it all together. In #1, you're doing it by hand. If you wanted the same result, you'd have to map the repr, not the str value of each item. (untested) .join(map(repr, stn_list_short) -- DaveA From roy at panix.com Mon Jan 7 20:24:01 2013 From: roy at panix.com (Roy Smith) Date: Mon, 07 Jan 2013 20:24:01 -0500 Subject: Difference between these two lists? References: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Message-ID: In article <700d2bd9-e1df-4d38-81c7-77029a36c47a at googlegroups.com>, andydtaylor at gmail.com wrote: > Hi, > > Python newbie here again - this is probably a quick one. What's the > difference between the lines I've numbered 1. and 2. below, which produce the > following results: > > Results: > 1. [ANG, BAR, BPK, CTN, QGH, QHD, KXX] > 2. ['ANG', 'BAR', 'BPK', 'CTN', 'QGH', 'QHD', 'KXX'] > > Code: > cursor_from.execute('SELECT * FROM tubestations LIMIT 1000') > > stn_list_short = [] > for row in cursor_from: > if row[4]: > # Station values for database > stn_list_short.append(row[5]) > > 1. print stn_fields = '[%s]' % ', '.join(map(str, stn_list_short)) > 2. print stn_list_short Hi Andy, You should try to reduce this down to some minimal test case. In this case, the database code has nothing to do with it, it's purely a matter of how a list of strings is printed. When you print a list, the repr() of each list element is printed. The repr() of a string includes quotes. For example: >>> print str("foo") foo >>> print repr("foo") 'foo' I'm not sure what "map(str, stn_list_short)" is all about. I'm assuming stn_list_short is already a string, so that's a no-op. In general, the best way to ask about code is to cut-and-paste the exact code that you ran. You didn't run: > 1. print stn_fields = '[%s]' % ', '.join(map(str, stn_list_short)) > 2. print stn_list_short because those are syntax errors. I understand you were just trying to annotate your code to make it easier to explain. A better way to do that would be to comment your code, something like: > print stn_fields = '[%s]' % ', '.join(map(str, stn_list_short)) # line 1 > print stn_list_short # line 2 Now you've got something which runs, and can be cut-and-pasted unmodified into your posting. That reduces the chance of confusion. From andydtaylor at gmail.com Mon Jan 7 21:21:08 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Mon, 7 Jan 2013 18:21:08 -0800 (PST) Subject: Difference between these two lists? In-Reply-To: References: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Message-ID: Thanks, I think I'm clear now. I guess (map(str, stn_list)) was all about how to make a string starting with integers. I picked that up and began using it without realising it was over catering for a list already containing strings, and join(stn_list) was really all I required. Repr and Eval I think I get. Eval certainly. That's a familiar concept, and one I hope to use tomorrow to feed a line to psycopg2. I might have opened a can of worms on map and repr though... I'll do some more reading tomorrow. Top tip on the code annotation, I didn't really think that through. Thanks again, Andy From rosuav at gmail.com Mon Jan 7 21:35:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Jan 2013 13:35:00 +1100 Subject: Difference between these two lists? In-Reply-To: References: <700d2bd9-e1df-4d38-81c7-77029a36c47a@googlegroups.com> Message-ID: On Tue, Jan 8, 2013 at 1:21 PM, wrote: > Repr and Eval I think I get. Eval certainly. That's a familiar concept, and one I hope to use tomorrow to feed a line to psycopg2. I hope not. Why do you need eval? It's extremely dangerous. Chances are there's a better way to do it; if your users are entering strings like "['Foo', 'Bar']" and you want them to be interpreted as lists, then you can get a much safer function ast.literal_eval - it's equivalent to eval, but (as the name suggests) works only with literals, so you can't call functions etc. But even that may be overkill, depending on what you actually need. ChrisA From brian at python.org Mon Jan 7 22:41:44 2013 From: brian at python.org (Brian Curtin) Date: Mon, 7 Jan 2013 21:41:44 -0600 Subject: FYI - wiki.python.org compromised Message-ID: On December 28th, an unknown attacker used a previously unknown remote code exploit on http://wiki.python.org/. The attacker was able to get shell access as the "moin" user, but no other services were affected. Some time later, the attacker deleted all files owned by the "moin" user, including all instance data for both the Python and Jython wikis. The attack also had full access to all MoinMoin user data on all wikis. In light of this, the Python Software Foundation encourages all wiki users to change their password on other sites if the same one is in use elsewhere. We apologize for the inconvenience and will post further news as we bring the new and improved wiki.python.org online. If you have any questions about this incident please contact jnoller at python.org. Thank you for your patience. From redstone-cold at 163.com Mon Jan 7 23:19:15 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 7 Jan 2013 20:19:15 -0800 (PST) Subject: how to download internet files by python ? Message-ID: for example ,if I want to download this file ,how to implement the download functionality by python ? http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3 as for download speed ,of course ,the fast ,the better ,so how to implement it ? It would be better to show me an example :) thanks !!! From cs at zip.com.au Mon Jan 7 23:44:00 2013 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 8 Jan 2013 15:44:00 +1100 Subject: how to download internet files by python ? In-Reply-To: References: Message-ID: <20130108044359.GA26332@cskk.homeip.net> On 07Jan2013 20:19, iMath wrote: | for example ,if I want to download this file ,how to implement the download functionality by python ? | | http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3 | | as for download speed ,of course ,the fast ,the better ,so how to implement it ? | It would be better to show me an example :) thanks !!! Look at urllib2. -- Cameron Simpson If God had intended Man to fly, He would have given him more money. - Jeff Cauhape, cauhape at TWG.COM From rodrick.brown at gmail.com Tue Jan 8 00:00:37 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 8 Jan 2013 00:00:37 -0500 Subject: how to download internet files by python ? In-Reply-To: References: Message-ID: On Mon, Jan 7, 2013 at 11:19 PM, iMath wrote: > for example ,if I want to download this file ,how to implement the > download functionality by python ? > > http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3 > > as for download speed ,of course ,the fast ,the better ,so how to > implement it ? > > It would be better to show me an example :) thanks !!! > -- > http://mail.python.org/mailman/listinfo/python-list > #!/usr/bin/python import urllib2 if __name__ == '__main__': fileurl=' http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3' mp3file = urllib2.urlopen(fileurl) with open('outfile.mp3','wb') as output: output.write(mp3file.read()) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Jan 8 10:19:49 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 08 Jan 2013 15:19:49 +0000 Subject: how to download internet files by python ? In-Reply-To: References: Message-ID: <50EC3915.5090408@mrabarnett.plus.com> On 2013-01-08 05:00, Rodrick Brown wrote: > On Mon, Jan 7, 2013 at 11:19 PM, iMath > wrote: > > for example ,if I want to download this file ,how to implement the > download functionality by python ? > > http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3 > > as for download speed ,of course ,the fast ,the better ,so how to > implement it ? > > It would be better to show me an example :) thanks !!! > -- > http://mail.python.org/mailman/listinfo/python-list > > > #!/usr/bin/python > import urllib2 > if __name__ == '__main__': > > fileurl='http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3' > > mp3file = urllib2.urlopen(fileurl) > with open('outfile.mp3','wb') as output: > output.write(mp3file.read()) > Why not just use urlretrieve? From roy at panix.com Tue Jan 8 00:04:54 2013 From: roy at panix.com (Roy Smith) Date: Tue, 08 Jan 2013 00:04:54 -0500 Subject: how to download internet files by python ? References: Message-ID: In article , Cameron Simpson wrote: > On 07Jan2013 20:19, iMath wrote: > | for example ,if I want to download this file ,how to implement the download > | functionality by python ? > | > | http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3 > | > | as for download speed ,of course ,the fast ,the better ,so how to > | implement it ? > | It would be better to show me an example :) thanks !!! > > Look at urllib2. Even better, look at requests (http://docs.python-requests.org/en/latest/). There's nothing you can do with requests that you can't do with urllib2, but the interface is a whole lot easier to work with. From redstone-cold at 163.com Wed Jan 9 21:08:24 2013 From: redstone-cold at 163.com (iMath) Date: Wed, 9 Jan 2013 18:08:24 -0800 (PST) Subject: how to download internet files by python ? In-Reply-To: References: Message-ID: ? 2013?1?8????UTC+8??1?04?54??Roy Smith??? > In article , > > Cameron Simpson wrote: > > > > > On 07Jan2013 20:19, iMath wrote: > > > | for example ,if I want to download this file ,how to implement the download > > > | functionality by python ? > > > | > > > | http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3 > > > | > > > | as for download speed ,of course ,the fast ,the better ,so how to > > > | implement it ? > > > | It would be better to show me an example :) thanks !!! > > > > > > Look at urllib2. > > > > Even better, look at requests > > (http://docs.python-requests.org/en/latest/). There's nothing you can > > do with requests that you can't do with urllib2, but the interface is a > > whole lot easier to work with. There is also a httplib2 module https://code.google.com/p/httplib2/ which one is more pythonic and powerful ? From timr at probo.com Wed Jan 9 23:31:21 2013 From: timr at probo.com (Tim Roberts) Date: Wed, 09 Jan 2013 20:31:21 -0800 Subject: how to download internet files by python ? References: Message-ID: iMath wrote: > >There is also a httplib2 module >https://code.google.com/p/httplib2/ > >which one is more pythonic and powerful ? Both are Pythonic, and power is irrelevant for this. Your code is going to spend 90% of its time waiting for the network. Just solve the problem. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From redstone-cold at 163.com Mon Jan 7 23:20:28 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 7 Jan 2013 20:20:28 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? Message-ID: How to get the selected text of the webpage in chrome through python ? From redstone-cold at 163.com Tue Jan 8 05:52:50 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 8 Jan 2013 02:52:50 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: <52c801cb-8ca6-4044-b9a7-b8d15e3c1a0c@googlegroups.com> ? 2013?1?8????UTC+8??12?20?28??iMath??? > How to get the selected text of the webpage in chrome through python ? I need the code ,cuz I am only familiar with Python ,so it would be better to give me the code written in Python . You can also give me the code in other programming language ,thanks in advance :) From d at davea.name Tue Jan 8 08:11:30 2013 From: d at davea.name (Dave Angel) Date: Tue, 08 Jan 2013 08:11:30 -0500 Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: <50EC1B02.2050805@davea.name> On 01/08/2013 07:38 AM, Dennis Lee Bieber wrote: > On Mon, 7 Jan 2013 20:20:28 -0800 (PST), iMath > declaimed the following in gmane.comp.python.general: > >> How to get the selected text of the webpage in chrome through python ? > Chrome is a browser, is it not... If you want to get the text in > Python, you have to write the equivalent of a browser -- something that > parses the returned HTML message, extracting the parts you want. To get a selection, you can either wait till it's copied to the clipboard, and get it from there, or you can write a addon for the application. Since Chrome accepts addons, I suggest you research that angle. Probably mozilla.org is the place to start, and function nsISelectionController::GetSelection() might be some place to examine. You might find some hints in http://stackoverflow.com/questions/2671474/range-selection-and-mozilla if you are going to work with the clipboard, realize that it works quite differently from one OS to another, and even from one desktop manager to another. -- DaveA From redstone-cold at 163.com Tue Jan 8 21:54:06 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 8 Jan 2013 18:54:06 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: ? 2013?1?8????UTC+8??9?11?30??Dave Angel??? > On 01/08/2013 07:38 AM, Dennis Lee Bieber wrote: > > > On Mon, 7 Jan 2013 20:20:28 -0800 (PST), iMath > > > declaimed the following in gmane.comp.python.general: > > > > > >> How to get the selected text of the webpage in chrome through python ? > > > Chrome is a browser, is it not... If you want to get the text in > > > Python, you have to write the equivalent of a browser -- something that > > > parses the returned HTML message, extracting the parts you want. > > > > To get a selection, you can either wait till it's copied to the > > clipboard, and get it from there, or you can write a addon for the > > application. Since Chrome accepts addons, I suggest you research that > > angle. Probably mozilla.org is the place to start, and function > > > > nsISelectionController::GetSelection() might be some place to examine. > > > > You might find some hints in > > http://stackoverflow.com/questions/2671474/range-selection-and-mozilla > > > > > > if you are going to work with the clipboard, realize that it works quite > > differently from one OS to another, and even from one desktop manager to > > another. > > > > -- > > > > DaveA It seems need Javascript to work it on . Unfortunately ?I am only familiar with python . From redstone-cold at 163.com Tue Jan 8 21:54:06 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 8 Jan 2013 18:54:06 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: ? 2013?1?8????UTC+8??9?11?30??Dave Angel??? > On 01/08/2013 07:38 AM, Dennis Lee Bieber wrote: > > > On Mon, 7 Jan 2013 20:20:28 -0800 (PST), iMath > > > declaimed the following in gmane.comp.python.general: > > > > > >> How to get the selected text of the webpage in chrome through python ? > > > Chrome is a browser, is it not... If you want to get the text in > > > Python, you have to write the equivalent of a browser -- something that > > > parses the returned HTML message, extracting the parts you want. > > > > To get a selection, you can either wait till it's copied to the > > clipboard, and get it from there, or you can write a addon for the > > application. Since Chrome accepts addons, I suggest you research that > > angle. Probably mozilla.org is the place to start, and function > > > > nsISelectionController::GetSelection() might be some place to examine. > > > > You might find some hints in > > http://stackoverflow.com/questions/2671474/range-selection-and-mozilla > > > > > > if you are going to work with the clipboard, realize that it works quite > > differently from one OS to another, and even from one desktop manager to > > another. > > > > -- > > > > DaveA It seems need Javascript to work it on . Unfortunately ?I am only familiar with python . From lisael at lisael.org Tue Jan 8 08:19:51 2013 From: lisael at lisael.org (Bruno Dupuis) Date: Tue, 8 Jan 2013 14:19:51 +0100 Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: <20130108131951.GA5254@gurdil> On Mon, Jan 07, 2013 at 08:20:28PM -0800, iMath wrote: > How to get the selected text of the webpage in chrome through python ? What you need is a way to get selected text from wherever it comes. The way to do this depends on your graphical environment. If you use X, i'd make a a quick and dirty call to xclip -o, although there must be a pure python implementation which in turn depends on the python framework you play with (gtk/qt/wx/tk/...). Short answer is : it depends on your system, and it may be easier and more portable if you use a graphical toolkit. cheers. -- Bruno Dupuis From miki.tebeka at gmail.com Tue Jan 8 09:01:49 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 8 Jan 2013 06:01:49 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: <0a37e6da-be0c-400f-8174-00d47dadd4ab@googlegroups.com> On Monday, January 7, 2013 8:20:28 PM UTC-8, iMath wrote: > How to get the selected text of the webpage in chrome through python ? You can probably use selenium to do that. From redstone-cold at 163.com Tue Jan 8 21:47:04 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 8 Jan 2013 18:47:04 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: ? 2013?1?8????UTC+8??9?19?51??Bruno Dupuis??? > On Mon, Jan 07, 2013 at 08:20:28PM -0800, iMath wrote: > > > How to get the selected text of the webpage in chrome through python ? > > > > What you need is a way to get selected text from wherever it comes. The > > way to do this depends on your graphical environment. If you use X, i'd make a > > a quick and dirty call to xclip -o, although there must be a pure python > > implementation which in turn depends on the python framework you play > > with (gtk/qt/wx/tk/...). > > > > Short answer is : it depends on your system, and it may be easier and more > > portable if you use a graphical toolkit. > > > > cheers. > > > > -- > > Bruno Dupuis I use it on WinXP , I also learned PyQt4 . can u help ? From redstone-cold at 163.com Tue Jan 8 21:47:04 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 8 Jan 2013 18:47:04 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: ? 2013?1?8????UTC+8??9?19?51??Bruno Dupuis??? > On Mon, Jan 07, 2013 at 08:20:28PM -0800, iMath wrote: > > > How to get the selected text of the webpage in chrome through python ? > > > > What you need is a way to get selected text from wherever it comes. The > > way to do this depends on your graphical environment. If you use X, i'd make a > > a quick and dirty call to xclip -o, although there must be a pure python > > implementation which in turn depends on the python framework you play > > with (gtk/qt/wx/tk/...). > > > > Short answer is : it depends on your system, and it may be easier and more > > portable if you use a graphical toolkit. > > > > cheers. > > > > -- > > Bruno Dupuis I use it on WinXP , I also learned PyQt4 . can u help ? From alister.ware at ntlworld.com Wed Jan 9 04:35:15 2013 From: alister.ware at ntlworld.com (Alister) Date: Wed, 09 Jan 2013 09:35:15 GMT Subject: How to get the selected text of the webpage in chrome through python ? References: Message-ID: On Mon, 07 Jan 2013 20:20:28 -0800, iMath wrote: > How to get the selected text of the webpage in chrome through python ? i think you need to explain your requirement further also what do you want to do to the text once you have it? -- Genius is one percent inspiration and ninety-nine percent perspiration. -- Thomas Alva Edison From redstone-cold at 163.com Wed Jan 9 20:55:19 2013 From: redstone-cold at 163.com (iMath) Date: Wed, 9 Jan 2013 17:55:19 -0800 (PST) Subject: How to get the selected text of the webpage in chrome through python ? In-Reply-To: References: Message-ID: ? 2013?1?9????UTC+8??5?35?15??Alister??? > On Mon, 07 Jan 2013 20:20:28 -0800, iMath wrote: > > > > > How to get the selected text of the webpage in chrome through python ? > > > > i think you need to explain your requirement further > > also what do you want to do to the text once you have it? > > > > > > > > > > -- > > Genius is one percent inspiration and ninety-nine percent perspiration. > > -- Thomas Alva Edison I want to google it with a mouse gesture From ltwisabc at gmail.com Tue Jan 8 00:28:07 2013 From: ltwisabc at gmail.com (Kelvin Li) Date: Mon, 07 Jan 2013 21:28:07 -0800 Subject: comparison between non-comparable objects Message-ID: <1357622887.2914.29.camel@qm> The language reference says: "...the choice whether one object [of built-in type] is considered smaller or larger than another one is made arbitrarily..." but that seems to be Python 2 behavior; Python 3 apparently raises a TypeError. Does the documentation need updating? Thanks, Kelvin From d at davea.name Tue Jan 8 01:03:30 2013 From: d at davea.name (Dave Angel) Date: Tue, 08 Jan 2013 01:03:30 -0500 Subject: comparison between non-comparable objects In-Reply-To: <1357622887.2914.29.camel@qm> References: <1357622887.2914.29.camel@qm> Message-ID: <50EBB6B2.1050700@davea.name> On 01/08/2013 12:28 AM, Kelvin Li wrote: > The language reference says: > > "...the choice whether one object [of built-in type] is considered > smaller or larger than another one is made arbitrarily..." When quoting some online source, please give a reference link. It took me a while to find the following page with your quote in it: http://docs.python.org/3.3/reference/expressions.html in section "6.9 Comparisons" > but that seems to be Python 2 behavior; Python 3 apparently raises a > TypeError. Does the documentation need updating? > That sentence is correct in context. The bullet items there are labeled "Comparison of objects of the same type..." And the particular bullet also qualifies the type of the two objects being compared: " Most other objects of built-in types..." Earlier in the same section, it considers the case of comparing objects of DIFFERENT type. .... while the <, >, >= and <= operators raise a TypeError when comparing objects of different types that do not implement these operators for the given pair of types.... -- DaveA From ltwisabc at gmail.com Tue Jan 8 02:53:50 2013 From: ltwisabc at gmail.com (Kelvin Li) Date: Mon, 07 Jan 2013 23:53:50 -0800 Subject: comparison between non-comparable objects In-Reply-To: <50EBB6B2.1050700@davea.name> Message-ID: <1357631630.2914.50.camel@qm> > When quoting some online source, please give a reference link. It took > me a while to find the following page with your quote in it: > > > http://docs.python.org/3.3/reference/expressions.html > > in section "6.9 Comparisons" Sorry about that. Thanks for finding the link. > > but that seems to be Python 2 behavior; Python 3 apparently raises a > > TypeError. Does the documentation need updating? > > > > That sentence is correct in context. The bullet items there are labeled > "Comparison of objects of the same type..." And the particular bullet > also qualifies the type of the two objects being compared: " Most > other objects of built-in types..." Got it, I was confusing built-in types with built-in functions--I incorrectly thought object(), for example, returned an object of a built-in type, and was behaving differently in Python 2 and 3: object() < object() Thanks, Kelvin From mohit.personal1987 at gmail.com Tue Jan 8 05:29:31 2013 From: mohit.personal1987 at gmail.com (Mohit Khanna) Date: Tue, 8 Jan 2013 02:29:31 -0800 (PST) Subject: How to call ltm function using rpy package in python Message-ID: <431b8876-6964-4666-a545-046b42b27667@googlegroups.com> I am trying the following code-- from rpy import * r.library("ltm") dat= #some data frame or matrix r.ltm(r('dat~z1')) error coming is--- RPy_RException: Error in eval(expr, envir, enclos) : object 'dat' not found Please tell me the right way to call ltm function using rpy library From piet at vanoostrum.org Fri Jan 11 14:47:06 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 11 Jan 2013 20:47:06 +0100 Subject: How to call ltm function using rpy package in python References: <431b8876-6964-4666-a545-046b42b27667@googlegroups.com> Message-ID: Mohit Khanna writes: > I am trying the following code-- > > from rpy import * > r.library("ltm") > > dat= #some data frame or matrix > r.ltm(r('dat~z1')) > > error coming is--- > RPy_RException: Error in eval(expr, envir, enclos) : object 'dat' not found > > Please tell me the right way to call ltm function using rpy library Your problem is that the 'dat' object is in the Python world but not in the R world. However, the expression r('dat~z1') is looking for a 'dat' object in the R world. So you must copy the Python object to the R world. I don't know if this will work in rpy, but it does work in rpy2. Rpy2 has much better possibilities than rpy. But just try it: r['=']('dat', dat) r.ltm(r('dat~z1')) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From morten.guldager at gmail.com Tue Jan 8 07:45:51 2013 From: morten.guldager at gmail.com (Morten Guldager) Date: Tue, 8 Jan 2013 13:45:51 +0100 Subject: Newbe accessing MySQL, need something like perl's prepare_cached Message-ID: 'Aloha Friends! Still quite new to python I'm trying to access a MySQL database. Being a former perl programmer I recognize much of the semantics going on. Create a database handle, compile a piece of SQL and put it into a cursor, run the query and use the result. exactly the same flow as I am used to. And it works just fine. But as programs grow larger, it is sometimes becomes a burden to compile those SQL's over and over again when they should be perfectly reusable. And implementing a "query cache" by myself seems not to be the right thing in this batteries included environment. Donno exactly what I'm looking for, but the perl equivalent is called prepare_cached. Oh, by the way, I'm using "import MySQLdb", hope that's not the most outdated, inefficient and stupid choice for a MySQL library... -- /Morten %-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at cinege.com Tue Jan 8 12:02:33 2013 From: dave at cinege.com (Dave Cinege) Date: Tue, 8 Jan 2013 12:02:33 -0500 Subject: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Message-ID: <201301081202.33576.dave@cinege.com> Thesaurus: A different way to call a dictionary. Thesaurus is a new a dictionary subclass which allows calling keys as if they are class attributes and will search through nested objects recursively when __getitem__ is called. You will notice that the code is disgusting simple. However I have found that this has completely changed the way I program in python. I've re-written some exiting programs using Thesaurus, and often realized 15-30% code reduction. Additionally I find the new code much easier to read. If you find yourself programing with nested dictionaries often, fighting to generate output or command lines for external programs, or wish you had a dictionary that could act (sort of) like a class, Thesaurus may be for you. -------------- next part -------------- A non-text attachment was scrubbed... Name: thesaurus.py Type: text/x-python Size: 2912 bytes Desc: not available URL: From ndbecker2 at gmail.com Tue Jan 8 14:16:08 2013 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 08 Jan 2013 14:16:08 -0500 Subject: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes References: <201301081202.33576.dave@cinege.com> Message-ID: Did you intend to give anyone permission to use the code? I see only a copyright notice, but no permissions. From ian.g.kelly at gmail.com Tue Jan 8 14:50:23 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Jan 2013 12:50:23 -0700 Subject: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes In-Reply-To: References: <201301081202.33576.dave@cinege.com> Message-ID: On Tue, Jan 8, 2013 at 12:16 PM, Neal Becker wrote: > Did you intend to give anyone permission to use the code? I see only a > copyright notice, but no permissions. It also says "Licence: python, Copyright notice may not be altered." Which suggests to me that the intent is that it be licensed under the PSF License, although I wouldn't want to be the one testing that inference in a courtroom. Dave, this announcement looks identical to the one you posted a couple months ago, and it also seems to include the earlier version of the source. From duncan.booth at invalid.invalid Thu Jan 10 06:34:23 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Jan 2013 11:34:23 GMT Subject: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes References: Message-ID: Dave Cinege wrote: > You will notice that the code is disgusting simple. However I have > found that this has completely changed the way I program in python. > I've re-written some exiting programs using Thesaurus, and often > relized 15-30% code reduction. Additionally I find the new code much > easier to read. And here's the same code written without your class but maintaining as far as possible the same structure. I find my version far easier to read then your's with all your spurious 'g.' 'L.' prefixes. ----------------------------------------------------- #!python2.7 from textwrap import dedent class Blob(object): pass prog = Blob() prog.VERSION = '1.0' # But isn't this so much cleaner? prog.NAME = 'Thesaurus' class TestClass: no = 'Class' way = 'this' def main (): tc = TestClass() l = ['Some', 'objects'] # Here's how you should create output without a fight. print dedent('''\ When programing python without {prog.NAME}, it is very easy to access your {l[1]}. {l[0]} people might say {prog.NAME} has no {tc.no}.''').format(prog=prog, l=l, tc=tc) if hasattr(prog, 'VERSION'): print 'But I challenge them to write code {tc.way} clean without it!'.format(**locals()) if __name__ == '__main__': main() ----------------------------------------------------- -- Duncan Booth http://kupuguy.blogspot.com From dihedral88888 at googlemail.com Thu Jan 10 08:04:48 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 10 Jan 2013 05:04:48 -0800 (PST) Subject: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes In-Reply-To: References: Message-ID: ? 2013?1?10????UTC+8??7?34?23??Duncan Booth??? > Dave Cinege wrote: > > > > > You will notice that the code is disgusting simple. However I have > > > found that this has completely changed the way I program in python. > > > I've re-written some exiting programs using Thesaurus, and often > > > relized 15-30% code reduction. Additionally I find the new code much > > > easier to read. > > > > And here's the same code written without your class but maintaining as > > far as possible the same structure. I find my version far easier to read > > then your's with all your spurious 'g.' 'L.' prefixes. > > > > > > ----------------------------------------------------- > > > > #!python2.7 > > from textwrap import dedent > > > > class Blob(object): pass > > > > prog = Blob() > > prog.VERSION = '1.0' # But isn't this so much cleaner? > > prog.NAME = 'Thesaurus' > > > > class TestClass: > > no = 'Class' > > way = 'this' > > > > def main (): > > tc = TestClass() > > l = ['Some', 'objects'] > > > > # Here's how you should create output without a fight. > > print dedent('''\ > > When programing python without {prog.NAME}, it is very > > easy to access your {l[1]}. > > > > {l[0]} people might say {prog.NAME} has no {tc.no}.''').format(prog=prog, l=l, tc=tc) > > > > if hasattr(prog, 'VERSION'): > > print 'But I challenge them to write code {tc.way} clean without it!'.format(**locals()) > > > > if __name__ == '__main__': > > main() > > ----------------------------------------------------- > > > > > > -- > > Duncan Booth http://kupuguy.blogspot.com An object can accquire new properties and methods in the run time without the limitations from the class definition of the object which belongs to. This is a true OOP language. From darcy at PyGreSQL.org Tue Jan 8 15:36:55 2013 From: darcy at PyGreSQL.org (D'Arcy J.M. Cain) Date: Tue, 8 Jan 2013 15:36:55 -0500 Subject: New version of PyGreSQL 4.1.1 - bug fixes Message-ID: <20130108153655.12c91949@dilbert> --------------------------------- Release of PyGreSQL version 4.1.1 --------------------------------- A few problems showed up with the 4.1 release so we are releasing a quick bugfix version. It is available at: http://pygresql.org/files/PyGreSQL-4.1.1.tgz. If you are running NetBSD, look in the packages directory under databases. There is also a package in the FreeBSD ports collection. Please refer to `changelog.txt `_ for things that have changed in this version. Please refer to `readme.txt `_ for general information. This version has been built and unit tested on: - NetBSD - FreeBSD - openSUSE 12.2 - Windows 7 with both MinGW and Visual Studio - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit - Python 2.5, 2.6 and 2.7 32 and 64bit | D'Arcy J.M. Cain | darcy at PyGreSQL.org -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org IM:darcy at Vex.Net From roy at panix.com Tue Jan 8 16:22:09 2013 From: roy at panix.com (Roy Smith) Date: 8 Jan 2013 16:22:09 -0500 Subject: How to tell how many weeks apart two datetimes are? Message-ID: How do you tell how many weeks apart two datetimes (t1 and t2) are? The "obvious" solution would be: weeks = (t2 - t1) / timedelta(days=7) but that doesn't appear to be allowed. Is there some fundamental reason why timedelta division not supported? From marduk at python.net Tue Jan 8 16:31:42 2013 From: marduk at python.net (marduk) Date: Tue, 08 Jan 2013 16:31:42 -0500 Subject: How to tell how many weeks apart two datetimes are? In-Reply-To: References: Message-ID: <1357680702.16005.140661175088049.02B157E9@webmail.messagingengine.com> On Tue, Jan 8, 2013, at 04:22 PM, Roy Smith wrote: > How do you tell how many weeks apart two datetimes (t1 and t2) are? > The "obvious" solution would be: > > weeks = (t2 - t1) / timedelta(days=7) > > but that doesn't appear to be allowed. Is there some fundamental > reason why timedelta division not supported? > -- > http://mail.python.org/mailman/listinfo/python-list It works for python 3(.2): >>> x = datetime.timedelta(days=666) >>> week = datetime.timedelta(days=7) >>> x / week 95.14285714285714 >>> halfday = datetime.timedelta(hours=12) >>> x / halfday 1332.0 From ian.g.kelly at gmail.com Tue Jan 8 16:33:50 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Jan 2013 14:33:50 -0700 Subject: How to tell how many weeks apart two datetimes are? In-Reply-To: References: Message-ID: On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith wrote: > How do you tell how many weeks apart two datetimes (t1 and t2) are? > The "obvious" solution would be: > > weeks = (t2 - t1) / timedelta(days=7) > > but that doesn't appear to be allowed. Is there some fundamental > reason why timedelta division not supported? Seems to be supported in Python 3.3, but not in 2.7. From ian.g.kelly at gmail.com Tue Jan 8 16:36:08 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Jan 2013 14:36:08 -0700 Subject: How to tell how many weeks apart two datetimes are? In-Reply-To: References: Message-ID: On Tue, Jan 8, 2013 at 2:33 PM, Ian Kelly wrote: > On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith wrote: >> How do you tell how many weeks apart two datetimes (t1 and t2) are? >> The "obvious" solution would be: >> >> weeks = (t2 - t1) / timedelta(days=7) >> >> but that doesn't appear to be allowed. Is there some fundamental >> reason why timedelta division not supported? > > Seems to be supported in Python 3.3, but not in 2.7. >From the docs: Changed in version 3.2: Floor division and true division of a timedelta object by another timedelta object are now supported, as are remainder operations and the divmod() function. True division and multiplication of a timedelta object by a float object are now supported. From python at mrabarnett.plus.com Tue Jan 8 17:50:41 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 08 Jan 2013 22:50:41 +0000 Subject: How to tell how many weeks apart two datetimes are? In-Reply-To: References: Message-ID: <50ECA2C1.1000305@mrabarnett.plus.com> On 2013-01-08 21:22, Roy Smith wrote: > How do you tell how many weeks apart two datetimes (t1 and t2) are? > The "obvious" solution would be: > > weeks = (t2 - t1) / timedelta(days=7) > > but that doesn't appear to be allowed. Is there some fundamental > reason why timedelta division not supported? > Try this: weeks = (t2 - t1).days / 7 From oscar.j.benjamin at gmail.com Tue Jan 8 17:54:20 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 8 Jan 2013 22:54:20 +0000 Subject: How to tell how many weeks apart two datetimes are? In-Reply-To: <50ECA2C1.1000305@mrabarnett.plus.com> References: <50ECA2C1.1000305@mrabarnett.plus.com> Message-ID: On 8 January 2013 22:50, MRAB wrote: > On 2013-01-08 21:22, Roy Smith wrote: >> >> How do you tell how many weeks apart two datetimes (t1 and t2) are? >> The "obvious" solution would be: >> >> weeks = (t2 - t1) / timedelta(days=7) >> >> but that doesn't appear to be allowed. Is there some fundamental >> reason why timedelta division not supported? >> > Try this: > > weeks = (t2 - t1).days / 7 You beat me to it... $ python Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> dt1 = datetime.datetime.now() >>> dt2 = dt1 - datetime.timedelta(days=8) >>> (dt2 - dt1) / 7 > datetime.timedelta(days=14) False Oscar From andydtaylor at gmail.com Tue Jan 8 19:19:59 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Tue, 8 Jan 2013 16:19:59 -0800 (PST) Subject: Best way to do this? List loop (matrix?) iteration Message-ID: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> Hi! I might be missing the obvious, or I may have found something more complicated than the VBA I am used to. Could it be I need to use a maths library? For a given list of k items I'd like to turn it into an k*k matrix of item pairs. List_sample = ['a', 'b', 'c'] Output: aa ab ac ba bb bc ca cb cc I'd like to have 2 hooks into this process 1. I want the opportunity to use a value pair each time they are generated (because I need to send these to an api and get a number back to put into a temporary list or dictionary - still tbd). 2. I'd also like to know each time a row is completed so I can bank that temporary list to a database table. Else build one big list and do it at the end, I'm still figuring this out. #Code I've tried: stn_count = len(stn_list_short) for rowcount in range (0, stn_count): for colcount in range (0, stn_count): print stn_list_long[rowcount] stn_list_long[colcount] I've found itertools, tee, and product and felt I was getting warmer. I'm still looking, but any pointers would be appreciated! Thanks, Andy From msirenef at lightbird.net Tue Jan 8 19:33:18 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Tue, 08 Jan 2013 19:33:18 -0500 Subject: Best way to do this? List loop (matrix?) iteration In-Reply-To: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> References: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> Message-ID: <50ECBACE.1030107@lightbird.net> On Tue 08 Jan 2013 07:19:59 PM EST, andydtaylor at gmail.com wrote: > Hi! > > I might be missing the obvious, or I may have found something more complicated than the VBA I am used to. Could it be I need to use a maths library? > > For a given list of k items I'd like to turn it into an k*k matrix of item pairs. > > List_sample = ['a', 'b', 'c'] > > Output: > > aa ab ac > ba bb bc > ca cb cc > > I'd like to have 2 hooks into this process > 1. I want the opportunity to use a value pair each time they are generated (because I need to send these to an api and get a number back to put into a temporary list or dictionary - still tbd). > 2. I'd also like to know each time a row is completed so I can bank that temporary list to a database table. Else build one big list and do it at the end, I'm still figuring this out. > > #Code I've tried: > > stn_count = len(stn_list_short) > for rowcount in range (0, stn_count): > for colcount in range (0, stn_count): > print stn_list_long[rowcount] stn_list_long[colcount] > > I've found itertools, tee, and product and felt I was getting warmer. I'm still looking, but any pointers would be appreciated! > > Thanks, > > Andy > > You can use itertools.product("abc", repeat=2) together with itertools recipe grouper() from the same page: http://docs.python.org/3.3/library/itertools.html?highlight=itertools#itertools HTH, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From rosuav at gmail.com Tue Jan 8 21:06:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Jan 2013 13:06:05 +1100 Subject: Best way to do this? List loop (matrix?) iteration In-Reply-To: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> References: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> Message-ID: On Wed, Jan 9, 2013 at 11:19 AM, wrote: > stn_count = len(stn_list_short) > for rowcount in range (0, stn_count): > for colcount in range (0, stn_count): > print stn_list_long[rowcount] stn_list_long[colcount] First off, you can iterate over the list directly: for row in stn_list_short: for col in stn_list_short: print row + col (I'm not sure what your code was doing with the print line, because it ought to have failed. Explicit concatenation will work.) Secondly, you can make a list of all of those pairs with a compact notation called a comprehension: pairs = [row + col for row in stn_list_short for col in stn_list_short] That covers your requirement #2, giving you a full list of all of them. How big is k going to be? Storing the whole list in memory will get a little awkward if you have very large k; on this system, I started seeing performance issues with a thousand elements in the list, but you could probably go to ten thousand (ie a hundred million pairs) if you have a decent bit of RAM. ChrisA From andydtaylor at gmail.com Wed Jan 9 18:24:49 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Wed, 9 Jan 2013 15:24:49 -0800 (PST) Subject: Best way to do this? List loop (matrix?) iteration In-Reply-To: References: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> Message-ID: <306bb7cd-c9b9-47db-87f5-a4aa8422a7c8@googlegroups.com> Thanks for your help - this is what I did - though it's probably obvious to most people reading this. for rowcount in range (0, stn_count): row_durations.append(stn_list_short[rowcount]) for colcount in range (0, stn_count): # 3. Determine Station pairs for API query query_origin_stop = stn_list_long[rowcount] query_destination_stop = stn_list_long[colcount] # 4. Paths for determining duration. "station x = station x" has journey time 0 # 4a. Stations are SAME ....etc. and this part works! I am now stuck on something else though, but I'll start a new topic for that. Thanks Andy From andydtaylor at gmail.com Wed Jan 9 18:24:49 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Wed, 9 Jan 2013 15:24:49 -0800 (PST) Subject: Best way to do this? List loop (matrix?) iteration In-Reply-To: References: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> Message-ID: <306bb7cd-c9b9-47db-87f5-a4aa8422a7c8@googlegroups.com> Thanks for your help - this is what I did - though it's probably obvious to most people reading this. for rowcount in range (0, stn_count): row_durations.append(stn_list_short[rowcount]) for colcount in range (0, stn_count): # 3. Determine Station pairs for API query query_origin_stop = stn_list_long[rowcount] query_destination_stop = stn_list_long[colcount] # 4. Paths for determining duration. "station x = station x" has journey time 0 # 4a. Stations are SAME ....etc. and this part works! I am now stuck on something else though, but I'll start a new topic for that. Thanks Andy From d at davea.name Wed Jan 9 18:49:53 2013 From: d at davea.name (Dave Angel) Date: Wed, 09 Jan 2013 18:49:53 -0500 Subject: Best way to do this? List loop (matrix?) iteration In-Reply-To: <306bb7cd-c9b9-47db-87f5-a4aa8422a7c8@googlegroups.com> References: <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> <306bb7cd-c9b9-47db-87f5-a4aa8422a7c8@googlegroups.com> Message-ID: <50EE0221.9060406@davea.name> On 01/09/2013 06:24 PM, andydtaylor at gmail.com wrote: > Thanks for your help - this is what I did - though it's probably obvious to most people reading this. > > for rowcount in range (0, stn_count): > row_durations.append(stn_list_short[rowcount]) > for colcount in range (0, stn_count): > # 3. Determine Station pairs for API query > query_origin_stop = stn_list_long[rowcount] > query_destination_stop = stn_list_long[colcount] > # 4. Paths for determining duration. "station x = station x" has journey time 0 > # 4a. Stations are SAME > Please reread Chris Angelico's message. Iterating over the lists themselves, instead of making a range, is shorter, easier to read, and usually quicker. > ....etc. and this part works! I am now stuck on something else though, but I'll start a new topic for that. > > Thanks > > Andy Untested: for rowshort, query_origin_stop in zip(stn_list_short, stn_list_long): row_durations.append(rowshort) for query_destination_stop in stn_list_long: #4 . Determine ... -- DaveA From chenyong20000 at gmail.com Wed Jan 9 03:23:56 2013 From: chenyong20000 at gmail.com (skyworld) Date: Wed, 9 Jan 2013 00:23:56 -0800 (PST) Subject: functon invoke or not Message-ID: Hi, I see someone's code as this: class ABC: .... def __init__(self, env): ....... self.jmpTable['batchQ']['submit_job'] = self.lsf_submit ....... def lsf_submit(self, cmd,env): ..... what confused me is why there is no parentheses for self.lsf_submit in "self.jmpTable['batchQ']['submit_job'] = self.lsf_submit"? what does this piece of code mean? thanks. From __peter__ at web.de Wed Jan 9 03:43:15 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 09 Jan 2013 09:43:15 +0100 Subject: functon invoke or not References: Message-ID: skyworld wrote: > Hi, > > I see someone's code as this: > > class ABC: .... > def __init__(self, env): > ....... > self.jmpTable['batchQ']['submit_job'] = self.lsf_submit The bound method self.lsf_submit is not invoked in this line, it is stored for later use. > ....... > def lsf_submit(self, cmd,env): > ..... > > what confused me is why there is no parentheses for self.lsf_submit in > "self.jmpTable['batchQ']['submit_job'] = self.lsf_submit"? what does > this piece of code mean? thanks. Somewhere else in the code the is probably code similar to var1 = ... var2 = ... self.jmpTable[var1][var2](some_command, some_env) When var1 is "batchQ" and var2 is "submit_job" this will in effect call self.lsf_submit(some_command, some_env) A slightly simplified example with just a dict and two functions: >>> def german(name): ... print "Guten Tag, Herr", name ... >>> def french(name): ... print "Bonjour, M.", name ... >>> lookup = {"fr": french, "de": german} >>> lookup["fr"]("Hulot") Bonjour, M. Hulot From msirenef at lightbird.net Wed Jan 9 03:46:57 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 09 Jan 2013 03:46:57 -0500 Subject: functon invoke or not In-Reply-To: References: Message-ID: <50ED2E81.5060705@lightbird.net> On Wed 09 Jan 2013 03:23:56 AM EST, skyworld wrote: > Hi, > > I see someone's code as this: > > class ABC: .... > def __init__(self, env): > ....... > self.jmpTable['batchQ']['submit_job'] = self.lsf_submit > ....... > def lsf_submit(self, cmd,env): > ..... > > what confused me is why there is no parentheses for self.lsf_submit in > "self.jmpTable['batchQ']['submit_job'] = self.lsf_submit"? what does > this piece of code mean? thanks. Presumably it will be called at a later point: def f(): print 'foo' lst = [f] # la la lst[0]() HTH, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From chenyong20000 at gmail.com Wed Jan 9 03:50:31 2013 From: chenyong20000 at gmail.com (skyworld) Date: Wed, 9 Jan 2013 00:50:31 -0800 (PST) Subject: functon invoke or not References: Message-ID: On 1?9?, ??4?46?, Mitya Sirenef wrote: > On Wed 09 Jan 2013 03:23:56 AM EST, skyworld wrote: > > > Hi, > > > I see someone's code as this: > > > class ABC: .... > > ? ? ?def __init__(self, env): > > ? ? ? ? ? ....... > > ? ? ? ? ? self.jmpTable['batchQ']['submit_job'] ?= self.lsf_submit > > ? ? ? ? ? ....... > > ? ? ?def lsf_submit(self, cmd,env): > > ? ? ? ? ? ..... > > > what confused me is why there is no parentheses for self.lsf_submit in > > "self.jmpTable['batchQ']['submit_job'] ?= self.lsf_submit"? what does > > this piece of code mean? thanks. > > Presumably it will be called at a later point: > > def f(): print 'foo' > > lst = [f] > # la la > lst[0]() > > HTH, ?-m > > -- > Lark's Tongue Guide to Python:http://lightbird.net/larks/ Thanks for both of your replies. I got it. From jpiitula at ling.helsinki.fi Wed Jan 9 03:55:03 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 09 Jan 2013 10:55:03 +0200 Subject: functon invoke or not References: Message-ID: skyworld writes: > Hi, > > I see someone's code as this: > > class ABC: .... > def __init__(self, env): > ....... > self.jmpTable['batchQ']['submit_job'] = self.lsf_submit > ....... > def lsf_submit(self, cmd,env): > ..... > > what confused me is why there is no parentheses for self.lsf_submit in > "self.jmpTable['batchQ']['submit_job'] = self.lsf_submit"? what does > this piece of code mean? thanks. Functions are objects. The above is storing the function lsf_submit in a dict from where it can later be taken and invoked. The invocation is indicated by the parentheses after an expression that denotes a function. Consider the following, and play with examples of your own in a Python interpreter. >>> from math import acos >>> def foo(x): return acos, x ... >>> foo(-1) (, -1) >>> foo(-1)[0] >>> foo(-1)[0](foo(-1)[1]) 3.141592653589793 Or simply: >>> acos >>> acos(-1) 3.141592653589793 From python.prog29 at gmail.com Wed Jan 9 05:08:23 2013 From: python.prog29 at gmail.com (python.prog29 at gmail.com) Date: Wed, 9 Jan 2013 02:08:23 -0800 (PST) Subject: Regex not matching a string Message-ID: <356fa8f5-0343-4fd5-80d8-5d2417ce1cd6@googlegroups.com> Hi All - In the following code ,am trying to remove a multi line - comment that contains "This is a test comment" for some reason the regex is not matching.. can anyone provide inputs on why it is so? import os import sys import re import fnmatch def find_and_remove(haystack, needle): pattern = re.compile(r'/\*.*?'+ needle + '.*?\*/', re.DOTALL) return re.sub(pattern, "", haystack) for path,dirs,files in os.walk(sys.argv[1]): for fname in files: for pat in ['*.cpp','*.c','*.h','*.txt']: if fnmatch.fnmatch(fname,pat): fullname = os.path.join(path,fname) # put all the text into f and read and replace... f = open(fullname).read() result = find_and_remove(f, r"This is a test comment") print result From steve+comp.lang.python at pearwood.info Wed Jan 9 05:33:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Jan 2013 10:33:55 GMT Subject: Regex not matching a string References: <356fa8f5-0343-4fd5-80d8-5d2417ce1cd6@googlegroups.com> Message-ID: <50ed4792$0$29898$c3e8da3$5496439d@news.astraweb.com> On Wed, 09 Jan 2013 02:08:23 -0800, python.prog29 wrote: > Hi All - > > > In the following code ,am trying to remove a multi line - comment that > contains "This is a test comment" for some reason the regex is not > matching.. can anyone provide inputs on why it is so? It works for me. Some observations: Perhaps you should consider using the glob module rather than manually using fnmatch. That's what glob does. Also, you never actually write to the files, is that deliberate? Finally, perhaps your regex simply doesn't match what you think it matches. Do you actually have any files containing the needle "/* ... This is a test comment ... */" (where the ... are any characters) exactly as shown? Instead of giving us all the irrelevant code that has nothing to do with matching a regex, you should come up with a simple piece of example code that demonstrates your problem. Or, in this case, *fails* to demonstrate the problem. import re haystack = "aaa\naaa /*xxxThis is a test comment \nxxx*/aaa\naaa\n" needle = "This is a test comment" pattern = re.compile(r'/\*.*?'+ needle + '.*?\*/', re.DOTALL) print haystack print re.sub(pattern, "", haystack) -- Steven From __peter__ at web.de Wed Jan 9 05:57:03 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 09 Jan 2013 11:57:03 +0100 Subject: Regex not matching a string References: <356fa8f5-0343-4fd5-80d8-5d2417ce1cd6@googlegroups.com> Message-ID: python.prog29 at gmail.com wrote: > In the following code ,am trying to remove a multi line - comment that > contains "This is a test comment" for some reason the regex is not > matching.. can anyone provide inputs on why it is so? > def find_and_remove(haystack, needle): > pattern = re.compile(r'/\*.*?'+ needle + '.*?\*/', re.DOTALL) > return re.sub(pattern, "", haystack) If a comment does not contain the needle "/\*.*?" extends over the end of that comment: >>> re.compile(r"/\*.*?xxx").search("/* xxx */").group() '/* xxx' >>> re.compile(r"/\*.*?xxx").search("/* yyy */ /* xxx */").group() '/* yyy */ /* xxx' One solution may be a substitution function: >>> def sub(match, needle="xxx"): ... s = match.group() ... if needle in s: ... return "" ... else: ... return s ... >>> re.compile(r"/\*.*?\*/").sub(sub, "/* yyy */ /* xxx */") '/* yyy */ ' From antoon.pardon at rece.vub.ac.be Wed Jan 9 08:22:28 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 09 Jan 2013 14:22:28 +0100 Subject: socket.makefile raises ValueError when mode = 'rt' Message-ID: <50ED6F14.70903@rece.vub.ac.be> This is using python 3.2. I am writing somekind of wrapper around the ftplib. So that you can work with it as if you are working with local files. The idea is that you start with making a connection like rmt = FTP(...) and then do something like the following rmtfl = rmt.open("rmtfilename", "rt") for ln in rmtfl: treat(ln) This is part of the code: class ftpfile: def __init__(self, cn, rfn, mode, bound = False): self.ftp = cn self.bound = bound if 'b' in mode: self.ftp.voidcmd('TYPE I') else: self.ftp.voidcmd('TYPE A') if 'r' in mode: self.cnct = self.ftp.transfercmd("RETR %s" % rfn) self.fl = self.cnct.makefile(mode) elif 'w' in mode: self.cnct = self.ftp.transfercmd("STOR %s" % rfn) self.fl = self.cnct.makefile(mode, newline = '\r\n') else: raise ValueError("%s: invalide mode" % mode) The problem is with makefile. If mode contains a "t" I get the following traceback: Traceback (most recent call last): File "ftputil.tpy", line 14, in test_textftp rmtfl1 = rmt.open('ftp1.py', 'wt') File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 76, in open return ftpfile(ftp, fn, mode, True) File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 15, in __init__ self.fl = self.cnct.makefile(mode, newline = '\r\n') File "/usr/lib/python3.2/socket.py", line 151, in makefile raise ValueError("invalid mode %r (only r, w, b allowed)") ValueError: invalid mode %r (only r, w, b allowed) But the documentation states: socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None, newline=None) Return a file object associated with the socket. The exact returned type depends on the arguments given to makefile(). These arguments are interpreted the same way as by the built-in open() function. And since 't' is allowed in the mode of the built-in open() function I would consider this a bug. Unless I am missing something? From d at davea.name Wed Jan 9 08:54:53 2013 From: d at davea.name (Dave Angel) Date: Wed, 09 Jan 2013 08:54:53 -0500 Subject: socket.makefile raises ValueError when mode = 'rt' In-Reply-To: <50ED6F14.70903@rece.vub.ac.be> References: <50ED6F14.70903@rece.vub.ac.be> Message-ID: <50ED76AD.5060303@davea.name> On 01/09/2013 08:22 AM, Antoon Pardon wrote: > This is using python 3.2. > > I am writing somekind of wrapper around the ftplib. So > that you can work with it as if you are working with > local files. > > The idea is that you start with making a connection like > > rmt = FTP(...) > > and then do something like the following > > rmtfl = rmt.open("rmtfilename", "rt") > for ln in rmtfl: > treat(ln) > > This is part of the code: > > class ftpfile: > def __init__(self, cn, rfn, mode, bound = False): > self.ftp = cn > self.bound = bound > if 'b' in mode: > self.ftp.voidcmd('TYPE I') > else: > self.ftp.voidcmd('TYPE A') > if 'r' in mode: > self.cnct = self.ftp.transfercmd("RETR %s" % rfn) > self.fl = self.cnct.makefile(mode) > elif 'w' in mode: > self.cnct = self.ftp.transfercmd("STOR %s" % rfn) > self.fl = self.cnct.makefile(mode, newline = '\r\n') > else: > raise ValueError("%s: invalide mode" % mode) > > The problem is with makefile. If mode contains a "t" I get > the following traceback: > > Traceback (most recent call last): > File "ftputil.tpy", line 14, in test_textftp > rmtfl1 = rmt.open('ftp1.py', 'wt') > File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 76, > in open > return ftpfile(ftp, fn, mode, True) > File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 15, > in __init__ > self.fl = self.cnct.makefile(mode, newline = '\r\n') > File "/usr/lib/python3.2/socket.py", line 151, in makefile > raise ValueError("invalid mode %r (only r, w, b allowed)") > ValueError: invalid mode %r (only r, w, b allowed) > > But the documentation states: > socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None, > newline=None) > Return a file object associated with the socket. The exact returned > type depends on the arguments given to makefile(). These arguments are > interpreted the same way as by the built-in open() function. > > And since 't' is allowed in the mode of the built-in open() function I > would consider this a bug. > Unless I am missing something? I believe that 't' was a new addition to mode, for Python 3.x So perhaps the socket library hasn't kept consistent with it. I don't really know the socket library. Does it even support text mode? Does that make sense? Remember that text mode means a different thing in 3.x than it did in 2.x -- DaveA From antoon.pardon at rece.vub.ac.be Wed Jan 9 09:14:46 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 09 Jan 2013 15:14:46 +0100 Subject: socket.makefile raises ValueError when mode = 'rt' In-Reply-To: <50ED76AD.5060303@davea.name> References: <50ED6F14.70903@rece.vub.ac.be> <50ED76AD.5060303@davea.name> Message-ID: <50ED7B56.105@rece.vub.ac.be> Op 01/09/13 14:54, Dave Angel schreef: > On 01/09/2013 08:22 AM, Antoon Pardon wrote: >> This is using python 3.2. ... >> But the documentation states: >> socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None, >> newline=None) >> Return a file object associated with the socket. The exact returned >> type depends on the arguments given to makefile(). These arguments are >> interpreted the same way as by the built-in open() function. >> >> And since 't' is allowed in the mode of the built-in open() function I >> would consider this a bug. >> Unless I am missing something? > I believe that 't' was a new addition to mode, for Python 3.x So > perhaps the socket library hasn't kept consistent with it. > > I don't really know the socket library. Does it even support text > mode? Does that make sense? Remember that text mode means a different > thing in 3.x than it did in 2.x As far as I understand the code, it does support text. This is part of the makefile method. def makefile(self, mode="r", buffering=None, *, encoding=None, errors=None, newline=None): for c in mode: if c not in {"r", "w", "b"}: raise ValueError("invalid mode %r (only r, w, b allowed)") writing = "w" in mode reading = "r" in mode or not writing assert reading or writing binary = "b" in mode ... if binary: return buffer text = io.TextIOWrapper(buffer, encoding, errors, newline) text.mode = mode return text So it seems that if the mode is not binary an io.TextIOWrapper is returned. That indicates to me that text mode is supported. -- Antoon Pardon From tjreedy at udel.edu Wed Jan 9 18:36:16 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 09 Jan 2013 18:36:16 -0500 Subject: socket.makefile raises ValueError when mode = 'rt' In-Reply-To: <50ED7B56.105@rece.vub.ac.be> References: <50ED6F14.70903@rece.vub.ac.be> <50ED76AD.5060303@davea.name> <50ED7B56.105@rece.vub.ac.be> Message-ID: On 1/9/2013 9:14 AM, Antoon Pardon wrote: > Op 01/09/13 14:54, Dave Angel schreef: >> On 01/09/2013 08:22 AM, Antoon Pardon wrote: >>> This is using python 3.2. > ... >>> But the documentation states: >>> socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None, >>> newline=None) >>> Return a file object associated with the socket. The exact returned >>> type depends on the arguments given to makefile(). These arguments are >>> interpreted the same way as by the built-in open() function. >>> >>> And since 't' is allowed in the mode of the built-in open() function I >>> would consider this a bug. >>> Unless I am missing something? >> I believe that 't' was a new addition to mode, for Python 3.x So >> perhaps the socket library hasn't kept consistent with it. >> >> I don't really know the socket library. Does it even support text >> mode? Does that make sense? Remember that text mode means a different >> thing in 3.x than it did in 2.x > As far as I understand the code, it does support text. This is part of > the makefile method. > > def makefile(self, mode="r", buffering=None, *, > encoding=None, errors=None, newline=None): > > for c in mode: > if c not in {"r", "w", "b"}: > raise ValueError("invalid mode %r (only r, w, b allowed)") > writing = "w" in mode > reading = "r" in mode or not writing > assert reading or writing > binary = "b" in mode > ... > if binary: > return buffer > text = io.TextIOWrapper(buffer, encoding, errors, newline) > text.mode = mode > return text > > So it seems that if the mode is not binary an io.TextIOWrapper is > returned. That indicates to me that > text mode is supported. The doc does not specify any limit on mode, though the exclusions 'a', '+', 'x', and 'U' seem proper to me. That contradicts the mode check. The exclusion of of 't' (which is the default, in that 'b' must be explicitly given to have effect) contradicts the later code. I think you should open an issue on the tracker suggesting that 't' be added to the mode check and that the doc mention the remaining mode limitation. In the meanwhile, your ftpfile.__init__ could remove t from the mode before passing it on. -- Terry Jan Reedy From j.trevino.a at gmail.com Wed Jan 9 09:45:43 2013 From: j.trevino.a at gmail.com (Jose Trevino) Date: Wed, 9 Jan 2013 06:45:43 -0800 (PST) Subject: PIL or something to open EXIF Metadata with Python Message-ID: I am trying to load the PIL module to manage exif metadata with Python but have had no success. I do some work relate with applescript, but for large files time increases exponentially. So I changed to Python with the intention of using PIL or something similar. I see that the last update of PIL is like 3 years ago, so I don't know if it is still working. I downloaded the last version of PIL to my mac, but I can't get python to recognize PIL included commands. Does anybody has a suggestion? Thanks. From mail at timgolden.me.uk Wed Jan 9 09:57:45 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 09 Jan 2013 14:57:45 +0000 Subject: PIL or something to open EXIF Metadata with Python In-Reply-To: References: Message-ID: <50ED8569.7070505@timgolden.me.uk> On 09/01/2013 14:45, Jose Trevino wrote: > I am trying to load the PIL module to manage exif metadata with > Python but have had no success. Try pyexiv2: http://tilloy.net/dev/pyexiv2/ TJG From petef4+usenet at gmail.com Thu Jan 10 06:16:48 2013 From: petef4+usenet at gmail.com (Pete Forman) Date: Thu, 10 Jan 2013 11:16:48 +0000 Subject: PIL or something to open EXIF Metadata with Python References: Message-ID: <86ip75e19b.fsf@gmail.com> Tim Golden writes: > On 09/01/2013 14:45, Jose Trevino wrote: >> I am trying to load the PIL module to manage exif metadata with >> Python but have had no success. > > > Try pyexiv2: > > http://tilloy.net/dev/pyexiv2/ > > TJG Or Hachoir http://pypi.python.org/pypi/hachoir-metadata https://bitbucket.org/haypo/hachoir/wiki/Home -- Pete Forman From kwakukwatiah at gmail.com Wed Jan 9 16:03:16 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Wed, 9 Jan 2013 15:03:16 -0600 Subject: new to python and programming at large Message-ID: <0CF6C67958A245C883EB705CEF9F968F@favour> pls I want to write a function that can compute for the sqrt root of any number.bt it not working pls help. from math import sqrt def squareroot(self): x = sqrt(y) print x -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 9 10:18:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Jan 2013 02:18:11 +1100 Subject: new to python and programming at large In-Reply-To: <0CF6C67958A245C883EB705CEF9F968F@favour> References: <0CF6C67958A245C883EB705CEF9F968F@favour> Message-ID: On Thu, Jan 10, 2013 at 8:03 AM, wrote: > pls I want to write a function that can compute for the sqrt root of any > number.bt it not working pls help. > from math import sqrt > def squareroot(self): > x = sqrt(y) > print x The 'self' argument is a convention used in classes. You probably want to call your argument y: def squareroot(y): since that's what you then pass to math.sqrt. Chris Angelico From alister.ware at ntlworld.com Wed Jan 9 10:38:20 2013 From: alister.ware at ntlworld.com (Alister) Date: Wed, 09 Jan 2013 15:38:20 GMT Subject: new to python and programming at large References: <0CF6C67958A245C883EB705CEF9F968F@favour> Message-ID: On Thu, 10 Jan 2013 02:18:11 +1100, Chris Angelico wrote: > On Thu, Jan 10, 2013 at 8:03 AM, wrote: >> pls I want to write a function that can compute for the sqrt root of >> any number.bt it not working pls help. >> from math import sqrt def squareroot(self): >> x = sqrt(y) >> print x > > The 'self' argument is a convention used in classes. You probably want > to call your argument y: > > def squareroot(y): > > since that's what you then pass to math.sqrt. > > Chris Angelico why even do this when simply calling sqrt is all that is needed? -- Outside of a dog, a book is man's best friend. Inside of a dog, it is too dark to read. From rosuav at gmail.com Wed Jan 9 10:43:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Jan 2013 02:43:23 +1100 Subject: new to python and programming at large In-Reply-To: References: <0CF6C67958A245C883EB705CEF9F968F@favour> Message-ID: On Thu, Jan 10, 2013 at 2:38 AM, Alister wrote: > On Thu, 10 Jan 2013 02:18:11 +1100, Chris Angelico wrote: > >> On Thu, Jan 10, 2013 at 8:03 AM, wrote: >>> pls I want to write a function that can compute for the sqrt root of >>> any number.bt it not working pls help. >>> from math import sqrt def squareroot(self): >>> x = sqrt(y) >>> print x >> >> The 'self' argument is a convention used in classes. You probably want >> to call your argument y: >> >> def squareroot(y): >> >> since that's what you then pass to math.sqrt. >> >> Chris Angelico > > why even do this when simply calling sqrt is all that is needed? Good question. But without a lot more context from the OP, none of this is really ponderable... ChrisA From kwakukwatiah at gmail.com Wed Jan 9 16:05:51 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Wed, 9 Jan 2013 15:05:51 -0600 Subject: new to python and programming at large Message-ID: <5C685724E89E4591A5869A1EB99A5598@favour> pls I want to write a function that can compute for the sqrt root of any number.bt it not working pls help. from math import sqrt def squareroot(self): x = sqrt(y) print x -------------- next part -------------- An HTML attachment was scrubbed... URL: From adrian.espinosa at jazztel.com Wed Jan 9 10:45:25 2013 From: adrian.espinosa at jazztel.com (Adrian Espinosa Moreno) Date: Wed, 9 Jan 2013 16:45:25 +0100 Subject: new to python and programming at large In-Reply-To: <5C685724E89E4591A5869A1EB99A5598@favour> References: <5C685724E89E4591A5869A1EB99A5598@favour> Message-ID: <0A05530EC8DF4244AAD8E4243ACCB24B27A2D5B806@EXI1PWM2.jazztel.com> Hello, you have to use the same parameter, not self which is used in classes def squareroot(n): return sqrt(n) -- Adri?n Espinosa. Engineering Support, Wholesale Systems. Jazztel.com De: kwakukwatiah at gmail.com [mailto:kwakukwatiah at gmail.com] Enviado el: mi?rcoles, 09 de enero de 2013 22:06 Para: python-list at python.org Asunto: new to python and programming at large pls I want to write a function that can compute for the sqrt root of any number.bt it not working pls help. from math import sqrt def squareroot(self): x = sqrt(y) print x ________________________________ -------------------------------------------------------------------------------- Este mensaje es privado y CONFIDENCIAL y se dirige exclusivamente a su destinatario. Si usted ha recibido este mensaje por error, no debe revelar, copiar, distribuir o usarlo en ning?n sentido. Le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. El correo electr?nico via Internet no permite asegurar la confidencialidad de los mensajes que se transmiten ni su integridad o correcta recepci?n. JAZZTEL no asume responsabilidad por estas circunstancias. Si el destinatario de este mensaje no consintiera la utilizaci?n del correo electr?nico via Internet y la grabaci?n de los mensajes, rogamos lo ponga en nuestro conocimiento de forma inmediata.Cualquier opini?n expresada en este mensaje pertenece ?nicamente al autor remitente, y no representa necesariamente la opini?n de JAZZTEL, a no ser que expresamente se diga y el remitente est? autorizado para hacerlo. -------------------------------------------------------------------------------- This message is private and CONFIDENTIAL and it is intended exclusively for its addressee. If you receive this message in error, you should not disclose, copy, distribute this e-mail or use it in any other way. Please inform the sender and delete the message and attachments from your system.Internet e-mail neither guarantees the confidentiality nor the integrity or proper receipt of the messages sent. JAZZTEL does not assume any liability for those circumstances. If the addressee of this message does not consent to the use of Internet e-mail and message recording, please notify us immediately.Any views or opinions contained in this message are solely those of the author, and do not necessarily represent those of JAZZTEL, unless otherwise specifically stated and the sender is authorised to do so. -------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From raphael at mameghani.de Wed Jan 9 11:02:58 2013 From: raphael at mameghani.de (raphael at mameghani.de) Date: Wed, 9 Jan 2013 08:02:58 -0800 (PST) Subject: Interpolating/crossfading a stack of matrices Message-ID: <5b5b7e09-7482-4609-b774-d143de366615@googlegroups.com> Hi, I want to interpolate (with quadratic splines) a stack of 2D-arrays/matrices y1, y2, y3, ... in a third dimension (which I call x) e.g. for crossfading images. I already have a working code which unfortunately still contains two explicit loops over the rows and colums of the matrices. Inside these loops I simply use 'interp1d' from scipy suitable for 1D-interpolations. Is anybody here aware of a better, more efficient solution of my problem? Maybe somewhere out there a compiled routine for my problem already exists in a python library... :-) My code: -----============================================----- from scipy.interpolate import interp1d from numpy import array, empty_like, dstack x = [0.0, 0.25, 0.5, 0.75, 1.0] y1 = array([[1, 10, 100, 1000], [1, 10, 100, 1000]], float) y2 = array([[2, 20, 200, 2000], [2, 20, 200, 2000]], float) y3 = array([[3, 30, 300, 3000], [4, 40, 400, 4000]], float) y4 = array([[4, 40, 400, 4000], [8, 80, 800, 8000]], float) y5 = array([[5, 50, 500, 5000], [16, 160, 1600, 16000]], float) y = dstack((y1, y2, y3, y4, y5)) y_interpol = empty_like(y[:, :, 0]) i_range, j_range = y.shape[:2] for i in xrange(i_range): for j in xrange(j_range): # interpolated value for x = 0.2 y_interpol[i,j] = interp1d(x, y[i, j,:], kind='quadratic')(0.2) print y_interpol -----============================================----- Cheers, Raphael From oscar.j.benjamin at gmail.com Wed Jan 9 17:59:56 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 9 Jan 2013 22:59:56 +0000 Subject: Interpolating/crossfading a stack of matrices In-Reply-To: <5b5b7e09-7482-4609-b774-d143de366615@googlegroups.com> References: <5b5b7e09-7482-4609-b774-d143de366615@googlegroups.com> Message-ID: On 9 January 2013 16:02, wrote: > Hi, > > I want to interpolate (with quadratic splines) a stack of 2D-arrays/matrices y1, y2, y3, ... in a third dimension (which I call x) e.g. for crossfading images. I already have a working code which unfortunately still contains two explicit loops over the rows and colums of the matrices. Inside these loops I simply use 'interp1d' from scipy suitable for 1D-interpolations. Is anybody here aware of a better, more efficient solution of my problem? Maybe somewhere out there a compiled routine for my problem already exists in a python library... :-) It's possible. I wouldn't be surprised if there wasn't any existing code ready for you to use. > > My code: > > -----============================================----- > from scipy.interpolate import interp1d > from numpy import array, empty_like, dstack > > x = [0.0, 0.25, 0.5, 0.75, 1.0] > > y1 = array([[1, 10, 100, 1000], [1, 10, 100, 1000]], float) > y2 = array([[2, 20, 200, 2000], [2, 20, 200, 2000]], float) > y3 = array([[3, 30, 300, 3000], [4, 40, 400, 4000]], float) > y4 = array([[4, 40, 400, 4000], [8, 80, 800, 8000]], float) > y5 = array([[5, 50, 500, 5000], [16, 160, 1600, 16000]], float) > > y = dstack((y1, y2, y3, y4, y5)) > > y_interpol = empty_like(y[:, :, 0]) > i_range, j_range = y.shape[:2] > > for i in xrange(i_range): > for j in xrange(j_range): > # interpolated value for x = 0.2 > y_interpol[i,j] = interp1d(x, y[i, j,:], kind='quadratic')(0.2) > > print y_interpol > -----============================================----- Since numpy arrays make it so easy to form linear combinations of arrays without loops I would probably eliminate the loops and just form the appropriate combinations of the image arrays. For example, to use linear interpolation you could do: def interp_frames_linear(times, frames, t): '''times is a vector of floats frames is a 3D array whose nth page is the image for time t[n] t is the time to interpolate for ''' # Find the two frames to interpolate between # Probably a better way of doing this for n in range(len(t)-1): if times[n] <= t < times[n+1]: break else: raise OutOfBoundsError # Interpolate between the two images alpha = (t - times[n]) / (times[n+1] - times[n]) return (1 - alpha) * frames[:, :, n] + alpha * frames[:, :, n+1] I'm not really sure how quadratic interpolation is supposed to work (I've only ever used linear and cubic) but you should be able to do the same sort of thing. Oscar From raphael at mameghani.de Fri Jan 11 07:20:10 2013 From: raphael at mameghani.de (raphael at mameghani.de) Date: Fri, 11 Jan 2013 04:20:10 -0800 (PST) Subject: Interpolating/crossfading a stack of matrices In-Reply-To: References: <5b5b7e09-7482-4609-b774-d143de366615@googlegroups.com> Message-ID: <7d05bc5a-1d6d-4e1d-8c82-d0198d1f1410@googlegroups.com> >> Hi, >> >> I want to interpolate (with quadratic splines) a stack of 2D-arrays/matrices >> y1, y2, y3, ... in a third dimension (which I call x) e.g. for crossfading >> images. I already have a working code which unfortunately still contains two >> explicit loops over the rows and colums of the matrices. Inside these loops I >> simply use 'interp1d' from scipy suitable for 1D-interpolations. Is anybody >> here aware of a better, more efficient solution of my problem? Maybe >> somewhere out there a compiled routine for my problem already exists in a >> python library... :-) > Since numpy arrays make it so easy to form linear combinations of > arrays without loops I would probably eliminate the loops and just > form the appropriate combinations of the image arrays. For example, to > use linear interpolation you could do: > > > > def interp_frames_linear(times, frames, t): > > '''times is a vector of floats > > frames is a 3D array whose nth page is the image for time t[n] > > t is the time to interpolate for > > ''' > > # Find the two frames to interpolate between > > # Probably a better way of doing this > > for n in range(len(t)-1): > > if times[n] <= t < times[n+1]: > > break > > else: > > raise OutOfBoundsError > > > > # Interpolate between the two images > > alpha = (t - times[n]) / (times[n+1] - times[n]) > > return (1 - alpha) * frames[:, :, n] + alpha * frames[:, :, n+1] > > > > I'm not really sure how quadratic interpolation is supposed to work > (I've only ever used linear and cubic) but you should be able to do > the same sort of thing. > > Oscar Indeed, the 'manual' reimplementation of the interpolation formula using numpy arrays significantly sped up the code. The numexpr package made it even faster. Thanks a lot for your advice! Raphael From raphael at mameghani.de Fri Jan 11 07:20:10 2013 From: raphael at mameghani.de (raphael at mameghani.de) Date: Fri, 11 Jan 2013 04:20:10 -0800 (PST) Subject: Interpolating/crossfading a stack of matrices In-Reply-To: References: <5b5b7e09-7482-4609-b774-d143de366615@googlegroups.com> Message-ID: <7d05bc5a-1d6d-4e1d-8c82-d0198d1f1410@googlegroups.com> >> Hi, >> >> I want to interpolate (with quadratic splines) a stack of 2D-arrays/matrices >> y1, y2, y3, ... in a third dimension (which I call x) e.g. for crossfading >> images. I already have a working code which unfortunately still contains two >> explicit loops over the rows and colums of the matrices. Inside these loops I >> simply use 'interp1d' from scipy suitable for 1D-interpolations. Is anybody >> here aware of a better, more efficient solution of my problem? Maybe >> somewhere out there a compiled routine for my problem already exists in a >> python library... :-) > Since numpy arrays make it so easy to form linear combinations of > arrays without loops I would probably eliminate the loops and just > form the appropriate combinations of the image arrays. For example, to > use linear interpolation you could do: > > > > def interp_frames_linear(times, frames, t): > > '''times is a vector of floats > > frames is a 3D array whose nth page is the image for time t[n] > > t is the time to interpolate for > > ''' > > # Find the two frames to interpolate between > > # Probably a better way of doing this > > for n in range(len(t)-1): > > if times[n] <= t < times[n+1]: > > break > > else: > > raise OutOfBoundsError > > > > # Interpolate between the two images > > alpha = (t - times[n]) / (times[n+1] - times[n]) > > return (1 - alpha) * frames[:, :, n] + alpha * frames[:, :, n+1] > > > > I'm not really sure how quadratic interpolation is supposed to work > (I've only ever used linear and cubic) but you should be able to do > the same sort of thing. > > Oscar Indeed, the 'manual' reimplementation of the interpolation formula using numpy arrays significantly sped up the code. The numexpr package made it even faster. Thanks a lot for your advice! Raphael From kevin.reed2 at hp.com Wed Jan 9 11:05:31 2013 From: kevin.reed2 at hp.com (Reed, Kevin) Date: Wed, 9 Jan 2013 16:05:31 +0000 Subject: wiki.python.org Message-ID: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> Hello, I have been unable to access wiki.python.org for two days. Is there a problem with the server, or is it me? Thank you much, Kevin C. Reed New Python User -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Wed Jan 9 11:26:27 2013 From: msarro at gmail.com (Matty Sarro) Date: Wed, 9 Jan 2013 11:26:27 -0500 Subject: wiki.python.org In-Reply-To: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> References: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> Message-ID: Wiki.python.org was compromised a few days ago, almost everything was wiped per a previous email. Not sure what the recovery status is. On Wed, Jan 9, 2013 at 11:05 AM, Reed, Kevin wrote: > Hello,**** > > ** ** > > I have been unable to access wiki.python.org for two days. Is there a > problem with the server, or is it me?**** > > ** ** > > Thank you much,**** > > ** ** > > Kevin C. Reed**** > > New Python User**** > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kensubuntu at gmail.com Wed Jan 9 11:30:03 2013 From: kensubuntu at gmail.com (Ken) Date: Wed, 9 Jan 2013 11:30:03 -0500 Subject: wiki.python.org In-Reply-To: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> References: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> Message-ID: <20130109163003.GA4740@ken-HP-Mini-110-1000> On Wed, Jan 09, 2013 at 04:05:31PM +0000, Reed, Kevin wrote: > Hello, > > I have been unable to access wiki.python.org for two days. Is there a problem with the server, or is it me? > > Thank you much, > > Kevin C. Reed > New Python User Well, I just tried it twice and could not get there, so I would say it is a problem on the server's end. Ken -- Corruption is not the #1 priority of the Police Commissioner. His job is to enforce the law and fight crime. -- P. B. A. President E. J. Kiernan From benjamin.kaplan at case.edu Wed Jan 9 11:36:42 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 9 Jan 2013 08:36:42 -0800 Subject: wiki.python.org In-Reply-To: <20130109163003.GA4740@ken-HP-Mini-110-1000> References: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> <20130109163003.GA4740@ken-HP-Mini-110-1000> Message-ID: On Wed, Jan 9, 2013 at 8:30 AM, Ken wrote: > On Wed, Jan 09, 2013 at 04:05:31PM +0000, Reed, Kevin wrote: >> Hello, >> >> I have been unable to access wiki.python.org for two days. Is there a problem with the server, or is it me? >> >> Thank you much, >> >> Kevin C. Reed >> New Python User > > Well, I just tried it twice and could not get there, so I would say it > is a problem on the server's end. > > Ken > > The server was compromised with a zero-day remote code exploit. It was taken offline to prevent further damage. http://mail.python.org/pipermail/python-list/2013-January/638182.html From carleton at vanoc.net Wed Jan 9 11:26:07 2013 From: carleton at vanoc.net (Ben Carleton) Date: Wed, 9 Jan 2013 11:26:07 -0500 (EST) Subject: wiki.python.org In-Reply-To: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> References: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> Message-ID: <472855929.1910.1357748767761.JavaMail.root@vanoc.net> ----- Original Message ----- > From: "Kevin Reed" > To: python-list at python.org > Sent: Wednesday, January 9, 2013 11:05:31 AM > Subject: wiki.python.org > Hello, > I have been unable to access wiki.python.org for two days. Is there a problem > with the server, or is it me? > Thank you much, > Kevin C. Reed > New Python User > -- > http://mail.python.org/mailman/listinfo/python-list Hi Kevin, There was a security issue with the Wiki and it was taken offline while they get it resolved. Take a look at this post on the list from earlier this month for more info: http://mail.python.org/pipermail/python-list/2013-January/638182.html -- Ben From driscoll at cs.wisc.edu Wed Jan 9 11:59:45 2013 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 09 Jan 2013 10:59:45 -0600 Subject: wiki.python.org In-Reply-To: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> References: <288052B326762C4F81AE8D527D183288111FD0@G6W2480.americas.hpqcorp.net> Message-ID: <50EDA201.1060900@cs.wisc.edu> On 01/09/2013 10:05 AM, Reed, Kevin wrote: > I have been unable to access wiki.python.org for two days. Is there a > problem with the server, or is it me? I can't speak to why, but it appears down for me as well. I also checked http://www.downforeveryoneorjustme.com/ (which is just about the best domain name ever) and it says it's down too. Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 554 bytes Desc: OpenPGP digital signature URL: From ulrich.eckhardt at dominolaser.com Wed Jan 9 11:06:05 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 09 Jan 2013 17:06:05 +0100 Subject: new to python and programming at large In-Reply-To: References: Message-ID: Am 09.01.2013 22:05, schrieb kwakukwatiah at gmail.com: > pls I want to write a function that can compute for the sqrt root of > any number.bt it not working pls help. Whenever describing an error, be precise. In this particular case, we have some sourcecode (which is good!) but what is still missing is what exactly you see when running that code (output and error messages) and what you expected instead. > from math import sqrt > def squareroot(self): > x = sqrt(y) > print x In this very case, I also wonder if the tutorial you are learning from assumes Python 2 while you are using Python 3. This is important, because "print" is a special statement in Python 2 but a normal function in Python 3. That said, I see two errors here: 1. "self": This is customary used when you have a class function that takes an instance of that class. This instance is then the first parameter and called "self". Python doesn't enforce this, but you should adhere to this convention to avoid confusion. Since you are not writing a class, don't name this parameter "self". 2. There is no "y" in that code. I guess that if you renamed your "self" to "y", you would get what you wanted. Good luck and welcome to Python! Uli From kwakukwatiah at gmail.com Wed Jan 9 17:28:04 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Wed, 9 Jan 2013 16:28:04 -0600 Subject: new to python and programming at large. Message-ID: thanks for ur help I wz able to do it.but I wish to expand it by asking a user to input a number for the sqrt to be calculated it I dd it this way but its not working. from math import sqrt number = raw_input('enter a number:') def number(y): return number(Y) thnx -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Wed Jan 9 13:00:54 2013 From: d at davea.name (Dave Angel) Date: Wed, 09 Jan 2013 13:00:54 -0500 Subject: new to python and programming at large. In-Reply-To: References: Message-ID: <50EDB056.9060500@davea.name> On 01/09/2013 05:28 PM, kwakukwatiah at gmail.com wrote: > thanks for ur help I wz able to do it.but I wish to expand it by asking a user to input a number for the sqrt to be calculated it I dd it this way but its not working. > > > from math import sqrt > number = raw_input('enter a number:') > def number(y): > return number(Y) > > > > Please don't keep posting new messages on the same topic. When adding to a thread, use Reply (and make sure python-list is in the to: or cc: field). This program has a pile of problems with it. You've used the name 'number' for three different purposes. Let me explain what those lines do. number = raw_input(... Capture a string from the user. Type is str. def number(y): toss out the string the user entered, and bind that name instead to a function definition that takes a parameter y. return number(Y) Attempt to call your own function recursively, but first crash since Y is undefined. Y is not the same as y. Fortunately, you never actually call the function, by any name. You never used the string you got from the user, but if you had fixed everything else, you'd have discovered that sqrt() expects either an int or a float. Suggestions: put your imports first then put your function definitions and classes only then put your initialization and calls to those functions and classes. Make sure you don't use the same name for two different purposes. It can frequently be okay, but it's certainly confusing for a beginner. Watch the case of any names you use. It matters. You don't have a spec, but perhaps this is close to what you want (untested): from math import sqrt def squareroot(y): return sqrt(y) number = float(raw_input('enter a number:')) print squareroot(number) -- DaveA From kwakukwatiah at gmail.com Wed Jan 9 21:45:03 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Wed, 9 Jan 2013 20:45:03 -0600 Subject: new to python and programming at large. In-Reply-To: <50EDB056.9060500@davea.name> References: <50EDB056.9060500@davea.name> Message-ID: <0C4AD4985823451295267B7505585C09@favour> -----Original Message----- From: Dave Angel Sent: Wednesday, January 09, 2013 12:00 PM To: python-list at python.org Subject: Re: new to python and programming at large. On 01/09/2013 05:28 PM, kwakukwatiah at gmail.com wrote: > thanks for ur help I wz able to do it.but I wish to expand it by asking a > user to input a number for the sqrt to be calculated it I dd it this way > but its not working. > > > from math import sqrt > number = raw_input('enter a number:') > def number(y): > return number(Y) > > > > Please don't keep posting new messages on the same topic. When adding to a thread, use Reply (and make sure python-list is in the to: or cc: field). This program has a pile of problems with it. You've used the name 'number' for three different purposes. Let me explain what those lines do. number = raw_input(... Capture a string from the user. Type is str. def number(y): toss out the string the user entered, and bind that name instead to a function definition that takes a parameter y. return number(Y) Attempt to call your own function recursively, but first crash since Y is undefined. Y is not the same as y. Fortunately, you never actually call the function, by any name. You never used the string you got from the user, but if you had fixed everything else, you'd have discovered that sqrt() expects either an int or a float. Suggestions: put your imports first then put your function definitions and classes only then put your initialization and calls to those functions and classes. Make sure you don't use the same name for two different purposes. It can frequently be okay, but it's certainly confusing for a beginner. Watch the case of any names you use. It matters. You don't have a spec, but perhaps this is close to what you want (untested): from math import sqrt def squareroot(y): return sqrt(y) number = float(raw_input('enter a number:')) print squareroot(number) -- DaveA thanks so much it worked.I have tried and tried.look at what I was doing. me = raw_input("Enter a value:") from math import sqrt def squareroot(y): me = squareroot(y) return squareroot(y) thanks I am very greatful. From torriem at gmail.com Wed Jan 9 22:01:09 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 09 Jan 2013 20:01:09 -0700 Subject: new to python and programming at large. In-Reply-To: <0C4AD4985823451295267B7505585C09@favour> References: <50EDB056.9060500@davea.name> <0C4AD4985823451295267B7505585C09@favour> Message-ID: <50EE2EF5.3020309@gmail.com> On 01/09/2013 07:45 PM, kwakukwatiah at gmail.com wrote: > thanks so much it worked.I have tried and tried.look at what I was doing. > me = raw_input("Enter a value:") > from math import sqrt > def squareroot(y): > > me = squareroot(y) > return squareroot(y) Congratulations! You've just created a recursive function! If you call your function, squareroot() with any value at all, the program will go into an infinite loop and never output or return anything. While recursive functions are useful, in your case I don't think that's what you were aiming for. What you need to do is drop the "me =" line, which does nothing here except put it in a loop, and modify the "return" line to return something useful (such as a calculation, perhaps created by calling the appropriate function in the python math library) instead of trying to return the result of calling your own function, which will put it into a loop. Step through the code in your head. Consider what happens when someone calls your squareroot function, with, say 5 as the input. The first line of the function runs, and then tries to run your function again with 5 as the input, which then tries to run your function again with 5 as the input which then tries to run your function again with 5 as the input, etc. Recursion is very abstract at first, but i hope you understand why this is happening. For more information on how to define functions in general, see http://docs.python.org/release/2.7/tutorial/controlflow.html#defining-functions From kevin.reed2 at hp.com Wed Jan 9 12:11:23 2013 From: kevin.reed2 at hp.com (Reed, Kevin) Date: Wed, 9 Jan 2013 17:11:23 +0000 Subject: Previous Question Answered - Thank You All For Your Replies Message-ID: <288052B326762C4F81AE8D527D18328811205D@G6W2480.americas.hpqcorp.net> Hello, My question concerning wiki.python.org unavailability has been answered. Thank you all for your assistance! You guys are awesome! For those of you who don't know, here's the info. http://mail.python.org/pipermail/python-list/2013-January/638182.html Thanks again, Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Wed Jan 9 12:38:59 2013 From: d at davea.name (Dave Angel) Date: Wed, 09 Jan 2013 12:38:59 -0500 Subject: Previous Question Answered - Thank You All For Your Replies In-Reply-To: <288052B326762C4F81AE8D527D18328811205D@G6W2480.americas.hpqcorp.net> References: <288052B326762C4F81AE8D527D18328811205D@G6W2480.americas.hpqcorp.net> Message-ID: <50EDAB33.3040705@davea.name> On 01/09/2013 12:11 PM, Reed, Kevin wrote: > Hello, > > My question concerning wiki.python.org unavailability has been answered. Thank you all for your assistance! You guys are awesome! > > For those of you who don't know, here's the info. > > http://mail.python.org/pipermail/python-list/2013-January/638182.html > > Thanks again, > > Kevin > > > Please don't start a new thread, nor change the subject line, when you're posting a followup on an existing thread. It's like responding to a letter by putting a note in a bottle and tossing it into the sea. Just use reply to an existing message in the thread, and make sure python-list at python.org is in the To or CC field. -- DaveA From gordon at panix.com Wed Jan 9 12:43:54 2013 From: gordon at panix.com (John Gordon) Date: Wed, 9 Jan 2013 17:43:54 +0000 (UTC) Subject: new to python and programming at large. References: Message-ID: In kwakukwatiah at gmail.com writes: > thanks for ur help I wz able to do it.but I wish to expand it by asking > a user to input a number for the sqrt to be calculated it I dd it this > way but its not working. > from math import sqrt > number = raw_input('enter a number:') > def number(y): > return number(Y) You're storing the user input in a variable called 'number', but then you define a method also called 'number'. Call them something different. Within your method, you probably want to return sqrt(y) instead of calling the method from itself. The argument to your method is called 'y' in the definition, but you refer to it as 'Y' in the return statement. Variable names are case-sensitive. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rodrick.brown at gmail.com Wed Jan 9 15:13:30 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 9 Jan 2013 15:13:30 -0500 Subject: Class confusion Message-ID: How can I make a class that has methods with attributes and other functions? I see a lot of code I'm reading the documentation to Redhat's Satellite software which has a XMLRPC interface and wrote the following code to test the api. I would like to extend this code to support methods with methods? I see this done a lot in python code but I'm not sure how to accomplish something like this? i.e. sc = SatelliteConnect() sc.get_systemlist().get_systemid() ? or sc.get_systemlist().get_running_kernel() How does one chain methods and attributes like this with classes? import xmlrpclib import os import sys class SatelliteConnect(object): SATELLITE_URL = "http://nebula.nydc.fxcorp.prv/rpc/api" SATELLITE_LOGIN = os.environ['USER'] SATELLITE_PASS = os.environ.get('SATELLITE_PASS',None) def __init__(self): self.client = xmlrpclib.Server(self.SATELLITE_URL, verbose=0) self._check_env('SATELLITE_PASS') self.key = self.client.auth.login(self.SATELLITE_LOGIN, self.SATELLITE_PASS) def _check_env(self, env_var): if not os.environ.get('SATELLITE_PASS'): print("{} error please set environment varible {} and re-run script".format(sys.argv[0], env_var)) sys.exit(-1) def get_runningkernel(self, sysid): self.get_systemid('somehost') kernel = self.client.system.getRunningKernel(self.key, sysid) if kernel: return kernel else: return None def get_systemlist(self): systemlist = self.client.system.listSystems(self.key) return([ system.get('name') for system in systemlist ]) self.client.auth.logout(self.key) def get_systemid(self, host): systemlist = self.client.system.getId(self.key, host) for system in systemlist: return system.get('id') -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Jan 9 16:28:35 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 Jan 2013 21:28:35 +0000 Subject: Class confusion In-Reply-To: References: Message-ID: <50EDE103.6080609@mrabarnett.plus.com> On 2013-01-09 20:13, Rodrick Brown wrote: > How can I make a class that has methods with attributes and other > functions? > I see a lot of code > > > I'm reading the documentation to Redhat's Satellite software which has a > XMLRPC interface and wrote the following code to test the api. > > I would like to extend this code to support methods with methods? I see > this done a lot in python code but I'm not sure how to accomplish > something like this? > > i.e. > > sc = SatelliteConnect() > sc.get_systemlist().get_systemid() ? > or > sc.get_systemlist().get_running_kernel() > > How does one chain methods and attributes like this with classes? > [snip] This: sc.get_systemlist().get_systemid() simply means that the method "get_systemlist" returns an instance of some class (let's call it "SystemList") which has a method "get_systemid". From matt.walker.jones at gmail.com Wed Jan 9 16:34:44 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Wed, 9 Jan 2013 15:34:44 -0600 Subject: Class confusion In-Reply-To: <50EDE103.6080609@mrabarnett.plus.com> References: <50EDE103.6080609@mrabarnett.plus.com> Message-ID: # Something like... class SystemList(object): def get_systemid(self): return "System Id: bleh" def get_running_kernel(self): return "Kernel: bleh" class SatelliteConnect(object): def get_systemlist(self): return SystemList() # Now the code you wrote would work, only return those literals thought, you'd want to do something meaningful inside of SystemList's methods. *Matt Jones* On Wed, Jan 9, 2013 at 3:28 PM, MRAB wrote: > On 2013-01-09 20:13, Rodrick Brown wrote: > >> How can I make a class that has methods with attributes and other >> functions? >> I see a lot of code >> >> >> I'm reading the documentation to Redhat's Satellite software which has a >> XMLRPC interface and wrote the following code to test the api. >> >> I would like to extend this code to support methods with methods? I see >> this done a lot in python code but I'm not sure how to accomplish >> something like this? >> >> i.e. >> >> sc = SatelliteConnect() >> sc.get_systemlist().get_**systemid() ? >> or >> sc.get_systemlist().get_**running_kernel() >> >> How does one chain methods and attributes like this with classes? >> >> [snip] > This: > > sc.get_systemlist().get_**systemid() > > simply means that the method "get_systemlist" returns an instance of > some class (let's call it "SystemList") which has a method > "get_systemid". > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrick.brown at gmail.com Wed Jan 9 17:18:40 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 9 Jan 2013 17:18:40 -0500 Subject: Class confusion In-Reply-To: References: <50EDE103.6080609@mrabarnett.plus.com> Message-ID: On Wed, Jan 9, 2013 at 4:34 PM, Matt Jones wrote: > # Something like... > > class SystemList(object): > def get_systemid(self): > return "System Id: bleh" > > def get_running_kernel(self): > return "Kernel: bleh" > > > class SatelliteConnect(object): > def get_systemlist(self): > return SystemList() > > > # Now the code you wrote would work, only return those literals thought, > you'd want to do something meaningful inside of SystemList's methods. > > Thanks for the tip Matt, I had no idea it was so simple. :-) > *Matt Jones* > > > On Wed, Jan 9, 2013 at 3:28 PM, MRAB wrote: > >> On 2013-01-09 20:13, Rodrick Brown wrote: >> >>> How can I make a class that has methods with attributes and other >>> functions? >>> I see a lot of code >>> >>> >>> I'm reading the documentation to Redhat's Satellite software which has a >>> XMLRPC interface and wrote the following code to test the api. >>> >>> I would like to extend this code to support methods with methods? I see >>> this done a lot in python code but I'm not sure how to accomplish >>> something like this? >>> >>> i.e. >>> >>> sc = SatelliteConnect() >>> sc.get_systemlist().get_**systemid() ? >>> or >>> sc.get_systemlist().get_**running_kernel() >>> >>> How does one chain methods and attributes like this with classes? >>> >>> [snip] >> This: >> >> sc.get_systemlist().get_**systemid() >> >> simply means that the method "get_systemlist" returns an instance of >> some class (let's call it "SystemList") which has a method >> "get_systemid". >> >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrick.brown at gmail.com Wed Jan 9 19:43:01 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 9 Jan 2013 19:43:01 -0500 Subject: Class confusion In-Reply-To: References: <50EDE103.6080609@mrabarnett.plus.com> Message-ID: Can anyone care to advise on the following? Based on the responses does this look sufficient? #!/opt/local/bin/python class SystemList(object): sysmap = { '1039' : 'nebula', '1040' : 'mercury'} def __init__(self, sysid): self.sysid = sysid def get_sysname(self): return self.sysmap[self.sysid] class System(object): def __init__(self): pass def get_hostname(self,sysid): return SystemList(sysid) if __name__ == '__main__': sc = System() for sysid in ('1039','1040'): print(sc.get_hostname(sysid).get_sysname()) On Wed, Jan 9, 2013 at 5:18 PM, Rodrick Brown wrote: > On Wed, Jan 9, 2013 at 4:34 PM, Matt Jones wrote: > >> # Something like... >> >> class SystemList(object): >> def get_systemid(self): >> return "System Id: bleh" >> >> def get_running_kernel(self): >> return "Kernel: bleh" >> >> >> class SatelliteConnect(object): >> def get_systemlist(self): >> return SystemList() >> >> >> # Now the code you wrote would work, only return those literals thought, >> you'd want to do something meaningful inside of SystemList's methods. >> >> > Thanks for the tip Matt, I had no idea it was so simple. :-) > > >> *Matt Jones* >> >> >> On Wed, Jan 9, 2013 at 3:28 PM, MRAB wrote: >> >>> On 2013-01-09 20:13, Rodrick Brown wrote: >>> >>>> How can I make a class that has methods with attributes and other >>>> functions? >>>> I see a lot of code >>>> >>>> >>>> I'm reading the documentation to Redhat's Satellite software which has a >>>> XMLRPC interface and wrote the following code to test the api. >>>> >>>> I would like to extend this code to support methods with methods? I see >>>> this done a lot in python code but I'm not sure how to accomplish >>>> something like this? >>>> >>>> i.e. >>>> >>>> sc = SatelliteConnect() >>>> sc.get_systemlist().get_**systemid() ? >>>> or >>>> sc.get_systemlist().get_**running_kernel() >>>> >>>> How does one chain methods and attributes like this with classes? >>>> >>>> [snip] >>> This: >>> >>> sc.get_systemlist().get_**systemid() >>> >>> simply means that the method "get_systemlist" returns an instance of >>> some class (let's call it "SystemList") which has a method >>> "get_systemid". >>> >>> -- >>> http://mail.python.org/**mailman/listinfo/python-list >>> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.walker.jones at gmail.com Wed Jan 9 22:19:27 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Wed, 9 Jan 2013 21:19:27 -0600 Subject: Class confusion In-Reply-To: References: <50EDE103.6080609@mrabarnett.plus.com> Message-ID: Does this look sufficient for what? You haven't actually told us what it is you're trying to accomplish. I gave you the "how", you must supply the "why". *Matt Jones* On Wed, Jan 9, 2013 at 6:43 PM, Rodrick Brown wrote: > Can anyone care to advise on the following? Based on the responses does > this look sufficient? > > #!/opt/local/bin/python > > class SystemList(object): > sysmap = { '1039' : 'nebula', > '1040' : 'mercury'} > > def __init__(self, sysid): > self.sysid = sysid > > def get_sysname(self): > return self.sysmap[self.sysid] > > class System(object): > def __init__(self): > pass > > def get_hostname(self,sysid): > return SystemList(sysid) > > if __name__ == '__main__': > sc = System() > > for sysid in ('1039','1040'): > print(sc.get_hostname(sysid).get_sysname()) > > > > On Wed, Jan 9, 2013 at 5:18 PM, Rodrick Brown wrote: > >> On Wed, Jan 9, 2013 at 4:34 PM, Matt Jones wrote: >> >>> # Something like... >>> >>> class SystemList(object): >>> def get_systemid(self): >>> return "System Id: bleh" >>> >>> def get_running_kernel(self): >>> return "Kernel: bleh" >>> >>> >>> class SatelliteConnect(object): >>> def get_systemlist(self): >>> return SystemList() >>> >>> >>> # Now the code you wrote would work, only return those literals thought, >>> you'd want to do something meaningful inside of SystemList's methods. >>> >>> >> Thanks for the tip Matt, I had no idea it was so simple. :-) >> >> >>> *Matt Jones* >>> >>> >>> On Wed, Jan 9, 2013 at 3:28 PM, MRAB wrote: >>> >>>> On 2013-01-09 20:13, Rodrick Brown wrote: >>>> >>>>> How can I make a class that has methods with attributes and other >>>>> functions? >>>>> I see a lot of code >>>>> >>>>> >>>>> I'm reading the documentation to Redhat's Satellite software which has >>>>> a >>>>> XMLRPC interface and wrote the following code to test the api. >>>>> >>>>> I would like to extend this code to support methods with methods? I see >>>>> this done a lot in python code but I'm not sure how to accomplish >>>>> something like this? >>>>> >>>>> i.e. >>>>> >>>>> sc = SatelliteConnect() >>>>> sc.get_systemlist().get_**systemid() ? >>>>> or >>>>> sc.get_systemlist().get_**running_kernel() >>>>> >>>>> How does one chain methods and attributes like this with classes? >>>>> >>>>> [snip] >>>> This: >>>> >>>> sc.get_systemlist().get_**systemid() >>>> >>>> simply means that the method "get_systemlist" returns an instance of >>>> some class (let's call it "SystemList") which has a method >>>> "get_systemid". >>>> >>>> -- >>>> http://mail.python.org/**mailman/listinfo/python-list >>>> >>> >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at bbarker.co.uk Wed Jan 9 15:10:43 2013 From: ben at bbarker.co.uk (ben at bbarker.co.uk) Date: Wed, 9 Jan 2013 12:10:43 -0800 (PST) Subject: paralell ftp uploads and pool size Message-ID: <5208c9ab-d3b0-4651-8e97-a2923e78b21b@googlegroups.com> Hello, I have a python script that uploads multiple files from the local machine to a remote server in parallel via ftp using p process pool: p = Pool(processes=x) Now as I increase the value of x, the overall upload time for all files drops as expected. If I set x too high however, then an exception is thrown. The exact value at which this happens varies, but is ~20 Traceback (most recent call last): File "uploadFTP.py", line 59, in FTP_Upload().multiupload() File "uploadFTP.py", line 56, in multiupload p.map(upload_function,files) File "/usr/lib64/python2.6/multiprocessing/pool.py", line 148, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib64/python2.6/multiprocessing/pool.py", line 422, in get raise self._value EOFError Now this is not a problem - 20 is more than enough - but I'm trying to understand the mechanisms involved, and why the exact number of processes at which this exception occurs seems to vary. I guess it comes down to the current resources of the server itself...but any insight would be much appreciated! From roy at panix.com Wed Jan 9 17:54:58 2013 From: roy at panix.com (Roy Smith) Date: 9 Jan 2013 17:54:58 -0500 Subject: Why BOM in logging message? Message-ID: We've got 10 (supposedly) identical servers, all running Ubuntu 12.04, Python 2.7, Django 1.3. We log to syslog using the logging module and a custom fomatter. 'formatters': { 'verbose': { 'format': '%(asctime)s [%(process)d]: %(program)s %(session_id)s %(request_id)s %(request_id_digest)s %(remote_addr)s %(name)s %(level\ name)s %(funcName)s() %(message)s', '()': 'songza.logging.ContextFormatter', }, }, There's nothing particularly exciting in the formatter code: class ContextFormatter(logging.Formatter): def format(self, record): record.program = context.get_program() record.request_id = context.get_request_id() record.request_id_digest = context.get_request_id_digest() record.session_id = context.get_session_id() or '-' record.remote_addr = context.get_remote_addr() or '-' return logging.Formatter.format(self, record) What's weird is that two of the servers, and only those two, stick a BOM (Byte Order Mark) in front of the message they log. It shows up in syslog as: 2013-01-09T00:00:00+00:00 web5.songza.com 2013-01-0900:00:00,754 [18979]: [etc...] The other machines, never put the BOM in. Given that all 10 machines are ostensibly clones of each other, we're scratching our heads what might be different about those two which cause the BOMs to appear. Any ideas? I suppose it's possible it's a syslog config problem and not a Python problem, but I figured I'd start at the beginning of the chain. From rosuav at gmail.com Wed Jan 9 18:07:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Jan 2013 10:07:18 +1100 Subject: Why BOM in logging message? In-Reply-To: References: Message-ID: On Thu, Jan 10, 2013 at 9:54 AM, Roy Smith wrote: > What's weird is that two of the servers, and only those two, stick a > BOM (Byte Order Mark) in front of the message they log. Could it be this issue you're looking at? http://bugs.python.org/issue14452 What are the exact Python versions in use? Are the two different servers running an older revision of Py 2.7? ChrisA From gordon at panix.com Wed Jan 9 18:19:14 2013 From: gordon at panix.com (John Gordon) Date: Wed, 9 Jan 2013 23:19:14 +0000 (UTC) Subject: Why BOM in logging message? References: Message-ID: In roy at panix.com (Roy Smith) writes: > What's weird is that two of the servers, and only those two, stick a > BOM (Byte Order Mark) in front of the message they log. It shows up > in syslog as: > 2013-01-09T00:00:00+00:00 web5.songza.com 2013-01-0900:00:00,754 [18979]: [etc...] I worked on an application that would insert a BOM in syslog messages if the logged message contained unicode, but not if it was plain ascii. Not sure if this relates to your issue, but it's similar enough that it seemed worth mentioning. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From roy at panix.com Wed Jan 9 20:17:02 2013 From: roy at panix.com (Roy Smith) Date: Wed, 09 Jan 2013 20:17:02 -0500 Subject: Why BOM in logging message? References: Message-ID: In article , John Gordon wrote: > In roy at panix.com (Roy Smith) writes: > > > What's weird is that two of the servers, and only those two, stick a > > BOM (Byte Order Mark) in front of the message they log. It shows up > > in syslog as: > > > 2013-01-09T00:00:00+00:00 web5.songza.com 2013-01-0900:00:00,754 > > [18979]: [etc...] > > I worked on an application that would insert a BOM in syslog messages if > the logged message contained unicode, but not if it was plain ascii. > > Not sure if this relates to your issue, but it's similar enough that it > seemed worth mentioning. That doesn't seem to be it. All messages from web{2,5} have BOMs, no message from web{1,3,4,6,7,8,9,10} ever does. I even tried looking at the output of socket.gethostname() on the various machines to see if maybe the hostname had some unicode character in it. No joy. From roy at panix.com Wed Jan 9 20:17:43 2013 From: roy at panix.com (Roy Smith) Date: Wed, 09 Jan 2013 20:17:43 -0500 Subject: Why BOM in logging message? References: Message-ID: In article , Chris Angelico wrote: > On Thu, Jan 10, 2013 at 9:54 AM, Roy Smith wrote: > > What's weird is that two of the servers, and only those two, stick a > > BOM (Byte Order Mark) in front of the message they log. > > Could it be this issue you're looking at? > > http://bugs.python.org/issue14452 > > What are the exact Python versions in use? Are the two different > servers running an older revision of Py 2.7? > > ChrisA It sounds like it might be it, but we're running 2.7.3 on all machines. From roy at panix.com Thu Jan 10 11:06:40 2013 From: roy at panix.com (Roy Smith) Date: 10 Jan 2013 11:06:40 -0500 Subject: Why BOM in logging message? References: Message-ID: In article , Roy Smith wrote: >In article , > Chris Angelico wrote: > >> On Thu, Jan 10, 2013 at 9:54 AM, Roy Smith wrote: >> > What's weird is that two of the servers, and only those two, stick a >> > BOM (Byte Order Mark) in front of the message they log. >> >> Could it be this issue you're looking at? >> >> http://bugs.python.org/issue14452 >> >> What are the exact Python versions in use? Are the two different >> servers running an older revision of Py 2.7? >> >> ChrisA > >It sounds like it might be it, but we're running 2.7.3 on all machines. Well, this is fascinating. It turns out that while all of our machines report that they're running 2.7.3, they have two different versions of /usr/lib/python2.7/logging/handlers.py! -rw-r--r-- 1 root root 45076 Aug 1 05:39 /usr/lib/python2.7/logging/handlers.py -rw-r--r-- 1 root root 45143 Apr 20 2012 /usr/lib/python2.7/logging/handlers.py The April 24th version has the BOM code in SysLogHander.emit(): | # Message is a string. Convert to bytes as required by RFC 5424 | if type(msg) is unicode: | msg = msg.encode('utf-8') | if codecs: | msg = codecs.BOM_UTF8 + msg | msg = prio + msg and the August 1st version doesn't: | # Message is a string. Convert to bytes as required by RFC 5424 | if type(msg) is unicode: | msg = msg.encode('utf-8') | msg = prio + msg Is it possible there's two different 2.7.3 builds that somehow got packaged by Ubuntu at different times? The pattern of which machines have the August code and which have the April code correlates with when we rolled out each server instance. From rosuav at gmail.com Thu Jan 10 11:16:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Jan 2013 03:16:09 +1100 Subject: Why BOM in logging message? In-Reply-To: References: Message-ID: On Fri, Jan 11, 2013 at 3:06 AM, Roy Smith wrote: > Well, this is fascinating. It turns out that while all of our > machines report that they're running 2.7.3, they have two different > versions of /usr/lib/python2.7/logging/handlers.py! > > -rw-r--r-- 1 root root 45076 Aug 1 05:39 /usr/lib/python2.7/logging/handlers.py > -rw-r--r-- 1 root root 45143 Apr 20 2012 /usr/lib/python2.7/logging/handlers.py Ha, that would do it! I don't have a corresponding system to compare against, but what package is that file managed by? $ dpkg -S /usr/lib/python2.7/logging/handlers.py See if both systems show it as part of the same package, and if so, if the package is at the same version on each. On my Maverick desktop, I have 2.6, and the package is python2.6-minimal. ChrisA From roy at panix.com Thu Jan 10 11:40:40 2013 From: roy at panix.com (Roy Smith) Date: 10 Jan 2013 11:40:40 -0500 Subject: Why BOM in logging message? References: Message-ID: >On Fri, Jan 11, 2013 at 3:06 AM, Roy Smith wrote: >> -rw-r--r-- 1 root root 45076 Aug 1 05:39 /usr/lib/python2.7/logging/handlers.py >> -rw-r--r-- 1 root root 45143 Apr 20 2012 /usr/lib/python2.7/logging/handlers.py Chris Angelico wrote: >$ dpkg -S /usr/lib/python2.7/logging/handlers.py Yup, on some machines we've got 2.7.3-0ubuntu3, and on others, 2.7.3-0ubuntu3.1 of python2.7-minimal. Details at: https://launchpad.net/ubuntu/+source/python2.7/2.7.3-0ubuntu3.1 Well, I guess today is dist-upgrade day :-) From rosuav at gmail.com Thu Jan 10 11:52:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Jan 2013 03:52:17 +1100 Subject: Why BOM in logging message? In-Reply-To: References: Message-ID: On Fri, Jan 11, 2013 at 3:40 AM, Roy Smith wrote: >>On Fri, Jan 11, 2013 at 3:06 AM, Roy Smith wrote: >>> -rw-r--r-- 1 root root 45076 Aug 1 05:39 /usr/lib/python2.7/logging/handlers.py >>> -rw-r--r-- 1 root root 45143 Apr 20 2012 /usr/lib/python2.7/logging/handlers.py > > Chris Angelico wrote: >>$ dpkg -S /usr/lib/python2.7/logging/handlers.py > > Yup, on some machines we've got 2.7.3-0ubuntu3, and on others, > 2.7.3-0ubuntu3.1 of python2.7-minimal. Details at: > > https://launchpad.net/ubuntu/+source/python2.7/2.7.3-0ubuntu3.1 I love it when everything adds up! The message even cites the specific change. It's like a cryptic crossword - once you get the answer, you KNOW it's the answer because suddenly it all makes sense :) Thanks for bringing a fun problem to solve! It's (unfortunately) a refreshing change to read a post from someone who knows how to ask smart questions. ChrisA From tjreedy at udel.edu Thu Jan 10 18:45:15 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Jan 2013 18:45:15 -0500 Subject: Why BOM in logging message? In-Reply-To: References: Message-ID: On 1/10/2013 11:06 AM, Roy Smith wrote: > Well, this is fascinating. It turns out that while all of our > machines report that they're running 2.7.3, they have two different > versions of /usr/lib/python2.7/logging/handlers.py! > > -rw-r--r-- 1 root root 45076 Aug 1 05:39 /usr/lib/python2.7/logging/handlers.py > -rw-r--r-- 1 root root 45143 Apr 20 2012 /usr/lib/python2.7/logging/handlers.py > > The April 24th version has the BOM code in SysLogHander.emit(): The 'BOM' you are discussing here is not a true 2 or 4 byte byte-order-mark, but the pseudo-BOM (pseudo because a stream of single bytes has no byte order within the single bytes) that Micro$tupid adds (sometimes) to utf-8 encoded bytes to mark their encoding as utf-8 rather than anything else. In otherwords, it is a non-(anti-)standard U(nicode)E(ncoding)M(ark). It is actually the utf-8 encoding of the 2-byte BOM, and hence not a single mark! It is really confusing when people use 'BOM' to refer to a UEM sequence instead of a BOM. > | # Message is a string. Convert to bytes as required by RFC 5424 > | if type(msg) is unicode: > | msg = msg.encode('utf-8') > | if codecs: > | msg = codecs.BOM_UTF8 + msg > | msg = prio + msg 2.7.3 was released in April. > and the August 1st version doesn't: > > | # Message is a string. Convert to bytes as required by RFC 5424 > | if type(msg) is unicode: > | msg = msg.encode('utf-8') > | msg = prio + msg The issue referenced in an earlier messaged was to remove the UEM where it did not belong. > Is it possible there's two different 2.7.3 builds that somehow got > packaged by Ubuntu at different times? As you discovered, Ubuntu sometimes updates a release with bug patches before we release a new official bugfix release. 2.7.4, with many bugfixes, is still to see the light of day. > The pattern of which machines > have the August code and which have the April code correlates with > when we rolled out each server instance. Great detective work ;-). -- Terry Jan Reedy From jkn_gg at nicorp.f9.co.uk Wed Jan 9 18:45:32 2013 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Wed, 9 Jan 2013 15:45:32 -0800 (PST) Subject: pylint or similar to test version-specific language constructs? Message-ID: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Hi all I have to write python code which must run on an old version of python (v2.4) as well as a newer (v2.7). I am using pylint and would like to check if is possible to check with pylint the use of operators etc. which are not present in 2.4; the ternary operator springs to mind. I haven't found anything in pylint which indicates it can do this sort of check; am I missing anything? Other suggestions for this kind of checking welcome. Thanks Jon N From gvanem at broadpark.no Wed Jan 9 19:07:40 2013 From: gvanem at broadpark.no (Gisle Vanem) Date: Thu, 10 Jan 2013 01:07:40 +0100 Subject: pylint or similar to test version-specific language constructs? References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: "jkn" wrote: > I have to write python code which must run on an old version of > python (v2.4) as well as a newer (v2.7). I am using pylint and would > like to check if is possible to check with pylint the use of operators > etc. which are not present in 2.4; the ternary operator springs to > mind. No idea about PyLint. Why not install Python 2.4 and test with that? Sounds safer IMHO. -gv From jkn+gg at nicorp.co.uk Fri Jan 11 03:29:10 2013 From: jkn+gg at nicorp.co.uk (The Night Tripper) Date: Fri, 11 Jan 2013 08:29:10 +0000 Subject: pylint or similar to test version-specific language constructs? References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: Gisle Vanem wrote: > "jkn" wrote: > >> I have to write python code which must run on an old version of >> python (v2.4) as well as a newer (v2.7). I am using pylint and would >> like to check if is possible to check with pylint the use of operators >> etc. which are not present in 2.4; the ternary operator springs to >> mind. > > No idea about PyLint. Why not install Python 2.4 and test > with that? Sounds safer IMHO. I do have Python 2.4 installed; but I would like a checker that warned me beforehand about trying to use constructs (like the ternary operator, decorators) which are version-specific. J^n From tjreedy at udel.edu Fri Jan 11 08:38:17 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 Jan 2013 08:38:17 -0500 Subject: pylint or similar to test version-specific language constructs? In-Reply-To: References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: On 1/11/2013 3:29 AM, The Night Tripper wrote: > Gisle Vanem wrote: > >> "jkn" wrote: >> >>> I have to write python code which must run on an old version of >>> python (v2.4) as well as a newer (v2.7). I am using pylint and would >>> like to check if is possible to check with pylint the use of operators >>> etc. which are not present in 2.4; the ternary operator springs to >>> mind. >> >> No idea about PyLint. Why not install Python 2.4 and test >> with that? Sounds safer IMHO. > > I do have Python 2.4 installed; but I would like a checker that warned me > beforehand about trying to use constructs (like the ternary operator, > decorators) which are version-specific. Search each chapter of the reference manual (about 7) for 'version changed'. -- Terry Jan Reedy From d at davea.name Fri Jan 11 10:06:30 2013 From: d at davea.name (Dave Angel) Date: Fri, 11 Jan 2013 10:06:30 -0500 Subject: pylint or similar to test version-specific language constructs? In-Reply-To: References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: <50F02A76.2080205@davea.name> On 01/11/2013 03:29 AM, The Night Tripper wrote: > Gisle Vanem wrote: > >> "jkn" wrote: >> >>> I have to write python code which must run on an old version of >>> python (v2.4) as well as a newer (v2.7). I am using pylint and would >>> like to check if is possible to check with pylint the use of operators >>> etc. which are not present in 2.4; the ternary operator springs to >>> mind. >> No idea about PyLint. Why not install Python 2.4 and test >> with that? Sounds safer IMHO. > I do have Python 2.4 installed; but I would like a checker that warned me > beforehand about trying to use constructs (like the ternary operator, > decorators) which are version-specific. > > J^n > Not sure what you mean by beforehand. Don't you run all your unit tests before putting each revision of your code into production? So run those tests twice, once on 2.7, and once on 2.4. A unit test that's testing code with a ternary operator will fail, without any need for a separate test. if it doesn't, then you've got some coverage gaps in your unit tests. -- DaveA From steve+comp.lang.python at pearwood.info Fri Jan 11 10:37:26 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Jan 2013 15:37:26 GMT Subject: pylint or similar to test version-specific language constructs? References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: <50f031b5$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Jan 2013 10:06:30 -0500, Dave Angel wrote: > On 01/11/2013 03:29 AM, The Night Tripper wrote: >> Gisle Vanem wrote: >> >>> "jkn" wrote: >>> >>>> I have to write python code which must run on an old version of >>>> python (v2.4) as well as a newer (v2.7). I am using pylint and would >>>> like to check if is possible to check with pylint the use of >>>> operators etc. which are not present in 2.4; the ternary operator >>>> springs to mind. >>> No idea about PyLint. Why not install Python 2.4 and test with that? >>> Sounds safer IMHO. >> I do have Python 2.4 installed; but I would like a checker that warned >> me beforehand about trying to use constructs (like the ternary >> operator, decorators) which are version-specific. Decorators work fine in Python 2.4. > Not sure what you mean by beforehand. Don't you run all your unit tests > before putting each revision of your code into production? So run those > tests twice, once on 2.7, and once on 2.4. A unit test that's testing > code with a ternary operator will fail, without any need for a separate > test. You don't even need tests for the code that includes the ternary operator. The module simply won't compile in Python 2.4, you get a SyntaxError when you try to import it or run it. You don't need PyLint to check for *illegal syntax*. Python already does that. -- Steven From d at davea.name Fri Jan 11 11:09:15 2013 From: d at davea.name (Dave Angel) Date: Fri, 11 Jan 2013 11:09:15 -0500 Subject: pylint or similar to test version-specific language constructs? In-Reply-To: <50f031b5$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> <50f031b5$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F0392B.9050001@davea.name> On 01/11/2013 10:37 AM, Steven D'Aprano wrote: > On Fri, 11 Jan 2013 10:06:30 -0500, Dave Angel wrote: > >> > >> Not sure what you mean by beforehand. Don't you run all your unit tests >> before putting each revision of your code into production? So run those >> tests twice, once on 2.7, and once on 2.4. A unit test that's testing >> code with a ternary operator will fail, without any need for a separate >> test. > You don't even need tests for the code that includes the ternary > operator. The module simply won't compile in Python 2.4, you get a > SyntaxError when you try to import it or run it. > > You don't need PyLint to check for *illegal syntax*. Python already does > that. > You're right of course. But I can weasel out of it by saying that Python will only check it if the particular module is imported. I've seen equivalent bugs in real projects, where a release went out with one of its dynamic libraries not even present. Another thing that can stop Python from checking is if some naive programmer uses a bare except in production code. Both of these would show up in the simplest of unit testing code. -- DaveA From jkn_gg at nicorp.f9.co.uk Sun Jan 13 12:56:38 2013 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Sun, 13 Jan 2013 09:56:38 -0800 (PST) Subject: pylint or similar to test version-specific language constructs? References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: Hi Dave On 11 Jan, 15:06, Dave Angel wrote: > > Not sure what you mean by beforehand. ?Don't you run all your unit tests > before putting each revision of your code into production? ?So run those > tests twice, once on 2.7, and once on 2.4. ?A unit test that's testing > code with a ternary operator will fail, without any need for a separate > test. > > if it doesn't, then you've got some coverage gaps in your unit tests. By 'beforehand' I meant 'before testing on my target 2.4 system; perhaps I should have been clearer in that I am running 2.7 on my 'development' platform, and 2.4 on my target. It would be painful to put 2.4 on my target system (although I continue to wonder about that...). So I was looking to catch such errors before migrating to the target. [Steven D'Aprano] > Decorators work fine in Python 2.4. Yes, I was just coming up with another example of a language construct which didn't exist at one point. > You don't even need tests for the code that includes the ternary > operator. The module simply won't compile in Python 2.4, you get a > SyntaxError when you try to import it or run it. In fact I had a misapprehension about this; for some reason (I thought I'd tried it) I thought such an error only got caught at runtime, not 'compile-time'. I now see that this is not the case, which means the athe problem is less of a concern than I thought. Thanks for the comments. Jon N From rosuav at gmail.com Sun Jan 13 15:59:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Jan 2013 07:59:15 +1100 Subject: pylint or similar to test version-specific language constructs? In-Reply-To: References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: On Mon, Jan 14, 2013 at 4:56 AM, jkn wrote: > Hi Dave > > On 11 Jan, 15:06, Dave Angel wrote: >> >> Not sure what you mean by beforehand. Don't you run all your unit tests >> before putting each revision of your code into production? So run those >> tests twice, once on 2.7, and once on 2.4. A unit test that's testing >> code with a ternary operator will fail, without any need for a separate >> test. >> >> if it doesn't, then you've got some coverage gaps in your unit tests. > > By 'beforehand' I meant 'before testing on my target 2.4 system; > perhaps I should have been clearer in that I am running 2.7 on my > 'development' platform, and 2.4 on my target. It would be painful to > put 2.4 on my target system (although I continue to wonder about > that...). So I was looking to catch such errors before migrating to > the target. Painful to put 2.4 on your dev, you mean? I've never done it, but I would expect that the old sources will compile against newer libraries with no problems. That's likely to be the easiest option. It's the language-level equivalent of watching for a thrown exception rather than asking forgiveness beforehand :) ChrisA From thenault at gmail.com Fri Jan 11 03:35:39 2013 From: thenault at gmail.com (thenault at gmail.com) Date: Fri, 11 Jan 2013 00:35:39 -0800 (PST) Subject: pylint or similar to test version-specific language constructs? In-Reply-To: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> References: <1454e34f-5ca0-4f49-ad29-c99df4fdd322@gu9g2000vbb.googlegroups.com> Message-ID: <259c43d5-d740-402f-8e8a-b427336854e5@googlegroups.com> On Thursday, January 10, 2013 12:45:32 AM UTC+1, jkn wrote: > Hi all > > I have to write python code which must run on an old version of > > python (v2.4) as well as a newer (v2.7). I am using pylint and would > > like to check if is possible to check with pylint the use of operators > > etc. which are not present in 2.4; the ternary operator springs to > > mind. > > > > I haven't found anything in pylint which indicates it can do this sort > > of check; am I missing anything? Other suggestions for this kind of > > checking welcome. Hi, there is no such checker in pylint yet, though it should be fairly easy to build one. The longer part being to identify all constructs that should be detected and their representation in the ast. Then pylint checkers are simple visitors. You'll get some help from the project mailing list (python-projects at lists.logilab.org) if you go that way. Regards, -- Sylvain From andydtaylor at gmail.com Wed Jan 9 18:52:12 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Wed, 9 Jan 2013 15:52:12 -0800 (PST) Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database Message-ID: Hi, I'm a bit stuck on this "INSERT INTO" syntax error. I have no idea why it's not working actually... I've tried changing column types to char but that didn't work. I've gone a bit blind looking at it, but hopefully you can set me right. With the '#'d out lines instead the file does work. What am I missing? Thanks Andy #!/usr/bin/python import psycopg2 import sys def main(): db = psycopg2.connect( host = 'localhost', database = 'gisdb', user = 'postgres', password = '######' ) cursor = db.cursor() cursor.execute("DROP TABLE IF EXISTS tubecross") cursor_to.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code char, SAJ interval, SPB interval, SOQ interval);") #cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, num integer, data varchar);") #cursor.execute("INSERT INTO tubecross (num, data) VALUES (%s, %s)",(900, "9abc'def")) cursor_to.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27)) db.commit() if __name__ == "__main__": main() From gordon at panix.com Wed Jan 9 19:08:05 2013 From: gordon at panix.com (John Gordon) Date: Thu, 10 Jan 2013 00:08:05 +0000 (UTC) Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database References: Message-ID: In andydtaylor at gmail.com writes: > I'm a bit stuck on this "INSERT INTO" syntax error. I have no idea why it's What syntax error? It's always helpful if you can post the actual error message. > not working actually... I've tried changing column types to char but that > didn't work. I've gone a bit blind looking at it, but hopefully you can set > me right. With the '#'d out lines instead the file does work. > #!/usr/bin/python > import psycopg2 > import sys > def main(): > db = psycopg2.connect( > host = 'localhost', > database = 'gisdb', > user = 'postgres', > password = '######' > ) > cursor = db.cursor() > cursor.execute("DROP TABLE IF EXISTS tubecross") > cursor_to.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code char, SAJ interval, SPB interval, SOQ interval);") > #cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, num integer, data varchar);") > #cursor.execute("INSERT INTO tubecross (num, data) VALUES (%s, %s)",(900, "9abc'def")) > cursor_to.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27)) > db.commit() > if __name__ == "__main__": > main() You appear to have two very different versions of the tubecross table. One version has three fields (id, num, data) and the other version has at least four (station_code, SAJ, SPB, SOQ). Which one is correct? Also, what is the 'cursor_to' variable? It doesn't appear to be defined anywhere. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From andydtaylor at gmail.com Wed Jan 9 19:19:10 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Wed, 9 Jan 2013 16:19:10 -0800 (PST) Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database In-Reply-To: References: Message-ID: Hi John, He're the code I would like to see work. The cursor_to is an oversight. I extracted this element from some other code in an attempt to isolate/resolve the problem myself, hence having a simplified table version. Which works actually, but unfortunately that's not educating me suffieciently. Actual error message I see follows. - - - - - - - - - - - - - - - - - - - - - - - - - Code: #!/usr/bin/python import psycopg2 import sys def main(): db = psycopg2.connect( host = 'localhost', database = 'gisdb', user = 'postgres', password = '######' ) cursor = db.cursor() cursor.execute("DROP TABLE IF EXISTS tubecross") cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code char, SAJ interval, SPB interval, SOQ interval);") cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27)) db.commit() if __name__ == "__main__": main() - - - - - - - - - - - - - - - - - - - - - - - - - Error Message: andyt at andyt-ThinkPad-X61:~/projects/django-stringer/Other/TFLJPAPI$ python creat_db_exp.py File "creat_db_exp.py", line 15 cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27)) ^ SyntaxError: invalid syntax Thanks for your help From msirenef at lightbird.net Wed Jan 9 20:07:22 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 09 Jan 2013 20:07:22 -0500 Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database In-Reply-To: References: Message-ID: <50EE144A.3070103@lightbird.net> On Wed 09 Jan 2013 07:19:10 PM EST, andydtaylor at gmail.com wrote: > Hi John, > > He're the code I would like to see work. The cursor_to is an oversight. I extracted this element from some other code in an attempt to isolate/resolve the problem myself, hence having a simplified table version. Which works actually, but unfortunately that's not educating me suffieciently. Actual error message I see follows. > > - - - - - - - - - - - - - - - - - - - - - - - - - > Code: > > #!/usr/bin/python > import psycopg2 > import sys > > def main(): > db = psycopg2.connect( > host = 'localhost', > database = 'gisdb', > user = 'postgres', > password = '######' > ) > cursor = db.cursor() > cursor.execute("DROP TABLE IF EXISTS tubecross") > cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code char, SAJ interval, SPB interval, SOQ interval);") > cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27)) > db.commit() > > if __name__ == "__main__": > main() > > - - - - - - - - - - - - - - - - - - - - - - - - - > Error Message: > > andyt at andyt-ThinkPad-X61:~/projects/django-stringer/Other/TFLJPAPI$ python creat_db_exp.py > File "creat_db_exp.py", line 15 > cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27)) > ^ > SyntaxError: invalid syntax > > > Thanks for your help 00:00 etc are not quoted? - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From python at mrabarnett.plus.com Wed Jan 9 20:11:59 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 10 Jan 2013 01:11:59 +0000 Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database In-Reply-To: References: Message-ID: <50EE155F.3030408@mrabarnett.plus.com> On 2013-01-10 00:19, andydtaylor at gmail.com wrote: > Hi John, > > He're the code I would like to see work. The cursor_to is an oversight. I extracted this element from some other code in an attempt to isolate/resolve the problem myself, hence having a simplified table version. Which works actually, but unfortunately that's not educating me suffieciently. Actual error message I see follows. > [snip] > - - - - - - - - - - - - - - - - - - - - - - - - - > Error Message: > > andyt at andyt-ThinkPad-X61:~/projects/django-stringer/Other/TFLJPAPI$ python creat_db_exp.py > File "creat_db_exp.py", line 15 > cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27)) > ^ > SyntaxError: invalid syntax > "00:00", etc, aren't valid Python, they're two ints with a colon between them. You need to determine what Python class to use to represent those. From andydtaylor at gmail.com Wed Jan 9 21:20:10 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Wed, 9 Jan 2013 18:20:10 -0800 (PST) Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database In-Reply-To: References: Message-ID: <717b5860-f35d-4c2f-a227-638568a8aae0@googlegroups.com> Thanks for your help guys. I was actually doing a few things wrong, but I have got this script to work by declaring fields as varchar and all values as strings. But I would like to log journey time values in hours/minutes, so I will have to look into the following: 1. Retrieving this data from postgres as text, converting it and using it. I will need to add/subtract on this time value; or 2. Recognising it as a time class in the first instance by using the string parsing function. Regards, Andy From andydtaylor at gmail.com Wed Jan 9 21:20:10 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Wed, 9 Jan 2013 18:20:10 -0800 (PST) Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database In-Reply-To: References: Message-ID: <717b5860-f35d-4c2f-a227-638568a8aae0@googlegroups.com> Thanks for your help guys. I was actually doing a few things wrong, but I have got this script to work by declaring fields as varchar and all values as strings. But I would like to log journey time values in hours/minutes, so I will have to look into the following: 1. Retrieving this data from postgres as text, converting it and using it. I will need to add/subtract on this time value; or 2. Recognising it as a time class in the first instance by using the string parsing function. Regards, Andy From msirenef at lightbird.net Wed Jan 9 21:56:19 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 09 Jan 2013 21:56:19 -0500 Subject: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database In-Reply-To: <717b5860-f35d-4c2f-a227-638568a8aae0@googlegroups.com> References: <717b5860-f35d-4c2f-a227-638568a8aae0@googlegroups.com> Message-ID: <50EE2DD3.2050707@lightbird.net> On Wed 09 Jan 2013 09:20:10 PM EST, andydtaylor at gmail.com wrote: > Thanks for your help guys. > > I was actually doing a few things wrong, but I have got this script to work by declaring fields as varchar and all values as strings. But I would like to log journey time values in hours/minutes, so I will have to look into the following: > > 1. Retrieving this data from postgres as text, converting it and using it. I will need to add/subtract on this time value; or > 2. Recognising it as a time class in the first instance by using the string parsing function. > > Regards, > > Andy Why not store as an int, in minutes, and then parse into h:m when displaying? - m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From kliateni at gmail.com Thu Jan 10 01:01:24 2013 From: kliateni at gmail.com (Karim) Date: Thu, 10 Jan 2013 07:01:24 +0100 Subject: How to run multiline shell command within python In-Reply-To: References: Message-ID: <50EE5934.7090609@gmail.com> Hello all, I want to run multiline shell command within python without using a command file but directly execute several lines of shell. I already use *subprocess.checkoutput("csh -f my_file.csh".split())* but I want to know if it is posssible to avoid making file and execute shell lines of code directly. Example: cat< myfile echo "foo" echo "bar" ... EOF Regards Karim From hugo.yoshi at gmail.com Thu Jan 10 03:31:43 2013 From: hugo.yoshi at gmail.com (Hugo Arts) Date: Thu, 10 Jan 2013 09:31:43 +0100 Subject: [Tutor] How to run multiline shell command within python In-Reply-To: <50EE5934.7090609@gmail.com> References: <50EE5934.7090609@gmail.com> Message-ID: On Thu, Jan 10, 2013 at 7:01 AM, Karim wrote: > > > Hello all, > > I want to run multiline shell command within python without using a > command file but directly execute several lines of shell. > I already use *subprocess.checkoutput("csh -f my_file.csh".split())* but I > want to know if it is posssible to avoid making file and execute > shell lines of code directly. > > Yes, this is very possible. Specify shell=True as an argument and you can do anything you can do in a shell: >>> commands = """echo hello ... echo hello | wc -l ... ps aux | grep python""" >>> b = subprocess.check_output(commands, shell=True) >>> print(b.decode('ascii')) hello 1 hugo 1255 1.0 0.6 777316 49924 ? Sl 09:14 0:08 /usr/bin/python2 /usr/bi hugo 6529 0.0 0.0 42408 7196 pts/0 S+ 09:23 0:00 python hugo 6559 0.0 0.0 10656 1128 pts/0 S+ 09:28 0:00 grep python >>> watch out though, accepting user input into the commands variable will lead to shell injection, which can be a dangerous security vulnerability. HTH, Hugo -------------- next part -------------- An HTML attachment was scrubbed... URL: From kliateni at gmail.com Thu Jan 10 09:25:57 2013 From: kliateni at gmail.com (Karim) Date: Thu, 10 Jan 2013 15:25:57 +0100 Subject: [Tutor] How to run multiline shell command within python In-Reply-To: References: <50EE5934.7090609@gmail.com> Message-ID: <50EECF75.5020400@gmail.com> On 10/01/2013 09:31, Hugo Arts wrote: > On Thu, Jan 10, 2013 at 7:01 AM, Karim > wrote: > > > > Hello all, > > I want to run multiline shell command within python without using > a command file but directly execute several lines of shell. > I already use *subprocess.checkoutput("csh -f > my_file.csh".split())* but I want to know if it is posssible to > avoid making file and execute > shell lines of code directly. > > > Yes, this is very possible. Specify shell=True as an argument and you > can do anything you can do in a shell: > > >>> commands = """echo hello > ... echo hello | wc -l > ... ps aux | grep python""" > >>> b = subprocess.check_output(commands, shell=True) > >>> print(b.decode('ascii')) > hello > 1 > hugo 1255 1.0 0.6 777316 49924 ? Sl 09:14 0:08 > /usr/bin/python2 /usr/bi > hugo 6529 0.0 0.0 42408 7196 pts/0 S+ 09:23 0:00 python > hugo 6559 0.0 0.0 10656 1128 pts/0 S+ 09:28 0:00 grep python > > >>> > > watch out though, accepting user input into the commands variable will > lead to shell injection, which can be a dangerous security vulnerability. > > HTH, > Hugo Many thanks Hugo. It makes my day! In my case there are no possibilities for shell injection. It is internal to a class. Regards Karim -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Thu Jan 10 10:21:53 2013 From: msarro at gmail.com (Matty Sarro) Date: Thu, 10 Jan 2013 10:21:53 -0500 Subject: [Tutor] How to run multiline shell command within python In-Reply-To: <50EECF75.5020400@gmail.com> References: <50EE5934.7090609@gmail.com> <50EECF75.5020400@gmail.com> Message-ID: Have you looked a the pexpect class? It works like gangbusters, especially if you're trying to run something with an interactive shell. http://www.noah.org/wiki/pexpect On Thu, Jan 10, 2013 at 9:25 AM, Karim wrote: > On 10/01/2013 09:31, Hugo Arts wrote: > > On Thu, Jan 10, 2013 at 7:01 AM, Karim wrote: > >> >> >> Hello all, >> >> I want to run multiline shell command within python without using a >> command file but directly execute several lines of shell. >> I already use *subprocess.checkoutput("csh -f my_file.csh".split())* but >> I want to know if it is posssible to avoid making file and execute >> shell lines of code directly. >> >> > Yes, this is very possible. Specify shell=True as an argument and you > can do anything you can do in a shell: > > >>> commands = """echo hello > ... echo hello | wc -l > ... ps aux | grep python""" > >>> b = subprocess.check_output(commands, shell=True) > >>> print(b.decode('ascii')) > hello > 1 > hugo 1255 1.0 0.6 777316 49924 ? Sl 09:14 0:08 > /usr/bin/python2 /usr/bi > hugo 6529 0.0 0.0 42408 7196 pts/0 S+ 09:23 0:00 python > hugo 6559 0.0 0.0 10656 1128 pts/0 S+ 09:28 0:00 grep > python > > >>> > > watch out though, accepting user input into the commands variable will > lead to shell injection, which can be a dangerous security vulnerability. > > HTH, > Hugo > > > Many thanks Hugo. It makes my day! > In my case there are no possibilities for shell injection. It is internal > to a class. > > Regards > Karim > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kliateni at gmail.com Thu Jan 10 14:07:16 2013 From: kliateni at gmail.com (Karim) Date: Thu, 10 Jan 2013 20:07:16 +0100 Subject: [Tutor] How to run multiline shell command within python In-Reply-To: References: <50EE5934.7090609@gmail.com> <50EECF75.5020400@gmail.com> Message-ID: <50EF1164.5020004@gmail.com> On 10/01/2013 16:21, Matty Sarro wrote: > Have you looked a the pexpect class? It works like gangbusters, > especially if you're trying to run something with an interactive shell. > > http://www.noah.org/wiki/pexpect > > > On Thu, Jan 10, 2013 at 9:25 AM, Karim > wrote: > > On 10/01/2013 09:31, Hugo Arts wrote: >> On Thu, Jan 10, 2013 at 7:01 AM, Karim > > wrote: >> >> >> >> Hello all, >> >> I want to run multiline shell command within python without >> using a command file but directly execute several lines of shell. >> I already use *subprocess.checkoutput("csh -f >> my_file.csh".split())* but I want to know if it is posssible >> to avoid making file and execute >> shell lines of code directly. >> >> >> Yes, this is very possible. Specify shell=True as an argument and >> you can do anything you can do in a shell: >> >> >>> commands = """echo hello >> ... echo hello | wc -l >> ... ps aux | grep python""" >> >>> b = subprocess.check_output(commands, shell=True) >> >>> print(b.decode('ascii')) >> hello >> 1 >> hugo 1255 1.0 0.6 777316 49924 ? Sl 09:14 0:08 >> /usr/bin/python2 /usr/bi >> hugo 6529 0.0 0.0 42408 7196 pts/0 S+ 09:23 0:00 >> python >> hugo 6559 0.0 0.0 10656 1128 pts/0 S+ 09:28 0:00 >> grep python >> >> >>> >> >> watch out though, accepting user input into the commands variable >> will lead to shell injection, which can be a dangerous security >> vulnerability. >> >> HTH, >> Hugo > > Many thanks Hugo. It makes my day! > In my case there are no possibilities for shell injection. It is > internal to a class. > > Regards > Karim > > > -- > http://mail.python.org/mailman/listinfo/python-list > > Thanks Matty! I will have a look specially for interactive session. Regards Karim -------------- next part -------------- An HTML attachment was scrubbed... URL: From michaeldcurry1 at gmail.com Wed Jan 9 19:20:40 2013 From: michaeldcurry1 at gmail.com (Michael Curry) Date: Wed, 9 Jan 2013 16:20:40 -0800 (PST) Subject: Getting audio input and processing it? Message-ID: <480ea35c-82b5-4199-a569-c3857061f6be@googlegroups.com> I've been working on a Morse Code translator, I've made it work so that you can input English and it will translate it to Morse and play the Audio. I now want to add a feature to the program that takes audio input, processes it and then outputs the English. Are there any specific APIs that I can use to take input from a microphone, is there any way to detect frequencies or amplitudes, as well as find out for how long the wave lasts? If not, are there any implementations of this? Would there be a way to do it? From d at davea.name Thu Jan 10 00:46:55 2013 From: d at davea.name (Dave Angel) Date: Thu, 10 Jan 2013 00:46:55 -0500 Subject: Getting audio input and processing it? In-Reply-To: <480ea35c-82b5-4199-a569-c3857061f6be@googlegroups.com> References: <480ea35c-82b5-4199-a569-c3857061f6be@googlegroups.com> Message-ID: <50EE55CF.2010904@davea.name> On 01/09/2013 07:20 PM, Michael Curry wrote: > I've been working on a Morse Code translator, I've made it work so that you can input English and it will translate it to Morse and play the Audio. I now want to add a feature to the program that takes audio input, processes it and then outputs the English. > > Are there any specific APIs that I can use to take input from a microphone, is there any way to detect frequencies or amplitudes, as well as find out for how long the wave lasts? If not, are there any implementations of this? Would there be a way to do it? If you find an approach that gets audio information from your hardware, and on your operating system, then you presumably end up with a stream of bytes (or of some other data type, if the sample size is bigger than 8 bits). If this were my project, I'd ignore the detecting of frequency (though it can be done, by various filtering techniques), and just measure energy. Presumably the signal is quiet for space, and noisy for mark. So you set a threshold, and measure how long the signal is below the threshold, and then how long it's above. The time above the threshold is how long the "wave lasts." Presumably you can then set a few length thresholds, and short values are dit and longer ones are dah. So, how do you measure energy on a byte string? The way I've seen audio encoded in 8 bits has 128 as the DC zero reference point. Values above and below that represent a nonzero signal voltage. So you'd do something like: abs( value-128) to get an instantaneous energy. Do a sanity check to make sure the "quiet" signal gives you a very small energy (some noise expected, of course). There are lots of refinements possible. But I suspect someone else is going to pop in and say that libary xyz on pypi will do it all for you automatically. There's probably someone who's done the whole project before. But what's the fun in that? -- DaveA From redstone-cold at 163.com Wed Jan 9 21:11:34 2013 From: redstone-cold at 163.com (iMath) Date: Wed, 9 Jan 2013 18:11:34 -0800 (PST) Subject: How to call wget by python ? Message-ID: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> can you give me an example code ? From rosuav at gmail.com Wed Jan 9 21:36:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Jan 2013 13:36:17 +1100 Subject: How to call wget by python ? In-Reply-To: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> References: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> Message-ID: On Thu, Jan 10, 2013 at 1:11 PM, iMath wrote: > can you give me an example code ? > -- > http://mail.python.org/mailman/listinfo/python-list You've asked several very vague questions. I would strongly recommend that you read this: http://www.catb.org/esr/faqs/smart-questions.html Invoking wget can be done, but you may want to consider alternatives such as doing the network request (HTTP, FTP, or whatever) directly in Python. A one-line request that we do heaps of work for you is not the best way to get results. ChrisA From torriem at gmail.com Wed Jan 9 22:04:31 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 09 Jan 2013 20:04:31 -0700 Subject: How to call wget by python ? In-Reply-To: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> References: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> Message-ID: <50EE2FBF.7010307@gmail.com> On 01/09/2013 07:11 PM, iMath wrote: > can you give me an example code ? No but I can suggest some alternative ideas, such as using httplib (built into python), or libcurl. Or if you have to use wget, you run it the same way you run any external command from python. If it were my I'd plunk a few search terms in google, such as "python run external process." From dihedral88888 at googlemail.com Wed Jan 9 22:21:30 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 9 Jan 2013 19:21:30 -0800 (PST) Subject: How to call wget by python ? In-Reply-To: References: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> Message-ID: <8aa23734-0ef9-4104-aacf-1c1dd817edb0@googlegroups.com> Michael Torrie? 2013?1?10????UTC+8??11?04?31???? > On 01/09/2013 07:11 PM, iMath wrote: > > > can you give me an example code ? > > > > No but I can suggest some alternative ideas, such as using httplib > > (built into python), or libcurl. Or if you have to use wget, you run it > > the same way you run any external command from python. If it were my > > I'd plunk a few search terms in google, such as "python run external > > process." Inherantly the python interpreter has a GC builtin to use pacakages like DLL by reference counting. From dihedral88888 at googlemail.com Wed Jan 9 22:21:30 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 9 Jan 2013 19:21:30 -0800 (PST) Subject: How to call wget by python ? In-Reply-To: References: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> Message-ID: <8aa23734-0ef9-4104-aacf-1c1dd817edb0@googlegroups.com> Michael Torrie? 2013?1?10????UTC+8??11?04?31???? > On 01/09/2013 07:11 PM, iMath wrote: > > > can you give me an example code ? > > > > No but I can suggest some alternative ideas, such as using httplib > > (built into python), or libcurl. Or if you have to use wget, you run it > > the same way you run any external command from python. If it were my > > I'd plunk a few search terms in google, such as "python run external > > process." Inherantly the python interpreter has a GC builtin to use pacakages like DLL by reference counting. From rosuav at gmail.com Wed Jan 9 22:38:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Jan 2013 14:38:15 +1100 Subject: How to call wget by python ? In-Reply-To: <8aa23734-0ef9-4104-aacf-1c1dd817edb0@googlegroups.com> References: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> <8aa23734-0ef9-4104-aacf-1c1dd817edb0@googlegroups.com> Message-ID: On Thu, Jan 10, 2013 at 2:21 PM, 88888 Dihedral wrote: > Inherantly the python interpreter has a GC builtin > to use pacakages like DLL by reference counting. That almost makes sense. And it's almost profound, too. ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 9 22:55:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Jan 2013 03:55:13 GMT Subject: How to call wget by python ? References: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> Message-ID: <50ee3ba1$0$29898$c3e8da3$5496439d@news.astraweb.com> On Wed, 09 Jan 2013 18:11:34 -0800, iMath wrote: > can you give me an example code ? Is the web broken where you are? If you google for "python wget", you will find example of how to call wget as an external process, as well as examples of downloading files from the web like wget would do but using only Python. https://duckduckgo.com/?q=python%20wget Or you could search for "python call external command" and then use wget as that external command. https://duckduckgo.com/?q=python%20call%20external%20command -- Steven From rurpy at yahoo.com Thu Jan 10 00:01:24 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 9 Jan 2013 21:01:24 -0800 (PST) Subject: How to call wget by python ? In-Reply-To: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> References: <49ca3718-159f-40cd-96bf-983ddb96202b@googlegroups.com> Message-ID: On Wednesday, January 9, 2013 7:11:34 PM UTC-7, iMath wrote: > can you give me an example code ? For running any system command from Python, you can use the subprocess module: http://docs.python.org/3/library/subprocess.html#module-subprocess To run "wget -p -k http://python.org" from Python you could do something like this: import subprocess subprocess.call (['wget', '-p', '-k', 'http://python.org']) From niklas.berliner at gmail.com Wed Jan 9 23:08:33 2013 From: niklas.berliner at gmail.com (Niklas Berliner) Date: Wed, 9 Jan 2013 23:08:33 -0500 Subject: subprocess.Popen and multiprocessing fails to execute external program Message-ID: I have a pipline that involves processing some data, handing the data to an external program (t_coffee used for sequence alignments in bioinformatics), and postprocessing the result. Since I have a lot of data, I need to run my pipeline in parallel which I implemented using the multiprocessing module following Doug Hellmanns blog ( http://blog.doughellmann.com/2009/04/pymotw-multiprocessing-part-1.html). My pipeline works perfectly fine when I run it with the multiprocessing implementation and one consumer, i.e. on one core. If I increase the number of consumers, i.e. that multiple instances of my pipeline run in parallel the external program fails with a core dump. To call the external programm I let python write a bash wrapper script that is called by subprocess.Popen(system_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) result, error = childProcess.communicate() rc = childProcess.returncode (I also tried shell=False and calling the program directly specifying the env for the call) To avoid conflict between the external program each program call gets a flushed environment and the important environment variables are set to unique, existing paths. An example looks like this: #!/bin/bash env -i export HOME_4_TCOFFEE="/home/niklas/tcoffee/parallel/99-1-Consumer-2/" export CACHE_4_TCOFFEE="$HOME_4_TCOFFEE/cache/" export TMP_4_TCOFFEE="$HOME_4_TCOFFEE/tmp/" export LOCKDIR_4_TCOFFEE="$HOME_4_TCOFFEE/lock/" mkdir -p $CACHE_4_TCOFFEE mkdir -p $TMP_4_TCOFFEE mkdir -p $LOCKDIR_4_TCOFFEE t_coffee -mode expresso -seq /home/niklas/tcoffee/parallel/Consumer-2Q9FHL4_ARATH -blast_server=LOCAL -pdb_db=pdbaa -outorder=input -output fasta_aln -quiet -no_warning -outfile=/tmp/tmpm3mViZ If I replace the t_coffee command by some simple 'touch I--was-here' the files are created as expected and no error is produced. The developers of the external program assured me that running their program in parallel should not be a problem if the environment variables are set correctly. If a take the exact same bash scripts that are generated by python and that failed when trying to run them in parallel through python and execute batches of them manually using a for loop in multiple terminals (i.e. in parallel) they don't produce an error. I am really puzzled and stuck. Python seems to work correctly on its own and the external program seems to work correctly on its own. But somehow, when combined, they won't work. Any help and hints would be really appreciated! I need that to work. I am using Ubuntu 12.04 with python 2.7.3 Cheers, Niklas -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Thu Jan 10 00:56:20 2013 From: d at davea.name (Dave Angel) Date: Thu, 10 Jan 2013 00:56:20 -0500 Subject: subprocess.Popen and multiprocessing fails to execute external program In-Reply-To: References: Message-ID: <50EE5804.4040704@davea.name> On 01/09/2013 11:08 PM, Niklas Berliner wrote: > I have a pipline that involves processing some data, handing the data to an > external program (t_coffee used for sequence alignments in bioinformatics), > and postprocessing the result. Since I have a lot of data, I need to run my > pipeline in parallel which I implemented using the multiprocessing module > following Doug Hellmanns blog ( > http://blog.doughellmann.com/2009/04/pymotw-multiprocessing-part-1.html). > > My pipeline works perfectly fine when I run it with the multiprocessing > implementation and one consumer, i.e. on one core. If I increase the number > of consumers, i.e. that multiple instances of my pipeline run in parallel > the external program fails with a core dump. > Could it be that the external program is not designed to have multiple simultaneous instances? There are many such programs, some of which check for an existing process before allowing another one to get far. When using the multiprocessing module, always make sure your externals are well-behaved before looking for problems in your multi-code. To put it more strongly, a well-written program cannot easily be crashed by the parent that launched it. -- DaveA From steve+comp.lang.python at pearwood.info Thu Jan 10 02:23:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Jan 2013 07:23:51 GMT Subject: RIse and fall of languages in 2012 Message-ID: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> "In general-purpose scripting languages, Python continues to grow slowly, JavaScript and Ruby are treading water, and Perl continues its long decline. According to Google trends, the number of searches for Perl is 19% of what it was in 2004. Its declining role in open-source communities further cements the perception that it's in an irretrievable tailspin. One should always be careful pronouncing a language dead or dying, because rare resurrections have occurred: JavaScript and Objective-C being two stand-out cases. However, Perl is unlikely to see such a new lease on life because of direct competition from Python, which is considerably more popular (whereas Objective-C and JavaScript had no direct equivalents when they came back)." http://www.drdobbs.com/jvm/the-rise-and-fall-of-languages-in-2012/240145800 And from the TIOBE Index, Python is steady at number 8: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html -- Steven From torriem at gmail.com Thu Jan 10 14:42:49 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 10 Jan 2013 12:42:49 -0700 Subject: RIse and fall of languages in 2012 In-Reply-To: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> References: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50EF19B9.2060000@gmail.com> On 01/10/2013 12:23 AM, Steven D'Aprano wrote: > "In general-purpose scripting languages, Python continues to grow slowly, > JavaScript and Ruby are treading water, and Perl continues its long > decline. According to Google trends, the number of searches for Perl is > 19% of what it was in 2004. Its declining role in open-source communities > further cements the perception that it's in an irretrievable tailspin. > One should always be careful pronouncing a language dead or dying, > because rare resurrections have occurred: JavaScript and Objective-C > being two stand-out cases. However, Perl is unlikely to see such a new > lease on life because of direct competition from Python, which is > considerably more popular (whereas Objective-C and JavaScript had no > direct equivalents when they came back)." > > http://www.drdobbs.com/jvm/the-rise-and-fall-of-languages-in-2012/240145800 > > > And from the TIOBE Index, Python is steady at number 8: > > http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html The TIOBE index is meaningless. Since it's based on google searches, one could probably guess that any language that is awkward and difficult will require more searches to figure out how to use the thing. Thus of course C is top! Especially if ranked by sarcastic queries like, "C sucks," and "why does C suck so much." Javascript is doing much more than just "treading water." Javascript may not be glamorous but it is *the* glue that makes the web run. Funny to see such a reputable journal make such an absurd statement. I can buy that Perl is in a slow decline. Certainly I'd use Python for the same tasks that people used to use Perl for. In short I see no rise and fall of languages in 2012. Seems like business as usual, and the usual suspects continue to get steady use. From john_ladasky at sbcglobal.net Thu Jan 10 17:50:14 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 10 Jan 2013 14:50:14 -0800 (PST) Subject: RIse and fall of languages in 2012 In-Reply-To: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> References: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, January 9, 2013 11:23:51 PM UTC-8, Steven D'Aprano wrote: > One should always be careful pronouncing a language dead or dying, No kidding! https://www.google.com/#q=is+fortran+still+used I usually use the query phrase "Why isn't Fortran dead yet?", but you get a better list of links with a less biased phrase. From steve+comp.lang.python at pearwood.info Thu Jan 10 18:32:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Jan 2013 23:32:55 GMT Subject: RIse and fall of languages in 2012 References: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ef4fa7$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Jan 2013 12:42:49 -0700, Michael Torrie wrote: >> And from the TIOBE Index, Python is steady at number 8: >> >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > The TIOBE index is meaningless. Since it's based on google searches, > one could probably guess that any language that is awkward and difficult > will require more searches to figure out how to use the thing. Thus of > course C is top! Especially if ranked by sarcastic queries like, "C > sucks," and "why does C suck so much." If you have a problem with TIOBE's methodology, feel free to come up with your own. Or take it up with them. I dispute that TIOBE measures difficulty of language. If it did, Malbolge would likely be at the top of the list. Yes, there are sarcastic queries asking "C sucks", but that's just measurement error: 21,200 hits for "C sucks" versus 9,900,000 for "C programming". It's not as if there is any language, not even Python, that is so easy to use that nobody needs to write about it. > Javascript is doing much more than just "treading water." How do you know? What's *your* methodology for determining the popularity of a language? * "But everybody knows that Javascript is super popular!!!" * "All my friends are using Javascript." * "I'm a web developer, and I use Javascript for my day job." * "I counted 14 job adverts on Monster.com for Javascript devs last week, what more evidence does anyone need?" * "I googled for `What's the most popular language?` and found a blog that says it's Javascript, that's good enough for me." * "I have a gut feeling." If you are going to criticise TIOBE's methodology, and then make your own claims for language popularity, you really need to demonstrate that your methodology is better. > Javascript > may not be glamorous but it is *the* glue that makes the web run. And web development is a tiny fraction of all software development. -- Steven From craigyk at me.com Thu Jan 10 22:50:42 2013 From: craigyk at me.com (Craig Yoshioka) Date: Thu, 10 Jan 2013 19:50:42 -0800 Subject: RIse and fall of languages in 2012 In-Reply-To: <50ef4fa7$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> <50ef4fa7$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: At one point or another I'm pretty sure I've googled "_____ sucks" for every language I've ever used- even the ones I like. ie: Python easily more than once. Craig reporting from the road 10550 N Torrey Pines Rd La Jolla CA 92037 work: 858 784 9208 cell: 619 623 2233 On Jan 10, 2013, at 3:32 PM, Steven D'Aprano wrote: > On Thu, 10 Jan 2013 12:42:49 -0700, Michael Torrie wrote: > >>> And from the TIOBE Index, Python is steady at number 8: >>> >>> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html >> >> The TIOBE index is meaningless. Since it's based on google searches, >> one could probably guess that any language that is awkward and difficult >> will require more searches to figure out how to use the thing. Thus of >> course C is top! Especially if ranked by sarcastic queries like, "C >> sucks," and "why does C suck so much." > > If you have a problem with TIOBE's methodology, feel free to come up with > your own. Or take it up with them. > > I dispute that TIOBE measures difficulty of language. If it did, Malbolge > would likely be at the top of the list. Yes, there are sarcastic queries > asking "C sucks", but that's just measurement error: 21,200 hits for "C > sucks" versus 9,900,000 for "C programming". It's not as if there is any > language, not even Python, that is so easy to use that nobody needs to > write about it. > > >> Javascript is doing much more than just "treading water." > > How do you know? What's *your* methodology for determining the popularity > of a language? > > * "But everybody knows that Javascript is super popular!!!" > > * "All my friends are using Javascript." > > * "I'm a web developer, and I use Javascript for my day job." > > * "I counted 14 job adverts on Monster.com for Javascript devs last week, > what more evidence does anyone need?" > > * "I googled for `What's the most popular language?` and found a blog > that says it's Javascript, that's good enough for me." > > * "I have a gut feeling." > > If you are going to criticise TIOBE's methodology, and then make your own > claims for language popularity, you really need to demonstrate that your > methodology is better. > > >> Javascript >> may not be glamorous but it is *the* glue that makes the web run. > > And web development is a tiny fraction of all software development. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list From walterhurry at lavabit.com Thu Jan 10 18:45:42 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 10 Jan 2013 23:45:42 +0000 (UTC) Subject: RIse and fall of languages in 2012 References: <50ee6c87$0$29898$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 10 Jan 2013 07:23:51 +0000, Steven D'Aprano wrote: > "In general-purpose scripting languages, Python continues to grow > slowly, JavaScript and Ruby are treading water, and Perl continues its > long decline. According to Google trends, the number of searches for > Perl is 19% of what it was in 2004. Its declining role in open-source > communities further cements the perception that it's in an irretrievable > tailspin. > One should always be careful pronouncing a language dead or dying, > because rare resurrections have occurred: JavaScript and Objective-C > being two stand-out cases. However, Perl is unlikely to see such a new > lease on life because of direct competition from Python, which is > considerably more popular (whereas Objective-C and JavaScript had no > direct equivalents when they came back)." Why should we care? We use Python because it's powerful, easy, elegant and all the other things. From niklas.berliner at gmail.com Thu Jan 10 09:34:43 2013 From: niklas.berliner at gmail.com (Niklas Berliner) Date: Thu, 10 Jan 2013 09:34:43 -0500 Subject: Python-list Digest, Vol 112, Issue 79 In-Reply-To: References: Message-ID: > > > > > ---------- Weitergeleitete Nachricht ---------- > From: Dave Angel > To: python-list at python.org > Cc: > Date: Thu, 10 Jan 2013 00:56:20 -0500 > Subject: Re: subprocess.Popen and multiprocessing fails to execute > external program > On 01/09/2013 11:08 PM, Niklas Berliner wrote: > > I have a pipline that involves processing some data, handing the data to > an > > external program (t_coffee used for sequence alignments in > bioinformatics), > > and postprocessing the result. Since I have a lot of data, I need to run > my > > pipeline in parallel which I implemented using the multiprocessing module > > following Doug Hellmanns blog ( > > http://blog.doughellmann.com/2009/04/pymotw-multiprocessing-part-1.html > ). > > > > My pipeline works perfectly fine when I run it with the multiprocessing > > implementation and one consumer, i.e. on one core. If I increase the > number > > of consumers, i.e. that multiple instances of my pipeline run in parallel > > the external program fails with a core dump. > > > > Could it be that the external program is not designed to have multiple > simultaneous instances? There are many such programs, some of which > check for an existing process before allowing another one to get far. > > When using the multiprocessing module, always make sure your externals > are well-behaved before looking for problems in your multi-code. > > To put it more strongly, a well-written program cannot easily be crashed > by the parent that launched it. > > > -- > > DaveA > > Hi Dave, the developers of the external program said that they are using the program with multiple simultaneous instances. Also, when I execute multiple simultaneous instances of the external program using a bash wrapper script on my machine it works (the same wrapper scripts that fail when executed through python). Before asking here I have contacted the developers of the external program but they couldn't help me any further. Cheers, Niklas -------------- next part -------------- An HTML attachment was scrubbed... URL: From dadapapa at googlemail.com Thu Jan 10 11:20:13 2013 From: dadapapa at googlemail.com (Harold) Date: Thu, 10 Jan 2013 08:20:13 -0800 (PST) Subject: problems importing from /usr/lib/pyshared/ Message-ID: Dear all, I recently upgraded my system from ubuntu 11.4 to 12.4 and since run into an issue when trying to import several packages in python2.7, e.g. harold at ubuntu:~$ python -c 'import gtk' Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py", line 30, in import gobject as _gobject File "/usr/share/pyshared/gobject/__init__.py", line 26, in from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \ File "/usr/share/pyshared/glib/__init__.py", line 22, in from glib._glib import * ImportError: No module named _glib the same, for example, with pysvn: harold at ubuntu:~$ python -c 'import pysvn' Traceback (most recent call last): File "", line 1, in File "/usr/share/pyshared/pysvn/__init__.py", line 99, in import _pysvn_2_7 ImportError: No module named _pysvn_2_7 After playing around a bit, I realized that I can import said packages without problems, if I delete /usr/lib/pyshared from the python path: >>> import sys >>> sys.path ['', '/usr/share/pyshared', '/home/harold', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] >>> del sys.path[1] >>> import gtk >>> import pysvn >>> Is /usr/lib/pyshared supposed to be in the python path? If not, how can I ensure that it is not included? Where is PYTHONPATH initialized by default, anyway? Thanks, harold. From dieter at handshake.de Sat Jan 12 02:08:30 2013 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 12 Jan 2013 08:08:30 +0100 Subject: problems importing from /usr/lib/pyshared/ References: Message-ID: <87mwweanf5.fsf@handshake.de> Harold writes: > I recently upgraded my system from ubuntu 11.4 to 12.4 and since run into an issue when trying to import several packages in python2.7, e.g. > > harold at ubuntu:~$ python -c 'import gtk' > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py", line 30, in > import gobject as _gobject > File "/usr/share/pyshared/gobject/__init__.py", line 26, in > from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \ > File "/usr/share/pyshared/glib/__init__.py", line 22, in > from glib._glib import * > ImportError: No module named _glib Ubuntu 12 has introduced important changes with respect to "glib" (and depending packages). In fact, there are now two quite incompatible implementations - the old "static" one and a new "dynamic" one. It looks as if in your case, old and new implementations were mixed. I had a similar problem when upgrading to "Ubuntu 12.4". In my case, it turned out that my (custom) "PYTHONPATH" setting was responsible for getting into the incompatibility. The new way to use "gtk" is via the "gi" (probable "gnome interface") module. It looks like: from gi.repository import Gtk,GdkPixbuf,GObject,Pango,Gdk,Gio From dadapapa at googlemail.com Sat Jan 12 11:45:17 2013 From: dadapapa at googlemail.com (Harold) Date: Sat, 12 Jan 2013 08:45:17 -0800 (PST) Subject: problems importing from /usr/lib/pyshared/ In-Reply-To: References: Message-ID: Thank you Dieter, > Ubuntu 12 has introduced important changes with respect to "glib" (and > depending packages). In fact, there are now two quite incompatible > implementations - the old "static" one and a new "dynamic" one. > It looks as if in your case, old and new implementations were mixed. > > I had a similar problem when upgrading to "Ubuntu 12.4". In my case, > it turned out that my (custom) "PYTHONPATH" setting was responsible for > getting into the incompatibility. > > The new way to use "gtk" is via the "gi" (probable "gnome interface") > module. It looks like: > > from gi.repository import Gtk,GdkPixbuf,GObject,Pango,Gdk,Gio I will investigate this gi module. As for my import problem, it turned out that it was my own fault: following some recommendation on the web, I had added /usr/share/pyshared to the python path in ~/.profile and forgot to log out and in again after undoing this change. Everything works fine again, and I am ready to explore the new modules. From dadapapa at googlemail.com Sat Jan 12 11:45:17 2013 From: dadapapa at googlemail.com (Harold) Date: Sat, 12 Jan 2013 08:45:17 -0800 (PST) Subject: problems importing from /usr/lib/pyshared/ In-Reply-To: References: Message-ID: Thank you Dieter, > Ubuntu 12 has introduced important changes with respect to "glib" (and > depending packages). In fact, there are now two quite incompatible > implementations - the old "static" one and a new "dynamic" one. > It looks as if in your case, old and new implementations were mixed. > > I had a similar problem when upgrading to "Ubuntu 12.4". In my case, > it turned out that my (custom) "PYTHONPATH" setting was responsible for > getting into the incompatibility. > > The new way to use "gtk" is via the "gi" (probable "gnome interface") > module. It looks like: > > from gi.repository import Gtk,GdkPixbuf,GObject,Pango,Gdk,Gio I will investigate this gi module. As for my import problem, it turned out that it was my own fault: following some recommendation on the web, I had added /usr/share/pyshared to the python path in ~/.profile and forgot to log out and in again after undoing this change. Everything works fine again, and I am ready to explore the new modules. From pcurad01 at gmail.com Thu Jan 10 12:50:37 2013 From: pcurad01 at gmail.com (pmec) Date: Thu, 10 Jan 2013 09:50:37 -0800 (PST) Subject: average time calculation?? Message-ID: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Hi there guys i've got a script that's suppose to find the average of two times as strings. The times are in minutes:seconds:milliseconds i'm doing ok in printing the right minutes and seconds my problem is with the milliseconds. Example if i have 00:02:20 and 00:04:40 the average will be 00:03:30 or 00:02:00 and 00:03:00 will be 00:02:30 Can anyone help me out with this please. Here is the code that i have so far: def lap_average(lap1, lap2): t1 = lap1.replace(":",'') t2 = lap2.replace(":",'') mins1, secs1, hundreths1 = t1[:2], t1[2:4], t1[4:] mins2, secs2, hundreths2 = t2[:2], t2[2:4], t2[4:] total_seconds = int(secs1) + int(secs2) + int(mins1) * 60 + int(mins2) * 60 millisec = (total_seconds * 1000) millisec = millisec / 2 micro_x = millisec minutes = micro_x / (60*1000) micro_x = micro_x - minutes * (60*1000) seconds = micro_x / 1000 micro_x = micro_x - seconds print '%02d:%02d:%s' % (minutes, seconds, micro_x) lap_average('03:40:00', '05:20:00') lap_average('03:00:02', '02:00:00') lap_average('02:25:50', '06:50:75') lap_average('00:02:00', '00:03:00') lap_average('00:02:20', '00:04:40') lap_average('02:40:40', '03:30:30') lap_average('02:60:30', '60:40:40') Thanks in Advance From oscar.j.benjamin at gmail.com Thu Jan 10 13:13:06 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 10 Jan 2013 18:13:06 +0000 Subject: average time calculation?? In-Reply-To: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: On 10 January 2013 17:50, pmec wrote: > Hi there guys i've got a script that's suppose to find the average of two times as strings. The times are in minutes:seconds:milliseconds > i'm doing ok in printing the right minutes and seconds my problem is with the milliseconds. You might find it easier to do this arithmetic if using datetime.time objects from the datetime module: http://docs.python.org/2/library/datetime.html > > Example if i have 00:02:20 and 00:04:40 the average will be 00:03:30 or 00:02:00 and 00:03:00 will be 00:02:30 > > Can anyone help me out with this please. Here is the code that i have so far: > > def lap_average(lap1, lap2): > > t1 = lap1.replace(":",'') > t2 = lap2.replace(":",'') > > mins1, secs1, hundreths1 = t1[:2], t1[2:4], t1[4:] > mins2, secs2, hundreths2 = t2[:2], t2[2:4], t2[4:] Are these really hundredths? At the top you said it goes minutes:seconds:milliseconds. A hundredth of a second is 10 milliseconds so you need to be clear about which one you want. > > total_seconds = int(secs1) + int(secs2) + int(mins1) * 60 + int(mins2) * 60 What happened to the hundredths in the line above. Surely you wanted to add 0.01 * hundredths there. > > millisec = (total_seconds * 1000) > millisec = millisec / 2 In Python 2 this division will always round down if millisec is an integer. Is that what you want? > > micro_x = millisec Is the line above just there to confuse me? I thought millisec was a good descriptive name. In this context micro would suggest microseconds which would be 1000 times smaller. > minutes = micro_x / (60*1000) Wouldn't it have been easier to just get this from total_seconds? > micro_x = micro_x - minutes * (60*1000) > seconds = micro_x / 1000 This will behave differently in Python 3. Safest to use floor division // here: http://stackoverflow.com/questions/183853/in-python-what-is-the-difference-between-and-when-used-for-division > micro_x = micro_x - seconds Surely that should be seconds*1000? > > print '%02d:%02d:%s' % (minutes, seconds, micro_x) Until your done debugging, I suggest you print all of these values out directly (without the format string): print(minutes, seconds, microx) > > lap_average('03:40:00', '05:20:00') > lap_average('03:00:02', '02:00:00') > lap_average('02:25:50', '06:50:75') > lap_average('00:02:00', '00:03:00') > lap_average('00:02:20', '00:04:40') > lap_average('02:40:40', '03:30:30') > lap_average('02:60:30', '60:40:40') Oscar From oscar.j.benjamin at gmail.com Thu Jan 10 13:14:53 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 10 Jan 2013 18:14:53 +0000 Subject: average time calculation?? In-Reply-To: References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: Two quick corrections to what I wrote... On 10 January 2013 18:13, Oscar Benjamin wrote: > On 10 January 2013 17:50, pmec wrote: >> Hi there guys i've got a script that's suppose to find the average of two times as strings. The times are in minutes:seconds:milliseconds >> i'm doing ok in printing the right minutes and seconds my problem is with the milliseconds. > > You might find it easier to do this arithmetic if using datetime.time > objects from the datetime module: > http://docs.python.org/2/library/datetime.html Actually I meant datetime.timedelta objects. > >> >> Example if i have 00:02:20 and 00:04:40 the average will be 00:03:30 or 00:02:00 and 00:03:00 will be 00:02:30 >> >> Can anyone help me out with this please. Here is the code that i have so far: >> >> def lap_average(lap1, lap2): >> >> t1 = lap1.replace(":",'') >> t2 = lap2.replace(":",'') >> >> mins1, secs1, hundreths1 = t1[:2], t1[2:4], t1[4:] >> mins2, secs2, hundreths2 = t2[:2], t2[2:4], t2[4:] > > Are these really hundredths? At the top you said it goes > minutes:seconds:milliseconds. A hundredth of a second is 10 > milliseconds so you need to be clear about which one you want. > >> >> total_seconds = int(secs1) + int(secs2) + int(mins1) * 60 + int(mins2) * 60 > > What happened to the hundredths in the line above. Surely you wanted > to add 0.01 * hundredths there. > >> >> millisec = (total_seconds * 1000) >> millisec = millisec / 2 > > In Python 2 this division will always round down if millisec is an > integer. Is that what you want? > >> >> micro_x = millisec > > Is the line above just there to confuse me? I thought millisec was a > good descriptive name. In this context micro would suggest > microseconds which would be 1000 times smaller. > >> minutes = micro_x / (60*1000) > > Wouldn't it have been easier to just get this from total_seconds? > >> micro_x = micro_x - minutes * (60*1000) >> seconds = micro_x / 1000 > > This will behave differently in Python 3. Safest to use floor division // here: > http://stackoverflow.com/questions/183853/in-python-what-is-the-difference-between-and-when-used-for-division > >> micro_x = micro_x - seconds > > Surely that should be seconds*1000? > >> >> print '%02d:%02d:%s' % (minutes, seconds, micro_x) micro_x is in units of microseconds. Did you want microseconds or hundredths of a second here in the output? > > Until your done debugging, I suggest you print all of these values out > directly (without the format string): > > print(minutes, seconds, microx) > >> >> lap_average('03:40:00', '05:20:00') >> lap_average('03:00:02', '02:00:00') >> lap_average('02:25:50', '06:50:75') >> lap_average('00:02:00', '00:03:00') >> lap_average('00:02:20', '00:04:40') >> lap_average('02:40:40', '03:30:30') >> lap_average('02:60:30', '60:40:40') > > > Oscar From pcurad01 at gmail.com Thu Jan 10 14:55:23 2013 From: pcurad01 at gmail.com (pmec) Date: Thu, 10 Jan 2013 11:55:23 -0800 (PST) Subject: average time calculation?? In-Reply-To: References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: <4d901582-2aa7-4abb-ab65-64c895505ab8@googlegroups.com> Hi Oscar, Thank you for your reply, and you are absolutely right, I meant hundredths of a second to be outputed From pcurad01 at gmail.com Thu Jan 10 14:55:23 2013 From: pcurad01 at gmail.com (pmec) Date: Thu, 10 Jan 2013 11:55:23 -0800 (PST) Subject: average time calculation?? In-Reply-To: References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: <4d901582-2aa7-4abb-ab65-64c895505ab8@googlegroups.com> Hi Oscar, Thank you for your reply, and you are absolutely right, I meant hundredths of a second to be outputed From python at mrabarnett.plus.com Thu Jan 10 13:22:55 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 10 Jan 2013 18:22:55 +0000 Subject: average time calculation?? In-Reply-To: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: <50EF06FF.8040909@mrabarnett.plus.com> On 2013-01-10 17:50, pmec wrote: > Hi there guys i've got a script that's suppose to find the average of two times as strings. The times are in minutes:seconds:milliseconds > i'm doing ok in printing the right minutes and seconds my problem is with the milliseconds. > > Example if i have 00:02:20 and 00:04:40 the average will be 00:03:30 or 00:02:00 and 00:03:00 will be 00:02:30 > If the final 2 digits are milliseconds, then the second average would be 00:02:500; if they're centiseconds (hundredths of a second), then the second average would be 00:02:50. If the average you give is correct ('00:02:30'), then that suggests that they are in fact hours:minutes:seconds. > Can anyone help me out with this please. Here is the code that i have so far: > > def lap_average(lap1, lap2): > > t1 = lap1.replace(":",'') > t2 = lap2.replace(":",'') > > mins1, secs1, hundreths1 = t1[:2], t1[2:4], t1[4:] > mins2, secs2, hundreths2 = t2[:2], t2[2:4], t2[4:] > > total_seconds = int(secs1) + int(secs2) + int(mins1) * 60 + int(mins2) * 60 > > millisec = (total_seconds * 1000) > millisec = millisec / 2 > > micro_x = millisec > minutes = micro_x / (60*1000) > > micro_x = micro_x - minutes * (60*1000) > seconds = micro_x / 1000 > micro_x = micro_x - seconds > > print '%02d:%02d:%s' % (minutes, seconds, micro_x) > > lap_average('03:40:00', '05:20:00') > lap_average('03:00:02', '02:00:00') > lap_average('02:25:50', '06:50:75') > lap_average('00:02:00', '00:03:00') > lap_average('00:02:20', '00:04:40') > lap_average('02:40:40', '03:30:30') > lap_average('02:60:30', '60:40:40') > > Thanks in Advance > I don't see the point of these 2 lines of removing the ':'; slice 'lap1' and 'lap2' instead: mins1, secs1, hundreths1 = lap1[:2], lap1[3:5], lap1[6:] mins2, secs2, hundreths2 = lap2[:2], lap2[3:5], lap2[6:] Better yet, split on ':': mins1, secs1, hundreths1 = lap1.split(':') mins2, secs2, hundreths2 = lap2.split(':') Incidentally, you're talking about milliseconds, but the names say 'hundreths'. A useful function is 'divmod', which, as its name suggests, performs both (integer) division and modulo in one step: seconds, millisec = divmod(millisec, 1000) minutes, seconds = divmod(seconds, 60) From pcurad01 at gmail.com Thu Jan 10 15:31:10 2013 From: pcurad01 at gmail.com (pmec) Date: Thu, 10 Jan 2013 12:31:10 -0800 (PST) Subject: average time calculation?? In-Reply-To: References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: Hi Oscar, again I do apologize for my beginner mistakes, I've changed the code taking in consideration some of your and MRAB suggestions. Could you give me an example on how could I use the datetime.timedelta function in this particular case. This is my code: def lap_average(lap1, lap2): mins1, secs1, hundreths1 = lap1.split(":") mins2, secs2, hundreths2 = lap2.split(":") minutes = int(mins1) + int(mins2) seconds = float(secs1) + float(secs2) hundredths = int(60000 * minutes + 1000 * seconds) hundredths = hundredths // 2 print hundredths lap_average('03:40:00', '05:20:00') lap_average('03:00:02', '02:00:00') lap_average('02:25:50', '06:50:75') lap_average('00:02:00', '00:03:00') #should output: 00:02:50 lap_average('00:02:20', '00:04:40') # 00:03:30 lap_average('02:40:40', '03:30:30') # etc lap_average('02:60:30', '60:40:40') Also I was a bit confused with what you said about : "> total_seconds = int(secs1) + int(secs2) + int(mins1) * 60 + int(mins2) * 60 What happened to the hundredths in the line above. Surely you wanted to add 0.01 * hundredths there." I thought the above was already the entire time as hundredths of second?? From pcurad01 at gmail.com Thu Jan 10 15:31:10 2013 From: pcurad01 at gmail.com (pmec) Date: Thu, 10 Jan 2013 12:31:10 -0800 (PST) Subject: average time calculation?? In-Reply-To: References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: Hi Oscar, again I do apologize for my beginner mistakes, I've changed the code taking in consideration some of your and MRAB suggestions. Could you give me an example on how could I use the datetime.timedelta function in this particular case. This is my code: def lap_average(lap1, lap2): mins1, secs1, hundreths1 = lap1.split(":") mins2, secs2, hundreths2 = lap2.split(":") minutes = int(mins1) + int(mins2) seconds = float(secs1) + float(secs2) hundredths = int(60000 * minutes + 1000 * seconds) hundredths = hundredths // 2 print hundredths lap_average('03:40:00', '05:20:00') lap_average('03:00:02', '02:00:00') lap_average('02:25:50', '06:50:75') lap_average('00:02:00', '00:03:00') #should output: 00:02:50 lap_average('00:02:20', '00:04:40') # 00:03:30 lap_average('02:40:40', '03:30:30') # etc lap_average('02:60:30', '60:40:40') Also I was a bit confused with what you said about : "> total_seconds = int(secs1) + int(secs2) + int(mins1) * 60 + int(mins2) * 60 What happened to the hundredths in the line above. Surely you wanted to add 0.01 * hundredths there." I thought the above was already the entire time as hundredths of second?? From ian.g.kelly at gmail.com Thu Jan 10 17:48:39 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Jan 2013 15:48:39 -0700 Subject: average time calculation?? In-Reply-To: References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: On Thu, Jan 10, 2013 at 1:31 PM, pmec wrote: > Hi Oscar, again I do apologize for my beginner mistakes, I've changed the code taking in consideration some of your and MRAB suggestions. > > Could you give me an example on how could I use the datetime.timedelta function in this particular case. td1 = timedelta(minutes=mins1, seconds=secs1, milliseconds=hundredths1*10) td2 = timedelta(minutes=mins2, seconds=secs2, milliseconds=hundredths2*10) average = (td1 + td2) / 2 mins, secs = divmod(average.seconds, 60) hundredths = average.microseconds // 10000 print("{:02d}:{:02d}:{:02d}".format(mins, secs, hundredths)) From tboell at domain.invalid Sat Jan 12 10:32:36 2013 From: tboell at domain.invalid (Thomas Boell) Date: Sat, 12 Jan 2013 16:32:36 +0100 Subject: average time calculation?? References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> Message-ID: <20130112163236.24357812@sampi> On Thu, 10 Jan 2013 09:50:37 -0800 (PST) pmec wrote: > Hi there guys i've got a script that's suppose to find the average of two times as strings. The times are in minutes:seconds:milliseconds > i'm doing ok in printing the right minutes and seconds my problem is with the milliseconds. > > Example if i have 00:02:20 and 00:04:40 the average will be 00:03:30 or 00:02:00 and 00:03:00 will be 00:02:30 This is how I would probably go about it: Convert your strings to floating point values which describe the time in seconds. Look at string.split() if you do it by hand. You could also use a regular expression ('re' module). Then, calculate the average: (a+b)*0.5 Then, convert back to your string format if you must. This may sound like more work at first but it is probably easier and less error-prone than messing with those separate values. Make sure you properly understand the string format first. minutes:seconds:milliseconds sounds unusual to me, but if you know for certain that is the format, then it is :) From rosuav at gmail.com Sat Jan 12 11:05:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Jan 2013 03:05:45 +1100 Subject: average time calculation?? In-Reply-To: <20130112163236.24357812@sampi> References: <6b86f2fe-8e23-423c-8c7a-7af7282c0ab2@googlegroups.com> <20130112163236.24357812@sampi> Message-ID: On Sun, Jan 13, 2013 at 2:32 AM, Thomas Boell wrote: > This is how I would probably go about it: > Convert your strings to floating point values which describe the time > in seconds. Either floats or integers (which would be milliseconds, or whatever your smallest unit is). I tend to prefer integers for this sort of work, but do whichever you feel more comfortable working with. ChrisA From mountdoom12 at gmail.com Thu Jan 10 13:32:28 2013 From: mountdoom12 at gmail.com (mountdoom12 at gmail.com) Date: Thu, 10 Jan 2013 10:32:28 -0800 (PST) Subject: How to change colors of multiple widgets after hovering in Tkinter Message-ID: Hello, I?m trying to make a script, which will change the background and foreground color of widgets after hovering. ------------------------- from Tkinter import * root=Tk() Hover1=Button(root,text="Red color", bg="white") Hover1.pack() Hover2=Button(root,text="Yellow color", bg="white") Hover2.pack() Hover1.bind("",Hover1.configure(bg="red")) Hover1.bind("",Hover1.configure(bg="white")) Hover2.bind("",Hover2.configure(bg="yellow")) Hover2.bind("",Hover2.configure(bg="white")) root.mainloop() ------------------------- but when I hover on any button, nothing happens, they stay white. I know I could use a function, but there would be two functions for every widget (1 for , 1 for ). I'd like to create a single function, which will recolor that widget I hover on and explain why this script is not doing what I want it to do. I hope I described my problem well. Thanks for every answer. PS: I would like to avoid classes. mountDoom From __peter__ at web.de Thu Jan 10 14:13:38 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 10 Jan 2013 20:13:38 +0100 Subject: How to change colors of multiple widgets after hovering in Tkinter References: Message-ID: mountdoom12 at gmail.com wrote: > I?m trying to make a script, which will change the background and > foreground color of widgets after hovering. > but when I hover on any button, nothing happens, they stay white. I know I > could use a function, but there would be two functions for every widget (1 > for , 1 for ). I'd like to create a single function, which will recolor > that widget I hover on and explain why this script is not doing what I > want it to do. > > I hope I described my problem well. You did. > from Tkinter import * > > root=Tk() > > Hover1=Button(root,text="Red color", bg="white") > Hover1.pack() > > Hover2=Button(root,text="Yellow color", bg="white") > Hover2.pack() > > Hover1.bind("",Hover1.configure(bg="red")) This calls Hover1.configure(bg="red") once and binds the result of that method call (which is None) to the event. So the above line is equivalent to Hover1.configure(bg="red") Hover1.bind("", None) You say you don't want to write a function, but that is really the correct aproach. Fortunately there is a way to create such a function on the fly: def f(event): Hover1.configure(bg="red") can be written as f = lambda event: Hover1.configure(bg="red") With that your code becomes Hover1.bind("", lambda event: Hover1.configure(bg="red")) Hover1.bind("", lambda event: Hover1.configure(bg="white")) and so on. In this specific case this doesn't have the desired effect because when the mouse enters a Button widget its background color changes to 'activebackground'. So you don't really need to bind the enter/leave events. Specify an activebackground instead when you create the buttons. For example: Hover1 = Button(root, text="Red color", bg="white", activebackground="red") Hover1.pack() From rantingrickjohnson at gmail.com Fri Jan 11 00:43:00 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 10 Jan 2013 21:43:00 -0800 (PST) Subject: How to change colors of multiple widgets after hovering in Tkinter In-Reply-To: References: Message-ID: On Thursday, January 10, 2013 1:13:38 PM UTC-6, Peter Otten wrote: > mountdoom wrote: > > I?m trying to make a script, which will change the background and > > foreground color of widgets after hovering. Peter's advice is spot on except you may want ALL widgets to change colors on and events. If you want all widgets use the "w.bind_all" method instead of "w.bind". Also check out the "w.bind_class" method to confine bindings to one particular class of widget (like a Tkinter.Button). From rantingrickjohnson at gmail.com Fri Jan 11 00:43:00 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 10 Jan 2013 21:43:00 -0800 (PST) Subject: How to change colors of multiple widgets after hovering in Tkinter In-Reply-To: References: Message-ID: On Thursday, January 10, 2013 1:13:38 PM UTC-6, Peter Otten wrote: > mountdoom wrote: > > I?m trying to make a script, which will change the background and > > foreground color of widgets after hovering. Peter's advice is spot on except you may want ALL widgets to change colors on and events. If you want all widgets use the "w.bind_all" method instead of "w.bind". Also check out the "w.bind_class" method to confine bindings to one particular class of widget (like a Tkinter.Button). From kalvinmanual at gmail.com Thu Jan 10 16:47:47 2013 From: kalvinmanual at gmail.com (kalvinmanual) Date: Thu, 10 Jan 2013 15:47:47 -0600 Subject: Organic Chemistry, 8th Ed by Wade, Jan Simek Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. instructor's solutions manual to OpenScape Voice V3.1R3 Test Configuration and connectivity Vol 2 , Application and Hardware Configuratio instructor's solutions manual to Operating System Concepts, 6E, Silberschatz, Galvin, Gagne instructor's solutions manual to Operating System Concepts, 7E, Silberschatz, Galvin, Gagne instructor's solutions manual to Operating systems Internals and Design principles 4th Edition Stallings instructor's solutions manual to Operating systems Internals and Design principles 5th Edition Stallings instructor's solutions manual to Operations Management 5th Ed by Nigel Slack, Chambers, Johnston instructor's solutions manual to Optical Fiber Communications 3rd E by Gerd Keiser instructor's solutions manual to Optical Properties of Solids 2nd Ed by Mark Fox instructor's solutions manual to Optics 4th Edition by Hecht E., Coffey M., Dolan P instructor's solutions manual to Optimal Control Theory An Introduction By Donald E. Kirk instructor's solutions manual to Optimal State Estimation Dan Simon instructor's solutions manual to Optimization of Chemical Processes by Edgar instructor's solutions manual to Options, Futures and Other Derivatives, 4E, by John Hull instructor's solutions manual to Options, Futures and Other Derivatives, 5E, by John Hull instructor's solutions manual to Options, Futures, and Other Derivatives 7th Ed by John C. Hull instructor's solutions manual to Orbital Mechanics for Engineering Students 2nd ED by Curtis instructor's solutions manual to Orbital Mechanics for Engineering Students by Curtis instructor's solutions manual to ORDINARY DIFFERENTIAL EQUATIONS by Adkins, Davidson instructor's solutions manual to Organic Chemistry - Clayden et.al. instructor's solutions manual to Organic Chemistry 2nd ed by Schore instructor's solutions manual to Organic Chemistry 2nd Edition by Hornback instructor's solutions manual to Organic Chemistry 5th Ed by Brown, Foote, Iverson, Ansyln instructor's solutions manual to Organic Chemistry 7ed, McMurry instructor's solutions manual to Organic Chemistry, 4E., by Carey, Atkins instructor's solutions manual to Organic Chemistry, 5E., by Carey, Atkins instructor's solutions manual to Organic Chemistry, 6 Ed by Wade, Jan Simek instructor's solutions manual to Organic Chemistry, 8th Ed by Wade, Jan Simek instructor's solutions manual to Parallel & Distributed Computation Numerical Methods by Bertsekas & Tsitsiklis instructor's solutions manual to Parallel Programming: Techniques and Applications Using Networked Workstations and Parallel Computers (2nd Ed., Barry Wilkinson & Michael Allen) instructor's solutions manual to PARTIAL DIFFERENTIAL EQUATIONS WITH FOURIER SERIES and BOUNDARY VALUE PROBLEMS 2nd Edition by NAKHLE H. ASMAR (Students Solutions Manual) instructor's solutions manual to Physical Basis of Biochemistry 2nd Ed by Bergethon, Hallock instructor's solutions manual to Physical Chemistry (7E, Peter Atkins & Julio de Paula) instructor's solutions manual to Physical Chemistry by Prem Dhawan instructor's solutions manual to Physical Chemistry by Thomas Engel & Philip Reid instructor's solutions manual to Physics - Concept and Connections - Book Two by Brian Heimbecker, Igor Nowikow, et al instructor's solutions manual to Physics - Concept and Connections -by Brian Heimbecker, Igor Nowikow, et al instructor's solutions manual to Physics - Principles and Problems instructor's solutions manual to Physics - Principles and Problems ( Glencoe ) instructor's solutions manual to Physics , Fifth Edition, Volume One (Halliday, Resnick, Krane) instructor's solutions manual to Physics 7th ed by Paul E. Tippens instructor's solutions manual to Physics 8 ED by Cutnell & Johnsen instructor's solutions manual to Physics for Scientist and Engineers, 5E, by Tipler, Mosca instructor's solutions manual to Physics For Scientists & Engineers 5th Ed (vol.I,vol.II) by Serway & Beichner instructor's solutions manual to Physics For Scientists & Engineers 7th Ed. by Serway & Jewett instructor's solutions manual to Physics For Scientists & Engineers Vol.1& 2 3rd Ed. by Serway & Jewett instructor's solutions manual to Physics For Scientists & Engineers Vol.1& 2 4th Ed. by Serway & Jewett instructor's solutions manual to Physics For Scientists & Engineers Vol.I 6th Ed. by Serway & Jewett instructor's solutions manual to Physics For Scientists & Engineers Vol.II 6th Ed. by Serway & Jewett instructor's solutions manual to Physics for Scientists & Engineers with Modern Physics 4th E by Douglas Giancoli instructor's solutions manual to Physics For Scientists and Engineers 8th ed VOL.1 by Gordon, McGrew, Serway ( student solutions manual and study guide ) instructor's solutions manual to Physics for Scientists and Engineers with Modern Physics (3rd Edition) by Douglas C. Giancoli instructor's solutions manual to Physics for Scientists and Engineers, 1st E by Knight instructor's solutions manual to Physics for Scientists and Engineers, 2/E by Knight instructor's solutions manual to Physics, 2nd Ed James S. Walker instructor's solutions manual to Physics, 5th Edition, Vol 1 by Halliday, Resnick, Krane instructor's solutions manual to Physics, 5th Edition, Vol 2 by Halliday, Resnick, Krane instructor's solutions manual to Physics: Principles with Applications with Mastering Physics, 6/E, Douglas C. Giancoli instructor's solutions manual to Power Electronics Converters, Applications and Design 2nd ED by Mohan, Robbins instructor's solutions manual to Power Electronics Converters, Applications, and Design 3rd ed By Ned Mohan, Tore M. Undeland, William P. Robbins instructor's solutions manual to Power System Analysis and Design, 3 E., by Glover, Sarma instructor's solutions manual to Power System Analysis and Design,4E., by Glover, Sarma instructor's solutions manual to Power System Analysis,John J. Grainger William D. Stevenson instructor's solutions manual to Power Systems Analysis - 2nd Edition by Hadi Saadat instructor's solutions manual to POWER SYSTEMS ANALYSIS by HADI SAADAT instructor's solutions manual to Precalculus - Mathematics for Calculus 3rd ed by Stewart, Watson instructor's solutions manual to Precalculus Mathematics for Calculus, 3rd E Stewart, Redlin, Watson instructor's solutions manual to Precalculus, 7th Ed by Sullivan instructor's solutions manual to Principles and Applications of Electrical EngineeringG. Rizzoni instructor's solutions manual to Principles of Communications- Systems, Modulation, and Noise (5th Ed.,Ziemer & W.H. Tranter) instructor's solutions manual to Principles of Corporate Finance 7th Ed by Brealey, Myers instructor's solutions manual to Principles of Digital Communication and coding by Andrew J. Viterbi and Jim K. Omura instructor's solutions manual to Principles of Dynamics 2nd ED, Donald T. Greenwood instructor's solutions manual to Principles of Electric Machines and Power Electronisa 2nd Ed by P.C. SEN instructor's solutions manual to Principles of Electronic Materials and Devices 2ed by Safa O. Kasap instructor's solutions manual to Principles of Foundation Engineering, 6E by Braja M.Das instructor's solutions manual to Principles of Geotechnical Engineering 6th edition by Braja M. Das instructor's solutions manual to Principles of Highway Engineering and Traffic Analysis 4 ED (Metric Units) by Mannering,Washburn,Kilareski instructor's solutions manual to Principles of Highway Engineering and Traffic Analysis 4 ED (US Units) by Mannering,Washburn,Kilareski instructor's solutions manual to Principles of Managerial Finance 4e by Gitman, Juchau, Flanagan instructor's solutions manual to Principles Of Mathmatical Analysis by Rudin instructor's solutions manual to Principles of Neurocomputing for Science and Engineering, Fredric M. Ham,Ivica Kostanic instructor's solutions manual to Principles of Physics 3rd ed Vol 1 by Serway, Jewett instructor's solutions manual to Principles of Physics 3rd ed Vol 2 by Serway, Jewett instructor's solutions manual to Principles of Physics A Calculus Based Text 4 Ed VOL 1 by Serway and Jewett instructor's solutions manual to Principles of Physics A Calculus Based Text 4 Ed VOL 2 by Serway and Jewett instructor's solutions manual to Principles of Polymer Engineering 2nd ED by McCrum, Buckley, Bucknall instructor's solutions manual to PRINCIPLES??OF??HEAT??TRANSFER,??7TH ED by KREITH,MANGLIK,BOHN instructor's solutions manual to Probability & Statistics for Engineers & Scientists (8th Ed., Walpole,Myers, Ye) instructor's solutions manual to Probability and Statistical Inference ( 8th Ed, Hogg & Tanis ) From thebalancepro at gmail.com Thu Jan 10 20:59:05 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Thu, 10 Jan 2013 17:59:05 -0800 (PST) Subject: Probabilistic unit tests? Message-ID: Hi, I've got a unit test that will usually succeed but sometimes fails. An occasional failure is expected and fine. It's failing all the time I want to test for. What I want to test is "on average, there are the same number of males and females in a sample, give or take 2%." Here's the unit test code: import unittest from collections import counter sex_count = Counter() for contact in range(self.binary_check_sample_size): p = get_record_as_dict() sex_count[p['Sex']] += 1 self.assertAlmostEqual(sex_count['male'], sex_count['female'], delta=sample_size * 2.0 / 100.0) My question is: how would you run an identical test 5 times and pass the group *as a whole* if only one or two iterations passed the test? Something like: for n in range(5): # self.assertAlmostEqual(...) # if test passed: break else: self.fail() (except that would create 5+1 tests as written!) Thanks for any thoughts, Best wishes, Nick From roy at panix.com Thu Jan 10 21:22:29 2013 From: roy at panix.com (Roy Smith) Date: Thu, 10 Jan 2013 21:22:29 -0500 Subject: Probabilistic unit tests? References: Message-ID: In article , Nick Mellor wrote: > Hi, > > I've got a unit test that will usually succeed but sometimes fails. An > occasional failure is expected and fine. It's failing all the time I want to > test for. > > What I want to test is "on average, there are the same number of males and > females in a sample, give or take 2%." > [...] > My question is: how would you run an identical test 5 times and pass the > group *as a whole* if only one or two iterations passed the test? Something > like: > > for n in range(5): > # self.assertAlmostEqual(...) > # if test passed: break > else: > self.fail() I would do something like: def do_test_body(): """Returns 1 if it passes, 0 if it fails""" results = [do_test() for n in range(number_of_trials)] self.assert(sum(results) > threshold) That's the simple part. The more complicated part is figuring out how many times to run the test and what an appropriate threshold is. For that, you need to talk to a statistician. From steve+comp.lang.python at pearwood.info Thu Jan 10 22:34:38 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Jan 2013 03:34:38 GMT Subject: Probabilistic unit tests? References: Message-ID: <50ef884e$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Jan 2013 17:59:05 -0800, Nick Mellor wrote: > Hi, > > I've got a unit test that will usually succeed but sometimes fails. An > occasional failure is expected and fine. It's failing all the time I > want to test for. Well, that's not really a task for unit testing. Unit tests, like most tests, are well suited to deterministic tests, but not really to probabilistic testing. As far as I know, there aren't really any good frameworks for probabilistic testing, so you're stuck with inventing your own. (Possibly on top of unittest.) > What I want to test is "on average, there are the same number of males > and females in a sample, give or take 2%." > > Here's the unit test code: > import unittest > from collections import counter > > sex_count = Counter() > for contact in range(self.binary_check_sample_size): > p = get_record_as_dict() > sex_count[p['Sex']] += 1 > self.assertAlmostEqual(sex_count['male'], > sex_count['female'], > delta=sample_size * 2.0 / 100.0) That's a cheap and easy way to almost get what you want, or at least what I think you should want. Rather than a "Succeed/Fail" boolean test result, I think it is worth producing a float between 0 and 1 inclusive, where 0 is "definitely failed" and 1 is "definitely passed", and intermediate values reflect some sort of fuzzy logic score. In your case, you might look at the ratio of males to females. If the ratio is exactly 1, the fuzzy score would be 1.0 ("definitely passed"), otherwise as the ratio gets further away from 1, the score would approach 0.0: if males <= females: score = males/females else: score = females/males should do it. Finally you probabilistic-test framework could then either report the score itself, or decide on a cut-off value below which you turn it into a unittest failure. That's still not quite right though. To be accurate, you're getting into the realm of hypotheses testing and conditional probabilities: - if these random samples of males and females came from a population of equal numbers of each, what is the probability I could have got the result I did? - should I reject the hypothesis that the samples came from a population with equal numbers of males and females? Talk to a statistician on how to do this. > My question is: how would you run an identical test 5 times and pass the > group *as a whole* if only one or two iterations passed the test? > Something like: > > for n in range(5): > # self.assertAlmostEqual(...) > # if test passed: break > else: > self.fail() > > (except that would create 5+1 tests as written!) Simple -- don't use assertAlmostEqual, or any other of the unittest assertSomething methods. Write your own function to decide whether or not something passed, then count how many times it passed: count = 0 for n in range(5): count += self.run_some_test() # returns 0 or 1, or a fuzzy score if count < some_cut_off: self.fail() -- Steven From wuwei23 at gmail.com Sat Jan 12 03:07:38 2013 From: wuwei23 at gmail.com (alex23) Date: Sat, 12 Jan 2013 00:07:38 -0800 (PST) Subject: Probabilistic unit tests? References: <50ef884e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <693d4bb1-8e1e-4de0-9d4d-8a136ea70ef4@pp8g2000pbb.googlegroups.com> On 11 Jan, 13:34, Steven D'Aprano wrote: > Well, that's not really a task for unit testing. Unit tests, like most > tests, are well suited to deterministic tests, but not really to > probabilistic testing. As far as I know, there aren't really any good > frameworks for probabilistic testing, so you're stuck with inventing your > own. (Possibly on top of unittest.) One approach I've had success with is providing a seed to the RNG, so that the random results are deterministic. From roy at panix.com Sat Jan 12 09:22:32 2013 From: roy at panix.com (Roy Smith) Date: Sat, 12 Jan 2013 09:22:32 -0500 Subject: Probabilistic unit tests? References: <50ef884e$0$30003$c3e8da3$5496439d@news.astraweb.com> <693d4bb1-8e1e-4de0-9d4d-8a136ea70ef4@pp8g2000pbb.googlegroups.com> Message-ID: In article <693d4bb1-8e1e-4de0-9d4d-8a136ea70ef4 at pp8g2000pbb.googlegroups.com>, alex23 wrote: > On 11 Jan, 13:34, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > > Well, that's not really a task for unit testing. Unit tests, like most > > tests, are well suited to deterministic tests, but not really to > > probabilistic testing. As far as I know, there aren't really any good > > frameworks for probabilistic testing, so you're stuck with inventing your > > own. (Possibly on top of unittest.) > > One approach I've had success with is providing a seed to the RNG, so > that the random results are deterministic. Sometimes, a hybrid approach is best. I was once working on some code which had timing-dependent behavior. The input space was so large, there was no way to exhaustively test all conditions. What we did was use a PRNG to drive the test scenarios, seeded with the time. We would print out the seed at the beginning of the test. This let us explore a much larger range of the input space than we could have with hand-written test scenarios. There was also a mode where you could supply your own PRNG seed. So, the typical deal would be to wait for a failure during normal (nightly build) testing, then grab the seed from the test logs and use that to replicate the behavior for further study. From buzzard at invalid.invalid Sat Jan 12 13:08:33 2013 From: buzzard at invalid.invalid (duncan smith) Date: Sat, 12 Jan 2013 18:08:33 +0000 Subject: Probabilistic unit tests? In-Reply-To: <693d4bb1-8e1e-4de0-9d4d-8a136ea70ef4@pp8g2000pbb.googlegroups.com> References: <50ef884e$0$30003$c3e8da3$5496439d@news.astraweb.com> <693d4bb1-8e1e-4de0-9d4d-8a136ea70ef4@pp8g2000pbb.googlegroups.com> Message-ID: <50f1a6a9$0$21754$a8266bb1@newsreader.readnews.com> On 12/01/13 08:07, alex23 wrote: > On 11 Jan, 13:34, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Well, that's not really a task for unit testing. Unit tests, like most >> tests, are well suited to deterministic tests, but not really to >> probabilistic testing. As far as I know, there aren't really any good >> frameworks for probabilistic testing, so you're stuck with inventing your >> own. (Possibly on top of unittest.) > > One approach I've had success with is providing a seed to the RNG, so > that the random results are deterministic. > My ex-boss once instructed to do the same thing to test functions for generating random variates. I used a statistical approach instead. There are often several ways of generating data that follow a particular distribution. If you use a given seed so that you get a deterministic sequence of uniform random variates you will get deterministic outputs for a specific implementation. But if you change the implementation the tests are likely to fail. e.g. To generate a negative exponential variate -ln(U)/lambda or -ln(1-U)/lambda will do the job correctly, but tests for one implementation would fail with the other. So each time you changed the implementation you'd need to change the tests. I think my boss had in mind that I would write the code, seed the RNG, call the function a few times, then use the generated values in the test. That would not even have tested the original implementation. I would have had a test that would only have tested whether the implementation had changed. I would argue, worse than no test at all. If I'd gone to the trouble of manually calculating the expected outputs so that I got valid tests for the original implementation, then I would have had a test that would effectively just serve as a reminder to go through the whole manual calculation process again for any changed implementation. A reasonably general statistical approach is possible. Any hypothesis about generated data that lends itself to statistical testing can be used to generate a sequence of p-values (one for each set of generated values) that can be checked (statistically) for uniformity. This effectively tests the distribution of the test statistic, so is better than simply testing whether tests on generated data pass, say, 95% of the time (for a chosen 5% Type I error rate). Cheers. Duncan From alister.ware at ntlworld.com Fri Jan 11 11:26:20 2013 From: alister.ware at ntlworld.com (Alister) Date: Fri, 11 Jan 2013 16:26:20 GMT Subject: Probabilistic unit tests? References: Message-ID: On Thu, 10 Jan 2013 17:59:05 -0800, Nick Mellor wrote: > Hi, > > I've got a unit test that will usually succeed but sometimes fails. An > occasional failure is expected and fine. It's failing all the time I > want to test for. > > What I want to test is "on average, there are the same number of males > and females in a sample, give or take 2%." > > Here's the unit test code: > import unittest from collections import counter > > sex_count = Counter() > for contact in range(self.binary_check_sample_size): > p = get_record_as_dict() > sex_count[p['Sex']] += 1 > self.assertAlmostEqual(sex_count['male'], > sex_count['female'], delta=sample_size * 2.0 / > 100.0) > > My question is: how would you run an identical test 5 times and pass the > group *as a whole* if only one or two iterations passed the test? > Something like: > > for n in range(5): > # self.assertAlmostEqual(...) > # if test passed: break > else: > self.fail() > > (except that would create 5+1 tests as written!) > > Thanks for any thoughts, > > Best wishes, > > Nick unit test are for testing your code, not checking if input data is in the correct range so unless you are writing a program intended to generate test data I don't see why unit test are appropriate in this case. -- Under capitalism, man exploits man. Under communism, it's just the opposite. -- J.K. Galbraith From steve+comp.lang.python at pearwood.info Fri Jan 11 12:46:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Jan 2013 17:46:31 GMT Subject: Probabilistic unit tests? References: Message-ID: <50f04ff7$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Jan 2013 16:26:20 +0000, Alister wrote: > On Thu, 10 Jan 2013 17:59:05 -0800, Nick Mellor wrote: > >> Hi, >> >> I've got a unit test that will usually succeed but sometimes fails. An >> occasional failure is expected and fine. It's failing all the time I >> want to test for. >> >> What I want to test is "on average, there are the same number of males >> and females in a sample, give or take 2%." [...] > unit test are for testing your code, not checking if input data is in > the correct range so unless you are writing a program intended to > generate test data I don't see why unit test are appropriate in this > case. I don't believe Nick is using unittest to check input data. As I understand it, Nick has a program which generates random values. If his program works correctly, it should generate approximately equal numbers of "male" and "female" values. So he writes a unit test to check that the numbers are roughly equal. This is an appropriate test, although as I already suggested earlier, unit tests are not well suited for non-deterministic testing. -- Steven From buzzard at invalid.invalid Fri Jan 11 13:05:05 2013 From: buzzard at invalid.invalid (duncan smith) Date: Fri, 11 Jan 2013 18:05:05 +0000 Subject: Probabilistic unit tests? In-Reply-To: References: Message-ID: <50f05458$0$13819$a8266bb1@newsreader.readnews.com> On 11/01/13 01:59, Nick Mellor wrote: > Hi, > > I've got a unit test that will usually succeed but sometimes fails. An occasional failure is expected and fine. It's failing all the time I want to test for. > > What I want to test is "on average, there are the same number of males and females in a sample, give or take 2%." > > Here's the unit test code: > import unittest > from collections import counter > > sex_count = Counter() > for contact in range(self.binary_check_sample_size): > p = get_record_as_dict() > sex_count[p['Sex']] += 1 > self.assertAlmostEqual(sex_count['male'], > sex_count['female'], > delta=sample_size * 2.0 / 100.0) > > My question is: how would you run an identical test 5 times and pass the group *as a whole* if only one or two iterations passed the test? Something like: > > for n in range(5): > # self.assertAlmostEqual(...) > # if test passed: break > else: > self.fail() > > (except that would create 5+1 tests as written!) > > Thanks for any thoughts, > > Best wishes, > > Nick > The appropriateness of "give or take 2%" will depend on sample size. e.g. If the proportion of males should be 0.5 and your sample size is small enough this will fail most of the time regardless of whether the proportion is 0.5. What you could do is perform a statistical test. Generally this involves generating a p-value and rejecting the null hypothesis if the p-value is below some chosen threshold (Type I error rate), often taken to be 0.05. Here the null hypothesis would be that the underlying proportion of males is 0.5. A statistical test will incorrectly reject a true null in a proportion of cases equal to the chosen Type I error rate. A test will also fail to reject false nulls a certain proportion of the time (the Type II error rate). The Type II error rate can be reduced by using larger samples. I prefer to generate several samples and test whether the proportion of failures is about equal to the error rate. The above implies that p-values follow a [0,1] uniform density function if the null hypothesis is true. So alternatively you could generate many samples / p-values and test the p-values for uniformity. That is what I generally do: p_values = [] for _ in range(numtests): values = data generated from code to be tested p_values.append(stat_test(values)) test p_values for uniformity The result is still a test that will fail a given proportion of the time. You just have to live with that. Run your test suite several times and check that no one test is "failing" too regularly (more often than the chosen Type I error rate for the test of uniformity). My experience is that any issues generally result in the test of uniformity being consistently rejected (which is why a do that rather than just performing a single test on a single generated data set). In your case you're testing a Binomial proportion and as long as you're generating enough data (you need to take into account any test assumptions / approximations) the observed proportions will be approximately normally distributed. Samples of e.g. 100 would be fine. P-values can be generated from the appropriate normal (http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval), and uniformity can be tested using e.g. the Kolmogorov-Smirnov or Anderson-Darling test (http://www.itl.nist.gov/div898/handbook/eda/section3/eda35g.htm). I'd have thought that something like this also exists somewhere. How do people usually test e.g. functions that generate random variates, or other cases where deterministic tests don't cut it? Duncan From rantingrickjohnson at gmail.com Fri Jan 11 01:01:37 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 10 Jan 2013 22:01:37 -0800 (PST) Subject: PyWart: Module access syntax Message-ID: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> Python's module/package access uses dot notation. mod1.mod2.mod3.modN Like many warts of the language, this wart is not so apparent when first learning the language. The dot seems innocently sufficient, however, in truth it is woefully inadequate! Observe: name1.name2.name3.name4.name5 Can you tell me which names are modules, which are classes, and which are methods/functions? Wait, i know the argument you'll use: """I can decipher from spelling! Modules use all lowercase, classes use initial uppercase, and methods use words_sep_by_underscore. I'm so smart!""" Indeed. But that's only *_IF_* everybody used the same style guide. And as we know many people don't follow the style guide (not to mention the style guide has issues!) And since style is NOT enforced, we suffer the unintuitive syntax nightmare! The solution is obvious by using proper syntax. import lib:gui:tkinter:dialogs.SimpleDialog as Blah You /could/ use two colons: import lib::gui::tkinter::dialogs.SimpleDialog as Blah ...and i think this syntax does help to separate the identifiers more clearly, but since these imports can be quite long, i prefer the single colon myself. From steve+comp.lang.python at pearwood.info Fri Jan 11 11:02:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Jan 2013 16:02:34 GMT Subject: PyWart: Module access syntax References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> Message-ID: <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Jan 2013 22:01:37 -0800, Rick Johnson wrote: > Python's module/package access uses dot notation. > > mod1.mod2.mod3.modN > > Like many warts of the language, this wart is not so apparent when first > learning the language. The dot seems innocently sufficient, however, in > truth it is woefully inadequate! Observe: > > name1.name2.name3.name4.name5 > > Can you tell me which names are modules, which are classes, and which > are methods/functions? Wait, i know the argument you'll use: > > """I can decipher from spelling! Modules use all lowercase, classes > use initial uppercase, and methods use words_sep_by_underscore. I'm so > smart!""" Wrong. My answer is... Who cares? Why do you care which names are modules, classes, etc? This is Python, and duck-typing rules! Today I have: x = mylib.stuff.spam().parrot.speak() where: - mylib is a module - stuff is a separate module imported into mylib - spam is a class - parrot a data attribute - and speak a method. But then tomorrow I re-factor the code and turn: - mylib into a package - stuff into a module of the package - spam into a factory function - parrot into a property - and speak into a dynamically generated static method created using __getattr__. How do I write this new code? Exactly the same as the old code -- no changes are required! x = mylib.stuff.spam().parrot.speak() *It doesn't matter* what kind of entity each of the dotted names represent, so long as they have the expected interface. > The solution is obvious by using proper syntax. Solution to what? You can only have a solution once you have identified a problem. You have not identified a problem. In any case, your suggestion is *not* obvious. > import lib:gui:tkinter:dialogs.SimpleDialog as Blah Which names are packages, modules, classes, methods, functions, or other objects? Why do you have lib:gui but dialogs.SimpleDialog? Is the rule "classes should always be preceded by a dot?" Following this import: import lib:gui how do I access attributes of that module? x = lib:gui:function() perhaps? Now I have to remember which attribute access uses dot operator and which uses colon operator. Does this mean there needs to four new be special methods: __getcolonattribute__ __getcolonattr__ __setcolonattr__ __delcolonattr__ to match the regular dot operator methods __getattribute__ __getattr__ __setattr__ __delattr__ ? Or do you think that the Python compiler should special-case attribute access from modules? > You /could/ use two colons: > > import lib::gui::tkinter::dialogs.SimpleDialog as Blah Before thinking about the syntax, you need to think about the behaviour, identify what actual problem you hope to solve, and how you hope to solve it. Not just throw random syntax around and hope that it's "obvious". -- Steven From rantingrickjohnson at gmail.com Fri Jan 11 23:34:20 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 11 Jan 2013 20:34:20 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> On Friday, 1-11-2013 10:02:34 AM, Steven D'Aprano wrote: > Solution to what? You can only have a solution once you have identified a > problem. You have not identified a problem. In any case, your suggestion > is *not* obvious. The problem is that by using the dot ubiquitously we are obfuscating the path to an identifier. > > import lib:gui:tkinter:dialogs.SimpleDialog as Blah > > Which names are packages, modules, classes, methods, functions, or other > objects? > > Why do you have lib:gui but dialogs.SimpleDialog? Is the rule "classes > should always be preceded by a dot?" No the rules are: * "Colon" must be used to access a "module" (or a package). * "Dot" must be used to access a "module member". In the line "lib:gui:tkinter:dialogs.SimpleDialog", "lib", "gui", "tkinter", and "dialogs" are all packages (or modules: same thing as far as paths are concerned). "SimpleDialog" however is a class, who's identifier is a member of the module "lib:gui:tkinter:dialogs". > Following this import: > > import lib:gui > > how do I access attributes of that module? > > x = lib:gui:function() perhaps? Now I have to remember which attribute > access uses dot operator and which uses colon operator. It's simple: MODULES&PACKAGES use colon, MODULE MEMBERS use dot. How many times must i explain these simple rules? If you don't know which names are modules and which names are members then how could a programmer possibly use the API in an intelligent way Steven? This syntax does not help the programmer much. Well, it can be beneficial to the programmer if he gets a *PathError* because he foolishly tried to instance a module named "simpledialog" when he actually meant to instance the object "simpledialog.SimpleDialog". (notice i did not use the word class!) Traceback (most recent call last): File "", line 1, in dlg = lib:gui:tkinter:dialogs.simpledialog() PathError: name 'simpledialog' is a module NOT a object! But that is not the reason for this syntax Steven, it is just a pleasant side effect. > Does this mean there needs to four new be special methods: > > __getcolonattribute__ > __getcolonattr__ > __setcolonattr__ > __delcolonattr__ Gawd no. getattr, setattr, and delattr will remain unchanged. The only change is how a /path/ to an identifier is "formed". > to match the regular dot operator methods > > __getattribute__ > __getattr__ > __setattr__ > __delattr__ > > ? Or do you think that the Python compiler should special-case attribute > access from modules? There is no "special casing" needed. Python could happily replace all colons in a path with dots and interpret the path internally just as it does today. > Before thinking about the syntax, you need to think about the behaviour, > identify what actual problem you hope to solve, and how you hope to solve > it. Not just throw random syntax around and hope that it's "obvious". *The problem:* ... is readability. The current dot syntax used ubiquitously in paths is not conveying the proper information to the reader, and in-fact obfuscating the code. *Method to solve the problem:* ... by introducing a new syntax that requires all module access to use the colon and all module members to use the dot. *The syntax:* ... is perfect. Of course we could argue over /which/ char to use, but no matter which char prevails, we are gaining explicitness at zero overhead to the programmer because we are replacing one single char(dot) for one single char(colon). The maintainer is the real winner. This is a win-win all around. From rosuav at gmail.com Fri Jan 11 23:40:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Jan 2013 15:40:36 +1100 Subject: PyWart: Module access syntax In-Reply-To: <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson wrote: > *The problem:* > ... is readability. The current dot syntax used ubiquitously in paths is not conveying the proper information to the reader, and in-fact obfuscating the code. Please explain how this is a problem. As Steven said, there is NO useful difference. I don't *care* whether it's a package, a module, or whatever. Module with class with static member? Fine. Package with module with class? Also fine. Imported special object that uses dunder methods to simulate either of the above? What's it matter to me, as long as I get my final result! Syntactic salt is seldom helpful. ChrisA From rantingrickjohnson at gmail.com Sat Jan 12 00:46:36 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 11 Jan 2013 21:46:36 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: <73ecfe98-997a-49bb-a4d7-4fbfbde4277a@googlegroups.com> On Friday, January 11, 2013 10:40:36 PM UTC-6, Chris Angelico wrote: > On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson > > *The problem:* > > ... is readability. The current dot syntax used ubiquitously in paths is not conveying the proper information to the reader, and in-fact obfuscating the code. > > Please explain how this is a problem. What is this importing? "import lib.gui.simpledialog" ...is that the "simpledialog module" or "SimpleDialog object"? Since naming conventions are not ENFORCED, we can NEVER be sure if an identifier is a object or module. And since object definitions (aka: classes) are often placed into a module with the same name, how are we to know? Why should we be forced to open source files to find out a small detail that proper syntax can easily provide? This is a matter of READABILITY, Christopher. It's one or the other (or the status quo): 1. Enforce naming conventions. 2. Enforce path syntax. 3. Continue to obfuscate code. The choice is yours. From rantingrickjohnson at gmail.com Sat Jan 12 00:46:36 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 11 Jan 2013 21:46:36 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: <73ecfe98-997a-49bb-a4d7-4fbfbde4277a@googlegroups.com> On Friday, January 11, 2013 10:40:36 PM UTC-6, Chris Angelico wrote: > On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson > > *The problem:* > > ... is readability. The current dot syntax used ubiquitously in paths is not conveying the proper information to the reader, and in-fact obfuscating the code. > > Please explain how this is a problem. What is this importing? "import lib.gui.simpledialog" ...is that the "simpledialog module" or "SimpleDialog object"? Since naming conventions are not ENFORCED, we can NEVER be sure if an identifier is a object or module. And since object definitions (aka: classes) are often placed into a module with the same name, how are we to know? Why should we be forced to open source files to find out a small detail that proper syntax can easily provide? This is a matter of READABILITY, Christopher. It's one or the other (or the status quo): 1. Enforce naming conventions. 2. Enforce path syntax. 3. Continue to obfuscate code. The choice is yours. From rosuav at gmail.com Sat Jan 12 00:59:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Jan 2013 16:59:31 +1100 Subject: PyWart: Module access syntax In-Reply-To: <73ecfe98-997a-49bb-a4d7-4fbfbde4277a@googlegroups.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <73ecfe98-997a-49bb-a4d7-4fbfbde4277a@googlegroups.com> Message-ID: On Sat, Jan 12, 2013 at 4:46 PM, Rick Johnson wrote: > This is a matter of READABILITY, Christopher. It's one or the other (or the status quo): > > 1. Enforce naming conventions. > 2. Enforce path syntax. > 3. Continue to duck type, like Python is good at. > > The choice is yours. FTFY. ChrisA From steve+comp.lang.python at pearwood.info Sat Jan 12 01:53:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Jan 2013 06:53:27 GMT Subject: PyWart: Module access syntax References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <73ecfe98-997a-49bb-a4d7-4fbfbde4277a@googlegroups.com> Message-ID: <50f10866$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Jan 2013 21:46:36 -0800, Rick Johnson wrote: > On Friday, January 11, 2013 10:40:36 PM UTC-6, Chris Angelico wrote: >> On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson > >> > *The problem:* >> > ... is readability. The current dot syntax used ubiquitously in paths >> > is not conveying the proper information to the reader, and in-fact >> > obfuscating the code. >> >> Please explain how this is a problem. > > > What is this importing? > > "import lib.gui.simpledialog" > > ...is that the "simpledialog module" or "SimpleDialog object"? It has to be the first, because: - you can't import members of modules directly using dot syntax ("import math.cos" will fail) - and it can't be SimpleDialog, because Python is case-sensitive and you wrote simpledialog. But ignoring the import, and just looking at the dotted name: lib.gui.simpledialog who cares what simpledialog happens to be? So long as you know the expected interface (say, "it's a callable object that takes three arguments"), you can use it the same way whether it is a function, a method, a class or something else. The implementation could change, and you need not care. If you actually do care what the type of simpledialog is, you can find out easily: type(lib.gui.simpledialog) -- Steven From dihedral88888 at googlemail.com Sat Jan 12 19:02:26 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 12 Jan 2013 16:02:26 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: <78f555ef-7c2e-4102-8a6a-993a8bbae058@googlegroups.com> Chris Angelico? 2013?1?12????UTC+8??12?40?36???? > On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson > > wrote: > > > *The problem:* > > > ... is readability. The current dot syntax used ubiquitously in paths is not conveying the proper information to the reader, and in-fact obfuscating the code. > > > > Please explain how this is a problem. As Steven said, there is NO > > useful difference. I don't *care* whether it's a package, a module, or > > whatever. Module with class with static member? Fine. Package with > > module with class? Also fine. Imported special object that uses dunder > > methods to simulate either of the above? What's it matter to me, as > > long as I get my final result! > > > > Syntactic salt is seldom helpful. > > > > ChrisA This is somewhat like the following problem. Do we have to argue with people about the tastes of dishes in different restaurants ? Of course, I do because I love to enjoy fine dishes. From dihedral88888 at googlemail.com Sat Jan 12 19:02:26 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 12 Jan 2013 16:02:26 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: <78f555ef-7c2e-4102-8a6a-993a8bbae058@googlegroups.com> Chris Angelico? 2013?1?12????UTC+8??12?40?36???? > On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson > > wrote: > > > *The problem:* > > > ... is readability. The current dot syntax used ubiquitously in paths is not conveying the proper information to the reader, and in-fact obfuscating the code. > > > > Please explain how this is a problem. As Steven said, there is NO > > useful difference. I don't *care* whether it's a package, a module, or > > whatever. Module with class with static member? Fine. Package with > > module with class? Also fine. Imported special object that uses dunder > > methods to simulate either of the above? What's it matter to me, as > > long as I get my final result! > > > > Syntactic salt is seldom helpful. > > > > ChrisA This is somewhat like the following problem. Do we have to argue with people about the tastes of dishes in different restaurants ? Of course, I do because I love to enjoy fine dishes. From jeanmichel at sequans.com Mon Jan 14 13:31:48 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 14 Jan 2013 19:31:48 +0100 (CET) Subject: PyWart: Module access syntax In-Reply-To: <78f555ef-7c2e-4102-8a6a-993a8bbae058@googlegroups.com> Message-ID: <1137408145.3935818.1358188308494.JavaMail.root@sequans.com> > > Please explain how this is a problem. As Steven said, there is NO > > > > useful difference. I don't *care* whether it's a package, a module, > > or > > > > whatever. Module with class with static member? Fine. Package with > > > > module with class? Also fine. Imported special object that uses > > dunder > > > > methods to simulate either of the above? What's it matter to me, as > > > > long as I get my final result! > > > > > > > > Syntactic salt is seldom helpful. > > > > > > > > ChrisA > This is somewhat like the following problem. > > Do we have to argue with people about the tastes > of dishes in different restaurants ? > > Of course, I do because I love to enjoy fine dishes. Is there any way to report a bug to that bot ? I don't know how it end up thinking we where talking about dishes. I hope it won't count this reply as a successful bot post. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From steve+comp.lang.python at pearwood.info Sat Jan 12 01:45:03 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Jan 2013 06:45:03 GMT Subject: PyWart: Module access syntax References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Jan 2013 20:34:20 -0800, Rick Johnson wrote: >> > import lib:gui:tkinter:dialogs.SimpleDialog as Blah >> >> Which names are packages, modules, classes, methods, functions, or >> other objects? >> >> Why do you have lib:gui but dialogs.SimpleDialog? Is the rule "classes >> should always be preceded by a dot?" > > No the rules are: > * "Colon" must be used to access a "module" (or a package). > * "Dot" must be used to access a "module member". So what do you do for, say, os.path? According to the first rule, you must write it as os:path because path is a module; according to the second rule, you must write it as os.path because path is a member of os. So which rule wins? If I do this: import math import string math.string = string is that legal, or do I have to write "math:string = string"? Suppose I do this: import random if random.random() < 0.5: math.string = "NOBODY expects the Spanish Inquisition!" else: math.string = string # assuming this actually is allowed How do I access the string member? try: print math.string # only works if string is a str object except SomeException: print math:string # only works if string is a module object That would suck *and* blow at the same time. I don't need to know the type of any other member object in order to look it up, why should I have to care whether it is a module? Now, suppose I then do this: class Blob: pass blob = Blob() blob.math = math # or should that be blob:math ? Now do I have to write this? blob.math:string.letters (assuming that math:string is a module, not a str object). [...] > It's simple: MODULES&PACKAGES use colon, MODULE MEMBERS use dot. How > many times must i explain these simple rules? At the time I asked the question, you hadn't explained it *at all*. [...] > This syntax does not help the programmer much. Well, it can be > beneficial to the programmer if he gets a *PathError* because he > foolishly tried to instance a module named "simpledialog" when he > actually meant to instance the object "simpledialog.SimpleDialog". > (notice i did not use the word class!) "Instance" is a noun. The verb you are looking for is "instantiate". > Traceback (most recent call last): > File "", line 1, in > dlg = lib:gui:tkinter:dialogs.simpledialog() > PathError: name 'simpledialog' is a module NOT a object! Of course it is an object. *Everything* in Python is an object. Modules are objects. Strings are objects. Types and classes are objects. None is an object. Metaclasses are objects. Properties are objects. Exceptions are objects. Have I made it clear yet? [...] > *The problem:* > ... is readability. The current dot syntax used ubiquitously in paths is > not conveying the proper information to the reader, and in-fact > obfuscating the code. So you say. I think you are caring too much about the type of members and not enough about what interface they provide. Why do you care if I grab module.my_singleton_object and replace my_singleton_object with a module? Modules are singletons in Python, in the sense that every[1] time you import a module you get the same object. Using modules as members for their singleton properties, not for their importability, is a common technique. With your proposal, I need to know whether a member is a module, or any other type, before I can access it. That is a really shitty design. Instead of having one syntax for *all* attribute access, now you have two, and we have to care whether a member is a module or not, which we never did before. Worse, you couple the syntax to implementation: if I use a module as a singleton, I need to use one syntax; if I use a custom type as a singleton, I have to use different syntax. Whichever choice I make *today*, if the implementation changes, the required syntax changes and my code will break. [1] Well, almost. There are ways to accidentally or deliberately confuse the import machinery. -- Steven From rantingrickjohnson at gmail.com Mon Jan 14 00:22:57 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 13 Jan 2013 21:22:57 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, January 12, 2013 12:45:03 AM UTC-6, Steven D'Aprano wrote: > On Fri, 11 Jan 2013 20:34:20 -0800, Rick Johnson wrote: > > [...] > So what do you do for, say, os.path? According to the first rule, you > must write it as os:path because path is a module; according to the > second rule, you must write it as os.path because path is a member of os. > So which rule wins? Since "path" is an identifier in the module "os" that points to a system specific module (which is loaded at run-time), you would access os.path just as you do today; using the dot. No changes here. Next! > If I do this: > > import math > import string > math.string = string > > is that legal, or do I have to write "math:string = string"? No. You are assigning the module "string" to a member variable of the module "math" so you use the dot. No changes here. Next! > Suppose I do this: *rolls-eyes* > import random > if random.random() < 0.5: > math.string = "NOBODY expects the Spanish Inquisition!" > else: > math.string = string # assuming this actually is allowed ...first allow me to remove all the cruft so you can ask this next iteration of the _same_ hypothetical question succinctly. if some_condition: math.string = "" else math.string = string > How do I access the string member? You access the member variable named "string" (that points to the "string module") as you would ANY _member_, using the dot. Next! > try: > print math.string # only works if string is a str object > except SomeException: > print math:string # only works if string is a module object EARTH TO STEVEN: You are sadly misunderstanding my suggested syntax and frankly making a complete fool of yourself. I cannot allow this to go on any longer. > That would suck *and* blow at the same time. Yes it would, but that's only _IF_ my suggested syntax works in the backwards way you suggest. Lucky for us, i'm designing this feature. > I don't need to know the > type of any other member object in order to look it up, why should I have > to care whether it is a module? I said it before and i'll say it again: If you don't know if your calls are accessing module space or object space (be it instanced object or static object), then you are sadly informed and shooting from the hip -- you're going to shoot your toes off! But that is not the worst part, no. The worst part is that by using only the dot, your code is superfluously obfuscated. That is a crime to me. A crime punishable by the syntax error. I condemn you to tortuous syntax errors until you change your rebellious ways. > Now, suppose I then do this: > > class Blob: pass > > blob = Blob() > blob.math = math # or should that be blob:math ? Oh lord. Has anyone noticed that every one of these hypotheticals is presenting the very same question using different circumstances. Do you think 1+1 will sometimes equal 2 Steven? You are missing the point of this syntax. The colon is to access MODULE NAMESPACE. The dot is to access MODULE MEMBERS. A module CAN BE another module's MEMBER. You are also unable to grasp this simple logical fact: Once you arrive at /any/ MODULE and you start accessing MEMBERS, you will *_ALWAYS_* find members from that point downwards. Observe: In module "lib:foo": import string import math import math as _math from math import ceil # string.math = math string.math.var="var" In __main__ (test 1): import lib:foo import lib:foo as foo # Test 1 print lib:foo.string.math.var -> "var" # Test 2 print foo.string.math.var -> "var" # Test 3 foo.string.math.ceil(.1) -> 1.0 # Test 4: foo.ceil(.1) -> 1.0 > [...] > > > Traceback (most recent call last): > > File "", line 1, in > > dlg = lib:gui:tkinter:dialogs.simpledialog() > > > Of course it is an object. *Everything* in Python is an object. And i agree! ("it" being "modules" in this case) > Modules > are objects. Strings are objects. Types and classes are objects. Wait, "classes" are NOT objects. Classes are structured code that DEFINE an object. You see, this is exactly why we need to stop using the word "class" to describe an "object definition". Your ability to grasp _what_ an object definition *IS* is due to poor terminology. > None is > an object. Metaclasses are objects. Properties are objects. Exceptions > are objects. Have I made it clear yet? Yes, but your point is invalid. I was comparing a module to an object. And even though EVERYTHING in Python is technically an object, you should have inferred the meaning of my comparison, but alas, you cannot even infer my syntax! > > *The problem:* > > ... is readability. The current dot syntax used ubiquitously in paths is > > not conveying the proper information to the reader, and in-fact > > obfuscating the code. > > So you say. I think you are caring too much about the type of members and > not enough about what interface they provide. Why do you care if I grab > module.my_singleton_object and replace my_singleton_object with a module? Because modules and objects are not the same and someone who is reading the source code NEEDS to know which "path members" are /modules/ and which "path members" are /objects/. And he needs to know that very important information WITHOUT opening source files to find out. Look, we cannot provide /every/ possible detail about an object via syntax alone, HOWEVER, here we have a golden opportunity to provide one more piece of that puzzle without any negative trade-offs. Oh yes, *rolls-eyes*, the programmer will need to be sure he places a colon between modules. Which means a programmer will need to know which path members are modules and which are objects... But are you actually telling me that you're unable to remember which objects you are accessing are modules and which are members? And if you cannot, you /could/ resolve the conflict much easier yourself than a reader can resolve the conflict -- Why? because you are closer to the code structure. And why are you closer to the code structure? BECAUSE YOU WROTE IT! > Modules are singletons in Python, in the sense that every[1] time you > import a module you get the same object. Using modules as members for > their singleton properties, not for their importability, is a common > technique. With your proposal, I need to know whether a member is a > module, or any other type, before I can access it. WRONG! What you need to do is to read my proposal again and try to comprehend it before going off on these nonsensical tirades. > That is a really > shitty design. Instead of having one syntax for *all* attribute access, > now you have two, and we have to care whether a member is a module or > not, which we never did before. Are you serious? You are pissing and moaning about keeping up with TWO types and any /real/ programmer has to corral many *many* types in one program? We not only have to care if a member is a module or not Steven, we have to care whether a member is a float, or an integer, or a string, or a tuple, or a complex, or an iterator, or a range, or a list, or a set, or a frozenset, or a dict, or a ordereddict or a function, or an object (as in: "user defined object") or blah, blah, blah. Your argument is nothing more than BS. You thought you could fool me with sleight of hand. Nice try, but you lose. Better luck next time. py> currentTroll.vanquish() py> trollist.next() From steve+comp.lang.python at pearwood.info Mon Jan 14 12:34:56 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2013 17:34:56 GMT Subject: PyWart: Module access syntax References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50f441c0$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Jan 2013 21:22:57 -0800, Rick Johnson wrote: > On Saturday, January 12, 2013 12:45:03 AM UTC-6, Steven D'Aprano wrote: >> On Fri, 11 Jan 2013 20:34:20 -0800, Rick Johnson wrote: >> > [...] >> So what do you do for, say, os.path? According to the first rule, you >> must write it as os:path because path is a module; according to the >> second rule, you must write it as os.path because path is a member of >> os. So which rule wins? > > Since "path" is an identifier in the module "os" that points to a system > specific module (which is loaded at run-time), you would access os.path > just as you do today; using the dot. No changes here. Next! Here you say that os.path will not change. But later in your post, you say: > the programmer will need to be sure he places a colon > between modules. Which means a programmer will need to know which path > members are modules and which are objects Since both os and path are modules, you here say that they need a colon between them. This contradicts the above when you say the syntax for os.path won't change. If even you don't understand your own proposal, how do you expect anyone else to understand it? Perhaps you should start by explaining, unambiguously and IN FULL, under what circumstances the programmer will need to use your : syntax. To start: os.path or os:path json.scanner or json:scanner > I said it before and i'll say it again: If you don't know if your calls > are accessing module space or object space (be it instanced object or > static object), then you are sadly informed "Sadly informed"? Dr Freud called, he wants his slip back. Modules are objects, and there is no difference between module space and object space, except that Python provides a convenience syntax for members of the current module. Modules are instances of a class, just like ints, strings, lists, and everything else. py> from types import ModuleType py> type(ModuleType) is type(int) True py> hasattr(os, '__dict__') True [...] > Wait, "classes" are NOT objects. They certainly are. Classes are created at runtime, they have a type -- the class of a class is the metaclass. You can even customize class behaviour with metaclass programming. Perhaps you are thinking about some other language, like Java, which fails to have first-class classes (pun intended). -- Steven From rantingrickjohnson at gmail.com Tue Jan 15 02:07:13 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 14 Jan 2013 23:07:13 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: <50f441c0$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> <50f441c0$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, January 14, 2013 11:34:56 AM UTC-6, Steven D'Aprano wrote: > Since both os and path are modules, you here say that they need a colon > between them. This contradicts the above when you say the syntax for > os.path won't change. But you forgot the rule about accessing module members with the dot :) > If even you don't understand your own proposal, how do you expect anyone > else to understand it? > > Perhaps you should start by explaining, unambiguously and IN FULL, under > what circumstances the programmer will need to use your : syntax. I will admit i may have confused a few of you (and myself) since i overused the word "module" when i really meant "package". pkg1:pkg2:pkgN.member1.member2.memberN From ian.g.kelly at gmail.com Mon Jan 14 13:51:50 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Jan 2013 11:51:50 -0700 Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 13, 2013 at 10:22 PM, Rick Johnson wrote: > You are missing the point of this syntax. The colon is to access MODULE NAMESPACE. The dot is to access MODULE MEMBERS. A module CAN BE another module's MEMBER. > > You are also unable to grasp this simple logical fact: Once you arrive at /any/ MODULE and you start accessing MEMBERS, you will *_ALWAYS_* find members from that point downwards. If you want us to understand the syntax, then you need to define precisely what you mean by these terms. In what situation does a module have a dotted/coloned path without being a member of another module? Any time you import a.b, the import mechanism finds and loads module b and adds it *as a member* to module a. It follows that a module accessible by a module path is *always* a member of another module. By the above rule, then it would seem that the dot would always be used, and the colon never. I think the distinction you are trying to make here is based upon the submodule's actual source location on the disk. If you have a package folder A which contains a file B.py, then you would access that as A:B, correct? If on the other hand you have a module A.py or package A/__init__.py that loads a module from some other location and then stores it in the A module with the name "B", then that would be "A.B", correct? If I have that right, then the problem with this is that it breaks the virtualization and encapsulation of Python's package structure. When I import os.path, I don't have to know or care how the submodule relationship is implemented, whether it's a simple module in a package or something more complicated. All I need to know is that path is a submodule of os. What you're asking for is that I have to type either "os.path" or "os:path" depending on an implementation detail of the module structure, and if that implementation detail ever changes, then my code breaks. > Because modules and objects are not the same and someone who is reading the source code NEEDS to know which "path members" are /modules/ and which "path members" are /objects/. And he needs to know that very important information WITHOUT opening source files to find out. Why does anybody reading the source code need to know this? We're talking about simple namespaces here. Nobody reading the source needs to care whether those namespaces are implemented as modules or some other type of object. The only substantive difference between the two is whether you can expect to be able to import them directly. If you need to know that, read the documentation. If they're documented as modules, then you can import them. Otherwise, make no such assumption, because even if it works now, that could change later. If we're *not* talking about simple namespaces, then it should be very obvious that they are not modules based upon the fact that the code uses them in ways that modules are not normally used for. From ian.g.kelly at gmail.com Mon Jan 14 14:04:37 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Jan 2013 12:04:37 -0700 Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 14, 2013 at 11:51 AM, Ian Kelly wrote: >> Because modules and objects are not the same and someone who is reading the source code NEEDS to know which "path members" are /modules/ and which "path members" are /objects/. And he needs to know that very important information WITHOUT opening source files to find out. What's more, if the purpose of the syntax is to distinguish modules from non-modules, then the syntax "os.path" (which you have stated would not change) would be misleading, because the "path" part is in fact a module. Your proposed syntax fails to even achieve its stated goal. From darcy at druid.net Mon Jan 14 14:35:40 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 14 Jan 2013 14:35:40 -0500 Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130114143540.35404db7@dilbert> On Mon, 14 Jan 2013 11:51:50 -0700 Ian Kelly wrote: > On Sun, Jan 13, 2013 at 10:22 PM, Rick Johnson > wrote: ...Whatever > If you want us to understand the syntax, then you need to define If you are going to feed the trolls can I please ask that you Cc them or send to them and Cc the list? That way those of us who filter out the trolls can filter out the responses to them as well. Thanks for understanding. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From ian.g.kelly at gmail.com Mon Jan 14 15:38:29 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Jan 2013 13:38:29 -0700 Subject: PyWart: Module access syntax In-Reply-To: <20130114143540.35404db7@dilbert> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> <20130114143540.35404db7@dilbert> Message-ID: On Mon, Jan 14, 2013 at 12:35 PM, D'Arcy J.M. Cain wrote: > On Mon, 14 Jan 2013 11:51:50 -0700 > Ian Kelly wrote: >> On Sun, Jan 13, 2013 at 10:22 PM, Rick Johnson >> wrote: > ...Whatever > >> If you want us to understand the syntax, then you need to define > > If you are going to feed the trolls can I please ask that you Cc them > or send to them and Cc the list? That way those of us who filter out the > trolls can filter out the responses to them as well. Sorry about that. I actually have him filtered out too, but then I see other people's responses and I get sucked in. From rantingrickjohnson at gmail.com Tue Jan 15 02:49:25 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 14 Jan 2013 23:49:25 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <913c3f21-5449-4b2c-9fb5-c3520acb3a9d@googlegroups.com> On Monday, January 14, 2013 12:51:50 PM UTC-6, Ian wrote: > I think the distinction you are trying to make here is based upon the > submodule's actual source location on the disk. If you have a package > folder A which contains a file B.py, then you would access that as > A:B, correct? If on the other hand you have a module A.py or package > A/__init__.py that loads a module from some other location and then > stores it in the A module with the name "B", then that would be "A.B", > correct? Yes! The colon accesses package space (the "top-level namespace" if you will). The dot accesses members. > If I have that right, then the problem with this is that it breaks the > virtualization and encapsulation of Python's package structure. When > I import os.path, I don't have to know or care how the submodule > relationship is implemented, whether it's a simple module in a package > or something more complicated. All I need to know is that path is a > submodule of os. Well one the main problem with packages is that we have no rules for defining them. I think of packages as namespaces. And as such they should have public members, private members, and shared members. The author of ANY package should place the /public members/ into the __init__ file *via import* for access by the user. The user should NEVER access package sub-modules directly! > What you're asking for is that I have to type either > "os.path" or "os:path" depending on an implementation detail of the > module structure, and if that implementation detail ever changes, then > my code breaks. You keep using os.path as an example. path should be it's OWN module living in some package, and NOT a member of os. So you would import them separately. But if insist on keeping "path" in "os", fine. Even IF os where a package, the syntax would still be the same because there is only one level of package ("os") before you get to the member "path". Do you understand? os.path.whatever However, if "os" lived in a package named "lib" you would access via: lib:os.path See, the colon designates package namespace. But these modules are bad examples because they do not require deep nesting of packages. GUI libraries however are a great example. That is why i posted the hypothetical path: lib:gui:tk:dialogs.SimpleDialog Here are few more to get a feel: lib:gui:tk:dialogs.MessageBox lib:gui:tk:dialogs.FileDlg lib:gui:tk.constants lib:gui:tk:widgets:Button lib:gui:tk:widgets:XXX If we build consistent packages and use a consistent syntax to access them, our code will be self documenting. However, I don't think the Python devs take the subject of packages very seriously. For example, look at Tkinter in Py3000, we still have a single monolithic "tkinter" module with every possible widget class stuffed into it, along with ABCs, and variables classes, and outdated functions, and the kitchen sink! All they did was to move and rename the dialog and font classes and then patted themselves on the back. This is NOT how you structure a package! We need to use a structured package approach to tame this wild beast called Tkinter. Look, maybe nobody has the time to deal with this module, so if you need some help, then feel free to ask for my assistance. All Guido has to do is send me a private email and say: """ Hello Rick! Your ideas for packaging of Tkinter are interesting, and i would like for you to send a patch over to {0} for immediate consideration. Thanks GvR """.format(destination) But if he cannot even care enough about Python to send a single paragraph email, or he's holding a grudge because i am critical of "some" parts of the language, well then, don't be expecting any help from me! I would not bother to criticize if i did not think Python was the best base for which to build a great language. Nobody can build a perfect language, Guido included. You give it you best shot and then you tweak and tinker as new unforeseen problems arise. Sometimes you have no choice but to break backwards compatibility. These are all necessary stepping stones in a languages evolution. This snake needs to shed an old skin so the new skin can grow. From rantingrickjohnson at gmail.com Tue Jan 15 02:49:25 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 14 Jan 2013 23:49:25 -0800 (PST) Subject: PyWart: Module access syntax In-Reply-To: References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <913c3f21-5449-4b2c-9fb5-c3520acb3a9d@googlegroups.com> On Monday, January 14, 2013 12:51:50 PM UTC-6, Ian wrote: > I think the distinction you are trying to make here is based upon the > submodule's actual source location on the disk. If you have a package > folder A which contains a file B.py, then you would access that as > A:B, correct? If on the other hand you have a module A.py or package > A/__init__.py that loads a module from some other location and then > stores it in the A module with the name "B", then that would be "A.B", > correct? Yes! The colon accesses package space (the "top-level namespace" if you will). The dot accesses members. > If I have that right, then the problem with this is that it breaks the > virtualization and encapsulation of Python's package structure. When > I import os.path, I don't have to know or care how the submodule > relationship is implemented, whether it's a simple module in a package > or something more complicated. All I need to know is that path is a > submodule of os. Well one the main problem with packages is that we have no rules for defining them. I think of packages as namespaces. And as such they should have public members, private members, and shared members. The author of ANY package should place the /public members/ into the __init__ file *via import* for access by the user. The user should NEVER access package sub-modules directly! > What you're asking for is that I have to type either > "os.path" or "os:path" depending on an implementation detail of the > module structure, and if that implementation detail ever changes, then > my code breaks. You keep using os.path as an example. path should be it's OWN module living in some package, and NOT a member of os. So you would import them separately. But if insist on keeping "path" in "os", fine. Even IF os where a package, the syntax would still be the same because there is only one level of package ("os") before you get to the member "path". Do you understand? os.path.whatever However, if "os" lived in a package named "lib" you would access via: lib:os.path See, the colon designates package namespace. But these modules are bad examples because they do not require deep nesting of packages. GUI libraries however are a great example. That is why i posted the hypothetical path: lib:gui:tk:dialogs.SimpleDialog Here are few more to get a feel: lib:gui:tk:dialogs.MessageBox lib:gui:tk:dialogs.FileDlg lib:gui:tk.constants lib:gui:tk:widgets:Button lib:gui:tk:widgets:XXX If we build consistent packages and use a consistent syntax to access them, our code will be self documenting. However, I don't think the Python devs take the subject of packages very seriously. For example, look at Tkinter in Py3000, we still have a single monolithic "tkinter" module with every possible widget class stuffed into it, along with ABCs, and variables classes, and outdated functions, and the kitchen sink! All they did was to move and rename the dialog and font classes and then patted themselves on the back. This is NOT how you structure a package! We need to use a structured package approach to tame this wild beast called Tkinter. Look, maybe nobody has the time to deal with this module, so if you need some help, then feel free to ask for my assistance. All Guido has to do is send me a private email and say: """ Hello Rick! Your ideas for packaging of Tkinter are interesting, and i would like for you to send a patch over to {0} for immediate consideration. Thanks GvR """.format(destination) But if he cannot even care enough about Python to send a single paragraph email, or he's holding a grudge because i am critical of "some" parts of the language, well then, don't be expecting any help from me! I would not bother to criticize if i did not think Python was the best base for which to build a great language. Nobody can build a perfect language, Guido included. You give it you best shot and then you tweak and tinker as new unforeseen problems arise. Sometimes you have no choice but to break backwards compatibility. These are all necessary stepping stones in a languages evolution. This snake needs to shed an old skin so the new skin can grow. From rosuav at gmail.com Tue Jan 15 03:08:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jan 2013 19:08:25 +1100 Subject: PyWart: Module access syntax In-Reply-To: <913c3f21-5449-4b2c-9fb5-c3520acb3a9d@googlegroups.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> <50f1066f$0$30003$c3e8da3$5496439d@news.astraweb.com> <913c3f21-5449-4b2c-9fb5-c3520acb3a9d@googlegroups.com> Message-ID: On Tue, Jan 15, 2013 at 6:49 PM, Rick Johnson wrote: > Look, maybe nobody has the time to deal with this module, so if you need some help, then feel free to ask for my assistance. All Guido has to do is send me a private email and say: > > """ Hello Rick! Your ideas for packaging of Tkinter are interesting, and i would like for you to send a patch over to {0} for immediate consideration. Thanks GvR """.format(destination) Python's open source. Grab the source, do it, and post! Consider yourself preemptively invited. I'm not kidding. You don't need to wait for Guido's invitation to do something. Just get in there, do something, and (preferably) show an upgrade path from "current status" to "proposed status" - which might involve a translation script similar to 2to3 - and people WILL take notice. ChrisA From ian.g.kelly at gmail.com Sat Jan 12 01:55:40 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Jan 2013 23:55:40 -0700 Subject: PyWart: Module access syntax In-Reply-To: <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: On Fri, Jan 11, 2013 at 9:34 PM, Rick Johnson wrote: > No the rules are: > * "Colon" must be used to access a "module" (or a package). > * "Dot" must be used to access a "module member". What about module a that does not natively contain module b, but imports it as a member like so? a.py: import b Must this be accessed as a:b or a.b? What about a module that is referenced by some other object that is not a module? Should it be "my_object.pickle_module" or "my_object:pickle_module"? > It's simple: MODULES&PACKAGES use colon, MODULE MEMBERS use dot. How many times must i explain these simple rules? Since you didn't actually explain them at all in your initial post, I would have to say that once is enough. > If you don't know which names are modules and which names are members then how could a programmer possibly use the API in an intelligent way Steven? You might start by reading the documentation. > This syntax does not help the programmer much. Well, it can be beneficial to the programmer if he gets a *PathError* because he foolishly tried to instance a module named "simpledialog" when he actually meant to instance the object "simpledialog.SimpleDialog". (notice i did not use the word class!) The problem here is bad naming on the part of the library designer, not bad syntax. Why is SimpleDialog confusingly contained in a module also named simpledialog? This is not Java; there is no absurd requirement of one class per file. A clearer path to SimpleDialog would just be "lib.gui.tkinter.dialogs.SimpleDialog". > Traceback (most recent call last): > File "", line 1, in > dlg = lib:gui:tkinter:dialogs.simpledialog() > PathError: name 'simpledialog' is a module NOT a object! See, here is the thing that seems to be eluding you. In Python, modules *are* objects. You can bind names to them, just like any other object. You can add them to collections. You can introspect them. Hell, you can even subclass ModuleType and create modules that can be called or multiplied or iterated over or any crazy thing you can think of. Your : syntax is trying to treat modules as being somehow special, but the fact is that they're *not* special, which is why I think it's a bad idea. >> Does this mean there needs to four new be special methods: >> >> __getcolonattribute__ >> __getcolonattr__ >> __setcolonattr__ >> __delcolonattr__ > > Gawd no. getattr, setattr, and delattr will remain unchanged. The only change is how a /path/ to an identifier is "formed". Then how is ModuleType.__getattr__ supposed to know whether to raise a "PathError" or not, after it determines whether the requested object turned out to be a module or not? It has no way of knowing whether it was invoked by '.' or by ':' or by getattr or by direct invocation. Or are you instead proposing a new bytecode "LOAD_COLON_ATTR" to complement "LOAD_ATTR", and that every single occurrence of LOAD_ATTR in every program would then have to check whether the loaded object turned out to be a module and whether the object it was loaded from also happened to be a module, all just to raise an exception in that case instead of just giving the programmer what he wants? From wuwei23 at gmail.com Sat Jan 12 02:36:43 2013 From: wuwei23 at gmail.com (alex23) Date: Fri, 11 Jan 2013 23:36:43 -0800 (PST) Subject: PyWart: Module access syntax References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> Message-ID: <3e6681dc-b5e3-45b5-b097-595f9e9479d8@y5g2000pbi.googlegroups.com> On 12 Jan, 14:34, Rick Johnson wrote: > If you don't know which names are modules and which names are members > then how could a programmer possibly use the API in an intelligent way Your initial argument is that with import's current dot notation, it's not obvious which is a module or not without accessing the documentation. You then say it's necessary to know which is which in order to use your suggested dot/colon notation. So what are you trying to achieve here? Your 'solution' requires someone to look up the documentation and know what is what, whereas the current approach _doesn't_. Anything can be imported into the current scope, and interrogated there without recourse to documentation. Your approach places onerous requirements on everyone just to satisfy some arbitrary rule-set you've pulled out of your rectum. It's not up to _my_ code to identify how _supporting libraries_ are structured. It just wants to import and use them. Which is, you know, the pragmatic, get-things-done-over-endless-wanking-on-the-mailing- list approach that Python is famous for. You're trolling again, plain & simple. From nicholas.cole at gmail.com Sat Jan 12 07:16:20 2013 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sat, 12 Jan 2013 12:16:20 +0000 Subject: PyWart: Module access syntax In-Reply-To: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> Message-ID: On Fri, Jan 11, 2013 at 6:01 AM, Rick Johnson wrote: > > Python's module/package access uses dot notation. > > mod1.mod2.mod3.modN > > Like many warts of the language, this wart is not so apparent when first > learning the language. The dot seems innocently sufficient, however, in > truth it is woefully inadequate! Observe: > > name1.name2.name3.name4.name5 > > I find it reassuring to have these kinds of questions on the list, because they actually remind me how brilliantly designed Python is. As the user of a module I shouldn't care about the internal arrangement of objects and files. I don't care. More than that, as the writer of a module I should be free to refactor the internals of a module without breaking existing code. There is absolutely nothing wrong at all with the syntax. In fact, it's fantastic. N. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrickjohnson at gmail.com Fri Jan 11 01:13:26 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 10 Jan 2013 22:13:26 -0800 (PST) Subject: PyWart: Import resolution order Message-ID: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Python's import resolution order is terrible.[1] The fact that Python looks in the stdlib _first_ is not a good idea. It would seem more intuitive for a custom "math" module (living in the current directory) to /override/ the stlib "math" module. The proper order is as follows: 1. Current package or directory 2. stdlib 3. under the bed 4. who cares at this point Look, if you want to keep you foolish imports starting from the stdlib, fine, just create a switch so we can change it to "package/directory" if we like. If /only/ the Python gods had placed all stdlib modules in a package named, i don't know, "lib" then none of this would be an issue. You could happily have a stdlib::math and a mylib::math, and when you import either module your code will reflect that path explicitly. Hmm, this last sentence reminded me of something??? Oh yes -> "Explicit is better than implicit". [1]: Yes, yes, i know about sys.path.insert. *puke*! From rosuav at gmail.com Fri Jan 11 01:30:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Jan 2013 17:30:27 +1100 Subject: PyWart: Import resolution order In-Reply-To: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Message-ID: On Fri, Jan 11, 2013 at 5:13 PM, Rick Johnson wrote: > The fact that Python looks in the stdlib _first_ is not a good idea. It would seem more intuitive for a custom "math" module (living in the current directory) to /override/ the stlib "math" module. The proper order is as follows: > > 1. Current package or directory > 2. stdlib > 3. under the bed > 4. who cares at this point Why is it better to import from the current directory first? Windows has that policy for executable commands; Unix, on the other hand, requires that you put an explicit path for anything that isn't in the standard search path. Which of these options is the more likely to produce security holes and/or unexpected behaviour? Welcome back to the list, Rick. Got any demonstrable code for Python 4000 yet? ChrisA From tjreedy at udel.edu Fri Jan 11 08:35:37 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 Jan 2013 08:35:37 -0500 Subject: PyWart: Import resolution order In-Reply-To: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Message-ID: On 1/11/2013 1:13 AM, Rick Johnson wrote: > > Python's import resolution order is terrible.[1] > > The fact that Python looks in the stdlib _first_ is not a good idea. And the fact is that it does not do so. The order depends on sys.path, and '' is the first entry. > It would seem more intuitive for a custom "math" module (living in > the current directory) to /override/ the stlib "math" module. Try it. This is a nuisance though, when not intended. Someone writes a random.py, and a year later in the same directory, an unrelated hopscotch.py, which tries to import random.exponential. The import fails and they post here, having forgotten about their own random.py, which does not have such a function. Posts like this happen a few times a year. -- Terry Jan Reedy From torriem at gmail.com Fri Jan 11 12:53:40 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 11 Jan 2013 10:53:40 -0700 Subject: PyWart: Import resolution order In-Reply-To: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Message-ID: <50F051A4.8090106@gmail.com> On 01/10/2013 11:13 PM, Rick Johnson wrote: > > Python's import resolution order is terrible.[1] > > The fact that Python looks in the stdlib _first_ is not a good idea. Whether or not the default behavior is desirable or not, sys.path is set by default to look in the current directory first on any Python distribution I have looked at. As Terry says, this fact causes a lot of problems for newbies who accidentally override standard library modules with their own python files and chaos ensues. If your python installation does not search the current directory first, then you must have changed sys.path. From rantingrickjohnson at gmail.com Fri Jan 11 23:50:34 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 11 Jan 2013 20:50:34 -0800 (PST) Subject: PyWart: Import resolution order In-Reply-To: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Message-ID: <11b267fb-3a3b-4ccf-8f46-a660cea69665@googlegroups.com> On Friday, January 11, 2013 7:35:37 AM UTC-6, Terry Reedy wrote: > On 1/11/2013 1:13 AM, Rick Johnson wrote: > > The fact that Python looks in the stdlib _first_ is not a good idea. > > And the fact is that it does not do so. The order depends on sys.path, > and '' is the first entry. > > > It would seem more intuitive for a custom "math" module (living in > > the current directory) to /override/ the stlib "math" module. > > This is a nuisance though, when not intended. Someone writes a > random.py, and a year later in the same directory, an unrelated > hopscotch.py, which tries to import random.exponential. The import fails > and they post here, having forgotten about their own random.py, which > does not have such a function. Posts like this happen a few times a year. That's why i also mentioned the failure of Python to wrap stdlib modules in a package. If we would protect all built-in modules by placing them in a package (lib or py) then this problem would never happen. Of course many people will piss and moan about the extra typing. I say, you have a choice: a few extra chars or multitudes of extra headaches -- I choose the first option. Since more time is spent /maintaining/ code bases than /writing/ them, the explicit path is always the correct path to choose. Anyone who says otherwise is either careless or selfish (aka: seeking job security). From wuwei23 at gmail.com Sat Jan 12 02:44:21 2013 From: wuwei23 at gmail.com (alex23) Date: Fri, 11 Jan 2013 23:44:21 -0800 (PST) Subject: PyWart: Import resolution order References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> <11b267fb-3a3b-4ccf-8f46-a660cea69665@googlegroups.com> Message-ID: <6415cbd4-0b6f-4703-a304-725590576807@po6g2000pbb.googlegroups.com> On 12 Jan, 14:50, Rick Johnson wrote: > Of course many people will piss and moan about the extra typing. You just ignored the fact that your original claim was incorrect and kept going on with your rant anyway. > Since more time is spent /maintaining/ code bases than /writing/ them In your case, more time is actually spent on insisting _other_ people maintain code bases. Everyone: PLEASE STOP FEEDING THE TROLL From rantingrickjohnson at gmail.com Sat Jan 12 00:28:49 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 11 Jan 2013 21:28:49 -0800 (PST) Subject: PyWart: Import resolution order In-Reply-To: References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Message-ID: <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: > Why is it better to import from the current directory first? Opps. I was not explicit enough with my explanation :). I meant, "look in the current directory FIRST when in a package". Since many times (most all times) packages will contain many sub-modules that need to be imported into the package's main.py module, and sometimes these modules will have the same name as a stdlib module, then looking in the package FIRST makes sense. But the real solution is not to change the default resolution order. The real solution is to wrap all builtin modules into a package and use full paths to access every module. But wait, i have an even better idea... read below! > Windows > has that policy for executable commands; Unix, on the other hand, > requires that you put an explicit path for anything that isn't in the > standard search path. Which of these options is the more likely to > produce security holes and/or unexpected behaviour? I prefer the latter of course :). I think if python where *strict* about full paths for non-builtins, then we would be in a better place. But there is an even better solution! Force all python users to wrap THEIR modules in a toplevel package. Maybe even create the package for them. YES!. Call it "lib". Any "naked" modules (meaning modules that are not in a package) would have to be accessed starting from "lib". Of course professionals like you and i are already using packages to properly nest out modules, but the newbie's won't realize the power of packaging modules for some time, so create the default "lib" package for them. For instance you could create a package named "chris" and then have a module named math exist inside. Alternatively if you choose to be a non-professional and create a math module without a containing package, python would throw the module into the default "lib" package. The only way you could access your math module now would be by using the path "lib.math". So the conclusion is: * We encourage python programmers to use packages so they avoid any name clashes with built-in modules. * if they refuse fine, any "naked" modules they create will be packaged in a default package (call it "lib", "userlib", or whatever) and will require them to prefix the module name with "lib." -- or "lib:" if i get my way! By doing this we solve the many problems related to module name resolution orders and we create cleaner code bases. Damn i am full of good ideas! > Welcome back to the list, Rick. Got any demonstrable code > for Python 4000 yet? I am working on it. Stay tuned. Rick is going to rock your little programming world /very/ soon. From rantingrickjohnson at gmail.com Sat Jan 12 00:28:49 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 11 Jan 2013 21:28:49 -0800 (PST) Subject: PyWart: Import resolution order In-Reply-To: References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Message-ID: <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: > Why is it better to import from the current directory first? Opps. I was not explicit enough with my explanation :). I meant, "look in the current directory FIRST when in a package". Since many times (most all times) packages will contain many sub-modules that need to be imported into the package's main.py module, and sometimes these modules will have the same name as a stdlib module, then looking in the package FIRST makes sense. But the real solution is not to change the default resolution order. The real solution is to wrap all builtin modules into a package and use full paths to access every module. But wait, i have an even better idea... read below! > Windows > has that policy for executable commands; Unix, on the other hand, > requires that you put an explicit path for anything that isn't in the > standard search path. Which of these options is the more likely to > produce security holes and/or unexpected behaviour? I prefer the latter of course :). I think if python where *strict* about full paths for non-builtins, then we would be in a better place. But there is an even better solution! Force all python users to wrap THEIR modules in a toplevel package. Maybe even create the package for them. YES!. Call it "lib". Any "naked" modules (meaning modules that are not in a package) would have to be accessed starting from "lib". Of course professionals like you and i are already using packages to properly nest out modules, but the newbie's won't realize the power of packaging modules for some time, so create the default "lib" package for them. For instance you could create a package named "chris" and then have a module named math exist inside. Alternatively if you choose to be a non-professional and create a math module without a containing package, python would throw the module into the default "lib" package. The only way you could access your math module now would be by using the path "lib.math". So the conclusion is: * We encourage python programmers to use packages so they avoid any name clashes with built-in modules. * if they refuse fine, any "naked" modules they create will be packaged in a default package (call it "lib", "userlib", or whatever) and will require them to prefix the module name with "lib." -- or "lib:" if i get my way! By doing this we solve the many problems related to module name resolution orders and we create cleaner code bases. Damn i am full of good ideas! > Welcome back to the list, Rick. Got any demonstrable code > for Python 4000 yet? I am working on it. Stay tuned. Rick is going to rock your little programming world /very/ soon. From rosuav at gmail.com Sat Jan 12 01:03:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Jan 2013 17:03:11 +1100 Subject: PyWart: Import resolution order In-Reply-To: <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> Message-ID: On Sat, Jan 12, 2013 at 4:28 PM, Rick Johnson wrote: > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: >> Welcome back to the list, Rick. Got any demonstrable code >> for Python 4000 yet? > > I am working on it. Stay tuned. Rick is going to rock your little programming world /very/ soon. So all I have to do is paper my programming world and I win? Sorry, can't hang around arguing about module search paths and your recommendations to add piles of syntactic salt. Gotta finish building and playing with today's Linux kernel (3.2.7, it's looking good so far). ChrisA From ian.g.kelly at gmail.com Sat Jan 12 02:36:43 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 12 Jan 2013 00:36:43 -0700 Subject: PyWart: Import resolution order In-Reply-To: <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> Message-ID: On Fri, Jan 11, 2013 at 10:28 PM, Rick Johnson wrote: > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: >> Why is it better to import from the current directory first? > > Opps. I was not explicit enough with my explanation :). I meant, "look in the current directory FIRST when in a package". Since many times (most all times) packages will contain many sub-modules that need to be imported into the package's main.py module, and sometimes these modules will have the same name as a stdlib module, then looking in the package FIRST makes sense. And again, in Python 2.x this is already the case. When importing in a package, it tries to do a relative import before it even looks at sys.path. > I think if python where *strict* about full paths for non-builtins, then we would be in a better place. And again, in Python 3, where implicit relative imports have been removed from the language, it already is strict about using full paths. You can still do relative imports, but you have to be explicit about them. > For instance you could create a package named "chris" and then have a module named math exist inside. Alternatively if you choose to be a non-professional and create a math module without a containing package, python would throw the module into the default "lib" package. The only way you could access your math module now would be by using the path "lib.math". What if I create a package named "math"? Does that also automatically get renamed to "lib.math"? How is it decided what package names are proper; is it just because it happens to clash with a stdlib name that the package gets magically renamed? What if I create a package, and then later a module with the same name happens to be added to the stdlib? My program that uses the package just breaks because it no longer imports the correct thing? > Damn i am full of good ideas! Your ideas might be better if you first spent some time gaining a better understanding of how the language works as is. From dihedral88888 at googlemail.com Sat Jan 12 22:56:22 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 12 Jan 2013 19:56:22 -0800 (PST) Subject: PyWart: Import resolution order In-Reply-To: References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> Message-ID: <1200a46d-9803-4d96-9195-6aedc779b90c@googlegroups.com> Ian? 2013?1?12????UTC+8??3?36?43???? > On Fri, Jan 11, 2013 at 10:28 PM, Rick Johnson > > wrote: > > > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: > > >> Why is it better to import from the current directory first? > > > > > > Opps. I was not explicit enough with my explanation :). I meant, "look in the current directory FIRST when in a package". Since many times (most all times) packages will contain many sub-modules that need to be imported into the package's main.py module, and sometimes these modules will have the same name as a stdlib module, then looking in the package FIRST makes sense. > > > > And again, in Python 2.x this is already the case. When importing in > > a package, it tries to do a relative import before it even looks at > > sys.path. > > > > > I think if python where *strict* about full paths for non-builtins, then we would be in a better place. > > > > And again, in Python 3, where implicit relative imports have been > > removed from the language, it already is strict about using full > > paths. You can still do relative imports, but you have to be explicit > > about them. > > > > > For instance you could create a package named "chris" and then have a module named math exist inside. Alternatively if you choose to be a non-professional and create a math module without a containing package, python would throw the module into the default "lib" package. The only way you could access your math module now would be by using the path "lib.math". > > > > What if I create a package named "math"? Does that also automatically > > get renamed to "lib.math"? How is it decided what package names are > > proper; is it just because it happens to clash with a stdlib name that > > the package gets magically renamed? > > > > What if I create a package, and then later a module with the same name > > happens to be added to the stdlib? My program that uses the package > > just breaks because it no longer imports the correct thing? > > > > > Damn i am full of good ideas! > > > > Your ideas might be better if you first spent some time gaining a > > better understanding of how the language works as is. OK, I think to develop a GUI with auto-code translations in an IDE with python as the CAD/CAM scripting language can be helpful. But usually this kind of sotware projects is in the commercial part. From dihedral88888 at googlemail.com Sat Jan 12 22:56:22 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 12 Jan 2013 19:56:22 -0800 (PST) Subject: PyWart: Import resolution order In-Reply-To: References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> Message-ID: <1200a46d-9803-4d96-9195-6aedc779b90c@googlegroups.com> Ian? 2013?1?12????UTC+8??3?36?43???? > On Fri, Jan 11, 2013 at 10:28 PM, Rick Johnson > > wrote: > > > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: > > >> Why is it better to import from the current directory first? > > > > > > Opps. I was not explicit enough with my explanation :). I meant, "look in the current directory FIRST when in a package". Since many times (most all times) packages will contain many sub-modules that need to be imported into the package's main.py module, and sometimes these modules will have the same name as a stdlib module, then looking in the package FIRST makes sense. > > > > And again, in Python 2.x this is already the case. When importing in > > a package, it tries to do a relative import before it even looks at > > sys.path. > > > > > I think if python where *strict* about full paths for non-builtins, then we would be in a better place. > > > > And again, in Python 3, where implicit relative imports have been > > removed from the language, it already is strict about using full > > paths. You can still do relative imports, but you have to be explicit > > about them. > > > > > For instance you could create a package named "chris" and then have a module named math exist inside. Alternatively if you choose to be a non-professional and create a math module without a containing package, python would throw the module into the default "lib" package. The only way you could access your math module now would be by using the path "lib.math". > > > > What if I create a package named "math"? Does that also automatically > > get renamed to "lib.math"? How is it decided what package names are > > proper; is it just because it happens to clash with a stdlib name that > > the package gets magically renamed? > > > > What if I create a package, and then later a module with the same name > > happens to be added to the stdlib? My program that uses the package > > just breaks because it no longer imports the correct thing? > > > > > Damn i am full of good ideas! > > > > Your ideas might be better if you first spent some time gaining a > > better understanding of how the language works as is. OK, I think to develop a GUI with auto-code translations in an IDE with python as the CAD/CAM scripting language can be helpful. But usually this kind of sotware projects is in the commercial part. From wuwei23 at gmail.com Sat Jan 12 22:23:33 2013 From: wuwei23 at gmail.com (alex23) Date: Sat, 12 Jan 2013 19:23:33 -0800 (PST) Subject: PyWart: Import resolution order References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> Message-ID: <04d06303-1ca0-4f80-b6dd-52d1af83c4c0@xm8g2000pbc.googlegroups.com> On Jan 12, 3:28?pm, Rick Johnson wrote: > I am working on it. Stay tuned. Rick is going to rock your little programming world /very/ soon. I am so confidant that this will never happen that if you _do_ ever produce _anything_ that even remotely resembles your claims, I pledge to provide you with enough funding to continue full-time development on it for 5 years, let's say 5 years @ US$50k per year. However, one condition for acceptance will be that you never post here again. From kwakukwatiah at gmail.com Fri Jan 11 10:35:10 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Fri, 11 Jan 2013 09:35:10 -0600 Subject: please i need explanation Message-ID: <2FB5A66FD91D456BBDFCC0AE25760392@favour> def factorial(n): if n<2: return 1 f = 1 while n>= 2: f *= n f -= 1 return f -------------- next part -------------- An HTML attachment was scrubbed... URL: From maillists at nic.fi Fri Jan 11 04:56:19 2013 From: maillists at nic.fi (K. Elo) Date: Fri, 11 Jan 2013 11:56:19 +0200 Subject: please i need explanation In-Reply-To: <2FB5A66FD91D456BBDFCC0AE25760392@favour> References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> Message-ID: <50EFE1C3.5000303@nic.fi> Hi! Since there is no stated question, I need to guess: n -= 1 (instead of "f -= 1") should work. Or maybe the question was a totally different one... -Kimmo 11.01.2013 17:35, kwakukwatiah at gmail.com wrote: > def factorial(n): > if n<2: > return 1 > f = 1 > while n>= 2: > f *= n > f -= 1 > return f > > > From kwakukwatiah at gmail.com Fri Jan 11 11:33:36 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Fri, 11 Jan 2013 10:33:36 -0600 Subject: please i need explanation In-Reply-To: <50EFE1C3.5000303@nic.fi> References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> <50EFE1C3.5000303@nic.fi> Message-ID: -----Original Message----- From: K. Elo Sent: Friday, January 11, 2013 3:56 AM To: python-list at python.org Subject: Re: please i need explanation Hi! Since there is no stated question, I need to guess: n -= 1 (instead of "f -= 1") should work. Or maybe the question was a totally different one... -Kimmo 11.01.2013 17:35, kwakukwatiah at gmail.com wrote: > def factorial(n): > if n<2: > return 1 > f = 1 > while n>= 2: > f *= n > f -= 1 > return f > > > please it works.but don?t get why the return 1 and the code below. From kliateni at gmail.com Fri Jan 11 05:41:42 2013 From: kliateni at gmail.com (Karim) Date: Fri, 11 Jan 2013 11:41:42 +0100 Subject: please i need explanation In-Reply-To: References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> <50EFE1C3.5000303@nic.fi> Message-ID: <50EFEC66.1060209@gmail.com> On 11/01/2013 17:33, kwakukwatiah at gmail.com wrote: > > > -----Original Message----- From: K. Elo > Sent: Friday, January 11, 2013 3:56 AM > To: python-list at python.org > Subject: Re: please i need explanation > > Hi! > > Since there is no stated question, I need to guess: > > n -= 1 (instead of "f -= 1") > > should work. > > Or maybe the question was a totally different one... > > -Kimmo > > 11.01.2013 17:35, kwakukwatiah at gmail.com wrote: >> def factorial(n): >> if n<2: >> return 1 >> f = 1 >> while n>= 2: >> f *= n >> f -= 1 >> return f >> >> >> > please it works.but don?t get why the return 1 and the code below. > factorial or n! = n*(n-1)*(n-2).... for n > 1. For n = 0, 1 the factorial is 1 the reason for the 'return 1'. f *= n <=> f = f* n f -= 1 <=> f = f - 1 but sure this is not correct as Kimmo said n = n - 1 or n -= 1 Regards Karim From square.steve at gmail.com Fri Jan 11 14:38:06 2013 From: square.steve at gmail.com (Steve Simmons) Date: Fri, 11 Jan 2013 19:38:06 +0000 Subject: please i need explanation In-Reply-To: References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> <50EFE1C3.5000303@nic.fi> Message-ID: <50F06A1E.4000608@gmail.com> I read the question as "I've got this function and it does what I expect but I don't understand the code". On that basis... The function creates a factorialfor the input number 'n' (i.e. 1*2*3*4.....*n) The first 2 lines checks to see that the input is less than 2 and, if so, returns a value of 1 The rest of the code counts down from n to 1 multiplying f by n at each iteration. If I guessed the right question, reply to the post for further clarification. Steve On 11/01/2013 16:33, kwakukwatiah at gmail.com wrote: > > > -----Original Message----- From: K. Elo > Sent: Friday, January 11, 2013 3:56 AM > To: python-list at python.org > Subject: Re: please i need explanation > > Hi! > > Since there is no stated question, I need to guess: > > n -= 1 (instead of "f -= 1") > > should work. > > Or maybe the question was a totally different one... > > -Kimmo > > 11.01.2013 17:35, kwakukwatiah at gmail.com wrote: >> def factorial(n): >> if n<2: >> return 1 >> f = 1 >> while n>= 2: >> f *= n >> f -= 1 >> return f >> >> >> > please it works.but don?t get why the return 1 and the code below. > From jpiitula at ling.helsinki.fi Fri Jan 11 07:20:31 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 Jan 2013 14:20:31 +0200 Subject: please i need explanation References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> <50EFE1C3.5000303@nic.fi> Message-ID: kwakukwatiah at gmail.com writes: > 11.01.2013 17:35, kwakukwatiah at gmail.com wrote: > > def factorial(n): > > if n<2: > > return 1 > > f = 1 > > while n>= 2: > > f *= n > > f -= 1 > > return f > > please it works.but don?t get why the return 1 and the code below. Ignoring the error that has been pointed out, this code seems to be "optimized" to avoid multiplication by 1. I doubt if the difference is measurable. If anyone cares enough to measure: def fast_factorial(n): if n < 2: return 1 f = 1 while n > 1: f *= n n -= 1 return f def slow_factorial(n): f = 1 while n != 0: f *= n n -= 1 return f (Untested, and just kidding. For fast factorial routines, search for a paper by Richard Fateman on the web. They're in Common Lisp, but the branching techniques should be generally applicable.) Additionally, your code produces nonsense quietly when called with (real) numbers outside its intended domain (negative integers and non-integers are outside). Not a good idea. (My version will loop indefinitely instead. Better than a wrong answer but also not very good. Caller beware. :) From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Fri Jan 11 07:58:35 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Fri, 11 Jan 2013 13:58:35 +0100 Subject: please i need explanation In-Reply-To: References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> <50EFE1C3.5000303@nic.fi> Message-ID: Am 11.01.2013 17:33 schrieb kwakukwatiah at gmail.com: >> def factorial(n): >> if n<2: >> return 1 >> f = 1 >> while n>= 2: >> f *= n >> f -= 1 >> return f >> >> >> > please it works. I doubt this. If you give n = 4, you run into an endless loop. > but don?t get why the return 1 and the code below. The "if n < 2: return 1" serves to shorten the calculation process below. It is redundant, as you have a "f = 1" and a "return f" for n < 2. The code below first sets f, which holds the result, to 1 and then multiplies it by n in each step. As the loop should contain a 'n -= 1', n decreases by 1 every step, turning it into f = n * (n-1) * (n-2) * ... * 2 and then, as n is not >= 2 any longer, stops the loop, returning f. HTH, Thomas From kliateni at gmail.com Fri Jan 11 04:59:30 2013 From: kliateni at gmail.com (Karim) Date: Fri, 11 Jan 2013 10:59:30 +0100 Subject: please i need explanation In-Reply-To: <2FB5A66FD91D456BBDFCC0AE25760392@favour> References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> Message-ID: <50EFE282.7080804@gmail.com> On 11/01/2013 16:35, kwakukwatiah at gmail.com wrote: > def factorial(n): > if n<2: > return 1 > f = 1 > while n>= 2: > f *= n > f -= 1 > return f > > What explanation this a function representing the math factorial. You provide a parameter n: if n est lower than 2 the factorial is 1 (return by the function). in other case you multiply previous factoriel value by n (f *= n <=> f = f *n). And you decrement n by 1 (f -=1 <=> f = f - 1). This gives n*(n-)*(n-2).... general formula for factorial. Regards Karim -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.vandevyvre at swing.be Fri Jan 11 05:11:17 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 11 Jan 2013 11:11:17 +0100 Subject: please i need explanation In-Reply-To: <2FB5A66FD91D456BBDFCC0AE25760392@favour> References: <2FB5A66FD91D456BBDFCC0AE25760392@favour> Message-ID: <50EFE545.7040408@swing.be> Le 11/01/13 16:35, kwakukwatiah at gmail.com a ?crit : > def factorial(n): > if n<2: > return 1 > f = 1 > while n>= 2: > f *= n > f -= 1 > return f > > > I guess you mean: f = 1 while n>= 2: f *= n n -= 1 return f Try it. -- Vincent V.V. Oqapy . Qarte . PaQager From hansmu at xs4all.nl Fri Jan 11 18:56:02 2013 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 12 Jan 2013 00:56:02 +0100 Subject: please i need explanation In-Reply-To: References: Message-ID: <50f0a692$0$6955$e4fe514c@news2.news.xs4all.nl> On 11/01/13 16:35:10, kwakukwatiah at gmail.com wrote: > def factorial(n): > if n<2: > return 1 > f = 1 > while n>= 2: > f *= n > f -= 1 U think this line should have been: n -= 1 > return f Hope this helps, -- HansM From walterhurry at lavabit.com Sun Jan 13 16:08:56 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Sun, 13 Jan 2013 21:08:56 +0000 (UTC) Subject: please i need explanation References: Message-ID: On Sun, 13 Jan 2013 15:04:34 -0600, Tony the Tiger wrote: > On Fri, 11 Jan 2013 09:35:10 -0600, kwakukwatiah wrote: > >> >> >>
>>
>>
def factorial(n):
> > Right, another html junkie, on windoze, no doubt. X-Mailer: Microsoft Windows Live Mail 15.4.3508.1109 From kwakukwatiah at gmail.com Thu Jan 10 13:35:40 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Thu, 10 Jan 2013 12:35:40 -0600 Subject: help Message-ID: <07AEBD8B16FA4C03A16257998C995B38@favour> pls this is a code to show the pay of two people.bt I want each of to be able to get a different money when they enter their user name,and to use it for about six people. database = [ ['Mac'], ['Sam'], ] pay1 = 1000 pay2 = 2000 name = raw_input('Enter your name: ') if [name] in database:print "your pay is $",pay -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.walker.jones at gmail.com Fri Jan 11 09:24:41 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Fri, 11 Jan 2013 08:24:41 -0600 Subject: help In-Reply-To: <07AEBD8B16FA4C03A16257998C995B38@favour> References: <07AEBD8B16FA4C03A16257998C995B38@favour> Message-ID: Pay isn't linked to the "people" in any way. A dictionary would serve this purpose better (at least in this simple example). database = { 'Mac' : 1000, 'Sam' : 2000 } name = raw_input('Enter your name:') if name in database.keys(): print "your pay is $", database[name] *Matt Jones* On Thu, Jan 10, 2013 at 12:35 PM, wrote: > pls this is a code to show the pay of two people.bt I want each of to > be able to get a different money when they enter their user name,and to use > it for about six people. > database = [ > ['Mac'], > ['Sam'], > ] > pay1 = 1000 > pay2 = 2000 > > name = raw_input('Enter your name: ') > if [name] in database:print "your pay is $",pay > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From msirenef at lightbird.net Fri Jan 11 13:16:09 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Fri, 11 Jan 2013 13:16:09 -0500 Subject: help In-Reply-To: References: <07AEBD8B16FA4C03A16257998C995B38@favour> Message-ID: <50F056E9.6010602@lightbird.net> On 01/11/2013 09:24 AM, Matt Jones wrote: > Pay isn't linked to the "people" in any way. A dictionary would serve > this purpose better (at least in this simple example). > > database = { > 'Mac' : 1000, > 'Sam' : 2000 > } > > name = raw_input('Enter your name:') > if name in database.keys(): print "your pay is $", database[name] This can be simplified a bit as: database = dict(Mac=1000, Sam=2000) name = raw_input('Enter your name: ') if name in database: print "your pay is $", database[name] -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From hansmu at xs4all.nl Fri Jan 11 18:51:04 2013 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 12 Jan 2013 00:51:04 +0100 Subject: help In-Reply-To: References: Message-ID: <50f0a569$0$6955$e4fe514c@news2.news.xs4all.nl> On 10/01/13 19:35:40, kwakukwatiah at gmail.com wrote: > pls this is a code to show the pay of two people.bt I want each of to be > able to get a different money when they enter their user name,and to use > it for about six people. > database = [ > ['Mac'], > ['Sam'], > ] > pay1 = 1000 > pay2 = 2000 > > name = raw_input('Enter your name: ') > if [name] in database:print "your pay is $",pay How about: database = dict(Mac=1000, Sam=2000, Eric=3000, Terry=4000, Graham=5000) name = raw_input('Enter your name: ') if name in database: print "Your pay is ${}".format(database[name]) Hope this helps, -- HansM From roy at panix.com Fri Jan 11 09:15:29 2013 From: roy at panix.com (Roy Smith) Date: Fri, 11 Jan 2013 09:15:29 -0500 Subject: Multiple disjoint sample sets? Message-ID: I have a list of items. I need to generate n samples of k unique items each. I not only want each sample set to have no repeats, but I also want to make sure the sets are disjoint (i.e. no item repeated between sets). random.sample(items, k) will satisfy the first constraint, but not the second. Should I just do random.sample(items, k*n), and then split the resulting big list into n pieces? Or is there some more efficient way? Typical values: len(items) = 5,000,000 n = 10 k = 100,000 From python at mrabarnett.plus.com Fri Jan 11 09:36:57 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 11 Jan 2013 14:36:57 +0000 Subject: Multiple disjoint sample sets? In-Reply-To: References: Message-ID: <50F02389.70507@mrabarnett.plus.com> On 2013-01-11 14:15, Roy Smith wrote: > I have a list of items. I need to generate n samples of k unique items > each. I not only want each sample set to have no repeats, but I also > want to make sure the sets are disjoint (i.e. no item repeated between > sets). > > random.sample(items, k) will satisfy the first constraint, but not the > second. Should I just do random.sample(items, k*n), and then split the > resulting big list into n pieces? Or is there some more efficient way? > > Typical values: > > len(items) = 5,000,000 > n = 10 > k = 100,000 > I don't know how efficient it would be, but couldn't you shuffle the list and then use slicing to get the samples? From d at davea.name Fri Jan 11 10:14:15 2013 From: d at davea.name (Dave Angel) Date: Fri, 11 Jan 2013 10:14:15 -0500 Subject: Multiple disjoint sample sets? In-Reply-To: <50F02389.70507@mrabarnett.plus.com> References: <50F02389.70507@mrabarnett.plus.com> Message-ID: <50F02C47.9070804@davea.name> On 01/11/2013 09:36 AM, MRAB wrote: > On 2013-01-11 14:15, Roy Smith wrote: >> I have a list of items. I need to generate n samples of k unique items >> each. I not only want each sample set to have no repeats, but I also >> want to make sure the sets are disjoint (i.e. no item repeated between >> sets). >> >> random.sample(items, k) will satisfy the first constraint, but not the >> second. Should I just do random.sample(items, k*n), and then split the >> resulting big list into n pieces? Or is there some more efficient way? >> >> Typical values: >> >> len(items) = 5,000,000 >> n = 10 >> k = 100,000 >> > I don't know how efficient it would be, but couldn't you shuffle the > list and then use slicing to get the samples? I like that answer best, but just to offer another choice... You start with a (presumably unique) list of items. After collecting your first sample, you could subtract them from the list, and use the smaller list for the next sample. One way is to convert list to set, subtract, then convert back to list. -- DaveA From __peter__ at web.de Sun Jan 13 05:16:03 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 13 Jan 2013 11:16:03 +0100 Subject: Multiple disjoint sample sets? References: Message-ID: Roy Smith wrote: > I have a list of items. I need to generate n samples of k unique items > each. I not only want each sample set to have no repeats, but I also > want to make sure the sets are disjoint (i.e. no item repeated between > sets). > > random.sample(items, k) will satisfy the first constraint, but not the > second. Should I just do random.sample(items, k*n), and then split the > resulting big list into n pieces? Or is there some more efficient way? > > Typical values: > > len(items) = 5,000,000 > n = 10 > k = 100,000 I would expect that your simple approach is more efficient than shuffling the whole list. Assuming there is a sample_iter(population) that generates unique items from the population (which has no repetitions itself) you can create the samples with g = sample_iter(items) samples = [list(itertools.islice(g, k) for _ in xrange(n)] My ideas for such a sample_iter(): def sample_iter_mark(items): n = len(items) while True: i = int(random()*n) v = items[i] if v is not None: yield v items[i] = None This is destructive and will degrade badly as the number of None items increases. For your typical values it seems to be OK though. You can make this non-destructive by adding a bit array or a set (random.Random.sample() has code that uses a set) to keep track of the seen items. Another sample_iter() (which is also part of the random.Random.sample() implementation): def sample_iter_replace(items): n = len(items) for k in xrange(n): i = int(random()*(n-k)) yield items[i] items[i] = items[n-k-1] You can micro-optimise that a bit to avoid the index calculation. Also, instead of overwriting items you could swap them, so that no values would be lost, only their initial order. From info at egenix.com Fri Jan 11 13:38:16 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Fri, 11 Jan 2013 19:38:16 +0100 Subject: ANN: Python Meeting =?ISO-8859-1?Q?D=FCsseldorf_-_22=2E01=2E?= =?ISO-8859-1?Q?2013_=28Erinnerung/Reminder=29?= Message-ID: <50F05C18.9030303@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG / ERINNERUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Dienstag, 22.01.2013, 18:00 Uhr Clara Schumann Raum DJH D?sseldorf Diese Nachricht k?nnen Sie auch online lesen: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2013-01-22 ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf (http://pyddf.de/) ist eine neue lokale Veranstaltung in D?sseldorf, die sich an Python Begeisterte in der Region wendet. Wir starten bei den Treffen mit einer kurzen Einleitung und gehen dann zu einer Reihe Kurzvortr?gen (Lightning Talks) ?ber, bei denen die Anwesenden ?ber neue Projekte, interessante Probleme und sonstige Aktivit?ten rund um Python berichten k?nnen. Anschlie?end geht es in eine Gastst?tte, um die Gespr?che zu vertiefen. Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: http://www.youtube.com/pyddf/ Daneben haben wir auch eine Mailing Liste f?r Python- Interessierte aus dem Ruhrgebiet und Meeting-Teilnehmer: https://www.egenix.com/mailman/listinfo/pyddf F?r Ank?ndigungen gibt es zus?tzlich folgende Kan?le: Twitter: https://twitter.com/pyddf Facebook Seite: https://www.facebook.com/PythonMeetingDusseldorf Facebook Gruppe: https://www.facebook.com/groups/397118706993326/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ ORT F?r das Python Meeting D?sseldorf haben wir den Clara Schumann Raum in der modernen Jugendherberge D?sseldorf angemietet: Jugendherberge D?sseldorf D?sseldorfer Str. 1 40545 D?sseldorf Telefon: +49 211 557310 http://www.duesseldorf.jugendherberge.de Die Jugendherberge verf?gt ?ber eine kostenpflichtige Tiefgarage (EUR 2,50 pro Stunde, maximal EUR 10,00). Es ist aber auch m?glich per Bus und Bahn anzureisen. Der Raum befindet sich im 1.OG links. ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks: Die Treffen starten mit einer kurzen Einleitung. Danach geht es weiter mit einer Lightning Talk Session, in der die Anwesenden Kurzvortr?ge von f?nf Minuten halten k?nnen. Hieraus ergeben sich dann meisten viele Ansatzpunkte f?r Diskussionen, die dann den Rest der verf?gbaren Zeit in Anspruch nehmen k?nnen. F?r 19:45 Uhr haben wir in einem nahegelegenen Restaurant Pl?tze reserviert, damit auch das leibliche Wohl nicht zu kurz kommt. Lightning Talks k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. Folien bitte als PDF auf USB Stick mitbringen. Lightning Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Da Tagungsraum, Beamer, Internet und Getr?nke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Dec 28 2012) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2013-01-22: Python Meeting Duesseldorf ... 25 days to go ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From sg552 at hotmail.co.uk Fri Jan 11 14:03:41 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Jan 2013 19:03:41 +0000 Subject: String concatenation benchmarking weirdness Message-ID: Hi all, the other day I 2to3'ed some code and found it ran much slower in 3.3.0 than 2.7.2. I fixed the problem but in the process of trying to diagnose it I've stumbled upon something weird that I hope someone here can explain to me. In what follows I'm using Python 2.7.2 on 64-bit Windows 7. Suppose I do this: from timeit import timeit # find out how the time taken to append a character to the end of a byte # string depends on the size of the string results = [] for size in range(0, 10000001, 100000): results.append(timeit("y = x + 'a'", setup = "x = 'a' * %i" % size, number = 1)) If I plot results against size, what I see is that the time taken increases approximately linearly with the size of the string, with the string of length 10000000 taking about 4 milliseconds. On the other hand, if I replace the statement to be timed with "x = x + 'a'" instead of "y = x + 'a'", the time taken seems to be pretty much independent of size, apart from a few spikes; the string of length 10000000 takes about 4 microseconds. I get similar results with strings (but not bytes) in 3.3.0. My guess is that this is some kind of optimisation that treats strings as mutable when carrying out operations that result in the original string being discarded. If so it's jolly clever, since it knows when there are other references to the same string: timeit("x = x + 'a'", setup = "x = y = 'a' * %i" % size, number = 1) # grows linearly with size timeit("x = x + 'a'", setup = "x, y = 'a' * %i", 'a' * %i" % (size, size), number = 1) # stays approximately constant It also can see through some attempts to fool it: timeit("x = ('' + x) + 'a'", setup = "x = 'a' * %i" % size, number = 1) # stays approximately constant timeit("x = x*1 + 'a'", setup = "x = 'a' * %i" % size, number = 1) # stays approximately constant Is my guess correct? If not, what is going on? If so, is it possible to explain to a programming noob how the interpreter does this? And is there a reason why it doesn't work with bytes in 3.3? -- I have made a thing that superficially resembles music: http://soundcloud.com/eroneity/we-berated-our-own-crapiness From ian.g.kelly at gmail.com Fri Jan 11 15:16:48 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Jan 2013 13:16:48 -0700 Subject: String concatenation benchmarking weirdness In-Reply-To: References: Message-ID: On Fri, Jan 11, 2013 at 12:03 PM, Rotwang wrote: > Hi all, > > the other day I 2to3'ed some code and found it ran much slower in 3.3.0 than > 2.7.2. I fixed the problem but in the process of trying to diagnose it I've > stumbled upon something weird that I hope someone here can explain to me. In > what follows I'm using Python 2.7.2 on 64-bit Windows 7. Suppose I do this: > > from timeit import timeit > > # find out how the time taken to append a character to the end of a byte > # string depends on the size of the string > > results = [] > for size in range(0, 10000001, 100000): > results.append(timeit("y = x + 'a'", > setup = "x = 'a' * %i" % size, number = 1)) > > If I plot results against size, what I see is that the time taken increases > approximately linearly with the size of the string, with the string of > length 10000000 taking about 4 milliseconds. On the other hand, if I replace > the statement to be timed with "x = x + 'a'" instead of "y = x + 'a'", the > time taken seems to be pretty much independent of size, apart from a few > spikes; the string of length 10000000 takes about 4 microseconds. > > I get similar results with strings (but not bytes) in 3.3.0. My guess is > that this is some kind of optimisation that treats strings as mutable when > carrying out operations that result in the original string being discarded. > If so it's jolly clever, since it knows when there are other references to > the same string: > > timeit("x = x + 'a'", setup = "x = y = 'a' * %i" % size, number = 1) > # grows linearly with size > > timeit("x = x + 'a'", setup = "x, y = 'a' * %i", 'a' * %i" > % (size, size), number = 1) > # stays approximately constant > > It also can see through some attempts to fool it: > > timeit("x = ('' + x) + 'a'", setup = "x = 'a' * %i" % size, number = 1) > # stays approximately constant > > timeit("x = x*1 + 'a'", setup = "x = 'a' * %i" % size, number = 1) > # stays approximately constant > > Is my guess correct? If not, what is going on? If so, is it possible to > explain to a programming noob how the interpreter does this? Basically, yes. You can find the discussion behind that optimization at: http://bugs.python.org/issue980695 It knows when there are other references to the string because all objects in CPython are reference-counted. It also works despite your attempts to "fool" it because after evaluating the first operation (which is easily optimized to return the string itself in both cases), the remaining part of the expression is essentially "x = TOS + 'a'", where x and the top of the stack are the same string object, which is the same state the original code reaches after evaluating just the x. The stated use case for this optimization is to make repeated concatenation more efficient, but note that it is still generally preferable to use the ''.join() construct, because the optimization is specific to CPython and may not exist for other Python implementations. > And is there a reason why it doesn't work with bytes in 3.3? No idea. Probably just never got implemented due to a lack of demand. From sg552 at hotmail.co.uk Fri Jan 11 15:51:27 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Jan 2013 20:51:27 +0000 Subject: String concatenation benchmarking weirdness In-Reply-To: References: Message-ID: On 11/01/2013 20:16, Ian Kelly wrote: > On Fri, Jan 11, 2013 at 12:03 PM, Rotwang wrote: >> Hi all, >> >> the other day I 2to3'ed some code and found it ran much slower in 3.3.0 than >> 2.7.2. I fixed the problem but in the process of trying to diagnose it I've >> stumbled upon something weird that I hope someone here can explain to me. >> >> [stuff about timings] >> >> Is my guess correct? If not, what is going on? If so, is it possible to >> explain to a programming noob how the interpreter does this? > > Basically, yes. You can find the discussion behind that optimization at: > > http://bugs.python.org/issue980695 > > It knows when there are other references to the string because all > objects in CPython are reference-counted. It also works despite your > attempts to "fool" it because after evaluating the first operation > (which is easily optimized to return the string itself in both cases), > the remaining part of the expression is essentially "x = TOS + 'a'", > where x and the top of the stack are the same string object, which is > the same state the original code reaches after evaluating just the x. Nice, thanks. > The stated use case for this optimization is to make repeated > concatenation more efficient, but note that it is still generally > preferable to use the ''.join() construct, because the optimization is > specific to CPython and may not exist for other Python > implementations. The slowdown in my code was caused by a method that built up a string of bytes by repeatedly using +=, before writing the result to a WAV file. My fix was to replaced the bytes string with a bytearray, which seems about as fast as the rewrite I just tried with b''.join. Do you know whether the bytearray method will still be fast on other implementations? -- I have made a thing that superficially resembles music: http://soundcloud.com/eroneity/we-berated-our-own-crapiness From wxjmfauth at gmail.com Sat Jan 12 03:38:32 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 12 Jan 2013 00:38:32 -0800 (PST) Subject: String concatenation benchmarking weirdness In-Reply-To: References: Message-ID: from timeit import timeit, repeat size = 1000 r = repeat("y = x + 'a'", setup = "x = 'a' * %i" % size) print('1:', r) r = repeat("y = x + '?'", setup = "x = 'a' * %i" % size) print('2:', r) r = repeat("y = x + '?'", setup = "x = 'a' * %i" % size) print('3:', r) r = repeat("y = x + '?'", setup = "x = 'a' * %i" % size) print('4:', r) r = repeat("y = x + '?'", setup = "x = '?' * %i" % size) print('5:', r) r = repeat("y = x + '?'", setup = "x = '?' * %i" % size) print('6:', r) r = repeat("y = ? + '?'", setup = "? = '?' * %i" % size) print('7:', r) r = repeat("y = ? + '?'", setup = "? = '?' * %i" % size) print('8:', r) >c:\python32\pythonw -u "vitesse3.py" 1: [0.3603178435286996, 0.42901157137281515, 0.35459694357592086] 2: [0.3576409223543202, 0.4272010951864649, 0.3590055732104662] 3: [0.3552022735516487, 0.4256544908828328, 0.35824546465278573] 4: [0.35488168890607774, 0.4271707696118834, 0.36109528098614074] 5: [0.3560675370237849, 0.4261538782668417, 0.36138160167082134] 6: [0.3570182634788317, 0.4270155971913008, 0.35770629956705324] 7: [0.3556977225493485, 0.4264969117143753, 0.3645634239700426] 8: [0.35511247834379844, 0.4259628665308437, 0.3580737510097034] >Exit code: 0 >c:\Python33\pythonw -u "vitesse3.py" 1: [0.3053600256152646, 0.3306491917840535, 0.3044963374976518] 2: [0.36252767208680514, 0.36937298133086727, 0.3685573415262271] 3: [0.7666293438924097, 0.7653473991487574, 0.7630926729867262] 4: [0.7636680712265038, 0.7647586103955284, 0.7631395397838059] 5: [0.44721085450773934, 0.3863234021671369, 0.45664368355696094] 6: [0.44699700013114807, 0.3873974001136613, 0.45167383387335036] 7: [0.4465200615491014, 0.387050034441188, 0.45459690419205856] 8: [0.44760587465455437, 0.3875261853459726, 0.45421212384964704] >Exit code: 0 The difference between a correct (coherent) unicode handling and ... jmf From tjreedy at udel.edu Sat Jan 12 06:31:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 12 Jan 2013 06:31:09 -0500 Subject: String concatenation benchmarking weirdness In-Reply-To: References: Message-ID: On 1/12/2013 3:38 AM, wxjmfauth at gmail.com wrote: > from timeit import timeit, repeat > > size = 1000 > > r = repeat("y = x + 'a'", setup = "x = 'a' * %i" % size) > print('1:', r) > r = repeat("y = x + '?'", setup = "x = 'a' * %i" % size) > print('2:', r) > r = repeat("y = x + '?'", setup = "x = 'a' * %i" % size) > print('3:', r) > r = repeat("y = x + '?'", setup = "x = 'a' * %i" % size) > print('4:', r) > r = repeat("y = x + '?'", setup = "x = '?' * %i" % size) > print('5:', r) > r = repeat("y = x + '?'", setup = "x = '?' * %i" % size) > print('6:', r) > r = repeat("y = ? + '?'", setup = "? = '?' * %i" % size) > print('7:', r) > r = repeat("y = ? + '?'", setup = "? = '?' * %i" % size) > print('8:', r) > > > >> c:\python32\pythonw -u "vitesse3.py" > 1: [0.3603178435286996, 0.42901157137281515, 0.35459694357592086] > 2: [0.3576409223543202, 0.4272010951864649, 0.3590055732104662] > 3: [0.3552022735516487, 0.4256544908828328, 0.35824546465278573] > 4: [0.35488168890607774, 0.4271707696118834, 0.36109528098614074] > 5: [0.3560675370237849, 0.4261538782668417, 0.36138160167082134] > 6: [0.3570182634788317, 0.4270155971913008, 0.35770629956705324] > 7: [0.3556977225493485, 0.4264969117143753, 0.3645634239700426] > 8: [0.35511247834379844, 0.4259628665308437, 0.3580737510097034] >> Exit code: 0 >> c:\Python33\pythonw -u "vitesse3.py" > 1: [0.3053600256152646, 0.3306491917840535, 0.3044963374976518] > 2: [0.36252767208680514, 0.36937298133086727, 0.3685573415262271] > 3: [0.7666293438924097, 0.7653473991487574, 0.7630926729867262] > 4: [0.7636680712265038, 0.7647586103955284, 0.7631395397838059] > 5: [0.44721085450773934, 0.3863234021671369, 0.45664368355696094] > 6: [0.44699700013114807, 0.3873974001136613, 0.45167383387335036] > 7: [0.4465200615491014, 0.387050034441188, 0.45459690419205856] > 8: [0.44760587465455437, 0.3875261853459726, 0.45421212384964704] >> Exit code: 0 > > > The difference between a correct (coherent) unicode handling and ... By 'correct' Jim means 'speedy', for a subset of string operations*. rather than 'accurate'. In 3.2 and before, CPython does not handle extended plane characters correctly on Windows and other narrow builds. This is, by the way, true of many other languages. For instance, Tcl 8.5 and before (not sure about the new 8.6) does not handle them at all. The same is true of Microsoft command windows. * lets try another comparison: from timeit import timeit print(timeit("a.encode()", "a = 'a'*10000")) 3.2: 12.1 seconds 3.3 .7 seconds 3.3 is 15 times faster!!! (The factor increases with the length of a.) A fairer comparison is the approximately 120 micro benchmarks in Tools/stringbench.py. Here they are, uncensored, for 3.3.0 and 3.2.3. It is in the Tools directory of some distributions but not all (including not Windows). It can be downloaded from http://hg.python.org/cpython/file/6fe28afa6611/Tools/stringbench In FireFox, Right-click on the stringbench.py link and 'Save link as...' to somewhere you can run it from. >>> stringbench v2.0 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] 2013-01-12 06:17:51.685781 bytes unicode (in ms) (in ms) % comment ========== case conversion -- dense 0.41 0.43 95.2 ("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower() (*1000) 0.42 0.43 95.8 ("where in the world is carmen san deigo?"*10).upper() (*1000) ========== case conversion -- rare 0.41 0.43 95.8 ("Where in the world is Carmen San Deigo?"*10).lower() (*1000) 0.42 0.43 96.3 ("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper() (*1000) ========== concat 20 strings of words length 4 to 15 1.83 1.95 94.1 s1+s2+s3+s4+...+s20 (*1000) ========== concat two strings 0.10 0.10 98.7 "Andrew"+"Dalke" (*1000) ========== count AACT substrings in DNA example 2.46 2.44 100.9 dna.count("AACT") (*10) ========== count newlines 0.77 0.75 103.6 ...text.with.2000.newlines.count("\n") (*10) ========== early match, single character 0.30 0.27 110.5 ("A"*1000).find("A") (*1000) 0.45 0.06 750.5 "A" in "A"*1000 (*1000) 0.30 0.27 110.4 ("A"*1000).index("A") (*1000) 0.24 0.22 107.2 ("A"*1000).partition("A") (*1000) 0.33 0.29 116.6 ("A"*1000).rfind("A") (*1000) 0.32 0.29 107.9 ("A"*1000).rindex("A") (*1000) 0.20 0.21 94.1 ("A"*1000).rpartition("A") (*1000) 0.42 0.45 93.4 ("A"*1000).rsplit("A", 1) (*1000) 0.39 0.41 95.9 ("A"*1000).split("A", 1) (*1000) ========== early match, two characters 0.32 0.27 121.1 ("AB"*1000).find("AB") (*1000) 0.45 0.06 729.5 "AB" in "AB"*1000 (*1000) 0.30 0.27 111.2 ("AB"*1000).index("AB") (*1000) 0.23 0.28 85.0 ("AB"*1000).partition("AB") (*1000) 0.33 0.30 110.6 ("AB"*1000).rfind("AB") (*1000) 0.33 0.30 110.5 ("AB"*1000).rindex("AB") (*1000) 0.22 0.27 83.1 ("AB"*1000).rpartition("AB") (*1000) 0.46 0.47 96.7 ("AB"*1000).rsplit("AB", 1) (*1000) 0.44 0.48 90.9 ("AB"*1000).split("AB", 1) (*1000) ========== endswith multiple characters 0.24 0.29 84.0 "Andrew".endswith("Andrew") (*1000) ========== endswith multiple characters - not! 0.26 0.28 92.9 "Andrew".endswith("Anders") (*1000) ========== endswith single character 0.25 0.28 90.0 "Andrew".endswith("w") (*1000) ========== formatting a string type with a dict N/A 0.67 0.0 "The %(k1)s is %(k2)s the %(k3)s."%{"k1":"x","k2":"y","k3":"z",} (*1000) ========== join empty string, with 1 character sep N/A 0.06 0.0 "A".join("") (*100) ========== join empty string, with 5 character sep N/A 0.06 0.0 "ABCDE".join("") (*100) ========== join list of 100 words, with 1 character sep 0.87 1.27 68.8 "A".join(["Bob"]*100)) (*1000) ========== join list of 100 words, with 5 character sep 1.14 1.54 74.0 "ABCDE".join(["Bob"]*100)) (*1000) ========== join list of 26 characters, with 1 character sep 0.27 0.37 72.0 "A".join(list("ABC..Z")) (*1000) ========== join list of 26 characters, with 5 character sep 0.32 0.43 75.7 "ABCDE".join(list("ABC..Z")) (*1000) ========== join string with 26 characters, with 1 character sep N/A 1.30 0.0 "A".join("ABC..Z") (*1000) ========== join string with 26 characters, with 5 character sep N/A 1.37 0.0 "ABCDE".join("ABC..Z") (*1000) ========== late match, 100 characters 3.25 3.23 100.5 s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E") (*100) 2.79 2.78 100.4 s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s) (*100) 1.98 1.94 102.3 s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E") (*100) 3.24 3.23 100.3 s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E") (*100) 4.26 3.62 117.7 s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E") (*100) 3.23 3.23 100.1 s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s) (*100) 2.32 2.32 100.1 s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E") (*100) 3.23 3.21 100.8 s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s) (*100) 3.58 3.57 100.4 s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s) (*100) 3.60 3.60 100.0 s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1) (*100) 3.60 3.56 101.2 s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1) (*100) ========== late match, two characters 0.62 0.58 106.3 ("AB"*300+"C").find("BC") (*1000) 0.92 0.82 111.8 ("AB"*300+"CA").find("CA") (*1000) 0.73 0.33 218.8 "BC" in ("AB"*300+"C") (*1000) 0.61 0.60 101.0 ("AB"*300+"C").index("BC") (*1000) 0.54 0.82 66.4 ("AB"*300+"C").partition("BC") (*1000) 0.66 0.63 104.6 ("C"+"AB"*300).rfind("CA") (*1000) 0.91 0.88 102.3 ("BC"+"AB"*300).rfind("BC") (*1000) 0.65 0.62 105.1 ("C"+"AB"*300).rindex("CA") (*1000) 0.53 0.56 94.5 ("C"+"AB"*300).rpartition("CA") (*1000) 0.75 0.77 96.6 ("C"+"AB"*300).rsplit("CA", 1) (*1000) 0.65 0.67 97.0 ("AB"*300+"C").split("BC", 1) (*1000) ========== no match, single character 0.89 0.87 102.3 ("A"*1000).find("B") (*1000) 1.03 0.64 159.1 "B" in "A"*1000 (*1000) 0.67 0.68 98.7 ("A"*1000).partition("B") (*1000) 0.87 0.85 102.8 ("A"*1000).rfind("B") (*1000) 0.67 0.68 98.5 ("A"*1000).rpartition("B") (*1000) 0.87 0.87 99.2 ("A"*1000).rsplit("B", 1) (*1000) 0.86 0.85 101.5 ("A"*1000).split("B", 1) (*1000) ========== no match, two characters 1.22 1.16 104.9 ("AB"*1000).find("BC") (*1000) 1.93 2.02 95.2 ("AB"*1000).find("CA") (*1000) 1.37 0.94 145.3 "BC" in "AB"*1000 (*1000) 1.39 2.14 65.1 ("AB"*1000).partition("BC") (*1000) 2.32 2.31 100.7 ("AB"*1000).rfind("BC") (*1000) 1.47 1.44 102.1 ("AB"*1000).rfind("CA") (*1000) 2.26 2.27 99.7 ("AB"*1000).rpartition("BC") (*1000) 2.46 2.45 100.2 ("AB"*1000).rsplit("BC", 1) (*1000) 1.15 1.16 99.1 ("AB"*1000).split("BC", 1) (*1000) ========== quick replace multiple character match 0.13 0.12 105.0 ("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1) (*10) ========== quick replace single character match 0.12 0.12 105.2 ("A" + ("Z"*128*1024)).replace("A", "BB", 1) (*10) ========== repeat 1 character 10 times 0.08 0.10 80.6 "A"*10 (*1000) ========== repeat 1 character 1000 times 0.16 0.18 93.1 "A"*1000 (*1000) ========== repeat 5 characters 10 times 0.11 0.13 84.4 "ABCDE"*10 (*1000) ========== repeat 5 characters 1000 times 0.39 0.41 94.8 "ABCDE"*1000 (*1000) ========== replace and expand multiple characters, big string 2.02 2.36 85.6 "...text.with.2000.newlines...replace("\n", "\r\n") (*10) ========== replace multiple characters, dna 3.12 3.23 96.6 dna.replace("ATC", "ATT") (*10) ========== replace single character 0.33 0.40 82.4 "This is a test".replace(" ", "\t") (*1000) ========== replace single character, big string 0.75 0.86 87.4 "...text.with.2000.lines...replace("\n", " ") (*10) ========== replace/remove multiple characters 0.41 0.48 86.1 "When shall we three meet again?".replace("ee", "") (*1000) ========== split 1 whitespace 0.14 0.18 79.3 ("Here are some words. "*2).partition(" ") (*1000) 0.11 0.14 75.1 ("Here are some words. "*2).rpartition(" ") (*1000) 0.35 0.39 90.3 ("Here are some words. "*2).rsplit(None, 1) (*1000) 0.32 0.38 83.9 ("Here are some words. "*2).split(None, 1) (*1000) ========== split 2000 newlines 1.74 2.02 86.3 "...text...".rsplit("\n") (*10) 1.69 1.97 85.5 "...text...".split("\n") (*10) 1.89 2.55 74.0 "...text...".splitlines() (*10) ========== split newlines 0.35 0.39 88.9 "this\nis\na\ntest\n".rsplit("\n") (*1000) 0.34 0.40 86.4 "this\nis\na\ntest\n".split("\n") (*1000) 0.32 0.40 80.7 "this\nis\na\ntest\n".splitlines() (*1000) ========== split on multicharacter separator (dna) 2.28 2.30 99.1 dna.rsplit("ACTAT") (*10) 2.63 2.66 98.9 dna.split("ACTAT") (*10) ========== split on multicharacter separator (small) 0.55 0.69 79.0 "this--is--a--test--of--the--emergency--broadcast--system".rsplit("--") (*1000) 0.58 0.70 82.9 "this--is--a--test--of--the--emergency--broadcast--system".split("--") (*1000) ========== split whitespace (huge) 1.51 2.12 71.4 human_text.rsplit() (*10) 1.51 2.05 73.6 human_text.split() (*10) ========== split whitespace (small) 0.48 0.68 70.1 ("Here are some words. "*2).rsplit() (*1000) 0.48 0.64 74.9 ("Here are some words. "*2).split() (*1000) ========== startswith multiple characters 0.24 0.25 95.9 "Andrew".startswith("Andrew") (*1000) ========== startswith multiple characters - not! 0.24 0.25 95.7 "Andrew".startswith("Anders") (*1000) ========== startswith single character 0.23 0.25 95.4 "Andrew".startswith("A") (*1000) ========== strip terminal newline 0.09 0.21 44.1 s="Hello!\n"; s[:-1] if s[-1]=="\n" else s (*1000) 0.09 0.12 74.0 "\nHello!".rstrip() (*1000) 0.09 0.12 74.0 "Hello!\n".rstrip() (*1000) 0.09 0.12 71.6 "\nHello!\n".strip() (*1000) 0.09 0.12 73.2 "\nHello!".strip() (*1000) 0.09 0.12 72.9 "Hello!\n".strip() (*1000) ========== strip terminal spaces and tabs 0.09 0.13 69.6 "\t \tHello".rstrip() (*1000) 0.09 0.13 72.3 "Hello\t \t".rstrip() (*1000) 0.07 0.08 86.8 "Hello\t \t".strip() (*1000) ========== tab split 0.59 0.65 90.9 GFF3_example.rsplit("\t", 8) (*1000) 0.55 0.59 94.2 GFF3_example.rsplit("\t") (*1000) 0.52 0.57 90.7 GFF3_example.split("\t", 8) (*1000) 0.52 0.57 90.1 GFF3_example.split("\t") (*1000) 108.87 116.31 93.6 TOTAL >>> stringbench v2.0 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)] 2013-01-12 06:23:05.994000 bytes unicode (in ms) (in ms) % comment ========== case conversion -- dense 0.63 3.01 21.0 ("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower() (*1000) 0.63 2.90 21.5 ("where in the world is carmen san deigo?"*10).upper() (*1000) ========== case conversion -- rare 0.84 2.83 29.8 ("Where in the world is Carmen San Deigo?"*10).lower() (*1000) 0.50 3.47 14.3 ("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper() (*1000) ========== concat 20 strings of words length 4 to 15 1.82 1.75 103.9 s1+s2+s3+s4+...+s20 (*1000) ========== concat two strings 0.09 0.08 115.5 "Andrew"+"Dalke" (*1000) ========== count AACT substrings in DNA example 2.40 2.64 91.1 dna.count("AACT") (*10) ========== count newlines 0.77 0.75 101.6 ...text.with.2000.newlines.count("\n") (*10) ========== early match, single character 0.19 0.18 101.9 ("A"*1000).find("A") (*1000) 0.39 0.05 824.7 "A" in "A"*1000 (*1000) 0.19 0.19 96.3 ("A"*1000).index("A") (*1000) 0.20 0.22 87.5 ("A"*1000).partition("A") (*1000) 0.20 0.20 101.8 ("A"*1000).rfind("A") (*1000) 0.20 0.20 101.2 ("A"*1000).rindex("A") (*1000) 0.18 0.22 82.5 ("A"*1000).rpartition("A") (*1000) 0.41 0.45 91.7 ("A"*1000).rsplit("A", 1) (*1000) 0.42 0.43 99.0 ("A"*1000).split("A", 1) (*1000) ========== early match, two characters 0.19 0.19 102.3 ("AB"*1000).find("AB") (*1000) 0.39 0.05 781.6 "AB" in "AB"*1000 (*1000) 0.19 0.20 97.9 ("AB"*1000).index("AB") (*1000) 0.23 0.33 71.1 ("AB"*1000).partition("AB") (*1000) 0.20 0.20 101.6 ("AB"*1000).rfind("AB") (*1000) 0.20 0.20 100.1 ("AB"*1000).rindex("AB") (*1000) 0.22 0.31 70.4 ("AB"*1000).rpartition("AB") (*1000) 0.47 0.53 90.0 ("AB"*1000).rsplit("AB", 1) (*1000) 0.45 0.52 85.0 ("AB"*1000).split("AB", 1) (*1000) ========== endswith multiple characters 0.18 0.18 97.6 "Andrew".endswith("Andrew") (*1000) ========== endswith multiple characters - not! 0.18 0.18 100.4 "Andrew".endswith("Anders") (*1000) ========== endswith single character 0.18 0.18 97.1 "Andrew".endswith("w") (*1000) ========== formatting a string type with a dict N/A 0.53 0.0 "The %(k1)s is %(k2)s the %(k3)s."%{"k1":"x","k2":"y","k3":"z",} (*1000) ========== join empty string, with 1 character sep N/A 0.05 0.0 "A".join("") (*100) ========== join empty string, with 5 character sep N/A 0.05 0.0 "ABCDE".join("") (*100) ========== join list of 100 words, with 1 character sep 1.02 1.02 99.6 "A".join(["Bob"]*100)) (*1000) ========== join list of 100 words, with 5 character sep 1.25 1.48 84.4 "ABCDE".join(["Bob"]*100)) (*1000) ========== join list of 26 characters, with 1 character sep 0.31 0.25 122.9 "A".join(list("ABC..Z")) (*1000) ========== join list of 26 characters, with 5 character sep 0.36 0.41 88.4 "ABCDE".join(list("ABC..Z")) (*1000) ========== join string with 26 characters, with 1 character sep N/A 1.06 0.0 "A".join("ABC..Z") (*1000) ========== join string with 26 characters, with 5 character sep N/A 1.22 0.0 "ABCDE".join("ABC..Z") (*1000) ========== late match, 100 characters 2.52 2.68 94.0 s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E") (*100) 2.35 3.06 76.9 s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s) (*100) 1.55 1.61 96.2 s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E") (*100) 2.51 2.68 94.0 s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E") (*100) 3.57 4.66 76.7 s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E") (*100) 3.23 3.24 99.8 s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s) (*100) 2.35 2.56 91.7 s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E") (*100) 3.23 3.24 99.8 s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s) (*100) 3.58 3.92 91.4 s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s) (*100) 3.62 3.96 91.4 s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1) (*100) 2.89 3.38 85.4 s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1) (*100) ========== late match, two characters 0.52 0.52 99.5 ("AB"*300+"C").find("BC") (*1000) 0.69 0.90 76.5 ("AB"*300+"CA").find("CA") (*1000) 0.67 0.37 179.2 "BC" in ("AB"*300+"C") (*1000) 0.51 0.53 96.8 ("AB"*300+"C").index("BC") (*1000) 0.48 0.81 59.3 ("AB"*300+"C").partition("BC") (*1000) 0.55 0.55 101.5 ("C"+"AB"*300).rfind("CA") (*1000) 0.85 0.85 100.0 ("BC"+"AB"*300).rfind("BC") (*1000) 0.55 0.55 100.3 ("C"+"AB"*300).rindex("CA") (*1000) 0.52 0.60 87.1 ("C"+"AB"*300).rpartition("CA") (*1000) 0.78 0.82 95.4 ("C"+"AB"*300).rsplit("CA", 1) (*1000) 0.65 0.72 91.2 ("AB"*300+"C").split("BC", 1) (*1000) ========== no match, single character 0.77 0.77 100.6 ("A"*1000).find("B") (*1000) 0.98 0.63 155.1 "B" in "A"*1000 (*1000) 0.66 0.66 99.7 ("A"*1000).partition("B") (*1000) 0.77 0.77 100.4 ("A"*1000).rfind("B") (*1000) 0.66 0.66 99.7 ("A"*1000).rpartition("B") (*1000) 0.88 0.88 100.4 ("A"*1000).rsplit("B", 1) (*1000) 0.88 0.87 101.2 ("A"*1000).split("B", 1) (*1000) ========== no match, two characters 1.19 1.21 98.1 ("AB"*1000).find("BC") (*1000) 1.79 2.51 71.2 ("AB"*1000).find("CA") (*1000) 1.28 1.08 119.1 "BC" in "AB"*1000 (*1000) 1.10 2.11 52.1 ("AB"*1000).partition("BC") (*1000) 2.37 2.37 100.0 ("AB"*1000).rfind("BC") (*1000) 1.36 1.36 100.5 ("AB"*1000).rfind("CA") (*1000) 2.25 2.26 99.9 ("AB"*1000).rpartition("BC") (*1000) 2.38 2.62 90.7 ("AB"*1000).rsplit("BC", 1) (*1000) 1.18 1.30 90.1 ("AB"*1000).split("BC", 1) (*1000) ========== quick replace multiple character match 0.12 0.32 37.1 ("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1) (*10) ========== quick replace single character match 0.12 0.30 37.9 ("A" + ("Z"*128*1024)).replace("A", "BB", 1) (*10) ========== repeat 1 character 10 times 0.08 0.09 90.3 "A"*10 (*1000) ========== repeat 1 character 1000 times 0.16 0.19 82.2 "A"*1000 (*1000) ========== repeat 5 characters 10 times 0.11 0.12 98.3 "ABCDE"*10 (*1000) ========== repeat 5 characters 1000 times 0.40 0.58 67.9 "ABCDE"*1000 (*1000) ========== replace and expand multiple characters, big string 1.95 2.13 91.7 "...text.with.2000.newlines...replace("\n", "\r\n") (*10) ========== replace multiple characters, dna 2.93 3.25 90.3 dna.replace("ATC", "ATT") (*10) ========== replace single character 0.25 0.26 96.6 "This is a test".replace(" ", "\t") (*1000) ========== replace single character, big string 0.73 1.01 72.0 "...text.with.2000.lines...replace("\n", " ") (*10) ========== replace/remove multiple characters 0.30 0.34 89.0 "When shall we three meet again?".replace("ee", "") (*1000) ========== split 1 whitespace 0.12 0.13 93.3 ("Here are some words. "*2).partition(" ") (*1000) 0.11 0.11 98.8 ("Here are some words. "*2).rpartition(" ") (*1000) 0.32 0.37 86.5 ("Here are some words. "*2).rsplit(None, 1) (*1000) 0.32 0.33 96.9 ("Here are some words. "*2).split(None, 1) (*1000) ========== split 2000 newlines 1.76 2.19 80.5 "...text...".rsplit("\n") (*10) 1.72 2.10 81.9 "...text...".split("\n") (*10) 1.87 2.58 72.4 "...text...".splitlines() (*10) ========== split newlines 0.36 0.34 103.9 "this\nis\na\ntest\n".rsplit("\n") (*1000) 0.35 0.33 105.9 "this\nis\na\ntest\n".split("\n") (*1000) 0.31 0.34 89.7 "this\nis\na\ntest\n".splitlines() (*1000) ========== split on multicharacter separator (dna) 2.18 2.34 93.4 dna.rsplit("ACTAT") (*10) 2.50 2.64 94.5 dna.split("ACTAT") (*10) ========== split on multicharacter separator (small) 0.59 0.62 95.3 "this--is--a--test--of--the--emergency--broadcast--system".rsplit("--") (*1000) 0.55 0.59 93.1 "this--is--a--test--of--the--emergency--broadcast--system".split("--") (*1000) ========== split whitespace (huge) 1.54 2.34 65.5 human_text.rsplit() (*10) 1.51 2.22 68.3 human_text.split() (*10) ========== split whitespace (small) 0.46 0.60 76.5 ("Here are some words. "*2).rsplit() (*1000) 0.45 0.51 87.6 ("Here are some words. "*2).split() (*1000) ========== startswith multiple characters 0.18 0.18 97.3 "Andrew".startswith("Andrew") (*1000) ========== startswith multiple characters - not! 0.18 0.18 100.1 "Andrew".startswith("Anders") (*1000) ========== startswith single character 0.17 0.18 96.8 "Andrew".startswith("A") (*1000) ========== strip terminal newline 0.11 0.21 52.0 s="Hello!\n"; s[:-1] if s[-1]=="\n" else s (*1000) 0.06 0.07 92.1 "\nHello!".rstrip() (*1000) 0.06 0.07 92.2 "Hello!\n".rstrip() (*1000) 0.06 0.07 91.2 "\nHello!\n".strip() (*1000) 0.06 0.07 91.1 "\nHello!".strip() (*1000) 0.06 0.07 91.1 "Hello!\n".strip() (*1000) ========== strip terminal spaces and tabs 0.07 0.07 89.4 "\t \tHello".rstrip() (*1000) 0.07 0.07 91.4 "Hello\t \t".rstrip() (*1000) 0.04 0.05 88.7 "Hello\t \t".strip() (*1000) ========== tab split 0.57 0.56 100.8 GFF3_example.rsplit("\t", 8) (*1000) 0.53 0.53 100.7 GFF3_example.rsplit("\t") (*1000) 0.49 0.49 101.2 GFF3_example.split("\t", 8) (*1000) 0.51 0.49 103.5 GFF3_example.split("\t") (*1000) 102.13 125.57 81.3 TOTAL -- Terry Jan Reedy From ian.g.kelly at gmail.com Sat Jan 12 12:34:12 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 12 Jan 2013 10:34:12 -0700 Subject: String concatenation benchmarking weirdness In-Reply-To: References: Message-ID: On Sat, Jan 12, 2013 at 1:38 AM, wrote: > The difference between a correct (coherent) unicode handling and ... This thread was about byte string concatenation, not unicode, so your rant is not even on-topic here. From joshua.kimball at gmail.com Fri Jan 11 14:30:22 2013 From: joshua.kimball at gmail.com (joshua.kimball at gmail.com) Date: Fri, 11 Jan 2013 11:30:22 -0800 (PST) Subject: Move modules to submodules question Message-ID: <697510fc-4048-47fc-9104-41b845283011@googlegroups.com> I have a set of utility modules that were all added to a folder called (util_mods). Recently the set of modules grew to be too large and I've been working on splitting it up into sets of sub modules, for example, util_mods\set_a. The issue is that if I start moving modules to sub folders I have to go through and update literally thousands of scripts that import the module from util_mods. I was wondering if there was a way to move these modules into submodules while still maintaining the imports. For example "import util_mods.moda " would actually import as "util_mods.set_a.moda". My longterm goal is to update the scripts to point to the correct submodule/module however I was hoping for a short term solution to this so I can make the change immediately and update the other scripts over time. From __peter__ at web.de Fri Jan 11 15:33:51 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 11 Jan 2013 21:33:51 +0100 Subject: Move modules to submodules question References: <697510fc-4048-47fc-9104-41b845283011@googlegroups.com> Message-ID: joshua.kimball at gmail.com wrote: > I have a set of utility modules that were all added to a folder called > (util_mods). Recently the set of modules grew to be too large and I've > been working on splitting it up into sets of sub modules, for example, > util_mods\set_a. The issue is that if I start moving modules to sub > folders I have to go through and update literally thousands of scripts > that import the module from util_mods. I was wondering if there was a way > to move these modules into submodules while still maintaining the imports. > For example "import util_mods.moda " would actually import as > "util_mods.set_a.moda". > > My longterm goal is to update the scripts to point to the correct > submodule/module however I was hoping for a short term solution to this so > I can make the change immediately and update the other scripts over time. Put from .set_a import moda into util_mods/__init__.py Alternatively create an additional util_mods/moda.py containing nothing but from .set_a.moda import * From aug2uag at gmail.com Fri Jan 11 16:06:01 2013 From: aug2uag at gmail.com (Reza Fatahi) Date: Fri, 11 Jan 2013 13:06:01 -0800 Subject: Python and Blender Message-ID: Dear Programmers, My name is rex and i just finished basic medical science training and now i am transitioning to computers. I was funded by the NIH for eight years, and have my PhD in biomedicine. I am looking for a mentor who can help me transition to become a developer. My goals are to contribute to the Blender Python API and to develop a web app for the NIH. I have spent the past year on open courseware and app-making tutorials. There are published sequences that can be used to automate 3D rendering of confocal microscopy files using Blender, along with GIMP and/or Inkscape: https://science.nichd.nih.gov/confluence/display/bvig/Confocal+Laser+Scanning+Microscopy+to+3D+Isosurface+format#ConfocalLaserScanningMicroscopyto3DIsosurfaceformat-ImportintoBlender http://kardon.genetics.utah.edu/Publications/pdfs/WanHansenIEEEComptureGraphicsAppl2012.pdf The goal is to have a single page application where scientists can upload their .wrl file and the app returns a 3D image or multiple images of the confocal microscopy. In the future we can add options such as color etc, but if we get the basic shell I would be able to write a proposal/plan for further development. There are some Django templates available that may possibly help to start, i am looking for anyone interested to develop this single page application. Django templates: https://masterbranch.com/blender-django-projects If anyone is available as a mentor to assist my transition to a developer, I live in the Los Angeles area, I can travel and work, and this would be a dream come true. Please feel free to contact me anytime. email aug2uag at gmail.com phone (818) 571-3626 Yours Sincerely, reza (rex) fatahi From 129km09 at gmail.com Fri Jan 11 17:17:52 2013 From: 129km09 at gmail.com (su29090) Date: Fri, 11 Jan 2013 14:17:52 -0800 (PST) Subject: Problem with importing in Python Message-ID: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> I'm trying to import a python file it keeps saying: ImportError: cannot import name Circle Here is the file I'm trying to import: Circle.py import math class circle: #Construct a circle object def __init__(self, radius = 1): self.radius = radius def getPerimeter(self): return 2 * self.radius * math.pi def getArea(self): return self.radius * self.radius * math.pi def setRadius(self, radius): self.radius = radius from Circle import Circle def main(): #Create a circle with a radius 1 circle1 = Circle() print("The area of the circle of radius", circle1.radius, "is" , circle1.getArea()) #Create a circle with a radius 25 circle2 = Circle(25) print("The area of the circle of radius", circle2.radius, "is" , circle2.getArea()) #Create a circle with a radius 125 circle3 = Circle(125) print("The area of the circle of radius", circle3.radius, "is" , circle3.getArea()) #Modify circle radius circle2.radius = 100 # or Circle2.setRadius(100) print("The area of the circle of radius", circle2.radius, "is" , circle2.getArea()) main() # Call the main function How can I solve this problem? Thanks in advance. From sadzak at gmail.com Fri Jan 11 17:25:24 2013 From: sadzak at gmail.com (Adnan Sadzak) Date: Fri, 11 Jan 2013 23:25:24 +0100 Subject: Problem with importing in Python In-Reply-To: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: Python is case sensitive. Circle and circle is not same. /* sent from android */ On Jan 11, 2013 11:22 PM, "su29090" <129km09 at gmail.com> wrote: > I'm trying to import a python file it keeps saying: > > ImportError: cannot import name Circle > > Here is the file I'm trying to import: > > Circle.py > > import math > > class circle: > #Construct a circle object > def __init__(self, radius = 1): > self.radius = radius > > def getPerimeter(self): > return 2 * self.radius * math.pi > > def getArea(self): > return self.radius * self.radius * math.pi > > def setRadius(self, radius): > self.radius = radius > > from Circle import Circle > > def main(): > #Create a circle with a radius 1 > circle1 = Circle() > print("The area of the circle of radius", > circle1.radius, "is" , circle1.getArea()) > > #Create a circle with a radius 25 > circle2 = Circle(25) > print("The area of the circle of radius", > circle2.radius, "is" , circle2.getArea()) > > #Create a circle with a radius 125 > circle3 = Circle(125) > print("The area of the circle of radius", > circle3.radius, "is" , circle3.getArea()) > > #Modify circle radius > circle2.radius = 100 # or Circle2.setRadius(100) > print("The area of the circle of radius", > circle2.radius, "is" , circle2.getArea()) > > main() # Call the main function > > How can I solve this problem? > > Thanks in advance. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Jan 11 17:27:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Jan 2013 09:27:21 +1100 Subject: Problem with importing in Python In-Reply-To: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: On Sat, Jan 12, 2013 at 9:17 AM, su29090 <129km09 at gmail.com> wrote: > Circle.py > > class circle: > > from Circle import Circle Inside the Circle module is a class named circle. You can't import Circle from that. But Python isn't Java. You don't have to put each class into its own file. Just put class circle (or class Circle to follow Python naming convention) into the other file, whose name you haven't given. If they're already in the same file, then just drop the import. Easy! By the way: > main() # Call the main function You'll need to put that flush left. At the moment, that call is part of the definition of main(). Hope that helps! ChrisA From 129km09 at gmail.com Fri Jan 11 17:29:35 2013 From: 129km09 at gmail.com (su29090) Date: Fri, 11 Jan 2013 14:29:35 -0800 (PST) Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: <955b94c4-4916-4fb6-9917-5652ff88f6d4@googlegroups.com> On Friday, January 11, 2013 5:25:24 PM UTC-5, Adnan Sadzak wrote: > Python is case sensitive. > > Circle and circle is not same. > > > > > > > /* sent from android */ > > On Jan 11, 2013 11:22 PM, "su29090" <129... at gmail.com> wrote: > > I'm trying to import a python file it keeps saying: > > > > ImportError: cannot import name Circle > > > > Here is the file I'm trying to import: > > > > Circle.py > > > > import math > > > > class circle: > > ? ? #Construct a circle object > > ? ? def __init__(self, radius = 1): > > ? ? ? ? self.radius = radius > > > > ? ? def getPerimeter(self): > > ? ? ? ? return 2 * self.radius * math.pi > > > > ? ? def getArea(self): > > ? ? ? ? return self.radius * self.radius * math.pi > > > > ? ? def setRadius(self, radius): > > ? ? ? ? self.radius = radius > > > > from Circle import Circle > > > > def main(): > > ? ? #Create a circle with a radius 1 > > ? ? circle1 = Circle() > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle1.radius, "is" , circle1.getArea()) > > > > ? ? #Create a circle with a radius 25 > > ? ? circle2 = Circle(25) > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle2.radius, "is" , circle2.getArea()) > > > > ? ? #Create a circle with a radius 125 > > ? ? circle3 = Circle(125) > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle3.radius, "is" , circle3.getArea()) > > > > ? ? #Modify circle radius > > ? ? circle2.radius = 100 # or Circle2.setRadius(100) > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle2.radius, "is" , circle2.getArea()) > > > > ? ? main() # Call the main function > > > > How can I solve this problem? > > > > Thanks in advance. > > > > -- > > http://mail.python.org/mailman/listinfo/python-list It still keeps showing the same message. From 129km09 at gmail.com Fri Jan 11 17:29:35 2013 From: 129km09 at gmail.com (su29090) Date: Fri, 11 Jan 2013 14:29:35 -0800 (PST) Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: <955b94c4-4916-4fb6-9917-5652ff88f6d4@googlegroups.com> On Friday, January 11, 2013 5:25:24 PM UTC-5, Adnan Sadzak wrote: > Python is case sensitive. > > Circle and circle is not same. > > > > > > > /* sent from android */ > > On Jan 11, 2013 11:22 PM, "su29090" <129... at gmail.com> wrote: > > I'm trying to import a python file it keeps saying: > > > > ImportError: cannot import name Circle > > > > Here is the file I'm trying to import: > > > > Circle.py > > > > import math > > > > class circle: > > ? ? #Construct a circle object > > ? ? def __init__(self, radius = 1): > > ? ? ? ? self.radius = radius > > > > ? ? def getPerimeter(self): > > ? ? ? ? return 2 * self.radius * math.pi > > > > ? ? def getArea(self): > > ? ? ? ? return self.radius * self.radius * math.pi > > > > ? ? def setRadius(self, radius): > > ? ? ? ? self.radius = radius > > > > from Circle import Circle > > > > def main(): > > ? ? #Create a circle with a radius 1 > > ? ? circle1 = Circle() > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle1.radius, "is" , circle1.getArea()) > > > > ? ? #Create a circle with a radius 25 > > ? ? circle2 = Circle(25) > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle2.radius, "is" , circle2.getArea()) > > > > ? ? #Create a circle with a radius 125 > > ? ? circle3 = Circle(125) > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle3.radius, "is" , circle3.getArea()) > > > > ? ? #Modify circle radius > > ? ? circle2.radius = 100 # or Circle2.setRadius(100) > > ? ? print("The area of the circle of radius", > > ? ? ? ? ? circle2.radius, "is" , circle2.getArea()) > > > > ? ? main() # Call the main function > > > > How can I solve this problem? > > > > Thanks in advance. > > > > -- > > http://mail.python.org/mailman/listinfo/python-list It still keeps showing the same message. From 129km09 at gmail.com Fri Jan 11 17:38:30 2013 From: 129km09 at gmail.com (su29090) Date: Fri, 11 Jan 2013 14:38:30 -0800 (PST) Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: On Friday, January 11, 2013 5:27:21 PM UTC-5, Chris Angelico wrote: > On Sat, Jan 12, 2013 at 9:17 AM, su29090 wrote: > > > Circle.py > > > > > > class circle: > > > > > > from Circle import Circle > > > > Inside the Circle module is a class named circle. You can't import > > Circle from that. > > > > But Python isn't Java. You don't have to put each class into its own > > file. Just put class circle (or class Circle to follow Python naming > > convention) into the other file, whose name you haven't given. > > > > If they're already in the same file, then just drop the import. Easy! > > > > By the way: > > > main() # Call the main function > > You'll need to put that flush left. At the moment, that call is part > > of the definition of main(). > > > > Hope that helps! > > > > ChrisA It worked! Thanks so much! :) From 129km09 at gmail.com Fri Jan 11 17:38:30 2013 From: 129km09 at gmail.com (su29090) Date: Fri, 11 Jan 2013 14:38:30 -0800 (PST) Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: On Friday, January 11, 2013 5:27:21 PM UTC-5, Chris Angelico wrote: > On Sat, Jan 12, 2013 at 9:17 AM, su29090 wrote: > > > Circle.py > > > > > > class circle: > > > > > > from Circle import Circle > > > > Inside the Circle module is a class named circle. You can't import > > Circle from that. > > > > But Python isn't Java. You don't have to put each class into its own > > file. Just put class circle (or class Circle to follow Python naming > > convention) into the other file, whose name you haven't given. > > > > If they're already in the same file, then just drop the import. Easy! > > > > By the way: > > > main() # Call the main function > > You'll need to put that flush left. At the moment, that call is part > > of the definition of main(). > > > > Hope that helps! > > > > ChrisA It worked! Thanks so much! :) From d at davea.name Fri Jan 11 17:43:10 2013 From: d at davea.name (Dave Angel) Date: Fri, 11 Jan 2013 17:43:10 -0500 Subject: Problem with importing in Python In-Reply-To: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: <50F0957E.4060707@davea.name> On 01/11/2013 05:17 PM, su29090 wrote: > I'm trying to import a python file it keeps saying: > > ImportError: cannot import name Circle > > Here is the file I'm trying to import: > > Circle.py > > import math > > class circle: > #Construct a circle object > def __init__(self, radius = 1): > self.radius = radius > > def getPerimeter(self): > return 2 * self.radius * math.pi > > def getArea(self): > return self.radius * self.radius * math.pi > > def setRadius(self, radius): > self.radius = radius > > from Circle import Circle > > def main(): > #Create a circle with a radius 1 > circle1 = Circle() > print("The area of the circle of radius", > circle1.radius, "is" , circle1.getArea()) > > #Create a circle with a radius 25 > circle2 = Circle(25) > print("The area of the circle of radius", > circle2.radius, "is" , circle2.getArea()) > > #Create a circle with a radius 125 > circle3 = Circle(125) > print("The area of the circle of radius", > circle3.radius, "is" , circle3.getArea()) > > #Modify circle radius > circle2.radius = 100 # or Circle2.setRadius(100) > print("The area of the circle of radius", > circle2.radius, "is" , circle2.getArea()) > > main() # Call the main function > > How can I solve this problem? > > Thanks in advance. > As Adnan has pointed out, Python is case insensitive. You're apparently trying to refer to the class Circle by the name circle, or the other way around. Some comments on asking clear questions: 1) Specify the Python version. I presume 3.3 It probably doesn't matter here, but it might have. 2) When showing two source files, identify where each starts and ends, and what the second one is called. 3) When showing an error, include the entire traceback, not just the last line. Now, there are conventions to follow as well (see Pep8). One is that modules should use all lowercase, and classes should begin with a capital. So the source file of your module should be named circle.py and the class Circle. When you imported and instantiated the class, you assumed it was called Circle, but when you defined it, you mistakenly called it circle. The next error is the accidental indentation of the call to main(). As it stands now, it's a recursive call to itself. And main() will never be called, because there's no call at top-level. -- DaveA From 129km09 at gmail.com Fri Jan 11 18:23:17 2013 From: 129km09 at gmail.com (su29090) Date: Fri, 11 Jan 2013 15:23:17 -0800 (PST) Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: On Friday, January 11, 2013 5:43:10 PM UTC-5, Dave Angel wrote: > On 01/11/2013 05:17 PM, su29090 wrote: > > > I'm trying to import a python file it keeps saying: > > > > > > ImportError: cannot import name Circle > > > > > > Here is the file I'm trying to import: > > > > > > Circle.py > > > > > > import math > > > > > > class circle: > > > #Construct a circle object > > > def __init__(self, radius = 1): > > > self.radius = radius > > > > > > def getPerimeter(self): > > > return 2 * self.radius * math.pi > > > > > > def getArea(self): > > > return self.radius * self.radius * math.pi > > > > > > def setRadius(self, radius): > > > self.radius = radius > > > > > > from Circle import Circle > > > > > > def main(): > > > #Create a circle with a radius 1 > > > circle1 = Circle() > > > print("The area of the circle of radius", > > > circle1.radius, "is" , circle1.getArea()) > > > > > > #Create a circle with a radius 25 > > > circle2 = Circle(25) > > > print("The area of the circle of radius", > > > circle2.radius, "is" , circle2.getArea()) > > > > > > #Create a circle with a radius 125 > > > circle3 = Circle(125) > > > print("The area of the circle of radius", > > > circle3.radius, "is" , circle3.getArea()) > > > > > > #Modify circle radius > > > circle2.radius = 100 # or Circle2.setRadius(100) > > > print("The area of the circle of radius", > > > circle2.radius, "is" , circle2.getArea()) > > > > > > main() # Call the main function > > > > > > How can I solve this problem? > > > > > > Thanks in advance. > > > > > > > As Adnan has pointed out, Python is case insensitive. You're apparently > > trying to refer to the class Circle by the name circle, or the other way > > around. > > > > Some comments on asking clear questions: > > > > 1) Specify the Python version. I presume 3.3 It probably doesn't > > matter here, but it might have. > > 2) When showing two source files, identify where each starts and ends, > > and what the second one is called. > > 3) When showing an error, include the entire traceback, not just the > > last line. > > > > Now, there are conventions to follow as well (see Pep8). One is that > > modules should use all lowercase, and classes should begin with a > > capital. So the source file of your module should be named > > circle.py and the class Circle. When you imported and instantiated > > the class, you assumed it was called Circle, but when you defined it, > > you mistakenly called it circle. > > > > The next error is the accidental indentation of the call to main(). As > > it stands now, it's a recursive call to itself. And main() will never > > be called, because there's no call at top-level. > > > > > > > > > > > > -- > > > > DaveA Thanks for explanation which was very clear! From 129km09 at gmail.com Fri Jan 11 18:23:17 2013 From: 129km09 at gmail.com (su29090) Date: Fri, 11 Jan 2013 15:23:17 -0800 (PST) Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: On Friday, January 11, 2013 5:43:10 PM UTC-5, Dave Angel wrote: > On 01/11/2013 05:17 PM, su29090 wrote: > > > I'm trying to import a python file it keeps saying: > > > > > > ImportError: cannot import name Circle > > > > > > Here is the file I'm trying to import: > > > > > > Circle.py > > > > > > import math > > > > > > class circle: > > > #Construct a circle object > > > def __init__(self, radius = 1): > > > self.radius = radius > > > > > > def getPerimeter(self): > > > return 2 * self.radius * math.pi > > > > > > def getArea(self): > > > return self.radius * self.radius * math.pi > > > > > > def setRadius(self, radius): > > > self.radius = radius > > > > > > from Circle import Circle > > > > > > def main(): > > > #Create a circle with a radius 1 > > > circle1 = Circle() > > > print("The area of the circle of radius", > > > circle1.radius, "is" , circle1.getArea()) > > > > > > #Create a circle with a radius 25 > > > circle2 = Circle(25) > > > print("The area of the circle of radius", > > > circle2.radius, "is" , circle2.getArea()) > > > > > > #Create a circle with a radius 125 > > > circle3 = Circle(125) > > > print("The area of the circle of radius", > > > circle3.radius, "is" , circle3.getArea()) > > > > > > #Modify circle radius > > > circle2.radius = 100 # or Circle2.setRadius(100) > > > print("The area of the circle of radius", > > > circle2.radius, "is" , circle2.getArea()) > > > > > > main() # Call the main function > > > > > > How can I solve this problem? > > > > > > Thanks in advance. > > > > > > > As Adnan has pointed out, Python is case insensitive. You're apparently > > trying to refer to the class Circle by the name circle, or the other way > > around. > > > > Some comments on asking clear questions: > > > > 1) Specify the Python version. I presume 3.3 It probably doesn't > > matter here, but it might have. > > 2) When showing two source files, identify where each starts and ends, > > and what the second one is called. > > 3) When showing an error, include the entire traceback, not just the > > last line. > > > > Now, there are conventions to follow as well (see Pep8). One is that > > modules should use all lowercase, and classes should begin with a > > capital. So the source file of your module should be named > > circle.py and the class Circle. When you imported and instantiated > > the class, you assumed it was called Circle, but when you defined it, > > you mistakenly called it circle. > > > > The next error is the accidental indentation of the call to main(). As > > it stands now, it's a recursive call to itself. And main() will never > > be called, because there's no call at top-level. > > > > > > > > > > > > -- > > > > DaveA Thanks for explanation which was very clear! From timr at probo.com Fri Jan 11 23:37:37 2013 From: timr at probo.com (Tim Roberts) Date: Fri, 11 Jan 2013 20:37:37 -0800 Subject: Problem with importing in Python References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: Dave Angel wrote: > >As Adnan has pointed out, Python is case insensitive. That's not really what you meant to say... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rosuav at gmail.com Fri Jan 11 23:54:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Jan 2013 15:54:37 +1100 Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: On Sat, Jan 12, 2013 at 3:37 PM, Tim Roberts wrote: > Dave Angel wrote: >> >>As Adnan has pointed out, Python is case insensitive. > > That's not really what you meant to say... UNinsensitive, your Majesty means, of course. UNinsensitive, of course, I meant. *watches the jurors write it down, some each way* ChrisA From d at davea.name Sat Jan 12 00:14:46 2013 From: d at davea.name (Dave Angel) Date: Sat, 12 Jan 2013 00:14:46 -0500 Subject: Problem with importing in Python In-Reply-To: References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: <50F0F146.9000502@davea.name> On 01/11/2013 11:37 PM, Tim Roberts wrote: > Dave Angel wrote: >> As Adnan has pointed out, Python is case insensitive. > That's not really what you meant to say... Nope. I meant Python is case sensitive. Thanks for the catch. I think the rest of my discourse made it clear that case matters. -- DaveA From tjreedy at udel.edu Fri Jan 11 22:53:47 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 Jan 2013 22:53:47 -0500 Subject: Problem with importing in Python In-Reply-To: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Message-ID: On 1/11/2013 5:17 PM, su29090 wrote: > Circle.py > > import math > > class circle: By current convention, you should call the file 'circle.py' and the class 'Circle'. Using all lower case for module filenames is the sanest thing to do in a world where different filesystems do different things with casing. -- Terry Jan Reedy From adelbertc at gmail.com Fri Jan 11 17:23:05 2013 From: adelbertc at gmail.com (Adelbert Chang) Date: Fri, 11 Jan 2013 14:23:05 -0800 (PST) Subject: Dependency management in Python? Message-ID: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> Hi all, I've been using Python for a while now but one of my concerns is if it is possible to have some sort of dependency management (not sure if right term) for Python? In the Scala language there is the Simple Build Tool that lets me specify on a project-by-project basis which libraries I want to use (provided they are in a central repository somewhere) and it will download them for me. Better yet, when a new version comes out I need only change the SBT configuration file for that project and it will download it for me. Is there something like this for Python. I am typically wary of downloading Python modules I use like NumPy, SciPy, NetworkX, etc because I want to be able to upgrade at any time and doing so seems to be a hassle - in fact, I am not entirely sure how to "upgrade". Thank you and regards, -Adelbert From rodrick.brown at gmail.com Fri Jan 11 17:34:40 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 11 Jan 2013 17:34:40 -0500 Subject: Dependency management in Python? In-Reply-To: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> References: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> Message-ID: On Fri, Jan 11, 2013 at 5:23 PM, Adelbert Chang wrote: > Hi all, > > I've been using Python for a while now but one of my concerns is if it is > possible to have some sort of dependency management (not sure if right > term) for Python? > > In the Scala language there is the Simple Build Tool that lets me specify > on a project-by-project basis which libraries I want to use (provided they > are in a central repository somewhere) and it will download them for me. > Better yet, when a new version comes out I need only change the SBT > configuration file for that project and it will download it for me. > > Is there something like this for Python. I am typically wary of > downloading Python modules I use like NumPy, SciPy, NetworkX, etc because I > want to be able to upgrade at any time and doing so seems to be a hassle - > in fact, I am not entirely sure how to "upgrade". > > Checkout PIP/setuptools and virtualenv > Thank you and regards, > -Adelbert > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at feete.org Fri Jan 11 18:04:38 2013 From: ian at feete.org (Ian Foote) Date: Fri, 11 Jan 2013 23:04:38 +0000 Subject: Dependency management in Python? In-Reply-To: References: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> Message-ID: <50F09A86.2030109@feete.org> On 11/01/13 22:34, Rodrick Brown wrote: > On Fri, Jan 11, 2013 at 5:23 PM, Adelbert Chang > wrote: > > Hi all, > > I've been using Python for a while now but one of my concerns is if > it is possible to have some sort of dependency management (not sure > if right term) for Python? > > In the Scala language there is the Simple Build Tool that lets me > specify on a project-by-project basis which libraries I want to use > (provided they are in a central repository somewhere) and it will > download them for me. Better yet, when a new version comes out I > need only change the SBT configuration file for that project and it > will download it for me. > > Is there something like this for Python. I am typically wary of > downloading Python modules I use like NumPy, SciPy, NetworkX, etc > because I want to be able to upgrade at any time and doing so seems > to be a hassle - in fact, I am not entirely sure how to "upgrade". > > > Checkout PIP/setuptools and virtualenv > > Thank you and regards, > -Adelbert > -- > http://mail.python.org/mailman/listinfo/python-list > pip and virtualenv is a great combination. I also like to use virtualenvwrapper for convenience, but it isn't necessary. Ian F From adelbertc at gmail.com Fri Jan 11 21:42:18 2013 From: adelbertc at gmail.com (Adelbert Chang) Date: Fri, 11 Jan 2013 18:42:18 -0800 (PST) Subject: Dependency management in Python? In-Reply-To: References: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> Message-ID: <69690331-5194-443e-bf6b-fad0c3bf3ff4@googlegroups.com> Perfect, PIP and virtualenv look great. Another question - how do we then get PIP to the latest version? Or is it relatively easy to uninstall/reinstall PIP? From adelbertc at gmail.com Fri Jan 11 21:42:18 2013 From: adelbertc at gmail.com (Adelbert Chang) Date: Fri, 11 Jan 2013 18:42:18 -0800 (PST) Subject: Dependency management in Python? In-Reply-To: References: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> Message-ID: <69690331-5194-443e-bf6b-fad0c3bf3ff4@googlegroups.com> Perfect, PIP and virtualenv look great. Another question - how do we then get PIP to the latest version? Or is it relatively easy to uninstall/reinstall PIP? From thbach at students.uni-mainz.de Sat Jan 12 07:43:28 2013 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Sat, 12 Jan 2013 13:43:28 +0100 Subject: Dependency management in Python? In-Reply-To: <69690331-5194-443e-bf6b-fad0c3bf3ff4@googlegroups.com> References: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> <69690331-5194-443e-bf6b-fad0c3bf3ff4@googlegroups.com> Message-ID: <20130112124328.GA3735@taris.box> On Fri, Jan 11, 2013 at 06:42:18PM -0800, Adelbert Chang wrote: > Another question - how do we then get PIP to the latest version? Or > is it relatively easy to uninstall/reinstall PIP? Simply do a $ pip install -U distribute $ pip install -U pip from time to time in your virtual environment. As a side note: some versions of distribute, pip and virtualenv do interact rather poorly on Python 3. Upgrading via easy_install: $ easy_install -U distribute $ easy_install -U pip usually solves these issues. Have fun! Thomas From dieter at handshake.de Sat Jan 12 02:14:30 2013 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 12 Jan 2013 08:14:30 +0100 Subject: Dependency management in Python? References: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> Message-ID: <87ip72an55.fsf@handshake.de> Adelbert Chang writes: > In the Scala language there is the Simple Build Tool that lets me specify on a project-by-project basis which libraries I want to use (provided they are in a central repository somewhere) and it will download them for me. Better yet, when a new version comes out I need only change the SBT configuration file for that project and it will download it for me. You might also have a look at "zc.buildout" (--> on "PyPI"). From wuwei23 at gmail.com Sat Jan 12 02:38:04 2013 From: wuwei23 at gmail.com (alex23) Date: Fri, 11 Jan 2013 23:38:04 -0800 (PST) Subject: Dependency management in Python? References: <6b91570c-9cf0-4caf-8727-b463c6d098cd@googlegroups.com> Message-ID: On 12 Jan, 17:14, Dieter Maurer wrote: > Adelbert Chang writes: > > In the Scala language there is the Simple Build Tool that lets me specify on a project-by-project basis which libraries I want to use (provided they are in a central repository somewhere) and it will download them for me. Better yet, when a new version comes out I need only change the SBT configuration file for that project and it will download it for me. > > You might also have a look at "zc.buildout" (--> on "PyPI"). +1 for zc.buildout I find virtualenv is great for setting up quick prototyping environments, while zc.buildout recipes are a much better approach for group development. From reganrexman at gmail.com Fri Jan 11 23:29:09 2013 From: reganrexman at gmail.com (reganrexman) Date: Fri, 11 Jan 2013 22:29:09 -0600 Subject: Fundamentals of Materials Science and Engineering- An Integrated Approach, 3rd Ed by Callister Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTIONS MANUAL TO Field and Wave Electromagnetics 2nd Ed by David K. Cheng SOLUTIONS MANUAL TO Financial Accounting 6th E with Annual Report by Libby, Short SOLUTIONS MANUAL TO Financial Accounting 6th Ed by Harrison SOLUTIONS MANUAL TO Financial Accounting An Integrated Approach, 6th Ed by Gibbins SOLUTIONS MANUAL TO Financial Management- Principles and Applications, 10th Ed by Keown, Scott SOLUTIONS MANUAL TO Financial Management- Theory and Practice 12 th ED by Brigham, Ehrhardt SOLUTIONS MANUAL TO Financial Reporting and Analysis Using Financial Accounting Information 10th Ed by Gibson SOLUTIONS MANUAL TO Financial Reporting and Analysis, 3E by Revsine, Collins, Johnson SOLUTIONS MANUAL TO Finite Element Techniques in Structural Mechanics Ross SOLUTIONS MANUAL TO First Course in Abstract Algebra, 3rd Ed by Joseph J. Rotman SOLUTIONS MANUAL TO First Course in Probability (7th Ed., Sheldon Ross) SOLUTIONS MANUAL TO Fluid Mechanics (5th Ed., White) SOLUTIONS MANUAL TO Fluid Mechanics 4th Ed by Cohen, Kundu SOLUTIONS MANUAL TO Fluid Mechanics 4th Edition by Frank M. White SOLUTIONS MANUAL TO Fluid Mechanics and Thermodynamics of Turbomachinery (5th Ed., S.L. Dixon) SOLUTIONS MANUAL TO Fluid Mechanics by CENGEL SOLUTIONS MANUAL TO Fluid Mechanics Egon Krause SOLUTIONS MANUAL TO Fluid Mechanics Fundamentals and Applications by Cengel & Cimbala SOLUTIONS MANUAL TO Fluid Mechanics with Engineering Applications, 10th Edition, by Finnemore SOLUTIONS MANUAL TO Foundations of Applied Combinatorics by Bender, Williamson SOLUTIONS MANUAL TO Foundations of Colloid Science 2e , Hunter SOLUTIONS MANUAL TO Foundations of Electromagnetic Theory by John R. Reitz, Frederick J. Milford SOLUTIONS MANUAL TO Foundations of Modern Macroeconomics 2nd Ed by Heijdra, Reijnders, Romp SOLUTIONS MANUAL TO Fourier and Laplace Transform - Antwoorden SOLUTIONS MANUAL TO Fractal Geometry Mathematical Foundations and Applications, 2nd Ed Kenneth Falcone SOLUTIONS MANUAL TO fracture mechanics ; fundamentals and applications, 2E, by T.L. Anderson SOLUTIONS MANUAL TO From Polymers to Plastics By A.K. van der Vegt SOLUTIONS MANUAL TO Fundamental Methods of Mathematical Economics 4th E by Chiang,Wainwright SOLUTIONS MANUAL TO Fundamental Quantum Mechanics for Engineers by Leon van Dommelen SOLUTIONS MANUAL TO Fundamentals of Advanced Accounting By Fischer, Taylor SOLUTIONS MANUAL TO Fundamentals of Aerodynamics ( 3 Ed., Anderson) SOLUTIONS MANUAL TO Fundamentals of Aerodynamics (2 Ed., Anderson) SOLUTIONS MANUAL TO Fundamentals of Aircraft Structural Analysis by Howard D. Curtis SOLUTIONS MANUAL TO Fundamentals of Applied Electromagnetics (5th Ed., Fawwaz T. Ulaby) SOLUTIONS MANUAL TO Fundamentals of Chemical Reaction Engineering by Davis SOLUTIONS MANUAL TO Fundamentals of Complex Analysis ( 3rd Ed., E. Saff & Arthur Snider ) SOLUTIONS MANUAL TO Fundamentals of Computer Organization and Architecture by Abd-El-Barr, El-Rewini SOLUTIONS MANUAL TO Fundamentals of Corporate Finance 8th edition by Ross SOLUTIONS MANUAL TO Fundamentals of Corporate Finance 9th edition by Ross SOLUTIONS MANUAL TO Fundamentals of Corporate Finance, 4th Edition (Brealey, Myers, Marcus) SOLUTIONS MANUAL TO Fundamentals of Differential Equations 7E Kent Nagle, B. Saff, Snider SOLUTIONS MANUAL TO Fundamentals of Differential Equations and Boundary Value Problems, 6th Ed by Nagle ,Saff, Snider SOLUTIONS MANUAL TO Fundamentals of Digital Logic with VHDL Design (1st Ed., Stephen Brown Vranesic) SOLUTIONS MANUAL TO Fundamentals of Digital Signal Processing Using Matlab 2nd Edition by Robert J. Schilling, Sandra L. Harris SOLUTIONS MANUAL TO Fundamentals of Electric Circuits (2nd.ed.) by C.K.Alexander M.N.O.Sadiku SOLUTIONS MANUAL TO Fundamentals of Electric Circuits (4E., Charles Alexander & Matthew Sadiku) SOLUTIONS MANUAL TO Fundamentals of Electromagnetics with Engineering Applications (Stuart Wentworth) SOLUTIONS MANUAL TO Fundamentals of Electronic Circuit Design , Comer SOLUTIONS MANUAL TO Fundamentals of Engineering Economics 2nd E by Chan S. Park SOLUTIONS MANUAL TO FUNDAMENTALS OF ENGINEERING ELECTROMAGNETICS, by DAVID CHENG SOLUTIONS MANUAL TO Fundamentals of Engineering Thermodynamics, 5th Ed (Michael J. Moran, Howard N. Shapiro) SOLUTIONS MANUAL TO Fundamentals of Engineering Thermodynamics, 6th Ed (Michael J. Moran, Howard N. Shapiro) SOLUTIONS MANUAL TO Fundamentals of Financial Management 12th edition James C. Van Horne, Wachowicz SOLUTIONS MANUAL TO Fundamentals of Fluid Mechanics 5th Ed Munson Young Okiishi SOLUTIONS MANUAL TO Fundamentals of Fluid Mechanics 6th Ed by Munson SOLUTIONS MANUAL TO Fundamentals of Fluid Mechanics, 4E (Bruce R. Munson, Donald F. Young, Theodore H.) SOLUTIONS MANUAL TO Fundamentals of Heat and Mass Transfer - 5th Edition F.P. Incropera D.P. DeWitt SOLUTIONS MANUAL TO Fundamentals of Heat and Mass Transfer (4th Ed., Incropera, DeWitt) SOLUTIONS MANUAL TO Fundamentals of Heat and Mass Transfer (6th Ed., Incropera, DeWitt) SOLUTIONS MANUAL TO Fundamentals of Hydraulic Engineering Systems 4th E by Houghtalen,Akan,Hwang SOLUTIONS MANUAL TO Fundamentals of Investments, 5th E by Jordan, Miller SOLUTIONS MANUAL TO Fundamentals of Logic Design, 5th Ed., by Charles Roth SOLUTIONS MANUAL TO Fundamentals of Machine Component Design (3rd Ed., Juvinall) SOLUTIONS MANUAL TO Fundamentals of Machine Component Design 4th Ed by Juvinall SOLUTIONS MANUAL TO Fundamentals of Machine Elements 2nd E by Bernard Hamrock SOLUTIONS MANUAL TO Fundamentals of Machine Elements by Bernard Hamrock SOLUTIONS MANUAL TO Fundamentals of Manufacturing 2nd Edition by Philip D. Rufe SOLUTIONS MANUAL TO Fundamentals of Materials Science and Engineering- An Integrated Approach, 3rd Ed by Callister SOLUTIONS MANUAL TO Fundamentals of Microelectronics by Behzad Razavi SOLUTIONS MANUAL TO Fundamentals of Modern Manufacturing 3rd Ed by Mikell P. Groover SOLUTIONS MANUAL TO Fundamentals of Modern Manufacturing: Materials, Processes, and Systems (2nd Ed., Mikell P. Groover) SOLUTIONS MANUAL TO Fundamentals of Momentum, Heat and Mass Transfer, 4th Ed by Welty,Wilson SOLUTIONS MANUAL TO Fundamentals of Momentum, Heat and Mass Transfer, 5th Ed by Welty,Wilson SOLUTIONS MANUAL TO Fundamentals of Organic Chemistry, 5E, by T. W. Graham Solomons SOLUTIONS MANUAL TO Fundamentals of Physics (7th Ed., David Halliday, Robert Resnick & Jearl Walker) SOLUTIONS MANUAL TO Fundamentals of Physics 9th Ed by Resnick, Walker, Halliday SOLUTIONS MANUAL TO Fundamentals of Physics, 8th Edition Halliday, Resnick, Walker SOLUTIONS MANUAL TO Fundamentals of Power Semiconductor Devices By Jayant Baliga SOLUTIONS MANUAL TO Fundamentals of Probability, with Stochastic Processes (3rd Ed., Saeed Ghahramani) SOLUTIONS MANUAL TO Fundamentals of Quantum Mechanics (C.L. Tang) SOLUTIONS MANUAL TO Fundamentals of Semiconductor Devices, 1st Edition by Anderson SOLUTIONS MANUAL TO Fundamentals of Signals and Systems Using the Web and Matlab (3rd Ed., Kamen & Bonnie S Heck) SOLUTIONS MANUAL TO Fundamentals of Structural Analysis 3rd Ed by Leet SOLUTIONS MANUAL TO Fundamentals of Thermal-Fluid Sciences, 2nd Ed. by Cengel SOLUTIONS MANUAL TO Fundamentals of Thermodynamics 5th Ed by Sonntag, Borgnakke and Van Wylen SOLUTIONS MANUAL TO Fundamentals of Thermodynamics 6th Ed by Sonntag, Borgnakke & Van Wylen SOLUTIONS MANUAL TO Fundamentals of Wireless Communication by Tse and Viswanath SOLUTIONS MANUAL TO Fundamentals of Wireless Communication by Tse, Viswanath SOLUTIONS MANUAL TO Gas Dynamics (3rd Ed., John & Keith) SOLUTIONS MANUAL TO General Chemistry 9 Edition by Ebbings, Gammon SOLUTIONS MANUAL TO General Chemistry, 8th Edition by Ralph H. Petrucci; William S. Harwood; Geoffrey Herring SOLUTIONS MANUAL TO Geometry - A High School Course by S. Lang and G. Murrow SOLUTIONS MANUAL TO Geometry ( Glencoe ) SOLUTIONS MANUAL TO Geometry and Discrete Mathematics Addison Wesley SOLUTIONS MANUAL TO Green Engineering - Environmentally Conscious Design of Chemical Processes by Shonnard, Allen SOLUTIONS MANUAL TO Guide to Energy Management, 6th Edition by Klaus Dieter E. Pawlik SOLUTIONS MANUAL TO Guide to Energy Management, Fifth Edition, Klaus-Dieter E. Pawlik From aleksey at silk.bz Fri Jan 11 23:43:55 2013 From: aleksey at silk.bz (aleksey at silk.bz) Date: Fri, 11 Jan 2013 20:43:55 -0800 (PST) Subject: async fuction Message-ID: <6bcc6374-88bb-47a0-b2c3-8082794ed158@googlegroups.com> Hello. Can someone help me to resolv error. code: import threading class TimeoutError(RuntimeError): pass class AsyncCall(object): def __init__(self, fnc, callback = None): self.Callable = fnc self.Callback = callback def __call__(self, *args, **kwargs): self.Thread = threading.Thread(target = self.run, name = self.Callable.__name__, args = args, kwargs = kwargs) self.Thread.start() return self def wait(self, timeout = None): self.Thread.join(timeout) if self.Thread.isAlive(): raise TimeoutError() else: return self.Result def run(self, *args, **kwargs): self.Result = self.Callable(*args, **kwargs) if self.Callback: self.Callback(self.Result) class AsyncMethod(object): def __init__(self, fnc, callback=None): self.Callable = fnc self.Callback = callback def __call__(self, *args, **kwargs): return AsyncCall(self.Callable, self.Callback)(*args, **kwargs) def Async(fnc = None, callback = None): if fnc == None: def AddAsyncCallback(fnc): return AsyncMethod(fnc, callback) return AddAsyncCallback else: return AsyncMethod(fnc, callback) @Async def fnc(pi, pp): print "fnc-" i=pi while ( i < 10000000 ) : i=i+1 print "fnc+" pass @Async def fnc1(pp): print "fnc1-",pp @Async def fnc2(): print "fnc2-" i=0 while ( i < 100000 ) : i=i+1 print "fnc2+" pass fnc(i=0,pp="123123") fnc1() error: Exception in thread fnc1: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner self.run() File "C:\Python27\lib\threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "C:/Users/rootiks/YandexDisk/py/myftpbackup/asynclib.py", line 26, in run self.Result = self.Callable(*args, **kwargs) TypeError: fnc1() takes exactly 1 argument (0 given) From rosuav at gmail.com Fri Jan 11 23:52:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Jan 2013 15:52:22 +1100 Subject: async fuction In-Reply-To: <6bcc6374-88bb-47a0-b2c3-8082794ed158@googlegroups.com> References: <6bcc6374-88bb-47a0-b2c3-8082794ed158@googlegroups.com> Message-ID: On Sat, Jan 12, 2013 at 3:43 PM, wrote: > def fnc1(pp): > print "fnc1-",pp > > fnc1() Like the message says, the function has been defined to take one argument, and you're giving it none. Try giving it an argument: fnc1("five-minute") ChrisA From python at mrabarnett.plus.com Sat Jan 12 13:01:35 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Jan 2013 18:01:35 +0000 Subject: async fuction In-Reply-To: <6bcc6374-88bb-47a0-b2c3-8082794ed158@googlegroups.com> References: <6bcc6374-88bb-47a0-b2c3-8082794ed158@googlegroups.com> Message-ID: <50F1A4FF.7050309@mrabarnett.plus.com> On 2013-01-12 04:43, aleksey at silk.bz wrote: > Hello. > > Can someone help me to resolv error. > > code: > [snip] > > @Async > def fnc(pi, pp): > > print "fnc-" > i=pi > while ( i < 10000000 ) : > i=i+1 > print "fnc+" > pass > > @Async > def fnc1(pp): > print "fnc1-",pp > > > @Async > def fnc2(): > print "fnc2-" > i=0 > while ( i < 100000 ) : > i=i+1 > print "fnc2+" > pass > > fnc(i=0,pp="123123") > fnc1() > > > error: > > Exception in thread fnc1: > Traceback (most recent call last): > File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner > self.run() > File "C:\Python27\lib\threading.py", line 504, in run > self.__target(*self.__args, **self.__kwargs) > File "C:/Users/rootiks/YandexDisk/py/myftpbackup/asynclib.py", line 26, in run > self.Result = self.Callable(*args, **kwargs) > TypeError: fnc1() takes exactly 1 argument (0 given) > 1. You're calling function 'fnc' with keyword arguments 'i' and 'pp'; it's expecting 'pi' and 'pp'. 2. You're calling function 'fnc1' with no arguments; it's expecting one argument. From robey.lawrence at gmail.com Sat Jan 12 01:09:21 2013 From: robey.lawrence at gmail.com (robey.lawrence at gmail.com) Date: Fri, 11 Jan 2013 22:09:21 -0800 (PST) Subject: Query windows event log with python Message-ID: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> Hi, I am looking to write a short program to query the windows event log. It needs to ask the user for input for The event type (Critical, Error, and Information), and the user needs to be able to specify a date since when they want to view results. I understand I will need the pywin32 extension, which i already have installed. I found this piece of code to start from, import win32evtlog # requires pywin32 pre-installed server = 'localhost' # name of the target computer to get event logs logtype = 'System' # 'Application' # 'Security' hand = win32evtlog.OpenEventLog(server,logtype) flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ total = win32evtlog.GetNumberOfEventLogRecords(hand) while True: events = win32evtlog.ReadEventLog(hand, flags,0) if events: for event in events: print 'Event Category:', event.EventCategory print 'Time Generated:', event.TimeGenerated print 'Source Name:', event.SourceName print 'Event ID:', event.EventID print 'Event Type:', event.EventType data = event.StringInserts if data: print 'Event Data:' for msg in data: print msg print Thanks for any help. Robey From wuwei23 at gmail.com Sat Jan 12 03:34:19 2013 From: wuwei23 at gmail.com (alex23) Date: Sat, 12 Jan 2013 00:34:19 -0800 (PST) Subject: Query windows event log with python References: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> Message-ID: On 12 Jan, 16:09, robey.lawre... at gmail.com wrote: > Hi, > > I am looking to write a short program to query the windows event log. > > It needs to ask the user for input for The event type (Critical, Error, and Information), and the user needs to be able to specify a date since when they want to view results. > > I understand I will need the pywin32 extension, which i already have installed. > > I found this piece of code to start from, > > > import win32evtlog # requires pywin32 pre-installed > > server = 'localhost' # name of the target computer to get event logs > logtype = 'System' # 'Application' # 'Security' > hand = win32evtlog.OpenEventLog(server,logtype) > flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ > total = win32evtlog.GetNumberOfEventLogRecords(hand) > > while True: > ? ? events = win32evtlog.ReadEventLog(hand, flags,0) > ? ? if events: > ? ? ? ? for event in events: > ? ? ? ? ? ? print 'Event Category:', event.EventCategory > ? ? ? ? ? ? print 'Time Generated:', event.TimeGenerated > ? ? ? ? ? ? print 'Source Name:', event.SourceName > ? ? ? ? ? ? print 'Event ID:', event.EventID > ? ? ? ? ? ? print 'Event Type:', event.EventType > ? ? ? ? ? ? data = event.StringInserts > ? ? ? ? ? ? if data: > ? ? ? ? ? ? ? ? print 'Event Data:' > ? ? ? ? ? ? ? ? for msg in data: > ? ? ? ? ? ? ? ? ? ? print msg > ? ? ? ? ? ? print > > > Thanks for any help. > Robey What would you like us to provide? Pointers to the Python tutorial? Or all of the code? Generally, the onus is on you to attempt to come up with solution yourself and then to ask for assistance where required. If you want someone to just write it for you, then you might want to mention how you plan on recompensing them. From mail at timgolden.me.uk Sat Jan 12 04:34:01 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 12 Jan 2013 09:34:01 +0000 Subject: Query windows event log with python In-Reply-To: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> References: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> Message-ID: <50F12E09.3060201@timgolden.me.uk> On 12/01/2013 06:09, robey.lawrence at gmail.com wrote: > I am looking to write a short program to query the windows event > log. > > It needs to ask the user for input for The event type (Critical, > Error, and Information), and the user needs to be able to specify a > date since when they want to view results. > > I found this piece of code to start from, [... snip ...] Well it looks like you have everything you need. Was there a specific question you wanted to ask? TJG From robey.lawrence at gmail.com Sun Jan 13 00:55:33 2013 From: robey.lawrence at gmail.com (robey.lawrence at gmail.com) Date: Sat, 12 Jan 2013 21:55:33 -0800 (PST) Subject: Query windows event log with python In-Reply-To: References: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> Message-ID: <2ba544a0-4a19-4c1e-bae3-c916ce83a84e@googlegroups.com> On Saturday, January 12, 2013 8:34:01 PM UTC+11, Tim Golden wrote: > On 12/01/2013 06:09, email.address at gmail.com wrote: > > > I am looking to write a short program to query the windows event > > > log. > > > > > > It needs to ask the user for input for The event type (Critical, > > > Error, and Information), and the user needs to be able to specify a > > > date since when they want to view results. > > > > > > I found this piece of code to start from, > > > > [... snip ...] > > > > Well it looks like you have everything you need. Was there a specific > > question you wanted to ask? > > > > TJG yes, I would like to run it in Command prompt and ask the user at the time what type and date of Event they would like to view. so i was wondering where in the code I could put something like "var=raw_input" Thanks TJG From robey.lawrence at gmail.com Sun Jan 13 00:55:33 2013 From: robey.lawrence at gmail.com (robey.lawrence at gmail.com) Date: Sat, 12 Jan 2013 21:55:33 -0800 (PST) Subject: Query windows event log with python In-Reply-To: References: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> Message-ID: <2ba544a0-4a19-4c1e-bae3-c916ce83a84e@googlegroups.com> On Saturday, January 12, 2013 8:34:01 PM UTC+11, Tim Golden wrote: > On 12/01/2013 06:09, email.address at gmail.com wrote: > > > I am looking to write a short program to query the windows event > > > log. > > > > > > It needs to ask the user for input for The event type (Critical, > > > Error, and Information), and the user needs to be able to specify a > > > date since when they want to view results. > > > > > > I found this piece of code to start from, > > > > [... snip ...] > > > > Well it looks like you have everything you need. Was there a specific > > question you wanted to ask? > > > > TJG yes, I would like to run it in Command prompt and ask the user at the time what type and date of Event they would like to view. so i was wondering where in the code I could put something like "var=raw_input" Thanks TJG From mail at timgolden.me.uk Mon Jan 14 04:07:06 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 14 Jan 2013 09:07:06 +0000 Subject: Query windows event log with python In-Reply-To: <2ba544a0-4a19-4c1e-bae3-c916ce83a84e@googlegroups.com> References: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> <2ba544a0-4a19-4c1e-bae3-c916ce83a84e@googlegroups.com> Message-ID: <50F3CABA.5020709@timgolden.me.uk> On 13/01/2013 05:55, robey.lawrence at gmail.com wrote: > On Saturday, January 12, 2013 8:34:01 PM UTC+11, Tim Golden wrote: >> On 12/01/2013 06:09, email.address at gmail.com wrote: >> >>> I am looking to write a short program to query the windows event >> >>> log. >> >>> >> >>> It needs to ask the user for input for The event type (Critical, >> >>> Error, and Information), and the user needs to be able to specify >>> a >> >>> date since when they want to view results. >> >>> >> >>> I found this piece of code to start from, >> >> >> >> [... snip ...] >> >> >> >> Well it looks like you have everything you need. Was there a >> specific >> >> question you wanted to ask? >> >> >> >> TJG > > yes, I would like to run it in Command prompt and ask the user at the > time what type and date of Event they would like to view. so i was > wondering where in the code I could put something like > "var=raw_input" Ok, so your query isn't so much with accessing the event log as with writing Python code at all. If you haven't already, could I suggest the Python tutorial here: http://docs.python.org/2/tutorial/ or, if that one doesn't suit, just search for "Python tutorial" to find something which fits your brain. Feel free to post back here with questions once you've got started. TJG From alec.taylor6 at gmail.com Sat Jan 12 02:45:38 2013 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 12 Jan 2013 18:45:38 +1100 Subject: Compiling native extensions with Visual Studio 2012? Message-ID: There have been various threads for MSVC 2010[1][2], but the most recent thing I found for MSVC 2012 was [3]? from 6 months ago. Basically I want to be able to compile bcrypt?and yes I should be using Keccak?x64 binaries on Windows x64. There are other packages also which I will benefit from, namely I won't need to use the unofficial setup files and will finally be able to use virtualenv. So anyway, can I get an update on the status of MSVC 2010 and MSVC 2012 compatibility? Thanks, Alec Taylor [1] http://bugs.python.org/issue13210 [2] http://webcache.googleusercontent.com/search?q=cache:xPaU9mlCBNEJ:wiki.python.org/moin/VS2010+&cd=1&hl=en&ct=clnk [3] https://groups.google.com/d/topic/dev-python/W1RpFhaOIGk From alec.taylor6 at gmail.com Sat Jan 12 03:30:15 2013 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 12 Jan 2013 19:30:15 +1100 Subject: Compiling native extensions with Visual Studio 2012? In-Reply-To: References: Message-ID: Okay, got all extensions I require to compile successfully with MSVC 2012. Trick was using this fork: https://github.com/wcdolphin/py-bcrypt (See their issue log for traceback) =] On Sat, Jan 12, 2013 at 6:45 PM, Alec Taylor wrote: > There have been various threads for MSVC 2010[1][2], but the most > recent thing I found for MSVC 2012 was [3]? from 6 months ago. > > Basically I want to be able to compile bcrypt?and yes I should be > using Keccak?x64 binaries on Windows x64. > > There are other packages also which I will benefit from, namely I > won't need to use the unofficial setup files and will finally be able > to use virtualenv. > > So anyway, can I get an update on the status of MSVC 2010 and MSVC > 2012 compatibility? > > Thanks, > > Alec Taylor > > [1] http://bugs.python.org/issue13210 > [2] http://webcache.googleusercontent.com/search?q=cache:xPaU9mlCBNEJ:wiki.python.org/moin/VS2010+&cd=1&hl=en&ct=clnk > [3] https://groups.google.com/d/topic/dev-python/W1RpFhaOIGk From christian at python.org Sat Jan 12 09:34:02 2013 From: christian at python.org (Christian Heimes) Date: Sat, 12 Jan 2013 15:34:02 +0100 Subject: Compiling native extensions with Visual Studio 2012? In-Reply-To: References: Message-ID: <50F1745A.8030808@python.org> Am 12.01.2013 08:45, schrieb Alec Taylor: > There have been various threads for MSVC 2010[1][2], but the most > recent thing I found for MSVC 2012 was [3]? from 6 months ago. > > Basically I want to be able to compile bcrypt?and yes I should be > using Keccak?x64 binaries on Windows x64. > > There are other packages also which I will benefit from, namely I > won't need to use the unofficial setup files and will finally be able > to use virtualenv. > > So anyway, can I get an update on the status of MSVC 2010 and MSVC > 2012 compatibility? The problem is that every MSVC has its own libc / CRT (msvcrt.dll) with its own implementations of malloc(), FILE pointer, thread local storage, errno etc. You shouldn't mix multiple CRTs in one program as this may lead to crashes and hard to find bugs. Why do you want to compile your own Keccak / SHA-3 binaries anyway? I have build and released binaries for X86 and X86_64 Windows and for Python 2.6 and 3.3. For Python 3.4 I'm working on a PEP about the integration of pbkdf2, bcrypt and scrypt into Python's stdlib. Christian From alec.taylor6 at gmail.com Sat Jan 12 11:06:54 2013 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 13 Jan 2013 03:06:54 +1100 Subject: Compiling native extensions with Visual Studio 2012? In-Reply-To: <50F1745A.8030808@python.org> References: <50F1745A.8030808@python.org> Message-ID: On Sun, Jan 13, 2013 at 1:34 AM, Christian Heimes wrote: > Am 12.01.2013 08:45, schrieb Alec Taylor: >> There have been various threads for MSVC 2010[1][2], but the most >> recent thing I found for MSVC 2012 was [3]? from 6 months ago. >> >> Basically I want to be able to compile bcrypt?and yes I should be >> using Keccak?x64 binaries on Windows x64. >> >> There are other packages also which I will benefit from, namely I >> won't need to use the unofficial setup files and will finally be able >> to use virtualenv. >> >> So anyway, can I get an update on the status of MSVC 2010 and MSVC >> 2012 compatibility? > > The problem is that every MSVC has its own libc / CRT (msvcrt.dll) with > its own implementations of malloc(), FILE pointer, thread local storage, > errno etc. You shouldn't mix multiple CRTs in one program as this may > lead to crashes and hard to find bugs. > > Why do you want to compile your own Keccak / SHA-3 binaries anyway? I > have build and released binaries for X86 and X86_64 Windows and for > Python 2.6 and 3.3. For Python 3.4 I'm working on a PEP about the > integration of pbkdf2, bcrypt and scrypt into Python's stdlib. > > Christian Would be awesome to get these built into stdlib. Compiling my own versions mostly for virtualenv purposes; though sometimes I can't find the binary on: http://www.lfd.uci.edu/~gohlke/pythonlibs/ From christian at python.org Tue Jan 15 09:23:16 2013 From: christian at python.org (Christian Heimes) Date: Tue, 15 Jan 2013 15:23:16 +0100 Subject: Compiling native extensions with Visual Studio 2012? In-Reply-To: References: <50F1745A.8030808@python.org> Message-ID: <50F56654.3040609@python.org> Am 12.01.2013 17:06, schrieb Alec Taylor: > Would be awesome to get these built into stdlib. > > Compiling my own versions mostly for virtualenv purposes; though > sometimes I can't find the binary on: > http://www.lfd.uci.edu/~gohlke/pythonlibs/ Let's see. I've 10 months to work on the PEP + implementation until the feature freeze of Python 3.4. It's feasible. Yeah, Christoph Gohlke's work is a time saver! Some people provide official Windows binaries for their Python packages. I'm in the lucky position to own a free MSDN subscription from Microsoft for my work on Python's Core. From rosuav at gmail.com Sat Jan 12 06:42:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Jan 2013 22:42:04 +1100 Subject: stringbench (was Re: String concatenation benchmarking weirdness) Message-ID: On Sat, Jan 12, 2013 at 10:31 PM, Terry Reedy wrote: > 0.41 0.43 95.2 ("WHERE IN THE WORLD IS CARMEN SAN > DEIGO?"*10).lower() Why does stringbench misspell the name Carmen Sandiego? Copyright avoidance? ChrisA From tjreedy at udel.edu Sat Jan 12 09:27:04 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 12 Jan 2013 09:27:04 -0500 Subject: stringbench (was Re: String concatenation benchmarking weirdness) In-Reply-To: References: Message-ID: On 1/12/2013 6:42 AM, Chris Angelico wrote: > On Sat, Jan 12, 2013 at 10:31 PM, Terry Reedy wrote: >> 0.41 0.43 95.2 ("WHERE IN THE WORLD IS CARMEN SAN >> DEIGO?"*10).lower() > > Why does stringbench misspell the name Carmen Sandiego? Copyright avoidance? Or ignorance. Perhaps I will fix it some day. -- Terry Jan Reedy From rosuav at gmail.com Sat Jan 12 09:31:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Jan 2013 01:31:19 +1100 Subject: stringbench (was Re: String concatenation benchmarking weirdness) In-Reply-To: References: Message-ID: On Sun, Jan 13, 2013 at 1:27 AM, Terry Reedy wrote: > On 1/12/2013 6:42 AM, Chris Angelico wrote: >> >> On Sat, Jan 12, 2013 at 10:31 PM, Terry Reedy wrote: >>> >>> 0.41 0.43 95.2 ("WHERE IN THE WORLD IS CARMEN SAN >>> DEIGO?"*10).lower() >> >> >> Why does stringbench misspell the name Carmen Sandiego? Copyright >> avoidance? > > > Or ignorance. Perhaps I will fix it some day. Heh. And here I was assuming everything had a strong and purposeful cause... ChrisA From szabolcs.blaga at gmail.com Sat Jan 12 08:30:03 2013 From: szabolcs.blaga at gmail.com (=?UTF-8?Q?Szabolcs_Bl=C3=A1ga?=) Date: Sat, 12 Jan 2013 14:30:03 +0100 Subject: proposal: Ellipsis in argument list Message-ID: Dear All, I have an idea that the Ellipsis object could be used in function calls. The "..." syntax should automagically turn into an Ellipsis positional argument. def f(*args): ext_args = [] for i, a in enumerate(args): if a is Ellipsis: ext_args.extend([x for x in range(args[i-1]-1, args[i+1])]) else: ext_args.append(a) return ext_args Calling it for the above example specifically: >>>f(34, ..., 43) [34, 35, 36, 37, 38, 39, 40, 41, 42, 43] That might be useless or someone might say it is confusing, but I think it would be relatively easy to implement and a nice little syntactic "sugar". Best regards, Szabolcs Blaga -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sat Jan 12 09:08:24 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 12 Jan 2013 15:08:24 +0100 Subject: proposal: Ellipsis in argument list In-Reply-To: References: Message-ID: Szabolcs Bl?ga, 12.01.2013 14:30: > I have an idea that the Ellipsis object could be used in function calls. > The "..." syntax should automagically turn into an Ellipsis positional > argument. > > def f(*args): > ext_args = [] > for i, a in enumerate(args): > if a is Ellipsis: > ext_args.extend([x for x in range(args[i-1]-1, args[i+1])]) > else: > ext_args.append(a) > return ext_args > > Calling it for the above example specifically: > > >>> f(34, ..., 43) > [34, 35, 36, 37, 38, 39, 40, 41, 42, 43] > > That might be useless or someone might say it is confusing, but I think it > would be relatively easy to implement and a nice little syntactic "sugar". Not sure what exactly you are proposing here, this works for me: Python 3.2.3 (default, Oct 19 2012, 19:53:16) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f(*args): print(args) >>> f(34, ..., 43) (34, Ellipsis, 43) Stefan From ckaynor at zindagigames.com Mon Jan 14 12:38:23 2013 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 14 Jan 2013 09:38:23 -0800 Subject: proposal: Ellipsis in argument list In-Reply-To: References: Message-ID: On Sat, Jan 12, 2013 at 5:30 AM, Szabolcs Bl?ga wrote: > Dear All, > > I have an idea that the Ellipsis object could be used in function calls. > The "..." syntax should automagically turn into an Ellipsis positional > argument. > > def f(*args): > ext_args = [] > for i, a in enumerate(args): > if a is Ellipsis: > ext_args.extend([x for x in range(args[i-1]-1, args[i+1])]) > else: > ext_args.append(a) > return ext_args > > Calling it for the above example specifically: > > >>>f(34, ..., 43) > [34, 35, 36, 37, 38, 39, 40, 41, 42, 43] > > That might be useless or someone might say it is confusing, but I think it > would be relatively easy to implement and a nice little syntactic "sugar". > > The basis for adding syntactic sugar is closer to: Is this something that cannot be done clearly without the change, and is commonly useful? Also, as Stefan showed, this is already valid syntax with differing meaning, and thus could break existing code, making the threshold for adding it even harder. This change doesn't seem to useful, and can be easily done already: f(range(34, 43)) Additionally, a decorator could easily be written to do this if you find this is a pattern you commonly use for specific functions (untested), or you can use your expansion function for other cases: def ellipsisExpand(func): def newFunc(*args, **kwargs): ext_args = [] for i, a in enumerate(args): if a is Ellipsis: ext_args.extend([x for x in range(args[i-1]-1, args[i+1])]) else: ext_args.append(a) return func(*ext_args, **kwargs) Then, you use this like: @ellipsisExpand def f(arg): print arg > Best regards, > > Szabolcs Blaga > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From reganrexman at gmail.com Sat Jan 12 14:07:51 2013 From: reganrexman at gmail.com (reganrexman) Date: Sat, 12 Jan 2013 13:07:51 -0600 Subject: Introduction to Mathematical Statistics (6th Ed., Hogg, Craig & McKean) Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTIONS MANUAL TO Industrial Organization Theory & Applications by Shy SOLUTIONS MANUAL TO Intermediate Accounting - IFRS Edition Vol.1 by Kieso, Weygandt, Warfield SOLUTIONS MANUAL TO Intermediate Accounting 12th ed by Kieso SOLUTIONS MANUAL TO Intermediate Accounting 13 ed by Kieso SOLUTIONS MANUAL TO Intermediate Accounting Kieso 12th ed SOLUTIONS MANUAL TO INTERMEDIATE ACCOUNTING, 6th Edition, by Spiceland, Sepe SOLUTIONS MANUAL TO Intermediate Algebra - Concepts & Applications 8th Ed by Bittinger, Ellenbogen SOLUTIONS MANUAL TO Introduction to Accounting 3rd Ed by Marriott, Mellett SOLUTIONS MANUAL TO Introduction to Algorithms, 2nd Ed by Cormen, Leiserson SOLUTIONS MANUAL TO Introduction To Analysis (3rdEd) -by William Wade SOLUTIONS MANUAL TO Introduction to Applied Modern Physics by Henok Abebe SOLUTIONS MANUAL TO Introduction to Chemical Engineering Thermodynamics (7th Ed., Smith & Van Ness) SOLUTIONS MANUAL TO Introduction to Commutative Algebra by M. F. Atiyah SOLUTIONS MANUAL TO Introduction to Digital Signal Processing (in Serbian) by Lj. Milic and Z. Dobrosavljevic SOLUTIONS MANUAL TO Introduction to Econometrics (2nd ed., James H. Stock & Mark W. Watson) SOLUTIONS MANUAL TO Introduction to Electric Circuits 7th Edition by Dorf, Svaboda SOLUTIONS MANUAL TO Introduction to Electric Circuits, 6E, Dorf SOLUTIONS MANUAL TO Introduction to Electrodynamics (3rd Ed., David J. Griffiths) SOLUTIONS MANUAL TO Introduction to Elementary Particles 2nd Ed by David Griffiths SOLUTIONS MANUAL TO Introduction to Environmental Engineering and Science (3rd Ed., Gilbert M. Masters & Wendell P. Ela) SOLUTIONS MANUAL TO Introduction to Environmental Engineering and Science, Edition 2, Masters SOLUTIONS MANUAL TO Introduction to Ergonomics 2E by Robert Bridger SOLUTIONS MANUAL TO Introduction to Fluid Mechanics ( 7 E., Robert Fox, Alan McDonald & Philip ) SOLUTIONS MANUAL TO Introduction to Fluid Mechanics (6E., Robert Fox, Alan McDonald & Philip) SOLUTIONS MANUAL TO Introduction to fluid mechanics 5th edition by Alan T. McDonald, Robert W Fox SOLUTIONS MANUAL TO Introduction to Graph Theory 2E - West SOLUTIONS MANUAL TO Introduction to Heat Transfer by Vedat S. Arpaci, Ahmet Selamet, Shu-Hsin Kao SOLUTIONS MANUAL TO Introduction to Java Programming, Comprehensive Version 7th Ed by Liang SOLUTIONS MANUAL TO Introduction to Linear Algebra, 3rd Ed., by Gilbert Strang SOLUTIONS MANUAL TO Introduction to Linear Optimization by Dimitris Bertsimas, John N. Tsitsiklis SOLUTIONS MANUAL TO Introduction to Management Accounting, 14 ED by Horngren, Schatzberg SOLUTIONS MANUAL TO Introduction to Materials Science for Engineers (6th Ed., Shackelford) SOLUTIONS MANUAL TO Introduction to Materials Science for Engineers 7th E by Shackelford SOLUTIONS MANUAL TO Introduction to Mathematical Statistics (6th Ed., Hogg, Craig & McKean) SOLUTIONS MANUAL TO Introduction to Mechatronics and Measurements Systems 2nd Ed by Alciatore, Histand SOLUTIONS MANUAL TO Introduction to Nuclear And Particle Physics 2nd E by Bromberg, Das, Ferbel SOLUTIONS MANUAL TO Introduction to Operations Research - 7th ed by Frederick Hillier, Gerald Lieberman SOLUTIONS MANUAL TO Introduction to Probability 2nd Ed by Bertsekas and Tsitsiklis SOLUTIONS MANUAL TO Introduction to Probability by Dimitri P. Bertsekas and John N. Tsitsiklis SOLUTIONS MANUAL TO Introduction to Probability by Grinstead, Snell SOLUTIONS MANUAL TO Introduction to Quantum Mechanics (2nd Ed., David J. Griffiths) SOLUTIONS MANUAL TO Introduction to Quantum Mechanics 1st edition (1995) by David J. Griffiths SOLUTIONS MANUAL TO Introduction to Queueing Theory 2nd Edition by R.B. Cooper SOLUTIONS MANUAL TO Introduction to Scientific Computation and Programming, 1st Edition by Daniel Kaplan SOLUTIONS MANUAL TO Introduction to Signal Processing by S. J. Orfanidis SOLUTIONS MANUAL TO Introduction to Signal Processing by Sophocles J. Orfanidis SOLUTIONS MANUAL TO Introduction to Solid State Physics 8th Ed by Kittel & Charles SOLUTIONS MANUAL TO Introduction to Statistical Physics by Kerson Huang SOLUTIONS MANUAL TO Introduction to Statistical Quality Control (5th Ed., Douglas C. Montgomery) SOLUTIONS MANUAL TO Introduction to the Theory of Computation by Ching Law SOLUTIONS MANUAL TO Introduction to the Thermodynamics of Materials 3 E by Gaskell SOLUTIONS MANUAL TO Introduction to Thermal and Fluids Engineering by Kaminski, Jensen SOLUTIONS MANUAL TO Introduction to Thermal Systems Engineering Moran Shapiro Munson SOLUTIONS MANUAL TO Introduction to VLSI Circuits and Systems, by John P. Uyemura SOLUTIONS MANUAL TO Introduction to Wireless Systems by P.M Shankar SOLUTIONS MANUAL TO Introductory Econometrics A Modern Approach, 3Ed by Jeffrey Wooldridge SOLUTIONS MANUAL TO Introductory Mathematical Analysis for Business, Economics and the Life and Social Sciences, 12th E By Haeussler,Paul,Wood SOLUTIONS MANUAL TO Introductory Quantum Optics (Christopher Gerry & Peter Knight) SOLUTIONS MANUAL TO Introdution to Solid State Physics, 8th Edition by Kittel SOLUTIONS MANUAL TO Investment Analysis & Portfolio Management, 7e by Reilly, Brown SOLUTIONS MANUAL TO Investment Analysis and Portfolio Management 7th Edition by Frank K. et al. Reilly SOLUTIONS MANUAL TO Investments by Charles P. Jones SOLUTIONS MANUAL TO IT Networking Labs by Tom Cavaiani SOLUTIONS MANUAL TO Java How to program 7th Ed by Deitel SOLUTIONS MANUAL TO Journey into Mathematics An Introduction to Proofs ,Joseph Rotman SOLUTIONS MANUAL TO Kinematics, Dynamics, and Design of Machinery, 2nd Ed., Waldron & Kinzel SOLUTIONS MANUAL TO Kinetics of Catalytic Reactions by M. Albert Vannice SOLUTIONS MANUAL TO LabVIEW for Engineers by Larsen SOLUTIONS MANUAL TO Laser Fundamentals (2nd Ed., William T. Silfvast) SOLUTIONS MANUAL TO Learning SAS in the Computer Lab 3rd ED by Elliott, Morrell SOLUTIONS MANUAL TO Lectures on Corporate Finance 2006, 2 Ed by Bossaerts, Oedegaard SOLUTIONS MANUAL TO Linear Algebra - 2 Ed - Poole SOLUTIONS MANUAL TO Linear Algebra and Its Applications 3rd ed by David C. Lay SOLUTIONS MANUAL TO Linear Algebra Done Right, 2nd Ed by Sheldon Axler SOLUTIONS MANUAL TO Linear Algebra with Applications (6th Ed., S. Leon) SOLUTIONS MANUAL TO Linear Algebra with Applications 3rd Ed by Otto Bretscher SOLUTIONS MANUAL TO Linear Algebra With Applications, 2nd Edition by W. Keith Nicholson SOLUTIONS MANUAL TO Linear Algebra, 4th Ed, by Stephen H. Friedberg , Arnold J. Insel , Lawrence E. Spence SOLUTIONS MANUAL TO Linear Algebra, by J. Hefferon SOLUTIONS MANUAL TO Linear Circuit Analysis Time Domain, Phasor and Laplace.., 2nd Ed, Lin SOLUTIONS MANUAL TO Linear Circuit Analysis, 2nd Ed by DeCarlo , Pen-Min Lin SOLUTIONS MANUAL TO Linear dynamic systems and signals by Zoran Gajic SOLUTIONS MANUAL TO Linear Systems And Signals, 1stE, B P Lathi SOLUTIONS MANUAL TO Logic and Computer Design Fundamentals, 2E, by Morris Mano and Charles Kime SOLUTIONS MANUAL TO Logic and Computer Design Fundamentals, 3d edition by Morris Mano and Charles Kime SOLUTIONS MANUAL TO Logic and Computer Design Fundamentals, 4/E, by Morris Mano and Charles Kime From tyson+usenet at tyson.me Sat Jan 12 17:12:25 2013 From: tyson+usenet at tyson.me (Tyson Moore) Date: Sat, 12 Jan 2013 17:12:25 -0500 Subject: Python 3.3 can't find PySide Message-ID: <50f1df87$0$26901$88263eea@blocknews.net> Hi everybody, I'm just starting to dabble in Python development after spending years with C# and Java, but there's one small thing holding me back: I can't seem to get PySide working for the life of me. Let me explain: I'm on OS X 10.6.8 and have installed Python 3.3.0 and Qt 4.8.4 with Homebrew. The Python interpreter works fine, and all the Qt utilites are in my $PATH and installed correctly. Homebrew has a package for PySide, but it's only compiled against Python 2.x instead of 3.x (there is an issue about this, https://github.com/mxcl/homebrew/issues/16439), so I can't use that. I tried using the PySide BuildScripts on GitHub, but those fail with an error that I can't seem to resolve (I'll save that for a PySide list, I guess). I can't compile it manually because I don't have the expertise to pass the right options to cmake and tell it where to find all my Python stuff, so I'm really at my wit's end. I tried installing the Homebrew PySide package anyways, but putting the PySide directory (with __init__.py) in my PYTHONPATH didn't allow me to import anything from PySide; I guess this means that PySide has to be told to compile for 3.x instead of 2.x. My question: is there anybody who has had success installing PySide on OS X for Python 3.x? There must be a way, I must be missing something... right? I'll try to find a more relevant PySide list or something to pose this question on but in the meantime, if anybody has any suggestions, I'd appreciate your input. Thanks in advance! -- Tyson Moore tyson+usenet at tyson.me From andrei.avk at gmail.com Sun Jan 13 00:11:53 2013 From: andrei.avk at gmail.com (AK) Date: Sun, 13 Jan 2013 00:11:53 -0500 Subject: ANN: Python training "text movies" Message-ID: <50F24219.7020407@gmail.com> I don't know what to call these, so for now I'll call them "training text movies" until I come up with a better name.. I hope these will be helpful, especially to new students of Python. http://lightbird.net/larks/tmovies.html I'll be adding more in the next few days... - mitya From steve+comp.lang.python at pearwood.info Sun Jan 13 01:35:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jan 2013 06:35:50 GMT Subject: ANN: Python training "text movies" References: Message-ID: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Jan 2013 00:11:53 -0500, AK wrote: > I don't know what to call these, so for now I'll call them "training > text movies" until I come up with a better name.. > > I hope these will be helpful, especially to new students of Python. > > http://lightbird.net/larks/tmovies.html For the benefit of those who don't have web access at the moment, or who don't like to click on random links they don't know anything about, would you like to say a few words describing what "text movies" are, and how you think these may be helpful? -- Steven From msirenef at lightbird.net Sun Jan 13 02:08:31 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 13 Jan 2013 02:08:31 -0500 Subject: ANN: Python training "text movies" In-Reply-To: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F25D6F.20604@lightbird.net> On 01/13/2013 01:35 AM, Steven D'Aprano wrote: > On Sun, 13 Jan 2013 00:11:53 -0500, AK wrote: > >> I don't know what to call these, so for now I'll call them "training >> text movies" until I come up with a better name.. >> >> I hope these will be helpful, especially to new students of Python. >> >> http://lightbird.net/larks/tmovies.html > > > For the benefit of those who don't have web access at the moment, or who > don't like to click on random links they don't know anything about, would > you like to say a few words describing what "text movies" are, and how > you think these may be helpful? > > > Sure: they play back a list of instructions on use of string methods and list comprehensions along with demonstration in a mock-up of the interpreter with a different display effect for commands typed into (and printed out by) the interpeter. The speed can be changed and the playback can be paused. - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From tjreedy at udel.edu Sun Jan 13 02:28:30 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 13 Jan 2013 02:28:30 -0500 Subject: ANN: Python training "text movies" In-Reply-To: <50F25D6F.20604@lightbird.net> References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> Message-ID: On 1/13/2013 2:08 AM, Mitya Sirenef wrote: > On 01/13/2013 01:35 AM, Steven D'Aprano wrote: >> On Sun, 13 Jan 2013 00:11:53 -0500, AK wrote: > > > >> I don't know what to call these, so for now I'll call them "training > >> text movies" until I come up with a better name.. > >> > >> I hope these will be helpful, especially to new students of Python. > >> > >> http://lightbird.net/larks/tmovies.html > > > > > > For the benefit of those who don't have web access at the moment, or who > > don't like to click on random links they don't know anything about, > would > > you like to say a few words describing what "text movies" are, and how > > you think these may be helpful? > > > > > > > > > Sure: they play back a list of instructions on use of string methods and > list comprehensions along with demonstration in a mock-up of the > interpreter with a different display effect for commands typed into (and > printed out by) the interpeter. The speed can be changed and the > playback can be paused. They are simulated videos of an interactive interpreter session, with entered commands appearing all at once instead of char by char, and with the extra features mentioned above. I presume the purported advantage over an after-the-fact transcript is focusing watcher attention on each entry and response. -- Terry Jan Reedy From msirenef at lightbird.net Sun Jan 13 02:42:24 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 13 Jan 2013 02:42:24 -0500 Subject: ANN: Python training "text movies" In-Reply-To: References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> Message-ID: <50F26560.9040800@lightbird.net> On 01/13/2013 02:28 AM, Terry Reedy wrote: > On 1/13/2013 2:08 AM, Mitya Sirenef wrote: >> On 01/13/2013 01:35 AM, Steven D'Aprano wrote: >>> On Sun, 13 Jan 2013 00:11:53 -0500, AK wrote: >> > >> >> I don't know what to call these, so for now I'll call them "training >> >> text movies" until I come up with a better name.. >> >> >> >> I hope these will be helpful, especially to new students of Python. >> >> >> >> http://lightbird.net/larks/tmovies.html >> > >> > >> > For the benefit of those who don't have web access at the moment, or who >> > don't like to click on random links they don't know anything about, >> would >> > you like to say a few words describing what "text movies" are, and how >> > you think these may be helpful? >> > >> > >> > >> >> >> Sure: they play back a list of instructions on use of string methods and >> list comprehensions along with demonstration in a mock-up of the >> interpreter with a different display effect for commands typed into (and >> printed out by) the interpeter. The speed can be changed and the >> playback can be paused. > > They are simulated videos of an interactive interpreter session, with > entered commands appearing all at once instead of char by char, and > with the extra features mentioned above. I presume the purported > advantage over an after-the-fact transcript is focusing watcher > attention on each entry and response. > That is right; I would also add that it may be overwhelming for a newbie to be reading through a large "wall of text" -- here you have blank space after the current paragraph so the attention is focused even more on the last few lines. Additionally, since instructions scroll automatically, I can space them out more than you would conventionally do in a manual. - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From jason at powerpull.net Sun Jan 13 09:38:19 2013 From: jason at powerpull.net (Jason Friedman) Date: Sun, 13 Jan 2013 06:38:19 -0800 Subject: ANN: Python training "text movies" In-Reply-To: <50F26560.9040800@lightbird.net> References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: > That is right; I would also add that it may be overwhelming for a newbie > to be reading through a large "wall of text" -- here you have blank > space after the current paragraph so the attention is focused even more > on the last few lines. > > Additionally, since instructions scroll automatically, I can space them > out more than you would conventionally do in a manual. > Pretty cool. From nobody at nowhere.org Mon Jan 14 01:34:58 2013 From: nobody at nowhere.org (Franck Ditter) Date: Mon, 14 Jan 2013 07:34:58 +0100 Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: In article , Jason Friedman wrote: > > That is right; I would also add that it may be overwhelming for a newbie > > to be reading through a large "wall of text" -- here you have blank > > space after the current paragraph so the attention is focused even more > > on the last few lines. > > > > Additionally, since instructions scroll automatically, I can space them > > out more than you would conventionally do in a manual. > > > > Pretty cool. When reading the source of the Web page which shows the scroll, I can't find the reference to the text displayed. Only "text"... How may we use the software which generates the Javascript ? Thanks, it's cool. franck From msirenef at lightbird.net Mon Jan 14 01:56:15 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 14 Jan 2013 01:56:15 -0500 Subject: ANN: Python training "text movies" In-Reply-To: References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: <50F3AC0F.3010600@lightbird.net> On 01/14/2013 01:34 AM, Franck Ditter wrote: > In article , > Jason Friedman wrote: > >>> That is right; I would also add that it may be overwhelming for a newbie >>> to be reading through a large "wall of text" -- here you have blank >>> space after the current paragraph so the attention is focused even more >>> on the last few lines. >>> >>> Additionally, since instructions scroll automatically, I can space them >>> out more than you would conventionally do in a manual. >>> >> Pretty cool. > When reading the source of the Web page which shows the scroll, > I can't find the reference to the text displayed. Only "text"... > How may we use the software which generates the Javascript ? > Thanks, it's cool. > > franck Thanks! the text is in var commands = ... You can download the generator script here: https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py (you also need to grab tmovies dir) -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From nobody at nowhere.org Sat Jan 19 04:32:28 2013 From: nobody at nowhere.org (Franck Ditter) Date: Sat, 19 Jan 2013 10:32:28 +0100 Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: In article , Mitya Sirenef wrote: > On 01/14/2013 01:34 AM, Franck Ditter wrote: > > In article , > > Jason Friedman wrote: > > > >>> That is right; I would also add that it may be overwhelming for a newbie > >>> to be reading through a large "wall of text" -- here you have blank > >>> space after the current paragraph so the attention is focused even more > >>> on the last few lines. > >>> > >>> Additionally, since instructions scroll automatically, I can space them > >>> out more than you would conventionally do in a manual. > >>> > >> Pretty cool. > > When reading the source of the Web page which shows the scroll, > > I can't find the reference to the text displayed. Only "text"... > > How may we use the software which generates the Javascript ? > > Thanks, it's cool. > > > > franck > > Thanks! > > the text is in var commands = ... > > You can download the generator script here: > > https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > > (you also need to grab tmovies dir) When looking at the source of the page : http://lightbird.net/larks/tmovies/strings.html I find commands = [] I can't guess where the strings displayed come from... franck From msirenef at lightbird.net Sat Jan 19 14:02:24 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sat, 19 Jan 2013 14:02:24 -0500 Subject: ANN: Python training "text movies" In-Reply-To: References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: <50FAEDC0.4090806@lightbird.net> On 01/19/2013 04:32 AM, Franck Ditter wrote: > In article , > Mitya Sirenef wrote: > >> On 01/14/2013 01:34 AM, Franck Ditter wrote: >>> In article , >>> Jason Friedman wrote: >>> >>>>> That is right; I would also add that it may be overwhelming for a newbie >>>>> to be reading through a large "wall of text" -- here you have blank >>>>> space after the current paragraph so the attention is focused even more >>>>> on the last few lines. >>>>> >>>>> Additionally, since instructions scroll automatically, I can space them >>>>> out more than you would conventionally do in a manual. >>>>> >>>> Pretty cool. >>> When reading the source of the Web page which shows the scroll, >>> I can't find the reference to the text displayed. Only "text"... >>> How may we use the software which generates the Javascript ? >>> Thanks, it's cool. >>> >>> franck >> Thanks! >> >> the text is in var commands = ... >> >> You can download the generator script here: >> >> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py >> >> (you also need to grab tmovies dir) > When looking at the source of the page : > http://lightbird.net/larks/tmovies/strings.html > I find commands = [] > I can't guess where the strings displayed come from... > > franck Look 10 lines below that line. I have also added a related page that allows you to paste your own text to make a movie; it's linked from the same page with the list of generated t-movies. (that page does not let you use typewriter effect or custom pauses though). - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From nobody at nowhere.org Sun Jan 20 12:37:38 2013 From: nobody at nowhere.org (Franck Ditter) Date: Sun, 20 Jan 2013 18:37:38 +0100 Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: In article , Mitya Sirenef wrote: > On 01/19/2013 04:32 AM, Franck Ditter wrote: > > In article , > > Mitya Sirenef wrote: > > > >> On 01/14/2013 01:34 AM, Franck Ditter wrote: > >>> In article , > >>> Jason Friedman wrote: > >>> > >>>>> That is right; I would also add that it may be overwhelming for a newbie > >>>>> to be reading through a large "wall of text" -- here you have blank > >>>>> space after the current paragraph so the attention is focused even more > >>>>> on the last few lines. > >>>>> > >>>>> Additionally, since instructions scroll automatically, I can space them > >>>>> out more than you would conventionally do in a manual. > >>>>> > >>>> Pretty cool. > >>> When reading the source of the Web page which shows the scroll, > >>> I can't find the reference to the text displayed. Only "text"... > >>> How may we use the software which generates the Javascript ? > >>> Thanks, it's cool. > >>> > >>> franck > >> Thanks! > >> > >> the text is in var commands = ... > >> > >> You can download the generator script here: > >> > >> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > >> > >> (you also need to grab tmovies dir) > > When looking at the source of the page : > > http://lightbird.net/larks/tmovies/strings.html > > I find commands = [] > > I can't guess where the strings displayed come from... > > > > franck > > Look 10 lines below that line. > > > I have also added a related page that allows you to paste your own > text to make a movie; it's linked from the same page with the > list of generated t-movies. > > (that page does not let you use typewriter effect or custom pauses > though). > > - mitya I'm probably blind but 10 line after the line "commands = []", I find : var commands = [ [ "text", " " ], [ "text", " " ], ....] but nothing concrete ! How come ? franck From nobody at nowhere.org Sun Jan 20 12:41:31 2013 From: nobody at nowhere.org (Franck Ditter) Date: Sun, 20 Jan 2013 18:41:31 +0100 Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: In article , Franck Ditter wrote: > In article , > Mitya Sirenef wrote: > > > On 01/19/2013 04:32 AM, Franck Ditter wrote: > > > In article , > > > Mitya Sirenef wrote: > > > > > >> On 01/14/2013 01:34 AM, Franck Ditter wrote: > > >>> In article , > > >>> Jason Friedman wrote: > > >>> > > >>>>> That is right; I would also add that it may be overwhelming for a newbie > > >>>>> to be reading through a large "wall of text" -- here you have blank > > >>>>> space after the current paragraph so the attention is focused even more > > >>>>> on the last few lines. > > >>>>> > > >>>>> Additionally, since instructions scroll automatically, I can space them > > >>>>> out more than you would conventionally do in a manual. > > >>>>> > > >>>> Pretty cool. > > >>> When reading the source of the Web page which shows the scroll, > > >>> I can't find the reference to the text displayed. Only "text"... > > >>> How may we use the software which generates the Javascript ? > > >>> Thanks, it's cool. > > >>> > > >>> franck > > >> Thanks! > > >> > > >> the text is in var commands = ... > > >> > > >> You can download the generator script here: > > >> > > >> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > > >> > > >> (you also need to grab tmovies dir) > > > When looking at the source of the page : > > > http://lightbird.net/larks/tmovies/strings.html > > > I find commands = [] > > > I can't guess where the strings displayed come from... > > > > > > franck > > > > Look 10 lines below that line. > > > > > > I have also added a related page that allows you to paste your own > > text to make a movie; it's linked from the same page with the > > list of generated t-movies. > > > > (that page does not let you use typewriter effect or custom pauses > > though). > > > > - mitya > > I'm probably blind but 10 line after the line "commands = []", I find : > > var commands = [ > [ > "text", > " " > ], > [ > "text", > " " > ], > ....] > > but nothing concrete ! How come ? > > franck OK OK found ! Thanks. franck From nobody at nowhere.org Sun Jan 20 12:54:03 2013 From: nobody at nowhere.org (Franck Ditter) Date: Sun, 20 Jan 2013 18:54:03 +0100 Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: In article , Franck Ditter wrote: > In article , > Franck Ditter wrote: > > > In article , > > Mitya Sirenef wrote: > > > > > On 01/19/2013 04:32 AM, Franck Ditter wrote: > > > > In article , > > > > Mitya Sirenef wrote: > > > > > > > >> On 01/14/2013 01:34 AM, Franck Ditter wrote: > > > >>> In article , > > > >>> Jason Friedman wrote: > > > >>> > > > >>>>> That is right; I would also add that it may be overwhelming for a newbie > > > >>>>> to be reading through a large "wall of text" -- here you have blank > > > >>>>> space after the current paragraph so the attention is focused even more > > > >>>>> on the last few lines. > > > >>>>> > > > >>>>> Additionally, since instructions scroll automatically, I can space them > > > >>>>> out more than you would conventionally do in a manual. > > > >>>>> > > > >>>> Pretty cool. > > > >>> When reading the source of the Web page which shows the scroll, > > > >>> I can't find the reference to the text displayed. Only "text"... > > > >>> How may we use the software which generates the Javascript ? > > > >>> Thanks, it's cool. > > > >>> > > > >>> franck > > > >> Thanks! > > > >> > > > >> the text is in var commands = ... > > > >> > > > >> You can download the generator script here: > > > >> > > > >> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > > > >> > > > >> (you also need to grab tmovies dir) > > > > When looking at the source of the page : > > > > http://lightbird.net/larks/tmovies/strings.html > > > > I find commands = [] > > > > I can't guess where the strings displayed come from... > > > > > > > > franck > > > > > > Look 10 lines below that line. > > > > > > > > > I have also added a related page that allows you to paste your own > > > text to make a movie; it's linked from the same page with the > > > list of generated t-movies. > > > > > > (that page does not let you use typewriter effect or custom pauses > > > though). > > > > > > - mitya > > > > I'm probably blind but 10 line after the line "commands = []", I find : > > > > var commands = [ > > [ > > "text", > > " " > > ], > > [ > > "text", > > " " > > ], > > ....] > > > > but nothing concrete ! How come ? > > > > franck > > OK OK found ! Thanks. > > franck When executing jstmovie.py, it complains : 'template.html' not found in tmovies... franck tmovies/template.html From msirenef at lightbird.net Sun Jan 20 13:34:49 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 20 Jan 2013 13:34:49 -0500 Subject: ANN: Python training "text movies" In-Reply-To: References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: <50FC38C9.8040105@lightbird.net> On 01/20/2013 12:54 PM, Franck Ditter wrote: > In article , > Franck Ditter wrote: > >> In article , >> Franck Ditter wrote: >> >>> In article , >>> Mitya Sirenef wrote: >>> >>>> On 01/19/2013 04:32 AM, Franck Ditter wrote: >>>>> In article , >>>>> Mitya Sirenef wrote: >>>>> >>>>>> On 01/14/2013 01:34 AM, Franck Ditter wrote: >>>>>>> In article , >>>>>>> Jason Friedman wrote: >>>>>>> >>>>>>>>> That is right; I would also add that it may be overwhelming for a newbie >>>>>>>>> to be reading through a large "wall of text" -- here you have blank >>>>>>>>> space after the current paragraph so the attention is focused even more >>>>>>>>> on the last few lines. >>>>>>>>> >>>>>>>>> Additionally, since instructions scroll automatically, I can space them >>>>>>>>> out more than you would conventionally do in a manual. >>>>>>>>> >>>>>>>> Pretty cool. >>>>>>> When reading the source of the Web page which shows the scroll, >>>>>>> I can't find the reference to the text displayed. Only "text"... >>>>>>> How may we use the software which generates the Javascript ? >>>>>>> Thanks, it's cool. >>>>>>> >>>>>>> franck >>>>>> Thanks! >>>>>> >>>>>> the text is in var commands = ... >>>>>> >>>>>> You can download the generator script here: >>>>>> >>>>>> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py >>>>>> >>>>>> (you also need to grab tmovies dir) >>>>> When looking at the source of the page : >>>>> http://lightbird.net/larks/tmovies/strings.html >>>>> I find commands = [] >>>>> I can't guess where the strings displayed come from... >>>>> >>>>> franck >>>> >>>> Look 10 lines below that line. >>>> >>>> >>>> I have also added a related page that allows you to paste your own >>>> text to make a movie; it's linked from the same page with the >>>> list of generated t-movies. >>>> >>>> (that page does not let you use typewriter effect or custom pauses >>>> though). >>>> >>>> - mitya >>> >>> I'm probably blind but 10 line after the line "commands = []", I find : >>> >>> var commands = [ >>> [ >>> "text", >>> " " >>> ], >>> [ >>> "text", >>> " " >>> ], >>> ....] >>> >>> but nothing concrete ! How come ? >>> >>> franck >> >> OK OK found ! Thanks. >> >> franck > > When executing jstmovie.py, it complains : > 'template.html' not found in tmovies... > > franck > > tmovies/template.html As I've said upthread, you need to download tmovies dir from the same repository where jstmovie.py is located: https://github.com/pythonbyexample/PBE/tree/master/code/ - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Admiration for a quality or an art can be so strong that it deters us from striving to possess it. Friedrich Nietzsche From steve+comp.lang.python at pearwood.info Sun Jan 20 18:55:44 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Jan 2013 23:55:44 GMT Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: <50fc8400$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Jan 2013 18:54:03 +0100, Franck Ditter wrote: [snip quoting NINE levels deep] > When executing jstmovie.py, it complains : 'template.html' not found in > tmovies... Please trim unnecessary quoted text out of your replies. We don't need to read page after page of irrelevant comments that we've already read before. Thank you. If there is more quoted text than new text you have written, or quoting exceeds 3, maybe 4 levels deep, then there probably is too much unnecessary quoting. -- Steven From nobody at nowhere.org Mon Jan 21 03:07:52 2013 From: nobody at nowhere.org (Franck Ditter) Date: Mon, 21 Jan 2013 09:07:52 +0100 Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: Ok I can make my way with jstmovie. Some remarks and questions : - Use encoding='utf-8' inside open of method __init__ of class Tutorial in jstmovie.py. Otherwise foreign languages are stuck. - To use the software outside Python, we need to have proper indentation as real spaces. We should be able to distinguish Arial type for usual text and fixed font for code. - Should have some colors. Wadda wadda yadda # blue annotation Cool and useful software, franck From msirenef at lightbird.net Mon Jan 21 03:31:30 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 21 Jan 2013 03:31:30 -0500 Subject: ANN: Python training "text movies" In-Reply-To: References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: <50FCFCE2.7020101@lightbird.net> On 01/21/2013 03:07 AM, Franck Ditter wrote: > Ok I can make my way with jstmovie. Some remarks and questions : > > - Use encoding='utf-8' inside open of method __init__ of class Tutorial > in jstmovie.py. Otherwise foreign languages are stuck. > > - To use the software outside Python, we need to have proper indentation > as real spaces. We should be able to distinguish Arial type for usual > text and fixed font for code. Not sure I understand about indentation.. You mean like wrapping everything in a textarea tag? Right now everything is in div, which leads to all spaces being compressed in html when viewed. > > > - Should have some colors. > > Wadda wadda yadda # blue annotation I'm thinking of possibly using something like ReStructured text and having css styles. Not sure yet. > > > Cool and useful software, > > franck Thanks! -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ He who would learn to fly one day must first learn to stand and walk and run and climb and dance; one cannot fly into flying. Friedrich Nietzsche From msirenef at lightbird.net Mon Jan 21 03:38:13 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 21 Jan 2013 03:38:13 -0500 Subject: ANN: Python training "text movies" In-Reply-To: References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: <50FCFE75.3090208@lightbird.net> On 01/21/2013 03:07 AM, Franck Ditter wrote: > Ok I can make my way with jstmovie. Some remarks and questions : > > - Use encoding='utf-8' inside open of method __init__ of class Tutorial > in jstmovie.py. Otherwise foreign languages are stuck. > Thanks, will fix this.. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ By nature's kindly disposition most questions which it is beyond a man's power to answer do not occur to him at all. George Santayana From nobody at nowhere.org Mon Jan 21 06:30:50 2013 From: nobody at nowhere.org (Franck Ditter) Date: Mon, 21 Jan 2013 12:30:50 +0100 Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: In article , Mitya Sirenef wrote: > > - To use the software outside Python, we need to have proper indentation > > as real spaces. We should be able to distinguish Arial type for usual > > text and fixed font for code. > > > Not sure I understand about indentation.. You mean like wrapping > everything in a textarea tag? Right now everything is in div, > which leads to all spaces being compressed in html when viewed. SOme spaces are translated in  , others in actual spaces. Say for Scheme, if I write this in foo.txt : > (define z (* 3+2i 1+i)) ; notation a+bi abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz I get this in foo.html (spaces missing) : > (define z (* 3+2i 1+i))???????????????? ; notation a+bi? abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz? franck From msirenef at lightbird.net Mon Jan 21 17:31:50 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 21 Jan 2013 17:31:50 -0500 Subject: ANN: Python training "text movies" In-Reply-To: References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <50F25D6F.20604@lightbird.net> <50F26560.9040800@lightbird.net> Message-ID: <50FDC1D6.8010508@lightbird.net> On 01/21/2013 06:30 AM, Franck Ditter wrote: > In article , > Mitya Sirenef wrote: > >> > - To use the software outside Python, we need to have proper indentation >> > as real spaces. We should be able to distinguish Arial type for usual >> > text and fixed font for code. >> >> >> Not sure I understand about indentation.. You mean like wrapping >> everything in a textarea tag? Right now everything is in div, >> which leads to all spaces being compressed in html when viewed. > > SOme spaces are translated in  , others in actual spaces. > Say for Scheme, if I write this in foo.txt : > >> (define z (* 3+2i 1+i)) ; notation a+bi > abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz > > I get this in foo.html (spaces missing) : > >> (define z (* 3+2i 1+i)) ; notation a+bi > abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz > > franck This applies to Python and all other languages equally, that's why I was confused. I've fixed this issue and added utf-8, and moved the files to a new location & also copied utils.py file which I forgot yesterday. https://github.com/pythonbyexample/PBE/tree/master/jstmovie -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The world is a perpetual caricature of itself; at every moment it is the mockery and the contradiction of what it is pretending to be. George Santayana From rustompmody at gmail.com Mon Jan 21 02:30:32 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 20 Jan 2013 23:30:32 -0800 (PST) Subject: ANN: Python training "text movies" References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20e67b06-7dcb-420c-a0f2-69d2ca767d51@th3g2000pbc.googlegroups.com> On Jan 13, 12:08?pm, Mitya Sirenef wrote: > Sure: they play back a list of instructions on use of string methods and > list comprehensions along with demonstration in a mock-up of the > interpreter with a different display effect for commands typed into (and > printed out by) the interpeter. The speed can be changed and the > playback can be paused. Hi Mitya. What do you use for making these 'text-movies'? [Asking after some googling] From msirenef at lightbird.net Mon Jan 21 03:26:04 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 21 Jan 2013 03:26:04 -0500 Subject: ANN: Python training "text movies" In-Reply-To: <20e67b06-7dcb-420c-a0f2-69d2ca767d51@th3g2000pbc.googlegroups.com> References: <50f255c6$0$30003$c3e8da3$5496439d@news.astraweb.com> <20e67b06-7dcb-420c-a0f2-69d2ca767d51@th3g2000pbc.googlegroups.com> Message-ID: <50FCFB9C.6020109@lightbird.net> On 01/21/2013 02:30 AM, rusi wrote: > On Jan 13, 12:08 pm, Mitya Sirenef wrote: >> Sure: they play back a list of instructions on use of string methods and >> list comprehensions along with demonstration in a mock-up of the >> interpreter with a different display effect for commands typed into (and >> printed out by) the interpeter. The speed can be changed and the >> playback can be paused. > > Hi Mitya. > What do you use for making these 'text-movies'? > [Asking after some googling] I'm using this script: https://github.com/pythonbyexample/PBE/tree/master/jstmovie/ sample source file is in tmovies/src/ -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Depression is rage spread thin. George Santayana From subhabangalore at gmail.com Sun Jan 13 07:45:39 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 13 Jan 2013 04:45:39 -0800 (PST) Subject: For Loop in List Message-ID: Dear Group, I have a list like, >>> list1=[1,2,3,4,5,6,7,8,9,10,11,12] Now, if I want to take a slice of it, I can. It may be done in, >>> list2=list1[:3] >>> print list2 [1, 2, 3] If I want to iterate the list, I may do as, >>> for i in list1: print "Iterated Value Is:",i Iterated Value Is: 1 Iterated Value Is: 2 Iterated Value Is: 3 Iterated Value Is: 4 Iterated Value Is: 5 Iterated Value Is: 6 Iterated Value Is: 7 Iterated Value Is: 8 Iterated Value Is: 9 Iterated Value Is: 10 Iterated Value Is: 11 Iterated Value Is: 12 Now, I want to combine iterator with a slicing condition like >>> for i=list2 in list1: print "Iterated Value Is:",i So, that I get the list in the slices like, [1,2,3] [4,5,6] [7,8,9] [10,11,12] But if I do this I get a Syntax Error, is there a solution? If anyone of the learned members may kindly let me know? Apology for any indentation error,etc. Thanking You in Advance, Regards, Subhabrata From d at davea.name Sun Jan 13 08:20:57 2013 From: d at davea.name (Dave Angel) Date: Sun, 13 Jan 2013 08:20:57 -0500 Subject: For Loop in List In-Reply-To: References: Message-ID: <50F2B4B9.5080601@davea.name> On 01/13/2013 07:45 AM, subhabangalore at gmail.com wrote: > Dear Group, > > I have a list like, > >>>> list1=[1,2,3,4,5,6,7,8,9,10,11,12] What version of Python? > Now, if I want to take a slice of it, I can. > It may be done in, >>>> list2=list1[:3] >>>> print list2 > [1, 2, 3] > > If I want to iterate the list, I may do as, > >>>> for i in list1: > print "Iterated Value Is:",i > > > Iterated Value Is: 1 > Iterated Value Is: 2 > Iterated Value Is: 3 > Iterated Value Is: 4 > Iterated Value Is: 5 > Iterated Value Is: 6 > Iterated Value Is: 7 > Iterated Value Is: 8 > Iterated Value Is: 9 > Iterated Value Is: 10 > Iterated Value Is: 11 > Iterated Value Is: 12 > > Now, I want to combine iterator with a slicing condition like > >>>> for i=list2 in list1: > print "Iterated Value Is:",i > > So, that I get the list in the slices like, > [1,2,3] > [4,5,6] > [7,8,9] > [10,11,12] > > But if I do this I get a Syntax Error, is there a solution? It'd be only polite if you actually included the traceback, instead of paraphrasing the error. > If anyone of the learned members may kindly let me know? > > Apology for any indentation error,etc. > > Thanking You in Advance, > > Regards, > Subhabrata > > > > let's examine the code that generates the syntax error. for i=list2 in list1: That doesn't match any of the grammar of Python, so it gives a syntax error. How could the compiler have interpreted it? Perhaps it could have thrown out the 'for' and the colon. That would be equivalent in this case to: i = False or we could toss out the "=list2" but that would give us your first loop. If I were doing this, I'd do something like (untested): temp = list1[:] #make a shallow copy of the list, so we're not modifying the original while temp print temp[:3] temp = temp[3:] I think you could do something similar with zip, but I don't have the energy this morning. -- DaveA From python.list at tim.thechases.com Sun Jan 13 08:29:20 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 13 Jan 2013 07:29:20 -0600 Subject: For Loop in List In-Reply-To: References: Message-ID: <50F2B6B0.3080309@tim.thechases.com> On 01/13/13 06:45, subhabangalore at gmail.com wrote: > Dear Group, > > I have a list like, > >>>> list1=[1,2,3,4,5,6,7,8,9,10,11,12] > > Now, if I want to take a slice of it, I can. > It may be done in, >>>> list2=list1[:3] >>>> print list2 [snip] > Now, I want to combine iterator with a slicing condition like > >>>> for i=list2 in list1: > print "Iterated Value Is:",i > > So, that I get the list in the slices like, > [1,2,3] > [4,5,6] > [7,8,9] > [10,11,12] Well, you get a SyntaxError because, well, it's a syntax error. It may take a little math to do this: >>> SIZE = 3 >>> for i in range(len(list1)//SICE): ... print list1[i*SIZE:i*SIZE+SIZE] ... [1, 2, 3] [4, 5, 6] [7, 8, 9] [10, 11, 12] Or, you can exploit the fact that iterators exhaust inside a for-loop: >>> i = iter(list1) >>> for item in i: ... print [item, i.next(), i.next()] ... [1, 2, 3] [4, 5, 6] [7, 8, 9] [10, 11, 12] Hope this helps, -tkc From lothiraldan at gmail.com Sun Jan 13 08:48:50 2013 From: lothiraldan at gmail.com (Boris FELD) Date: Sun, 13 Jan 2013 14:48:50 +0100 Subject: For Loop in List In-Reply-To: <50F2B6B0.3080309@tim.thechases.com> References: <50F2B6B0.3080309@tim.thechases.com> Message-ID: 2013/1/13 Tim Chase : > On 01/13/13 06:45, subhabangalore at gmail.com wrote: > >>>> SIZE = 3 >>>> for i in range(len(list1)//SICE): > ... print list1[i*SIZE:i*SIZE+SIZE] > ... > [1, 2, 3] > [4, 5, 6] > [7, 8, 9] > [10, 11, 12] > A little shorter and simpler version: >>> x = x[1:] >>> for i in range(0,len(x),SIZE): ... print x[i: i+SIZE] ... [1, 2, 3] [4, 5, 6] [7, 8, 9] [10, 11, 12] Hope it helps > Hope this helps, > > -tkc From python.list at tim.thechases.com Sun Jan 13 09:07:10 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 13 Jan 2013 08:07:10 -0600 Subject: For Loop in List In-Reply-To: References: <50F2B6B0.3080309@tim.thechases.com> Message-ID: <50F2BF8E.2000909@tim.thechases.com> On 01/13/13 07:48, Boris FELD wrote: > 2013/1/13 Tim Chase : >>>>> SIZE = 3 >>>>> for i in range(len(list1)//SICE): >> ... print list1[i*SIZE:i*SIZE+SIZE] > > A little shorter and simpler version: >>>> x = x[1:] >>>> for i in range(0,len(x),SIZE): > ... print x[i: i+SIZE] Doh, I always forget that range() takes an optional stride. Or rather, I use it so infrequently that I reach for other alternatives before it occurs to me :) -tkc From msirenef at lightbird.net Sun Jan 13 12:41:39 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 13 Jan 2013 12:41:39 -0500 Subject: For Loop in List In-Reply-To: References: Message-ID: <50F2F1D3.6050709@lightbird.net> On 01/13/2013 07:45 AM, subhabangalore at gmail.com wrote: > Dear Group, > > I have a list like, > >>>> list1=[1,2,3,4,5,6,7,8,9,10,11,12] > Now, if I want to take a slice of it, I can. > It may be done in, >>>> list2=list1[:3] >>>> print list2 > [1, 2, 3] > > If I want to iterate the list, I may do as, > >>>> for i in list1: > print "Iterated Value Is:",i > > > Iterated Value Is: 1 > Iterated Value Is: 2 > Iterated Value Is: 3 > Iterated Value Is: 4 > Iterated Value Is: 5 > Iterated Value Is: 6 > Iterated Value Is: 7 > Iterated Value Is: 8 > Iterated Value Is: 9 > Iterated Value Is: 10 > Iterated Value Is: 11 > Iterated Value Is: 12 > > Now, I want to combine iterator with a slicing condition like > >>>> for i=list2 in list1: > print "Iterated Value Is:",i > > So, that I get the list in the slices like, > [1,2,3] > [4,5,6] > [7,8,9] > [10,11,12] > > But if I do this I get a Syntax Error, is there a solution? > > If anyone of the learned members may kindly let me know? > > Apology for any indentation error,etc. > > Thanking You in Advance, > > Regards, > Subhabrata > > > > Another good answer is to use a recipe from itertools docs page. There are a lot of good recipes there and you may want to keep them all in a module you can import from when needed. Here is the recipe: def grouper(n, iterable, fillvalue=None): """From itertools recipes: collect data into fixed-length chunks or blocks.""" # grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) >>> list(grouper(3, range(12)) ... ... ... ... ) [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)] HTH, - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From abhasbhattacharya2 at gmail.com Sun Jan 13 10:36:51 2013 From: abhasbhattacharya2 at gmail.com (Abhas Bhattacharya) Date: Sun, 13 Jan 2013 07:36:51 -0800 (PST) Subject: Creating continuous keystroke with python Message-ID: <4d4fb80f-432a-4023-8f32-39bca0b1ddc4@googlegroups.com> I need to generate continuous keystroke with python. I have been trying with the sendkeys module, but the only command it supports is sending discrete keypresses. But I need a continous keypress, so that the other application (which in this case is a game which triggers an action only when a key is continously pressed for some time)can recognise it as such. Also I tried using the sendkeys function on pywin32 api, but it does the same thing too. My hope is there will be another function in pywin32 or some other api which can create seperate keydown event and keyup event so that I can bypass the keydown event for some time. From maillists at nic.fi Sun Jan 13 11:13:28 2013 From: maillists at nic.fi (K. Elo) Date: Sun, 13 Jan 2013 18:13:28 +0200 Subject: Keyboard hook in linux Message-ID: <50F2DD28.9020001@nic.fi> Hi! I am working on a small console app for linux. The idea is to display some sensor values and the screen should update itself in, say, every 10 seconds. The user should have the possibly to change some configurations or gwt help by pressing different keys (like you can do when running e.g. 'top'). In other words: the program should NOT wait for the keypress (so input() is not the solution), but simply capture keypresses and act accordingly. If no key is pressed, the program should continue updating the screen. Practically I am looking for something similar than Pascal's "keypressed" function (http://www.freepascal.org/docs-html/rtl/crt/keypressed.html). The python code would be something like this: --- snip --- while True: if keypressed: ch=screen.getch() # From 'curses' # Test, if 'ch' is a valid key # Do what the user want read_sensors() update_screen() --- snip --- I have searched in the Web and in several tutorials (e.g. "Programming python"), but this seems to be a tricky one. The 'pyHook' library seems to offer a keyboard hook manager, but 'pyHook' is not available for linux :( IMHO, the 'curses' library offers no (direct) solution to this... Does anybody have an idea / a solution, how to capture keystrokes in linux? Kind regards, Kimmo From torriem at gmail.com Sun Jan 13 11:42:01 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 13 Jan 2013 09:42:01 -0700 Subject: Keyboard hook in linux In-Reply-To: <50F2DD28.9020001@nic.fi> References: <50F2DD28.9020001@nic.fi> Message-ID: <50F2E3D9.3080708@gmail.com> On 01/13/2013 09:13 AM, K. Elo wrote: > I am working on a small console app for linux. The idea is to display > some sensor values and the screen should update itself in, say, every 10 > seconds. > > The user should have the possibly to change some configurations or gwt > help by pressing different keys (like you can do when running e.g. > 'top'). In other words: the program should NOT wait for the keypress (so > input() is not the solution), but simply capture keypresses and act > accordingly. If no key is pressed, the program should continue updating > the screen. 'top' is built using a programming library called 'curses' or 'ncurses.' That's likely where you'll need to go to. At least if you want to be able to run properly on different terminals. ncurses handles terminal output including writing text at certain positions, and input/output, and even mouse interactions if you felt you needed that. It's apparently part of the standard python library: http://docs.python.org/2/library/curses.html From torriem at gmail.com Sun Jan 13 11:46:31 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 13 Jan 2013 09:46:31 -0700 Subject: Keyboard hook in linux In-Reply-To: <50F2DD28.9020001@nic.fi> References: <50F2DD28.9020001@nic.fi> Message-ID: <50F2E4E7.2050008@gmail.com> On 01/13/2013 09:13 AM, K. Elo wrote: > I have searched in the Web and in several tutorials (e.g. "Programming > python"), but this seems to be a tricky one. The 'pyHook' library seems > to offer a keyboard hook manager, but 'pyHook' is not available for > linux :( IMHO, the 'curses' library offers no (direct) solution to this... You're wrong. curses does offer a direct solution to this. Check the docs. Also here's a nice intro document for Python 3: http://docs.python.org/dev/howto/curses.html You can check to see if a keystroke is waiting, grab it and then do something useful. curses can even grab keys like page up or page down. From maillists at nic.fi Sun Jan 13 13:10:46 2013 From: maillists at nic.fi (K. Elo) Date: Sun, 13 Jan 2013 20:10:46 +0200 Subject: Keyboard hook in linux In-Reply-To: <50F2E4E7.2050008@gmail.com> References: <50F2DD28.9020001@nic.fi> <50F2E4E7.2050008@gmail.com> Message-ID: <50F2F8A6.5020102@nic.fi> Hi! Thanks, Michael, for your quick - and heplful - reply. 13.01.2013 18:46, Michael Torrie wrote: > You're wrong. curses does offer a direct solution to this. Check the > docs. Also here's a nice intro document for Python 3: > http://docs.python.org/dev/howto/curses.html You are right :) The docs tell us (I somehow missed this when reading the doc last time): "It?s possible to change this behavior with the method nodelay(). After nodelay(1), getch() for the window becomes non-blocking and returns curses.ERR (a value of -1) when no input is ready. There?s also a halfdelay() function, which can be used to (in effect) set a timer on each getch(); if no input becomes available within a specified delay (measured in tenths of a second), curses raises an exception." This is actually funny: if you google for e.g. "capture keystrokes python", you will find masses of suggestions, none of them having this simple and elegant (i.e. python-like :) ) solution included. Now it works and my problem is solved. Thank you! Kind regards, Kimmo From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Jan 13 13:11:29 2013 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 13 Jan 2013 18:11:29 +0000 (UTC) Subject: Keyboard hook in linux References: Message-ID: K. Elo wrote: > Practically I am looking for something similar than Pascal's > "keypressed" function As already mentioned, (n)curses is a good solution. However, if you need/want to go to lower levels, you can read /dev/input/event* like this (excerpt from one of my programs): def opendevs(): return [os.open(dev, os.O_RDONLY) for dev in glob.glob("/dev/input/event*")] def readevent(fds): try: # file descriptor has disappeared - we unplugged the keyboard, # resumed from suspend etc... ps = [os.read(fd, 16) for fd in fds] except OSError: traceback.print_exc() yield None, None, None for p in ps: timeval, suseconds, typ, code, value = struct.unpack( 'llHHI', p[:16]) yield typ, value, code def run_print(fds): while 1: rs, ws, xs = select.select(fds, [], []) for t, v, e in readevent(rs): print "Event code:", e, "type:", t, "value:", v fds = opendevs() run_print(fds) This is of course not portable at all (and won't run on ancient Linuces), but the advantage is that you can hook to the keys or key combinations curses cannot (e.g. modifiers, Scrolllock etc...) and the program can react to the key events even in the background. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From phaley at MIT.EDU Sun Jan 13 13:00:54 2013 From: phaley at MIT.EDU (Patrick Haley) Date: Sun, 13 Jan 2013 18:00:54 +0000 Subject: Upgrading Python with NumPy, SciPy and Mayavi in a Rocks 6.0 cluster Message-ID: <3EE10DA10D22C64F9D3FF9B5A7AA36CA0306E6@OC11EXPO26.exchange.mit.edu> Hi, We are looking for some guidance in installing an upgraded Python on our cluster. Our cluster was installed with Rocks 6.0, is running CentOs 6.2, and has python-2.6.6, gcc-4.4.6. We would like to install an upgraded version of Python along with the following modules NumPy Scipy (which will require a compatible version of the Atlas libraries) Mayavi (which will require a compatible version of vtk) We were wondering if anyone has experience in installing these packages, what are the best combinations of compatible versions, what other upgrades will be needed (e.g. will we need to upgrade the gnu compilers to install the latest versions) and where these should be installed (local disks, /share/apps, other?). A little more background, our students are currently working with a local installation using Python-2.7.1 numpy-1.5.1 scipy-0.9.0b1 Mayavi-3.4.0 ATLAS-3.8.3 vtk-5.4 We would like to install these packages in a more appropriate, cluster-wide area and upgrade these packages as appropriate. We are also aware of a Rocks python roll which contains python-2.7.2 and an upspecified version of NumPy (is it possible to find out which version, before installing the roll?). Thanks -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Pat Haley Email: phaley at mit.edu Center for Ocean Engineering Phone: (617) 253-6824 Dept. of Mechanical Engineering Fax: (617) 253-8125 MIT, Room 5-213 http://web.mit.edu/phaley/www/ 77 Massachusetts Avenue Cambridge, MA 02139-4301 -------------- next part -------------- An HTML attachment was scrubbed... URL: From subhabangalore at gmail.com Sun Jan 13 15:05:54 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 13 Jan 2013 12:05:54 -0800 (PST) Subject: Subgraph Drawing Message-ID: Dear Group, I have two questions, if I take a subseries of the matrix as in eigenvalue here, provided I have one graph of the full form in G, how may I show it, as if I do the nx.draw(G) it takes only the original graph. >>> import numpy >>> import networkx as nx >>> import matplotlib.pyplot as plt >>> G=nx.Graph() >>> G.add_edges_from([(1,2),(1,3),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8)]) >>> L =nx.laplacian(G) >>> print L [[ 7. -1. -1. -1. -1. -1. -1. -1.] [-1. 1. 0. 0. 0. 0. 0. 0.] [-1. 0. 1. 0. 0. 0. 0. 0.] [-1. 0. 0. 1. 0. 0. 0. 0.] [-1. 0. 0. 0. 1. 0. 0. 0.] [-1. 0. 0. 0. 0. 1. 0. 0.] [-1. 0. 0. 0. 0. 0. 1. 0.] [-1. 0. 0. 0. 0. 0. 0. 1.]] >>> print numpy.linalg.eigvals(L) [ 8.00000000e+00 2.22044605e-16 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00] for more than 1000 nodes it is coming too slow on Windows 7 machine with 3GB RAM. If any one of the learned members can help. Apology for any indentation error etc. Thanking all in Advance, Regards, Subhabrata Banerjee. From oscar.j.benjamin at gmail.com Sun Jan 13 18:26:31 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 13 Jan 2013 23:26:31 +0000 Subject: Subgraph Drawing In-Reply-To: References: Message-ID: On 13 January 2013 20:05, wrote: > Dear Group, > > I have two questions, if I take a subseries of the matrix as in eigenvalue here, > provided I have one graph of the full form in G, how may I show it, as if I do the nx.draw(G) it takes only the original graph. I'm sorry, but I really don't understand what you mean. When you say "subseries" do you mean "subgraph"? Or do you mean a subset of the eigenvalues? It would be good if you could give a simple example of what you mean using code and showing the expected/desired output. > >>>> import numpy >>>> import networkx as nx >>>> import matplotlib.pyplot as plt >>>> G=nx.Graph() >>>> G.add_edges_from([(1,2),(1,3),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8)]) >>>> L =nx.laplacian(G) >>>> print L > [[ 7. -1. -1. -1. -1. -1. -1. -1.] > [-1. 1. 0. 0. 0. 0. 0. 0.] > [-1. 0. 1. 0. 0. 0. 0. 0.] > [-1. 0. 0. 1. 0. 0. 0. 0.] > [-1. 0. 0. 0. 1. 0. 0. 0.] > [-1. 0. 0. 0. 0. 1. 0. 0.] > [-1. 0. 0. 0. 0. 0. 1. 0.] > [-1. 0. 0. 0. 0. 0. 0. 1.]] >>>> print numpy.linalg.eigvals(L) > [ 8.00000000e+00 2.22044605e-16 1.00000000e+00 1.00000000e+00 > 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00] > > for more than 1000 nodes it is coming too slow on Windows 7 machine with 3GB RAM. What is too slow? Oscar From steve+comp.lang.python at pearwood.info Sun Jan 13 19:35:49 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2013 00:35:49 GMT Subject: Subgraph Drawing References: Message-ID: <50f352e4$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Jan 2013 12:05:54 -0800, subhabangalore wrote: > Dear Group, > > I have two questions, if I take a subseries of the matrix as in > eigenvalue here, provided I have one graph of the full form in G, how > may I show it, as if I do the nx.draw(G) it takes only the original > graph. Is this what you mean? If not, you will have to explain your question better. L = = nx.laplacian(G) E = numpy.linalg.eigvals(L) nx.draw(E) > >>> print numpy.linalg.eigvals(L) > [ 8.00000000e+00 2.22044605e-16 1.00000000e+00 1.00000000e+00 > 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00] > for more than 1000 nodes it is coming too slow on Windows 7 machine with > 3GB RAM. Get a faster machine. Or use fewer nodes. Or be patient and wait. Solving a graph problem with 1000 nodes is a fairly big problem for a desktop PC. It will take time. Calculations don't just happen instantly, the more work you have to do the longer they take. The last alternative is to ask on a specialist numpy list. But I expect they will probably tell you the same thing. -- Steven From subhabangalore at gmail.com Sun Jan 13 23:01:21 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 13 Jan 2013 20:01:21 -0800 (PST) Subject: Subgraph Drawing In-Reply-To: <50f352e4$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50f352e4$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <206286d8-1be8-4764-9eaf-e25b78263741@googlegroups.com> On Monday, January 14, 2013 6:05:49 AM UTC+5:30, Steven D'Aprano wrote: > On Sun, 13 Jan 2013 12:05:54 -0800, subhabangalore wrote: > > > > > Dear Group, > > > > > > I have two questions, if I take a subseries of the matrix as in > > > eigenvalue here, provided I have one graph of the full form in G, how > > > may I show it, as if I do the nx.draw(G) it takes only the original > > > graph. > > > > Is this what you mean? If not, you will have to explain your question > > better. > > > > > > L = = nx.laplacian(G) > > E = numpy.linalg.eigvals(L) > > nx.draw(E) > > > > > > > >>> print numpy.linalg.eigvals(L) > > > [ 8.00000000e+00 2.22044605e-16 1.00000000e+00 1.00000000e+00 > > > 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00] > > > for more than 1000 nodes it is coming too slow on Windows 7 machine with > > > 3GB RAM. > > > > Get a faster machine. Or use fewer nodes. Or be patient and wait. > > > > Solving a graph problem with 1000 nodes is a fairly big problem for a > > desktop PC. It will take time. Calculations don't just happen instantly, > > the more work you have to do the longer they take. > > > > The last alternative is to ask on a specialist numpy list. But I expect > > they will probably tell you the same thing. > > > > > > -- > > Steven Dear Steven, Thank you for your kind effort. You got the problem right. But it is giving following error, Traceback (most recent call last): File "", line 1, in nx.draw(E) File "C:\Python27\lib\site-packages\networkx\drawing\nx_pylab.py", line 138, in draw draw_networkx(G,pos=pos,ax=ax,**kwds) File "C:\Python27\lib\site-packages\networkx\drawing\nx_pylab.py", line 267, in draw_networkx pos=nx.drawing.spring_layout(G) # default to spring layout File "C:\Python27\lib\site-packages\networkx\drawing\layout.py", line 241, in fruchterman_reingold_layout A=nx.to_numpy_matrix(G,weight=weight) File "C:\Python27\lib\site-packages\networkx\convert.py", line 492, in to_numpy_matrix nodelist = G.nodes() AttributeError: 'numpy.ndarray' object has no attribute 'nodes' >>> there are other solution of converting back the matrix to graph should I try that? Regards, Subhabrata. From steve+comp.lang.python at pearwood.info Sun Jan 13 23:13:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2013 04:13:50 GMT Subject: Subgraph Drawing References: <50f352e4$0$30003$c3e8da3$5496439d@news.astraweb.com> <206286d8-1be8-4764-9eaf-e25b78263741@googlegroups.com> Message-ID: <50f385fe$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Jan 2013 20:01:21 -0800, subhabangalore wrote: > there are other solution of converting back the matrix to graph should I > try that? Yes. -- Steven From yogeswar.prasad1 at gmail.com Sun Jan 13 15:35:01 2013 From: yogeswar.prasad1 at gmail.com (Divya Thakur) Date: Sun, 13 Jan 2013 12:35:01 -0800 (PST) Subject: please solve my problem Message-ID: <72e8aec3-4fa3-44af-aad7-8b32196da774@googlegroups.com> hello i need help for my ecommerce project ,and here i am facing some problem here is my query "i want to show image by the help of MEDIA_URL and this is my template file code for this
{% block content %}{% endblock %}
{% endblock %} and this is my category .html file {% extends "catalog.html" %} {% block content %}

{{ c.name }}

{{ c.description }}

{% for p in products %} {% endfor %} {% endblock %} and this is my product.html file {% extends "catalog.html" %} {% block content %}
{{ 

p.name }}

{{ p.name }}

Brand: {{ p.brand }}

SKU: {{ p.sku }}
In categor{{ categories.count|pluralize:"y,ies" }}: {% for c in categories %} {{ c.name }} {% if not forloop.last %},{% endif %} {% endfor %}

{% if p.sale_price %} Was: $ {{ p.old_price }}
Now: $ {{ p.price }} {% else %} Price: $ {{ p.price }} {% endif %}

[add to cart button]



Product Description

{{ p.description }} {% endblock %} so please help me and fix that problem for me although i know that the error in template file but i could,t able to fix it From roy at panix.com Sun Jan 13 15:42:47 2013 From: roy at panix.com (Roy Smith) Date: Sun, 13 Jan 2013 15:42:47 -0500 Subject: please solve my problem References: <72e8aec3-4fa3-44af-aad7-8b32196da774@googlegroups.com> Message-ID: In article <72e8aec3-4fa3-44af-aad7-8b32196da774 at googlegroups.com>, Divya Thakur wrote: > "i want to show image by the help of MEDIA_URL and this is my template file > code for this > not working This is a django-specific question. You would do better to ask on the django-users mailing list: https://groups.google.com/forum/?fromgroups#!forum/django-users From rosuav at gmail.com Sun Jan 13 15:47:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Jan 2013 07:47:21 +1100 Subject: please solve my problem In-Reply-To: <72e8aec3-4fa3-44af-aad7-8b32196da774@googlegroups.com> References: <72e8aec3-4fa3-44af-aad7-8b32196da774@googlegroups.com> Message-ID: On Mon, Jan 14, 2013 at 7:35 AM, Divya Thakur wrote: > raise TemplateDoesNotExist(name) > TemplateDoesNotExist: 500.html > [14/Jan/2013 01:08:11] "GET /static/images/products/thumbnails/12345 HTTP/1.1" 500 59 This sounds like a Django-specific issue. You'll probably get better results from a more Django-specific list: https://www.djangoproject.com/community/ > here is my settings.py file > # Make this unique, and don't share it with anybody. > SECRET_KEY = '2h(8t+9z4z-m(fuhl17eqp78q!yxo4&i54jofml3uoyv at a3y3x' You've just dumped a huge amount of text to us, including something that probably shouldn't have been shared. I strongly recommend you change this key, now that it's gone public, and consider trimming your text down to just what's needed to reproduce the problem. ChrisA From dreamingforward at gmail.com Sun Jan 13 21:10:48 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 13 Jan 2013 20:10:48 -0600 Subject: Beowulf clusters Message-ID: Has anyone used python for high-performance computing on Beowulf clusters? Thanks, MarkJ From oscar.j.benjamin at gmail.com Sun Jan 13 21:19:14 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 14 Jan 2013 02:19:14 +0000 Subject: Beowulf clusters In-Reply-To: References: Message-ID: On 14 January 2013 02:10, Mark Janssen wrote: > Has anyone used python for high-performance computing on Beowulf clusters? Yes. From dreamingforward at gmail.com Sun Jan 13 21:22:37 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 13 Jan 2013 20:22:37 -0600 Subject: Beowulf clusters In-Reply-To: References: Message-ID: On Sun, Jan 13, 2013 at 8:19 PM, Oscar Benjamin wrote: > On 14 January 2013 02:10, Mark Janssen wrote: >> Has anyone used python for high-performance computing on Beowulf clusters? > > Yes. How did they deal with the Global interpreter lock across many machines? Cheers, Mark From oscar.j.benjamin at gmail.com Sun Jan 13 21:30:17 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 14 Jan 2013 02:30:17 +0000 Subject: Beowulf clusters In-Reply-To: References: Message-ID: On 14 January 2013 02:22, Mark Janssen wrote: > On Sun, Jan 13, 2013 at 8:19 PM, Oscar Benjamin > wrote: >> On 14 January 2013 02:10, Mark Janssen wrote: >>> Has anyone used python for high-performance computing on Beowulf clusters? >> >> Yes. > > How did they deal with the Global interpreter lock across many machines? Unless I've drastically misunderstood something there is no GIL across many machines. The GIL is a per-process lock so there is a different GIL for each process on the same machine and there is no interaction between the GILs on the same, or on different, machines. Oscar From dreamingforward at gmail.com Sun Jan 13 21:46:13 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 13 Jan 2013 20:46:13 -0600 Subject: Beowulf clusters In-Reply-To: References: Message-ID: On Sun, Jan 13, 2013 at 8:37 PM, Oscar Benjamin wrote: > On 14 January 2013 02:33, Mark Janssen wrote: >> Lol, well that's why I'm asking. I don't see how they can do it >> without considerable difficulties. > > What do you want the GIL for across machines? The normal purpose of > the GIL is to preserve the integrity of Python's in-memory data > structures. These are only accessible within one process so what good > would a multi-process GIL be? Excuse me, I actually thought you knew what you were talking about. A Beowulf cluster, by it's nature, is across many-machines. Now you can't have a GIL and a single python program across many-machines without some tricks. I'm just wondering how (or if) they solved that problem.... mark From oscar.j.benjamin at gmail.com Sun Jan 13 21:50:46 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 14 Jan 2013 02:50:46 +0000 Subject: Beowulf clusters In-Reply-To: References: Message-ID: On 14 January 2013 02:46, Mark Janssen wrote: > On Sun, Jan 13, 2013 at 8:37 PM, Oscar Benjamin > wrote: >> On 14 January 2013 02:33, Mark Janssen wrote: >>> Lol, well that's why I'm asking. I don't see how they can do it >>> without considerable difficulties. >> >> What do you want the GIL for across machines? The normal purpose of >> the GIL is to preserve the integrity of Python's in-memory data >> structures. These are only accessible within one process so what good >> would a multi-process GIL be? > > Excuse me, I actually thought you knew what you were talking about. Steady on... > A Beowulf cluster, by it's nature, is across many-machines. Now you > can't have a GIL and a single python program across many-machines > without some tricks. I'm just wondering how (or if) they solved that > problem.... You've used the word 'program'. I used the word 'process'. I have used HPC clusters that I assume count as Beowulf clusters. However, I have never used them in such a way that a single process occurred on multiple machines (the idea seems absurd to me). Maybe I've missed something here... Oscar From craigyk at me.com Sun Jan 13 21:35:55 2013 From: craigyk at me.com (Craig Yoshioka) Date: Sun, 13 Jan 2013 18:35:55 -0800 Subject: Beowulf clusters In-Reply-To: References: Message-ID: When you write HPC code the GIL isn't an issue, but you'll have plenty of others. Craig reporting from the road 10550 N Torrey Pines Rd La Jolla CA 92037 work: 858 784 9208 cell: 619 623 2233 On Jan 13, 2013, at 6:22 PM, Mark Janssen wrote: > On Sun, Jan 13, 2013 at 8:19 PM, Oscar Benjamin > wrote: >> On 14 January 2013 02:10, Mark Janssen wrote: >>> Has anyone used python for high-performance computing on Beowulf clusters? >> >> Yes. > > How did they deal with the Global interpreter lock across many machines? > > Cheers, > > Mark > -- > http://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Sun Jan 13 23:16:29 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2013 04:16:29 GMT Subject: Thought of the day Message-ID: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> A programmer had a problem, and thought Now he has "I know, I'll solve two it with threads!" problems. -- Steven From d at davea.name Mon Jan 14 00:31:59 2013 From: d at davea.name (Dave Angel) Date: Mon, 14 Jan 2013 00:31:59 -0500 Subject: Thought of the day In-Reply-To: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F3984F.6070301@davea.name> On 01/13/2013 11:16 PM, Steven D'Aprano wrote: > A programmer had a problem, and thought Now he has "I know, I'll solve > two it with threads!" problems. > > ++10 I've been thinking about threads lately, and have come to the tentative conclusion that they're a solution which has outlived its usefulness for 99% of the use cases. Much like the Windows 3.1 model of memory usage, where all memory was shared, and apps promised not to step too hard on each other. Or the "640k is more memory than any application will ever need" notion. When you multiprocess, everything is private except those things you work at sharing. When you multithread, everything is shared, and you promise not to intentionally do anything too nasty with the ability. -- DaveA From wuwei23 at gmail.com Mon Jan 14 07:09:23 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 14 Jan 2013 04:09:23 -0800 (PST) Subject: Thought of the day References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jan 14, 2:16?pm, Steven D'Aprano wrote: > A programmer had a problem, and thought Now he has "I know, I'll solve > two it with threads!" problems. I laughed far far longer than I should have, cheers :) From python.list at tim.thechases.com Mon Jan 14 09:15:34 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 14 Jan 2013 08:15:34 -0600 Subject: Thought of the day In-Reply-To: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F41306.8090507@tim.thechases.com> On 01/13/13 22:16, Steven D'Aprano wrote: > A programmer had a problem, and thought Now he has "I know, I'll > solve two it with threads!" problems. A newbie programmer had a problem and thought "I'll solve it by posting on python-list at python.org and on Google Groups". And now we have the problem of two threads... Intentionally-misinterpreting'ly yours, -tkc From rosuav at gmail.com Mon Jan 14 09:18:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jan 2013 01:18:19 +1100 Subject: Thought of the day In-Reply-To: <50F41306.8090507@tim.thechases.com> References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> <50F41306.8090507@tim.thechases.com> Message-ID: On Tue, Jan 15, 2013 at 1:15 AM, Tim Chase wrote: > A newbie programmer had a problem and thought > > > > "I'll solve it by posting on > > > > python-list at python.org and on Google Groups". > > > > And now we have the problem of two threads... And, when faced with problems of having two threads, the most obvious solution is to add sleep() calls, so it looks like the above... Am I dragging the analogy out too far? ChrisA From d at davea.name Mon Jan 14 09:31:30 2013 From: d at davea.name (Dave Angel) Date: Mon, 14 Jan 2013 09:31:30 -0500 Subject: Thought of the day In-Reply-To: References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> <50F41306.8090507@tim.thechases.com> Message-ID: <50F416C2.7010609@davea.name> On 01/14/2013 09:18 AM, Chris Angelico wrote: > On Tue, Jan 15, 2013 at 1:15 AM, Tim Chase > wrote: >> A newbie programmer had a problem and thought >> >> >> >> "I'll solve it by posting on >> >> >> >> python-list at python.org and on Google Groups". >> >> >> >> And now we have the problem of two threads... > And, when faced with problems of having two threads, the most obvious > solution is to add sleep() calls, so it looks like the above... Am I > dragging the analogy out too far? > > ChrisA Naaah, too far would be trying to relate the GIL to KILL files. For example, I avoid the google groups double-post syndrome by killfiling any message with google-groups in the To: or CC: fields. 596 messages in six months. I still get the second copy. -- DaveA From dan at tombstonezero.net Mon Jan 14 09:44:35 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 14 Jan 2013 14:44:35 GMT Subject: Thought of the day References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 14 Jan 2013 00:31:59 -0500, Dave Angel wrote: > On 01/13/2013 11:16 PM, Steven D'Aprano wrote: >> A programmer had a problem, and thought Now he has "I know, I'll solve >> two it with threads!" problems. > > ++10 It took me a moment to figure it out, but in the end I smiled and I agree: +1. > I've been thinking about threads lately, and have come to the tentative > conclusion that they're a solution which has outlived its usefulness for > 99% of the use cases. Much like the Windows 3.1 model of memory usage, > where all memory was shared, and apps promised not to step too hard on > each other. Or the "640k is more memory than any application will ever > need" notion. With this, however, I don't agree. If Python's GIL didn't interfere with the concurrency of threads, I can't think of a good reason to use multiple processes instead, except to use a tool that runs outside the Python virtual machine, or to provide more fault tolerance for long- running server-like applications. We're all adults here, and if the policy is to invoke the methods of objects as documented, then that policy extends to stepping on (or not stepping on) the memory of other threads, too. The APIs for threads and processes is pretty much the same, so I suppose it doesn't matter much, either. Use the right tool for the job. Dan From d at davea.name Mon Jan 14 12:12:54 2013 From: d at davea.name (Dave Angel) Date: Mon, 14 Jan 2013 12:12:54 -0500 Subject: Thought of the day In-Reply-To: References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F43C96.3030806@davea.name> On 01/14/2013 09:44 AM, Dan Sommers wrote: > On Mon, 14 Jan 2013 00:31:59 -0500, Dave Angel wrote: > >> On 01/13/2013 11:16 PM, Steven D'Aprano wrote: >>> A programmer had a problem, and thought Now he has "I know, I'll solve >>> two it with threads!" problems. >> ++10 > It took me a moment to figure it out, but in the end I smiled and I > agree: +1. > >> I've been thinking about threads lately, and have come to the tentative >> conclusion that they're a solution which has outlived its usefulness for >> 99% of the use cases. Much like the Windows 3.1 model of memory usage, >> where all memory was shared, and apps promised not to step too hard on >> each other. Or the "640k is more memory than any application will ever >> need" notion. > With this, however, I don't agree. If Python's GIL didn't interfere with > the concurrency of threads, Better minds than mine have tried very hard to eliminate the GIL, so for now I consider that a feature of Python. If the GIL weren't needed for the lowest levels of the interpreter, something else would be needed for all the possible data structures that need atomic updates. Hello semaphores, mutexes, etc. If threading were considered important in a language, it'd have a way to declare an object sharable (default off), and the low level code would go at full speed for any object not so declared. But the language would then provide guarantees for the standard objects that are marked as sharable. That's not current Python. > I can't think of a good reason to use > multiple processes instead, except to use a tool that runs outside the > Python virtual machine, or to provide more fault tolerance for long- > running server-like applications. We're all adults here, and if the > policy is to invoke the methods of objects as documented, then that > policy extends to stepping on (or not stepping on) the memory of other > threads, too. > > The APIs for threads and processes is pretty much the same, so I suppose > it doesn't matter much, either. Use the right tool for the job. > > Dan For other languages, I've done extensive work on projects with heavy multithreading, and getting it right is extremely difficult. Another way of putting it is that any non-trivial project with multithreading is probably buggy. -- DaveA From invalid at invalid.invalid Mon Jan 14 10:08:12 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 14 Jan 2013 15:08:12 +0000 (UTC) Subject: Thought of the day References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-01-14, Steven D'Aprano wrote: > A programmer had a problem, and thought Now he has "I know, I'll solve > two it with threads!" problems. :) That took a few seconds -- must be the cold. -- Grant Edwards grant.b.edwards Yow! I hope I bought the at right relish ... zzzzzzzzz gmail.com ... From demianbrecht at gmail.com Mon Jan 14 12:30:05 2013 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 14 Jan 2013 09:30:05 -0800 Subject: Thought of the day In-Reply-To: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: I love getting that "what's up with this guy" when I start chuckling so hard that I nearly spit out my coffee first thing Monday morning. Thank you sir, this has given my week a bright start :) Demian Brecht http://demianbrecht.github.com On 2013-01-13 8:16 PM, "Steven D'Aprano" wrote: >A programmer had a problem, and thought Now he has "I know, I'll solve >two it with threads!" problems. > > > >-- >Steven >-- >http://mail.python.org/mailman/listinfo/python-list From demianbrecht at gmail.com Mon Jan 14 12:30:58 2013 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 14 Jan 2013 09:30:58 -0800 Subject: Thought of the day In-Reply-To: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: ? And I hope you don't mind? I may very well "borrow" this as my e-mail sig. Comedic gold imo. Demian Brecht http://demianbrecht.github.com On 2013-01-13 8:16 PM, "Steven D'Aprano" wrote: >A programmer had a problem, and thought Now he has "I know, I'll solve >two it with threads!" problems. > > > >-- >Steven >-- >http://mail.python.org/mailman/listinfo/python-list From torriem at gmail.com Mon Jan 14 12:37:54 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 14 Jan 2013 10:37:54 -0700 Subject: Thought of the day In-Reply-To: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F44272.1010404@gmail.com> On 01/13/2013 09:16 PM, Steven D'Aprano wrote: > A programmer had a problem, and thought Now he has "I know, I'll solve > two it with threads!" problems. The same applies to regular expressions, which is actually what the expression was first used with years ago. Probably applies to just about any technology. Including Java. From gordon at panix.com Mon Jan 14 13:09:36 2013 From: gordon at panix.com (John Gordon) Date: Mon, 14 Jan 2013 18:09:36 +0000 (UTC) Subject: Thought of the day References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Michael Torrie writes: > On 01/13/2013 09:16 PM, Steven D'Aprano wrote: > > A programmer had a problem, and thought Now he has "I know, I'll solve > > two it with threads!" problems. > The same applies to regular expressions, which is actually what the > expression was first used with years ago. Probably applies to just > about any technology. Including Java. Steven cleverly worded it in such a way as to apply directly to threads. The sentences are jumbled and interleaved, as if they were the output of two threads that are not synchronized. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From torriem at gmail.com Mon Jan 14 13:25:22 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 14 Jan 2013 11:25:22 -0700 Subject: Thought of the day In-Reply-To: References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F44D92.8060105@gmail.com> On 01/14/2013 11:09 AM, John Gordon wrote: > In Michael Torrie writes: > >> On 01/13/2013 09:16 PM, Steven D'Aprano wrote: >>> A programmer had a problem, and thought Now he has "I know, I'll solve >>> two it with threads!" problems. > >> The same applies to regular expressions, which is actually what the >> expression was first used with years ago. Probably applies to just >> about any technology. Including Java. > > Steven cleverly worded it in such a way as to apply directly to threads. > The sentences are jumbled and interleaved, as if they were the output of > two threads that are not synchronized. Very true! Guess I was too distracted by Python's warts to notice. Haha. From solipsis at pitrou.net Tue Jan 15 11:48:09 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 15 Jan 2013 16:48:09 +0000 (UTC) Subject: Thought of the day References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano pearwood.info> writes: > > A programmer had a problem, and thought Now he has "I know, I'll solve > two it with threads!" problems. Host: Last week the Royal Festival Hall saw the first performance of a new logfile by one of the world's leading modern programmers, Steven "Two threads" D'Aprano. Mr D'Aprano. D'Aprano: Hello. Host: May I just sidetrack for one moment. This -- what shall I call it -- nickname of yours... D'Aprano: Ah yes. Host: "Two threads". How did you come by it? D'Aprano: Well, I don't use it myself, but some of my friends call me "Two Threads". Host: And do you in fact have two threads? D'Aprano: No, I've only got one. I've had one for some time, but a few years ago I said I was thinking of spawning another, and since then some people have called me "Two Threads". Host: In spite of the fact that you only have one. D'Aprano: Yes. Host: And are you still intending to spawn this second thread? D'Aprano: (impatient) No! Host: ...To bring you in line with your epithet? D'Aprano: No. Host: I see, I see. Well to return to your program. D'Aprano: Ah yes. Host: Did you write this logfile in the thread? D'Aprano: (surprised) No! Host: Have you written any of your recent files in this thread of yours? D'Aprano: No, no, not at all. It's just an ordinary daemon thread. Host: I see, I see. And you're thinking of spawning this second thread to write in! D'Aprano: No, no. Look. This thread business -- it doesn't really matter. The threads aren't important. A few friends call me Two Threads and that's all there is to it. I wish you'd ask me about the logfile. Everybody talks about the threads. They've got it out of proportion -- I'm a programmer. I'm going to get rid of the thread. I'm fed up with it! Host: Then you'll be Steven "No Threads" D'Aprano, eh? From mail at timgolden.me.uk Tue Jan 15 11:59:58 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Jan 2013 16:59:58 +0000 Subject: Thought of the day In-Reply-To: References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F58B0E.8090401@timgolden.me.uk> On 15/01/2013 16:48, Antoine Pitrou wrote: > Steven D'Aprano pearwood.info> writes: >> >> A programmer had a problem, and thought Now he has "I know, I'll solve >> two it with threads!" problems. > > > Host: Last week the Royal Festival Hall saw the first performance of a new > logfile by one of the world's leading modern programmers, Steven > "Two threads" D'Aprano. Mr D'Aprano. [... snip ...] Brilliant, just brilliant. TJG From rosuav at gmail.com Tue Jan 15 15:27:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jan 2013 07:27:10 +1100 Subject: Thought of the day In-Reply-To: References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 16, 2013 at 3:48 AM, Antoine Pitrou wrote: > D'Aprano: No, no. Look. This thread business -- it doesn't really matter. > The threads aren't important. A few friends call me Two Threads and that's > all there is to it. I wish you'd ask me about the logfile. Everybody talks > about the threads. They've got it out of proportion -- I'm a programmer. > I'm going to get rid of the thread. I'm fed up with it! > > Host: Then you'll be Steven "No Threads" D'Aprano, eh? Close, Host. He'd be Steven "No Marbles" D'Aprano. *whistles innocently* ChrisA From djc at news.invalid Tue Jan 15 17:54:58 2013 From: djc at news.invalid (DJC) Date: Tue, 15 Jan 2013 22:54:58 +0000 Subject: Thought of the day In-Reply-To: References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 15/01/13 16:48, Antoine Pitrou wrote: > Steven D'Aprano pearwood.info> writes: >> >> A programmer had a problem, and thought Now he has "I know, I'll solve >> two it with threads!" problems. > > > Host: Last week the Royal Festival Hall saw the first performance of a new > logfile by one of the world's leading modern programmers, Steven > "Two threads" D'Aprano. Mr D'Aprano. > > D'Aprano: Hello. > > Host: May I just sidetrack for one moment. This -- what shall I call it -- > nickname of yours... > > D'Aprano: Ah yes. > > Host: "Two threads". How did you come by it? [...] > Host: I see, I see. And you're thinking of spawning this second thread to > write in! > > D'Aprano: No, no. Look. This thread business -- it doesn't really matter. > The threads aren't important. A few friends call me Two Threads and that's > all there is to it. I wish you'd ask me about the logfile. Everybody talks > about the threads. They've got it out of proportion -- I'm a programmer. > I'm going to get rid of the thread. I'm fed up with it! > > Host: Then you'll be Steven "No Threads" D'Aprano, eh? + Applause From john_ladasky at sbcglobal.net Thu Jan 17 02:26:20 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 16 Jan 2013 23:26:20 -0800 (PST) Subject: Thought of the day In-Reply-To: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8c6a2f88-08ba-48f2-aca8-daa3c8400593@googlegroups.com> On Sunday, January 13, 2013 8:16:29 PM UTC-8, Steven D'Aprano wrote: > A programmer had a problem, and thought Now he has "I know, I'll solve > two it with threads!" problems. Very nice! :^) This problem isn't exclusive to Python, however. Other multi-threaded applications can produce jumbled output like this, even when the threads (processes?) are running on independent CPU's. I use a very well-regarded application for molecular dynamics simulation: GROMACS, which I believe is written mostly in C (but there's even a little Fortran in it? And supposedly, this is critical to performance?). The GROMACS core program, mdrun, will grab as many CPUs as you allow it to use. The output of mdrun looks exactly like your little quip as each CPU reports back that it has started its piece of mdrun. From kalvinmanual at gmail.com Mon Jan 14 00:52:40 2013 From: kalvinmanual at gmail.com (kalvinmanual) Date: Sun, 13 Jan 2013 23:52:40 -0600 Subject: An Introduction to Stochastic Modeling 3rd Ed by Taylor, Karlin Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTIONS MANUAL TO A First Course in Differential Equations (7th ed.) Zill & Diferential Equations (5th ed.)Zill & Cullen SOLUTIONS MANUAL TO 2500 Solved Problems in Fluid Mechanics & Hydraulics Schaums by Evett, cheng Liu SOLUTIONS MANUAL TO A Course in Game Theory by Osborne, Rubinstein SOLUTIONS MANUAL TO A Course in Modern Mathematical Physics by Peter Szekeres SOLUTIONS MANUAL TO A Course in Ordinary Differential Equations by Swift, Wirkus SOLUTIONS MANUAL TO A First Course in Abstract Algebra (7th Ed., John B. Fraleigh) SOLUTIONS MANUAL TO A First Course in Differential Equations - The Classic Fifth Edition By Zill, Dennis G SOLUTIONS MANUAL TO A First Course in Differential Equations, 9th Ed by Dennis G. Zill SOLUTIONS MANUAL TO A First Course In Probability 7th Edition by Sheldon M. Ross SOLUTIONS MANUAL TO A First Course in Probability Theory, 6th edition, by S. Ross. SOLUTIONS MANUAL TO A First Course in String Theory, 2004, Barton Zwiebach SOLUTIONS MANUAL TO A First Course in the Finite Element Method, 4th Edition logan SOLUTIONS MANUAL TO A Practical Introduction to Data Structures and Algorithm Analysis 2Ed by Shaffer SOLUTIONS MANUAL TO A Quantum Approach to Condensed Matter Physics (Philip L. Taylor & Olle Heinonen) SOLUTIONS MANUAL TO A Short Course in General Relativity 2e by J. Foster and J. D. Nightingale SOLUTIONS MANUAL TO A Short Introduction to Quantum Information and Quantum Computation by Michel Le Bellac SOLUTIONS MANUAL TO A Transition to Advanced Mathematics 5th E by Smith, Eggen, Andre SOLUTIONS MANUAL TO Accounting Principles 8e by Kieso, Kimmel SOLUTIONS MANUAL TO Accounting principles 8th Ed by Weygandt SOLUTIONS MANUAL TO Accounting, 23 Ed by Carl S. Warren, James M. Reeve, Jonathan Duchac SOLUTIONS MANUAL TO Accounting,8th Ed by Horngren,Harrison, Oliver SOLUTIONS MANUAL TO Adaptive Control, 2nd. Ed., by Astrom, Wittenmark SOLUTIONS MANUAL TO Adaptive Filter Theory (4th Ed., Simon Haykin) SOLUTIONS MANUAL TO Advanced Accounting 10E international ED by Beams , Clement, Anthony, Lowensohn SOLUTIONS MANUAL TO Advanced accounting 9th Ed by Hoyle, Schaefer SOLUTIONS MANUAL TO Advanced Calculus Gerald B. Folland SOLUTIONS MANUAL TO Advanced Digital Design with the Verilog HDL by Michael D. Ciletti SOLUTIONS MANUAL TO Advanced Dynamics (Greenwood) SOLUTIONS MANUAL TO Advanced Engineering Electromagnetics by Constantine A. Balanis SOLUTIONS MANUAL TO Advanced Engineering Mathematics 3rd ed zill SOLUTIONS MANUAL TO Advanced Engineering Mathematics 8Ed Erwin Kreyszig SOLUTIONS MANUAL TO Advanced Engineering Mathematics by Erwin Kreyszig, 9th ed SOLUTIONS MANUAL TO Advanced Engineering Mathematics, 6th Edition by Peter V. O'Neil SOLUTIONS MANUAL TO Advanced Engineering Mathematics,2E, by Zill, Cullen SOLUTIONS MANUAL TO Advanced Engineering Thermodynamics, 3rd Edition by Adrian Bejan SOLUTIONS MANUAL TO Advanced Financial Accounting by Baker SOLUTIONS MANUAL TO Advanced Financial Accounting 5 Ed by Baker SOLUTIONS MANUAL TO Advanced Financial Accounting 8th Ed by Baker SOLUTIONS MANUAL TO Advanced Industrial Economics by Martin SOLUTIONS MANUAL TO Advanced Industrial Economics, 2nd ED Stephen Martin SOLUTIONS MANUAL TO Advanced Macroeconomics 2nd edition by David Romer SOLUTIONS MANUAL TO Advanced Macroeconomics, by David Romer SOLUTIONS MANUAL TO Advanced Mechanics of Materials 6th ed by Boresi, Schmidt SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 3rd Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 4th Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics, 3rd Ed., by G. James SOLUTIONS MANUAL TO Advanced Organic Chemistry Part A- Structure and Mechanisms 5th E by Carey, Sundberg SOLUTIONS MANUAL TO Aircraft Structures for Engineering Students (4th Ed., T.H.G. Megson) SOLUTIONS MANUAL TO Algebra & Trigonometry and Precalculus, 3rd Ed By Beecher, Penna, Bittinger SOLUTIONS MANUAL TO Algebra Baldor SOLUTIONS MANUAL TO Algebra-By Thomas W. Hungerford SOLUTIONS MANUAL TO Algorithm Design (Jon Kleinberg & ????va Tardos) SOLUTIONS MANUAL TO An Interactive Introduction to Mathematical Analysis 2nd E (Jonathan Lewin) SOLUTIONS MANUAL TO An Introduction To Analysis 4th Ed by William Wade SOLUTIONS MANUAL TO An Introduction to Database Systems (8th Ed., C.J. Date) SOLUTIONS MANUAL TO An Introduction to Economic Dynamics by Ronald Shone SOLUTIONS MANUAL TO An Introduction to Modern Astrophysics (2nd Ed., Bradley W. Carroll & Dale A. Ostlie) SOLUTIONS MANUAL TO An Introduction to Numerical Analysis By Endre S??li,David F. Mayers SOLUTIONS MANUAL TO An Introduction to Ordinary Differential Equations (James C. Robinson) SOLUTIONS MANUAL TO An Introduction to Signals and Systems by John Stuller SOLUTIONS MANUAL TO An Introduction to Stochastic Modeling 3rd Ed by Taylor, Karlin SOLUTIONS MANUAL TO An Introduction to the Finite Element Method (3rd Ed., J. N. Reddy) SOLUTIONS MANUAL TO An Introduction to Thermal Physics by Schroeder, Daniel V SOLUTIONS MANUAL TO An Introduction to Thermodynamics and Statistical Mechanics (2nd Ed, Keith Stowe) SOLUTIONS MANUAL TO An Introduction to Wavelets through Linear Algebra by Frazier SOLUTIONS MANUAL TO Analog Integrated Circuit Design, by Johns, Martin SOLUTIONS MANUAL TO Analysis and Design of Analog Integrated Circuits (4th Edition) by Gray , Lewis , Meyer SOLUTIONS MANUAL TO Analysis With an Introduction to Proof 4th E by Lay SOLUTIONS MANUAL TO Analytical Chemistry, Higson SOLUTIONS MANUAL TO Analytical Mechanics 7E by Grant R. Fowles, George L. Cassiday SOLUTIONS MANUAL TO Antenna Theory 2nd edition by Balanis SOLUTIONS MANUAL TO Antenna Theory and Design, 2nd Ed Vol.1 by Stutzman, Thiele SOLUTIONS MANUAL TO Antennas for All Applications (3rd Ed., John Kraus & Ronald Marhefka) SOLUTIONS MANUAL TO Applied Calculus by Hallett,Gleason, Lock, Flath SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 7 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 8 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Econometric Time Series, 2nd Edition by Enders SOLUTIONS MANUAL TO Applied Finite Element Analysis 2ed, by LJ SEGERLIND SOLUTIONS MANUAL TO Applied Fluid Mechanics (6th Ed., Mott) SOLUTIONS MANUAL TO Applied Linear Regression 3rd Ed by Sanford Weisberg SOLUTIONS MANUAL TO Applied Numerical Analysis, 7th Edition, by Gerald, Wheatley SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists 2nd E by Chapra SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists( Steven C. Chapra) SOLUTIONS MANUAL TO Applied Partial Differential Equations (4th Ed., Haberman) SOLUTIONS MANUAL TO Applied Partial Differential Equations by J. David Logan SOLUTIONS MANUAL TO Applied Probability Models with Optimization Applications By Sheldon M. Ross SOLUTIONS MANUAL TO Applied Quantum Mechanics ( A. F. J. Levi ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers ( 2nd Ed., Douglas Montgomery & George Runger ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers (3rd Ed., Douglas Montgomery & George Runger) SOLUTIONS MANUAL TO Applied Strength of Materials (4th Ed., Mott) SOLUTIONS MANUAL TO Applied Strength of Materials (5th Ed., Mott) SOLUTIONS MANUAL TO Applying Maths in the Chemical and Biomolecular Sciences, Beddard SOLUTIONS MANUAL TO Artificial Intelligence A Modern Approach 2e by Russell, Norvig SOLUTIONS MANUAL TO Artificial Neural Networks by B. Yegnanarayana and S. Ramesh SOLUTIONS MANUAL TO Assembly Language for Intel-Based Computers ( 3rd Edition ) by Kip R. Irvine SOLUTIONS MANUAL TO Auditing and Assurance Services- An Integrated Approach 12E by Arens SOLUTIONS MANUAL TO Auditing and Assurance Services, 12th edition, Alvin A Arens, Randal J Elder, Mark Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 13 ed by Arens, Elder, Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 2nd Ed by Louwers SOLUTIONS MANUAL TO Automatic Control Systems 9 Ed by Kuo, Golnaraghi SOLUTIONS MANUAL TO Automatic Control Systems, 8E, by Kuo, Golnaraghi SOLUTIONS MANUAL TO Basic Econometrics 4 ed by Damodar N. Gujarati SOLUTIONS MANUAL TO Basic Electrical Engineering By Nagrath, D P Kothari SOLUTIONS MANUAL TO Basic Electromagnetics with Applications by Nannapaneni Narayana Rao SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 7th Ed by David Irwin SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 8th Edition by J. David Irwin, R. Mark Nelms SOLUTIONS MANUAL TO Basic Heat and Mass Transfer by A. F. Mills SOLUTIONS MANUAL TO Basic Principles and Calculations in Chemical engineering 7th Edition by David M. Himmelblau, James B. Riggs SOLUTIONS MANUAL TO Basic Probability Theory by Robert B. Ash SOLUTIONS MANUAL TO Bayesian Core by Christian P. Robert and Jean-Michel Marin SOLUTIONS MANUAL TO Bioprocess Engineering Principles (Pauline M. Doran) SOLUTIONS MANUAL TO Business Statistics - Decision Making 7th E by David F. Groebner From rantingrickjohnson at gmail.com Mon Jan 14 01:46:44 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 13 Jan 2013 22:46:44 -0800 (PST) Subject: PyWart (Terminolgy): "Class" Message-ID: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> I have believed for a very long time that "class" was a poor choice of keyword to designate an "object definition". Firstly, the word /class/ does not transform smoothly into CS from English. NO English definition of "class" comes anywhere close to describing the "structured source code that defines an object". Or even generally as: "something that defines something else". You could try to hammer "classification" into the round hole, but you soon find out it's just a damn square peg! Secondly, "class" is confusing to newbies. How can someone understand the fundamentals of OOP (which defines objects and interfaces) when they are asked to write classes? (teacher:) "Okay /class/, we are going to create a new object by writing a class." (student:) HUH? Thirdly, once people *DO* understand that a "class" is simply an "object definition", they still go on to say idiotic things like: "Classes are objects"! It is obvious these people are a victim of their own terminology. ============================================================ Other possible terms include: ============================================================ "subclass": Since every "user defined object" *must* subclass /something/, using this word would infer such a relationship to the reader. HOWEVER, we would then need to differentiate the general usage of "subclass" (as in: an object that is an extension of another object) from a "user defined subclass" (as in: source code). In any event, "subclass" is a good contender. He's going to the 12th round for sure. "template": This term is very close, but still lacking a concrete relationship between source code (definition of object) and the resulting "thing" living in memory (object). I think this one is TKO in round 3. "object": This is my favorite word however it does suffer a "verbial" disconnection. What are we suggesting? A single word can be very ambiguous as to intent. However, if we couple the word "object" with the word "define" we then inject intent. "define object" on it's face is perfect! We know everything we need to know. 1) We are defining "something" and 2) that *THAT* "something" is an object! YAY! Now since "methods" and "functions" (PyWart on these terms coming soon!) require defining, the syntax will now be symmetrical (omitting for now that funcs/meths only use "def"!). However we could drop the "def" and use only "object" to save a few keystrokes and a lot of pyparsing. I am sure the main arguments against such a clear and logical syntax would be that we would confuse "object definitions" with "real live objects" in normal conversation. But i say that is non-sense because we NEED to be more specific when conversing anyway. Choosing a word like "class" just because we don't want to use two words to refer to "source code that defines an object" (in conversation) is ridiculous. This syntax will inject specificity into our communications and convey meaning more appropriately. Dear language designers: Stop propagating such foolish terminology! End the infection of "class" in all source code, docs, and daily conversation. Be more consistent and logical. Resist temptation to use poor terminology simply because other languages have done so before you. Grow a pair already! From rosuav at gmail.com Mon Jan 14 02:10:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Jan 2013 18:10:10 +1100 Subject: PyWart (Terminolgy): "Class" In-Reply-To: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: On Mon, Jan 14, 2013 at 5:46 PM, Rick Johnson wrote: > Dear language designers: Stop propagating such foolish terminology! End the infection of "class" in all source code, docs, and daily conversation. Be more consistent and logical. Resist temptation to use poor terminology simply because other languages have done so before you. Grow a pair already! Absolutely. We should learn from Lars Pensj? and start referring to "blueprint objects" and "clones". Or take the updated version and call them "programs" and "objects". I'm sure that'll make a huge amount more sense than using the terms that millions of programmers already understand. Alternatively, we could take the Humpty Dumpty approach and assign meanings to names arbitrarily. But wait till Saturday night when they come for their wages. ChrisA From rantingrickjohnson at gmail.com Mon Jan 14 02:32:55 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 13 Jan 2013 23:32:55 -0800 (PST) Subject: PyWart (Terminolgy): "Class" In-Reply-To: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: On Monday 1-14-2013 at 12:46 AM, Rick Johnson wrote: > [...] > "object": > > This is my favorite word however it does suffer a > "verbial" disconnection. What are we suggesting? A single > word can be very ambiguous as to intent. However, if we > couple the word "object" with the word "define" we then > inject intent. "define object" on it's face is perfect! I just had an epiphany of sorts. I really don't like using two words ("define object", or "def obj") and using one single keyword is ambiguous ("object" or "obj"). So the obvious solution is to combine the abbreviated words into one compound keyword that will save keystrokes, save parsing, and all-the-while maintain symmetry. That keyword is "defobj". Coupled with "defmeth" and "deffunc" we now have a symmetrical definition syntax! deffunc bar(): return defobj Foo(): defmeth __init__(self, blah): pass Extra Credit: Can anyone think of a better solution for defining objects without using keywords at all? Hmm... I'm getting a chubby just thinking about it! From rosuav at gmail.com Mon Jan 14 02:56:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Jan 2013 18:56:08 +1100 Subject: PyWart (Terminolgy): "Class" In-Reply-To: References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: On Mon, Jan 14, 2013 at 6:32 PM, Rick Johnson wrote: > I really don't like using two words ("define object", or "def obj") and using one single keyword is ambiguous ("object" or "obj"). So the obvious solution is to combine the abbreviated words into one compound keyword that will save keystrokes, save parsing, and all-the-while maintain symmetry. That keyword is "defobj". Coupled with "defmeth" and "deffunc" we now have a symmetrical definition syntax! > > deffunc bar(): > return > > defobj Foo(): > defmeth __init__(self, blah): > pass Awesome! Now, just one more step to make Python into the World's Most Awesome Language(tm): Replace those lengthy words with single symbols found in the Unicode set; compress everything down and enforce perfect Unicode handling. Also, demand that names be one character long, to enforce creativity by the Mark Rosewater principle. We will then have a truly wonderful language; everything will be so utterly readable. ChrisA From python.list at tim.thechases.com Mon Jan 14 09:30:56 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 14 Jan 2013 08:30:56 -0600 Subject: PyWart (Terminolgy): "Class" In-Reply-To: References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: <50F416A0.1080409@tim.thechases.com> On 01/14/13 01:56, Chris Angelico wrote: > On Mon, Jan 14, 2013 at 6:32 PM, Rick Johnson > wrote: >> I really don't like using two words ("define object", or "def obj") and using one single keyword is ambiguous ("object" or "obj"). So the obvious solution is to combine the abbreviated words into one compound keyword that will save keystrokes, save parsing, and all-the-while maintain symmetry. That keyword is "defobj". Coupled with "defmeth" and "deffunc" we now have a symmetrical definition syntax! >> >> deffunc bar(): >> return >> >> defobj Foo(): >> defmeth __init__(self, blah): >> pass > > Awesome! Now, just one more step to make Python into the World's Most > Awesome Language(tm): Replace those lengthy words with single symbols > found in the Unicode set; compress everything down and enforce perfect > Unicode handling. APL will rise to linguistic domination! ?maniacal laughter? -tkc From peter.milliken at gmail.com Mon Jan 14 14:43:34 2013 From: peter.milliken at gmail.com (Peter) Date: Mon, 14 Jan 2013 11:43:34 -0800 (PST) Subject: PyWart (Terminolgy): "Class" In-Reply-To: References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> Real mature lot of responses here guys - shows how much you have grown up. Reading this thread looked more like observing a bunch of 3rd grader - somebody offers an opinion and all you can do is ridicule it? Real mature - certainly gives Python a good name having followers like this... But then I guess I will cop flack for this rejoinder too... From rosuav at gmail.com Mon Jan 14 15:57:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jan 2013 07:57:58 +1100 Subject: PyWart (Terminolgy): "Class" In-Reply-To: <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> Message-ID: On Tue, Jan 15, 2013 at 6:43 AM, Peter wrote: > Real mature lot of responses here guys - shows how much you have grown up. > > Reading this thread looked more like observing a bunch of 3rd grader - somebody offers an opinion and all you can do is ridicule it? > > Real mature - certainly gives Python a good name having followers like this... > > But then I guess I will cop flack for this rejoinder too... Rick Johnson is a well-known troll. Opinion is divided as to the best way to handle the matter; one school follows the "Don't feed the trolls" motto and ignores him, the other trolls him right back. Rick has promised for a long time now that he's going to produce a Python 4000 (though I suspect Guido will produce Python 4.0 first, so it'll become Python 5000), but so far we haven't seen *any* code. His eternal complaints about Python are thus pure trolling and not well respected. I'm sorry the forum comes across sounding immature, but it's like a good game of Whack-A-Troll, or what Railbastard calls an "apparatusing". It's the community's way of maintaining itself. Expressing opinions won't get you flamed. Demanding that other people write a whole lot of code to suit your ridiculous notions of "warts" and doing none of the coding yourself, and keeping this up for years and years, WILL eventually get you flamed. And along the way, it gets you into a lot of people's killfiles. Oh, and Dennis? Mal. Bad. From the Latin. :) ChrisA From tim.delaney at aptare.com Mon Jan 14 16:04:53 2013 From: tim.delaney at aptare.com (Tim Delaney) Date: Tue, 15 Jan 2013 08:04:53 +1100 Subject: PyWart (Terminolgy): "Class" In-Reply-To: References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> Message-ID: On 15 January 2013 07:57, Chris Angelico wrote: > > Oh, and Dennis? Mal. Bad. From the Latin. :) > I was about to point out the same thing, using the same quote ;) Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.milliken at gmail.com Mon Jan 14 14:43:34 2013 From: peter.milliken at gmail.com (Peter) Date: Mon, 14 Jan 2013 11:43:34 -0800 (PST) Subject: PyWart (Terminolgy): "Class" In-Reply-To: References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> Real mature lot of responses here guys - shows how much you have grown up. Reading this thread looked more like observing a bunch of 3rd grader - somebody offers an opinion and all you can do is ridicule it? Real mature - certainly gives Python a good name having followers like this... But then I guess I will cop flack for this rejoinder too... From steve+comp.lang.python at pearwood.info Mon Jan 14 21:08:38 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2013 02:08:38 GMT Subject: PyWart (Terminolgy): "Class" References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> Message-ID: <50f4ba26$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Jan 2013 07:57:58 +1100, Chris Angelico wrote: > Rick Johnson is a well-known troll. I disagree that Rick is a troll. Trolling requires that the troll makes statements that he doesn't believe are true, simply in order to get a response. I do not believe that Rick is doing that. I think he simply has an imperfect, and poor, understanding of Python design principles, coupled with astonishingly high levels of arrogance and self-superiority. Pure Dunning-Kruger effect in action. http://rationalwiki.org/wiki/Dunning-Kruger_effect If I believed he was *dishonestly playing dumb to gain reactions*, then I would not bother to engage with him. But I truly believe that he is not beyond all hope. His posts on tkinter sometimes demonstrate actual knowledge. He is clearly articulate and knows more than one programming language -- although probably not *well*. But, I must admit, the sheer power of Rick's Reality Denial Field often defeats me. In frustration I too often killfile him so I don't have to read his screeds. So I certainly don't blame others who do the same. > Opinion is divided as to the best > way to handle the matter; one school follows the "Don't feed the trolls" > motto and ignores him, the other trolls him right back. I object to that characterisation. I am not dishonestly making provocative statements when I engage with Rick. -- Steven From darcy at druid.net Mon Jan 14 22:28:03 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 14 Jan 2013 22:28:03 -0500 Subject: PyWart (Terminolgy): "Class" In-Reply-To: <50f4ba26$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> <50f4ba26$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130114222803.78e87e42@dilbert> On 15 Jan 2013 02:08:38 GMT Steven D'Aprano wrote: > > Rick Johnson is a well-known troll. > > I disagree that Rick is a troll. Trolling requires that the troll Doesn't matter. He duck types as one. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From wuwei23 at gmail.com Tue Jan 15 03:44:17 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 15 Jan 2013 00:44:17 -0800 (PST) Subject: PyWart (Terminolgy): "Class" References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <9dc26878-d8b8-4f0d-95e1-c51313daafa2@googlegroups.com> <50f4ba26$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <65ce1b2c-3663-43bf-94b3-a67feb5a053f@l3g2000pbq.googlegroups.com> On Jan 15, 1:28?pm, "D'Arcy J.M. Cain" wrote: > Steven D'Aprano wrote: > > I disagree that Rick is a troll. Trolling requires that the troll > > Doesn't matter. ?He duck types as one. +1 Intent isn't magic. If Rick intends to contribute, he could actually contribute. From rhodri at wildebst.demon.co.uk Mon Jan 14 17:53:40 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 14 Jan 2013 22:53:40 -0000 Subject: PyWart (Terminolgy): "Class" References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: On Mon, 14 Jan 2013 19:43:34 -0000, Peter wrote: > Real mature lot of responses here guys - shows how much you have grown > up. > > Reading this thread looked more like observing a bunch of 3rd grader - > somebody offers an opinion and all you can do is ridicule it? Now read the rest of the thread. While it is true that Rick offers sufficiently many daft opinions that ridicule is actually likely to be the correct response, there have been detailed (and therefore ignored) responses pointing out his failure to understand both the English language and the last couple of decades of computer science. -- Rhodri James *-* Wildebeest Herder to the Masses From dan at tombstonezero.net Mon Jan 14 09:46:13 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 14 Jan 2013 14:46:13 GMT Subject: PyWart (Terminolgy): "Class" References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: On Mon, 14 Jan 2013 18:56:08 +1100, Chris Angelico wrote: > Awesome! Now, just one more step to make Python into the World's Most > Awesome Language(tm): Replace those lengthy words with single symbols > found in the Unicode set; compress everything down and enforce perfect > Unicode handling. Also, demand that names be one character long, to > enforce creativity by the Mark Rosewater principle. We will then have a > truly wonderful language; everything will be so utterly readable. I think we did that once. We called it APL. ;-) Dan From steve+comp.lang.python at pearwood.info Mon Jan 14 12:26:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2013 17:26:37 GMT Subject: PyWart (Terminolgy): "Class" References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> Message-ID: <50f43fcd$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Jan 2013 22:46:44 -0800, Rick Johnson wrote: > I have believed for a very long time that "class" was a poor choice of > keyword to designate an "object definition". > > Firstly, the word /class/ does not transform smoothly into CS from > English. NO English definition of "class" comes anywhere close to > describing the "structured source code that defines an object". Or even > generally as: "something that defines something else". Your knowledge of English has failed you. Here is the first definition from Webster's Dictionary (1913 edition): Class \Class\ (kl[.a]s), n. [F. classe, fr. L. classis class, collection, fleet; akin to Gr. klh^sis a calling, kalei^n to call, E. claim, haul.] 1. A group of individuals ranked together as possessing common characteristics; as, the different classes of society; the educated class; the lower classes. [1913 Webster] And definitions 3 and 4: 3. A comprehensive division of animate or inanimate objects, grouped together on account of their common characteristics, in any classification in natural science, and subdivided into orders, families, tribes, genera, etc. [1913 Webster] 4. A set; a kind or description, species or variety. [1913 Webster] "Class" is an excellent ordinary English word to describe what computer science calls a "class". > Thirdly, once people *DO* understand that a "class" is simply an "object > definition", they still go on to say idiotic things like: "Classes are > objects"! Your knowledge of Python has failed you. Classes are objects in Python, although not in all other languages. Classes are created at runtime, not compile time. They have an id, like all instances. They have a __class__ attribute, like all instances. They have a type, like all instances. They *are* instances. py> class Spam(object): ... pass ... py> id(Spam) 168149924 py> isinstance(Spam, type) True > It is obvious these people are a victim of their own terminology. You're very funny. > "subclass": > Since every "user defined object" *must* subclass /something/, Only in Python 3. In Python 2, some classes are not subclasses. py> class OldStyleClass: ... pass ... py> OldStyleClass.__bases__ () > "template": > This term is very close, but still lacking a concrete relationship > between source code (definition of object) and the resulting "thing" > living in memory (object). I think this one is TKO in round 3. A template is certainly not correct for class-based OOP languages like Python, since it implies *copying*. It might be more appropriate for prototype-cased OOP languages like Javascript. [...] > Now since "methods" and "functions" (PyWart on these terms coming soon!) Oh I can barely contain my excitement. -- Steven From python.list at tim.thechases.com Mon Jan 14 13:00:13 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 14 Jan 2013 12:00:13 -0600 Subject: PyWart (Terminolgy): "Class" In-Reply-To: <50f43fcd$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <50f43fcd$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F447AD.8010505@tim.thechases.com> On 01/14/13 11:26, Steven D'Aprano wrote: > Your knowledge of English has failed you. Here is the first definition > from Webster's Dictionary (1913 edition): > > > Class \Class\ (kl[.a]s), n. [F. classe, fr. L. classis class, > collection, fleet; akin to Gr. klh^sis a calling, kalei^n to > call, E. claim, haul.] > 1. A group of individuals ranked together as possessing > common characteristics; as, the different classes of > society; the educated class; the lower classes. > [1913 Webster] Clearly Python should use a keyword like "Kingdom" or "Phylum" instead. I guess "Kingdom" should be reserved for metaclasses (or would they be metaphylums? or metaphyla?) kingdom Baz: pass phylum Foo: __metaphylum__ = Baz That is SO much clearer ;-) -tkc From dan at tombstonezero.net Mon Jan 14 19:51:13 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Tue, 15 Jan 2013 00:51:13 GMT Subject: PyWart (Terminolgy): "Class" References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <50f43fcd$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5K1Js.80533$LS5.49538@newsfe10.iad> On Mon, 14 Jan 2013 12:00:13 -0600, Tim Chase wrote: > Clearly Python should use a keyword like "Kingdom" or "Phylum" instead. > I guess "Kingdom" should be reserved for metaclasses (or would they be > metaphylums? or metaphyla?) Metaphyla, of course. > kingdom Baz: > pass > > phylum Foo: > __metaphylum__ = Baz But it's obvious that kingdoms are metaphyla, and it would be silly for one phylum to inherit from another (let alone for a phylum to inherit from a class), so couldn't we just claim that Foo inherits from Baz and be done with it: phylum Foo(Baz): pass > That is SO much clearer ;-) For some definitions of "SO" and "much," yes. ;-) Dan From rantingrickjohnson at gmail.com Tue Jan 15 01:54:10 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 14 Jan 2013 22:54:10 -0800 (PST) Subject: PyWart (Terminolgy): "Class" In-Reply-To: <50f43fcd$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <50f43fcd$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2f6db7bc-44d6-444f-91dc-1c67d25bca24@googlegroups.com> On Monday, January 14, 2013 11:26:37 AM UTC-6, Steven D'Aprano wrote: > On Sun, 13 Jan 2013 22:46:44 -0800, Rick Johnson wrote: > [...] > Your knowledge of English has failed you. Here is the first definition > from Webster's Dictionary (1913 edition): > > Class [...] > 1. A group of individuals ranked together as possessing > common characteristics; as, the different classes of > society; the educated class; the lower classes. > [1913 Webster] This is a poor definition for an object. I would rather apply this definition to a collection of objects than to the definition of a single object. Remember, we want to choose a word that is "self documenting". > And definitions 3 and 4: > > 3. A comprehensive division of animate or inanimate objects, > grouped together on account of their common > characteristics, in any classification in natural science, > and subdivided into orders, families, tribes, genera, etc. > [1913 Webster] > > 4. A set; a kind or description, species or variety. > [1913 Webster] But again, neither of these definitions describe what an object is, in fact, "class" creates a cognitive disconnect between "object definitions" and "objects". "Class" is only concerned with grouping, characteristics, or comparisons. And let's not forget the obvious. When we are defining "objects" we are wielding a paradigm called "Object Oriented Programming". Only a fool would choose something besides "object" as a keyword. > "Class" is an excellent ordinary English word to describe what computer > science calls a "class". Well if that statement is not a fine example of circular reasoning, i don't what is. o_O > > Thirdly, once people *DO* understand that a "class" is simply an "object > > definition", they still go on to say idiotic things like: "Classes are > > objects"! > > Your knowledge of Python has failed you. > > Classes are objects in Python, although not in all other languages. Python "classes" are OBJECT DEFINITIONS, not OBJECTS! > Classes are created at runtime, not compile time. No, classes DO NOT exist at runtime OR compile time! Classes are only *structured text* (or code if you prefer) that instruct Python to build *real* MEMORY OBJECTS for us. The "magic" that you are witnessing is Python, not classes. Would you argue as intently that the fictional characters of LOTR are real? They could be considered real in your imagination, but without a mind to interpret these characters they will be nothing more than text on a page. Same goes for classes. > They [classes] have an id, like > all instances. They have a __class__ attribute, like all instances. They > have a type, like all instances. They *are* instances. Replace "class" with object and you will be correct. > py> class Spam(object): > ... pass > ... > py> id(Spam) > 168149924 > py> isinstance(Spam, type) > True Do you understand that your object definition named "Spam" is transformed into a memory object by python and that the id() function and the isinstance() function are operating on a memory object and not your structured text? Stop fooling around Steven, really. > > "subclass": > > Since every "user defined object" *must* subclass /something/, > > Only in Python 3. In Python 2, some classes are not subclasses. > > py> class OldStyleClass: > ... pass > ... > py> OldStyleClass.__bases__ > () Ignoring the fact that this comment has nothing to do with the main argument and is in fact an attempt to distract the audience from your downward spiral of circular reasoning... "OldStyleClasses are a direct result of GvR and his anti OOP (anti functional also) programming mentality and lend no weight to your argument. Gudio was wrong to allow classes to be defined without deriving from /something/. He wisely removed old style classes in Python3000. They don't exist in Python's future. Let them rest in peace. > > "template": > > This term is very close, but still lacking a concrete relationship > > between source code (definition of object) and the resulting "thing" > > living in memory (object). I think this one is TKO in round 3. > > A template is certainly not correct for class-based OOP languages like > Python, since it implies *copying*. It might be more appropriate for > prototype-cased OOP languages like Javascript. Agreed. I never really liked the term anyway, but i needed one more choice to round out my list of candidates. Think of "template" as the ugly friend the average girl brings to the bar to make herself seem prettier by comparison. *wink* From steve+comp.lang.python at pearwood.info Tue Jan 15 04:01:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2013 09:01:41 GMT Subject: PyWart (Terminolgy): "Class" References: <5171d66e-580e-4bb3-bb8d-7e3f1de70ec4@googlegroups.com> <50f43fcd$0$30003$c3e8da3$5496439d@news.astraweb.com> <2f6db7bc-44d6-444f-91dc-1c67d25bca24@googlegroups.com> Message-ID: <50f51af4$0$11112$c3e8da3@news.astraweb.com> On Mon, 14 Jan 2013 22:54:10 -0800, Rick Johnson wrote: > No, classes DO NOT exist at runtime OR compile time! Classes are only > *structured text* (or code if you prefer) that instruct Python to build > *real* MEMORY OBJECTS for us. The "magic" that you are witnessing is > Python, not classes. Ultimately, everything in Python is "structured text", because the only way to create a Python program is to write source code. Everything you say is equally true for every other data type in Python. Floats. Strings. Ints. Lists. Tuples. Dicts. *Everything*. They are only "structured text" when they appear in source code, or on the command line, or in the interactive interpreter, just like classes, and Python then constructs an object in memory to represent that data structure. Just like classes. So if you wish to deny that classes are objects, you also have to deny that lists and strings and ints and floats are objects too. In Python, either nothing is an object, or everything is an object. There is no middle ground. You cannot treat classes differently from lists, because Python treats them the same: source code of a list literal => list object in memory source code of a float literal => float object in memory source code of a class definition => class object in memory >> py> class Spam(object): >> ... pass >> ... >> py> id(Spam) >> 168149924 >> py> isinstance(Spam, type) >> True > > Do you understand that your object definition named "Spam" is > transformed into a memory object by python and that the id() function > and the isinstance() function are operating on a memory object and not > your structured text? You don't need a class statement ("object definition") to create a class object. Because classes are instances of the metaclass, there is a default metaclass (called "type") that does the work of instantiating the metaclass: py> name = "Spam" py> bases = (object,) py> dict_ = {} py> thingy = type(name, bases, dict_) py> isinstance(thingy, type) True py> thingy Classes are instances of type. That is reality in Python. Classes are objects just like ints and strings and lists. This is a fundamental design choice of Python. Deal with it. -- Steven From antoon.pardon at rece.vub.ac.be Mon Jan 14 06:03:41 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 14 Jan 2013 12:03:41 +0100 Subject: Making a logging handler that produces context. Message-ID: <50F3E60D.2000503@rece.vub.ac.be> I have some in house code for which I am considering replacing the logging code with something that uses the logging module. The code is typically used as a cron job with everything higher than info logged to a file and everything higher than warning logged to stderr. However there is one thing the in-house log code does, that seems difficult to do with the logging module, provide some context. The in-house handlers give the possibilty to specify the number of lines of context the hander can provide. So the following code: Logger(fn = "file.log", level = info) Logger(fl = stderr, level = warning, context = 2) log(INFO, "line 1") log(INFO, "line 2") log(INFO, "line 3") log(INFO, "line 4") log(WARNING, "line 5") Will sent something like the following lines to stderr: INFO: line 3 INFO: line 4 WARNING: line 5 I tried the code below, but that produced the same as the ordinary StreamHandler. class ContextStreamHandler (StreamHandler): def __init__(self, stream=None, context = 5): self.recqueue = deque([], context) StreamHandler.__init__(self, stream) #__init__ def handle(self, record): print("CONTEXT HANDLER") rv = self.filter(record) if rv: self.acquire() try: for rec in self.recqueue: self.emit(rec) self.recqueue.clear() self.emit(record) finally: self.release else: self.recqueue.append(record) return rv #handle #ContextStreamHandler From __peter__ at web.de Mon Jan 14 07:38:12 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 14 Jan 2013 13:38:12 +0100 Subject: Making a logging handler that produces context. References: <50F3E60D.2000503@rece.vub.ac.be> Message-ID: Antoon Pardon wrote: > I have some in house code for which I am considering replacing the > logging code with something that uses the logging module. > However there is one thing the in-house log code does, that seems > difficult to do with the logging module, provide some context. The > in-house handlers give the possibilty to specify the number of lines of > context the hander can provide. > So the following code: > Logger(fl = stderr, level = warning, context = 2) > > log(INFO, "line 1") > log(INFO, "line 2") > log(INFO, "line 3") > log(INFO, "line 4") > log(WARNING, "line 5") > > Will sent something like the following lines to stderr: > > INFO: line 3 > INFO: line 4 > WARNING: line 5 > > I tried the code below, but that produced the same > as the ordinary StreamHandler. > > class ContextStreamHandler (StreamHandler): > > def __init__(self, stream=None, context = 5): > self.recqueue = deque([], context) > StreamHandler.__init__(self, stream) > #__init__ > > def handle(self, record): > print("CONTEXT HANDLER") > rv = self.filter(record) > if rv: > self.acquire() > try: > for rec in self.recqueue: > self.emit(rec) > self.recqueue.clear() > self.emit(record) > finally: > self.release > else: > self.recqueue.append(record) > return rv > #handle > #ContextStreamHandler It turns out the logic of the above is correct. The problem is that the handler has to see the INFO-level records while the filter() method has to reject them. The following configuration seems to achieve that: import logging from collections import deque class ContextStreamHandler(logging.StreamHandler): def __init__(self, stream=None, context=5): self.record_queue = deque([], context + 1) logging.StreamHandler.__init__(self, stream) def handle(self, record): rv = self.filter(record) self.record_queue.append(record) if rv: self.acquire() try: for record in self.record_queue: self.emit(record) self.record_queue.clear() finally: self.release() return rv class LevelFilter(logging.Filter): def __init__(self, level, name=""): logging.Filter.__init__(self, name) self._filter_level = level def filter(self, record): return record.levelno >= self._filter_level if __name__ == "__main__": root = logging.getLogger() root.setLevel(logging.INFO) handler = ContextStreamHandler(context=2) handler.addFilter(LevelFilter(logging.WARN)) root.addHandler(handler) for i in range(20): if i % 5: root.info("message #%d" % i) else: root.warn("MESSAGE #%d" % i) From antoon.pardon at rece.vub.ac.be Mon Jan 14 09:26:03 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 14 Jan 2013 15:26:03 +0100 Subject: Making a logging handler that produces context. In-Reply-To: References: <50F3E60D.2000503@rece.vub.ac.be> Message-ID: <50F4157B.3040806@rece.vub.ac.be> Op 14-01-13 13:38, Peter Otten schreef: > It turns out the logic of the above is correct. The problem is that the > handler has to see the INFO-level records while the filter() method has to > reject them. The following configuration seems to achieve that: I see, I thought trowing away logrecords of too low a level was also done by the filter method. But if I now understand correctly logrecords of too low a level are thrown away earlier and don't even reach the handle method. Thanks for the insight. -- Antoon Pardon From zoom at yahoo.com Mon Jan 14 09:54:27 2013 From: zoom at yahoo.com (zoom) Date: Mon, 14 Jan 2013 15:54:27 +0100 Subject: Python modules Message-ID: Is there any "rules" regarding importing python modules within your own module? I mean, how does this affects the performance of the program? For example, I have my own module named "sound". At the top of the file sound.py I have: import scipy In the code I have: import scipy, sound, etc Now I have two instances of every function within scipy, e.g. scipy.r_[a] = sound.scipy.r_[a] Module importing is quite fast, but not instant. It takes some time, but it happens only once. My concern is whether I hold all these multiple instances of same function in the memory, and does this reduce the performance of my program. In short, when creating a module, is it worthwhile to be careful and import only necessary functions, nothing more? From rosuav at gmail.com Mon Jan 14 10:04:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jan 2013 02:04:00 +1100 Subject: Python modules In-Reply-To: References: Message-ID: On Tue, Jan 15, 2013 at 1:54 AM, zoom wrote: > Is there any "rules" regarding importing python modules within your own > module? I mean, how does this affects the performance of the program? > > In short, when creating a module, is it worthwhile to be careful and import > only necessary functions, nothing more? Nope. When you import a module, a record of it is kept in sys.modules, so the next time you import it, it's just picking up the same module object. > scipy.r_[a] = sound.scipy.r_[a] They'll actually be the same thing, which you can test with the 'is' operator. The performance cost of reimporting a module is very low; in fact, trying to avoid it by adorning all your usage with an extra dot-level will probably cost you a lot more, since there'll be an extra lookup every time. Have at it! :) ChrisA From dan at tombstonezero.net Mon Jan 14 10:01:09 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 14 Jan 2013 15:01:09 GMT Subject: Python modules References: Message-ID: On Mon, 14 Jan 2013 15:54:27 +0100, zoom wrote: > Is there any "rules" regarding importing python modules within your own > module? I mean, how does this affects the performance of the program? "Even the initializers are optimized!" -- Mel, the real programmer Unless you've profiled it, and the extra memory taken up by unused functions or modules is measurable and near the top of the list of performance issues, I wouldn't worry about it. > Now I have two instances of every function within scipy, e.g. > scipy.r_[a] = sound.scipy.r_[a] No: now you have two names for every function within scipy. The functions themselves are not duplicated. Dan From zoom at yahoo.com Mon Jan 14 10:03:12 2013 From: zoom at yahoo.com (zoom) Date: Mon, 14 Jan 2013 16:03:12 +0100 Subject: Python modules In-Reply-To: References: Message-ID: On 01/14/2013 04:01 PM, Dan Sommers wrote: > On Mon, 14 Jan 2013 15:54:27 +0100, zoom wrote: > >> Is there any "rules" regarding importing python modules within your own >> module? I mean, how does this affects the performance of the program? > > "Even the initializers are optimized!" -- Mel, the real programmer > Great! > Unless you've profiled it, and the extra memory taken up by unused > functions or modules is measurable and near the top of the list of > performance issues, I wouldn't worry about it. > >> Now I have two instances of every function within scipy, e.g. >> scipy.r_[a] = sound.scipy.r_[a] > > No: now you have two names for every function within scipy. The > functions themselves are not duplicated. > > Dan Now I love Python even more... From rantingrickjohnson at gmail.com Mon Jan 14 11:27:56 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 14 Jan 2013 08:27:56 -0800 (PST) Subject: Python modules In-Reply-To: References: Message-ID: <6945d53f-3e70-4454-96fd-e2a1c19b0b97@googlegroups.com> On Monday, January 14, 2013 9:04:00 AM UTC-6, Chris Angelico wrote: > The performance cost of reimporting a module is very low; > in fact, trying to avoid it by adorning all your usage > with an extra dot-level will probably cost you a lot more, > since there'll be an extra lookup every time. Most people "adorn" a module with an extra dot to: 1. create a shorter name (f.e.[1] tk instead of Tkinter) 2. keep their namespace clean. Only a fool would do "from Tkinter import *"[2]. A wise programmer, who needed to access many members of Tkinter, would do instead "import Tkinter as tk", and then prepend all members with "tk.". [1] Abbr: (F)or (E)xample. (I feel an EnglishWart brewing on this subject!) [2] With the exception of command line testing, learning, or playing. From rantingrickjohnson at gmail.com Mon Jan 14 11:27:56 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 14 Jan 2013 08:27:56 -0800 (PST) Subject: Python modules In-Reply-To: References: Message-ID: <6945d53f-3e70-4454-96fd-e2a1c19b0b97@googlegroups.com> On Monday, January 14, 2013 9:04:00 AM UTC-6, Chris Angelico wrote: > The performance cost of reimporting a module is very low; > in fact, trying to avoid it by adorning all your usage > with an extra dot-level will probably cost you a lot more, > since there'll be an extra lookup every time. Most people "adorn" a module with an extra dot to: 1. create a shorter name (f.e.[1] tk instead of Tkinter) 2. keep their namespace clean. Only a fool would do "from Tkinter import *"[2]. A wise programmer, who needed to access many members of Tkinter, would do instead "import Tkinter as tk", and then prepend all members with "tk.". [1] Abbr: (F)or (E)xample. (I feel an EnglishWart brewing on this subject!) [2] With the exception of command line testing, learning, or playing. From invalid at invalid.invalid Mon Jan 14 14:48:05 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 14 Jan 2013 19:48:05 +0000 (UTC) Subject: Python modules References: Message-ID: On 2013-01-14, Rick Johnson wrote: > Only a fool would do "from Tkinter import *"[2]. > [2] With the exception of command line testing, learning, or playing. I don't think those should be excepted. Habits acquired during learning/playing will be continue when doing real work, and "Example" code provided as part of lessons/tutorials _will_ get copied into real programs. IMO, tutorials that take shortcuts like "from Tkinter import *" are A Bad Thing(tm). When teaching somebody how to do something, don't show them the wrong way do to something and then after they've learned that add "by the way, don't actually do it that way". -- Grant Edwards grant.b.edwards Yow! Your CHEEKS sit like at twin NECTARINES above gmail.com a MOUTH that knows no BOUNDS -- From mmanns at gmx.net Sun Jan 13 17:12:36 2013 From: mmanns at gmx.net (Martin Manns) Date: Sun, 13 Jan 2013 23:12:36 +0100 Subject: [ANN] pyspread 0.2.3 Message-ID: ============== pyspread 0.2.3 ============== Pyspread 0.2.3 is released. The new version improves GPG integration. About pyspread ============== Pyspread is a non-traditional spreadsheet application that is based on and written in the programming language Python. The goal of pyspread is to be the most pythonic spreadsheet application. Pyspread is designed for Linux and other GTK platforms. Pyspread is free software. It is released under the GPL v3. Project website: http://manns.github.com/pyspread/ What is new in 0.2.3 ==================== * GUI front-end for matplotlib charts * Image display in cells * Localization in German, Dutch, Danish and Ukrainian (partly finished) * Dependency to PyMe, rpy and gmpy removed for easier packaging * New dependencies matplotlib, python-gnupg * New example files * Various bug fixes Enjoy Martin From servekarimi at gmail.com Mon Jan 14 14:48:08 2013 From: servekarimi at gmail.com (servekarimi at gmail.com) Date: Mon, 14 Jan 2013 11:48:08 -0800 (PST) Subject: Finding the variables (read or write) Message-ID: <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> I'd like to develop a small debugging tool for python programs.In Dynamic Slicing How can I find the variables that are accessed in a statement? And find the type of access (read or write) for those variables (in Python). ### Write: A statement can change the program state. ### Read : A statement can read the program state . **For example in these 4 lines we have: (1) x = a+b => write{x} & read{a,b} (2) y=6 => write{y} & read{} (3) while(n>1) => write{} & read{n} (4) n=n-1 => write{n} & read{n} @@If I use dis(disassembler) How can I get output of dis in python as dictionary? Thanks From rosuav at gmail.com Mon Jan 14 16:28:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jan 2013 08:28:28 +1100 Subject: Finding the variables (read or write) In-Reply-To: <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> References: <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> Message-ID: On Tue, Jan 15, 2013 at 6:48 AM, wrote: > I'd like to develop a small debugging tool for python programs.In Dynamic Slicing How can I find the variables that are accessed in a statement? And find the type of access (read or write) for those variables (in Python). > ### Write: A statement can change the program state. > ### Read : A statement can read the program state . > **For example in these 4 lines we have: > (1) x = a+b => write{x} & read{a,b} > (2) y=6 => write{y} & read{} > (3) while(n>1) => write{} & read{n} > (4) n=n-1 => write{n} & read{n} An interesting question. What's your definition of "variable"? For instance, what is written and what is read by this statement: self.lst[2] += 4 Is "self.lst" considered a variable? (In C++ etc, this would be a member function manipulating an instance variable.) Or is "self" the variable? And in either case, was it written to? What about: self.lst.append(self.lst[-1]+self.lst[-2]) (which might collect Fibonacci numbers)? ChrisA From ckaynor at zindagigames.com Mon Jan 14 16:37:33 2013 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 14 Jan 2013 13:37:33 -0800 Subject: Finding the variables (read or write) In-Reply-To: References: <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> Message-ID: On Mon, Jan 14, 2013 at 1:28 PM, Chris Angelico wrote: > On Tue, Jan 15, 2013 at 6:48 AM, wrote: > > I'd like to develop a small debugging tool for python programs.In > Dynamic Slicing How can I find the variables that are accessed in a > statement? And find the type of access (read or write) for those variables > (in Python). > > ### Write: A statement can change the program state. > > ### Read : A statement can read the program state . > > **For example in these 4 lines we have: > > (1) x = a+b => write{x} & read{a,b} > > (2) y=6 => write{y} & read{} > > (3) while(n>1) => write{} & read{n} > > (4) n=n-1 => write{n} & read{n} > > An interesting question. What's your definition of "variable"? For > instance, what is written and what is read by this statement: > > self.lst[2] += 4 > > Is "self.lst" considered a variable? (In C++ etc, this would be a > member function manipulating an instance variable.) Or is "self" the > variable? And in either case, was it written to? What about: > > self.lst.append(self.lst[-1]+self.lst[-2]) > > (which might collect Fibonacci numbers)? > And those aren't even covering the case that a, normally non-mutating, method actually mutates. Consider the following class (untested): class Test(object): def __init__(self, value): self.value = value self.adds = 0 def __add__(self, other): self.adds += 1 other.adds += 1 return Test(self.value + other.value) With that class, x = a + b would mutate x, a, and b, presuming a and b are instances of Test. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 14 16:46:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jan 2013 08:46:39 +1100 Subject: Finding the variables (read or write) In-Reply-To: References: <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> Message-ID: On Tue, Jan 15, 2013 at 8:37 AM, Chris Kaynor wrote: > And those aren't even covering the case that a, normally non-mutating, > method actually mutates. If it's static analysis, I'd quietly ignore those sorts of cases. Anything can be changed any time, including stuff that's completely unrelated to what you're working on. Now, if the OP just wants to know what names get referenced (without distinguishing reads from writes), that's quite possible, and in fact easy - if you're willing to analyze a whole function instead of a single statement. >>> def foo(): x=y+1 >>> foo.__code__.co_varnames ('x',) >>> foo.__code__.co_names ('y',) The first one is the ones that get assigned to (not quite the same as "written to"), the second is ones that don't. Well, more or less. In simple cases. ChrisA From tjreedy at udel.edu Mon Jan 14 16:42:42 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 14 Jan 2013 16:42:42 -0500 Subject: Finding the variables (read or write) In-Reply-To: References: <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> Message-ID: On 1/14/2013 4:28 PM, Chris Angelico wrote: > On Tue, Jan 15, 2013 at 6:48 AM, wrote: >> I'd like to develop a small debugging tool for python programs.In Dynamic Slicing How can I find the variables that are accessed in a statement? And find the type of access (read or write) for those variables (in Python). >> ### Write: A statement can change the program state. >> ### Read : A statement can read the program state . >> **For example in these 4 lines we have: >> (1) x = a+b => write{x} & read{a,b} >> (2) y=6 => write{y} & read{} >> (3) while(n>1) => write{} & read{n} >> (4) n=n-1 => write{n} & read{n} I would try compiling the source code to an ast (abstract syntax tree). See the ast module for how to do that and how to 'read' the resulting tree. > An interesting question. What's your definition of "variable"? For > instance, what is written and what is read by this statement: > > self.lst[2] += 4 > > Is "self.lst" considered a variable? (In C++ etc, this would be a > member function manipulating an instance variable.) Or is "self" the > variable? And in either case, was it written to? 'self' is read, 'lst' is written to. What about: > > self.lst.append(self.lst[-1]+self.lst[-2]) > > (which might collect Fibonacci numbers)? 'self' read, 'lst' read and written. Knowing that for non-builtins is another matter ;-). -- Terry Jan Reedy From menkomigen6 at gmail.com Mon Jan 14 15:29:17 2013 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Mon, 14 Jan 2013 12:29:17 -0800 (PST) Subject: unit selection problem Message-ID: Unit selection doesn't work properly. Pygames event.pos returns a tuple of the coords within the current window, so it's not possible to select units outside of the top left corner. from pygamehelper import * from pygame import * from pygame.locals import * from vec2d import * from math import e, pi, cos, sin, sqrt from random import uniform from mapeditor import * from entity import * from spritesheet import * # version alpha 0.1 # map drawing seems functional, albeit crude class Starter(PygameHelper): def __init__(self): self.w, self.h = 1600, 900 PygameHelper.__init__(self, size=(self.w, self.h), fill=((255,255,255))) self.map_layout = map_constructor("map.png", 2400) self.object_counter = len(self.map_layout.all_map_objects) map_textures = get_sprites( (48, 48) ,"spritesheet.png" , (0, 0) ) self.collision_map = [] # defines all map objects in readable format self.map_sprite_list = { 'floor_red' : map_textures.sprites[0], 'floor_dark' : map_textures.sprites[2], 'wall' : map_textures.sprites[1], 'proto_unit' : map_textures.sprites[3], } # map scrolling modifiers self.mod_w = 0 self.mod_h = 0 # introduce agents self.agent_list = [] self.selected = [] # TODO: make surface size relative to map size self.mapSurf = pygame.Surface( (3600, 3600) ) # draw the floor once for e in self.map_layout.fixed_list: if e.type == 1: self.mapSurf.blit(self.map_sprite_list['floor_red'], e.rect) self.mapSurfRect = self.mapSurf.get_rect() # create a collision map based on wall positions for e in self.map_layout.all_map_objects: if e.type == 2: wall_object = wall() wall_object.pos = vec2d((e.x_position + 24), (e.y_position + 30)) wall_object.target = wall_object.pos self.collision_map.append(wall_object) for e in self.map_layout.all_map_objects: # check map for agents if e.type == 3: a = agent() a.pos = vec2d(e.x_position, e.y_position) print a.pos a.target = a.pos self.agent_list.append(a) def update(self): # map scrolling self.mapSurfRect.center = (((self.w / 2) + self.mod_w), (((self.h / 2)) + self.mod_h)) # update agent position for a in self.agent_list: dir = a.target - a.pos if dir.length >= 3: dir.length = 3 a.pos = a.pos + dir # update the walls, so they are drawn above the floor for e in self.map_layout.fixed_list: if e.type == 2: self.mapSurf.blit(self.map_sprite_list['wall'], e.rect) # add agents to the mapSurf for a in self.agent_list: self.mapSurf.blit(self.map_sprite_list['proto_unit'], a.pos) def keyUp(self, key): pass def keyDown(self, key): # move the mapSurf object # TODO: implement continuous camera movement while key is pressed if key == K_RIGHT: self.mod_w -= 100 if key == K_LEFT: self.mod_w += 100 if key == K_UP: self.mod_h += 100 if key == K_DOWN: self.mod_h -= 100 def mouseUp(self, button, pos): # select agent if button==1: print pos for a in self.agent_list: if a.pos.get_distance(vec2d(pos)) < 24: self.selected.append(a) print 'selected' # right click to move selected agents if button==3: for a in self.selected: a.target = vec2d(pos) def mouseMotion(self, buttons, pos, rel): pass def draw(self): #self.screen.fill((255,255,255)) self.screen.fill((0,0,0)) self.screen.blit(self.mapSurf, self.mapSurfRect) #for a in self.selected: # pygame.draw.circle(self.mapSurf, (50,200,50), a.pos.inttup(), 18, 1) # represent selected units s = Starter() s.mainLoop(100) From ulrich.eckhardt at dominolaser.com Tue Jan 15 03:08:30 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 15 Jan 2013 09:08:30 +0100 Subject: unit selection problem In-Reply-To: References: Message-ID: Am 14.01.2013 21:29, schrieb Paul Pittlerson: > map_textures = get_sprites( (48, 48) ,"spritesheet.png" , (0, 0) ) You forgot to include spritesheet.png in your message. Seriously, condense your code down to a minimal example. This might help you finding the problem yourself, otherwise post the complete compilable example here. Uli From joepvandelft at xs4all.nl Mon Jan 14 18:50:01 2013 From: joepvandelft at xs4all.nl (Joep van Delft) Date: Tue, 15 Jan 2013 00:50:01 +0100 Subject: strace of python shows nonsense Message-ID: <20130115005001.6a7b0239@xs4all.nl> Hi there, I am puzzled at how I borked my installation. Python loads slow on my machine, and I decided to use strace and /usr/bin/time to see what is actually happening. # sync && echo 3 > /proc/sys/vm/drop_caches $ /usr/bin/time python2 -c "" 0.19user 0.04system 0:01.22elapsed 19%CPU (0avgtext+0avgdata 4200maxresident)k 7312inputs+0outputs (4major+1145minor)pagefaults 0swaps And when all is in memory: $ /usr/bin/time python2 -c "" 0.19user 0.01system 0:00.21elapsed 98%CPU (0avgtext+0avgdata 4216maxresident)k 0inputs+0outputs (0major+1153minor)pagefaults 0swaps $ /usr/bin/time python2 -c "import argparse" 0.36user 0.02system 0:00.39elapsed 98%CPU (0avgtext+0avgdata 5752maxresident)k 0inputs+0outputs (0major+1699minor)pagefaults 0swaps .2 and .4 seconds to not even get started when all disk I/O is cached. So what is happening here? $ strace -c python2 -c "" % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 93.26 0.001910 8 230 168 open 3.66 0.000075 9 8 mprotect 3.08 0.000063 1 97 fstat64 0.00 0.000000 0 172 read 0.00 0.000000 0 63 close <...> $ strace -c python2 -c "import argparse" % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 51.89 0.003732 13 290 read 47.29 0.003401 18 192 155 stat64 0.82 0.000059 0 129 mmap2 0.00 0.000000 0 549 443 open 0.00 0.000000 0 107 close <...> What puzzles me, is the amount of errors for open and stat64. There are references to stuff I don't know (~/GNUStep directory? Stuff under site-packages that does not exist? Subdirs of site-packages that are not included in sys.path?) What is python doing there, and why? And, more importantly, how can this be corrected? Probably irrelevant, but Python2 version 2.7.3, Archlinux (current as of previous weekend). Thanks, Joep From steve+comp.lang.python at pearwood.info Mon Jan 14 23:25:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2013 04:25:21 GMT Subject: strace of python shows nonsense References: <20130115005001.6a7b0239@xs4all.nl> Message-ID: <50f4da31$0$29983$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Jan 2013 00:50:01 +0100, Joep van Delft wrote: > Hi there, > > > I am puzzled at how I borked my installation. Python loads slow on my > machine, and I decided to use strace and /usr/bin/time to see what is > actually happening. Before dropping down to such a low level, I suggest you start at a higher, Python level. Run `python -E` to disable any environment variables and startup file. Does that help? Compare sys.path when running with and without the -E switch. Any important differences? Anything unusual in sys.path, such as directories that don't exist? Run `python -v` to print modules as they are loaded. (Warning: there are a lot of them.) Can you see any obvious delays? [...] > What puzzles me, is the amount of errors for open and stat64. There are > references to stuff I don't know (~/GNUStep directory? Stuff under > site-packages that does not exist? Subdirs of site-packages that are not > included in sys.path?) What is python doing there, and why? And, more > importantly, how can this be corrected? What's the value of the environment variable PYTHONPATH? Do you have a PYTHONSTARTUP set? What is in that file? -- Steven From dieter at handshake.de Tue Jan 15 02:41:50 2013 From: dieter at handshake.de (Dieter Maurer) Date: Tue, 15 Jan 2013 08:41:50 +0100 Subject: strace of python shows nonsense References: <20130115005001.6a7b0239@xs4all.nl> Message-ID: <874niiao5d.fsf@handshake.de> Joep van Delft writes: > ... > What puzzles me, is the amount of errors for open and stat64. The high number of errors comes from Python's import logic: when Python should import a module/package (not yet imported), it looks into each member on "sys.path" for about 6 different potential filename spellings corresponding to the module -- until it succeeds or has tried all members. Most such filesystem lookups will fail - giving a high number of "stat" errors. From rodrick.brown at gmail.com Mon Jan 14 23:00:16 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Mon, 14 Jan 2013 23:00:16 -0500 Subject: code explanation Message-ID: Can someone explain what's going on here. def _build_magic_dispatcher(method): def inner(self, *args, **kwargs): return self.__dict__[method](*args, **kwargs) inner.__name__ = method return inner Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Jan 14 23:38:09 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2013 04:38:09 GMT Subject: code explanation References: Message-ID: <50f4dd31$0$29983$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Jan 2013 23:00:16 -0500, Rodrick Brown wrote: > Can someone explain what's going on here. > > def _build_magic_dispatcher(method): > def inner(self, *args, **kwargs): > return self.__dict__[method](*args, **kwargs) > inner.__name__ = method > return inner > > Thanks. This is a factory function, probably intended to be used as a decorator: class K: @_build_magic_dispatcher def something(self, x, y, z): ... except that it appears to be broken. It seems to be expecting a *string*, the name of a method, despite the function parameter claiming to require a method itself. So maybe you use it like this: class K: def __init__(self): self.parrot = _build_magic_dispatcher("parrot") or something similar. Without seeing the context, it's hard for me to tell whether it works or is broken. I suspect it is broken, or useless, or both. So, this factory function seems to take the *name* of a method as argument. Then it builds an inner method, which accepts arbitrary arguments (args and kwargs), renames the inner method to the name you passed as argument, and returns it. The inner method simply looks up an attribute with the same name, and calls it as a function with whatever args and kwargs it gets. Does this help? -- Steven From rodrick.brown at gmail.com Mon Jan 14 23:51:40 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Mon, 14 Jan 2013 23:51:40 -0500 Subject: code explanation In-Reply-To: <50f4dd31$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <50f4dd31$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 14, 2013 at 11:38 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Mon, 14 Jan 2013 23:00:16 -0500, Rodrick Brown wrote: > > > Can someone explain what's going on here. > > > > def _build_magic_dispatcher(method): > > def inner(self, *args, **kwargs): > > return self.__dict__[method](*args, **kwargs) > > inner.__name__ = method > > return inner > > > > Thanks. > > > This is a factory function, probably intended to be used as a decorator: > > class K: > @_build_magic_dispatcher > def something(self, x, y, z): ... > > except that it appears to be broken. It seems to be expecting a *string*, > the name of a method, despite the function parameter claiming to require > a method itself. So maybe you use it like this: > > class K: > def __init__(self): > self.parrot = _build_magic_dispatcher("parrot") > > > or something similar. Without seeing the context, it's hard for me to > tell whether it works or is broken. I suspect it is broken, or useless, > or both. > > So, this factory function seems to take the *name* of a method as > argument. Then it builds an inner method, which accepts arbitrary > arguments (args and kwargs), renames the inner method to the name you > passed as argument, and returns it. > > Thanks Steven, here is the full context of the code. I'm trying to understand what exactly the author is trying to accomplish here. import sys PY3K = sys.version_info >= (3,) methods = set([ "__iter__", "__len__", "__contains__", "__lt__", "__le__", "__eq__", "__ne__", "__gt__", "__ge__", "__add__", "__and__", "__divmod__", "__floordiv__", "__lshift__", "__mod__", "__mul__", "__or__", "__pow__", "__rshift__", "__sub__", "__truediv__", "__xor__", ]) if PY3K: methods.add("__next__") methods.add("__bool__") else: methods.add("__div__") methods.add("__nonzero__") MAGIC_METHODS = frozenset(methods) del methods def _build_magic_dispatcher(method): def inner(self, *args, **kwargs): return self.__dict__[method](*args, **kwargs) inner.__name__ = method return inner class stub(object): _classes_cache = {} def __new__(cls, **kwargs): magic_methods_present = MAGIC_METHODS.intersection(kwargs) if magic_methods_present not in cls._classes_cache: attrs = dict( (method, _build_magic_dispatcher(method)) for method in magic_methods_present ) attrs["__module__"] = cls.__module__ cls._classes_cache[magic_methods_present] = type("stub", (cls,), attrs) new_cls = cls._classes_cache[magic_methods_present] return super(stub, new_cls).__new__(new_cls, **kwargs) def __init__(self, **kwargs): self.__dict__.update(kwargs) > The inner method simply looks up an attribute with the same name, and > calls it as a function with whatever args and kwargs it gets. > > > Does this help? > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Jan 15 00:39:57 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Jan 2013 22:39:57 -0700 Subject: code explanation In-Reply-To: References: <50f4dd31$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 14, 2013 at 9:51 PM, Rodrick Brown wrote: > import sys > > PY3K = sys.version_info >= (3,) > > > methods = set([ > "__iter__", > "__len__", > "__contains__", > > "__lt__", > "__le__", > "__eq__", > "__ne__", > "__gt__", > "__ge__", > > "__add__", > "__and__", > "__divmod__", > "__floordiv__", > "__lshift__", > "__mod__", > "__mul__", > "__or__", > "__pow__", > "__rshift__", > "__sub__", > "__truediv__", > "__xor__", > ]) > if PY3K: > methods.add("__next__") > methods.add("__bool__") > else: > methods.add("__div__") > methods.add("__nonzero__") > MAGIC_METHODS = frozenset(methods) > del methods > > def _build_magic_dispatcher(method): > def inner(self, *args, **kwargs): > return self.__dict__[method](*args, **kwargs) > inner.__name__ = method > return inner > > > class stub(object): > _classes_cache = {} > > def __new__(cls, **kwargs): > magic_methods_present = MAGIC_METHODS.intersection(kwargs) > if magic_methods_present not in cls._classes_cache: > attrs = dict( > (method, _build_magic_dispatcher(method)) > for method in magic_methods_present > ) > attrs["__module__"] = cls.__module__ > cls._classes_cache[magic_methods_present] = type("stub", (cls,), > attrs) > new_cls = cls._classes_cache[magic_methods_present] > return super(stub, new_cls).__new__(new_cls, **kwargs) > > def __init__(self, **kwargs): > self.__dict__.update(kwargs) The stub class is called with keyword arguments where the keys are the names of Python "magic methods" and the values are functions. When called, it builds a new subclass of itself populated with a corresponding set of methods, each of which is built by _build_magic_dispatcher; these look up the method with the same name in the instance dictionary and delegate the call to whatever they find. For some reason that eludes me, the generated methods appear to discard the "self" argument in the process. After the subclass is generated, it constructs and returns an instance of the subclass, and then when the __init__ method is called it simply populates the instance dictionary with the functions that were passed in. The purpose of this appears to be to construct objects with magic methods that are defined on the object itself rather than on the class. Normally, when Python calls a magic method it doesn't look in the instance dictionary at all and only looks in the class dictionary. The subclasses of "stub" side-step that by having the desired magic methods on the class delegate calls to the instance. From tjreedy at udel.edu Mon Jan 14 23:48:02 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 14 Jan 2013 23:48:02 -0500 Subject: code explanation In-Reply-To: References: Message-ID: On 1/14/2013 11:00 PM, Rodrick Brown wrote: > Can someone explain what's going on here. > > def _build_magic_dispatcher(method): > def inner(self, *args, **kwargs): > return self.__dict__[method](*args, **kwargs) > inner.__name__ = method > return inner Nothing, until you run that with some particular version of Python. If you do run it, the result should be as documented for that particular version. If you write additional code to call the function, the result will depend on the Python version and argument. Now, what did you actually want to know ;-? You should likely find the answer in the reference manual, especially the section on def statements. -- Terry Jan Reedy From llanitedave at veawb.coop Tue Jan 15 02:09:28 2013 From: llanitedave at veawb.coop (llanitedave) Date: Mon, 14 Jan 2013 23:09:28 -0800 (PST) Subject: sqlite3 puzzle Message-ID: I'm trying to get an application working in Python 2.7 and wx.Python which contains an embedded sqlite3 file. There are a few tables with foreign keys defined. In looking at the sqlite3 documentation, it says "Assuming the library is compiled with foreign key constraints enabled, it must still be enabled by the application at runtime, using the PRAGMA foreign_keys command." It goes on to say that foreign keys must be enabled separately for each connection, which is fine as my app has only one. So I put the following test code in my initialization method: # open database file self.geologger_db = sqlite3.connect('geologger.mgc') self.db_cursor = self.geologger_db.cursor() self.foreign_key_status = self.db_cursor.execute("PRAGMA foreign_keys = ON") self.foreign_key_status = self.foreign_key_status.fetchone() print self.foreign_key_status I ran this several times while I was arranging the downstream queries, and each time it returned '(1,)', which means foreign keys is enabled. But I was using a variable named 'cmd1' as a placeholder until I changed the name to the more descriptive 'self.foreign_key_status'. Since I made the name change, however, the code only returns 'None'. Reverting to the previous variable name has no effect. Yes, I'm closing the connection with self.db_cursor.close() at the end of each run. According to the sqlite3 website, getting no return value, not even a '0', means that "the version of SQLite you are using does not support foreign keys (either because it is older than 3.6.19 or because it was compiled with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined)." How can that be a compilation issue when it worked previously? Does this somehow relate to it being a Python plugin instance? I'm very confused. From robert.day at merton.oxon.org Tue Jan 15 09:36:51 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Tue, 15 Jan 2013 14:36:51 +0000 Subject: sqlite3 puzzle In-Reply-To: References: Message-ID: On 15 January 2013 07:09, llanitedave wrote: > So I put the following test code in my initialization method: > > # open database file > self.geologger_db = sqlite3.connect('geologger.mgc') > self.db_cursor = self.geologger_db.cursor() > self.foreign_key_status = self.db_cursor.execute("PRAGMA foreign_keys = ON") > self.foreign_key_status = self.foreign_key_status.fetchone() > > print self.foreign_key_status > > I ran this several times while I was arranging the downstream queries, and each time it returned '(1,)', which means foreign keys is enabled. > > But I was using a variable named 'cmd1' as a placeholder until I changed the name to > the more descriptive 'self.foreign_key_status'. Since I made the name change, however, > the code only returns 'None'. Reverting to the previous variable name has no effect. Hmm - your code doesn't quite match up with the docs at http://docs.python.org/2/library/sqlite3.html. That seems to suggest that you should call fetchone() on the cursor, not on the result of execute(). Does the following work? # open database file self.geologger_db = sqlite3.connect('geologger.mgc') self.db_cursor = self.geologger_db.cursor() self.db_cursor.execute("PRAGMA foreign_keys = ON") print self.db_cursor.fetchone() -- Robert K. Day robert.day at merton.oxon.org From llanitedave at veawb.coop Tue Jan 15 10:51:33 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 15 Jan 2013 07:51:33 -0800 (PST) Subject: sqlite3 puzzle In-Reply-To: References: Message-ID: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> On Tuesday, January 15, 2013 6:36:51 AM UTC-8, Rob Day wrote: > On 15 January 2013 07:09, llanitedave wrote: > > > > > So I put the following test code in my initialization method: > > > > > > # open database file > > > self.geologger_db = sqlite3.connect('geologger.mgc') > > > self.db_cursor = self.geologger_db.cursor() > > > self.foreign_key_status = self.db_cursor.execute("PRAGMA foreign_keys = ON") > > > self.foreign_key_status = self.foreign_key_status.fetchone() > > > > > > print self.foreign_key_status > > > > > > I ran this several times while I was arranging the downstream queries, and each time it returned '(1,)', which means foreign keys is enabled. > > > > > > But I was using a variable named 'cmd1' as a placeholder until I changed the name to > > > the more descriptive 'self.foreign_key_status'. Since I made the name change, however, > > > the code only returns 'None'. Reverting to the previous variable name has no effect. > > > > Hmm - your code doesn't quite match up with the docs at > > http://docs.python.org/2/library/sqlite3.html. That seems to suggest > > that you should call fetchone() on the cursor, not on the result of > > execute(). > > > > Does the following work? > > > > # open database file > > self.geologger_db = sqlite3.connect('geologger.mgc') > > self.db_cursor = self.geologger_db.cursor() > > self.db_cursor.execute("PRAGMA foreign_keys = ON") > > print self.db_cursor.fetchone() > > > > > > -- > > Robert K. Day > > robert.day at merton.oxon.org Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. From llanitedave at veawb.coop Tue Jan 15 10:51:33 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 15 Jan 2013 07:51:33 -0800 (PST) Subject: sqlite3 puzzle In-Reply-To: References: Message-ID: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> On Tuesday, January 15, 2013 6:36:51 AM UTC-8, Rob Day wrote: > On 15 January 2013 07:09, llanitedave wrote: > > > > > So I put the following test code in my initialization method: > > > > > > # open database file > > > self.geologger_db = sqlite3.connect('geologger.mgc') > > > self.db_cursor = self.geologger_db.cursor() > > > self.foreign_key_status = self.db_cursor.execute("PRAGMA foreign_keys = ON") > > > self.foreign_key_status = self.foreign_key_status.fetchone() > > > > > > print self.foreign_key_status > > > > > > I ran this several times while I was arranging the downstream queries, and each time it returned '(1,)', which means foreign keys is enabled. > > > > > > But I was using a variable named 'cmd1' as a placeholder until I changed the name to > > > the more descriptive 'self.foreign_key_status'. Since I made the name change, however, > > > the code only returns 'None'. Reverting to the previous variable name has no effect. > > > > Hmm - your code doesn't quite match up with the docs at > > http://docs.python.org/2/library/sqlite3.html. That seems to suggest > > that you should call fetchone() on the cursor, not on the result of > > execute(). > > > > Does the following work? > > > > # open database file > > self.geologger_db = sqlite3.connect('geologger.mgc') > > self.db_cursor = self.geologger_db.cursor() > > self.db_cursor.execute("PRAGMA foreign_keys = ON") > > print self.db_cursor.fetchone() > > > > > > -- > > Robert K. Day > > robert.day at merton.oxon.org Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. From robert.day at merton.oxon.org Tue Jan 15 12:13:13 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Tue, 15 Jan 2013 17:13:13 +0000 Subject: sqlite3 puzzle In-Reply-To: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> References: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> Message-ID: On 15 January 2013 15:51, llanitedave wrote: > Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. > > I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. Well - you might be able to accept that, but I'm not sure I can! If it was working before, it must be compiled in, and so it must be possible to make it work again. http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that "PRAGMA foreign_keys = ON" never returns anything, and it's only "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported). With that in mind, does the following code work? # open database file self.geologger_db = sqlite3.connect('geologger.mgc') self.db_cursor = self.geologger_db.cursor() self.db_cursor.execute("PRAGMA foreign_keys = ON") self.db_cursor.execute("PRAGMA foreign_keys") print self.db_cursor.fetchone() From llanitedave at veawb.coop Tue Jan 15 15:29:28 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 15 Jan 2013 12:29:28 -0800 (PST) Subject: sqlite3 puzzle In-Reply-To: References: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> Message-ID: <8d9daaa7-091c-4810-85d2-0a7b03838441@googlegroups.com> On Tuesday, January 15, 2013 9:13:13 AM UTC-8, Rob Day wrote: > On 15 January 2013 15:51, llanitedave wrote: > > > Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. > > > > > > I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. > > > > Well - you might be able to accept that, but I'm not sure I can! If it > > was working before, it must be compiled in, and so it must be possible > > to make it work again. > > > > http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that > > "PRAGMA foreign_keys = ON" never returns anything, and it's only > > "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported). > > With that in mind, does the following code work? > > > > # open database file > > > > self.geologger_db = sqlite3.connect('geologger.mgc') > > self.db_cursor = self.geologger_db.cursor() > > self.db_cursor.execute("PRAGMA foreign_keys = ON") > > self.db_cursor.execute("PRAGMA foreign_keys") > > print self.db_cursor.fetchone() "http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that "PRAGMA foreign_keys = ON" never returns anything, and it's only "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported)." That was it, exactly, Rob. I don't know where I got the idea that I was getting a '1' from the 'ON' command, although I was sure that I'd seen it. But once I just called "foreign_key" it returned just fine. Ummm... Obviously I was up fiddling around too late. Yeah, that's it. Thanks! It's solved now. From llanitedave at veawb.coop Tue Jan 15 15:29:28 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 15 Jan 2013 12:29:28 -0800 (PST) Subject: sqlite3 puzzle In-Reply-To: References: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> Message-ID: <8d9daaa7-091c-4810-85d2-0a7b03838441@googlegroups.com> On Tuesday, January 15, 2013 9:13:13 AM UTC-8, Rob Day wrote: > On 15 January 2013 15:51, llanitedave wrote: > > > Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. > > > > > > I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. > > > > Well - you might be able to accept that, but I'm not sure I can! If it > > was working before, it must be compiled in, and so it must be possible > > to make it work again. > > > > http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that > > "PRAGMA foreign_keys = ON" never returns anything, and it's only > > "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported). > > With that in mind, does the following code work? > > > > # open database file > > > > self.geologger_db = sqlite3.connect('geologger.mgc') > > self.db_cursor = self.geologger_db.cursor() > > self.db_cursor.execute("PRAGMA foreign_keys = ON") > > self.db_cursor.execute("PRAGMA foreign_keys") > > print self.db_cursor.fetchone() "http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that "PRAGMA foreign_keys = ON" never returns anything, and it's only "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported)." That was it, exactly, Rob. I don't know where I got the idea that I was getting a '1' from the 'ON' command, although I was sure that I'd seen it. But once I just called "foreign_key" it returned just fine. Ummm... Obviously I was up fiddling around too late. Yeah, that's it. Thanks! It's solved now. From robert.day at merton.oxon.org Tue Jan 15 17:27:28 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Tue, 15 Jan 2013 22:27:28 +0000 Subject: sqlite3 puzzle In-Reply-To: <8d9daaa7-091c-4810-85d2-0a7b03838441@googlegroups.com> References: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> <8d9daaa7-091c-4810-85d2-0a7b03838441@googlegroups.com> Message-ID: Glad I could help! Using a local source control system like git, bzr or hg is really useful in situations like these - it's far, far easier to debug issues of the form "I made changes and now it's broken" when you can do `git diff yesterday's-version today's-version` and see exactly what the changes were. On 15 January 2013 20:29, llanitedave wrote: > On Tuesday, January 15, 2013 9:13:13 AM UTC-8, Rob Day wrote: >> On 15 January 2013 15:51, llanitedave wrote: >> >> > Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. >> >> > >> >> > I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. >> >> >> >> Well - you might be able to accept that, but I'm not sure I can! If it >> >> was working before, it must be compiled in, and so it must be possible >> >> to make it work again. >> >> >> >> http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that >> >> "PRAGMA foreign_keys = ON" never returns anything, and it's only >> >> "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported). >> >> With that in mind, does the following code work? >> >> >> >> # open database file >> >> >> >> self.geologger_db = sqlite3.connect('geologger.mgc') >> >> self.db_cursor = self.geologger_db.cursor() >> >> self.db_cursor.execute("PRAGMA foreign_keys = ON") >> >> self.db_cursor.execute("PRAGMA foreign_keys") >> >> print self.db_cursor.fetchone() > > "http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that "PRAGMA foreign_keys = ON" never returns anything, and it's only "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported)." > > That was it, exactly, Rob. I don't know where I got the idea that I was getting a '1' from the 'ON' command, although I was sure that I'd seen it. But once I just called "foreign_key" it returned just fine. > > Ummm... Obviously I was up fiddling around too late. Yeah, that's it. > > > Thanks! It's solved now. > -- > http://mail.python.org/mailman/listinfo/python-list -- Robert K. Day robert.day at merton.oxon.org From llanitedave at veawb.coop Tue Jan 15 17:46:12 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 15 Jan 2013 14:46:12 -0800 (PST) Subject: sqlite3 puzzle In-Reply-To: References: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> <8d9daaa7-091c-4810-85d2-0a7b03838441@googlegroups.com> Message-ID: <7a59a9e5-fa84-4779-815b-fac1bc02c3d3@googlegroups.com> Yabut I'm talking about changes I'd made 30 seconds before to code I'd written 5 minutes before. My short-term memory is nothing to write home about, even if I could remember my mailing address! On Tuesday, January 15, 2013 2:27:28 PM UTC-8, Rob Day wrote: > Glad I could help! > > > > > > Using a local source control system like git, bzr or hg is really > > useful in situations like these - it's far, far easier to debug issues > > of the form "I made changes and now it's broken" when you can do `git > > diff yesterday's-version today's-version` and see exactly what the > > changes were. > > > > > > On 15 January 2013 20:29, llanitedave wrote: > > > On Tuesday, January 15, 2013 9:13:13 AM UTC-8, Rob Day wrote: > > >> On 15 January 2013 15:51, llanitedave wrote: > > >> > > >> > Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. > > >> > > >> > > > >> > > >> > I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. > > >> > > >> > > >> > > >> Well - you might be able to accept that, but I'm not sure I can! If it > > >> > > >> was working before, it must be compiled in, and so it must be possible > > >> > > >> to make it work again. > > >> > > >> > > >> > > >> http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that > > >> > > >> "PRAGMA foreign_keys = ON" never returns anything, and it's only > > >> > > >> "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported). > > >> > > >> With that in mind, does the following code work? > > >> > > >> > > >> > > >> # open database file > > >> > > >> > > >> > > >> self.geologger_db = sqlite3.connect('geologger.mgc') > > >> > > >> self.db_cursor = self.geologger_db.cursor() > > >> > > >> self.db_cursor.execute("PRAGMA foreign_keys = ON") > > >> > > >> self.db_cursor.execute("PRAGMA foreign_keys") > > >> > > >> print self.db_cursor.fetchone() > > > > > > "http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that "PRAGMA foreign_keys = ON" never returns anything, and it's only "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported)." > > > > > > That was it, exactly, Rob. I don't know where I got the idea that I was getting a '1' from the 'ON' command, although I was sure that I'd seen it. But once I just called "foreign_key" it returned just fine. > > > > > > Ummm... Obviously I was up fiddling around too late. Yeah, that's it. > > > > > > > > > Thanks! It's solved now. > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > Robert K. Day > > robert.day at merton.oxon.org From llanitedave at veawb.coop Tue Jan 15 17:46:12 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 15 Jan 2013 14:46:12 -0800 (PST) Subject: sqlite3 puzzle In-Reply-To: References: <2fce91ea-374c-4f55-9e53-fe4032c2f5fd@googlegroups.com> <8d9daaa7-091c-4810-85d2-0a7b03838441@googlegroups.com> Message-ID: <7a59a9e5-fa84-4779-815b-fac1bc02c3d3@googlegroups.com> Yabut I'm talking about changes I'd made 30 seconds before to code I'd written 5 minutes before. My short-term memory is nothing to write home about, even if I could remember my mailing address! On Tuesday, January 15, 2013 2:27:28 PM UTC-8, Rob Day wrote: > Glad I could help! > > > > > > Using a local source control system like git, bzr or hg is really > > useful in situations like these - it's far, far easier to debug issues > > of the form "I made changes and now it's broken" when you can do `git > > diff yesterday's-version today's-version` and see exactly what the > > changes were. > > > > > > On 15 January 2013 20:29, llanitedave wrote: > > > On Tuesday, January 15, 2013 9:13:13 AM UTC-8, Rob Day wrote: > > >> On 15 January 2013 15:51, llanitedave wrote: > > >> > > >> > Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. > > >> > > >> > > > >> > > >> > I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working. > > >> > > >> > > >> > > >> Well - you might be able to accept that, but I'm not sure I can! If it > > >> > > >> was working before, it must be compiled in, and so it must be possible > > >> > > >> to make it work again. > > >> > > >> > > >> > > >> http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that > > >> > > >> "PRAGMA foreign_keys = ON" never returns anything, and it's only > > >> > > >> "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported). > > >> > > >> With that in mind, does the following code work? > > >> > > >> > > >> > > >> # open database file > > >> > > >> > > >> > > >> self.geologger_db = sqlite3.connect('geologger.mgc') > > >> > > >> self.db_cursor = self.geologger_db.cursor() > > >> > > >> self.db_cursor.execute("PRAGMA foreign_keys = ON") > > >> > > >> self.db_cursor.execute("PRAGMA foreign_keys") > > >> > > >> print self.db_cursor.fetchone() > > > > > > "http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that "PRAGMA foreign_keys = ON" never returns anything, and it's only "PRAGMA foreign_keys" which returns 0, 1 or None (when unsupported)." > > > > > > That was it, exactly, Rob. I don't know where I got the idea that I was getting a '1' from the 'ON' command, although I was sure that I'd seen it. But once I just called "foreign_key" it returned just fine. > > > > > > Ummm... Obviously I was up fiddling around too late. Yeah, that's it. > > > > > > > > > Thanks! It's solved now. > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > Robert K. Day > > robert.day at merton.oxon.org From inq1ltd at inqvista.com Tue Jan 15 11:54:42 2013 From: inq1ltd at inqvista.com (inq1ltd) Date: Tue, 15 Jan 2013 11:54:42 -0500 Subject: sqlite3 puzzle In-Reply-To: References: Message-ID: <5600792.TDe4m74tzM@mach-114-20> On Monday, January 14, 2013 11:09:28 PM llanitedave wrote: > I'm trying to get an application working in Python 2.7 and wx.Python which > contains an embedded sqlite3 file. There are a few tables with foreign > keys defined. In looking at the sqlite3 documentation, it says > > "Assuming the library is compiled with foreign key constraints enabled, it > must still be enabled by the application at runtime, using the PRAGMA > foreign_keys command." It goes on to say that foreign keys must be enabled > separately for each connection, which is fine as my app has only one. > > So I put the following test code in my initialization method: > > # open database file > self.geologger_db = sqlite3.connect('geologger.mgc') > self.db_cursor = self.geologger_db.cursor() > self.foreign_key_status = self.db_cursor.execute("PRAGMA foreign_keys = > ON") self.foreign_key_status = self.foreign_key_status.fetchone() > > print self.foreign_key_status > > I ran this several times while I was arranging the downstream queries, and > each time it returned '(1,)', which means foreign keys is enabled. > > But I was using a variable named 'cmd1' as a placeholder until I changed the > name to the more descriptive 'self.foreign_key_status'. Since I made the > name change, however, the code only returns 'None'. Reverting to the > previous variable name has no effect. > > Yes, I'm closing the connection with self.db_cursor.close() at the end of > each run. > > According to the sqlite3 website, getting no return value, not even a '0', > means that "the version of SQLite you are using does not support foreign > keys (either because it is older than 3.6.19 or because it was compiled > with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined)." > > How can that be a compilation issue when it worked previously? Does this > somehow relate to it being a Python plugin instance? > > I'm very confused. I haven't run this myself but after self.foreign_key_status.fetchone() try : self.geologger_db.commit() then close the db jimonlinux -------------- next part -------------- An HTML attachment was scrubbed... URL: From michels at mps.mpg.de Tue Jan 15 04:39:18 2013 From: michels at mps.mpg.de (Helmut Michels) Date: Tue, 15 Jan 2013 10:39:18 +0100 Subject: [ANN] Data Plotting Library DISLIN 10.3 Message-ID: Dear Python users, I am pleased to announce version 10.3 of the data plotting software DISLIN. DISLIN is a high-level and easy to use plotting library for displaying data as curves, bar graphs, pie charts, 3D-colour plots, surfaces, contours and maps. Several output formats are supported such as X11, VGA, PostScript, PDF, CGM, WMF, HPGL, TIFF, GIF, PNG, BMP and SVG. The software is available for the most C, Fortran 77 and Fortran 90/95 compilers. Plotting extensions for the interpreting languages Perl, Python, Java, Ch, Ruby and TCL are also supported. DISLIN distributions and manuals in PDF and HTML format are available from the DISLIN home page http://www.dislin.de and via FTP from the server ftp://ftp.gwdg.de/pub/grafik/dislin All DISLIN distributions are free for non-commercial use. Licenses for commercial use are available from the site http://www.dislin.de. ------------------- Helmut Michels Max Planck Institute for Solar System Research Phone: +49 5556 979-334 Max-Planck-Str. 2 Fax : +49 5556 979-240 D-37191 Katlenburg-Lindau Mail : michels at mps.mpg.de From levinie001 at gmail.com Tue Jan 15 04:46:08 2013 From: levinie001 at gmail.com (Levi Nie) Date: Tue, 15 Jan 2013 17:46:08 +0800 Subject: interrupt the file sending if the file size over the quota...some errors here... Message-ID: i want to interrupt the file sending. but i can't change the client. so i need change the server. All things go well, but the message i wanna response seem not work. is the self.transport.loseConnection() (the last line) blocking the messages? in fact, i work on Cumulus(nimbus project) which based on twisted. And i use s3cmd as the client. here is the my code: def headerReceived(self,line): pycb.log(logging.INFO, "===== def headerReceived of cumulus.py") http.HTTPChannel.headerReceived(self,line) pycb.log(logging.INFO, "===== self.length is %s"%self.length) header, data = line.split(':', 1) header = header.lower() data = data.strip() if header=='authorization': self.authorization=data if self.length and self.authorization: user_id = self.authorization.split(':')[0].split()[1].strip() user = pycb.config.auth.get_user(user_id) pycb.log(logging.INFO, "===== user who put this object is %s"%user) remaining_quota = user.get_remaining_quota() pycb.log(logging.INFO, "===== remaining_quota is %s"%remaining_quota) quota_check=self.length-remaining_quota pycb.log(logging.INFO, "===== quota_check=self.length-remaining_quota of cumulus.py") if quota_check>0: requestId = str(uuid.uuid1()).replace("-", "") ex=cbException('AccountProblem') m_msg = "HTTP/1.1 %s %s\r\n" % (ex.httpCode, ex.httpDesc) self.transport.write(m_msg) m_msg = "%s: %s\r\n" % (('x-amz-request-id', requestId)) self.transport.write(m_msg) #req.setHeader('x-amz-request-id', requestId) m_msg = "%s: %s\r\n" % (('x-amz-id-2', str(uuid.uuid1()))) self.transport.write(m_msg) e_msg = ex.make_xml_string(self._path, str(uuid.uuid1())) pycb.log(logging.INFO, "===== e_msg is %s"%e_msg) #self.transport.write("\r\n") self.transport.write(e_msg) pycb.log(logging.INFO, "===== self.transport.write(e_msg)") self.transport.loseConnection() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Tue Jan 15 07:46:52 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 15 Jan 2013 13:46:52 +0100 Subject: interrupt the file sending if the file size over the quota...some errors here... In-Reply-To: References: Message-ID: Am 15.01.2013 10:46, schrieb Levi Nie: > i want to interrupt the file sending. but i can't change the client. so i > need change the server. > All things go well, but the message i wanna response seem not work. Ahem, what? It doesn't work, so does it sit on the couch all day? > is the self.transport.loseConnection() (the last line) blocking the > messages? > in fact, i work on Cumulus(nimbus project) which based on twisted. And i > use s3cmd as the client. I'm wondering if questions concerning twisted don't have a better forum. In any case, I can only comment on the general approach. For that, there are two things you can do: 1. When receiving the the request header, you have a content length. If that exceeds the allowed amount, shutdown() receiving and send an according HTTP response before closing the connection. 2. If the data exceeds the amount advertised by the content length, close the connection and discard the request. If you want to be nice, send an according response before closing, but I personally wouldn't go to that effort for broken HTTP clients. Concerning the question why your client hangs, it could also be the sending. If you try to send something before receiving the full request, client and server could enter a deadlock where each side waits for the other to receive some data. For that reason, you should shutdown() receiving in such a case. HTH Uli From steve at spvi.com Tue Jan 15 07:25:34 2013 From: steve at spvi.com (Steve Spicklemire) Date: Tue, 15 Jan 2013 05:25:34 -0700 Subject: atexit handler in IDLE? Message-ID: <24E53D14-FD57-4FE2-8763-99149773650B@spvi.com> Hello Pythonistas! I'm trying to get this program, which works on the command line, to run correctly in the IDLE environment: import atexit print "This is my program" def exit_func(): print "OK.. that's all folks!" atexit.register(exit_func) print "Program is ending..." When I run this on the command line I see: This is my program Program is ending... OK.. that's all folks! When I run this in IDLE I see: This is my program Program is ending... But the atexit handler is never called. ;-( I tried to fish through the IDLE source to see how the program is actually called, and I decided it looked like it was being invoked with with os.spawnv, but I'm not sure why this would defeat the atexit handler. Anybody know? I'd like to register such a function in my module, but I need it to work in IDLE so that students can easily use it. thanks! -steve From dreamingforward at gmail.com Tue Jan 15 12:22:03 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 15 Jan 2013 11:22:03 -0600 Subject: atexit handler in IDLE? In-Reply-To: References: <24E53D14-FD57-4FE2-8763-99149773650B@spvi.com> Message-ID: On Tue, Jan 15, 2013 at 6:25 AM, Steve Spicklemire wrote: > I'm trying to get this program, which works on the command line, to run correctly in the IDLE environment: > > import atexit > > print "This is my program" > > def exit_func(): > print "OK.. that's all folks!" > > atexit.register(exit_func) > > print "Program is ending..." You know, I think I looked at this problem once. It was rather strange, but I think you need to create a tempfile, so that Python knows that IDLE is running. There's an item for this in IDLE's TODO list. I was going to implement it, which is fairly east, but never got to it. mark From steve at spvi.com Tue Jan 15 14:38:15 2013 From: steve at spvi.com (Steve Spicklemire) Date: Tue, 15 Jan 2013 12:38:15 -0700 Subject: atexit handler in IDLE? In-Reply-To: References: <24E53D14-FD57-4FE2-8763-99149773650B@spvi.com> Message-ID: <67909E83-860B-43DB-BC6B-29B75744C41E@spvi.com> On Jan 15, 2013, at 10:22 AM, Mark Janssen wrote: > On Tue, Jan 15, 2013 at 6:25 AM, Steve Spicklemire wrote: >> I'm trying to get this program, which works on the command line, to run correctly in the IDLE environment: >> >> import atexit >> >> print "This is my program" >> >> def exit_func(): >> print "OK.. that's all folks!" >> >> atexit.register(exit_func) >> >> print "Program is ending..." > > You know, I think I looked at this problem once. It was rather > strange, but I think you need to create a tempfile, so that Python > knows that IDLE is running. There's an item for this in IDLE's TODO > list. I was going to implement it, which is fairly east, but never > got to it. > > mark > -- > http://mail.python.org/mailman/listinfo/python-list I don't really know how to use this. Is there a detailed todo list somewhere? I did find this tantalizing bit in news.txt, but when I tried to test it (by setting to option to false), I couldn't get it to work. Is there a set of tests for idle that might exercise this option? ---------- What's New in IDLEfork 0.9b1? ============================= *Release date: 02-Jun-2003* - Added the delete-exitfunc option to config-main.def. (This option is not included in the Options dialog.) Setting this to True (the default) will cause IDLE to not run sys.exitfunc/atexit when the subprocess exits. ------------- Thanks! -steve From tjreedy at udel.edu Tue Jan 15 20:27:22 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Jan 2013 20:27:22 -0500 Subject: atexit handler in IDLE? In-Reply-To: <24E53D14-FD57-4FE2-8763-99149773650B@spvi.com> References: <24E53D14-FD57-4FE2-8763-99149773650B@spvi.com> Message-ID: On 1/15/2013 7:25 AM, Steve Spicklemire wrote: > import atexit > print "This is my program" > > def exit_func(): > print "OK.. that's all folks!" > > atexit.register(exit_func) > print "Program is ending..." If you put () around the strings, it will run the same *and* work in 3.x. > When I run this on the command line I see: > > This is my program > Program is ending... > OK.. that's all folks! > > When I run this in IDLE I see: > > This is my program > Program is ending... > > But the atexit handler is never called. ;-( I tried in 3.3 idle and get the same. -- Terry Jan Reedy From contropinion at gmail.com Tue Jan 15 09:20:04 2013 From: contropinion at gmail.com (contro opinion) Date: Tue, 15 Jan 2013 22:20:04 +0800 Subject: i can't understand decorator Message-ID: >>> def deco(func): ... def kdeco(): ... print("before myfunc() called.") ... func() ... print(" after myfunc() called.") ... return kdeco ... >>> @deco ... def myfunc(): ... print(" myfunc() called.") ... >>> myfunc() before myfunc() called. myfunc() called. after myfunc() called. >>> deco(myfunc)() before myfunc() called. before myfunc() called. myfunc() called. after myfunc() called. after myfunc() called. 1. why there are two lines :before myfunc() called.and tow lines :after myfunc() called. in the output? 2.why the result is not before myfunc() called. myfunc() called. after myfunc() called. before myfunc() called. myfunc() called. after myfunc() called. -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Jan 15 09:31:25 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 15 Jan 2013 14:31:25 +0000 Subject: i can't understand decorator In-Reply-To: References: Message-ID: On 15 January 2013 14:20, contro opinion wrote: >>>> def deco(func): > ... def kdeco(): > ... print("before myfunc() called.") > ... func() > ... print(" after myfunc() called.") > ... return kdeco > ... >>>> @deco > ... def myfunc(): > ... print(" myfunc() called.") > ... >>>> myfunc() > before myfunc() called. > myfunc() called. > after myfunc() called. >>>> deco(myfunc)() > before myfunc() called. > before myfunc() called. > myfunc() called. > after myfunc() called. > after myfunc() called. > 1. > why there are two lines :before myfunc() called.and tow lines :after > myfunc() called. in the output? You have wrapped the function twice with the decorator. Try changing the line print("before func() called") to print("about to call", func,__name__) and you'll see that the function it is about to call is not the same in both cases. > 2.why the result is not > before myfunc() called. > myfunc() called. > after myfunc() called. > before myfunc() called. > myfunc() called. > after myfunc() called. You would get this output if you just called myfunc() twice. I don't know why you expect wrapping the function twice to have this effect. Oscar From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jan 15 16:21:24 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 15 Jan 2013 22:21:24 +0100 Subject: i can't understand decorator In-Reply-To: References: Message-ID: Am 15.01.2013 15:20 schrieb contro opinion: > >>> def deco(func): > ... def kdeco(): > ... print("before myfunc() called.") > ... func() > ... print(" after myfunc() called.") > ... return kdeco > ... > >>> @deco > ... def myfunc(): > ... print(" myfunc() called.") > ... > >>> myfunc() > before myfunc() called. > myfunc() called. > after myfunc() called. > >>> deco(myfunc)() > before myfunc() called. > before myfunc() called. > myfunc() called. > after myfunc() called. > after myfunc() called. Wrapping works this way: The function is defined, and the wrapper replaces the function with a different one which (in this case) calls the original one. Try print(myfunc) here and you see that myfunc is only a name for another function called kdeco. It is the one returned by the decorator. > 1. > why there are two lines :before myfunc() called.and tow lines :after > myfunc() called. in the output? This is because the "before" line is printed, then the modified "myfunc" is called, which in turn prints another "before" line and then calls the "really original" function. After it returns, the "after" line is called by the inner placement function (the one which sticks at the myfunc identifier). This function returns and the function instance which called the first "before" line is printed then. > 2.why the result is not > before myfunc() called. > myfunc() called. > after myfunc() called. > before myfunc() called. > myfunc() called. > after myfunc() called. Because the function calls are wrapped and not repeated. Thomas From dreadpiratejeff at gmail.com Tue Jan 15 18:24:44 2013 From: dreadpiratejeff at gmail.com (J) Date: Tue, 15 Jan 2013 18:24:44 -0500 Subject: Is there a more elegant way to handle determing fail status? Message-ID: Ok, so I have a diagnostic tool, written by someone else. That tool runs a series of small tests defined by the user and can simplified summary output that can be one of the following: FAILED_CRITICAL FAILED_HIGH FAILED_MEDIUM FAILED_LOW PASSED I also have a wrapper script I wrote to run these tests, summarize the results of all tests aggregated and then fail based on a particular fail level. The idea is that if I run 3 tests with the diagnostic tool and it tells me the following: testA: PASSED testB: FAILED_MEDIUM testC: PASSED AND I told the wrapper to only fail on HIGH or above, the wrapper will tell me that I had a medium failure, but the wrapper will still exit with a 0 (success) if I get the same results as above, but tell the wrapper to fail on LOW, then it will tell me I had that medium failure, but the wrapper will exit with a 1 (failure). The problem is that my exit determination looks like this: if fail_priority == fail_levels['FAILED_CRITICAL']: if critical_fails: return 1 if fail_priority == fail_levels['FAILED_HIGH']: if critical_fails or high_fails: return 1 if fail_priority == fail_levels['FAILED_MEDIUM']: if critical_fails or high_fails or medium_fails: return 1 if fail_priority == fail_levels['FAILED_LOW']: if critical_fails or high_fails or medium_fails or low_fails: return 1 return 0 So, to explain the above... the fail level can be set by the user when running the wrapper using -f (or it defaults to 'high') the wrapper assigns a number to each level using this: # Set correct fail level args.fail_level = 'FAILED_%s' % args.fail_level.upper() # Get our failure priority and create the priority values fail_levels = {'FAILED_CRITICAL':4, 'FAILED_HIGH':3, 'FAILED_MEDIUM':2, 'FAILED_LOW':1} fail_priority = fail_levels[args.fail_level] the variables critical_fails, high_fails, medium_fails, low_fails are all counters that are etiher None, or the number of tests that were failed. So using this output from the diagnostic tool: testA: PASSED testB: FAILED_HIGH testC: PASSED testD: FAILED_MEDIUM testE: PASSED critical_fails would be None high_fails would be 1 medium_fails would be 1 low_fails would be None. The exit code determination above works, but it just feels inelegant. It feels like there's a better way of implementing that, but I can't come up with one that still honors the fail level properly (e.g. other solutions will fail on medium, but won't fail properly on medium OR higher). I can provide the full script if necessary, if the above isn't enough to point me in a direction that has a better way of doing this... Thanks for looking, Jeff From donarb at nwlink.com Tue Jan 15 18:52:43 2013 From: donarb at nwlink.com (donarb) Date: Tue, 15 Jan 2013 15:52:43 -0800 (PST) Subject: Is there a more elegant way to handle determing fail status? In-Reply-To: References: Message-ID: On Tuesday, January 15, 2013 3:24:44 PM UTC-8, J wrote: > Ok, so I have a diagnostic tool, written by someone else. That tool > > runs a series of small tests defined by the user and can simplified > > summary output that can be one of the following: > > > > FAILED_CRITICAL > > FAILED_HIGH > > FAILED_MEDIUM > > FAILED_LOW > > PASSED > > > > I also have a wrapper script I wrote to run these tests, summarize the > > results of all tests aggregated and then fail based on a particular > > fail level. > > > > The idea is that if I run 3 tests with the diagnostic tool and it > > tells me the following: > > > > testA: PASSED > > testB: FAILED_MEDIUM > > testC: PASSED > > > > AND I told the wrapper to only fail on HIGH or above, the wrapper will > > tell me that I had a medium failure, but the wrapper will still exit > > with a 0 (success) > > > > if I get the same results as above, but tell the wrapper to fail on > > LOW, then it will tell me I had that medium failure, but the wrapper > > will exit with a 1 (failure). > > > > The problem is that my exit determination looks like this: > > > > if fail_priority == fail_levels['FAILED_CRITICAL']: > > if critical_fails: > > return 1 > > if fail_priority == fail_levels['FAILED_HIGH']: > > if critical_fails or high_fails: > > return 1 > > if fail_priority == fail_levels['FAILED_MEDIUM']: > > if critical_fails or high_fails or medium_fails: > > return 1 > > if fail_priority == fail_levels['FAILED_LOW']: > > if critical_fails or high_fails or medium_fails or low_fails: > > return 1 > > > > return 0 > > > > So, to explain the above... the fail level can be set by the user when > > running the wrapper using -f (or it defaults to 'high') > > the wrapper assigns a number to each level using this: > > > > # Set correct fail level > > args.fail_level = 'FAILED_%s' % args.fail_level.upper() > > > > # Get our failure priority and create the priority values > > fail_levels = {'FAILED_CRITICAL':4, > > 'FAILED_HIGH':3, > > 'FAILED_MEDIUM':2, > > 'FAILED_LOW':1} > > fail_priority = fail_levels[args.fail_level] > > > > the variables critical_fails, high_fails, medium_fails, low_fails are > > all counters that are etiher None, or the number of tests that were > > failed. > > > > So using this output from the diagnostic tool: > > > > testA: PASSED > > testB: FAILED_HIGH > > testC: PASSED > > testD: FAILED_MEDIUM > > testE: PASSED > > > > critical_fails would be None > > high_fails would be 1 > > medium_fails would be 1 > > low_fails would be None. > > > > The exit code determination above works, but it just feels inelegant. > > It feels like there's a better way of implementing that, but I can't > > come up with one that still honors the fail level properly (e.g. other > > solutions will fail on medium, but won't fail properly on medium OR > > higher). > > > > I can provide the full script if necessary, if the above isn't enough > > to point me in a direction that has a better way of doing this... > > > > Thanks for looking, > > > > Jeff My back of the envelope coding would do it this way. Use an array of fail_counters, with PASSED as the first element all the way up to FAILED_CRITICAL as the last element. Then use a simple loop starting from index fail_priority to the end of the list looking for errors. Like this: # Array of fail counters fail_counters = [ 0, # PASSED 0, # LOW 0, # MEDIUM 0, # HIGH 0 # CRITICAL ] ... run tests, accumulate error counts in fail_counters for i in range(fail_priority, len(fail_counters)): if fail_counters[i]: return 1 return 0 From donarb at nwlink.com Tue Jan 15 18:52:43 2013 From: donarb at nwlink.com (donarb) Date: Tue, 15 Jan 2013 15:52:43 -0800 (PST) Subject: Is there a more elegant way to handle determing fail status? In-Reply-To: References: Message-ID: On Tuesday, January 15, 2013 3:24:44 PM UTC-8, J wrote: > Ok, so I have a diagnostic tool, written by someone else. That tool > > runs a series of small tests defined by the user and can simplified > > summary output that can be one of the following: > > > > FAILED_CRITICAL > > FAILED_HIGH > > FAILED_MEDIUM > > FAILED_LOW > > PASSED > > > > I also have a wrapper script I wrote to run these tests, summarize the > > results of all tests aggregated and then fail based on a particular > > fail level. > > > > The idea is that if I run 3 tests with the diagnostic tool and it > > tells me the following: > > > > testA: PASSED > > testB: FAILED_MEDIUM > > testC: PASSED > > > > AND I told the wrapper to only fail on HIGH or above, the wrapper will > > tell me that I had a medium failure, but the wrapper will still exit > > with a 0 (success) > > > > if I get the same results as above, but tell the wrapper to fail on > > LOW, then it will tell me I had that medium failure, but the wrapper > > will exit with a 1 (failure). > > > > The problem is that my exit determination looks like this: > > > > if fail_priority == fail_levels['FAILED_CRITICAL']: > > if critical_fails: > > return 1 > > if fail_priority == fail_levels['FAILED_HIGH']: > > if critical_fails or high_fails: > > return 1 > > if fail_priority == fail_levels['FAILED_MEDIUM']: > > if critical_fails or high_fails or medium_fails: > > return 1 > > if fail_priority == fail_levels['FAILED_LOW']: > > if critical_fails or high_fails or medium_fails or low_fails: > > return 1 > > > > return 0 > > > > So, to explain the above... the fail level can be set by the user when > > running the wrapper using -f (or it defaults to 'high') > > the wrapper assigns a number to each level using this: > > > > # Set correct fail level > > args.fail_level = 'FAILED_%s' % args.fail_level.upper() > > > > # Get our failure priority and create the priority values > > fail_levels = {'FAILED_CRITICAL':4, > > 'FAILED_HIGH':3, > > 'FAILED_MEDIUM':2, > > 'FAILED_LOW':1} > > fail_priority = fail_levels[args.fail_level] > > > > the variables critical_fails, high_fails, medium_fails, low_fails are > > all counters that are etiher None, or the number of tests that were > > failed. > > > > So using this output from the diagnostic tool: > > > > testA: PASSED > > testB: FAILED_HIGH > > testC: PASSED > > testD: FAILED_MEDIUM > > testE: PASSED > > > > critical_fails would be None > > high_fails would be 1 > > medium_fails would be 1 > > low_fails would be None. > > > > The exit code determination above works, but it just feels inelegant. > > It feels like there's a better way of implementing that, but I can't > > come up with one that still honors the fail level properly (e.g. other > > solutions will fail on medium, but won't fail properly on medium OR > > higher). > > > > I can provide the full script if necessary, if the above isn't enough > > to point me in a direction that has a better way of doing this... > > > > Thanks for looking, > > > > Jeff My back of the envelope coding would do it this way. Use an array of fail_counters, with PASSED as the first element all the way up to FAILED_CRITICAL as the last element. Then use a simple loop starting from index fail_priority to the end of the list looking for errors. Like this: # Array of fail counters fail_counters = [ 0, # PASSED 0, # LOW 0, # MEDIUM 0, # HIGH 0 # CRITICAL ] ... run tests, accumulate error counts in fail_counters for i in range(fail_priority, len(fail_counters)): if fail_counters[i]: return 1 return 0 From steve+comp.lang.python at pearwood.info Tue Jan 15 21:55:52 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2013 02:55:52 GMT Subject: Is there a more elegant way to handle determing fail status? References: Message-ID: <50f616b7$0$11112$c3e8da3@news.astraweb.com> On Tue, 15 Jan 2013 18:24:44 -0500, J wrote: > The problem is that my exit determination looks like this: > > if fail_priority == fail_levels['FAILED_CRITICAL']: > if critical_fails: > return 1 > if fail_priority == fail_levels['FAILED_HIGH']: > if critical_fails or high_fails: > return 1 > if fail_priority == fail_levels['FAILED_MEDIUM']: > if critical_fails or high_fails or medium_fails: > return 1 > if fail_priority == fail_levels['FAILED_LOW']: > if critical_fails or high_fails or medium_fails or low_fails: > return 1 > return 0 Here's a general solution that doesn't require the failure levels to be numbers, or listed in order, or to support any operation except equality testing. Start with an ordered list of failure severity levels, and an equivalent ordered list of failure counts. Find the offset of the requested failure level in the FAILURES list. Then inspect the failure counts, up to and including that offset, ignoring any failure outside of that range: failures = [FAILED_CRITICAL, FAILED_HIGH, FAILED_MEDIUM, FAILED_LOW] counts = [critical_fails, high_fails, medium_fails, low_fails] i = failures.index(fail_priority) if any(counts[:i+1]): print "Failed" else: print "No failures that we care about" The actual values for FAILED_CRITICAL etc. can be arbitrary values: integers *in any order*, strings, complicated records, anything so long as they support equality and are distinct. fail_priority must be set to one of those values. > the variables critical_fails, high_fails, medium_fails, low_fails are > all counters that are etiher None, or the number of tests that were > failed. Why set them to None when no tests failed? If no tests failed, why not just use 0? That is, instead of the counters being "the number of failures, or None", they could be "the number of failures". -- Steven From oscar.j.benjamin at gmail.com Tue Jan 15 18:56:04 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 15 Jan 2013 23:56:04 +0000 Subject: Is there a more elegant way to handle determing fail status? In-Reply-To: References: Message-ID: On 15 January 2013 23:24, J wrote: > Ok, so I have a diagnostic tool, written by someone else. That tool > runs a series of small tests defined by the user and can simplified > summary output that can be one of the following: > > FAILED_CRITICAL > FAILED_HIGH > FAILED_MEDIUM > FAILED_LOW > PASSED > > I also have a wrapper script I wrote to run these tests, summarize the > results of all tests aggregated and then fail based on a particular > fail level. > > The idea is that if I run 3 tests with the diagnostic tool and it > tells me the following: > > testA: PASSED > testB: FAILED_MEDIUM > testC: PASSED > > AND I told the wrapper to only fail on HIGH or above, the wrapper will > tell me that I had a medium failure, but the wrapper will still exit > with a 0 (success) > > if I get the same results as above, but tell the wrapper to fail on > LOW, then it will tell me I had that medium failure, but the wrapper > will exit with a 1 (failure). > > The problem is that my exit determination looks like this: > > if fail_priority == fail_levels['FAILED_CRITICAL']: > if critical_fails: > return 1 > if fail_priority == fail_levels['FAILED_HIGH']: > if critical_fails or high_fails: > return 1 > if fail_priority == fail_levels['FAILED_MEDIUM']: > if critical_fails or high_fails or medium_fails: > return 1 > if fail_priority == fail_levels['FAILED_LOW']: > if critical_fails or high_fails or medium_fails or low_fails: > return 1 > > return 0 > [SNIP] > > The exit code determination above works, but it just feels inelegant. > It feels like there's a better way of implementing that, but I can't > come up with one that still honors the fail level properly (e.g. other > solutions will fail on medium, but won't fail properly on medium OR > higher). How about the following? FAILED_CRITICAL = 4 FAILED_HIGH = 3 FAILED_MEDIUM = 2 FAILED_LOW = 1 PASSED = 0 if fail_level: print fail_message if fail_level > fail_priority: return 1 Oscar From ian.g.kelly at gmail.com Tue Jan 15 19:01:07 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 15 Jan 2013 17:01:07 -0700 Subject: Is there a more elegant way to handle determing fail status? In-Reply-To: References: Message-ID: On Tue, Jan 15, 2013 at 4:24 PM, J wrote: > The exit code determination above works, but it just feels inelegant. > It feels like there's a better way of implementing that, but I can't > come up with one that still honors the fail level properly (e.g. other > solutions will fail on medium, but won't fail properly on medium OR > higher). First, instead of having separate variables 'critical_fails', 'high_fails', etc., put them in a collections.Counter 'fails' keyed by fail level. Second, make sure those fail level keys are orderable by severity. Then your check is just: if fail_priority <= max(fails): return 1 return 0 From aclark at aclark.net Tue Jan 15 19:50:41 2013 From: aclark at aclark.net (Alex Clark) Date: Tue, 15 Jan 2013 19:50:41 -0500 Subject: Please help test Pillow for Python 3 Message-ID: Hi, Python 3 support for PIL has been merged into the Pillow (PIL fork) master branch. If this interests you, please help test! - git://github.com/python-imaging/Pillow.git More on the subject: - http://blog.aclark.net/2013/01/10/pillow-python-3/ -- Alex Clark ? https://www.gittip.com/aclark4life/ From rosuav at gmail.com Wed Jan 16 00:03:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jan 2013 16:03:47 +1100 Subject: cymbalic reference? In-Reply-To: <20130115205604.178fa30eff8ae7155174d900@lavabit.com> References: <20130115205604.178fa30eff8ae7155174d900@lavabit.com> Message-ID: On Wed, Jan 16, 2013 at 3:56 PM, rh wrote: > While I'm at it what magic could I use to print "the-class-I-am-in good" > instead of hard-coding "Abc good"? I tried __class_ and self.__class__ Almost there! Try self.__class__.__name__ to get the name as a string. ChrisA From benjamin.kaplan at case.edu Wed Jan 16 00:08:02 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 15 Jan 2013 21:08:02 -0800 Subject: cymbalic reference? In-Reply-To: <20130115205604.178fa30eff8ae7155174d900@lavabit.com> References: <20130115205604.178fa30eff8ae7155174d900@lavabit.com> Message-ID: On Tue, Jan 15, 2013 at 8:56 PM, rh wrote: > I have this working and I am curious to know how others do same. > > class Abc(object): > def __init__(self): > pass > def good(self): > print "Abc good" > def better(self): > print "Abc better" > > urls = {'Abc':'http://example.com'} > strings = ['good', 'better'] > > for s in urls: > o = eval("%s()" % s) > for string in strings: > eval("o.%s()" % string) > > > Yes, 'spose symbolic references is what these are.... > > While I'm at it what magic could I use to print "the-class-I-am-in good" > instead of hard-coding "Abc good"? I tried __class_ and self.__class__ > > -- Rather than using eval, you can grab the class out of globals(), and then use getattr to get the methods. >>> for s in urls : ... o = globals()[s]() ... for method in strings : ... getattr(o, method)() ... Abc good Abc better And for getting the class name, the class has a __name__ attribute. So you could use self.__class__.__name__. From tjreedy at udel.edu Wed Jan 16 19:30:03 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Jan 2013 19:30:03 -0500 Subject: cymbalic reference? In-Reply-To: <20130116130632.d0fa6835d87a92d04c286284@lavabit.com> References: <20130115205604.178fa30eff8ae7155174d900@lavabit.com> <20130116130632.d0fa6835d87a92d04c286284@lavabit.com> Message-ID: On 1/16/2013 4:06 PM, rh wrote: > My final product uses your suggestions along with one from the other post. > I like the idea of storing the class name as the key. Then no call to globals() > is needed. But I still have to test how that object behaves when it's a key. > i.e. Is it deeply bound? Shallow? Tight? Loose? Not sure which is the correct > term! The only effect on an object of making it a dict key is that it cannot disappear. class C: pass d = {C: 'C'} del C # The name 'C' can no longer be used to access the class # However, the class cannot be deleted because it is in use for c in d: print(c) > So maybe I want {Abc:'http://example.com'} and o = s() instead. Yes, as I suggested. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 16 00:23:38 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Jan 2013 00:23:38 -0500 Subject: cymbalic reference? In-Reply-To: <20130115205604.178fa30eff8ae7155174d900@lavabit.com> References: <20130115205604.178fa30eff8ae7155174d900@lavabit.com> Message-ID: On 1/15/2013 11:56 PM, rh wrote: > I have this working and I am curious to know how others do same. > > class Abc(object): > def __init__(self): > pass > def good(self): > print "Abc good" > def better(self): > print "Abc better" > > urls = {'Abc':'http://example.com'} > strings = ['good', 'better'] > > for s in urls: > o = eval("%s()" % s) > for string in strings: > eval("o.%s()" % string) for s in urls: o = globals()[s]() for string in strings: getattr(o,string)() has same output. eval is seldom needed. Of course, if you more sensibly use the class or an instance as key urls = {Abc: 'http://example.com'} urls = {Abc(): 'http://example.com'} instead of the name, then o = s() or o = s directly. > While I'm at it what magic could I use to print "the-class-I-am-in good" > instead of hard-coding "Abc good"? I tried __class_ and self.__class__ self.__class__.__name__ or type(self).__name__) -- Terry Jan Reedy From rantingrickjohnson at gmail.com Wed Jan 16 00:59:42 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 15 Jan 2013 21:59:42 -0800 (PST) Subject: PyWart: Exception error paths far too verbose Message-ID: Python needs to trim the path to the source file from which the exception was caught and only display the relative path starting from your personal library folder. For example. Say your personal library exists in: C:\users\user\documents\python\lib ...then there is no need to post THAT portion of the path EVERY STINKING TIME! For instance, let's say a script at: C:\users\user\documents\python\lib\sound\effects\echo.py ...throws an error. What will we see? Traceback (most recent call last): File "C:\users\user\documents\python\lib\sound\effects\echo.py", line N, in BLAH Why do i need to see "C:\users\user\documents\python\lib" EVERY time? Since all directories *BELOW* the directory that holds your personal Python library are /superfluous/ when posting exceptions to stderr, trimming this bloat can really help to make exception messages easier to read. Traceback (most recent call last): File "...\sound\effects\reverb.py", line XXX, in YYY From donarb at nwlink.com Wed Jan 16 03:31:04 2013 From: donarb at nwlink.com (donarb) Date: Wed, 16 Jan 2013 00:31:04 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: Done https://github.com/erikrose/tracefront This module displays traces with shortened paths, and will even prepend your editor of choice and line number to the path, making a shortcut to jumping to the source in error via copy/paste. From rosuav at gmail.com Wed Jan 16 03:39:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jan 2013 19:39:32 +1100 Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: On Wed, Jan 16, 2013 at 7:31 PM, donarb wrote: > Done > > https://github.com/erikrose/tracefront > > This module displays traces with shortened paths, and will even prepend your editor of choice and line number to the path, making a shortcut to jumping to the source in error via copy/paste. Are you aware of the extreme dangers inherent in the use of time machines? ChrisA From tjreedy at udel.edu Wed Jan 16 04:53:55 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Jan 2013 04:53:55 -0500 Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: On 1/16/2013 12:59 AM, Rick Johnson wrote: > > Python needs to trim the path to the source file from which the > exception was caught and only display the relative path starting from > your personal library folder. > > For example. Say your personal library exists in: > > C:\users\user\documents\python\lib > > ...then there is no need to post THAT portion of the path EVERY > STINKING TIME! For instance, let's say a script at: > > C:\users\user\documents\python\lib\sound\effects\echo.py > > ...throws an error. What will we see? > > Traceback (most recent call last): File > "C:\users\user\documents\python\lib\sound\effects\echo.py", line N, > in BLAH > > Why do i need to see "C:\users\user\documents\python\lib" EVERY > time? > > Since all directories *BELOW* the directory that holds your personal > Python library are /superfluous/ when posting exceptions to stderr, > trimming this bloat can really help to make exception messages easier > to read. > > Traceback (most recent call last): File > "...\sound\effects\reverb.py", line XXX, in YYY I agree with the complaint and you may have the germ of a good idea. The problem is that for some tracebacks, paths jump all over the place rather than having a common prefix. Dealing with this might require preprocessing the entire traceback before iterating and printing each item. Are you are aware of ''' sys.excepthook(type, value, traceback) This function prints out a given traceback and exception to sys.stderr. When an exception is raised and uncaught, the interpreter calls sys.excepthook with three arguments, the exception class, exception instance, and a traceback object. In an interactive session this happens just before control is returned to the prompt; in a Python program this happens just before the program exits. The handling of such top-level exceptions can be customized by assigning another three-argument function to sys.excepthook. ''' This is how some apps and environments customize exception reporting (and logging). I believe some people also put a replacement in their site module. >>> import sys; sys.excepthook I expect the default, excepthook, is something like def excepthook(typ, value, traceback): print('Traceback (most recent call last):', file=sys.stderr) for item in traceback: print(format_tb_item(item), file=sys.stderr) print('{}: {}'.format(typ.__name__, value), file=sys.stderr) (or the equivalent with sys.stderr.write) What you want to change is format_tb_item (possibly, as I said, after scanning traceback before the print loop). If you come up with something nice, I would like to see it. The only thing special that IDLE does now is to color the text red. I should sometime see how that is done. (Being able to doubleclick on an item and have IDLE open an edit window at the specified line would be really nice!) -- Terry Jan Reedy From torriem at gmail.com Wed Jan 16 09:20:12 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 16 Jan 2013 07:20:12 -0700 Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: <50F6B71C.6080008@gmail.com> On 01/15/2013 10:59 PM, Rick Johnson wrote: > Why do i need to see "C:\users\user\documents\python\lib" EVERY time? You're thinking about things from a very windows-centric point of view. There are many cases where as a developer I need to see the full paths. My modules are not always going to be in a common subfolder. Django apps, for example, live in an arbitrary folder, in my case, /var/www/apps on my web server. Sometimes they live in my home projects folder. Django itself lives partly in /usr/lib/python2.7/site-packages and partly in /usr/share/django. Granted most of my errors are going to happen in my own code, which is in /var/www/apps/blah. But occasionally I might uncover a django bug (less likely of course). Seeing the full path is essential for me. As well, runtime errors get logged as the system is serving, and they could come from any of my apps, depending on how bad a programmer I am. Finally, in an ideal world, all runtime errors should be trapped by the program. The end user should never see them. Sure in my django apps things go south from time to time. But typically the trace gets logged to a file, and the end user sees a 503 error, and gives me a call. Ideally of course, the code should recover gracefully and let the user do most of what he wants. Traces are for developers, not users. From steve+comp.lang.python at pearwood.info Wed Jan 16 09:45:47 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2013 14:45:47 GMT Subject: PyWart: Exception error paths far too verbose References: Message-ID: <50f6bd1b$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Jan 2013 21:59:42 -0800, Rick Johnson wrote: > Python needs to trim the path to the source file from which the > exception was caught and only display the relative path starting from > your personal library folder. What personal library folder? > For example. Say your personal library exists in: > > C:\users\user\documents\python\lib I have Python scripts in my home directory: /home/steve/ and in a python subdirectory: /home/steve/python and in site packages: /usr/lib/python2.4/site-packages/ /usr/local/lib/python2.5/site-packages/ /usr/local/lib/python2.6/site-packages/ /usr/local/lib/python2.7/site-packages/ /usr/local/lib/python3.2/site-packages/ /usr/local/lib/python3.3/site-packages/ and to my shame on my Desktop, the bane of my life (can't live with it, can't live without it): /home/steve/Desktop and in my scripts directory: /home/steve/scripts So, which of those directories is my personal library? > Since all directories *BELOW* the directory that holds your personal > Python library are /superfluous/ when posting exceptions to stderr, I think you mean "above". The root is at the top of the directory tree, not the bottom. /a/b/c c is below b, which is below a. > trimming this bloat can really help to make exception messages easier to > read. > > Traceback (most recent call last): > File "...\sound\effects\reverb.py", line XXX, in YYY There is a difference between "less words to read" and "more helpful". Professional programmers do not have the luxury of only working in their comfortable, personal computer. Often they are called in to fix a problem with other people's programs: customers and clients. It would be a real PITA to be working on an unfamiliar program on an unfamiliar system and be faced with a error message like that. *Especially* if you then search for a file reverb.py and get results like: C:\Documents\python\sound\effects\reverb.py C:\users\george\My Documents\sound\effects\reverb.py C:\users\susan\programming\python\lib\sound\effects\reverb.py E:\Temp\sound\effects\reverb.py F:\Development\python\lib\music\sound\effects\reverb.py G:\app-dev\sound\effects\reverb.py Printing the full path is harmless when you already know which directory the file is, because you can skim over the path and just pay attention to the file name. If you don't know which directory the file is in, printing the full path is essential. On the other hand, abbreviating the path gains you practically nothing when you know where the file is, and costs you a lot when you don't. -- Steven From rantingrickjohnson at gmail.com Wed Jan 16 12:32:28 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 16 Jan 2013 09:32:28 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: <50f6bd1b$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50f6bd1b$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58444614-2c49-4aeb-941f-b2092f54c15f@googlegroups.com> On 1-16-2013 8:45 AM Steven D'Aprano wrote: > What personal library folder? The single MONOLITHIC folder you SHOULD be using to contain all your personal modules and scripts! But of course you are not doing this, only professionals are consistent. > I have Python scripts in my home directory: > > /home/steve/ > > and in a python subdirectory: > > /home/steve/python > > and in site packages: > > /usr/lib/python2.4/site-packages/ > /usr/local/lib/python2.5/site-packages/ > /usr/local/lib/python2.6/site-packages/ > /usr/local/lib/python2.7/site-packages/ > /usr/local/lib/python3.2/site-packages/ > /usr/local/lib/python3.3/site-packages/ > > and to my shame on my Desktop, the bane of my life (can't > live with it, can't live without it): > > /home/steve/Desktop > > and in my scripts directory: > > /home/steve/scripts > > So, which of those directories is my personal library? All of these scripts /should have/ been placed under a single directory, and i don't care where that directory is, but they should be under a single directory! ALWAYS! And why the HELL would you place scripts on the desktop? So you can easily double click and run them? *giggles* Steven, have you heard of the new invention called a symbolic link? http://en.wikipedia.org/wiki/Symbolic_link > > Rick said: > > Since all directories *BELOW* the directory that holds > > your personal Python library are /superfluous/ when > > posting exceptions to stderr, > > > I think you mean "above". The root is at the top of the > directory tree, not the bottom. > > > /a/b/c > > c is below b, which is below a. So you understood my statement, however, you felt the need to correct me because i say "toe-mate-toe" and you say "toe-maught-toe"? interesting. > There is a difference between "less words to read" and > "more helpful". Yes, and verbosity does not /always/ equal "more helpful". > Professional programmers do not have the luxury of only > working in their comfortable, personal computer. Often > they are called in to fix a problem with other people's > programs: customers and clients. It would be a real PITA > to be working on an unfamiliar program on an unfamiliar > system and be faced with a error message like that. Another new invention you may not know of are "command line switches" > *Especially* if you then search for a file reverb.py and > get results like: > > C:\Documents\python\sound\effects\reverb.py > C:\users\george\My Documents\sound\effects\reverb.py > C:\users\susan\programming\python\lib\sound\effects\reverb.py > E:\Temp\sound\effects\reverb.py > F:\Development\python\lib\music\sound\effects\reverb.py > G:\app-dev\sound\effects\reverb.py Well. Okay. Lets imagine a user "switched on" the functionality i suggest. Let's also imagine they hired you to fix some problem they are having (a stretch for most of us, i know!). Let's also /imagine/ that Python devs would be dumb enough to create a command line switch to turn something on, but no way to disable it because /somehow/ this command line switch has become persistent (well, at least to your mind). Now /imaging/ all that, let's inspect these paths: > C:\users\george\My Documents\sound\effects\reverb.py > C:\users\susan\programming\python\lib\sound\effects\reverb.py These two are invalid because you can only repair one problem at a time. And if you don't know the username of the person who's problem you are repairing, then you are not fit to repair the problem are you? Next! > E:\Temp\sound\effects\reverb.py Python source files should NEVER be under a temp directory, you can safely ignore this one. > C:\Documents\python\sound\effects\reverb.py > F:\Development\python\lib\music\sound\effects\reverb.py > G:\app-dev\sound\effects\reverb.py If these last three files really exist, and are /actually/ Python scripts, i would suggest charging extra so you could have time to teach this "dev" how to intelligently store files using structure and consistency. > Printing the full path is harmless when you already know > which directory the file is, because you can skim over the > path and just pay attention to the file name. If you don't > know which directory the file is in, printing the full > path is essential. But you will, IF you keep all your python scripts under a single library folder. Actually, my suggested functionality would be a great motivator for lazies like you. > On the other hand, abbreviating the path gains you > practically nothing when you know where the file is, and > costs you a lot when you don't. Actually that is wrong. Because remember, the path, lineno, and containing object exist on the same line. Since paths tend to be long, i find this line is always wrapping and breaking up the block structure of a printed exception message. Traceback (most recent call last): File C:\users\user\documents\python\lib\sound\effects\echo.py, line 1423, in distribute_weights_evenly By shorting paths (ONLY THOSE PATHS THAT LIVE IN A REGISTERED LIBRARY FOLDER), we can maintain printed exception message structure. I would go further and suggest moving the line number and containing object to their own lines. Traceback (most recent call last): File: "...\lib\sound\effects\echo.py" Line: 1423 In: "display_echo_waveform" Trace: ... From rosuav at gmail.com Wed Jan 16 16:21:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Jan 2013 08:21:46 +1100 Subject: PyWart: Exception error paths far too verbose In-Reply-To: <58444614-2c49-4aeb-941f-b2092f54c15f@googlegroups.com> References: <50f6bd1b$0$30003$c3e8da3$5496439d@news.astraweb.com> <58444614-2c49-4aeb-941f-b2092f54c15f@googlegroups.com> Message-ID: On Thu, Jan 17, 2013 at 4:32 AM, Rick Johnson wrote: > On 1-16-2013 8:45 AM Steven D'Aprano wrote: >> What personal library folder? > > The single MONOLITHIC folder you SHOULD be using to contain all your personal modules and scripts! But of course you are not doing this, only professionals are consistent. On the contrary; it's easy to be consistent in clinical conditions, but the Real World is very messy. Just a few reasons for scripts to move around a bit: * A few of the files need to be auto-updated by some remote system, so they're stored in a directory owned by some other user to isolate rsync * Some files come from a package that's managed by an external facility (eg apt-get), so there's no point moving them * Part of the code gets extracted or decrypted on-the-fly from some other source, so they're in /tmp * The most important scripts are in a source-control managed tree You can't rely on a single directory ("folder") containing all the non-system code. If Python were to absolutely *demand* that, then I suppose you could set up a bunch of symlinks (as long as you're on Linux - on Windows, you MIGHT be able to do that), but it wouldn't gain you anything. >> and to my shame on my Desktop, the bane of my life (can't >> live with it, can't live without it): >> >> /home/steve/Desktop > > And why the HELL would you place scripts on the desktop? So you can easily double click and run them? *giggles* Steven, have you heard of the new invention called a symbolic link? Back in the early 1990s, on our OS/2 boxes, I got into the rather useful habit of creating a file called 1. If I want an extension on that, I can call it "1.cmd" for a REXX command, or whatever. If I need two, "2.cmd" comes next. Saves you the trouble of coming up with a name that fits your "standard library", and it keeps showing the thing to you, demanding attention, and asking either to be renamed to something permanent or finished with and deleted. Not all files are for long-term use. Mind you, some temporary names end up surviving. I still have a file called 1 that stores snippets and cool quotes from the MUDs I play, and when I made them web-accessible, I kept the name - http://rosuav.com/1/ - after all, nothing is so permanent as a temporary name. But I digress. > So you understood my statement, however, you felt the need to correct me because i say "toe-mate-toe" and you say "toe-maught-toe"? interesting. This is an argument I've had many times at work. Incorrect use of language SHOULD be corrected, even when it's unambiguous; otherwise, language becomes useless. If your and Steven's disagreement were ignored, then sooner or later an ambiguous situation will arise, and you'll understand different things from the same words. That's dangerous. (And by the way, feel free to point out my own spelling/grammar errors. I'm sure I've made some; one of the fundamental rules of the universe is that it's impossible to nitpick someone else's use of English without making your own mistakes.) >> Professional programmers do not have the luxury of only >> working in their comfortable, personal computer. Often >> they are called in to fix a problem with other people's >> programs: customers and clients. It would be a real PITA >> to be working on an unfamiliar program on an unfamiliar >> system and be faced with a error message like that. > > Another new invention you may not know of are "command line switches" Errors are notoriously hard to replicate. That's why production code has logfiles. There's only one state that matters, and that's the state the system was in when the one-off error occurred. The programmer gets called in, he pulls up the log, he finds a traceback, and gets to work. If that traceback is clear, readable, and carries all the information he needs, it's a ten-minute job; if it's abbreviated and he has to search the whole filesystem to find the files, it's a huge and onerous task. (The middle ground, that he can inspect some environment variable or whatever, isn't too much work, but it's still unnecessary; the traceback could just contain it directly.) > Now /imaging/ all that, let's inspect these paths: (Imagining, but I digress.) > These two are invalid because you can only repair one problem at a time. And if you don't know the username of the person who's problem you are repairing, then you are not fit to repair the problem are you? Next! Since when do usernames relate to people? And since when do you know whose problem you're repairing? Going back to my scenario examples above, the username might actually relate to the rsync source, or it might be a descriptive-only name - for instance, I have a user "content" on one of our servers, and whenever the web site's content gets updated, it's rsync'd up to that user. So most of the files are in /home/content/.../.../... rather than anything relating to a human. >> E:\Temp\sound\effects\reverb.py > > Python source files should NEVER be under a temp directory, you can safely ignore this one. Well, see above. Perfectly plausible justification for executing code from /tmp. >> C:\Documents\python\sound\effects\reverb.py >> F:\Development\python\lib\music\sound\effects\reverb.py >> G:\app-dev\sound\effects\reverb.py > > If these last three files really exist, and are /actually/ Python scripts, i would suggest charging extra so you could have time to teach this "dev" how to intelligently store files using structure and consistency. And how to totally trash his system by not being allowed to have multiple versions of things. And forbid him to use virtualenv, too. Come to think of it, we should all use the Macbook Wheel file system model - never mind about paths, just press both sides of the wheel and get an alphabetized list of all files on your disk. >> Printing the full path is harmless when you already know >> which directory the file is, because you can skim over the >> path and just pay attention to the file name. If you don't >> know which directory the file is in, printing the full >> path is essential. Additionally: When heaps of text is scrolling past you, it's very easy to eyeball it for differences. When most or all of your paths start with the same string, the eye will happily skip over it and find what's important. > Actually that is wrong. Because remember, the path, lineno, and containing object exist on the same line. Since paths tend to be long, i find this line is always wrapping and breaking up the block structure of a printed exception message. A fair point. There are a few solutions to this; one is to abolish the 80-character width limit. When you're working in a log file (rather than directly on a console) this is easy, and you can just scroll horizontally. Another is... > Traceback (most recent call last): > File C:\users\user\documents\python\lib\sound\effects\echo.py, line 1423, in distribute_weights_evenly > > By shorting paths (ONLY THOSE PATHS THAT LIVE IN A REGISTERED LIBRARY FOLDER), we can maintain printed exception message structure. ... by shortening (please keep the 'en', this is an international forum and we need to declare the language correctly - that way, you can talk about 'shortdeing' German paths) the paths themselves. This sounds like a job for a simple filter though, not for a language feature. > I would go further and suggest moving the line number and containing object to their own lines. > > Traceback (most recent call last): > File: "...\lib\sound\effects\echo.py" > Line: 1423 > In: "display_echo_waveform" I disagree. It's much more useful to have the file name and line, at least, together; but what might be useful would be to go for a more compact notation: C:\users\user\documents\python\lib\sound\effects\echo.py:1423: display_echo_waveform Trace.... This is a standard that many tools emit/recognize, and it's more compact than showing "File" and "Line" in words. That might squidge your traceback under the eighty-character limit. But whatever is done, it's much easier to keep the file and line together; tools can more easily work with it that way and smoothly take you to the appropriate line in your editor, or whatever. Move the function name off, if you need to, or just let it wrap. (That's why I put it at the end.) ChrisA From wuwei23 at gmail.com Wed Jan 16 19:33:29 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 16 Jan 2013 16:33:29 -0800 (PST) Subject: PyWart: Exception error paths far too verbose References: <50f6bd1b$0$30003$c3e8da3$5496439d@news.astraweb.com> <58444614-2c49-4aeb-941f-b2092f54c15f@googlegroups.com> Message-ID: On Jan 17, 3:32?am, Rick Johnson wrote: > On 1-16-2013 8:45 AM Steven D'Aprano wrote: > > > What personal library folder? > > The single MONOLITHIC folder you SHOULD be using to contain all your > personal modules and scripts! But of course you are not doing this, > only professionals are consistent. And here you reveal you have no idea whatsoever of what "professional" programmers do. In my workplace, we are each working on multiple projects simultaneously, which will often require different versions of the same libraries. How do I shove 2 versions of the same Python library into this monolithic folder? Since you're so fond of absolute declarations that will benefit the Python community, here's on for you: I've seen many times people responding to Rick as if he held legitimate opinions and I believe I should define the situations in which you should and shouldn't listen to him. Is he talking about Tkinter? If not, he's talking garbage. If so, *and* he's including code examples, then assess what he's saying carefully and just ignore any pointless rhetoric. He has NO suggestions that would improve Python as a whole because he's coming from a place of theoretical-point-scoring over *pragmatic and tested change*. If he was so keen on these suggestions of his, there are a myriad of ways in which he could contribute back - patches, pypi libraries, code samples - rather than rant and rant and *rant* without producing anything. No one is going to redefine the entire language of computer science on the say so of one annoying idiot. From rantingrickjohnson at gmail.com Wed Jan 16 11:31:24 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 16 Jan 2013 08:31:24 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: On Wednesday, January 16, 2013 8:20:12 AM UTC-6, Michael Torrie wrote: > On 01/15/2013 10:59 PM, Rick Johnson wrote: > > Why do i need to see "C:\users\user\documents\python\lib" EVERY time? > > You're thinking about things from a very windows-centric point of view. How are file paths or directories a windows _only_ point of view. Last time i checked, the other "big two" supported such features. > There are many cases where as a developer I need to see the full paths. Yes i agree, but not if those files exist in you dev library. > My modules are not always going to be in a common subfolder. Well they should be, however, there are a few valid exceptions. > Django > apps, for example, live in an arbitrary folder, in my case, > /var/www/apps on my web server. And a web server would be a valid exception -- granted that the web sever is NOT your actual library folder, if it were the path could be shortened. > Sometimes they live in my home projects > folder. Django itself lives partly in /usr/lib/python2.7/site-packages > and partly in /usr/share/django. Granted most of my errors are going to > happen in my own code, which is in /var/www/apps/blah. But occasionally > I might uncover a django bug (less likely of course). Seeing the full > path is essential for me. And under my plan you WILL see the whole path _IF_ the django folder is NOT your "registered"[1] lib folder. > As well, runtime errors get logged as the > system is serving, and they could come from any of my apps, depending on > how bad a programmer I am. > > Finally, in an ideal world, all runtime errors should be trapped by the > program. The end user should never see them. Who said anything about end users? My comments are for developer ears only. > Traces are for developers, not users. This comment ignores the main point, but i agree. [1] Whether a dev must register a lib folder or use a predetermined folder is yet to be decided. From rantingrickjohnson at gmail.com Wed Jan 16 11:31:24 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 16 Jan 2013 08:31:24 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: On Wednesday, January 16, 2013 8:20:12 AM UTC-6, Michael Torrie wrote: > On 01/15/2013 10:59 PM, Rick Johnson wrote: > > Why do i need to see "C:\users\user\documents\python\lib" EVERY time? > > You're thinking about things from a very windows-centric point of view. How are file paths or directories a windows _only_ point of view. Last time i checked, the other "big two" supported such features. > There are many cases where as a developer I need to see the full paths. Yes i agree, but not if those files exist in you dev library. > My modules are not always going to be in a common subfolder. Well they should be, however, there are a few valid exceptions. > Django > apps, for example, live in an arbitrary folder, in my case, > /var/www/apps on my web server. And a web server would be a valid exception -- granted that the web sever is NOT your actual library folder, if it were the path could be shortened. > Sometimes they live in my home projects > folder. Django itself lives partly in /usr/lib/python2.7/site-packages > and partly in /usr/share/django. Granted most of my errors are going to > happen in my own code, which is in /var/www/apps/blah. But occasionally > I might uncover a django bug (less likely of course). Seeing the full > path is essential for me. And under my plan you WILL see the whole path _IF_ the django folder is NOT your "registered"[1] lib folder. > As well, runtime errors get logged as the > system is serving, and they could come from any of my apps, depending on > how bad a programmer I am. > > Finally, in an ideal world, all runtime errors should be trapped by the > program. The end user should never see them. Who said anything about end users? My comments are for developer ears only. > Traces are for developers, not users. This comment ignores the main point, but i agree. [1] Whether a dev must register a lib folder or use a predetermined folder is yet to be decided. From rantingrickjohnson at gmail.com Wed Jan 16 11:43:29 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 16 Jan 2013 08:43:29 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: <85ec4ecd-4d28-4c3e-980f-d7668e059eed@googlegroups.com> On Wednesday, January 16, 2013 3:53:55 AM UTC-6, Terry Reedy wrote: > I agree with the complaint and you may have the germ of a good idea. The > problem is that for some tracebacks, paths jump all over the place > rather than having a common prefix. Dealing with this might require > preprocessing the entire traceback before iterating and printing each item. Your comment is too ambiguous for me to comprehend... Are you referring to the case where devs keep python modules and scripts in /many/ places on their disc, or something else? > Are you are aware of > ''' > sys.excepthook(type, value, traceback) > > This function prints out a given traceback and exception to sys.stderr. > > [...] > > This is how some apps and environments customize exception reporting > (and logging). I believe some people also put a replacement in their > site module. I'll check it out. If the path can be trimmed there, then the problem is solved for me, but what about everyone else? > What you want to change is format_tb_item (possibly, as I said, after > scanning traceback before the print loop). If you come up with something > nice, I would like to see it. If i do i will post it. First i need to respond to someone who always needs me to explain every detail because he has trouble comprehending even the simplest of ideas. *cough*even*cough*prano > The only thing special that IDLE does now is to color the text red. I > should sometime see how that is done. (Being able to doubleclick on an > item and have IDLE open an edit window at the specified line would be > really nice!) IDLE already has a build in command from the context menu called "go to file/line" that will parse any right-clicked line for file paths and line numbers, then, open that file in a new IDLE editor instance and adjust the view so you can see the lineno in question (typical IDE stuff)... but most devs prefer to use IDEs with less bugs asinine interfaces :-) From rantingrickjohnson at gmail.com Wed Jan 16 11:43:29 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 16 Jan 2013 08:43:29 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: <85ec4ecd-4d28-4c3e-980f-d7668e059eed@googlegroups.com> On Wednesday, January 16, 2013 3:53:55 AM UTC-6, Terry Reedy wrote: > I agree with the complaint and you may have the germ of a good idea. The > problem is that for some tracebacks, paths jump all over the place > rather than having a common prefix. Dealing with this might require > preprocessing the entire traceback before iterating and printing each item. Your comment is too ambiguous for me to comprehend... Are you referring to the case where devs keep python modules and scripts in /many/ places on their disc, or something else? > Are you are aware of > ''' > sys.excepthook(type, value, traceback) > > This function prints out a given traceback and exception to sys.stderr. > > [...] > > This is how some apps and environments customize exception reporting > (and logging). I believe some people also put a replacement in their > site module. I'll check it out. If the path can be trimmed there, then the problem is solved for me, but what about everyone else? > What you want to change is format_tb_item (possibly, as I said, after > scanning traceback before the print loop). If you come up with something > nice, I would like to see it. If i do i will post it. First i need to respond to someone who always needs me to explain every detail because he has trouble comprehending even the simplest of ideas. *cough*even*cough*prano > The only thing special that IDLE does now is to color the text red. I > should sometime see how that is done. (Being able to doubleclick on an > item and have IDLE open an edit window at the specified line would be > really nice!) IDLE already has a build in command from the context menu called "go to file/line" that will parse any right-clicked line for file paths and line numbers, then, open that file in a new IDLE editor instance and adjust the view so you can see the lineno in question (typical IDE stuff)... but most devs prefer to use IDEs with less bugs asinine interfaces :-) From tjreedy at udel.edu Wed Jan 16 19:51:31 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Jan 2013 19:51:31 -0500 Subject: PyWart: Exception error paths far too verbose In-Reply-To: <85ec4ecd-4d28-4c3e-980f-d7668e059eed@googlegroups.com> References: <85ec4ecd-4d28-4c3e-980f-d7668e059eed@googlegroups.com> Message-ID: On 1/16/2013 11:43 AM, Rick Johnson wrote: > On Wednesday, January 16, 2013 3:53:55 AM UTC-6, Terry Reedy wrote: > >> I agree with the complaint and you may have the germ of a good >> idea. The problem is that for some tracebacks, paths jump all over >> the place rather than having a common prefix. Dealing with this >> might require preprocessing the entire traceback before iterating >> and printing each item. > > Your comment is too ambiguous for me to comprehend... Are you > referring to the case where devs keep python modules and scripts in > /many/ places on their disc, or something else? I missed in your original post that you only want one consistent personal library path abbreviated, leaving everything else alone. So the above is not applicable. And a custom excepthook very easy. How should the traceback mechanism will know what that path is? To answer the objection about having to search the whole disk when on a 'foreign' machine, the top line of the traceback could be Traceback: ... = C:/users/me/pystuff >> The only thing special that IDLE does now is to color the text red. >> I should sometime see how that is done. (Being able to doubleclick >> on an item and have IDLE open an edit window at the specified line >> would be really nice!) > > IDLE already has a build in command from the context menu called "go > to file/line" that will parse any right-clicked line for file paths > and line numbers, then, open that file in a new IDLE editor instance > and adjust the view so you can see the lineno in question (typical > IDE stuff)... I never noticed that. Thanks for the exchange of information. -- Terry Jan Reedy From rantingrickjohnson at gmail.com Fri Jan 18 19:34:56 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 18 Jan 2013 16:34:56 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: <85ec4ecd-4d28-4c3e-980f-d7668e059eed@googlegroups.com> Message-ID: <13b05d8b-b5fa-42ab-b00b-8a9be1ff4f1e@googlegroups.com> On Wednesday, January 16, 2013 6:51:31 PM UTC-6, Terry Reedy wrote: > I missed in your original post that you only want one consistent > personal library path abbreviated, leaving everything else alone. So the > above is not applicable. And a custom excepthook very easy. > > How should the traceback mechanism -will- know what that path is? Well, the jury is still deliberating on the specifics, however, as for myself, i would sway more to the /explicit/ side. A few possibilities include: * A configuration file. Python already checks the current directory for ".pth" files, which it then reads and adds the contained paths to sys.path -- most folks stopped typing commands OVER and OVER on the commandline many years ago. But to each his own. * A runtime command or keyword placed in a script (YUCK!) * A commandline switch (only good for members of the python historical society.) From rantingrickjohnson at gmail.com Fri Jan 18 19:34:56 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 18 Jan 2013 16:34:56 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: <85ec4ecd-4d28-4c3e-980f-d7668e059eed@googlegroups.com> Message-ID: <13b05d8b-b5fa-42ab-b00b-8a9be1ff4f1e@googlegroups.com> On Wednesday, January 16, 2013 6:51:31 PM UTC-6, Terry Reedy wrote: > I missed in your original post that you only want one consistent > personal library path abbreviated, leaving everything else alone. So the > above is not applicable. And a custom excepthook very easy. > > How should the traceback mechanism -will- know what that path is? Well, the jury is still deliberating on the specifics, however, as for myself, i would sway more to the /explicit/ side. A few possibilities include: * A configuration file. Python already checks the current directory for ".pth" files, which it then reads and adds the contained paths to sys.path -- most folks stopped typing commands OVER and OVER on the commandline many years ago. But to each his own. * A runtime command or keyword placed in a script (YUCK!) * A commandline switch (only good for members of the python historical society.) From maniandram01 at gmail.com Sat Jan 19 22:15:55 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 19 Jan 2013 19:15:55 -0800 (PST) Subject: PyWart: Exception error paths far too verbose In-Reply-To: References: Message-ID: <347f554e-bc8e-47de-8bba-015e19734e38@googlegroups.com> On Wednesday, 16 January 2013 15:23:55 UTC+5:30, Terry Reedy wrote: > On 1/16/2013 12:59 AM, Rick Johnson wrote: > > > > > > Python needs to trim the path to the source file from which the > > > exception was caught and only display the relative path starting from > > > your personal library folder. > > > > > > For example. Say your personal library exists in: > > > > > > C:\users\user\documents\python\lib > > > > > > ...then there is no need to post THAT portion of the path EVERY > > > STINKING TIME! For instance, let's say a script at: > > > > > > C:\users\user\documents\python\lib\sound\effects\echo.py > > > > > > ...throws an error. What will we see? > > > > > > Traceback (most recent call last): File > > > "C:\users\user\documents\python\lib\sound\effects\echo.py", line N, > > > in BLAH > > > > > > Why do i need to see "C:\users\user\documents\python\lib" EVERY > > > time? > > > > > > Since all directories *BELOW* the directory that holds your personal > > > Python library are /superfluous/ when posting exceptions to stderr, > > > trimming this bloat can really help to make exception messages easier > > > to read. > > > > > > Traceback (most recent call last): File > > > "...\sound\effects\reverb.py", line XXX, in YYY > > > > I agree with the complaint and you may have the germ of a good idea. The > > problem is that for some tracebacks, paths jump all over the place > > rather than having a common prefix. Dealing with this might require > > preprocessing the entire traceback before iterating and printing each item. > > > > Are you are aware of > > ''' > > sys.excepthook(type, value, traceback) > > > > This function prints out a given traceback and exception to sys.stderr. > > > > When an exception is raised and uncaught, the interpreter calls > > sys.excepthook with three arguments, the exception class, exception > > instance, and a traceback object. In an interactive session this happens > > just before control is returned to the prompt; in a Python program this > > happens just before the program exits. The handling of such top-level > > exceptions can be customized by assigning another three-argument > > function to sys.excepthook. > > ''' > > This is how some apps and environments customize exception reporting > > (and logging). I believe some people also put a replacement in their > > site module. > > > > >>> import sys; sys.excepthook > > > > > > I expect the default, excepthook, is something like > > > > def excepthook(typ, value, traceback): > > print('Traceback (most recent call last):', file=sys.stderr) > > for item in traceback: > > print(format_tb_item(item), file=sys.stderr) > > print('{}: {}'.format(typ.__name__, value), file=sys.stderr) > > > > (or the equivalent with sys.stderr.write) > > > > What you want to change is format_tb_item (possibly, as I said, after > > scanning traceback before the print loop). If you come up with something > > nice, I would like to see it. > > > > The only thing special that IDLE does now is to color the text red. I > > should sometime see how that is done. (Being able to doubleclick on an > > item and have IDLE open an edit window at the specified line would be > > really nice!) > > > > -- > > Terry Jan Reedy Right-click the file in the traceback and there is an "Go to file/line" option. From steve+comp.lang.python at pearwood.info Sun Jan 20 01:08:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Jan 2013 06:08:20 GMT Subject: PyWart: Exception error paths far too verbose References: <347f554e-bc8e-47de-8bba-015e19734e38@googlegroups.com> Message-ID: <50fb89d4$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 19 Jan 2013 19:15:55 -0800, Ramchandra Apte wrote: [snip dozens of irrelevant quoted lines] > Right-click the file in the traceback and there is an "Go to file/line" > option. Please trim your replies so that the reader doesn't have to scroll through page after page of irrelevant text they've already read. Thank you. -- Steven From tjreedy at udel.edu Sun Jan 20 11:08:18 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 Jan 2013 11:08:18 -0500 Subject: PyWart: Exception error paths far too verbose In-Reply-To: <50fb89d4$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <347f554e-bc8e-47de-8bba-015e19734e38@googlegroups.com> <50fb89d4$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/20/2013 1:08 AM, Steven D'Aprano wrote: > On Sat, 19 Jan 2013 19:15:55 -0800, Ramchandra Apte wrote: > > [snip dozens of irrelevant quoted lines] >> Right-click the file in the traceback and there is an "Go to file/line" >> option. > > > Please trim your replies so that the reader doesn't have to scroll > through page after page of irrelevant text they've already read. > > Thank you. Quite aside from the fact that there already was a quick reply telling me the same thing. A properly threaded reader would have placed it just below my post. -- Terry Jan Reedy From levinie001 at gmail.com Wed Jan 16 04:57:49 2013 From: levinie001 at gmail.com (Levi Nie) Date: Wed, 16 Jan 2013 17:57:49 +0800 Subject: Python-list Digest, Vol 112, Issue 114 In-Reply-To: References: Message-ID: TKS, Ulrich. I finally write some back (self.transport.write()), and shutdown the connections. > > ---------- ????? ---------- > From: Ulrich Eckhardt > To: python-list at python.org > Cc: > Date: Tue, 15 Jan 2013 13:46:52 +0100 > Subject: Re: interrupt the file sending if the file size over the > quota...some errors here... > Am 15.01.2013 10:46, schrieb Levi Nie: > >> i want to interrupt the file sending. but i can't change the client. so i >> need change the server. >> All things go well, but the message i wanna response seem not work. >> > > Ahem, what? It doesn't work, so does it sit on the couch all day? > > > is the self.transport.loseConnection(**) (the last line) blocking the >> messages? >> in fact, i work on Cumulus(nimbus project) which based on twisted. And i >> use s3cmd as the client. >> > > I'm wondering if questions concerning twisted don't have a better forum. > In any case, I can only comment on the general approach. For that, there > are two things you can do: > > 1. When receiving the the request header, you have a content length. If > that exceeds the allowed amount, shutdown() receiving and send an according > HTTP response before closing the connection. > 2. If the data exceeds the amount advertised by the content length, close > the connection and discard the request. If you want to be nice, send an > according response before closing, but I personally wouldn't go to that > effort for broken HTTP clients. > > Concerning the question why your client hangs, it could also be the > sending. If you try to send something before receiving the full request, > client and server could enter a deadlock where each side waits for the > other to receive some data. For that reason, you should shutdown() > receiving in such a case. > > HTH > > Uli > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From p at gmane.2013.dobrogost.net Wed Jan 16 06:46:10 2013 From: p at gmane.2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 16 Jan 2013 11:46:10 +0000 (UTC) Subject: DLLs folder on Windows Message-ID: Hi! I'm curious how dlls from the DLLs folder on Windows are being loaded? As they are not placed in the same folder where python.exe resides I guess they must be loaded by giving the path explicitly but I'm not sure. I'm asking because there's no DLLs folder being created when creating virtualenv and I suspect it should be. This is a followup to my question "Why doesn't virtualenv create DLLs folder?" (http://stackoverflow.com/q/6657541/95735) and to the virtualenv's issue 87 - "Problems creating virtualenv on Windows when Python is not installed for all users." (https://github.com/pypa/virtualenv/issues/87). Regards, Piotr Dobrogost ps. This was originaly posted to python-devel see http://thread.gmane.org/gmane.comp.python.devel/136821 From nikos.gr33k at gmail.com Wed Jan 16 08:51:56 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 16 Jan 2013 05:51:56 -0800 (PST) Subject: Forcing Python to detect DocumentRoot Message-ID: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html f = open( '../' + page ) How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? From joel.goldstick at gmail.com Wed Jan 16 09:01:07 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 16 Jan 2013 09:01:07 -0500 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus wrote: > When trying to open an html template within Python script i use a relative > path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect > DocumentRoot by itself? > -- > http://mail.python.org/mailman/listinfo/python-list > I don't think I understand your question. But, I think your answer is here: http://docs.python.org/2/library/os.path.html -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Wed Jan 16 09:32:42 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 16 Jan 2013 06:32:42 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: ?? ???????, 16 ?????????? 2013 4:01:07 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus wrote: > > When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html > > > > > f = open( '../' + page ) > > > > How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > I don't think I understand your question.? But, I think your answer is here: Nowhere that page says something about python detecting documentroot directory (www or public_html) that is. From joel.goldstick at gmail.com Wed Jan 16 09:39:43 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 16 Jan 2013 09:39:43 -0500 Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: On Wed, Jan 16, 2013 at 9:32 AM, Ferrous Cranus wrote: > ?? ???????, 16 ?????????? 2013 4:01:07 ?.?. UTC+2, ? ??????? Joel > Goldstick ??????: > > On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus > wrote: > > > > When trying to open an html template within Python script i use a > relative path to say go one folder back and open index.html > > > > > > > > > > f = open( '../' + page ) > > > > > > > > How to say the same thing in an absolute way by forcing Python to detect > DocumentRoot by itself? > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > I don't think I understand your question. But, I think your answer is > here: > > Nowhere that page says something about python detecting documentroot > directory (www or public_html) that is. > What is DocumentRoot? This is a convention, not something a language would 'know' about > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Wed Jan 16 09:32:42 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 16 Jan 2013 06:32:42 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: ?? ???????, 16 ?????????? 2013 4:01:07 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus wrote: > > When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html > > > > > f = open( '../' + page ) > > > > How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > I don't think I understand your question.? But, I think your answer is here: Nowhere that page says something about python detecting documentroot directory (www or public_html) that is. From nikos.gr33k at gmail.com Thu Jan 17 04:03:42 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 17 Jan 2013 01:03:42 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: Document Root for me is /home/nikos/public_html Is where Apache store the user www files. How to tell it my using a variable? From rustompmody at gmail.com Thu Jan 17 08:51:30 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 17 Jan 2013 05:51:30 -0800 (PST) Subject: Forcing Python to detect DocumentRoot References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: On Jan 16, 6:51?pm, Ferrous Cranus wrote: > When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? Is this what you want? import os os.getcwd() From roy at panix.com Thu Jan 17 09:09:02 2013 From: roy at panix.com (Roy Smith) Date: Thu, 17 Jan 2013 09:09:02 -0500 Subject: Forcing Python to detect DocumentRoot References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca at googlegroups.com>, Ferrous Cranus wrote: > When trying to open an html template within Python script i use a relative > path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect > DocumentRoot by itself? Can you give us more details of what you're doing. Is there some web framework you're using? Can you post some code that's not working for you? From joel.goldstick at gmail.com Thu Jan 17 10:14:19 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 17 Jan 2013 10:14:19 -0500 Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith wrote: > In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca at googlegroups.com>, > Ferrous Cranus wrote: > > > When trying to open an html template within Python script i use a > relative > > path to say go one folder back and open index.html > > > > f = open( '../' + page ) > > > > How to say the same thing in an absolute way by forcing Python to detect > > DocumentRoot by itself? > > Can you give us more details of what you're doing. Is there some web > framework you're using? Can you post some code that's not working for > you? > -- > http://mail.python.org/mailman/listinfo/python-list > Import os Then read os.environ['HOME'] This will give you the home directory of the user. in my case: >>> os.environ['HOME'] '/home/jcg' >>> This is probably linux only, but that seems to be the environment you are working in . -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Fri Jan 18 08:02:23 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 05:02:23 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> ?? ??????, 17 ?????????? 2013 5:14:19 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith wrote: > > In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca at googlegroups.com>, > > > > ?Ferrous Cranus wrote: > > > > > When trying to open an html template within Python script i use a relative > > > path to say go one folder back and open index.html > > > > > > f = open( '../' + page ) > > > > > > How to say the same thing in an absolute way by forcing Python to detect > > > DocumentRoot by itself? > > > > Can you give us more details of what you're doing. ?Is there some web > > framework you're using? ?Can you post some code that's not working for > > you? > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Import os > > Then read os.environ['HOME'] > > > This will give you the home directory of the user.? in my case: > > > >>> os.environ['HOME'] > '/home/jcg' > >>> > > > This is probably linux only, but that seems to be the environment you are working in . Yes my Python scripts exist in a linux web host. os.environ['HOME'] will indeed give the home directory of the user. to me /home/nikos/ but i want a variable to point to /home/nikos/public_html whice is called DocumentRoot. is there avariable for that? i can't seem to find any... From nikos.gr33k at gmail.com Fri Jan 18 08:02:23 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 05:02:23 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> ?? ??????, 17 ?????????? 2013 5:14:19 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith wrote: > > In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca at googlegroups.com>, > > > > ?Ferrous Cranus wrote: > > > > > When trying to open an html template within Python script i use a relative > > > path to say go one folder back and open index.html > > > > > > f = open( '../' + page ) > > > > > > How to say the same thing in an absolute way by forcing Python to detect > > > DocumentRoot by itself? > > > > Can you give us more details of what you're doing. ?Is there some web > > framework you're using? ?Can you post some code that's not working for > > you? > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Import os > > Then read os.environ['HOME'] > > > This will give you the home directory of the user.? in my case: > > > >>> os.environ['HOME'] > '/home/jcg' > >>> > > > This is probably linux only, but that seems to be the environment you are working in . Yes my Python scripts exist in a linux web host. os.environ['HOME'] will indeed give the home directory of the user. to me /home/nikos/ but i want a variable to point to /home/nikos/public_html whice is called DocumentRoot. is there avariable for that? i can't seem to find any... From joel.goldstick at gmail.com Fri Jan 18 08:28:10 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 18 Jan 2013 08:28:10 -0500 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: On Fri, Jan 18, 2013 at 8:02 AM, Ferrous Cranus wrote: > ?? ??????, 17 ?????????? 2013 5:14:19 ?.?. UTC+2, ? ??????? Joel Goldstick > ??????: > > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith wrote: > > > > In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca at googlegroups.com>, > > > > > > > > Ferrous Cranus wrote: > > > > > > > > > When trying to open an html template within Python script i use a > relative > > > > > path to say go one folder back and open index.html > > > > > > > > > > f = open( '../' + page ) > > > > > > > > > > How to say the same thing in an absolute way by forcing Python to > detect > > > > > DocumentRoot by itself? > > > > > > > > Can you give us more details of what you're doing. Is there some web > > > > framework you're using? Can you post some code that's not working for > > > > you? > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > Import os > > > > Then read os.environ['HOME'] > > > > > > This will give you the home directory of the user. in my case: > > > > > > >>> os.environ['HOME'] > > '/home/jcg' > > >>> > > > > > > This is probably linux only, but that seems to be the environment you > are working in . > > Yes my Python scripts exist in a linux web host. > > os.environ['HOME'] will indeed give the home directory of the user. > > to me /home/nikos/ > > but i want a variable to point to > > /home/nikos/public_html whice is called DocumentRoot. > > is there avariable for that? i can't seem to find any... > -- > http://mail.python.org/mailman/listinfo/python-list > DocumentRoot = os.environ['HOME'] + 'public_html' -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrick.brown at gmail.com Fri Jan 18 08:41:47 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 18 Jan 2013 08:41:47 -0500 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: On Friday, January 18, 2013, Ferrous Cranus wrote: > ?? ??????, 17 ?????????? 2013 5:14:19 ?.?. UTC+2, ? ??????? Joel Goldstick > ??????: > > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith > > wrote: > > > > In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca at googlegroups.com > >, > > > > > > > > Ferrous Cranus > wrote: > > > > > > > > > When trying to open an html template within Python script i use a > relative > > > > > path to say go one folder back and open index.html > > > > > > > > > > f = open( '../' + page ) > > > > > > > > > > How to say the same thing in an absolute way by forcing Python to > detect > > > > > DocumentRoot by itself? > > $ export DOCUMENT_ROOT=${HOME}/public _html Then from python os.environ['DOCUMENT_ROOT'] will have the relative path. I hope this helps. > > > > > > Can you give us more details of what you're doing. Is there some web > > > > framework you're using? Can you post some code that's not working for > > > > you? > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > Import os > > > > Then read os.environ['HOME'] > > > > > > This will give you the home directory of the user. in my case: > > > > > > >>> os.environ['HOME'] > > '/home/jcg' > > >>> > > > > > > This is probably linux only, but that seems to be the environment you > are working in . > > Yes my Python scripts exist in a linux web host. > > os.environ['HOME'] will indeed give the home directory of the user. > > to me /home/nikos/ > > but i want a variable to point to > > /home/nikos/public_html whice is called DocumentRoot. > > is there avariable for that? i can't seem to find any... > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Fri Jan 18 13:58:54 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 10:58:54 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> ?? ?????????, 18 ?????????? 2013 3:28:10 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > DocumentRoot = os.environ['HOME'] + 'public_html' Yes, iam using this and it works. One last thing: my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ How python is able to run the following statement? f = open( '/home/nikos/public_html/' + page ) which is clearly levels up of addon domain's DocumentRoot? From nikos.gr33k at gmail.com Fri Jan 18 13:58:54 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 10:58:54 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> ?? ?????????, 18 ?????????? 2013 3:28:10 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > DocumentRoot = os.environ['HOME'] + 'public_html' Yes, iam using this and it works. One last thing: my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ How python is able to run the following statement? f = open( '/home/nikos/public_html/' + page ) which is clearly levels up of addon domain's DocumentRoot? From joel.goldstick at gmail.com Fri Jan 18 14:11:43 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 18 Jan 2013 14:11:43 -0500 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: On Fri, Jan 18, 2013 at 1:58 PM, Ferrous Cranus wrote: > ?? ?????????, 18 ?????????? 2013 3:28:10 ?.?. UTC+2, ? ??????? Joel > Goldstick ??????: > > > DocumentRoot = os.environ['HOME'] + 'public_html' > > Yes, iam using this and it works. > One last thing: > > my python script file is located at > /home/nikos/public_html/addon_domain/cgi-bin/ > > How python is able to run the following statement? > > f = open( '/home/nikos/public_html/' + page ) > > which is clearly levels up of addon domain's DocumentRoot? > -- > http://mail.python.org/mailman/listinfo/python-list > My website experience with python has been using mod wsgi (and django), not cgi. I can't help you with how to configure cgi, but googling python cgi might help -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Jan 18 16:34:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jan 2013 08:34:05 +1100 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: On Sat, Jan 19, 2013 at 5:58 AM, Ferrous Cranus wrote: > ?? ?????????, 18 ?????????? 2013 3:28:10 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > >> DocumentRoot = os.environ['HOME'] + 'public_html' > > Yes, iam using this and it works. > One last thing: > > my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ > > How python is able to run the following statement? > > f = open( '/home/nikos/public_html/' + page ) > > which is clearly levels up of addon domain's DocumentRoot? Time to take a step backward and figure out what you're really trying to accomplish. I think, after gazing idly into my crystal ball for a while, that you actually want to chroot your script - instead of seeing "/home/nikos/public_html/" it would see just "/", and then it can't access anything outside of that. ChrisA From nikos.gr33k at gmail.com Sat Jan 19 03:01:29 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 19 Jan 2013 00:01:29 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: ?? ?????????, 18 ?????????? 2013 11:34:05 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sat, Jan 19, 2013 at 5:58 AM, Ferrous Cranus wrote: > > > ?? ?????????, 18 ?????????? 2013 3:28:10 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > > > > > >> DocumentRoot = os.environ['HOME'] + 'public_html' > > > > > > Yes, iam using this and it works. > > > One last thing: > > > > > > my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ > > > > > > How python is able to run the following statement? > > > > > > f = open( '/home/nikos/public_html/' + page ) > > > > > > which is clearly levels up of addon domain's DocumentRoot? > > > > Time to take a step backward and figure out what you're really trying > > to accomplish. I think, after gazing idly into my crystal ball for a > > while, that you actually want to chroot your script - instead of > > seeing "/home/nikos/public_html/" it would see just "/", and then it > > can't access anything outside of that. > > > > ChrisA This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root ======================================== # render html template and print it data = f.read() counter = '''
''' % hits[0] ======================================== While from within the same counter.py file # open html template file f = open( '/home/nikos/public_html/test.txt' ) opens OK the page file which is also past addons domain's document root Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct? From nikos.gr33k at gmail.com Sat Jan 19 03:01:29 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 19 Jan 2013 00:01:29 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: ?? ?????????, 18 ?????????? 2013 11:34:05 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sat, Jan 19, 2013 at 5:58 AM, Ferrous Cranus wrote: > > > ?? ?????????, 18 ?????????? 2013 3:28:10 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > > > > > >> DocumentRoot = os.environ['HOME'] + 'public_html' > > > > > > Yes, iam using this and it works. > > > One last thing: > > > > > > my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ > > > > > > How python is able to run the following statement? > > > > > > f = open( '/home/nikos/public_html/' + page ) > > > > > > which is clearly levels up of addon domain's DocumentRoot? > > > > Time to take a step backward and figure out what you're really trying > > to accomplish. I think, after gazing idly into my crystal ball for a > > while, that you actually want to chroot your script - instead of > > seeing "/home/nikos/public_html/" it would see just "/", and then it > > can't access anything outside of that. > > > > ChrisA This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root ======================================== # render html template and print it data = f.read() counter = '''
??????? ?????????? %d
''' % hits[0] ======================================== While from within the same counter.py file # open html template file f = open( '/home/nikos/public_html/test.txt' ) opens OK the page file which is also past addons domain's document root Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct? From torriem at gmail.com Mon Jan 21 13:49:48 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 21 Jan 2013 11:49:48 -0700 Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: <50FD8DCC.1030205@gmail.com> On 01/19/2013 01:01 AM, Ferrous Cranus wrote: > # render html template and print it data = f.read() counter = > '''
src="/data/images/mail.png"> > >
??????? ?????????? %d
''' % hits[0] > ======================================== > > While from within the same counter.py file > > # open html template file f = open( > '/home/nikos/public_html/test.txt' ) > > opens OK the page file which is also past addons domain's document > root > > Can you help counter.py to load the image? Why does it fail to load > it? Python can have access to ANY filesystempath , no matter from > what folder counter.py script runs from. Correct? No I can't because counter.py doesn't "load the image." The browser does. If the image fails to load it is because the apache web server cannot find it. In other words your image src url is bad. It has nothing to do with python. Python is only spitting out html code. That's it. Image loading is done by apache on behalf of a request from the web browser. Since the url is a direct url to a file, there is no CGI that runs. I understand that you have a difficulty understanding the relationship between the browser, the web server, and the cgi script. The process goes like this: - browser requests the url, which happens to be the CGI script, counter.py. - web server runs counter.py returns html code to the browser. - browser parses html code, renders it, and requests any images that the html code references. - Web server tries to locate the image based on its own rules and config, and serves it if possible, otherwise, returns error 404. So you simply have the image url wrong. apache is not mapping /data to where you think it is. You have to either fix this in apache's configs, or determine where the image really is in apache's url space, and change the cgi to output the correct html. Your problem isn't a python one at all; it's an apache problem. From piet at vanoostrum.org Sat Jan 19 15:01:15 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 19 Jan 2013 21:01:15 +0100 Subject: Forcing Python to detect DocumentRoot References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: Ferrous Cranus writes: > This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root > > ======================================== > # render html template and print it > data = f.read() > counter = '''
> > >
> ??????? ?????????? %d
> > ''' % hits[0] > ======================================== > > While from within the same counter.py file > > # open html template file > f = open( '/home/nikos/public_html/test.txt' ) > > opens OK the page file which is also past addons domain's document root > > Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct? That piece of code is not opening the image file. It just issues the URL for the image file. The file will then be loaded by the browser in a new request. The image should be at /home/nikos/public_html/data/images/mail.png P.S. I don't understand what you mean by "addon domain". -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nikos.gr33k at gmail.com Mon Jan 21 01:25:19 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 20 Jan 2013 22:25:19 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: ?? ???????, 19 ?????????? 2013 10:01:15 ?.?. UTC+2, ? ??????? Piet van Oostrum ??????: > Ferrous Cranus writes: > > > > > This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root > > > > > > ======================================== > > > # render html template and print it > > > data = f.read() > > > counter = '''
> > > > > > > > >
??????? ?????????? %d
> > > > > > ''' % hits[0] > > > ======================================== > > > > > > > > While from within the same counter.py file > > > > > > # open html template file > > > f = open( '/home/nikos/public_html/test.txt' ) > > > > > > opens OK the page file which is also past addons domain's document root > > > > > > Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct? > > > > That piece of code is not opening the image file. It just issues the URL > > for the image file. The file will then be loaded by the browser in a new > > request. The image should be at > > /home/nikos/public_html/data/images/mail.png Yes the image is this and is located at that folder. /home/nikos/public_html/cgi-bin/counter.py that has embedded this line: can open the file normally as seen if you visit http://superhost.gr > P.S. I don't understand what you mean by "addon domain". While /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py that has also embedded this line: cannnot open the file normally. And the questions iw WHY since python script can open ANY filesystempath file the user has access too. From d at davea.name Mon Jan 21 07:33:22 2013 From: d at davea.name (Dave Angel) Date: Mon, 21 Jan 2013 07:33:22 -0500 Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: <50FD3592.1010804@davea.name> On 01/21/2013 01:25 AM, Ferrous Cranus wrote: > ?? ???????, 19 ?????????? 2013 10:01:15 ?.?. UTC+2, ? ??????? Piet van Oostrum ??????: >> Ferrous Cranus writes: > While > > /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py > > that has also embedded this line: > > > > cannnot open the file normally. > > And the questions iw WHY since python script can open ANY filesystempath > file the user has access too. > As Piet has said,Python is NOT opening the file mail.png. When the html is sent to the browser, and the browser requests that image file, it's the server itself who figures out where the actual file is. Python isn't involved at all. -- DaveA From nikos.gr33k at gmail.com Mon Jan 21 09:55:32 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 06:55:32 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: <52e3e53e-f2fe-4e0f-a11d-1c6d52f39c36@googlegroups.com> ?? ???????, 21 ?????????? 2013 2:33:22 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/21/2013 01:25 AM, Ferrous Cranus wrote: > > > ?? ???????, 19 ?????????? 2013 10:01:15 ?.?. UTC+2, ? ??????? Piet van Oostrum ??????: > > >> Ferrous Cranus writes: > > > > > While > > > > > > /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py > > > > > > that has also embedded this line: > > > > > > > > > > > > cannnot open the file normally. > > > > > > And the questions iw WHY since python script can open ANY filesystempath > > > file the user has access too. > > > > > > > As Piet has said,Python is NOT opening the file mail.png. When the html > > is sent to the browser, and the browser requests that image file, it's > > the server itself who figures out where the actual file is. Python > > isn't involved at all. > > > > -- > > DaveA Yes Dave so we need to remove since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file. From nikos.gr33k at gmail.com Mon Jan 21 09:55:32 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 06:55:32 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> Message-ID: <52e3e53e-f2fe-4e0f-a11d-1c6d52f39c36@googlegroups.com> ?? ???????, 21 ?????????? 2013 2:33:22 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/21/2013 01:25 AM, Ferrous Cranus wrote: > > > ?? ???????, 19 ?????????? 2013 10:01:15 ?.?. UTC+2, ? ??????? Piet van Oostrum ??????: > > >> Ferrous Cranus writes: > > > > > While > > > > > > /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py > > > > > > that has also embedded this line: > > > > > > > > > > > > cannnot open the file normally. > > > > > > And the questions iw WHY since python script can open ANY filesystempath > > > file the user has access too. > > > > > > > As Piet has said,Python is NOT opening the file mail.png. When the html > > is sent to the browser, and the browser requests that image file, it's > > the server itself who figures out where the actual file is. Python > > isn't involved at all. > > > > -- > > DaveA Yes Dave so we need to remove since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file. From torriem at gmail.com Mon Jan 21 13:42:06 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 21 Jan 2013 11:42:06 -0700 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <52e3e53e-f2fe-4e0f-a11d-1c6d52f39c36@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com> <52e3e53e-f2fe-4e0f-a11d-1c6d52f39c36@googlegroups.com> Message-ID: <50FD8BFE.3010106@gmail.com> On 01/21/2013 07:55 AM, Ferrous Cranus wrote: > Yes Dave so we need to remove > since the apache cant see to open it and let Python open it which we > know it can because it has access to any system file the user has > access too. What are you trying to accomplish? I don't see how opening the file with python will do anything because as has been said many times on this thread, your python CGI generates html code which the browser then renders. Opening an image file with python will do nothing useful. > So if a python script can open any file the user has access too then > we need a "python way" of opening this file. Still don't understand why you want python to open the image file. What do you want python to do with it? It's running on a web server, so there's no screen for python to display the image too. Technically it is possible to have a script that opens the image and serves it up as a binary stream to the browser using the image content-type header, but it's way more efficient to serve up the file statically. And you'd have to have a proper link in the html code anyway, to refer to your image-serving CGI script. Methinks you're barking up the wrong tree with python opening the image file. From nikos.gr33k at gmail.com Fri Jan 18 15:49:31 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 12:49:31 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: <4f5c4fda-87df-4897-8b0c-13c36d12d918@googlegroups.com> Yes, iam using this and it works. One last thing: my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ How python is able to run the following statement? f = open( '/home/nikos/public_html/' + page ) which is clearly levels up of addon domain's DocumentRoot? From nikos.gr33k at gmail.com Fri Jan 18 15:49:31 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 12:49:31 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: <4f5c4fda-87df-4897-8b0c-13c36d12d918@googlegroups.com> Yes, iam using this and it works. One last thing: my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ How python is able to run the following statement? f = open( '/home/nikos/public_html/' + page ) which is clearly levels up of addon domain's DocumentRoot? From torriem at gmail.com Mon Jan 21 10:46:35 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 21 Jan 2013 08:46:35 -0700 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: <50FD62DB.5080508@gmail.com> On 01/18/2013 06:02 AM, Ferrous Cranus wrote: > Yes my Python scripts exist in a linux web host. > > os.environ['HOME'] will indeed give the home directory of the user. > > to me /home/nikos/ > > but i want a variable to point to > > /home/nikos/public_html whice is called DocumentRoot. Not it's not. There is nothing in the operating system that defines this. > is there avariable for that? i can't seem to find any... Not there's nothing in the operating system that specifies this. This is a convention that makes sense only to the apache daemon itself. If your python script is running as a CGI script, then apache will set environment variables that you can read with the os module. See the Apache docs for information on this. From nikos.gr33k at gmail.com Mon Jan 21 11:02:02 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 08:02:02 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: <70bb8ac8-8089-4882-b8c8-a8c26fb1ffdf@googlegroups.com> Ok i see its just a convention. Can you help on this: so we need to remove since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file. From nikos.gr33k at gmail.com Mon Jan 21 11:02:02 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 08:02:02 -0800 (PST) Subject: Forcing Python to detect DocumentRoot In-Reply-To: References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: <70bb8ac8-8089-4882-b8c8-a8c26fb1ffdf@googlegroups.com> Ok i see its just a convention. Can you help on this: so we need to remove since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file. From torriem at gmail.com Mon Jan 21 13:36:29 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 21 Jan 2013 11:36:29 -0700 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <70bb8ac8-8089-4882-b8c8-a8c26fb1ffdf@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> <70bb8ac8-8089-4882-b8c8-a8c26fb1ffdf@googlegroups.com> Message-ID: <50FD8AAD.5060101@gmail.com> On 01/21/2013 09:02 AM, Ferrous Cranus wrote: > Ok i see its just a convention. Can you help on this: > > so we need to remove since the > apache cant see to open it and let Python open it which we know it > can because it has access to any system file the user has access too. Is this link generated by your python CGI script? If so you'll have to work out some way for your python script to interact with Apache and ask it where the document root is. If this link is in static html, then you simply need to fix your html to make the link valid. Or maybe you need to modify your apache installation so that it knows where "/data" is using an alias directive in your apache config. From piet at vanoostrum.org Mon Jan 21 14:05:44 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 21 Jan 2013 20:05:44 +0100 Subject: Forcing Python to detect DocumentRoot References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> <10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com> Message-ID: Ferrous Cranus writes: > Ok i see its just a convention. > Can you help on this: > > so we need to remove since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. > > httpd cannot open this file because the location of the image is past the addon domain's Document Root. > > /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root > > /home/nikos/public_html/data/images/mail.png = where the image file is located > > and the python scipt is on: > > /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py > > So if a python script can open any file the user has access too then we need a "python way" of opening this file. So why don't you put the image at /home/nikos/public_html/cafebar-idea.gr/data/images/mail.png? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From barry at barrys-emacs.org Sat Jan 19 06:40:35 2013 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 19 Jan 2013 11:40:35 +0000 Subject: Forcing Python to detect DocumentRoot In-Reply-To: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: <588273B8-F089-42E3-A977-53806C74846F@barrys-emacs.org> On 16 Jan 2013, at 13:51, Ferrous Cranus wrote: > When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? In the general case it is not possible. There is no single convention you can use to detect the top of a web site. If you always use apache httpd then read the value of DocumentRoot from httpd.conf Barry From wuwei23 at gmail.com Sat Jan 19 20:53:20 2013 From: wuwei23 at gmail.com (alex23) Date: Sat, 19 Jan 2013 17:53:20 -0800 (PST) Subject: Forcing Python to detect DocumentRoot References: <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com> Message-ID: On Jan 16, 11:51?pm, Ferrous Cranus wrote: > When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? The main ways we handle something like this are: 1. Set an environment variable that Python then reads to get the DocumentRoot value. 2. Use something like zc.buildout to produce both your httpd.conf and create a config file containing the value of DocumentRoot. From mailinglists at xgm.de Wed Jan 16 09:42:42 2013 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 16 Jan 2013 15:42:42 +0100 Subject: Using inner dict as class interface Message-ID: Hello, I have a: class C: def __init__(self): d = dict_like_object_created_somewhere_else() def some_other_methods(self): pass class C should behave like a it was the dict d. So I could do: c = C() print c["key"] print len(c) but also c.some_other_method() How can I achieve that? Do I need to define all methods like __getitem__, __len__, ... (what else?) to access the inner dict or is there something more slick? Thanks, Florian From steve+comp.lang.python at pearwood.info Wed Jan 16 09:54:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2013 14:54:45 GMT Subject: Using inner dict as class interface References: Message-ID: <50f6bf35$0$30003$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote: > Hello, > > I have a: > > class C: > def __init__(self): > d = dict_like_object_created_somewhere_else() > > def some_other_methods(self): > pass > > > class C should behave like a it was the dict d. Then make it a dict: class C(dict): def some_other_methods(self): pass my_dict = C(key="value") # or C({"key": "value"}) print len(my_dict) print my_dict['key'] my_dict.some_other_methods() -- Steven From __peter__ at web.de Wed Jan 16 12:34:42 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 16 Jan 2013 18:34:42 +0100 Subject: Using inner dict as class interface References: <50f6bf35$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote: > >> Hello, >> >> I have a: >> >> class C: >> def __init__(self): >> d = dict_like_object_created_somewhere_else() >> >> def some_other_methods(self): >> pass >> >> >> class C should behave like a it was the dict d. > > Then make it a dict: > > class C(dict): > def some_other_methods(self): > pass > > my_dict = C(key="value") # or C({"key": "value"}) > print len(my_dict) > print my_dict['key'] > my_dict.some_other_methods() If for some reason it is impractical to follow Steven's advice you can subclass collections.Mapping or collections.MutableMapping. That should give you a clear notion of the required methods and has defaults for some of them. >>> class A(Mapping): pass ... >>> A() Traceback (most recent call last): File "", line 1, in TypeError: Can't instantiate abstract class A with abstract methods __getitem__, __iter__, __len__ >>> class B(Mapping): ... def __getitem__(self, key): ... return {1:2}[key] ... def __len__(self): return 1 ... def __iter__(self): yield 1 ... >>> b = B() >>> list(b) [1] >>> b.items() [(1, 2)] From matt.walker.jones at gmail.com Wed Jan 16 09:58:21 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Wed, 16 Jan 2013 08:58:21 -0600 Subject: Using inner dict as class interface In-Reply-To: References: Message-ID: Explicit is better than implicit. Define the dunder methods so you know exactly what your class is doing when being indexed. You only need __getitem__ and __setitem__ really, but if you want to treat it just like a dict you'll need __delitem__, __len__, __iter__, __contains__ as well. *Matt Jones* On Wed, Jan 16, 2013 at 8:42 AM, Florian Lindner wrote: > Hello, > > I have a: > > class C: > def __init__(self): > d = dict_like_object_created_somewhere_else() > > def some_other_methods(self): > pass > > > class C should behave like a it was the dict d. So I could do: > > c = C() > print c["key"] > print len(c) > > but also > > c.some_other_method() > > How can I achieve that? Do I need to define all methods like > __getitem__, __len__, ... (what else?) to access the inner dict or is > there something more slick? > > Thanks, > > Florian > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.walker.jones at gmail.com Wed Jan 16 09:59:16 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Wed, 16 Jan 2013 08:59:16 -0600 Subject: Using inner dict as class interface In-Reply-To: References: Message-ID: Or do what Steven said if its exactly a dict and doesn't require special management of the underlying dict. *Matt Jones* On Wed, Jan 16, 2013 at 8:58 AM, Matt Jones wrote: > Explicit is better than implicit. Define the dunder methods so you know > exactly what your class is doing when being indexed. You only need > __getitem__ and __setitem__ really, but if you want to treat it just like a > dict you'll need __delitem__, __len__, __iter__, __contains__ as well. > > *Matt Jones* > > > On Wed, Jan 16, 2013 at 8:42 AM, Florian Lindner wrote: > >> Hello, >> >> I have a: >> >> class C: >> def __init__(self): >> d = dict_like_object_created_somewhere_else() >> >> def some_other_methods(self): >> pass >> >> >> class C should behave like a it was the dict d. So I could do: >> >> c = C() >> print c["key"] >> print len(c) >> >> but also >> >> c.some_other_method() >> >> How can I achieve that? Do I need to define all methods like >> __getitem__, __len__, ... (what else?) to access the inner dict or is >> there something more slick? >> >> Thanks, >> >> Florian >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Wed Jan 16 10:05:26 2013 From: d at davea.name (Dave Angel) Date: Wed, 16 Jan 2013 10:05:26 -0500 Subject: Using inner dict as class interface In-Reply-To: References: Message-ID: <50F6C1B6.2030901@davea.name> On 01/16/2013 09:42 AM, Florian Lindner wrote: > Hello, > > I have a: > > class C: > def __init__(self): > d = dict_like_object_created_somewhere_else() > > def some_other_methods(self): > pass > > > class C should behave like a it was the dict d. So I could do: Is it a specific requirement that the class NOT be derived from dict? Are you trying to look like a dict, but with a few extra features? Or must you have a dict somewhere else (singleton ??!) that you're trying to tie this to as a proxy. Assuming you really have to tie this to some other dict, the first thing you need to do is save d, perhaps as a line like: self.d = dict_like_ob.... > > c = C() > print c["key"] > print len(c) > > but also > > c.some_other_method() > > How can I achieve that? Do I need to define all methods like > __getitem__, __len__, ... (what else?) See http://docs.python.org/reference/datamodel.html#special-method-names Because you're duck-typing, you don't need them all, just the ones your user will need. > to access the inner dict or is > there something more slick? > The more slick is to derive from dict. -- DaveA From glicerinu at gmail.com Wed Jan 16 14:58:26 2013 From: glicerinu at gmail.com (Marc Aymerich) Date: Wed, 16 Jan 2013 11:58:26 -0800 (PST) Subject: Loading a PKCS#1 public key using M2Crypto Message-ID: <922c97d0-77cf-4e68-8edc-d65c6d7e7831@googlegroups.com> Hi, I've been trying very, very hard to load an RSA key using M2Crypto but without any success. basically this is what I'm trying to do: >>> from M2Crypto import BIO, RSA >>> >>> pubkey = """-----BEGIN RSA PUBLIC KEY----- ... MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7 ... wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z ... TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR ... dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp ... c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB ... A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB ... -----END RSA PUBLIC KEY-----""" >>> >>> bio = BIO.MemoryBuffer(pubkey.encode('ascii')) >>> RSA.load_pub_key_bio(bio) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 422, in load_pub_key_bio rsa_error() File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 302, in rsa_error raise RSAError, m2.err_reason_error_string(m2.err_get_error()) M2Crypto.RSA.RSAError: no start line Reading all whats in Internet about this problem it seems that my key is in PKCS#1 format but M2Crypto only reads X.501 RSA keys. I know that python-crypto doesn't have any problem loading this key, but I'll prefer to stick with M2Crypto because I already have lots code using M2Crypto. So my question is, is there any way to load this key using M2Crypto? Can I convert somehow the key to X.501? I'll be very, very grateful if someone can come up with an interesting idea! thanks a lot!! Marc From piet at vanoostrum.org Wed Jan 16 19:32:25 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 17 Jan 2013 01:32:25 +0100 Subject: Loading a PKCS#1 public key using M2Crypto References: <922c97d0-77cf-4e68-8edc-d65c6d7e7831@googlegroups.com> Message-ID: Marc Aymerich writes: > Hi, > I've been trying very, very hard to load an RSA key using M2Crypto but without any success. > > basically this is what I'm trying to do: >>>> from M2Crypto import BIO, RSA >>>> >>>> pubkey = """-----BEGIN RSA PUBLIC KEY----- > ... MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7 > ... wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z > ... TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR > ... dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp > ... c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB > ... A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB > ... -----END RSA PUBLIC KEY-----""" >>>> >>>> bio = BIO.MemoryBuffer(pubkey.encode('ascii')) >>>> RSA.load_pub_key_bio(bio) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 422, in load_pub_key_bio > rsa_error() > File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 302, in rsa_error > raise RSAError, m2.err_reason_error_string(m2.err_get_error()) > M2Crypto.RSA.RSAError: no start line > > > Reading all whats in Internet about this problem it seems that my key is in PKCS#1 format but M2Crypto only reads X.501 RSA keys. > > I know that python-crypto doesn't have any problem loading this key, but I'll prefer to stick with M2Crypto because I already have lots code using M2Crypto. > > So my question is, is there any way to load this key using M2Crypto? Can I convert somehow the key to X.501? > Converting to X.501 isn't difficult (assuming this is a 2048 bit key): Get rid of the 'RSA' in header and trailer Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data Reformat the lines to 64 characters. from M2Crypto import BIO, RSA pubkey="""-----BEGIN RSA PUBLIC KEY----- MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7 wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB -----END RSA PUBLIC KEY----- """ pk = pubkey.split('\n') pk = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' + ''.join(pk[1:-2]) pk = [pk[i:i+64] for i in range(0, len(pk), 64)] pk = '-----BEGIN PUBLIC KEY-----\n' + '\n'.join(pk) + '\n-----END PUBLIC KEY-----' bio = BIO.MemoryBuffer(pk) # pk is ASCII, don't encode key = RSA.load_pub_key_bio(bio) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From glicerinu at gmail.com Thu Jan 17 04:16:21 2013 From: glicerinu at gmail.com (Marc Aymerich) Date: Thu, 17 Jan 2013 01:16:21 -0800 (PST) Subject: Loading a PKCS#1 public key using M2Crypto In-Reply-To: References: <922c97d0-77cf-4e68-8edc-d65c6d7e7831@googlegroups.com> Message-ID: <1fde980b-ca96-4e4d-867d-edb5e6f4871f@googlegroups.com> On Thursday, January 17, 2013 1:32:25 AM UTC+1, Piet van Oostrum wrote: > Marc Aymerich writes: > > > > > Hi, > > > I've been trying very, very hard to load an RSA key using M2Crypto but without any success. > > > > > > basically this is what I'm trying to do: > > >>>> from M2Crypto import BIO, RSA > > >>>> > > >>>> pubkey = """-----BEGIN RSA PUBLIC KEY----- > > > ... MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7 > > > ... wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z > > > ... TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR > > > ... dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp > > > ... c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB > > > ... A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB > > > ... -----END RSA PUBLIC KEY-----""" > > >>>> > > >>>> bio = BIO.MemoryBuffer(pubkey.encode('ascii')) > > >>>> RSA.load_pub_key_bio(bio) > > > Traceback (most recent call last): > > > File "", line 1, in > > > File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 422, in load_pub_key_bio > > > rsa_error() > > > File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 302, in rsa_error > > > raise RSAError, m2.err_reason_error_string(m2.err_get_error()) > > > M2Crypto.RSA.RSAError: no start line > > > > > > > > > Reading all whats in Internet about this problem it seems that my key is in PKCS#1 format but M2Crypto only reads X.501 RSA keys. > > > > > > I know that python-crypto doesn't have any problem loading this key, but I'll prefer to stick with M2Crypto because I already have lots code using M2Crypto. > > > > > > So my question is, is there any way to load this key using M2Crypto? Can I convert somehow the key to X.501? > > > > > Converting to X.501 isn't difficult (assuming this is a 2048 bit key): > > Get rid of the 'RSA' in header and trailer > > Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data > > Reformat the lines to 64 characters. > > > > from M2Crypto import BIO, RSA > > > > pubkey="""-----BEGIN RSA PUBLIC KEY----- > > MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7 > > wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z > > TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR > > dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp > > c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB > > A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB > > -----END RSA PUBLIC KEY----- > > """ > > > > pk = pubkey.split('\n') > > pk = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' + ''.join(pk[1:-2]) > > pk = [pk[i:i+64] for i in range(0, len(pk), 64)] > > pk = '-----BEGIN PUBLIC KEY-----\n' + '\n'.join(pk) + '\n-----END PUBLIC KEY-----' > > > > bio = BIO.MemoryBuffer(pk) # pk is ASCII, don't encode > > key = RSA.load_pub_key_bio(bio) > > Piet, that was really awesome, it seems so easy to do now :) Thank you very, very much! really. From piet at vanoostrum.org Thu Jan 17 11:39:57 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 17 Jan 2013 17:39:57 +0100 Subject: Loading a PKCS#1 public key using M2Crypto References: <922c97d0-77cf-4e68-8edc-d65c6d7e7831@googlegroups.com> Message-ID: Piet van Oostrum wrote: > Converting to X.501 isn't difficult (assuming this is a 2048 bit key): > Get rid of the 'RSA' in header and trailer > Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data > Reformat the lines to 64 characters. This solution is a bit restricted as it only works if the key is 2048 bits and uses an exponent of 65537 (which is the default). Otherwise it fails. Here is a robust solution that works for all PKCS#1 keys. Instead of using a fixed X.501 header it calculates the header. We could do a complete ASN.1 encoding, but most of the parts are fixed. The only variable parts are two length fields. So I just plug these into the fixed stuff. This saves using one of the ASN.1 libraries. We do have to work in binary (DER format) instead of base64, however. from M2Crypto import BIO, RSA import base64 def der_length(length): """DER encoding of a length""" if length < 128: return chr(length) prefix = 0x80 result = '' while length > 0: result = chr(length & 0xff) + result length >>= 8 prefix += 1 return chr(prefix) + result pubkey="""-----BEGIN RSA PUBLIC KEY----- MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7 wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB -----END RSA PUBLIC KEY----- """ pk = pubkey.split('\n') pk = '\0' + base64.decodestring("".join(pk[1:-2])) pk = '\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03' + \ der_length(len(pk)) + pk pk = '\x30' + der_length(len(pk)) + pk pk = '-----BEGIN PUBLIC KEY-----\n' + base64.encodestring(pk) + '-----END PUBLIC KEY-----' bio = BIO.MemoryBuffer(pk) key = RSA.load_pub_key_bio(bio) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From glicerinu at gmail.com Thu Jan 17 12:13:43 2013 From: glicerinu at gmail.com (Marc Aymerich) Date: Thu, 17 Jan 2013 09:13:43 -0800 (PST) Subject: Loading a PKCS#1 public key using M2Crypto In-Reply-To: References: <922c97d0-77cf-4e68-8edc-d65c6d7e7831@googlegroups.com> Message-ID: <58e8a6c7-d512-4f44-b41f-a4f7efacf14f@googlegroups.com> On Thursday, January 17, 2013 5:39:57 PM UTC+1, Piet van Oostrum wrote: > > Converting to X.501 isn't difficult (assuming this is a 2048 bit key): > > > Get rid of the 'RSA' in header and trailer > > > Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data > > > Reformat the lines to 64 characters. > > > > This solution is a bit restricted as it only works if the key is 2048 > > bits and uses an exponent of 65537 (which is the default). Otherwise it > > fails. > > > > Here is a robust solution that works for all PKCS#1 keys. Instead of > > using a fixed X.501 header it calculates the header. We could do a > > complete ASN.1 encoding, but most of the parts are fixed. The only > > variable parts are two length fields. So I just plug these into the > > fixed stuff. This saves using one of the ASN.1 libraries. We do have to > > work in binary (DER format) instead of base64, however. > Thank you very much Piet, I'm just starting to grasp these cryptography related concepts and your code is helping me a lot to understand how to handle these keys in a low level. I'm updating my code incorporating your new contribution! Just to let you know, during my previous research I had found a python-Crypto related solution that also uses DER and ASN.1 [1], but it uses a different approach (I guess). I suspect that this approach is also possible with M2Crypto because it has a method for constructing RSA keys [2]. [1] http://stackoverflow.com/a/10574723 [2] http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.RSA-module.html#new_pub_key Thanks again! Marc PS: Sorry for my email format, I'm using google groups and it seems to ignore any mailing best practice. From piet at vanoostrum.org Thu Jan 17 18:10:20 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 18 Jan 2013 00:10:20 +0100 Subject: Loading a PKCS#1 public key using M2Crypto References: <922c97d0-77cf-4e68-8edc-d65c6d7e7831@googlegroups.com> <58e8a6c7-d512-4f44-b41f-a4f7efacf14f@googlegroups.com> Message-ID: Marc Aymerich writes: > Thank you very much Piet, > I'm just starting to grasp these cryptography related concepts and your code is helping me a lot to understand how to handle these keys in a low level. > > I'm updating my code incorporating your new contribution! > > Just to let you know, during my previous research I had found a python-Crypto related solution that also uses DER and ASN.1 [1], but it uses a different approach (I guess). I suspect that this approach is also possible with M2Crypto because it has a method for constructing RSA keys [2]. > > [1] http://stackoverflow.com/a/10574723 > [2] http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.RSA-module.html#new_pub_key > new_pub_key could be used but then you would have to do an ASN.1 parse of the DER format of your key to get the n and e values. AFAICT M2Crypto doesn't have methods to do this, so you would need to use one of the python ASN.1 libraries (or write that part yourself). -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From glicerinu at gmail.com Fri Jan 18 04:13:01 2013 From: glicerinu at gmail.com (Marc Aymerich) Date: Fri, 18 Jan 2013 10:13:01 +0100 Subject: Loading a PKCS#1 public key using M2Crypto In-Reply-To: References: <922c97d0-77cf-4e68-8edc-d65c6d7e7831@googlegroups.com> <58e8a6c7-d512-4f44-b41f-a4f7efacf14f@googlegroups.com> Message-ID: On Fri, Jan 18, 2013 at 12:10 AM, Piet van Oostrum wrote: > Marc Aymerich writes: > >> Thank you very much Piet, >> I'm just starting to grasp these cryptography related concepts and your code is helping me a lot to understand how to handle these keys in a low level. >> >> I'm updating my code incorporating your new contribution! >> >> Just to let you know, during my previous research I had found a python-Crypto related solution that also uses DER and ASN.1 [1], but it uses a different approach (I guess). I suspect that this approach is also possible with M2Crypto because it has a method for constructing RSA keys [2]. >> >> [1] http://stackoverflow.com/a/10574723 >> [2] http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.RSA-module.html#new_pub_key >> > new_pub_key could be used but then you would have to do an ASN.1 parse > of the DER format of your key to get the n and e values. AFAICT M2Crypto > doesn't have methods to do this, so you would need to use one of the > python ASN.1 libraries (or write that part yourself). Thanks for the clarifications, Just sharing the document I'm reading right now, in case anyone found this thread and want to know more about ASN.1 and DER: ftp://ftp.rsasecurity.com/pub/pkcs/ascii/layman.asc -- Marc From rantingrickjohnson at gmail.com Wed Jan 16 15:03:30 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 16 Jan 2013 12:03:30 -0800 (PST) Subject: PyTut: (Teminology) To clone, copy, or spawn -- that is the question! Message-ID: <6663ae09-b05c-4ad2-aa11-356eb1476d7f@googlegroups.com> PyTut: (Teminology) To clone, copy, or spawn -- that is the question! I've many time seen these three words applied improperly as symbols and believe i should explicitly define these terms in a programming context so that we all might use them correctly. Also notice that i did not mention "deepcopy". I did so for good reason because i believe the term "deepcopy" should NEVER be used in a programming context anymore (maybe anywhere). Firstly let's understand the English definitions of clone, copy and spawn: -------------------------------------------------------- Define: Clone ------------------------------------------------------- 1. A cell, cell product, or organism that is genetically identical to the unit or individual from which it was derived. 2. Something that duplicates, imitates, or closely resembles another in appearance, function, performance, or style: All the fashion models seemed to be clones of one another. [Disambiguation] In the first definition, a clone is an object that is created by building an new object whos' internal structure is perfectly /identical/ to the internal structure of the existing object. In the second definition an object imitates another object so closely that an observer cannot distinguish between the individuals of a group and consequently refers to all members as a whole. Both are correct within their respective relativities, however, the first definition is based upon /tangible facts/ and the second depends on an observers' /interpretation/. -------------------------------------------------------- Define: Copy -------------------------------------------------------- A thing made to be similar or identical to another. [Disambiguation] I believe this definition is self-defeating. Maybe even expressing circular reasoning. Can something be similar or identical? I think not! identical and similar are NOT interchangeable. My /strong/ opinion is that ALL copies must be /identical/. Not only in appearance, but in every possible detail; internal structure, state, EVERYTHING! -------------------------------------------------------- Define: Spawn -------------------------------------------------------- To bring forth, or generate. [Disambiguation] This definition is the correct base definition of "spawn". However, the definition does disqualify specific use of the word leaving only general usage. Sure, we are creating (or "spawning") /something/, but what /exactly/ are we creating? Also, we have no hint as to which paradigm will be used to do the creating; will the result of this "spawning" be an *exact* copy of "something", or a /similar/ copy of "something", or something new that is based on a paradigm of creation for which we are oblivious? Who knows? -------------------------------------------------------- Terminology Transformation -------------------------------------------------------- If you ever find yourself in a situation where you need to create a new object from an existing object, be sure you use them following these simple and intuitive rules: * Clone: Only use "clone" when you intent to create a new object that is an exact replication of the existing object (interface) but NOT an object that will be initalized with the existing objects' state! The new clone should look like the old object and interface like the old object, HOWEVER, the new clone's state should be a default, NOT A COPY! * Copy: Only use "copy" when you intend to create a new object that is an EXACT copy of the original object. Yes, that means all the way down to the deepest nesting, farthest corners, and smelliest nether-regions of the object! I don't like the term "deepcopy" because there is only ONE type of copy, and that is the *EXACT* copy. * Spawn: This term is so general that usage of it should be limited to /very/ generic interfaces. Interfaces that need to create something in a "factory" type manner would be a good example. These interfaces should be low level. Interfaces existing above should provide more specifics and use the copy or clone terminology appropriately. -rr From reganrexman at gmail.com Wed Jan 16 15:52:54 2013 From: reganrexman at gmail.com (reganrexman) Date: Wed, 16 Jan 2013 14:52:54 -0600 Subject: Modern Control Engineering 5 Ed. - K. OGATA Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTION - MANUAL - Machine Design : An Integrated Approach (3rd Ed., Norton) SOLUTION - MANUAL - Machines and Mechanisms - Applied Kinematic Analysis, 3E by David H. Myszka SOLUTION - MANUAL - Managerial Accounting 11th Ed by Garrison & Noreen SOLUTION - MANUAL - Managerial Accounting 13th E by Garrison, Noreen, Brewer SOLUTION - MANUAL - Managing Business and Professional Communication 2nd ed Carley H. Dodd SOLUTION - MANUAL - Managing Business Process Flows: Principles of Operations Management(2nd Ed., Anupind, Chopra, Deshmukh, et al) SOLUTION - MANUAL - Managing Engineering and Technology (4th, Morse & Babcock) SOLUTION - MANUAL - manual for Mathematical Methods in the Physical Sciences; 3 edition by Mary L. Boas SOLUTION - MANUAL - Manufacturing Processes for Engineering Materials (5th Ed. Kalpakjian & Smith) SOLUTION - MANUAL - Materials - engineering, science, properties, and design SOLUTION - MANUAL - Materials and Processes in Manufacturing (9th Ed., E. Paul DeGarmo, J. T. Black,Kohser) SOLUTION - MANUAL - Materials for Civil and Construction Engineers 3rd ED by Mamlouk, Zaniewski SOLUTION - MANUAL - Materials Science and Engineering- An Introduction ( 7th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - Materials Science and Engineering- An Introduction (6th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - MATH 1010 - Applied Finite Mathematics by D.W. Trim SOLUTION - MANUAL - Mathematical Analysis, Second Edition by Tom M. Apostol SOLUTION - MANUAL - Mathematical Methods for Physicists 5 Ed, Arfken SOLUTION - MANUAL - Mathematical Methods for Physics and Engineering, (3rd Ed., Riley,Hobson) SOLUTION - MANUAL - Mathematical Models in Biology An Introduction (Elizabeth S. Allman & John A. Rhodes) SOLUTION - MANUAL - Mathematical Proofs - A Transition to Advanced Mathematics 2nd Ed by Chartrand, Polimeni, Zhang SOLUTION - MANUAL - Mathematical Techniques 4th ED by D W Jordan & P Smith SOLUTION - MANUAL - Mathematics for Economists, by Carl P. Simon , Lawrence E. Blume SOLUTION - MANUAL - Mathematics for Management Science - A Bridging Course by Tulett SOLUTION - MANUAL - Mathematics for Physicists by Susan Lea SOLUTION - MANUAL - Matrix Analysis and Applied Linear Algebra by Meyer SOLUTION - MANUAL - Matter and Interactions, 3rd Ed by Chabay, Sherwood SOLUTION - MANUAL - McGraw-Hill Ryerson Calculus & Advanced Function by Dearling, Erdman, et all SOLUTION - MANUAL - Mechanical Engineering Design 8th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design 9th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design, 7th Ed. by Mischke, Shigley SOLUTION - MANUAL - Mechanical Measurements (6th Ed., Beckwith, Marangoni & Lienhard) SOLUTION - MANUAL - Mechanical Vibrations ( Vol.1) 4th Ed., Rao SOLUTION - MANUAL - Mechanical Vibrations (3rd Ed., Rao) SOLUTION - MANUAL - Mechanical Vibrations 4th Ed SI Units by Rao SOLUTION - MANUAL - Mechanics of Aircraft Structures, 2nd Ed by Sun SOLUTION - MANUAL - Mechanics of Fluids (8th Ed., Massey) SOLUTION - MANUAL - Mechanics of Fluids 3rd ED Vol 1 by Merle C. Potter SOLUTION - MANUAL - Mechanics of Materials 5 edition by James M. Gere SOLUTION - MANUAL - Mechanics of Materials (6th Ed., Riley, Sturges & Morris) SOLUTION - MANUAL - Mechanics of Materials 4 E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials 4th Ed by Beer Johnston SOLUTION - MANUAL - Mechanics of Materials 8th E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics Of Materials Beer Johnston 3rd SOLUTION - MANUAL - Mechanics of Materials, 2nd Ed by Roy R. Craig SOLUTION - MANUAL - Mechanics of Materials, 6E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 6th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Materials, 7E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 7th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Solids, ross SOLUTION - MANUAL - Mechanism Design Analysis and Synthesis (4th Edition) by Erdman, Sandor, Kota SOLUTION - MANUAL - MEMS and Microsystems Design, Manufacture and Nanoscale Engineering 2nd ED by Tai-Ran Hsu SOLUTION - MANUAL - Microeconomic Analysis, 3rd Ed., by H. Varian SOLUTION - MANUAL - Microeconomic Theory Basic Principles and Extensions 9E ( South-Western ) by Walter Nicholson SOLUTION - MANUAL - Microeconomic Theory by Segal Tadelis Hara Chiaka Hara Steve Tadelis SOLUTION - MANUAL - Microeconomic Theory, by Mas-Colell, Whinston, Green SOLUTION - MANUAL - Microeconomics, 6th Ed by Pyndick, Rubinfeld SOLUTION - MANUAL - Microelectronic Circuit Analysis and Design, 3rd Edition, by D. Neamen SOLUTION - MANUAL - Microelectronic Circuit Design (3rd Ed., Richard Jaeger & Travis Blalock) SOLUTION - MANUAL - Microelectronic Circuits By Adel Sedra 5th Edition SOLUTION - MANUAL - Microelectronic Circuits, 4th Ed. by Sedra and Smith SOLUTION - MANUAL - Microelectronic Circuits, 5th Ed. by Sedra and Smith SOLUTION - MANUAL - Microelectronics Digital and Analog Circuits and Systems by Millman SOLUTION - MANUAL - Microelectronics I & II by Dr.Chang SOLUTION - MANUAL - Microelectronics,Solution MANUAL,5thEd,MAZ SOLUTION - MANUAL - Microprocessors and Interfacing, Revised 2nd Edition by Douglas V Hall SOLUTION - MANUAL - Microwave and Rf Design of Wireless Systems, 1st Edition, by Pozar SOLUTION - MANUAL - Microwave Engineering, 2nd Ed., by David M. Pozar SOLUTION - MANUAL - Microwave Engineering, 3rd Ed., by David M. Pozar SOLUTION - MANUAL - Microwave Transistor Amplifiers Analysis and Design, 2nd Ed., by Guillermo Gonzalez SOLUTION - MANUAL - Mobile Communications 2nd ed by Jochen Schiller SOLUTION - MANUAL - Modern Control Engineering 3rd Ed. - K. OGATA SOLUTION - MANUAL - Modern Control Engineering 4th Ed. - K. OGATA SOLUTION - MANUAL - Modern Control Engineering 5 Ed. - K. OGATA SOLUTION - MANUAL - Modern Control Systems 11E by Richard C Dorf and Robert H. Bishop SOLUTION - MANUAL - Modern Control Systems 9 E by Richard C Dorf and Robert H. Bishop SOLUTION - MANUAL - Modern Control Systems, 12th Ed by Dorf, Bishop SOLUTION - MANUAL - Modern Digital and Analog Communication Systems, 3rd Ed., by Lathi SOLUTION - MANUAL - Modern Digital Electronics 3 Ed by R P Jain SOLUTION - MANUAL - Modern Digital Electronics,3E by R P JAIN SOLUTION - MANUAL - Modern Digital Signal Processing-Roberto Cristi SOLUTION - MANUAL - MODERN OPERATING SYSTEMS 2nd ed A.S.TANENBAUM SOLUTION - MANUAL - Modern Organic Synthesis An Introduction by George Zweifel, Michael Nantz SOLUTION - MANUAL - Modern Physics 2nd E by Randy Harris SOLUTION - MANUAL - Modern Physics 4th ed by Mark Llewellyn SOLUTION - MANUAL - Modern Physics 4th ed by Tipler, Llewellyn SOLUTION - MANUAL - Modern Physics for Scientists and Engineers 3rd E by Thornton and Rex SOLUTION - MANUAL - MODERN POWER SYSTEM ANALYSIS 3rd E by Kothari,Nagrath SOLUTION - MANUAL - Modern Quantum Mechanics (Revised Edition) by J. J. Sakurai SOLUTION - MANUAL - Modern Thermodynamics - From Heat Engines to Dissipative Structures by Kondepudi, Prigogine SOLUTION - MANUAL - Modern Thermodynamics - From Heat Engines to Dissipative Structures Vol 1 by Kondepudi, Prigogine SOLUTION - MANUAL - Molecular Driving Forces 2nd ED ( vol.1 ) by Dill, Bromberg SOLUTION - MANUAL - Molecular Symmetry and Group Theory by Robert L. Carter SOLUTION - MANUAL - Multinational Business Finance 10 E by Stonehill, Moffett, Eiteman SOLUTION - MANUAL - Multivariable Calculus, 4th Edition, JAMES STEWART SOLUTION - MANUAL - Multivariable Calculus, 5th Edition, JAMES STEWART SOLUTION - MANUAL - Multivariable Calculus, Applications and Theory by Kenneth Kuttler SOLUTION - MANUAL - Nanoengineering of Structural, Functional and Smart Materials, Mark J. Schulz, Ajit D. Kelkar SOLUTION - MANUAL - Network Flows: Theory, Algorithms, and Applications by Ravindra K. Ahuja , Thomas L. Magnanti , James B. Orlin SOLUTION - MANUAL - Networks and Grids - Technology and Theory by Thomas G. Robertazzi SOLUTION - MANUAL - Neural networks and learning machines 3rd edition by Simon S. Haykin ( 2,3,7,14 missing ) SOLUTION - MANUAL - Nonlinear Programming 2nd Edition , Dimitri P.Bertsekas SOLUTION - MANUAL - Nonlinear Programming ,2ndEdition , Dimitri P.Bertsekas SOLUTION - MANUAL - Numerical Analysis 8th ED by BURDEN & FAIRES SOLUTION - MANUAL - Numerical Computing with MATLAB by Moler SOLUTION - MANUAL - Numerical Methods for Engineers (3rd Ed. Steven C. Chapra) SOLUTION - MANUAL - Numerical Methods for Engineers (5th Ed. Steven C. Chapra) SOLUTION - MANUAL - Numerical Methods Using MATLAB (3rd Edition)by John H. Mathews & Fink SOLUTION - MANUAL - Numerical Methods Using Matlab, 4E by Mathews, Kurtis K. Fink From reganrexman at gmail.com Wed Jan 16 15:53:03 2013 From: reganrexman at gmail.com (reganrexman) Date: Wed, 16 Jan 2013 14:53:03 -0600 Subject: Modern Control Engineering 5 Ed. - K. OGATA Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTION - MANUAL - Machine Design : An Integrated Approach (3rd Ed., Norton) SOLUTION - MANUAL - Machines and Mechanisms - Applied Kinematic Analysis, 3E by David H. Myszka SOLUTION - MANUAL - Managerial Accounting 11th Ed by Garrison & Noreen SOLUTION - MANUAL - Managerial Accounting 13th E by Garrison, Noreen, Brewer SOLUTION - MANUAL - Managing Business and Professional Communication 2nd ed Carley H. Dodd SOLUTION - MANUAL - Managing Business Process Flows: Principles of Operations Management(2nd Ed., Anupind, Chopra, Deshmukh, et al) SOLUTION - MANUAL - Managing Engineering and Technology (4th, Morse & Babcock) SOLUTION - MANUAL - manual for Mathematical Methods in the Physical Sciences; 3 edition by Mary L. Boas SOLUTION - MANUAL - Manufacturing Processes for Engineering Materials (5th Ed. Kalpakjian & Smith) SOLUTION - MANUAL - Materials - engineering, science, properties, and design SOLUTION - MANUAL - Materials and Processes in Manufacturing (9th Ed., E. Paul DeGarmo, J. T. Black,Kohser) SOLUTION - MANUAL - Materials for Civil and Construction Engineers 3rd ED by Mamlouk, Zaniewski SOLUTION - MANUAL - Materials Science and Engineering- An Introduction ( 7th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - Materials Science and Engineering- An Introduction (6th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - MATH 1010 - Applied Finite Mathematics by D.W. Trim SOLUTION - MANUAL - Mathematical Analysis, Second Edition by Tom M. Apostol SOLUTION - MANUAL - Mathematical Methods for Physicists 5 Ed, Arfken SOLUTION - MANUAL - Mathematical Methods for Physics and Engineering, (3rd Ed., Riley,Hobson) SOLUTION - MANUAL - Mathematical Models in Biology An Introduction (Elizabeth S. Allman & John A. Rhodes) SOLUTION - MANUAL - Mathematical Proofs - A Transition to Advanced Mathematics 2nd Ed by Chartrand, Polimeni, Zhang SOLUTION - MANUAL - Mathematical Techniques 4th ED by D W Jordan & P Smith SOLUTION - MANUAL - Mathematics for Economists, by Carl P. Simon , Lawrence E. Blume SOLUTION - MANUAL - Mathematics for Management Science - A Bridging Course by Tulett SOLUTION - MANUAL - Mathematics for Physicists by Susan Lea SOLUTION - MANUAL - Matrix Analysis and Applied Linear Algebra by Meyer SOLUTION - MANUAL - Matter and Interactions, 3rd Ed by Chabay, Sherwood SOLUTION - MANUAL - McGraw-Hill Ryerson Calculus & Advanced Function by Dearling, Erdman, et all SOLUTION - MANUAL - Mechanical Engineering Design 8th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design 9th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design, 7th Ed. by Mischke, Shigley SOLUTION - MANUAL - Mechanical Measurements (6th Ed., Beckwith, Marangoni & Lienhard) SOLUTION - MANUAL - Mechanical Vibrations ( Vol.1) 4th Ed., Rao SOLUTION - MANUAL - Mechanical Vibrations (3rd Ed., Rao) SOLUTION - MANUAL - Mechanical Vibrations 4th Ed SI Units by Rao SOLUTION - MANUAL - Mechanics of Aircraft Structures, 2nd Ed by Sun SOLUTION - MANUAL - Mechanics of Fluids (8th Ed., Massey) SOLUTION - MANUAL - Mechanics of Fluids 3rd ED Vol 1 by Merle C. Potter SOLUTION - MANUAL - Mechanics of Materials 5 edition by James M. Gere SOLUTION - MANUAL - Mechanics of Materials (6th Ed., Riley, Sturges & Morris) SOLUTION - MANUAL - Mechanics of Materials 4 E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials 4th Ed by Beer Johnston SOLUTION - MANUAL - Mechanics of Materials 8th E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics Of Materials Beer Johnston 3rd SOLUTION - MANUAL - Mechanics of Materials, 2nd Ed by Roy R. Craig SOLUTION - MANUAL - Mechanics of Materials, 6E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 6th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Materials, 7E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 7th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Solids, ross SOLUTION - MANUAL - Mechanism Design Analysis and Synthesis (4th Edition) by Erdman, Sandor, Kota SOLUTION - MANUAL - MEMS and Microsystems Design, Manufacture and Nanoscale Engineering 2nd ED by Tai-Ran Hsu SOLUTION - MANUAL - Microeconomic Analysis, 3rd Ed., by H. Varian SOLUTION - MANUAL - Microeconomic Theory Basic Principles and Extensions 9E ( South-Western ) by Walter Nicholson SOLUTION - MANUAL - Microeconomic Theory by Segal Tadelis Hara Chiaka Hara Steve Tadelis SOLUTION - MANUAL - Microeconomic Theory, by Mas-Colell, Whinston, Green SOLUTION - MANUAL - Microeconomics, 6th Ed by Pyndick, Rubinfeld SOLUTION - MANUAL - Microelectronic Circuit Analysis and Design, 3rd Edition, by D. Neamen SOLUTION - MANUAL - Microelectronic Circuit Design (3rd Ed., Richard Jaeger & Travis Blalock) SOLUTION - MANUAL - Microelectronic Circuits By Adel Sedra 5th Edition SOLUTION - MANUAL - Microelectronic Circuits, 4th Ed. by Sedra and Smith SOLUTION - MANUAL - Microelectronic Circuits, 5th Ed. by Sedra and Smith SOLUTION - MANUAL - Microelectronics Digital and Analog Circuits and Systems by Millman SOLUTION - MANUAL - Microelectronics I & II by Dr.Chang SOLUTION - MANUAL - Microelectronics,Solution MANUAL,5thEd,MAZ SOLUTION - MANUAL - Microprocessors and Interfacing, Revised 2nd Edition by Douglas V Hall SOLUTION - MANUAL - Microwave and Rf Design of Wireless Systems, 1st Edition, by Pozar SOLUTION - MANUAL - Microwave Engineering, 2nd Ed., by David M. Pozar SOLUTION - MANUAL - Microwave Engineering, 3rd Ed., by David M. Pozar SOLUTION - MANUAL - Microwave Transistor Amplifiers Analysis and Design, 2nd Ed., by Guillermo Gonzalez SOLUTION - MANUAL - Mobile Communications 2nd ed by Jochen Schiller SOLUTION - MANUAL - Modern Control Engineering 3rd Ed. - K. OGATA SOLUTION - MANUAL - Modern Control Engineering 4th Ed. - K. OGATA SOLUTION - MANUAL - Modern Control Engineering 5 Ed. - K. OGATA SOLUTION - MANUAL - Modern Control Systems 11E by Richard C Dorf and Robert H. Bishop SOLUTION - MANUAL - Modern Control Systems 9 E by Richard C Dorf and Robert H. Bishop SOLUTION - MANUAL - Modern Control Systems, 12th Ed by Dorf, Bishop SOLUTION - MANUAL - Modern Digital and Analog Communication Systems, 3rd Ed., by Lathi SOLUTION - MANUAL - Modern Digital Electronics 3 Ed by R P Jain SOLUTION - MANUAL - Modern Digital Electronics,3E by R P JAIN SOLUTION - MANUAL - Modern Digital Signal Processing-Roberto Cristi SOLUTION - MANUAL - MODERN OPERATING SYSTEMS 2nd ed A.S.TANENBAUM SOLUTION - MANUAL - Modern Organic Synthesis An Introduction by George Zweifel, Michael Nantz SOLUTION - MANUAL - Modern Physics 2nd E by Randy Harris SOLUTION - MANUAL - Modern Physics 4th ed by Mark Llewellyn SOLUTION - MANUAL - Modern Physics 4th ed by Tipler, Llewellyn SOLUTION - MANUAL - Modern Physics for Scientists and Engineers 3rd E by Thornton and Rex SOLUTION - MANUAL - MODERN POWER SYSTEM ANALYSIS 3rd E by Kothari,Nagrath SOLUTION - MANUAL - Modern Quantum Mechanics (Revised Edition) by J. J. Sakurai SOLUTION - MANUAL - Modern Thermodynamics - From Heat Engines to Dissipative Structures by Kondepudi, Prigogine SOLUTION - MANUAL - Modern Thermodynamics - From Heat Engines to Dissipative Structures Vol 1 by Kondepudi, Prigogine SOLUTION - MANUAL - Molecular Driving Forces 2nd ED ( vol.1 ) by Dill, Bromberg SOLUTION - MANUAL - Molecular Symmetry and Group Theory by Robert L. Carter SOLUTION - MANUAL - Multinational Business Finance 10 E by Stonehill, Moffett, Eiteman SOLUTION - MANUAL - Multivariable Calculus, 4th Edition, JAMES STEWART SOLUTION - MANUAL - Multivariable Calculus, 5th Edition, JAMES STEWART SOLUTION - MANUAL - Multivariable Calculus, Applications and Theory by Kenneth Kuttler SOLUTION - MANUAL - Nanoengineering of Structural, Functional and Smart Materials, Mark J. Schulz, Ajit D. Kelkar SOLUTION - MANUAL - Network Flows: Theory, Algorithms, and Applications by Ravindra K. Ahuja , Thomas L. Magnanti , James B. Orlin SOLUTION - MANUAL - Networks and Grids - Technology and Theory by Thomas G. Robertazzi SOLUTION - MANUAL - Neural networks and learning machines 3rd edition by Simon S. Haykin ( 2,3,7,14 missing ) SOLUTION - MANUAL - Nonlinear Programming 2nd Edition , Dimitri P.Bertsekas SOLUTION - MANUAL - Nonlinear Programming ,2ndEdition , Dimitri P.Bertsekas SOLUTION - MANUAL - Numerical Analysis 8th ED by BURDEN & FAIRES SOLUTION - MANUAL - Numerical Computing with MATLAB by Moler SOLUTION - MANUAL - Numerical Methods for Engineers (3rd Ed. Steven C. Chapra) SOLUTION - MANUAL - Numerical Methods for Engineers (5th Ed. Steven C. Chapra) SOLUTION - MANUAL - Numerical Methods Using MATLAB (3rd Edition)by John H. Mathews & Fink SOLUTION - MANUAL - Numerical Methods Using Matlab, 4E by Mathews, Kurtis K. Fink From info at wingware.com Wed Jan 16 15:59:40 2013 From: info at wingware.com (Wingware) Date: Wed, 16 Jan 2013 15:59:40 -0500 Subject: ANN: Wing IDE 4.1.10 released Message-ID: <50F714BC.8040305@wingware.com> Hi, Wingware has released version 4.1.10 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ This minor release includes: * Allow setting syntax highlighting colors for all supported file types * Added Previous/Next buttons to the Find Uses tool * Added more line editing key bindings in default keyboard personality * Added Close Others to the Open Files tool's context menu * Updated German localization (thanks to Chris Heitkamp!) * Added character order fixup auto-editing operation (such as x(.) -> x().) * Preference for maximum file size to try to open (default is 100MB) * Enter during rename, move, and introduce var refactoring does the operation * Fix typing and pasting into rectangular selection in non-VI keyboard modes * Recognize *.m as matlab file by default * Find Uses prioritizes current file over the rest of the project * Several auto-editing and Turbo completion mode fixes * Fix VI mode r (replace char) on non-ascii characters * About 15 other bug fixes and minor improvements For a complete change log see http://wingware.com/pub/wingide/4.1.10/CHANGELOG.txt Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: http://wingware.com/wingide/features More information: http://wingware.com/ Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at sales at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE Advancing Software Development www.wingware.com From copybin at gmail.com Wed Jan 16 17:01:17 2013 From: copybin at gmail.com (Elias Andrawos) Date: Wed, 16 Jan 2013 14:01:17 -0800 (PST) Subject: SimpleAI, Artificial Intelligence with Python - [released] Message-ID: <6d3c2c9f-fd13-417e-9534-ca0b9ef85bdc@googlegroups.com> SimpleAI is an easy to use lib implementing in python many of the artificial intelligence algorithms described on the book "Artificial Intelligence, a Modern Approach", from Stuart Russel and Peter Norvig. This implementation takes some of the ideas from the Norvig's implementation (the aima-python lib), but it's made with a more "pythonic" approach, and more emphasis on creating a stable, modern, and maintainable version. We are testing the majority of the lib, it's available via pip install, has a standard repository and lib architecture, well documented, respects the python pep8 guidelines, provides only working code (no placeholders for future things), etc. Even the internal code is written with readability in mind, not only the external API. This new release adds a few statistical classification methods to SimpleAI with the intention of start replicating the machine learning aspects of aima-python, also includes lots of tests for the classifiers, documentation, and a few sample uses of the classifiers. http://simpleai.readthedocs.org/ https://github.com/simpleai-team/simpleai twitter: @machinalis From wuwei23 at gmail.com Wed Jan 16 19:38:12 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 16 Jan 2013 16:38:12 -0800 (PST) Subject: SimpleAI, Artificial Intelligence with Python - [released] References: <6d3c2c9f-fd13-417e-9534-ca0b9ef85bdc@googlegroups.com> Message-ID: <8073bd31-be26-43b7-9fe0-35fcf5c85c57@d2g2000pbd.googlegroups.com> On Jan 17, 8:01?am, Elias Andrawos wrote: > SimpleAI is an easy to use lib implementing in python many of the > artificial intelligence algorithms described on the book "Artificial > Intelligence, a Modern Approach" Thanks for this, it looks great. One question: I couldn't find any mention of what Python versions are supported? 2 only? Late 2? 3? Cheers! From fisadev at gmail.com Thu Jan 17 09:06:05 2013 From: fisadev at gmail.com (fisadev at gmail.com) Date: Thu, 17 Jan 2013 06:06:05 -0800 (PST) Subject: SimpleAI, Artificial Intelligence with Python - [released] In-Reply-To: <8073bd31-be26-43b7-9fe0-35fcf5c85c57@d2g2000pbd.googlegroups.com> References: <6d3c2c9f-fd13-417e-9534-ca0b9ef85bdc@googlegroups.com> <8073bd31-be26-43b7-9fe0-35fcf5c85c57@d2g2000pbd.googlegroups.com> Message-ID: On Wednesday, January 16, 2013 9:38:12 PM UTC-3, alex23 wrote: > On Jan 17, 8:01?am, Elias Andrawos wrote: > > > SimpleAI is an easy to use lib implementing in python many of the > > > artificial intelligence algorithms described on the book "Artificial > > > Intelligence, a Modern Approach" > > > > Thanks for this, it looks great. One question: I couldn't find any > > mention of what Python versions are supported? 2 only? Late 2? 3? > > > > Cheers! Hi! We currently support "late 2" versions of python (we have tested it under 2.7). But there are plans to make it compatible with python 3, it shouldn't be very difficult :) -- fisa - Juan Pedro Fisanotti From 2281570025 at qq.com Wed Jan 16 19:34:22 2013 From: 2281570025 at qq.com (=?utf-8?B?aU1hdGg=?=) Date: Thu, 17 Jan 2013 08:34:22 +0800 Subject: To make a method or attribute private Message-ID: An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Jan 16 20:04:00 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 16 Jan 2013 17:04:00 -0800 (PST) Subject: To make a method or attribute private References: Message-ID: On Jan 17, 10:34?am, "iMath" <2281570... at qq.com> wrote: > To make a method or attribute private (inaccessible from the outside), simply start its > name with two underscores > > but there is another saying goes: > Beginning a variable name with a single underscore indicates that the variable should be treated as ?private?. > I test both these 2 rules ,it seems only names that start with two underscores are REAL private methods or attributes . > so what is your opinion about single leading underscore and private methods or attributes? The key word in the second quote is "indicates". Placing a single underscore before an attribute name does nothing but _show_ other programmers that you consider this to be part of the implementation rather than the interface, and that you make no guarantees of its continued existence over time. More importantly, however: there is no real concept of "private" attributes in Python. Try this at the command prompt: >>> ap._A__a '__a' It's still readable, and it's still writable too. The double- underscore naming is referred to as "name mangling" and while it's often passed off as the way to make private methods in Python (the tutorial even states this), what it is really intended for is to ensure that multiple inheritance works correctly: >>> class A(object): ... foo = 'A' ... def get_A_foo(self): ... return self.foo ... >>> class B(object): ... foo = 'B' ... def get_B_foo(self): ... return self.foo ... >>> class C(A, B): ... def __init__(self): ... super(C, self).__init__() ... >>> c = C() >>> c.get_A_foo() 'A' >>> c.get_B_foo() 'A' Here, we haven't mangled the attribute 'foo' on either A or B, so on the instance of C, which inherits from both, the inherited methods are referring to the same attribute, which is A's in this case due to the method resolution order. By re-naming 'foo' on both A and B to '__foo', each can then refer to their _own_ attribute, and also allow for C to have its own 'foo' attribute which doesn't conflict with either of them: >>> class A(object): ... __foo = 'A' ... def get_A_foo(self): ... return self.__foo ... >>> class B(object): ... __foo = 'B' ... def get_B_foo(self): ... return self.__foo ... >>> class C(A, B): ... foo = 'C' ... def __init__(self): ... super(C, self).__init__() ... >>> c = C() >>> c.get_A_foo() 'A' >>> c.get_B_foo() 'B' >>> c.foo 'C' There is no way to make an externally private attribute. This is generally considered a good thing by most Python developers: if I _need_ to access your class's implementation, I can do so, but the name mangling forces me to be aware that this is something you don't recommend doing. You'll often hear the term "consenting adults" used to refer to this, meaning we can all decide for ourselves if we're willing to risk using an implementation detail. From redstone-cold at 163.com Sun Jan 20 09:52:32 2013 From: redstone-cold at 163.com (iMath) Date: Sun, 20 Jan 2013 06:52:32 -0800 (PST) Subject: To make a method or attribute private In-Reply-To: References: Message-ID: <43381757-44d7-4807-b3cc-3d7d8b46348e@googlegroups.com> ? 2013?1?17????UTC+8??9?04?00??alex23??? > On Jan 17, 10:34?am, "iMath" <2281570... at qq.com> wrote: > > > To make a method or attribute private (inaccessible from the outside), simply start its > > > name with two underscores > > > > > > but there is another saying goes: > > > Beginning a variable name with a single underscore indicates that the variable should be treated as ?private?. > > > I test both these 2 rules ,it seems only names that start with two underscores are REAL private methods or attributes . > > > so what is your opinion about single leading underscore and private methods or attributes? > > > > The key word in the second quote is "indicates". Placing a single > > underscore before an attribute name does nothing but _show_ other > > programmers that you consider this to be part of the implementation > > rather than the interface, and that you make no guarantees of its > > continued existence over time. > > > > More importantly, however: there is no real concept of "private" > > attributes in Python. Try this at the command prompt: > > > > >>> ap._A__a > > '__a' > > > > It's still readable, and it's still writable too. The double- > > underscore naming is referred to as "name mangling" and while it's > > often passed off as the way to make private methods in Python (the > > tutorial even states this), what it is really intended for is to > > ensure that multiple inheritance works correctly: > > > > >>> class A(object): > > ... foo = 'A' > > ... def get_A_foo(self): > > ... return self.foo > > ... > > >>> class B(object): > > ... foo = 'B' > > ... def get_B_foo(self): > > ... return self.foo > > ... > > >>> class C(A, B): > > ... def __init__(self): > > ... super(C, self).__init__() > > ... > > >>> c = C() > > >>> c.get_A_foo() > > 'A' > > >>> c.get_B_foo() > > 'A' > > > > Here, we haven't mangled the attribute 'foo' on either A or B, so on > > the instance of C, which inherits from both, the inherited methods are > > referring to the same attribute, which is A's in this case due to the > > method resolution order. By re-naming 'foo' on both A and B to > > '__foo', each can then refer to their _own_ attribute, and also allow > > for C to have its own 'foo' attribute which doesn't conflict with > > either of them: > > > > >>> class A(object): > > ... __foo = 'A' > > ... def get_A_foo(self): > > ... return self.__foo > > ... > > >>> class B(object): > > ... __foo = 'B' > > ... def get_B_foo(self): > > ... return self.__foo > > ... > > >>> class C(A, B): > > ... foo = 'C' > > ... def __init__(self): > > ... super(C, self).__init__() > > ... > > >>> c = C() > > >>> c.get_A_foo() > > 'A' > > >>> c.get_B_foo() > > 'B' > > >>> c.foo > > 'C' > > > > There is no way to make an externally private attribute. This is > > generally considered a good thing by most Python developers: if I > > _need_ to access your class's implementation, I can do so, but the > > name mangling forces me to be aware that this is something you don't > > recommend doing. You'll often hear the term "consenting adults" used > > to refer to this, meaning we can all decide for ourselves if we're > > willing to risk using an implementation detail. what's the meaning of 'object' in class A(object) and class B(object) ? From steve+comp.lang.python at pearwood.info Sun Jan 20 10:15:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Jan 2013 15:15:42 GMT Subject: To make a method or attribute private References: <43381757-44d7-4807-b3cc-3d7d8b46348e@googlegroups.com> Message-ID: <50fc0a1d$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Jan 2013 06:52:32 -0800, iMath wrote: [snip many dozens of lines of irrelevant text] > what's the meaning of 'object' in > class A(object) > and > class B(object) ? Please trim your replies. We don't need to scroll past page after page of irrelevant text which we have already read. "object" is the name of the base class defining common methods used by all new classes. In Python 2, you should always subclass object, unless you are subclassing something else. In Python 3, subclassing object is automatic, whether you write it or not. In Python 2, if you fail to subclass object, you get an "old-style class", and features like property, classmethod, staticmethod, super and multiple inheritance may not work at all, or be buggy. -- Steven From steve+comp.lang.python at pearwood.info Wed Jan 16 21:38:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2013 02:38:58 GMT Subject: To make a method or attribute private References: Message-ID: <50f76441$0$29863$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Jan 2013 08:34:22 +0800, iMath wrote: >
To make a method or attribute private (inaccessible from the > outside), simply start its 
name with two > underscores

----?Beginning Python From Novice > to Professional?

but there is another saying > goes:
Beginning a variable name with a single underscore > indicates that the variable should be treated as > ?private?.

... Please do not send HTML emails to this newsgroup. -- Steven From redstone-cold at 163.com Sun Jan 20 20:14:36 2013 From: redstone-cold at 163.com (iMath) Date: Sun, 20 Jan 2013 17:14:36 -0800 (PST) Subject: To make a method or attribute private In-Reply-To: References: Message-ID: ? 2013?1?17????UTC+8??8?34?22??iMath??? > To make a method or attribute private (inaccessible from the outside), simply start its? > name with two underscores > > > ----?Beginning Python From Novice to Professional? > > > but there is another saying goes: > Beginning a variable name with a single underscore indicates that the variable should be treated as ?private?. > > > I test both these 2 rules ,it seems only names that start with two underscores are REAL private methods or attributes . > > > >>> class A: > ... ? ? def __init__(self): > ... ? ? ? ? self.a = 'a' > ... ? ? ? ? self._a = '_a' > ... ? ? ? ? self.__a = '__a' > ... > > > > > > > >>> ap = A() > >>> ap.a > 'a' > >>> ap._a > '_a' > >>> ap.__a > Traceback (most recent call last): > ? File "", line 1, in ? > AttributeError: A instance has no attribute '__a' > > > so what is your opinion about single leading underscore and private methods or attributes? so there is no REAL private variable in Python but conversion exists in it that python programmer should follow and recognize .right ? From rosuav at gmail.com Sun Jan 20 20:26:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Jan 2013 12:26:18 +1100 Subject: To make a method or attribute private In-Reply-To: References: Message-ID: On Mon, Jan 21, 2013 at 12:14 PM, iMath wrote: > so there is no REAL private variable in Python but conversion exists in it that python programmer should follow and recognize .right ? That's about it. If you think about C++ public members as the "interface" and private/protected members as the "implementation", then Python's convention is a leading underscore on the latter; you can reasonably expect that non-underscore members can be trusted to be maintained, but underscored members will quite possibly change in subsequent versions. Among smart people, conventions like this are all you need. ChrisA From steve+comp.lang.python at pearwood.info Sun Jan 20 22:27:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2013 03:27:37 GMT Subject: To make a method or attribute private References: Message-ID: <50fcb5a9$0$11101$c3e8da3@news.astraweb.com> On Sun, 20 Jan 2013 17:14:36 -0800, iMath wrote: [...] > so there is no REAL private variable in Python but conversion exists in > it that python programmer should follow and recognize .right ? There are no "REAL private variables" in most languages. Consider the C++ trick "#define private public". Or pointer tricks, or using reflection in Java. Yes, the convention in Python is that names starting with a single underscore should be considered private implementation details. -- Steven From rosuav at gmail.com Sun Jan 20 23:46:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Jan 2013 15:46:07 +1100 Subject: To make a method or attribute private In-Reply-To: <50fcb5a9$0$11101$c3e8da3@news.astraweb.com> References: <50fcb5a9$0$11101$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jan 21, 2013 at 2:27 PM, Steven D'Aprano wrote: > On Sun, 20 Jan 2013 17:14:36 -0800, iMath wrote: > > [...] >> so there is no REAL private variable in Python but conversion exists in >> it that python programmer should follow and recognize .right ? > > There are no "REAL private variables" in most languages. Consider the C++ > trick "#define private public". Or pointer tricks, or using reflection in > Java. Uhh, that's like saying there are no REAL floats in C, because you can #define float int And pointer tricks, well, you can do anything with raw memory access. These aren't proofs that something doesn't exist, they're proofs that trying to enforce privacy is bound to fail - so you may as well strip that code from your compiler/interpreter and go with the Python style. Much easier. I agree with your point, just not your argument. :) ChrisA From wuwei23 at gmail.com Mon Jan 21 00:44:48 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 Jan 2013 21:44:48 -0800 (PST) Subject: To make a method or attribute private References: <50fcb5a9$0$11101$c3e8da3@news.astraweb.com> Message-ID: <8b966006-9299-4e94-a7ac-8444e3a55201@po6g2000pbb.googlegroups.com> On Jan 21, 2:46?pm, Chris Angelico wrote: > These aren't proofs that something doesn't exist, they're proofs that > trying to enforce privacy is bound to fail But if you can't enforce it, can you really say it exists? Semantics, they are fun! I feel another PyWart post coming on... From lie.1296 at gmail.com Fri Jan 18 02:46:55 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 18 Jan 2013 18:46:55 +1100 Subject: To make a method or attribute private In-Reply-To: References: Message-ID: On 17/01/13 11:34, iMath wrote: > To make a method or attribute private (inaccessible from the outside), > simply start its name with two underscores > > ----?Beginning Python From Novice to Professional? > > but there is another saying goes: > Beginning a variable name with a single underscore indicates that the > variable should be treated as ?private?. > > I test both these 2 rules ,it seems only names that start with two > underscores are REAL private methods or attributes . Python does not have a REAL private methods/attributes. The double leading underscore is meant to trigger name mangling to avoid naming collisions with subclasses, the method/attribute is still accessible using the mangled name: >>> ap._A__a '__a' You generally only use double leading underscores when your private method/attribute is in a very high risk of having naming clashes with superclasses/subclasses. > so what is your opinion about single leading underscore and private > methods or attributes? We're all consenting adults. Use methods/attributes with single or double leading underscore at your own risk. Most programming languages do not actually have a private attribute that is totally inaccessible from outside, there are usually ways work around access restrictions, usually using reflections or pointers. Python only makes it easy to do so by making private variables only a convention. From monosij.forums at gmail.com Thu Jan 17 02:37:26 2013 From: monosij.forums at gmail.com (monosij.forums at gmail.com) Date: Wed, 16 Jan 2013 23:37:26 -0800 (PST) Subject: Importing Classes from child folders. Message-ID: Trying to do some OO Python with files in different directories. I have a blank __init__.py in each directory. It is my assumption that having an __init__.py marks the directory as a module. I am trying to run Controller.py from the command line. I would assume this has already been solved but could not find in forum I am somewhat new to Python. Using Python3 under Ubuntu. ... So I have a project structure as follows: ... ProjectX (root folder) __init__.py Controller.py + service (folder under ProjectX) __init__.py SystemSetup.py (has a class SystemSetup) + model (folder under ProjectX) __init__.py Directory.py (has a class Directory) In Controller.py if I want to use SystemSetup class, I do: from service.SystemSetup import SystemSetup ... and in Controller Class I have: def main(): systemSetup = SystemSetup() I get error: File "Controller.py", line 4, in from service.SystemSetup import SystemSetup ImportError: cannot import name SystemSetup What am I doing wrong? I am running from the command line. Do I need to set the project in PYTHONPATH first? But if SystemSetup and Directory are in same directory as Controller I have no problems. Your help would be highly appreciated. ... Btw I also tried: import sys, os.path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) from service.SystemSetup import SystemSetup ... No luck. Thank you again. Monosij From tm at tobix.eu Thu Jan 17 04:31:03 2013 From: tm at tobix.eu (Tobias M.) Date: Thu, 17 Jan 2013 10:31:03 +0100 Subject: Importing Classes from child folders. In-Reply-To: References: Message-ID: <50F7C4D7.1050807@tobix.eu> On an import python looks for the module in the directories specified in sys.path. The documentation on sys.path says: "As initialized upon program startup, the first item of this list is the directory containing the script that was used to invoke the Python interpreter." [1] So it`s important that the script you execute by passing it to the python interpreter is in your root folder ("ProjectX"). If this script is Controller.py, you might want to check the path there by: import sys print(sys.path) There should be an entry with a empty string ("") standing for the current directory. Note: This is just what I suggest according to my knowledge (I'm also a newbie in python). References: [1] http://docs.python.org/3.3/library/sys.html#sys.path On 17.01.2013 08:37, monosij.forums at gmail.com wrote: > Trying to do some OO Python with files in different directories. > I have a blank __init__.py in each directory. > It is my assumption that having an __init__.py marks the directory as a module. > I am trying to run Controller.py from the command line. > > I would assume this has already been solved but could not find in forum > I am somewhat new to Python. Using Python3 under Ubuntu. > ... > So I have a project structure as follows: > ... > ProjectX (root folder) > __init__.py > Controller.py > + service (folder under ProjectX) > __init__.py > SystemSetup.py (has a class SystemSetup) > + model (folder under ProjectX) > __init__.py > Directory.py (has a class Directory) > > In Controller.py if I want to use SystemSetup class, I do: > from service.SystemSetup import SystemSetup > ... > and in Controller Class I have: > def main(): > systemSetup = SystemSetup() > > I get error: > File "Controller.py", line 4, in > from service.SystemSetup import SystemSetup > ImportError: cannot import name SystemSetup > > What am I doing wrong? I am running from the command line. > Do I need to set the project in PYTHONPATH first? > > But if SystemSetup and Directory are in same directory as Controller I have no problems. > > Your help would be highly appreciated. > ... > Btw I also tried: > import sys, os.path > sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) > from service.SystemSetup import SystemSetup > ... > No luck. > > Thank you again. > > Monosij From warem2888 at gmail.com Thu Jan 17 04:56:21 2013 From: warem2888 at gmail.com (Constantine) Date: Thu, 17 Jan 2013 01:56:21 -0800 (PST) Subject: Big girl pleasuring herself Message-ID: <67a721e3-20a9-4d96-9219-33e31bad5295@googlegroups.com> Big girl pleasuring herself http://ninelirowaytu.blogspot.com/2013/01/big-girl-pleasuring-herself.html From wolfgang.maier at biologie.uni-freiburg.de Thu Jan 17 05:35:31 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 17 Jan 2013 11:35:31 +0100 Subject: iterating over the lines of a file - difference between Python 2.7 and 3? Message-ID: <000301cdf49e$602fd510$208f7f30$@biologie.uni-freiburg.de> I just came across an unexpected behavior in Python 3.3, which has to do with file iterators and their interplay with other methods of file/IO class methods, like readline() and tell(): Basically, I got used to the fact that it is a bad idea to mix them because the iterator would use that hidden read-ahead buffer, so what you got with subsequent calls to readline() or tell() was what was beyond that buffer, but not the next thing after what the iterator just returned. Example: in_file_object=open(?some_file?,?rb?) for line in in_file_object: print (line) if in_file_object.tell() > 300: # assuming that individual lines are shorter break This wouldn?t print anything in Python 2.7 since next(in_file_object) would read ahead beyond the 300 position immediately, as evidenced by a subsequent call to in_file_object.tell() (returning 8192 on my system). However, I find that under Python 3.3 this same code works: it prints some lines from my file and after completing in_file_object.tell() returns a quite reasonable 314 as the current position in the file. I couldn?t find this difference anywhere in the documentation. Is the 3.3 behavior official, and if so, when was it introduced and how is it implemented? I assume the read-ahead buffer still exists? By the way, the 3.3 behavior only works in binary mode. In text mode, the code will raise an OSError: telling position disabled by next() call. In Python 2.7 there was no difference between the binary and text mode behavior. Could not find this documented either. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Jan 17 07:04:25 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 17 Jan 2013 13:04:25 +0100 Subject: iterating over the lines of a file - difference between Python 2.7 and 3? References: <000301cdf49e$602fd510$208f7f30$@biologie.uni-freiburg.de> Message-ID: Wolfgang Maier wrote: > I just came across an unexpected behavior in Python 3.3, which has to do > with file iterators and their interplay with other methods of file/IO > class methods, like readline() and tell(): Basically, I got used to the > fact that it is a bad idea to mix them because the iterator would use that > hidden read-ahead buffer, so what you got with subsequent calls to > readline() or tell() was what was beyond that buffer, but not the next > thing after what the iterator just returned. > > Example: > > in_file_object=open(?some_file?,?rb?) > > for line in in_file_object: > > print (line) > > if in_file_object.tell() > 300: > > # assuming that individual lines are > # shorter > > break > > > > This wouldn?t print anything in Python 2.7 since next(in_file_object) > would read ahead beyond the 300 position immediately, as evidenced by a > subsequent call to in_file_object.tell() (returning 8192 on my system). > > However, I find that under Python 3.3 this same code works: it prints some > lines from my file and after completing in_file_object.tell() returns a > quite reasonable 314 as the current position in the file. > > I couldn?t find this difference anywhere in the documentation. Is the 3.3 > behavior official, and if so, when was it introduced and how is it > implemented? I assume the read-ahead buffer still exists? You can get the Python 3 behaviour with io.open() in Python 2.7. There is an implementation in Python in _pyio.py: def tell(self): return _BufferedIOMixin.tell(self) - len(self._read_buf) + self._read_pos > By the way, the 3.3 behavior only works in binary mode. In text mode, the > code will raise an OSError: telling position disabled by next() call. In > Python 2.7 there was no difference between the binary and text mode > behavior. Could not find this documented either. From tjreedy at udel.edu Thu Jan 17 08:39:52 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 Jan 2013 08:39:52 -0500 Subject: iterating over the lines of a file - difference between Python 2.7 and 3? In-Reply-To: References: <000301cdf49e$602fd510$208f7f30$@biologie.uni-freiburg.de> Message-ID: On 1/17/2013 7:04 AM, Peter Otten wrote: > Wolfgang Maier wrote: > >> I just came across an unexpected behavior in Python 3.3, which has to do >> with file iterators and their interplay with other methods of file/IO >> class methods, like readline() and tell(): Basically, I got used to the >> fact that it is a bad idea to mix them because the iterator would use that >> hidden read-ahead buffer, so what you got with subsequent calls to >> readline() or tell() was what was beyond that buffer, but not the next >> thing after what the iterator just returned. >> >> Example: >> >> in_file_object=open(?some_file?,?rb?) >> >> for line in in_file_object: >> >> print (line) >> >> if in_file_object.tell() > 300: >> >> # assuming that individual lines are >> # shorter >> >> break >> >> >> >> This wouldn?t print anything in Python 2.7 since next(in_file_object) >> would read ahead beyond the 300 position immediately, as evidenced by a >> subsequent call to in_file_object.tell() (returning 8192 on my system). >> >> However, I find that under Python 3.3 this same code works: it prints some >> lines from my file and after completing in_file_object.tell() returns a >> quite reasonable 314 as the current position in the file. >> >> I couldn?t find this difference anywhere in the documentation. Is the 3.3 >> behavior official, and if so, when was it introduced and how is it >> implemented? I assume the read-ahead buffer still exists? > > You can get the Python 3 behaviour with io.open() in Python 2.7. There is an > implementation in Python in _pyio.py: > > def tell(self): > return _BufferedIOMixin.tell(self) - len(self._read_buf) + > self._read_pos In 2.7, open returns file object, which is a thin wrapper of the particular (proprietary) C compiler stdio library. They vary because the C standard leaves some things implementation-defined, and people interpret differently (no official test suite, at least not originally), and people make mistakes. The io module is intended to bring more uniformity, and there is a test suite for other implementations to match actual behavior to. -- Terry Jan Reedy From wolfgang.maier at biologie.uni-freiburg.de Thu Jan 17 11:38:30 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 17 Jan 2013 17:38:30 +0100 Subject: iterating over the lines of a file - difference between Python 2.7 and 3? Message-ID: <005f01cdf4d1$15836fd0$408a4f70$@biologie.uni-freiburg.de> Thanks Peter, for this very helpful reply and for pointing out _pyio.py to me! It's great to be able to check implementation details sometimes. So, if I understand you correctly, I can simply import io and open files with io.open() - instead of open and although this is a bit a detour in Python3 - and this will ensure version-independent behavior of my code? That?s cool! What will my IO object return then when I read from it in Python 2.7? str where Python3 gives bytes, and unicode instead of str ? This is what I understood from the Python 2.7 io module doc. -----Original Message----- From: Peter Otten [mailto:__peter__ at web.de] Sent: Thursday, January 17, 2013 1:04 PM To: python-list at python.org Subject: Re: iterating over the lines of a file - difference between Python 2.7 and 3? You can get the Python 3 behaviour with io.open() in Python 2.7. There is an implementation in Python in _pyio.py: def tell(self): return _BufferedIOMixin.tell(self) - len(self._read_buf) + self._read_pos Wolfgang Maier wrote: > I just came across an unexpected behavior in Python 3.3, which has to > do with file iterators and their interplay with other methods of > file/IO class methods, like readline() and tell(): Basically, I got > used to the fact that it is a bad idea to mix them because the > iterator would use that hidden read-ahead buffer, so what you got with > subsequent calls to > readline() or tell() was what was beyond that buffer, but not the next > thing after what the iterator just returned. > > Example: > > in_file_object=open(?some_file?,?rb?) > > for line in in_file_object: > > print (line) > > if in_file_object.tell() > 300: > > # assuming that individual lines are > # shorter > > break > > > > This wouldn?t print anything in Python 2.7 since next(in_file_object) > would read ahead beyond the 300 position immediately, as evidenced by > a subsequent call to in_file_object.tell() (returning 8192 on my system). > > However, I find that under Python 3.3 this same code works: it prints > some lines from my file and after completing in_file_object.tell() > returns a quite reasonable 314 as the current position in the file. > > I couldn?t find this difference anywhere in the documentation. Is the > 3.3 behavior official, and if so, when was it introduced and how is it > implemented? I assume the read-ahead buffer still exists? > > By the way, the 3.3 behavior only works in binary mode. In text mode, the > code will raise an OSError: telling position disabled by next() call. In > Python 2.7 there was no difference between the binary and text mode > behavior. Could not find this documented either. From __peter__ at web.de Thu Jan 17 12:59:46 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 17 Jan 2013 18:59:46 +0100 Subject: iterating over the lines of a file - difference between Python 2.7 and 3? References: <005f01cdf4d1$15836fd0$408a4f70$@biologie.uni-freiburg.de> Message-ID: Wolfgang Maier wrote: > What will my IO object return then when I read from it in Python 2.7? str > where Python3 gives bytes, and unicode instead of str ? This is what I > understood from the Python 2.7 io module doc. You can always double-check in the interpreter: >>> with open("tmp.txt", "w") as f: f.write("let's try\n") ... >>> import io >>> with io.open("tmp.txt", "r") as f: print type(f.read()) ... >>> with io.open("tmp.txt", "rb") as f: print type(f.read()) ... So yes. Also: >>> str is bytes True From goffi at goffi.org Thu Jan 17 07:34:35 2013 From: goffi at goffi.org (Goffi) Date: Thu, 17 Jan 2013 13:34:35 +0100 Subject: [ANN] Salut =?UTF-8?B?w6A=?= Toi 0.3: Python social XMPP client Message-ID: <50f7efdc$0$21913$426a74cc@news.free.fr> G'day everybody, I've released the 0.3 version of Salut ? Toi, a python XMPP client, which is multi-frontends (desktop, web, console, cli). You can see a live demo on http://www.libervia.org . S?T is made using Twisted/Wokkel, and Pyjamas for the web frontend. It offers features such as microblogging (with access restriction), games, pipe over XMPP or collective radio, and there is a social contract ( which can be seen on http://sat.goffi.org ). It's a free software (AGPL v3+) I'm looking for people who would like to help on this project, and looking for alternative to websites like fb or g+. Here is the release announce: http://www.goffi.org/post/2013/01/11/Salut-%C3%A0-Toi-version-0.3.0-%28with- demo-online-%21%29 Cheers Goffi From alt.mcarter at gmail.com Thu Jan 17 09:35:29 2013 From: alt.mcarter at gmail.com (Mark Carter) Date: Thu, 17 Jan 2013 06:35:29 -0800 (PST) Subject: Param decorator - can you suggest improvements Message-ID: <00a6f42e-58e9-4e5e-b124-5b315990829c@googlegroups.com> I thought it would be interesting to try to implement Scheme SRFI 39 (Parameter objects) in Python. The idea is that you define a function that returns a default value. If you call that function with no arguments, it returns the current default. If you call it with an argument, it resets the default to the value passed in. Here's a working implementation: # http://www.artima.com/weblogs/viewpost.jsp?thread=240845 from functools import wraps class Param(object): def __init__(self, default): self.default = default #self.func = func def __call__(self, func, *args): @wraps(func) def wrapper(*args): #print 'calling hi' if len(args) >0: self.default = args[0] #print len(args), ' ', args return self.default # self.func(*args) return wrapper @Param(42) def hi(newval): pass print hi() # 42 print hi(12) # 12 print hi() # 12 hi(13) # sets it to 13 print hi() # 13 Can anyone suggest a better implementation? From steve+comp.lang.python at pearwood.info Thu Jan 17 10:21:08 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2013 15:21:08 GMT Subject: Param decorator - can you suggest improvements References: <00a6f42e-58e9-4e5e-b124-5b315990829c@googlegroups.com> Message-ID: <50f816e3$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote: > I thought it would be interesting to try to implement Scheme SRFI 39 > (Parameter objects) in Python. > > The idea is that you define a function that returns a default value. If > you call that function with no arguments, it returns the current > default. If you call it with an argument, it resets the default to the > value passed in. Here's a working implementation: [...] > Can anyone suggest a better implementation? I don't like the decorator version, because it requires creating a do- nothing function that just gets thrown away. He's my version, a factory function that takes two arguments, the default value and an optional function name, and returns a Param function: def param(default, name=None): SENTINEL = object() default = [default] def param(arg=SENTINEL): if arg is SENTINEL: return default[0] else: default[0] = arg return arg if name is not None: param.__name__ = name return param In Python 3, it's even nicer, although no shorter: def param(default, name=None): SENTINEL = object() def param(arg=SENTINEL): nonlocal default if arg is SENTINEL: return default else: default = arg return arg if name is not None: param.__name__ = name return param -- Steven From dan at tombstonezero.net Thu Jan 17 22:38:08 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 18 Jan 2013 03:38:08 GMT Subject: Param decorator - can you suggest improvements References: <00a6f42e-58e9-4e5e-b124-5b315990829c@googlegroups.com> <50f816e3$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 17 Jan 2013 15:21:08 +0000, Steven D'Aprano wrote: > On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote: > >> I thought it would be interesting to try to implement Scheme SRFI 39 >> (Parameter objects) in Python. >> >> The idea is that you define a function that returns a default value. If >> you call that function with no arguments, it returns the current >> default. If you call it with an argument, it resets the default to the >> value passed in. Here's a working implementation: > [...] >> Can anyone suggest a better implementation? > > I don't like the decorator version, because it requires creating a do- > nothing function that just gets thrown away. He's my version, a factory > function that takes two arguments, the default value and an optional > function name, and returns a Param function: > [...] This, or something like this, is very old: sentinel = object() class Magic: def __init__(self, value): self.value = value def __call__(self, value=sentinel): if value != sentinel: self.value = value return self.value It's not a function, nor a decorator, but it behaves like a function. I'm pretty sure that it's from Alex Martelli, and ended up as an ActiveState recipe at some point, but I can't find it now (I didn't look very hard). It may have been called Magic, or it may have been called Pocket. And the sentinel may have been None, but then you can't set the value to None (at least not through the apparent API). Dan From steve+comp.lang.python at pearwood.info Fri Jan 18 04:10:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jan 2013 09:10:34 GMT Subject: Param decorator - can you suggest improvements References: <00a6f42e-58e9-4e5e-b124-5b315990829c@googlegroups.com> <50f816e3$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50f9118a$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Jan 2013 03:38:08 +0000, Dan Sommers wrote: > On Thu, 17 Jan 2013 15:21:08 +0000, Steven D'Aprano wrote: > >> On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote: >> >>> I thought it would be interesting to try to implement Scheme SRFI 39 >>> (Parameter objects) in Python. >>> >>> The idea is that you define a function that returns a default value. >>> If you call that function with no arguments, it returns the current >>> default. If you call it with an argument, it resets the default to the >>> value passed in. Here's a working implementation: >> [...] >>> Can anyone suggest a better implementation? >> >> I don't like the decorator version, because it requires creating a do- >> nothing function that just gets thrown away. He's my version, a factory >> function that takes two arguments, the default value and an optional >> function name, and returns a Param function: [...] > > This, or something like this, is very old: > > sentinel = object() > class Magic: > def __init__(self, value): > self.value = value > def __call__(self, value=sentinel): > if value != sentinel: > self.value = value > return self.value There's not really any magic in that :-) Better to use "if value is not sentinel" rather than != because the caller might provide a custom object that compares equal to sentinel. Also you should name it SENTINEL, or even _SENTINEL, to indicate that it is (1) a constant, and (2) a private variable. > It's not a function, nor a decorator, but it behaves like a function. A callable, so-called because you can call it :-) I believe that C++ calls it a "functor", not to be confused with what Haskell calls a functor, which is completely different. -- Steven From dan at tombstonezero.net Fri Jan 18 09:18:48 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 18 Jan 2013 14:18:48 GMT Subject: Param decorator - can you suggest improvements References: <00a6f42e-58e9-4e5e-b124-5b315990829c@googlegroups.com> <50f816e3$0$30003$c3e8da3$5496439d@news.astraweb.com> <50f9118a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 18 Jan 2013 09:10:34 +0000, Steven D'Aprano wrote: > On Fri, 18 Jan 2013 03:38:08 +0000, Dan Sommers wrote: >> This, or something like this, is very old: >> >> sentinel = object() >> class Magic: >> def __init__(self, value): >> self.value = value >> def __call__(self, value=sentinel): >> if value != sentinel: >> self.value = value >> return self.value > > There's not really any magic in that :-) Well, not any more, no, but this one has stuck in my mind because of the magic it revealed the first time I saw it. It was definitely one of those Aha! moments for me. > Better to use "if value is not sentinel" rather than != because the > caller might provide a custom object that compares equal to sentinel. > > Also you should name it SENTINEL, or even _SENTINEL, to indicate that it > is (1) a constant, and (2) a private variable. Both fair points. > I believe that C++ calls it a "functor", not to be confused with what > Haskell calls a functor, which is completely different. But we like overloaded terminology! ;-) Dan From doetoe at gmail.com Thu Jan 17 10:02:24 2013 From: doetoe at gmail.com (Utpal Sarkar) Date: Thu, 17 Jan 2013 07:02:24 -0800 (PST) Subject: python sys.stdout and C++ iostreams::cout Message-ID: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> Hi, I was assuming that sys.stdout would be referencing the same physical stream as iostreams::cout running in the same process, but this doesn't seem to be the case. The following code, which makes a call to a C++ function with a python wrapper called "write", that writes to cout: from cStringIO import StringIO import sys orig_stdout = sys.stdout sys.stdout = stringout = StringIO() write("cout") # wrapped C++ function that writes to cout print "-" * 40 print "stdout" sys.stdout = orig_stdout print stringout.getvalue() immediately writes "cout" to the console, then the separator "---...", and finally, as the return value of stringout.getvalue(), the string "stdout". My intention was to capture in stringout also the string written to cout from C++. Does anyone know what is going on, and if so, how I can capture what is written to cout in a python string? Thanks in advance. From nobody at nowhere.com Thu Jan 17 10:35:27 2013 From: nobody at nowhere.com (Nobody) Date: Thu, 17 Jan 2013 15:35:27 +0000 Subject: python sys.stdout and C++ iostreams::cout References: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> Message-ID: On Thu, 17 Jan 2013 07:02:24 -0800, Utpal Sarkar wrote: > I was assuming that sys.stdout would be referencing the same physical > stream as iostreams::cout running in the same process, but this doesn't > seem to be the case. At startup, it refers to the same FILE* as C's stdout. This initially shares a buffer with C++'s std::cout, but that can be changed via std::ios_base::sync_with_stdio(). However ... > The following code, which makes a call to a C++ > function with a python wrapper called "write", that writes to cout: > > from cStringIO import StringIO > import sys > orig_stdout = sys.stdout > sys.stdout = stringout = StringIO() > write("cout") # wrapped C++ function that writes to cout print "-" * 40 > print "stdout" > sys.stdout = orig_stdout > print stringout.getvalue() This code changes sys.stdout so that it refers to something other than C's stdout. C's stdout is still the same FILE*, C++'s std::count is still the same std::ostream, and the synchronisation between the two hasn't changed. > immediately writes "cout" to the console, then the separator "---...", and > finally, as the return value of stringout.getvalue(), the string "stdout". > My intention was to capture in stringout also the string written to cout > from C++. Does anyone know what is going on, and if so, how I can capture > what is written to cout in a python string? Changing sys.stdout doesn't (and cannot) have any effect upon how C or C++ code behaves. sys.stdout is just a Python variable. If you want to capture output from C or C++ code, you'll have to do so via other means, e.g. freopen() or dup2(). From rosuav at gmail.com Thu Jan 17 10:42:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Jan 2013 02:42:24 +1100 Subject: python sys.stdout and C++ iostreams::cout In-Reply-To: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> References: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> Message-ID: On Fri, Jan 18, 2013 at 2:02 AM, Utpal Sarkar wrote: > I was assuming that sys.stdout would be referencing the same physical stream as iostreams::cout running in the same process, but this doesn't seem to be the case. That's more-or-less true, but there will likely be separate buffering, so even without redirection you might see some oddities. But the problem with your code is that you're not actually redirecting stdout in any way; you're catching, at a fairly high level, everything that Python would otherwise have sent there. Is there any way that you can get the C++ code to offer a way to redirect its output? Otherwise, you're going to have to fiddle around with the usual mess of I/O redirection (with dup2), and you can only send it to what the OS sees as a file (so, no StringIO buffer). So to achieve your goal, you may need either a temporary physical file, or some sort of pipe (and worry about reading from it before it fills up, etc, etc). There may be alternatives, but in any case, the easiest way is going to be with some assistance from the C++ function. ChrisA From doetoe at gmail.com Thu Jan 17 10:51:42 2013 From: doetoe at gmail.com (Utpal Sarkar) Date: Thu, 17 Jan 2013 07:51:42 -0800 (PST) Subject: python sys.stdout and C++ iostreams::cout In-Reply-To: References: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> Message-ID: <1908dad0-7f29-4b54-a244-7cb89510e9b0@googlegroups.com> Thanks a lot Chris and Nobody! I'll have a look at dup2 for a start. > > I was assuming that sys.stdout would be referencing the same physical stream as iostreams::cout running in the same process, but this doesn't seem to be the case. > > > > That's more-or-less true, but there will likely be separate buffering, > > so even without redirection you might see some oddities. But the > > problem with your code is that you're not actually redirecting stdout > > in any way; you're catching, at a fairly high level, everything that > > Python would otherwise have sent there. > > > > Is there any way that you can get the C++ code to offer a way to > > redirect its output? Otherwise, you're going to have to fiddle around > > with the usual mess of I/O redirection (with dup2), and you can only > > send it to what the OS sees as a file (so, no StringIO buffer). So to > > achieve your goal, you may need either a temporary physical file, or > > some sort of pipe (and worry about reading from it before it fills up, > > etc, etc). There may be alternatives, but in any case, the easiest way > > is going to be with some assistance from the C++ function. > > > > ChrisA From rosuav at gmail.com Thu Jan 17 10:54:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Jan 2013 02:54:53 +1100 Subject: python sys.stdout and C++ iostreams::cout In-Reply-To: <1908dad0-7f29-4b54-a244-7cb89510e9b0@googlegroups.com> References: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> <1908dad0-7f29-4b54-a244-7cb89510e9b0@googlegroups.com> Message-ID: On Fri, Jan 18, 2013 at 2:51 AM, Utpal Sarkar wrote: > Thanks a lot Chris and Nobody! I'll have a look at dup2 for a start. Okay. Look for code that redirects the standard I/O streams and then exec()s another process (possibly after fork()ing); you're going to be doing pretty much the same thing. Good luck, have fun. It's a LOT messier than simply assigning to sys.stdout, unfortunately. ChrisA From doetoe at gmail.com Thu Jan 17 10:51:42 2013 From: doetoe at gmail.com (Utpal Sarkar) Date: Thu, 17 Jan 2013 07:51:42 -0800 (PST) Subject: python sys.stdout and C++ iostreams::cout In-Reply-To: References: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> Message-ID: <1908dad0-7f29-4b54-a244-7cb89510e9b0@googlegroups.com> Thanks a lot Chris and Nobody! I'll have a look at dup2 for a start. > > I was assuming that sys.stdout would be referencing the same physical stream as iostreams::cout running in the same process, but this doesn't seem to be the case. > > > > That's more-or-less true, but there will likely be separate buffering, > > so even without redirection you might see some oddities. But the > > problem with your code is that you're not actually redirecting stdout > > in any way; you're catching, at a fairly high level, everything that > > Python would otherwise have sent there. > > > > Is there any way that you can get the C++ code to offer a way to > > redirect its output? Otherwise, you're going to have to fiddle around > > with the usual mess of I/O redirection (with dup2), and you can only > > send it to what the OS sees as a file (so, no StringIO buffer). So to > > achieve your goal, you may need either a temporary physical file, or > > some sort of pipe (and worry about reading from it before it fills up, > > etc, etc). There may be alternatives, but in any case, the easiest way > > is going to be with some assistance from the C++ function. > > > > ChrisA From lie.1296 at gmail.com Fri Jan 18 02:21:47 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 18 Jan 2013 18:21:47 +1100 Subject: python sys.stdout and C++ iostreams::cout In-Reply-To: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> References: <2699150a-cf67-46ac-b863-34c92bffceaf@googlegroups.com> Message-ID: On 18/01/13 02:02, Utpal Sarkar wrote: > Hi, > > I was assuming that sys.stdout would be referencing the same physical stream as iostreams::cout running in the same process, but this doesn't seem to be the case. > The following code, which makes a call to a C++ function with a python wrapper called "write", that writes to cout: > > from cStringIO import StringIO > import sys > orig_stdout = sys.stdout > sys.stdout = stringout = StringIO() > write("cout") # wrapped C++ function that writes to cout > print "-" * 40 > print "stdout" > sys.stdout = orig_stdout > print stringout.getvalue() > > immediately writes "cout" to the console, then the separator "---...", and finally, as the return value of stringout.getvalue(), the string "stdout". > My intention was to capture in stringout also the string written to cout from C++. > Does anyone know what is going on, and if so, how I can capture what is written to cout in a python string? > > Thanks in advance. > You might have a better luck if you check std::ios::rdbuf (http://www.cplusplus.com/reference/ios/ios/rdbuf/) Using std::ios::rdbuf() you can get the cout's streambuf, which is a filebuf for the stdout and then use std::ios::rdbuf(streambuf*) to replace cout's internal streambuf and replace it with your own implementation that captures everything written using cout before passing it back to the original streambuf. This is essentially similar to assigning to sys.stdout in python. From Arah.Leonard at bruker-axs.com Thu Jan 17 10:29:28 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 17 Jan 2013 15:29:28 +0000 Subject: Thorough Python 2.7.3 Windows Build Documentation? Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> Hello fellow Python programmers, I'm building a 32-bit CPython 2.7.3 distro for Windows using the MS Visual Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler. My build works, technically, but it also happens to benchmark over 30% slower than the precompiled binaries in the distributed Python 2.7.3 MSI. Can anyone point me in the direction of some thoroughly detailed build documentation so that I can figure out how to get that 30% back with my build? The only documentation that I can find just says MSVC 9, period. There's no mention of SP1 or not, hotfixes, nor of any specific compiler/linker optimizations used to build the official distro. Something, somewhere, has to be significantly different between our builds for a 30% performance difference, and it'd probably be handy for the Python community to know how to avoid the same pitfall that cost me performance so that we can all get the most out of Python. Any and all help will be greatly appreciated. Thanks. Sincerely, Arah Leonard Arah Leonard Software Development Engineer Bruker AXS Inc. 5465 East Cheryl Parkway Madison, WI 53711 US Phone: +1 608-276-3812 Phone: +1 800-234-XRAY(9729) Fax: Arah.Leonard at bruker-axs.com www.bruker.com ________________________________ The information contained in this email is confidential. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, reproduction, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Jan 17 10:55:10 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 Jan 2013 10:55:10 -0500 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> Message-ID: On 1/17/2013 10:29 AM, Leonard, Arah wrote: > Hello fellow Python programmers, > > I?m building a 32-bit CPython 2.7.3 distro for Windows using the MS > Visual Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler. > My build works, technically, but it also happens to benchmark over 30% > slower than the precompiled binaries in the distributed Python 2.7.3 > MSI. Can anyone point me in the direction of some thoroughly detailed > build documentation so that I can figure out how to get that 30% back > with my build? The only documentation that I can find just says MSVC 9, > period. There?s no mention of SP1 or not, hotfixes, nor of any specific > compiler/linker optimizations used to build the official distro. > Something, somewhere, has to be significantly different between our > builds for a 30% performance difference, and it?d probably be handy for > the Python community to know how to avoid the same pitfall that cost me > performance so that we can all get the most out of Python. Any and all > help will be greatly appreciated. Thanks. The 'documentation' of how we build Python on Windows is the PCBuild directory in the source tree. -- Terry Jan Reedy From stefan at bytereef.org Thu Jan 17 11:12:42 2013 From: stefan at bytereef.org (Stefan Krah) Date: Thu, 17 Jan 2013 17:12:42 +0100 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> Message-ID: <20130117161242.GA8527@sleipnir.bytereef.org> Leonard, Arah wrote: > I?m building a 32-bit CPython 2.7.3 distro for Windows using the MS Visual > Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler. My build > works, technically, but it also happens to benchmark over 30% slower than the > precompiled binaries in the distributed Python 2.7.3 MSI. Can anyone point me > in the direction of some thoroughly detailed build documentation so that I can > figure out how to get that 30% back with my build? I think the official binaries use the PGO build. Be sure to run all tests thoroughly, we've had problems in with the PGO build in 3.3. Stefan Krah From Arah.Leonard at bruker-axs.com Thu Jan 17 12:09:42 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 17 Jan 2013 17:09:42 +0000 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <20130117161242.GA8527@sleipnir.bytereef.org> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> <20130117161242.GA8527@sleipnir.bytereef.org> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07585387@msnmail2.bruker-axs.com> > I think the official binaries use the PGO build. Be sure to run all tests thoroughly, we've had problems in with the PGO build in 3.3. Thanks Stefan. I hope that's not the case. PGO seems something of an anathema from well-documented builds. Unless I'm missing something, if PGO is used it means that without knowing the specific CPU of the build machine there would be no way to reliably duplicate the build except by accident. Even with knowing, unless you have the same CPU... But after benchmarking a PGO build made by running the build_pgo.bat it turns out that it made no difference whatsoever to my performance loss. Within an acceptable statistical variation in the benchmark tool itself my PGO build performed identically to my regular build. Which means that I'm still running 30% slower than the precompiled binaries somehow even though I'm theoretically using the right compiler. And which also means that I can neither confirm nor deny if the released precompiled binaries are PGO builds or not. It's one of those days I guess. But thanks anyway. I appreciate the useful input. And yes, absolutely thorough testing is on the agenda. :) Sincerely, Arah Leonard From stefan at bytereef.org Thu Jan 17 12:29:52 2013 From: stefan at bytereef.org (Stefan Krah) Date: Thu, 17 Jan 2013 18:29:52 +0100 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07585387@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> <20130117161242.GA8527@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E07585387@msnmail2.bruker-axs.com> Message-ID: <20130117172952.GA20265@sleipnir.bytereef.org> Leonard, Arah wrote: > But after benchmarking a PGO build made by running the build_pgo.bat it turns out that it made no difference whatsoever to my performance loss. Within an acceptable statistical variation in the benchmark tool itself my PGO build performed identically to my regular build. Which means that I'm still running 30% slower than the precompiled binaries somehow even though I'm theoretically using the right compiler. And which also means that I can neither confirm nor deny if the released precompiled binaries are PGO builds or not. I remember that some versions of Visual Studio silently completed the PGO build without actually having PGO capabilities. :) I think for VS 2008 at least "Professional" is needed, for VS 2010 "Ultimate". Stefan Krah From Arah.Leonard at bruker-axs.com Thu Jan 17 13:10:17 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 17 Jan 2013 18:10:17 +0000 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <20130117172952.GA20265@sleipnir.bytereef.org> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> <20130117161242.GA8527@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E07585387@msnmail2.bruker-axs.com> <20130117172952.GA20265@sleipnir.bytereef.org> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E075853B8@msnmail2.bruker-axs.com> > I remember that some versions of Visual Studio silently completed the PGO build without actually having PGO capabilities. :) > I think for VS 2008 at least "Professional" is needed, for VS 2010 "Ultimate". Well, that certainly sounds like Microsoft. Fortunately I'm using VS 2008 Professional, so I guess that's not it. :( But thanks! By the way, do you happen to know how tricky it is to get Python 2.7.3 to build with VS 2010? Or have any tips there? It doesn't seem to be officially supported, but it sure would be nice to get out of the dark ages of MS compilers and be only one version behind the latest. From stefan at bytereef.org Thu Jan 17 14:54:51 2013 From: stefan at bytereef.org (Stefan Krah) Date: Thu, 17 Jan 2013 20:54:51 +0100 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E075853B8@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> <20130117161242.GA8527@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E07585387@msnmail2.bruker-axs.com> <20130117172952.GA20265@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E075853B8@msnmail2.bruker-axs.com> Message-ID: <20130117195451.GA32407@sleipnir.bytereef.org> Leonard, Arah wrote: > By the way, do you happen to know how tricky it is to get Python 2.7.3 to build with VS 2010? Or have any tips there? It doesn't seem to be officially supported, but it sure would be nice to get out of the dark ages of MS compilers and be only one version behind the latest. I wouldn't attempt it. For Python 3.3 the conversion has been done and the diff was enormous. Stefan Krah From Arah.Leonard at bruker-axs.com Thu Jan 17 17:19:25 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 17 Jan 2013 22:19:25 +0000 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <20130117195451.GA32407@sleipnir.bytereef.org> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> <20130117161242.GA8527@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E07585387@msnmail2.bruker-axs.com> <20130117172952.GA20265@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E075853B8@msnmail2.bruker-axs.com> <20130117195451.GA32407@sleipnir.bytereef.org> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07585443@msnmail2.bruker-axs.com> Hello Python programmers, Here's an update on my conundrum: When compiling and building CPython 2.7.3 for Win32 from source I see a 30% performance loss from the precompiled binaries in the Python 2.7.3 MSI. Everything that I do gets the same results. I've tried a standard release build. I've tried a PGO build by running build_pgo.bat. I've tried changing every compile and link optimization flag manually. I've tried VS 2008 Professional with SP1 and hotfixes applied, and then without. I've even tried building on two different PCs just in case. I always get the same results: 30% less performance than the precompiled binaries. Frankly, I'm out of things to try. All that I can imagine at this point is that maybe a different edition of VS 2008 creates a 30% faster executable than the Professional edition I have access to? If anyone has specific knowledge of the exact build machine hardware and compiler version used to create the Win32 Python 2.7.3 precompiled binaries I would greatly appreciate knowing how to duplicate that verbatim. Thanks. Sincerely, Arah Leonard From Arah.Leonard at bruker-axs.com Mon Jan 21 11:28:14 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Mon, 21 Jan 2013 16:28:14 +0000 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07585443@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> <20130117161242.GA8527@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E07585387@msnmail2.bruker-axs.com> <20130117172952.GA20265@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E075853B8@msnmail2.bruker-axs.com> <20130117195451.GA32407@sleipnir.bytereef.org> <2ECADBDABCB17E40B66A25D839706F5E07585443@msnmail2.bruker-axs.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07585C74@msnmail2.bruker-axs.com> Hello again Python programmers, Final update on my Python 2.7.3 build issues. After much insanity I finally used a process sniffer when running Python and tracked down that because of a path environment variable and the stupidity of Microsoft, Windows was loading another python27.dll rather than the one in the directory with the python.exe that I built, thus rendering my former tests useless. Sorting this out using the .exe.local trick, I was able to re-test everything and come to reliable conclusions. Based on performance results, it is without a doubt in my mind that the Python 2.7.3 precompiled binaries in the MSI are a PGO build. I can now build my own binaries with the same performance as the released precompiled binaries. And on my machine at least, these PGO built binaries do perform 30-36% faster than a normal release build. Useful information if you're doing your own Python builds. I'd still like to see Python start including some thorough build documentation on each release, but I'm certainly not going to be holding my breath on that. ;) Cheers. Sincerely, Arah Leonard From donarb at nwlink.com Thu Jan 17 12:51:26 2013 From: donarb at nwlink.com (donarb) Date: Thu, 17 Jan 2013 09:51:26 -0800 (PST) Subject: Thorough Python 2.7.3 Windows Build Documentation? References: Message-ID: <6df5947a-5665-4b92-906d-5aba9e399b5b@d10g2000yqe.googlegroups.com> On Jan 17, 7:29?am, "Leonard, Arah" wrote: > Hello fellow Python programmers, > > I'm building a 32-bit CPython 2.7.3 distro for Windows using the MS Visual Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler. ?My build works, technically, but it also happens to benchmark over 30% slower than the precompiled binaries in the distributed Python 2.7.3 MSI. ?Can anyone point me in the direction of some thoroughly detailed build documentation so that I can figure out how to get that 30% back with my build? ?The only documentation that I can find just says MSVC 9, period. ?There's no mention of SP1 or not, hotfixes, nor of any specific compiler/linker optimizations used to build the official distro. ?Something, somewhere, has to be significantly different between our builds for a 30% performance difference, and it'd probably be handy for the Python community to know how to avoid the same pitfall that cost me performance so that we can all get the most out of Python. ?Any and all help will be greatly appreciated. ?Thanks. > > Sincerely, > Arah Leonard > > Arah Leonard > Software Development Engineer > > Bruker AXS Inc. > 5465 East Cheryl Parkway > Madison, WI 53711 > US ? ? ? Phone: +1 608-276-3812 > ?Phone: +1 800-234-XRAY(9729) > ?Fax: > > ? Arah.Leon... at bruker-axs.com > ?www.bruker.com > > ________________________________ > > The information contained in this email is confidential. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, reproduction, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately. Try dumping the build configuration parameters: >>> import pprint, sysconfig >>> pprint.pprint(sysconfig.get_config_vars()) Then you can compare the existing version with yours. From Arah.Leonard at bruker-axs.com Thu Jan 17 13:25:06 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 17 Jan 2013 18:25:06 +0000 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <6df5947a-5665-4b92-906d-5aba9e399b5b@d10g2000yqe.googlegroups.com> References: <6df5947a-5665-4b92-906d-5aba9e399b5b@d10g2000yqe.googlegroups.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E075853DC@msnmail2.bruker-axs.com> >Try dumping the build configuration parameters: > > >>> import pprint, sysconfig > >>> pprint.pprint(sysconfig.get_config_vars()) > >Then you can compare the existing version with yours. I would absolutely love to be able to do that and have it work. Most unfortunately that only works on *nix OSes. The Python sysconfig module's config vars are almost non-existent on Windows with a really tiny and almost useless subset. :( I really wish someone would fix that, but hey, it's free so I'm not complaining. Just wishing. In case anyone else didn't know that, here's the results containing the complete and total list of config vars on Windows: >>> import pprint, sysconfig >>> pprint.pprint(sysconfig.get_config_vars()) {'BINDIR': 'C:\\Python27', 'BINLIBDEST': 'C:\\Python27\\Lib', 'EXE': '.exe', 'INCLUDEPY': 'C:\\Python27\\Include', 'LIBDEST': 'C:\\Python27\\Lib', 'SO': '.pyd', 'VERSION': '27', 'base': 'C:\\Python27', 'exec_prefix': 'C:\\Python27', 'platbase': 'C:\\Python27', 'prefix': 'C:\\Python27', 'projectbase': 'C:\\Python27', 'py_version': '2.7.3', 'py_version_nodot': '27', 'py_version_short': '2.7', 'srcdir': 'C:\\Python27', 'userbase': 'C:\\Documents and Settings\\Administrator\\Application Data\\Python'} That's it. It's actually also a common cause of problems in distutils and the likes when people write their module installers for Linux and never test those scriptlets on Windows, not realizing that in Python on Windows the sysconfig / distutils.sysconfig config vars are hamstrung like that. From stephane at wirtel.be Mon Jan 21 12:16:53 2013 From: stephane at wirtel.be (Stephane Wirtel) Date: Mon, 21 Jan 2013 18:16:53 +0100 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> Message-ID: <20130121171653.GA28857@atlantis> Hi Leonard, Please, could you limit your text to 80 columns, because it's unreadable. Your text is too long :( Thank you in advance. St?phane * Leonard, Arah [2013-01-17 15:29:28 +0000]: > Hello fellow Python programmers, > > I'm building a 32-bit CPython 2.7.3 distro for Windows using the MS Visual Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler. My build works, technically, but it also happens to benchmark over 30% slower than the precompiled binaries in the distributed Python 2.7.3 MSI. Can anyone point me in the direction of some thoroughly detailed build documentation so that I can figure out how to get that 30% back with my build? The only documentation that I can find just says MSVC 9, period. There's no mention of SP1 or not, hotfixes, nor of any specific compiler/linker optimizations used to build the official distro. Something, somewhere, has to be significantly different between our builds for a 30% performance difference, and it'd probably be handy for the Python community to know how to avoid the same pitfall that cost me performance so that we can all get the most out of Python. Any and all help will be greatly appreciated. Thanks. > > Sincerely, > Arah Leonard > > Arah Leonard > Software Development Engineer > > > > Bruker AXS Inc. > 5465 East Cheryl Parkway > Madison, WI 53711 > US Phone: +1 608-276-3812 > Phone: +1 800-234-XRAY(9729) > Fax: > > > Arah.Leonard at bruker-axs.com > www.bruker.com > > ________________________________ > > The information contained in this email is confidential. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, reproduction, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately. > > > -- > http://mail.python.org/mailman/listinfo/python-list -- St?phane Wirtel - http://wirtel.be - @matrixise From irmen.NOSPAM at xs4all.nl Mon Jan 21 13:22:55 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 21 Jan 2013 19:22:55 +0100 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> Message-ID: <50fd8781$0$6989$e4fe514c@news.xs4all.nl> On 21-1-2013 18:16, Stephane Wirtel wrote: > Hi Leonard, > > Please, could you limit your text to 80 columns, because it's > unreadable. Your text is too long :( Stephane, shouldn't your news reader simply wrap the lines...? At least mine does. (Thunderbird) Irmen From stephane at wirtel.be Mon Jan 21 16:03:14 2013 From: stephane at wirtel.be (Stephane Wirtel) Date: Mon, 21 Jan 2013 22:03:14 +0100 Subject: Thorough Python 2.7.3 Windows Build Documentation? In-Reply-To: <50fd8781$0$6989$e4fe514c@news.xs4all.nl> References: <2ECADBDABCB17E40B66A25D839706F5E07585302@msnmail2.bruker-axs.com> <50fd8781$0$6989$e4fe514c@news.xs4all.nl> Message-ID: <20130121210314.GA32757@atlantis> * Irmen de Jong [2013-01-21 19:22:55 +0100]: > On 21-1-2013 18:16, Stephane Wirtel wrote: > > Hi Leonard, > > > > Please, could you limit your text to 80 columns, because it's > > unreadable. Your text is too long :( > > Stephane, shouldn't your news reader simply wrap the lines...? At least mine does. > (Thunderbird) > I removed Thunderbird during the last month because I had a big problem of performance with the memory and the CPU :( Sorry, I dropped it About the limit of 80, this is a problem of typography :( -- St?phane Wirtel - http://wirtel.be - @matrixise From vinay_sajip at yahoo.co.uk Thu Jan 17 12:41:49 2013 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 17 Jan 2013 09:41:49 -0800 (PST) Subject: ANN: A new version (0.3.2) of the Python module which wraps GnuPG has been released. Message-ID: A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is a minor enhancement and bug-fix release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. Summary: Improved support for status messages from GnuPG. Fixed key generation to skip empty values. Fixed list_keys to handle escaped characters. Removed doctests which required interactive entry of passwords. The current version passes all tests on Windows (CPython 2.4, 2.5, 2.6, 3.1, 2.7 and Jython 2.5.1) and Ubuntu (CPython 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2). On Windows, GnuPG 1.4.11 has been used for the tests. Tests also pass under CPython 2.5 and CPython 2.6 on OS X. What Does It Do? ================ The gnupg module allows Python programs to make use of the functionality provided by the Gnu Privacy Guard (abbreviated GPG or GnuPG). Using this module, Python programs can encrypt and decrypt data, digitally sign documents and verify digital signatures, manage (generate, list and delete) encryption keys, using proven Public Key Infrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as it makes use of the subprocess module which appeared in that version of Python. This module is a newer version derived from earlier work by Andrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg >>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory') >>> gpg.list_keys() [{ ... 'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid': '197D5DAC68F1AAB2', 'length': '1024', 'type': 'pub', 'uids': ['', 'Gary Gross (A test user) ']}, { ... 'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid': '0C5FEFA7A921FC4A', 'length': '1024', ... 'uids': ['', 'Danny Davis (A test user) ']}] >>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A']) >>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n \nhQIOA/6NHMDTXUwcEAf ... -----END PGP MESSAGE-----\n' >>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret') >>> str(decrypted) 'Hello, world!' >>> signed = gpg.sign("Goodbye, world!", passphrase='secret') >>> verified = gpg.verify(str(signed)) >>> print "Verified" if verified else "Not verified" 'Verified' For more information, visit http://code.google.com/p/python-gnupg/ - as always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. From bv8bv8bv8 at gmail.com Thu Jan 17 14:03:39 2013 From: bv8bv8bv8 at gmail.com (BV BV) Date: Thu, 17 Jan 2013 11:03:39 -0800 (PST) Subject: Islam In Brief Message-ID: Islam In Brief Islam in Brief is the first part of The Fog is Lifting series of documentaries challenging your knowledge about the Islamic faith and traditions http://www.youtube.com/profile?user=IslamInBrief#g/p thank you From uccoord at microsoft.com Thu Jan 17 16:48:53 2013 From: uccoord at microsoft.com (Jillian) Date: Thu, 17 Jan 2013 13:48:53 -0800 (PST) Subject: Have You Ever Used Evernote API? Message-ID: Hey Guys, Im with User Research and we're currently doing a National Research Study for Devs who have used the Evernote API. The study is just a 90 minute phone call and all participants will receive their choice of technical software, hardware, or videogames. If you're interested in participating, please feel free to email me Jillian at uccoord at microsoft.com This study is for residents of the US only at this time. Thanks! Jillian User Research From steve+comp.lang.python at pearwood.info Thu Jan 17 17:48:57 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2013 22:48:57 GMT Subject: Warning for users of the Python and Jython wiki Message-ID: <50f87fd9$0$30003$c3e8da3$5496439d@news.astraweb.com> Hello all, Some time recently, the wiki at http://wiki.python.org/ was hacked. The vandal who broke in deleted all the wiki data. However, it is possible that before destroying the data, he may have gained access to user passwords. If you had an account on the wiki, and use the same password elsewhere, then you should change that password immediately. In general, you should not use the same password for multiple systems, and naturally once a password has been (potentially) compromised, never use it, or trivial modifications of it, again. http://thehackernews.com/2013/01/official-debian-and-python-wiki-servers.html#_ -- Steven From kalvinmanual1 at gmail.com Thu Jan 17 20:40:02 2013 From: kalvinmanual1 at gmail.com (kalvinmanual1) Date: Thu, 17 Jan 2013 19:40:02 -0600 Subject: College Physics 9th edition by Sears, Zemansky Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. solutions manual :: CALCULO VECTORIAL 7th Ed. by Louis Leithold solutions manual :: Calculus 8th Edition by Varberg, Purcell, Rigdon solutions manual :: Calculus - Early Transcendentals, 6th E, by Anton, Bivens, Davis solutions manual :: Calculus - Early Transcendentals, 7E, by Anton, Bivens, Davis solutions manual :: Calculus - Late Transcendentals Single Variable, 8th Ed by Anton, Bivens, Davis solutions manual :: Calculus ( 9th Ed., Dale Varberg, Edwin Purcell & Steve Rigdon) solutions manual :: Calculus 2nd edition-M. Spivak solutions manual :: Calculus 3rd Ed by Michael Spivak solutions manual :: Calculus 6th ed by James Stewart solutions manual :: Calculus 8th Ed by Ron Larson, Robert P. Hostetler, Bruce H. Edwards solutions manual :: Calculus A Complete Course 6th Edition by by R.A. Adams solutions manual :: CALCULUS An Intuitive and Physical Approach 2nd ed by Morris Kline solutions manual :: Calculus and its Applications (11th Ed., Larry J Goldstein, Schneider, Lay & Asmar) solutions manual :: Calculus by Gilbert Strang solutions manual :: Calculus early transcendentals 8th Ed, by Anton Bivens Davis solutions manual :: Calculus Early Transcendentals, 5th Edition, JAMES STEWART solutions manual :: Calculus George Thomas 10th ed Vol 1 solutions manual :: Calculus of Variations MA 4311 LECTURE NOTES ( Russak ) solutions manual :: Calculus On Manifolds by Spivak solutions manual :: Calculus One & Several Variables 8e by S Salas solutions manual :: Calculus Vol 2 by Apostol solutions manual :: CALCULUS VOL.1 , 2nd edition by Tom M. Apostol solutions manual :: Calculus Volume 1 by J. Marsden, A. Weinstein solutions manual :: Calculus With Analytic Geometry 4th ( Henry Edwards & David E. Penney) solutions manual :: Calculus with Applications 8 Edition by Lial, Greenwell, Ritchey solutions manual :: Calculus, 4th edition stewart solutions manual :: Calculus, An Applied Approach, 7E, by Larson solutions manual :: Calculus, Early Transcendentals 7 Ed by Edwards & Penney solutions manual :: Calculus, Single and Multivariable, 4E.,Vol 1& Vol 2 by Hughes-Hallett,McCallum solutions manual :: Calculus, Single Variable, 3E by Hughes-Hallett,McCallum solutions manual :: Chemical and Engineering Thermodynamics 3Ed by Stanley I. Sandler solutions manual :: Chemical Engineering Design (Coulson & Richardson's Chemical Engineering - Volume 6) - (4th Ed., Sinnott) solutions manual :: Chemical Engineering Volume 1, 6th Edition, by Richardson, Coulson,Backhurst, Harker solutions manual :: Chemical, Biochemical, and Engineering Thermodynamics, 4th Ed by Sandler solutions manual :: Chemistry 2nd Edition Vol.1 by Julia Burdge solutions manual :: Chemistry, 10th Ed by Chang solutions manual :: Chip Design for Submicron VLSI CMOS Layout and Simulation, John P. Uyemura solutions manual :: Cisco Technical Solution Series IP Telephony Solution Guide Version 2.0 solutions manual :: Classical Dynamics of Particles and Systems, 5th Ed, by Marion, Thornton solutions manual :: Classical Dynamics, A Contemporary Approach (Jorge V. Jose) solutions manual :: Classical Electrodynamics 2nd edition by John David Jackson solutions manual :: Classical Electrodynamics by John David Jackson solutions manual :: Classical Electrodynamics by Kasper Van Wijk solutions manual :: Classical Mechanics (Douglas Gregory) solutions manual :: Classical Mechanics 2nd Ed by Goldstein solutions manual :: CMOS Analog Circuit Design, 2ed by Phillip E. Allen, Douglas R. Holberg solutions manual :: CMOS- Circuit Design, Layout, and Simulation, Revised 2nd Ed by R. Jacob Baker solutions manual :: Cmos Digital Integrated Circuits , Sung-Mo Kang,Yusuf Leblebici solutions manual :: CMOS Mixed-Signal Circuit Design, 2nd Ed by R. Jacob Baker solutions manual :: CMOS VLSI Design Circuit & Design Perspective 3rd Ed by Haris & West solutions manual :: College Algebra 8th Ed by Michael Sullivan solutions manual :: COLLEGE ALGEBRA AND TRIGONOMETRY 6th E by Aufmann, Barker, Verity solutions manual :: College Geometry A Discovery Approach 2nd E by David Kay solutions manual :: College Physics 8 ED by Serway, Faughn, Vuille solutions manual :: College Physics 9 ED by Serway, Faughn, Vuille solutions manual :: College Physics 9th edition by Sears, Zemansky solutions manual :: Communication Networks, 2e, Alberto Leon-Garcia, Indra Widjaja solutions manual :: Communication Systems (4th Ed., Simon Haykin) solutions manual :: Communication Systems An Introduction to Signals and Noise in Electrical Communication, 4E, A. Bruce Carlson solutions manual :: Communication Systems Engineering (2nd Ed., John G. Proakis & Masoud Salehi) solutions manual :: Complex Variables and Applications 7 ed by JW Brown RV Churchill solutions manual :: Complex Variables with Applications, 3rd ED by David A. Wunsch solutions manual :: COMPUTATIONAL FINANCE A SCIENTIFIC PERSPECTIVE MILEN KASSABOV,CORNELIS A. LOS solutions manual :: Computational Techniques for Fluid Dynamics Srinivas, K., Fletcher, C.A.J. solutions manual :: Computer Architecture - A Quantitative Approach, 4th Ed by Hennessy, Patterson solutions manual :: Computer Architecture Pipelined & Parallel Processor Design by Michael J Flynn solutions manual :: Computer Graphics Using OpenGL 3rd E by Francis S Hill, Jr. & Stephen M Kelley solutions manual :: Computer Networking A Top-Down Approach Featuring the Internet, 3E Kurose,Ross solutions manual :: Computer Networking: A Top-Down Approach (4th Ed., James F. Kurose & Keith W. Ross) solutions manual :: Computer Networks - A Systems Approach 3 ed by Peterson Davie solutions manual :: Computer Networks - A Systems Approach 4 ed by Peterson Davie solutions manual :: Computer Networks A Systems Approach, 2nd Edition, Larry Peterson, Bruce Davie solutions manual :: Computer Networks, 4th Ed., by Andrew S. Tanenbaum solutions manual :: Computer Organization 3rd Edition by Carl Hamacher , Zvonoko Vranesic ,Safwat Zaky solutions manual :: Computer Organization and Architecture: Designing for Performance (7th Ed., William Stallings) solutions manual :: Computer Organization and Design The Hardware Software Interface 4 ed by David A Patterson solutions manual :: Computer Organization and Design The Hardware Software Interface, 3rd edition by David A Patterson and John L Hennessy solutions manual :: Computer Science Illuminated 4th ed by Nell Dale, John Lewis solutions manual :: Computer system architecture 3rd Ed Morris Mano solutions manual :: Computer Systems Organization and Architecture by John D. Carpinelli solutions manual :: Computer Vision A Modern Approach by Forsyth, Ponce solutions manual :: Computer-Controlled Systems 3rd ED by Astrom, Wittenmark solutions manual :: Concepts and Applications of Finite Element Analysis (4th Ed., Cook, Malkus, Plesha & Witt) solutions manual :: Concepts in Thermal Physics 2nd Ed by Blundell solutions manual :: Concepts of Modern Physics 6th ED by Arthur Beiser solutions manual :: Concepts of Physics (Volume 1 & 2) by H.C. Verma solutions manual :: Concepts of Programming Languages 7th ED by Sebesta solutions manual :: Construction Surveying and Layout 2ed by Crawford solutions manual :: Contemporary Engineering Economics (4th Ed., Chan Park) solutions manual :: Contemporary Engineering Economics 5th Ed by Chan S. Park solutions manual :: Continuum Electromechanics by James R. Melcher solutions manual :: Control Systems Engineering, 4E, by Norman Nise solutions manual :: Control Systems Principles and Design 2e by M. Gopal solutions manual :: Corporate Finance & MyFinanceLab Student Access Code Card, Global 2 Ed by Berk, DeMarzo solutions manual :: Corporate Finance 8th edition by Ross solutions manual :: Corporate Finance 9th edition by Ross solutions manual :: Corporate Finance The Core plus MyFinanceLab Student Access Kit (Jonathan Berk & Peter DeMarzo) solutions manual :: Corporate Finance, 7E, by Ross solutions manual :: Corporations, Partnerships, Estates and Trusts ( 2011 ) by Hoffman, Maloney solutions manual :: COST ACCOUNTING - Creating Value for Management 5th E by MICHAEL MAHER solutions manual :: Cost Accounting-A Managerial Emphasis 13th Ed by Charles Horngren solutions manual :: Cryptography and Network Security (4th Ed., William Stallings) From wq-doux at cn.fujitsu.com Thu Jan 17 21:49:30 2013 From: wq-doux at cn.fujitsu.com (douxin) Date: Fri, 18 Jan 2013 10:49:30 +0800 Subject: [HELP!] a doubt about entering password in python Message-ID: <50F8B83A.6030403@cn.fujitsu.com> Hi all: i have some doubts in doing python programming i wanted to execute a command "su -c 'fdisk -l'",and it needed a password so i wanted to write a python script to get this done. i knew 'pexpect' would work fine,but i had to set a certain timeout to take care of the real delay time which i probably didn't know i tried to use 'subprocess' to do this,however,it did not work well,and came the problem i use Popen to execute "su -c 'fdisk -l'" in sub process,and assigned subprocess.PIPE to stdin,stdout i tried to enter password by doing "stdin.write("password"+"\n")" and i expected i could get the output of "fdisk -l" by doing "stdout.read()" it didn't work. will somebody tell me what is going on with that? i'll appreciate i can learn from you Dou -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Jan 17 22:12:00 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jan 2013 03:12:00 GMT Subject: [HELP!] a doubt about entering password in python References: Message-ID: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote: > i use Popen to execute "su -c 'fdisk -l'" in sub process,and > assigned subprocess.PIPE to stdin,stdout i tried to enter password > by doing "stdin.write("password"+"\n")" and i expected i could get > the output of "fdisk -l" by doing "stdout.read()" > it didn't work. > > will somebody tell me what is going on with that? Would you like us to guess what happened? I love guessing games! My guess is that it output "su: incorrect password", which means you have the wrong password. Is that it? If not, my guess is that it output "fdisk: command not found", in which case your system is broken and the fdisk binary is missing or not on the PATH. Am I close? Last guess: you got a Python traceback with an error: NameError: name 'subprocess' is not defined You need to import the subprocess first. If none of my guesses are correct, could we have some hints? Perhaps show us the actual code you are using, and the actual results, copied and pasted exactly. Thank you. -- Steven From python at mrabarnett.plus.com Thu Jan 17 23:00:29 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 18 Jan 2013 04:00:29 +0000 Subject: [HELP!] a doubt about entering password in python In-Reply-To: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50F8C8DD.8010903@mrabarnett.plus.com> On 2013-01-18 03:12, Steven D'Aprano wrote: > On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote: > >> i use Popen to execute "su -c 'fdisk -l'" in sub process,and >> assigned subprocess.PIPE to stdin,stdout i tried to enter password >> by doing "stdin.write("password"+"\n")" and i expected i could get >> the output of "fdisk -l" by doing "stdout.read()" >> it didn't work. >> >> will somebody tell me what is going on with that? > > Would you like us to guess what happened? I love guessing games! > > My guess is that it output "su: incorrect password", which means you have > the wrong password. Is that it? > > If not, my guess is that it output "fdisk: command not found", in which > case your system is broken and the fdisk binary is missing or not on the > PATH. Am I close? > > Last guess: you got a Python traceback with an error: > > NameError: name 'subprocess' is not defined > > You need to import the subprocess first. > > > If none of my guesses are correct, could we have some hints? Perhaps show > us the actual code you are using, and the actual results, copied and > pasted exactly. > It may, of course, be that for security reasons it won't accept a password from whatever happens to be connected to stdin, but instead insists that it's entered directly from the keyboard, if you see what I mean. From maniandram01 at gmail.com Thu Jan 17 23:45:57 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 17 Jan 2013 20:45:57 -0800 (PST) Subject: [HELP!] a doubt about entering password in python In-Reply-To: References: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <189d777e-33c7-4eb6-b301-e477f9122dee@googlegroups.com> On Friday, January 18, 2013 9:30:29 AM UTC+5:30, MRAB wrote: > On 2013-01-18 03:12, Steven D'Aprano wrote: > > > On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote: > > > > > >> i use Popen to execute "su -c 'fdisk -l'" in sub process,and > > >> assigned subprocess.PIPE to stdin,stdout i tried to enter password > > >> by doing "stdin.write("password"+"\n")" and i expected i could get > > >> the output of "fdisk -l" by doing "stdout.read()" > > >> it didn't work. > > >> > > >> will somebody tell me what is going on with that? > > > > > > Would you like us to guess what happened? I love guessing games! > > > > > > My guess is that it output "su: incorrect password", which means you have > > > the wrong password. Is that it? > > > > > > If not, my guess is that it output "fdisk: command not found", in which > > > case your system is broken and the fdisk binary is missing or not on the > > > PATH. Am I close? > > > > > > Last guess: you got a Python traceback with an error: > > > > > > NameError: name 'subprocess' is not defined > > > > > > You need to import the subprocess first. > > > > > > > > > If none of my guesses are correct, could we have some hints? Perhaps show > > > us the actual code you are using, and the actual results, copied and > > > pasted exactly. > > > > > It may, of course, be that for security reasons it won't accept a > > password from > > whatever happens to be connected to stdin, but instead insists that it's > > entered > > directly from the keyboard, if you see what I mean. I think you are correct - su uses some tty magic to stop ECHO and probably doesn't read the password from stdin. From maniandram01 at gmail.com Thu Jan 17 23:45:57 2013 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 17 Jan 2013 20:45:57 -0800 (PST) Subject: [HELP!] a doubt about entering password in python In-Reply-To: References: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <189d777e-33c7-4eb6-b301-e477f9122dee@googlegroups.com> On Friday, January 18, 2013 9:30:29 AM UTC+5:30, MRAB wrote: > On 2013-01-18 03:12, Steven D'Aprano wrote: > > > On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote: > > > > > >> i use Popen to execute "su -c 'fdisk -l'" in sub process,and > > >> assigned subprocess.PIPE to stdin,stdout i tried to enter password > > >> by doing "stdin.write("password"+"\n")" and i expected i could get > > >> the output of "fdisk -l" by doing "stdout.read()" > > >> it didn't work. > > >> > > >> will somebody tell me what is going on with that? > > > > > > Would you like us to guess what happened? I love guessing games! > > > > > > My guess is that it output "su: incorrect password", which means you have > > > the wrong password. Is that it? > > > > > > If not, my guess is that it output "fdisk: command not found", in which > > > case your system is broken and the fdisk binary is missing or not on the > > > PATH. Am I close? > > > > > > Last guess: you got a Python traceback with an error: > > > > > > NameError: name 'subprocess' is not defined > > > > > > You need to import the subprocess first. > > > > > > > > > If none of my guesses are correct, could we have some hints? Perhaps show > > > us the actual code you are using, and the actual results, copied and > > > pasted exactly. > > > > > It may, of course, be that for security reasons it won't accept a > > password from > > whatever happens to be connected to stdin, but instead insists that it's > > entered > > directly from the keyboard, if you see what I mean. I think you are correct - su uses some tty magic to stop ECHO and probably doesn't read the password from stdin. From rosuav at gmail.com Fri Jan 18 01:36:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Jan 2013 17:36:50 +1100 Subject: [HELP!] a doubt about entering password in python In-Reply-To: <189d777e-33c7-4eb6-b301-e477f9122dee@googlegroups.com> References: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> <189d777e-33c7-4eb6-b301-e477f9122dee@googlegroups.com> Message-ID: On Fri, Jan 18, 2013 at 3:45 PM, Ramchandra Apte wrote: > I think you are correct - su uses some tty magic to stop ECHO and probably doesn't read the password from stdin. I believe that's right, but the 'sudo' command - at least on my Debian and Ubuntu systems - accepts a -S parameter to read from stdin instead of the terminal. Actually, sudo might be better suited to the OP's task anyway, if it's available. ChrisA From double.620 at gmail.com Fri Jan 18 00:25:43 2013 From: double.620 at gmail.com (Nick Dong) Date: Thu, 17 Jan 2013 21:25:43 -0800 (PST) Subject: Parent module adsite.adsiteviews.mainhanlder does not exist Message-ID: <1795aead-8260-4f68-9597-a6aa488f6513@googlegroups.com> I created a django project using django 1.4.2. There is one 'app'(adsite) in this project. And It works. But when I copied some 'py' files into the 'app' folder, I got "Parent module adsite.adsiteviews.mainhanlder does not exist." Should I register the new files to __init__ in the 'app'? Did new coped files break the "import" rules? views.py from django.http import HttpResponse from django.template import Context, loader from adsite.models import UserInfo def showusers(request): userlist = UserInfo.objects.all() c = Context({ 'userlist':userlist, }) t = loader.get_template('users.html') return HttpResponse(t.render(c)) copied file: adsiteviews.py class mainhanlder(TemplateView) def get(self): """ """ variables = { 'user': self.get_current_user(), 'mchosts' : MCHOSTS, 'servers' : servers} index_templ = tmpl_lookup.get_template("index.html") body = index_templ.render(**variables) self.write(body) urls.py urlpatterns = patterns('', # Examples: url(r'^$', 'adsite.adsiteviews.mainhandler.as_View()'), url(r'^users/$', 'adsite.views.showusers'), I have no clues about this problem. any suggestions would be appreciated. thx for your time. From jason at powerpull.net Sun Jan 20 09:49:40 2013 From: jason at powerpull.net (Jason Friedman) Date: Sun, 20 Jan 2013 07:49:40 -0700 Subject: Parent module adsite.adsiteviews.mainhanlder does not exist In-Reply-To: <1795aead-8260-4f68-9597-a6aa488f6513@googlegroups.com> References: <1795aead-8260-4f68-9597-a6aa488f6513@googlegroups.com> Message-ID: > I created a django project using django 1.4.2. There is one 'app'(adsite) in this project. And It works. But when I copied some 'py' files into the 'app' folder, I got "Parent module adsite.adsiteviews.mainhanlder does not exist." Should I register the new files to __init__ in the 'app'? Did new coped files break the "import" rules? I do not know if this is your problem, and I know little about django, but is "mainhanlder" a typographical error? From andrew3 at r3dsolutions.com Thu Jan 17 18:59:41 2013 From: andrew3 at r3dsolutions.com (Andrew Robinson) Date: Thu, 17 Jan 2013 23:59:41 +0000 Subject: Vote tallying... Message-ID: <50F8906D.9040203@r3dsolutions.com> Hi, I have a problem which may fit in a mysql database, but which I only have python as an alternate tool to solve... so I'd like to hear some opinions... I'm building a experimental content management program on a standard Linux Web server. And I'm needing to keep track of archived votes and their voters -- for years. Periodically, a python program could be given a batch of new votes removed from the database, and some associated comments, which are no longer real-time necessary; and then a python script needs to take that batch of votes, and apply them to an appropriate archive file. It's important to note that it won't just be appending new votes, it will be sorting through a list of 10's of thousands of votes, and changing a *few* of them, and appending the rest. XML may not be the ideal solution, but I am easily able to see how it might work. I imagine a file like the following might be inefficient, but capable of solving the problem: 12345A3 FF734B5D 7FBED The woodstock games I think you're on drugs, man.! It would have been better if they didn't wake up in the morning. 10 1 3 The questions I have are, is using XML for vote recording going to be slow compared to other stock solutions that Python may have to offer? The voter ID's are unique, 32 bits long, and the votes are only from 1 to 10. (4 bits.). I'm free to use any import that comes with python 2.5. so if there's something better than XML, I'm interested. And secondly, how likely is this to still work once the vote count reaches 10 million? Is an XML file with millions of entries something someone has already tried succesfully? From lie.1296 at gmail.com Fri Jan 18 03:39:49 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 18 Jan 2013 19:39:49 +1100 Subject: Vote tallying... In-Reply-To: <50F8906D.9040203@r3dsolutions.com> References: <50F8906D.9040203@r3dsolutions.com> Message-ID: On 18/01/13 10:59, Andrew Robinson wrote: > Hi, > > I have a problem which may fit in a mysql database, but which I only > have python as an alternate tool to solve... so I'd like to hear some > opinions... Since you have a large dataset, you might want to use sqlite3 (http://docs.python.org/2.5/lib/module-sqlite3.html, https://www.sqlite.org/), which comes in the standard library since Python 2.5. SQLite is a self-contained, serverless, zero configuration, transactional SQL database engine. XML with a million entries are probably not a good idea due to its verbosity; XML was designed for data interchange, not for complex relational data processing. From stefan_ml at behnel.de Fri Jan 18 03:47:43 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 18 Jan 2013 09:47:43 +0100 Subject: Vote tallying... In-Reply-To: <50F8906D.9040203@r3dsolutions.com> References: <50F8906D.9040203@r3dsolutions.com> Message-ID: Andrew Robinson, 18.01.2013 00:59: > I have a problem which may fit in a mysql database Everything fits in a MySQL database - not a reason to use it, though. Py2.5 and later ship with sqlite3 and if you go for an external database, why use MySQL if you can have PostgreSQL for the same price? > but which I only have > python as an alternate tool to solve... so I'd like to hear some opinions... > > I'm building a experimental content management program on a standard Linux > Web server. > And I'm needing to keep track of archived votes and their voters -- for years. > > Periodically, a python program could be given a batch of new votes removed > from the database, and some associated comments, which are no longer > real-time necessary; and then a python script needs to take that batch of > votes, and apply them to an appropriate archive file. It's important to > note that it won't just be appending new votes, it will be sorting through > a list of 10's of thousands of votes, and changing a *few* of them, and > appending the rest. > > XML may not be the ideal solution, but I am easily able to see how it might > work. I imagine a file like the following might be inefficient, but > capable of solving the problem: > > > > > > 12345A3 > FF734B5D > 7FBED > The woodstock games > > > > I think you're on drugs, > man.! > It would have been > better if they didn't wake up in the morning. > > > > 10 > 1 > 3 > > > > The questions I have are, is using XML for vote recording going to be slow > compared to other stock solutions that Python may have to offer? The voter > ID's are unique, 32 bits long, and the votes are only from 1 to 10. (4 > bits.). I'm free to use any import that comes with python 2.5. so if > there's something better than XML, I'm interested. > > And secondly, how likely is this to still work once the vote count reaches > 10 million? > Is an XML file with millions of entries something someone has already tried > succesfully? Sure. However, XML files are a rather static thing and meant to be processed from start to end on each run. That adds up if the changes are small and local while the file is ever growing. You seem to propose one file per article, which might work. That's unlikely to become too huge to process, and Python's cElementTree is a very fast XML processor. However, your problem sounds a lot like you could map it to one of the dbm databases that Python ships. They work like dicts, just on disk. IIUC, you want to keep track of comments and their associated votes, maybe also keep a top-N list of the highest voted comments. So, keep each comment and its votes in a dbm record, referenced by the comment's ID (which, I assume, you keep a list of in the article that it comments on). You can use pickle (see the shelve module) or JSON or whatever you like for storing that record. Then, on each votes update, look up the comment, change its votes and store it back. If you keep a top-N list for an article, update it at the same time. Consider storing it either as part of the article or in another record referenced by the article, depending of how you normally access it. You can also store the votes independent of the comment (i.e. in a separate record for each comment), in case you don't normally care about the votes but read the comments frequently. It's just a matter of adding an indirection for things that you use less frequently and/or that you use in more than one place (not in your case, where comments and votes are unique to an article). You see, lots of options, even just using the stdlib... Stefan From andrew3 at r3dsolutions.com Fri Jan 18 08:43:42 2013 From: andrew3 at r3dsolutions.com (Andrew Robinson) Date: Fri, 18 Jan 2013 13:43:42 +0000 Subject: Vote tallying... In-Reply-To: References: <50F8906D.9040203@r3dsolutions.com> Message-ID: <50F9518E.3040509@r3dsolutions.com> On 01/18/2013 08:47 AM, Stefan Behnel wrote: > Andrew Robinson, 18.01.2013 00:59: >> I have a problem which may fit in a mysql database > Everything fits in a MySQL database - not a reason to use it, though. Py2.5 > and later ship with sqlite3 and if you go for an external database, why use > MySQL if you can have PostgreSQL for the same price? MySQL is provided by the present server host. It's pretty standard at web hosting sites. It works through "import MySQLdb" -- and it means an IP call for every action... Postgre isn't available :( otherwise, I'd use it.... I'm mildly concerned about scaling issues.... but don't have a lot of time (just a few days) to come to a decision. I don't need high performance, just no grotesque degradation when the system is scaled up, and no maintenance nightmare. The votes table is going to get monsterous if all votes are held in one table.... Your comment about sqlite is interesting; I've never used it before. At a glance, it uses individual files as databases, which is good... But it wants to lock the entire database against reads as well as writes when any access of the database happens. Which is bad... http://www.sqlite.org/different.html http://www.sqlite.org/whentouse.html > ... XML files are a rather static thing and meant to be > processed from start to end on each run. That adds up if the changes are > small and local while the file is ever growing. You seem to propose one > file per article, which might work. That's unlikely to become too huge to > process, and Python's cElementTree is a very fast XML processor. Yes, that's exactly what I was thinking.... one file/article. It's attractive, I think, because many Python programs are allowed to read the XML file concurrently, but only one periodically updates it as a batch/chron/or triggered process; eg: the number/frequency of update is actually controllable. eg: MySQL accumulates a list of new votes and vote changes and python occasionally flushes the database into the archive file. That way, MySQL only maintains a small database of real-time changes, and the speed/accuracy of the vote tally can be tailored to the user's need. > > However, your problem sounds a lot like you could map it to one of the dbm > databases that Python ships. They work like dicts, just on disk. Doing a Google search, I see some of these that you are mentioning -- yes, they may have some potential. > > IIUC, you want to keep track of comments and their associated votes, maybe > also keep a top-N list of the highest voted comments. So, keep each comment > and its votes in a dbm record, referenced by the comment's ID (which, I > assume, you keep a list of in the article that it comments on). The comments themselves are just ancillary information; the votes only apply to the article itself at this time. The two pieces of feedback information are independent, occasionally having a user that gives both kinds. Statistically, there are many votes -- and few comments. Each archive file has the same filename as the article that is being commented or voted on; but with a different extension (eg: xml, or .db,or...) so there's no need to store article information on each vote or comment; (unlike the MySQL database, which has to store all that information for every vote.... ugh....!) > You can use > pickle (see the shelve module) or JSON or whatever you like for storing > that record. Then, on each votes update, look up the comment, change its > votes and store it back. If you keep a top-N list for an article, update it > at the same time. Consider storing it either as part of the article or in > another record referenced by the article, depending of how you normally > access it. You can also store the votes independent of the comment (i.e. in > a separate record for each comment), in case you don't normally care about > the votes but read the comments frequently. It's just a matter of adding an > indirection for things that you use less frequently and/or that you use in > more than one place (not in your case, where comments and votes are unique > to an article). > > You see, lots of options, even just using the stdlib... > > Stefan > Yes, lots of options.... Let's see... you've noticed just about everything important, and have lots of helpful thoughts; thank you. There are implementation details I'm not aware of regarding how the file-system dictionaries (dbm) work; and I wouldn't know how to compare it to XML access speed either.... but I do know some general information about how the data might be handled algorithmically; and which might suggest a better Python import to use? If I were to sort all votes by voter ID (a 32 bit number), and append the vote value (A 4 to 8bit number); Then a vote becomes a chunk of 40 bits, fixed length; and I can stack one right after another in a compact format. Blocks of compacted votes are ideal for binary searching; since they have fixed length... and if I am only wanting to change a vote, I don't need to re-write the entire file, because a changed vote doesn't change the file length. ( So, now I have COMPACT + FASTER ). If I were to wish to insert new votes, in this sorted list of votes -- I would need to do something like a merge sort; which means changing the length of the file by a bulk copy of most of it to open up a "little" space for 1 or two votes; BUT: It's also possible to break the vote list up into compact ranges of voter ID's; And perhaps using indirection like you suggested.... and I was thinking it might not be hard to add *some* limited blank space in the file -- like this XML example: 0xFFFFFABCDEFAFDADADADAFAFADADADAFADADAFAFAFADDAFAFAD................ 0xFEEEEAFFFFABCDEFAFDADADADAFAFADADADAFADADAFAFAFADDAFAFAD...... So that inserting a vote to block "125" could be done by a simultaneous deleting of some of the padding characters "...." and therefore, the whole file rarely needs a re-write. I don't want to waste a large amount of time optimizing this, as a fast C-api COPY in one library might make merge sort tons faster than a python interpreter based blank space shrink-expand; But, do any of the possible optimizations I just gave suggest one standard Python library might be better suited than another? Thanks for the help. :) From lie.1296 at gmail.com Sat Jan 19 06:58:17 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 19 Jan 2013 22:58:17 +1100 Subject: Vote tallying... In-Reply-To: <50F9518E.3040509@r3dsolutions.com> References: <50F8906D.9040203@r3dsolutions.com> <50F9518E.3040509@r3dsolutions.com> Message-ID: On 19/01/13 00:43, Andrew Robinson wrote: > On 01/18/2013 08:47 AM, Stefan Behnel wrote: >> Andrew Robinson, 18.01.2013 00:59: >>> I have a problem which may fit in a mysql database >> Everything fits in a MySQL database - not a reason to use it, though. >> Py2.5 >> and later ship with sqlite3 and if you go for an external database, >> why use >> MySQL if you can have PostgreSQL for the same price? > MySQL is provided by the present server host. It's pretty standard at > web hosting sites. > It works through "import MySQLdb" -- and it means an IP call for every > action... That is not quite true. With most client libraries, including MySQLdb, connection to localhost goes through a local unix socket (or named pipe in Windows) instead of the TCP stack. > But > it wants to lock the entire database against reads as well as writes > when any access of the database happens. Which is bad... Which is the same restriction as when using XML/JSON. What it means by locking the entire database is that an sqlite database can only be read/written by a single program at any moment in time. For batch processing, locking the entire database is never going to be a problem; for CGI scripts (and their variants), it may be a performance bottleneck for extremely high volume websites. From lie.1296 at gmail.com Sat Jan 19 20:15:02 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 20 Jan 2013 12:15:02 +1100 Subject: Vote tallying... In-Reply-To: References: <50F8906D.9040203@r3dsolutions.com> <50F9518E.3040509@r3dsolutions.com> Message-ID: On 20/01/13 08:22, Dennis Lee Bieber wrote: > On Sat, 19 Jan 2013 22:58:17 +1100, Lie Ryan >> Which is the same restriction as when using XML/JSON. What it means by >> locking the entire database is that an sqlite database can only be >> read/written by a single program at any moment in time. For batch > > Actually, SQLite3 will happily permit multiple readers (or did, the > newest version may have a new locking scheme). However, the first > connection that seeks to write will block as long as open readers are > active, yet will also block /new/ readers. When the open readers close, > the write can complete, and then new readers can enter. Conclusion: > ensure that even read-only operations have a "commit" operation to close > them You're correct. For more precise description of what sqlite can or cannot do with respect to concurrency, see http://www.sqlite.org/faq.html#q5. As far as I know, dbm does not support concurrencies at all, and neither does xml unless you put a lot of efforts into implementing your own file locking and all. From nick.cash at npcinternational.com Fri Jan 18 10:19:49 2013 From: nick.cash at npcinternational.com (Nick Cash) Date: Fri, 18 Jan 2013 15:19:49 +0000 Subject: Vote tallying... In-Reply-To: <50F8906D.9040203@r3dsolutions.com> References: <50F8906D.9040203@r3dsolutions.com> Message-ID: <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> > I have a problem which may fit in a mysql database, but which I only > have python as an alternate tool to solve... so I'd like to hear some > opinions... Is there a reason you can't use an RDBMS for this? MySQL would certainly be fine, although I always recommend PostgreSQL over it. Based on the amount of data you've specified, you really don't want to be rolling your own data storage system. If you absolutely cannot install any new software, Sqllite is built into Python and would work almost as well. From kwpolska at gmail.com Fri Jan 18 14:26:07 2013 From: kwpolska at gmail.com (Kwpolska) Date: Fri, 18 Jan 2013 20:26:07 +0100 Subject: Vote tallying... In-Reply-To: <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> Message-ID: On Fri, Jan 18, 2013 at 4:19 PM, Nick Cash wrote: > MySQL would certainly be fine, although I always recommend PostgreSQL over it. Bonus question, why? -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From ben+python at benfinney.id.au Fri Jan 18 15:24:40 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 19 Jan 2013 07:24:40 +1100 Subject: Vote tallying... References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> Message-ID: <7whames0hj.fsf@benfinney.id.au> Kwpolska writes: > On Fri, Jan 18, 2013 at 4:19 PM, Nick Cash > wrote: > > MySQL would certainly be fine, although I always recommend > > PostgreSQL over it. > Bonus question, why? The PostgreSQL community gets asked this question so often that they have a page with resources answering in various ways depending on what the reader needs to know . For me, the reasons are many. Some important ones: * MySQL happily alters data on input to the database, if it feels the need, without regard for data integrity. PostgreSQL has always valued the integrity of your data, rejecting invalid data before it can become an integrity problem. * MySQL has atrocious error messages and opaque error reporting, making it very difficult to figure out what has actually gone wrong with a command it doesn't like. PostgreSQL's error reporting is far clearer, helping pinpoint the location of the error. It also has an exception-raising mechanism that the programmer can use. * MySQL's development has suffered under Sun, and become virtually moribund under Oracle. They operate as a closed shop, occasionally tossing GPL-licensed releases over the wall, with very little input accepted from the community. PostgreSQL development has for a long time now been faster than MySQL's, and their community is far more open to contributors and bug reports. As a result, the development is much more community-focussed and addresses requests more directly. That latter point is a big flag that Oracle's MySQL is a dead end while PostgreSQL has a vibrant future. If only from the perspective of who's going to support you better in the long run, the choice is clear to me. -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From rosuav at gmail.com Fri Jan 18 16:57:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jan 2013 08:57:12 +1100 Subject: Vote tallying... In-Reply-To: <7whames0hj.fsf@benfinney.id.au> References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <7whames0hj.fsf@benfinney.id.au> Message-ID: On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney wrote: > * MySQL's development has suffered under Sun, and become virtually > moribund under Oracle. They operate as a closed shop, occasionally > tossing GPL-licensed releases over the wall, with very little input > accepted from the community. I don't know whether it's a legit concern or pure FUD, but it's been suggested that since the MySQL license is GPL and not LGPL, any code that links against it is forced to be GPL too. I'm not sure how far that goes (eg if you're using it from Python, at what point does it stop being "code linked to GPL code" and start being a discrete system), and IANAL, but I prefer to work with systems with more freedom in their licensing. PostgreSQL is under a BSD-like license, so it can be used without issues. Also, and a completely irrelevant point but maybe of curiosity: It's perfectly possible to use PostgreSQL without linking against libpq (by reimplementing the wire protocol - Pike's pgsql module does that), but I've never heard of anyone doing that with MySQL. Perhaps if someone cared, they could release a non-GPL equivalent to libmysql and that would solve this problem. Not gonna be me, though, I'm quite happy with PG 9.1. MySQL works very nicely with PHP. They each have certain sloppinesses that work well together to make it easy for an idiot to create a dynamic web site. PostgreSQL works equally nicely with stricter languages, where if you make a mistake, you get an error. MySQL gives your script a place to store data; PostgreSQL lets you set up a database and have application(s) manipulate it. The assumption in MySQL is that the script is always right; the assumption in PostgreSQL is that the database is always right. It's a philosophical distinction, and you just have to take your choice. For me, that's an easy choice, partly since I grew up with IBM DB2 on OS/2, with extremely strict rules (and, by the way, nothing *like* the performance of a modern database - old 200MB IDE hard drives didn't give quite the same TPS as a modern SATA). ChrisA From kushal.kumaran+python at gmail.com Fri Jan 18 20:25:15 2013 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 19 Jan 2013 06:55:15 +0530 Subject: Vote tallying... In-Reply-To: References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <7whames0hj.fsf@benfinney.id.au> Message-ID: <50f9f602.2583440a.7194.311c@mx.google.com> Chris Angelico writes: > On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney wrote: >> * MySQL's development has suffered under Sun, and become virtually >> moribund under Oracle. They operate as a closed shop, occasionally >> tossing GPL-licensed releases over the wall, with very little input >> accepted from the community. > > I don't know whether it's a legit concern or pure FUD, but it's been > suggested that since the MySQL license is GPL and not LGPL, any code > that links against it is forced to be GPL too. I'm not sure how far > that goes (eg if you're using it from Python, at what point does it > stop being "code linked to GPL code" and start being a discrete > system), and IANAL, but I prefer to work with systems with more > freedom in their licensing. PostgreSQL is under a BSD-like license, so > it can be used without issues. > Oracle have a page about this: http://www.mysql.com/about/legal/licensing/foss-exception/ > Also, and a completely irrelevant point but maybe of curiosity: It's > perfectly possible to use PostgreSQL without linking against libpq (by > reimplementing the wire protocol - Pike's pgsql module does that), but > I've never heard of anyone doing that with MySQL. Perhaps if someone > cared, they could release a non-GPL equivalent to libmysql and that > would solve this problem. Not gonna be me, though, I'm quite happy > with PG 9.1. > As far as python goes, there are at least two pure-python implementations of the mysql protocol available: - https://github.com/petehunt/PyMySQL (MIT license) - https://launchpad.net/myconnpy (GPL) The second one is an "official" Oracle project. Both of them support python 3 as well. > MySQL works very nicely with PHP. They each have certain sloppinesses > that work well together to make it easy for an idiot to create a > dynamic web site. PostgreSQL works equally nicely with stricter > languages, where if you make a mistake, you get an error. MySQL gives > your script a place to store data; PostgreSQL lets you set up a > database and have application(s) manipulate it. The assumption in > MySQL is that the script is always right; the assumption in PostgreSQL > is that the database is always right. It's a philosophical > distinction, and you just have to take your choice. For me, that's an > easy choice, partly since I grew up with IBM DB2 on OS/2, with > extremely strict rules (and, by the way, nothing *like* the > performance of a modern database - old 200MB IDE hard drives didn't > give quite the same TPS as a modern SATA). > -- regards, kushal From rosuav at gmail.com Fri Jan 18 21:00:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jan 2013 13:00:48 +1100 Subject: Vote tallying... In-Reply-To: <50f9f602.2583440a.7194.311c@mx.google.com> References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <7whames0hj.fsf@benfinney.id.au> <50f9f602.2583440a.7194.311c@mx.google.com> Message-ID: On Sat, Jan 19, 2013 at 12:25 PM, Kushal Kumaran wrote: > Chris Angelico writes: > >> On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney wrote: >>> * MySQL's development has suffered under Sun, and become virtually >>> moribund under Oracle. They operate as a closed shop, occasionally >>> tossing GPL-licensed releases over the wall, with very little input >>> accepted from the community. >> >> I don't know whether it's a legit concern or pure FUD, but it's been >> suggested that since the MySQL license is GPL and not LGPL, any code >> that links against it is forced to be GPL too. I'm not sure how far >> that goes (eg if you're using it from Python, at what point does it >> stop being "code linked to GPL code" and start being a discrete >> system), and IANAL, but I prefer to work with systems with more >> freedom in their licensing. PostgreSQL is under a BSD-like license, so >> it can be used without issues. >> > > Oracle have a page about this: > http://www.mysql.com/about/legal/licensing/foss-exception/ Thanks, I was working from memory and wasn't sure. So yes, it's a fully legit issue, and it basically means you can't use MySQL with any proprietary code. So if I create a thin wrapper around libmysql, release that wrapper under the BSD 2-clause license (which is listed among the valid licenses - at least, I'm guessing that they mean the 2-clause), and then use that wrapper in a proprietary project, is that valid? This is getting ridiculously messy, and I'm definitely glad now not using MySQL at work. > As far as python goes, there are at least two pure-python > implementations of the mysql protocol available: > > - https://github.com/petehunt/PyMySQL (MIT license) That should be perfectly legal then. You're not linking against any GPL'd code, you're just connecting via a TCP socket to a GPL application. Really, I don't see what GPLing the client library achieves, other than creating a mess for people. ChrisA From stefan_ml at behnel.de Sat Jan 19 02:22:03 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 19 Jan 2013 08:22:03 +0100 Subject: Vote tallying... In-Reply-To: References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <7whames0hj.fsf@benfinney.id.au> <50f9f602.2583440a.7194.311c@mx.google.com> Message-ID: Chris Angelico, 19.01.2013 03:00: > On Sat, Jan 19, 2013 at 12:25 PM, Kushal Kumaran wrote: >> Chris Angelico writes: >> >>> On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney wrote: >>>> * MySQL's development has suffered under Sun, and become virtually >>>> moribund under Oracle. They operate as a closed shop, occasionally >>>> tossing GPL-licensed releases over the wall, with very little input >>>> accepted from the community. >>> >>> I don't know whether it's a legit concern or pure FUD, but it's been >>> suggested that since the MySQL license is GPL and not LGPL, any code >>> that links against it is forced to be GPL too. I'm not sure how far >>> that goes (eg if you're using it from Python, at what point does it >>> stop being "code linked to GPL code" and start being a discrete >>> system), and IANAL, but I prefer to work with systems with more >>> freedom in their licensing. PostgreSQL is under a BSD-like license, so >>> it can be used without issues. >> >> Oracle have a page about this: >> http://www.mysql.com/about/legal/licensing/foss-exception/ > > Thanks, I was working from memory and wasn't sure. So yes, it's a > fully legit issue, and it basically means you can't use MySQL with any > proprietary code. Well, you can, just like with any proprietary software that you link against GPL code. As long as you don't ship your code to someone else who doesn't have access to your source code, you're free to do whatever you like with it. That's usually the case when you deploy your software on your own servers, for example. Only if you distribute your software to other people, the GPL enforces that you give them your source code under the same license. Stefan From walterhurry at lavabit.com Sat Jan 19 21:02:38 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Sun, 20 Jan 2013 02:02:38 +0000 (UTC) Subject: Vote tallying... References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <7whames0hj.fsf@benfinney.id.au> Message-ID: On Sat, 19 Jan 2013 00:12:25 -0500, Dennis Lee Bieber wrote: > On Sat, 19 Jan 2013 07:24:40 +1100, Ben Finney > declaimed the following in > gmane.comp.python.general: > > >> * MySQL's development has suffered under Sun, and become virtually >> moribund under Oracle. They operate as a closed shop, occasionally >> tossing GPL-licensed releases over the wall, with very little input >> accepted from the community. >> > It has been forked by some of the original developers... > My vote is to put MySQL where it has always belonged (still more so, now that Oracle has taken it over), and use Postgres. From python.list at tim.thechases.com Fri Jan 18 15:57:32 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 18 Jan 2013 14:57:32 -0600 Subject: Vote tallying... In-Reply-To: References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> Message-ID: <50F9B73C.8020801@tim.thechases.com> On 01/18/13 13:26, Kwpolska wrote: > On Fri, Jan 18, 2013 at 4:19 PM, Nick Cash wrote: >> MySQL would certainly be fine, although I always recommend PostgreSQL over it. > > Bonus question, why? I write only from my personal experience, but the following might be reasons that Nick recommends PostgreSQL over MySQL: - Postgres has a history of putting SQL/database integrity first where MySQL emphasized speed over correctness. - it took a long time for MySQL to add more complex transactions and complex queries (things got a bit better in the 5.1 iterations of MySQL) - better support in Postgres for FOREIGN KEY constraints - a more linear scaling (the performance graphs I've seen for MySQL tend to buckle at a certain point, while the PSQL graphs for the same load tend to be more linear) - Postgres has a better track record of scaling across multiple processors/cores - there are just some serious what-the-heck's in MySQL's handling of some edge cases regarding NULL values and dates (Feb 31st anybody). There's a good compilation of them at [1]. Any one of them is enough to make me queasy at the idea of entrusting my data to it. - I'm not sure I'd trust MySQL under Oracle these days having seen how they (don't) promote it I do find that administering MySQL is just a bit less headache, but at a certain level of administration needs, Postgres offers more features. Just my 0.02 of whatever your local currency is :-) -tkc [1] http://sql-info.de/mysql/gotchas.html From schesis at gmail.com Fri Jan 18 17:54:32 2013 From: schesis at gmail.com (Zero Piraeus) Date: Fri, 18 Jan 2013 18:54:32 -0400 Subject: Vote tallying... In-Reply-To: <50F9B73C.8020801@tim.thechases.com> References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <50F9B73C.8020801@tim.thechases.com> Message-ID: : On 18 January 2013 16:57, Tim Chase wrote: > > - there are just some serious what-the-heck's in MySQL's handling of some > edge cases regarding NULL values and dates (Feb 31st anybody). There's a > good compilation of them at [1]. > > [1] > http://sql-info.de/mysql/gotchas.html I'm getting the following from that URL: ERROR: database not available ... which, as irony goes, is kinda delicious :-) -[]z. From python.list at tim.thechases.com Sat Jan 19 12:46:33 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 19 Jan 2013 11:46:33 -0600 Subject: Vote tallying... In-Reply-To: References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <50F9B73C.8020801@tim.thechases.com> Message-ID: <50FADBF9.9000901@tim.thechases.com> On 01/18/13 23:19, Dennis Lee Bieber wrote: > On Fri, 18 Jan 2013 18:54:32 -0400, Zero Piraeus >> On 18 January 2013 16:57, Tim Chase wrote: >>> >>> - there are just some serious what-the-heck's in MySQL's handling of some >>> edge cases regarding NULL values and dates (Feb 31st anybody). There's a >>> good compilation of them at http://sql-info.de/mysql/gotchas.html >> >> I'm getting the following from that URL: >> >> ERROR: database not available >> >> ... which, as irony goes, is kinda delicious :-) >> > Loads for me... Though the page does state that it applies to MySQL > 4.1 and earlier, and not to the current 5.x series (which added prepared > queries, stored procedures, and triggers as I recall). > > And the first link in the text is to: > http://sql-info.de/postgresql/postgres-gotchas.html The site was up for me both times I hit it, but it doesn't mean that Zero Piraeus didn't get a DB error (which *is* quite an amusing error in the context of the subject matter). Reading the MySQL gotchas and comparing it to the PostgreSQL gotchas, the MySQL ones scare the pants off my inner DBA, while the PostgreSQL ones are mostly "if you're running at 6+yr old version of the software, there are some peculiar behaviors". -tkc From rosuav at gmail.com Sat Jan 19 16:47:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Jan 2013 08:47:33 +1100 Subject: Vote tallying... In-Reply-To: <50FADBF9.9000901@tim.thechases.com> References: <50F8906D.9040203@r3dsolutions.com> <846C3A8E860C4344B567D813B63AA51D64BC9424@BL2PRD0610MB349.namprd06.prod.outlook.com> <50F9B73C.8020801@tim.thechases.com> <50FADBF9.9000901@tim.thechases.com> Message-ID: On Sun, Jan 20, 2013 at 4:46 AM, Tim Chase wrote: > Reading the MySQL gotchas and comparing it to the PostgreSQL gotchas, the > MySQL ones scare the pants off my inner DBA, while the PostgreSQL ones are > mostly "if you're running at 6+yr old version of the software, there are > some peculiar behaviors". > Some of them are still current, though they're the least serious. The requirement for "AS" in column aliasing is, imho, not a serious problem - according to the SQL spec, an omitted comma is interpreted as an alias, but PG will throw an error. The point that "SELECT COUNT(*) FROM table" is slow is simply that MySQL happens to know the current size of the table and can return it instantly... as soon as you put a WHERE clause on it, both databases will perform more comparably. Also, I think that advantage applies only to MyISAM tables, the default but also the most problematic. PostgreSQL does have a number of gotchas, mostly relating to performance (for instance, the default configuration on install is designed to work on as many systems as possible, which means it'll perform suboptimally everywhere, and especially will not take advantage of heaps of RAM). But MySQL has a *lot* more (whose insane idea was it to treat "database" and "schema" as synonymous??). ChrisA From dexter.rao19 at gmail.com Fri Jan 18 05:30:52 2013 From: dexter.rao19 at gmail.com (dexter.rao19 at gmail.com) Date: Fri, 18 Jan 2013 02:30:52 -0800 (PST) Subject: Weirdness with python and stdin redirection under Win32 In-Reply-To: References: <65c27c6b.0212040325.506fcca1@posting.google.com> Message-ID: <343090ed-89a8-4021-9f69-b5c5b81e16bf@googlegroups.com> On Saturday, December 7, 2002 5:10:07 AM UTC+5:30, Jonathan M. Gilligan wrote: > The bug is NOT fixed in Win2k. That's where I am seeing it (Win2K Pro SP3). > > Jonathan > > "Thomas Heller" wrote in message > news:fzteezlp.fsf at python.net... > > Norbert.Klamann at klamann-software.de (Norbert Klamann) writes: > > > If I remember correctly this is a Windows bug, it was mentioned > sometimes on this > > > list. > > > > > Right, but it is fixed in Win2k (and hopefully also on XP). > > > > Thomas Guys, I am trying my hands on Python, and i bump into an error and woah! when you google it up, it's an bug in windows. The bug which you people are discussing about is still not patched up in Win XP. I have updated all the my windows update and have installed all kinds of patch. regards dexter From jeanmichel at sequans.com Fri Jan 18 05:36:43 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 18 Jan 2013 11:36:43 +0100 (CET) Subject: Any built-in ishashable method ? In-Reply-To: <131224083.6623338.1358505012496.JavaMail.root@sequans.com> Message-ID: <759302175.6634281.1358505403597.JavaMail.root@sequans.com> Hello people, Is there any built-in way to know if an object is a valid dictionary key ? From what I know, the object must be hashable, and from the python doc, an object is hashable if it has the __hash__ and (__cmp__ or __eq__) methods. http://docs.python.org/2/glossary.html#term-hashable I found this on the net, but considering the above definition, does it really check the cmp/eq existence ? def ishashable(x): try: hash(x) except TypeError: return False else: return True I was trying to know if any custom class can be used as a dict key. It looks like you can. Yet I'm a little bit concerned, because last time I used invalid objects as keys, I got a bug that was really difficult to spot. Regards, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From d at davea.name Fri Jan 18 06:05:52 2013 From: d at davea.name (Dave Angel) Date: Fri, 18 Jan 2013 06:05:52 -0500 Subject: Any built-in ishashable method ? In-Reply-To: <759302175.6634281.1358505403597.JavaMail.root@sequans.com> References: <759302175.6634281.1358505403597.JavaMail.root@sequans.com> Message-ID: <50F92C90.5000505@davea.name> On 01/18/2013 05:36 AM, Jean-Michel Pichavant wrote: > Hello people, > > Is there any built-in way to know if an object is a valid dictionary key ? From what I know, the object must be hashable, and from the python doc, an object is hashable if it has the __hash__ and (__cmp__ or __eq__) methods. > > http://docs.python.org/2/glossary.html#term-hashable > > I found this on the net, but considering the above definition, does it really check the cmp/eq existence ? > > def ishashable(x): > try: > hash(x) > except TypeError: > return False > else: > return True > > I was trying to know if any custom class can be used as a dict key. It looks like you can. Yet I'm a little bit concerned, because last time I used invalid objects as keys, I got a bug that was really difficult to spot. > Yes, one can write custom classes whose objects may be used a dict key. The main conceptual requirement is the object be conceptually immutable. The way the class author indicates that is to define the two methods, __hash__() and __eq__(). (or __cmp__() I suppose) To avoid bugs, there are obviously some constraints on the semantics of those methods. Main ones are 1) that the hash value should not change over time, and 2) that if two instances are equal at one moment, that they stay so, and vice versa. -- DaveA From __peter__ at web.de Fri Jan 18 06:22:28 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 18 Jan 2013 12:22:28 +0100 Subject: Any built-in ishashable method ? References: <131224083.6623338.1358505012496.JavaMail.root@sequans.com> <759302175.6634281.1358505403597.JavaMail.root@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Hello people, > > Is there any built-in way to know if an object is a valid dictionary key ? > From what I know, the object must be hashable, and from the python doc, an > object is hashable if it has the __hash__ and (__cmp__ or __eq__) methods. > > http://docs.python.org/2/glossary.html#term-hashable > > I found this on the net, but considering the above definition, does it > really check the cmp/eq existence ? > > def ishashable(x): > try: > hash(x) > except TypeError: > return False > else: > return True > > I was trying to know if any custom class can be used as a dict key. It > looks like you can. Yet I'm a little bit concerned, because last time I > used invalid objects as keys, I got a bug that was really difficult to > spot. Hm, but trying to put an unhashable key into a dict gives the obvious exception: >>> class A(object): ... __hash__ = None ... >>> {A(): 42} Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'A' So I'm guessing you had a key where key1 == key2 did not imply hash(key1) == hash(key2) I don't see a way to avoid that problem in a look-before-you-leap test. From jeanmichel at sequans.com Fri Jan 18 06:56:09 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 18 Jan 2013 12:56:09 +0100 (CET) Subject: Any built-in ishashable method ? In-Reply-To: Message-ID: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> > So I'm guessing you had a key where > > key1 == key2 did not imply hash(key1) == hash(key2) > > I don't see a way to avoid that problem in a look-before-you-leap > test. > > -- > http://mail.python.org/mailman/listinfo/python-list > You guessed right. But it took me a lot of time before jumping to that conclusion, mostly because the code worked in the first place (it can with a little bit of luck). Now I'm extra careful about what I use as dict key, I was just wondering if there was a reliable quick way to verify an object can be used as key. That brings me to another question, is there any valid test case where key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design flaw ? JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From __peter__ at web.de Fri Jan 18 07:06:13 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 18 Jan 2013 13:06:13 +0100 Subject: Any built-in ishashable method ? References: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > That brings me to another question, is there any valid test case where > key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design > flaw ? I don't think there is a use case for such a behaviour other than annoying your collegues ;) From d at davea.name Fri Jan 18 07:29:21 2013 From: d at davea.name (Dave Angel) Date: Fri, 18 Jan 2013 07:29:21 -0500 Subject: Any built-in ishashable method ? In-Reply-To: References: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> Message-ID: <50F94021.8030701@davea.name> On 01/18/2013 07:06 AM, Peter Otten wrote: > Jean-Michel Pichavant wrote: > >> That brings me to another question, is there any valid test case where >> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design >> flaw ? > > I don't think there is a use case for such a behaviour other than annoying > your collegues ;) > Beg to differ. Nothing wrong with getting the same hash on objects that compare different. It's called a hash collision, and is quite common, especially in large collections. The problem is the converse of this, where the objects compare equal, but they have different hashes. -- DaveA From __peter__ at web.de Sat Jan 19 03:49:13 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 19 Jan 2013 09:49:13 +0100 Subject: Any built-in ishashable method ? References: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> <50F94021.8030701@davea.name> Message-ID: Dave Angel wrote: > On 01/18/2013 07:06 AM, Peter Otten wrote: >> Jean-Michel Pichavant wrote: >> >>> That brings me to another question, is there any valid test case where >>> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design >>> flaw ? >> >> I don't think there is a use case for such a behaviour other than >> annoying your collegues ;) >> > > Beg to differ. Nothing wrong with getting the same hash on objects that > compare different. It's called a hash collision, and is quite common, > especially in large collections. Of course. > The problem is the converse of this, where the objects compare equal, > but they have different hashes. And that I read because my expectations won over the actual text. From kushal.kumaran+python at gmail.com Fri Jan 18 20:36:32 2013 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 19 Jan 2013 07:06:32 +0530 Subject: Any built-in ishashable method ? In-Reply-To: References: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> Message-ID: <50f9f8a6.85ee440a.41aa.3094@mx.google.com> Peter Otten <__peter__ at web.de> writes: > Jean-Michel Pichavant wrote: > >> That brings me to another question, is there any valid test case where >> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design >> flaw ? > > I don't think there is a use case for such a behaviour other than annoying > your collegues ;) > It's fairly common. The set of possible keys can be much larger (possibly infinite) than the set of possible hash values (restricted to 32-bit or 64-bit integer values, afaict). -- regards, kushal From __peter__ at web.de Sat Jan 19 02:53:22 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 19 Jan 2013 08:53:22 +0100 Subject: Any built-in ishashable method ? References: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> <50f9f8a6.85ee440a.41aa.3094@mx.google.com> Message-ID: Kushal Kumaran wrote: > Peter Otten <__peter__ at web.de> writes: > >> Jean-Michel Pichavant wrote: >> >>> That brings me to another question, is there any valid test case where >>> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design >>> flaw ? >> >> I don't think there is a use case for such a behaviour other than >> annoying your collegues ;) >> > > It's fairly common. The set of possible keys can be much larger > (possibly infinite) than the set of possible hash values (restricted to > 32-bit or 64-bit integer values, afaict). Sorry, I misread the quoted text. If you replace key1 != key2 and hash(key1) == hash(key2) in Jean-Michel's question with key1 == key2 and hash(key1) != hash(key2) my reply should start to make sense... From christian at python.org Fri Jan 18 07:25:18 2013 From: christian at python.org (Christian Heimes) Date: Fri, 18 Jan 2013 13:25:18 +0100 Subject: Any built-in ishashable method ? In-Reply-To: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> References: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> Message-ID: <50F93F2E.6000600@python.org> Am 18.01.2013 12:56, schrieb Jean-Michel Pichavant: > You guessed right. But it took me a lot of time before jumping to that conclusion, mostly because the code worked in the first place (it can with a little bit of luck). > Now I'm extra careful about what I use as dict key, I was just wondering if there was a reliable quick way to verify an object can be used as key. > > That brings me to another question, is there any valid test case where key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design flaw ? That's a valid case. Hashing is not a permutation, it's (usually) surjective, not bijective. hash(key1) == hash(key2) is called a "hash collision". A good hashing algorithm should try to reduce the probability of collisions for likely keys. A secure algorithm should also make it as hard as possible to calculate deliberate collision. Collisions diminish the efficiency of a hash map from O(1) to O(n) and can be used for denial of service attacks. From tjreedy at udel.edu Fri Jan 18 07:27:34 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 18 Jan 2013 07:27:34 -0500 Subject: Any built-in ishashable method ? In-Reply-To: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> References: <627444785.6706139.1358510169194.JavaMail.root@sequans.com> Message-ID: On 1/18/2013 6:56 AM, Jean-Michel Pichavant wrote: > is there any valid test case You mean use case? > where key1 != key2 and hash(key1) == hash(key2) ? This is the normal case. There are many unequal items that have the same hash. The point of using hash is to quickly find items in the set/dict that *might* be equal to the candidate item, and to place items where they can be easily found. The alternative is a unordered list and a linear O(n) search, or a sorted list and a bisecting O(log(n)) search. (The latter is quite useful when one is doing insertion sort for small N or the list is static (or mostly so) and one want to know which items in the list bracket a candidate item that is not in the list.) The rule is key==key implies hash==hash, which is equivalent to hash != hash implies key != key. Reference 3.3 object.__hash__ "The only required property is that objects which compare equal have the same hash value;" > Or is it some kind of design flaw ? The flaw would be key1 == key2 and hash(key1) != hash(key2). Then the set/dict could store equal items multiple times in different places (unless it did a linear search of all members, which would make hashing pointless!). -- Terry Jan Reedy From jeanmichel at sequans.com Fri Jan 18 09:09:52 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 18 Jan 2013 15:09:52 +0100 (CET) Subject: Any built-in ishashable method ? In-Reply-To: Message-ID: <1308139807.6805047.1358518192691.JavaMail.root@sequans.com> > The flaw would be key1 == key2 and hash(key1) != hash(key2). Then the > set/dict could store equal items multiple times in different places > (unless it did a linear search of all members, which would make > hashing > pointless!). > > -- > Terry Jan Reedy My understanding of a hash function was wrong in the first place. Thank to this thread, I think I got it right now. Thanks to all who have contributed, (and those who haven't, yes, I'm in a good mood now). JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From tjreedy at udel.edu Fri Jan 18 06:25:51 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 18 Jan 2013 06:25:51 -0500 Subject: Any built-in ishashable method ? In-Reply-To: <759302175.6634281.1358505403597.JavaMail.root@sequans.com> References: <131224083.6623338.1358505012496.JavaMail.root@sequans.com> <759302175.6634281.1358505403597.JavaMail.root@sequans.com> Message-ID: On 1/18/2013 5:36 AM, Jean-Michel Pichavant wrote: > Hello people, > > Is there any built-in way to know if an object is a valid dictionary key ? For the instances of a class to be properly useable as set members or dict keys, __eq__ must return bool, __hash__ must return int, the __eq__ and __hash__ methods must define equivalence relations on the instances of the class, and the hash relation should be a coarsening of the eq relation. By default, for objects()s, equality is identity and hash is id, so these condition are met. If the instances of a class can compare equal to instances of another class then apply the , then apply the above to the union of the classes if they are used together in one set or dict. An example of when the union condition was broken. We had 0.0 == 0 and == decimal(0) but 0.0 != decimal(0). The breaking of transitivity of == has nasty effects when mixing floats, ints, and decimals in one set/class. (This is fixed now.) For one thing, set((0, 0.0, decimal(0))) had one member while set((0.0, 0, decimal(0))) had two ;-) > I was trying to know if any custom class can be used as a dict key. Yes, unless the __eq__ and __hash__ methods have been over-written in the inheritance chain in a way that violates the conditions, or if the class instances are mixed with other class instances that joint violate the conditions. > Yet I'm a little bit concerned, because last time I used invalid > objects as keys, I got a bug that was really difficult to spot. Yeh, see the example above ;-). -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Jan 18 07:16:52 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jan 2013 12:16:52 GMT Subject: Any built-in ishashable method ? References: Message-ID: <50f93d34$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Jan 2013 12:56:09 +0100, Jean-Michel Pichavant wrote: >> So I'm guessing you had a key where >> >> key1 == key2 did not imply hash(key1) == hash(key2) >> >> I don't see a way to avoid that problem in a look-before-you-leap test. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > You guessed right. But it took me a lot of time before jumping to that > conclusion, mostly because the code worked in the first place (it can > with a little bit of luck). Now I'm extra careful about what I use as > dict key, I was just wondering if there was a reliable quick way to > verify an object can be used as key. No. You can verify that an object is hashable, by trying to hash it, but there is no quick way to verify that the object's hash method isn't buggy. > That brings me to another question, is there any valid test case where > key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design > flaw ? Neither. It is a consequence of the nature of the universe: the Pigeonhole Principle. You can't put N+1 pigeons into N pigeonholes without at least one pigeonhole containing two pigeons. Take, for example, ints. There are an infinite number of possible ints in Python, or at least limited only by memory. But there are only a finite number of values they can be hashed to: hash values are limited to the values -2147483648 through 2147483647 in Python 2.7. You can't have an infinite set of values hash to a finite number of hashes without there being some duplicates. And so we have: py> hash(1) 1 py> hash(2**32) 1 py> hash(2**64) 1 py> hash(2**128) 1 py> hash(2**2048) 1 etc. Likewise, there are an infinite number of potential strings, which must hash into a finite number of hash values. Although it is hard for me to find hash collisions, I know that there must be some, because there are more strings than hash values. This is not a design flaw in the hash function, and can't be fixed by finding a more clever hash function. Nor is it a deliberate feature. It's just the way hashing works. -- Steven From python-list at wodny.org Fri Jan 18 07:04:38 2013 From: python-list at wodny.org (Marcin Szewczyk) Date: Fri, 18 Jan 2013 13:04:38 +0100 Subject: Inconsistent behaviour of methods waiting for child process Message-ID: <20130118120438.GA9862@magazyn-ziarno.chello.pl> Hi, I've done some experiments with: 1) multiprocessing.Process.join() 2) os.waitpid() 3) subprocess.Popen.wait() These three methods behave completely different when interrupted with a signal which I find disturbing. Reactions are: 1) exit with no exception or special return code 2) OSError exception 3) quiet retry (no exit) The 1) case is very impractical. Is there any movement towards standardization of those 3? Am I missing something and there is a way to get more information from Process.join()? -- Marcin Szewczyk http://wodny.org mailto:Marcin.Szewczyk at wodny.borg <- remove b / usu? b xmpp:wodny at ubuntu.pl xmpp:wodny at jabster.pl From matt.walker.jones at gmail.com Fri Jan 18 09:10:29 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Fri, 18 Jan 2013 08:10:29 -0600 Subject: Inconsistent behaviour of methods waiting for child process In-Reply-To: <20130118120438.GA9862@magazyn-ziarno.chello.pl> References: <20130118120438.GA9862@magazyn-ziarno.chello.pl> Message-ID: What version of python and os are you running? *Matt Jones* On Fri, Jan 18, 2013 at 6:04 AM, Marcin Szewczyk wrote: > Hi, > > I've done some experiments with: > 1) multiprocessing.Process.join() > 2) os.waitpid() > 3) subprocess.Popen.wait() > > These three methods behave completely different when interrupted with a > signal which I find disturbing. > > Reactions are: > 1) exit with no exception or special return code > 2) OSError exception > 3) quiet retry (no exit) > > The 1) case is very impractical. > > Is there any movement towards standardization of those 3? > > Am I missing something and there is a way to get more information from > Process.join()? > > -- > Marcin Szewczyk http://wodny.org > mailto:Marcin.Szewczyk at wodny.borg <- remove b / usu? b > xmpp:wodny at ubuntu.pl xmpp:wodny at jabster.pl > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Marcin.Szewczyk at wodny.org Fri Jan 18 09:17:04 2013 From: Marcin.Szewczyk at wodny.org (Marcin Szewczyk) Date: Fri, 18 Jan 2013 15:17:04 +0100 Subject: Inconsistent behaviour of methods waiting for child process In-Reply-To: References: <20130118120438.GA9862@magazyn-ziarno.chello.pl> Message-ID: <20130118141704.GF9862@magazyn-ziarno.chello.pl> On Fri, Jan 18, 2013 at 08:10:03AM -0600, Matt Jones wrote: > What version of python and os are you running? $ python --version Python 2.7.3rc2 $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 7.0 (wheezy) Release: 7.0 Codename: wheezy $ uname -a Linux magazyn-ziarno 3.2.0-4-686-pae #1 SMP Debian 3.2.35-2 i686 GNU/Linux -- Marcin Szewczyk http://wodny.org mailto:Marcin.Szewczyk at wodny.borg <- remove b / usu? b xmpp:wodny at ubuntu.pl xmpp:wodny at jabster.pl From rik.j.cross at gmail.com Fri Jan 18 09:47:52 2013 From: rik.j.cross at gmail.com (Rik) Date: Fri, 18 Jan 2013 06:47:52 -0800 (PST) Subject: Beginner Tutorials Message-ID: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use. www.usingpython.com From marco.kretz at jobmensa.de Fri Jan 18 10:53:05 2013 From: marco.kretz at jobmensa.de (marco.kretz at jobmensa.de) Date: Fri, 18 Jan 2013 07:53:05 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <844d9082-09dd-49b7-a2e2-72808192949f@googlegroups.com> Am Freitag, 18. Januar 2013 15:47:52 UTC+1 schrieb Rik: > Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use. > > > > www.usingpython.com Very nice and clean structure, I like it! But I would recommend to place the menu right below the header ;) From vs at it.uu.se Fri Jan 18 10:52:46 2013 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 18 Jan 2013 16:52:46 +0100 Subject: Beginner Tutorials In-Reply-To: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <50F96FCE.8020003@it.uu.se> On 18-Jan-2013 15:47, Rik wrote: > Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use. > > www.usingpython.com You have done well Rik. I like your approach to passwords for solutions and your selection of topics is quite good for a "jump start" with Python. However, I suggest that in your menu you change several of your items to lower case (for consistency with the Python language): For -> for, While -> while, if-Else -> if-else, Elif -> elif. I am curious --- what software did you use to create your nice web pages for this tutorial? In summary --- good work Rik :-) --V From joel.goldstick at gmail.com Fri Jan 18 11:35:57 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 18 Jan 2013 11:35:57 -0500 Subject: Beginner Tutorials In-Reply-To: <50F96FCE.8020003@it.uu.se> References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: On Fri, Jan 18, 2013 at 10:52 AM, Virgil Stokes wrote: > On 18-Jan-2013 15:47, Rik wrote: > >> Hi, I've developed a website for beginners to Python. I'd appreciate any >> comments or criticism. It's still under development, and should be finished >> in the next few months. Oh, and it's free to use. >> >> www.usingpython.com >> > You have done well Rik. I like your approach to passwords for solutions > and your selection of topics is quite good for a "jump start" with Python. > However, I suggest that in your menu you change several of your items to > lower case (for consistency with the Python language): For -> for, While > -> while, if-Else -> if-else, Elif -> elif. > > I am curious --- what software did you use to create your nice web pages > for this tutorial? > I was curious too, since I noticed right click doesn't work on the pages. So, you use Wordpress and have this plugin: http://chetangole.com/blog/wp-copyprotect/ . I am wondering why you think it is so important that your source code not be viewed? Of course it can be viewed with curl or wget or similar methods, just not be a curious reader who is interested in the underlying html that produced the site. Messing with the reader's browser is not considered polite by many! > > In summary --- good work Rik :-) > > --V > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rik.j.cross at gmail.com Fri Jan 18 12:04:39 2013 From: rik.j.cross at gmail.com (Rik) Date: Fri, 18 Jan 2013 09:04:39 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: The reason for disabling right-click has nothing to do with protecting content, and everything to do with stopping my students from taking the lazy way out. Given the chance, they'll copy/paste the code and download the designs and edit them slightly. They'd get through the tutorials in about 25 minutes and have learnt next to nothing. In talking to students about existing resources, they said that blindly copying code didn't really help them get a deep understanding of algorithms and how to apply them to other problems. In the password-protected solutions i will provide downloads to source code, etc, and any student smart enough to get around my protection probably understands python basics :) Thanks for the comments. From joel.goldstick at gmail.com Fri Jan 18 12:34:31 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 18 Jan 2013 12:34:31 -0500 Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: On Fri, Jan 18, 2013 at 12:04 PM, Rik wrote: > The reason for disabling right-click has nothing to do with protecting > content, and everything to do with stopping my students from taking the > lazy way out. > > Given the chance, they'll copy/paste the code and download the designs and > edit them slightly. They'd get through the tutorials in about 25 minutes > and have learnt next to nothing. > Ha Ha! that is hilarious. I haven't been a student for a while. I guess I am naive to think that young people would be interested, and take pleasure in becoming proficient rather than just a quick way to get a better grade. > > In talking to students about existing resources, they said that blindly > copying code didn't really help them get a deep understanding of algorithms > and how to apply them to other problems. > > In the password-protected solutions i will provide downloads to source > code, etc, and any student smart enough to get around my protection > probably understands python basics :) > > Thanks for the comments. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From xenplex at gmail.com Fri Jan 18 12:44:21 2013 From: xenplex at gmail.com (Ritchie Flick) Date: Fri, 18 Jan 2013 18:44:21 +0100 Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: Still a student myself and even if you really want to become good at what you're doing, some days one just feels lazy and in the mood for copy/pasting to get the job done quickly xD I like the site, will check it out ;) On Fri, Jan 18, 2013 at 6:34 PM, Joel Goldstick wrote: > > > > On Fri, Jan 18, 2013 at 12:04 PM, Rik wrote: > >> The reason for disabling right-click has nothing to do with protecting >> content, and everything to do with stopping my students from taking the >> lazy way out. >> >> Given the chance, they'll copy/paste the code and download the designs >> and edit them slightly. They'd get through the tutorials in about 25 >> minutes and have learnt next to nothing. >> > > Ha Ha! that is hilarious. I haven't been a student for a while. I guess > I am naive to think that young people would be interested, and take > pleasure in becoming proficient rather than just a quick way to get a > better grade. > >> >> In talking to students about existing resources, they said that blindly >> copying code didn't really help them get a deep understanding of algorithms >> and how to apply them to other problems. >> >> In the password-protected solutions i will provide downloads to source >> code, etc, and any student smart enough to get around my protection >> probably understands python basics :) >> >> Thanks for the comments. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Joel Goldstick > http://joelgoldstick.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Ritchie Flick -------------- next part -------------- An HTML attachment was scrubbed... URL: From rik.j.cross at gmail.com Fri Jan 18 12:04:39 2013 From: rik.j.cross at gmail.com (Rik) Date: Fri, 18 Jan 2013 09:04:39 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: The reason for disabling right-click has nothing to do with protecting content, and everything to do with stopping my students from taking the lazy way out. Given the chance, they'll copy/paste the code and download the designs and edit them slightly. They'd get through the tutorials in about 25 minutes and have learnt next to nothing. In talking to students about existing resources, they said that blindly copying code didn't really help them get a deep understanding of algorithms and how to apply them to other problems. In the password-protected solutions i will provide downloads to source code, etc, and any student smart enough to get around my protection probably understands python basics :) Thanks for the comments. From kwpolska at gmail.com Fri Jan 18 14:20:13 2013 From: kwpolska at gmail.com (Kwpolska) Date: Fri, 18 Jan 2013 20:20:13 +0100 Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: On Fri, Jan 18, 2013 at 6:04 PM, Rik wrote: > The reason for disabling right-click has nothing to do with protecting content, and everything to do with stopping my students from taking the lazy way out. http://lmgtfy.com/?q=don%27t+disable+right+click > Given the chance, they'll copy/paste the code and download the designs and edit them slightly. They'd get through the tutorials in about 25 minutes and have learnt next to nothing. Ways to overcome it: (a) curl/python -c 'import requests; requests.get('/wget http://usingpython.com/; (a nice textarea with the code (b) browser development tools, view source keyboard shortcuts etc.; (c) OCR; (d) disabling JavaScript; (e) writing it by hand, because it is relatively short. > In talking to students about existing resources, they said that blindly copying code didn't really help them get a deep understanding of algorithms and how to apply them to other problems. Can?t you fail them (or whatnot) if they don?t learn that? That sounds like the best solution to such problems. > In the password-protected solutions i will provide downloads to source code, etc, and any student smart enough to get around my protection probably understands python basics :) WordPress ? Python, unless your password is a code used to generate the 01189998819991197253 number out of prime factorization or something like that. > Thanks for the comments. > -- > http://mail.python.org/mailman/listinfo/python-list -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From kwpolska at gmail.com Sat Jan 19 06:46:06 2013 From: kwpolska at gmail.com (Kwpolska) Date: Sat, 19 Jan 2013 12:46:06 +0100 Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: Who thought that not setting the??Reply replies to the ML? option was a good idea? ---------- Forwarded message ---------- From: Rik Date: Fri, Jan 18, 2013 at 8:31 PM Subject: Re: Beginner Tutorials To: kwpolska at gmail.com On Friday, January 18, 2013 7:20:13 PM UTC, Kwpolska wrote: > > On Fri, Jan 18, 2013 at 6:04 PM, Rik wrote: > > The reason for disabling right-click has nothing to do with protecting content, and everything to do with stopping my students from taking the lazy way out. > > http://lmgtfy.com/?q=don%27t+disable+right+click > > > Given the chance, they'll copy/paste the code and download the designs and edit them slightly. They'd get through the tutorials in about 25 minutes and have learnt next to nothing. > > Ways to overcome it: > (a) curl/python -c 'import requests; requests.get('/wget > http://usingpython.com/; (a nice textarea with the code > (b) browser development tools, view source keyboard shortcuts etc.; > (c) OCR; > (d) disabling JavaScript; > (e) writing it by hand, because it is relatively short. > > > In talking to students about existing resources, they said that blindly copying code didn't really help them get a deep understanding of algorithms and how to apply them to other problems. > > Can?t you fail them (or whatnot) if they don?t learn that? That > sounds like the best solution to such problems. Yeah I could, and maybe for larger problems i'll maybe not block the code, I just find that students copy/paste the examples and *think* they understand what's going on, and then aren't able to be independent in solving similar problems. This way they are sort of 'forced' to actually understand the examples to a level that i'm happy will hep them solve other problems. It's my job to guide their learning in that way. > > > > > > In the password-protected solutions i will provide downloads to source code, etc, and any student smart enough to get around my protection probably understands python basics :) > > WordPress ? Python, unless your password is a code used to generate > the 01189998819991197253 number out of prime factorization or > something like that. Now that'd make a nice problem :) > > > > Thanks for the comments. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- > Kwpolska | GPG KEY: 5EAAEA16 > stop html mail | always bottom-post > http://asciiribbon.org | http://caliburn.nl/topposting.html From rantingrickjohnson at gmail.com Fri Jan 18 20:25:58 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 18 Jan 2013 17:25:58 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: <86b70a14-3b24-45c8-a7b1-c435b5779f0f@googlegroups.com> On Friday, January 18, 2013 11:04:39 AM UTC-6, Rik wrote: > The reason for disabling right-click has nothing to do > with protecting content, and everything to do with > stopping my students from taking the lazy way out. > > Given the chance, they'll copy/paste the code and download > the designs and edit them slightly. They'd get through the > tutorials in about 25 minutes and have learnt next to > nothing. > > In talking to students about existing resources, they said > that blindly copying code didn't really help them get a > deep understanding of algorithms and how to apply them to > other problems. Well anyone who is just blindly copying code to get through a CS course is obviously not a "natural" problem solver ,and thus, /incapable/ of becoming a proficient programmer anyhow. Programming *IS* problem solving. If you don't get any thrill from the hunt, you might as well go home and watch Monty python until your eyes bleed or the next welfare check arrives. But don't paint with too wide a brush on the copy-paste subject matter either because i have /no/ hesitation to copy paste when the code is mostly boilerplate required by some asinine interface, like oh I dunno, WINDOWS GUI PROGRAMMING!!! ?_?. I am not about to invest one second /learning/ much less trying to /comprehend/ why someone would create and release such a gawd awful monstrosity. Natural problem solvers always love a challenge and they always like to peek under the hood and see what makes this or that "tick". You need no more than to present these people with a problem and they *WILL* discover the answer (given enough time of course). "The only limit to an individuals imagination is his lifespan" --rr From rantingrickjohnson at gmail.com Fri Jan 18 20:25:58 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 18 Jan 2013 17:25:58 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> Message-ID: <86b70a14-3b24-45c8-a7b1-c435b5779f0f@googlegroups.com> On Friday, January 18, 2013 11:04:39 AM UTC-6, Rik wrote: > The reason for disabling right-click has nothing to do > with protecting content, and everything to do with > stopping my students from taking the lazy way out. > > Given the chance, they'll copy/paste the code and download > the designs and edit them slightly. They'd get through the > tutorials in about 25 minutes and have learnt next to > nothing. > > In talking to students about existing resources, they said > that blindly copying code didn't really help them get a > deep understanding of algorithms and how to apply them to > other problems. Well anyone who is just blindly copying code to get through a CS course is obviously not a "natural" problem solver ,and thus, /incapable/ of becoming a proficient programmer anyhow. Programming *IS* problem solving. If you don't get any thrill from the hunt, you might as well go home and watch Monty python until your eyes bleed or the next welfare check arrives. But don't paint with too wide a brush on the copy-paste subject matter either because i have /no/ hesitation to copy paste when the code is mostly boilerplate required by some asinine interface, like oh I dunno, WINDOWS GUI PROGRAMMING!!! ?_?. I am not about to invest one second /learning/ much less trying to /comprehend/ why someone would create and release such a gawd awful monstrosity. Natural problem solvers always love a challenge and they always like to peek under the hood and see what makes this or that "tick". You need no more than to present these people with a problem and they *WILL* discover the answer (given enough time of course). "The only limit to an individuals imagination is his lifespan" --rr From driscoll at cs.wisc.edu Fri Jan 18 23:36:09 2013 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Fri, 18 Jan 2013 22:36:09 -0600 Subject: Beginner Tutorials In-Reply-To: <86b70a14-3b24-45c8-a7b1-c435b5779f0f@googlegroups.com> References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> <86b70a14-3b24-45c8-a7b1-c435b5779f0f@googlegroups.com> Message-ID: <50FA22B9.8020606@cs.wisc.edu> On 1/18/2013 7:25 PM, Rick Johnson wrote: > Well anyone who is just blindly copying code to get through a CS > course is obviously not a "natural" problem solver ,and thus, > /incapable/ of becoming a proficient programmer anyhow. Programming > *IS* problem solving. If you don't get any thrill from the hunt, > you might as well go home and watch Monty python until your eyes > bleed or the next welfare check arrives. I have only skimmed this thread and so am unsure exactly what is being protected against casual copy/paste, but at least on its face I would *vehemently* disagree with your statement. There are at least two significant problems with it. First you ignore short-term pressures. It sounds like the tutorial in question is being used in some kind of course? If so, perhaps an assignment or two are badly timed with other life events (projects from other classes, external pressures, etc.) and, even though a person WOULD enjoy and be competent at solving the problem, those constraints pressure them to take the short-term "out" in the programming course, which also leads to them learning so much. But the bigger problem is that -- while you are right that programming is problem solving -- doing problem solving is probably not why most people got into it. At least personally, I got into it because I liked making stuff. If someone is attracted to the field because they go "oh hey I can program the next video game!" that doesn't automatically mean that they won't be good at it, but it may be that the problem-solving aspect of it is an acquired taste. As an analogy, I've been rock climbing for several years. There are several types of climbing; two of them are top roping, which is roped climbing and what you see most people in a climbing gym doing, and bouldering, which is climbing routes low to the ground (usually under 3 meters or so) without a rope. When I started, I basically exclusively did top roping. Bouldering seemed... dumb to me, like it was missing the point: "the reason you go climbing is to *climb*, and bouldering gives you very little of that." :-) But after I was going for a while, getting high above the ground became less of why I did it and the challenge of figuring out the right movements and such to complete the route started being my primary motivation for liking it. And those are things that bouldering has in fine measures; in some respects, it does that *better* than roped climbing*. (* Arguing about roped climbing vs bouldering might be that community's version of "Emacs is better than Vi". :-)) In other words, why I started climbing is very different from why I continued it. And I feel that the same could be said of programming. Just because you don't enjoy parts of programming when you're starting out doesn't mean that you're a lost cause by ANY means. Evan From rantingrickjohnson at gmail.com Sat Jan 19 01:22:25 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 18 Jan 2013 22:22:25 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> <86b70a14-3b24-45c8-a7b1-c435b5779f0f@googlegroups.com> Message-ID: <560868ee-fd4e-4fc9-b34e-25f562d20d0a@googlegroups.com> On Friday, January 18, 2013 10:36:09 PM UTC-6, Evan Driscoll wrote: > I have only skimmed this thread and so am unsure exactly what is being > protected against casual copy/paste, but at least on its face I would > *vehemently* disagree with your statement. Well if you skim just a wee bit more you will see how i took a view from both sides of the argument :) > There are at least two significant problems with it. First you ignore > short-term pressures. I think we can all understand short term pressures (especially those among us who actually work for a living) however, cheating not only harms the cheater, but also degrades the value of the education that the fellow students worked honestly to achieve -- that's my real beef. > But the bigger problem is that -- while you are right that programming > is problem solving -- doing problem solving is probably not why most > people got into it. At least personally, I got into it because I liked > making stuff. Is not "making stuff" a form of problem solving? You may not enjoy writing code because it solves a real world tangible problem (like a calculator for solving math equations or a spreadsheet for organizing data, or flight control software... wait, don't use python for the last one!) but the "act" of creating anything involves solving problems, yes? * What am i making? * What language provides the tools i need? * How will it interface with the world? * What will it do? (Even if only to not throw an exception) :) * Will it be automated or require input control? * GUI or command line? * What dependencies will it require? * etc... And that's just the initial draft design phase. These handful of problems have deeply nested sub-problems hidden below. But maybe you are referring to the satisfaction you get when witnessing your "creation" in action. Ah, yes. This is a great feeling! Especially when you've worked for hours tracking some subtle bug because of a bad language feature or poor interface and you almost threw in the towel twenty times, but /something/ kept you coming back. What was it? Was it the fact that you would not allow yourself to be defeated? Was it the addiction to the satisfaction you get from creating a program that runs without error and actually does something useful? These are the monkeys on the back of every good programmer. > If someone is attracted to the field because they go "oh > hey I can program the next video game!" that doesn't automatically mean > that they won't be good at it, but it may be that the problem-solving > aspect of it is an acquired taste. Like these people you mention, my initial interest was very specific. I needed to create a few tools for myself, and i thought that would be the extent of my programming. But after writing a few apps i was hooked! And as i progressed writing more and more code, i became more and more addicted. Coding actually transformed the way i interpret the world. I am constantly looking for consistency, logic, intuitiveness in every interface around me. That could be my car, my toaster, whatever. But most importantly, programming has honed my problem solving skills to razor perfection! Especially OOP. Which can be transformed into many problem domains. I think a lot of energetic and naive people get attracted to writing code from games, however, once they start up the steep learning curve without an ability to problem-solve (or a good starter language like python), they get frustrated and quit. These people cannot problem-solve themselves out of a wet paper bag! And i think a good programmer, along with being a great problem solver, is a bit of a risk taker. I mean, how else are you going to learn without taking risks. An infinite recursion here, a segfault there... accidentally used rmdir on your porn folder, oops! It's all part of cutting teeth. Another trait of the programmer, an innate sense of curiosity. A good litmus test is to offer a complicated software application to a group of people of which none have used before and all are unfamiliar with. Then, see who becomes proficient with the interface. That's the subgroup who will make great programmers! While the dummies start out reading the manual, the natural problem solvers will jump head first into the interface and attempt to intuit every command. When, after exhausting all there comprehensive abilities, they don't understand a certain feature, then and *only* then do they consult the docs. And sometimes, the doc are just insufficient anyways. But the point is, the true problem solver discovers his own weaknesses, takes mental note of them, and then methodically *DESTROYS* them. Divide and conquer. This is the method by which intelligent beings solve problems. > As an analogy, I've been rock climbing for several years. There are > several types of climbing; two of them are top roping, which is roped > climbing and what you see most people in a climbing gym doing, and > bouldering, which is climbing routes low to the ground (usually under 3 > meters or so) without a rope. When I started, I basically exclusively > did top roping. Bouldering seemed... dumb to me, like it was missing the > point: "the reason you go climbing is to *climb*, and bouldering gives > you very little of that." :-) But after I was going for a while, getting > high above the ground became less of why I did it and the challenge of > figuring out the right movements and such to complete the route started > being my primary motivation for liking it. And those are things that > bouldering has in fine measures; in some respects, it does that *better* > than roped climbing*. > > (* Arguing about roped climbing vs bouldering might be that community's > version of "Emacs is better than Vi". :-)) That was a great analogy! > In other words, why I started climbing is very different from why I > continued it. And I feel that the same could be said of programming. > Just because you don't enjoy parts of programming when you're starting > out doesn't mean that you're a lost cause by ANY means. I agree completely. However, my condemnation was mainly against cheating. From rantingrickjohnson at gmail.com Sat Jan 19 01:22:25 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 18 Jan 2013 22:22:25 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> <50F96FCE.8020003@it.uu.se> <86b70a14-3b24-45c8-a7b1-c435b5779f0f@googlegroups.com> Message-ID: <560868ee-fd4e-4fc9-b34e-25f562d20d0a@googlegroups.com> On Friday, January 18, 2013 10:36:09 PM UTC-6, Evan Driscoll wrote: > I have only skimmed this thread and so am unsure exactly what is being > protected against casual copy/paste, but at least on its face I would > *vehemently* disagree with your statement. Well if you skim just a wee bit more you will see how i took a view from both sides of the argument :) > There are at least two significant problems with it. First you ignore > short-term pressures. I think we can all understand short term pressures (especially those among us who actually work for a living) however, cheating not only harms the cheater, but also degrades the value of the education that the fellow students worked honestly to achieve -- that's my real beef. > But the bigger problem is that -- while you are right that programming > is problem solving -- doing problem solving is probably not why most > people got into it. At least personally, I got into it because I liked > making stuff. Is not "making stuff" a form of problem solving? You may not enjoy writing code because it solves a real world tangible problem (like a calculator for solving math equations or a spreadsheet for organizing data, or flight control software... wait, don't use python for the last one!) but the "act" of creating anything involves solving problems, yes? * What am i making? * What language provides the tools i need? * How will it interface with the world? * What will it do? (Even if only to not throw an exception) :) * Will it be automated or require input control? * GUI or command line? * What dependencies will it require? * etc... And that's just the initial draft design phase. These handful of problems have deeply nested sub-problems hidden below. But maybe you are referring to the satisfaction you get when witnessing your "creation" in action. Ah, yes. This is a great feeling! Especially when you've worked for hours tracking some subtle bug because of a bad language feature or poor interface and you almost threw in the towel twenty times, but /something/ kept you coming back. What was it? Was it the fact that you would not allow yourself to be defeated? Was it the addiction to the satisfaction you get from creating a program that runs without error and actually does something useful? These are the monkeys on the back of every good programmer. > If someone is attracted to the field because they go "oh > hey I can program the next video game!" that doesn't automatically mean > that they won't be good at it, but it may be that the problem-solving > aspect of it is an acquired taste. Like these people you mention, my initial interest was very specific. I needed to create a few tools for myself, and i thought that would be the extent of my programming. But after writing a few apps i was hooked! And as i progressed writing more and more code, i became more and more addicted. Coding actually transformed the way i interpret the world. I am constantly looking for consistency, logic, intuitiveness in every interface around me. That could be my car, my toaster, whatever. But most importantly, programming has honed my problem solving skills to razor perfection! Especially OOP. Which can be transformed into many problem domains. I think a lot of energetic and naive people get attracted to writing code from games, however, once they start up the steep learning curve without an ability to problem-solve (or a good starter language like python), they get frustrated and quit. These people cannot problem-solve themselves out of a wet paper bag! And i think a good programmer, along with being a great problem solver, is a bit of a risk taker. I mean, how else are you going to learn without taking risks. An infinite recursion here, a segfault there... accidentally used rmdir on your porn folder, oops! It's all part of cutting teeth. Another trait of the programmer, an innate sense of curiosity. A good litmus test is to offer a complicated software application to a group of people of which none have used before and all are unfamiliar with. Then, see who becomes proficient with the interface. That's the subgroup who will make great programmers! While the dummies start out reading the manual, the natural problem solvers will jump head first into the interface and attempt to intuit every command. When, after exhausting all there comprehensive abilities, they don't understand a certain feature, then and *only* then do they consult the docs. And sometimes, the doc are just insufficient anyways. But the point is, the true problem solver discovers his own weaknesses, takes mental note of them, and then methodically *DESTROYS* them. Divide and conquer. This is the method by which intelligent beings solve problems. > As an analogy, I've been rock climbing for several years. There are > several types of climbing; two of them are top roping, which is roped > climbing and what you see most people in a climbing gym doing, and > bouldering, which is climbing routes low to the ground (usually under 3 > meters or so) without a rope. When I started, I basically exclusively > did top roping. Bouldering seemed... dumb to me, like it was missing the > point: "the reason you go climbing is to *climb*, and bouldering gives > you very little of that." :-) But after I was going for a while, getting > high above the ground became less of why I did it and the challenge of > figuring out the right movements and such to complete the route started > being my primary motivation for liking it. And those are things that > bouldering has in fine measures; in some respects, it does that *better* > than roped climbing*. > > (* Arguing about roped climbing vs bouldering might be that community's > version of "Emacs is better than Vi". :-)) That was a great analogy! > In other words, why I started climbing is very different from why I > continued it. And I feel that the same could be said of programming. > Just because you don't enjoy parts of programming when you're starting > out doesn't mean that you're a lost cause by ANY means. I agree completely. However, my condemnation was mainly against cheating. From ian at feete.org Fri Jan 18 11:35:55 2013 From: ian at feete.org (Ian Foote) Date: Fri, 18 Jan 2013 16:35:55 +0000 Subject: Beginner Tutorials In-Reply-To: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <50F979EB.6010104@feete.org> On 18/01/13 14:47, Rik wrote: > Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use. > > www.usingpython.com > Is there a particular reason you disable right-click with javascript? Regards, Ian F From ian at feete.org Fri Jan 18 11:44:46 2013 From: ian at feete.org (Ian Foote) Date: Fri, 18 Jan 2013 16:44:46 +0000 Subject: Beginner Tutorials In-Reply-To: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <50F97BFE.80503@feete.org> On 18/01/13 14:47, Rik wrote: > Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use. > > www.usingpython.com > Your example code on http://usingpython.com/variables/ is missing a space: #Whatever the user enters is stored in a variable called ?name?. name = input("What is your name? ") # Remember how we can use + to ?add? strings together? print("Hello" + name + "!") Here's my output: >>> name = input("What is your name? ") What is your name? Ian >>> print("Hello" + name + "!") HelloIan! Your final print should be: print("Hello " + name + "!") Regards, Ian F From rik.j.cross at gmail.com Fri Jan 18 11:55:58 2013 From: rik.j.cross at gmail.com (Rik) Date: Fri, 18 Jan 2013 08:55:58 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <437504c1-bcc9-4fba-8d7d-b4295f395de9@googlegroups.com> Thanks for the comments. I have changed the headings to lower case as you suggested. The site was created in wordpress using a standard theme, and linked pages rather than posts. i'd recommend using it to quickly set up a site; i started developing my own site but wanted to focus on site content and not HTML! > You have done well Rik. I like your approach to passwords for solutions and > > your selection of topics is quite good for a "jump start" with Python. However, > > I suggest that in your menu you change several of your items to lower case (for > > consistency with the Python language): For -> for, While -> while, if-Else -> > > if-else, Elif -> elif. > > > > I am curious --- what software did you use to create your nice web pages for > > this tutorial? > > > > In summary --- good work Rik :-) > > > > --V From rik.j.cross at gmail.com Fri Jan 18 11:55:58 2013 From: rik.j.cross at gmail.com (Rik) Date: Fri, 18 Jan 2013 08:55:58 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <437504c1-bcc9-4fba-8d7d-b4295f395de9@googlegroups.com> Thanks for the comments. I have changed the headings to lower case as you suggested. The site was created in wordpress using a standard theme, and linked pages rather than posts. i'd recommend using it to quickly set up a site; i started developing my own site but wanted to focus on site content and not HTML! > You have done well Rik. I like your approach to passwords for solutions and > > your selection of topics is quite good for a "jump start" with Python. However, > > I suggest that in your menu you change several of your items to lower case (for > > consistency with the Python language): For -> for, While -> while, if-Else -> > > if-else, Elif -> elif. > > > > I am curious --- what software did you use to create your nice web pages for > > this tutorial? > > > > In summary --- good work Rik :-) > > > > --V From rik.j.cross at gmail.com Fri Jan 18 12:16:39 2013 From: rik.j.cross at gmail.com (Rik) Date: Fri, 18 Jan 2013 09:16:39 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <07fae3cf-9794-4f81-9ce0-50d71ffbe78a@googlegroups.com> Well spotted! > Your final print should be: > > > > print("Hello " + name + "!") > > > > Regards, > > Ian F From rik.j.cross at gmail.com Fri Jan 18 12:16:39 2013 From: rik.j.cross at gmail.com (Rik) Date: Fri, 18 Jan 2013 09:16:39 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: <07fae3cf-9794-4f81-9ce0-50d71ffbe78a@googlegroups.com> Well spotted! > Your final print should be: > > > > print("Hello " + name + "!") > > > > Regards, > > Ian F From kalvinmanual1 at gmail.com Fri Jan 18 14:09:25 2013 From: kalvinmanual1 at gmail.com (kalvinmanual1) Date: Fri, 18 Jan 2013 13:09:25 -0600 Subject: Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight) Message-ID: I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. solutions manual :: Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight) solutions manual :: Satellite Communications 2nd Ed By Timothy Pratt, Charles W. Bostian solutions manual :: Scientific Computing with Case Studies by Dianne P. O'Leary solutions manual :: Semiconductor Device Fundamentals by Pierret solutions manual :: SEMICONDUCTOR DEVICES Physics and Technology 2nd Ed by SZE solutions manual :: Semiconductor Physics and Applications by Balkanski, Wallis solutions manual :: Semiconductor Physics and Devices (3rd Ed., Donald A. Neamen) solutions manual :: Semiconductor Physics and Devices 4th E by Donald A. Neamen solutions manual :: Separation Process Principles 2nd ED by Seader, Henley solutions manual :: Separation Process Principles by Seader & Henley solutions manual :: SERWAY AND VUILLE???S COLLEGE PHYSICS NINTH EDITION solutions manual :: Shigley's Mechanical Engineering Design (8th Ed., Budynas) solutions manual :: Signal Processing and Linear Systems by Lathi solutions manual :: Signal Processing First by Mclellan, Schafer & Yoder solutions manual :: Signals and Systems 2e by Haykin & B Van Veen solutions manual :: Signals and Systems 2nd Edition Oppenheim, Willsky and Nawab solutions manual :: Signals and Systems Analysis of Signals Through Linear Systems by M.J. Roberts, M.J. Roberts solutions manual :: Signals and Systems, 2nd Edition, Oppenheim, Willsky, Hamid, Nawab solutions manual :: Signals and Systems: Analysis Using Transform Methods and MATLAB, 1st Ed., by M. J. Roberts solutions manual :: Signals, Systems & Transforms 3rd ED by Phillips, Parr & Riskin solutions manual :: Signals, Systems & Transforms 4 ED by Phillips, Parr & Riskin solutions manual :: SILICON VLSI TECHNOLOGY Fundamentals, Practice and Modeling By Plummer, Griffin solutions manual :: Simply C# - An Application-Driven (TM) Tutorial Approach by Deitel solutions manual :: Single Variable Calculus Early Transcendentals, 4th Edition, JAMES STEWART solutions manual :: Single Variable Calculus Early Transcendentals, 5th Edition, JAMES STEWART solutions manual :: Sipser's Introduction to the Theory of COMPUTATION solutions manual :: Skill - Assessment Exercises to Accompany Control Systems Engineering 3rd edt. by Norman S. Nise solutions manual :: Skill - Assessment Exercises to Accompany Control Systems Engineering 5th edt. by Norman S. Nise solutions manual :: Soil Mechanics 7th ed by R. F. Craig solutions manual :: Soil Mechanics Concepts and Applications, 2nd Ed., by Powrie solutions manual :: Solid State Electronic Devices (6th Ed., Ben Streetman, Sanjay Banerjee) solutions manual :: Solid State Electronics 5th ed by Ben Streetman, Sanjay Banerjee solutions manual :: Solid State Physics by Ashcroft & Mermin solutions manual :: Solid State Physics by Lazlo Mihaly, Michael C. Martin solutions manual :: Solving Applied Mathematical Problems with MATLAB by Xue, Chen solutions manual :: Solving ODEs with MATLAB (L. F. Shampine, I. Gladwell & S. Thompson) solutions manual :: South-Western Federal Taxation 2012 - Corporations, Partnerships, Estates and Trusts, 35th Ed by Hoffman, Maloney solutions manual :: Special Relativity (P.M. Schwarz & J.H. Schwarz) solutions manual :: Statics and Mechanics of Materials by Bedford, Fowler, Liechti solutions manual :: Statics and Mechanics of Materials, 2/E., By Russell C. Hibbeler solutions manual :: Statistical and Adaptive Signal Processing by Manolakis, Ingle, Kogon solutions manual :: Statistical Digital Signal Processing and Modeling ,Monson H. Hayes solutions manual :: Statistical Inference 2e by Casella G., Berger R.L. and Santana solutions manual :: Statistical Inference, Second Edition Casella-Berger solutions manual :: Statistical Physics of Fields by Mehran Kardar solutions manual :: Statistical Physics of Particles by Mehran Kardar solutions manual :: Statistics and Finance - An Introduction by David Ruppert solutions manual :: Statistics and Finance - An Introduction by David Ruppert solutions manual :: Statistics for Business and Economics 8 ED by Anderson, Sweeney solutions manual :: Statistics for Business and Economics 9 ED by Anderson, Sweeney solutions manual :: Statistics for Engineering and the Sciences 5th E by Mendenhall,Sincich solutions manual :: Statistics for Engineers and Scientists 2 E by Navidi solutions manual :: Steel Design, 4th Edition Segui solutions manual :: STEEL DESIGN, 5th Edition By WILLIAM T. SEGUI solutions manual :: Stochastic Calculus for Finance, Vol I & Vol II by Yan Zeng solutions manual :: Stochastic Processes An Introduction by Peter W Jones and Peter Smith solutions manual :: Strength of Materials 4th Ed. by Ferdinand L. Singer & Andrew Pytel solutions manual :: Structural Analysis (5th Edition) by R.C. Hibbeler solutions manual :: Structural Analysis (7th Edition) by R.C. Hibbeler solutions manual :: Structural analysis 3rd Edition Aslam Kassimali solutions manual :: Structural Analysis 4th Ed by Aslam??Kassimali?? solutions manual :: Structural and Stress Analysis (2nd Ed., Megson) solutions manual :: Structural Steel Design 4th Ed by McCormac solutions manual :: Student's Solutions Manual to Complex Variables and Applications 8th ed by James Ward Brown, Ruel V.Churchill solutions manual :: Surveying - Principles & Applications 8th ed by Barry F. Kavanagh solutions manual :: Surveying with Construction Applications 7th Ed by Barry Kavanagh solutions manual :: System Dynamics 3rd Ed. by Katsuhiko Ogata solutions manual :: System Dynamics and Response, S. Graham Kelly solutions manual :: System Dynamics by William Palm III solutions manual :: Techniques of Problem Solving by Luis Fernandez solutions manual :: The 8051 Microcontroller 4th Ed. by I. Scott MacKenzie and Raphael C.-W. Phan solutions manual :: THE 8088 & 8086 MICROPROCESSORS 4e by Triebel & Singh solutions manual :: The Calculus 7ed by Louis Leithold solutions manual :: The Chemistry Maths Book 2nd ED by Erich Steiner solutions manual :: The Econometrics of Financial Markets, by Adamek, Cambell, Lo, MacKinlay, Viceira solutions manual :: The Economics of Financial Markets by Roy E. Bailey solutions manual :: The Elements of Statistics- With Applications to Economics and the Social Sciences by Ramsey solutions manual :: The Environment by Greg Lewis solutions manual :: The Physical Basis of Biochemistry 2nd edition by Peter R. Bergethon, Kevin Hallock solutions manual :: The Science & Engineering of Materials ( Vol 1) 5th Ed by Askeland solutions manual :: The Science and Engineering of Materials, 4E, by Donald R.Askeland, Pradeep P. Phule solutions manual :: The Sciences- An Integrated Approach, 5th Ed by Trefil, Hazen solutions manual :: The Structure and Interpretation of Signals and Systems (Edward A. Lee & Pravin Varaiya) solutions manual :: The Theory of Interest 3rd ED by Stephen Kellison solutions manual :: Theory and Design for Mechanical Measurements (4th Ed, Figliola & Beasley) solutions manual :: Theory of Asset Pricing (George Pennacchi) solutions manual :: Thermal Physics, 2nd Edition, by Charles Kittel solutions manual :: Thermodynamics - An Engineering Approach 7th E by Cengel, Boles solutions manual :: Thermodynamics - An Engineering Approach, 2E Yunus A. Cengel solutions manual :: Thermodynamics An Engineering Approach ( 7th Ed., Cengel ) solutions manual :: Thermodynamics An Engineering Approach (5th Ed., Cengel) solutions manual :: Thermodynamics: An Engineering Approach (6th Ed., Cengel) solutions manual :: Thomas and Maurice's Managerial Economics, 10th edition solutions manual :: Thomas' Calculus Early Transcendentals 10th ed Vol 1 by Thomas, Finney, Weir, Giordano solutions manual :: Thomas' Calculus Early Transcendentals 10th ed Vol 2 by Thomas, Finney, Weir, Giordano solutions manual :: Thomas' Calculus, Early Transcendentals, Media Upgrade, 11E by Thomas, Weir, Hass, Giordano solutions manual :: Thomas' Calculus, Multivariable, 12th Ed By Thomas,Weir,Hass solutions manual :: Thomas' Calculus, Single Variable, 12th Ed By Thomas,Weir,Hass solutions manual :: Topology Problem Solver (Problem Solvers) solutions manual :: Traffic & Highway Engineering 3rd E by Garber, Hoel From roy at panix.com Fri Jan 18 20:32:49 2013 From: roy at panix.com (Roy Smith) Date: Fri, 18 Jan 2013 20:32:49 -0500 Subject: Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight) References: Message-ID: Can whoever manages the mailing list block this bozo? In article , kalvinmanual1 wrote: > I have solutions manuals to all problems and exercises in these textbooks. To > get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com > and let me know its title, author and edition. Please this service is NOT > free. From robertmiles at teranews.com Sat Jan 19 01:03:22 2013 From: robertmiles at teranews.com (Robert Miles) Date: Sat, 19 Jan 2013 00:03:22 -0600 Subject: Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight) In-Reply-To: References: Message-ID: On 1/18/2013 7:32 PM, Roy Smith wrote: > Can whoever manages the mailing list block this bozo? > > In article , > kalvinmanual1 wrote: > >> I have solutions manuals to all problems and exercises in these textbooks. To >> get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com >> and let me know its title, author and edition. Please this service is NOT >> free. I don't use the mailing list, but I'll try another method for blocking this alleged human. From nikos.gr33k at gmail.com Fri Jan 18 15:48:15 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 12:48:15 -0800 (PST) Subject: Uniquely identifying each & every html template Message-ID: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> I use this .htaccess file to rewrite every .html request to counter.py # ================================================================================================================= RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA] # ================================================================================================================= counter.py script is created for creating, storing, increasing, displaying a counter for each webpage for every website i have. It's supposed to identify each webpage by a and then do it's database stuff from there # ================================================================================================================= # open current html template and get the page ID number # ================================================================================================================= f = open( '/home/nikos/public_html/' + page ) # read first line of the file firstline = f.readline() # find the ID of the file and store it pin = re.match( r'', firstline ).group(1) # ================================================================================================================= It works as expected and you can see it works normally by viewing: http//superhost.gr (bottom down its the counter) What is the problem you ask?! Problem is that i have to insert at the very first line of every .html template of mine, a unique string containing a number like: index.html somefile.html other.html nikos.html cool.html to HELP counter.py identify each webpage at a unique way. Well.... its about 1000 .html files inside my DocumentRoot and i cannot edit ALL of them of course! Some of them created by Notepad++, some with the use of Dreamweaver and some others with Joomla CMS Even if i could embed a number to every html page, it would have been a very tedious task, and what if a change was in order? Edit them ALL back again? Of course not. My question is HOW am i suppose to identify each and every html webpage i have, without the need of editing and embedding a string containing a number for them. In other words by not altering their contents. or perhaps by modifying them a bit..... but in an automatic way....? Thank you ALL in advance. From gordon at panix.com Fri Jan 18 15:59:17 2013 From: gordon at panix.com (John Gordon) Date: Fri, 18 Jan 2013 20:59:17 +0000 (UTC) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> Message-ID: In <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e at googlegroups.com> Ferrous Cranus writes: > Problem is that i have to insert at the very first line of every .html template of mine, a unique string containing a number like: > index.html > somefile.html > other.html > nikos.html > cool.html > to HELP counter.py identify each webpage at a unique way. Instead of inserting unique content in every page, can you use the document path itself as the identifier? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From nikos.gr33k at gmail.com Fri Jan 18 17:12:33 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 18 Jan 2013 14:12:33 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> Message-ID: <56802884-9a7d-4aae-b080-115a300b1023@googlegroups.com> ?? ?????????, 18 ?????????? 2013 10:59:17 ?.?. UTC+2, ? ??????? John Gordon ??????: > Instead of inserting unique content in every page, can't you use the > document path itself as the identifier? No, i cannot, becaue it would mess things at later time when i for example: 1. mv name.html othername.html (document's filename altered) 2. mv name.html /subfolder/name.html (document's path altered) Hence, new database counters will be created for each of the above cases. From d at davea.name Fri Jan 18 17:09:28 2013 From: d at davea.name (Dave Angel) Date: Fri, 18 Jan 2013 17:09:28 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> Message-ID: <50F9C818.9010707@davea.name> On 01/18/2013 03:48 PM, Ferrous Cranus wrote: > I use this .htaccess file to rewrite every .html request to counter.py > > # ================================================================================================================= > RewriteEngine On > RewriteCond %{REQUEST_FILENAME} -f > RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA] > # ================================================================================================================= > > > > counter.py script is created for creating, storing, increasing, displaying a counter for each webpage for every website i have. > It's supposed to identify each webpage by a and then do it's database stuff from there > > # ================================================================================================================= > # open current html template and get the page ID number > # ================================================================================================================= > f = open( '/home/nikos/public_html/' + page ) > > # read first line of the file > firstline = f.readline() > > # find the ID of the file and store it > pin = re.match( r'', firstline ).group(1) > # ================================================================================================================= > > It works as expected and you can see it works normally by viewing: http//superhost.gr (bottom down its the counter) > > What is the problem you ask?! > Problem is that i have to insert at the very first line of every .html template of mine, a unique string containing a number like: > > index.html > somefile.html > other.html > nikos.html > cool.html > > to HELP counter.py identify each webpage at a unique way. > > Well.... its about 1000 .html files inside my DocumentRoot and i cannot edit ALL of them of course! > Some of them created by Notepad++, some with the use of Dreamweaver and some others with Joomla CMS > Even if i could embed a number to every html page, it would have been a very tedious task, and what if a change was in order? Edit them ALL back again? Of course not. > > My question is HOW am i suppose to identify each and every html webpage i have, without the need of editing and embedding a string containing a number for them. In other words by not altering their contents. > > or perhaps by modifying them a bit..... but in an automatic way....? > > Thank you ALL in advance. > > I don't understand the problem. A trivial Python script could scan through all the files in the directory, checking which ones are missing the identifier, and rewriting the file with the identifier added. So, since you didn't come to that conclusion, there must be some other reason you don't want to edit the files. Is it that the real sources are elsewhere (e.g. Dreamweaver), and whenever one recompiles those sources, these files get replaced (without identifiers)? If that's the case, then I figure you have about 3 choices: 1) use the file path as your key, instead of requiring a number 2) use a hash of the page (eg. md5) as your key. of course this could mean that you get a new value whenever the page is updated. That's good in many situations, but you don't give enough information to know if that's desirable for you or not. 3) Keep an external list of filenames, and their associated id numbers. The database would be a good place to store such a list, in a separate table. -- DaveA From nikos.gr33k at gmail.com Sat Jan 19 03:39:44 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 19 Jan 2013 00:39:44 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> Message-ID: <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> ?? ???????, 19 ?????????? 2013 12:09:28 ?.?. UTC+2, ? ??????? Dave Angel ??????: > I don't understand the problem. A trivial Python script could scan > > through all the files in the directory, checking which ones are missing > > the identifier, and rewriting the file with the identifier added. > > So, since you didn't come to that conclusion, there must be some other > > reason you don't want to edit the files. Is it that the real sources > > are elsewhere (e.g. Dreamweaver), and whenever one recompiles those > > sources, these files get replaced (without identifiers)? Exactly. Files get modified/updates thus the embedded identifier will be missing each time. So, relying on embedding code to html template content is not practical. > If that's the case, then I figure you have about 3 choices: > 1) use the file path as your key, instead of requiring a number No, i cannot, because it would mess things at a later time on when i for example: 1. mv name.html othername.html (document's filename altered) 2. mv name.html /subfolder/name.html (document's filepath altered) Hence, new database counters will be created for each of the above actions, therefore i will be having 2 counters for the same file, and the latter one will start from a zero value. Pros: If the file's contents gets updated, that won't affect the counter. Cons: If filepath is altered, then duplicity will happen. > 2) use a hash of the page (eg. md5) as your key. of course this could > mean that you get a new value whenever the page is updated. That's good > in many situations, but you don't give enough information to know if > that's desirable for you or not. That sounds nice! A hash is a mathematical algorithm that produce a unique number after analyzing each file's contents? But then again what if the html templated gets updated? That update action will create a new hash for the file, hence another counter will be created for the same file, same end result as (1) solution. Pros: If filepath is altered, that won't affect the counter. Cons: If file's contents gets updated the, then duplicity will happen. > 3) Keep an external list of filenames, and their associated id numbers. > The database would be a good place to store such a list, in a separate table. I did not understand that solution. We need to find a way so even IF: (filepath gets modified && file content's gets modified) simultaneously the counter will STILL retains it's value. From nikos.gr33k at gmail.com Sat Jan 19 03:39:44 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 19 Jan 2013 00:39:44 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> Message-ID: <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> ?? ???????, 19 ?????????? 2013 12:09:28 ?.?. UTC+2, ? ??????? Dave Angel ??????: > I don't understand the problem. A trivial Python script could scan > > through all the files in the directory, checking which ones are missing > > the identifier, and rewriting the file with the identifier added. > > So, since you didn't come to that conclusion, there must be some other > > reason you don't want to edit the files. Is it that the real sources > > are elsewhere (e.g. Dreamweaver), and whenever one recompiles those > > sources, these files get replaced (without identifiers)? Exactly. Files get modified/updates thus the embedded identifier will be missing each time. So, relying on embedding code to html template content is not practical. > If that's the case, then I figure you have about 3 choices: > 1) use the file path as your key, instead of requiring a number No, i cannot, because it would mess things at a later time on when i for example: 1. mv name.html othername.html (document's filename altered) 2. mv name.html /subfolder/name.html (document's filepath altered) Hence, new database counters will be created for each of the above actions, therefore i will be having 2 counters for the same file, and the latter one will start from a zero value. Pros: If the file's contents gets updated, that won't affect the counter. Cons: If filepath is altered, then duplicity will happen. > 2) use a hash of the page (eg. md5) as your key. of course this could > mean that you get a new value whenever the page is updated. That's good > in many situations, but you don't give enough information to know if > that's desirable for you or not. That sounds nice! A hash is a mathematical algorithm that produce a unique number after analyzing each file's contents? But then again what if the html templated gets updated? That update action will create a new hash for the file, hence another counter will be created for the same file, same end result as (1) solution. Pros: If filepath is altered, that won't affect the counter. Cons: If file's contents gets updated the, then duplicity will happen. > 3) Keep an external list of filenames, and their associated id numbers. > The database would be a good place to store such a list, in a separate table. I did not understand that solution. We need to find a way so even IF: (filepath gets modified && file content's gets modified) simultaneously the counter will STILL retains it's value. From d at davea.name Sat Jan 19 04:00:15 2013 From: d at davea.name (Dave Angel) Date: Sat, 19 Jan 2013 04:00:15 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> Message-ID: <50FA609F.5030509@davea.name> On 01/19/2013 03:39 AM, Ferrous Cranus wrote: > ?? ???????, 19 ?????????? 2013 12:09:28 ?.?. UTC+2, ? ??????? Dave Angel ??????: > >> I don't understand the problem. A trivial Python script could scan >> >> through all the files in the directory, checking which ones are missing >> >> the identifier, and rewriting the file with the identifier added. > >> >> So, since you didn't come to that conclusion, there must be some other >> >> reason you don't want to edit the files. Is it that the real sources >> >> are elsewhere (e.g. Dreamweaver), and whenever one recompiles those >> >> sources, these files get replaced (without identifiers)? > > Exactly. Files get modified/updates thus the embedded identifier will be missing each time. So, relying on embedding code to html template content is not practical. > > >> If that's the case, then I figure you have about 3 choices: >> 1) use the file path as your key, instead of requiring a number > > No, i cannot, because it would mess things at a later time on when i for example: > > 1. mv name.html othername.html (document's filename altered) > 2. mv name.html /subfolder/name.html (document's filepath altered) > > Hence, new database counters will be created for each of the above actions, therefore i will be having 2 counters for the same file, and the latter one will start from a zero value. > > Pros: If the file's contents gets updated, that won't affect the counter. > Cons: If filepath is altered, then duplicity will happen. > > >> 2) use a hash of the page (eg. md5) as your key. of course this could >> mean that you get a new value whenever the page is updated. That's good >> in many situations, but you don't give enough information to know if >> that's desirable for you or not. > > That sounds nice! A hash is a mathematical algorithm that produce a unique number after analyzing each file's contents? But then again what if the html templated gets updated? That update action will create a new hash for the file, hence another counter will be created for the same file, same end result as (1) solution. > > Pros: If filepath is altered, that won't affect the counter. > Cons: If file's contents gets updated the, then duplicity will happen. > > >> 3) Keep an external list of filenames, and their associated id numbers. >> The database would be a good place to store such a list, in a separate table. > > I did not understand that solution. > > > We need to find a way so even IF: > > (filepath gets modified && file content's gets modified) simultaneously the counter will STILL retains it's value. > You don't yet have a programming problem, you have a specification problem. Somehow, you want a file to be considered "the same" even when it's moved, renamed and/or modified. So all files are the same, and you only need one id. Don't pick a mechanism until you have an self-consistent spec. -- DaveA From nikos.gr33k at gmail.com Mon Jan 21 01:52:26 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 20 Jan 2013 22:52:26 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> Message-ID: ?? ???????, 19 ?????????? 2013 11:32:41 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Sat, 19 Jan 2013 00:39:44 -0800 (PST), Ferrous Cranus > > declaimed the following in > > gmane.comp.python.general: > > > We need to find a way so even IF: > > > > > > (filepath gets modified && file content's gets modified) simultaneously the counter will STILL retains it's value. > > > > The only viable solution the /I/ can visualize is one in which any > > operation ON the template file MUST ALSO operate on the counter... That > > is; you only operate on the templates using a front-end application that > > automatically links the counter information every time... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ CANNOT BE DONE because every html templates has been written by different methods. dramweaver joomla notepad++ From nikos.gr33k at gmail.com Mon Jan 21 01:52:26 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 20 Jan 2013 22:52:26 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> Message-ID: ?? ???????, 19 ?????????? 2013 11:32:41 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Sat, 19 Jan 2013 00:39:44 -0800 (PST), Ferrous Cranus > > declaimed the following in > > gmane.comp.python.general: > > > We need to find a way so even IF: > > > > > > (filepath gets modified && file content's gets modified) simultaneously the counter will STILL retains it's value. > > > > The only viable solution the /I/ can visualize is one in which any > > operation ON the template file MUST ALSO operate on the counter... That > > is; you only operate on the templates using a front-end application that > > automatically links the counter information every time... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ CANNOT BE DONE because every html templates has been written by different methods. dramweaver joomla notepad++ From nikos.gr33k at gmail.com Mon Jan 21 02:08:00 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 20 Jan 2013 23:08:00 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> Message-ID: <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> ?? ???????, 19 ?????????? 2013 11:00:15 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/19/2013 03:39 AM, Ferrous Cranus wrote: > > > ?? ???????, 19 ?????????? 2013 12:09:28 ?.?. UTC+2, ? ??????? Dave Angel ??????: > > > > > >> I don't understand the problem. A trivial Python script could scan > > >> > > >> through all the files in the directory, checking which ones are missing > > >> > > >> the identifier, and rewriting the file with the identifier added. > > > > > >> > > >> So, since you didn't come to that conclusion, there must be some other > > >> > > >> reason you don't want to edit the files. Is it that the real sources > > >> > > >> are elsewhere (e.g. Dreamweaver), and whenever one recompiles those > > >> > > >> sources, these files get replaced (without identifiers)? > > > > > > Exactly. Files get modified/updates thus the embedded identifier will be missing each time. So, relying on embedding code to html template content is not practical. > > > > > > > > >> If that's the case, then I figure you have about 3 choices: > > >> 1) use the file path as your key, instead of requiring a number > > > > > > No, i cannot, because it would mess things at a later time on when i for example: > > > > > > 1. mv name.html othername.html (document's filename altered) > > > 2. mv name.html /subfolder/name.html (document's filepath altered) > > > > > > Hence, new database counters will be created for each of the above actions, therefore i will be having 2 counters for the same file, and the latter one will start from a zero value. > > > > > > Pros: If the file's contents gets updated, that won't affect the counter. > > > Cons: If filepath is altered, then duplicity will happen. > > > > > > > > >> 2) use a hash of the page (eg. md5) as your key. of course this could > > >> mean that you get a new value whenever the page is updated. That's good > > >> in many situations, but you don't give enough information to know if > > >> that's desirable for you or not. > > > > > > That sounds nice! A hash is a mathematical algorithm that produce a unique number after analyzing each file's contents? But then again what if the html templated gets updated? That update action will create a new hash for the file, hence another counter will be created for the same file, same end result as (1) solution. > > > > > > Pros: If filepath is altered, that won't affect the counter. > > > Cons: If file's contents gets updated the, then duplicity will happen. > > > > > > > > >> 3) Keep an external list of filenames, and their associated id numbers. > > >> The database would be a good place to store such a list, in a separate table. > > > > > > I did not understand that solution. > > > > > > > > > We need to find a way so even IF: > > > > > > (filepath gets modified && file content's gets modified) simultaneously the counter will STILL retains it's value. > > > > > > > You don't yet have a programming problem, you have a specification > > problem. Somehow, you want a file to be considered "the same" even when > > it's moved, renamed and/or modified. So all files are the same, and you > > only need one id. > > Don't pick a mechanism until you have an self-consistent spec. I do have the specification. An .html page must retain its database counter value even if its: (renamed && moved && contents altered) [original attributes of the file]: filename: index.html filepath: /home/nikos/public_html/ contents: Hello [get modified to]: filename: index2.html filepath: /home/nikos/public_html/folder/subfolder/ contents: Hello, people The file is still the same, even though its attributes got modified. We want counter.py script to still be able to "identify" the .html page, hence its counter value in order to get increased properly. From nikos.gr33k at gmail.com Mon Jan 21 02:08:00 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 20 Jan 2013 23:08:00 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> Message-ID: <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> ?? ???????, 19 ?????????? 2013 11:00:15 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/19/2013 03:39 AM, Ferrous Cranus wrote: > > > ?? ???????, 19 ?????????? 2013 12:09:28 ?.?. UTC+2, ? ??????? Dave Angel ??????: > > > > > >> I don't understand the problem. A trivial Python script could scan > > >> > > >> through all the files in the directory, checking which ones are missing > > >> > > >> the identifier, and rewriting the file with the identifier added. > > > > > >> > > >> So, since you didn't come to that conclusion, there must be some other > > >> > > >> reason you don't want to edit the files. Is it that the real sources > > >> > > >> are elsewhere (e.g. Dreamweaver), and whenever one recompiles those > > >> > > >> sources, these files get replaced (without identifiers)? > > > > > > Exactly. Files get modified/updates thus the embedded identifier will be missing each time. So, relying on embedding code to html template content is not practical. > > > > > > > > >> If that's the case, then I figure you have about 3 choices: > > >> 1) use the file path as your key, instead of requiring a number > > > > > > No, i cannot, because it would mess things at a later time on when i for example: > > > > > > 1. mv name.html othername.html (document's filename altered) > > > 2. mv name.html /subfolder/name.html (document's filepath altered) > > > > > > Hence, new database counters will be created for each of the above actions, therefore i will be having 2 counters for the same file, and the latter one will start from a zero value. > > > > > > Pros: If the file's contents gets updated, that won't affect the counter. > > > Cons: If filepath is altered, then duplicity will happen. > > > > > > > > >> 2) use a hash of the page (eg. md5) as your key. of course this could > > >> mean that you get a new value whenever the page is updated. That's good > > >> in many situations, but you don't give enough information to know if > > >> that's desirable for you or not. > > > > > > That sounds nice! A hash is a mathematical algorithm that produce a unique number after analyzing each file's contents? But then again what if the html templated gets updated? That update action will create a new hash for the file, hence another counter will be created for the same file, same end result as (1) solution. > > > > > > Pros: If filepath is altered, that won't affect the counter. > > > Cons: If file's contents gets updated the, then duplicity will happen. > > > > > > > > >> 3) Keep an external list of filenames, and their associated id numbers. > > >> The database would be a good place to store such a list, in a separate table. > > > > > > I did not understand that solution. > > > > > > > > > We need to find a way so even IF: > > > > > > (filepath gets modified && file content's gets modified) simultaneously the counter will STILL retains it's value. > > > > > > > You don't yet have a programming problem, you have a specification > > problem. Somehow, you want a file to be considered "the same" even when > > it's moved, renamed and/or modified. So all files are the same, and you > > only need one id. > > Don't pick a mechanism until you have an self-consistent spec. I do have the specification. An .html page must retain its database counter value even if its: (renamed && moved && contents altered) [original attributes of the file]: filename: index.html filepath: /home/nikos/public_html/ contents: Hello [get modified to]: filename: index2.html filepath: /home/nikos/public_html/folder/subfolder/ contents: Hello, people The file is still the same, even though its attributes got modified. We want counter.py script to still be able to "identify" the .html page, hence its counter value in order to get increased properly. From rosuav at gmail.com Mon Jan 21 02:20:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Jan 2013 18:20:15 +1100 Subject: Uniquely identifying each & every html template In-Reply-To: <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: On Mon, Jan 21, 2013 at 6:08 PM, Ferrous Cranus wrote: > An .html page must retain its database counter value even if its: > > (renamed && moved && contents altered) Then you either need to tag them in some external way, or have some kind of tracking operation - for instance, if you require that all renames/moves be done through a script, that script can update its pointer. Otherwise, you need magic, and lots of it. ChrisA From nikos.gr33k at gmail.com Mon Jan 21 04:19:07 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 01:19:07 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> ?? ???????, 21 ?????????? 2013 9:20:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Mon, Jan 21, 2013 at 6:08 PM, Ferrous Cranus wrote: > > > An .html page must retain its database counter value even if its: > > > > > > (renamed && moved && contents altered) > > > > Then you either need to tag them in some external way, or have some > > kind of tracking operation - for instance, if you require that all > > renames/moves be done through a script, that script can update its > > pointer. Otherwise, you need magic, and lots of it. > > > > ChrisA This python script acts upon websites other people use and every html templates has been written by different methods(notepad++, dreamweaver, joomla). Renames and moves are performed, either by shell access or either by cPanel access by website owners. That being said i have no control on HOW and WHEN users alter their html pages. From rosuav at gmail.com Mon Jan 21 04:31:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Jan 2013 20:31:24 +1100 Subject: Uniquely identifying each & every html template In-Reply-To: <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> Message-ID: On Mon, Jan 21, 2013 at 8:19 PM, Ferrous Cranus wrote: > This python script acts upon websites other people use and > every html templates has been written by different methods(notepad++, dreamweaver, joomla). > > Renames and moves are performed, either by shell access or either by cPanel access by website owners. > > That being said i have no control on HOW and WHEN users alter their html pages. Then I recommend investing in some magic. There's an old-established business JW Wells & Co, Family Sorcerers. They've a first-rate assortment of magic, and for raising a posthumous shade with effects that are comic, or tragic, there's no cheaper house in the trade! If anyone anything lacks, he'll find it all ready in stacks, if he'll only look in on the resident Djinn, number seventy, Simmery Axe! Seriously, you're asking for something that's beyond the power of humans or computers. You want to identify that something's the same file, without tracking the change or having any identifiable tag. That's a fundamentally impossible task. ChrisA From nikos.gr33k at gmail.com Mon Jan 21 04:19:07 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 01:19:07 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> ?? ???????, 21 ?????????? 2013 9:20:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Mon, Jan 21, 2013 at 6:08 PM, Ferrous Cranus wrote: > > > An .html page must retain its database counter value even if its: > > > > > > (renamed && moved && contents altered) > > > > Then you either need to tag them in some external way, or have some > > kind of tracking operation - for instance, if you require that all > > renames/moves be done through a script, that script can update its > > pointer. Otherwise, you need magic, and lots of it. > > > > ChrisA This python script acts upon websites other people use and every html templates has been written by different methods(notepad++, dreamweaver, joomla). Renames and moves are performed, either by shell access or either by cPanel access by website owners. That being said i have no control on HOW and WHEN users alter their html pages. From nikos.gr33k at gmail.com Mon Jan 21 07:06:23 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 04:06:23 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> Message-ID: <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> ?? ???????, 21 ?????????? 2013 11:31:24 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Mon, Jan 21, 2013 at 8:19 PM, Ferrous Cranus wrote: > > > This python script acts upon websites other people use and > > > every html templates has been written by different methods(notepad++, dreamweaver, joomla). > > > > > > Renames and moves are performed, either by shell access or either by cPanel access by website owners. > > > > > > That being said i have no control on HOW and WHEN users alter their html pages. > > > > Then I recommend investing in some magic. There's an old-established > > business JW Wells & Co, Family Sorcerers. They've a first-rate > > assortment of magic, and for raising a posthumous shade with effects > > that are comic, or tragic, there's no cheaper house in the trade! If > > anyone anything lacks, he'll find it all ready in stacks, if he'll > > only look in on the resident Djinn, number seventy, Simmery Axe! > > > > Seriously, you're asking for something that's beyond the power of > > humans or computers. You want to identify that something's the same > > file, without tracking the change or having any identifiable tag. > > That's a fundamentally impossible task. No, it is difficult but not impossible. It just cannot be done by tagging the file by: 1. filename 2. filepath 3. hash (math algorithm producing a string based on the file's contents) We need another way to identify the file WITHOUT using the above attributes. From nikos.gr33k at gmail.com Mon Jan 21 07:06:23 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 04:06:23 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> Message-ID: <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> ?? ???????, 21 ?????????? 2013 11:31:24 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Mon, Jan 21, 2013 at 8:19 PM, Ferrous Cranus wrote: > > > This python script acts upon websites other people use and > > > every html templates has been written by different methods(notepad++, dreamweaver, joomla). > > > > > > Renames and moves are performed, either by shell access or either by cPanel access by website owners. > > > > > > That being said i have no control on HOW and WHEN users alter their html pages. > > > > Then I recommend investing in some magic. There's an old-established > > business JW Wells & Co, Family Sorcerers. They've a first-rate > > assortment of magic, and for raising a posthumous shade with effects > > that are comic, or tragic, there's no cheaper house in the trade! If > > anyone anything lacks, he'll find it all ready in stacks, if he'll > > only look in on the resident Djinn, number seventy, Simmery Axe! > > > > Seriously, you're asking for something that's beyond the power of > > humans or computers. You want to identify that something's the same > > file, without tracking the change or having any identifiable tag. > > That's a fundamentally impossible task. No, it is difficult but not impossible. It just cannot be done by tagging the file by: 1. filename 2. filepath 3. hash (math algorithm producing a string based on the file's contents) We need another way to identify the file WITHOUT using the above attributes. From oscar.j.benjamin at gmail.com Mon Jan 21 07:39:18 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 21 Jan 2013 12:39:18 +0000 Subject: Uniquely identifying each & every html template In-Reply-To: <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: On 21 January 2013 12:06, Ferrous Cranus wrote: > ?? ???????, 21 ?????????? 2013 11:31:24 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> >> Seriously, you're asking for something that's beyond the power of >> humans or computers. You want to identify that something's the same >> file, without tracking the change or having any identifiable tag. >> >> That's a fundamentally impossible task. > > No, it is difficult but not impossible. > It just cannot be done by tagging the file by: > > 1. filename > 2. filepath > 3. hash (math algorithm producing a string based on the file's contents) > > We need another way to identify the file WITHOUT using the above attributes. This is a very old problem (still unsolved I believe): http://en.wikipedia.org/wiki/Ship_of_Theseus Oscar From joel.goldstick at gmail.com Mon Jan 21 07:47:54 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 21 Jan 2013 07:47:54 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: This is trolling Ferrous. you are a troll. Go away On Mon, Jan 21, 2013 at 7:39 AM, Oscar Benjamin wrote: > On 21 January 2013 12:06, Ferrous Cranus wrote: > > ?? ???????, 21 ?????????? 2013 11:31:24 ?.?. UTC+2, ? ??????? Chris > Angelico ??????: > >> > >> Seriously, you're asking for something that's beyond the power of > >> humans or computers. You want to identify that something's the same > >> file, without tracking the change or having any identifiable tag. > >> > >> That's a fundamentally impossible task. > > > > No, it is difficult but not impossible. > > It just cannot be done by tagging the file by: > > > > 1. filename > > 2. filepath > > 3. hash (math algorithm producing a string based on the file's contents) > > > > We need another way to identify the file WITHOUT using the above > attributes. > > This is a very old problem (still unsolved I believe): > http://en.wikipedia.org/wiki/Ship_of_Theseus > > > Oscar > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Mon Jan 21 10:00:56 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 07:00:56 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: ?? ???????, 21 ?????????? 2013 2:47:54 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > This is trolling Ferrous.? you are a troll.? Go away Just because you cannot answer my question that doesn't make me a troll you know. From torriem at gmail.com Tue Jan 22 18:55:07 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 16:55:07 -0700 Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: <50FF26DB.10106@gmail.com> On 01/21/2013 08:00 AM, Ferrous Cranus wrote: > ?? ???????, 21 ?????????? 2013 2:47:54 ?.?. UTC+2, ? ??????? Joel > Goldstick ??????: >> This is trolling Ferrous. you are a troll. Go away > > Just because you cannot answer my question that doesn't make me a > troll you know. It becomes trolling when you refuse to even try to understand the answers you are given. And you refuse to take the advise of many knowledgeable people who have a lot more experience in web application development than you do (I'm not including myself in this category). You refuse to use a database in a way that it was designed to be used. If you're unwilling to identify a file based on name, path, and contents, then you're only solution is to use a database to associate a particular file with an id. When you move or rename the file you have to update the database. That's the only answer we can give you. Asking the same question over and over again on different threads is not going to change this. This is the third thread you've started on essentially the same question. And you're getting the same advice on each thread. There's a reason for this! It's apparent that you don't have a lot of background in computer programming or algorithms. That's okay. No one will fault you for this. But if you're going to reject the solutions posed by those with such background, then it behooves you to gain a bit of knowledge in these areas and learn why these suggestions are going made. I in no way intend anything I have said to be condescending. It's just that those who are honestly trying to help you are getting frustrated. And possibly you will interpret this frustration as hostility or elitism, which it really is not. From nikos.gr33k at gmail.com Wed Jan 23 04:12:31 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 01:12:31 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> ?? ???????, 23 ?????????? 2013 1:55:07 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > You refuse to use a database in a way that it was designed to be used. > > If you're unwilling to identify a file based on name, path, and > > contents, then you're only solution is to use a database to associate a > > particular file with an id. When you move or rename the file you have > > to update the database. That's the only answer we can give you. table counters: pin ---- page ----- hosts table visitors: pin ---- host ---- hits ---- useros ---- browser ---- date 1. Who is going to create the 'pin' ? the database automatically when i'am inserting a new record from python? 2. How's the 'pin' going to be associated with 'page' ? 3. if 'page' renames/moves then i have to manually edit the counter database table to find the specific 'page' record and upadate it by hand? > I in no way intend anything I have said to be condescending. It's just > > that those who are honestly trying to help you are getting frustrated. > > And possibly you will interpret this frustration as hostility or > > elitism, which it really is not. They are getting frustrated because they do not want to follow the logic i'am imposing. From nikos.gr33k at gmail.com Wed Jan 23 04:12:31 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 01:12:31 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> ?? ???????, 23 ?????????? 2013 1:55:07 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > You refuse to use a database in a way that it was designed to be used. > > If you're unwilling to identify a file based on name, path, and > > contents, then you're only solution is to use a database to associate a > > particular file with an id. When you move or rename the file you have > > to update the database. That's the only answer we can give you. table counters: pin ---- page ----- hosts table visitors: pin ---- host ---- hits ---- useros ---- browser ---- date 1. Who is going to create the 'pin' ? the database automatically when i'am inserting a new record from python? 2. How's the 'pin' going to be associated with 'page' ? 3. if 'page' renames/moves then i have to manually edit the counter database table to find the specific 'page' record and upadate it by hand? > I in no way intend anything I have said to be condescending. It's just > > that those who are honestly trying to help you are getting frustrated. > > And possibly you will interpret this frustration as hostility or > > elitism, which it really is not. They are getting frustrated because they do not want to follow the logic i'am imposing. From wuwei23 at gmail.com Wed Jan 23 04:37:29 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 23 Jan 2013 01:37:29 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> Message-ID: <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> On Jan 23, 7:12?pm, Ferrous Cranus wrote: > They are getting frustrated because they do not want to follow the logic i'am imposing. No, it's because you're an obvious troll and you're wasting everyone's time. Now be a good lad and sod off. From breamoreboy at yahoo.co.uk Wed Jan 23 04:49:09 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 23 Jan 2013 09:49:09 +0000 Subject: Uniquely identifying each & every html template In-Reply-To: <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> Message-ID: On 23/01/2013 09:37, alex23 wrote: > On Jan 23, 7:12 pm, Ferrous Cranus wrote: >> They are getting frustrated because they do not want to follow the logic i'am imposing. > > No, it's because you're an obvious troll and you're wasting everyone's > time. > > Now be a good lad and sod off. > What an appalling lack of manners, it's sod off please :) -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Wed Jan 23 05:29:44 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 02:29:44 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> Message-ID: <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> ?? ???????, 23 ?????????? 2013 11:37:29 ?.?. UTC+2, ? ??????? alex23 ??????: > On Jan 23, 7:12?pm, Ferrous Cranus wrote: > > > They are getting frustrated because they do not want to follow the logic i'am imposing. > > > > No, it's because you're an obvious troll and you're wasting everyone's > > time. > > > > Now be a good lad and sod off. 1. I'am a troll because i want to generate a solution in a specific way? 2. Am' i not wasting my time trying to reply to everybody? From joel.goldstick at gmail.com Wed Jan 23 07:03:51 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 23 Jan 2013 07:03:51 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 5:29 AM, Ferrous Cranus wrote: > ?? ???????, 23 ?????????? 2013 11:37:29 ?.?. UTC+2, ? ??????? alex23 > ??????: > > On Jan 23, 7:12 pm, Ferrous Cranus wrote: > > > > > They are getting frustrated because they do not want to follow the > logic i'am imposing. > > > > > > > > No, it's because you're an obvious troll and you're wasting everyone's > > > > time. > > > > > > > > Now be a good lad and sod off. > > 1. I'am a troll because i want to generate a solution in a specific way? > 2. Am' i not wasting my time trying to reply to everybody? > This is so weird. Your time is not wasted, because your time is not valuable. You aren't even a person. You are a fiction. If you were real, someone would beat you to death, and you would stop annoying people. I don't understand the troll thing. Its really anti social. I like the web, but this is so strange > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Wed Jan 23 07:26:47 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 04:26:47 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> Message-ID: ?? ???????, 23 ?????????? 2013 2:03:51 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Wed, Jan 23, 2013 at 5:29 AM, Ferrous Cranus wrote: > > ?? ???????, 23 ?????????? 2013 11:37:29 ?.?. UTC+2, ? ??????? alex23 ??????: > > > > On Jan 23, 7:12?pm, Ferrous Cranus wrote: > > > > > > > They are getting frustrated because they do not want to follow the logic i'am imposing. > > > > > > > > > > > > No, it's because you're an obvious troll and you're wasting everyone's > > > > > > time. > > > > > > > > > > > > Now be a good lad and sod off. > > > > 1. I'am a troll because i want to generate a solution in a specific way? > > 2. Am' i not wasting my time trying to reply to everybody? > > > > This is so weird. ? Your time is not wasted, because your time is not valuable.? You aren't even a person.? You are a fiction.? If you were real, someone would beat you to death, and you would stop annoying people. ? I don't understand the troll thing.? Its really anti social. > > > > I like the web, but this is so strange > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > > > Joel Goldstick > http://joelgoldstick.com Who told you that my time is NOT valuable and yours is? And yes iam an actual person. From nikos.gr33k at gmail.com Wed Jan 23 07:26:47 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 04:26:47 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> Message-ID: ?? ???????, 23 ?????????? 2013 2:03:51 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Wed, Jan 23, 2013 at 5:29 AM, Ferrous Cranus wrote: > > ?? ???????, 23 ?????????? 2013 11:37:29 ?.?. UTC+2, ? ??????? alex23 ??????: > > > > On Jan 23, 7:12?pm, Ferrous Cranus wrote: > > > > > > > They are getting frustrated because they do not want to follow the logic i'am imposing. > > > > > > > > > > > > No, it's because you're an obvious troll and you're wasting everyone's > > > > > > time. > > > > > > > > > > > > Now be a good lad and sod off. > > > > 1. I'am a troll because i want to generate a solution in a specific way? > > 2. Am' i not wasting my time trying to reply to everybody? > > > > This is so weird. ? Your time is not wasted, because your time is not valuable.? You aren't even a person.? You are a fiction.? If you were real, someone would beat you to death, and you would stop annoying people. ? I don't understand the troll thing.? Its really anti social. > > > > I like the web, but this is so strange > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > > > Joel Goldstick > http://joelgoldstick.com Who told you that my time is NOT valuable and yours is? And yes iam an actual person. From d at davea.name Wed Jan 23 07:38:16 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 07:38:16 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> Message-ID: <50FFD9B8.3090304@davea.name> On 01/23/2013 05:29 AM, Ferrous Cranus wrote: >> >> > > 1. I'am a troll because i want to generate a solution in a specific way? > 2. Am' i not wasting my time trying to reply to everybody? > 1) your username is obviously a pseudonym, and identified by multiple websites as a troll. Further, your actions conform to the description on at least one of those websites. 2) Your replies are mostly of the forms: a) but I want a car that gets 300 miles to the gallon b) I know you explained that, but would you write all the code for me c) I haven't read any of the literature on computer science, so please build me a perpetual motion machine. Never mind there's a better way to solve my problem, I don't want to hear it d) I'll ignore any message that I don't understand 3) The time that the OP spends ostensibly trying to get help is time he's spending for his own benefit. The time that all the experienced people on here are spending has been mostly to try to help the OP. That's a big difference. Your last code sample was in perl, and while I can read it (and have worked in it when it was absolutely necessary) I choose not to. But just fixing a hash so it doesn't confuse abc with cba will NOT take away the very real probability of collisions. Those calculations I did for you were for the ideal hash. Most are much worse than that. And increasing the range of pin from 10000 to 100000 will reduce the chances of collision, but not by nearly enough. It still only takes about 150 average samples to get a collision likelihood of over 10% You think it's an accident that md5 size is roughly equivalent to 39 decimal digits? Or that the ones that haven't been proven insecure are much larger than that? The sha512 hash is roughly equivalent to 154 decimal digits. -- DaveA From rosuav at gmail.com Wed Jan 23 18:25:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 10:25:58 +1100 Subject: Uniquely identifying each & every html template In-Reply-To: <50FFD9B8.3090304@davea.name> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> <50FFD9B8.3090304@davea.name> Message-ID: On Wed, Jan 23, 2013 at 11:38 PM, Dave Angel wrote: > You think it's an accident that md5 size is roughly equivalent to 39 decimal > digits? Or that the ones that haven't been proven insecure are much larger > than that? The sha512 hash is roughly equivalent to 154 decimal digits. Proving a hash function secure or not is orthogonal to its length. You could have a cryptographically secure hash function that produces a single byte; you'd get collisions pretty often, but that's understood. Conversely, you could have an insecure hash that produces a value several orders of magnitude longer than SHA512. Look at this: def big_long_hash(val): return sum(bytes(str(val),"utf-8"))*12345678901234567890 But longer hashes do reduce the chance of collisions, by the fundamental rules of mathematics. ChrisA From d at davea.name Wed Jan 23 19:09:52 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 19:09:52 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> <50FFD9B8.3090304@davea.name> Message-ID: <51007BD0.1030105@davea.name> On 01/23/2013 06:25 PM, Chris Angelico wrote: > On Wed, Jan 23, 2013 at 11:38 PM, Dave Angel wrote: >> You think it's an accident that md5 size is roughly equivalent to 39 decimal >> digits? Or that the ones that haven't been proven insecure are much larger >> than that? The sha512 hash is roughly equivalent to 154 decimal digits. > > Proving a hash function secure or not is orthogonal to its length. You > could have a cryptographically secure hash function that produces a > single byte; you'd get collisions pretty often, but that's understood. > Conversely, you could have an insecure hash that produces a value > several orders of magnitude longer than SHA512. Look at this: > > def big_long_hash(val): > return sum(bytes(str(val),"utf-8"))*12345678901234567890 > > But longer hashes do reduce the chance of collisions, by the > fundamental rules of mathematics. > I certainly can't disagree that it's easy to produce a very long hash that isn't at all secure. But I would disagree that longer hashes *automatically* reduce chances of collision. Anyway, about cryptographically ... OK, I'd like to learn here. I thought that "cryptographically secure" meant that it was infeasible to take a given message and make an innocuous change to it (such as adding a trailer of whatever size) and from that produce a predetermined hash value. Obviously "infeasible" will change over time. But if my definition is even close, then wouldn't it be a necessary (not sufficient) condition that the hash be at least some certain size. It is that size I was trying to impress on the OP. Wikipedia - http://en.wikipedia.org/wiki/Cryptographic_hash_function seems to say that there are four requirements. it is easy to compute the hash value for any given message it is infeasible to generate a message that has a given hash it is infeasible to modify a message without changing the hash it is infeasible to find two different messages with the same hash Seems to me a small hash wouldn't be able to meet the last 3 conditions. -- DaveA From rosuav at gmail.com Wed Jan 23 19:39:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 11:39:16 +1100 Subject: Uniquely identifying each & every html template In-Reply-To: <51007BD0.1030105@davea.name> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> <50FFD9B8.3090304@davea.name> <51007BD0.1030105@davea.name> Message-ID: On Thu, Jan 24, 2013 at 11:09 AM, Dave Angel wrote: > I certainly can't disagree that it's easy to produce a very long hash that > isn't at all secure. But I would disagree that longer hashes > *automatically* reduce chances of collision. Sure. But by and large, longer hashes give you a better chance at avoiding collisions. Caveat: I am not a cryptography expert. My statements are based on my own flawed understanding of what's going on. I use the stuff but I don't invent it. > Wikipedia - http://en.wikipedia.org/wiki/Cryptographic_hash_function > > seems to say that there are four requirements. > it is easy to compute the hash value for any given message > it is infeasible to generate a message that has a given hash > it is infeasible to modify a message without changing the hash > it is infeasible to find two different messages with the same hash > > Seems to me a small hash wouldn't be able to meet the last 3 conditions. True, but the definition of "small" is tricky. Of course the one-byte hash I proposed isn't going to be difficult to break, since you can just brute-force a bunch of message changes until you find one that has the right hash. But it's more about the cascade effect - that any given message has equal probability of having any of the possible hashes. Make a random change, get another random hash. So for a perfect one-byte hash, you have exactly one chance in 256 of getting any particular hash. By comparison, a simple/naive hash that just XORs together all the byte values fails these checks. Even if you take the message 64 bytes at a time (thus producing a 512-bit hash), you'll still be insecure, because it's easy to predict what hash you'll get after making a particular change. This property of the hash doesn't change as worldwide computing power improves. A hashing function might go from being "military-grade security" to being "home-grade security" to being "two-foot fence around your property", while still being impossible to predict without brute-forcing. But when an algorithm is found that generates collisions faster than the hash size indicates, it effectively reduces the hash size to the collision rate - MD5 is 128-bit, but (if I understand the Wikipedia note correctly) a known attack cuts that to 20.96 bits of "real hash size". So MD5 is still better than a perfect 16-bit hash, but not as good as a perfect 32-bit hash. (And on today's hardware, that's not good enough.) http://en.wikipedia.org/wiki/Collision_resistant ChrisA From d at davea.name Wed Jan 23 19:53:28 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 19:53:28 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> <50FFD9B8.3090304@davea.name> <51007BD0.1030105@davea.name> Message-ID: <51008608.2090209@davea.name> On 01/23/2013 07:39 PM, Chris Angelico wrote: > On Thu, Jan 24, 2013 at 11:09 AM, Dave Angel wrote: >> I certainly can't disagree that it's easy to produce a very long hash that >> isn't at all secure. But I would disagree that longer hashes >> *automatically* reduce chances of collision. > > Sure. But by and large, longer hashes give you a better chance at > avoiding collisions. > > Caveat: I am not a cryptography expert. My statements are based on my > own flawed understanding of what's going on. I use the stuff but I > don't invent it. > >> Wikipedia - http://en.wikipedia.org/wiki/Cryptographic_hash_function >> >> seems to say that there are four requirements. >> it is easy to compute the hash value for any given message >> it is infeasible to generate a message that has a given hash >> it is infeasible to modify a message without changing the hash >> it is infeasible to find two different messages with the same hash >> >> Seems to me a small hash wouldn't be able to meet the last 3 conditions. > > True, but the definition of "small" is tricky. Of course the one-byte > hash I proposed isn't going to be difficult to break, since you can > just brute-force a bunch of message changes until you find one that > has the right hash. > > But it's more about the cascade effect - that any given message has > equal probability of having any of the possible hashes. Make a random > change, get another random hash. So for a perfect one-byte hash, you > have exactly one chance in 256 of getting any particular hash. > > By comparison, a simple/naive hash that just XORs together all the > byte values fails these checks. Even if you take the message 64 bytes > at a time (thus producing a 512-bit hash), you'll still be insecure, > because it's easy to predict what hash you'll get after making a > particular change. > > This property of the hash doesn't change as worldwide computing power > improves. A hashing function might go from being "military-grade > security" to being "home-grade security" to being "two-foot fence > around your property", while still being impossible to predict without > brute-forcing. But when an algorithm is found that generates > collisions faster than the hash size indicates, it effectively reduces > the hash size to the collision rate - MD5 is 128-bit, but (if I > understand the Wikipedia note correctly) a known attack cuts that to > 20.96 bits of "real hash size". So MD5 is still better than a perfect > 16-bit hash, but not as good as a perfect 32-bit hash. (And on today's > hardware, that's not good enough.) > > http://en.wikipedia.org/wiki/Collision_resistant > > ChrisA > Thanks. I've read a lot about encryption and data compression (two overlapping fields), and done some amateurish work (first time was 1975) that was just to keep something secret, not to be especially secure. I find the field fascinating, but have never needed to do anything particularly secure for a real product. -- DaveA From wuwei23 at gmail.com Wed Jan 23 09:25:17 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 23 Jan 2013 06:25:17 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <2391171e-e170-4647-8924-8e446ea1c6b1@googlegroups.com> <9d9b287c-ca2a-49c1-a16b-e42cb2a5db38@q16g2000pbt.googlegroups.com> <6f3e7d20-3005-4d1e-b949-d90a78e7bbf6@googlegroups.com> Message-ID: <8d4233c4-fcd4-4ebf-829e-babc78397f2d@i7g2000pbf.googlegroups.com> On Jan 23, 8:29?pm, Ferrous Cranus wrote: > 1. I'am a troll because i want to generate a solution in a specific way? No, it's because you have the name & behaviour of a known type of troll: As has been pointed out: http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm "Ferrous Cranus is utterly impervious to reason, persuasion and new ideas, and when engaged in battle he will not yield an inch in his position regardless of its hopelessness. Though his thrusts are decisively repulsed, his arguments crushed in every detail and his defenses demolished beyond repair he will remount the same attack again and again with only the slightest variation in tactics." Sound familiar? From wuwei23 at gmail.com Mon Jan 21 07:55:03 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 21 Jan 2013 04:55:03 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: On Jan 21, 10:39?pm, Oscar Benjamin wrote: > This is a very old problem (still unsolved I believe):http://en.wikipedia.org/wiki/Ship_of_Theseus +1 internets for referencing my most favourite thought experiment ever :) From rustompmody at gmail.com Mon Jan 21 22:24:18 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 21 Jan 2013 19:24:18 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: <34a47f4b-af49-49df-b0f2-f275c4b99f36@ui9g2000pbc.googlegroups.com> On Jan 21, 5:55?pm, alex23 wrote: > On Jan 21, 10:39?pm, Oscar Benjamin > wrote: > > > This is a very old problem (still unsolved I believe):http://en.wikipedia.org/wiki/Ship_of_Theseus > > +1 internets for referencing my most favourite thought experiment > ever :) +2 Oscar for giving me this name. A more apposite (to computers) experience: Ive a computer whose OS I wanted to upgrade without disturbing the existing setup. Decided to fit a new hard disk with a new OS. Installed the OS on a new hard disk, fitted the new hard disk into the old computer and rebooted. The messages that started coming were: New Hardware detected: monitor, mouse, network card etc etc. but not new disk! Strange! The only one thing new is not seen as new but all the old things are seen as new. So? Ask a layman whats a computer and he'll point to the box and call it 'CPU'. Ask a more computer literate person and he'll point to the chip inside the box and say 'CPU' Ask the computer itself and it says 'Disk'. Moral: Object identity is at best hard -- usually unsolvable From rosuav at gmail.com Mon Jan 21 23:39:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Jan 2013 15:39:45 +1100 Subject: Uniquely identifying each & every html template In-Reply-To: <34a47f4b-af49-49df-b0f2-f275c4b99f36@ui9g2000pbc.googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> <34a47f4b-af49-49df-b0f2-f275c4b99f36@ui9g2000pbc.googlegroups.com> Message-ID: On Tue, Jan 22, 2013 at 2:24 PM, rusi wrote: > Ive a computer whose OS I wanted to upgrade without disturbing the > existing setup. Decided to fit a new hard disk with a new OS. > Installed the OS on a new hard disk, fitted the new hard disk into the > old computer and rebooted. > > The messages that started coming were: New Hardware detected: monitor, > mouse, network card etc etc. but not new disk! > > Strange! The only one thing new is not seen as new but all the old > things are seen as new. That's because you asked the OS to look at the computer, and the OS was on the disk. So in that sense, you did give it a whole lot of new hardware but not a new disk. However, Windows Product Activation would probably have called that a new computer, meaning that Microsoft deems it to be new. (I've no idea about other non-free systems. Free systems don't care about new computer vs same computer, of course.) ChrisA From werotizy at freent.dd Mon Jan 21 18:01:39 2013 From: werotizy at freent.dd (Tom P) Date: Tue, 22 Jan 2013 00:01:39 +0100 Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: On 01/21/2013 01:39 PM, Oscar Benjamin wrote: > On 21 January 2013 12:06, Ferrous Cranus wrote: >> ?? ???????, 21 ?????????? 2013 11:31:24 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >>> >>> Seriously, you're asking for something that's beyond the power of >>> humans or computers. You want to identify that something's the same >>> file, without tracking the change or having any identifiable tag. >>> >>> That's a fundamentally impossible task. >> >> No, it is difficult but not impossible. >> It just cannot be done by tagging the file by: >> >> 1. filename >> 2. filepath >> 3. hash (math algorithm producing a string based on the file's contents) >> >> We need another way to identify the file WITHOUT using the above attributes. > > This is a very old problem (still unsolved I believe): > http://en.wikipedia.org/wiki/Ship_of_Theseus > > > Oscar > That wiki article gives a hint to a poosible solution -use a timestamp to determine which key is valid when. From oscar.j.benjamin at gmail.com Mon Jan 21 18:43:20 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 21 Jan 2013 23:43:20 +0000 Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: On 21 January 2013 23:01, Tom P wrote: > On 01/21/2013 01:39 PM, Oscar Benjamin wrote: >> >> On 21 January 2013 12:06, Ferrous Cranus wrote: >>> >>> ?? ???????, 21 ?????????? 2013 11:31:24 ?.?. UTC+2, ? ??????? Chris >>> Angelico ??????: >>>> >>>> >>>> Seriously, you're asking for something that's beyond the power of >>>> humans or computers. You want to identify that something's the same >>>> file, without tracking the change or having any identifiable tag. >>>> >>>> That's a fundamentally impossible task. >>> >>> >>> No, it is difficult but not impossible. >>> It just cannot be done by tagging the file by: >>> >>> 1. filename >>> 2. filepath >>> 3. hash (math algorithm producing a string based on the file's contents) >>> >>> We need another way to identify the file WITHOUT using the above >>> attributes. >> >> >> This is a very old problem (still unsolved I believe): >> http://en.wikipedia.org/wiki/Ship_of_Theseus >> > That wiki article gives a hint to a poosible solution -use a timestamp to > determine which key is valid when. In the Ship of Theseus, it is only argued that it is the same ship because people were aware of the incremental changes that took place along the way. The same applies here: if you don't track the incremental changes and the two files have nothing concrete in common, what does it mean to say that a file is "the same file" as some older file? That being said, I've always been impressed with the way that git can understand when I think that a file is the same as some older file (though it does sometimes go wrong): ~/tmp$ git init Initialized empty Git repository in /home/oscar/tmp/.git/ ~/tmp$ vim old.py ~/tmp$ cat old.py #!/usr/bin/env python print('This is a fairly useless script.') print("Maybe I'll improve it later...") ~/tmp$ git add old.py ~/tmp$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached ..." to unstage) # # new file: old.py # ~/tmp$ git commit [master (root-commit) 8e91665] First commit 1 file changed, 4 insertions(+) create mode 100644 old.py ~/tmp$ ls old.py ~/tmp$ cat old.py > new.py ~/tmp$ rm old.py ~/tmp$ vim new.py ~/tmp$ cat new.py #!/usr/bin/env python print('This is a fairly useless script.') print("Maybe I'll improve it later...") print("Although, I've edited it somewhat, it's still useless") ~/tmp$ git status # On branch master # Changes not staged for commit: # (use "git add/rm ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # deleted: old.py # # Untracked files: # (use "git add ..." to include in what will be committed) # # new.py no changes added to commit (use "git add" and/or "git commit -a") ~/tmp$ git add -A . ~/tmp$ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # renamed: old.py -> new.py # So it *is* Theseus' ship! Oscar From rosuav at gmail.com Mon Jan 21 19:04:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Jan 2013 11:04:37 +1100 Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: On Tue, Jan 22, 2013 at 10:43 AM, Oscar Benjamin wrote: > On 21 January 2013 23:01, Tom P wrote: >> On 01/21/2013 01:39 PM, Oscar Benjamin wrote: >>> This is a very old problem (still unsolved I believe): >>> http://en.wikipedia.org/wiki/Ship_of_Theseus >>> >> That wiki article gives a hint to a poosible solution -use a timestamp to >> determine which key is valid when. > > In the Ship of Theseus, it is only argued that it is the same ship > because people were aware of the incremental changes that took place > along the way. The same applies here: if you don't track the > incremental changes and the two files have nothing concrete in common, > what does it mean to say that a file is "the same file" as some older > file? > > That being said, I've always been impressed with the way that git can > understand when I think that a file is the same as some older file > (though it does sometimes go wrong): Yeah, git's awesome like that :) It looks at file similarity, though, so if you completely rewrite a file and simultaneously rename/move it, git will lose track of it. And as you say, sometimes it gets things wrong - if you merge a large file into a small one, git will report it as a deletion and rename. (Of course, it doesn't make any difference. It's just a matter of reporting.) Mercurial, if I understand correctly, actually _tracks_ moves (and copies), but git just records a deletion and a creation. My family in fact has a literal "grandfather's axe" (except that I don't think either of my grandfathers actually owned it, but it's my Dad's old axe) that has had many new handles and a couple of new heads. Bringing it back to computers, we have on our network two computers "Stanley" and "Ollie" that have been there ever since we first set up that network. Back then, it was coax cable, 10base2, no routers/switches/etc, and the computers were I think early Pentiums. We installed the database on one of them, and set the other in Dad's office. Today, we have a modern Ethernet setup with modern hardware and cat-5 cable; we still have Stanley with the database and Ollie in the office. The name/identity of the computer is mostly associated with its roles; but those roles can shift too (there was a time when Ollie was the internet gateway, but that's no longer the case). Identity is its own attribute. The problem isn't that identity can't exist. It's that it can't be discovered. That takes external knowledge. Dave's analogy is accurate. ChrisA From wuwei23 at gmail.com Tue Jan 22 20:36:32 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 22 Jan 2013 17:36:32 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: <45ef0f07-505e-4986-bc99-bd0ce86c101c@q16g2000pbt.googlegroups.com> On Jan 22, 10:04?am, Chris Angelico wrote: > My family in fact has a literal "grandfather's axe" (except that I > don't think either of my grandfathers actually owned it, but it's my > Dad's old axe) that has had many new handles and a couple of new > heads. Ah, that's brilliant, I hadn't heard that term before, and it'll be a lot easier to explain to people than the Theseus example. How we think of identity is _awesome_ :) From d at davea.name Mon Jan 21 17:26:57 2013 From: d at davea.name (Dave Angel) Date: Mon, 21 Jan 2013 17:26:57 -0500 Subject: Uniquely identifying each & every html template In-Reply-To: <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <239abe33-fa5b-41a9-ae80-5260b9b1bd9c@googlegroups.com> Message-ID: <50FDC0B1.2020004@davea.name> On 01/21/2013 07:06 AM, Ferrous Cranus wrote: > >> >> >> >> Seriously, you're asking for something that's beyond the power of >> >> humans or computers. You want to identify that something's the same >> >> file, without tracking the change or having any identifiable tag. >> >> That's a fundamentally impossible task. > > No, it is difficult but not impossible. > It just cannot be done by tagging the file by: > > 1. filename > 2. filepath > 3. hash (math algorithm producing a string based on the file's contents) > > We need another way to identify the file WITHOUT using the above attributes. > Repeating the same impossible scenario won't solve it. You need to find some other way to recognize the file. If you can't count on either name, location, or content, you can't do it. Try solving the problem by hand. If you examine the files, and a particular one has both changed names and content, how are you going to decide that it's the "same" one? Define "same" in a way that you could do it by hand, and you're halfway towards a programming solution. Maybe it'd be obvious from an analogy. Suppose you're HR for a company with 100 employees, and a strange policy of putting paychecks under the wipers of the employees' windshields. All the employee cars are kept totally clean of personal belongings, with no registration or license plates. The lot has no reserved parking places, so every car has a random location. For a while, you just memorize the make/model/color of each car, and everything's fine. But one day several of the employees buy new cars. How do you then associate each car with each employee? I've got it - you require each one to keep a numbered parking sticker, and they move the sticker when they get a new car. Or, you give everyone a marked, reserved parking place. Or you require each employee to report any car exchanges to you, so you can update your records. If you can solve this one, you can probably solve the other one. Until then, we have no spec. -- DaveA From timr at probo.com Mon Jan 21 22:57:54 2013 From: timr at probo.com (Tim Roberts) Date: Mon, 21 Jan 2013 19:57:54 -0800 Subject: Uniquely identifying each & every html template References: <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> Message-ID: Ferrous Cranus wrote: > >No, it is difficult but not impossible. >It just cannot be done by tagging the file by: > >1. filename >2. filepath >3. hash (math algorithm producing a string based on the file's contents) > >We need another way to identify the file WITHOUT using the above attributes. Think about it this way. Say that YOU, as a human being, were inserted into the web server. You are handed the path and the contents of a page about to be served. How would YOU solve this problem? If you can't describe in words how YOU would recognize these altered files, then there is absolutely no way to teach a computer how to do it. It IS impossible. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Mon Jan 21 23:04:09 2013 From: timr at probo.com (Tim Roberts) Date: Mon, 21 Jan 2013 20:04:09 -0800 Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> Message-ID: Ferrous Cranus wrote: > >Renames and moves are performed, either by shell access or either by cPanel access by website owners. > >That being said i have no control on HOW and WHEN users alter their html pages. Right, and that makes it impossible to solve this problem. Think about some scenarios. Let's say I have a web site with two pages: ~/web/page1.html ~/web/page2.html Now let's say I use some editor to make a copy of page1 called page1a.html. ~/web/page1.html ~/web/page1a.html ~/web/page2.html Should page1a.html be considered the same page as page1.html? What if I subsequently delete page1.html? What if I don't? How long will you wait before deciding they are the same? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nikos.gr33k at gmail.com Tue Jan 22 01:49:31 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 22:49:31 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> Message-ID: <179d586e-1fa7-4b2e-8ef2-25b99bf46116@googlegroups.com> ?? ?????, 22 ?????????? 2013 6:04:09 ?.?. UTC+2, ? ??????? Tim Roberts ??????: > Ferrous Cranus wrote: > > > > > >Renames and moves are performed, either by shell access or either by cPanel access by website owners. > > > > > >That being said i have no control on HOW and WHEN users alter their html pages. > > > > Right, and that makes it impossible to solve this problem. > > > > Think about some scenarios. Let's say I have a web site with two pages: > > ~/web/page1.html > > ~/web/page2.html > > > > Now let's say I use some editor to make a copy of page1 called page1a.html. > > ~/web/page1.html > > ~/web/page1a.html > > ~/web/page2.html > > > > Should page1a.html be considered the same page as page1.html? What if I > > subsequently delete page1.html? What if I don't? How long will you wait > > before deciding they are the same? > > -- > > Tim Roberts, timr at probo.com > > Providenza & Boekelheide, Inc. You are right, it cannot be done. So i have 2 options . Either identify an .html file from its "filepath" or from its "hash". Which method do you advice me to utilize? From nikos.gr33k at gmail.com Wed Jan 23 04:15:24 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 01:15:24 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <179d586e-1fa7-4b2e-8ef2-25b99bf46116@googlegroups.com> Message-ID: <1c84a142-a40c-425d-82f2-6916c709f0ee@googlegroups.com> ?? ?????, 22 ?????????? 2013 11:08:57 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Mon, 21 Jan 2013 22:49:31 -0800 (PST), Ferrous Cranus > > declaimed the following in > > gmane.comp.python.general: > > > > > You are right, it cannot be done. > > > > > > So i have 2 options . > > > > > > Either identify an .html file from its "filepath" or from its "hash". > > > > > > Which method do you advice me to utilize? > > > > The hash identifies based upon the file contents -- any edit to the > > file will result in a different hash (and if the hash system isn't large > > enough, you may even encounter collisions where two or more files have > > the same hash). However, moving or renaming the file should still > > produce the same hash. > > > > Path/name at least lets the file contents be edited. Anything that > > changes the path/name will be seen as a new file. > > > > Which condition is most useful to your needs: allowing free content > > edits while keeping the counter tied to the end URL; or tying the > > counter to a fixed page but letting the URL to that page change. The best would be to: Allow free content edits, while the URL to that page may also change. From nikos.gr33k at gmail.com Wed Jan 23 04:15:24 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 01:15:24 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <187d77e0-e948-46bf-acc5-668c446cf3aa@googlegroups.com> <179d586e-1fa7-4b2e-8ef2-25b99bf46116@googlegroups.com> Message-ID: <1c84a142-a40c-425d-82f2-6916c709f0ee@googlegroups.com> ?? ?????, 22 ?????????? 2013 11:08:57 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Mon, 21 Jan 2013 22:49:31 -0800 (PST), Ferrous Cranus > > declaimed the following in > > gmane.comp.python.general: > > > > > You are right, it cannot be done. > > > > > > So i have 2 options . > > > > > > Either identify an .html file from its "filepath" or from its "hash". > > > > > > Which method do you advice me to utilize? > > > > The hash identifies based upon the file contents -- any edit to the > > file will result in a different hash (and if the hash system isn't large > > enough, you may even encounter collisions where two or more files have > > the same hash). However, moving or renaming the file should still > > produce the same hash. > > > > Path/name at least lets the file contents be edited. Anything that > > changes the path/name will be seen as a new file. > > > > Which condition is most useful to your needs: allowing free content > > edits while keeping the counter tied to the end URL; or tying the > > counter to a fixed page but letting the URL to that page change. The best would be to: Allow free content edits, while the URL to that page may also change. From wuwei23 at gmail.com Mon Jan 21 07:56:24 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 21 Jan 2013 04:56:24 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: <291e92a6-c984-4636-927a-ed6cd78e49d1@pu9g2000pbc.googlegroups.com> On Jan 21, 7:19?pm, Ferrous Cranus wrote: > Renames and ?moves are performed, either by shell access or either by cPanel access by website owners. These websites owners, are you charging them for this "service" you provide? You seriously need to read up on some fundamentals of how the web + apache + Python works. As it stands, you're asking us to do your job for you, and it's getting TEDIOUS with you TELLING us how WRONG we are. From nikos.gr33k at gmail.com Mon Jan 21 10:03:39 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 07:03:39 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: <291e92a6-c984-4636-927a-ed6cd78e49d1@pu9g2000pbc.googlegroups.com> References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <291e92a6-c984-4636-927a-ed6cd78e49d1@pu9g2000pbc.googlegroups.com> Message-ID: <97131fb6-26d9-488c-8929-6cb721447028@googlegroups.com> ?? ???????, 21 ?????????? 2013 2:56:24 ?.?. UTC+2, ? ??????? alex23 ??????: > On Jan 21, 7:19?pm, Ferrous Cranus wrote: > > > Renames and ?moves are performed, either by shell access or either by cPanel access by website owners. > > > > These websites owners, are you charging them for this "service" you > > provide? > > > > You seriously need to read up on some fundamentals of how the web + > > apache + Python works. As it stands, you're asking us to do your job > > for you, and it's getting TEDIOUS with you TELLING us how WRONG we are. Dude, i host 4 sites of friend fo mine who want the same type of counter like i use iun my website. ALL, iam asking for is a way to make this work. From wuwei23 at gmail.com Mon Jan 21 18:35:29 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 21 Jan 2013 15:35:29 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <291e92a6-c984-4636-927a-ed6cd78e49d1@pu9g2000pbc.googlegroups.com> <97131fb6-26d9-488c-8929-6cb721447028@googlegroups.com> Message-ID: On Jan 22, 1:03?am, Ferrous Cranus wrote: > ALL, iam asking for is a way to make this work. No, ALL you are asking is for us to take an _impossible_ situation and make it magically work for you, without your having to improve your understanding of the problem or modifying your requirements in any way. You don't see *your ignorance* as the problem, preferring instead to blame others and Python itself for your failings. None of the solutions proposed satisfy you because they seem like too much work, and you're convinced that this can just happen. It can't, and you desperately need to educate yourself on some vital aspects of _how the web works_ (and Python, and file systems, and *NIX environments etc etc). From piet at vanoostrum.org Mon Jan 21 15:48:11 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 21 Jan 2013 21:48:11 +0100 Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: Ferrous Cranus writes: > This python script acts upon websites other people use and every html > templates has been written by different methods(notepad++, > dreamweaver, joomla). > > Renames and moves are performed, either by shell access or either by > cPanel access by website owners. > > That being said i have no control on HOW and WHEN users alter their html pages. Under these circumstances the only way to solve it is to put an identification *inside* the file and make sure it will not be changed. It could for example be some invisible piece of HTML, or an attribute to some tag. If that can't be done the problem cannot be solved and it makes no sense keeping asking the same question over and over again. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nikos.gr33k at gmail.com Tue Jan 22 01:38:18 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 22:38:18 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: ?? ???????, 21 ?????????? 2013 10:48:11 ?.?. UTC+2, ? ??????? Piet van Oostrum ??????: > Ferrous Cranus writes: > > > > > This python script acts upon websites other people use and every html > > > templates has been written by different methods(notepad++, > > > dreamweaver, joomla). > > > > > > Renames and moves are performed, either by shell access or either by > > > cPanel access by website owners. > > > > > > That being said i have no control on HOW and WHEN users alter their html pages. > > > > Under these circumstances the only way to solve it is to put an > > identification *inside* the file and make sure it will not be changed. > > It could for example be some invisible piece of HTML, or an attribute to > > some tag. If that can't be done the problem cannot be solved and it > > makes no sense keeping asking the same question over and over again. The solution you propose is what i already use for my website. Since its my website i can edit all the .html i want embedding a unique number in each and evey one of them as i showed in my initial post. Problem is i'am not allowed to do the same with the other websites i host. And apart from that even if i was allowed to, an html page could be rewritten thus the identified would get lost. From nikos.gr33k at gmail.com Mon Jan 21 10:07:05 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 07:07:05 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: <231d970b-da08-475d-b53c-ebbad032658b@googlegroups.com> ?? ???????, 21 ?????????? 2013 9:20:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Mon, Jan 21, 2013 at 6:08 PM, Ferrous Cranus wrote: > > > An .html page must retain its database counter value even if its: > > > > > > (renamed && moved && contents altered) > > > > Then you either need to tag them in some external way, or have some > > kind of tracking operation - for instance, if you require that all > > renames/moves be done through a script, that script can update its > > pointer. Otherwise, you need magic, and lots of it. > > > > ChrisA Perhaps we should look into on how's the OS handles the file to get an idea on how its done? From nikos.gr33k at gmail.com Mon Jan 21 10:07:05 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 21 Jan 2013 07:07:05 -0800 (PST) Subject: Uniquely identifying each & every html template In-Reply-To: References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> Message-ID: <231d970b-da08-475d-b53c-ebbad032658b@googlegroups.com> ?? ???????, 21 ?????????? 2013 9:20:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Mon, Jan 21, 2013 at 6:08 PM, Ferrous Cranus wrote: > > > An .html page must retain its database counter value even if its: > > > > > > (renamed && moved && contents altered) > > > > Then you either need to tag them in some external way, or have some > > kind of tracking operation - for instance, if you require that all > > renames/moves be done through a script, that script can update its > > pointer. Otherwise, you need magic, and lots of it. > > > > ChrisA Perhaps we should look into on how's the OS handles the file to get an idea on how its done? From wuwei23 at gmail.com Mon Jan 21 18:36:13 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 21 Jan 2013 15:36:13 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <231d970b-da08-475d-b53c-ebbad032658b@googlegroups.com> Message-ID: <72375b47-cd1b-4cf6-a9cf-04187ecb9e26@y5g2000pbi.googlegroups.com> On Jan 22, 1:07?am, Ferrous Cranus wrote: > Perhaps we should look into on how's the OS handles the file to get an idea on how its done? Who is this "we" you speak of? You mean "you", right? You do that and get back to us when you believe you've found something that helps. From rustompmody at gmail.com Mon Jan 21 23:18:34 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 21 Jan 2013 20:18:34 -0800 (PST) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> <03581a24-9330-4019-bde9-61a607000d3d@googlegroups.com> <231d970b-da08-475d-b53c-ebbad032658b@googlegroups.com> Message-ID: On Jan 21, 8:07?pm, Ferrous Cranus wrote: > ?? ???????, 21 ?????????? 2013 9:20:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > > > > > > > > > > On Mon, Jan 21, 2013 at 6:08 PM, Ferrous Cranus wrote: > > > > An .html page must retain its database counter value even if its: > > > > (renamed && moved && contents altered) > > > Then you either need to tag them in some external way, or have some > > > kind of tracking operation - for instance, if you require that all > > > renames/moves be done through a script, that script can update its > > > pointer. Otherwise, you need magic, and lots of it. > > > ChrisA > > Perhaps we should look into on how's the OS handles the file to get an idea on how its done? Yes? Perhaps the most useful for you suggestion Ive seen in this thread is to look at git. If you do you will find that a. git has to do a great deal more work than you expect to factorize out content-tracking from file-tracking b. Yet it can get it wrong Look at snapshoting file systems http://en.wikipedia.org/wiki/Snapshot_%28computer_storage%29#File_systems like winfs (cancelled) and btrfs Slightly more practical may be timevault http://www.dedoimedo.com/computers/timevault.html From gordon at panix.com Tue Jan 22 11:35:10 2013 From: gordon at panix.com (John Gordon) Date: Tue, 22 Jan 2013 16:35:10 +0000 (UTC) Subject: Uniquely identifying each & every html template References: <8deb6f5d-ff10-4b36-bdd6-36f9eed58e1e@googlegroups.com> <5dd4babd-716d-4542-ad36-e6a841b73ec3@googlegroups.com> Message-ID: In <5dd4babd-716d-4542-ad36-e6a841b73ec3 at googlegroups.com> Ferrous Cranus writes: > > If that's the case, then I figure you have about 3 choices: > > 1) use the file path as your key, instead of requiring a number > No, i cannot, because it would mess things at a later time on when i for > example: > 1. mv name.html othername.html (document's filename altered) > 2. mv name.html /subfolder/name.html (document's filepath altered) Will the file always reside on the same device? If so, perhaps you could use the file inode number as the key. (That seems fairly brittle though. For example if the disk crashes and is restored from a backup, the inodes could easily be different.) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve+comp.lang.python at pearwood.info Fri Jan 18 23:07:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2013 04:07:13 GMT Subject: Safely add a key to a dict only if it does not already exist? Message-ID: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> I wish to add a key to a dict only if it doesn't already exist, but do it in a thread-safe manner. The naive code is: if key not in dict: dict[key] = value but of course there is a race condition there: it is possible that another thread may have added the same key between the check and the store. How can I add a key in a thread-safe manner? Any solutions must work with built-in dicts, I cannot use a custom dict subclass. -- Steven From clp2 at rebertia.com Fri Jan 18 23:15:26 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 18 Jan 2013 20:15:26 -0800 Subject: Safely add a key to a dict only if it does not already exist? In-Reply-To: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, January 18, 2013, Steven D'Aprano wrote: > I wish to add a key to a dict only if it doesn't already exist, but do it > in a thread-safe manner. > > The naive code is: > > if key not in dict: > dict[key] = value > > > but of course there is a race condition there: it is possible that another thread may have added the same key between the check and the > store. > > How can I add a key in a thread-safe manner? > I'm not entirely sure, but have you investigated dict.setdefault() ? -- Cheers, Chris -- http://rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Jan 19 00:00:25 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 19 Jan 2013 16:00:25 +1100 Subject: Safely add a key to a dict only if it does not already exist? In-Reply-To: References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/01/13 15:15, Chris Rebert wrote: > On Friday, January 18, 2013, Steven D'Aprano wrote: > > I wish to add a key to a dict only if it doesn't already exist, but > do it > in a thread-safe manner. > > The naive code is: > > if key not in dict: > dict[key] = value > > > but of course there is a race condition there: it is possible that > > another thread may have added the same key between the check and the > store. > > How can I add a key in a thread-safe manner? > > > I'm not entirely sure, but have you investigated dict.setdefault() ? dict.setdefault() was not atomic on older python version, they were made atomic in Python 2.7.3 and Python 3.2.3. See bug13521 in the issue tracker http://bugs.python.org/issue13521 PS: The bug tracker seems down at the moment, so pulled this from Google's cache: https://webcache.googleusercontent.com/search?q=cache:59PO_F-VEfwJ:bugs.python.org/issue13521+&cd=1&hl=en&ct=clnk&client=ubuntu From vito.detullio at gmail.com Sat Jan 19 02:27:12 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 19 Jan 2013 08:27:12 +0100 Subject: Safely add a key to a dict only if it does not already exist? References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Rebert wrote: >> How can I add a key in a thread-safe manner? > I'm not entirely sure, but have you investigated dict.setdefault() ? but how setdefault makes sense in this context? It's used to set a default value when you try to retrieve an element from the dict, not when you try to set a new one ... -- ZeD From msirenef at lightbird.net Sat Jan 19 02:35:12 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sat, 19 Jan 2013 02:35:12 -0500 Subject: Safely add a key to a dict only if it does not already exist? In-Reply-To: References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50FA4CB0.5020308@lightbird.net> On 01/19/2013 02:27 AM, Vito De Tullio wrote: > Chris Rebert wrote: > >>> How can I add a key in a thread-safe manner? >> I'm not entirely sure, but have you investigated dict.setdefault() ? > but how setdefault makes sense in this context? It's used to set a default > value when you try to retrieve an element from the dict, not when you try to > set a new one ... > I guess setdefault with a sentinel default value, then set to your new value if d[k] is sentinel? - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From msirenef at lightbird.net Sat Jan 19 03:18:42 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sat, 19 Jan 2013 03:18:42 -0500 Subject: Safely add a key to a dict only if it does not already exist? In-Reply-To: <50FA4CB0.5020308@lightbird.net> References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> <50FA4CB0.5020308@lightbird.net> Message-ID: <50FA56E2.5090206@lightbird.net> On 01/19/2013 02:35 AM, Mitya Sirenef wrote: > On 01/19/2013 02:27 AM, Vito De Tullio wrote: >> Chris Rebert wrote: >> >>>> How can I add a key in a thread-safe manner? >>> I'm not entirely sure, but have you investigated dict.setdefault() ? >> but how setdefault makes sense in this context? It's used to set a >> default >> value when you try to retrieve an element from the dict, not when you >> try to >> set a new one ... >> > > I guess setdefault with a sentinel default value, then set to your > new value if d[k] is sentinel? > > - mitya > > Er, that makes no sense.. just setdefault to desired value. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From __peter__ at web.de Sat Jan 19 03:02:45 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 19 Jan 2013 09:02:45 +0100 Subject: Safely add a key to a dict only if it does not already exist? References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Vito De Tullio wrote: > Chris Rebert wrote: > >>> How can I add a key in a thread-safe manner? >> I'm not entirely sure, but have you investigated dict.setdefault() ? > > but how setdefault makes sense in this context? It's used to set a default > value when you try to retrieve an element from the dict, not when you try > to set a new one ... But it also sets the value if the key is not found: """ setdefault(...) D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """ >>> d = {} >>> d.setdefault(1, 2) 2 >>> d {1: 2} >>> d.setdefault(1, 3) 2 >>> d {1: 2} It has been suggested that get_or_set() would have been a better name for that functionality... From vito.detullio at gmail.com Sat Jan 19 03:16:48 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 19 Jan 2013 09:16:48 +0100 Subject: Safely add a key to a dict only if it does not already exist? References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Peter Otten wrote: >>>> How can I add a key in a thread-safe manner? >>> I'm not entirely sure, but have you investigated dict.setdefault() ? >> >> but how setdefault makes sense in this context? It's used to set a >> default value when you try to retrieve an element from the dict, not when >> you try to set a new one ... > > But it also sets the value if the key is not found: yeah, sure, but with a fixed value :) I mean: if the value is not important, why bother at all trying not to override it with an if or a lock or other tecniques? doing d['key'] = 'fixed_value' multiple times in different threads is not a problem in my eyes... -- ZeD From rosuav at gmail.com Sat Jan 19 03:23:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jan 2013 19:23:51 +1100 Subject: Safely add a key to a dict only if it does not already exist? In-Reply-To: References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 19, 2013 at 7:16 PM, Vito De Tullio wrote: > yeah, sure, but with a fixed value :) > > I mean: if the value is not important, why bother at all trying not to > override it with an if or a lock or other tecniques? doing > > d['key'] = 'fixed_value' > > multiple times in different threads is not a problem in my eyes... How fixed is fixed? >>> d={} >>> d.setdefault("foo",1) 1 >>> d.setdefault("bar",2) 2 >>> d {'bar': 2, 'foo': 1} If list append is guaranteed atomic, and since setdefault is apparently atomic, then this would be a thread-safe way to maintain a dictionary of lists: >>> d={} >>> lst=d.setdefault("foo",[]) >>> lst.append(1) Are those guarantees made? ChrisA From vito.detullio at gmail.com Sat Jan 19 03:19:03 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 19 Jan 2013 09:19:03 +0100 Subject: Safely add a key to a dict only if it does not already exist? References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Peter Otten wrote: uhhmm.. I think I misread the example >>>> d = {} >>>> d.setdefault(1, 2) > 2 >>>> d > {1: 2} >>>> d.setdefault(1, 3) > 2 >>>> d > {1: 2} yeah, sure it can be useful for the OP... -- ZeD From vito.detullio at gmail.com Sat Jan 19 02:25:27 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 19 Jan 2013 08:25:27 +0100 Subject: Safely add a key to a dict only if it does not already exist? References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I wish to add a key to a dict only if it doesn't already exist, but do it > in a thread-safe manner. > > The naive code is: > > if key not in dict: > dict[key] = value > > > but of course there is a race condition there: it is possible that > another thread may have added the same key between the check and the > store. > > How can I add a key in a thread-safe manner? using locks? import threading lock = threading.Lock() with lock: if key not in dict: dict[key] = value -- ZeD From steve+comp.lang.python at pearwood.info Sat Jan 19 05:31:40 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2013 10:31:40 GMT Subject: Safely add a key to a dict only if it does not already exist? References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50fa760b$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Jan 2013 20:15:26 -0800, Chris Rebert wrote: > On Friday, January 18, 2013, Steven D'Aprano wrote: > >> I wish to add a key to a dict only if it doesn't already exist, but do >> it in a thread-safe manner. [...] > I'm not entirely sure, but have you investigated dict.setdefault() ? Great! That's exactly what I need, thanks to everyone who responded. -- Steven From roy at panix.com Sat Jan 19 08:04:15 2013 From: roy at panix.com (Roy Smith) Date: Sat, 19 Jan 2013 08:04:15 -0500 Subject: Safely add a key to a dict only if it does not already exist? References: <50fa1bf1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <50fa1bf1$0$30003$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I wish to add a key to a dict only if it doesn't already exist, but do it > in a thread-safe manner. > > The naive code is: > > if key not in dict: > dict[key] = value > > > but of course there is a race condition there: it is possible that > another thread may have added the same key between the check and the > store. > > How can I add a key in a thread-safe manner? You want something along the lines of: from threading import Lock lock = Lock() [...] lock.acquire() if key not in dict: dict[key] = value lock.release() You probably want to wrap that up in a context manager to ensure the lock is released if you get an exception. You don't want your entire program to hang just because somebody handed you a key which wasn't hashable, for example. From iwarobots at gmail.com Fri Jan 18 23:50:18 2013 From: iwarobots at gmail.com (Cen Wang) Date: Fri, 18 Jan 2013 20:50:18 -0800 (PST) Subject: Question related to multiprocessing.Process Message-ID: <6816f48f-753f-4ae3-be79-3b16bd83e6f2@googlegroups.com> Hi, when I use multiprocessing.Process in this way: from multiprocessing import Process class MyProcess(Process): def __init__(self): Process.__init__(self) def run(self): print 'x' p = MyProcess() p.start() It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. From rosuav at gmail.com Sat Jan 19 00:05:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jan 2013 16:05:07 +1100 Subject: Question related to multiprocessing.Process In-Reply-To: <6816f48f-753f-4ae3-be79-3b16bd83e6f2@googlegroups.com> References: <6816f48f-753f-4ae3-be79-3b16bd83e6f2@googlegroups.com> Message-ID: On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang wrote: > Hi, when I use multiprocessing.Process in this way: > > from multiprocessing import Process > > class MyProcess(Process): > > def __init__(self): > Process.__init__(self) > > def run(self): > print 'x' > > p = MyProcess() > p.start() > > It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. Multiprocessing on Windows requires that your module be importable. So it imports your main module, which instantiates another MyProcess, starts it, rinse and repeat. You'll need to protect your main routine code: if __name__=="__main__": p = MyProcess() p.start() ChrisA From tjreedy at udel.edu Sat Jan 19 06:27:33 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 19 Jan 2013 06:27:33 -0500 Subject: Question related to multiprocessing.Process In-Reply-To: References: <6816f48f-753f-4ae3-be79-3b16bd83e6f2@googlegroups.com> Message-ID: On 1/19/2013 12:05 AM, Chris Angelico wrote: > On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang wrote: >> Hi, when I use multiprocessing.Process in this way: >> >> from multiprocessing import Process >> >> class MyProcess(Process): >> >> def __init__(self): >> Process.__init__(self) >> >> def run(self): >> print 'x' >> >> p = MyProcess() >> p.start() >> >> It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. > > Multiprocessing on Windows requires that your module be importable. So > it imports your main module, which instantiates another MyProcess, > starts it, rinse and repeat. You'll need to protect your main routine > code: > > if __name__=="__main__": > p = MyProcess() > p.start() This is documented in 17.2.3. Programming guidelines 17.2.3.2. Windows -- Terry Jan Reedy From iwarobots at gmail.com Sat Jan 19 00:33:35 2013 From: iwarobots at gmail.com (Cen Wang) Date: Fri, 18 Jan 2013 21:33:35 -0800 (PST) Subject: Question related to multiprocessing.Process In-Reply-To: References: <6816f48f-753f-4ae3-be79-3b16bd83e6f2@googlegroups.com> Message-ID: <044321bf-8e91-4a63-9a78-99a3ec5e40db@googlegroups.com> Thanks! It now works! On Saturday, 19 January 2013 13:05:07 UTC+8, Chris Angelico wrote: > On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang wrote: > > > Hi, when I use multiprocessing.Process in this way: > > > > > > from multiprocessing import Process > > > > > > class MyProcess(Process): > > > > > > def __init__(self): > > > Process.__init__(self) > > > > > > def run(self): > > > print 'x' > > > > > > p = MyProcess() > > > p.start() > > > > > > It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. > > > > Multiprocessing on Windows requires that your module be importable. So > > it imports your main module, which instantiates another MyProcess, > > starts it, rinse and repeat. You'll need to protect your main routine > > code: > > > > if __name__=="__main__": > > p = MyProcess() > > p.start() > > > > ChrisA From iwarobots at gmail.com Sat Jan 19 00:33:35 2013 From: iwarobots at gmail.com (Cen Wang) Date: Fri, 18 Jan 2013 21:33:35 -0800 (PST) Subject: Question related to multiprocessing.Process In-Reply-To: References: <6816f48f-753f-4ae3-be79-3b16bd83e6f2@googlegroups.com> Message-ID: <044321bf-8e91-4a63-9a78-99a3ec5e40db@googlegroups.com> Thanks! It now works! On Saturday, 19 January 2013 13:05:07 UTC+8, Chris Angelico wrote: > On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang wrote: > > > Hi, when I use multiprocessing.Process in this way: > > > > > > from multiprocessing import Process > > > > > > class MyProcess(Process): > > > > > > def __init__(self): > > > Process.__init__(self) > > > > > > def run(self): > > > print 'x' > > > > > > p = MyProcess() > > > p.start() > > > > > > It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. > > > > Multiprocessing on Windows requires that your module be importable. So > > it imports your main module, which instantiates another MyProcess, > > starts it, rinse and repeat. You'll need to protect your main routine > > code: > > > > if __name__=="__main__": > > p = MyProcess() > > p.start() > > > > ChrisA From scubbojj at gmail.com Sat Jan 19 00:47:12 2013 From: scubbojj at gmail.com (scubbojj at gmail.com) Date: Fri, 18 Jan 2013 21:47:12 -0800 (PST) Subject: problems trying to build python 2.6 as a shared library In-Reply-To: <524da24d-d44b-4dab-80be-cbcea36a9eaf@z34g2000vbl.googlegroups.com> References: <524da24d-d44b-4dab-80be-cbcea36a9eaf@z34g2000vbl.googlegroups.com> Message-ID: <5ff4a69c-2ea9-402f-a1ce-9a62adee1395@googlegroups.com> On Friday, 25 September 2009 04:36:28 UTC-7, Marco Nawijn wrote: > On Sep 25, 1:08?pm, Chris Withers wrote: > > Hi All, > > > > I'm trying to build Python 2.6 as a shared library, so I did: > > > > ? ?./configure --enable-shared > > ? ?make > > ? ?make altinstall > > > > No obvious signs of failure, but when I try and use the resulting > > python, I get: > > > > python2.6: error while loading shared libraries: libpython2.6.so.1.0: > > cannot open shared object file: No such file or directory > > > > Why might that be? > > > > cheers, > > > > Chris > > > > -- > > Simplistix - Content Management, Batch Processing & Python Consulting > > ? ? ? ? ? ? -http://www.simplistix.co.uk > > Hello Chris, > > The dynamic loader cannot find the python shared library. There are > at least 2 options: > 1. Add path that contains the shared library to the > LD_LIBRARY_PATH environment variable. In a bash shell this can be > accomplished by: export LD_LIBRARY_PATH=/path/to/python_shared_lib: > $LD_LIBRARY_PATH > 2. Add path to dynamic linker configuration file. This typically > is in '/etc/ld.so.conf'. See man page for ld for more information. > > Note that I assumed that you are on a Unix/Linux machine. > > Regards, > > Marco Could you elaborate on this for a Linux newbie please? I carried out step 1 with no problems, but when I view /etc/ld.so.conf, I get the following: $ cat /etc/ld.so.conf include ld.so.conf.d/*.conf I don't know how to use ld - I see from the man pag that it's used for linking files, but I don't know (in this context) what files I want to be linking to what. I've copied libpython2.7.so and libpython2.7.so.1.0 to the folder in $LD_LIBRARY_PATH, meaning I don't get the problems detailed in the original post anymore, but I'm concerned that I'm sticking a plaster over a bigger problem. From pwsteele at gmail.com Sat Jan 19 02:32:05 2013 From: pwsteele at gmail.com (Peter Steele) Date: Fri, 18 Jan 2013 23:32:05 -0800 (PST) Subject: Sending a broadcast message using raw sockets Message-ID: I want to write a program in Python that sends a broadcast message using raw sockets. The system where this program will run has no IP or default route defined, hence the reason I need to use a broadcast message. I've done some searches and found some bits and pieces about using raw sockets in Python, but I haven't been able to find an example that explains how to construct a broadcast message using raw sockets. Any pointers would be appreciated. From rtw at rtw.me.uk Mon Jan 21 04:10:06 2013 From: rtw at rtw.me.uk (Rob Williscroft) Date: Mon, 21 Jan 2013 09:10:06 +0000 (UTC) Subject: Sending a broadcast message using raw sockets References: Message-ID: Peter Steele wrote in news:f37ccb35-8439-42cd-a063-962249b44903 at googlegroups.com in comp.lang.python: > I want to write a program in Python that sends a broadcast message > using raw sockets. The system where this program will run has no IP or > default route defined, hence the reason I need to use a broadcast > message. > > I've done some searches and found some bits and pieces about using raw > sockets in Python, but I haven't been able to find an example that > explains how to construct a broadcast message using raw sockets. > > Any pointers would be appreciated. This is part of my Wake-On-Lan script: def WOL_by_mac( mac, ip = '', port = 9 ): import struct, socket a = mac.replace( ':', '-' ).split( '-' ) addr = struct.pack( 'B'*6, *[ int(_, 16) for _ in a ] ) msg = b'\xff' * 6 + addr * 16 s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) s.setsockopt( socket.SOL_SOCKET, socket.SO_BROADCAST, 1 ) s.sendto( msg, ( ip, port ) ) s.close() The mac address is 6 pairs of hex digits seperated by '-' or ':'. http://en.wikipedia.org/wiki/Wake-on-LAN Rob. From pwsteele at gmail.com Mon Jan 21 20:06:02 2013 From: pwsteele at gmail.com (Peter Steele) Date: Mon, 21 Jan 2013 17:06:02 -0800 (PST) Subject: Sending a broadcast message using raw sockets In-Reply-To: References: Message-ID: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> On Monday, January 21, 2013 1:10:06 AM UTC-8, Rob Williscroft wrote: > Peter Steele wrote in > > news:f37ccb35-8439-42cd-a063-962249b44903 at googlegroups.com in > > comp.lang.python: > > > I want to write a program in Python that sends a broadcast message > > using raw sockets. The system where this program will run has no IP or > > default route defined, hence the reason I need to use a broadcast > > message. > > > > I've done some searches and found some bits and pieces about using raw > > sockets in Python, but I haven't been able to find an example that > > explains how to construct a broadcast message using raw sockets. > > > > Any pointers would be appreciated. > > This is part of my Wake-On-Lan script: > > def WOL_by_mac( mac, ip = '', port = 9 ): > > import struct, socket > > a = mac.replace( ':', '-' ).split( '-' ) > addr = struct.pack( 'B'*6, *[ int(_, 16) for _ in a ] ) > msg = b'\xff' * 6 + addr * 16 > > s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) > s.setsockopt( socket.SOL_SOCKET, socket.SO_BROADCAST, 1 ) > s.sendto( msg, ( ip, port ) ) > s.close() > > The mac address is 6 pairs of hex digits seperated by '-' or ':'. Thanks for the code sample. Does this code work if the box has no IP or default route assigned? I'm away from the office at the moment so I can't test this. From rtw at rtw.me.uk Tue Jan 22 04:06:20 2013 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 22 Jan 2013 09:06:20 +0000 (UTC) Subject: Sending a broadcast message using raw sockets References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> Message-ID: Peter Steele wrote in news:0c2b3482-df46-4324-8bf9-2c45d3f6b516 at googlegroups.com in comp.lang.python: > On Monday, January 21, 2013 1:10:06 AM UTC-8, Rob Williscroft wrote: >> Peter Steele wrote in >> >> news:f37ccb35-8439-42cd-a063-962249b44903 at googlegroups.com in >> >> comp.lang.python: >> >> > I want to write a program in Python that sends a broadcast message [snip] >> This is part of my Wake-On-Lan script: >> >> def WOL_by_mac( mac, ip = '', port = 9 ): [snip] > Thanks for the code sample. Does this code work if the box has no IP > or default route assigned? I'm away from the office at the moment so I > can't test this. No idea, but the sockets system must be up and running before the card (interface) has an IP (otherwise how would it ever get assigned) and I presume DHCP works in a similar manner. However the "route assignemt" is irrelevent, broadcast messages never get routed. Rob -- From pwsteele at gmail.com Tue Jan 22 10:11:24 2013 From: pwsteele at gmail.com (Peter Steele) Date: Tue, 22 Jan 2013 07:11:24 -0800 (PST) Subject: Sending a broadcast message using raw sockets In-Reply-To: References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> Message-ID: <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> I just tried running you code, and the "sendto" call fails with "Network is unreachable". That's what I expected, based on other tests I've done. That's why I was asking about how to do raw sockets, since tools like dhclient use raw sockets to do what they do. It can clearly be duplicated in Python, I just need to find some code samples on how to construct a raw packet. From coreylebleu at gmail.com Tue Jan 22 11:07:12 2013 From: coreylebleu at gmail.com (Corey LeBleu) Date: Tue, 22 Jan 2013 10:07:12 -0600 Subject: Sending a broadcast message using raw sockets In-Reply-To: <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> Message-ID: If you don't *have* to use the actual socket library, you might want to have a look at scapy. It's a packet manipulation program/library. It might make things a little easier. http://www.secdev.org/projects/scapy/ On Jan 22, 2013 9:17 AM, "Peter Steele" wrote: > I just tried running you code, and the "sendto" call fails with "Network > is unreachable". That's what I expected, based on other tests I've done. > That's why I was asking about how to do raw sockets, since tools like > dhclient use raw sockets to do what they do. It can clearly be duplicated > in Python, I just need to find some code samples on how to construct a raw > packet. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pwsteele at gmail.com Tue Jan 22 12:57:59 2013 From: pwsteele at gmail.com (Peter Steele) Date: Tue, 22 Jan 2013 09:57:59 -0800 (PST) Subject: Sending a broadcast message using raw sockets In-Reply-To: References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> Message-ID: <28c05d48-1af1-46db-a316-69d29089d487@googlegroups.com> In fact, I have used scapy in the past, but I am working in a restricted environment and don't have this package available. It provides tones more than I really need anyway, and I figured a simple raw socket send/receive can't be *that* hard. I may have to reverse engineer some C code, such as dhclient... On Tuesday, January 22, 2013 8:07:12 AM UTC-8, Corey LeBleu wrote: > If you don't *have* to use the actual socket library, you might want to have a look at scapy.? It's a packet manipulation program/library. It might make things a little easier. > > http://www.secdev.org/projects/scapy/ > > > > On Jan 22, 2013 9:17 AM, "Peter Steele" wrote: > > I just tried running you code, and the "sendto" call fails with "Network is unreachable". That's what I expected, based on other tests I've done. That's why I was asking about how to do raw sockets, since tools like dhclient use raw sockets to do what they do. It can clearly be duplicated in Python, I just need to find some code samples on how to construct a raw packet. > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list From pwsteele at gmail.com Tue Jan 22 12:57:59 2013 From: pwsteele at gmail.com (Peter Steele) Date: Tue, 22 Jan 2013 09:57:59 -0800 (PST) Subject: Sending a broadcast message using raw sockets In-Reply-To: References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> Message-ID: <28c05d48-1af1-46db-a316-69d29089d487@googlegroups.com> In fact, I have used scapy in the past, but I am working in a restricted environment and don't have this package available. It provides tones more than I really need anyway, and I figured a simple raw socket send/receive can't be *that* hard. I may have to reverse engineer some C code, such as dhclient... On Tuesday, January 22, 2013 8:07:12 AM UTC-8, Corey LeBleu wrote: > If you don't *have* to use the actual socket library, you might want to have a look at scapy.? It's a packet manipulation program/library. It might make things a little easier. > > http://www.secdev.org/projects/scapy/ > > > > On Jan 22, 2013 9:17 AM, "Peter Steele" wrote: > > I just tried running you code, and the "sendto" call fails with "Network is unreachable". That's what I expected, based on other tests I've done. That's why I was asking about how to do raw sockets, since tools like dhclient use raw sockets to do what they do. It can clearly be duplicated in Python, I just need to find some code samples on how to construct a raw packet. > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jan 22 16:19:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 08:19:14 +1100 Subject: Sending a broadcast message using raw sockets In-Reply-To: <28c05d48-1af1-46db-a316-69d29089d487@googlegroups.com> References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> <28c05d48-1af1-46db-a316-69d29089d487@googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 4:57 AM, Peter Steele wrote: > In fact, I have used scapy in the past, but I am working in a restricted environment and don't have this package available. It provides tones more than I really need anyway, and I figured a simple raw socket send/receive can't be *that* hard. I may have to reverse engineer some C code, such as dhclient... Yeah, I think you're working with something fairly esoteric there - bypassing the lower tiers of support (routing etc). Chances are you won't find any good Python examples, and C's all you'll have. Are you reasonably familiar with C? Point to note: Raw sockets *may* require special privileges. Some systems require that only root employ them, for security's sake. ChrisA From pwsteele at gmail.com Tue Jan 22 16:36:39 2013 From: pwsteele at gmail.com (Peter Steele) Date: Tue, 22 Jan 2013 13:36:39 -0800 (PST) Subject: Sending a broadcast message using raw sockets In-Reply-To: References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> <28c05d48-1af1-46db-a316-69d29089d487@googlegroups.com> Message-ID: <662fc299-e362-4720-85d2-9ab07addd8d7@googlegroups.com> Actually, I used to teach C, so yeah, I know it pretty well. :-) Scapy is a possibility, I just need to add it to my environment (which doesn't have a C compiler). I can jury rig something though. On Tuesday, January 22, 2013 1:19:14 PM UTC-8, Chris Angelico wrote: > On Wed, Jan 23, 2013 at 4:57 AM, Peter Steele wrote: > > > In fact, I have used scapy in the past, but I am working in a restricted environment and don't have this package available. It provides tones more than I really need anyway, and I figured a simple raw socket send/receive can't be *that* hard. I may have to reverse engineer some C code, such as dhclient... > > > > Yeah, I think you're working with something fairly esoteric there - > > bypassing the lower tiers of support (routing etc). Chances are you > > won't find any good Python examples, and C's all you'll have. Are you > > reasonably familiar with C? > > > > Point to note: Raw sockets *may* require special privileges. Some > > systems require that only root employ them, for security's sake. > > > > ChrisA From pwsteele at gmail.com Tue Jan 22 16:36:39 2013 From: pwsteele at gmail.com (Peter Steele) Date: Tue, 22 Jan 2013 13:36:39 -0800 (PST) Subject: Sending a broadcast message using raw sockets In-Reply-To: References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> <28c05d48-1af1-46db-a316-69d29089d487@googlegroups.com> Message-ID: <662fc299-e362-4720-85d2-9ab07addd8d7@googlegroups.com> Actually, I used to teach C, so yeah, I know it pretty well. :-) Scapy is a possibility, I just need to add it to my environment (which doesn't have a C compiler). I can jury rig something though. On Tuesday, January 22, 2013 1:19:14 PM UTC-8, Chris Angelico wrote: > On Wed, Jan 23, 2013 at 4:57 AM, Peter Steele wrote: > > > In fact, I have used scapy in the past, but I am working in a restricted environment and don't have this package available. It provides tones more than I really need anyway, and I figured a simple raw socket send/receive can't be *that* hard. I may have to reverse engineer some C code, such as dhclient... > > > > Yeah, I think you're working with something fairly esoteric there - > > bypassing the lower tiers of support (routing etc). Chances are you > > won't find any good Python examples, and C's all you'll have. Are you > > reasonably familiar with C? > > > > Point to note: Raw sockets *may* require special privileges. Some > > systems require that only root employ them, for security's sake. > > > > ChrisA From rtw at rtw.me.uk Tue Jan 22 16:58:07 2013 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 22 Jan 2013 21:58:07 +0000 (UTC) Subject: Sending a broadcast message using raw sockets References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> Message-ID: Peter Steele wrote in news:96947c45-f16b-4e97-b055-edc1241ee4a1 at googlegroups.com in comp.lang.python: > I just tried running you code, and the "sendto" call fails with > "Network is unreachable". That's what I expected, based on other tests > I've done. That's why I was asking about how to do raw sockets, since > tools like dhclient use raw sockets to do what they do. It can clearly > be duplicated in Python, I just need to find some code samples on how > to construct a raw packet. > Try s = socket.socket( socket.AF_INET, socket.SOCK_RAW ) I tried this on windows and it needed admin privaleges to run. Rob. -- From peter at peaxy.net Tue Jan 22 20:21:27 2013 From: peter at peaxy.net (peter at peaxy.net) Date: Tue, 22 Jan 2013 17:21:27 -0800 (PST) Subject: Sending a broadcast message using raw sockets In-Reply-To: References: <0c2b3482-df46-4324-8bf9-2c45d3f6b516@googlegroups.com> <96947c45-f16b-4e97-b055-edc1241ee4a1@googlegroups.com> Message-ID: Yes, raw sockets need admin privileges, I knew that. The app I'm writing runs as root so that's not a problem. It runs during the %pre script stage of a kickstart controlled install. On Tuesday, January 22, 2013 1:58:07 PM UTC-8, Rob Williscroft wrote: > Try > > s = socket.socket( socket.AF_INET, socket.SOCK_RAW ) > > > > I tried this on windows and it needed admin privaleges to > > run. > > > > Rob. > > -- From sntshkmr60 at gmail.com Sat Jan 19 05:13:27 2013 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Sat, 19 Jan 2013 15:43:27 +0530 Subject: Any algorithm to preserve whitespaces? Message-ID: I have a working script which takes argv[1] as an input, deassembles each line, and then each word. Then after it capitalizes all its word (upcases the first letter) and then prints it out on the stdout. That script does the capitalization work fine, but, when it reassemble the the words, it does it like this: lines.append(' '.join(words)) The biggest problem is, even when the input file has many spaces, it strips it down to one. A file with this line: This line contains many spaces becomes: This Line Contains Many Spaces The whole script will look clumsy here. I have put it up on GitHub, here is it: https://github.com/santosh/capitalizr.py/blob/master/capitalizr From lie.1296 at gmail.com Sat Jan 19 05:26:52 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 19 Jan 2013 21:26:52 +1100 Subject: Any algorithm to preserve whitespaces? In-Reply-To: References: Message-ID: On 19/01/13 21:13, Santosh Kumar wrote: > I have a working script which takes argv[1] as an input, deassembles > each line, and then each word. Then after it capitalizes all its word > (upcases the first letter) and then prints it out on the stdout. > > That script does the capitalization work fine, but, when it reassemble > the the words, it does it like this: > > lines.append(' '.join(words)) > > The biggest problem is, even when the input file has many spaces, it > strips it down to one. replace: words = line.split() with: words = line.split(' ') > The whole script will look clumsy here. I have put it up on GitHub, > here is it: https://github.com/santosh/capitalizr.py/blob/master/capitalizr In general, when the script is just this short, it's better to put it directly on the message. From msirenef at lightbird.net Sat Jan 19 14:04:03 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sat, 19 Jan 2013 14:04:03 -0500 Subject: Any algorithm to preserve whitespaces? In-Reply-To: References: Message-ID: <50FAEE23.5030107@lightbird.net> On 01/19/2013 05:13 AM, Santosh Kumar wrote: > I have a working script which takes argv[1] as an input, deassembles > each line, and then each word. Then after it capitalizes all its word > (upcases the first letter) and then prints it out on the stdout. > > That script does the capitalization work fine, but, when it reassemble > the the words, it does it like this: > > lines.append(' '.join(words)) > > The biggest problem is, even when the input file has many spaces, it > strips it down to one. > > A file with this line: > > This line contains many spaces > becomes: > > This Line Contains Many Spaces > > > The whole script will look clumsy here. I have put it up on GitHub, > here is it: https://github.com/santosh/capitalizr.py/blob/master/capitalizr You know that mystr.title() can do this? - m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From sntshkmr60 at gmail.com Wed Jan 23 04:20:12 2013 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Wed, 23 Jan 2013 14:50:12 +0530 Subject: Any algorithm to preserve whitespaces? In-Reply-To: <50FAEE23.5030107@lightbird.net> References: <50FAEE23.5030107@lightbird.net> Message-ID: I am in a problem. words = line.split(' ') preserve whitespaces but the problem is it writes an additional line after every line. And: words = line.split() works as I expect (does not adds addition line after every line) but does not preserves whitespaces. From __peter__ at web.de Wed Jan 23 04:46:50 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 23 Jan 2013 10:46:50 +0100 Subject: Any algorithm to preserve whitespaces? References: <50FAEE23.5030107@lightbird.net> Message-ID: Santosh Kumar wrote: > I am in a problem. > > words = line.split(' ') > > preserve whitespaces but the problem is it writes an additional line > after every line. Strip off the newline at the end of the line with: line = line.rstrip("\n") words = line.split(" ") From d at davea.name Wed Jan 23 05:34:45 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 05:34:45 -0500 Subject: Any algorithm to preserve whitespaces? In-Reply-To: References: <50FAEE23.5030107@lightbird.net> Message-ID: <50FFBCC5.5020506@davea.name> On 01/23/2013 04:20 AM, Santosh Kumar wrote: > I am in a problem. > > words = line.split(' ') > > preserve whitespaces but the problem is it writes an additional line > after every line. > Think about what you said. It might be clearer if you wrote: "but the problem is it doesn't strip off the newline (which is whitespace)." You might want to fix it by doing an rstrip(), as Peter said, or you might want to check if the last character is \n, and delete it if so. Or you might want to fix the other logic where you use the reconstituted line, making sure it doesn't add an extra newline to a line that already has one. Best answer depends on whether there might be other whitespace at the end of the line, and on whether you consider the newline part of the last field on the line. Chances are that Peter's response is the one you want, but I had to point out that without a spec, we're really just guessing. For another example, suppose that some of the words in the file are separated by tabs. If so, perhaps you'd better rethink the whole split logic. -- DaveA From sntshkmr60 at gmail.com Wed Jan 23 09:56:55 2013 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Wed, 23 Jan 2013 20:26:55 +0530 Subject: Any algorithm to preserve whitespaces? In-Reply-To: <50FFBCC5.5020506@davea.name> References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: Yes, Peter got it right. Now, how can I replace: script, givenfile = argv with something better that takes argv[1] as input file as well as reads input from stdin. By input from stdin, I mean that currently when I do `cat foo.txt | capitalizr` it throws a ValueError error: Traceback (most recent call last): File "/home/santosh/bin/capitalizr", line 16, in script, givenfile = argv ValueError: need more than 1 value to unpack I want both input methods. From torriem at gmail.com Wed Jan 23 16:34:29 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 23 Jan 2013 14:34:29 -0700 Subject: Any algorithm to preserve whitespaces? In-Reply-To: References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: <51005765.1000703@gmail.com> On 01/23/2013 07:56 AM, Santosh Kumar wrote: > Yes, Peter got it right. > > Now, how can I replace: > > script, givenfile = argv > > with something better that takes argv[1] as input file as well as > reads input from stdin. > > By input from stdin, I mean that currently when I do `cat foo.txt | > capitalizr` it throws a ValueError error: > > Traceback (most recent call last): > File "/home/santosh/bin/capitalizr", line 16, in > script, givenfile = argv > ValueError: need more than 1 value to unpack > > I want both input methods. That's up to your program logic to do. Check to see if the arguments have been provided, and if not, open sys.stdin. It's quite common for command-line utilities to do this, but most of them use an explicit parameter '-' to indicate that you want the command to use standard-in. Again, you can code this any way you want. Personally I use one of the standard library command-line argument parsing modules, like optparse, but there are others that may be better. From __peter__ at web.de Wed Jan 23 17:04:02 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 23 Jan 2013 23:04:02 +0100 Subject: Any algorithm to preserve whitespaces? References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: Santosh Kumar wrote: > Yes, Peter got it right. > > Now, how can I replace: > > script, givenfile = argv > > with something better that takes argv[1] as input file as well as > reads input from stdin. > > By input from stdin, I mean that currently when I do `cat foo.txt | > capitalizr` it throws a ValueError error: > > Traceback (most recent call last): > File "/home/santosh/bin/capitalizr", line 16, in > script, givenfile = argv > ValueError: need more than 1 value to unpack > > I want both input methods. You can use argparse and its FileType: import argparse import sys parser = argparse.ArgumentParser() parser.add_argument("infile", type=argparse.FileType("r"), nargs="?", default=sys.stdin) args = parser.parse_args() for line in args.infile: print line.strip().title() # replace with your code As this has the small disadvantage that infile is opened immediately I tend to use a slight variation: import argparse import sys from contextlib import contextmanager @contextmanager def xopen(filename): if filename is None or filename == "-": yield sys.stdin else: with open(filename) as instream: yield instream parser = argparse.ArgumentParser() parser.add_argument("infile", nargs="?") args = parser.parse_args() with xopen(args.infile) as instream: for line in instream: print line.strip().title() From sntshkmr60 at gmail.com Thu Jan 24 04:19:24 2013 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Thu, 24 Jan 2013 14:49:24 +0530 Subject: Any algorithm to preserve whitespaces? In-Reply-To: References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: On 1/24/13, Peter Otten <__peter__ at web.de> wrote: > Santosh Kumar wrote: > >> Yes, Peter got it right. >> >> Now, how can I replace: >> >> script, givenfile = argv >> >> with something better that takes argv[1] as input file as well as >> reads input from stdin. >> >> By input from stdin, I mean that currently when I do `cat foo.txt | >> capitalizr` it throws a ValueError error: >> >> Traceback (most recent call last): >> File "/home/santosh/bin/capitalizr", line 16, in >> script, givenfile = argv >> ValueError: need more than 1 value to unpack >> >> I want both input methods. > > You can use argparse and its FileType: > > import argparse > import sys > > parser = argparse.ArgumentParser() > parser.add_argument("infile", type=argparse.FileType("r"), nargs="?", > default=sys.stdin) > args = parser.parse_args() > > for line in args.infile: > print line.strip().title() # replace with your code > This works file when I do `script.py inputfile.txt`; capitalizes as expected. But it work unexpected if I do `cat inputfile.txt | script.py`; leaves the first word of each line and then capitalizes remaining. From __peter__ at web.de Thu Jan 24 04:30:54 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 Jan 2013 10:30:54 +0100 Subject: Any algorithm to preserve whitespaces? References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: Santosh Kumar wrote: > On 1/24/13, Peter Otten <__peter__ at web.de> wrote: >> Santosh Kumar wrote: >> >>> Yes, Peter got it right. >>> >>> Now, how can I replace: >>> >>> script, givenfile = argv >>> >>> with something better that takes argv[1] as input file as well as >>> reads input from stdin. >>> >>> By input from stdin, I mean that currently when I do `cat foo.txt | >>> capitalizr` it throws a ValueError error: >>> >>> Traceback (most recent call last): >>> File "/home/santosh/bin/capitalizr", line 16, in >>> script, givenfile = argv >>> ValueError: need more than 1 value to unpack >>> >>> I want both input methods. >> >> You can use argparse and its FileType: >> >> import argparse >> import sys >> >> parser = argparse.ArgumentParser() >> parser.add_argument("infile", type=argparse.FileType("r"), nargs="?", >> default=sys.stdin) >> args = parser.parse_args() >> >> for line in args.infile: >> print line.strip().title() # replace with your code >> > > This works file when I do `script.py inputfile.txt`; capitalizes as > expected. But it work unexpected if I do `cat inputfile.txt | > script.py`; leaves the first word of each line and then capitalizes > remaining. I cannot reproduce that: $ cat title.py #!/usr/bin/env python import argparse import sys parser = argparse.ArgumentParser() parser.add_argument("infile", type=argparse.FileType("r"), nargs="?", default=sys.stdin) args = parser.parse_args() for line in args.infile: print line.strip().title() # replace with your code $ cat inputfile.txt alpha beta gamma delta epsilon zeta $ cat inputfile.txt | ./title.py Alpha Beta Gamma Delta Epsilon Zeta $ ./title.py inputfile.txt Alpha Beta Gamma Delta Epsilon Zeta From sntshkmr60 at gmail.com Thu Jan 24 05:09:09 2013 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Thu, 24 Jan 2013 15:39:09 +0530 Subject: Any algorithm to preserve whitespaces? In-Reply-To: References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: But I can; see: http://pastebin.com/ZGGeZ71r On 1/24/13, Peter Otten <__peter__ at web.de> wrote: > Santosh Kumar wrote: > >> On 1/24/13, Peter Otten <__peter__ at web.de> wrote: >>> Santosh Kumar wrote: >>> >>>> Yes, Peter got it right. >>>> >>>> Now, how can I replace: >>>> >>>> script, givenfile = argv >>>> >>>> with something better that takes argv[1] as input file as well as >>>> reads input from stdin. >>>> >>>> By input from stdin, I mean that currently when I do `cat foo.txt | >>>> capitalizr` it throws a ValueError error: >>>> >>>> Traceback (most recent call last): >>>> File "/home/santosh/bin/capitalizr", line 16, in >>>> script, givenfile = argv >>>> ValueError: need more than 1 value to unpack >>>> >>>> I want both input methods. >>> >>> You can use argparse and its FileType: >>> >>> import argparse >>> import sys >>> >>> parser = argparse.ArgumentParser() >>> parser.add_argument("infile", type=argparse.FileType("r"), nargs="?", >>> default=sys.stdin) >>> args = parser.parse_args() >>> >>> for line in args.infile: >>> print line.strip().title() # replace with your code >>> >> >> This works file when I do `script.py inputfile.txt`; capitalizes as >> expected. But it work unexpected if I do `cat inputfile.txt | >> script.py`; leaves the first word of each line and then capitalizes >> remaining. > > I cannot reproduce that: > > $ cat title.py > #!/usr/bin/env python > import argparse > import sys > > parser = argparse.ArgumentParser() > parser.add_argument("infile", type=argparse.FileType("r"), nargs="?", > default=sys.stdin) > args = parser.parse_args() > > for line in args.infile: > print line.strip().title() # replace with your code > $ cat inputfile.txt > alpha beta > gamma delta epsilon > zeta > $ cat inputfile.txt | ./title.py > Alpha Beta > Gamma Delta Epsilon > Zeta > $ ./title.py inputfile.txt > Alpha Beta > Gamma Delta Epsilon > Zeta > > > -- > http://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu Jan 24 05:47:03 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 Jan 2013 11:47:03 +0100 Subject: Any algorithm to preserve whitespaces? References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: Santosh Kumar wrote: > But I can; see: http://pastebin.com/ZGGeZ71r You have messed with your cat command -- it adds line numbers. Therefore the output of cat somefile | ./argpa.py differs from ./argpa.py somefile Try ./argpa.py < somefile to confirm my analysis. As to why your capitalisation algorithm fails on those augmented lines: the number is separated from the rest of the line by a TAB -- therefore the first word is "1\tthis" and the only candidate to be capitalised is the "1". To fix this you could use regular expressions (which I wanted to avoid initially): >>> parts = re.compile("(\s+)").split(" 1\tthis is it") >>> parts ['', ' ', '1', '\t', 'this', ' ', 'is', ' ', 'it'] Process every other part as you wish and then join all parts: >>> parts[::2] = [s.upper() for s in parts[::2]] >>> parts ['', ' ', '1', '\t', 'THIS', ' ', 'IS', ' ', 'IT'] >>> print "".join(parts) 1 THIS IS IT From steve+comp.lang.python at pearwood.info Wed Jan 23 19:49:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 24 Jan 2013 11:49:59 +1100 Subject: Any algorithm to preserve whitespaces? References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> Message-ID: <51008538$0$29992$c3e8da3$5496439d@news.astraweb.com> Santosh Kumar wrote: > Yes, Peter got it right. Peter? Which Peter? What's "it" that he got right? You have deleted all context from your post, so I have no idea what you are talking about. And whatever program you are using to post is stripping out threading information, so I can't tell what post you are replying to. Please take careful note of the posting conventions used by the experienced regulars on this forum, and copy their style. That is for your benefit as well as ours. > Now, how can I replace: > > script, givenfile = argv > > with something better that takes argv[1] as input file as well as > reads input from stdin. > > By input from stdin, I mean that currently when I do `cat foo.txt | > capitalizr` it throws a ValueError error: > > Traceback (most recent call last): > File "/home/santosh/bin/capitalizr", line 16, in > script, givenfile = argv > ValueError: need more than 1 value to unpack > > I want both input methods. The usual convention in Unix and Linux is that if the file name is "-", read from stdin instead. Something like this, untested: givenfile = sys.argv[1] if givenfile == '-': data = sys.stdin.read() else: data = open(givenfile).read() Adding error checking etc. is left as an exercise. -- Steven From d at davea.name Wed Jan 23 21:05:59 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 21:05:59 -0500 Subject: Any algorithm to preserve whitespaces? In-Reply-To: <51008538$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <50FAEE23.5030107@lightbird.net> <50FFBCC5.5020506@davea.name> <51008538$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51009707.30903@davea.name> On 01/23/2013 07:49 PM, Steven D'Aprano wrote: > Santosh Kumar wrote: > >> Yes, Peter got it right. > > Peter? Which Peter? What's "it" that he got right? > > You have deleted all context from your post, so I have no idea what you are > talking about. Right. > And whatever program you are using to post is stripping out > threading information, so I can't tell what post you are replying to. You're not entirely right here. Santosh's message threads correctly to mine when I look with Thunderbird. And mine is parallel to one by Peter Otten, who suggested rstrip() to get rid of the extra newline. About 10% of your posts show up as top-level (starting new threads), even though I know you're careful. So there seem to be more than one threading protocol, and the multiple protocols are fighting each other. I'd love to see a spec that I could use to (manually?) check whether the threads are right or not. the relevant timestamps (at least as seen from USA EST zone) are Santosh at 4:20 am Peter Otten at 4:46 am DaveA at 5:34 am Santosh at 9:56 am Steven D'Aprano at 7:49 pm But your message was a reply to Santosh's 9:56 am message. (I'm deleting the rest, because I'm not responding to the commandline parsing question) -- DaveA From jt at toerring.de Sat Jan 19 09:47:16 2013 From: jt at toerring.de (Jens Thoms Toerring) Date: 19 Jan 2013 14:47:16 GMT Subject: Messing with the GC Message-ID: Hi, triggered by some problems I had with PySide I got a bit confused about what the GC may do in certain situations. Here's a small test program I cobbled together: import sys class X( object ) : def __init__( self, parent, cnt ) : print( "In constructor for {0} {1}".format( self, cnt ), file = sys.stderr ) self.parent = parent self.cnt = cnt def __del__( self ) : print( "In destructor for {0} {1}".format( self, self.cnt ), file = sys.stderr ) def foo( self ) : print( "Before", file = sys.stderr ) self.parent.z = X( self.parent, 2 ) # Is this bad? print( "After", file = sys.stderr ) class Y( object ) : def __init__( self ) : print( "In constructor for {0}".format( self ), file = sys.stderr ) self.z = X( self, 1 ) def __del__( self ) : print( "In destructor for {0}".format( self ), file = sys.stderr ) Y( ).z.foo( ) Have a look at the line with the comment. At this point the only reference in existence to the X class instance, of which a method is just being executed, goes out of scope. Thus I would assume that the GC could now kick any time, possibly even before the following call of print() or before the method call returns. That, in turn might result in a crash of the script. Is my assumption about this flawed and there are no potential dangers? Perhaps with Y( ).z.foo( ) a temporary second reference is created that keeps the GC for removing the X instance... Another thing I'm puzzled about is the output of the script: In constructor for <__main__.Y object at 0x2919210> In constructor for <__main__.X object at 0x2919310> 1 Before In constructor for <__main__.X object at 0x2919350> 2 After In destructor for <__main__.X object at 0x2919310> 1 Ok, the destrucor for the first instance of the X class is called only after printing out "After", so the GC didn't delete the object before. But then there are obviously no calls of the destructors of neither the second instance of the X class nor of the Y class instance. Shouldn't they be invoked before the program ends? Thanks and best regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From steve+comp.lang.python at pearwood.info Sat Jan 19 11:24:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2013 16:24:37 GMT Subject: Messing with the GC References: Message-ID: <50fac8c5$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 19 Jan 2013 14:47:16 +0000, Jens Thoms Toerring wrote: > Ok, the destrucor for the first instance of the X class is called only > after printing out "After", so the GC didn't delete the object before. > But then there are obviously no calls of the destructors of neither the > second instance of the X class nor of the Y class instance. Shouldn't > they be invoked before the program ends? You should avoid __del__ destructors whenever not absolutely necessary. __del__ may not be called for objects that still exist when Python exits. If you have a cycle of objects, and *any* of them have a __del__ method, it may be impossible for Python to work out a safe order for them to be deleted. Consequently they will never be reclaimed by the garbage collector. http://docs.python.org/2/reference/datamodel.html#special-method-names http://docs.python.org/2/library/gc.html#gc.garbage -- Steven From steve+comp.lang.python at pearwood.info Sat Jan 19 11:34:53 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2013 16:34:53 GMT Subject: Messing with the GC References: <50fac8c5$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50facb2d$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 19 Jan 2013 16:24:37 +0000, Steven D'Aprano wrote: > On Sat, 19 Jan 2013 14:47:16 +0000, Jens Thoms Toerring wrote: > >> Ok, the destrucor for the first instance of the X class is called only >> after printing out "After", so the GC didn't delete the object before. >> But then there are obviously no calls of the destructors of neither the >> second instance of the X class nor of the Y class instance. Shouldn't >> they be invoked before the program ends? > > You should avoid __del__ destructors whenever not absolutely necessary. And here is another opinion: you should avoid cycles, rather the __del__. http://eli.thegreenplace.net/2009/06/12/safely-using-destructors-in-python/ -- Steven From tjreedy at udel.edu Sat Jan 19 11:40:28 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 19 Jan 2013 11:40:28 -0500 Subject: Messing with the GC In-Reply-To: References: Message-ID: On 1/19/2013 9:47 AM, Jens Thoms Toerring wrote: The code comments mostly answer your questions about what happens or does not happen and when. The comments after add more detail. > import sys > > class X( object ) : > def __init__( self, parent, cnt ) : > print( "In constructor for {0} {1}".format( self, cnt ), > file = sys.stderr ) > self.parent = parent > self.cnt = cnt > > def __del__( self ) : > print( "In destructor for {0} {1}".format( self, self.cnt ), > file = sys.stderr ) > > def foo( self ) : At this point, self is self.parent.z, which is to say, self and self.parent.z are 2 references to 1 object. The self and self.parent object refer to each other and therefore constitute a reference cycle. > print( "Before", file = sys.stderr ) > self.parent.z = X( self.parent, 2 ) # Is this bad? At this point, self.parent.z is another instance of X, breaking the existing reference cycle *and* creating a new one. Now self has just the one reference 'self' (plus another non-circular, hidden one, see below#). > print( "After", file = sys.stderr ) At this point, self goes out of scope, the CPython reference count goes to 0, and the object that was self is deleted. Other implementations typically wait longer to delete. > class Y( object ) : > def __init__( self ) : > print( "In constructor for {0}".format( self ), > file = sys.stderr ) > self.z = X( self, 1 ) At this point, self is self.z.parent, where z is an X. This is a circular reference: self and self.z reference each other. > def __del__( self ) : > print( "In destructor for {0}".format( self ), > file = sys.stderr ) > > Y( ).z.foo( ) Y() creates a reference cycle. z.foo() substitute a different instance of X in the cycle but there still is a cycle, so the Y and X objects have reference counts of 1. There are no other references to the two objects, making them unreachable and 'dead' to the program. The cyclic reference garbage collector (see the gc module doc) that is meant to delete such orphans does not delete them here because of the __del__ methods. Since gc was added, __del__ is semi-obsolete. If an object might possibly be put in a reference cycle (which is quite easy), any code that might have been put in __del__ should go in an explicitly called .close() method. > Have a look at the line with the comment. At this point the > only reference in existence to the X class instance, of which > a method is just being executed, goes out of scope. Nope, the remaining reference, 'self', stays in scope until after the function exits. That is when X1 is deleted and the deletion message printed. > Is my assumption about this flawed Yes > and there are no potential dangers? The orphaned two-object cycle constitutes a memory leak. If you called Y( ).z.foo( ) a million times, you would have a million useless pairs of objects. This is why gc was added. > Y( ).z.foo( ) > > [perhaps] a temporary second reference is created that keeps the GC > for removing the X instance... Function calls (normally) bind argument object to parameter names in the function's local namespace. That binding is a temporary reference and objects will not disappear in the middle of the call. # In CPython, at least, there is another internal reference to arguments that also disappears when the function returns, allowing the deletion of arguments without other references. >>> x = 12343252 # random large number to make sure its a new object >>> sys.getrefcount(x) 2 >>> def f(a): print(sys.getrefcount(a)) >>> f(x) 4 So print(sys.getrefcount(self)) at the top of foo prints 4 (3+1), rather than 3 (2+1), as one might expect. The +1 is explained in the doc sys.getrefcount(obj): Return the reference count of the object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to getrefcount(). (Why doesn't getrefcount add 2 instead of 1, as f seems to? I don't know, but perhaps because it is written in C rather than Python and Python code objects are different from C code.) -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Jan 19 11:44:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2013 16:44:04 GMT Subject: Messing with the GC References: Message-ID: <50facd53$0$30003$c3e8da3$5496439d@news.astraweb.com> And further thoughts... On Sat, 19 Jan 2013 14:47:16 +0000, Jens Thoms Toerring wrote: > Hi, > > triggered by some problems I had with PySide I got a bit > confused about what the GC may do in certain situations. Here's a small > test program I cobbled together: > > import sys > > class X( object ) : > def __init__( self, parent, cnt ) : > print( "In constructor for {0} {1}".format( self, cnt ), > file = sys.stderr ) > self.parent = parent > self.cnt = cnt > > def __del__( self ) : > print( "In destructor for {0} {1}".format( self, self.cnt ), > file = sys.stderr ) > > def foo( self ) : > print( "Before", file = sys.stderr ) > self.parent.z = X( self.parent, 2 ) # Is this bad? > print( "After", file = sys.stderr ) > > class Y( object ) : > def __init__( self ) : > print( "In constructor for {0}".format( self ), > file = sys.stderr ) > self.z = X( self, 1 ) > > def __del__( self ) : > print( "In destructor for {0}".format( self ), > file = sys.stderr ) > > Y( ).z.foo( ) > > Have a look at the line with the comment. You mean this line? self.parent.z = X( self.parent, 2 ) # Is this bad? > At this point the only > reference in existence to the X class instance, of which a method is > just being executed, goes out of scope. I don't understand this, but to the extent that I do understand it, I think you are wrong. What do you mean, "the X class instance"? If you mean the class X itself, no, that survives until both the class itself is deleted and every one of it's instances. If you mean "self", no, that doesn't get deleted by that line at all. > Thus I would assume that the GC > could now kick any time, possibly even before the following call of > print() or before the method call returns. That, in turn might result in > a crash of the script. It would be a pretty crappy garbage collector that collected objects while they were still being used. > Is my assumption about this flawed and there are no potential dangers? > Perhaps with > > Y( ).z.foo( ) > > a temporary second reference is created that keeps the GC for removing > the X instance... I'm not even sure what X instance you are referring to, or why you think it is going out of scope. -- Steven From jt at toerring.de Sun Jan 20 15:09:32 2013 From: jt at toerring.de (Jens Thoms Toerring) Date: 20 Jan 2013 20:09:32 GMT Subject: Messing with the GC References: Message-ID: Hi, thank you for the explanations. I had overlooked the cyclic nature of what I had produced here and, of course, the GC can't be blamed for not collecting objects that are part of a cycle. The other question about the last refe- rence to an object vanishing within a method call (which, as I now clearly understand, can't happen and wouldn't make much sense) was triggered by a segmentation fault I get when I do something similar in PySide, so I was getting worried if it might be due to a GC issue. Now I know its got to be something different;-) Thanks and best regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From tjreedy at udel.edu Sun Jan 20 17:14:43 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 Jan 2013 17:14:43 -0500 Subject: Messing with the GC In-Reply-To: References: Message-ID: On 1/20/2013 3:09 PM, Jens Thoms Toerring wrote: > thank you for the explanations. I had overlooked the > cyclic nature of what I had produced here and, of course, > the GC can't be blamed for not collecting objects that are > part of a cycle. The other question about the last refe- > rence to an object vanishing within a method call (which, > as I now clearly understand, can't happen and wouldn't make > much sense) was triggered by a segmentation fault I get > when I do something similar in PySide, so I was getting > worried if it might be due to a GC issue. Now I know its > got to be something different;-) Perhaps the hardest part of writing C extensions to CPython directly in C (versus something like Cython) is properly balancing increfs and decrefs. An incref without a later decref can lead to a memory leak. A decref without a preceding incref (so CPython thinks the object can be deleted, when it should not be) can lead to segfaults. So I would report PySide code leading to segfaults to the PySide people. -- Terry Jan Reedy From jt at toerring.de Sun Jan 20 20:02:22 2013 From: jt at toerring.de (Jens Thoms Toerring) Date: 21 Jan 2013 01:02:22 GMT Subject: Messing with the GC References: Message-ID: Terry Reedy wrote: > On 1/20/2013 3:09 PM, Jens Thoms Toerring wrote: > > thank you for the explanations. I had overlooked the > > cyclic nature of what I had produced here and, of course, > > the GC can't be blamed for not collecting objects that are > > part of a cycle. The other question about the last refe- > > rence to an object vanishing within a method call (which, > > as I now clearly understand, can't happen and wouldn't make > > much sense) was triggered by a segmentation fault I get > > when I do something similar in PySide, so I was getting > > worried if it might be due to a GC issue. Now I know its > > got to be something different;-) > Perhaps the hardest part of writing C extensions to CPython directly in > C (versus something like Cython) is properly balancing increfs and > decrefs. An incref without a later decref can lead to a memory leak. A > decref without a preceding incref (so CPython thinks the object can be > deleted, when it should not be) can lead to segfaults. Definitely - I got started with Python having to write glue code to get Python to work with a C++ library. And keeping track of which side thinks it owns an object can sometimes be a bit of a challenge... > So I would report PySide code leading to segfaults to the > PySide people. Now that I'm more sure that it's unlikely to be a Python GC related issue (or my not understanding what I'm doing, to be precise) this is on my to-do list. But first I have to distill things down to a very short example program still exhibiting the problem - and experience tells me that this will most li- kely result in the realization that it's not a PySide issue at all but some misunderstanding on my side;-) Best regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From subhabangalore at gmail.com Sat Jan 19 13:50:13 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 19 Jan 2013 10:50:13 -0800 (PST) Subject: Question on Python Conference Message-ID: <1506a9c3-7abb-4360-91f1-f656311043af@googlegroups.com> Dear Group, As I know Python Foundation organizes some conferences all through the year. Most probably they are known as Pycon. But I have some different question. The question is, is it possible to attend it by Video Conferencing? Or if I request for the same will it be granted? Regards, Subhabrata. From nad at acm.org Sat Jan 19 16:12:11 2013 From: nad at acm.org (Ned Deily) Date: Sat, 19 Jan 2013 13:12:11 -0800 Subject: Question on Python Conference References: <1506a9c3-7abb-4360-91f1-f656311043af@googlegroups.com> Message-ID: In article <1506a9c3-7abb-4360-91f1-f656311043af at googlegroups.com>, subhabangalore at gmail.com wrote: > As I know Python Foundation organizes some conferences all through the year. > Most probably they are known as Pycon. But I have some different question. > The question is, is it possible to attend it by Video Conferencing? Or if I > request for the same will it be granted? As far as I know, there is no live video conferencing from PyCon. However, nearly all sessions at recent PyCons are recorded and made available on the web. The videos from the 2012 PyCon are here: http://pyvideo.org/category/17/pycon-us-2012 -- Ned Deily, nad at acm.org From steve+comp.lang.python at pearwood.info Sat Jan 19 21:59:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Jan 2013 02:59:45 GMT Subject: How do functions get access to builtins? Message-ID: <50fb5da1$0$30003$c3e8da3$5496439d@news.astraweb.com> I've been playing around with ChainedMap in Python 3.3, and run into something which perplexes me. Let's start with an ordinary function that accesses one global and one builtin. x = 42 def f(): print(x) If you call f(), it works as expected. But let's make a version with no access to builtins, and watch it break: from types import FunctionType g = FunctionType(f.__code__, {'x': 23}) If you call g(), you get an exception: py> g() Traceback (most recent call last): File "", line 1, in File "", line 2, in f NameError: global name 'print' is not defined (Don't be fooled by the traceback referring to "f" rather than g. That's because g's code was copied from f.) We can add support for builtins: import builtins # use __builtin__ with no "s" in Python 2 g.__globals__['__builtins__'] = builtins # Note the "s" in the key. and now calling g() prints 23, as expected. Now let me try the same thing using Python 3.3's ChainMap. Unfortunately, functions insist that their __global__ is a dict, so we fool it into accepting a ChainMap with some multiple inheritance trickery: from collections import ChainMap class ChainedDict(ChainMap, dict): pass d = ChainedDict({}, {'x': 23}, {'x': 42}) assert d['x'] == 23 g = FunctionType(f.__code__, d) As before, calling g() raises NameError, "global name 'print' is not defined". So I expected to be able to fix it just as I did before: g.__globals__['__builtins__'] = builtins But it doesn't work -- I still get the same NameError. Why does this not work here, when it works for a regular dict? I can fix it by adding the builtins into the ChainMap: g.__globals__.maps.append(builtins.__dict__) And now calling g() prints 23 as expected. -- Steven From rouslank at msn.com Sun Jan 20 20:02:04 2013 From: rouslank at msn.com (Rouslan Korneychuk) Date: Sun, 20 Jan 2013 20:02:04 -0500 Subject: How do functions get access to builtins? In-Reply-To: <50fb5da1$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50fb5da1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/19/2013 09:59 PM, Steven D'Aprano wrote: > I've been playing around with ChainedMap in Python 3.3, and run into > something which perplexes me. Let's start with an ordinary function that > accesses one global and one builtin. > > > x = 42 > def f(): > print(x) > > > If you call f(), it works as expected. But let's make a version with no > access to builtins, and watch it break: > > from types import FunctionType > g = FunctionType(f.__code__, {'x': 23}) > > > If you call g(), you get an exception: > > py> g() > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in f > NameError: global name 'print' is not defined > > > (Don't be fooled by the traceback referring to "f" rather than g. > That's because g's code was copied from f.) > > We can add support for builtins: > > import builtins # use __builtin__ with no "s" in Python 2 > g.__globals__['__builtins__'] = builtins # Note the "s" in the key. > > > and now calling g() prints 23, as expected. > > Now let me try the same thing using Python 3.3's ChainMap. Unfortunately, > functions insist that their __global__ is a dict, so we fool it into > accepting a ChainMap with some multiple inheritance trickery: > > > from collections import ChainMap > class ChainedDict(ChainMap, dict): > pass > > d = ChainedDict({}, {'x': 23}, {'x': 42}) > assert d['x'] == 23 > g = FunctionType(f.__code__, d) > > > As before, calling g() raises NameError, "global name 'print' is not > defined". So I expected to be able to fix it just as I did before: > > g.__globals__['__builtins__'] = builtins > > > But it doesn't work -- I still get the same NameError. Why does this not > work here, when it works for a regular dict? > I found the answer in Python's source code. When you execute a code object, PyFrame_New is called which gets 'bultins' from 'globals', but inside PyFrame_New (defined on line 596 of Objects/frameobject.c) is the following (line 613): builtins = PyDict_GetItem(globals, builtin_object); Unlike PyObject_GetItem, PyDict_GetItem is specialized for dict objects. Your ChainedDict class uses ChainMaps's storage and leaves dict's storage empty, so PyDict_GetItem doesn't find anything. > I can fix it by adding the builtins into the ChainMap: > > g.__globals__.maps.append(builtins.__dict__) > > > And now calling g() prints 23 as expected. > The reason this works is unlike PyFrame_New, the LOAD_GLOBAL opcode first checks if globals' type is dict (and not a subclass), and falls back to using PyObject_GetItem if it's anything else. Interestingly: it looks like it could be fixed easily enough. Unless there are other places where globals is assumed to be a dict object, it would just be a matter of doing the same check and fallback in PyFrame_New that is done in LOAD_GLOBAL (technically, you could just use PyObject_GetItem; obviously, this is an optimization). From steve+comp.lang.python at pearwood.info Thu Jan 24 06:31:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 24 Jan 2013 22:31:06 +1100 Subject: How do functions get access to builtins? References: <50fb5da1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51011b7b$0$29976$c3e8da3$5496439d@news.astraweb.com> Rouslan Korneychuk wrote: > I found the answer in Python's source code. When you execute a code > object, PyFrame_New is called which gets 'bultins' from 'globals', but > inside PyFrame_New (defined on line 596 of Objects/frameobject.c) is the > following (line 613): > > builtins = PyDict_GetItem(globals, builtin_object); > > Unlike PyObject_GetItem, PyDict_GetItem is specialized for dict objects. > Your ChainedDict class uses ChainMaps's storage and leaves dict's > storage empty, so PyDict_GetItem doesn't find anything. [...] > Interestingly: it looks like it could be fixed easily enough. Unless > there are other places where globals is assumed to be a dict object, it > would just be a matter of doing the same check and fallback in > PyFrame_New that is done in LOAD_GLOBAL (technically, you could just use > PyObject_GetItem; obviously, this is an optimization). Thanks for the reply Rouslan. Perhaps I should report this as a bug. -- Steven From redstone-cold at 163.com Sun Jan 20 04:17:34 2013 From: redstone-cold at 163.com (iMath) Date: Sun, 20 Jan 2013 01:17:34 -0800 (PST) Subject: To make a method or attribute private Message-ID: <8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com> To make a method or attribute private (inaccessible from the outside), simply start its name with two underscores ----?Beginning Python From Novice to Professional? but there is another saying goes: Beginning a variable name with a single underscore indicates that the variable should be treated as ?private?. I test both these 2 rules ,it seems only names that start with two underscores are REAL private methods or attributes . >>> class A: ... def __init__(self): ... self.a = 'a' ... self._a = '_a' ... self.__a = '__a' ... >>> ap = A() >>> ap.a 'a' >>> ap._a '_a' >>> ap.__a Traceback (most recent call last): File "", line 1, in ? AttributeError: A instance has no attribute '__a' so what is your opinion about single leading underscore and private methods or attributes? From rosuav at gmail.com Sun Jan 20 04:23:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Jan 2013 20:23:18 +1100 Subject: To make a method or attribute private In-Reply-To: <8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com> References: <8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com> Message-ID: On Sun, Jan 20, 2013 at 8:17 PM, iMath wrote: > so what is your opinion about single leading underscore and private methods or attributes? Didn't this get discussed recently? http://mail.python.org/pipermail/python-list/2013-January/638687.html ChrisA From wuwei23 at gmail.com Sun Jan 20 18:14:40 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 Jan 2013 15:14:40 -0800 (PST) Subject: To make a method or attribute private References: <8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com> Message-ID: <350446de-b601-4ff8-96e4-9f9a5674c48e@sb6g2000pbb.googlegroups.com> On Jan 20, 7:23?pm, Chris Angelico wrote: > On Sun, Jan 20, 2013 at 8:17 PM, iMath wrote: > > so what is your opinion about single leading underscore and private methods or attributes? > > Didn't this get discussed recently? > > http://mail.python.org/pipermail/python-list/2013-January/638687.html > > ChrisA Isn't that a link to the same post that started this thread? :) From d at davea.name Sun Jan 20 18:32:49 2013 From: d at davea.name (Dave Angel) Date: Sun, 20 Jan 2013 18:32:49 -0500 Subject: To make a method or attribute private In-Reply-To: <350446de-b601-4ff8-96e4-9f9a5674c48e@sb6g2000pbb.googlegroups.com> References: <8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com> <350446de-b601-4ff8-96e4-9f9a5674c48e@sb6g2000pbb.googlegroups.com> Message-ID: <50FC7EA1.8000008@davea.name> On 01/20/2013 06:14 PM, alex23 wrote: > On Jan 20, 7:23 pm, Chris Angelico wrote: >> On Sun, Jan 20, 2013 at 8:17 PM, iMath wrote: >>> so what is your opinion about single leading underscore and private methods or attributes? >> >> Didn't this get discussed recently? >> >> http://mail.python.org/pipermail/python-list/2013-January/638687.html >> >> ChrisA > > Isn't that a link to the same post that started this thread? :) > No, that's the one that started the earlier thread, by the same name, three whole days ago. iMath posted an apparently complete duplicate of his earlier message. -- DaveA From wuwei23 at gmail.com Sun Jan 20 21:24:32 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 Jan 2013 18:24:32 -0800 (PST) Subject: To make a method or attribute private References: <8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com> <350446de-b601-4ff8-96e4-9f9a5674c48e@sb6g2000pbb.googlegroups.com> Message-ID: <5a502e5a-9912-4584-bcad-4c00ca350da5@qi8g2000pbb.googlegroups.com> On Jan 21, 9:32?am, Dave Angel wrote: > On 01/20/2013 06:14 PM, alex23 wrote: > > > On Jan 20, 7:23 pm, Chris Angelico wrote: > >> On Sun, Jan 20, 2013 at 8:17 PM, iMath wrote: > >>> so what is your opinion about single leading underscore and private methods or attributes? > > >> Didn't this get discussed recently? > > >>http://mail.python.org/pipermail/python-list/2013-January/638687.html > > >> ChrisA > > > Isn't that a link to the same post that started this thread? :) > > No, that's the one that started the earlier thread, by the same name, > three whole days ago. ?iMath posted an apparently complete duplicate of > his earlier message. The link is to a post of the same date as the original of this thread, and the very first response is mine, same as with this thread. I'm still not seeing the dupe? From msirenef at lightbird.net Sun Jan 20 21:45:00 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 20 Jan 2013 21:45:00 -0500 Subject: To make a method or attribute private In-Reply-To: <5a502e5a-9912-4584-bcad-4c00ca350da5@qi8g2000pbb.googlegroups.com> References: <8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com> <350446de-b601-4ff8-96e4-9f9a5674c48e@sb6g2000pbb.googlegroups.com> <5a502e5a-9912-4584-bcad-4c00ca350da5@qi8g2000pbb.googlegroups.com> Message-ID: <50FCABAC.4000908@lightbird.net> On 01/20/2013 09:24 PM, alex23 wrote: > On Jan 21, 9:32 am, Dave Angel wrote: >> On 01/20/2013 06:14 PM, alex23 wrote: >> >>> On Jan 20, 7:23 pm, Chris Angelico wrote: >>>> On Sun, Jan 20, 2013 at 8:17 PM, iMath wrote: >>>>> so what is your opinion about single leading underscore and private methods or attributes? >> >>>> Didn't this get discussed recently? >> >>>> http://mail.python.org/pipermail/python-list/2013-January/638687.html >> >>>> ChrisA >> >>> Isn't that a link to the same post that started this thread? :) >> >> No, that's the one that started the earlier thread, by the same name, >> three whole days ago. iMath posted an apparently complete duplicate of >> his earlier message. > > The link is to a post of the same date as the original of this thread, > and the very first response is mine, same as with this thread. I'm > still not seeing the dupe? I do see the duplicate in my reader.. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ To knock a thing down, especially if it is cocked at an arrogant angle, is a deep delight of the blood. George Santayana From warem2888 at gmail.com Sun Jan 20 09:00:56 2013 From: warem2888 at gmail.com (Constantine) Date: Sun, 20 Jan 2013 06:00:56 -0800 (PST) Subject: Its So Fucking Big Message-ID: Its So Fucking Big http://t.co/zSgyOAuF From ggkraemer at gmail.com Sun Jan 20 17:04:39 2013 From: ggkraemer at gmail.com (Garry) Date: Sun, 20 Jan 2013 14:04:39 -0800 (PST) Subject: RE Help splitting CVS data Message-ID: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> I'm trying to manipulate family tree data using Python. I'm using linux and Python 2.7.3 and have data files saved as Linux formatted cvs files The data appears in this format: Marriage,Husband,Wife,Date,Place,Source,Note0x0a Note: the Source field or the Note field can contain quoted data (same as the Place field) Actual data: [F0244],[I0690],[I0354],1916-06-08,"Neely's Landing, Cape Gir. Co, MO",,0x0a [F0245],[I0692],[I0355],1919-09-04,"Cape Girardeau Co, MO",,0x0a code snippet follows: import os import re #I'm using the following regex in an attempt to decode the data: RegExp2 = "^(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\d{,4}\-\d{,2}\-\d{,2})\,(.*|\".*\")\,(.*|\".*\")\,(.*|\".*\")" # line = "[F0244],[I0690],[I0354],1916-06-08,\"Neely's Landing, Cape Gir. Co, MO\",," # (Marriage,Husband,Wife,Date,Place,Source,Note) = re.split(RegExp2,line) # #However, this does not decode the 7 fields. # The following error is displayed: Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack # # When I use xx the fields apparently get unpacked. xx = re.split(RegExp2,line) # >>> print xx[0] >>> print xx[1] [F0244] >>> print xx[5] "Neely's Landing, Cape Gir. Co, MO" >>> print xx[6] >>> print xx[7] >>> print xx[8] Why is there an extra NULL field before and after my record contents? I'm stuck, comments and solutions greatly appreciated. Garry From msirenef at lightbird.net Sun Jan 20 17:14:30 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 20 Jan 2013 17:14:30 -0500 Subject: RE Help splitting CVS data In-Reply-To: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> Message-ID: <50FC6C46.1010001@lightbird.net> On 01/20/2013 05:04 PM, Garry wrote: > I'm trying to manipulate family tree data using Python. > I'm using linux and Python 2.7.3 and have data files saved as Linux formatted cvs files > The data appears in this format: > > Marriage,Husband,Wife,Date,Place,Source,Note0x0a > Note: the Source field or the Note field can contain quoted data (same as the Place field) > > Actual data: > [F0244],[I0690],[I0354],1916-06-08,"Neely's Landing, Cape Gir. Co, MO",,0x0a > [F0245],[I0692],[I0355],1919-09-04,"Cape Girardeau Co, MO",,0x0a > > code snippet follows: > > import os > import re > #I'm using the following regex in an attempt to decode the data: > RegExp2 = "^(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\d{,4}\-\d{,2}\-\d{,2})\,(.*|\".*\")\,(.*|\".*\")\,(.*|\".*\")" > # > line = "[F0244],[I0690],[I0354],1916-06-08,\"Neely's Landing, Cape Gir. Co, MO\",," > # > (Marriage,Husband,Wife,Date,Place,Source,Note) = re.split(RegExp2,line) > # > #However, this does not decode the 7 fields. > # The following error is displayed: > Traceback (most recent call last): > File "", line 1, in > ValueError: too many values to unpack > # > # When I use xx the fields apparently get unpacked. > xx = re.split(RegExp2,line) > # >>>> print xx[0] >>>> print xx[1] > [F0244] >>>> print xx[5] > "Neely's Landing, Cape Gir. Co, MO" >>>> print xx[6] >>>> print xx[7] >>>> print xx[8] > Why is there an extra NULL field before and after my record contents? > I'm stuck, comments and solutions greatly appreciated. > > Garry > Gosh, you really don't want to use regex to split csv lines like that.... Use csv module: >>> s '[F0244],[I0690],[I0354],1916-06-08,"Neely\'s Landing, Cape Gir. Co, MO",,0x0a' >>> import csv >>> r = csv.reader([s]) >>> for l in r: print(l) ... ['[F0244]', '[I0690]', '[I0354]', '1916-06-08', "Neely's Landing, Cape Gir. Co, MO", '', '0x0a'] the arg to csv.reader can be the file object (or a list of lines). - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From tjreedy at udel.edu Sun Jan 20 17:16:21 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 Jan 2013 17:16:21 -0500 Subject: RE Help splitting CVS data In-Reply-To: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> Message-ID: On 1/20/2013 5:04 PM, Garry wrote: > I'm trying to manipulate family tree data using Python. > I'm using linux and Python 2.7.3 and have data files saved as Linux formatted cvs files ... > I'm stuck, comments and solutions greatly appreciated. Why are you not using the cvs module? -- Terry Jan Reedy From python.list at tim.thechases.com Sun Jan 20 19:10:04 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 20 Jan 2013 18:10:04 -0600 Subject: RE Help splitting CVS data In-Reply-To: References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> Message-ID: <50FC875C.1070202@tim.thechases.com> On 01/20/13 16:16, Terry Reedy wrote: > On 1/20/2013 5:04 PM, Garry wrote: >> I'm trying to manipulate family tree data using Python. >> I'm using linux and Python 2.7.3 and have data files saved as Linux formatted cvs files > ... >> I'm stuck, comments and solutions greatly appreciated. > > Why are you not using the cvs module? that's an easy answer: >>> import cvs Traceback (most recent call last): File "", line 1, in ImportError: No module named cvs Now the *csv* module... ;-) -tkc From d at davea.name Sun Jan 20 17:21:33 2013 From: d at davea.name (Dave Angel) Date: Sun, 20 Jan 2013 17:21:33 -0500 Subject: Help splitting CVS data In-Reply-To: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> Message-ID: <50FC6DED.4090200@davea.name> On 01/20/2013 05:04 PM, Garry wrote: > I'm trying to manipulate family tree data using Python. > I'm using linux and Python 2.7.3 and have data files saved as Linux formatted cvs files > The data appears in this format: > > Marriage,Husband,Wife,Date,Place,Source,Note0x0a > Note: the Source field or the Note field can contain quoted data (same as the Place field) > > Actual data: > [F0244],[I0690],[I0354],1916-06-08,"Neely's Landing, Cape Gir. Co, MO",,0x0a > [F0245],[I0692],[I0355],1919-09-04,"Cape Girardeau Co, MO",,0x0a > > code snippet follows: > > import os > import re > #I'm using the following regex in an attempt to decode the data: > RegExp2 = "^(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\d{,4}\-\d{,2}\-\d{,2})\,(.*|\".*\")\,(.*|\".*\")\,(.*|\".*\")" > # Well, you lost me about there. For a csv file, why not use the csv module: import csv ifile = open('test.csv', "rb") reader = csv.reader(ifile) For reference, see http://docs.python.org/2/library/csv.html and for sample use and discussion, see http://www.linuxjournal.com/content/handling-csv-files-python -- DaveA From roy at panix.com Sun Jan 20 19:00:50 2013 From: roy at panix.com (Roy Smith) Date: Sun, 20 Jan 2013 19:00:50 -0500 Subject: RE Help splitting CVS data References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> Message-ID: In article <3e1e8567-b9f4-446a-8a59-75f45367d2ac at googlegroups.com>, Garry wrote: > Actual data: > [F0244],[I0690],[I0354],1916-06-08,"Neely's Landing, Cape Gir. Co, MO",,0x0a > [F0245],[I0692],[I0355],1919-09-04,"Cape Girardeau Co, MO",,0x0a > > code snippet follows: > > import os > import re > #I'm using the following regex in an attempt to decode the data: First suggestion, don't try to parse CSV data with regex. I'm a huge regex fan, but it's just the wrong tool for this job. Use the built-in csv module (http://docs.python.org/2/library/csv.html). Or, if you want something fancier, read_csv() from pandas (http://tinyurl.com/ajxdxjm). Second, when you use regexes, *always* use raw strings around the pattern: RegExp2 = r'....' Lastly, take a look at the re.VERBOSE flag. It lets you write monster regexes split up into several lines. Between re.VERBOSE and raw strings, it can make the difference between line noise like this: > RegExp2 = > "^(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\d{,4}\-\d{,2}\-\d > {,2})\,(.*|\".*\")\,(.*|\".*\")\,(.*|\".*\")" and something that mere mortals can understand. From ggkraemer at gmail.com Sun Jan 20 19:41:12 2013 From: ggkraemer at gmail.com (Garry) Date: Sun, 20 Jan 2013 16:41:12 -0800 (PST) Subject: RE Help splitting CVS data In-Reply-To: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> Message-ID: <9e90bf6e-9072-4747-917f-0291b1ae9a05@googlegroups.com> On Sunday, January 20, 2013 3:04:39 PM UTC-7, Garry wrote: > I'm trying to manipulate family tree data using Python. > > I'm using linux and Python 2.7.3 and have data files saved as Linux formatted cvs files > > The data appears in this format: > > > > Marriage,Husband,Wife,Date,Place,Source,Note0x0a > > Note: the Source field or the Note field can contain quoted data (same as the Place field) > > > > Actual data: > > [F0244],[I0690],[I0354],1916-06-08,"Neely's Landing, Cape Gir. Co, MO",,0x0a > > [F0245],[I0692],[I0355],1919-09-04,"Cape Girardeau Co, MO",,0x0a > > > > code snippet follows: > > > > import os > > import re > > #I'm using the following regex in an attempt to decode the data: > > RegExp2 = "^(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\d{,4}\-\d{,2}\-\d{,2})\,(.*|\".*\")\,(.*|\".*\")\,(.*|\".*\")" > > # > > line = "[F0244],[I0690],[I0354],1916-06-08,\"Neely's Landing, Cape Gir. Co, MO\",," > > # > > (Marriage,Husband,Wife,Date,Place,Source,Note) = re.split(RegExp2,line) > > # > > #However, this does not decode the 7 fields. > > # The following error is displayed: > > Traceback (most recent call last): > > File "", line 1, in > > ValueError: too many values to unpack > > # > > # When I use xx the fields apparently get unpacked. > > xx = re.split(RegExp2,line) > > # > > >>> print xx[0] > > > > >>> print xx[1] > > [F0244] > > >>> print xx[5] > > "Neely's Landing, Cape Gir. Co, MO" > > >>> print xx[6] > > > > >>> print xx[7] > > > > >>> print xx[8] > > > > Why is there an extra NULL field before and after my record contents? > > I'm stuck, comments and solutions greatly appreciated. > > > > Garry Thanks everyone for your comments. I'm new to Python, but can get around in Perl and regular expressions. I sure was taking the long way trying to get the cvs data parsed. Sure hope to teach myself python. Maybe I need to look into courses offered at the local Jr College! Garry From rosuav at gmail.com Sun Jan 20 20:30:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Jan 2013 12:30:11 +1100 Subject: RE Help splitting CVS data In-Reply-To: <9e90bf6e-9072-4747-917f-0291b1ae9a05@googlegroups.com> References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> <9e90bf6e-9072-4747-917f-0291b1ae9a05@googlegroups.com> Message-ID: On Mon, Jan 21, 2013 at 11:41 AM, Garry wrote: > Thanks everyone for your comments. I'm new to Python, but can get around in Perl and regular expressions. I sure was taking the long way trying to get the cvs data parsed. As has been hinted by Tim, you're actually talking about csv data - Comma Separated Values. Not to be confused with cvs, an old vcs. (See? The v can go anywhere...) Not a big deal, but it's much easier to find stuff on PyPI or similar when you have the right keyword to search for! ChrisA From alister.ware at ntlworld.com Mon Jan 21 03:28:44 2013 From: alister.ware at ntlworld.com (Alister) Date: Mon, 21 Jan 2013 08:28:44 GMT Subject: RE Help splitting CVS data References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> <9e90bf6e-9072-4747-917f-0291b1ae9a05@googlegroups.com> Message-ID: <0%6Ls.1$J74.0@fx31.fr7> On Sun, 20 Jan 2013 16:41:12 -0800, Garry wrote: > On Sunday, January 20, 2013 3:04:39 PM UTC-7, Garry wrote: >> I'm trying to manipulate family tree data using Python. >> >> I'm using linux and Python 2.7.3 and have data files saved as Linux >> formatted cvs files >> >> The data appears in this format: >> >> >> >> Marriage,Husband,Wife,Date,Place,Source,Note0x0a >> >> Note: the Source field or the Note field can contain quoted data (same >> as the Place field) >> >> >> >> Actual data: >> >> [F0244],[I0690],[I0354],1916-06-08,"Neely's Landing, Cape Gir. Co, >> MO",,0x0a >> >> [F0245],[I0692],[I0355],1919-09-04,"Cape Girardeau Co, MO",,0x0a >> >> >> >> code snippet follows: >> >> >> >> import os >> >> import re >> >> #I'm using the following regex in an attempt to decode the data: >> >> RegExp2 = >> "^(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\d{,4}\-\d {,2}\-\d{,2})\,(.*|\".*\")\,(.*|\".*\")\,(.*|\".*\")" >> >> # >> >> line = "[F0244],[I0690],[I0354],1916-06-08,\"Neely's Landing, Cape Gir. >> Co, MO\",," >> >> # >> >> (Marriage,Husband,Wife,Date,Place,Source,Note) = re.split(RegExp2,line) >> >> # >> >> #However, this does not decode the 7 fields. >> >> # The following error is displayed: >> >> Traceback (most recent call last): >> >> File "", line 1, in >> >> ValueError: too many values to unpack >> >> # >> >> # When I use xx the fields apparently get unpacked. >> >> xx = re.split(RegExp2,line) >> >> # >> >> >>> print xx[0] >> >> >> >> >>> print xx[1] >> >> [F0244] >> >> >>> print xx[5] >> >> "Neely's Landing, Cape Gir. Co, MO" >> >> >>> print xx[6] >> >> >> >> >>> print xx[7] >> >> >> >> >>> print xx[8] >> >> >> >> Why is there an extra NULL field before and after my record contents? >> >> I'm stuck, comments and solutions greatly appreciated. >> >> >> >> Garry > > Thanks everyone for your comments. I'm new to Python, but can get > around in Perl and regular expressions. I sure was taking the long way > trying to get the cvs data parsed. > > Sure hope to teach myself python. Maybe I need to look into courses > offered at the local Jr College! > > Garry don't waste time at college (at least not yet) there are many good tutorials available on the web. as you are already an experienced programmer "Dive into Python" would not be a bad start & the official python tutorial is also one not to miss -- "Just think of a computer as hardware you can program." -- Nigel de la Tierre From neilc at norwich.edu Mon Jan 21 09:12:06 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 21 Jan 2013 14:12:06 GMT Subject: RE Help splitting CVS data References: <3e1e8567-b9f4-446a-8a59-75f45367d2ac@googlegroups.com> <9e90bf6e-9072-4747-917f-0291b1ae9a05@googlegroups.com> Message-ID: On 2013-01-21, Garry wrote: > Thanks everyone for your comments. I'm new to Python, but can > get around in Perl and regular expressions. I sure was taking > the long way trying to get the cvs data parsed. > > Sure hope to teach myself python. Maybe I need to look into > courses offered at the local Jr College! There's more than enough free resources online for the resourceful Perl programmer to get going. It sounds like you might be interested in Text Processing in Python. http://gnosis.cx/TPiP/ Also good for your purposes is Dive Into Python. http://www.diveintopython.net/ -- Neil Cerutti From techgeek201 at gmail.com Sun Jan 20 23:40:47 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:40:47 -0800 (PST) Subject: Else statement executing when it shouldnt Message-ID: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped! Here is my code: #Cmd #Created By Eli M. #import modules import random import math gtn = 0 print ("Type in help for a list of cmd functions") #initiate main loop cmd = 0 while cmd == 0: #ask for input on function function = raw_input("Type in a function:") #start math loop if function == "math": run = 0 while run == 0: #ask for math operation type = raw_input("What math operation do you want to use?") if type == "multiplication": x = raw_input("Type in your first number:") y = raw_input("Multiply your first number by:") try: ans = int(x) * int(y) print (ans) try: ans = float(x) * float(y) print (ans) except ValueError, err: print ("Not a valid number") except OverflowError, err: print ("Number too large") #division math function if type == "division": x = raw_input("Type in your first number:") y = raw_input("Divide your first number by:") try: ans = float(x) / float(y) print (ans) except ZeroDivisionError, err: print ("Can't divide by zero") except ValueError, err: print ("Not a valid number") except OverflowError, err: print ("Number too large") #subtraction math function if type == "subtraction": x = raw_input("Type in your first number:") y = raw_input("Subtract your first number by:") try: ans = float(x) - float(y) print (ans) except ValueError, err: print ("Not a valid number") #addition math function if type == "addition": x = raw_input("Type in your first number:") y = raw_input("Add your first number by:") try: ans = float(x) + float(y) print (ans) except ValueError, err: try: ans = int(x) + int(y) print (ans) except ValueError, err: print ("Not a valid number") except OverflowError, err: print ("Number too large") #square root math function if type == "square root": x = raw_input("Type in your number:") try: y = float(x) z = math.sqrt(y) print (z) except ValueError, err: print ("Not a valid number") except OverflowError, err: print ("Number too large") #to the power of... math function if type == "power": x = raw_input("Type in your number:") y = raw_input("Multiply your first number by the power of:") try: ans = float(x) ** float(y) print (ans) except OverflowError, err: print ("Number too large") except ValueError, err: print ("Not a valid number") #break the math loop if type == "main": run = 1 #absolute value math function if type == "absolute value": try: x = float(raw_input("Type in your number:")) y = math.fabs(x) print (y) except ValueError, err: print ("Not a valid number") if function == "random number": try: x = int(raw_input("Minimum number:")) y = int(raw_input("Maximum number:")) num = random.randint(x, y) print (num) except ValueError, err: print ("Not a valid number") if function == "games": games = 0 while games == 0: gamechoice = raw_input("What game do you want to play:") if gamechoice == "guess the number": run = 0 while run == 0: print ("I am thinking of a number between 1 and 20") num = random.randint(1, 20) num = int(num) guesses = 0 guessestaken = 0 while guesses == 0: try: guess = raw_input("Your guess:") guess = int(guess) guessestaken = (guessestaken) + 1 guessestaken = int(guessestaken) if guess == (num): print 'Correct! It took you', int(guessestaken), 'guesses!' playagain = raw_input("Do you want to play again?") if playagain == "yes": guesses = 1 if playagain == "no": run = 1 guesses = 1 if guess > num: print ("My number is lower") if guess < num: print ("My number is higher") except TypeError, err: print ("Not a valid number") if gamechoice == "main": games = 1 #help function if function == "help": helpfunc = 0 while helpfunc == 0: #show functions print ("Functions:") print ("Math: multiplication, division, subtraction, addition, square root, power, absolute value") print ("Random Number") print ("Games: Guess the number") helpmain = raw_input("Type in main to go back") if helpmain == "main": #end helpfunction loop helpfunc = 1 cmd = 0 else: print ("Not a valid function") From roy at panix.com Sun Jan 20 23:47:25 2013 From: roy at panix.com (Roy Smith) Date: Sun, 20 Jan 2013 23:47:25 -0500 Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: In article <2cc6791f-ba56-406c-a5b0-b23023caf4bb at googlegroups.com>, eli m wrote: > an else statement is running when it shouldnt be. It is on the last line. > Whenever i am in the math or game function, when i type in main, it goes back > to the start of the program, but it also says not a valid function. I am > stumped! > Here is my code: [many lines of code elided] TL;DNR :-) A basic debugging technique is to try to find the minimum amount of code that can reproduce the problem. Find some hunk of lines that you're pretty sure can't be at fault, and delete them. See if you can still reproduce the problem. Assuming you can, delete another hunk of code. Keep going until you're down to the smallest possible amount of code which demonstrates the problem. There's a couple of good things that come out of this. One is that it's likely that in the course of doing this, you'll figure out what's wrong. The other is that if you can't figure it out, at least now you'll have something that's easy to show somebody else when you ask for help. From rosuav at gmail.com Sun Jan 20 23:52:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Jan 2013 15:52:12 +1100 Subject: Else statement executing when it shouldnt In-Reply-To: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: On Mon, Jan 21, 2013 at 3:40 PM, eli m wrote: > an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped! Check your indentation levels. I see a few things here that look odd: > if function == "help": > while helpfunc == 0: > if helpmain == "main": > else: What is the else meant to bind to? The innermost if? The 'if function == "help"'? It's currently binding to the while. Recommendation: Break this up! Your main loop is huge! It's way too easy to get lost in it. And while you're at it, consider unifying some of the similar blocks of code. The solution to both issues is simple: Use functions. Have you been taught about them yet? Also, side tip: Be honest about homework. I'm fairly sure that's what this is. :) ChrisA From rene.klacan at gmail.com Sun Jan 20 23:54:13 2013 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Mon, 21 Jan 2013 05:54:13 +0100 Subject: Else statement executing when it shouldnt In-Reply-To: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: You have to break while loop not to execute else branch Rene On Mon, Jan 21, 2013 at 5:40 AM, eli m wrote: > an else statement is running when it shouldnt be. It is on the last line. > Whenever i am in the math or game function, when i type in main, it goes > back to the start of the program, but it also says not a valid function. I > am stumped! > Here is my code: > #Cmd > #Created By Eli M. > #import modules > import random > import math > gtn = 0 > print ("Type in help for a list of cmd functions") > #initiate main loop > cmd = 0 > while cmd == 0: > #ask for input on function > function = raw_input("Type in a function:") > #start math loop > if function == "math": > run = 0 > while run == 0: > #ask for math operation > type = raw_input("What math operation do you want to use?") > if type == "multiplication": > x = raw_input("Type in your first number:") > y = raw_input("Multiply your first number by:") > try: > ans = int(x) * int(y) > print (ans) > try: > ans = float(x) * float(y) > print (ans) > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > #division math function > if type == "division": > x = raw_input("Type in your first number:") > y = raw_input("Divide your first number by:") > try: > ans = float(x) / float(y) > print (ans) > except ZeroDivisionError, err: > print ("Can't divide by zero") > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > #subtraction math function > if type == "subtraction": > x = raw_input("Type in your first number:") > y = raw_input("Subtract your first number by:") > try: > ans = float(x) - float(y) > print (ans) > except ValueError, err: > print ("Not a valid number") > #addition math function > if type == "addition": > x = raw_input("Type in your first number:") > y = raw_input("Add your first number by:") > try: > ans = float(x) + float(y) > print (ans) > except ValueError, err: > try: > ans = int(x) + int(y) > print (ans) > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > #square root math function > if type == "square root": > x = raw_input("Type in your number:") > try: > y = float(x) > z = math.sqrt(y) > print (z) > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > > #to the power of... math function > if type == "power": > x = raw_input("Type in your number:") > y = raw_input("Multiply your first number by the power > of:") > try: > ans = float(x) ** float(y) > print (ans) > except OverflowError, err: > print ("Number too large") > except ValueError, err: > print ("Not a valid number") > #break the math loop > if type == "main": > run = 1 > #absolute value math function > if type == "absolute value": > try: > x = float(raw_input("Type in your number:")) > y = math.fabs(x) > print (y) > except ValueError, err: > print ("Not a valid number") > if function == "random number": > try: > x = int(raw_input("Minimum number:")) > y = int(raw_input("Maximum number:")) > num = random.randint(x, y) > print (num) > except ValueError, err: > print ("Not a valid number") > if function == "games": > games = 0 > while games == 0: > gamechoice = raw_input("What game do you want to play:") > if gamechoice == "guess the number": > run = 0 > while run == 0: > print ("I am thinking of a number between 1 and 20") > num = random.randint(1, 20) > num = int(num) > guesses = 0 > guessestaken = 0 > while guesses == 0: > try: > guess = raw_input("Your guess:") > guess = int(guess) > guessestaken = (guessestaken) + 1 > guessestaken = int(guessestaken) > if guess == (num): > print 'Correct! It took you', > int(guessestaken), 'guesses!' > playagain = raw_input("Do you want to play > again?") > if playagain == "yes": > guesses = 1 > if playagain == "no": > run = 1 > guesses = 1 > if guess > num: > print ("My number is lower") > if guess < num: > print ("My number is higher") > except TypeError, err: > print ("Not a valid number") > if gamechoice == "main": > games = 1 > > #help function > if function == "help": > helpfunc = 0 > while helpfunc == 0: > #show functions > print ("Functions:") > print ("Math: multiplication, division, subtraction, addition, > square root, power, absolute value") > print ("Random Number") > print ("Games: Guess the number") > helpmain = raw_input("Type in main to go back") > if helpmain == "main": > #end helpfunction loop > helpfunc = 1 > cmd = 0 > else: > print ("Not a valid function") > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From techgeek201 at gmail.com Sun Jan 20 23:54:11 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:54:11 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <9f1f33ac-9550-4f39-9c61-7129e0c4f1a9@googlegroups.com> On Sunday, January 20, 2013 8:40:47 PM UTC-8, eli m wrote: hint: Use the comments in the code to find out where my error is. > > Here is my code: > > #Cmd > > #Created By Eli M. > > #import modules > > import random > > import math > > gtn = 0 > > print ("Type in help for a list of cmd functions") > > #initiate main loop > > cmd = 0 > > while cmd == 0: > > #ask for input on function > > function = raw_input("Type in a function:") > > #start math loop > > if function == "math": > > run = 0 > > while run == 0: > > #ask for math operation > > type = raw_input("What math operation do you want to use?") > > if type == "multiplication": > > x = raw_input("Type in your first number:") > > y = raw_input("Multiply your first number by:") > > try: > > ans = int(x) * int(y) > > print (ans) > > try: > > ans = float(x) * float(y) > > print (ans) > > except ValueError, err: > > print ("Not a valid number") > > except OverflowError, err: > > print ("Number too large") > > #division math function > > if type == "division": > > x = raw_input("Type in your first number:") > > y = raw_input("Divide your first number by:") > > try: > > ans = float(x) / float(y) > > print (ans) > > except ZeroDivisionError, err: > > print ("Can't divide by zero") > > except ValueError, err: > > print ("Not a valid number") > > except OverflowError, err: > > print ("Number too large") > > #subtraction math function > > if type == "subtraction": > > x = raw_input("Type in your first number:") > > y = raw_input("Subtract your first number by:") > > try: > > ans = float(x) - float(y) > > print (ans) > > except ValueError, err: > > print ("Not a valid number") > > #addition math function > > if type == "addition": > > x = raw_input("Type in your first number:") > > y = raw_input("Add your first number by:") > > try: > > ans = float(x) + float(y) > > print (ans) > > except ValueError, err: > > try: > > ans = int(x) + int(y) > > print (ans) > > except ValueError, err: > > print ("Not a valid number") > > except OverflowError, err: > > print ("Number too large") > > #square root math function > > if type == "square root": > > x = raw_input("Type in your number:") > > try: > > y = float(x) > > z = math.sqrt(y) > > print (z) > > except ValueError, err: > > print ("Not a valid number") > > except OverflowError, err: > > print ("Number too large") > > > > #to the power of... math function > > if type == "power": > > x = raw_input("Type in your number:") > > y = raw_input("Multiply your first number by the power of:") > > try: > > ans = float(x) ** float(y) > > print (ans) > > except OverflowError, err: > > print ("Number too large") > > except ValueError, err: > > print ("Not a valid number") > > #break the math loop > > if type == "main": > > run = 1 > > #absolute value math function > > if type == "absolute value": > > try: > > x = float(raw_input("Type in your number:")) > > y = math.fabs(x) > > print (y) > > except ValueError, err: > > print ("Not a valid number") > > if function == "random number": > > try: > > x = int(raw_input("Minimum number:")) > > y = int(raw_input("Maximum number:")) > > num = random.randint(x, y) > > print (num) > > except ValueError, err: > > print ("Not a valid number") > > if function == "games": > > games = 0 > > while games == 0: > > gamechoice = raw_input("What game do you want to play:") > > if gamechoice == "guess the number": > > run = 0 > > while run == 0: > > print ("I am thinking of a number between 1 and 20") > > num = random.randint(1, 20) > > num = int(num) > > guesses = 0 > > guessestaken = 0 > > while guesses == 0: > > try: > > guess = raw_input("Your guess:") > > guess = int(guess) > > guessestaken = (guessestaken) + 1 > > guessestaken = int(guessestaken) > > if guess == (num): > > print 'Correct! It took you', int(guessestaken), 'guesses!' > > playagain = raw_input("Do you want to play again?") > > if playagain == "yes": > > guesses = 1 > > if playagain == "no": > > run = 1 > > guesses = 1 > > if guess > num: > > print ("My number is lower") > > if guess < num: > > print ("My number is higher") > > except TypeError, err: > > print ("Not a valid number") > > if gamechoice == "main": > > games = 1 > > > > #help function > > if function == "help": > > helpfunc = 0 > > while helpfunc == 0: > > #show functions > > print ("Functions:") > > print ("Math: multiplication, division, subtraction, addition, square root, power, absolute value") > > print ("Random Number") > > print ("Games: Guess the number") > > helpmain = raw_input("Type in main to go back") > > if helpmain == "main": > > #end helpfunction loop > > helpfunc = 1 > > cmd = 0 > > else: > > print ("Not a valid function") From wuwei23 at gmail.com Mon Jan 21 01:00:10 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 Jan 2013 22:00:10 -0800 (PST) Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <9f1f33ac-9550-4f39-9c61-7129e0c4f1a9@googlegroups.com> Message-ID: On Jan 21, 2:54?pm, eli m wrote: > hint: Use the comments in the code to find out where my error is. Pro-tip: when people you're asking for help tell you how you can make it easier for them to help you, a snide response isn't the correct approach. From steve+comp.lang.python at pearwood.info Mon Jan 21 03:04:44 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2013 08:04:44 GMT Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <9f1f33ac-9550-4f39-9c61-7129e0c4f1a9@googlegroups.com> Message-ID: <50fcf69c$0$11101$c3e8da3@news.astraweb.com> On Sun, 20 Jan 2013 22:00:10 -0800, alex23 wrote: > On Jan 21, 2:54?pm, eli m wrote: >> hint: Use the comments in the code to find out where my error is. > > Pro-tip: when people you're asking for help tell you how you can make it > easier for them to help you, a snide response isn't the correct > approach. Alex, thank you for saying this. I can now delete my *much* less polite version saying the same thing. -- Steven From msirenef at lightbird.net Sun Jan 20 23:57:03 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 20 Jan 2013 23:57:03 -0500 Subject: Else statement executing when it shouldnt In-Reply-To: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <50FCCA9F.4040306@lightbird.net> On 01/20/2013 11:40 PM, eli m wrote: > an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped! > Here is my code: > #Cmd > #Created By Eli M. > #import modules > import random > import math > gtn = 0 > print ("Type in help for a list of cmd functions") > #initiate main loop > cmd = 0 > while cmd == 0: > #ask for input on function > function = raw_input("Type in a function:") > #start math loop > if function == "math": > run = 0 > while run == 0: > #ask for math operation > type = raw_input("What math operation do you want to use?") > if type == "multiplication": > x = raw_input("Type in your first number:") > y = raw_input("Multiply your first number by:") > try: > ans = int(x) * int(y) > print (ans) > try: > ans = float(x) * float(y) > print (ans) > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > #division math function > if type == "division": > x = raw_input("Type in your first number:") > y = raw_input("Divide your first number by:") > try: > ans = float(x) / float(y) > print (ans) > except ZeroDivisionError, err: > print ("Can't divide by zero") > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > #subtraction math function > if type == "subtraction": > x = raw_input("Type in your first number:") > y = raw_input("Subtract your first number by:") > try: > ans = float(x) - float(y) > print (ans) > except ValueError, err: > print ("Not a valid number") > #addition math function > if type == "addition": > x = raw_input("Type in your first number:") > y = raw_input("Add your first number by:") > try: > ans = float(x) + float(y) > print (ans) > except ValueError, err: > try: > ans = int(x) + int(y) > print (ans) > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > #square root math function > if type == "square root": > x = raw_input("Type in your number:") > try: > y = float(x) > z = math.sqrt(y) > print (z) > except ValueError, err: > print ("Not a valid number") > except OverflowError, err: > print ("Number too large") > > #to the power of... math function > if type == "power": > x = raw_input("Type in your number:") > y = raw_input("Multiply your first number by the power of:") > try: > ans = float(x) ** float(y) > print (ans) > except OverflowError, err: > print ("Number too large") > except ValueError, err: > print ("Not a valid number") > #break the math loop > if type == "main": > run = 1 > #absolute value math function > if type == "absolute value": > try: > x = float(raw_input("Type in your number:")) > y = math.fabs(x) > print (y) > except ValueError, err: > print ("Not a valid number") > if function == "random number": > try: > x = int(raw_input("Minimum number:")) > y = int(raw_input("Maximum number:")) > num = random.randint(x, y) > print (num) > except ValueError, err: > print ("Not a valid number") > if function == "games": > games = 0 > while games == 0: > gamechoice = raw_input("What game do you want to play:") > if gamechoice == "guess the number": > run = 0 > while run == 0: > print ("I am thinking of a number between 1 and 20") > num = random.randint(1, 20) > num = int(num) > guesses = 0 > guessestaken = 0 > while guesses == 0: > try: > guess = raw_input("Your guess:") > guess = int(guess) > guessestaken = (guessestaken) + 1 > guessestaken = int(guessestaken) > if guess == (num): > print 'Correct! It took you', int(guessestaken), 'guesses!' > playagain = raw_input("Do you want to play again?") > if playagain == "yes": > guesses = 1 > if playagain == "no": > run = 1 > guesses = 1 > if guess > num: > print ("My number is lower") > if guess < num: > print ("My number is higher") > except TypeError, err: > print ("Not a valid number") > if gamechoice == "main": > games = 1 > > #help function > if function == "help": > helpfunc = 0 > while helpfunc == 0: > #show functions > print ("Functions:") > print ("Math: multiplication, division, subtraction, addition, square root, power, absolute value") > print ("Random Number") > print ("Games: Guess the number") > helpmain = raw_input("Type in main to go back") > if helpmain == "main": > #end helpfunction loop > helpfunc = 1 > cmd = 0 > else: > print ("Not a valid function") Your else is lined up with while, not with if. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ When a friend succeeds, I die a little. Gore Vidal From techgeek201 at gmail.com Sun Jan 20 23:57:45 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:57:45 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: On Sunday, January 20, 2013 8:54:13 PM UTC-8, Ren? Kla?an wrote: > You have to break while loop not to execute else branch > > > Rene > > > Can you explain in more detail please. From techgeek201 at gmail.com Sun Jan 20 23:57:45 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:57:45 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: On Sunday, January 20, 2013 8:54:13 PM UTC-8, Ren? Kla?an wrote: > You have to break while loop not to execute else branch > > > Rene > > > Can you explain in more detail please. From rene.klacan at gmail.com Mon Jan 21 00:06:05 2013 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Mon, 21 Jan 2013 06:06:05 +0100 Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: Examples: # else branch will be executed i = 0 while i < 5: i += 1 else: print('loop is over') # else branch will be executed i = 0 while i < 5: i += 1 if i == 7: print('i == 7') break else: print('loop is over') # else branch wont be executed i = 0 while i < 5: i += 1 if i == 3: print('i == 3') break else: print('loop is over') On Mon, Jan 21, 2013 at 5:57 AM, eli m wrote: > On Sunday, January 20, 2013 8:54:13 PM UTC-8, Ren? Kla?an wrote: > > You have to break while loop not to execute else branch > > > > > > Rene > > > > > > > Can you explain in more detail please. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rene.klacan at gmail.com Mon Jan 21 00:07:08 2013 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Mon, 21 Jan 2013 06:07:08 +0100 Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: Examples: # else branch will be executed i = 0 while i < 5: i += 1 else: print('loop is over') # else branch will be executed i = 0 while i < 5: i += 1 if i == 7: print('i == 7') break else: print('loop is over') # else branch wont be executed i = 0 while i < 5: i += 1 if i == 3: print('i == 3') break else: print('loop is over') On Mon, Jan 21, 2013 at 5:57 AM, eli m wrote: > On Sunday, January 20, 2013 8:54:13 PM UTC-8, Ren? Kla?an wrote: > > You have to break while loop not to execute else branch > > > > > > Rene > > > > > > > Can you explain in more detail please. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tboell at domain.invalid Tue Jan 22 10:39:24 2013 From: tboell at domain.invalid (Thomas Boell) Date: Tue, 22 Jan 2013 16:39:24 +0100 Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <20130122163924.74038876@sampi> On Mon, 21 Jan 2013 06:07:08 +0100 Ren? Kla?an wrote: > Examples: > > # else branch will be executed > i = 0 > while i < 5: > i += 1 > else: > print('loop is over') > > > # else branch will be executed > i = 0 > while i < 5: > i += 1 > if i == 7: > print('i == 7') > break > else: > print('loop is over') > > > # else branch wont be executed > i = 0 > while i < 5: > i += 1 > if i == 3: > print('i == 3') > break > else: > print('loop is over') Huh?! I would have expected all your examples to raise a SyntaxError or IndentationError. Why don't they? Is 'else' not required to have a matching 'if'? From rosuav at gmail.com Tue Jan 22 10:42:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 02:42:27 +1100 Subject: Else statement executing when it shouldnt In-Reply-To: <20130122163924.74038876@sampi> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> Message-ID: On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell wrote: > Huh?! I would have expected all your examples to raise a SyntaxError or > IndentationError. Why don't they? Is 'else' not required to have a > matching 'if'? Other things can have else, including 'for' and 'while' loops. :) ChrisA From duncan.booth at invalid.invalid Tue Jan 22 10:48:11 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Jan 2013 15:48:11 GMT Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> Message-ID: Thomas Boell wrote: > Huh?! I would have expected all your examples to raise a SyntaxError or > IndentationError. Why don't they? Is 'else' not required to have a > matching 'if'? > Matching 'if' or 'for' or 'while'. See http://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops -- Duncan Booth http://kupuguy.blogspot.com From duncan.booth at invalid.invalid Tue Jan 22 10:52:08 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Jan 2013 15:52:08 GMT Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> Message-ID: Duncan Booth wrote: > Matching 'if' or 'for' or 'while'. > or of course 'try'. -- Duncan Booth http://kupuguy.blogspot.com From tboell at domain.invalid Tue Jan 22 10:48:35 2013 From: tboell at domain.invalid (Thomas Boell) Date: Tue, 22 Jan 2013 16:48:35 +0100 Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> Message-ID: <20130122164835.74a0ebf6@sampi> On Wed, 23 Jan 2013 02:42:27 +1100 Chris Angelico wrote: > On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell wrote: > > Huh?! I would have expected all your examples to raise a SyntaxError or > > IndentationError. Why don't they? Is 'else' not required to have a > > matching 'if'? > > Other things can have else, including 'for' and 'while' loops. :) I must say, that's bound to be confusing for anyone who knows any language other than Python (or none, even). Syntax like that is "an accident waiting to happen"... From rosuav at gmail.com Tue Jan 22 11:07:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 03:07:21 +1100 Subject: Else statement executing when it shouldnt In-Reply-To: <20130122164835.74a0ebf6@sampi> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> Message-ID: On Wed, Jan 23, 2013 at 2:48 AM, Thomas Boell wrote: > On Wed, 23 Jan 2013 02:42:27 +1100 > Chris Angelico wrote: > >> On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell wrote: >> > Huh?! I would have expected all your examples to raise a SyntaxError or >> > IndentationError. Why don't they? Is 'else' not required to have a >> > matching 'if'? >> >> Other things can have else, including 'for' and 'while' loops. :) > > I must say, that's bound to be confusing for anyone who knows any > language other than Python (or none, even). Syntax like that is "an > accident waiting to happen"... It can be confusing and does take that bit of learning, but it's SO handy. In C code, I sometimes simulate it with a 'goto' and a comment, but the actual keyword is much clearer. ChrisA From steve+comp.lang.python at pearwood.info Tue Jan 22 18:22:53 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:22:53 GMT Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> Message-ID: <50ff1f4c$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 16:48:35 +0100, Thomas Boell wrote: > On Wed, 23 Jan 2013 02:42:27 +1100 > Chris Angelico wrote: > >> On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell >> wrote: >> > Huh?! I would have expected all your examples to raise a SyntaxError >> > or IndentationError. Why don't they? Is 'else' not required to have a >> > matching 'if'? >> >> Other things can have else, including 'for' and 'while' loops. :) > > I must say, that's bound to be confusing for anyone who knows any > language other than Python (or none, even). Syntax like that is "an > accident waiting to happen"... Oh it's even worse than that. I reckon that nearly everyone thinks that for...else runs the "else" clause if the for loop is empty, at least the first time they see it. Or for the slow of thinking like me, the first few dozen times. # this is wrong, but it looks right for x in sequence: do_something_with(x) else: print "sequence is empty" But no, that's not what it does. `for...else` is actually more like this: # this is right for x in sequence: do_something_with(x) if condition: break else: print "condition was never true" That's right. The `else` block *unconditionally* executes after the `for` block. The only way to skip it is to use `break`, which skips all the way out of the combined for...else statement. This is a very useful feature, very badly named. -- Steven From rene.klacan at gmail.com Tue Jan 22 19:34:02 2013 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Wed, 23 Jan 2013 01:34:02 +0100 Subject: Else statement executing when it shouldnt In-Reply-To: <50ff1f4c$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> <50ff1f4c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: it seems that lot of you are forgeting about this case: for i in [1,2,3,4,5]: print i else: print('this will be printed also because cycle wasnt broke') so the one case when else branch is executed is when condition is not satisfied and the other case is when there is no break executed during the cycle On Wed, Jan 23, 2013 at 12:22 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Tue, 22 Jan 2013 16:48:35 +0100, Thomas Boell wrote: > > > On Wed, 23 Jan 2013 02:42:27 +1100 > > Chris Angelico wrote: > > > >> On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell > >> wrote: > >> > Huh?! I would have expected all your examples to raise a SyntaxError > >> > or IndentationError. Why don't they? Is 'else' not required to have a > >> > matching 'if'? > >> > >> Other things can have else, including 'for' and 'while' loops. :) > > > > I must say, that's bound to be confusing for anyone who knows any > > language other than Python (or none, even). Syntax like that is "an > > accident waiting to happen"... > > Oh it's even worse than that. I reckon that nearly everyone thinks that > for...else runs the "else" clause if the for loop is empty, at least the > first time they see it. Or for the slow of thinking like me, the first > few dozen times. > > # this is wrong, but it looks right > for x in sequence: > do_something_with(x) > else: > print "sequence is empty" > > > But no, that's not what it does. `for...else` is actually more like this: > > > # this is right > for x in sequence: > do_something_with(x) > if condition: > break > else: > print "condition was never true" > > > That's right. The `else` block *unconditionally* executes after the `for` > block. The only way to skip it is to use `break`, which skips all the way > out of the combined for...else statement. > > This is a very useful feature, very badly named. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Jan 22 20:28:35 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 22 Jan 2013 17:28:35 -0800 (PST) Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> Message-ID: <66a33143-c4e5-400d-b6eb-2305a345ca3e@ro7g2000pbb.googlegroups.com> On Jan 23, 1:48?am, Thomas Boell wrote: > I must say, that's bound to be confusing for anyone who knows any > language other than Python (or none, even). ?Syntax like that is "an > accident waiting to happen"... No, ignorantly expecting every language to conform to every other is the pending accident. From tboell at domain.invalid Wed Jan 23 06:22:47 2013 From: tboell at domain.invalid (Thomas Boell) Date: Wed, 23 Jan 2013 12:22:47 +0100 Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> <66a33143-c4e5-400d-b6eb-2305a345ca3e@ro7g2000pbb.googlegroups.com> Message-ID: <20130123122247.43031d2e@sampi> On Tue, 22 Jan 2013 17:28:35 -0800 (PST) alex23 wrote: > On Jan 23, 1:48?am, Thomas Boell wrote: > > I must say, that's bound to be confusing for anyone who knows any > > language other than Python (or none, even). ?Syntax like that is "an > > accident waiting to happen"... > > No, ignorantly expecting every language to conform to every other is > the pending accident. Using a keyword that has a well-understood meaning in just about every other programming language on the planet *and even in English*, redefining it to mean something completely different, and then making the syntax look like the original, well-understood meaning -- that's setting a trap out for users. The feature isn't bad, it's just very, very badly named. From jpiitula at ling.helsinki.fi Wed Jan 23 08:35:29 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 23 Jan 2013 15:35:29 +0200 Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> <66a33143-c4e5-400d-b6eb-2305a345ca3e@ro7g2000pbb.googlegroups.com> <20130123122247.43031d2e@sampi> Message-ID: Thomas Boell writes: > Using a keyword that has a well-understood meaning in just about > every other programming language on the planet *and even in > English*, redefining it to mean something completely different, and > then making the syntax look like the original, well-understood > meaning -- that's setting a trap out for users. > > The feature isn't bad, it's just very, very badly named. I believe it would read better - much better - if it was "for/then" and "while/then" instead of "for/else" and "while/else". I believe someone didn't want to introduce a new keyword for this, hence "else". From malaclypse2 at gmail.com Wed Jan 23 09:53:08 2013 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 23 Jan 2013 09:53:08 -0500 Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> <66a33143-c4e5-400d-b6eb-2305a345ca3e@ro7g2000pbb.googlegroups.com> <20130123122247.43031d2e@sampi> Message-ID: On Wed, Jan 23, 2013 at 8:35 AM, Jussi Piitulainen wrote: >> The feature isn't bad, it's just very, very badly named. > > I believe it would read better - much better - if it was "for/then" > and "while/then" instead of "for/else" and "while/else". That's always been my opinion too. I'd remember how the construct worked if it was for/then (and while/then). Since seeing for/else always makes my brain lock up for a few seconds when I'm reading code, I don't bother using it. Jerry From frank at chagford.com Fri Jan 25 03:15:56 2013 From: frank at chagford.com (Frank Millman) Date: Fri, 25 Jan 2013 10:15:56 +0200 Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <20130122163924.74038876@sampi> <20130122164835.74a0ebf6@sampi> <66a33143-c4e5-400d-b6eb-2305a345ca3e@ro7g2000pbb.googlegroups.com> <20130123122247.43031d2e@sampi> Message-ID: On 23/01/2013 15:35, Jussi Piitulainen wrote: > Thomas Boell writes: > >> Using a keyword that has a well-understood meaning in just about >> every other programming language on the planet *and even in >> English*, redefining it to mean something completely different, and >> then making the syntax look like the original, well-understood >> meaning -- that's setting a trap out for users. >> >> The feature isn't bad, it's just very, very badly named. > > I believe it would read better - much better - if it was "for/then" > and "while/then" instead of "for/else" and "while/else". > > I believe someone didn't want to introduce a new keyword for this, > hence "else". > There is a scenario, which I use from time to time, where 'else' makes perfect sense. You want to loop through an iterable, looking for 'something'. If you find it, you want to do something and break. If you do not find it, you want to do something else. for item in iterable: if item == 'something': do_something() break else: # item was not found do_something_else() Not arguing for or against, just saying it is difficult to find one word which covers all requirements. Frank Millman From techgeek201 at gmail.com Sun Jan 20 23:59:19 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:59:19 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <11a77bd2-c537-4d0b-8af4-99d1f8c252d0@googlegroups.com> > > > > Your else is lined up with while, not with if. > > > > -m > > > > > > -- > > Lark's Tongue Guide to Python: http://lightbird.net/larks/ > > > > When a friend succeeds, I die a little. Gore Vidal Its lined up. It got messed up when i copied the code into the post. From techgeek201 at gmail.com Sun Jan 20 23:59:19 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:59:19 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <11a77bd2-c537-4d0b-8af4-99d1f8c252d0@googlegroups.com> > > > > Your else is lined up with while, not with if. > > > > -m > > > > > > -- > > Lark's Tongue Guide to Python: http://lightbird.net/larks/ > > > > When a friend succeeds, I die a little. Gore Vidal Its lined up. It got messed up when i copied the code into the post. From msirenef at lightbird.net Mon Jan 21 01:09:21 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 21 Jan 2013 01:09:21 -0500 Subject: Else statement executing when it shouldnt In-Reply-To: <11a77bd2-c537-4d0b-8af4-99d1f8c252d0@googlegroups.com> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <11a77bd2-c537-4d0b-8af4-99d1f8c252d0@googlegroups.com> Message-ID: <50FCDB91.3040407@lightbird.net> On 01/20/2013 11:59 PM, eli m wrote: > >> >> >> >> Your else is lined up with while, not with if. >> >> >> >> -m >> >> >> >> >> >> -- >> >> Lark's Tongue Guide to Python: http://lightbird.net/larks/ >> >> >> >> When a friend succeeds, I die a little. Gore Vidal > Its lined up. It got messed up when i copied the code into the post. > I would recommend using while True: and break vs. while var: as you have. In most cases while True: works better, especially in case of long and/or nested 'while' loops, as you have. 'while True' blocks have two advantages: 1. you can break the loop at any location and 2. when looking at the code, you can tell on which condition it breaks by looking at the break line. Even more importantly, break it up into a few functions. The code as you have it is too hard to work with and to debug. It's hard to tell what your 'else' is lined up to, or whether some other lines are mis-aligned, as well. Generally, try to avoid making a loop if it's 20+ lines; if there are nested loops, it makes things even worse. Compare: if something: while True: if not process(): break def process(): [... 20 lines that loop ...] [ return None to break the loop ] Now this is really clear, because just by looking at the first three lines, I know what the loop is supposed to do (process something), that it continues looping until it returns a false value; when looking at the function body I don't need to care which block it aligns to, I already know the entire function body is in the while loop. HTH, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The irrational in the human has something about it altogether repulsive and terrible, as we see in the maniac, the miser, the drunkard or the ape. George Santayana From wuwei23 at gmail.com Mon Jan 21 00:46:47 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 Jan 2013 21:46:47 -0800 (PST) Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <49b9c29e-362a-4483-8f4f-ea95d27f31df@jl13g2000pbb.googlegroups.com> On Jan 21, 2:59?pm, eli m wrote: > Its lined up. It got messed up when i copied the code into the post. Sorry, we're not going to take your word for it. Reduce it to the minimal amount of code that reproduces your error and post that. From techgeek201 at gmail.com Sun Jan 20 23:55:29 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:55:29 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <22041867-b67f-433e-8c24-451d328d7086@googlegroups.com> On Sunday, January 20, 2013 8:52:12 PM UTC-8, Chris Angelico wrote: > On Mon, Jan 21, 2013 at 3:40 PM, eli m wrote: > > > an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped! > > > > Check your indentation levels. I see a few things here that look odd: > > > > > if function == "help": > > > while helpfunc == 0: > > > if helpmain == "main": > > > else: > > > > What is the else meant to bind to? The innermost if? The 'if function > > == "help"'? It's currently binding to the while. > > > > Recommendation: Break this up! Your main loop is huge! It's way too > > easy to get lost in it. And while you're at it, consider unifying some > > of the similar blocks of code. The solution to both issues is simple: > > Use functions. Have you been taught about them yet? > > > > Also, side tip: Be honest about homework. I'm fairly sure that's what > > this is. :) > > > > ChrisA Its not homework. It is a personal project. From techgeek201 at gmail.com Sun Jan 20 23:55:29 2013 From: techgeek201 at gmail.com (eli m) Date: Sun, 20 Jan 2013 20:55:29 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <22041867-b67f-433e-8c24-451d328d7086@googlegroups.com> On Sunday, January 20, 2013 8:52:12 PM UTC-8, Chris Angelico wrote: > On Mon, Jan 21, 2013 at 3:40 PM, eli m wrote: > > > an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped! > > > > Check your indentation levels. I see a few things here that look odd: > > > > > if function == "help": > > > while helpfunc == 0: > > > if helpmain == "main": > > > else: > > > > What is the else meant to bind to? The innermost if? The 'if function > > == "help"'? It's currently binding to the while. > > > > Recommendation: Break this up! Your main loop is huge! It's way too > > easy to get lost in it. And while you're at it, consider unifying some > > of the similar blocks of code. The solution to both issues is simple: > > Use functions. Have you been taught about them yet? > > > > Also, side tip: Be honest about homework. I'm fairly sure that's what > > this is. :) > > > > ChrisA Its not homework. It is a personal project. From wuwei23 at gmail.com Mon Jan 21 00:56:59 2013 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 Jan 2013 21:56:59 -0800 (PST) Subject: Else statement executing when it shouldnt References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: On Jan 21, 2:40?pm, eli m wrote: > an else statement is running when it shouldnt be. It is > on the last line. Whenever i am in the math or game > function, when i type in main, it goes back to the start > of the program, but it also says not a valid function. > I am stumped! Here is your code with the irrelevancy stripped away: function = raw_input("Type in a function:") #start math loop if function == "math": #math code if function == "random number": #random code if function == "games": #games code if function == "help": #help code else: print ("Not a valid function") Say you enter 'math'. It passes the first condition, so runs the math code. It then fails on the next 3 conditions, the last of which has an else, so if you type _anything_ other than 'help', you'll see "Not a valid function". Easy answer, use `elif` ("else if") instead of else for the subsequent tests: if function == "math": #math code elif function == "random number": #random code elif function == "games": #games code elif function == "help": #help code else: print ("Not a valid function") Better answer: read up on real functions, and look into dictionary dispatch: def f_math(): #math code def f_random_number(): #random code function_dispatcher = { 'math': f_math, 'random number': f_random_number, } while cmd == 0: function_name = raw_input("Type in a function:") if function_name in function_dispatcher: function_dispatcher[function_name]() else: print("Not a valid function") To have your functions break out of the loop, use a `global` variable or pass a context object into each function to allow them to set `cmd`. From techgeek201 at gmail.com Mon Jan 21 10:37:59 2013 From: techgeek201 at gmail.com (eli m) Date: Mon, 21 Jan 2013 07:37:59 -0800 (PST) Subject: Else statement executing when it shouldnt In-Reply-To: References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> Message-ID: <1796075c-5b40-4034-ac44-ec33f5c54e67@googlegroups.com> On Sunday, January 20, 2013 9:56:59 PM UTC-8, alex23 wrote: > On Jan 21, 2:40?pm, eli m wrote: > > > an else statement is running when it shouldnt be. It is > > > on the last line. Whenever i am in the math or game > > > function, when i type in main, it goes back to the start > > > of the program, but it also says not a valid function. > > > I am stumped! > > > > Here is your code with the irrelevancy stripped away: > > > > function = raw_input("Type in a function:") > > #start math loop > > if function == "math": > > #math code > > if function == "random number": > > #random code > > if function == "games": > > #games code > > if function == "help": > > #help code > > else: > > print ("Not a valid function") > > > > Say you enter 'math'. It passes the first condition, so runs the math > > code. > > It then fails on the next 3 conditions, the last of which has an else, > > so if you type _anything_ other than 'help', you'll see "Not a valid > > function". > > > > Easy answer, use `elif` ("else if") instead of else for the subsequent > > tests: > > > > if function == "math": > > #math code > > elif function == "random number": > > #random code > > elif function == "games": > > #games code > > elif function == "help": > > #help code > > else: > > print ("Not a valid function") > > > > Better answer: read up on real functions, and look into dictionary > > dispatch: > > > > def f_math(): > > #math code > > > > def f_random_number(): > > #random code > > > > > > > > function_dispatcher = { > > 'math': f_math, > > 'random number': f_random_number, > > > > } > > > > while cmd == 0: > > function_name = raw_input("Type in a function:") > > if function_name in function_dispatcher: > > function_dispatcher[function_name]() > > else: > > print("Not a valid function") > > > > To have your functions break out of the loop, use a `global` variable > > or pass a context object into each function to allow them to set > > `cmd`. Thank you, that solved my problem. Sorry for my posts, i am a noob and this is my first time posting on here. From rosuav at gmail.com Mon Jan 21 13:44:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Jan 2013 05:44:16 +1100 Subject: Else statement executing when it shouldnt In-Reply-To: <1796075c-5b40-4034-ac44-ec33f5c54e67@googlegroups.com> References: <2cc6791f-ba56-406c-a5b0-b23023caf4bb@googlegroups.com> <1796075c-5b40-4034-ac44-ec33f5c54e67@googlegroups.com> Message-ID: On Tue, Jan 22, 2013 at 2:37 AM, eli m wrote: > Thank you, that solved my problem. Sorry for my posts, i am a noob and this is my first time posting on here. There's nothing wrong with being a noob, we all start out that way. Want to be one of the people we love to help? Here are some tips: http://www.catb.org/esr/faqs/smart-questions.html It's longish, but you'll find it helpful. The principles laid out in that document govern pretty much every geeky forum, and a good number of others besides. ChrisA From kwakukwatiah at gmail.com Mon Jan 21 11:06:41 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Mon, 21 Jan 2013 10:06:41 -0600 Subject: need explanation Message-ID: please I need some explanation on sys.stdin and sys.stdout, and piping out -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 21 15:58:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Jan 2013 07:58:02 +1100 Subject: need explanation In-Reply-To: References: Message-ID: On Tue, Jan 22, 2013 at 3:06 AM, wrote: > please I need some explanation on sys.stdin and sys.stdout, and piping out Try the documentation or a web search. If that doesn't help, ask a specific question. ChrisA From square.steve at gmail.com Mon Jan 21 05:46:07 2013 From: square.steve at gmail.com (Steve Simmons) Date: Mon, 21 Jan 2013 10:46:07 +0000 Subject: handling return codes from CTYPES Message-ID: <50FD1C6F.6030801@gmail.com> PY33, Win7, Python Newbie, Not homework:-) I'm trying to use some 'C' DLLs from Python using ctypes and I have a minor issue with the return valuesbut I am new to Python; ctypes and using DLLs so I am at the bottom of so many learning curves, I'm not sure where or how to find my mistake. When I call the DLL, I am expecting a return of 1 (success) or a negative number (one of a set of error conditions)the return value is specified as 'short' in the DLL call specification - "short InitScanLib (const char * szLicense)". What I get back is either a 1 or something like 65535. This implies that I am receiving the expected value (-1) but 'something' is being lost in the translation. The code is asper the snippet below: >>> from ctypes import * >>> sLib = cdll.slib >>> lic_key = c_char_p("asdfghjkl".encode(encoding='utf_8', errors='strict')) >>> initResult = sLib.InitScanLib(lic_key.value) >>> print("InitScanLib Result: ", initResult) InitScanLib Result: 65535 >>> I've tried declaring initResult as c_short by: inserting... >>> initResult = c_short(0) ... before the call to sLib.InitScanLib but I still get the same response (65535). Interactively, I can see ... >>> c_short(65535) c_short(-1) >>> c_short(-1) c_short(-1) >>> It's not a critical issue because I only want the return value to lookupa textual error message but I do want to understand what's going on. Any input appreciated. From duncan.booth at invalid.invalid Mon Jan 21 06:11:22 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Jan 2013 11:11:22 GMT Subject: handling return codes from CTYPES References: Message-ID: Steve Simmons wrote: > >>> from ctypes import * > >>> sLib = cdll.slib > >>> lic_key = c_char_p("asdfghjkl".encode(encoding='utf_8', > errors='strict')) > >>> initResult = sLib.InitScanLib(lic_key.value) > >>> print("InitScanLib Result: ", initResult) > InitScanLib Result: 65535 > >>> > > I've tried declaring initResult as c_short by: inserting... > > >>> initResult = c_short(0) > > ... before the call to sLib.InitScanLib but I still get the same > response (65535). Tell the function what type to return before you call it: InitScanLib = sLib.InitScanLib InitScanLib.restype = c_short See http://docs.python.org/2/library/ctypes.html#return-types You can also tell it what parameter types to expect which will make calling it simpler. -- Duncan Booth http://kupuguy.blogspot.com From square.steve at gmail.com Tue Jan 22 03:02:51 2013 From: square.steve at gmail.com (Steve Simmons) Date: Tue, 22 Jan 2013 08:02:51 +0000 Subject: handling return codes from CTYPES In-Reply-To: References: Message-ID: <50FE47AB.10700@gmail.com> Duncan, Mike, MRAB, Thank you. New technology set, same forgotten lesson - RTFM (all of it!). Thanks also for the clarification on discarding objects and Garbage Collection. Looks like I'll have to turn a large chunk of my previous understanding of (mainframe) languages 'inside out'. I'm just wondering how often I'll have to chant "it isn't a variable, it's a name bound to an object" before I can write a chunk of code without spending ages pondering why it isn't working. I already like Python for its clean design but I think it'll be a while before I love it completely. Steve On 21/01/2013 11:11, Duncan Booth wrote: > Tell the function what type to return before you call it: InitScanLib > = sLib.InitScanLib InitScanLib.restype = c_short See > http://docs.python.org/2/library/ctypes.html#return-types You can also > tell it what parameter types to expect which will make calling it > simpler. From rosuav at gmail.com Tue Jan 22 08:10:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 00:10:04 +1100 Subject: handling return codes from CTYPES In-Reply-To: <50FE47AB.10700@gmail.com> References: <50FE47AB.10700@gmail.com> Message-ID: On Tue, Jan 22, 2013 at 7:02 PM, Steve Simmons wrote: > Thanks also for the clarification on discarding objects and Garbage > Collection. Looks like I'll have to turn a large chunk of my previous > understanding of (mainframe) languages 'inside out'. > > I'm just wondering how often I'll have to chant "it isn't a variable, it's a > name bound to an object" before I can write a chunk of code without spending > ages pondering why it isn't working. > > I already like Python for its clean design but I think it'll be a while > before I love it completely. Yeah, it takes some getting used to. I've spent the past couple of decades writing imperative code with strict declarations and fairly close to the metal, and I still have one C++ module at work - but more and more, I'm pushing to write code in a modern high-level language like Python, where memory management isn't my problem, and failings in the code result in easily-readable (and catchable!) exceptions. I often fire up gdb for the C++ code at work, but usually a Python or Pike exception traceback is enough on its own. Learning curve, rewarded with immensely easier work. So many things are like that; life is all about figuring out which ones are worth the curve's effort. ChrisA From mcfletch at vrplumber.com Mon Jan 21 10:14:15 2013 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Mon, 21 Jan 2013 10:14:15 -0500 Subject: handling return codes from CTYPES In-Reply-To: <50FD1C6F.6030801@gmail.com> References: <50FD1C6F.6030801@gmail.com> Message-ID: <50FD5B47.8030807@vrplumber.com> On 13-01-21 05:46 AM, Steve Simmons wrote: ... > >>> from ctypes import * > >>> sLib = cdll.slib > >>> lic_key = c_char_p("asdfghjkl".encode(encoding='utf_8', > errors='strict')) > >>> initResult = sLib.InitScanLib(lic_key.value) > >>> print("InitScanLib Result: ", initResult) > InitScanLib Result: 65535 > >>> > > I've tried declaring initResult as c_short by: inserting... > > >>> initResult = c_short(0) > > ... before the call to sLib.InitScanLib but I still get the same > response (65535). That's because you've just discarded the object you created. What you wanted was, I believe: initScanLib = sLib.InitScanLib initScanLib.restype = c_short initResult = initScanLib( ... ) i.e. you tell the initScanLib function how to coerce its result-type. *Some* C functions take a pointer to a data-value to fill in their data, but not *your* function. That pattern looks like: result = c_short(0) my_ctypes_function( ..., byref(result) ) print result.value i.e. you have to pass the variable into the function (as a reference/pointer). HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From square.steve at gmail.com Mon Jan 21 11:52:37 2013 From: square.steve at gmail.com (Steve Simmons) Date: Mon, 21 Jan 2013 16:52:37 +0000 Subject: handling return codes from CTYPES In-Reply-To: <50FD5B47.8030807@vrplumber.com> References: <50FD1C6F.6030801@gmail.com> <50FD5B47.8030807@vrplumber.com> Message-ID: <50FD7255.3010206@gmail.com> Mike, Thanks for your response - I was puzzled by one part of it though... On 21/01/2013 15:14, Mike C. Fletcher wrote: > That's because you've just discarded the object you created I (mis?)understood from the ctypes documentation that '>>> initResult = c_short(0)' would result in the creation of a ctypes 'short' called initResult and that this object would be mutable. On that basis, I expected the following statement '>>> initResult = initScanLib( ... )' would assign the result of the call to initResult. So, I can understand that I am not using the correct approach but I don't understand how I discarded the object I created. Can you clarify please? Steve From python at mrabarnett.plus.com Mon Jan 21 15:21:22 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 21 Jan 2013 20:21:22 +0000 Subject: handling return codes from CTYPES In-Reply-To: <50FD7255.3010206@gmail.com> References: <50FD1C6F.6030801@gmail.com> <50FD5B47.8030807@vrplumber.com> <50FD7255.3010206@gmail.com> Message-ID: <50FDA342.5000505@mrabarnett.plus.com> On 2013-01-21 16:52, Steve Simmons wrote: > Mike, > > Thanks for your response - I was puzzled by one part of it though... > > On 21/01/2013 15:14, Mike C. Fletcher wrote: >> That's because you've just discarded the object you created > > I (mis?)understood from the ctypes documentation that '>>> initResult = > c_short(0)' would result in the creation of a ctypes 'short' called > initResult and that this object would be mutable. On that basis, I > expected the following statement '>>> initResult = initScanLib( ... )' > would assign the result of the call to initResult. > > So, I can understand that I am not using the correct approach but I > don't understand how I discarded the object I created. Can you clarify > please? > This: initResult = initScanLib( ... ) will make initResult refer to whatever initScanLib(...) returned, just as this: initResult = c_short(0) will make initResult refer to whatever c_short(0) returned. What you were doing was this: 1. You created a c_short object and bound initResult to it. 2. You called a function and bound initResult to its result, unbinding the c_short object in the process. 3. There were no other references to the c_short object, therefore it could be discarded by the garbage collector. From mcfletch at vrplumber.com Mon Jan 21 15:31:20 2013 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Mon, 21 Jan 2013 15:31:20 -0500 Subject: handling return codes from CTYPES In-Reply-To: <50FD7255.3010206@gmail.com> References: <50FD1C6F.6030801@gmail.com> <50FD5B47.8030807@vrplumber.com> <50FD7255.3010206@gmail.com> Message-ID: <50FDA598.6000309@vrplumber.com> On 13-01-21 11:52 AM, Steve Simmons wrote: > Mike, > > Thanks for your response - I was puzzled by one part of it though... > > On 21/01/2013 15:14, Mike C. Fletcher wrote: >> That's because you've just discarded the object you created > > I (mis?)understood from the ctypes documentation that '>>> initResult > = c_short(0)' would result in the creation of a ctypes 'short' called > initResult and that this object would be mutable. On that basis, I > expected the following statement '>>> initResult = initScanLib( ... )' > would assign the result of the call to initResult. > > So, I can understand that I am not using the correct approach but I > don't understand how I discarded the object I created. Can you > clarify please? Sure, the problem isn't here a ctypes issue, but a Python one. When you do the following: >>> initResult = c_short(0) you have bound the name "initResult" (a string key in a "namespace" dictionary) to a ctypes c_short object. The name "initResult" is in no way special, nor is there any "type" associated with that variable name. The fact that it has been assigned to a c_short *at this moment* does not affect any *future* value assigned to that name. >>> initResult = initScanLib( ... ) Here you have assigned whatever object is the result of initScanLib( ... ) to the name "initResult". The old object pointed to by "initResult" is no longer referenced by that name, so the Python intepreter is free to discard that old object immediately. Thus you have "discarded" the object you created by reassigning the single reference to it to another object, which leaves it free to be garbage collected (depending on Python implementation that might be instantly or eventually). Python does not have typed *variables*, every variable is a pointer to an object (PyObject *) under the covers. There is nothing in Python like: int i; short j; nothing which makes a variable type-enforcing or constrained. At least, nothing in core Python. In theory you can create a namespace which *does* allow such things, but that's getting pretty involved. Hope that helps, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From feefreelance at gmail.com Mon Jan 21 05:49:43 2013 From: feefreelance at gmail.com (feefreelance at gmail.com) Date: Mon, 21 Jan 2013 02:49:43 -0800 (PST) Subject: FREE DOWNLOAD Video Games Wii Message-ID: <3a01700a-a7e2-4384-9912-0c573a8b5320@googlegroups.com> You can find may information about video games nintendo wii Including review of PS2 Video Games, Xbox, PSP, Nintendo. It's all here completely. http://www.videogames-101.com I'm confident you'll find my website very helpful! Cheers, Oky Ade Irmawan lantabur - Trainee From kwakukwatiah at gmail.com Mon Jan 21 12:02:10 2013 From: kwakukwatiah at gmail.com (kwakukwatiah at gmail.com) Date: Mon, 21 Jan 2013 11:02:10 -0600 Subject: why not? Message-ID: <8CAC60710F6447FFA746695B2D24522B@favour> f = open(r'c:\text\somefile.txt') for i in range(3): print str(i) + ': ' + f.readline(), please with the print str(i) + ?: ? + f.readline(), why not print str(i) + f.readline(), -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Jan 21 10:56:15 2013 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 22 Jan 2013 02:56:15 +1100 Subject: why not? In-Reply-To: <8CAC60710F6447FFA746695B2D24522B@favour> References: <8CAC60710F6447FFA746695B2D24522B@favour> Message-ID: On 22/01/13 04:02, kwakukwatiah at gmail.com wrote: > f = open(r'c:\text\somefile.txt') > for i in range(3): > print str(i) + ': ' + f.readline(), > please with the print str(i) + ?: ? + f.readline(), why not print str(i) > + f.readline(), Try running both code. What do you see? What's the difference? When do you think you might want one or the other? From sjbenner at gmail.com Tue Jan 22 02:04:14 2013 From: sjbenner at gmail.com (Josh Benner) Date: Mon, 21 Jan 2013 23:04:14 -0800 Subject: why not? In-Reply-To: References: <8CAC60710F6447FFA746695B2D24522B@favour> Message-ID: On Mon, Jan 21, 2013 at 7:56 AM, Lie Ryan wrote: > On 22/01/13 04:02, kwakukwatiah at gmail.com wrote: > >> f = open(r'c:\text\somefile.txt') >> for i in range(3): >> print str(i) + ': ' + f.readline(), >> please with the print str(i) + ?: ? + f.readline(), why not print str(i) >> + f.readline(), >> > > Try running both code. What do you see? What's the difference? When do you > think you might want one or the other? > -- > http://mail.python.org/**mailman/listinfo/python-list > There is nothing 'wrong' with either print statement. The why or why not, depends on the requirements of who or what intends to 'consume' the output. In other words, what problem does this code solve? Think about which print statement produces the best output for that problem. It is also always a good idea to close the file object when you are done with it. Consider executing file operations inside a 'with' block. with open(r'c:\text\somefile.txt') as f: for i in range(3): print str(i) + ': ' + f.readline() The above code can be generalized further for use with text files that contain a variable number of lines. with open(r'c:\text\somefile.txt') as f: for index, line in enumerate( f ): print str( index ) + ': ' + f.readline() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Mon Jan 21 05:21:52 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 21 Jan 2013 11:21:52 +0100 Subject: need explanation In-Reply-To: References: Message-ID: <0fhvs9-56h.ln1@satorlaser.homedns.org> Am 21.01.2013 17:06, schrieb kwakukwatiah at gmail.com: > please I need some explanation on sys.stdin and sys.stdout, and piping out http://www.catb.org/esr/faqs/smart-questions.html Uli From steve+comp.lang.python at pearwood.info Mon Jan 21 06:42:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2013 11:42:14 GMT Subject: need explanation References: Message-ID: <50fd2995$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 Jan 2013 10:06:41 -0600, kwakukwatiah wrote: > please I need some explanation on sys.stdin and sys.stdout, and piping > out "stdin" and "stdout" (and also stderr) are three special, standard, system files used by console programs that read and write text. That's nearly all of them. "stdin" is short for "standard input". Likewise for "standard output" and "standard error". When you give the Python command: print "Hello World" the string "Hello World" is written to stdout, which then displays it in the console. "stderr" is similar, except that it is used for error messages. And stdin is used for input, rather than output. So, in Python, I can do this: py> import sys py> sys.stdout.write("Hello world\n") Hello world But of course normally you would just use print. Using sys.stdout, sys.stdin and sys.stderr in Python is usually considered moderately advanced. Beginners do not usually need to care about them. These three special files do *not* live on the disk. There is no disk file called "stdout" unless you create one yourself, and if you do, it won't be special, it will just be an ordinary file with the name "stdout". These standard files are used in Unix and Linux, and less so in Windows, for console applications. For example, under Linux I might write this command: [steve at ando ~]$ touch foo [steve at ando ~]$ ls foo foo The output of the `ls` command is written to stdout, which displays it on the console. But I can *redirect* that output to a real file on disk: [steve at ando ~]$ ls foo > /tmp/a [steve at ando ~]$ cat /tmp/a foo Errors don't go to stdout, they go to stderr: [steve at ando ~]$ ls bar > /tmp/a ls: bar: No such file or directory Because there is no file called "bar", the `ls` command writes an error message to stderr. Even though I am redirecting stdout, I am not touching stderr, so it prints to the console. Of course there is a way to redirect stderr as well: [steve at ando ~]$ ls bar 2> /tmp/a [steve at ando ~]$ cat /tmp/a ls: bar: No such file or directory Similarly, you can redirect stdin, or you can use a pipe | to turn the output of one command into the input of another command. This is mostly useful when using something like command.com in Windows, not so common in Python. -- Steven From borkintom at gmail.com Mon Jan 21 06:25:06 2013 From: borkintom at gmail.com (Tom Borkin) Date: Mon, 21 Jan 2013 07:25:06 -0400 Subject: Windows subprocess.call problem Message-ID: Hi; I have this code: #!/Python27/python import os, subprocess, sys lyrics_path = "/Users/Tom/Documents/lyrics" os.chdir(lyrics_path) songs = ['livin-la-vida-loca', 'whos-that-lady'] for song in songs: subprocess.call(['notepad.exe', '%s.txt' % song]) my_songs_path = "aa english lyrics" os.chdir(my_songs_path) for song in my_songs: subprocess.call(['notepad.exe', '%s.txt' % song]) print song It opens the first song and hangs on subsequent songs. It doesn't open the next song or execute the print until I have closed the first one. I want it to open all in the list, one after another, so I have all those songs available. Please advise. TIA, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Mon Jan 21 06:33:34 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 21 Jan 2013 11:33:34 +0000 Subject: Windows subprocess.call problem In-Reply-To: References: Message-ID: <50FD278E.4060007@timgolden.me.uk> On 21/01/2013 11:25, Tom Borkin wrote: > Hi; > I have this code: > > #!/Python27/python > import os, subprocess, sys > lyrics_path = "/Users/Tom/Documents/lyrics" > os.chdir(lyrics_path) > > songs = ['livin-la-vida-loca', 'whos-that-lady'] > for song in songs: > subprocess.call(['notepad.exe', '%s.txt' % song]) > my_songs_path = "aa english lyrics" > os.chdir(my_songs_path) > for song in my_songs: > subprocess.call(['notepad.exe', '%s.txt' % song]) > print song > > It opens the first song and hangs on subsequent songs. It doesn't open > the next song or execute the print until I have closed the first one. I > want it to open all in the list, one after another, so I have all those > songs available. Please advise. subprocess.call is a convenience for starting a process and waiting for it to finish. If you want to start a process and carry on, use subprocess.Popen directly (same params) TJG From nobody at nowhere.com Mon Jan 21 06:32:25 2013 From: nobody at nowhere.com (Nobody) Date: Mon, 21 Jan 2013 11:32:25 +0000 Subject: Windows subprocess.call problem References: Message-ID: On Mon, 21 Jan 2013 07:25:06 -0400, Tom Borkin wrote: > It opens the first song and hangs on subsequent songs. It doesn't open the > next song or execute the print until I have closed the first one. I want it > to open all in the list, one after another, so I have all those songs > available. Please advise. If you want to be able to keep track of the child process (e.g. to determine when it has finished), use subprocess.Popen(). If you just want to "fire and forget", use the "start" shell command, e.g.: subprocess.call(['start', 'notepad.exe', '%s.txt' % song], shell=True) From d at davea.name Mon Jan 21 08:04:13 2013 From: d at davea.name (Dave Angel) Date: Mon, 21 Jan 2013 08:04:13 -0500 Subject: Windows subprocess.call problem In-Reply-To: References: Message-ID: <50FD3CCD.4060707@davea.name> On 01/21/2013 06:25 AM, Tom Borkin wrote: > Hi; > I have this code: > > for song in my_songs: > subprocess.call(['notepad.exe', '%s.txt' % song]) > print song > > It opens the first song and hangs on subsequent songs. It doesn't open the > next song or execute the print until I have closed the first one. I want it > to open all in the list, one after another, so I have all those songs > available. Please advise. Why not just pass all the filenames as parameters in one invocation of notepad? Assuming Notepad is written reasonably, that'll give it all to you in one window, instead of opening many separate ones. -- DaveA From borkintom at gmail.com Mon Jan 21 18:22:14 2013 From: borkintom at gmail.com (Tom Borkin) Date: Mon, 21 Jan 2013 19:22:14 -0400 Subject: Windows subprocess.call problem In-Reply-To: <50FD3CCD.4060707@davea.name> References: <50FD3CCD.4060707@davea.name> Message-ID: nobody at nowhere.com had an excellent suggestion that worked right off the bat and achieved exactly what I was after. Thanks all! Tom On Mon, Jan 21, 2013 at 9:04 AM, Dave Angel wrote: > On 01/21/2013 06:25 AM, Tom Borkin wrote: > >> Hi; >> I have this code: >> >> >> for song in my_songs: >> subprocess.call(['notepad.exe'**, '%s.txt' % song]) >> print song >> >> It opens the first song and hangs on subsequent songs. It doesn't open the >> next song or execute the print until I have closed the first one. I want >> it >> to open all in the list, one after another, so I have all those songs >> available. Please advise. >> > > Why not just pass all the filenames as parameters in one invocation of > notepad? Assuming Notepad is written reasonably, that'll give it all to > you in one window, instead of opening many separate ones. > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jan 21 18:38:27 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 21 Jan 2013 18:38:27 -0500 Subject: Windows subprocess.call problem In-Reply-To: References: <50FD3CCD.4060707@davea.name> Message-ID: On 1/21/2013 6:22 PM, Tom Borkin wrote: > nobody at nowhere.com had an excellent > suggestion that worked right off the bat and achieved exactly what I was > after. Thanks all! And what was it? > > On Mon, Jan 21, 2013 at 9:04 AM, Dave Angel > wrote: > > On 01/21/2013 06:25 AM, Tom Borkin wrote: > > Hi; > I have this code: > > > for song in my_songs: > subprocess.call(['notepad.exe'__, '%s.txt' % song]) > print song > > It opens the first song and hangs on subsequent songs. It > doesn't open the > next song or execute the print until I have closed the first > one. I want it > to open all in the list, one after another, so I have all those > songs > available. Please advise. > > > Why not just pass all the filenames as parameters in one invocation > of notepad? Assuming Notepad is written reasonably, that'll give it > all to you in one window, instead of opening many separate ones. -- Terry Jan Reedy From rosuav at gmail.com Mon Jan 21 18:43:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Jan 2013 10:43:34 +1100 Subject: Windows subprocess.call problem In-Reply-To: <50FD3CCD.4060707@davea.name> References: <50FD3CCD.4060707@davea.name> Message-ID: On Tue, Jan 22, 2013 at 12:04 AM, Dave Angel wrote: > Why not just pass all the filenames as parameters in one invocation of > notepad? Assuming Notepad is written reasonably, that'll give it all to you > in one window, instead of opening many separate ones. The OP is talking about Windows Notepad. Assuming it to be, quote, "written reasonably", unquote, is like assuming that an elected politician has a brain, or that a young child will like broccoli, or that a post from 88888 Dihedral will be useful and intelligible. Also, I just tested Notepad, and if it's given multiple parameters, it interprets them as a single filename with spaces in it (and then offers to create that file). Was worth a try though. ChrisA From steve+comp.lang.python at pearwood.info Mon Jan 21 06:37:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2013 11:37:25 GMT Subject: why not? References: Message-ID: <50fd2875$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 Jan 2013 11:02:10 -0600, kwakukwatiah wrote: > f = open(r'c:\text\somefile.txt') > for i in range(3): > print str(i) + ': ' + f.readline(), > > please with the print str(i) + ?: ? + f.readline(), > why not print str(i) + f.readline(), Because the output will be different. The first code will print: 0: first line 1: second line 2: third line The second code will print: 0first line 1second line 2third line You should really try these things and see what they do before asking. -- Steven From domainatorocc at gmail.com Mon Jan 21 09:44:20 2013 From: domainatorocc at gmail.com (Web Developers) Date: Mon, 21 Jan 2013 06:44:20 -0800 (PST) Subject: The most important website in the world for any entrepreneur Message-ID: Hello, We just launched our new site - www.webmeeters.com a couple of days back. It allows the formation of virtual "companies" made up of workers from around the world, and then allows them to be crowd-funded for any business idea they may have. The site can be used by anyone - someone in the corporate world, musicians, artists, whatever. So... please check it out, and if you like it, we'd appreciate you spreading the word and telling all your friends :) Thanks, The Webmaster, www.webmeeters.com From jhsu802701 at gmail.com Mon Jan 21 11:18:19 2013 From: jhsu802701 at gmail.com (Jason Hsu) Date: Mon, 21 Jan 2013 08:18:19 -0800 (PST) Subject: Slightly OT: What metro areas are best for a software development career? Message-ID: <0df3f09e-18fd-472d-a5cb-37fc76030f34@googlegroups.com> I am looking for a position as a software development engineer. I'm currently learning to develop Android apps (http://www.jasonhsu.com/android-apps), and I use Python for implementing Doppler Value Investing (http://www.dopplervalueinvesting.com) and for developing Swift Linux (http://www.swiftlinux.org). NOTE: Thanks to those of you who answered the questions I asked as I developed Doppler Value Investing. I currently live in Minnesota about 50 miles west of Minneapolis, and I am considering moving. What are the best metro areas (Silicon Valley, Los Angeles, San Diego, Chicago, Twin Cities, Boston, NYC, DC, etc.) for a software development career, how would you rank them, and why? The Twin Cities metro area has a technical community portal called http://tech.mn . Are there analogous technical community portals for other metro areas? From matt.walker.jones at gmail.com Mon Jan 21 11:28:42 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Mon, 21 Jan 2013 10:28:42 -0600 Subject: Slightly OT: What metro areas are best for a software development career? In-Reply-To: <0df3f09e-18fd-472d-a5cb-37fc76030f34@googlegroups.com> References: <0df3f09e-18fd-472d-a5cb-37fc76030f34@googlegroups.com> Message-ID: Check out this article. It lists some information about IT/Sofware jobs and places where you can get them. I recommend Austin personally, as I've lived for a number of years. http://msn.careerbuilder.com/Article/MSN-3218-Job-Info-and-Trends-A-closer-look-at-the-fast-growing-technology-field/?SiteId=cbmsn43218&sc_extcmp=JS_3218_advice *Matt Jones* On Mon, Jan 21, 2013 at 10:18 AM, Jason Hsu wrote: > I am looking for a position as a software development engineer. I'm > currently learning to develop Android apps ( > http://www.jasonhsu.com/android-apps), and I use Python for implementing > Doppler Value Investing (http://www.dopplervalueinvesting.com) and for > developing Swift Linux (http://www.swiftlinux.org). NOTE: Thanks to > those of you who answered the questions I asked as I developed Doppler > Value Investing. > > I currently live in Minnesota about 50 miles west of Minneapolis, and I am > considering moving. What are the best metro areas (Silicon Valley, Los > Angeles, San Diego, Chicago, Twin Cities, Boston, NYC, DC, etc.) for a > software development career, how would you rank them, and why? > > The Twin Cities metro area has a technical community portal called > http://tech.mn . Are there analogous technical community portals for > other metro areas? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Arah.Leonard at bruker-axs.com Mon Jan 21 11:58:38 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Mon, 21 Jan 2013 16:58:38 +0000 Subject: Slightly OT: What metro areas are best for a software development career? In-Reply-To: <0df3f09e-18fd-472d-a5cb-37fc76030f34@googlegroups.com> References: <0df3f09e-18fd-472d-a5cb-37fc76030f34@googlegroups.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07585C94@msnmail2.bruker-axs.com> > I am looking for a position as a software development engineer. I'm currently learning to develop Android apps (http://www.jasonhsu.com/android-apps), and I use > Python for implementing Doppler Value Investing (http://www.dopplervalueinvesting.com) and for developing Swift Linux (http://www.swiftlinux.org). NOTE: Thanks > to those of you who answered the questions I asked as I developed Doppler Value Investing. > > I currently live in Minnesota about 50 miles west of Minneapolis, and I am considering moving. What are the best metro areas (Silicon Valley, Los Angeles, San Diego, > Chicago, Twin Cities, Boston, NYC, DC, etc.) for a software development career, how would you rank them, and why? > > The Twin Cities metro area has a technical community portal called http://tech.mn . Are there analogous technical community portals for other metro areas? Well, for what it's worth, I've literally moved from coast to coast and from my experience, that really depends entirely on what kind of programming you want to do. Nevada has lots of jobs for casino-style gaming software development. Texas has a lot of industrial programming for oil rigs. Washington (state) has a lot of Microsoft-related jobs. Portland, Oregon has a lot of Intel-related jobs. Etc. (Pennsylvania just kind of sucked.) In most cases it's about what major business is in the area. So I'd say if you're not looking to be near your family or anything non-work related, then just ask yourself what you want to do, look up who does it best and where their main offices are located, and then apply for jobs there. Even if you don't get the dream job on the get-go, just getting a job that helps you move into the area makes it that much easier to continue applying for your dream job over the years. So you say that you're currently developing Android apps. Google is Android, so I'd suggest looking more around the Mountain View, CA area. (I wouldn't count on a Python-specific career anywhere though. Those kinds of jobs are ones that you have to chase to the oddest ends of the Earth because they're so rare.) Or, if you're just happy being a general programmer or switching things up a lot, then aim for the more heavily populated areas like Silicon Valley and prepare to be chewed up and spat out by random companies while you grow in experience. Just make sure to look into the cost of living in and around the area that you want to move to, keeping various forms of commuting in mind, so that you can plan for how you'll pay the rent once you find a job you like. ;) Fortunately, most major metro areas have good forms of public transportation. (Maybe not enjoyable, but dependable and affordable at least.) That, and if you have any allergies or medical conditions, keep in mind the area. Portland, OR was a lovely place to be my first year there, but my second spring there the pollen counts shot through the roof so I had to leave after a really bad bout of bronchitis. So if you have any health issues, research the area well. Even a whole year of living there isn't always enough to prove the area safe. And good luck! Sincerely, Arah Leonard From irmen.NOSPAM at xs4all.nl Mon Jan 21 14:25:54 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 21 Jan 2013 20:25:54 +0100 Subject: serpent, a serializer based around ast.literal_eval Message-ID: <50fd9644$0$6959$e4fe514c@news.xs4all.nl> Hi, I've been toying a bit with ast.literal_eval. I've come up with "serpent", a serializer based around that. Which means that it takes a Python object tree and turns it into a serialized form that can be safely read back by ast.literal_eval(). Why I wrote serpent and didn't simply use repr()+ast.literal_eval: * it serializes directly to bytes (utf-8 encoded), instead of a string, so it can immediately be saved to a file or sent over a socket * it encodes byte-types as base-64 instead of inefficient escaping notation that repr would use (this does mean you have to base-64 decode these strings manually on the receiving side to get your bytes back) * it contains a few custom serializers for several additional Python types such as uuid, datetime, array and decimal * it tries to serialize unrecognised types as a dict (you can control this with __getstate__ on your own types) * it can create a pretty-printed (indented) output for readability purposes * it works around a few quirks of ast.literal_eval() on the various Python implementations. It works with Python 2.6+ (including 3.x), IronPython 2.7+, Jython 2.7+. Serpent can be downloaded from Pypi: http://pypi.python.org/pypi/serpent A simple example session can be seen here: https://gist.github.com/4588429 I'm considering writing Java and .NET counterparts for this as well so I'll be able to exchange messages between the three. What do you think? Would you consider this useful at all? Cheers Irmen de Jong From briandenzer at gmail.com Mon Jan 21 20:56:58 2013 From: briandenzer at gmail.com (Brian D) Date: Mon, 21 Jan 2013 17:56:58 -0800 (PST) Subject: Storing class objects dynamically in an array Message-ID: Hi, I'm trying to instantiate a class object repeated times, dynamically for as many times as are required, storing each class object in a container to later write out to a database. It kind of looks like what's needed is a two-dimensional class object, but I can't quite conceptualize how to do that. A simpler approach might be to just store class objects in a dictionary, using a reference value (or table row number/ID) as the key. In the real-world application, I'm parsing row, column values out of a table in a document which will have not more than about 20 rows, but I can't expect the document output to leave columns well-ordered. I want to be able to call the class objects by their respective row number. A starter example follows, but it's clear that only the last instance of the class is stored. I'm not quite finding what I want from online searches, so what recommendations might Python users make for the best way to do this? Maybe I need to re-think the approach? Thanks, Brian class Car(object): def __init__(self, Brand, Color, Condition): self.Brand = Brand self.Color = Color self.Condition = Condition brandList = ['Ford', 'Toyota', 'Fiat'] colorList = ['Red', 'Green', 'Yellow'] conditionList = ['Excellent', 'Good', 'Needs Help'] usedCarLot = {} for c in range(0, len(brandList)): print c, brandList[c] usedCarLot[c] = Car usedCarLot[c].Brand = brandList[c] usedCarLot[c].Color = colorList[c] usedCarLot[c].Condition = conditionList[c] for k, v in usedCarLot.items(): print k, v.Brand, v.Color, v.Condition >>> 0 Ford 1 Toyota 2 Fiat 0 Fiat Yellow Needs Help 1 Fiat Yellow Needs Help 2 Fiat Yellow Needs Help From d at davea.name Mon Jan 21 21:26:22 2013 From: d at davea.name (Dave Angel) Date: Mon, 21 Jan 2013 21:26:22 -0500 Subject: Storing class objects dynamically in an array In-Reply-To: References: Message-ID: <50FDF8CE.5090009@davea.name> On 01/21/2013 08:56 PM, Brian D wrote: > Hi, > > I'm trying to instantiate a class object repeated times, dynamically for as many times as are required, storing each class object in a container to later write out to a database. It kind of looks like what's needed is a two-dimensional class object, but I can't quite conceptualize how to do that. > > A simpler approach might be to just store class objects in a dictionary, using a reference value (or table row number/ID) as the key. > > In the real-world application, I'm parsing row, column values out of a table in a document which will have not more than about 20 rows, but I can't expect the document output to leave columns well-ordered. I want to be able to call the class objects by their respective row number. > > A starter example follows, but it's clear that only the last instance of the class is stored. > > I'm not quite finding what I want from online searches, so what recommendations might Python users make for the best way to do this? > > Maybe I need to re-think the approach? > > > Thanks, > Brian > > > > class Car(object): > > def __init__(self, Brand, Color, Condition): > self.Brand = Brand > self.Color = Color > self.Condition = Condition > > brandList = ['Ford', 'Toyota', 'Fiat'] > colorList = ['Red', 'Green', 'Yellow'] > conditionList = ['Excellent', 'Good', 'Needs Help'] > > usedCarLot = {} > > for c in range(0, len(brandList)): > print c, brandList[c] > usedCarLot[c] = Car It'd work better if you actually instantiated Car, instead of just storing the class object multiple times. Consider: usedCarLot[c] = Car(brandList[c], colorList[c], conditionList[c]) > usedCarLot[c].Brand = brandList[c] > usedCarLot[c].Color = colorList[c] > usedCarLot[c].Condition = conditionList[c] > Don't do those 3, since you already had to supply the values when constructing the object. > for k, v in usedCarLot.items(): > print k, v.Brand, v.Color, v.Condition > > >>>> > 0 Ford > 1 Toyota > 2 Fiat > 0 Fiat Yellow Needs Help > 1 Fiat Yellow Needs Help > 2 Fiat Yellow Needs Help > Next time, please supply the Python version, and state what you actually expected the output to represent. -- DaveA From d at davea.name Mon Jan 21 21:30:57 2013 From: d at davea.name (Dave Angel) Date: Mon, 21 Jan 2013 21:30:57 -0500 Subject: Storing class objects dynamically in an array In-Reply-To: References: Message-ID: <50FDF9E1.7010803@davea.name> On 01/21/2013 08:56 PM, Brian D wrote: > Hi, > > I'm trying to instantiate a class object repeated times, dynamically for as many times as are required, storing each class object in a container to later write out to a database. It kind of looks like what's needed is a two-dimensional class object, but I can't quite conceptualize how to do that. > > A simpler approach might be to just store class objects in a dictionary, using a reference value (or table row number/ID) as the key. > > In the real-world application, I'm parsing row, column values out of a table in a document which will have not more than about 20 rows, but I can't expect the document output to leave columns well-ordered. I want to be able to call the class objects by their respective row number. > > A starter example follows, but it's clear that only the last instance of the class is stored. > > I'm not quite finding what I want from online searches, so what recommendations might Python users make for the best way to do this? > > Maybe I need to re-think the approach? > > > Thanks, > Brian > > > > class Car(object): > > def __init__(self, Brand, Color, Condition): > self.Brand = Brand > self.Color = Color > self.Condition = Condition > > brandList = ['Ford', 'Toyota', 'Fiat'] > colorList = ['Red', 'Green', 'Yellow'] > conditionList = ['Excellent', 'Good', 'Needs Help'] > > usedCarLot = {} > > for c in range(0, len(brandList)): > print c, brandList[c] > usedCarLot[c] = Car > usedCarLot[c].Brand = brandList[c] > usedCarLot[c].Color = colorList[c] > usedCarLot[c].Condition = conditionList[c] Or even better: (untested) for c, vals in enumerate(zip(brandList, colorList, conditionList)): usedCarLot[c] = Car(*vals) > > for k, v in usedCarLot.items(): > print k, v.Brand, v.Color, v.Condition > > >>>> > 0 Ford > 1 Toyota > 2 Fiat > 0 Fiat Yellow Needs Help > 1 Fiat Yellow Needs Help > 2 Fiat Yellow Needs Help > -- DaveA From python at mrabarnett.plus.com Mon Jan 21 21:29:50 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 22 Jan 2013 02:29:50 +0000 Subject: Storing class objects dynamically in an array In-Reply-To: References: Message-ID: <50FDF99E.8070305@mrabarnett.plus.com> On 2013-01-22 01:56, Brian D wrote: > Hi, > > I'm trying to instantiate a class object repeated times, dynamically for as many times as are required, storing each class object in a container to later write out to a database. It kind of looks like what's needed is a two-dimensional class object, but I can't quite conceptualize how to do that. > > A simpler approach might be to just store class objects in a dictionary, using a reference value (or table row number/ID) as the key. > > In the real-world application, I'm parsing row, column values out of a table in a document which will have not more than about 20 rows, but I can't expect the document output to leave columns well-ordered. I want to be able to call the class objects by their respective row number. > > A starter example follows, but it's clear that only the last instance of the class is stored. > > I'm not quite finding what I want from online searches, so what recommendations might Python users make for the best way to do this? > > Maybe I need to re-think the approach? > > > Thanks, > Brian > > > > class Car(object): > > def __init__(self, Brand, Color, Condition): > self.Brand = Brand > self.Color = Color > self.Condition = Condition > > brandList = ['Ford', 'Toyota', 'Fiat'] > colorList = ['Red', 'Green', 'Yellow'] > conditionList = ['Excellent', 'Good', 'Needs Help'] > > usedCarLot = {} > > for c in range(0, len(brandList)): > print c, brandList[c] > usedCarLot[c] = Car > usedCarLot[c].Brand = brandList[c] > usedCarLot[c].Color = colorList[c] > usedCarLot[c].Condition = conditionList[c] > > for k, v in usedCarLot.items(): > print k, v.Brand, v.Color, v.Condition > > >>>> > 0 Ford > 1 Toyota > 2 Fiat > 0 Fiat Yellow Needs Help > 1 Fiat Yellow Needs Help > 2 Fiat Yellow Needs Help > You're repeatedly putting the class itself in the dict and setting its (the class's) attributes; you're not even using the __init__ method you defined. What you should be doing is creating instances of the class: for c in range(len(brandList)): print c, brandList[c] usedCarLot[c] = Car(brandList[c], colorList[c], conditionList[c]) From briandenzer at gmail.com Mon Jan 21 22:32:17 2013 From: briandenzer at gmail.com (Brian D) Date: Mon, 21 Jan 2013 19:32:17 -0800 (PST) Subject: Storing class objects dynamically in an array In-Reply-To: References: Message-ID: <8d2eddbc-be53-42a4-9ef7-148520d16d5a@googlegroups.com> On Monday, January 21, 2013 8:29:50 PM UTC-6, MRAB wrote: > On 2013-01-22 01:56, Brian D wrote: > > > Hi, > > > > > > I'm trying to instantiate a class object repeated times, dynamically for as many times as are required, storing each class object in a container to later write out to a database. It kind of looks like what's needed is a two-dimensional class object, but I can't quite conceptualize how to do that. > > > > > > A simpler approach might be to just store class objects in a dictionary, using a reference value (or table row number/ID) as the key. > > > > > > In the real-world application, I'm parsing row, column values out of a table in a document which will have not more than about 20 rows, but I can't expect the document output to leave columns well-ordered. I want to be able to call the class objects by their respective row number. > > > > > > A starter example follows, but it's clear that only the last instance of the class is stored. > > > > > > I'm not quite finding what I want from online searches, so what recommendations might Python users make for the best way to do this? > > > > > > Maybe I need to re-think the approach? > > > > > > > > > Thanks, > > > Brian > > > > > > > > > > > > class Car(object): > > > > > > def __init__(self, Brand, Color, Condition): > > > self.Brand = Brand > > > self.Color = Color > > > self.Condition = Condition > > > > > > brandList = ['Ford', 'Toyota', 'Fiat'] > > > colorList = ['Red', 'Green', 'Yellow'] > > > conditionList = ['Excellent', 'Good', 'Needs Help'] > > > > > > usedCarLot = {} > > > > > > for c in range(0, len(brandList)): > > > print c, brandList[c] > > > usedCarLot[c] = Car > > > usedCarLot[c].Brand = brandList[c] > > > usedCarLot[c].Color = colorList[c] > > > usedCarLot[c].Condition = conditionList[c] > > > > > > for k, v in usedCarLot.items(): > > > print k, v.Brand, v.Color, v.Condition > > > > > > > > >>>> > > > 0 Ford > > > 1 Toyota > > > 2 Fiat > > > 0 Fiat Yellow Needs Help > > > 1 Fiat Yellow Needs Help > > > 2 Fiat Yellow Needs Help > > > > > You're repeatedly putting the class itself in the dict and setting its > > (the class's) attributes; you're not even using the __init__ method you > > defined. > > > > What you should be doing is creating instances of the class: > > > > for c in range(len(brandList)): > > print c, brandList[c] > > usedCarLot[c] = Car(brandList[c], colorList[c], conditionList[c]) Thanks for the quick reply Dave & MRAB. I wasn't even sure it could be done, so missing the instantiation just completely slipped. The simplest fix is as follows, but Dave, I'll try to tighten it up a little, when I turn to the real-world code, following your enumeration example. And yes, thanks for the reminder (2.7.3). The output is fine -- I just need a record number and the list of values stored in the class object. This is the quick fix -- instantiate class Car: usedCarLot[c] = Car('','','') It may not, however, be the best, most Pythonic way. Here's the full implementation. I hope this helps someone else. Thanks very much for the help! class Car(object): def __init__(self, Brand, Color, Condition): self.Brand = Brand self.Color = Color self.Condition = Condition brandList = ['Ford', 'Toyota', 'Fiat'] colorList = ['Red', 'Green', 'Yellow'] conditionList = ['Excellent', 'Good', 'Needs Help'] #usedCarLot = {0:Car, 1:Car, 2:Car} usedCarLot = {} for c in range(0, len(brandList)): #print c, brandList[c] usedCarLot[c] = Car('','','') usedCarLot[c].Brand = brandList[c] usedCarLot[c].Color = colorList[c] usedCarLot[c].Condition = conditionList[c] for k, v in usedCarLot.items(): print k, v.Brand, v.Color, v.Condition From briandenzer at gmail.com Mon Jan 21 22:32:17 2013 From: briandenzer at gmail.com (Brian D) Date: Mon, 21 Jan 2013 19:32:17 -0800 (PST) Subject: Storing class objects dynamically in an array In-Reply-To: References: Message-ID: <8d2eddbc-be53-42a4-9ef7-148520d16d5a@googlegroups.com> On Monday, January 21, 2013 8:29:50 PM UTC-6, MRAB wrote: > On 2013-01-22 01:56, Brian D wrote: > > > Hi, > > > > > > I'm trying to instantiate a class object repeated times, dynamically for as many times as are required, storing each class object in a container to later write out to a database. It kind of looks like what's needed is a two-dimensional class object, but I can't quite conceptualize how to do that. > > > > > > A simpler approach might be to just store class objects in a dictionary, using a reference value (or table row number/ID) as the key. > > > > > > In the real-world application, I'm parsing row, column values out of a table in a document which will have not more than about 20 rows, but I can't expect the document output to leave columns well-ordered. I want to be able to call the class objects by their respective row number. > > > > > > A starter example follows, but it's clear that only the last instance of the class is stored. > > > > > > I'm not quite finding what I want from online searches, so what recommendations might Python users make for the best way to do this? > > > > > > Maybe I need to re-think the approach? > > > > > > > > > Thanks, > > > Brian > > > > > > > > > > > > class Car(object): > > > > > > def __init__(self, Brand, Color, Condition): > > > self.Brand = Brand > > > self.Color = Color > > > self.Condition = Condition > > > > > > brandList = ['Ford', 'Toyota', 'Fiat'] > > > colorList = ['Red', 'Green', 'Yellow'] > > > conditionList = ['Excellent', 'Good', 'Needs Help'] > > > > > > usedCarLot = {} > > > > > > for c in range(0, len(brandList)): > > > print c, brandList[c] > > > usedCarLot[c] = Car > > > usedCarLot[c].Brand = brandList[c] > > > usedCarLot[c].Color = colorList[c] > > > usedCarLot[c].Condition = conditionList[c] > > > > > > for k, v in usedCarLot.items(): > > > print k, v.Brand, v.Color, v.Condition > > > > > > > > >>>> > > > 0 Ford > > > 1 Toyota > > > 2 Fiat > > > 0 Fiat Yellow Needs Help > > > 1 Fiat Yellow Needs Help > > > 2 Fiat Yellow Needs Help > > > > > You're repeatedly putting the class itself in the dict and setting its > > (the class's) attributes; you're not even using the __init__ method you > > defined. > > > > What you should be doing is creating instances of the class: > > > > for c in range(len(brandList)): > > print c, brandList[c] > > usedCarLot[c] = Car(brandList[c], colorList[c], conditionList[c]) Thanks for the quick reply Dave & MRAB. I wasn't even sure it could be done, so missing the instantiation just completely slipped. The simplest fix is as follows, but Dave, I'll try to tighten it up a little, when I turn to the real-world code, following your enumeration example. And yes, thanks for the reminder (2.7.3). The output is fine -- I just need a record number and the list of values stored in the class object. This is the quick fix -- instantiate class Car: usedCarLot[c] = Car('','','') It may not, however, be the best, most Pythonic way. Here's the full implementation. I hope this helps someone else. Thanks very much for the help! class Car(object): def __init__(self, Brand, Color, Condition): self.Brand = Brand self.Color = Color self.Condition = Condition brandList = ['Ford', 'Toyota', 'Fiat'] colorList = ['Red', 'Green', 'Yellow'] conditionList = ['Excellent', 'Good', 'Needs Help'] #usedCarLot = {0:Car, 1:Car, 2:Car} usedCarLot = {} for c in range(0, len(brandList)): #print c, brandList[c] usedCarLot[c] = Car('','','') usedCarLot[c].Brand = brandList[c] usedCarLot[c].Color = colorList[c] usedCarLot[c].Condition = conditionList[c] for k, v in usedCarLot.items(): print k, v.Brand, v.Color, v.Condition From monosij.forums at gmail.com Mon Jan 21 23:55:05 2013 From: monosij.forums at gmail.com (monosij.forums at gmail.com) Date: Mon, 21 Jan 2013 20:55:05 -0800 (PST) Subject: pycache directories Message-ID: <841fcc01-df05-4a8b-8b4f-1217c49aac44@googlegroups.com> I am doing some OO python3 where I am using multiple dirs/sub-dirs. So everything works fine, however when I run code __pycache__ directories are being created in every directory touched by the execution. Is it possible to set a configuration to be able to create these pycache directories in a specific location? Coming from the Java world - am used to the /src, /bin aspects - so somewhat prefer the 'executables' out of the way. I am using python3 on Ubuntu so wondering if there is some environ setting? Thanks for your help. From tjreedy at udel.edu Tue Jan 22 01:01:44 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Jan 2013 01:01:44 -0500 Subject: pycache directories In-Reply-To: <841fcc01-df05-4a8b-8b4f-1217c49aac44@googlegroups.com> References: <841fcc01-df05-4a8b-8b4f-1217c49aac44@googlegroups.com> Message-ID: On 1/21/2013 11:55 PM, monosij.forums at gmail.com wrote: > I am doing some OO python3 where I am using multiple dirs/sub-dirs. > > So everything works fine, however when I run code __pycache__ > directories are being created in every directory touched by the > execution. This is much better than having multiple .pyc files in every directory, as in Py2. You should soon learn to ignore them. > Is it possible to set a configuration to be able to create these > pycache directories in a specific location? No. (I am very sure.) You can however, not have the .pyc files written, but that means recompile with every run. So that option is meant for running off a read-only medium. -- Terry Jan Reedy From monosij.forums at gmail.com Tue Jan 22 18:44:06 2013 From: monosij.forums at gmail.com (monosij.forums at gmail.com) Date: Tue, 22 Jan 2013 15:44:06 -0800 (PST) Subject: pycache directories In-Reply-To: References: <841fcc01-df05-4a8b-8b4f-1217c49aac44@googlegroups.com> Message-ID: <437b29ed-14ae-4b22-9cb2-48ab629bf7ba@googlegroups.com> On Tuesday, January 22, 2013 1:01:44 AM UTC-5, Terry Reedy wrote: > > > I am doing some OO python3 where I am using multiple dirs/sub-dirs. > > > > > > So everything works fine, however when I run code __pycache__ > > > directories are being created in every directory touched by the > > > execution. > > > > This is much better than having multiple .pyc files in every directory, > > as in Py2. You should soon learn to ignore them. > > > > > Is it possible to set a configuration to be able to create these > > > pycache directories in a specific location? > > > > No. (I am very sure.) You can however, not have the .pyc files written, > > but that means recompile with every run. So that option is meant for > > running off a read-only medium. > > > > -- > > Terry Jan Reedy Thanks Terry. I understand needing to adjust. Appreciate this forum. Monosij From monosij.forums at gmail.com Tue Jan 22 18:44:06 2013 From: monosij.forums at gmail.com (monosij.forums at gmail.com) Date: Tue, 22 Jan 2013 15:44:06 -0800 (PST) Subject: pycache directories In-Reply-To: References: <841fcc01-df05-4a8b-8b4f-1217c49aac44@googlegroups.com> Message-ID: <437b29ed-14ae-4b22-9cb2-48ab629bf7ba@googlegroups.com> On Tuesday, January 22, 2013 1:01:44 AM UTC-5, Terry Reedy wrote: > > > I am doing some OO python3 where I am using multiple dirs/sub-dirs. > > > > > > So everything works fine, however when I run code __pycache__ > > > directories are being created in every directory touched by the > > > execution. > > > > This is much better than having multiple .pyc files in every directory, > > as in Py2. You should soon learn to ignore them. > > > > > Is it possible to set a configuration to be able to create these > > > pycache directories in a specific location? > > > > No. (I am very sure.) You can however, not have the .pyc files written, > > but that means recompile with every run. So that option is meant for > > running off a read-only medium. > > > > -- > > Terry Jan Reedy Thanks Terry. I understand needing to adjust. Appreciate this forum. Monosij From bryanjugglercryptographer at yahoo.com Tue Jan 22 03:57:50 2013 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Tue, 22 Jan 2013 00:57:50 -0800 (PST) Subject: PyWart fixed mostly, was: Re: Python Gotcha's? Message-ID: <6d9efb3a-993f-46c5-b7a4-7c06808ace18@p1g2000pbc.googlegroups.com> On Apr 14 2012, 2:47 pm I wrote: > Miki Tebeka wrote: > > If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. > > Python 3(K) likes to use the same '.py' file extension as its > incompatible predecessors, and in some/many/most *nix implementations, > it likes to install in the same place. Python 3 is an improvement upon > Python 2, but Python went from, "sure... Python just works," to, > "well... that depends... which Python?" My "gotcha" is addressed by PEP 394, "The 'python' Command on Unix- Like Systems", and PEP 397, "A Python launcher for Windows". They alleviate much of that pain and suffering of running both Python 2.x and 3.x. On *nix systems, if a Python 2 interpreter is available it should be runnable as "python2". If Python 3 is available, it should runnable as "python3". The modern Python shebang line is "#!/usr/bin/env python3". [PEP 394] On Microsoft Windows, the latest and greatest Python installation, 3.3, no longer usurps the ".py" extension for its own version-specific interpreter. It associates ".py" with a multi-version launcher, called "py", that makes a reasonable attempt to do the right thing py-version- wise. The modern shebang line will help even on MS-Windows. [PEP 397] There's room for improvement. The launcher invocation, "py", should work on Unix. And everywhere it runs it should respect shebang lines that name itself. The modern shebang line ought to be "#!/usr/bin/env py -3" (but it's not yet so don't use it). The other big idea in supporting multiple Pythons is virtual environments. Python 3.3 has PEP 405, virtual environments in the core. Unfortunately the aforementioned PEP 397 windows launcher, also in Python 3.3, ignores an active virtual environment. Be warned. -Bryan From mail at timgolden.me.uk Tue Jan 22 04:24:23 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 22 Jan 2013 09:24:23 +0000 Subject: Retrieving the full command line Message-ID: <50FE5AC7.3050909@timgolden.me.uk> [Python 2.7/3.3 (and hg tip) running on Windows. Not Windows-specific, though]. I use the python -mpackage incantation to run a package which has a __main__.py module and which uses relative imports internally. I'm developing under cherrypy which includes a reloader for development. The reloader attempts to rebuild the original command line by combining sys.executable and sys.argv and then does an execv. There does not appear to be any way within Python of determining the command line I used. The combination of sys.executable and sys.argv in this case will look like: "c:\python33\python.exe app/__main__.py". But running this precludes the use of package-relative imports. I can pull the command line out of the Windows API to solve this specific problem, but is there not a gap here? Even if sys.flags somehow indicated the -m (it doesn't) that wouldn't give me the filepath which it used. Have I missed something? TJG From tjreedy at udel.edu Tue Jan 22 09:53:37 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Jan 2013 09:53:37 -0500 Subject: Retrieving the full command line In-Reply-To: <50FE5AC7.3050909@timgolden.me.uk> References: <50FE5AC7.3050909@timgolden.me.uk> Message-ID: On 1/22/2013 4:24 AM, Tim Golden wrote: > [Python 2.7/3.3 (and hg tip) running on Windows. Not Windows-specific, > though]. > > I use the python -mpackage incantation to run a package which has a > __main__.py module and which uses relative imports internally. > > I'm developing under cherrypy which includes a reloader for development. > The reloader attempts to rebuild the original > command line by combining sys.executable and sys.argv and then does an > execv. > > There does not appear to be any way within Python of determining the > command line I used. The combination of sys.executable and sys.argv in > this case will look like: "c:\python33\python.exe app/__main__.py". But > running this precludes the use of package-relative imports. If I understand right, the reloader should be updated to translate 'x/__main__.py' to '-m x'. Filenames of form'__x__' are reserved, in a sense, like similar identifiers in programs, and '__main__.py' should not be used for a file meant to executed directly. -- Terry Jan Reedy From mail at timgolden.me.uk Tue Jan 22 10:07:18 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 22 Jan 2013 15:07:18 +0000 Subject: Retrieving the full command line In-Reply-To: References: <50FE5AC7.3050909@timgolden.me.uk> Message-ID: <50FEAB26.7010601@timgolden.me.uk> On 22/01/2013 14:53, Terry Reedy wrote: > On 1/22/2013 4:24 AM, Tim Golden wrote: >> [Python 2.7/3.3 (and hg tip) running on Windows. Not Windows-specific, >> though]. >> >> I use the python -mpackage incantation to run a package which has a >> __main__.py module and which uses relative imports internally. >> >> I'm developing under cherrypy which includes a reloader for development. >> The reloader attempts to rebuild the original >> command line by combining sys.executable and sys.argv and then does an >> execv. >> >> There does not appear to be any way within Python of determining the >> command line I used. The combination of sys.executable and sys.argv in >> this case will look like: "c:\python33\python.exe app/__main__.py". But >> running this precludes the use of package-relative imports. > > If I understand right, the reloader should be updated to translate > 'x/__main__.py' to '-m x'. Filenames of form'__x__' are reserved, in a > sense, like similar identifiers in programs, and '__main__.py' should > not be used for a file meant to executed directly. To be clear: it's Python itself, not the reloader, which is coming up with __main__.py. sys.executable is "c:\python33\python.exe" and sys.argv is ['c:\path\to\__main__.py'] for a program which has been started by "c:\python33\python.exe -mpath\to". Obviously, there is any number of ways around this specific issue, including what you suggest: a canonical rewrite of "python path\to\__main__.py" into "python -mpath\to". But it's not clear to me that this rewrite should be the responsibility of calling code. TJG From steve+comp.lang.python at pearwood.info Tue Jan 22 18:46:49 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:46:49 GMT Subject: Retrieving the full command line References: <50FE5AC7.3050909@timgolden.me.uk> Message-ID: <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 15:07:18 +0000, Tim Golden wrote: > On 22/01/2013 14:53, Terry Reedy wrote: >> On 1/22/2013 4:24 AM, Tim Golden wrote: >>> [Python 2.7/3.3 (and hg tip) running on Windows. Not Windows-specific, >>> though]. >>> >>> I use the python -mpackage incantation to run a package which has a >>> __main__.py module and which uses relative imports internally. >>> >>> I'm developing under cherrypy which includes a reloader for >>> development. The reloader attempts to rebuild the original command >>> line by combining sys.executable and sys.argv and then does an execv. >>> >>> There does not appear to be any way within Python of determining the >>> command line I used. The combination of sys.executable and sys.argv in >>> this case will look like: "c:\python33\python.exe app/__main__.py". >>> But running this precludes the use of package-relative imports. >> >> If I understand right, the reloader should be updated to translate >> 'x/__main__.py' to '-m x'. Filenames of form'__x__' are reserved, in a >> sense, like similar identifiers in programs, and '__main__.py' should >> not be used for a file meant to executed directly. > > To be clear: it's Python itself, not the reloader, which is coming up > with __main__.py. sys.executable is "c:\python33\python.exe" and > sys.argv is ['c:\path\to\__main__.py'] for a program which has been > started by "c:\python33\python.exe -mpath\to". I don't believe you can give direct paths to the -m flag. It uses the normal import mechanism to locate a module or package, so you have to give it a name which would be importable. c:\python33\python.exe -m app would work, where "app" is either a package or module: C:\something\on\PYTHONPATH\app\__main__.py C:\something\on\PYTHONPATH\app.py > Obviously, there is any number of ways around this specific issue, > including what you suggest: a canonical rewrite of "python > path\to\__main__.py" into "python -mpath\to". But it's not clear to me > that this rewrite should be the responsibility of calling code. I am a bit disturbed that you cannot distinguish between: python C:\something\on\pythonpath\app\__main__.py python -m app by inspecting the command line. I consider it a bug, or at least a misfeature, if Python transforms the command line before making it available in sys.argv. -- Steven From oscar.j.benjamin at gmail.com Tue Jan 22 19:53:21 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 00:53:21 +0000 Subject: Retrieving the full command line In-Reply-To: <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22 January 2013 23:46, Steven D'Aprano wrote: [SNIP] > > I am a bit disturbed that you cannot distinguish between: > > python C:\something\on\pythonpath\app\__main__.py > > python -m app > > > by inspecting the command line. I consider it a bug, or at least a > misfeature, if Python transforms the command line before making it > available in sys.argv. The purpose of the -m option is that you can run a script that is located via the Python import path instead of an explicit file path. The idea is that if '/path/to/somewhere' is in sys.path then: python -m script arg1 arg2 is equivalent to python /path/to/somewhere/script.py arg1 arg2 If Python didn't modify sys.argv then 'script.py' would need to be rewritten to understand that sys.argv would be in a different format when it was invoked using the -m option. I believe that it has previously been proposed to include something like sys.raw_argv, although perhaps for different reasons. Although something that might be more useful to the OP (and that I at one point wanted) would be a function similar to execfile but that would launch a separate process using the same interpreter as the current process. Oscar From steve+comp.lang.python at pearwood.info Tue Jan 22 22:58:52 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2013 03:58:52 GMT Subject: Retrieving the full command line References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> On Wed, 23 Jan 2013 00:53:21 +0000, Oscar Benjamin wrote: > On 22 January 2013 23:46, Steven D'Aprano > wrote: [SNIP] >> >> I am a bit disturbed that you cannot distinguish between: >> >> python C:\something\on\pythonpath\app\__main__.py >> >> python -m app >> >> >> by inspecting the command line. I consider it a bug, or at least a >> misfeature, if Python transforms the command line before making it >> available in sys.argv. > > The purpose of the -m option is that you can run a script that is > located via the Python import path instead of an explicit file path. The > idea is that if '/path/to/somewhere' is in sys.path then: > python -m script arg1 arg2 > is equivalent to > python /path/to/somewhere/script.py arg1 arg2 > > If Python didn't modify sys.argv then 'script.py' would need to be > rewritten to understand that sys.argv would be in a different format > when it was invoked using the -m option. I don't think that it would be in a different format. Normally people only care about sys.argv[1:], the actual arguments. argv[0], the name of the script, already comes in multiple formats: absolute or relative paths. Currently, if I have a package __main__.py that prints sys.argv, I get results like this: steve at runes:~$ python3.3 /home/steve/python/testpackage/__main__.py ham spam eggs ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] which is correct, that's what I gave on the command line. But: steve at runes:~$ python3.3 -m testpackage ham spam eggs ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] The second example is lying. It should say: ['-m testpackage', 'ham', 'spam', 'eggs'] If you are one of the few people who care about argv[0], then you are already dealing with the fact that the name of the executable script is not always an absolute path and therefore can vary greatly from one call to another. Hell, if you are on a system with soft links, the name of the script in the command line is not even necessarily the name of the module. So there's not much more effort involved in dealing with one extra case: # assuming you care, which most people don't if sys.argv[0].startswith('-m'): do_something() elif os.path.isabs(sys.argv[0]): do_this() else: # relative path do_that() -- Steven From mail at timgolden.me.uk Wed Jan 23 04:58:02 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 23 Jan 2013 09:58:02 +0000 Subject: Retrieving the full command line In-Reply-To: <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50FFB42A.7040402@timgolden.me.uk> On 23/01/2013 03:58, Steven D'Aprano wrote: > Currently, if I have a package __main__.py that prints sys.argv, I get > results like this: > > steve at runes:~$ python3.3 /home/steve/python/testpackage/__main__.py ham > spam eggs > ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] > > > which is correct, that's what I gave on the command line. But: > > steve at runes:~$ python3.3 -m testpackage ham spam eggs > ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] > > > The second example is lying. It should say: > > ['-m testpackage', 'ham', 'spam', 'eggs'] Thanks for the input, Steven & Oscar. Apologies for the confusion over my initial example. Of course, -m runs something on sys.path, not something in the filesystem as such. I confused myself because, running on Windows where the current directory is on the path, I sit in c:\path\to and do python -mapp Now I look harder, this discussion is basically issue14208: http://bugs.python.org/issue14208 so I'll probably go and contribute over there. TJG From oscar.j.benjamin at gmail.com Wed Jan 23 05:01:24 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 10:01:24 +0000 Subject: Retrieving the full command line In-Reply-To: <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23 January 2013 03:58, Steven D'Aprano wrote: > On Wed, 23 Jan 2013 00:53:21 +0000, Oscar Benjamin wrote: > >> On 22 January 2013 23:46, Steven D'Aprano >> wrote: [SNIP] >>> >> The purpose of the -m option is that you can run a script that is >> located via the Python import path instead of an explicit file path. The >> idea is that if '/path/to/somewhere' is in sys.path then: >> python -m script arg1 arg2 >> is equivalent to >> python /path/to/somewhere/script.py arg1 arg2 >> >> If Python didn't modify sys.argv then 'script.py' would need to be >> rewritten to understand that sys.argv would be in a different format >> when it was invoked using the -m option. > > I don't think that it would be in a different format. Normally people > only care about sys.argv[1:], the actual arguments. argv[0], the name of > the script, already comes in multiple formats: absolute or relative paths. > > Currently, if I have a package __main__.py that prints sys.argv, I get > results like this: > > steve at runes:~$ python3.3 /home/steve/python/testpackage/__main__.py ham > spam eggs > ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] > > > which is correct, that's what I gave on the command line. But: > > steve at runes:~$ python3.3 -m testpackage ham spam eggs > ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] > > > The second example is lying. It should say: > > ['-m testpackage', 'ham', 'spam', 'eggs'] I don't know why you would expect this. I imagined that you would want ['-m', 'testpackage', 'ham', 'spam', 'eggs'] If the two were combined into one string I would expect it to at least be a valid argument list: ['-mtestpackage', 'ham', 'spam', 'eggs'] > > > If you are one of the few people who care about argv[0], then you are > already dealing with the fact that the name of the executable script is > not always an absolute path and therefore can vary greatly from one call > to another. Hell, if you are on a system with soft links, the name of the > script in the command line is not even necessarily the name of the > module. So there's not much more effort involved in dealing with one > extra case: Unless I've missed something sys.argv[0] is always a valid path to the script. Whether it is absolute or not shouldn't matter. For imported modules the path is available from __name__. For a script that is executed rather than imported __name__ == "__main__" but the path is accessible from sys.argv[0]. If you are one of those people who cares about sys.argv[0] then this is probably the value that you wanted it to contain. If it were important for sys.argv to show how exactly the script was located and executed, then why not also include the 'python3.3' command line argument (the real argv[0])? sys.argv emulates the argv that e.g. a C program would get. The real command line used is not exactly the same since a Python script is not a directly executable binary, so Python processes the argument list before passing it through. In the OP's case, the script is never invoked without -m so the following works: cmdline = [sys.executable, '-m', __package__] + sys.argv[1:] In the more general case it would be better to have an API specifically for this purpose. Oscar From steve+comp.lang.python at pearwood.info Wed Jan 23 23:49:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Jan 2013 04:49:13 GMT Subject: Retrieving the full command line References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> On Wed, 23 Jan 2013 10:01:24 +0000, Oscar Benjamin wrote: > On 23 January 2013 03:58, Steven D'Aprano > wrote: >> On Wed, 23 Jan 2013 00:53:21 +0000, Oscar Benjamin wrote: >> >>> On 22 January 2013 23:46, Steven D'Aprano >>> wrote: [SNIP] >>>> >>> The purpose of the -m option is that you can run a script that is >>> located via the Python import path instead of an explicit file path. >>> The idea is that if '/path/to/somewhere' is in sys.path then: >>> python -m script arg1 arg2 >>> is equivalent to >>> python /path/to/somewhere/script.py arg1 arg2 >>> >>> If Python didn't modify sys.argv then 'script.py' would need to be >>> rewritten to understand that sys.argv would be in a different format >>> when it was invoked using the -m option. >> >> I don't think that it would be in a different format. Normally people >> only care about sys.argv[1:], the actual arguments. argv[0], the name >> of the script, already comes in multiple formats: absolute or relative >> paths. >> >> Currently, if I have a package __main__.py that prints sys.argv, I get >> results like this: >> >> steve at runes:~$ python3.3 /home/steve/python/testpackage/__main__.py ham >> spam eggs >> ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] >> >> >> which is correct, that's what I gave on the command line. But: >> >> steve at runes:~$ python3.3 -m testpackage ham spam eggs >> ['/home/steve/python/testpackage/__main__.py', 'ham', 'spam', 'eggs'] >> >> >> The second example is lying. It should say: >> >> ['-m testpackage', 'ham', 'spam', 'eggs'] > > I don't know why you would expect this. I imagined that you would want > > ['-m', 'testpackage', 'ham', 'spam', 'eggs'] No. argv[0] is intended to be the script being called, argv[1:] for the arguments to the script. Given the two choices: 1) Break every Python script that expects argv[1:] to be the arguments to the script, forcing them to decide whether they should look at argv[1:] or argv[2:] according to whether or not argv[0] == '-m'; or 2) don't break anything, but make a very small addition to the semantics of argv[0] (was: "the path to the script", add "or -m and the name of module/package") that won't break anyone's code; there's practically no choice in the matter. > If the two were combined into one string I would expect it to at least > be a valid argument list: > > ['-mtestpackage', 'ham', 'spam', 'eggs'] Okay, fair point. I didn't consider that. Note however that there is an ambiguity between calling "python -mspam" and calling a script literally named "-mspam". But that same ambiguity exists in the shell, so I don't consider it a problem. You cannot call a script named -mspam unless you use something like this "python ./-mspam". >> If you are one of the few people who care about argv[0], then you are >> already dealing with the fact that the name of the executable script is >> not always an absolute path and therefore can vary greatly from one >> call to another. Hell, if you are on a system with soft links, the name >> of the script in the command line is not even necessarily the name of >> the module. So there's not much more effort involved in dealing with >> one extra case: > > Unless I've missed something sys.argv[0] is always a valid path to the > script. Whether it is absolute or not shouldn't matter. Sure. But if you care about argv[0] (say, you want to pull out the name of the script at runtime, instead of hard-coding it), then you need to be aware that you could be given an absolute path, a relative path, a bare script name, or the path of a softlink to the file you actually care about. Adding one more trivially simple case is not a large burden. People hardly ever care about argv[0]. At least, I don't think I ever have. But the OP does, and Python mangling argv[0] is causing him grief because it lies, claiming to have called the __main__.py of his package directly when in fact he called it with -m. > For imported > modules the path is available from __name__. For a script that is > executed rather than imported __name__ == "__main__" but the path is > accessible from sys.argv[0]. If you are one of those people who cares > about sys.argv[0] then this is probably the value that you wanted it to > contain. I'm wary about guessing what people "probably" want, and therefore lying about what they actually got. That's DWIM coding, and that almost always ends in tears. > If it were important for sys.argv to show how exactly the script was > located and executed, then why not also include the 'python3.3' command > line argument (the real argv[0])? sys.argv emulates the argv that e.g. a > C program would get. The real command line used is not exactly the same > since a Python script is not a directly executable binary, so Python > processes the argument list before passing it through. Also a good point. To some degree, we're constrained by backwards compatibility -- there's only so much change we can do without breaking code, and setting argv[0] to the python executable instead of the script is too big a change. In any case, you can get that information using sys.executable, or at least you can get the path of the actual Python binary, or you can use sys.version (or equivalent) to determine which version of Python you're using. This does mean that you can't play dirty hacks like some C binaries do, where they change their behaviour depending on whether you call them via one path or another path. vi does that. But that's hardly a big loss. Contrariwise, I don't believe that there is currently *any* way to distinguish between running a script with or without -m. That should be fixed. -- Steven From rosuav at gmail.com Thu Jan 24 00:06:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 16:06:45 +1100 Subject: Retrieving the full command line In-Reply-To: <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 24, 2013 at 3:49 PM, Steven D'Aprano wrote: > Note however that there is an ambiguity between calling "python -mspam" > and calling a script literally named "-mspam". But that same ambiguity > exists in the shell, so I don't consider it a problem. You cannot call a > script named -mspam unless you use something like this "python ./-mspam". Another spanner for your works: "python -- -mspam" succeeds. That sets argv[0] to '-mspam'. > People hardly ever care about argv[0]. At least, I don't think I ever > have. But the OP does, and Python mangling argv[0] is causing him grief > because it lies, claiming to have called the __main__.py of his package > directly when in fact he called it with -m. Usually when I reference argv[0], $0, or any equivalent, it's for a usage display - eg: USAGE: $0 [opts] infile [outfile] --foo Fooify the file --bar Burn your computer to the ground So I don't particularly care about symlinks or relative paths (if it worked once, it'll probably work another time). But ambiguities may be an issue. ChrisA From oscar.j.benjamin at gmail.com Thu Jan 24 05:06:37 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 10:06:37 +0000 Subject: Retrieving the full command line In-Reply-To: <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24 January 2013 04:49, Steven D'Aprano wrote: [SNIP] > > Contrariwise, I don't believe that there is currently *any* way to > distinguish between running a script with or without -m. That should be > fixed. As I said earlier in the thread, the __package__ module global distinguishes the two cases: ~$ mkdir pkg ~$ touch pkg/__init__.py ~$ vim pkg/__main__.py ~$ cat pkg/__main__.py import sys if __package__ is None: cmdline = [sys.executable] + sys.argv else: cmdline = [sys.executable, '-m', __package__] + sys.argv[1:] print(cmdline) ~$ python pkg/__main__.py arg1 arg2 ['q:\\tools\\Python27\\python.exe', 'pkg/__main__.py', 'arg1', 'arg2'] ~$ python -m pkg arg1 arg2 ['q:\\tools\\Python27\\python.exe', '-m', 'pkg', 'arg1', 'arg2'] Oscar From mail at timgolden.me.uk Thu Jan 24 05:56:00 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2013 10:56:00 +0000 Subject: Retrieving the full command line In-Reply-To: References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51011340.6020309@timgolden.me.uk> On 24/01/2013 10:06, Oscar Benjamin wrote: > On 24 January 2013 04:49, Steven D'Aprano > wrote: > [SNIP] >> >> Contrariwise, I don't believe that there is currently *any* way to >> distinguish between running a script with or without -m. That should be >> fixed. > > As I said earlier in the thread, the __package__ module global > distinguishes the two cases: > > ~$ mkdir pkg > ~$ touch pkg/__init__.py > ~$ vim pkg/__main__.py > ~$ cat pkg/__main__.py > import sys > if __package__ is None: > cmdline = [sys.executable] + sys.argv > else: > cmdline = [sys.executable, '-m', __package__] + sys.argv[1:] > print(cmdline) > ~$ python pkg/__main__.py arg1 arg2 > ['q:\\tools\\Python27\\python.exe', 'pkg/__main__.py', 'arg1', 'arg2'] > ~$ python -m pkg arg1 arg2 > ['q:\\tools\\Python27\\python.exe', '-m', 'pkg', 'arg1', 'arg2'] Reasonable (and thanks for the clear example), but it doesn't work if the package which is reconstructing the command line the package which was the target of the original command line. In my case, I'm making use of the cherrypy reloader, whose __package__ is cherrypy.process. But the command which invoked the program was python -m myapp. ie I'm issuing "python -m myapp". In myapp.__main__ I'm importing cherrypy, itself a package, and somewhere in cherrypy.whatever there is code which attempts to reconstruct the command line. TJG From mail at timgolden.me.uk Thu Jan 24 06:04:36 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2013 11:04:36 +0000 Subject: Retrieving the full command line In-Reply-To: <51011340.6020309@timgolden.me.uk> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> Message-ID: <51011544.9030402@timgolden.me.uk> On 24/01/2013 10:56, Tim Golden wrote: > if the package which is reconstructing the command line the package > which was the target of the original command line. Sorry: if the package which is reconstructing the command line *is not* the package which was the target of the original command line. TJG From oscar.j.benjamin at gmail.com Thu Jan 24 06:30:29 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 11:30:29 +0000 Subject: Retrieving the full command line In-Reply-To: <51011340.6020309@timgolden.me.uk> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> Message-ID: On 24 January 2013 10:56, Tim Golden wrote: > On 24/01/2013 10:06, Oscar Benjamin wrote: >> On 24 January 2013 04:49, Steven D'Aprano >> wrote: >> [SNIP] >>> >>> Contrariwise, I don't believe that there is currently *any* way to >>> distinguish between running a script with or without -m. That should be >>> fixed. >> >> As I said earlier in the thread, the __package__ module global >> distinguishes the two cases: >> >> ~$ mkdir pkg >> ~$ touch pkg/__init__.py >> ~$ vim pkg/__main__.py >> ~$ cat pkg/__main__.py >> import sys >> if __package__ is None: >> cmdline = [sys.executable] + sys.argv >> else: >> cmdline = [sys.executable, '-m', __package__] + sys.argv[1:] >> print(cmdline) >> ~$ python pkg/__main__.py arg1 arg2 >> ['q:\\tools\\Python27\\python.exe', 'pkg/__main__.py', 'arg1', 'arg2'] >> ~$ python -m pkg arg1 arg2 >> ['q:\\tools\\Python27\\python.exe', '-m', 'pkg', 'arg1', 'arg2'] > > Reasonable (and thanks for the clear example), but it doesn't work > if the package which is reconstructing the command line the package > which was the target of the original command line. In my case, > I'm making use of the cherrypy reloader, whose __package__ is > cherrypy.process. But the command which invoked the program was > python -m myapp. > > ie I'm issuing "python -m myapp". In myapp.__main__ I'm importing > cherrypy, itself a package, and somewhere in cherrypy.whatever there is > code which attempts to reconstruct the command line. Easy enough: ~$ mkdir pkg ~$ touch pkg/__init__.py ~$ vim pkg/__main__.py ~$ cat pkg/__main__.py import pkg.whatever ~$ vim pkg/whatever.py ~$ cat pkg/whatever.py import sys import pkg.__main__ as main cmdline = [sys.executable, '-m', main.__package__] + sys.argv[1:] print(cmdline) ~$ python -m pkg ['q:\\tools\\Python27\\python.exe', '-m', 'pkg'] ~$ python -m pkg arg1 arg32 ['q:\\tools\\Python27\\python.exe', '-m', 'pkg', 'arg1', 'arg32'] I don't really understand what your spec is. Why do you need to inspect this information from sys.argv? Can you not just always use 'python -m pkg' as your entry point? Oscar From mail at timgolden.me.uk Thu Jan 24 08:45:48 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2013 13:45:48 +0000 Subject: Retrieving the full command line In-Reply-To: References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> Message-ID: <51013B0C.6000309@timgolden.me.uk> On 24/01/2013 11:30, Oscar Benjamin wrote: > I don't really understand what your spec is. Why do you need to > inspect this information from sys.argv? Can you not just always use > 'python -m pkg' as your entry point? Sorry about the confusion. I think my original point was simply one of surprise that sys.argv wouldn't essentially mirror the elements of the command line which I used to get there. The specifics of my use-case weren't really too important. For completeness, I'm talking about the cherrypy Autoreloader which attempts to restart (via execv) whatever process was responsible for loading it in the first place, via an identical or equivalent command line. The current (cherrypy) code simply joins sys.executable and sys.argv but this fails in the face of python -m as we have seen. The cherrypy package has no especial knowledge of the structure of the application which imported it and so must piece together the command line somehow. Clearly, I can take various approaches of the sort which you've outlined, or subclass the reloader, or fetch the original command line from the OS, etc. It's not that this is a showstopper, merely slightly surprising. (To me). TJG From oscar.j.benjamin at gmail.com Thu Jan 24 10:28:31 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 15:28:31 +0000 Subject: Retrieving the full command line In-Reply-To: <51013B0C.6000309@timgolden.me.uk> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> Message-ID: On 24 January 2013 13:45, Tim Golden wrote: > On 24/01/2013 11:30, Oscar Benjamin wrote: >> I don't really understand what your spec is. Why do you need to >> inspect this information from sys.argv? Can you not just always use >> 'python -m pkg' as your entry point? > [SNIP] > > For completeness, I'm talking about the cherrypy Autoreloader which > attempts to restart (via execv) whatever process was responsible for > loading it in the first place, via an identical or equivalent command > line. The current (cherrypy) code simply joins sys.executable and > sys.argv but this fails in the face of python -m as we have seen. > > The cherrypy package has no especial knowledge of the structure of the > application which imported it and so must piece together the command > line somehow. Clearly, I can take various approaches of the sort > which you've outlined, or subclass the reloader, or fetch the original > command line from the OS, etc. It's not that this is a showstopper, > merely slightly surprising. (To me). Ok I understand. Then I guess you want: import __main__ pkg = __main__.__package__ Oscar From mail at timgolden.me.uk Thu Jan 24 10:51:33 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2013 15:51:33 +0000 Subject: Retrieving the full command line In-Reply-To: References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> Message-ID: <51015885.9060104@timgolden.me.uk> On 24/01/2013 15:28, Oscar Benjamin wrote: > On 24 January 2013 13:45, Tim Golden wrote: >> On 24/01/2013 11:30, Oscar Benjamin wrote: >>> I don't really understand what your spec is. Why do you need to >>> inspect this information from sys.argv? Can you not just always use >>> 'python -m pkg' as your entry point? >> > [SNIP] >> >> For completeness, I'm talking about the cherrypy Autoreloader which >> attempts to restart (via execv) whatever process was responsible for >> loading it in the first place, via an identical or equivalent command >> line. The current (cherrypy) code simply joins sys.executable and >> sys.argv but this fails in the face of python -m as we have seen. >> >> The cherrypy package has no especial knowledge of the structure of the >> application which imported it and so must piece together the command >> line somehow. Clearly, I can take various approaches of the sort >> which you've outlined, or subclass the reloader, or fetch the original >> command line from the OS, etc. It's not that this is a showstopper, >> merely slightly surprising. (To me). > > Ok I understand. Then I guess you want: > > import __main__ > pkg = __main__.__package__ Brilliant. Never thought of importing __main__. Thanks. For the benefit of anyone still watching, the code (which has to be compatible back to 2.3) looks something like this: import __main__ # [.. .snip ...] try: is_package = bool(__main__.__package__) except NameError: is_package = False if is_package: args = [sys.executable, '-m', __main__.__package__] + sys.argv[1:] else: args = [sys.executable] + sys.argv os.chdir(_startup_cwd) # avoids relative/absolute issues os.execv(args[0], args) I don't pretend it's foolproot, but it certainly works for my particular case. Nor have I considered it against all the cases identified in PEP 432: http://www.python.org/dev/peps/pep-0432/#configuring-sys-argv TJG From oscar.j.benjamin at gmail.com Thu Jan 24 11:08:50 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 16:08:50 +0000 Subject: Retrieving the full command line In-Reply-To: <51015885.9060104@timgolden.me.uk> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> <51015885.9060104@timgolden.me.uk> Message-ID: On 24 January 2013 15:51, Tim Golden wrote: > On 24/01/2013 15:28, Oscar Benjamin wrote: >> On 24 January 2013 13:45, Tim Golden wrote: >>> On 24/01/2013 11:30, Oscar Benjamin wrote: >>>> I don't really understand what your spec is. Why do you need to >>>> inspect this information from sys.argv? Can you not just always use >>>> 'python -m pkg' as your entry point? >>> >> [SNIP] >>> >>> For completeness, I'm talking about the cherrypy Autoreloader which >>> attempts to restart (via execv) whatever process was responsible for >>> loading it in the first place, via an identical or equivalent command >>> line. The current (cherrypy) code simply joins sys.executable and >>> sys.argv but this fails in the face of python -m as we have seen. >>> >>> The cherrypy package has no especial knowledge of the structure of the >>> application which imported it and so must piece together the command >>> line somehow. Clearly, I can take various approaches of the sort >>> which you've outlined, or subclass the reloader, or fetch the original >>> command line from the OS, etc. It's not that this is a showstopper, >>> merely slightly surprising. (To me). >> >> Ok I understand. Then I guess you want: >> >> import __main__ >> pkg = __main__.__package__ > > Brilliant. Never thought of importing __main__. Thanks. > > For the benefit of anyone still watching, the code (which has to be > compatible back to 2.3) looks something like this: > > > import __main__ > > # [.. .snip ...] > > try: > is_package = bool(__main__.__package__) > except NameError: > is_package = False > if is_package: > args = [sys.executable, '-m', __main__.__package__] + sys.argv[1:] > else: > args = [sys.executable] + sys.argv > > os.chdir(_startup_cwd) # avoids relative/absolute issues > os.execv(args[0], args) > > > > I don't pretend it's foolproot, but it certainly works for my particular > case. Nor have I considered it against all the cases identified in PEP > 432: http://www.python.org/dev/peps/pep-0432/#configuring-sys-argv Does it work if you use the -m option to run a module rather than a script? Oscar From oscar.j.benjamin at gmail.com Thu Jan 24 11:53:58 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 16:53:58 +0000 Subject: Retrieving the full command line In-Reply-To: References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> <51015885.9060104@timgolden.me.uk> Message-ID: On 24 January 2013 16:08, Oscar Benjamin wrote: > On 24 January 2013 15:51, Tim Golden wrote: >> On 24/01/2013 15:28, Oscar Benjamin wrote: >>> On 24 January 2013 13:45, Tim Golden wrote: >>>> On 24/01/2013 11:30, Oscar Benjamin wrote: >>>>> I don't really understand what your spec is. Why do you need to >>>>> inspect this information from sys.argv? Can you not just always use >>>>> 'python -m pkg' as your entry point? >>>> >>> [SNIP] >>>> >>>> For completeness, I'm talking about the cherrypy Autoreloader which >>>> attempts to restart (via execv) whatever process was responsible for >>>> loading it in the first place, via an identical or equivalent command >>>> line. The current (cherrypy) code simply joins sys.executable and >>>> sys.argv but this fails in the face of python -m as we have seen. >>>> >>>> The cherrypy package has no especial knowledge of the structure of the >>>> application which imported it and so must piece together the command >>>> line somehow. Clearly, I can take various approaches of the sort >>>> which you've outlined, or subclass the reloader, or fetch the original >>>> command line from the OS, etc. It's not that this is a showstopper, >>>> merely slightly surprising. (To me). >>> >>> Ok I understand. Then I guess you want: >>> >>> import __main__ >>> pkg = __main__.__package__ >> >> Brilliant. Never thought of importing __main__. Thanks. >> >> For the benefit of anyone still watching, the code (which has to be >> compatible back to 2.3) looks something like this: >> >> >> import __main__ >> >> # [.. .snip ...] >> >> try: >> is_package = bool(__main__.__package__) >> except NameError: >> is_package = False >> if is_package: >> args = [sys.executable, '-m', __main__.__package__] + sys.argv[1:] >> else: >> args = [sys.executable] + sys.argv >> >> os.chdir(_startup_cwd) # avoids relative/absolute issues >> os.execv(args[0], args) >> >> >> >> I don't pretend it's foolproot, but it certainly works for my particular >> case. Nor have I considered it against all the cases identified in PEP >> 432: http://www.python.org/dev/peps/pep-0432/#configuring-sys-argv > > Does it work if you use the -m option to run a module rather than a script? Sorry that was written incorrectly. I meant to say: does it work when a module is directly on sys.path rather than as a submodule of a package? In this case __package__ is set to the empty string if run with -m or None if run with a direct path. So the check needs to be "__package__ is not None" rather than "bool(__package__)". Oscar From mail at timgolden.me.uk Thu Jan 24 12:13:09 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2013 17:13:09 +0000 Subject: Retrieving the full command line In-Reply-To: References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> <51015885.9060104@timgolden.me.uk> Message-ID: <51016BA5.6010401@timgolden.me.uk> On 24/01/2013 16:53, Oscar Benjamin wrote: >> Does it work if you use the -m option to run a module rather than a script? > > Sorry that was written incorrectly. I meant to say: does it work when > a module is directly on sys.path rather than as a submodule of a > package? In this case __package__ is set to the empty string if run > with -m or None if run with a direct path. So the check needs to be > "__package__ is not None" rather than "bool(__package__)". The answer is: it depends. Given the code I outlined earlier: A package-based module run via -m (python -m package.module) works as described (including the implicit __main__ module, my primary use-case). A module run from the filesystem (python c:\path\to\module.py) works by dropping through through to the not is_package logic branch. A module run via -m (python -m module) actually works by accident, because it too drops through to the not is_package branch and is rerun with its full filesystem path. This doesn't have the same problems as running a package from the filesystem because relative imports aren't an issue. I don't know if there are any other differences between python -mmodule and python c:\path\to\module.py. As you say, a more refined check could determine a blank __package__ as opposed to a None __package__. But this code (cherrypy) must also cope with version of Python before 2.6 which didn't even have a __package__ attribute, muddying the waters that little bit further. TJG From oscar.j.benjamin at gmail.com Thu Jan 24 15:01:36 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 20:01:36 +0000 Subject: Retrieving the full command line In-Reply-To: <51016BA5.6010401@timgolden.me.uk> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> <51015885.9060104@timgolden.me.uk> <51016BA5.6010401@timgolden.me.uk> Message-ID: On 24 January 2013 17:13, Tim Golden wrote: > On 24/01/2013 16:53, Oscar Benjamin wrote: >>> Does it work if you use the -m option to run a module rather than a script? >> >> Sorry that was written incorrectly. I meant to say: does it work when >> a module is directly on sys.path rather than as a submodule of a >> package? In this case __package__ is set to the empty string if run >> with -m or None if run with a direct path. So the check needs to be >> "__package__ is not None" rather than "bool(__package__)". > > The answer is: it depends. Given the code I outlined earlier: > > A package-based module run via -m (python -m package.module) works > as described (including the implicit __main__ module, my > primary use-case). Does it work in the "python -m package.module" case? It looks to me as if the code below will run "python -m package" instead. I think you need to split the module name out of sys.argv[0] and put that into the command line as well. > import __main__ > > # [.. .snip ...] > > try: > is_package = bool(__main__.__package__) > except NameError: > is_package = False > if is_package: > args = [sys.executable, '-m', __main__.__package__] + sys.argv[1:] > else: > args = [sys.executable] + sys.argv > > os.chdir(_startup_cwd) # avoids relative/absolute issues > os.execv(args[0], args) I believe "python -m package" and "python -m package.__main__" are equivalent so it doesn't matter in that case. > > A module run from the filesystem (python c:\path\to\module.py) works > by dropping through through to the not is_package logic branch. > > A module run via -m (python -m module) actually works by accident, > because it too drops through to the not is_package branch and is > rerun with its full filesystem path. This doesn't have the same > problems as running a package from the filesystem because relative > imports aren't an issue. I don't know if there are any other differences > between python -mmodule and python c:\path\to\module.py. There is a (probably pathological) case in which running the script via a file path and running it via -m are not equivalent. "python dir/script.py" places "dir" at the top of sys.path. "python -m script" only works if "dir" is in sys.path but it needn't be at the top. This means that the order of sys.path is changed and import conflicts may be resolved differently in the two cases: ~$ cat ~/.local/lib/python2.7/site-packages/script.py print("Running script.py") import optparse ~$ cat ~/.local/lib/python2.7/site-packages/optparse.py raise ImportError('Wrong optparse!') ~$ python ~/.local/lib/python2.7/site-packages/script.py Running script.py Traceback (most recent call last): File "/home/oscar/.local/lib/python2.7/site-packages/script.py", line 2, in import optparse File "/home/oscar/.local/lib/python2.7/site-packages/optparse.py", line 1, in raise ImportError('Wrong optparse!') ImportError: Wrong optparse! ~$ python -m script Running script.py ~$ python ~/.local/lib/python2.7/site-packages/script.py Running script.py Traceback (most recent call last): File "/home/oscar/.local/lib/python2.7/site-packages/script.py", line 2, in import optparse File "/home/oscar/.local/lib/python2.7/site-packages/optparse.py", line 1, in raise ImportError('Wrong optparse!') ImportError: Wrong optparse! ~$ python -m script Running script.py > > As you say, a more refined check could determine a blank __package__ > as opposed to a None __package__. But this code (cherrypy) must also > cope with version of Python before 2.6 which didn't even have a > __package__ attribute, muddying the waters that little bit further. Then you won't be able to use this method to get the -m switch to work on Python < 2.6. If it's ok to just never try the -m switch on those versions then it's as simple as doing: pkg = getattr(__main__, '__package__', None) Oscar From mail at timgolden.me.uk Thu Jan 24 15:54:44 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Jan 2013 20:54:44 +0000 Subject: Retrieving the full command line In-Reply-To: References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> <51015885.9060104@timgolden.me.uk> <51016BA5.6010401@timgolden.me.uk> Message-ID: <51019F94.8090309@timgolden.me.uk> On 24/01/2013 20:01, Oscar Benjamin wrote: > On 24 January 2013 17:13, Tim Golden wrote: >> A package-based module run via -m (python -m package.module) works >> as described (including the implicit __main__ module, my >> primary use-case). > > Does it work in the "python -m package.module" case? It looks to me as > if the code below will run "python -m package" instead. I think you > need to split the module name out of sys.argv[0] and put that into the > command line as well. Good catch. Unless I am, once again, mistaken, I can't see any way of recreating a dotted module path which is running as a main module without the somewhat fragile expedient of walking back up the filepath and hoping that nothing strange has happened to the imports on the way down? (pywin32: I'm looking at you!) And we haven't even touched on zipped archives or other invented loaders (pulling modules from a database or direct from the internet). I think, though, that the point which with I started this thread is still valid: that to reconstruct the command line with which Python was started, you need an increasingly awkward set of conditions and checks. As opposed to asking the interpreter: please give me the command line which started you. How common that particular requirement actually is, I couldn't say. But the two cases which clearly could use it are: the reloader setup we've been discussing here; and the apply-new-version-and-restart which I'm hoping to use in another setup at work. Thanks for all the help and input on this, Oscar TJG From oscar.j.benjamin at gmail.com Tue Jan 22 20:14:15 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 01:14:15 +0000 Subject: Retrieving the full command line In-Reply-To: <50FE5AC7.3050909@timgolden.me.uk> References: <50FE5AC7.3050909@timgolden.me.uk> Message-ID: On 22 January 2013 09:24, Tim Golden wrote: > [Python 2.7/3.3 (and hg tip) running on Windows. Not Windows-specific, > though]. > > I use the python -mpackage incantation to run a package which has a > __main__.py module and which uses relative imports internally. > > I'm developing under cherrypy which includes a reloader for development. > The reloader attempts to rebuild the original > command line by combining sys.executable and sys.argv and then does an > execv. > > There does not appear to be any way within Python of determining the > command line I used. The combination of sys.executable and sys.argv in > this case will look like: "c:\python33\python.exe app/__main__.py". But > running this precludes the use of package-relative imports. I tried this on Linux but I imagine that it works the same on Windows. You can check the value of the __package__ module global: ~$ mkdir tmp ~$ touch tmp/__init__.py ~$ vim tmp/__main__.py ~$ cat tmp/__main__.py if __package__ is None: print 'Running as a script' else: print 'Running with the -m option' ~$ python tmp/__main__.py Running as a script ~$ python -m tmp Running with the -m option Oscar From nikos.gr33k at gmail.com Tue Jan 22 05:07:54 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 02:07:54 -0800 (PST) Subject: Using filepath method to identify an .html page Message-ID: Hello, i decided to switch from embedding string into .html to actually grab the filepath in order to identify it: # ================================================================================================================= # open current html template and get the page ID number # =============================== f = open( page ) # read first line of the file firstline = f.readline() # find the ID of the file and store it pin = re.match( r'', firstline ).group(1) ================================= This is what i used to have. Now, can you pleas help me write the switch to filepath identifier? I'am having trouble writing it. From steve+comp.lang.python at pearwood.info Tue Jan 22 06:31:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 11:31:11 GMT Subject: Using filepath method to identify an .html page References: Message-ID: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 02:07:54 -0800, Ferrous Cranus wrote: > Hello, i decided to switch from embedding string into .html to actually > grab the filepath in order to identify it: What do you think "the filepath" means, and how do you think you would grab it? I can only guess you mean the full path to the file, like: /home/steve/mypage.html C:\My Documents\mypage.html Is that what you mean? > # open current html template and get the page ID number > f = open( page ) > # read first line of the file > firstline = f.readline() > # find the ID of the file and store it > pin = re.match( r'', firstline ).group(1) > > This is what i used to have. > > Now, can you pleas help me write the switch to filepath identifier? I'am > having trouble writing it. I don't understand the question. -- Steven From nikos.gr33k at gmail.com Tue Jan 22 06:53:44 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 03:53:44 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: # ================================================== # produce a hash based on html page's filepath and convert it to an integet, that will be uses to identify the page itself. # ================================================== pin = int( hashlib.md5( htmlpage ) ) I just tried that but it produced an error. What am i doing wrong? From rosuav at gmail.com Tue Jan 22 07:26:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Jan 2013 23:26:36 +1100 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 22, 2013 at 10:53 PM, Ferrous Cranus wrote: > # ================================================== > # produce a hash based on html page's filepath and convert it to an integet, that will be uses to identify the page itself. > # ================================================== > > pin = int( hashlib.md5( htmlpage ) ) > > > I just tried that but it produced an error. > What am i doing wrong? First and foremost, here's what you're doing wrong: You're saying "it produced an error". Python is one of those extremely helpful languages that tells you, to the best of its ability, exactly WHAT went wrong, WHERE it went wrong, and - often - WHY it failed. For comparison, I've just tonight been trying to fix up a legacy accounting app that was written in Visual BASIC back when that wouldn't get scorn heaped on you from the whole world. When we fire up one particular module, it bombs with a little message box saying "File not found". That's all. Just one little message, and the application terminates (uncleanly, at that). What file? How was it trying to open it? I do know that it isn't one of its BTrieve data files, because when one of THEM isn't found, the crash looks different (but it's still a crash). My current guess is that it's probably a Windows DLL file or something, but it's really not easy to tell... ChrisA From nikos.gr33k at gmail.com Tue Jan 22 07:02:26 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 04:02:26 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: # ==================================================================================================================================== # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself # ==================================================================================================================================== pin = int( hashlib.md5( htmlpage ) ) This fails. why? htmlpage = a string respresenting the absolute path of the requested .html file hashlib.md5( htmlpage ) = conversion of the above string to a hashed string int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number Why this fails? From lele at metapensiero.it Tue Jan 22 07:22:02 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 22 Jan 2013 13:22:02 +0100 Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vcapbe6t.fsf@metapensiero.it> Ferrous Cranus writes: > pin = int( hashlib.md5( htmlpage ) ) > > This fails. why? > > htmlpage = a string respresenting the absolute path of the requested .html file > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string No, that statement does not "convert" a string into another, but rather returns a "md5 HASH object": >>> import hashlib >>> hashlib.md5('foo') Consulting the hashlib documentation[1], you could learn about that object's methods. > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > Why this fails? Because in general you can't "convert" an arbitrary object instance (in your case an hashlib.HASH instance) to an integer value. Why do you need an integer? Isn't hexdigest() what you want? >>> print _.hexdigest() acbd18db4cc2f85cedef654fccc4a4d8 Do yourself a favor and learn using the interpreter to test your snippets line by line, most problems will find an easy answer :-) ciao, lele. [1] http://docs.python.org/2.7/library/hashlib.html#module-hashlib -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From d at davea.name Tue Jan 22 07:29:21 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 07:29:21 -0500 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50FE8621.6020405@davea.name> On 01/22/2013 07:02 AM, Ferrous Cranus wrote: > # ==================================================================================================================================== > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself > # ==================================================================================================================================== > > pin = int( hashlib.md5( htmlpage ) ) > > This fails. why? > > htmlpage = a string respresenting the absolute path of the requested .html file > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > Why this fails? > Is your copy/paste broken? It could be useful to actually show in what way it "fails." The md5 method produces a "HASH object", not a string. So int() cannot process that. To produce a digest string from the hash object, you want to call hexdigest() method. The result of that is a hex literal string. So you cannot just call int() on it, since that defaults to decimal. To convert a hex string to an int, you need the extra parameter of int: int(mystring, 16) Now, see if you can piece it together. -- DaveA From nikos.gr33k at gmail.com Tue Jan 22 07:47:16 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 04:47:16 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> ?? ?????, 22 ?????????? 2013 2:29:21 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/22/2013 07:02 AM, Ferrous Cranus wrote: > > > # ==================================================================================================================================== > > > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself > > > # ==================================================================================================================================== > > > > > > pin = int( hashlib.md5( htmlpage ) ) > > > > > > This fails. why? > > > > > > htmlpage = a string respresenting the absolute path of the requested .html file > > > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string > > > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > > > > > Why this fails? > > > > > > > Is your copy/paste broken? It could be useful to actually show in what > > way it "fails." > > > > The md5 method produces a "HASH object", not a string. So int() cannot > > process that. > > > > To produce a digest string from the hash object, you want to call > > hexdigest() method. The result of that is a hex literal string. So you > > cannot just call int() on it, since that defaults to decimal. > > > > To convert a hex string to an int, you need the extra parameter of int: > > > > int(mystring, 16) > > > > Now, see if you can piece it together. > htmlpage = a string respresenting the absolute path of the requested .html file What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string. so to get an integer out of a string i would just have to type: pin = int( htmlpage ) But would that be unique? From nikos.gr33k at gmail.com Tue Jan 22 07:47:16 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 04:47:16 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> ?? ?????, 22 ?????????? 2013 2:29:21 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/22/2013 07:02 AM, Ferrous Cranus wrote: > > > # ==================================================================================================================================== > > > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself > > > # ==================================================================================================================================== > > > > > > pin = int( hashlib.md5( htmlpage ) ) > > > > > > This fails. why? > > > > > > htmlpage = a string respresenting the absolute path of the requested .html file > > > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string > > > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > > > > > Why this fails? > > > > > > > Is your copy/paste broken? It could be useful to actually show in what > > way it "fails." > > > > The md5 method produces a "HASH object", not a string. So int() cannot > > process that. > > > > To produce a digest string from the hash object, you want to call > > hexdigest() method. The result of that is a hex literal string. So you > > cannot just call int() on it, since that defaults to decimal. > > > > To convert a hex string to an int, you need the extra parameter of int: > > > > int(mystring, 16) > > > > Now, see if you can piece it together. > htmlpage = a string respresenting the absolute path of the requested .html file What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string. so to get an integer out of a string i would just have to type: pin = int( htmlpage ) But would that be unique? From nikos.gr33k at gmail.com Tue Jan 22 07:50:38 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 04:50:38 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> Message-ID: ?? ?????, 22 ?????????? 2013 2:47:16 ?.?. UTC+2, ? ??????? Ferrous Cranus ??????: > ?? ?????, 22 ?????????? 2013 2:29:21 ?.?. UTC+2, ? ??????? Dave Angel ??????: > > > On 01/22/2013 07:02 AM, Ferrous Cranus wrote: > > > > > > > # ==================================================================================================================================== > > > > > > > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself > > > > > > > # ==================================================================================================================================== > > > > > > > > > > > > > > pin = int( hashlib.md5( htmlpage ) ) > > > > > > > > > > > > > > This fails. why? > > > > > > > > > > > > > > htmlpage = a string respresenting the absolute path of the requested .html file > > > > > > > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string > > > > > > > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > > > > > > > > > > > > > Why this fails? > > > > > > > > > > > > > > > > > > > Is your copy/paste broken? It could be useful to actually show in what > > > > > > way it "fails." > > > > > > > > > > > > The md5 method produces a "HASH object", not a string. So int() cannot > > > > > > process that. > > > > > > > > > > > > To produce a digest string from the hash object, you want to call > > > > > > hexdigest() method. The result of that is a hex literal string. So you > > > > > > cannot just call int() on it, since that defaults to decimal. > > > > > > > > > > > > To convert a hex string to an int, you need the extra parameter of int: > > > > > > > > > > > > int(mystring, 16) > > > > > > > > > > > > Now, see if you can piece it together. > > > > > > > > > htmlpage = a string respresenting the absolute path of the requested .html file > > > > > > What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string. > > > > so to get an integer out of a string i would just have to type: > > > > pin = int( htmlpage ) > > > > But would that be unique? Another error even without hasing anyhting http://superhost.gr to view it please From nikos.gr33k at gmail.com Tue Jan 22 07:50:38 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 04:50:38 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> Message-ID: ?? ?????, 22 ?????????? 2013 2:47:16 ?.?. UTC+2, ? ??????? Ferrous Cranus ??????: > ?? ?????, 22 ?????????? 2013 2:29:21 ?.?. UTC+2, ? ??????? Dave Angel ??????: > > > On 01/22/2013 07:02 AM, Ferrous Cranus wrote: > > > > > > > # ==================================================================================================================================== > > > > > > > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself > > > > > > > # ==================================================================================================================================== > > > > > > > > > > > > > > pin = int( hashlib.md5( htmlpage ) ) > > > > > > > > > > > > > > This fails. why? > > > > > > > > > > > > > > htmlpage = a string respresenting the absolute path of the requested .html file > > > > > > > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string > > > > > > > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > > > > > > > > > > > > > Why this fails? > > > > > > > > > > > > > > > > > > > Is your copy/paste broken? It could be useful to actually show in what > > > > > > way it "fails." > > > > > > > > > > > > The md5 method produces a "HASH object", not a string. So int() cannot > > > > > > process that. > > > > > > > > > > > > To produce a digest string from the hash object, you want to call > > > > > > hexdigest() method. The result of that is a hex literal string. So you > > > > > > cannot just call int() on it, since that defaults to decimal. > > > > > > > > > > > > To convert a hex string to an int, you need the extra parameter of int: > > > > > > > > > > > > int(mystring, 16) > > > > > > > > > > > > Now, see if you can piece it together. > > > > > > > > > htmlpage = a string respresenting the absolute path of the requested .html file > > > > > > What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string. > > > > so to get an integer out of a string i would just have to type: > > > > pin = int( htmlpage ) > > > > But would that be unique? Another error even without hasing anyhting http://superhost.gr to view it please From rosuav at gmail.com Tue Jan 22 07:59:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Jan 2013 23:59:07 +1100 Subject: Using filepath method to identify an .html page In-Reply-To: <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com> Message-ID: On Tue, Jan 22, 2013 at 11:47 PM, Ferrous Cranus wrote: > What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string. > > so to get an integer out of a string i would just have to type: > > pin = int( htmlpage ) > > But would that be unique? The absolute path probably isn't that big. Just use it. Any form of hashing will give you a chance of a collision. ChrisA From steve+comp.lang.python at pearwood.info Tue Jan 22 08:04:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 13:04:41 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 04:47:16 -0800, Ferrous Cranus wrote: > htmlpage = a string respresenting the absolute path of the requested > .html file That is a very misleading name for a variable. The contents of the variable are not a html page, but a file name. htmlpage = "/home/steve/my-web-page.html" # Bad variable name. filename = "/home/steve/my-web-page.html" # Better variable name. > What i want to do, is to associate a number to an html page's absolute > path for to be able to use that number for my database relations instead > of the BIG absolute path string. Firstly, don't bother. What you consider "BIG", your database will consider trivially small. What is it, 100 characters long? 200? Unlikely to be 300, since I think many file systems don't support paths that long. But let's say it is 300 characters long. That's likely to be 600 bytes, or a bit more than half a kilobyte. Your database won't even notice that. > so to get an integer out of a string i would just have to type: > > pin = int( htmlpage ) No, that doesn't work. int() does not convert arbitrary strings into numbers. What made you think that this could possibly work? What do you expect int("my-web-page.html") to return? Should it return 23 or 794 or 109432985462940911485 or 42? > But would that be unique? Wrong question. Just tell your database to make the file name an indexed field, and it will handle giving every path a unique number for you. You can then forget all about that unique number, because it is completely irrelevant to you, and safely use the path while the database treats it in the fastest and most efficient fashion necessary. -- Steven From nikos.gr33k at gmail.com Tue Jan 22 08:57:13 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 05:57:13 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> ?? ?????, 22 ?????????? 2013 3:04:41 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > What do you expect int("my-web-page.html") to return? Should it return 23 > or 794 or 109432985462940911485 or 42? I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test. > Just tell your database to make the file name an indexed field, and it > > will handle giving every path a unique number for you. You can then > > forget all about that unique number, because it is completely irrelevant > > to you, and safely use the path while the database treats it in the > > fastest and most efficient fashion necessary. This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this: /home/nikos/public_html/varsa.gr/articles/html/files/index.html In addition to that my counter.py script maintains details in a database table that stores information for each and every webpage requested. My 'visitors' database has 2 tables: pin --- page ---- hits (that's to store general information for all html pages) pin <-refers to-> page pin ---- host ---- hits ---- useros ---- browser ---- date (that's to store detailed information for all html pages) (thousands of records to hold every page's information) 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!! So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path) Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can). So, that why i need to get a "unique" number out of a string. please help. From rosuav at gmail.com Tue Jan 22 09:33:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 01:33:03 +1100 Subject: Using filepath method to identify an .html page In-Reply-To: <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus wrote: > ?? ?????, 22 ?????????? 2013 3:04:41 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > >> What do you expect int("my-web-page.html") to return? Should it return 23 >> or 794 or 109432985462940911485 or 42? > > I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test. Just run python without any args, and you'll get interactive mode. You can try things out there. > This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this: > > /home/nikos/public_html/varsa.gr/articles/html/files/index.html That's not big. Trust me, modern databases work just fine with unique indexes like that. The most common way to organize the index is with a binary tree, so the database has to look through log(N) entries. That's like figuring out if the two numbers 142857 and 857142 are the same; you don't need to look through 1,000,000 possibilities, you just need to look through the six digits each number has. > 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!! Not that bad actually. I've happily used keys easily that long, and expected the database to ensure uniqueness without costing performance. > So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path) Is there any chance that you'll have more than 10,000 pages? If so, a four-digit number is *guaranteed* to have duplicates. And if you research the Birthday Paradox, you'll find that any sort of hashing algorithm is likely to produce collisions a lot sooner than that. > Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can). > > So, that why i need to get a "unique" number out of a string. please help. Ultimately, that unique number would end up being a foreign key into a table of URLs and IDs. So just skip that table and use the URLs directly - much easier. In this instance, there's no value in normalizing. ChrisA From nikos.gr33k at gmail.com Tue Jan 22 09:55:04 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 06:55:04 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: ?? ?????, 22 ?????????? 2013 4:33:03 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus wrote: > > > ?? ?????, 22 ?????????? 2013 3:04:41 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > > > > > >> What do you expect int("my-web-page.html") to return? Should it return 23 > > >> or 794 or 109432985462940911485 or 42? > > > > > > I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test. > > > > Just run python without any args, and you'll get interactive mode. You > > can try things out there. > > > > > This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this: > > > > > > /home/nikos/public_html/varsa.gr/articles/html/files/index.html > > > > That's not big. Trust me, modern databases work just fine with unique > > indexes like that. The most common way to organize the index is with a > > binary tree, so the database has to look through log(N) entries. > > That's like figuring out if the two numbers 142857 and 857142 are the > > same; you don't need to look through 1,000,000 possibilities, you just > > need to look through the six digits each number has. > > > > > 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!! > > > > Not that bad actually. I've happily used keys easily that long, and > > expected the database to ensure uniqueness without costing > > performance. > > > > > So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path) > > > > Is there any chance that you'll have more than 10,000 pages? If so, a > > four-digit number is *guaranteed* to have duplicates. And if you > > research the Birthday Paradox, you'll find that any sort of hashing > > algorithm is likely to produce collisions a lot sooner than that. > > > > > Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can). > > > > > > So, that why i need to get a "unique" number out of a string. please help. > > > > Ultimately, that unique number would end up being a foreign key into a > > table of URLs and IDs. So just skip that table and use the URLs > > directly - much easier. In this instance, there's no value in > > normalizing. > > > > ChrisA I insist, perhaps compeleld, to use a key to associate a number to a filename. Would you help please? I dont know this is supposed to be written. i just know i need this: number = function_that_returns_a_number_out_of_a_string( absolute_path_of_a_html_file) Would someone help me write that in python coding? We are talkign 1 line of code here.... From d at davea.name Tue Jan 22 10:05:49 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 10:05:49 -0500 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <50FEAACD.3090808@davea.name> On 01/22/2013 09:55 AM, Ferrous Cranus wrote: > ?? ?????, 22 ?????????? 2013 4:33:03 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus wrote: >> >>> ?? ?????, 22 ?????????? 2013 3:04:41 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: >> >>> >> >>>> What do you expect int("my-web-page.html") to return? Should it return 23 >> >>>> or 794 or 109432985462940911485 or 42? >> >>> >> >>> I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test. >> >> >> >> Just run python without any args, and you'll get interactive mode. You >> >> can try things out there. >> >> >> >>> This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this: >> >>> >> >>> /home/nikos/public_html/varsa.gr/articles/html/files/index.html >> >> >> >> That's not big. Trust me, modern databases work just fine with unique >> >> indexes like that. The most common way to organize the index is with a >> >> binary tree, so the database has to look through log(N) entries. >> >> That's like figuring out if the two numbers 142857 and 857142 are the >> >> same; you don't need to look through 1,000,000 possibilities, you just >> >> need to look through the six digits each number has. >> >> >> >>> 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!! >> >> >> >> Not that bad actually. I've happily used keys easily that long, and >> >> expected the database to ensure uniqueness without costing >> >> performance. >> >> >> >>> So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path) >> >> >> >> Is there any chance that you'll have more than 10,000 pages? If so, a >> >> four-digit number is *guaranteed* to have duplicates. And if you >> >> research the Birthday Paradox, you'll find that any sort of hashing >> >> algorithm is likely to produce collisions a lot sooner than that. >> >> >> >>> Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can). >> >>> >> >>> So, that why i need to get a "unique" number out of a string. please help. >> >> >> >> Ultimately, that unique number would end up being a foreign key into a >> >> table of URLs and IDs. So just skip that table and use the URLs >> >> directly - much easier. In this instance, there's no value in >> >> normalizing. >> >> >> >> ChrisA > > I insist, perhaps compeleld, to use a key to associate a number to a filename. > Would you help please? > > I dont know this is supposed to be written. i just know i need this: > > number = function_that_returns_a_number_out_of_a_string( absolute_path_of_a_html_file) > > Would someone help me write that in python coding? We are talkign 1 line of code here.... > I gave you every piece of that code in my last response. So you're not willing to compose the line from the clues? -- DaveA From rosuav at gmail.com Tue Jan 22 10:07:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 02:07:57 +1100 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 1:55 AM, Ferrous Cranus wrote: > I insist, perhaps compeleld, to use a key to associate a number to a filename. > Would you help please? > > I dont know this is supposed to be written. i just know i need this: > > number = function_that_returns_a_number_out_of_a_string( absolute_path_of_a_html_file) > > Would someone help me write that in python coding? We are talkign 1 line of code here.... def function_that_returns_a_number_out_of_a_string(string, cache=[]): return cache.index(string) if string in cache else (cache.append(string) or len(cache)-1) That will work perfectly, as long as you don't care how long the numbers end up, and as long as you have a single Python script doing the work, and as long as you make sure you save and load that cache any time you shut down the script, and so on. It will also, and rightly, be decried as a bad idea. But hey, you did specify that it be one line of code. For your real job, USE A DATABASE COLUMN. ChrisA From nikos.gr33k at gmail.com Tue Jan 22 10:21:28 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 07:21:28 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> ?? ?????, 22 ?????????? 2013 5:05:49 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/22/2013 09:55 AM, Ferrous Cranus wrote: > > > ?? ?????, 22 ?????????? 2013 4:33:03 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > >> On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus wrote: > > >> > > >>> ?? ?????, 22 ?????????? 2013 3:04:41 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > > >> > > >>> > > >> > > >>>> What do you expect int("my-web-page.html") to return? Should it return 23 > > >> > > >>>> or 794 or 109432985462940911485 or 42? > > >> > > >>> > > >> > > >>> I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test. > > >> > > >> > > >> > > >> Just run python without any args, and you'll get interactive mode. You > > >> > > >> can try things out there. > > >> > > >> > > >> > > >>> This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this: > > >> > > >>> > > >> > > >>> /home/nikos/public_html/varsa.gr/articles/html/files/index.html > > >> > > >> > > >> > > >> That's not big. Trust me, modern databases work just fine with unique > > >> > > >> indexes like that. The most common way to organize the index is with a > > >> > > >> binary tree, so the database has to look through log(N) entries. > > >> > > >> That's like figuring out if the two numbers 142857 and 857142 are the > > >> > > >> same; you don't need to look through 1,000,000 possibilities, you just > > >> > > >> need to look through the six digits each number has. > > >> > > >> > > >> > > >>> 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!! > > >> > > >> > > >> > > >> Not that bad actually. I've happily used keys easily that long, and > > >> > > >> expected the database to ensure uniqueness without costing > > >> > > >> performance. > > >> > > >> > > >> > > >>> So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path) > > >> > > >> > > >> > > >> Is there any chance that you'll have more than 10,000 pages? If so, a > > >> > > >> four-digit number is *guaranteed* to have duplicates. And if you > > >> > > >> research the Birthday Paradox, you'll find that any sort of hashing > > >> > > >> algorithm is likely to produce collisions a lot sooner than that. > > >> > > >> > > >> > > >>> Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can). > > >> > > >>> > > >> > > >>> So, that why i need to get a "unique" number out of a string. please help. > > >> > > >> > > >> > > >> Ultimately, that unique number would end up being a foreign key into a > > >> > > >> table of URLs and IDs. So just skip that table and use the URLs > > >> > > >> directly - much easier. In this instance, there's no value in > > >> > > >> normalizing. > > >> > > >> > > >> > > >> ChrisA > > > > > > I insist, perhaps compeleld, to use a key to associate a number to a filename. > > > Would you help please? > > > > > > I dont know this is supposed to be written. i just know i need this: > > > > > > number = function_that_returns_a_number_out_of_a_string( absolute_path_of_a_html_file) > > > > > > Would someone help me write that in python coding? We are talkign 1 line of code here.... > > > > > > > I gave you every piece of that code in my last response. So you're not > > willing to compose the line from the clues? I cannot. I don't even know yet if hashing needs to be used for what i need. The only thing i know is that: a) i only need to get a number out of string(being an absolute path) b) That number needs to be unique, because "that" number is an indicator to the actual html file. Would you help me write this in python? Why the hell pin = int ( '/home/nikos/public_html/index.html' ) fails? because it has slashes in it? From nikos.gr33k at gmail.com Tue Jan 22 10:21:28 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 07:21:28 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> ?? ?????, 22 ?????????? 2013 5:05:49 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/22/2013 09:55 AM, Ferrous Cranus wrote: > > > ?? ?????, 22 ?????????? 2013 4:33:03 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > >> On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus wrote: > > >> > > >>> ?? ?????, 22 ?????????? 2013 3:04:41 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > > >> > > >>> > > >> > > >>>> What do you expect int("my-web-page.html") to return? Should it return 23 > > >> > > >>>> or 794 or 109432985462940911485 or 42? > > >> > > >>> > > >> > > >>> I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test. > > >> > > >> > > >> > > >> Just run python without any args, and you'll get interactive mode. You > > >> > > >> can try things out there. > > >> > > >> > > >> > > >>> This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this: > > >> > > >>> > > >> > > >>> /home/nikos/public_html/varsa.gr/articles/html/files/index.html > > >> > > >> > > >> > > >> That's not big. Trust me, modern databases work just fine with unique > > >> > > >> indexes like that. The most common way to organize the index is with a > > >> > > >> binary tree, so the database has to look through log(N) entries. > > >> > > >> That's like figuring out if the two numbers 142857 and 857142 are the > > >> > > >> same; you don't need to look through 1,000,000 possibilities, you just > > >> > > >> need to look through the six digits each number has. > > >> > > >> > > >> > > >>> 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!! > > >> > > >> > > >> > > >> Not that bad actually. I've happily used keys easily that long, and > > >> > > >> expected the database to ensure uniqueness without costing > > >> > > >> performance. > > >> > > >> > > >> > > >>> So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path) > > >> > > >> > > >> > > >> Is there any chance that you'll have more than 10,000 pages? If so, a > > >> > > >> four-digit number is *guaranteed* to have duplicates. And if you > > >> > > >> research the Birthday Paradox, you'll find that any sort of hashing > > >> > > >> algorithm is likely to produce collisions a lot sooner than that. > > >> > > >> > > >> > > >>> Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can). > > >> > > >>> > > >> > > >>> So, that why i need to get a "unique" number out of a string. please help. > > >> > > >> > > >> > > >> Ultimately, that unique number would end up being a foreign key into a > > >> > > >> table of URLs and IDs. So just skip that table and use the URLs > > >> > > >> directly - much easier. In this instance, there's no value in > > >> > > >> normalizing. > > >> > > >> > > >> > > >> ChrisA > > > > > > I insist, perhaps compeleld, to use a key to associate a number to a filename. > > > Would you help please? > > > > > > I dont know this is supposed to be written. i just know i need this: > > > > > > number = function_that_returns_a_number_out_of_a_string( absolute_path_of_a_html_file) > > > > > > Would someone help me write that in python coding? We are talkign 1 line of code here.... > > > > > > > I gave you every piece of that code in my last response. So you're not > > willing to compose the line from the clues? I cannot. I don't even know yet if hashing needs to be used for what i need. The only thing i know is that: a) i only need to get a number out of string(being an absolute path) b) That number needs to be unique, because "that" number is an indicator to the actual html file. Would you help me write this in python? Why the hell pin = int ( '/home/nikos/public_html/index.html' ) fails? because it has slashes in it? From rosuav at gmail.com Tue Jan 22 10:27:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 02:27:45 +1100 Subject: Using filepath method to identify an .html page In-Reply-To: <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 2:21 AM, Ferrous Cranus wrote: > Why the hell > > pin = int ( '/home/nikos/public_html/index.html' ) > > fails? because it has slashes in it? What do you expect it to return? 141592653589793? Go through the Python tutorial. Better yet, find a book that distinguishes between technology and magic, and sets out clearly what each one's field is. Then go here, and read. http://www.catb.org/esr/faqs/smart-questions.html Then go back to your project. Have another shot at things. Put your new-found knowledge and understanding to work. You'll be far better able to figure things out, and better able to understand what we've all been saying. ChrisA From torriem at gmail.com Tue Jan 22 13:36:31 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 11:36:31 -0700 Subject: Using filepath method to identify an .html page In-Reply-To: <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50FEDC2F.4030000@gmail.com> I'm sorry you are getting so frustrated. There's obviously a language barrier here, but also your frustration is preventing you from thinking clearly. You need to take a step back, breath, and re-read everything that's been written to you on this thread. All your questions that can be answered have been answered. If you are being paid to develop this, then we don't want to do your work for you since we're not the ones being paid. If you're doing this for a class assignment, then again we don't want to do it for you because that would defeat the purpose of your education. But if you're willing to learn, then I think the others have said on this thread will help you learn it. You can't learn Python by developing CGI scripts and running them on the server. You need to try out snippets of code in an interactive way. You've been told how to do this, and you don't need IDLE. Although nothing prevents you from installing IDLE on your local machine. I hope you have the python interpreter on your local workstation. If not, download it and install it. You will need it. Use the python standard library reference online (or download it). You will need it. On 01/22/2013 08:21 AM, Ferrous Cranus wrote: > Why the hell > > pin = int ( '/home/nikos/public_html/index.html' ) > > fails? because it has slashes in it? That line fails because the string you passed it simply cannot be parsed into a number. Just for simplicity's sake here, suppose we define a number as any number of digits, 0-9, followed by a '.' or a ',' depending on locale, and some more digits, 0-9. This is very simplistic but it will server our purpose for this example. So given that a number is defined as above, we expect that we can parse the following strings: int('123.433') == int(123.433) == 123 but '/home/nikos/public_html/index.html' contains nothing that is recognizable as a number. There are no 0-9 digits in it, no periods or commas. So rather than returning 0, which would be absolutely incorrect, int() throws an exception because you've passed it a string which does not contain a recognizable number. If you really want to get a number to identify a string you'll have to create a hash of some kind. You were on the right track with hashlib. Except that int() again cannot work with the hash object because nothing in the hash object's string representation looks like a number. If you would follow the link you've already been given on the documentation for hashlib you'd find that the object returned by md5 has methods you can call to give you the hash in different forms, including a large number. From steve+comp.lang.python at pearwood.info Tue Jan 22 18:40:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:40:11 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff235b$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:40:24 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:40:24 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From torriem at gmail.com Tue Jan 22 19:07:22 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 17:07:22 -0700 Subject: Using filepath method to identify an .html page In-Reply-To: <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50FF29BA.5010703@gmail.com> On 01/22/2013 04:40 PM, Steven D'Aprano wrote: > On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > >> I'm sorry you are getting so frustrated. There's obviously a language >> barrier here, > > I don't think there is. The OP's posts have been written in excellent > English. Well, his English is pretty good. But his quote string is Cyrillic, and he uses phrases that are not common in everyday English, such as "I am compelled." English is clearly his second language. From python at mrabarnett.plus.com Tue Jan 22 19:40:57 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 23 Jan 2013 00:40:57 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: <50FF29BA.5010703@gmail.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50FF29BA.5010703@gmail.com> Message-ID: <50FF3199.6030104@mrabarnett.plus.com> On 2013-01-23 00:07, Michael Torrie wrote: > On 01/22/2013 04:40 PM, Steven D'Aprano wrote: >> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: >> >>> I'm sorry you are getting so frustrated. There's obviously a language >>> barrier here, >> >> I don't think there is. The OP's posts have been written in excellent >> English. > > Well, his English is pretty good. But his quote string is Cyrillic, and > he uses phrases that are not common in everyday English, such as "I am > compelled." English is clearly his second language. > "his quote string is Cyrillic"? If you're referring to the "?? ?????, 22 ?????????? 2013 6:23:16 ?.?. UTC+2, ? ??????? Leonard, Arah ??????", that's Greek. From torriem at gmail.com Wed Jan 23 00:10:55 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 22:10:55 -0700 Subject: Using filepath method to identify an .html page In-Reply-To: <50FF3199.6030104@mrabarnett.plus.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50FF29BA.5010703@gmail.com> <50FF3199.6030104@mrabarnett.plus.com> Message-ID: <50FF70DF.7020605@gmail.com> On 01/22/2013 05:40 PM, MRAB wrote: > "his quote string is Cyrillic"? > > If you're referring to the "?? ?????, 22 ?????????? 2013 6:23:16 ?.?. > UTC+2, ? ??????? Leonard, Arah ??????", that's Greek. Oh, haha! you're so right! From Arah.Leonard at bruker-axs.com Wed Jan 23 11:33:11 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Wed, 23 Jan 2013 16:33:11 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: <50FF3199.6030104@mrabarnett.plus.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50FF29BA.5010703@gmail.com> <50FF3199.6030104@mrabarnett.plus.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07586699@msnmail2.bruker-axs.com> > "his quote string is Cyrillic"? > > If you're referring to the "?? ?????, 22 ?????????? 2013 6:23:16 ?.?. > UTC+2, ? ??????? Leonard, Arah ??????", that's Greek. > Cyrillic or not, it's all Greek to me. ;) From nikos.gr33k at gmail.com Wed Jan 23 11:51:49 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 08:51:49 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50FF29BA.5010703@gmail.com> <50FF3199.6030104@mrabarnett.plus.com> Message-ID: ?? ???????, 23 ?????????? 2013 6:33:11 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > "his quote string is Cyrillic"? > > > > > > If you're referring to the "?? ?????, 22 ?????????? 2013 6:23:16 ?.?. > > > UTC+2, ? ??????? Leonard, Arah ??????", that's Greek. > > > > > > Cyrillic or not, it's all Greek to me. ;) ============================================= my @i = split(//,$url); # put each letter in it's own bin my $j=0; # Initailize our my $k=1; # hashing increment values my @m=(); # workspace foreach my $n(@i){ my $q=ord($n); # ASCII for character $k += $j; # Increment our hash offset $q += $k; # add our "old" value $j = $k; # store that. push @m,$q; # save the offsetted value } my $hashval=0; #initialize our hash value # Generate that map { $hashval = ($hashval + $_) % 100000} @m; ============================================= Is this the solution i seek to turn an 'absolute path' <=> '5-digit number' in a bi-directional way? From Arah.Leonard at bruker-axs.com Wed Jan 23 13:19:52 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Wed, 23 Jan 2013 18:19:52 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50FF29BA.5010703@gmail.com> <50FF3199.6030104@mrabarnett.plus.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E075867DB@msnmail2.bruker-axs.com> > ============================================= > my @i = split(//,$url); # put each letter in it's own bin > my $j=0; # Initailize our > my $k=1; # hashing increment values > my @m=(); # workspace > foreach my $n(@i){ > my $q=ord($n); # ASCII for character > $k += $j; # Increment our hash offset > $q += $k; # add our "old" value > $j = $k; # store that. > push @m,$q; # save the offsetted value > } > > my $hashval=0; #initialize our hash value # Generate that map { $hashval = ($hashval + $_) % 100000} @m; > ============================================= > > > Is this the solution i seek to turn an 'absolute path' <=> '5-digit number' in a bi-directional way? > 1) There is NO solution to turn a complete path into a 4-digit number in a bi-directional way, no matter what language you write it in. Nor does adding one more digit make it any more plausible. It is NOT possible. Which is why EVERYONE keeps telling you that. The only way to store a complete path in a unique and bi-directional way is to STORE THE COMPLETE PATH. Even if you compress the path data in some way, you would still need to store the complete path. 2) Within reason and sanity, any use of a modulus operator to chop a large checksum value into a small value means that the results are not unique and not reversible. This was plainly stated from the beginning, and is still true no matter how many programming languages you write it in. 3) This is a Python-specific resource and that's not even Python code. What next? Javascript? Ada? Fortran? COBOL? 8-bit x86 assembly with minimal comments written in Esperanto? 4) The novelty of the entertainment resulting from this perversity has waned, even for me. The educational aspect to novice programmers has likewise run dry. I've now officially grown bored of your game and am joining everyone else who already has already gotten off of this kiddie ride. Congratulations on beating a dead horse into mince-meat and successfully milking the one-uddered cow until the pale is full. I hope that you enjoyed your meal. Or to borrow a phrase, "I say GOOD DAY, sir!" From breamoreboy at yahoo.co.uk Wed Jan 23 13:36:27 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 23 Jan 2013 18:36:27 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E075867DB@msnmail2.bruker-axs.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50FF29BA.5010703@gmail.com> <50FF3199.6030104@mrabarnett.plus.com> <2ECADBDABCB17E40B66A25D839706F5E075867DB@msnmail2.bruker-axs.com> Message-ID: On 23/01/2013 18:19, Leonard, Arah wrote: > 3) This is a Python-specific resource and that's not even Python code. What next? Javascript? Ada? Fortran? COBOL? 8-bit x86 assembly with minimal comments written in Esperanto? > Please can we have CORAL 66 mentioned on the odd occasion. > 4) The novelty of the entertainment resulting from this perversity has waned, even for me. The educational aspect to novice programmers has likewise run dry. I've now officially grown bored of your game and am joining everyone else who already has already gotten off of this kiddie ride. Congratulations on beating a dead horse into mince-meat and successfully milking the one-uddered cow until the pale is full. I hope that you enjoyed your meal. > Pail not pale :) > Or to borrow a phrase, "I say GOOD DAY, sir!" > Or madam? -- Cheers. Mark Lawrence From d at davea.name Wed Jan 23 17:46:56 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 17:46:56 -0500 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50FF29BA.5010703@gmail.com> <50FF3199.6030104@mrabarnett.plus.com> <2ECADBDABCB17E40B66A25D839706F5E075867DB@msnmail2.bruker-axs.com> Message-ID: <51006860.1070208@davea.name> On 01/23/2013 01:36 PM, Mark Lawrence wrote: > On 23/01/2013 18:19, Leonard, Arah wrote: >> 3) This is a Python-specific resource and that's not even Python >> code. What next? Javascript? Ada? Fortran? COBOL? 8-bit x86 >> assembly with minimal comments written in Esperanto? >> > > Please can we have CORAL 66 mentioned on the odd occasion. > >> 4) The novelty of the entertainment resulting from this perversity has >> waned, even for me. The educational aspect to novice programmers has >> likewise run dry. I've now officially grown bored of your game and am >> joining everyone else who already has already gotten off of this >> kiddie ride. Congratulations on beating a dead horse into mince-meat >> and successfully milking the one-uddered cow until the pale is full. >> I hope that you enjoyed your meal. >> > > Pail not pale :) > >> Or to borrow a phrase, "I say GOOD DAY, sir!" >> > > Or madam? > or 'script kiddie' -- DaveA From steve+comp.lang.python at pearwood.info Tue Jan 22 21:50:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2013 02:50:07 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ff4fde$0$29877$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 23:40:24 +0000, Steven D'Aprano wrote: [snip content] Holy crap! Sorry for the flood of duplicated posts. That was out of my control, honest. -- Steven From rustompmody at gmail.com Tue Jan 22 22:04:53 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 22 Jan 2013 19:04:53 -0800 (PST) Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff4fde$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: <763db78e-864c-4f58-9820-d4fcda0a7101@6g2000pbh.googlegroups.com> On Jan 23, 7:50?am, Steven D'Aprano wrote: > On Tue, 22 Jan 2013 23:40:24 +0000, Steven D'Aprano wrote: > > [snip content] > > Holy crap! Sorry for the flood of duplicated posts. That was out of my > control, honest. > > -- > Steven Now Now! Considering that you've fried the of all the poor "out- of-my-control' double-posting GG users, what punishment shall we find for you? Heres an idea: Use GG yourself. It will help the group/mailing list by reducing 5-fold double-posting to only 2. It will make you more morally muscular From rosuav at gmail.com Tue Jan 22 23:44:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 15:44:01 +1100 Subject: Using filepath method to identify an .html page In-Reply-To: <763db78e-864c-4f58-9820-d4fcda0a7101@6g2000pbh.googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff4fde$0$29877$c3e8da3$5496439d@news.astraweb.com> <763db78e-864c-4f58-9820-d4fcda0a7101@6g2000pbh.googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 2:04 PM, rusi wrote: > Considering that you've fried the of all the poor "out- > of-my-control' double-posting GG users, what punishment shall we find > for you? > > Heres an idea: Use GG yourself. > It will help the group/mailing list by reducing 5-fold double-posting > to only 2. > It will make you more morally muscular My object all sublime, I shall achieve in time, to let the punishment fit the crime, the punishment fit the crime! Steven, you are hereby sentenced to two hundred hours of community service, responding to posts from Google Groups users who have sent to both python-list and c.l.p. However, this court does know leniency, and time already served will be counted. You are therefore free. Go and sin no more. ChrisA From python at mrabarnett.plus.com Tue Jan 22 22:35:22 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 23 Jan 2013 03:35:22 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: <2cluf89hpt0sjrs0su9f7gm2c0cp9q41h1@invalid.netcom.com> References: <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> <50ff2368$0$29994$c3e8da3$5496439d@news.astraweb.com> <2cluf89hpt0sjrs0su9f7gm2c0cp9q41h1@invalid.netcom.com> Message-ID: <50FF5A7A.6050600@mrabarnett.plus.com> On 2013-01-23 03:15, Dennis Lee Bieber wrote: > On 22 Jan 2013 23:40:24 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > >> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: >> >> > I'm sorry you are getting so frustrated. There's obviously a language >> > barrier here, >> >> I don't think there is. The OP's posts have been written in excellent >> English. >> > > > Okay -- somebody's server glitched... I just received sixteen copies > of this message. > You counted them? I didn't bother! :-) From steve+comp.lang.python at pearwood.info Tue Jan 22 18:34:02 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:34:02 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff21ea$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:35:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:35:34 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff2246$0$29982$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:34:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:34:32 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff2208$0$29968$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:36:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:36:36 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff2283$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:36:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:36:19 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff2273$0$29987$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:37:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:37:06 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff22a2$0$29980$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:39:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:39:23 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff232b$0$29967$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:38:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:38:21 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff22ed$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:39:54 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:39:54 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff234a$0$6574$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:38:08 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:38:08 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff22e0$0$6512$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:37:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:37:51 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff22ce$0$29984$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:39:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:39:10 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff231e$0$29973$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:36:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:36:50 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff2291$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:35:03 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:35:03 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff2227$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 18:37:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:37:20 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com> Message-ID: <50ff22b0$0$29983$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses the name of a troll as his user name. http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Thanks to Alan Spence for linking to the "Flame Warriors" web site. I can't believe that it took so long for anyone to realise that we were being trolled. I hate to admit it, but I kind of have to admire somebody who can play dumb so well for so long for the lulz. Well played Ferrous Cranus, well played. Now please go and play your silly games elsewhere. -- Steven From __peter__ at web.de Tue Jan 22 10:25:42 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 22 Jan 2013 16:25:42 +0100 Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: Ferrous Cranus wrote: > I insist, perhaps compeleld, to use a key to associate a number to a > filename. Would you help please? > > I dont know this is supposed to be written. i just know i need this: > > number = function_that_returns_a_number_out_of_a_string( > absolute_path_of_a_html_file) > > Would someone help me write that in python coding? We are talkign 1 line > of code here.... Since you insist: >>> def function_that_returns_a_number_out_of_a_string(absolute_path_of_a_html_file): ... return int(absolute_path_of_a_html_file.encode("hex"), 16) ... >>> function_that_returns_a_number_out_of_a_string("/foo/bar/baz") 14669632128886499728813089146L As a bonus here is how to turn the number back into a path: >>> x = 14669632128886499728813089146 >>> "{:x}".format(x).decode("hex") '/foo/bar/baz' ;) From nikos.gr33k at gmail.com Tue Jan 22 09:55:04 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 06:55:04 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: ?? ?????, 22 ?????????? 2013 4:33:03 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus wrote: > > > ?? ?????, 22 ?????????? 2013 3:04:41 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > > > > > >> What do you expect int("my-web-page.html") to return? Should it return 23 > > >> or 794 or 109432985462940911485 or 42? > > > > > > I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test. > > > > Just run python without any args, and you'll get interactive mode. You > > can try things out there. > > > > > This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this: > > > > > > /home/nikos/public_html/varsa.gr/articles/html/files/index.html > > > > That's not big. Trust me, modern databases work just fine with unique > > indexes like that. The most common way to organize the index is with a > > binary tree, so the database has to look through log(N) entries. > > That's like figuring out if the two numbers 142857 and 857142 are the > > same; you don't need to look through 1,000,000 possibilities, you just > > need to look through the six digits each number has. > > > > > 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!! > > > > Not that bad actually. I've happily used keys easily that long, and > > expected the database to ensure uniqueness without costing > > performance. > > > > > So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path) > > > > Is there any chance that you'll have more than 10,000 pages? If so, a > > four-digit number is *guaranteed* to have duplicates. And if you > > research the Birthday Paradox, you'll find that any sort of hashing > > algorithm is likely to produce collisions a lot sooner than that. > > > > > Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can). > > > > > > So, that why i need to get a "unique" number out of a string. please help. > > > > Ultimately, that unique number would end up being a foreign key into a > > table of URLs and IDs. So just skip that table and use the URLs > > directly - much easier. In this instance, there's no value in > > normalizing. > > > > ChrisA I insist, perhaps compeleld, to use a key to associate a number to a filename. Would you help please? I dont know this is supposed to be written. i just know i need this: number = function_that_returns_a_number_out_of_a_string( absolute_path_of_a_html_file) Would someone help me write that in python coding? We are talkign 1 line of code here.... From nikos.gr33k at gmail.com Tue Jan 22 10:46:14 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 07:46:14 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly. pin = int( htmlpage.encode("hex"), 16 ) I just tried whayt you gace me This produces a number of: 140530319499494727...677522822126923116L Visit http://superhost.gr to see that displayed error. I think it Why did you use "hex" for? to encode the string to hexarithmetic? what for? From nikos.gr33k at gmail.com Tue Jan 22 10:46:14 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 07:46:14 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly. pin = int( htmlpage.encode("hex"), 16 ) I just tried whayt you gace me This produces a number of: 140530319499494727...677522822126923116L Visit http://superhost.gr to see that displayed error. I think it Why did you use "hex" for? to encode the string to hexarithmetic? what for? From d at davea.name Tue Jan 22 11:11:35 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 11:11:35 -0500 Subject: Using filepath method to identify an .html page In-Reply-To: <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> Message-ID: <50FEBA37.8050107@davea.name> On 01/22/2013 10:46 AM, Ferrous Cranus wrote: > Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly. > > pin = int( htmlpage.encode("hex"), 16 ) > > I just tried whayt you gace me > > This produces a number of: 140530319499494727...677522822126923116L > > Visit http://superhost.gr to see that displayed error. I think it > > Why did you use "hex" for? to encode the string to hexarithmetic? what for? > There are plenty of people (but not me) giving you database advice, but you don't want it. Apparently you do have web access, so why aren't you looking up the functions that don't behave the way you think they should? This page has the built-in functions: http://docs.python.org/2/library/functions.html To get quickly to a particular function, follow the link from the function name at the top of that page. """""" int(x=0) int(x, base=10) Convert a number or string x to an integer, or return 0 if no arguments are given. If x is a number, it can be a plain integer, a long integer, or a floating point number. If x is floating point, the conversion truncates towards zero. If the argument is outside the integer range, the function returns a long object instead. If x is not a number or if base is given, then x must be a string or Unicode object representing an integer literal in radix base. Optionally, the literal can be preceded by + or - (with no space in between) and surrounded by whitespace. A base-n literal consists of the digits 0 to n-1, with a to z (or A to Z) having values 10 to 35. The default base is 10. The allowed values are 0 and 2-36. Base-2, -8, and -16 literals can be optionally prefixed with 0b/0B, 0o/0O/0, or 0x/0X, as with integer literals in code. Base 0 means to interpret the string exactly as an integer literal, so that the actual base is 2, 8, 10, or 16. The integer type is described in Numeric Types ? int, float, long, complex. """""""" Are there words in there which are unclear? A filename is a string, but it doesn't represent an integer literal in any base, and especially not in base 10. -- DaveA From Arah.Leonard at bruker-axs.com Tue Jan 22 11:23:16 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Tue, 22 Jan 2013 16:23:16 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07586186@msnmail2.bruker-axs.com> > Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly. Okay, I think we need to throw the flag on the field at this point. What you're asking for has gone into a realm where you clearly don't even appear to understand what you're asking for. What is the reason for your integer being limited to only 4 digits? Not even databases are limited in such a way. So what are you doing that imposes that kind of a limit, and why? From nikos.gr33k at gmail.com Tue Jan 22 13:13:42 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:13:42 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> Message-ID: ?? ?????, 22 ?????????? 2013 6:23:16 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly. > > > > Okay, I think we need to throw the flag on the field at this point. What you're asking for has gone into a realm where you clearly don't even appear to understand what you're asking for. > > > > What is the reason for your integer being limited to only 4 digits? Not even databases are limited in such a way. So what are you doing that imposes that kind of a limit, and why? a) I'am a reseller, i have unlimited ftp quota, hence database space b) I'am feeling compelled to do it this way c) i DO NOT want to use BIG absolute paths to identify files, just small numbers , shich they are easier to maintain. Your solution i know it works and i thank you very much for providing it to me! Can you help please on the errors that http://superhost.gr gives? From nikos.gr33k at gmail.com Tue Jan 22 13:13:42 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:13:42 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> Message-ID: ?? ?????, 22 ?????????? 2013 6:23:16 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly. > > > > Okay, I think we need to throw the flag on the field at this point. What you're asking for has gone into a realm where you clearly don't even appear to understand what you're asking for. > > > > What is the reason for your integer being limited to only 4 digits? Not even databases are limited in such a way. So what are you doing that imposes that kind of a limit, and why? a) I'am a reseller, i have unlimited ftp quota, hence database space b) I'am feeling compelled to do it this way c) i DO NOT want to use BIG absolute paths to identify files, just small numbers , shich they are easier to maintain. Your solution i know it works and i thank you very much for providing it to me! Can you help please on the errors that http://superhost.gr gives? From torriem at gmail.com Tue Jan 22 13:43:53 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 11:43:53 -0700 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <9d89d978-e570-4b2c-a18e-58d86c35dd4c@googlegroups.com> Message-ID: <50FEDDE9.8030002@gmail.com> On 01/22/2013 11:13 AM, Ferrous Cranus wrote: > a) I'am a reseller, i have unlimited ftp quota, hence database space Space doesn't even come into the equation. There's virtually no difference between a 4-digit number and a 100-character string. Yes there is an absolute difference in storage space, but the difference is so miniscule that there's no point even thinking about it. Especially if you are dealing with less than a million database rows. > b) I'am feeling compelled to do it this way Why? Who's compelling you? Your boss? > c) i DO NOT want to use BIG absolute paths to identify files, just > small numbers , shich they are easier to maintain. No it won't be easier to maintain. I've done my share of web development over the years. There's no difference between using a string index and some form of number index. And if you have to go over the database by hand, having a string is infinitely easier for your brain to comprehend than a magic number. Now don't get me wrong. I've done plenty of tables linked by index numbers, but it's certainly harder to fix the data by hand since an index number only has meaning in the context of a query with another table. > > Your solution i know it works and i thank you very much for > providing it to me! > > Can you help please on the errors that http://superhost.gr gives? Sorry I cannot, since I don't have access to your site's source code, or your database. From nikos.gr33k at gmail.com Tue Jan 22 10:59:58 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 07:59:58 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> ?? ?????, 22 ?????????? 2013 5:25:42 ?.?. UTC+2, ? ??????? Peter Otten ??????: > Ferrous Cranus wrote: > > > > > I insist, perhaps compeleld, to use a key to associate a number to a > > > filename. Would you help please? > > > > > > I dont know this is supposed to be written. i just know i need this: > > > > > > number = function_that_returns_a_number_out_of_a_string( > > > absolute_path_of_a_html_file) > > > > > > Would someone help me write that in python coding? We are talkign 1 line > > > of code here.... > > > > Since you insist: > > > > >>> def function_that_returns_a_number_out_of_a_string(absolute_path_of_a_html_file): > > ... return int(absolute_path_of_a_html_file.encode("hex"), 16) > > ... > > >>> function_that_returns_a_number_out_of_a_string("/foo/bar/baz") > > 14669632128886499728813089146L > > > > As a bonus here is how to turn the number back into a path: > > > > >>> x = 14669632128886499728813089146 > > >>> "{:x}".format(x).decode("hex") > > '/foo/bar/baz' > > > > ;) Thank you but no...no that would be unnecessary complex. I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( From nikos.gr33k at gmail.com Tue Jan 22 10:59:58 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 07:59:58 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> ?? ?????, 22 ?????????? 2013 5:25:42 ?.?. UTC+2, ? ??????? Peter Otten ??????: > Ferrous Cranus wrote: > > > > > I insist, perhaps compeleld, to use a key to associate a number to a > > > filename. Would you help please? > > > > > > I dont know this is supposed to be written. i just know i need this: > > > > > > number = function_that_returns_a_number_out_of_a_string( > > > absolute_path_of_a_html_file) > > > > > > Would someone help me write that in python coding? We are talkign 1 line > > > of code here.... > > > > Since you insist: > > > > >>> def function_that_returns_a_number_out_of_a_string(absolute_path_of_a_html_file): > > ... return int(absolute_path_of_a_html_file.encode("hex"), 16) > > ... > > >>> function_that_returns_a_number_out_of_a_string("/foo/bar/baz") > > 14669632128886499728813089146L > > > > As a bonus here is how to turn the number back into a path: > > > > >>> x = 14669632128886499728813089146 > > >>> "{:x}".format(x).decode("hex") > > '/foo/bar/baz' > > > > ;) Thank you but no...no that would be unnecessary complex. I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( From rosuav at gmail.com Tue Jan 22 11:11:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 03:11:20 +1100 Subject: Using filepath method to identify an .html page In-Reply-To: <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 2:59 AM, Ferrous Cranus wrote: > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( Either you are deliberately trolling, or you have a major comprehension problem. Please go back and read, carefully, all the remarks you've been offered in this thread. Feel free to ask for clarification of anything that doesn't make sense, but be sure to read all of it. You are asking something that is fundamentally impossible[1]. There simply are not enough numbers to go around. ChrisA [1] Well, impossible in decimal. If you work in base 4294967296, you could do what you want in four "digits". From nikos.gr33k at gmail.com Tue Jan 22 13:26:10 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:26:10 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> Message-ID: <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> ?? ?????, 22 ?????????? 2013 6:11:20 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Wed, Jan 23, 2013 at 2:59 AM, Ferrous Cranus wrote: > > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( > > > > Either you are deliberately trolling, or you have a major > > comprehension problem. Please go back and read, carefully, all the > > remarks you've been offered in this thread. Feel free to ask for > > clarification of anything that doesn't make sense, but be sure to read > > all of it. You are asking something that is fundamentally > > impossible[1]. There simply are not enough numbers to go around. > > > > ChrisA > > [1] Well, impossible in decimal. If you work in base 4294967296, you > > could do what you want in four "digits". Fundamentally impossible? Well.... OK: How about this in Perl: $ cat testMD5.pl use strict; foreach my $url(qw@ /index.html /about/time.html @){ hashit($url); } sub hashit { my $url=shift; my @ltrs=split(//,$url); my $hash = 0; foreach my $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; } printf "%s: %0.4d\n",$url,$hash } which yields: $ perl testMD5.pl /index.html: 1066 /about/time.html: 1547 From nikos.gr33k at gmail.com Tue Jan 22 13:26:10 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:26:10 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> Message-ID: <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> ?? ?????, 22 ?????????? 2013 6:11:20 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Wed, Jan 23, 2013 at 2:59 AM, Ferrous Cranus wrote: > > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( > > > > Either you are deliberately trolling, or you have a major > > comprehension problem. Please go back and read, carefully, all the > > remarks you've been offered in this thread. Feel free to ask for > > clarification of anything that doesn't make sense, but be sure to read > > all of it. You are asking something that is fundamentally > > impossible[1]. There simply are not enough numbers to go around. > > > > ChrisA > > [1] Well, impossible in decimal. If you work in base 4294967296, you > > could do what you want in four "digits". Fundamentally impossible? Well.... OK: How about this in Perl: $ cat testMD5.pl use strict; foreach my $url(qw@ /index.html /about/time.html @){ hashit($url); } sub hashit { my $url=shift; my @ltrs=split(//,$url); my $hash = 0; foreach my $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; } printf "%s: %0.4d\n",$url,$hash } which yields: $ perl testMD5.pl /index.html: 1066 /about/time.html: 1547 From python at mrabarnett.plus.com Tue Jan 22 13:49:45 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 22 Jan 2013 18:49:45 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Message-ID: <50FEDF49.1090400@mrabarnett.plus.com> On 2013-01-22 18:26, Ferrous Cranus wrote: > ?? ?????, 22 ?????????? 2013 6:11:20 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> On Wed, Jan 23, 2013 at 2:59 AM, Ferrous Cranus wrote: >> >> > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( >> >> Either you are deliberately trolling, or you have a major >> comprehension problem. Please go back and read, carefully, all the >> remarks you've been offered in this thread. Feel free to ask for >> clarification of anything that doesn't make sense, but be sure to read >> all of it. You are asking something that is fundamentally >> impossible[1]. There simply are not enough numbers to go around. >> >> ChrisA >> >> [1] Well, impossible in decimal. If you work in base 4294967296, you >> >> could do what you want in four "digits". > > Fundamentally impossible? > Yes. > Well.... > > OK: How about this in Perl: > > $ cat testMD5.pl > use strict; > > foreach my $url(qw@ /index.html /about/time.html @){ > hashit($url); > } > > sub hashit { > my $url=shift; > my @ltrs=split(//,$url); > my $hash = 0; > > foreach my $ltr(@ltrs){ > $hash = ( $hash + ord($ltr)) %10000; > } > printf "%s: %0.4d\n",$url,$hash > > } > > > which yields: > $ perl testMD5.pl > /index.html: 1066 > /about/time.html: 1547 > That shortens the int to 4 digits. A hash isn't guaranteed to be unique. A hash is an attempt to make an int which is highly sensitive to a change in the data so that a small change in the data will result in a different int. If the change is big enough it _could_ give the same int, but the hope is that it probably won't. (Ideally, if the hash has 4 decimal digits, you'd hope that the chance of different data giving the same hash would be about 1 in 10000.) From torriem at gmail.com Tue Jan 22 13:49:47 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 11:49:47 -0700 Subject: Using filepath method to identify an .html page In-Reply-To: <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Message-ID: <50FEDF4B.5010800@gmail.com> On 01/22/2013 11:26 AM, Ferrous Cranus wrote: > which yields: > $ perl testMD5.pl > /index.html: 1066 > /about/time.html: 1547 Well do it the same with in python then. Just read the docs on the hashlib so you know what kind of object it returns and how to call methods on that object to return a big number that you can then do % 10000 on it. Note that your perl code is guaranteed to have collisions in the final number generated. If you're comfortable with perl, maybe you should use it rather than fight a language that you are not comfortable with and not understanding. From d at davea.name Tue Jan 22 14:00:16 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 14:00:16 -0500 Subject: Using filepath method to identify an .html page In-Reply-To: <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Message-ID: <50FEE1C0.6080508@davea.name> On 01/22/2013 01:26 PM, Ferrous Cranus wrote: > >> > > sub hashit { > my $url=shift; > my @ltrs=split(//,$url); > my $hash = 0; > > foreach my $ltr(@ltrs){ > $hash = ( $hash + ord($ltr)) %10000; > } > printf "%s: %0.4d\n",$url,$hash > > } > > > which yields: > $ perl testMD5.pl > /index.html: 1066 > /about/time.html: 1547 > If you use that algorithm to get a 4 digit number, it'll look good for the first few files. But if you try 100 files, you've got almost 40% chance of a collision, and if you try 10001, you've got a 100% chance. So is it really okay to reuse the same integer for different files? I tried to help you when you were using the md5 algorithm. By using enough digits/characters, you can cut the likelihood of a collision quite small. But 4 digits, don't be ridiculous. -- DaveA From __peter__ at web.de Tue Jan 22 14:16:34 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 22 Jan 2013 20:16:34 +0100 Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Message-ID: Ferrous Cranus wrote: > ?? ?????, 22 ?????????? 2013 6:11:20 ?.?. UTC+2, ? ??????? Chris Angelico > ??????: >> all of it. You are asking something that is fundamentally >> impossible[1]. There simply are not enough numbers to go around. > Fundamentally impossible? > > Well.... > > OK: How about this in Perl: > > $ cat testMD5.pl > use strict; > > foreach my $url(qw@ /index.html /about/time.html @){ > hashit($url); > } > > sub hashit { > my $url=shift; > my @ltrs=split(//,$url); > my $hash = 0; > > foreach my $ltr(@ltrs){ > $hash = ( $hash + ord($ltr)) %10000; > } > printf "%s: %0.4d\n",$url,$hash > > } > > > which yields: > $ perl testMD5.pl > /index.html: 1066 > /about/time.html: 1547 $ cat clashes.pl use strict; foreach my $url(qw@ /public/fails.html /large/cannot.html /number/being.html /hope/already.html /being/really.html /index/breath.html /can/although.html @){ hashit($url); } sub hashit { my $url=shift; my @ltrs=split(//,$url); my $hash = 0; foreach my $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; } printf "%s: %0.4d\n",$url,$hash } $ perl clashes.pl /public/fails.html: 1743 /large/cannot.html: 1743 /number/being.html: 1743 /hope/already.html: 1743 /being/really.html: 1743 /index/breath.html: 1743 /can/although.html: 1743 Hm, I must be holding it wrong... From nikos.gr33k at gmail.com Wed Jan 23 02:25:45 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 23:25:45 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Message-ID: <2a972302-27ee-4fcb-9928-e0e67afeec36@googlegroups.com> ?? ?????, 22 ?????????? 2013 9:16:34 ?.?. UTC+2, ? ??????? Peter Otten ??????: > Ferrous Cranus wrote: > > > > > ?? ?????, 22 ?????????? 2013 6:11:20 ?.?. UTC+2, ? ??????? Chris Angelico > > > ??????: > > > > >> all of it. You are asking something that is fundamentally > > >> impossible[1]. There simply are not enough numbers to go around. > > > > > Fundamentally impossible? > > > > > > Well.... > > > > > > OK: How about this in Perl: > > > > > > $ cat testMD5.pl > > > use strict; > > > > > > foreach my $url(qw@ /index.html /about/time.html @){ > > > hashit($url); > > > } > > > > > > sub hashit { > > > my $url=shift; > > > my @ltrs=split(//,$url); > > > my $hash = 0; > > > > > > foreach my $ltr(@ltrs){ > > > $hash = ( $hash + ord($ltr)) %10000; > > > } > > > printf "%s: %0.4d\n",$url,$hash > > > > > > } > > > > > > > > > which yields: > > > $ perl testMD5.pl > > > /index.html: 1066 > > > /about/time.html: 1547 > > > > $ cat clashes.pl > > use strict; > > > > foreach my $url(qw@ > > /public/fails.html > > /large/cannot.html > > /number/being.html > > /hope/already.html > > /being/really.html > > /index/breath.html > > /can/although.html > > @){ > > hashit($url); > > } > > > > sub hashit { > > my $url=shift; > > my @ltrs=split(//,$url); > > my $hash = 0; > > > > foreach my $ltr(@ltrs){ > > $hash = ( $hash + ord($ltr)) %10000; > > } > > printf "%s: %0.4d\n",$url,$hash > > > > } > > $ perl clashes.pl > > /public/fails.html: 1743 > > /large/cannot.html: 1743 > > /number/being.html: 1743 > > /hope/already.html: 1743 > > /being/really.html: 1743 > > /index/breath.html: 1743 > > /can/although.html: 1743 > > > > Hm, I must be holding it wrong... my @i = split(//,$url); # put each letter in it's own bin my $j=0; # Initailize our my $k=1; # hashing increment values my @m=(); # workspace foreach my $n(@i){ my $q=ord($n); # ASCII for character $k += $j; # Increment our hash offset $q += $k; # add our "old" value $j = $k; # store that. push @m,$q; # save the offsetted value } my $hashval=0; #initialize our hash value # Generate that map { $hashval = ($hashval + $_) % 10000} @m; Using that method ABC.html and CBA.html now have different values because each letter position's value gets bumped up increasingly from left to right. From nikos.gr33k at gmail.com Wed Jan 23 02:25:45 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 23:25:45 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Message-ID: <2a972302-27ee-4fcb-9928-e0e67afeec36@googlegroups.com> ?? ?????, 22 ?????????? 2013 9:16:34 ?.?. UTC+2, ? ??????? Peter Otten ??????: > Ferrous Cranus wrote: > > > > > ?? ?????, 22 ?????????? 2013 6:11:20 ?.?. UTC+2, ? ??????? Chris Angelico > > > ??????: > > > > >> all of it. You are asking something that is fundamentally > > >> impossible[1]. There simply are not enough numbers to go around. > > > > > Fundamentally impossible? > > > > > > Well.... > > > > > > OK: How about this in Perl: > > > > > > $ cat testMD5.pl > > > use strict; > > > > > > foreach my $url(qw@ /index.html /about/time.html @){ > > > hashit($url); > > > } > > > > > > sub hashit { > > > my $url=shift; > > > my @ltrs=split(//,$url); > > > my $hash = 0; > > > > > > foreach my $ltr(@ltrs){ > > > $hash = ( $hash + ord($ltr)) %10000; > > > } > > > printf "%s: %0.4d\n",$url,$hash > > > > > > } > > > > > > > > > which yields: > > > $ perl testMD5.pl > > > /index.html: 1066 > > > /about/time.html: 1547 > > > > $ cat clashes.pl > > use strict; > > > > foreach my $url(qw@ > > /public/fails.html > > /large/cannot.html > > /number/being.html > > /hope/already.html > > /being/really.html > > /index/breath.html > > /can/although.html > > @){ > > hashit($url); > > } > > > > sub hashit { > > my $url=shift; > > my @ltrs=split(//,$url); > > my $hash = 0; > > > > foreach my $ltr(@ltrs){ > > $hash = ( $hash + ord($ltr)) %10000; > > } > > printf "%s: %0.4d\n",$url,$hash > > > > } > > $ perl clashes.pl > > /public/fails.html: 1743 > > /large/cannot.html: 1743 > > /number/being.html: 1743 > > /hope/already.html: 1743 > > /being/really.html: 1743 > > /index/breath.html: 1743 > > /can/although.html: 1743 > > > > Hm, I must be holding it wrong... my @i = split(//,$url); # put each letter in it's own bin my $j=0; # Initailize our my $k=1; # hashing increment values my @m=(); # workspace foreach my $n(@i){ my $q=ord($n); # ASCII for character $k += $j; # Increment our hash offset $q += $k; # add our "old" value $j = $k; # store that. push @m,$q; # save the offsetted value } my $hashval=0; #initialize our hash value # Generate that map { $hashval = ($hashval + $_) % 10000} @m; Using that method ABC.html and CBA.html now have different values because each letter position's value gets bumped up increasingly from left to right. From torriem at gmail.com Wed Jan 23 10:25:36 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 23 Jan 2013 08:25:36 -0700 Subject: Using filepath method to identify an .html page In-Reply-To: <2a972302-27ee-4fcb-9928-e0e67afeec36@googlegroups.com> References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> <2a972302-27ee-4fcb-9928-e0e67afeec36@googlegroups.com> Message-ID: <510000F0.4070406@gmail.com> On 01/23/2013 12:25 AM, Ferrous Cranus wrote: > > Using that method ABC.html and CBA.html now have different values > because each letter position's value gets bumped up increasingly from > left to right. You have run this little "hash" algorithm on a whole bunch of files, say C:\windows\system32 right? And how many collisions did you get? You've already rejected using the file path or url as a key because it could change. Why are you wanting to do this hash based on the file's path or url anyway? From nikos.gr33k at gmail.com Wed Jan 23 10:56:56 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 07:56:56 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> <2a972302-27ee-4fcb-9928-e0e67afeec36@googlegroups.com> Message-ID: <31584b1b-4e84-459d-b027-8daf65bf2910@googlegroups.com> ?? ???????, 23 ?????????? 2013 5:25:36 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 01/23/2013 12:25 AM, Ferrous Cranus wrote: > > > > > > Using that method ABC.html and CBA.html now have different values > > > because each letter position's value gets bumped up increasingly from > > > left to right. > > > > You have run this little "hash" algorithm on a whole bunch of files, say > > C:\windows\system32 right? And how many collisions did you get? > > > > You've already rejected using the file path or url as a key because it > > could change. Why are you wanting to do this hash based on the file's > > path or url anyway? No, its inevitable, something must remain the same. Filepath *must* be used. Can you transliterate this code to Python code please? From nikos.gr33k at gmail.com Wed Jan 23 10:56:56 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 07:56:56 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> <2a972302-27ee-4fcb-9928-e0e67afeec36@googlegroups.com> Message-ID: <31584b1b-4e84-459d-b027-8daf65bf2910@googlegroups.com> ?? ???????, 23 ?????????? 2013 5:25:36 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 01/23/2013 12:25 AM, Ferrous Cranus wrote: > > > > > > Using that method ABC.html and CBA.html now have different values > > > because each letter position's value gets bumped up increasingly from > > > left to right. > > > > You have run this little "hash" algorithm on a whole bunch of files, say > > C:\windows\system32 right? And how many collisions did you get? > > > > You've already rejected using the file path or url as a key because it > > could change. Why are you wanting to do this hash based on the file's > > path or url anyway? No, its inevitable, something must remain the same. Filepath *must* be used. Can you transliterate this code to Python code please? From gordon at panix.com Tue Jan 22 11:55:02 2013 From: gordon at panix.com (John Gordon) Date: Tue, 22 Jan 2013 16:55:02 +0000 (UTC) Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: In Ferrous Cranus writes: > I just need a way to CONVERT a string(absolute path) to a 4-digit unique > number with INT!!! That's all i want!! But i cannot make it work :( Given your requirements, I don't think it *can* work. There's just no way to do it. How can the computer guarantee that billions of possible inputs (file paths) map to 10,000 unique outputs (4-digit numbers)? It's not possible. It might be possible if you had control over the format of the input strings, but it doesn't sound like you do. Can you maintain a separate database which maps file paths to numbers? If so, then this is an easy problem. Just keep a lookup table, like so: filepath number -------- ------ /home/files/bob/foo.html 0001 /home/files/bob/bar.html 0002 /home/files/steve/recipes/chocolate-cake.html 0003 /home/files/mary/payroll.html 0004 -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From nikos.gr33k at gmail.com Tue Jan 22 13:07:21 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:07:21 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <4847a0e3-aefa-4330-9252-db08f2e993df@googlegroups.com> ?? ?????, 22 ?????????? 2013 6:55:02 ?.?. UTC+2, ? ??????? John Gordon ??????: > In Ferrous Cranus writes: > > > > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique > > > number with INT!!! That's all i want!! But i cannot make it work :( > > > > Given your requirements, I don't think it *can* work. There's just no > > way to do it. > > > > How can the computer guarantee that billions of possible inputs (file paths) > > map to 10,000 unique outputs (4-digit numbers)? It's not possible. > > > > It might be possible if you had control over the format of the input strings, > > but it doesn't sound like you do. > > > > Can you maintain a separate database which maps file paths to numbers? > > If so, then this is an easy problem. Just keep a lookup table, like so: > > > > filepath number > > -------- ------ > > /home/files/bob/foo.html 0001 > > /home/files/bob/bar.html 0002 > > /home/files/steve/recipes/chocolate-cake.html 0003 > > /home/files/mary/payroll.html 0004 > > > > -- > > John Gordon A is for Amy, who fell down the stairs > > gordon at panix.com B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies" No, because i DO NOT WANT to store LOTS OF BIGS absolute paths in the database. And the .html files are not even close 10.000 From gordon at panix.com Tue Jan 22 13:37:10 2013 From: gordon at panix.com (John Gordon) Date: Tue, 22 Jan 2013 18:37:10 +0000 (UTC) Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <4847a0e3-aefa-4330-9252-db08f2e993df@googlegroups.com> Message-ID: In <4847a0e3-aefa-4330-9252-db08f2e993df at googlegroups.com> Ferrous Cranus writes: > And the .html files are not even close 10.000 You said you wanted a 4-digit number. There are 10,000 different 4-digit numbers. 0000 0001 0002 ... 9999 -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve+comp.lang.python at pearwood.info Tue Jan 22 18:23:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 23:23:42 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <4847a0e3-aefa-4330-9252-db08f2e993df@googlegroups.com> Message-ID: <50ff1f7d$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 10:07:21 -0800, Ferrous Cranus wrote: > No, because i DO NOT WANT to store LOTS OF BIGS absolute paths in the > database. They are not big. They are tiny. Please stop being too arrogant to listen to advice from people who have been programming for years or decades. -- Steven From rustompmody at gmail.com Tue Jan 22 12:33:00 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 22 Jan 2013 09:33:00 -0800 (PST) Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: On Jan 22, 8:59?pm, Ferrous Cranus wrote: > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! > That's all i want!! But i cannot make it work :( I just need a way to eat my soup with a screwdriver. No I WONT use a spoon. Im starving HELP From breamoreboy at yahoo.co.uk Tue Jan 22 12:54:44 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 22 Jan 2013 17:54:44 +0000 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: On 22/01/2013 17:33, rusi wrote: > On Jan 22, 8:59 pm, Ferrous Cranus wrote: >> I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! >> That's all i want!! But i cannot make it work :( > > I just need a way to eat my soup with a screwdriver. > No I WONT use a spoon. > > Im starving > HELP > Unfortunately a spoon wouldn't help in this case as the soup is being served in a basket. However I still absolutely insist that a Python solution to this problem is found. -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Tue Jan 22 13:23:57 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:23:57 -0800 (PST) Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <068984f0-851c-462a-8fc3-455dceb20295@googlegroups.com> ?? ?????, 22 ?????????? 2013 7:33:00 ?.?. UTC+2, ? ??????? rusi ??????: > On Jan 22, 8:59?pm, Ferrous Cranus wrote: > > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! > > > That's all i want!! But i cannot make it work :( > > > > I just need a way to eat my soup with a screwdriver. > > No I WONT use a spoon. > > > > Im starving > > HELP That was funny! From steve+comp.lang.python at pearwood.info Tue Jan 22 17:45:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 22:45:30 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <50ff168a$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 09:33:00 -0800, rusi wrote: > On Jan 22, 8:59?pm, Ferrous Cranus wrote: >> I just need a way to CONVERT a string(absolute path) to a 4-digit >> unique number with INT!!! That's all i want!! But i cannot make it work >> :( > > I just need a way to eat my soup with a screwdriver. No I WONT use a > spoon. > > Im starving > HELP Very well done :-) -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 22 17:44:29 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2013 22:44:29 GMT Subject: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <50ff164d$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 09:33:00 -0800, rusi wrote: > On Jan 22, 8:59?pm, Ferrous Cranus wrote: >> I just need a way to CONVERT a string(absolute path) to a 4-digit >> unique number with INT!!! That's all i want!! But i cannot make it work >> :( > > I just need a way to eat my soup with a screwdriver. No I WONT use a > spoon. > > Im starving > HELP Very well done :-) -- Steven From msirenef at lightbird.net Tue Jan 22 19:23:55 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Tue, 22 Jan 2013 19:23:55 -0500 Subject: Using filepath method to identify an .html page In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Message-ID: <50FF2D9B.8000207@lightbird.net> On 01/22/2013 12:33 PM, rusi wrote: > On Jan 22, 8:59 pm, Ferrous Cranus wrote: >> I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! >> That's all i want!! But i cannot make it work :( > > I just need a way to eat my soup with a screwdriver. > No I WONT use a spoon. > > Im starving > HELP Well done, sir! :-) -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Life is not a spectacle or a feast; it is a predicament. George Santayana From torriem at gmail.com Tue Jan 22 13:21:23 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 11:21:23 -0700 Subject: Using filepath method to identify an .html page In-Reply-To: References: Message-ID: <50FED8A3.2040702@gmail.com> On 01/22/2013 03:07 AM, Ferrous Cranus wrote: > Now, can you pleas help me write the switch to filepath identifier? > I'am having trouble writing it. Unfortunately this isn't the way to go either. Apache uses its own config and rules to map a url to a "filepath." There's no way for Python to do this without interrogating Apache. And it's not necessary anyway. Urls to paths are mapped in a fairly static way by Apache. Just put your files in the right folders and generate the appropriate urls. It's not hard. You're struggling because you either don't understand how apache works, or you're trying to work against it. I've been deploying web sites for years and I've never had to do any of the things you are trying to make Python do. From wuwei23 at gmail.com Tue Jan 22 20:27:04 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 22 Jan 2013 17:27:04 -0800 (PST) Subject: Using filepath method to identify an .html page References: Message-ID: <7015fdf8-fcab-4d67-9cb8-52e29f788098@y3g2000pbq.googlegroups.com> On Jan 22, 8:07?pm, Ferrous Cranus wrote: > Hello, i decided to switch from embedding string into .html to actually grab the filepath in order to identify it So all that crap you wrote in past threads about absolutely essentially needing to identify a html page _no matter where it was stored on the filesystem_ *was* just crap then? You're almost certainly trolling. On the minimal chance that you're not, you should _never_ be identifying a web page by its physical storage location, you should be identifying it by its _url_. But your "oh no, those two lines of code are two complex, I MUST DO IT WITH INT" shrillness has pretty much convinced me you're an idiot and/ or a troll. Look out, everyone, Br'er Ferrous is trying to get you all stuck in a tar thread again. From warem2888 at gmail.com Tue Jan 22 08:20:13 2013 From: warem2888 at gmail.com (Constantine) Date: Tue, 22 Jan 2013 05:20:13 -0800 (PST) Subject: Nurse Dames gives her boss a good farewell fucking Message-ID: <926d16ed-00fc-4c02-9f8c-1acaff701317@googlegroups.com> Nurse Dames gives her boss a good farewell fucking http://t.co/Ox0UsUMj From nikos.gr33k at gmail.com Tue Jan 22 11:15:50 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 08:15:50 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) Message-ID: I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( And the best part is that "that" number must be able to turn back into a path. This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!! 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. I turn the path into a 4-digitnumber 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great! From Arah.Leonard at bruker-axs.com Tue Jan 22 11:27:32 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Tue, 22 Jan 2013 16:27:32 +0000 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07586197@msnmail2.bruker-axs.com> > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( > > And the best part is that "that" number must be able to turn back into a path. > > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!! > > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. I turn the path into a 4-digitnumber 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great! Without involving some kind of lookup table/map service to store the paths (which would entirely defeat the purpose) what you are ranting about is technically impossible. If you tried really really hard you *might* be able to convert a string that long into some kind of 4-digit integer checksum, but you would *never* be able to convert that back into a file path. Nor would it be guaranteed to be unique. From darcy at druid.net Tue Jan 22 12:04:45 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 22 Jan 2013 12:04:45 -0500 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07586197@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07586197@msnmail2.bruker-axs.com> Message-ID: <20130122120445.7f7dc146@imp> On Tue, 22 Jan 2013 16:27:32 +0000 "Leonard, Arah" wrote: > > I just need a way to CONVERT a string(absolute path) to a 4-digit > > unique number with INT!!! That's all i want!! But i cannot make it > > work :( Why bother? Just wish for a zillion dollars and then you never have to program again. At least that would be theoretically possible. > *might* be able to convert a string that long into some kind of > 4-digit integer checksum, but you would *never* be able to convert > that back into a file path. Nor would it be guaranteed to be unique. In fact, if you have 10,001 files it is absolutely guaranteed to have at least one duplicate entry. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From breamoreboy at yahoo.co.uk Tue Jan 22 11:27:47 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 22 Jan 2013 16:27:47 +0000 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: Message-ID: On 22/01/2013 16:15, Ferrous Cranus wrote: > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( > > And the best part is that "that" number must be able to turn back into a path. > > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!! > > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) > 2. I turn the path into a 4-digitnumber > 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great! > Hi Iron Skull, I hereby nominate you for Troll of the Millenium. -- Cheers. Mark Lawrence From d at davea.name Tue Jan 22 11:40:57 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 11:40:57 -0500 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: Message-ID: <50FEC119.3070006@davea.name> On 01/22/2013 11:15 AM, Ferrous Cranus wrote: > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( > > And the best part is that "that" number must be able to turn back into a path. > > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!! > > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) > 2. I turn the path into a 4-digitnumber > 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great! > I had prepared a detailed response, showing what your choices are with this new constraint. But I can see from this post here that there's no point, so I've thrown it out. Either you're trolling, or you have a very limited knowledge of mathematics. This isn't a programming problem, it's a simple problem of information theory. Unless you constrain your users to very restrictive filenames, what you ask here simply cannot be done. Perpetual motion machine, anyone? Or a compression algorithm which can be applied repeatedly to a chunk of data until it shrinks down to one byte? No way to do it without cheating, and the literature is full of examples of people cheating. -- DaveA From nikos.gr33k at gmail.com Tue Jan 22 12:02:58 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 09:02:58 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: Message-ID: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> ?? ?????, 22 ?????????? 2013 6:27:32 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( > > > > > > And the best part is that "that" number must be able to turn back into a path. > > > > > > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!! > > > > > > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. I turn the path into a 4-digitnumber 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great! > > > > Without involving some kind of lookup table/map service to store the paths (which would entirely >defeat the purpose) what you are ranting about is technically impossible. If you tried really >really hard you *might* be able to convert a string that long into some kind of 4-digit integer >checksum, but you would *never* be able to convert that back into a file path. Nor would it be >guaranteed to be unique. Now that iam thinking of it more and more, i don't have to turn the 'path' back to a 'number' So, what i want is a function foo() that does this: foo( "some long string" ) --> 1234 ===================== 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. turn the 'path' to 4-digit number and save it as 'pin' (how?) 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE HTML PAGE'S PATH TO THE DATABASE ANYMORE!!! this is just great! At some later time i want to check the weblog of that .html page 1. request the page as: http://mydomain.gr/index.html?show=log 2. .htaccess gives my script the absolute path of the requested .html file 3. turn the 'path' to 4-digit number and save it as 'pin' (this is what i'am asking) 4. select all log records for that specific .html page (based on the 'pin' column) Since i have the requested 'path' which has been converted to a database stored 4-digit number, i'am aware for which page i'am requesting detailed data from, so i look upon the 'pin' column in the database and thus i know which records i want to select. No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page Can this be done? From nikos.gr33k at gmail.com Tue Jan 22 12:02:58 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 09:02:58 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: Message-ID: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> ?? ?????, 22 ?????????? 2013 6:27:32 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( > > > > > > And the best part is that "that" number must be able to turn back into a path. > > > > > > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!! > > > > > > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. I turn the path into a 4-digitnumber 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great! > > > > Without involving some kind of lookup table/map service to store the paths (which would entirely >defeat the purpose) what you are ranting about is technically impossible. If you tried really >really hard you *might* be able to convert a string that long into some kind of 4-digit integer >checksum, but you would *never* be able to convert that back into a file path. Nor would it be >guaranteed to be unique. Now that iam thinking of it more and more, i don't have to turn the 'path' back to a 'number' So, what i want is a function foo() that does this: foo( "some long string" ) --> 1234 ===================== 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. turn the 'path' to 4-digit number and save it as 'pin' (how?) 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE HTML PAGE'S PATH TO THE DATABASE ANYMORE!!! this is just great! At some later time i want to check the weblog of that .html page 1. request the page as: http://mydomain.gr/index.html?show=log 2. .htaccess gives my script the absolute path of the requested .html file 3. turn the 'path' to 4-digit number and save it as 'pin' (this is what i'am asking) 4. select all log records for that specific .html page (based on the 'pin' column) Since i have the requested 'path' which has been converted to a database stored 4-digit number, i'am aware for which page i'am requesting detailed data from, so i look upon the 'pin' column in the database and thus i know which records i want to select. No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page Can this be done? From Arah.Leonard at bruker-axs.com Tue Jan 22 12:24:26 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Tue, 22 Jan 2013 17:24:26 +0000 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E075861DE@msnmail2.bruker-axs.com> > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page > > Can this be done? Guaranteed to be unique? Not even remotely possible. Even with a lookup table approach (which defeats your purpose of not storing the path) with 4 digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse. Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make: pin = int( htmlpage.encode("hex"), 16 ) % 10000 It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that. From nikos.gr33k at gmail.com Tue Jan 22 12:39:11 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 09:39:11 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> Message-ID: <592233bd-3fc1-4e13-97f8-e11f89fbb0ba@googlegroups.com> ?? ?????, 22 ?????????? 2013 7:24:26 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page > > > > > > Can this be done? > > > > Guaranteed to be unique? Not even remotely possible. Even with a lookup table approach (which defeats your purpose of not storing the path) with 4 digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse. > > > > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make: > > pin = int( htmlpage.encode("hex"), 16 ) % 10000 > > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that. Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!! NOW, if you please explain it to me from the innermost parenthesis please, because i do want to understand it!!! And since i'am sure it works, and i just used it on http://superhost.gr please view my domain and help me understand why its producing errors for me. Your 1-line code surely works but somethings not letting my webpage load normally. Please take a look.... From nikos.gr33k at gmail.com Tue Jan 22 12:39:11 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 09:39:11 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> Message-ID: <592233bd-3fc1-4e13-97f8-e11f89fbb0ba@googlegroups.com> ?? ?????, 22 ?????????? 2013 7:24:26 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page > > > > > > Can this be done? > > > > Guaranteed to be unique? Not even remotely possible. Even with a lookup table approach (which defeats your purpose of not storing the path) with 4 digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse. > > > > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make: > > pin = int( htmlpage.encode("hex"), 16 ) % 10000 > > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that. Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!! NOW, if you please explain it to me from the innermost parenthesis please, because i do want to understand it!!! And since i'am sure it works, and i just used it on http://superhost.gr please view my domain and help me understand why its producing errors for me. Your 1-line code surely works but somethings not letting my webpage load normally. Please take a look.... From gordon at panix.com Tue Jan 22 13:36:05 2013 From: gordon at panix.com (John Gordon) Date: Tue, 22 Jan 2013 18:36:05 +0000 (UTC) Subject: Converting a string to a number by using INT (no hash method) References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <592233bd-3fc1-4e13-97f8-e11f89fbb0ba@googlegroups.com> Message-ID: In <592233bd-3fc1-4e13-97f8-e11f89fbb0ba at googlegroups.com> Ferrous Cranus writes: > > pin int( htmlpage.encode("hex"), 16 ) % 10000 > > > > It'll give you your number, but there are no guarantees of uniqueness. > You're looking at more blind random luck using that. > Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!! No it isn't; you said you wanted a unique 4-digit number. This method can return the same 4-digit number for lots of different file paths. > NOW, if you please explain it to me from the innermost parenthesis please, > because i do want to understand it!!! 1. Transform the html path string into a (large) hexadecimal number using the encode() function. 2. Convert the hexadecimal number into a decimal integer using the int() function. 3. Shrink the integer into the range 0-9999 by using the % operator. From nikos.gr33k at gmail.com Tue Jan 22 13:37:36 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:37:36 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> Message-ID: <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> ?? ?????, 22 ?????????? 2013 7:24:26 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page > > > > > > Can this be done? > > > > Guaranteed to be unique? Not even remotely possible. Even with a lookup table approach (which defeats your purpose of not storing the path) with 4 digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse. > > > > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make: > > pin = int( htmlpage.encode("hex"), 16 ) % 10000 > > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that. ============================================== pin = int( htmlpage.encode("hex"), 16 ) % 10000 ============================================== Can you please explain the differences to what you have posted opposed to this perl coding? ============================================== foreach my $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; ============================================== I want to understand this and see it implemented in Python. From nikos.gr33k at gmail.com Tue Jan 22 13:37:36 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 10:37:36 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> Message-ID: <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> ?? ?????, 22 ?????????? 2013 7:24:26 ?.?. UTC+2, ? ??????? Leonard, Arah ??????: > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page > > > > > > Can this be done? > > > > Guaranteed to be unique? Not even remotely possible. Even with a lookup table approach (which defeats your purpose of not storing the path) with 4 digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse. > > > > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make: > > pin = int( htmlpage.encode("hex"), 16 ) % 10000 > > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that. ============================================== pin = int( htmlpage.encode("hex"), 16 ) % 10000 ============================================== Can you please explain the differences to what you have posted opposed to this perl coding? ============================================== foreach my $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; ============================================== I want to understand this and see it implemented in Python. From torriem at gmail.com Tue Jan 22 14:02:48 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Jan 2013 12:02:48 -0700 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> Message-ID: <50FEE258.6080402@gmail.com> On 01/22/2013 11:37 AM, Ferrous Cranus wrote: > ============================================== pin = int( > htmlpage.encode("hex"), 16 ) % 10000 > ============================================== > > Can you please explain the differences to what you have posted > opposed to this perl coding? > > ============================================== foreach my > $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; > ============================================== > > I want to understand this and see it implemented in Python. It isn't quite the thing. The perl code is merely a checksum of the ascii value of the characters in the file name, that is then chopped down to a number < 10000. The Python code is taking the ascii value of each character in the file name, converting it to a hexadecimal pair of digits, stringing them all out into a long string, then converting that to a number using the hexadecimal number parser. This results in a *very* large number, 8-bits per letter in the original file name, and then chops that down to 10000. Technically neither method is a hash and neither will generate unique numbers. Here's the python algorithm used on a short word: 'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f) => 0x68656c6c6f => 448378203247 mod that with 10000 and you get 3247 If you would simply run the python interpreter and try these things out you could see how and why they work or not work. What is stopping you from doing this? From d at davea.name Tue Jan 22 14:08:14 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 14:08:14 -0500 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> Message-ID: <50FEE39E.4060204@davea.name> On 01/22/2013 01:37 PM, Ferrous Cranus wrote: > >> >> > > ============================================== > pin = int( htmlpage.encode("hex"), 16 ) % 10000 > ============================================== > > Can you please explain the differences to what you have posted opposed to this perl coding? > > ============================================== > foreach my $ltr(@ltrs){ > $hash = ( $hash + ord($ltr)) %10000; > ============================================== > > I want to understand this and see it implemented in Python. > The perl code will produce the same hash for "abc.html" as for "bca.html" That's probably one reason Leonard didn't try to transliterate the buggy code. In any case, the likelihood of a hash collision for any non-trivial website is substantial. As I said elsewhere, if you hash 100 files you have about a 40% chance of a collision. If you hash 220 files, the likelihood is about 90% -- DaveA From Arah.Leonard at bruker-axs.com Tue Jan 22 15:30:23 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Tue, 22 Jan 2013 20:30:23 +0000 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: <50FEE39E.4060204@davea.name> References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> <50FEE39E.4060204@davea.name> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E075862B8@msnmail2.bruker-axs.com> > The perl code will produce the same hash for "abc.html" as for "bca.html" That's probably one reason Leonard didn't try to transliterate the buggy code. > Actually, to give credit where it's due, it wasn't me. I just modified someone else's interesting solution in this thread and added the silly limit of 10000 to it. > In any case, the likelihood of a hash collision for any non-trivial website is substantial. > Exactly. Four digits is hardly enough range for it to be even remotely safe. And even then range isn't really the issue as technically it just improves your odds. The results of a modulus operator are still non-unique no matter how many digits are there to work with ... within reason. Statistically anyone who buys a ticket could potentially win the lottery no matter how bad the odds are. ;) And now back to the OP, I'm still confused on this four-digit limitation. Why isn't the limitation at least adhering to a bytelength like byte/short/long? Is this database storing a string of characters instead of an actual number? (And if so, then why not just block out 255 characters instead of 4 to store a whole path? Or at the very least treat 4 characters as 4 bytes to greatly increase the numeric range?) From d at davea.name Tue Jan 22 15:43:27 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 15:43:27 -0500 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E075862B8@msnmail2.bruker-axs.com> References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> <50FEE39E.4060204@davea.name> <2ECADBDABCB17E40B66A25D839706F5E075862B8@msnmail2.bruker-axs.com> Message-ID: <50FEF9EF.6060206@davea.name> On 01/22/2013 03:30 PM, Leonard, Arah wrote: >> The perl code will produce the same hash for "abc.html" as for "bca.html" That's probably one reason Leonard didn't try to transliterate the buggy code. >> > > Actually, to give credit where it's due, it wasn't me. I just modified someone else's interesting solution in this thread and added the silly limit of 10000 to it. > That's okay. The OP doesn't seem to know anything about programming, or about information theory, so the fact you gave a single line that actually "works" must be extraordinarily valuable to him. When he was trying to use the md5 module, I gave him the hints about his five programming errors, and was about to expand on it when i noticed his 4 digit limitation. >> In any case, the likelihood of a hash collision for any non-trivial website is substantial. >> > > Exactly. Four digits is hardly enough range for it to be even remotely safe. And even then range isn't really the issue as technically it just improves your odds. > > The results of a modulus operator are still non-unique no matter how many digits are there to work with ... within reason. Statistically anyone who buys a ticket could potentially win the lottery no matter how bad the odds are. ;) > > And now back to the OP, I'm still confused on this four-digit limitation. Why isn't the limitation at least adhering to a bytelength like byte/short/long? Is this database storing a string of characters instead of an actual number? (And if so, then why not just block out 255 characters instead of 4 to store a whole path? Or at the very least treat 4 characters as 4 bytes to greatly increase the numeric range?) > I wish I had done the internet search earlier. This name 'ferrous cranus' is a pseudonym of various trolls, and anybody who'd adopt it isn't worth our time. Thanks to Alan Spence for spotting that. I'll plonk 'ferrous cranus' now. -- DaveA From nikos.gr33k at gmail.com Tue Jan 22 14:28:55 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 11:28:55 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> Message-ID: <97e31693-5928-4e43-bc97-c449118f2de0@googlegroups.com> ?? ?????, 22 ?????????? 2013 9:02:48 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 01/22/2013 11:37 AM, Ferrous Cranus wrote: > > > ============================================== pin = int( > > > htmlpage.encode("hex"), 16 ) % 10000 > > > ============================================== > > > > > > Can you please explain the differences to what you have posted > > > opposed to this perl coding? > > > > > > ============================================== foreach my > > > $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; > > > ============================================== > > > > > > I want to understand this and see it implemented in Python. > > > > It isn't quite the thing. The perl code is merely a checksum of the > > ascii value of the characters in the file name, that is then chopped > > down to a number < 10000. The Python code is taking the ascii value of > > each character in the file name, converting it to a hexadecimal pair of > > digits, stringing them all out into a long string, then converting that > > to a number using the hexadecimal number parser. This results in a > > *very* large number, 8-bits per letter in the original file name, and > > then chops that down to 10000. Technically neither method is a hash and > > neither will generate unique numbers. > > > > Here's the python algorithm used on a short word: > > 'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f) > > => 0x68656c6c6f => 448378203247 > > mod that with 10000 and you get 3247 > > > > If you would simply run the python interpreter and try these things out > > you could see how and why they work or not work. What is stopping you > > from doing this? May i sent you my code by mail so for you see whats wrong and http://superhost.gr produces error?

1. this is not a script that iam being paid for. 2, this is not a class assignemnt I just want to use that method of gettign this to work. From nikos.gr33k at gmail.com Tue Jan 22 14:28:55 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 22 Jan 2013 11:28:55 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> Message-ID: <97e31693-5928-4e43-bc97-c449118f2de0@googlegroups.com> ?? ?????, 22 ?????????? 2013 9:02:48 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 01/22/2013 11:37 AM, Ferrous Cranus wrote: > > > ============================================== pin = int( > > > htmlpage.encode("hex"), 16 ) % 10000 > > > ============================================== > > > > > > Can you please explain the differences to what you have posted > > > opposed to this perl coding? > > > > > > ============================================== foreach my > > > $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; > > > ============================================== > > > > > > I want to understand this and see it implemented in Python. > > > > It isn't quite the thing. The perl code is merely a checksum of the > > ascii value of the characters in the file name, that is then chopped > > down to a number < 10000. The Python code is taking the ascii value of > > each character in the file name, converting it to a hexadecimal pair of > > digits, stringing them all out into a long string, then converting that > > to a number using the hexadecimal number parser. This results in a > > *very* large number, 8-bits per letter in the original file name, and > > then chops that down to 10000. Technically neither method is a hash and > > neither will generate unique numbers. > > > > Here's the python algorithm used on a short word: > > 'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f) > > => 0x68656c6c6f => 448378203247 > > mod that with 10000 and you get 3247 > > > > If you would simply run the python interpreter and try these things out > > you could see how and why they work or not work. What is stopping you > > from doing this? May i sent you my code by mail so for you see whats wrong and http://superhost.gr produces error?

1. this is not a script that iam being paid for. 2, this is not a class assignemnt I just want to use that method of gettign this to work. From alan.spence at ntlworld.com Tue Jan 22 15:00:12 2013 From: alan.spence at ntlworld.com (Alan Spence) Date: Tue, 22 Jan 2013 20:00:12 +0000 Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: <97e31693-5928-4e43-bc97-c449118f2de0@googlegroups.com> References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> <97e31693-5928-4e43-bc97-c449118f2de0@googlegroups.com> Message-ID: On 22 Jan 2013, at 19:28, Ferrous Cranus wrote: > ?? ?????, 22 ?????????? 2013 9:02:48 ?.?. UTC+2, ? ??????? Michael Torrie ??????: >> On 01/22/2013 11:37 AM, Ferrous Cranus wrote: >> >>> ============================================== pin = int( >> >>> htmlpage.encode("hex"), 16 ) % 10000 >> >>> ============================================== >> >>> >> >>> Can you please explain the differences to what you have posted >> >>> opposed to this perl coding? >> >>> >> >>> ============================================== foreach my >> >>> $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; >> >>> ============================================== >> >>> >> >>> I want to understand this and see it implemented in Python. >> >> >> >> It isn't quite the thing. The perl code is merely a checksum of the >> >> ascii value of the characters in the file name, that is then chopped >> >> down to a number < 10000. The Python code is taking the ascii value of >> >> each character in the file name, converting it to a hexadecimal pair of >> >> digits, stringing them all out into a long string, then converting that >> >> to a number using the hexadecimal number parser. This results in a >> >> *very* large number, 8-bits per letter in the original file name, and >> >> then chops that down to 10000. Technically neither method is a hash and >> >> neither will generate unique numbers. >> >> >> >> Here's the python algorithm used on a short word: >> >> 'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f) >> >> => 0x68656c6c6f => 448378203247 >> >> mod that with 10000 and you get 3247 >> >> >> >> If you would simply run the python interpreter and try these things out >> >> you could see how and why they work or not work. What is stopping you >> >> from doing this? > > > May i sent you my code by mail so for you see whats wrong and http://superhost.gr produces error?

> > 1. this is not a script that iam being paid for. > 2, this is not a class assignemnt > > I just want to use that method of gettign this to work. > -- > http://mail.python.org/mailman/listinfo/python-list All pages, strings and objects map to: http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm Alan From gordon at panix.com Tue Jan 22 15:40:39 2013 From: gordon at panix.com (John Gordon) Date: Tue, 22 Jan 2013 20:40:39 +0000 (UTC) Subject: Converting a string to a number by using INT (no hash method) References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> Message-ID: In Ferrous Cranus writes: > May i sent you my code by mail so for you see whats wrong and > http://superhost.gr produces error? I tried going to that address and got some error output. I noticed this in the error dump: 186 if cursor.rowcount == 0: 187 cursor.execute( '''INSERT INTO visitors(pin, host , hits, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (pin, hos t, 1, useros, browser, date) ) The INSERT statement gives six column names but only five placeholders (%s) in the VALUES clause. Perhaps that's the problem? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From nikos.gr33k at gmail.com Wed Jan 23 03:44:47 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 00:44:47 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) In-Reply-To: References: <4339f8d7-2d78-450f-ad0e-91da35615e6d@googlegroups.com> <2de57cf7-4a8f-4304-91cf-0024963315d7@googlegroups.com> Message-ID: <1ffaadd0-f700-4172-84a4-7c1d73745f83@googlegroups.com> ?? ?????, 22 ?????????? 2013 10:40:39 ?.?. UTC+2, ? ??????? John Gordon ??????: > In Ferrous Cranus writes: > > > > > May i sent you my code by mail so for you see whats wrong and > > > http://superhost.gr produces error? > > > > I tried going to that address and got some error output. I noticed this > > in the error dump: > > > > 186 if cursor.rowcount == 0: > > 187 cursor.execute( '''INSERT INTO visitors(pin, host > > , hits, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (pin, hos > > t, 1, useros, browser, date) ) > > > > The INSERT statement gives six column names but only five placeholders (%s) > > in the VALUES clause. > > > > Perhaps that's the problem? Excatly Gordon, i missed the extra placeholder(%s) when i was adding a new useros column. I also used a 5-digit number. Now my website finally works as intended. Just visit the following links plz. ------------------------------------------------------------------------------ 1. http://superhost.gr 2. http://superhost.gr/?show=log 3. http://i.imgur.com/3Hcz1uP.png (this displays the database's column 'pin', a 5-digit number acting as a filepath indicator. I guess i won't be needing column 'page' anymore) 4. http://i.imgur.com/kRwzLp3.png (this is the detailed page information associated to 'pin' column indicator instead of something like '/home/nikos/public_html/index.html' Isn't it a nice solution? From wuwei23 at gmail.com Tue Jan 22 20:32:58 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 22 Jan 2013 17:32:58 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) References: Message-ID: On Jan 23, 2:40?am, Dave Angel wrote: > Unless you constrain your users to very restrictive filenames, what you > ask here simply cannot be done. He's also INSISTED in other threads that these files should be moveable at will by other users and still be recognisable as the same file. So yes: troll or willful ignorance seems to be what we're seeing here. From steve+comp.lang.python at pearwood.info Tue Jan 22 22:02:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2013 03:02:07 GMT Subject: Converting a string to a number by using INT (no hash method) References: Message-ID: <50ff52af$0$29877$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Jan 2013 17:32:58 -0800, alex23 wrote: > On Jan 23, 2:40?am, Dave Angel wrote: >> Unless you constrain your users to very restrictive filenames, what you >> ask here simply cannot be done. > > He's also INSISTED in other threads that these files should be moveable > at will by other users and still be recognisable as the same file. So > yes: troll or willful ignorance seems to be what we're seeing here. Definitely troll, and we got well and truly had. Shame on us -- he practically *screamed* "I am a troll" in his user-name. "Ferrous Cranus" ("Iron Skull") is the name of a particular subspecies of troll in Mike Reed's well known compendium: http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm How many days was he posting here, pretending to be dumber than a box of hammers? How many hours have we collectively wasted, reading and replying to his posts? I wouldn't even trust that he is Greek. Quite likely he uses a non- English attribution line to hint that English is not his first language, so his victims will think that there is a language barrier. "Maybe he doesn't understand me. If I answer again, in a slightly different way, perhaps it will be more clear." -- Steven From wuwei23 at gmail.com Tue Jan 22 22:59:11 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 22 Jan 2013 19:59:11 -0800 (PST) Subject: Converting a string to a number by using INT (no hash method) References: <50ff52af$0$29877$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jan 23, 1:02?pm, Steven D'Aprano wrote: > How many days was he posting here, pretending to be dumber than a box of > hammers? How many hours have we collectively wasted, reading and replying > to his posts? Trying to find some positive in this: the people sincerely responding at least stretched themselves to try and find solutions or better ways of communicating. The troll just learned how to be a better troll. We still win. From rahulgarg44 at gmail.com Tue Jan 22 12:20:39 2013 From: rahulgarg44 at gmail.com (rahulgarg44 at gmail.com) Date: Tue, 22 Jan 2013 09:20:39 -0800 (PST) Subject: Is PyArg_ParseTuple necessary to parse arguments? Message-ID: Or can I just loop through the argument tuple manually by using something like PyTuple_GET_ITEM(args,i), then putting manual code to convert the objects to appropriate C type? The use case is that I am interfacing Python with another interpreter and do not know the type and number of arguments till runtime :) rahul From dieter at handshake.de Wed Jan 23 02:00:23 2013 From: dieter at handshake.de (dieter) Date: Wed, 23 Jan 2013 08:00:23 +0100 Subject: Is PyArg_ParseTuple necessary to parse arguments? References: Message-ID: <87bocg8jug.fsf@handshake.de> rahulgarg44 at gmail.com writes: > Or can I just loop through the argument tuple manually by using something like PyTuple_GET_ITEM(args,i), then putting manual code to convert the objects to appropriate C type? If you like you can do the "parsing" yourself. From stefan_ml at behnel.de Wed Jan 23 02:50:23 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 23 Jan 2013 08:50:23 +0100 Subject: Is PyArg_ParseTuple necessary to parse arguments? In-Reply-To: References: Message-ID: rahulgarg44 at gmail.com, 22.01.2013 18:20: > Or can I just loop through the argument tuple manually by using something like PyTuple_GET_ITEM(args,i), then putting manual code to convert the objects to appropriate C type? > The use case is that I am interfacing Python with another interpreter and do not know the type and number of arguments till runtime :) Just in case you're not aware of it, C extensions are quite commonly written in Cython instead of C these days. I've used it for Lupa, for example, which embeds the Lua(JIT) runtime in CPython. That should be quite similar to what you're after. It certainly makes things a lot easier to write cdef class Wrapper: "Wraps an external object for usage in Python." cdef mylib.sometype* _wrapped_object # pointer to external 'thing' def __call__(self, *args): mapped_args = malloc(len(args)*...) # ... for i, arg in enumerate(args): map_value_to_external(arg, mapped_args[i]) # ... result = call_external(self._wrapped_object, mapped_args) return map_value_from_external(result) than to do these things in plain C. If nothing else, it saves you from having to put thoughts into reference counting and other common CPython C-API pitfalls. Stefan From tjreedy at udel.edu Tue Jan 22 12:44:05 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Jan 2013 12:44:05 -0500 Subject: Understanding while...else... Message-ID: Several people have trouble understanding Python's while-else and for-else constructs. It is actually quite simple if one starts with if-else, which few have any trouble with. Start with, for example if n > 0: n -= 1 else: n = None The else clause is executed if and when the condition is false. (That the code is useless is not the point here.) Now use pseudo-Python label and goto statements to repeatedly decrement n label: check if n > 0: n -= 1 goto: check else: n = None The else clause is executed if and when the condition is false. (I am aware that the above will always set n to None if it terminates normally and that something more is needed to do anything useful, but this is not the point here.) Now use a real Python while statement to do the *same thing*. while n > 0: n -= 1 else: n = None The else clause is executed if and when the condition is false. This is the same as with the non-problematical if statement! To see that the pseudo-Python is the 'correct' expansion, we can look at the disassembled CPython byte code. from dis import dis dis('if n > 0: n -= 1\nelse: n = None') dis('while n > 0: n -= 1\nelse: n = None') produces 1 0 LOAD_NAME 0 (n) 3 LOAD_CONST 0 (0) 6 COMPARE_OP 4 (>) 9 POP_JUMP_IF_FALSE 25 12 LOAD_NAME 0 (n) 15 LOAD_CONST 1 (1) 18 INPLACE_SUBTRACT 19 STORE_NAME 0 (n) 22 JUMP_FORWARD 6 (to 31) 2 >> 25 LOAD_CONST 2 (None) 28 STORE_NAME 0 (n) >> 31 LOAD_CONST 2 (None) 34 RETURN_VALUE 1 0 SETUP_LOOP 32 (to 35) >> 3 LOAD_NAME 0 (n) 6 LOAD_CONST 0 (0) 9 COMPARE_OP 4 (>) 12 POP_JUMP_IF_FALSE 28 15 LOAD_NAME 0 (n) 18 LOAD_CONST 1 (1) 21 INPLACE_SUBTRACT 22 STORE_NAME 0 (n) 25 JUMP_ABSOLUTE 3 >> 28 POP_BLOCK 2 29 LOAD_CONST 2 (None) 32 STORE_NAME 0 (n) >> 35 LOAD_CONST 2 (None) 38 RETURN_VALUE The while loop code adds SETUP_LOOP to set up the context to handle continue and break statements. It also add POP_BLOCK after the while block. I presume this disables the loop context. Most importantly for this discussion, JUMP_FORWARD (past the else block), which is implicit in if-else statements, changes to JUMP_ABSOLUTE (to the condition test), which is implicit in while statements and explicit in the pseudo-Python expansion. Everything else is the same -- in particular the POP_JUMP_IF_FALSE, after the condition test, which in both cases jumps to the else block. So in both statements, the else block is executed if and when the condition is false. As for for-else statements, a for loop is basically a specialized while loop plus assignment. The implicit while condition is that the iterable has another item to process. So the else clause executes if and when that condition is false, when iter(iterable) is exhausted. -- Terry Jan Reedy From jeanmichel at sequans.com Tue Jan 22 13:15:58 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 22 Jan 2013 19:15:58 +0100 (CET) Subject: Understanding while...else... In-Reply-To: Message-ID: <1860347092.8310858.1358878558150.JavaMail.root@sequans.com> ----- Original Message ----- > Several people have trouble understanding Python's while-else and > for-else constructs. It is actually quite simple agreed on the last part. [snip long story] Did you just try to make it simple by showing the compiled code ? I'm quite not sure about that... JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From tjreedy at udel.edu Wed Jan 23 17:47:51 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 23 Jan 2013 17:47:51 -0500 Subject: Understanding while...else... In-Reply-To: <1860347092.8310858.1358878558150.JavaMail.root@sequans.com> References: <1860347092.8310858.1358878558150.JavaMail.root@sequans.com> Message-ID: On 1/22/2013 1:15 PM, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> Several people have trouble understanding Python's while-else and >> for-else constructs. It is actually quite simple > > agreed on the last part. > > [snip long story] > > Did you just try to make it simple by showing the compiled code ? I'm > quite not sure about that... The dis output was an optional appendix for anyone who doubted the correctly of my claimed python-level equivalence ;-). -- Terry Jan Reedy From ethan at stoneleaf.us Tue Jan 22 15:09:25 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 22 Jan 2013 12:09:25 -0800 Subject: Understanding while...else... In-Reply-To: References: Message-ID: <50FEF1F5.9050501@stoneleaf.us> On 01/22/2013 09:44 AM, Terry Reedy wrote: > Several people have trouble understanding Python's while-else and > for-else constructs. It is actually quite simple if one starts with > if-else, which few have any trouble with. > > Start with, for example > > if n > 0: > n -= 1 > else: > n = None > > The else clause is executed if and when the condition is false. (That > the code is useless is not the point here.) Now use pseudo-Python label > and goto statements to repeatedly decrement n > > label: check > if n > 0: > n -= 1 > goto: check > else: > n = None > > The else clause is executed if and when the condition is false. > Now use a real Python while statement to do the *same > thing*. > > while n > 0: > n -= 1 > else: > n = None I understand how it works (although it did take a while for it to sink in); my gripe, and probably why it is misunderstood so often, is that nine times out of ten when I /want/ to use a while-else or for-else I only want the true/false check /once/, at the beginning of the loop. /Occasionally/ I'll actually have use for the search pattern, and then I can use the while- or for-else construct, but that's pretty rare for me. ~Ethan~ From tjreedy at udel.edu Tue Jan 22 18:41:56 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Jan 2013 18:41:56 -0500 Subject: Understanding while...else... In-Reply-To: <50FEF1F5.9050501@stoneleaf.us> References: <50FEF1F5.9050501@stoneleaf.us> Message-ID: On 1/22/2013 3:09 PM, Ethan Furman wrote: > On 01/22/2013 09:44 AM, Terry Reedy wrote: >> Several people have trouble understanding Python's while-else and >> for-else constructs. It is actually quite simple if one starts with >> if-else, which few have any trouble with. >> >> Start with, for example >> >> if n > 0: >> n -= 1 >> else: >> n = None >> >> The else clause is executed if and when the condition is false. (That >> the code is useless is not the point here.) Now use pseudo-Python label >> and goto statements to repeatedly decrement n >> >> label: check >> if n > 0: >> n -= 1 >> goto: check >> else: >> n = None >> >> The else clause is executed if and when the condition is false. >> Now use a real Python while statement to do the *same >> thing*. >> >> while n > 0: >> n -= 1 >> else: >> n = None > > I understand how it works (although it did take a while for it to sink > in); my gripe, and probably why it is misunderstood so often, is that > nine times out of ten when I /want/ to use a while-else or for-else I > only want the true/false check /once/, at the beginning of the loop. I do not understand what you are saying. There already is only one true/false check, at the beginning of the loop. If you only want the check *performed* once, you would use if-else. But I presume you know this. -- Terry Jan Reedy From oscar.j.benjamin at gmail.com Tue Jan 22 19:39:39 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 00:39:39 +0000 Subject: Understanding while...else... In-Reply-To: References: <50FEF1F5.9050501@stoneleaf.us> Message-ID: On 22 January 2013 23:41, Terry Reedy wrote: > On 1/22/2013 3:09 PM, Ethan Furman wrote: >> >> On 01/22/2013 09:44 AM, Terry Reedy wrote: >>> [SNIP] >>> The else clause is executed if and when the condition is false. >>> Now use a real Python while statement to do the *same >>> thing*. >>> >>> while n > 0: >>> n -= 1 >>> else: >>> n = None >> >> >> I understand how it works (although it did take a while for it to sink >> in); my gripe, and probably why it is misunderstood so often, is that >> nine times out of ten when I /want/ to use a while-else or for-else I >> only want the true/false check /once/, at the beginning of the loop. > > > I do not understand what you are saying. There already is only one > true/false check, at the beginning of the loop. If you only want the check > *performed* once, you would use if-else. But I presume you know this. I think he meant that he would use the else clause more often if it had the semantics so that the two blocks below were equivalent: # Version 1 while condition: # stuff else: # other stuff # Version 2 if condition: while condition: # stuff else: # other stuff So he wants a convenient way to execute code only if the loop performed zero iterations. I think that often when people are confused about the else clause on while loops it is because they expect this behaviour (which would also be useful). The same confusion arises with for loops where people expect the else clause to execute if the iterable was empty so that these would be equivalent: # Version 1 for x in iterable: # stuff else: # other stuff # Version 2 iterated = False for x in iterable: iterated = True # stuff if not iterated: # other stuff Oscar From rene.klacan at gmail.com Wed Jan 23 06:03:09 2013 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Wed, 23 Jan 2013 12:03:09 +0100 Subject: Understanding while...else... In-Reply-To: References: <50FEF1F5.9050501@stoneleaf.us> Message-ID: they wouldnt be equivalent if #staff in version 1 did not cointain "break" statement and this is common mistake On Wed, Jan 23, 2013 at 1:39 AM, Oscar Benjamin wrote: > On 22 January 2013 23:41, Terry Reedy wrote: > > On 1/22/2013 3:09 PM, Ethan Furman wrote: > >> > >> On 01/22/2013 09:44 AM, Terry Reedy wrote: > >>> > [SNIP] > >>> The else clause is executed if and when the condition is false. > >>> Now use a real Python while statement to do the *same > >>> thing*. > >>> > >>> while n > 0: > >>> n -= 1 > >>> else: > >>> n = None > >> > >> > >> I understand how it works (although it did take a while for it to sink > >> in); my gripe, and probably why it is misunderstood so often, is that > >> nine times out of ten when I /want/ to use a while-else or for-else I > >> only want the true/false check /once/, at the beginning of the loop. > > > > > > I do not understand what you are saying. There already is only one > > true/false check, at the beginning of the loop. If you only want the > check > > *performed* once, you would use if-else. But I presume you know this. > > I think he meant that he would use the else clause more often if it > had the semantics so that the two blocks below were equivalent: > > # Version 1 > while condition: > # stuff > else: > # other stuff > > # Version 2 > if condition: > while condition: > # stuff > else: > # other stuff > > So he wants a convenient way to execute code only if the loop > performed zero iterations. I think that often when people are confused > about the else clause on while loops it is because they expect this > behaviour (which would also be useful). The same confusion arises with > for loops where people expect the else clause to execute if the > iterable was empty so that these would be equivalent: > > # Version 1 > for x in iterable: > # stuff > else: > # other stuff > > # Version 2 > iterated = False > for x in iterable: > iterated = True > # stuff > if not iterated: > # other stuff > > > Oscar > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rene.klacan at gmail.com Wed Jan 23 06:03:32 2013 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Wed, 23 Jan 2013 12:03:32 +0100 Subject: Understanding while...else... In-Reply-To: References: <50FEF1F5.9050501@stoneleaf.us> Message-ID: > > # Version 1 > while condition: > # stuff > else: > # other stuff > > # Version 2 > if condition: > while condition: > # stuff > else: > # other stuff > they wouldnt be equivalent if #staff in version did not cointain "break" statement and this is common mistake On Wed, Jan 23, 2013 at 12:03 PM, Ren? Kla?an wrote: > they wouldnt be equivalent if #staff in version 1 did not cointain "break" > statement and this is common mistake > > > On Wed, Jan 23, 2013 at 1:39 AM, Oscar Benjamin < > oscar.j.benjamin at gmail.com> wrote: > >> On 22 January 2013 23:41, Terry Reedy wrote: >> > On 1/22/2013 3:09 PM, Ethan Furman wrote: >> >> >> >> On 01/22/2013 09:44 AM, Terry Reedy wrote: >> >>> >> [SNIP] >> >>> The else clause is executed if and when the condition is false. >> >>> Now use a real Python while statement to do the *same >> >>> thing*. >> >>> >> >>> while n > 0: >> >>> n -= 1 >> >>> else: >> >>> n = None >> >> >> >> >> >> I understand how it works (although it did take a while for it to sink >> >> in); my gripe, and probably why it is misunderstood so often, is that >> >> nine times out of ten when I /want/ to use a while-else or for-else I >> >> only want the true/false check /once/, at the beginning of the loop. >> > >> > >> > I do not understand what you are saying. There already is only one >> > true/false check, at the beginning of the loop. If you only want the >> check >> > *performed* once, you would use if-else. But I presume you know this. >> >> I think he meant that he would use the else clause more often if it >> had the semantics so that the two blocks below were equivalent: >> >> # Version 1 >> while condition: >> # stuff >> else: >> # other stuff >> >> # Version 2 >> if condition: >> while condition: >> # stuff >> else: >> # other stuff >> >> So he wants a convenient way to execute code only if the loop >> performed zero iterations. I think that often when people are confused >> about the else clause on while loops it is because they expect this >> behaviour (which would also be useful). The same confusion arises with >> for loops where people expect the else clause to execute if the >> iterable was empty so that these would be equivalent: >> >> # Version 1 >> for x in iterable: >> # stuff >> else: >> # other stuff >> >> # Version 2 >> iterated = False >> for x in iterable: >> iterated = True >> # stuff >> if not iterated: >> # other stuff >> >> >> Oscar >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Wed Jan 23 06:18:31 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 11:18:31 +0000 Subject: Understanding while...else... In-Reply-To: References: <50FEF1F5.9050501@stoneleaf.us> Message-ID: On 23 January 2013 11:03, Ren? Kla?an wrote: > On Wed, Jan 23, 2013 at 1:39 AM, Oscar Benjamin wrote: You missed off an important piece of context in your post: >> I think he meant that he would use the else clause more often if it >> had the semantics so that the two blocks below were equivalent: The key word in that sentence is "if". >> # Version 1 >> while condition: >> # stuff >> else: >> # other stuff >> >> # Version 2 >> if condition: >> while condition: >> # stuff >> else: >> # other stuff > > they wouldnt be equivalent if #staff in version did not cointain "break" > statement and this is common mistake I realise that they are not equivalent. My point was that some people expect, or would prefer, different behaviour so that those two *would* be equivalent (assuming that evaluating "condition" doesn't have side effects). Oscar From tjreedy at udel.edu Wed Jan 23 18:05:39 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 23 Jan 2013 18:05:39 -0500 Subject: Understanding while...else... In-Reply-To: References: <50FEF1F5.9050501@stoneleaf.us> Message-ID: On 1/22/2013 7:39 PM, Oscar Benjamin wrote: > On 22 January 2013 23:41, Terry Reedy wrote: >> On 1/22/2013 3:09 PM, Ethan Furman wrote: >>> >>> On 01/22/2013 09:44 AM, Terry Reedy wrote: >>>> > [SNIP] >>>> The else clause is executed if and when the condition is false. >>>> Now use a real Python while statement to do the *same >>>> thing*. >>>> >>>> while n > 0: >>>> n -= 1 >>>> else: >>>> n = None >>> >>> >>> I understand how it works (although it did take a while for it to sink >>> in); my gripe, and probably why it is misunderstood so often, is that >>> nine times out of ten when I /want/ to use a while-else or for-else I >>> only want the true/false check /once/, at the beginning of the loop. >> >> >> I do not understand what you are saying. There already is only one >> true/false check, at the beginning of the loop. If you only want the check >> *performed* once, you would use if-else. But I presume you know this. > > I think he meant that he would use the else clause more often if it > had the semantics so that the two blocks below were equivalent: > > # Version 1 > while condition: > # stuff > else: > # other stuff > > # Version 2 > if condition: > while condition: > # stuff > else: > # other stuff > > So he wants a convenient way to execute code only if the loop > performed zero iterations. I think that often when people are confused > about the else clause on while loops it is because they expect this > behaviour (which would also be useful). Thank you for the clarification. If 'condition' has side effects, or if one is really bothered by computing it twice, Version 2 could be re-written as if condition: while True: stuff() if not condition: break else: other_stuff() > The same confusion arises with > for loops where people expect the else clause to execute if the > iterable was empty so that these would be equivalent: > > # Version 1 > for x in iterable: > # stuff > else: > # other stuff > > # Version 2 > iterated = False > for x in iterable: > iterated = True > # stuff > if not iterated: > # other stuff I see. I guess people who want version 2 will have to write it explicitly. -- Terry Jan Reedy From kdawg44 at gmail.com Tue Jan 22 14:33:45 2013 From: kdawg44 at gmail.com (Kevin Holleran) Date: Tue, 22 Jan 2013 14:33:45 -0500 Subject: Importing class from another file Message-ID: Hello, I have a class called My_Class in a subdir called Sub_Dir. in My_Class.py is the following class My_Class_Connector: def __init__(self,un,pw,qs_srv="domain.com"): self.username = un self.password = pw ... Then I am trying to call from a script in the parent dir like this: from Sub_Dir.My_Class import * q_api = My_Class.My_Class_Connector(string1,string2) I have not worked much with Python classes so I am not sure what I am doing wrong. When running this from my script, I get the following error: Traceback (most recent call last): File "testing.py", line 1, in from Sub_Dir.My_Class import * ImportError: No module named Sub_Dir.My_Class I have played around a bit with the calls (removing the My_Class in the q_api assignment to instantiate the object, etc). Thanks for any help. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Tue Jan 22 14:47:34 2013 From: gordon at panix.com (John Gordon) Date: Tue, 22 Jan 2013 19:47:34 +0000 (UTC) Subject: Importing class from another file References: Message-ID: In Kevin Holleran writes: > I have a class called My_Class in a subdir called Sub_Dir. > in My_Class.py is the following > class My_Class_Connector: > def __init__(self,un,pw,qs_srv="domain.com"): > self.username = un > self.password = pw > Then I am trying to call from a script in the parent dir like this: > from Sub_Dir.My_Class import * > q_api = My_Class.My_Class_Connector(string1,string2) Even if your import had worked, this would be wrong. You're importing everything from Sub_Dir.My_Class, so My_Class_Connector is in the current namespace. You don't need to add "My_Class." on the front (and in fact it's an error to do so.) > Traceback (most recent call last): > File "testing.py", line 1, in > from Sub_Dir.My_Class import * > ImportError: No module named Sub_Dir.My_Class Is there a file named __init__.py in Sub_Dir? A directory must contain that file in order to be considered a "module". (If you don't know what to put in the file, just leave it empty.) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From kdawg44 at gmail.com Tue Jan 22 15:44:44 2013 From: kdawg44 at gmail.com (Kevin Holleran) Date: Tue, 22 Jan 2013 15:44:44 -0500 Subject: Importing class from another file In-Reply-To: References: Message-ID: Thanks, you got me straightened out. -- Kevin Holleran Master of Science, Computer Information Systems Grand Valley State University Master of Business Administration Western Michigan University SANS GCFA, SANS GCFE, CCNA, ISA, MCSA, MCDST, MCP "Do today what others won't, do tomorrow what others can't" - SEALFit "We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle On Tue, Jan 22, 2013 at 2:47 PM, John Gordon wrote: > In Kevin Holleran < > kdawg44 at gmail.com> writes: > > > I have a class called My_Class in a subdir called Sub_Dir. > > > in My_Class.py is the following > > > class My_Class_Connector: > > def __init__(self,un,pw,qs_srv="domain.com"): > > self.username = un > > self.password = pw > > > Then I am trying to call from a script in the parent dir like this: > > > from Sub_Dir.My_Class import * > > > q_api = My_Class.My_Class_Connector(string1,string2) > > Even if your import had worked, this would be wrong. You're importing > everything from Sub_Dir.My_Class, so My_Class_Connector is in the current > namespace. You don't need to add "My_Class." on the front (and in fact > it's an error to do so.) > > > Traceback (most recent call last): > > File "testing.py", line 1, in > > from Sub_Dir.My_Class import * > > ImportError: No module named Sub_Dir.My_Class > > Is there a file named __init__.py in Sub_Dir? A directory must contain > that file in order to be considered a "module". (If you don't know what > to put in the file, just leave it empty.) > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tm at tobix.eu Wed Jan 23 04:53:21 2013 From: tm at tobix.eu (Tobias M.) Date: Wed, 23 Jan 2013 10:53:21 +0100 Subject: Importing class from another file In-Reply-To: References: Message-ID: <50FFB311.7090301@tobix.eu> Hi, Kevin Holleran wrote: > > Traceback (most recent call last): > > File "testing.py", line 1, in > > from Sub_Dir.My_Class import * > > ImportError: No module named Sub_Dir.My_Class > > Make sure, the script you execute by passing it to the python interpreter is in the parent directory of Sub_Dir. Additionaly put an empty file called __init__.py (double underscores!) in Sub_Dir if you don't already have. This is necessary to use Sub_Dir as a package and import modules from it. For more details see: http://docs.python.org/3.3/tutorial/modules.html#packages > I have played around a bit with the calls (removing the My_Class in > the q_api assignment to instantiate the object, etc). > When using "from...import" on the module that contains the class, you can use the class without the package identifier: q_api = My_Class_Connector(string1,string2) For your information: I think beginner questions like this one should be asked on the tutor list: http://mail.python.org/mailman/listinfo/tutor From zughumancapital at yahoo.com.br Tue Jan 22 14:43:00 2013 From: zughumancapital at yahoo.com.br (zughumancapital) Date: Tue, 22 Jan 2013 19:43:00 -0000 Subject: =?iso-8859-1?q?Oportunidade:_Desenvolvedor_Python/Django_S=EAnior_-_RJ?= Message-ID: Arpex Capital Seleciona: Desenvolvedor Python/Django S?nior Estamos em busca daqueles(as) que: acham que meritocracia ? indispens?vel, programam desde a inf?ncia, possuem sede por aprender e programar e querem trabalhar muito para fazer algo especial! O desenvolvedor estar? envolvido em um projeto Python/Django para uma das startups da ArpexCapital (fundo de investimentos americano com foco no mercado brasileiro). Skills necess?rios: Python, HTML, MySQL Skills desej?veis (b?nus): Framework Django, Javascript, Linux, Scrum ou XP Local de Trabalho: Centro/RJ Os interessados dever?o enviar o CV com pretens?o salarial para kgarcia at arpexcapital.com.br, mencionando no assunto Desenvolvedor Python/Django S?nior. From zughumancapital at yahoo.com.br Tue Jan 22 14:43:30 2013 From: zughumancapital at yahoo.com.br (zughumancapital) Date: Tue, 22 Jan 2013 19:43:30 -0000 Subject: Oportunidade: Programador Python Pleno / RJ Message-ID: Arpex Capital seleciona para uma de suas startups: Programador Python Pleno Descri??o: Programador para Web Crawler Python - Experi?ncia m?nima de 1 ano em python - Conhecimento de padr?es de projeto - S?lido conhecimento OO - Ser auto-gerenci?vel - Conhecimento de SQL Desej?vel: - Ter github - Ter interesse por NPL ? J? ter feito um scraper/crawler/parser - Saber qualquer NoSQL Local de Trabalho: Botafogo/RJ Gradua??o Completa em Ci?ncia da Computa??o e/ou afins; Os interessados dever?o enviar CV com PRENTENS?O SALARIAL para kgarcia at arpexcapital.com.br , mencionando no assunto Programador Python/Botafogo. From kdawg44 at gmail.com Tue Jan 22 20:32:00 2013 From: kdawg44 at gmail.com (Kevin Holleran) Date: Tue, 22 Jan 2013 20:32:00 -0500 Subject: Parse a Wireshark pcap file Message-ID: Is there a way to parse out a wireshark pcap file and extract key value pairs from the data? I am illustrated a sniff of some traffic and why it needs utilize HTTPS instead of HTTP but I was hoping to run the pcap through a python script and just output some interesting key value pairs.... Thanks for your help. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Tue Jan 22 22:03:46 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 22:03:46 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: References: Message-ID: <50FF5312.50309@davea.name> On 01/22/2013 08:32 PM, Kevin Holleran wrote: > Is there a way to parse out a wireshark pcap file and extract key value > pairs from the data? I am illustrated a sniff of some traffic and why it > needs utilize HTTPS instead of HTTP but I was hoping to run the pcap > through a python script and just output some interesting key value > pairs.... > Sure. scapy can create and/or parse pcap files. http://pypi.python.org/pypi/Scapy -- DaveA From kdawg44 at gmail.com Tue Jan 22 22:15:29 2013 From: kdawg44 at gmail.com (Kevin Holleran) Date: Tue, 22 Jan 2013 22:15:29 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: <50FF5312.50309@davea.name> References: <50FF5312.50309@davea.name> Message-ID: Thanks, I have been trying to get it to work but I am on Mac OS 10.8.2. I tried to get it from Macports and download/install it myself. Both seem to get me to here: ImportError: No module named dnet I tried to download libdnet but no matter what I do this is what I get. Granted I am doing; from scapy.all import * But I have no idea what I need. I am not trying to craft packets but filter packets based on tcp.dstport 80 & frame matches signin.aspx. Then my goal is to parse the data looking for post vars txtUserId & txtPwd and extract them, dumping them to the screen as userid_value => password. Thanks for your help. -- Kevin Holleran Master of Science, Computer Information Systems Grand Valley State University Master of Business Administration Western Michigan University SANS GCFA, SANS GCFE, CCNA, ISA, MCSA, MCDST, MCP "Do today what others won't, do tomorrow what others can't" - SEALFit "We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle On Tue, Jan 22, 2013 at 10:03 PM, Dave Angel wrote: > On 01/22/2013 08:32 PM, Kevin Holleran wrote: > >> Is there a way to parse out a wireshark pcap file and extract key value >> pairs from the data? I am illustrated a sniff of some traffic and why it >> needs utilize HTTPS instead of HTTP but I was hoping to run the pcap >> through a python script and just output some interesting key value >> pairs.... >> >> > Sure. scapy can create and/or parse pcap files. > > http://pypi.python.org/pypi/**Scapy > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kdawg44 at gmail.com Tue Jan 22 22:26:00 2013 From: kdawg44 at gmail.com (Kevin Holleran) Date: Tue, 22 Jan 2013 22:26:00 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: References: <50FF5312.50309@davea.name> Message-ID: I also found this: http://code.google.com/p/py-greppcap/ Which I can leverage to do what I want but I also get that dnet error! -- Kevin Holleran Master of Science, Computer Information Systems Grand Valley State University Master of Business Administration Western Michigan University SANS GCFA, SANS GCFE, CCNA, ISA, MCSA, MCDST, MCP "Do today what others won't, do tomorrow what others can't" - SEALFit "We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle On Tue, Jan 22, 2013 at 10:15 PM, Kevin Holleran wrote: > Thanks, I have been trying to get it to work but I am on Mac OS 10.8.2. I > tried to get it from Macports and download/install it myself. Both seem to > get me to here: > > ImportError: No module named dnet > > I tried to download libdnet but no matter what I do this is what I get. > Granted I am doing; > > from scapy.all import * > > > But I have no idea what I need. I am not trying to craft packets but > filter packets based on tcp.dstport 80 & frame matches signin.aspx. Then > my goal is to parse the data looking for post vars txtUserId & txtPwd and > extract them, dumping them to the screen as userid_value => password. > > > Thanks for your help. > > -- > Kevin Holleran > Master of Science, Computer Information Systems > Grand Valley State University > Master of Business Administration > Western Michigan University > SANS GCFA, SANS GCFE, CCNA, ISA, MCSA, MCDST, MCP > > "Do today what others won't, do tomorrow what others can't" - SEALFit > > "We are what we repeatedly do. Excellence, then, is not an act, but a > habit." - Aristotle > > > On Tue, Jan 22, 2013 at 10:03 PM, Dave Angel wrote: > >> On 01/22/2013 08:32 PM, Kevin Holleran wrote: >> >>> Is there a way to parse out a wireshark pcap file and extract key value >>> pairs from the data? I am illustrated a sniff of some traffic and why it >>> needs utilize HTTPS instead of HTTP but I was hoping to run the pcap >>> through a python script and just output some interesting key value >>> pairs.... >>> >>> >> Sure. scapy can create and/or parse pcap files. >> >> http://pypi.python.org/pypi/**Scapy >> >> >> -- >> DaveA >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Tue Jan 22 22:29:20 2013 From: d at davea.name (Dave Angel) Date: Tue, 22 Jan 2013 22:29:20 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: References: <50FF5312.50309@davea.name> Message-ID: <50FF5910.7060309@davea.name> On 01/22/2013 10:15 PM, Kevin Holleran wrote: > Thanks, I have been trying to get it to work but I am on Mac OS 10.8.2. I > tried to get it from Macports and download/install it myself. Both seem to > get me to here: > > ImportError: No module named dnet > > I tried to download libdnet but no matter what I do this is what I get. > Granted I am doing; > > from scapy.all import * > > > But I have no idea what I need. I am not trying to craft packets but > filter packets based on tcp.dstport 80 & frame matches signin.aspx. Then > my goal is to parse the data looking for post vars txtUserId & txtPwd and > extract them, dumping them to the screen as userid_value => password. > I've never worked on Mac OSx And the only times I had and used scapy were on a work machine that's long gone. I still run Linux, but versions of everything have changed since then. I don't know if there's anyone here that's more current with scapy and/or with Mac, but in case there is, you could be lots clearer about what you're doing and how it fails. Version of OS. You said that well. Version of Python,. Exact location you got scapy from, what version it was How you installed it (I don't know Macports, clearly) What the full traceback was when it died. -- DaveA From kdawg44 at gmail.com Tue Jan 22 22:43:24 2013 From: kdawg44 at gmail.com (Kevin Holleran) Date: Tue, 22 Jan 2013 22:43:24 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: <50FF5910.7060309@davea.name> References: <50FF5312.50309@davea.name> <50FF5910.7060309@davea.name> Message-ID: On Tue, Jan 22, 2013 at 10:29 PM, Dave Angel wrote: > On 01/22/2013 10:15 PM, Kevin Holleran wrote: > >> Thanks, I have been trying to get it to work but I am on Mac OS 10.8.2. I >> tried to get it from Macports and download/install it myself. Both seem >> to >> get me to here: >> >> ImportError: No module named dnet >> >> I tried to download libdnet but no matter what I do this is what I get. >> Granted I am doing; >> >> from scapy.all import * >> >> >> But I have no idea what I need. I am not trying to craft packets but >> filter packets based on tcp.dstport 80 & frame matches signin.aspx. Then >> my goal is to parse the data looking for post vars txtUserId & txtPwd and >> extract them, dumping them to the screen as userid_value => password. >> >> > I've never worked on Mac OSx And the only times I had and used scapy > were on a work machine that's long gone. I still run Linux, but versions > of everything have changed since then. > > I don't know if there's anyone here that's more current with scapy and/or > with Mac, but in case there is, you could be lots clearer about what you're > doing and how it fails. > > Version of OS. You said that well. > Version of Python,. > Exact location you got scapy from, what version it was > How you installed it (I don't know Macports, clearly) > What the full traceback was when it died. > > > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > Noted, I will try to be more verbose. Mac OS 10.8.2 Python v.2.7 I downloaded from the sourceforge site, then tried to install with MacPorts when some dependencies were failing. I then downloaded & installed pcapy-0.10.6 when that dependency still failed. That solved that but I received the dnet error: from scapy.all import conf File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in from arch import * File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", line 75, in from bsd import * File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, in from unix import * File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line 20, in from pcapdnet import * File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line 160, in import dnet ImportError: No module named dnet So I downloaded and compiled libdnet-1.11 with a: $ sudo ./configure && make I see it compile fine & the libraries have been installed to: /usr/local/sbin/dnet However, python can't find it... I am not clear on how to point Python there... Thanks again. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From john.g.evans.ne at gmail.com Wed Jan 23 07:25:02 2013 From: john.g.evans.ne at gmail.com (John Evans) Date: Wed, 23 Jan 2013 07:25:02 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: References: <50FF5312.50309@davea.name> <50FF5910.7060309@davea.name> Message-ID: The import "from scapy.all import *" does work for me with macports and 10.6.8 When I installed the scapy port, I did see that macports installed the py27-libdnet package as well. On Wed, Jan 23, 2013 at 1:24 AM, Dennis Lee Bieber wrote: > On Tue, 22 Jan 2013 22:43:24 -0500, Kevin Holleran > declaimed the following in gmane.comp.python.general: > > > > > Mac OS 10.8.2 > > Python v.2.7 > > I downloaded from the sourceforge site, then tried to install with > MacPorts > > when some dependencies were failing. I then downloaded & installed > > pcapy-0.10.6 when that dependency still failed. That solved that but I > > received the dnet error: > > > > from scapy.all import conf > > File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in > > > > from arch import * > > File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", line > 75, > > in > > from bsd import * > > File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, in > > > > from unix import * > > File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line 20, > in > > > > from pcapdnet import * > > File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line > > 160, in > > import dnet > > ImportError: No module named dnet > > > > So I downloaded and compiled libdnet-1.11 with a: > > $ sudo ./configure && make > > > > I see it compile fine & the libraries have been installed to: > > /usr/local/sbin/dnet > > > > However, python can't find it... I am not clear on how to point Python > > there... > > > "libdnet" is likely a shared object binary... What I /think/ you > are > missing is the Python library that interfaces with that binary... > > Could http://pypi.python.org/pypi/dnet answer the question? > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- John Evans -------------- next part -------------- An HTML attachment was scrubbed... URL: From kdawg44 at gmail.com Wed Jan 23 09:01:14 2013 From: kdawg44 at gmail.com (Kevin Holleran) Date: Wed, 23 Jan 2013 09:01:14 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: References: <50FF5312.50309@davea.name> <50FF5910.7060309@davea.name> Message-ID: On Wed, Jan 23, 2013 at 7:25 AM, John Evans wrote: > The import "from scapy.all import *" does work for me with macports and > 10.6.8 When I installed the scapy port, I did see that macports installed > the py27-libdnet package as well. > > > ? > > > On Wed, Jan 23, 2013 at 1:24 AM, Dennis Lee Bieber wrote: > >> On Tue, 22 Jan 2013 22:43:24 -0500, Kevin Holleran >> declaimed the following in gmane.comp.python.general: >> >> > >> > Mac OS 10.8.2 >> > Python v.2.7 >> > I downloaded from the sourceforge site, then tried to install with >> MacPorts >> > when some dependencies were failing. I then downloaded & installed >> > pcapy-0.10.6 when that dependency still failed. That solved that but I >> > received the dnet error: >> > >> > from scapy.all import conf >> > File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in >> > >> > from arch import * >> > File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", line >> 75, >> > in >> > from bsd import * >> > File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, >> in >> > >> > from unix import * >> > File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line 20, >> in >> > >> > from pcapdnet import * >> > File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line >> > 160, in >> > import dnet >> > ImportError: No module named dnet >> > >> > So I downloaded and compiled libdnet-1.11 with a: >> > $ sudo ./configure && make >> > >> > I see it compile fine & the libraries have been installed to: >> > /usr/local/sbin/dnet >> > >> > However, python can't find it... I am not clear on how to point Python >> > there... >> > >> "libdnet" is likely a shared object binary... What I /think/ you >> are >> missing is the Python library that interfaces with that binary... >> >> Could http://pypi.python.org/pypi/dnet answer the question? >> -- >> Wulfraed Dennis Lee Bieber AF6VN >> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > John Evans > > -- > http://mail.python.org/mailman/listinfo/python-list > > I downloaded scapy manually since for some reason, after using macports, it wouldn't find the package at all. I am also trying to install libdnet manually as mentioned above, so after ./configure && make I go into the python directory & do a python setup.py install, which generates a bunch of warnings & the following two errors: /dnet.c:2729:4: error: assignment to cast is illegal, lvalue casts are not supported ((PyObject*)__pyx_v_next) = Py_None; Py_INCREF(((PyObject*)__pyx_v_next)); ~^~~~~~~~~~~~~~~~~~~~~~~~ ~ ./dnet.c:2741:6: error: assignment to cast is illegal, lvalue casts are not supported ((PyObject *)__pyx_v_next) = __pyx_3; ~^~~~~~~~~~~~~~~~~~~~~~~~~ ~ Thanks again for any help. Need to get all this working for this mini-project and also because I am starting a SANS class that leverages scapy quite a bit... Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From john.g.evans.ne at gmail.com Wed Jan 23 10:57:29 2013 From: john.g.evans.ne at gmail.com (John Evans) Date: Wed, 23 Jan 2013 10:57:29 -0500 Subject: Parse a Wireshark pcap file In-Reply-To: References: <50FF5312.50309@davea.name> <50FF5910.7060309@davea.name> Message-ID: It looks like there was some very recent reorganization of the scapy packaging on macports, see http://lists.macosforge.org/pipermail/macports-dev/2013-January/021620.html Did you have an updated port tree when you installed? If not, I'd suggest uninstalling whatever port you installed, resync with "port selfupdate", then install the scapy port again. You should see not only the libdnet port installed, but also py27-libdnet, which is the missing glue you need for interfacing with libdnet. On Wed, Jan 23, 2013 at 9:01 AM, Kevin Holleran wrote: > > On Wed, Jan 23, 2013 at 7:25 AM, John Evans wrote: > >> The import "from scapy.all import *" does work for me with macports and >> 10.6.8 When I installed the scapy port, I did see that macports installed >> the py27-libdnet package as well. >> >> >> ? >> >> >> On Wed, Jan 23, 2013 at 1:24 AM, Dennis Lee Bieber > > wrote: >> >>> On Tue, 22 Jan 2013 22:43:24 -0500, Kevin Holleran >>> declaimed the following in gmane.comp.python.general: >>> >>> > >>> > Mac OS 10.8.2 >>> > Python v.2.7 >>> > I downloaded from the sourceforge site, then tried to install with >>> MacPorts >>> > when some dependencies were failing. I then downloaded & installed >>> > pcapy-0.10.6 when that dependency still failed. That solved that but I >>> > received the dnet error: >>> > >>> > from scapy.all import conf >>> > File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in >>> > >>> > from arch import * >>> > File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", >>> line 75, >>> > in >>> > from bsd import * >>> > File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, >>> in >>> > >>> > from unix import * >>> > File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line >>> 20, in >>> > >>> > from pcapdnet import * >>> > File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line >>> > 160, in >>> > import dnet >>> > ImportError: No module named dnet >>> > >>> > So I downloaded and compiled libdnet-1.11 with a: >>> > $ sudo ./configure && make >>> > >>> > I see it compile fine & the libraries have been installed to: >>> > /usr/local/sbin/dnet >>> > >>> > However, python can't find it... I am not clear on how to point Python >>> > there... >>> > >>> "libdnet" is likely a shared object binary... What I /think/ you >>> are >>> missing is the Python library that interfaces with that binary... >>> >>> Could http://pypi.python.org/pypi/dnet answer the question? >>> -- >>> Wulfraed Dennis Lee Bieber AF6VN >>> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> >> -- >> John Evans >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > I downloaded scapy manually since for some reason, after using macports, > it wouldn't find the package at all. > > I am also trying to install libdnet manually as mentioned above, so after > ./configure && make I go into the python directory & do a python setup.py > install, which generates a bunch of warnings & the following two errors: > > /dnet.c:2729:4: error: assignment to cast is illegal, lvalue casts are not > supported > ((PyObject*)__pyx_v_next) = Py_None; > Py_INCREF(((PyObject*)__pyx_v_next)); > ~^~~~~~~~~~~~~~~~~~~~~~~~ ~ > ./dnet.c:2741:6: error: assignment to cast is illegal, lvalue casts are > not supported > ((PyObject *)__pyx_v_next) = __pyx_3; > ~^~~~~~~~~~~~~~~~~~~~~~~~~ ~ > > > Thanks again for any help. Need to get all this working for this > mini-project and also because I am starting a SANS class that leverages > scapy quite a bit... > > Kevin > > -- John Evans -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Wed Jan 23 16:50:59 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 23 Jan 2013 21:50:59 +0000 (UTC) Subject: Parse a Wireshark pcap file References: Message-ID: On 2013-01-23, Kevin Holleran wrote: > Is there a way to parse out a wireshark pcap file and extract key value > pairs from the data? You can use pylibpcap to read pcap files (or to capture live data). I'm afraid I don't know what "parse out" or "extract key value pairs" means. pylibpcap doesn't have access to any of wireshark's packet disecter plugins, if that's what you're after. > I am illustrated a sniff of some traffic and why it needs utilize > HTTPS instead of HTTP but I was hoping to run the pcap through a > python script and just output some interesting key value pairs.... To what does "key value pairs" refer? -- Grant Edwards grant.b.edwards Yow! I am a traffic light, at and Alan Ginzberg kidnapped gmail.com my laundry in 1927! From liujz39 at gmail.com Tue Jan 22 21:43:23 2013 From: liujz39 at gmail.com (liujz39 at gmail.com) Date: Tue, 22 Jan 2013 18:43:23 -0800 (PST) Subject: Failed to import a "pyd: File When python intepreter embed in C++ project Message-ID: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> I create a pyd File named "testPyd" with boostPython,and then I import the testPyd module into "test.py", it works perfect! But when I embeded the python interpreter into my C++ project and run the "test.py", it comes out a "ImportErr: no module named testPyd". It has confused me for two days and I googled for long time,but I can't find the answer! Anybody here can help me ? Thank you! From rosuav at gmail.com Tue Jan 22 23:49:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jan 2013 15:49:43 +1100 Subject: Failed to import a "pyd: File When python intepreter embed in C++ project In-Reply-To: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> References: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> Message-ID: On Wed, Jan 23, 2013 at 1:43 PM, wrote: > I create a pyd File named "testPyd" with boostPython,and then I import the testPyd module into "test.py", it works perfect! > But when I embeded the python interpreter into my C++ project and run the "test.py", it comes out a "ImportErr: no module named testPyd". > It has confused me for two days and I googled for long time,but I can't find the answer! > Anybody here can help me ? > Thank you! First thing you should do is to get a minimal example that demonstrates the problem, and *copy and paste* it and the exception traceback. When your own spelling is as sloppy as this, we need to see Python's accuracies to have any chance of being able to help you. Plus, the process of shrinking your example to the minimum often highlights the actual cause of the problem. Even if it doesn't, it'll certainly be easier for us to help you if it's a small, self-contained script than if it's huge. http://sscce.org/ ChrisA From liujz39 at gmail.com Wed Jan 23 02:05:09 2013 From: liujz39 at gmail.com (liujz39 at gmail.com) Date: Tue, 22 Jan 2013 23:05:09 -0800 (PST) Subject: Failed to import a "pyd: File When python intepreter embed in C++ project In-Reply-To: References: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> Message-ID: <10549479-c8fa-47a9-9511-9f1454b9c9ca@googlegroups.com> On Wednesday, January 23, 2013 12:49:43 PM UTC+8, Chris Angelico wrote: > > > > Thank you! > > > > First thing you should do is to get a minimal example that > > demonstrates the problem, and *copy and paste* it and the exception > > traceback. When your own spelling is as sloppy as this, we need to see > > Python's accuracies to have any chance of being able to help you. > > Plus, the process of shrinking your example to the minimum often > > highlights the actual cause of the problem. Even if it doesn't, it'll > > certainly be easier for us to help you if it's a small, self-contained > > script than if it's huge. > > > > ChrisA Thanks for your attention and sorry for the sloppy of my spelling!!! Here is my test examples: The C++ codes to build the *pyd File* is: Excute.h #ifndef EXCUTE_H_ #define EXCUTE_H_ #include class Excute { public: Excute(){} int getIoReuslt(std::string ioStr); int getSignal(); }; #endif Excute.cpp: #include "Excute.h" #include "Explanation.h" #include int Excute::getIoReuslt(std::string ioStr) { return 1; } int Excute::getSignal() { int i = rand()%2; return i; } BOOST_PYTHON_MODULE(pythonDll) { using namespace boost::python; class_("Excute", init<>()) .def("getIoResult", &Excute::getIoReuslt) .def("getSignal", &Excute::getSignal) ; } Then a pyd File Named pythonDll is created(pythonDll.pyd), Here are the codes in my test.py: test.py: from pythonDll import* h=Excurte() print h.getIoResult("a") print h.getSignal() And this script works perfect in IDLE. And then I embed python into my C++ project,Here are the test codes: #include #include int main(int argc, char* argv[]) { Py_Initialize(); FILE * fp = fopen("$PATH/test.py", "r"); if (fp == NULL) { return 1; } PyRun_SimpleString("execfile($PATH/test.py')"); Py_Finalize(); system("Pause"); return 0; } The result is: Traceback (most recent call last): File "", line 1, in File "$PATH/test.py", line 1, in from pythonDll import* ImportError: No module named pythonDll [19228 refs] It bored me for a couple of days!If you get any ways to solve this ,please let me know!And thank you again! From Arah.Leonard at bruker-axs.com Wed Jan 23 11:28:58 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Wed, 23 Jan 2013 16:28:58 +0000 Subject: Failed to import a "pyd: File When python intepreter embed in C++ project In-Reply-To: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> References: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07586684@msnmail2.bruker-axs.com> > I create a pyd File named "testPyd" with boostPython,and then I import the testPyd module into "test.py", it works perfect! > But when I embeded the python interpreter into my C++ project and run the "test.py", it comes out a "ImportErr: no module named testPyd". > It has confused me for two days and I googled for long time,but I can't find the answer! > Anybody here can help me ? > Thank you! > Ah, that sounds familiar. I have a small bit of experience with Boost. I could be wrong, because once you start mixing it up with Boost all sorts of weird things can happen (especially on a MS compiler, because no one tests for Windows, let alone a pay-for compiler) but my experience has shown that if you get that specific import error, what it actually means is just that the PYD import failed for ANY reason. It has nothing to do with the name or that the PYD couldn't be found. Just that somewhere, at some time during import, it failed to fully load. In my use a lot of times it was either that a DLL that module depended on wasn't in the path, or my favorite kicker, that some compile/link flags between the PYD and the Python interpreter don't match well enough. (Usually from mixing debug and release builds together.) From what I've seen anyway, the Python interpreter really doesn't like being built in a traditional debug mode, so I always do a release build of it. It's a little inconvenient, but in the linker flags you can still set your PYDs to generate debug information even in release builds, so you can still run the debugger on them when you attach to the process of the python interpreter EXE. And especially be sure to use the RELEASE runtime library flag (such as /MD) instead of the debug flag (such as /MDd). That's as much as I know anyway. Though depending, if you add any new templates/libraries into Boost (such as for NumPy ndarray), you also may need to use the /DBOOST_ALL_NO_LIB compiler macro on an MS compiler because MS doesn't adhere to template standards correctly and you often end up with multiply-defined functions if you don't use that macro. If I remember correctly. (It's been a while.) That and you may be picking up variable length arrays out of your teeth, replacing chunks of code with the use of new and delete operators. No one tests for Microsoft and the MS compiler is way behind in adhering to C/C++ standards, and VLAs pop up a lot. Hopefully something in all of this helped. Boost can be ... daunting. I get it, in theory. But in practice it often hurts my head. ;) Sincerely, Arah Leonard From liujz39 at gmail.com Wed Jan 23 21:43:50 2013 From: liujz39 at gmail.com (Junze Liu) Date: Wed, 23 Jan 2013 18:43:50 -0800 (PST) Subject: Failed to import a "pyd: File When python intepreter embed in C++ project In-Reply-To: References: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> Message-ID: On Thursday, January 24, 2013 12:28:58 AM UTC+8, Leonard, Arah wrote: > > I create a pyd File named "testPyd" with boostPython,and then I import the testPyd module into "test.py", it works perfect! > > > But when I embeded the python interpreter into my C++ project and run the "test.py", it comes out a "ImportErr: no module named testPyd". > > > It has confused me for two days and I googled for long time,but I can't find the answer! > > > Anybody here can help me ? > > > Thank you! > > > > > > > Ah, that sounds familiar. I have a small bit of experience with Boost. I could be wrong, because once you start mixing it up with Boost all sorts of weird things can happen (especially on a MS compiler, because no one tests for Windows, let alone a pay-for compiler) but my experience has shown that if you get that specific import error, what it actually means is just that the PYD import failed for ANY reason. It has nothing to do with the name or that the PYD couldn't be found. Just that somewhere, at some time during import, it failed to fully load. > > > > In my use a lot of times it was either that a DLL that module depended on wasn't in the path, or my favorite kicker, that some compile/link flags between the PYD and the Python interpreter don't match well enough. (Usually from mixing debug and release builds together.) > > > > From what I've seen anyway, the Python interpreter really doesn't like being built in a traditional debug mode, so I always do a release build of it. It's a little inconvenient, but in the linker flags you can still set your PYDs to generate debug information even in release builds, so you can still run the debugger on them when you attach to the process of the python interpreter EXE. And especially be sure to use the RELEASE runtime library flag (such as /MD) instead of the debug flag (such as /MDd). > > > > That's as much as I know anyway. Though depending, if you add any new templates/libraries into Boost (such as for NumPy ndarray), you also may need to use the /DBOOST_ALL_NO_LIB compiler macro on an MS compiler because MS doesn't adhere to template standards correctly and you often end up with multiply-defined functions if you don't use that macro. If I remember correctly. (It's been a while.) > > > > That and you may be picking up variable length arrays out of your teeth, replacing chunks of code with the use of new and delete operators. No one tests for Microsoft and the MS compiler is way behind in adhering to C/C++ standards, and VLAs pop up a lot. > > > > Hopefully something in all of this helped. Boost can be ... daunting. I get it, in theory. But in practice it often hurts my head. ;) > > > > Sincerely, > > Arah Leonard Dear Lenoard, Thanks for your hearty assistance, and it finally works.I just change my RELEASE Run Time Library flag to MD, then the results come out. Before I receive your mail, I googled for kinds of solutions and tried to solve this problem, but none of them works.Yesterday, someones said that the python module in *pyd Files* should be initialized before they can be embed into C++, and a function named init should be called before importing the module, I was confused with this for a couple of hours until I saw your mail. I am new to boost.python.If I propose any questions that seems naive to you the other days, any suggestion from you would be more than welcome! Thanks again for your help to make me out of my wrong way! Sincerely, George Liu From liujz39 at gmail.com Wed Jan 23 21:43:50 2013 From: liujz39 at gmail.com (Junze Liu) Date: Wed, 23 Jan 2013 18:43:50 -0800 (PST) Subject: Failed to import a "pyd: File When python intepreter embed in C++ project In-Reply-To: References: <552da0d2-e744-4ce2-8204-14a7274515de@googlegroups.com> Message-ID: On Thursday, January 24, 2013 12:28:58 AM UTC+8, Leonard, Arah wrote: > > I create a pyd File named "testPyd" with boostPython,and then I import the testPyd module into "test.py", it works perfect! > > > But when I embeded the python interpreter into my C++ project and run the "test.py", it comes out a "ImportErr: no module named testPyd". > > > It has confused me for two days and I googled for long time,but I can't find the answer! > > > Anybody here can help me ? > > > Thank you! > > > > > > > Ah, that sounds familiar. I have a small bit of experience with Boost. I could be wrong, because once you start mixing it up with Boost all sorts of weird things can happen (especially on a MS compiler, because no one tests for Windows, let alone a pay-for compiler) but my experience has shown that if you get that specific import error, what it actually means is just that the PYD import failed for ANY reason. It has nothing to do with the name or that the PYD couldn't be found. Just that somewhere, at some time during import, it failed to fully load. > > > > In my use a lot of times it was either that a DLL that module depended on wasn't in the path, or my favorite kicker, that some compile/link flags between the PYD and the Python interpreter don't match well enough. (Usually from mixing debug and release builds together.) > > > > From what I've seen anyway, the Python interpreter really doesn't like being built in a traditional debug mode, so I always do a release build of it. It's a little inconvenient, but in the linker flags you can still set your PYDs to generate debug information even in release builds, so you can still run the debugger on them when you attach to the process of the python interpreter EXE. And especially be sure to use the RELEASE runtime library flag (such as /MD) instead of the debug flag (such as /MDd). > > > > That's as much as I know anyway. Though depending, if you add any new templates/libraries into Boost (such as for NumPy ndarray), you also may need to use the /DBOOST_ALL_NO_LIB compiler macro on an MS compiler because MS doesn't adhere to template standards correctly and you often end up with multiply-defined functions if you don't use that macro. If I remember correctly. (It's been a while.) > > > > That and you may be picking up variable length arrays out of your teeth, replacing chunks of code with the use of new and delete operators. No one tests for Microsoft and the MS compiler is way behind in adhering to C/C++ standards, and VLAs pop up a lot. > > > > Hopefully something in all of this helped. Boost can be ... daunting. I get it, in theory. But in practice it often hurts my head. ;) > > > > Sincerely, > > Arah Leonard Dear Lenoard, Thanks for your hearty assistance, and it finally works.I just change my RELEASE Run Time Library flag to MD, then the results come out. Before I receive your mail, I googled for kinds of solutions and tried to solve this problem, but none of them works.Yesterday, someones said that the python module in *pyd Files* should be initialized before they can be embed into C++, and a function named init should be called before importing the module, I was confused with this for a couple of hours until I saw your mail. I am new to boost.python.If I propose any questions that seems naive to you the other days, any suggestion from you would be more than welcome! Thanks again for your help to make me out of my wrong way! Sincerely, George Liu From winefrog at gmail.com Tue Jan 22 23:06:41 2013 From: winefrog at gmail.com (Isaac Won) Date: Tue, 22 Jan 2013 20:06:41 -0800 (PST) Subject: Memory error with quadratic interpolation Message-ID: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Hi all, I have tried to use different interpolation methods with Scipy. My code seems just fine with linear interpolation, but shows memory error with quadratic. I am a novice for python. I will appreciate any help. #code f = open(filin, "r") for columns in ( raw.strip().split() for raw in f ): a.append(columns[5]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') p = interp(indices) ------------------------------------------------------------------------ The number of data is 31747. Thank you, Isaac From ulrich.eckhardt at dominolaser.com Wed Jan 23 03:55:14 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 23 Jan 2013 09:55:14 +0100 Subject: Memory error with quadratic interpolation In-Reply-To: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: Am 23.01.2013 05:06, schrieb Isaac Won: > I have tried to use different interpolation methods with Scipy. My > code seems just fine with linear interpolation, but shows memory > error with quadratic. I am a novice for python. I will appreciate any > help. > > #code > f = open(filin, "r") Check out the "with open(...) as f" syntax. > for columns in ( raw.strip().split() for raw in f ): For the record, this first builds a sequence and then iterates over that sequence. This is not very memory-efficient, try this instead: for line in f: columns = line.strip().split() Concerning the rest of your problems, there is lots of code and the datafile missing. However, there is also too much of it, try replacing the file with generated data and remove everything from the code that is not absolutely necessary. Good luck! Uli From oscar.j.benjamin at gmail.com Wed Jan 23 05:08:13 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 10:08:13 +0000 Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: On 23 January 2013 08:55, Ulrich Eckhardt wrote: > Am 23.01.2013 05:06, schrieb Isaac Won: > >> I have tried to use different interpolation methods with Scipy. My >> code seems just fine with linear interpolation, but shows memory >> error with quadratic. I am a novice for python. I will appreciate any >> help. > [SNIP] > > > Concerning the rest of your problems, there is lots of code and the datafile > missing. However, there is also too much of it, try replacing the file with > generated data and remove everything from the code that is not absolutely > necessary. Also please copy paste the actual error message rather than paraphrasing it. Oscar From winefrog at gmail.com Wed Jan 23 09:26:25 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:26:25 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: <369aff35-d655-4706-bfae-3a9a0535b923@googlegroups.com> On Wednesday, January 23, 2013 4:08:13 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 08:55, Ulrich Eckhardt > > wrote: > > > Am 23.01.2013 05:06, schrieb Isaac Won: > > > > > >> I have tried to use different interpolation methods with Scipy. My > > >> code seems just fine with linear interpolation, but shows memory > > >> error with quadratic. I am a novice for python. I will appreciate any > > >> help. > > > > > [SNIP] > > > > > > > > > Concerning the rest of your problems, there is lots of code and the datafile > > > missing. However, there is also too much of it, try replacing the file with > > > generated data and remove everything from the code that is not absolutely > > > necessary. > > > > Also please copy paste the actual error message rather than paraphrasing it. > > > > > > Oscar I really appreciate to both Ulich and Oscar. To Oscar My actual error message is: File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError -------------------------------------------------------------------------- Thank you, Isaac From winefrog at gmail.com Wed Jan 23 09:26:25 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:26:25 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: <369aff35-d655-4706-bfae-3a9a0535b923@googlegroups.com> On Wednesday, January 23, 2013 4:08:13 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 08:55, Ulrich Eckhardt > > wrote: > > > Am 23.01.2013 05:06, schrieb Isaac Won: > > > > > >> I have tried to use different interpolation methods with Scipy. My > > >> code seems just fine with linear interpolation, but shows memory > > >> error with quadratic. I am a novice for python. I will appreciate any > > >> help. > > > > > [SNIP] > > > > > > > > > Concerning the rest of your problems, there is lots of code and the datafile > > > missing. However, there is also too much of it, try replacing the file with > > > generated data and remove everything from the code that is not absolutely > > > necessary. > > > > Also please copy paste the actual error message rather than paraphrasing it. > > > > > > Oscar I really appreciate to both Ulich and Oscar. To Oscar My actual error message is: File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError -------------------------------------------------------------------------- Thank you, Isaac From winefrog at gmail.com Wed Jan 23 09:28:03 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:28:03 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> On Wednesday, January 23, 2013 4:08:13 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 08:55, Ulrich Eckhardt > > > > > Am 23.01.2013 05:06, schrieb Isaac Won: > > > > > >> I have tried to use different interpolation methods with Scipy. My > > >> code seems just fine with linear interpolation, but shows memory > > >> error with quadratic. I am a novice for python. I will appreciate any > > >> help. > > > > > [SNIP] > > > > > > > > > Concerning the rest of your problems, there is lots of code and the datafile > > > missing. However, there is also too much of it, try replacing the file with > > > generated data and remove everything from the code that is not absolutely > > > necessary. > > > > Also please copy paste the actual error message rather than paraphrasing it. > > > > > > Oscar I really appreciate to both Ulich and Oscar. To Oscar My actual error message is: File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError -------------------------------------------------------------------------- Thank you, Hoonill From winefrog at gmail.com Wed Jan 23 09:28:03 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:28:03 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> On Wednesday, January 23, 2013 4:08:13 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 08:55, Ulrich Eckhardt > > > > > Am 23.01.2013 05:06, schrieb Isaac Won: > > > > > >> I have tried to use different interpolation methods with Scipy. My > > >> code seems just fine with linear interpolation, but shows memory > > >> error with quadratic. I am a novice for python. I will appreciate any > > >> help. > > > > > [SNIP] > > > > > > > > > Concerning the rest of your problems, there is lots of code and the datafile > > > missing. However, there is also too much of it, try replacing the file with > > > generated data and remove everything from the code that is not absolutely > > > necessary. > > > > Also please copy paste the actual error message rather than paraphrasing it. > > > > > > Oscar I really appreciate to both Ulich and Oscar. To Oscar My actual error message is: File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError -------------------------------------------------------------------------- Thank you, Hoonill From oscar.j.benjamin at gmail.com Wed Jan 23 09:40:54 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 14:40:54 +0000 Subject: Memory error with quadratic interpolation In-Reply-To: <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> Message-ID: On 23 January 2013 14:28, Isaac Won wrote: > On Wednesday, January 23, 2013 4:08:13 AM UTC-6, Oscar Benjamin wrote: > > To Oscar > My actual error message is: > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ > self._spline = splmake(x,oriented_y,order=order) > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake > coefs = func(xk, yk, order, conds, B) > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest > u,s,vh = np.dual.svd(B) > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd > full_matrices=full_matrices, overwrite_a = overwrite_a) > MemoryError Are you sure that's the *whole* error message? The traceback only refers to the scipy modules. I can't see the line from your code that is generating the error. Oscar From winefrog at gmail.com Wed Jan 23 09:57:39 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:57:39 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> Message-ID: On Wednesday, January 23, 2013 8:40:54 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 14:28, Isaac Won wrote: > > > On Wednesday, January 23, 2013 4:08:13 AM UTC-6, Oscar Benjamin wrote: > > > > > > To Oscar > > > My actual error message is: > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ > > > self._spline = splmake(x,oriented_y,order=order) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake > > > coefs = func(xk, yk, order, conds, B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest > > > u,s,vh = np.dual.svd(B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd > > > full_matrices=full_matrices, overwrite_a = overwrite_a) > > > MemoryError > > > > Are you sure that's the *whole* error message? The traceback only > > refers to the scipy modules. I can't see the line from your code that > > is generating the error. > > > > > > Oscar Dear Oscar, Following is full error message after I adjusted following Ulich's advice: interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError ---------------------------------------------------------------------- Thank you, Hoonill From winefrog at gmail.com Wed Jan 23 09:57:39 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:57:39 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> Message-ID: On Wednesday, January 23, 2013 8:40:54 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 14:28, Isaac Won wrote: > > > On Wednesday, January 23, 2013 4:08:13 AM UTC-6, Oscar Benjamin wrote: > > > > > > To Oscar > > > My actual error message is: > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ > > > self._spline = splmake(x,oriented_y,order=order) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake > > > coefs = func(xk, yk, order, conds, B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest > > > u,s,vh = np.dual.svd(B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd > > > full_matrices=full_matrices, overwrite_a = overwrite_a) > > > MemoryError > > > > Are you sure that's the *whole* error message? The traceback only > > refers to the scipy modules. I can't see the line from your code that > > is generating the error. > > > > > > Oscar Dear Oscar, Following is full error message after I adjusted following Ulich's advice: interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError ---------------------------------------------------------------------- Thank you, Hoonill From oscar.j.benjamin at gmail.com Wed Jan 23 11:51:43 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 16:51:43 +0000 Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> Message-ID: On 23 January 2013 14:57, Isaac Won wrote: > On Wednesday, January 23, 2013 8:40:54 AM UTC-6, Oscar Benjamin wrote: >> On 23 January 2013 14:28, Isaac Won wrote: >> [SNIP] > > Following is full error message after I adjusted following Ulich's advice: > > interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ > self._spline = splmake(x,oriented_y,order=order) > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake > coefs = func(xk, yk, order, conds, B) > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest > u,s,vh = np.dual.svd(B) > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd > full_matrices=full_matrices, overwrite_a = overwrite_a) > MemoryError Where is the new code? You should show full working code (with the import statements) and the full error that is generated by exactly that code. If possible you should also write code that someone else could run even without having access to your data files. If you did that in your first post, you'd probably have an answer to your problem by now. Here is a version of your code that many people on this list can test straight away: import numpy as np from scipy.interpolate import interp1d x = np.array(31747 * [0.0], float) indices = np.arange(len(x)) interp = interp1d(indices, x, kind='quadratic') Running this gives the following error: ~$ python tmp.py Traceback (most recent call last): File "tmp.py", line 5, in interp = interp1d(indices, x, kind='quadratic') File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 308, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 805, in splmake B = _fitpack._bsplmat(order, xk) MemoryError Unless I've misunderstood how this function is supposed to be used, it just doesn't really seem to work for arrays of much more than a few hundred elements. Oscar From winefrog at gmail.com Wed Jan 23 12:33:31 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 09:33:31 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> Message-ID: <94ef456a-af84-48fe-8007-df42c4a625c4@googlegroups.com> On Wednesday, January 23, 2013 10:51:43 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 14:57, Isaac Won wrote: > > > On Wednesday, January 23, 2013 8:40:54 AM UTC-6, Oscar Benjamin wrote: > > >> On 23 January 2013 14:28, Isaac Won wrote: > > >> > > [SNIP] > > > > > > Following is full error message after I adjusted following Ulich's advice: > > > > > > interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ > > > self._spline = splmake(x,oriented_y,order=order) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake > > > coefs = func(xk, yk, order, conds, B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest > > > u,s,vh = np.dual.svd(B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd > > > full_matrices=full_matrices, overwrite_a = overwrite_a) > > > MemoryError > > > > Where is the new code? You should show full working code (with the > > import statements) and the full error that is generated by exactly > > that code. If possible you should also write code that someone else > > could run even without having access to your data files. If you did > > that in your first post, you'd probably have an answer to your problem > > by now. > > > > Here is a version of your code that many people on this list can test > > straight away: > > > > import numpy as np > > from scipy.interpolate import interp1d > > x = np.array(31747 * [0.0], float) > > indices = np.arange(len(x)) > > interp = interp1d(indices, x, kind='quadratic') > > > > Running this gives the following error: > > > > ~$ python tmp.py > > Traceback (most recent call last): > > File "tmp.py", line 5, in > > interp = interp1d(indices, x, kind='quadratic') > > File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", > > line 308, in __init__ > > self._spline = splmake(x,oriented_y,order=order) > > File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", > > line 805, in splmake > > B = _fitpack._bsplmat(order, xk) > > MemoryError > > > > Unless I've misunderstood how this function is supposed to be used, it > > just doesn't really seem to work for arrays of much more than a few > > hundred elements. > > > > > > Oscar Thank you Oscar for your help and advice. I agree with you. So, I tried to find the way to solve this problem. My full code adjusted is: from scipy.interpolate import interp1d import numpy as np import matplotlib.pyplot as plt with open(filin, "r") as f: for line in f: columns = line.strip().split() a.append(columns[5]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') p = interp(indices) k = np.arange(31747) plt.subplot(211) plt.plot(k, p) plt.xlabel('Quadratic interpolation') plt.subplot(212) plt.plot(k, x) plt.show() ----------------------------------------------------------------- Whole error message was: Traceback (most recent call last): File "QI1.py", line 22, in interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError ---------------------------------------------------------------------- Thank you again Oscar, Isaac From winefrog at gmail.com Wed Jan 23 12:33:31 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 09:33:31 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> Message-ID: <94ef456a-af84-48fe-8007-df42c4a625c4@googlegroups.com> On Wednesday, January 23, 2013 10:51:43 AM UTC-6, Oscar Benjamin wrote: > On 23 January 2013 14:57, Isaac Won wrote: > > > On Wednesday, January 23, 2013 8:40:54 AM UTC-6, Oscar Benjamin wrote: > > >> On 23 January 2013 14:28, Isaac Won wrote: > > >> > > [SNIP] > > > > > > Following is full error message after I adjusted following Ulich's advice: > > > > > > interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ > > > self._spline = splmake(x,oriented_y,order=order) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake > > > coefs = func(xk, yk, order, conds, B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest > > > u,s,vh = np.dual.svd(B) > > > File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd > > > full_matrices=full_matrices, overwrite_a = overwrite_a) > > > MemoryError > > > > Where is the new code? You should show full working code (with the > > import statements) and the full error that is generated by exactly > > that code. If possible you should also write code that someone else > > could run even without having access to your data files. If you did > > that in your first post, you'd probably have an answer to your problem > > by now. > > > > Here is a version of your code that many people on this list can test > > straight away: > > > > import numpy as np > > from scipy.interpolate import interp1d > > x = np.array(31747 * [0.0], float) > > indices = np.arange(len(x)) > > interp = interp1d(indices, x, kind='quadratic') > > > > Running this gives the following error: > > > > ~$ python tmp.py > > Traceback (most recent call last): > > File "tmp.py", line 5, in > > interp = interp1d(indices, x, kind='quadratic') > > File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", > > line 308, in __init__ > > self._spline = splmake(x,oriented_y,order=order) > > File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", > > line 805, in splmake > > B = _fitpack._bsplmat(order, xk) > > MemoryError > > > > Unless I've misunderstood how this function is supposed to be used, it > > just doesn't really seem to work for arrays of much more than a few > > hundred elements. > > > > > > Oscar Thank you Oscar for your help and advice. I agree with you. So, I tried to find the way to solve this problem. My full code adjusted is: from scipy.interpolate import interp1d import numpy as np import matplotlib.pyplot as plt with open(filin, "r") as f: for line in f: columns = line.strip().split() a.append(columns[5]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') p = interp(indices) k = np.arange(31747) plt.subplot(211) plt.plot(k, p) plt.xlabel('Quadratic interpolation') plt.subplot(212) plt.plot(k, x) plt.show() ----------------------------------------------------------------- Whole error message was: Traceback (most recent call last): File "QI1.py", line 22, in interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError ---------------------------------------------------------------------- Thank you again Oscar, Isaac From oscar.j.benjamin at gmail.com Thu Jan 24 05:30:55 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 10:30:55 +0000 Subject: Memory error with quadratic interpolation In-Reply-To: <94ef456a-af84-48fe-8007-df42c4a625c4@googlegroups.com> References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> <8daf86cf-386c-44ae-83d5-25fb04572c00@googlegroups.com> <94ef456a-af84-48fe-8007-df42c4a625c4@googlegroups.com> Message-ID: On 23 January 2013 17:33, Isaac Won wrote: > On Wednesday, January 23, 2013 10:51:43 AM UTC-6, Oscar Benjamin wrote: >> On 23 January 2013 14:57, Isaac Won wrote: >> >> > On Wednesday, January 23, 2013 8:40:54 AM UTC-6, Oscar Benjamin wrote: >> >> Unless I've misunderstood how this function is supposed to be used, it >> just doesn't really seem to work for arrays of much more than a few >> hundred elements. >> The solution is to use UnivariateSpline. I don't know what the difference is but it works where the other fails: import numpy as np from scipy.interpolate import UnivariateSpline x = np.array(10000 * [0.0], float) indices = np.arange(len(x)) interp = UnivariateSpline(indices, x, k=2) print(interp(1.5)) Oscar From winefrog at gmail.com Wed Jan 23 09:47:36 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:47:36 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: <1daeb571-3769-455a-b2d6-e784d816db58@googlegroups.com> On Wednesday, January 23, 2013 2:55:14 AM UTC-6, Ulrich Eckhardt wrote: > Am 23.01.2013 05:06, schrieb Isaac Won: > > > I have tried to use different interpolation methods with Scipy. My > > > code seems just fine with linear interpolation, but shows memory > > > error with quadratic. I am a novice for python. I will appreciate any > > > help. > > > > > > #code > > > f = open(filin, "r") > > > > Check out the "with open(...) as f" syntax. > > > > > > > for columns in ( raw.strip().split() for raw in f ): > > > > For the record, this first builds a sequence and then iterates over that > > sequence. This is not very memory-efficient, try this instead: > > > > for line in f: > > columns = line.strip().split() > > > > > > Concerning the rest of your problems, there is lots of code and the > > datafile missing. However, there is also too much of it, try replacing > > the file with generated data and remove everything from the code that is > > not absolutely necessary. > > > > Good luck! > > > > Uli Hi Ulich, I tried to change the code following your advice, but it doesn't seem to work still. My adjusted code is: a = [] with open(filin, "r") as f: for line in f: columns = line.strip().split() a.append(columns[5]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') p = interp(indices) --------------------------------------------------------------------- And full error message is: interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError ----------------------------------------------------------------------- Could you give me some advice for this situation? Thank you always, Isaac From winefrog at gmail.com Wed Jan 23 09:24:02 2013 From: winefrog at gmail.com (Isaac Won) Date: Wed, 23 Jan 2013 06:24:02 -0800 (PST) Subject: Memory error with quadratic interpolation In-Reply-To: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> References: <0909ee56-c304-4b9d-8be9-97c7a3261d27@googlegroups.com> Message-ID: <9686dfe5-3229-4040-8e16-ac0d039d1b3f@googlegroups.com> On Tuesday, January 22, 2013 10:06:41 PM UTC-6, Isaac Won wrote: > Hi all, > > > > I have tried to use different interpolation methods with Scipy. My code seems just fine with linear interpolation, but shows memory error with quadratic. I am a novice for python. I will appreciate any help. > > > > #code > > f = open(filin, "r") > > for columns in ( raw.strip().split() for raw in f ): > > a.append(columns[5]) > > x = np.array(a, float) > > > > > > not_nan = np.logical_not(np.isnan(x)) > > indices = np.arange(len(x)) > > interp = interp1d(indices[not_nan], x[not_nan], kind = 'quadratic') > > > > p = interp(indices) > > > > ------------------------------------------------------------------------ > > The number of data is 31747. > > > > Thank you, > > > > Isaac I really appreciate to both Ulich and Oscar. To Oscar My actual error message is: File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 311, in __init__ self._spline = splmake(x,oriented_y,order=order) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in splmake coefs = func(xk, yk, order, conds, B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 530, in _find_smoothest u,s,vh = np.dual.svd(B) File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 91, in svd full_matrices=full_matrices, overwrite_a = overwrite_a) MemoryError -------------------------------------------------------------------------- Thank you, Hoonill From moonhkt at gmail.com Wed Jan 23 02:26:45 2013 From: moonhkt at gmail.com (moonhkt) Date: Tue, 22 Jan 2013 23:26:45 -0800 (PST) Subject: Increase value in hash table Message-ID: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Hi Al I have Data file have below Data file V1 V2 V3 V4 V4 V3 How to using count number of data ? Output V1 = 1 V2 = 1 V3 =2 V4 = 2 # Global Veriable printque = {} in def have below printque[val] = printque[val] + 1 I have below error File "xprintlogchk.py", line 78, in chklog printque[val] = printque[val] + 1 KeyError: 'nan' From clp2 at rebertia.com Wed Jan 23 02:34:56 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 22 Jan 2013 23:34:56 -0800 Subject: Increase value in hash table In-Reply-To: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: On Jan 22, 2013 11:31 PM, "moonhkt" wrote: > > Hi Al > > I have Data file have below > > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 Construct a frequency table using collections.Counter: http://docs.python.org/2.7/library/collections.html#collections.Counter -------------- next part -------------- An HTML attachment was scrubbed... URL: From moonhkt at gmail.com Wed Jan 23 04:23:04 2013 From: moonhkt at gmail.com (moonhkt) Date: Wed, 23 Jan 2013 01:23:04 -0800 (PST) Subject: Increase value in hash table References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: On Jan 23, 3:34?pm, Chris Rebert wrote: > On Jan 22, 2013 11:31 PM, "moonhkt" wrote: > > > > > > > > > > > > > Hi Al > > > I have Data file have below > > > Data file > > V1 > > V2 > > V3 > > V4 > > V4 > > V3 > > > How to using count number of data ? > > > Output > > V1 = 1 > > V2 = 1 > > V3 =2 > > V4 = 2 > > Construct a frequency table using collections.Counter: > > http://docs.python.org/2.7/library/collections.html#collections.Counter What is problem for below ? #!/usr/bin/env python # Python hash {} # Python Lists [] global age karry = "ER" k1 = "EU" age = {} age[karry] = 3 age[k1] = 5 def ABC(): global age global karry i = 0 a = "A B" karry = a.split() age[karry[0]] += 1 ABC() for key in age: print key, age[key] Result ex_array.py Traceback (most recent call last): File "ex_array.py", line 21, in ABC() File "ex_array.py", line 18, in ABC age[karry[0]] += 1 KeyError: 'A' From oscar.j.benjamin at gmail.com Wed Jan 23 05:12:25 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 23 Jan 2013 10:12:25 +0000 Subject: Increase value in hash table In-Reply-To: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: On 23 January 2013 07:26, moonhkt wrote: > Hi Al > > I have Data file have below > > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 > > > > # Global Veriable > printque = {} > in def have below > > printque[val] = printque[val] + 1 > > I have below error > File "xprintlogchk.py", line 78, in chklog > printque[val] = printque[val] + 1 > KeyError: 'nan' You can't retrieve the value of printque[val] if you haven't yet added an entry with the key val to the dict. Try this: if val not in printque: printque[val] = 1 else: printque[val] = printque[val] + 1 Oscar From moonhkt at gmail.com Wed Jan 23 10:33:09 2013 From: moonhkt at gmail.com (moonhk) Date: Wed, 23 Jan 2013 23:33:09 +0800 Subject: Increase value in hash table In-Reply-To: References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: Works. prndev = line.split() # print line for key in prndev : if key in 'lpr': val = prndev[5].replace("-P","") if val not in printque: printque[val] = 1 else: printque[val] = printque[val] + 1 if key in "/dev/null": val='null' if val not in printque: printque[val] = 1 else: printque[val] = printque[val] + 1 On Wed, Jan 23, 2013 at 6:12 PM, Oscar Benjamin wrote: > On 23 January 2013 07:26, moonhkt wrote: >> Hi Al >> >> I have Data file have below >> >> Data file >> V1 >> V2 >> V3 >> V4 >> V4 >> V3 >> >> How to using count number of data ? >> >> Output >> V1 = 1 >> V2 = 1 >> V3 =2 >> V4 = 2 >> >> >> >> # Global Veriable >> printque = {} >> in def have below >> >> printque[val] = printque[val] + 1 >> >> I have below error >> File "xprintlogchk.py", line 78, in chklog >> printque[val] = printque[val] + 1 >> KeyError: 'nan' > > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 > > > Oscar -- moonhkt GMT+8 From moonhkt at gmail.com Wed Jan 23 10:39:27 2013 From: moonhkt at gmail.com (moonhkt) Date: Wed, 23 Jan 2013 07:39:27 -0800 (PST) Subject: Increase value in hash table References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: <3ea1fef0-4a59-49f6-9e4f-ee62009bbb8e@y3g2000pbq.googlegroups.com> On Jan 23, 11:33?pm, moonhk wrote: > Works. > > ? ? ?prndev = line.split() > ? ? ? ? ?# print line > ? ? ? ? ?for key in prndev : > ? ? ? ? ? ? ?if key in 'lpr': > ? ? ? ? ? ? ? ? val = prndev[5].replace("-P","") > ? ? ? ? ? ? ? ? if val not in printque: > ? ? ? ? ? ? ? ? ? ?printque[val] = 1 > ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ?printque[val] = printque[val] + 1 > ? ? ? ? ? ? ?if key in "/dev/null": > ? ? ? ? ? ? ? ? ?val='null' > ? ? ? ? ? ? ? ? ?if val not in printque: > ? ? ? ? ? ? ? ? ? ? printque[val] = 1 > ? ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ? printque[val] = printque[val] + 1 > > On Wed, Jan 23, 2013 at 6:12 PM, Oscar Benjamin > > > > > > > > > > wrote: > > On 23 January 2013 07:26, moonhkt wrote: > >> Hi Al > > >> I have Data file have below > > >> Data file > >> V1 > >> V2 > >> V3 > >> V4 > >> V4 > >> V3 > > >> How to using count number of data ? > > >> Output > >> V1 = 1 > >> V2 = 1 > >> V3 =2 > >> V4 = 2 > > >> # Global Veriable > >> printque = {} > >> in def have below > > >> printque[val] = ?printque[val] + 1 > > >> I have below error > >> ? File "xprintlogchk.py", line 78, in chklog > >> ? ? printque[val] = ?printque[val] + 1 > >> KeyError: 'nan' > > > You can't retrieve the value of printque[val] if you haven't yet added > > an entry with the key val to the dict. Try this: > > > if val not in printque: > > ? ? printque[val] = 1 > > else: > > ? ? printque[val] = printque[val] + 1 > > > Oscar > > -- > moonhkt > GMT+8 Tried below works a = "A B" karry = a.split() age[karry[0]] = age.get(karry[0], 100) + 1 age[karry[1]] = age.get(karry[1], 0) + 1 age[karry[1]] = age.get(karry[1], 0) + 1 Result A 101 B 2 From d at davea.name Wed Jan 23 17:35:18 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 17:35:18 -0500 Subject: Increase value in hash table In-Reply-To: <3ea1fef0-4a59-49f6-9e4f-ee62009bbb8e@y3g2000pbq.googlegroups.com> References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> <3ea1fef0-4a59-49f6-9e4f-ee62009bbb8e@y3g2000pbq.googlegroups.com> Message-ID: <510065A6.3010707@davea.name> On 01/23/2013 10:39 AM, moonhkt wrote: > On Jan 23, 11:33 pm, moonhk wrote: >> Works. For some definition of 'works" >> >> prndev = line.split() >> # print line >> for key in prndev : >> if key in 'lpr': This test will fire if key is the letter "l", or the letter "p", or the letter "r". Probably not what you want. Suggest you change it to if key == "lpr": >> val = prndev[5].replace("-P","") >> if val not in printque: >> printque[val] = 1 >> else: >> printque[val] = printque[val] + 1 >> if key in "/dev/null": ditto here >> val='null' >> if val not in printque: >> printque[val] = 1 >> else: >> printque[val] = printque[val] + 1 >> Of course, I don't know what prndev actually looks like, so I could be wrong as well. But I doubt it "works" as written. -- DaveA From steve+comp.lang.python at pearwood.info Wed Jan 23 05:47:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2013 10:47:51 GMT Subject: Increase value in hash table References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: <50ffbfd7$0$30003$c3e8da3$5496439d@news.astraweb.com> On Wed, 23 Jan 2013 10:12:25 +0000, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of writing that is: printque[val] = printque.get(val, 0) + 1 -- Steven From steve+comp.lang.python at pearwood.info Wed Jan 23 05:54:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 23 Jan 2013 21:54:31 +1100 Subject: Multiple postings [was Re: Increase value in hash table] References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> <50ffbfd7$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50ffc167$0$29985$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: [snip content] Arrgggh, it's happened again. Sorry for the multiple posts folks, I *swear* I only sent it once. Trying this time with a different news client. -- Steven From rustompmody at gmail.com Wed Jan 23 09:00:26 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 23 Jan 2013 06:00:26 -0800 (PST) Subject: Multiple postings [was Re: Increase value in hash table] References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> <50ffbfd7$0$30003$c3e8da3$5496439d@news.astraweb.com> <50ffc167$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <34cd32ca-9e36-40a7-ba12-7801e04c7bab@t6g2000pba.googlegroups.com> On Jan 23, 3:54?pm, Steven D'Aprano wrote: > Steven D'Aprano wrote: > > I *swear* I only sent it once. Now Now Steven! Good boys dont swear. > Arrgggh, it's happened again. Sorry for the multiple posts folks... > Trying this time with a different news client. Its a law of the universe called karma. Thou shalt double triple quadruple post for each GG user thou tickest off. And the choice for instant liberation is always there: Use GG!! From steve+comp.lang.python at pearwood.info Wed Jan 23 05:46:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2013 10:46:50 GMT Subject: Increase value in hash table References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: <50ffbf9a$0$29995$c3e8da3$5496439d@news.astraweb.com> On Wed, 23 Jan 2013 10:12:25 +0000, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of writing that is: printque[val] = printque.get(val, 0) + 1 -- Steven From steve+comp.lang.python at pearwood.info Wed Jan 23 05:46:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2013 10:46:20 GMT Subject: Increase value in hash table References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: <50ffbf7c$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 23 Jan 2013 10:12:25 +0000, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of writing that is: printque[val] = printque.get(val, 0) + 1 -- Steven From steve+comp.lang.python at pearwood.info Wed Jan 23 05:47:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2013 10:47:21 GMT Subject: Increase value in hash table References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: <50ffbfb8$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 23 Jan 2013 10:12:25 +0000, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of writing that is: printque[val] = printque.get(val, 0) + 1 -- Steven From vito.detullio at gmail.com Thu Jan 24 13:30:17 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Thu, 24 Jan 2013 19:30:17 +0100 Subject: Increase value in hash table References: <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> Message-ID: moonhkt wrote: > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 import collections with open(data_file) as f: print(collections.Counter(f.readlines())) it's a start -- ZeD From nikos.gr33k at gmail.com Wed Jan 23 07:21:55 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 04:21:55 -0800 (PST) Subject: Converting a number back to it's original string (that was hashed to generate that number) Message-ID: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Now my website finally works as intended. Just visit the following links plz. ------------------------------------------------------------------------------ 1. http://superhost.gr 2. http://superhost.gr/?show=log 3. http://i.imgur.com/89Eqmtf.png (this displays the database's column 'pin', a 5-digit number acting as a filepath indicator) 4. http://i.imgur.com/9js4Pz0.png (this is the detailed html page's information associated to 'pin' column indicator instead of something like '/home/nikos/public_html/index.html' Isn't it a nice solution? I beleive it is. but what happens when: http://superhost.gr/?show=stats I just see the number that correspons to a specific html page and hence i need to convert that number back to its original string. # ========================================================== # generating an 5-digit integer based on filepath, for to identify the current html page # ========================================================== pin = int( htmlpage.encode("hex"), 16 ) % 100000 Now i need the opposite procedure. Will hex.decode(number) convert back to the original string? I think not because this isnt a hash procedure. But how can it be done then? From lele at metapensiero.it Wed Jan 23 08:06:47 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 23 Jan 2013 14:06:47 +0100 Subject: Converting a number back to it's original string (that was hashed to generate that number) References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: <877gn459qw.fsf@metapensiero.it> Ferrous Cranus writes: > pin = int( htmlpage.encode("hex"), 16 ) % 100000 > > Now i need the opposite procedure. As already said several times by different persons in this thread, there is no way you can get the original string that originated a particular ?pin?: the function you are using is ?lossy?, that is, information gets lost in order to reduce a BIG string into a SMALL five-digits integer number. > Will hex.decode(number) convert back to the original string? NO. As people demonstrated you, you are going to meet collisions very fast, if you insist going this way (even you thought a ?smarter? way to get a checksum out of your string by using a different weight for the single characters, there is still high chances of collisions, not counting the final ?modulo? operation). Once you get such a collision, there is not enough information in that single tiny number to get back a single string that generated it. Imagine that, instead of using an integer checksum of your full path, you ?shrink? it by replacing each name in the path with its starting letter, that is: /home/ferrous/public_html/index.html => /h/f/p/i That is evidently way shorter of the original, but you LOST information, and you cannot write code in any language that eventually reproduce the original. The only way out is either use the fullpath as the primary key of your table, or using a mapping table with a bi-directional univoke mapping between any single fullpath to the corresponding "short" integer value. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From newspost2012 at gmx.de Wed Jan 23 08:24:03 2013 From: newspost2012 at gmx.de (newspost2012 at gmx.de) Date: Wed, 23 Jan 2013 05:24:03 -0800 (PST) Subject: Converting a number back to it's original string (that was hashed to generate that number) In-Reply-To: References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: please don't feed the troll. cu, Kurt From newspost2012 at gmx.de Wed Jan 23 08:24:03 2013 From: newspost2012 at gmx.de (newspost2012 at gmx.de) Date: Wed, 23 Jan 2013 05:24:03 -0800 (PST) Subject: Converting a number back to it's original string (that was hashed to generate that number) In-Reply-To: References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: please don't feed the troll. cu, Kurt From nikos.gr33k at gmail.com Wed Jan 23 08:38:00 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 05:38:00 -0800 (PST) Subject: Converting a number back to it's original string (that was hashed to generate that number) In-Reply-To: References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know) I will not create any kind of primary/unique keys to the database. I will not store the filepath into the database, just the number which indicates the filepath(html page). Also no external table associating fielpaths and numbers. i want this to be solved only by Python Code, not database oriented. That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing. But it's the % modulo that breaks the forth/back association. So, the question is: HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information? From nikos.gr33k at gmail.com Wed Jan 23 08:38:00 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 05:38:00 -0800 (PST) Subject: Converting a number back to it's original string (that was hashed to generate that number) In-Reply-To: References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know) I will not create any kind of primary/unique keys to the database. I will not store the filepath into the database, just the number which indicates the filepath(html page). Also no external table associating fielpaths and numbers. i want this to be solved only by Python Code, not database oriented. That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing. But it's the % modulo that breaks the forth/back association. So, the question is: HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information? From d at davea.name Wed Jan 23 08:58:45 2013 From: d at davea.name (Dave Angel) Date: Wed, 23 Jan 2013 08:58:45 -0500 Subject: Converting a number back to it's original string (that was hashed to generate that number) In-Reply-To: References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: <50FFEC95.6090306@davea.name> On 01/23/2013 08:38 AM, Ferrous Cranus wrote: > Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know) > I will not create any kind of primary/unique keys to the database. > I will not store the filepath into the database, just the number which indicates the filepath(html page). > Also no external table associating fielpaths and numbers. > i want this to be solved only by Python Code, not database oriented. > > > That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string > > int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing. > > But it's the % modulo that breaks the forth/back association. > > So, the question is: > > HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information? > Simple. Predefine the 100,000 legal strings, and don't let the user use anything else. One way to do that would be to require a path string of no more than 5 characters, and require them all to be of a restricted alphabet of 10 characters. (eg. the alphabet could be 0-9, which is obvious, or it could be ".aehilmpst" (no uppercase, no underscore, no digits, no non-ascii, etc.) In the realistic case of file paths or URLs, it CANNOT be done. -- DaveA From nikos.gr33k at gmail.com Wed Jan 23 10:30:49 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 07:30:49 -0800 (PST) Subject: Converting a number back to it's original string (that was hashed to generate that number) In-Reply-To: References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: ?? ???????, 23 ?????????? 2013 3:58:45 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/23/2013 08:38 AM, Ferrous Cranus wrote: > > > Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know) > > > I will not create any kind of primary/unique keys to the database. > > > I will not store the filepath into the database, just the number which indicates the filepath(html page). > > > Also no external table associating fielpaths and numbers. > > > i want this to be solved only by Python Code, not database oriented. > > > > > > > > > That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string > > > > > > int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing. > > > > > > But it's the % modulo that breaks the forth/back association. > > > > > > So, the question is: > > > > > > HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information? > > > > > > > Simple. Predefine the 100,000 legal strings, and don't let the user use > > anything else. One way to do that would be to require a path string of > > no more than 5 characters, and require them all to be of a restricted > > alphabet of 10 characters. (eg. the alphabet could be 0-9, which is > > obvious, or it could be ".aehilmpst" (no uppercase, no underscore, no > > digits, no non-ascii, etc.) > > > > In the realistic case of file paths or URLs, it CANNOT be done. OK, its not doable. I'll stop asking for it. CHANGE of plans. i will use the database solution which is the most easy wau to do it: ============================================================ # insert new page record in table counters or update it if already exists try: cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) # update existing visitor record if same pin and same host found try: cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, page, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # insert new visitor record if above update did not affect a row if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) ============================================================ I can INSERT a row to the table "counter" I cannot UPDATE or INSERT into the table "visitors" without knowing the "pin" primary key number the database created. Can you help on this please? From nikos.gr33k at gmail.com Wed Jan 23 10:30:49 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 23 Jan 2013 07:30:49 -0800 (PST) Subject: Converting a number back to it's original string (that was hashed to generate that number) In-Reply-To: References: <2c2351fb-2044-4351-af3e-63cff4fbf0f8@googlegroups.com> Message-ID: ?? ???????, 23 ?????????? 2013 3:58:45 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 01/23/2013 08:38 AM, Ferrous Cranus wrote: > > > Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know) > > > I will not create any kind of primary/unique keys to the database. > > > I will not store the filepath into the database, just the number which indicates the filepath(html page). > > > Also no external table associating fielpaths and numbers. > > > i want this to be solved only by Python Code, not database oriented. > > > > > > > > > That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string > > > > > > int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing. > > > > > > But it's the % modulo that breaks the forth/back association. > > > > > > So, the question is: > > > > > > HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information? > > > > > > > Simple. Predefine the 100,000 legal strings, and don't let the user use > > anything else. One way to do that would be to require a path string of > > no more than 5 characters, and require them all to be of a restricted > > alphabet of 10 characters. (eg. the alphabet could be 0-9, which is > > obvious, or it could be ".aehilmpst" (no uppercase, no underscore, no > > digits, no non-ascii, etc.) > > > > In the realistic case of file paths or URLs, it CANNOT be done. OK, its not doable. I'll stop asking for it. CHANGE of plans. i will use the database solution which is the most easy wau to do it: ============================================================ # insert new page record in table counters or update it if already exists try: cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) # update existing visitor record if same pin and same host found try: cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, page, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # insert new visitor record if above update did not affect a row if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) ============================================================ I can INSERT a row to the table "counter" I cannot UPDATE or INSERT into the table "visitors" without knowing the "pin" primary key number the database created. Can you help on this please? From software at gmgsistemi.it Wed Jan 23 11:42:33 2013 From: software at gmgsistemi.it (Rep. Software - GMG Sistemi Srl) Date: Wed, 23 Jan 2013 17:42:33 +0100 Subject: PDF/A with pyPDF Message-ID: <810DB3E0D542497492F40ECAE9FEA4D6@gmgsistemi.loc> Hi all, I wonder if pyPDF module can manage PDF/A format of PDF... Can anyone tell me? thank you!! =================================================== Davide Scatto Resp. Gestionale Gulliver GMG SISTEMI SRL Via Belluno, 43-45 30035 Mirano (VE) e-mail: software at gmgsistemi.it Tel.: 041/5703131 (r.a.) Fax: 041/5703006 P.I. e C.F. 02938960271 Reg. Imp. VE 02938960271 R.E.A. C.C.I.A.A. VE n. 251319 Cap. Soc. Euro 50.000 i.v. =================================================== INFORMAZIONI STRETTAMENTE CONFIDENZIALI: L'invio di questa e-mail ? destinato solo ad uso personale o a enti sopra nominati e potrebbe contenere informazioni riservate, coperte da segreto professionale, e non soggette a divulgazione ai sensi di legge. Se non ne siete i corretti destinatari, con la presente siete informati che non vi ? assolutamente permessa alcuna divulgazione, copia, distribuzione, o altro uso delle informazioni in essa contenute. Se per errore avete ricevuto questo messaggio, Vi chiedo cortesemente di informarci immediatamente al nostro indirizzo di posta elettronica. Grazie -------------- next part -------------- An HTML attachment was scrubbed... URL: From spek06 at gmail.com Wed Jan 23 14:05:31 2013 From: spek06 at gmail.com (spek06 at gmail.com) Date: Wed, 23 Jan 2013 11:05:31 -0800 (PST) Subject: Search log for string and display hourly/daily report Message-ID: <4f952e77-258d-47ae-9d76-a86daa8acaa2@googlegroups.com> I need to search a log file for a specific string (Successfully Sent) and report the number of instances in the last hour (from when executed) and total for the day so far (midnight till the time executed). Can anyone provide any examples of such a program or get me started? From python.list at tim.thechases.com Wed Jan 23 15:08:19 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 23 Jan 2013 14:08:19 -0600 Subject: Search log for string and display hourly/daily report In-Reply-To: <4f952e77-258d-47ae-9d76-a86daa8acaa2@googlegroups.com> References: <4f952e77-258d-47ae-9d76-a86daa8acaa2@googlegroups.com> Message-ID: <51004333.30103@tim.thechases.com> On 01/23/13 13:05, spek06 at gmail.com wrote: > I need to search a log file for a specific string (Successfully > Sent) and report the number of instances in the last hour (from > when executed) and total for the day so far (midnight till the > time executed). Can anyone provide any examples of such a program > or get me started? You'd have to specify additional details on how the log-file is formatted, presumably how it's delimited, and what the format of the corresponding time-stamp is. Something like "I have a tab-delimited log file where the 4th column is the timestamp in the format 'YYYY-MM-DD HH:mm:ss' and the 18th column is the status. I want to search for items where the status contains 'Successfully Sent' and then further filter them by (1) events in the last hour, and (2) all events today" -tkc From gordon at panix.com Wed Jan 23 16:25:59 2013 From: gordon at panix.com (John Gordon) Date: Wed, 23 Jan 2013 21:25:59 +0000 (UTC) Subject: Search log for string and display hourly/daily report References: <4f952e77-258d-47ae-9d76-a86daa8acaa2@googlegroups.com> Message-ID: In <4f952e77-258d-47ae-9d76-a86daa8acaa2 at googlegroups.com> spek06 at gmail.com writes: > I need to search a log file for a specific string (Successfully Sent) and > report the number of instances in the last hour (from when executed) and > total for the day so far (midnight till the time executed). Can anyone > provide any examples of such a program or get me started? from datetime import datetime, timedelta from time import mktime, strptime now = datetime.now() midnight = now.replace(hour=0, minute=0, second=0, microsecond=0) one_hour_ago = now - timedelta(hours=1) daily_instances = 0 hourly_instances = 0 with open('myfile.log') as logfile: for line in logfile: if 'Successfully Sent' in line: time_string = line[0:19] struct = strptime(time_string, "%Y-%m-%dT%H:%M:%S") log_time = datetime.fromtimestamp(mktime(struct)) if log_time > midnight: daily_instances += 1 if log_time > one_hour_ago: hourly_instances += 1 print "Instances in the last hour: ", hourly_instances print "Instances since midnight: ", daily_instances This code assumes that log lines begin with a timestamp similar to "2013-01-23T09:27:01". If the timestamp is in a different format, or occurs elsewhere in the line, you'll have to adjust for that. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From spek06 at gmail.com Wed Jan 23 19:57:50 2013 From: spek06 at gmail.com (spek06 at gmail.com) Date: Wed, 23 Jan 2013 16:57:50 -0800 (PST) Subject: Search log for string and display hourly/daily report In-Reply-To: References: <4f952e77-258d-47ae-9d76-a86daa8acaa2@googlegroups.com> Message-ID: <2fc8e789-2c0b-4f4f-bb1e-e0381398583b@googlegroups.com> On Wednesday, January 23, 2013 4:25:59 PM UTC-5, John Gordon wrote: > In <4f952e77-258d-47ae-9d76-a86daa8acaa2 at googlegroups.com> spek06 writes: > > > > > I need to search a log file for a specific string (Successfully Sent) and > > > report the number of instances in the last hour (from when executed) and > > > total for the day so far (midnight till the time executed). Can anyone > > > provide any examples of such a program or get me started? > > > > from datetime import datetime, timedelta > > from time import mktime, strptime > > > > now = datetime.now() > > midnight = now.replace(hour=0, minute=0, second=0, microsecond=0) > > one_hour_ago = now - timedelta(hours=1) > > > > daily_instances = 0 > > hourly_instances = 0 > > > > with open('myfile.log') as logfile: > > for line in logfile: > > if 'Successfully Sent' in line: > > time_string = line[0:19] > > struct = strptime(time_string, "%Y-%m-%dT%H:%M:%S") > > log_time = datetime.fromtimestamp(mktime(struct)) > > > > if log_time > midnight: > > daily_instances += 1 > > > > if log_time > one_hour_ago: > > hourly_instances += 1 > > > > print "Instances in the last hour: ", hourly_instances > > print "Instances since midnight: ", daily_instances > > > > > > This code assumes that log lines begin with a timestamp similar to > > "2013-01-23T09:27:01". If the timestamp is in a different format, or > > occurs elsewhere in the line, you'll have to adjust for that. > > > > -- > > John Gordon A is for Amy, who fell down the stairs > > B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies" Thanks John, I think this will definitely help get me started! From torriem at gmail.com Wed Jan 23 17:12:30 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 23 Jan 2013 15:12:30 -0700 Subject: Search log for string and display hourly/daily report In-Reply-To: <4f952e77-258d-47ae-9d76-a86daa8acaa2@googlegroups.com> References: <4f952e77-258d-47ae-9d76-a86daa8acaa2@googlegroups.com> Message-ID: <5100604E.5050208@gmail.com> On 01/23/2013 12:05 PM, spek06 at gmail.com wrote: > I need to search a log file for a specific string (Successfully Sent) > and report the number of instances in the last hour (from when > executed) and total for the day so far (midnight till the time > executed). Can anyone provide any examples of such a program or get > me started? Take a look at this very interesting presentation/document: http://www.dabeaz.com/generators/ From nick.cash at npcinternational.com Wed Jan 23 15:07:56 2013 From: nick.cash at npcinternational.com (Nick Cash) Date: Wed, 23 Jan 2013 20:07:56 +0000 Subject: urllib2 FTP Weirdness Message-ID: <846C3A8E860C4344B567D813B63AA51D6F905ED8@BL2PRD0610MB349.namprd06.prod.outlook.com> Python 2.7.3 on linux This has me fairly stumped. It looks like urllib2.urlopen("ftp://some.ftp.site/path").read() will either immediately return '' or hang indefinitely. But response = urllib2.urlopen("ftp://some.ftp.site/path") response.read() works fine and returns what is expected. This is only an issue with urllib2, vanilla urllib doesn't do it. The site I first noticed it on is private, but I can reproduce it with "ftp://ftp2.census.gov/". I've tested the equivalent code on Python 3.2.3 and get the same results, except that one time I got a socket error (may have been a spurious network blip, though). I'm at a loss as to how that could even work differently. My only guess is that by not having a reference to the addinfourl response object, something important is getting garbage collected or closed... that seems like a stretch, though. Is this a urllib2 bug, or am I crazy? -Nick Cash From rosuav at gmail.com Wed Jan 23 18:58:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 10:58:04 +1100 Subject: urllib2 FTP Weirdness In-Reply-To: <846C3A8E860C4344B567D813B63AA51D6F905ED8@BL2PRD0610MB349.namprd06.prod.outlook.com> References: <846C3A8E860C4344B567D813B63AA51D6F905ED8@BL2PRD0610MB349.namprd06.prod.outlook.com> Message-ID: On Thu, Jan 24, 2013 at 7:07 AM, Nick Cash wrote: > Python 2.7.3 on linux > > This has me fairly stumped. It looks like > urllib2.urlopen("ftp://some.ftp.site/path").read() > will either immediately return '' or hang indefinitely. But > response = urllib2.urlopen("ftp://some.ftp.site/path") > response.read() > works fine and returns what is expected. This is only an issue with urllib2, vanilla urllib doesn't do it. > > The site I first noticed it on is private, but I can reproduce it with "ftp://ftp2.census.gov/". Confirmed on 2.6.5 on Windows, fwiw. This is extremely weird. Possibly it's some kind of race condition?? ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 23 19:41:44 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 24 Jan 2013 11:41:44 +1100 Subject: urllib2 FTP Weirdness References: Message-ID: <51008349$0$9505$c3e8da3$5496439d@news.astraweb.com> Nick Cash wrote: > Python 2.7.3 on linux > > This has me fairly stumped. It looks like > urllib2.urlopen("ftp://some.ftp.site/path").read() > will either immediately return '' or hang indefinitely. But > response = urllib2.urlopen("ftp://some.ftp.site/path") > response.read() > works fine and returns what is expected. This is only an issue with > urllib2, vanilla urllib doesn't do it. > > The site I first noticed it on is private, but I can reproduce it with > "ftp://ftp2.census.gov/". Then why not give that in your example, to make running your code easier? :-) I cannot reproduce the problem: py> import urllib2 py> x = urllib2.urlopen("ftp://ftp2.census.gov/").read() py> len(x) 5550 Works fine for me using Python 2.7.2 on Linux. I cannot see how the two snippets you give could possibly be different. If you are using a proxy, what happens if you bypass it? If you can reproduce this at will, with and without proxy, with multiple sites, then I suppose it is conceivable that it could be some sort of bug. But I wouldn't bet on it. -- Steven From hansmu at xs4all.nl Wed Jan 23 19:45:31 2013 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 24 Jan 2013 01:45:31 +0100 Subject: urllib2 FTP Weirdness In-Reply-To: References: <846C3A8E860C4344B567D813B63AA51D6F905ED8@BL2PRD0610MB349.namprd06.prod.outlook.com> Message-ID: <51008432$0$6940$e4fe514c@news2.news.xs4all.nl> On 24/01/13 00:58:04, Chris Angelico wrote: > On Thu, Jan 24, 2013 at 7:07 AM, Nick Cash > wrote: >> Python 2.7.3 on linux >> >> This has me fairly stumped. It looks like >> urllib2.urlopen("ftp://some.ftp.site/path").read() >> will either immediately return '' or hang indefinitely. But >> response = urllib2.urlopen("ftp://some.ftp.site/path") >> response.read() >> works fine and returns what is expected. This is only an issue with urllib2, vanilla urllib doesn't do it. >> >> The site I first noticed it on is private, but I can reproduce it with "ftp://ftp2.census.gov/". > > Confirmed on 2.6.5 on Windows, fwiw. This is extremely weird. It works fine with 2.7.3 on my Mac. > Possibly it's some kind of race condition?? If urllib2 is using active mode FTP, then a firewall on your box could explain what you're seeing. But then, that's why active mode is hardly used these days. Hope this helps, -- HansM From steve+comp.lang.python at pearwood.info Wed Jan 23 23:12:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Jan 2013 04:12:16 GMT Subject: urllib2 FTP Weirdness References: <846C3A8E860C4344B567D813B63AA51D6F905ED8@BL2PRD0610MB349.namprd06.prod.outlook.com> <51008432$0$6940$e4fe514c@news2.news.xs4all.nl> Message-ID: <5100b4a0$0$29877$c3e8da3$5496439d@news.astraweb.com> On Thu, 24 Jan 2013 01:45:31 +0100, Hans Mulder wrote: > On 24/01/13 00:58:04, Chris Angelico wrote: >> On Thu, Jan 24, 2013 at 7:07 AM, Nick Cash >> wrote: >>> Python 2.7.3 on linux >>> >>> This has me fairly stumped. It looks like >>> urllib2.urlopen("ftp://some.ftp.site/path").read() >>> will either immediately return '' or hang indefinitely. But >>> response = urllib2.urlopen("ftp://some.ftp.site/path") >>> response.read() >>> works fine and returns what is expected. This is only an issue with >>> urllib2, vanilla urllib doesn't do it. >>> >>> The site I first noticed it on is private, but I can reproduce it with >>> "ftp://ftp2.census.gov/". >> >> Confirmed on 2.6.5 on Windows, fwiw. This is extremely weird. > > It works fine with 2.7.3 on my Mac. > >> Possibly it's some kind of race condition?? > > If urllib2 is using active mode FTP, then a firewall on your box could > explain what you're seeing. But then, that's why active mode is hardly > used these days. Explain please? I cannot see how the firewall could possible distinguish between using a temporary variable or not in these two snippets: # no temporary variable hangs, or fails urllib2.urlopen("ftp://ftp2.census.gov/").read() # temporary variable succeeds response = urllib2.urlopen("ftp://ftp2.census.gov/") response.read() -- Steven From gauravj123 at gmail.com Wed Jan 23 16:56:22 2013 From: gauravj123 at gmail.com (Coolgg) Date: Wed, 23 Jan 2013 13:56:22 -0800 (PST) Subject: Arent these snippets equivalent? Message-ID: Is this: while True: data = fp.read(4096) if not data: break ... not equivalent to this: data = fp.read (4096) while data: ...{handle the chunk here} data = fp.read (4096) Heres the article that sparked this question: http://wordaligned.org/articles/pythons-lesser-known-loop-control From gordon at panix.com Wed Jan 23 17:06:24 2013 From: gordon at panix.com (John Gordon) Date: Wed, 23 Jan 2013 22:06:24 +0000 (UTC) Subject: Arent these snippets equivalent? References: Message-ID: In Coolgg writes: > Is this: > while True: > data = fp.read(4096) > if not data: > break > ... > not equivalent to this: > data = fp.read (4096) > while data: > ...{handle the chunk here} > data = fp.read (4096) It looks equivalent to me (in terms of control flow). But in the second example the fp.read() statement is duplicated, which is undesirable. It would be all too easy for a maintenance programmer to go into the code a year from now and change the first one but miss the second one. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Wed Jan 23 17:13:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 09:13:14 +1100 Subject: Arent these snippets equivalent? In-Reply-To: References: Message-ID: On Thu, Jan 24, 2013 at 8:56 AM, Coolgg wrote: > Is this: > > while True: > data = fp.read(4096) > if not data: > break > ... > > not equivalent to this: > > data = fp.read (4096) > while data: > ...{handle the chunk here} > data = fp.read (4096) They should do the same thing, but there's one critical difference in the second: Edits to something that's really part of the loop now have to be done twice, at the bottom of the loop and *before the loop*. It's a violation of the principle Don't Repeat Yourself. Personally, I'd much rather have a 'while' condition that does assignment, but that's something Python's unlikely ever to do. There've been various proposals to make that possible, but ultimately the only way to make that work is for assignment to be an expression, which is right up there alongside braces defining blocks. (Wonder when we'll see "from __future__ import assignment_expression" implemented...) The 'break' method is the most common. Assuming you're doing something as simple as the above, with a single function call and a clear condition, it's pretty readable. Compare: while (data = fp.read(4096)) { ... imagine about 20 lines here } and while True: data = fp.read(4096) if not data: break ... imagine those same 20 lines, ported to Python The critical parts of your while loop are in those first three lines. It's the same goal as a C-style for loop - you can see everything you need right up there at the loop header. All you have to do is understand that the "loop header" is three lines long now. With the second form of the loop, though, the loop header is down at the bottom of the loop too. It's less clear. Granted, this might be how a compiler lays it out in memory, but programmers shouldn't have to read it that way. ChrisA From roy at panix.com Wed Jan 23 17:47:55 2013 From: roy at panix.com (Roy Smith) Date: Wed, 23 Jan 2013 17:47:55 -0500 Subject: Arent these snippets equivalent? References: Message-ID: In article , Chris Angelico wrote: > Personally, I'd much rather have a 'while' condition that does > assignment, but that's something Python's unlikely ever to do. > There've been various proposals to make that possible, but ultimately > the only way to make that work is for assignment to be an expression, > which is right up there alongside braces defining blocks. while getchar() as c: putchar(c) That would give people (including me) the use case they're after most of the time (call a function, assign the return value, and test it). It's way less klunky than: while True: c = getchar() if c: break putchar() It wouldn't require assignment as an expression, or braces, or any new keywords. It would also be quite analogous to try: blah() except BogusThing as ex: whatever() in both cases, the effect is "perform some action, grab a value which resulted from that, and if it passes some test, make it available in the next block bound to a name". From python.list at tim.thechases.com Wed Jan 23 18:29:47 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 23 Jan 2013 17:29:47 -0600 Subject: Arent these snippets equivalent? In-Reply-To: References: Message-ID: <5100726B.2050300@tim.thechases.com> On 01/23/13 16:47, Roy Smith wrote: > while getchar() as c: > putchar(c) > > That would give people (including me) the use case they're after most of > the time (call a function, assign the return value, and test it). It's > way less klunky than: > > while True: > c = getchar() > if c: # I presume you mean "if not c:" here. > break > putchar() I was a pretty strong advocate early in one of these long threads, and for the simple cases, it's some attractive syntactic sugar. However, I found that it quickly blossomed into a lot of really ugly edge cases (multiple tests, multiple results, checking for "is None" vs. false'ness or some other condition such as "< 0"). I found that it was pretty easy to create a generator-wrapper for this: def getter(fn): while True: val = fn() if not val: break yield val # DB example cursor = conn.cursor() for row in getter(lambda: cursor.fetchmany()): do_something(row) # your getchar example for c in getter(getchar): do_something_else(c) This allowed me to have both the readability and customized tests (and the ability to return multiple values). It could be expanded with def getter(fn, is_at_end=lambda v: not v): while True: val = fn() if is_at_end(val): break yield val which would even allow you to do things like for line in getter(file("foo.txt"), lambda s: s.find("xxx") < 0): print "This line has 'xxx' in it:" print line and those felt a lot more pythonic than any of the proposals I saw on the list. -tkc From tjreedy at udel.edu Wed Jan 23 21:38:54 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 23 Jan 2013 21:38:54 -0500 Subject: Arent these snippets equivalent? In-Reply-To: <5100726B.2050300@tim.thechases.com> References: <5100726B.2050300@tim.thechases.com> Message-ID: On 1/23/2013 6:29 PM, Tim Chase wrote: > On 01/23/13 16:47, Roy Smith wrote: >> while getchar() as c: >> putchar(c) >> >> That would give people (including me) the use case they're after most of >> the time (call a function, assign the return value, and test it). It's >> way less klunky than: >> >> while True: >> c = getchar() >> if c: > # I presume you mean "if not c:" here. >> break >> putchar() > > I was a pretty strong advocate early in one of these long threads, and > for the simple cases, it's some attractive syntactic sugar. However, I > found that it quickly blossomed into a lot of really ugly edge cases > (multiple tests, multiple results, checking for "is None" vs. false'ness > or some other condition such as "< 0"). I found that it was pretty easy > to create a generator-wrapper for this: > > def getter(fn): > while True: > val = fn() > if not val: break > yield val > > # DB example > cursor = conn.cursor() > for row in getter(lambda: cursor.fetchmany()): > do_something(row) > > # your getchar example > for c in getter(getchar): > do_something_else(c) > > This allowed me to have both the readability and customized tests (and > the ability to return multiple values). It could be expanded with > > def getter(fn, is_at_end=lambda v: not v): > while True: > val = fn() > if is_at_end(val): break > yield val > > which would even allow you to do things like > > for line in getter(file("foo.txt"), lambda s: s.find("xxx") < 0): > print "This line has 'xxx' in it:" > print line > > and those felt a lot more pythonic than any of the proposals I saw on > the list. I agree. To me, the beauty of iterators and for loops is that they separate production of the items of a collection from the processing of the same items. The two processes are often quite independent, and separating them clearly allows us to mix and match. For instance, when summing numbers, the internal details of producing the numbers does not matter. -- Terry Jan Reedy From gauravj123 at gmail.com Thu Jan 24 00:01:37 2013 From: gauravj123 at gmail.com (Coolgg) Date: Wed, 23 Jan 2013 21:01:37 -0800 (PST) Subject: Arent these snippets equivalent? In-Reply-To: References: <5100726B.2050300@tim.thechases.com> Message-ID: On Wednesday, January 23, 2013 6:38:54 PM UTC-8, Terry Reedy wrote: > On 1/23/2013 6:29 PM, Tim Chase wrote: > > > On 01/23/13 16:47, Roy Smith wrote: > > >> while getchar() as c: > > >> putchar(c) > > >> > > >> That would give people (including me) the use case they're after most of > > >> the time (call a function, assign the return value, and test it). It's > > >> way less klunky than: > > >> > > >> while True: > > >> c = getchar() > > >> if c: > > > # I presume you mean "if not c:" here. > > >> break > > >> putchar() > > > > > > I was a pretty strong advocate early in one of these long threads, and > > > for the simple cases, it's some attractive syntactic sugar. However, I > > > found that it quickly blossomed into a lot of really ugly edge cases > > > (multiple tests, multiple results, checking for "is None" vs. false'ness > > > or some other condition such as "< 0"). I found that it was pretty easy > > > to create a generator-wrapper for this: > > > > > > def getter(fn): > > > while True: > > > val = fn() > > > if not val: break > > > yield val > > > > > > # DB example > > > cursor = conn.cursor() > > > for row in getter(lambda: cursor.fetchmany()): > > > do_something(row) > > > > > > # your getchar example > > > for c in getter(getchar): > > > do_something_else(c) > > > > > > This allowed me to have both the readability and customized tests (and > > > the ability to return multiple values). It could be expanded with > > > > > > def getter(fn, is_at_end=lambda v: not v): > > > while True: > > > val = fn() > > > if is_at_end(val): break > > > yield val > > > > > > which would even allow you to do things like > > > > > > for line in getter(file("foo.txt"), lambda s: s.find("xxx") < 0): > > > print "This line has 'xxx' in it:" > > > print line > > > > > > and those felt a lot more pythonic than any of the proposals I saw on > > > the list. > > > > I agree. To me, the beauty of iterators and for loops is that they > > separate production of the items of a collection from the processing of > > the same items. The two processes are often quite independent, and > > separating them clearly allows us to mix and match. For instance, when > > summing numbers, the internal details of producing the numbers does not > > matter. > > > > -- > > Terry Jan Reedy Thanks for all the perspectives everyone. I was just curious about the functional equivalence and I got what I needed. From gauravj123 at gmail.com Thu Jan 24 00:01:37 2013 From: gauravj123 at gmail.com (Coolgg) Date: Wed, 23 Jan 2013 21:01:37 -0800 (PST) Subject: Arent these snippets equivalent? In-Reply-To: References: <5100726B.2050300@tim.thechases.com> Message-ID: On Wednesday, January 23, 2013 6:38:54 PM UTC-8, Terry Reedy wrote: > On 1/23/2013 6:29 PM, Tim Chase wrote: > > > On 01/23/13 16:47, Roy Smith wrote: > > >> while getchar() as c: > > >> putchar(c) > > >> > > >> That would give people (including me) the use case they're after most of > > >> the time (call a function, assign the return value, and test it). It's > > >> way less klunky than: > > >> > > >> while True: > > >> c = getchar() > > >> if c: > > > # I presume you mean "if not c:" here. > > >> break > > >> putchar() > > > > > > I was a pretty strong advocate early in one of these long threads, and > > > for the simple cases, it's some attractive syntactic sugar. However, I > > > found that it quickly blossomed into a lot of really ugly edge cases > > > (multiple tests, multiple results, checking for "is None" vs. false'ness > > > or some other condition such as "< 0"). I found that it was pretty easy > > > to create a generator-wrapper for this: > > > > > > def getter(fn): > > > while True: > > > val = fn() > > > if not val: break > > > yield val > > > > > > # DB example > > > cursor = conn.cursor() > > > for row in getter(lambda: cursor.fetchmany()): > > > do_something(row) > > > > > > # your getchar example > > > for c in getter(getchar): > > > do_something_else(c) > > > > > > This allowed me to have both the readability and customized tests (and > > > the ability to return multiple values). It could be expanded with > > > > > > def getter(fn, is_at_end=lambda v: not v): > > > while True: > > > val = fn() > > > if is_at_end(val): break > > > yield val > > > > > > which would even allow you to do things like > > > > > > for line in getter(file("foo.txt"), lambda s: s.find("xxx") < 0): > > > print "This line has 'xxx' in it:" > > > print line > > > > > > and those felt a lot more pythonic than any of the proposals I saw on > > > the list. > > > > I agree. To me, the beauty of iterators and for loops is that they > > separate production of the items of a collection from the processing of > > the same items. The two processes are often quite independent, and > > separating them clearly allows us to mix and match. For instance, when > > summing numbers, the internal details of producing the numbers does not > > matter. > > > > -- > > Terry Jan Reedy Thanks for all the perspectives everyone. I was just curious about the functional equivalence and I got what I needed. From rosuav at gmail.com Wed Jan 23 18:29:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 10:29:06 +1100 Subject: Arent these snippets equivalent? In-Reply-To: References: Message-ID: On Thu, Jan 24, 2013 at 9:47 AM, Roy Smith wrote: > while getchar() as c: > putchar(c) > > That would give people (including me) the use case they're after most of > the time (call a function, assign the return value, and test it). It's > way less klunky than: > > while True: > c = getchar() > if c: > break > putchar() > > It wouldn't require assignment as an expression, or braces, or any new > keywords. I believe this was discussed recently (on python-ideas?). It's nice in its simplest form, but doesn't cover all possibilities. My point about braces was that, like assignment-expressions, it's a feature that Python will not be implementing. Fundamentally against the "push" of the language. If you want C, you know where to get it. (There are other options, of course; ECMAScript and Pike come to mind. But you know what I mean.) ChrisA From driscoll at cs.wisc.edu Wed Jan 23 18:17:45 2013 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 23 Jan 2013 17:17:45 -0600 Subject: Arent these snippets equivalent? In-Reply-To: References: Message-ID: <51006F99.7070104@cs.wisc.edu> On 01/23/2013 03:56 PM, Coolgg wrote: > Is this: > > while True: > data = fp.read(4096) > if not data: > break > ... > > not equivalent to this: > > data = fp.read (4096) > while data: > ...{handle the chunk here} > data = fp.read (4096) > > Heres the article that sparked this question: > http://wordaligned.org/articles/pythons-lesser-known-loop-control There is at least one potentially-critical difference: what happens if there is a 'continue' statement in the "..." part. The upper loop will set data again, while the lower one will not. So if what you mean is "are they equivalent no matter what legal Python code you put in the ...", no, they aren't. Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 554 bytes Desc: OpenPGP digital signature URL: From andrew3 at r3dsolutions.com Wed Jan 23 10:22:23 2013 From: andrew3 at r3dsolutions.com (Andrew Robinson) Date: Wed, 23 Jan 2013 15:22:23 +0000 Subject: XML/XHTML/HTML differences, bugs... and howto Message-ID: <5100002F.7020809@r3dsolutions.com> Good day :), I've been exploring XML parsers in python; particularly: xml.etree.cElementTree; and I'm trying to figure out how to do it incrementally, for very large XML files -- although I don't think the problems are restricted to incremental parsing. First problem: I've come across an issue where etree silently drops text without telling me; and separate. I am under the impression that XHTML is a subset of XML (eg:defined tags), and that once an HTML file is converted to XHTML, the body of the document can be handled entirely as XML. If I convert a (partial/contrived) html file like:

This is example bold text.

to XHTML, I might do --right or wrong-- (1):

This is example bold text.

or, alternate difference: (2): "

This is example bold text.

" But, when I parse with etree, in example (1) both "This is an example" and "text." are dropped; The missing text is part of the start, or end event tags, in the incrementally parsed method. Likewise: In example (2), only "text" gets dropped. So, etree is silently dropping all text following a close tag, but before another open tag happens. Q: Isn't XML supposed to error out when invalid xml is parsed? Is there a way in etree to recover/access the dropped text? If not -- is the a python library issue, or the underlying expat.so, etc. library. Secondly; I have an XML file which will grow larger than memory on a target machine, so here's what I want to do: Given a source XML file, and a destination file: 1) iteratively scan part of the source tree. 2) Optionally Modify some of scanned tree. 3) Write partial scan/tree out to the destination file. 4) Free memory of no-longer needed (partial) source XML. 5) continue scanning a new section of the source file... eg: goto step 1 until source file is exhausted. But, I don't see a way to write portions of an XML tree, or iteratively write a tree to disk. How can this be done? :) Thanks! From stefan_ml at behnel.de Thu Jan 24 01:42:22 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 24 Jan 2013 07:42:22 +0100 Subject: XML/XHTML/HTML differences, bugs... and howto In-Reply-To: <5100002F.7020809@r3dsolutions.com> References: <5100002F.7020809@r3dsolutions.com> Message-ID: Andrew Robinson, 23.01.2013 16:22: > Good day :), > > I've been exploring XML parsers in python; particularly: > xml.etree.cElementTree; and I'm trying to figure out how to do it > incrementally, for very large XML files -- although I don't think the > problems are restricted to incremental parsing. > > First problem: > I've come across an issue where etree silently drops text without telling > me; and separate. > > I am under the impression that XHTML is a subset of XML (eg:defined tags), > and that once an HTML file is converted to XHTML, the body of the document > can be handled entirely as XML. > > If I convert a (partial/contrived) html file like: > > >
>

This is example bold text. >

> > > to XHTML, I might do --right or wrong-- (1): > > >
>

This is example bold text. >

> > > or, alternate difference: (2): "

This is example bold text.

" > > But, when I parse with etree, in example (1) both "This is an example" and > "text." are dropped; > The missing text is part of the start, or end event tags, in the > incrementally parsed method. > > Likewise: In example (2), only "text" gets dropped. Nope, you should read the manual on this. Here's a tutorial: http://lxml.de/tutorial.html#elements-contain-text This is using lxml.etree, which is the Python XML library most people use these days. It's ElementTree compatible, so the tutorial also works for ET (unless stated otherwise). > Isn't XML supposed to error out when invalid xml is parsed? It does. > I have an XML file which will grow larger than memory on a target machine, > so here's what I want to do: > > Given a source XML file, and a destination file: > 1) iteratively scan part of the source tree. > 2) Optionally Modify some of scanned tree. > 3) Write partial scan/tree out to the destination file. > 4) Free memory of no-longer needed (partial) source XML. > 5) continue scanning a new section of the source file... eg: goto step 1 > until source file is exhausted. > > But, I don't see a way to write portions of an XML tree, or iteratively > write a tree to disk. > How can this be done? There are several ways to do it. Python has a couple of external libraries available that are made specifically for generating markup incrementally. lxml also gained that feature recently. It's not documented yet, but here are usage examples: https://github.com/lxml/lxml/blob/master/src/lxml/tests/test_incremental_xmlfile.py Stefan From andrew3 at r3dsolutions.com Wed Jan 23 18:32:48 2013 From: andrew3 at r3dsolutions.com (Andrew Robinson) Date: Wed, 23 Jan 2013 23:32:48 +0000 Subject: XML/XHTML/HTML differences, bugs... and howto In-Reply-To: References: <5100002F.7020809@r3dsolutions.com> Message-ID: <51007320.6050608@r3dsolutions.com> On 01/24/2013 06:42 AM, Stefan Behnel wrote: > Andrew Robinson, 23.01.2013 16:22: >> Good day :), > Nope, you should read the manual on this. Here's a tutorial: > > http://lxml.de/tutorial.html#elements-contain-text I see, so it should be under the "tail" attribute, not the "text" attribute. That's why I missed it. >> >> But, I don't see a way to write portions of an XML tree, or iteratively >> write a tree to disk. >> How can this be done? > There are several ways to do it. Python has a couple of external libraries > available that are made specifically for generating markup incrementally. > > lxml also gained that feature recently. It's not documented yet, but here > are usage examples: > > https://github.com/lxml/lxml/blob/master/src/lxml/tests/test_incremental_xmlfile.py > > Stefan Thanks Stefan ! I'll look that over. :) From matt17 at gmail.com Wed Jan 23 23:39:10 2013 From: matt17 at gmail.com (Milter Skyler) Date: Wed, 23 Jan 2013 20:39:10 -0800 (PST) Subject: Decrease for loop by one Message-ID: <7694aab5-7926-482e-975a-7685c7b94351@googlegroups.com> I'm using this code with Sikuli so thats why I have click() for x in range(0,10): decimal_value = random.randint(1,12) if myList.count(decimal_value) < 1: egg = 'A%d.png' % (decimal_value) egg = wait(egg) click(egg.getCenter().offset(random.randint(-10,10), random.randint(-10,10))) myList.append(decimal_value) else: print x x-1 = x print x I made an array to check if the random integer already exists and then I send it to the else statement at which point I want to decrease x by 1 so that it doesn't count as one of the loops. In other languages this works but it just comes up with the output: 3 2 9 8 10 9 From rosuav at gmail.com Wed Jan 23 23:59:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 15:59:13 +1100 Subject: Decrease for loop by one In-Reply-To: <7694aab5-7926-482e-975a-7685c7b94351@googlegroups.com> References: <7694aab5-7926-482e-975a-7685c7b94351@googlegroups.com> Message-ID: On Thu, Jan 24, 2013 at 3:39 PM, Milter Skyler wrote: > I made an array to check if the random integer already exists and then I send it to the else statement at which point I want to decrease x by 1 so that it doesn't count as one of the loops. In other languages this works... A Python 'for' loop doesn't behave like that; you can't just edit the loop counter. But take a step back: what are you actually trying to accomplish? As I see it, you're trying to pick ten unique random values in the range 1-12 inclusive. Try this: random.sample(range(1,13),10) # note that range() stops *before* its second arg That'll give you a list of those integers, and it's a lot safer and more reliable than the try-fail-retry method. Your loop can become: for decimal_value in random.sample(range(1,13),10): egg = 'A%d.png' % (decimal_value) egg = wait(egg) click(egg.getCenter().offset(random.randint(-10,10), random.randint(-10,10))) By the way, this line simply won't work: x-1 = x I think you mean: x = x-1 But I strongly suggest you copy and paste directly rather than retype; it's less error-prone. Hope that helps! ChrisA From matt17 at gmail.com Thu Jan 24 00:10:37 2013 From: matt17 at gmail.com (Milter Skyler) Date: Wed, 23 Jan 2013 21:10:37 -0800 (PST) Subject: Decrease for loop by one In-Reply-To: References: <7694aab5-7926-482e-975a-7685c7b94351@googlegroups.com> Message-ID: <24b5f5ee-f88f-45a1-9c12-f3381209b647@googlegroups.com> On Wednesday, January 23, 2013 9:59:13 PM UTC-7, Chris Angelico wrote: > On Thu, Jan 24, 2013 at 3:39 PM, Milter Skyler <> wrote: > > > I made an array to check if the random integer already exists and then I send it to the else statement at which point I want to decrease x by 1 so that it doesn't count as one of the loops. In other languages this works... > > > > A Python 'for' loop doesn't behave like that; you can't just edit the > > loop counter. But take a step back: what are you actually trying to > > accomplish? As I see it, you're trying to pick ten unique random > > values in the range 1-12 inclusive. Try this: > > > > random.sample(range(1,13),10) # note that range() stops *before* its second arg > > > > That'll give you a list of those integers, and it's a lot safer and > > more reliable than the try-fail-retry method. Your loop can become: > > > > for decimal_value in random.sample(range(1,13),10): > > egg = 'A%d.png' % (decimal_value) > > egg = wait(egg) > > click(egg.getCenter().offset(random.randint(-10,10), > > random.randint(-10,10))) > > > > By the way, this line simply won't work: > > > > x-1 = x > > > > I think you mean: > > > > x = x-1 > > > > But I strongly suggest you copy and paste directly rather than retype; > > it's less error-prone. > > > > Hope that helps! > > > > ChrisA Thanks! That worked perfect, I was trying to figure that out but instead I just went down the hard route I went down. From matt17 at gmail.com Thu Jan 24 00:10:37 2013 From: matt17 at gmail.com (Milter Skyler) Date: Wed, 23 Jan 2013 21:10:37 -0800 (PST) Subject: Decrease for loop by one In-Reply-To: References: <7694aab5-7926-482e-975a-7685c7b94351@googlegroups.com> Message-ID: <24b5f5ee-f88f-45a1-9c12-f3381209b647@googlegroups.com> On Wednesday, January 23, 2013 9:59:13 PM UTC-7, Chris Angelico wrote: > On Thu, Jan 24, 2013 at 3:39 PM, Milter Skyler <> wrote: > > > I made an array to check if the random integer already exists and then I send it to the else statement at which point I want to decrease x by 1 so that it doesn't count as one of the loops. In other languages this works... > > > > A Python 'for' loop doesn't behave like that; you can't just edit the > > loop counter. But take a step back: what are you actually trying to > > accomplish? As I see it, you're trying to pick ten unique random > > values in the range 1-12 inclusive. Try this: > > > > random.sample(range(1,13),10) # note that range() stops *before* its second arg > > > > That'll give you a list of those integers, and it's a lot safer and > > more reliable than the try-fail-retry method. Your loop can become: > > > > for decimal_value in random.sample(range(1,13),10): > > egg = 'A%d.png' % (decimal_value) > > egg = wait(egg) > > click(egg.getCenter().offset(random.randint(-10,10), > > random.randint(-10,10))) > > > > By the way, this line simply won't work: > > > > x-1 = x > > > > I think you mean: > > > > x = x-1 > > > > But I strongly suggest you copy and paste directly rather than retype; > > it's less error-prone. > > > > Hope that helps! > > > > ChrisA Thanks! That worked perfect, I was trying to figure that out but instead I just went down the hard route I went down. From wking at tremily.us Thu Jan 24 02:05:33 2013 From: wking at tremily.us (W. Trevor King) Date: Thu, 24 Jan 2013 02:05:33 -0500 Subject: Flatten an email Message with a non-ASCII body using 8bit CTE Message-ID: <20130124070533.GA20291@odin.tremily.us> Hello list! I'm trying to figure out how to flatten a MIMEText message to bytes using an 8bit Content-Transfer-Encoding in Python 3.3. Here's what I've tried so far: # -*- encoding: utf-8 -*- import email.encoders from email.charset import Charset from email.generator import BytesGenerator from email.mime.text import MIMEText import sys body = '????' encoding = 'utf-8' charset = Charset(encoding) charset.body_encoding = email.encoders.encode_7or8bit message = MIMEText(body, 'plain', encoding) del message['Content-Transfer-Encoding'] message.set_payload(body, charset) try: BytesGenerator(sys.stdout.buffer).flatten(message) except UnicodeEncodeError as e: print('error with string input:') print(e) message = MIMEText(body, 'plain', encoding) del message['Content-Transfer-Encoding'] message.set_payload(body.encode(encoding), charset) try: BytesGenerator(sys.stdout.buffer).flatten(message) except TypeError as e: print('error with byte input:') print(e) The `del m[?]; m.set_payload()` bits work around #16324 [1] and should be orthogonal to the encoding issues. It's possible that #12553 is trying to address this issue [2,3], but that issue's comments are a bit vague, so I'm not sure. The problem with the string payload is that email.generator.BytesGenerator.write is getting the Unicode string payload unencoded and trying to encode it as ASCII. It may be possible to work around this by encoding the payload so that anything that doesn't encode (using the body charset) to a 7bit value is replaced with a surrogate escape, but I'm not sure how to do that. The problem with the byte payload is that _has_surrogates (used in email.generator.Generator._handle_text and BytesGenerator._handle_text) chokes on byte input: TypeError: can't use a string pattern on a bytes-like object For UTF-8, you can get away with: message.as_string().encode(message.get_charset().get_output_charset()) because the headers are encoded into 7 bits, so re-encoding them with UTF-8 is a no-op. However, if the body charset is UTF-16-LE or any other encoding that remaps 7bit characters, this hack breaks down. Thoughts? Trevor [1]: http://bugs.python.org/issue16324 [2]: http://bugs.python.org/issue12553 [3]: http://bugs.python.org/issue12552#msg140294 -- This email may be signed or encrypted with GnuPG (http://www.gnupg.org). For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From hseventyfour at gmail.com Thu Jan 24 04:43:31 2013 From: hseventyfour at gmail.com (Hazard Seventyfour) Date: Thu, 24 Jan 2013 01:43:31 -0800 (PST) Subject: The best, friendly and easy use Python Editor. Message-ID: Hello, I new in this python and decided to learn more about it, so i can make an own script :), for all senior can you suggest me the best, friendly and easy use with nice GUI editor for me, and have many a good features such as auto complete/auto correct. any recommend? Thanks ^_^ From mikprog at gmail.com Thu Jan 24 05:34:45 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Thu, 24 Jan 2013 02:34:45 -0800 (PST) Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: Message-ID: <01aa34a1-b6d9-4c13-b793-34cb71a0ec0d@googlegroups.com> On Thursday, January 24, 2013 9:43:31 AM UTC, Hazard Seventyfour wrote: > Hello, > > > > I new in this python and decided to learn more about it, so i can make an own script :), > > > > for all senior can you suggest me the best, friendly and easy use with nice GUI editor for me, and have many a good features such as auto complete/auto correct. > > > > any recommend? Thanks ^_^ Hi, an editor is pretty much a matter of personal preferences. I personally like Eclipse as I use it for most of my projects (not only Python) so I use Eclipse + PyDev plug-in for Python. mik From miki.tebeka at gmail.com Fri Jan 25 09:18:23 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 25 Jan 2013 06:18:23 -0800 (PST) Subject: The best, friendly and easy use Python Editor. In-Reply-To: <01aa34a1-b6d9-4c13-b793-34cb71a0ec0d@googlegroups.com> References: <01aa34a1-b6d9-4c13-b793-34cb71a0ec0d@googlegroups.com> Message-ID: On Thursday, January 24, 2013 2:34:45 AM UTC-8, mik... at gmail.com wrote: > On Thursday, January 24, 2013 9:43:31 AM UTC, Hazard Seventyfour wrote: > > for all senior can you suggest me the best, friendly and easy use with nice GUI editor for me, and have many a good features such as auto complete/auto correct. > I personally like Eclipse as I use it for most of my projects (not only Python) so I use Eclipse + PyDev plug-in for Python. Aptana is doing a great job bundling Eclipse + PyDev (+ other goodies). From rosuav at gmail.com Thu Jan 24 06:10:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 22:10:21 +1100 Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: Message-ID: On Thu, Jan 24, 2013 at 8:43 PM, Hazard Seventyfour wrote: > Hello, > > I new in this python and decided to learn more about it, so i can make an own script :), > > for all senior can you suggest me the best, friendly and easy use with nice GUI editor for me, and have many a good features such as auto complete/auto correct. > > any recommend? Thanks ^_^ Here we go, it's holy war time again! :) You'll get a HUGE lot of responses. Many use emacs or vim, and you'll get a few recommendations for IDLE. After that, it's a huge field of options. I personally use SciTE; it's a good editor, but I don't particularly like the way the project is run (nothing strong, but I didn't like the tone on its mailing list). Eclipse has its fans, too. A Python IDE is not nearly as beneficial as, say, a Java IDE. A good Python editor just needs to do the basics like indentation, syntax highlighting, and such; I like IDLE's method info when I'm working interactively, but it's not a big deal when I'm writing a program. In fact, all you really need out of an IDE can probably be supplied by just a good editor, maybe a makefile, and alt-tabbing to IDLE. However, if you want an IDE, they do exist. ChrisA From gordon at panix.com Thu Jan 24 10:12:19 2013 From: gordon at panix.com (John Gordon) Date: Thu, 24 Jan 2013 15:12:19 +0000 (UTC) Subject: The best, friendly and easy use Python Editor. References: Message-ID: In Hazard Seventyfour writes: > Hello, > I new in this python and decided to learn more about it, so i can make > an own script :), > for all senior can you suggest me the best, friendly and easy use with > nice GUI editor for me, and have many a good features such as auto > complete/auto correct. Try PyScripter. http://code.google.com/p/pyscripter/ -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From sharwan.joram at gmail.com Thu Jan 24 10:37:10 2013 From: sharwan.joram at gmail.com (Sharwan Joram) Date: Thu, 24 Jan 2013 07:37:10 -0800 (PST) Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: Message-ID: On Thursday, January 24, 2013 8:42:19 PM UTC+5:30, John Gordon wrote: > In Hazard Seventyfour writes: > > > > > Hello, > > > > > I new in this python and decided to learn more about it, so i can make > > > an own script :), > > > > > for all senior can you suggest me the best, friendly and easy use with > > > nice GUI editor for me, and have many a good features such as auto > > > complete/auto correct. > > > > Try PyScripter. > > > > http://code.google.com/p/pyscripter/ > > > > -- > > John Gordon A is for Amy, who fell down the stairs > > gordon at panix.com B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies" use vim. ~Sharwan Joram From gordon at panix.com Thu Jan 24 10:51:15 2013 From: gordon at panix.com (John Gordon) Date: Thu, 24 Jan 2013 15:51:15 +0000 (UTC) Subject: The best, friendly and easy use Python Editor. References: Message-ID: In Sharwan Joram writes: > use vim. He said he wanted autocomplete. Does Vim have that? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From neilc at norwich.edu Thu Jan 24 15:04:13 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 24 Jan 2013 20:04:13 GMT Subject: The best, friendly and easy use Python Editor. References: Message-ID: On 2013-01-24, John Gordon wrote: > In Sharwan Joram writes: > >> use vim. > > He said he wanted autocomplete. Does Vim have that? Yes, you use its ctags support to get it working, I believe. -- Neil Cerutti From io at noi.com Thu Jan 24 16:14:23 2013 From: io at noi.com (Tetsuya) Date: Thu, 24 Jan 2013 22:14:23 +0100 Subject: The best, friendly and easy use Python Editor. References: Message-ID: On 01/24/2013 04:51 PM, John Gordon wrote: > In Sharwan Joram writes: > >> use vim. > > He said he wanted autocomplete. Does Vim have that? > Vim has everything, you just need a bunch of plugins. I code mainly in python and django, and I use these plugins (among others): powerline (status bar indicating git branch, etc..) syntastic (support for pep8, flake8, pyflakes, etc..) ctrlp (fuzzy search for filenames) jedi (*awesome* python smart autocompletion) tagbar (support for ctags, tags in a side window, jump around, etc) fugitive (git with vim commands, very useful) nerdcommenter (smart comment management) nerdtree (filesystem management, tree of files, etc) snipmate (snippets and autoexpanding of boilerplates) gundo (undo management - vim has a smarter-than-others undo system) supertab (autocomplete everything with TAB, smartly depending on language and context). Is this enough? :-) I can continue, but I think that, just to start, is enough. Vim wins. From torriem at gmail.com Fri Jan 25 12:47:44 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 25 Jan 2013 10:47:44 -0700 Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: Message-ID: <5102C540.5080206@gmail.com> On 01/24/2013 02:14 PM, Tetsuya wrote: > Vim has everything, you just need a bunch of plugins. > I code mainly in python and django, and I use these plugins (among others): > > powerline (status bar indicating git branch, etc..) > syntastic (support for pep8, flake8, pyflakes, etc..) > ctrlp (fuzzy search for filenames) > jedi (*awesome* python smart autocompletion) > tagbar (support for ctags, tags in a side window, jump around, etc) > fugitive (git with vim commands, very useful) > nerdcommenter (smart comment management) > nerdtree (filesystem management, tree of files, etc) > snipmate (snippets and autoexpanding of boilerplates) > gundo (undo management - vim has a smarter-than-others undo system) > supertab (autocomplete everything with TAB, smartly depending on > language and context). > > Is this enough? :-) > I can continue, but I think that, just to start, is enough. Vim wins. Awesome. I'm checking out these plugins right now, especially jedi and supertab. Thanks so much! From io at noi.com Fri Jan 25 17:03:49 2013 From: io at noi.com (Tetsuya) Date: Fri, 25 Jan 2013 23:03:49 +0100 Subject: The best, friendly and easy use Python Editor. References: Message-ID: On 01/25/2013 06:47 PM, Michael Torrie wrote: > On 01/24/2013 02:14 PM, Tetsuya wrote: >> Vim has everything, you just need a bunch of plugins. [...] >> jedi (*awesome* python smart autocompletion) [...] >> supertab (autocomplete everything with TAB, smartly depending on >> language and context). > > Awesome. I'm checking out these plugins right now, especially jedi and > supertab. Thanks so much! > ;-) you're welcome! From rustompmody at gmail.com Thu Jan 24 10:54:55 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 24 Jan 2013 07:54:55 -0800 (PST) Subject: The best, friendly and easy use Python Editor. References: Message-ID: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> On Jan 24, 2:43?pm, Hazard Seventyfour wrote: > Hello, > > I new in this python and decided to learn more about it, so i can make an own script :), > > for all senior can you suggest me the best, friendly and easy use with nice GUI editor for me, and have many a good features such as auto complete/auto correct. > > any recommend? Thanks ^_^ What editor you use does not matter. What matters is that you learn to use the interpreter. That is learn to use things like - history - last expression with _ (underscore) - Using introspection to find out about odd stuff (ie use dir and help) - Loading a python file - And after things kind-of work, copy pasting into your editor Here's a test to check whether youve got the idea: Do you think that to write a program you need to write a 'main?' If yes then no! [I personally use emacs. It would be sadistic to make that into a recommendation] From rosuav at gmail.com Thu Jan 24 11:01:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 03:01:16 +1100 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> References: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> Message-ID: On Fri, Jan 25, 2013 at 2:54 AM, rusi wrote: > - last expression with _ (underscore) Small terminology quibble: That's not last expression, but last non-None result. >>> 1+2 3 >>> _ 3 >>> _,None (3, None) >>> _ (3, None) >>> _[1] >>> _ (3, None) Otherwise, agree totally. Get to know the interactive interpreter, and keep it handy. ChrisA From theller at ctypes.org Thu Jan 24 11:23:57 2013 From: theller at ctypes.org (Thomas Heller) Date: Thu, 24 Jan 2013 17:23:57 +0100 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> References: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> Message-ID: Am 24.01.2013 16:54, schrieb rusi: > [I personally use emacs. It would be sadistic to make that into a > recommendation] > It would be truly sadistic to force a long-time emacs user to any other editor. Thomas From python.list at tim.thechases.com Thu Jan 24 12:01:30 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 24 Jan 2013 11:01:30 -0600 Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> Message-ID: <510168EA.4020607@tim.thechases.com> On 01/24/13 10:23, Thomas Heller wrote: > Am 24.01.2013 16:54, schrieb rusi: >> [I personally use emacs. It would be sadistic to make that into a >> recommendation] >> > It would be truly sadistic to force a long-time emacs user to any > other editor. I saw the recommendation for Vim elsewhere on the thread and comment the same as this sub-thread: "I personally use vim. It would be sadistic to make that into a recommendation" And likewise, it's "truly sadistic to force a long-time vim user to any other editor." :-) Not that Vim isn't great for programming Python (which I do daily)...it *is*! It's just not where I'd throw somebody who doesn't already have an existing editor preference *and* doesn't know Python. -tkc From neilc at norwich.edu Thu Jan 24 15:06:10 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 24 Jan 2013 20:06:10 GMT Subject: The best, friendly and easy use Python Editor. References: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> Message-ID: On 2013-01-24, Tim Chase wrote: > On 01/24/13 10:23, Thomas Heller wrote: >> Am 24.01.2013 16:54, schrieb rusi: >>> [I personally use emacs. It would be sadistic to make that into a >>> recommendation] >>> >> It would be truly sadistic to force a long-time emacs user to any >> other editor. > > I saw the recommendation for Vim elsewhere on the thread and comment > the same as this sub-thread: "I personally use vim. It would be > sadistic to make that into a recommendation" And likewise, it's > "truly sadistic to force a long-time vim user to any other editor." :-) > > Not that Vim isn't great for programming Python (which I do > daily)...it *is*! It's just not where I'd throw somebody who > doesn't already have an existing editor preference *and* doesn't > know Python. I agree. Vim is great, Emacs is great. I'm glad I know one of them. But learning one of them is as project unto itself. So selecting either just for Python is skipping too many decisions and maybe biting off too big a piece of the snake. -- Neil Cerutti From llanitedave at veawb.coop Thu Jan 24 16:09:28 2013 From: llanitedave at veawb.coop (llanitedave) Date: Thu, 24 Jan 2013 13:09:28 -0800 (PST) Subject: The best, friendly and easy use Python Editor. In-Reply-To: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> References: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> Message-ID: <73914552-3853-4dde-8205-b31998b753cf@googlegroups.com> On Thursday, January 24, 2013 7:54:55 AM UTC-8, rusi wrote: > > [I personally use emacs. It would be sadistic to make that into a > > recommendation] Lol! That's just too true. It's also true for Eclipse, which I use very comfortably on Windows 7, but has proven to be a nightmare to set up on Ubuntu. On Linux, I've tried several, but always keep coming back to Geany. From dreyemi at gmail.com Thu Jan 24 16:24:00 2013 From: dreyemi at gmail.com (Kayode Odeyemi) Date: Thu, 24 Jan 2013 22:24:00 +0100 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <73914552-3853-4dde-8205-b31998b753cf@googlegroups.com> References: <82c4ecc1-3d18-47ba-ad2d-f238bfaf878e@y3g2000pbq.googlegroups.com> <73914552-3853-4dde-8205-b31998b753cf@googlegroups.com> Message-ID: Simply use Netbeans On Thu, Jan 24, 2013 at 10:09 PM, llanitedave wrote: > On Thursday, January 24, 2013 7:54:55 AM UTC-8, rusi wrote: > > > > > [I personally use emacs. It would be sadistic to make that into a > > > > recommendation] > > Lol! That's just too true. It's also true for Eclipse, which I use very > comfortably on Windows 7, but has proven to be a nightmare to set up on > Ubuntu. > > On Linux, I've tried several, but always keep coming back to Geany. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Odeyemi 'Kayode O. http://ng.linkedin.com/in/kayodeodeyemi. t: @charyorde blog: http://sinati.com/tree/java-cheat-sheet -------------- next part -------------- An HTML attachment was scrubbed... URL: From andgudovich at gmail.com Thu Jan 24 12:18:07 2013 From: andgudovich at gmail.com (Andrew Gudovich) Date: Thu, 24 Jan 2013 09:18:07 -0800 (PST) Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: Message-ID: <2f7d67a8-9f02-4f11-bf90-33813cc41bd9@googlegroups.com> I think PyCharm is ideal for you. http://www.jetbrains.com/pycharm/ From kpekarov at gmail.com Fri Jan 25 04:43:15 2013 From: kpekarov at gmail.com (Kirill Pekarov) Date: Fri, 25 Jan 2013 01:43:15 -0800 (PST) Subject: The best, friendly and easy use Python Editor. In-Reply-To: <2f7d67a8-9f02-4f11-bf90-33813cc41bd9@googlegroups.com> References: <2f7d67a8-9f02-4f11-bf90-33813cc41bd9@googlegroups.com> Message-ID: <53da70cb-7a07-4505-bbd9-3d13e274be05@googlegroups.com> > I think PyCharm is ideal for you. > http://www.jetbrains.com/pycharm/ +1 for PyCharm. I used many editors, and PyCharm (IDEA) is just perfect. From xenplex at gmail.com Fri Jan 25 09:06:59 2013 From: xenplex at gmail.com (Ritchie Flick) Date: Fri, 25 Jan 2013 15:06:59 +0100 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <53da70cb-7a07-4505-bbd9-3d13e274be05@googlegroups.com> References: <2f7d67a8-9f02-4f11-bf90-33813cc41bd9@googlegroups.com> <53da70cb-7a07-4505-bbd9-3d13e274be05@googlegroups.com> Message-ID: You could try ninja-ide or Sublime Text 2. -------------------------------------------- This message was send from my phone Flick Ritchie On 25 Jan 2013 10:45, "Kirill Pekarov" wrote: > > I think PyCharm is ideal for you. > > http://www.jetbrains.com/pycharm/ > > +1 for PyCharm. > I used many editors, and PyCharm (IDEA) is just perfect. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From walterhurry at lavabit.com Thu Jan 24 14:18:24 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 24 Jan 2013 19:18:24 +0000 (UTC) Subject: The best, friendly and easy use Python Editor. References: Message-ID: On Thu, 24 Jan 2013 22:10:21 +1100, Chris Angelico wrote: > On Thu, Jan 24, 2013 at 8:43 PM, Hazard Seventyfour > wrote: >> Hello, >> >> I new in this python and decided to learn more about it, so i can make >> an own script :), >> >> for all senior can you suggest me the best, friendly and easy use with >> nice GUI editor for me, and have many a good features such as auto >> complete/auto correct. >> >> any recommend? Thanks ^_^ > > Here we go, it's holy war time again! :) > > You'll get a HUGE lot of responses. Many use emacs or vim, and you'll > get a few recommendations for IDLE. After that, it's a huge field of > options. I personally use SciTE; it's a good editor, but I don't > particularly like the way the project is run (nothing strong, but I > didn't like the tone on its mailing list). Eclipse has its fans, too. > > A Python IDE is not nearly as beneficial as, say, a Java IDE. A good > Python editor just needs to do the basics like indentation, syntax > highlighting, and such; I like IDLE's method info when I'm working > interactively, but it's not a big deal when I'm writing a program. In > fact, all you really need out of an IDE can probably be supplied by just > a good editor, maybe a makefile, and alt-tabbing to IDLE. However, if > you want an IDE, they do exist. All true (especially the holy wars bit!). OP didn't (as far as I can see) even say which OS he is using. Anyway, my suggestion is generally that people use the editor with which they are already comfortable. From Arah.Leonard at bruker-axs.com Thu Jan 24 14:34:43 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 24 Jan 2013 19:34:43 +0000 Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> > All true (especially the holy wars bit!). OP didn't (as far as I can see) even say which OS he is using. Anyway, my suggestion is generally that people use the editor with which they are already comfortable. > Sound advice. Most of the time I still use Visual Studio for editing Python because I also use it for C++, so it's just what I'm used to. No big deal, really. Whatever works is what works. It's just a text file after all. From dave.hirschfeld at gmail.com Thu Jan 24 15:01:37 2013 From: dave.hirschfeld at gmail.com (Dave Hirschfeld) Date: Thu, 24 Jan 2013 20:01:37 +0000 (UTC) Subject: The best, friendly and easy use Python Editor. References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: Leonard, Arah bruker-axs.com> writes: > > > All true (especially the holy wars bit!). OP didn't (as far as I can see) > >even say which OS he is using. > Anyway, my suggestion is generally that people use the editor with which > > they are already comfortable. > > > > Sound advice. Most of the time I still use Visual Studio for editing Python > because I also use it for C++, so > it's just what I'm used to. No big deal, really. Whatever works is what > works. It's just a text file after all. > I assume you're using PyTools (http://pytools.codeplex.com/)? -Dave From Arah.Leonard at bruker-axs.com Thu Jan 24 15:32:46 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 24 Jan 2013 20:32:46 +0000 Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07586F2A@msnmail2.bruker-axs.com> >> Sound advice. Most of the time I still use Visual Studio for editing >> Python because I also use it for C++, so it's just what I'm used to. >> No big deal, really. Whatever works is what works. It's just a text >> file after all. >> > > I assume you're using PyTools (http://pytools.codeplex.com/)? > Would that I could! To my knowledge they still haven't backported PyTools to VS2008, which I'm presently stuck on because Python 2.7 still doesn't compile on VS2010. :( Kind of makes you think... From python.list at tim.thechases.com Thu Jan 24 15:25:40 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 24 Jan 2013 14:25:40 -0600 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: <510198C4.10907@tim.thechases.com> On 01/24/13 13:34, Leonard, Arah wrote: >> All true (especially the holy wars bit!). OP didn't (as far as >> I can see) even say which OS he is using. Anyway, my suggestion >> is generally that people use the editor with which they are >> already comfortable. > > Sound advice. [snip] Whatever works is what works. It's just a > text file after all. So even "ed" or "edlin" or even "cat" would do ;-) ? -tkc ? wq From rosuav at gmail.com Thu Jan 24 18:29:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 10:29:05 +1100 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <510198C4.10907@tim.thechases.com> References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> <510198C4.10907@tim.thechases.com> Message-ID: On Fri, Jan 25, 2013 at 7:25 AM, Tim Chase wrote: > On 01/24/13 13:34, Leonard, Arah wrote: >>> >>> All true (especially the holy wars bit!). OP didn't (as far as >>> I can see) even say which OS he is using. Anyway, my suggestion >>> is generally that people use the editor with which they are >>> already comfortable. >> >> >> Sound advice. [snip] Whatever works is what works. It's just a >> text file after all. > > > So even "ed" or "edlin" or even "cat" would do ;-) Definitely. Especially if your edlin syntax highlights Python. ChrisA From wayne at waynewerner.com Thu Jan 31 08:34:53 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 31 Jan 2013 07:34:53 -0600 (CST) Subject: The best, friendly and easy use Python Editor. In-Reply-To: <510198C4.10907@tim.thechases.com> References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> <510198C4.10907@tim.thechases.com> Message-ID: On Thu, 24 Jan 2013, Tim Chase wrote: > On 01/24/13 13:34, Leonard, Arah wrote: >>> All true (especially the holy wars bit!). OP didn't (as far as >>> I can see) even say which OS he is using. Anyway, my suggestion >>> is generally that people use the editor with which they are >>> already comfortable. >> >> Sound advice. [snip] Whatever works is what works. It's just a >> text file after all. > > So even "ed" or "edlin" or even "cat" would do ;-) > ? > -tkc > ? > wq ed *is* the standard editor. Also, I see what you did there ;) -w . wq From breamoreboy at yahoo.co.uk Fri Jan 25 04:12:11 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 25 Jan 2013 09:12:11 +0000 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: On 24/01/2013 19:34, Leonard, Arah wrote: > > It's just a text file after all. > True indeed, let's not worry about trivial issues like indentation, mixing tabs and spaces or whatever. Notepad anybody? :) -- Cheers. Mark Lawrence From Arah.Leonard at bruker-axs.com Fri Jan 25 12:35:53 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Fri, 25 Jan 2013 17:35:53 +0000 Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: <2ECADBDABCB17E40B66A25D839706F5E0758713D@msnmail2.bruker-axs.com> >> >> It's just a text file after all. >> > > True indeed, let's not worry about trivial issues like indentation, mixing tabs and spaces or whatever. Notepad anybody? :) > Hey, I didn't say Notepad was the *best* tool for the job, just that Python scripts are merely text files. Though, that said, I have used Notepad and Wordpad any number of times in the past to edit Python files, all without bringing the universe to an untimely end. Even used DOS Edit once. You use what you have at the time. A good craftsman never blames the tools. ;) From rosuav at gmail.com Fri Jan 25 12:42:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 26 Jan 2013 04:42:37 +1100 Subject: The best, friendly and easy use Python Editor. In-Reply-To: <2ECADBDABCB17E40B66A25D839706F5E0758713D@msnmail2.bruker-axs.com> References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> <2ECADBDABCB17E40B66A25D839706F5E0758713D@msnmail2.bruker-axs.com> Message-ID: On Sat, Jan 26, 2013 at 4:35 AM, Leonard, Arah wrote: >>> >>> It's just a text file after all. >>> >> >> True indeed, let's not worry about trivial issues like indentation, mixing tabs and spaces or whatever. Notepad anybody? :) >> > > Hey, I didn't say Notepad was the *best* tool for the job, just that Python scripts are merely text files. > > Though, that said, I have used Notepad and Wordpad any number of times in the past to edit Python files, all without bringing the universe to an untimely end. Even used DOS Edit once. You use what you have at the time. A good craftsman never blames the tools. ;) I've edited files using any number of poor tools, but that doesn't mean I'd choose them for daily work. Blame your tools no, but choose which ones you carry around on your belt. I have a couple of special-purpose editors that absolutely *suck* for general work, but have a specific feature that makes them good for one particular situation... one editor has a 32KB limit, no spiffy features, and sometimes mishandles line endings, but it edits files on my remote server, and can sometimes work when SSHing isn't an option. But there's no way I'd use that for any other purpose than remote editing. ChrisA From neilc at norwich.edu Fri Jan 25 12:54:39 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 25 Jan 2013 17:54:39 GMT Subject: The best, friendly and easy use Python Editor. References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: On 2013-01-25, Leonard, Arah wrote: > Though, that said, I have used Notepad and Wordpad any number > of times in the past to edit Python files, all without bringing > the universe to an untimely end. Even used DOS Edit once. You > use what you have at the time. A good craftsman never blames > the tools. ;) DOS Edit was great for quick edits. The file size limit is a pity, though. -- Neil Cerutti From davea at davea.name Fri Jan 25 13:12:14 2013 From: davea at davea.name (Dave Angel) Date: Fri, 25 Jan 2013 13:12:14 -0500 Subject: The best, friendly and easy use Python Editor. In-Reply-To: References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: <5102CAFE.6060102@davea.name> On 01/25/2013 12:54 PM, Neil Cerutti wrote: > On 2013-01-25, Leonard, Arah wrote: >> Though, that said, I have used Notepad and Wordpad any number >> of times in the past to edit Python files, all without bringing >> the universe to an untimely end. Even used DOS Edit once. You >> use what you have at the time. A good craftsman never blames >> the tools. ;) > > DOS Edit was great for quick edits. The file size limit is a > pity, though. > I once had to write a text editor that would run in a 32k machine without a disk drive. The editor had to fit in RAM with the data, so the text files were limited to 320 lines. -- DaveA From rustompmody at gmail.com Tue Jan 29 13:01:24 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 29 Jan 2013 10:01:24 -0800 (PST) Subject: The best, friendly and easy use Python Editor. References: <2ECADBDABCB17E40B66A25D839706F5E07586EE4@msnmail2.bruker-axs.com> Message-ID: On Jan 25, 10:35?pm, "Leonard, Arah" wrote: > >> It's just a text file after all. > > > True indeed, let's not worry about trivial issues like indentation, mixing tabs and spaces or whatever. ?Notepad anybody? :) > > Hey, I didn't say Notepad was the *best* tool for the job, just that Python scripts are merely > text files. "text files" ok. "Merely text files" needs some rebuttal http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html Yeah its a bit tongue-in-cheek and does not directly answer the OP (to which anyway I said: interpreter is more important than editor) From feliphil at gmx.net Fri Jan 25 11:24:46 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Fri, 25 Jan 2013 17:24:46 +0100 Subject: The best, friendly and easy use Python Editor. References: Message-ID: <20130125172446.bf029e9da8eec5e6d13c0705@gmx.net> > for all senior can you suggest me the best, friendly and easy use > with nice GUI editor for me, and have many a good features such as > auto complete/auto correct. Depends on what you are used to. If you're used to bare-bones editors such as emacs, vim etc, they can be used for Python. If you're used to IDEs, WingIDE is one long-standing competitor. The "101" version is free. There are also editors implemented *in* Python, which can be used for programming Python, such as Editra, which features quite a few useful plugins. Sincerely, Wolfgang From mikprog at gmail.com Thu Jan 24 05:31:58 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Thu, 24 Jan 2013 02:31:58 -0800 (PST) Subject: Python to send Midi commands to iPad via USB Message-ID: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> Dear all, I am asking for a design/strategy suggestion. What I have to do is to write a Python application that will send MIDI commands to an iPad application. All I know is that the iPad application can be connected to an external Midi deck through a usb cable and be controlled. So I think I would connect the iPad via USB to my computer and... try to send midi commands. I think the limitation is that the iPad will allow signaling/connection only to Midi devices, so I have to make so that my Python script pretends that my computer is a Midi device. So far I have tried PyUSB library and I can see the iPad, but I can't send anything to it (probably because I am not pretending to be a Midi device well enough). I am keen to try PyUSB + pygame for the Midi stuff. Any suggestion / recommendation / hint / whatever to tell me? I appreciate every idea at this stage! Thanks for reading, Mik From rosuav at gmail.com Thu Jan 24 05:44:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 21:44:47 +1100 Subject: Python to send Midi commands to iPad via USB In-Reply-To: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> Message-ID: On Thu, Jan 24, 2013 at 9:31 PM, wrote: > What I have to do is to write a Python application that will send MIDI commands to an iPad application. > All I know is that the iPad application can be connected to an external Midi deck through a usb cable and be controlled. > So I think I would connect the iPad via USB to my computer and... try to send midi commands. Are you able to hook into ALSA? I've had reasonable success driving a USB-MIDI cable using ALSA. See if you can do it with the inbuilt 'pmidi' app first: $ pmidi -p 128:0 No.19.mid (that uses port 128:0 which is a TiMidity-provided one) If that works, you can then look for Python ALSA bindings, which I believe are available on PyPI. My example is from Linux, so you may need to tweak things on other OSes. ChrisA From mikprog at gmail.com Thu Jan 24 06:48:15 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Thu, 24 Jan 2013 03:48:15 -0800 (PST) Subject: Python to send Midi commands to iPad via USB In-Reply-To: References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> Message-ID: <9793e716-4026-4465-b706-9fbe59358cae@googlegroups.com> On Thursday, January 24, 2013 10:44:47 AM UTC, Chris Angelico wrote: [..] > > Are you able to hook into ALSA? I've had reasonable success driving a > > USB-MIDI cable using ALSA. See if you can do it with the inbuilt > > 'pmidi' app first: > > > > $ pmidi -p 128:0 No.19.mid > > > > (that uses port 128:0 which is a TiMidity-provided one) > > > > If that works, you can then look for Python ALSA bindings, which I > > believe are available on PyPI. > Thanks for your help Chris! forgive my ignorance, but I am not sure what you mean. I've installed pmidi and what I get is: ~$ pmidi -p 128:0 No.19.mid Could not open file No.19.mid Doesn't that mean that the iPad is not seen? where: ~$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 002: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth) Bus 005 Device 002: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor Bus 003 Device 003: ID 413c:8157 Dell Computer Corp. Integrated Keyboard Bus 003 Device 004: ID 413c:8158 Dell Computer Corp. Integrated Touchpad / Trackstick Bus 006 Device 002: ID 192f:0416 Avago Technologies, Pte. Bus 002 Device 003: ID 05ac:12a4 Apple, Inc. Essentially the reason to use the iPad is because we have to make a demo where with our hardware we send midi commands and the iPad has a very good DJ application that can be used with a USB midi controller. So I wish to connect our hardware to a Raspberry Pi (or similar) via BLE and then the board (Raspberry Pi) to the iPad through USB cable. I think the weak point is communication from the Raspberry Pi (or PC) to the iPad via USB. I could actually remove that if I find a decent Linux/Python application that acts as a DJ deck. I am having a look at pygame.midi as well, but I am not sure how to link that with a USB cable. mik From mikprog at gmail.com Thu Jan 24 06:48:15 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Thu, 24 Jan 2013 03:48:15 -0800 (PST) Subject: Python to send Midi commands to iPad via USB In-Reply-To: References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> Message-ID: <9793e716-4026-4465-b706-9fbe59358cae@googlegroups.com> On Thursday, January 24, 2013 10:44:47 AM UTC, Chris Angelico wrote: [..] > > Are you able to hook into ALSA? I've had reasonable success driving a > > USB-MIDI cable using ALSA. See if you can do it with the inbuilt > > 'pmidi' app first: > > > > $ pmidi -p 128:0 No.19.mid > > > > (that uses port 128:0 which is a TiMidity-provided one) > > > > If that works, you can then look for Python ALSA bindings, which I > > believe are available on PyPI. > Thanks for your help Chris! forgive my ignorance, but I am not sure what you mean. I've installed pmidi and what I get is: ~$ pmidi -p 128:0 No.19.mid Could not open file No.19.mid Doesn't that mean that the iPad is not seen? where: ~$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 002: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth) Bus 005 Device 002: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor Bus 003 Device 003: ID 413c:8157 Dell Computer Corp. Integrated Keyboard Bus 003 Device 004: ID 413c:8158 Dell Computer Corp. Integrated Touchpad / Trackstick Bus 006 Device 002: ID 192f:0416 Avago Technologies, Pte. Bus 002 Device 003: ID 05ac:12a4 Apple, Inc. Essentially the reason to use the iPad is because we have to make a demo where with our hardware we send midi commands and the iPad has a very good DJ application that can be used with a USB midi controller. So I wish to connect our hardware to a Raspberry Pi (or similar) via BLE and then the board (Raspberry Pi) to the iPad through USB cable. I think the weak point is communication from the Raspberry Pi (or PC) to the iPad via USB. I could actually remove that if I find a decent Linux/Python application that acts as a DJ deck. I am having a look at pygame.midi as well, but I am not sure how to link that with a USB cable. mik From rosuav at gmail.com Thu Jan 24 06:56:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 22:56:42 +1100 Subject: Python to send Midi commands to iPad via USB In-Reply-To: <9793e716-4026-4465-b706-9fbe59358cae@googlegroups.com> References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> <9793e716-4026-4465-b706-9fbe59358cae@googlegroups.com> Message-ID: On Thu, Jan 24, 2013 at 10:48 PM, wrote: > Thanks for your help Chris! > forgive my ignorance, but I am not sure what you mean. > I've installed pmidi and what I get is: > > ~$ pmidi -p 128:0 No.19.mid > Could not open file No.19.mid > > Doesn't that mean that the iPad is not seen? Heya! That was just an example; I used track number 19 from the opera "Iolanthe" as my test file. Pick any other MIDI file you have handy. Though, I may have my commands mixed up; aplaymidi may be more what you want. In any case, the key is the port number. Try this to enumerate ports: $ aplaymidi -l That's lower-case l for list. If that tells you about something that looks like your iPad, you're in luck, ALSA has already done most of the work! And you should be able to play any file with: $ aplaymidi -p X:Y some-file.mid where X:Y is from the first column of aplaymidi -l output. On my system currently, I have 128:0 through 128:3 from TiMidity, and 14:0 "Midi Through". When my USB device is connected, I get a couple more ports from it. ChrisA From mikprog at gmail.com Thu Jan 24 07:25:55 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Thu, 24 Jan 2013 04:25:55 -0800 (PST) Subject: Python to send Midi commands to iPad via USB In-Reply-To: References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> <9793e716-4026-4465-b706-9fbe59358cae@googlegroups.com> Message-ID: [..] > > > ~$ pmidi -p 128:0 No.19.mid > > > Could not open file No.19.mid > > > > > > Doesn't that mean that the iPad is not seen? > > > Heya! That was just an example; I used track number 19 from the opera > > "Iolanthe" as my test file. Pick any other MIDI file you have handy. This is exactly the point where I feel dumb :-) [..] > $ aplaymidi -l > I think I am not lucky :-( $ aplaymidi -l Port Client name Port name 14:0 Midi Through Midi Through Port-0 I get the same either the iPad is connected or not. So I guess is not recognized. Shame. I'll keep on investigating, hopefully without loosing any of my neurons. Thanks, mik From rosuav at gmail.com Thu Jan 24 07:36:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 23:36:21 +1100 Subject: Python to send Midi commands to iPad via USB In-Reply-To: References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> <9793e716-4026-4465-b706-9fbe59358cae@googlegroups.com> Message-ID: On Thu, Jan 24, 2013 at 11:25 PM, wrote: > I think I am not lucky :-( > > $ aplaymidi -l > Port Client name Port name > 14:0 Midi Through Midi Through Port-0 > > I get the same either the iPad is connected or not. > So I guess is not recognized. > Shame. > > I'll keep on investigating, hopefully without loosing any of my neurons. Yeah, this is the bit where you have to poke around with iPad stuff. They say "there's an app for that"; maybe there's a way to turn an iPad into a USB MIDI device. I did a quick Google search for 'ipad usb midi' and there seem to be some decent hits, so your luck mightn't have completely run out yet. ChrisA From mikprog at gmail.com Thu Jan 24 07:25:55 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Thu, 24 Jan 2013 04:25:55 -0800 (PST) Subject: Python to send Midi commands to iPad via USB In-Reply-To: References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> <9793e716-4026-4465-b706-9fbe59358cae@googlegroups.com> Message-ID: [..] > > > ~$ pmidi -p 128:0 No.19.mid > > > Could not open file No.19.mid > > > > > > Doesn't that mean that the iPad is not seen? > > > Heya! That was just an example; I used track number 19 from the opera > > "Iolanthe" as my test file. Pick any other MIDI file you have handy. This is exactly the point where I feel dumb :-) [..] > $ aplaymidi -l > I think I am not lucky :-( $ aplaymidi -l Port Client name Port name 14:0 Midi Through Midi Through Port-0 I get the same either the iPad is connected or not. So I guess is not recognized. Shame. I'll keep on investigating, hopefully without loosing any of my neurons. Thanks, mik From rustompmody at gmail.com Thu Jan 24 14:22:24 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 24 Jan 2013 11:22:24 -0800 (PST) Subject: Python to send Midi commands to iPad via USB References: <3612c184-28d6-4b58-9c70-fb83e103893e@googlegroups.com> Message-ID: <95ac5385-50f7-45d8-a12e-7c21b11f53b2@xm8g2000pbc.googlegroups.com> On Jan 24, 3:31?pm, mikp... at gmail.com wrote: > Dear all, > > I am asking for a design/strategy suggestion. > > What I have to do is to write a Python application that will send MIDI commands to an iPad application. > All I know is that the iPad application can be connected to an external Midi deck through a usb cable and be controlled. > So I think I would connect the iPad via USB to my computer and... try to send midi commands. > I think the limitation is that the iPad will allow signaling/connection only to Midi devices, so I have to make so that my Python script pretends that my computer is a Midi device. > So far I have tried PyUSB library and I can see the iPad, but I can't send anything to it (probably because I am not pretending to be a Midi device well enough). > > I am keen to try PyUSB + pygame for the Midi stuff. > > Any suggestion / recommendation / hint / whatever to tell me? > I appreciate every idea at this stage! > > Thanks for reading, > Mik Some suggestions: 1. The linux audio list will serve you better than the python list for this line of questions 2. Before worrying about python get your 'plumbing' right with dedicated midi s/w like rosegarden, qtractor etc 3. [I dont understand much midi but?] look at aconnect, aseqnet in addition to pmidi, aplaymidi 4. On some recent linuxes, (notably ubuntu) timidity is broken thanks to pulseaudio. In particular, timidity as a normal program works does not imply that timidity as a server works From insideshoes at gmail.com Thu Jan 24 05:37:55 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Thu, 24 Jan 2013 11:37:55 +0100 Subject: using split for a string : error Message-ID: Here I have a code which basically reads a csv file, tries to compare the last 2 items in each line of the file. f = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") for l in f: sp = l.split(",") if len(sp) != 11: print >> of, l, else: #print sp[9], sp[10] if sp[9] == sp[10]: print " Same class" else : print "Different class" f.close() For me I think the programme is logically correct, but its giving me results which are strange. It is Printing " Different Class" even when sp[9] is equal to sp[10] and "Same class" when sp[9] is not equal to sp[10]. and sp[9] and sp[10] are simple integers like 3, 3, 4 ,4. I have a little understanding why the programme is behaving like this ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tm at tobix.eu Thu Jan 24 05:55:17 2013 From: tm at tobix.eu (Tobias M.) Date: Thu, 24 Jan 2013 11:55:17 +0100 Subject: using split for a string : error In-Reply-To: References: Message-ID: <51011315.3060406@tobix.eu> Hi, do a "print sp" after the split and you might see that the strings don't look as you expected. There might be leading or trailing whitespaces in the splitted strings and in sp[10] there probably is a line break "\n" at the end. To remove those unwanted characters you could use the strip() function. So your code could be: if sp[9].strip() == sp[10].strip(): print "Same class" else: print "Different class" At least this works for me when I tried it... Am 24.01.2013 11:37, schrieb inshu chauhan: > Here I have a code which basically reads a csv file, tries to compare > the last 2 items in each line of the file. > > f = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") > for l in f: > sp = l.split(",") > if len(sp) != 11: > print >> of, l, > > else: > #print sp[9], sp[10] > if sp[9] == sp[10]: > print " Same class" > else : > print "Different class" > > f.close() > > For me I think the programme is logically correct, but its giving me > results which are strange. > It is Printing " Different Class" even when sp[9] is equal to sp[10] > and "Same class" when sp[9] is not equal to sp[10]. and sp[9] and > sp[10] are simple integers like 3, 3, 4 ,4. > > I have a little understanding why the programme is behaving like this ? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From insideshoes at gmail.com Thu Jan 24 06:01:00 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Thu, 24 Jan 2013 12:01:00 +0100 Subject: using split for a string : error In-Reply-To: <51011315.3060406@tobix.eu> References: <51011315.3060406@tobix.eu> Message-ID: On Thu, Jan 24, 2013 at 11:55 AM, Tobias M. wrote: > Hi, > > do a "print sp" after the split and you might see that the strings don't > look as you expected. There might be leading or trailing whitespaces in the > splitted strings and in sp[10] there probably is a line break "\n" at the > end. > To remove those unwanted characters you could use the strip() function. > > So your code could be: > > if sp[9].strip() == sp[10].strip(): > > print "Same class" > else: > print "Different class" > > At least this works for me when I tried it... > > Am 24.01.2013 11:37, schrieb inshu chauhan: > > Here I have a code which basically reads a csv file, tries to compare > the last 2 items in each line of the file. > > f = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") > for l in f: > sp = l.split(",") > if len(sp) != 11: > print >> of, l, > > else: > #print sp[9], sp[10] > if sp[9] == sp[10]: > print " Same class" > else : > print "Different class" > > f.close() > > For me I think the programme is logically correct, but its giving me > results which are strange. > It is Printing " Different Class" even when sp[9] is equal to sp[10] > and "Same class" when sp[9] is not equal to sp[10]. and sp[9] and sp[10] > are simple integers like 3, 3, 4 ,4. > > I have a little understanding why the programme is behaving like this ? > > > Yeah I tried printing, there were trailing white spaces, so i used > strip() and IT Worked !!! :) > Thank you > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jan 24 06:17:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 22:17:38 +1100 Subject: using split for a string : error In-Reply-To: References: <51011315.3060406@tobix.eu> Message-ID: On Thu, Jan 24, 2013 at 10:01 PM, inshu chauhan wrote: > Yeah I tried printing, there were trailing white spaces, so i used strip() > and IT Worked !!! :) Awesome! Keep repr() in mind, it's a great way to check what's really there. ChrisA From rosuav at gmail.com Thu Jan 24 05:58:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 21:58:35 +1100 Subject: using split for a string : error In-Reply-To: References: Message-ID: On Thu, Jan 24, 2013 at 9:37 PM, inshu chauhan wrote: > For me I think the programme is logically correct, but its giving me results > which are strange. > It is Printing " Different Class" even when sp[9] is equal to sp[10] and > "Same class" when sp[9] is not equal to sp[10]. and sp[9] and sp[10] are > simple integers like 3, 3, 4 ,4. > > I have a little understanding why the programme is behaving like this ? Without your data file I can't advise, but here's a couple of things to try. I see you've tried displaying the values: #print sp[9], sp[10] Try this version: print repr(sp[9]), repr(sp[10]) That'll make it obvious if, for instance, there are leading/trailing spaces. The other thing you may want to consider, if the values are supposed to be integers, is to convert them to Python integers before comparing. Currently, you're working with strings. Replace this: if sp[9] == sp[10]: with this: if int(sp[9]) == int(sp[10]): That will consider "1" and "1 " to be the same, since they'll both be parsed as the integer 1. Alternatively, consider what Tobias said and explicitly strip spaces. Either way, displaying repr() of the strings (or printing the whole of sp, as Tobias suggests) will show you what's needed. ChrisA From tm at tobix.eu Thu Jan 24 06:16:50 2013 From: tm at tobix.eu (Tobias M.) Date: Thu, 24 Jan 2013 12:16:50 +0100 Subject: using split for a string : error In-Reply-To: References: Message-ID: <51011822.3020702@tobix.eu> Chris Angelico wrote: > > > The other thing you may want to consider, if the values are supposed > to be integers, is to convert them to Python integers before > comparing. Currently, you're working with strings. Replace this: > > if sp[9] == sp[10]: > > with this: > > if int(sp[9]) == int(sp[10]): I thought of this too and I wonder if there are any major differences regarding performance compared to using the strip() method when parsing large files. In addition I guess one should catch the ValueError that might be raised by the cast if there is something else than a number in the file. From rosuav at gmail.com Thu Jan 24 06:35:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 22:35:22 +1100 Subject: using split for a string : error In-Reply-To: <51011822.3020702@tobix.eu> References: <51011822.3020702@tobix.eu> Message-ID: On Thu, Jan 24, 2013 at 10:16 PM, Tobias M. wrote: > Chris Angelico wrote: >> The other thing you may want to consider, if the values are supposed >> to be integers, is to convert them to Python integers before >> comparing. > > I thought of this too and I wonder if there are any major differences > regarding performance compared to using the strip() method when parsing > large files. > > In addition I guess one should catch the ValueError that might be raised by > the cast if there is something else than a number in the file. I'd not consider the performance, but the correctness. If you're expecting them to be integers, just cast them, and specifically _don't_ catch ValueError. Any non-integer value will then noisily abort the script. (It may be worth checking for blank first, though, depending on the data origin.) It's usually fine to have int() complain about any non-numerics in the string, but I must confess, I do sometimes yearn for atoi() semantics: atoi("123asd") == 123, and atoi("qqq") == 0. I've not seen a convenient Python function for doing that. Usually it involves manually getting the digits off the front. All I want is to suppress the error on finding a non-digit. Oh well. ChrisA From tm at tobix.eu Thu Jan 24 06:58:49 2013 From: tm at tobix.eu (Tobias M.) Date: Thu, 24 Jan 2013 12:58:49 +0100 Subject: using split for a string : error In-Reply-To: References: <51011822.3020702@tobix.eu> Message-ID: <510121F9.70508@tobix.eu> Chris Angelico wrote: > I'd not consider the performance, but the correctness. If you're > expecting them to be integers, just cast them, and specifically > _don't_ catch ValueError. Any non-integer value will then noisily > abort the script. (It may be worth checking for blank first, though, > depending on the data origin.) Well, when I said you should catch the ValueError I didn't imply you should ignore the error and supress any error messages. Of course this depents on the use case. Maybe you want to raise another exception with a more user friendly error message or you might want to skip the line and just print a warning. :) What I'm trying to say: When I give a script/program to a user who is not a python programmer I don't want him to see an error message like "ValueError: invalid literal for int() with base 10: 'abc'" as this would help him in no way. From rosuav at gmail.com Thu Jan 24 07:02:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 23:02:02 +1100 Subject: using split for a string : error In-Reply-To: <510121F9.70508@tobix.eu> References: <51011822.3020702@tobix.eu> <510121F9.70508@tobix.eu> Message-ID: On Thu, Jan 24, 2013 at 10:58 PM, Tobias M. wrote: > Chris Angelico wrote: >> >> I'd not consider the performance, but the correctness. If you're >> expecting them to be integers, just cast them, and specifically >> _don't_ catch ValueError. Any non-integer value will then noisily >> abort the script. (It may be worth checking for blank first, though, >> depending on the data origin.) > > Well, when I said you should catch the ValueError I didn't imply you should > ignore the error and supress any error messages. Of course this depents on > the use case. Maybe you want to raise another exception with a more user > friendly error message or you might want to skip the line and just print a > warning. :) > > What I'm trying to say: When I give a script/program to a user who is not a > python programmer I don't want him to see an error message like "ValueError: > invalid literal for int() with base 10: 'abc'" as this would help him in no > way. Sure. Definitely. But for a proglet where the programmer IS the user (which I think is one of Python's best use-cases), that exception landing on the console is better than having to think ahead of time about what might go wrong. ChrisA From tm at tobix.eu Thu Jan 24 07:10:13 2013 From: tm at tobix.eu (Tobias M.) Date: Thu, 24 Jan 2013 13:10:13 +0100 Subject: using split for a string : error In-Reply-To: References: <51011822.3020702@tobix.eu> <510121F9.70508@tobix.eu> Message-ID: <510124A5.6080701@tobix.eu> Am 24.01.2013 13:02, schrieb Chris Angelico: > On Thu, Jan 24, 2013 at 10:58 PM, Tobias M. wrote: >> Chris Angelico wrote: >>> I'd not consider the performance, but the correctness. If you're >>> expecting them to be integers, just cast them, and specifically >>> _don't_ catch ValueError. Any non-integer value will then noisily >>> abort the script. (It may be worth checking for blank first, though, >>> depending on the data origin.) >> Well, when I said you should catch the ValueError I didn't imply you should >> ignore the error and supress any error messages. Of course this depents on >> the use case. Maybe you want to raise another exception with a more user >> friendly error message or you might want to skip the line and just print a >> warning. :) >> >> What I'm trying to say: When I give a script/program to a user who is not a >> python programmer I don't want him to see an error message like "ValueError: >> invalid literal for int() with base 10: 'abc'" as this would help him in no >> way. > Sure. Definitely. But for a proglet where the programmer IS the user > (which I think is one of Python's best use-cases), that exception > landing on the console is better than having to think ahead of time > about what might go wrong. > > ChrisA Okay, I absolutely agree with that :) Tobias From insideshoes at gmail.com Thu Jan 24 07:29:43 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Thu, 24 Jan 2013 13:29:43 +0100 Subject: using split for a string : error In-Reply-To: <510124A5.6080701@tobix.eu> References: <51011822.3020702@tobix.eu> <510121F9.70508@tobix.eu> <510124A5.6080701@tobix.eu> Message-ID: Thanks a lot people.. :).. :) On Thu, Jan 24, 2013 at 1:10 PM, Tobias M. wrote: > Am 24.01.2013 13:02, schrieb Chris Angelico: > > On Thu, Jan 24, 2013 at 10:58 PM, Tobias M. wrote: >> >>> Chris Angelico wrote: >>> >>>> I'd not consider the performance, but the correctness. If you're >>>> expecting them to be integers, just cast them, and specifically >>>> _don't_ catch ValueError. Any non-integer value will then noisily >>>> abort the script. (It may be worth checking for blank first, though, >>>> depending on the data origin.) >>>> >>> Well, when I said you should catch the ValueError I didn't imply you >>> should >>> ignore the error and supress any error messages. Of course this depents >>> on >>> the use case. Maybe you want to raise another exception with a more user >>> friendly error message or you might want to skip the line and just print >>> a >>> warning. :) >>> >>> What I'm trying to say: When I give a script/program to a user who is >>> not a >>> python programmer I don't want him to see an error message like >>> "ValueError: >>> invalid literal for int() with base 10: 'abc'" as this would help him in >>> no >>> way. >>> >> Sure. Definitely. But for a proglet where the programmer IS the user >> (which I think is one of Python's best use-cases), that exception >> landing on the console is better than having to think ahead of time >> about what might go wrong. >> >> ChrisA >> > Okay, I absolutely agree with that :) > > Tobias > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Thu Jan 24 20:03:21 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 25 Jan 2013 01:03:21 +0000 Subject: using split for a string : error In-Reply-To: References: <51011822.3020702@tobix.eu> Message-ID: On 24 January 2013 11:35, Chris Angelico wrote: > > It's usually fine to have int() complain about any non-numerics in the > string, but I must confess, I do sometimes yearn for atoi() semantics: > atoi("123asd") == 123, and atoi("qqq") == 0. I've not seen a > convenient Python function for doing that. Usually it involves > manually getting the digits off the front. All I want is to suppress > the error on finding a non-digit. Oh well. > I'm interested to know what the situations are where you want the behaviour of atoi(). Personally, I consider the int() function too permissive because of its behaviour in truncating non-integer numeric types. But then that's because I'm always paranoid that the values of my precious numbers are being changed without my knowledge. From my vantage point I really can't see why the ambiguous behaviour of atoi() would actually be desired by anyone (unless they were stuck using a language that made string manipulation generally a bit awkward). Oscar From rosuav at gmail.com Thu Jan 24 20:11:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 12:11:41 +1100 Subject: using split for a string : error In-Reply-To: References: <51011822.3020702@tobix.eu> Message-ID: On Fri, Jan 25, 2013 at 12:03 PM, Oscar Benjamin wrote: > On 24 January 2013 11:35, Chris Angelico wrote: >> >> It's usually fine to have int() complain about any non-numerics in the >> string, but I must confess, I do sometimes yearn for atoi() semantics: >> atoi("123asd") == 123, and atoi("qqq") == 0. I've not seen a >> convenient Python function for doing that. Usually it involves >> manually getting the digits off the front. All I want is to suppress >> the error on finding a non-digit. Oh well. >> > > I'm interested to know what the situations are where you want the > behaviour of atoi(). It simplifies operations on strings that contain numbers. For instance, here's a problem from yesterday. I have a set of files (MIDI files of The Rose of Persia) which have been sloppily numbered: Rose_1.mid Rose_10.mid Rose_11.mid Rose_12.mid Rose_13.mid Rose_14.mid Rose_15.mid Rose_16.mid Rose_17.mid Rose_18.mid Rose_19.mid Rose_2.mid Rose_20.mid Rose_21.mid Rose_22.mid Rose_23.mid Rose_24.mid Rose_3.mid Rose_4.mid Rose_5.mid Rose_6.mid Rose_7.mid Rose_8.mid Rose_9.mid Rose_Int.mid They're not in order. The one marked "Int" is the Introduction and should be first; then Rose_1 ... Rose_9, then Rose_10 ... Rose_24. In fact, the correct sort order is exactly: atoi(filename[5:]) Most of the time, it makes no difference. Python's int() will do exactly what atoi() does. It's only in the unusual case where they even differ. ChrisA From oscar.j.benjamin at gmail.com Thu Jan 24 20:33:52 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 25 Jan 2013 01:33:52 +0000 Subject: using split for a string : error In-Reply-To: References: <51011822.3020702@tobix.eu> Message-ID: On 25 January 2013 01:11, Chris Angelico wrote: > On Fri, Jan 25, 2013 at 12:03 PM, Oscar Benjamin > wrote: >> On 24 January 2013 11:35, Chris Angelico wrote: >>> >>> It's usually fine to have int() complain about any non-numerics in the >>> string, but I must confess, I do sometimes yearn for atoi() semantics: >>> atoi("123asd") == 123, and atoi("qqq") == 0. I've not seen a >>> convenient Python function for doing that. Usually it involves >>> manually getting the digits off the front. All I want is to suppress >>> the error on finding a non-digit. Oh well. >>> >> >> I'm interested to know what the situations are where you want the >> behaviour of atoi(). > > It simplifies operations on strings that contain numbers. For > instance, here's a problem from yesterday. I have a set of files (MIDI > files of The Rose of Persia) which have been sloppily numbered: > > Rose_1.mid > Rose_10.mid > Rose_11.mid > Rose_12.mid > Rose_13.mid > Rose_14.mid > Rose_15.mid > Rose_16.mid > Rose_17.mid > Rose_18.mid > Rose_19.mid > Rose_2.mid > Rose_20.mid > Rose_21.mid > Rose_22.mid > Rose_23.mid > Rose_24.mid > Rose_3.mid > Rose_4.mid > Rose_5.mid > Rose_6.mid > Rose_7.mid > Rose_8.mid > Rose_9.mid > Rose_Int.mid > > They're not in order. The one marked "Int" is the Introduction and > should be first; then Rose_1 ... Rose_9, then Rose_10 ... Rose_24. In > fact, the correct sort order is exactly: > > atoi(filename[5:]) I have solved similar situations with sorted(filenames, key=lambda s: (len(s), s)) which is better than lexicographical ordering for sorting integer strings. It gets the _Int file wrong in this case (but I consider it luck that atoi does what you want for that file). Oscar From rosuav at gmail.com Thu Jan 24 20:39:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 12:39:18 +1100 Subject: using split for a string : error In-Reply-To: References: <51011822.3020702@tobix.eu> Message-ID: On Fri, Jan 25, 2013 at 12:33 PM, Oscar Benjamin wrote: > I have solved similar situations with > sorted(filenames, key=lambda s: (len(s), s)) > which is better than lexicographical ordering for sorting integer > strings. It gets the _Int file wrong in this case (but I consider it > luck that atoi does what you want for that file). Yep. Now give me an easy way to rename them all so that the glob *.mid will produce them in the right order. BTW, there's no guarantee that the files have no gaps; some other directories have things like Iol_08_11.mid being followed by Iol_12.mid - I'd rather not renumber them based on their indices in the final list. But like I said, it's an unusual case. ChrisA From neilc at norwich.edu Fri Jan 25 09:04:02 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 25 Jan 2013 14:04:02 GMT Subject: using split for a string : error References: <51011822.3020702@tobix.eu> Message-ID: On 2013-01-25, Oscar Benjamin wrote: > On 24 January 2013 11:35, Chris Angelico wrote: >> It's usually fine to have int() complain about any >> non-numerics in the string, but I must confess, I do sometimes >> yearn for atoi() semantics: atoi("123asd") == 123, and >> atoi("qqq") == 0. I've not seen a convenient Python function >> for doing that. Usually it involves manually getting the >> digits off the front. All I want is to suppress the error on >> finding a non-digit. Oh well. > > I'm interested to know what the situations are where you want > the behaviour of atoi(). Right. atoi is no good even in C. You get much better control using the sprintf family. int would need to return a tuple of the number it found plus the number of characters consumed to be more useful for parsing. >>> intparse("123abc") (123, 3) But that would make it might inconvenient for general use. -- Neil Cerutti From hansmu at xs4all.nl Fri Jan 25 09:31:21 2013 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 25 Jan 2013 15:31:21 +0100 Subject: using split for a string : error In-Reply-To: References: <51011822.3020702@tobix.eu> Message-ID: <51029739$0$6876$e4fe514c@news2.news.xs4all.nl> On 25/01/13 15:04:02, Neil Cerutti wrote: > On 2013-01-25, Oscar Benjamin wrote: >> On 24 January 2013 11:35, Chris Angelico wrote: >>> It's usually fine to have int() complain about any >>> non-numerics in the string, but I must confess, I do sometimes >>> yearn for atoi() semantics: atoi("123asd") == 123, and >>> atoi("qqq") == 0. I've not seen a convenient Python function >>> for doing that. Usually it involves manually getting the >>> digits off the front. All I want is to suppress the error on >>> finding a non-digit. Oh well. >> >> I'm interested to know what the situations are where you want >> the behaviour of atoi(). > > Right. atoi is no good even in C. You get much better control > using the sprintf family. I think you meant sscanf. It's true that sscanf gives you more control. That being said, sometimes the one option atoi gives you, just happens to be what you need. > int would need to return a tuple of the > number it found plus the number of characters consumed to be more > useful for parsing. > >>>> intparse("123abc") > (123, 3) > > But that would make it might inconvenient for general use. If the new function is nameed intparse, and the existing int function remains available, then most use cases would be served by int, and intparse would be available as a building block for other use cases. For example atoi could be defined as: def atoi(s): return intparse(s)[0] intparse("xyz") should return (0, 0), and leave it to the caller to decide whether a ValueError shoud be raised. -- HansM From joel.goldstick at gmail.com Fri Jan 25 09:44:03 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 25 Jan 2013 09:44:03 -0500 Subject: using split for a string : error In-Reply-To: <51029739$0$6876$e4fe514c@news2.news.xs4all.nl> References: <51011822.3020702@tobix.eu> <51029739$0$6876$e4fe514c@news2.news.xs4all.nl> Message-ID: Don't forget to look at csv reader. http://docs.python.org/2/library/csv.html On Fri, Jan 25, 2013 at 9:31 AM, Hans Mulder wrote: > On 25/01/13 15:04:02, Neil Cerutti wrote: > > On 2013-01-25, Oscar Benjamin wrote: > >> On 24 January 2013 11:35, Chris Angelico wrote: > >>> It's usually fine to have int() complain about any > >>> non-numerics in the string, but I must confess, I do sometimes > >>> yearn for atoi() semantics: atoi("123asd") == 123, and > >>> atoi("qqq") == 0. I've not seen a convenient Python function > >>> for doing that. Usually it involves manually getting the > >>> digits off the front. All I want is to suppress the error on > >>> finding a non-digit. Oh well. > >> > >> I'm interested to know what the situations are where you want > >> the behaviour of atoi(). > > > > Right. atoi is no good even in C. You get much better control > > using the sprintf family. > > I think you meant sscanf. > > It's true that sscanf gives you more control. That being said, > sometimes the one option atoi gives you, just happens to be what > you need. > > > int would need to return a tuple of the > > number it found plus the number of characters consumed to be more > > useful for parsing. > > > >>>> intparse("123abc") > > (123, 3) > > > > But that would make it might inconvenient for general use. > > If the new function is nameed intparse, and the existing int > function remains available, then most use cases would be served > by int, and intparse would be available as a building block for > other use cases. For example atoi could be defined as: > > def atoi(s): return intparse(s)[0] > > intparse("xyz") should return (0, 0), and leave it to the caller > to decide whether a ValueError shoud be raised. > > > -- HansM > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Fri Jan 25 10:14:53 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 25 Jan 2013 15:14:53 GMT Subject: using split for a string : error References: <51011822.3020702@tobix.eu> <51029739$0$6876$e4fe514c@news2.news.xs4all.nl> Message-ID: On 2013-01-25, Hans Mulder wrote: >> Right. atoi is no good even in C. You get much better control >> using the sprintf family. > > I think you meant sscanf. Yes, thanks for knocking that huge chunk of rust off of me. ;) -- Neil Cerutti From steve+comp.lang.python at pearwood.info Thu Jan 24 19:20:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 25 Jan 2013 11:20:42 +1100 Subject: using split for a string : error References: <51011822.3020702@tobix.eu> Message-ID: <5101cfdb$0$29980$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > It's usually fine to have int() complain about any non-numerics in the > string, but I must confess, I do sometimes yearn for atoi() semantics: > atoi("123asd") == 123, and atoi("qqq") == 0. I've not seen a > convenient Python function for doing that. Usually it involves > manually getting the digits off the front. All I want is to suppress > the error on finding a non-digit. Oh well. It's easy enough to write your own. All you need do is decide what you mean by "suppress the error on finding a non-digit". Should atoi("123xyz456") return 123 or 123456? Should atoi("xyz123") return 0 or 123? And here's a good one: Should atoi("1OOl") return 1, 100, or 1001? That last is a serious suggestion by the way. There are still many people who do not distinguish between 1 and l or 0 and O. Actually I lied. It's not that easy. Consider: py> s = '???' py> int(s) 129 Actually I lied again. It's not that hard: def atoi(s): from unicodedata import digit i = 0 for c in s: i *= 10 i += digit(c, 0) return i Variations that stop on the first non-digit, instead of treating them as zero, are not much more difficult. -- Steven From rosuav at gmail.com Thu Jan 24 20:07:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 12:07:35 +1100 Subject: using split for a string : error In-Reply-To: <5101cfdb$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <51011822.3020702@tobix.eu> <5101cfdb$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 25, 2013 at 11:20 AM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> It's usually fine to have int() complain about any non-numerics in the >> string, but I must confess, I do sometimes yearn for atoi() semantics: >> atoi("123asd") == 123, and atoi("qqq") == 0. I've not seen a >> convenient Python function for doing that. Usually it involves >> manually getting the digits off the front. All I want is to suppress >> the error on finding a non-digit. Oh well. > > It's easy enough to write your own. All you need do is decide what you > mean by "suppress the error on finding a non-digit". > > Should atoi("123xyz456") return 123 or 123456? > > Should atoi("xyz123") return 0 or 123? > > And here's a good one: > > Should atoi("1OOl") return 1, 100, or 1001? 123, 0, and 1. That's standard atoi semantics. > That last is a serious suggestion by the way. There are still many people > who do not distinguish between 1 and l or 0 and O. Sure. But I'm not trying to cater to people who get it wrong; that's a job for a DWIM. > def atoi(s): > from unicodedata import digit > i = 0 > for c in s: > i *= 10 > i += digit(c, 0) > return i > > Variations that stop on the first non-digit, instead of treating them as > zero, are not much more difficult. And yes, I'm fully aware that I can roll my own. Here's a shorter version (ASCII digits only, feel free to expand to Unicode), not necessarily better: def atoi(s): return int("0"+s[:-len(s.lstrip("0123456789"))]) It just seems silly that this should have to be done separately, when it's really just a tweak to the usual string-to-int conversion: when you come to a non-digit, take one of three options (throw error, skip, or terminate). Anyway, not a big deal. ChrisA From nikos.gr33k at gmail.com Thu Jan 24 06:04:46 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 03:04:46 -0800 (PST) Subject: mysql solution Message-ID: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> # insert new page record in table counters or update it if already exists try: cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) # update existing visitor record if same pin and same host found try: cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # insert new visitor record if above update did not affect a row if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) ====================================================== I;am now convinced the hash solution isn't reversible and also isn't unique. I'am trying the database oriented solution. pin column = 5-digit integer Primary Key. When i'am inserting a new record to table counters, a sequenced number is crated as pin. Thats works ok. But when i try to Update or Insert into the visitors table the 'pin' comunn is needed to to identify the rrecord for which iam trying to update like here: ================================ cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) ================================ how is the mysql statement is going to find the 'pin' to update the specific record. And also in here: ================================ if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(pin, hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s, %s)''', (pin, 1, host, useros, browser, date) ) ================================ 'pin' column's value is also need to make insert From rosuav at gmail.com Thu Jan 24 06:16:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 22:16:51 +1100 Subject: mysql solution In-Reply-To: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: On Thu, Jan 24, 2013 at 10:04 PM, Ferrous Cranus wrote: > I;am now convinced the hash solution isn't reversible and also isn't unique. > I'am trying the database oriented solution. Glad you've listened to at least some of what you've been told. But if you want to be taken seriously on this list, I recommend going back to your previous name of ???????? ?????? (which Google Translate tells me transliterates as Nicholas Kouri), apologizing for trolling, and being VERY careful to be respectful. I suspect a number of the list's best posters have already killfiled you. ChrisA From lele at metapensiero.it Thu Jan 24 06:25:20 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 24 Jan 2013 12:25:20 +0100 Subject: mysql solution References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: <87pq0u961r.fsf@metapensiero.it> Ferrous Cranus writes: > I;am now convinced the hash solution isn't reversible and also isn't > unique. Great! > how is the mysql statement is going to find the 'pin' to update the > specific record. The simplest way is to execute a SELECT just after the insertion, doing a SELECT pin FROM counters WHERE page = %s I don't use MySQL, so I can't say if it supports "INSERT ... RETURNING ..." SQL syntax: should it, then you could insert the data and fetch the pin in one shot, with something like INSERT INTO counters (page, hits) VALUES (%s, %s) RETURNING (pin) ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From rosuav at gmail.com Thu Jan 24 06:29:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Jan 2013 22:29:05 +1100 Subject: mysql solution In-Reply-To: <87pq0u961r.fsf@metapensiero.it> References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <87pq0u961r.fsf@metapensiero.it> Message-ID: On Thu, Jan 24, 2013 at 10:25 PM, Lele Gaifax wrote: > The simplest way is to execute a SELECT just after the insertion, doing > a > > SELECT pin FROM counters WHERE page = %s > > I don't use MySQL, so I can't say if it supports "INSERT ... RETURNING ..." > SQL syntax: should it, then you could insert the data and fetch > the pin in one shot, with something like > > INSERT INTO counters (page, hits) VALUES (%s, %s) RETURNING (pin) AFAIK it doesn't, but if pin is an AUTO_INCREMENT primary key, you can retrieve the ID of the newly inserted record. It's not nearly as flexible as INSERT... RETURNING, but it covers the most common use case. ChrisA From nikos.gr33k at gmail.com Thu Jan 24 07:01:40 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 04:01:40 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> ?? ??????, 24 ?????????? 2013 1:25:20 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > Ferrous Cranus writes: > > > > > I;am now convinced the hash solution isn't reversible and also isn't > > > unique. > > > > Great! > > > > > how is the mysql statement is going to find the 'pin' to update the > > > specific record. > > > > The simplest way is to execute a SELECT just after the insertion, doing > > a > > > > SELECT pin FROM counters WHERE page = %s > > > > I don't use MySQL, so I can't say if it supports "INSERT ... RETURNING ..." > > SQL syntax: should it, then you could insert the data and fetch > > the pin in one shot, with something like > > > > INSERT INTO counters (page, hits) VALUES (%s, %s) RETURNING (pin) > > > > ciao, lele. > > -- > > nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri > > real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. > > lele at metapensiero.it | -- Fortunato Depero, 1929. I just tried this statement: ========================================== cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNING (pin) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) ========================================== and the error python tells me is: : 'ProgrammingError' object has no attribute 'excepinfo' args = ("'ProgrammingError' object has no attribute 'excepinfo'",) message = "'ProgrammingError' object has no attribute 'excepinfo'" From nikos.gr33k at gmail.com Thu Jan 24 07:01:40 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 04:01:40 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> ?? ??????, 24 ?????????? 2013 1:25:20 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > Ferrous Cranus writes: > > > > > I;am now convinced the hash solution isn't reversible and also isn't > > > unique. > > > > Great! > > > > > how is the mysql statement is going to find the 'pin' to update the > > > specific record. > > > > The simplest way is to execute a SELECT just after the insertion, doing > > a > > > > SELECT pin FROM counters WHERE page = %s > > > > I don't use MySQL, so I can't say if it supports "INSERT ... RETURNING ..." > > SQL syntax: should it, then you could insert the data and fetch > > the pin in one shot, with something like > > > > INSERT INTO counters (page, hits) VALUES (%s, %s) RETURNING (pin) > > > > ciao, lele. > > -- > > nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri > > real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. > > lele at metapensiero.it | -- Fortunato Depero, 1929. I just tried this statement: ========================================== cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNING (pin) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) ========================================== and the error python tells me is: : 'ProgrammingError' object has no attribute 'excepinfo' args = ("'ProgrammingError' object has no attribute 'excepinfo'",) message = "'ProgrammingError' object has no attribute 'excepinfo'" From lele at metapensiero.it Thu Jan 24 07:22:26 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 24 Jan 2013 13:22:26 +0100 Subject: mysql solution References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> Message-ID: <87libi93el.fsf@metapensiero.it> Ferrous Cranus writes: > ?? ??????, 24 ?????????? 2013 1:25:20 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: Please, trim your response messages, cutting away useless details. > > I just tried this statement: > > ========================================== > cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNING (pin) > ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > ========================================== > > and the error python tells me is: > > : 'ProgrammingError' object has no attribute 'excepinfo' > args = ("'ProgrammingError' object has no attribute 'excepinfo'",) > message = "'ProgrammingError' object has no attribute 'excepinfo'" As the error message says, you have a typo in your exception handler. I suggest using the logging[1] module to print out such information, as it expose a bunch of handy methods that make it easier to print the exception, for example: ... except MySQLdb.Error: logging.error('Query Error!', exc_info=True) or even ... except MySQLdb.Error: logging.exception('Query Error!') ciao, lele. [1] http://docs.python.org/2.7/library/logging.html#module-logging -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From nikos.gr33k at gmail.com Thu Jan 24 08:24:15 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 05:24:15 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> Message-ID: <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> column 'pin' is an 5-digit integer auto_increment primary key. What i want is to insert a new record or update the existing one, if 'pin' column's value exist. The following statement fails. [code] cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNING (pin) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) [/code] Also except from the inserting/updating job, i also need 'pin' colum's value to be extracted from the above statement so to be used to subsequent statement like the following. This is not happening, hence the following statement have no way to find 'pin' column's value which is to be used as a parameter to it. [code] cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) [/code] Can someone correct this please and explain? From nikos.gr33k at gmail.com Thu Jan 24 08:24:15 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 05:24:15 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> Message-ID: <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> column 'pin' is an 5-digit integer auto_increment primary key. What i want is to insert a new record or update the existing one, if 'pin' column's value exist. The following statement fails. [code] cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNING (pin) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) [/code] Also except from the inserting/updating job, i also need 'pin' colum's value to be extracted from the above statement so to be used to subsequent statement like the following. This is not happening, hence the following statement have no way to find 'pin' column's value which is to be used as a parameter to it. [code] cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) [/code] Can someone correct this please and explain? From lele at metapensiero.it Thu Jan 24 08:37:24 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 24 Jan 2013 14:37:24 +0100 Subject: mysql solution References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: <87ham68zxn.fsf@metapensiero.it> Ferrous Cranus writes: > The following statement fails. > > [code] > cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNING (pin) > ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) > [/code] How? What's the error message/traceback? If, as Chris said, MySQL does not support the ?RETURNING? syntax, you cannot use that. I gave two different solutions in my previous message, did you try the ?simplest? one? ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From nikos.gr33k at gmail.com Thu Jan 24 09:35:35 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 06:35:35 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: <00fb394a-15c4-43dd-8a94-86d1c7c307d6@googlegroups.com> ?? ??????, 24 ?????????? 2013 3:37:24 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > How? What's the error message/traceback? REURNING is not a correct mysql syntax thats why it produces errors. > If, as Chris said, MySQL does not support the ?RETURNING? syntax, you > > cannot use that. I gave two different solutions in my previous message, > > did you try the ?simplest? one? SELECT pin FROM counters WHERE page = %s I can do that but then i have to use that pin column's value in my next statement. cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) From nikos.gr33k at gmail.com Thu Jan 24 09:35:35 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 06:35:35 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: <00fb394a-15c4-43dd-8a94-86d1c7c307d6@googlegroups.com> ?? ??????, 24 ?????????? 2013 3:37:24 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > How? What's the error message/traceback? REURNING is not a correct mysql syntax thats why it produces errors. > If, as Chris said, MySQL does not support the ?RETURNING? syntax, you > > cannot use that. I gave two different solutions in my previous message, > > did you try the ?simplest? one? SELECT pin FROM counters WHERE page = %s I can do that but then i have to use that pin column's value in my next statement. cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) From duncan.booth at invalid.invalid Thu Jan 24 10:19:53 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 24 Jan 2013 15:19:53 GMT Subject: mysql solution References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: Ferrous Cranus wrote: > I can do that but then i have to use that pin column's value in my > next statement. > > cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, > browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, > browser, date, pin, host)) I'm not MySQL expert, but something like this might work: cursor.execute('''UPDATE visitors,counter SET visitors.hits=visitors.hits+1, visitors.useros=%s, visitors.browser =%s, visitors.date=%s WHERE visitors.pin=counter.pin AND counter.page = %s AND visitors.host=%s''', (useros, browser, date, page, host)) -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Thu Jan 24 10:27:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 02:27:03 +1100 Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: On Fri, Jan 25, 2013 at 2:19 AM, Duncan Booth wrote: > Ferrous Cranus wrote: > >> I can do that but then i have to use that pin column's value in my >> next statement. >> >> cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, >> browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, >> browser, date, pin, host)) > > I'm not MySQL expert, but something like this might work: > > cursor.execute('''UPDATE visitors,counter > SET visitors.hits=visitors.hits+1, visitors.useros=%s, > visitors.browser =%s, visitors.date=%s > WHERE visitors.pin=counter.pin AND counter.page = %s > AND visitors.host=%s''', > (useros, browser, date, page, host)) Not sure that that works. This should, though: UPDATE visitors SET hits=hits+1,blah,blah WHERE visitors.pin=(SELECT pin FROM counter WHERE page=%s) I prefer not to mention a table for updating if it's not actually being updated. ChrisA From lele at metapensiero.it Thu Jan 24 10:39:54 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 24 Jan 2013 16:39:54 +0100 Subject: mysql solution References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: <87d2wu8u9h.fsf@metapensiero.it> Duncan Booth writes: > I'm not MySQL expert, but something like this might work: > > cursor.execute('''UPDATE visitors,counter > SET visitors.hits=visitors.hits+1, visitors.useros=%s, > visitors.browser =%s, visitors.date=%s > WHERE visitors.pin=counter.pin AND counter.page = %s > AND visitors.host=%s''', > (useros, browser, date, page, host)) I stopped surprising at MySQL syntax eons ago, so if that works... great! Otherwise I would write the equivalent statement with a more "standard syntax" (for whatever meaning of "standard" in the SQL world :-) as: UPDATE visitors SET visitors.hits=visitors.hits+1, visitors.useros=%s, visitors.browser=%s, visitors.date=%s WHERE visitors.pin=(SELECT counters.pin FROM counters WHERE counters.page=%s) AND visitors.host=%s But I wonder about the "logic" here: why are you storing the "useros", "browser" and "date" in a table where the primary key seems to be ("pin", "host")? I mean, what happens if a user visits the same page twice, first with Firefox and then with Chrome? hope this helps, ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From nikos.gr33k at gmail.com Thu Jan 24 13:22:30 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 10:22:30 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: ?? ??????, 24 ?????????? 2013 5:39:54 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > UPDATE visitors > > SET visitors.hits=visitors.hits+1, > > visitors.useros=%s, > > visitors.browser=%s, > > visitors.date=%s > > WHERE visitors.pin=(SELECT counters.pin > > FROM counters > > WHERE counters.page=%s) > > AND visitors.host=%s > > > > But I wonder about the "logic" here: why are you storing the "useros", > > "browser" and "date" in a table where the primary key seems to be > > ("pin", "host")? I mean, what happens if a user visits the same page > > twice, first with Firefox and then with Chrome? it doesn't work, it creates new entries on every webpage visit instead of updating. this is what i have up until now: [code] # insert new page record in table counters or update it if already exists try: cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # update existing visitor record if same pin and same host found try: cursor.execute('''UPDATE visitors SET hits=hits+1, useros=%s, browser=%s, date=%s WHERE id=(SELECT id FROM counters WHERE page=%s) AND host=%s''', (useros, browser, date, htmlpage, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # insert new visitor record if above update did not affect a row if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) [/code] Something is definately wrong here, its logic is not correct..... From nikos.gr33k at gmail.com Thu Jan 24 13:22:30 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 10:22:30 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <774065a6-3d15-4cff-88d8-7f822ed1c0b0@googlegroups.com> <25438e79-de00-463d-9ae3-7ea63e282e4a@googlegroups.com> Message-ID: ?? ??????, 24 ?????????? 2013 5:39:54 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > UPDATE visitors > > SET visitors.hits=visitors.hits+1, > > visitors.useros=%s, > > visitors.browser=%s, > > visitors.date=%s > > WHERE visitors.pin=(SELECT counters.pin > > FROM counters > > WHERE counters.page=%s) > > AND visitors.host=%s > > > > But I wonder about the "logic" here: why are you storing the "useros", > > "browser" and "date" in a table where the primary key seems to be > > ("pin", "host")? I mean, what happens if a user visits the same page > > twice, first with Firefox and then with Chrome? it doesn't work, it creates new entries on every webpage visit instead of updating. this is what i have up until now: [code] # insert new page record in table counters or update it if already exists try: cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # update existing visitor record if same pin and same host found try: cursor.execute('''UPDATE visitors SET hits=hits+1, useros=%s, browser=%s, date=%s WHERE id=(SELECT id FROM counters WHERE page=%s) AND host=%s''', (useros, browser, date, htmlpage, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # insert new visitor record if above update did not affect a row if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) [/code] Something is definately wrong here, its logic is not correct..... From nikos.gr33k at gmail.com Thu Jan 24 08:31:44 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 05:31:44 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: <7b2026c4-0a2e-4d18-8520-2e50061d501e@googlegroups.com> ?? ??????, 24 ?????????? 2013 1:16:51 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Jan 24, 2013 at 10:04 PM, Ferrous Cranus wrote: > > > I;am now convinced the hash solution isn't reversible and also isn't unique. > > > I'am trying the database oriented solution. > > > > Glad you've listened to at least some of what you've been told. But if > > you want to be taken seriously on this list, I recommend going back to > > your previous name of ???????? ?????? (which Google Translate tells me > > transliterates as Nicholas Kouri), apologizing for trolling, and being > > VERY careful to be respectful. I suspect a number of the list's best > > posters have already killfiled you. First of all i'am not trolling, it looks like i'am trolling because i persist "on my way" of handling a problem. Secondly, why go back to that handle? From nikos.gr33k at gmail.com Thu Jan 24 08:31:44 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Thu, 24 Jan 2013 05:31:44 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: <7b2026c4-0a2e-4d18-8520-2e50061d501e@googlegroups.com> ?? ??????, 24 ?????????? 2013 1:16:51 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Jan 24, 2013 at 10:04 PM, Ferrous Cranus wrote: > > > I;am now convinced the hash solution isn't reversible and also isn't unique. > > > I'am trying the database oriented solution. > > > > Glad you've listened to at least some of what you've been told. But if > > you want to be taken seriously on this list, I recommend going back to > > your previous name of ???????? ?????? (which Google Translate tells me > > transliterates as Nicholas Kouri), apologizing for trolling, and being > > VERY careful to be respectful. I suspect a number of the list's best > > posters have already killfiled you. First of all i'am not trolling, it looks like i'am trolling because i persist "on my way" of handling a problem. Secondly, why go back to that handle? From rosuav at gmail.com Thu Jan 24 09:46:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 01:46:45 +1100 Subject: mysql solution In-Reply-To: <7b2026c4-0a2e-4d18-8520-2e50061d501e@googlegroups.com> References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <7b2026c4-0a2e-4d18-8520-2e50061d501e@googlegroups.com> Message-ID: On Fri, Jan 25, 2013 at 12:31 AM, Ferrous Cranus wrote: > ?? ??????, 24 ?????????? 2013 1:16:51 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> Glad you've listened to at least some of what you've been told. But if >> you want to be taken seriously on this list, I recommend going back to >> your previous name of ???????? ?????? (which Google Translate tells me >> transliterates as Nicholas Kouri), apologizing for trolling, and being >> VERY careful to be respectful. I suspect a number of the list's best >> posters have already killfiled you. > > First of all i'am not trolling, it looks like i'am trolling because i persist "on my way" of handling a problem. Then why do you use, as your name, something which everyone who tries a quick web search will see is the name of a category of troll? And, what's more, a category which clearly includes you? Python believes in "duck typing". Instead of writing a function that expects a File object, Python tends toward writing functions that expect an object that can be given data to write() out. Or, instead of looking for an integer, Python code will look for "something that can be added to 5". In the same way, we on this list do not ask "are you a troll". We ask "does your behaviour match that of a troll". You are treated as a troll because you act like one. > Secondly, why go back to that handle? That said, though, carrying the name of a troll doesn't help. Using your real name is the best way to get started. If you want to win respect, you want to win it for yourself, not for some strange title. (There are exceptions to that principle. Some people on the list don't use their names, and I'm on another list where one of the regular posters freely admits that the name "John Spartan" isn't actually his. But in general, you should use your real name.) Among geeks (and this list/newsgroup is full of them), respect is everything. You earn it, you give it. The best ways to earn respect are to give respect and to contribute to the community. Contributing is fairly obvious; answering questions, helping out, submitting patches, triaging bugs, reviewing and confirming bug reports. Stuff that takes time and benefits other people. The "top dogs" in a geeky community are usually the ones who give the most time. I've no idea how many hours Guido puts into Python, but it'll be rather a lot. Giving respect is a little harder to define, but just as important. The main thing to remember is that we, here, helping you, are volunteers. Nobody is paying us to solve your problems, especially not you yourself. Demanding that we solve your problems is NOT respectful. Offering us interesting problems (which we enjoy), following up courteously, helping to maintain the community's standards (even in supposedly-trivial matters like bottom-posting), and doing your own work before asking for help, ARE. I recently dropped someone a private note thanking him for the way he phrased his question, because it made for a very interesting little puzzle, and he'd clearly put work into it. It was a pleasure to help him, cliche though that sound. He was respectful of the time people would put in, and afterward of the time they had put in, and thus he won respect. Ferrous/Nicholas, you are currently looking like that very worst thing on a mailing list: an open-ended time sink. You are looking like you'll cost huge numbers of smart-person-hours (that's like man-hours but not gender specific, or like programmer-hours but less mythical) with little or no benefit to the community. Continue down this path and you will find yourself with nobody to talk to, as everyone will decide that the best use of time is to delete your posts unread. ChrisA From nikos.gr33k at gmail.com Fri Jan 25 10:43:53 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 25 Jan 2013 07:43:53 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: ?? ??????, 24 ?????????? 2013 10:43:59 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Thu, 24 Jan 2013 03:04:46 -0800 (PST), Ferrous Cranus > > declaimed the following in > > gmane.comp.python.general: > > > > > # insert new page record in table counters or update it if already exists > > > try: > > > cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) > > > ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) > > > except MySQLdb.Error, e: > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > > > # update existing visitor record if same pin and same host found > > > try: > > > cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) > > > except MySQLdb.Error, e: > > > print ( "Error %d: %s" % (e.args[0], e.args[1]) ) > > > > > > # insert new visitor record if above update did not affect a row > > > if cursor.rowcount == 0: > > > cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) > > > > > > > Seeing the database schema would help. At present I have no idea > > what is defined as a key, what may be a foreign key, etc. > > > > For example: you show a "counters" table in which you are saving > > "hits" per page (I presume the URL is being saved). But the very next > > thing you are doing is something with a hit count in a "visitors" table > > which appears to be keyed by the combination of "host" and "pin" -- but > > you've failed to provide "pin" on the INSERT. > > > > Furthermore, your "visitors" table is only saving the most recent > > "useros" and "browser" data... Is that what you really want -- or do you > > want to log ALL users that visit the page. > > > > Making presumptions, I'd probably have something like: > > > > SCHEMA: > > > > create table counters > > ( > > ID integer not null auto_increment primary key, > > URL varchar(255) not null, > > hits integer not null default 1, > > unique index (URL) > > ); > > > > create table visitors > > ( > > ID integer not null auto_increment primary key, > > counterID integer not null, > > host varchar(255) not null, > > userOS varchar(255) not null, > > browser varchar(255) not null, > > hits integer not null default 1, > > lastVisit datetime not null, > > foreign key (counterID) references counters (ID), > > unique index (counterID, host) > > ); > > > > -=-=-=- > > > > con = db.connection() > > > > cur = con.cursor() > > > > try: > > #find the needed counter for the page URL > > cur.execute("select ID from counters where URL = %s", (htmlpage, ) ) > > data = cur.fetchone() #URL is unique, so should only be one > > if not data: > > #first time for page; primary key is automatic, hit is defaulted > > cur.execute("insert into counters (URL) values (%s)", > > (htmlpage,) ) > > cID = cur.lastrowid #get the primary key value of the new record > > else: > > #found the page, save primary key and use it to issue hit update > > cID = data[0] > > cur.execute("update counters set hits = hits + 1 where ID = %s", > > (cID,) ) > > > > #find the visitor record for the (saved) cID and current host > > cur.execute("""select ID from visitors > > where counterID = %s > > and host = %s""", > > (cID, host) ) > > data = cur.fetchone() #cID&host are unique > > if not data: > > #first time for this host on this page, create new record > > cur.execute("""insert into visitors > > (counterID, host, userOS, browser, lastVisit) > > values (%s, %s, %s, %s, %s)""", > > (cID, host, useros, browser, date) ) > > #primary key and hits are defaulted, don't care about key > > else: > > #found the page, save its primary key for later use > > vID = data[0] > > #update record using retrieved vID > > cur.execute("""update visitors set > > userOS = %s, > > browser = %s, > > lastVisit = %s, > > hits = hits + 1 > > where ID = %s""", > > (useros, browser, date, vID) ) > > > > con.commit() #if we made it here, the transaction is complete > > > > except: #blind excepts aren't "good", but you get the idea > > #ANY exception needs to rollback the above sequence > > con.rollback() #something failed, rollback the entire transaction > > print "ERROR DURING hit counter update sequence" > It worked like a charm! Thank you very much! what do you mean by that? " Furthermore, your "visitors" table is only saving the most recent "useros" and "browser" data... Is that what you really want -- or do you want to log ALL users that visit the page. " If the same hostname visits my webpage multiple times i only update the userOS, bwoswer, date information. What do you mean? And also: why does the table 'visitors' ahs to have an auto increment column ID what for? From nikos.gr33k at gmail.com Fri Jan 25 10:43:53 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Fri, 25 Jan 2013 07:43:53 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: ?? ??????, 24 ?????????? 2013 10:43:59 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Thu, 24 Jan 2013 03:04:46 -0800 (PST), Ferrous Cranus > > declaimed the following in > > gmane.comp.python.general: > > > > > # insert new page record in table counters or update it if already exists > > > try: > > > cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) > > > ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) > > > except MySQLdb.Error, e: > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > > > # update existing visitor record if same pin and same host found > > > try: > > > cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, pin, host)) > > > except MySQLdb.Error, e: > > > print ( "Error %d: %s" % (e.args[0], e.args[1]) ) > > > > > > # insert new visitor record if above update did not affect a row > > > if cursor.rowcount == 0: > > > cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) > > > > > > > Seeing the database schema would help. At present I have no idea > > what is defined as a key, what may be a foreign key, etc. > > > > For example: you show a "counters" table in which you are saving > > "hits" per page (I presume the URL is being saved). But the very next > > thing you are doing is something with a hit count in a "visitors" table > > which appears to be keyed by the combination of "host" and "pin" -- but > > you've failed to provide "pin" on the INSERT. > > > > Furthermore, your "visitors" table is only saving the most recent > > "useros" and "browser" data... Is that what you really want -- or do you > > want to log ALL users that visit the page. > > > > Making presumptions, I'd probably have something like: > > > > SCHEMA: > > > > create table counters > > ( > > ID integer not null auto_increment primary key, > > URL varchar(255) not null, > > hits integer not null default 1, > > unique index (URL) > > ); > > > > create table visitors > > ( > > ID integer not null auto_increment primary key, > > counterID integer not null, > > host varchar(255) not null, > > userOS varchar(255) not null, > > browser varchar(255) not null, > > hits integer not null default 1, > > lastVisit datetime not null, > > foreign key (counterID) references counters (ID), > > unique index (counterID, host) > > ); > > > > -=-=-=- > > > > con = db.connection() > > > > cur = con.cursor() > > > > try: > > #find the needed counter for the page URL > > cur.execute("select ID from counters where URL = %s", (htmlpage, ) ) > > data = cur.fetchone() #URL is unique, so should only be one > > if not data: > > #first time for page; primary key is automatic, hit is defaulted > > cur.execute("insert into counters (URL) values (%s)", > > (htmlpage,) ) > > cID = cur.lastrowid #get the primary key value of the new record > > else: > > #found the page, save primary key and use it to issue hit update > > cID = data[0] > > cur.execute("update counters set hits = hits + 1 where ID = %s", > > (cID,) ) > > > > #find the visitor record for the (saved) cID and current host > > cur.execute("""select ID from visitors > > where counterID = %s > > and host = %s""", > > (cID, host) ) > > data = cur.fetchone() #cID&host are unique > > if not data: > > #first time for this host on this page, create new record > > cur.execute("""insert into visitors > > (counterID, host, userOS, browser, lastVisit) > > values (%s, %s, %s, %s, %s)""", > > (cID, host, useros, browser, date) ) > > #primary key and hits are defaulted, don't care about key > > else: > > #found the page, save its primary key for later use > > vID = data[0] > > #update record using retrieved vID > > cur.execute("""update visitors set > > userOS = %s, > > browser = %s, > > lastVisit = %s, > > hits = hits + 1 > > where ID = %s""", > > (useros, browser, date, vID) ) > > > > con.commit() #if we made it here, the transaction is complete > > > > except: #blind excepts aren't "good", but you get the idea > > #ANY exception needs to rollback the above sequence > > con.rollback() #something failed, rollback the entire transaction > > print "ERROR DURING hit counter update sequence" > It worked like a charm! Thank you very much! what do you mean by that? " Furthermore, your "visitors" table is only saving the most recent "useros" and "browser" data... Is that what you really want -- or do you want to log ALL users that visit the page. " If the same hostname visits my webpage multiple times i only update the userOS, bwoswer, date information. What do you mean? And also: why does the table 'visitors' ahs to have an auto increment column ID what for? From nikos.gr33k at gmail.com Sat Jan 26 05:35:42 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 26 Jan 2013 02:35:42 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: <3f50eac6-ea27-46d7-be6b-5efb7f435b07@googlegroups.com> ?? ?????????, 25 ?????????? 2013 11:56:44 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: ===================== #find the visitor record for the (saved) cID and current host cur.execute('''SELECT * FROM visitors WHERE counterID = %s and host = %s''', (cID, host) ) data = cur.fetchone() #cID&host are unique if not data: #first time for this host on this page, create new record cur.execute('''INSERT INTO visitors (counterID, host, userOS, browser, lastvisit) VALUES (%s, %s, %s, %s, %s)''', (cID, host, useros, browser, date) ) else: #found the page, save its primary key for later use vID = data[0] #UPDATE record using retrieved vID cur.execute('''UPDATE visitors SET userOS = %s, browser = %s, hits = hits + 1, lastvisit = %s WHERE counterID = %s and host = %s''', (useros, browser, date, vID, host) ) ======================================= Instead of the above logic which you provided and it works as expected, wouldn't be easier to just: Try to update the 'visitors' record, for that 'page' and that 'host' if update fails(doesnt return any data), then we insert a new record entry. We dont have to check 'SELECT * FROM visitors WHERE counterID = %s and host = %s' first, this one less cursor.execute. From nikos.gr33k at gmail.com Sat Jan 26 05:35:42 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 26 Jan 2013 02:35:42 -0800 (PST) Subject: mysql solution In-Reply-To: References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> Message-ID: <3f50eac6-ea27-46d7-be6b-5efb7f435b07@googlegroups.com> ?? ?????????, 25 ?????????? 2013 11:56:44 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: ===================== #find the visitor record for the (saved) cID and current host cur.execute('''SELECT * FROM visitors WHERE counterID = %s and host = %s''', (cID, host) ) data = cur.fetchone() #cID&host are unique if not data: #first time for this host on this page, create new record cur.execute('''INSERT INTO visitors (counterID, host, userOS, browser, lastvisit) VALUES (%s, %s, %s, %s, %s)''', (cID, host, useros, browser, date) ) else: #found the page, save its primary key for later use vID = data[0] #UPDATE record using retrieved vID cur.execute('''UPDATE visitors SET userOS = %s, browser = %s, hits = hits + 1, lastvisit = %s WHERE counterID = %s and host = %s''', (useros, browser, date, vID, host) ) ======================================= Instead of the above logic which you provided and it works as expected, wouldn't be easier to just: Try to update the 'visitors' record, for that 'page' and that 'host' if update fails(doesnt return any data), then we insert a new record entry. We dont have to check 'SELECT * FROM visitors WHERE counterID = %s and host = %s' first, this one less cursor.execute. From andrew3 at r3dsolutions.com Wed Jan 23 22:28:28 2013 From: andrew3 at r3dsolutions.com (Andrew Robinson) Date: Thu, 24 Jan 2013 03:28:28 +0000 Subject: XML validation / exception. Message-ID: <5100AA5C.5070203@r3dsolutions.com> A quick question: On xml.etree, When I scan in a handwritten XML file, and there are mismatched tags -- it will throw an exception. and the exception will contain a line number of the closing tag which does not have a mate of the same kind. Is there a way to get the line number of the earlier tag which caused the XML parser to know the closing tag was mismatched, so I can narrow down the location of the mismatches for a manual repair? (I don't want auto-repair like beautiful soup. but google is worthless for finding a solution...) And secondly, for times where I want to throw a software/content specific error on valid XML files; I don't see which attribute of an element, or method, allows me to find out the line number and column number that an element I am examining is found at. ? How do I get it ? Cheers, --Andrew. From dieter at handshake.de Fri Jan 25 03:20:05 2013 From: dieter at handshake.de (dieter) Date: Fri, 25 Jan 2013 09:20:05 +0100 Subject: XML validation / exception. References: <5100AA5C.5070203@r3dsolutions.com> Message-ID: <878v7hk72i.fsf@handshake.de> Andrew Robinson writes: > On xml.etree, > When I scan in a handwritten XML file, and there are mismatched tags -- > it will throw an exception. > and the exception will contain a line number of the closing tag which > does not have a mate of the same kind. > > Is there a way to get the line number of the earlier tag which caused > the XML parser to know the closing tag was mismatched, so I can narrow > down the location of the mismatches for a manual repair? This is parser dependent -- and likely not the case for the standard parsers. In order to check for the correspondence between opening and closing tags, that parser must maintain a stack of open tags. Your request can be fullfilled when the parser keeps associated line numbers in this stack. I expect that most parser will not do that. Python's "xml" framework is highly modularied - with each component having only a minimal task. Especially, the parser is responsible for parsing only: it parses and generated events for what is sees (opening tag, closing tag, text, comment, entity, error, ...). The events are consumend by a separate component (when I remember right, a so called "handler"). Such a component is responsible to create the "ETree" during the parsing. You might be able to provide an alternative for this component which captures (in addition) line information for opening tags. Alternatively, you could provide an alternative parser. From redstone-cold at 163.com Thu Jan 24 09:25:27 2013 From: redstone-cold at 163.com (iMath) Date: Thu, 24 Jan 2013 06:25:27 -0800 (PST) Subject: anyone can make a Python bindings of VLC-Qt ? Message-ID: anyone can make a Python bindings of VLC-Qt ? https://github.com/ntadej/vlc-qt accurately, can anyone make a PyQt bindings of VLC-Qt ? From rosuav at gmail.com Thu Jan 24 10:05:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Jan 2013 02:05:45 +1100 Subject: anyone can make a Python bindings of VLC-Qt ? In-Reply-To: References: Message-ID: On Fri, Jan 25, 2013 at 1:25 AM, iMath wrote: > > anyone can make a Python bindings of VLC-Qt ? > https://github.com/ntadej/vlc-qt > accurately, can anyone make a PyQt bindings of VLC-Qt ? Yes, someone can. Ideally, someone who knows C++, Python, VLC, and Qt, and has the time to port the code you just linked to. It'll probably be a fairly big job, but relatively straight-forward for someone who knows. That someone isn't me, though (I don't know Qt, and I'm not familiar with VLC's internals - my knowledge of VLC is just as a user); maybe it's you? ChrisA From tamnt54 at gmail.com Thu Jan 24 12:06:19 2013 From: tamnt54 at gmail.com (tamnt54 at gmail.com) Date: Thu, 24 Jan 2013 09:06:19 -0800 (PST) Subject: monolithic apps Message-ID: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Any suggestions for study?..: Is is possible to take a large executable with GUI and real time data and images, to extract modules, and it can run as if it looks like a monolithic application (windows over main windows, or images over other images) but is various python script driven modules calling each other as separate apps? From d at davea.name Thu Jan 24 12:25:18 2013 From: d at davea.name (Dave Angel) Date: Thu, 24 Jan 2013 12:25:18 -0500 Subject: monolithic apps In-Reply-To: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: <51016E7E.800@davea.name> On 01/24/2013 12:06 PM, tamnt54 at gmail.com wrote: > Any suggestions for study?..: > Is is possible to take a large executable with GUI and real time data and images, to extract modules, and it can run as if it looks like a monolithic application (windows over main windows, or images over other images) but is various python script driven modules calling each other as separate apps? > I can see at least 4 things you might mean. Perhaps you'd better spell it out. 1) glom all the scripts & binary modules into one big file, so the user thinks it's one huge app 2) Manipulate multiple gui apps while having the same UI as though there was just one main window, and other windows all belong to it. Multiple GUI processes, but some central control to change the user experience into resembling a single GUI app. 3) Have one gui app "main" that other apps can somehow call to manipulate the windows of "main." Multiple processes, only one of them with a GUI. 4) From a GUI app, use other apps as loadable modules, and reuse their class definitions and functions by calling them from the GUI app. One process. You say this a topic for study, but there's a lot of other things you may need to specify before you get to implementing. What OS, what version of Python, what GUI, are these apps modifiable, or are you just allowed to write glue, ... -- DaveA From ulrich.eckhardt at dominolaser.com Thu Jan 24 12:25:32 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 24 Jan 2013 18:25:32 +0100 Subject: monolithic apps In-Reply-To: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: <51016E8C.8090604@dominolaser.com> Am 24.01.2013 18:06, schrieb tamnt54 at gmail.com: > Any suggestions for study?..: Is is possible to take a large > executable with GUI and real time data and images, to extract > modules, and it can run as if it looks like a monolithic application > (windows over main windows, or images over other images) but is > various python script driven modules calling each other as separate > apps? > http://www.gnu.org/software/hurd/ Uli From tamnt54 at gmail.com Fri Jan 25 09:00:37 2013 From: tamnt54 at gmail.com (tamnt54 at gmail.com) Date: Fri, 25 Jan 2013 06:00:37 -0800 (PST) Subject: monolithic apps In-Reply-To: References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: ..snipped... > > 2) Manipulate multiple gui apps while having the same UI as though there > was just one main window, and other windows all belong to it. Multiple > GUI processes, but some central control to change the user experience > into resembling a single GUI app. ...snipped > > You say this a topic for study, but there's a lot of other things you > may need to specify before you get to implementing. What OS, what > version of Python, what GUI, are these apps modifiable, or are you just > allowed to write glue, ... > -- > DaveA Hey Thanks, Dave! Definitely (2). However: you say "and other windows all belong to it." That is not such a great idea as long as the main window can close the other windows. But that's the point. I have a humongous commercial app in C++ on Win32. (It could require porting at some time because main tools it uses could get ported by separate vendor) So what I'd like to do is write real-time imaging functions separately and control them using python scripting with whatever windows or overlayed images are needed. Debug these separately and call+control them as individual stand alone, and glue together as needed. glue being mainly python, and what is being glued would also be controlled as separate python modules. This ends up running as one monolithic application that looks the same (better I hope) as the previous huge monolithic win32 app. thanks again! From tamnt54 at gmail.com Fri Jan 25 09:00:37 2013 From: tamnt54 at gmail.com (tamnt54 at gmail.com) Date: Fri, 25 Jan 2013 06:00:37 -0800 (PST) Subject: monolithic apps In-Reply-To: References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: ..snipped... > > 2) Manipulate multiple gui apps while having the same UI as though there > was just one main window, and other windows all belong to it. Multiple > GUI processes, but some central control to change the user experience > into resembling a single GUI app. ...snipped > > You say this a topic for study, but there's a lot of other things you > may need to specify before you get to implementing. What OS, what > version of Python, what GUI, are these apps modifiable, or are you just > allowed to write glue, ... > -- > DaveA Hey Thanks, Dave! Definitely (2). However: you say "and other windows all belong to it." That is not such a great idea as long as the main window can close the other windows. But that's the point. I have a humongous commercial app in C++ on Win32. (It could require porting at some time because main tools it uses could get ported by separate vendor) So what I'd like to do is write real-time imaging functions separately and control them using python scripting with whatever windows or overlayed images are needed. Debug these separately and call+control them as individual stand alone, and glue together as needed. glue being mainly python, and what is being glued would also be controlled as separate python modules. This ends up running as one monolithic application that looks the same (better I hope) as the previous huge monolithic win32 app. thanks again! From tamnt54 at gmail.com Fri Jan 25 09:05:05 2013 From: tamnt54 at gmail.com (tamnt54 at gmail.com) Date: Fri, 25 Jan 2013 06:05:05 -0800 (PST) Subject: monolithic apps In-Reply-To: References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: Glue not just python but whatever is needed to communicate back and forth. lots of data, but whatever could be glue in python of course. The C++ glue and functions would be controlled as python data and communicated between different modules. todd. From tamnt54 at gmail.com Fri Jan 25 09:06:03 2013 From: tamnt54 at gmail.com (tamnt54 at gmail.com) Date: Fri, 25 Jan 2013 06:06:03 -0800 (PST) Subject: monolithic apps In-Reply-To: References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: <66ff1132-c6ea-410e-912d-1399300e07db@googlegroups.com> My App takes over the whole system from power up to shutdown. From tamnt54 at gmail.com Fri Jan 25 09:06:03 2013 From: tamnt54 at gmail.com (tamnt54 at gmail.com) Date: Fri, 25 Jan 2013 06:06:03 -0800 (PST) Subject: monolithic apps In-Reply-To: References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: <66ff1132-c6ea-410e-912d-1399300e07db@googlegroups.com> My App takes over the whole system from power up to shutdown. From tamnt54 at gmail.com Fri Jan 25 09:05:05 2013 From: tamnt54 at gmail.com (tamnt54 at gmail.com) Date: Fri, 25 Jan 2013 06:05:05 -0800 (PST) Subject: monolithic apps In-Reply-To: References: <3ba34039-76e9-40f6-bc38-473f800cb543@googlegroups.com> Message-ID: Glue not just python but whatever is needed to communicate back and forth. lots of data, but whatever could be glue in python of course. The C++ glue and functions would be controlled as python data and communicated between different modules. todd. From angel.gutierrez.rodriguez at gmail.com Thu Jan 24 12:40:44 2013 From: angel.gutierrez.rodriguez at gmail.com (Angel) Date: Thu, 24 Jan 2013 09:40:44 -0800 (PST) Subject: Changing the font size of anOptionMenu widget Message-ID: <83d0b476-bf42-4390-bba8-32add52017f4@googlegroups.com> I am changing the font of an OptionMenu widget: w = OptionMenu(master, variable, "one", "two", "three") with w.configure(....) That changes the font of the widget but how can I change also the font (size) of the menu that appears when the mouse clicks it? Thanks in advandce, A. From rantingrickjohnson at gmail.com Fri Jan 25 00:57:00 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 24 Jan 2013 21:57:00 -0800 (PST) Subject: Changing the font size of anOptionMenu widget In-Reply-To: <83d0b476-bf42-4390-bba8-32add52017f4@googlegroups.com> References: <83d0b476-bf42-4390-bba8-32add52017f4@googlegroups.com> Message-ID: <6eb67005-b7b6-43a3-9f5e-5103eb6b8db0@googlegroups.com> Ignoring the fact that the Tkinter.Optionmenu is by far the worst widget in the toolkit, not to mention that the whole idea of "Tkinter X_Variables" was a poor attempt to reuse code at the expense destroying the simple and intuitive interface of "get" and "set"; here is your answer: ## START CODE ## from Tkinter import * master = Tk() variable = StringVar(master) variable.set("one") # default value optMenu = OptionMenu(master, variable, "one", "two", "three") optMenu.pack() # Get the menu menu = optMenu.nametowidget(optMenu.menuname) menu.configure(font=('Impact', 30)) mainloop() ## END CODE ## PS: You could have probably intuited the answer yourself if you used the dir() function on "w". Of course you probably would have expected the Optionmenu to have a reference to the submenu. It does, however not a direct reference. PPS: Or, if you prefer information overload you could have called "help(w)". From angel.gutierrez.rodriguez at gmail.com Fri Jan 25 15:55:49 2013 From: angel.gutierrez.rodriguez at gmail.com (Angel) Date: Fri, 25 Jan 2013 12:55:49 -0800 (PST) Subject: Changing the font size of anOptionMenu widget In-Reply-To: <6eb67005-b7b6-43a3-9f5e-5103eb6b8db0@googlegroups.com> References: <83d0b476-bf42-4390-bba8-32add52017f4@googlegroups.com> <6eb67005-b7b6-43a3-9f5e-5103eb6b8db0@googlegroups.com> Message-ID: <777b41f1-dcd2-4592-b3e8-362cedab4c40@googlegroups.com> Den fredagen den 25:e januari 2013 kl. 06:57:00 UTC+1 skrev Rick Johnson: > > menu = optMenu.nametowidget(optMenu.menuname) > That was what I was missing, the '.nametowidget'. It worked like a charm: o1=Tkinter.OptionMenu(t,v3, "?", "$") o1.config(font=self.font) o1.nametowidget(o1.menuname).config(font=self.font) Thanks! From marlenconer2 at gmail.com Thu Jan 24 13:46:39 2013 From: marlenconer2 at gmail.com (Marlen Coner) Date: Thu, 24 Jan 2013 10:46:39 -0800 (PST) Subject: Search Engine optimization technique Message-ID: jilltoler.com is a web blog where you can find WHAT IS Search Engine optimization, what is SEO Analytics, and how to you SEO tools and Importance of SEO Rankings. For more information please visit : http://www.jilltoler.com From jcasale at activenetwerx.com Thu Jan 24 15:58:00 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 24 Jan 2013 20:58:00 +0000 Subject: Dict comp help Message-ID: Hi, Slightly different take on an old problem, I have a list of dicts, I need to build one dict from this based on two values from each dict in the list. Each of the dicts in the list have similar key names, but values of course differ. [{'a': 'xx',?'b': 'yy',?'c': 'zz'}, ?{'a': 'dd',?'b': 'ee',?'c': 'ff'}] { 'xx': 'zz', 'dd': 'ff'} Anyone have insight on how to pull this off? Thanks! jlc From d at davea.name Thu Jan 24 16:08:43 2013 From: d at davea.name (Dave Angel) Date: Thu, 24 Jan 2013 16:08:43 -0500 Subject: Dict comp help In-Reply-To: References: Message-ID: <5101A2DB.9050308@davea.name> On 01/24/2013 03:58 PM, Joseph L. Casale wrote: > Hi, > Slightly different take on an old problem, I have a list of dicts, I need to build one dict > from this based on two values from each dict in the list. Each of the dicts in the list have > similar key names, but values of course differ. > > > [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}] > > > { 'xx': 'zz', 'dd': 'ff'} > > > Anyone have insight on how to pull this off? > Not till you tell us what the pattern is supposed to be. I can see how you might want xx:dd, yy:ee, zz:ff but have no idea what the intended connection is between the source dicts and the result. -- DaveA From oscar.j.benjamin at gmail.com Thu Jan 24 16:11:32 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 24 Jan 2013 21:11:32 +0000 Subject: Dict comp help In-Reply-To: References: Message-ID: On 24 January 2013 20:58, Joseph L. Casale wrote: > Hi, > Slightly different take on an old problem, I have a list of dicts, I need to build one dict > from this based on two values from each dict in the list. Each of the dicts in the list have > similar key names, but values of course differ. > > > [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}] > > > { 'xx': 'zz', 'dd': 'ff'} > > > Anyone have insight on how to pull this off? > Your specification is not exactly clear about how to handle all of the different cases or what you really want but how about: >>> l = [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}] >>> dict(d.values()[:2] for d in l) {'xx': 'zz', 'dd': 'ff'} Oscar From robert.day at merton.oxon.org Thu Jan 24 16:41:19 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Thu, 24 Jan 2013 21:41:19 +0000 Subject: Dict comp help In-Reply-To: References: Message-ID: On 24 January 2013 21:11, Oscar Benjamin wrote: >>>> l = [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}] >>>> dict(d.values()[:2] for d in l) > {'xx': 'zz', 'dd': 'ff'} Python doesn't guarantee any ordering of items in a dictionary; {'a': 'xx', 'b': 'yy', 'c': 'zz'}.values()[:2] may not return ['xx', 'zz'] in different Python implementations or future versions (though it seems to work consistently in CPython 2.7). See http://docs.python.org/2/library/stdtypes.html#dict.items. -- Robert K. Day robert.day at merton.oxon.org From __peter__ at web.de Thu Jan 24 16:23:42 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 Jan 2013 22:23:42 +0100 Subject: Dict comp help References: Message-ID: Joseph L. Casale wrote: > Slightly different take on an old problem, I have a list of dicts, I need > to build one dict from this based on two values from each dict in the > list. Each of the dicts in the list have similar key names, but values of > course differ. > > > [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}] > > > { 'xx': 'zz', 'dd': 'ff'} > > > Anyone have insight on how to pull this off? >>> data = [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}] >>> {d["a"]: d["c"] for d in data} {'xx': 'zz', 'dd': 'ff'} From jcasale at activenetwerx.com Thu Jan 24 17:21:44 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 24 Jan 2013 22:21:44 +0000 Subject: Dict comp help In-Reply-To: References: <753cb595af8449f689dabf8b28611e52@exch.activenetwerx.com>, Message-ID: > >>> data = [{'a': 'xx', 'b': 'yy', 'c': 'zz'},? {'a': 'dd', 'b': 'ee', 'c':?'ff'}]? > >>> {d["a"]: d["c"] for d in data} > {'xx': 'zz', 'dd': 'ff'} Priceless, That is exactly what I needed, for which I certainly over complicated! Thanks everyone! jlc From Arah.Leonard at bruker-axs.com Thu Jan 24 16:39:37 2013 From: Arah.Leonard at bruker-axs.com (Leonard, Arah) Date: Thu, 24 Jan 2013 21:39:37 +0000 Subject: Dict comp help In-Reply-To: References: Message-ID: <2ECADBDABCB17E40B66A25D839706F5E07586F72@msnmail2.bruker-axs.com> > Hi, > Slightly different take on an old problem, I have a list of dicts, I need to build one dict from this based on two values from each dict in the list. Each of the dicts in the list have similar key names, but values of course differ. > > > [{'a': 'xx',?'b': 'yy',?'c': 'zz'}, ?{'a': 'dd',?'b': 'ee',?'c': 'ff'}] > > > { 'xx': 'zz', 'dd': 'ff'} > > > Anyone have insight on how to pull this off? > > > Thanks! > jlc > listy = [{'a':'xx', 'b':'yy', 'c':'zz'}, {'a':'dd', 'b':'ee','c':'ff'}] kryten = {} keys = [] for l in listy: for key in l.keys(): if key not in keys: keys.append(key) for key in keys: kryten[key] = '' for l in listy: kryten[key] += l.has_key(key) and l[key] or '' print kryten From tundra at tundraware.com Thu Jan 24 20:29:51 2013 From: tundra at tundraware.com (Tim Daneliuk) Date: Thu, 24 Jan 2013 19:29:51 -0600 Subject: Need Pattern For Logging Into A Website Message-ID: I need to write a Python script to do the following: - Connect to a URL and accept any certificate - self-signed or authoritative - Provide login name/password credentials - Fill in some presented fields - Hit a "Submit" button Why? Because I don't want to have to start a browser and do this interactively every time I authenticate with a particular server. I want to do this at the command line with no interactive intervention. I know Python pretty well. I don't quite know how to do this and was hoping someone had a simple pattern they could share for doing this. TIA, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From spetrie at gmail.com Fri Jan 25 11:01:39 2013 From: spetrie at gmail.com (Steve Petrie) Date: Fri, 25 Jan 2013 08:01:39 -0800 (PST) Subject: Need Pattern For Logging Into A Website In-Reply-To: References: Message-ID: <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com> On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk wrote: > I need to write a Python script to do the following: > > > > - Connect to a URL and accept any certificate - self-signed or authoritative > > - Provide login name/password credentials > > - Fill in some presented fields > > - Hit a "Submit" button > > > > Why? Because I don't want to have to start a browser and do this > > interactively every time I authenticate with a particular server. > > I want to do this at the command line with no interactive intervention. > > > > I know Python pretty well. I don't quite know how to do this and > > was hoping someone had a simple pattern they could share for > > doing this. > > > > TIA, > > -- > > ---------------------------------------------------------------------------- > > Tim Daneliuk tundra at tundraware.com > > PGP Key: http://www.tundraware.com/PGP/ The mechanize module (http://wwwsearch.sourceforge.net/mechanize/) might be a place to start. I've done something similar with code like this: response = mechanize.urlopen(login_form_url) forms = mechanize.ParseResponse(response, backwards_compat=False) response.close() form = forms[0] # might be more than one, though # fill the form form.set_value(username, name='userName') form.set_value(password, name='password') # set headers - user-agent, etc. login_request = form.click() login_response = mechanize.urlopen(login_request) login_response_content = login_response.read() ... From tundra at tundraware.com Fri Jan 25 11:18:34 2013 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 25 Jan 2013 10:18:34 -0600 Subject: Need Pattern For Logging Into A Website In-Reply-To: <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com> References: <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com> Message-ID: On 01/25/2013 10:01 AM, Steve Petrie wrote: > On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk wrote: >> I need to write a Python script to do the following: >> >> >> >> - Connect to a URL and accept any certificate - self-signed or authoritative >> >> - Provide login name/password credentials >> >> - Fill in some presented fields >> >> - Hit a "Submit" button >> >> >> >> Why? Because I don't want to have to start a browser and do this >> >> interactively every time I authenticate with a particular server. >> >> I want to do this at the command line with no interactive intervention. >> >> >> >> I know Python pretty well. I don't quite know how to do this and >> >> was hoping someone had a simple pattern they could share for >> >> doing this. >> >> >> >> TIA, >> >> -- >> >> ---------------------------------------------------------------------------- >> >> Tim Daneliuk tundra at tundraware.com >> >> PGP Key: http://www.tundraware.com/PGP/ > > The mechanize module (http://wwwsearch.sourceforge.net/mechanize/) might be a place to start. I've done something similar with code like this: > > response = mechanize.urlopen(login_form_url) > forms = mechanize.ParseResponse(response, backwards_compat=False) > response.close() > form = forms[0] # might be more than one, though > # fill the form > form.set_value(username, name='userName') > form.set_value(password, name='password') > # set headers - user-agent, etc. > login_request = form.click() > login_response = mechanize.urlopen(login_request) > login_response_content = login_response.read() > ... > Thanks. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From torriem at gmail.com Fri Jan 25 14:18:11 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 25 Jan 2013 12:18:11 -0700 Subject: Need Pattern For Logging Into A Website In-Reply-To: References: <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com> Message-ID: <5102DA73.6000402@gmail.com> On 01/25/2013 09:18 AM, Tim Daneliuk wrote: > On 01/25/2013 10:01 AM, Steve Petrie wrote: >> On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk >> wrote: The mechanize module >> (http://wwwsearch.sourceforge.net/mechanize/) might be a place to >> start. I've done something similar with code like this: > Thanks. I've had good luck using urllib2 and a cookiejar. Just post your login credentials against the login url, keep all the cookies and then make your other requests using that cookiejar. Besides the Python standard library docs on urllib2 and cookielib, here's an article that gives an overview of how to use it: http://www.techchorus.net/using-cookie-jar-urllib2 This technique has the advantage of not requiring anything outside of the standard library. From tundra at tundraware.com Fri Jan 25 19:15:00 2013 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 25 Jan 2013 18:15:00 -0600 Subject: Need Pattern For Logging Into A Website In-Reply-To: References: <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com> Message-ID: <5pjbt9-lli2.ln1@ozzie.tundraware.com> On 01/25/2013 01:18 PM, Michael Torrie wrote: > On 01/25/2013 09:18 AM, Tim Daneliuk wrote: >> On 01/25/2013 10:01 AM, Steve Petrie wrote: >>> On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk >>> wrote: The mechanize module >>> (http://wwwsearch.sourceforge.net/mechanize/) might be a place to >>> start. I've done something similar with code like this: >> Thanks. > > I've had good luck using urllib2 and a cookiejar. Just post your login > credentials against the login url, keep all the cookies and then make > your other requests using that cookiejar. Besides the Python standard > library docs on urllib2 and cookielib, here's an article that gives an > overview of how to use it: > > http://www.techchorus.net/using-cookie-jar-urllib2 > > This technique has the advantage of not requiring anything outside of > the standard library. > Does it handle self-signed SSL certs? -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From torriem at gmail.com Sat Jan 26 01:53:11 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 25 Jan 2013 23:53:11 -0700 Subject: Need Pattern For Logging Into A Website In-Reply-To: <5pjbt9-lli2.ln1@ozzie.tundraware.com> References: <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com> <5pjbt9-lli2.ln1@ozzie.tundraware.com> Message-ID: <51037D57.2090008@gmail.com> On 01/25/2013 05:15 PM, Tim Daneliuk wrote: > Does it handle self-signed SSL certs? No idea. you'd have to try it. From tundra at tundraware.com Sat Jan 26 15:00:20 2013 From: tundra at tundraware.com (Tim Daneliuk) Date: Sat, 26 Jan 2013 14:00:20 -0600 Subject: Need Pattern For Logging Into A Website In-Reply-To: References: <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com> <5pjbt9-lli2.ln1@ozzie.tundraware.com> Message-ID: On 01/26/2013 12:53 AM, Michael Torrie wrote: > On 01/25/2013 05:15 PM, Tim Daneliuk wrote: >> Does it handle self-signed SSL certs? > > No idea. you'd have to try it. > OK, thanks for the pointer. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From jhnwsk at gmail.com Mon Jan 28 03:57:35 2013 From: jhnwsk at gmail.com (=?UTF-8?Q?Jan_W=C4=85sak?=) Date: Mon, 28 Jan 2013 00:57:35 -0800 (PST) Subject: Need Pattern For Logging Into A Website In-Reply-To: References: Message-ID: <6060b71d-24b8-406d-8feb-d27e46884c03@googlegroups.com> On Friday, January 25, 2013 2:29:51 AM UTC+1, Tim Daneliuk wrote: > I need to write a Python script to do the following: > > > > - Connect to a URL and accept any certificate - self-signed or authoritative > > - Provide login name/password credentials > > - Fill in some presented fields > > - Hit a "Submit" button > > > > Why? Because I don't want to have to start a browser and do this > > interactively every time I authenticate with a particular server. > > I want to do this at the command line with no interactive intervention. > > > > I know Python pretty well. I don't quite know how to do this and > > was hoping someone had a simple pattern they could share for > > doing this. > > > > TIA, > Hello Tim, I think you may also want to take a look at python requests. http://docs.python-requests.org/en/latest/user/advanced/ >From my experience they do a much nicer job than urllib and anything I've tried. You will probably get what you want out of them easily and in no time. -- cheers, john From jupiter.hce at gmail.com Thu Jan 24 23:20:41 2013 From: jupiter.hce at gmail.com (nobody) Date: Thu, 24 Jan 2013 20:20:41 -0800 (PST) Subject: Inherent asyncore.dispatcher_with_send exception Message-ID: <2e56f8d1-32a8-4800-9249-f1b201fbc9bb@googlegroups.com> Hi, I have a class ClientHandler(asyncore.dispatcher_with_send), it was running fine without calling any of my own classes. But it got following exception when I called my own class GetMyResponse inside the def handle_read(self). Not sure why it causes disturbance to asyncore.dispatcher_with_send __init__ when calling an extra class? Appreciate any clues and tips. class GetMyResponse: def __init__(self, message): .... class ClientHandler(asyncore.dispatcher_with_send): def handle_read(self): .... handleResponse = GetMyResponse(data) self.send(handleResponse.getResponse()) error: uncaptured python exception, closing channel <__main__.ClientHandler connected 127.0.0.1:42383 at 0x7f3b638b6758> (:__init__() takes exactly 4 arguments (3 given) [/usr/lib64/python2.6/asyncore.py|read|78] [/usr/lib64/python2.6/asyncore.py|handle_read_event|428] From anthra.norell at bluewin.ch Fri Jan 25 01:55:06 2013 From: anthra.norell at bluewin.ch (F.R.) Date: Fri, 25 Jan 2013 07:55:06 +0100 Subject: MySQL - "create table" creates malfunctioning tables Message-ID: <51022C4A.4070100@bluewin.ch> The other day, for unfathomable reasons, I lost control over tables which I create. There was no concurrent change of anything on the machine, such as an update. So I have no suspect. Does the following action log suggest any recommendation to experienced SQL programmers? 1. A table: mysql> select * from expenses; +----+------------+-------+----------+--------+-------------+-------+ | id | date | place | stuff | amount | category | flags | +----+------------+-------+----------+--------+-------------+-------+ | 38 | 2013-01-15 | ATT | Sim card | 25.00 | Visa credit | | +----+------------+-------+----------+--------+-------------+-------+ 1 row in set (0.00 sec) 2. I want to delete everything: mysql> delete from expenses; 3. Nothing happens for about one minute. Then this: ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction mysql> 4. I want to delete the table: mysql> drop table expenses; 5. Nothing happens indefinitely. I have to hit Ctrl-C ^CCtrl-C -- sending "KILL QUERY 167" to server ... Ctrl-C -- query aborted. ERROR 1317 (70100): Query execution was interrupted mysql> 6. I expect to find "expenses.frm", "expenses.MYD" and "expenses.MYI". I find only the format file: root at hatchbox-one:/home/fr# find / -name 'expenses.*' -ls 1055950 12 -rw-rw---- 1 mysql mysql 8783 Jan 25 01:51 /var/lib/mysql/fr/expenses.frm root at hatchbox-one:/home/fr# 7. All the tables I regularly work with have a "frm", a "MYD" and a "MYI" file in the directory "/var/lib/mysql/fr/". 8. I'd like to drop the table "expenses", plus a number of other tables I created, hoping to hit it right by chance. I didn't and now I have a bunch of unusable tables which I can't drop and I don't know where their files are hiding. If I did, I could remove them. Grateful for any hint, comment, suggestion Frederic Dell E6500 Ubuntu 10.04 LTS Python 2.7.3 (default, Aug 1 2012, 05:16:07) \n[GCC 4.6.3 MySQL (Can't find a version number) Server version: 5.5.28-0ubuntu0.12.04.3 (Ubuntu) From walterhurry at lavabit.com Fri Jan 25 02:23:24 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 25 Jan 2013 07:23:24 +0000 (UTC) Subject: MySQL - "create table" creates malfunctioning tables References: Message-ID: On Fri, 25 Jan 2013 07:55:06 +0100, F.R. wrote: > The other day, for unfathomable reasons, I lost control over tables > which I create. There was no concurrent change of anything on the > machine, such as an update. So I have no suspect. Does the following > action log suggest any recommendation to experienced SQL programmers? > This is a Python list. From liujz39 at gmail.com Fri Jan 25 05:48:51 2013 From: liujz39 at gmail.com (Junze Liu) Date: Fri, 25 Jan 2013 02:48:51 -0800 (PST) Subject: How to debug pyd File in Vs??? Message-ID: Recently, I build a hybrid system with C++ and python. First,I encapsulate a class(I can't guarantee the robustness of this class ) with boost.python which can implement some functions that can not be implemented by C++, I get a .pyd File in result. Second,I embed a python interpreter in c++. Third, use the embed interpreter to execute a .py File.The .py File include the module that in .pyd File I created. Here, the problem comes out! When I start my main project. I can only debug the problems in my main project, when my main project use the python interpreter to execute the python interpreter, I can't see what happened in my pyd File, the whole project collapsed.I know the error is in the pyd File, and if I set a break point in my resource files of pyd File, either the project will go to the break point. Is there any methods to debug the resource file in this condition! From nhodgson at iinet.net.au Fri Jan 25 07:01:09 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Fri, 25 Jan 2013 23:01:09 +1100 Subject: How to debug pyd File in Vs??? In-Reply-To: References: Message-ID: Junze Liu: > Third, use the embed interpreter to execute a .py File.The .py File include the module that in .pyd File I created. > Here, the problem comes out! When I start my main project. I can only debug the problems in my main project, when my main project use the python interpreter to execute the python interpreter, I can't see what happened in my pyd File, the whole project collapsed.I know the error is in the pyd File, and if I set a break point in my resource files of pyd File, either the project will go to the break point. This normally works unless Visual Studio can't understand the relationship between the .pyd and source files. Make sure you have built the .pyd using a release configuration but with debugging information turned on for both compiling and linking. Or use a debug build of python along with a debug build of the .pyd. > Is there any methods to debug the resource file in this condition! You can call DebugBreak() somewhere in the .pyd code which will start up Visual Studio as a debugger. It normally works out where the source code is and then you can add more breakpoints and step through. http://msdn.microsoft.com/en-us/library/windows/desktop/ms679297(v=vs.85).aspx Neil From moonhkt at gmail.com Fri Jan 25 07:06:22 2013 From: moonhkt at gmail.com (moonhkt) Date: Fri, 25 Jan 2013 04:06:22 -0800 (PST) Subject: create object base on text file Message-ID: Hi All Python 2.6.x on AIX Data file PrinterA print Production batch1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx print Production batch2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx print Production batch3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PrinterB print Production batch4 xxxxxxxxxxxxxxxxxxxxxxxxxxx print Production batch5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx What to using python create object base on date file ? I know how to read text file. object["PrinterA"] have batch1, batch2, batch3 object["PrinterB"] have batch4, batch5 moonhkt From d at davea.name Fri Jan 25 08:04:31 2013 From: d at davea.name (Dave Angel) Date: Fri, 25 Jan 2013 08:04:31 -0500 Subject: create object base on text file In-Reply-To: References: Message-ID: <510282DF.6040706@davea.name> On 01/25/2013 07:06 AM, moonhkt wrote: > Hi All > > Python 2.6.x on AIX > > Data file > > PrinterA > print Production batch1 > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > print Production batch2 > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > print Production batch3 > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > PrinterB > print Production batch4 > xxxxxxxxxxxxxxxxxxxxxxxxxxx > print Production batch5 > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > What to using python create object base on date file ? I know how to > read text file. > > object["PrinterA"] have batch1, batch2, batch3 > > object["PrinterB"] have batch4, batch5 > > moonhkt > What Python version are you targeting? It would save everyone a lot of time if you quoted the homework assignment directly. Also, be more careful about typos. Is it a date file, or a data file? You can create an object very easily. a = object(). You can add attributes to many objects by simply saying a.attrib = 42 Unfortunately you can't do that to an "object" class instance. So you need to clarify. Now, you used dictionary syntax, so perhaps you didn't mean create an object, but create a dict. a = dict() a["PrinterA"] = "batch1", "batch2", "batch3" print a produces {'PrinterA': ('batch1', 'batch2', 'batch3')} What part of the assignment is giving you trouble? What have you written so far? -- DaveA From cxleung at gmail.com Fri Jan 25 10:28:52 2013 From: cxleung at gmail.com (cxleung at gmail.com) Date: Fri, 25 Jan 2013 07:28:52 -0800 (PST) Subject: create object base on text file In-Reply-To: References: Message-ID: On Friday, January 25, 2013 9:04:31 PM UTC+8, Dave Angel wrote: > On 01/25/2013 07:06 AM, moonhkt wrote: > > > Hi All > > > > > > Python 2.6.x on AIX > > > > > > Data file > > > > > > PrinterA > > > print Production batch1 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > print Production batch2 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > print Production batch3 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > > > > PrinterB > > > print Production batch4 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxx > > > print Production batch5 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > > > > > > > What to using python create object base on date file ? I know how to > > > read text file. > > > > > > object["PrinterA"] have batch1, batch2, batch3 > > > > > > object["PrinterB"] have batch4, batch5 > > > > > > moonhkt > > > > > > > What Python version are you targeting? > > > > It would save everyone a lot of time if you quoted the homework > > assignment directly. Also, be more careful about typos. Is it a date > > file, or a data file? > > > > You can create an object very easily. a = object(). You can add > > attributes to many objects by simply saying > > a.attrib = 42 > > > > Unfortunately you can't do that to an "object" class instance. So you > > need to clarify. > > > > Now, you used dictionary syntax, so perhaps you didn't mean create an > > object, but create a dict. > > > > a = dict() > > a["PrinterA"] = "batch1", "batch2", "batch3" > > print a > > > > produces > > {'PrinterA': ('batch1', 'batch2', 'batch3')} > > > > > > What part of the assignment is giving you trouble? What have you > > written so far? > > > > > > -- > > DaveA Thank I get the methods. Python 2.6.2 I just leaning python , before using gawk/ksh. #!/usr/bin/env python a= dict() a["PrintA"]= ["batch1","batch2","batch3"] a["PrintB"] = ["batch4","batch5"] a["PrintA"].append("batch6") print a for k in sorted(a.keys()): for j in sorted(a[k]): print k , j Output {'PrintA': ['batch1', 'batch2', 'batch3', 'batch6'], 'PrintB': ['batch4', 'batch5']} PrintA batch1 PrintA batch2 PrintA batch3 PrintA batch6 PrintB batch4 PrintB batch5 From cxleung at gmail.com Fri Jan 25 10:28:52 2013 From: cxleung at gmail.com (cxleung at gmail.com) Date: Fri, 25 Jan 2013 07:28:52 -0800 (PST) Subject: create object base on text file In-Reply-To: References: Message-ID: On Friday, January 25, 2013 9:04:31 PM UTC+8, Dave Angel wrote: > On 01/25/2013 07:06 AM, moonhkt wrote: > > > Hi All > > > > > > Python 2.6.x on AIX > > > > > > Data file > > > > > > PrinterA > > > print Production batch1 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > print Production batch2 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > print Production batch3 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > > > > PrinterB > > > print Production batch4 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxx > > > print Production batch5 > > > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > > > > > > > > > What to using python create object base on date file ? I know how to > > > read text file. > > > > > > object["PrinterA"] have batch1, batch2, batch3 > > > > > > object["PrinterB"] have batch4, batch5 > > > > > > moonhkt > > > > > > > What Python version are you targeting? > > > > It would save everyone a lot of time if you quoted the homework > > assignment directly. Also, be more careful about typos. Is it a date > > file, or a data file? > > > > You can create an object very easily. a = object(). You can add > > attributes to many objects by simply saying > > a.attrib = 42 > > > > Unfortunately you can't do that to an "object" class instance. So you > > need to clarify. > > > > Now, you used dictionary syntax, so perhaps you didn't mean create an > > object, but create a dict. > > > > a = dict() > > a["PrinterA"] = "batch1", "batch2", "batch3" > > print a > > > > produces > > {'PrinterA': ('batch1', 'batch2', 'batch3')} > > > > > > What part of the assignment is giving you trouble? What have you > > written so far? > > > > > > -- > > DaveA Thank I get the methods. Python 2.6.2 I just leaning python , before using gawk/ksh. #!/usr/bin/env python a= dict() a["PrintA"]= ["batch1","batch2","batch3"] a["PrintB"] = ["batch4","batch5"] a["PrintA"].append("batch6") print a for k in sorted(a.keys()): for j in sorted(a[k]): print k , j Output {'PrintA': ['batch1', 'batch2', 'batch3', 'batch6'], 'PrintB': ['batch4', 'batch5']} PrintA batch1 PrintA batch2 PrintA batch3 PrintA batch6 PrintB batch4 PrintB batch5 From wgsl2005 at gmail.com Fri Jan 25 11:34:16 2013 From: wgsl2005 at gmail.com (Alex) Date: Fri, 25 Jan 2013 08:34:16 -0800 (PST) Subject: Python GUI able to display a spatial image Message-ID: <9b99edf2-6529-4dec-9876-7005af192971@googlegroups.com> Hello, does python have capabilities to display a spatial image and read the coordinates from it? If so, what modules or extension do I need to achieve that? I'll appreciate any help. Thanks, Alex From eagleds88 at gmail.com Mon Jan 28 20:47:04 2013 From: eagleds88 at gmail.com (eagleds88 at gmail.com) Date: Mon, 28 Jan 2013 17:47:04 -0800 (PST) Subject: Python GUI able to display a spatial image In-Reply-To: <9b99edf2-6529-4dec-9876-7005af192971@googlegroups.com> References: <9b99edf2-6529-4dec-9876-7005af192971@googlegroups.com> Message-ID: <1a2afcf0-5a35-4c42-a1ff-12b205fe6681@googlegroups.com> On Friday, January 25, 2013 8:34:16 AM UTC-8, Alex wrote: > Hello, does python have capabilities to display a spatial image and read the coordinates from it? If so, what modules or extension do I need to achieve that? I'll appreciate any help. > > > > Thanks, > > Alex Try basemap: http://matplotlib.org/basemap/ From lars at rational-it.com Fri Jan 25 12:40:49 2013 From: lars at rational-it.com (lars van gemerden) Date: Fri, 25 Jan 2013 09:40:49 -0800 (PST) Subject: finding abc's Message-ID: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> Hi all, i was writing a function to determine the common base class of a number classes: def common_base(classes): if not len(classes): return None common = set(classes.pop().mro()) for cls in classes: common.intersection_update(cls.mro()) while len(common) > 1: cls1 = common.pop() cls2 = common.pop() if issubclass(cls1, cls2): common.add(cls1) elif issubclass(cls2, cls1): common.add(cls2) return common.pop() and ran common_base(int, float), hoping to get numbers.Number. this did not work because abstract base classes are not always in the mro() of classes. My question is: is there a way to obtain the abc's of a class or otherwise a way to make the function above take abc's into account (maybe via a predefined function)? Cheers, Lars From ian.g.kelly at gmail.com Fri Jan 25 14:04:32 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 Jan 2013 12:04:32 -0700 Subject: finding abc's In-Reply-To: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> Message-ID: On Fri, Jan 25, 2013 at 10:40 AM, lars van gemerden wrote: > Hi all, > > i was writing a function to determine the common base class of a number classes: > [...] > > and ran common_base(int, float), hoping to get numbers.Number. > > this did not work because abstract base classes are not always in the mro() of classes. > > My question is: is there a way to obtain the abc's of a class or otherwise a way to make the function above take abc's into account (maybe via a predefined function)? If the abstract base class's module has not been imported, it may not even be loaded into memory, even though it is technically considered a superclass. Consider this: Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def common_base(classes): ... common = set() ... for cls in object.__subclasses__(): ... if all(issubclass(c, cls) for c in classes): ... common.add(cls) ... return common ... >>> common_base([int, float]) set([]) >>> import numbers >>> common_base([int, float]) set([, ]) If you're okay with that, then the approach above might work. > while len(common) > 1: > cls1 = common.pop() > cls2 = common.pop() > if issubclass(cls1, cls2): > common.add(cls1) > elif issubclass(cls2, cls1): > common.add(cls2) There is a flaw with your set reduction code here. If neither class is a subclass of the other, then both will be removed. There may not actually be a single closest common base class, however. What would you expect the function to return in the following situation? class A(object): pass class B(object): pass class C(A, B): pass class D(A, B): pass print common_base([C, D]) From __peter__ at web.de Fri Jan 25 14:08:18 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 25 Jan 2013 20:08:18 +0100 Subject: finding abc's References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> Message-ID: lars van gemerden wrote: > Hi all, > > i was writing a function to determine the common base class of a number > classes: > > def common_base(classes): > if not len(classes): > return None > common = set(classes.pop().mro()) > for cls in classes: > common.intersection_update(cls.mro()) > while len(common) > 1: > cls1 = common.pop() > cls2 = common.pop() > if issubclass(cls1, cls2): > common.add(cls1) > elif issubclass(cls2, cls1): > common.add(cls2) > return common.pop() > > and ran common_base(int, float), hoping to get numbers.Number. > > this did not work because abstract base classes are not always in the > mro() of classes. > > My question is: is there a way to obtain the abc's of a class or otherwise > a way to make the function above take abc's into account (maybe via a > predefined function)? The abstract base classes may run arbitrary code to determine the subclass relationship: >>> from abc import ABCMeta >>> import random >>> class Maybe(metaclass=ABCMeta): ... @classmethod ... def __subclasshook__(cls, C): ... print("processing", C) ... return random.choice((False, True)) ... >>> isinstance(1.1, Maybe) processing True >>> isinstance(1.1, Maybe) True >>> isinstance(1, Maybe) processing False >>> issubclass(float, Maybe) True You'd have to check every pair of classes explicitly and might still miss (for example) numbers.Number as the module may not have been imported. I think you are out of luck. From lars at rational-it.com Fri Jan 25 15:05:34 2013 From: lars at rational-it.com (lars van gemerden) Date: Fri, 25 Jan 2013 12:05:34 -0800 (PST) Subject: finding abc's In-Reply-To: References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> Message-ID: <9ac2bf34-1945-4819-9bd5-c0a42179fd00@googlegroups.com> On Friday, January 25, 2013 8:04:32 PM UTC+1, Ian wrote: > On Fri, Jan 25, 2013 at 10:40 AM, lars van gemerden > > wrote: > > > Hi all, > > > > > > i was writing a function to determine the common base class of a number classes: > > > > > [...] > > > > > > and ran common_base(int, float), hoping to get numbers.Number. > > > > > > this did not work because abstract base classes are not always in the mro() of classes. > > > > > > My question is: is there a way to obtain the abc's of a class or otherwise a way to make the function above take abc's into account (maybe via a predefined function)? > > > > > > If the abstract base class's module has not been imported, it may not > > even be loaded into memory, even though it is technically considered a > > superclass. Consider this: > > > > > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> def common_base(classes): > > ... common = set() > > ... for cls in object.__subclasses__(): > > ... if all(issubclass(c, cls) for c in classes): > > ... common.add(cls) > > ... return common > > ... > > >>> common_base([int, float]) > > set([]) > > >>> import numbers > > >>> common_base([int, float]) > > set([, ]) > > > > > > If you're okay with that, then the approach above might work. > > > > > > > while len(common) > 1: > > > cls1 = common.pop() > > > cls2 = common.pop() > > > if issubclass(cls1, cls2): > > > common.add(cls1) > > > elif issubclass(cls2, cls1): > > > common.add(cls2) > > > > There is a flaw with your set reduction code here. If neither class > > is a subclass of the other, then both will be removed. There may not > > actually be a single closest common base class, however. What would > > you expect the function to return in the following situation? > > > > class A(object): pass > > class B(object): pass > > class C(A, B): pass > > class D(A, B): pass > > > > print common_base([C, D]) thanks, good catch, and very concise answer. I'll give up on trying to get abc's and improve my algorithm. From lars at rational-it.com Fri Jan 25 15:05:34 2013 From: lars at rational-it.com (lars van gemerden) Date: Fri, 25 Jan 2013 12:05:34 -0800 (PST) Subject: finding abc's In-Reply-To: References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> Message-ID: <9ac2bf34-1945-4819-9bd5-c0a42179fd00@googlegroups.com> On Friday, January 25, 2013 8:04:32 PM UTC+1, Ian wrote: > On Fri, Jan 25, 2013 at 10:40 AM, lars van gemerden > > wrote: > > > Hi all, > > > > > > i was writing a function to determine the common base class of a number classes: > > > > > [...] > > > > > > and ran common_base(int, float), hoping to get numbers.Number. > > > > > > this did not work because abstract base classes are not always in the mro() of classes. > > > > > > My question is: is there a way to obtain the abc's of a class or otherwise a way to make the function above take abc's into account (maybe via a predefined function)? > > > > > > If the abstract base class's module has not been imported, it may not > > even be loaded into memory, even though it is technically considered a > > superclass. Consider this: > > > > > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> def common_base(classes): > > ... common = set() > > ... for cls in object.__subclasses__(): > > ... if all(issubclass(c, cls) for c in classes): > > ... common.add(cls) > > ... return common > > ... > > >>> common_base([int, float]) > > set([]) > > >>> import numbers > > >>> common_base([int, float]) > > set([, ]) > > > > > > If you're okay with that, then the approach above might work. > > > > > > > while len(common) > 1: > > > cls1 = common.pop() > > > cls2 = common.pop() > > > if issubclass(cls1, cls2): > > > common.add(cls1) > > > elif issubclass(cls2, cls1): > > > common.add(cls2) > > > > There is a flaw with your set reduction code here. If neither class > > is a subclass of the other, then both will be removed. There may not > > actually be a single closest common base class, however. What would > > you expect the function to return in the following situation? > > > > class A(object): pass > > class B(object): pass > > class C(A, B): pass > > class D(A, B): pass > > > > print common_base([C, D]) thanks, good catch, and very concise answer. I'll give up on trying to get abc's and improve my algorithm. From lars at rational-it.com Fri Jan 25 15:08:12 2013 From: lars at rational-it.com (lars van gemerden) Date: Fri, 25 Jan 2013 12:08:12 -0800 (PST) Subject: finding abc's In-Reply-To: References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> Message-ID: <0d837f4c-c4a7-4df6-978c-b62a10ef9d70@googlegroups.com> On Friday, January 25, 2013 8:08:18 PM UTC+1, Peter Otten wrote: > lars van gemerden wrote: > > > > > Hi all, > > > > > > i was writing a function to determine the common base class of a number > > > classes: > > > > > > def common_base(classes): > > > if not len(classes): > > > return None > > > common = set(classes.pop().mro()) > > > for cls in classes: > > > common.intersection_update(cls.mro()) > > > while len(common) > 1: > > > cls1 = common.pop() > > > cls2 = common.pop() > > > if issubclass(cls1, cls2): > > > common.add(cls1) > > > elif issubclass(cls2, cls1): > > > common.add(cls2) > > > return common.pop() > > > > > > and ran common_base(int, float), hoping to get numbers.Number. > > > > > > this did not work because abstract base classes are not always in the > > > mro() of classes. > > > > > > My question is: is there a way to obtain the abc's of a class or otherwise > > > a way to make the function above take abc's into account (maybe via a > > > predefined function)? > > > > The abstract base classes may run arbitrary code to determine the subclass > > relationship: > > > > >>> from abc import ABCMeta > > >>> import random > > >>> class Maybe(metaclass=ABCMeta): > > ... @classmethod > > ... def __subclasshook__(cls, C): > > ... print("processing", C) > > ... return random.choice((False, True)) > > ... > > >>> isinstance(1.1, Maybe) > > processing > > True > > >>> isinstance(1.1, Maybe) > > True > > >>> isinstance(1, Maybe) > > processing > > False > > >>> issubclass(float, Maybe) > > True > > > > You'd have to check every pair of classes explicitly and might still miss > > (for example) numbers.Number as the module may not have been imported. > > > > I think you are out of luck. Thank you, interesting example. Added confirmation that trying to get the abc's is a bad idea. From lars at rational-it.com Fri Jan 25 15:08:12 2013 From: lars at rational-it.com (lars van gemerden) Date: Fri, 25 Jan 2013 12:08:12 -0800 (PST) Subject: finding abc's In-Reply-To: References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> Message-ID: <0d837f4c-c4a7-4df6-978c-b62a10ef9d70@googlegroups.com> On Friday, January 25, 2013 8:08:18 PM UTC+1, Peter Otten wrote: > lars van gemerden wrote: > > > > > Hi all, > > > > > > i was writing a function to determine the common base class of a number > > > classes: > > > > > > def common_base(classes): > > > if not len(classes): > > > return None > > > common = set(classes.pop().mro()) > > > for cls in classes: > > > common.intersection_update(cls.mro()) > > > while len(common) > 1: > > > cls1 = common.pop() > > > cls2 = common.pop() > > > if issubclass(cls1, cls2): > > > common.add(cls1) > > > elif issubclass(cls2, cls1): > > > common.add(cls2) > > > return common.pop() > > > > > > and ran common_base(int, float), hoping to get numbers.Number. > > > > > > this did not work because abstract base classes are not always in the > > > mro() of classes. > > > > > > My question is: is there a way to obtain the abc's of a class or otherwise > > > a way to make the function above take abc's into account (maybe via a > > > predefined function)? > > > > The abstract base classes may run arbitrary code to determine the subclass > > relationship: > > > > >>> from abc import ABCMeta > > >>> import random > > >>> class Maybe(metaclass=ABCMeta): > > ... @classmethod > > ... def __subclasshook__(cls, C): > > ... print("processing", C) > > ... return random.choice((False, True)) > > ... > > >>> isinstance(1.1, Maybe) > > processing > > True > > >>> isinstance(1.1, Maybe) > > True > > >>> isinstance(1, Maybe) > > processing > > False > > >>> issubclass(float, Maybe) > > True > > > > You'd have to check every pair of classes explicitly and might still miss > > (for example) numbers.Number as the module may not have been imported. > > > > I think you are out of luck. Thank you, interesting example. Added confirmation that trying to get the abc's is a bad idea. From lars at rational-it.com Fri Jan 25 19:48:17 2013 From: lars at rational-it.com (lars van gemerden) Date: Fri, 25 Jan 2013 16:48:17 -0800 (PST) Subject: finding abc's In-Reply-To: <0d837f4c-c4a7-4df6-978c-b62a10ef9d70@googlegroups.com> References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> <0d837f4c-c4a7-4df6-978c-b62a10ef9d70@googlegroups.com> Message-ID: for future reference, i decided to go with 2 functions: def common_bases(classes): if not len(classes): return None common = set(classes.pop().mro()) for cls in classes: common.intersection_update(cls.mro()) #all subclasses in common return [cls for cls in common if not any(sub in common for sub in cls.__subclasses__())] #the classes of which no subclasses are present def unique_common_base(classes): while len(classes) > 1: classes = common_bases(classes) return classes.pop() if i tested and understood correctly, they only take classes in the mro() into account (which might include abc's), the first gives all common base classes, the second recursively reduces further to one single class (the latter might not make to much sense, but in my program it is a safe bet for rare cases). Thanks again for the help, Cheers, Lars From lars at rational-it.com Fri Jan 25 19:48:17 2013 From: lars at rational-it.com (lars van gemerden) Date: Fri, 25 Jan 2013 16:48:17 -0800 (PST) Subject: finding abc's In-Reply-To: <0d837f4c-c4a7-4df6-978c-b62a10ef9d70@googlegroups.com> References: <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> <0d837f4c-c4a7-4df6-978c-b62a10ef9d70@googlegroups.com> Message-ID: for future reference, i decided to go with 2 functions: def common_bases(classes): if not len(classes): return None common = set(classes.pop().mro()) for cls in classes: common.intersection_update(cls.mro()) #all subclasses in common return [cls for cls in common if not any(sub in common for sub in cls.__subclasses__())] #the classes of which no subclasses are present def unique_common_base(classes): while len(classes) > 1: classes = common_bases(classes) return classes.pop() if i tested and understood correctly, they only take classes in the mro() into account (which might include abc's), the first gives all common base classes, the second recursively reduces further to one single class (the latter might not make to much sense, but in my program it is a safe bet for rare cases). Thanks again for the help, Cheers, Lars From arnodel at gmail.com Fri Jan 25 18:14:41 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 25 Jan 2013 23:14:41 +0000 Subject: Retrieving an object from a set Message-ID: Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equal to x. My problem is how to retrieve y, without going through the whole set. Here is a simple illustration with tuples (my actual scenario is not with tuples but with a custom class): >>> y = (1, 2, 3) # This is the 'hidden object' >>> S = set([y] + range(10000)) >>> x = (1, 2, 3) >>> x in S True >>> x is y False I haven't found y. It's a very simple problem, and this is the simplest solution I can think of: class FindEqual(object): def __init__(self, obj): self.obj = obj def __hash__(self): return hash(self.obj) def __eq__(self, other): equal = self.obj == other if equal: self.lastequal = other return equal >>> yfinder = FindEqual(x) >>> yfinder in S True >>> yfinder.lastequal is y True I've found y! I'm not happy with this as it really is a trick. Is there a cleaner solution? -- Arnaud From ian.g.kelly at gmail.com Fri Jan 25 18:30:50 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 Jan 2013 16:30:50 -0700 Subject: Retrieving an object from a set In-Reply-To: References: Message-ID: On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S which is equal to x. My > problem is how to retrieve y, without going through the whole set. You could use a dict. >>> y = (1, 2, 3) >>> S = {x: x for x in [y] + range(10000)} >>> x = (1, 2, 3) >>> x in S True >>> x is y False >>> S[x] is y True From ian.g.kelly at gmail.com Fri Jan 25 18:37:02 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 Jan 2013 16:37:02 -0700 Subject: Retrieving an object from a set In-Reply-To: References: Message-ID: On Fri, Jan 25, 2013 at 4:30 PM, Ian Kelly wrote: > On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: >> Dear Pythoneers, >> >> I've got a seemingly simple problem, but for which I cannot find a >> simple solution. >> >> I have a set of objects (say S) containing an object which is equal to >> a given object (say x). So >> >> x in S >> >> is true. So there is an object y in S which is equal to x. My >> problem is how to retrieve y, without going through the whole set. > > You could use a dict. > >>>> y = (1, 2, 3) >>>> S = {x: x for x in [y] + range(10000)} >>>> x = (1, 2, 3) >>>> x in S > True >>>> x is y > False >>>> S[x] is y > True Or you could use a set intersection: >>> S = set([y] + list(range(10000))) >>> S.intersection([x]).pop() (1, 2, 3) In my testing, the time needed for this is small and does not seem to depend on the size of the set. From python at mrabarnett.plus.com Fri Jan 25 18:45:38 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 25 Jan 2013 23:45:38 +0000 Subject: Retrieving an object from a set In-Reply-To: References: Message-ID: <51031922.2020104@mrabarnett.plus.com> On 2013-01-25 23:14, Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S which is equal to x. My > problem is how to retrieve y, without going through the whole set. > Here is a simple illustration with tuples (my actual scenario is not > with tuples but with a custom class): > >>>> y = (1, 2, 3) # This is the 'hidden object' >>>> S = set([y] + range(10000)) >>>> x = (1, 2, 3) >>>> x in S > True >>>> x is y > False > You could first limit the search to only those which it could be: S & set([y]) A search would be: >>> f = [m for m in S & set([y]) if m is y][0] >>> f is y True From ian.g.kelly at gmail.com Fri Jan 25 19:26:46 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 Jan 2013 17:26:46 -0700 Subject: Retrieving an object from a set In-Reply-To: <51031922.2020104@mrabarnett.plus.com> References: <51031922.2020104@mrabarnett.plus.com> Message-ID: On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: > You could first limit the search to only those which it could be: > > S & set([y]) > > A search would be: > >>>> f = [m for m in S & set([y]) if m is y][0] >>>> f is y > True But in practice he won't have y, only x. So that would have to be: >>> f = [m for m in S & set([x]) if m is x][0] >>> f is y False And it turns out that my earlier "intersection" suggestion fails for the same reason. From python at mrabarnett.plus.com Fri Jan 25 21:56:58 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 26 Jan 2013 02:56:58 +0000 Subject: Retrieving an object from a set In-Reply-To: References: <51031922.2020104@mrabarnett.plus.com> Message-ID: <510345FA.5000607@mrabarnett.plus.com> On 2013-01-26 00:26, Ian Kelly wrote: > On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: >> You could first limit the search to only those which it could be: >> >> S & set([y]) >> >> A search would be: >> >>>>> f = [m for m in S & set([y]) if m is y][0] >>>>> f is y >> True > > But in practice he won't have y, only x. So that would have to be: > >>>> f = [m for m in S & set([x]) if m is x][0] >>>> f is y > False > > And it turns out that my earlier "intersection" suggestion fails for > the same reason. > It turns out that both S & {x} and {x} & S return {x}, not {y}. OK, so... The members that don't equal x are S - {x}. Remove those and you get the members that _do_ equal x: >>> (S - (S - {x})).pop() is y True From vito.detullio at gmail.com Sat Jan 26 02:55:50 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 26 Jan 2013 08:55:50 +0100 Subject: Retrieving an object from a set References: <51031922.2020104@mrabarnett.plus.com> <510345FA.5000607@mrabarnett.plus.com> Message-ID: MRAB wrote: > It turns out that both S & {x} and {x} & S return {x}, not {y}. curious. $ python Python 2.7.3 (default, Jul 3 2012, 19:58:39) [GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = (1,2,3) >>> y = (1,2,3) >>> s = set([y]) >>> (s & set([x])).pop() is y False >>> (set([x]) & s).pop() is y True maybe it's implementation-defined? -- ZeD From __peter__ at web.de Sat Jan 26 03:10:24 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 26 Jan 2013 09:10:24 +0100 Subject: Retrieving an object from a set References: <51031922.2020104@mrabarnett.plus.com> <510345FA.5000607@mrabarnett.plus.com> Message-ID: Vito De Tullio wrote: > MRAB wrote: > >> It turns out that both S & {x} and {x} & S return {x}, not {y}. > > curious. > > $ python > Python 2.7.3 (default, Jul 3 2012, 19:58:39) > [GCC 4.7.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> x = (1,2,3) >>>> y = (1,2,3) >>>> s = set([y]) >>>> (s & set([x])).pop() is y > False >>>> (set([x]) & s).pop() is y > True > > maybe it's implementation-defined? I think the algorithm looks for the smaller set: >>> set(range(5)) & set(map(float, range(10))) set([0, 1, 2, 3, 4]) >>> set(range(10)) & set(map(float, range(5))) set([0.0, 1.0, 2.0, 3.0, 4.0]) You have two sets of the same length, so there is no advantage in swapping them before calculating the intersection. From ethan at stoneleaf.us Fri Jan 25 18:38:16 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 25 Jan 2013 15:38:16 -0800 Subject: Retrieving an object from a set In-Reply-To: References: Message-ID: <51031768.2080402@stoneleaf.us> On 01/25/2013 03:14 PM, Arnaud Delobelle wrote: > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S which is equal to x. My > problem is how to retrieve y, without going through the whole set. > Here is a simple illustration with tuples (my actual scenario is not > with tuples but with a custom class): > >>>> y = (1, 2, 3) # This is the 'hidden object' >>>> S = set([y] + range(10000)) >>>> x = (1, 2, 3) >>>> x in S > True >>>> x is y > False > > I haven't found y. It's a very simple problem, and this is the > simplest solution I can think of: > > class FindEqual(object): > def __init__(self, obj): > self.obj = obj > def __hash__(self): > return hash(self.obj) > def __eq__(self, other): > equal = self.obj == other > if equal: > self.lastequal = other > return equal > >>>> yfinder = FindEqual(x) >>>> yfinder in S > True >>>> yfinder.lastequal is y > True > > I've found y! I'm not happy with this as it really is a trick. Is > there a cleaner solution? I don't know if there is a cleaner solution, and I quite like yours. Can you tell us, though, why you have to have y if x == y? Is there some subtle difference between the two equal objects? ~Ethan~ From d at davea.name Fri Jan 25 18:56:14 2013 From: d at davea.name (Dave Angel) Date: Fri, 25 Jan 2013 18:56:14 -0500 Subject: Retrieving an object from a set In-Reply-To: References: Message-ID: <51031B9E.70902@davea.name> On 01/25/2013 06:14 PM, Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S which is equal to x. My > problem is how to retrieve y, without going through the whole set. > Here is a simple illustration with tuples (my actual scenario is not > with tuples but with a custom class): > >>>> y = (1, 2, 3) # This is the 'hidden object' >>>> S = set([y] + range(10000)) >>>> x = (1, 2, 3) >>>> x in S > True >>>> x is y > False > > I haven't found y. Baloney. You've got the item y which is equal to x, not identical to x. So just what did you expect? "is" is the wrong comparator. What exactly is your problem? -- DaveA From steve+comp.lang.python at pearwood.info Sat Jan 26 01:25:12 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 26 Jan 2013 17:25:12 +1100 Subject: Retrieving an object from a set References: Message-ID: <510376c9$0$29992$c3e8da3$5496439d@news.astraweb.com> Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S which is equal to x. My > problem is how to retrieve y, without going through the whole set. Why do you care? Since x == y, what benefit do you get from extracting the actual object y? I'm not necessarily saying that you *should not* care, only that it is a very rare occurrence. The only thing I can think of is interning objects, which is best done with a dict, not a set: CACHE = {} def intern(obj): return CACHE.setdefault(obj, obj) which you could then use like this: py> s = "hello world" py> intern(s) 'hello world' py> t = 'hello world' py> t is s False py> intern(t) is s True However, there aren't very many cases where doing this is actually helpful. Under normal circumstances, object equality is much more important than identity, and if you find that identity is important to you, then you probably should rethink your code. So... now that I've told you why you shouldn't do it, here's how you can do it anyway: def retrieve(S, x): """Returns the object in set S which is equal to x.""" s = set(S) # make a copy of S s.discard(x) t = S.difference(s) if t: return t.pop() raise KeyError('not found') S = set(range(10)) y = (1, 2, "hello world") x = (1, 2, "hello world") assert x is not y and x == y S.add(y) z = retrieve(S, x) assert z is y By the way, since this makes a copy of the set, it is O(n). The straight-forward approach: for element in S: if x == element: x = element break is also O(n), but with less overhead. On the other hand, the retrieve function above does most of its work in C, while the straight-forward loop is pure Python, so it's difficult to say which will be faster. I suggest you time them and see. -- Steven From devonfelix79 at yahoo.com Fri Jan 25 22:07:06 2013 From: devonfelix79 at yahoo.com (devonfelix79 at yahoo.com) Date: Fri, 25 Jan 2013 19:07:06 -0800 (PST) Subject: Toontown Message-ID: <885abceb-19d3-4f91-9d45-ad323ee95ca5@googlegroups.com> Hi i am working on tryin to import texture into Toontown. It involves PyDatagrams, Billboard 3d textures and the tt server if anyone could help please post below or aim me at: Gamerboy1998 at yahoo.com :) Thanks. ps: For those of you that do not know toontown runs on python coding. From aquagnu at gmail.com Fri Jan 25 22:31:41 2013 From: aquagnu at gmail.com (Paul) Date: Fri, 25 Jan 2013 19:31:41 -0800 (PST) Subject: doctests/unittest problem with exception Message-ID: Hello. I converted doctests into DocTestSuite() to use with unittest. And try it under Python 3. And, sure, I get errors with unmatched exceptions details (mismatched name of exception class: a.b.c.MyError instead of MyError). So, I have 2 questions: 1) how to turn on option IGNORE_EXCEPTION_DETAIL for all doctests in DocStestSuite (like 'optionflags' argument in doctest.testmod()) 2) Is a way to ignore all 'package path' of exception but not message? Something like: ---cut--- Traceback (most recent call last): ... ...MyError: 'details are not ignored!' ---cut--- see, ellipsis-prefix in MyError From steve+comp.lang.python at pearwood.info Sat Jan 26 22:49:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 27 Jan 2013 14:49:32 +1100 Subject: doctests/unittest problem with exception References: Message-ID: <5104a3cd$0$29997$c3e8da3$5496439d@news.astraweb.com> Paul wrote: > Hello. I converted doctests into DocTestSuite() to use with unittest. And > try it under Python 3. > > And, sure, I get errors with unmatched exceptions details (mismatched name > of exception class: a.b.c.MyError instead of MyError). So, I have 2 > questions: > > 1) how to turn on option IGNORE_EXCEPTION_DETAIL for all doctests in > DocStestSuite (like 'optionflags' argument in doctest.testmod()) Have you tried reading the Fine Manual? If you don't have access to the Python documentation http://docs.python.org/3/library/doctest.html you can get interactive help at the interpreter. Launch the Python interactive interpreter, and then give these two commands: import doctest help(doctest.DocTestSuite) In particular, note that DocTestSuite takes a keyword argument: optionflags A set of doctest option flags expressed as an integer. So try passing optionFlags=doctest.IGNORE_EXCEPTION_DETAIL to the DocTestSuite. > 2) Is a way to ignore all 'package path' of exception but not message? > Something like: > ---cut--- > Traceback (most recent call last): > ... > ...MyError: 'details are not ignored!' > ---cut--- > see, ellipsis-prefix in MyError Have you tried it to see? Add this comment to your docstring, following the line which causes an exception: >>> example() #doctest: +ELLIPSIS Traceback (most recent call last): ... ...MyError: 'details are not ignored!' Does that do what you expect? -- Steven From angel.gutierrez.rodriguez at gmail.com Fri Jan 25 23:41:36 2013 From: angel.gutierrez.rodriguez at gmail.com (Angel) Date: Fri, 25 Jan 2013 20:41:36 -0800 (PST) Subject: Fonts & Tinker Message-ID: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> I am changing the default font for a Tkinter application: class FuelControl(Tkinter.Frame): def __init__(self,master): self.version='0.02' self.font=tkFont.Font(family="Helvetica",size=18) print self.font.actual() . . . and everything looks ok: {'family': 'Nimbus Sans L', 'weight': 'normal', 'slant': 'roman', 'overstrike': 0, 'underline': 0, 'size': 18} and the size of the text are 18 on the screen. Then a button creates a new window through this callback: def loc_add(self): addw=Tix.Tk() addw.title('Add location') print self.font.actual() Tkinter.Label(addw,text='Nickname:', font=self.font).grid(row=0,column=0) Tkinter.Label(addw,text='Fullname:', font=self.font).grid(row=1,column=0) Tkinter.Label(addw,text='Address:', font=self.font).grid(row=2,column=0) Tkinter.Label(addw,text='Fuel name:',font=self.font).grid(row=3,column=0) ... The self.font stays with the right value: {'family': 'Nimbus Sans L', 'weight': 'normal', 'slant': 'roman', 'overstrike': 0, 'underline': 0, 'size': 18} but the real displayed fonts in the window are smaller (default size of 12, maybe). Am I missing something? Thanks in advance, A. From angel.gutierrez.rodriguez at gmail.com Fri Jan 25 23:42:36 2013 From: angel.gutierrez.rodriguez at gmail.com (Angel) Date: Fri, 25 Jan 2013 20:42:36 -0800 (PST) Subject: Fonts & Tinker In-Reply-To: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> References: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> Message-ID: <5cf7db22-8108-4255-996b-87bf44066f2a@googlegroups.com> Dammm it should be Tkinter for subject..:D From aquagnu at gmail.com Sat Jan 26 00:18:01 2013 From: aquagnu at gmail.com (Paul) Date: Fri, 25 Jan 2013 21:18:01 -0800 (PST) Subject: Fonts & Tinker In-Reply-To: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> References: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> Message-ID: class FontSpec: """Wrapper for something like 'Arial 10 bold #red' """ tkf = None # Tk Font spec = "" # specification tkspec = "" # specification for Tk family = None size = 0 color = "black" weight = "normal" slant = "roman" underline = 0 overstrike = 0 linespace = 0 descent = 0 ascent = 0 def __init__(self, spec=None): """spec: familty with capital letter, color with # (#red, ##FF00FF), size - int, other are styles""" try: if not spec: return spec = spec.split() family = [s for s in spec if s.istitle()] if family: self.family = family[0] spec.remove(self.family) color = [s for s in spec if s.startswith('#')] if color: self.color = color[0] spec.remove(self.color) self.color = self.color[1:] size = [s for s in spec if s.isdigit()] if size: self.size = size[0] spec.remove(self.size) self.size = int(self.size) if "bold" in spec: self.weight = "bold" if "italic" in spec: self.slant = "italic" if "underline" in spec: self.underline = 1 if "overstrike" in spec: self.overstrike = 1 # create tkFont for metrics self.tkf = tkFont.Font(family=self.family, size=self.size, weight=self.weight, slant=self.slant, underline=self.underline, overstrike=self.overstrike) self.ascent = self.tkf.metrics("ascent") self.descent = self.tkf.metrics("descent") self.linespace = self.tkf.metrics("linespace") # tkspec - specific. of font in Tk standard self.tkspec = [] if self.family: self.tkspec.append(self.family) if self.size: self.tkspec.append(str(self.size)) if self.weight == "bold": self.tkspec.append("bold") if self.slant == "italic": self.tkspec.append("italic") if self.underline: self.tkspec.append("underline") if self.overstrike: self.tkspec.append("overstrike") self.tkspec = " ".join(self.tkspec) except: raise ValueError("invalid font specification") def __str__(self): return self.tkspec --- only for ideas From rantingrickjohnson at gmail.com Sun Jan 27 10:34:58 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 27 Jan 2013 07:34:58 -0800 (PST) Subject: Fonts & Tinker In-Reply-To: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> References: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> Message-ID: On Friday, January 25, 2013 10:41:36 PM UTC-6, Angel wrote: > I am changing the default font for a Tkinter application: > > > > class FuelControl(Tkinter.Frame): > > def __init__(self,master): > > self.version='0.02' > > self.font=tkFont.Font(family="Helvetica",size=18) > > print self.font.actual() You may want to check out these universal Tkinter widget methods: w.option_add(pattern, value, priority=None) w.option_clear() w.option_get(name, classname) w.option_readfile(fileName, priority=None) http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html While you are there, poke around the docs a bit because there is tons of good info you are going to need in the future. May want to get familiar with the new ttk widgets and themes. From mail at lukaszposadowski.pl Mon Jan 28 06:28:56 2013 From: mail at lukaszposadowski.pl (=?UTF-8?Q?=C5=81ukasz?= Posadowski) Date: Mon, 28 Jan 2013 12:28:56 +0100 Subject: [SPAM] Fonts & Tinker In-Reply-To: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> References: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> Message-ID: <1359372536.1774.5.camel@localhost> Dnia 2013-01-25, pi? o godzinie 20:41 -0800, Angel pisze: > but the real displayed fonts in the window are smaller (default size of 12, maybe). > > Am I missing something? > > Thanks in advance, > A. > Did you tried this by simple: --------------------------- root = Tk() root.option_add('*Font', "Heveltica 14") --------------------------- We'll see if it's a local tkinter installation problem. -- ?ukasz Posadowski From angel.gutierrez.rodriguez at gmail.com Wed Jan 30 05:08:27 2013 From: angel.gutierrez.rodriguez at gmail.com (Angel) Date: Wed, 30 Jan 2013 02:08:27 -0800 (PST) Subject: Fonts & Tinker In-Reply-To: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> References: <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> Message-ID: <1d69c340-0824-48d6-b3ec-7e27b7175bb3@googlegroups.com> THis one workd fine: .....option_add('*Font', "Heveltica 14") Thanks! ?. From jupiter.hce at gmail.com Sat Jan 26 06:19:20 2013 From: jupiter.hce at gmail.com (nobody) Date: Sat, 26 Jan 2013 03:19:20 -0800 (PST) Subject: sockobj.connect Errno 13 Permission denied Message-ID: Hi, I have a client program Client.py which has a statement of sockobj.connect(), the port number 60000 is used, so no problem from port permission. I am puzzled because I can run Client.py from command line in my user account or apache user account without any problems. But if I run it from a web page http://localhost/client.php, the client.php called exec("Client.py"), then it got an exception of sockobj.connect Errno 13 Permission denied. Why it can run from command line, but cannot make connection from a web file? Appreciate any tips and clues. Thank you. Kind regards. From joel.goldstick at gmail.com Sat Jan 26 08:47:20 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 26 Jan 2013 08:47:20 -0500 Subject: sockobj.connect Errno 13 Permission denied In-Reply-To: References: Message-ID: On Sat, Jan 26, 2013 at 6:19 AM, nobody wrote: > Hi, > > I have a client program Client.py which has a statement of > sockobj.connect(), the port number 60000 is used, so no problem from port > permission. > > I am puzzled because I can run Client.py from command line in my user > account or apache user account without any problems. > > But if I run it from a web page http://localhost/client.php, the > client.php called exec("Client.py"), Check the arguments to exec. I think it has to be an open file object. > then it got an exception of sockobj.connect Errno 13 Permission denied. > > Why it can run from command line, but cannot make connection from a web > file? Appreciate any tips and clues. > > Thank you. > > Kind regards. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Sat Jan 26 08:52:37 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 26 Jan 2013 08:52:37 -0500 Subject: sockobj.connect Errno 13 Permission denied In-Reply-To: References: Message-ID: On Sat, Jan 26, 2013 at 8:47 AM, Joel Goldstick wrote: > > > > On Sat, Jan 26, 2013 at 6:19 AM, nobody wrote: > >> Hi, >> >> I have a client program Client.py which has a statement of >> sockobj.connect(), the port number 60000 is used, so no problem from port >> permission. >> >> I am puzzled because I can run Client.py from command line in my user >> account or apache user account without any problems. >> >> But if I run it from a web page http://localhost/client.php, the >> client.php called exec("Client.py"), > > > > Check the arguments to exec. I think it has to be an open file object. > > > >> then it got an exception of sockobj.connect Errno 13 Permission denied. >> >> Why it can run from command line, but cannot make connection from a web >> file? Appreciate any tips and clues. >> >> Thank you. >> >> Kind regards. >> >> >> Maybe I spoke too soon. You should probably be asking in a php forum since what you are doing is running a php exec. If you are actually getting a python error you should show the code and the traceback so that someone can look at your code. In either case (py and php) it looks like exec needs either a string of executable text or (in py case) an open file handle. So the code you describe isn't really what you are running > >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Joel Goldstick > http://joelgoldstick.com > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From marduk at letterboxes.org Sat Jan 26 12:07:22 2013 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 26 Jan 2013 12:07:22 -0500 Subject: sockobj.connect Errno 13 Permission denied In-Reply-To: References: Message-ID: <1359220042.19038.140661182691377.14E3FF96@webmail.messagingengine.com> On Sat, Jan 26, 2013, at 08:52 AM, Joel Goldstick wrote: > On Sat, Jan 26, 2013 at 8:47 AM, Joel Goldstick > wrote: > > > > > > > > > On Sat, Jan 26, 2013 at 6:19 AM, nobody wrote: > > > >> Hi, > >> > >> I have a client program Client.py which has a statement of > >> sockobj.connect(), the port number 60000 is used, so no problem from port > >> permission. > >> > >> I am puzzled because I can run Client.py from command line in my user > >> account or apache user account without any problems. > >> > >> But if I run it from a web page http://localhost/client.php, the > >> client.php called exec("Client.py"), > > > > > > > > Check the arguments to exec. I think it has to be an open file object. > > > > > > > >> then it got an exception of sockobj.connect Errno 13 Permission denied. > >> > >> Why it can run from command line, but cannot make connection from a web > >> file? Appreciate any tips and clues. > >> > >> Thank you. > >> > >> Kind regards. > >> > >> > >> > Maybe I spoke too soon. You should probably be asking in a php forum > since > what you are doing is running a php exec. If you are actually getting a > python error you should show the code and the traceback so that someone > can > look at your code. > > In either case (py and php) it looks like exec needs either a string of > executable text or (in py case) an open file handle. So the code you > describe isn't really what you are running > Also your php/apache config needs to be set up to enable execs (I think it's off by the default). Either way it's a PHP question, not a Python question. From hyperboreean at nerdshack.com Sat Jan 26 08:14:08 2013 From: hyperboreean at nerdshack.com (hyperboreean) Date: Sat, 26 Jan 2013 15:14:08 +0200 Subject: Cancel threads after timeout Message-ID: <20130126131408.GA6300@sagitarius.getae.net> Here's the use case I want to implement - I have to generate a report from multiple database servers. This report should be generated every 2 hours. Sometimes it happens that a query on one of the database servers takes longer than expected and impedes the generation of this report (that's right, the queries are ran sequential). What I am trying to achieve is to parallelize the queries on each database server and to be able to cancel one of them if it takes longer than X minutes. threading.Thread doesn't support this and seems that in general programming languages don't implement a way to cancel threads from the outside. Now, I've read all the stackoverflow threads about killing a thread, canceling a thread after a timeout, but all of them imply that you are able to check from within the thread if you should end the computation or not - that's not really my case, where the computation is a SQL query. So, what I have in mind is something like: the main loop starts a threading.Thread which in turn is responsible for starting another thread in which the actual computation happens (could be a threading.Thread or a multiprocessing.Process) *and* checks if the specified timeout has passed. If the time is up, it exits, letting the main loop know. Lots of words, no code - let me know if you have any suggestions, ideas to this rant. Thanks! From jsf80238 at gmail.com Sat Jan 26 10:43:26 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 26 Jan 2013 08:43:26 -0700 Subject: Cancel threads after timeout In-Reply-To: <20130126131408.GA6300@sagitarius.getae.net> References: <20130126131408.GA6300@sagitarius.getae.net> Message-ID: > Sometimes it happens that a query on one of the database servers > takes longer than expected and impedes the generation of this report > (that's right, the queries are ran sequential). What I am trying to > achieve is to parallelize the queries on each database server and to be > able to cancel one of them if it takes longer than X minutes. Only answering a small portion of your question .... Assuming you are able to figure out how to "cancel" a thread or process on your side, it is possible the database itself will not respect that. In other words, if you execute "SELECT ..." singly, outside of Python, and type CNTL-C, does your database quickly recognize you are no longer interested in the result set and stop its work? From matt.walker.jones at gmail.com Sat Jan 26 10:48:31 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Sat, 26 Jan 2013 09:48:31 -0600 Subject: Cancel threads after timeout In-Reply-To: References: <20130126131408.GA6300@sagitarius.getae.net> Message-ID: It sounds like your real problem is with your SQL query... Is that part of this problem under your control? Can you break the query into smaller, quicker, pieces that you can run in a reasonable amount of time? If not, nesting threads might be your best programmatic solution. Heed Jason's warning though that the SQL Server my still be working even if you cancel an operation from the outside (which could compound your problem). *Matt Jones* On Sat, Jan 26, 2013 at 9:43 AM, Jason Friedman wrote: > > Sometimes it happens that a query on one of the database servers > > takes longer than expected and impedes the generation of this report > > (that's right, the queries are ran sequential). What I am trying to > > achieve is to parallelize the queries on each database server and to be > > able to cancel one of them if it takes longer than X minutes. > > Only answering a small portion of your question .... > Assuming you are able to figure out how to "cancel" a thread or > process on your side, it is possible the database itself will not > respect that. In other words, if you execute "SELECT ..." singly, > outside of Python, and type CNTL-C, does your database quickly > recognize you are no longer interested in the result set and stop its > work? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Sat Jan 26 19:34:13 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 27 Jan 2013 11:34:13 +1100 Subject: Cancel threads after timeout In-Reply-To: References: Message-ID: <20130127003413.GA21696@cskk.homeip.net> On 26Jan2013 09:48, Matt Jones wrote: | It sounds like your real problem is with your SQL query... Is that part of | this problem under your control? Can you break the query into smaller, | quicker, pieces that you can run in a reasonable amount of time? Another option to investigate is whether you can ask the database itself to limit the run time of a query. Of course, that will abort the query but so does your proposed solution. Another approach might be to simply run each query regularly (with a pause between so the database is not spending its whole life running your query). Snapshot each latest result. Compute your report from the latest pair of snapshots at any given time on an independent schedule. It may not be valid for what you need, but if it is then this decouples you from the query time completely. Cheers, -- Cameron Simpson Do not taunt Happy Fun Coder. From jsf80238 at gmail.com Sun Jan 27 23:57:14 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 27 Jan 2013 21:57:14 -0700 Subject: Cancel threads after timeout In-Reply-To: <20130127003413.GA21696@cskk.homeip.net> References: <20130127003413.GA21696@cskk.homeip.net> Message-ID: > On 26Jan2013 09:48, Matt Jones wrote: > | It sounds like your real problem is with your SQL query... Is that part of > | this problem under your control? Can you break the query into smaller, > | quicker, pieces that you can run in a reasonable amount of time? > > Another option to investigate is whether you can ask the database itself > to limit the run time of a query. Of course, that will abort the query > but so does your proposed solution. > > Another approach might be to simply run each query regularly (with a > pause between so the database is not spending its whole life running > your query). Snapshot each latest result. Compute your report from the > latest pair of snapshots at any given time on an independent schedule. > It may not be valid for what you need, but if it is then this decouples > you from the query time completely. Along these lines, if you are running on Linux then the bash shell comes with a "timeout" command, which you can prepend to snapshot requests. From cs at zip.com.au Mon Jan 28 01:40:24 2013 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 28 Jan 2013 17:40:24 +1100 Subject: Cancel threads after timeout In-Reply-To: References: Message-ID: <20130128064024.GA16727@cskk.homeip.net> On 27Jan2013 21:57, Jason Friedman wrote: | > On 26Jan2013 09:48, Matt Jones wrote: | > | It sounds like your real problem is with your SQL query... Is that part of | > | this problem under your control? Can you break the query into smaller, | > | quicker, pieces that you can run in a reasonable amount of time? | > | > Another option to investigate is whether you can ask the database itself | > to limit the run time of a query. Of course, that will abort the query | > but so does your proposed solution. | > | > Another approach might be to simply run each query regularly (with a | > pause between so the database is not spending its whole life running | > your query). Snapshot each latest result. Compute your report from the | > latest pair of snapshots at any given time on an independent schedule. | > It may not be valid for what you need, but if it is then this decouples | > you from the query time completely. | | Along these lines, if you are running on Linux then the bash shell | comes with a "timeout" command, which you can prepend to snapshot | requests. I was thinking that if he does something equivalent to: while :; do run-sql-query1-with-snapshot-of-result; sleep 900; done & while :; do run-sql-query2-with-snapshot-of-result; sleep 900; done & while : do report on latest pair of snapshots sleep 7200 done Then he doesn't need any timeouts. Cheers, -- Cameron Simpson From hyperboreean at nerdshack.com Sun Jan 27 04:51:49 2013 From: hyperboreean at nerdshack.com (hyperboreean) Date: Sun, 27 Jan 2013 11:51:49 +0200 Subject: Cancel threads after timeout In-Reply-To: References: <20130126131408.GA6300@sagitarius.getae.net> Message-ID: <20130127095127.GA12570@sagitarius.getae.net> On 01/26, Matt Jones wrote: The SQL part is not under control and getting it there requires more development time than the management is willing to allocate. So this would be a first step before refactoring that part. I'm aware that the database might not notice that I don't want to receive the result of the query, but I'm willing to assume that risk for now. Thank you. > It sounds like your real problem is with your SQL query... Is that part of > this problem under your control? Can you break the query into smaller, > quicker, pieces that you can run in a reasonable amount of time? > > If not, nesting threads might be your best programmatic solution. Heed > Jason's warning though that the SQL Server my still be working even if you > cancel an operation from the outside (which could compound your problem). > > *Matt Jones* > > > On Sat, Jan 26, 2013 at 9:43 AM, Jason Friedman wrote: > > > > Sometimes it happens that a query on one of the database servers > > > takes longer than expected and impedes the generation of this report > > > (that's right, the queries are ran sequential). What I am trying to > > > achieve is to parallelize the queries on each database server and to be > > > able to cancel one of them if it takes longer than X minutes. > > > > Only answering a small portion of your question .... > > Assuming you are able to figure out how to "cancel" a thread or > > process on your side, it is possible the database itself will not > > respect that. In other words, if you execute "SELECT ..." singly, > > outside of Python, and type CNTL-C, does your database quickly > > recognize you are no longer interested in the result set and stop its > > work? > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list From dieter at handshake.de Sun Jan 27 02:29:08 2013 From: dieter at handshake.de (dieter) Date: Sun, 27 Jan 2013 08:29:08 +0100 Subject: Cancel threads after timeout References: <20130126131408.GA6300@sagitarius.getae.net> Message-ID: <871ud79j97.fsf@handshake.de> hyperboreean writes: > Here's the use case I want to implement - I have to generate a report > from multiple database servers. This report should be generated every 2 > hours. Sometimes it happens that a query on one of the database servers > takes longer than expected and impedes the generation of this report > (that's right, the queries are ran sequential). What I am trying to > achieve is to parallelize the queries on each database server and to be > able to cancel one of them if it takes longer than X minutes. > threading.Thread doesn't support this and seems that in > general programming languages don't implement a way to cancel threads > from the outside. And it is difficult in general. The problem lies in the interaction between Python and (unknown by Python) C extensions. Many C extensions would not work properly when simply aborted in between (loose memory, fail to release resources, leave an inconsistent state). You need something like "try: ... finally: ..." or "try: ... except: ..." to have the ability to handle asynchronous aborts - but C lacks such support. In the light of this difficulty, the Python developpers decided not to expose the possibility of many threading packages to abort a thread. I was told that their is an approximative function at the Python C interface (in Python 2, not sure whether it is also available in Python 3): a function that allows you register the wish for a thread aborting. This wish is recognized only when the thread is on Python (not C) level (thus, not applicable in your case) and it causes an exception that normally leads to the thread abortion but plays well with Python's "try: ... finally: ..." and "try: ... except: ...": thus, the thread can properly clean up. You best approach is probably to ask the databases in parallel, wait for some time and simply ignore answers that do not arrive within that time (without any aborting trial). From rosegun38 at gmail.com Sun Jan 27 03:27:25 2013 From: rosegun38 at gmail.com (Jason Ma) Date: Sun, 27 Jan 2013 16:27:25 +0800 Subject: Cancel threads after timeout In-Reply-To: <20130126131408.GA6300@sagitarius.getae.net> References: <20130126131408.GA6300@sagitarius.getae.net> Message-ID: I am not sure which database you're using, but all the mainstream RDBMS is server-client Architecture, when you're running one DML(including the SELECT), the RDBMS setting up a server process, the query running in that process instead of your client process, so I guess your problem can solved in the database layer more elegant than in your program. 1. Investigate the reason why you're take more time 2. Find your DBA or yourself, setting the related parameters in the database. 3. If possible, using some embedded language in the database (like PL/SQL in Oracle), it is more convenient. Regards, Jason 2013/1/26 hyperboreean > Here's the use case I want to implement - I have to generate a report > from multiple database servers. This report should be generated every 2 > hours. Sometimes it happens that a query on one of the database servers > takes longer than expected and impedes the generation of this report > (that's right, the queries are ran sequential). What I am trying to > achieve is to parallelize the queries on each database server and to be > able to cancel one of them if it takes longer than X minutes. > threading.Thread doesn't support this and seems that in > general programming languages don't implement a way to cancel threads > from the outside. > > Now, I've read all the stackoverflow threads about killing a thread, > canceling a thread after a timeout, but all of them imply that you are > able to check from within the thread if you should end the computation > or not - that's not really my case, where the computation is a SQL > query. > > So, what I have in mind is something like: the main loop starts a > threading.Thread which in turn is responsible for starting another > thread in which the actual computation happens (could be a > threading.Thread or a multiprocessing.Process) *and* checks if the > specified timeout has passed. If the time is up, it exits, letting the > main loop know. > > Lots of words, no code - let me know if you have any suggestions, ideas > to this rant. > > Thanks! > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Best wishes, Jason Ma -------------- next part -------------- An HTML attachment was scrubbed... URL: From joao.cowperthwaite at nobleprog.us Sat Jan 26 11:12:22 2013 From: joao.cowperthwaite at nobleprog.us (joao.cowperthwaite at nobleprog.us) Date: Sat, 26 Jan 2013 08:12:22 -0800 (PST) Subject: Python Programming - 28 hours training in New York for $3999 Message-ID: <2ff3746a-926e-4b25-8e3f-05b5e967aa93@googlegroups.com> Python Programming - 28 hours training in New York for $3999 Course Outline: http://www.nobleprog.us/python-programming/training-course Course Date: 2013-03-05 09:30 - 2013-03-08 16:30 Course Price: $3999 per person, usually $4730 per person Remarks: A complimentary lunch will be provided Venue: 369 Lexington Ave New York, New York 10017 Please use the link below to book: http://be.nobleprog.us/node/add/course-booking?ce=751 Link(s) to other Courses you might be interested in: http://www.nobleprog.us/python-training-courses Thanks NobleProg LLC If you need any further information please contact us at: training at nobleprog.us or 646 461 6132 From juhani.karlsson at talvi.com Sat Jan 26 11:38:26 2013 From: juhani.karlsson at talvi.com (Juhani Karlsson) Date: Sat, 26 Jan 2013 18:38:26 +0200 Subject: Python Programming - 28 hours training in New York for $3999 In-Reply-To: <2ff3746a-926e-4b25-8e3f-05b5e967aa93@googlegroups.com> References: <2ff3746a-926e-4b25-8e3f-05b5e967aa93@googlegroups.com> Message-ID: https://www.edx.org/courses/MITx/6.00x/2013_Spring/about Or take this course for free and buy 500 lunches. Your choice. On 26 January 2013 18:12, wrote: > Python Programming - 28 hours training in New York for $3999 > > > Course Outline: http://www.nobleprog.us/python-programming/training-course > > Course Date: 2013-03-05 09:30 - 2013-03-08 16:30 > Course Price: $3999 per person, usually $4730 per person > Remarks: A complimentary lunch will be provided > > Venue: > 369 Lexington Ave > New York, New York 10017 > > Please use the link below to book: > http://be.nobleprog.us/node/add/course-booking?ce=751 > > Link(s) to other Courses you might be interested in: > http://www.nobleprog.us/python-training-courses > > > Thanks > NobleProg LLC > > If you need any further information please contact us at: > training at nobleprog.us or 646 461 6132 > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- Juhani Karlsson 3D Artist/TD Talvi Digital Oy Pursimiehenkatu 29-31 b 2krs. 00150 Helsinki +358 443443088 juhani.karlsson at talvi.fi www.vimeo.com/talvi -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Jan 26 18:57:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 10:57:18 +1100 Subject: Python Programming - 28 hours training in New York for $3999 In-Reply-To: References: <2ff3746a-926e-4b25-8e3f-05b5e967aa93@googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 3:38 AM, Juhani Karlsson wrote: > Or take this course for free and buy 500 lunches. > Your choice. You spend $8 on lunch? Wow, that's taking TANSTAAFL a long way... ChrisA From d at davea.name Sat Jan 26 19:15:34 2013 From: d at davea.name (Dave Angel) Date: Sat, 26 Jan 2013 19:15:34 -0500 Subject: Python Programming - 28 hours training in New York for $3999 In-Reply-To: References: <2ff3746a-926e-4b25-8e3f-05b5e967aa93@googlegroups.com> Message-ID: <510471A6.7040201@davea.name> On 01/26/2013 06:57 PM, Chris Angelico wrote: > On Sun, Jan 27, 2013 at 3:38 AM, Juhani Karlsson > wrote: >> Or take this course for free and buy 500 lunches. >> Your choice. > > You spend $8 on lunch? Wow, that's taking TANSTAAFL a long way... > > ChrisA > MYCROFTXXX I remember when lunches at IBM were never more than $1 -- DaveA From juhani.karlsson at talvi.com Sat Jan 26 19:24:15 2013 From: juhani.karlsson at talvi.com (Juhani Karlsson) Date: Sun, 27 Jan 2013 02:24:15 +0200 Subject: Python Programming - 28 hours training in New York for $3999 In-Reply-To: References: <2ff3746a-926e-4b25-8e3f-05b5e967aa93@googlegroups.com> Message-ID: Hah yeah! 8e is normal price here in Finland. : ) On 27 January 2013 01:57, Chris Angelico wrote: > On Sun, Jan 27, 2013 at 3:38 AM, Juhani Karlsson > wrote: > > Or take this course for free and buy 500 lunches. > > Your choice. > > You spend $8 on lunch? Wow, that's taking TANSTAAFL a long way... > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- Juhani Karlsson 3D Artist/TD Talvi Digital Oy Pursimiehenkatu 29-31 b 2krs. 00150 Helsinki +358 443443088 juhani.karlsson at talvi.fi www.vimeo.com/talvi -------------- next part -------------- An HTML attachment was scrubbed... URL: From bv8bv8bv8 at gmail.com Sat Jan 26 11:41:03 2013 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 26 Jan 2013 08:41:03 -0800 (PST) Subject: ??????????? DOES GOG EXIST Message-ID: <0e1e1fd3-916b-4f83-9272-b5d6f5620bb0@4g2000yqv.googlegroups.com> DOES GOG EXIST http://www.youtube.com/watch?v=tRMmTbCXXAk&feature=related THANK YOU From wuwei23 at gmail.com Sat Jan 26 18:31:16 2013 From: wuwei23 at gmail.com (alex23) Date: Sat, 26 Jan 2013 15:31:16 -0800 (PST) Subject: ??????????? DOES GOG EXIST References: <0e1e1fd3-916b-4f83-9272-b5d6f5620bb0@4g2000yqv.googlegroups.com> Message-ID: <97c312a5-ec3d-4501-aed8-94d35342d05e@w9g2000pbg.googlegroups.com> On Jan 27, 2:41?am, BV BV wrote: > DOES GOG EXIST Yes, they've been happily selling non-DRMed games for years now: http://www.gog.com/ Highly recommended. From frank at chagford.com Sun Jan 27 00:34:25 2013 From: frank at chagford.com (Frank Millman) Date: Sun, 27 Jan 2013 07:34:25 +0200 Subject: ??????????? DOES GOG EXIST In-Reply-To: <0e1e1fd3-916b-4f83-9272-b5d6f5620bb0@4g2000yqv.googlegroups.com> References: <0e1e1fd3-916b-4f83-9272-b5d6f5620bb0@4g2000yqv.googlegroups.com> Message-ID: On 26/01/2013 18:41, BV BV wrote: > > DOES GOG EXIST > > > http://www.youtube.com/watch?v=tRMmTbCXXAk&feature=related > > > > THANK YOU > Did you hear about the dyslexic agnostic insomniac? He lies awake at night wondering if there is a dog. From nikos.gr33k at gmail.com Sat Jan 26 12:51:32 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 26 Jan 2013 09:51:32 -0800 (PST) Subject: Formatting a column's value output Message-ID: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> try: cur.execute( '''SELECT URL, hits FROM counters ORDER BY hits DESC''' ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) else: data = cur.fetchall() for row in data: print ( "
" ) for item in row: print ( "" % item ) sys.exit(0) ===================================== In the aboce code wheb 'URL' is to be typed out be print i need it to be formatted as a link, so the viewer can click on it. Is this possible please? Thank you. From rosuav at gmail.com Sat Jan 26 13:04:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 05:04:12 +1100 Subject: Formatting a column's value output In-Reply-To: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus wrote: > print ( "" % item ) > > In the aboce code wheb 'URL' is to be typed out be print i need it to be formatted as a link, so the viewer can click on it. > > Is this possible please? Easy, just make a tuple of item,item and have two %s markers: print( "" % (item, item) ) But you need to concern yourself with escaping. In fact, you already needed to, just to produce it as text - but it's now even more important. I strongly suggest you look into that. ChrisA From nikos.gr33k at gmail.com Sat Jan 26 14:41:40 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 26 Jan 2013 11:41:40 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: ?? ???????, 26 ?????????? 2013 8:04:12 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus wrote: > > > print ( "" % item ) > > > > > > > > In the aboce code wheb 'URL' is to be typed out be print i need it to be formatted as a link, so the viewer can click on it. > > > > > > Is this possible please? > > > > Easy, just make a tuple of item,item and have two %s markers: > > > > print( "" % (item, item) ) > > > > But you need to concern yourself with escaping. In fact, you already > > needed to, just to produce it as text - but it's now even more > > important. I strongly suggest you look into that. I can use triple (''') quoting so i dont have to escape special characters. But i didnt understand you suggestion about the tuple. The dataset returns many lines and i need to transfor only the URL column.... Sorry i did not understood. From nikos.gr33k at gmail.com Sat Jan 26 14:41:40 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 26 Jan 2013 11:41:40 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: ?? ???????, 26 ?????????? 2013 8:04:12 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus wrote: > > > print ( "" % item ) > > > > > > > > In the aboce code wheb 'URL' is to be typed out be print i need it to be formatted as a link, so the viewer can click on it. > > > > > > Is this possible please? > > > > Easy, just make a tuple of item,item and have two %s markers: > > > > print( "" % (item, item) ) > > > > But you need to concern yourself with escaping. In fact, you already > > needed to, just to produce it as text - but it's now even more > > important. I strongly suggest you look into that. I can use triple (''') quoting so i dont have to escape special characters. But i didnt understand you suggestion about the tuple. The dataset returns many lines and i need to transfor only the URL column.... Sorry i did not understood. From torriem at gmail.com Sat Jan 26 17:26:44 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 26 Jan 2013 15:26:44 -0700 Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: <51045824.7000502@gmail.com> On 01/26/2013 12:41 PM, Ferrous Cranus wrote: > I can use triple (''') quoting so i dont have to escape special characters. Hmm. I think you missed what he was getting at. He's not talking about Python escape sequences. He's talking about HTML ones. There is a function in one of the standard library modules that does this. I think it's called html_sanitize or something. Google will find this. > But i didnt understand you suggestion about the tuple. What don't you understand about it? It's basic python string formatting (well python 2.x string formatting). http://docs.python.org/2/library/stdtypes.html#string-formatting-operations A tuple is one method for passing variables into the string formatter. So if you need to display something twice, just put in two "%s" in the format string, and pass it the same variable twice. > The dataset returns many lines and i need to transfor only the URL column.... > Sorry i did not understood. From nikos.gr33k at gmail.com Sun Jan 27 04:04:25 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 27 Jan 2013 01:04:25 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: ?? ???????, 27 ?????????? 2013 12:26:44 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > A tuple is one method for passing variables into the string formatter. > > So if you need to display something twice, just put in two "%s" in the > > format string, and pass it the same variable twice. Yes i know what a tuple is, iam just telling that the next code: ================================ try: cur.execute( '''SELECT URL, hits FROM counters ORDER BY hits DESC''' ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) else: data = cur.fetchall() for row in data: print ( "" ) for item in row: print( '''''' % (item, item) ) sys.exit(0) ================================= 1. ruteruns a dataset 2. seperate each rows 3. itermate over the items of a row. Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only? From nikos.gr33k at gmail.com Sun Jan 27 04:04:25 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 27 Jan 2013 01:04:25 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: ?? ???????, 27 ?????????? 2013 12:26:44 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > A tuple is one method for passing variables into the string formatter. > > So if you need to display something twice, just put in two "%s" in the > > format string, and pass it the same variable twice. Yes i know what a tuple is, iam just telling that the next code: ================================ try: cur.execute( '''SELECT URL, hits FROM counters ORDER BY hits DESC''' ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) else: data = cur.fetchall() for row in data: print ( "" ) for item in row: print( '''''' % (item, item) ) sys.exit(0) ================================= 1. ruteruns a dataset 2. seperate each rows 3. itermate over the items of a row. Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only? From rosuav at gmail.com Sun Jan 27 04:08:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 20:08:15 +1100 Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 8:04 PM, Ferrous Cranus wrote: > Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only? Step 1: Learn to read documentation. Step 2: Learn to write code, rather than just ask someone else to do it for free. ChrisA From nikos.gr33k at gmail.com Sun Jan 27 04:16:29 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 27 Jan 2013 01:16:29 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: <0f1f99da-f2fd-472c-8be3-d333289f7a9f@googlegroups.com> ?? ???????, 27 ?????????? 2013 11:08:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sun, Jan 27, 2013 at 8:04 PM, Ferrous Cranus wrote: > > > Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only? > > > > Step 1: Learn to read documentation. > > Step 2: Learn to write code, rather than just ask someone else to do > > it for free. I have tried code and i have showed to you, bu i cannot get it to work as i want, thats why i ask. The solution you provided me its not correct. From rosuav at gmail.com Sun Jan 27 04:26:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 20:26:38 +1100 Subject: Formatting a column's value output In-Reply-To: <0f1f99da-f2fd-472c-8be3-d333289f7a9f@googlegroups.com> References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <0f1f99da-f2fd-472c-8be3-d333289f7a9f@googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 8:16 PM, Ferrous Cranus wrote: > ?? ???????, 27 ?????????? 2013 11:08:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> On Sun, Jan 27, 2013 at 8:04 PM, Ferrous Cranus wrote: >> >> > Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only? >> >> >> >> Step 1: Learn to read documentation. >> >> Step 2: Learn to write code, rather than just ask someone else to do >> >> it for free. > > I have tried code and i have showed to you, bu i cannot get it to work as i want, thats why i ask. The solution you provided me its not correct. You have been given a number of hints. Coding requires work, not just complaining that someone else's code "is not correct". Either pay someone to do the work, or do it yourself, but don't expect and demand that volunteers do it for you. http://www.catb.org/esr/faqs/smart-questions.html ChrisA From nikos.gr33k at gmail.com Sun Jan 27 04:16:29 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 27 Jan 2013 01:16:29 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: <0f1f99da-f2fd-472c-8be3-d333289f7a9f@googlegroups.com> ?? ???????, 27 ?????????? 2013 11:08:15 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sun, Jan 27, 2013 at 8:04 PM, Ferrous Cranus wrote: > > > Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only? > > > > Step 1: Learn to read documentation. > > Step 2: Learn to write code, rather than just ask someone else to do > > it for free. I have tried code and i have showed to you, bu i cannot get it to work as i want, thats why i ask. The solution you provided me its not correct. From nikos.gr33k at gmail.com Sun Jan 27 04:30:12 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Sun, 27 Jan 2013 01:30:12 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <0f1f99da-f2fd-472c-8be3-d333289f7a9f@googlegroups.com> Message-ID: <83b86472-b769-42f1-b913-f69db7a23490@googlegroups.com> ?? ???????, 27 ?????????? 2013 11:26:38 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > You have been given a number of hints. Coding requires work, not just > > complaining that someone else's code "is not correct". Either pay > > someone to do the work, or do it yourself, but don't expect and demand > > that volunteers do it for you. This is a free usenet newsgroup about python problems, so i expect free *voluntary* help. If you dont want to help then dont. Its not that i didnt try to write the code, i tried and cannot proceed from there. From nikos.gr33k at gmail.com Sun Jan 27 04:30:12 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Sun, 27 Jan 2013 01:30:12 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <0f1f99da-f2fd-472c-8be3-d333289f7a9f@googlegroups.com> Message-ID: <83b86472-b769-42f1-b913-f69db7a23490@googlegroups.com> ?? ???????, 27 ?????????? 2013 11:26:38 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > You have been given a number of hints. Coding requires work, not just > > complaining that someone else's code "is not correct". Either pay > > someone to do the work, or do it yourself, but don't expect and demand > > that volunteers do it for you. This is a free usenet newsgroup about python problems, so i expect free *voluntary* help. If you dont want to help then dont. Its not that i didnt try to write the code, i tried and cannot proceed from there. From rurpy at yahoo.com Sun Jan 27 11:12:59 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 27 Jan 2013 08:12:59 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> On 01/27/2013 02:04 AM, Ferrous Cranus wrote: >[...] > data = cur.fetchall() > for row in data: > print ( "" ) > > for item in row: > print( '''''' % (item, item) ) >[...] > Okey, so far BUT i want the url linking to happen only for the URL column's > value, and not for the hits column too. How do i apply the url link to the > URL column's value only? Ferrous, 'row' has two items (the url and the hit count) in it, right? So print each separately rather than in a loop: data = cur.fetchall() for row in data: url = row[0] hits = row[1] print ( "" ) print( ": % (url, hits) ) From vs at it.uu.se Sun Jan 27 12:46:24 2013 From: vs at it.uu.se (Virgil Stokes) Date: Sun, 27 Jan 2013 18:46:24 +0100 Subject: Formatting a column's value output In-Reply-To: <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> Message-ID: <510567F0.2030907@it.uu.se> On 27-Jan-2013 17:12, rurpy at yahoo.com wrote: > On 01/27/2013 02:04 AM, Ferrous Cranus wrote: >> [...] >> data = cur.fetchall() >> for row in data: >> print ( "" ) >> >> for item in row: >> print( '''''' % (item, item) ) >> [...] >> Okey, so far BUT i want the url linking to happen only for the URL column's >> value, and not for the hits column too. How do i apply the url link to the >> URL column's value only? > Ferrous, > > 'row' has two items (the url and the hit count) in it, right? > So print each separately rather than in a loop: > > data = cur.fetchall() > for row in data: > url = row[0] > hits = row[1] > print ( "" ) > print( ": % (url, hits) ) It is nice to see some constructive feedback to Ferrous from the python-list. This will hopefully help to get Ferrous on the right track. From nikos.gr33k at gmail.com Sun Jan 27 13:05:02 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Sun, 27 Jan 2013 10:05:02 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> Message-ID: ?? ???????, 27 ?????????? 2013 6:12:59 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > On 01/27/2013 02:04 AM, Ferrous Cranus wrote: > > >[...] > > > data = cur.fetchall() > > > for row in data: > > > print ( "" ) > > > > > > for item in row: > > > print( '''''' % (item, item) ) > > >[...] > > > Okey, so far BUT i want the url linking to happen only for the URL column's > > > value, and not for the hits column too. How do i apply the url link to the > > > URL column's value only? > > > > Ferrous, > > > > 'row' has two items (the url and the hit count) in it, right? > > So print each separately rather than in a loop: > > > > data = cur.fetchall() > > for row in data: > > url = row[0] > > hits = row[1] > > print ( "" ) > > print( ": % (url, hits) ) Yes that can work, but i want to ask you if its possible to do the same thing from within the loop as i have it coded it until now. Is there a way to seperate the values within the loop? From joel.goldstick at gmail.com Sun Jan 27 13:36:42 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 27 Jan 2013 13:36:42 -0500 Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 1:05 PM, ?????? ???????????? wrote: > ?? ???????, 27 ?????????? 2013 6:12:59 ?.?. UTC+2, ? ??????? > ru... at yahoo.com ??????: > > On 01/27/2013 02:04 AM, Ferrous Cranus wrote: > > > > >[...] > > > > > data = cur.fetchall() > > > > > for row in data: > > > > > print ( "" ) > > > > > > > > > > for item in row: > > > > > print( '''''' % (item, item) ) > > > > >[...] > > > > > Okey, so far BUT i want the url linking to happen only for the URL > column's > > > > > value, and not for the hits column too. How do i apply the url link to > the > > > > > URL column's value only? > > > > > > > > Ferrous, > > > > > > > > 'row' has two items (the url and the hit count) in it, right? > > > > So print each separately rather than in a loop: > > > > > > > > data = cur.fetchall() > > > > for row in data: > > > > url = row[0] > > > > hits = row[1] > > > > print ( "" ) > > > > print( ": % > (url, hits) ) > > Yes that can work, but i want to ask you if its possible to do the same > thing from within the loop as i have it coded it until now. > > Is there a way to seperate the values within the loop? > for row in data: print( ": " % (row[0], row[1]) ) > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Sun Jan 27 13:44:55 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Sun, 27 Jan 2013 10:44:55 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> Message-ID: <68ccd5e6-98b6-4a1d-b991-084e7b7fb459@googlegroups.com> ?? ???????, 27 ?????????? 2013 8:36:42 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Sun, Jan 27, 2013 at 1:05 PM, ?????? ???????????? wrote: > > ?? ???????, 27 ?????????? 2013 6:12:59 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > > > > > > On 01/27/2013 02:04 AM, Ferrous Cranus wrote: > > > > > > >[...] > > > > > > > ? ? ? ? ? ? data = cur.fetchall() > > > > > > > ? ? ? ? ? ? for row in data: > > > > > > > ? ? ? ? ? ? ? ? ? ? print ( "" ) > > > > > > > > > > > > > > ? ? ? ? ? ? ? ? ? ? for item in row: > > > > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? print( '''''' % (item, item) ) > > > > > > > >[...] > > > > > > > Okey, so far BUT i want the url linking to happen only for the URL column's > > > > > > > value, and not for the hits column too. How do i apply the url link to the > > > > > > > URL column's value only? > > > > > > > > > > > > Ferrous, > > > > > > > > > > > > 'row' has two items (the url and the hit count) in it, right? > > > > > > So print each separately rather than in a loop: > > > > > > > > > > > > ? ? data = cur.fetchall() > > > > > > ? ? for row in data: > > > > > > ? ? ? url = row[0] > > > > > > ? ? ? hits = row[1] > > > > > > ? ? ? ? print ( "" ) > > > > > > ? ? ? ? print( ": % (url, hits) ) > > > > Yes that can work, but i want to ask you if its possible to do the same thing from within the loop as i have it coded it until now. > > > > Is there a way to seperate the values within the loop? > > > > for row in data: > > ? ? print( ": " % (row[0], row[1]) ) This is not correct. the attribute is for url (row[0]) only, not for url and hits too. i want the following working code: ============= data = cur.fetchall() for row in data: url = row[0] hits = row[1] print ( "" ) print( "" % (url, url) ) print( "" % (hits) ) ============= inside the loop i posted initially, if its possible. From nikos.gr33k at gmail.com Sun Jan 27 13:44:55 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Sun, 27 Jan 2013 10:44:55 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> Message-ID: <68ccd5e6-98b6-4a1d-b991-084e7b7fb459@googlegroups.com> ?? ???????, 27 ?????????? 2013 8:36:42 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > On Sun, Jan 27, 2013 at 1:05 PM, ?????? ???????????? wrote: > > ?? ???????, 27 ?????????? 2013 6:12:59 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > > > > > > On 01/27/2013 02:04 AM, Ferrous Cranus wrote: > > > > > > >[...] > > > > > > > ? ? ? ? ? ? data = cur.fetchall() > > > > > > > ? ? ? ? ? ? for row in data: > > > > > > > ? ? ? ? ? ? ? ? ? ? print ( "" ) > > > > > > > > > > > > > > ? ? ? ? ? ? ? ? ? ? for item in row: > > > > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? print( '''''' % (item, item) ) > > > > > > > >[...] > > > > > > > Okey, so far BUT i want the url linking to happen only for the URL column's > > > > > > > value, and not for the hits column too. How do i apply the url link to the > > > > > > > URL column's value only? > > > > > > > > > > > > Ferrous, > > > > > > > > > > > > 'row' has two items (the url and the hit count) in it, right? > > > > > > So print each separately rather than in a loop: > > > > > > > > > > > > ? ? data = cur.fetchall() > > > > > > ? ? for row in data: > > > > > > ? ? ? url = row[0] > > > > > > ? ? ? hits = row[1] > > > > > > ? ? ? ? print ( "" ) > > > > > > ? ? ? ? print( ": % (url, hits) ) > > > > Yes that can work, but i want to ask you if its possible to do the same thing from within the loop as i have it coded it until now. > > > > Is there a way to seperate the values within the loop? > > > > for row in data: > > ? ? print( ": " % (row[0], row[1]) ) This is not correct. the attribute is for url (row[0]) only, not for url and hits too. i want the following working code: ============= data = cur.fetchall() for row in data: url = row[0] hits = row[1] print ( "" ) print( "" % (url, url) ) print( "" % (hits) ) ============= inside the loop i posted initially, if its possible. From rurpy at yahoo.com Sun Jan 27 14:12:16 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 27 Jan 2013 11:12:16 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> Message-ID: On 01/27/2013 11:44 AM, ?????? ???????????? wrote: > This is not correct. > the attribute is for url (row[0]) only, not for url and hits too. > > i want the following working code: > > ============= > data = cur.fetchall() > for row in data: > url = row[0] > hits = row[1] > print ( "" ) > print( "" % (url, url) ) > print( "" % (hits) ) > ============= > > inside the loop i posted initially, if its possible. The easiest way is to separate them when you read 'row' data = cur.fetchall() for row in data: for url,hits in row: print ( "" ) print( ": % (url, hits) ) Note that sql query you used guaranties that each row will contain exactly two items so there is no point in using a loop to go through each row item as you would if you did not know how many items it contained. But if you insist on going through them item by item in a loop, then you need to figure out which item is which inside the loop. One way is like: data = cur.fetchall() for row in data: print ( "" ) item_position = 0 for item in row: if item_position == 0: print( ":" % (item[0], item[0])) if item_position == 1: print( "" % item[1] ) item_position += 1 There are many variations of that. You can simplify the above a little by getting rid of the "item_position=" lines and replacing "for item in row:" with "for item_position, item = enumerate (item):" But I think you can see the very first code example above is way more simple. By the way, it would be a lot easier to read your posts if you would snip out the extra blank lines that Google Groups adds. There are some suggestions in http://wiki.python.org/moin/GoogleGroupsPython From nikos.gr33k at gmail.com Sun Jan 27 15:24:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Sun, 27 Jan 2013 12:24:50 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> Message-ID: <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> ?? ???????, 27 ?????????? 2013 9:12:16 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > Yes indeed, there is no need to use a loop since i know the exact number of items i'am expecting. Thanks you very much for clarifying this to me: One last thing i want to ask you: ======================================== try: cur.execute( '''SELECT host, userOS, browser, hits, lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE URL = %s) ORDER BY lastvisit DESC''', (htmlpage,) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) else: data = cur.fetchall() for host, useros, browser, hits, lastvisit in data: print ( "" ) for item in host, useros, browser, hits, lastvisit.strftime('%A %e %b, %H:%M').decode('cp1253').encode('utf8'): print ( "" % item ) sys.exit(0) ======================================= That would be also written as: for row in data: print ("tr>") for item in row: print( "blah blah blah" ) And that would make the code easier to read and more clear, but its that 'lastvisit' column's value than needs formating,hence it makes me use the above syntax. Is there any simpler way to write the above working code without the need to specify all of the columns' names into the loop? From msirenef at lightbird.net Sun Jan 27 15:50:33 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 27 Jan 2013 15:50:33 -0500 Subject: Formatting a column's value output In-Reply-To: <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> Message-ID: <51059319.5080301@lightbird.net> On 01/27/2013 03:24 PM, ?????? ???????????? wrote: > ?? ???????, 27 ?????????? 2013 9:12:16 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: >> > > Yes indeed, there is no need to use a loop since i know the exact number of items i'am expecting. Thanks you very much for clarifying this to me: > One last thing i want to ask you: > > ======================================== > try: > cur.execute( '''SELECT host, userOS, browser, hits, lastvisit FROM visitors > WHERE counterID = (SELECT ID FROM counters WHERE URL = %s) ORDER BY lastvisit DESC''', (htmlpage,) ) > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > else: > data = cur.fetchall() > > for host, useros, browser, hits, lastvisit in data: > print ( "" ) > > for item in host, useros, browser, hits, lastvisit.strftime('%A %e %b, %H:%M').decode('cp1253').encode('utf8'): > print ( "" % item ) > > sys.exit(0) > ======================================= > > That would be also written as: > > for row in data: > print ("tr>") > for item in row: > print( "blah blah blah" ) > > And that would make the code easier to read and more clear, but its that 'lastvisit' column's value than needs formating,hence it makes me use the above syntax. > > Is there any simpler way to write the above working code without the need to specify all of the columns' names into the loop? You can write: for row in data: print ("tr>") row = list(row) row[-1] = row[-1].strftime(...) for item in row: print( "blah blah blah" ) - mitya -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The existence of any evil anywhere at any time absolutely ruins a total optimism. George Santayana From rurpy at yahoo.com Sun Jan 27 17:27:12 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 27 Jan 2013 14:27:12 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> Message-ID: On 01/27/2013 01:50 PM, Mitya Sirenef wrote: > On 01/27/2013 03:24 PM, ?????? ???????????? wrote: >> ?? ???????, 27 ?????????? 2013 9:12:16 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > >> > > > > Yes indeed, there is no need to use a loop since i know the exact > number of items i'am expecting. Thanks you very much for clarifying this > to me: > > One last thing i want to ask you: > > > > ======================================== > > try: > > cur.execute( '''SELECT host, userOS, browser, hits, lastvisit FROM > visitors > > WHERE counterID = (SELECT ID FROM counters WHERE URL = %s) ORDER BY > lastvisit DESC''', (htmlpage,) ) > > except MySQLdb.Error, e: > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > else: > > data = cur.fetchall() > > > > for host, useros, browser, hits, lastvisit in data: > > print ( "" ) > > > > for item in host, useros, browser, hits, lastvisit.strftime('%A %e > %b, %H:%M').decode('cp1253').encode('utf8'): > > print ( "" % item ) > > > > sys.exit(0) > > ======================================= > > > > That would be also written as: > > > > for row in data: > > print ("tr>") > > for item in row: > > print( "blah blah blah" ) > > > > And that would make the code easier to read and more clear, but its > that 'lastvisit' column's value than needs formating,hence it makes me > use the above syntax. > > > > Is there any simpler way to write the above working code without the > need to specify all of the columns' names into the loop? > > > You can write: > > for row in data: > print ("tr>") > row = list(row) > row[-1] = row[-1].strftime(...) > for item in row: > print( "blah blah blah" ) Or alternatively, for row in data: print ("tr>") for item_num, item in enumerate (row): if item_num != len(row) - 1: print( "blah blah blah" ) else: print( item.strftime(...) ) Or, being a little clearer, LASTVISIT_POS = 4 for row in data: print ("tr>") for item_num, item in enumerate (row): if item_num != LASTVISIT_POS: print( "blah blah blah" ) else: print( item.strftime(...) ) From nikos.gr33k at gmail.com Mon Jan 28 04:47:03 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Mon, 28 Jan 2013 01:47:03 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> Message-ID: <687991f7-60a5-4066-85b0-01e265c78c53@googlegroups.com> ?? ???????, 28 ?????????? 2013 12:27:12 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > On 01/27/2013 01:50 PM, Mitya Sirenef wrote: > > > On 01/27/2013 03:24 PM, ?????? ???????????? wrote: > > >> ?? ???????, 27 ?????????? 2013 9:12:16 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > > > >> > > > > > > > > Yes indeed, there is no need to use a loop since i know the exact > > > number of items i'am expecting. Thanks you very much for clarifying this > > > to me: > > > > One last thing i want to ask you: > > > > > > > > ======================================== > > > > try: > > > > cur.execute( '''SELECT host, userOS, browser, hits, lastvisit FROM > > > visitors > > > > WHERE counterID = (SELECT ID FROM counters WHERE URL = %s) ORDER BY > > > lastvisit DESC''', (htmlpage,) ) > > > > except MySQLdb.Error, e: > > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > else: > > > > data = cur.fetchall() > > > > > > > > for host, useros, browser, hits, lastvisit in data: > > > > print ( "" ) > > > > > > > > for item in host, useros, browser, hits, lastvisit.strftime('%A %e > > > %b, %H:%M').decode('cp1253').encode('utf8'): > > > > print ( "" % item ) > > > > > > > > sys.exit(0) > > > > ======================================= > > > > > > > > That would be also written as: > > > > > > > > for row in data: > > > > print ("tr>") > > > > for item in row: > > > > print( "blah blah blah" ) > > > > > > > > And that would make the code easier to read and more clear, but its > > > that 'lastvisit' column's value than needs formating,hence it makes me > > > use the above syntax. > > > > > > > > Is there any simpler way to write the above working code without the > > > need to specify all of the columns' names into the loop? > > > > > > > > > You can write: > > > > > > for row in data: > > > print ("tr>") > > > row = list(row) > > > row[-1] = row[-1].strftime(...) > > > for item in row: > > > print( "blah blah blah" ) > > > > Or alternatively, > > > > for row in data: > > print ("tr>") > > for item_num, item in enumerate (row): > > if item_num != len(row) - 1: > > print( "blah blah blah" ) > > else: > > print( item.strftime(...) ) > > > > Or, being a little clearer, > > > > LASTVISIT_POS = 4 > > for row in data: > > print ("tr>") > > for item_num, item in enumerate (row): > > if item_num != LASTVISIT_POS: > > print( "blah blah blah" ) > > else: > > print( item.strftime(...) ) Thank you very much, your alternatives are great but i think i'll use Mity'as solution, its more easy to me. Thank you very much! From nikos.gr33k at gmail.com Mon Jan 28 04:44:43 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Mon, 28 Jan 2013 01:44:43 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> Message-ID: <1adfcf88-7bd8-4699-adbf-ac8eece357d0@googlegroups.com> ?? ???????, 27 ?????????? 2013 10:50:33 ?.?. UTC+2, ? ??????? Mitya Sirenef ??????: > On 01/27/2013 03:24 PM, ?????????????????? ???????????????????????????????????? wrote: > > > ?????? ?????????????????????, 27 ?????????????????????????????? 2013 9:12:16 ???.???. UTC+2, ??? ????????????????????? ru... at yahoo.com ??????????????????: > > >> > > > > > > Yes indeed, there is no need to use a loop since i know the exact > > number of items i'am expecting. Thanks you very much for clarifying this > > to me: > > > One last thing i want to ask you: > > > > > > ======================================== > > > try: > > > cur.execute( '''SELECT host, userOS, browser, hits, lastvisit FROM > > visitors > > > WHERE counterID = (SELECT ID FROM counters WHERE URL = %s) ORDER BY > > lastvisit DESC''', (htmlpage,) ) > > > except MySQLdb.Error, e: > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > else: > > > data = cur.fetchall() > > > > > > for host, useros, browser, hits, lastvisit in data: > > > print ( "" ) > > > > > > for item in host, useros, browser, hits, lastvisit.strftime('%A %e > > %b, %H:%M').decode('cp1253').encode('utf8'): > > > print ( "" % item ) > > > > > > sys.exit(0) > > > ======================================= > > > > > > That would be also written as: > > > > > > for row in data: > > > print ("tr>") > > > for item in row: > > > print( "blah blah blah" ) > > > > > > And that would make the code easier to read and more clear, but its > > that 'lastvisit' column's value than needs formating,hence it makes me > > use the above syntax. > > > > > > Is there any simpler way to write the above working code without the > > need to specify all of the columns' names into the loop? > > > > > > You can write: > > > > for row in data: > > print ("tr>") > > row = list(row) > > row[-1] = row[-1].strftime(...) > > for item in row: > > print( "blah blah blah" ) > > > > > > - mitya > > > > > > -- > > Lark's Tongue Guide to Python: http://lightbird.net/larks/ > > > > The existence of any evil anywhere at any time absolutely ruins a total > > optimism. George Santayana Thank you very much, your solution makes the code looks so much clearer! From nikos.gr33k at gmail.com Mon Jan 28 04:44:43 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?=) Date: Mon, 28 Jan 2013 01:44:43 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> Message-ID: <1adfcf88-7bd8-4699-adbf-ac8eece357d0@googlegroups.com> ?? ???????, 27 ?????????? 2013 10:50:33 ?.?. UTC+2, ? ??????? Mitya Sirenef ??????: > On 01/27/2013 03:24 PM, ?????????????????? ???????????????????????????????????? wrote: > > > ?????? ?????????????????????, 27 ?????????????????????????????? 2013 9:12:16 ???.???. UTC+2, ??? ????????????????????? ru... at yahoo.com ??????????????????: > > >> > > > > > > Yes indeed, there is no need to use a loop since i know the exact > > number of items i'am expecting. Thanks you very much for clarifying this > > to me: > > > One last thing i want to ask you: > > > > > > ======================================== > > > try: > > > cur.execute( '''SELECT host, userOS, browser, hits, lastvisit FROM > > visitors > > > WHERE counterID = (SELECT ID FROM counters WHERE URL = %s) ORDER BY > > lastvisit DESC''', (htmlpage,) ) > > > except MySQLdb.Error, e: > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > else: > > > data = cur.fetchall() > > > > > > for host, useros, browser, hits, lastvisit in data: > > > print ( "" ) > > > > > > for item in host, useros, browser, hits, lastvisit.strftime('%A %e > > %b, %H:%M').decode('cp1253').encode('utf8'): > > > print ( "" % item ) > > > > > > sys.exit(0) > > > ======================================= > > > > > > That would be also written as: > > > > > > for row in data: > > > print ("tr>") > > > for item in row: > > > print( "blah blah blah" ) > > > > > > And that would make the code easier to read and more clear, but its > > that 'lastvisit' column's value than needs formating,hence it makes me > > use the above syntax. > > > > > > Is there any simpler way to write the above working code without the > > need to specify all of the columns' names into the loop? > > > > > > You can write: > > > > for row in data: > > print ("tr>") > > row = list(row) > > row[-1] = row[-1].strftime(...) > > for item in row: > > print( "blah blah blah" ) > > > > > > - mitya > > > > > > -- > > Lark's Tongue Guide to Python: http://lightbird.net/larks/ > > > > The existence of any evil anywhere at any time absolutely ruins a total > > optimism. George Santayana Thank you very much, your solution makes the code looks so much clearer! From nikos.gr33k at gmail.com Sat Jan 26 16:07:49 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 26 Jan 2013 13:07:49 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: ?? ???????, 26 ?????????? 2013 8:04:12 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus wrote: > > > print ( "" % item ) > > > > > > > > In the aboce code wheb 'URL' is to be typed out be print i need it to be formatted as a link, so the viewer can click on it. > > > > > > Is this possible please? > > > > Easy, just make a tuple of item,item and have two %s markers: > > > > print( "" % (item, item) ) That code works, but it creates links for both the URL and hits columns! Only the URL must be linked not the hits column! From nikos.gr33k at gmail.com Sat Jan 26 16:07:49 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 26 Jan 2013 13:07:49 -0800 (PST) Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: ?? ???????, 26 ?????????? 2013 8:04:12 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus wrote: > > > print ( "" % item ) > > > > > > > > In the aboce code wheb 'URL' is to be typed out be print i need it to be formatted as a link, so the viewer can click on it. > > > > > > Is this possible please? > > > > Easy, just make a tuple of item,item and have two %s markers: > > > > print( "" % (item, item) ) That code works, but it creates links for both the URL and hits columns! Only the URL must be linked not the hits column! From rosuav at gmail.com Sat Jan 26 17:18:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 09:18:38 +1100 Subject: Formatting a column's value output In-Reply-To: References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 8:07 AM, Ferrous Cranus wrote: > That code works, but it creates links for both the URL and hits columns! > Only the URL must be linked not the hits column! 1) Trim your quotes. I can't be bothered doing your trimming for you, so I'm now under-quoting. 2) Quit using Google Groups, or manually fix its brain-dead double-spacing. 3) Look into Python's formatting options and see how to solve your own problem. You'll probably want to use .format() rather than %. 4) Look into HTML entity escaping and do not publish anything to the web until you understand why what you had before was dangerous. ChrisA From wuwei23 at gmail.com Sat Jan 26 18:29:54 2013 From: wuwei23 at gmail.com (alex23) Date: Sat, 26 Jan 2013 15:29:54 -0800 (PST) Subject: Formatting a column's value output References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> Message-ID: <03036f30-ec7a-4992-9494-4c3372a4e02e@ui9g2000pbc.googlegroups.com> On Jan 27, 8:18?am, Chris Angelico wrote: > 1) Trim your quotes. I can't be bothered doing your trimming for you, > so I'm now under-quoting. > > 2) Quit using Google Groups, or manually fix its brain-dead double-spacing. > > 3) Look into Python's formatting options and see how to solve your own > problem. You'll probably want to use .format() rather than %. > > 4) Look into HTML entity escaping and do not publish anything to the > web until you understand why what you had before was dangerous. 5) Please stop writing code for his _commercial web hosting service_ for free. Notice that his next question is to ask you to modify your solution to provide _exactly_ what he wants. He has no interest in learning Python. From rosuav at gmail.com Sat Jan 26 18:38:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 10:38:31 +1100 Subject: Formatting a column's value output In-Reply-To: <03036f30-ec7a-4992-9494-4c3372a4e02e@ui9g2000pbc.googlegroups.com> References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <03036f30-ec7a-4992-9494-4c3372a4e02e@ui9g2000pbc.googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 10:29 AM, alex23 wrote: > 5) Please stop writing code for his _commercial web hosting service_ > for free. You mean, stop asking us to write &c.? With that edit, yes, I agree. One of the difficulties on this list is that we don't have two-dimensional people. Even our worst trolls have some redeeming features. I can't just dismiss Ferrous out of hand... ChrisA From sajuptpm at gmail.com Sat Jan 26 14:12:39 2013 From: sajuptpm at gmail.com (sajuptpm) Date: Sat, 26 Jan 2013 11:12:39 -0800 (PST) Subject: python: HTTP connections through a proxy server requiring authentication Message-ID: <2b240090-4ae2-403b-9e82-61394d8a545f@googlegroups.com> Hi, I followed http://dabase.com/blog/Minimal_squid3_proxy_configuration/ to setup proxy server. I tested my proxy server with firefox with IP:127.0.0.1 and Port:3128 and it working (asking for proxy username and password). But, i could not make http connection through proxy server requiring authentication using following python code.. ########## Python code ########## import urllib2 proxy = urllib2.ProxyHandler({'http':'http://saju:123 at saju-Inspiron-N5010:3128'}) opener = urllib2.build_opener(proxy, urllib2.HTTPHandler) urllib2.install_opener(opener) conn = urllib2.urlopen('http://python.org') return_str = conn.read() print "===return_st====", return_str ==== ERROR ==== Traceback (most recent call last): File "my_proxy.py", line 6, in conn = urllib2.urlopen('http://python.org') File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 407, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 520, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 445, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required ########## Proxy Server Settings ########## sudo vim /etc/squid3/squid.conf ------------------------------- auth_param digest program /usr/lib/squid3/digest_pw_auth -c /etc/squid3/passwords auth_param digest realm saju-Inspiron-N5010 acl authenticated proxy_auth REQUIRED http_access allow authenticated http_port 3128 Setting up user -------------- htdigest -c /etc/squid3/passwords saju-Inspiron-N5010 saju ============================== From sajuptpm at gmail.com Sat Jan 26 14:31:15 2013 From: sajuptpm at gmail.com (sajuptpm) Date: Sat, 26 Jan 2013 11:31:15 -0800 (PST) Subject: python: HTTP connections through a proxy server requiring authentication In-Reply-To: <2b240090-4ae2-403b-9e82-61394d8a545f@googlegroups.com> References: <2b240090-4ae2-403b-9e82-61394d8a545f@googlegroups.com> Message-ID: <1903bc16-3056-4177-bea1-7996e6fbfeb5@googlegroups.com> Hi, /etc/squid3/squid.conf ----------------------------------- saju at saju-Inspiron-N5010:~$ cat squid.conf | grep ^[^#] auth_param digest program /usr/lib/squid3/digest_pw_auth -c /etc/squid3/passwords auth_param digest realm saju-Inspiron-N5010 acl manager proto cache_object acl localhost src 127.0.0.1/32 ::1 acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1 acl authenticated proxy_auth REQUIRED acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT http_access allow manager localhost http_access deny manager http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow authenticated http_access deny all http_port 3128 coredump_dir /var/spool/squid3 refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern (Release|Packages(.gz)*)$ 0 20% 2880 refresh_pattern . 0 20% 4320 saju at saju-Inspiron-N5010:~$ Thanks, From barry at barrys-emacs.org Mon Jan 28 18:31:29 2013 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 28 Jan 2013 23:31:29 +0000 Subject: python: HTTP connections through a proxy server requiring authentication In-Reply-To: <1903bc16-3056-4177-bea1-7996e6fbfeb5@googlegroups.com> References: <2b240090-4ae2-403b-9e82-61394d8a545f@googlegroups.com> <1903bc16-3056-4177-bea1-7996e6fbfeb5@googlegroups.com> Message-ID: <4ED36D7D-7803-444A-91E4-E194EAC8159C@barrys-emacs.org> The shipped python library code does not work. See http://bugs.python.org/issue7291 for patches. Barry From sajuptpm at gmail.com Tue Jan 29 01:50:44 2013 From: sajuptpm at gmail.com (Saju M) Date: Tue, 29 Jan 2013 12:20:44 +0530 Subject: python: HTTP connections through a proxy server requiring authentication In-Reply-To: <4ED36D7D-7803-444A-91E4-E194EAC8159C@barrys-emacs.org> References: <2b240090-4ae2-403b-9e82-61394d8a545f@googlegroups.com> <1903bc16-3056-4177-bea1-7996e6fbfeb5@googlegroups.com> <4ED36D7D-7803-444A-91E4-E194EAC8159C@barrys-emacs.org> Message-ID: Hi , Thanks barry, I solved that issue. I reconfigured squid3 with ncsa_auth, now its working same python code. Earlier I used digest_pw_auth. Actually I am trying to fix an issue related to python boto API. Please check this post https://groups.google.com/forum/#!topic/boto-users/1qk6d7v2HpQ Regards Saju Madhavan +91 09535134654 On Tue, Jan 29, 2013 at 5:01 AM, Barry Scott wrote: > The shipped python library code does not work. > > See http://bugs.python.org/issue7291 for patches. > > Barry > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Jan 26 16:42:56 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 27 Jan 2013 08:42:56 +1100 Subject: word_set [snip enormous subject line] References: <9a980d5f-f8b7-4782-b4d8-70ae9818c1c2@ro7g2000pbb.googlegroups.com> Message-ID: <51044de1$0$29998$c3e8da3$5496439d@news.astraweb.com> Martin Musatov wrote: > word_set = set() [snip SIXTEEN THOUSAND words copied from a spelling dictionary] If you have a question, please: - ASK THE QUESTION, we cannot read your mind; - don't send us thousands of lines taken straight out of a dictionary, just use the SMALLEST amount of sample data needed to demonstrate the problem; three or four words is enough, no need to waste everyone's time and bandwidth with sixteen thousand words; - choose a MEANINGFUL subject line, there is no need to paste the entire body of your code in the subject line. Thank you. -- Steven From twiztidtrees at gmail.com Sat Jan 26 17:26:41 2013 From: twiztidtrees at gmail.com (twiztidtrees at gmail.com) Date: Sat, 26 Jan 2013 14:26:41 -0800 (PST) Subject: looking for advice python Message-ID: <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> Hey I'm new to programming and I have been working on calculating miles per gallon. iv posted below what I have and constructive criticism would be wonderful. Thanks #This is a program used to calculate miles per gallon #variable used to gather miles driven string_miles = input('How many miles did you drive?') #variable used to gather the amount of gallons used string_gas = input('How many gallons of gas did you use?') #used to convert the miles input miles = int(string_miles) #used to convert the gas input gas = int(string_gas) #used to calculate mpg through division mpg = miles/gas print(float(string_miles)) print(float(string_gas)) print('Your miles per gallon is', format(mpg,'.2f')) From rosuav at gmail.com Sat Jan 26 17:48:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 09:48:01 +1100 Subject: looking for advice python In-Reply-To: <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> References: <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> Message-ID: On Sun, Jan 27, 2013 at 9:26 AM, wrote: > miles = int(string_miles) > gas = int(string_gas) > > #used to calculate mpg through division > mpg = miles/gas > > print(float(string_miles)) > print(float(string_gas)) > print('Your miles per gallon is', format(mpg,'.2f')) Welcome aboard! You turn your inputs into integers, then display them as floats... from the original strings. (Though I guess this is probably debugging code?) I would advise against doing this; at very least, it's confusing. I would recommend simply using floats everywhere, and thus allowing non-integer inputs: How many miles did you drive?60.9 How many gallons of gas did you use?11.9 Traceback (most recent call last): File "123.py", line 11, in miles = int(string_miles) ValueError: invalid literal for int() with base 10: '60.9' Small additional point: It's common to put a space at the end of your prompt, to avoid the "crammed" look of "drive?60.9". Are there any particular areas that you'd like comments on? ChrisA From davea at davea.name Sat Jan 26 18:00:10 2013 From: davea at davea.name (Dave Angel) Date: Sat, 26 Jan 2013 18:00:10 -0500 Subject: looking for advice python In-Reply-To: <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> References: <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> Message-ID: <51045FFA.4000108@davea.name> On 01/26/2013 05:26 PM, twiztidtrees at gmail.com wrote: > Hey I'm new to programming and I have been working on calculating miles per gallon. iv posted below what I have and constructive criticism would be wonderful. Thanks > A good post for the python-tutor mailing list. If you want help with a program, the first thing you should specify is what version of Python you're using. And usually which OS you're running, but in this case it doesn't matter much. I don't see either a shebang line nor a coding line. > #This is a program used to calculate miles per gallon > > > #variable used to gather miles driven > string_miles = input('How many miles did you drive?') > > #variable used to gather the amount of gallons used > string_gas = input('How many gallons of gas did you use?') > Why do you bother to have separate variables for the string versions? Why not just miles = int( input("xxxx")) ? For that matter, what if the user enters a decimal value for the gallons? Perhaps you'd better use gas = float( input("yyy") ) > #used to convert the miles input > miles = int(string_miles) > > #used to convert the gas input > gas = int(string_gas) > > #used to calculate mpg through division > mpg = miles/gas This isn't portable to Python 2.x. In 2.x, it would truncate the result. > > print(float(string_miles)) > print(float(string_gas)) > print('Your miles per gallon is', format(mpg,'.2f')) > What if the user enters something that isn't a valid number, either int or float? Where's the try/catch to handle it? Is this a class assignment? If not, why would you have a comment and a blank line between every line of useful code? -- DaveA From twiztidtrees at gmail.com Sun Jan 27 13:57:47 2013 From: twiztidtrees at gmail.com (twiztidtrees at gmail.com) Date: Sun, 27 Jan 2013 10:57:47 -0800 (PST) Subject: looking for advice python In-Reply-To: References: <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> Message-ID: <6cc43b88-daf0-40fa-ae29-8fda465e08ce@googlegroups.com> I am in a class and was just looking for different advice. This is the first time iv ever tried to do this. That's all that iv taken from two chapters and wondering how bad I did. I also like to learn. Thanks for everyones input From twiztidtrees at gmail.com Mon Jan 28 16:59:50 2013 From: twiztidtrees at gmail.com (twiztidtrees at gmail.com) Date: Mon, 28 Jan 2013 13:59:50 -0800 (PST) Subject: looking for advice python In-Reply-To: <6cc43b88-daf0-40fa-ae29-8fda465e08ce@googlegroups.com> References: <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> <6cc43b88-daf0-40fa-ae29-8fda465e08ce@googlegroups.com> Message-ID: <317d381c-25ac-47c8-a421-7b6d501c986a@googlegroups.com> On Sunday, January 27, 2013 1:57:47 PM UTC-5, twizti... at gmail.com wrote: > I am in a class and was just looking for different advice. This is the first time iv ever tried to do this. That's all that iv taken from two chapters and wondering how bad I did. I also like to learn. Thanks for everyones input This is what I have now thanks for the advice. It did seem a lot easier this way, but any criticism would be nice thanks. windows 7 and python 3.3.0 while True: try: miles = float(input("How many miles did you drive?")) break except ValueError: print("That is not a valid number. Please try again.") while True: try: gas = float(input("How many gallons of gas did you use?")) break except ValueError: print("That is not a valid number. Please try again.") mpg = miles/gas print('Your miles per gallons is', format(mpg,'.2f')) From skip at pobox.com Sat Jan 26 19:15:05 2013 From: skip at pobox.com (Skip Montanaro) Date: Sat, 26 Jan 2013 18:15:05 -0600 Subject: Ctypes can't find libc on Solaris Message-ID: I'm trying to build PyPy on a Solaris 10 system (not supported by the PyPy gang). After worming around distutils' inability to use environment variables to add command line flags to gcc, I'm stuck with an error trying to locate libc: [translation:ERROR] Error: [translation:ERROR] Traceback (most recent call last): [translation:ERROR] File "translate.py", line 269, in main [translation:ERROR] default_goal='compile') [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/translator/driver.py", line 790, in from_targetspec [translation:ERROR] spec = target(driver, args) [translation:ERROR] File "targetpypystandalone.py", line 152, in target [translation:ERROR] enable_allworkingmodules(config) [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/pypyoption.py", line 419, in enable_allworkingmodules [translation:ERROR] config.objspace.usemodules.suggest(**dict.fromkeys(modules, True)) [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 118, in suggest [translation:ERROR] self.suggestoption(name, value) [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 122, in suggestoption [translation:ERROR] self.setoption(name, value, "suggested") [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 113, in setoption [translation:ERROR] child.setoption(self, value, who) [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 311, in setoption [translation:ERROR] self._validator(toplevel) [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/pypyoption.py", line 116, in validator [translation:ERROR] __import__(name) [translation:ERROR] File "/var/tmp/pypy-pypy-07e08e9c885c/pypy/rlib/clibffi.py", line 305, in [translation:ERROR] assert libc_name is not None, "Cannot find C library, ctypes.util.find_library('c') returned None" [translation:ERROR] AssertionError: Cannot find C library, ctypes.util.find_library('c') returned None [translation] start debugger... Digging into ctypes/util.py, it became apparent that it can't find libc on Solaris. If you run ctypes/util.py as a main program, it spits out some library info. On Linux: % python Python 2.7.2 (default, Oct 16 2012, 16:54:10) [GCC 4.4.6 [TWW]] on linux3 Type "help", "copyright", "credits" or "license" for more information. >>> % python /opt/TWWfsw/python27/lib/python2.7/ctypes/util.py libm.so.6 libc.so.6 libbz2.so.1 libcrypt.so.1 On my Mac: % python ~/src/python/release27-maint/Lib/ctypes/util.py /usr/lib/libm.dylib /usr/lib/libc.dylib /usr/lib/libbz2.dylib On Solaris: % python /opt/TWWfsw/python27/lib/python2.7/ctypes/util.py None None None None If I can't locate libc (and perhaps some other libraries), I'm not going to get any further. Has anyone encountered this problem and figured out a workaround? Thanks, Skip Montanaro From skip at pobox.com Sat Jan 26 19:25:14 2013 From: skip at pobox.com (Skip Montanaro) Date: Sat, 26 Jan 2013 18:25:14 -0600 Subject: Ctypes can't find libc on Solaris In-Reply-To: References: Message-ID: > .... After worming around distutils' inability to use > environment variables to add command line flags to gcc, I'm stuck with > an error trying to locate libc: ... Should have poked around bugs.python.org first. This was reported, with a patch that works for me: http://bugs.python.org/issue5289 Sorry for the noise... S From roy at panix.com Sat Jan 26 20:47:01 2013 From: roy at panix.com (Roy Smith) Date: Sat, 26 Jan 2013 20:47:01 -0500 Subject: Comparing offset-aware and offset-naive datetimes? Message-ID: I have two datetimes. One is offset-naive. The other is offset-aware, but I happen to know its offset is 0 (i.e. GMT). How can I compare these? May the flies of a thousand Norwegian Blue parrots infest the armpits of whoever invented timezones. From vito.detullio at gmail.com Sat Jan 26 23:59:02 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sun, 27 Jan 2013 05:59:02 +0100 Subject: Comparing offset-aware and offset-naive datetimes? References: Message-ID: Roy Smith wrote: > I have two datetimes. One is offset-naive. The other is offset-aware, > but I happen to know its offset is 0 (i.e. GMT). How can I compare > these? http://pytz.sourceforge.net/#localized-times-and-date-arithmetic -- ZeD From ben+python at benfinney.id.au Sun Jan 27 00:12:36 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 27 Jan 2013 16:12:36 +1100 Subject: Comparing offset-aware and offset-naive datetimes? References: Message-ID: <7w38xnqke3.fsf@benfinney.id.au> Roy Smith writes: > I have two datetimes. One is offset-naive. The other is offset-aware, > but I happen to know its offset is 0 (i.e. GMT). Do you know the timezone of the offset-naive value? Or is the above mixed up, and you mean ?one is offset-aware; the other is offset-naive, but I happen to know its offset is UTC+0?? > How can I compare these? Assuming you have a datetime value which is timezone-naive, and you have no way of getting its timezone, and are unwilling to guess, you can't sensibly compare that value to a datetime in a specific timezone:: >>> import datetime >>> import pytz >>> timestamp_a = datetime.datetime(2012, 7, 1, 3, 45, 0) >>> timestamp_b = datetime.datetime( ... 2012, 8, 1, 20, 15, 0, tzinfo=pytz.UTC) >>> timestamp_a.tzinfo is None True >>> timestamp_b.tzinfo >>> timestamp_a == timestamp_b Traceback (most recent call last): File "", line 1, in TypeError: can't compare offset-naive and offset-aware datetimes So I'll assume that my interpretation about the mix-up is true, and that you actually have a situation like the following:: >>> import datetime >>> import pytz >>> timestamp_a = datetime.datetime(2012, 7, 1, 3, 45, 0) >>> timezone_for_a = pytz.UTC >>> timestamp_b = datetime.datetime( ... 2012, 8, 1, 20, 15, 0, tzinfo=pytz.timezone("Asia/Gaza")) >>> timestamp_a.tzinfo is None True >>> timestamp_b.tzinfo In which case, you can create a new timezone-aware value using the timezone-naive value and the timezone you've decided to apply:: >>> timestamp_c = timestamp_a.replace(tzinfo=timezone_for_a) >>> timestamp_c.tzinfo >>> timestamp_c == timestamp_b False >>> timestamp_c > timestamp_b False >>> timestamp_c < timestamp_b True > May the flies of a thousand Norwegian Blue parrots infest the armpits of > whoever invented timezones. Heh. I'm fine with timezones; they are a good-enough solution to allow our puny brains to speak about points in time in a reality that refuses to accommodate our prejudice that the time of day is the same everywhere on the globe. What I'm not fine with is politicians who think it's a fun game to fiddle with the specific timezone definitions with little advance notice and leave we programmers to clean up the mess they keep making. Those people are sorely in need of a nasal infestation of parrot fleas. -- \ ?For every complex problem, there is a solution that is simple, | `\ neat, and wrong.? ?Henry L. Mencken | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Jan 27 00:25:13 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 27 Jan 2013 16:25:13 +1100 Subject: The utter mess of current timezone definitions (was: Comparing offset-aware and offset-naive datetimes?) References: Message-ID: <7wy5ffp58m.fsf@benfinney.id.au> Roy Smith writes: > but I happen to know its offset is 0 (i.e. GMT). As further fuel for your hatred: GMT is not the same thing as UTC+0, and never has been. (See the definitions of those two separate timezones for more; Wikipedia's articles are probably a good start.) > May the flies of a thousand Norwegian Blue parrots infest the armpits of > whoever invented timezones. Further support my position that the inventor of timezones is not to blame for the utter mess in their current implementation, if you are interested, can be found in the commentary within the Olson timezone database itself. Here is a fun article giving a ?literary appreciation? of the database . -- \ ?What we usually pray to God is not that His will be done, but | `\ that He approve ours.? ?Helga Bergold Gross | _o__) | Ben Finney From rosuav at gmail.com Sun Jan 27 00:32:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Jan 2013 16:32:37 +1100 Subject: The utter mess of current timezone definitions (was: Comparing offset-aware and offset-naive datetimes?) In-Reply-To: <7wy5ffp58m.fsf@benfinney.id.au> References: <7wy5ffp58m.fsf@benfinney.id.au> Message-ID: On Sun, Jan 27, 2013 at 4:25 PM, Ben Finney wrote: >> but I happen to know its offset is 0 (i.e. GMT). > > As further fuel for your hatred: GMT is not the same thing as UTC+0, and > never has been. (See the definitions of those two separate timezones for > more; Wikipedia's articles are probably a good start.) For most people's purposes, GMT and UTC are equivalent. I tell people that my D&D sessions are Sundays from 2:00 UTC to roughly 6:00-7:00 UTC, and if they treat that as GMT, they're not going to miss the session. It's a lot better than a mess of "local time" with DST. Timezones aren't a problem. Daylight/Summer time (or Ireland's alternative, Winter time) is. ChrisA From roy at panix.com Sun Jan 27 09:37:56 2013 From: roy at panix.com (Roy Smith) Date: Sun, 27 Jan 2013 09:37:56 -0500 Subject: The utter mess of current timezone definitions (was: Comparing offset-aware and offset-naive datetimes?) References: Message-ID: In article , Ben Finney wrote: > Roy Smith writes: > > > but I happen to know its offset is 0 (i.e. GMT). > > As further fuel for your hatred: GMT is not the same thing as UTC+0, and > never has been. (See the definitions of those two separate timezones for > more; Wikipedia's articles are probably a good start.) Yes, I am aware of the difference between GMT and UTC (and UT0, UT1, etc). None of which really matters for my purpose. In this case, it just so happens that the original string is: Sat, 26 Jan 2013 20:10:34 GMT so if anybody is conflating GMT and UTC, it's the dateutil parser :-) From roy at panix.com Sun Jan 27 10:17:59 2013 From: roy at panix.com (Roy Smith) Date: Sun, 27 Jan 2013 10:17:59 -0500 Subject: Comparing offset-aware and offset-naive datetimes? References: Message-ID: In article , Ben Finney wrote: > Roy Smith writes: > > > I have two datetimes. One is offset-naive. The other is offset-aware, > > but I happen to know its offset is 0 (i.e. GMT). > > Do you know the timezone of the offset-naive value? > > Or is the above mixed up, and you mean ???one is offset-aware; the other > is offset-naive, but I happen to know its offset is UTC+0???? Well, actually, what I wrote was correct, but incomplete. The naive value came from a unix timestamp, so I know it is UTC. The aware value came from dateutil's parsing of a string that looks like: Sat, 26 Jan 2013 20:10:34 GMT so I know that one's UTC too :-) Unfortunately, the boto documentation describes it only as "The string timestamp representing the last time this object was modified in S3" without specifying the exact format. I'm not sure if it's showing up in GMT because my server happens to be running on GMT, or if it always does, so I'd rather let dateutil figure it out for me. > In which case, you can create a new timezone-aware value using the > timezone-naive value and the timezone you've decided to apply:: > > >>> timestamp_c = timestamp_a.replace(tzinfo=timezone_for_a) That's what I ended up with, thanks: s3_time = dateutil.parser.parse(s3_key.last_modified) info = os.stat(file) file_time = datetime.utcfromtimestamp(info.st_mtime) utc = dateutil.tz.tzutc() file_time = file_time.replace(tzinfo=utc) if s3_time < file_time: > What I'm not fine with is politicians who think it's a fun game to > fiddle with the specific timezone definitions with little advance notice > and leave we programmers to clean up the mess they keep making. Those > people are sorely in need of a nasal infestation of parrot fleas. Yes, indeed. I've been around long enough to remember when calendar code had the "Nixon flag" and the "Ford flag", named for the first two yahoos who started playing timekeeper for a day. That was before the Olson database existed. From george.15 at talktalk.net Sun Jan 27 11:29:45 2013 From: george.15 at talktalk.net (george.15 at talktalk.net) Date: Sun, 27 Jan 2013 08:29:45 -0800 (PST) Subject: Algorithm. Tony Gaddis book 2 Starting python3 Message-ID: Hi Question 3 Chp2 Page 76 Adds2 to a and assigns the result to b. I have several attemtps,would like to check my answer.help please At 80 i need all the help i can find. Thanks George Smart From joel.goldstick at gmail.com Sun Jan 27 12:24:53 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 27 Jan 2013 12:24:53 -0500 Subject: Algorithm. Tony Gaddis book 2 Starting python3 In-Reply-To: References: Message-ID: On Sun, Jan 27, 2013 at 11:29 AM, wrote: > Hi > Question 3 Chp2 Page 76 > Adds2 to a and assigns the result to b. > I have several attemtps,would like to check my answer.help please > At 80 i need all the help i can find. > Thanks George Smart > -- > http://mail.python.org/mailman/listinfo/python-list > Your question is not clear. Neither is your subject line. It seems that maybe you are using a book written by Tony Gaddis. I googled that and didn't come up with anything. Anyway, I don't have that book. You will get an answer to your question if you ask it more clearly -- perhaps quote from the book. Also, paste into your question the code you have tried and the results you have gotten. -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Sun Jan 27 12:46:30 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 27 Jan 2013 10:46:30 -0700 Subject: Algorithm. Tony Gaddis book 2 Starting python3 In-Reply-To: References: Message-ID: <510567F6.5020304@gmail.com> On 01/27/2013 09:29 AM, george.15 at talktalk.net wrote: > Hi > Question 3 Chp2 Page 76 > Adds2 to a and assigns the result to b. > I have several attemtps,would like to check my answer.help please > At 80 i need all the help i can find. > Thanks George Smart Awesome that you are learning Python! Indeed it is for all ages! What does the question say, exactly (maybe quote it)? And definitely post your answer to the question as well. It's better for us to work with what you have already. Michael From gheskett at wdtv.com Sun Jan 27 13:07:25 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 27 Jan 2013 13:07:25 -0500 Subject: Algorithm. Tony Gaddis book 2 Starting python3 In-Reply-To: References: Message-ID: <201301271307.25977.gheskett@wdtv.com> On Sunday 27 January 2013 13:05:27 george.15 at talktalk.net did opine: Message additions Copyright Sunday 27 January 2013 by Gene Heskett > Hi > Question 3 Chp2 Page 76 > Adds2 to a and assigns the result to b. > I have several attemtps,would like to check my answer.help please > At 80 i need all the help i can find. > Thanks George Smart Darn, I've just been dethroned from my resident oldest fart on this list throne, I'm only 78. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: is up! My views Thyme's Law: Everything goes wrong at once. I was taught to respect my elders, but its getting harder and harder to find any... From shi at somewhere.be Sun Jan 27 14:25:46 2013 From: shi at somewhere.be (shi) Date: Sun, 27 Jan 2013 20:25:46 +0100 Subject: Algorithm. Tony Gaddis book 2 Starting python3 References: Message-ID: Hello George, I found the book you're referring to via google (searching for: tony gaddis starting out with python). The question is this: 3. Write assignment statements that perform the following operations with the variables a,b and c. a. Adds 2 to a and assigns the result to b b. Multiplies b times 4 and assigns the result to a c. Divides a by 3.14 and assigns the result to b d. Subtracts 8 from and assigns the result to a The typical way this list helps in homework assignments is for the student to post his solution first, and then let someone explain if/why something is wrong, and how to go about the right solution. I think you will have a lot of fun learning python. It's very rewarding. Best regards, Stefaan. From shi at somewhere.be Sun Jan 27 14:27:41 2013 From: shi at somewhere.be (shi) Date: Sun, 27 Jan 2013 20:27:41 +0100 Subject: Algorithm. Tony Gaddis book 2 Starting python3 References: Message-ID: > d. Subtracts 8 from and assigns the result to a this should read: "Subtracts 8 from b and assigns the result to a" Funny how none of the assignments involve a variable c, despite the question :) From leonix.power at gmail.com Sun Jan 27 17:59:20 2013 From: leonix.power at gmail.com (leonix.power at gmail.com) Date: Sun, 27 Jan 2013 14:59:20 -0800 (PST) Subject: simple tkinter battery monitor Message-ID: <1ecfaec4-7f98-4647-b750-52b86103cf0a@googlegroups.com> I tried to write a simple battery monitor for laptops which shows normally just the battery percentage, and when is clicked some more info. If I click just one time it works, but if I click a second time, the additional info Label seems to be empty (but it holds the dimension of the StringVar content, even if it isn't displayed) Where am I wrong? --------------------------------------------------- #!/usr/bin/python3.2 from re import findall, search from threading import Thread from time import sleep from subprocess import Popen, call, PIPE, STDOUT from tkinter import * class battery_monitor: def __init__(self): root=Tk() # root.geometry("-0+0") root.overrideredirect(True) root.wm_attributes("-topmost", 1) self.battery_string=StringVar() self.battery_percent=StringVar() self.battery_label=Label(root, extvariable=self.battery_string, font=("fixed", 9)) self.battery_icon=Label(root, textvariable=self.battery_percent, font=("fixed", 9), width=3) self.battery_icon.grid() t=Thread(target=self.update_battery_level_loop) t.start() root.bind("", self.display_details) self.root=root root.mainloop() # displays a message about details of battery status # i.e. "on-line" or "charging, 20 min left" and so on def display_details(self, event): self.battery_icon.grid_remove() self.battery_label.grid() self.root.update_idletasks() sleep(1) self.battery_label.grid_remove() self.battery_icon.grid() self.root.update_idletasks() # dummy function used just to test the GUI def read_battery_level(self): self.level=100 return "battery is full" # threaded function, should constantly update the battery level def update_battery_level_loop(self): self.read_battery_level() while True: self.battery_percent.set(self.level) self.battery_string.set(self.read_battery_level()) sleep(5) ############################################## # # main battery_monitor() From d at davea.name Sun Jan 27 18:21:32 2013 From: d at davea.name (Dave Angel) Date: Sun, 27 Jan 2013 18:21:32 -0500 Subject: simple tkinter battery monitor In-Reply-To: <1ecfaec4-7f98-4647-b750-52b86103cf0a@googlegroups.com> References: <1ecfaec4-7f98-4647-b750-52b86103cf0a@googlegroups.com> Message-ID: <5105B67C.7000502@davea.name> On 01/27/2013 05:59 PM, leonix.power at gmail.com wrote: > I tried to write a simple battery monitor for laptops which shows normally just the battery percentage, and when is clicked some more info. > If I click just one time it works, but if I click a second time, the additional info Label seems to be empty (but it holds the dimension of the StringVar content, even if it isn't displayed) > Where am I wrong? See inline comment. > --------------------------------------------------- > #!/usr/bin/python3.2 > > from re import findall, search > from threading import Thread > from time import sleep > from subprocess import Popen, call, PIPE, STDOUT > from tkinter import * > > > > class battery_monitor: > > def __init__(self): > root=Tk() > # root.geometry("-0+0") > root.overrideredirect(True) > root.wm_attributes("-topmost", 1) > self.battery_string=StringVar() > self.battery_percent=StringVar() > self.battery_label=Label(root, extvariable=self.battery_string, font=("fixed", 9)) I don't know tkinter very well, and I don't have 3.2, but the keyword seems to be wrong. Don't you want textvariable= ?? > self.battery_icon=Label(root, textvariable=self.battery_percent, font=("fixed", 9), width=3) > self.battery_icon.grid() > t=Thread(target=self.update_battery_level_loop) > t.start() > root.bind("", self.display_details) > self.root=root > root.mainloop() > > # displays a message about details of battery status > # i.e. "on-line" or "charging, 20 min left" and so on > def display_details(self, event): > self.battery_icon.grid_remove() > self.battery_label.grid() > self.root.update_idletasks() > sleep(1) Never use sleep() inside a gui's main thread. There are other ways to delay the UI without locking it up. > self.battery_label.grid_remove() > self.battery_icon.grid() > self.root.update_idletasks() > > # dummy function used just to test the GUI > def read_battery_level(self): > self.level=100 > return "battery is full" > > # threaded function, should constantly update the battery level > def update_battery_level_loop(self): > self.read_battery_level() > while True: > self.battery_percent.set(self.level) > self.battery_string.set(self.read_battery_level()) > sleep(5) This sleep() is okay. > > > > > > ############################################## > # > # main > > battery_monitor() > -- DaveA From rantingrickjohnson at gmail.com Sun Jan 27 19:56:32 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 27 Jan 2013 16:56:32 -0800 (PST) Subject: simple tkinter battery monitor In-Reply-To: <1ecfaec4-7f98-4647-b750-52b86103cf0a@googlegroups.com> References: <1ecfaec4-7f98-4647-b750-52b86103cf0a@googlegroups.com> Message-ID: On Sunday, January 27, 2013 4:59:20 PM UTC-6, leonix... at gmail.com wrote: > I tried to write a simple battery monitor for laptops > which shows normally just the battery percentage, and when > is clicked some more info. > > If I click just one time it works, but if I click a second > time, the additional info Label seems to be empty (but it > holds the dimension of the StringVar content, even if it > isn't displayed) > > Where am I wrong? Before i discover your code logic error, i want to expose style errors. > --------------------------------------------------- > #!/usr/bin/python3.2 > > from re import findall, search > from threading import Thread > from time import sleep > from subprocess import Popen, call, PIPE, STDOUT > from tkinter import * I am wondering why you would "selectively" import from the re module, which is a quite normal sized module, but then do the global import from tkinter, of which who's namespace is terribly polluted due to lack of packaging. > class battery_monitor: Bad naming convention here! ALL class identifiers must (at the very least) /start/ with a capital letter. My strong opinion is to cap EVERY word. So for example: OptionMenu NOT Optionmenu ComboBox NOT Combobox etc... Using "lowercase_with_underscores" should be reserved for interface methods and global functions. > def __init__(self): > root=Tk() > # root.geometry("-0+0") > root.overrideredirect(True) > root.wm_attributes("-topmost", 1) I just hate when people use 1 and 0 for True and False. I know Python allows such non-sense, but i just hate it because it can cause subtle bugs -- and most logical people agree with me. > self.battery_string=StringVar() > self.battery_percent=StringVar() Two issues here. First you use a function/interface style to define a variable. Then you go and add insult to injury by using an ambiguous name. You should have used something like: "batteryStringVar" and "batteryPercentVar". > self.battery_label=Label(root, extvariable=self.battery_string, font=("fixed", 9)) > self.battery_icon=Label(root, textvariable=self.battery_percent, font=("fixed", 9), width=3) > self.battery_icon.grid() > t=Thread(target=self.update_battery_level_loop) Don't assign variables without leaving buffer spaces around the equals sign. Only omit the spaces when passing arguments to a class, method, or function. > t.start() > root.bind("", self.display_details) > self.root=root > root.mainloop() > > # displays a message about details of battery status > # i.e. "on-line" or "charging, 20 min left" and so on Oh gawd this is a major pet peeve of mine!!!! Always place a comment at the same indention level of the function or class that it references. AND NEVER, EVER, place a comment OUTSIDE of a function, method, or class like you have done here. > def display_details(self, event): > self.battery_icon.grid_remove() > self.battery_label.grid() > self.root.update_idletasks() > sleep(1) You may want to look into the Universal Tkinter widget method: "w.after(ms, func)". > self.battery_label.grid_remove() > self.battery_icon.grid() > self.root.update_idletasks() > > # dummy function used just to test the GUI > def read_battery_level(self): > self.level=100 > return "battery is full" > > # threaded function, should constantly update the battery level > def update_battery_level_loop(self): > self.read_battery_level() > while True: > self.battery_percent.set(self.level) > self.battery_string.set(self.read_battery_level()) > sleep(5) Finally, i don't understand why you are using such a deep indention level. Unknown Source said: "Four spaces thou shalt indent, and the number of thou indention shall be four." Only after you clean up these style abominations by submitting a new example of your code will i offer any more help. Thanks. From leonix.power at gmail.com Tue Jan 29 22:02:56 2013 From: leonix.power at gmail.com (leonix.power at gmail.com) Date: Tue, 29 Jan 2013 19:02:56 -0800 (PST) Subject: simple tkinter battery monitor In-Reply-To: <1ecfaec4-7f98-4647-b750-52b86103cf0a@googlegroups.com> References: <1ecfaec4-7f98-4647-b750-52b86103cf0a@googlegroups.com> Message-ID: <3a7a64d1-f0c2-4d5e-9754-75b4b4f1fe8e@googlegroups.com> Thank you very much! fixed with w.after Here is the code, works under Linux for those who have acpi. My output of "acpi -V" is the following, the code is parsing the first line of the output. Any improvements are appreciated. > $ acpi -V > Battery 0: Discharging, 12%, 00:10:59 remaining > Battery 0: design capacity 2200 mAh, last full capacity 1349 mAh = 61% > Adapter 0: off-line > Thermal 0: ok, 40.0 degrees C > Thermal 0: trip point 0 switches to mode critical at temperature 98.0 degrees C > Thermal 0: trip point 1 switches to mode passive at temperature 93.0 degrees C > Cooling 0: Processor 0 of 10 > Cooling 1: Processor 0 of 10 > Cooling 2: Processor 0 of 10 > Cooling 3: Processor 0 of 10 > Cooling 4: LCD 0 of 9 ---------------------------------------------------------- ---------------------------------------------------------- ---------------------------------------------------------- #!/usr/bin/python3.2 from re import findall, search from threading import Thread from time import sleep from subprocess import Popen, call, PIPE, STDOUT from tkinter import Tk, Label, StringVar def runProcess(exe): p=Popen(exe, stdout=PIPE, stderr=STDOUT) while True: retcode=p.poll() line=p.stdout.readline() yield line if retcode is not None: break class BatteryMonitor: def __init__(self): root = Tk() root.configure(padx=1, pady=1, bg="#555753") root.geometry("-0+0") root.overrideredirect(True) root.wm_attributes("-topmost", True) self.batteryExtendedStringVar = StringVar() self.batteryPercentStringVar = StringVar() self.batteryExtendedLabel = Label(root, textvariable=self.batteryExtendedStringVar, font=("fixed", 9), bg="#3e4446", fg="#d3d7cf", padx=10, pady=-1) self.batteryPercentLabel = Label(root, textvariable=self.batteryPercentStringVar, font=("fixed", 9), width=4, bg="#3e4446", fg="#d3d7cf", padx=-1, pady=-1) self.batteryPercentLabel.grid() t = Thread(target=self.update_battery_level_loop) t.start() root.bind("", self.display_details) self.root = root root.mainloop() def display_details(self, event): # displays a message about details of battery status # i.e. "on-line" or "charging, 20 min left" and so on self.batteryPercentLabel.grid_remove() self.batteryExtendedLabel.grid() self.batteryExtendedLabel.after(1000, self.batteryExtendedLabel.grid_remove) self.batteryPercentLabel.after(1000, self.batteryPercentLabel.grid) def read_battery_level(self): # dummy function used just to test the GUI for line in runProcess(["acpi", "-V"]): if line[11:-1]!=b"on-line": self.level = findall(b"\d\d?", line[11:])[0] else: self.level = b"0" return line[11:-1] def update_battery_level_loop(self): # threaded function, should constantly update the battery level self.read_battery_level() while True: self.batteryPercentStringVar.set(str(self.level)[2:-1]+"%") self.batteryExtendedStringVar.set(self.read_battery_level()) if self.level == 2: runProcess(["shutdown", "-h", "now"]) return sleep(5) ############################################## # # main BatteryMonitor() From jldunn2000 at gmail.com Mon Jan 28 06:47:07 2013 From: jldunn2000 at gmail.com (loial) Date: Mon, 28 Jan 2013 03:47:07 -0800 (PST) Subject: Reading file issue Message-ID: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> I am parseing a file to extract data, but am seeing the file being updated even though I never explicitly write to the file. It is possible that another process is doing this at some later time, but I just want to check that opening the file as follows and ignoring a record would not result in that record being removed from the file. I'm damned sure it wouldn't, but just wanted to check with the experts!. for line in open("/home/john/myfile"): linecount = linecount + 1 if linecount == 1: # ignore header continue From rosuav at gmail.com Mon Jan 28 06:57:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Jan 2013 22:57:43 +1100 Subject: Reading file issue In-Reply-To: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> References: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> Message-ID: On Mon, Jan 28, 2013 at 10:47 PM, loial wrote: > I am parseing a file to extract data, but am seeing the file being updated even though I never explicitly write to the file. It is possible that another process is doing this at some later time, but I just want to check that opening the file as follows and ignoring a record would not result in that record being removed from the file. > > I'm damned sure it wouldn't, but just wanted to check with the experts!. > > for line in open("/home/john/myfile"): Absolutely not. You're opening the file (by default) for reading only. That's not going to edit the file in any way. (It might cause the directory entry to be rewritten, eg last-access time, but not the file contents.) Your expectation is 100% correct. ChrisA From jldunn2000 at gmail.com Mon Jan 28 07:03:54 2013 From: jldunn2000 at gmail.com (loial) Date: Mon, 28 Jan 2013 04:03:54 -0800 (PST) Subject: Reading file issue In-Reply-To: References: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> Message-ID: <3d1de311-79f3-418d-a5d4-7f8d1b6053db@googlegroups.com> Thanks for confirming my sanity On Monday, 28 January 2013 11:57:43 UTC, Chris Angelico wrote: > On Mon, Jan 28, 2013 at 10:47 PM, loial wrote: > I am parseing a file to extract data, but am seeing the file being updated even though I never explicitly write to the file. It is possible that another process is doing this at some later time, but I just want to check that opening the file as follows and ignoring a record would not result in that record being removed from the file. > > I'm damned sure it wouldn't, but just wanted to check with the experts!. > > for line in open("/home/john/myfile"): Absolutely not. You're opening the file (by default) for reading only. That's not going to edit the file in any way. (It might cause the directory entry to be rewritten, eg last-access time, but not the file contents.) Your expectation is 100% correct. ChrisA From jldunn2000 at gmail.com Mon Jan 28 07:03:54 2013 From: jldunn2000 at gmail.com (loial) Date: Mon, 28 Jan 2013 04:03:54 -0800 (PST) Subject: Reading file issue In-Reply-To: References: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> Message-ID: <3d1de311-79f3-418d-a5d4-7f8d1b6053db@googlegroups.com> Thanks for confirming my sanity On Monday, 28 January 2013 11:57:43 UTC, Chris Angelico wrote: > On Mon, Jan 28, 2013 at 10:47 PM, loial wrote: > I am parseing a file to extract data, but am seeing the file being updated even though I never explicitly write to the file. It is possible that another process is doing this at some later time, but I just want to check that opening the file as follows and ignoring a record would not result in that record being removed from the file. > > I'm damned sure it wouldn't, but just wanted to check with the experts!. > > for line in open("/home/john/myfile"): Absolutely not. You're opening the file (by default) for reading only. That's not going to edit the file in any way. (It might cause the directory entry to be rewritten, eg last-access time, but not the file contents.) Your expectation is 100% correct. ChrisA From oscar.j.benjamin at gmail.com Mon Jan 28 06:58:52 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 28 Jan 2013 11:58:52 +0000 Subject: Reading file issue In-Reply-To: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> References: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> Message-ID: On 28 January 2013 11:47, loial wrote: > I am parseing a file to extract data, but am seeing the file being updated even though I never explicitly write to the file. It is possible that another process is doing this at some later time, but I just want to check that opening the file as follows and ignoring a record would not result in that record being removed from the file. > > I'm damned sure it wouldn't, but just wanted to check with the experts!. > > > for line in open("/home/john/myfile"): The line above opens the file in read-only mode. It's not possible to make changes to the file if you only open it in read-only mode. So no this code is not modifying the file. It is, however, slightly better to write the above as with open('/home/john/myfile') as fin: for line in fin: # stuff This is better as the "with" statement handles errors better than just calling open directly. > linecount = linecount + 1 > > if linecount == 1: # ignore header > continue Another way of achieving this would be to do: headerline = fin.readline() for line in fin: # No need to worry about that header line now Oscar From python.list at tim.thechases.com Mon Jan 28 07:14:53 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 28 Jan 2013 06:14:53 -0600 Subject: Reading file issue In-Reply-To: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> References: <6d84c2f6-e99a-4481-b557-ddb38b04bab9@googlegroups.com> Message-ID: <20130128061453.24424742@bigbox.christie.dr> On Mon, 28 Jan 2013 03:47:07 -0800 (PST) loial wrote: > I am parseing a file to extract data, but am seeing the file being > updated even though I never explicitly write to the file. It is > possible that another process is doing this at some later time, but > I just want to check that opening the file as follows and ignoring > a record would not result in that record being removed from the > file. The only complication I'd see would be the reader bombing out because the writer process is in the middle of writing. A quick test on WinXP showed that it's possible to continue to write to a file that another process has open for reading (this shouldn't be an issue on POSIX OSes; Win32 can be a bit more fascist about sharing files, especially if they're both open for writing). However, that doesn't alter the data written, so all it takes is just re-running the reader process. -tkc From 7millionatives at gmail.com Mon Jan 28 07:34:49 2013 From: 7millionatives at gmail.com (Huey Mataruse) Date: Mon, 28 Jan 2013 04:34:49 -0800 (PST) Subject: Hello All Message-ID: <99b78bfe-bdb8-47e3-8d54-d60d22427b1d@googlegroups.com> I have been learning Python on my own and its been 1yr now and i still feel i dont know anything, is there a way that i can use to increase my way of learning. I feel there is more that i can do with python that other languages cannot. Please help. From davea at davea.name Mon Jan 28 07:55:42 2013 From: davea at davea.name (Dave Angel) Date: Mon, 28 Jan 2013 07:55:42 -0500 Subject: Hello All In-Reply-To: <99b78bfe-bdb8-47e3-8d54-d60d22427b1d@googlegroups.com> References: <99b78bfe-bdb8-47e3-8d54-d60d22427b1d@googlegroups.com> Message-ID: <5106754E.1090303@davea.name> On 01/28/2013 07:34 AM, Huey Mataruse wrote: > I have been learning Python on my own and its been 1yr now and i still feel i dont know anything, is there a way that i can use to increase my way of learning. > I feel there is more that i can do with python that other languages cannot. > > Please help. > Welcome to Python. Nothing wrong with learning Python on your own, but if you feel you haven't made much progress in a year, perhaps your approach is inadequate, or perhaps you need more discipline in applying it. Or maybe you actually know more than your realize. If you could be specific in some concept that escapes you, maybe we could give some specific help. First, your background. Are you fluent in any other languages? Have you any college training in any particular computer skills? Do you use them in your work, or what? Next, what have you been doing to actually try to learn? Have you worked through a tutorial, and I mean really worked through it, writing programs for every exercise, not just read it, and hoped it'd stick? If so, which tutorial? Finally, what version of Python are you learning, and on what OS can you play? Do you actually have it installed, or is this book learning? Do you work in an environment where you could write an occasional utility in your own choice of language? Or does it all need to be on your own time? tutor at python.org is generally better suited for beginner's questions than python-list. But since you're already here... -- DaveA From zughumancapital at yahoo.com.br Mon Jan 28 07:55:11 2013 From: zughumancapital at yahoo.com.br (zughumancapital) Date: Mon, 28 Jan 2013 12:55:11 -0000 Subject: Arpex Capital Seleciona: Programador Python Pleno/RJ Message-ID: Arpex Capital seleciona para uma de suas startups: Programador Python Pleno Descri??o: Programador para Web Crawler Python - Experi?ncia m?nima de 1 ano em python - Conhecimento de padr?es de projeto - S?lido conhecimento OO - Ser auto-gerenci?vel - Conhecimento de SQL Desej?vel: - Ter github - Ter interesse por NPL ? J? ter feito um scraper/crawler/parser - Saber qualquer NoSQL Local de Trabalho: Botafogo/RJ Gradua??o Completa em Ci?ncia da Computa??o e/ou afins; Os interessados dever?o enviar CV com PRENTENS?O SALARIAL para kgarcia at arpexcapital.com.br , mencionando no assunto Programador Python/Botafogo. From zughumancapital at yahoo.com.br Mon Jan 28 07:55:35 2013 From: zughumancapital at yahoo.com.br (zughumancapital) Date: Mon, 28 Jan 2013 12:55:35 -0000 Subject: =?iso-8859-1?q?Arpex_Capital_Seleciona:_Desenvolvedor_Python/Django_S=EAnior_=96_RJ?= Message-ID: Arpex Capital seleciona para uma de suas startups: Desenvolvedor Python/Django S?nior Estamos em busca daqueles(as) que: acham que meritocracia ? indispens?vel, programam desde a inf?ncia, possuem sede por aprender e programar e querem trabalhar muito para fazer algo especial! O desenvolvedor estar? envolvido em um projeto Python/Django para uma das startups da ArpexCapital (fundo de investimentos americano com foco no mercado brasileiro). Skills necess?rios: Python, HTML, MySQL Skills desej?veis (b?nus): Framework Django, Javascript, Linux, Scrum ou XP Local de Trabalho: Centro/RJ Os interessados dever?o enviar o CV com pretens?o salarial para kgarcia at arpexcapital.com.br, mencionando no assunto Desenvolvedor Python/Django S?nior. From mikprog at gmail.com Mon Jan 28 08:15:49 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Mon, 28 Jan 2013 05:15:49 -0800 (PST) Subject: software app and Python: any experience? Message-ID: <7d3f8958-1475-42db-ad7a-bbb1ef75451b@googlegroups.com> Hi guys, I am thinking of driving a DJ application from Python. I am running Linux and I found the Mixxx app. Does anyone know if there are python bindings, or if this is possible at all? or does anyone have experience with another software that does the same DJ thing? I have also found the pymixxx module that I could install... but I didn't find any documentation so far or example code that could help me start (I'm keeping on searching). Finally maybe that there is any DJ app that could be driven by pygame.midi? Any idea appreciated. Sorry to fail to be more specific. Mik From insideshoes at gmail.com Mon Jan 28 08:31:31 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Mon, 28 Jan 2013 14:31:31 +0100 Subject: Reading data from 2 different files and writing to a single file Message-ID: In the code below I am trying to read 2 files f1 and f2 , extract some data from them and then trying to write them into a single file that is 'nf'. import cv f1 = open(r"Z:\modules\Feature_Vectors_300.arff") f2 = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") nf = open(r"Z:\modules\trial.arff", "w") for l in f1: sp = l.split(",") if len(sp)!= 12: continue else: ix = sp[0].strip() iy = sp[1].strip() print ix, iy for s in f2: st = s.split(",") if len(st)!= 11: continue else: clas = st[10].strip() print ix, iy, clas print >> nf, ix, iy, clas f1.close() f2.close() nf.close() I think my code is not so correct , as I am not getting desired results and logically it follows also but I am stuck , cannot find a way around this simple problem of writing to a same file.. Please suggest some good pythonic way I can do it.. Thanks in Advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 28 08:43:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jan 2013 00:43:14 +1100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: Message-ID: On Tue, Jan 29, 2013 at 12:31 AM, inshu chauhan wrote: > I think my code is not so correct , as I am not getting desired results... Firstly, what results are you getting, and what are you desiring? It helps to be clear with that. > import cv What module is this? Do you need it? Does it affect things? It's not a Python standard library module, as far as I know. > for l in f1: > else: > print ix, iy > for s in f2: This will bomb immediately with an IndentationError. I can't be sure whether you intended for the loops to be nested or not. One of the consequences of Python's use of indentation to define blocks is that you have to be really careful when you copy and paste. (Which bit me somewhat this weekend; I tried to share some Python code via a spreadsheet, and it mangled the leading whitespace. Very tiresome.) Can you try pasting in your actual code, please? Chris Angelico From jeanmichel at sequans.com Mon Jan 28 08:52:52 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 28 Jan 2013 14:52:52 +0100 (CET) Subject: Reading data from 2 different files and writing to a single file In-Reply-To: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> Message-ID: <593271165.11093490.1359381172613.JavaMail.root@sequans.com> ----- Original Message ----- > > ----- Original Message ----- > > > In the code below I am trying to read 2 files f1 and f2 , extract > > some data from them and then trying to write them into a single > > file > > that is 'nf'. > > [snip code] > > > I think my code is not so correct , as I am not getting desired > > results and logically it follows also but I am stuck , cannot find > > a > > way around this simple problem of writing to a same file.. Please > > suggest some good pythonic way I can do it.. > > > Thanks in Advance > > Hi, > > What result do you expect ? can you provide the 2 first lines of f1 > and f2, and finally what is the exact error you are experiencing ? > > Cheers, > > JM Resending to the list, I replied to the OP by mistake. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From insideshoes at gmail.com Mon Jan 28 09:12:56 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Mon, 28 Jan 2013 15:12:56 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: <593271165.11093490.1359381172613.JavaMail.root@sequans.com> References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> Message-ID: Yes Chris, I understand, My Original code was for l in f1: sp = l.split(",") if len(sp)!= 12: continue else: ix = sp[0].strip() iy = sp[1].strip() for s in f2: st = s.split(",") if len(st)!= 11: continue else: clas = st[10].strip() print ix, iy, clas print >> nf, ix, iy, clas f1.close() f2.close() nf.close() where f1 contains something like : 297, 404, , .... 298, 404, , ...... 299, 404, ..... ..... ...... 295, 452, .... and f2 contains something like : .... 7 ..... 2 ....2 .....7 and what I want to be written in the new file i.e. nf is something like: 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 7 297 404 2 297 404 2 297 404 2 297 404 2 297 404 2 which m getting but partially correct because only last value is changing not the first two... which should not happen.. In every loop all the three values should change.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 28 09:19:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jan 2013 01:19:23 +1100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> Message-ID: On Tue, Jan 29, 2013 at 1:12 AM, inshu chauhan wrote: > where f1 contains something like : > > 297, 404, , .... > 298, 404, , ...... > 299, 404, ..... > ..... ...... > 295, 452, .... > > and f2 contains something like : > > .... 7 > ..... 2 > ....2 > .....7 > > and what I want to be written in the new file i.e. nf is something like: > > 297 404 7 > 297 404 2 > > which m getting but partially correct because only last value is changing > not the first two... which should not happen.. In every loop all the three > values should change.. In that case, Dave's suggestion to read into a list and iterate over the list is to be strongly considered. But I'm not entirely sure what your goal is here. Are you trying to make the Cartesian product of the two files, where you have one line in the output for each possible pair of matching lines? That is, for each line in the first file, you make a line in the output for each line in the second? That's what your code will currently do. ChrisA From insideshoes at gmail.com Mon Jan 28 09:24:49 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Mon, 28 Jan 2013 15:24:49 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> Message-ID: > In that case, Dave's suggestion to read into a list and iterate over > the list is to be strongly considered. But I'm not entirely sure what > your goal is here. Are you trying to make the Cartesian product of the > two files, where you have one line in the output for each possible > pair of matching lines? That is, for each line in the first file, you > make a line in the output for each line in the second? That's what > your code will currently do. > No , I dont want that , actually both files have equal no of lines, I want to read the first line of f1 , take 2 datas from it, nd then read first line of f2, take data from it, then print them to the same first line of new file i.e nf. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 28 09:32:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jan 2013 01:32:30 +1100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> Message-ID: On Tue, Jan 29, 2013 at 1:24 AM, inshu chauhan wrote: >> In that case, Dave's suggestion to read into a list and iterate over >> the list is to be strongly considered. But I'm not entirely sure what >> your goal is here. Are you trying to make the Cartesian product of the >> two files, where you have one line in the output for each possible >> pair of matching lines? That is, for each line in the first file, you >> make a line in the output for each line in the second? That's what >> your code will currently do. > > No , I dont want that , actually both files have equal no of lines, I want > to read the first line of f1 , take 2 datas from it, nd then read first line > of f2, take data from it, > then print them to the same first line of new file i.e nf. Okay, so you want an algorithm something like this: for l1 in f1: # make sure you have the right sort of line, and 'continue' if not for l2 in f2: # same again, 'continue' if not right print >> nf # whatever you need to output break The 'break' in the second loop will mean that it never consumes more than one valid line. You still need to deal with the possibilities of one file being shorter than the other, of the lines mismatching, etc, but at least you don't get a failed Cartesian product. ChrisA From d at davea.name Mon Jan 28 09:37:51 2013 From: d at davea.name (Dave Angel) Date: Mon, 28 Jan 2013 09:37:51 -0500 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> Message-ID: <51068D3F.2040106@davea.name> On 01/28/2013 09:12 AM, inshu chauhan wrote: > Yes Chris, I understand, My Original code was > > for l in f1: > sp = l.split(",") > > if len(sp)!= 12: > continue > else: > ix = sp[0].strip() > iy = sp[1].strip() > > > for s in f2: > st = s.split(",") > > if len(st)!= 11: > continue > else: > clas = st[10].strip() > > print ix, iy, clas > print >> nf, ix, iy, clas > > f1.close() > f2.close() > nf.close() > > where f1 contains something like : > > 297, 404, , .... > 298, 404, , ...... > 299, 404, ..... > ..... ...... > 295, 452, .... > > and f2 contains something like : > > .... 7 > ..... 2 > ....2 > .....7 > > and what I want to be written in the new file i.e. nf is something like: > > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 7 > 297 404 2 > 297 404 2 > 297 404 2 > 297 404 2 > 297 404 2 > > which m getting but partially correct because only last value is changing > not the first two... which should not happen.. In every loop all the three > values should change.. > > Your current logic tries to scan through the first file, and for each line that has 12 elements, scans through the entire second file. It fails to actually do it, because you never do a seek on the second file. Now it appears your requirement is entirely different. I believe you have two text files each having the same number of lines. You want to loop through the pair of lines (once from each file, doing some kind of processing and printing). If that's the case, your nested loop is the wrong thing, and you can forget my caveat about nesting file reads. What you want is the zip() function for l,s in zip(f1, f2): #you now have one line from each file, # which you can then validate and process Note, this assumes that when a line is "bad" from either file, you're going to also ignore the corresponding line from the other. If you have to accommodate variable misses in the lining up, then your work is *much* harder. -- DaveA From rosuav at gmail.com Mon Jan 28 09:49:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jan 2013 01:49:32 +1100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: <51068D3F.2040106@davea.name> References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> <51068D3F.2040106@davea.name> Message-ID: On Tue, Jan 29, 2013 at 1:37 AM, Dave Angel wrote: > What you want is the zip() function > > for l,s in zip(f1, f2): > #you now have one line from each file, > # which you can then validate and process > > Note, this assumes that when a line is "bad" from either file, you're going > to also ignore the corresponding line from the other. If you have to > accommodate variable misses in the lining up, then your work is *much* > harder. Much harder? Not really - see my solution above with a simple 'break'. Much less clear what's going on, though, it is. Iterating together over both files with zip is much cleaner. ChrisA From vs at it.uu.se Mon Jan 28 12:29:03 2013 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 28 Jan 2013 18:29:03 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> <51068D3F.2040106@davea.name> Message-ID: <5106B55F.9070104@it.uu.se> On 28-Jan-2013 15:49, Chris Angelico wrote: > On Tue, Jan 29, 2013 at 1:37 AM, Dave Angel wrote: >> What you want is the zip() function >> >> for l,s in zip(f1, f2): >> #you now have one line from each file, >> # which you can then validate and process >> >> Note, this assumes that when a line is "bad" from either file, you're going >> to also ignore the corresponding line from the other. If you have to >> accommodate variable misses in the lining up, then your work is *much* >> harder. > Much harder? Not really - see my solution above with a simple 'break'. > Much less clear what's going on, though, it is. Iterating together > over both files with zip is much cleaner. > > ChrisA Nice example of the power of zip, Chris :-) From insideshoes at gmail.com Mon Jan 28 09:47:52 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Mon, 28 Jan 2013 15:47:52 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: <51068D3F.2040106@davea.name> References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> <51068D3F.2040106@davea.name> Message-ID: Your current logic tries to scan through the first file, and for each line that has 12 elements, scans through the entire second file. It fails to actually do it, because you never do a seek on the second file. > > Now it appears your requirement is entirely different. I believe you have > two text files each having the same number of lines. You want to loop > through the pair of lines (once from each file, doing some kind of > processing and printing). If that's the case, your nested loop is the > wrong thing, and you can forget my caveat about nesting file reads. > > What you want is the zip() function > > for l,s in zip(f1, f2): > #you now have one line from each file, > # which you can then validate and process > > Note, this assumes that when a line is "bad" from either file, you're > going to also ignore the corresponding line from the other. If you have to > accommodate variable misses in the lining up, then your work is *much* > harder. > > > > > > Actually these are Arff files used in Weka (Data Mining ), So they have a certain amount of header information which is the same in both files(in same no. of lines too ) and both files have equal lines, So when I read basically In both files I am trying to ignore the Header information. then it is like reading first line from f1 and first line from f2, extracting the data I want from each file and simply write it to a third file line by line... What does actually Zip function do ? Thanks and Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Jan 28 10:10:48 2013 From: davea at davea.name (Dave Angel) Date: Mon, 28 Jan 2013 10:10:48 -0500 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> <51068D3F.2040106@davea.name> Message-ID: <510694F8.8020603@davea.name> On 01/28/2013 09:47 AM, inshu chauhan wrote: > Your current logic tries to scan through the first file, and for each line > that has 12 elements, scans through the entire second file. It fails to > actually do it, because you never do a seek on the second file. > >> >> Now it appears your requirement is entirely different. I believe you have >> two text files each having the same number of lines. You want to loop >> through the pair of lines (once from each file, doing some kind of >> processing and printing). If that's the case, your nested loop is the >> wrong thing, and you can forget my caveat about nesting file reads. >> >> What you want is the zip() function >> >> for l,s in zip(f1, f2): >> #you now have one line from each file, >> # which you can then validate and process >> >> Note, this assumes that when a line is "bad" from either file, you're >> going to also ignore the corresponding line from the other. If you have to >> accommodate variable misses in the lining up, then your work is *much* >> harder. >> >> >> >> >> >> Actually these are Arff files used in Weka (Data Mining ), So they have a > certain amount of header information which is the same in both files(in > same no. of lines too ) and both files have equal lines, So when I read > basically In both files I am trying to ignore the Header information. > > then it is like reading first line from f1 and first line from f2, > extracting the data I want from each file and simply write it to a third > file line by line... > > What does actually Zip function do ? > > Thanks and Regards > > > That's "zip" not "Zip" Have you tried looking at the docs? Or even typing help(zip) at the python interpreter prompt? In rough terms, zip takes one element (line) from each of the iterators, and creates a new list that holds tuples of those elements. If you use it in this form: for item1, item2 in zip(iter1, iter2): then item1 will be the first item of iter1, and item2 will be the first item of iter2. You then process them, and loop around. It stops when either iterator runs out of items. https://duckduckgo.com/?q=python+zip gives me http://docs.python.org/2/library/functions.html#zip as the first link. This will read the entire content of both files into the list, so if they are more than 100meg or so, you might want to use izip(). (In Python3.x, zip will do what izip does on Python 2.x) -- DaveA From insideshoes at gmail.com Mon Jan 28 10:18:08 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Mon, 28 Jan 2013 16:18:08 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: <510694F8.8020603@davea.name> References: <292387252.11081839.1359381055903.JavaMail.root@sequans.com> <593271165.11093490.1359381172613.JavaMail.root@sequans.com> <51068D3F.2040106@davea.name> <510694F8.8020603@davea.name> Message-ID: >> >> >> > That's "zip" not "Zip" > > Have you tried looking at the docs? Or even typing help(zip) at the > python interpreter prompt? > > In rough terms, zip takes one element (line) from each of the iterators, > and creates a new list that holds tuples of those elements. If you use it > in this form: > > for item1, item2 in zip(iter1, iter2): > > then item1 will be the first item of iter1, and item2 will be the first > item of iter2. You then process them, and loop around. It stops when > either iterator runs out of items. > > https://duckduckgo.com/?q=**python+zip > gives me http://docs.python.org/2/**library/functions.html#zip > > as the first link. > > This will read the entire content of both files into the list, so if they > are more than 100meg or so, you might want to use izip(). (In Python3.x, > zip will do what izip does on Python 2.x) > > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > Thanks Dave, I am Sorry , true I dint look up for it because as per the Suggetion by Chris, 'break' does solve my problem but I wanted to know a little about 'zip' for I encounter any other problem, parsing these two files. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Jan 28 09:05:25 2013 From: davea at davea.name (Dave Angel) Date: Mon, 28 Jan 2013 09:05:25 -0500 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: Message-ID: <510685A5.5000108@davea.name> On 01/28/2013 08:31 AM, inshu chauhan wrote: > In the code below I am trying to read 2 files f1 and f2 , extract some data > from them and then trying to write them into a single file that is 'nf'. > > import cv > f1 = open(r"Z:\modules\Feature_Vectors_300.arff") > f2 = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") > nf = open(r"Z:\modules\trial.arff", "w") > > > for l in f1: > sp = l.split(",") > > if len(sp)!= 12: > continue > else: > ix = sp[0].strip() > iy = sp[1].strip() > print ix, iy > > for s in f2: > st = s.split(",") > > if len(st)!= 11: > continue > else: > clas = st[10].strip() > > print ix, iy, clas > print >> nf, ix, iy, clas > > f1.close() > f2.close() > nf.close() > > > I think my code is not so correct , as I am not getting desired results and > logically it follows also but I am stuck , cannot find a way around this > simple problem of writing to a same file.. Please suggest some good > pythonic way I can do it.. > > > Thanks in Advance > > > The other questions are useful, but I'll make a guess based on what you've said so far. You're trying to read the same file f2 multiple times, as you loop around the f1 file. But you just keep the file open and try to iterate over it multiple times. You either need to close and open it each time, or do a seek to beginning, or you'll not see any data for the second and later iteration. Or better, just read file f2 into a list, and iterate over that, which you can do as many times as you like. (Naturally this assumes it's not over a couple of hundred meg). file2 = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") f2 = file2.readlines() file2.close() -- DaveA From wolfgang.maier at biologie.uni-freiburg.de Mon Jan 28 10:08:38 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 28 Jan 2013 16:08:38 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: Message-ID: <00c701cdfd69$5a457ff0$0ed07fd0$@biologie.uni-freiburg.de> Hi, as many others I am not exactly sure what the purpose of your code really is. However, if what you?re trying to do here is to take one line from f1, one line from f2 and then write some combined data to nf, it is not surprising that you're not getting what you expect (the main reason being that your for loops are nested, as pointed out already). In that case, a much cleaner and less error-prone solution would be iterator-zipping, leaving you with just one for loop that is easy to understand: for l,s in zip(f1,f2): # now l holds the next line from f1, s the corresponding line from f2 do_yourstuf() write_output() if your files are large, then in python 2.x you should use: import itertools for l,s in itertools.izip(f1,f2): do_yourstuff() write_output() The reason for this is that before python 3 zip gathered and returned your results as an in-memory list. itertools.izip and the built-in python 3 zip return iterators. Hope that helps, Wolfgang From: inshu chauhan [mailto:insideshoes at gmail.com] Sent: Monday, January 28, 2013 2:32 PM To: python-list at python.org Subject: Reading data from 2 different files and writing to a single file In the code below I am trying to read 2 files f1 and f2 , extract some data from them and then trying to write them into a single file that is 'nf'. import cv f1 = open(r"Z:\modules\Feature_Vectors_300.arff") f2 = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") nf = open(r"Z:\modules\trial.arff", "w") for l in f1: ??? sp = l.split(",") ??? ??? if len(sp)!= 12: ??????? continue ??? else: ??????? ix = sp[0].strip() ??????? iy = sp[1].strip() ??????? print ix, iy ??????? ?????? for s in f2: ??????????? st = s.split(",") ??? ??????????? if len(st)!= 11: ??????????????? continue ??????????? else: ??????????????? clas = st[10].strip() ??????? ???????????? print ix, iy, clas ???????????? print >> nf, ix, iy, clas f1.close() f2.close() nf.close() I think my code is not so correct , as I am not getting desired results and logically it follows also but I am stuck , cannot find a way around this simple problem of writing to a same file.. Please suggest some good pythonic way I can do it.. Thanks in Advance From insideshoes at gmail.com Wed Jan 30 05:43:05 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Wed, 30 Jan 2013 11:43:05 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: Message-ID: On Mon, Jan 28, 2013 at 6:05 PM, Dennis Lee Bieber wrote: > On Mon, 28 Jan 2013 14:31:31 +0100, inshu chauhan > declaimed the following in > gmane.comp.python.general: > > > In the code below I am trying to read 2 files f1 and f2 , extract some > data > > from them and then trying to write them into a single file that is 'nf'. > > > > import cv > > f1 = open(r"Z:\modules\Feature_Vectors_300.arff") > > f2 = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") > > nf = open(r"Z:\modules\trial.arff", "w") > > > > > > for l in f1: > > sp = l.split(",") > > If you are going to be splitting on commas, you might want to read > up on the csv (comma separate values) module > The csv module has many fuctions but not of much use to me and it makes my programme slower > > > > > if len(sp)!= 12: > > continue > > else: > > Given the apparent block structure, you could drop the > continue/else, and more cleanly just use > Yeah, Thats Right > > if len(sp) == 12: > > ix = sp[0].strip() > > iy = sp[1].strip() > > print ix, iy > > > > for s in f2: > > It's been mentioned that the indentation is wrong here > I dont know why the indentation is wrong ? > > > st = s.split(",") > > > csv module again > > > if len(st)!= 11: > > continue > > else: > > I'm tempted to repeat the comment on reversing the conditional BUT > > > clas = st[10].strip() > > > > print ix, iy, clas > > print >> nf, ix, iy, clas > > > The indentation of the print statements is not aligned with the > previous assignment -- the effect is the same however as everything > under the else is executed anyway. > > But as has also been mentioned, ignoring indentation, the apparent > algorithm you have here is going to process every line of f2 for the > first line of f1 -- and then for later lines in f1 it will find f2 is at > the end of file, and do nothing. If it is supposed to process every line > of f2 for each line of f1, you'll need to rewind f2. > For that I added 'Break' statement as suggested by Chris in above mails. > > If you mean to match one line of f1 with one line of f2, you do not > want nested loops. But now you have to define the behavior if one of the > two files is correct length and the other is not? Do you skip both or > read the next line from the wrong length file? And how will you handle > files with different numbers of records. > Yes , actually my Prog was like this : for l in f1: sp = l.split(",") if len(sp)!= 12: continue else: ix = sp[0].strip() iy = sp[1].strip() for s in f2: st = s.split(",") if len(st)!= 11: continue else: clas = st[10].strip() print ix, iy, clas print >> nf, ix, iy, clas break f1.close() f2.close() nf.close() I actually dont want nested loops but cant find another way to achieve what I want, But for these files I am sure that they have equal lengths, thats why I am taking the risk of using nested loops.. Can you suggest any different way to go around this problem , which could be flexible and non-errorneous ? > > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 30 05:47:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jan 2013 21:47:18 +1100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: Message-ID: On Wed, Jan 30, 2013 at 9:43 PM, inshu chauhan wrote: > I actually dont want nested loops but cant find another way to achieve what > I want, But for these files I am sure that they have equal lengths, thats > why I am taking the risk of using nested loops.. Can you suggest any > different way to go around this problem , which could be flexible and > non-errorneous ? Easy. Just trim off the header row(s), if you know how many to expect, and then use zip() as Dave mentioned earlier. ChrisA From d at davea.name Wed Jan 30 08:23:05 2013 From: d at davea.name (Dave Angel) Date: Wed, 30 Jan 2013 08:23:05 -0500 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: References: Message-ID: <51091EB9.8040905@davea.name> On 01/30/2013 05:43 AM, inshu chauhan wrote: > On Mon, Jan 28, 2013 at 6:05 PM, Dennis Lee Bieber wrote: > >> On Mon, 28 Jan 2013 14:31:31 +0100, inshu chauhan >> declaimed the following in >> gmane.comp.python.general: >> >>> In the code below I am trying to read 2 files f1 and f2 , extract some >> data >>> from them and then trying to write them into a single file that is 'nf'. >>> >>> import cv >>> f1 = open(r"Z:\modules\Feature_Vectors_300.arff") >>> f2 = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff") >>> nf = open(r"Z:\modules\trial.arff", "w") >>> >>> >>> for l in f1: >>> sp = l.split(",") >> >> If you are going to be splitting on commas, you might want to read >> up on the csv (comma separate values) module >> > > The csv module has many fuctions but not of much use to me and it makes my > programme slower > >> >>> >>> if len(sp)!= 12: >>> continue >>> else: >> >> Given the apparent block structure, you could drop the >> continue/else, and more cleanly just use >> > > Yeah, Thats Right > >> >> if len(sp) == 12: >>> ix = sp[0].strip() >>> iy = sp[1].strip() >>> print ix, iy >>> >>> for s in f2: >> >> It's been mentioned that the indentation is wrong here >> > > I dont know why the indentation is wrong ? Your for statement is not lined up with the print that precedes it. If your code were really that way, you'd be getting an indentation error. So we assume it's because your email editor is mangling the code. Post in text email, not in html. > >> >>> st = s.split(",") >>> >> csv module again >> >>> if len(st)!= 11: >>> continue >>> else: >> >> I'm tempted to repeat the comment on reversing the conditional BUT >> >>> clas = st[10].strip() >>> >>> print ix, iy, clas >>> print >> nf, ix, iy, clas >>> >> The indentation of the print statements is not aligned with the >> previous assignment -- the effect is the same however as everything >> under the else is executed anyway. >> >> But as has also been mentioned, ignoring indentation, the apparent >> algorithm you have here is going to process every line of f2 for the >> first line of f1 -- and then for later lines in f1 it will find f2 is at >> the end of file, and do nothing. If it is supposed to process every line >> of f2 for each line of f1, you'll need to rewind f2. >> > > For that I added 'Break' statement as suggested by Chris in above mails. > >> >> If you mean to match one line of f1 with one line of f2, you do not >> want nested loops. But now you have to define the behavior if one of the >> two files is correct length and the other is not? Do you skip both or >> read the next line from the wrong length file? And how will you handle >> files with different numbers of records. >> > > Yes , actually my Prog was like this : > for l in f1: > sp = l.split(",") > > if len(sp)!= 12: > continue > else: > ix = sp[0].strip() > iy = sp[1].strip() > > > for s in f2: This is not nested, it's back at the left margin. Or it could be posting wrong because you're still posting in html, instead of plain text email. > st = s.split(",") > > if len(st)!= 11: > continue > else: > clas = st[10].strip() > > print ix, iy, clas > print >> nf, ix, iy, clas > break > > > f1.close() > f2.close() > nf.close() > > I actually dont want nested loops but cant find another way to achieve what > I want, But for these files I am sure that they have equal lengths, thats > why I am taking the risk of using nested loops. You have that backwards. Because you say you can assume they're the same length, you don't need the flexibility (and unreadability) of the nested approach. The zip approach works great, and nested is unnecessary. . Can you suggest any > different way to go around this problem , which could be flexible and > non-errorneous ? > > -- DaveA From insideshoes at gmail.com Wed Jan 30 08:58:32 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Wed, 30 Jan 2013 14:58:32 +0100 Subject: Reading data from 2 different files and writing to a single file In-Reply-To: <51091EB9.8040905@davea.name> References: <51091EB9.8040905@davea.name> Message-ID: On Wed, Jan 30, 2013 at 2:23 PM, Dave Angel wrote: > On 01/30/2013 05:43 AM, inshu chauhan wrote: > >> On Mon, Jan 28, 2013 at 6:05 PM, Dennis Lee Bieber > >wrote: >> >> On Mon, 28 Jan 2013 14:31:31 +0100, inshu chauhan >>> declaimed the following in >>> gmane.comp.python.general: >>> >>> In the code below I am trying to read 2 files f1 and f2 , extract some >>>> >>> data >>> >>>> from them and then trying to write them into a single file that is 'nf'. >>>> >>>> import cv >>>> f1 = open(r"Z:\modules\Feature_**Vectors_300.arff") >>>> f2 = open(r"Z:\modules\Feature_**Vectors_300_Pclass.arff") >>>> nf = open(r"Z:\modules\trial.arff", "w") >>>> >>>> >>>> for l in f1: >>>> sp = l.split(",") >>>> >>> >>> If you are going to be splitting on commas, you might want to >>> read >>> up on the csv (comma separate values) module >>> >>> >> The csv module has many fuctions but not of much use to me and it makes >> my >> programme slower >> >> >>> >>>> if len(sp)!= 12: >>>> continue >>>> else: >>>> >>> >>> Given the apparent block structure, you could drop the >>> continue/else, and more cleanly just use >>> >>> >> Yeah, Thats Right >> >> >>> if len(sp) == 12: >>> >>>> ix = sp[0].strip() >>>> iy = sp[1].strip() >>>> print ix, iy >>>> >>>> for s in f2: >>>> >>> >>> It's been mentioned that the indentation is wrong here >>> >>> >> I dont know why the indentation is wrong ? >> > > Your for statement is not lined up with the print that precedes it. If > your code were really that way, you'd be getting an indentation error. So > we assume it's because your email editor is mangling the code. Post in > text email, not in html. > > > >> >>> st = s.split(",") >>>> >>>> csv module again >>> >>> if len(st)!= 11: >>>> continue >>>> else: >>>> >>> >>> I'm tempted to repeat the comment on reversing the conditional >>> BUT >>> >>> clas = st[10].strip() >>>> >>>> print ix, iy, clas >>>> print >> nf, ix, iy, clas >>>> >>>> The indentation of the print statements is not aligned with >>> the >>> previous assignment -- the effect is the same however as everything >>> under the else is executed anyway. >>> >>> But as has also been mentioned, ignoring indentation, the >>> apparent >>> algorithm you have here is going to process every line of f2 for the >>> first line of f1 -- and then for later lines in f1 it will find f2 is at >>> the end of file, and do nothing. If it is supposed to process every line >>> of f2 for each line of f1, you'll need to rewind f2. >>> >>> >> For that I added 'Break' statement as suggested by Chris in above mails. >> >> >>> If you mean to match one line of f1 with one line of f2, you do >>> not >>> want nested loops. But now you have to define the behavior if one of the >>> two files is correct length and the other is not? Do you skip both or >>> read the next line from the wrong length file? And how will you handle >>> files with different numbers of records. >>> >>> >> Yes , actually my Prog was like this : >> for l in f1: >> sp = l.split(",") >> >> if len(sp)!= 12: >> continue >> else: >> ix = sp[0].strip() >> iy = sp[1].strip() >> >> >> for s in f2: >> > > This is not nested, it's back at the left margin. Or it could be posting > wrong because you're still posting in html, instead of plain text email. > Yes My Initial code was not nested at the same time of no use too, I am > trying to use zip() now :) :) nyways.. > > > st = s.split(",") >> >> if len(st)!= 11: >> continue >> else: >> clas = st[10].strip() >> >> print ix, iy, clas >> print >> nf, ix, iy, clas >> break >> >> >> f1.close() >> f2.close() >> nf.close() >> >> I actually dont want nested loops but cant find another way to achieve >> what >> I want, But for these files I am sure that they have equal lengths, thats >> why I am taking the risk of using nested loops. >> > > You have that backwards. Because you say you can assume they're the same > length, you don't need the flexibility (and unreadability) of the nested > approach. The zip approach works great, and nested is unnecessary. > > > . Can you suggest any > >> different way to go around this problem , which could be flexible and >> non-errorneous ? >> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 28 08:55:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jan 2013 00:55:42 +1100 Subject: [Python-ideas] while conditional in list comprehension ?? In-Reply-To: <00b701cdfd5c$18d01100$4a703300$@biologie.uni-freiburg.de> References: <00b701cdfd5c$18d01100$4a703300$@biologie.uni-freiburg.de> Message-ID: On Tue, Jan 29, 2013 at 12:33 AM, Wolfgang Maier wrote: > Why not extend this filtering by allowing a while statement in addition to > if, as in: > > [n for n in range(1,1000) while n < 400] The time machine strikes again! Check out itertools.takewhile - it can do pretty much that: import itertools [n for n in itertools.takewhile(lambda n: n<400, range(1,1000))] It's not quite list comp notation, but it works. >>> [n for n in itertools.takewhile(lambda n: n<40, range(1,100))] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39] ChrisA From rosuav at gmail.com Mon Jan 28 08:56:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jan 2013 00:56:14 +1100 Subject: [Python-ideas] while conditional in list comprehension ?? In-Reply-To: References: <00b701cdfd5c$18d01100$4a703300$@biologie.uni-freiburg.de> Message-ID: Argh, sorry folks. Hit the wrong list. :( On Tue, Jan 29, 2013 at 12:55 AM, Chris Angelico wrote: > On Tue, Jan 29, 2013 at 12:33 AM, Wolfgang Maier > wrote: >> Why not extend this filtering by allowing a while statement in addition to >> if, as in: >> >> [n for n in range(1,1000) while n < 400] > > The time machine strikes again! Check out itertools.takewhile - it can > do pretty much that: > > import itertools > [n for n in itertools.takewhile(lambda n: n<400, range(1,1000))] > > It's not quite list comp notation, but it works. > >>>> [n for n in itertools.takewhile(lambda n: n<40, range(1,100))] > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, > 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, > 37, 38, 39] > > ChrisA From mikprog at gmail.com Mon Jan 28 10:10:20 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Mon, 28 Jan 2013 07:10:20 -0800 (PST) Subject: Mixxx DJ app and Python Message-ID: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Hi guys, I am thinking of driving a DJ application from Python. I am running Linux and I found the Mixxx app. Does anyone know if there are python bindings, or if this is possible at all? or does anyone have experience with another software that does the same DJ thing? I have also found the pymixxx module that I could install... but I didn't find any documentation so far or example code that could help me start (I'm keeping on searching). Finally maybe that there is any DJ app that could be driven by pygame.midi? Any idea appreciated. Sorry to fail to be more specific. Mik PS: I've reposted this message as the previous subject (software app and Python: any experience?) didn't make any sense From dwightdhutto at gmail.com Tue Jan 29 11:06:17 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 11:06:17 -0500 Subject: Mixxx DJ app and Python In-Reply-To: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Mon, Jan 28, 2013 at 10:10 AM, wrote: > > Hi guys, > > I am thinking of driving a DJ application from Python. > I am running Linux and I found the Mixxx app. > Does anyone know if there are python bindings, or if this is possible at all? > or does anyone have experience with another software that does the same DJ thing? > > I have also found the pymixxx module that I could install... but I didn't find any documentation so far or example code that could help me start (I'm keeping on searching). > > Finally maybe that there is any DJ app that could be driven by pygame.midi? > > Any idea appreciated. > Sorry to fail to be more specific. I'd just go with a command line app that triggered a .wav file at certain points using time.sleep(x) Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Jan 29 11:13:09 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 11:13:09 -0500 Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Tue, Jan 29, 2013 at 11:06 AM, David Hutto wrote: > On Mon, Jan 28, 2013 at 10:10 AM, wrote: >> >> Hi guys, >> >> I am thinking of driving a DJ application from Python. >> I am running Linux and I found the Mixxx app. >> Does anyone know if there are python bindings, or if this is possible at all? >> or does anyone have experience with another software that does the same DJ thing? >> Hydrogen, and audacity work perfectly together. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Jan 29 11:16:46 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 11:16:46 -0500 Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: >>> Does anyone know if there are python bindings, or if this is possible at all? >>> or does anyone have experience with another software that does the same DJ thing? >>> > >Hydrogen, and audacity work perfectly together. What I was about to do is take the mic, get the soundtrack/beat to the song going, and then plug it into audacity for further modification, or you can roll your own. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Jan 29 11:19:34 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 11:19:34 -0500 Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Tue, Jan 29, 2013 at 11:16 AM, David Hutto wrote: >>>> Does anyone know if there are python bindings, or if this is possible at all? >>>> or does anyone have experience with another software that does the same DJ thing? >>>> >> >>Hydrogen, and audacity work perfectly together. > > What I was about to do is take the output to the headphones, get the soundtrack/beat to the song going, and then plug it into audacity(mic) for further modification, or you can roll your own. > -- > > > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From bungiman at gmail.com Tue Jan 29 11:45:18 2013 From: bungiman at gmail.com (Ben) Date: Tue, 29 Jan 2013 08:45:18 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> This may not be too helpful, but I built a TCP server into the Mixxx application (in C++). I placed the server in ratecontroller (as I needed to vary the rate remotely). I then could send and receive TCP packets with a single board computer that ran a python client. It wasn't too bad. If you want I can see if I can release the server code. On Tuesday, January 29, 2013 11:19:34 AM UTC-5, David Hutto wrote: > On Tue, Jan 29, 2013 at 11:16 AM, David Hutto wrote: > > >>>> Does anyone know if there are python bindings, or if this is possible at all? > > >>>> or does anyone have experience with another software that does the same DJ thing? > > >>>> > > >> > > >>Hydrogen, and audacity work perfectly together. > > > > > > > > What I was about to do is take the output to the headphones, get the > > soundtrack/beat to the > > song going, and then plug it into audacity(mic) for further modification, > > or you can roll your own. > > > > > -- > > > > > > > > > Best Regards, > > > David Hutto > > > CEO: http://www.hitwebdevelopment.com > > > > > > > > -- > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com From bungiman at gmail.com Tue Jan 29 11:45:18 2013 From: bungiman at gmail.com (Ben) Date: Tue, 29 Jan 2013 08:45:18 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> This may not be too helpful, but I built a TCP server into the Mixxx application (in C++). I placed the server in ratecontroller (as I needed to vary the rate remotely). I then could send and receive TCP packets with a single board computer that ran a python client. It wasn't too bad. If you want I can see if I can release the server code. On Tuesday, January 29, 2013 11:19:34 AM UTC-5, David Hutto wrote: > On Tue, Jan 29, 2013 at 11:16 AM, David Hutto wrote: > > >>>> Does anyone know if there are python bindings, or if this is possible at all? > > >>>> or does anyone have experience with another software that does the same DJ thing? > > >>>> > > >> > > >>Hydrogen, and audacity work perfectly together. > > > > > > > > What I was about to do is take the output to the headphones, get the > > soundtrack/beat to the > > song going, and then plug it into audacity(mic) for further modification, > > or you can roll your own. > > > > > -- > > > > > > > > > Best Regards, > > > David Hutto > > > CEO: http://www.hitwebdevelopment.com > > > > > > > > -- > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Jan 29 11:58:05 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 11:58:05 -0500 Subject: Mixxx DJ app and Python In-Reply-To: <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> Message-ID: On Tue, Jan 29, 2013 at 11:45 AM, Ben wrote: > This may not be too helpful, but I built a TCP server into the Mixxx application (in C++). I placed the server in ratecontroller (as I needed to vary the rate remotely). I then could send and receive TCP packets with a single board computer that ran a python client. > > So you used a digital buffer region for your wave forms? How did you handle the rest of the data; allocate memory, or delete if the data became too lengthy? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From mikprog at gmail.com Tue Jan 29 12:05:05 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Tue, 29 Jan 2013 09:05:05 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> Message-ID: <759fe48d-c4c6-4a38-b9b5-7c9c09bd665d@googlegroups.com> On Tuesday, January 29, 2013 4:45:18 PM UTC, Ben wrote: > This may not be too helpful, but I built a TCP server into the Mixxx application (in C++). I placed the server in ratecontroller (as I needed to vary the rate remotely). I then could send and receive TCP packets with a single board computer that ran a python client. Hi Ben, this would be actually interesting to look at. If you are not going to face problems, please send me the code. Thanks, Mik From mikprog at gmail.com Tue Jan 29 12:05:05 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Tue, 29 Jan 2013 09:05:05 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> <56bf9051-9727-4485-9a97-74590426ef2d@googlegroups.com> Message-ID: <759fe48d-c4c6-4a38-b9b5-7c9c09bd665d@googlegroups.com> On Tuesday, January 29, 2013 4:45:18 PM UTC, Ben wrote: > This may not be too helpful, but I built a TCP server into the Mixxx application (in C++). I placed the server in ratecontroller (as I needed to vary the rate remotely). I then could send and receive TCP packets with a single board computer that ran a python client. Hi Ben, this would be actually interesting to look at. If you are not going to face problems, please send me the code. Thanks, Mik From mikprog at gmail.com Tue Jan 29 11:18:15 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Tue, 29 Jan 2013 08:18:15 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Tuesday, January 29, 2013 4:13:09 PM UTC, David Hutto wrote: [..] > > >> or does anyone have experience with another software that does the same DJ thing? > > > > > Hydrogen, and audacity work perfectly together. Hi David, thanks for your reply. I am not sure though that this is going to help me. We have built a kind of basic controller that sends commands via bluetooth. Then I should have some device (like a linux pc or raspberry Pi) where I have my applications that listen for these bluetooth commands and drives a DJ application accordingly (like mixing two sounds, sync them etc). Obviously to write the whole application will take ages and I saw that the Mixxx one does everything I want. So I am searching for a way to interface to it programatically. Do you mean that Hydrogen and Audacity would replace the Mixxx app and I can call their functionality from Python? Or were you thinking about something else? Thanks, Mik From dwightdhutto at gmail.com Tue Jan 29 11:42:07 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 11:42:07 -0500 Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Tue, Jan 29, 2013 at 11:18 AM, wrote: > On Tuesday, January 29, 2013 4:13:09 PM UTC, David Hutto wrote: > [..] >> >> >> or does anyone have experience with another software that does the same DJ thing? >> >> >> >> >> Hydrogen, and audacity work perfectly together. > > > Hi David, > thanks for your reply. > I am not sure though that this is going to help me. > We have built a kind of basic controller that sends commands via bluetooth. > Then I should have some device (like a linux pc or raspberry Pi) where I have my applications that listen for these bluetooth commands and drives a DJ application accordingly (like mixing two sounds, sync them etc). > > Obviously to write the whole application will take ages and I saw that the Mixxx one does everything I want. > So I am searching for a way to interface to it programatically. Well you can just use their(Mixx's) source code that they used from another wav form manipulation library(more than likely), after the trigger from the bluetooth. If you're talking voice, and music to sync, then either go with transmitting at the same, or take two receivers(one for each transmitter), and run them in unison on different frequencies, after they've been received.. I've never tried this, but it seems logical. > > Do you mean that Hydrogen and Audacity would replace the Mixxx app and I can call their functionality from Python? > Or were you thinking about something else? > > Thanks, > Mik > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From mikprog at gmail.com Tue Jan 29 11:18:15 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Tue, 29 Jan 2013 08:18:15 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Tuesday, January 29, 2013 4:13:09 PM UTC, David Hutto wrote: [..] > > >> or does anyone have experience with another software that does the same DJ thing? > > > > > Hydrogen, and audacity work perfectly together. Hi David, thanks for your reply. I am not sure though that this is going to help me. We have built a kind of basic controller that sends commands via bluetooth. Then I should have some device (like a linux pc or raspberry Pi) where I have my applications that listen for these bluetooth commands and drives a DJ application accordingly (like mixing two sounds, sync them etc). Obviously to write the whole application will take ages and I saw that the Mixxx one does everything I want. So I am searching for a way to interface to it programatically. Do you mean that Hydrogen and Audacity would replace the Mixxx app and I can call their functionality from Python? Or were you thinking about something else? Thanks, Mik From mikprog at gmail.com Tue Jan 29 12:10:00 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Tue, 29 Jan 2013 09:10:00 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Tuesday, January 29, 2013 4:42:07 PM UTC, David Hutto wrote: [..] > > Well you can just use their(Mixx's) source code that they used from > > another wav form manipulation library(more than likely), after the > > trigger from the bluetooth. If you're talking voice, and music to > > sync, then either go with transmitting at the same, or take two > > receivers(one for each transmitter), and run them in unison on > > different frequencies, after they've been received.. > > > > I've never tried this, but it seems logical. > Thanks David. It seems that the code is in C++ so I should write Python wrappers myself, which could be interesting, but given the time frame I have is just not possible, Pity :-( However I was not going to transmit sounds, but just commands to mix the sounds that are already in the same machine were the Mixxx is going to run. I hope I will have time to come back to it in future. Thanks. Mik From mikprog at gmail.com Tue Jan 29 12:10:00 2013 From: mikprog at gmail.com (mikprog at gmail.com) Date: Tue, 29 Jan 2013 09:10:00 -0800 (PST) Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: On Tuesday, January 29, 2013 4:42:07 PM UTC, David Hutto wrote: [..] > > Well you can just use their(Mixx's) source code that they used from > > another wav form manipulation library(more than likely), after the > > trigger from the bluetooth. If you're talking voice, and music to > > sync, then either go with transmitting at the same, or take two > > receivers(one for each transmitter), and run them in unison on > > different frequencies, after they've been received.. > > > > I've never tried this, but it seems logical. > Thanks David. It seems that the code is in C++ so I should write Python wrappers myself, which could be interesting, but given the time frame I have is just not possible, Pity :-( However I was not going to transmit sounds, but just commands to mix the sounds that are already in the same machine were the Mixxx is going to run. I hope I will have time to come back to it in future. Thanks. Mik From dwightdhutto at gmail.com Tue Jan 29 12:26:39 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 12:26:39 -0500 Subject: Mixxx DJ app and Python In-Reply-To: References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: > Thanks David. > It seems that the code is in C++ so I should write Python wrappers myself, Or ctypes. which could be interesting, but given the time frame I have is just not possible, Pity :-( > However I was not going to transmit sounds, but just commands to mix the sounds that are already in the same machine were the Mixxx is going to run. A filter is minutia in comparison of code so it was always going to be a comand line app, with a python GUI, to perform alterations on the wave forms?. > I hope I will have time to come back to it in future. > Just a little practice, that makes every programmer listening scramble. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Tue Jan 29 22:43:16 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 29 Jan 2013 19:43:16 -0800 (PST) Subject: Mixxx DJ app and Python References: <15df6fe7-d419-44f0-85c2-a72eb1078fdd@googlegroups.com> Message-ID: <68d573a5-7898-4068-9bde-1f419ecb3a91@sk1g2000pbb.googlegroups.com> On Jan 29, 1:10?am, mikp... at gmail.com wrote: > I am thinking of driving a DJ application from Python. > I am running Linux and I found the Mixxx app. > Does anyone know if there are python bindings, or if this is possible at all? > or does anyone have experience with another software that does the same DJ thing? The simplest way I think would be to control Mixxx via midi, using something like pyPortMidi: http://alumni.media.mit.edu/~harrison/code.html If that doesn't give you the full range of control you're after, perhaps you could use ctypes to wrap Mixxx's code libraries? From nkolatsis at gmail.com Mon Jan 28 10:21:37 2013 From: nkolatsis at gmail.com (Nicholas Kolatsis) Date: Mon, 28 Jan 2013 07:21:37 -0800 (PST) Subject: I have issues installing pycrypto (and thus fabric) with pip Message-ID: I'm not sure this is the right place for this but I'm don't know where else to put this. I want to give fabric a try (as recommended here: http://www.jeffknupp.com/blog/2012/10/24/starting-a-django-14-project-the-right-way/). Installing fabric results in two dependencies (paramiko and pycrypto) being installed as well. All is dandy until it is time to install pycrypto. A bit of searching reveals this in the documentation: Package tools We strongly recommend using pip to install Fabric as it is newer and generally better than easy_install. However, a combination of bugs in specific versions of Python, pip and PyCrypto can prevent installation of PyCrypto. Specifically: Python = 2.5.x PyCrypto >= 2.1 (which is required to run Fabric >= 1.3) pip < 0.8.1 When all three criteria are met, you may encounter No such file or directory IOErrors when trying to pip install Fabric or pip install PyCrypto. The fix is simply to make sure at least one of the above criteria is not met, by doing the following (in order of preference): Upgrade to pip 0.8.1 or above, e.g. by running pip install -U pip. Upgrade to Python 2.6 or above. Downgrade to Fabric 1.2.x, which does not require PyCrypto >= 2.1, and install PyCrypto 2.0.1 (the oldest version on PyPI which works with Fabric 1.2.) (dp130128)cheeky at n5110:~/proj/dp130128$ yolk -l Django - 1.4.3 - active Python - 2.7.3 - active development (/usr/lib/python2.7/lib-dynload) <--check South - 0.7.6 - active argparse - 1.2.1 - active development (/usr/lib/python2.7) pip - 1.2.1 - active <--check setuptools - 0.6c11 - active wsgiref - 0.1.2 - active development (/usr/lib/python2.7) yolk - 0.4.3 - active I've got pip and python covered above but I'm still unable to install fabric as shown below. (dp130128)cheeky at n5110:~/proj/dp130128$ pip install fabric Downloading/unpacking fabric Running setup.py egg_info for package fabric warning: no previously-included files matching '*' found under directory 'docs/_build' warning: no previously-included files matching '*.pyc' found under directory 'tests' warning: no previously-included files matching '*.pyo' found under directory 'tests' Downloading/unpacking paramiko>=1.9.0 (from fabric) Running setup.py egg_info for package paramiko Downloading/unpacking pycrypto>=2.1,!=2.4 (from paramiko>=1.9.0->fabric) Running setup.py egg_info for package pycrypto Installing collected packages: fabric, paramiko, pycrypto Running setup.py install for fabric warning: no previously-included files matching '*' found under directory 'docs/_build' warning: no previously-included files matching '*.pyc' found under directory 'tests' warning: no previously-included files matching '*.pyo' found under directory 'tests' Installing fab script to /home/cheeky/.virtualenvs/dp130128/bin Running setup.py install for paramiko Running setup.py install for pycrypto warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Hash._MD2' extension gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-i686-2.7/src/MD2.o src/MD2.c:31:20: fatal error: Python.h: No such file or directory compilation terminated. error: command 'gcc' failed with exit status 1 Complete output from command /home/cheeky/.virtualenvs/dp130128/bin/python -c "import setuptools;__file__='/home/cheeky/.virtualenvs/dp130128/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-0X00No-record/install-record.txt --single-version-externally-managed --install-headers /home/cheeky/.virtualenvs/dp130128/include/site/python2.7: running install running build running build_py running build_ext running build_configure warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Hash._MD2' extension gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-i686-2.7/src/MD2.o src/MD2.c:31:20: fatal error: Python.h: No such file or directory compilation terminated. error: command 'gcc' failed with exit status 1 ---------------------------------------- Command /home/cheeky/.virtualenvs/dp130128/bin/python -c "import setuptools;__file__='/home/cheeky/.virtualenvs/dp130128/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-0X00No-record/install-record.txt --single-version-externally-managed --install-headers /home/cheeky/.virtualenvs/dp130128/include/site/python2.7 failed with error code 1 in /home/cheeky/.virtualenvs/dp130128/build/pycrypto Storing complete log in /home/cheeky/.pip/pip.log From kwpolska at gmail.com Mon Jan 28 12:13:12 2013 From: kwpolska at gmail.com (Kwpolska) Date: Mon, 28 Jan 2013 18:13:12 +0100 Subject: I have issues installing pycrypto (and thus fabric) with pip In-Reply-To: References: Message-ID: On Mon, Jan 28, 2013 at 4:21 PM, Nicholas Kolatsis wrote: > I'm not sure this is the right place for this It is > but I'm don't know where else to put this. Here. (s/I?m/I/) > I want to give fabric a try (as recommended here: http://www.jeffknupp.com/blog/2012/10/24/starting-a-django-14-project-the-right-way/). Installing fabric results in two dependencies (paramiko and pycrypto) being installed as well. All is dandy until it is time to install pycrypto. Note that Fabric is useful for much, MUCH more than this. > (dp130128)cheeky at n5110:~/proj/dp130128$ pip install fabric Off-topic: why is your virtualenv/project name so weird? > Downloading/unpacking fabric > Running setup.py egg_info for package fabric > > warning: no previously-included files matching '*' found under directory 'docs/_build' > warning: no previously-included files matching '*.pyc' found under directory 'tests' > warning: no previously-included files matching '*.pyo' found under directory 'tests' > Downloading/unpacking paramiko>=1.9.0 (from fabric) > Running setup.py egg_info for package paramiko > > Downloading/unpacking pycrypto>=2.1,!=2.4 (from paramiko>=1.9.0->fabric) > Running setup.py egg_info for package pycrypto > > Installing collected packages: fabric, paramiko, pycrypto > Running setup.py install for fabric > > warning: no previously-included files matching '*' found under directory 'docs/_build' > warning: no previously-included files matching '*.pyc' found under directory 'tests' > warning: no previously-included files matching '*.pyo' found under directory 'tests' > Installing fab script to /home/cheeky/.virtualenvs/dp130128/bin > Running setup.py install for paramiko > Seems to be properly installed. > Running setup.py install for pycrypto > warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. > building 'Crypto.Hash._MD2' extension > gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-i686-2.7/src/MD2.o > src/MD2.c:31:20: fatal error: Python.h: No such file or directory > compilation terminated. > error: command 'gcc' failed with exit status 1 Here comes your problem: you do not have the Python header files, required to compile the C code used by pycrypto (for speed in certain operations, because they are quite resource-intensive). Where can you get them? I don?t know, ask your distro. They are usually in a package ending with -dev or -devel (depending on your distro; human distros do not bother with this and ship them along with the rest of the thing?) -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From nkolatsis at gmail.com Tue Jan 29 11:18:21 2013 From: nkolatsis at gmail.com (Nicholas Kolatsis) Date: Tue, 29 Jan 2013 08:18:21 -0800 (PST) Subject: I have issues installing pycrypto (and thus fabric) with pip In-Reply-To: References: Message-ID: Thanks. I've gotten everything working now. For anyone else who comes along, 'sudo apt-get install python-dev' did the job. > > Note that Fabric is useful for much, MUCH more than this. > I look forward to finding out :) > > Off-topic: why is your virtualenv/project name so weird? > Noted. It's the naming pattern that I use for my projects. I should use something better but I'm using this because I usually restart something several times before I'm happy with it. I was reading up on branching with git earlier. It looks like that will put an end to this bad practice. From nkolatsis at gmail.com Tue Jan 29 11:18:21 2013 From: nkolatsis at gmail.com (Nicholas Kolatsis) Date: Tue, 29 Jan 2013 08:18:21 -0800 (PST) Subject: I have issues installing pycrypto (and thus fabric) with pip In-Reply-To: References: Message-ID: Thanks. I've gotten everything working now. For anyone else who comes along, 'sudo apt-get install python-dev' did the job. > > Note that Fabric is useful for much, MUCH more than this. > I look forward to finding out :) > > Off-topic: why is your virtualenv/project name so weird? > Noted. It's the naming pattern that I use for my projects. I should use something better but I'm using this because I usually restart something several times before I'm happy with it. I was reading up on branching with git earlier. It looks like that will put an end to this bad practice. From wanderer at dialup4less.com Mon Jan 28 10:47:46 2013 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 28 Jan 2013 07:47:46 -0800 (PST) Subject: WLAN tester Message-ID: I'm looking to make a WLAN tester for a manufacturing test. Something that could send and receive a bunch of files and measure how long it took. I would repeat this a number of times for a device under test and then use some metric to decide pass/fail and create a report. What libraries are available for Python for communicating with networks? My google searches have been disappointing. I'd prefer to do this in Windows but I'll consider Linux if that is the better option. Thanks From d at davea.name Mon Jan 28 11:30:47 2013 From: d at davea.name (Dave Angel) Date: Mon, 28 Jan 2013 11:30:47 -0500 Subject: WLAN tester In-Reply-To: References: Message-ID: <5106A7B7.3090007@davea.name> On 01/28/2013 10:47 AM, Wanderer wrote: > I'm looking to make a WLAN tester for a manufacturing test. Something that could send and receive a bunch of files and measure how long it took. I would repeat this a number of times for a device under test and then use some metric to decide pass/fail and create a report. What libraries are available for Python for communicating with networks? My google searches have been disappointing. I'd prefer to do this in Windows but I'll consider Linux if that is the better option. > > Thanks > For what version of Python? Depending on what's at the far end of your connection, you may not need to do much at all. For example, if you have an ftp server, check out http://docs.python.org/2/library/ftplib.html in the standard library. Since you're doing performance testing, be aware that it's quite tricky to get meaningful results. For example, some connections have a satellite link in them, and thus have very long latency. A simple protocol will go very slowly in such a case, but most downloaders will open multiple sockets, and do many transfers in parallel. So you could either measure the slow way or the fast way, and both numbers are meaningful. Of course, it's more than a 2-way choice. Some protocols will compress the data, send it, and decompress it on the other end. Others (like the one rsync uses) will evaluate both ends, and decide which (if any) files need to be transferred at all. I believe it also does partial file updates if possible, but I'm not at all sure about that. Naturally, the throughput will vary greatly from moment to moment, and may be affected by lots of things you cannot see. -- DaveA From wanderer at dialup4less.com Mon Jan 28 12:07:52 2013 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 28 Jan 2013 09:07:52 -0800 (PST) Subject: WLAN tester In-Reply-To: References: Message-ID: <1ae25a0e-c701-4ba3-8b9c-7cdde72e2a17@googlegroups.com> On Monday, January 28, 2013 11:30:47 AM UTC-5, Dave Angel wrote: > On 01/28/2013 10:47 AM, Wanderer wrote: > > > I'm looking to make a WLAN tester for a manufacturing test. Something that could send and receive a bunch of files and measure how long it took. I would repeat this a number of times for a device under test and then use some metric to decide pass/fail and create a report. What libraries are available for Python for communicating with networks? My google searches have been disappointing. I'd prefer to do this in Windows but I'll consider Linux if that is the better option. > > > > > > Thanks > > > > > For what version of Python? > > > > Depending on what's at the far end of your connection, you may not need > > to do much at all. For example, if you have an ftp server, check out > > http://docs.python.org/2/library/ftplib.html > > > > in the standard library. > > > > > > > > Since you're doing performance testing, be aware that it's quite tricky > > to get meaningful results. For example, some connections have a > > satellite link in them, and thus have very long latency. A simple > > protocol will go very slowly in such a case, but most downloaders will > > open multiple sockets, and do many transfers in parallel. So you could > > either measure the slow way or the fast way, and both numbers are > > meaningful. > > > > Of course, it's more than a 2-way choice. Some protocols will compress > > the data, send it, and decompress it on the other end. Others (like the > > one rsync uses) will evaluate both ends, and decide which (if any) files > > need to be transferred at all. I believe it also does partial file > > updates if possible, but I'm not at all sure about that. > > > > Naturally, the throughput will vary greatly from moment to moment, and > > may be affected by lots of things you cannot see. > > > > -- > > DaveA Yes. I noticed this variability. I've been using the Totusoft Lan_Speedtest.exe to test some modules. I've tested through the wifi to our intranet and saw variations I believe do to network traffic. I also tried peer to peer and the write time actual got worse. I don't know if it has do to with the firewall or the hard drive speed or just Windows giving this process low priority. I also saw drop outs. So figuring out the metric for pass/fail will be interesting. I'll check into setting an ftp for this test. Thanks From wanderer at dialup4less.com Mon Jan 28 12:07:52 2013 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 28 Jan 2013 09:07:52 -0800 (PST) Subject: WLAN tester In-Reply-To: References: Message-ID: <1ae25a0e-c701-4ba3-8b9c-7cdde72e2a17@googlegroups.com> On Monday, January 28, 2013 11:30:47 AM UTC-5, Dave Angel wrote: > On 01/28/2013 10:47 AM, Wanderer wrote: > > > I'm looking to make a WLAN tester for a manufacturing test. Something that could send and receive a bunch of files and measure how long it took. I would repeat this a number of times for a device under test and then use some metric to decide pass/fail and create a report. What libraries are available for Python for communicating with networks? My google searches have been disappointing. I'd prefer to do this in Windows but I'll consider Linux if that is the better option. > > > > > > Thanks > > > > > For what version of Python? > > > > Depending on what's at the far end of your connection, you may not need > > to do much at all. For example, if you have an ftp server, check out > > http://docs.python.org/2/library/ftplib.html > > > > in the standard library. > > > > > > > > Since you're doing performance testing, be aware that it's quite tricky > > to get meaningful results. For example, some connections have a > > satellite link in them, and thus have very long latency. A simple > > protocol will go very slowly in such a case, but most downloaders will > > open multiple sockets, and do many transfers in parallel. So you could > > either measure the slow way or the fast way, and both numbers are > > meaningful. > > > > Of course, it's more than a 2-way choice. Some protocols will compress > > the data, send it, and decompress it on the other end. Others (like the > > one rsync uses) will evaluate both ends, and decide which (if any) files > > need to be transferred at all. I believe it also does partial file > > updates if possible, but I'm not at all sure about that. > > > > Naturally, the throughput will vary greatly from moment to moment, and > > may be affected by lots of things you cannot see. > > > > -- > > DaveA Yes. I noticed this variability. I've been using the Totusoft Lan_Speedtest.exe to test some modules. I've tested through the wifi to our intranet and saw variations I believe do to network traffic. I also tried peer to peer and the write time actual got worse. I don't know if it has do to with the firewall or the hard drive speed or just Windows giving this process low priority. I also saw drop outs. So figuring out the metric for pass/fail will be interesting. I'll check into setting an ftp for this test. Thanks From robert.day at merton.oxon.org Mon Jan 28 12:32:50 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Mon, 28 Jan 2013 17:32:50 +0000 Subject: WLAN tester In-Reply-To: <1ae25a0e-c701-4ba3-8b9c-7cdde72e2a17@googlegroups.com> References: <1ae25a0e-c701-4ba3-8b9c-7cdde72e2a17@googlegroups.com> Message-ID: On 28 January 2013 17:07, Wanderer wrote: > Yes. I noticed this variability. I've been using the Totusoft Lan_Speedtest.exe to test some modules. I've tested through the wifi to our intranet and saw variations I believe do to network traffic. I also tried peer to peer and the write time actual got worse. I don't know if it has do to with the firewall or the hard drive speed or just Windows giving this process low priority. I also saw drop outs. So figuring out the metric for pass/fail will be interesting. I'll check into setting an ftp for this test. Why involve a protocol at all? I'd just create a socket (http://docs.python.org/3.3/library/socket.html) and measure how long, on average, it took to write a given number of arbitrary bytes (e.g. "This is a string" repeated a million times) to it and then read a given number of bytes back. That would be a relatively consistent metric, whereas if you try using FTP you'll run into issues, as already noted, where disk read/write speed and details of your FTP server implementation like compression or multiple network connections affect the result significantly. -- Robert K. Day robert.day at merton.oxon.org From wanderer at dialup4less.com Mon Jan 28 17:33:06 2013 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 28 Jan 2013 14:33:06 -0800 (PST) Subject: WLAN tester In-Reply-To: References: <1ae25a0e-c701-4ba3-8b9c-7cdde72e2a17@googlegroups.com> Message-ID: <9824f533-f7a5-4c1b-a4fd-93af225ef53e@googlegroups.com> On Monday, January 28, 2013 12:32:50 PM UTC-5, Rob Day wrote: > On 28 January 2013 17:07, Wanderer wrote: > > > Yes. I noticed this variability. I've been using the Totusoft Lan_Speedtest.exe to test some modules. I've tested through the wifi to our intranet and saw variations I believe do to network traffic. I also tried peer to peer and the write time actual got worse. I don't know if it has do to with the firewall or the hard drive speed or just Windows giving this process low priority. I also saw drop outs. So figuring out the metric for pass/fail will be interesting. I'll check into setting an ftp for this test. > > > > Why involve a protocol at all? I'd just create a socket > > (http://docs.python.org/3.3/library/socket.html) and measure how long, > > on average, it took to write a given number of arbitrary bytes (e.g. > > "This is a string" repeated a million times) to it and then read a > > given number of bytes back. That would be a relatively consistent > > metric, whereas if you try using FTP you'll run into issues, as > > already noted, where disk read/write speed and details of your FTP > > server implementation like compression or multiple network connections > > affect the result significantly. > > > > -- > > Robert K. Day > > Thanks, I'll check out sockets. That's probably what I needed to search for instead WLAN and Wi-Fi. From wanderer at dialup4less.com Mon Jan 28 17:33:06 2013 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 28 Jan 2013 14:33:06 -0800 (PST) Subject: WLAN tester In-Reply-To: References: <1ae25a0e-c701-4ba3-8b9c-7cdde72e2a17@googlegroups.com> Message-ID: <9824f533-f7a5-4c1b-a4fd-93af225ef53e@googlegroups.com> On Monday, January 28, 2013 12:32:50 PM UTC-5, Rob Day wrote: > On 28 January 2013 17:07, Wanderer wrote: > > > Yes. I noticed this variability. I've been using the Totusoft Lan_Speedtest.exe to test some modules. I've tested through the wifi to our intranet and saw variations I believe do to network traffic. I also tried peer to peer and the write time actual got worse. I don't know if it has do to with the firewall or the hard drive speed or just Windows giving this process low priority. I also saw drop outs. So figuring out the metric for pass/fail will be interesting. I'll check into setting an ftp for this test. > > > > Why involve a protocol at all? I'd just create a socket > > (http://docs.python.org/3.3/library/socket.html) and measure how long, > > on average, it took to write a given number of arbitrary bytes (e.g. > > "This is a string" repeated a million times) to it and then read a > > given number of bytes back. That would be a relatively consistent > > metric, whereas if you try using FTP you'll run into issues, as > > already noted, where disk read/write speed and details of your FTP > > server implementation like compression or multiple network connections > > affect the result significantly. > > > > -- > > Robert K. Day > > Thanks, I'll check out sockets. That's probably what I needed to search for instead WLAN and Wi-Fi. From theo.england at skillsmatter.com Mon Jan 28 12:40:31 2013 From: theo.england at skillsmatter.com (Theo) Date: Mon, 28 Jan 2013 09:40:31 -0800 (PST) Subject: =?windows-1252?Q?The_London_Python_Group=3ASwitch_to_Python_3=85_Now=85?= =?windows-1252?Q?_Immediately_=2D_February_12th?= Message-ID: <35eecce4-5e62-4d74-ad33-9f7b5ebad715@googlegroups.com> Russel Winder gives numerous reasons why now is the time for you to switch to Python 3 RIGHT NOW! With Python 3.2 and even more with Python 3.3, Python 3 became usable for release products. Indeed given the things that are in Python 3 that are not being back-ported to Python 2, using Python 3 should probably be considered mandatory for all Python use. Certainly for new projects, and 2 ? 3 ports for all extant codes. In this session we will investigate some of the issues, especially those relating to handling of concurrency and parallelism, and in particular concurrent.futures. Some material on CSP will almost certainly creep into the session. Sign up for the free evening event here - http://skillsmatter.com/podcast/java-jee/switch-to-python-3-now-immediately From r.vrajmohan at gmail.com Mon Jan 28 16:31:27 2013 From: r.vrajmohan at gmail.com (Vraj Mohan) Date: Mon, 28 Jan 2013 16:31:27 -0500 Subject: pip and distutils Message-ID: I have created a source distribution using distutils which specifies external packages using: setup( ..., requires = ['Foo (>= 0.7)', 'Bar (>= 2.4.5)'], ... ) When I use pip to install this distribution, I find that it does not automatically install the packages Foo and Bar. What extra step do I need to perform to have pip automatically install the "required" packages? I am using Python 3.2.3. --Vraj From saturnhs at gmail.com Mon Jan 28 17:46:00 2013 From: saturnhs at gmail.com (Malcolm McCrimmon) Date: Mon, 28 Jan 2013 14:46:00 -0800 (PST) Subject: Further evidence that Python may be the best language forever Message-ID: <7b3df03f-c917-4b57-a9a1-d9d6fee15a5e@googlegroups.com> My company recently hosted a programming competition for schools across the country. One team made it to the finals using the Python client, one of the four default clients provided (I wrote it). Most of the other teams were using Java or C#. Guess which team won? http://www.windward.net/codewar/2013_01/finals.html From torriem at gmail.com Mon Jan 28 20:15:17 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 28 Jan 2013 18:15:17 -0700 Subject: Further evidence that Python may be the best language forever In-Reply-To: <7b3df03f-c917-4b57-a9a1-d9d6fee15a5e@googlegroups.com> References: <7b3df03f-c917-4b57-a9a1-d9d6fee15a5e@googlegroups.com> Message-ID: <510722A5.6020101@gmail.com> On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote: > My company recently hosted a programming competition for schools > across the country. One team made it to the finals using the Python > client, one of the four default clients provided (I wrote it). Most > of the other teams were using Java or C#. Guess which team won? > > http://www.windward.net/codewar/2013_01/finals.html What language was the web page hosted in? It comes up completely blank for me. :) From stefan_ml at behnel.de Tue Jan 29 01:59:39 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 29 Jan 2013 07:59:39 +0100 Subject: Further evidence that Python may be the best language forever In-Reply-To: <510722A5.6020101@gmail.com> References: <7b3df03f-c917-4b57-a9a1-d9d6fee15a5e@googlegroups.com> <510722A5.6020101@gmail.com> Message-ID: Michael Torrie, 29.01.2013 02:15: > On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote: >> My company recently hosted a programming competition for schools >> across the country. One team made it to the finals using the Python >> client, one of the four default clients provided (I wrote it). Most >> of the other teams were using Java or C#. Guess which team won? >> >> http://www.windward.net/codewar/2013_01/finals.html We did a similar (although way smaller) contest once at a university. The task was to write a network simulator. We had a C team, a Java team and a Python team, four people each. The Java and C people knew their language, the Python team just started learning it. The C team ended up getting totally lost and failed. The Java team got most things working ok and passed. The Python team got everything working, but additionally implemented a web interface for the simulator that monitored and visualised its current state. They said it helped them with debugging. > What language was the web page hosted in? It comes up completely blank > for me. :) Yep, same here. Hidden behind a flash wall, it seems. Stefan From michael.poeltl at univie.ac.at Tue Jan 29 05:31:05 2013 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Tue, 29 Jan 2013 11:31:05 +0100 Subject: Further evidence that Python may be the best language forever In-Reply-To: References: <7b3df03f-c917-4b57-a9a1-d9d6fee15a5e@googlegroups.com> <510722A5.6020101@gmail.com> Message-ID: <20130129103105.GC11574@terra.cms.at> hi Stefan, * Stefan Behnel [2013-01-29 08:00]: > Michael Torrie, 29.01.2013 02:15: > > On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote: > >> My company recently hosted a programming competition for schools > >> across the country. One team made it to the finals using the Python > >> client, one of the four default clients provided (I wrote it). Most > >> of the other teams were using Java or C#. Guess which team won? > >> > >> http://www.windward.net/codewar/2013_01/finals.html > > We did a similar (although way smaller) contest once at a university. The > task was to write a network simulator. We had a C team, a Java team and a > Python team, four people each. The Java and C people knew their language, > the Python team just started learning it. > > The C team ended up getting totally lost and failed. The Java team got most > things working ok and passed. The Python team got everything working, but > additionally implemented a web interface for the simulator that monitored > and visualised its current state. They said it helped them with debugging. quite interesting! I'd liked to see the code is it available for 'download'? thx Michael > > > > What language was the web page hosted in? It comes up completely blank > > for me. :) > > Yep, same here. Hidden behind a flash wall, it seems. > > Stefan > > > -- > http://mail.python.org/mailman/listinfo/python-list -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From saturnhs at gmail.com Tue Jan 29 12:37:23 2013 From: saturnhs at gmail.com (Malcolm McCrimmon) Date: Tue, 29 Jan 2013 09:37:23 -0800 (PST) Subject: Further evidence that Python may be the best language forever In-Reply-To: References: <7b3df03f-c917-4b57-a9a1-d9d6fee15a5e@googlegroups.com> <510722A5.6020101@gmail.com> Message-ID: <2e33d6f2-5ade-497f-9873-cbd4e4e87799@googlegroups.com> Sure! I don't think we've publicly posted the teams' implementations, but the original client code is all up here--http://www.windward.net/codewar/2013_01/windwardopolis.php The issue with the original link may be if you're running Firefox--it's a Vimeo video, and I know they have some ongoing issues with Firefox that prevent their videos from displaying or playing back. On Tuesday, January 29, 2013 3:31:05 AM UTC-7, Michael Poeltl wrote: > hi Stefan, > > > > * Stefan Behnel [2013-01-29 08:00]: > > > Michael Torrie, 29.01.2013 02:15: > > > > On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote: > > > >> My company recently hosted a programming competition for schools > > > >> across the country. One team made it to the finals using the Python > > > >> client, one of the four default clients provided (I wrote it). Most > > > >> of the other teams were using Java or C#. Guess which team won? > > > >> > > > >> http://www.windward.net/codewar/2013_01/finals.html > > > > > > We did a similar (although way smaller) contest once at a university. The > > > task was to write a network simulator. We had a C team, a Java team and a > > > Python team, four people each. The Java and C people knew their language, > > > the Python team just started learning it. > > > > > > The C team ended up getting totally lost and failed. The Java team got most > > > things working ok and passed. The Python team got everything working, but > > > additionally implemented a web interface for the simulator that monitored > > > and visualised its current state. They said it helped them with debugging. > > quite interesting! > > I'd liked to see the code > > is it available for 'download'? > > > > thx > > Michael > > > > > > > > > > What language was the web page hosted in? It comes up completely blank > > > > for me. :) > > > > > > Yep, same here. Hidden behind a flash wall, it seems. > > > > > > Stefan > > > > > > > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > -- > > Michael Poeltl > > Computational Materials Physics voice: +43-1-4277-51409 > > Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) > > A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at > > ------------------------------------------------------------------------------- > > slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12 > > ------------------------------------------------------------------------------- From saturnhs at gmail.com Tue Jan 29 12:37:23 2013 From: saturnhs at gmail.com (Malcolm McCrimmon) Date: Tue, 29 Jan 2013 09:37:23 -0800 (PST) Subject: Further evidence that Python may be the best language forever In-Reply-To: References: <7b3df03f-c917-4b57-a9a1-d9d6fee15a5e@googlegroups.com> <510722A5.6020101@gmail.com> Message-ID: <2e33d6f2-5ade-497f-9873-cbd4e4e87799@googlegroups.com> Sure! I don't think we've publicly posted the teams' implementations, but the original client code is all up here--http://www.windward.net/codewar/2013_01/windwardopolis.php The issue with the original link may be if you're running Firefox--it's a Vimeo video, and I know they have some ongoing issues with Firefox that prevent their videos from displaying or playing back. On Tuesday, January 29, 2013 3:31:05 AM UTC-7, Michael Poeltl wrote: > hi Stefan, > > > > * Stefan Behnel [2013-01-29 08:00]: > > > Michael Torrie, 29.01.2013 02:15: > > > > On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote: > > > >> My company recently hosted a programming competition for schools > > > >> across the country. One team made it to the finals using the Python > > > >> client, one of the four default clients provided (I wrote it). Most > > > >> of the other teams were using Java or C#. Guess which team won? > > > >> > > > >> http://www.windward.net/codewar/2013_01/finals.html > > > > > > We did a similar (although way smaller) contest once at a university. The > > > task was to write a network simulator. We had a C team, a Java team and a > > > Python team, four people each. The Java and C people knew their language, > > > the Python team just started learning it. > > > > > > The C team ended up getting totally lost and failed. The Java team got most > > > things working ok and passed. The Python team got everything working, but > > > additionally implemented a web interface for the simulator that monitored > > > and visualised its current state. They said it helped them with debugging. > > quite interesting! > > I'd liked to see the code > > is it available for 'download'? > > > > thx > > Michael > > > > > > > > > > What language was the web page hosted in? It comes up completely blank > > > > for me. :) > > > > > > Yep, same here. Hidden behind a flash wall, it seems. > > > > > > Stefan > > > > > > > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > -- > > Michael Poeltl > > Computational Materials Physics voice: +43-1-4277-51409 > > Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) > > A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at > > ------------------------------------------------------------------------------- > > slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12 > > ------------------------------------------------------------------------------- From redstone-cold at 163.com Mon Jan 28 21:09:23 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 28 Jan 2013 18:09:23 -0800 (PST) Subject: what is the difference between commenting and uncommenting the __init__ method in this class? Message-ID: <0a5c1e54-4113-4f88-b249-8a4e3e05d303@googlegroups.com> what is the difference between commenting and uncommenting the __init__ method in this class? class CounterList(list): counter = 0 ## def __init__(self, *args): ## super(CounterList, self).__init__(*args) def __getitem__(self, index): self.__class__.counter += 1 return super(CounterList, self).__getitem__(index) From davea at davea.name Mon Jan 28 21:19:50 2013 From: davea at davea.name (Dave Angel) Date: Mon, 28 Jan 2013 21:19:50 -0500 Subject: what is the difference between commenting and uncommenting the __init__ method in this class? In-Reply-To: <0a5c1e54-4113-4f88-b249-8a4e3e05d303@googlegroups.com> References: <0a5c1e54-4113-4f88-b249-8a4e3e05d303@googlegroups.com> Message-ID: <510731C6.4050404@davea.name> On 01/28/2013 09:09 PM, iMath wrote: > what is the difference between commenting and uncommenting the __init__ method in this class? > > > class CounterList(list): > counter = 0 > > ## def __init__(self, *args): > ## super(CounterList, self).__init__(*args) > > def __getitem__(self, index): > > self.__class__.counter += 1 > return super(CounterList, self).__getitem__(index) > If you don't call the super-class' __init__() method, then the list won't take anyparameters. So the list will be empty, -- DaveA From msirenef at lightbird.net Mon Jan 28 22:00:00 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 28 Jan 2013 22:00:00 -0500 Subject: what is the difference between commenting and uncommenting the __init__ method in this class? In-Reply-To: <0a5c1e54-4113-4f88-b249-8a4e3e05d303@googlegroups.com> References: <0a5c1e54-4113-4f88-b249-8a4e3e05d303@googlegroups.com> Message-ID: <51073B30.4080308@lightbird.net> On 01/28/2013 09:09 PM, iMath wrote: > what is the difference between commenting and uncommenting the __init__ method in this class? > > > class CounterList(list): > counter = 0 > > ## def __init__(self, *args): > ## super(CounterList, self).__init__(*args) > > def __getitem__(self, index): > > self.__class__.counter += 1 > return super(CounterList, self).__getitem__(index) > No difference as this code doesn't do anything else in the __init__() it overrides. Normally you would add some additional processing there but if you don't need to, there is no reason to override __init__(), therefore it's clearer and better to delete those 2 lines. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ It is always pleasant to be urged to do something on the ground that one can do it well. George Santayana From ngcbmy at gmail.com Tue Jan 29 03:41:54 2013 From: ngcbmy at gmail.com (C. Ng) Date: Tue, 29 Jan 2013 00:41:54 -0800 (PST) Subject: numpy array operation Message-ID: Is there a numpy operation that does the following to the array? 1 2 ==> 4 3 3 4 2 1 Thanks in advance. From __peter__ at web.de Tue Jan 29 04:28:02 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 29 Jan 2013 10:28:02 +0100 Subject: numpy array operation References: Message-ID: C. Ng wrote: > Is there a numpy operation that does the following to the array? > > 1 2 ==> 4 3 > 3 4 2 1 How about >>> a array([[1, 2], [3, 4]]) >>> a[::-1].transpose()[::-1].transpose() array([[4, 3], [2, 1]]) Or did you mean >>> a.reshape((4,))[::-1].reshape((2,2)) array([[4, 3], [2, 1]]) Or even >>> -a + 5 array([[4, 3], [2, 1]]) From tjandacw at cox.net Tue Jan 29 07:59:43 2013 From: tjandacw at cox.net (Tim Williams) Date: Tue, 29 Jan 2013 04:59:43 -0800 (PST) Subject: numpy array operation In-Reply-To: References: Message-ID: <3111692c-2341-4c6d-9bea-35d6167a0c94@googlegroups.com> On Tuesday, January 29, 2013 3:41:54 AM UTC-5, C. Ng wrote: > Is there a numpy operation that does the following to the array? > > > > 1 2 ==> 4 3 > > 3 4 2 1 > > > > Thanks in advance. >>> import numpy as np >>> a=np.array([[1,2],[3,4]]) >>> a array([[1, 2], [3, 4]]) >>> np.fliplr(np.flipud(a)) array([[4, 3], [2, 1]]) From as8ca at virginia.edu Tue Jan 29 13:49:24 2013 From: as8ca at virginia.edu (Alok Singhal) Date: Tue, 29 Jan 2013 18:49:24 +0000 (UTC) Subject: numpy array operation References: Message-ID: On Tue, 29 Jan 2013 00:41:54 -0800, C. Ng wrote: > Is there a numpy operation that does the following to the array? > > 1 2 ==> 4 3 > 3 4 2 1 > > Thanks in advance. How about: >>> import numpy as np >>> a = np.array([[1,2],[3,4]]) >>> a array([[1, 2], [3, 4]]) >>> a[::-1, ::-1] array([[4, 3], [2, 1]]) From tjreedy at udel.edu Tue Jan 29 15:05:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 29 Jan 2013 15:05:09 -0500 Subject: numpy array operation In-Reply-To: References: Message-ID: On 1/29/2013 1:49 PM, Alok Singhal wrote: > On Tue, 29 Jan 2013 00:41:54 -0800, C. Ng wrote: > >> Is there a numpy operation that does the following to the array? >> >> 1 2 ==> 4 3 >> 3 4 2 1 >> >> Thanks in advance. > > How about: > >>>> import numpy as np >>>> a = np.array([[1,2],[3,4]]) >>>> a > array([[1, 2], [3, 4]]) >>>> a[::-1, ::-1] > array([[4, 3], [2, 1]]) > Nice. The regular Python equivalent is a = [[1,2],[3,4]] print([row[::-1] for row in a[::-1]]) >>> [[4, 3], [2, 1]] The second slice can be replaced with reversed(a), which returns an iterator, to get [row[::-1] for row in reversed(a)] The first slice would have to be list(reversed(a)) to get the same result. -- Terry Jan Reedy From jabba.laci at gmail.com Tue Jan 29 08:18:01 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 29 Jan 2013 14:18:01 +0100 Subject: environment fingerprint Message-ID: Hi, I have a script that I want to run in different environments: on Linux, on Windows, on my home machine, at my workplace, in virtualbox, etc. In each environment I want to use different configurations. For instance the temp. directory on Linux would be /tmp, on Windows c:\temp, etc. When the script starts, I want to test the environment and load the corresponding config. settings. How to get an OS-independent fingerprint of the environment? Thanks, Laszlo From bahamutzero8825 at gmail.com Tue Jan 29 08:43:55 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 29 Jan 2013 07:43:55 -0600 Subject: environment fingerprint In-Reply-To: References: Message-ID: <5107D21B.8050305@gmail.com> On 2013.01.29 07:18, Jabba Laci wrote: > Hi, > > I have a script that I want to run in different environments: on > Linux, on Windows, on my home machine, at my workplace, in virtualbox, > etc. In each environment I want to use different configurations. For > instance the temp. directory on Linux would be /tmp, on Windows > c:\temp, etc. When the script starts, I want to test the environment > and load the corresponding config. settings. How to get an > OS-independent fingerprint of the environment? http://docs.python.org/3.3/library/platform.html http://docs.python.org/3.3/library/os.html#os.environ -- CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE From jabba.laci at gmail.com Tue Jan 29 18:33:12 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 30 Jan 2013 00:33:12 +0100 Subject: environment fingerprint In-Reply-To: <5107D21B.8050305@gmail.com> References: <5107D21B.8050305@gmail.com> Message-ID: Hi, Thanks for the tip. I came up with the solution below. For my purposes the short fingerprint is enough. Laszlo ====== import platform as p import uuid import hashlib def get_fingerprint(md5=False): """ Fingerprint of the current operating system/platform. If md5 is True, a digital fingerprint is returned. """ sb = [] sb.append(p.node()) sb.append(p.architecture()[0]) sb.append(p.architecture()[1]) sb.append(p.machine()) sb.append(p.processor()) sb.append(p.system()) sb.append(str(uuid.getnode())) # MAC address text = '#'.join(sb) if md5: md5 = hashlib.md5() md5.update(text) return md5.hexdigest() else: return text def get_short_fingerprint(length=6): """ A short digital fingerprint of the current operating system/platform. Length should be at least 6 characters. """ assert 6 <= length <= 32 # return get_fingerprint(md5=True)[-length:] On Tue, Jan 29, 2013 at 2:43 PM, Andrew Berg wrote: > On 2013.01.29 07:18, Jabba Laci wrote: >> Hi, >> >> I have a script that I want to run in different environments: on >> Linux, on Windows, on my home machine, at my workplace, in virtualbox, >> etc. In each environment I want to use different configurations. For >> instance the temp. directory on Linux would be /tmp, on Windows >> c:\temp, etc. When the script starts, I want to test the environment >> and load the corresponding config. settings. How to get an >> OS-independent fingerprint of the environment? > http://docs.python.org/3.3/library/platform.html > http://docs.python.org/3.3/library/os.html#os.environ > > -- > CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jan 29 19:18:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jan 2013 11:18:41 +1100 Subject: environment fingerprint In-Reply-To: References: <5107D21B.8050305@gmail.com> Message-ID: On Wed, Jan 30, 2013 at 10:33 AM, Jabba Laci wrote: > if md5: > md5 = hashlib.md5() > md5.update(text) > return md5.hexdigest() Simpler: if md5: return hashlib.md5(text).hexdigest() ChrisA From redstone-cold at 163.com Tue Jan 29 08:21:16 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 29 Jan 2013 05:21:16 -0800 (PST) Subject: [os.path.join(r'E:\Python', name) for name in []] returns [] Message-ID: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> why [os.path.join(r'E:\Python', name) for name in []] returns [] ? please explain it in detail ? From rosuav at gmail.com Tue Jan 29 08:33:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jan 2013 00:33:06 +1100 Subject: [os.path.join(r'E:\Python', name) for name in []] returns [] In-Reply-To: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> References: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> Message-ID: On Wed, Jan 30, 2013 at 12:21 AM, iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? > please explain it in detail ? That's a list comprehension. If you're familiar with functional programming, it's like a map operation. Since the input list (near the end of the comprehension, just inside its square brackets) is empty, so is the result list, and os.path.join is never called. I've given you a massive oversimplification. The docs are here: http://docs.python.org/3.3/tutorial/datastructures.html#list-comprehensions Pro tip: The docs are there before you ask the question, too. You might find it faster to search them than to ask and wait for an answer :) ChrisA From steve+comp.lang.python at pearwood.info Tue Jan 29 08:33:26 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 30 Jan 2013 00:33:26 +1100 Subject: [os.path.join(r'E:\Python', name) for name in []] returns [] References: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> Message-ID: <5107cfa6$0$30002$c3e8da3$5496439d@news.astraweb.com> iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? Because you are iterating over an empty list, []. That list comprehension is the equivalent of: result = [] for name in []: result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an empty list, the body of the loop never executes, and the result list remains empty. What did you expect it to do? -- Steven From redstone-cold at 163.com Tue Jan 29 20:56:30 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 29 Jan 2013 17:56:30 -0800 (PST) Subject: [os.path.join(r'E:\Python', name) for name in []] returns [] In-Reply-To: <5107cfa6$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> <5107cfa6$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <81dbe6cb-714c-4396-aa69-b56855f19f8d@googlegroups.com> ? 2013?1?29????UTC+8??9?33?26??Steven D'Aprano??? > iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? Because you are iterating over an empty list, []. That list comprehension is the equivalent of: result = [] for name in []: result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an empty list, the body of the loop never executes, and the result list remains empty. What did you expect it to do? -- Steven just in order to get the full path name of each file . From rosuav at gmail.com Tue Jan 29 21:17:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jan 2013 13:17:03 +1100 Subject: [os.path.join(r'E:\Python', name) for name in []] returns [] In-Reply-To: <81dbe6cb-714c-4396-aa69-b56855f19f8d@googlegroups.com> References: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> <5107cfa6$0$30002$c3e8da3$5496439d@news.astraweb.com> <81dbe6cb-714c-4396-aa69-b56855f19f8d@googlegroups.com> Message-ID: On Wed, Jan 30, 2013 at 12:56 PM, iMath wrote: > ? 2013?1?29????UTC+8??9?33?26??Steven D'Aprano??? >> iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? Because you are iterating over an empty list, []. That list comprehension is the equivalent of: result = [] for name in []: result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an empty list, the body of the loop never executes, and the result list remains empty. What did you expect it to do? -- Steven > > just in order to get the full path name of each file . Then it's done exactly what it should. It's given you the full path of all of your list of zero files. ChrisA From jeanmichel at sequans.com Tue Jan 29 08:33:36 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 29 Jan 2013 14:33:36 +0100 (CET) Subject: [os.path.join(r'E:\Python', name) for name in []] returns [] In-Reply-To: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> Message-ID: <197442022.11625310.1359466416433.JavaMail.root@sequans.com> ----- Original Message ----- > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? > please explain it in detail ? > -- > http://mail.python.org/mailman/listinfo/python-list > You're mapping an empty list. "for name in []" JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From davea at davea.name Tue Jan 29 08:36:21 2013 From: davea at davea.name (Dave Angel) Date: Tue, 29 Jan 2013 08:36:21 -0500 Subject: [os.path.join(r'E:\Python', name) for name in []] returns [] In-Reply-To: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> References: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> Message-ID: <5107D055.7060902@davea.name> On 01/29/2013 08:21 AM, iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? > please explain it in detail ? > [ os.path.join(r'E:\Python', name) for name in [] ] It'd be nice if you would explain what part of it bothers you. Do you know what a list comprehension is? Do you know how to decompose a list comprehension into a for-loop? Do you know that [] is an empty list object? res = [] for name in []: res.append( XXXX ) Since the for loop doesn't loop even once, the result is the initial value, the empty loop. -- DaveA From rustompmody at gmail.com Tue Jan 29 12:32:57 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 29 Jan 2013 09:32:57 -0800 (PST) Subject: ] returns [] References: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> Message-ID: <722d57be-7d3d-40a8-a8f9-2e30de372059@pu9g2000pbc.googlegroups.com> On Jan 29, 6:22?pm, iMath wrote: > ? 2013?1?29????UTC+8??9?21?16??iMath??? > > > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? please explain it in detail ? > >>> [os.path.join(r'E:\Python', name) for name in []] > > [] [Small algebra lesson] In algebra there is the concept of identity and absorbent. For example, 1 is the identity for multiply and 0 is the absorbent. ie for all x: 1 * x = x and 0 * x = 0 [end algebra lesson] In the case of lists, [] is an identity for ++ but behaves like an absorbent for comprehensions. Modern terminology for 'absorbent' is 'zero-element'. I personally find the older terminology more useful. Others have pointed out why operationally [] behaves like an absorbent in comprehensions. Ive seen even experienced programmers trip up on this so I believe its good to know it as an algebraic law in addition to the operational explanation. From marty.musatov at gmail.com Tue Jan 29 19:38:47 2013 From: marty.musatov at gmail.com (marty.musatov at gmail.com) Date: Tue, 29 Jan 2013 16:38:47 -0800 (PST) Subject: ] returns [] In-Reply-To: <722d57be-7d3d-40a8-a8f9-2e30de372059@pu9g2000pbc.googlegroups.com> References: <1cda35c7-46d1-4ea5-854d-e7b9a92de0df@googlegroups.com> <722d57be-7d3d-40a8-a8f9-2e30de372059@pu9g2000pbc.googlegroups.com> Message-ID: MUSATOV From theo.england at skillsmatter.com Tue Jan 29 11:43:41 2013 From: theo.england at skillsmatter.com (Theo) Date: Tue, 29 Jan 2013 08:43:41 -0800 (PST) Subject: In The Brain of Russel Winder: Python is a High Performance Programming Language Message-ID: <47f6cbc8-311e-4ad9-a8e1-bf4a753bff3a@googlegroups.com> Russel Winder gave a talk at Skills Matter last year on why Python should be considered a high performance programming language. Leading Python expert Russel Winder argues that traditionally, people view bytecode/virtual machine-based languages as slow and clunky. Java put paid to that idea with its just-in-time compilation. Python is similarly a bytecode/virtual machine-based language but until recently had not been seen as being in need of being a high performance language. Russel argues this is changing. In this session Russel will take an interactive wander through all these issues, resulting in the conclusion that Python is up there with C++ and Fortran as a high performance language. Learn more - http://bit.ly/UA6cgv From moonhkt at gmail.com Tue Jan 29 11:57:26 2013 From: moonhkt at gmail.com (moonhkt) Date: Tue, 29 Jan 2013 08:57:26 -0800 (PST) Subject: Split string first data have ", Message-ID: <00b96a1b-67c9-46c4-a492-1edf216b6c18@q16g2000pbt.googlegroups.com> >>> y = '"abc.p,zip.p",a,b' >>> print y "abc.p,zip.p",a,b >>> From nick.cash at npcinternational.com Tue Jan 29 12:07:18 2013 From: nick.cash at npcinternational.com (Nick Cash) Date: Tue, 29 Jan 2013 17:07:18 +0000 Subject: Split string first data have ", In-Reply-To: <00b96a1b-67c9-46c4-a492-1edf216b6c18@q16g2000pbt.googlegroups.com> References: <00b96a1b-67c9-46c4-a492-1edf216b6c18@q16g2000pbt.googlegroups.com> Message-ID: <846C3A8E860C4344B567D813B63AA51D7413B8B5@BL2PRD0610MB349.namprd06.prod.outlook.com> > >>> y = '"abc.p,zip.p",a,b' > >>> print y > "abc.p,zip.p",a,b > >>> >>> x = "what is your question??" >>> print x I'm guessing that you want to split on ",", but want the quoted section to be a single token? Have you looked at the CSV module (http://docs.python.org/3/library/csv.html)? If my guess is wrong, or you're having difficulties with the csv module, a more specific question will help you get the answer you're looking for. -Nick Cash From moonhkt at gmail.com Tue Jan 29 11:59:47 2013 From: moonhkt at gmail.com (moonhkt) Date: Tue, 29 Jan 2013 08:59:47 -0800 (PST) Subject: Split string data have "," Message-ID: <5b28f1c8-2eb7-40d3-b28f-d2bfbe766728@ro7g2000pbb.googlegroups.com> Hi All Python 2.6.2 on AIX 5.3 How to using split o >>> y = '"abc.p,zip.p",a,b' >>> print y "abc.p,zip.p",a,b >>> >>> k= y.split(",") >>> print k[0] "abc.p >>> Need Result, First element is abc.p,zip.p From python.list at tim.thechases.com Tue Jan 29 12:14:10 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 29 Jan 2013 11:14:10 -0600 Subject: Split string data have "," In-Reply-To: <5b28f1c8-2eb7-40d3-b28f-d2bfbe766728@ro7g2000pbb.googlegroups.com> References: <5b28f1c8-2eb7-40d3-b28f-d2bfbe766728@ro7g2000pbb.googlegroups.com> Message-ID: <20130129111410.062bdf33@bigbox.christie.dr> On Tue, 29 moonhkt wrote: > >>> y = '"abc.p,zip.p",a,b' > >>> print y > "abc.p,zip.p",a,b > >>> > > >>> k= y.split(",") > >>> print k[0] > "abc.p > >>> > > Need Result, First element is > abc.p,zip.p The csv module should handle this nicely: >>> import csv >>> y = '"abc.p,zip.p",a,b' >>> print y "abc.p,zip.p",a,b >>> r = csv.reader([y]) >>> print r.next() ['abc.p,zip.p', 'a', 'b'] -tkc From clp2 at rebertia.com Tue Jan 29 12:08:50 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 29 Jan 2013 09:08:50 -0800 Subject: Split string data have "," In-Reply-To: <5b28f1c8-2eb7-40d3-b28f-d2bfbe766728@ro7g2000pbb.googlegroups.com> References: <5b28f1c8-2eb7-40d3-b28f-d2bfbe766728@ro7g2000pbb.googlegroups.com> Message-ID: On Jan 29, 2013 9:05 AM, "moonhkt" wrote: > > Hi All > > Python 2.6.2 on AIX 5.3 > How to using split o > > >>> y = '"abc.p,zip.p",a,b' > >>> print y > "abc.p,zip.p",a,b > >>> > > >>> k= y.split(",") > >>> print k[0] > "abc.p > >>> > > Need Result, First element is > abc.p,zip.p Try the csv module or the shlex module. -------------- next part -------------- An HTML attachment was scrubbed... URL: From moonhkt at gmail.com Tue Jan 29 21:21:59 2013 From: moonhkt at gmail.com (moonhkt) Date: Tue, 29 Jan 2013 18:21:59 -0800 (PST) Subject: Split string data have "," References: <5b28f1c8-2eb7-40d3-b28f-d2bfbe766728@ro7g2000pbb.googlegroups.com> Message-ID: On Jan 30, 1:08?am, Chris Rebert wrote: > On Jan 29, 2013 9:05 AM, "moonhkt" wrote: > > > > > > > > > > > > > Hi All > > > Python 2.6.2 on AIX 5.3 > > How to using split o > > > >>> y = '"abc.p,zip.p",a,b' > > >>> print y > > "abc.p,zip.p",a,b > > > >>> k= y.split(",") > > >>> print k[0] > > "abc.p > > > Need Result, First element is > > abc.p,zip.p > > Try the csv module or the shlex module. Thank a lot, Using csv is good for me. From cyrille.rossant at gmail.com Tue Jan 29 13:23:30 2013 From: cyrille.rossant at gmail.com (Cyrille Rossant) Date: Tue, 29 Jan 2013 18:23:30 +0000 Subject: Galry, a high-performance interactive visualization package in Python Message-ID: Dear all, I'm making available today a first pre-release of Galry < http://rossant.github.com/galry/>, a BSD-licensed high performance interactive visualization toolbox in Python based on OpenGL. Its matplotlib-like high-level interface allows to interactively visualize plots with tens of millions of points. Galry is highly flexible and natively supports 2D plots, 3D meshes, text, planar graphs, images, custom shaders, etc. The low-level interface can be used to write graphical interfaces in Qt with efficient visualization widgets. The goal of this beta pre-release is to ensure that Galry can work on the widest possible range of systems and graphics cards (OpenGL v2+ is required). If you're interested, please feel free to give it a try! Also, I'd very much appreciate if you could fill in a really short form on the webpage to indicate what you'd like to do with this package. Your feedback will be invaluable in the future development of Galry. Best regards, Cyrille Rossant -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Jan 29 14:52:11 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 29 Jan 2013 14:52:11 -0500 Subject: Galry, a high-performance interactive visualization package in Python In-Reply-To: References: Message-ID: On 1/29/2013 1:23 PM, Cyrille Rossant wrote: > The goal of this beta pre-release is to ensure that Galry can work on > the widest possible range of systems and graphics cards (OpenGL v2+ is > required). > From that site: "Mandatory dependencies include Python 2.7," For a new, still-beta package, this is somewhat sad. 2.7 is 3.5 years old and has only 1.5 years of semi-normal maintainance left. It will be more like 1 year when you get to your final release. If you are not supporting anything before 2.7, it should not be hard to make your python code also support 3.x. Use the future imports for print and unicode. Others have written more guidelines. "Numpy, either PyQt4 or PySide, PyOpenGL, matplotlib" These all support 3.2,3.3 (PyOpenGl says 'experimental'). -- Terry Jan Reedy From copybin at gmail.com Tue Jan 29 15:27:34 2013 From: copybin at gmail.com (Elias Andrawos) Date: Tue, 29 Jan 2013 12:27:34 -0800 (PST) Subject: Quepy, transform questions in natural language into queries in a DB language using python Message-ID: <4c3d9def-f1d9-46c1-a2c4-ddef75560048@googlegroups.com> We are sharing an open source framework that we made here at Machinalis: Quepy https://github.com/machinalis/quepy Quepy is a Python framework to transform questions in natural language into queries in a database language. It can be easily adapted to different types of questions in natural language, so that with little code you can build your own interface to a database in natural language. Currently, Quepy supports only the SPARQL query language, but in future versions and with the collaboration of the community we are planning to extend it to other database query languages. You are invited to participate and collaborate with the project. We leave here links to the documentation [0], the source code [1], and also a Pypi package [2]. Also, as an example, we have an online instance of Quepy the interacts with DBpedia available [3]. Source code for this example instance is available within the Quepy package so you can kickstart your project from an existing, working example. If you like it, or if you have suggestions: Tell us about it! We're just an email away [4]. Cheers! [0] https://github.com/machinalis/quepy [1] http://quepy.readthedocs.org/ [2] http://pypi.python.org/pypi/quepy/ [3] quepy.machinalis.com (Don't expect a QA system, it's an example) [4] quepyproject[(at)]machinalis.com We're doing an online hangout to show example code and answer questions about the project: Hangout event on Wed, January 30 at 14:00 UTC or Hangout event on Wed, January 30 at 19:00 UTC Also we invite you to try the new user interface: http://quepy.machinalis.com/ Regards El?as From alexprengere at gmail.com Tue Jan 29 16:25:39 2013 From: alexprengere at gmail.com (Alex) Date: Tue, 29 Jan 2013 13:25:39 -0800 (PST) Subject: GeoBases: data services and visualization Message-ID: This new project provides tools to play with geographical data. It also works with non-geographical data, except for map visualizations :). There are embedded data sources in the project, but you can easily play with your own data in addition to the available ones. Files containing data about airports, train stations, countries, ... are loaded, then you can: - performs various types of queries ( find this key, or find keys with this property) - fuzzy searches based on string distance ( find things roughly named like this) - geographical searches ( find things next to this place) - get results on a map, or export it as csv data, or as a Python object This is entirely written in Python. The core part is a Python package, but there is a command line tool as well! For tutorials and documentation, check out http://opentraveldata.github.com/geobases/ From guil.genet at gmail.com Wed Jan 30 08:28:46 2013 From: guil.genet at gmail.com (guil.genet at gmail.com) Date: Wed, 30 Jan 2013 05:28:46 -0800 (PST) Subject: GeoBases: data services and visualization In-Reply-To: References: Message-ID: <4c811219-e73f-4965-94ee-fe08cf25f369@googlegroups.com> Le mardi 29 janvier 2013 22:25:39 UTC+1, Alex Prengere a ?crit?: > This new project provides tools to play with geographical data. It also works with non-geographical data, except for map visualizations :). There are embedded data sources in the project, but you can easily play with your own data in addition to the available ones. Files containing data about airports, train stations, countries, ... are loaded, then you can: - performs various types of queries ( find this key, or find keys with this property) - fuzzy searches based on string distance ( find things roughly named like this) - geographical searches ( find things next to this place) - get results on a map, or export it as csv data, or as a Python object This is entirely written in Python. The core part is a Python package, but there is a command line tool as well! For tutorials and documentation, check out http://opentraveldata.github.com/geobases/ Preum's From guil.genet at gmail.com Wed Jan 30 08:30:20 2013 From: guil.genet at gmail.com (guil.genet at gmail.com) Date: Wed, 30 Jan 2013 05:30:20 -0800 (PST) Subject: GeoBases: data services and visualization In-Reply-To: <4c811219-e73f-4965-94ee-fe08cf25f369@googlegroups.com> References: <4c811219-e73f-4965-94ee-fe08cf25f369@googlegroups.com> Message-ID: Le mercredi 30 janvier 2013 14:28:46 UTC+1, guil.... at gmail.com a ?crit?: > Le mardi 29 janvier 2013 22:25:39 UTC+1, Alex Prengere a ?crit?: > This new project provides tools to play with geographical data. It also works with non-geographical data, except for map visualizations :). There are embedded data sources in the project, but you can easily play with your own data in addition to the available ones. Files containing data about airports, train stations, countries, ... are loaded, then you can: - performs various types of queries ( find this key, or find keys with this property) - fuzzy searches based on string distance ( find things roughly named like this) - geographical searches ( find things next to this place) - get results on a map, or export it as csv data, or as a Python object This is entirely written in Python. The core part is a Python package, but there is a command line tool as well! For tutorials and documentation, check out http://opentraveldata.github.com/geobases/ Preum's First From agamal100 at gmail.com Tue Jan 29 17:57:19 2013 From: agamal100 at gmail.com (agamal100 at gmail.com) Date: Tue, 29 Jan 2013 14:57:19 -0800 (PST) Subject: Ways to apply while learning.... Message-ID: <79366274-a623-43ab-b7dd-e5569eadbb0d@googlegroups.com> Hello, I am learning programming as a spare time hobby and learning python through codecademy. Today I have downloaded and installed aptana, and found out that although I have been progressing for some time now but I do not remember how to code and I have to look everything up. I want to know what is the best way to learn python and some small projects that I can make using console(I know there is a long way to develop something for the desktop) Thank you. ps: I am coming from vb6 paradigm. From dwightdhutto at gmail.com Tue Jan 29 18:09:35 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 29 Jan 2013 18:09:35 -0500 Subject: Ways to apply while learning.... In-Reply-To: <79366274-a623-43ab-b7dd-e5569eadbb0d@googlegroups.com> References: <79366274-a623-43ab-b7dd-e5569eadbb0d@googlegroups.com> Message-ID: On Tue, Jan 29, 2013 at 5:57 PM, wrote: > Hello, > I am learning programming as a spare time hobby and learning python through codecademy. > > Today I have downloaded and installed aptana, and found out that although I have been progressing for some time now but I do not remember how to code and I have to look everything up. When using different languages to mean client needs,this will be a necessity. > > I want to know what is the best way to learn python and some small projects that I can make using console you might need to utilize subrocess, but many ahve their preference. (I know there is a long way to develop something for the desktop) Do you mean command line app, or with a GUI? > > Thank you. > ps: I am coming from vb6 paradigm. > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From xenplex at gmail.com Wed Jan 30 04:28:33 2013 From: xenplex at gmail.com (Ritchie Flick) Date: Wed, 30 Jan 2013 10:28:33 +0100 Subject: Ways to apply while learning.... In-Reply-To: References: <79366274-a623-43ab-b7dd-e5569eadbb0d@googlegroups.com> Message-ID: It's perfectly normal that you need to look things up, even the most seasoned programmer has to look up something at some point. Finding small projects is often difficult, because many projects grow to such an extent, that they're simply to difficult to grasp for a beginner and even for an experienced programmer if the code documentation sucks. I would suggets reading some python code on http://ww.github.com Learning through reading other peoples code also helps in learning a language. On Wed, Jan 30, 2013 at 12:09 AM, David Hutto wrote: > On Tue, Jan 29, 2013 at 5:57 PM, wrote: > > Hello, > > I am learning programming as a spare time hobby and learning python > through codecademy. > > > > Today I have downloaded and installed aptana, and found out that > although I have been progressing for some time now but I do not remember > how to code and I have to look everything up. > > When using different languages to mean client needs,this will be a > necessity. > > > > > I want to know what is the best way to learn python and some small > projects that I can make using console > > you might need to utilize subrocess, but many ahve their preference. > (I know there is a long way to develop something for the desktop) > Do you mean command line app, or with a GUI? > > > > Thank you. > > ps: I am coming from vb6 paradigm. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ritchie Flick -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwrousejr at nethere.comNOSPAM Tue Jan 29 21:55:10 2013 From: dwrousejr at nethere.comNOSPAM (Daniel W. Rouse Jr.) Date: Tue, 29 Jan 2013 18:55:10 -0800 Subject: Please provide a better explanation of tuples and dictionaries Message-ID: Hi all, I have recently started learning Python (2.7.3) but need a better explanation of how to use tuples and dictionaries. I am currently using "Learning Python" by Mark Lutz and David Ascher, published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations insufficient and the number of examples to be sparse. I do understand some ANSI C programming in addition to Python (and the book often wanders off into a comparison of C and Python in its numerous footnotes), but I need a better real-world example of how tuples and dictionaries are being used in actual Python code. Any recommendations of a better book that doesn't try to write such compact and clever code for a learning book? Or, can an anyone provide an example of more than a three-line example of a tuple or dictionary? The purpose of my learning Python in this case is not for enterprise level or web-based application level testing at this point. I initially intend to use it for Software QA Test Automation purposes. Thanks in advance for any replies. From rosuav at gmail.com Tue Jan 29 22:11:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jan 2013 14:11:07 +1100 Subject: Please provide a better explanation of tuples and dictionaries In-Reply-To: References: Message-ID: On Wed, Jan 30, 2013 at 1:55 PM, Daniel W. Rouse Jr. wrote: > I am currently using "Learning Python" by Mark Lutz and David Ascher, > published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations > insufficient and the number of examples to be sparse. I do understand some > ANSI C programming in addition to Python (and the book often wanders off > into a comparison of C and Python in its numerous footnotes), but I need a > better real-world example of how tuples and dictionaries are being used in > actual Python code. Have you checked out the online documentation at http://docs.python.org/ ? That might have what you're looking for. By the way, you may want to consider learning and using Python 3.3 instead of the older branch 2.7; new features are only being added to the 3.x branch now, with 2.7 getting bugfixes and such for a couple of years, but ultimately it's not going anywhere. Obviously if you're supporting existing code, you'll need to learn the language that it was written in, but if this is all new code, go with the recent version. ChrisA From dwrousejr at nethere.comNOSPAM Tue Jan 29 22:42:18 2013 From: dwrousejr at nethere.comNOSPAM (Daniel W. Rouse Jr.) Date: Tue, 29 Jan 2013 19:42:18 -0800 Subject: Please provide a better explanation of tuples and dictionaries In-Reply-To: References: Message-ID: "Chris Angelico" wrote in message news:mailman.1197.1359515470.2939.python-list at python.org... > On Wed, Jan 30, 2013 at 1:55 PM, Daniel W. Rouse Jr. > wrote: >> I am currently using "Learning Python" by Mark Lutz and David Ascher, >> published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations >> insufficient and the number of examples to be sparse. I do understand >> some >> ANSI C programming in addition to Python (and the book often wanders off >> into a comparison of C and Python in its numerous footnotes), but I need >> a >> better real-world example of how tuples and dictionaries are being used >> in >> actual Python code. > > Have you checked out the online documentation at > http://docs.python.org/ ? That might have what you're looking for. > I'll check the online documentation but I was really seeking a book recommendation or other offline resource. I am not always online, and often times when I code I prefer local machine documentation or a book. I do also have the .chm format help file in the Windows version of Python. > By the way, you may want to consider learning and using Python 3.3 > instead of the older branch 2.7; new features are only being added to > the 3.x branch now, with 2.7 getting bugfixes and such for a couple of > years, but ultimately it's not going anywhere. Obviously if you're > supporting existing code, you'll need to learn the language that it > was written in, but if this is all new code, go with the recent > version. > Honestly, I don't know what code is being supported. I've just seen enough test automation requirements calling for Python (in addition to C# and perl) in some of the latest job listings that I figured I better get some working knowledge of Python to avoid becoming obsolete should I ever need to find another job. From rosuav at gmail.com Tue Jan 29 22:51:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jan 2013 14:51:09 +1100 Subject: Please provide a better explanation of tuples and dictionaries In-Reply-To: References: Message-ID: On Wed, Jan 30, 2013 at 2:42 PM, Daniel W. Rouse Jr. wrote: > "Chris Angelico" wrote in message > news:mailman.1197.1359515470.2939.python-list at python.org... >> Have you checked out the online documentation at >> http://docs.python.org/ ? That might have what you're looking for. >> > I'll check the online documentation but I was really seeking a book > recommendation or other offline resource. I am not always online, and often > times when I code I prefer local machine documentation or a book. I do also > have the .chm format help file in the Windows version of Python. Ah. I think the tutorial's in the chm file, but I'm not certain. But for actual books, I can't point to any; I learned from online info only, never actually sought a book (in fact, the last time I used dead-tree reference books was for C and C++). Sorry! >> By the way, you may want to consider learning and using Python 3.3 >> instead of the older branch 2.7... >> > Honestly, I don't know what code is being supported. I've just seen enough > test automation requirements calling for Python (in addition to C# and perl) > in some of the latest job listings that I figured I better get some working > knowledge of Python to avoid becoming obsolete should I ever need to find > another job. A fair point. In that case, it's probably worth learning both; they're very similar. Learn either one first, then master the differences. ChrisA From msirenef at lightbird.net Tue Jan 29 22:51:40 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Tue, 29 Jan 2013 22:51:40 -0500 Subject: Please provide a better explanation of tuples and dictionaries In-Reply-To: References: Message-ID: <510898CC.70809@lightbird.net> On 01/29/2013 09:55 PM, Daniel W. Rouse Jr. wrote: > Hi all, > > I have recently started learning Python (2.7.3) but need a better explanation of how to use tuples and dictionaries. > > I am currently using "Learning Python" by Mark Lutz and David Ascher, published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations insufficient and the number of examples to be sparse. I do understand some ANSI C programming in addition to Python (and the book often wanders off into a comparison of C and Python in its numerous footnotes), but I need a better real-world example of how tuples and dictionaries are being used in actual Python code. > > Any recommendations of a better book that doesn't try to write such compact and clever code for a learning book? Or, can an anyone provide an example of more than a three-line example of a tuple or dictionary? > > The purpose of my learning Python in this case is not for enterprise level or web-based application level testing at this point. I initially intend to use it for Software QA Test Automation purposes. > > Thanks in advance for any replies. It's not finished yet, but you may find my text-movie tutorial on dicts useful: http://lightbird.net/larks/tmovies/dicts.html -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Idleness is the mother of psychology. Friedrich Nietzsche From gordon at panix.com Wed Jan 30 00:15:43 2013 From: gordon at panix.com (John Gordon) Date: Wed, 30 Jan 2013 05:15:43 +0000 (UTC) Subject: Please provide a better explanation of tuples and dictionaries References: Message-ID: In "Daniel W. Rouse Jr." writes: > I have recently started learning Python (2.7.3) but need a better > explanation of how to use tuples and dictionaries. A tuple is a linear sequence of items, accessed via subscripts that start at zero. Tuples are read-only; items cannot be added, removed, nor replaced. Items in a tuple need not be the same type. Example: >>> my_tuple = (1, 5, 'hello', 9.9999) >>> print my_tuple[0] 1 >>> print my_tuple[2] hello A dictionary is a mapping type; it allows you to access items via a meaningful name (usually a string.) Dictionaries do not preserve the order in which items are created (but there is a class in newer python versions, collections.OrderedDict, which does preserve order.) Example: >>> person = {} # start with an empty dictionary >>> person['name'] = 'John' >>> person['age'] = 40 >>> person['occupation'] = 'Programmer' >>> print person['age'] 40 Dictionaries can also be created with some initial values, like so: >>> person = { 'name': 'John', 'age': 40, 'occupation' : 'Programmer' } -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From dwrousejr at nethere.comNOSPAM Wed Jan 30 01:14:42 2013 From: dwrousejr at nethere.comNOSPAM (Daniel W. Rouse Jr.) Date: Tue, 29 Jan 2013 22:14:42 -0800 Subject: Please provide a better explanation of tuples and dictionaries In-Reply-To: References: Message-ID: "John Gordon" wrote in message news:keaa9v$1ru$1 at reader1.panix.com... > In "Daniel W. Rouse Jr." > writes: > >> I have recently started learning Python (2.7.3) but need a better >> explanation of how to use tuples and dictionaries. > > A tuple is a linear sequence of items, accessed via subscripts that start > at zero. > > Tuples are read-only; items cannot be added, removed, nor replaced. > > Items in a tuple need not be the same type. > > Example: > > >>> my_tuple = (1, 5, 'hello', 9.9999) > >>> print my_tuple[0] > 1 > >>> print my_tuple[2] > hello > To me, this looks like an array. Is tuple just the Python name for an array? > A dictionary is a mapping type; it allows you to access items via a > meaningful name (usually a string.) > > Dictionaries do not preserve the order in which items are created (but > there is a class in newer python versions, collections.OrderedDict, which > does preserve order.) > > Example: > > >>> person = {} # start with an empty dictionary > >>> person['name'] = 'John' > >>> person['age'] = 40 > >>> person['occupation'] = 'Programmer' > >>> print person['age'] > 40 > > Dictionaries can also be created with some initial values, like so: > > >>> person = { 'name': 'John', 'age': 40, 'occupation' : 'Programmer' } > Thank you, I understand it better it is kind of like a hash table. From rosuav at gmail.com Wed Jan 30 01:25:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jan 2013 17:25:51 +1100 Subject: Please provide a better explanation of tuples and dictionaries In-Reply-To: References: Message-ID: On Wed, Jan 30, 2013 at 5:14 PM, Daniel W. Rouse Jr. wrote: > To me, this looks like an array. Is tuple just the Python name for an array? Not quite. An array is closer to a Python list - a tuple can be thought of as a "frozen list", if you like. Lists can be added to, removed from, and changed in many ways; tuples are what they are, and there's no changing them (the objects inside it could be changed, but WHAT objects are in it won't). Python has no strict match to a C-style array with a fixed size and changeable members; a Python list is closest to a C++ std::vector, if that helps at all. ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 30 02:12:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Jan 2013 07:12:59 GMT Subject: Please provide a better explanation of tuples and dictionaries References: Message-ID: <5108c7fb$0$11104$c3e8da3@news.astraweb.com> On Tue, 29 Jan 2013 22:14:42 -0800, Daniel W. Rouse Jr. wrote: > "John Gordon" wrote in message > news:keaa9v$1ru$1 at reader1.panix.com... >> A tuple is a linear sequence of items, accessed via subscripts that >> start at zero. >> >> Tuples are read-only; items cannot be added, removed, nor replaced. >> >> Items in a tuple need not be the same type. >> >> Example: >> >> >>> my_tuple = (1, 5, 'hello', 9.9999) >> >>> print my_tuple[0] >> 1 >> >>> print my_tuple[2] >> hello >> > To me, this looks like an array. Is tuple just the Python name for an > array? Absolutely not. Arrays can be modified in place. Tuples cannot. Arrays can be resized (depending on the language). Tuples cannot. Arrays are normally limited to a single data type. Tuples are not. Python lists are closer to arrays, although the "array" type found in the array module is even closer still. You create lists either with the list() function, or list builder notation using [ ]. Tuples are intended to be the equivalent of a C struct or Pascal record. Lists are very roughly intended to be somewhat close to an array, although as I said the array.py module is even closer. >> A dictionary is a mapping type; it allows you to access items via a >> meaningful name (usually a string.) [...] > Thank you, I understand it better it is kind of like a hash table. Correct. Also known as "associative array". -- Steven From rustompmody at gmail.com Wed Jan 30 03:14:42 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 30 Jan 2013 00:14:42 -0800 (PST) Subject: Please provide a better explanation of tuples and dictionaries References: Message-ID: <6b00f501-5234-4e0c-a297-807ead99f14f@v7g2000pbg.googlegroups.com> On Jan 30, 7:55?am, "Daniel W. Rouse Jr." wrote: > Or, can an anyone provide an example of > more than a three-line example of a tuple or dictionary? Have you seen this byt the creator of python -- GvR? http://www.python.org/doc/essays/graphs.html > I have recently started learning Python (2.7.3) but need a better > explanation of how to use tuples and dictionaries. This is an important question: To start off you need to digest whats the diff between value oriented and object oriented. Since this is more to do with paradigm than with a specific language you may read for example: http://www.haskell.org/haskellwiki/The_Monad.Reader/Issue3/Functional_Programming_vs_Object_Oriented_Programming In the python data structure world: value | object tuple | list XX | dictionary frozen-set | set > > I am currently using "Learning Python" by Mark Lutz and David Ascher, > published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations > insufficient and the number of examples to be sparse. I do understand some > ANSI C programming in addition to Python (and the book often wanders off > into a comparison of C and Python in its numerous footnotes), but I need a > better real-world example of how tuples and dictionaries are being used in > actual Python code. > > Any recommendations of a better book that doesn't try to write such compact > and clever code for a learning book? > The purpose of my learning Python in this case is not for enterprise level > or web-based application level testing at this point. I initially intend to > use it for Software QA Test Automation purposes. > > Thanks in advance for any replies. From 129km09 at gmail.com Tue Jan 29 22:26:03 2013 From: 129km09 at gmail.com (su29090) Date: Tue, 29 Jan 2013 19:26:03 -0800 (PST) Subject: struggling with these problems Message-ID: <72be91aa-b9fc-4225-bd54-0ae3459acea3@googlegroups.com> 1.Given that worst_offenders has been defined as a list with at least 6 elements, write a statement that defines lesser_offenders to be a new list that contains all the elements from index 5 of worst_offenders and beyond. Do not modify worst_offenders . I tried this but it didn't work: lesser_offenders = worst_offenders[5:6] 2.Given a variable temps that refers to a list, all of whose elements refer to values of type float , representing temperature data, compute the average temperature and assign it to a variable named avg_temp . Besides temps and avg_temp , you may use two other variables -- k and total . I'm not sure about this one but this is what I have: for k in range(len(temps)): total += temps[k] avg_temp = total / len(temps) 3.Associate the sum of the non-negative values in the list numbers with the variable sum . is it this: for numbers in sum: if sum +=? I'm confused at #3 the most i'm not doing it in python 3.2.3 it's called Myprogramminglab. From python at mrabarnett.plus.com Tue Jan 29 22:59:32 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 30 Jan 2013 03:59:32 +0000 Subject: struggling with these problems In-Reply-To: <72be91aa-b9fc-4225-bd54-0ae3459acea3@googlegroups.com> References: <72be91aa-b9fc-4225-bd54-0ae3459acea3@googlegroups.com> Message-ID: <51089AA4.2010609@mrabarnett.plus.com> On 2013-01-30 03:26, su29090 wrote: > 1.Given that worst_offenders has been defined as a list with at least 6 elements, write a statement that defines lesser_offenders to be a new list that contains all the elements from index 5 of worst_offenders and beyond. Do not modify worst_offenders . > > I tried this but it didn't work: > > lesser_offenders = worst_offenders[5:6] > Python uses half-open ranges (and counts from 0), which means that the start index is included and the end index is excluded. Therefore, worst_offenders[5:6] means the slice from index 5 up to, but excluding, index 6; in other words, an empty list. The question says "and beyond"; in Python you can just omit the end index to indicate everything up to the end. > 2.Given a variable temps that refers to a list, all of whose elements refer to values of type float , representing temperature data, compute the average temperature and assign it to a variable named avg_temp . Besides temps and avg_temp , you may use two other variables -- k and total . > > > I'm not sure about this one but this is what I have: > > for k in range(len(temps)): > total += temps[k] > > avg_temp = total / len(temps) > You didn't set the initial value of total, which is 0. > 3.Associate the sum of the non-negative values in the list numbers with the variable sum . > > is it this: > > for numbers in sum: > if sum +=? > > I'm confused at #3 the most > Well, that's not valid Python. What you want to do is to add each number from the list to the sum only if it's non-negative, i.e. greater than or equal to 0. > i'm not doing it in python 3.2.3 it's called Myprogramminglab. > Have a look at Dive Into Python: http://www.diveintopython.net/ From steve+comp.lang.python at pearwood.info Tue Jan 29 23:43:56 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Jan 2013 04:43:56 GMT Subject: struggling with these problems References: <72be91aa-b9fc-4225-bd54-0ae3459acea3@googlegroups.com> Message-ID: <5108a50c$0$11104$c3e8da3@news.astraweb.com> On Wed, 30 Jan 2013 03:59:32 +0000, MRAB wrote: > Python uses half-open ranges (and counts from 0), which means that the > start index is included and the end index is excluded. > > Therefore, worst_offenders[5:6] means the slice from index 5 up to, but > excluding, index 6; in other words, an empty list. Er, no. It's a one-element list: index 5 is included, index 6 is excluded. py> L = list("abcdefgh") py> L[5:6] ['f'] -- Steven From r_delaney2001 at yahoo.com Tue Jan 29 23:55:44 2013 From: r_delaney2001 at yahoo.com (RichD) Date: Tue, 29 Jan 2013 20:55:44 -0800 (PST) Subject: security quirk Message-ID: I read Wall Street Journal, and occasionally check articles on their Web site. It's mostly free, with some items available to subscribers only. It seems random, which ones they block, about 20%. Anywho, sometimes I use their search utility, the usual author or title search, and it blocks, then I look it up on Google, and link from there, and it loads! ok, Web gurus, what's going on? -- Rich From ben+python at benfinney.id.au Wed Jan 30 00:10:23 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 30 Jan 2013 16:10:23 +1100 Subject: Signal versus noise (was: security quirk) References: Message-ID: <7wobg7uugw.fsf@benfinney.id.au> RichD writes: > Anywho, sometimes I use their search utility, the usual author > or title search, and it blocks, then I look it up on Google, and > link from there, and it loads! ok, Web gurus, what's going on? That evidently has nothing in particular to do with the topic of this forum: the Python programming language. If you want to just comment on arbitrary things with the internet at large, you have many other forums available. Please at least try to keep this forum on-topic. -- \ ?Outside of a dog, a book is man's best friend. Inside of a | `\ dog, it's too dark to read.? ?Groucho Marx | _o__) | Ben Finney From rodrick.brown at gmail.com Wed Jan 30 00:14:01 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 30 Jan 2013 00:14:01 -0500 Subject: security quirk In-Reply-To: References: Message-ID: On Tue, Jan 29, 2013 at 11:55 PM, RichD wrote: > I read Wall Street Journal, and occasionally check > articles on their Web site. It's mostly free, with some items > available to subscribers only. It seems random, which ones > they block, about 20%. > > Anywho, sometimes I use their search utility, the usual author > or title search, and it blocks, then I look it up on Google, and > link from there, and it loads! ok, Web gurus, what's going on? > > Its Gremlins! I tell you Gremlins!!! > > -- > Rich > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Jan 30 00:16:03 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 29 Jan 2013 21:16:03 -0800 Subject: security quirk In-Reply-To: References: Message-ID: On Tue, Jan 29, 2013 at 8:55 PM, RichD wrote: > I read Wall Street Journal, and occasionally check > articles on their Web site. It's mostly free, with some items > available to subscribers only. It seems random, which ones > they block, about 20%. > > Anywho, sometimes I use their search utility, the usual author > or title search, and it blocks, then I look it up on Google, and > link from there, and it loads! ok, Web gurus, what's going on? http://www.google.com/search?btnG=1&pws=0&q=first+click+free BTW, this has absolutely jack squat to do with Python. Please direct similar future inquiries to a more relevant forum. Regards, Chris From marty.musatov at gmail.com Wed Jan 30 09:37:11 2013 From: marty.musatov at gmail.com (Martin Musatov) Date: Wed, 30 Jan 2013 06:37:11 -0800 (PST) Subject: security quirk References: Message-ID: <2b0bd8ac-1aa1-4b42-8e60-f83b64201d8e@d8g2000pbm.googlegroups.com> On Jan 29, 8:55?pm, RichD wrote: > I read Wall Street Journal, and occasionally check 00commentBegin 01comment 02commentEnd 03 04 (); Open middle Close Open middle Close Open middle Close %% > articles on their Web site. ?It's mostly free, with some items > available to subscribers only. ?It seems random, which ones > they block, about 20%. > > Anywho, sometimes I use their search utility, the usual author > or title search, and it blocks, then I look it up on Google, and > link from there, and it loads! ?ok, Web gurus, what's going on? > > -- > Rich From not.my.real at email.address Wed Jan 30 17:40:48 2013 From: not.my.real at email.address (Auric__) Date: Wed, 30 Jan 2013 22:40:48 +0000 (UTC) Subject: security quirk References: <2b0bd8ac-1aa1-4b42-8e60-f83b64201d8e@d8g2000pbm.googlegroups.com> Message-ID: Martin Musatov wrote: > On Jan 29, 8:55?pm, RichD wrote: >> I read Wall Street Journal, and occasionally check > [snip] > > Ignoring the big ol' unneccessary crosspost... What the fuck? -- Oooh, I just learned a new euphemism. From gandalf at the.dead.ISP.of.Community.net Wed Jan 30 09:39:18 2013 From: gandalf at the.dead.ISP.of.Community.net (Gandalf Parker) Date: Wed, 30 Jan 2013 14:39:18 +0000 (UTC) Subject: security quirk References: Message-ID: RichD contributed wisdom to news:b968c6c6-5aa9- 4584-bd7a-5b097f17c54d at pu9g2000pbc.googlegroups.com: > Web gurus, what's going on? > That is the fault of the site itself. If they are going to block access to users then they should also block access to the automated spiders that hit the site to collect data. From r_delaney2001 at yahoo.com Wed Jan 30 14:39:41 2013 From: r_delaney2001 at yahoo.com (RichD) Date: Wed, 30 Jan 2013 11:39:41 -0800 (PST) Subject: security quirk References: Message-ID: On Jan 30, Gandalf Parker wrote: > > Web gurus, what's going on? > > That is the fault of the site itself. > If they are going to block access to users then they should also block > access to the automated spiders that hit the site to collect data. well yeah, but what's going on, under the hood? How does it get confused? How could this happen? I'm looking for some insight, regarding a hypothetical programmimg glitch - -- Rich From joel.goldstick at gmail.com Wed Jan 30 14:45:30 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 30 Jan 2013 14:45:30 -0500 Subject: security quirk In-Reply-To: References: Message-ID: On Wed, Jan 30, 2013 at 2:39 PM, RichD wrote: > On Jan 30, Gandalf Parker > wrote: > > > Web gurus, what's going on? > > > > That is the fault of the site itself. > > If they are going to block access to users then they should also block > > access to the automated spiders that hit the site to collect data. > > well yeah, but what's going on, under the hood? > How does it get confused? How could this > happen? I'm looking for some insight, regarding a > hypothetical programmimg glitch - > > > -- > Rich > -- > > As was pointed out, this really is off topic for this group. You might try googling. The NYTimes makes articles available by adding a parameter to the tail of the url I believe -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Jan 30 20:16:00 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 30 Jan 2013 17:16:00 -0800 (PST) Subject: security quirk References: Message-ID: On Jan 31, 5:39?am, RichD wrote: > well yeah, but what's going on, under the hood? > How does it get confused? ?How could this > happen? ?I'm looking for some insight, regarding a > hypothetical programmimg glitch - As has been stated, this has nothing to do with Python, so please stop posting your questions here. However, here's an answer to get you to stop repeating yourself: it's not uncommon to find that content you're restricted from accessing via a site's own search is available to you through Google. This has to do with Google's policy of _requiring_ that pages that it is allowed to index _must_ be available for view. Any site that allows Google to index its pages that then blocks you from viewing them will swiftly find themselves web site-a non gratis in Google search. As most websites are attention whores, they'll do anything to ensure they remain within Google's indices. From gandalf at the.dead.ISP.of.Community.net Thu Jan 31 09:07:21 2013 From: gandalf at the.dead.ISP.of.Community.net (Gandalf Parker) Date: Thu, 31 Jan 2013 14:07:21 +0000 (UTC) Subject: security quirk References: Message-ID: RichD contributed wisdom to news:badd4188-196b- 45e3-ba8a-511d471282fa at nh8g2000pbc.googlegroups.com: > On Jan 30, Gandalf Parker > wrote: >> > Web gurus, what's going on? >> >> That is the fault of the site itself. >> If they are going to block access to users then they should also block >> access to the automated spiders that hit the site to collect data. > > well yeah, but what's going on, under the hood? > How does it get confused? How could this > happen? I'm looking for some insight, regarding a > hypothetical programmimg glitch - (from alt.hacker) You dont understand. It is not in the code. It is in the site. It is as if someone comes and picks fruit off of your tree, and you are questioning the tree for how it bears fruit. The site creates web pages. Google collects web pages. The site needs to set things like robot.txt to tell Google to NOT collect the pages in the archives. Which is not an absolute protection but at least its an effort that works for most sites. From BigBadBob-at-mrp3-dot-com at testing.local Wed Jan 30 14:59:19 2013 From: BigBadBob-at-mrp3-dot-com at testing.local (Big Bad Bob) Date: Wed, 30 Jan 2013 11:59:19 -0800 Subject: security quirk In-Reply-To: References: Message-ID: <5e2dncvzz7Y55pTMnZ2dnUVZ_smdnZ2d@earthlink.com> On 01/29/13 20:55, RichD so wittily quipped: > I read Wall Street Journal, and occasionally check > articles on their Web site. It's mostly free, with some items > available to subscribers only. It seems random, which ones > they block, about 20%. > > Anywho, sometimes I use their search utility, the usual author > or title search, and it blocks, then I look it up on Google, and > link from there, and it loads! ok, Web gurus, what's going on? in my last post, I quoted an article from 'The Register' where they talk about how Facebook (literally) "broke" that feature. [this works in a LOT of places, but sometimes you have to enable cookies or javascript to actually see the content] From arne at vajhoej.dk Wed Jan 30 20:40:23 2013 From: arne at vajhoej.dk (=?ISO-8859-1?Q?Arne_Vajh=F8j?=) Date: Wed, 30 Jan 2013 20:40:23 -0500 Subject: security quirk In-Reply-To: References: Message-ID: <5109cb8c$0$288$14726298@news.sunsite.dk> On 1/29/2013 11:55 PM, RichD wrote: > I read Wall Street Journal, and occasionally check > articles on their Web site. It's mostly free, with some items > available to subscribers only. It seems random, which ones > they block, about 20%. > > Anywho, sometimes I use their search utility, the usual author > or title search, and it blocks, then I look it up on Google, and > link from there, and it loads! ok, Web gurus, what's going on? WSJ want their articles to be findable from Google. So they open up for Google indexing them. If they require any type of registration to see an article, then Google will remove the link. So therefore WSJ (and many other web sites!) gives more access if you come from Google than if not. Arne From jaorozco at estudiantes.uci.cu Wed Jan 30 02:13:36 2013 From: jaorozco at estudiantes.uci.cu (Jorge Alberto Diaz Orozco) Date: Wed, 30 Jan 2013 02:13:36 -0500 (EST) Subject: pyrudp In-Reply-To: Message-ID: can someone give me a link to download pyrudp. I tried here http://code.google.com/p/pyrudp/ but didn?t worked. if someone can give me another idea it will be great to. I?m traying to make a reliable udp connection help will be really appreciated From rodrick.brown at gmail.com Wed Jan 30 08:45:05 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 30 Jan 2013 08:45:05 -0500 Subject: pyrudp In-Reply-To: References: Message-ID: <-8366160877585761872@unknownmsgid> On Jan 30, 2013, at 8:12 AM, Jorge Alberto Diaz Orozco wrote: > can someone give me a link to download pyrudp. > I tried here http://code.google.com/p/pyrudp/ but didn?t worked. > > if someone can give me another idea it will be great to. > I?m traying to make a reliable udp connection What about the native socket call to SOCK_DGRAM? Here is a simple example to read messages of a udp socket. import socket UDP_IP = "127.0.0.1" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes print "received message:", data > > help will be really appreciated > > > > -- > http://mail.python.org/mailman/listinfo/python-list From jaorozco at estudiantes.uci.cu Wed Jan 30 12:02:52 2013 From: jaorozco at estudiantes.uci.cu (Jorge Alberto Diaz Orozco) Date: Wed, 30 Jan 2013 12:02:52 -0500 (EST) Subject: pyrudp In-Reply-To: <-8366160877585761872@unknownmsgid> Message-ID: <0fc69471-a63b-4b4e-8e70-d0e3daa2fa74@ucimail4.uci.cu> I?ve tried it but it?s not reliable. Datagrams can arive disorganised or just not arive. Some programmers said I most use TCP, but I need to use UDP. that?s why I need pyrudp, but I can not find it. On Jan 30, 2013, at 8:12 AM, Jorge Alberto Diaz Orozco What about the native socket call to SOCK_DGRAM? Here is a simple example to read messages of a udp socket. import socket UDP_IP = "127.0.0.1" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes print "received message:", data From torriem at gmail.com Wed Jan 30 12:16:15 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 30 Jan 2013 10:16:15 -0700 Subject: pyrudp In-Reply-To: <0fc69471-a63b-4b4e-8e70-d0e3daa2fa74@ucimail4.uci.cu> References: <0fc69471-a63b-4b4e-8e70-d0e3daa2fa74@ucimail4.uci.cu> Message-ID: <5109555F.3050307@gmail.com> On 01/30/2013 10:02 AM, Jorge Alberto Diaz Orozco wrote: > I?ve tried it but it?s not reliable. Datagrams can arive disorganised or just not arive. > Some programmers said I most use TCP, but I need to use UDP. > that?s why I need pyrudp, but I can not find it. Excuse me for chuckling, but your complaint that UDP packets can "arive disorganised or just not arive" describes exactly what UDP does by design! If you need to use UDP then you will have to live with this. I always consider UDP to stand for "UNRELIABLE datagram packets." They can and do come in any order, or not at all. That's exactly the expected behavior of UDP. If you want to build a reliable connection on top of UDP you'll have to invent some sort of tcp-like protocol that uses UDP packets. An example of a real all that does this is openvpn. The Bell Labs Plan 9 RUDP protocol is probably what you were shooting for by trying to use the non-existent pyrudp code. But I fear you'll have to implement it yourself. pyrudp is an empty project on Google Code. The owner intended to develop some code but never did. From jaorozco at estudiantes.uci.cu Wed Jan 30 14:55:20 2013 From: jaorozco at estudiantes.uci.cu (Jorge Alberto Diaz Orozco) Date: Wed, 30 Jan 2013 14:55:20 -0500 (EST) Subject: pyrudp In-Reply-To: <5109555F.3050307@gmail.com> Message-ID: I want to use a reliable UDP connection like you say, a TCP like connection but over UDP. thaks for your recomendation, if I get good results I promise to share them. ----- Original Message ----- From: "Michael Torrie" To: python-list at python.org Sent: Wednesday, January 30, 2013 9:16:15 AM Subject: Re: pyrudp Excuse me for chuckling, but your complaint that UDP packets can "arive disorganised or just not arive" describes exactly what UDP does by design! If you need to use UDP then you will have to live with this. I always consider UDP to stand for "UNRELIABLE datagram packets." They can and do come in any order, or not at all. That's exactly the expected behavior of UDP. If you want to build a reliable connection on top of UDP you'll have to invent some sort of tcp-like protocol that uses UDP packets. An example of a real all that does this is openvpn. The Bell Labs Plan 9 RUDP protocol is probably what you were shooting for by trying to use the non-existent pyrudp code. But I fear you'll have to implement it yourself. pyrudp is an empty project on Google Code. The owner intended to develop some code but never did. From davea at davea.name Wed Jan 30 17:14:45 2013 From: davea at davea.name (Dave Angel) Date: Wed, 30 Jan 2013 17:14:45 -0500 Subject: pyrudp In-Reply-To: References: Message-ID: <51099B55.80808@davea.name> On 01/30/2013 02:55 PM, Jorge Alberto Diaz Orozco wrote: > I want to use a reliable UDP connection like you say, a TCP like connection but over UDP. thaks for your recomendation, if I get good results I promise to share them. > It's nice to "want" but what is your actual condition/problem? Are you trying to re-invent the wheel, implement a senior project, or are you trying to work around some administrative or technical restriction against tcp? What's the use case? Do you have control over both ends? Are you writing both ends of the imitation tcp you're writing? One of the car magazines published a road test of the Mercedes GT (garbage truck). It had plenty of power, but its top speed was 6 mph, and it leaned horribly around the pylon obstacle course. Not what I'd take to the race track. Point is that a definitive specification of requirements will be much more useful than a simple wanna. -- DaveA From jaorozco at estudiantes.uci.cu Wed Jan 30 19:04:17 2013 From: jaorozco at estudiantes.uci.cu (Jorge Alberto Diaz Orozco) Date: Wed, 30 Jan 2013 19:04:17 -0500 (EST) Subject: pyrudp In-Reply-To: <51099B55.80808@davea.name> Message-ID: I have restrictions in my system that does not allow me to use TCP, so I want to make a pipe over UDP imitating TCP behavior. I have control over both endpoints, and I?m writing both of them. I just don?t want to re-invent the wheel and I?m looking for a reliable UDP sockets implementation for Python so I can start from there. _____________ It's nice to "want" but what is your actual condition/problem? Are you trying to re-invent the wheel, implement a senior project, or are you trying to work around some administrative or technical restriction against tcp? What's the use case? Do you have control over both ends? Are you writing both ends of the imitation tcp you're writing? One of the car magazines published a road test of the Mercedes GT (garbage truck). It had plenty of power, but its top speed was 6 mph, and it leaned horribly around the pylon obstacle course. Not what I'd take to the race track. Point is that a definitive specification of requirements will be much more useful than a simple wanna. From rosuav at gmail.com Wed Jan 30 19:14:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 31 Jan 2013 11:14:27 +1100 Subject: pyrudp In-Reply-To: References: <51099B55.80808@davea.name> Message-ID: On Thu, Jan 31, 2013 at 11:04 AM, Jorge Alberto Diaz Orozco wrote: > I have restrictions in my system that does not allow me to use TCP, so I want to make a pipe over UDP imitating TCP behavior. > I have control over both endpoints, and I?m writing both of them. > I just don?t want to re-invent the wheel and I?m looking for a reliable UDP sockets implementation for Python so I can start from there. Then... I think the place to start is here: http://www.ietf.org/rfc/rfc793.txt ChrisA From wrw at mac.com Wed Jan 30 23:26:01 2013 From: wrw at mac.com (wrw at mac.com) Date: Wed, 30 Jan 2013 23:26:01 -0500 Subject: pyrudp In-Reply-To: References: <51099B55.80808@davea.name> Message-ID: <8540677A-5B7C-4AF2-B0CD-CA78E0589ED3@mac.com> On Jan 30, 2013, at 7:14 PM, Chris Angelico wrote: > On Thu, Jan 31, 2013 at 11:04 AM, Jorge Alberto Diaz Orozco > wrote: >> I have restrictions in my system that does not allow me to use TCP, so I want to make a pipe over UDP imitating TCP behavior. >> I have control over both endpoints, and I?m writing both of them. >> I just don?t want to re-invent the wheel and I?m looking for a reliable UDP sockets implementation for Python so I can start from there. > > Then... I think the place to start is here: > > http://www.ietf.org/rfc/rfc793.txt > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list I think you really ought to think about this long and hard. Although TCP started as a fairly simple-minded protocol designed to guarantee reliable delivery of packets in the order in which they were transmitted, it has evolved considerably over the years. It now incorporates concepts of "fairness" and a very sophisticated rate control system that is constantly probing available network bandwidth to be sure it isn't over driving or hogging the network connection. It would be easy to say: "I really don't need all that - all I'm doing is X." - but in reality you do, and getting reliable delivery over UDP really does require it all. Now, the good news is that because UDP-based protocols all run in user memory space (as opposed to TCP that runs privileged in kernel space) it is relatively straightforward for non-privledged users to write and test UDP transport schemes and this has become a fairly standard CS exercise at the graduate level. If I were in your shoes, I'd start Googling for the papers published on protocols like HURRICANE, ATAU, or even just the general subject of UDP transport protocols. Two places you might start are: http://www.ogf.org/documents/GFD.55.pdf and http://www.ornl.gov/~webworks/cppr/y2001/rpt/121150.pdf Most, if not all of these UDP schemes are in the public domain, have been written in high-level languages, and could be translated into python. -Bill From rosuav at gmail.com Wed Jan 30 23:32:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 31 Jan 2013 15:32:42 +1100 Subject: pyrudp In-Reply-To: <8540677A-5B7C-4AF2-B0CD-CA78E0589ED3@mac.com> References: <51099B55.80808@davea.name> <8540677A-5B7C-4AF2-B0CD-CA78E0589ED3@mac.com> Message-ID: On Thu, Jan 31, 2013 at 3:26 PM, wrote: > Now, the good news is that because UDP-based protocols all run in user memory space (as opposed to TCP that runs privileged in kernel space) it is relatively straightforward for non-privledged users to write and test UDP transport schemes and this has become a fairly standard CS exercise at the graduate level. If I were in your shoes, I'd start Googling for the papers published on protocols like HURRICANE, ATAU, or even just the general subject of UDP transport protocols. I'd still include reading up on TCP. The RFC has a good bit about why things are the way they are; when you're designing a protocol that does similar things, it's worth getting an understanding of what your predecessors did. Either you'll get some ideas ("yeah, that's how I'll do it!") or you'll decide you can do better, but it's still worth a read. ChrisA From rosuav at gmail.com Wed Jan 30 17:34:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 31 Jan 2013 09:34:58 +1100 Subject: pyrudp In-Reply-To: References: <5109555F.3050307@gmail.com> Message-ID: On Thu, Jan 31, 2013 at 6:55 AM, Jorge Alberto Diaz Orozco wrote: > I want to use a reliable UDP connection like you say, a TCP like connection but over UDP. thaks for your recomendation, if I get good results I promise to share them. To get something reliable over UDP, you're going to need to acknowledge everything you're sent, and if you don't hear back an acknowledgement, re-send. Basically reimplement TCP, or parts of it. Why do you need to use UDP? I've used UDP for a number of purposes, but usually in a "fire and forget" system. For instance, my latest use of it was a peer-to-peer self-healing network; each node would broadcast a periodic UDP packet saying "Hi, I'm here, and here's my current status", and each node would keep track of the timestamp when it last received such a packet from each known IP address. If the time-since-last-received exceeds three broadcast intervals, the node is considered to be dead. But for this to work, I have to not care about individual packet loss; there is no data in the packet that won't be repeated in the next one. This is a reliable *system* built on UDP. Can you explain your goals and restrictions? Might help us figure out how to advise. ChrisA From robert.day at merton.oxon.org Wed Jan 30 13:01:30 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Wed, 30 Jan 2013 18:01:30 +0000 Subject: pyrudp In-Reply-To: <0fc69471-a63b-4b4e-8e70-d0e3daa2fa74@ucimail4.uci.cu> References: <-8366160877585761872@unknownmsgid> <0fc69471-a63b-4b4e-8e70-d0e3daa2fa74@ucimail4.uci.cu> Message-ID: Have you seen http://pyraknet.slowchop.com/? It appears to do a similar thing. On 30 January 2013 17:02, Jorge Alberto Diaz Orozco wrote: > I?ve tried it but it?s not reliable. Datagrams can arive disorganised or just not arive. > Some programmers said I most use TCP, but I need to use UDP. > that?s why I need pyrudp, but I can not find it. > > On Jan 30, 2013, at 8:12 AM, Jorge Alberto Diaz Orozco > > What about the native socket call to SOCK_DGRAM? > > Here is a simple example to read messages of a udp socket. > > import socket > UDP_IP = "127.0.0.1" > UDP_PORT = 5005 > > sock = socket.socket(socket.AF_INET, # Internet > socket.SOCK_DGRAM) # UDP > sock.bind((UDP_IP, UDP_PORT)) > > while True: > data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes > print "received message:", data > -- > http://mail.python.org/mailman/listinfo/python-list -- Robert K. Day robert.day at merton.oxon.org From garabik-news-2005-05 at kassiopeia.juls.savba.sk Wed Jan 30 16:01:56 2013 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Wed, 30 Jan 2013 21:01:56 +0000 (UTC) Subject: pyrudp References: Message-ID: Jorge Alberto Diaz Orozco wrote: > I want to use a reliable UDP connection like you say, a TCP like > connection but over UDP. thaks for your recomendation, if I get good > results I promise to share them. > utalk (long since disappeared from the surface of the internet) did have such an implementation, and I once wrote a half-cooked python implementation of its semi-reliable protocol over UDP. Nowadays, I'd recommend using openvpn, or perhaps investigate the possibility of PPP over UDP, or maybe look into SCTP. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From frank at chagford.com Wed Jan 30 06:51:23 2013 From: frank at chagford.com (Frank Millman) Date: Wed, 30 Jan 2013 13:51:23 +0200 Subject: Sorting a hierarchical table (SQL) Message-ID: Hi all This is not really a python question, but I am hoping that some of you can offer some suggestions. I have a SQL table with hierarchical data. There are two models that can be used to represent this - Adjacency Lists and Nested Sets. Here is a link to an article that discusses and compares the two approaches - http://explainextended.com/2009/09/24/adjacency-list-vs-nested-sets-postgresql/ A feature of the Nested Sets model is that a SELECT returns the rows by following the links in the structure - root first, followed by its first child, followed by *its* first child, until the bottom is reached, then any siblings, then up one level to the next child, and so on, until the entire tree is exhausted. I am looking for a way to emulate this behaviour using Adjacency Lists. It is not that easy. The article above shows a way of doing this using an Array. Unfortunately that is a PostgreSQL feature not available in all databases, so I want to avoid that. Here is the best I have come up with. For each row, I know the parent id, I know the level (depth in the tree), and I know the sequence number - every row has a sequence number that is unique within any group of siblings within the tree, always starting from zero. I create a string to be used as a sort key, consisting of the parent's sort key, a comma, and the row's sequence number. So the root has a key of '0', the first child has '0,0', its first child has '0,0,0', etc. If there could never be more than 10 siblings, that would work, but if it goes over 10, the next key would contain the substring '10', which sorts earlier than '2', which would be incorrect. Therefore, on the assumption that there will never be more that 10000 siblings, I zero-fill each element to a length of 4, so the first key is '0000', the next one is '0000,0000', then '0000,0000,0000', etc. All this is done in SQL, as part of a complicated SELECT statement. It works, and it would be unusual to have a tree with a depth of more than 4 or 5, so I can live with it. However, it is not pretty. I wondered if anyone can suggest a more elegant solution. Thanks Frank Millman From robin at reportlab.com Wed Jan 30 09:58:25 2013 From: robin at reportlab.com (Robin Becker) Date: Wed, 30 Jan 2013 14:58:25 +0000 Subject: looping versus comprehension Message-ID: <51093511.9050701@chamonix.reportlab.co.uk> An email in reportlab-users at reportlab.com claimed that the following loop in a charting module was taking a long time > I use ReportLab 2.6 but I also found the problem in ReportLab daily from 01/29/2013 in /src/reportlab/graphics/charts/lineplots.py: > 276 # Iterate over data columns. > 277 if self.joinedLines: > 278 points = [] > 279 for xy in row: > 280 points += [xy[0], xy[1]] > > If I use a list comprehension instead, the plot is generated within seconds or minutes: > 278 points = [[xy[0], xy[1]] for xy in row] however, when I tried an experiment in python 2.7 using the script below I find that the looping algorithms perform better. A naive loop using list += list would appear to be an O(n**2) operation, but python seems to be doing better than that. Also why does the append version fail so dismally. Is my test coded wrongly or is pre-allocation of the list making this better than expected? C:\code\tests>tpoints 86000 860000 #################### START n=86000 #################### existing algorithm took 0.08 seconds existing algorithm using list took 0.12 seconds existing algorithm using list assuming length 2 took 0.12 seconds map(list,row) took 0.16 seconds [list(xy) for xy in row] took 0.28 seconds [[xy[0],xy[1]] for xy in row] took 0.22 seconds append algorithm took 0.19 seconds #################### END n=86000 #################### #################### START n=860000 #################### existing algorithm took 0.86 seconds existing algorithm using list took 1.33 seconds existing algorithm using list assuming length 2 took 1.25 seconds map(list,row) took 3.44 seconds [list(xy) for xy in row] took 3.03 seconds [[xy[0],xy[1]] for xy in row] took 2.70 seconds append algorithm took 2.48 seconds #################### END n=860000 #################### ######################################### import sys, time def main(n): print 20*'#','START n=%s'%n,20*'#' row = [(i,i+1) for i in xrange(2*n)] print 'existing algorithm', t0 = time.time() points = [] for xy in row: points += [xy[0],xy[1]] t1 = time.time() print 'took %.2f seconds' % (t1-t0) print 'existing algorithm using list', t0 = time.time() points = [] for xy in row: points += list(xy[:2]) t1 = time.time() print 'took %.2f seconds' % (t1-t0) print 'existing algorithm using list assuming length 2', t0 = time.time() points = [] for xy in row: points += list(xy) t1 = time.time() print 'took %.2f seconds' % (t1-t0) print 'map(list,row)', t0 = time.time() points = map(list,row) t1 = time.time() print 'took %.2f seconds' % (t1-t0) print '[list(xy) for xy in row]', t0 = time.time() points = [list(xy) for xy in row] t1 = time.time() print 'took %.2f seconds' % (t1-t0) print '[[xy[0],xy[1]] for xy in row]', t0 = time.time() points = [[xy[0],xy[1]] for xy in row] t1 = time.time() print 'took %.2f seconds' % (t1-t0) print 'append algorithm', t0 = time.time() points = [].append for xy in row: points([xy[0],xy[1]]) points = points.__self__ t1 = time.time() print 'took %.2f seconds' % (t1-t0) print 20*'#','END n=%s'%n,20*'#','\n\n' if __name__=='__main__': if len(sys.argv)==1: N = [86000] else: N = map(int,sys.argv[1:]) for n in N: main(n) ######################################### -- Robin Becker From rosuav at gmail.com Wed Jan 30 10:49:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 31 Jan 2013 02:49:31 +1100 Subject: looping versus comprehension In-Reply-To: <51093511.9050701@chamonix.reportlab.co.uk> References: <51093511.9050701@chamonix.reportlab.co.uk> Message-ID: On Thu, Jan 31, 2013 at 1:58 AM, Robin Becker wrote: > however, when I tried an experiment in python 2.7 using the script below I > find that the looping algorithms perform better. A naive loop using list += > list would appear to be an O(n**2) operation, but python seems to be doing > better than that. Also why does the append version fail so dismally. Is my > test coded wrongly or is pre-allocation of the list making this better than > expected? First off, are you aware that your first three blocks of code and your last four produce different results? The first ones flatten the list, the others simply convert tuples to lists. With n = 3: >>> points = [] >>> for xy in row: points += [xy[0],xy[1]] >>> points [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6] >>> map(list,row) [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]] Once that's sorted out, then timings can be played with. But it's worth noting that list appending is not going to be O(N*N), because it's going to allow room for expansion. ChrisA From robin at reportlab.com Wed Jan 30 12:58:27 2013 From: robin at reportlab.com (Robin Becker) Date: Wed, 30 Jan 2013 17:58:27 +0000 Subject: looping versus comprehension In-Reply-To: References: <51093511.9050701@chamonix.reportlab.co.uk> Message-ID: <51095F43.4040502@chamonix.reportlab.co.uk> On 30/01/2013 15:49, Chris Angelico wrote: > On Thu, Jan 31, 2013 at 1:58 AM, Robin Becker wrote: >> however, when I tried an experiment in python 2.7 using the script below I >> find that the looping algorithms perform better. A naive loop using list += >> list would appear to be an O(n**2) operation, but python seems to be doing >> better than that. Also why does the append version fail so dismally. Is my >> test coded wrongly or is pre-allocation of the list making this better than >> expected? > > First off, are you aware that your first three blocks of code and your > last four produce different results? The first ones flatten the list, > the others simply convert tuples to lists. With n = 3: > >>>> points = [] >>>> for xy in row: > points += [xy[0],xy[1]] >>>> points > [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6] >>>> map(list,row) > [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]] > > Once that's sorted out, then timings can be played with. But it's > worth noting that list appending is not going to be O(N*N), because > it's going to allow room for expansion. > > ChrisA > No I missed that :( the list is a flattened one. That'll teach me not to copy the code from the users without checking. Now you point it out it's clear that his code is doing something different. Presumably it's not drawing the same thing at all :) no wonder it got much faster. -- Robin Becker From robin at reportlab.com Wed Jan 30 12:58:27 2013 From: robin at reportlab.com (Robin Becker) Date: Wed, 30 Jan 2013 17:58:27 +0000 Subject: looping versus comprehension In-Reply-To: References: <51093511.9050701@chamonix.reportlab.co.uk> Message-ID: <51095F43.4040502@chamonix.reportlab.co.uk> On 30/01/2013 15:49, Chris Angelico wrote: > On Thu, Jan 31, 2013 at 1:58 AM, Robin Becker wrote: >> however, when I tried an experiment in python 2.7 using the script below I >> find that the looping algorithms perform better. A naive loop using list += >> list would appear to be an O(n**2) operation, but python seems to be doing >> better than that. Also why does the append version fail so dismally. Is my >> test coded wrongly or is pre-allocation of the list making this better than >> expected? > > First off, are you aware that your first three blocks of code and your > last four produce different results? The first ones flatten the list, > the others simply convert tuples to lists. With n = 3: > >>>> points = [] >>>> for xy in row: > points += [xy[0],xy[1]] >>>> points > [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6] >>>> map(list,row) > [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]] > > Once that's sorted out, then timings can be played with. But it's > worth noting that list appending is not going to be O(N*N), because > it's going to allow room for expansion. > > ChrisA > No I missed that :( the list is a flattened one. That'll teach me not to copy the code from the users without checking. Now you point it out it's clear that his code is doing something different. Presumably it's not drawing the same thing at all :) no wonder it got much faster. -- Robin Becker From steve+comp.lang.python at pearwood.info Thu Jan 31 00:17:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Jan 2013 05:17:32 GMT Subject: looping versus comprehension References: <51093511.9050701@chamonix.reportlab.co.uk> Message-ID: <5109fe6b$0$11104$c3e8da3@news.astraweb.com> On Thu, 31 Jan 2013 02:49:31 +1100, Chris Angelico wrote: > it's worth > noting that list appending is not going to be O(N*N), because it's going > to allow room for expansion. This is true for list.append, which is amortized constant time. But it is not true for list addition, alist + blist, which is O(N**2) and hence gets really, really slow: steve at runes:~$ python -m timeit "L = []" "for i in xrange(1000): L = L + [1]" 100 loops, best of 3: 3.08 msec per loop steve at runes:~$ python -m timeit "L = []" "for i in xrange(5000): L = L + [1]" 10 loops, best of 3: 71 msec per loop steve at runes:~$ python -m timeit "L = []" "for i in xrange(25000): L = L + [1]" 10 loops, best of 3: 2.06 sec per loop Notice that as the number of list additions goes up by a factor of 5, the time taken goes up by a factor of 25. -- Steven From roy at panix.com Thu Jan 31 03:28:41 2013 From: roy at panix.com (Roy Smith) Date: Thu, 31 Jan 2013 03:28:41 -0500 Subject: looping versus comprehension References: <51093511.9050701@chamonix.reportlab.co.uk> <5109fe6b$0$11104$c3e8da3@news.astraweb.com> Message-ID: In article <5109fe6b$0$11104$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 31 Jan 2013 02:49:31 +1100, Chris Angelico wrote: > > > it's worth > > noting that list appending is not going to be O(N*N), because it's going > > to allow room for expansion. > > This is true for list.append, which is amortized constant time. But it is > not true for list addition, alist + blist, which is O(N**2) and hence > gets really, really slow: > > steve at runes:~$ python -m timeit "L = []" "for i in xrange(1000): L = L + [1]" > 100 loops, best of 3: 3.08 msec per loop > steve at runes:~$ python -m timeit "L = []" "for i in xrange(5000): L = L + [1]" > 10 loops, best of 3: 71 msec per loop > steve at runes:~$ python -m timeit "L = []" "for i in xrange(25000): L = L + [1]" > 10 loops, best of 3: 2.06 sec per loop > > > Notice that as the number of list additions goes up by a factor of 5, > the time taken goes up by a factor of 25. It's not the addition, per-se, that's the problem. It's the creation of a new list each time. If you use +=, it's back to O(n): ~$ python -m timeit "L = []" "for i in xrange(1000): L += [1]" 1000 loops, best of 3: 275 usec per loop ~$ python -m timeit "L = []" "for i in xrange(5000): L += [1]" 1000 loops, best of 3: 1.34 msec per loop ~$ python -m timeit "L = []" "for i in xrange(25000): L += [1]" 100 loops, best of 3: 6.91 msec per loop From jenn.duerr at gmail.com Wed Jan 30 12:15:25 2013 From: jenn.duerr at gmail.com (noydb) Date: Wed, 30 Jan 2013 09:15:25 -0800 (PST) Subject: how to use subprocess to execute an exe with args and an output Message-ID: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> I am looking for some guidance on using subprocess to execute an EXE with arguments and an output. The below code works in that it returns a 0 exit code, but no output file is created. I have tried a few different versions of this code (used Popen instead, some stderr/stdout), but no luck. Can anyone offer an explanation or suggestion? (GPSBabel is freeware) Python 2.7 on windows7 64-bit import subprocess subprocess.call([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"]) If I use this below, I get a returncode of 1, exit code of 0. import subprocess x = subprocess.Popen([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", "-o", "gpx", r"C:\Temp\gpx\test28output.gpx", "shell=True", "stdout=subprocess.PIPE", "stderr=subprocess.PIPE"]) x.wait() print x.returncode Thanks in advance for any help From jenn.duerr at gmail.com Wed Jan 30 12:19:45 2013 From: jenn.duerr at gmail.com (noydb) Date: Wed, 30 Jan 2013 09:19:45 -0800 (PST) Subject: how to use subprocess to execute an exe with args and an output In-Reply-To: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> References: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> Message-ID: <9053e859-871d-4fc6-8bed-f9be1a5f966c@googlegroups.com> To add on, I need to eventually write a script that takes input, feeds it into this exe, and takes the output file to perform more 'tools'/manipulations on it. Is call or Popen called for, why? Or maybe some other module??? From clp2 at rebertia.com Wed Jan 30 12:57:24 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 Jan 2013 09:57:24 -0800 Subject: how to use subprocess to execute an exe with args and an output In-Reply-To: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> References: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> Message-ID: On Wed, Jan 30, 2013 at 9:15 AM, noydb wrote: > I am looking for some guidance on using subprocess to execute an EXE with arguments and an output. The below code works in that it returns a 0 exit code, but no output file is created. I have tried a few different versions of this code (used Popen instead, some stderr/stdout), but no luck. Can anyone offer an explanation or suggestion? (GPSBabel is freeware) > Python 2.7 on windows7 64-bit > > import subprocess > subprocess.call([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", > "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", > "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"]) If my cursory reading of GPSBabel's documentation is right, you're missing a "-F" before the output filepath. Try: subprocess.call([ r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", "-o", "gpx", "-F", r"C:\Temp\gpx\test28output.gpx", ]) Regards, Chris From python at mrabarnett.plus.com Wed Jan 30 13:11:51 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 30 Jan 2013 18:11:51 +0000 Subject: how to use subprocess to execute an exe with args and an output In-Reply-To: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> References: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> Message-ID: <51096267.4040604@mrabarnett.plus.com> On 2013-01-30 17:15, noydb wrote: > I am looking for some guidance on using subprocess to execute an EXE with arguments and an output. The below code works in that it returns a 0 exit code, but no output file is created. I have tried a few different versions of this code (used Popen instead, some stderr/stdout), but no luck. Can anyone offer an explanation or suggestion? (GPSBabel is freeware) > Python 2.7 on windows7 64-bit > > import subprocess > subprocess.call([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", > "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", > "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"]) > > If I use this below, I get a returncode of 1, exit code of 0. > import subprocess > x = subprocess.Popen([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", > "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", > "-o", "gpx", r"C:\Temp\gpx\test28output.gpx", > "shell=True", "stdout=subprocess.PIPE", "stderr=subprocess.PIPE"]) > > x.wait() > print x.returncode > > Thanks in advance for any help > The second example is incorrect. The parts starting from "shell" are supposed to be further arguments for Popen itself, not something passed to "gpsbabel.exe": x = subprocess.Popen([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) From tjreedy at udel.edu Wed Jan 30 14:58:19 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 30 Jan 2013 14:58:19 -0500 Subject: how to use subprocess to execute an exe with args and an output In-Reply-To: <51096267.4040604@mrabarnett.plus.com> References: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> <51096267.4040604@mrabarnett.plus.com> Message-ID: On 1/30/2013 1:11 PM, MRAB wrote: > On 2013-01-30 17:15, noydb wrote: >> I am looking for some guidance on using subprocess to execute an EXE >> with arguments and an output. The below code works in that it returns >> a 0 exit code, but no output file is created. I have tried a few >> different versions of this code (used Popen instead, some >> stderr/stdout), but no luck. Can anyone offer an explanation or >> suggestion? (GPSBabel is freeware) >> Python 2.7 on windows7 64-bit >> >> import subprocess >> subprocess.call([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", >> "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", >> "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"]) >> >> If I use this below, I get a returncode of 1, exit code of 0. >> import subprocess >> x = subprocess.Popen([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", >> "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", >> "-o", "gpx", r"C:\Temp\gpx\test28output.gpx", >> "shell=True", "stdout=subprocess.PIPE", >> "stderr=subprocess.PIPE"]) >> >> x.wait() >> print x.returncode >> >> Thanks in advance for any help >> > The second example is incorrect. The parts starting from "shell" are > supposed to be further arguments for Popen itself, not something passed > to "gpsbabel.exe": > > x = subprocess.Popen([r"C:\Program Files (x86)\GPSBabel\gpsbabel.exe", > "-i", "gdb", "-f", r"C:\Temp\GDBdata\testgps28.gdb", > "-o", "gpx", r"C:\Temp\gpx\test28output.gpx"], > shell=True, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > and it is apparently best to not use shell=True unless actually needed for shell processing, which I do not think is the case here. -- Terry Jan Reedy From jenn.duerr at gmail.com Wed Jan 30 13:40:47 2013 From: jenn.duerr at gmail.com (noydb) Date: Wed, 30 Jan 2013 10:40:47 -0800 (PST) Subject: how to use subprocess to execute an exe with args and an output In-Reply-To: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> References: <7c1ddf67-5a76-4e11-8ff9-1a60ef35d102@googlegroups.com> Message-ID: oh DUH! that was it, just missing the -F. Thank-you!! From fred.sells at adventistcare.org Wed Jan 30 15:05:52 2013 From: fred.sells at adventistcare.org (Sells, Fred) Date: Wed, 30 Jan 2013 20:05:52 +0000 Subject: derived class name in python 2.6/2.7 Message-ID: This is simple, but I just cannot find it after quite a bit of searching I have this basic design class A: def __init__(self): print 'I am an instance of ', self.__class__.name class B(A): pass X = B I would like this to print "I am an instance of B" but I keep getting A. Can someone help me out here. From oscar.j.benjamin at gmail.com Wed Jan 30 15:17:05 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 30 Jan 2013 20:17:05 +0000 Subject: derived class name in python 2.6/2.7 In-Reply-To: References: Message-ID: On 30 January 2013 20:05, Sells, Fred wrote: > This is simple, but I just cannot find it after quite a bit of searching > > I have this basic design > > class A: > def __init__(self): > print 'I am an instance of ', self.__class__.name Did you mean to use __name__ instead of name? > > class B(A): > pass > > X = B I assume that this is X = B() > I would like this to print "I am an instance of B" but I keep getting A. Can someone help me out here. If you make those two changes then it should do what you want. Oscar From d at davea.name Wed Jan 30 15:20:33 2013 From: d at davea.name (Dave Angel) Date: Wed, 30 Jan 2013 15:20:33 -0500 Subject: derived class name in python 2.6/2.7 In-Reply-To: References: Message-ID: <51098091.1050200@davea.name> On 01/30/2013 03:05 PM, Sells, Fred wrote: > This is simple, but I just cannot find it after quite a bit of searching > > I have this basic design > > class A: > def __init__(self): > print 'I am an instance of ', self.__class__.name > > class B(A): > pass > > > X = B > I would like this to print "I am an instance of B" but I keep getting A. Can someone help me out here. > Why would creating an alias for class B execute the initializer for either class? perhaps you meant: x = B() BTW, since you're on 2.x python, you should derive A from object. Otherwise it's an old-style class. -- DaveA From vinay_sajip at yahoo.co.uk Wed Jan 30 15:09:01 2013 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 30 Jan 2013 20:09:01 +0000 (GMT) Subject: A new script which creates Python 3.3 venvs with Distribute and pip installed in them Message-ID: <1359576541.17079.YahooMailNeo@web171404.mail.ir2.yahoo.com> Python 3.3 includes a script, pyvenv, which is used to create virtual environments. However, Distribute and pip are not installed in such environments - because, though they are popular, they are third-party packages - not part of Python. The Python 3.3 venv machinery allows customisation of virtual environments fairly readily. To demonstrate how to do this, and to provide at the same time a script which might be useful to people, I've created a script, pyvenvex.py, at https://gist.github.com/4673395 which extends the pyvenv script to not only create virtual environments, but to also install Distribute and pip into them. The script needs Python 3.3, and one way to use it is: 1. Download the script to a directory in your path, and (on Posix platforms) make it executable. 2. Add a shebang line at the top of your script, pointing to your Python 3.3 interpreter (Posix, and also Windows if you have the PEP 397 launcher which is part of Python 3.3 on Windows). 3. Run the pyvenvex script to create your virtual environments, in place of pyvenv, when you want Distribute and pip to be installed for you (this is how virtualenv sets up environments it creates). You can run the script with -h to see the command line options available, which are a superset of the pyvenv script. Regards, Vinay Sajip From ian.g.kelly at gmail.com Wed Jan 30 15:42:09 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 30 Jan 2013 13:42:09 -0700 Subject: A new script which creates Python 3.3 venvs with Distribute and pip installed in them In-Reply-To: <1359576541.17079.YahooMailNeo@web171404.mail.ir2.yahoo.com> References: <1359576541.17079.YahooMailNeo@web171404.mail.ir2.yahoo.com> Message-ID: On Wed, Jan 30, 2013 at 1:09 PM, Vinay Sajip wrote: > Python 3.3 includes a script, pyvenv, which is used to create virtual environments. However, Distribute and pip are not installed in such environments - because, though they are popular, they are third-party packages - not part of Python. > > The Python 3.3 venv machinery allows customisation of virtual environments fairly readily. To demonstrate how to do this, and to provide at the same time a script which might be useful to people, I've created a script, pyvenvex.py, at > > https://gist.github.com/4673395 > > which extends the pyvenv script to not only create virtual environments, but to also install Distribute and pip into them. The script needs Python 3.3, and one way to use it is: > > 1. Download the script to a directory in your path, and (on Posix platforms) make it executable. > 2. Add a shebang line at the top of your script, pointing to your Python 3.3 interpreter (Posix, and also Windows if you have the PEP 397 launcher which is part of Python 3.3 on Windows). > 3. Run the pyvenvex script to create your virtual environments, in place of pyvenv, when you want Distribute and pip to be installed for you (this is how virtualenv sets up environments it creates). You can run the script with -h to see the command line options available, which are a superset of the pyvenv script. I have a shell script for this: #!/bin/sh python3 -m venv $1 cd $1 . bin/activate wget http://python-distribute.org/distribute_setup.py python distribute_setup.py bin/easy_install pip From vinay_sajip at yahoo.co.uk Wed Jan 30 17:18:50 2013 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 30 Jan 2013 22:18:50 +0000 (UTC) Subject: A new script which creates Python 3.3 venvs with Distribute =?utf-8?b?YW5kCXBpcA==?= installed in them References: <1359576541.17079.YahooMailNeo@web171404.mail.ir2.yahoo.com> Message-ID: Ian Kelly gmail.com> writes: > > I have a shell script for this: > Sure - there's a similar one at https://gist.github.com/4591655 The main purpose of the script was to illustrate how to subclass venv.EnvBuilder, and I've added it as an example to the 3.3 and in-development documentation: http://docs.python.org/3/library/venv.html#an-example-of-extending-envbuilder Doing it in Python means that it runs cross-platform, offers a few benefits such as command line help, or the option to install Distribute but not pip. Regards, Vinay Sajip From pombredanne at nexb.com Thu Jan 31 04:05:17 2013 From: pombredanne at nexb.com (Philippe Ombredanne) Date: Thu, 31 Jan 2013 10:05:17 +0100 Subject: [Distutils] A new script which creates Python 3.3 venvs with Distribute and pip installed in them In-Reply-To: <1359576541.17079.YahooMailNeo@web171404.mail.ir2.yahoo.com> References: <1359576541.17079.YahooMailNeo@web171404.mail.ir2.yahoo.com> Message-ID: On Wed, Jan 30, 2013 at 9:09 PM, Vinay Sajip wrote: > Python 3.3 includes a script, pyvenv, which is used to create virtual environments. > However, Distribute and pip are not installed in such environments - because, > though they are popular, they are third-party packages - not part of Python. > The Python 3.3 venv machinery allows customisation of virtual environments > fairly readily. To demonstrate how to do this, and to provide at the same time > a script which might be useful to people, I've created a script, pyvenvex.py, at > https://gist.github.com/4673395 > which extends the pyvenv script to not only create virtual environments, but to also install Distribute and pip into them. Excellent and one step closer to sane package management .... I wonder if you could not source instead the code that is directly in the virtualenv.py scripts? it also includes the packed distribute and pip .... Meaning that would allow the installation entirely offline (with the --never-download venv flag) And btw, why pip is not part of the standard Python? This is nowadays officially recommended on Pypi as the tool to use to install package.... Per http://pypi.python.org/pypi "Get Packages: To use a package from this index either "pip install package" (get pip) or download, unpack and "python setup.py install" it." This does not make sense to me: I know about some of the controversies .... but this is rather inconsistent to recommend using a tool and not supporting it directly. -- Philippe Ombredanne +1 650 799 0949 | pombredanne at nexB.com DejaCode Enterprise at http://www.dejacode.com nexB Inc. at http://www.nexb.com From zughumancapital at yahoo.com.br Wed Jan 30 15:13:30 2013 From: zughumancapital at yahoo.com.br (zughumancapital) Date: Wed, 30 Jan 2013 20:13:30 -0000 Subject: Arpex Capital seleciona:Programador Python Jr. Message-ID: Arpex Capital seleciona para uma de suas startups: Programador Python Jr. Requisitos: - Python/Lua/Lisp/Go/Erlang, etc qualquer linguagem ex?tica vale, mesmo n?o sendo python; - Interesse por Software Livre; - Ingl?s fluente. Local de Trabalho: Centro/RJ. Forma??o: Gradu??o completa e/ou cursando Ci?ncia da Computa??o e/ou afins. Aceitamos CVs de estudantes do primeiro per?odo. Os interessados dever?o enviar CV com pretens?o salarial para kgarcia at arpexcapital.com.br, mencionando no assunto Programador Python Jr. From aramildaern at gmail.com Wed Jan 30 16:16:51 2013 From: aramildaern at gmail.com (aramildaern at gmail.com) Date: Wed, 30 Jan 2013 13:16:51 -0800 (PST) Subject: help Message-ID: Hi everyone! I don't mean to intrude, but ive heard great things about this group and ive stumped myself with my python code. heres my code: #! /usr/bin/python import sys global labelList labelList= dict() global counter counter = 0 def execute(line): if line.find("::print") != -1: stripPrint = line.find("::print") startPrint = line.find('"', stripPrint) stopPrint = line.find('"', startPrint + 1) printSection = line[startPrint + 1 : stopPrint] print(printSection) if line.find("::label") != -1: stripLabel = line.find("::label") startLabel = line.find(' ', stripLabel) stopLabel = line.find('--', startLabel + 1) label = line[startLabel + 1 : stopLabel] line.strip("\r\n") labelList[label] = counter if len(sys.argv) < 2: print("error: no input files") print("compilation terminated") else: fileName = sys.argv[1] jadeFile = open(fileName, 'r') for line in jadeFile: counter = counter + 1 execute(line) jadeFile.close() i = 0 while i < len(labelList): print(labelList.keys()[i], ":", labelList.values()[i]) i = i + 1 and its giving me a bunch of errors thanks for the help in advance! From ian.g.kelly at gmail.com Wed Jan 30 17:08:57 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 30 Jan 2013 15:08:57 -0700 Subject: help In-Reply-To: References: Message-ID: On Wed, Jan 30, 2013 at 2:16 PM, wrote: > Hi everyone! I don't mean to intrude, but ive heard great things about this group and ive stumped myself with my python code. > > heres my code: It would be helpful if you would also include the error that you get when trying to run the code. > global labelList > labelList= dict() > > global counter > counter = 0 That said, these lines stick out as being obviously wrong. The global statement is used within the context of a function to declare that a name used within that function has global scope rather than local scope. There is no meaning to using the statement at the module level like this -- Python already knows the name is global, because it's not being used within a function -- and I'd be surprised if this didn't result in a SyntaxError. From joel.goldstick at gmail.com Wed Jan 30 17:09:49 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 30 Jan 2013 17:09:49 -0500 Subject: help In-Reply-To: References: Message-ID: On Wed, Jan 30, 2013 at 4:16 PM, wrote: > Hi everyone! I don't mean to intrude, but ive heard great things about > this group and ive stumped myself with my python code. > No intrusion. That is what the list is for. Two points: You should use a descriptive subject line -- "Help" isn't really descriptive. You should run your code, cut and paste the traceback you get showing the errors. This is extremely useful for people to help you with, and as you program, you will learn how useful it can be to find problems on your own. So, do that, and come back with that info > > heres my code: > #! /usr/bin/python > > import sys > > global labelList > labelList= dict() > > global counter > counter = 0 > > def execute(line): > if line.find("::print") != -1: > stripPrint = line.find("::print") > startPrint = line.find('"', stripPrint) > stopPrint = line.find('"', startPrint + 1) > printSection = line[startPrint + 1 : stopPrint] > print(printSection) > > if line.find("::label") != -1: > stripLabel = line.find("::label") > startLabel = line.find(' ', stripLabel) > stopLabel = line.find('--', startLabel + 1) > label = line[startLabel + 1 : stopLabel] > line.strip("\r\n") > labelList[label] = counter > > if len(sys.argv) < 2: > print("error: no input files") > print("compilation terminated") > > else: > fileName = sys.argv[1] > jadeFile = open(fileName, 'r') > > for line in jadeFile: > counter = counter + 1 > execute(line) > > jadeFile.close() > > i = 0 > > while i < len(labelList): > print(labelList.keys()[i], ":", labelList.values()[i]) > i = i + 1 > > > and its giving me a bunch of errors thanks for the help in advance! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 30 17:20:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 31 Jan 2013 09:20:14 +1100 Subject: help In-Reply-To: References: Message-ID: On Thu, Jan 31, 2013 at 8:16 AM, wrote: > Hi everyone! I don't mean to intrude, but ive heard great things about this group and ive stumped myself with my python code. Hi! As others have said, this is no intrusion, but it'd help a lot if you posted your errors and used a more useful subject line. Additionally, when you post, can you give some example lines from the file? This part of your code is impossible for us to simulate: > fileName = sys.argv[1] > jadeFile = open(fileName, 'r') > > for line in jadeFile: > counter = counter + 1 > execute(line) > > jadeFile.close() But this much I can suggest: > i = 0 > > while i < len(labelList): > print(labelList.keys()[i], ":", labelList.values()[i]) > i = i + 1 Instead of iterating with a counter, you can iterate with a Python 'for' loop. for label,count in labelList.items(): print(label,":",count) It's that simple! ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 30 21:42:24 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 31 Jan 2013 13:42:24 +1100 Subject: help References: Message-ID: <5109da11$0$29998$c3e8da3$5496439d@news.astraweb.com> aramildaern at gmail.com wrote: > its giving me a bunch of errors thanks for the help in advance! Yay! Guessing games! I love guessing games! Let me see if I can guess the errors you have... /usr/bin/python: bad interpreter: No such file or directory You haven't actually got Python installed, or at least not where you think it is. Am I close? If not, I recommend that you actually show us the errors you are getting. -- Steven From d at davea.name Wed Jan 30 22:13:54 2013 From: d at davea.name (Dave Angel) Date: Wed, 30 Jan 2013 22:13:54 -0500 Subject: help In-Reply-To: References: Message-ID: <5109E172.3000100@davea.name> On 01/30/2013 04:16 PM, aramildaern at gmail.com wrote: > Hi everyone! I don't mean to intrude, but ive heard great things about this group and ive stumped myself with my python code. > > heres my code: > #! /usr/bin/python > > import sys > > global labelList > labelList= dict() > > global counter > counter = 0 > > def execute(line): > if line.find("::print") != -1: > stripPrint = line.find("::print") > startPrint = line.find('"', stripPrint) > stopPrint = line.find('"', startPrint + 1) > printSection = line[startPrint + 1 : stopPrint] > print(printSection) > > if line.find("::label") != -1: > stripLabel = line.find("::label") > startLabel = line.find(' ', stripLabel) > stopLabel = line.find('--', startLabel + 1) > label = line[startLabel + 1 : stopLabel] > line.strip("\r\n") > labelList[label] = counter > > if len(sys.argv) < 2: > print("error: no input files") > print("compilation terminated") > > else: > fileName = sys.argv[1] > jadeFile = open(fileName, 'r') > > for line in jadeFile: > counter = counter + 1 > execute(line) > > jadeFile.close() > > i = 0 > > while i < len(labelList): > print(labelList.keys()[i], ":", labelList.values()[i]) > i = i + 1 > > > and its giving me a bunch of errors thanks for the help in advance! > davea at think2:~/temppython$ python aram.py error: no input files compilation terminated These messages are triggered by sys.argv being less than 2. Cure is to pass some string as the first argument on the command line. Fixed that: davea at think2:~/temppython$ ./aram.py myfile.txt Traceback (most recent call last): File "./aram.py", line 33, in jadeFile = open(fileName, 'r') IOError: [Errno 2] No such file or directory: 'myfile.txt' (notice that I pasted the full traceback into this message.) Problem is that the program is treating that parameter as a filename, and I don't have a file by that filename. davea at think2:~/temppython$ ./aram.py aram.py ) != -1: ) (' stripLabel = line.find("::label")', ':', 20) ('!= -1:', ':', 19) Worked perfectly. Of course, nobody has said what it's supposed to do. So anything that doesn't display an error must be okay. How about describing what version of Python this is intended for, how you ran it, and what errors you're getting. Don't paraphrase, don't summarize (lots of errors ???!), just copy/paste. And if it's appropriate, show a sample data file for it to open, not attached, but pasted into your email message. -- DaveA From jason.swails at gmail.com Wed Jan 30 19:34:03 2013 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 30 Jan 2013 19:34:03 -0500 Subject: confusion with decorators Message-ID: Hello, I was having some trouble understanding decorators and inheritance and all that. This is what I was trying to do: # untested class A(object): def _protector_decorator(fcn): def newfcn(self, *args, **kwargs): return fcn(self, *args, **kwargs) return newfcn @_protector_decorator def my_method(self, *args, **kwargs): """ do something here """ class B(A): def _protector_decorator(fcn): def newfcn(self, *args, **kwargs): raise MyException('I do not want B to be able to access the protected functions') return newfcn The goal of all that was to be able to change the behavior of my_method inside class B simply by redefining the decorator. Basically, what I want is B.my_method() to be decorated by B._protector_decorator, but in the code I'm running it's decorated by A._protector_decorator. I presume this is because once the decorator is applied to my_method in class A, A.my_method is immediately bound to the new, 'decorated' function, which is subsequently inherited (and not decorated, obviously), by B. Am I correct here? My workaround was to simply copy the method from class A to class B, after which B._protector_decorator decorated the methods in B. While this doesn't make the use of decorators completely pointless (the decorators actually do something in each class, it's just different), it does add a bunch of code duplication which I was at one point hopeful to avoid. I'm still stumbling around with decorators a little, but this exercise has made them a lot clearer to me. Thanks! Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Wed Jan 30 20:12:39 2013 From: davea at davea.name (Dave Angel) Date: Wed, 30 Jan 2013 20:12:39 -0500 Subject: confusion with decorators In-Reply-To: References: Message-ID: <5109C507.3050008@davea.name> On 01/30/2013 07:34 PM, Jason Swails wrote: > Hello, > > I was having some trouble understanding decorators and inheritance and all > that. This is what I was trying to do: > > # untested > class A(object): > def _protector_decorator(fcn): > def newfcn(self, *args, **kwargs): > return fcn(self, *args, **kwargs) > return newfcn > > @_protector_decorator > def my_method(self, *args, **kwargs): > """ do something here """ > > class B(A): > def _protector_decorator(fcn): > def newfcn(self, *args, **kwargs): > raise MyException('I do not want B to be able to access the > protected functions') > return newfcn > > The goal of all that was to be able to change the behavior of my_method > inside class B simply by redefining the decorator. Basically, what I want > is B.my_method() to be decorated by B._protector_decorator, but in the code > I'm running it's decorated by A._protector_decorator. > > I presume this is because once the decorator is applied to my_method in > class A, A.my_method is immediately bound to the new, 'decorated' function, > which is subsequently inherited (and not decorated, obviously), by B. > > Am I correct here? My workaround was to simply copy the method from class > A to class B, after which B._protector_decorator decorated the methods in > B. While this doesn't make the use of decorators completely pointless (the > decorators actually do something in each class, it's just different), it > does add a bunch of code duplication which I was at one point hopeful to > avoid. > > I'm still stumbling around with decorators a little, but this exercise has > made them a lot clearer to me. > > I'm certainly not the expert on decorators; I've only used them for simple things. But I think I can clear up one misconception. The decorator function will execute while *compiling* the class A, and the one in class B is unreferenced. The decorator @_protector_decorator is shorthand for something like mymethod = _protector_decorator(mymethod) So by the time the compiler ends with class A, the mymethod has its final value. (Note, I've not used a decorator that was defined inside a class, so I'm probably missing the appropriate A. or self. or cls. overrides.) But the order of definition is still correct. A decorator executes once, just after a function is completed. -- DaveA From steve+comp.lang.python at pearwood.info Thu Jan 31 00:46:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Jan 2013 05:46:35 GMT Subject: confusion with decorators References: Message-ID: <510a053a$0$11104$c3e8da3@news.astraweb.com> On Wed, 30 Jan 2013 19:34:03 -0500, Jason Swails wrote: > Hello, > > I was having some trouble understanding decorators and inheritance and > all that. This is what I was trying to do: > > # untested > class A(object): > def _protector_decorator(fcn): > def newfcn(self, *args, **kwargs): > return fcn(self, *args, **kwargs) > return newfcn Well, that surely isn't going to work, because it always decorates the same function, the global "fcn". You probably want to add an extra parameter to the newfcn definition: def newfcn(self, fcn, *args, **kwargs): Also, I trust you realise that this is a pointless decorator that doesn't do anything useful? It just adds an extra layer of indirection, without adding any functionality. > @_protector_decorator > def my_method(self, *args, **kwargs): > """ do something here """ > > class B(A): > def _protector_decorator(fcn): > def newfcn(self, *args, **kwargs): > raise MyException('I do not want B to be able to access the > protected functions') > return newfcn That's not going to work, because B's _protector_decorator never gets called. True, it overrides A's _protector_decorator, but too late. A has already used it to decorate the methods, and B does not override those methods, so A's version are inherited. But even if it could work, it relies on class B protecting class A from B. All B needs do to overcome the protection is ... *not* define the magic decorator. > The goal of all that was to be able to change the behavior of my_method > inside class B simply by redefining the decorator. Basically, what I > want is B.my_method() to be decorated by B._protector_decorator, but in > the code I'm running it's decorated by A._protector_decorator. Yes. Remember that you don't have a B.my_method, so B merely inherits A.my_method. > I presume this is because once the decorator is applied to my_method in > class A, A.my_method is immediately bound to the new, 'decorated' > function, which is subsequently inherited (and not decorated, > obviously), by B. Correct. > Am I correct here? My workaround was to simply copy the method from > class A to class B, after which B._protector_decorator decorated the > methods in B. That's not a work-around, that's an anti-pattern. Why is B inheriting from A if you don't want it to be able to use A's methods? That's completely crazy, if you don't mind me saying so. If you don't want B to access A's methods, simply don't inherit from A. I really don't understand what you are trying to accomplish here. Possibly Java. http://dirtsimple.org/2004/12/python-is-not-java.html http://dirtsimple.org/2004/12/java-is-not-python-either.html But you can accomplish something close to what you are after like this: import functools def decorate(func): @functools.wraps(func) def inner(self, *args, **kwargs): protector = getattr(self, '_protect', None) if protector is not None: protector() return func(self, *args, **kwargs) return inner class A(object): @decorate def mymethod(self): """Do something useful.""" class B(A): def _protect(self): raise RuntimeError("I'm sorry Dave, I'm afraid I cannot do that.") Try studying that to see how it works, and then try studying it to realise how pointless it is, since it too relies on class B protecting class A from B. -- Steven From jason.swails at gmail.com Thu Jan 31 08:25:59 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 31 Jan 2013 08:25:59 -0500 Subject: confusion with decorators In-Reply-To: <510a053a$0$11104$c3e8da3@news.astraweb.com> References: <510a053a$0$11104$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jan 31, 2013 at 12:46 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Wed, 30 Jan 2013 19:34:03 -0500, Jason Swails wrote: > > > Hello, > > > > I was having some trouble understanding decorators and inheritance and > > all that. This is what I was trying to do: > > > > # untested > > class A(object): > > def _protector_decorator(fcn): > > def newfcn(self, *args, **kwargs): > > return fcn(self, *args, **kwargs) > > return newfcn > > Well, that surely isn't going to work, because it always decorates the > same function, the global "fcn". > I don't think this is right. fcn is a passed function (at least if it acts as a decorator) that is declared locally in the _protector_decorator scope. Since newfcn is bound in the same scope and fcn is not defined inside newfcn, I'm pretty sure that newfcn will just grab the fcn passed into the decorator. The following code illustrates what I'm trying to say (I think): test.py: #!/usr/bin/env python a = 3 print 'Global namespace:', a def myfunc(a): def nested_func(): print 'nested_func a is:', a, 'id(a) =', id(a) print 'passed a is:', a, 'id(a) = ', id(a) nested_func() myfunc(10) $ python test.py Global namespace: 3 passed a is: 10 id(a) = 6416096 nested_func a is: 10 id(a) = 6416096 Likewise, newfcn will use the function bound to the passed argument to the decorator. This syntax appears to work in my 'real' program. > You probably want to add an extra parameter to the newfcn definition: > > def newfcn(self, fcn, *args, **kwargs): > I don't think I want to do that, since fcn will simply become the first argument that I pass to the decorated myfunc(), and if it's not callable I'll get a traceback. Also, I trust you realise that this is a pointless decorator that doesn't > do anything useful? It just adds an extra layer of indirection, without > adding any functionality. > Naturally. I tried to contrive the simplest example to demonstrate what I wanted. In retrospect I should've picked something functional instead. > Am I correct here? My workaround was to simply copy the method from > > class A to class B, after which B._protector_decorator decorated the > > methods in B. > > That's not a work-around, that's an anti-pattern. > > Why is B inheriting from A if you don't want it to be able to use A's > methods? That's completely crazy, if you don't mind me saying so. If you > don't want B to access A's methods, simply don't inherit from A. > > I really don't understand what you are trying to accomplish here. > Again, my example code is over-simplified. A brief description of my class is a list of 'patch' (diff) files with various attributes. If I want information from any of those files, I instantiate a Patch instance (and cache it for later use if desired) and return any of the information I want from that patch (like when it was created, who created it, what files will be altered in the patch, etc.). But a lot of these patches are stored online, so I wanted a new class (a RemotePatchList) to handle lists of patches in an online repository. I can do many of the things with an online patch that I can with one stored locally, but not everything, hence my desire to squash the methods I don't want to support. I'd imagine a much more sensible approach is to generate a base class that implements all methods common to both and simply raises an exception in those methods that aren't. I agree it doesn't make much sense to inherit from an object that has MORE functionality than you want. However, my desire to use decorators was not to disable methods in one class vs. another. The _protector_decorator (a name borrowed from my actual code), is designed to wrap a function call inside a try/except, to account for specific exceptions I might raise inside. One of my classes deals with local file objects, and the other deals with remote file objects via urllib. Naturally, the latter has other exceptions that can be raised, like HTTPError and the like. So my desire was to override the decorator to handle more types of exceptions, but leave the underlying methods intact without duplicating them. I can do this without decorators easily enough, but I thought the decorator syntax was a bit more elegant and I saw an opportunity to learn more about them. Possibly Java. > I took a Java class in high school once ~10 years ago... haven't used it since. :) Truth be told, outside of Python, the languages I can work in are Fortran (and to a much lesser extent), C and C++. import functools > I need to support Python 2.4, and the docs suggest this is 2.5+. Too bad, too, since functools appears pretty useful. Thanks for the help! Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jan 31 10:28:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Feb 2013 02:28:41 +1100 Subject: confusion with decorators In-Reply-To: References: <510a053a$0$11104$c3e8da3@news.astraweb.com> Message-ID: On Fri, Feb 1, 2013 at 12:25 AM, Jason Swails wrote: > On Thu, Jan 31, 2013 at 12:46 AM, Steven D'Aprano > wrote: >> >> On Wed, 30 Jan 2013 19:34:03 -0500, Jason Swails wrote: >> >> > Hello, >> > >> > I was having some trouble understanding decorators and inheritance and >> > all that. This is what I was trying to do: >> > >> > # untested >> > class A(object): >> > def _protector_decorator(fcn): >> > def newfcn(self, *args, **kwargs): >> > return fcn(self, *args, **kwargs) >> > return newfcn >> >> Well, that surely isn't going to work, because it always decorates the >> same function, the global "fcn". > > > I don't think this is right. fcn is a passed function (at least if it acts > as a decorator) that is declared locally in the _protector_decorator scope. > Since newfcn is bound in the same scope and fcn is not defined inside > newfcn, I'm pretty sure that newfcn will just grab the fcn passed into the > decorator. Yet it adds a level of indirection that achieves nothing. Why not simply: def _protector_decorator(fcn): return fcn ? I'm not understanding the purpose here. ChrisA From jason.swails at gmail.com Thu Jan 31 11:00:58 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 31 Jan 2013 11:00:58 -0500 Subject: confusion with decorators In-Reply-To: References: <510a053a$0$11104$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jan 31, 2013 at 10:28 AM, Chris Angelico wrote: > > >> Well, that surely isn't going to work, because it always decorates the > >> same function, the global "fcn". > > > > > > I don't think this is right. fcn is a passed function (at least if it > acts > > as a decorator) that is declared locally in the _protector_decorator > scope. > > Since newfcn is bound in the same scope and fcn is not defined inside > > newfcn, I'm pretty sure that newfcn will just grab the fcn passed into > the > > decorator. > > Yet it adds a level of indirection that achieves nothing. Why not simply: > def _protector_decorator(fcn): > return fcn > > ? I'm not understanding the purpose here. > Bad example. A better (longer) one that is closer to my true use-case: from somewhere.exceptions import MyTypeError from somewhere.different import AuthorClass, RemoteAuthorClass from urllib2 import HTTPError class A(object): authorclass = AuthorClass def __init__(self, obj_list): """ Instantiate a list of obj_list objects that may have an "author" attribute """ self.things = [] for o in obj_list: if not isinstance(o, self.authorclass): raise MyTypeError('Bad type given to constructor') self.things.append(o) def _protector(fcn): def newfcn(self, *args, **kwargs): try: return fcn(self, *args, **kwargs) # returns a string except AttributeError: return 'Attribute not available.' except IndexError: return 'Not that many AuthorClasses loaded' return newfcn @_protector def author(self, idx): return self.things[idx].author @_protector def description(self, idx): return self.things[idx].description @_protector def hobbies(self, idx): return self.things[idx].hobbies class B(A): authorclass = RemoteAuthorClass def _protector(fcn): def newfcn(self, *args, **kwargs): try: return fcn(self, *args, **kwargs) except AttributeError: return 'Attribute not available' except IndexError: return 'Not that many RemoteAuthorClasses loaded' except HTTPError: return 'Could not connect' return fcn Basically, while RemoteAuthorClass and AuthorClass are related (via inheritance), the RemoteAuthorClass has the potential for HTTPError's now. I could just expand the A class decorator to catch the HTTPError, but since that should not be possible in AuthorClass, I'd rather not risk masking a bug. I'm under no impressions that the above code will decorate A-inherited functions with the B-decorator (I know it won't), but that's the effect I'm trying to achieve... Thanks! Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Candidate 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Thu Jan 31 12:53:13 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 31 Jan 2013 12:53:13 -0500 Subject: confusion with decorators In-Reply-To: References: <510a053a$0$11104$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jan 31, 2013 at 11:00 AM, Jason Swails wrote: > > > On Thu, Jan 31, 2013 at 10:28 AM, Chris Angelico wrote: > >> >> >> Well, that surely isn't going to work, because it always decorates the >> >> same function, the global "fcn". >> > >> > >> > I don't think this is right. fcn is a passed function (at least if it >> acts >> > as a decorator) that is declared locally in the _protector_decorator >> scope. >> > Since newfcn is bound in the same scope and fcn is not defined inside >> > newfcn, I'm pretty sure that newfcn will just grab the fcn passed into >> the >> > decorator. >> >> Yet it adds a level of indirection that achieves nothing. Why not simply: >> def _protector_decorator(fcn): >> return fcn >> >> ? I'm not understanding the purpose here. >> > > Bad example. A better (longer) one that is closer to my true use-case: > > > from somewhere.exceptions import MyTypeError > from somewhere.different import AuthorClass, RemoteAuthorClass > from urllib2 import HTTPError > > class A(object): > > authorclass = AuthorClass > > def __init__(self, obj_list): > """ > Instantiate a list of obj_list objects that may have an "author" > attribute > """ > self.things = [] > for o in obj_list: > if not isinstance(o, self.authorclass): > raise MyTypeError('Bad type given to constructor') > self.things.append(o) > > def _protector(fcn): > def newfcn(self, *args, **kwargs): > try: > return fcn(self, *args, **kwargs) # returns a string > except AttributeError: > return 'Attribute not available.' > except IndexError: > return 'Not that many AuthorClasses loaded' > > return newfcn > > @_protector > def author(self, idx): > return self.things[idx].author > > @_protector > def description(self, idx): > return self.things[idx].description > > @_protector > def hobbies(self, idx): > return self.things[idx].hobbies > > class B(A): > > authorclass = RemoteAuthorClass > > def _protector(fcn): > def newfcn(self, *args, **kwargs): > try: > return fcn(self, *args, **kwargs) > except AttributeError: > return 'Attribute not available' > except IndexError: > return 'Not that many RemoteAuthorClasses loaded' > except HTTPError: > return 'Could not connect' > return fcn > > Basically, while RemoteAuthorClass and AuthorClass are related (via > inheritance), the RemoteAuthorClass has the potential for HTTPError's now. > I could just expand the A class decorator to catch the HTTPError, but > since that should not be possible in AuthorClass, I'd rather not risk > masking a bug. I'm under no impressions that the above code will decorate > A-inherited functions with the B-decorator (I know it won't), but that's > the effect I'm trying to achieve... > The approach I'm switching to here is to make the decorators wrappers instead that are passed the functions that need to be called. Basically, wrap at run-time rather than 'compile time' (i.e., when the Python code is 'compiled' into class definitions). That way each child of the main class can simply change the wrapping behavior by implementing the wrapping functions instead of duplicating all of the code. And since this part of the code is not performance-intensive, I don't care about the overhead of extra function calls. It seems to me to be the more appropriate course of action here, since decorators don't seem to naturally lend themselves to what I'm trying to do. --Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Jan 31 16:31:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 01 Feb 2013 08:31:13 +1100 Subject: confusion with decorators References: <510a053a$0$11104$c3e8da3@news.astraweb.com> Message-ID: <510ae2a2$0$6599$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: >> def _protector_decorator(fcn): >> def newfcn(self, *args, **kwargs): >> return fcn(self, *args, **kwargs) >> return newfcn > > Well, that surely isn't going to work, because it always decorates the > same function, the global "fcn". Good grief, I can't believe I failed to see that fcn was declared as a parameter to _protector_decorator. > You probably want to add an extra parameter to the newfcn definition: > > def newfcn(self, fcn, *args, **kwargs): And that's also rubbish. The right place for the fcn parameter is the decorator function itself, exactly where it already is. Whatever crack I was smoking yesterday, it must have been pretty awful stuff. -- Steven From steve+comp.lang.python at pearwood.info Thu Jan 31 18:16:54 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 01 Feb 2013 10:16:54 +1100 Subject: confusion with decorators References: <510a053a$0$11104$c3e8da3@news.astraweb.com> Message-ID: <510afb67$0$30002$c3e8da3$5496439d@news.astraweb.com> Jason Swails wrote: > On Thu, Jan 31, 2013 at 12:46 AM, Steven D'Aprano < > steve+comp.lang.python at pearwood.info> wrote: >> Well, that surely isn't going to work, because it always decorates the >> same function, the global "fcn". > > I don't think this is right. It certainly isn't. Sorry for the noise. [...] > Again, my example code is over-simplified. A brief description of my > class > is a list of 'patch' (diff) files with various attributes. If I want > information from any of those files, I instantiate a Patch instance (and > cache it for later use if desired) and return any of the information I > want from that patch (like when it was created, who created it, what files > will be altered in the patch, etc.). > > But a lot of these patches are stored online, so I wanted a new class (a > RemotePatchList) to handle lists of patches in an online repository. I > can do many of the things with an online patch that I can with one stored > locally, but not everything, hence my desire to squash the methods I don't > want to support. Normally, subclasses should extend functionality, not take it away. A fundamental principle of OO design is that anywhere you could sensibly allow an instance, should also be able to use a subclass. So if you have a Patch class, and a RemotePatch subclass, then everything that a Patch can do, a RemotePatch can do too, because RemotePatch instances *are also* instances of Patch. But the rule doesn't go in reverse: you can't necessarily use a Patch instance where you were using a RemotePatch. Subclasses are allowed to do *more*, but they shouldn't do *less*. On the other hand, if you have a Patch class, and a RemotePatchList class, inheritance does not seem to be the right relationship here. A RemotePatchList does not seem to be a kind of Patch, but a kind of list. > I'd imagine a much more sensible approach is to generate a base class that > implements all methods common to both and simply raises an exception in > those methods that aren't. I agree it doesn't make much sense to inherit > from an object that has MORE functionality than you want. If a method is not common to both, it doesn't belong in the base class. The base should only include common methods. In fact, I'm usually rather suspicious of base classes that don't ever get used except as a base for subclassing. I'm not saying it's wrong, but it could be excessive abstraction. Abstraction is good, but you can have too much of a good thing. If the base class is not used, consider a flatter hierarchy: class Patch: ... class RemotePatch(Patch): ... rather than: class PatchBase: ... class Patch(PatchBase): ... class RemotePatch(Patch): ... although this is okay: class PatchBase: ... class Patch(PatchBase): ... class RemotePatch(PatchBase): ... > However, my desire to use decorators was not to disable methods in one > class vs. another. The _protector_decorator (a name borrowed from my > actual code), is designed to wrap a function call inside a try/except, to > account for specific exceptions I might raise inside. Ah, your example looked like you were trying to implement some sort of access control, where some methods were flagged as "protected" to prevent subclasses from using them. Hence my quip about Java. What you describe here makes more sense. > One of my classes > deals with local file objects, and the other deals with remote file > objects > via urllib. Naturally, the latter has other exceptions that can be > raised, > like HTTPError and the like. So my desire was to override the decorator > to handle more types of exceptions, but leave the underlying methods > intact without duplicating them. >>> decorated(3) 4 One way to do that is to keep a list of exceptions to catch: class Patch: catch_these = [SpamException, HamException] def method(self, arg): try: do_this() except self.catch_these: do_that() The subclass can then extend or replace that list: class RemotePatch(Patch): catch_these = Patch.catch_these + [EggsException, CheeseException] >> import functools > > I need to support Python 2.4, and the docs suggest this is 2.5+. Too bad, > too, since functools appears pretty useful. functools.wraps is pretty simple. You can use this as an equivalent: # `functools.wraps` was added in Python 2.5. def wraps(func_to_wrap): """Return a decorator that wraps its argument. This is a reimplementation of functools.wraps() which copies the name, module, docstring and attributes of the base function to the decorated function. wraps() is available in the standard library from Python 2.5. >>> def undecorated(x): ... '''This is a doc string.''' ... return x+1 ... >>> undecorated.__module__ = 'parrot' >>> undecorated.attr = 'something' >>> @wraps(undecorated) ... def decorated(x): ... return undecorated(x) ... >>> decorated(3) 4 >>> decorated.__doc__ 'This is a doc string.' >>> decorated.attr 'something' >>> decorated.__module__ 'parrot' >>> decorated.__name__ 'undecorated' """ def decorator(func): def f(*args, **kwargs): return func(*args, **kwargs) f.__doc__ = func_to_wrap.__doc__ try: f.__name__ = func_to_wrap.__name__ except Exception: # Older versions of Python (2.3 and older perhaps?) # don't allow assigning to function __name__. pass f.__module__ = func_to_wrap.__module__ if hasattr(func_to_wrap, '__dict__'): f.__dict__.update(func_to_wrap.__dict__) return f return decorator The doctest passes for Python 2.4. -- Steven From jason.swails at gmail.com Thu Jan 31 22:13:30 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 31 Jan 2013 22:13:30 -0500 Subject: confusion with decorators In-Reply-To: <510afb67$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <510a053a$0$11104$c3e8da3@news.astraweb.com> <510afb67$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 31, 2013 at 6:16 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > > Normally, subclasses should extend functionality, not take it away. A > fundamental principle of OO design is that anywhere you could sensibly > allow an instance, should also be able to use a subclass. > > So if you have a Patch class, and a RemotePatch subclass, then everything > that a Patch can do, a RemotePatch can do too, because RemotePatch > instances *are also* instances of Patch. > > But the rule doesn't go in reverse: you can't necessarily use a Patch > instance where you were using a RemotePatch. Subclasses are allowed to do > *more*, but they shouldn't do *less*. > > On the other hand, if you have a Patch class, and a RemotePatchList class, > inheritance does not seem to be the right relationship here. A > RemotePatchList does not seem to be a kind of Patch, but a kind of list. > > > > I'd imagine a much more sensible approach is to generate a base class > that > > implements all methods common to both and simply raises an exception in > > those methods that aren't. I agree it doesn't make much sense to inherit > > from an object that has MORE functionality than you want. > > If a method is not common to both, it doesn't belong in the base class. The > base should only include common methods. > Yes, I agree here. The only reason I was considering NOT doing this was because I wanted to control the exception that gets raised rather than let through a simple NameError. The reason, in case you care, is that I like creating my own custom excepthook() which optionally suppresses tracebacks of the base exception class of my program (which can be overridden by a --debug option of some sort). That way I don't worry about returning error codes and the like and my exceptions double as error messages which don't scare users away. Of course, if I didn't raise the exception myself, then I definitely want to know what line that error occurred on so I can fix it (since that typically means it's a bug or error I did not handle gracefully). I suppose I could get the same effect by dumping everything into a main() function somewhere and wrapping that in a try/except where I catch my base class, but I like the flexibility > In fact, I'm usually rather suspicious of base classes that don't ever get > used except as a base for subclassing. I'm not saying it's wrong, but it > could be excessive abstraction. Abstraction is good, but you can have too > much of a good thing. If the base class is not used, consider a flatter > hierarchy: > > class Patch: ... > class RemotePatch(Patch): ... > > > rather than: > > class PatchBase: ... > class Patch(PatchBase): ... > class RemotePatch(Patch): ... > > although this is okay: > > class PatchBase: ... > class Patch(PatchBase): ... > class RemotePatch(PatchBase): ... > This last one is what I've settled on. Patch and RemotePatch have common functionality. But RemotePatch can be downloaded and Patch can be parsed through (in my app, if you're going to spend the time to parse through the whole RemotePatch, it just gets downloaded and instantiated as a Patch). So this last form of inheritance made the most sense to me. > > > > However, my desire to use decorators was not to disable methods in one > > class vs. another. The _protector_decorator (a name borrowed from my > > actual code), is designed to wrap a function call inside a try/except, to > > account for specific exceptions I might raise inside. > > Ah, your example looked like you were trying to implement some sort of > access control, where some methods were flagged as "protected" to prevent > subclasses from using them. Hence my quip about Java. What you describe > here makes more sense. > > > > One of my classes > > deals with local file objects, and the other deals with remote file > > objects > > via urllib. Naturally, the latter has other exceptions that can be > > raised, > > like HTTPError and the like. So my desire was to override the decorator > > to handle more types of exceptions, but leave the underlying methods > > intact without duplicating them. > > >>> decorated(3) > 4 > > One way to do that is to keep a list of exceptions to catch: > > > class Patch: > catch_these = [SpamException, HamException] > def method(self, arg): > try: > do_this() > except self.catch_these: > do_that() > > The subclass can then extend or replace that list: > > class RemotePatch(Patch): > catch_these = Patch.catch_these + [EggsException, CheeseException] > Ha! I use this technique all the time to avoid code duplication (it's used several times in the program I'm writing). It didn't even occur to me in this context... Thanks for pointing this out! As always, the time you put into responses and helping is appreciated. All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From theller at ctypes.org Thu Jan 31 04:03:33 2013 From: theller at ctypes.org (Thomas Heller) Date: Thu, 31 Jan 2013 10:03:33 +0100 Subject: Python launcher (PEP 397) and emacs python-mode.el Message-ID: Has someone managed to patch python-mode.el to use the PEP 397 python launcher when you hit C-c C-c? It seems that emacs should parse the shebang line in the edited python script and pass the corresponding arguments to py.exe. Thomas From andreas.roehler at online.de Thu Jan 31 06:05:53 2013 From: andreas.roehler at online.de (=?ISO-8859-1?Q?Andreas_R=F6hler?=) Date: Thu, 31 Jan 2013 12:05:53 +0100 Subject: Python launcher (PEP 397) and emacs python-mode.el In-Reply-To: References: Message-ID: <510A5011.4010005@online.de> Am 31.01.2013 10:03, schrieb Thomas Heller: > Has someone managed to patch python-mode.el to use > the PEP 397 python launcher when you hit C-c C-c? > > It seems that emacs should parse the shebang line in the edited > python script and pass the corresponding arguments to py.exe. > Yes, that's the way python-mode.el acts by default. AFAIU that launcher is implemented in Python3.3 and should not need any patch at all. Should it not work, please file a bug-report at https://bugs.launchpad.net/python-mode Andreas > Thomas From theller at ctypes.org Thu Jan 31 11:35:24 2013 From: theller at ctypes.org (Thomas Heller) Date: Thu, 31 Jan 2013 17:35:24 +0100 Subject: Python launcher (PEP 397) and emacs python-mode.el In-Reply-To: References: Message-ID: Am 31.01.2013 12:05, schrieb Andreas R?hler: > Am 31.01.2013 10:03, schrieb Thomas Heller: >> Has someone managed to patch python-mode.el to use >> the PEP 397 python launcher when you hit C-c C-c? >> >> It seems that emacs should parse the shebang line in the edited >> python script and pass the corresponding arguments to py.exe. >> > > Yes, that's the way python-mode.el acts by default. > > AFAIU that launcher is implemented in Python3.3 and should not need any > patch at all. > Should it not work, please file a bug-report at > > https://bugs.launchpad.net/python-mode Well, let me make these remarks: 1. I'm on Windows, using gnu-emacs 24.2.1, and python-mode.el 6.1.0. I do not understand how the shebang line is used by python-mode.el, depending on what I write into it either 'python.exe' is started when I hit C-c C-c, or I get 'Spawning child process: invalid argument'. The latter occurs most often when the shebang string contains 'jython'. 2. I would like to use the PEP 397 python launcher to start the python version that is specified in the shebang line. The python launcher py.exe parses this line when I run 'py script.py', and then starts the corresponding python interpreter version. The launcher parses the shebang line by its own rules (see pep397 for exact details). One example is this: The python launcher starts 'c:\Python31\python.exe -3.1-32 script.py'. I would like emacs to do the same; however this would require emacs to do the same shebang line parsing as the launcher does. Thomas From vinay_sajip at yahoo.co.uk Thu Jan 31 13:26:53 2013 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 31 Jan 2013 18:26:53 +0000 (UTC) Subject: Python launcher (PEP 397) and emacs python-mode.el References: Message-ID: Thomas Heller ctypes.org> writes: > > > The python launcher starts 'c:\Python31\python.exe -3.1-32 script.py'. > That doesn't seem right, the launcher on my system launches using c:\Python31\python.exe script.py if I just run script.py, or if I invoke it as py -3.1-32 script.py it still launches using c:\Python31\python.exe script.py Regards, Vinay Sajip From andreas.roehler at online.de Thu Jan 31 13:40:19 2013 From: andreas.roehler at online.de (=?ISO-8859-1?Q?Andreas_R=F6hler?=) Date: Thu, 31 Jan 2013 19:40:19 +0100 Subject: Python launcher (PEP 397) and emacs python-mode.el In-Reply-To: References: Message-ID: <510ABA93.70607@online.de> Am 31.01.2013 17:35, schrieb Thomas Heller: > Am 31.01.2013 12:05, schrieb Andreas R?hler: >> Am 31.01.2013 10:03, schrieb Thomas Heller: >>> Has someone managed to patch python-mode.el to use >>> the PEP 397 python launcher when you hit C-c C-c? >>> >>> It seems that emacs should parse the shebang line in the edited >>> python script and pass the corresponding arguments to py.exe. >>> >> >> Yes, that's the way python-mode.el acts by default. >> >> AFAIU that launcher is implemented in Python3.3 and should not need any >> patch at all. >> Should it not work, please file a bug-report at >> >> https://bugs.launchpad.net/python-mode > > Well, let me make these remarks: > > 1. I'm on Windows, using gnu-emacs 24.2.1, and python-mode.el 6.1.0. > I do not understand how the shebang line is used by python-mode.el, it uses py-shebang-regexp to determine - if a shebang is given - if, yes, which interpreter to run > depending on what I write into it either 'python.exe' is started when > I hit C-c C-c, or I get 'Spawning child process: invalid argument'. > The latter occurs most often when the shebang string contains 'jython'. please file a bug-report giving some example script which triggers the bug > > > 2. I would like to use the PEP 397 python launcher to start the python > version that is specified in the shebang line. > The python launcher py.exe parses this line when I run 'py script.py', > and then starts the corresponding python interpreter version. > The launcher parses the shebang line by its own rules (see pep397 for > exact details). One example is this: > > > > The python launcher starts 'c:\Python31\python.exe -3.1-32 script.py'. > unfortunatly don't have a windows at my disposal. At linux it would run exactly the interpreter specified. Might be okay for windows as shown. > I would like emacs to do the same; however this would require emacs > to do the same shebang line parsing as the launcher does. > So we do - looks like python-mode.el precedes PEP 397 :) Expecting the bug elsewhere. > Thomas From theller at ctypes.org Thu Jan 31 15:53:23 2013 From: theller at ctypes.org (Thomas Heller) Date: Thu, 31 Jan 2013 21:53:23 +0100 Subject: Python launcher (PEP 397) and emacs python-mode.el In-Reply-To: References: Message-ID: Am 31.01.2013 19:26, schrieb Vinay Sajip: > Thomas Heller ctypes.org> writes: > >> >> >> The python launcher starts 'c:\Python31\python.exe -3.1-32 script.py'. >> > > That doesn't seem right, the launcher on my system launches using > > c:\Python31\python.exe script.py > > if I just run script.py, or if I invoke it as > > py -3.1-32 script.py > > it still launches using > > c:\Python31\python.exe script.py Sorry for the confusion that I am causing. Vinay, you are right of course. What I meant to write is this: when the shebang line in script.py contains this: #!/usr/bin/python3.1-32 then emacs SHOULD run py.exe -3.1-32 script.py and the launcher runs c:\Python31\python.exe script.py Thomas From vinay_sajip at yahoo.co.uk Thu Jan 31 18:59:31 2013 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 31 Jan 2013 23:59:31 +0000 (UTC) Subject: Python launcher (PEP 397) and emacs python-mode.el References: Message-ID: Thomas Heller ctypes.org> writes: > What I meant to write is this: > > when the shebang line in script.py contains this: > #!/usr/bin/python3.1-32 > then emacs SHOULD run > py.exe -3.1-32 script.py > and the launcher runs > c:\Python31\python.exe script.py IMO it would be better for emacs to just run py.exe script.py and py.exe can read the shebang and do the right thing. This saves the emacs code from having to duplicate the shebang line processing logic that py.exe uses (which, as we know, is unusual. So for a cross-platform you can have a shebang line of #!/usr/bin/python3.2, and on Windows it will still call the appropriate Python 3.2 even if it's not in /usr/bin, as there's no /usr/bin :-)) Regards, Vinay Sajip From jenn.duerr at gmail.com Thu Jan 31 08:33:48 2013 From: jenn.duerr at gmail.com (noydb) Date: Thu, 31 Jan 2013 05:33:48 -0800 (PST) Subject: advice, python for binary to xml Message-ID: <6ddffcda-ecc1-4ffb-8eef-5a497aede4b8@googlegroups.com> I'm looking for knowlegde about how best to go about converting a binary file (from a GPS unit) to GPX/XML. I am completely clueless on this, so any start-from-the-beginning info would be greatly appreciated! I'm guessing the level of effort will be huge? Python 2.7, Windows 7 From maarten.sneep at knmi.nl Thu Jan 31 08:41:34 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Thu, 31 Jan 2013 05:41:34 -0800 (PST) Subject: advice, python for binary to xml In-Reply-To: <6ddffcda-ecc1-4ffb-8eef-5a497aede4b8@googlegroups.com> References: <6ddffcda-ecc1-4ffb-8eef-5a497aede4b8@googlegroups.com> Message-ID: On Thursday, January 31, 2013 2:33:48 PM UTC+1, noydb wrote: > I'm looking for knowlegde about how best to go about converting a binary file (from a GPS unit) to GPX/XML. I am completely clueless on this, so any start-from-the-beginning info would be greatly appreciated! I'm guessing the level of effort will be huge? I assume that you've looked into GPSBabel? http://www.gpsbabel.org/ Maarten From jenn.duerr at gmail.com Thu Jan 31 10:05:43 2013 From: jenn.duerr at gmail.com (noydb) Date: Thu, 31 Jan 2013 07:05:43 -0800 (PST) Subject: advice, python for binary to xml In-Reply-To: References: <6ddffcda-ecc1-4ffb-8eef-5a497aede4b8@googlegroups.com> Message-ID: <15feebe0-22fe-48a3-ae73-ee4d2fc8c705@googlegroups.com> On Thursday, January 31, 2013 8:41:34 AM UTC-5, Maarten wrote: > On Thursday, January 31, 2013 2:33:48 PM UTC+1, noydb wrote: > > > I'm looking for knowlegde about how best to go about converting a binary file (from a GPS unit) to GPX/XML. I am completely clueless on this, so any start-from-the-beginning info would be greatly appreciated! I'm guessing the level of effort will be huge? > > > > I assume that you've looked into GPSBabel? http://www.gpsbabel.org/ > > > > Maarten Yes, I have. Was hoping to use it, but client is very resistent to adding such things to their system - python is desireable. So what GPSbabel does is what I need, just one translation, from Garmin's gdb file (binary) to gpx. From maarten.sneep at knmi.nl Thu Jan 31 12:17:07 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Thu, 31 Jan 2013 09:17:07 -0800 (PST) Subject: advice, python for binary to xml In-Reply-To: <15feebe0-22fe-48a3-ae73-ee4d2fc8c705@googlegroups.com> References: <6ddffcda-ecc1-4ffb-8eef-5a497aede4b8@googlegroups.com> <15feebe0-22fe-48a3-ae73-ee4d2fc8c705@googlegroups.com> Message-ID: <8e17292e-f2bd-431a-9234-d370b5ddbec2@googlegroups.com> On Thursday, January 31, 2013 4:05:43 PM UTC+1, noydb wrote: > > I assume that you've looked into GPSBabel? http://www.gpsbabel.org/ > > Yes, I have. Was hoping to use it, but client is very resistent to adding such things to their system - python is desireable. So what GPSbabel does is what I need, just one translation, from Garmin's gdb file (binary) to gpx. They realize that they'll get a much higher bill, and more bugs to boot? I don't think there is an easy way around this, but at least you have some code to start reading gdb - as far as I know the GPSBabel sources are the only public description of the gdb file format. It is not trivial, but restricting yourself to the parts needed for the application may provide some shortcuts. Maarten - pay more, get less: way to go. From jenn.duerr at gmail.com Thu Jan 31 12:34:10 2013 From: jenn.duerr at gmail.com (noydb) Date: Thu, 31 Jan 2013 09:34:10 -0800 (PST) Subject: advice, python for binary to xml In-Reply-To: <8e17292e-f2bd-431a-9234-d370b5ddbec2@googlegroups.com> References: <6ddffcda-ecc1-4ffb-8eef-5a497aede4b8@googlegroups.com> <15feebe0-22fe-48a3-ae73-ee4d2fc8c705@googlegroups.com> <8e17292e-f2bd-431a-9234-d370b5ddbec2@googlegroups.com> Message-ID: <6100ab60-8382-48ea-bb54-8d90a8e18342@googlegroups.com> :-) yeah... From alexandra at compulab.co.il Thu Jan 31 08:03:32 2013 From: alexandra at compulab.co.il (alexandra) Date: Thu, 31 Jan 2013 15:03:32 +0200 Subject: PyGresql 4.1.1 for python2.7 Message-ID: <510A6BA4.4070306@compulab.co.il> An HTML attachment was scrubbed... URL: From jknupp at gmail.com Thu Jan 31 09:25:40 2013 From: jknupp at gmail.com (jknupp at gmail.com) Date: Thu, 31 Jan 2013 06:25:40 -0800 (PST) Subject: "Writing Idiomatic Python" book now available Message-ID: <84172c4a-626c-41ce-84e3-3f66d54f3f02@googlegroups.com> Just wanted to let everyone know I've just released a book: Writing Idiomatic Python (http://www.jeffknupp.com/writing-idiomatic-python-ebook/). It's presented as a series of examples of Pythonic code broken down by topic (e.g. lists, strings, classes, arranging your code, etc.). There are separate versions for Python 2.7.3 and Python 3.3. It's also available on Google Play Books and Amazon. Hopefully, some people in this group will find it useful. From kryptox.exchange at gmail.com Thu Jan 31 11:43:03 2013 From: kryptox.exchange at gmail.com (kryptox.exchange at gmail.com) Date: Thu, 31 Jan 2013 08:43:03 -0800 (PST) Subject: Need some help confirming transactions using sha256 Message-ID: <21037ba0-57e5-4e44-8d50-6503a1187492@googlegroups.com> I'm wondering if anyone can help me as I can't seem to get this to work. There is an online dice game that is provably fair by calculating the 'dice roll' using using a sha256 hash calculated against my transaction ID generated by me. The secret used to make the calculation is revealed at the end of each day thus allowing you to prove they didn't cheat. So they provide the following to allow you to verify the calculation of the dice roll: Secret used = r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA Secret hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA) = 48d78d573b9b8e11a13a72d9a78011f2e5d9754d89de47b209f32c51777f535d Lucky hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA:108128 06653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1) = dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4 Lucky Number 0x48e4 = 18660 So, I'm doing the following: C:\Python27>python Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib, hmac >>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA' >>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1' >>> for nout in range(10): print nout, int(hmac.new(secret, "%s:%d" % (txid, nout), hashlib.sha256).hexdigest()[:4], 16) ... 0 39800 1 4705 2 24058 3 11188 4 36307 5 781 6 62165 7 44612 8 17042 9 46099 >>> idx 1 should equal 18660 but it doesn't. What am I doing wrong? Secondly, I'm wondering if someone could help take it one step further. I would like to import a .txt file with a unique transaction ID on each line. So txid = transactions.txt or something like this. I would like it to get the "lucky number" based on a static sha256 which I would supply and the script would output the result to a text file. I'd like the output to be for idx 1 only. ie. "txid here", "lucky number for idx 1" Thanks for any help in advance! Edit/Delete Message From kryptox.exchange at gmail.com Thu Jan 31 12:30:59 2013 From: kryptox.exchange at gmail.com (kryptox.exchange at gmail.com) Date: Thu, 31 Jan 2013 09:30:59 -0800 (PST) Subject: Need some help confirming transactions using sha256 In-Reply-To: <21037ba0-57e5-4e44-8d50-6503a1187492@googlegroups.com> References: <21037ba0-57e5-4e44-8d50-6503a1187492@googlegroups.com> Message-ID: <86472650-e712-4fc4-9ca5-0a6b96229210@googlegroups.com> Ok, I'm still stuck! :( I do however now think that I'm not supposed to use hmac here. From ppearson at nowhere.invalid Thu Jan 31 12:55:05 2013 From: ppearson at nowhere.invalid (Peter Pearson) Date: 31 Jan 2013 17:55:05 GMT Subject: Need some help confirming transactions using sha256 References: <21037ba0-57e5-4e44-8d50-6503a1187492@googlegroups.com> Message-ID: On Thu, 31 Jan 2013 08:43:03 -0800 (PST), kryptox.exchange at gmail.com wrote: > I'm wondering if anyone can help me as I can't seem to get > this to work. There is an online dice game that is > provably fair by calculating the 'dice roll' using using a > sha256 hash calculated against my transaction ID generated > by me. The secret used to make the calculation is revealed > at the end of each day thus allowing you to prove they > didn't cheat. So they provide the following to allow you > to verify the calculation of the dice roll: > > Secret used = r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA > Secret hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA) = 48d78d573b9b8e11a13a72d9a78011f2e5d9754d89de47b209f32c51777f535d > Lucky hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA:108128 06653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1) = dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4 > > Lucky Number 0x48e4 = 18660 > > So, I'm doing the following: > > C:\Python27>python > Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import hashlib, hmac >>>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA' >>>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1' [snip] >>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA' >>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1' >>> hashlib.sha256(txid+":"+secret).hexdigest() 'dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4' >>> 0x48e4 18660 >>> . . . which is the number you wanted, right? -- To email me, substitute nowhere->spamcop, invalid->net. From kryptox.exchange at gmail.com Thu Jan 31 13:44:24 2013 From: kryptox.exchange at gmail.com (kryptox.exchange at gmail.com) Date: Thu, 31 Jan 2013 10:44:24 -0800 (PST) Subject: Need some help confirming transactions using sha256 In-Reply-To: References: <21037ba0-57e5-4e44-8d50-6503a1187492@googlegroups.com> Message-ID: On Thursday, January 31, 2013 6:55:05 PM UTC+1, Peter Pearson wrote: > On Thu, 31 Jan 2013 08:43:03 -0800 (PST), kryptox.exchange at gmail.com wrote: > > > > > I'm wondering if anyone can help me as I can't seem to get > > > this to work. There is an online dice game that is > > > provably fair by calculating the 'dice roll' using using a > > > sha256 hash calculated against my transaction ID generated > > > by me. The secret used to make the calculation is revealed > > > at the end of each day thus allowing you to prove they > > > didn't cheat. So they provide the following to allow you > > > to verify the calculation of the dice roll: > > > > > > Secret used = r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA > > > Secret hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA) = 48d78d573b9b8e11a13a72d9a78011f2e5d9754d89de47b209f32c51777f535d > > > Lucky hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA:108128 06653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1) = dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4 > > > > > > Lucky Number 0x48e4 = 18660 > > > > > > So, I'm doing the following: > > > > > > C:\Python27>python > > > Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 > > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> import hashlib, hmac > > >>>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA' > > >>>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1' > > [snip] > > > > >>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA' > > >>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1' > > >>> hashlib.sha256(txid+":"+secret).hexdigest() > > 'dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4' > > >>> 0x48e4 > > 18660 > > >>> > > > > . . . which is the number you wanted, right? > > > > > > -- > > To email me, substitute nowhere->spamcop, invalid->net. Yes, thank you Peter! From python.list at tim.thechases.com Thu Jan 31 14:03:05 2013 From: python.list at tim.thechases.com (python.list at tim.thechases.com) Date: Thu, 31 Jan 2013 13:03:05 -0600 Subject: (any)dbm module lacks a context manager Message-ID: <20130131130305.40fc78a8@bigbox.christie.dr> I don't know if this has been remedied in a more recent version than I've got on my box (Debian Stable), but it seems like it should work out of the box: Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dbm >>> with dbm.open("mydb", 'c') as d: ... d["hello"] = "world" ... Traceback (most recent call last): File "", line 1, in AttributeError: '_dbm.dbm' object has no attribute '__exit__' I'm guessing it's an easy fix? (or even already fixed) -tkc From nick.cash at npcinternational.com Thu Jan 31 14:34:16 2013 From: nick.cash at npcinternational.com (Nick Cash) Date: Thu, 31 Jan 2013 19:34:16 +0000 Subject: (any)dbm module lacks a context manager In-Reply-To: <20130131130305.40fc78a8@bigbox.christie.dr> References: <20130131130305.40fc78a8@bigbox.christie.dr> Message-ID: <846C3A8E860C4344B567D813B63AA51D7413F072@BL2PRD0610MB349.namprd06.prod.outlook.com> > >>> import dbm > >>> with dbm.open("mydb", 'c') as d: > ... d["hello"] = "world" > ... > Traceback (most recent call last): > File "", line 1, in > AttributeError: '_dbm.dbm' object has no attribute '__exit__' This error message is somewhat misleading... it actually means you're trying to use an object as a context manager, and it doesn't implement the context manager protocol (defined __enter__ and __exit__ methods). In this case, db.open() returns a dict -like object that is not a context manager. You'd need to refactor your code to something like: import dbm d = dbm.open("mydb", 'c') d["hello"] = "world" d.close() You may want to wrap any actions on d with a try-except-finally so you can always close the db. If dbm objects were real context managers, they would do this for you. This does seem like a useful enhancement. It might be slightly involved to do, as the dbm module has multiple implementations depending on what libraries are available on the OS. -Nick Cash From tjreedy at udel.edu Thu Jan 31 17:38:25 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 31 Jan 2013 17:38:25 -0500 Subject: (any)dbm module lacks a context manager In-Reply-To: <20130131130305.40fc78a8@bigbox.christie.dr> References: <20130131130305.40fc78a8@bigbox.christie.dr> Message-ID: On 1/31/2013 2:03 PM, python.list at tim.thechases.com wrote: > I don't know if this has been remedied in a more recent version than > I've got on my box (Debian Stable), but it seems like it should work > out of the box: > > Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import dbm >>>> with dbm.open("mydb", 'c') as d: > ... d["hello"] = "world" > ... > Traceback (most recent call last): > File "", line 1, in > AttributeError: '_dbm.dbm' object has no attribute '__exit__' > > > I'm guessing it's an easy fix? (or even already fixed) Go to our public tracker, enter 'dbm context manager' in the top search box, (change Status to 'don't care' in case there is a closed issue,) and you get one hit: http://bugs.python.org/issue11287 (Awaiting response to most recent patch review.) -- Terry Jan Reedy From chris at simplistix.co.uk Thu Jan 31 17:05:29 2013 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 31 Jan 2013 22:05:29 +0000 Subject: xlrd 0.9.0 released, now with Python 3 support! Message-ID: <510AEAA9.2030106@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.9.0: http://pypi.python.org/pypi/xlrd/0.9.0 This release means the supported versions of Python supported by xlrd are 2.6, 2.7, 3.2 and 3.3! Very exciting stuff, and a massive thank you to Thomas Kluyver (@takluyver on GitHub) for doing the bulk of the work to make this happen. Also thanks to Martin Panter (@vadmium in GitHub, if I'm following correctly) for his additional work on the pull request and Manfred Moitzi for re-licensing his unit tests so we could include them. This is obviously a big release, so I wouldn't recommend jumping on it in production just yet, but it would be great if people could get testing on both Python 2 and Python 3. If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlrd/issues Full details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From dg.google.groups at thesamovar.net Thu Jan 31 20:05:07 2013 From: dg.google.groups at thesamovar.net (dg.google.groups at thesamovar.net) Date: Thu, 31 Jan 2013 17:05:07 -0800 (PST) Subject: Help the visibility of Python in computational science Message-ID: Hi everyone, There is currently a competition running that could help give Python in computational science a bit of visibility. The competition is for the most popular recently published article on the Scholarpedia website, one of which is about a Python package "Brian" for computational neuroscience simulations. If you could take one minute to make sure you are signed in to your Google+ account and click the g+1 icon near the top right of the page, it has a chance of winning the competition. Here's the link to the article: http://www.scholarpedia.org/article/Brian_simulator Full disclosure, I'm the first author of that article, and I'd be happy to win the competition too. :) More details: Scholarpedia is an alternative to wikipedia with slightly tighter control: contributions only allowed from scholars, etc. "Brain Corporation" is offering $10000 in prizes to the top 3 most popular entries published between last October and this June based on google +1 votes. It's a bit of a silly popularity contest because of this, but I still think it would be great if a Python based thing could win it. "Brian" is a package I wrote (with several others) to do simulations of spiking neural networks in Python. Read the article if you want to know more! :) Thanks all for your attention, Dan From rosuav at gmail.com Thu Jan 31 20:16:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Feb 2013 12:16:25 +1100 Subject: Help the visibility of Python in computational science In-Reply-To: References: Message-ID: On Fri, Feb 1, 2013 at 12:05 PM, wrote: > "Brian" is a package I wrote (with several others) to do simulations of > spiking neural networks in Python. Read the article if you want to know > more! :) Ah, I don't need to read it. You're simulating a brain; the rest is mere appendix! (couldn't resist quoting the great detective being wrong) I don't do social networking though, sorry. Networking is my antidote to being social. :) ChrisA From tjreedy at udel.edu Thu Jan 31 22:06:44 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 31 Jan 2013 22:06:44 -0500 Subject: Help the visibility of Python in computational science In-Reply-To: References: Message-ID: On 1/31/2013 8:05 PM, dg.google.groups at thesamovar.net wrote: > Hi everyone, > > There is currently a competition running that could help give Python in > computational science a bit of visibility. The competition is for the > most popular recently published article on the Scholarpedia website, one > of which is about a Python package "Brian" for computational > neuroscience simulations. If you could take one minute to make sure you > are signed in to your Google+ account and click the g+1 icon near the > top right of the page, it has a chance of winning the competition. > Here's the link to the article: > > http://www.scholarpedia.org/article/Brian_simulator 'Brian' is obviously a play on 'brain', with two letters transposed. But comparison of the logo on the page above with the image on https://en.wikipedia.org/wiki/Life_of_brian shows another source ;-). -- Terry Jan Reedy From dg.google.groups at thesamovar.net Thu Jan 31 22:45:39 2013 From: dg.google.groups at thesamovar.net (dg.google.groups at thesamovar.net) Date: Thu, 31 Jan 2013 19:45:39 -0800 (PST) Subject: Help the visibility of Python in computational science In-Reply-To: References: Message-ID: <0f9682de-d485-4aa4-bea7-c9730ebb8ead@googlegroups.com> On Thursday, January 31, 2013 10:06:44 PM UTC-5, Terry Reedy wrote: > On 1/31/2013 8:05 PM, dg.google.groups at thesamovar.net wrote: > > Here's the link to the article: > > http://www.scholarpedia.org/article/Brian_simulator > > 'Brian' is obviously a play on 'brain', with two letters transposed. But > > comparison of the logo on the page above with the image on > > https://en.wikipedia.org/wiki/Life_of_brian > > shows another source ;-). > Pure coincidence I assure you, I'm just very stuck in the old days of web design with 3D text logos. ;) Dan From dg.google.groups at thesamovar.net Thu Jan 31 22:45:39 2013 From: dg.google.groups at thesamovar.net (dg.google.groups at thesamovar.net) Date: Thu, 31 Jan 2013 19:45:39 -0800 (PST) Subject: Help the visibility of Python in computational science In-Reply-To: References: Message-ID: <0f9682de-d485-4aa4-bea7-c9730ebb8ead@googlegroups.com> On Thursday, January 31, 2013 10:06:44 PM UTC-5, Terry Reedy wrote: > On 1/31/2013 8:05 PM, dg.google.groups at thesamovar.net wrote: > > Here's the link to the article: > > http://www.scholarpedia.org/article/Brian_simulator > > 'Brian' is obviously a play on 'brain', with two letters transposed. But > > comparison of the logo on the page above with the image on > > https://en.wikipedia.org/wiki/Life_of_brian > > shows another source ;-). > Pure coincidence I assure you, I'm just very stuck in the old days of web design with 3D text logos. ;) Dan From ben+python at benfinney.id.au Thu Jan 31 21:07:46 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 01 Feb 2013 13:07:46 +1100 Subject: why no pydoc python? References: <20130131145738.01cbd61ba1b671a797e8d951@lavabit.com> Message-ID: <7wr4l0yefh.fsf@benfinney.id.au> rh writes: > I installed python from tarball and I wonder if I did something wrong. > pydoc pydoc works fine but there's no pydoc python. What would you expect ?pydoc python? to show? The word ?python? is not a keyword, is not a built-in identifier, is not a standard library module. > There is a man page for python. Maybe there is no python doc for > pydoc? There is a man page for the command ?python? because it's a command that can be invoked from the operating system shell. Python's documentation (accessed with the ?pydoc? command) is not the place to document that. -- \ ?My doctor told me to stop having intimate dinners for four. | `\ Unless there are three other people.? ?Orson Welles | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Jan 31 23:24:10 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 01 Feb 2013 15:24:10 +1100 Subject: why no pydoc python? References: <20130131145738.01cbd61ba1b671a797e8d951@lavabit.com> <7wr4l0yefh.fsf@benfinney.id.au> <20130131193926.92c63c86ebe239163e8d1e5f@lavabit.com> Message-ID: <7wehh0ek5x.fsf@benfinney.id.au> rh writes: > pydoc can be invoked from the operating system shell. Which is irrelevant to what ?pydoc? produces, since it is looking in the Python documentation. You'll notice that ?pydoc pydoc? does not give the contents of the ?pydoc? manpage. Instead, it gives documentation for the ?pydoc? module, as expected. > So the question remains, why not? Because the ?pydoc? command is for displaying Python documentation, not man pages. -- \ ?Are you pondering what I'm pondering?? ?I think so, Brain, but | `\ pants with horizontal stripes make me look chubby.? ?_Pinky and | _o__) The Brain_ | Ben Finney From contact at xavierho.com Thu Jan 31 23:14:49 2013 From: contact at xavierho.com (Xavier Ho) Date: Fri, 1 Feb 2013 15:14:49 +1100 Subject: Python 2 multiprocessing examples in docs.python.org Message-ID: Hey all, I ran the example code on multiprocessing. On the "Pool example", an assertion failed with "testing garbage collection". Traceback (most recent call last): File "test.py", line 314, in test() File "test.py", line 295, in test assert not worker.is_alive() AssertionError The relevant example code reads: pool = multiprocessing.Pool(2) DELTA = 0.1 processes = pool._pool ignore = pool.apply(pow3, [2]) results = [pool.apply_async(time.sleep, [DELTA]) for i in range(100)] results = pool = None time.sleep(DELTA * 2) for worker in processes: assert not worker.is_alive() My questions are 1) How does that GC test work, and 2) Does that mean my GC isn't working as fast as it should have been? The machine's Python: xav ? /tmp > python Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From wheelman.fm at gmail.com Thu Jan 31 23:16:37 2013 From: wheelman.fm at gmail.com (wheelman.fm at gmail.com) Date: Thu, 31 Jan 2013 20:16:37 -0800 (PST) Subject: Cheat Engine In Python Message-ID: <1b7d037e-c476-4790-8ed7-08867e4cd194@googlegroups.com> Are there any softwares like cheat engine and written in python , I mean just the code not compiled ? Thanks .
??????? ?????????? %d
%s %s %s %s %s %s %s
%s
%s
%s
%s
%s
%s
%s
%s
%s >
%s %s
?%s ?
?%s ? ?%s ?
%s %s
?%s ?
?%s ? ?%s ?
%s %s
%s %s
%s
%s %s
%s
%s
%s
%s
%s
%s
%s %s %s %s