[Tutor] Bundle help!
I'm to use the bundle method to append some information to a list. I have no idea how to do that! I have Python for Dummies and I think I need Python for Complete Idiots because I am not seeing how to do this!! I have basic C+ knowledge and about 6 programs to write (in one month's time!) and I know NOTHING!! HELP!!! Sara - 8:00? 8:25? 8:40? Find a flick in no time with theYahoo! Search movie showtime shortcut.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help! Pickle file
This may sound silly, but when writing a program where there is a pickle file, how does that get included into the entire program? For instance; to create a new pickle file.. #!/usr/bin/python # Filename: pickling.py import cPickle as p #import pickle as p (snipped from python.org) Does this fall anywhere in the program in particular? I'm REALLY unfamiliar with this and I'm using Python for Dummies and Python.org. Thanks! SJ - Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Key Error
Sorry, this is probably too general a question, but I can't find any specific information on it. What exactly is a "key error" and how do I clear it? I entered something like this: abcd=h[key]['ABCD'] and when I run it I'm getting KeyError: 'ABCD' What does this mean? Thanks! - Shape Yahoo! in your own image. Join our Network Research Panel today!___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Key Error
Probably best if I skip the example and show what code I do have: ~~~ for key in h.keys(): wssd=h[key]['WSSD'] wspd=h[key]['WSPD'] wmax=h[key]['WMAX'] newi=h[key]['NEWI'] if wssd<-989. or wspd<-989. or wmax<-989.: break if wspd==0.: break ~ Where the "newi" = "abcd" that I showed before. I have no where else in my code anything pertaining to these 4 keys. The first 3 were there, and produce no errors. I am making adjustments to an existing script. I only have C programming knowledge so my thought was that it "newi" was just a variable that needed to be assigned. You'll notice the parameters below (i.e., if wssd < -989 ) but there is obviously nothing for "newi" at the moment. The program's only error at the moment seems to be this line: newi=h[key]['NEWI'] But as you can see, the other items are set up the same way. Thanks bundles!!! Sara Message: 7 Date: Sun, 08 Jul 2007 02:21:25 -0400 From: Brian van den Broek Subject: Re: [Tutor] Key Error To: [EMAIL PROTECTED] Cc: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Sara Johnson said unto the world upon 07/08/2007 01:34 AM: > Sorry, this is probably too general a question, but I can't find > any specific information on it. What exactly is a "key error" and > how do I clear it? > > I entered something like this: > > abcd=h[key]['ABCD'] > > and when I run it I'm getting > > KeyError: 'ABCD' > > What does this mean? > > Thanks! > Hi Sara, It means you've tried to access a data structure (most likely a dictionary) with a key that does not exist in that structure. Witness >>> my_dict={42:"Six times seven", 1: "The loneliest number"} >>> my_dict[42] 'Six times seven' >>> my_dict['42'] Traceback (most recent call last): File "", line 1, in KeyError: '42' >>> my_dict[17] Traceback (most recent call last): File "", line 1, in KeyError: 17 >>> It isn't a question of `clearing' it, but of tracking down the wrong assumption behind your code. It may be that you thought you were using a key you'd added before and were wrong (my_dict['42'] as opposed to my_dict[42] shows a common source of that). But, from your > abcd=h[key]['ABCD'] I'm guessing that you've got the key-access syntax a bit wrong. Did you mean abcd = h['ABCD'] instead? HTH, Brian vdB - Don't get soaked. Take a quick peak at the forecast with theYahoo! Search weather shortcut.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Key Error
I appologize...but what is, 'grep'? I'm at the end of my rope, which right now looks about as sturdy as string (and I don't mean a string buffer either)!!! Okay, where to go from here... Again, as I mentioned there may be holes in what I'm giving but that's because 1). segments of this program do work, and I don't want to overload this list with my Python problems (and believe me, I have enough to probably keep you kind, knowledgable folks busy for weeks!) and 2). I don't always know if I'm giving you all enough information to decipher my mess, or too much information. I believe 'NEWI' is supposed to be a new subkey that will hold a value called 'newind.' But if I can't get the program to initialize this 'NEWI' then I don't know how any values can come from it. Thanks anyways... I'll keep digging, Sara "Sara Johnson" wrote > Probably best if I skip the example and show what code I do have: > ~~~ > for key in h.keys(): > wssd=h[key]['WSSD'] > wspd=h[key]['WSPD'] > wmax=h[key]['WMAX'] > newi=h[key]['NEWI'] > if wssd<-989. or wspd<-989. or wmax<-989.: break > if wspd==0.: break > ~ > Where the "newi" = "abcd" that I showed before. OK, Then that is telling us that h is a dictionary containing further dictionaries inside. The error tells us that at least one of the dictionaries does not have a key 'NEWI' If this code is supposed to be production strength it is not of good quality. It should either be defending these dictionary accesses with a try/except block or it should be using the get() method of the dictionary to force a default value. (The tests at the end are poorly written too. If one of my team produced code like this I'd be having strong words with them!) Which is the best solution will depend on the situation... > I have no where else in my code anything pertaining to > these 4 keys. Might I suggest grep? :-) > The first 3 were there, and produce no errors. I am making > adjustments to an existing script. I only have C programming > knowledge I hope you have at least basic Python too? Otherwise even reading the code will be difficult. While Python is easy to read thats a strictly relative measure! > so my thought was that it "newi" was just a variable that > needed to be assigned. newi is indeed a "just a variable" that is being assigned a value, but the value does not exist. This is a data error, your problems lie in the initialisation of the dictionaries coupled to the vulnerability of the code to this kind of error. > You'll notice the parameters below (i.e., if wssd < -989 ) but > there is obviously nothing for "newi" at the moment. Indeed, but there may be further on. Its certainly not involved in any of these tests. > The program's only error at the moment seems to be this line: > > newi=h[key]['NEWI'] The program has several errors IMHO but the one that is causing the interpreter to complain is due to non existent data. You need to find why that data is missing. Or, you could find a valid default value and assign that, either through a try/except block or by uysing a get() instead of key access. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld - Get the Yahoo! toolbar and be alerted to new email wherever you're surfing. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Key Error
If this is in reference to the code that I listed. I have no experience with Python so I may have left something off unknowingly which resulted in him questioning whatever was there. The strong words probably should be directed at me for not knowing what I'm doing. jim stockford <[EMAIL PROTECTED]> wrote: On Jul 8, 2007, at 9:45 AM, Alan Gauld wrote: > (The tests at the end > are poorly written too. If one of my team produced code like > this I'd be having strong words with them!) If you'd be willing to share your strong words, I'd be grateful to learn better alternatives. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor - We won't tell. Get more on shows you hate to love (and love to hate): Yahoo! TV's Guilty Pleasures list.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bundle help!
I brought this up with Kent a little while ago... >>>If you have a list of pairs of (name, percentage) then you should be >>>able to sort it directly with the sort() method of the list. For >>>example: >>>In [3]: data = [ ('Kent', 50), ('Sara', 80), ('Fred', 20) ] >>>In [4]: data.sort() >>>In [5]: data >>>Out[5]: [('Fred', 20), ('Kent', 50), ('Sara', 80)] >Use append() to add more data, then sort again to get it in order: >>>In [6]: data.append(('Joe', 90)) >>>In [7]: data.sort() >>>In [8]: data >>>Out[8]: [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)] What happens if I need to sort alphabetical and numerically? I guess in this case it would be ('Fred', 20), ('Joe', 50), ('Kent', 80), ('Sara', 90) I'm taking the original list and the original values i.e., ('Fred', 20), ('Joe', 90), ('Kent', 80)... and switching it so that it reads in both ways... List 1, [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)] List 2, ('Fred', 20), ('Joe', 50), ('Kent', 80), ('Sara', 90)] How would I do that so I wind up with both lists? I have two lists now, but if I try and reorder them they just reverse in alphabetical order without affecting the second value (the number). Thanks! - Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bundle help!
Sorry to be so confusing. Just realized a dumb mistake I made. It doesn't need to be resorted alphabetically and numerically. I need one list alphabetical and one numerical. (Alphabetical) List 1, [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)] (Numerical) List 2, [('Fred', 20), ('Kent', 50), ('Sara', 80) ('Joe', 90)] It looks like these are appended together, but to re-sort, how do I (not sure if this is a word) "unappend" them? Thanks, Sara Alan Gauld <[EMAIL PROTECTED]> wrote: "Sara Johnson" wrote >>Use append() to add more data, then sort again to get it in order: >>>>In [6]: data.append(('Joe', 90)) >>>>In [7]: data.sort() >>>>In [8]: data >>>>Out[8]: [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)] > > What happens if I need to sort alphabetical and numerically? You can supply your own comparison function to the sort routine. You can also just specify the key to sort by for simple cases. > I'm taking the original list and the original values > i.e., ('Fred', 20), ('Joe', 90), ('Kent', 80)... and switching it > so that it reads in both ways... > List 1, [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)] > List 2, ('Fred', 20), ('Joe', 50), ('Kent', 80), ('Sara', 90)] But you lost me here. You seem to be switching the values in the tuples around and its not clear to me by what criteria. - Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bundle help!
Sorry, just needing to clarify. As I may have eluded to in other posts, this is sort of a script that was written and I'm making modifications to. Due to my serious lack of experience, I'm afraid to rewrite anything. However, would I accomplish the same result by copying the lists, then breaking them apart with zip()? I haven't used that before, but I'm willing to try it as long as I don't ruin what's already been done. Unfortunately, the link you posted didn't bring up anything. I tried to search google groups and got a bunch of asian text (using comp.lang.py). Again, sorry for my lack of experience here. I do speak C somewhat. Guess I should sign this: HTDI...(hope that didn't irritate!) Sara David Perlman <[EMAIL PROTECTED]> wrote: I think what you want to do is start from the beginning with two separate lists, sort each one however you want, and then either join them with zip() or simply reference them as (list1[n], list2[n]). I believe there's also a way to use zip() to separate your list of tuples into separate lists, but I don't know how off the top of my head. You can find out if you follow these instructions though: Go to http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&group=comp.lang.py enter 'zip inverse', and check search Python only. On Jul 8, 2007, at 6:41 PM, Sara Johnson wrote: > How would I do that so I wind up with both lists? I have two lists > now, but if I try and reorder them they just reverse in > alphabetical order without affecting the second value (the number). > -- -dave All I ask is that the kind of unsolvable that it turns out to be has respectable precedents. -Jerry Fodor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor - Pinpoint customers who are looking for what you sell. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bundle help!
Alan Gauld <[EMAIL PROTECTED]> wrote: "Sara Johnson" wrote > this is sort of a script that was written and I'm making > modifications to. Due to my serious lack of experience, > I'm afraid to rewrite anything. This is probably a long shot given the code you've posted so far, but I don't suppose there are any design documents available? Structure charets, class diagrams? Even plain text or pseudo code? Not sure I follow what you mean by those specific documents or diagrams, but I do have the output and the sample code. Seems like it would be easy to just enter it all in and get that output, except for the different files I've had to include ("chmod" command on various scripts). Not sure if I've described that correctly. Nonetheless, I've had to bundle this and pickle that and create 3 different files plus one script. Only close on one of those. If you are talking about the output on this one step, I can put it into a text file and attach it. Again my fear is that whatever I do to make that happen will eventually lead to the other outputs as well. In an ideal world it would be possible to find the faulty function without having to read any code, but few projects are that well documented. But then again few projects have nothing! If you can find it it might tell you at a high level how the code hangs together. I'm not sure zip is the best tool for breaking lists apart, but I'm no expert with it. But its easy to do with a simple loop if you are dealing with a list of tuples: list1 = [] list2 = [] for item in theList: list1.append(item[0]) list2.append(item[1]) I will give this a try and some of the other suggestions I have received. Thanks again! - Choose the right car based on your needs. Check out Yahoo! Autos new Car Finder tool.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bundle help!
Thanks to everyone for your help and quick responses! Has anyone heard of the "bundle method?" Some of you have already said you didn't. I wonder why it's included as part of my code/instructions. I'm trying to accomplish what I 'think' they want with the other questions I've posed here. Here's my instruction: #SUB-TASK 1: Fix the above to print/write only the keys with >0% missing, sorted alphabetically #by the key. (No need to use the "bundle method" for that). But ALSO append the #same information to outfile2, sorted by worst offender. (Use bundle for that). Just curious, but in this link (' http://xahlee.org/perl-python/sort_list.html ') you mentioned, what does the "re" part mean? At first I thought it was the name of the list or 'return' but that's included later. *** def myComp (x,y): import re def getNum(str): return float(re.findall(r'\d+',str)[0]) return cmp(getNum(x),getNum(y)) li.sort(myComp) print li # returns ['web7-s.jpg', 'my23i.jpg', 'fris88large.jpg', 'my283.jpg'] Thanks, Sara * David Perlman <[EMAIL PROTECTED]> wrote: Maybe this reference will help: http://xahlee.org/perl-python/sort_list.html Just the first part of the discussion there. - We won't tell. Get more on shows you hate to love (and love to hate): Yahoo! TV's Guilty Pleasures list.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bundle help!
Regarding my early question on bundle. Not sure if this makes any sense, but I noticed where else it's used. If this looks funny, remember that I did not write it (and therefore do not entirely understand it). I'm only editing it according to some specific guidelines. >>>for key in h.keys(): >>>bundle=(h[key]['TA9M'],key) #bundle is a tuple, (a list would also be ok) >>>if bundle[0]>0.: >>>allt.append(bundle) Thanks, Sara - Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] interpreter restarts
Luke, Jacob, et. al... Dumb question (may be slightly off course from what you two were discussing), but are you both describing how to get the IDLE to run along with the editor? I may just be getting too many things confused. I've tried to run IDLE, but that's not working. I have the same function through opening it separately from the Start menu but then it doesn't work as IDLE should work with the editor (or so I've been told that happens). I can type the word Python in my editor and it comes up, but then the editor is gone. I've gone so long with just SSH, but at this point it's worth it if I find a way that makes sense. As someone mentioned from this list, at least it'll be code that is easier to read for a newbie like myself. (Hope that didn't confuse or cause unnecessary headaches...) Sara - Original Message From: Luke Paireepinart <[EMAIL PROTECTED]> To: Tiger12506 <[EMAIL PROTECTED]> Cc: tutor@python.org Sent: Monday, July 16, 2007 7:00:53 PM Subject: Re: [Tutor] interpreter restarts Tiger12506 wrote: >> But there's an exception to that - if you right-click a file in Windoze >> and 'edit' it, >> IDLE won't open up its subprocess, and as such, it can't restart the >> interpreter session because it's running in the same >> process as IDLE, and to restart the interpreter would mean restarting >> IDLE. >> Boy, that 'edit with idle' thing sure does cause some problems, don't it? >> :) >> -Luke >> > > Thanks, Luke. I hadn't thought of that. Question: Why won't IDLE open up its > subprocess? > > This is the command that is in the registry concerning the Edit with IDLE > menu. > "C:\Python25\pythonw.exe" "C:\Python25\Lib\idlelib\idle.pyw" -n -e "%1" > > This is the Target for the shortcut in the Start Menu (Note: the Target box > was disabled!) > Python 2.5.1 > > I thought that this was incredibly strange, so I opened this shortcut in a > hex editor to see what was different about this shortcut. (Normally, they > have a path in the target box) > > What I found surprised me. The title of the file in the hex editor said > "python_icon.exe" > I started laughing maniacally and checked the full path of the file from > within the hex editor. > C:\windows\installer\{3184-6386-4999-a519-518f2d78d8f0}\python_icon.exe > > IDLE is started in two *very* different ways. So my next question was: Can > you pass arguments to this python_icon.exe? Simple navigations to that > directory and a confirmation... Yuck. You can't even execute it from > explorer. A low-level ZwTerminateProcess function from ntdll is called ... > Let me try something... > > Woah... {3184-6386-4999-a519-518f2d78d8f0} appears in the registry in > alot of places. The Uninstall key for Add/Remove Programs, some weird data > thing... Okay, this is beyond me. I don't know the registry or understand > CLSIDs very well. Someone who knows Windows inside and out has done a number > with the python installer, or at least the msi installer does this all > automatically. Interesting. I wonder just how python_icon.exe starts IDLE. > If I could figure that out, I could emulate it with the Edit w/Idle menu > item and get IDLE to start a subprocess! But how any ideas? > It sounds like python_icon.exe is a fake executable that just contains the icon for python programs... hence the name. You probably stumbled across the path to the icon to use, instead of the path that is used when running the 'Edit with IDLE' thing. Try this: open an Explorer window, via Start Button -> Run -> explorer {ENTER} or your favorite method. Use the My Computer shortcut if you want, either way. Now hit "Alt, t, o" to browse to the Tools -> Folder Options menu setting. Go to the File Types tab, and scroll down till you find "PY" click the Advanced button. You should now see a dialog box with Edit with IDLE listed under actions. Click Edit when "Edit with IDLE" is selected. in the "Application used to perform action:" field you should see something like this: "C:\Python24\pythonw.exe" "C:\Python24\Lib\idlelib\idle.pyw" -n -e "%1" Basically, this is the same as saying: python idle.py except it's more verbose because python may not be on your path (and pythonw is used instead of python so there's no dos box) As you will notice, there are some parameters there at the end. the -n is the one you're interested in . -n means no subprocess. Just remove that, and you will have a subprocess on the 'Edit with IDLE' feature. There is some caveat here - it doesn't work correctly on some systems, I'm told. I've never had problems changing this, but I don't recommend it to people randomly just in case it were to cause problems for them. Then I'd feel bad. But since you asked, I thought I'd give you all the info you need. HTH, -Luke P.S. nice detective skillz ;) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___
Re: [Tutor] IDLE Usage - was Interpreter Restarts
First off, yes, I was referring to (I guess you could say) a non-python editor. I use an SSH editor set up by my school. If I type python at the prompt in SSH, I get the Python shell. My problem is, I can't open a GUI no matter what I subscribe to or purchase. I have Python 2.3 and yes, I can access the commandline, but that does not work the way it's been described to work. If this still doesn't make any sense, just ignore me... Sara >>Not quite what we were discussing, but I think you may have given just enough clues that i can be of some help. Just for reference ~ which editor are you using? IDLE is both an editor and a python shell or interpreter. It is not the same thing as typing python.exe wherever you might be typing it. Typing Python into an editor should put the word "Python" into your currently open file. I don't believe that this is what you mean. Perhaps you are confusing what exactly is an editor? You use Windows you've mentioned before. So here's what you can do. Start -> Programs -> Python 2.5 -> Python (commandline) This is the python interpreter. As you might already know. And then this. Start -> Programs -> Python 2.5 -> IDLE (Python GUI) This is IDLE. As you probably know. Two windows should come up when you click IDLE. One is an editor. The other is the python shell, or interpreter. You can open .py files in IDLE by right clicking and selecting "Edit with IDLE". At any time that you wish to run a program that is open in the editor half of IDLE, hit F5 and the Python shell half of IDLE comes to the top and runs the program. If doing all that doesn't do what I expect it to do, or you have something else in mind, reply back. If it does, then great! Oh. And tell me which editor you are using which magically opens a python interpreter when you type Python into it. ;-) JS ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor It's here! Your new message! Get new email alerts with the free Yahoo! Toolbar. http://tools.search.yahoo.com/toolbar/features/mail/___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE Usage - was Interpreter Restarts
Everyone who has commented... I have XWin32It hasn't worked. I've talked to some people in the IT departments and they've given me things to check (boxes to check or uncheck) and that doesn't seem to make a difference. When I picked up these projects I was given a lot of stuff and left to figure it out. I was also left with the impression that I should have the GUI working. If a lot of Python programmers use SSH, then I guess there is no problem. But when you're a newbie who really doesn't understand what they're doing, anything that might make the process a tad more straight-forward is worth it. For example, I worked on this basic Unix editor 'Pico' before I learned I could switch to Vi and have my code color-coordinated so that I knew where my comments were and I could see if I accidentally commented something out that needs to be there. So maybe it's not too important that I use the Python shell with my school's editor program open (as I was advised to do). Some of you have already seen my confusion from the different questions I've asked about my code (or rather, the code I've been editing). So I thought most of the Python programmers preferred to use IDLE and that maybe it would simplify things just a tad for me. I'm about 2000 miles away from where I should be with these projects. Thanks, Sara - Original Message From: Luke Paireepinart <[EMAIL PROTECTED]> To: Sara Johnson <[EMAIL PROTECTED]> Cc: tutor@python.org Sent: Tuesday, July 17, 2007 12:24:11 AM Subject: Re: [Tutor] IDLE Usage - was Interpreter Restarts Sara Johnson wrote: > First off, yes, I was referring to (I guess you could say) a > non-python editor. I use an SSH editor set up by my school. If I > type python at the prompt in SSH, I get the Python shell. My problem > is, I can't open a GUI no matter what I subscribe to or purchase. I > have Python 2.3 and yes, I can access the commandline, but that does > not work the way it's been described to work. > > If this still doesn't make any sense, just ignore me... I'm not sure what your problem is. Does the SSH program provide a file transfer utility? could you write your code on your local computer then just transfer the final code to the server? A lot of Python programmers use Vi for writing their code. do you have access to that through SSH? I'm not quite sure what you mean by "SSH editor." -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Need a vacation? Get great deals to amazing places on Yahoo! Travel. http://travel.yahoo.com/___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE Usage - was Interpreter Restarts
I initially thought Vim was sort of the same as Vi, just a few small differences or upgrades. Or have I got that confused? Sara - Original Message From: Tiger12506 <[EMAIL PROTECTED]> To: tutor@python.org Sent: Tuesday, July 17, 2007 12:33:54 PM Subject: Re: [Tutor] IDLE Usage - was Interpreter Restarts Yeah. But she's running Windows. Perhaps vim is scary to some Windows users. (I thought it was scary and annoying. Are all those ~ characters really in the file or not? I kept second guessing the editor.) --Sara, could you give an example of how it doesn't work? Just what happens? Just what doesn't happen? You say you have Python 2.3 installed... > Greetings, > > I use an editor called 'vim' on GNU/Linux. > I invoke vim on the command-line by typing: vi > (vi is a link to /usr/bin/vim) > In my home directory I have a vim config file > named .vimrc (that is: dot_vimrc [the dot makes it hidden]). > The .vimrc file has some things in it that do some nice stuff > for editing Python files; such as syntax highlighting, line numbers, > indenting, and also runs Python when I press the F2 function key. > I run vim in an X ternminal called Konsole. I can also run it > from the command-line in any tty. > > Okay, here it is. Just copy/paste this into an editor, and save it as: > .vimrc > > -8<--Cut Here>8--- > " .vimrc > " > " Created by Jeff Elkner 23 January 2006 > " Last modified 2 February 2006 > " > " Turn on syntax highlighting and autoindenting > syntax enable > filetype indent on > " set autoindent width to 4 spaces (see > " http://www.vim.org/tips/tip.php?tip_id=83) > set nu > set et > set sw=4 > set smarttab > " Bind key to running the python interpreter on the currently active > " file. (curtesy of Steve Howell from email dated 1 Feb 2006). > map :w\|!python % > -8<--Cut Here>8--- > > To use it, just type: vi myCode.py > (If you don't have a link named vi that points to /usr/bin/vim, > you'll have to type vim or /usr/bin/vim to get it going... > since I don't have any idea what you're working at, I can't say.) > > Once you're in vim, looking at your code, press F2 to run it. > > I understand that Emacs also does Python! =) > But I won't go there... I don't do Emacs. > -- > bhaaluu at gmail dot com > > On 7/17/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote: >> A lot of Python programmers >> use Vi for writing their code. do you have access to that through SSH? >> I'm not quite sure what you mean by "SSH editor." >> -Luke >> ___ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor >> > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games. http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE Usage - was Interpreter Restarts
Sorry all... SSH editor means "Unix" Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE Usage - was Interpreter Restarts
Sure, sounds good. Should I assume that 'any' Unix version allows Vim? Thanks, Sara - Original Message From: jim stockford <[EMAIL PROTECTED]> To: Sara Johnson <[EMAIL PROTECTED]> Cc: tutor@python.org Sent: Tuesday, July 17, 2007 12:30:12 PM Subject: Re: [Tutor] IDLE Usage - was Interpreter Restarts you want a very brief set of vi(m) commands-- a get-you-started tutorial that's nearly painless? I'll send if "yes". jim On Jul 16, 2007, at 9:26 PM, Sara Johnson wrote: > First off, yes, I was referring to (I guess you could say) a > non-python editor. I use an SSH editor set up by my school. If I > type python at the prompt in SSH, I get the Python shell. My problem > is, I can't open a GUI no matter what I subscribe to or purchase. I > have Python 2.3 and yes, I can access the commandline, but that does > not work the way it's been described to work. > > If this still doesn't make any sense, just ignore me... > > Sara > > > >>Not quite what we were discussing, but I think you may have given > just > enough clues that i can be of some help. Just for reference ~ which > editor > are you using? > > IDLE is both an editor and a python shell or interpreter. It is not > the same > thing as typing python.exe wherever you might be typing it. > > Typing Python into an editor should put the word "Python" into your > currently open file. I don't believe that this is what you mean. > Perhaps you > are confusing what exactly is an editor? > > You use Windows you've mentioned before. So here's what you can do. > Start -> > Programs -> Python 2.5 -> Python (commandline) > > This is the python interpreter. As you might already know. > > And then this. > Start -> Programs -> Python 2.5 -> IDLE (Python GUI) > > This is IDLE. As you probably know. > > Two windows should come up when you click IDLE. One is an editor. The > other > is the python shell, or interpreter. You can open .py files in IDLE by > right > clicking and selecting "Edit with IDLE". At any time that you wish to > run a > program that is open in the editor half of IDLE, hit F5 and the Python > shell > half of IDLE comes to the top and runs the program. > > If doing all that doesn't do what I expect it to do, or you have > something > else in mind, reply back. If it does, then great! > > Oh. And tell me which editor you are using which magically opens a > python > interpreter when you type Python into it. ;-) > > JS > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > Moody friends. Drama queens. Your life? Nope! - their life, your story. > Play Sims Stories at Yahoo! > Games.___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor 8:00? 8:25? 8:40? Find a flick in no time with the Yahoo! Search movie showtime shortcut. http://tools.search.yahoo.com/shortcuts/#news___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE Usage - was Interpreter Restarts
- Original Message From: Robert H. Haener IV [EMAIL PROTECTED] If you name the SSH client (which I believe you've been calling an "SSH editor") you're using, I might be able to give you step by step instructions for setting your client to use X Forwarding. If the SSH server doesn't allow X Forwarding, I recommend using a program called 'screen'. Basically, 'screen' allows you to use a shell a bit like the tabbed browsing in Firefox (or Opera, IE7, etc.) by creating a framework wherein you can create new virtual shells and switch between them using keyboard shortcuts. What is more, you can label the virtual shells and even copy/paste text between them. I can give you plenty of information about using 'screen' if you want it, what I'm getting around to is that if I was in your situation I would have the python interpreter running in one virtual shell whilst running vim in another virtual shell. That's pretty much what I was attempting. I was advised to mark the "Tunneling" box (TunnelingX11 Connections), and it's checked. I don't see the X Forwarding option, however. Under that same tab I checked for anything else system-wise that would pertain and I don't see anything. Again, I have XWin32 installed, but I probably need to renew it or somehow get it to work as you've described. Anything else I should check? >>For example, I worked on this basic Unix editor 'Pico' before I learned I >>could switch to Vi and >>have Sorry...I meant to say "Putty" not Pico... Not important, just clarifying. Thanks, Sara Get the Yahoo! toolbar and be alerted to new email wherever you're surfing. http://new.toolbar.yahoo.com/toolbar/features/mail/index.php___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] IDLE connection - was IDLE Usage
I am setting up an Xming/XWindows (forwarding?) and I followed what was instructed. When I got ready to connect, it all looked okay, but then I got this message. 'Warning: Missing charsets in String to FontSet conversion' Anyone know? Thanks, Sara - Original Message From: Robert H. Haener IV <[EMAIL PROTECTED]> To: Sara Johnson <[EMAIL PROTECTED]> Cc: Python Sent: Tuesday, July 17, 2007 1:49:19 PM Subject: Re: [Tutor] IDLE Usage - was Interpreter Restarts Sara Johnson wrote: > That's pretty much what I was attempting. I was advised to mark the > "Tunneling" box (TunnelingX11 Connections), and it's checked. I don't > see the X Forwarding option, however. Under that same tab I checked for > anything else system-wise that would pertain and I don't see anything. > Again, I have XWin32 installed, but I probably need to renew it or > somehow get it to work as you've described. Anything else I should check? > >>>For example, I worked on this basic Unix editor 'Pico' before I > learned I could switch to Vi and >>have > Sorry...I meant to say "Putty" not Pico... Not important, just clarifying. > > Thanks, > Sara I have never attempted to use X Forwarding in Windows, but here is a guide that seems to tell you all you need to know: http://www.math.umn.edu/systems_guide/putty_xwin32.html >>From what I can gather, you should contact whomever is in charge of the SSH >>server if you can't get GUI programs working after following that guide. Also, just so we don't end up massively confusing each other: PuTTy is your "SSH client." The server to which you are connecting is the "SSH server." Pico and Vim are examples of "text editors," which are sometimes called "UNIX editors" by Windows folks. -Robert ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. http://mobile.yahoo.com/go?refer=1GNXIC___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE connection - was IDLE Usage
Okay, carry on then. :-) Still haven't figured it out either and I've tried reloading it. - Original Message From: Robert H. Haener IV <[EMAIL PROTECTED]> To: Sara Johnson <[EMAIL PROTECTED]> Cc: Python Sent: Saturday, July 21, 2007 9:04:52 PM Subject: Re: [Tutor] IDLE connection - was IDLE Usage Sara Johnson wrote: > I am setting up an Xming/XWindows (forwarding?) and I followed what was > instructed. When I got ready to connect, it all looked okay, but then I > got this message. > > 'Warning: Missing charsets in String to FontSet conversion' > > Anyone know? > > Thanks, > Sara Sounds like you're missing some fonts, but that's just a guess. I will look it up further later tonight/tomorrow morning, I'm in the midst of a Thin Man marathon. -Robert ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Get the Yahoo! toolbar and be alerted to new email wherever you're surfing. http://new.toolbar.yahoo.com/toolbar/features/mail/index.php___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE Usage - was Interpreter Restarts
Alan, Actually, I think you just solved one of the main issues I've had. That is, trying to figure out how much it'll help to have the GUI session open with the SSH session (as was recommended when I set out to do these projects). I had it in my mind that having this up and working would mean that these projects would make more sense. I could have been using two SSH sessions all along, I suppose. Another concern was more towards the specific nature of these projects, once I have to concern myself with graphics on a few tasks. For all I know it may not matter either way, but I had to check. I've been talking to someone else off list about that. Anyways, thanks for help! Sara - Original Message From: Alan Gauld <[EMAIL PROTECTED]> To: tutor@python.org Sent: Sunday, July 22, 2007 4:39:51 AM Subject: Re: [Tutor] IDLE Usage - was Interpreter Restarts "Sara Johnson" <[EMAIL PROTECTED]> wrote > I use an SSH editor set up by my school. If I type python at the > prompt in SSH, > I get the Python shell. My problem is, I can't open a GUI no matter > what > I subscribe to or purchase. OK, Personally I'd forget about a GUI, its not that big a win for Python IMHO. What I'd do instead is open two SSH sessions, in one of them I'd open a vim session (or emacs if you prefer) to edit my code. In the second window open a python interactive session for testing stuff. You can also use Unix job control to background this session if you need to test the scripts, or you can open a third SSH session with a Unix shell prompt. In practice that's how I do nearly all my serious Python programming on Windows - using 3 separate windows: vim, Pyhon and shell. Try ideas out in the Python session, copy those ideas into the editor and save the file and then run the code in the shell window. Repeat as needed. > I have Python 2.3 and yes, I can access the commandline, but that > does > not work the way it's been described to work. What is missing? It should work like any standard >>> prompt. However it will be the vanilla version without some of the nice extras that IDE shells often provide and depending on how your Python was built it may not offer GNU readline capability to recall previous commands etc. Finally, If you really want to run an X GUI I'd recommend getting cygwin. Its big but it includes a near complete Unix/ X environment for your PC (including the fonts) as well as an SSH client and provi8ded your SSH server allows X to run - and many don't for security reasons - then it should work. You will have to issue the xhosts incantations of course to tell the server to accept requests from your PC. Pesonally I think its more work than is worth it unless you will be doing a lot of work on that server over a long time.. My opinion for what its worth! :-) -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV. http://tv.yahoo.com/___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] comparing lists, __lt__ and __gt__
First off, Kent, thanks for posting that! I know it's in the Python library but it does help to have a bookmark for things I know I'll need pretty soon. Second... What if there is a '<<' or '>>'? Does that just mean the same thing (maybe a little over emphasized.. ;) I thought I saw this when I was learning boolean expressions, but I don't recall. - Original Message From: Kent Johnson [EMAIL PROTECTED] Good question! The only doc I can find on this behavior is this: http://docs.python.org/lib/comparisons.html which just says that the comparison operation exists. There doesn't seem to be any documentation on how comparison works with sequences. I think it is pretty safe to count on the current behaviour of < and > for lists. I'll put in a documentation bug on this - the meaning of these operations (and ==) should be explicit in the docs. Kent Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] comparing lists, __lt__ and __gt__
Thanks Alan. That said, any idea what it means in this context? for key in skeys: fracmiss=1.*numberMissing(z[key].values())/nsites #note decimal multiplication, 1.* outstring="%s has %4.1f%% missing" % (key,100*fracmiss) if fracmiss >>0 - Original Message From: Alan Gauld <[EMAIL PROTECTED]> To: tutor@python.org Sent: Saturday, July 28, 2007 5:03:05 PM Subject: Re: [Tutor] comparing lists, __lt__ and __gt__ "Sara Johnson" <[EMAIL PROTECTED]> wrote > What if there is a '<<' or '>>'? > Does that just mean the same thing (maybe a little over emphasized.. > ;) The double chevron operator is for bit-shifting its not a camparison operation. So no operator override function exists. > I thought I saw this when I was learning boolean expressions, > but I don't recall. Possibly, because its often used to manipulate bitpatterns in conjunction with bitwise boolean comparisons (and/or/xor etc) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] attribute error
I thought 'sort()' was a function you could use as long as the dict or key had some value. When is this not right? Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center. http://autos.yahoo.com/green_center/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error
I scrapped that other attempt. I keep hitting brick walls. However, is there an indentation error here? I may just be too frustrated to see it. for key in skeys: fracmiss=1.*numberMissing(z[key].values())/nsites #note decimal multiplication, 1.* outstring="%s has %4.1f%% missing" % (key,100*fracmiss) if fracmiss>0.: print outstring - Original Message From: Bob Gailer <[EMAIL PROTECTED]> To: Sara Johnson <[EMAIL PROTECTED]> Cc: Python Sent: Saturday, July 28, 2007 10:14:58 PM Subject: Re: [Tutor] attribute error Sara Johnson wrote: > I thought 'sort()' was a function you could use as long as the dict or > key had some value. When is this not right? Please give us some context for the question. Code fragment, traceback. sort is a method of mutable sequence types (lists, ...) myList = [1, 3, 2] myList.sort() # returns None print myList [1, 2, 3] -- Bob Gailer 510-978-4454 Oakland, CA 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Choose the right car based on your needs. Check out Yahoo! Autos new Car Finder tool. http://autos.yahoo.com/carfinder/___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error --Disregard
Disregard this post. Sorry for the added message in everyone's inbox. - Original Message From: Sara Johnson <[EMAIL PROTECTED]> To: Python Sent: Saturday, July 28, 2007 11:19:15 PM Subject: Re: [Tutor] attribute error I scrapped that other attempt. I keep hitting brick walls. However, is there an indentation error here? I may just be too frustrated to see it. for key in skeys: fracmiss=1.*numberMissing(z[key].values())/nsites #note decimal multiplication, 1.* outstring="%s has %4.1f%% missing" % (key,100*fracmiss) if fracmiss>0.: print outstring - Original Message From: Bob Gailer <[EMAIL PROTECTED]> To: Sara Johnson <[EMAIL PROTECTED]> Cc: Python Sent: Saturday, July 28, 2007 10:14:58 PM Subject: Re: [Tutor] attribute error Sara Johnson wrote: > I thought 'sort()' was a function you could use as long as the dict or > key had some value. When is this not right? Please give us some context for the question. Code fragment, traceback. sort is a method of mutable sequence types (lists, ...) myList = [1, 3, 2] myList.sort() # returns None print myList [1, 2, 3] -- Bob Gailer 510-978-4454 Oakland, CA 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Shape Yahoo! in your own image. Join our Network Research Panel today! Pinpoint customers who are looking for what you sell. http://searchmarketing.yahoo.com/___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error
- Original Message From: Alan Gauld [EMAIL PROTECTED] >> for key in skeys: >> fracmiss=1.*numberMissing(z[key].values())/nsites #note decimal >> multiplication, 1.* >This is a mess. Why have that long comment when all that's needed >is to add the zero?! (and some spaces to make it legible...) I wish I could take credit for that. At least it would feel like progress. I didn't write it. All I'm trying to do now is sort it alphabetically, and then attempt to append it with another list and sort that. While I didn't write that, I always thought with floats you needed a 0.0. I do have some percentages that are less than 1% but more than 0.0. >fracmiss = 1.0 * numberMissing( z[key].values() ) / nsites >outstring = "%s has %4.1f%% missing" % (key, 100 * fracmiss) >if fracmiss > 0.0: print outstring >It looks OK apart from the poor style but I don't see anything that is >an error. What are you seeing? I pasted a part of the script in some other part of the program unknowingly. Still getting used to Vi/Vim. Thanks Alan! Sara Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when. http://tv.yahoo.com/collections/222___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error
Is this the correct traceback? Output okay except it will not sort alphabetically. Traceback (most recent call last): File "./mymods.py", line 83, in ? outfile2.sort() AttributeError: 'file' object has no attribute 'sort' * Here's the code. I did not write most of this, I'm only modifying it. In fact, I'm only responsible for the last two lines. #reverse the dictionary of dictionaries, making new dictonary z: z={} #initialize empty dictionary skeys=h[keys[0]].keys() #get the "sub-keys" for i in skeys: #use sub-keys as new main-keys z[i]={} for j in keys: #use main-keys as new sub-keys z[i][j]=h[j][i] #use the new dictionary to find number of missing values: print "\n fraction of sites with missing measurements:" nsites=len(h.keys()) outfile2=open('missmeas.dat','w') for key in skeys: fracmiss=1.*numberMissing(z[key].values())/nsites outstring="%s has %4.1f%% missing" % (key,100*fracmiss) if fracmiss>0.: print outstring - Original Message From: Alan Gauld <[EMAIL PROTECTED]> To: tutor@python.org Sent: Sunday, July 29, 2007 2:23:55 AM Subject: Re: [Tutor] attribute error "Sara Johnson" <[EMAIL PROTECTED]> wrote > However, is there an indentation error here? Not that I can see. Is there an error? If so can you send the traceback? Its very hard to answer questions without any context. > I may just be too frustrated to see it. > > for key in skeys: > fracmiss=1.*numberMissing(z[key].values())/nsites #note > decimal multiplication, 1.* This is a mess. Why have that long comment when all that's needed is to add the zero?! (and some spaces to make it legible...) fracmiss = 1.0 * numberMissing( z[key].values() ) / nsites outstring = "%s has %4.1f%% missing" % (key, 100 * fracmiss) if fracmiss > 0.0: print outstring It looks OK apart from the poor style but I don't see anything that is an error. What are you seeing? On the style front, if you want to force a result to a float it's more conventional to use the float() conversion function: fracmiss = float( numberMissing( z[key].values() ) / nsites ) And comparing to 0.0 doesn't really add anything except two characters, it could just as well be plain old 0. if fracmiss > 0: HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error - quick addition
Sorry...I forgot a few more lines at the end of the code. Starts with "outfile2write..." I also added outfile2.sort() Is this the correct traceback? Output okay except it will not sort alphabetically. Traceback (most recent call last): File "./mymods.py", line 83, in ? outfile2.sort() AttributeError: 'file' object has no attribute 'sort' * Here's the code. I did not write most of this, I'm only modifying it. In fact, I'm only responsible for the last two lines. #reverse the dictionary of dictionaries, making new dictonary z: z={} #initialize empty dictionary skeys=h[keys[0]].keys() #get the "sub-keys" for i in skeys: #use sub-keys as new main-keys z[i]={} for j in keys: #use main-keys as new sub-keys z[i][j]=h[j][i] #use the new dictionary to find number of missing values: print "\n fraction of sites with missing measurements:" nsites=len(h.keys()) outfile2=open('missmeas.dat','w') for key in skeys: fracmiss=1.*numberMissing(z[key].values())/nsites outstring="%s has %4.1f%% missing" % (key,100*fracmiss) if fracmiss>0.: print outstring outfile2.write(outstring+'\n') #notice explicit newline \n outfile2.sort() outfile2.close() - Original Message From: Alan Gauld <[EMAIL PROTECTED]> To: tutor@python.org Sent: Sunday, July 29, 2007 2:23:55 AM Subject: Re: [Tutor] attribute error "Sara Johnson" <[EMAIL PROTECTED]> wrote > However, is there an indentation error here? Not that I can see. Is there an error? If so can you send the traceback? Its very hard to answer questions without any context. > I may just be too frustrated to see it. > > for key in skeys: > fracmiss=1.*numberMissing(z[key].values())/nsites #note > decimal multiplication, 1.* This is a mess. Why have that long comment when all that's needed is to add the zero?! (and some spaces to make it legible...) fracmiss = 1.0 * numberMissing( z[key].values() ) / nsites outstring = "%s has %4.1f%% missing" % (key, 100 * fracmiss) if fracmiss > 0.0: print outstring It looks OK apart from the poor style but I don't see anything that is an error. What are you seeing? On the style front, if you want to force a result to a float it's more conventional to use the float() conversion function: fracmiss = float( numberMissing( z[key].values() ) / nsites ) And comparing to 0.0 doesn't really add anything except two characters, it could just as well be plain old 0. if fracmiss > 0: HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Pinpoint customers who are looking for what you sell. Yahoo! oneSearch: Finally, mobile search that gives answers, not web links. http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error - quick addition
Thanks Alan and Kent (for the sorting notes)! Alan...I guess I thought outfile2 had data. { i.e., outfile2=open('missmeas.dat','w') } My mistake. Thanks, Sara - Original Message From: Alan Gauld <[EMAIL PROTECTED]> To: tutor@python.org Sent: Sunday, July 29, 2007 7:00:12 PM Subject: Re: [Tutor] attribute error - quick addition "Sara Johnson" <[EMAIL PROTECTED]> wrote > Sorry...I forgot a few more lines at the end of the code. Starts > with "outfile2write..." > I also added outfile2.sort() OK, at leasrt we see where the error occcurs. The problem emains that you are trying to sort a file which doesn't have a sort method. You need to sort the data before saving it. Alan G. outfile2=open('missmeas.dat','w') for key in skeys: fracmiss=1.*numberMissing(z[key].values())/nsites outstring="%s has %4.1f%% missing" % (key,100*fracmiss) if fracmiss>0.: print outstring outfile2.write(outstring+'\n') #notice explicit newline \n outfile2.sort() outfile2.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Choose the right car based on your needs. Check out Yahoo! Autos new Car Finder tool. http://autos.yahoo.com/carfinder/___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error - quick addition
Sorry... I'm still learning about lists, tuples, etc... Thanks, Sara - Original Message From: Tiger12506 <[EMAIL PROTECTED]> To: tutor@python.org Sent: Monday, July 30, 2007 5:42:47 PM Subject: Re: [Tutor] attribute error - quick addition > Thanks Alan and Kent (for the sorting notes)! > > Alan...I guess I thought outfile2 had data. { i.e., > outfile2=open('missmeas.dat','w') } Argghh!!! No, no, no! Attribute Error! No matter how much data you have in the file, you will *never* be able to call sort on it, because file objects do not understand sort. They do not have the "attribute" called "sort". Lists have sort. If you want to sort them like you are trying, you will have to convert the file into a list (of lines). lst = list(outfile2) lst.sort() JS > My mistake. > > Thanks, > Sara ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games. http://sims.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] attribute error - quick addition
No luck finding tutors. I don't make enough. It seems to be this script that's throwing me off. But I understand and I'll take what I've learned to date and something will work eventually. Thanks for your concern and support. Sara - Original Message From: Alan Gauld <[EMAIL PROTECTED]> To: tutor@python.org Sent: Monday, July 30, 2007 5:55:56 PM Subject: Re: [Tutor] attribute error - quick addition "Sara Johnson" <[EMAIL PROTECTED]> wrote > Sorry... I'm still learning about lists, tuples, etc... Sarah, You've been hanging around with this list for a few weeks now. If you just took one day out to go through the official tutorial then you should know enough to answer all of these questions. Seriously, invest the time to learn the language and you will cut the time messing around and solve your problem a lot sooner. Hacking away in the hope of stumbling on a solution and asking questions here if it doesn't work is one of the most inefficient ways to get your job done. (Both for you and us!) We are all here to help people learn Python and answer questions but you will make it easier on all of us if you work through a tutor to get the basics clearly fixed. Not only will your problem be easier to solve but the answers we give will make more sense too! Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center. http://autos.yahoo.com/green_center/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor